]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/watchpoint-reuse-slot.exp
x86 Linux watchpoints: Couldn't write debug register: Invalid argument.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / watchpoint-reuse-slot.exp
1 # Copyright 2014 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 # 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
23 # trigger.)
24
25 if [target_info exists gdb,no_hardware_watchpoints] {
26 unsupported "no target support"
27 return
28 }
29
30 standard_testfile
31
32 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
33 return -1
34 }
35
36 if ![runto_main] then {
37 fail "Can't run to main"
38 return 0
39 }
40
41 # The line we'll be stepping.
42 set srcline [gdb_get_line_number "stepi line"]
43
44 # The address the program is stopped at currently.
45 set cur_addr ""
46
47 # Get the current PC.
48
49 proc get_pc {} {
50 global hex gdb_prompt
51
52 set addr ""
53 set test "get PC"
54 gdb_test_multiple "p /x \$pc" "$test" {
55 -re " = ($hex).*$gdb_prompt $" {
56 set addr $expect_out(1,string)
57 pass "$test"
58 }
59 }
60
61 return $addr
62 }
63
64
65 # Issue a stepi, and make sure the program advanced past the current
66 # instruction (stored in the CUR_ADDR global).
67
68 proc stepi {} {
69 global hex gdb_prompt cur_addr
70
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} {
77 pass $test
78 } else {
79 fail $test
80 }
81 set cur_addr addr
82 }
83 }
84 }
85
86 gdb_breakpoint $srcline
87 gdb_continue_to_breakpoint "stepi line"
88
89 # The test tries various sequences of different types of watchpoints.
90 # Probe for support first.
91
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"
95
96 # The list of supported commands. Below we'll probe for support and
97 # add elements to this list.
98 set cmds {}
99
100 foreach cmd {"watch" "awatch" "rwatch"} {
101 set test $cmd
102 gdb_test_multiple "$cmd buf.byte\[0\]" $test {
103 -re "You may have requested too many.*$gdb_prompt $" {
104 unsupported $test
105 }
106 -re "$gdb_prompt $" {
107 pass $test
108 lappend cmds $cmd
109 }
110 }
111
112 delete_breakpoints
113 }
114
115 set test "hbreak"
116 gdb_test_multiple "hbreak main" $test {
117 -re "You may have requested too many.*$gdb_prompt $" {
118 pass $test
119 }
120 -re "$gdb_prompt $" {
121 pass $test
122 lappend cmds "hbreak"
123 }
124 }
125
126 delete_breakpoints
127
128 set cur_addr [get_pc]
129
130 # Watch WIDTH bytes at BASE + OFFSET. CMD specifices the specific
131 # type of watchpoint to use. If CMD is "hbreak", WIDTH is ignored.
132
133 proc watch_command {cmd base offset width} {
134 global srcfile srcline hex
135
136 if {$cmd == "hbreak"} {
137 set expr "*(buf.byte + $base + $offset)"
138 gdb_test "hbreak $expr" "Hardware assisted breakpoint \[0-9\]+ at $hex"
139 } elseif {$cmd == "watch"} {
140 set expr "*(buf.byte + $base + $offset)@$width"
141 gdb_test "$cmd $expr" \
142 "Hardware watchpoint \[0-9\]+: [string_to_regexp $expr]"
143 } elseif {$cmd == "awatch"} {
144 set expr "*(buf.byte + $base + $offset)@$width"
145 gdb_test "$cmd $expr" \
146 "Hardware access \\(read/write\\) watchpoint \[0-9\]+: [string_to_regexp $expr]"
147 } elseif {$cmd == "rwatch"} {
148 set expr "*(buf.byte + $base + $offset)@$width"
149 gdb_test "$cmd $expr" \
150 "Hardware read watchpoint \[0-9\]+: [string_to_regexp $expr]"
151 }
152 }
153
154 # Run test proper. See intro for description.
155
156 foreach always_inserted {"off" "on" } {
157 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
158 foreach cmd1 $cmds {
159 foreach cmd2 $cmds {
160 for {set width 1} {$width < 4} {incr width} {
161
162 if {$cmd1 == "hbreak" && $cmd2 == "hbreak" && $width > 1} {
163 # hbreak ignores WIDTH, no use testing more than
164 # once.
165 continue
166 }
167
168 for {set x 0} {$x < 4} {incr x} {
169 set prefix "always-inserted $always_inserted: "
170 append prefix "$cmd1 x $cmd2: "
171 with_test_prefix "$prefix: width $width, iter $x" {
172 with_test_prefix "base + 0" {
173 watch_command $cmd1 $x 0 $width
174 stepi
175 gdb_test_no_output "delete \$bpnum"
176 }
177 with_test_prefix "base + 1" {
178 watch_command $cmd2 $x 1 $width
179 stepi
180 gdb_test_no_output "delete \$bpnum"
181 }
182 }
183 }
184 }
185 }
186 }
187 }