Commit | Line | Data |
---|---|---|
9c7bb332 AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
ecd75fc8 | 3 | # Copyright 1997-2014 Free Software Foundation, Inc. |
c906108c SS |
4 | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 7 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 8 | # (at your option) any later version. |
e22f8b7c | 9 | # |
c906108c SS |
10 | # This program is distributed in the hope that it will be useful, |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
e22f8b7c | 14 | # |
c906108c | 15 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 17 | |
c906108c SS |
18 | # |
19 | # test running programs | |
20 | # | |
c906108c | 21 | |
289f9037 | 22 | standard_testfile break.c break1.c |
c906108c | 23 | |
289f9037 TT |
24 | if {[prepare_for_testing ${testfile}.exp ${testfile} \ |
25 | [list $srcfile $srcfile2] {debug nowarnings}]} { | |
26 | return -1 | |
a1dea79a FF |
27 | } |
28 | ||
a1dea79a | 29 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] |
816338b5 | 30 | set bp_location7 [gdb_get_line_number "set breakpoint 7 here"] |
289f9037 TT |
31 | set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile2] |
32 | set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile2] | |
a1dea79a | 33 | set bp_location11 [gdb_get_line_number "set breakpoint 11 here"] |
289f9037 TT |
34 | set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile2] |
35 | set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile2] | |
36 | set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile2] | |
37 | set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile2] | |
38 | set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile2] | |
39 | set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile2] | |
a1dea79a | 40 | |
c906108c SS |
41 | if ![runto_main] then { fail "enable/disable break tests suppressed" } |
42 | ||
43 | # Verify that we can set a breakpoint (the location is irrelevant), | |
44 | # then enable it (yes, it's already enabled by default), then hit it. | |
c906108c | 45 | |
9c7bb332 AC |
46 | proc break_at { breakpoint where } { |
47 | global gdb_prompt | |
48 | global expect_out | |
c906108c | 49 | |
9c7bb332 AC |
50 | set test "break $breakpoint" |
51 | set bp 0 | |
52 | gdb_test_multiple "$test" "$test" { | |
53 | -re "Breakpoint (\[0-9\]*) at .*$where.*$gdb_prompt $" { | |
54 | set bp $expect_out(1,string) | |
55 | pass "$test" | |
56 | } | |
57 | } | |
58 | return $bp | |
c906108c SS |
59 | } |
60 | ||
9c7bb332 | 61 | set bp [break_at "marker1" " line ($bp_location15|$bp_location16)"] |
c906108c | 62 | |
27d3a1a2 | 63 | gdb_test_no_output "enable $bp" "enable break marker1" |
c906108c | 64 | |
9c7bb332 AC |
65 | gdb_test "info break $bp" \ |
66 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*" \ | |
67 | "info break marker1" | |
c906108c | 68 | |
9c7bb332 AC |
69 | # See the comments in condbreak.exp for "run until breakpoint at |
70 | # marker1" for an explanation of the xfail below. | |
71 | set test "continue to break marker1" | |
72 | gdb_test_multiple "continue" "$test" { | |
73 | -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" { | |
74 | pass "$test" | |
75 | } | |
76 | -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" { | |
77 | xfail "$test" | |
78 | } | |
c906108c SS |
79 | } |
80 | ||
27d3a1a2 | 81 | gdb_test_no_output "delete $bp" "delete break marker1" |
c906108c | 82 | |
9c7bb332 AC |
83 | # Verify that we can set a breakpoint to be self-disabling after the |
84 | # first time it triggers. | |
85 | set bp [break_at "marker2" " line ($bp_location8|$bp_location9)"] | |
c906108c | 86 | |
27d3a1a2 | 87 | gdb_test_no_output "enable once $bp" "enable once break marker2" |
9c7bb332 AC |
88 | |
89 | gdb_test "info break $bp" \ | |
90 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*" \ | |
91 | "info auto-disabled break marker2" | |
92 | ||
93 | # See the comments in condbreak.exp for "run until breakpoint at | |
94 | # marker1" for an explanation of the xfail below. | |
95 | set test "continue to auto-disabled break marker2" | |
96 | gdb_test_multiple "continue" "$test" { | |
97 | -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $" { | |
98 | pass "$test" | |
99 | } | |
100 | -re "Breakpoint \[0-9\]*, $hex in marker2.*$gdb_prompt $" { | |
101 | xfail "$test" | |
102 | } | |
c906108c SS |
103 | } |
104 | ||
9c7bb332 AC |
105 | gdb_test "info break $bp" \ |
106 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*" \ | |
107 | "info auto-disabled break marker2" | |
108 | ||
c906108c | 109 | # Verify that we don't stop at a disabled breakpoint. |
7a292a7a SS |
110 | gdb_continue_to_end "no stop" |
111 | rerun_to_main | |
112 | gdb_continue_to_end "no stop at auto-disabled break marker2" | |
c906108c | 113 | |
9c7bb332 AC |
114 | # Verify that we can set a breakpoint to be self-deleting after the |
115 | # first time it triggers. | |
116 | if ![runto_main] then { | |
117 | fail "enable/disable break tests suppressed" | |
c906108c SS |
118 | } |
119 | ||
9c7bb332 | 120 | set bp [break_at "marker3" " line ($bp_location17|$bp_location18)"] |
c906108c | 121 | |
27d3a1a2 | 122 | gdb_test_no_output "enable del $bp" "enable del break marker3" |
c906108c | 123 | |
9c7bb332 AC |
124 | gdb_test "info break $bp" \ |
125 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*" \ | |
126 | "info auto-deleted break marker2" | |
c906108c | 127 | |
9c7bb332 AC |
128 | gdb_test "continue" \ |
129 | ".*marker3 .*:($bp_location17|$bp_location18).*" \ | |
130 | "continue to auto-deleted break marker3" | |
131 | ||
132 | gdb_test "info break $bp" \ | |
e5a67952 | 133 | ".*No breakpoint or watchpoint matching.*" \ |
9c7bb332 | 134 | "info auto-deleted break marker3" |
c906108c SS |
135 | |
136 | # Verify that we can set a breakpoint and manually disable it (we've | |
137 | # already proven that disabled bp's don't trigger). | |
c906108c | 138 | |
9c7bb332 | 139 | set bp [break_at "marker4" " line ($bp_location14|$bp_location13).*"] |
c906108c | 140 | |
27d3a1a2 | 141 | gdb_test_no_output "disable $bp" "disable break marker4" |
9c7bb332 AC |
142 | |
143 | gdb_test "info break $bp" \ | |
144 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*" \ | |
145 | "info break marker4" | |
c906108c | 146 | |
816338b5 SS |
147 | if ![runto_main] then { |
148 | fail "enable/disable break tests suppressed" | |
149 | } | |
150 | ||
151 | # Test enable count by stopping at a location until it is disabled | |
152 | # and passes through. | |
153 | ||
154 | set bp [break_at $bp_location7 "line $bp_location7"] | |
155 | ||
156 | set bp2 [break_at marker1 " line ($bp_location15|$bp_location16)"] | |
157 | ||
158 | gdb_test_no_output "enable count 2 $bp" "disable break with count" | |
159 | ||
160 | gdb_test "continue" \ | |
161 | ".*factorial .*:$bp_location7.*" \ | |
162 | "continue from enable count, first time" | |
163 | ||
164 | gdb_test "continue" \ | |
165 | ".*factorial .*:$bp_location7.*" \ | |
166 | "continue from enable count, second time" | |
167 | ||
168 | gdb_test "continue" \ | |
169 | ".*marker1 .*:($bp_location15|$bp_location16).*" \ | |
170 | "continue through enable count, now disabled" | |
171 | ||
c906108c SS |
172 | # Verify that we can set a breakpoint with an ignore count N, which |
173 | # should cause the next N triggers of the bp to be ignored. (This is | |
174 | # a flavor of enablement/disablement, after all.) | |
c906108c | 175 | |
9c7bb332 AC |
176 | if ![runto_main] then { |
177 | fail "enable/disable break tests suppressed" | |
c906108c SS |
178 | } |
179 | ||
9c7bb332 AC |
180 | set bp [break_at "marker1" " line ($bp_location15|$bp_location16).*"] |
181 | ||
c906108c SS |
182 | # Verify that an ignore of a non-existent breakpoint is gracefully |
183 | # handled. | |
9c7bb332 AC |
184 | |
185 | gdb_test "ignore 999 2" \ | |
186 | "No breakpoint number 999..*" \ | |
187 | "ignore non-existent break" | |
c906108c SS |
188 | |
189 | # Verify that a missing ignore count is gracefully handled. | |
9c7bb332 AC |
190 | |
191 | gdb_test "ignore $bp" \ | |
192 | "Second argument .specified ignore-count. is missing..*" \ | |
193 | "ignore break with missing ignore count" | |
c906108c SS |
194 | |
195 | # Verify that a negative or zero ignore count is handled gracefully | |
196 | # (they both are treated the same). | |
c906108c | 197 | |
9c7bb332 AC |
198 | gdb_test "ignore $bp -1" \ |
199 | "Will stop next time breakpoint \[0-9\]* is reached..*" \ | |
200 | "ignore break marker1 -1" | |
c906108c | 201 | |
9c7bb332 AC |
202 | gdb_test "ignore $bp 0" \ |
203 | "Will stop next time breakpoint \[0-9\]* is reached..*" \ | |
204 | "ignore break marker1 0" | |
c906108c | 205 | |
9c7bb332 AC |
206 | gdb_test "ignore $bp 1" \ |
207 | "Will ignore next crossing of breakpoint \[0-9\]*.*" \ | |
208 | "ignore break marker1" | |
209 | ||
210 | gdb_test "info break $bp" \ | |
211 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*" \ | |
212 | "info ignored break marker1" | |
c906108c | 213 | |
7a292a7a SS |
214 | gdb_continue_to_end "no stop at ignored break marker1" |
215 | rerun_to_main | |
c906108c | 216 | |
11cf8741 JM |
217 | # See the comments in condbreak.exp for "run until breakpoint at marker1" |
218 | # for an explanation of the xfail below. | |
9c7bb332 AC |
219 | set test "continue to break marker1, 2nd time" |
220 | gdb_test_multiple "continue" "$test" { | |
221 | -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" { | |
222 | pass "continue to break marker1, 2nd time" | |
223 | } | |
224 | -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" { | |
225 | xfail "continue to break marker1, 2nd time" | |
226 | } | |
c906108c SS |
227 | } |
228 | ||
229 | # Verify that we can specify both an ignore count and an auto-delete. | |
c906108c | 230 | |
9c7bb332 AC |
231 | if ![runto_main] then { |
232 | fail "enable/disable break tests suppressed" | |
c906108c SS |
233 | } |
234 | ||
9c7bb332 | 235 | set bp [break_at marker1 " line ($bp_location15|$bp_location16).*"] |
c906108c | 236 | |
9c7bb332 AC |
237 | gdb_test "ignore $bp 1" \ |
238 | "Will ignore next crossing of breakpoint \[0-9\]*.*" \ | |
239 | "ignore break marker1" | |
c906108c | 240 | |
27d3a1a2 | 241 | gdb_test_no_output "enable del $bp" "enable del break marker1" |
9c7bb332 AC |
242 | |
243 | gdb_test "info break $bp" \ | |
244 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*" \ | |
245 | "info break marker1" | |
c906108c | 246 | |
7a292a7a SS |
247 | gdb_continue_to_end "no stop at ignored & auto-deleted break marker1" |
248 | rerun_to_main | |
c906108c | 249 | |
9c7bb332 AC |
250 | gdb_test "continue" \ |
251 | ".*marker1 .*:($bp_location15|$bp_location16).*" \ | |
252 | "continue to ignored & auto-deleted break marker1" | |
c906108c SS |
253 | |
254 | # Verify that a disabled breakpoint's ignore count isn't updated when | |
255 | # the bp is encountered. | |
c906108c | 256 | |
9c7bb332 AC |
257 | if ![runto_main] then { |
258 | fail "enable/disable break tests suppressed" | |
c906108c SS |
259 | } |
260 | ||
9c7bb332 | 261 | set bp [break_at marker1 " line ($bp_location15|$bp_location16)"] |
c906108c | 262 | |
9c7bb332 AC |
263 | gdb_test "ignore $bp 10" \ |
264 | "Will ignore next 10 crossings of breakpoint \[0-9\]*.*" \ | |
265 | "ignore break marker1" | |
266 | ||
27d3a1a2 | 267 | gdb_test_no_output "disable $bp" "disable break marker1" |
c906108c | 268 | |
7a292a7a SS |
269 | gdb_continue_to_end "no stop at ignored & disabled break marker1" |
270 | rerun_to_main | |
c906108c | 271 | |
9c7bb332 AC |
272 | gdb_test "info break $bp" \ |
273 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*" \ | |
274 | "info ignored & disabled break marker1" | |
c906108c SS |
275 | |
276 | # Verify that GDB correctly handles the "continue" command with an argument, | |
277 | # which is an ignore count to set on the currently stopped-at breakpoint. | |
278 | # (Also verify that GDB gracefully handles the case where the inferior | |
279 | # isn't stopped at a breakpoint.) | |
280 | # | |
281 | if ![runto_main] then { fail "enable/disable break tests suppressed" } | |
282 | ||
9c7bb332 AC |
283 | gdb_test "break $bp_location1" \ |
284 | "Breakpoint \[0-9\]*.*, line $bp_location1.*" \ | |
285 | "prepare to continue with ignore count" | |
286 | ||
287 | gdb_test "continue 2" \ | |
288 | "Will ignore next crossing of breakpoint \[0-9\]*. Continuing..*" \ | |
289 | "continue with ignore count" | |
290 | ||
291 | gdb_test "next" ".*$bp_location11\[ \t\]*marker1.*" \ | |
c1ea7c01 | 292 | "step after continue with ignore count" |
9c7bb332 AC |
293 | |
294 | set test "continue with ignore count, not stopped at bpt" | |
295 | gdb_test_multiple "continue 2" "$test" { | |
296 | -re "Not stopped at any breakpoint; argument ignored.*$gdb_prompt $" { | |
297 | pass "$test" | |
298 | } | |
299 | -re "No breakpoint number -1.*$gdb_prompt $" { | |
300 | kfail gdb/1689 "$test" | |
301 | } | |
c906108c SS |
302 | } |
303 | ||
9eaabc75 MW |
304 | # Verify that GDB correctly handles the "enable/disable" command |
305 | # with arguments, that include multiple locations. | |
306 | # | |
307 | if ![runto_main] then { fail "enable/disable break tests suppressed" } | |
308 | ||
309 | set b1 0 | |
310 | set b2 0 | |
311 | set b3 0 | |
312 | set b4 0 | |
313 | set b1 [break_at main ""] | |
314 | set b2 [break_at main ""] | |
315 | set b3 [break_at main ""] | |
316 | set b4 [break_at main ""] | |
317 | ||
318 | # Perform tests for disable/enable commands on multiple | |
319 | # locations and breakpoints. | |
320 | # | |
321 | # WHAT - the command to test (disable/enable). | |
322 | # | |
323 | proc test_ena_dis_br { what } { | |
324 | global b1 | |
325 | global b2 | |
326 | global b3 | |
327 | global b4 | |
328 | global gdb_prompt | |
329 | ||
330 | # OPPOS - the command opposite to WHAT. | |
331 | # WHAT_RES - whether breakpoints are expected to end | |
332 | # up enabled or disabled. | |
333 | # OPPOS_RES- same as WHAT_RES but opposite. | |
334 | # P1/P2 - proc to call (pass/fail). Must be | |
335 | # opposites. | |
336 | # Set variable values for disable command. | |
337 | set oppos "enable" | |
338 | set oppos_res "y" | |
339 | set what_res "n" | |
340 | set p1 "pass" | |
341 | set p2 "fail" | |
342 | ||
343 | if { "$what" == "enable" } { | |
344 | # Set varibale values for enable command. | |
345 | set oppos "disable" | |
346 | set oppos_res "n" | |
347 | set what_res "y" | |
348 | set p1 "fail" | |
349 | set p2 "pass" | |
350 | } | |
351 | ||
352 | # Now enable(disable) $b.1 $b2.1. | |
353 | gdb_test_no_output "$what $b1.1 $b2.1" "$what \$b1.1 \$b2.1" | |
354 | set test1 "${what}d \$b1.1 and \$b2.1" | |
355 | ||
356 | # Now $b1.1 and $b2.1 should be enabled(disabled). | |
357 | gdb_test_multiple "info break" "$test1" { | |
358 | -re "(${b1}.1)(\[^\n\r\]*)( n.*)(${b2}.1)(\[^\n\r\]*)( n.*)$gdb_prompt $" { | |
359 | $p1 "$test1" | |
360 | } | |
361 | -re ".*$gdb_prompt $" { | |
362 | $p2 "$test1" | |
363 | } | |
364 | } | |
365 | ||
366 | # Now enable(disable) $b1 fooo.1, it should give error on fooo. | |
367 | gdb_test "$what $b1 fooo.1" \ | |
368 | "Bad breakpoint number 'fooo'" \ | |
369 | "$what \$b1 fooo.1" | |
370 | ||
371 | # $b1 should be enabled(disabled). | |
372 | gdb_test "info break" \ | |
373 | "(${b1})(\[^\n\r]*)( $what_res.*)" \ | |
374 | "${what}d \$b1" | |
375 | ||
376 | gdb_test_no_output "$oppos $b3" "$oppos \$b3" | |
377 | gdb_test_no_output "$what $b4 $b3.1" "$what \$b4 \$b3.1" | |
378 | set test1 "${what}d \$b4 and \$b3.1,remain ${oppos}d \$b3" | |
379 | ||
380 | # Now $b4 $b3.1 should be enabled(disabled) and | |
381 | # $b3 should remain disabled(enabled). | |
382 | gdb_test_multiple "info break" "$test1" { | |
383 | -re "(${b3})(\[^\n\r]*)( $oppos_res.*)(${b3}.1)(\[^\n\r\]*)( n.*)(${b4})(\[^\n\r\]*)( $what_res.*)$gdb_prompt $" { | |
384 | $p1 "$test1" | |
385 | } | |
386 | -re "(${b3})(\[^\n\r]*)( $oppos_res.*)(${b4})(\[^\n\r\]*)( $what_res.*)$gdb_prompt $" { | |
387 | $p2 "$test1" | |
388 | } | |
389 | } | |
390 | ||
391 | # Now enable(disable) $b4.1 fooobaar and | |
392 | # it should give warning on fooobaar. | |
393 | gdb_test "$what $b4.1 fooobaar" \ | |
394 | "warning: bad breakpoint number at or near 'fooobaar'" \ | |
395 | "$what \$b4.1 fooobar" | |
396 | set test1 "${what}d \$b4.1" | |
397 | ||
398 | # $b4.1 should be enabled(disabled). | |
399 | gdb_test_multiple "info break" "$test1" { | |
400 | -re "(${b4}.1)(\[^\n\r\]*)( n.*)$gdb_prompt $" { | |
401 | $p1 "$test1" | |
402 | } | |
403 | -re ".*$gdb_prompt $" { | |
404 | $p2 "$test1" | |
405 | } | |
406 | } | |
407 | } | |
408 | ||
409 | test_ena_dis_br "disable" | |
410 | test_ena_dis_br "enable" | |
411 | ||
c906108c SS |
412 | gdb_exit |
413 | return 0 |