1 # Copyright 2011-2020 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 ![gdb_trace_common_supports_arch] {
25 unsupported "no trace-common.h support for arch"
29 if [prepare_for_testing "failed to prepare" $executable $srcfile \
30 [list debug $additional_flags]] {
35 fail "can't run to main to check for trace support"
39 if ![gdb_target_supports_trace] {
40 unsupported "target does not support trace"
44 # Set breakpoint and tracepoint at the same address.
46 proc break_trace_same_addr_1 { trace_type option } \
47 { with_test_prefix "1 $trace_type $option" \
52 # Start with a fresh gdb.
53 clean_restart ${executable}
55 fail "can't run to main"
59 gdb_test_no_output "set breakpoint always-inserted ${option}"
61 gdb_breakpoint "end" qualified
63 gdb_breakpoint "set_point" qualified
64 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
66 gdb_test_no_output "tstart"
68 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
69 "continue to set_point"
71 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
73 gdb_test_no_output "tstop"
75 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
76 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
79 # Set multiple tracepoints at the same address.
81 proc break_trace_same_addr_2 { trace_type1 trace_type2 option } \
82 { with_test_prefix "2 $trace_type1 $trace_type2 $option" \
87 # Start with a fresh gdb.
88 clean_restart ${executable}
90 fail "can't run to main"
94 gdb_test_no_output "set breakpoint always-inserted ${option}"
96 gdb_breakpoint "end" qualified
98 gdb_test "${trace_type1} set_point" \
99 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
100 "${trace_type1} set_point (1)"
102 gdb_test "${trace_type2} set_point" \
103 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
104 "${trace_type2} set_point (2)"
106 gdb_test_no_output "tstart"
107 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
110 gdb_test_no_output "tstop"
112 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
113 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
114 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
117 # Set breakpoint and tracepoint at the same address. Delete breakpoint, and verify
118 # that tracepoint still works.
120 proc break_trace_same_addr_3 { trace_type option } \
121 { with_test_prefix "3 $trace_type $option" \
126 # Start with a fresh gdb.
127 clean_restart ${executable}
129 fail "can't run to main"
133 gdb_test_no_output "set breakpoint always-inserted ${option}"
134 gdb_breakpoint "marker" qualified
135 gdb_breakpoint "end" qualified
137 gdb_breakpoint "set_point" qualified
138 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
140 gdb_test_no_output "tstart"
142 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
144 gdb_test "delete break 4"
146 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
148 gdb_test_no_output "tstop"
150 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
151 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
154 # Set breakpoint and tracepoint at the same address. Delete tracepoint, and verify
155 # that breakpoint still works.
157 proc break_trace_same_addr_4 { trace_type option } \
158 { with_test_prefix "4 $trace_type $option" \
164 # Start with a fresh gdb.
165 clean_restart ${executable}
167 fail "can't run to main"
171 gdb_test_no_output "set breakpoint always-inserted ${option}"
172 gdb_breakpoint "marker" qualified
173 gdb_breakpoint "end" qualified
175 gdb_breakpoint "set_point" qualified
176 gdb_test "${trace_type} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*"
178 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
180 # Delete tracepoint set on set_point.
181 gdb_test "delete trace 5"
183 gdb_test "tstart" "No tracepoints defined, not starting trace.*"
185 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
186 "continue to set_point"
187 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
189 gdb_test "tstop" "Trace is not running.*"
191 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
194 # Set two tracepoints TRACE1 and TRACE2 at two locations, and start tracing.
195 # Then, set tracepoint TRACE3 at either of these two locations.
196 # TRACE3_AT_FIRST_LOC is a boolean variable to decide insert TRACE3 at which
197 # of two locations. Verify these tracepoints work as expected.
199 proc break_trace_same_addr_5 { trace1 trace2 trace3 trace3_at_first_loc } \
200 { with_test_prefix "5 $trace1 $trace2 ${trace3}@${trace3_at_first_loc}" \
208 # Start with a fresh gdb.
209 clean_restart ${executable}
211 fail "can't run to main"
215 gdb_breakpoint "marker" qualified
216 gdb_breakpoint "end" qualified
218 gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
219 "${trace1} set_point 1"
220 gdb_trace_setactions "set action for tracepoint 1" "" \
221 "collect \$$pcreg" "^$"
222 gdb_test "${trace2} after_set_point" \
223 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
224 "${trace2} after_set_point 1"
226 gdb_trace_setactions "set action for tracepoint 2" "" \
227 "collect \$$spreg" "^$"
229 gdb_test_no_output "tstart"
231 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
234 if [string equal $trace3_at_first_loc "1"] {
235 gdb_test "${trace3} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
236 "${trace3} set_point 2"
238 gdb_test "${trace3} after_set_point" \
239 "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
240 "${trace2} after_set_point 2"
242 gdb_trace_setactions "set action for tracepoint 3" "" \
243 "collect \$$fpreg" "^$"
245 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
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_breakpoint "marker" qualified
290 gdb_breakpoint "end" qualified
292 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
295 gdb_test "${trace1} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
296 "${trace1} set_point 1"
297 gdb_trace_setactions "set action for tracepoint 1" "" \
298 "collect \$$pcreg" "^$"
299 gdb_test "${trace2} set_point" "\(Fast t|T\)racepoint \[0-9\] at $hex: file.*" \
300 "${trace2} set_point 2"
301 gdb_trace_setactions "set action for tracepoint 2" "" \
302 "collect \$$spreg" "^$"
304 gdb_test_no_output "$enable1 4"
305 gdb_test_no_output "$enable2 5"
307 gdb_test_no_output "tstart"
308 gdb_test "continue" "Continuing\\.\[ \r\n\]+(Thread .* hit )?Breakpoint.*" \
310 gdb_test_no_output "tstop"
313 if [string equal $enable1 "enable"] {
314 gdb_test "tfind tracepoint 4" "Found trace frame \[0-9\], tracepoint .*" \
315 "tfind test frame of tracepoint 4"
317 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${pcreg} = .*" \
319 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
320 "reset to frame 0 (1)"
322 gdb_test "tfind tracepoint 4" "Target failed to find requested trace frame.*" \
323 "tfind test frame of tracepoint 4"
326 if [string equal $enable2 "enable"] {
327 gdb_test "tfind tracepoint 5" "Found trace frame \[0-9\], tracepoint .*" \
328 "tfind test frame of tracepoint 5"
330 "Data collected at tracepoint .*, trace frame \[0-9\]:.*\\$${spreg} = .*" \
332 gdb_test "tfind 0" "Found trace frame 0, tracepoint .*" \
333 "reset to frame 0 (2)"
335 gdb_test "tfind tracepoint 5" "Target failed to find requested trace frame.*" \
336 "tfind test frame of tracepoint 5"
341 foreach break_always_inserted { "on" "off" } {
342 break_trace_same_addr_1 "trace" ${break_always_inserted}
343 break_trace_same_addr_2 "trace" "trace" ${break_always_inserted}
344 break_trace_same_addr_3 "trace" ${break_always_inserted}
345 break_trace_same_addr_4 "trace" ${break_always_inserted}
348 foreach at_first_loc { "1" "0" } {
349 break_trace_same_addr_5 "trace" "trace" "trace" ${at_first_loc}
352 break_trace_same_addr_6 "trace" "enable" "trace" "disable"
353 break_trace_same_addr_6 "trace" "disable" "trace" "enable"
355 if {[skip_shlib_tests]} {
359 set libipa [get_in_proc_agent]
360 set remote_libipa [gdb_load_shlib $libipa]
362 # Can't use prepare_for_testing, because that splits compiling into
363 # building objects and then linking, and we'd fail with "linker input
364 # file unused because linking not done" when building the object.
366 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
367 executable [list debug $additional_flags shlib=$libipa] ] != "" } {
368 untested "failed to compile"
371 clean_restart ${executable}
374 fail "can't run to main for ftrace tests"
378 gdb_reinitialize_dir $srcdir/$subdir
379 if { [gdb_test "info sharedlibrary" ".*${remote_libipa}.*" "IPA loaded"] != 0 } {
380 untested "could not find IPA lib loaded"
382 foreach break_always_inserted { "on" "off" } {
383 break_trace_same_addr_1 "ftrace" ${break_always_inserted}
384 break_trace_same_addr_2 "trace" "ftrace" ${break_always_inserted}
385 break_trace_same_addr_2 "ftrace" "trace" ${break_always_inserted}
386 break_trace_same_addr_2 "ftrace" "ftrace" ${break_always_inserted}
387 break_trace_same_addr_3 "ftrace" ${break_always_inserted}
388 break_trace_same_addr_4 "ftrace" ${break_always_inserted}
391 foreach trace1 { "trace" "ftrace" } {
392 foreach trace2 { "trace" "ftrace" } {
393 foreach trace3 { "trace" "ftrace" } {
395 if { [string equal $trace1 "trace"]
396 && [string equal $trace2 "trace"]
397 && [string equal $trace3 "trace"] } {
401 foreach at_first_loc { "1" "0" } {
402 break_trace_same_addr_5 $trace1 $trace2 $trace3 $at_first_loc
408 foreach trace1 { "trace" "ftrace" } {
409 foreach trace2 { "trace" "ftrace" } {
410 if { [string equal $trace1 "trace"]
411 && [string equal $trace2 "trace"] } {
414 break_trace_same_addr_6 $trace1 "enable" $trace2 "disable"
415 break_trace_same_addr_6 $trace1 "disable" $trace2 "enable"