From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 22/23] Test "set multiple-symbols on" creating multiple breakpoints
Date: Mon, 16 May 2022 19:40:29 +0100 [thread overview]
Message-ID: <20220516184030.665489-23-pedro@palves.net> (raw)
In-Reply-To: <20220516184030.665489-1-pedro@palves.net>
To look for code paths that lead to create_breakpoints_sal creating
multiple breakpoints, I ran the whole testsuite with this hack:
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8377,8 +8377,7 @@ create_breakpoints_sal (struct gdbarch *gdbarch,
int from_tty,
int enabled, int internal, unsigned flags)
{
- if (canonical->pre_expanded)
- gdb_assert (canonical->lsals.size () == 1);
+ gdb_assert (canonical->lsals.size () == 1);
surprisingly, the assert never failed...
The way to get to create_breakpoints_sal with multiple lsals is to use
"set multiple-symbols ask" and then select multiple options from the
menu, like so:
(gdb) set multiple-symbols ask
(gdb) b overload1arg
[0] cancel
[1] all
[2] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg()
[3] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(char)
[4] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(double)
[5] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(float)
[6] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(int)
[7] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(long)
[8] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(short)
[9] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(signed char)
[10] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned char)
[11] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned int)
[12] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned long)
[13] /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc:foo::overload1arg(unsigned short)
> 2-3
Breakpoint 2 at 0x1532: file /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc, line 107.
Breakpoint 3 at 0x154b: file /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.cp/ovldbreak.cc, line 110.
warning: Multiple breakpoints were set.
Use the "delete" command to delete unwanted breakpoints.
... which would trigger the assert.
This commit makes gdb.cp/ovldbreak.exp test this scenario. It does
that by making set_bp_overloaded take a list of expected created
breakpoints rather than just one breakpoint. It converts the
procedure to use gdb_test_multiple instead of send_gdb/gdb_expect
along the way.
Change-Id: Id87d1e08feb6670440d926f5344e5081f5e37c8e
---
gdb/testsuite/gdb.cp/ovldbreak.exp | 100 +++++++++++++++++++++--------
1 file changed, 75 insertions(+), 25 deletions(-)
diff --git a/gdb/testsuite/gdb.cp/ovldbreak.exp b/gdb/testsuite/gdb.cp/ovldbreak.exp
index 681edf204d3..06adf82ecbb 100644
--- a/gdb/testsuite/gdb.cp/ovldbreak.exp
+++ b/gdb/testsuite/gdb.cp/ovldbreak.exp
@@ -67,43 +67,75 @@ proc take_gdb_out_of_choice_menu {} {
-# This procedure sets an overloaded breakpoint.
-# When I ask for such a breakpoint, gdb gives me a menu of 'cancel' 'all'
-# and a bunch of choices. I then choose from that menu by number.
+# This procedure sets an overloaded breakpoint. When users ask for
+# such a breakpoint, gdb gives a menu of 'cancel' 'all' and one choice
+# per overload. Users can then choose from that menu by number.
+#
+# NAME is the spec to use to create the breakpoint. EXPECTEDMENU is
+# the expected menu. MYCHOICE is the choice selected. Can be more
+# than one overload, e.g. "2-3". BPNUMBER is the expected next
+# breakpoint created. LINENUMBERS is a list of line numbers, one
+# element per expected breakpoint created.
-proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} {
- global gdb_prompt hex srcfile
+proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumbers} {
+ global gdb_prompt hex decimal srcfile
# Get into the overload menu.
- send_gdb "break $name\n"
- gdb_expect {
- -re "$expectedmenu" {
- pass "bp menu for $name choice $mychoice"
-
- # Choose my choice.
- send_gdb "$mychoice\n"
- gdb_expect {
- -re "Breakpoint $bpnumber at $hex: file.*$srcfile, line $linenumber.\r\n$gdb_prompt $" {
- pass "set bp $bpnumber on $name $mychoice line $linenumber"
- }
- -re ".*$gdb_prompt $" {
- fail "set bp $bpnumber on $name $mychoice line $linenumber (bad bp)"
+ gdb_test_multiple "break $name" "bp menu for $name choice $mychoice" {
+ -re "$expectedmenu" {
+ pass $gdb_test_name
+
+ set any "\[^\r\n\]*"
+
+ # True if we've seen a bad breakpoint.
+ set bad_bp 0
+
+ # How many breakpoints we expect to see.
+ set expected_bps [llength $linenumbers]
+
+ # The count of seen breakpoints.
+ set seen_bps 0
+
+ # Choose my choice.
+ gdb_test_multiple "$mychoice" "set bp $bpnumber on $name $mychoice line $linenumbers" {
+ -re "Breakpoint ($decimal) at $hex: file$any$srcfile, line ($decimal).\r\n" {
+
+ set got_num $expect_out(1,string)
+ set got_line $expect_out(2,string)
+
+ if {$seen_bps >= $expected_bps} {
+ set bad_bp 1
+ } else {
+ set linenumber [lindex $linenumbers $seen_bps]
+
+ if {$got_num != $bpnumber || $got_line != $linenumber} {
+ set bad_bp 1
+ }
+
+ incr bpnumber
+ incr seen_bps
+ }
+ exp_continue
+ }
+ -re "$gdb_prompt $" {
+ gdb_assert {!$bad_bp && $seen_bps == $expected_bps} \
+ $gdb_test_name
}
timeout {
- fail "set bp $bpnumber on $name $mychoice line $linenumber (timeout)"
+ fail "$gdb_test_name (timeout)"
take_gdb_out_of_choice_menu
}
}
}
-re ".*\r\n> " {
- fail "bp menu for $name choice $mychoice (bad menu)"
+ fail "$gdb_test_name (bad menu)"
take_gdb_out_of_choice_menu
}
-re ".*$gdb_prompt $" {
- fail "bp menu for $name choice $mychoice (no menu)"
+ fail "$gdb_test_name (no menu)"
}
timeout {
- fail "bp menu for $name choice $mychoice (timeout)"
+ fail "$gdb_test_name (timeout)"
take_gdb_out_of_choice_menu
}
}
@@ -198,8 +230,10 @@ append menu_overload1arg {[\r\n]*> $}
# of the multiple-choice menu when breaking on an overloaded method.
gdb_test_no_output "set multiple-symbols ask"
-# Set breakpoints on foo::overload1arg, one by one.
+# The last breakpoint created.
set bpnum 1
+
+# Set breakpoints on foo::overload1arg, one by one.
set method "foo::overload1arg"
for {set idx 0} {$idx < [llength $overloads]} {incr idx} {
set type [lindex $overloads $idx]
@@ -257,6 +291,21 @@ gdb_expect {
gdb_test "info break" $bptable "breakpoint info (after cancel)"
+# Test that if the user selects multiple entries from the option list,
+# GDB creates one breakpoint per entry.
+with_test_prefix "multiple breakpoints" {
+ set method "foo::overload1arg"
+
+ set expected_lines {}
+ for {set i 0} {$i < 2} {incr i} {
+ set type [lindex $overloads $i]
+ lappend expected_lines $line($type_map("$type"))
+ }
+ set_bp_overloaded $method $menu_overload1arg \
+ "2-3" [incr bpnum] $expected_lines
+ incr bpnum
+}
+
# Delete these breakpoints.
send_gdb "delete breakpoints\n"
@@ -284,6 +333,7 @@ gdb_test "info breakpoints" "No breakpoints or watchpoints." "breakpoint info (a
# Test choice "all".
# This is copy-and-paste from set_bp_overloaded.
+incr bpnum
send_gdb "break foo::overload1arg\n"
gdb_expect {
-re "$menu_overload1arg" {
@@ -291,7 +341,7 @@ gdb_expect {
# Choose all.
send_gdb "1\n"
gdb_expect {
- -re "Breakpoint $decimal at $hex: foo::overload1arg. .12 locations.\r\n.*$gdb_prompt $" {
+ -re "Breakpoint $bpnum at $hex: foo::overload1arg. .12 locations.\r\n.*$gdb_prompt $" {
pass "set bp on overload1arg all"
}
-re ".*$gdb_prompt $" {
@@ -380,7 +430,7 @@ array set might_fail {
}
foreach type $all_types {
- continue_to_bp_overloaded 14 $might_fail($type) $line($type) \
+ continue_to_bp_overloaded $bpnum $might_fail($type) $line($type) \
$type $arguments($type)
}
--
2.36.0
next prev parent reply other threads:[~2022-05-16 18:41 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-16 18:40 [PATCH 00/23] More breakpoints cleanups Pedro Alves
2022-05-16 18:40 ` [PATCH 01/23] add_location_to_breakpoint -> breakpoint::add_location Pedro Alves
2022-05-16 18:40 ` [PATCH 02/23] Make structs breakpoint/base_breakpoint/catchpoint be abstract Pedro Alves
2022-05-16 18:40 ` [PATCH 03/23] ranged_breakpoint: don't use init_raw_breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 04/23] ranged_breakpoint, use install_breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 05/23] ranged_breakpoint - move initialization to ctor Pedro Alves
2022-05-16 18:40 ` [PATCH 06/23] Make a few functions work with base_breakpoint instead of breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 07/23] More breakpoint_ops parameter elimination Pedro Alves
2022-05-16 18:40 ` [PATCH 08/23] Remove "internal" parameter from a couple functions Pedro Alves
2022-05-16 18:40 ` [PATCH 09/23] init_breakpoint_sal -> base_breakpoint::base_breakpoint Pedro Alves
2022-05-20 13:40 ` Lancelot SIX
2022-05-20 19:20 ` Pedro Alves
2022-05-16 18:40 ` [PATCH 10/23] Make ada_catchpoint_location's owner ctor parameter be ada_catchpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 11/23] Convert init_ada_exception_catchpoint to a ctor Pedro Alves
2022-05-16 18:40 ` [PATCH 12/23] Refactor set_internal_breakpoint / internal_breakpoint ctor Pedro Alves
2022-05-16 18:40 ` [PATCH 13/23] Refactor momentary breakpoints, eliminate set_raw_breakpoint{, _without_location} Pedro Alves
2022-05-16 18:40 ` [PATCH 14/23] Make exception_catchpoint inherit base_breakpoint instead of catchpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 15/23] Make breakpoint_address_bits look at the location kind Pedro Alves
2022-05-16 18:40 ` [PATCH 16/23] Make catchpoint inherit breakpoint, eliminate init_raw_breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 17/23] Move common bits of catchpoint/exception_catchpoint to breakpoint's ctor Pedro Alves
2022-05-16 18:40 ` [PATCH 18/23] Move add_location(sal) to base_breakpoint Pedro Alves
2022-05-16 18:40 ` [PATCH 19/23] Add/tweak intro comments of struct breakpoint and several subclasses Pedro Alves
2022-05-16 18:40 ` [PATCH 20/23] Momentary breakpoints should have no breakpoint number Pedro Alves
2022-05-20 16:00 ` Tom Tromey
2022-05-20 19:25 ` Pedro Alves
2022-05-16 18:40 ` [PATCH 21/23] Make sure momentary breakpoints are always thread-specific Pedro Alves
2022-05-16 18:40 ` Pedro Alves [this message]
2022-05-16 18:40 ` [PATCH 23/23] Rename base_breakpoint -> code_breakpoint Pedro Alves
2022-05-20 16:05 ` Tom Tromey
2022-05-20 16:06 ` [PATCH 00/23] More breakpoints cleanups Tom Tromey
2022-05-20 19:43 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220516184030.665489-23-pedro@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).