]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/savedregs.exp
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / savedregs.exp
CommitLineData
b811d2c2 1# Copyright 2004-2020 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
a1e167bb 32
0ab77f5f
TT
33standard_testfile .c
34
a1e167bb 35if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
84c93cd5 36 untested "failed to compile"
a1e167bb
AC
37 return -1
38}
39
40# get things started
0ab77f5f 41clean_restart ${binfile}
a1e167bb
AC
42
43# Advance to main
c8ee3f04
PW
44if ![runto_main] then {
45 fail "can't run to main"
46 return 0
a1e167bb
AC
47}
48
49proc process_saved_regs { current inner outer } {
50 global gdb_prompt
51 global expect_out
52 global saved_regs
53
54 # Skip the CURRENT frame.
55
56 set level 1
57
58 # Run over the list of INNER frames capturing the "info frame"
59 # output for each. Both dummy and sigtramp frames need to be
60 # handled specially: they do not yet have correct function names;
61 # and for dummy frames won't have saved registers. If there's a
62 # problem, fail but capture the output anyway, hopefully later
63 # "info frame" requests for that same frame will at least fail in
64 # a consistent manner (stops propogated fails).
65
66 foreach func $inner {
67 set saved_regs($func) "error"
bc6c7af4 68 set test "get $func info frame"
a1e167bb
AC
69 # Both dummy and sigtramp frames have problems.
70 switch $func {
71 dummy {
72 # Dummy frame's do not have saved registers, and do
73 # not print <dummy>.
1303f75e 74 set pat "Stack frame at .*"
a1e167bb
AC
75 }
76 sigtramp {
77 # Sigtramp frames don't yet print <signal trampoline>.
9cf0961b 78 set pat "Stack frame at .* Saved registers:.*"
a1e167bb
AC
79 }
80 default {
8aa08a8d 81 set pat "Stack frame at .* in $func .*( Saved registers:.*)?"
a1e167bb
AC
82 }
83 }
84 # If the "info frame" barf, capture the output anyway so that
85 # it does not cascade further failures.
86 gdb_test_multiple "info frame $level" "$test" {
87 -re "($pat)$gdb_prompt " {
88 set saved_regs($func) "$expect_out(1,string)"
89 pass "$test"
90 }
91 -re "(Stack frame at .*)$gdb_prompt " {
92 set saved_regs($func) "$expect_out(1,string)"
93 fail "$test"
94 }
95 -re "(Cannot access .*)$gdb_prompt " {
96 set saved_regs($func) "$expect_out(1,string)"
97 fail "$test"
98 }
99 }
100 incr level
101 }
102
103 # Now iterate through the list of OUTER frames checking that the
104 # "info frame" output from each still matches what was captured
105 # during an early query. To avoid cascading failures, checking is
106 # abandoned after the first failure. The assumption is that,
107 # since frames outer to the botched frame rely on the botched
108 # frame's info, those more outer frames are also botched. Besides
109 # we've got the failure we're after.
110
111 set ok 1
112 foreach func $outer {
113 set test [concat "Check $func info frame; stack contains" \
114 $current $inner $outer]
115 if $ok {
116 set ok 0
117 set pat [string_to_regexp "$saved_regs($func)"]
118 gdb_test_multiple "info frame $level" "$test" {
119 -re "$pat$gdb_prompt " {
120 pass "$test"
121 set ok 1
122 }
123 }
124 } {
125 pass "$test (skipped)"
126 }
127 incr level
128 }
129}
130
131
132# Continue to the signal thrower, capture main's saved-reg info.
133gdb_test "advance thrower" "thrower .* at .*"
134process_saved_regs thrower { main } { }
135
136# Continue to the signal catcher, check main's saved-reg info, capture
137# catcher's saved-reg info.
138gdb_test "handle SIGSEGV pass print nostop"
d93f7b5c 139gdb_test "handle SIGILL pass print nostop"
a1e167bb
AC
140gdb_test "advance catcher" "catcher .* at .*"
141process_saved_regs catcher { sigtramp thrower } { main }
142
143# Breakpoint at and call the caller function, saved-regs of main and
144# catcher, capture caller's registers.
145gdb_test "break caller"
146gdb_test "call caller (1,2,3,4,5,6,7,8)"
147process_saved_regs caller { dummy catcher } { sigtramp thrower main }
148
149# Run to callee, again check everything.
150gdb_test "advance callee" "callee .* at .*"
151process_saved_regs callee { caller } { dummy catcher sigtramp thrower main }