]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.trace/backtrace.exp
Update Copyright year range in all files maintained by GDB.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / backtrace.exp
CommitLineData
ecd75fc8 1# Copyright 1998-2014 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Michael Snyder (msnyder@cygnus.com)
17
4ec70201 18load_lib "trace-support.exp"
c906108c 19
48bbe0bf
YQ
20standard_testfile actions.c
21set executable $testfile
22set expfile $testfile.exp
c906108c 23
48bbe0bf
YQ
24if [prepare_for_testing $expfile $executable $srcfile \
25 [list debug nowarnings]] {
26 untested "failed to prepare for trace tests"
27 return -1
28}
c906108c 29
48bbe0bf
YQ
30if ![runto_main] {
31 fail "Can't run to main to check for trace support"
f8b7eaf3 32 return -1
c906108c 33}
c906108c 34
c906108c 35if { ![gdb_target_supports_trace] } then {
10010058 36 unsupported "Current target does not support trace"
ae59b1da 37 return 1
c906108c
SS
38
39}
40
41#
42# test backtraces in trace frames
43#
44
45set testline1 0
46set testline2 0
47set testline3 0
48set testline4 0
49set testline5 0
50set testline6 0
51
52set arg1 1
53set arg2 2
54set arg3 3
55set arg4 4
56set arg5 5
57set arg6 6
58
4ec70201 59set baseline [gdb_find_recursion_test_baseline $srcfile]
c906108c
SS
60if { $baseline == -1 } {
61 fail "Could not find gdb_recursion_test function"
4ec70201 62 return
c906108c
SS
63}
64
0ab48859
MS
65set return_me 0
66
67gdb_test_multiple "list $baseline, +12" "all tests in this module will fail" {
c906108c
SS
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) } {
b60f0898 94 untested backtrace.exp
0ab48859 95 set return_me 1
c906108c
SS
96all tests in this module will fail."
97 }
98 }
99 default {
b60f0898 100 untested backtrace.exp
0ab48859 101 set return_me 1
c906108c 102all tests in this module will fail."
0ab48859
MS
103 }
104}
105
106if { $return_me == 1 } then {
ae59b1da 107 return -1
c906108c
SS
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
118gdb_delete_tracepoints
119set tdp2 [gdb_gettpnum $testline2]
120set tdp3 [gdb_gettpnum $testline3]
121set tdp4 [gdb_gettpnum $testline4]
122set tdp5 [gdb_gettpnum $testline5]
123set tdp6 [gdb_gettpnum $testline6]
124if { $tdp2 <= 0 || $tdp3 <= 0 || \
125 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
126 fail "setting tracepoints failed"
4ec70201 127 return
c906108c
SS
128}
129
130#gdb_trace_setactions "setup TP to collect FP" \
131# "$tdp2" \
132# "collect \$fp" ""
133#
134
135gdb_trace_setactions "8.6: setup TP to collect regs" \
136 "$tdp3" \
137 "collect \$regs" "^$"
138
139gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
140 "$tdp4" \
141 "collect \$regs, \$args, \$locs" "^$"
142
7f062217 143if [is_amd64_regs_target] {
6a8f2671
PA
144 set fpreg "\$rbp"
145 set spreg "\$rsp"
7f062217 146} elseif [is_x86_like_target] {
6a8f2671
PA
147 set fpreg "\$ebp"
148 set spreg "\$esp"
149} else {
150 set fpreg "\$fp"
151 set spreg "\$sp"
152}
153
c906108c 154gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
6a8f2671
PA
155 "$tdp6" \
156 "collect $fpreg, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
c906108c 157
48bbe0bf 158gdb_test_no_output "tstart" ""
c906108c 159
de7ff789 160gdb_test "break end" ".*" ""
f8b7eaf3
DJ
161gdb_test "continue" \
162 "Continuing.*Breakpoint $decimal, end.*" \
163 "run trace experiment"
c906108c 164
48bbe0bf 165gdb_test_no_output "tstop" ""
c906108c
SS
166
167proc gdb_backtrace_tdp_1 { msg } {
168 global gdb_prompt
169
170 # We are in a trace frame at which we didn't collect anything
171 # except $PC. Therefore we expect to be able to identify stack
172 # frame #0, but that's about all. In particular we do not expect
173 # to be able to display the function's arguments or locals, and we
174 # do not expect to be able to identify the caller of this function.
175
0ab48859
MS
176 gdb_test "backtrace" \
177 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
178 "$msg"
c906108c
SS
179}
180
181proc gdb_backtrace_tdp_2 { msg } {
182 global gdb_prompt
183
184 # We are in a trace frame at which we collected only the registers
185 # Therefore we expect to be able to identify stack frame #0, but
186 # we don't expect to be able to display its args unles they are
187 # passed in registers (which isn't the case for m68k), and we
188 # don't expect to be able to identify the caller's stack frame.
189
0ab48859
MS
190 gdb_test "backtrace" \
191 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
192 "$msg"
c906108c
SS
193}
194
195proc gdb_backtrace_tdp_3 { msg } {
196 global gdb_prompt
197
198 # We are in a trace frame at which we collected all registers, all
199 # arguments and all locals. This means that the display of
200 # stack frame #0 should be complete (including argument values).
201
0ab48859 202 gdb_test_multiple "backtrace" "$msg" {
c906108c
SS
203 -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 $" {
204 pass "$msg"
205 }
206 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
207 fail "$msg (failed to collect arguments)"
208 }
c906108c
SS
209 }
210}
211
680558e8 212proc gdb_backtrace_tdp_4 { msg depth traceframe } {
c906108c
SS
213 global gdb_prompt
214
680558e8
YQ
215 with_test_prefix "traceframe $traceframe" {
216 # We are in a trace frame at which we collected all registers,
217 # plus a sizeable hunk of stack memory. This should enable us to
218 # display at least several stack frames worth of backtrace. We'll
219 # assume that if we can't display at least "depth" levels (with
220 # args), it counts as an error.
221
222 gdb_test_multiple "backtrace" "$msg" {
223 -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 $" {
224 pass "$msg"
225 }
226 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
227 fail "$msg (args missing from #$depth stack frame)"
228 }
229 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
230 fail "$msg (fewer than $depth stack frames found)"
231 }
c906108c 232 }
de74e63a
YQ
233
234 set output_string0 ""
235 # Match the output of command 'tdump' and save it in
236 # $output_string0.
237 set test "tdump on frame 0"
238 gdb_test_multiple "tdump" $test {
239 -re "tdump\[\r\n\]+(.*)\[\r\n\]+$gdb_prompt $" {
240 set output_string0 $expect_out(1,string)
241 }
242 }
243
244 gdb_test "up" ".*" ""
245
246 # Test that command 'tdump' still works properly when the
247 # selected frame is not the current frame, and save the output
248 # in $output_string1.
249 set test "tdump on frame 1"
250 set output_string1 ""
251 gdb_test_multiple "tdump" $test {
252 -re "tdump\[\r\n\]+(.*)\[\r\n\]+$gdb_prompt $" {
253 set output_string1 $expect_out(1,string)
254 }
255 }
256
257 # Output of 'tdump' on frame 0 and frame 1 should be
258 # identical.
259 if ![string compare $output_string0 $output_string1] {
260 pass "tdump output"
261 } else {
262 fail "tdump output"
263 }
c906108c
SS
264 }
265}
266
267#
268# begin backtrace test
269#
270
271set timeout 60
272
273gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
274
275gdb_tfind_test "8.6: find start frame" "start" "0"
276gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
277 "TDP $tdp2:" ""
278gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
279
280gdb_tfind_test "8.6: find frame 1" "1" "1"
281gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
282 "TDP $tdp3:" ""
283gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
284
285gdb_tfind_test "8.6: find frame 2" "2" "2"
286gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
287 "TDP $tdp4:" ""
288gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
289
290
291gdb_tfind_test "8.6: find frame 4" "4" "4"
292gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
293 "TDP $tdp6:" ""
680558e8 294gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 4
c906108c
SS
295
296gdb_tfind_test "8.6: find frame 5" "5" "5"
297gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
298 "TDP $tdp2:" ""
299gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
300
301gdb_tfind_test "8.6: find frame 6" "6" "6"
302gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
303 "TDP $tdp3:" ""
304gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
305
306gdb_tfind_test "8.6: find frame 7" "7" "7"
307gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
308 "TDP $tdp4:" ""
309gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
310
311
312gdb_tfind_test "8.6: find frame 9" "9" "9"
313gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
314 "TDP $tdp6:" ""
680558e8 315gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 9
c906108c
SS
316
317gdb_tfind_test "8.6: find frame 10" "10" "10"
318gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
319 "TDP $tdp2:" ""
320gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
321
322gdb_tfind_test "8.6: find frame 11" "11" "11"
323gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
324 "TDP $tdp3:" ""
325gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
326
327gdb_tfind_test "8.6: find frame 12" "12" "12"
328gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
329 "TDP $tdp4:" ""
330gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
331
332
333gdb_tfind_test "8.6: find frame 14" "14" "14"
334gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
335 "TDP $tdp6:" ""
680558e8 336gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 14
c906108c
SS
337
338gdb_tfind_test "8.6: find frame 15" "15" "15"
339gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
340 "TDP $tdp2:" ""
341gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
342
343gdb_tfind_test "8.6: find frame 16" "16" "16"
344gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
345 "TDP $tdp3:" ""
346gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
347
348gdb_tfind_test "8.6: find frame 17" "17" "17"
349gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
350 "TDP $tdp4:" ""
351gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
352
353
354gdb_tfind_test "8.6: find frame 19" "19" "19"
355gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
356 "TDP $tdp6:" ""
680558e8 357gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 19
c906108c
SS
358
359gdb_test "printf \"x \%d x\\n\", depth == 3" \
360 "x 0 x" \
361 "1.13: trace in recursion: depth not equal to 3"
362
363# Finished!
de7ff789 364gdb_test "tfind none" ".*" ""