Commit | Line | Data |
---|---|---|
029d2200 AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
0b302171 | 3 | # Copyright 1998-2002, 2004, 2007-2012 Free Software Foundation, Inc. |
c906108c SS |
4 | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 7 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 8 | # (at your option) any later version. |
e22f8b7c | 9 | # |
c906108c SS |
10 | # This program is distributed in the hope that it will be useful, |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
e22f8b7c | 14 | # |
c906108c | 15 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 17 | |
c906108c SS |
18 | # Test GDB's ability to restore saved registers from stack frames |
19 | # when using the `return' command. | |
20 | # | |
21 | # This file was written by Jim Blandy <jimb@cygnus.com>, with | |
22 | # fragments borrowed from return.exp. | |
23 | ||
c906108c SS |
24 | |
25 | set testfile "restore" | |
26 | set srcfile ${testfile}.c | |
27 | set binfile ${objdir}/${subdir}/${testfile} | |
28 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
29 | untested restore.exp |
30 | return -1 | |
c906108c SS |
31 | } |
32 | ||
33 | proc restore_tests { } { | |
34 | global gdb_prompt | |
35 | ||
029d2200 AC |
36 | if { ! [ runto driver ] } { |
37 | return 0 | |
38 | } | |
c906108c SS |
39 | |
40 | set limit 5 | |
41 | ||
c906108c SS |
42 | # For each caller function, |
43 | # call each of the callee functions, | |
44 | # force a return from the callee, and | |
45 | # make sure that the local variables still have the right values. | |
029d2200 | 46 | |
c906108c SS |
47 | for {set c 1} {$c <= $limit} {incr c} { |
48 | ||
1b8947f0 | 49 | # Set a breakpoint at the next caller function. |
18ac113b | 50 | gdb_test "tbreak caller$c" "Temporary breakpoint.*\[0-9\]*\\." \ |
029d2200 | 51 | "tbreak caller$c" |
1b8947f0 | 52 | |
c906108c | 53 | # Continue to the next caller function. |
029d2200 | 54 | gdb_test "continue" " caller$c prologue .*" "run to caller$c" |
c906108c SS |
55 | |
56 | # Do each callee function. | |
57 | for {set e 1} {$e <= $limit} {incr e} { | |
1b8947f0 | 58 | |
18ac113b | 59 | gdb_test "tbreak callee$e" "Temporary breakpoint.*\[0-9\]*\\." \ |
029d2200 | 60 | "caller$c calls callee$e; tbreak callee" |
1b8947f0 | 61 | |
029d2200 AC |
62 | gdb_test "continue" " callee$e prologue .*/" \ |
63 | "caller$c calls callee$e; continue to callee" | |
64 | ||
c906108c | 65 | # Do a forced return from the callee. |
029d2200 | 66 | set test "caller$c calls callee$e; return callee now" |
02746bbc MS |
67 | |
68 | gdb_test "return 0" \ | |
69 | " caller$c .*" \ | |
70 | "$test" \ | |
71 | "Make .* return now.*y or n. $" \ | |
72 | "y" | |
c906108c SS |
73 | |
74 | # Check that the values of the local variables are what | |
75 | # they should be. | |
76 | for {set var 1} {$var <= $c} {incr var} { | |
d4f3574e | 77 | set expected [expr 0x7eeb + $var] |
c906108c | 78 | gdb_test "print l$var" " = $expected" \ |
029d2200 | 79 | "caller$c calls callee$e; return restored l$var to $expected" |
c906108c SS |
80 | } |
81 | } | |
82 | } | |
83 | ||
958a4e4c MS |
84 | if ![gdb_skip_stdio_test "run to completion"] { |
85 | send_gdb "continue\n" | |
86 | ||
87 | gdb_expect { | |
88 | -re "exiting" { | |
89 | pass "run to completion" | |
90 | } | |
91 | timeout { | |
92 | fail "(timeout) run to completion" | |
93 | } | |
94 | } | |
95 | } else { | |
de7ff789 | 96 | gdb_test "continue" ".*" "" |
c906108c SS |
97 | } |
98 | } | |
99 | ||
100 | ||
958a4e4c | 101 | |
c906108c SS |
102 | # Start with a fresh gdb. |
103 | ||
104 | gdb_exit | |
105 | gdb_start | |
106 | gdb_reinitialize_dir $srcdir/$subdir | |
107 | gdb_load ${binfile} | |
108 | ||
97f2ed50 | 109 | set prev_timeout $timeout |
c906108c SS |
110 | set timeout 30 |
111 | restore_tests | |
97f2ed50 | 112 | set timeout $prev_timeout |