1 # Copyright 1998, 2007-2012 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";
24 set testfile "actions"
25 set srcfile ${testfile}.c
26 set binfile $objdir/$subdir/backtrace
27 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
28 executable {debug nowarnings}] != "" } {
29 untested backtrace.exp
33 gdb_test "tstop" ".*" ""
34 gdb_test "tfind none" ".*" ""
36 gdb_reinitialize_dir $srcdir/$subdir
38 if { ![gdb_target_supports_trace] } then {
39 unsupported "Current target does not support trace"
45 # test backtraces in trace frames
62 set baseline [gdb_find_recursion_test_baseline $srcfile];
63 if { $baseline == -1 } {
64 fail "Could not find gdb_recursion_test function"
70 gdb_test_multiple "list $baseline, +12" "all tests in this module will fail" {
71 -re "\[\r\n\](\[0-9\]+).*gdbtestline 1 " {
72 set testline1 $expect_out(1,string)
75 -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
76 set testline2 $expect_out(1,string)
79 -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
80 set testline3 $expect_out(1,string)
83 -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
84 set testline4 $expect_out(1,string)
87 -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
88 set testline5 $expect_out(1,string)
91 -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
92 set testline6 $expect_out(1,string)
95 -re ".*$gdb_prompt $" {
96 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
97 untested backtrace.exp
99 all tests in this module will fail."
103 untested backtrace.exp
105 all tests in this module will fail."
109 if { $return_me == 1 } then {
114 # Setup backtrace experiment. This will involve:
115 # 1) a tracepoint where nothing is collected
116 # 2) a tracepoint where only regs are collected
117 # 3) a tracepoint where regs, locals and args are collected
118 # 4) a tracepoint where regs plus some amount of stack are collected.
121 gdb_delete_tracepoints
122 set tdp2 [gdb_gettpnum $testline2]
123 set tdp3 [gdb_gettpnum $testline3]
124 set tdp4 [gdb_gettpnum $testline4]
125 set tdp5 [gdb_gettpnum $testline5]
126 set tdp6 [gdb_gettpnum $testline6]
127 if { $tdp2 <= 0 || $tdp3 <= 0 || \
128 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
129 fail "setting tracepoints failed"
133 #gdb_trace_setactions "setup TP to collect FP" \
138 gdb_trace_setactions "8.6: setup TP to collect regs" \
140 "collect \$regs" "^$"
142 gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
144 "collect \$regs, \$args, \$locs" "^$"
146 if [is_amd64_regs_target] {
149 } elseif [is_x86_like_target] {
157 gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
159 "collect $fpreg, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
161 gdb_test "tstart" ".*" ""
163 gdb_test "break end" ".*" ""
164 gdb_test "continue" \
165 "Continuing.*Breakpoint $decimal, end.*" \
166 "run trace experiment"
168 gdb_test "tstop" ".*" ""
170 proc gdb_backtrace_tdp_1 { msg } {
173 # We are in a trace frame at which we didn't collect anything
174 # except $PC. Therefore we expect to be able to identify stack
175 # frame #0, but that's about all. In particular we do not expect
176 # to be able to display the function's arguments or locals, and we
177 # do not expect to be able to identify the caller of this function.
179 gdb_test "backtrace" \
180 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
184 proc gdb_backtrace_tdp_2 { msg } {
187 # We are in a trace frame at which we collected only the registers
188 # Therefore we expect to be able to identify stack frame #0, but
189 # we don't expect to be able to display its args unles they are
190 # passed in registers (which isn't the case for m68k), and we
191 # don't expect to be able to identify the caller's stack frame.
193 gdb_test "backtrace" \
194 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
198 proc gdb_backtrace_tdp_3 { msg } {
201 # We are in a trace frame at which we collected all registers, all
202 # arguments and all locals. This means that the display of
203 # stack frame #0 should be complete (including argument values).
205 gdb_test_multiple "backtrace" "$msg" {
206 -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 $" {
209 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
210 fail "$msg (failed to collect arguments)"
215 proc gdb_backtrace_tdp_4 { msg depth } {
218 # We are in a trace frame at which we collected all registers,
219 # plus a sizeable hunk of stack memory. This should enable us to
220 # display at least several stack frames worth of backtrace. We'll
221 # assume that if we can't display at least "depth" levels (with
222 # args), it counts as an error.
224 gdb_test_multiple "backtrace" "$msg" {
225 -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 $" {
228 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
229 fail "$msg (args missing from #$depth stack frame)"
231 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
232 fail "$msg (fewer than $depth stack frames found)"
238 # begin backtrace test
243 gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
245 gdb_tfind_test "8.6: find start frame" "start" "0"
246 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
248 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
250 gdb_tfind_test "8.6: find frame 1" "1" "1"
251 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
253 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
255 gdb_tfind_test "8.6: find frame 2" "2" "2"
256 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
258 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
261 gdb_tfind_test "8.6: find frame 4" "4" "4"
262 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
264 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
266 gdb_tfind_test "8.6: find frame 5" "5" "5"
267 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
269 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
271 gdb_tfind_test "8.6: find frame 6" "6" "6"
272 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
274 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
276 gdb_tfind_test "8.6: find frame 7" "7" "7"
277 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
279 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
282 gdb_tfind_test "8.6: find frame 9" "9" "9"
283 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
285 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
287 gdb_tfind_test "8.6: find frame 10" "10" "10"
288 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
290 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
292 gdb_tfind_test "8.6: find frame 11" "11" "11"
293 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
295 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
297 gdb_tfind_test "8.6: find frame 12" "12" "12"
298 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
300 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
303 gdb_tfind_test "8.6: find frame 14" "14" "14"
304 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
306 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
308 gdb_tfind_test "8.6: find frame 15" "15" "15"
309 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
311 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
313 gdb_tfind_test "8.6: find frame 16" "16" "16"
314 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
316 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
318 gdb_tfind_test "8.6: find frame 17" "17" "17"
319 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
321 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
324 gdb_tfind_test "8.6: find frame 19" "19" "19"
325 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
327 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
329 gdb_test "printf \"x \%d x\\n\", depth == 3" \
331 "1.13: trace in recursion: depth not equal to 3"
334 gdb_test "tfind none" ".*" ""