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