]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/change-loc.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / change-loc.exp
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.
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 require allow_shlib_tests
18
19 require gdb_trace_common_supports_arch
20
21 standard_testfile
22 set libfile1 "change-loc-1"
23 set libfile2 "change-loc-2"
24 set executable $testfile
25 set libsrc1 $srcdir/$subdir/$libfile1.c
26 set libsrc2 $srcdir/$subdir/$libfile2.c
27 set lib_sl1 [standard_output_file $libfile1.sl]
28 set lib_sl2 [standard_output_file $libfile2.sl]
29
30 set lib_opts debug
31
32 # Some targets have leading underscores on assembly symbols.
33 set additional_flags [list debug shlib=$lib_sl1 shlib_load [gdb_target_symbol_prefix_flags]]
34
35 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
36 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
37 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
38 untested "failed to compile"
39 return -1
40 }
41
42 clean_restart $executable
43
44 gdb_load_shlib $lib_sl1
45 gdb_load_shlib $lib_sl2
46
47 if ![runto_main] {
48 return -1
49 }
50
51 if {![gdb_target_supports_trace]} {
52 unsupported "current target does not support trace"
53 return -1
54 }
55
56
57 # Set tracepoint during tracing experiment.
58
59 proc tracepoint_change_loc_1 { trace_type } {
60 with_test_prefix "1 $trace_type" {
61 global testfile
62 global srcfile
63 global pcreg
64 global gdb_prompt
65
66 clean_restart ${testfile}
67 if ![runto_main] {
68 return -1
69 }
70 gdb_test_no_output "delete break 1"
71
72 # Set a tracepoint we'll never meet. Just to avoid the
73 # complain after type `tstart' later.
74 gdb_test "next" ".*"
75 gdb_test "trace main" \
76 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
77 "set tracepoint on main"
78
79 gdb_test "break marker" \
80 "Breakpoint.*at.* file .*$srcfile, line.*" \
81 "breakpoint on marker"
82
83 gdb_test_no_output "tstart"
84
85 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
86 "continue to marker 1"
87 # Set a tracepoint during tracing.
88 set test "set tracepoint on set_tracepoint"
89 gdb_test_multiple "${trace_type} set_tracepoint" $test {
90 -re "Target returns error code .* too far .*$gdb_prompt $" {
91 if [string equal $trace_type "ftrace"] {
92 # The target was unable to install the fast tracepoint
93 # (e.g., jump pad too far from tracepoint).
94 pass "$test (too far)"
95 } else {
96 fail $test
97 }
98 }
99 -re "\r\n$gdb_prompt $" {
100 pass $test
101 }
102 }
103
104 gdb_trace_setactions "set action for tracepoint" "" \
105 "collect \$$pcreg" "^$"
106
107 # tracepoint has two locations after shlib change-loc-1 is loaded.
108 gdb_test "info trace" \
109 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
110 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \
111 "tracepoint with two locations"
112
113 set test "continue to marker 2"
114 gdb_test_multiple "continue" $test {
115 -re "Target returns error code .* too far .*$gdb_prompt $" {
116 if [string equal $trace_type "ftrace"] {
117 # Expected if the target was unable to install the
118 # fast tracepoint (e.g., jump pad too far from
119 # tracepoint).
120 pass "$test (too far)"
121 # Skip the rest of the tests.
122 return
123 } else {
124 fail "continue to marker 2"
125 fail $test
126 }
127
128 }
129 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
130 pass "continue to marker 2"
131 }
132 }
133
134 # tracepoint has three locations after shlib change-loc-2 is
135 # loaded.
136 gdb_test "info trace" \
137 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
138 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \
139 "tracepoint with three locations"
140
141 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
142 "continue to marker 3"
143
144 # shlib is unloaded, there are still three locations, but one
145 # is pending.
146 gdb_test "info trace" \
147 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
148 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
149 (4\.\[1-3].* in func4.*\tinstalled on target.*){2}" \
150 "tracepoint with two locations - installed (unload)"
151
152 gdb_test "info trace" \
153 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
154 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
155 4\.\[1-3].* \<PENDING\>\[\t \]+set_tracepoint.*" \
156 "tracepoint with two locations - pending (unload)"
157
158 gdb_test_no_output "tstop"
159
160 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" \
161 "tfind frame 0"
162 gdb_test "tfind" \
163 "Target failed to find requested trace frame\\..*"
164 }
165 }
166
167 # Set pending tracepoint.
168
169 proc tracepoint_change_loc_2 { trace_type } {
170 with_test_prefix "2 $trace_type" {
171 global srcdir
172 global srcfile
173 global subdir
174 global pcreg
175 global binfile
176 global gdb_prompt
177
178 clean_restart
179
180 gdb_test_multiple "${trace_type} set_tracepoint" "set pending tracepoint" {
181 -re ".*Make \(|fast \)tracepoint pending.*y or \\\[n\\\]. $" {
182 gdb_test "y" "\(Fast t|T\)racepoint.*set_tracepoint.*pending." "set pending tracepoint"
183 }
184 }
185
186 gdb_trace_setactions "set action for tracepoint" "" \
187 "collect \$$pcreg" "^$"
188
189 # tracepoint has no location information now. Make sure nothing
190 # else is displayed.
191 gdb_test "info trace" \
192 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
193 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*PENDING.*set_tracepoint\r\n\[\t \]+collect \\$$pcreg" \
194 "single pending tracepoint info (without symbols)"
195
196 gdb_load ${binfile}
197 # tracepoint has one location after executable is loaded.
198 gdb_test "info trace" \
199 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
200 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*func4.*" \
201 "tracepoint with one location"
202
203 set main_bp 0
204 gdb_test_multiple "break -q main" "set breakpoint on main" {
205 -re "Breakpoint (\[0-9\]*) at .*, line.*$gdb_prompt $" {
206 set main_bp $expect_out(1,string)
207 }
208 }
209 gdb_run_cmd
210
211 gdb_test "" \
212 ".*Breakpoint.*main.*at.*$srcfile.*" \
213 "run to main"
214 gdb_test_no_output "delete break $main_bp"
215
216 # tracepoint has two locations after shlib change-loc-1 is loaded.
217 gdb_test "info trace" \
218 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
219 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*" \
220 "tracepoint with two locations"
221
222 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
223 "breakpoint on marker"
224
225 # tracepoint with two locations will be downloaded and installed.
226 set test "tstart"
227 gdb_test_multiple "tstart" $test {
228 -re "^tstart\r\n$gdb_prompt $" {
229 pass "tstart"
230 }
231 -re "Target returns error code .* too far .*$gdb_prompt $" {
232 if [string equal $trace_type "ftrace"] {
233 # The target was unable to install the fast tracepoint
234 # (e.g., jump pad too far from tracepoint).
235 pass "$test (too far)"
236 # Skip the rest of the tests.
237 return
238 } else {
239 fail $test
240 }
241 }
242 }
243
244 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
245 "continue to marker 1"
246
247 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
248 "continue to marker 2"
249
250 # tracepoint has three locations after shlib change-loc-2 is loaded.
251 gdb_test "info trace" \
252 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
253 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*1\.3.* in func4 .*" \
254 "tracepoint with three locations"
255
256 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
257 "continue to marker 3"
258
259 # shlib is unloaded, there are still three locations, but one is pending.
260 gdb_test "info trace" \
261 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
262 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
263 (1\.\[1-3].* in func4.*\tinstalled on target.*){2}" \
264 "tracepoint with two locations - installed (unload)"
265
266 gdb_test "info trace" \
267 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
268 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
269 1\.\[1-3].* \<PENDING\>\[\t \]+set_tracepoint.*" \
270 "tracepoint with two locations - pending (unload)"
271
272 gdb_test_no_output "tstop"
273
274 gdb_test "tfind" "Found trace frame 0, tracepoint 1.*" "tfind frame 0"
275 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind frame 1"
276 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind frame 2"
277 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
278 }
279 }
280
281 # Test that setting a tracepoint while the trace experiment is ongoing
282 # doesn't work when we force-disable the InstallInTrace RSP feature.
283
284 proc tracepoint_install_in_trace_disabled { trace_type } {
285 with_test_prefix "InstallInTrace disabled: $trace_type" {
286 global testfile
287 global srcfile
288 global pcreg
289 global gdb_prompt
290
291 clean_restart ${testfile}
292 if ![runto_main] {
293 return -1
294 }
295
296 # This test only makes sense with the remote target.
297 if ![gdb_is_target_remote] {
298 return
299 }
300
301 gdb_test_no_output "delete break 1"
302
303 # Set a tracepoint we'll never meet. Just to avoid the
304 # complain after `tstart' later.
305 gdb_test "next" ".*"
306 gdb_test "trace main" \
307 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
308 "set tracepoint on main"
309
310 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
311 "breakpoint on marker"
312
313 gdb_test_no_output "tstart"
314
315 # Force-disable the InstallInTrace RSP feature.
316 gdb_test \
317 "set remote install-in-trace-packet off" \
318 "Support for the 'InstallInTrace' packet on the current remote target is set to \"off\"."
319
320 # Set a tracepoint while a trace experiment is ongoing.
321 gdb_test "${trace_type} set_tracepoint" \
322 "racepoint .* at .* set_tracepoint.*" \
323 "set tracepoint on set_tracepoint"
324
325 gdb_trace_setactions "set action for tracepoint" "" \
326 "collect \$$pcreg" "^$"
327
328 # Make sure the tracepoint is _not_ installed on the target.
329 gdb_test "info trace" \
330 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
331 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*installed on target.*\<MULTIPLE\>.*4\.1.* in func4.*not installed on target.*4\.2.* in func4.*not installed on target.*" \
332 "tracepoint is not installed"
333
334 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
335 "continue to marker"
336
337 gdb_test_no_output "tstop"
338
339 # Nothing should have been collected.
340 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
341 }
342 }
343
344 tracepoint_change_loc_1 "trace"
345 tracepoint_change_loc_2 "trace"
346 tracepoint_install_in_trace_disabled "trace"
347
348 # Re-compile test case with IPA.
349 set libipa [get_in_proc_agent]
350 gdb_load_shlib $libipa
351
352 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
353 [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
354 untested "failed to compile"
355 return -1
356 }
357
358 tracepoint_change_loc_1 "ftrace"
359 tracepoint_change_loc_2 "ftrace"
360 tracepoint_install_in_trace_disabled "ftrace"