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