1 # Copyright 2011-2014 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]} {
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 if [get_compiler_info] {
36 # Some targets have leading underscores on assembly symbols.
37 set additional_flags [list debug shlib=$lib_sl1 shlib_load [gdb_target_symbol_prefix_flags]]
39 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
40 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
41 || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
42 untested "Could not compile either $libsrc1 or $srcdir/$subdir/$srcfile."
46 clean_restart $executable
48 gdb_load_shlibs $lib_sl1
49 gdb_load_shlibs $lib_sl2
52 fail "Can't run to main to check for trace support"
56 if { ![gdb_target_supports_trace] } then {
57 unsupported "Current target does not support trace"
61 if [is_amd64_regs_target] {
63 } elseif [is_x86_like_target] {
70 # Set tracepoint during tracing experiment.
72 proc tracepoint_change_loc_1 { trace_type } {
73 with_test_prefix "1 $trace_type" {
79 clean_restart ${testfile}
81 fail "Can't run to main"
84 gdb_test_no_output "delete break 1"
86 # Set a tracepoint we'll never meet. Just to avoid the
87 # complain after type `tstart' later.
89 gdb_test "trace main" \
90 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
91 "set tracepoint on main"
93 gdb_test "break marker" \
94 "Breakpoint.*at.* file .*$srcfile, line.*" \
95 "breakpoint on marker"
97 gdb_test_no_output "tstart"
99 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
100 "continue to marker 1"
101 # Set a tracepoint during tracing.
102 set test "set tracepoint on set_tracepoint"
103 gdb_test_multiple "${trace_type} set_tracepoint" $test {
104 -re "Target returns error code .* too far .*$gdb_prompt $" {
105 if [string equal $trace_type "ftrace"] {
106 # The target was unable to install the fast tracepoint
107 # (e.g., jump pad too far from tracepoint).
108 pass "$test (too far)"
113 -re "\r\n$gdb_prompt $" {
118 gdb_trace_setactions "set action for tracepoint" "" \
119 "collect \$$pcreg" "^$"
121 # tracepoint has two locations after shlib change-loc-1 is loaded.
122 gdb_test "info trace" \
123 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
124 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \
125 "tracepoint with two locations"
127 set test "continue to marker 2"
128 gdb_test_multiple "continue" $test {
129 -re "Target returns error code .* too far .*$gdb_prompt $" {
130 if [string equal $trace_type "ftrace"] {
131 # Expected if the target was unable to install the
132 # fast tracepoint (e.g., jump pad too far from
134 pass "$test (too far)"
135 # Skip the rest of the tests.
138 fail "continue to marker 2"
143 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
144 pass "continue to marker 2"
148 # tracepoint has three locations after shlib change-loc-2 is
150 gdb_test "info trace" \
151 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
152 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \
153 "tracepoint with three locations"
155 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
156 "continue to marker 3"
158 # shlib is unloaded, there are still three locations, but one
160 gdb_test "info trace" \
161 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
162 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
163 4\.1.* in func4.*\tinstalled on target\r\n(4\.2.* in func4.*\tinstalled on target\r\n4\.3.* \<PENDING\>\[\t \]+set_tracepoint|4\.2.* \<PENDING\>\[\t \]+set_tracepoint.*4\.3.* in func4.*\tinstalled on target).*" \
164 "tracepoint with two locations (unload)"
166 gdb_test_no_output "tstop"
168 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" \
171 "Target failed to find requested trace frame\\..*"
175 # Set pending tracepoint.
177 proc tracepoint_change_loc_2 { trace_type } {
178 with_test_prefix "2 $trace_type" {
188 gdb_reinitialize_dir $srcdir/$subdir
190 gdb_test_multiple "${trace_type} set_tracepoint" "set pending tracepoint" {
191 -re ".*Make \(|fast \)tracepoint pending.*y or \\\[n\\\]. $" {
192 gdb_test "y" "\(Fast t|T\)racepoint.*set_tracepoint.*pending." "set pending tracepoint"
196 gdb_trace_setactions "set action for tracepoint" "" \
197 "collect \$$pcreg" "^$"
199 # tracepoint has no location information now. Make sure nothing
201 gdb_test "info trace" \
202 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
203 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*PENDING.*set_tracepoint\r\n\[\t \]+collect \\$$pcreg\r" \
204 "single pending tracepoint info (without symbols)"
207 # tracepoint has one location after executable is loaded.
208 gdb_test "info trace" \
209 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
210 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*func4.*" \
211 "tracepoint with one location"
214 gdb_test_multiple "break main" "set breakpoint on main" {
215 -re "Breakpoint (\[0-9\]*) at .*, line.*$gdb_prompt $" {
216 set main_bp $expect_out(1,string)
222 ".*Breakpoint.*main.*at.*$srcfile.*" \
224 gdb_test_no_output "delete break $main_bp"
226 # tracepoint has two locations after shlib change-loc-1 is loaded.
227 gdb_test "info trace" \
228 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
229 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*" \
230 "tracepoint with two locations"
232 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
233 "breakpoint on marker"
235 # tracepoint with two locations will be downloaded and installed.
237 gdb_test_multiple "tstart" $test {
238 -re "^tstart\r\n$gdb_prompt $" {
241 -re "Target returns error code .* too far .*$gdb_prompt $" {
242 if [string equal $trace_type "ftrace"] {
243 # The target was unable to install the fast tracepoint
244 # (e.g., jump pad too far from tracepoint).
245 pass "$test (too far)"
246 # Skip the rest of the tests.
254 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
255 "continue to marker 1"
257 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
258 "continue to marker 2"
260 # tracepoint has three locations after shlib change-loc-2 is loaded.
261 gdb_test "info trace" \
262 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
263 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*1\.3.* in func4 .*" \
264 "tracepoint with three locations"
266 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
267 "continue to marker 3"
269 # shlib is unloaded, there are still three locations, but one is pending.
270 gdb_test "info trace" \
271 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
272 \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*
273 1\.1.* in func4.*\tinstalled on target\r\n(1\.2.* in func4.*\tinstalled on target\r\n1\.3.* \<PENDING\>\[\t \]+set_tracepoint|1\.2.* \<PENDING\>\[\t \]+set_tracepoint\r\n1\.3.* in func4.*\tinstalled on target).*" \
274 "tracepoint with two locations (unload)"
276 gdb_test_no_output "tstop"
278 gdb_test "tfind" "Found trace frame 0, tracepoint 1.*" "tfind frame 0"
279 gdb_test "tfind" "Found trace frame 1, tracepoint 1.*" "tfind frame 1"
280 gdb_test "tfind" "Found trace frame 2, tracepoint 1.*" "tfind frame 2"
281 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
285 # Test that setting a tracepoint while the trace experiment is ongoing
286 # doesn't work when we force-disable the InstallInTrace RSP feature.
288 proc tracepoint_install_in_trace_disabled { trace_type } {
289 with_test_prefix "InstallInTrace disabled: $trace_type" {
295 clean_restart ${testfile}
297 fail "Can't run to main"
301 # This test only makes sense with the remote target.
302 if ![gdb_is_target_remote] {
306 gdb_test_no_output "delete break 1"
308 # Set a tracepoint we'll never meet. Just to avoid the
309 # complain after `tstart' later.
311 gdb_test "trace main" \
312 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
313 "set tracepoint on main"
315 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
316 "breakpoint on marker"
318 gdb_test_no_output "tstart"
320 # Force-disable the InstallInTrace RSP feature.
321 gdb_test_no_output "set remote install-in-trace-packet off"
323 # Set a tracepoint while a trace experiment is ongoing.
324 gdb_test "${trace_type} set_tracepoint" \
325 "racepoint .* at .* set_tracepoint.*" \
326 "set tracepoint on set_tracepoint"
328 gdb_trace_setactions "set action for tracepoint" "" \
329 "collect \$$pcreg" "^$"
331 # Make sure the tracepoint is _not_ installed on the target.
332 gdb_test "info trace" \
333 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
334 \[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.*" \
335 "tracepoint is not installed"
337 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
340 gdb_test_no_output "tstop"
342 # Nothing should have been collected.
343 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
347 tracepoint_change_loc_1 "trace"
348 tracepoint_change_loc_2 "trace"
349 tracepoint_install_in_trace_disabled "trace"
351 # Re-compile test case with IPA.
352 set libipa [get_in_proc_agent]
353 gdb_load_shlibs $libipa
355 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \
356 [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } {
357 untested change-loc.exp
361 tracepoint_change_loc_1 "ftrace"
362 tracepoint_change_loc_2 "ftrace"
363 tracepoint_install_in_trace_disabled "ftrace"