Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / watchpoint-unaligned.exp
blobd31a9cdc2c8e981ba4d4a9141809b8b7ae4c1ae9
1 # Copyright 2017-2023 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 require allow_hw_watchpoint_tests
22 standard_testfile
23 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
24 return -1
27 if ![runto_main] {
28 return -1
31 gdb_breakpoint [gdb_get_line_number "start_again"] "Breakpoint $decimal at $hex" "start_again"
33 set sizes {1 2 4 8}
34 array set alignedend {1 1 2 2 3 4 4 4 5 8 6 8 7 8 8 8}
36 set rwatch "rwatch"
37 set rwatch_exp "Hardware read watchpoint"
38 if {[istarget "s390*-*-*"]} {
39 # Target does not support this type of hardware watchpoint."
40 set rwatch "watch"
41 set rwatch_exp "Hardware watchpoint"
44 foreach wpsize $sizes {
45 for {set wpoffset 0} {$wpoffset < 8 / $wpsize} {incr wpoffset} {
46 set wpstart [expr $wpoffset * $wpsize]
47 set wpend [expr ($wpoffset + 1) * $wpsize]
48 set wpendaligned $alignedend($wpend)
49 foreach rdsize $sizes {
50 for {set rdoffset 0} {$rdoffset < 8 / $rdsize} {incr rdoffset} {
51 set rdstart [expr $rdoffset * $rdsize]
52 set rdend [expr ($rdoffset + 1) * $rdsize]
53 set expect_hit [expr max ($wpstart, $rdstart) < min ($wpend, $rdend)]
54 set test "$rwatch data.u.size$wpsize\[$wpoffset\]"
55 set wpnum ""
56 gdb_test_multiple $test $test {
57 -re "$rwatch_exp (\[0-9\]+): .*\r\n$gdb_prompt $" {
58 set wpnum $expect_out(1,string)
60 -re "Expression cannot be implemented with read/access watchpoint.\r\n$gdb_prompt $" {
61 if {$wpsize == 8 && [istarget "arm*-*-*"]} {
62 untested $test
63 continue
65 fail $test
68 gdb_test_no_output -nopass "set variable size = $rdsize"
69 gdb_test_no_output -nopass "set variable offset = $rdoffset"
70 set test "continue"
71 set got_hit 0
72 gdb_test_multiple $test $test {
73 -re "$rwatch_exp $wpnum:.*alue = .*\r\n$gdb_prompt $" {
74 set got_hit 1
75 send_gdb "continue\n"
76 exp_continue
78 -re " start_again .*\r\n$gdb_prompt $" {
81 gdb_test_no_output -nopass "delete $wpnum"
82 set test "wp(size=$wpsize offset=$wpoffset) rd(size=$rdsize offset=$rdoffset) expect=$expect_hit"
83 if {$expect_hit == $got_hit} {
84 pass $test
85 } else {
86 # We do not know if we run on a fixed Linux kernel
87 # or not. Report XFAIL only in the FAIL case.
88 if {$expect_hit == 0 && $rdstart < $wpendaligned} {
89 setup_xfail external/20207 "aarch64*-*-linux*"
91 if {!$expect_hit && [expr max ($wpstart / 8, $rdstart / 8) < min (($wpend + 7) / 8, ($rdend + 7) / 8)]} {
92 setup_xfail breakpoints/23131 "powerpc*-*-*"
94 fail $test
101 foreach wpcount {4 7} {
102 array set wpoffset_to_wpnum {}
103 for {set wpoffset 1} {$wpoffset <= $wpcount} {incr wpoffset} {
104 set test "$rwatch data.u.size1\[$wpoffset\]"
105 set wpnum ""
106 # Initialize the result incase the test fails.
107 set wpoffset_to_wpnum($wpoffset) 0
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 $" {
113 if {$wpoffset > 1} {
114 setup_xfail breakpoints/23131 "powerpc*-*-*"
115 setup_xfail breakpoints/23131 "arm*-*-*"
117 fail $test
121 gdb_test_no_output -nopass "set variable size = 1"
122 gdb_test_no_output -nopass "set variable offset = 1"
123 set test "continue"
124 set got_hit 0
125 gdb_test_multiple $test $test {
126 -re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
128 -re "$rwatch_exp $wpoffset_to_wpnum(1):.*alue = .*\r\n$gdb_prompt $" {
129 set got_hit 1
130 send_gdb "continue\n"
131 exp_continue
133 -re " start_again .*\r\n$gdb_prompt $" {
136 for {set wpoffset 1} {$wpoffset <= $wpcount} {incr wpoffset} {
137 if {$wpoffset_to_wpnum($wpoffset)} {
138 gdb_test_no_output "delete $wpoffset_to_wpnum($wpoffset)" ""
141 set test "wpcount($wpcount)"
142 if {!$wpoffset_to_wpnum([expr $wpcount - 1])} {
143 untested $test
144 continue
146 if {$wpcount > 4} {
147 if {![istarget "s390*-*-*"]} {
148 setup_kfail tdep/22389 *-*-*
151 gdb_assert $got_hit $test
154 if ![runto_main] {
155 return -1
157 gdb_breakpoint [gdb_get_line_number "final_return"] "Breakpoint $decimal at $hex" "final_return"
158 set test {watch data.u.size8twice[1]}
159 set wpnum 0
160 gdb_test_multiple $test $test {
161 -re "Hardware watchpoint (\[0-9\]+): .*\r\n$gdb_prompt $" {
162 set wpnum $expect_out(1,string)
163 pass $gdb_test_name
165 -re "Watchpoint (\[0-9\]+): .*\r\n$gdb_prompt $" {
166 if {[istarget "arm*-*-*"]} {
167 untested $gdb_test_name
168 } else {
169 fail $gdb_test_name
173 if {$wpnum} {
174 set test "continue"
175 set got_hit 0
176 gdb_test_multiple $test $test {
177 -re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
179 -re "Hardware watchpoint $wpnum:.*New value = .*\r\n$gdb_prompt $" {
180 set got_hit 1
181 send_gdb "continue\n"
182 exp_continue
184 -re " final_return .*\r\n$gdb_prompt $" {
187 gdb_assert $got_hit "size8twice write"