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