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