1 # Copyright 2011-2020 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 if ![gdb_trace_common_supports_arch] {
22 unsupported "no trace-common.h support for arch"
27 set libfile1 "pendshr1"
28 set libfile2 "pendshr2"
29 set executable $testfile
30 set libsrc1 $srcdir/$subdir/$libfile1.c
31 set libsrc2 $srcdir/$subdir/$libfile2.c
32 set lib_sl1 [standard_output_file $libfile1.sl]
33 set lib_sl2 [standard_output_file $libfile2.sl]
35 set lib_opts [gdb_target_symbol_prefix_flags]
37 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
38 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""} {
39 untested "failed to compile shared library"
43 set exec_opts [list debug shlib=$lib_sl1 shlib_load]
44 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
45 untested "failed to compile"
49 clean_restart $executable
51 gdb_load_shlib $lib_sl1
52 gdb_load_shlib $lib_sl2
55 fail "can't run to main to check for trace support"
59 if ![gdb_target_supports_trace] {
60 unsupported "current target does not support trace"
64 # Verify pending tracepoint is resolved to running to main.
66 proc pending_tracepoint_resolved { trace_type } {
67 with_test_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"
107 # Verify pending tracepoint is resolved and works as expected.
109 proc pending_tracepoint_works { trace_type } {
110 with_test_prefix "$trace_type works" {
116 # Restart with a fresh gdb.
117 clean_restart $executable
119 # Test setting and querying pending tracepoints
121 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
122 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
124 "\(Fast t|T\)racepoint.*set_point1.*pending." \
125 "set pending tracepoint"
129 gdb_test "info trace" \
130 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
131 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
132 "single pending tracepoint info"
134 # Run to main which should resolve a pending tracepoint
135 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
136 "breakpoint function"
138 gdb_test "" "Breakpoint 2, main.*"
140 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
141 "breakpoint on marker"
143 set test "start trace experiment"
144 gdb_test_multiple "tstart" $test {
145 -re "^tstart\r\n$gdb_prompt $" {
148 -re "Target returns error code .* too far .*$gdb_prompt $" {
149 if [string equal $trace_type "ftrace"] {
150 # The target was unable to install the fast tracepoint
151 # (e.g., jump pad too far from tracepoint).
152 pass "$test (too far)"
153 # Skip the rest of the tests.
162 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*$srcfile.*" \
165 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
167 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
168 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" \
170 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" \
173 "Target failed to find requested trace frame..*" \
178 # Verify pending tracepoint is resolved during trace.
180 proc pending_tracepoint_resolved_during_trace { trace_type } \
181 { with_test_prefix "$trace_type resolved_in_trace" \
188 # Start with a fresh gdb.
189 clean_restart $executable
191 fail "can't run to main"
195 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
196 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
197 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
198 "set pending tracepoint (without symbols)"
202 gdb_test "info trace" \
203 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
204 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
205 "single pending tracepoint on set_point2"
207 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
208 "breakpoint on marker"
210 gdb_test_no_output "tstart" "start trace experiment"
212 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
213 "continue to marker 1"
215 set test "continue to marker 2"
216 gdb_test_multiple "continue" $test {
217 -re "Target returns error code .* too far .*$gdb_prompt $" {
218 if [string equal $trace_type "ftrace"] {
219 # Expected if the target was unable to install the
220 # fast tracepoint (e.g., jump pad too far from
222 pass "$test (too far)"
223 # Skip the rest of the tests.
229 -re "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\n(Thread .* hit )?Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
234 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
236 # tracepoint should be resolved.
237 gdb_test "info trace" \
238 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
239 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
240 "tracepoint is resolved"
242 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
243 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
246 # Verify pending tracepoint is resolved and installed during trace.
248 proc pending_tracepoint_installed_during_trace { trace_type } \
249 { with_test_prefix "$trace_type installed_in_trace" \
257 # Start with a fresh gdb.
258 clean_restart $executable
260 fail "can't run to main"
265 gdb_test "trace main" "Tracepoint \[0-9\] at .*" "set tracepoint on main"
267 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
268 "breakpoint on marker"
270 gdb_test_no_output "tstart" "start trace experiment"
272 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*${srcfile}.*" \
273 "continue to marker 1"
275 # Set a pending tracepoint during a tracing experiment.
276 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
277 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
278 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
279 "set pending tracepoint"
283 gdb_test "info trace" \
284 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
285 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \t\]+keep y.*PENDING.*set_point2.*" \
286 "single pending tracepoint on set_point2"
288 set test "continue to marker 2"
289 gdb_test_multiple "continue" $test {
290 -re "Target returns error code .* too far .*$gdb_prompt $" {
291 if [string equal $trace_type "ftrace"] {
292 # Expected if the target was unable to install the
293 # fast tracepoint (e.g., jump pad too far from
295 pass "$test (too far)"
296 # Skip the rest of the tests.
302 -re "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\n(Thread .* hit )?Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
307 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
309 # tracepoint should be resolved.
310 gdb_test "info trace" \
311 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
312 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
313 "tracepoint is resolved"
315 # powerpc64 shows "in .pendfunc2" here.
316 gdb_test "tfind start" "#0 $hex in .?pendfunc2 .*" "tfind test frame 0"
317 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
321 # Verify pending tracepoint will no longer work if we disconnect during tracing.
323 proc pending_tracepoint_disconnect_during_trace { trace_type } \
324 { with_test_prefix "$trace_type disconn" \
331 # Start with a fresh gdb.
332 clean_restart $executable
334 fail "can't run to main"
338 gdb_test_multiple "trace pendfunc3" "set pending tracepoint on set_point2" {
339 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
340 gdb_test "y" "\(Fast t|T\)racepoint.*pendfunc3.*pending." \
341 "set pending tracepoint on pendfun3"
345 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
346 "breakpoint on marker"
348 gdb_test_no_output "tstart" "start trace experiment"
350 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
353 set test "disconnect with pending tracepoint"
354 gdb_test_multiple "disconnect" $test {
355 -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\\) $" {
358 set test "disconnected"
359 gdb_test_multiple "y" $test {
360 -re "$gdb_prompt $" {
369 # Verify disconnect after pending tracepoint has been resolved.
371 proc pending_tracepoint_disconnect_after_resolved { trace_type } \
372 { with_test_prefix "$trace_type disconn_resolved" \
379 # Start with a fresh gdb.
380 clean_restart $executable
382 fail "can't run to main"
386 gdb_test_multiple "trace set_point2" "set pending tracepoint on set_point2" {
387 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
388 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
389 "set pending tracepoint on pendfun2"
393 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
394 "breakpoint on marker"
396 gdb_test_no_output "tstart" "start trace experiment"
398 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
399 "continue to marker 1"
400 gdb_test "continue" "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
401 "continue to marker 2"
403 # There should be no pending tracepoint, so no warning should be emitted.
404 set test "disconnect with resolved tracepoint"
405 gdb_test_multiple "disconnect" $test {
406 -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\\) $" {
409 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
413 set test "disconnected"
414 gdb_test_multiple "y" $test {
415 -re "$gdb_prompt $" {
421 # Verify action works properly in resolved tracepoint.
423 proc pending_tracepoint_with_action_resolved { trace_type } \
424 { with_test_prefix "$trace_type action_resolved" \
432 # Start with a fresh gdb.
433 clean_restart $executable
435 fail "can't run to main"
439 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
440 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
441 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
442 "set pending tracepoint (without symbols)"
446 gdb_trace_setactions "set action for pending tracepoint" "" \
447 "collect \$$pcreg" "^$"
449 gdb_test "info trace" \
450 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
451 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
452 "single pending tracepoint on set_point2"
454 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
455 "breakpoint on marker"
457 gdb_test_no_output "tstart" "start trace experiment"
459 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
460 "continue to marker 1"
462 set test "continue to marker 2"
463 gdb_test_multiple "continue" $test {
464 -re "Target returns error code .* too far .*$gdb_prompt $" {
465 if [string equal $trace_type "ftrace"] {
466 # Expected if the target was unable to install the
467 # fast tracepoint (e.g., jump pad too far from
469 pass "$test (too far)"
470 # Skip the rest of the tests.
476 -re "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\n(Thread .* hit )?Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
477 pass "continue to marker 2"
482 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
484 # tracepoint should be resolved.
485 gdb_test "info trace" \
486 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
487 \[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
488 "tracepoint is resolved"
490 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
491 gdb_test "tdump" "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*"
492 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
495 pending_tracepoint_resolved "trace"
497 pending_tracepoint_works "trace"
499 pending_tracepoint_resolved_during_trace "trace"
501 pending_tracepoint_disconnect_during_trace "trace"
503 pending_tracepoint_disconnect_after_resolved "trace"
505 pending_tracepoint_with_action_resolved "trace"
507 pending_tracepoint_installed_during_trace "trace"
509 # Re-compile test case with IPA.
510 set libipa [get_in_proc_agent]
511 gdb_load_shlib $libipa
513 lappend exec_opts "shlib=$libipa"
515 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
516 untested "failed to compile with in-process agent library"
520 pending_tracepoint_resolved "ftrace"
521 pending_tracepoint_works "ftrace"
522 pending_tracepoint_resolved_during_trace "ftrace"
523 pending_tracepoint_disconnect_during_trace "ftrace"
524 pending_tracepoint_disconnect_after_resolved "ftrace"
525 pending_tracepoint_with_action_resolved "ftrace"
526 pending_tracepoint_installed_during_trace "ftrace"