1# Copyright 1992-2016 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 19standard_testfile 20 21if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} { 22 untested $testfile.exp 23 return -1 24} 25 26proc recurse_tests {} { 27 28 # Disable hardware watchpoints if necessary. 29 if [target_info exists gdb,no_hardware_watchpoints] { 30 gdb_test_no_output "set can-use-hw-watchpoints 0" "" 31 } 32 33 if [runto recurse] then { 34 # First we need to step over the assignment of b, so it has a known 35 # value. 36 gdb_test "next" "if \\(a == 1\\)" "next over b = 0 in first instance" 37 gdb_test "watch b" ".*\[Ww\]atchpoint \[0-9]*: b" \ 38 "set first instance watchpoint" 39 40 # Continue until initial set of b. 41 if [gdb_test "continue" \ 42 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 10.*" \ 43 "continue to first instance watchpoint, first time"] then { 44 gdb_suppress_tests 45 } 46 47 # Continue inward for a few iterations 48 gdb_test "continue" "Breakpoint.* recurse \\(a=9\\).*" \ 49 "continue to recurse (a = 9)" 50 gdb_test "continue" "Breakpoint.* recurse \\(a=8\\).*" \ 51 "continue to recurse (a = 8)" 52 gdb_test "continue" "Breakpoint.* recurse \\(a=7\\).*" \ 53 "continue to recurse (a = 7)" 54 gdb_test "continue" "Breakpoint.* recurse \\(a=6\\).*" \ 55 "continue to recurse (a = 6)" 56 gdb_test "continue" "Breakpoint.* recurse \\(a=5\\).*" \ 57 "continue to recurse (a = 5)" 58 59 # Put a watchpoint on another instance of b 60 # First we need to step over the assignment of b, so it has a known 61 # value. 62 gdb_test "next" "if \\(a == 1\\)" "next over b = 0 in second instance" 63 gdb_test "watch b" ".*\[Ww\]atchpoint \[0-9]*: b" \ 64 "set second instance watchpoint" 65 66 # Continue until initial set of b (second instance). 67 if [gdb_test "continue" \ 68 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 5.*"\ 69 "continue to second instance watchpoint, first time"] then { 70 gdb_suppress_tests 71 } 72 73 # Continue inward for a few iterations 74 gdb_test "continue" "Breakpoint.* recurse \\(a=4\\).*" \ 75 "continue to recurse (a = 4)" 76 gdb_test "continue" "Breakpoint.* recurse \\(a=3\\).*" \ 77 "continue to recurse (a = 3)" 78 gdb_test "continue" "Breakpoint.* recurse \\(a=2\\).*" \ 79 "continue to recurse (a = 2)" 80 gdb_test "continue" "Breakpoint.* recurse \\(a=1\\).*" \ 81 "continue to recurse (a = 1)" 82 83 # Continue until second set of b (second instance). 84 if [gdb_test "continue" \ 85 "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 5.*New value = 120.*return.*" \ 86 "continue to second instance watchpoint, second time"] then { 87 gdb_suppress_tests 88 } 89 90 # Continue again. We should have a watchpoint go out of scope now 91 if [gdb_test "continue" \ 92 "Continuing.*\[Ww\]atchpoint.*deleted.*recurse \\(a=6\\) .*" \ 93 "second instance watchpoint deleted when leaving scope"] then { 94 gdb_suppress_tests 95 } 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 if [gdb_test "continue" \ 103 "Continuing.*\[Ww\]atchpoint.*b.*Old value = 10.*New value = \(3628800|24320\).*return.*" \ 104 "continue to first 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 # 110 # The former version expected the test to return to main(). 111 # Now it expects the test to return to main or to stop in the 112 # function's epilogue. 113 # 114 # The problem is that gdb needs to (but doesn't) understand 115 # function epilogues in the same way as for prologues. 116 # 117 # If there is no hardware watchpoint (such as a x86 debug register), 118 # then watchpoints are done "the hard way" by single-stepping the 119 # target until the value of the watched variable changes. If you 120 # are single-stepping, you will eventually step into an epilogue. 121 # When you do that, the "top" stack frame may become partially 122 # deconstructed (as when you pop the frame pointer, for instance), 123 # and from that point on, GDB can no longer make sense of the stack. 124 # 125 # A test which stops in the epilogue is trying to determine when GDB 126 # leaves the stack frame in which the watchpoint was created. It does 127 # this basically by watching for the frame pointer to change. When 128 # the frame pointer changes, the test expects to be back in main, but 129 # instead it is still in the epilogue of the callee. 130 if [gdb_test "continue" \ 131 "Continuing.*\[Ww\]atchpoint.*deleted.*\(main \\(\\) \|21.*\}\).*" \ 132 "first instance watchpoint deleted when leaving scope"] then { 133 gdb_suppress_tests 134 } 135 } 136 gdb_stop_suppressing_tests 137} 138 139# Preserve the old timeout, and set a new one that should be 140# sufficient to avoid timing out during this test. 141set oldtimeout $timeout 142set timeout [expr "$timeout + 60"] 143verbose "Timeout is now $timeout seconds" 2 144 145recurse_tests 146 147# Restore the preserved old timeout value. 148set timeout $oldtimeout 149verbose "Timeout is now $timeout seconds" 2 150 151