1 # Copyright 1998, 2007, 2008, 2009, 2010 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 # This file was written by Michael Snyder (msnyder@cygnus.com)
18 load_lib "trace-support.exp";
30 set testfile "actions"
31 set srcfile ${testfile}.c
32 set binfile $objdir/$subdir/backtrace
33 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
34 executable {debug nowarnings}] != "" } {
35 untested backtrace.exp
39 gdb_test "tstop" "" ""
40 gdb_test "tfind none" "" ""
42 gdb_reinitialize_dir $srcdir/$subdir
44 # We generously give ourselves one "pass" if we successfully
45 # detect that this test cannot be run on this target!
46 if { ![gdb_target_supports_trace] } then {
47 pass "Current target does not support trace"
53 # test backtraces in trace frames
70 set baseline [gdb_find_recursion_test_baseline $srcfile];
71 if { $baseline == -1 } {
72 fail "Could not find gdb_recursion_test function"
76 send_gdb "list $baseline, +12\n"
78 -re "\[\r\n\](\[0-9\]+).*gdbtestline 1 " {
79 set testline1 $expect_out(1,string)
82 -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
83 set testline2 $expect_out(1,string)
86 -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
87 set testline3 $expect_out(1,string)
90 -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
91 set testline4 $expect_out(1,string)
94 -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
95 set testline5 $expect_out(1,string)
98 -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
99 set testline6 $expect_out(1,string)
102 -re ".*$gdb_prompt $" {
103 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
104 untested backtrace.exp
106 all tests in this module will fail."
110 untested backtrace.exp
112 all tests in this module will fail."
117 # Setup backtrace experiment. This will involve:
118 # 1) a tracepoint where nothing is collected
119 # 2) a tracepoint where only regs are collected
120 # 3) a tracepoint where regs, locals and args are collected
121 # 4) a tracepoint where regs plus some amount of stack are collected.
124 gdb_delete_tracepoints
125 set tdp2 [gdb_gettpnum $testline2]
126 set tdp3 [gdb_gettpnum $testline3]
127 set tdp4 [gdb_gettpnum $testline4]
128 set tdp5 [gdb_gettpnum $testline5]
129 set tdp6 [gdb_gettpnum $testline6]
130 if { $tdp2 <= 0 || $tdp3 <= 0 || \
131 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
132 fail "setting tracepoints failed"
136 #gdb_trace_setactions "setup TP to collect FP" \
141 gdb_trace_setactions "8.6: setup TP to collect regs" \
143 "collect \$regs" "^$"
145 gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
147 "collect \$regs, \$args, \$locs" "^$"
149 if [istarget "x86_64-*"] then {
152 } elseif [istarget "i?86-*"] then {
160 gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
162 "collect $fpreg, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
164 gdb_test "tstart" "" ""
166 gdb_test "break end" "" ""
167 gdb_test "continue" \
168 "Continuing.*Breakpoint $decimal, end.*" \
169 "run trace experiment"
171 gdb_test "tstop" "" ""
173 proc gdb_backtrace_tdp_1 { msg } {
176 # We are in a trace frame at which we didn't collect anything
177 # except $PC. Therefore we expect to be able to identify stack
178 # frame #0, but that's about all. In particular we do not expect
179 # to be able to display the function's arguments or locals, and we
180 # do not expect to be able to identify the caller of this function.
182 send_gdb "backtrace\n"
184 -re "#0\[\t \]+gdb_recursion_test.*depth=.*$gdb_prompt $" {
187 -re ".*$gdb_prompt $" {
190 timeout { fail "$msg (timeout)" }
194 proc gdb_backtrace_tdp_2 { msg } {
197 # We are in a trace frame at which we collected only the registers
198 # Therefore we expect to be able to identify stack frame #0, but
199 # we don't expect to be able to display its args unles they are
200 # passed in registers (which isn't the case for m68k), and we
201 # don't expect to be able to identify the caller's stack frame.
203 send_gdb "backtrace\n"
205 -re "#0\[\t \]+gdb_recursion_test.*depth=.*$gdb_prompt $" {
208 -re ".*$gdb_prompt $" {
211 timeout { fail "$msg (timeout)" }
215 proc gdb_backtrace_tdp_3 { msg } {
218 # We are in a trace frame at which we collected all registers, all
219 # arguments and all locals. This means that the display of
220 # stack frame #0 should be complete (including argument values).
222 send_gdb "backtrace\n"
224 -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 $" {
227 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
228 fail "$msg (failed to collect arguments)"
230 -re ".*$gdb_prompt $" {
233 timeout { fail "$msg (timeout)" }
237 proc gdb_backtrace_tdp_4 { msg depth } {
240 # We are in a trace frame at which we collected all registers,
241 # plus a sizeable hunk of stack memory. This should enable us to
242 # display at least several stack frames worth of backtrace. We'll
243 # assume that if we can't display at least "depth" levels (with
244 # args), it counts as an error.
246 send_gdb "backtrace\n"
248 -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 $" {
251 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
252 fail "$msg (args missing from #$depth stack frame)"
254 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
255 fail "$msg (fewer than $depth stack frames found)"
257 -re ".*$gdb_prompt $" {
260 timeout { fail "$msg (timeout)" }
265 # begin backtrace test
270 gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
272 gdb_tfind_test "8.6: find start frame" "start" "0"
273 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
275 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
277 gdb_tfind_test "8.6: find frame 1" "1" "1"
278 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
280 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
282 gdb_tfind_test "8.6: find frame 2" "2" "2"
283 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
285 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
288 gdb_tfind_test "8.6: find frame 4" "4" "4"
289 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
291 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
293 gdb_tfind_test "8.6: find frame 5" "5" "5"
294 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
296 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
298 gdb_tfind_test "8.6: find frame 6" "6" "6"
299 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
301 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
303 gdb_tfind_test "8.6: find frame 7" "7" "7"
304 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
306 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
309 gdb_tfind_test "8.6: find frame 9" "9" "9"
310 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
312 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
314 gdb_tfind_test "8.6: find frame 10" "10" "10"
315 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
317 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
319 gdb_tfind_test "8.6: find frame 11" "11" "11"
320 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
322 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
324 gdb_tfind_test "8.6: find frame 12" "12" "12"
325 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
327 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
330 gdb_tfind_test "8.6: find frame 14" "14" "14"
331 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
333 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
335 gdb_tfind_test "8.6: find frame 15" "15" "15"
336 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
338 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
340 gdb_tfind_test "8.6: find frame 16" "16" "16"
341 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
343 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
345 gdb_tfind_test "8.6: find frame 17" "17" "17"
346 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
348 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
351 gdb_tfind_test "8.6: find frame 19" "19" "19"
352 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
354 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
356 gdb_test "printf \"x \%d x\\n\", depth == 3" \
358 "1.13: trace in recursion: depth not equal to 3"
361 gdb_test "tfind none" "" ""