]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.trace/trace-break.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / trace-break.exp
CommitLineData
213516ef 1# Copyright 2011-2023 Free Software Foundation, Inc.
b9fd1791
PA
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
4ec70201 15load_lib "trace-support.exp"
b9fd1791 16
497a5eb0 17standard_testfile
b9fd1791 18set executable $testfile
b9fd1791
PA
19set expfile $testfile.exp
20
21# Some targets have leading underscores on assembly symbols.
22set additional_flags [gdb_target_symbol_prefix_flags]
23
8bca2978
SL
24if ![gdb_trace_common_supports_arch] {
25 unsupported "no trace-common.h support for arch"
26 return -1
27}
28
5b362f04 29if [prepare_for_testing "failed to prepare" $executable $srcfile \
b9fd1791 30 [list debug $additional_flags]] {
b9fd1791
PA
31 return -1
32}
33
34if ![runto_main] {
b9fd1791
PA
35 return -1
36}
37
38if ![gdb_target_supports_trace] {
39 unsupported "target does not support trace"
ae59b1da 40 return -1
b9fd1791
PA
41}
42
43# Set breakpoint and tracepoint at the same address.
44
6a5870ce 45proc break_trace_same_addr_1 { trace_type option } \
0f4d39d5 46{ with_test_prefix "1 $trace_type $option" \
6a5870ce 47{
b9fd1791 48 global executable
b9fd1791
PA
49 global hex
50
b9fd1791
PA
51 # Start with a fresh gdb.
52 clean_restart ${executable}
53 if ![runto_main] {
b9fd1791
PA
54 return -1
55 }
56
57 gdb_test_no_output "set breakpoint always-inserted ${option}"
58
194ed413 59 gdb_breakpoint "end" qualified
b9fd1791 60
194ed413 61 gdb_breakpoint "set_point" qualified
b9fd1791
PA
62 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
63
64 gdb_test_no_output "tstart"
65
bd0a71fa
MK
66 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
67 "continue to set_point"
b9fd1791 68
bd0a71fa
MK
69 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
70 "continue to end"
b9fd1791
PA
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\\..*"
6a5870ce 75}}
b9fd1791
PA
76
77# Set multiple tracepoints at the same address.
78
6a5870ce 79proc break_trace_same_addr_2 { trace_type1 trace_type2 option } \
0f4d39d5 80{ with_test_prefix "2 $trace_type1 $trace_type2 $option" \
6a5870ce 81{
b9fd1791 82 global executable
b9fd1791
PA
83 global hex
84
b9fd1791
PA
85 # Start with a fresh gdb.
86 clean_restart ${executable}
87 if ![runto_main] {
b9fd1791
PA
88 return -1
89 }
90
91 gdb_test_no_output "set breakpoint always-inserted ${option}"
92
194ed413 93 gdb_breakpoint "end" qualified
b9fd1791
PA
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"
bd0a71fa
MK
104 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
105 "continue to end"
b9fd1791
PA
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\\..*"
6a5870ce 112}}
b9fd1791
PA
113
114# Set breakpoint and tracepoint at the same address. Delete breakpoint, and verify
115# that tracepoint still works.
116
6a5870ce 117proc break_trace_same_addr_3 { trace_type option } \
0f4d39d5 118{ with_test_prefix "3 $trace_type $option" \
6a5870ce 119{
b9fd1791 120 global executable
b9fd1791
PA
121 global hex
122
b9fd1791
PA
123 # Start with a fresh gdb.
124 clean_restart ${executable}
125 if ![runto_main] {
b9fd1791
PA
126 return -1
127 }
128
129 gdb_test_no_output "set breakpoint always-inserted ${option}"
194ed413
AA
130 gdb_breakpoint "marker" qualified
131 gdb_breakpoint "end" qualified
b9fd1791 132
194ed413 133 gdb_breakpoint "set_point" qualified
b9fd1791
PA
134 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
135
136 gdb_test_no_output "tstart"
137
bd0a71fa
MK
138 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
139 "continue to marker"
b9fd1791
PA
140 gdb_test "delete break 4"
141
bd0a71fa
MK
142 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
143 "continue to end"
b9fd1791
PA
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\\..*"
6a5870ce 148}}
b9fd1791
PA
149
150# Set breakpoint and tracepoint at the same address. Delete tracepoint, and verify
151# that breakpoint still works.
152
6a5870ce 153proc break_trace_same_addr_4 { trace_type option } \
0f4d39d5 154{ with_test_prefix "4 $trace_type $option" \
6a5870ce 155{
b9fd1791 156 global executable
b9fd1791
PA
157 global hex
158
b9fd1791
PA
159
160 # Start with a fresh gdb.
161 clean_restart ${executable}
162 if ![runto_main] {
b9fd1791
PA
163 return -1
164 }
165
166 gdb_test_no_output "set breakpoint always-inserted ${option}"
194ed413
AA
167 gdb_breakpoint "marker" qualified
168 gdb_breakpoint "end" qualified
b9fd1791 169
194ed413 170 gdb_breakpoint "set_point" qualified
b9fd1791
PA
171 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
172
bd0a71fa
MK
173 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
174 "continue to marker"
b9fd1791
PA
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
bd0a71fa
MK
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"
b9fd1791
PA
184 gdb_test "tstop" "Trace is not running.*"
185
186 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
6a5870ce 187}}
b9fd1791 188
1e4d1764
YQ
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
6a5870ce 194proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } \
0f4d39d5 195{ with_test_prefix "5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}" \
6a5870ce 196{
1e4d1764 197 global executable
1e4d1764
YQ
198 global hex
199 global fpreg
200 global spreg
201 global pcreg
202
1e4d1764
YQ
203 # Start with a fresh gdb.
204 clean_restart ${executable}
205 if ![runto_main] {
1e4d1764
YQ
206 return -1
207 }
208
194ed413
AA
209 gdb_breakpoint "marker" qualified
210 gdb_breakpoint "end" qualified
1e4d1764
YQ
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
bd0a71fa
MK
225 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
226 "continue to marker"
1e4d1764
YQ
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
bd0a71fa
MK
239 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
240 "continue to end"
1e4d1764
YQ
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"
6a5870ce 262}}
1e4d1764
YQ
263
264# Set two tracepoints at the same address, and enable/disable them. Verify
265# tracepoints work as expect.
266
6a5870ce 267proc break_trace_same_addr_6 { trace1 enable1 trace2 enable2 } \
0f4d39d5 268{ with_test_prefix "6 $trace1 $enable1 $trace2 $enable2" \
6a5870ce 269{
1e4d1764 270 global executable
1e4d1764
YQ
271 global hex
272 global gdb_prompt
273 global spreg
274 global pcreg
275
1e4d1764
YQ
276 # Start with a fresh gdb.
277 clean_restart ${executable}
278 if ![runto_main] {
1e4d1764
YQ
279 return -1
280 }
281
194ed413
AA
282 gdb_breakpoint "marker" qualified
283 gdb_breakpoint "end" qualified
1e4d1764 284
bd0a71fa
MK
285 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
286 "continue to marker"
1e4d1764
YQ
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"
bd0a71fa
MK
301 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
302 "continue to end"
1e4d1764
YQ
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 }
6a5870ce 331}}
1e4d1764
YQ
332
333
b9fd1791
PA
334foreach 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
1e4d1764
YQ
341foreach at_first_loc { "1" "0" } {
342 break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc}
343}
344
345break_trace_same_addr_6 "trace" "enable" "trace" "disable"
346break_trace_same_addr_6 "trace" "disable" "trace" "enable"
347
8bca2978
SL
348if {[skip_shlib_tests]} {
349 return 0
350}
351
c0d4d1c0 352set libipa [get_in_proc_agent]
952ebca5 353set remote_libipa [gdb_load_shlib $libipa]
b9fd1791
PA
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
359if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
360 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
84c93cd5 361 untested "failed to compile"
b9fd1791
PA
362 return -1
363}
364clean_restart ${executable}
365
366if ![runto_main] {
b9fd1791
PA
367 return 0
368}
369
370gdb_reinitialize_dir $srcdir/$subdir
952ebca5 371if { [gdb_test "info sharedlibrary" ".*${remote_libipa}.*" "IPA loaded"] != 0 } {
bc6c7af4 372 untested "could not find IPA lib loaded"
b9fd1791
PA
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}
a59306a3 378 break_trace_same_addr_2 "ftrace" "ftrace" ${break_always_inserted}
b9fd1791
PA
379 break_trace_same_addr_3 "ftrace" ${break_always_inserted}
380 break_trace_same_addr_4 "ftrace" ${break_always_inserted}
381 }
1e4d1764
YQ
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 }
b9fd1791 410}