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