]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/recurse.exp
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / recurse.exp
1 # Copyright 1992-2024 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This file was written by Jeff Law. (law@cs.utah.edu)
17
18 # The allow_hw_watchpoint_tests checks if watchpoints are supported by the
19 # processor. On PowerPC, the check runs a small test program under gdb
20 # to determine if the Power processor supports HW watchpoints. The check
21 # must be done before starting the test so as to not disrupt the execution
22 # of the actual test.
23
24 set allow_hw_watchpoint_tests_p [allow_hw_watchpoint_tests]
25
26 standard_testfile
27
28 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
29 return -1
30 }
31
32 proc recurse_tests {} {
33
34 # Disable hardware watchpoints if necessary.
35 global allow_hw_watchpoint_tests_p
36
37 if {!$allow_hw_watchpoint_tests_p} {
38 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
39 }
40
41 if {[runto recurse]} {
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 gdb_test "continue" \
50 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 10.*" \
51 "continue to first instance watchpoint, first time"
52
53 # Continue inward for a few iterations
54 gdb_test "continue" "Breakpoint.* recurse \\(a=9\\).*" \
55 "continue to recurse (a = 9)"
56 gdb_test "continue" "Breakpoint.* recurse \\(a=8\\).*" \
57 "continue to recurse (a = 8)"
58 gdb_test "continue" "Breakpoint.* recurse \\(a=7\\).*" \
59 "continue to recurse (a = 7)"
60 gdb_test "continue" "Breakpoint.* recurse \\(a=6\\).*" \
61 "continue to recurse (a = 6)"
62 gdb_test "continue" "Breakpoint.* recurse \\(a=5\\).*" \
63 "continue to recurse (a = 5)"
64
65 # Put a watchpoint on another instance of b
66 # First we need to step over the assignment of b, so it has a known
67 # value.
68 gdb_test "next" "if \\(a == 1\\)" "next over b = 0 in second instance"
69 gdb_test "watch b" ".*\[Ww\]atchpoint \[0-9]*: b" \
70 "set second instance watchpoint"
71
72 # Continue until initial set of b (second instance).
73 gdb_test "continue" \
74 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 5.*"\
75 "continue to second instance watchpoint, first time"
76
77 # Continue inward for a few iterations
78 gdb_test "continue" "Breakpoint.* recurse \\(a=4\\).*" \
79 "continue to recurse (a = 4)"
80 gdb_test "continue" "Breakpoint.* recurse \\(a=3\\).*" \
81 "continue to recurse (a = 3)"
82 gdb_test "continue" "Breakpoint.* recurse \\(a=2\\).*" \
83 "continue to recurse (a = 2)"
84 gdb_test "continue" "Breakpoint.* recurse \\(a=1\\).*" \
85 "continue to recurse (a = 1)"
86
87 # Continue until second set of b (second instance).
88 gdb_test "continue" \
89 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 5.*New value = 120.*return.*" \
90 "continue to second instance watchpoint, second time"
91
92 # Continue again. We should have a watchpoint go out of scope now
93 gdb_test "continue" \
94 "Continuing.*\[Ww\]atchpoint.*deleted.*recurse \\(a=6\\) .*" \
95 "second instance watchpoint deleted when leaving scope"
96
97 # Continue until second set of b (first instance).
98 # 24320 is allowed as the final value for b as that's the value
99 # b would have on systems with 16bit integers.
100 #
101 # We could fix the test program to deal with this too.
102 gdb_test "continue" \
103 "Continuing.*\[Ww\]atchpoint.*b.*Old value = 10.*New value = \(3628800|24320\).*return.*" \
104 "continue to first instance watchpoint, second time"
105
106 # Continue again. We should have a watchpoint go out of scope now.
107 #
108 # The former version expected the test to return to main().
109 # Now it expects the test to return to main or to stop in the
110 # function's epilogue.
111 #
112 # The problem is that gdb needs to (but doesn't) understand
113 # function epilogues in the same way as for prologues.
114 #
115 # If there is no hardware watchpoint (such as a x86 debug register),
116 # then watchpoints are done "the hard way" by single-stepping the
117 # target until the value of the watched variable changes. If you
118 # are single-stepping, you will eventually step into an epilogue.
119 # When you do that, the "top" stack frame may become partially
120 # deconstructed (as when you pop the frame pointer, for instance),
121 # and from that point on, GDB can no longer make sense of the stack.
122 #
123 # A test which stops in the epilogue is trying to determine when GDB
124 # leaves the stack frame in which the watchpoint was created. It does
125 # this basically by watching for the frame pointer to change. When
126 # the frame pointer changes, the test expects to be back in main, but
127 # instead it is still in the epilogue of the callee.
128 gdb_test "continue" \
129 "Continuing.*\[Ww\]atchpoint.*deleted.*\(main \\(\\) \|21.*\}\).*" \
130 "first instance watchpoint deleted when leaving scope"
131 }
132 }
133
134 # Preserve the old timeout, and set a new one that should be
135 # sufficient to avoid timing out during this test.
136 set oldtimeout $timeout
137 set timeout [expr "$timeout + 60"]
138 verbose "Timeout is now $timeout seconds" 2
139
140 recurse_tests
141
142 # Restore the preserved old timeout value.
143 set timeout $oldtimeout
144 verbose "Timeout is now $timeout seconds" 2
145