diff options
author | Pedro Alves <pedro@palves.net> | 2020-09-13 18:02:19 +0100 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2020-09-13 18:02:19 +0100 |
commit | 6791b1172abea5867268c95a460aba1c66c2b6b0 (patch) | |
tree | d8d1f1043094a1dfa82f3cd0d7dcd03e13dac5e4 /gdb/testsuite | |
parent | 3b8d4c5cc045ba80cc5b095fba06287050b7ef87 (diff) | |
download | gdb-6791b1172abea5867268c95a460aba1c66c2b6b0.zip gdb-6791b1172abea5867268c95a460aba1c66c2b6b0.tar.gz gdb-6791b1172abea5867268c95a460aba1c66c2b6b0.tar.bz2 |
Add MI "-break-insert --qualified"
Currently -break-insert always creates a wildmatching breakpoint, and
there's no way to ask for a fullname match. To address that, this
patch adds the equivalent of "break -qualified" to MI:
"-break-insert --qualified".
For the testcase, curiously, it doesn't look like we have _any_
testcase that tests a breakpoint with multiple locations, and, the
existing mi_create_breakpoint / mi_make_breakpoint procedures are only
good for breakpoints with a single location. This patch thus adds a
few new companion routines to mi-support.exp for breakpoints with
multiple locations: mi_create_breakpoint_multi,
mi_make_breakpoint_loc, mi_make_breakpoint_multi.
gdb/ChangeLog:
* NEWS: Document "-break-insert --qualified".
* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Handle "--qualified".
gdb/doc/ChangeLog:
* gdb.texinfo (GDB/MI Breakpoint Commands): Document
"-break-insert --qualified" and "-dprintf-insert --qualified".
gdb/testsuite/ChangeLog:
* gdb.mi/mi-break-qualified.cc: New file.
* gdb.mi/mi-break-qualified.exp: New file.
* lib/mi-support.exp (mi_create_breakpoint_multi)
(mi_make_breakpoint_loc, mi_make_breakpoint_multi): New
procedures.
(mi_create_breakpoint_1): New, factored out from
mi_create_breakpoint.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 10 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-break-qualified.cc | 53 | ||||
-rw-r--r-- | gdb/testsuite/gdb.mi/mi-break-qualified.exp | 106 | ||||
-rw-r--r-- | gdb/testsuite/lib/mi-support.exp | 135 |
4 files changed, 283 insertions, 21 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index c339151..24a58ad 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,15 @@ 2020-09-13 Pedro Alves <pedro@palves.net> + * gdb.mi/mi-break-qualified.cc: New file. + * gdb.mi/mi-break-qualified.exp: New file. + * lib/mi-support.exp (mi_create_breakpoint_multi) + (mi_make_breakpoint_loc, mi_make_breakpoint_multi): New + procedures. + (mi_create_breakpoint_1): New, factored out from + mi_create_breakpoint. + +2020-09-13 Pedro Alves <pedro@palves.net> + * gdb.cp/inherit.exp: No longer pass -Wno-deprecated-register. * gdb.cp/misc.exp: No longer pass -Wno-deprecated-register. * gdb.cp/misc.cc (class small, small::method, marker_reg1) diff --git a/gdb/testsuite/gdb.mi/mi-break-qualified.cc b/gdb/testsuite/gdb.mi/mi-break-qualified.cc new file mode 100644 index 0000000..d4e2703 --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-break-qualified.cc @@ -0,0 +1,53 @@ +/* Copyright 2020 Free Software Foundation, Inc. + + This file is part of GDB. + + 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/>. */ + +namespace NS { + +int +func (int i) +{ + return i; /* location NS::func here */ +} + +} /* namespace NS */ + +struct foo +{ + long func (long l); +}; + +long +foo::func (long l) +{ + return l; /* location foo::func here */ +} + +char +func (char c) +{ + return c; /* location func here */ +} + +int +main () +{ + foo f; + f.func (1); + NS::func (2); + func (3); + return 0; +} diff --git a/gdb/testsuite/gdb.mi/mi-break-qualified.exp b/gdb/testsuite/gdb.mi/mi-break-qualified.exp new file mode 100644 index 0000000..adbc3b5 --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-break-qualified.exp @@ -0,0 +1,106 @@ +# Copyright 2020 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/>. + +# Test '-break-insert --qualified' and C++ wildmatching. +# +# The goal is not to test GDB functionality, which is done by other +# tests, but to verify the correct output response to MI operations. + +load_lib mi-support.exp +set MIFLAGS "-i=mi" + +standard_testfile .cc + +if {[build_executable $testfile.exp $testfile $srcfile {c++ debug}] == -1} { + untested "failed to compile" + return -1 +} + +set loc_ns_func_line [gdb_get_line_number "location NS::func here"] +set loc_foo_func_line [gdb_get_line_number "location foo::func here"] +set loc_func_line [gdb_get_line_number "location func here"] + +proc test_break_qualified {} { + global hex + global loc_ns_func_line loc_foo_func_line loc_func_line + + # We have three functions called "func" in the program. Check + # that --qualified only picks the one explicitly specified. + + set bps {} + set test "--qualified func" + lappend bps [mi_create_breakpoint $test $test \ + -func "func\\(char\\)" \ + -file ".*mi-break-qualified.cc" \ + -line $loc_func_line] + + set test "--qualified NS::func" + lappend bps [mi_create_breakpoint $test $test \ + -func "NS::func\\(int\\)" \ + -file ".*mi-break-qualified.cc" \ + -line $loc_ns_func_line] + + set test "--qualified foo::func" + lappend bps [mi_create_breakpoint $test $test \ + -func "foo::func\\(long\\)" \ + -file ".*mi-break-qualified.cc" \ + -line $loc_foo_func_line] + + # Also check that without --qualified, we get a breakpoint with a + # location for each of the functions called "func" in the program. + + # Small helper wrapper around mi_make_breakpoint_loc. + proc make_loc_re {func line_no} { + global hex + + return [mi_make_breakpoint_loc \ + -enabled "y" \ + -func "$func" \ + -file ".*mi-break-qualified.cc" \ + -line="$line_no"] + } + + set loc1 [make_loc_re "NS::func\\(int\\)" $loc_ns_func_line] + set loc2 [make_loc_re "foo::func\\(long\\)" $loc_foo_func_line] + set loc3 [make_loc_re "func\\(char\\)" $loc_func_line] + + set test "func" + set bp [mi_create_breakpoint_multi $test $test \ + -original-location "func" \ + -locations "\\\[$loc1,$loc2,$loc3\\\]"] + + lappend bps $bp + + # List the breakpoints. + mi_gdb_test "666-break-list" \ + "666\\\^done,[mi_make_breakpoint_table $bps]" \ + "list of breakpoints" + + mi_gdb_test "777-break-delete" \ + "777\\^done" \ + "delete temp breakpoints" +} + +mi_gdb_exit + +if [mi_gdb_start ""] { + return +} + +mi_delete_breakpoints +mi_gdb_reinitialize_dir $srcdir/$subdir +mi_gdb_load ${binfile} + +test_break_qualified diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index 1e59919..7c1dcd6 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -1376,6 +1376,15 @@ proc mi_create_breakpoint {location test args} { return $bp } +# Like mi_create_breakpoint, but creates a breakpoint with multiple +# locations using mi_make_breakpoint_multi instead. + +proc mi_create_breakpoint_multi {location test args} { + set bp [eval mi_make_breakpoint_multi $args] + mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test + return $bp +} + # Creates varobj named NAME for EXPRESSION. # Name cannot be "-". proc mi_create_varobj { name expression testname } { @@ -2477,36 +2486,39 @@ proc mi_build_kv_pairs {attr_list {joiner ,}} { return "[join $l $joiner]" } -# Construct a breakpoint regexp. This may be used to test the output of -# -break-insert, -dprintf-insert, or -break-info. +# Construct a breakpoint location regexp. This may be used along with +# mi_make_breakpoint_multi to test the output of -break-insert, +# -dprintf-insert, or -break-info with breapoints with multiple +# locations. # -# All arguments for the breakpoint may be specified using the options -# number, type, disp, enabled, addr, func, file, fullanme, line, -# thread-groups, cond, evaluated-by, times, ignore, script, -# and original-location. +# All arguments for the breakpoint location may be specified using the +# options number, enabled, addr, func, file, fullname, line and +# thread-groups. # -# Only if -script and -ignore are given will they appear in the output. -# Otherwise, this procedure will skip them using ".*". -# -# Example: mi_make_breakpoint -number 2 -file ".*/myfile.c" -line 3 -# will return the breakpoint: -# bkpt={number="2",type=".*",disp=".*",enabled=".*",addr=".*",func=".*", -# file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\], -# times="0".*original-location=".*"} +# Example: mi_make_breakpoint_loc -number 2.1 -file ".*/myfile.c" -line 3 +# will return the breakpoint location: +# {number="2.1",enabled=".*",addr=".*",func=".*", +# file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\]} -proc mi_make_breakpoint {args} { - parse_args {{number .*} {type .*} {disp .*} {enabled .*} {addr .*} +proc mi_make_breakpoint_loc {args} { + parse_args {{number .*} {enabled .*} {addr .*} {func .*} {file .*} {fullname .*} {line .*} - {thread-groups \\\[.*\\\]} {times .*} {ignore 0} - {script ""} {original-location .*} {cond ""} {evaluated-by ""}} + {thread-groups \\\[.*\\\]}} set attr_list {} - foreach attr [list number type disp enabled addr func file \ + foreach attr [list number enabled addr func file \ fullname line thread-groups] { lappend attr_list $attr [set $attr] } - set result "bkpt={[mi_build_kv_pairs $attr_list]" + return "{[mi_build_kv_pairs $attr_list]}" +} + +# Bits shared between mi_make_breakpoint and mi_make_breakpoint_multi. + +proc mi_make_breakpoint_1 {attr_list cond evaluated-by times \ + ignore script original-location} { + set result "bkpt=\\\{[mi_build_kv_pairs $attr_list]" # There are always exceptions. @@ -2546,7 +2558,88 @@ proc mi_make_breakpoint {args} { } append result [mi_build_kv_pairs \ [list "original-location" ${original-location}]] - append result "}" + + return $result +} + + +# Construct a breakpoint regexp, for a breakpoint with multiple +# locations. This may be used to test the output of -break-insert, +# -dprintf-insert, or -break-info with breakpoints with multiple +# locations. +# +# All arguments for the breakpoint may be specified using the options +# number, type, disp, enabled, func, cond, evaluated-by, times, +# ignore, script and locations. +# +# Only if -script and -ignore are given will they appear in the output. +# Otherwise, this procedure will skip them using ".*". +# +# Example: mi_make_breakpoint_multi -number 2 -locations "$loc" +# will return the breakpoint: +# bkpt={number="2",type=".*",disp=".*",enabled=".*",addr="<MULTIPLE>", +# times="0".*original-location=".*",locations=$loc} +# +# You can construct the list of locations with mi_make_breakpoint_loc. + +proc mi_make_breakpoint_multi {args} { + parse_args {{number .*} {type .*} {disp .*} {enabled .*} + {times .*} {ignore 0} + {script ""} {original-location .*} {cond ""} {evaluated-by ""} + {locations .*}} + + set attr_list {} + foreach attr [list number type disp enabled] { + lappend attr_list $attr [set $attr] + } + + lappend attr_list "addr" "<MULTIPLE>" + + set result [mi_make_breakpoint_1 \ + $attr_list $cond ${evaluated-by} $times \ + $ignore $script ${original-location}] + + append result "," + append result [mi_build_kv_pairs [list "locations" $locations]] + + append result "\\\}" + return $result +} + +# Construct a breakpoint regexp. This may be used to test the output of +# -break-insert, -dprintf-insert, or -break-info. +# +# All arguments for the breakpoint may be specified using the options +# number, type, disp, enabled, addr, func, file, fullanme, line, +# thread-groups, cond, evaluated-by, times, ignore, script, +# and original-location. +# +# Only if -script and -ignore are given will they appear in the output. +# Otherwise, this procedure will skip them using ".*". +# +# Example: mi_make_breakpoint -number 2 -file ".*/myfile.c" -line 3 +# will return the breakpoint: +# bkpt={number="2",type=".*",disp=".*",enabled=".*",addr=".*",func=".*", +# file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\], +# times="0".*original-location=".*"} + +proc mi_make_breakpoint {args} { + parse_args {{number .*} {type .*} {disp .*} {enabled .*} {addr .*} + {func .*} {file .*} {fullname .*} {line .*} + {thread-groups \\\[.*\\\]} {times .*} {ignore 0} + {script ""} {original-location .*} {cond ""} {evaluated-by ""}} + + set attr_list {} + foreach attr [list number type disp enabled addr func file \ + fullname line thread-groups] { + lappend attr_list $attr [set $attr] + } + + set result [mi_make_breakpoint_1 \ + $attr_list $cond ${evaluated-by} $times \ + $ignore $script ${original-location}] + + append result "\\\}" return $result } |