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