]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.trace/backtrace.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / backtrace.exp
CommitLineData
8acc9f48 1# Copyright 1998-2013 Free Software Foundation, Inc.
c906108c
SS
2#
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Michael Snyder (msnyder@cygnus.com)
17
18load_lib "trace-support.exp";
19
c906108c
SS
20
21gdb_exit
22gdb_start
23
497a5eb0 24standard_testfile actions.c
f8b7eaf3
DJ
25if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
26 executable {debug nowarnings}] != "" } {
27 untested backtrace.exp
28 return -1
c906108c 29}
f8b7eaf3 30gdb_load $binfile
de7ff789
MS
31gdb_test "tstop" ".*" ""
32gdb_test "tfind none" ".*" ""
f8b7eaf3 33runto_main
c906108c
SS
34gdb_reinitialize_dir $srcdir/$subdir
35
c906108c 36if { ![gdb_target_supports_trace] } then {
10010058 37 unsupported "Current target does not support trace"
c906108c
SS
38 return 1;
39
40}
41
42#
43# test backtraces in trace frames
44#
45
46set testline1 0
47set testline2 0
48set testline3 0
49set testline4 0
50set testline5 0
51set testline6 0
52
53set arg1 1
54set arg2 2
55set arg3 3
56set arg4 4
57set arg5 5
58set arg6 6
59
60set baseline [gdb_find_recursion_test_baseline $srcfile];
61if { $baseline == -1 } {
62 fail "Could not find gdb_recursion_test function"
63 return;
64}
65
0ab48859
MS
66set return_me 0
67
68gdb_test_multiple "list $baseline, +12" "all tests in this module will fail" {
c906108c
SS
69 -re "\[\r\n\](\[0-9\]+).*gdbtestline 1 " {
70 set testline1 $expect_out(1,string)
71 exp_continue
72 }
73 -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
74 set testline2 $expect_out(1,string)
75 exp_continue
76 }
77 -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
78 set testline3 $expect_out(1,string)
79 exp_continue
80 }
81 -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
82 set testline4 $expect_out(1,string)
83 exp_continue
84 }
85 -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
86 set testline5 $expect_out(1,string)
87 exp_continue
88 }
89 -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
90 set testline6 $expect_out(1,string)
91 exp_continue
92 }
93 -re ".*$gdb_prompt $" {
94 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
b60f0898 95 untested backtrace.exp
0ab48859 96 set return_me 1
c906108c
SS
97all tests in this module will fail."
98 }
99 }
100 default {
b60f0898 101 untested backtrace.exp
0ab48859 102 set return_me 1
c906108c 103all tests in this module will fail."
0ab48859
MS
104 }
105}
106
107if { $return_me == 1 } then {
108 return -1;
c906108c
SS
109}
110
111#
112# Setup backtrace experiment. This will involve:
113# 1) a tracepoint where nothing is collected
114# 2) a tracepoint where only regs are collected
115# 3) a tracepoint where regs, locals and args are collected
116# 4) a tracepoint where regs plus some amount of stack are collected.
117#
118
119gdb_delete_tracepoints
120set tdp2 [gdb_gettpnum $testline2]
121set tdp3 [gdb_gettpnum $testline3]
122set tdp4 [gdb_gettpnum $testline4]
123set tdp5 [gdb_gettpnum $testline5]
124set tdp6 [gdb_gettpnum $testline6]
125if { $tdp2 <= 0 || $tdp3 <= 0 || \
126 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
127 fail "setting tracepoints failed"
128 return;
129}
130
131#gdb_trace_setactions "setup TP to collect FP" \
132# "$tdp2" \
133# "collect \$fp" ""
134#
135
136gdb_trace_setactions "8.6: setup TP to collect regs" \
137 "$tdp3" \
138 "collect \$regs" "^$"
139
140gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
141 "$tdp4" \
142 "collect \$regs, \$args, \$locs" "^$"
143
7f062217 144if [is_amd64_regs_target] {
6a8f2671
PA
145 set fpreg "\$rbp"
146 set spreg "\$rsp"
7f062217 147} elseif [is_x86_like_target] {
6a8f2671
PA
148 set fpreg "\$ebp"
149 set spreg "\$esp"
150} else {
151 set fpreg "\$fp"
152 set spreg "\$sp"
153}
154
c906108c 155gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
6a8f2671
PA
156 "$tdp6" \
157 "collect $fpreg, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
c906108c 158
de7ff789 159gdb_test "tstart" ".*" ""
c906108c 160
de7ff789 161gdb_test "break end" ".*" ""
f8b7eaf3
DJ
162gdb_test "continue" \
163 "Continuing.*Breakpoint $decimal, end.*" \
164 "run trace experiment"
c906108c 165
de7ff789 166gdb_test "tstop" ".*" ""
c906108c
SS
167
168proc gdb_backtrace_tdp_1 { msg } {
169 global gdb_prompt
170
171 # We are in a trace frame at which we didn't collect anything
172 # except $PC. Therefore we expect to be able to identify stack
173 # frame #0, but that's about all. In particular we do not expect
174 # to be able to display the function's arguments or locals, and we
175 # do not expect to be able to identify the caller of this function.
176
0ab48859
MS
177 gdb_test "backtrace" \
178 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
179 "$msg"
c906108c
SS
180}
181
182proc gdb_backtrace_tdp_2 { msg } {
183 global gdb_prompt
184
185 # We are in a trace frame at which we collected only the registers
186 # Therefore we expect to be able to identify stack frame #0, but
187 # we don't expect to be able to display its args unles they are
188 # passed in registers (which isn't the case for m68k), and we
189 # don't expect to be able to identify the caller's stack frame.
190
0ab48859
MS
191 gdb_test "backtrace" \
192 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
193 "$msg"
c906108c
SS
194}
195
196proc gdb_backtrace_tdp_3 { msg } {
197 global gdb_prompt
198
199 # We are in a trace frame at which we collected all registers, all
200 # arguments and all locals. This means that the display of
201 # stack frame #0 should be complete (including argument values).
202
0ab48859 203 gdb_test_multiple "backtrace" "$msg" {
c906108c
SS
204 -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 $" {
205 pass "$msg"
206 }
207 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
208 fail "$msg (failed to collect arguments)"
209 }
c906108c
SS
210 }
211}
212
213proc gdb_backtrace_tdp_4 { msg depth } {
214 global gdb_prompt
215
216 # We are in a trace frame at which we collected all registers,
217 # plus a sizeable hunk of stack memory. This should enable us to
218 # display at least several stack frames worth of backtrace. We'll
219 # assume that if we can't display at least "depth" levels (with
220 # args), it counts as an error.
221
0ab48859 222 gdb_test_multiple "backtrace" "$msg" {
c906108c
SS
223 -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 $" {
224 pass "$msg"
225 }
226 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
227 fail "$msg (args missing from #$depth stack frame)"
228 }
229 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
230 fail "$msg (fewer than $depth stack frames found)"
231 }
c906108c
SS
232 }
233}
234
235#
236# begin backtrace test
237#
238
239set timeout 60
240
241gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
242
243gdb_tfind_test "8.6: find start frame" "start" "0"
244gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
245 "TDP $tdp2:" ""
246gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
247
248gdb_tfind_test "8.6: find frame 1" "1" "1"
249gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
250 "TDP $tdp3:" ""
251gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
252
253gdb_tfind_test "8.6: find frame 2" "2" "2"
254gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
255 "TDP $tdp4:" ""
256gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
257
258
259gdb_tfind_test "8.6: find frame 4" "4" "4"
260gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
261 "TDP $tdp6:" ""
262gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
263
264gdb_tfind_test "8.6: find frame 5" "5" "5"
265gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
266 "TDP $tdp2:" ""
267gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
268
269gdb_tfind_test "8.6: find frame 6" "6" "6"
270gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
271 "TDP $tdp3:" ""
272gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
273
274gdb_tfind_test "8.6: find frame 7" "7" "7"
275gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
276 "TDP $tdp4:" ""
277gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
278
279
280gdb_tfind_test "8.6: find frame 9" "9" "9"
281gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
282 "TDP $tdp6:" ""
283gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
284
285gdb_tfind_test "8.6: find frame 10" "10" "10"
286gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
287 "TDP $tdp2:" ""
288gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
289
290gdb_tfind_test "8.6: find frame 11" "11" "11"
291gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
292 "TDP $tdp3:" ""
293gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
294
295gdb_tfind_test "8.6: find frame 12" "12" "12"
296gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
297 "TDP $tdp4:" ""
298gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
299
300
301gdb_tfind_test "8.6: find frame 14" "14" "14"
302gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
303 "TDP $tdp6:" ""
304gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
305
306gdb_tfind_test "8.6: find frame 15" "15" "15"
307gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
308 "TDP $tdp2:" ""
309gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
310
311gdb_tfind_test "8.6: find frame 16" "16" "16"
312gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
313 "TDP $tdp3:" ""
314gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
315
316gdb_tfind_test "8.6: find frame 17" "17" "17"
317gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
318 "TDP $tdp4:" ""
319gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
320
321
322gdb_tfind_test "8.6: find frame 19" "19" "19"
323gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
324 "TDP $tdp6:" ""
325gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
326
327gdb_test "printf \"x \%d x\\n\", depth == 3" \
328 "x 0 x" \
329 "1.13: trace in recursion: depth not equal to 3"
330
331# Finished!
de7ff789 332gdb_test "tfind none" ".*" ""