* gdb.trace/backtrace.exp: Adjust for x86 and x86_64.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / backtrace.exp
CommitLineData
4c38e0a4 1# Copyright 1998, 2007, 2008, 2009, 2010 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
20if $tracelevel then {
21 strace $tracelevel
22}
23
24set prms_id 0
25set bug_id 0
26
27gdb_exit
28gdb_start
29
f8b7eaf3
DJ
30set testfile "actions"
31set srcfile ${testfile}.c
32set binfile $objdir/$subdir/backtrace
33if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
34 executable {debug nowarnings}] != "" } {
35 untested backtrace.exp
36 return -1
c906108c 37}
f8b7eaf3
DJ
38gdb_load $binfile
39gdb_test "tstop" "" ""
40gdb_test "tfind none" "" ""
41runto_main
c906108c
SS
42gdb_reinitialize_dir $srcdir/$subdir
43
44# We generously give ourselves one "pass" if we successfully
45# detect that this test cannot be run on this target!
46if { ![gdb_target_supports_trace] } then {
0ef2251b 47 pass "Current target does not support trace"
c906108c
SS
48 return 1;
49
50}
51
52#
53# test backtraces in trace frames
54#
55
56set testline1 0
57set testline2 0
58set testline3 0
59set testline4 0
60set testline5 0
61set testline6 0
62
63set arg1 1
64set arg2 2
65set arg3 3
66set arg4 4
67set arg5 5
68set arg6 6
69
70set baseline [gdb_find_recursion_test_baseline $srcfile];
71if { $baseline == -1 } {
72 fail "Could not find gdb_recursion_test function"
73 return;
74}
75
76send_gdb "list $baseline, +12\n"
77gdb_expect {
78 -re "\[\r\n\](\[0-9\]+).*gdbtestline 1 " {
79 set testline1 $expect_out(1,string)
80 exp_continue
81 }
82 -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
83 set testline2 $expect_out(1,string)
84 exp_continue
85 }
86 -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
87 set testline3 $expect_out(1,string)
88 exp_continue
89 }
90 -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
91 set testline4 $expect_out(1,string)
92 exp_continue
93 }
94 -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
95 set testline5 $expect_out(1,string)
96 exp_continue
97 }
98 -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
99 set testline6 $expect_out(1,string)
100 exp_continue
101 }
102 -re ".*$gdb_prompt $" {
103 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
b60f0898
JB
104 untested backtrace.exp
105 return -1
c906108c
SS
106all tests in this module will fail."
107 }
108 }
109 default {
b60f0898
JB
110 untested backtrace.exp
111 return -1
c906108c
SS
112all tests in this module will fail."
113 }
114}
115
116#
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.
122#
123
124gdb_delete_tracepoints
125set tdp2 [gdb_gettpnum $testline2]
126set tdp3 [gdb_gettpnum $testline3]
127set tdp4 [gdb_gettpnum $testline4]
128set tdp5 [gdb_gettpnum $testline5]
129set tdp6 [gdb_gettpnum $testline6]
130if { $tdp2 <= 0 || $tdp3 <= 0 || \
131 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
132 fail "setting tracepoints failed"
133 return;
134}
135
136#gdb_trace_setactions "setup TP to collect FP" \
137# "$tdp2" \
138# "collect \$fp" ""
139#
140
141gdb_trace_setactions "8.6: setup TP to collect regs" \
142 "$tdp3" \
143 "collect \$regs" "^$"
144
145gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
146 "$tdp4" \
147 "collect \$regs, \$args, \$locs" "^$"
148
6a8f2671
PA
149if [istarget "x86_64-*"] then {
150 set fpreg "\$rbp"
151 set spreg "\$rsp"
152} elseif [istarget "i?86-*"] then {
153 set fpreg "\$ebp"
154 set spreg "\$esp"
155} else {
156 set fpreg "\$fp"
157 set spreg "\$sp"
158}
159
c906108c 160gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
6a8f2671
PA
161 "$tdp6" \
162 "collect $fpreg, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
c906108c
SS
163
164gdb_test "tstart" "" ""
165
f8b7eaf3
DJ
166gdb_test "break end" "" ""
167gdb_test "continue" \
168 "Continuing.*Breakpoint $decimal, end.*" \
169 "run trace experiment"
c906108c
SS
170
171gdb_test "tstop" "" ""
172
173proc gdb_backtrace_tdp_1 { msg } {
174 global gdb_prompt
175
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.
181
182 send_gdb "backtrace\n"
183 gdb_expect {
184 -re "#0\[\t \]+gdb_recursion_test.*depth=.*$gdb_prompt $" {
185 pass "$msg"
186 }
187 -re ".*$gdb_prompt $" {
188 fail "$msg"
189 }
190 timeout { fail "$msg (timeout)" }
191 }
192}
193
194proc gdb_backtrace_tdp_2 { msg } {
195 global gdb_prompt
196
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.
202
203 send_gdb "backtrace\n"
204 gdb_expect {
205 -re "#0\[\t \]+gdb_recursion_test.*depth=.*$gdb_prompt $" {
206 pass "$msg"
207 }
208 -re ".*$gdb_prompt $" {
209 fail "$msg"
210 }
211 timeout { fail "$msg (timeout)" }
212 }
213}
214
215proc gdb_backtrace_tdp_3 { msg } {
216 global gdb_prompt
217
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).
221
222 send_gdb "backtrace\n"
223 gdb_expect {
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 $" {
225 pass "$msg"
226 }
227 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
228 fail "$msg (failed to collect arguments)"
229 }
230 -re ".*$gdb_prompt $" {
231 fail "$msg"
232 }
233 timeout { fail "$msg (timeout)" }
234 }
235}
236
237proc gdb_backtrace_tdp_4 { msg depth } {
238 global gdb_prompt
239
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.
245
246 send_gdb "backtrace\n"
247 gdb_expect {
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 $" {
249 pass "$msg"
250 }
251 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
252 fail "$msg (args missing from #$depth stack frame)"
253 }
254 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
255 fail "$msg (fewer than $depth stack frames found)"
256 }
257 -re ".*$gdb_prompt $" {
258 fail "$msg"
259 }
260 timeout { fail "$msg (timeout)" }
261 }
262}
263
264#
265# begin backtrace test
266#
267
268set timeout 60
269
270gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
271
272gdb_tfind_test "8.6: find start frame" "start" "0"
273gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
274 "TDP $tdp2:" ""
275gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
276
277gdb_tfind_test "8.6: find frame 1" "1" "1"
278gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
279 "TDP $tdp3:" ""
280gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
281
282gdb_tfind_test "8.6: find frame 2" "2" "2"
283gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
284 "TDP $tdp4:" ""
285gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
286
287
288gdb_tfind_test "8.6: find frame 4" "4" "4"
289gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
290 "TDP $tdp6:" ""
291gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
292
293gdb_tfind_test "8.6: find frame 5" "5" "5"
294gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
295 "TDP $tdp2:" ""
296gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
297
298gdb_tfind_test "8.6: find frame 6" "6" "6"
299gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
300 "TDP $tdp3:" ""
301gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
302
303gdb_tfind_test "8.6: find frame 7" "7" "7"
304gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
305 "TDP $tdp4:" ""
306gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
307
308
309gdb_tfind_test "8.6: find frame 9" "9" "9"
310gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
311 "TDP $tdp6:" ""
312gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
313
314gdb_tfind_test "8.6: find frame 10" "10" "10"
315gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
316 "TDP $tdp2:" ""
317gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
318
319gdb_tfind_test "8.6: find frame 11" "11" "11"
320gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
321 "TDP $tdp3:" ""
322gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
323
324gdb_tfind_test "8.6: find frame 12" "12" "12"
325gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
326 "TDP $tdp4:" ""
327gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
328
329
330gdb_tfind_test "8.6: find frame 14" "14" "14"
331gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
332 "TDP $tdp6:" ""
333gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
334
335gdb_tfind_test "8.6: find frame 15" "15" "15"
336gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
337 "TDP $tdp2:" ""
338gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
339
340gdb_tfind_test "8.6: find frame 16" "16" "16"
341gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
342 "TDP $tdp3:" ""
343gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
344
345gdb_tfind_test "8.6: find frame 17" "17" "17"
346gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
347 "TDP $tdp4:" ""
348gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
349
350
351gdb_tfind_test "8.6: find frame 19" "19" "19"
352gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
353 "TDP $tdp6:" ""
354gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
355
356gdb_test "printf \"x \%d x\\n\", depth == 3" \
357 "x 0 x" \
358 "1.13: trace in recursion: depth not equal to 3"
359
360# Finished!
361gdb_test "tfind none" "" ""
This page took 1.467883 seconds and 4 git commands to generate.