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