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