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.
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.
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/>.
15 load_lib "trace-support.exp"
18 set executable $testfile
19 set expfile $testfile.exp
21 # Some targets have leading underscores on assembly symbols.
22 set additional_flags [gdb_target_symbol_prefix_flags]
24 if [prepare_for_testing "failed to prepare" $executable $srcfile \
25 [list debug $additional_flags]] {
30 fail "can't run to main to check for trace support"
34 if ![gdb_target_supports_trace] {
35 unsupported "target does not support trace"
39 # Set breakpoint and tracepoint at the same address.
41 proc break_trace_same_addr_1 { trace_type option } \
42 { with_test_prefix "1 $trace_type $option" \
47 # Start with a fresh gdb.
48 clean_restart ${executable}
50 fail "can't run to main"
54 gdb_test_no_output "set breakpoint always-inserted ${option}"
56 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
58 gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
59 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
61 gdb_test_no_output "tstart"
63 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
64 "continue to set_point"
66 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
68 gdb_test_no_output "tstop"
70 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
71 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
74 # Set multiple tracepoints at the same address.
76 proc break_trace_same_addr_2 { trace_type1 trace_type2 option } \
77 { with_test_prefix "2 $trace_type1 $trace_type2 $option" \
82 # Start with a fresh gdb.
83 clean_restart ${executable}
85 fail "can't run to main"
89 gdb_test_no_output "set breakpoint always-inserted ${option}"
91 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
93 gdb_test "${trace_type1} set_point" \
94 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
95 "${trace_type1} set_point (1)"
97 gdb_test "${trace_type2} set_point" \
98 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
99 "${trace_type2} set_point (2)"
101 gdb_test_no_output "tstart"
102 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
105 gdb_test_no_output "tstop"
107 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
108 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
109 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
112 # Set breakpoint and tracepoint at the same address. Delete breakpoint, and verify
113 # that tracepoint still works.
115 proc break_trace_same_addr_3 { trace_type option } \
116 { with_test_prefix "3 $trace_type $option" \
121 # Start with a fresh gdb.
122 clean_restart ${executable}
124 fail "can't run to main"
128 gdb_test_no_output "set breakpoint always-inserted ${option}"
129 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
130 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
132 gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
133 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
135 gdb_test_no_output "tstart"
137 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
139 gdb_test "delete break 4"
141 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
143 gdb_test_no_output "tstop"
145 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
146 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
149 # Set breakpoint and tracepoint at the same address. Delete tracepoint, and verify
150 # that breakpoint still works.
152 proc break_trace_same_addr_4 { trace_type option } \
153 { with_test_prefix "4 $trace_type $option" \
159 # Start with a fresh gdb.
160 clean_restart ${executable}
162 fail "can't run to main"
166 gdb_test_no_output "set breakpoint always-inserted ${option}"
167 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
168 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
170 gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
171 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
173 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
175 # Delete tracepoint set on set_point.
176 gdb_test "delete trace 5"
178 gdb_test "tstart" "No tracepoints defined, not starting trace.*"
180 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
181 "continue to set_point"
182 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
184 gdb_test "tstop" "Trace is not running.*"
186 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
189 # Set two tracepoints TRACE1 and TRACE2 at two locations, and start tracing.
190 # Then, set tracepoint TRACE3 at either of these two locations.
191 # TRACE3_AT_FIRST_LOC is a boolean variable to decide insert TRACE3 at which
192 # of two locations. Verify these tracepoints work as expected.
194 proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } \
195 { with_test_prefix "5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}" \
203 # Start with a fresh gdb.
204 clean_restart ${executable}
206 fail "can't run to main"
210 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
211 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
213 gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
214 "${trace1} set_point 1"
215 gdb_trace_setactions "set action for tracepoint 1" "" \
216 "collect \$$pcreg" "^$"
217 gdb_test "${trace2} after_set_point" \
218 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
219 "${trace2} after_set_point 1"
221 gdb_trace_setactions "set action for tracepoint 2" "" \
222 "collect \$$spreg" "^$"
224 gdb_test_no_output "tstart"
226 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
229 if [string equal $trace3_at_first_loc "1"] {
230 gdb_test "${trace3} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
231 "${trace3} set_point 2"
233 gdb_test "${trace3} after_set_point" \
234 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
235 "${trace2} after_set_point 2"
237 gdb_trace_setactions "set action for tracepoint 3" "" \
238 "collect \$$fpreg" "^$"
240 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
242 gdb_test_no_output "tstop"
244 gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
245 "tfind test frame of tracepoint 4"
247 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
249 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
250 "reset to frame 0 (1)"
251 gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
252 "tfind test frame of tracepoint 5"
254 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
256 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
257 "reset to frame 0 (2)"
258 gdb_test "tfind tracepoint 6" "Found trace frame \[0-9\], tracepoint .*" \
259 "tfind test frame of tracepoint 6"
261 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${fpreg} = .*" \
265 # Set two tracepoints at the same address, and enable/disable them. Verify
266 # tracepoints work as expect.
268 proc break_trace_same_addr_6 { trace1 enable1 trace2 enable2 } \
269 { with_test_prefix "6 $trace1 $enable1 $trace2 $enable2" \
277 # Start with a fresh gdb.
278 clean_restart ${executable}
280 fail "can't run to main"
284 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
285 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
287 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
290 gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
291 "${trace1} set_point 1"
292 gdb_trace_setactions "set action for tracepoint 1" "" \
293 "collect \$$pcreg" "^$"
294 gdb_test "${trace2} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
295 "${trace2} set_point 2"
296 gdb_trace_setactions "set action for tracepoint 2" "" \
297 "collect \$$spreg" "^$"
299 gdb_test_no_output "$enable1 4"
300 gdb_test_no_output "$enable2 5"
302 gdb_test_no_output "tstart"
303 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
305 gdb_test_no_output "tstop"
308 if [string equal $enable1 "enable"] {
309 gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
310 "tfind test frame of tracepoint 4"
312 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
314 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
315 "reset to frame 0 (1)"
317 gdb_test "tfind tracepoint 4" "Target failed to find requested trace frame.*" \
318 "tfind test frame of tracepoint 4"
321 if [string equal $enable2 "enable"] {
322 gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
323 "tfind test frame of tracepoint 5"
325 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
327 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
328 "reset to frame 0 (2)"
330 gdb_test "tfind tracepoint 5" "Target failed to find requested trace frame.*" \
331 "tfind test frame of tracepoint 5"
336 foreach break_always_inserted { "on" "off" } {
337 break_trace_same_addr_1 "trace" ${break_always_inserted}
338 break_trace_same_addr_2 "trace" "trace" ${break_always_inserted}
339 break_trace_same_addr_3 "trace" ${break_always_inserted}
340 break_trace_same_addr_4 "trace" ${break_always_inserted}
343 foreach at_first_loc { "1" "0" } {
344 break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc}
347 break_trace_same_addr_6 "trace" "enable" "trace" "disable"
348 break_trace_same_addr_6 "trace" "disable" "trace" "enable"
350 set libipa [get_in_proc_agent]
351 set remote_libipa [gdb_load_shlib $libipa]
353 # Can't use prepare_for_testing, because that splits compiling into
354 # building objects and then linking, and we'd fail with "linker input
355 # file unused because linking not done" when building the object.
357 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
358 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
359 untested "failed to compile"
362 clean_restart ${executable}
365 fail "can't run to main for ftrace tests"
369 gdb_reinitialize_dir $srcdir/$subdir
370 if { [gdb_test "info sharedlibrary" ".*${remote_libipa}.*" "IPA loaded"] != 0 } {
371 untested "could not find IPA lib loaded"
373 foreach break_always_inserted { "on" "off" } {
374 break_trace_same_addr_1 "ftrace" ${break_always_inserted}
375 break_trace_same_addr_2 "trace" "ftrace" ${break_always_inserted}
376 break_trace_same_addr_2 "ftrace" "trace" ${break_always_inserted}
377 break_trace_same_addr_2 "ftrace" "ftrace" ${break_always_inserted}
378 break_trace_same_addr_3 "ftrace" ${break_always_inserted}
379 break_trace_same_addr_4 "ftrace" ${break_always_inserted}
382 foreach trace1 { "trace" "ftrace" } {
383 foreach trace2 { "trace" "ftrace" } {
384 foreach trace3 { "trace" "ftrace" } {
386 if { [string equal $trace1 "trace"]
387 && [string equal $trace2 "trace"]
388 && [string equal $trace3 "trace"] } {
392 foreach at_first_loc { "1" "0" } {
393 break_trace_same_addr_5 $trace1 $trace2 $trace3 $at_first_loc
399 foreach trace1 { "trace" "ftrace" } {
400 foreach trace2 { "trace" "ftrace" } {
401 if { [string equal $trace1 "trace"]
402 && [string equal $trace2 "trace"] } {
405 break_trace_same_addr_6 $trace1 "enable" $trace2 "disable"
406 break_trace_same_addr_6 $trace1 "disable" $trace2 "enable"