1 # Copyright
1992, 1994, 1995, 1996, 1997, 1999, 2000
2 # Free Software Foundation
, Inc.
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.
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.
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.
18 # Please email
any bugs
, comments
, and
/or additions to this file to
:
19 # bug
-gdb@prep.ai.mit.edu
21 # This file was written by Jeff Law.
(law@cs.utah.edu
)
30 set testfile
"recurse"
31 set srcfile $
{testfile
}.c
32 set binfile $
{objdir
}/$
{subdir
}/$
{testfile
}
33 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
37 # Start with a fresh gdb.
41 gdb_reinitialize_dir $srcdir
/$subdir
44 proc recurse_tests
{} {
46 # Disable hardware watchpoints
if necessary.
47 if [target_info
exists gdb
,no_hardware_watchpoints
] {
48 gdb_test
"set can-use-hw-watchpoints 0" "" ""
51 if [runto recurse
] then {
52 # First we need to step over the assignment of b
, so it has a known
54 gdb_test
"next" "if \\(a == 1\\)" "next over b = 0 in first instance"
55 gdb_test
"watch b" ".*\[Ww\]atchpoint \[0-9]*: b" \
56 "set first instance watchpoint"
58 #
Continue until initial
set of b.
59 if [gdb_test
"continue" \
60 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 10.*" \
61 "continue to first instance watchpoint, first time"] then {
65 #
Continue inward
for a few iterations
66 gdb_test
"continue" "Breakpoint.* recurse \\(a=9\\).*" \
67 "continue to recurse (a = 9)"
68 gdb_test
"continue" "Breakpoint.* recurse \\(a=8\\).*" \
69 "continue to recurse (a = 8)"
70 gdb_test
"continue" "Breakpoint.* recurse \\(a=7\\).*" \
71 "continue to recurse (a = 7)"
72 gdb_test
"continue" "Breakpoint.* recurse \\(a=6\\).*" \
73 "continue to recurse (a = 6)"
74 gdb_test
"continue" "Breakpoint.* recurse \\(a=5\\).*" \
75 "continue to recurse (a = 5)"
77 # Put a watchpoint
on another instance of b
78 # First we need to step over the assignment of b
, so it has a known
80 gdb_test
"next" "if \\(a == 1\\)" "next over b = 0 in second instance"
81 gdb_test
"watch b" ".*\[Ww\]atchpoint \[0-9]*: b" \
82 "set second instance watchpoint"
84 #
Continue until initial
set of b
(second instance
).
85 if [gdb_test
"continue" \
86 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 5.*"\
87 "continue to second instance watchpoint, first time"] then {
91 #
Continue inward
for a few iterations
92 gdb_test
"continue" "Breakpoint.* recurse \\(a=4\\).*" \
93 "continue to recurse (a = 4)"
94 gdb_test
"continue" "Breakpoint.* recurse \\(a=3\\).*" \
95 "continue to recurse (a = 3)"
96 gdb_test
"continue" "Breakpoint.* recurse \\(a=2\\).*" \
97 "continue to recurse (a = 2)"
98 gdb_test
"continue" "Breakpoint.* recurse \\(a=1\\).*" \
99 "continue to recurse (a = 1)"
101 #
Continue until second
set of b
(second instance
).
102 if [gdb_test
"continue" \
103 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 5.*New value = 120.*return.*" \
104 "continue to second instance watchpoint, second time"] then {
108 #
Continue again. We should have a watchpoint go out of scope now
109 if [gdb_test
"continue" \
110 "Continuing.*\[Ww\]atchpoint.*deleted.*recurse \\(a=6\\) .*" \
111 "second instance watchpoint deleted when leaving scope"] then {
115 #
Continue until second
set of b
(first instance
).
116 #
24320 is allowed as the final value
for b as that
's the value
117 # b would have on systems with 16bit integers.
119 # We could fix the test program to deal with this too.
120 if [gdb_test "continue" \
121 "Continuing.*\[Ww\]atchpoint.*b.*Old value = 10.*New value = \(3628800|24320\).*return.*" \
122 "continue to first instance watchpoint, second time"] then {
126 # Continue again. We should have a watchpoint go out of scope now.
128 # The former version expected the test to return to main().
129 # Now it expects the test to return to main or to stop in the
130 # function's epilogue.
132 # The problem is that gdb needs to
(but doesn
't) understand
133 # function epilogues in the same way as for prologues.
135 # If there is no hardware watchpoint (such as a x86 debug register),
136 # then watchpoints are done "the hard way" by single-stepping the
137 # target until the value of the watched variable changes. If you
138 # are single-stepping, you will eventually step into an epilogue.
139 # When you do that, the "top" stack frame may become partially
140 # deconstructed (as when you pop the frame pointer, for instance),
141 # and from that point on, GDB can no longer make sense of the stack.
143 # A test which stops in the epilogue is trying to determine when GDB
144 # leaves the stack frame in which the watchpoint was created. It does
145 # this basically by watching for the frame pointer to change. When
146 # the frame pointer changes, the test expects to be back in main, but
147 # instead it is still in the epilogue of the callee.
148 if [gdb_test "continue" \
149 "Continuing.*\[Ww\]atchpoint.*deleted.*\(main \\(\\) \|21.*\}\).*" \
150 "first instance watchpoint deleted when leaving scope"] then {
154 gdb_stop_suppressing_tests;
157 # Preserve the old timeout, and set a new one that should be
158 # sufficient to avoid timing out during this test.
159 set oldtimeout $timeout
160 set timeout [expr "$timeout + 60"]
161 verbose "Timeout is now $timeout seconds" 2
165 # Restore the preserved old timeout value.
166 set timeout $oldtimeout
167 verbose "Timeout is now $timeout seconds" 2