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