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