Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2011-2020 Free Software Foundation, Inc. |
1e4d1764 YQ |
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 | ||
4ec70201 | 15 | load_lib "trace-support.exp" |
1e4d1764 | 16 | |
1e4d1764 YQ |
17 | if {[skip_shlib_tests]} { |
18 | return 0 | |
19 | } | |
20 | ||
8bca2978 SL |
21 | if ![gdb_trace_common_supports_arch] { |
22 | unsupported "no trace-common.h support for arch" | |
23 | return -1 | |
24 | } | |
25 | ||
497a5eb0 | 26 | standard_testfile |
1e4d1764 YQ |
27 | set libfile1 "change-loc-1" |
28 | set libfile2 "change-loc-2" | |
1e4d1764 YQ |
29 | set executable $testfile |
30 | set libsrc1 $srcdir/$subdir/$libfile1.c | |
31 | set libsrc2 $srcdir/$subdir/$libfile2.c | |
497a5eb0 TT |
32 | set lib_sl1 [standard_output_file $libfile1.sl] |
33 | set lib_sl2 [standard_output_file $libfile2.sl] | |
1e4d1764 YQ |
34 | |
35 | set lib_opts debug | |
36 | ||
4c93b1db | 37 | if [get_compiler_info] { |
1e4d1764 YQ |
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] != ""} { | |
84c93cd5 | 47 | untested "failed to compile" |
1e4d1764 YQ |
48 | return -1 |
49 | } | |
50 | ||
51 | clean_restart $executable | |
52 | ||
d9019901 SM |
53 | gdb_load_shlib $lib_sl1 |
54 | gdb_load_shlib $lib_sl2 | |
1e4d1764 YQ |
55 | |
56 | if ![runto_main] { | |
bc6c7af4 | 57 | fail "can't run to main to check for trace support" |
1e4d1764 YQ |
58 | return -1 |
59 | } | |
60 | ||
61 | if { ![gdb_target_supports_trace] } then { | |
bc6c7af4 | 62 | unsupported "current target does not support trace" |
ae59b1da | 63 | return -1 |
1e4d1764 YQ |
64 | } |
65 | ||
1e4d1764 YQ |
66 | |
67 | # Set tracepoint during tracing experiment. | |
68 | ||
0a251e08 YQ |
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] { | |
bc6c7af4 | 78 | fail "can't run to main" |
0a251e08 | 79 | return -1 |
f4647387 | 80 | } |
0a251e08 YQ |
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 | } | |
f4647387 | 113 | } |
1e4d1764 | 114 | |
0a251e08 YQ |
115 | gdb_trace_setactions "set action for tracepoint" "" \ |
116 | "collect \$$pcreg" "^$" | |
1e4d1764 | 117 | |
0a251e08 YQ |
118 | # tracepoint has two locations after shlib change-loc-1 is loaded. |
119 | gdb_test "info trace" \ | |
120 | "Num Type\[ \]+Disp Enb Address\[ \]+What.* | |
1e4d1764 | 121 | \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*" \ |
0a251e08 YQ |
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 | } | |
f4647387 | 138 | |
0a251e08 YQ |
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.* | |
1e4d1764 | 149 | \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*4\.1.* in func4.*4\.2.* in func4.*4\.3.* in func4 .*" \ |
0a251e08 | 150 | "tracepoint with three locations" |
1e4d1764 | 151 | |
0a251e08 YQ |
152 | gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ |
153 | "continue to marker 3" | |
bfccc43c | 154 | |
0a251e08 YQ |
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.* | |
f2a8bc8a | 159 | \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.* |
ba84e0da MK |
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)" | |
bfccc43c | 168 | |
0a251e08 | 169 | gdb_test_no_output "tstop" |
1e4d1764 | 170 | |
0a251e08 YQ |
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 | } | |
1e4d1764 | 177 | |
bfccc43c YQ |
178 | # Set pending tracepoint. |
179 | ||
0a251e08 YQ |
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 | } | |
bfccc43c | 197 | } |
bfccc43c | 198 | |
0a251e08 YQ |
199 | gdb_trace_setactions "set action for tracepoint" "" \ |
200 | "collect \$$pcreg" "^$" | |
bfccc43c | 201 | |
0a251e08 YQ |
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.* | |
f2a8bc8a | 206 | \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*PENDING.*set_tracepoint\r\n\[\t \]+collect \\$$pcreg\r" \ |
0a251e08 | 207 | "single pending tracepoint info (without symbols)" |
bfccc43c | 208 | |
0a251e08 YQ |
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.* | |
bfccc43c | 213 | \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*func4.*" \ |
0a251e08 | 214 | "tracepoint with one location" |
bfccc43c | 215 | |
0a251e08 YQ |
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 | } | |
bfccc43c | 221 | } |
0a251e08 | 222 | gdb_run_cmd |
bfccc43c | 223 | |
0a251e08 YQ |
224 | gdb_test "" \ |
225 | ".*Breakpoint.*main.*at.*$srcfile.*" \ | |
226 | "run to main" | |
227 | gdb_test_no_output "delete break $main_bp" | |
bfccc43c | 228 | |
0a251e08 YQ |
229 | # tracepoint has two locations after shlib change-loc-1 is loaded. |
230 | gdb_test "info trace" \ | |
231 | "Num Type\[ \]+Disp Enb Address\[ \]+What.* | |
bfccc43c | 232 | \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*" \ |
0a251e08 YQ |
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 | } | |
bfccc43c | 255 | } |
bfccc43c | 256 | |
0a251e08 YQ |
257 | gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ |
258 | "continue to marker 1" | |
f4647387 | 259 | |
0a251e08 YQ |
260 | gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ |
261 | "continue to marker 2" | |
bfccc43c | 262 | |
0a251e08 YQ |
263 | # tracepoint has three locations after shlib change-loc-2 is loaded. |
264 | gdb_test "info trace" \ | |
265 | "Num Type\[ \]+Disp Enb Address\[ \]+What.* | |
bfccc43c | 266 | \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.*1\.1.* in func4.*1\.2.* in func4.*1\.3.* in func4 .*" \ |
0a251e08 | 267 | "tracepoint with three locations" |
bfccc43c | 268 | |
0a251e08 YQ |
269 | gdb_test "continue" ".*Breakpoint.*marker.*at.*$srcfile.*" \ |
270 | "continue to marker 3" | |
bfccc43c | 271 | |
0a251e08 YQ |
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.* | |
f2a8bc8a | 275 | \[0-9\]+\[\t \]+\(|fast \)tracepoint\[ \]+keep y.*\<MULTIPLE\>.* |
ba84e0da MK |
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)" | |
bfccc43c | 284 | |
0a251e08 | 285 | gdb_test_no_output "tstop" |
bfccc43c | 286 | |
0a251e08 YQ |
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 | } | |
1e4d1764 | 293 | |
4082afcc PA |
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] { | |
bc6c7af4 | 306 | fail "can't run to main" |
4082afcc PA |
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 | ||
1e4d1764 | 356 | tracepoint_change_loc_1 "trace" |
bfccc43c | 357 | tracepoint_change_loc_2 "trace" |
4082afcc | 358 | tracepoint_install_in_trace_disabled "trace" |
1e4d1764 YQ |
359 | |
360 | # Re-compile test case with IPA. | |
c0d4d1c0 | 361 | set libipa [get_in_proc_agent] |
d9019901 | 362 | gdb_load_shlib $libipa |
1e4d1764 YQ |
363 | |
364 | if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable \ | |
365 | [list debug nowarnings shlib=$libipa shlib=$lib_sl1 shlib_load] ] != "" } { | |
5b362f04 | 366 | untested "failed to compile" |
1e4d1764 YQ |
367 | return -1 |
368 | } | |
369 | ||
370 | tracepoint_change_loc_1 "ftrace" | |
bfccc43c | 371 | tracepoint_change_loc_2 "ftrace" |
4082afcc | 372 | tracepoint_install_in_trace_disabled "ftrace" |