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