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