Commit | Line | Data |
---|---|---|
9c7bb332 AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
28e7fd62 | 3 | # Copyright 1997-2013 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 SS |
21 | |
22 | set testfile "break" | |
23 | set srcfile ${testfile}.c | |
a1dea79a | 24 | set srcfile1 ${testfile}1.c |
c906108c SS |
25 | set binfile ${objdir}/${subdir}/${testfile} |
26 | ||
fc91c6c2 | 27 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } { |
b60f0898 JB |
28 | untested ena-dis-br.exp |
29 | return -1 | |
a1dea79a FF |
30 | } |
31 | ||
fc91c6c2 | 32 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } { |
b60f0898 JB |
33 | untested ena-dis-br.exp |
34 | return -1 | |
a1dea79a FF |
35 | } |
36 | ||
fc91c6c2 | 37 | if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } { |
b60f0898 JB |
38 | untested ena-dis-br.exp |
39 | return -1 | |
c906108c SS |
40 | } |
41 | ||
42 | gdb_exit | |
43 | gdb_start | |
44 | gdb_reinitialize_dir $srcdir/$subdir | |
45 | gdb_load ${binfile} | |
46 | ||
a1dea79a | 47 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] |
816338b5 | 48 | set bp_location7 [gdb_get_line_number "set breakpoint 7 here"] |
a1dea79a FF |
49 | set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1] |
50 | set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1] | |
51 | set bp_location11 [gdb_get_line_number "set breakpoint 11 here"] | |
52 | set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1] | |
53 | set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1] | |
54 | set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile1] | |
55 | set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile1] | |
56 | set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile1] | |
57 | set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile1] | |
58 | ||
c906108c SS |
59 | if ![runto_main] then { fail "enable/disable break tests suppressed" } |
60 | ||
61 | # Verify that we can set a breakpoint (the location is irrelevant), | |
62 | # then enable it (yes, it's already enabled by default), then hit it. | |
c906108c | 63 | |
9c7bb332 AC |
64 | proc break_at { breakpoint where } { |
65 | global gdb_prompt | |
66 | global expect_out | |
c906108c | 67 | |
9c7bb332 AC |
68 | set test "break $breakpoint" |
69 | set bp 0 | |
70 | gdb_test_multiple "$test" "$test" { | |
71 | -re "Breakpoint (\[0-9\]*) at .*$where.*$gdb_prompt $" { | |
72 | set bp $expect_out(1,string) | |
73 | pass "$test" | |
74 | } | |
75 | } | |
76 | return $bp | |
c906108c SS |
77 | } |
78 | ||
9c7bb332 | 79 | set bp [break_at "marker1" " line ($bp_location15|$bp_location16)"] |
c906108c | 80 | |
27d3a1a2 | 81 | gdb_test_no_output "enable $bp" "enable break marker1" |
c906108c | 82 | |
9c7bb332 AC |
83 | gdb_test "info break $bp" \ |
84 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*" \ | |
85 | "info break marker1" | |
c906108c | 86 | |
9c7bb332 AC |
87 | # See the comments in condbreak.exp for "run until breakpoint at |
88 | # marker1" for an explanation of the xfail below. | |
89 | set test "continue to break marker1" | |
90 | gdb_test_multiple "continue" "$test" { | |
91 | -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" { | |
92 | pass "$test" | |
93 | } | |
94 | -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" { | |
95 | xfail "$test" | |
96 | } | |
c906108c SS |
97 | } |
98 | ||
27d3a1a2 | 99 | gdb_test_no_output "delete $bp" "delete break marker1" |
c906108c | 100 | |
9c7bb332 AC |
101 | # Verify that we can set a breakpoint to be self-disabling after the |
102 | # first time it triggers. | |
103 | set bp [break_at "marker2" " line ($bp_location8|$bp_location9)"] | |
c906108c | 104 | |
27d3a1a2 | 105 | gdb_test_no_output "enable once $bp" "enable once break marker2" |
9c7bb332 AC |
106 | |
107 | gdb_test "info break $bp" \ | |
108 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*" \ | |
109 | "info auto-disabled break marker2" | |
110 | ||
111 | # See the comments in condbreak.exp for "run until breakpoint at | |
112 | # marker1" for an explanation of the xfail below. | |
113 | set test "continue to auto-disabled break marker2" | |
114 | gdb_test_multiple "continue" "$test" { | |
115 | -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $" { | |
116 | pass "$test" | |
117 | } | |
118 | -re "Breakpoint \[0-9\]*, $hex in marker2.*$gdb_prompt $" { | |
119 | xfail "$test" | |
120 | } | |
c906108c SS |
121 | } |
122 | ||
9c7bb332 AC |
123 | gdb_test "info break $bp" \ |
124 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*" \ | |
125 | "info auto-disabled break marker2" | |
126 | ||
c906108c | 127 | # Verify that we don't stop at a disabled breakpoint. |
7a292a7a SS |
128 | gdb_continue_to_end "no stop" |
129 | rerun_to_main | |
130 | gdb_continue_to_end "no stop at auto-disabled break marker2" | |
c906108c | 131 | |
9c7bb332 AC |
132 | # Verify that we can set a breakpoint to be self-deleting after the |
133 | # first time it triggers. | |
134 | if ![runto_main] then { | |
135 | fail "enable/disable break tests suppressed" | |
c906108c SS |
136 | } |
137 | ||
9c7bb332 | 138 | set bp [break_at "marker3" " line ($bp_location17|$bp_location18)"] |
c906108c | 139 | |
27d3a1a2 | 140 | gdb_test_no_output "enable del $bp" "enable del break marker3" |
c906108c | 141 | |
9c7bb332 AC |
142 | gdb_test "info break $bp" \ |
143 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*" \ | |
144 | "info auto-deleted break marker2" | |
c906108c | 145 | |
9c7bb332 AC |
146 | gdb_test "continue" \ |
147 | ".*marker3 .*:($bp_location17|$bp_location18).*" \ | |
148 | "continue to auto-deleted break marker3" | |
149 | ||
150 | gdb_test "info break $bp" \ | |
e5a67952 | 151 | ".*No breakpoint or watchpoint matching.*" \ |
9c7bb332 | 152 | "info auto-deleted break marker3" |
c906108c SS |
153 | |
154 | # Verify that we can set a breakpoint and manually disable it (we've | |
155 | # already proven that disabled bp's don't trigger). | |
c906108c | 156 | |
9c7bb332 | 157 | set bp [break_at "marker4" " line ($bp_location14|$bp_location13).*"] |
c906108c | 158 | |
27d3a1a2 | 159 | gdb_test_no_output "disable $bp" "disable break marker4" |
9c7bb332 AC |
160 | |
161 | gdb_test "info break $bp" \ | |
162 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*" \ | |
163 | "info break marker4" | |
c906108c | 164 | |
816338b5 SS |
165 | if ![runto_main] then { |
166 | fail "enable/disable break tests suppressed" | |
167 | } | |
168 | ||
169 | # Test enable count by stopping at a location until it is disabled | |
170 | # and passes through. | |
171 | ||
172 | set bp [break_at $bp_location7 "line $bp_location7"] | |
173 | ||
174 | set bp2 [break_at marker1 " line ($bp_location15|$bp_location16)"] | |
175 | ||
176 | gdb_test_no_output "enable count 2 $bp" "disable break with count" | |
177 | ||
178 | gdb_test "continue" \ | |
179 | ".*factorial .*:$bp_location7.*" \ | |
180 | "continue from enable count, first time" | |
181 | ||
182 | gdb_test "continue" \ | |
183 | ".*factorial .*:$bp_location7.*" \ | |
184 | "continue from enable count, second time" | |
185 | ||
186 | gdb_test "continue" \ | |
187 | ".*marker1 .*:($bp_location15|$bp_location16).*" \ | |
188 | "continue through enable count, now disabled" | |
189 | ||
c906108c SS |
190 | # Verify that we can set a breakpoint with an ignore count N, which |
191 | # should cause the next N triggers of the bp to be ignored. (This is | |
192 | # a flavor of enablement/disablement, after all.) | |
c906108c | 193 | |
9c7bb332 AC |
194 | if ![runto_main] then { |
195 | fail "enable/disable break tests suppressed" | |
c906108c SS |
196 | } |
197 | ||
9c7bb332 AC |
198 | set bp [break_at "marker1" " line ($bp_location15|$bp_location16).*"] |
199 | ||
c906108c SS |
200 | # Verify that an ignore of a non-existent breakpoint is gracefully |
201 | # handled. | |
9c7bb332 AC |
202 | |
203 | gdb_test "ignore 999 2" \ | |
204 | "No breakpoint number 999..*" \ | |
205 | "ignore non-existent break" | |
c906108c SS |
206 | |
207 | # Verify that a missing ignore count is gracefully handled. | |
9c7bb332 AC |
208 | |
209 | gdb_test "ignore $bp" \ | |
210 | "Second argument .specified ignore-count. is missing..*" \ | |
211 | "ignore break with missing ignore count" | |
c906108c SS |
212 | |
213 | # Verify that a negative or zero ignore count is handled gracefully | |
214 | # (they both are treated the same). | |
c906108c | 215 | |
9c7bb332 AC |
216 | gdb_test "ignore $bp -1" \ |
217 | "Will stop next time breakpoint \[0-9\]* is reached..*" \ | |
218 | "ignore break marker1 -1" | |
c906108c | 219 | |
9c7bb332 AC |
220 | gdb_test "ignore $bp 0" \ |
221 | "Will stop next time breakpoint \[0-9\]* is reached..*" \ | |
222 | "ignore break marker1 0" | |
c906108c | 223 | |
9c7bb332 AC |
224 | gdb_test "ignore $bp 1" \ |
225 | "Will ignore next crossing of breakpoint \[0-9\]*.*" \ | |
226 | "ignore break marker1" | |
227 | ||
228 | gdb_test "info break $bp" \ | |
229 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*" \ | |
230 | "info ignored break marker1" | |
c906108c | 231 | |
7a292a7a SS |
232 | gdb_continue_to_end "no stop at ignored break marker1" |
233 | rerun_to_main | |
c906108c | 234 | |
11cf8741 JM |
235 | # See the comments in condbreak.exp for "run until breakpoint at marker1" |
236 | # for an explanation of the xfail below. | |
9c7bb332 AC |
237 | set test "continue to break marker1, 2nd time" |
238 | gdb_test_multiple "continue" "$test" { | |
239 | -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" { | |
240 | pass "continue to break marker1, 2nd time" | |
241 | } | |
242 | -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" { | |
243 | xfail "continue to break marker1, 2nd time" | |
244 | } | |
c906108c SS |
245 | } |
246 | ||
247 | # Verify that we can specify both an ignore count and an auto-delete. | |
c906108c | 248 | |
9c7bb332 AC |
249 | if ![runto_main] then { |
250 | fail "enable/disable break tests suppressed" | |
c906108c SS |
251 | } |
252 | ||
9c7bb332 | 253 | set bp [break_at marker1 " line ($bp_location15|$bp_location16).*"] |
c906108c | 254 | |
9c7bb332 AC |
255 | gdb_test "ignore $bp 1" \ |
256 | "Will ignore next crossing of breakpoint \[0-9\]*.*" \ | |
257 | "ignore break marker1" | |
c906108c | 258 | |
27d3a1a2 | 259 | gdb_test_no_output "enable del $bp" "enable del break marker1" |
9c7bb332 AC |
260 | |
261 | gdb_test "info break $bp" \ | |
262 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*" \ | |
263 | "info break marker1" | |
c906108c | 264 | |
7a292a7a SS |
265 | gdb_continue_to_end "no stop at ignored & auto-deleted break marker1" |
266 | rerun_to_main | |
c906108c | 267 | |
9c7bb332 AC |
268 | gdb_test "continue" \ |
269 | ".*marker1 .*:($bp_location15|$bp_location16).*" \ | |
270 | "continue to ignored & auto-deleted break marker1" | |
c906108c SS |
271 | |
272 | # Verify that a disabled breakpoint's ignore count isn't updated when | |
273 | # the bp is encountered. | |
c906108c | 274 | |
9c7bb332 AC |
275 | if ![runto_main] then { |
276 | fail "enable/disable break tests suppressed" | |
c906108c SS |
277 | } |
278 | ||
9c7bb332 | 279 | set bp [break_at marker1 " line ($bp_location15|$bp_location16)"] |
c906108c | 280 | |
9c7bb332 AC |
281 | gdb_test "ignore $bp 10" \ |
282 | "Will ignore next 10 crossings of breakpoint \[0-9\]*.*" \ | |
283 | "ignore break marker1" | |
284 | ||
27d3a1a2 | 285 | gdb_test_no_output "disable $bp" "disable break marker1" |
c906108c | 286 | |
7a292a7a SS |
287 | gdb_continue_to_end "no stop at ignored & disabled break marker1" |
288 | rerun_to_main | |
c906108c | 289 | |
9c7bb332 AC |
290 | gdb_test "info break $bp" \ |
291 | "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*" \ | |
292 | "info ignored & disabled break marker1" | |
c906108c SS |
293 | |
294 | # Verify that GDB correctly handles the "continue" command with an argument, | |
295 | # which is an ignore count to set on the currently stopped-at breakpoint. | |
296 | # (Also verify that GDB gracefully handles the case where the inferior | |
297 | # isn't stopped at a breakpoint.) | |
298 | # | |
299 | if ![runto_main] then { fail "enable/disable break tests suppressed" } | |
300 | ||
9c7bb332 AC |
301 | gdb_test "break $bp_location1" \ |
302 | "Breakpoint \[0-9\]*.*, line $bp_location1.*" \ | |
303 | "prepare to continue with ignore count" | |
304 | ||
305 | gdb_test "continue 2" \ | |
306 | "Will ignore next crossing of breakpoint \[0-9\]*. Continuing..*" \ | |
307 | "continue with ignore count" | |
308 | ||
309 | gdb_test "next" ".*$bp_location11\[ \t\]*marker1.*" \ | |
310 | step after continue with ignore count" | |
311 | ||
312 | set test "continue with ignore count, not stopped at bpt" | |
313 | gdb_test_multiple "continue 2" "$test" { | |
314 | -re "Not stopped at any breakpoint; argument ignored.*$gdb_prompt $" { | |
315 | pass "$test" | |
316 | } | |
317 | -re "No breakpoint number -1.*$gdb_prompt $" { | |
318 | kfail gdb/1689 "$test" | |
319 | } | |
c906108c SS |
320 | } |
321 | ||
322 | gdb_exit | |
323 | return 0 |