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