1 # Copyright (C) 1998-2016 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # written by Elena Zannoni (ezannoni@cygnus.com)
17 # modified by Michael Chastain (chastain@redhat.com)
19 # This file is part of the gdb testsuite
21 # tests for overloaded member functions. Set breakpoints on
22 # overloaded member functions
28 # test running programs
31 if { [skip_cplus_tests] } { continue }
35 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
39 # set it up at a breakpoint so we can play with the variable values
42 perror "couldn't run to breakpoint"
46 # When I ask gdb to set a breakpoint on an overloaded function,
47 # gdb gives me a choice menu. I might get stuck in that choice menu
48 # (for example, if C++ name mangling is not working properly).
50 # This procedure issues a command that works at either the menu
51 # prompt or the command prompt to get back to the command prompt.
53 # Note that an empty line won't do it (it means 'repeat the previous command'
54 # at top level). A line with a single space in it works nicely.
56 proc take_gdb_out_of_choice_menu {} {
58 gdb_test_multiple " " " " {
59 -re ".*$gdb_prompt $" {
66 # This procedure sets an overloaded breakpoint.
67 # When I ask for such a breakpoint, gdb gives me a menu of 'cancel' 'all'
68 # and a bunch of choices. I then choose from that menu by number.
70 proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} {
71 global gdb_prompt hex srcfile
73 # Get into the overload menu.
74 send_gdb "break $name\n"
77 pass "bp menu for $name choice $mychoice"
80 send_gdb "$mychoice\n"
82 -re "Breakpoint $bpnumber at $hex: file.*$srcfile, line $linenumber.\r\n$gdb_prompt $" {
83 pass "set bp $bpnumber on $name $mychoice line $linenumber"
85 -re ".*$gdb_prompt $" {
86 fail "set bp $bpnumber on $name $mychoice line $linenumber (bad bp)"
89 fail "set bp $bpnumber on $name $mychoice line $linenumber (timeout)"
90 take_gdb_out_of_choice_menu
95 fail "bp menu for $name choice $mychoice (bad menu)"
96 take_gdb_out_of_choice_menu
98 -re ".*$gdb_prompt $" {
99 fail "bp menu for $name choice $mychoice (no menu)"
102 fail "bp menu for $name choice $mychoice (timeout)"
103 take_gdb_out_of_choice_menu
108 # Compute the expected menu for overload1arg.
109 # Note the arg type variations for void and integer types.
110 # This accommodates different versions of g++.
112 # Probe for the real types. This will do some unnecessary checking
113 # for some simple types (like "int"), but it's just easier to loop
114 # over all_types instead of calling out just the exceptions.
115 # This list /must/ remain in the same order that the methods are
116 # called in the source code. Otherwise the order in which breakpoints
117 # are hit (tested below) will be incorrect.
118 set all_types [list void char signed_char unsigned_char short_int \
119 unsigned_short_int int unsigned_int long_int \
120 unsigned_long_int float double]
122 # ARGUMENTS is an array that will map from synthetic type to argument
123 # expressions in the source code, which is of the form "arg = $decimal".
124 # ARGUMENTS stores this decimal number.
125 array set arguments {
140 unset -nocomplain line types
141 foreach type $all_types {
142 # TYPES is an array that maps the synthetic names in ALL_TYPES
143 # to the real type used in the debugger. These will be checked
144 # below and changed if the debugger thinks they are different from
145 # their default values.
146 set types($type) [join [split $type "_"] " "]
148 # LINE is an array that will map from synthetic type to line number.
149 # in the source code.
150 set line($type) [gdb_get_line_number "fo1 $type"]
152 # Probe for the actual type.
153 gdb_test_multiple "print &foo::overload1arg($types($type))" \
154 "probe $types($type)" {
155 -re ".*\<foo::.*\>.*$gdb_prompt $" {
156 regexp {<.*>} $expect_out(0,string) func
157 regexp {\(.*\)} $func real_type
159 # Store the real type into TYPES.
160 set types($type) [string trim $real_type {()}]
162 # Create an inverse mapping of the actual type to
163 # the synthetic type.
164 set type_map("$types($type)") $type
170 # This is a list of the actual overloaded method arguments.
172 foreach type $all_types {
173 lappend overloads $types($type)
176 # Sort this list alphabetically.
177 set overloads [lsort $overloads]
179 # Create the menu list.
180 set items {"cancel" "all"}
181 foreach ovld $overloads {
182 lappend items "$srcfile:foo::overload1arg\\($ovld\\)"
186 foreach item $items {
187 lappend menu_items ".$idx. .*$item"
190 set menu_overload1arg [join $menu_items {[\r\n]*}]
191 append menu_overload1arg {[\r\n]*> $}
193 # Set multiple-symbols to "ask", to allow us to test the use
194 # of the multiple-choice menu when breaking on an overloaded method.
195 gdb_test_no_output "set multiple-symbols ask"
197 # Set breakpoints on foo::overload1arg, one by one.
199 set method "foo::overload1arg"
200 for {set idx 0} {$idx < [llength $overloads]} {incr idx} {
201 set type [lindex $overloads $idx]
202 set_bp_overloaded $method $menu_overload1arg \
203 [expr {$idx + 2}] [incr bpnum] $line($type_map("$type"))
206 # Verify the breakpoints.
207 set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*"
208 append bptable "\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\[\r\n\]+"
209 append bptable "\[\t \]+breakpoint already hit 1 time\[\r\n\]+"
210 foreach ovld $overloads {
211 append bptable [format "\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(%s\\) at.*$srcfile:%d\[\r\n\]+" $ovld \
212 $line($type_map("$ovld"))]
214 gdb_test "info break" $bptable "breakpoint info (after setting one-by-one)"
216 # Test choice "cancel".
217 # This is copy-and-paste from set_bp_overloaded.
219 send_gdb "break foo::overload1arg\n"
221 -re "$menu_overload1arg" {
222 pass "bp menu for foo::overload1arg choice cancel"
226 -re "canceled\r\n$gdb_prompt $" {
227 pass "set bp on overload1arg canceled"
229 -re "cancelled\r\n$gdb_prompt $" {
230 pass "set bp on overload1arg canceled"
232 -re ".*$gdb_prompt $" {
233 fail "set bp on overload1arg canceled (bad message)"
236 fail "set bp on overload1arg canceled (timeout)"
237 take_gdb_out_of_choice_menu
242 fail "bp menu for foo::overload1arg choice cancel (bad menu)"
243 take_gdb_out_of_choice_menu
245 -re ".*$gdb_prompt $" {
246 fail "bp menu for foo::overload1arg choice cancel (no menu)"
249 fail "bp menu for foo::overload1arg choice cancel (timeout)"
250 take_gdb_out_of_choice_menu
254 gdb_test "info break" $bptable "breakpoint info (after cancel)"
256 # Delete these breakpoints.
258 send_gdb "delete breakpoints\n"
260 -re "Delete all breakpoints.* $" {
263 -re ".*$gdb_prompt $" {
264 pass "delete all breakpoints"
267 fail "delete all breakpoints (timeout)"
272 fail "delete all breakpoints (timeout)"
276 gdb_test "info breakpoints" "No breakpoints or watchpoints." "breakpoint info (after delete)"
281 # This is copy-and-paste from set_bp_overloaded.
283 send_gdb "break foo::overload1arg\n"
285 -re "$menu_overload1arg" {
286 pass "bp menu for foo::overload1arg choice all"
290 -re "Breakpoint $decimal at $hex: foo::overload1arg. .12 locations.\r\n.*$gdb_prompt $" {
291 pass "set bp on overload1arg all"
293 -re ".*$gdb_prompt $" {
294 fail "set bp on overload1arg all (bad message)"
297 fail "set bp on overload1arg all (timeout)"
298 take_gdb_out_of_choice_menu
303 fail "bp menu for foo::overload1arg choice all (bad menu)"
304 take_gdb_out_of_choice_menu
306 -re ".*$gdb_prompt $" {
307 fail "bp menu for foo::overload1arg choice all (no menu)"
310 fail "bp menu for foo::overload1arg choice all (timeout)"
311 take_gdb_out_of_choice_menu
315 # Create the breakpoint table for "info breakpoint".
316 set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*\[\r\n]+"
317 append bptable "\[0-9\]+\[\t \]+breakpoint\[\t \]+keep\[\t \]y\[\t \]+<MULTIPLE>.*\[\r\n\]+"
318 foreach ovld {void char signed_char unsigned_char short_int \
319 unsigned_short_int int unsigned_int long_int \
320 unsigned_long_int float double} {
321 append bptable [format "\[0-9\]+.\[0-9\]+\[\t \]+y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(%s\\) at.*$srcfile:%d\[\r\n\]+" \
322 $types($ovld) $line($ovld)]
325 gdb_test "info break" $bptable "breakpoint info (after setting on all)"
327 # Run through each breakpoint.
328 proc continue_to_bp_overloaded {bpnumber might_fail line argtype argument} {
329 global gdb_prompt hex decimal srcfile
331 if {$argument == ""} {
334 set actuals "arg=$argument"
335 if {[regexp {char} $argtype]} {
336 append actuals " \\'\\\\00$argument\\'"
340 if {[string match $argtype "void"]} {
341 set body "return $decimal;"
343 set body "arg = 0; return $decimal;"
346 gdb_test_multiple "continue" "continue to bp overloaded : $argtype" {
347 -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}(, )?$actuals\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
348 pass "continue to bp overloaded : $argtype"
351 -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}, arg=.*\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
353 kfail "c++/8130" "continue to bp overloaded : $argtype"
355 fail "continue to bp overloaded : $argtype"
361 # An array which describes which of these methods might be expected
362 # to kfail on GCC 2.95. See C++/8210.
363 array set might_fail {
378 foreach type $all_types {
379 continue_to_bp_overloaded 14 $might_fail($type) $line($type) \
380 $type $arguments($type)
383 # Test breaking on an overloaded function when multiple-symbols
385 gdb_test_no_output "set multiple-symbols cancel"
386 gdb_test "break foo::foofunc" \
389 # Test breaking on an overloaded function when multiple-symbols
391 gdb_test_no_output "set multiple-symbols all"
392 gdb_test "break foo::foofunc" \
393 "Breakpoint \[0-9\]+ at ${hex}: foo::foofunc. .2 locations..*"
397 unset -nocomplain line types
398 gdb_continue_to_end "finish program"