Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1992-2020 Free Software Foundation, Inc. |
c906108c SS |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
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. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | # This file was written by Fred Fish. (fnf@cygnus.com) |
17 | ||
c906108c | 18 | |
62cef515 | 19 | standard_testfile |
c906108c | 20 | |
4c93b1db | 21 | if [get_compiler_info] { |
c906108c SS |
22 | return -1 |
23 | } | |
24 | ||
c906108c | 25 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
84c93cd5 | 26 | untested "failed to compile" |
b60f0898 | 27 | return -1 |
c906108c SS |
28 | } |
29 | ||
4b3c9f41 PA |
30 | # True if we're forcing no hardware watchpoints. |
31 | set no_hw 0 | |
32 | ||
c906108c SS |
33 | # Prepare for watchpoint tests by setting up two breakpoints and one |
34 | # watchpoint. | |
35 | # | |
36 | # We use breakpoints at marker functions to get past all the startup code, | |
37 | # so we can get to the watchpoints in a reasonable amount of time from a | |
38 | # known starting point. | |
39 | # | |
40 | # For simplicity, so we always know how to reference specific breakpoints or | |
41 | # watchpoints by number, we expect a particular ordering and numbering of | |
42 | # each in the combined breakpoint/watchpoint table, as follows: | |
43 | # | |
44 | # Number What Where | |
45 | # 1 Breakpoint marker1() | |
46 | # 2 Breakpoint marker2() | |
47 | # 3 Watchpoint ival3 | |
48 | ||
49 | proc initialize {} { | |
50 | global gdb_prompt | |
51 | global hex | |
52 | global decimal | |
53 | global srcfile | |
54 | ||
55 | if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] { | |
ae59b1da | 56 | return 0 |
c906108c SS |
57 | } |
58 | ||
59 | ||
60 | if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] { | |
ae59b1da | 61 | return 0 |
c906108c SS |
62 | } |
63 | ||
64 | ||
65 | if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] { | |
ae59b1da | 66 | return 0 |
c906108c SS |
67 | } |
68 | ||
100aa3ae | 69 | gdb_test "watch ival3" ".*\[Ww\]atchpoint 3: ival3.*" "set watchpoint on ival3" |
c906108c | 70 | |
d77f58be | 71 | if [gdb_test "info watch" "3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] { |
ae59b1da | 72 | return 0 |
c906108c SS |
73 | } |
74 | ||
75 | ||
76 | # After installing the watchpoint, we disable it until we are ready | |
77 | # to use it. This allows the test program to run at full speed until | |
78 | # we get to the first marker function. | |
79 | ||
80 | if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] { | |
ae59b1da | 81 | return 0 |
c906108c SS |
82 | } |
83 | ||
84 | ||
85 | return 1 | |
86 | } | |
87 | ||
88 | # | |
89 | # Test simple watchpoint. | |
90 | # | |
91 | ||
92 | proc test_simple_watchpoint {} { | |
93 | global gdb_prompt | |
94 | global hex | |
95 | global decimal | |
96 | ||
97 | # Ensure that the watchpoint is disabled when we startup. | |
98 | ||
100aa3ae | 99 | if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] { |
ae59b1da | 100 | return 0 |
c906108c SS |
101 | } |
102 | ||
c906108c SS |
103 | # Run until we get to the first marker function. |
104 | ||
105 | gdb_run_cmd | |
106 | set timeout 600 | |
4033a6bf PA |
107 | set test "run to marker1 in test_simple_watchpoint" |
108 | set retcode [gdb_test_multiple "" $test { | |
c906108c | 109 | -re "Breakpoint 1, marker1 .*$gdb_prompt $" { |
4033a6bf | 110 | pass $test |
c906108c | 111 | } |
4033a6bf PA |
112 | }] |
113 | ||
114 | if { $retcode != 0 } { | |
115 | return | |
c906108c SS |
116 | } |
117 | ||
118 | # After reaching the marker function, enable the watchpoint. | |
119 | ||
120 | if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] { | |
ae59b1da | 121 | return |
c906108c SS |
122 | } |
123 | ||
124 | ||
125 | gdb_test "break func1" "Breakpoint.*at.*" | |
27d3a1a2 | 126 | gdb_test_no_output "set \$func1_breakpoint_number = \$bpnum" |
c906108c SS |
127 | |
128 | gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \ | |
129 | "continue to breakpoint at func1" | |
130 | ||
131 | # Continue until the first change, from -1 to 0 | |
132 | ||
4033a6bf PA |
133 | set test "watchpoint hit, first time" |
134 | gdb_test_multiple "cont" $test { | |
c906108c | 135 | -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" { |
4033a6bf | 136 | pass $test |
c906108c SS |
137 | } |
138 | -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" { | |
139 | setup_xfail "m68*-*-*" 2597 | |
140 | fail "thought it hit breakpoint at func1 twice" | |
27d3a1a2 | 141 | gdb_test_no_output "delete \$func1_breakpoint_number" |
c906108c SS |
142 | gdb_test "continue" "\ |
143 | Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \ | |
4033a6bf | 144 | $test |
c906108c | 145 | } |
c906108c SS |
146 | } |
147 | ||
c2d11a7d | 148 | # Check that the hit count is reported correctly |
cdc7edd7 | 149 | gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 1 time.*" "watchpoint hit count is 1" |
c2d11a7d | 150 | |
27d3a1a2 | 151 | gdb_test_no_output "delete \$func1_breakpoint_number" |
c906108c SS |
152 | |
153 | # Continue until the next change, from 0 to 1. | |
154 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time" | |
155 | ||
c2d11a7d | 156 | # Check that the hit count is reported correctly |
cdc7edd7 | 157 | gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 2 times.*" "watchpoint hit count is 2" |
c2d11a7d | 158 | |
c906108c SS |
159 | # Continue until the next change, from 1 to 2. |
160 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time" | |
c2d11a7d JM |
161 | |
162 | # Check that the hit count is reported correctly | |
cdc7edd7 | 163 | gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 3 times.*" "watchpoint hit count is 3" |
c906108c SS |
164 | |
165 | # Continue until the next change, from 2 to 3. | |
166 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time" | |
167 | ||
c2d11a7d | 168 | # Check that the hit count is reported correctly |
cdc7edd7 | 169 | gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 4 times.*" "watchpoint hit count is 4" |
c2d11a7d | 170 | |
c906108c SS |
171 | # Continue until the next change, from 3 to 4. |
172 | # Note that this one is outside the loop. | |
173 | ||
174 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time" | |
175 | ||
c2d11a7d | 176 | # Check that the hit count is reported correctly |
cdc7edd7 | 177 | gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 5 times.*" "watchpoint hit count is 5" |
c2d11a7d | 178 | |
c906108c SS |
179 | # Continue until we hit the finishing marker function. |
180 | # Make sure we hit no more watchpoints. | |
181 | ||
182 | gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \ | |
183 | "continue to marker2" | |
184 | ||
185 | # Disable the watchpoint so we run at full speed until we exit. | |
186 | ||
187 | if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] { | |
ae59b1da | 188 | return |
c906108c SS |
189 | } |
190 | ||
191 | ||
192 | # Run until process exits. | |
193 | ||
194 | if [target_info exists gdb,noresults] { return } | |
195 | ||
7a292a7a | 196 | gdb_continue_to_end "continue to exit in test_simple_watchpoint" |
c906108c SS |
197 | } |
198 | ||
199 | # Test disabling watchpoints. | |
200 | ||
201 | proc test_disabling_watchpoints {} { | |
202 | global gdb_prompt | |
203 | global binfile | |
204 | global srcfile | |
205 | global decimal | |
206 | global hex | |
207 | ||
e4d63ba2 | 208 | gdb_test "info watch" "\[0-9]+\[ \]*.*watchpoint.*ival3.*" "watchpoints found in watchpoint/breakpoint table" |
085dd6e6 | 209 | |
c906108c SS |
210 | # Ensure that the watchpoint is disabled when we startup. |
211 | ||
212 | if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] { | |
ae59b1da | 213 | return 0 |
c906108c SS |
214 | } |
215 | ||
216 | ||
217 | # Run until we get to the first marker function. | |
218 | ||
219 | gdb_run_cmd | |
220 | set timeout 600 | |
4033a6bf PA |
221 | set test "run to marker1 in test_disabling_watchpoints" |
222 | set retcode [gdb_test_multiple "" $test { | |
c906108c | 223 | -re "Breakpoint 1, marker1 .*$gdb_prompt $" { |
4033a6bf | 224 | pass $test |
c906108c | 225 | } |
4033a6bf PA |
226 | }] |
227 | ||
228 | if { $retcode != 0 } { | |
229 | return | |
c906108c SS |
230 | } |
231 | ||
232 | # After reaching the marker function, enable the watchpoint. | |
233 | ||
234 | if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] { | |
ae59b1da | 235 | return |
c906108c SS |
236 | } |
237 | ||
238 | ||
239 | # Continue until the first change, from -1 to 0 | |
240 | # Don't check the old value, because on VxWorks the variable value | |
241 | # will not have been reinitialized. | |
242 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time" | |
243 | ||
244 | # Continue until the next change, from 0 to 1. | |
245 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, second time" | |
246 | ||
247 | # Disable the watchpoint but leave breakpoints | |
248 | ||
249 | if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] { | |
ae59b1da | 250 | return 0 |
c906108c SS |
251 | } |
252 | ||
253 | ||
254 | # Check watchpoint list, looking for the entry that confirms the | |
255 | # watchpoint is disabled. | |
085dd6e6 | 256 | gdb_test "info watchpoints" "\[0-9]+\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table" |
c906108c SS |
257 | |
258 | # Continue until we hit the finishing marker function. | |
259 | # Make sure we hit no more watchpoints. | |
260 | gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \ | |
261 | "disabled watchpoint skipped" | |
262 | ||
263 | if [target_info exists gdb,noresults] { return } | |
264 | ||
7a292a7a | 265 | gdb_continue_to_end "continue to exit in test_disabling_watchpoints" |
c906108c SS |
266 | } |
267 | ||
268 | # Test stepping and other mundane operations with watchpoints enabled | |
269 | proc test_stepping {} { | |
270 | global gdb_prompt | |
271 | ||
272 | if [runto marker1] then { | |
273 | gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2" | |
274 | ||
275 | # Well, let's not be too mundane. It should be a *bit* of a challenge | |
276 | gdb_test "break func2 if 0" "Breakpoint.*at.*" | |
277 | gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*" | |
278 | ||
085dd6e6 | 279 | gdb_test "p func1 ()" "= 73" \ |
4b2b3b3e | 280 | "calling function with watchpoint enabled" |
c906108c SS |
281 | |
282 | # | |
283 | # "finish" brings us back to main. | |
284 | # On some targets (e.g. alpha) gdb will stop from the finish in midline | |
285 | # of the marker1 call. This is due to register restoring code on | |
286 | # the alpha and might be caused by stack adjustment instructions | |
287 | # on other targets. In this case we will step once more. | |
288 | # | |
289 | ||
290 | send_gdb "finish\n" | |
291 | gdb_expect { | |
2df3850c JM |
292 | -re "Run.*exit from.*marker1.* at" { |
293 | pass "finish from marker1" | |
294 | } | |
dfcd3bfb | 295 | default { fail "finish from marker1 (timeout)" ; return } |
c906108c SS |
296 | } |
297 | ||
298 | gdb_expect { | |
299 | -re "marker1 \\(\\);.*$gdb_prompt $" { | |
300 | send_gdb "step\n" | |
301 | exp_continue | |
302 | } | |
303 | -re "func1 \\(\\);.*$gdb_prompt $" { | |
dfcd3bfb | 304 | pass "back at main from marker1" |
c906108c SS |
305 | } |
306 | -re ".*$gdb_prompt $" { | |
dfcd3bfb | 307 | fail "back at main from marker1" |
c906108c | 308 | } |
dfcd3bfb | 309 | default { fail "back at main from marker1 (timeout)" ; return } |
c906108c SS |
310 | } |
311 | ||
312 | gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp" | |
313 | ||
314 | # Now test that "until" works. It's a bit tricky to test | |
315 | # "until", because compilers don't always arrange the code | |
316 | # exactly the same way, and we might get slightly different | |
317 | # sequences of statements. But the following should be true | |
318 | # (if not it is a compiler or a debugger bug): The user who | |
319 | # does "until" at every statement of a loop should end up | |
320 | # stepping through the loop once, and the debugger should not | |
321 | # stop for any of the remaining iterations. | |
322 | ||
323 | gdb_test "until" "ival1 = count.*" "until to ival1 assignment" | |
324 | gdb_test "until" "ival3 = count.*" "until to ival3 assignment" | |
4033a6bf PA |
325 | set test "until out of loop" |
326 | gdb_test_multiple "until" $test { | |
c906108c | 327 | -re "(for \\(count = 0|\}).*$gdb_prompt $" { |
4033a6bf | 328 | gdb_test "until" "ival1 = count; /. Outside loop ./" $test |
c906108c SS |
329 | } |
330 | -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" { | |
4033a6bf | 331 | pass $test |
c906108c | 332 | } |
c906108c SS |
333 | } |
334 | ||
335 | gdb_test "step" "ival2 = count.*" "step to ival2 assignment" | |
336 | } | |
337 | } | |
338 | ||
339 | # Test stepping and other mundane operations with watchpoints enabled | |
340 | proc test_watchpoint_triggered_in_syscall {} { | |
341 | global gdb_prompt | |
342 | ||
958a4e4c MS |
343 | # These tests won't work without printf support. |
344 | if [gdb_skip_stdio_test "watchpoints triggered in syscall"] { | |
4ec70201 | 345 | return |
c906108c SS |
346 | } |
347 | # Run until we get to the first marker function. | |
348 | set x 0 | |
349 | set y 0 | |
bc6c7af4 | 350 | set testname "watch buffer passed to read syscall" |
c906108c SS |
351 | if [runto marker2] then { |
352 | gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]" | |
353 | gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]" | |
354 | gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]" | |
355 | gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]" | |
356 | gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]" | |
357 | gdb_test "break marker4" ".*Breakpoint.*" | |
358 | ||
27d3a1a2 | 359 | gdb_test_no_output "set doread = 1" |
c906108c | 360 | |
4033a6bf | 361 | # If we send gdb "123\n" before gdb has switched the tty, then it goes |
c906108c SS |
362 | # to gdb, not the inferior, and we lose. So that is why we have |
363 | # watchpoint.c prompt us, so we can wait for that prompt. | |
02746bbc | 364 | |
4ec70201 | 365 | send_gdb "continue\n" |
c906108c SS |
366 | gdb_expect { |
367 | -re "Continuing\\.\r\ntype stuff for buf now:" { | |
368 | pass "continue to read" | |
369 | } | |
370 | default { | |
4ec70201 | 371 | fail "continue to read" |
ae59b1da | 372 | return |
c906108c SS |
373 | } |
374 | } | |
375 | ||
4033a6bf PA |
376 | set test "sent 123" |
377 | gdb_test_multiple "123" $test { | |
c906108c SS |
378 | -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } |
379 | -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } | |
380 | -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } | |
381 | -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } | |
4033a6bf | 382 | -re ".*$gdb_prompt $" { pass $test } |
c906108c SS |
383 | } |
384 | ||
385 | # Examine the values in buf to see how many watchpoints we | |
386 | # should have printed. | |
4033a6bf PA |
387 | set test "print buf\[0\]" |
388 | gdb_test_multiple $test $test { | |
389 | -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass $test } | |
390 | -re ".*= 0.*$gdb_prompt $" { $test } | |
c906108c | 391 | } |
4033a6bf PA |
392 | set test "print buf\[1\]" |
393 | gdb_test_multiple $test $test { | |
394 | -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass $test } | |
395 | -re ".*= 0.*$gdb_prompt $" { pass $test } | |
c906108c | 396 | } |
4033a6bf PA |
397 | set test "print buf\[2\]" |
398 | gdb_test_multiple $test $test { | |
399 | -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass $test } | |
400 | -re ".*= 0.*$gdb_prompt $" { pass $test } | |
c906108c | 401 | } |
4033a6bf PA |
402 | set test "print buf\[3\]" |
403 | gdb_test_multiple $test $test { | |
404 | -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass $test } | |
405 | -re ".*= 0.*$gdb_prompt $" { pass $test } | |
c906108c SS |
406 | } |
407 | ||
408 | # Did we find what we were looking for? If not, flunk it. | |
409 | if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"} | |
410 | ||
411 | # Continue until we hit the finishing marker function. | |
412 | # Make sure we hit no more watchpoints. | |
413 | gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \ | |
414 | "continue to marker4" | |
415 | ||
416 | # Disable everything so we can finish the program at full speed | |
27d3a1a2 | 417 | gdb_test_no_output "disable" "disable in test_watchpoint_triggered_in_syscall" |
c906108c SS |
418 | |
419 | if [target_info exists gdb,noresults] { return } | |
420 | ||
7a292a7a | 421 | gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall" |
c906108c SS |
422 | } |
423 | } | |
424 | ||
425 | # Do a simple test of of watching through a pointer when the pointer | |
426 | # itself changes. Should add some more complicated stuff here. | |
427 | ||
428 | proc test_complex_watchpoint {} { | |
429 | global gdb_prompt | |
430 | ||
431 | if [runto marker4] then { | |
432 | gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val" | |
433 | gdb_test "break marker5" ".*Breakpoint.*" | |
434 | ||
cdc7edd7 | 435 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "test complex watchpoint" |
c906108c SS |
436 | |
437 | # Continue until we hit the marker5 function. | |
438 | # Make sure we hit no more watchpoints. | |
439 | ||
440 | gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \ | |
441 | "did not trigger wrong watchpoint" | |
442 | ||
085dd6e6 JM |
443 | # Test watches of things declared locally in a function. |
444 | # In particular, test that a watch of stack-based things | |
445 | # is deleted when the stack-based things go out of scope. | |
446 | # | |
96b6697f | 447 | gdb_test_no_output "disable" "disable in test_complex_watchpoint, first time" |
085dd6e6 JM |
448 | gdb_test "break marker6" ".*Breakpoint.*" |
449 | gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \ | |
450 | "continue to marker6" | |
bdddb4de | 451 | gdb_breakpoint [gdb_get_line_number "func2 breakpoint here"] |
96b6697f | 452 | gdb_continue_to_breakpoint "func2 breakpoint here, first time" |
085dd6e6 JM |
453 | |
454 | # Test a watch of a single stack-based variable, whose scope | |
455 | # is the function we're now in. This should auto-delete when | |
456 | # execution exits the scope of the watchpoint. | |
457 | # | |
458 | gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch" | |
459 | gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch" | |
e2de5390 JK |
460 | |
461 | set test "self-delete local watch" | |
462 | gdb_test_multiple "cont" $test { | |
463 | -re "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*\r\n$gdb_prompt $" { | |
464 | pass $test | |
465 | } | |
466 | -re "can't compute CFA for this frame.*\r\n$gdb_prompt $" { | |
a97b16b8 | 467 | global no_hw |
e2de5390 JK |
468 | |
469 | # GCC < 4.5.0 does not get LOCATIONS_VALID set by dwarf2read.c. | |
470 | # Therefore epilogue unwinder gets applied which is | |
471 | # incompatible with dwarf2_frame_cfa. | |
e2de5390 JK |
472 | if {$no_hw && ([test_compiler_info {gcc-[0-3]-*}] |
473 | || [test_compiler_info {gcc-4-[0-4]-*}])} { | |
474 | xfail "$test (old GCC has broken watchpoints in epilogues)" | |
475 | return | |
476 | } | |
477 | fail $test | |
478 | } | |
479 | } | |
085dd6e6 | 480 | |
96b6697f | 481 | gdb_continue_to_breakpoint "func2 breakpoint here, second time" |
085dd6e6 JM |
482 | # We should be in "func2" again now. Test a watch of an |
483 | # expression which includes both a stack-based local and | |
484 | # something whose scope is larger than this invocation | |
485 | # of "func2". This should also auto-delete. | |
486 | # | |
487 | gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \ | |
488 | "set partially local watch" | |
489 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \ | |
490 | "trigger1 partially local watch" | |
491 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \ | |
492 | "trigger2 partially local watch" | |
493 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \ | |
494 | "self-delete partially local watch" | |
495 | ||
496 | # We should be in "func2" again now. Test a watch of a | |
497 | # static (non-stack-based) local. Since this has scope | |
498 | # across any invocations of "func2", it should not auto- | |
499 | # delete. | |
500 | # | |
96b6697f | 501 | gdb_continue_to_breakpoint "func2 breakpoint here, third time" |
085dd6e6 JM |
502 | gdb_test "watch static_b" ".*\[Ww\]atchpoint \[0-9\]*: static_b" \ |
503 | "set static local watch" | |
504 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: static_b.*" \ | |
505 | "trigger static local watch" | |
506 | gdb_test "cont" "Continuing.*marker6 \\(\\).*" \ | |
507 | "continue after trigger static local watch" | |
508 | gdb_test "info break" ".*watchpoint.*static_b.*" \ | |
509 | "static local watch did not self-delete" | |
510 | ||
511 | # We should be in "recurser" now. Test a watch of a stack- | |
512 | # based local. Symbols mentioned in a watchpoint are bound | |
513 | # at watchpoint-creation. Thus, a watch of a stack-based | |
514 | # local to a recursing function should be bound only to that | |
515 | # one invocation, and should not trigger for other invocations. | |
516 | # | |
96b6697f AB |
517 | with_test_prefix "local_x" { |
518 | gdb_test "tbreak recurser" ".*breakpoint.*" | |
519 | gdb_test "cont" "Continuing.*recurser.*" | |
520 | gdb_test "next" "if \\(x > 0.*" "next past local_x initialization" | |
521 | gdb_test "watch local_x" ".*\[Ww\]atchpoint \[0-9\]*: local_x" \ | |
522 | "set local watch in recursive call" | |
523 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_x.*New value = 2.*" \ | |
524 | "trigger local watch in recursive call" | |
525 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \ | |
526 | "self-delete local watch in recursive call" | |
527 | } | |
085dd6e6 | 528 | |
97ddaa9b PH |
529 | # Repeat the preceding test, but this time use "recurser::local_x" as |
530 | # the variable to track. | |
96b6697f AB |
531 | with_test_prefix "recurser::local_x" { |
532 | gdb_test "cont" "Continuing.*marker6.*" "continue to marker6" | |
533 | gdb_test "tbreak recurser" ".*breakpoint.*" | |
534 | gdb_test "cont" "Continuing.*recurser.*" "continue to recurser" | |
535 | gdb_test "next" "if \\(x > 0.*" "next past local_x initialization" | |
536 | gdb_test "watch recurser::local_x" ".*\[Ww\]atchpoint \[0-9\]*: recurser::local_x" \ | |
537 | "set local watch in recursive call with explicit scope" | |
538 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: recurser::local_x.*New value = 2.*" \ | |
539 | "trigger local watch with explicit scope in recursive call" | |
540 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \ | |
541 | "self-delete local watch with explicit scope in recursive call (2)" | |
542 | } | |
97ddaa9b | 543 | |
c906108c | 544 | # Disable everything so we can finish the program at full speed |
96b6697f | 545 | gdb_test_no_output "disable" "disable in test_complex_watchpoint, second time" |
c906108c SS |
546 | |
547 | if [target_info exists gdb,noresults] { return } | |
548 | ||
085dd6e6 | 549 | gdb_continue_to_end "continue to exit in test_complex_watchpoint" |
c906108c SS |
550 | } |
551 | } | |
552 | ||
293e9a31 DC |
553 | proc test_watchpoint_and_breakpoint {} { |
554 | global gdb_prompt | |
555 | ||
31e77af2 | 556 | # This is a test for PR breakpoints/7143, which involves setting a |
293e9a31 DC |
557 | # watchpoint right after you've reached a breakpoint. |
558 | ||
559 | if [runto func3] then { | |
560 | gdb_breakpoint [gdb_get_line_number "second x assignment"] | |
561 | gdb_continue_to_breakpoint "second x assignment" | |
562 | gdb_test "watch x" ".*atchpoint \[0-9\]+: x" | |
31e77af2 PA |
563 | gdb_test "next" \ |
564 | ".*atchpoint \[0-9\]+: x\r\n\r\nOld value = 0\r\nNew value = 1\r\n.*" \ | |
565 | "next after watch x" | |
06a64a0b TT |
566 | |
567 | gdb_test_no_output "delete \$bpnum" "delete watch x" | |
293e9a31 DC |
568 | } |
569 | } | |
65d79d4b SDJ |
570 | |
571 | proc test_constant_watchpoint {} { | |
572 | gdb_test "watch 5" "Cannot watch constant value `5'." "number is constant" | |
aeaa2474 SA |
573 | gdb_test "watch (int *)5" "Cannot watch constant value `\\(int \\*\\)5'." \ |
574 | "number with cast is constant" | |
65d79d4b SDJ |
575 | gdb_test "watch marker1" "Cannot watch constant value `marker1'." \ |
576 | "marker1 is constant" | |
577 | gdb_test "watch count + 6" ".*atchpoint \[0-9\]+: count \\+ 6" | |
578 | gdb_test_no_output "delete \$bpnum" "delete watchpoint `count + 6'" | |
579 | gdb_test "watch 7 + count" ".*atchpoint \[0-9\]+: 7 \\+ count" | |
580 | gdb_test_no_output "delete \$bpnum" "delete watchpoint `7 + count'" | |
581 | } | |
582 | ||
efa80663 PA |
583 | proc test_disable_enable_software_watchpoint {} { |
584 | # This is regression test for a bug that caused `enable' to fail | |
585 | # for software watchpoints. | |
586 | ||
587 | # Watch something not memory to force a software watchpoint. | |
588 | gdb_test {watch $pc} ".*atchpoint \[0-9\]+: .pc" | |
589 | ||
590 | gdb_test_no_output "disable \$bpnum" "disable watchpoint `\$pc'" | |
591 | gdb_test_no_output "enable \$bpnum" "reenable watchpoint `\$pc'" | |
592 | ||
593 | gdb_test "info watchpoint \$bpnum" \ | |
594 | ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+.pc.*" \ | |
595 | "watchpoint `\$pc' is enabled" | |
596 | ||
597 | gdb_test_no_output "delete \$bpnum" "delete watchpoint `\$pc'" | |
598 | } | |
599 | ||
06a64a0b | 600 | proc test_watch_location {} { |
c72b2e7b YQ |
601 | global gdb_prompt |
602 | ||
06a64a0b TT |
603 | gdb_breakpoint [gdb_get_line_number "func5 breakpoint here"] |
604 | gdb_continue_to_breakpoint "func5 breakpoint here" | |
605 | ||
c72b2e7b YQ |
606 | # Check first if a null pointer can be dereferenced on the target. |
607 | gdb_test_multiple "p *nullptr" "" { | |
608 | -re "Cannot access memory at address 0x0.*$gdb_prompt $" { | |
609 | gdb_test "watch -location nullptr->p->x" \ | |
610 | "Cannot access memory at address 0x0" | |
611 | } | |
612 | -re ".*$gdb_prompt $" { | |
613 | # Null pointer dereference is legitimate. | |
614 | } | |
615 | } | |
3a1115a0 | 616 | |
06a64a0b TT |
617 | gdb_test "watch -location *x" "atchpoint .*: .*" "watch -location .x" |
618 | ||
619 | gdb_test "continue" \ | |
620 | "Continuing.*\[Ww\]atchpoint .*: .*New value = 27.*" \ | |
621 | "continue with watch -location" | |
622 | ||
623 | gdb_test_no_output "delete \$bpnum" "delete watch -location" | |
624 | } | |
625 | ||
fabde485 PA |
626 | # Tests watching areas larger than a word. |
627 | ||
628 | proc test_wide_location_1 {} { | |
4b3c9f41 | 629 | global no_hw |
b62e2b27 | 630 | global gdb_prompt |
4b3c9f41 | 631 | |
fabde485 PA |
632 | # This test watches two words on most 32-bit ABIs, and one word on |
633 | # most 64-bit ABIs. | |
634 | ||
635 | # Platforms where the target can't watch such a large region | |
636 | # should clear hw_expected below. | |
b62e2b27 | 637 | if { $no_hw || [target_info exists gdb,no_hardware_watchpoints] |
bdddb4de UW |
638 | || [istarget arm*-*-*] |
639 | || ([istarget powerpc*-*-*] && ![is_lp64_target])} { | |
fabde485 PA |
640 | set hw_expected 0 |
641 | } else { | |
642 | set hw_expected 1 | |
643 | } | |
644 | ||
645 | gdb_breakpoint [gdb_get_line_number "func6 breakpoint here"] | |
646 | gdb_continue_to_breakpoint "func6 breakpoint here" | |
647 | ||
648 | if { $hw_expected } { | |
11af934b | 649 | gdb_test "watch foo2" "Hardware watchpoint .*: .*" |
fabde485 PA |
650 | gdb_test "continue" \ |
651 | "Continuing.*Hardware watchpoint .*: .*New value = \\\{val = \\\{0, 11\\\}\\\}.*" \ | |
652 | "continue with watch foo2" | |
653 | } else { | |
11af934b | 654 | gdb_test "watch foo2" "atchpoint .*: .*" |
b62e2b27 UW |
655 | set test "continue with watch foo2" |
656 | gdb_test_multiple "cont" $test { | |
657 | -re "Continuing.*\[Ww\]atchpoint .*: .*New value = \\\{val = \\\{0, 11\\\}\\\}.*$gdb_prompt $" { | |
658 | pass $test | |
659 | } | |
660 | -re "Could not insert hardware breakpoints:.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" { | |
661 | # This may happen with remote targets that support | |
662 | # hardware watchpoints. We only find out the | |
663 | # watchpoint was too large, for example, at insert | |
664 | # time. If GDB is ever adjusted to downgrade the | |
665 | # watchpoint automatically in this case, this match | |
666 | # should be removed. | |
667 | pass $test | |
668 | } | |
669 | } | |
fabde485 PA |
670 | } |
671 | ||
672 | gdb_test_no_output "delete \$bpnum" "delete watch foo2" | |
673 | } | |
674 | ||
675 | proc test_wide_location_2 {} { | |
4b3c9f41 | 676 | global no_hw |
b62e2b27 | 677 | global gdb_prompt |
4b3c9f41 | 678 | |
fabde485 PA |
679 | # This test watches four words on most 32-bit ABIs, and two words |
680 | # on 64-bit ABIs. | |
681 | ||
682 | # Platforms where the target can't watch such a large region | |
683 | # should clear hw_expected below. | |
b62e2b27 | 684 | if { $no_hw || [target_info exists gdb,no_hardware_watchpoints] |
bdddb4de UW |
685 | || [istarget arm*-*-*] |
686 | || [istarget powerpc*-*-*]} { | |
fabde485 PA |
687 | set hw_expected 0 |
688 | } else { | |
689 | set hw_expected 1 | |
690 | } | |
691 | ||
692 | gdb_breakpoint [gdb_get_line_number "func7 breakpoint here"] | |
693 | gdb_continue_to_breakpoint "func7 breakpoint here" | |
694 | ||
695 | if { $hw_expected } { | |
11af934b | 696 | gdb_test "watch foo4" "Hardware watchpoint .*: .*" |
fabde485 PA |
697 | gdb_test "continue" \ |
698 | "Continuing.*Hardware watchpoint .*: .*New value = \\\{val = \\\{0, 0, 0, 33\\\}\\\}.*" \ | |
699 | "continue with watch foo4" | |
700 | } else { | |
11af934b | 701 | gdb_test "watch foo4" "atchpoint .*: .*" |
b62e2b27 UW |
702 | set test "continue with watch foo4" |
703 | gdb_test_multiple "cont" $test { | |
704 | -re "Continuing.*\[Ww\]atchpoint .*: .*New value = \\\{val = \\\{0, 0, 0, 33\\\}\\\}.*$gdb_prompt $" { | |
705 | pass $test | |
706 | } | |
707 | -re "Could not insert hardware breakpoints:.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" { | |
708 | # This may happen with remote targets that support | |
709 | # hardware watchpoints. We only find out the | |
710 | # watchpoint was too large, for example, at insert | |
711 | # time. If GDB is ever adjusted to downgrade the | |
712 | # watchpoint automatically in this case, this match | |
713 | # should be removed. | |
714 | pass $test | |
715 | } | |
716 | } | |
fabde485 PA |
717 | } |
718 | ||
719 | gdb_test_no_output "delete \$bpnum" "delete watch foo4" | |
720 | } | |
721 | ||
fa4727a6 DJ |
722 | proc test_inaccessible_watchpoint {} { |
723 | global gdb_prompt | |
724 | ||
725 | # This is a test for watchpoints on currently inaccessible (but later | |
726 | # valid) memory. | |
727 | ||
728 | if [runto func4] then { | |
ccc57cf9 PA |
729 | # Make sure we only allow memory access errors. |
730 | set msg "watchpoint refused to insert on nonexistent struct member" | |
731 | gdb_test_multiple "watch struct1.nosuchmember" $msg { | |
732 | -re ".*atchpoint \[0-9\]+: struct1.nosuchmember.*$gdb_prompt $" { | |
733 | # PR breakpoints/9681 | |
734 | fail $msg | |
735 | } | |
736 | -re "There is no member named nosuchmember\\..*$gdb_prompt $" { | |
737 | pass $msg | |
738 | } | |
739 | } | |
740 | ||
8464be76 DJ |
741 | # See whether a watchpoint on a normal variable is a hardware |
742 | # watchpoint or not. The watchpoints on NULL should be hardware | |
743 | # iff this one is. | |
744 | set watchpoint_msg "Watchpoint" | |
745 | gdb_test_multiple "watch global_ptr" "watch global_ptr" { | |
746 | -re "Watchpoint \[0-9\]+: global_ptr\r\n.*$gdb_prompt $" { | |
747 | pass "watch global_ptr" | |
748 | } | |
749 | -re "Hardware watchpoint \[0-9\]+: global_ptr\r\n.*$gdb_prompt $" { | |
750 | set watchpoint_msg "Hardware watchpoint" | |
751 | pass "watch global_ptr" | |
752 | } | |
753 | } | |
754 | delete_breakpoints | |
755 | ||
756 | # Make sure that we can watch a constant address, and correctly | |
757 | # use a HW watchpoint if supported. | |
758 | gdb_test "watch *(int *) 0" \ | |
759 | "$watchpoint_msg \[0-9\]+: \\*\\(int \\*\\) 0" | |
760 | delete_breakpoints | |
761 | ||
a1442452 PA |
762 | # The same, but using -location through an indirection. |
763 | gdb_test "watch -location *global_ptr" \ | |
4a4106ca | 764 | "$watchpoint_msg \[0-9\]+: \-location \\*global_ptr" |
a1442452 PA |
765 | delete_breakpoints |
766 | ||
b800ec70 UW |
767 | # This step requires two HW watchpoints. Since some platforms only |
768 | # have a single one, accept either SW or HW watchpoint in this case. | |
769 | if {[skip_hw_watchpoint_multi_tests]} { | |
770 | set watchpoint_msg "(Watchpoint|Hardware watchpoint)" | |
efd11a33 JK |
771 | } |
772 | ||
773 | gdb_test "watch *global_ptr" "$watchpoint_msg \[0-9\]+: \\\*global_ptr" | |
65d79d4b SDJ |
774 | gdb_test "set \$global_ptr_breakpoint_number = \$bpnum" "" |
775 | gdb_test "next" ".*global_ptr = buf.*" "global_ptr next" | |
fa4727a6 DJ |
776 | gdb_test_multiple "next" "next over ptr init" { |
777 | -re ".*atchpoint \[0-9\]+: \\*global_ptr\r\n\r\nOld value = .*\r\nNew value = 3 .*\r\n.*$gdb_prompt $" { | |
778 | # We can not test for <unknown> here because NULL may be readable. | |
779 | # This test does rely on *NULL != 3. | |
780 | pass "next over ptr init" | |
781 | } | |
782 | } | |
783 | gdb_test_multiple "next" "next over buffer set" { | |
784 | -re ".*atchpoint \[0-9\]+: \\*global_ptr\r\n\r\nOld value = 3 .*\r\nNew value = 7 .*\r\n.*$gdb_prompt $" { | |
785 | pass "next over buffer set" | |
786 | } | |
787 | } | |
65d79d4b SDJ |
788 | gdb_test "delete \$global_ptr_breakpoint_number" "" |
789 | gdb_test "watch **global_ptr_ptr" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr" | |
790 | gdb_test "set \$global_ptr_ptr_breakpoint_number = \$bpnum" "" | |
c79a8e11 | 791 | gdb_test "next" ".*global_ptr_ptr = &global_ptr.*" "global_ptr_ptr next" |
65d79d4b SDJ |
792 | gdb_test "next" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr\[\r\n\]+Old value = .*\r\nNew value = 7 .*" "next over global_ptr_ptr init" |
793 | gdb_test "next" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr\[\r\n\]+Old value = 7 .*\r\nNew value = 9 .*" "next over global_ptr_ptr buffer set" | |
794 | gdb_test "next" ".*atchpoint \[0-9\]+: \\*\\*global_ptr_ptr\[\r\n\]+Old value = 9 .*\r\nNew value = 5 .*" "next over global_ptr_ptr pointer advance" | |
795 | gdb_test_no_output "delete \$global_ptr_ptr_breakpoint_number" | |
fa4727a6 DJ |
796 | } |
797 | } | |
a13491c8 PA |
798 | |
799 | proc test_no_hw_watchpoints {} { | |
4b3c9f41 PA |
800 | global testfile |
801 | ||
802 | clean_restart $testfile | |
a13491c8 PA |
803 | |
804 | # Verify that a user can force GDB to use "slow" watchpoints. | |
805 | # (This proves rather little on kernels that don't support | |
806 | # fast watchpoints, but still...) | |
807 | # | |
808 | if ![runto_main] then { fail "watch tests suppressed" } | |
809 | ||
810 | gdb_test_no_output "set can-use-hw-watchpoints 0" "disable fast watches" | |
811 | ||
812 | gdb_test "show can-use-hw-watchpoints" \ | |
813 | "Debugger's willingness to use watchpoint hardware is 0." \ | |
814 | "show disable fast watches" | |
815 | ||
816 | gdb_test "watch ival3 if count > 1" \ | |
817 | "Watchpoint \[0-9\]*: ival3.*" \ | |
818 | "set slow conditional watch" | |
819 | ||
820 | gdb_test "continue" \ | |
821 | "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*" \ | |
822 | "trigger slow conditional watch" | |
823 | ||
824 | gdb_test_no_output "delete \$bpnum" "delete watch ival3" | |
825 | ||
cb8ea32b KS |
826 | gdb_test "watch ival3 if count > 1 thread 1 " \ |
827 | "Watchpoint \[0-9\]*: ival3.*" \ | |
828 | "set slow condition watch w/thread" | |
829 | ||
830 | gdb_test_no_output "delete \$bpnum" "delete watch w/condition and thread" | |
831 | ||
a13491c8 PA |
832 | # We've explicitly disabled hardware watches. Verify that GDB |
833 | # refrains from using them. | |
834 | # | |
835 | gdb_test "rwatch ival3" \ | |
638aa5a1 | 836 | "Can't set read/access watchpoint when hardware watchpoints are disabled." \ |
a13491c8 | 837 | "rwatch disallowed when can-set-hw-watchpoints cleared" |
638aa5a1 AB |
838 | gdb_test "awatch ival3" \ |
839 | "Can't set read/access watchpoint when hardware watchpoints are disabled." \ | |
840 | "awatch disallowed when can-set-hw-watchpoints cleared" | |
841 | ||
a13491c8 PA |
842 | |
843 | # Re-enable hardware watchpoints if necessary. | |
844 | if ![target_info exists gdb,no_hardware_watchpoints] { | |
845 | gdb_test_no_output "set can-use-hw-watchpoints 1" "" | |
846 | } | |
847 | } | |
848 | ||
218d2fc6 TJB |
849 | proc test_watchpoint_in_big_blob {} { |
850 | global gdb_prompt | |
851 | ||
274f47f3 PA |
852 | # On native targets where we do hardware resource accounting, this |
853 | # may end up as a software watchpoint. | |
854 | set ok 0 | |
855 | set test "watch buf" | |
856 | gdb_test_multiple "watch buf" $test { | |
857 | -re "Hardware watchpoint \[0-9\]+: buf.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" { | |
858 | # This may happen with remote targets (where we don't do | |
859 | # resource accounting) that support hardware watchpoints, | |
860 | # when breakpoint always-inserted is on. The watchpoint | |
861 | # was too large, for example. If GDB is ever adjusted to | |
862 | # downgrade the watchpoint automatically in this case, | |
863 | # this match should be removed. Note the breakpoint has | |
864 | # been created, and is in the list, so it needs deleting. | |
865 | pass $test | |
866 | } | |
867 | -re ".*atchpoint \[0-9\]+: buf.*$gdb_prompt $" { | |
868 | pass $test | |
869 | set ok 1 | |
870 | } | |
871 | } | |
872 | ||
873 | if { $ok } { | |
874 | set test "watchpoint on buf hit" | |
875 | gdb_test_multiple "cont" $test { | |
876 | -re "Continuing.*atchpoint \[0-9\]+: buf\r\n\r\nOld value = .*testte\".*$gdb_prompt $" { | |
877 | pass $test | |
878 | } | |
879 | -re "Could not insert hardware breakpoints:.*You may have requested too many hardware breakpoints/watchpoints.*$gdb_prompt $" { | |
880 | # This may happen with remote targets that support | |
881 | # hardware watchpoints. We only find out the | |
882 | # watchpoint was too large, for example, at insert | |
883 | # time. If GDB is ever adjusted to downgrade the | |
884 | # watchpoint automatically in this case, this match | |
885 | # should be removed. | |
886 | pass $test | |
887 | } | |
888 | } | |
889 | } | |
06a64a0b TT |
890 | |
891 | gdb_test_no_output "delete \$bpnum" "delete watch buf" | |
218d2fc6 TJB |
892 | } |
893 | ||
638aa5a1 AB |
894 | proc test_watch_register_location {} { |
895 | global no_hw | |
896 | ||
897 | if {!$no_hw && ![target_info exists gdb,no_hardware_watchpoints]} { | |
898 | # Non-memory read/access watchpoints are not supported, they would | |
899 | # require software read/access watchpoint support (which is not | |
900 | # currently available). | |
901 | gdb_test "rwatch \$pc" \ | |
902 | "Expression cannot be implemented with read/access watchpoint..*" \ | |
903 | "rwatch disallowed for register based expression" | |
904 | gdb_test "awatch \$pc" \ | |
905 | "Expression cannot be implemented with read/access watchpoint..*" \ | |
906 | "awatch disallowed for register based expression" | |
907 | } | |
908 | } | |
909 | ||
c906108c SS |
910 | # Start with a fresh gdb. |
911 | ||
78b4f468 | 912 | set prev_timeout $timeout |
c906108c SS |
913 | set timeout 600 |
914 | verbose "Timeout now 600 sec.\n" | |
915 | ||
4b3c9f41 | 916 | test_no_hw_watchpoints |
c906108c | 917 | |
4b3c9f41 PA |
918 | proc do_tests {} { |
919 | global testfile | |
920 | global no_hw | |
c906108c | 921 | |
4b3c9f41 | 922 | clean_restart $testfile |
c906108c | 923 | |
bdddb4de | 924 | if {$no_hw || [target_info exists gdb,no_hardware_watchpoints]} { |
4b3c9f41 PA |
925 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" |
926 | } | |
927 | ||
928 | if [initialize] then { | |
929 | ||
930 | test_simple_watchpoint | |
931 | ||
932 | test_disabling_watchpoints | |
933 | ||
934 | if ![target_info exists gdb,cannot_call_functions] { | |
935 | test_stepping | |
936 | } | |
c906108c SS |
937 | } |
938 | ||
f3ad2025 PA |
939 | # Tests below don't rely on the markers and watchpoint set by |
940 | # `initialize' anymore. | |
941 | clean_restart $testfile | |
942 | ||
bdddb4de | 943 | if {$no_hw || [target_info exists gdb,no_hardware_watchpoints]} { |
4b3c9f41 PA |
944 | gdb_test_no_output "set can-use-hw-watchpoints 0" "" |
945 | } | |
946 | ||
c906108c SS |
947 | # Only enabled for some targets merely because it has not been tested |
948 | # elsewhere. | |
949 | # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4 | |
950 | # breakpoint before stopping for the watchpoint. I don't know why. | |
951 | if {[istarget "hppa*-*-*"]} then { | |
952 | test_watchpoint_triggered_in_syscall | |
953 | } | |
954 | ||
dbd95daf | 955 | test_complex_watchpoint |
085dd6e6 | 956 | |
8464be76 DJ |
957 | test_inaccessible_watchpoint |
958 | ||
293e9a31 | 959 | test_watchpoint_and_breakpoint |
218d2fc6 TJB |
960 | |
961 | test_watchpoint_in_big_blob | |
65d79d4b | 962 | |
65d79d4b | 963 | test_constant_watchpoint |
06a64a0b | 964 | |
efa80663 PA |
965 | test_disable_enable_software_watchpoint |
966 | ||
06a64a0b | 967 | test_watch_location |
fabde485 | 968 | |
fabde485 PA |
969 | test_wide_location_1 |
970 | test_wide_location_2 | |
638aa5a1 AB |
971 | |
972 | test_watch_register_location | |
c906108c | 973 | } |
78b4f468 | 974 | |
4b3c9f41 PA |
975 | # On targets that can do hardware watchpoints, run the tests twice: |
976 | # once with hardware watchpoints enabled; another with hardware | |
977 | # watchpoints force-disabled. | |
978 | ||
979 | do_tests | |
980 | if ![target_info exists gdb,no_hardware_watchpoints] { | |
0f4d39d5 | 981 | with_test_prefix "no-hw" { |
6a5870ce PA |
982 | set no_hw 1 |
983 | do_tests | |
984 | } | |
4b3c9f41 PA |
985 | } |
986 | ||
78b4f468 RE |
987 | # Restore old timeout |
988 | set timeout $prev_timeout | |
989 | verbose "Timeout now $timeout sec.\n" |