2004-07-16 22:21:52 +00:00
|
|
|
# This testcase is part of GDB, the GNU debugger.
|
|
|
|
|
2007-01-09 17:59:20 +00:00
|
|
|
# Copyright 1998, 1999, 2000, 2001, 2002, 2004, 2007
|
|
|
|
# Free Software Foundation, Inc.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-08-23 18:14:19 +00:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
1999-04-16 01:35:26 +00:00
|
|
|
# (at your option) any later version.
|
2007-08-23 18:14:19 +00:00
|
|
|
#
|
1999-04-16 01:35:26 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2007-08-23 18:14:19 +00:00
|
|
|
#
|
1999-04-16 01:35:26 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-08-23 18:14:19 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
# Test GDB's ability to restore saved registers from stack frames
|
|
|
|
# when using the `return' command.
|
|
|
|
#
|
|
|
|
# This file was written by Jim Blandy <jimb@cygnus.com>, with
|
|
|
|
# fragments borrowed from return.exp.
|
|
|
|
|
|
|
|
if $tracelevel then {
|
2004-07-16 22:21:52 +00:00
|
|
|
strace $tracelevel
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set prms_id 0
|
|
|
|
set bug_id 0
|
|
|
|
|
|
|
|
set testfile "restore"
|
|
|
|
set srcfile ${testfile}.c
|
|
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
|
|
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
|
2006-08-10 05:27:22 +00:00
|
|
|
untested restore.exp
|
|
|
|
return -1
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proc restore_tests { } {
|
|
|
|
global gdb_prompt
|
|
|
|
|
2004-07-16 22:21:52 +00:00
|
|
|
if { ! [ runto driver ] } {
|
|
|
|
return 0
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
set limit 5
|
|
|
|
|
|
|
|
# For each caller function,
|
|
|
|
# call each of the callee functions,
|
|
|
|
# force a return from the callee, and
|
|
|
|
# make sure that the local variables still have the right values.
|
2004-07-16 22:21:52 +00:00
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
for {set c 1} {$c <= $limit} {incr c} {
|
|
|
|
|
2001-09-17 19:42:28 +00:00
|
|
|
# Set a breakpoint at the next caller function.
|
2004-07-16 22:21:52 +00:00
|
|
|
gdb_test "tbreak caller$c" "Breakpoint.*\[0-9\]*\\." \
|
|
|
|
"tbreak caller$c"
|
2001-09-17 19:42:28 +00:00
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
# Continue to the next caller function.
|
2004-07-16 22:21:52 +00:00
|
|
|
gdb_test "continue" " caller$c prologue .*" "run to caller$c"
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
# Do each callee function.
|
|
|
|
for {set e 1} {$e <= $limit} {incr e} {
|
2001-09-17 19:42:28 +00:00
|
|
|
|
|
|
|
gdb_test "tbreak callee$e" "Breakpoint.*\[0-9\]*\\." \
|
2004-07-16 22:21:52 +00:00
|
|
|
"caller$c calls callee$e; tbreak callee"
|
2001-09-17 19:42:28 +00:00
|
|
|
|
2004-07-16 22:21:52 +00:00
|
|
|
gdb_test "continue" " callee$e prologue .*/" \
|
|
|
|
"caller$c calls callee$e; continue to callee"
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
# Do a forced return from the callee.
|
2004-07-16 22:21:52 +00:00
|
|
|
set test "caller$c calls callee$e; return callee now"
|
|
|
|
gdb_test_multiple "return 0" "$test" {
|
1999-04-16 01:35:26 +00:00
|
|
|
-re "Make .* return now.*y or n. $" {
|
|
|
|
send_gdb "y\n"
|
|
|
|
exp_continue
|
|
|
|
}
|
2004-07-16 22:21:52 +00:00
|
|
|
-re " caller$c .*$gdb_prompt $" {
|
|
|
|
pass "$test"
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check that the values of the local variables are what
|
|
|
|
# they should be.
|
|
|
|
for {set var 1} {$var <= $c} {incr var} {
|
1999-09-09 00:02:17 +00:00
|
|
|
set expected [expr 0x7eeb + $var]
|
1999-04-16 01:35:26 +00:00
|
|
|
gdb_test "print l$var" " = $expected" \
|
2004-07-16 22:21:52 +00:00
|
|
|
"caller$c calls callee$e; return restored l$var to $expected"
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-14 22:12:26 +00:00
|
|
|
if ![gdb_skip_stdio_test "run to completion"] {
|
|
|
|
send_gdb "continue\n"
|
|
|
|
|
|
|
|
gdb_expect {
|
|
|
|
-re "exiting" {
|
|
|
|
pass "run to completion"
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
fail "(timeout) run to completion"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gdb_test "continue" "" ""
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-14 22:12:26 +00:00
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
# Start with a fresh gdb.
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
gdb_load ${binfile}
|
|
|
|
|
|
|
|
set timeout 30
|
|
|
|
restore_tests
|