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