Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.trace / trace-break.exp
blob635155c57cee2db43f5ebcec719a4866ddead3e0
1 # Copyright 2011-2024 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.
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.
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/>.
15 load_lib "trace-support.exp"
17 standard_testfile
18 set executable $testfile
19 set expfile $testfile.exp
21 # Some targets have leading underscores on assembly symbols.
22 set additional_flags [gdb_target_symbol_prefix_flags]
24 require gdb_trace_common_supports_arch
26 if [prepare_for_testing "failed to prepare" $executable $srcfile \
27         [list debug $additional_flags]] {
28     return -1
31 if ![runto_main] {
32     return -1
35 if ![gdb_target_supports_trace] {
36     unsupported "target does not support trace"
37     return -1
40 # Set breakpoint and tracepoint at the same address.
42 proc break_trace_same_addr_1 { trace_type option } \
43 { with_test_prefix "1 $trace_type $option" \
45     global executable
46     global hex
48     # Start with a fresh gdb.
49     clean_restart ${executable}
50     if ![runto_main] {
51         return -1
52     }
54     gdb_test_no_output "set breakpoint always-inserted ${option}"
56     gdb_breakpoint "end" qualified
58     gdb_breakpoint "set_point" qualified
59     gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
61     gdb_test_no_output "tstart"
63     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
64         "continue to set_point"
66     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
67         "continue to end"
68     gdb_test_no_output "tstop"
70     gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
71     gdb_test "tfind" "Target failed to find requested trace frame\\..*"
74 # Set multiple tracepoints at the same address.
76 proc break_trace_same_addr_2 { trace_type1 trace_type2 option } \
77 { with_test_prefix "2 $trace_type1 $trace_type2 $option" \
79     global executable
80     global hex
82     # Start with a fresh gdb.
83     clean_restart ${executable}
84     if ![runto_main] {
85         return -1
86     }
88     gdb_test_no_output "set breakpoint always-inserted ${option}"
90     gdb_breakpoint "end" qualified
92     gdb_test "${trace_type1} set_point" \
93         "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
94         "${trace_type1} set_point, first trace type"
96     gdb_test "${trace_type2} set_point" \
97         "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
98         "${trace_type2} set_point, second trace type"
100     gdb_test_no_output "tstart"
101     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
102         "continue to end"
104     gdb_test_no_output "tstop"
106     gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
107     gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
108     gdb_test "tfind" "Target failed to find requested trace frame\\..*"
111 # Set breakpoint and tracepoint at the same address.  Delete breakpoint, and verify
112 # that tracepoint still works.
114 proc break_trace_same_addr_3 { trace_type option } \
115 { with_test_prefix "3 $trace_type $option" \
117     global executable
118     global hex
120     # Start with a fresh gdb.
121     clean_restart ${executable}
122     if ![runto_main] {
123         return -1
124     }
126     gdb_test_no_output "set breakpoint always-inserted ${option}"
127     gdb_breakpoint "marker" qualified
128     gdb_breakpoint "end" qualified
130     gdb_breakpoint "set_point" qualified
131     gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
133     gdb_test_no_output "tstart"
135     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
136         "continue to marker"
137     gdb_test "delete break 4"
139     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
140         "continue to end"
141     gdb_test_no_output "tstop"
143     gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
144     gdb_test "tfind" "Target failed to find requested trace frame\\..*"
147 # Set breakpoint and tracepoint at the same address.  Delete tracepoint, and verify
148 # that breakpoint still works.
150 proc break_trace_same_addr_4 { trace_type option } \
151 { with_test_prefix "4 $trace_type $option" \
153     global executable
154     global hex
157     # Start with a fresh gdb.
158     clean_restart ${executable}
159     if ![runto_main] {
160         return -1
161     }
163     gdb_test_no_output "set breakpoint always-inserted ${option}"
164     gdb_breakpoint "marker" qualified
165     gdb_breakpoint "end" qualified
167     gdb_breakpoint "set_point" qualified
168     gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
170     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
171         "continue to marker"
172     # Delete tracepoint set on set_point.
173     gdb_test "delete trace 5"
175     gdb_test "tstart" "No tracepoints defined, not starting trace.*"
177     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
178         "continue to set_point"
179     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
180         "continue to end"
181     gdb_test "tstop" "Trace is not running.*"
183     gdb_test "tfind" "Target failed to find requested trace frame\\..*"
186 # Set two tracepoints TRACE1 and TRACE2 at two locations, and start tracing.
187 # Then, set tracepoint TRACE3 at either of these two locations.
188 # TRACE3_AT_FIRST_LOC is a boolean variable to decide insert TRACE3 at which
189 # of two locations.  Verify  these tracepoints work as expected.
191 proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } \
192 { with_test_prefix "5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}" \
194     global executable
195     global hex
196     global fpreg
197     global spreg
198     global pcreg
200     # Start with a fresh gdb.
201     clean_restart ${executable}
202     if ![runto_main] {
203         return -1
204     }
206     gdb_breakpoint "marker" qualified
207     gdb_breakpoint "end" qualified
209     gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
210         "${trace1} set_point 1"
211     gdb_trace_setactions "set action for tracepoint 1" "" \
212         "collect \$$pcreg" "^$"
213     gdb_test "${trace2} after_set_point" \
214         "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
215         "${trace2} after_set_point 1"
217     gdb_trace_setactions "set action for tracepoint 2" "" \
218         "collect \$$spreg" "^$"
220     gdb_test_no_output "tstart"
222     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
223         "continue to marker"
225     if [string equal $trace3_at_first_loc "1"] {
226         gdb_test "${trace3} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
227             "${trace3} set_point 2"
228     } else {
229         gdb_test "${trace3} after_set_point" \
230             "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
231             "${trace2} after_set_point 2"
232     }
233     gdb_trace_setactions "set action for tracepoint 3" "" \
234         "collect \$$fpreg" "^$"
236     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
237         "continue to end"
238     gdb_test_no_output "tstop"
240     gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
241         "tfind test frame of tracepoint 4"
242     gdb_test "tdump" \
243         "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
244         "tdump 1"
245     gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
246         "reset to frame 0, first time"
247     gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
248         "tfind test frame of tracepoint 5"
249     gdb_test "tdump" \
250         "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
251         "tdump 2"
252     gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
253         "reset to frame 0, second time"
254     gdb_test "tfind tracepoint 6" "Found trace frame \[0-9\], tracepoint .*" \
255         "tfind test frame of tracepoint 6"
256     gdb_test "tdump" \
257         "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${fpreg} = .*" \
258         "tdump 3"
261 # Set two tracepoints at the same address, and enable/disable them.  Verify
262 # tracepoints work as expect.
264 proc break_trace_same_addr_6 { trace1 enable1 trace2 enable2 } \
265 { with_test_prefix "6 $trace1 $enable1 $trace2 $enable2" \
267     global executable
268     global hex
269     global gdb_prompt
270     global spreg
271     global pcreg
273     # Start with a fresh gdb.
274     clean_restart ${executable}
275     if ![runto_main] {
276         return -1
277     }
279     gdb_breakpoint "marker" qualified
280     gdb_breakpoint "end" qualified
282     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
283         "continue to marker"
285     gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
286         "${trace1} set_point 1"
287     gdb_trace_setactions "set action for tracepoint 1" "" \
288         "collect \$$pcreg" "^$"
289     gdb_test "${trace2} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
290         "${trace2} set_point 2"
291     gdb_trace_setactions "set action for tracepoint 2" "" \
292         "collect \$$spreg" "^$"
294     gdb_test_no_output "$enable1 4"
295     gdb_test_no_output "$enable2 5"
297     gdb_test_no_output "tstart"
298     gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
299         "continue to end"
300     gdb_test_no_output "tstop"
303     if [string equal $enable1 "enable"] {
304         gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
305             "tfind test frame of tracepoint 4"
306         gdb_test "tdump" \
307             "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
308             "tdump 1"
309         gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
310             "reset to frame 0, first time"
311     } else {
312         gdb_test "tfind tracepoint 4" "Target failed to find requested trace frame.*" \
313             "tfind test frame of tracepoint 4"
314     }
316     if [string equal $enable2 "enable"] {
317         gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
318             "tfind test frame of tracepoint 5"
319         gdb_test "tdump" \
320             "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
321             "tdump 2"
322         gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
323             "reset to frame 0, second time"
324     } else {
325         gdb_test "tfind tracepoint 5" "Target failed to find requested trace frame.*" \
326             "tfind test frame of tracepoint 5"
327     }
331 foreach_with_prefix break_always_inserted { "on" "off" } {
332     break_trace_same_addr_1 "trace" ${break_always_inserted}
333     break_trace_same_addr_2 "trace" "trace" ${break_always_inserted}
334     break_trace_same_addr_3 "trace" ${break_always_inserted}
335     break_trace_same_addr_4 "trace" ${break_always_inserted}
338 foreach at_first_loc { "1" "0" } {
339     break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc}
342 break_trace_same_addr_6 "trace" "enable" "trace" "disable"
343 break_trace_same_addr_6 "trace" "disable" "trace" "enable"
345 require allow_shlib_tests
347 require allow_in_proc_agent
348 set libipa [get_in_proc_agent]
349 set remote_libipa [gdb_load_shlib $libipa]
351 # Can't use prepare_for_testing, because that splits compiling into
352 # building objects and then linking, and we'd fail with "linker input
353 # file unused because linking not done" when building the object.
355 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
356           executable [list debug $additional_flags shlib=$libipa] ] != "" } {
357     untested "failed to compile"
358     return -1
360 clean_restart ${executable}
362 if ![runto_main] {
363     return 0
366 gdb_reinitialize_dir $srcdir/$subdir
367 if { [gdb_test "info sharedlibrary" ".*${remote_libipa}.*" "IPA loaded"] != 0 } {
368     untested "could not find IPA lib loaded"
369 } else {
370     foreach break_always_inserted { "on" "off" } {
371         break_trace_same_addr_1 "ftrace" ${break_always_inserted}
372         break_trace_same_addr_2 "trace" "ftrace" ${break_always_inserted}
373         break_trace_same_addr_2 "ftrace" "trace" ${break_always_inserted}
374         break_trace_same_addr_2 "ftrace" "ftrace" ${break_always_inserted}
375         break_trace_same_addr_3 "ftrace" ${break_always_inserted}
376         break_trace_same_addr_4 "ftrace" ${break_always_inserted}
377     }
379     foreach trace1 { "trace" "ftrace" } {
380         foreach trace2 { "trace" "ftrace" } {
381             foreach trace3 { "trace" "ftrace" } {
383                 if { [string equal $trace1 "trace"]
384                      && [string equal $trace2 "trace"]
385                      && [string equal $trace3 "trace"] } {
386                     continue
387                 }
389                 foreach at_first_loc { "1" "0" } {
390                     break_trace_same_addr_5 $trace1 $trace2 $trace3 $at_first_loc
391                 }
392             }
393         }
394     }
396     foreach trace1 { "trace" "ftrace" } {
397         foreach trace2 { "trace" "ftrace" } {
398             if { [string equal $trace1 "trace"]
399                  && [string equal $trace2 "trace"] } {
400                     continue
401                 }
402             break_trace_same_addr_6 $trace1 "enable" $trace2 "disable"
403             break_trace_same_addr_6 $trace1 "disable" $trace2 "enable"
404         }
405     }