Fix more cases of improper test names
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / backtrace.exp
CommitLineData
618f726f 1# Copyright 1998-2016 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
5b362f04 24if [prepare_for_testing "failed to prepare" $executable $srcfile \
48bbe0bf 25 [list debug nowarnings]] {
48bbe0bf
YQ
26 return -1
27}
c906108c 28
48bbe0bf 29if ![runto_main] {
bc6c7af4 30 fail "can't run to main to check for trace support"
f8b7eaf3 31 return -1
c906108c 32}
c906108c 33
c906108c 34if { ![gdb_target_supports_trace] } then {
bc6c7af4 35 unsupported "current target does not support trace"
ae59b1da 36 return 1
c906108c
SS
37
38}
39
40#
41# test backtraces in trace frames
42#
43
44set testline1 0
45set testline2 0
46set testline3 0
47set testline4 0
48set testline5 0
49set testline6 0
50
51set arg1 1
52set arg2 2
53set arg3 3
54set arg4 4
55set arg5 5
56set arg6 6
57
4ec70201 58set baseline [gdb_find_recursion_test_baseline $srcfile]
c906108c 59if { $baseline == -1 } {
bc6c7af4 60 fail "could not find gdb_recursion_test function"
4ec70201 61 return
c906108c
SS
62}
63
0ab48859
MS
64set return_me 0
65
66gdb_test_multiple "list $baseline, +12" "all tests in this module will fail" {
c906108c
SS
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) } {
84c93cd5 93 untested "unexpected testline values"
0ab48859 94 set return_me 1
c906108c
SS
95all tests in this module will fail."
96 }
97 }
98 default {
84c93cd5 99 untested "couldn't match pattern"
0ab48859 100 set return_me 1
c906108c 101all tests in this module will fail."
0ab48859
MS
102 }
103}
104
105if { $return_me == 1 } then {
ae59b1da 106 return -1
c906108c
SS
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
117gdb_delete_tracepoints
118set tdp2 [gdb_gettpnum $testline2]
119set tdp3 [gdb_gettpnum $testline3]
120set tdp4 [gdb_gettpnum $testline4]
121set tdp5 [gdb_gettpnum $testline5]
122set tdp6 [gdb_gettpnum $testline6]
123if { $tdp2 <= 0 || $tdp3 <= 0 || \
124 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
125 fail "setting tracepoints failed"
4ec70201 126 return
c906108c
SS
127}
128
129#gdb_trace_setactions "setup TP to collect FP" \
130# "$tdp2" \
131# "collect \$fp" ""
132#
133
134gdb_trace_setactions "8.6: setup TP to collect regs" \
135 "$tdp3" \
136 "collect \$regs" "^$"
137
138gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
139 "$tdp4" \
140 "collect \$regs, \$args, \$locs" "^$"
141
142gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
6a8f2671 143 "$tdp6" \
45f38546 144 "collect \$$fpreg, \(\*\(void \*\*\) \(\$$spreg\)\) @ 128" "^$"
c906108c 145
48bbe0bf 146gdb_test_no_output "tstart" ""
c906108c 147
de7ff789 148gdb_test "break end" ".*" ""
f8b7eaf3
DJ
149gdb_test "continue" \
150 "Continuing.*Breakpoint $decimal, end.*" \
151 "run trace experiment"
c906108c 152
48bbe0bf 153gdb_test_no_output "tstop" ""
c906108c
SS
154
155proc 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
0ab48859
MS
164 gdb_test "backtrace" \
165 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
166 "$msg"
c906108c
SS
167}
168
169proc 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
0ab48859
MS
178 gdb_test "backtrace" \
179 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
180 "$msg"
c906108c
SS
181}
182
183proc 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
0ab48859 190 gdb_test_multiple "backtrace" "$msg" {
c906108c
SS
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 }
c906108c
SS
197 }
198}
199
680558e8 200proc gdb_backtrace_tdp_4 { msg depth traceframe } {
c906108c
SS
201 global gdb_prompt
202
680558e8
YQ
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 }
c906108c 220 }
de74e63a
YQ
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.
bd293940
PA
247 gdb_assert ![string compare $output_string0 $output_string1] \
248 "tdump output"
c906108c
SS
249 }
250}
251
252#
253# begin backtrace test
254#
255
256set timeout 60
257
258gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
259
260gdb_tfind_test "8.6: find start frame" "start" "0"
261gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
262 "TDP $tdp2:" ""
263gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
264
265gdb_tfind_test "8.6: find frame 1" "1" "1"
266gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
267 "TDP $tdp3:" ""
268gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
269
270gdb_tfind_test "8.6: find frame 2" "2" "2"
271gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
272 "TDP $tdp4:" ""
273gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
274
275
276gdb_tfind_test "8.6: find frame 4" "4" "4"
277gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
278 "TDP $tdp6:" ""
680558e8 279gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 4
c906108c
SS
280
281gdb_tfind_test "8.6: find frame 5" "5" "5"
282gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
283 "TDP $tdp2:" ""
284gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
285
286gdb_tfind_test "8.6: find frame 6" "6" "6"
287gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
288 "TDP $tdp3:" ""
289gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
290
291gdb_tfind_test "8.6: find frame 7" "7" "7"
292gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
293 "TDP $tdp4:" ""
294gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
295
296
297gdb_tfind_test "8.6: find frame 9" "9" "9"
298gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
299 "TDP $tdp6:" ""
680558e8 300gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 9
c906108c
SS
301
302gdb_tfind_test "8.6: find frame 10" "10" "10"
303gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
304 "TDP $tdp2:" ""
305gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
306
307gdb_tfind_test "8.6: find frame 11" "11" "11"
308gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
309 "TDP $tdp3:" ""
310gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
311
312gdb_tfind_test "8.6: find frame 12" "12" "12"
313gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
314 "TDP $tdp4:" ""
315gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
316
317
318gdb_tfind_test "8.6: find frame 14" "14" "14"
319gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
320 "TDP $tdp6:" ""
680558e8 321gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 14
c906108c
SS
322
323gdb_tfind_test "8.6: find frame 15" "15" "15"
324gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
325 "TDP $tdp2:" ""
326gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
327
328gdb_tfind_test "8.6: find frame 16" "16" "16"
329gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
330 "TDP $tdp3:" ""
331gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
332
333gdb_tfind_test "8.6: find frame 17" "17" "17"
334gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
335 "TDP $tdp4:" ""
336gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
337
338
339gdb_tfind_test "8.6: find frame 19" "19" "19"
340gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
341 "TDP $tdp6:" ""
680558e8 342gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 19
c906108c
SS
343
344gdb_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!
de7ff789 349gdb_test "tfind none" ".*" ""
This page took 3.235092 seconds and 4 git commands to generate.