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