OSDN Git Service

import gdb-19990422 snapshot
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.hp / watch-hp.exp
1 # Copyright (C) 1992, 1994, 1997 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 if { [skip_hp_tests] } then { continue }
27
28 set prms_id 0
29 set bug_id 0
30
31 set testfile "watch-hp"
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
34 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
35      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
36 }
37
38 if [get_compiler_info ${binfile}] {
39     return -1;
40 }
41 if { $gcc_compiled } then { continue }
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
65     if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] { 
66       return 0; 
67     }
68
69
70     if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] { 
71       return 0; 
72     }
73
74
75     if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] { 
76       return 0; 
77     }
78
79 # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
80 # before running can cause the inferior to croak on HP-UX 10.30 and
81 # 11.0 for reasons as yet unknown, we've disabled the ability to set
82 # watches without a running inferior.  Verify the restriction.
83 #
84     send_gdb "watch ival3\n"
85     gdb_expect {
86         -re ".*can't do that without a running program; try \"break main\", \"run\" first.*$gdb_prompt $" {
87             pass "set watchpoint on ival3"
88         }
89         -re ".*$gdb_prompt $" { fail "set watchpoint on ival3"  }
90         timeout { fail "set watchpoint on ival3 (timeout)"  }
91     }
92
93
94 #    if [gdb_test "watch ival3" ".*\[Ww\]atchpoint 3: ival3" "set watchpoint on ival3" ] { 
95 #      return 0; 
96 #    }
97
98
99     # "info watch" is the same as "info break"
100
101 #    if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] { 
102 #      return 0; 
103 #    }
104
105
106     # After installing the watchpoint, we disable it until we are ready
107     # to use it.  This allows the test program to run at full speed until
108     # we get to the first marker function.
109
110 #    if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] { 
111 #      return 0; 
112 #    }
113
114
115     return 1
116 }
117
118 #
119 # Test simple watchpoint.
120 #
121
122 proc test_simple_watchpoint {} {
123     global gdb_prompt
124     global hex
125     global decimal
126
127     # Ensure that the watchpoint is disabled when we startup.
128
129 #    if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] { 
130 #      return 0; 
131 #    }
132
133
134     # Run until we get to the first marker function.
135
136     gdb_run_cmd
137     set timeout 600
138     gdb_expect {
139         -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
140             pass "run to marker1 in test_simple_watchpoint"
141         }
142         -re ".*$gdb_prompt $" {
143             fail "run to marker1 in test_simple_watchpoint"
144             return
145         }
146         timeout {
147             fail "run to marker1 in test_simple_watchpoint (timeout)"
148             return
149         }
150     }
151 #************************
152
153 # ??rehrauer: To fix DTS #CHFts23014, in which setting a watchpoint
154 # before running can cause the inferior to croak on HP-UX 10.30 and
155 # 11.0 for reasons as yet unknown, we've disabled the ability to set
156 # watches without a running inferior.  The following testpoints used
157 # to be in [initialize].
158 #
159     send_gdb "watch ival3\n"
160     gdb_expect {
161         -re ".*\[Ww\]atchpoint 3: ival3\r\n$gdb_prompt $" { 
162             pass "set watchpoint on ival3"
163         }
164         -re ".*$gdb_prompt $" { fail "set watchpoint on ival3"  }
165         timeout { fail "set watchpoint on ival3 (timeout)"  }
166     }
167
168     # "info watch" is the same as "info break"
169
170     send_gdb "info watch\n"
171     gdb_expect {
172         -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$gdb_prompt $" {
173             pass "watchpoint found in watchpoint/breakpoint table"
174         }
175         -re ".*$gdb_prompt $" {
176             fail "watchpoint found in watchpoint/breakpoint table" 
177         }
178         timeout {
179            fail "watchpoint found in watchpoint/breakpoint table" 
180         }
181     }
182
183     # After installing the watchpoint, we disable it until we are ready
184     # to use it.  This allows the test program to run at full speed until
185     # we get to the first marker function.
186
187     send_gdb "disable 3\n"
188     gdb_expect {
189         -re "disable 3\[\r\n\]+$gdb_prompt $" { pass "disable watchpoint" }
190         -re ".*$gdb_prompt $" { fail "disable watchpoint"  }
191         timeout { fail "disable watchpoint (timeout)"  }
192     }
193 #******
194     # After reaching the marker function, enable the watchpoint.
195
196     if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] { 
197       return ; 
198     }
199
200
201     gdb_test "break func1" "Breakpoint.*at.*"
202     gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
203
204     gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \
205         "continue to breakpoint at func1"
206
207     # Continue until the first change, from -1 to 0
208
209     send_gdb "cont\n"
210     gdb_expect {
211         -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
212             pass "watchpoint hit, first time"
213         }
214         -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
215             setup_xfail "m68*-*-*" 2597
216             fail "thought it hit breakpoint at func1 twice"
217             gdb_test "delete \$func1_breakpoint_number" ""
218             gdb_test "continue" "\
219 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
220                 "watchpoint hit, first time"
221         }
222         -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
223         timeout { fail "watchpoint hit, first time (timeout)" ; return }
224         eof { fail "watchpoint hit, first time (eof)" ; return }
225     }
226
227     gdb_test "delete \$func1_breakpoint_number" ""
228
229     # Continue until the next change, from 0 to 1.
230     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
231
232     # Continue until the next change, from 1 to 2.
233     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
234     
235     # Continue until the next change, from 2 to 3.
236     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
237
238     # Continue until the next change, from 3 to 4.
239     # Note that this one is outside the loop.
240
241     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
242
243     # Continue until we hit the finishing marker function.
244     # Make sure we hit no more watchpoints.
245
246     gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
247         "continue to marker2"
248
249     # Disable the watchpoint so we run at full speed until we exit.
250
251     if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] { 
252       return ; 
253     }
254
255
256     # Run until process exits.
257
258     if [target_info exists gdb,noresults] { return }
259
260     gdb_test "cont" "Continuing.*Program exited normally.*" \
261         "continue to exit in test_simple_watchpoint"
262 }
263
264 # Test disabling watchpoints.
265
266 proc test_disabling_watchpoints {} {
267     global gdb_prompt
268     global binfile
269     global srcfile
270     global decimal
271     global hex
272
273     # Ensure that the watchpoint is disabled when we startup.
274
275     if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] { 
276       return 0; 
277     }
278
279
280     # Run until we get to the first marker function.
281
282     gdb_run_cmd
283     set timeout 600
284     gdb_expect {
285         -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
286             pass "run to marker1 in test_disabling_watchpoints"
287         }
288         -re ".*$gdb_prompt $" {
289             fail "run to marker1 in test_disabling_watchpoints"
290             return
291         }
292         timeout {
293             fail "run to marker1 in test_disabling_watchpoints (timeout)"
294             return
295         }
296     }
297
298     # After reaching the marker function, enable the watchpoint.
299
300     if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] { 
301       return ; 
302     }
303
304
305     # Continue until the first change, from -1 to 0
306     # Don't check the old value, because on VxWorks the variable value
307     # will not have been reinitialized.
308     gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
309     
310     # Continue until the next change, from 0 to 1.
311     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"
312     
313     # Disable the watchpoint but leave breakpoints
314
315     if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] { 
316       return 0; 
317     }
318
319
320     # Check watchpoint list, looking for the entry that confirms the
321     # watchpoint is disabled.
322     gdb_test "info watchpoints" "3\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
323
324     # Continue until we hit the finishing marker function.
325     # Make sure we hit no more watchpoints.
326     gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
327         "disabled watchpoint skipped"
328     
329     if [target_info exists gdb,noresults] { return }
330
331     gdb_test "cont" "Continuing.*Program exited normally.*" \
332         "continue to exit in test_disabling_watchpoints"
333 }
334
335 # Test stepping and other mundane operations with watchpoints enabled
336 proc test_stepping {} {
337     global gdb_prompt
338
339     if [runto marker1] then {
340         gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
341
342         # Well, let's not be too mundane.  It should be a *bit* of a challenge
343         gdb_test "break func2 if 0" "Breakpoint.*at.*"
344         gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
345
346         # The HPPA has a problem here if it's not using hardware watchpoints
347         if {[ istarget "hppa*-*-*" ] && ![ istarget "hppa*-*-*bsd*" ]} then {
348             # Don't actually try doing the call, if we do we can't continue.
349             setup_xfail "*-*-*"
350             fail "calling function with watchpoint enabled"
351         } else {
352             # The problem is that GDB confuses stepping through the call
353             # dummy with hitting the breakpoint at the end of the call dummy.
354             # Will be fixed once all architectures define 
355             # CALL_DUMMY_BREAKPOINT_OFFSET.
356             setup_xfail "*-*-*"
357             # This doesn't occur if the call dummy starts with a call,
358             # because we are out of the dummy by the first time the inferior
359             # stops.
360             clear_xfail "d10v*-*-*"
361             clear_xfail "m68*-*-*"
362             clear_xfail "i*86*-*-*"
363             clear_xfail "vax-*-*"
364             # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
365             clear_xfail "alpha-*-*"
366             clear_xfail "mips*-*-*"
367             clear_xfail "sparc-*-*"
368             clear_xfail "hppa*-*-*bsd*"
369             # It works with the generic inferior function calling code too.
370             clear_xfail "mn10200*-*-*"
371             clear_xfail "mn10300*-*-*"
372             gdb_test "p func1 ()" "= 73" \
373                 "calling function with watchpoint enabled"
374         }
375
376         # 
377         # "finish" brings us back to main.
378         # On some targets (e.g. alpha) gdb will stop from the finish in midline
379         # of the marker1 call. This is due to register restoring code on
380         # the alpha and might be caused by stack adjustment instructions
381         # on other targets. In this case we will step once more.
382         #
383
384         send_gdb "finish\n"
385         gdb_expect {
386             -re "Run.*exit from.*marker1.* at" { }
387             default { fail "finish from marker1" ; return }
388         }
389
390         gdb_expect {
391             -re "marker1 \\(\\);.*$gdb_prompt $" {
392                 send_gdb "step\n"
393                 exp_continue
394             }
395             -re "func1 \\(\\);.*$gdb_prompt $" {
396                 pass "finish from marker1"
397             }
398             -re ".*$gdb_prompt $" {
399                 fail "finish from marker1"
400             }
401             default { fail "finish from marker1" ; return }
402         }
403
404         gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
405
406         # Now test that "until" works.  It's a bit tricky to test
407         # "until", because compilers don't always arrange the code
408         # exactly the same way, and we might get slightly different
409         # sequences of statements.  But the following should be true
410         # (if not it is a compiler or a debugger bug): The user who
411         # does "until" at every statement of a loop should end up
412         # stepping through the loop once, and the debugger should not
413         # stop for any of the remaining iterations.
414
415         gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
416         gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
417         send_gdb "until\n"
418         gdb_expect {
419             -re "(for \\(count = 0|\}).*$gdb_prompt $" {
420                 gdb_test "until" "ival1 = count; /. Outside loop ./" \
421                     "until out of loop"
422             }
423             -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
424                 pass "until out of loop"
425             }
426             -re ".*$gdb_prompt $" {
427                 fail "until out of loop"
428             }
429             default { fail "until out of loop" ; return }
430         }
431
432         gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
433     }
434 }
435
436 # Test stepping and other mundane operations with watchpoints enabled
437 proc test_watchpoint_triggered_in_syscall {} {
438     global gdb_prompt
439
440     if [target_info exists gdb,noinferiorio] {
441         verbose "Skipping test_watchpoint_triggered_in_syscall due to noinferiorio"
442         return
443     }
444     # Run until we get to the first marker function.
445     set x 0
446     set y 0
447     set testname "Watch buffer passed to read syscall"
448     if [runto marker2] then {
449         gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
450         gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
451         gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
452         gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
453         gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
454         gdb_test "break marker4" ".*Breakpoint.*"
455
456         gdb_test "set doread = 1" ""
457
458         # If we send_gdb "123\n" before gdb has switched the tty, then it goes
459         # to gdb, not the inferior, and we lose.  So that is why we have
460         # watchpoint.c prompt us, so we can wait for that prompt.
461         send_gdb "continue\n";
462         gdb_expect {
463             -re "Continuing\\.\r\ntype stuff for buf now:" {
464                 pass "continue to read"
465             }
466             default {
467                 fail "continue to read";
468                 return ;
469             }
470         }
471
472         send_gdb "123\n"
473         gdb_expect {
474             -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
475             -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
476             -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
477             -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
478             -re ".*$gdb_prompt $" { pass "sent 123" }
479             timeout { fail "sent 123 (timeout)" }
480         }
481
482         # Examine the values in buf to see how many watchpoints we
483         # should have printed.
484         send_gdb "print buf\[0\]\n"
485         gdb_expect {
486             -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
487             -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
488             -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
489             default { fail "print buf\[0\]"}
490         }
491         send_gdb "print buf\[1\]\n"
492         gdb_expect {
493             -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
494             -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
495             -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
496             default { fail "print buf\[1\]"}
497         }
498         send_gdb "print buf\[2\]\n"
499         gdb_expect {
500             -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
501             -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
502             -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
503             default { fail "print buf\[2\]"}
504         }
505         send_gdb "print buf\[3\]\n"
506         gdb_expect {
507             -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
508             -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
509             -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
510             default { fail "print buf\[3\]" }
511         }
512
513         # Did we find what we were looking for?  If not, flunk it.
514         if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
515
516         # Continue until we hit the finishing marker function.
517         # Make sure we hit no more watchpoints.
518         gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
519             "continue to marker4"
520
521         # Disable everything so we can finish the program at full speed
522         gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
523
524         if [target_info exists gdb,noresults] { return }
525
526         gdb_test "cont" "Continuing.*Program exited normally.*" \
527             "continue to exit in test_watchpoint_triggered_in_syscall"
528     }
529 }
530
531 # Do a simple test of of watching through a pointer when the pointer
532 # itself changes.  Should add some more complicated stuff here.
533
534 proc test_complex_watchpoint {} {
535     global gdb_prompt
536
537     if [runto marker4] then {
538         gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
539         gdb_test "break marker5" ".*Breakpoint.*"
540
541         gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
542
543         # Continue until we hit the marker5 function.
544         # Make sure we hit no more watchpoints.
545
546         gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
547             "did not trigger wrong watchpoint"
548 #********************
549         # Test watches of things declared locally in a function.
550         # In particular, test that a watch of stack-based things
551         # is deleted when the stack-based things go out of scope.
552         #
553         gdb_test "disable" "" "disable in test_complex_watchpoint"
554         gdb_test "break marker6" ".*Breakpoint.*"
555         gdb_test "cont" "Continuing.*Breakpoint.*marker6 \\(\\).*" \
556             "continue to marker6"
557         gdb_test "break func2" ".*Breakpoint.*"
558         gdb_test "cont" "Continuing.*func2.*"
559
560         # Test a watch of a single stack-based variable, whose scope
561         # is the function we're now in.  This should auto-delete when
562         # execution exits the scope of the watchpoint.
563         #
564         gdb_test "watch local_a" ".*\[Ww\]atchpoint \[0-9\]*: local_a" "set local watch"
565         gdb_test "cont" "\[Ww\]atchpoint.*local_a.*" "trigger local watch"
566         gdb_test "cont" "Continuing.*Watchpoint .* deleted because the program has left the block in.*which its expression is valid.*" "self-delete local watch"
567
568         # after func2 returned, gdb stopped and deleted the watchpoint
569         # we're now in main, let's get to func2
570         gdb_test "cont" "Continuing.*func2.*"
571
572         # We should be in "func2" again now.  Test a watch of an
573         # expression which includes both a stack-based local and
574         # something whose scope is larger than this invocation
575         # of "func2".  This should also auto-delete.
576         #
577         gdb_test "watch local_a + ival5" ".*\[Ww\]atchpoint \[0-9\]*: local_a . ival5" \
578                  "set partially local watch"
579         gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
580                  "trigger1 partially local watch"
581         gdb_test "cont" "Continuing.*\[Ww\]atchpoint .*: local_a . ival5.*" \
582                  "trigger2 partially local watch"
583         gdb_test "cont" "Continuing.*\[Ww\]atchpoint .* deleted because the program has left the block in.*which its expression is valid.*" \
584                  "self-delete partially local watch"
585
586         # after func2 returned, gdb stopped and deleted the watchpoint
587         # we're now in main, let's get to func2
588         gdb_test "cont" "Continuing.*func2.*"
589
590         # We should be in "func2" again now.  Test a watch of a
591         # static (non-stack-based) local.  Since this has scope
592         # across any invocations of "func2", it should not auto-
593         # delete.
594         #
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
620
621
622 #******************
623         # Disable everything so we can finish the program at full speed
624         gdb_test "disable" "" "disable in test_complex_watchpoint"
625
626         if [target_info exists gdb,noresults] { return }
627
628
629         gdb_test "cont" "Continuing.*Program exited normally.*" \
630             "continue to exit in test_complex_watchpoint"
631     }
632 }
633
634 # Start with a fresh gdb.
635
636 gdb_start
637 gdb_reinitialize_dir $srcdir/$subdir
638 gdb_load $binfile
639 set timeout 600 
640 verbose "Timeout now 600 sec.\n"
641
642 if [initialize] then {
643
644     test_simple_watchpoint
645
646     # The IDT/sim monitor only has 8 (!) open files, of which it uses
647     # 4 (!).  So we have to make sure one program exits before
648     # starting another one.
649     if [istarget "mips-idt-*"] then {
650         gdb_exit
651         gdb_start
652         gdb_reinitialize_dir $srcdir/$subdir
653         gdb_load $binfile
654         initialize
655     }
656
657     test_disabling_watchpoints
658
659     # See above.
660     if [istarget "mips-idt-*"] then {
661         gdb_exit
662         gdb_start
663         gdb_reinitialize_dir $srcdir/$subdir
664         gdb_load $binfile
665         initialize
666     }
667
668     if ![target_info exists gdb,cannot_call_functions] {
669         test_stepping
670
671         # See above.
672         if [istarget "mips-idt-*"] then {
673             gdb_exit
674             gdb_start
675             gdb_reinitialize_dir $srcdir/$subdir
676             gdb_load $binfile
677             initialize
678         }
679     }
680
681     # Only enabled for some targets merely because it has not been tested 
682     # elsewhere.
683     # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4 
684     # breakpoint before stopping for the watchpoint.  I don't know why.
685     if {[istarget "hppa*-*-*"]} then {
686         test_watchpoint_triggered_in_syscall
687     }
688
689     # See above.
690     if [istarget "mips-idt-*"] then {
691         gdb_exit
692         gdb_start
693         gdb_reinitialize_dir $srcdir/$subdir
694         gdb_load $binfile
695         initialize
696     }
697
698     # Only enabled for some targets merely because it has not been tested 
699     # elsewhere.
700     if {[istarget "hppa*-*-*"] || \
701             [istarget "sparc*-*-sunos*"] || \
702             [istarget "m32r-*-*"]} then {
703         test_complex_watchpoint
704 #***************
705     }
706
707     # Verify that a user can force GDB to use "slow" watchpoints.
708     # (This proves rather little on kernels that don't support
709     # fast watchpoints, but still...)
710     #
711     if ![runto_main] then { fail "watch tests suppressed" }
712
713     send_gdb "set can-use-hw-watchpoints 0\n"
714     gdb_expect {
715       -re "$gdb_prompt $"\
716               {pass "disable fast watches"}
717       timeout {fail "(timeout) disable fast watches"}
718     }
719     send_gdb "show can-use-hw-watchpoints\n"
720     gdb_expect {
721       -re "Debugger's willingness to use watchpoint hardware is 0.*$gdb_prompt $"\
722               {pass "show disable fast watches"}
723       -re "$gdb_prompt $"\
724               {fail "show disable fast watches"}
725       timeout {fail "(timeout) show disable fast watches"}
726     }
727     send_gdb "watch ival3 if  count > 1\n"
728     gdb_expect {
729       -re "Watchpoint \[0-9\]*: ival3.*$gdb_prompt $"\
730               {pass "set slow conditional watch"}
731       -re "$gdb_prompt $"\
732               {fail "set slow conditional watch"}
733       timeout {fail "(timeout) set slow conditional watch"}
734     }
735     send_gdb "continue\n"
736     gdb_expect {
737       -re "Watchpoint \[0-9\]*: ival3.*Old value = 1.*New value = 2.*$gdb_prompt $"\
738               {pass "trigger slow conditional watch"}
739       -re "$gdb_prompt $"\
740               {fail "trigger slow conditional watch"}
741       timeout {fail "(timeout) trigger slow conditional watch"}
742     }
743
744     # We've explicitly disabled hardware watches.  Verify that GDB
745     # 
746     #
747     send_gdb "rwatch ival3\n"
748     gdb_expect {
749       -re "Expression cannot be implemented with read/access watchpoint..*$gdb_prompt $"\
750               {pass "rwatch disallowed when can-set-hw-watchpoints cleared"}
751       -re "$gdb_prompt $"\
752               {fail "rwatch disallowed when can-set-hw-watchpoints cleared"}
753       timeout {fail "(timeout) rwatch disallowed when can-use-hw-watchpoints cleared"}
754     }
755
756     # Read- and access watchpoints are unsupported on HP-UX.  Verify
757     # that GDB gracefully responds to requests to create them.
758     #
759     if [istarget "hppa*-*-hpux*"] then {
760       send_gdb "set can-use-hw-watchpoints 1\n"
761       gdb_expect {
762         -re "$gdb_prompt $"\
763                 {pass "enable fast watches"}
764         timeout {fail "(timeout) enable fast watches"}
765       }
766       send_gdb "rwatch ival3\n"
767       gdb_expect {
768         -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
769                 {pass "read watches disallowed"}
770         -re "$gdb_prompt $"\
771                 {fail "read watches disallowed"}
772         timeout {fail "(timeout) read watches disallowed"}
773       }
774
775       send_gdb "awatch ival3\n"
776       gdb_expect {
777         -re "Target does not have this type of hardware watchpoint support.*$gdb_prompt $"\
778                 {pass "access watches disallowed"}
779         -re "$gdb_prompt $"\
780                 {fail "access watches disallowed"}
781         timeout {fail "(timeout) access watches disallowed"}
782       }
783
784 #***************
785     }
786 }