Update/correct copyright notices.
[binutils-gdb.git] / gdb / testsuite / gdb.base / watchpoint.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000
2 # Free Software Foundation, Inc.
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
23 if $tracelevel then {
24 strace $tracelevel
25 }
26
27 set prms_id 0
28 set bug_id 0
29
30 set testfile "watchpoint"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33
34 set wp_set 1
35
36 if [get_compiler_info ${binfile}] {
37 return -1
38 }
39
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
41 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
42 }
43
44 # Prepare for watchpoint tests by setting up two breakpoints and one
45 # watchpoint.
46 #
47 # We use breakpoints at marker functions to get past all the startup code,
48 # so we can get to the watchpoints in a reasonable amount of time from a
49 # known starting point.
50 #
51 # For simplicity, so we always know how to reference specific breakpoints or
52 # watchpoints by number, we expect a particular ordering and numbering of
53 # each in the combined breakpoint/watchpoint table, as follows:
54 #
55 # Number What Where
56 # 1 Breakpoint marker1()
57 # 2 Breakpoint marker2()
58 # 3 Watchpoint ival3
59
60 proc initialize {} {
61 global gdb_prompt
62 global hex
63 global decimal
64 global srcfile
65 global wp_set
66
67 # Disable hardware watchpoints if necessary.
68 if [target_info exists gdb,no_hardware_watchpoints] {
69 gdb_test "set can-use-hw-watchpoints 0" "" ""
70 }
71
72 if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] {
73 return 0;
74 }
75
76
77 if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] {
78 return 0;
79 }
80
81
82 if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] {
83 return 0;
84 }
85
86
87 # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
88 # before running can cause the inferior to croak on HP-UX 11.0 for
89 # reasons yet unknown, we've disabled the ability to set watches
90 # without a running inferior. Verify the restriction.
91 #
92 send_gdb "watch ival3\n"
93 gdb_expect {
94 -re ".*\[Ww\]atchpoint 3: ival3.*$gdb_prompt $" {
95 pass "set watchpoint on ival3"
96 }
97 -re "warning: can't do that without a running program; try \"break main\", \"run\" first.*$gdb_prompt $" {
98 pass "set watchpoint on ival3"
99 set wp_set 0
100 return 1
101 }
102 timeout {
103 fail "(timeout) set watchpoint on ival3"
104 return 0
105 }
106 }
107
108 # "info watch" is the same as "info break"
109
110 if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] {
111 return 0;
112 }
113
114
115 # After installing the watchpoint, we disable it until we are ready
116 # to use it. This allows the test program to run at full speed until
117 # we get to the first marker function.
118
119 if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] {
120 return 0;
121 }
122
123
124 return 1
125 }
126
127 #
128 # Test simple watchpoint.
129 #
130
131 proc test_simple_watchpoint {} {
132 global gdb_prompt
133 global hex
134 global decimal
135 global wp_set
136
137 # Ensure that the watchpoint is disabled when we startup.
138
139 if { $wp_set } {
140 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] {
141 return 0;
142 }
143 }
144
145
146 # Run until we get to the first marker function.
147
148 gdb_run_cmd
149 set timeout 600
150 gdb_expect {
151 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
152 pass "run to marker1 in test_simple_watchpoint"
153 }
154 -re ".*$gdb_prompt $" {
155 fail "run to marker1 in test_simple_watchpoint"
156 return
157 }
158 timeout {
159 fail "run to marker1 in test_simple_watchpoint (timeout)"
160 return
161 }
162 }
163
164 if { !$wp_set } {
165 # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
166 # before running can cause the inferior to croak on HP-UX 11.0
167 # for reasons yet unknown, we've disabled the ability to set
168 # watches without a running inferior. The following testpoints used
169 # to be in [initialize].
170 #
171 send_gdb "watch ival3\n"
172 gdb_expect {
173 -re ".*\[Ww\]atchpoint 3: ival3\r\n$gdb_prompt $" {
174 pass "set watchpoint on ival3"
175 }
176 -re ".*$gdb_prompt $" { fail "set watchpoint on ival3" }
177 timeout { fail "set watchpoint on ival3 (timeout)" }
178 }
179
180 set wp_set 1
181
182 # "info watch" is the same as "info break"
183
184 send_gdb "info watch\n"
185 gdb_expect {
186 -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$gdb_prompt $" {
187 pass "watchpoint found in watchpoint/breakpoint table"
188 }
189 -re ".*$gdb_prompt $" {
190 fail "watchpoint found in watchpoint/breakpoint table"
191 }
192 timeout {
193 fail "watchpoint found in watchpoint/breakpoint table"
194 }
195 }
196
197 # After installing the watchpoint, we disable it until we are ready
198 # to use it. This allows the test program to run at full speed until
199 # we get to the first marker function.
200
201 send_gdb "disable 3\n"
202 gdb_expect {
203 -re "disable 3\[\r\n\]+$gdb_prompt $" { pass "disable watchpoint" }
204 -re ".*$gdb_prompt $" { fail "disable watchpoint" }
205 timeout { fail "disable watchpoint (timeout)" }
206 }
207 }
208
209 # After reaching the marker function, enable the watchpoint.
210
211 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] {
212 return ;
213 }
214
215
216 gdb_test "break func1" "Breakpoint.*at.*"
217 gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
218
219 gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \
220 "continue to breakpoint at func1"
221
222 # Continue until the first change, from -1 to 0
223
224 send_gdb "cont\n"
225 gdb_expect {
226 -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
227 pass "watchpoint hit, first time"
228 }
229 -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
230 setup_xfail "m68*-*-*" 2597
231 fail "thought it hit breakpoint at func1 twice"
232 gdb_test "delete \$func1_breakpoint_number" ""
233 gdb_test "continue" "\
234 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
235 "watchpoint hit, first time"
236 }
237 -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
238 timeout { fail "watchpoint hit, first time (timeout)" ; return }
239 eof { fail "watchpoint hit, first time (eof)" ; return }
240 }
241
242 # Check that the hit count is reported correctly
243 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 1 time.*" "Watchpoint hit count is 1"
244
245 gdb_test "delete \$func1_breakpoint_number" ""
246
247 # Continue until the next change, from 0 to 1.
248 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
249
250 # Check that the hit count is reported correctly
251 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 2 times.*" "Watchpoint hit count is 2"
252
253 # Continue until the next change, from 1 to 2.
254 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
255
256 # Check that the hit count is reported correctly
257 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 3 times.*" "Watchpoint hit count is 3"
258
259 # Continue until the next change, from 2 to 3.
260 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
261
262 # Check that the hit count is reported correctly
263 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 4 times.*" "Watchpoint hit count is 4"
264
265 # Continue until the next change, from 3 to 4.
266 # Note that this one is outside the loop.
267
268 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
269
270 # Check that the hit count is reported correctly
271 gdb_test "info break" ".*watchpoint\[ \t\]+keep\[ \t\]+y\[ \t\]+ival3\r\n\[ \t]+breakpoint already hit 5 times.*" "Watchpoint hit count is 5"
272
273 # Continue until we hit the finishing marker function.
274 # Make sure we hit no more watchpoints.
275
276 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
277 "continue to marker2"
278
279 # Disable the watchpoint so we run at full speed until we exit.
280
281 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] {
282 return ;
283 }
284
285
286 # Run until process exits.
287
288 if [target_info exists gdb,noresults] { return }
289
290 gdb_continue_to_end "continue to exit in test_simple_watchpoint"
291 }
292
293 # Test disabling watchpoints.
294
295 proc test_disabling_watchpoints {} {
296 global gdb_prompt
297 global binfile
298 global srcfile
299 global decimal
300 global hex
301
302 # "info watch" is the same as "info break"
303 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"
304
305 # Ensure that the watchpoint is disabled when we startup.
306
307 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] {
308 return 0;
309 }
310
311
312 # Run until we get to the first marker function.
313
314 gdb_run_cmd
315 set timeout 600
316 gdb_expect {
317 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
318 pass "run to marker1 in test_disabling_watchpoints"
319 }
320 -re ".*$gdb_prompt $" {
321 fail "run to marker1 in test_disabling_watchpoints"
322 return
323 }
324 timeout {
325 fail "run to marker1 in test_disabling_watchpoints (timeout)"
326 return
327 }
328 }
329
330 # After reaching the marker function, enable the watchpoint.
331
332 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] {
333 return ;
334 }
335
336
337 # Continue until the first change, from -1 to 0
338 # Don't check the old value, because on VxWorks the variable value
339 # will not have been reinitialized.
340 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
341
342 # Continue until the next change, from 0 to 1.
343 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"
344
345 # Disable the watchpoint but leave breakpoints
346
347 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] {
348 return 0;
349 }
350
351
352 # Check watchpoint list, looking for the entry that confirms the
353 # watchpoint is disabled.
354 gdb_test "info watchpoints" "\[0-9]+\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
355
356 # Continue until we hit the finishing marker function.
357 # Make sure we hit no more watchpoints.
358 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
359 "disabled watchpoint skipped"
360
361 if [target_info exists gdb,noresults] { return }
362
363 gdb_continue_to_end "continue to exit in test_disabling_watchpoints"
364 }
365
366 # Test stepping and other mundane operations with watchpoints enabled
367 proc test_stepping {} {
368 global gdb_prompt
369
370 if [runto marker1] then {
371 gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
372
373 # Well, let's not be too mundane. It should be a *bit* of a challenge
374 gdb_test "break func2 if 0" "Breakpoint.*at.*"
375 gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
376
377 # The problem is that GDB confuses stepping through the call
378 # dummy with hitting the breakpoint at the end of the call dummy.
379 # Will be fixed once all architectures define
380 # CALL_DUMMY_BREAKPOINT_OFFSET.
381 setup_xfail "*-*-*"
382 # This doesn't occur if the call dummy starts with a call,
383 # because we are out of the dummy by the first time the inferior
384 # stops.
385 clear_xfail "arm*-*-*"
386 clear_xfail "d10v*-*-*"
387 clear_xfail "m68*-*-*"
388 clear_xfail "i*86*-*-*"
389 clear_xfail "vax-*-*"
390 # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
391 clear_xfail "alpha-*-*"
392 clear_xfail "mips*-*-*"
393 clear_xfail "sparc-*-*"
394 clear_xfail "hppa*-*-*bsd*"
395 # It works with the generic inferior function calling code too.
396 clear_xfail "mn10200*-*-*"
397 clear_xfail "mn10300*-*-*"
398 # The following architectures define CALL_DUMMY_HAS_COMPLETED.
399 clear_xfail "hppa*-*-*hpux*"
400 gdb_test "p func1 ()" "= 73" \
401 "calling function with watchpoint enabled"
402
403 #
404 # "finish" brings us back to main.
405 # On some targets (e.g. alpha) gdb will stop from the finish in midline
406 # of the marker1 call. This is due to register restoring code on
407 # the alpha and might be caused by stack adjustment instructions
408 # on other targets. In this case we will step once more.
409 #
410
411 send_gdb "finish\n"
412 gdb_expect {
413 -re "Run.*exit from.*marker1.* at" {
414 pass "finish from marker1"
415 }
416 default { fail "finish from marker1 (timeout)" ; return }
417 }
418
419 gdb_expect {
420 -re "marker1 \\(\\);.*$gdb_prompt $" {
421 send_gdb "step\n"
422 exp_continue
423 }
424 -re "func1 \\(\\);.*$gdb_prompt $" {
425 pass "back at main from marker1"
426 }
427 -re ".*$gdb_prompt $" {
428 fail "back at main from marker1"
429 }
430 default { fail "back at main from marker1 (timeout)" ; return }
431 }
432
433 gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
434
435 # Now test that "until" works. It's a bit tricky to test
436 # "until", because compilers don't always arrange the code
437 # exactly the same way, and we might get slightly different
438 # sequences of statements. But the following should be true
439 # (if not it is a compiler or a debugger bug): The user who
440 # does "until" at every statement of a loop should end up
441 # stepping through the loop once, and the debugger should not
442 # stop for any of the remaining iterations.
443
444 gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
445 gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
446 send_gdb "until\n"
447 gdb_expect {
448 -re "(for \\(count = 0|\}).*$gdb_prompt $" {
449 gdb_test "until" "ival1 = count; /. Outside loop ./" \
450 "until out of loop"
451 }
452 -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
453 pass "until out of loop"
454 }
455 -re ".*$gdb_prompt $" {
456 fail "until out of loop"
457 }
458 default { fail "until out of loop (timeout)" ; return }
459 }
460
461 gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
462 }
463 }
464
465 # Test stepping and other mundane operations with watchpoints enabled
466 proc test_watchpoint_triggered_in_syscall {} {
467 global gdb_prompt
468
469 # These tests won't work without printf support.
470 if [gdb_skip_stdio_test "watchpoints triggered in syscall"] {
471 return;
472 }
473 # Run until we get to the first marker function.
474 set x 0
475 set y 0
476 set testname "Watch buffer passed to read syscall"
477 if [runto marker2] then {
478 gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
479 gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
480 gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
481 gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
482 gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
483 gdb_test "break marker4" ".*Breakpoint.*"
484
485 gdb_test "set doread = 1" ""
486
487 # If we send_gdb "123\n" before gdb has switched the tty, then it goes
488 # to gdb, not the inferior, and we lose. So that is why we have
489 # watchpoint.c prompt us, so we can wait for that prompt.
490 send_gdb "continue\n";
491 gdb_expect {
492 -re "Continuing\\.\r\ntype stuff for buf now:" {
493 pass "continue to read"
494 }
495 default {
496 fail "continue to read";
497 return ;
498 }
499 }
500
501 send_gdb "123\n"
502 gdb_expect {
503 -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
504 -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
505 -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
506 -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
507 -re ".*$gdb_prompt $" { pass "sent 123" }
508 timeout { fail "sent 123 (timeout)" }
509 }
510
511 # Examine the values in buf to see how many watchpoints we
512 # should have printed.
513 send_gdb "print buf\[0\]\n"
514 gdb_expect {
515 -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
516 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
517 -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
518 default { fail "print buf\[0\]"}
519 }
520 send_gdb "print buf\[1\]\n"
521 gdb_expect {
522 -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
523 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
524 -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
525 default { fail "print buf\[1\]"}
526 }
527 send_gdb "print buf\[2\]\n"
528 gdb_expect {
529 -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
530 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
531 -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
532 default { fail "print buf\[2\]"}
533 }
534 send_gdb "print buf\[3\]\n"
535 gdb_expect {
536 -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
537 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
538 -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
539 default { fail "print buf\[3\]" }
540 }
541
542 # Did we find what we were looking for? If not, flunk it.
543 if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
544
545 # Continue until we hit the finishing marker function.
546 # Make sure we hit no more watchpoints.
547 gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
548 "continue to marker4"
549
550 # Disable everything so we can finish the program at full speed
551 gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
552
553 if [target_info exists gdb,noresults] { return }
554
555 gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall"
556 }
557 }
558
559 # Do a simple test of of watching through a pointer when the pointer
560 # itself changes. Should add some more complicated stuff here.
561
562 proc test_complex_watchpoint {} {
563 global gdb_prompt
564
565 if [runto marker4] then {
566 gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
567 gdb_test "break marker5" ".*Breakpoint.*"
568
569 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
570
571 # Continue until we hit the marker5 function.
572 # Make sure we hit no more watchpoints.
573
574 gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
575 "did not trigger wrong watchpoint"
576
577 # Test watches of things declared locally in a function.
578 # In particular, test that a watch of stack-based things
579 # is deleted when the stack-based things go out of scope.
580 #
581 gdb_test "disable" "" "disable in test_complex_watchpoint"
582 gdb_test "break marker6" ".*Breakpoint.*"
583 gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \
584 "continue to marker6"
585 gdb_test "break func2" ".*Breakpoint.*"
586 gdb_test "cont" "Continuing.*func2.*"
587
588 # Test a watch of a single stack-based variable, whose scope
589 # is the function we're now in. This should auto-delete when
590 # execution exits the scope of the watchpoint.
591 #
592 gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch"
593 gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch"
594 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" "self-delete local watch"
595
596 gdb_test "cont" "Continuing.*func2.*"
597 # We should be in "func2" again now. Test a watch of an
598 # expression which includes both a stack-based local and
599 # something whose scope is larger than this invocation
600 # of "func2". This should also auto-delete.
601 #
602 gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \
603 "set partially local watch"
604 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
605 "trigger1 partially local watch"
606 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
607 "trigger2 partially local watch"
608 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
609 "self-delete partially local watch"
610
611 # We should be in "func2" again now. Test a watch of a
612 # static (non-stack-based) local. Since this has scope
613 # across any invocations of "func2", it should not auto-
614 # delete.
615 #
616 gdb_test "cont" "Continuing.*func2.*"
617 gdb_test "watch static_b" ".*\[Ww\]atchpoint \[0-9\]*: static_b" \
618 "set static local watch"
619 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: static_b.*" \
620 "trigger static local watch"
621 gdb_test "cont" "Continuing.*marker6 \\(\\).*" \
622 "continue after trigger static local watch"
623 gdb_test "info break" ".*watchpoint.*static_b.*" \
624 "static local watch did not self-delete"
625
626 # We should be in "recurser" now. Test a watch of a stack-
627 # based local. Symbols mentioned in a watchpoint are bound
628 # at watchpoint-creation. Thus, a watch of a stack-based
629 # local to a recursing function should be bound only to that
630 # one invocation, and should not trigger for other invocations.
631 #
632 gdb_test "tbreak recurser" ".*Breakpoint.*"
633 gdb_test "cont" "Continuing.*recurser.*"
634 gdb_test "watch local_x" ".*\[Ww\]atchpoint \[0-9\]*: local_x" \
635 "set local watch in recursive call"
636 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_x.*New value = 2.*" \
637 "trigger local watch in recursive call"
638 gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
639 "self-delete local watch in recursive call"
640
641 # Disable everything so we can finish the program at full speed
642 gdb_test "disable" "" "disable in test_complex_watchpoint"
643
644 if [target_info exists gdb,noresults] { return }
645
646 gdb_continue_to_end "continue to exit in test_complex_watchpoint"
647 }
648 }
649
650 # Start with a fresh gdb.
651
652 gdb_exit
653 gdb_start
654 gdb_reinitialize_dir $srcdir/$subdir
655 gdb_load $binfile
656 set timeout 600
657 verbose "Timeout now 600 sec.\n"
658
659 if [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 }
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 }
800 }