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