Clean up gdb.trace test results on targets not supporting this feature.
[binutils-gdb.git] / gdb / testsuite / gdb.trace / change-loc.exp
1 # Copyright 2011-2018 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 if [get_compiler_info] {
38 return -1
39 }
40
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]]
43
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"
48 return -1
49 }
50
51 clean_restart $executable
52
53 gdb_load_shlib $lib_sl1
54 gdb_load_shlib $lib_sl2
55
56 if ![runto_main] {
57 fail "can't run to main to check for trace support"
58 return -1
59 }
60
61 if { ![gdb_target_supports_trace] } then {
62 unsupported "current target does not support trace"
63 return -1
64 }
65
66
67 # Set tracepoint during tracing experiment.
68
69 proc tracepoint_change_loc_1 { trace_type } {
70 with_test_prefix "1 $trace_type" {
71 global testfile
72 global srcfile
73 global pcreg
74 global gdb_prompt
75
76 clean_restart ${testfile}
77 if ![runto_main] {
78 fail "can't run to main"
79 return -1
80 }
81 gdb_test_no_output "delete break 1"
82
83 # Set a tracepoint we'll never meet. Just to avoid the
84 # complain after type `tstart' later.
85 gdb_test "next" ".*"
86 gdb_test "trace main" \
87 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
88 "set tracepoint on main"
89
90 gdb_test "break marker" \
91 "Breakpoint.*at.* file .*$srcfile, line.*" \
92 "breakpoint on marker"
93
94 gdb_test_no_output "tstart"
95
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)"
106 } else {
107 fail $test
108 }
109 }
110 -re "\r\n$gdb_prompt $" {
111 pass $test
112 }
113 }
114
115 gdb_trace_setactions "set action for tracepoint" "" \
116 "collect \$$pcreg" "^$"
117
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"
123
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
130 # tracepoint).
131 pass "$test (too far)"
132 # Skip the rest of the tests.
133 return
134 } else {
135 fail "continue to marker 2"
136 fail $test
137 }
138
139 }
140 -re ".*Breakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
141 pass "continue to marker 2"
142 }
143 }
144
145 # tracepoint has three locations after shlib change-loc-2 is
146 # loaded.
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"
151
152 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
153 "continue to marker 3"
154
155 # shlib is unloaded, there are still three locations, but one
156 # is pending.
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)"
162
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)"
168
169 gdb_test_no_output "tstop"
170
171 gdb_test "tfind" "Found trace frame 0, tracepoint 4.*" \
172 "tfind frame 0"
173 gdb_test "tfind" \
174 "Target failed to find requested trace frame\\..*"
175 }
176 }
177
178 # Set pending tracepoint.
179
180 proc tracepoint_change_loc_2 { trace_type } {
181 with_test_prefix "2 $trace_type" {
182 global srcdir
183 global srcfile
184 global subdir
185 global pcreg
186 global binfile
187 global gdb_prompt
188
189 gdb_exit
190 gdb_start
191 gdb_reinitialize_dir $srcdir/$subdir
192
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"
196 }
197 }
198
199 gdb_trace_setactions "set action for tracepoint" "" \
200 "collect \$$pcreg" "^$"
201
202 # tracepoint has no location information now. Make sure nothing
203 # else is displayed.
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)"
208
209 gdb_load ${binfile}
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"
215
216 set main_bp 0
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)
220 }
221 }
222 gdb_run_cmd
223
224 gdb_test "" \
225 ".*Breakpoint.*main.*at.*$srcfile.*" \
226 "run to main"
227 gdb_test_no_output "delete break $main_bp"
228
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"
234
235 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
236 "breakpoint on marker"
237
238 # tracepoint with two locations will be downloaded and installed.
239 set test "tstart"
240 gdb_test_multiple "tstart" $test {
241 -re "^tstart\r\n$gdb_prompt $" {
242 pass "tstart"
243 }
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.
250 return
251 } else {
252 fail $test
253 }
254 }
255 }
256
257 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
258 "continue to marker 1"
259
260 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
261 "continue to marker 2"
262
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"
268
269 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
270 "continue to marker 3"
271
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)"
278
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)"
284
285 gdb_test_no_output "tstop"
286
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\\..*"
291 }
292 }
293
294 # Test that setting a tracepoint while the trace experiment is ongoing
295 # doesn't work when we force-disable the InstallInTrace RSP feature.
296
297 proc tracepoint_install_in_trace_disabled { trace_type } {
298 with_test_prefix "InstallInTrace disabled: $trace_type" {
299 global testfile
300 global srcfile
301 global pcreg
302 global gdb_prompt
303
304 clean_restart ${testfile}
305 if ![runto_main] {
306 fail "can't run to main"
307 return -1
308 }
309
310 # This test only makes sense with the remote target.
311 if ![gdb_is_target_remote] {
312 return
313 }
314
315 gdb_test_no_output "delete break 1"
316
317 # Set a tracepoint we'll never meet. Just to avoid the
318 # complain after `tstart' later.
319 gdb_test "next" ".*"
320 gdb_test "trace main" \
321 "Tracepoint \[0-9\] at.* file .*$srcfile, line.*" \
322 "set tracepoint on main"
323
324 gdb_test "break marker" "Breakpoint.*at.* file .*$srcfile, line.*" \
325 "breakpoint on marker"
326
327 gdb_test_no_output "tstart"
328
329 # Force-disable the InstallInTrace RSP feature.
330 gdb_test_no_output "set remote install-in-trace-packet off"
331
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"
336
337 gdb_trace_setactions "set action for tracepoint" "" \
338 "collect \$$pcreg" "^$"
339
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"
345
346 gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \
347 "continue to marker"
348
349 gdb_test_no_output "tstop"
350
351 # Nothing should have been collected.
352 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
353 }
354 }
355
356 tracepoint_change_loc_1 "trace"
357 tracepoint_change_loc_2 "trace"
358 tracepoint_install_in_trace_disabled "trace"
359
360 # Re-compile test case with IPA.
361 set libipa [get_in_proc_agent]
362 gdb_load_shlib $libipa
363
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"
367 return -1
368 }
369
370 tracepoint_change_loc_1 "ftrace"
371 tracepoint_change_loc_2 "ftrace"
372 tracepoint_install_in_trace_disabled "ftrace"