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