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