1 # Copyright 1998-2016 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Michael Snyder (msnyder@cygnus.com)
18 load_lib "trace-support.exp"
20 standard_testfile actions.c
21 set executable $testfile
22 set expfile $testfile.exp
24 if [prepare_for_testing "failed to prepare" $executable $srcfile \
25 [list debug nowarnings]] {
30 fail "can't run to main to check for trace support"
34 if { ![gdb_target_supports_trace] } then {
35 unsupported "current target does not support trace"
41 # test backtraces in trace frames
58 set baseline [gdb_find_recursion_test_baseline $srcfile]
59 if { $baseline == -1 } {
60 fail "could not find gdb_recursion_test function"
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)
71 -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
72 set testline2 $expect_out(1,string)
75 -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
76 set testline3 $expect_out(1,string)
79 -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
80 set testline4 $expect_out(1,string)
83 -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
84 set testline5 $expect_out(1,string)
87 -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
88 set testline6 $expect_out(1,string)
91 -re ".*$gdb_prompt $" {
92 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
93 untested "unexpected testline values"
95 all tests in this module will fail."
99 untested "couldn't match pattern"
101 all tests in this module will fail."
105 if { $return_me == 1 } then {
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.
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"
129 #gdb_trace_setactions "setup TP to collect FP" \
134 gdb_trace_setactions "8.6: setup TP to collect regs" \
136 "collect \$regs" "^$"
138 gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
140 "collect \$regs, \$args, \$locs" "^$"
142 gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
144 "collect \$$fpreg, \(\*\(void \*\*\) \(\$$spreg\)\) @ 128" "^$"
146 gdb_test_no_output "tstart" ""
148 gdb_test "break end" ".*" ""
149 gdb_test "continue" \
150 "Continuing.*Breakpoint $decimal, end.*" \
151 "run trace experiment"
153 gdb_test_no_output "tstop" ""
155 proc gdb_backtrace_tdp_1 { msg } {
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.
164 gdb_test "backtrace" \
165 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
169 proc gdb_backtrace_tdp_2 { msg } {
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.
178 gdb_test "backtrace" \
179 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
183 proc gdb_backtrace_tdp_3 { msg } {
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).
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 $" {
194 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
195 fail "$msg (failed to collect arguments)"
200 proc gdb_backtrace_tdp_4 { msg depth traceframe } {
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.
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 $" {
214 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
215 fail "$msg (args missing from #$depth stack frame)"
217 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
218 fail "$msg (fewer than $depth stack frames found)"
222 set output_string0 ""
223 # Match the output of command 'tdump' and save it in
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)
232 gdb_test "up" ".*" ""
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)
245 # Output of 'tdump' on frame 0 and frame 1 should be
247 gdb_assert ![string compare $output_string0 $output_string1] \
253 # begin backtrace test
258 gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
260 gdb_tfind_test "8.6: find start frame" "start" "0"
261 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
263 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
265 gdb_tfind_test "8.6: find frame 1" "1" "1"
266 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
268 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
270 gdb_tfind_test "8.6: find frame 2" "2" "2"
271 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
273 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
276 gdb_tfind_test "8.6: find frame 4" "4" "4"
277 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
279 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 4
281 gdb_tfind_test "8.6: find frame 5" "5" "5"
282 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
284 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
286 gdb_tfind_test "8.6: find frame 6" "6" "6"
287 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
289 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
291 gdb_tfind_test "8.6: find frame 7" "7" "7"
292 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
294 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
297 gdb_tfind_test "8.6: find frame 9" "9" "9"
298 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
300 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 9
302 gdb_tfind_test "8.6: find frame 10" "10" "10"
303 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
305 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
307 gdb_tfind_test "8.6: find frame 11" "11" "11"
308 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
310 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
312 gdb_tfind_test "8.6: find frame 12" "12" "12"
313 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
315 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
318 gdb_tfind_test "8.6: find frame 14" "14" "14"
319 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
321 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 14
323 gdb_tfind_test "8.6: find frame 15" "15" "15"
324 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
326 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
328 gdb_tfind_test "8.6: find frame 16" "16" "16"
329 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
331 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
333 gdb_tfind_test "8.6: find frame 17" "17" "17"
334 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
336 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
339 gdb_tfind_test "8.6: find frame 19" "19" "19"
340 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
342 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 19
344 gdb_test "printf \"x \%d x\\n\", depth == 3" \
346 "1.13: trace in recursion: depth not equal to 3"
349 gdb_test "tfind none" ".*" ""