* gdb.base/watchpoint.exp(test_watchpoint_triggered_in_syscall):
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / watchpoint.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 "watchpoint"
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 perror "Couldn't compile ${srcfile}"
34 return -1
35 }
36
37 # Prepare for watchpoint tests by setting up two breakpoints and one
38 # watchpoint.
39 #
40 # We use breakpoints at marker functions to get past all the startup code,
41 # so we can get to the watchpoints in a reasonable amount of time from a
42 # known starting point.
43 #
44 # For simplicity, so we always know how to reference specific breakpoints or
45 # watchpoints by number, we expect a particular ordering and numbering of
46 # each in the combined breakpoint/watchpoint table, as follows:
47 #
48 # Number What Where
49 # 1 Breakpoint marker1()
50 # 2 Breakpoint marker2()
51 # 3 Watchpoint ival3
52
53 proc initialize {} {
54 global gdb_prompt
55 global hex
56 global decimal
57 global srcfile
58
59 if [gdb_test "break marker1" "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker1" ] {
60 return 0;
61 }
62
63
64 if [gdb_test "break marker2" "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*" "set breakpoint at marker2" ] {
65 return 0;
66 }
67
68
69 if [gdb_test "info break" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*" "info break in watchpoint.exp" ] {
70 return 0;
71 }
72
73
74 if [gdb_test "watch ival3" ".*\[Ww\]atchpoint 3: ival3" "set watchpoint on ival3" ] {
75 return 0;
76 }
77
78
79 # "info watch" is the same as "info break"
80
81 if [gdb_test "info watch" "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3" "watchpoint found in watchpoint/breakpoint table" ] {
82 return 0;
83 }
84
85
86 # After installing the watchpoint, we disable it until we are ready
87 # to use it. This allows the test program to run at full speed until
88 # we get to the first marker function.
89
90 if [gdb_test "disable 3" "disable 3\[\r\n\]+" "disable watchpoint" ] {
91 return 0;
92 }
93
94
95 return 1
96 }
97
98 #
99 # Test simple watchpoint.
100 #
101
102 proc test_simple_watchpoint {} {
103 global gdb_prompt
104 global hex
105 global decimal
106
107 # Ensure that the watchpoint is disabled when we startup.
108
109 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_simple_watchpoint" ] {
110 return 0;
111 }
112
113
114 # Run until we get to the first marker function.
115
116 gdb_run_cmd
117 set timeout 600
118 gdb_expect {
119 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
120 pass "run to marker1 in test_simple_watchpoint"
121 }
122 -re ".*$gdb_prompt $" {
123 fail "run to marker1 in test_simple_watchpoint"
124 return
125 }
126 timeout {
127 fail "run to marker1 in test_simple_watchpoint (timeout)"
128 return
129 }
130 }
131
132 # After reaching the marker function, enable the watchpoint.
133
134 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "enable watchpoint" ] {
135 return ;
136 }
137
138
139 gdb_test "break func1" "Breakpoint.*at.*"
140 gdb_test "set \$func1_breakpoint_number = \$bpnum" ""
141
142 gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \
143 "continue to breakpoint at func1"
144
145 # Continue until the first change, from -1 to 0
146
147 send_gdb "cont\n"
148 gdb_expect {
149 -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$gdb_prompt $" {
150 pass "watchpoint hit, first time"
151 }
152 -re "Continuing.*Breakpoint.*func1.*$gdb_prompt $" {
153 setup_xfail "m68*-*-*" 2597
154 fail "thought it hit breakpoint at func1 twice"
155 gdb_test "delete \$func1_breakpoint_number" ""
156 gdb_test "continue" "\
157 Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \
158 "watchpoint hit, first time"
159 }
160 -re ".*$gdb_prompt $" { fail "watchpoint hit, first time" ; return }
161 timeout { fail "watchpoint hit, first time (timeout)" ; return }
162 eof { fail "watchpoint hit, first time (eof)" ; return }
163 }
164
165 gdb_test "delete \$func1_breakpoint_number" ""
166
167 # Continue until the next change, from 0 to 1.
168 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time"
169
170 # Continue until the next change, from 1 to 2.
171 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time"
172
173 # Continue until the next change, from 2 to 3.
174 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time"
175
176 # Continue until the next change, from 3 to 4.
177 # Note that this one is outside the loop.
178
179 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time"
180
181 # Continue until we hit the finishing marker function.
182 # Make sure we hit no more watchpoints.
183
184 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \
185 "continue to marker2"
186
187 # Disable the watchpoint so we run at full speed until we exit.
188
189 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "watchpoint disabled" ] {
190 return ;
191 }
192
193
194 # Run until process exits.
195
196 if [target_info exists gdb,noresults] { return }
197
198 gdb_test "cont" "Continuing.*Program exited normally.*" \
199 "continue to exit in test_simple_watchpoint"
200 }
201
202 # Test disabling watchpoints.
203
204 proc test_disabling_watchpoints {} {
205 global gdb_prompt
206 global binfile
207 global srcfile
208 global decimal
209 global hex
210
211 # Ensure that the watchpoint is disabled when we startup.
212
213 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint in test_disabling_watchpoints" ] {
214 return 0;
215 }
216
217
218 # Run until we get to the first marker function.
219
220 gdb_run_cmd
221 set timeout 600
222 gdb_expect {
223 -re "Breakpoint 1, marker1 .*$gdb_prompt $" {
224 pass "run to marker1 in test_disabling_watchpoints"
225 }
226 -re ".*$gdb_prompt $" {
227 fail "run to marker1 in test_disabling_watchpoints"
228 return
229 }
230 timeout {
231 fail "run to marker1 in test_disabling_watchpoints (timeout)"
232 return
233 }
234 }
235
236 # After reaching the marker function, enable the watchpoint.
237
238 if [gdb_test "enable 3" "^enable 3\[\r\n\]+" "watchpoint enabled" ] {
239 return ;
240 }
241
242
243 # Continue until the first change, from -1 to 0
244 # Don't check the old value, because on VxWorks the variable value
245 # will not have been reinitialized.
246 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time"
247
248 # Continue until the next change, from 0 to 1.
249 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"
250
251 # Disable the watchpoint but leave breakpoints
252
253 if [gdb_test "disable 3" "^disable 3\[\r\n\]+" "disable watchpoint #2 in test_disabling_watchpoints" ] {
254 return 0;
255 }
256
257
258 # Check watchpoint list, looking for the entry that confirms the
259 # watchpoint is disabled.
260 gdb_test "info watchpoints" "3\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table"
261
262 # Continue until we hit the finishing marker function.
263 # Make sure we hit no more watchpoints.
264 gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \
265 "disabled watchpoint skipped"
266
267 if [target_info exists gdb,noresults] { return }
268
269 gdb_test "cont" "Continuing.*Program exited normally.*" \
270 "continue to exit in test_disabling_watchpoints"
271 }
272
273 # Test stepping and other mundane operations with watchpoints enabled
274 proc test_stepping {} {
275 global gdb_prompt
276
277 if [runto marker1] then {
278 gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2"
279
280 # Well, let's not be too mundane. It should be a *bit* of a challenge
281 gdb_test "break func2 if 0" "Breakpoint.*at.*"
282 gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*"
283
284 # The HPPA has a problem here if it's not using hardware watchpoints
285 if {[ istarget "hppa*-*-*" ] && ![ istarget "hppa*-*-*bsd*" ]} then {
286 # Don't actually try doing the call, if we do we can't continue.
287 setup_xfail "*-*-*"
288 fail "calling function with watchpoint enabled"
289 } else {
290 # The problem is that GDB confuses stepping through the call
291 # dummy with hitting the breakpoint at the end of the call dummy.
292 # Will be fixed once all architectures define
293 # CALL_DUMMY_BREAKPOINT_OFFSET.
294 setup_xfail "*-*-*"
295 # This doesn't occur if the call dummy starts with a call,
296 # because we are out of the dummy by the first time the inferior
297 # stops.
298 clear_xfail "m68*-*-*"
299 clear_xfail "i*86*-*-*"
300 clear_xfail "vax-*-*"
301 # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET.
302 clear_xfail "alpha-*-*"
303 clear_xfail "mips*-*-*"
304 clear_xfail "sparc-*-*"
305 clear_xfail "hppa*-*-*bsd*"
306 # It works with the generic inferior function calling code too.
307 clear_xfail "mn10200*-*-*"
308 gdb_test "p func1 ()" "= 73" \
309 "calling function with watchpoint enabled"
310 }
311
312 #
313 # "finish" brings us back to main.
314 # On some targets (e.g. alpha) gdb will stop from the finish in midline
315 # of the marker1 call. This is due to register restoring code on
316 # the alpha and might be caused by stack adjustment instructions
317 # on other targets. In this case we will step once more.
318 #
319
320 send_gdb "finish\n"
321 gdb_expect {
322 -re "Run.*exit from.*marker1.* at" { }
323 default { fail "finish from marker1" ; return }
324 }
325
326 gdb_expect {
327 -re "marker1 \\(\\);.*$gdb_prompt $" {
328 send_gdb "step\n"
329 exp_continue
330 }
331 -re "func1 \\(\\);.*$gdb_prompt $" {
332 pass "finish from marker1"
333 }
334 -re ".*$gdb_prompt $" {
335 fail "finish from marker1"
336 }
337 default { fail "finish from marker1" ; return }
338 }
339
340 gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp"
341
342 # Now test that "until" works. It's a bit tricky to test
343 # "until", because compilers don't always arrange the code
344 # exactly the same way, and we might get slightly different
345 # sequences of statements. But the following should be true
346 # (if not it is a compiler or a debugger bug): The user who
347 # does "until" at every statement of a loop should end up
348 # stepping through the loop once, and the debugger should not
349 # stop for any of the remaining iterations.
350
351 gdb_test "until" "ival1 = count.*" "until to ival1 assignment"
352 gdb_test "until" "ival3 = count.*" "until to ival3 assignment"
353 send_gdb "until\n"
354 gdb_expect {
355 -re "(for \\(count = 0|\}).*$gdb_prompt $" {
356 gdb_test "until" "ival1 = count; /. Outside loop ./" \
357 "until out of loop"
358 }
359 -re "ival1 = count; /. Outside loop ./.*$gdb_prompt $" {
360 pass "until out of loop"
361 }
362 -re ".*$gdb_prompt $" {
363 fail "until out of loop"
364 }
365 default { fail "until out of loop" ; return }
366 }
367
368 gdb_test "step" "ival2 = count.*" "step to ival2 assignment"
369 }
370 }
371
372 # Test stepping and other mundane operations with watchpoints enabled
373 proc test_watchpoint_triggered_in_syscall {} {
374 global gdb_prompt
375
376 if [target_info exists gdb,noinferiorio] {
377 verbose "Skipping test_watchpoint_triggered_in_syscall due to noinferiorio"
378 return
379 }
380 # Run until we get to the first marker function.
381 set x 0
382 set y 0
383 set testname "Watch buffer passed to read syscall"
384 if [runto marker2] then {
385 gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]"
386 gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]"
387 gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]"
388 gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]"
389 gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]"
390 gdb_test "break marker4" ".*Breakpoint.*"
391
392 gdb_test "set doread = 1" ""
393
394 # If we send_gdb "123\n" before gdb has switched the tty, then it goes
395 # to gdb, not the inferior, and we lose. So that is why we have
396 # watchpoint.c prompt us, so we can wait for that prompt.
397 send_gdb "continue\n";
398 gdb_expect {
399 -re "Continuing\\.\r\ntype stuff for buf now:" {
400 pass "continue to read"
401 }
402 default {
403 fail "continue to read";
404 return ;
405 }
406 }
407
408 send_gdb "123\n"
409 gdb_expect {
410 -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
411 -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
412 -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
413 -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue }
414 -re ".*$gdb_prompt $" { pass "sent 123" }
415 timeout { fail "sent 123 (timeout)" }
416 }
417
418 # Examine the values in buf to see how many watchpoints we
419 # should have printed.
420 send_gdb "print buf\[0\]\n"
421 gdb_expect {
422 -re ".*= 49.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[0\]"}
423 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[0\]"}
424 -re ".*$gdb_prompt $" { fail "print buf\[0\]"}
425 default { fail "print buf\[0\]"}
426 }
427 send_gdb "print buf\[1\]\n"
428 gdb_expect {
429 -re ".*= 50.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[1\]"}
430 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[1\]"}
431 -re ".*$gdb_prompt $" { fail "print buf\[1\]"}
432 default { fail "print buf\[1\]"}
433 }
434 send_gdb "print buf\[2\]\n"
435 gdb_expect {
436 -re ".*= 51.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[2\]"}
437 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[2\]"}
438 -re ".*$gdb_prompt $" { fail "print buf\[2\]"}
439 default { fail "print buf\[2\]"}
440 }
441 send_gdb "print buf\[3\]\n"
442 gdb_expect {
443 -re ".*= 10.*$gdb_prompt $" { set y [expr $y+1]; pass "print buf\[3\]"}
444 -re ".*= 0.*$gdb_prompt $" { pass "print buf\[3\]"}
445 -re ".*$gdb_prompt $" { fail "print buf\[3\]" }
446 default { fail "print buf\[3\]" }
447 }
448
449 # Did we find what we were looking for? If not, flunk it.
450 if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"}
451
452 # Continue until we hit the finishing marker function.
453 # Make sure we hit no more watchpoints.
454 gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \
455 "continue to marker4"
456
457 # Disable everything so we can finish the program at full speed
458 gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall"
459
460 if [target_info exists gdb,noresults] { return }
461
462 gdb_test "cont" "Continuing.*Program exited normally.*" \
463 "continue to exit in test_watchpoint_triggered_in_syscall"
464 }
465 }
466
467 # Do a simple test of of watching through a pointer when the pointer
468 # itself changes. Should add some more complicated stuff here.
469
470 proc test_complex_watchpoint {} {
471 global gdb_prompt
472
473 if [runto marker4] then {
474 gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val"
475 gdb_test "break marker5" ".*Breakpoint.*"
476
477 gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint"
478
479 # Continue until we hit the marker5 function.
480 # Make sure we hit no more watchpoints.
481
482 gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \
483 "did not trigger wrong watchpoint"
484
485 # Disable everything so we can finish the program at full speed
486 gdb_test "disable" "" "disable in test_complex_watchpoint"
487
488 if [target_info exists gdb,noresults] { return }
489
490
491 gdb_test "cont" "Continuing.*Program exited normally.*" \
492 "continue to exit in test_complex_watchpoint"
493 }
494 }
495
496 # Start with a fresh gdb.
497
498 gdb_start
499 gdb_reinitialize_dir $srcdir/$subdir
500 gdb_load $binfile
501 set timeout 600
502 verbose "Timeout now 600 sec.\n"
503
504 if [initialize] then {
505
506 test_simple_watchpoint
507
508 # The IDT/sim monitor only has 8 (!) open files, of which it uses
509 # 4 (!). So we have to make sure one program exits before
510 # starting another one.
511 if [istarget "mips-idt-*"] then {
512 gdb_exit
513 gdb_start
514 gdb_reinitialize_dir $srcdir/$subdir
515 gdb_load $binfile
516 initialize
517 }
518
519 test_disabling_watchpoints
520
521 # See above.
522 if [istarget "mips-idt-*"] then {
523 gdb_exit
524 gdb_start
525 gdb_reinitialize_dir $srcdir/$subdir
526 gdb_load $binfile
527 initialize
528 }
529
530 test_stepping
531
532 # See above.
533 if [istarget "mips-idt-*"] then {
534 gdb_exit
535 gdb_start
536 gdb_reinitialize_dir $srcdir/$subdir
537 gdb_load $binfile
538 initialize
539 }
540
541 # Only enabled for some targets merely because it has not been tested
542 # elsewhere.
543 # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4
544 # breakpoint before stopping for the watchpoint. I don't know why.
545 if {[istarget "hppa*-*-*"]} then {
546 test_watchpoint_triggered_in_syscall
547 }
548
549 # See above.
550 if [istarget "mips-idt-*"] then {
551 gdb_exit
552 gdb_start
553 gdb_reinitialize_dir $srcdir/$subdir
554 gdb_load $binfile
555 initialize
556 }
557
558 # Only enabled for some targets merely because it has not been tested
559 # elsewhere.
560 if {[istarget "hppa*-*-*"] || \
561 [istarget "sparc*-*-sunos*"] || \
562 [istarget "m32r-*-*"]} then {
563 test_complex_watchpoint
564 }
565 }
This page took 0.041416 seconds and 5 git commands to generate.