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