1 # Copyright 1998, 2007, 2008 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
19 # This file was written by Michael Snyder (msnyder@cygnus.com)
21 load_lib "trace-support.exp";
33 if [istarget "m68k-*-elf"] then {
34 load_lib "emc-support.exp";
35 set srcfile gdb_c_test.c
36 set binfile [board_info target d490_binfile];
37 gdb_test "set remotetimeout 6" "" ""
39 gdb_target_monitor "$binfile"
40 # Give a TSTOP and ignore errors, to make sure any previous trace is off
41 gdb_test "tstop" "" ""
42 gdb_test "tfind none" "" ""
43 send_gdb "compare-sections CS\n"
45 -re "MIS-MATCHED.*$gdb_prompt $" {
46 untested backtrace.exp
48 all tests in this module will fail.";
50 -re ".*$gdb_prompt $" { }
53 set testfile "actions"
54 set srcfile ${testfile}.c
55 set binfile $objdir/$subdir/$testfile
56 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
57 executable {debug nowarnings}] != "" } {
58 untested backtrace.exp
62 gdb_test "tstop" "" ""
63 gdb_test "tfind none" "" ""
66 gdb_reinitialize_dir $srcdir/$subdir
68 # We generously give ourselves one "pass" if we successfully
69 # detect that this test cannot be run on this target!
70 if { ![gdb_target_supports_trace] } then {
71 pass "Current target does not support trace"
77 # test backtraces in trace frames
94 set baseline [gdb_find_recursion_test_baseline $srcfile];
95 if { $baseline == -1 } {
96 fail "Could not find gdb_recursion_test function"
100 send_gdb "list $baseline, +12\n"
102 -re "\[\r\n\](\[0-9\]+).*gdbtestline 1 " {
103 set testline1 $expect_out(1,string)
106 -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
107 set testline2 $expect_out(1,string)
110 -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
111 set testline3 $expect_out(1,string)
114 -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
115 set testline4 $expect_out(1,string)
118 -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
119 set testline5 $expect_out(1,string)
122 -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
123 set testline6 $expect_out(1,string)
126 -re ".*$gdb_prompt $" {
127 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
128 untested backtrace.exp
130 all tests in this module will fail."
134 untested backtrace.exp
136 all tests in this module will fail."
141 # Setup backtrace experiment. This will involve:
142 # 1) a tracepoint where nothing is collected
143 # 2) a tracepoint where only regs are collected
144 # 3) a tracepoint where regs, locals and args are collected
145 # 4) a tracepoint where regs plus some amount of stack are collected.
148 gdb_delete_tracepoints
149 set tdp2 [gdb_gettpnum $testline2]
150 set tdp3 [gdb_gettpnum $testline3]
151 set tdp4 [gdb_gettpnum $testline4]
152 set tdp5 [gdb_gettpnum $testline5]
153 set tdp6 [gdb_gettpnum $testline6]
154 if { $tdp2 <= 0 || $tdp3 <= 0 || \
155 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
156 fail "setting tracepoints failed"
160 #gdb_trace_setactions "setup TP to collect FP" \
165 gdb_trace_setactions "8.6: setup TP to collect regs" \
167 "collect \$regs" "^$"
169 gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
171 "collect \$regs, \$args, \$locs" "^$"
173 gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
175 "collect \$fp, \(\*\(void \*\*\) \(\$sp\)\) @ 64" "^$"
177 gdb_test "tstart" "" ""
179 if [istarget "m68k-*-elf"] then {
180 gdb_emclaptop_command "85,$arg1,$arg2,$arg3,$arg4,$arg5,$arg6"
183 gdb_test "break end" "" ""
184 gdb_test "continue" \
185 "Continuing.*Breakpoint $decimal, end.*" \
186 "run trace experiment"
189 gdb_test "tstop" "" ""
191 proc gdb_backtrace_tdp_1 { msg } {
194 # We are in a trace frame at which we didn't collect anything
195 # except $PC. Therefore we expect to be able to identify stack
196 # frame #0, but that's about all. In particular we do not expect
197 # to be able to display the function's arguments or locals, and we
198 # do not expect to be able to identify the caller of this function.
200 send_gdb "backtrace\n"
202 -re "#0\[\t \]+gdb_recursion_test.*depth=.*$gdb_prompt $" {
205 -re ".*$gdb_prompt $" {
208 timeout { fail "$msg (timeout)" }
212 proc gdb_backtrace_tdp_2 { msg } {
215 # We are in a trace frame at which we collected only the registers
216 # Therefore we expect to be able to identify stack frame #0, but
217 # we don't expect to be able to display its args unles they are
218 # passed in registers (which isn't the case for m68k), and we
219 # don't expect to be able to identify the caller's stack frame.
221 send_gdb "backtrace\n"
223 -re "#0\[\t \]+gdb_recursion_test.*depth=.*$gdb_prompt $" {
226 -re ".*$gdb_prompt $" {
229 timeout { fail "$msg (timeout)" }
233 proc gdb_backtrace_tdp_3 { msg } {
236 # We are in a trace frame at which we collected all registers, all
237 # arguments and all locals. This means that the display of
238 # stack frame #0 should be complete (including argument values).
240 send_gdb "backtrace\n"
242 -re "#0\[\t \]+gdb_recursion_test.*depth=\[0-9\]+.*q1=\[0-9\]+.*q2=\[0-9\]+.*q3=\[0-9\]+.*q4=\[0-9\]+.*q5=\[0-9\]+.*q6=\[0-9\]+.*$gdb_prompt $" {
245 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
246 fail "$msg (failed to collect arguments)"
248 -re ".*$gdb_prompt $" {
251 timeout { fail "$msg (timeout)" }
255 proc gdb_backtrace_tdp_4 { msg depth } {
258 # We are in a trace frame at which we collected all registers,
259 # plus a sizeable hunk of stack memory. This should enable us to
260 # display at least several stack frames worth of backtrace. We'll
261 # assume that if we can't display at least "depth" levels (with
262 # args), it counts as an error.
264 send_gdb "backtrace\n"
266 -re "#$depth\[\t \].*gdb_recursion_test.*depth=\[0-9\]+.*q1=\[0-9\]+.*q2=\[0-9\]+.*q3=\[0-9\]+.*q4=\[0-9\]+.*q5=\[0-9\]+.*q6=\[0-9\]+.*$gdb_prompt $" {
269 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
270 fail "$msg (args missing from #$depth stack frame)"
272 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
273 fail "$msg (fewer than $depth stack frames found)"
275 -re ".*$gdb_prompt $" {
278 timeout { fail "$msg (timeout)" }
283 # begin backtrace test
288 gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
290 gdb_tfind_test "8.6: find start frame" "start" "0"
291 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
293 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
295 gdb_tfind_test "8.6: find frame 1" "1" "1"
296 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
298 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
300 gdb_tfind_test "8.6: find frame 2" "2" "2"
301 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
303 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
306 gdb_tfind_test "8.6: find frame 4" "4" "4"
307 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
309 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
311 gdb_tfind_test "8.6: find frame 5" "5" "5"
312 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
314 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
316 gdb_tfind_test "8.6: find frame 6" "6" "6"
317 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
319 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
321 gdb_tfind_test "8.6: find frame 7" "7" "7"
322 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
324 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
327 gdb_tfind_test "8.6: find frame 9" "9" "9"
328 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
330 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
332 gdb_tfind_test "8.6: find frame 10" "10" "10"
333 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
335 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
337 gdb_tfind_test "8.6: find frame 11" "11" "11"
338 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
340 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
342 gdb_tfind_test "8.6: find frame 12" "12" "12"
343 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
345 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
348 gdb_tfind_test "8.6: find frame 14" "14" "14"
349 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
351 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
353 gdb_tfind_test "8.6: find frame 15" "15" "15"
354 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
356 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
358 gdb_tfind_test "8.6: find frame 16" "16" "16"
359 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
361 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
363 gdb_tfind_test "8.6: find frame 17" "17" "17"
364 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
366 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
369 gdb_tfind_test "8.6: find frame 19" "19" "19"
370 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
372 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
374 gdb_test "printf \"x \%d x\\n\", depth == 3" \
376 "1.13: trace in recursion: depth not equal to 3"
379 gdb_test "tfind none" "" ""