[patch 8/8] Test cases

Yao Qi
2011-11-08T06:56:02Z

[-- Attachment #1: Type: text/plain, Size: 587 bytes --]

These new test cases are to verify that tracepoint changed after
`tstart' still work properly. There are two FAILs in change-loc.exp on
x86_64-linux, but they are not related to this patch set. They are
caused by an existing problem that jmp insn is incorrectly generated in
jump pad if offset exceeds the limit of integer (32-bit). It could
happen on x86_64 system.

I opened PR 13392, and KFAIL'ed them.

KFAIL: gdb.trace/change-loc.exp: 1 trace: tfind frame 0 (PRMS: gdb/13392)
KFAIL: gdb.trace/change-loc.exp: 1 ftrace: tfind frame 0 (PRMS: gdb/13392)

--
Yao (é½å°§)

[-- Attachment #2: 0008-testsuite-tracepoint-change-loc.patch --]
[-- Type: text/x-patch, Size: 19357 bytes --]

2011-11-08 Yao Qi <yao@codesourcery.com>

* gdb.trace/change-loc-1.c: New.
* gdb.trace/change-loc-2.c: New.
* gdb.trace/change-loc.c: New.
* gdb.trace/change-loc.exp: New.
* gdb.trace/change-loc.h: New.
* gdb.trace/trace-break.c (marker): Define new symbol.
* gdb.trace/trace-break.exp (break_trace_same_addr_5):
New.
(break_trace_same_addr_6): New.
---
gdb/testsuite/gdb.trace/change-loc-1.c | 29 +++++
gdb/testsuite/gdb.trace/change-loc-2.c | 24 ++++
gdb/testsuite/gdb.trace/change-loc.c | 53 +++++++++
gdb/testsuite/gdb.trace/change-loc.exp | 157 +++++++++++++++++++++++++
gdb/testsuite/gdb.trace/change-loc.h | 42 +++++++
gdb/testsuite/gdb.trace/trace-break.c | 7 +
gdb/testsuite/gdb.trace/trace-break.exp | 193 +++++++++++++++++++++++++++++++
7 files changed, 505 insertions(+), 0 deletions(-)
create mode 100644 gdb/testsuite/gdb.trace/change-loc-1.c
create mode 100644 gdb/testsuite/gdb.trace/change-loc-2.c
create mode 100644 gdb/testsuite/gdb.trace/change-loc.c
create mode 100644 gdb/testsuite/gdb.trace/change-loc.exp
create mode 100644 gdb/testsuite/gdb.trace/change-loc.h

diff --git a/gdb/testsuite/gdb.trace/change-loc-1.c b/gdb/testsuite/gdb.trace/change-loc-1.c
new file mode 100644
index 0000000..92d453c
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/change-loc-1.c
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2011 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/>. */
+
+#include "change-loc.h"
+
+void func1 (int x)
+{
+ int y = x + 4;
+ func4 ();
+}
+
+void func (int x)
+{
+ func1 (x);
+}
diff --git a/gdb/testsuite/gdb.trace/change-loc-2.c b/gdb/testsuite/gdb.trace/change-loc-2.c
new file mode 100644
index 0000000..d479917
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/change-loc-2.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2011 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/>. */
+
+#include "change-loc.h"
+
+void
+func2 (int x)
+{
+ func4 ();
+}
diff --git a/gdb/testsuite/gdb.trace/change-loc.c b/gdb/testsuite/gdb.trace/change-loc.c
new file mode 100644
index 0000000..d1e0a7f
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/change-loc.c
@@ -0,0 +1,53 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2011 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/>. */
+
+#include <stdio.h>
+#include <dlfcn.h>
+#include "change-loc.h"
+
+extern void func (int x);
+
+static void
+marker () {}
+
+int main()
+{
+ const char *libname = "change-loc-2.sl";
+ void *h;
+ int (*p_func) (int);
+
+ func (3);
+
+ func4 ();
+
+ marker ();
+
+ h = dlopen (libname, RTLD_LAZY);
+ if (h == NULL) return 1;
+
+ p_func = dlsym (h, "func2");
+ if (p_func == NULL) return 2;
+
+ (*p_func) (4);
+
+ marker ();
+
+ dlclose (h);
+
+ marker ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.trace/change-loc.exp b/gdb/testsuite/gdb.trace/change-loc.exp
new file mode 100644
index 0000000..6425a26
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/change-loc.exp
@@ -0,0 +1,157 @@
+# Copyright 2011 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";
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+#
+# test running programs
+#
+
+if {[skip_shlib_tests]} {
+ return 0
+}
+
+set testfile "change-loc"
+set libfile1 "change-loc-1"
+set libfile2 "change-loc-2"
+set srcfile $testfile.c
+set executable $testfile
+set libsrc1 $srcdir/$subdir/$libfile1.c
+set libsrc2 $srcdir/$subdir/$libfile2.c
+set binfile $objdir/$subdir/$testfile
+set lib_sl1 $objdir/$subdir/$libfile1.sl
+set lib_sl2 $objdir/$subdir/$libfile2.sl
+
+set lib_opts debug
+
+if [get_compiler_info ${binfile}] {
+ return -1
+}
+
+# Some targets have leading underscores on assembly symbols.
+set additional_flags [list debug shlib=$lib_sl1 shlib_load [gdb_target_symbol_prefix_flags]]
+
+if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
+ || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
+ || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
+ untested "Could not compile either $libsrc1 or $srcdir/$subdir/$srcfile."
+ return -1
+}
+
+clean_restart $executable
+
+gdb_load_shlibs $lib_sl1
+gdb_load_shlibs $lib_sl2
+
+if ![runto_main] {
+ fail "Can't run to main to check for trace support"
+ return -1
+}
+
+if { ![gdb_target_supports_trace] } then {
+ unsupported "Current target does not support trace"
+ return -1;
+}
+
+if [is_amd64_regs_target] {
+ set pcreg "rip"
+} elseif [is_x86_like_target] {
+ set pcreg "eip"
+} else {
+ set pcreg "pc"
+}
+
+
+# Set tracepoint during tracing experiment.
+
+proc tracepoint_change_loc_1 { trace_type } {
+ global testfile
+ global srcfile
+ global pcreg
+ global gdb_prompt
+ global pf_prefix
+
+ set old_pf_prefix $pf_prefix
+ set pf_prefix "$pf_prefix 1 $trace_type:"
+
+ clean_restart ${testfile}
+ if ![runto_main] {
+ fail "Can't run to main"
+ set pf_prefix $old_pf_prefix
+ return -1
+ }
+ gdb_test_no_output "delete break 1"
+
+ # Set a tracepoint we'll never meet. Just to avoid the complain after
+ # type `tstart' later.
+ gdb_test "next" ".*"
+ gdb_test "trace main" "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
+ "set tracepoint on main"
+
+ gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
+ "breakpoint on marker"
+
+ gdb_test_no_output "tstart"
+
+ gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
+ "continue to marker 1"
+ # Set a tracepoint during tracing.
+ gdb_test "${trace_type} set_tracepoint" ".*" "set tracepoint on set_tracepoint"
+
+ gdb_trace_setactions "set action for tracepoint" "" \
+ "collect \$$pcreg" "^$"
+
+ # tracepoint has two locations after shlib change-loc-1 is loaded.
+ gdb_test "info trace" \
+ "Num Type\[ \]+Disp Enb Address\[ \]+What.*
+\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \
+ "tracepoint with two locations"
+
+ setup_kfail "gdb/13392" x86_64-*-*
+ gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
+ "continue to marker 2"
+
+ # tracepoint has three locations after shlib change-loc-2 is loaded.
+ gdb_test "info trace" \
+ "Num Type\[ \]+Disp Enb Address\[ \]+What.*
+\[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \
+ "tracepoint with three locations"
+
+ gdb_test_no_output "tstop"
+
+ setup_kfail "gdb/13392" x86_64-*-*
+ gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" "tfind frame 0"
+ gdb_test "tfind" "Target failed to find requested trace frame\\..*"
+
+ set pf_prefix $old_pf_prefix
+}
+
+
+tracepoint_change_loc_1 "trace"
+
+# Re-compile test case with IPA.
+set libipa $objdir/../gdbserver/libinproctrace.so
+gdb_load_shlibs $libipa
+
+if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
+ [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
+ untested change-loc.exp
+ return -1
+}
+
+tracepoint_change_loc_1 "ftrace"
diff --git a/gdb/testsuite/gdb.trace/change-loc.h b/gdb/testsuite/gdb.trace/change-loc.h
new file mode 100644
index 0000000..1b0e303
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/change-loc.h
@@ -0,0 +1,42 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2011 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/>. */
+
+#ifdef SYMBOL_PREFIX
+#define SYMBOL(str) SYMBOL_PREFIX #str
+#else
+#define SYMBOL(str) #str
+#endif
+
+/* Called from asm. */
+static void __attribute__((used))
+func5 (void)
+{}
+
+static void
+func4 (void)
+{
+ /* `set_tracepoint' is the label where we'll set multiple tracepoints and
+ breakpoints at. The insn at the label must the large enough to
+ fit a fast tracepoint jump. */
+ asm (" .global " SYMBOL(set_tracepoint) "\n"
+ SYMBOL(set_tracepoint) ":\n"
+#if (defined __x86_64__ || defined __i386__)
+ " call " SYMBOL(func5) "\n"
+#endif
+ );
+
+}
diff --git a/gdb/testsuite/gdb.trace/trace-break.c b/gdb/testsuite/gdb.trace/trace-break.c
index fd06142..a327202 100644
--- a/gdb/testsuite/gdb.trace/trace-break.c
+++ b/gdb/testsuite/gdb.trace/trace-break.c
@@ -43,6 +43,13 @@ marker (void)
" call " SYMBOL(func) "\n"
#endif
);
+
+ asm (" .global " SYMBOL(after_set_point) "\n"
+ SYMBOL(after_set_point) ":\n"
+#if (defined __x86_64__ || defined __i386__)
+ " call " SYMBOL(func) "\n"
+#endif
+ );
}

static void
diff --git a/gdb/testsuite/gdb.trace/trace-break.exp b/gdb/testsuite/gdb.trace/trace-break.exp
index c2d7b2c..b80f7cd 100644
--- a/gdb/testsuite/gdb.trace/trace-break.exp
+++ b/gdb/testsuite/gdb.trace/trace-break.exp
@@ -39,6 +39,20 @@ if ![gdb_target_supports_trace] {
return -1;
}

+set fpreg "fp"
+set spreg "sp"
+set pcreg "pc"
+
+if [is_amd64_regs_target] {
+ set fpreg "rbp"
+ set spreg "rsp"
+ set pcreg "rip"
+} elseif [is_x86_like_target] {
+ set fpreg "ebp"
+ set spreg "esp"
+ set pcreg "eip"
+}
+
# Set breakpoint and tracepoint at the same address.

proc break_trace_same_addr_1 { trace_type option } {
@@ -200,6 +214,150 @@ proc break_trace_same_addr_4 { trace_type option } {
set pf_prefix $old_pf_prefix
}

+# Set two tracepoints TRACE1 and TRACE2 at two locations, and start tracing.
+# Then, set tracepoint TRACE3 at either of these two locations.
+# TRACE3_AT_FIRST_LOC is a boolean variable to decide insert TRACE3 at which
+# of two locations. Verify these tracepoints work as expected.
+
+proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } {
+ global executable
+ global pf_prefix
+ global hex
+ global fpreg
+ global spreg
+ global pcreg
+
+ set old_pf_prefix $pf_prefix
+ set pf_prefix "$pf_prefix 5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}:"
+
+ # Start with a fresh gdb.
+ clean_restart ${executable}
+ if ![runto_main] {
+ fail "Can't run to main"
+ set pf_prefix $old_pf_prefix
+ return -1
+ }
+
+ gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
+ gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
+
+ gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
+ gdb_trace_setactions "set action for tracepoint 1" "" \
+ "collect \$$pcreg" "^$"
+ gdb_test "${trace2} after_set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
+ gdb_trace_setactions "set action for tracepoint 2" "" \
+ "collect \$$spreg" "^$"
+
+ gdb_test_no_output "tstart"
+
+ gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
+
+ if [string equal $trace3_at_first_loc "1"] {
+ gdb_test "${trace3} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
+ } else {
+ gdb_test "${trace3} after_set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
+ }
+ gdb_trace_setactions "set action for tracepoint 3" "" \
+ "collect \$$fpreg" "^$"
+
+ gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
+ gdb_test_no_output "tstop"
+
+ gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
+ "tfind test frame of tracepoint 4"
+ gdb_test "tdump" \
+ "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
+ "tdump 1"
+ gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
+ "reset to frame 0 (1)"
+ gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
+ "tfind test frame of tracepoint 5"
+ gdb_test "tdump" \
+ "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
+ "tdump 2"
+ gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
+ "reset to frame 0 (2)"
+ gdb_test "tfind tracepoint 6" "Found trace frame \[0-9\], tracepoint .*" \
+ "tfind test frame of tracepoint 6"
+ gdb_test "tdump" \
+ "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${fpreg} = .*" \
+ "tdump 3"
+
+ set pf_prefix $old_pf_prefix
+}
+
+# Set two tracepoints at the same address, and enable/disable them. Verify
+# tracepoints work as expect.
+
+proc break_trace_same_addr_6 { trace1 enable1 trace2 enable2 } {
+ global executable
+ global pf_prefix
+ global hex
+ global gdb_prompt
+ global spreg
+ global pcreg
+
+ set old_pf_prefix $pf_prefix
+ set pf_prefix "$pf_prefix 6 $trace1 $enable1 $trace2 $enable2:"
+
+ # Start with a fresh gdb.
+ clean_restart ${executable}
+ if ![runto_main] {
+ fail "Can't run to main"
+ set pf_prefix $old_pf_prefix
+ return -1
+ }
+
+ gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
+ gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
+
+ gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
+
+ gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
+ gdb_trace_setactions "set action for tracepoint 1" "" \
+ "collect \$$pcreg" "^$"
+ gdb_test "${trace2} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
+ gdb_trace_setactions "set action for tracepoint 2" "" \
+ "collect \$$spreg" "^$"
+
+ gdb_test_no_output "$enable1 4"
+ gdb_test_no_output "$enable2 5"
+
+ gdb_test_no_output "tstart"
+ gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
+ gdb_test_no_output "tstop"
+
+
+ if [string equal $enable1 "enable"] {
+ gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
+ "tfind test frame of tracepoint 4"
+ gdb_test "tdump" \
+ "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
+ "tdump 1"
+ gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
+ "reset to frame 0 (1)"
+ } else {
+ gdb_test "tfind tracepoint 4" "Target failed to find requested trace frame.*" \
+ "tfind test frame of tracepoint 4"
+ }
+
+ if [string equal $enable2 "enable"] {
+ gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
+ "tfind test frame of tracepoint 5"
+ gdb_test "tdump" \
+ "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
+ "tdump 2"
+ gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
+ "reset to frame 0 (2)"
+ } else {
+ gdb_test "tfind tracepoint 5" "Target failed to find requested trace frame.*" \
+ "tfind test frame of tracepoint 5"
+ }
+
+ set pf_prefix $old_pf_prefix
+}
+
+
foreach break_always_inserted { "on" "off" } {
break_trace_same_addr_1 "trace" ${break_always_inserted}
break_trace_same_addr_2 "trace" "trace" ${break_always_inserted}
@@ -207,6 +365,13 @@ foreach break_always_inserted { "on" "off" } {
break_trace_same_addr_4 "trace" ${break_always_inserted}
}

+foreach at_first_loc { "1" "0" } {
+ break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc}
+}
+
+break_trace_same_addr_6 "trace" "enable" "trace" "disable"
+break_trace_same_addr_6 "trace" "disable" "trace" "enable"
+
set libipa $objdir/../gdbserver/libinproctrace.so
gdb_load_shlibs $libipa

@@ -238,4 +403,32 @@ if { [gdb_test "info sharedlibrary" ".*libinproctrace\.so.*" "IPA loaded"] != 0
break_trace_same_addr_3 "ftrace" ${break_always_inserted}
break_trace_same_addr_4 "ftrace" ${break_always_inserted}
}
+
+ foreach trace1 { "trace" "ftrace" } {
+ foreach trace2 { "trace" "ftrace" } {
+ foreach trace3 { "trace" "ftrace" } {
+
+ if { [string equal $trace1 "trace"]
+ && [string equal $trace2 "trace"]
+ && [string equal $trace3 "trace"] } {
+ continue
+ }
+
+ foreach at_first_loc { "1" "0" } {
+ break_trace_same_addr_5 $trace1 $trace2 $trace3 $at_first_loc
+ }
+ }
+ }
+ }
+
+ foreach trace1 { "trace" "ftrace" } {
+ foreach trace2 { "trace" "ftrace" } {
+ if { [string equal $trace1 "trace"]
+ && [string equal $trace2 "trace"] } {
+ continue
+ }
+ break_trace_same_addr_6 $trace1 "enable" $trace2 "disable"
+ break_trace_same_addr_6 $trace1 "disable" $trace2 "enable"
+ }
+ }
}
--
1.7.0.4