1# Copyright 2014-2023 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 is part of the gdb testsuite 17 18# The skip_hw_watchpoint_tests checks if watchpoints are supported by the 19# processor. On PowerPC, the check runs a small test program under gdb 20# to determine if the Power processor supports HW watchpoints. The check 21# must be done before starting the test so as to not disrupt the execution 22# of the actual test. 23# Disable hardware watchpoints if the target does not support them. 24 25set skip_hw_watchpoint_tests_p [skip_hw_watchpoint_tests] 26 27standard_testfile 28 29if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { 30 return -1 31} 32 33# Set a watchpoint watching EXPR. 34proc watch { expr } { 35 global decimal 36 37 set expr_re [string_to_regexp $expr] 38 gdb_test "watch $expr" \ 39 "\(Hardware \)?\[Ww\]atchpoint $decimal: $expr_re" 40} 41 42# Continue inferior execution, expecting the watchpoint EXPR to be triggered 43# having old value OLD and new value NEW. 44proc expect_watchpoint { expr old new } { 45 with_test_prefix "$expr: $old->$new" { 46 set expr_re [string_to_regexp $expr] 47 gdb_test "print $expr" "\\$\\d+ = $old\\s" "print expression before" 48 gdb_test "continue" "$expr_re\\s.*Old value = $old\\s+New value = $new\\s.*" 49 gdb_test "print $expr" "\\$\\d+ = $new\\s" "print expression after" 50 } 51} 52 53# Check that -location watchpoints against bitfields trigger properly. 54proc test_watch_location {} { 55 with_test_prefix "-location watch against bitfields" { 56 if {![runto_main]} { 57 return -1 58 } 59 60 watch "-location q.a" 61 watch "-location q.e" 62 expect_watchpoint "q.a" 0 1 63 expect_watchpoint "q.e" 0 5 64 expect_watchpoint "q.a" 1 0 65 expect_watchpoint "q.e" 5 4 66 67 # It'll execute a large amount of code with software watchpoint 68 # enabled, which means GDB will single stepping all the way 69 # through til the inferior exits. Increase the timeout by a 70 # factor of 4. 71 with_timeout_factor 4 { 72 gdb_continue_to_end 73 } 74 } 75} 76 77# Check that regular watchpoints against expressions involving 78# bitfields trigger properly. 79proc test_regular_watch {} { 80 with_test_prefix "regular watch against bitfields" { 81 if {![runto_main]} { 82 return -1 83 } 84 85 watch "q.d + q.f + q.g" 86 expect_watchpoint "q.d + q.f + q.g" 0 4 87 expect_watchpoint "q.d + q.f + q.g" 4 10 88 expect_watchpoint "q.d + q.f + q.g" 10 3 89 expect_watchpoint "q.d + q.f + q.g" 3 2 90 expect_watchpoint "q.d + q.f + q.g" 2 1 91 expect_watchpoint "q.d + q.f + q.g" 1 0 92 93 # It'll execute a large amount of code with software watchpoint 94 # enabled, which means GDB will single stepping all the way 95 # through til the inferior exits. Increase the timeout by a 96 # factor of 4. 97 with_timeout_factor 4 { 98 gdb_continue_to_end 99 } 100 } 101} 102 103# Disable hardware watchpoints if the target does not support them. 104if {$skip_hw_watchpoint_tests_p} { 105 gdb_test_no_output "set can-use-hw-watchpoints 0" "" 106} 107 108test_watch_location 109test_regular_watch 110