]>
Commit | Line | Data |
---|---|---|
4dc75a28 | 1 | # Copyright (C) 1992, 1994 Free Software Foundation, Inc. |
ef44eed1 SS |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
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 | |
782445c7 | 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
ef44eed1 SS |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # [email protected] | |
19 | ||
20 | # This file was written by Fred Fish. ([email protected]) | |
21 | ||
22 | if $tracelevel then { | |
23 | strace $tracelevel | |
24 | } | |
25 | ||
26 | set prms_id 0 | |
27 | set bug_id 0 | |
28 | ||
782445c7 | 29 | set testfile "watchpoint" |
1be1bc38 | 30 | set srcfile ${testfile}.c |
782445c7 | 31 | set binfile ${objdir}/${subdir}/${testfile} |
1be1bc38 | 32 | if { [compile "${srcdir}/${subdir}/${srcfile} -g -o ${binfile}"] != "" } { |
782445c7 FF |
33 | perror "Couldn't compile ${srcfile}" |
34 | return -1 | |
ef44eed1 SS |
35 | } |
36 | ||
ef44eed1 SS |
37 | # Prepare for watchpoint tests by setting up two breakpoints and one |
38 | # watchpoint. | |
39 | # | |
40 | # We use breakpoints at marker functions to get past all the startup code, | |
41 | # so we can get to the watchpoints in a reasonable amount of time from a | |
42 | # known starting point. | |
43 | # | |
44 | # For simplicity, so we always know how to reference specific breakpoints or | |
45 | # watchpoints by number, we expect a particular ordering and numbering of | |
46 | # each in the combined breakpoint/watchpoint table, as follows: | |
47 | # | |
48 | # Number What Where | |
49 | # 1 Breakpoint marker1() | |
50 | # 2 Breakpoint marker2() | |
51 | # 3 Watchpoint ival3 | |
52 | ||
53 | proc initialize {} { | |
54 | global prompt | |
55 | global hex | |
56 | global decimal | |
57 | global srcfile | |
58 | ||
59 | send "break marker1\n" | |
60 | expect { | |
4dc75a28 JK |
61 | -re "Breakpoint 1 at $hex: file .*$srcfile, line $decimal.*$prompt $" { |
62 | pass "set breakpoint at marker1" | |
63 | } | |
ef44eed1 SS |
64 | -re ".*$prompt $" { fail "set breakpoint at marker1" ; return 0 } |
65 | timeout { fail "set breakpoint at marker1 (timeout)" ; return 0 } | |
66 | } | |
67 | ||
68 | send "break marker2\n" | |
69 | expect { | |
4dc75a28 JK |
70 | -re "Breakpoint 2 at $hex: file .*$srcfile, line $decimal.*$prompt $" { |
71 | pass "set breakpoint at marker2" | |
72 | } | |
ef44eed1 SS |
73 | -re ".*$prompt $" { fail "set breakpoint at marker2" ; return 0 } |
74 | timeout { fail "set breakpoint at marker2 (timeout)" ; return 0 } | |
75 | } | |
76 | ||
77 | send "info break\n" | |
78 | expect { | |
4dc75a28 JK |
79 | -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n$prompt $" { pass "info break in watchpoint.exp" } |
80 | -re ".*$prompt $" { fail "info break in watchpoint.exp" ; return 0 } | |
81 | timeout { fail "info break in watchpoint.exp (timeout)" ; return 0 } | |
ef44eed1 SS |
82 | } |
83 | ||
84 | send "watch ival3\n" | |
85 | expect { | |
4dc75a28 JK |
86 | -re ".*\[Ww\]atchpoint 3: ival3\r\n$prompt $" { |
87 | pass "set watchpoint on ival3" | |
88 | } | |
ef44eed1 SS |
89 | -re ".*$prompt $" { fail "set watchpoint on ival3" ; return 0 } |
90 | timeout { fail "set watchpoint on ival3 (timeout)" ; return 0 } | |
91 | } | |
92 | ||
93 | # "info watch" is the same as "info break" | |
94 | ||
95 | send "info watch\n" | |
96 | expect { | |
97 | -re "1\[ \]*breakpoint.*marker1.*\r\n2\[ \]*breakpoint.*marker2.*\r\n3\[ \]*.*watchpoint.*ival3\r\n$prompt $" { | |
98 | pass "watchpoint found in watchpoint/breakpoint table" | |
99 | } | |
4dc75a28 JK |
100 | -re ".*$prompt $" { |
101 | fail "watchpoint found in watchpoint/breakpoint table" ; return 0 | |
102 | } | |
103 | timeout { | |
104 | fail "watchpoint found in watchpoint/breakpoint table" ; return 0 | |
105 | } | |
ef44eed1 SS |
106 | } |
107 | ||
108 | # After installing the watchpoint, we disable it until we are ready | |
109 | # to use it. This allows the test program to run at full speed until | |
110 | # we get to the first marker function. | |
111 | ||
112 | send "disable 3\n" | |
113 | expect { | |
782445c7 | 114 | -re "disable 3\[\r\n\]+$prompt $" { pass "disable watchpoint" } |
4dc75a28 JK |
115 | -re ".*$prompt $" { fail "disable watchpoint" ; return 0 } |
116 | timeout { fail "disable watchpoint (timeout)" ; return 0 } | |
ef44eed1 SS |
117 | } |
118 | ||
119 | return 1 | |
120 | } | |
121 | ||
122 | # | |
123 | # Test simple watchpoint. | |
124 | # | |
125 | ||
126 | proc test_simple_watchpoint {} { | |
127 | global prompt | |
128 | global hex | |
129 | global decimal | |
1be1bc38 | 130 | global noresults |
ef44eed1 SS |
131 | |
132 | # Ensure that the watchpoint is disabled when we startup. | |
133 | ||
134 | send "disable 3\n" | |
135 | expect { | |
782445c7 | 136 | -re "^disable 3\[\r\n\]+$prompt $" { |
4dc75a28 JK |
137 | pass "disable watchpoint in test_simple_watchpoint" |
138 | } | |
139 | -re ".*$prompt $" { | |
140 | fail "disable watchpoint in test_simple_watchpoint" | |
141 | return 0 | |
142 | } | |
143 | timeout { | |
144 | fail "disable watchpoint in test_simple_watchpoint (timeout)" | |
145 | return 0 | |
146 | } | |
ef44eed1 SS |
147 | } |
148 | ||
149 | # Run until we get to the first marker function. | |
150 | ||
4dc75a28 | 151 | gdb_run_cmd |
ef44eed1 | 152 | expect { |
4dc75a28 JK |
153 | -re "Breakpoint 1, marker1 .*$prompt $" { |
154 | pass "run to marker1 in test_simple_watchpoint" | |
155 | } | |
156 | -re ".*$prompt $" { | |
157 | fail "run to marker1 in test_simple_watchpoint" | |
158 | return | |
159 | } | |
160 | timeout { | |
161 | fail "run to marker1 in test_simple_watchpoint (timeout)" | |
162 | return | |
ef44eed1 | 163 | } |
ef44eed1 SS |
164 | } |
165 | ||
166 | # After reaching the marker function, enable the watchpoint. | |
167 | ||
168 | send "enable 3\n" | |
169 | expect { | |
782445c7 | 170 | -re "^enable 3\[\r\n\]+$prompt $" { pass "enable watchpoint" } |
4dc75a28 JK |
171 | -re ".*$prompt $" { fail "enable watchpoint" ; return } |
172 | timeout { fail "enable watchpoint (timeout)" ; return } | |
ef44eed1 SS |
173 | } |
174 | ||
4dc75a28 JK |
175 | gdb_test "break func1" "Breakpoint.*at.*" |
176 | gdb_test "set \$func1_breakpoint_number = \$bpnum" "" | |
ef44eed1 | 177 | |
4dc75a28 | 178 | gdb_test "continue" "Continuing.*Breakpoint \[0-9\]*, func1.*" \ |
ef44eed1 SS |
179 | "continue to breakpoint at func1" |
180 | ||
181 | # Continue until the first change, from -1 to 0 | |
182 | ||
183 | send "cont\n" | |
184 | expect { | |
4dc75a28 | 185 | -re "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*$prompt $" { |
ef44eed1 SS |
186 | pass "watchpoint hit, first time" |
187 | } | |
ef44eed1 SS |
188 | -re "Continuing.*Breakpoint.*func1.*$prompt $" { |
189 | setup_xfail "m68*-*-*" 2597 | |
190 | fail "thought it hit breakpoint at func1 twice" | |
4dc75a28 | 191 | gdb_test "delete \$func1_breakpoint_number" "" |
ef44eed1 | 192 | gdb_test "continue" "\ |
4dc75a28 | 193 | Continuing.*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count;" \ |
ef44eed1 SS |
194 | "watchpoint hit, first time" |
195 | } | |
4dc75a28 JK |
196 | -re ".*$prompt $" { fail "watchpoint hit, first time" ; return } |
197 | timeout { fail "watchpoint hit, first time (timeout)" ; return } | |
198 | eof { fail "watchpoint hit, first time (eof)" ; return } | |
ef44eed1 SS |
199 | } |
200 | ||
4dc75a28 | 201 | gdb_test "delete \$func1_breakpoint_number" "" |
ef44eed1 SS |
202 | |
203 | # Continue until the next change, from 0 to 1. | |
4dc75a28 JK |
204 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" "watchpoint hit, second time" |
205 | ||
ef44eed1 | 206 | # Continue until the next change, from 1 to 2. |
4dc75a28 | 207 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" "watchpoint hit, third time" |
ef44eed1 SS |
208 | |
209 | # Continue until the next change, from 2 to 3. | |
4dc75a28 JK |
210 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" "watchpoint hit, fourth time" |
211 | ||
ef44eed1 SS |
212 | # Continue until the next change, from 3 to 4. |
213 | # Note that this one is outside the loop. | |
4dc75a28 JK |
214 | |
215 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" "watchpoint hit, fifth time" | |
216 | ||
ef44eed1 SS |
217 | # Continue until we hit the finishing marker function. |
218 | # Make sure we hit no more watchpoints. | |
4dc75a28 JK |
219 | |
220 | gdb_test "cont" "Continuing.*Breakpoint.*marker2 \(\).*" \ | |
221 | "continue to marker2" | |
222 | ||
ef44eed1 SS |
223 | # Disable the watchpoint so we run at full speed until we exit. |
224 | ||
225 | send "disable 3\n" | |
226 | expect { | |
782445c7 | 227 | -re "^disable 3\[\r\n\]+$prompt $" { pass "watchpoint disabled" } |
4dc75a28 JK |
228 | -re ".*$prompt $" { fail "watchpoint disabled" ; return } |
229 | timeout { fail "watchpoint disabled (timeout)" ; return } | |
ef44eed1 SS |
230 | } |
231 | ||
232 | # Run until process exits. | |
4dc75a28 | 233 | |
1be1bc38 JL |
234 | if $noresults==1 then { return } |
235 | ||
4dc75a28 JK |
236 | gdb_test "cont" "Continuing.*Program exited normally.*" \ |
237 | "continue to exit in test_simple_watchpoint" | |
ef44eed1 SS |
238 | } |
239 | ||
240 | # Test disabling watchpoints. | |
241 | ||
242 | proc test_disabling_watchpoints {} { | |
243 | global prompt | |
244 | global binfile | |
245 | global srcfile | |
246 | global decimal | |
247 | global hex | |
1be1bc38 | 248 | global noresults |
ef44eed1 SS |
249 | |
250 | # Ensure that the watchpoint is disabled when we startup. | |
251 | ||
252 | send "disable 3\n" | |
253 | expect { | |
782445c7 | 254 | -re "^disable 3\[\r\n\]+$prompt $" { |
4dc75a28 JK |
255 | pass "disable watchpoint in test_disabling_watchpoints" |
256 | } | |
257 | -re ".*$prompt $" { | |
258 | fail "disable watchpoint in test_disabling_watchpoints" | |
259 | return 0 | |
260 | } | |
261 | timeout { | |
262 | fail "disable watchpoint in test_disabling_watchpoints (timeout)" | |
263 | return 0 | |
264 | } | |
ef44eed1 SS |
265 | } |
266 | ||
267 | # Run until we get to the first marker function. | |
268 | ||
4dc75a28 | 269 | gdb_run_cmd |
ef44eed1 | 270 | expect { |
4dc75a28 JK |
271 | -re "Breakpoint 1, marker1 .*$prompt $" { |
272 | pass "run to marker1 in test_disabling_watchpoints" | |
273 | } | |
274 | -re ".*$prompt $" { | |
275 | fail "run to marker1 in test_disabling_watchpoints" | |
276 | return | |
277 | } | |
278 | timeout { | |
279 | fail "run to marker1 in test_disabling_watchpoints (timeout)" | |
280 | return | |
ef44eed1 | 281 | } |
ef44eed1 SS |
282 | } |
283 | ||
284 | # After reaching the marker function, enable the watchpoint. | |
285 | ||
286 | send "enable 3\n" | |
287 | expect { | |
782445c7 | 288 | -re "^enable 3\[\r\n\]+$prompt $" { pass "watchpoint enabled" } |
4dc75a28 JK |
289 | -re ".*$prompt $" { fail "watchpoint enabled" ; return } |
290 | timeout { fail "watchpoint enabled (timeout)" ; return } | |
ef44eed1 SS |
291 | } |
292 | ||
293 | # Continue until the first change, from -1 to 0 | |
294 | # Don't check the old value, because on VxWorks the variable value | |
295 | # will not have been reinitialized. | |
4dc75a28 | 296 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ival3.*Old value = .*New value = 0.*ival3 = count; ival4 = count;.*" "watchpoint hit in test_disabling_watchpoints, first time" |
ef44eed1 SS |
297 | |
298 | # Continue until the next change, from 0 to 1. | |
4dc75a28 | 299 | 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" |
ef44eed1 SS |
300 | |
301 | # Disable the watchpoint but leave breakpoints | |
302 | ||
303 | send "disable 3\n" | |
304 | expect { | |
782445c7 | 305 | -re "^disable 3\[\r\n\]+$prompt $" { |
4dc75a28 | 306 | pass "disable watchpoint #2 in test_disabling_watchpoints" |
ef44eed1 SS |
307 | } |
308 | -re ".*$prompt $" { | |
4dc75a28 JK |
309 | "disable watchpoint #2 in test_disabling_watchpoints" |
310 | return 0 | |
311 | } | |
312 | timeout { | |
313 | "disable watchpoint #2 in test_disabling_watchpoints (timeout)" | |
314 | return 0 | |
ef44eed1 | 315 | } |
ef44eed1 SS |
316 | } |
317 | ||
4dc75a28 JK |
318 | # Check watchpoint list, looking for the entry that confirms the |
319 | # watchpoint is disabled. | |
320 | gdb_test "info watchpoints" "3\[ \]*.*watchpoint\[ \]*keep\[ \]*n\[ \]*ival3\r\n.*" "watchpoint disabled in table" | |
321 | ||
ef44eed1 SS |
322 | # Continue until we hit the finishing marker function. |
323 | # Make sure we hit no more watchpoints. | |
4dc75a28 JK |
324 | gdb_test "cont" "Continuing.*Breakpoint.*marker2 \\(\\).*" \ |
325 | "disabled watchpoint skipped" | |
ef44eed1 | 326 | |
1be1bc38 JL |
327 | if $noresults==1 then { return } |
328 | ||
4dc75a28 JK |
329 | gdb_test "cont" "Continuing.*Program exited normally.*" \ |
330 | "continue to exit in test_disabling_watchpoints" | |
ef44eed1 SS |
331 | } |
332 | ||
333 | # Test stepping and other mundane operations with watchpoints enabled | |
334 | proc test_stepping {} { | |
335 | global prompt | |
336 | ||
337 | if [runto marker1] then { | |
338 | gdb_test "watch ival2" ".*\[Ww\]atchpoint \[0-9\]*: ival2" | |
339 | ||
340 | # Well, let's not be too mundane. It should be a *bit* of a challenge | |
4dc75a28 JK |
341 | gdb_test "break func2 if 0" "Breakpoint.*at.*" |
342 | gdb_test "p \$func2_breakpoint_number = \$bpnum" " = .*" | |
ef44eed1 | 343 | |
4dc75a28 JK |
344 | # The HPPA has a problem here if it's not using hardware watchpoints |
345 | if {[ istarget "hppa*-*-*" ] && ![ istarget "hppa*-*-*bsd*" ]} then { | |
ef44eed1 SS |
346 | # Don't actually try doing the call, if we do we can't continue. |
347 | setup_xfail "*-*-*" | |
348 | fail "calling function with watchpoint enabled" | |
349 | } else { | |
350 | # The problem is that GDB confuses stepping through the call | |
351 | # dummy with hitting the breakpoint at the end of the call dummy. | |
352 | # Will be fixed once all architectures define | |
353 | # CALL_DUMMY_BREAKPOINT_OFFSET. | |
354 | setup_xfail "*-*-*" | |
355 | # This doesn't occur if the call dummy starts with a call, | |
356 | # because we are out of the dummy by the first time the inferior | |
357 | # stops. | |
358 | clear_xfail "m68*-*-*" | |
359 | clear_xfail "i*86*-*-*" | |
360 | clear_xfail "vax-*-*" | |
361 | # The following architectures define CALL_DUMMY_BREAKPOINT_OFFSET. | |
362 | clear_xfail "alpha-*-*" | |
363 | clear_xfail "mips*-*-*" | |
364 | clear_xfail "sparc-*-*" | |
4dc75a28 | 365 | clear_xfail "hppa*-*-*bsd*" |
ef44eed1 SS |
366 | gdb_test "p func1 ()" "= 73" \ |
367 | "calling function with watchpoint enabled" | |
368 | } | |
369 | ||
370 | # | |
371 | # "finish" brings us back to main. | |
372 | # On some targets (e.g. alpha) gdb will stop from the finish in midline | |
373 | # of the marker1 call. This is due to register restoring code on | |
374 | # the alpha and might be caused by stack adjustment instructions | |
375 | # on other targets. In this case we will step once more. | |
376 | # | |
4dc75a28 | 377 | |
ef44eed1 SS |
378 | send "finish\n" |
379 | expect { | |
380 | -re "Run.*exit from.*marker1.*main.* at" { } | |
381 | default { fail "finish from marker1" ; return } | |
382 | } | |
383 | expect { | |
4dc75a28 | 384 | -re "marker1 \\(\\);.*$prompt $" { |
ef44eed1 SS |
385 | send "step\n" |
386 | exp_continue | |
387 | } | |
4dc75a28 | 388 | -re "func1 \\(\\);.*$prompt $" { |
ef44eed1 SS |
389 | pass "finish from marker1" |
390 | } | |
391 | -re ".*$prompt $" { | |
392 | fail "finish from marker1" | |
393 | } | |
394 | default { fail "finish from marker1" ; return } | |
395 | } | |
396 | ||
4dc75a28 | 397 | gdb_test "next" "for \\(count = 0.*" "next to `for' in watchpoint.exp" |
ef44eed1 SS |
398 | |
399 | # Now test that "until" works. It's a bit tricky to test | |
400 | # "until", because compilers don't always arrange the code | |
401 | # exactly the same way, and we might get slightly different | |
402 | # sequences of statements. But the following should be true | |
403 | # (if not it is a compiler or a debugger bug): The user who | |
404 | # does "until" at every statement of a loop should end up | |
405 | # stepping through the loop once, and the debugger should not | |
406 | # stop for any of the remaining iterations. | |
407 | ||
4dc75a28 JK |
408 | gdb_test "until" "ival1 = count.*" "until to ival1 assignment" |
409 | gdb_test "until" "ival3 = count.*" "until to ival3 assignment" | |
ef44eed1 SS |
410 | send "until\n" |
411 | expect { | |
4dc75a28 JK |
412 | -re "(for \\(count = 0|\}).*$prompt $" { |
413 | gdb_test "until" "ival1 = count; /. Outside loop ./" \ | |
414 | "until out of loop" | |
ef44eed1 SS |
415 | } |
416 | -re "ival1 = count; /. Outside loop ./.*$prompt $" { | |
417 | pass "until out of loop" | |
418 | } | |
419 | -re ".*$prompt $" { | |
420 | fail "until out of loop" | |
421 | } | |
422 | default { fail "until out of loop" ; return } | |
423 | } | |
424 | ||
4dc75a28 | 425 | gdb_test "step" "ival2 = count.*" "step to ival2 assignment" |
ef44eed1 SS |
426 | } |
427 | } | |
428 | ||
429 | # Test stepping and other mundane operations with watchpoints enabled | |
430 | proc test_watchpoint_triggered_in_syscall {} { | |
431 | global prompt | |
9ce4ab84 | 432 | global noinferiorio |
ef44eed1 | 433 | |
9ce4ab84 JL |
434 | if $noinferiorio { |
435 | verbose "Skipping test_watchpoint_triggered_in_syscall due to noinferiorio" | |
436 | return | |
437 | } | |
ef44eed1 SS |
438 | # Run until we get to the first marker function. |
439 | set x 0 | |
440 | set y 0 | |
441 | set testname "Watch buffer passed to read syscall" | |
442 | if [runto marker2] then { | |
4dc75a28 JK |
443 | gdb_test "watch buf\[0\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[0\\\]" |
444 | gdb_test "watch buf\[1\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[1\\\]" | |
445 | gdb_test "watch buf\[2\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[2\\\]" | |
446 | gdb_test "watch buf\[3\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[3\\\]" | |
447 | gdb_test "watch buf\[4\]" ".*\[Ww\]atchpoint \[0-9\]*: buf\\\[4\\\]" | |
ef44eed1 SS |
448 | gdb_test "break marker4" ".*Breakpoint.*" |
449 | ||
4dc75a28 | 450 | gdb_test "set doread = 1" "" |
ef44eed1 | 451 | |
7e7b4a02 SG |
452 | # If we send "123\n" before gdb has switched the tty, then it goes |
453 | # to gdb, not the inferior, and we lose. So that is why we have | |
454 | # watchpoint.c prompt us, so we can wait for that prompt. | |
ef44eed1 | 455 | send "continue\n" |
7e7b4a02 SG |
456 | expect { |
457 | -re "Continuing\\.\r\ntype stuff for buf now:" { | |
458 | pass "continue to read" | |
459 | } | |
460 | default { fail "continue to read"; return } | |
461 | } | |
ef44eed1 SS |
462 | send "123\n" |
463 | expect { | |
4dc75a28 JK |
464 | -re ".*\[Ww\]atchpoint.*buf\\\[0\\\].*Old value = 0.*New value = 49\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } |
465 | -re ".*\[Ww\]atchpoint.*buf\\\[1\\\].*Old value = 0.*New value = 50\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } | |
466 | -re ".*\[Ww\]atchpoint.*buf\\\[2\\\].*Old value = 0.*New value = 51\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } | |
467 | -re ".*\[Ww\]atchpoint.*buf\\\[3\\\].*Old value = 0.*New value = 10\[^\n\]*\n" { set x [expr $x+1] ; exp_continue } | |
7e7b4a02 SG |
468 | -re ".*$prompt $" { pass "sent 123" } |
469 | timeout { fail "sent 123" } | |
ef44eed1 SS |
470 | } |
471 | ||
ef44eed1 SS |
472 | # Examine the values in buf to see how many watchpoints we |
473 | # should have printed. | |
474 | send "print buf\[0\]\n" | |
475 | expect { | |
7e7b4a02 SG |
476 | -re ".*= 49.*$prompt $" { set y [expr $y+1]; pass "print buf\[0\]"} |
477 | -re ".*= 0.*$prompt $" { pass "print buf\[0\]"} | |
478 | -re ".*$prompt $" { fail "print buf\[0\]"} | |
479 | default { fail "print buf\[0\]"} | |
ef44eed1 SS |
480 | } |
481 | send "print buf\[1\]\n" | |
482 | expect { | |
7e7b4a02 SG |
483 | -re ".*= 50.*$prompt $" { set y [expr $y+1]; pass "print buf\[1\]"} |
484 | -re ".*= 0.*$prompt $" { pass "print buf\[1\]"} | |
485 | -re ".*$prompt $" { fail "print buf\[1\]"} | |
486 | default { fail "print buf\[1\]"} | |
ef44eed1 SS |
487 | } |
488 | send "print buf\[2\]\n" | |
489 | expect { | |
7e7b4a02 SG |
490 | -re ".*= 51.*$prompt $" { set y [expr $y+1]; pass "print buf\[2\]"} |
491 | -re ".*= 0.*$prompt $" { pass "print buf\[2\]"} | |
492 | -re ".*$prompt $" { fail "print buf\[2\]"} | |
493 | default { fail "print buf\[2\]"} | |
ef44eed1 SS |
494 | } |
495 | send "print buf\[3\]\n" | |
496 | expect { | |
7e7b4a02 SG |
497 | -re ".*= 10.*$prompt $" { set y [expr $y+1]; pass "print buf\[3\]"} |
498 | -re ".*= 0.*$prompt $" { pass "print buf\[3\]"} | |
499 | -re ".*$prompt $" { fail "print buf\[3\]" } | |
500 | default { fail "print buf\[3\]" } | |
ef44eed1 SS |
501 | } |
502 | ||
503 | # Did we find what we were looking for? If not, flunk it. | |
4dc75a28 | 504 | if [expr $x==$y] then { pass $testname } else { fail "$testname (only triggered $x watchpoints, expected $y)"} |
ef44eed1 SS |
505 | |
506 | # Continue until we hit the finishing marker function. | |
507 | # Make sure we hit no more watchpoints. | |
4dc75a28 JK |
508 | gdb_test "cont" "Continuing.*Breakpoint.*marker4 \\(\\).*" \ |
509 | "continue to marker4" | |
ef44eed1 | 510 | |
ef44eed1 | 511 | # Disable everything so we can finish the program at full speed |
4dc75a28 | 512 | gdb_test "disable" "" "disable in test_watchpoint_triggered_in_syscall" |
ef44eed1 | 513 | |
4dc75a28 JK |
514 | gdb_test "cont" "Continuing.*Program exited normally.*" \ |
515 | "continue to exit in test_watchpoint_triggered_in_syscall" | |
ef44eed1 SS |
516 | } |
517 | } | |
518 | ||
519 | # Do a simple test of of watching through a pointer when the pointer | |
520 | # itself changes. Should add some more complicated stuff here. | |
521 | ||
522 | proc test_complex_watchpoint {} { | |
523 | global prompt | |
524 | ||
ef44eed1 SS |
525 | if [runto marker4] then { |
526 | gdb_test "watch ptr1->val" ".*\[Ww\]atchpoint \[0-9\]*: ptr1->val" | |
527 | gdb_test "break marker5" ".*Breakpoint.*" | |
528 | ||
4dc75a28 | 529 | gdb_test "cont" "Continuing.*\[Ww\]atchpoint.*ptr1->val.*Old value = 1.*New value = 2.*" "Test complex watchpoint" |
ef44eed1 SS |
530 | |
531 | # Continue until we hit the marker5 function. | |
532 | # Make sure we hit no more watchpoints. | |
533 | ||
4dc75a28 JK |
534 | gdb_test "cont" "Continuing.*Breakpoint.*marker5 \\(\\).*" \ |
535 | "did not trigger wrong watchpoint" | |
ef44eed1 SS |
536 | |
537 | # Disable everything so we can finish the program at full speed | |
4dc75a28 | 538 | gdb_test "disable" "" "disable in test_complex_watchpoint" |
ef44eed1 | 539 | |
4dc75a28 JK |
540 | gdb_test "cont" "Continuing.*Program exited normally.*" \ |
541 | "continue to exit in test_complex_watchpoint" | |
ef44eed1 SS |
542 | } |
543 | } | |
544 | ||
545 | # Start with a fresh gdb. | |
546 | ||
547 | gdb_exit | |
548 | gdb_start | |
549 | gdb_reinitialize_dir $srcdir/$subdir | |
782445c7 | 550 | gdb_load $binfile |
ef44eed1 SS |
551 | |
552 | if [initialize] then { | |
553 | ||
ef44eed1 SS |
554 | test_simple_watchpoint |
555 | ||
556 | # The IDT/sim monitor only has 8 (!) open files, of which it uses | |
557 | # 4 (!). So we have to make sure one program exits before | |
558 | # starting another one. | |
559 | if [istarget "mips-idt-*"] then { | |
560 | gdb_exit | |
561 | gdb_start | |
562 | gdb_reinitialize_dir $srcdir/$subdir | |
782445c7 | 563 | gdb_load $binfile |
ef44eed1 SS |
564 | initialize |
565 | } | |
566 | ||
ef44eed1 SS |
567 | test_disabling_watchpoints |
568 | ||
569 | # See above. | |
570 | if [istarget "mips-idt-*"] then { | |
571 | gdb_exit | |
572 | gdb_start | |
573 | gdb_reinitialize_dir $srcdir/$subdir | |
782445c7 | 574 | gdb_load $binfile |
ef44eed1 SS |
575 | initialize |
576 | } | |
577 | ||
578 | test_stepping | |
579 | ||
580 | # See above. | |
581 | if [istarget "mips-idt-*"] then { | |
582 | gdb_exit | |
583 | gdb_start | |
584 | gdb_reinitialize_dir $srcdir/$subdir | |
782445c7 | 585 | gdb_load $binfile |
ef44eed1 SS |
586 | initialize |
587 | } | |
588 | ||
4dc75a28 JK |
589 | # Only enabled for some targets merely because it has not been tested |
590 | # elsewhere. | |
7e7b4a02 SG |
591 | # On sparc-sun-sunos4.1.3, GDB was running all the way to the marker4 |
592 | # breakpoint before stopping for the watchpoint. I don't know why. | |
593 | if {[istarget "hppa*-*-*"]} then { | |
ef44eed1 SS |
594 | test_watchpoint_triggered_in_syscall |
595 | } | |
596 | ||
597 | # See above. | |
598 | if [istarget "mips-idt-*"] then { | |
599 | gdb_exit | |
600 | gdb_start | |
601 | gdb_reinitialize_dir $srcdir/$subdir | |
782445c7 | 602 | gdb_load $binfile |
ef44eed1 SS |
603 | initialize |
604 | } | |
605 | ||
4dc75a28 JK |
606 | # Only enabled for some targets merely because it has not been tested |
607 | # elsewhere. | |
608 | if {[istarget "hppa*-*-*"] || [istarget "sparc*-*-sunos*"]} then { | |
ef44eed1 SS |
609 | test_complex_watchpoint |
610 | } | |
ef44eed1 | 611 | } |