]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/ena-dis-br.exp
6a73bbeb311cbe8df6f5a1b0a479ea402d94a29a
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ena-dis-br.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 1997, 1998, 1999, 2003, 2004 Free Software Foundation,
4 # Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 global usestubs
25
26 #
27 # test running programs
28 #
29 set prms_id 0
30 set bug_id 0
31
32 set testfile "break"
33 set srcfile ${testfile}.c
34 set srcfile1 ${testfile}1.c
35 set binfile ${objdir}/${subdir}/${testfile}
36
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
38 untested ena-dis-br.exp
39 return -1
40 }
41
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
43 untested ena-dis-br.exp
44 return -1
45 }
46
47 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
48 untested ena-dis-br.exp
49 return -1
50 }
51
52 gdb_exit
53 gdb_start
54 gdb_reinitialize_dir $srcdir/$subdir
55 gdb_load ${binfile}
56
57 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
58 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
59 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
60 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
61 set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
62 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
63 set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile1]
64 set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile1]
65 set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile1]
66 set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile1]
67
68 if ![runto_main] then { fail "enable/disable break tests suppressed" }
69
70 # Verify that we can set a breakpoint (the location is irrelevant),
71 # then enable it (yes, it's already enabled by default), then hit it.
72
73 proc break_at { breakpoint where } {
74 global gdb_prompt
75 global expect_out
76
77 set test "break $breakpoint"
78 set bp 0
79 gdb_test_multiple "$test" "$test" {
80 -re "Breakpoint (\[0-9\]*) at .*$where.*$gdb_prompt $" {
81 set bp $expect_out(1,string)
82 pass "$test"
83 }
84 }
85 return $bp
86 }
87
88 set bp [break_at "marker1" " line ($bp_location15|$bp_location16)"]
89
90 gdb_test "enable $bp" "" "enable break marker1"
91
92 gdb_test "info break $bp" \
93 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*" \
94 "info break marker1"
95
96 # See the comments in condbreak.exp for "run until breakpoint at
97 # marker1" for an explanation of the xfail below.
98 set test "continue to break marker1"
99 gdb_test_multiple "continue" "$test" {
100 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
101 pass "$test"
102 }
103 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
104 xfail "$test"
105 }
106 }
107
108 gdb_test "delete $bp" "" "delete break marker1"
109
110 # Verify that we can set a breakpoint to be self-disabling after the
111 # first time it triggers.
112 set bp [break_at "marker2" " line ($bp_location8|$bp_location9)"]
113
114 gdb_test "enable once $bp" "" "enable once break marker2"
115
116 gdb_test "info break $bp" \
117 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*" \
118 "info auto-disabled break marker2"
119
120 # See the comments in condbreak.exp for "run until breakpoint at
121 # marker1" for an explanation of the xfail below.
122 set test "continue to auto-disabled break marker2"
123 gdb_test_multiple "continue" "$test" {
124 -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $" {
125 pass "$test"
126 }
127 -re "Breakpoint \[0-9\]*, $hex in marker2.*$gdb_prompt $" {
128 xfail "$test"
129 }
130 }
131
132 gdb_test "info break $bp" \
133 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*" \
134 "info auto-disabled break marker2"
135
136 # Verify that we don't stop at a disabled breakpoint.
137 gdb_continue_to_end "no stop"
138 rerun_to_main
139 gdb_continue_to_end "no stop at auto-disabled break marker2"
140
141 # Verify that we can set a breakpoint to be self-deleting after the
142 # first time it triggers.
143 if ![runto_main] then {
144 fail "enable/disable break tests suppressed"
145 }
146
147 set bp [break_at "marker3" " line ($bp_location17|$bp_location18)"]
148
149 gdb_test "enable del $bp" "" "enable del break marker3"
150
151 gdb_test "info break $bp" \
152 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*" \
153 "info auto-deleted break marker2"
154
155 gdb_test "continue" \
156 ".*marker3 .*:($bp_location17|$bp_location18).*" \
157 "continue to auto-deleted break marker3"
158
159 gdb_test "info break $bp" \
160 ".*No breakpoint or watchpoint number.*" \
161 "info auto-deleted break marker3"
162
163 # Verify that we can set a breakpoint and manually disable it (we've
164 # already proven that disabled bp's don't trigger).
165
166 set bp [break_at "marker4" " line ($bp_location14|$bp_location13).*"]
167
168 gdb_test "disable $bp" "" "disable break marker4"
169
170 gdb_test "info break $bp" \
171 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*" \
172 "info break marker4"
173
174 # Verify that we can set a breakpoint with an ignore count N, which
175 # should cause the next N triggers of the bp to be ignored. (This is
176 # a flavor of enablement/disablement, after all.)
177
178 if ![runto_main] then {
179 fail "enable/disable break tests suppressed"
180 }
181
182 set bp [break_at "marker1" " line ($bp_location15|$bp_location16).*"]
183
184 # Verify that an ignore of a non-existent breakpoint is gracefully
185 # handled.
186
187 gdb_test "ignore 999 2" \
188 "No breakpoint number 999..*" \
189 "ignore non-existent break"
190
191 # Verify that a missing ignore count is gracefully handled.
192
193 gdb_test "ignore $bp" \
194 "Second argument .specified ignore-count. is missing..*" \
195 "ignore break with missing ignore count"
196
197 # Verify that a negative or zero ignore count is handled gracefully
198 # (they both are treated the same).
199
200 gdb_test "ignore $bp -1" \
201 "Will stop next time breakpoint \[0-9\]* is reached..*" \
202 "ignore break marker1 -1"
203
204 gdb_test "ignore $bp 0" \
205 "Will stop next time breakpoint \[0-9\]* is reached..*" \
206 "ignore break marker1 0"
207
208 gdb_test "ignore $bp 1" \
209 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
210 "ignore break marker1"
211
212 gdb_test "info break $bp" \
213 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*" \
214 "info ignored break marker1"
215
216 gdb_continue_to_end "no stop at ignored break marker1"
217 rerun_to_main
218
219 # See the comments in condbreak.exp for "run until breakpoint at marker1"
220 # for an explanation of the xfail below.
221 set test "continue to break marker1, 2nd time"
222 gdb_test_multiple "continue" "$test" {
223 -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
224 pass "continue to break marker1, 2nd time"
225 }
226 -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
227 xfail "continue to break marker1, 2nd time"
228 }
229 }
230
231 # Verify that we can specify both an ignore count and an auto-delete.
232
233 if ![runto_main] then {
234 fail "enable/disable break tests suppressed"
235 }
236
237 set bp [break_at marker1 " line ($bp_location15|$bp_location16).*"]
238
239 gdb_test "ignore $bp 1" \
240 "Will ignore next crossing of breakpoint \[0-9\]*.*" \
241 "ignore break marker1"
242
243 gdb_test "enable del $bp" "" "enable del break marker1"
244
245 gdb_test "info break $bp" \
246 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*" \
247 "info break marker1"
248
249 gdb_continue_to_end "no stop at ignored & auto-deleted break marker1"
250 rerun_to_main
251
252 gdb_test "continue" \
253 ".*marker1 .*:($bp_location15|$bp_location16).*" \
254 "continue to ignored & auto-deleted break marker1"
255
256 # Verify that a disabled breakpoint's ignore count isn't updated when
257 # the bp is encountered.
258
259 if ![runto_main] then {
260 fail "enable/disable break tests suppressed"
261 }
262
263 set bp [break_at marker1 " line ($bp_location15|$bp_location16)"]
264
265 gdb_test "ignore $bp 10" \
266 "Will ignore next 10 crossings of breakpoint \[0-9\]*.*" \
267 "ignore break marker1"
268
269 gdb_test "disable $bp" "" "disable break marker1"
270
271 gdb_continue_to_end "no stop at ignored & disabled break marker1"
272 rerun_to_main
273
274 gdb_test "info break $bp" \
275 "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*" \
276 "info ignored & disabled break marker1"
277
278 # Verify that GDB correctly handles the "continue" command with an argument,
279 # which is an ignore count to set on the currently stopped-at breakpoint.
280 # (Also verify that GDB gracefully handles the case where the inferior
281 # isn't stopped at a breakpoint.)
282 #
283 if ![runto_main] then { fail "enable/disable break tests suppressed" }
284
285 gdb_test "break $bp_location1" \
286 "Breakpoint \[0-9\]*.*, line $bp_location1.*" \
287 "prepare to continue with ignore count"
288
289 gdb_test "continue 2" \
290 "Will ignore next crossing of breakpoint \[0-9\]*. Continuing..*" \
291 "continue with ignore count"
292
293 gdb_test "next" ".*$bp_location11\[ \t\]*marker1.*" \
294 step after continue with ignore count"
295
296 set test "continue with ignore count, not stopped at bpt"
297 gdb_test_multiple "continue 2" "$test" {
298 -re "Not stopped at any breakpoint; argument ignored.*$gdb_prompt $" {
299 pass "$test"
300 }
301 -re "No breakpoint number -1.*$gdb_prompt $" {
302 kfail gdb/1689 "$test"
303 }
304 }
305
306 gdb_exit
307 return 0