Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / recurse.exp
CommitLineData
88b9d363 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. (law@cs.utah.edu)
17
c906108c 18
822bd149 19standard_testfile
c906108c 20
5b362f04 21if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
822bd149
TT
22 return -1
23}
c906108c
SS
24
25proc recurse_tests {} {
26
958a4e4c
MS
27 # Disable hardware watchpoints if necessary.
28 if [target_info exists gdb,no_hardware_watchpoints] {
35ec993f 29 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
958a4e4c
MS
30 }
31
c906108c
SS
32 if [runto recurse] then {
33 # First we need to step over the assignment of b, so it has a known
34 # value.
35 gdb_test "next" "if \\(a == 1\\)" "next over b = 0 in first instance"
36 gdb_test "watch b" ".*\[Ww\]atchpoint \[0-9]*: b" \
37 "set first instance watchpoint"
38
39 # Continue until initial set of b.
0ac85db5 40 gdb_test "continue" \
c906108c 41 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 10.*" \
0ac85db5 42 "continue to first instance watchpoint, first time"
c906108c
SS
43
44 # Continue inward for a few iterations
45 gdb_test "continue" "Breakpoint.* recurse \\(a=9\\).*" \
46 "continue to recurse (a = 9)"
47 gdb_test "continue" "Breakpoint.* recurse \\(a=8\\).*" \
48 "continue to recurse (a = 8)"
49 gdb_test "continue" "Breakpoint.* recurse \\(a=7\\).*" \
50 "continue to recurse (a = 7)"
51 gdb_test "continue" "Breakpoint.* recurse \\(a=6\\).*" \
52 "continue to recurse (a = 6)"
53 gdb_test "continue" "Breakpoint.* recurse \\(a=5\\).*" \
54 "continue to recurse (a = 5)"
55
56 # Put a watchpoint on another instance of b
57 # First we need to step over the assignment of b, so it has a known
58 # value.
59 gdb_test "next" "if \\(a == 1\\)" "next over b = 0 in second instance"
60 gdb_test "watch b" ".*\[Ww\]atchpoint \[0-9]*: b" \
61 "set second instance watchpoint"
62
63 # Continue until initial set of b (second instance).
0ac85db5 64 gdb_test "continue" \
c906108c 65 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 5.*"\
0ac85db5 66 "continue to second instance watchpoint, first time"
c906108c
SS
67
68 # Continue inward for a few iterations
69 gdb_test "continue" "Breakpoint.* recurse \\(a=4\\).*" \
70 "continue to recurse (a = 4)"
71 gdb_test "continue" "Breakpoint.* recurse \\(a=3\\).*" \
72 "continue to recurse (a = 3)"
73 gdb_test "continue" "Breakpoint.* recurse \\(a=2\\).*" \
74 "continue to recurse (a = 2)"
75 gdb_test "continue" "Breakpoint.* recurse \\(a=1\\).*" \
76 "continue to recurse (a = 1)"
77
78 # Continue until second set of b (second instance).
0ac85db5 79 gdb_test "continue" \
c906108c 80 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 5.*New value = 120.*return.*" \
0ac85db5 81 "continue to second instance watchpoint, second time"
c906108c
SS
82
83 # Continue again. We should have a watchpoint go out of scope now
0ac85db5 84 gdb_test "continue" \
c906108c 85 "Continuing.*\[Ww\]atchpoint.*deleted.*recurse \\(a=6\\) .*" \
0ac85db5 86 "second instance watchpoint deleted when leaving scope"
c906108c
SS
87
88 # Continue until second set of b (first instance).
89 # 24320 is allowed as the final value for b as that's the value
90 # b would have on systems with 16bit integers.
91 #
92 # We could fix the test program to deal with this too.
0ac85db5 93 gdb_test "continue" \
c906108c 94 "Continuing.*\[Ww\]atchpoint.*b.*Old value = 10.*New value = \(3628800|24320\).*return.*" \
0ac85db5 95 "continue to first instance watchpoint, second time"
c906108c 96
f3bcedc1
CV
97 # Continue again. We should have a watchpoint go out of scope now.
98 #
99 # The former version expected the test to return to main().
100 # Now it expects the test to return to main or to stop in the
101 # function's epilogue.
102 #
103 # The problem is that gdb needs to (but doesn't) understand
104 # function epilogues in the same way as for prologues.
105 #
106 # If there is no hardware watchpoint (such as a x86 debug register),
107 # then watchpoints are done "the hard way" by single-stepping the
108 # target until the value of the watched variable changes. If you
109 # are single-stepping, you will eventually step into an epilogue.
110 # When you do that, the "top" stack frame may become partially
111 # deconstructed (as when you pop the frame pointer, for instance),
112 # and from that point on, GDB can no longer make sense of the stack.
113 #
114 # A test which stops in the epilogue is trying to determine when GDB
115 # leaves the stack frame in which the watchpoint was created. It does
116 # this basically by watching for the frame pointer to change. When
117 # the frame pointer changes, the test expects to be back in main, but
118 # instead it is still in the epilogue of the callee.
0ac85db5 119 gdb_test "continue" \
f3bcedc1 120 "Continuing.*\[Ww\]atchpoint.*deleted.*\(main \\(\\) \|21.*\}\).*" \
0ac85db5 121 "first instance watchpoint deleted when leaving scope"
c906108c 122 }
c906108c
SS
123}
124
b22a6027
SB
125# Preserve the old timeout, and set a new one that should be
126# sufficient to avoid timing out during this test.
127set oldtimeout $timeout
128set timeout [expr "$timeout + 60"]
129verbose "Timeout is now $timeout seconds" 2
c906108c 130
b22a6027 131recurse_tests
c906108c 132
b22a6027
SB
133# Restore the preserved old timeout value.
134set timeout $oldtimeout
135verbose "Timeout is now $timeout seconds" 2
c906108c 136
This page took 3.925727 seconds and 4 git commands to generate.