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