1 # Copyright 1998, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Michael Snyder (msnyder@cygnus.com)
19 load_lib "trace-support.exp";
29 set testfile "actions"
30 set srcfile ${testfile}.c
31 set binfile $objdir/$subdir/backtrace
32 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
33 executable {debug nowarnings}] != "" } {
34 untested backtrace.exp
38 gdb_test "tstop" ".*" ""
39 gdb_test "tfind none" ".*" ""
41 gdb_reinitialize_dir $srcdir/$subdir
43 # We generously give ourselves one "pass" if we successfully
44 # detect that this test cannot be run on this target!
45 if { ![gdb_target_supports_trace] } then {
46 pass "Current target does not support trace"
52 # test backtraces in trace frames
69 set baseline [gdb_find_recursion_test_baseline $srcfile];
70 if { $baseline == -1 } {
71 fail "Could not find gdb_recursion_test function"
77 gdb_test_multiple "list $baseline, +12" "all tests in this module will fail" {
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."
116 if { $return_me == 1 } then {
121 # Setup backtrace experiment. This will involve:
122 # 1) a tracepoint where nothing is collected
123 # 2) a tracepoint where only regs are collected
124 # 3) a tracepoint where regs, locals and args are collected
125 # 4) a tracepoint where regs plus some amount of stack are collected.
128 gdb_delete_tracepoints
129 set tdp2 [gdb_gettpnum $testline2]
130 set tdp3 [gdb_gettpnum $testline3]
131 set tdp4 [gdb_gettpnum $testline4]
132 set tdp5 [gdb_gettpnum $testline5]
133 set tdp6 [gdb_gettpnum $testline6]
134 if { $tdp2 <= 0 || $tdp3 <= 0 || \
135 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
136 fail "setting tracepoints failed"
140 #gdb_trace_setactions "setup TP to collect FP" \
145 gdb_trace_setactions "8.6: setup TP to collect regs" \
147 "collect \$regs" "^$"
149 gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
151 "collect \$regs, \$args, \$locs" "^$"
153 if [istarget "x86_64-*"] then {
156 } elseif [istarget "i?86-*"] then {
164 gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
166 "collect $fpreg, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
168 gdb_test "tstart" ".*" ""
170 gdb_test "break end" ".*" ""
171 gdb_test "continue" \
172 "Continuing.*Breakpoint $decimal, end.*" \
173 "run trace experiment"
175 gdb_test "tstop" ".*" ""
177 proc gdb_backtrace_tdp_1 { msg } {
180 # We are in a trace frame at which we didn't collect anything
181 # except $PC. Therefore we expect to be able to identify stack
182 # frame #0, but that's about all. In particular we do not expect
183 # to be able to display the function's arguments or locals, and we
184 # do not expect to be able to identify the caller of this function.
186 gdb_test "backtrace" \
187 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
191 proc gdb_backtrace_tdp_2 { msg } {
194 # We are in a trace frame at which we collected only the registers
195 # Therefore we expect to be able to identify stack frame #0, but
196 # we don't expect to be able to display its args unles they are
197 # passed in registers (which isn't the case for m68k), and we
198 # don't expect to be able to identify the caller's stack frame.
200 gdb_test "backtrace" \
201 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
205 proc gdb_backtrace_tdp_3 { msg } {
208 # We are in a trace frame at which we collected all registers, all
209 # arguments and all locals. This means that the display of
210 # stack frame #0 should be complete (including argument values).
212 gdb_test_multiple "backtrace" "$msg" {
213 -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 $" {
216 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
217 fail "$msg (failed to collect arguments)"
222 proc gdb_backtrace_tdp_4 { msg depth } {
225 # We are in a trace frame at which we collected all registers,
226 # plus a sizeable hunk of stack memory. This should enable us to
227 # display at least several stack frames worth of backtrace. We'll
228 # assume that if we can't display at least "depth" levels (with
229 # args), it counts as an error.
231 gdb_test_multiple "backtrace" "$msg" {
232 -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 $" {
235 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
236 fail "$msg (args missing from #$depth stack frame)"
238 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
239 fail "$msg (fewer than $depth stack frames found)"
245 # begin backtrace test
250 gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
252 gdb_tfind_test "8.6: find start frame" "start" "0"
253 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
255 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
257 gdb_tfind_test "8.6: find frame 1" "1" "1"
258 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
260 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
262 gdb_tfind_test "8.6: find frame 2" "2" "2"
263 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
265 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
268 gdb_tfind_test "8.6: find frame 4" "4" "4"
269 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
271 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
273 gdb_tfind_test "8.6: find frame 5" "5" "5"
274 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
276 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
278 gdb_tfind_test "8.6: find frame 6" "6" "6"
279 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
281 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
283 gdb_tfind_test "8.6: find frame 7" "7" "7"
284 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
286 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
289 gdb_tfind_test "8.6: find frame 9" "9" "9"
290 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
292 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
294 gdb_tfind_test "8.6: find frame 10" "10" "10"
295 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
297 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
299 gdb_tfind_test "8.6: find frame 11" "11" "11"
300 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
302 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
304 gdb_tfind_test "8.6: find frame 12" "12" "12"
305 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
307 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
310 gdb_tfind_test "8.6: find frame 14" "14" "14"
311 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
313 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
315 gdb_tfind_test "8.6: find frame 15" "15" "15"
316 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
318 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
320 gdb_tfind_test "8.6: find frame 16" "16" "16"
321 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
323 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
325 gdb_tfind_test "8.6: find frame 17" "17" "17"
326 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
328 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
331 gdb_tfind_test "8.6: find frame 19" "19" "19"
332 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
334 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
336 gdb_test "printf \"x \%d x\\n\", depth == 3" \
338 "1.13: trace in recursion: depth not equal to 3"
341 gdb_test "tfind none" ".*" ""