This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH v2] Fix a bug in atvar_op::print: we did not output the module arg
- From: "Yichun Zhang (agentzh)" <agentzh at gmail dot com>
- To: systemtap at sourceware dot org
- Cc: "Yichun Zhang (agentzh)" <agentzh at gmail dot com>
- Date: Wed, 22 Aug 2018 23:09:43 -0700
- Subject: [PATCH v2] Fix a bug in atvar_op::print: we did not output the module arg
- References: <20180804075052.33628-1-agentzh@gmail.com>
This was an issue left by commit bd1fcba. My bad.
Also added some tests to cover this fix.
---
staptree.cxx | 5 +-
testsuite/systemtap.base/at_var_print.exp | 74 +++++++++++++++++++++++++++++
testsuite/systemtap.base/at_var_print_1.c | 5 ++
testsuite/systemtap.base/at_var_print_1.stp | 8 ++++
testsuite/systemtap.base/at_var_print_2.stp | 4 ++
5 files changed, 95 insertions(+), 1 deletion(-)
create mode 100644 testsuite/systemtap.base/at_var_print.exp
create mode 100644 testsuite/systemtap.base/at_var_print_1.c
create mode 100644 testsuite/systemtap.base/at_var_print_1.stp
create mode 100644 testsuite/systemtap.base/at_var_print_2.stp
diff --git a/staptree.cxx b/staptree.cxx
index 8c791675d..d1193e336 100644
--- a/staptree.cxx
+++ b/staptree.cxx
@@ -520,7 +520,10 @@ void atvar_op::print (ostream& o) const
{
if (addressof)
o << "&";
- o << name << "(\"" << target_name << "\")";
+ o << name << "(\"" << target_name << "\"";
+ if (module.length() > 0)
+ o << ", " << lex_cast_qstring (module);
+ o << ')';
for (unsigned i = 0; i < components.size(); ++i)
o << components[i];
}
diff --git a/testsuite/systemtap.base/at_var_print.exp b/testsuite/systemtap.base/at_var_print.exp
new file mode 100644
index 000000000..03c686f2f
--- /dev/null
+++ b/testsuite/systemtap.base/at_var_print.exp
@@ -0,0 +1,74 @@
+set test "at_var_print"
+set testpath "$srcdir/$subdir"
+
+# Only run on make installcheck and uprobes present.
+if {! [installtest_p]} { untested "$test"; return }
+if {! [uretprobes_p]} { untested "$test"; return }
+
+# --- TEST 1 ---
+
+set subtest1 "TEST 1: atvar_op::print() output the module arg properly."
+
+set out_pat "\\yreturn \\@var\\(\"v\", \"\[^\\n\"]+/a\\.out\"\\);"
+
+set res [target_compile ${testpath}/${test}_1.c ./a.out executable \
+ "additional_flags=-O additional_flags=-g"]
+if {$res ne ""} {
+ verbose "target_compile failed: $res" 2
+ fail "${subtest1}: unable to compile ${test}_1.c"
+} else {
+ set cmd "stap -p1 -c ./a.out '$srcdir/$subdir/${test}_1.stp'"
+ set pipe [open "| sh -c {$cmd}" r]
+ set out [read $pipe]
+ set is_err 0
+ if {[catch {close $pipe} stderr] != 0} { set is_err 1 }
+
+ if {[regexp -lineanchor -- $out_pat $out]} {
+ pass "${subtest1}: output matches \"$out_pat\""
+ } else {
+ fail "${subtest1}: output fails to match \"$out_pat\": Got \"$out\""
+ }
+
+ if {$is_err} {
+ fail "${subtest1}: exit code not zero"
+ } else {
+ pass "${subtest1}: exit code is zero"
+ }
+ if {$stderr ne ""} {
+ send_log "stderr:\n$stderr"
+ }
+}
+
+# --- TEST 2 ---
+
+set subtest2 "TEST 2: atvar_op::print() does not output the module arg if there is none"
+
+set out_pat "\\yprintln\\(\\@var\\(\"v\"\\)\\);"
+
+set res [target_compile ${testpath}/${test}_1.c ./a.out executable \
+ "additional_flags=-O additional_flags=-g"]
+if {$res ne ""} {
+ verbose "target_compile failed: $res" 2
+ fail "${subtest2}: unable to compile ${test}_1.c"
+} else {
+ set cmd "stap -p1 -c ./a.out '$srcdir/$subdir/${test}_2.stp'"
+ set pipe [open "| sh -c {$cmd}" r]
+ set out [read $pipe]
+ set is_err 0
+ if {[catch {close $pipe} stderr] != 0} { set is_err 1 }
+
+ if {[regexp -lineanchor -- $out_pat $out]} {
+ pass "${subtest2}: output matches \"$out_pat\""
+ } else {
+ fail "${subtest2}: output fails to match \"$out_pat\": Got \"$out\""
+ }
+
+ if {$is_err} {
+ fail "${subtest2}: exit code not zero"
+ } else {
+ pass "${subtest2}: exit code is zero"
+ }
+ if {$stderr ne ""} {
+ send_log "stderr:\n$stderr"
+ }
+}
diff --git a/testsuite/systemtap.base/at_var_print_1.c b/testsuite/systemtap.base/at_var_print_1.c
new file mode 100644
index 000000000..8c3b7bc46
--- /dev/null
+++ b/testsuite/systemtap.base/at_var_print_1.c
@@ -0,0 +1,5 @@
+long v = 0xbeefdead;
+
+int main(void) {
+ return 0;
+}
diff --git a/testsuite/systemtap.base/at_var_print_1.stp b/testsuite/systemtap.base/at_var_print_1.stp
new file mode 100644
index 000000000..423bd7c44
--- /dev/null
+++ b/testsuite/systemtap.base/at_var_print_1.stp
@@ -0,0 +1,8 @@
+function f() {
+ return @var("v", "$^PWD/a.out");
+}
+
+probe process.function("main") {
+ println(f());
+ exit();
+}
diff --git a/testsuite/systemtap.base/at_var_print_2.stp b/testsuite/systemtap.base/at_var_print_2.stp
new file mode 100644
index 000000000..508896770
--- /dev/null
+++ b/testsuite/systemtap.base/at_var_print_2.stp
@@ -0,0 +1,4 @@
+probe process.function("main") {
+ println(@var("v"));
+ exit();
+}
--
2.11.0.295.gd7dffce