]> Git Repo - binutils.git/blame - gdb/testsuite/gdb.base/recurse.exp
Automatic date update in version.in
[binutils.git] / gdb / testsuite / gdb.base / recurse.exp
CommitLineData
4a94e368 1# Copyright 1992-2022 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. ([email protected])
17
f760c4f2
CL
18# The skip_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
24set skip_hw_watchpoint_tests_p [skip_hw_watchpoint_tests]
c906108c 25
822bd149 26standard_testfile
c906108c 27
5b362f04 28if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
822bd149
TT
29 return -1
30}
c906108c
SS
31
32proc recurse_tests {} {
33
958a4e4c 34 # Disable hardware watchpoints if necessary.
f760c4f2
CL
35 global skip_hw_watchpoint_tests_p
36
37 if {$skip_hw_watchpoint_tests_p} {
38 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
958a4e4c
MS
39 }
40
65a33d75 41 if {[runto recurse]} {
c906108c
SS
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.
0ac85db5 49 gdb_test "continue" \
c906108c 50 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 10.*" \
0ac85db5 51 "continue to first instance watchpoint, first time"
c906108c
SS
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).
0ac85db5 73 gdb_test "continue" \
c906108c 74 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 5.*"\
0ac85db5 75 "continue to second instance watchpoint, first time"
c906108c
SS
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).
0ac85db5 88 gdb_test "continue" \
c906108c 89 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 5.*New value = 120.*return.*" \
0ac85db5 90 "continue to second instance watchpoint, second time"
c906108c
SS
91
92 # Continue again. We should have a watchpoint go out of scope now
0ac85db5 93 gdb_test "continue" \
c906108c 94 "Continuing.*\[Ww\]atchpoint.*deleted.*recurse \\(a=6\\) .*" \
0ac85db5 95 "second instance watchpoint deleted when leaving scope"
c906108c
SS
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.
0ac85db5 102 gdb_test "continue" \
c906108c 103 "Continuing.*\[Ww\]atchpoint.*b.*Old value = 10.*New value = \(3628800|24320\).*return.*" \
0ac85db5 104 "continue to first instance watchpoint, second time"
c906108c 105
f3bcedc1
CV
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.
0ac85db5 128 gdb_test "continue" \
f3bcedc1 129 "Continuing.*\[Ww\]atchpoint.*deleted.*\(main \\(\\) \|21.*\}\).*" \
0ac85db5 130 "first instance watchpoint deleted when leaving scope"
c906108c 131 }
c906108c
SS
132}
133
b22a6027
SB
134# Preserve the old timeout, and set a new one that should be
135# sufficient to avoid timing out during this test.
136set oldtimeout $timeout
137set timeout [expr "$timeout + 60"]
138verbose "Timeout is now $timeout seconds" 2
c906108c 139
b22a6027 140recurse_tests
c906108c 141
b22a6027
SB
142# Restore the preserved old timeout value.
143set timeout $oldtimeout
144verbose "Timeout is now $timeout seconds" 2
c906108c 145
This page took 5.752761 seconds and 5 git commands to generate.