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