summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tapset-utrace.cxx125
-rw-r--r--testsuite/systemtap.base/utrace_p4.exp19
-rw-r--r--testsuite/systemtap.base/utrace_p5.exp22
3 files changed, 125 insertions, 41 deletions
diff --git a/tapset-utrace.cxx b/tapset-utrace.cxx
index ec20282a..a3a4ca3d 100644
--- a/tapset-utrace.cxx
+++ b/tapset-utrace.cxx
@@ -407,54 +407,97 @@ utrace_var_expanding_visitor::visit_target_symbol_cached (target_symbol* e)
void
utrace_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e)
{
- string argnum_s = e->base_name.substr(4,e->base_name.length()-4);
- int argnum = lex_cast<int>(argnum_s);
-
if (flags != UDPF_SYSCALL)
- throw semantic_error ("only \"process(PATH_OR_PID).syscall\" support $argN.", e->tok);
+ throw semantic_error ("only \"process(PATH_OR_PID).syscall\" support $argN or $$parms.", e->tok);
- if (e->components.size() > 0)
+ if (e->base_name == "$$parms")
{
- switch (e->components[0].first)
- {
- case target_symbol::comp_literal_array_index:
- throw semantic_error("utrace target variable '$argN' may not be used as array",
- e->tok);
- break;
- case target_symbol::comp_struct_member:
- throw semantic_error("utrace target variable '$argN' may not be used as a structure",
- e->tok);
- break;
- default:
- throw semantic_error ("invalid use of utrace target variable '$argN'",
- e->tok);
- break;
- }
- }
+ // copy from tracepoint
+ print_format* pf = new print_format;
+ token* pf_tok = new token(*e->tok);
+ pf_tok->content = "sprintf";
+ pf->tok = pf_tok;
+ pf->print_to_stream = false;
+ pf->print_with_format = true;
+ pf->print_with_delim = false;
+ pf->print_with_newline = false;
+ pf->print_char = false;
+
+ target_symbol_seen = true;
+
+ for (unsigned i = 0; i < 6; ++i)
+ {
+ if (i > 0)
+ pf->raw_components += " ";
+ pf->raw_components += "$arg" + lex_cast<string>(i+1);
+ target_symbol *tsym = new target_symbol;
+ tsym->tok = e->tok;
+ tsym->base_name = "$arg" + lex_cast<string>(i+1);
+ tsym->saved_conversion_error = 0;
+ pf->raw_components += "=%#x"; //FIXME: missing type info
+
+ functioncall* n = new functioncall; //same as the following
+ n->tok = e->tok;
+ n->function = "_utrace_syscall_arg";
+ n->referent = 0;
+ literal_number *num = new literal_number(i);
+ num->tok = e->tok;
+ n->args.push_back(num);
+
+ pf->args.push_back(n);
+ }
+ pf->components = print_format::string_to_components(pf->raw_components);
+
+ provide (pf);
+ }
+ else // $argN
+ {
+ string argnum_s = e->base_name.substr(4,e->base_name.length()-4);
+ int argnum = lex_cast<int>(argnum_s);
+
+ if (e->components.size() > 0)
+ {
+ switch (e->components[0].first)
+ {
+ case target_symbol::comp_literal_array_index:
+ throw semantic_error("utrace target variable '$argN' may not be used as array",
+ e->tok);
+ break;
+ case target_symbol::comp_struct_member:
+ throw semantic_error("utrace target variable '$argN' may not be used as a structure",
+ e->tok);
+ break;
+ default:
+ throw semantic_error ("invalid use of utrace target variable '$argN'",
+ e->tok);
+ break;
+ }
+ }
- // FIXME: max argnument number should not be hardcoded.
- if (argnum < 1 || argnum > 6)
- throw semantic_error ("invalid syscall argument number (1-6)", e->tok);
+ // FIXME: max argnument number should not be hardcoded.
+ if (argnum < 1 || argnum > 6)
+ throw semantic_error ("invalid syscall argument number (1-6)", e->tok);
- bool lvalue = is_active_lvalue(e);
- if (lvalue)
- throw semantic_error("utrace '$argN' variable is read-only", e->tok);
+ bool lvalue = is_active_lvalue(e);
+ if (lvalue)
+ throw semantic_error("utrace '$argN' variable is read-only", e->tok);
- // Remember that we've seen a target variable.
- target_symbol_seen = true;
+ // Remember that we've seen a target variable.
+ target_symbol_seen = true;
- // We're going to substitute a synthesized '_utrace_syscall_arg'
- // function call for the '$argN' reference.
- functioncall* n = new functioncall;
- n->tok = e->tok;
- n->function = "_utrace_syscall_arg";
- n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session
+ // We're going to substitute a synthesized '_utrace_syscall_arg'
+ // function call for the '$argN' reference.
+ functioncall* n = new functioncall;
+ n->tok = e->tok;
+ n->function = "_utrace_syscall_arg";
+ n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session
- literal_number *num = new literal_number(argnum - 1);
- num->tok = e->tok;
- n->args.push_back(num);
+ literal_number *num = new literal_number(argnum - 1);
+ num->tok = e->tok;
+ n->args.push_back(num);
- provide (n);
+ provide (n);
+ }
}
void
@@ -542,12 +585,12 @@ utrace_var_expanding_visitor::visit_target_symbol (target_symbol* e)
if (e->addressof)
throw semantic_error("cannot take address of utrace variable", e->tok);
- if (e->base_name.substr(0,4) == "$arg")
+ if (e->base_name.substr(0,4) == "$arg" || e->base_name == "$$parms")
visit_target_symbol_arg(e);
else if (e->base_name == "$syscall" || e->base_name == "$return")
visit_target_symbol_context(e);
else
- throw semantic_error ("invalid target symbol for utrace probe, $syscall, $return or $argN expected",
+ throw semantic_error ("invalid target symbol for utrace probe, $syscall, $return, $argN or $$parms expected",
e->tok);
}
diff --git a/testsuite/systemtap.base/utrace_p4.exp b/testsuite/systemtap.base/utrace_p4.exp
index 8d323a8a..c76503cb 100644
--- a/testsuite/systemtap.base/utrace_p4.exp
+++ b/testsuite/systemtap.base/utrace_p4.exp
@@ -10,6 +10,7 @@
set begin_script {"probe process(\"/bin/ls\").begin { print(\"ls begin\") }"}
set end_script {"probe process(\"/bin/ls\").end { print(\"ls end\") }"}
set syscall_script {"probe process(\"/bin/ls\").syscall { printf(\"|%d\", \$syscall) }"}
+set syscall_parms_script {"probe process(\"/bin/ls\").syscall { printf(\"|%s\", \$\$parms) }"}
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\") }"}
@@ -18,6 +19,7 @@ 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\") }"}
set pid_syscall_script {"probe process(123).syscall { printf(\"|%d\", \$syscall) }"}
+set pid_parms_script {"probe process(123).syscall { printf(\"|%s\", \$\$parms) }"}
set pid_syscall_return_script {"probe process(123).syscall.return { printf(\"|%d\", \$syscall) }"}
set pid_thread_begin_script {"probe process(123).thread.begin { print(\"123 thread.begin\") }"}
set pid_thread_end_script {"probe process(123).thread.end { print(\"123 thread.end\") }"}
@@ -129,3 +131,20 @@ if {![utrace_p]} {
# Try compiling an system-wide begin script
stap_compile $TEST_NAME 1 $all_begin_script
}
+
+set TEST_NAME "UTRACE_P4_08"
+if {![utrace_p]} {
+ untested "$TEST_NAME : no kernel utrace support found"
+} else {
+ # Try compiling a syscall parms script using a path
+ stap_compile $TEST_NAME 1 $syscall_parms_script
+}
+
+set TEST_NAME "UTRACE_P4_09"
+if {![utrace_p]} {
+ untested "$TEST_NAME : no kernel utrace support found"
+} else {
+ # Try compiling a syscall parms script using a pid
+ stap_compile $TEST_NAME 1 $pid_parms_script
+}
+
diff --git a/testsuite/systemtap.base/utrace_p5.exp b/testsuite/systemtap.base/utrace_p5.exp
index 3d432dc3..7062bc0d 100644
--- a/testsuite/systemtap.base/utrace_p5.exp
+++ b/testsuite/systemtap.base/utrace_p5.exp
@@ -89,6 +89,18 @@ set bz6841_script {
}
set bz6841_script_output ".+ issues syscall \\d+ times\r\n"
+set syscall_parms_script {
+ global syscall_parms_string
+ probe begin { printf("systemtap starting probe\n") }
+ probe process.syscall { syscall_parms_string = $$parms exit() }
+ probe end { printf("systemtap ending probe\n")
+ printf("%s\n",syscall_parms_string)
+ delete syscall_parms_string
+ }
+}
+set syscall_parms_script_output "(.+arg\[1-6\]=0x\[0-9a-f\]+)+\r\n"
+
+
# Set up our own copy of /bin/cat, to make testing for a particular
# executable easy. We can't use 'ln' here, since we might be creating
# a cross-device link. We can't use 'ln -s' here, since the kernel
@@ -202,5 +214,15 @@ if {![utrace_p]} {
-e $bz6841_script
}
+set TEST_NAME "UTRACE_P5_08"
+if {![utrace_p]} {
+ untested "$TEST_NAME : no kernel utrace support found"
+} elseif {![installtest_p]} {
+ untested "$TEST_NAME"
+} else {
+ set script [format $syscall_parms_script "%s"]
+ stap_run $TEST_NAME no_load $syscall_parms_script_output -e $script
+}
+
# Cleanup
exec rm -f $exepath $multi_exepath