]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/ena-dis-br-range.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / ena-dis-br-range.exp
CommitLineData
1d506c26 1# Copyright 2017-2024 Free Software Foundation, Inc.
d0fe4701
XR
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# This file is part of the gdb testsuite.
17
18# Test the enable/disable commands with breakpoint location ranges.
19
20# Note: more tests involving involving disable/enable commands on
21# multiple locations and breakpoints are found in
22# gdb.base/ena-dis-br.exp.
23
0b94d2b9 24require allow_cplus_tests
d0fe4701
XR
25
26standard_testfile .cc
27
28if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
29 return -1
30}
31
95701cae 32if {![runto 'marker']} {
d0fe4701
XR
33 return -1
34}
35
36# Returns a buffer corresponding to what GDB replies when asking for
37# 'info breakpoint'. The parameters are all the existing breakpoints
38# enabled/disable value: 'n' or 'y'.
39
40proc make_info_breakpoint_reply_re {b1 b2 b21 b22 b23 b24} {
41 set ws "\[\t \]+"
42 return [multi_line \
43 "Num Type${ws}Disp Enb Address${ws}What.*" \
44 "1${ws}breakpoint keep ${b1}${ws}.* in marker\\(\\) at .*" \
45 "${ws}breakpoint already hit 1 time.*" \
46 "2${ws}breakpoint${ws}keep${ws}${b2}${ws}<MULTIPLE>.*" \
fbcda577
PA
47 "2.1${ws}${b21}${ws}.*" \
48 "2.2${ws}${b22}${ws}.*" \
49 "2.3${ws}${b23}${ws}.*" \
50 "2.4${ws}${b24}${ws}.*" \
d0fe4701
XR
51 ]
52}
53
54gdb_test "break foo::overload" \
55 "Breakpoint \[0-9\]+ at $hex: foo::overload. .4 locations." \
56 "set breakpoint at overload"
57
58gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
59 "breakpoint info"
60
61# Test the enable/disable commands, and check the enable/disable state
62# of the breakpoints/locations in the "info break" output. CMD is the
63# actual disable/enable command. The bNN parameters are the same as
64# make_info_breakpoint_reply_re's.
65proc test_enable_disable {cmd b1 b2 b21 b22 b23 b24} {
66 gdb_test_no_output $cmd
67
68 set re [make_info_breakpoint_reply_re $b1 $b2 $b21 $b22 $b23 $b24]
69 gdb_test "info break" $re "breakpoint info $cmd"
70}
71
72# Check that we can disable/enable a breakpoint with a single
73# location.
74test_enable_disable "disable 1" n y y y y y
75test_enable_disable "enable 1" y y y y y y
76
fbcda577 77# Check that we can disable/enable a breakpoint with multiple
d0fe4701 78# locations.
fbcda577
PA
79test_enable_disable "disable 2" y n y- y- y- y-
80test_enable_disable "enable 2" y y y y y y
d0fe4701 81
fbcda577
PA
82# Check that we can disable/enable a range of breakpoints.
83test_enable_disable "disable 1-2" n n y- y- y- y-
84test_enable_disable "enable 1-2" y y y y y y
a02b41a7 85
fbcda577
PA
86# Check that we can disable/enable a list of breakpoints.
87test_enable_disable "disable 1 2" n n y- y- y- y-
88test_enable_disable "enable 1 2" y y y y y y
a02b41a7 89
d0fe4701
XR
90# Check that we can disable/enable a single location breakpoint.
91test_enable_disable "disable 2.2" y y y n y y
92test_enable_disable "enable 2.2" y y y y y y
93
94# Check that we can disable/enable a range of breakpoint locations.
95test_enable_disable "disable 2.2-3" y y y n n y
96test_enable_disable "enable 2.2-3" y y y y y y
97
98# Check that we can disable/enable a breakpoint location range with
99# START==END.
100test_enable_disable "disable 2.2-2" y y y n y y
101test_enable_disable "enable 2.2-2" y y y y y y
102
fbcda577 103# Check that we can disable/enable a list of breakpoints that
a02b41a7
PA
104# includes some elements with location ranges and others without.
105test_enable_disable "disable 1 2.1 2.3-4" n y n y n n
106test_enable_disable "enable 1 2.1 2.3-4" y y y y y y
107
d0fe4701
XR
108# Check that we can disable a location breakpoint range with max >
109# existing breakpoint location.
110gdb_test "disable 2.3-5" "Bad breakpoint location number '5'" \
111 "disable location breakpoint range with max > existing"
112
113gdb_test "info break" [make_info_breakpoint_reply_re y y y y n n] \
114 "breakpoint info disable 2.3 to 2.5"
115
116# Check that we can enable a location breakpoint range with max >
117# existing breakpoint location.
118gdb_test "enable 2.3-5" "Bad breakpoint location number '5'" \
119 "enable location breakpoint range with max > existing"
120
121gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
122 "breakpoint info enable 2.3 to 2.5"
123
95e95a6d 124# Check that disabling an inverted breakpoint location range does not
d0fe4701 125# work.
95e95a6d 126gdb_test "disable 2.3-2" "Inverted breakpoint location range at '3-2'"
d0fe4701
XR
127
128gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
129 "breakpoint info disable 2.3-2"
130
131# Check that disabling an invalid breakpoint location range does not
132# cause unexpected behavior.
133gdb_test "disable 2.6-7" "Bad breakpoint location number '6'" \
134 "disable an unvalid location breakpoint range"
135
136gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
137 "breakpoint info disable 2.6-7"
138
139# Check that disabling an invalid breakpoint location range does not
140# cause trouble.
95e95a6d 141gdb_test "disable 2.8-6" "Inverted breakpoint location range at '8-6'"
d0fe4701
XR
142
143gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
144 "breakpoint info disable 2.8-6"
cee62dbd
PA
145
146# Check that invalid/open ranges are handled correctly.
147with_test_prefix "open range" {
95e95a6d
PA
148 gdb_test "disable -" "Bad breakpoint number at or near: '-'"
149 gdb_test "disable -1" "Negative breakpoint number '-1'"
150 gdb_test "disable 1-" "Bad breakpoint number at or near: '1-'"
151 gdb_test "disable 1.-2" "Negative breakpoint location number '-2'"
152 gdb_test "disable 1.2-" "Bad breakpoint location number at or near: '2-'"
153 gdb_test "disable 1.-2-3" "Negative breakpoint location number '-2'"
154 gdb_test "disable 1-2-3" "Bad breakpoint number '2-3'"
cee62dbd
PA
155}
156
157with_test_prefix "dangling period" {
95e95a6d
PA
158 gdb_test "disable 2." "Bad breakpoint number at or near: '2.'"
159 gdb_test "disable .2" "Bad breakpoint number at or near: '.2'"
160 gdb_test "disable 2.3.4" "Bad breakpoint location number '3.4'"
cee62dbd
PA
161}
162
163# Check that 0s are handled correctly.
164with_test_prefix "zero" {
95e95a6d
PA
165 gdb_test "disable 0" "Bad breakpoint number '0'"
166 gdb_test "disable 0.0" "Bad breakpoint number '0'"
167 gdb_test "disable 0.1" "Bad breakpoint number '0'"
168 gdb_test "disable 0.1-2" "Bad breakpoint number '0'"
169 gdb_test "disable 2.0" "Bad breakpoint location number '0'"
170 gdb_test "disable 2.0-0" "Bad breakpoint location number '0'"
171 gdb_test "disable 2.0-1" "Bad breakpoint location number '0'"
172 gdb_test "disable 2.1-0" "Bad breakpoint location number '0'"
173}
174
175# Test "disable BPLIST" with an invalid breakpoint/location BPLIST.
176# PREFIX and SUFFIX are concatenated to form BPLIST. The invalid part
177# is always in SUFFIX.
178
179proc disable_invalid {prefix suffix} {
180 set bad_re [string_to_regexp $suffix]
181
182 if {$prefix == ""} {
183 gdb_test \
184 "disable $suffix" \
185 "Bad breakpoint number '${bad_re}'"
186 } else {
187 gdb_test \
188 "disable ${prefix}$suffix" \
189 "Bad breakpoint location number '${bad_re}'"
190 }
191}
cee62dbd 192
95e95a6d 193# Like disable_invalid, but expects an "inverted range" error.
cee62dbd 194
95e95a6d
PA
195proc disable_inverted {prefix suffix} {
196 set bad_re [string_to_regexp $suffix]
197
198 if {$prefix == ""} {
199 gdb_test \
200 "disable $suffix" \
201 "Inverted breakpoint range at '${bad_re}'"
202 } else {
203 gdb_test \
204 "disable ${prefix}$suffix" \
205 "Inverted breakpoint location range at '${bad_re}'"
206 }
207}
208
209# Like disable_invalid, but expects a "negative number" error.
210
211proc disable_negative {prefix suffix} {
212 set bad_re [string_to_regexp $suffix]
213
214 if {$prefix == ""} {
215 gdb_test \
216 "disable $suffix" \
217 "Negative breakpoint number '${bad_re}'"
218 } else {
219 gdb_test \
220 "disable ${prefix}$suffix" \
221 "Negative breakpoint location number '${bad_re}'"
222 }
223}
cee62dbd 224
95e95a6d
PA
225with_test_prefix "bad numbers" {
226 gdb_test "p \$zero = 0" " = 0"
227 gdb_test "p \$one = 1" " = 1"
228 gdb_test "p \$two = 2" " = 2"
229 gdb_test "p \$minus_one = -1" " = -1"
230 foreach prefix {"" "1." "$one."} {
231 set prefix_re [string_to_regexp $prefix]
232
233 disable_invalid $prefix "foo"
234 disable_invalid $prefix "1foo"
235 disable_invalid $prefix "foo1"
236
237 disable_inverted $prefix "2-1"
238 disable_inverted $prefix "2-\$one"
239 disable_inverted $prefix "\$two-1"
240 disable_inverted $prefix "\$two-\$one"
241
242 disable_negative $prefix "-1"
243 disable_negative $prefix "-\$one"
244 disable_negative $prefix "\$minus_one"
245 }
cee62dbd
PA
246}
247
248gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
249 "breakpoint info after invalids"