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