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