1 # Copyright (C) 1998-1999, 2001, 2004, 2007-2012 Free Software
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # This file is part of the gdb testsuite
22 # tests for overloaded member functions. Set breakpoints on
23 # overloaded member functions
29 # test running programs
32 if { [skip_cplus_tests] } { continue }
34 set testfile "ovldbreak"
35 set srcfile $testfile.cc
36 set binfile $objdir/$subdir/$testfile
38 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
39 untested ovldbreak.exp
43 # set it up at a breakpoint so we can play with the variable values
46 perror "couldn't run to breakpoint"
50 # When I ask gdb to set a breakpoint on an overloaded function,
51 # gdb gives me a choice menu. I might get stuck in that choice menu
52 # (for example, if C++ name mangling is not working properly).
54 # This procedure issues a command that works at either the menu
55 # prompt or the command prompt to get back to the command prompt.
57 # Note that an empty line won't do it (it means 'repeat the previous command'
58 # at top level). A line with a single space in it works nicely.
60 proc take_gdb_out_of_choice_menu {} {
62 gdb_test_multiple " " " " {
63 -re ".*$gdb_prompt $" {
66 perror "could not resynchronize to command prompt (timeout)"
74 # This procedure sets an overloaded breakpoint.
75 # When I ask for such a breakpoint, gdb gives me a menu of 'cancel' 'all'
76 # and a bunch of choices. I then choose from that menu by number.
78 proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} {
79 global gdb_prompt hex srcfile
81 # Get into the overload menu.
82 send_gdb "break $name\n"
85 pass "bp menu for $name choice $mychoice"
88 send_gdb "$mychoice\n"
90 -re "Breakpoint $bpnumber at $hex: file.*$srcfile, line $linenumber.\r\n$gdb_prompt $" {
91 pass "set bp $bpnumber on $name $mychoice line $linenumber"
93 -re ".*$gdb_prompt $" {
94 fail "set bp $bpnumber on $name $mychoice line $linenumber (bad bp)"
97 fail "set bp $bpnumber on $name $mychoice line $linenumber (timeout)"
98 take_gdb_out_of_choice_menu
103 fail "bp menu for $name choice $mychoice (bad menu)"
104 take_gdb_out_of_choice_menu
106 -re ".*$gdb_prompt $" {
107 fail "bp menu for $name choice $mychoice (no menu)"
110 fail "bp menu for $name choice $mychoice (timeout)"
111 take_gdb_out_of_choice_menu
116 # Compute the expected menu for overload1arg.
117 # Note the arg type variations for void and integer types.
118 # This accommodates different versions of g++.
120 # Probe for the real types. This will do some unnecessary checking
121 # for some simple types (like "int"), but it's just easier to loop
122 # over all_types instead of calling out just the exceptions.
123 # This list /must/ remain in the same order that the methods are
124 # called in the source code. Otherwise the order in which breakpoints
125 # are hit (tested below) will be incorrect.
126 set all_types [list void char signed_char unsigned_char short_int \
127 unsigned_short_int int unsigned_int long_int \
128 unsigned_long_int float double]
130 # ARGUMENTS is an array that will map from synthetic type to argument
131 # expressions in the source code, which is of the form "arg = $decimal".
132 # ARGUMENTS stores this decimal number.
133 array set arguments {
148 unset -nocomplain line types
149 foreach type $all_types {
150 # TYPES is an array that maps the synthetic names in ALL_TYPES
151 # to the real type used in the debugger. These will be checked
152 # below and changed if the debugger thinks they are different from
153 # their default values.
154 set types($type) [join [split $type "_"] " "]
156 # LINE is an array that will map from synthetic type to line number.
157 # in the source code.
158 set line($type) [gdb_get_line_number "fo1 $type"]
160 # Probe for the actual type.
161 gdb_test_multiple "print &foo::overload1arg($types($type))" \
162 "probe $types($type)" {
163 -re ".*\<foo::.*\>.*$gdb_prompt $" {
164 regexp {<.*>} $expect_out(0,string) func
165 regexp {\(.*\)} $func real_type
167 # Store the real type into TYPES.
168 set types($type) [string trim $real_type {()}]
170 # Create an inverse mapping of the actual type to
171 # the synthetic type.
172 set type_map("$types($type)") $type
178 # This is a list of the actual overloaded method arguments.
180 foreach type $all_types {
181 lappend overloads $types($type)
184 # Sort this list alphabetically.
185 set overloads [lsort $overloads]
187 # Create the menu list.
188 set items {"cancel" "all"}
189 foreach ovld $overloads {
190 lappend items "$srcfile:foo::overload1arg\\($ovld\\)"
194 foreach item $items {
195 lappend menu_items ".$idx. .*$item"
198 set menu_overload1arg [join $menu_items {[\r\n]*}]
199 append menu_overload1arg {[\r\n]*> $}
201 # Set multiple-symbols to "ask", to allow us to test the use
202 # of the multiple-choice menu when breaking on an overloaded method.
203 gdb_test_no_output "set multiple-symbols ask"
205 # Set breakpoints on foo::overload1arg, one by one.
207 set method "foo::overload1arg"
208 for {set idx 0} {$idx < [llength $overloads]} {incr idx} {
209 set type [lindex $overloads $idx]
210 set_bp_overloaded $method $menu_overload1arg \
211 [expr {$idx + 2}] [incr bpnum] $line($type_map("$type"))
214 # Verify the breakpoints.
215 set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*"
216 append bptable "\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\[\r\n\]+"
217 append bptable "\[\t \]+breakpoint already hit 1 time\[\r\n\]+"
218 foreach ovld $overloads {
219 append bptable [format "\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(%s\\) at.*$srcfile:%d\[\r\n\]+" $ovld \
220 $line($type_map("$ovld"))]
222 gdb_test "info break" $bptable "breakpoint info (after setting one-by-one)"
224 # Test choice "cancel".
225 # This is copy-and-paste from set_bp_overloaded.
227 send_gdb "break foo::overload1arg\n"
229 -re "$menu_overload1arg" {
230 pass "bp menu for foo::overload1arg choice cancel"
234 -re "canceled\r\n$gdb_prompt $" {
235 pass "set bp on overload1arg canceled"
237 -re "cancelled\r\n$gdb_prompt $" {
238 pass "set bp on overload1arg canceled"
240 -re ".*$gdb_prompt $" {
241 fail "set bp on overload1arg canceled (bad message)"
244 fail "set bp on overload1arg canceled (timeout)"
245 take_gdb_out_of_choice_menu
250 fail "bp menu for foo::overload1arg choice cancel (bad menu)"
251 take_gdb_out_of_choice_menu
253 -re ".*$gdb_prompt $" {
254 fail "bp menu for foo::overload1arg choice cancel (no menu)"
257 fail "bp menu for foo::overload1arg choice cancel (timeout)"
258 take_gdb_out_of_choice_menu
262 gdb_test "info break" $bptable "breakpoint info (after cancel)"
264 # Delete these breakpoints.
266 send_gdb "delete breakpoints\n"
268 -re "Delete all breakpoints.* $" {
271 -re ".*$gdb_prompt $" {
272 pass "delete all breakpoints"
275 fail "delete all breakpoints (timeout)"
280 fail "delete all breakpoints (timeout)"
284 gdb_test "info breakpoints" "No breakpoints or watchpoints." "breakpoint info (after delete)"
289 # This is copy-and-paste from set_bp_overloaded.
291 send_gdb "break foo::overload1arg\n"
293 -re "$menu_overload1arg" {
294 pass "bp menu for foo::overload1arg choice all"
298 -re "Breakpoint $decimal at $hex: foo::overload1arg. .12 locations.\r\n.*$gdb_prompt $" {
299 pass "set bp on overload1arg all"
301 -re ".*$gdb_prompt $" {
302 fail "set bp on overload1arg all (bad message)"
305 fail "set bp on overload1arg all (timeout)"
306 take_gdb_out_of_choice_menu
311 fail "bp menu for foo::overload1arg choice all (bad menu)"
312 take_gdb_out_of_choice_menu
314 -re ".*$gdb_prompt $" {
315 fail "bp menu for foo::overload1arg choice all (no menu)"
318 fail "bp menu for foo::overload1arg choice all (timeout)"
319 take_gdb_out_of_choice_menu
323 # Create the breakpoint table for "info breakpoint".
324 set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*\[\r\n]+"
325 append bptable "\[0-9\]+\[\t \]+breakpoint\[\t \]+keep\[\t \]y\[\t \]+<MULTIPLE>.*\[\r\n\]+"
326 foreach ovld {void char signed_char unsigned_char short_int \
327 unsigned_short_int int unsigned_int long_int \
328 unsigned_long_int float double} {
329 append bptable [format "\[0-9\]+.\[0-9\]+\[\t \]+y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(%s\\) at.*$srcfile:%d\[\r\n\]+" \
330 $types($ovld) $line($ovld)]
333 gdb_test "info break" $bptable "breakpoint info (after setting on all)"
335 # Run through each breakpoint.
336 proc continue_to_bp_overloaded {bpnumber might_fail line argtype argument} {
337 global gdb_prompt hex decimal srcfile
339 if {$argument == ""} {
342 set actuals "arg=$argument"
343 if {[regexp {char} $argtype]} {
344 append actuals " \\'\\\\00$argument\\'"
348 if {[string match $argtype "void"]} {
349 set body "return $decimal;"
351 set body "arg = 0; return $decimal;"
354 gdb_test_multiple "continue" "continue to bp overloaded : $argtype" {
355 -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}(, )?$actuals\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
356 pass "continue to bp overloaded : $argtype"
359 -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}, arg=.*\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
361 kfail "c++/8130" "continue to bp overloaded : $argtype"
363 fail "continue to bp overloaded : $argtype"
369 # An array which describes which of these methods might be expected
370 # to kfail on GCC 2.95. See C++/8210.
371 array set might_fail {
386 foreach type $all_types {
387 continue_to_bp_overloaded 14 $might_fail($type) $line($type) \
388 $type $arguments($type)
391 # Test breaking on an overloaded function when multiple-symbols
393 gdb_test_no_output "set multiple-symbols cancel"
394 gdb_test "break foo::foofunc" \
397 # Test breaking on an overloaded function when multiple-symbols
399 gdb_test_no_output "set multiple-symbols all"
400 gdb_test "break foo::foofunc" \
401 "Breakpoint \[0-9\]+ at ${hex}: foo::foofunc. .2 locations..*"
405 unset -nocomplain line types
406 gdb_continue_to_end "finish program"