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 require allow_shlib_tests
19 require gdb_trace_common_supports_arch
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]
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]]
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"
42 clean_restart $executable
44 gdb_load_shlib $lib_sl1
45 gdb_load_shlib $lib_sl2
51 if {![gdb_target_supports_trace]} {
52 unsupported "current target does not support trace"
57 # Set tracepoint during tracing experiment.
59 proc tracepoint_change_loc_1 { trace_type } {
60 with_test_prefix "1 $trace_type" {
66 clean_restart ${testfile}
70 gdb_test_no_output "delete break 1"
72 # Set a tracepoint we'll never meet. Just to avoid the
73 # complain after type `tstart' later.
75 gdb_test "trace main" \
76 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
77 "set tracepoint on main"
79 gdb_test "break marker" \
80 "Breakpoint.*at.* file .*$srcfile, line.*" \
81 "breakpoint on marker"
83 gdb_test_no_output "tstart"
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)"
99 -re "\r\n$gdb_prompt $" {
104 gdb_trace_setactions "set action for tracepoint" "" \
105 "collect \$$pcreg" "^$"
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"
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
120 pass "$test (too far)"
121 # Skip the rest of the tests.
124 fail "continue to marker 2"
129 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
130 pass "continue to marker 2"
134 # tracepoint has three locations after shlib change-loc-2 is
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"
141 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
142 "continue to marker 3"
144 # shlib is unloaded, there are still three locations, but one
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)"
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)"
158 gdb_test_no_output "tstop"
160 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" \
163 "Target failed to find requested trace frame\\..*"
167 # Set pending tracepoint.
169 proc tracepoint_change_loc_2 { trace_type } {
170 with_test_prefix "2 $trace_type" {
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"
186 gdb_trace_setactions "set action for tracepoint" "" \
187 "collect \$$pcreg" "^$"
189 # tracepoint has no location information now. Make sure nothing
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)"
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"
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)
212 ".*Breakpoint.*main.*at.*$srcfile.*" \
214 gdb_test_no_output "delete break $main_bp"
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"
222 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
223 "breakpoint on marker"
225 # tracepoint with two locations will be downloaded and installed.
227 gdb_test_multiple "tstart" $test {
228 -re "^tstart\r\n$gdb_prompt $" {
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.
244 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
245 "continue to marker 1"
247 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
248 "continue to marker 2"
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"
256 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
257 "continue to marker 3"
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)"
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)"
272 gdb_test_no_output "tstop"
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\\..*"
281 # Test that setting a tracepoint while the trace experiment is ongoing
282 # doesn't work when we force-disable the InstallInTrace RSP feature.
284 proc tracepoint_install_in_trace_disabled { trace_type } {
285 with_test_prefix "InstallInTrace disabled: $trace_type" {
291 # This test only makes sense with remote targets.
292 if ![gdb_protocol_is_remote] {
296 clean_restart ${testfile}
301 gdb_test_no_output "delete break 1"
303 # Set a tracepoint we'll never meet. Just to avoid the
304 # complain after `tstart' later.
306 gdb_test "trace main" \
307 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
308 "set tracepoint on main"
310 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
311 "breakpoint on marker"
313 gdb_test_no_output "tstart"
315 # Force-disable the InstallInTrace RSP feature.
317 "set remote install-in-trace-packet off" \
318 "Support for the 'InstallInTrace' packet on the current remote target is set to \"off\"."
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"
325 gdb_trace_setactions "set action for tracepoint" "" \
326 "collect \$$pcreg" "^$"
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"
334 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
337 gdb_test_no_output "tstop"
339 # Nothing should have been collected.
340 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
344 tracepoint_change_loc_1 "trace"
345 tracepoint_change_loc_2 "trace"
346 tracepoint_install_in_trace_disabled "trace"
348 # Re-compile test case with IPA.
349 require allow_in_proc_agent
350 set libipa [get_in_proc_agent]
351 gdb_load_shlib $libipa
353 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
354 [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
355 untested "failed to compile"
359 tracepoint_change_loc_1 "ftrace"
360 tracepoint_change_loc_2 "ftrace"
361 tracepoint_install_in_trace_disabled "ftrace"