PR gold/14309
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / ovldbreak.exp
CommitLineData
0b302171
JB
1# Copyright (C) 1998-1999, 2001, 2004, 2007-2012 Free Software
2# Foundation, Inc.
c906108c
SS
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c 17# written by Elena Zannoni (ezannoni@cygnus.com)
b2bbed47 18# modified by Michael Chastain (chastain@redhat.com)
c906108c
SS
19
20# This file is part of the gdb testsuite
21#
22# tests for overloaded member functions. Set breakpoints on
23# overloaded member functions
24#
25
cec808ec
KS
26global timeout
27set timeout 15
c906108c
SS
28#
29# test running programs
30#
c906108c 31
d4f3574e
SS
32if { [skip_cplus_tests] } { continue }
33
c906108c 34set testfile "ovldbreak"
d3dc44a6
KS
35set srcfile $testfile.cc
36set binfile $objdir/$subdir/$testfile
c906108c 37
d3dc44a6
KS
38if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
39 untested ovldbreak.exp
40 return -1
c906108c
SS
41}
42
c906108c
SS
43# set it up at a breakpoint so we can play with the variable values
44#
d3dc44a6 45if {![runto_main]} {
c906108c
SS
46 perror "couldn't run to breakpoint"
47 continue
48}
49
b2bbed47
MC
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).
53#
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.
56#
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.
c906108c 59
b2bbed47
MC
60proc take_gdb_out_of_choice_menu {} {
61 global gdb_prompt
f8d3bf8f 62 gdb_test_multiple " " " " {
b2bbed47
MC
63 -re ".*$gdb_prompt $" {
64 }
65 timeout {
66 perror "could not resynchronize to command prompt (timeout)"
67 continue
68 }
69 }
70}
c906108c
SS
71
72
c906108c 73
b2bbed47
MC
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.
c906108c 77
b2bbed47
MC
78proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} {
79 global gdb_prompt hex srcfile
c906108c 80
b2bbed47
MC
81 # Get into the overload menu.
82 send_gdb "break $name\n"
83 gdb_expect {
84 -re "$expectedmenu" {
85 pass "bp menu for $name choice $mychoice"
c906108c 86
b2bbed47
MC
87 # Choose my choice.
88 send_gdb "$mychoice\n"
c906108c 89 gdb_expect {
b2bbed47
MC
90 -re "Breakpoint $bpnumber at $hex: file.*$srcfile, line $linenumber.\r\n$gdb_prompt $" {
91 pass "set bp $bpnumber on $name $mychoice line $linenumber"
92 }
93 -re ".*$gdb_prompt $" {
94 fail "set bp $bpnumber on $name $mychoice line $linenumber (bad bp)"
95 }
96 timeout {
97 fail "set bp $bpnumber on $name $mychoice line $linenumber (timeout)"
98 take_gdb_out_of_choice_menu
99 }
100 }
101 }
102 -re ".*\r\n> " {
103 fail "bp menu for $name choice $mychoice (bad menu)"
104 take_gdb_out_of_choice_menu
105 }
106 -re ".*$gdb_prompt $" {
107 fail "bp menu for $name choice $mychoice (no menu)"
108 }
109 timeout {
110 fail "bp menu for $name choice $mychoice (timeout)"
111 take_gdb_out_of_choice_menu
112 }
113 }
114}
c906108c 115
d3dc44a6 116# Compute the expected menu for overload1arg.
cec808ec 117# Note the arg type variations for void and integer types.
b2bbed47 118# This accommodates different versions of g++.
c906108c 119
d3dc44a6
KS
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.
126set 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]
129
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.
133array set arguments {
134 void ""
135 char 2
136 signed_char 3
137 unsigned_char 4
138 short_int 5
139 unsigned_short_int 6
140 int 7
141 unsigned_int 8
142 long_int 9
143 unsigned_long_int 10
144 float 100(.0)?
145 double 200(.0)?
146}
147
148unset -nocomplain line types
149foreach 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 "_"] " "]
155
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"]
159
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
166
167 # Store the real type into TYPES.
168 set types($type) [string trim $real_type {()}]
169
170 # Create an inverse mapping of the actual type to
171 # the synthetic type.
172 set type_map("$types($type)") $type
173 pass "detect $type"
174 }
175 }
176}
177
178# This is a list of the actual overloaded method arguments.
179set overloads {}
180foreach type $all_types {
181 lappend overloads $types($type)
182}
183
184# Sort this list alphabetically.
185set overloads [lsort $overloads]
186
187# Create the menu list.
188set items {"cancel" "all"}
189foreach ovld $overloads {
190 lappend items "$srcfile:foo::overload1arg\\($ovld\\)"
191}
192set menu_items {}
193set idx 0
194foreach item $items {
195 lappend menu_items ".$idx. .*$item"
196 incr idx
197}
198set menu_overload1arg [join $menu_items {[\r\n]*}]
199append menu_overload1arg {[\r\n]*> $}
c906108c 200
eae06beb
JB
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.
a8d52276 203gdb_test_no_output "set multiple-symbols ask"
c906108c 204
b2bbed47 205# Set breakpoints on foo::overload1arg, one by one.
d3dc44a6
KS
206set bpnum 1
207set method "foo::overload1arg"
208for {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"))
212}
c906108c 213
b2bbed47 214# Verify the breakpoints.
d3dc44a6
KS
215set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*"
216append bptable "\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\[\r\n\]+"
217append bptable "\[\t \]+breakpoint already hit 1 time\[\r\n\]+"
218foreach 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"))]
221}
222gdb_test "info break" $bptable "breakpoint info (after setting one-by-one)"
c906108c 223
b2bbed47
MC
224# Test choice "cancel".
225# This is copy-and-paste from set_bp_overloaded.
c906108c
SS
226
227send_gdb "break foo::overload1arg\n"
228gdb_expect {
b2bbed47
MC
229 -re "$menu_overload1arg" {
230 pass "bp menu for foo::overload1arg choice cancel"
231 # Choose cancel.
232 send_gdb "0\n"
233 gdb_expect {
234 -re "canceled\r\n$gdb_prompt $" {
235 pass "set bp on overload1arg canceled"
236 }
237 -re "cancelled\r\n$gdb_prompt $" {
238 pass "set bp on overload1arg canceled"
239 }
240 -re ".*$gdb_prompt $" {
241 fail "set bp on overload1arg canceled (bad message)"
242 }
243 timeout {
244 fail "set bp on overload1arg canceled (timeout)"
245 take_gdb_out_of_choice_menu
246 }
247 }
248 }
249 -re ".*\r\n> " {
250 fail "bp menu for foo::overload1arg choice cancel (bad menu)"
251 take_gdb_out_of_choice_menu
252 }
253 -re ".*$gdb_prompt $" {
254 fail "bp menu for foo::overload1arg choice cancel (no menu)"
255 }
256 timeout {
257 fail "bp menu for foo::overload1arg choice cancel (timeout)"
258 take_gdb_out_of_choice_menu
259 }
260}
c906108c 261
d3dc44a6 262gdb_test "info break" $bptable "breakpoint info (after cancel)"
c906108c 263
b2bbed47 264# Delete these breakpoints.
c906108c
SS
265
266send_gdb "delete breakpoints\n"
267gdb_expect {
b2bbed47 268 -re "Delete all breakpoints.* $" {
c906108c
SS
269 send_gdb "y\n"
270 gdb_expect {
271 -re ".*$gdb_prompt $" {
b2bbed47
MC
272 pass "delete all breakpoints"
273 }
274 timeout {
275 fail "delete all breakpoints (timeout)"
c906108c 276 }
c906108c
SS
277 }
278 }
b2bbed47
MC
279 timeout {
280 fail "delete all breakpoints (timeout)"
281 }
c906108c
SS
282}
283
b2bbed47 284gdb_test "info breakpoints" "No breakpoints or watchpoints." "breakpoint info (after delete)"
c906108c
SS
285
286
c906108c 287
b2bbed47
MC
288# Test choice "all".
289# This is copy-and-paste from set_bp_overloaded.
c906108c 290
b2bbed47
MC
291send_gdb "break foo::overload1arg\n"
292gdb_expect {
293 -re "$menu_overload1arg" {
294 pass "bp menu for foo::overload1arg choice all"
295 # Choose all.
296 send_gdb "1\n"
297 gdb_expect {
f8eba3c6 298 -re "Breakpoint $decimal at $hex: foo::overload1arg. .12 locations.\r\n.*$gdb_prompt $" {
b2bbed47
MC
299 pass "set bp on overload1arg all"
300 }
301 -re ".*$gdb_prompt $" {
302 fail "set bp on overload1arg all (bad message)"
303 }
304 timeout {
305 fail "set bp on overload1arg all (timeout)"
306 take_gdb_out_of_choice_menu
307 }
308 }
309 }
310 -re ".*\r\n> " {
311 fail "bp menu for foo::overload1arg choice all (bad menu)"
312 take_gdb_out_of_choice_menu
313 }
314 -re ".*$gdb_prompt $" {
315 fail "bp menu for foo::overload1arg choice all (no menu)"
316 }
317 timeout {
318 fail "bp menu for foo::overload1arg choice all (timeout)"
319 take_gdb_out_of_choice_menu
320 }
321}
c906108c 322
40e084e1
KS
323# Create the breakpoint table for "info breakpoint".
324set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*\[\r\n]+"
325append bptable "\[0-9\]+\[\t \]+breakpoint\[\t \]+keep\[\t \]y\[\t \]+<MULTIPLE>.*\[\r\n\]+"
326foreach 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)]
331}
b2bbed47 332
40e084e1 333gdb_test "info break" $bptable "breakpoint info (after setting on all)"
c906108c 334
b2bbed47 335# Run through each breakpoint.
d3dc44a6
KS
336proc continue_to_bp_overloaded {bpnumber might_fail line argtype argument} {
337 global gdb_prompt hex decimal srcfile
338
339 if {$argument == ""} {
340 set actuals ""
341 } else {
342 set actuals "arg=$argument"
343 if {[regexp {char} $argtype]} {
344 append actuals " \\'\\\\00$argument\\'"
345 }
346 }
b2bbed47 347
d3dc44a6
KS
348 if {[string match $argtype "void"]} {
349 set body "return $decimal;"
350 } else {
351 set body "arg = 0; return $decimal;"
352 }
d1fe6965 353
d3dc44a6
KS
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"
357 }
b2bbed47 358
d3dc44a6
KS
359 -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}, arg=.*\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" {
360 if $might_kfail {
361 kfail "c++/8130" "continue to bp overloaded : $argtype"
362 } else {
363 fail "continue to bp overloaded : $argtype"
364 }
365 }
c906108c 366 }
dfcd3bfb 367}
c906108c 368
d3dc44a6
KS
369# An array which describes which of these methods might be expected
370# to kfail on GCC 2.95. See C++/8210.
371array set might_fail {
372 void 0
373 char 1
374 signed_char 1
375 unsigned_char 1
376 short_int 1
377 unsigned_short_int 1
378 int 0
379 unsigned_int 0
380 long_int 0
381 unsigned_long_int 0
382 float 0
383 double 1
384}
385
386foreach type $all_types {
387 continue_to_bp_overloaded 14 $might_fail($type) $line($type) \
388 $type $arguments($type)
389}
b2bbed47 390
eae06beb
JB
391# Test breaking on an overloaded function when multiple-symbols
392# is set to "cancel"
a8d52276 393gdb_test_no_output "set multiple-symbols cancel"
eae06beb
JB
394gdb_test "break foo::foofunc" \
395 "canceled.*"
396
397# Test breaking on an overloaded function when multiple-symbols
398# is set to "all"
a8d52276 399gdb_test_no_output "set multiple-symbols all"
eae06beb 400gdb_test "break foo::foofunc" \
f8eba3c6 401 "Breakpoint \[0-9\]+ at ${hex}: foo::foofunc. .2 locations..*"
dfcd3bfb 402
b2bbed47 403# That's all, folks.
dfcd3bfb 404
d3dc44a6 405unset -nocomplain line types
dfcd3bfb 406gdb_continue_to_end "finish program"
This page took 1.196696 seconds and 4 git commands to generate.