Commit | Line | Data |
---|---|---|
c5a57081 | 1 | # Copyright 2011-2012 Free Software Foundation, Inc. |
b9fd1791 PA |
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 | set testfile "trace-break" | |
18 | set executable $testfile | |
19 | set srcfile $testfile.c | |
20 | set binfile $objdir/$subdir/$testfile | |
21 | set expfile $testfile.exp | |
22 | ||
23 | # Some targets have leading underscores on assembly symbols. | |
24 | set additional_flags [gdb_target_symbol_prefix_flags] | |
25 | ||
26 | if [prepare_for_testing $expfile $executable $srcfile \ | |
27 | [list debug $additional_flags]] { | |
28 | untested "failed to prepare for trace tests" | |
29 | return -1 | |
30 | } | |
31 | ||
32 | if ![runto_main] { | |
33 | fail "Can't run to main to check for trace support" | |
34 | return -1 | |
35 | } | |
36 | ||
37 | if ![gdb_target_supports_trace] { | |
38 | unsupported "target does not support trace" | |
39 | return -1; | |
40 | } | |
41 | ||
1e4d1764 YQ |
42 | set fpreg "fp" |
43 | set spreg "sp" | |
44 | set pcreg "pc" | |
45 | ||
46 | if [is_amd64_regs_target] { | |
47 | set fpreg "rbp" | |
48 | set spreg "rsp" | |
49 | set pcreg "rip" | |
50 | } elseif [is_x86_like_target] { | |
51 | set fpreg "ebp" | |
52 | set spreg "esp" | |
53 | set pcreg "eip" | |
54 | } | |
55 | ||
b9fd1791 PA |
56 | # Set breakpoint and tracepoint at the same address. |
57 | ||
58 | proc break_trace_same_addr_1 { trace_type option } { | |
59 | global executable | |
60 | global pf_prefix | |
61 | global hex | |
62 | ||
63 | set old_pf_prefix $pf_prefix | |
64 | set pf_prefix "$pf_prefix 1 $trace_type $option:" | |
65 | ||
66 | # Start with a fresh gdb. | |
67 | clean_restart ${executable} | |
68 | if ![runto_main] { | |
69 | fail "Can't run to main" | |
70 | set pf_prefix $old_pf_prefix | |
71 | return -1 | |
72 | } | |
73 | ||
74 | gdb_test_no_output "set breakpoint always-inserted ${option}" | |
75 | ||
76 | gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*" | |
77 | ||
78 | gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*" | |
79 | gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" | |
80 | ||
81 | gdb_test_no_output "tstart" | |
82 | ||
83 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to set_point" | |
84 | ||
85 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" | |
86 | gdb_test_no_output "tstop" | |
87 | ||
88 | gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0" | |
89 | gdb_test "tfind" "Target failed to find requested trace frame\\..*" | |
90 | ||
91 | set pf_prefix $old_pf_prefix | |
92 | } | |
93 | ||
94 | # Set multiple tracepoints at the same address. | |
95 | ||
96 | proc break_trace_same_addr_2 { trace_type1 trace_type2 option } { | |
97 | global executable | |
98 | global pf_prefix | |
99 | global hex | |
100 | ||
101 | set old_pf_prefix $pf_prefix | |
102 | set pf_prefix "$pf_prefix 2 $trace_type1 $trace_type2 $option:" | |
103 | ||
104 | # Start with a fresh gdb. | |
105 | clean_restart ${executable} | |
106 | if ![runto_main] { | |
107 | fail "Can't run to main" | |
108 | set pf_prefix $old_pf_prefix | |
109 | return -1 | |
110 | } | |
111 | ||
112 | gdb_test_no_output "set breakpoint always-inserted ${option}" | |
113 | ||
114 | gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*" | |
115 | ||
116 | gdb_test "${trace_type1} set_point" \ | |
117 | "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \ | |
118 | "${trace_type1} set_point (1)" | |
119 | ||
120 | gdb_test "${trace_type2} set_point" \ | |
121 | "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \ | |
122 | "${trace_type2} set_point (2)" | |
123 | ||
124 | gdb_test_no_output "tstart" | |
125 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" | |
126 | ||
127 | gdb_test_no_output "tstop" | |
128 | ||
129 | gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0" | |
130 | gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1" | |
131 | gdb_test "tfind" "Target failed to find requested trace frame\\..*" | |
132 | ||
133 | set pf_prefix $old_pf_prefix | |
134 | } | |
135 | ||
136 | # Set breakpoint and tracepoint at the same address. Delete breakpoint, and verify | |
137 | # that tracepoint still works. | |
138 | ||
139 | proc break_trace_same_addr_3 { trace_type option } { | |
140 | global executable | |
141 | global pf_prefix | |
142 | global hex | |
143 | ||
144 | set old_pf_prefix $pf_prefix | |
145 | set pf_prefix "$pf_prefix 3 $trace_type $option:" | |
146 | ||
147 | # Start with a fresh gdb. | |
148 | clean_restart ${executable} | |
149 | if ![runto_main] { | |
150 | fail "Can't run to main" | |
151 | set pf_prefix $old_pf_prefix | |
152 | return -1 | |
153 | } | |
154 | ||
155 | gdb_test_no_output "set breakpoint always-inserted ${option}" | |
156 | gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*" | |
157 | gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*" | |
158 | ||
159 | gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*" | |
160 | gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" | |
161 | ||
162 | gdb_test_no_output "tstart" | |
163 | ||
164 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker" | |
165 | gdb_test "delete break 4" | |
166 | ||
167 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" | |
168 | gdb_test_no_output "tstop" | |
169 | ||
170 | gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0" | |
171 | gdb_test "tfind" "Target failed to find requested trace frame\\..*" | |
172 | ||
173 | set pf_prefix $old_pf_prefix | |
174 | } | |
175 | ||
176 | # Set breakpoint and tracepoint at the same address. Delete tracepoint, and verify | |
177 | # that breakpoint still works. | |
178 | ||
179 | proc break_trace_same_addr_4 { trace_type option } { | |
180 | global executable | |
181 | global pf_prefix | |
182 | global hex | |
183 | ||
184 | set old_pf_prefix $pf_prefix | |
185 | set pf_prefix "$pf_prefix 4 $trace_type $option:" | |
186 | ||
187 | # Start with a fresh gdb. | |
188 | clean_restart ${executable} | |
189 | if ![runto_main] { | |
190 | fail "Can't run to main" | |
191 | set pf_prefix $old_pf_prefix | |
192 | return -1 | |
193 | } | |
194 | ||
195 | gdb_test_no_output "set breakpoint always-inserted ${option}" | |
196 | gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*" | |
197 | gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*" | |
198 | ||
199 | gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*" | |
200 | gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" | |
201 | ||
202 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker" | |
203 | # Delete tracepoint set on set_point. | |
204 | gdb_test "delete trace 5" | |
205 | ||
206 | gdb_test "tstart" "No tracepoints defined, not starting trace.*" | |
207 | ||
208 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to set_point" | |
209 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" | |
210 | gdb_test "tstop" "Trace is not running.*" | |
211 | ||
212 | gdb_test "tfind" "Target failed to find requested trace frame\\..*" | |
213 | ||
214 | set pf_prefix $old_pf_prefix | |
215 | } | |
216 | ||
1e4d1764 YQ |
217 | # Set two tracepoints TRACE1 and TRACE2 at two locations, and start tracing. |
218 | # Then, set tracepoint TRACE3 at either of these two locations. | |
219 | # TRACE3_AT_FIRST_LOC is a boolean variable to decide insert TRACE3 at which | |
220 | # of two locations. Verify these tracepoints work as expected. | |
221 | ||
222 | proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } { | |
223 | global executable | |
224 | global pf_prefix | |
225 | global hex | |
226 | global fpreg | |
227 | global spreg | |
228 | global pcreg | |
229 | ||
230 | set old_pf_prefix $pf_prefix | |
231 | set pf_prefix "$pf_prefix 5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}:" | |
232 | ||
233 | # Start with a fresh gdb. | |
234 | clean_restart ${executable} | |
235 | if ![runto_main] { | |
236 | fail "Can't run to main" | |
237 | set pf_prefix $old_pf_prefix | |
238 | return -1 | |
239 | } | |
240 | ||
241 | gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*" | |
242 | gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*" | |
243 | ||
244 | gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \ | |
245 | "${trace1} set_point 1" | |
246 | gdb_trace_setactions "set action for tracepoint 1" "" \ | |
247 | "collect \$$pcreg" "^$" | |
248 | gdb_test "${trace2} after_set_point" \ | |
249 | "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \ | |
250 | "${trace2} after_set_point 1" | |
251 | ||
252 | gdb_trace_setactions "set action for tracepoint 2" "" \ | |
253 | "collect \$$spreg" "^$" | |
254 | ||
255 | gdb_test_no_output "tstart" | |
256 | ||
257 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker" | |
258 | ||
259 | if [string equal $trace3_at_first_loc "1"] { | |
260 | gdb_test "${trace3} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \ | |
261 | "${trace3} set_point 2" | |
262 | } else { | |
263 | gdb_test "${trace3} after_set_point" \ | |
264 | "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \ | |
265 | "${trace2} after_set_point 2" | |
266 | } | |
267 | gdb_trace_setactions "set action for tracepoint 3" "" \ | |
268 | "collect \$$fpreg" "^$" | |
269 | ||
270 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" | |
271 | gdb_test_no_output "tstop" | |
272 | ||
273 | gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \ | |
274 | "tfind test frame of tracepoint 4" | |
275 | gdb_test "tdump" \ | |
276 | "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \ | |
277 | "tdump 1" | |
278 | gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \ | |
279 | "reset to frame 0 (1)" | |
280 | gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \ | |
281 | "tfind test frame of tracepoint 5" | |
282 | gdb_test "tdump" \ | |
283 | "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \ | |
284 | "tdump 2" | |
285 | gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \ | |
286 | "reset to frame 0 (2)" | |
287 | gdb_test "tfind tracepoint 6" "Found trace frame \[0-9\], tracepoint .*" \ | |
288 | "tfind test frame of tracepoint 6" | |
289 | gdb_test "tdump" \ | |
290 | "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${fpreg} = .*" \ | |
291 | "tdump 3" | |
292 | ||
293 | set pf_prefix $old_pf_prefix | |
294 | } | |
295 | ||
296 | # Set two tracepoints at the same address, and enable/disable them. Verify | |
297 | # tracepoints work as expect. | |
298 | ||
299 | proc break_trace_same_addr_6 { trace1 enable1 trace2 enable2 } { | |
300 | global executable | |
301 | global pf_prefix | |
302 | global hex | |
303 | global gdb_prompt | |
304 | global spreg | |
305 | global pcreg | |
306 | ||
307 | set old_pf_prefix $pf_prefix | |
308 | set pf_prefix "$pf_prefix 6 $trace1 $enable1 $trace2 $enable2:" | |
309 | ||
310 | # Start with a fresh gdb. | |
311 | clean_restart ${executable} | |
312 | if ![runto_main] { | |
313 | fail "Can't run to main" | |
314 | set pf_prefix $old_pf_prefix | |
315 | return -1 | |
316 | } | |
317 | ||
318 | gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*" | |
319 | gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*" | |
320 | ||
321 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker" | |
322 | ||
323 | gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \ | |
324 | "${trace1} set_point 1" | |
325 | gdb_trace_setactions "set action for tracepoint 1" "" \ | |
326 | "collect \$$pcreg" "^$" | |
327 | gdb_test "${trace2} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \ | |
328 | "${trace2} set_point 2" | |
329 | gdb_trace_setactions "set action for tracepoint 2" "" \ | |
330 | "collect \$$spreg" "^$" | |
331 | ||
332 | gdb_test_no_output "$enable1 4" | |
333 | gdb_test_no_output "$enable2 5" | |
334 | ||
335 | gdb_test_no_output "tstart" | |
336 | gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end" | |
337 | gdb_test_no_output "tstop" | |
338 | ||
339 | ||
340 | if [string equal $enable1 "enable"] { | |
341 | gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \ | |
342 | "tfind test frame of tracepoint 4" | |
343 | gdb_test "tdump" \ | |
344 | "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \ | |
345 | "tdump 1" | |
346 | gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \ | |
347 | "reset to frame 0 (1)" | |
348 | } else { | |
349 | gdb_test "tfind tracepoint 4" "Target failed to find requested trace frame.*" \ | |
350 | "tfind test frame of tracepoint 4" | |
351 | } | |
352 | ||
353 | if [string equal $enable2 "enable"] { | |
354 | gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \ | |
355 | "tfind test frame of tracepoint 5" | |
356 | gdb_test "tdump" \ | |
357 | "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \ | |
358 | "tdump 2" | |
359 | gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \ | |
360 | "reset to frame 0 (2)" | |
361 | } else { | |
362 | gdb_test "tfind tracepoint 5" "Target failed to find requested trace frame.*" \ | |
363 | "tfind test frame of tracepoint 5" | |
364 | } | |
365 | ||
366 | set pf_prefix $old_pf_prefix | |
367 | } | |
368 | ||
369 | ||
b9fd1791 PA |
370 | foreach break_always_inserted { "on" "off" } { |
371 | break_trace_same_addr_1 "trace" ${break_always_inserted} | |
372 | break_trace_same_addr_2 "trace" "trace" ${break_always_inserted} | |
373 | break_trace_same_addr_3 "trace" ${break_always_inserted} | |
374 | break_trace_same_addr_4 "trace" ${break_always_inserted} | |
375 | } | |
376 | ||
1e4d1764 YQ |
377 | foreach at_first_loc { "1" "0" } { |
378 | break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc} | |
379 | } | |
380 | ||
381 | break_trace_same_addr_6 "trace" "enable" "trace" "disable" | |
382 | break_trace_same_addr_6 "trace" "disable" "trace" "enable" | |
383 | ||
b9fd1791 PA |
384 | set libipa $objdir/../gdbserver/libinproctrace.so |
385 | gdb_load_shlibs $libipa | |
386 | ||
387 | # Can't use prepare_for_testing, because that splits compiling into | |
388 | # building objects and then linking, and we'd fail with "linker input | |
389 | # file unused because linking not done" when building the object. | |
390 | ||
391 | if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ | |
392 | executable [list debug $additional_flags shlib=$libipa] ] != "" } { | |
393 | untested "failed to compile ftrace tests" | |
394 | return -1 | |
395 | } | |
396 | clean_restart ${executable} | |
397 | ||
398 | if ![runto_main] { | |
399 | fail "Can't run to main for ftrace tests" | |
400 | return 0 | |
401 | } | |
402 | ||
403 | gdb_reinitialize_dir $srcdir/$subdir | |
404 | if { [gdb_test "info sharedlibrary" ".*libinproctrace\.so.*" "IPA loaded"] != 0 } { | |
405 | untested "Could not find IPA lib loaded" | |
406 | } else { | |
407 | foreach break_always_inserted { "on" "off" } { | |
408 | break_trace_same_addr_1 "ftrace" ${break_always_inserted} | |
409 | break_trace_same_addr_2 "trace" "ftrace" ${break_always_inserted} | |
410 | break_trace_same_addr_2 "ftrace" "trace" ${break_always_inserted} | |
a59306a3 | 411 | break_trace_same_addr_2 "ftrace" "ftrace" ${break_always_inserted} |
b9fd1791 PA |
412 | break_trace_same_addr_3 "ftrace" ${break_always_inserted} |
413 | break_trace_same_addr_4 "ftrace" ${break_always_inserted} | |
414 | } | |
1e4d1764 YQ |
415 | |
416 | foreach trace1 { "trace" "ftrace" } { | |
417 | foreach trace2 { "trace" "ftrace" } { | |
418 | foreach trace3 { "trace" "ftrace" } { | |
419 | ||
420 | if { [string equal $trace1 "trace"] | |
421 | && [string equal $trace2 "trace"] | |
422 | && [string equal $trace3 "trace"] } { | |
423 | continue | |
424 | } | |
425 | ||
426 | foreach at_first_loc { "1" "0" } { | |
427 | break_trace_same_addr_5 $trace1 $trace2 $trace3 $at_first_loc | |
428 | } | |
429 | } | |
430 | } | |
431 | } | |
432 | ||
433 | foreach trace1 { "trace" "ftrace" } { | |
434 | foreach trace2 { "trace" "ftrace" } { | |
435 | if { [string equal $trace1 "trace"] | |
436 | && [string equal $trace2 "trace"] } { | |
437 | continue | |
438 | } | |
439 | break_trace_same_addr_6 $trace1 "enable" $trace2 "disable" | |
440 | break_trace_same_addr_6 $trace1 "disable" $trace2 "enable" | |
441 | } | |
442 | } | |
b9fd1791 | 443 | } |