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