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