1 # Copyright 1998-2014 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 $expfile $executable $srcfile \
25 [list debug nowarnings]] {
26 untested "failed to prepare for trace tests"
31 fail "Can't run to main to check for trace support"
35 if { ![gdb_target_supports_trace] } then {
36 unsupported "Current target does not support trace"
42 # test backtraces in trace frames
59 set baseline [gdb_find_recursion_test_baseline $srcfile]
60 if { $baseline == -1 } {
61 fail "Could not find gdb_recursion_test function"
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)
72 -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
73 set testline2 $expect_out(1,string)
76 -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
77 set testline3 $expect_out(1,string)
80 -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
81 set testline4 $expect_out(1,string)
84 -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
85 set testline5 $expect_out(1,string)
88 -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
89 set testline6 $expect_out(1,string)
92 -re ".*$gdb_prompt $" {
93 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
94 untested backtrace.exp
96 all tests in this module will fail."
100 untested backtrace.exp
102 all tests in this module will fail."
106 if { $return_me == 1 } then {
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.
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"
130 #gdb_trace_setactions "setup TP to collect FP" \
135 gdb_trace_setactions "8.6: setup TP to collect regs" \
137 "collect \$regs" "^$"
139 gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
141 "collect \$regs, \$args, \$locs" "^$"
143 if [is_amd64_regs_target] {
146 } elseif [is_x86_like_target] {
154 gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
156 "collect $fpreg, \(\*\(void \*\*\) \($spreg\)\) @ 64" "^$"
158 gdb_test_no_output "tstart" ""
160 gdb_test "break end" ".*" ""
161 gdb_test "continue" \
162 "Continuing.*Breakpoint $decimal, end.*" \
163 "run trace experiment"
165 gdb_test_no_output "tstop" ""
167 proc gdb_backtrace_tdp_1 { msg } {
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.
176 gdb_test "backtrace" \
177 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
181 proc gdb_backtrace_tdp_2 { msg } {
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.
190 gdb_test "backtrace" \
191 "#0\[\t \]+gdb_recursion_test.*depth=.*" \
195 proc gdb_backtrace_tdp_3 { msg } {
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).
202 gdb_test_multiple "backtrace" "$msg" {
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 $" {
206 -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
207 fail "$msg (failed to collect arguments)"
212 proc gdb_backtrace_tdp_4 { msg depth traceframe } {
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.
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 $" {
226 -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
227 fail "$msg (args missing from #$depth stack frame)"
229 -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
230 fail "$msg (fewer than $depth stack frames found)"
234 set output_string0 ""
235 # Match the output of command 'tdump' and save it in
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)
244 gdb_test "up" ".*" ""
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)
257 # Output of 'tdump' on frame 0 and frame 1 should be
259 if ![string compare $output_string0 $output_string1] {
268 # begin backtrace test
273 gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
275 gdb_tfind_test "8.6: find start frame" "start" "0"
276 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
278 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
280 gdb_tfind_test "8.6: find frame 1" "1" "1"
281 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
283 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
285 gdb_tfind_test "8.6: find frame 2" "2" "2"
286 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
288 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
291 gdb_tfind_test "8.6: find frame 4" "4" "4"
292 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
294 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 4
296 gdb_tfind_test "8.6: find frame 5" "5" "5"
297 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
299 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
301 gdb_tfind_test "8.6: find frame 6" "6" "6"
302 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
304 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
306 gdb_tfind_test "8.6: find frame 7" "7" "7"
307 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
309 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
312 gdb_tfind_test "8.6: find frame 9" "9" "9"
313 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
315 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 9
317 gdb_tfind_test "8.6: find frame 10" "10" "10"
318 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
320 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
322 gdb_tfind_test "8.6: find frame 11" "11" "11"
323 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
325 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
327 gdb_tfind_test "8.6: find frame 12" "12" "12"
328 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
330 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
333 gdb_tfind_test "8.6: find frame 14" "14" "14"
334 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
336 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 14
338 gdb_tfind_test "8.6: find frame 15" "15" "15"
339 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
341 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
343 gdb_tfind_test "8.6: find frame 16" "16" "16"
344 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
346 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
348 gdb_tfind_test "8.6: find frame 17" "17" "17"
349 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
351 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
354 gdb_tfind_test "8.6: find frame 19" "19" "19"
355 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
357 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0" 19
359 gdb_test "printf \"x \%d x\\n\", depth == 3" \
361 "1.13: trace in recursion: depth not equal to 3"
364 gdb_test "tfind none" ".*" ""