1 # Copyright 2017-2022 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite.
18 # Test inserting read watchpoints on unaligned addresses.
20 if {[skip_hw_watchpoint_tests]} {
25 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
33 gdb_breakpoint [gdb_get_line_number "start_again"] "Breakpoint $decimal at $hex" "start_again"
36 array set alignedend {1 1 2 2 3 4 4 4 5 8 6 8 7 8 8 8}
39 set rwatch_exp "Hardware read watchpoint"
40 if {[istarget "s390*-*-*"]} {
41 # Target does not support this type of hardware watchpoint."
43 set rwatch_exp "Hardware watchpoint"
46 foreach wpsize $sizes {
47 for {set wpoffset 0} {$wpoffset < 8 / $wpsize} {incr wpoffset} {
48 set wpstart [expr $wpoffset * $wpsize]
49 set wpend [expr ($wpoffset + 1) * $wpsize]
50 set wpendaligned $alignedend($wpend)
51 foreach rdsize $sizes {
52 for {set rdoffset 0} {$rdoffset < 8 / $rdsize} {incr rdoffset} {
53 set rdstart [expr $rdoffset * $rdsize]
54 set rdend [expr ($rdoffset + 1) * $rdsize]
55 set expect_hit [expr max ($wpstart, $rdstart) < min ($wpend, $rdend)]
56 set test "$rwatch data.u.size$wpsize\[$wpoffset\]"
58 gdb_test_multiple $test $test {
59 -re "$rwatch_exp (\[0-9\]+): .*\r\n$gdb_prompt $" {
60 set wpnum $expect_out(1,string)
62 -re "Expression cannot be implemented with read/access watchpoint.\r\n$gdb_prompt $" {
63 if {$wpsize == 8 && [istarget "arm*-*-*"]} {
70 gdb_test_no_output -nopass "set variable size = $rdsize"
71 gdb_test_no_output -nopass "set variable offset = $rdoffset"
74 gdb_test_multiple $test $test {
75 -re "$rwatch_exp $wpnum:.*alue = .*\r\n$gdb_prompt $" {
80 -re " start_again .*\r\n$gdb_prompt $" {
83 gdb_test_no_output -nopass "delete $wpnum"
84 set test "wp(size=$wpsize offset=$wpoffset) rd(size=$rdsize offset=$rdoffset) expect=$expect_hit"
85 if {$expect_hit == $got_hit} {
88 # We do not know if we run on a fixed Linux kernel
89 # or not. Report XFAIL only in the FAIL case.
90 if {$expect_hit == 0 && $rdstart < $wpendaligned} {
91 setup_xfail external/20207 "aarch64*-*-linux*"
93 if {!$expect_hit && [expr max ($wpstart / 8, $rdstart / 8) < min (($wpend + 7) / 8, ($rdend + 7) / 8)]} {
94 setup_xfail breakpoints/23131 "powerpc*-*-*"
103 foreach wpcount {4 7} {
104 array set wpoffset_to_wpnum {}
105 for {set wpoffset 1} {$wpoffset <= $wpcount} {incr wpoffset} {
106 set test "$rwatch data.u.size1\[$wpoffset\]"
108 gdb_test_multiple $test $test {
109 -re "$rwatch_exp (\[0-9\]+): .*\r\n$gdb_prompt $" {
110 set wpoffset_to_wpnum($wpoffset) $expect_out(1,string)
112 -re "There are not enough available hardware resources for this watchpoint.\r\n$gdb_prompt $" {
114 setup_xfail breakpoints/23131 "powerpc*-*-*"
115 setup_xfail breakpoints/23131 "arm*-*-*"
118 set wpoffset_to_wpnum($wpoffset) 0
122 gdb_test_no_output -nopass "set variable size = 1"
123 gdb_test_no_output -nopass "set variable offset = 1"
126 gdb_test_multiple $test $test {
127 -re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
129 -re "$rwatch_exp $wpoffset_to_wpnum(1):.*alue = .*\r\n$gdb_prompt $" {
131 send_gdb "continue\n"
134 -re " start_again .*\r\n$gdb_prompt $" {
137 for {set wpoffset 1} {$wpoffset <= $wpcount} {incr wpoffset} {
138 if {$wpoffset_to_wpnum($wpoffset)} {
139 gdb_test_no_output "delete $wpoffset_to_wpnum($wpoffset)" ""
142 set test "wpcount($wpcount)"
143 if {!$wpoffset_to_wpnum([expr $wpcount - 1])} {
148 if {![istarget "s390*-*-*"]} {
149 setup_kfail tdep/22389 *-*-*
152 gdb_assert $got_hit $test
158 gdb_breakpoint [gdb_get_line_number "final_return"] "Breakpoint $decimal at $hex" "final_return"
159 set test {watch data.u.size8twice[1]}
161 gdb_test_multiple $test $test {
162 -re "Hardware watchpoint (\[0-9\]+): .*\r\n$gdb_prompt $" {
163 set wpnum $expect_out(1,string)
165 -re "Watchpoint (\[0-9\]+): .*\r\n$gdb_prompt $" {
166 if {[istarget "arm*-*-*"]} {
175 gdb_test_multiple $test $test {
176 -re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
178 -re "Hardware watchpoint $wpnum:.*New value = .*\r\n$gdb_prompt $" {
180 send_gdb "continue\n"
183 -re " final_return .*\r\n$gdb_prompt $" {
186 gdb_assert $got_hit "size8twice write"