2011-10-26 Yao Qi * gdb.trace/trace-break.c: New. * gdb.trace/trace-break.exp: New. --- gdb/testsuite/gdb.trace/trace-break.c | 46 ++++++ gdb/testsuite/gdb.trace/trace-break.exp | 233 +++++++++++++++++++++++++++++++ 3 files changed, 290 insertions(+), 0 deletions(-) create mode 100644 gdb/testsuite/gdb.trace/trace-break.c create mode 100644 gdb/testsuite/gdb.trace/trace-break.exp diff --git a/gdb/testsuite/gdb.trace/trace-break.c b/gdb/testsuite/gdb.trace/trace-break.c new file mode 100644 index 0000000..0eda029 --- /dev/null +++ b/gdb/testsuite/gdb.trace/trace-break.c @@ -0,0 +1,46 @@ +/* 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 . */ + + +static void +func () +{} + +static void +marker () +{ + int a = 0; + int b = a; + + asm (".global set_point"); + asm (" set_point:"); /* The lable that we'll set tracepoint on. */ +#if (defined __x86_64__ || defined __i386__) + /* It is a five-byte insn, so that fast trace point can be set on it. */ + asm ("call func"); +#endif +} + +static void +end () +{} + +int main() +{ + marker (); + end (); + return 0; +} diff --git a/gdb/testsuite/gdb.trace/trace-break.exp b/gdb/testsuite/gdb.trace/trace-break.exp new file mode 100644 index 0000000..6f8d9aa --- /dev/null +++ b/gdb/testsuite/gdb.trace/trace-break.exp @@ -0,0 +1,233 @@ +# 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 . + +load_lib "trace-support.exp"; + +if $tracelevel then { + strace $tracelevel +} + +set testfile "trace-break" + +set srcfile $testfile.c +set binfile $objdir/$subdir/$testfile +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ + executable [list debug nowarnings] ] != "" } { + untested trace-break.exp + return -1 +} + +gdb_start +gdb_load ${binfile} + +runto_main +gdb_reinitialize_dir $srcdir/$subdir + +# We generously give ourselves one "pass" if we successfully +# detect that this test cannot be run on this target! +if { ![gdb_target_supports_trace] } then { + pass "Current target does not support trace" + return 1; +} + +# Set breakpoint and tracepoint at the same address. + +proc break_trace_same_addr_1 { trace_type option } { + global srcdir + global subdir + global binfile + global pf_prefix + global srcfile + + # Start with a fresh gdb. + gdb_exit + gdb_start + gdb_load ${binfile} + runto_main + gdb_reinitialize_dir $srcdir/$subdir + + set old_pf_prefix $pf_prefix + set pf_prefix "$pf_prefix 1 $trace_type $option:" + + gdb_test_no_output "set breakpoint always-inserted ${option}" + + gdb_test "break end" "Breakpoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + + gdb_test "break set_point" "Breakpoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + + gdb_test_no_output "tstart" + + gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to set_point" + + gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" + gdb_test_no_output "tstop" + + gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0" + gdb_test "tfind" "Target failed to find requested trace frame\\..*" + + set pf_prefix $old_pf_prefix +} + +# Set multiple tracepoints at the same address. + +proc break_trace_same_addr_2 { trace_type1 trace_type2 option } { + global srcdir + global subdir + global binfile + global pf_prefix + global srcfile + + # Start with a fresh gdb. + gdb_exit + gdb_start + gdb_load ${binfile} + runto_main + gdb_reinitialize_dir $srcdir/$subdir + + set old_pf_prefix $pf_prefix + set pf_prefix "$pf_prefix 2 $trace_type1 $trace_type2 $option:" + + gdb_test_no_output "set breakpoint always-inserted ${option}" + + gdb_test "break end" "Breakpoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + gdb_test "${trace_type1} set_point" "\(Fast t|T\)racepoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + gdb_test "${trace_type2} set_point" "\(Fast t|T\)racepoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + + gdb_test_no_output "tstart" + gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" + + gdb_test_no_output "tstop" + + gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0" + gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1" + gdb_test "tfind" "Target failed to find requested trace frame\\..*" + + set pf_prefix $old_pf_prefix +} + +# Set breakpoint and tracepoint at the same address. Delete breakpoint, and verify +# that tracepoint still works. + +proc break_trace_same_addr_3 { trace_type option } { + global srcdir + global subdir + global binfile + global pf_prefix + global srcfile + + # Start with a fresh gdb. + gdb_exit + gdb_start + gdb_load ${binfile} + runto_main + gdb_reinitialize_dir $srcdir/$subdir + + set old_pf_prefix $pf_prefix + set pf_prefix "$pf_prefix 3 $trace_type $option:" + + gdb_test_no_output "set breakpoint always-inserted ${option}" + gdb_test "break marker" "Breakpoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + gdb_test "break end" "Breakpoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + + gdb_test "break set_point" "Breakpoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + + gdb_test_no_output "tstart" + + gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker" + gdb_test "delete break 4" + + gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" + gdb_test_no_output "tstop" + + gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0" + gdb_test "tfind" "Target failed to find requested trace frame\\..*" + + set pf_prefix $old_pf_prefix +} + +# Set breakpoint and tracepoint at the same address. Delete tracepoint, and verify +# that breakpoint still works. + +proc break_trace_same_addr_4 { trace_type option } { + global srcdir + global subdir + global binfile + global pf_prefix + global srcfile + + # Start with a fresh gdb. + gdb_exit + gdb_start + gdb_load ${binfile} + runto_main + gdb_reinitialize_dir $srcdir/$subdir + + set old_pf_prefix $pf_prefix + set pf_prefix "$pf_prefix 4 $trace_type $option:" + + gdb_test_no_output "set breakpoint always-inserted ${option}" + gdb_test "break marker" "Breakpoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + gdb_test "break end" "Breakpoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + + gdb_test "break set_point" "Breakpoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at 0x\[0-9a-fA-F\]+: file.*" + + gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker" + # Detele tracepoint set on set_point. + gdb_test "delete trace 5" + + gdb_test "tstart" "No tracepoints defined, not starting trace.*" + + gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to set_point" + gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" + gdb_test "tstop" "Trace is not running.*" + + gdb_test "tfind" "Target failed to find requested trace frame\\..*" + + 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} + break_trace_same_addr_3 "trace" ${break_always_inserted} + break_trace_same_addr_4 "trace" ${break_always_inserted} +} + +gdb_exit + +set libipa $objdir/../gdbserver/libinproctrace.so + +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ + executable [list debug nowarnings shlib=$libipa] ] != "" } { + untested trace-break.exp + return -1 +} + +gdb_start +gdb_load ${binfile} + +runto_main +gdb_reinitialize_dir $srcdir/$subdir +gdb_test "info sharedlibrary" ".*libinproctrace\.so.*" "check libinproctrace.so" + +foreach break_always_inserted { "on" "off" } { + break_trace_same_addr_1 "ftrace" ${break_always_inserted} + break_trace_same_addr_2 "trace" "ftrace" ${break_always_inserted} + break_trace_same_addr_2 "ftrace" "trace" ${break_always_inserted} + break_trace_same_addr_3 "ftrace" ${break_always_inserted} + break_trace_same_addr_4 "ftrace" ${break_always_inserted} +} -- 1.7.0.4