gdb:
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / savedregs.exp
CommitLineData
4c38e0a4 1# Copyright 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
a1e167bb
AC
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
a1e167bb 6# (at your option) any later version.
e22f8b7c 7#
a1e167bb
AC
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#
a1e167bb 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/>.
a1e167bb
AC
15
16# This test is to check that a frame's "info frame", especially the
17# saved registers list, doesn't change while that frame isn't current.
18
19# It uses the program savedregs.c to construct a somewhat warped
20# backtrace (contains both signal and dummy frames) and then, at each
21# step checks that non-inner frames have consistent "info frame"
22# output. Note that a frame's "info frame" can only be captured after
23# it is non-current (made a call, interrupted, ...), this is because
24# instructions executed to perform the call may affect "info frame"
25# output.
26
27if [target_info exists gdb,nosignals] {
28 verbose "Skipping savedregs.exp because of nosignals."
29 continue
30}
31
32if $tracelevel then {
33 strace $tracelevel
34}
35
a1e167bb
AC
36
37set testfile savedregs
38set srcfile ${testfile}.c
39set binfile ${objdir}/${subdir}/${testfile}
40if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
41 untested "Couldn't compile ${module}.c"
42 return -1
43}
44
45# get things started
46gdb_exit
47gdb_start
48gdb_reinitialize_dir $srcdir/$subdir
49gdb_load ${binfile}
50
51# Advance to main
52if { ![runto_main] } {
53 gdb_suppress_tests;
54}
55
56proc process_saved_regs { current inner outer } {
57 global gdb_prompt
58 global expect_out
59 global saved_regs
60
61 # Skip the CURRENT frame.
62
63 set level 1
64
65 # Run over the list of INNER frames capturing the "info frame"
66 # output for each. Both dummy and sigtramp frames need to be
67 # handled specially: they do not yet have correct function names;
68 # and for dummy frames won't have saved registers. If there's a
69 # problem, fail but capture the output anyway, hopefully later
70 # "info frame" requests for that same frame will at least fail in
71 # a consistent manner (stops propogated fails).
72
73 foreach func $inner {
74 set saved_regs($func) "error"
75 set test "Get $func info frame"
76 # Both dummy and sigtramp frames have problems.
77 switch $func {
78 dummy {
79 # Dummy frame's do not have saved registers, and do
80 # not print <dummy>.
1303f75e 81 set pat "Stack frame at .*"
a1e167bb
AC
82 }
83 sigtramp {
84 # Sigtramp frames don't yet print <signal trampoline>.
9cf0961b 85 set pat "Stack frame at .* Saved registers:.*"
a1e167bb
AC
86 }
87 default {
88 set pat "Stack frame at .* in $func .* Saved registers:.*"
89 }
90 }
91 # If the "info frame" barf, capture the output anyway so that
92 # it does not cascade further failures.
93 gdb_test_multiple "info frame $level" "$test" {
94 -re "($pat)$gdb_prompt " {
95 set saved_regs($func) "$expect_out(1,string)"
96 pass "$test"
97 }
98 -re "(Stack frame at .*)$gdb_prompt " {
99 set saved_regs($func) "$expect_out(1,string)"
100 fail "$test"
101 }
102 -re "(Cannot access .*)$gdb_prompt " {
103 set saved_regs($func) "$expect_out(1,string)"
104 fail "$test"
105 }
106 }
107 incr level
108 }
109
110 # Now iterate through the list of OUTER frames checking that the
111 # "info frame" output from each still matches what was captured
112 # during an early query. To avoid cascading failures, checking is
113 # abandoned after the first failure. The assumption is that,
114 # since frames outer to the botched frame rely on the botched
115 # frame's info, those more outer frames are also botched. Besides
116 # we've got the failure we're after.
117
118 set ok 1
119 foreach func $outer {
120 set test [concat "Check $func info frame; stack contains" \
121 $current $inner $outer]
122 if $ok {
123 set ok 0
124 set pat [string_to_regexp "$saved_regs($func)"]
125 gdb_test_multiple "info frame $level" "$test" {
126 -re "$pat$gdb_prompt " {
127 pass "$test"
128 set ok 1
129 }
130 }
131 } {
132 pass "$test (skipped)"
133 }
134 incr level
135 }
136}
137
138
139# Continue to the signal thrower, capture main's saved-reg info.
140gdb_test "advance thrower" "thrower .* at .*"
141process_saved_regs thrower { main } { }
142
143# Continue to the signal catcher, check main's saved-reg info, capture
144# catcher's saved-reg info.
145gdb_test "handle SIGSEGV pass print nostop"
146gdb_test "advance catcher" "catcher .* at .*"
147process_saved_regs catcher { sigtramp thrower } { main }
148
149# Breakpoint at and call the caller function, saved-regs of main and
150# catcher, capture caller's registers.
151gdb_test "break caller"
152gdb_test "call caller (1,2,3,4,5,6,7,8)"
153process_saved_regs caller { dummy catcher } { sigtramp thrower main }
154
155# Run to callee, again check everything.
156gdb_test "advance callee" "callee .* at .*"
157process_saved_regs callee { caller } { dummy catcher sigtramp thrower main }
This page took 0.604011 seconds and 4 git commands to generate.