public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: "Yichun Zhang (agentzh)" <yichun@openresty.com>
To: systemtap@sourceware.org
Cc: "Yichun Zhang (agentzh)" <yichun@openresty.com>
Subject: [PATCH] PR23799 - sprint_ustack() always returns empty string values
Date: Fri, 19 Oct 2018 22:05:00 -0000	[thread overview]
Message-ID: <20181019220447.42137-1-yichun@openresty.com> (raw)

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

             reply	other threads:[~2018-10-19 22:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-19 22:05 Yichun Zhang (agentzh) [this message]
2018-10-19 22:10 ` Yichun Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181019220447.42137-1-yichun@openresty.com \
    --to=yichun@openresty.com \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).