1 # Copyright 2011-2020 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 if {[skip_shlib_tests]} {
21 if ![gdb_trace_common_supports_arch] {
22 unsupported "no trace-common.h support for arch"
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]
37 if [get_compiler_info] {
41 # Some targets have leading underscores on assembly symbols.
42 set additional_flags [list debug shlib=$lib_sl1 shlib_load [gdb_target_symbol_prefix_flags]]
44 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
45 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
46 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
47 untested "failed to compile"
51 clean_restart $executable
53 gdb_load_shlib $lib_sl1
54 gdb_load_shlib $lib_sl2
57 fail "can't run to main to check for trace support"
61 if { ![gdb_target_supports_trace] } then {
62 unsupported "current target does not support trace"
67 # Set tracepoint during tracing experiment.
69 proc tracepoint_change_loc_1 { trace_type } {
70 with_test_prefix "1 $trace_type" {
76 clean_restart ${testfile}
78 fail "can't run to main"
81 gdb_test_no_output "delete break 1"
83 # Set a tracepoint we'll never meet. Just to avoid the
84 # complain after type `tstart' later.
86 gdb_test "trace main" \
87 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
88 "set tracepoint on main"
90 gdb_test "break marker" \
91 "Breakpoint.*at.* file .*$srcfile, line.*" \
92 "breakpoint on marker"
94 gdb_test_no_output "tstart"
96 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
97 "continue to marker 1"
98 # Set a tracepoint during tracing.
99 set test "set tracepoint on set_tracepoint"
100 gdb_test_multiple "${trace_type} set_tracepoint" $test {
101 -re "Target returns error code .* too far .*$gdb_prompt $" {
102 if [string equal $trace_type "ftrace"] {
103 # The target was unable to install the fast tracepoint
104 # (e.g., jump pad too far from tracepoint).
105 pass "$test (too far)"
110 -re "\r\n$gdb_prompt $" {
115 gdb_trace_setactions "set action for tracepoint" "" \
116 "collect \$$pcreg" "^$"
118 # tracepoint has two locations after shlib change-loc-1 is loaded.
119 gdb_test "info trace" \
120 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
121 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \
122 "tracepoint with two locations"
124 set test "continue to marker 2"
125 gdb_test_multiple "continue" $test {
126 -re "Target returns error code .* too far .*$gdb_prompt $" {
127 if [string equal $trace_type "ftrace"] {
128 # Expected if the target was unable to install the
129 # fast tracepoint (e.g., jump pad too far from
131 pass "$test (too far)"
132 # Skip the rest of the tests.
135 fail "continue to marker 2"
140 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
141 pass "continue to marker 2"
145 # tracepoint has three locations after shlib change-loc-2 is
147 gdb_test "info trace" \
148 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
149 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \
150 "tracepoint with three locations"
152 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
153 "continue to marker 3"
155 # shlib is unloaded, there are still three locations, but one
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].* in func4.*\tinstalled on target.*){2}" \
161 "tracepoint with two locations - installed (unload)"
163 gdb_test "info trace" \
164 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
165 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
166 4\.\[1-3].* \<PENDING\>\[\t \]+set_tracepoint.*" \
167 "tracepoint with two locations - pending (unload)"
169 gdb_test_no_output "tstop"
171 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" \
174 "Target failed to find requested trace frame\\..*"
178 # Set pending tracepoint.
180 proc tracepoint_change_loc_2 { trace_type } {
181 with_test_prefix "2 $trace_type" {
191 gdb_reinitialize_dir $srcdir/$subdir
193 gdb_test_multiple "${trace_type} set_tracepoint" "set pending tracepoint" {
194 -re ".*Make \(|fast \)tracepoint pending.*y or \\\[n\\\]. $" {
195 gdb_test "y" "\(Fast t|T\)racepoint.*set_tracepoint.*pending." "set pending tracepoint"
199 gdb_trace_setactions "set action for tracepoint" "" \
200 "collect \$$pcreg" "^$"
202 # tracepoint has no location information now. Make sure nothing
204 gdb_test "info trace" \
205 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
206 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*PENDING.*set_tracepoint\r\n\[\t \]+collect \\$$pcreg\r" \
207 "single pending tracepoint info (without symbols)"
210 # tracepoint has one location after executable is loaded.
211 gdb_test "info trace" \
212 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
213 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*func4.*" \
214 "tracepoint with one location"
217 gdb_test_multiple "break main" "set breakpoint on main" {
218 -re "Breakpoint (\[0-9\]*) at .*, line.*$gdb_prompt $" {
219 set main_bp $expect_out(1,string)
225 ".*Breakpoint.*main.*at.*$srcfile.*" \
227 gdb_test_no_output "delete break $main_bp"
229 # tracepoint has two locations after shlib change-loc-1 is loaded.
230 gdb_test "info trace" \
231 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
232 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*" \
233 "tracepoint with two locations"
235 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
236 "breakpoint on marker"
238 # tracepoint with two locations will be downloaded and installed.
240 gdb_test_multiple "tstart" $test {
241 -re "^tstart\r\n$gdb_prompt $" {
244 -re "Target returns error code .* too far .*$gdb_prompt $" {
245 if [string equal $trace_type "ftrace"] {
246 # The target was unable to install the fast tracepoint
247 # (e.g., jump pad too far from tracepoint).
248 pass "$test (too far)"
249 # Skip the rest of the tests.
257 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
258 "continue to marker 1"
260 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
261 "continue to marker 2"
263 # tracepoint has three locations after shlib change-loc-2 is loaded.
264 gdb_test "info trace" \
265 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
266 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*1\.3.* in func4 .*" \
267 "tracepoint with three locations"
269 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
270 "continue to marker 3"
272 # shlib is unloaded, there are still three locations, but one is pending.
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].* in func4.*\tinstalled on target.*){2}" \
277 "tracepoint with two locations - installed (unload)"
279 gdb_test "info trace" \
280 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
281 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
282 1\.\[1-3].* \<PENDING\>\[\t \]+set_tracepoint.*" \
283 "tracepoint with two locations - pending (unload)"
285 gdb_test_no_output "tstop"
287 gdb_test "tfind" "Found trace frame 0, tracepoint 1.*" "tfind frame 0"
288 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind frame 1"
289 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind frame 2"
290 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
294 # Test that setting a tracepoint while the trace experiment is ongoing
295 # doesn't work when we force-disable the InstallInTrace RSP feature.
297 proc tracepoint_install_in_trace_disabled { trace_type } {
298 with_test_prefix "InstallInTrace disabled: $trace_type" {
304 clean_restart ${testfile}
306 fail "can't run to main"
310 # This test only makes sense with the remote target.
311 if ![gdb_is_target_remote] {
315 gdb_test_no_output "delete break 1"
317 # Set a tracepoint we'll never meet. Just to avoid the
318 # complain after `tstart' later.
320 gdb_test "trace main" \
321 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
322 "set tracepoint on main"
324 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
325 "breakpoint on marker"
327 gdb_test_no_output "tstart"
329 # Force-disable the InstallInTrace RSP feature.
330 gdb_test_no_output "set remote install-in-trace-packet off"
332 # Set a tracepoint while a trace experiment is ongoing.
333 gdb_test "${trace_type} set_tracepoint" \
334 "racepoint .* at .* set_tracepoint.*" \
335 "set tracepoint on set_tracepoint"
337 gdb_trace_setactions "set action for tracepoint" "" \
338 "collect \$$pcreg" "^$"
340 # Make sure the tracepoint is _not_ installed on the target.
341 gdb_test "info trace" \
342 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
343 \[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.*" \
344 "tracepoint is not installed"
346 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
349 gdb_test_no_output "tstop"
351 # Nothing should have been collected.
352 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
356 tracepoint_change_loc_1 "trace"
357 tracepoint_change_loc_2 "trace"
358 tracepoint_install_in_trace_disabled "trace"
360 # Re-compile test case with IPA.
361 set libipa [get_in_proc_agent]
362 gdb_load_shlib $libipa
364 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
365 [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
366 untested "failed to compile"
370 tracepoint_change_loc_1 "ftrace"
371 tracepoint_change_loc_2 "ftrace"
372 tracepoint_install_in_trace_disabled "ftrace"