]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.trace/pending.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / pending.exp
CommitLineData
213516ef 1# Copyright 2011-2023 Free Software Foundation, Inc.
bfccc43c
YQ
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.
6#
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.
11#
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/>.
14
4ec70201 15load_lib "trace-support.exp"
bfccc43c 16
bfccc43c
YQ
17if {[skip_shlib_tests]} {
18 return 0
19}
20
8bca2978
SL
21if ![gdb_trace_common_supports_arch] {
22 unsupported "no trace-common.h support for arch"
23 return -1
24}
25
497a5eb0 26standard_testfile
bfccc43c
YQ
27set libfile1 "pendshr1"
28set libfile2 "pendshr2"
29set executable $testfile
bfccc43c
YQ
30set libsrc1 $srcdir/$subdir/$libfile1.c
31set libsrc2 $srcdir/$subdir/$libfile2.c
497a5eb0
TT
32set lib_sl1 [standard_output_file $libfile1.sl]
33set lib_sl2 [standard_output_file $libfile2.sl]
bfccc43c
YQ
34
35set lib_opts [gdb_target_symbol_prefix_flags]
36
37if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
38 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""} {
84c93cd5 39 untested "failed to compile shared library"
bfccc43c
YQ
40 return -1
41}
42
43set exec_opts [list debug shlib=$lib_sl1 shlib_load]
44if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
84c93cd5 45 untested "failed to compile"
bfccc43c
YQ
46 return -1
47}
48
49clean_restart $executable
50
d9019901
SM
51gdb_load_shlib $lib_sl1
52gdb_load_shlib $lib_sl2
bfccc43c
YQ
53
54if ![runto_main] {
bfccc43c
YQ
55 return -1
56}
57
58if ![gdb_target_supports_trace] {
bc6c7af4 59 unsupported "current target does not support trace"
ae59b1da 60 return -1
bfccc43c
YQ
61}
62
63# Verify pending tracepoint is resolved to running to main.
64
0a251e08
YQ
65proc pending_tracepoint_resolved { trace_type } {
66 with_test_prefix "$trace_type resolved" {
67 global srcdir
68 global subdir
69 global binfile
70 global srcfile
71 global lib_sl1
72
73 # Start with a fresh gdb.
74 gdb_exit
75 gdb_start
76 gdb_reinitialize_dir $srcdir/$subdir
77
78 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
79 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
80 gdb_test "y" "\(Fast t|T\)racepoint.*set_point1.*pending." \
81 "set pending tracepoint (without symbols)"
82 }
bfccc43c 83 }
bfccc43c 84
0a251e08
YQ
85 gdb_test "info trace" \
86 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
bfccc43c 87\[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
0a251e08 88 "single pending tracepoint info (without symbols)"
bfccc43c 89
0a251e08 90 gdb_load ${binfile}
bfccc43c 91
e777225b 92 gdb_test "break -q main" "Breakpoint.*at.* file .*$srcfile, line.*" \
0a251e08 93 "breakpoint function"
bfccc43c 94
0a251e08
YQ
95 gdb_run_cmd
96 gdb_test "" "Breakpoint 2, main.*"
bfccc43c 97
0a251e08
YQ
98 # Run to main which should resolve a pending tracepoint
99 gdb_test "info trace" \
100 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
bfccc43c 101\[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc.*" \
0a251e08
YQ
102 "single tracepoint info"
103 }
104}
bfccc43c
YQ
105
106# Verify pending tracepoint is resolved and works as expected.
107
0a251e08
YQ
108proc pending_tracepoint_works { trace_type } {
109 with_test_prefix "$trace_type works" {
110 global executable
111 global srcfile
112 global lib_sl1
113 global gdb_prompt
bfccc43c 114
0a251e08
YQ
115 # Restart with a fresh gdb.
116 clean_restart $executable
bfccc43c 117
0a251e08 118 # Test setting and querying pending tracepoints
bfccc43c 119
0a251e08
YQ
120 gdb_test_multiple "$trace_type set_point1" "set pending tracepoint" {
121 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
122 gdb_test "y" \
123 "\(Fast t|T\)racepoint.*set_point1.*pending." \
124 "set pending tracepoint"
125 }
bfccc43c 126 }
bfccc43c 127
0a251e08
YQ
128 gdb_test "info trace" \
129 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
bfccc43c 130\[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point1.*" \
0a251e08 131 "single pending tracepoint info"
bfccc43c 132
0a251e08 133 # Run to main which should resolve a pending tracepoint
e777225b 134 gdb_test "break -q main" "Breakpoint.*at.* file .*$srcfile, line.*" \
0a251e08
YQ
135 "breakpoint function"
136 gdb_run_cmd
137 gdb_test "" "Breakpoint 2, main.*"
bfccc43c 138
0a251e08
YQ
139 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
140 "breakpoint on marker"
bfccc43c 141
0a251e08
YQ
142 set test "start trace experiment"
143 gdb_test_multiple "tstart" $test {
144 -re "^tstart\r\n$gdb_prompt $" {
145 pass $test
146 }
147 -re "Target returns error code .* too far .*$gdb_prompt $" {
148 if [string equal $trace_type "ftrace"] {
149 # The target was unable to install the fast tracepoint
150 # (e.g., jump pad too far from tracepoint).
151 pass "$test (too far)"
152 # Skip the rest of the tests.
153 return
154 } else {
155 fail $test
156 }
f4647387 157 }
f4647387 158
0a251e08 159 }
bfccc43c 160
bd0a71fa 161 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*$srcfile.*" \
0a251e08 162 "continue to marker"
f4647387 163
0a251e08 164 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
bfccc43c 165
0a251e08
YQ
166 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
167 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" \
168 "tfind test frame 1"
169 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" \
170 "tfind test frame 2"
171 gdb_test "tfind" \
172 "Target failed to find requested trace frame..*" \
173 "tfind test frame"
174 }
175}
bfccc43c
YQ
176
177# Verify pending tracepoint is resolved during trace.
178
6a5870ce 179proc pending_tracepoint_resolved_during_trace { trace_type } \
0f4d39d5 180{ with_test_prefix "$trace_type resolved_in_trace" \
6a5870ce 181{
bfccc43c
YQ
182 global executable
183 global srcfile
184 global gdb_prompt
185 global lib_sl1
bfccc43c
YQ
186
187 # Start with a fresh gdb.
188 clean_restart $executable
189 if ![runto_main] {
bfccc43c
YQ
190 return -1
191 }
192
193 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
194 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
195 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
196 "set pending tracepoint (without symbols)"
197 }
198 }
199
200 gdb_test "info trace" \
201 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
202\[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
203 "single pending tracepoint on set_point2"
204
205 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
206 "breakpoint on marker"
207
208 gdb_test_no_output "tstart" "start trace experiment"
209
bd0a71fa 210 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
bfccc43c
YQ
211 "continue to marker 1"
212
f4647387
YQ
213 set test "continue to marker 2"
214 gdb_test_multiple "continue" $test {
215 -re "Target returns error code .* too far .*$gdb_prompt $" {
216 if [string equal $trace_type "ftrace"] {
217 # Expected if the target was unable to install the
218 # fast tracepoint (e.g., jump pad too far from
219 # tracepoint).
220 pass "$test (too far)"
221 # Skip the rest of the tests.
222 return
223 } else {
224 fail $test
225 }
bfccc43c 226 }
cc5fd9ab 227 -re "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\n(Thread .* hit )?Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
f4647387 228 pass $test
bfccc43c
YQ
229 }
230 }
231
232 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
233
234 # tracepoint should be resolved.
235 gdb_test "info trace" \
236 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
237\[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
238 "tracepoint is resolved"
239
240 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
241 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
6a5870ce 242}}
bfccc43c
YQ
243
244# Verify pending tracepoint is resolved and installed during trace.
245
6a5870ce 246proc pending_tracepoint_installed_during_trace { trace_type } \
0f4d39d5 247{ with_test_prefix "$trace_type installed_in_trace" \
6a5870ce 248{
bfccc43c
YQ
249 global executable
250 global srcfile
251 global lib_sl1
252 global gdb_prompt
bfccc43c
YQ
253 global hex
254
bfccc43c
YQ
255 # Start with a fresh gdb.
256 clean_restart $executable
257 if ![runto_main] {
bfccc43c
YQ
258 return -1
259 }
260
261 gdb_test "next" ".*"
262 gdb_test "trace main" "Tracepoint \[0-9\] at .*" "set tracepoint on main"
263
264 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
265 "breakpoint on marker"
266
267 gdb_test_no_output "tstart" "start trace experiment"
268
bd0a71fa 269 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*${srcfile}.*" \
bfccc43c
YQ
270 "continue to marker 1"
271
272 # Set a pending tracepoint during a tracing experiment.
273 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
274 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
275 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
276 "set pending tracepoint"
277 }
278 }
279
280 gdb_test "info trace" \
281 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
282\[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \t\]+keep y.*PENDING.*set_point2.*" \
283 "single pending tracepoint on set_point2"
284
f4647387
YQ
285 set test "continue to marker 2"
286 gdb_test_multiple "continue" $test {
287 -re "Target returns error code .* too far .*$gdb_prompt $" {
288 if [string equal $trace_type "ftrace"] {
289 # Expected if the target was unable to install the
290 # fast tracepoint (e.g., jump pad too far from
291 # tracepoint).
292 pass "$test (too far)"
293 # Skip the rest of the tests.
294 return
295 } else {
296 fail $test
297 }
bfccc43c 298 }
bd0a71fa 299 -re "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\n(Thread .* hit )?Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
f4647387
YQ
300 pass $test
301 }
bfccc43c
YQ
302 }
303
304 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
305
306 # tracepoint should be resolved.
307 gdb_test "info trace" \
308 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
309\[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
310 "tracepoint is resolved"
311
b04fd3be
MK
312 # powerpc64 shows "in .pendfunc2" here.
313 gdb_test "tfind start" "#0 $hex in .?pendfunc2 .*" "tfind test frame 0"
bfccc43c 314 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
6a5870ce 315}}
bfccc43c
YQ
316
317
318# Verify pending tracepoint will no longer work if we disconnect during tracing.
319
6a5870ce 320proc pending_tracepoint_disconnect_during_trace { trace_type } \
0f4d39d5 321{ with_test_prefix "$trace_type disconn" \
6a5870ce 322{
bfccc43c
YQ
323 global executable
324 global srcfile
325 global lib_sl1
bfccc43c
YQ
326 global gdb_prompt
327
bfccc43c
YQ
328 # Start with a fresh gdb.
329 clean_restart $executable
330 if ![runto_main] {
bfccc43c
YQ
331 return -1
332 }
333
334 gdb_test_multiple "trace pendfunc3" "set pending tracepoint on set_point2" {
335 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
336 gdb_test "y" "\(Fast t|T\)racepoint.*pendfunc3.*pending." \
337 "set pending tracepoint on pendfun3"
338 }
339 }
340
341 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
342 "breakpoint on marker"
343
344 gdb_test_no_output "tstart" "start trace experiment"
345
bd0a71fa 346 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
bfccc43c
YQ
347 "continue to marker"
348
349 set test "disconnect with pending tracepoint"
350 gdb_test_multiple "disconnect" $test {
351 -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\\) $" {
352 pass $test
353
354 set test "disconnected"
355 gdb_test_multiple "y" $test {
356 -re "$gdb_prompt $" {
357 pass "$test"
358 }
359 }
360 }
361 }
6a5870ce 362}}
bfccc43c
YQ
363
364
365# Verify disconnect after pending tracepoint has been resolved.
366
6a5870ce 367proc pending_tracepoint_disconnect_after_resolved { trace_type } \
0f4d39d5 368{ with_test_prefix "$trace_type disconn_resolved" \
6a5870ce 369{
bfccc43c
YQ
370 global executable
371 global srcfile
372 global lib_sl1
373 global gdb_prompt
bfccc43c
YQ
374
375 # Start with a fresh gdb.
376 clean_restart $executable
377 if ![runto_main] {
bfccc43c
YQ
378 return -1
379 }
380
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"
385 }
386 }
387
388 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
389 "breakpoint on marker"
390
391 gdb_test_no_output "tstart" "start trace experiment"
392
bd0a71fa 393 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
bfccc43c 394 "continue to marker 1"
bd0a71fa 395 gdb_test "continue" "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
bfccc43c
YQ
396 "continue to marker 2"
397
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\\) $" {
402 fail $test
403 }
404 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
405 pass $test
406 }
407 }
408 set test "disconnected"
409 gdb_test_multiple "y" $test {
410 -re "$gdb_prompt $" {
411 pass "$test"
412 }
413 }
6a5870ce 414}}
bfccc43c
YQ
415
416# Verify action works properly in resolved tracepoint.
417
6a5870ce 418proc pending_tracepoint_with_action_resolved { trace_type } \
0f4d39d5 419{ with_test_prefix "$trace_type action_resolved" \
6a5870ce 420{
bfccc43c
YQ
421 global executable
422 global srcfile
423 global lib_sl1
424 global gdb_prompt
6e7675a7 425 global pcreg
bfccc43c
YQ
426
427 # Start with a fresh gdb.
428 clean_restart $executable
429 if ![runto_main] {
bfccc43c
YQ
430 return -1
431 }
432
433 gdb_test_multiple "$trace_type set_point2" "set pending tracepoint on set_point2" {
434 -re ".*Make \(fast |\)tracepoint pending.*y or \\\[n\\\]. $" {
435 gdb_test "y" "\(Fast t|T\)racepoint.*set_point2.*pending." \
436 "set pending tracepoint (without symbols)"
437 }
438 }
439
bfccc43c
YQ
440 gdb_trace_setactions "set action for pending tracepoint" "" \
441 "collect \$$pcreg" "^$"
442
443 gdb_test "info trace" \
444 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
445\[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*PENDING.*set_point2.*" \
446 "single pending tracepoint on set_point2"
447
448 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
449 "breakpoint on marker"
450
451 gdb_test_no_output "tstart" "start trace experiment"
452
bd0a71fa 453 gdb_test "continue" "Continuing.\r\n\r\n(Thread .* hit )?Breakpoint.*marker.*at.*pending.c.*" \
bfccc43c
YQ
454 "continue to marker 1"
455
f4647387
YQ
456 set test "continue to marker 2"
457 gdb_test_multiple "continue" $test {
458 -re "Target returns error code .* too far .*$gdb_prompt $" {
459 if [string equal $trace_type "ftrace"] {
460 # Expected if the target was unable to install the
461 # fast tracepoint (e.g., jump pad too far from
462 # tracepoint).
463 pass "$test (too far)"
464 # Skip the rest of the tests.
465 return
466 } else {
467 fail $test
468 }
469 }
bd0a71fa 470 -re "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\n(Thread .* hit )?Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
bfccc43c
YQ
471 pass "continue to marker 2"
472 }
f4647387 473
bfccc43c
YQ
474 }
475
476 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
477
478 # tracepoint should be resolved.
479 gdb_test "info trace" \
480 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
481\[0-9\]+\[\t \]+\(fast |\)tracepoint\[ \]+keep y.*pendfunc2.*" \
482 "tracepoint is resolved"
483
484 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
485 gdb_test "tdump" "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*"
486 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
6a5870ce 487}}
bfccc43c
YQ
488
489pending_tracepoint_resolved "trace"
490
491pending_tracepoint_works "trace"
492
493pending_tracepoint_resolved_during_trace "trace"
494
495pending_tracepoint_disconnect_during_trace "trace"
496
497pending_tracepoint_disconnect_after_resolved "trace"
498
499pending_tracepoint_with_action_resolved "trace"
500
501pending_tracepoint_installed_during_trace "trace"
502
503# Re-compile test case with IPA.
c0d4d1c0 504set libipa [get_in_proc_agent]
d9019901 505gdb_load_shlib $libipa
bfccc43c
YQ
506
507lappend exec_opts "shlib=$libipa"
508
509if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
84c93cd5 510 untested "failed to compile with in-process agent library"
bfccc43c
YQ
511 return -1
512}
513
514pending_tracepoint_resolved "ftrace"
515pending_tracepoint_works "ftrace"
516pending_tracepoint_resolved_during_trace "ftrace"
517pending_tracepoint_disconnect_during_trace "ftrace"
518pending_tracepoint_disconnect_after_resolved "ftrace"
519pending_tracepoint_with_action_resolved "ftrace"
520pending_tracepoint_installed_during_trace "ftrace"