5fcc1ac586a97ff93a8c5ef0a8daf4aadce91654
[external/binutils.git] / gdb / testsuite / gdb.trace / trace-break.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 set testfile "trace-break"
18 set executable $testfile
19 set srcfile $testfile.c
20 set binfile $objdir/$subdir/$testfile
21 set expfile $testfile.exp
22
23 # Some targets have leading underscores on assembly symbols.
24 set additional_flags [gdb_target_symbol_prefix_flags]
25
26 if [prepare_for_testing $expfile $executable $srcfile \
27         [list debug $additional_flags]] {
28     untested "failed to prepare for trace tests"
29     return -1
30 }
31
32 if ![runto_main] {
33     fail "Can't run to main to check for trace support"
34     return -1
35 }
36
37 if ![gdb_target_supports_trace] {
38     unsupported "target does not support trace"
39     return -1;
40 }
41
42 set fpreg "fp"
43 set spreg "sp"
44 set pcreg "pc"
45
46 if [is_amd64_regs_target] {
47     set fpreg "rbp"
48     set spreg "rsp"
49     set pcreg "rip"
50 } elseif [is_x86_like_target] {
51     set fpreg "ebp"
52     set spreg "esp"
53     set pcreg "eip"
54 }
55
56 # Set breakpoint and tracepoint at the same address.
57
58 proc break_trace_same_addr_1 { trace_type option } \
59 { with_test_prefix " 1 $trace_type $option:" \
60 {
61     global executable
62     global hex
63
64     # Start with a fresh gdb.
65     clean_restart ${executable}
66     if ![runto_main] {
67         fail "Can't run to main"
68         return -1
69     }
70
71     gdb_test_no_output "set breakpoint always-inserted ${option}"
72
73     gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
74
75     gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
76     gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
77
78     gdb_test_no_output "tstart"
79
80     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to set_point"
81
82     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
83     gdb_test_no_output "tstop"
84
85     gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
86     gdb_test "tfind" "Target failed to find requested trace frame\\..*"
87 }}
88
89 # Set multiple tracepoints at the same address.
90
91 proc break_trace_same_addr_2 { trace_type1 trace_type2 option } \
92 { with_test_prefix " 2 $trace_type1 $trace_type2 $option:" \
93 {
94     global executable
95     global hex
96
97     # Start with a fresh gdb.
98     clean_restart ${executable}
99     if ![runto_main] {
100         fail "Can't run to main"
101         return -1
102     }
103
104     gdb_test_no_output "set breakpoint always-inserted ${option}"
105
106     gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
107
108     gdb_test "${trace_type1} set_point" \
109         "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
110         "${trace_type1} set_point (1)"
111
112     gdb_test "${trace_type2} set_point" \
113         "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
114         "${trace_type2} set_point (2)"
115
116     gdb_test_no_output "tstart"
117     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
118
119     gdb_test_no_output "tstop"
120
121     gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
122     gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
123     gdb_test "tfind" "Target failed to find requested trace frame\\..*"
124 }}
125
126 # Set breakpoint and tracepoint at the same address.  Delete breakpoint, and verify
127 # that tracepoint still works.
128
129 proc break_trace_same_addr_3 { trace_type option } \
130 { with_test_prefix " 3 $trace_type $option:" \
131 {
132     global executable
133     global hex
134
135     # Start with a fresh gdb.
136     clean_restart ${executable}
137     if ![runto_main] {
138         fail "Can't run to main"
139         return -1
140     }
141
142     gdb_test_no_output "set breakpoint always-inserted ${option}"
143     gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
144     gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
145
146     gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
147     gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
148
149     gdb_test_no_output "tstart"
150
151     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
152     gdb_test "delete break 4"
153
154     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
155     gdb_test_no_output "tstop"
156
157     gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
158     gdb_test "tfind" "Target failed to find requested trace frame\\..*"
159 }}
160
161 # Set breakpoint and tracepoint at the same address.  Delete tracepoint, and verify
162 # that breakpoint still works.
163
164 proc break_trace_same_addr_4 { trace_type option } \
165 { with_test_prefix " 4 $trace_type $option:" \
166 {
167     global executable
168     global hex
169
170
171     # Start with a fresh gdb.
172     clean_restart ${executable}
173     if ![runto_main] {
174         fail "Can't run to main"
175         return -1
176     }
177
178     gdb_test_no_output "set breakpoint always-inserted ${option}"
179     gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
180     gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
181
182     gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
183     gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
184
185     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
186     # Delete tracepoint set on set_point.
187     gdb_test "delete trace 5"
188
189     gdb_test "tstart" "No tracepoints defined, not starting trace.*"
190
191     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to set_point"
192     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
193     gdb_test "tstop" "Trace is not running.*"
194
195     gdb_test "tfind" "Target failed to find requested trace frame\\..*"
196 }}
197
198 # Set two tracepoints TRACE1 and TRACE2 at two locations, and start tracing.
199 # Then, set tracepoint TRACE3 at either of these two locations.
200 # TRACE3_AT_FIRST_LOC is a boolean variable to decide insert TRACE3 at which
201 # of two locations.  Verify  these tracepoints work as expected.
202
203 proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } \
204 { with_test_prefix " 5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}:" \
205 {
206     global executable
207     global hex
208     global fpreg
209     global spreg
210     global pcreg
211
212     # Start with a fresh gdb.
213     clean_restart ${executable}
214     if ![runto_main] {
215         fail "Can't run to main"
216         return -1
217     }
218
219     gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
220     gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
221
222     gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
223         "${trace1} set_point 1"
224     gdb_trace_setactions "set action for tracepoint 1" "" \
225         "collect \$$pcreg" "^$"
226     gdb_test "${trace2} after_set_point" \
227         "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
228         "${trace2} after_set_point 1"
229
230     gdb_trace_setactions "set action for tracepoint 2" "" \
231         "collect \$$spreg" "^$"
232
233     gdb_test_no_output "tstart"
234
235     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
236
237     if [string equal $trace3_at_first_loc "1"] {
238         gdb_test "${trace3} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
239             "${trace3} set_point 2"
240     } else {
241         gdb_test "${trace3} after_set_point" \
242             "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
243             "${trace2} after_set_point 2"
244     }
245     gdb_trace_setactions "set action for tracepoint 3" "" \
246         "collect \$$fpreg" "^$"
247
248     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
249     gdb_test_no_output "tstop"
250
251     gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
252         "tfind test frame of tracepoint 4"
253     gdb_test "tdump" \
254         "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
255         "tdump 1"
256     gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
257         "reset to frame 0 (1)"
258     gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
259         "tfind test frame of tracepoint 5"
260     gdb_test "tdump" \
261         "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
262         "tdump 2"
263     gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
264         "reset to frame 0 (2)"
265     gdb_test "tfind tracepoint 6" "Found trace frame \[0-9\], tracepoint .*" \
266         "tfind test frame of tracepoint 6"
267     gdb_test "tdump" \
268         "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${fpreg} = .*" \
269         "tdump 3"
270 }}
271
272 # Set two tracepoints at the same address, and enable/disable them.  Verify
273 # tracepoints work as expect.
274
275 proc break_trace_same_addr_6 { trace1 enable1 trace2 enable2 } \
276 { with_test_prefix " 6 $trace1 $enable1 $trace2 $enable2:" \
277 {
278     global executable
279     global hex
280     global gdb_prompt
281     global spreg
282     global pcreg
283
284     # Start with a fresh gdb.
285     clean_restart ${executable}
286     if ![runto_main] {
287         fail "Can't run to main"
288         return -1
289     }
290
291     gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
292     gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
293
294     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
295
296     gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
297         "${trace1} set_point 1"
298     gdb_trace_setactions "set action for tracepoint 1" "" \
299         "collect \$$pcreg" "^$"
300     gdb_test "${trace2} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
301         "${trace2} set_point 2"
302     gdb_trace_setactions "set action for tracepoint 2" "" \
303         "collect \$$spreg" "^$"
304
305     gdb_test_no_output "$enable1 4"
306     gdb_test_no_output "$enable2 5"
307
308     gdb_test_no_output "tstart"
309     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
310     gdb_test_no_output "tstop"
311
312
313     if [string equal $enable1 "enable"] {
314         gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
315             "tfind test frame of tracepoint 4"
316         gdb_test "tdump" \
317             "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
318             "tdump 1"
319         gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
320             "reset to frame 0 (1)"
321     } else {
322         gdb_test "tfind tracepoint 4" "Target failed to find requested trace frame.*" \
323             "tfind test frame of tracepoint 4"
324     }
325
326     if [string equal $enable2 "enable"] {
327         gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
328             "tfind test frame of tracepoint 5"
329         gdb_test "tdump" \
330             "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
331             "tdump 2"
332         gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
333             "reset to frame 0 (2)"
334     } else {
335         gdb_test "tfind tracepoint 5" "Target failed to find requested trace frame.*" \
336             "tfind test frame of tracepoint 5"
337     }
338 }}
339
340
341 foreach break_always_inserted { "on" "off" } {
342     break_trace_same_addr_1 "trace" ${break_always_inserted}
343     break_trace_same_addr_2 "trace" "trace" ${break_always_inserted}
344     break_trace_same_addr_3 "trace" ${break_always_inserted}
345     break_trace_same_addr_4 "trace" ${break_always_inserted}
346 }
347
348 foreach at_first_loc { "1" "0" } {
349     break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc}
350 }
351
352 break_trace_same_addr_6 "trace" "enable" "trace" "disable"
353 break_trace_same_addr_6 "trace" "disable" "trace" "enable"
354
355 set libipa $objdir/../gdbserver/libinproctrace.so
356 gdb_load_shlibs $libipa
357
358 # Can't use prepare_for_testing, because that splits compiling into
359 # building objects and then linking, and we'd fail with "linker input
360 # file unused because linking not done" when building the object.
361
362 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
363           executable [list debug $additional_flags shlib=$libipa] ] != "" } {
364     untested "failed to compile ftrace tests"
365     return -1
366 }
367 clean_restart ${executable}
368
369 if ![runto_main] {
370     fail "Can't run to main for ftrace tests"
371     return 0
372 }
373
374 gdb_reinitialize_dir $srcdir/$subdir
375 if { [gdb_test "info sharedlibrary" ".*libinproctrace\.so.*" "IPA loaded"] != 0 } {
376     untested "Could not find IPA lib loaded"
377 } else {
378     foreach break_always_inserted { "on" "off" } {
379         break_trace_same_addr_1 "ftrace" ${break_always_inserted}
380         break_trace_same_addr_2 "trace" "ftrace" ${break_always_inserted}
381         break_trace_same_addr_2 "ftrace" "trace" ${break_always_inserted}
382         break_trace_same_addr_2 "ftrace" "ftrace" ${break_always_inserted}
383         break_trace_same_addr_3 "ftrace" ${break_always_inserted}
384         break_trace_same_addr_4 "ftrace" ${break_always_inserted}
385     }
386
387     foreach trace1 { "trace" "ftrace" } {
388         foreach trace2 { "trace" "ftrace" } {
389             foreach trace3 { "trace" "ftrace" } {
390
391                 if { [string equal $trace1 "trace"]
392                      && [string equal $trace2 "trace"]
393                      && [string equal $trace3 "trace"] } {
394                     continue
395                 }
396
397                 foreach at_first_loc { "1" "0" } {
398                     break_trace_same_addr_5 $trace1 $trace2 $trace3 $at_first_loc
399                 }
400             }
401         }
402     }
403
404     foreach trace1 { "trace" "ftrace" } {
405         foreach trace2 { "trace" "ftrace" } {
406             if { [string equal $trace1 "trace"]
407                  && [string equal $trace2 "trace"] } {
408                     continue
409                 }
410             break_trace_same_addr_6 $trace1 "enable" $trace2 "disable"
411             break_trace_same_addr_6 $trace1 "disable" $trace2 "enable"
412         }
413     }
414 }