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";
28 set testfile "actions"
29 set srcfile ${testfile}.c
30 set binfile $objdir/$subdir/backtrace
31 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
32 executable {debug nowarnings}] != "" } {
33 untested backtrace.exp
37 gdb_test "tstop" ".*" ""
38 gdb_test "tfind none" ".*" ""
40 gdb_reinitialize_dir $srcdir/$subdir
42 # We generously give ourselves one "pass" if we successfully
43 # detect that this test cannot be run on this target!
44 if { ![gdb_target_supports_trace] } then {
45 pass "Current target does not support trace"
51 # test backtraces in trace frames
68 set baseline [gdb_find_recursion_test_baseline $srcfile];
69 if { $baseline == -1 } {
70 fail "Could not find gdb_recursion_test function"
76 gdb_test_multiple "list $baseline, +12" "all tests in this module will fail" {
77 -re "\[\r\n\](\[0-9\]+).*gdbtestline 1 " {
78 set testline1 $expect_out(1,string)
81 -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
82 set testline2 $expect_out(1,string)
85 -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
86 set testline3 $expect_out(1,string)
89 -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
90 set testline4 $expect_out(1,string)
93 -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
94 set testline5 $expect_out(1,string)
97 -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
98 set testline6 $expect_out(1,string)
101 -re ".*$gdb_prompt $" {
102 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
103 untested backtrace.exp
105 all tests in this module will fail."
109 untested backtrace.exp
111 all tests in this module will fail."
115 if { $return_me == 1 } then {
120 # Setup backtrace experiment. This will involve:
121 # 1) a tracepoint where nothing is collected
122 # 2) a tracepoint where only regs are collected
123 # 3) a tracepoint where regs, locals and args are collected
124 # 4) a tracepoint where regs plus some amount of stack are collected.
127 gdb_delete_tracepoints
128 set tdp2 [gdb_gettpnum $testline2]
129 set tdp3 [gdb_gettpnum $testline3]
130 set tdp4 [gdb_gettpnum $testline4]
131 set tdp5 [gdb_gettpnum $testline5]
132 set tdp6 [gdb_gettpnum $testline6]
133 if { $tdp2 <= 0 || $tdp3 <= 0 || \
134 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
135 fail "setting tracepoints failed"
139 #gdb_trace_setactions "setup TP to collect FP" \
144 gdb_trace_setactions "8.6: setup TP to collect regs" \
146 "collect \$regs" "^$"
148 gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
150 "collect \$regs, \$args, \$locs" "^$"
152 if [istarget "x86_64-*"] then {
155 } elseif [istarget "i?86-*"] then {
163 gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
165 "collect $fpreg, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
167 gdb_test "tstart" ".*" ""
169 gdb_test "break end" ".*" ""
170 gdb_test "continue" \
171 "Continuing.*Breakpoint $decimal, end.*" \
172 "run trace experiment"
174 gdb_test "tstop" ".*" ""
176 proc gdb_backtrace_tdp_1 { msg } {
179 # We are in a trace frame at which we didn't collect anything
180 # except $PC. Therefore we expect to be able to identify stack
181 # frame #0, but that's about all. In particular we do not expect
182 # to be able to display the function's arguments or locals, and we
183 # do not expect to be able to identify the caller of this function.
185 gdb_test "backtrace" \
186 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
190 proc gdb_backtrace_tdp_2 { msg } {
193 # We are in a trace frame at which we collected only the registers
194 # Therefore we expect to be able to identify stack frame #0, but
195 # we don't expect to be able to display its args unles they are
196 # passed in registers (which isn't the case for m68k), and we
197 # don't expect to be able to identify the caller's stack frame.
199 gdb_test "backtrace" \
200 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
204 proc gdb_backtrace_tdp_3 { msg } {
207 # We are in a trace frame at which we collected all registers, all
208 # arguments and all locals. This means that the display of
209 # stack frame #0 should be complete (including argument values).
211 gdb_test_multiple "backtrace" "$msg" {
212 -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 $" {
215 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
216 fail "$msg (failed to collect arguments)"
221 proc gdb_backtrace_tdp_4 { msg depth } {
224 # We are in a trace frame at which we collected all registers,
225 # plus a sizeable hunk of stack memory. This should enable us to
226 # display at least several stack frames worth of backtrace. We'll
227 # assume that if we can't display at least "depth" levels (with
228 # args), it counts as an error.
230 gdb_test_multiple "backtrace" "$msg" {
231 -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 $" {
234 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
235 fail "$msg (args missing from #$depth stack frame)"
237 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
238 fail "$msg (fewer than $depth stack frames found)"
244 # begin backtrace test
249 gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
251 gdb_tfind_test "8.6: find start frame" "start" "0"
252 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
254 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
256 gdb_tfind_test "8.6: find frame 1" "1" "1"
257 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
259 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
261 gdb_tfind_test "8.6: find frame 2" "2" "2"
262 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
264 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
267 gdb_tfind_test "8.6: find frame 4" "4" "4"
268 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
270 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
272 gdb_tfind_test "8.6: find frame 5" "5" "5"
273 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
275 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
277 gdb_tfind_test "8.6: find frame 6" "6" "6"
278 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
280 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
282 gdb_tfind_test "8.6: find frame 7" "7" "7"
283 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
285 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
288 gdb_tfind_test "8.6: find frame 9" "9" "9"
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 10" "10" "10"
294 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
296 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
298 gdb_tfind_test "8.6: find frame 11" "11" "11"
299 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
301 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
303 gdb_tfind_test "8.6: find frame 12" "12" "12"
304 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
306 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
309 gdb_tfind_test "8.6: find frame 14" "14" "14"
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 15" "15" "15"
315 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
317 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
319 gdb_tfind_test "8.6: find frame 16" "16" "16"
320 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
322 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
324 gdb_tfind_test "8.6: find frame 17" "17" "17"
325 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
327 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
330 gdb_tfind_test "8.6: find frame 19" "19" "19"
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_test "printf \"x \%d x\\n\", depth == 3" \
337 "1.13: trace in recursion: depth not equal to 3"
340 gdb_test "tfind none" ".*" ""