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