From 37c610c57c328844b6c7197acec59471686ef978 Mon Sep 17 00:00:00 2001 From: Abegail Jakop Date: Fri, 25 Jul 2014 14:41:55 -0400 Subject: [PATCH] PR17101: updated docs and added a test case --- NEWS | 11 ++ man/stap.1 | 5 + session.cxx | 2 + .../systemtap.base/additional_scripts.exp | 120 ++++++++++++++++++ .../systemtap.base/additional_scripts.stp | 1 + 5 files changed, 139 insertions(+) create mode 100644 testsuite/systemtap.base/additional_scripts.exp create mode 100644 testsuite/systemtap.base/additional_scripts.stp diff --git a/NEWS b/NEWS index 07029d3ee..db786fab8 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,17 @@ process(PID).function("*") +- SystemTap now accepts additional scripts through the new -E SCRIPT option. + There still needs to be a main script specified through -e or file in order + to provide an additional script. This makes it feasible to have scripts in + the $HOME/.systemtap/rc file. Such a script could be, for example: + + -E 'probe begin, end, error { log("systemtap script " . pn()) }' + + The -E SCRIPT option can also be used in lisitng mode (-l/-L), such that + probe points for the additional scripts will not listed, but other parts of + the script are still available, such as macros or aliases. + * What's new in version 2.5, 2014-04-30 - Systemtap now supports backtracing through its own, invoking module. diff --git a/man/stap.1 b/man/stap.1 index c2ce04e66..38312039d 100644 --- a/man/stap.1 +++ b/man/stap.1 @@ -259,6 +259,11 @@ a specific process. Scripts run independent of the PID's lifespan. .BI \-e " SCRIPT" Run the given SCRIPT specified on the command line. .TP +.BI \-E " SCRIPT" +Run the given SCRIPT specified. This SCRIPT is run in addition to the main +script specified, through -e, or as a script file. This option can be repeated +to run multiple scripts, and can be used in listing mode (\-l/\-L). +.TP .BI \-l " PROBE" Instead of running a probe script, just list all available probe points matching the given single probe point. The pattern may include diff --git a/session.cxx b/session.cxx index f01ce8f43..56198ef53 100644 --- a/session.cxx +++ b/session.cxx @@ -559,6 +559,8 @@ systemtap_session::usage (int exitcode) " %s\n" " -o FILE send script output to file, instead of stdout. This supports\n" " strftime(3) formats for FILE\n" + " -E SCRIPT run the SCRIPT in addition to the main script specified\n" + " through -e or a script file\n" " -c CMD start the probes, run CMD, and exit when it finishes\n" " -x PID sets target() to PID\n" " -F run as on-file flight recorder with -o.\n" diff --git a/testsuite/systemtap.base/additional_scripts.exp b/testsuite/systemtap.base/additional_scripts.exp new file mode 100644 index 000000000..6e88b4e2e --- /dev/null +++ b/testsuite/systemtap.base/additional_scripts.exp @@ -0,0 +1,120 @@ +set test_name additional_scripts + +# test scripts and arguements +set script1 { "probe begin\{printf(\"beginning\")\}" } +set script2 { "probe process.begin\{printf(\"%s\", \$1)\}" } +set timeout_script { "probe timer.s(15) \{ printf(\"ending\") exit ()\}" } +set script_alias { "probe pb=process.begin {exit();} probe process.end{exit();}" } +set bad_script { "probe pppppppp.begin { exit(); }" } +set script_file "$srcdir/$subdir/$test_name.stp" +set arg1 { "\"hello\"" } + +# running test scripts +# -E and no -e or script file +# -E is for additional scripts. a "main" script or script file must be given +eval spawn stap -v -E $timeout_script +expect { + -timeout 60 + -re {A script must be specified} { pass "$test_name (no script)" } + eof { fail "$test_name (no script)" } +} + +# -E BAD_SCRIPT, where BAD_SCRIPT causes a semantic error +eval spawn stap -v -e $script1 -E $bad_script +set success 0 +expect { + -timeout 120 + -re {semantic error[ A-Za-z:]+'pppppppp'} { set success 1 } +} +if { $success == 1 } { pass "$test_name (-E BAD_SCRIPT) " } { fail "$test_name (-E BAD_SCRIPT)" } + +# -E SCRIPT, +eval spawn stap -v -e $script1 -E $timeout_script +set success 0 +expect { + -timeout 120 + -re {beginning} { + set success 1 + verbose -log "saw:beginning" + exp_continue + } + -re {ending} { + if { $success == 1 } { + verbose -log "saw:ending" + set success 2 + } + exp_continue + } +} +if { $success == 2 } { pass "$test_name (-e and -E ) " } { fail "$test_name (-e and -E)" } + +# script file and -E +eval spawn stap -v $script_file -E $timeout_script +set success 0 +expect { + -timeout 120 + -re {a process began} { + if { $success == 0 } { + verbose -log "\nsaw:a process began" + set success 1 + } + exp_continue + } + -re {ending} { + if { $success == 1 } { + set success 2 + verbose -log "\nsaw:ending" + } + exp_continue + } +} +if { $success == 2 } { pass "$test_name (file and -E ) " } { fail "$test_name (file and -E)" } + +# multiple -E, with an argument mixed in there +eval spawn stap -v -e $script2 -E $script1 -E $timeout_script $arg1 +set success 0 +expect { + -timeout 120 + -re {beginning} { + set success 1 + verbose -log "\nsaw:beginning" + exp_continue + } + -re {hello} { + if { $success == 1 } { + verbose -log "\nsaw:hello" + set success 2 + } + exp_continue + } + -re {ending} { + if { $success == 2 } { + set success 3 + verbose -log "\nsaw:ending" + } + exp_continue + } +} +if { $success == 3 } { pass "$test_name (multiple -E ) " } { fail "$test_name (multiple -E)" } + +# -E, with probe point listing +eval spawn stap -l "pb" -E $script_alias +set success 0 +expect { + -timeout 120 + -re {pb} { if { $success == 0 } { set success 1 } } + -re {process.begin} { if { $success == 0 } { set success 1 } } + -re {process.end} { set success 4 } +} +if { $success == 1 } { pass "$test_name (-E listing probes) " } { fail "$test_name (-E listing probes)" } + +# -E BAD_SCRIPT when listing probes. should still list the proper probe pts +eval spawn stap -l "pb" -E $script_alias -E $bad_script +set success 0 +expect { + -timeout 120 + -re {pb} { if { $success == 0 } { set success 1 } } + -re {process.begin} { if { $success == 0 } { set success 1 } } + -re {process.end} { set success 4 } +} +if { $success == 1 } { pass "$test_name (-E BAD_SCRIPT listing probes) " } { fail "$test_name (-E BAD_SCRIPT listing probes)" } diff --git a/testsuite/systemtap.base/additional_scripts.stp b/testsuite/systemtap.base/additional_scripts.stp new file mode 100644 index 000000000..8b6158cb2 --- /dev/null +++ b/testsuite/systemtap.base/additional_scripts.stp @@ -0,0 +1 @@ +probe process.begin{printf("a process began")} -- 2.43.5