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