1 # Copyright 2014 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
25 if [target_info exists gdb,no_hardware_watchpoints] {
26 unsupported "no target support"
32 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
36 if ![runto_main] then {
37 fail "Can't run to main"
41 # The line we'll be stepping.
42 set srcline [gdb_get_line_number "stepi line"]
44 # The address the program is stopped at currently.
54 gdb_test_multiple "p /x \$pc" "$test" {
55 -re " = ($hex).*$gdb_prompt $" {
56 set addr $expect_out(1,string)
65 # Issue a stepi, and make sure the program advanced past the current
66 # instruction (stored in the CUR_ADDR global).
69 global hex gdb_prompt cur_addr
71 set srcline " for (i = 0; i < 100000; i++); /* stepi line */"
72 set test "stepi advanced"
73 gdb_test_multiple "stepi" $test {
74 -re "($hex).*[string_to_regexp $srcline]\r\n$gdb_prompt $" {
75 set addr $expect_out(1,string)
76 if {$addr != $cur_addr} {
86 gdb_breakpoint $srcline
87 gdb_continue_to_breakpoint "stepi line"
89 # The test tries various sequences of different types of watchpoints.
90 # Probe for support first.
92 # So we get an immediate warning/error if the target doesn't support a
93 # given watchpoint type.
94 gdb_test_no_output "set breakpoint always-inserted on"
96 # The list of supported commands. Below we'll probe for support and
97 # add elements to this list.
100 foreach cmd {"watch" "awatch" "rwatch"} {
102 gdb_test_multiple "$cmd buf.byte\[0\]" $test {
103 -re "You may have requested too many.*$gdb_prompt $" {
106 -re "Target does not support.*$gdb_prompt $" {
109 -re "$gdb_prompt $" {
119 gdb_test_multiple "hbreak main" $test {
120 -re "You may have requested too many.*$gdb_prompt $" {
123 -re "No hardware breakpoint support.*$gdb_prompt $" {
126 -re "$gdb_prompt $" {
128 lappend cmds "hbreak"
134 set cur_addr [get_pc]
136 # Watch WIDTH bytes at BASE + OFFSET. CMD specifices the specific
137 # type of watchpoint to use. If CMD is "hbreak", WIDTH is ignored.
139 proc watch_command {cmd base offset width} {
140 global srcfile srcline hex
142 if {$cmd == "hbreak"} {
143 set expr "*(buf.byte + $base + $offset)"
144 gdb_test "hbreak $expr" "Hardware assisted breakpoint \[0-9\]+ at $hex"
145 } elseif {$cmd == "watch"} {
146 set expr "*(buf.byte + $base + $offset)@$width"
147 gdb_test "$cmd $expr" \
148 "Hardware watchpoint \[0-9\]+: [string_to_regexp $expr]"
149 } elseif {$cmd == "awatch"} {
150 set expr "*(buf.byte + $base + $offset)@$width"
151 gdb_test "$cmd $expr" \
152 "Hardware access \\(read/write\\) watchpoint \[0-9\]+: [string_to_regexp $expr]"
153 } elseif {$cmd == "rwatch"} {
154 set expr "*(buf.byte + $base + $offset)@$width"
155 gdb_test "$cmd $expr" \
156 "Hardware read watchpoint \[0-9\]+: [string_to_regexp $expr]"
160 # Run test proper. See intro for description.
162 foreach always_inserted {"off" "on" } {
163 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
166 for {set width 1} {$width < 4} {incr width} {
168 if {$cmd1 == "hbreak" && $cmd2 == "hbreak" && $width > 1} {
169 # hbreak ignores WIDTH, no use testing more than
174 for {set x 0} {$x < 4} {incr x} {
175 set prefix "always-inserted $always_inserted: "
176 append prefix "$cmd1 x $cmd2: "
177 with_test_prefix "$prefix: width $width, iter $x" {
178 with_test_prefix "base + 0" {
179 watch_command $cmd1 $x 0 $width
181 gdb_test_no_output "delete \$bpnum"
183 with_test_prefix "base + 1" {
184 watch_command $cmd2 $x 1 $width
186 gdb_test_no_output "delete \$bpnum"