watch-read.exp revision 1.9
1# This testcase is part of GDB, the GNU debugger. 2 3# Copyright 2010-2020 Free Software Foundation, Inc. 4 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18# This file is part of the gdb testsuite. 19 20# 21# Tests involving read watchpoints, and other kinds of watchpoints 22# watching the same memory as read watchpoints. 23# 24 25standard_testfile .c 26 27if {[skip_hw_watchpoint_access_tests]} { 28 return 0 29} 30 31if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { 32 return -1 33} 34 35if { ![runto main] } then { 36 fail "run to main" 37 return 38} 39 40set read_line [gdb_get_line_number "read line" $srcfile] 41 42# Test running to a read of `global', with a read watchpoint set 43# watching it. 44 45gdb_test "rwatch global" \ 46 "Hardware read watchpoint .*: global" \ 47 "set hardware read watchpoint on global variable" 48 49# The first read is on entry to the loop. 50 51gdb_test "continue" \ 52 "read watchpoint .*: global.*.*Value = 0.*in main.*$srcfile:$read_line.*" \ 53 "read watchpoint triggers on first read" 54 55# The second read happens on second loop iteration, after `global' 56# having been incremented. On architectures where gdb has to emulate 57# read watchpoints with access watchpoints, this tests the 58# only-report-if-value-changed logic. On targets that support real 59# read watchpoints, this tests that GDB ignores the watchpoint's old 60# value, knowing that some untrapped write could have changed it, and 61# so reports the read watchpoint unconditionally. 62 63gdb_test "continue" \ 64 "read watchpoint .*: global.*.*Value = 1.*in main.*$srcfile:$read_line.*" \ 65 "read watchpoint triggers on read after value changed" 66 67# The following tests check that when the user sets a write or access 68# watchpoint watching the same memory as a read watchpoint, GDB also 69# applies the only-report-if-value-changed logic even on targets that 70# support real read watchpoints. 71 72# The program should be stopped at the read line. Set a write 73# watchpoint (leaving the read watchpoint) and continue. Only the 74# write watchpoint should be reported as triggering. 75 76gdb_test "watch global" \ 77 "atchpoint .*: global" \ 78 "set write watchpoint on global variable" 79 80gdb_test "continue" \ 81 "atchpoint .*: global.*Old value = 1.*New value = 2.*" \ 82 "write watchpoint triggers" 83 84set exp "" 85set exp "${exp}2.*read watchpoint.*keep y.*global.*breakpoint already hit 2 times.*" 86set exp "${exp}3.*watchpoint.*keep y.*global.*breakpoint already hit 1 time.*" 87gdb_test "info watchpoints" \ 88 "$exp" \ 89 "only write watchpoint triggers when value changes" 90 91# The program is now stopped at the write line. Continuing should 92# stop at the read line, and only the read watchpoint should be 93# reported as triggering. 94 95gdb_test "continue" \ 96 "read watchpoint .*: global.*Value = 2.*in main.*$srcfile:$read_line.*" \ 97 "read watchpoint triggers when value doesn't change, trapping reads and writes" 98 99set exp "" 100set exp "${exp}2.*read watchpoint.*keep y.*global.*breakpoint already hit 3 times.*" 101set exp "${exp}3.*watchpoint.*keep y.*global.*breakpoint already hit 1 time.*" 102gdb_test "info watchpoints" \ 103 "$exp" \ 104 "only read watchpoint triggers when value doesn't change" 105