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