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