2006-11-10 Vladimir Prus <vladimir@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / recurse.exp
CommitLineData
b6ba6518
KB
1# Copyright 1992, 1994, 1995, 1996, 1997, 1999, 2000
2# Free Software Foundation, Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-gdb@prep.ai.mit.edu
20
21# This file was written by Jeff Law. (law@cs.utah.edu)
22
23if $tracelevel then {
24 strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
30set testfile "recurse"
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
34 untested recurse.exp
35 return -1
c906108c
SS
36}
37
38# Start with a fresh gdb.
39
40gdb_exit
41gdb_start
42gdb_reinitialize_dir $srcdir/$subdir
43gdb_load ${binfile}
44
45proc recurse_tests {} {
46
958a4e4c
MS
47 # Disable hardware watchpoints if necessary.
48 if [target_info exists gdb,no_hardware_watchpoints] {
49 gdb_test "set can-use-hw-watchpoints 0" "" ""
50 }
51
c906108c
SS
52 if [runto recurse] then {
53 # First we need to step over the assignment of b, so it has a known
54 # value.
55 gdb_test "next" "if \\(a == 1\\)" "next over b = 0 in first instance"
56 gdb_test "watch b" ".*\[Ww\]atchpoint \[0-9]*: b" \
57 "set first instance watchpoint"
58
59 # Continue until initial set of b.
60 if [gdb_test "continue" \
61 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 10.*" \
62 "continue to first instance watchpoint, first time"] then {
63 gdb_suppress_tests;
64 }
65
66 # Continue inward for a few iterations
67 gdb_test "continue" "Breakpoint.* recurse \\(a=9\\).*" \
68 "continue to recurse (a = 9)"
69 gdb_test "continue" "Breakpoint.* recurse \\(a=8\\).*" \
70 "continue to recurse (a = 8)"
71 gdb_test "continue" "Breakpoint.* recurse \\(a=7\\).*" \
72 "continue to recurse (a = 7)"
73 gdb_test "continue" "Breakpoint.* recurse \\(a=6\\).*" \
74 "continue to recurse (a = 6)"
75 gdb_test "continue" "Breakpoint.* recurse \\(a=5\\).*" \
76 "continue to recurse (a = 5)"
77
78 # Put a watchpoint on another instance of b
79 # First we need to step over the assignment of b, so it has a known
80 # value.
81 gdb_test "next" "if \\(a == 1\\)" "next over b = 0 in second instance"
82 gdb_test "watch b" ".*\[Ww\]atchpoint \[0-9]*: b" \
83 "set second instance watchpoint"
84
85 # Continue until initial set of b (second instance).
86 if [gdb_test "continue" \
87 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 5.*"\
88 "continue to second instance watchpoint, first time"] then {
89 gdb_suppress_tests;
90 }
91
92 # Continue inward for a few iterations
93 gdb_test "continue" "Breakpoint.* recurse \\(a=4\\).*" \
94 "continue to recurse (a = 4)"
95 gdb_test "continue" "Breakpoint.* recurse \\(a=3\\).*" \
96 "continue to recurse (a = 3)"
97 gdb_test "continue" "Breakpoint.* recurse \\(a=2\\).*" \
98 "continue to recurse (a = 2)"
99 gdb_test "continue" "Breakpoint.* recurse \\(a=1\\).*" \
100 "continue to recurse (a = 1)"
101
102 # Continue until second set of b (second instance).
103 if [gdb_test "continue" \
104 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 5.*New value = 120.*return.*" \
105 "continue to second instance watchpoint, second time"] then {
106 gdb_suppress_tests;
107 }
108
109 # Continue again. We should have a watchpoint go out of scope now
110 if [gdb_test "continue" \
111 "Continuing.*\[Ww\]atchpoint.*deleted.*recurse \\(a=6\\) .*" \
112 "second instance watchpoint deleted when leaving scope"] then {
113 gdb_suppress_tests;
114 }
115
116 # Continue until second set of b (first instance).
117 # 24320 is allowed as the final value for b as that's the value
118 # b would have on systems with 16bit integers.
119 #
120 # We could fix the test program to deal with this too.
121 if [gdb_test "continue" \
122 "Continuing.*\[Ww\]atchpoint.*b.*Old value = 10.*New value = \(3628800|24320\).*return.*" \
123 "continue to first instance watchpoint, second time"] then {
124 gdb_suppress_tests
125 }
126
f3bcedc1
CV
127 # Continue again. We should have a watchpoint go out of scope now.
128 #
129 # The former version expected the test to return to main().
130 # Now it expects the test to return to main or to stop in the
131 # function's epilogue.
132 #
133 # The problem is that gdb needs to (but doesn't) understand
134 # function epilogues in the same way as for prologues.
135 #
136 # If there is no hardware watchpoint (such as a x86 debug register),
137 # then watchpoints are done "the hard way" by single-stepping the
138 # target until the value of the watched variable changes. If you
139 # are single-stepping, you will eventually step into an epilogue.
140 # When you do that, the "top" stack frame may become partially
141 # deconstructed (as when you pop the frame pointer, for instance),
142 # and from that point on, GDB can no longer make sense of the stack.
143 #
144 # A test which stops in the epilogue is trying to determine when GDB
145 # leaves the stack frame in which the watchpoint was created. It does
146 # this basically by watching for the frame pointer to change. When
147 # the frame pointer changes, the test expects to be back in main, but
148 # instead it is still in the epilogue of the callee.
c906108c 149 if [gdb_test "continue" \
f3bcedc1 150 "Continuing.*\[Ww\]atchpoint.*deleted.*\(main \\(\\) \|21.*\}\).*" \
c906108c
SS
151 "first instance watchpoint deleted when leaving scope"] then {
152 gdb_suppress_tests;
153 }
154 }
155 gdb_stop_suppressing_tests;
156}
157
b22a6027
SB
158# Preserve the old timeout, and set a new one that should be
159# sufficient to avoid timing out during this test.
160set oldtimeout $timeout
161set timeout [expr "$timeout + 60"]
162verbose "Timeout is now $timeout seconds" 2
c906108c 163
b22a6027 164recurse_tests
c906108c 165
b22a6027
SB
166# Restore the preserved old timeout value.
167set timeout $oldtimeout
168verbose "Timeout is now $timeout seconds" 2
c906108c 169
This page took 0.749098 seconds and 4 git commands to generate.