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