1# This testcase is part of GDB, the GNU debugger. 2 3# Copyright 2010-2013 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 was written by Pedro Alves <pedro@codesourcery.com> 19 20# This file is part of the gdb testsuite. 21 22# 23# Tests involving read watchpoints, and other kinds of watchpoints 24# watching the same memory as read watchpoints. 25# 26 27set testfile "watch-read" 28set srcfile ${testfile}.c 29 30if {[skip_hw_watchpoint_access_tests]} { 31 return 0 32} 33 34if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { 35 untested ${testfile}.exp 36 return -1 37} 38 39if { ![runto main] } then { 40 fail "run to main" 41 return 42} 43 44set read_line [gdb_get_line_number "read line" $srcfile] 45 46# Test running to a read of `global', with a read watchpoint set 47# watching it. 48 49gdb_test "rwatch global" \ 50 "Hardware read watchpoint .*: global" \ 51 "set hardware read watchpoint on global variable" 52 53# The first read is on entry to the loop. 54 55gdb_test "continue" \ 56 "read watchpoint .*: global.*.*Value = 0.*in main.*$srcfile:$read_line.*" \ 57 "read watchpoint triggers on first read" 58 59# The second read happens on second loop iteration, after `global' 60# having been incremented. On architectures where gdb has to emulate 61# read watchpoints with access watchpoints, this tests the 62# only-report-if-value-changed logic. On targets that support real 63# read watchpoints, this tests that GDB ignores the watchpoint's old 64# value, knowing that some untrapped write could have changed it, and 65# so reports the read watchpoint unconditionally. 66 67gdb_test "continue" \ 68 "read watchpoint .*: global.*.*Value = 1.*in main.*$srcfile:$read_line.*" \ 69 "read watchpoint triggers on read after value changed" 70 71# The following tests check that when the user sets a write or access 72# watchpoint watching the same memory as a read watchpoint, GDB also 73# applies the only-report-if-value-changed logic even on targets that 74# support real read watchpoints. 75 76# The program should be stopped at the read line. Set a write 77# watchpoint (leaving the read watchpoint) and continue. Only the 78# write watchpoint should be reported as triggering. 79 80gdb_test "watch global" \ 81 "atchpoint .*: global" \ 82 "set write watchpoint on global variable" 83 84gdb_test "continue" \ 85 "atchpoint .*: global.*Old value = 1.*New value = 2.*" \ 86 "write watchpoint triggers" 87 88set exp "" 89set exp "${exp}2.*read watchpoint.*keep y.*global.*breakpoint already hit 2 times.*" 90set exp "${exp}3.*watchpoint.*keep y.*global.*breakpoint already hit 1 time.*" 91gdb_test "info watchpoints" \ 92 "$exp" \ 93 "only write watchpoint triggers when value changes" 94 95# The program is now stopped at the write line. Continuing should 96# stop at the read line, and only the read watchpoint should be 97# reported as triggering. 98 99gdb_test "continue" \ 100 "read watchpoint .*: global.*Value = 2.*in main.*$srcfile:$read_line.*" \ 101 "read watchpoint triggers when value doesn't change, trapping reads and writes" 102 103set exp "" 104set exp "${exp}2.*read watchpoint.*keep y.*global.*breakpoint already hit 3 times.*" 105set exp "${exp}3.*watchpoint.*keep y.*global.*breakpoint already hit 1 time.*" 106gdb_test "info watchpoints" \ 107 "$exp" \ 108 "only read watchpoint triggers when value doesn't change" 109