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 } { with_test_prefix "$trace_type resolved" {
70 # Start with a fresh gdb.
73 gdb_reinitialize_dir $srcdir/$subdir
75 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
76 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
77 gdb_test "y" "\(Fast t|T\)racepoint.*set_point1.*pending." \
78 "set pending tracepoint (without symbols)"
82 gdb_test "info trace" \
83 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
84 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
85 "single pending tracepoint info (without symbols)"
89 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
93 gdb_test "" "Breakpoint 2, main.*"
95 # Run to main which should resolve a pending tracepoint
96 gdb_test "info trace" \
97 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
98 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc.*" \
99 "single tracepoint info"
102 # Verify pending tracepoint is resolved and works as expected.
104 proc pending_tracepoint_works { trace_type } { with_test_prefix "$trace_type works" {
110 # Restart with a fresh gdb.
111 clean_restart $executable
113 # Test setting and querying pending tracepoints
115 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
116 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
117 gdb_test "y" "\(Fast t|T\)racepoint.*set_point1.*pending." "set pending tracepoint"
121 gdb_test "info trace" \
122 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
123 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
124 "single pending tracepoint info"
126 # Run to main which should resolve a pending tracepoint
127 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
128 "breakpoint function"
130 gdb_test "" "Breakpoint 2, main.*"
132 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
133 "breakpoint on marker"
135 set test "start trace experiment"
136 gdb_test_multiple "tstart" $test {
137 -re "^tstart\r\n$gdb_prompt $" {
140 -re "Target returns error code .* too far .*$gdb_prompt $" {
141 if [string equal $trace_type "ftrace"] {
142 # The target was unable to install the fast tracepoint
143 # (e.g., jump pad too far from tracepoint).
144 pass "$test (too far)"
145 # Skip the rest of the tests.
154 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*" \
157 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
159 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
160 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind test frame 1"
161 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind test frame 2"
162 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
165 # Verify pending tracepoint is resolved during trace.
167 proc pending_tracepoint_resolved_during_trace { trace_type } \
168 { with_test_prefix "$trace_type resolved_in_trace" \
175 # Start with a fresh gdb.
176 clean_restart $executable
178 fail "Can't run to main"
182 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
183 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
184 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
185 "set pending tracepoint (without symbols)"
189 gdb_test "info trace" \
190 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
191 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
192 "single pending tracepoint on set_point2"
194 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
195 "breakpoint on marker"
197 gdb_test_no_output "tstart" "start trace experiment"
199 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
200 "continue to marker 1"
202 set test "continue to marker 2"
203 gdb_test_multiple "continue" $test {
204 -re "Target returns error code .* too far .*$gdb_prompt $" {
205 if [string equal $trace_type "ftrace"] {
206 # Expected if the target was unable to install the
207 # fast tracepoint (e.g., jump pad too far from
209 pass "$test (too far)"
210 # Skip the rest of the tests.
216 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
221 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
223 # tracepoint should be resolved.
224 gdb_test "info trace" \
225 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
226 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
227 "tracepoint is resolved"
229 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
230 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
233 # Verify pending tracepoint is resolved and installed during trace.
235 proc pending_tracepoint_installed_during_trace { trace_type } \
236 { with_test_prefix "$trace_type installed_in_trace" \
244 # Start with a fresh gdb.
245 clean_restart $executable
247 fail "Can't run to main"
252 gdb_test "trace main" "Tracepoint \[0-9\] at .*" "set tracepoint on main"
254 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
255 "breakpoint on marker"
257 gdb_test_no_output "tstart" "start trace experiment"
259 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*${srcfile}.*" \
260 "continue to marker 1"
262 # Set a pending tracepoint during a tracing experiment.
263 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
264 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
265 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
266 "set pending tracepoint"
270 gdb_test "info trace" \
271 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
272 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \t\]+keep y.*PENDING.*set_point2.*" \
273 "single pending tracepoint on set_point2"
275 set test "continue to marker 2"
276 gdb_test_multiple "continue" $test {
277 -re "Target returns error code .* too far .*$gdb_prompt $" {
278 if [string equal $trace_type "ftrace"] {
279 # Expected if the target was unable to install the
280 # fast tracepoint (e.g., jump pad too far from
282 pass "$test (too far)"
283 # Skip the rest of the tests.
289 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
294 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
296 # tracepoint should be resolved.
297 gdb_test "info trace" \
298 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
299 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
300 "tracepoint is resolved"
302 gdb_test "tfind start" "#0 $hex in pendfunc2 .*" "tfind test frame 0"
303 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
307 # Verify pending tracepoint will no longer work if we disconnect during tracing.
309 proc pending_tracepoint_disconnect_during_trace { trace_type } \
310 { with_test_prefix "$trace_type disconn" \
317 # Start with a fresh gdb.
318 clean_restart $executable
320 fail "Can't run to main"
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 $" {
355 # Verify disconnect after pending tracepoint has been resolved.
357 proc pending_tracepoint_disconnect_after_resolved { trace_type } \
358 { with_test_prefix "$trace_type disconn_resolved" \
365 # Start with a fresh gdb.
366 clean_restart $executable
368 fail "Can't run to main"
372 gdb_test_multiple "trace set_point2" "set pending tracepoint on set_point2" {
373 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
374 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
375 "set pending tracepoint on pendfun2"
379 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
380 "breakpoint on marker"
382 gdb_test_no_output "tstart" "start trace experiment"
384 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
385 "continue to marker 1"
386 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
387 "continue to marker 2"
389 # There should be no pending tracepoint, so no warning should be emitted.
390 set test "disconnect with resolved tracepoint"
391 gdb_test_multiple "disconnect" $test {
392 -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\\) $" {
395 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
399 set test "disconnected"
400 gdb_test_multiple "y" $test {
401 -re "$gdb_prompt $" {
407 # Verify action works properly in resolved tracepoint.
409 proc pending_tracepoint_with_action_resolved { trace_type } \
410 { with_test_prefix "$trace_type action_resolved" \
417 # Start with a fresh gdb.
418 clean_restart $executable
420 fail "Can't run to main"
424 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
425 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
426 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
427 "set pending tracepoint (without symbols)"
432 if [is_amd64_regs_target] {
434 } elseif [is_x86_like_target] {
438 gdb_trace_setactions "set action for pending tracepoint" "" \
439 "collect \$$pcreg" "^$"
441 gdb_test "info trace" \
442 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
443 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
444 "single pending tracepoint on set_point2"
446 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
447 "breakpoint on marker"
449 gdb_test_no_output "tstart" "start trace experiment"
451 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
452 "continue to marker 1"
454 set test "continue to marker 2"
455 gdb_test_multiple "continue" $test {
456 -re "Target returns error code .* too far .*$gdb_prompt $" {
457 if [string equal $trace_type "ftrace"] {
458 # Expected if the target was unable to install the
459 # fast tracepoint (e.g., jump pad too far from
461 pass "$test (too far)"
462 # Skip the rest of the tests.
468 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
469 pass "continue to marker 2"
474 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
476 # tracepoint should be resolved.
477 gdb_test "info trace" \
478 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
479 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
480 "tracepoint is resolved"
482 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
483 gdb_test "tdump" "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*"
484 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
487 pending_tracepoint_resolved "trace"
489 pending_tracepoint_works "trace"
491 pending_tracepoint_resolved_during_trace "trace"
493 pending_tracepoint_disconnect_during_trace "trace"
495 pending_tracepoint_disconnect_after_resolved "trace"
497 pending_tracepoint_with_action_resolved "trace"
499 pending_tracepoint_installed_during_trace "trace"
501 # Re-compile test case with IPA.
502 set libipa [get_in_proc_agent]
503 gdb_load_shlibs $libipa
505 lappend exec_opts "shlib=$libipa"
507 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
508 untested "Failed to compile $srcfile"
512 pending_tracepoint_resolved "ftrace"
513 pending_tracepoint_works "ftrace"
514 pending_tracepoint_resolved_during_trace "ftrace"
515 pending_tracepoint_disconnect_during_trace "ftrace"
516 pending_tracepoint_disconnect_after_resolved "ftrace"
517 pending_tracepoint_with_action_resolved "ftrace"
518 pending_tracepoint_installed_during_trace "ftrace"