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