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