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