rpms/stapitrace/F-10 it-update.patch, NONE, 1.1 stapitrace.spec, 1.19, 1.20

Maynard Johnson maynardj at fedoraproject.org
Mon Dec 15 22:19:27 UTC 2008


Author: maynardj

Update of /cvs/pkgs/rpms/stapitrace/F-10
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv5185

Modified Files:
	stapitrace.spec 
Added Files:
	it-update.patch 
Log Message:
update package to match SystemTap 0.8 updates

it-update.patch:

--- NEW FILE it-update.patch ---
diff -paur Dpiperf/src/stap/itrace.1 Dpiperf-fixed/src/stap/itrace.1
--- Dpiperf/src/stap/itrace.1	2008-12-10 19:42:55.000000000 -0500
+++ Dpiperf-fixed/src/stap/itrace.1	2008-12-10 19:02:26.000000000 -0500
@@ -37,7 +37,7 @@ program can start up the Systemtap instr
 dmesg should be used to verify that the usr_itrace_init() has completed.  There should be a message like:
 .BR
 .SAMPLE
-	usr_itrace_init:step_flag = 2
+	usr_itrace_init:step_flag = 3
 .ESAMPLE
 .SH OPTIONS
 .TP
@@ -47,28 +47,26 @@ Show help message.
 .B --verbose
 Write verbose output to stdout.
 .TP
-.B --addr=<hex_lo>:<hex_hi>
-Instruction tracing data will be generated turned on at <hex_lo> and turned
-off at <hex_hi>.  Zero or more --addr options is allowed.  At least one
---func, or --addr option must be specified.
-.TP
-.B --func=<func_name>
-Instruction tracing will be turned on at the beginning of the <func_name>
+.B --func=<func_name> [required]
+Instruction tracing will be turned on at the beginning of <func_name>
 and turned off on return from <func_name>.  The --func option must be
-accompanied by a --prog option.  Zero or more --func options is allowed.
-At least one --func, or --addr option must be specified.
-.TP
-.B --pid=<pid>
-If the program to be traced is already running the --pid option tells the
-itrace script its pid. [required]
+accompanied by a --prog option where the specified program contains <func_name>.
+More than one --func option is allowed.
 .TP
-.B --prog=<prog_name>
+.B --prog=<prog_name> [required]
 The --prog option allows
 .IR itrace
-to map function names given in --func option to the corresponding address.  --prog is required when using the --func option.
+to map function names given in --func option to the corresponding address.
+.TP
+.B --pid=<pid>
+If the program to be traced is already running, use this option to specify the process ID
+of the running program. If you do use this option, then
+.IR itrace
+will execute the program given in the --prog option.
 .TP
 .B --qtrace
-Generate qtrace output file from the itrace data collected.
+Generate qtrace output file from the itrace data collected (saved as output.qt in
+the current directory).
 .TP
 .B --debuginfo
 This option indicates that kernel debuginfo is available which will allow
@@ -81,21 +79,30 @@ Name the trace output file.  [default: i
 only collected on branch instructions.
 .TP
 .B --keep
-Keep the generated SystemTap tapscript and other temporary files.
+Keep the generated SystemTap tapscript and other temporary files.a
+.TP
+.B Optional arguments to stap
+All other arguments will be passed to stap, the
+SystemTap translator.  See the man page for stap(1) for details.
 .SH EXAMPLE
-A typical scenario might be:
+.IR itrace
+does not allow for passing arguments to the program you are tracing.  If your
+program requires arguments, then you must start the program first and then use
+the --pid option to pass the program's process ID to
+.IR itrace.
+For example:
 .BR
 .SAMPLE
 
 ------------ window 1 -------------
-% ./my_prog
+% ./my_prog <some args for my_prog>
 My pid is 12657  [program waits for <ENTER> to continue]
 Another technique would be to start the user program, and immediately
 suspend it.  This would only work if the user program could be
 suspended before the code you want to trace starts execution.
 ------------ window 2 -------------
 % itrace --func=my_func --prog=my_prog --output=my_prog.out --pid=12657
-/usr/bin/stap -g /tmp/itraceD8vi7M/itrace_it.stp -o itrace.out 12657
+/usr/bin/stap -g /tmp/itraceD8vi7M/itrace_it.stp -o itrace.out
 
 NOTE: If stap produces errors re-run with -vvvv option
 To complete instruction tracing:
diff -paur Dpiperf/src/stap/itrace.c Dpiperf-fixed/src/stap/itrace.c
--- Dpiperf/src/stap/itrace.c	2008-12-10 19:42:55.000000000 -0500
+++ Dpiperf-fixed/src/stap/itrace.c	2008-12-10 19:42:35.000000000 -0500
@@ -30,27 +30,17 @@
  * systemtap script and running it to collect instruction trace data
  */
 enum options {
-	ADDR, FUNC, PROG, PID, VERBOSE, KEEP, OUTPUT, 
-	QTRACE, DEBUGINFO, HELP, UNKNOWN};
+	FUNC, PROG, PID, OUTPUT, VERBOSE, KEEP, QTRACE,
+	DEBUGINFO, HELP, UNKNOWN};
 
 char *option_names[] = {
-	"--addr", "--func", "--prog", "--pid", "--verbose", "--keep",
-	"--output", "--step_trace", "--qtrace", "--debuginfo", "--help"
+	"--func", "--prog", "--pid", "--output", "--verbose", "--keep",
+	"--qtrace", "--debuginfo", "--help"
 };
 
-typedef struct func_addr_t {
-	char *func;
-	char *addr;
-} func_addr_t;
-
-typedef struct trace_addr_t {
-	unsigned long lo;
-	unsigned long hi;
-} trace_addr_t;
 
 #define MAX_ARGS 100
 int num_funcs = 0;
-int num_addrs = 0;
 int num_stap_args = 0;
 int verbose = 0;
 int keep = 0;
@@ -61,8 +51,7 @@ char *trace_pid = NULL;
 char *output_name = "itrace.out";
 char *step_mode = "single_step";
 char *stap_args[MAX_ARGS];
-trace_addr_t addrs[MAX_ARGS];
-func_addr_t funcs[MAX_ARGS];
+char *funcs[MAX_ARGS];
 char generated_stap_file[PATH_MAX];
 char *line_buffer;
 pid_t child_pid;
@@ -81,17 +70,19 @@ void do_help(void)
 		"usage: itrace --func=<func> --prog=<prog> --pid=<pid>",
 		" [--output=<file>]");
 	printf("%s\n", "   --help          this message");
-	printf("%s\n", "   --func=<func>   function to be traced ");
-	printf("%s%s\n", "   --prog=<prog>   program to be executed and traced;",
-		" [required with --func]");
-	printf("%s%s\n", "   --pid=<pid>     pid of process to be traced;",
+	printf("%s%s\n", "   --func=<function>   function to be traced ",
 		" [required]");
+	printf("%s%s\n", "   --prog=<program>   program to be executed and traced",
+		" [required]");
+	printf("%s\n", "   --pid=<pid>     pid of process to be traced",
+	       " [if not given, the program specified in --prog option will be executed]");
 	printf("%s%s\n", "   --output=<file> name output trace file",
 		" [default: itrace.out]");
 	printf("%s\n", "   --verbose       produce verbose output");
 	printf("%s\n", "   --keep          keep generated tapscript");
 	printf("%s\n", "   --debuginfo     use kernel debuginfo to terminate systemtap session");
 	printf("%s\n", "   --qtrace        generate qtrace output");
+	printf("%s\n", "   Arguments to stap");
 }
 
 void error_if_empty(char *arg, char *value)
@@ -114,59 +105,7 @@ enum options lookup_option(char *arg)
 	
 }
 
-int hex_str_to_long(char *str, unsigned long *addr)
-{
-	int i;
-	unsigned long val = 0;
 
-	for (i= 0; i < strlen(str); i++) {
-		char digit = str[i];
-
-		if (digit >= '0' && digit <= '9')
-			val = 16*val + digit-'0';
-		else if (digit >= 'a' && digit <= 'f')
-			val = 16*val + 10 + digit-'a';
-		else if (digit >= 'A' && digit <= 'F')
-			val = 16*val + 10 + digit-'A';
-		else if (digit == 'x' || digit == 'X') {
-			if (i != 1 || str[0] != '0') {
-				printf("malformed hex address: %s\n", str);
-				return 0;
-			}
-		} else {
-			printf("malformed hex address: %s\n", str);
-			return 0;
-		}
-	}
-	*addr = val;
-	return 1;
-} 
-
-void check_addrs(char *arg)
-{
-	char *colon = index(arg, ':');
-	char *lo = arg;
-	char *hi = NULL;
-	trace_addr_t addr;
-	int got_addrs;
-
-	unsigned long lo_addr;
-	unsigned long hi_addr;
-
-	if (colon) {
-		*colon = 0;
-		hi = colon + 1;
-	} else {
-		printf("invalid addrs option, missing high hex address: %s\n", arg);
-		exit(1);
-	}
-
-	 got_addrs = hex_str_to_long(lo, &lo_addr);
-	 if (hex_str_to_long(hi, &hi_addr) && got_addrs) {
-		addrs[num_addrs].lo = lo_addr;
-		addrs[num_addrs++].hi = hi_addr;
-	}
-}
 
 int check_options (int argc, char * argv[])
 {
@@ -188,14 +127,9 @@ int check_options (int argc, char * argv
 		}
 
 		switch(lookup_option(arg)) {
-		case ADDR:
-			error_if_empty(arg, val);
-			check_addrs(val);
-			break;
 		case FUNC:
 			error_if_empty(arg, val);
-			funcs[num_funcs].func = val;
-			funcs[num_funcs++].addr = NULL;
+			funcs[num_funcs++] = val;
 			break;
 
 		case PROG:
@@ -264,13 +198,9 @@ void dump_options(void)
 	if (prog) {
 		printf("PROG:\t\t%s\n", prog);
 		for (i = 0; i < num_funcs; i++)
-			printf("FUNC:\t\t%s:%s\n",
-				funcs[i].func, funcs[i].addr);
+			printf("FUNC:\t\t%s\n",
+				funcs[i]);
 	}
-
-	for (i = 0; i < num_addrs; i++)
-		printf("ADDRS:\t\t(0x%08lx, 0x%08lx)\n", addrs[i].lo, addrs[i].hi);
-
 }
 
 char *strinit(char *str)
@@ -283,111 +213,17 @@ char *strinit(char *str)
 	return new_str;
 }
 
-#define FUNC_ADDR_SCRIPT \
-"#! /bin/sh\n \
-prog=$1; shift\n \
-dir=$1; shift\n \
-ret_stat=0\n \
-nm $prog > $dir/nm.out\n \
-for func in $*; do\n \
-	grep -w $func $dir/nm.out | grep ' [tT] ' | sed -e 's/\\([0-9a-f]*\\) [Tt] \\(.*\\)/0x\\1 \\2/' >> $dir/func_addrs\n \
-	if test \"$?\" != 0; then\n \
-		ret_stat = 1\n \
-	fi\n \
-done\n \
-exit $ret_stat"
 
 int find_func(char *func)
 {
 	int i;
 
 	for (i=0; i < num_funcs; i++)
-		if (strcmp(func, funcs[i].func) == 0)
+		if (strcmp(func, funcs[i]) == 0)
 			return i;
 	return -1;
 }
 
-int lookup_funcs()
-{
-	int i;
-	int chars;
-	int n = LINE_MAX;
-	char cmd[1024];
-	char *script_body = FUNC_ADDR_SCRIPT;
-	char script_path[PATH_MAX];
-	FILE *script_fd;
-	char result_path[PATH_MAX];
-	FILE *result_fd;
-	char *line_buffer = (char *)malloc(LINE_MAX);
-	char *lp = line_buffer;
-	int got_func = 0;
-
-
-	sprintf(script_path, "%s/get_funcs.sh", tmp_dir);
-	if (!(script_fd = fopen(script_path, "w"))) {
-		fprintf(stderr,
-			"itrace: ERROR creating %s\n", script_path);
-		goto lookup_funcs_result;
-	}
-	if (!fwrite(script_body, strlen(script_body), 1, script_fd)) {
-		fprintf(stderr,
-			"itrace: cannot create script: %s\n", script_path);
-		goto lookup_funcs_result;
-	}
-	fclose(script_fd);
-
-	if (chmod(script_path, S_IWUSR | S_IRUSR | S_IXUSR)) {
-		perror("itrace");
-		goto lookup_funcs_result;
-	}
-
-	sprintf(cmd, "%s %s %s ", script_path, prog, tmp_dir, tmp_dir);
-	for (i=0; i < num_funcs; i++) {
-		strcat(cmd, funcs[i].func);
-		strcat(cmd, " ");
-	}
-
-	if (system(cmd) != 0) {
-		fprintf(stderr, "itrace: command execution failed: %s\n", cmd);
-		goto lookup_funcs_result;
-	}
-
-	sprintf(result_path, "%s/func_addrs", tmp_dir);
-	if (!(result_fd = fopen(result_path, "r"))) {
-		fprintf(stderr,
-			"itrace: ERROR cannot open %s\n", result_path);
-		goto lookup_funcs_result;
-	}
-
-	while ((chars = getline(&lp, &n, result_fd)) > 0) {
-		char *func = index(lp, ' ');
-		char *addr = lp;
-
-		lp[chars-1] = 0;   /* terminate func string */
-		if (func) {
-			int func_index;
-			*func = 0; /* terminate addr string */
-			func += 1;
-			func_index = find_func(func);
-			if (func_index >= 0) {
-				funcs[func_index].addr = strinit(addr);
-			}
-		}
-			
-		
-	}
-
-	for (i=0; i < num_funcs; i++)
-		if (funcs[i].addr)
-			got_func = 1;
-		else
-			fprintf(stderr, "itrace: cannot find address for %s\n",
-				funcs[i].func);
-lookup_funcs_result:
-	fclose(result_fd);
-	return got_func;
-
-}
 
 void cleanup(void)
 {
@@ -411,8 +247,10 @@ void run_stap(void)
 	int status = 0;
 	int signum;
 	sigset_t sigset;
+	int arg_number = 0;
 	char *argv[100];
 	struct stat statbuf;
+	char argument[PATH_MAX + 3];
 
 	signal(SIGINT, sigint_handler);
 	sigemptyset(&sigset);
@@ -423,28 +261,39 @@ void run_stap(void)
 		perror ("fork");
 		return;
 	} else if (child_pid == 0) {	/* child */
+		if (trace_pid)
+			snprintf(argument, PATH_MAX + 3, "-x %s", trace_pid);
+		else
+			snprintf(argument, PATH_MAX + 3, "-c %s", prog);
 
-		printf("/usr/bin/stap -g %s -o %s %s \n",
-				generated_stap_file, output_name, trace_pid);
-		argv[0] = "stap";
-		argv[1] = "-g";
-		argv[2] = generated_stap_file;
-		argv[3] = "-o";
-		argv[4] = output_name;
-		argv[5] = trace_pid;
+		printf("/usr/bin/stap -g %s %s -o %s\n",
+		       argument, generated_stap_file, output_name);
+		argv[arg_number++] = "stap";
+		argv[arg_number++] = "-g";
+		if (trace_pid) {
+			argv[arg_number++] = "-x";
+			argv[arg_number++] = trace_pid;
+		} else {
+			argv[arg_number++] = "-c";
+			argv[arg_number++] = prog;
+		}
+		argv[arg_number++] = generated_stap_file;
+		argv[arg_number++] = "-o";
+		argv[arg_number++] = output_name;
 		for (i=0; i < num_stap_args; i++) {
-			argv[6+i] = stap_args[i];
+			argv[arg_number + i] = stap_args[i];
 			printf("%s ", stap_args[i]);
+			arg_number++;
 		}
 		putchar('\n');
-		argv[6+num_stap_args] = 0;
+		argv[arg_number + num_stap_args] = 0;
 		unlink(output_name);
 
 		signal(SIGINT, SIG_DFL);
 		printf("NOTE: If stap produces errors re-run with -vvvv option\n");
 		printf("To complete instruction tracing:\n");
 		printf("- check dmesg to wait for usr_itrace initialization completion\n");
-		printf("- continue program to be traced\n");
+		printf("- continue program to be traced (if necessary)\n");
 		printf("- hit ^C to terminate systemtap session when done tracing\n");
 		fflush(stdout);
 		if (execv("/usr/bin/stap", argv) < 0) {
@@ -491,26 +340,14 @@ int main (int argc, char * argv[])
 	}
 
 	check_options(argc, argv);
-	if (!trace_pid) {
-		fprintf(stderr, "itrace: --pid option required\n");
-		arg_error = 1;
-	}
-
-	if (num_funcs) {
-		if (!prog) {
-			fprintf(stderr,
-			"itrace: --prog option required with --func option\n");
-			arg_error = 1;
-		} else if (!lookup_funcs())
-			arg_error = 1;
-	}
 
-	if (num_addrs + num_funcs == 0) {
+	if (!num_funcs || !prog) {
 		fprintf(stderr,
-		"itrace: either --func or --addr option required\n");
+			"itrace: --prog and --func options required\n");
 		arg_error = 1;
 	}
 
+
 	if (keep)
 		printf("temp file directory= %s\n", tmp_dir);
 
@@ -538,6 +375,7 @@ int gen_stapfile(void)
 
 #define FPF(str) fprintf(stap_fd, str);
 #define FPF1(str, arg) fprintf(stap_fd, str, arg);
+#define FPF2(str, arg1, arg2) fprintf(stap_fd, str, arg1, arg2);
 FPF("%{\n");
 FPF("/* AUTOMATICALLY GENERATED SCRIPT FOR USER INSTRUCTION TRACING\n");
 FPF(" * Copyright (C) 2005, 2006, 2007 IBM Corp.\n");
@@ -547,15 +385,6 @@ FPF(" * Public License (GPL); either ver
 FPF(" * later version.\n");
 FPF(" */\n");
 FPF("\n");
-FPF("/*\n");
-FPF(" * This sample script for doing user space instruction tracing takes 1 argument,\n");
-FPF(" * the pid of the process you want to trace\n");
-FPF(" * To run the script:\n");
-FPF(" * 	stap -g itrace_it.stp <pid>n");
-FPF(" * where\n");
-FPF(" *	<pid> is the pid of the user program you are tracing\n");
-FPF(" *\n");
-FPF(" */\n");
 FPF("\n");
 FPF("#include <linux/sched.h>\n");
 FPF("#include <asm/ptrace.h>\n");
@@ -580,6 +409,7 @@ FPF("%{\n");
 FPF("	THIS->__retvalue = (u64)&pi_itrace_create_task;\n");
 FPF("%}\n");
 FPF("\n");
+FPF("global trace_tid\n");
 FPF("probe begin\n");
 FPF("{\n");
 FPF("	ppc_usr_itrace_init()\n");
@@ -595,18 +425,16 @@ FPF("}\n");
 FPF("\n");
 FPF("\n");
 
-		for (i=0; i < num_funcs; i++)
-			if (funcs[i].addr) {
-FPF1("probe process($1).statement(%s).absolute ", funcs[i].addr);
-FPF1("// %s\n", funcs[i].func);
+		for (i=0; i < num_funcs; i++) {
+FPF2("probe process(\"%s\").function(\"%s\")", prog, funcs[i]);
 FPF("{\n");
-FPF("	if (usr_itrace_on(tid()) < 0)\n");
+FPF("   trace_tid = tid()\n");
+FPF("	if (usr_itrace_on(trace_tid) < 0)\n");
 FPF("		exit()\n");
-FPF("	pi_itrace_on(tid())\n");
+FPF("	pi_itrace_on(trace_tid)\n");
 FPF("}\n");
 FPF("\n");
-FPF1("probe process($1).statement(%s).absolute.return ", funcs[i].addr);
-FPF1(" // %s\n", funcs[i].func);
+FPF2("probe process(\"%s\").function(\"%s\").return ", prog, funcs[i]);
 FPF("{\n");
 FPF("	usr_itrace_off(tid())\n");
 FPF("	pi_itrace_off()\n");
@@ -614,25 +442,10 @@ FPF("}\n");
 FPF("\n");
 			}
 
-	for (i=0; i < num_addrs; i++) {
-FPF1("probe process($1).statement(0x%lx).absolute\n", addrs[i].lo);
-FPF("{\n");
-FPF("	if (usr_itrace_on(tid()) < 0)\n");
-FPF("		exit()\n");
-FPF("	pi_itrace_on(tid())\n");
-FPF("}\n");
-FPF("\n");
-FPF1("probe process($1).statement(0x%lx).absolute\n", addrs[i].hi);
-FPF("{\n");
-FPF("	usr_itrace_off(tid())\n");
-FPF("	pi_itrace_off()\n");
-FPF("}\n");
-FPF("\n");
-	}
 if (debuginfo) {
 FPF("probe kernel.function(\"do_exit\")\n");
 FPF("{\n");
-FPF("	if (pid() == $1)\n");
+FPF("	if (tid() == trace_tid)\n");
 FPF("		exit()\n");
 FPF("}\n");
 }
diff -paur Dpiperf/src/stap/usr_itrace.stp Dpiperf-fixed/src/stap/usr_itrace.stp
--- Dpiperf/src/stap/usr_itrace.stp	2008-12-10 19:42:55.000000000 -0500
+++ Dpiperf-fixed/src/stap/usr_itrace.stp	2008-12-03 16:30:47.000000000 -0500
@@ -262,7 +262,7 @@ void static remove_usr_itrace_info(struc
 	spin_lock(&itrace_lock);
 	if (ui->tsk && ui->engine) {
 		status = utrace_control(ui->tsk, ui->engine, UTRACE_DETACH);
-		if (status < 0)
+		if (status < 0 && status != -ESRCH)
 			printk(KERN_ERR
 				 "utrace_control(UTRACE_DETACH) returns %d\n",
 				status);


Index: stapitrace.spec
===================================================================
RCS file: /cvs/pkgs/rpms/stapitrace/F-10/stapitrace.spec,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- stapitrace.spec	23 Oct 2008 17:43:42 -0000	1.19
+++ stapitrace.spec	15 Dec 2008 22:18:57 -0000	1.20
@@ -6,7 +6,7 @@
 Name:		stapitrace
 Summary:	Instruction Tracing Tool
 Version:	1.0.0
-Release:	19.%{alphatag}%{?dist}
+Release:	20.%{alphatag}%{?dist}
 License:	GPLv2+
 Group:		Development/Tools
 URL:		http://sourceforge.net/projects/perfinsp
@@ -14,6 +14,7 @@
 Patch0:		itrace_fix1.patch
 Patch1:		stapitrace-fix-bfd-configure.patch
 Patch2:		stapitrace-utrace2.patch
+Patch3: 	it-update.patch
 BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root
 Requires:	systemtap systemtap-runtime binutils binutils-devel
 BuildRequires:	binutils binutils-devel autoconf automake zlib-devel
@@ -40,6 +41,7 @@
 %patch0 -p1
 %patch1 -p1
 %patch2 -p1
+%patch3 -p1
 
 %build
 autoreconf -i --force
@@ -87,6 +89,9 @@
 %{_bindir}/itrace
 
 %changelog -n itrace
+* Fri Dec 12 2008 Maynard Johnson <maynardj at us.ibm.com>
+- updates to match SystemTap 0.8
+
 * Wed Oct 15 2008 Dave Nomura <dcnltc at us.ibm.com>
 - upgrade to utrace2
 




More information about the fedora-extras-commits mailing list