]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/watchpoint.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / watchpoint.exp
CommitLineData
6aba47ca 1# Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2007
b6ba6518 2# Free Software Foundation, Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-gdb@prep.ai.mit.edu
20
21# This file was written by Fred Fish. (fnf@cygnus.com)
22
23if $tracelevel then {
24 strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
30set testfile "watchpoint"
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33
085dd6e6 34set wp_set 1
c906108c
SS
35
36if [get_compiler_info ${binfile}] {
37 return -1
38}
39
c906108c 40if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
41 untested watchpoint.exp
42 return -1
c906108c
SS
43}
44
45# Prepare for watchpoint tests by setting up two breakpoints and one
46# watchpoint.
47#
48# We use breakpoints at marker functions to get past all the startup code,
49# so we can get to the watchpoints in a reasonable amount of time from a
50# known starting point.
51#
52# For simplicity, so we always know how to reference specific breakpoints or
53# watchpoints by number, we expect a particular ordering and numbering of
54# each in the combined breakpoint/watchpoint table, as follows:
55#
56# Number What Where
57# 1 Breakpoint marker1()
58# 2 Breakpoint marker2()
59# 3 Watchpoint ival3
60
61proc initialize {} {
62 global gdb_prompt
63 global hex
64 global decimal
65 global srcfile
085dd6e6 66 global wp_set
c906108c 67
958a4e4c
MS
68 # Disable hardware watchpoints if necessary.
69 if [target_info exists gdb,no_hardware_watchpoints] {
70 gdb_test "set can-use-hw-watchpoints 0" "" ""
71 }
72
c906108c
SS
73 if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] {
74 return 0;
75 }
76
77
78 if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] {
79 return 0;
80 }
81
82
83 if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] {
84 return 0;
85 }
86
87
085dd6e6 88 # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
a0b3c4fd
JM
89 # before running can cause the inferior to croak on HP-UX 11.0 for
90 # reasons yet unknown, we've disabled the ability to set watches
91 # without a running inferior. Verify the restriction.
085dd6e6
JM
92 #
93 send_gdb "watch ival3\n"
94 gdb_expect {
95 -re ".*\[Ww\]atchpoint 3: ival3.*$gdb_prompt $" {
96 pass "set watchpoint on ival3"
97 }
98 -re "warning: can't do that without a running program; try \"break main\", \"run\" first.*$gdb_prompt $" {
99 pass "set watchpoint on ival3"
100 set wp_set 0
101 return 1
102 }
103 timeout {
104 fail "(timeout) set watchpoint on ival3"
105 return 0
106 }
c906108c
SS
107 }
108
c906108c
SS
109 # "info watch" is the same as "info break"
110
111 if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] {
112 return 0;
113 }
114
115
116 # After installing the watchpoint, we disable it until we are ready
117 # to use it. This allows the test program to run at full speed until
118 # we get to the first marker function.
119
120 if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] {
121 return 0;
122 }
123
124
125 return 1
126}
127
128#
129# Test simple watchpoint.
130#
131
132proc test_simple_watchpoint {} {
133 global gdb_prompt
134 global hex
135 global decimal
085dd6e6 136 global wp_set
c906108c
SS
137
138 # Ensure that the watchpoint is disabled when we startup.
139
085dd6e6
JM
140 if { $wp_set } {
141 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] {
142 return 0;
143 }
c906108c
SS
144 }
145
146
147 # Run until we get to the first marker function.
148
149 gdb_run_cmd
150 set timeout 600
151 gdb_expect {
152 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
153 pass "run to marker1 in test_simple_watchpoint"
154 }
155 -re ".*$gdb_prompt $" {
156 fail "run to marker1 in test_simple_watchpoint"
157 return
158 }
159 timeout {
160 fail "run to marker1 in test_simple_watchpoint (timeout)"
161 return
162 }
163 }
164
085dd6e6
JM
165 if { !$wp_set } {
166 # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
a0b3c4fd
JM
167 # before running can cause the inferior to croak on HP-UX 11.0
168 # for reasons yet unknown, we've disabled the ability to set
085dd6e6
JM
169 # watches without a running inferior. The following testpoints used
170 # to be in [initialize].
171 #
172 send_gdb "watch ival3\n"
173 gdb_expect {
174 -re ".*\[Ww\]atchpoint 3: ival3\r\n$gdb_prompt $" {
175 pass "set watchpoint on ival3"
176 }
177 -re ".*$gdb_prompt $" { fail "set watchpoint on ival3" }
178 timeout { fail "set watchpoint on ival3 (timeout)" }
179 }
180
181 set wp_set 1
182
183 # "info watch" is the same as "info break"
184
185 send_gdb "info watch\n"
186 gdb_expect {
187 -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$gdb_prompt $" {
188 pass "watchpoint found in watchpoint/breakpoint table"
189 }
190 -re ".*$gdb_prompt $" {
191 fail "watchpoint found in watchpoint/breakpoint table"
192 }
193 timeout {
194 fail "watchpoint found in watchpoint/breakpoint table"
195 }
196 }
197
198 # After installing the watchpoint, we disable it until we are ready
199 # to use it. This allows the test program to run at full speed until
200 # we get to the first marker function.
201
202 send_gdb "disable 3\n"
203 gdb_expect {
204 -re "disable 3\[\r\n\]+$gdb_prompt $" { pass "disable watchpoint" }
205 -re ".*$gdb_prompt $" { fail "disable watchpoint" }
206 timeout { fail "disable watchpoint (timeout)" }
207 }
208 }
209
c906108c
SS
210 # After reaching the marker function, enable the watchpoint.
211
212 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] {
213 return ;
214 }
215
216
217 gdb_test "break func1" "Breakpoint.*at.*"
218 gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
219
220 gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \
221 "continue to breakpoint at func1"
222
223 # Continue until the first change, from -1 to 0
224
225 send_gdb "cont\n"
226 gdb_expect {
227 -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
228 pass "watchpoint hit, first time"
229 }
230 -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
231 setup_xfail "m68*-*-*" 2597
232 fail "thought it hit breakpoint at func1 twice"
233 gdb_test "delete \$func1_breakpoint_number" ""
234 gdb_test "continue" "\
235Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
236 "watchpoint hit, first time"
237 }
238 -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
239 timeout { fail "watchpoint hit, first time (timeout)" ; return }
240 eof { fail "watchpoint hit, first time (eof)" ; return }
241 }
242
c2d11a7d
JM
243 # Check that the hit count is reported correctly
244 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 1 time.*" "Watchpoint hit count is 1"
245
c906108c
SS
246 gdb_test "delete \$func1_breakpoint_number" ""
247
248 # Continue until the next change, from 0 to 1.
249 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
250
c2d11a7d
JM
251 # Check that the hit count is reported correctly
252 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 2 times.*" "Watchpoint hit count is 2"
253
c906108c
SS
254 # Continue until the next change, from 1 to 2.
255 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
c2d11a7d
JM
256
257 # Check that the hit count is reported correctly
258 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
259
260 # Continue until the next change, from 2 to 3.
261 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
262
c2d11a7d
JM
263 # Check that the hit count is reported correctly
264 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 4 times.*" "Watchpoint hit count is 4"
265
c906108c
SS
266 # Continue until the next change, from 3 to 4.
267 # Note that this one is outside the loop.
268
269 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
270
c2d11a7d
JM
271 # Check that the hit count is reported correctly
272 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 5 times.*" "Watchpoint hit count is 5"
273
c906108c
SS
274 # Continue until we hit the finishing marker function.
275 # Make sure we hit no more watchpoints.
276
277 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
278 "continue to marker2"
279
280 # Disable the watchpoint so we run at full speed until we exit.
281
282 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] {
283 return ;
284 }
285
286
287 # Run until process exits.
288
289 if [target_info exists gdb,noresults] { return }
290
7a292a7a 291 gdb_continue_to_end "continue to exit in test_simple_watchpoint"
c906108c
SS
292}
293
294# Test disabling watchpoints.
295
296proc test_disabling_watchpoints {} {
297 global gdb_prompt
298 global binfile
299 global srcfile
300 global decimal
301 global hex
302
085dd6e6
JM
303 # "info watch" is the same as "info break"
304 gdb_test "info watch" "\[0-9\]+\[ \]*breakpoint.*marker1.*\r\n\[0-9\]+\[ \]*breakpoint.*marker2.*\r\n\[0-9]+\[ \]*.*watchpoint.*ival3\r\n\.*\[0-9\]+ times.*" "watchpoints found in watchpoint/breakpoint table"
305
c906108c
SS
306 # Ensure that the watchpoint is disabled when we startup.
307
308 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] {
309 return 0;
310 }
311
312
313 # Run until we get to the first marker function.
314
315 gdb_run_cmd
316 set timeout 600
317 gdb_expect {
318 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
319 pass "run to marker1 in test_disabling_watchpoints"
320 }
321 -re ".*$gdb_prompt $" {
322 fail "run to marker1 in test_disabling_watchpoints"
323 return
324 }
325 timeout {
326 fail "run to marker1 in test_disabling_watchpoints (timeout)"
327 return
328 }
329 }
330
331 # After reaching the marker function, enable the watchpoint.
332
333 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] {
334 return ;
335 }
336
337
338 # Continue until the first change, from -1 to 0
339 # Don't check the old value, because on VxWorks the variable value
340 # will not have been reinitialized.
341 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
342
343 # Continue until the next change, from 0 to 1.
344 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"
345
346 # Disable the watchpoint but leave breakpoints
347
348 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] {
349 return 0;
350 }
351
352
353 # Check watchpoint list, looking for the entry that confirms the
354 # watchpoint is disabled.
085dd6e6 355 gdb_test "info watchpoints" "\[0-9]+\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
c906108c
SS
356
357 # Continue until we hit the finishing marker function.
358 # Make sure we hit no more watchpoints.
359 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
360 "disabled watchpoint skipped"
361
362 if [target_info exists gdb,noresults] { return }
363
7a292a7a 364 gdb_continue_to_end "continue to exit in test_disabling_watchpoints"
c906108c
SS
365}
366
367# Test stepping and other mundane operations with watchpoints enabled
368proc test_stepping {} {
369 global gdb_prompt
370
371 if [runto marker1] then {
372 gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
373
374 # Well, let's not be too mundane. It should be a *bit* of a challenge
375 gdb_test "break func2 if 0" "Breakpoint.*at.*"
376 gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
377
085dd6e6 378 gdb_test "p func1 ()" "= 73" \
4b2b3b3e 379 "calling function with watchpoint enabled"
c906108c
SS
380
381 #
382 # "finish" brings us back to main.
383 # On some targets (e.g. alpha) gdb will stop from the finish in midline
384 # of the marker1 call. This is due to register restoring code on
385 # the alpha and might be caused by stack adjustment instructions
386 # on other targets. In this case we will step once more.
387 #
388
389 send_gdb "finish\n"
390 gdb_expect {
2df3850c
JM
391 -re "Run.*exit from.*marker1.* at" {
392 pass "finish from marker1"
393 }
dfcd3bfb 394 default { fail "finish from marker1 (timeout)" ; return }
c906108c
SS
395 }
396
397 gdb_expect {
398 -re "marker1 \\(\\);.*$gdb_prompt $" {
399 send_gdb "step\n"
400 exp_continue
401 }
402 -re "func1 \\(\\);.*$gdb_prompt $" {
dfcd3bfb 403 pass "back at main from marker1"
c906108c
SS
404 }
405 -re ".*$gdb_prompt $" {
dfcd3bfb 406 fail "back at main from marker1"
c906108c 407 }
dfcd3bfb 408 default { fail "back at main from marker1 (timeout)" ; return }
c906108c
SS
409 }
410
411 gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
412
413 # Now test that "until" works. It's a bit tricky to test
414 # "until", because compilers don't always arrange the code
415 # exactly the same way, and we might get slightly different
416 # sequences of statements. But the following should be true
417 # (if not it is a compiler or a debugger bug): The user who
418 # does "until" at every statement of a loop should end up
419 # stepping through the loop once, and the debugger should not
420 # stop for any of the remaining iterations.
421
422 gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
423 gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
424 send_gdb "until\n"
425 gdb_expect {
426 -re "(for \\(count = 0|\}).*$gdb_prompt $" {
427 gdb_test "until" "ival1 = count; /. Outside loop ./" \
428 "until out of loop"
429 }
430 -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
431 pass "until out of loop"
432 }
433 -re ".*$gdb_prompt $" {
434 fail "until out of loop"
435 }
c4093a6a 436 default { fail "until out of loop (timeout)" ; return }
c906108c
SS
437 }
438
439 gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
440 }
441}
442
443# Test stepping and other mundane operations with watchpoints enabled
444proc test_watchpoint_triggered_in_syscall {} {
445 global gdb_prompt
446
958a4e4c
MS
447 # These tests won't work without printf support.
448 if [gdb_skip_stdio_test "watchpoints triggered in syscall"] {
449 return;
c906108c
SS
450 }
451 # Run until we get to the first marker function.
452 set x 0
453 set y 0
454 set testname "Watch buffer passed to read syscall"
455 if [runto marker2] then {
456 gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
457 gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
458 gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
459 gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
460 gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
461 gdb_test "break marker4" ".*Breakpoint.*"
462
463 gdb_test "set doread = 1" ""
464
465 # If we send_gdb "123\n" before gdb has switched the tty, then it goes
466 # to gdb, not the inferior, and we lose. So that is why we have
467 # watchpoint.c prompt us, so we can wait for that prompt.
468 send_gdb "continue\n";
469 gdb_expect {
470 -re "Continuing\\.\r\ntype stuff for buf now:" {
471 pass "continue to read"
472 }
473 default {
474 fail "continue to read";
475 return ;
476 }
477 }
478
479 send_gdb "123\n"
480 gdb_expect {
481 -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
482 -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
483 -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
484 -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
485 -re ".*$gdb_prompt $" { pass "sent 123" }
486 timeout { fail "sent 123 (timeout)" }
487 }
488
489 # Examine the values in buf to see how many watchpoints we
490 # should have printed.
491 send_gdb "print buf\[0\]\n"
492 gdb_expect {
493 -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
494 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
495 -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
496 default { fail "print buf\[0\]"}
497 }
498 send_gdb "print buf\[1\]\n"
499 gdb_expect {
500 -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
501 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
502 -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
503 default { fail "print buf\[1\]"}
504 }
505 send_gdb "print buf\[2\]\n"
506 gdb_expect {
507 -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
508 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
509 -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
510 default { fail "print buf\[2\]"}
511 }
512 send_gdb "print buf\[3\]\n"
513 gdb_expect {
514 -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
515 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
516 -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
517 default { fail "print buf\[3\]" }
518 }
519
520 # Did we find what we were looking for? If not, flunk it.
521 if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
522
523 # Continue until we hit the finishing marker function.
524 # Make sure we hit no more watchpoints.
525 gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
526 "continue to marker4"
527
528 # Disable everything so we can finish the program at full speed
529 gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
530
531 if [target_info exists gdb,noresults] { return }
532
7a292a7a 533 gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall"
c906108c
SS
534 }
535}
536
537# Do a simple test of of watching through a pointer when the pointer
538# itself changes. Should add some more complicated stuff here.
539
540proc test_complex_watchpoint {} {
541 global gdb_prompt
542
543 if [runto marker4] then {
544 gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
545 gdb_test "break marker5" ".*Breakpoint.*"
546
547 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
548
549 # Continue until we hit the marker5 function.
550 # Make sure we hit no more watchpoints.
551
552 gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
553 "did not trigger wrong watchpoint"
554
085dd6e6
JM
555 # Test watches of things declared locally in a function.
556 # In particular, test that a watch of stack-based things
557 # is deleted when the stack-based things go out of scope.
558 #
559 gdb_test "disable" "" "disable in test_complex_watchpoint"
560 gdb_test "break marker6" ".*Breakpoint.*"
561 gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \
562 "continue to marker6"
563 gdb_test "break func2" ".*Breakpoint.*"
564 gdb_test "cont" "Continuing.*func2.*"
565
566 # Test a watch of a single stack-based variable, whose scope
567 # is the function we're now in. This should auto-delete when
568 # execution exits the scope of the watchpoint.
569 #
570 gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch"
571 gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch"
572 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" "self-delete local watch"
573
574 gdb_test "cont" "Continuing.*func2.*"
575 # We should be in "func2" again now. Test a watch of an
576 # expression which includes both a stack-based local and
577 # something whose scope is larger than this invocation
578 # of "func2". This should also auto-delete.
579 #
580 gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \
581 "set partially local watch"
582 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
583 "trigger1 partially local watch"
584 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
585 "trigger2 partially local watch"
586 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
587 "self-delete partially local watch"
588
589 # We should be in "func2" again now. Test a watch of a
590 # static (non-stack-based) local. Since this has scope
591 # across any invocations of "func2", it should not auto-
592 # delete.
593 #
594 gdb_test "cont" "Continuing.*func2.*"
595 gdb_test "watch static_b" ".*\[Ww\]atchpoint \[0-9\]*: static_b" \
596 "set static local watch"
597 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: static_b.*" \
598 "trigger static local watch"
599 gdb_test "cont" "Continuing.*marker6 \\(\\).*" \
600 "continue after trigger static local watch"
601 gdb_test "info break" ".*watchpoint.*static_b.*" \
602 "static local watch did not self-delete"
603
604 # We should be in "recurser" now. Test a watch of a stack-
605 # based local. Symbols mentioned in a watchpoint are bound
606 # at watchpoint-creation. Thus, a watch of a stack-based
607 # local to a recursing function should be bound only to that
608 # one invocation, and should not trigger for other invocations.
609 #
610 gdb_test "tbreak recurser" ".*Breakpoint.*"
611 gdb_test "cont" "Continuing.*recurser.*"
612 gdb_test "watch local_x" ".*\[Ww\]atchpoint \[0-9\]*: local_x" \
613 "set local watch in recursive call"
614 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_x.*New value = 2.*" \
615 "trigger local watch in recursive call"
616 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
617 "self-delete local watch in recursive call"
618
c906108c
SS
619 # Disable everything so we can finish the program at full speed
620 gdb_test "disable" "" "disable in test_complex_watchpoint"
621
622 if [target_info exists gdb,noresults] { return }
623
085dd6e6 624 gdb_continue_to_end "continue to exit in test_complex_watchpoint"
c906108c
SS
625 }
626}
627
293e9a31
DC
628proc test_watchpoint_and_breakpoint {} {
629 global gdb_prompt
630
631 # This is a test for PR gdb/38, which involves setting a
632 # watchpoint right after you've reached a breakpoint.
633
634 if [runto func3] then {
635 gdb_breakpoint [gdb_get_line_number "second x assignment"]
636 gdb_continue_to_breakpoint "second x assignment"
637 gdb_test "watch x" ".*atchpoint \[0-9\]+: x"
638 gdb_test_multiple "next" "next after watch x" {
639 -re ".*atchpoint \[0-9\]+: x\r\n\r\nOld value = 0\r\nNew value = 1\r\n.*$gdb_prompt $" {
640 pass "next after watch x"
641 }
642 -re "\[0-9\]+\[\t \]+y = 1;\r\n$gdb_prompt $" {
643 kfail "gdb/38" "next after watch x"
644 }
645 }
646 }
647}
648
c906108c
SS
649# Start with a fresh gdb.
650
085dd6e6 651gdb_exit
c906108c
SS
652gdb_start
653gdb_reinitialize_dir $srcdir/$subdir
654gdb_load $binfile
78b4f468 655set prev_timeout $timeout
c906108c
SS
656set timeout 600
657verbose "Timeout now 600 sec.\n"
658
659if [initialize] then {
660
661 test_simple_watchpoint
662
663 # The IDT/sim monitor only has 8 (!) open files, of which it uses
664 # 4 (!). So we have to make sure one program exits before
665 # starting another one.
666 if [istarget "mips-idt-*"] then {
667 gdb_exit
668 gdb_start
669 gdb_reinitialize_dir $srcdir/$subdir
670 gdb_load $binfile
671 initialize
672 }
673
674 test_disabling_watchpoints
675
676 # See above.
677 if [istarget "mips-idt-*"] then {
678 gdb_exit
679 gdb_start
680 gdb_reinitialize_dir $srcdir/$subdir
681 gdb_load $binfile
682 initialize
683 }
684
685 if ![target_info exists gdb,cannot_call_functions] {
686 test_stepping
687
688 # See above.
689 if [istarget "mips-idt-*"] then {
690 gdb_exit
691 gdb_start
692 gdb_reinitialize_dir $srcdir/$subdir
693 gdb_load $binfile
694 initialize
695 }
696 }
697
698 # Only enabled for some targets merely because it has not been tested
699 # elsewhere.
700 # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4
701 # breakpoint before stopping for the watchpoint. I don't know why.
702 if {[istarget "hppa*-*-*"]} then {
703 test_watchpoint_triggered_in_syscall
704 }
705
706 # See above.
707 if [istarget "mips-idt-*"] then {
708 gdb_exit
709 gdb_start
710 gdb_reinitialize_dir $srcdir/$subdir
711 gdb_load $binfile
712 initialize
713 }
714
715 # Only enabled for some targets merely because it has not been tested
716 # elsewhere.
717 if {[istarget "hppa*-*-*"] || \
718 [istarget "sparc*-*-sunos*"] || \
719 [istarget "m32r-*-*"]} then {
720 test_complex_watchpoint
721 }
085dd6e6
JM
722
723 # Verify that a user can force GDB to use "slow" watchpoints.
724 # (This proves rather little on kernels that don't support
725 # fast watchpoints, but still...)
726 #
727 if ![runto_main] then { fail "watch tests suppressed" }
728
729 send_gdb "set can-use-hw-watchpoints 0\n"
730 gdb_expect {
731 -re "$gdb_prompt $"\
732 {pass "disable fast watches"}
733 timeout {fail "(timeout) disable fast watches"}
734 }
735 send_gdb "show can-use-hw-watchpoints\n"
736 gdb_expect {
737 -re "Debugger's willingness to use watchpoint hardware is 0.*$gdb_prompt $"\
738 {pass "show disable fast watches"}
739 -re "$gdb_prompt $"\
740 {fail "show disable fast watches"}
741 timeout {fail "(timeout) show disable fast watches"}
742 }
743 send_gdb "watch ival3 if count > 1\n"
744 gdb_expect {
745 -re "Watchpoint \[0-9\]*: ival3.*$gdb_prompt $"\
746 {pass "set slow conditional watch"}
747 -re "$gdb_prompt $"\
748 {fail "set slow conditional watch"}
749 timeout {fail "(timeout) set slow conditional watch"}
750 }
751 send_gdb "continue\n"
752 gdb_expect {
753 -re "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*$gdb_prompt $"\
754 {pass "trigger slow conditional watch"}
755 -re "$gdb_prompt $"\
756 {fail "trigger slow conditional watch"}
757 timeout {fail "(timeout) trigger slow conditional watch"}
758 }
759
760 # We've explicitly disabled hardware watches. Verify that GDB
761 #
762 #
763 send_gdb "rwatch ival3\n"
764 gdb_expect {
765 -re "Expression cannot be implemented with read/access watchpoint..*$gdb_prompt $"\
766 {pass "rwatch disallowed when can-set-hw-watchpoints cleared"}
767 -re "$gdb_prompt $"\
768 {fail "rwatch disallowed when can-set-hw-watchpoints cleared"}
769 timeout {fail "(timeout) rwatch disallowed when can-use-hw-watchpoints cleared"}
770 }
771
772 # Read- and access watchpoints are unsupported on HP-UX. Verify
773 # that GDB gracefully responds to requests to create them.
774 #
775 if [istarget "hppa*-*-hpux*"] then {
776 send_gdb "set can-use-hw-watchpoints 1\n"
777 gdb_expect {
778 -re "$gdb_prompt $"\
779 {pass "enable fast watches"}
780 timeout {fail "(timeout) enable fast watches"}
781 }
782 send_gdb "rwatch ival3\n"
783 gdb_expect {
784 -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
785 {pass "read watches disallowed"}
786 -re "$gdb_prompt $"\
787 {fail "read watches disallowed"}
788 timeout {fail "(timeout) read watches disallowed"}
789 }
790
791 send_gdb "awatch ival3\n"
792 gdb_expect {
793 -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
794 {pass "access watches disallowed"}
795 -re "$gdb_prompt $"\
796 {fail "access watches disallowed"}
797 timeout {fail "(timeout) access watches disallowed"}
798 }
799 }
293e9a31
DC
800
801 # See above.
802 if [istarget "mips-idt-*"] then {
803 gdb_exit
804 gdb_start
805 gdb_reinitialize_dir $srcdir/$subdir
806 gdb_load $binfile
807 initialize
808 }
809
810 test_watchpoint_and_breakpoint
c906108c 811}
78b4f468
RE
812
813# Restore old timeout
814set timeout $prev_timeout
815verbose "Timeout now $timeout sec.\n"