aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/ena-dis-br.exp
blob: 83d83c63ff6a9e8c3b592d49114659a07782ae8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# This testcase is part of GDB, the GNU debugger.

# Copyright 1997, 1998, 1999, 2003, 2004, 2007, 2008, 2009, 2010
# Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if $tracelevel then {
    strace $tracelevel
}

global usestubs

#
# test running programs
#

set testfile "break"
set srcfile ${testfile}.c
set srcfile1 ${testfile}1.c
set binfile ${objdir}/${subdir}/${testfile}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
     untested ena-dis-br.exp
     return -1
}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
     untested ena-dis-br.exp
     return -1
}

if  { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
     untested ena-dis-br.exp
     return -1
}

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile1]
set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile1]
set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile1]
set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile1]

if ![runto_main] then { fail "enable/disable break tests suppressed" }

# Verify that we can set a breakpoint (the location is irrelevant),
# then enable it (yes, it's already enabled by default), then hit it.

proc break_at { breakpoint where } {
    global gdb_prompt
    global expect_out

    set test "break $breakpoint"
    set bp 0
    gdb_test_multiple "$test" "$test" {
	-re "Breakpoint (\[0-9\]*) at .*$where.*$gdb_prompt $" {
	    set bp $expect_out(1,string)
	    pass "$test"
	}
    }
    return $bp
}

set bp [break_at "marker1" " line ($bp_location15|$bp_location16)"]

gdb_test_no_output "enable $bp" "enable break marker1"

gdb_test "info break $bp" \
    "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*" \
    "info break marker1"

# See the comments in condbreak.exp for "run until breakpoint at
# marker1" for an explanation of the xfail below.
set test "continue to break marker1"
gdb_test_multiple "continue" "$test" {
    -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
	pass "$test"
    }
    -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
	xfail "$test"
    }
}

gdb_test_no_output "delete $bp" "delete break marker1"

# Verify that we can set a breakpoint to be self-disabling after the
# first time it triggers.
set bp [break_at "marker2" " line ($bp_location8|$bp_location9)"]

gdb_test_no_output "enable once $bp" "enable once break marker2"

gdb_test "info break $bp" \
    "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+y.*" \
    "info auto-disabled break marker2"

# See the comments in condbreak.exp for "run until breakpoint at
# marker1" for an explanation of the xfail below.
set test "continue to auto-disabled break marker2"
gdb_test_multiple "continue" "$test" {
    -re "Breakpoint \[0-9\]*, marker2.*$gdb_prompt $" {
	pass "$test"
    }
    -re "Breakpoint \[0-9\]*, $hex in marker2.*$gdb_prompt $" {
	xfail "$test"
    }
}

gdb_test "info break $bp" \
    "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+dis\[ \t\]+n.*" \
    "info auto-disabled break marker2"

# Verify that we don't stop at a disabled breakpoint.
gdb_continue_to_end "no stop"
rerun_to_main
gdb_continue_to_end "no stop at auto-disabled break marker2"

# Verify that we can set a breakpoint to be self-deleting after the
# first time it triggers.
if ![runto_main] then {
    fail "enable/disable break tests suppressed"
}

set bp [break_at "marker3" " line ($bp_location17|$bp_location18)"]

gdb_test_no_output "enable del $bp" "enable del break marker3"

gdb_test "info break $bp" \
    "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*" \
    "info auto-deleted break marker2"

gdb_test "continue" \
    ".*marker3 .*:($bp_location17|$bp_location18).*" \
    "continue to auto-deleted break marker3"

gdb_test "info break $bp" \
    ".*No breakpoint or watchpoint number.*" \
    "info auto-deleted break marker3"

# Verify that we can set a breakpoint and manually disable it (we've
# already proven that disabled bp's don't trigger).

set bp [break_at "marker4" " line ($bp_location14|$bp_location13).*"]

gdb_test_no_output "disable $bp" "disable break marker4"

gdb_test "info break $bp" \
    "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*" \
    "info break marker4"

# Verify that we can set a breakpoint with an ignore count N, which
# should cause the next N triggers of the bp to be ignored.  (This is
# a flavor of enablement/disablement, after all.)

if ![runto_main] then {
    fail "enable/disable break tests suppressed"
}

set bp [break_at "marker1" " line ($bp_location15|$bp_location16).*"]

# Verify that an ignore of a non-existent breakpoint is gracefully
# handled.

gdb_test "ignore 999 2" \
    "No breakpoint number 999..*" \
    "ignore non-existent break"

# Verify that a missing ignore count is gracefully handled.

gdb_test "ignore $bp" \
    "Second argument .specified ignore-count. is missing..*" \
    "ignore break with missing ignore count"

# Verify that a negative or zero ignore count is handled gracefully
# (they both are treated the same).

gdb_test "ignore $bp -1" \
    "Will stop next time breakpoint \[0-9\]* is reached..*" \
    "ignore break marker1 -1"

gdb_test "ignore $bp 0" \
    "Will stop next time breakpoint \[0-9\]* is reached..*" \
    "ignore break marker1 0"

gdb_test "ignore $bp 1" \
    "Will ignore next crossing of breakpoint \[0-9\]*.*" \
    "ignore break marker1"

gdb_test "info break $bp" \
    "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+y.*ignore next 1 hits.*" \
    "info ignored break marker1"

gdb_continue_to_end "no stop at ignored break marker1"
rerun_to_main

# See the comments in condbreak.exp for "run until breakpoint at marker1" 
# for an explanation of the xfail below.
set test "continue to break marker1, 2nd time"
gdb_test_multiple "continue" "$test" {
    -re "Breakpoint \[0-9\]*, marker1.*$gdb_prompt $" {
	pass "continue to break marker1, 2nd time"
    }
    -re "Breakpoint \[0-9\]*, $hex in marker1.*$gdb_prompt $" {
	xfail "continue to break marker1, 2nd time"
    }
}

# Verify that we can specify both an ignore count and an auto-delete.

if ![runto_main] then {
    fail "enable/disable break tests suppressed"
}

set bp [break_at marker1 " line ($bp_location15|$bp_location16).*"]

gdb_test "ignore $bp 1" \
    "Will ignore next crossing of breakpoint \[0-9\]*.*" \
    "ignore break marker1"

gdb_test_no_output "enable del $bp" "enable del break marker1"

gdb_test "info break $bp" \
    "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+del\[ \t\]+y.*ignore next 1 hits.*" \
    "info break marker1"

gdb_continue_to_end "no stop at ignored & auto-deleted break marker1"
rerun_to_main

gdb_test "continue" \
    ".*marker1 .*:($bp_location15|$bp_location16).*" \
    "continue to ignored & auto-deleted break marker1"

# Verify that a disabled breakpoint's ignore count isn't updated when
# the bp is encountered.

if ![runto_main] then {
    fail "enable/disable break tests suppressed"
}

set bp [break_at marker1 " line ($bp_location15|$bp_location16)"]

gdb_test "ignore $bp 10" \
    "Will ignore next 10 crossings of breakpoint \[0-9\]*.*" \
    "ignore break marker1"

gdb_test_no_output "disable $bp" "disable break marker1"

gdb_continue_to_end "no stop at ignored & disabled break marker1"
rerun_to_main

gdb_test "info break $bp" \
    "\[0-9\]*\[ \t\]+breakpoint\[ \t\]+keep\[ \t\]+n.*ignore next 10 hits.*" \
    "info ignored & disabled break marker1"

# Verify that GDB correctly handles the "continue" command with an argument,
# which is an ignore count to set on the currently stopped-at breakpoint.
# (Also verify that GDB gracefully handles the case where the inferior
# isn't stopped at a breakpoint.)
#
if ![runto_main] then { fail "enable/disable break tests suppressed" }

gdb_test "break $bp_location1" \
    "Breakpoint \[0-9\]*.*, line $bp_location1.*" \
    "prepare to continue with ignore count"

gdb_test "continue 2" \
    "Will ignore next crossing of breakpoint \[0-9\]*.  Continuing..*" \
    "continue with ignore count"

gdb_test "next" ".*$bp_location11\[ \t\]*marker1.*" \
    step after continue with ignore count"

set test "continue with ignore count, not stopped at bpt"
gdb_test_multiple "continue 2" "$test" {
    -re "Not stopped at any breakpoint; argument ignored.*$gdb_prompt $" {
	pass "$test"
    }
    -re "No breakpoint number -1.*$gdb_prompt $" {
	kfail gdb/1689 "$test"
    }
}

gdb_exit
return 0