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";
17 if {[skip_shlib_tests]} {
21 set testfile "pending"
22 set libfile1 "pendshr1"
23 set libfile2 "pendshr2"
24 set executable $testfile
25 set srcfile $testfile.c
26 set libsrc1 $srcdir/$subdir/$libfile1.c
27 set libsrc2 $srcdir/$subdir/$libfile2.c
28 set binfile $objdir/$subdir/$testfile
29 set lib_sl1 $objdir/$subdir/$libfile1.sl
30 set lib_sl2 $objdir/$subdir/$libfile2.sl
32 set lib_opts [gdb_target_symbol_prefix_flags]
34 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
35 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""} {
36 untested "Could not compile either $libsrc1 or $libsrc2"
40 set exec_opts [list debug shlib=$lib_sl1 shlib_load]
41 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
42 untested "Failed to compile $srcfile"
46 clean_restart $executable
48 gdb_load_shlibs $lib_sl1
49 gdb_load_shlibs $lib_sl2
52 fail "Can't run to main to check for trace support"
56 if ![gdb_target_supports_trace] {
57 unsupported "Current target does not support trace"
61 # Verify pending tracepoint is resolved to running to main.
63 proc pending_tracepoint_resolved { trace_type } {
71 set old_pf_prefix $pf_prefix
72 lappend pf_prefix "$trace_type" "resolved:"
74 # Start with a fresh gdb.
77 gdb_reinitialize_dir $srcdir/$subdir
79 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
80 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
81 gdb_test "y" "\(Fast t|T\)racepoint.*set_point1.*pending." \
82 "set pending tracepoint (without symbols)"
86 gdb_test "info trace" \
87 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
88 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
89 "single pending tracepoint info (without symbols)"
93 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
97 gdb_test "" "Breakpoint 2, main.*"
99 # Run to main which should resolve a pending tracepoint
100 gdb_test "info trace" \
101 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
102 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc.*" \
103 "single tracepoint info"
105 set pf_prefix $old_pf_prefix
108 # Verify pending tracepoint is resolved and works as expected.
110 proc pending_tracepoint_works { trace_type } {
117 set old_pf_prefix $pf_prefix
118 lappend pf_prefix "$trace_type" "works:"
120 # Restart with a fresh gdb.
121 clean_restart $executable
123 # Test setting and querying pending tracepoints
125 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
126 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
127 gdb_test "y" "\(Fast t|T\)racepoint.*set_point1.*pending." "set pending tracepoint"
131 gdb_test "info trace" \
132 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
133 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
134 "single pending tracepoint info"
136 # Run to main which should resolve a pending tracepoint
137 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
138 "breakpoint function"
140 gdb_test "" "Breakpoint 2, main.*"
142 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
143 "breakpoint on marker"
145 gdb_test_no_output "tstart" "start trace experiment"
147 gdb_test_multiple "continue" "continue to marker" {
148 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
149 pass "continue to marker"
151 -re ".*$gdb_prompt $" {
152 kfail "gdb/13392" "continue to marker"
153 set pf_prefix $old_pf_prefix
158 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
160 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
161 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind test frame 1"
162 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind test frame 2"
163 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
165 set pf_prefix $old_pf_prefix
168 # Verify pending tracepoint is resolved during trace.
170 proc pending_tracepoint_resolved_during_trace { trace_type } {
177 set old_pf_prefix $pf_prefix
178 lappend pf_prefix "$trace_type" "resolved_in_trace:"
180 # Start with a fresh gdb.
181 clean_restart $executable
183 fail "Can't run to main"
184 set pf_prefix $old_pf_prefix
188 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
189 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
190 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
191 "set pending tracepoint (without symbols)"
195 gdb_test "info trace" \
196 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
197 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
198 "single pending tracepoint on set_point2"
200 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
201 "breakpoint on marker"
203 gdb_test_no_output "tstart" "start trace experiment"
205 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
206 "continue to marker 1"
208 gdb_test_multiple "continue" "continue to marker 2" {
209 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
210 pass "continue to marker 2"
212 -re ".*$gdb_prompt $" {
213 kfail "gdb/13392" "continue to marker 2"
214 set pf_prefix $old_pf_prefix
219 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
221 # tracepoint should be resolved.
222 gdb_test "info trace" \
223 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
224 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
225 "tracepoint is resolved"
227 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
228 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
230 set pf_prefix $old_pf_prefix
233 # Verify pending tracepoint is resolved and installed during trace.
235 proc pending_tracepoint_installed_during_trace { trace_type } {
243 set old_pf_prefix $pf_prefix
244 lappend pf_prefix "$trace_type" "installed_in_trace:"
246 # Start with a fresh gdb.
247 clean_restart $executable
249 fail "Can't run to main"
250 set pf_prefix $old_pf_prefix
255 gdb_test "trace main" "Tracepoint \[0-9\] at .*" "set tracepoint on main"
257 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
258 "breakpoint on marker"
260 gdb_test_no_output "tstart" "start trace experiment"
262 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*${srcfile}.*" \
263 "continue to marker 1"
265 # Set a pending tracepoint during a tracing experiment.
266 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
267 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
268 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
269 "set pending tracepoint"
273 gdb_test "info trace" \
274 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
275 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \t\]+keep y.*PENDING.*set_point2.*" \
276 "single pending tracepoint on set_point2"
278 gdb_test_multiple "continue" "continue to marker 2" {
279 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
280 pass "continue to marker 2"
282 -re ".*$gdb_prompt $" {
283 kfail "gdb/13392" "continue to marker 2"
284 set pf_prefix $old_pf_prefix
289 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
291 # tracepoint should be resolved.
292 gdb_test "info trace" \
293 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
294 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
295 "tracepoint is resolved"
297 gdb_test "tfind start" "#0 $hex in pendfunc2 .*" "tfind test frame 0"
298 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
300 set pf_prefix $old_pf_prefix
304 # Verify pending tracepoint will no longer work if we disconnect during tracing.
306 proc pending_tracepoint_disconnect_during_trace { trace_type } {
313 set old_pf_prefix $pf_prefix
314 lappend pf_prefix "$trace_type" "disconn:"
316 # Start with a fresh gdb.
317 clean_restart $executable
319 fail "Can't run to main"
320 set pf_prefix $old_pf_prefix
324 gdb_test_multiple "trace pendfunc3" "set pending tracepoint on set_point2" {
325 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
326 gdb_test "y" "\(Fast t|T\)racepoint.*pendfunc3.*pending." \
327 "set pending tracepoint on pendfun3"
331 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
332 "breakpoint on marker"
334 gdb_test_no_output "tstart" "start trace experiment"
336 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
339 set test "disconnect with pending tracepoint"
340 gdb_test_multiple "disconnect" $test {
341 -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\\) $" {
344 set test "disconnected"
345 gdb_test_multiple "y" $test {
346 -re "$gdb_prompt $" {
353 set pf_prefix $old_pf_prefix
357 # Verify disconnect after pending tracepoint has been resolved.
359 proc pending_tracepoint_disconnect_after_resolved { trace_type } {
366 set old_pf_prefix $pf_prefix
367 lappend pf_prefix "$trace_type" "disconn_resolved:"
369 # Start with a fresh gdb.
370 clean_restart $executable
372 fail "Can't run to main"
373 set pf_prefix $old_pf_prefix
377 gdb_test_multiple "trace set_point2" "set pending tracepoint on set_point2" {
378 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
379 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
380 "set pending tracepoint on pendfun2"
384 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
385 "breakpoint on marker"
387 gdb_test_no_output "tstart" "start trace experiment"
389 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
390 "continue to marker 1"
391 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
392 "continue to marker 2"
394 # There should be no pending tracepoint, so no warning should be emitted.
395 set test "disconnect with resolved tracepoint"
396 gdb_test_multiple "disconnect" $test {
397 -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\\) $" {
400 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
404 set test "disconnected"
405 gdb_test_multiple "y" $test {
406 -re "$gdb_prompt $" {
411 set pf_prefix $old_pf_prefix
414 # Verify action works properly in resolved tracepoint.
416 proc pending_tracepoint_with_action_resolved { trace_type } {
423 set old_pf_prefix $pf_prefix
424 lappend pf_prefix "$trace_type" "action_resolved:"
426 # Start with a fresh gdb.
427 clean_restart $executable
429 fail "Can't run to main"
430 set pf_prefix $old_pf_prefix
434 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
435 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
436 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
437 "set pending tracepoint (without symbols)"
442 if [is_amd64_regs_target] {
444 } elseif [is_x86_like_target] {
448 gdb_trace_setactions "set action for pending tracepoint" "" \
449 "collect \$$pcreg" "^$"
451 gdb_test "info trace" \
452 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
453 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
454 "single pending tracepoint on set_point2"
456 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
457 "breakpoint on marker"
459 gdb_test_no_output "tstart" "start trace experiment"
461 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
462 "continue to marker 1"
464 gdb_test_multiple "continue" "continue to marker 2" {
465 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
466 pass "continue to marker 2"
468 -re ".*$gdb_prompt $" {
469 kfail "gdb/13392" "continue to marker 2"
470 set pf_prefix $old_pf_prefix
475 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
477 # tracepoint should be resolved.
478 gdb_test "info trace" \
479 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
480 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
481 "tracepoint is resolved"
483 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
484 gdb_test "tdump" "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*"
485 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
487 set pf_prefix $old_pf_prefix
490 pending_tracepoint_resolved "trace"
492 pending_tracepoint_works "trace"
494 pending_tracepoint_resolved_during_trace "trace"
496 pending_tracepoint_disconnect_during_trace "trace"
498 pending_tracepoint_disconnect_after_resolved "trace"
500 pending_tracepoint_with_action_resolved "trace"
502 pending_tracepoint_installed_during_trace "trace"
504 # Re-compile test case with IPA.
505 set libipa $objdir/../gdbserver/libinproctrace.so
506 gdb_load_shlibs $libipa
508 lappend exec_opts "shlib=$libipa"
510 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
511 untested "Failed to compile $srcfile"
515 pending_tracepoint_resolved "ftrace"
516 pending_tracepoint_works "ftrace"
517 pending_tracepoint_resolved_during_trace "ftrace"
518 pending_tracepoint_disconnect_during_trace "ftrace"
519 pending_tracepoint_disconnect_after_resolved "ftrace"
520 pending_tracepoint_with_action_resolved "ftrace"
521 pending_tracepoint_installed_during_trace "ftrace"