1 # Copyright 2011-2013 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"
44 if [is_amd64_regs_target] {
48 } elseif [is_x86_like_target] {
54 # Set breakpoint and tracepoint at the same address.
56 proc break_trace_same_addr_1 { trace_type option } \
57 { with_test_prefix "1 $trace_type $option" \
62 # Start with a fresh gdb.
63 clean_restart ${executable}
65 fail "Can't run to main"
69 gdb_test_no_output "set breakpoint always-inserted ${option}"
71 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
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.*"
76 gdb_test_no_output "tstart"
78 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to set_point"
80 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
81 gdb_test_no_output "tstop"
83 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
84 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
87 # Set multiple tracepoints at the same address.
89 proc break_trace_same_addr_2 { trace_type1 trace_type2 option } \
90 { with_test_prefix "2 $trace_type1 $trace_type2 $option" \
95 # Start with a fresh gdb.
96 clean_restart ${executable}
98 fail "Can't run to main"
102 gdb_test_no_output "set breakpoint always-inserted ${option}"
104 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
106 gdb_test "${trace_type1} set_point" \
107 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
108 "${trace_type1} set_point (1)"
110 gdb_test "${trace_type2} set_point" \
111 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
112 "${trace_type2} set_point (2)"
114 gdb_test_no_output "tstart"
115 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
117 gdb_test_no_output "tstop"
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\\..*"
124 # Set breakpoint and tracepoint at the same address. Delete breakpoint, and verify
125 # that tracepoint still works.
127 proc break_trace_same_addr_3 { trace_type option } \
128 { with_test_prefix "3 $trace_type $option" \
133 # Start with a fresh gdb.
134 clean_restart ${executable}
136 fail "Can't run to main"
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.*"
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.*"
147 gdb_test_no_output "tstart"
149 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
150 gdb_test "delete break 4"
152 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
153 gdb_test_no_output "tstop"
155 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
156 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
159 # Set breakpoint and tracepoint at the same address. Delete tracepoint, and verify
160 # that breakpoint still works.
162 proc break_trace_same_addr_4 { trace_type option } \
163 { with_test_prefix "4 $trace_type $option" \
169 # Start with a fresh gdb.
170 clean_restart ${executable}
172 fail "Can't run to main"
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.*"
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.*"
183 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
184 # Delete tracepoint set on set_point.
185 gdb_test "delete trace 5"
187 gdb_test "tstart" "No tracepoints defined, not starting trace.*"
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.*"
193 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
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.
201 proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } \
202 { with_test_prefix "5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}" \
210 # Start with a fresh gdb.
211 clean_restart ${executable}
213 fail "Can't run to main"
217 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
218 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
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"
228 gdb_trace_setactions "set action for tracepoint 2" "" \
229 "collect \$$spreg" "^$"
231 gdb_test_no_output "tstart"
233 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
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"
239 gdb_test "${trace3} after_set_point" \
240 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
241 "${trace2} after_set_point 2"
243 gdb_trace_setactions "set action for tracepoint 3" "" \
244 "collect \$$fpreg" "^$"
246 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
247 gdb_test_no_output "tstop"
249 gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
250 "tfind test frame of tracepoint 4"
252 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
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"
259 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
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"
266 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${fpreg} = .*" \
270 # Set two tracepoints at the same address, and enable/disable them. Verify
271 # tracepoints work as expect.
273 proc break_trace_same_addr_6 { trace1 enable1 trace2 enable2 } \
274 { with_test_prefix "6 $trace1 $enable1 $trace2 $enable2" \
282 # Start with a fresh gdb.
283 clean_restart ${executable}
285 fail "Can't run to main"
289 gdb_test "break marker" "Breakpoint \[0-9\] at $hex: file.*"
290 gdb_test "break end" "Breakpoint \[0-9\] at $hex: file.*"
292 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to marker"
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" "^$"
303 gdb_test_no_output "$enable1 4"
304 gdb_test_no_output "$enable2 5"
306 gdb_test_no_output "tstart"
307 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
308 gdb_test_no_output "tstop"
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"
315 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
317 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
318 "reset to frame 0 (1)"
320 gdb_test "tfind tracepoint 4" "Target failed to find requested trace frame.*" \
321 "tfind test frame of tracepoint 4"
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"
328 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
330 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
331 "reset to frame 0 (2)"
333 gdb_test "tfind tracepoint 5" "Target failed to find requested trace frame.*" \
334 "tfind test frame of tracepoint 5"
339 foreach 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}
346 foreach at_first_loc { "1" "0" } {
347 break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc}
350 break_trace_same_addr_6 "trace" "enable" "trace" "disable"
351 break_trace_same_addr_6 "trace" "disable" "trace" "enable"
353 set libipa [get_in_proc_agent]
354 gdb_load_shlibs $libipa
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.
360 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
361 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
362 untested "failed to compile ftrace tests"
365 clean_restart ${executable}
368 fail "Can't run to main for ftrace tests"
372 gdb_reinitialize_dir $srcdir/$subdir
373 if { [gdb_test "info sharedlibrary" ".*${libipa}.*" "IPA loaded"] != 0 } {
374 untested "Could not find IPA lib loaded"
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}
380 break_trace_same_addr_2 "ftrace" "ftrace" ${break_always_inserted}
381 break_trace_same_addr_3 "ftrace" ${break_always_inserted}
382 break_trace_same_addr_4 "ftrace" ${break_always_inserted}
385 foreach trace1 { "trace" "ftrace" } {
386 foreach trace2 { "trace" "ftrace" } {
387 foreach trace3 { "trace" "ftrace" } {
389 if { [string equal $trace1 "trace"]
390 && [string equal $trace2 "trace"]
391 && [string equal $trace3 "trace"] } {
395 foreach at_first_loc { "1" "0" } {
396 break_trace_same_addr_5 $trace1 $trace2 $trace3 $at_first_loc
402 foreach trace1 { "trace" "ftrace" } {
403 foreach trace2 { "trace" "ftrace" } {
404 if { [string equal $trace1 "trace"]
405 && [string equal $trace2 "trace"] } {
408 break_trace_same_addr_6 $trace1 "enable" $trace2 "disable"
409 break_trace_same_addr_6 $trace1 "disable" $trace2 "enable"