aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@redhat.com>2012-04-27 20:52:06 +0000
committerSergio Durigan Junior <sergiodj@redhat.com>2012-04-27 20:52:06 +0000
commit62e5f89c34f8c206917617978d156da4efb750df (patch)
tree03e070649e0436121c7549c6666363eb77df25dd /gdb/testsuite
parent28106bc2feb5553aede17c93fcb01c08bf935ad1 (diff)
downloadgdb-62e5f89c34f8c206917617978d156da4efb750df.zip
gdb-62e5f89c34f8c206917617978d156da4efb750df.tar.gz
gdb-62e5f89c34f8c206917617978d156da4efb750df.tar.bz2
gdb/doc/ChangeLog:
2012-04-27 Sergio Durigan Junior <sergiodj@redhat.com> Tom Tromey <tromey@redhat.com> * gdb.texinfo (Static Probe Points): New entry, explaining SystemTap and generic static probe support on GDB. gdb/testsuite/ChangeLog: 2012-04-27 Sergio Durigan Junior <sergiodj@redhat.com> Tom Tromey <tromey@redhat.com> * gdb.base/default.exp: Add `$_probe_arg*' convenience variables. * gdb.base/stap-probe.c: New file. * gdb.base/stap-probe.exp: New file. * gdb.trace/stap-trace.c: New file. * gdb.trace/stap-trace.exp: New file. * gdb.cp/nextoverthrow.exp: Add check for SystemTap probe in libgcc's unwinder.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog12
-rw-r--r--gdb/testsuite/gdb.base/default.exp13
-rw-r--r--gdb/testsuite/gdb.base/stap-probe.c108
-rw-r--r--gdb/testsuite/gdb.base/stap-probe.exp183
-rw-r--r--gdb/testsuite/gdb.cp/nextoverthrow.exp11
-rw-r--r--gdb/testsuite/gdb.trace/stap-trace.c71
-rw-r--r--gdb/testsuite/gdb.trace/stap-trace.exp128
7 files changed, 526 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index ba84133..ba9d339 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,15 @@
+2012-04-27 Sergio Durigan Junior <sergiodj@redhat.com>
+ Tom Tromey <tromey@redhat.com>
+
+ * gdb.base/default.exp: Add `$_probe_arg*' convenience
+ variables.
+ * gdb.base/stap-probe.c: New file.
+ * gdb.base/stap-probe.exp: New file.
+ * gdb.trace/stap-trace.c: New file.
+ * gdb.trace/stap-trace.exp: New file.
+ * gdb.cp/nextoverthrow.exp: Add check for SystemTap probe in
+ libgcc's unwinder.
+
2012-04-26 Maciej W. Rozycki <macro@codesourcery.com>
* gdb.arch/mips16-thunks-inmain.c: New file.
diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index e2859d5..73fbe98 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -604,6 +604,19 @@ gdb_test_list_exact "show convenience" "show convenience" \
{$_sdata = void} \
{$_siginfo = void} \
{$_thread = 0} \
+ {$_probe_argc = <error: No frame selected>} \
+ {$_probe_arg0 = <error: No frame selected>} \
+ {$_probe_arg1 = <error: No frame selected>} \
+ {$_probe_arg2 = <error: No frame selected>} \
+ {$_probe_arg3 = <error: No frame selected>} \
+ {$_probe_arg4 = <error: No frame selected>} \
+ {$_probe_arg5 = <error: No frame selected>} \
+ {$_probe_arg6 = <error: No frame selected>} \
+ {$_probe_arg7 = <error: No frame selected>} \
+ {$_probe_arg8 = <error: No frame selected>} \
+ {$_probe_arg9 = <error: No frame selected>} \
+ {$_probe_arg10 = <error: No frame selected>} \
+ {$_probe_arg11 = <error: No frame selected>} \
}
#test show directories
diff --git a/gdb/testsuite/gdb.base/stap-probe.c b/gdb/testsuite/gdb.base/stap-probe.c
new file mode 100644
index 0000000..1c7b05f
--- /dev/null
+++ b/gdb/testsuite/gdb.base/stap-probe.c
@@ -0,0 +1,108 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2012 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if USE_PROBES
+
+#define _SDT_HAS_SEMAPHORES
+__extension__ unsigned short test_user_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
+#define TEST test_user_semaphore
+
+__extension__ unsigned short test_two_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
+#define TEST2 test_two_semaphore
+
+__extension__ unsigned short test_m4_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
+
+__extension__ unsigned short test_pstr_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
+
+__extension__ unsigned short test_ps_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
+#else
+
+#define TEST 1
+#define TEST2 1
+
+#endif
+
+#include <sys/sdt.h>
+
+/* We only support SystemTap and only the v3 form. */
+#if _SDT_NOTE_TYPE != 3
+#error "not using SystemTap v3 probes"
+#endif
+
+struct funcs
+{
+ int val;
+
+ const char *(*ps) (int);
+};
+
+static void
+m1 (void)
+{
+ if (TEST2)
+ STAP_PROBE (test, two);
+}
+
+static void
+m2 (void)
+{
+ if (TEST2)
+ STAP_PROBE (test, two);
+}
+
+static int
+f (int x)
+{
+ if (TEST)
+ STAP_PROBE1 (test, user, x);
+ return x+5;
+}
+
+static const char *
+pstr (int val)
+{
+ const char *a = "This is a test message.";
+ const char *b = "This is another test message.";
+
+ STAP_PROBE3 (test, ps, a, b, val);
+
+ return val == 0 ? a : b;
+}
+
+static void
+m4 (const struct funcs *fs, int v)
+{
+ STAP_PROBE3 (test, m4, fs->val, fs->ps (v), v);
+}
+
+int
+main()
+{
+ struct funcs fs;
+
+ fs.val = 42;
+ fs.ps = pstr;
+
+ f (f (23));
+ m1 ();
+ m2 ();
+
+ m4 (&fs, 0);
+ m4 (&fs, 1);
+
+ return 0; /* last break here */
+}
diff --git a/gdb/testsuite/gdb.base/stap-probe.exp b/gdb/testsuite/gdb.base/stap-probe.exp
new file mode 100644
index 0000000..30ca427
--- /dev/null
+++ b/gdb/testsuite/gdb.base/stap-probe.exp
@@ -0,0 +1,183 @@
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set testfile stap-probe
+
+# Run the tests. We run the tests two different ways: once with a
+# plain probe, and once with a probe that has an associated semaphore.
+# This returns -1 on failure to compile or start, 0 otherwise.
+proc stap_test {exec_name {arg ""}} {
+ global testfile hex
+
+ if {[prepare_for_testing ${testfile}.exp ${exec_name} ${testfile}.c \
+ [concat $arg debug]]} {
+ return -1
+ }
+
+ if ![runto_main] {
+ return -1
+ }
+
+ gdb_test "print \$_probe_argc" "No SystemTap probe at PC $hex" \
+ "check argument not at probe point"
+
+ gdb_test "info probes stap" \
+ "test *user *$hex .*" \
+ "info probes stap"
+
+ if {[runto "-pstap test:user"]} {
+ pass "run to -pstap test:user"
+ } else {
+ fail "run to -pstap test:user"
+ }
+
+ # Test probe arguments.
+ gdb_test "print \$_probe_argc" " = 1" \
+ "print \$_probe_argc for probe user"
+ gdb_test "print \$_probe_arg0 == x" " = 1" \
+ "check \$_probe_arg0 for probe user"
+ gdb_test "print \$_probe_arg1" \
+ "Invalid probe argument 1 -- probe has 1 arguments available" \
+ "check \$_probe_arg1 for probe user"
+
+ # Set a breakpoint with multiple probe locations.
+ gdb_test "break -pstap test:two" \
+ "Breakpoint \[0-9\]+ at $hex.*2 locations.*" \
+ "set multi-location probe breakpoint (probe two)"
+
+ # Reinit GDB, set a breakpoint on probe m4.
+ delete_breakpoints
+ rerun_to_main
+ if {[runto "-pstap test:m4"]} {
+ pass "run to -pstap test:m4"
+ } else {
+ fail "run to -pstap test:m4"
+ }
+
+ # Testing probe arguments.
+ gdb_test "print \$_probe_argc" " = 3" \
+ "print \$_probe_argc for probe m4"
+ gdb_test "print \$_probe_arg0" " = 42" \
+ "check \$_probe_arg0 for probe m4"
+ gdb_test "print (const char *) \$_probe_arg1" \
+ " = $hex .This is a test message.*" \
+ "check \$_probe_arg1 for probe m4"
+ gdb_test "print \$_probe_arg2 == v" " = 1" \
+ "check \$_probe_arg2 for probe m4"
+
+ # Reinit GDB, set a breakpoint on probe ps.
+ delete_breakpoints
+ rerun_to_main
+ if {[runto "-pstap test:ps"]} {
+ pass "run to -pstap test:m4"
+ } else {
+ fail "run to -pstap test:m4"
+ }
+
+ gdb_test "print \$_probe_argc" " = 3" \
+ "print \$_probe_argc for probe ps"
+ gdb_test "print (const char *) \$_probe_arg1" \
+ " = $hex .This is another test message.*" \
+ "print \$_probe_arg1 for probe ps"
+
+ return 0
+}
+
+proc stap_test_no_debuginfo {exec_name {arg ""}} {
+ global testfile hex
+
+ if {[prepare_for_testing ${testfile}.exp ${exec_name} ${testfile}.c \
+ {$arg nodebug optimize=-O2}]} {
+ return -1
+ }
+
+ if {[runto "-pstap test:user"]} {
+ pass "run to -pstap test:user"
+ } else {
+ fail "run to -pstap test:user"
+ }
+
+ # Test probe arguments.
+ gdb_test "print \$_probe_argc" " = 1" \
+ "print \$_probe_argc for probe user"
+ gdb_test "print \$_probe_arg0 == 23" " = 1" \
+ "check \$_probe_arg0 for probe user"
+ gdb_test "print \$_probe_arg1" \
+ "Invalid probe argument 1 -- probe has 1 arguments available" \
+ "check \$_probe_arg1 for probe user"
+
+ # Set a breakpoint with multiple probe locations.
+ # In this scenario, we may expect more than 2 locations because of
+ # the optimizations (inlining, loop unrolling, etc).
+ gdb_test "break -pstap test:two" \
+ "Breakpoint .* at $hex.*\[0-9\]+ locations.*" \
+ "set multi-location probe breakpoint (probe two)"
+
+ # Reinit GDB, set a breakpoint on probe m4.
+ delete_breakpoints
+ rerun_to_main
+ if {[runto "-pstap test:m4"]} {
+ pass "run to -pstap test:m4"
+ } else {
+ fail "run to -pstap test:m4"
+ }
+
+ # Testing probe arguments.
+ gdb_test "print \$_probe_argc" " = 3" \
+ "print \$_probe_argc for probe m4"
+ gdb_test "print \$_probe_arg0" " = 42" \
+ "check \$_probe_arg0 for probe m4"
+ gdb_test "print (const char *) \$_probe_arg1" \
+ " = $hex .This is a test message.*" \
+ "check \$_probe_arg1 for probe m4"
+ gdb_test "print \$_probe_arg2 == 0" " = 1" \
+ "check \$_probe_arg2 for probe m4"
+
+ # Reinit GDB, set a breakpoint on probe ps.
+ delete_breakpoints
+ rerun_to_main
+ if {[runto "-pstap test:ps"]} {
+ pass "run to -pstap test:m4"
+ } else {
+ fail "run to -pstap test:m4"
+ }
+
+ gdb_test "print \$_probe_argc" " = 3" \
+ "print \$_probe_argc for probe ps"
+ gdb_test "print (const char *) \$_probe_arg1" \
+ " = $hex .This is another test message.*" \
+ "print \$_probe_arg1 for probe ps"
+
+ return 0
+}
+
+with_test_prefix "without semaphore, not optimized" {
+ if {[stap_test "stap-probe-nosem-noopt"] == -1} {
+ untested stap-probe.exp
+ return -1
+ }
+}
+
+with_test_prefix "with semaphore, not optimized" {
+ stap_test "stap-probe-sem-noopt" "-DUSE_PROBES"
+}
+
+with_test_prefix "without semaphore, optimized" {
+ stap_test_no_debuginfo "stap-probe-nosem-opt"
+}
+
+with_test_prefix "with semaphore, optimized" {
+ stap_test_no_debuginfo "stap-probe-sem-opt" "-DUSE_PROBES"
+}
diff --git a/gdb/testsuite/gdb.cp/nextoverthrow.exp b/gdb/testsuite/gdb.cp/nextoverthrow.exp
index 7d4a0c5..2dafcab 100644
--- a/gdb/testsuite/gdb.cp/nextoverthrow.exp
+++ b/gdb/testsuite/gdb.cp/nextoverthrow.exp
@@ -54,6 +54,17 @@ gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
}
}
if {!$ok} {
+ gdb_test_multiple "info probe" "check for stap probe in unwinder" {
+ -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
+ pass "check for stap probe in unwinder"
+ set ok 1
+ }
+ -re "\r\n$gdb_prompt $" {
+ }
+ }
+}
+
+if {!$ok} {
unsupported "nextoverthrow.exp could not find _Unwind_DebugHook"
return -1
}
diff --git a/gdb/testsuite/gdb.trace/stap-trace.c b/gdb/testsuite/gdb.trace/stap-trace.c
new file mode 100644
index 0000000..7c638db
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/stap-trace.c
@@ -0,0 +1,71 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2012 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if USE_PROBES
+
+#define _SDT_HAS_SEMAPHORES
+__extension__ unsigned short test_user_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
+#define TEST test_user_semaphore
+
+__extension__ unsigned short test_two_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes")));
+#define TEST2 test_two_semaphore
+
+#else
+
+#define TEST 1
+#define TEST2 1
+
+#endif /* USE_PROBES */
+
+#include <sys/sdt.h>
+
+/* We only support SystemTap and only the v3 form. */
+#if _SDT_NOTE_TYPE != 3
+#error "not using SystemTap v3 probes"
+#endif
+
+void
+m1 (int x)
+{
+ if (TEST2)
+ STAP_PROBE1 (test, two, x);
+}
+
+int
+f (int x)
+{
+ if (TEST)
+ STAP_PROBE1(test, user, x);
+ return x+5;
+}
+
+void
+nothing (void)
+{
+ int a = 1 + 1;
+ return;
+}
+
+int
+main()
+{
+ f (f (23));
+ m1 (46);
+ nothing (); /* end-here */
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.trace/stap-trace.exp b/gdb/testsuite/gdb.trace/stap-trace.exp
new file mode 100644
index 0000000..562eec4
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/stap-trace.exp
@@ -0,0 +1,128 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+load_lib "trace-support.exp"
+
+set testfile "stap-trace"
+set srcfile ${testfile}.c
+set executable ""
+set binfile_dir $objdir/$subdir
+
+set ws "\[\r\n\t \]+"
+set cr "\[\r\n\]+"
+
+# Only x86 and x86_64 targets are supported for now.
+
+if { ![istarget "x86_64-*"] && ![istarget "i?86-*"] } {
+ continue
+}
+
+proc compile_stap_bin {exec_name {arg ""}} {
+ global srcfile
+ global binfile_dir
+ global srcdir
+ global subdir
+ global executable
+
+ if { $arg != "" } {
+ set arg "additional_flags=$arg"
+ }
+
+ set executable ${exec_name}
+
+ if { [gdb_compile "$srcdir/$subdir/$srcfile" \
+ "$binfile_dir/$exec_name" \
+ executable [concat $arg debug nowarnings]] != "" } {
+ untested "Could not compile ${srcfile}"
+ return -1
+ }
+}
+
+proc prepare_for_trace_test {} {
+ global executable
+
+ clean_restart $executable
+
+ if { ![runto_main] } {
+ perror "Could not run to `main'."
+ continue
+ }
+
+ gdb_breakpoint [gdb_get_line_number "end-here"]
+}
+
+proc run_trace_experiment { test_probe msg } {
+ global gdb_prompt
+
+ set test "collect $msg: start trace experiment"
+ gdb_test_multiple "tstart" "$test" {
+ -re "^tstart\r\n$gdb_prompt $" {
+ pass "$test"
+ }
+ }
+
+ gdb_test "continue" \
+ "Continuing.*Breakpoint \[0-9\]+.*" \
+ "collect $msg: run trace experiment"
+ gdb_test "tstop" \
+ "\[\r\n\]+" \
+ "collect $msg: stop trace experiment"
+ gdb_test "tfind start" \
+ "#0 .*" \
+ "collect $msg: tfind test frame"
+}
+
+proc gdb_collect_probe_arg { msg probe val_arg0 } {
+ global gdb_prompt
+ global cr
+
+ prepare_for_trace_test
+
+ gdb_test "trace $probe" \
+ "Tracepoint \[0-9\]+ at .*" \
+ "collect $msg: set tracepoint"
+ gdb_trace_setactions "collect $msg: define actions" \
+ "" \
+ "collect \$_probe_arg0" "^$"
+
+ # Begin the test.
+ run_trace_experiment $msg $probe
+
+ gdb_test "print \$_probe_arg0" \
+ "\\$\[0-9\]+ = $val_arg0$cr" \
+ "collect $msg: collected probe arg0"
+}
+
+compile_stap_bin "stap-probe-nosem"
+
+clean_restart $executable
+if { ![runto_main] } {
+ perror "Could not run to `main'."
+ continue
+}
+
+if { ![gdb_target_supports_trace] } {
+ # Test cannot run on this target.
+ return 1;
+}
+
+gdb_collect_probe_arg "probe args without semaphore" "-probe-stap user" "23"
+gdb_exit
+
+compile_stap_bin "stap-probe-sem" "-DUSE_PROBES"
+gdb_collect_probe_arg "probe args with semaphore" "-probe-stap two" "46"
+
+# Finished!
+gdb_test "tfind none" ".*" ""