1 # Copyright 2011-2013 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]} {
22 set libfile1 "pendshr1"
23 set libfile2 "pendshr2"
24 set executable $testfile
25 set libsrc1 $srcdir/$subdir/$libfile1.c
26 set libsrc2 $srcdir/$subdir/$libfile2.c
27 set lib_sl1 [standard_output_file $libfile1.sl]
28 set lib_sl2 [standard_output_file $libfile2.sl]
30 set lib_opts [gdb_target_symbol_prefix_flags]
32 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
33 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""} {
34 untested "Could not compile either $libsrc1 or $libsrc2"
38 set exec_opts [list debug shlib=$lib_sl1 shlib_load]
39 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
40 untested "Failed to compile $srcfile"
44 clean_restart $executable
46 gdb_load_shlibs $lib_sl1
47 gdb_load_shlibs $lib_sl2
50 fail "Can't run to main to check for trace support"
54 if ![gdb_target_supports_trace] {
55 unsupported "Current target does not support trace"
59 # Verify pending tracepoint is resolved to running to main.
61 proc pending_tracepoint_resolved { trace_type } { with_test_prefix "$trace_type resolved" {
68 # Start with a fresh gdb.
71 gdb_reinitialize_dir $srcdir/$subdir
73 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
74 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
75 gdb_test "y" "\(Fast t|T\)racepoint.*set_point1.*pending." \
76 "set pending tracepoint (without symbols)"
80 gdb_test "info trace" \
81 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
82 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
83 "single pending tracepoint info (without symbols)"
87 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
91 gdb_test "" "Breakpoint 2, main.*"
93 # Run to main which should resolve a pending tracepoint
94 gdb_test "info trace" \
95 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
96 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc.*" \
97 "single tracepoint info"
100 # Verify pending tracepoint is resolved and works as expected.
102 proc pending_tracepoint_works { trace_type } { with_test_prefix "$trace_type works" {
108 # Restart with a fresh gdb.
109 clean_restart $executable
111 # Test setting and querying pending tracepoints
113 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
114 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
115 gdb_test "y" "\(Fast t|T\)racepoint.*set_point1.*pending." "set pending tracepoint"
119 gdb_test "info trace" \
120 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
121 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
122 "single pending tracepoint info"
124 # Run to main which should resolve a pending tracepoint
125 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
126 "breakpoint function"
128 gdb_test "" "Breakpoint 2, main.*"
130 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
131 "breakpoint on marker"
133 set test "start trace experiment"
134 gdb_test_multiple "tstart" $test {
135 -re "^tstart\r\n$gdb_prompt $" {
138 -re "Target returns error code .* too far .*$gdb_prompt $" {
139 if [string equal $trace_type "ftrace"] {
140 # The target was unable to install the fast tracepoint
141 # (e.g., jump pad too far from tracepoint).
142 pass "$test (too far)"
143 # Skip the rest of the tests.
152 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*" \
155 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
157 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
158 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind test frame 1"
159 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind test frame 2"
160 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
163 # Verify pending tracepoint is resolved during trace.
165 proc pending_tracepoint_resolved_during_trace { trace_type } \
166 { with_test_prefix "$trace_type resolved_in_trace" \
173 # Start with a fresh gdb.
174 clean_restart $executable
176 fail "Can't run to main"
180 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
181 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
182 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
183 "set pending tracepoint (without symbols)"
187 gdb_test "info trace" \
188 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
189 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
190 "single pending tracepoint on set_point2"
192 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
193 "breakpoint on marker"
195 gdb_test_no_output "tstart" "start trace experiment"
197 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
198 "continue to marker 1"
200 set test "continue to marker 2"
201 gdb_test_multiple "continue" $test {
202 -re "Target returns error code .* too far .*$gdb_prompt $" {
203 if [string equal $trace_type "ftrace"] {
204 # Expected if the target was unable to install the
205 # fast tracepoint (e.g., jump pad too far from
207 pass "$test (too far)"
208 # Skip the rest of the tests.
214 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
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"
231 # Verify pending tracepoint is resolved and installed during trace.
233 proc pending_tracepoint_installed_during_trace { trace_type } \
234 { with_test_prefix "$trace_type installed_in_trace" \
242 # Start with a fresh gdb.
243 clean_restart $executable
245 fail "Can't run to main"
250 gdb_test "trace main" "Tracepoint \[0-9\] at .*" "set tracepoint on main"
252 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
253 "breakpoint on marker"
255 gdb_test_no_output "tstart" "start trace experiment"
257 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*${srcfile}.*" \
258 "continue to marker 1"
260 # Set a pending tracepoint during a tracing experiment.
261 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
262 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
263 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
264 "set pending tracepoint"
268 gdb_test "info trace" \
269 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
270 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \t\]+keep y.*PENDING.*set_point2.*" \
271 "single pending tracepoint on set_point2"
273 set test "continue to marker 2"
274 gdb_test_multiple "continue" $test {
275 -re "Target returns error code .* too far .*$gdb_prompt $" {
276 if [string equal $trace_type "ftrace"] {
277 # Expected if the target was unable to install the
278 # fast tracepoint (e.g., jump pad too far from
280 pass "$test (too far)"
281 # Skip the rest of the tests.
287 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
292 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
294 # tracepoint should be resolved.
295 gdb_test "info trace" \
296 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
297 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
298 "tracepoint is resolved"
300 gdb_test "tfind start" "#0 $hex in pendfunc2 .*" "tfind test frame 0"
301 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
305 # Verify pending tracepoint will no longer work if we disconnect during tracing.
307 proc pending_tracepoint_disconnect_during_trace { trace_type } \
308 { with_test_prefix "$trace_type disconn" \
315 # Start with a fresh gdb.
316 clean_restart $executable
318 fail "Can't run to main"
322 gdb_test_multiple "trace pendfunc3" "set pending tracepoint on set_point2" {
323 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
324 gdb_test "y" "\(Fast t|T\)racepoint.*pendfunc3.*pending." \
325 "set pending tracepoint on pendfun3"
329 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
330 "breakpoint on marker"
332 gdb_test_no_output "tstart" "start trace experiment"
334 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
337 set test "disconnect with pending tracepoint"
338 gdb_test_multiple "disconnect" $test {
339 -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\\) $" {
342 set test "disconnected"
343 gdb_test_multiple "y" $test {
344 -re "$gdb_prompt $" {
353 # Verify disconnect after pending tracepoint has been resolved.
355 proc pending_tracepoint_disconnect_after_resolved { trace_type } \
356 { with_test_prefix "$trace_type disconn_resolved" \
363 # Start with a fresh gdb.
364 clean_restart $executable
366 fail "Can't run to main"
370 gdb_test_multiple "trace set_point2" "set pending tracepoint on set_point2" {
371 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
372 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
373 "set pending tracepoint on pendfun2"
377 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
378 "breakpoint on marker"
380 gdb_test_no_output "tstart" "start trace experiment"
382 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
383 "continue to marker 1"
384 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
385 "continue to marker 2"
387 # There should be no pending tracepoint, so no warning should be emitted.
388 set test "disconnect with resolved tracepoint"
389 gdb_test_multiple "disconnect" $test {
390 -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\\) $" {
393 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
397 set test "disconnected"
398 gdb_test_multiple "y" $test {
399 -re "$gdb_prompt $" {
405 # Verify action works properly in resolved tracepoint.
407 proc pending_tracepoint_with_action_resolved { trace_type } \
408 { with_test_prefix "$trace_type action_resolved" \
415 # Start with a fresh gdb.
416 clean_restart $executable
418 fail "Can't run to main"
422 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
423 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
424 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
425 "set pending tracepoint (without symbols)"
430 if [is_amd64_regs_target] {
432 } elseif [is_x86_like_target] {
436 gdb_trace_setactions "set action for pending tracepoint" "" \
437 "collect \$$pcreg" "^$"
439 gdb_test "info trace" \
440 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
441 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
442 "single pending tracepoint on set_point2"
444 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
445 "breakpoint on marker"
447 gdb_test_no_output "tstart" "start trace experiment"
449 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
450 "continue to marker 1"
452 set test "continue to marker 2"
453 gdb_test_multiple "continue" $test {
454 -re "Target returns error code .* too far .*$gdb_prompt $" {
455 if [string equal $trace_type "ftrace"] {
456 # Expected if the target was unable to install the
457 # fast tracepoint (e.g., jump pad too far from
459 pass "$test (too far)"
460 # Skip the rest of the tests.
466 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
467 pass "continue to marker 2"
472 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
474 # tracepoint should be resolved.
475 gdb_test "info trace" \
476 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
477 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
478 "tracepoint is resolved"
480 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
481 gdb_test "tdump" "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*"
482 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
485 pending_tracepoint_resolved "trace"
487 pending_tracepoint_works "trace"
489 pending_tracepoint_resolved_during_trace "trace"
491 pending_tracepoint_disconnect_during_trace "trace"
493 pending_tracepoint_disconnect_after_resolved "trace"
495 pending_tracepoint_with_action_resolved "trace"
497 pending_tracepoint_installed_during_trace "trace"
499 # Re-compile test case with IPA.
500 set libipa [get_in_proc_agent]
501 gdb_load_shlibs $libipa
503 lappend exec_opts "shlib=$libipa"
505 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
506 untested "Failed to compile $srcfile"
510 pending_tracepoint_resolved "ftrace"
511 pending_tracepoint_works "ftrace"
512 pending_tracepoint_resolved_during_trace "ftrace"
513 pending_tracepoint_disconnect_during_trace "ftrace"
514 pending_tracepoint_disconnect_after_resolved "ftrace"
515 pending_tracepoint_with_action_resolved "ftrace"
516 pending_tracepoint_installed_during_trace "ftrace"