]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/pending.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / pending.exp
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.
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 {[skip_shlib_tests]} {
18 return 0
19 }
20
21 standard_testfile
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]
29
30 set lib_opts [gdb_target_symbol_prefix_flags]
31
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"
35 return -1
36 }
37
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"
41 return -1
42 }
43
44 clean_restart $executable
45
46 gdb_load_shlibs $lib_sl1
47 gdb_load_shlibs $lib_sl2
48
49 if ![runto_main] {
50 fail "Can't run to main to check for trace support"
51 return -1
52 }
53
54 if ![gdb_target_supports_trace] {
55 unsupported "Current target does not support trace"
56 return -1;
57 }
58
59 # Verify pending tracepoint is resolved to running to main.
60
61 proc pending_tracepoint_resolved { trace_type } { with_test_prefix "$trace_type resolved" {
62 global srcdir
63 global subdir
64 global binfile
65 global srcfile
66 global lib_sl1
67
68 # Start with a fresh gdb.
69 gdb_exit
70 gdb_start
71 gdb_reinitialize_dir $srcdir/$subdir
72
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)"
77 }
78 }
79
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)"
84
85 gdb_load ${binfile}
86
87 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
88 "breakpoint function"
89
90 gdb_run_cmd
91 gdb_test "" "Breakpoint 2, main.*"
92
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"
98 }}
99
100 # Verify pending tracepoint is resolved and works as expected.
101
102 proc pending_tracepoint_works { trace_type } { with_test_prefix "$trace_type works" {
103 global executable
104 global srcfile
105 global lib_sl1
106 global gdb_prompt
107
108 # Restart with a fresh gdb.
109 clean_restart $executable
110
111 # Test setting and querying pending tracepoints
112
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"
116 }
117 }
118
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"
123
124 # Run to main which should resolve a pending tracepoint
125 gdb_test "break main" "Breakpoint.*at.* file .*$srcfile, line.*" \
126 "breakpoint function"
127 gdb_run_cmd
128 gdb_test "" "Breakpoint 2, main.*"
129
130 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
131 "breakpoint on marker"
132
133 set test "start trace experiment"
134 gdb_test_multiple "tstart" $test {
135 -re "^tstart\r\n$gdb_prompt $" {
136 pass $test
137 }
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.
144 return
145 } else {
146 fail $test
147 }
148 }
149
150 }
151
152 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*" \
153 "continue to marker"
154
155 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
156
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"
161 }}
162
163 # Verify pending tracepoint is resolved during trace.
164
165 proc pending_tracepoint_resolved_during_trace { trace_type } \
166 { with_test_prefix "$trace_type resolved_in_trace" \
167 {
168 global executable
169 global srcfile
170 global gdb_prompt
171 global lib_sl1
172
173 # Start with a fresh gdb.
174 clean_restart $executable
175 if ![runto_main] {
176 fail "Can't run to main"
177 return -1
178 }
179
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)"
184 }
185 }
186
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"
191
192 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
193 "breakpoint on marker"
194
195 gdb_test_no_output "tstart" "start trace experiment"
196
197 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
198 "continue to marker 1"
199
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
206 # tracepoint).
207 pass "$test (too far)"
208 # Skip the rest of the tests.
209 return
210 } else {
211 fail $test
212 }
213 }
214 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
215 pass $test
216 }
217 }
218
219 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
220
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"
226
227 gdb_test "tfind start" "#0 .*" "tfind test frame 0"
228 gdb_test "tfind" "Target failed to find requested trace frame..*" "tfind test frame"
229 }}
230
231 # Verify pending tracepoint is resolved and installed during trace.
232
233 proc pending_tracepoint_installed_during_trace { trace_type } \
234 { with_test_prefix "$trace_type installed_in_trace" \
235 {
236 global executable
237 global srcfile
238 global lib_sl1
239 global gdb_prompt
240 global hex
241
242 # Start with a fresh gdb.
243 clean_restart $executable
244 if ![runto_main] {
245 fail "Can't run to main"
246 return -1
247 }
248
249 gdb_test "next" ".*"
250 gdb_test "trace main" "Tracepoint \[0-9\] at .*" "set tracepoint on main"
251
252 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
253 "breakpoint on marker"
254
255 gdb_test_no_output "tstart" "start trace experiment"
256
257 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*${srcfile}.*" \
258 "continue to marker 1"
259
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"
265 }
266 }
267
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"
272
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
279 # tracepoint).
280 pass "$test (too far)"
281 # Skip the rest of the tests.
282 return
283 } else {
284 fail $test
285 }
286 }
287 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
288 pass $test
289 }
290 }
291
292 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
293
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"
299
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"
302 }}
303
304
305 # Verify pending tracepoint will no longer work if we disconnect during tracing.
306
307 proc pending_tracepoint_disconnect_during_trace { trace_type } \
308 { with_test_prefix "$trace_type disconn" \
309 {
310 global executable
311 global srcfile
312 global lib_sl1
313 global gdb_prompt
314
315 # Start with a fresh gdb.
316 clean_restart $executable
317 if ![runto_main] {
318 fail "Can't run to main"
319 return -1
320 }
321
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"
326 }
327 }
328
329 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
330 "breakpoint on marker"
331
332 gdb_test_no_output "tstart" "start trace experiment"
333
334 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
335 "continue to marker"
336
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\\) $" {
340 pass $test
341
342 set test "disconnected"
343 gdb_test_multiple "y" $test {
344 -re "$gdb_prompt $" {
345 pass "$test"
346 }
347 }
348 }
349 }
350 }}
351
352
353 # Verify disconnect after pending tracepoint has been resolved.
354
355 proc pending_tracepoint_disconnect_after_resolved { trace_type } \
356 { with_test_prefix "$trace_type disconn_resolved" \
357 {
358 global executable
359 global srcfile
360 global lib_sl1
361 global gdb_prompt
362
363 # Start with a fresh gdb.
364 clean_restart $executable
365 if ![runto_main] {
366 fail "Can't run to main"
367 return -1
368 }
369
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"
374 }
375 }
376
377 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
378 "breakpoint on marker"
379
380 gdb_test_no_output "tstart" "start trace experiment"
381
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"
386
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\\) $" {
391 fail $test
392 }
393 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
394 pass $test
395 }
396 }
397 set test "disconnected"
398 gdb_test_multiple "y" $test {
399 -re "$gdb_prompt $" {
400 pass "$test"
401 }
402 }
403 }}
404
405 # Verify action works properly in resolved tracepoint.
406
407 proc pending_tracepoint_with_action_resolved { trace_type } \
408 { with_test_prefix "$trace_type action_resolved" \
409 {
410 global executable
411 global srcfile
412 global lib_sl1
413 global gdb_prompt
414
415 # Start with a fresh gdb.
416 clean_restart $executable
417 if ![runto_main] {
418 fail "Can't run to main"
419 return -1
420 }
421
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)"
426 }
427 }
428
429 set pcreg "pc"
430 if [is_amd64_regs_target] {
431 set pcreg "rip"
432 } elseif [is_x86_like_target] {
433 set pcreg "eip"
434 }
435
436 gdb_trace_setactions "set action for pending tracepoint" "" \
437 "collect \$$pcreg" "^$"
438
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"
443
444 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
445 "breakpoint on marker"
446
447 gdb_test_no_output "tstart" "start trace experiment"
448
449 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
450 "continue to marker 1"
451
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
458 # tracepoint).
459 pass "$test (too far)"
460 # Skip the rest of the tests.
461 return
462 } else {
463 fail $test
464 }
465 }
466 -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
467 pass "continue to marker 2"
468 }
469
470 }
471
472 gdb_test "tstop" "\[\r\n\]+" "stop trace experiment"
473
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"
479
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"
483 }}
484
485 pending_tracepoint_resolved "trace"
486
487 pending_tracepoint_works "trace"
488
489 pending_tracepoint_resolved_during_trace "trace"
490
491 pending_tracepoint_disconnect_during_trace "trace"
492
493 pending_tracepoint_disconnect_after_resolved "trace"
494
495 pending_tracepoint_with_action_resolved "trace"
496
497 pending_tracepoint_installed_during_trace "trace"
498
499 # Re-compile test case with IPA.
500 set libipa [get_in_proc_agent]
501 gdb_load_shlibs $libipa
502
503 lappend exec_opts "shlib=$libipa"
504
505 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
506 untested "Failed to compile $srcfile"
507 return -1
508 }
509
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"