binutils-gdb/gdb/testsuite/gdb.cp/ena-dis-br-range.exp

251 lines
8.4 KiB
Plaintext
Raw Normal View History

# Copyright 2017-2018 Free Software Foundation, Inc.
Allow enabling/disabling breakpoint location ranges When a breakpoint has multiple locations, like e.g.: Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x080486a2 in void foo<int>()... 1.2 y 0x080486ca in void foo<double>()... [....] 1.5 y 0x080487fa in void foo<long>()... it's possible to enable/disable the individual locations using the '<breakpoint_number>.<location_number>' syntax, like e.g.: (gdb) disable 1.2 1.3 1.4 1.5 That's inconvenient when you have a long list of locations to disable, however. This patch adds shorthand for the above, by making it possible to specify a range of locations with the following syntax (similar to thread id ranges): <breakpoint_number>.<first_location_number>-<last_location_number> For example, the command above can now be simplified to: (gdb) disable 1.2-5 gdb/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * breakpoint.c (map_breakpoint_number_range): New, factored out from ... (map_breakpoint_numbers): ... here. (find_location_by_number): Change parameters from string to breakpoint number and location. (extract_bp_number_and_location): New function. (enable_disable_bp_num_loc) (enable_disable_breakpoint_location_range) (enable_disable_command): New functions, factored out ... (enable_command, disable_command): ... these functions, and adjusted to support ranges. * NEWS: Document enable/disable breakpoint location range feature. gdb/doc/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.texinfo (Set Breaks): Document support for breakpoint location ranges in the enable/disable commands. gdb/testsuite/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.base/ena-dis-br.exp: Add reference to gdb.cp/ena-dis-br-range.exp. * gdb.cp/ena-dis-br-range.exp: New file. * gdb.cp/ena-dis-br-range.cc: New file.
2017-11-07 12:00:31 +01:00
# 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/>.
# This file is part of the gdb testsuite.
# Test the enable/disable commands with breakpoint location ranges.
# Note: more tests involving involving disable/enable commands on
# multiple locations and breakpoints are found in
# gdb.base/ena-dis-br.exp.
if { [skip_cplus_tests] } { continue }
standard_testfile .cc
if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
return -1
}
if ![runto 'marker'] then {
fail "run to marker"
return -1
}
# Returns a buffer corresponding to what GDB replies when asking for
# 'info breakpoint'. The parameters are all the existing breakpoints
# enabled/disable value: 'n' or 'y'.
proc make_info_breakpoint_reply_re {b1 b2 b21 b22 b23 b24} {
set ws "\[\t \]+"
return [multi_line \
"Num Type${ws}Disp Enb Address${ws}What.*" \
"1${ws}breakpoint keep ${b1}${ws}.* in marker\\(\\) at .*" \
"${ws}breakpoint already hit 1 time.*" \
"2${ws}breakpoint${ws}keep${ws}${b2}${ws}<MULTIPLE>.*" \
"2.1${ws}${b21}.*" \
"2.2${ws}${b22}.*" \
"2.3${ws}${b23}.*" \
"2.4${ws}${b24}.*" \
]
}
gdb_test "break foo::overload" \
"Breakpoint \[0-9\]+ at $hex: foo::overload. .4 locations." \
"set breakpoint at overload"
gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
"breakpoint info"
# Test the enable/disable commands, and check the enable/disable state
# of the breakpoints/locations in the "info break" output. CMD is the
# actual disable/enable command. The bNN parameters are the same as
# make_info_breakpoint_reply_re's.
proc test_enable_disable {cmd b1 b2 b21 b22 b23 b24} {
gdb_test_no_output $cmd
set re [make_info_breakpoint_reply_re $b1 $b2 $b21 $b22 $b23 $b24]
gdb_test "info break" $re "breakpoint info $cmd"
}
# Check that we can disable/enable a breakpoint with a single
# location.
test_enable_disable "disable 1" n y y y y y
test_enable_disable "enable 1" y y y y y y
# Check that we can disable/disable a breakpoint with multiple
# locations.
test_enable_disable "disable 2" y n y y y y
test_enable_disable "enable 2" y y y y y y
# Check that we can disable/disable a range of breakpoints.
test_enable_disable "disable 1-2" n n y y y y
test_enable_disable "enable 1-2" y y y y y y
# Check that we can disable/disable a list of breakpoints.
test_enable_disable "disable 1 2" n n y y y y
test_enable_disable "enable 1 2" y y y y y y
Allow enabling/disabling breakpoint location ranges When a breakpoint has multiple locations, like e.g.: Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x080486a2 in void foo<int>()... 1.2 y 0x080486ca in void foo<double>()... [....] 1.5 y 0x080487fa in void foo<long>()... it's possible to enable/disable the individual locations using the '<breakpoint_number>.<location_number>' syntax, like e.g.: (gdb) disable 1.2 1.3 1.4 1.5 That's inconvenient when you have a long list of locations to disable, however. This patch adds shorthand for the above, by making it possible to specify a range of locations with the following syntax (similar to thread id ranges): <breakpoint_number>.<first_location_number>-<last_location_number> For example, the command above can now be simplified to: (gdb) disable 1.2-5 gdb/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * breakpoint.c (map_breakpoint_number_range): New, factored out from ... (map_breakpoint_numbers): ... here. (find_location_by_number): Change parameters from string to breakpoint number and location. (extract_bp_number_and_location): New function. (enable_disable_bp_num_loc) (enable_disable_breakpoint_location_range) (enable_disable_command): New functions, factored out ... (enable_command, disable_command): ... these functions, and adjusted to support ranges. * NEWS: Document enable/disable breakpoint location range feature. gdb/doc/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.texinfo (Set Breaks): Document support for breakpoint location ranges in the enable/disable commands. gdb/testsuite/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.base/ena-dis-br.exp: Add reference to gdb.cp/ena-dis-br-range.exp. * gdb.cp/ena-dis-br-range.exp: New file. * gdb.cp/ena-dis-br-range.cc: New file.
2017-11-07 12:00:31 +01:00
# Check that we can disable/enable a single location breakpoint.
test_enable_disable "disable 2.2" y y y n y y
test_enable_disable "enable 2.2" y y y y y y
# Check that we can disable/enable a range of breakpoint locations.
test_enable_disable "disable 2.2-3" y y y n n y
test_enable_disable "enable 2.2-3" y y y y y y
# Check that we can disable/enable a breakpoint location range with
# START==END.
test_enable_disable "disable 2.2-2" y y y n y y
test_enable_disable "enable 2.2-2" y y y y y y
# Check that we can disable/disable a list of breakpoints that
# includes some elements with location ranges and others without.
test_enable_disable "disable 1 2.1 2.3-4" n y n y n n
test_enable_disable "enable 1 2.1 2.3-4" y y y y y y
Allow enabling/disabling breakpoint location ranges When a breakpoint has multiple locations, like e.g.: Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x080486a2 in void foo<int>()... 1.2 y 0x080486ca in void foo<double>()... [....] 1.5 y 0x080487fa in void foo<long>()... it's possible to enable/disable the individual locations using the '<breakpoint_number>.<location_number>' syntax, like e.g.: (gdb) disable 1.2 1.3 1.4 1.5 That's inconvenient when you have a long list of locations to disable, however. This patch adds shorthand for the above, by making it possible to specify a range of locations with the following syntax (similar to thread id ranges): <breakpoint_number>.<first_location_number>-<last_location_number> For example, the command above can now be simplified to: (gdb) disable 1.2-5 gdb/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * breakpoint.c (map_breakpoint_number_range): New, factored out from ... (map_breakpoint_numbers): ... here. (find_location_by_number): Change parameters from string to breakpoint number and location. (extract_bp_number_and_location): New function. (enable_disable_bp_num_loc) (enable_disable_breakpoint_location_range) (enable_disable_command): New functions, factored out ... (enable_command, disable_command): ... these functions, and adjusted to support ranges. * NEWS: Document enable/disable breakpoint location range feature. gdb/doc/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.texinfo (Set Breaks): Document support for breakpoint location ranges in the enable/disable commands. gdb/testsuite/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.base/ena-dis-br.exp: Add reference to gdb.cp/ena-dis-br-range.exp. * gdb.cp/ena-dis-br-range.exp: New file. * gdb.cp/ena-dis-br-range.cc: New file.
2017-11-07 12:00:31 +01:00
# Check that we can disable a location breakpoint range with max >
# existing breakpoint location.
gdb_test "disable 2.3-5" "Bad breakpoint location number '5'" \
"disable location breakpoint range with max > existing"
gdb_test "info break" [make_info_breakpoint_reply_re y y y y n n] \
"breakpoint info disable 2.3 to 2.5"
# Check that we can enable a location breakpoint range with max >
# existing breakpoint location.
gdb_test "enable 2.3-5" "Bad breakpoint location number '5'" \
"enable location breakpoint range with max > existing"
gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
"breakpoint info enable 2.3 to 2.5"
# Check that disabling an inverted breakpoint location range does not
Allow enabling/disabling breakpoint location ranges When a breakpoint has multiple locations, like e.g.: Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x080486a2 in void foo<int>()... 1.2 y 0x080486ca in void foo<double>()... [....] 1.5 y 0x080487fa in void foo<long>()... it's possible to enable/disable the individual locations using the '<breakpoint_number>.<location_number>' syntax, like e.g.: (gdb) disable 1.2 1.3 1.4 1.5 That's inconvenient when you have a long list of locations to disable, however. This patch adds shorthand for the above, by making it possible to specify a range of locations with the following syntax (similar to thread id ranges): <breakpoint_number>.<first_location_number>-<last_location_number> For example, the command above can now be simplified to: (gdb) disable 1.2-5 gdb/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * breakpoint.c (map_breakpoint_number_range): New, factored out from ... (map_breakpoint_numbers): ... here. (find_location_by_number): Change parameters from string to breakpoint number and location. (extract_bp_number_and_location): New function. (enable_disable_bp_num_loc) (enable_disable_breakpoint_location_range) (enable_disable_command): New functions, factored out ... (enable_command, disable_command): ... these functions, and adjusted to support ranges. * NEWS: Document enable/disable breakpoint location range feature. gdb/doc/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.texinfo (Set Breaks): Document support for breakpoint location ranges in the enable/disable commands. gdb/testsuite/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.base/ena-dis-br.exp: Add reference to gdb.cp/ena-dis-br-range.exp. * gdb.cp/ena-dis-br-range.exp: New file. * gdb.cp/ena-dis-br-range.cc: New file.
2017-11-07 12:00:31 +01:00
# work.
gdb_test "disable 2.3-2" "Inverted breakpoint location range at '3-2'"
Allow enabling/disabling breakpoint location ranges When a breakpoint has multiple locations, like e.g.: Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x080486a2 in void foo<int>()... 1.2 y 0x080486ca in void foo<double>()... [....] 1.5 y 0x080487fa in void foo<long>()... it's possible to enable/disable the individual locations using the '<breakpoint_number>.<location_number>' syntax, like e.g.: (gdb) disable 1.2 1.3 1.4 1.5 That's inconvenient when you have a long list of locations to disable, however. This patch adds shorthand for the above, by making it possible to specify a range of locations with the following syntax (similar to thread id ranges): <breakpoint_number>.<first_location_number>-<last_location_number> For example, the command above can now be simplified to: (gdb) disable 1.2-5 gdb/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * breakpoint.c (map_breakpoint_number_range): New, factored out from ... (map_breakpoint_numbers): ... here. (find_location_by_number): Change parameters from string to breakpoint number and location. (extract_bp_number_and_location): New function. (enable_disable_bp_num_loc) (enable_disable_breakpoint_location_range) (enable_disable_command): New functions, factored out ... (enable_command, disable_command): ... these functions, and adjusted to support ranges. * NEWS: Document enable/disable breakpoint location range feature. gdb/doc/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.texinfo (Set Breaks): Document support for breakpoint location ranges in the enable/disable commands. gdb/testsuite/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.base/ena-dis-br.exp: Add reference to gdb.cp/ena-dis-br-range.exp. * gdb.cp/ena-dis-br-range.exp: New file. * gdb.cp/ena-dis-br-range.cc: New file.
2017-11-07 12:00:31 +01:00
gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
"breakpoint info disable 2.3-2"
# Check that disabling an invalid breakpoint location range does not
# cause unexpected behavior.
gdb_test "disable 2.6-7" "Bad breakpoint location number '6'" \
"disable an unvalid location breakpoint range"
gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
"breakpoint info disable 2.6-7"
# Check that disabling an invalid breakpoint location range does not
# cause trouble.
gdb_test "disable 2.8-6" "Inverted breakpoint location range at '8-6'"
Allow enabling/disabling breakpoint location ranges When a breakpoint has multiple locations, like e.g.: Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> 1.1 y 0x080486a2 in void foo<int>()... 1.2 y 0x080486ca in void foo<double>()... [....] 1.5 y 0x080487fa in void foo<long>()... it's possible to enable/disable the individual locations using the '<breakpoint_number>.<location_number>' syntax, like e.g.: (gdb) disable 1.2 1.3 1.4 1.5 That's inconvenient when you have a long list of locations to disable, however. This patch adds shorthand for the above, by making it possible to specify a range of locations with the following syntax (similar to thread id ranges): <breakpoint_number>.<first_location_number>-<last_location_number> For example, the command above can now be simplified to: (gdb) disable 1.2-5 gdb/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * breakpoint.c (map_breakpoint_number_range): New, factored out from ... (map_breakpoint_numbers): ... here. (find_location_by_number): Change parameters from string to breakpoint number and location. (extract_bp_number_and_location): New function. (enable_disable_bp_num_loc) (enable_disable_breakpoint_location_range) (enable_disable_command): New functions, factored out ... (enable_command, disable_command): ... these functions, and adjusted to support ranges. * NEWS: Document enable/disable breakpoint location range feature. gdb/doc/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.texinfo (Set Breaks): Document support for breakpoint location ranges in the enable/disable commands. gdb/testsuite/ChangeLog: 2017-11-07 Xavier Roirand <roirand@adacore.com> Pedro Alves <palves@redhat.com> * gdb.base/ena-dis-br.exp: Add reference to gdb.cp/ena-dis-br-range.exp. * gdb.cp/ena-dis-br-range.exp: New file. * gdb.cp/ena-dis-br-range.cc: New file.
2017-11-07 12:00:31 +01:00
gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
"breakpoint info disable 2.8-6"
# Check that invalid/open ranges are handled correctly.
with_test_prefix "open range" {
gdb_test "disable -" "Bad breakpoint number at or near: '-'"
gdb_test "disable -1" "Negative breakpoint number '-1'"
gdb_test "disable 1-" "Bad breakpoint number at or near: '1-'"
gdb_test "disable 1.-2" "Negative breakpoint location number '-2'"
gdb_test "disable 1.2-" "Bad breakpoint location number at or near: '2-'"
gdb_test "disable 1.-2-3" "Negative breakpoint location number '-2'"
gdb_test "disable 1-2-3" "Bad breakpoint number '2-3'"
}
with_test_prefix "dangling period" {
gdb_test "disable 2." "Bad breakpoint number at or near: '2.'"
gdb_test "disable .2" "Bad breakpoint number at or near: '.2'"
gdb_test "disable 2.3.4" "Bad breakpoint location number '3.4'"
}
# Check that 0s are handled correctly.
with_test_prefix "zero" {
gdb_test "disable 0" "Bad breakpoint number '0'"
gdb_test "disable 0.0" "Bad breakpoint number '0'"
gdb_test "disable 0.1" "Bad breakpoint number '0'"
gdb_test "disable 0.1-2" "Bad breakpoint number '0'"
gdb_test "disable 2.0" "Bad breakpoint location number '0'"
gdb_test "disable 2.0-0" "Bad breakpoint location number '0'"
gdb_test "disable 2.0-1" "Bad breakpoint location number '0'"
gdb_test "disable 2.1-0" "Bad breakpoint location number '0'"
}
# Test "disable BPLIST" with an invalid breakpoint/location BPLIST.
# PREFIX and SUFFIX are concatenated to form BPLIST. The invalid part
# is always in SUFFIX.
proc disable_invalid {prefix suffix} {
set bad_re [string_to_regexp $suffix]
if {$prefix == ""} {
gdb_test \
"disable $suffix" \
"Bad breakpoint number '${bad_re}'"
} else {
gdb_test \
"disable ${prefix}$suffix" \
"Bad breakpoint location number '${bad_re}'"
}
}
# Like disable_invalid, but expects an "inverted range" error.
proc disable_inverted {prefix suffix} {
set bad_re [string_to_regexp $suffix]
if {$prefix == ""} {
gdb_test \
"disable $suffix" \
"Inverted breakpoint range at '${bad_re}'"
} else {
gdb_test \
"disable ${prefix}$suffix" \
"Inverted breakpoint location range at '${bad_re}'"
}
}
# Like disable_invalid, but expects a "negative number" error.
proc disable_negative {prefix suffix} {
set bad_re [string_to_regexp $suffix]
if {$prefix == ""} {
gdb_test \
"disable $suffix" \
"Negative breakpoint number '${bad_re}'"
} else {
gdb_test \
"disable ${prefix}$suffix" \
"Negative breakpoint location number '${bad_re}'"
}
}
with_test_prefix "bad numbers" {
gdb_test "p \$zero = 0" " = 0"
gdb_test "p \$one = 1" " = 1"
gdb_test "p \$two = 2" " = 2"
gdb_test "p \$minus_one = -1" " = -1"
foreach prefix {"" "1." "$one."} {
set prefix_re [string_to_regexp $prefix]
disable_invalid $prefix "foo"
disable_invalid $prefix "1foo"
disable_invalid $prefix "foo1"
disable_inverted $prefix "2-1"
disable_inverted $prefix "2-\$one"
disable_inverted $prefix "\$two-1"
disable_inverted $prefix "\$two-\$one"
disable_negative $prefix "-1"
disable_negative $prefix "-\$one"
disable_negative $prefix "\$minus_one"
}
}
gdb_test "info break" [make_info_breakpoint_reply_re y y y y y y] \
"breakpoint info after invalids"