import gdb-1999-10-11 snapshot
[external/binutils.git] / gdb / testsuite / gdb.base / watchpoint.exp
1 # Copyright (C) 1992, 1994, 1997, 1998 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Fred Fish. (fnf@cygnus.com)
21
22 if $tracelevel then {
23     strace $tracelevel
24 }
25
26 set prms_id 0
27 set bug_id 0
28
29 set testfile "watchpoint"
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
32
33 set wp_set 1
34
35 if [get_compiler_info ${binfile}] {
36     return -1
37 }
38
39 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41 }
42
43 # Prepare for watchpoint tests by setting up two breakpoints and one
44 # watchpoint.
45 #
46 # We use breakpoints at marker functions to get past all the startup code,
47 # so we can get to the watchpoints in a reasonable amount of time from a
48 # known starting point.
49 #
50 # For simplicity, so we always know how to reference specific breakpoints or
51 # watchpoints by number, we expect a particular ordering and numbering of
52 # each in the combined breakpoint/watchpoint table, as follows:
53 #
54 #       Number          What            Where
55 #       1               Breakpoint      marker1()
56 #       2               Breakpoint      marker2()
57 #       3               Watchpoint      ival3
58
59 proc initialize {} {
60     global gdb_prompt
61     global hex
62     global decimal
63     global srcfile
64     global wp_set
65
66     if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] { 
67       return 0; 
68     }
69
70
71     if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] { 
72       return 0; 
73     }
74
75
76     if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] { 
77       return 0; 
78     }
79
80
81     # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
82     # before running can cause the inferior to croak on HP-UX 11.0 for
83     # reasons yet unknown, we've disabled the ability to set watches
84     # without a running inferior.  Verify the restriction. 
85     #
86     send_gdb "watch ival3\n"
87     gdb_expect {
88         -re ".*\[Ww\]atchpoint 3: ival3.*$gdb_prompt $" {
89             pass "set watchpoint on ival3"
90         }
91         -re "warning: can't do that without a running program; try \"break main\", \"run\" first.*$gdb_prompt $" {
92             pass "set watchpoint on ival3"
93             set wp_set 0
94             return 1
95         }
96         timeout {
97             fail "(timeout) set watchpoint on ival3"
98             return 0
99         }
100     }
101
102     # "info watch" is the same as "info break"
103
104     if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] { 
105       return 0; 
106     }
107
108
109     # After installing the watchpoint, we disable it until we are ready
110     # to use it.  This allows the test program to run at full speed until
111     # we get to the first marker function.
112
113     if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] { 
114       return 0; 
115     }
116
117
118     return 1
119 }
120
121 #
122 # Test simple watchpoint.
123 #
124
125 proc test_simple_watchpoint {} {
126     global gdb_prompt
127     global hex
128     global decimal
129     global wp_set
130
131     # Ensure that the watchpoint is disabled when we startup.
132
133     if { $wp_set } {
134         if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] { 
135             return 0; 
136         }
137     }
138
139
140     # Run until we get to the first marker function.
141
142     gdb_run_cmd
143     set timeout 600
144     gdb_expect {
145         -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
146             pass "run to marker1 in test_simple_watchpoint"
147         }
148         -re ".*$gdb_prompt $" {
149             fail "run to marker1 in test_simple_watchpoint"
150             return
151         }
152         timeout {
153             fail "run to marker1 in test_simple_watchpoint (timeout)"
154             return
155         }
156     }
157
158     if { !$wp_set } {
159         # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
160         # before running can cause the inferior to croak on HP-UX 11.0
161         # for reasons yet unknown, we've disabled the ability to set 
162         # watches without a running inferior.  The following testpoints used
163         # to be in [initialize].
164         #
165         send_gdb "watch ival3\n"
166         gdb_expect {
167             -re ".*\[Ww\]atchpoint 3: ival3\r\n$gdb_prompt $" { 
168                 pass "set watchpoint on ival3"
169             }
170             -re ".*$gdb_prompt $" { fail "set watchpoint on ival3"  }
171             timeout { fail "set watchpoint on ival3 (timeout)"  }
172         }
173
174         set wp_set 1
175
176         # "info watch" is the same as "info break"
177
178         send_gdb "info watch\n"
179         gdb_expect {
180             -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$gdb_prompt $" {
181                 pass "watchpoint found in watchpoint/breakpoint table"
182             }
183             -re ".*$gdb_prompt $" {
184                 fail "watchpoint found in watchpoint/breakpoint table"
185             }
186             timeout {
187                fail "watchpoint found in watchpoint/breakpoint table"
188             }
189         }
190
191         # After installing the watchpoint, we disable it until we are ready
192         # to use it.  This allows the test program to run at full speed until
193         # we get to the first marker function.
194
195         send_gdb "disable 3\n"
196         gdb_expect {
197             -re "disable 3\[\r\n\]+$gdb_prompt $" { pass "disable watchpoint" }
198             -re ".*$gdb_prompt $" { fail "disable watchpoint"  }
199             timeout { fail "disable watchpoint (timeout)"  }
200         }
201     }
202
203     # After reaching the marker function, enable the watchpoint.
204
205     if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] { 
206       return ; 
207     }
208
209
210     gdb_test "break func1" "Breakpoint.*at.*"
211     gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
212
213     gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \
214         "continue to breakpoint at func1"
215
216     # Continue until the first change, from -1 to 0
217
218     send_gdb "cont\n"
219     gdb_expect {
220         -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
221             pass "watchpoint hit, first time"
222         }
223         -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
224             setup_xfail "m68*-*-*" 2597
225             fail "thought it hit breakpoint at func1 twice"
226             gdb_test "delete \$func1_breakpoint_number" ""
227             gdb_test "continue" "\
228 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
229                 "watchpoint hit, first time"
230         }
231         -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
232         timeout { fail "watchpoint hit, first time (timeout)" ; return }
233         eof { fail "watchpoint hit, first time (eof)" ; return }
234     }
235
236     gdb_test "delete \$func1_breakpoint_number" ""
237
238     # Continue until the next change, from 0 to 1.
239     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
240
241     # Continue until the next change, from 1 to 2.
242     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
243     
244     # Continue until the next change, from 2 to 3.
245     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
246
247     # Continue until the next change, from 3 to 4.
248     # Note that this one is outside the loop.
249
250     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
251
252     # Continue until we hit the finishing marker function.
253     # Make sure we hit no more watchpoints.
254
255     gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
256         "continue to marker2"
257
258     # Disable the watchpoint so we run at full speed until we exit.
259
260     if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] { 
261       return ; 
262     }
263
264
265     # Run until process exits.
266
267     if [target_info exists gdb,noresults] { return }
268
269     gdb_continue_to_end "continue to exit in test_simple_watchpoint"
270 }
271
272 # Test disabling watchpoints.
273
274 proc test_disabling_watchpoints {} {
275     global gdb_prompt
276     global binfile
277     global srcfile
278     global decimal
279     global hex
280
281     # "info watch" is the same as "info break"
282     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"
283
284     # Ensure that the watchpoint is disabled when we startup.
285
286     if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] { 
287       return 0; 
288     }
289
290
291     # Run until we get to the first marker function.
292
293     gdb_run_cmd
294     set timeout 600
295     gdb_expect {
296         -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
297             pass "run to marker1 in test_disabling_watchpoints"
298         }
299         -re ".*$gdb_prompt $" {
300             fail "run to marker1 in test_disabling_watchpoints"
301             return
302         }
303         timeout {
304             fail "run to marker1 in test_disabling_watchpoints (timeout)"
305             return
306         }
307     }
308
309     # After reaching the marker function, enable the watchpoint.
310
311     if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] { 
312       return ; 
313     }
314
315
316     # Continue until the first change, from -1 to 0
317     # Don't check the old value, because on VxWorks the variable value
318     # will not have been reinitialized.
319     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
320     
321     # Continue until the next change, from 0 to 1.
322     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"
323     
324     # Disable the watchpoint but leave breakpoints
325
326     if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] { 
327       return 0; 
328     }
329
330
331     # Check watchpoint list, looking for the entry that confirms the
332     # watchpoint is disabled.
333     gdb_test "info watchpoints" "\[0-9]+\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
334
335     # Continue until we hit the finishing marker function.
336     # Make sure we hit no more watchpoints.
337     gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
338         "disabled watchpoint skipped"
339     
340     if [target_info exists gdb,noresults] { return }
341
342     gdb_continue_to_end "continue to exit in test_disabling_watchpoints"
343 }
344
345 # Test stepping and other mundane operations with watchpoints enabled
346 proc test_stepping {} {
347     global gdb_prompt
348
349     if [runto marker1] then {
350         gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
351
352         # Well, let's not be too mundane.  It should be a *bit* of a challenge
353         gdb_test "break func2 if 0" "Breakpoint.*at.*"
354         gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
355
356         # The problem is that GDB confuses stepping through the call
357         # dummy with hitting the breakpoint at the end of the call dummy.
358         # Will be fixed once all architectures define 
359         # CALL_DUMMY_BREAKPOINT_OFFSET.
360         setup_xfail "*-*-*"
361         # This doesn't occur if the call dummy starts with a call,
362         # because we are out of the dummy by the first time the inferior
363         # stops.
364         clear_xfail "d10v*-*-*"
365         clear_xfail "m68*-*-*"
366         clear_xfail "i*86*-*-*"
367         clear_xfail "vax-*-*"
368         # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
369         clear_xfail "alpha-*-*"
370         clear_xfail "mips*-*-*"
371         clear_xfail "sparc-*-*"
372         clear_xfail "hppa*-*-*bsd*"
373         # It works with the generic inferior function calling code too.
374         clear_xfail "mn10200*-*-*"
375         clear_xfail "mn10300*-*-*"
376         # The following architectures define CALL_DUMMY_HAS_COMPLETED.
377         clear_xfail "hppa*-*-*hpux*"
378         gdb_test "p func1 ()" "= 73" \
379         "calling function with watchpoint enabled"
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 {
391             -re "Run.*exit from.*marker1.* at" {
392                 pass "finish from marker1"
393             }
394             default { fail "finish from marker1" ; return }
395         }
396
397         gdb_expect {
398             -re "marker1 \\(\\);.*$gdb_prompt $" {
399                 send_gdb "step\n"
400                 exp_continue
401             }
402             -re "func1 \\(\\);.*$gdb_prompt $" {
403                 pass "finish from marker1"
404             }
405             -re ".*$gdb_prompt $" {
406                 fail "finish from marker1"
407             }
408             default { fail "finish from marker1" ; return }
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             }
436             default { fail "until out of loop" ; return }
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
444 proc test_watchpoint_triggered_in_syscall {} {
445     global gdb_prompt
446
447     if [target_info exists gdb,noinferiorio] {
448         verbose "Skipping test_watchpoint_triggered_in_syscall due to noinferiorio"
449         return
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
533         gdb_continue_to_end "continue to exit in test_watchpoint_triggered_in_syscall"
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
540 proc 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
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
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
624         gdb_continue_to_end "continue to exit in test_complex_watchpoint"
625     }
626 }
627
628 # Start with a fresh gdb.
629
630 gdb_exit
631 gdb_start
632 gdb_reinitialize_dir $srcdir/$subdir
633 gdb_load $binfile
634 set timeout 600 
635 verbose "Timeout now 600 sec.\n"
636
637 if [initialize] then {
638
639     test_simple_watchpoint
640
641     # The IDT/sim monitor only has 8 (!) open files, of which it uses
642     # 4 (!).  So we have to make sure one program exits before
643     # starting another one.
644     if [istarget "mips-idt-*"] then {
645         gdb_exit
646         gdb_start
647         gdb_reinitialize_dir $srcdir/$subdir
648         gdb_load $binfile
649         initialize
650     }
651
652     test_disabling_watchpoints
653
654     # See above.
655     if [istarget "mips-idt-*"] then {
656         gdb_exit
657         gdb_start
658         gdb_reinitialize_dir $srcdir/$subdir
659         gdb_load $binfile
660         initialize
661     }
662
663     if ![target_info exists gdb,cannot_call_functions] {
664         test_stepping
665
666         # See above.
667         if [istarget "mips-idt-*"] then {
668             gdb_exit
669             gdb_start
670             gdb_reinitialize_dir $srcdir/$subdir
671             gdb_load $binfile
672             initialize
673         }
674     }
675
676     # Only enabled for some targets merely because it has not been tested 
677     # elsewhere.
678     # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4 
679     # breakpoint before stopping for the watchpoint.  I don't know why.
680     if {[istarget "hppa*-*-*"]} then {
681         test_watchpoint_triggered_in_syscall
682     }
683
684     # See above.
685     if [istarget "mips-idt-*"] then {
686         gdb_exit
687         gdb_start
688         gdb_reinitialize_dir $srcdir/$subdir
689         gdb_load $binfile
690         initialize
691     }
692
693     # Only enabled for some targets merely because it has not been tested 
694     # elsewhere.
695     if {[istarget "hppa*-*-*"] || \
696             [istarget "sparc*-*-sunos*"] || \
697             [istarget "m32r-*-*"]} then {
698         test_complex_watchpoint
699     }
700
701     # Verify that a user can force GDB to use "slow" watchpoints.
702     # (This proves rather little on kernels that don't support
703     # fast watchpoints, but still...)
704     #
705     if ![runto_main] then { fail "watch tests suppressed" }
706
707     send_gdb "set can-use-hw-watchpoints 0\n"
708     gdb_expect {
709       -re "$gdb_prompt $"\
710               {pass "disable fast watches"}
711       timeout {fail "(timeout) disable fast watches"}
712     }
713     send_gdb "show can-use-hw-watchpoints\n"
714     gdb_expect {
715       -re "Debugger's willingness to use watchpoint hardware is 0.*$gdb_prompt $"\
716               {pass "show disable fast watches"}
717       -re "$gdb_prompt $"\
718               {fail "show disable fast watches"}
719       timeout {fail "(timeout) show disable fast watches"}
720     }
721     send_gdb "watch ival3 if  count > 1\n"
722     gdb_expect {
723       -re "Watchpoint \[0-9\]*: ival3.*$gdb_prompt $"\
724               {pass "set slow conditional watch"}
725       -re "$gdb_prompt $"\
726               {fail "set slow conditional watch"}
727       timeout {fail "(timeout) set slow conditional watch"}
728     }
729     send_gdb "continue\n"
730     gdb_expect {
731       -re "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*$gdb_prompt $"\
732               {pass "trigger slow conditional watch"}
733       -re "$gdb_prompt $"\
734               {fail "trigger slow conditional watch"}
735       timeout {fail "(timeout) trigger slow conditional watch"}
736     }
737
738     # We've explicitly disabled hardware watches.  Verify that GDB
739     # 
740     #
741     send_gdb "rwatch ival3\n"
742     gdb_expect {
743       -re "Expression cannot be implemented with read/access watchpoint..*$gdb_prompt $"\
744               {pass "rwatch disallowed when can-set-hw-watchpoints cleared"}
745       -re "$gdb_prompt $"\
746               {fail "rwatch disallowed when can-set-hw-watchpoints cleared"}
747       timeout {fail "(timeout) rwatch disallowed when can-use-hw-watchpoints cleared"}
748     }
749
750     # Read- and access watchpoints are unsupported on HP-UX.  Verify
751     # that GDB gracefully responds to requests to create them.
752     #
753     if [istarget "hppa*-*-hpux*"] then {
754       send_gdb "set can-use-hw-watchpoints 1\n"
755       gdb_expect {
756         -re "$gdb_prompt $"\
757                 {pass "enable fast watches"}
758         timeout {fail "(timeout) enable fast watches"}
759       }
760       send_gdb "rwatch ival3\n"
761       gdb_expect {
762         -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
763                 {pass "read watches disallowed"}
764         -re "$gdb_prompt $"\
765                 {fail "read watches disallowed"}
766         timeout {fail "(timeout) read watches disallowed"}
767       }
768
769       send_gdb "awatch ival3\n"
770       gdb_expect {
771         -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
772                 {pass "access watches disallowed"}
773         -re "$gdb_prompt $"\
774                 {fail "access watches disallowed"}
775         timeout {fail "(timeout) access watches disallowed"}
776       }
777     }
778 }