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\]+Breakpoint.*" "continue to set_point"
66 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
67 gdb_test_no_output "tstop"
69 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
70 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
73 # Set multiple tracepoints at the same address.
75 proc break_trace_same_addr_2 { trace_type1 trace_type2 option } \
76 { with_test_prefix "2 $trace_type1 $trace_type2 $option" \
81 # Start with a fresh gdb.
82 clean_restart ${executable}
84 fail "Can't run to main"
88 gdb_test_no_output "set breakpoint always-inserted ${option}"
90 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
92 gdb_test "${trace_type1} set_point" \
93 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
94 "${trace_type1} set_point (1)"
96 gdb_test "${trace_type2} set_point" \
97 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
98 "${trace_type2} set_point (2)"
100 gdb_test_no_output "tstart"
101 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
103 gdb_test_no_output "tstop"
105 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
106 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
107 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
110 # Set breakpoint and tracepoint at the same address. Delete breakpoint, and verify
111 # that tracepoint still works.
113 proc break_trace_same_addr_3 { trace_type option } \
114 { with_test_prefix "3 $trace_type $option" \
119 # Start with a fresh gdb.
120 clean_restart ${executable}
122 fail "Can't run to main"
126 gdb_test_no_output "set breakpoint always-inserted ${option}"
127 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
128 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
130 gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
131 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
133 gdb_test_no_output "tstart"
135 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
136 gdb_test "delete break 4"
138 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
139 gdb_test_no_output "tstop"
141 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
142 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
145 # Set breakpoint and tracepoint at the same address. Delete tracepoint, and verify
146 # that breakpoint still works.
148 proc break_trace_same_addr_4 { trace_type option } \
149 { with_test_prefix "4 $trace_type $option" \
155 # Start with a fresh gdb.
156 clean_restart ${executable}
158 fail "Can't run to main"
162 gdb_test_no_output "set breakpoint always-inserted ${option}"
163 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
164 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
166 gdb_test "break set_point" "Breakpoint \[0-9\] at $hex: file.*"
167 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
169 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
170 # Delete tracepoint set on set_point.
171 gdb_test "delete trace 5"
173 gdb_test "tstart" "No tracepoints defined, not starting trace.*"
175 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to set_point"
176 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
177 gdb_test "tstop" "Trace is not running.*"
179 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
182 # Set two tracepoints TRACE1 and TRACE2 at two locations, and start tracing.
183 # Then, set tracepoint TRACE3 at either of these two locations.
184 # TRACE3_AT_FIRST_LOC is a boolean variable to decide insert TRACE3 at which
185 # of two locations. Verify these tracepoints work as expected.
187 proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } \
188 { with_test_prefix "5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}" \
196 # Start with a fresh gdb.
197 clean_restart ${executable}
199 fail "Can't run to main"
203 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
204 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
206 gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
207 "${trace1} set_point 1"
208 gdb_trace_setactions "set action for tracepoint 1" "" \
209 "collect \$$pcreg" "^$"
210 gdb_test "${trace2} after_set_point" \
211 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
212 "${trace2} after_set_point 1"
214 gdb_trace_setactions "set action for tracepoint 2" "" \
215 "collect \$$spreg" "^$"
217 gdb_test_no_output "tstart"
219 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
221 if [string equal $trace3_at_first_loc "1"] {
222 gdb_test "${trace3} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
223 "${trace3} set_point 2"
225 gdb_test "${trace3} after_set_point" \
226 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
227 "${trace2} after_set_point 2"
229 gdb_trace_setactions "set action for tracepoint 3" "" \
230 "collect \$$fpreg" "^$"
232 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
233 gdb_test_no_output "tstop"
235 gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
236 "tfind test frame of tracepoint 4"
238 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
240 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
241 "reset to frame 0 (1)"
242 gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
243 "tfind test frame of tracepoint 5"
245 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
247 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
248 "reset to frame 0 (2)"
249 gdb_test "tfind tracepoint 6" "Found trace frame \[0-9\], tracepoint .*" \
250 "tfind test frame of tracepoint 6"
252 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${fpreg} = .*" \
256 # Set two tracepoints at the same address, and enable/disable them. Verify
257 # tracepoints work as expect.
259 proc break_trace_same_addr_6 { trace1 enable1 trace2 enable2 } \
260 { with_test_prefix "6 $trace1 $enable1 $trace2 $enable2" \
268 # Start with a fresh gdb.
269 clean_restart ${executable}
271 fail "Can't run to main"
275 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
276 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
278 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
280 gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
281 "${trace1} set_point 1"
282 gdb_trace_setactions "set action for tracepoint 1" "" \
283 "collect \$$pcreg" "^$"
284 gdb_test "${trace2} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
285 "${trace2} set_point 2"
286 gdb_trace_setactions "set action for tracepoint 2" "" \
287 "collect \$$spreg" "^$"
289 gdb_test_no_output "$enable1 4"
290 gdb_test_no_output "$enable2 5"
292 gdb_test_no_output "tstart"
293 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
294 gdb_test_no_output "tstop"
297 if [string equal $enable1 "enable"] {
298 gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
299 "tfind test frame of tracepoint 4"
301 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
303 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
304 "reset to frame 0 (1)"
306 gdb_test "tfind tracepoint 4" "Target failed to find requested trace frame.*" \
307 "tfind test frame of tracepoint 4"
310 if [string equal $enable2 "enable"] {
311 gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
312 "tfind test frame of tracepoint 5"
314 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
316 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
317 "reset to frame 0 (2)"
319 gdb_test "tfind tracepoint 5" "Target failed to find requested trace frame.*" \
320 "tfind test frame of tracepoint 5"
325 foreach break_always_inserted { "on" "off" } {
326 break_trace_same_addr_1 "trace" ${break_always_inserted}
327 break_trace_same_addr_2 "trace" "trace" ${break_always_inserted}
328 break_trace_same_addr_3 "trace" ${break_always_inserted}
329 break_trace_same_addr_4 "trace" ${break_always_inserted}
332 foreach at_first_loc { "1" "0" } {
333 break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc}
336 break_trace_same_addr_6 "trace" "enable" "trace" "disable"
337 break_trace_same_addr_6 "trace" "disable" "trace" "enable"
339 set libipa [get_in_proc_agent]
340 gdb_load_shlibs $libipa
342 # Can't use prepare_for_testing, because that splits compiling into
343 # building objects and then linking, and we'd fail with "linker input
344 # file unused because linking not done" when building the object.
346 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
347 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
348 untested "failed to compile ftrace tests"
351 clean_restart ${executable}
354 fail "Can't run to main for ftrace tests"
358 gdb_reinitialize_dir $srcdir/$subdir
359 if { [gdb_test "info sharedlibrary" ".*${libipa}.*" "IPA loaded"] != 0 } {
360 untested "Could not find IPA lib loaded"
362 foreach break_always_inserted { "on" "off" } {
363 break_trace_same_addr_1 "ftrace" ${break_always_inserted}
364 break_trace_same_addr_2 "trace" "ftrace" ${break_always_inserted}
365 break_trace_same_addr_2 "ftrace" "trace" ${break_always_inserted}
366 break_trace_same_addr_2 "ftrace" "ftrace" ${break_always_inserted}
367 break_trace_same_addr_3 "ftrace" ${break_always_inserted}
368 break_trace_same_addr_4 "ftrace" ${break_always_inserted}
371 foreach trace1 { "trace" "ftrace" } {
372 foreach trace2 { "trace" "ftrace" } {
373 foreach trace3 { "trace" "ftrace" } {
375 if { [string equal $trace1 "trace"]
376 && [string equal $trace2 "trace"]
377 && [string equal $trace3 "trace"] } {
381 foreach at_first_loc { "1" "0" } {
382 break_trace_same_addr_5 $trace1 $trace2 $trace3 $at_first_loc
388 foreach trace1 { "trace" "ftrace" } {
389 foreach trace2 { "trace" "ftrace" } {
390 if { [string equal $trace1 "trace"]
391 && [string equal $trace2 "trace"] } {
394 break_trace_same_addr_6 $trace1 "enable" $trace2 "disable"
395 break_trace_same_addr_6 $trace1 "disable" $trace2 "enable"