1 # Copyright 2011-2012 Free Software Foundation, Inc.
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 3 of the License, or
5 # (at your option) any later version.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 load_lib "trace-support.exp";
21 if {[skip_shlib_tests]} {
25 set testfile "pending"
26 set libfile1 "pendshr1"
27 set libfile2 "pendshr2"
28 set executable $testfile
29 set srcfile $testfile.c
30 set libsrc1 $srcdir/$subdir/$libfile1.c
31 set libsrc2 $srcdir/$subdir/$libfile2.c
32 set binfile $objdir/$subdir/$testfile
33 set lib_sl1 $objdir/$subdir/$libfile1.sl
34 set lib_sl2 $objdir/$subdir/$libfile2.sl
36 set lib_opts [gdb_target_symbol_prefix_flags]
38 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
39 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""} {
40 untested "Could not compile either $libsrc1 or $libsrc2"
44 set exec_opts [list debug shlib=$lib_sl1 shlib_load]
45 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
46 untested "Failed to compile $srcfile"
50 clean_restart $executable
52 gdb_load_shlibs $lib_sl1
53 gdb_load_shlibs $lib_sl2
56 fail "Can't run to main to check for trace support"
60 if ![gdb_target_supports_trace] {
61 unsupported "Current target does not support trace"
65 # Verify pending tracepoint is resolved to running to main.
67 proc pending_tracepoint_resolved { trace_type } {
75 set old_pf_prefix $pf_prefix
76 lappend pf_prefix "$trace_type" "resolved:"
78 # Start with a fresh gdb.
81 gdb_reinitialize_dir $srcdir/$subdir
83 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
84 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
85 gdb_test "y" "\(Fast t|T\)racepoint.*set_point1.*pending." \
86 "set pending tracepoint (without symbols)"
90 gdb_test "info trace" \
91 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
92 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
93 "single pending tracepoint info (without symbols)"
97 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
101 gdb_test "" "Breakpoint 2, main.*"
103 # Run to main which should resolve a pending tracepoint
104 gdb_test "info trace" \
105 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
106 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc.*" \
107 "single tracepoint info"
109 set pf_prefix $old_pf_prefix
112 # Verify pending tracepoint is resolved and works as expected.
114 proc pending_tracepoint_works { trace_type } {
121 set old_pf_prefix $pf_prefix
122 lappend pf_prefix "$trace_type" "works:"
124 # Restart with a fresh gdb.
125 clean_restart $executable
127 # Test setting and querying pending tracepoints
129 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
130 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
131 gdb_test "y" "\(Fast t|T\)racepoint.*set_point1.*pending." "set pending tracepoint"
135 gdb_test "info trace" \
136 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
137 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
138 "single pending tracepoint info"
140 # Run to main which should resolve a pending tracepoint
141 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
142 "breakpoint function"
144 gdb_test "" "Breakpoint 2, main.*"
146 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
147 "breakpoint on marker"
149 gdb_test_no_output "tstart" "start trace experiment"
151 gdb_test_multiple "continue" "continue to marker" {
152 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
153 pass "continue to marker"
155 -re ".*$gdb_prompt $" {
156 kfail "gdb/13392" "continue to marker"
157 set pf_prefix $old_pf_prefix
162 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
164 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
165 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind test frame 1"
166 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind test frame 2"
167 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
169 set pf_prefix $old_pf_prefix
172 # Verify pending tracepoint is resolved during trace.
174 proc pending_tracepoint_resolved_during_trace { trace_type } {
181 set old_pf_prefix $pf_prefix
182 lappend pf_prefix "$trace_type" "resolved_in_trace:"
184 # Start with a fresh gdb.
185 clean_restart $executable
187 fail "Can't run to main"
188 set pf_prefix $old_pf_prefix
192 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
193 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
194 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
195 "set pending tracepoint (without symbols)"
199 gdb_test "info trace" \
200 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
201 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
202 "single pending tracepoint on set_point2"
204 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
205 "breakpoint on marker"
207 gdb_test_no_output "tstart" "start trace experiment"
209 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
210 "continue to marker 1"
212 gdb_test_multiple "continue" "continue to marker 2" {
213 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
214 pass "continue to marker 2"
216 -re ".*$gdb_prompt $" {
217 kfail "gdb/13392" "continue to marker 2"
218 set pf_prefix $old_pf_prefix
223 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
225 # tracepoint should be resolved.
226 gdb_test "info trace" \
227 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
228 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
229 "tracepoint is resolved"
231 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
232 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
234 set pf_prefix $old_pf_prefix
237 # Verify pending tracepoint is resolved and installed during trace.
239 proc pending_tracepoint_installed_during_trace { trace_type } {
247 set old_pf_prefix $pf_prefix
248 lappend pf_prefix "$trace_type" "installed_in_trace:"
250 # Start with a fresh gdb.
251 clean_restart $executable
253 fail "Can't run to main"
254 set pf_prefix $old_pf_prefix
259 gdb_test "trace main" "Tracepoint \[0-9\] at .*" "set tracepoint on main"
261 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
262 "breakpoint on marker"
264 gdb_test_no_output "tstart" "start trace experiment"
266 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*${srcfile}.*" \
267 "continue to marker 1"
269 # Set a pending tracepoint during a tracing experiment.
270 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
271 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
272 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
273 "set pending tracepoint"
277 gdb_test "info trace" \
278 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
279 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \t\]+keep y.*PENDING.*set_point2.*" \
280 "single pending tracepoint on set_point2"
282 gdb_test_multiple "continue" "continue to marker 2" {
283 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
284 pass "continue to marker 2"
286 -re ".*$gdb_prompt $" {
287 kfail "gdb/13392" "continue to marker 2"
288 set pf_prefix $old_pf_prefix
293 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
295 # tracepoint should be resolved.
296 gdb_test "info trace" \
297 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
298 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
299 "tracepoint is resolved"
301 gdb_test "tfind start" "#0 $hex in pendfunc2 .*" "tfind test frame 0"
302 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
304 set pf_prefix $old_pf_prefix
308 # Verify pending tracepoint will no longer work if we disconnect during tracing.
310 proc pending_tracepoint_disconnect_during_trace { trace_type } {
317 set old_pf_prefix $pf_prefix
318 lappend pf_prefix "$trace_type" "disconn:"
320 # Start with a fresh gdb.
321 clean_restart $executable
323 fail "Can't run to main"
324 set pf_prefix $old_pf_prefix
328 gdb_test_multiple "trace pendfunc3" "set pending tracepoint on set_point2" {
329 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
330 gdb_test "y" "\(Fast t|T\)racepoint.*pendfunc3.*pending." \
331 "set pending tracepoint on pendfun3"
335 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
336 "breakpoint on marker"
338 gdb_test_no_output "tstart" "start trace experiment"
340 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
343 set test "disconnect with pending tracepoint"
344 gdb_test_multiple "disconnect" $test {
345 -re "warning: Pending tracepoints will not be resolved while GDB is disconnected.*Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
348 set test "disconnected"
349 gdb_test_multiple "y" $test {
350 -re "$gdb_prompt $" {
357 set pf_prefix $old_pf_prefix
361 # Verify disconnect after pending tracepoint has been resolved.
363 proc pending_tracepoint_disconnect_after_resolved { trace_type } {
370 set old_pf_prefix $pf_prefix
371 lappend pf_prefix "$trace_type" "disconn_resolved:"
373 # Start with a fresh gdb.
374 clean_restart $executable
376 fail "Can't run to main"
377 set pf_prefix $old_pf_prefix
381 gdb_test_multiple "trace set_point2" "set pending tracepoint on set_point2" {
382 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
383 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
384 "set pending tracepoint on pendfun2"
388 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
389 "breakpoint on marker"
391 gdb_test_no_output "tstart" "start trace experiment"
393 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
394 "continue to marker 1"
395 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
396 "continue to marker 2"
398 # There should be no pending tracepoint, so no warning should be emitted.
399 set test "disconnect with resolved tracepoint"
400 gdb_test_multiple "disconnect" $test {
401 -re "warning: Pending tracepoints will not be resolved while GDB is disconnected.*Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
404 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
408 set test "disconnected"
409 gdb_test_multiple "y" $test {
410 -re "$gdb_prompt $" {
415 set pf_prefix $old_pf_prefix
418 # Verify action works properly in resolved tracepoint.
420 proc pending_tracepoint_with_action_resolved { trace_type } {
427 set old_pf_prefix $pf_prefix
428 lappend pf_prefix "$trace_type" "action_resolved:"
430 # Start with a fresh gdb.
431 clean_restart $executable
433 fail "Can't run to main"
434 set pf_prefix $old_pf_prefix
438 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
439 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
440 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
441 "set pending tracepoint (without symbols)"
446 if [is_amd64_regs_target] {
448 } elseif [is_x86_like_target] {
452 gdb_trace_setactions "set action for pending tracepoint" "" \
453 "collect \$$pcreg" "^$"
455 gdb_test "info trace" \
456 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
457 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
458 "single pending tracepoint on set_point2"
460 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
461 "breakpoint on marker"
463 gdb_test_no_output "tstart" "start trace experiment"
465 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
466 "continue to marker 1"
468 gdb_test_multiple "continue" "continue to marker 2" {
469 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
470 pass "continue to marker 2"
472 -re ".*$gdb_prompt $" {
473 kfail "gdb/13392" "continue to marker 2"
474 set pf_prefix $old_pf_prefix
479 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
481 # tracepoint should be resolved.
482 gdb_test "info trace" \
483 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
484 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
485 "tracepoint is resolved"
487 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
488 gdb_test "tdump" "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*"
489 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
491 set pf_prefix $old_pf_prefix
494 pending_tracepoint_resolved "trace"
496 pending_tracepoint_works "trace"
498 pending_tracepoint_resolved_during_trace "trace"
500 pending_tracepoint_disconnect_during_trace "trace"
502 pending_tracepoint_disconnect_after_resolved "trace"
504 pending_tracepoint_with_action_resolved "trace"
506 pending_tracepoint_installed_during_trace "trace"
508 # Re-compile test case with IPA.
509 set libipa $objdir/../gdbserver/libinproctrace.so
510 gdb_load_shlibs $libipa
512 lappend exec_opts "shlib=$libipa"
514 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
515 untested "Failed to compile $srcfile"
519 pending_tracepoint_resolved "ftrace"
520 pending_tracepoint_works "ftrace"
521 pending_tracepoint_resolved_during_trace "ftrace"
522 pending_tracepoint_disconnect_during_trace "ftrace"
523 pending_tracepoint_disconnect_after_resolved "ftrace"
524 pending_tracepoint_with_action_resolved "ftrace"
525 pending_tracepoint_installed_during_trace "ftrace"