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