-# 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
}
}
# 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]
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"
# 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" {
# 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 $" {
}
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)
}