From 6cdf2889024b6538665a00f2ecd7321626624bb8 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 12 Aug 2008 10:18:56 -0500 Subject: [PATCH] PR 6445 (partial). Implemented system-wide utrace probes. 2008-08-12 David Smith PR 6445 (partial) * tapsets.cxx (utrace_builder::build): Validates pid and allows probing of "*" to mean all threads. * stapprobes.5.in: Added note about a process path of "*" means to probe all threads. 2008-08-12 David Smith PR 6445 (partial) * task_finder.c (stap_register_task_finder_target): Handles probing all threads. (__stp_utrace_attach_match_filename): Ditto. (stap_start_task_finder): Ditto. 2008-08-12 David Smith PR 6445 (partial) * systemtap.base/utrace_p4.exp: Added test that probes all threads. * semko/utrace14.stp: New test. --- ChangeLog | 8 ++++++ runtime/ChangeLog | 8 ++++++ runtime/task_finder.c | 38 ++++++++++++++++---------- stapprobes.5.in | 3 ++ tapsets.cxx | 21 ++++++++++++-- testsuite/ChangeLog | 6 ++++ testsuite/semko/utrace14.stp | 4 +++ testsuite/systemtap.base/utrace_p4.exp | 9 ++++++ 8 files changed, 81 insertions(+), 16 deletions(-) create mode 100755 testsuite/semko/utrace14.stp diff --git a/ChangeLog b/ChangeLog index d6226d2d3..4432ece4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-08-12 David Smith + + PR 6445 (partial) + * tapsets.cxx (utrace_builder::build): Validates pid and allows + probing of "*" to mean all threads. + * stapprobes.5.in: Added note about a process path of "*" means to + probe all threads. + 2008-08-11 Wenji Huang * tapsets.cxx : Fixed compilation warning on gcc 3.x. diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 7dfade1cc..7ec5d4535 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,11 @@ +2008-08-12 David Smith + + PR 6445 (partial) + * task_finder.c (stap_register_task_finder_target): Handles + probing all threads. + (__stp_utrace_attach_match_filename): Ditto. + (stap_start_task_finder): Ditto. + 2008-08-08 David Smith * task_finder.c (stap_utrace_detach): New function. diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 1832c7954..263757805 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -130,8 +130,10 @@ stap_register_task_finder_target(struct stap_task_finder_target *new_tgt) && ((new_tgt->pathlen > 0 && tgt->pathlen == new_tgt->pathlen && strcmp(tgt->pathname, new_tgt->pathname) == 0) - /* pid-based target */ - || (new_tgt->pid != 0 && tgt->pid == new_tgt->pid))) { + /* pid-based target (a specific pid or all + * pids) */ + || (new_tgt->pathlen == 0 + && tgt->pid == new_tgt->pid))) { found_node = 1; break; } @@ -375,23 +377,29 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk, size_t filelen; struct list_head *tgt_node; struct stap_task_finder_target *tgt; - int found_node = 0; filelen = strlen(filename); list_for_each(tgt_node, &__stp_task_finder_list) { + struct list_head *cb_node; + tgt = list_entry(tgt_node, struct stap_task_finder_target, list); - // Note that we don't bother with looking for pids - // here, since they are handled at startup. - if (tgt != NULL && tgt->pathlen > 0 - && tgt->pathlen == filelen - && strcmp(tgt->pathname, filename) == 0) { - found_node = 1; - break; - } - } - if (found_node) { - struct list_head *cb_node; + // If we've got a matching pathname or we're probing + // all threads, we've got a match. We've got to keep + // matching since a single thread could match a + // pathname and match an "all thread" probe. + if (tgt == NULL) + continue; + else if (tgt->pathlen > 0 + && (tgt->pathlen != filelen + || strcmp(tgt->pathname, filename) != 0)) + continue; + /* Ignore pid-based target, they were handled at startup. */ + else if (tgt->pid != 0) + continue; + /* Notice that "pid == 0" (which means to probe all + * threads) falls through. */ + list_for_each(cb_node, &tgt->callback_list_head) { struct stap_task_finder_target *cb_tgt; int rc; @@ -1030,6 +1038,8 @@ stap_start_task_finder(void) /* pid-based target */ else if (tgt->pid != 0 && tgt->pid != tsk->pid) continue; + /* Notice that "pid == 0" (which means to + * probe all threads) falls through. */ list_for_each(cb_node, &tgt->callback_list_head) { struct stap_task_finder_target *cb_tgt; diff --git a/stapprobes.5.in b/stapprobes.5.in index d20ea006f..c71f79d3e 100644 --- a/stapprobes.5.in +++ b/stapprobes.5.in @@ -423,6 +423,9 @@ Note that names refer to executables that are searched the same way shells do: relative to the working directory if they contain a "/" character, otherwise in .BR $PATH . +A +.I PATH +of "*" means to probe all threads. .SS PROCFS diff --git a/tapsets.cxx b/tapsets.cxx index 6dcd2c001..664dfb1f9 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -5931,8 +5931,25 @@ struct utrace_builder: public derived_probe_builder else if (has_null_param (parameters, TOK_END)) flags = UDPF_END; - // If we have a path, we need to validate it. - if (has_path) + // Validate pid. + if (has_pid) + { + // We can't probe 'init' (pid 1). + if (pid < 2) + throw semantic_error ("process pid must be greater than 1", + location->tok); + } + // If we have a path whose value is "*", this means to probe + // everything. Convert this to a pid-based probe. + else if (has_path && path == "*") + { + has_path = false; + path.clear(); + has_pid = true; + pid = 0; + } + // If we have a regular path, we need to validate it. + else if (has_path) { string::size_type start_pos, end_pos; string component; diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 405dd7546..ad393ac40 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-08-12 David Smith + + PR 6445 (partial) + * systemtap.base/utrace_p4.exp: Added test that probes all threads. + * semko/utrace14.stp: New test. + 2008-08-11 Frank Ch. Eigler * systemtap.base/vars.exp: Adjust to loss of "\n" at end of $$vars diff --git a/testsuite/semko/utrace14.stp b/testsuite/semko/utrace14.stp new file mode 100755 index 000000000..80847f7f4 --- /dev/null +++ b/testsuite/semko/utrace14.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# pid can't be less than 2 +probe process(1).begin { } diff --git a/testsuite/systemtap.base/utrace_p4.exp b/testsuite/systemtap.base/utrace_p4.exp index 3083b97fd..081fee95a 100644 --- a/testsuite/systemtap.base/utrace_p4.exp +++ b/testsuite/systemtap.base/utrace_p4.exp @@ -15,6 +15,7 @@ set syscall_script {"probe process(\"/bin/ls\").syscall { printf(\"|%d\", \$sysc set syscall_return_script {"probe process(\"/bin/ls\").syscall.return { printf(\"|%d\", \$syscall) }"} set thread_begin_script {"probe process(\"/bin/ls\").thread.begin { print(\"ls thread.begin\") }"} set thread_end_script {"probe process(\"/bin/ls\").thread.end { print(\"ls thread.end\") }"} +set all_begin_script {"probe process(\"*\").begin { print(\"begin\") }"} set pid_begin_script {"probe process(123).begin { print(\"123 begin\") }"} set pid_end_script {"probe process(123).end { print(\"123 end\") }"} @@ -128,3 +129,11 @@ if {$utrace_support_found == 0} { # Try compiling an thread.end script using a pid stap_compile $TEST_NAME 1 $pid_thread_end_script } + +set TEST_NAME "UTRACE_P4_07" +if {$utrace_support_found == 0} { + untested "$TEST_NAME : no kernel utrace support found" +} else { + # Try compiling an begin script using a path of "*" + stap_compile $TEST_NAME 1 $all_begin_script +} -- 2.43.5