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 $expfile $executable $srcfile \
25 [list debug $additional_flags]] {
26 untested "failed to prepare for trace tests"
31 fail "can't run to main to check for trace support"
35 if ![gdb_target_supports_trace] {
36 unsupported "target does not support trace"
40 # Set breakpoint and tracepoint at the same address.
42 proc break_trace_same_addr_1 { trace_type option } \
43 { with_test_prefix "1 $trace_type $option" \
48 # Start with a fresh gdb.
49 clean_restart ${executable}
51 fail "can't run to main"
55 gdb_test_no_output "set breakpoint always-inserted ${option}"
57 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
59 gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
60 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
62 gdb_test_no_output "tstart"
64 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
65 "continue to set_point"
67 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
69 gdb_test_no_output "tstop"
71 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
72 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
75 # Set multiple tracepoints at the same address.
77 proc break_trace_same_addr_2 { trace_type1 trace_type2 option } \
78 { with_test_prefix "2 $trace_type1 $trace_type2 $option" \
83 # Start with a fresh gdb.
84 clean_restart ${executable}
86 fail "can't run to main"
90 gdb_test_no_output "set breakpoint always-inserted ${option}"
92 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
94 gdb_test "${trace_type1} set_point" \
95 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
96 "${trace_type1} set_point (1)"
98 gdb_test "${trace_type2} set_point" \
99 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
100 "${trace_type2} set_point (2)"
102 gdb_test_no_output "tstart"
103 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
106 gdb_test_no_output "tstop"
108 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
109 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
110 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
113 # Set breakpoint and tracepoint at the same address. Delete breakpoint, and verify
114 # that tracepoint still works.
116 proc break_trace_same_addr_3 { trace_type option } \
117 { with_test_prefix "3 $trace_type $option" \
122 # Start with a fresh gdb.
123 clean_restart ${executable}
125 fail "can't run to main"
129 gdb_test_no_output "set breakpoint always-inserted ${option}"
130 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
131 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
133 gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
134 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
136 gdb_test_no_output "tstart"
138 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
140 gdb_test "delete break 4"
142 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
144 gdb_test_no_output "tstop"
146 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
147 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
150 # Set breakpoint and tracepoint at the same address. Delete tracepoint, and verify
151 # that breakpoint still works.
153 proc break_trace_same_addr_4 { trace_type option } \
154 { with_test_prefix "4 $trace_type $option" \
160 # Start with a fresh gdb.
161 clean_restart ${executable}
163 fail "can't run to main"
167 gdb_test_no_output "set breakpoint always-inserted ${option}"
168 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
169 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
171 gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
172 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
174 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
176 # Delete tracepoint set on set_point.
177 gdb_test "delete trace 5"
179 gdb_test "tstart" "No tracepoints defined, not starting trace.*"
181 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
182 "continue to set_point"
183 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
185 gdb_test "tstop" "Trace is not running.*"
187 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
190 # Set two tracepoints TRACE1 and TRACE2 at two locations, and start tracing.
191 # Then, set tracepoint TRACE3 at either of these two locations.
192 # TRACE3_AT_FIRST_LOC is a boolean variable to decide insert TRACE3 at which
193 # of two locations. Verify these tracepoints work as expected.
195 proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } \
196 { with_test_prefix "5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}" \
204 # Start with a fresh gdb.
205 clean_restart ${executable}
207 fail "can't run to main"
211 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
212 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
214 gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
215 "${trace1} set_point 1"
216 gdb_trace_setactions "set action for tracepoint 1" "" \
217 "collect \$$pcreg" "^$"
218 gdb_test "${trace2} after_set_point" \
219 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
220 "${trace2} after_set_point 1"
222 gdb_trace_setactions "set action for tracepoint 2" "" \
223 "collect \$$spreg" "^$"
225 gdb_test_no_output "tstart"
227 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
230 if [string equal $trace3_at_first_loc "1"] {
231 gdb_test "${trace3} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
232 "${trace3} set_point 2"
234 gdb_test "${trace3} after_set_point" \
235 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
236 "${trace2} after_set_point 2"
238 gdb_trace_setactions "set action for tracepoint 3" "" \
239 "collect \$$fpreg" "^$"
241 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
243 gdb_test_no_output "tstop"
245 gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
246 "tfind test frame of tracepoint 4"
248 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
250 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
251 "reset to frame 0 (1)"
252 gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
253 "tfind test frame of tracepoint 5"
255 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
257 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
258 "reset to frame 0 (2)"
259 gdb_test "tfind tracepoint 6" "Found trace frame \[0-9\], tracepoint .*" \
260 "tfind test frame of tracepoint 6"
262 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${fpreg} = .*" \
266 # Set two tracepoints at the same address, and enable/disable them. Verify
267 # tracepoints work as expect.
269 proc break_trace_same_addr_6 { trace1 enable1 trace2 enable2 } \
270 { with_test_prefix "6 $trace1 $enable1 $trace2 $enable2" \
278 # Start with a fresh gdb.
279 clean_restart ${executable}
281 fail "can't run to main"
285 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
286 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
288 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
291 gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
292 "${trace1} set_point 1"
293 gdb_trace_setactions "set action for tracepoint 1" "" \
294 "collect \$$pcreg" "^$"
295 gdb_test "${trace2} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
296 "${trace2} set_point 2"
297 gdb_trace_setactions "set action for tracepoint 2" "" \
298 "collect \$$spreg" "^$"
300 gdb_test_no_output "$enable1 4"
301 gdb_test_no_output "$enable2 5"
303 gdb_test_no_output "tstart"
304 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
306 gdb_test_no_output "tstop"
309 if [string equal $enable1 "enable"] {
310 gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
311 "tfind test frame of tracepoint 4"
313 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
315 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
316 "reset to frame 0 (1)"
318 gdb_test "tfind tracepoint 4" "Target failed to find requested trace frame.*" \
319 "tfind test frame of tracepoint 4"
322 if [string equal $enable2 "enable"] {
323 gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
324 "tfind test frame of tracepoint 5"
326 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
328 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
329 "reset to frame 0 (2)"
331 gdb_test "tfind tracepoint 5" "Target failed to find requested trace frame.*" \
332 "tfind test frame of tracepoint 5"
337 foreach break_always_inserted { "on" "off" } {
338 break_trace_same_addr_1 "trace" ${break_always_inserted}
339 break_trace_same_addr_2 "trace" "trace" ${break_always_inserted}
340 break_trace_same_addr_3 "trace" ${break_always_inserted}
341 break_trace_same_addr_4 "trace" ${break_always_inserted}
344 foreach at_first_loc { "1" "0" } {
345 break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc}
348 break_trace_same_addr_6 "trace" "enable" "trace" "disable"
349 break_trace_same_addr_6 "trace" "disable" "trace" "enable"
351 set libipa [get_in_proc_agent]
352 set remote_libipa [gdb_load_shlib $libipa]
354 # Can't use prepare_for_testing, because that splits compiling into
355 # building objects and then linking, and we'd fail with "linker input
356 # file unused because linking not done" when building the object.
358 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
359 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
360 untested "failed to compile ftrace tests"
363 clean_restart ${executable}
366 fail "can't run to main for ftrace tests"
370 gdb_reinitialize_dir $srcdir/$subdir
371 if { [gdb_test "info sharedlibrary" ".*${remote_libipa}.*" "IPA loaded"] != 0 } {
372 untested "could not find IPA lib loaded"
374 foreach break_always_inserted { "on" "off" } {
375 break_trace_same_addr_1 "ftrace" ${break_always_inserted}
376 break_trace_same_addr_2 "trace" "ftrace" ${break_always_inserted}
377 break_trace_same_addr_2 "ftrace" "trace" ${break_always_inserted}
378 break_trace_same_addr_2 "ftrace" "ftrace" ${break_always_inserted}
379 break_trace_same_addr_3 "ftrace" ${break_always_inserted}
380 break_trace_same_addr_4 "ftrace" ${break_always_inserted}
383 foreach trace1 { "trace" "ftrace" } {
384 foreach trace2 { "trace" "ftrace" } {
385 foreach trace3 { "trace" "ftrace" } {
387 if { [string equal $trace1 "trace"]
388 && [string equal $trace2 "trace"]
389 && [string equal $trace3 "trace"] } {
393 foreach at_first_loc { "1" "0" } {
394 break_trace_same_addr_5 $trace1 $trace2 $trace3 $at_first_loc
400 foreach trace1 { "trace" "ftrace" } {
401 foreach trace2 { "trace" "ftrace" } {
402 if { [string equal $trace1 "trace"]
403 && [string equal $trace2 "trace"] } {
406 break_trace_same_addr_6 $trace1 "enable" $trace2 "disable"
407 break_trace_same_addr_6 $trace1 "disable" $trace2 "enable"