1 # Copyright
2014-2019 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 # Test alternating between watchpoint types
, watching a sliding window
17 # of addresses
(thus alternating between aligned and unaligned
18 # addresses
). Only a single watchpoint
exists at
any given time.
On
19 # targets that only
update the debug registers
on resume
, this
20 # stresses the debug register setup code
, both in GDB and in the
21 # target
/kernel as one watchpoint replaces the other in a single
22 # operation.
(Note that we don
't have any of these watchpoints
27 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
31 if ![runto_main] then {
32 fail "can't run to main
"
36 # The line we
'll be stepping.
37 set srcline [gdb_get_line_number "stepi line"]
39 # The address the program is stopped at currently.
49 gdb_test_multiple "p /x \$pc" "$test" {
50 -re " = ($hex).*$gdb_prompt $" {
51 set addr $expect_out(1,string)
60 # Issue a stepi, and make sure the program advanced past the current
61 # instruction (stored in the CUR_ADDR global).
64 global hex gdb_prompt cur_addr
66 set srcline " for (i = 0; i < 100000; i++); /* stepi line */"
67 set test "stepi advanced"
68 gdb_test_multiple "stepi" $test {
69 -re "($hex).*[string_to_regexp $srcline]\r\n$gdb_prompt $" {
70 set addr $expect_out(1,string)
71 if {$addr != $cur_addr} {
81 gdb_breakpoint $srcline
82 gdb_continue_to_breakpoint "stepi line"
85 # The test tries various sequences of different types of watchpoints.
86 # Probe for support first.
87 proc build_cmds_list {} {
90 # So we get an immediate warning/error if the target doesn't support a
91 # given watchpoint type.
92 gdb_test_no_output
"set breakpoint always-inserted on" \
93 "Set breakpoints always inserted while building cmds list"
95 # The list of supported commands. Below we
'll probe for support and
96 # add elements to this list.
99 foreach cmd {"watch" "awatch" "rwatch"} {
101 gdb_test_multiple "$cmd buf.byte\[0\]" $test {
102 -re "You may have requested too many.*$gdb_prompt $" {
105 -re "Target does not support.*$gdb_prompt $" {
108 -re "Can't
set read
/access watchpoint when hardware watchpoints are disabled.
*$gdb_prompt $
" {
111 -re
"$gdb_prompt $" {
121 gdb_test_multiple
"hbreak main" $test {
122 -re
"You may have requested too many.*$gdb_prompt $" {
125 -re
"No hardware breakpoint support.*$gdb_prompt $" {
128 -re
"$gdb_prompt $" {
130 lappend cmds
"hbreak"
139 #
Return true
if the memory range
[buf.byte
+ OFFSET
, +WIDTH
] can be
140 # monitored by CMD
, otherwise
return false.
142 proc valid_addr_p
{cmd offset width
} {
144 if { [istarget
"aarch64*-*-linux*"] } {
145 # The aarch64 Linux kernel port only accepts
4-byte aligned addresses
146 #
for hardware breakpoints and
8-byte aligned addresses
for hardware
147 # watchpoints. However
, both GDB and GDBserver support unaligned
148 # watchpoints by using more than one properly aligned watchpoint
149 # registers to represent the whole unaligned region. Breakpoint
150 # addresses must still be aligned though.
151 if {$cmd
== "hbreak" } {
152 if { [expr
($offset
) % 4] != 0 } {
156 } elseif
{ [istarget
"arm*-*-linux*"] } {
157 if { $cmd
== "hbreak" } {
158 # Breakpoints must be of length
2 (thumb
) or
4 (ARM
) bytes.
159 if { $width
!= 2 && $width
!= 4 } {
163 # Watchpoints can be of length
1, 2, 4 or
8 bytes.
164 if { [expr $width
% 2] != 0 } {
169 if { [expr
($offset
) % 8] == 0 && $width
== 8 } {
170 #
If WIDTH is
8 byte
, the address should be
8-byte aligned.
172 } elseif
{ [expr
($offset
) % 4] == 0 } {
174 } elseif
{ [expr
($offset
) % 4] == 2 && $width
== 2 } {
175 # Halfword watchpoints and breakpoints.
177 } elseif
{ [expr
($offset
) % 4] == 1 && $width
== 1 && $cmd
!= "hbreak" } {
178 # Single byte watchpoints.
188 #
Watch WIDTH bytes at BASE
+ OFFSET. CMD specifices the specific
189 # type of watchpoint to use.
If CMD is
"hbreak", WIDTH is ignored.
190 # The HW_WP_P flag tells us
if hardware watchpoints are enabled or
193 proc watch_command
{cmd base offset width hw_wp_p
} {
194 global srcfile srcline hex
196 if {$cmd
== "hbreak"} {
197 set expr
"*(buf.byte + $base + $offset)"
198 gdb_test
"hbreak $expr" "Hardware assisted breakpoint \[0-9\]+ at $hex"
199 } elseif
{$cmd
== "watch"} {
200 set expr
"*(buf.byte + $base + $offset)@$width"
203 set wp_prefix
"Watchpoint"
205 set wp_prefix
"Hardware watchpoint"
208 gdb_test
"$cmd $expr" \
209 "${wp_prefix} \[0-9\]+: [string_to_regexp $expr]"
210 } elseif
{$cmd
== "awatch"} {
211 set expr
"*(buf.byte + $base + $offset)@$width"
212 gdb_test
"$cmd $expr" \
213 "Hardware access \\(read/write\\) watchpoint \[0-9\]+: [string_to_regexp $expr]"
214 } elseif
{$cmd
== "rwatch"} {
215 set expr
"*(buf.byte + $base + $offset)@$width"
216 gdb_test
"$cmd $expr" \
217 "Hardware read watchpoint \[0-9\]+: [string_to_regexp $expr]"
221 # Run the watchpoint tests
(see the description at the top
for details
), the
222 # HW_WP_P flag tells us
if hardware watchpoints are enabled or not.
223 proc run_watchpoints_tests
{hw_wp_p
} {
225 set cmds
[build_cmds_list
]
227 foreach always_inserted
{"off" "on" } {
228 gdb_test_no_output
"set breakpoint always-inserted $always_inserted"
231 for {set width
1} {$width
< 4} {incr width
} {
233 if {$cmd1
== "hbreak" && $cmd2 == "hbreak" \
235 # hbreak ignores WIDTH
, no use testing more than
240 for {set x
0} {$x
< 4} {incr x
} {
242 if { ![valid_addr_p $cmd1 $x $width
]
243 ||
![valid_addr_p $cmd2 $x
+1 $width
] } {
244 # Skip tests
if requested address or length
245 # of breakpoint or watchpoint don
't meet
246 # target or kernel requirements.
250 set prefix "always-inserted $always_inserted: "
251 append prefix "$cmd1 x $cmd2: "
252 with_test_prefix "$prefix: width $width, iter $x" {
253 with_test_prefix "base + 0" {
254 watch_command $cmd1 $x 0 $width $hw_wp_p
256 gdb_test_no_output "delete \$bpnum"
258 with_test_prefix "base + 1" {
259 watch_command $cmd2 $x 1 $width $hw_wp_p
261 gdb_test_no_output "delete \$bpnum"
271 # Based on HW_WP_P set whether hardware watchpoints can be used or
272 # not, then call RUN_WATCHPOINTS_TESTS.
273 proc setup_and_run_watchpoints_tests { hw_wp_p } {
275 set prefix "hw-watch"
277 set prefix "sw-watch"
280 with_test_prefix $prefix {
281 gdb_test_no_output "set can-use-hw-watchpoints ${hw_wp_p}"
283 run_watchpoints_tests $hw_wp_p
287 # Run tests with hardware watchpoints disabled, then again with them
288 # enabled (if this target supports hardware watchpoints).
289 if { ![target_info exists gdb,no_hardware_watchpoints]} {
290 # Run test with H/W enabled.
291 setup_and_run_watchpoints_tests 1
294 # Run test with H/W disabled
295 setup_and_run_watchpoints_tests 0