public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] PR23799 - sprint_ustack() always returns empty string values
@ 2018-10-19 22:05 Yichun Zhang (agentzh)
  2018-10-19 22:10 ` Yichun Zhang
  0 siblings, 1 reply; 2+ messages in thread
From: Yichun Zhang (agentzh) @ 2018-10-19 22:05 UTC (permalink / raw)
  To: systemtap; +Cc: Yichun Zhang (agentzh)

The tapset function sprint_ustack() forgot to actually return
the computed string value. Alas.
---
 tapset/linux/ucontext-symbols.stp     |  2 +-
 testsuite/systemtap.base/ustack.exp   | 49 +++++++++++++++++++++++++++++++++++
 testsuite/systemtap.base/ustack_1.c   | 12 +++++++++
 testsuite/systemtap.base/ustack_1.stp |  3 +++
 testsuite/systemtap.base/ustack_2.stp |  3 +++
 5 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 testsuite/systemtap.base/ustack.exp
 create mode 100644 testsuite/systemtap.base/ustack_1.c
 create mode 100644 testsuite/systemtap.base/ustack_1.stp
 create mode 100644 testsuite/systemtap.base/ustack_2.stp

diff --git a/tapset/linux/ucontext-symbols.stp b/tapset/linux/ucontext-symbols.stp
index 95ea33d18..f1eb61c50 100644
--- a/tapset/linux/ucontext-symbols.stp
+++ b/tapset/linux/ucontext-symbols.stp
@@ -137,7 +137,7 @@ function print_usyms (callers:string) {
  *
  * NOTE: it is recommended to use sprint_usyms() instead of this function.
  */
-function sprint_ustack:string(stk:string) { sprint_usyms(stk) }
+function sprint_ustack:string(stk:string) { return sprint_usyms(stk) }
 
 /**
  * sfunction sprint_usyms - Return stack for user addresses from string
diff --git a/testsuite/systemtap.base/ustack.exp b/testsuite/systemtap.base/ustack.exp
new file mode 100644
index 000000000..30671326a
--- /dev/null
+++ b/testsuite/systemtap.base/ustack.exp
@@ -0,0 +1,49 @@
+set test "ustack"
+set testpath "$srcdir/$subdir"
+
+if {! [installtest_p]} { untested $test; return }
+if {! [uretprobes_p]} { untested $test; return }
+
+# --- TEST 1 ---
+
+set subtest1 "TEST 1: PR23799: sprint_ustack() returns empty strings"
+
+set res [target_compile ${testpath}/${test}_1.c ./a.out executable \
+    "additional_flags=-O additional_flags=-g additional_flags=-O0"]
+if {$res ne ""} {
+    verbose "target_compile failed: $res" 2
+    fail "$test: $subtest1: unable to compile ${test}_1.c"
+} else {
+    set test_name "$test: $subtest1"
+
+    set cmd "stap --ldd -c ./a.out '$srcdir/$subdir/${test}_1.stp'"
+    set exit_code [run_cmd_2way $cmd out stderr]
+    set out_pat " : foo\\+.*? : bar\\+.*? : main\\+"
+    like "${test_name}: stdout" $out $out_pat ""
+    is "${test_name}: exit code" $exit_code 0
+    if {$stderr ne ""} {
+        send_log "stderr:\n$stderr"
+    }
+}
+
+# --- TEST 2 ---
+
+set subtest2 "TEST 2: print_ustack()"
+
+set res [target_compile ${testpath}/${test}_1.c ./a.out executable \
+    "additional_flags=-O additional_flags=-g additional_flags=-O0"]
+if {$res ne ""} {
+    verbose "target_compile failed: $res" 2
+    fail "$test: $subtest2: unable to compile ${test}_1.c"
+} else {
+    set test_name "$test: $subtest2"
+
+    set cmd "stap --ldd -c ./a.out '$srcdir/$subdir/${test}_2.stp'"
+    set exit_code [run_cmd_2way $cmd out stderr]
+    set out_pat " : foo\\+.*? : bar\\+.*? : main\\+"
+    like "${test_name}: stdout" $out $out_pat ""
+    is "${test_name}: exit code" $exit_code 0
+    if {$stderr ne ""} {
+        send_log "stderr:\n$stderr"
+    }
+}
diff --git a/testsuite/systemtap.base/ustack_1.c b/testsuite/systemtap.base/ustack_1.c
new file mode 100644
index 000000000..449ef72c3
--- /dev/null
+++ b/testsuite/systemtap.base/ustack_1.c
@@ -0,0 +1,12 @@
+int foo(void) {
+    return 3;
+}
+
+int bar(void) {
+    return foo();
+}
+
+int main(void) {
+    bar();
+    return 0;
+}
diff --git a/testsuite/systemtap.base/ustack_1.stp b/testsuite/systemtap.base/ustack_1.stp
new file mode 100644
index 000000000..0cc1452c6
--- /dev/null
+++ b/testsuite/systemtap.base/ustack_1.stp
@@ -0,0 +1,3 @@
+probe process.function("foo") {
+    print(sprint_ustack(ubacktrace()));
+}
diff --git a/testsuite/systemtap.base/ustack_2.stp b/testsuite/systemtap.base/ustack_2.stp
new file mode 100644
index 000000000..03b28c9da
--- /dev/null
+++ b/testsuite/systemtap.base/ustack_2.stp
@@ -0,0 +1,3 @@
+probe process.function("foo") {
+    print_ustack(ubacktrace());
+}
-- 
2.11.0.295.gd7dffce

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PR23799 - sprint_ustack() always returns empty string values
  2018-10-19 22:05 [PATCH] PR23799 - sprint_ustack() always returns empty string values Yichun Zhang (agentzh)
@ 2018-10-19 22:10 ` Yichun Zhang
  0 siblings, 0 replies; 2+ messages in thread
From: Yichun Zhang @ 2018-10-19 22:10 UTC (permalink / raw)
  To: systemtap

Hello!

On Fri, Oct 19, 2018 at 3:05 PM Yichun Zhang (agentzh)
<yichun@openresty.com> wrote:
>
> The tapset function sprint_ustack() forgot to actually return
> the computed string value. Alas.

Just committed to master with the approval of fche.

Best,
Yichun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-19 22:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-19 22:05 [PATCH] PR23799 - sprint_ustack() always returns empty string values Yichun Zhang (agentzh)
2018-10-19 22:10 ` Yichun Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).