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