1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 1998, 1999, 2000, 2001, 2002, 2004, 2007, 2008, 2009, 2010
4 # Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Test GDB's ability to restore saved registers from stack frames
20 # when using the `return' command.
22 # This file was written by Jim Blandy <jimb@cygnus.com>, with
23 # fragments borrowed from return.exp.
30 set testfile "restore"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
38 proc restore_tests { } {
41 if { ! [ runto driver ] } {
47 # For each caller function,
48 # call each of the callee functions,
49 # force a return from the callee, and
50 # make sure that the local variables still have the right values.
52 for {set c 1} {$c <= $limit} {incr c} {
54 # Set a breakpoint at the next caller function.
55 gdb_test "tbreak caller$c" "Temporary breakpoint.*\[0-9\]*\\." \
58 # Continue to the next caller function.
59 gdb_test "continue" " caller$c prologue .*" "run to caller$c"
61 # Do each callee function.
62 for {set e 1} {$e <= $limit} {incr e} {
64 gdb_test "tbreak callee$e" "Temporary breakpoint.*\[0-9\]*\\." \
65 "caller$c calls callee$e; tbreak callee"
67 gdb_test "continue" " callee$e prologue .*/" \
68 "caller$c calls callee$e; continue to callee"
70 # Do a forced return from the callee.
71 set test "caller$c calls callee$e; return callee now"
76 "Make .* return now.*y or n. $" \
79 # Check that the values of the local variables are what
81 for {set var 1} {$var <= $c} {incr var} {
82 set expected [expr 0x7eeb + $var]
83 gdb_test "print l$var" " = $expected" \
84 "caller$c calls callee$e; return restored l$var to $expected"
89 if ![gdb_skip_stdio_test "run to completion"] {
94 pass "run to completion"
97 fail "(timeout) run to completion"
101 gdb_test "continue" ".*" ""
107 # Start with a fresh gdb.
111 gdb_reinitialize_dir $srcdir/$subdir
114 set prev_timeout $timeout
117 set timeout $prev_timeout