2012-02-15 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / backtrace.exp
1 # Copyright 1998, 2007-2012 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
21 gdb_exit
22 gdb_start
23
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
30 return -1
31 }
32 gdb_load $binfile
33 gdb_test "tstop" ".*" ""
34 gdb_test "tfind none" ".*" ""
35 runto_main
36 gdb_reinitialize_dir $srcdir/$subdir
37
38 if { ![gdb_target_supports_trace] } then {
39 unsupported "Current target does not support trace"
40 return 1;
41
42 }
43
44 #
45 # test backtraces in trace frames
46 #
47
48 set testline1 0
49 set testline2 0
50 set testline3 0
51 set testline4 0
52 set testline5 0
53 set testline6 0
54
55 set arg1 1
56 set arg2 2
57 set arg3 3
58 set arg4 4
59 set arg5 5
60 set arg6 6
61
62 set baseline [gdb_find_recursion_test_baseline $srcfile];
63 if { $baseline == -1 } {
64 fail "Could not find gdb_recursion_test function"
65 return;
66 }
67
68 set return_me 0
69
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)
73 exp_continue
74 }
75 -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
76 set testline2 $expect_out(1,string)
77 exp_continue
78 }
79 -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
80 set testline3 $expect_out(1,string)
81 exp_continue
82 }
83 -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
84 set testline4 $expect_out(1,string)
85 exp_continue
86 }
87 -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
88 set testline5 $expect_out(1,string)
89 exp_continue
90 }
91 -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
92 set testline6 $expect_out(1,string)
93 exp_continue
94 }
95 -re ".*$gdb_prompt $" {
96 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
97 untested backtrace.exp
98 set return_me 1
99 all tests in this module will fail."
100 }
101 }
102 default {
103 untested backtrace.exp
104 set return_me 1
105 all tests in this module will fail."
106 }
107 }
108
109 if { $return_me == 1 } then {
110 return -1;
111 }
112
113 #
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.
119 #
120
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"
130 return;
131 }
132
133 #gdb_trace_setactions "setup TP to collect FP" \
134 # "$tdp2" \
135 # "collect \$fp" ""
136 #
137
138 gdb_trace_setactions "8.6: setup TP to collect regs" \
139 "$tdp3" \
140 "collect \$regs" "^$"
141
142 gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
143 "$tdp4" \
144 "collect \$regs, \$args, \$locs" "^$"
145
146 if [is_amd64_regs_target] {
147 set fpreg "\$rbp"
148 set spreg "\$rsp"
149 } elseif [is_x86_like_target] {
150 set fpreg "\$ebp"
151 set spreg "\$esp"
152 } else {
153 set fpreg "\$fp"
154 set spreg "\$sp"
155 }
156
157 gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
158 "$tdp6" \
159 "collect $fpreg, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
160
161 gdb_test "tstart" ".*" ""
162
163 gdb_test "break end" ".*" ""
164 gdb_test "continue" \
165 "Continuing.*Breakpoint $decimal, end.*" \
166 "run trace experiment"
167
168 gdb_test "tstop" ".*" ""
169
170 proc gdb_backtrace_tdp_1 { msg } {
171 global gdb_prompt
172
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.
178
179 gdb_test "backtrace" \
180 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
181 "$msg"
182 }
183
184 proc gdb_backtrace_tdp_2 { msg } {
185 global gdb_prompt
186
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.
192
193 gdb_test "backtrace" \
194 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
195 "$msg"
196 }
197
198 proc gdb_backtrace_tdp_3 { msg } {
199 global gdb_prompt
200
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).
204
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 $" {
207 pass "$msg"
208 }
209 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
210 fail "$msg (failed to collect arguments)"
211 }
212 }
213 }
214
215 proc gdb_backtrace_tdp_4 { msg depth } {
216 global gdb_prompt
217
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.
223
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 $" {
226 pass "$msg"
227 }
228 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
229 fail "$msg (args missing from #$depth stack frame)"
230 }
231 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
232 fail "$msg (fewer than $depth stack frames found)"
233 }
234 }
235 }
236
237 #
238 # begin backtrace test
239 #
240
241 set timeout 60
242
243 gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
244
245 gdb_tfind_test "8.6: find start frame" "start" "0"
246 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
247 "TDP $tdp2:" ""
248 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
249
250 gdb_tfind_test "8.6: find frame 1" "1" "1"
251 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
252 "TDP $tdp3:" ""
253 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
254
255 gdb_tfind_test "8.6: find frame 2" "2" "2"
256 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
257 "TDP $tdp4:" ""
258 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
259
260
261 gdb_tfind_test "8.6: find frame 4" "4" "4"
262 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
263 "TDP $tdp6:" ""
264 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
265
266 gdb_tfind_test "8.6: find frame 5" "5" "5"
267 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
268 "TDP $tdp2:" ""
269 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
270
271 gdb_tfind_test "8.6: find frame 6" "6" "6"
272 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
273 "TDP $tdp3:" ""
274 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
275
276 gdb_tfind_test "8.6: find frame 7" "7" "7"
277 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
278 "TDP $tdp4:" ""
279 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
280
281
282 gdb_tfind_test "8.6: find frame 9" "9" "9"
283 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
284 "TDP $tdp6:" ""
285 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
286
287 gdb_tfind_test "8.6: find frame 10" "10" "10"
288 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
289 "TDP $tdp2:" ""
290 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
291
292 gdb_tfind_test "8.6: find frame 11" "11" "11"
293 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
294 "TDP $tdp3:" ""
295 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
296
297 gdb_tfind_test "8.6: find frame 12" "12" "12"
298 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
299 "TDP $tdp4:" ""
300 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
301
302
303 gdb_tfind_test "8.6: find frame 14" "14" "14"
304 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
305 "TDP $tdp6:" ""
306 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
307
308 gdb_tfind_test "8.6: find frame 15" "15" "15"
309 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
310 "TDP $tdp2:" ""
311 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
312
313 gdb_tfind_test "8.6: find frame 16" "16" "16"
314 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
315 "TDP $tdp3:" ""
316 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
317
318 gdb_tfind_test "8.6: find frame 17" "17" "17"
319 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
320 "TDP $tdp4:" ""
321 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
322
323
324 gdb_tfind_test "8.6: find frame 19" "19" "19"
325 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
326 "TDP $tdp6:" ""
327 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
328
329 gdb_test "printf \"x \%d x\\n\", depth == 3" \
330 "x 0 x" \
331 "1.13: trace in recursion: depth not equal to 3"
332
333 # Finished!
334 gdb_test "tfind none" ".*" ""
This page took 0.037599 seconds and 5 git commands to generate.