1# Copyright 2009-2019 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 Pierre Muller. (muller@ics.u-strasbg.fr) 17 18 19standard_testfile 20 21set wp_set 1 22 23if [get_compiler_info] { 24 return -1 25} 26 27if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { 28 return -1 29} 30 31with_test_prefix "before inferior start" { 32 # Ensure that if we turn off hardware watchpoints and set a watch point 33 # before starting the inferior the watchpoint created will not be a 34 # hardware watchpoint. 35 gdb_test_no_output "set can-use-hw-watchpoints 0" "" 36 gdb_test "watch ival1" "Watchpoint \[0-9\]+: ival1" \ 37 "create watchpoint" 38 39 # The next tests are written to match the current state of gdb: access 40 # and read watchpoints require hardware watchpoint support, with this 41 # turned off these can't be created. 42 gdb_test "awatch ival1" \ 43 "Can't set read/access watchpoint when hardware watchpoints are disabled." \ 44 "create access watchpoint" 45 gdb_test "rwatch ival1" \ 46 "Can't set read/access watchpoint when hardware watchpoints are disabled." \ 47 "create read watchpoint" 48} 49 50 # This will turn hardware watchpoints back on and delete the watchpoint 51 # we just created. 52 clean_restart ${binfile} 53 54 # Disable hardware watchpoints if necessary. 55 if [target_info exists gdb,no_hardware_watchpoints] { 56 gdb_test_no_output "set can-use-hw-watchpoints 0" "" 57 } 58 59 runto_main 60 gdb_test "watch ival1" ".*" "" 61 gdb_test "watch ival3" ".*" "" 62 63 set prev_timeout $timeout 64 set timeout 600 65 66 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival1.*Old value = -1.*New value = 0.*ival1 = count; ival2 = count;.*" "watchpoint hit, first time" 67 68 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit, first time" 69 70 # Check that the ival3 hit count is reported correctly 71 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 1 time.*" "watchpoint hit count is 1" 72 73 # Continue until the next change for ival1, from 0 to 1. 74 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival1.*Old value = 0.*New value = 1.*ival1 = count; ival2 = count;.*" "watchpoint ival1 hit, second time" 75 76 # Check that the hit count for ival1 is reported correctly 77 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival1\r\n\[ \t]+breakpoint already hit 2 times.*" "watchpoint ival1 hit count is 2" 78 79 # Continue until the next change for ival3, from 0 to 1. 80 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time" 81 82 # Check that the hit count is reported correctly 83 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 2 times.*" "watchpoint hit count is 2" 84 85 # Continue until the next change, from 1 to 2. 86 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival1.*Old value = 1.*New value = 2.*ival1 = count; ival2 = count;.*" "watchpoint ival1 hit, third time" 87 88 # Check that the hit count is reported correctly 89 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival1\r\n\[ \t]+breakpoint already hit 3 times.*" "watchpoint ival1 hit count is 3" 90 # Disable ival1 watchpoint 91 gdb_test_no_output "disable 2" "" 92 93 # Continue until the next change, from 1 to 2. 94 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time" 95 96 # Check that the hit count is reported correctly 97 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 3 times.*" "watchpoint hit count is 3" 98 99 # Continue until the next change, from 2 to 3. 100 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time" 101 102 # Check that the hit count is reported correctly 103 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 4 times.*" "watchpoint hit count is 4" 104 105 # Continue until the next change, from 3 to 4. 106 # Note that this one is outside the loop. 107 108 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time" 109 110 # Check that the hit count is reported correctly 111 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 5 times.*" "watchpoint hit count is 5" 112 113set timeout $prev_timeout 114