Commit | Line | Data |
---|---|---|
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 |
26 | global timeout |
27 | set timeout 15 | |
c906108c SS |
28 | # |
29 | # test running programs | |
30 | # | |
c906108c | 31 | |
d4f3574e SS |
32 | if { [skip_cplus_tests] } { continue } |
33 | ||
f5f3a911 | 34 | standard_testfile .cc |
c906108c | 35 | |
d3dc44a6 | 36 | if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { |
d3dc44a6 | 37 | return -1 |
c906108c SS |
38 | } |
39 | ||
c906108c SS |
40 | # set it up at a breakpoint so we can play with the variable values |
41 | # | |
d3dc44a6 | 42 | if {![runto_main]} { |
c906108c SS |
43 | perror "couldn't run to breakpoint" |
44 | continue | |
45 | } | |
46 | ||
b2bbed47 MC |
47 | # When I ask gdb to set a breakpoint on an overloaded function, |
48 | # gdb gives me a choice menu. I might get stuck in that choice menu | |
49 | # (for example, if C++ name mangling is not working properly). | |
50 | # | |
51 | # This procedure issues a command that works at either the menu | |
52 | # prompt or the command prompt to get back to the command prompt. | |
53 | # | |
54 | # Note that an empty line won't do it (it means 'repeat the previous command' | |
55 | # at top level). A line with a single space in it works nicely. | |
c906108c | 56 | |
b2bbed47 MC |
57 | proc take_gdb_out_of_choice_menu {} { |
58 | global gdb_prompt | |
f8d3bf8f | 59 | gdb_test_multiple " " " " { |
b2bbed47 MC |
60 | -re ".*$gdb_prompt $" { |
61 | } | |
62 | timeout { | |
63 | perror "could not resynchronize to command prompt (timeout)" | |
64 | continue | |
65 | } | |
66 | } | |
67 | } | |
c906108c SS |
68 | |
69 | ||
c906108c | 70 | |
b2bbed47 MC |
71 | # This procedure sets an overloaded breakpoint. |
72 | # When I ask for such a breakpoint, gdb gives me a menu of 'cancel' 'all' | |
73 | # and a bunch of choices. I then choose from that menu by number. | |
c906108c | 74 | |
b2bbed47 MC |
75 | proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} { |
76 | global gdb_prompt hex srcfile | |
c906108c | 77 | |
b2bbed47 MC |
78 | # Get into the overload menu. |
79 | send_gdb "break $name\n" | |
80 | gdb_expect { | |
81 | -re "$expectedmenu" { | |
82 | pass "bp menu for $name choice $mychoice" | |
c906108c | 83 | |
b2bbed47 MC |
84 | # Choose my choice. |
85 | send_gdb "$mychoice\n" | |
c906108c | 86 | gdb_expect { |
b2bbed47 MC |
87 | -re "Breakpoint $bpnumber at $hex: file.*$srcfile, line $linenumber.\r\n$gdb_prompt $" { |
88 | pass "set bp $bpnumber on $name $mychoice line $linenumber" | |
89 | } | |
90 | -re ".*$gdb_prompt $" { | |
91 | fail "set bp $bpnumber on $name $mychoice line $linenumber (bad bp)" | |
92 | } | |
93 | timeout { | |
94 | fail "set bp $bpnumber on $name $mychoice line $linenumber (timeout)" | |
95 | take_gdb_out_of_choice_menu | |
96 | } | |
97 | } | |
98 | } | |
99 | -re ".*\r\n> " { | |
100 | fail "bp menu for $name choice $mychoice (bad menu)" | |
101 | take_gdb_out_of_choice_menu | |
102 | } | |
103 | -re ".*$gdb_prompt $" { | |
104 | fail "bp menu for $name choice $mychoice (no menu)" | |
105 | } | |
106 | timeout { | |
107 | fail "bp menu for $name choice $mychoice (timeout)" | |
108 | take_gdb_out_of_choice_menu | |
109 | } | |
110 | } | |
111 | } | |
c906108c | 112 | |
d3dc44a6 | 113 | # Compute the expected menu for overload1arg. |
cec808ec | 114 | # Note the arg type variations for void and integer types. |
b2bbed47 | 115 | # This accommodates different versions of g++. |
c906108c | 116 | |
d3dc44a6 KS |
117 | # Probe for the real types. This will do some unnecessary checking |
118 | # for some simple types (like "int"), but it's just easier to loop | |
119 | # over all_types instead of calling out just the exceptions. | |
120 | # This list /must/ remain in the same order that the methods are | |
121 | # called in the source code. Otherwise the order in which breakpoints | |
122 | # are hit (tested below) will be incorrect. | |
123 | set all_types [list void char signed_char unsigned_char short_int \ | |
124 | unsigned_short_int int unsigned_int long_int \ | |
125 | unsigned_long_int float double] | |
126 | ||
127 | # ARGUMENTS is an array that will map from synthetic type to argument | |
128 | # expressions in the source code, which is of the form "arg = $decimal". | |
129 | # ARGUMENTS stores this decimal number. | |
130 | array set arguments { | |
131 | void "" | |
132 | char 2 | |
133 | signed_char 3 | |
134 | unsigned_char 4 | |
135 | short_int 5 | |
136 | unsigned_short_int 6 | |
137 | int 7 | |
138 | unsigned_int 8 | |
139 | long_int 9 | |
140 | unsigned_long_int 10 | |
141 | float 100(.0)? | |
142 | double 200(.0)? | |
143 | } | |
144 | ||
145 | unset -nocomplain line types | |
146 | foreach type $all_types { | |
147 | # TYPES is an array that maps the synthetic names in ALL_TYPES | |
148 | # to the real type used in the debugger. These will be checked | |
149 | # below and changed if the debugger thinks they are different from | |
150 | # their default values. | |
151 | set types($type) [join [split $type "_"] " "] | |
152 | ||
153 | # LINE is an array that will map from synthetic type to line number. | |
154 | # in the source code. | |
155 | set line($type) [gdb_get_line_number "fo1 $type"] | |
156 | ||
157 | # Probe for the actual type. | |
158 | gdb_test_multiple "print &foo::overload1arg($types($type))" \ | |
159 | "probe $types($type)" { | |
160 | -re ".*\<foo::.*\>.*$gdb_prompt $" { | |
161 | regexp {<.*>} $expect_out(0,string) func | |
162 | regexp {\(.*\)} $func real_type | |
163 | ||
164 | # Store the real type into TYPES. | |
165 | set types($type) [string trim $real_type {()}] | |
166 | ||
167 | # Create an inverse mapping of the actual type to | |
168 | # the synthetic type. | |
169 | set type_map("$types($type)") $type | |
170 | pass "detect $type" | |
171 | } | |
172 | } | |
173 | } | |
174 | ||
175 | # This is a list of the actual overloaded method arguments. | |
176 | set overloads {} | |
177 | foreach type $all_types { | |
178 | lappend overloads $types($type) | |
179 | } | |
180 | ||
181 | # Sort this list alphabetically. | |
182 | set overloads [lsort $overloads] | |
183 | ||
184 | # Create the menu list. | |
185 | set items {"cancel" "all"} | |
186 | foreach ovld $overloads { | |
187 | lappend items "$srcfile:foo::overload1arg\\($ovld\\)" | |
188 | } | |
189 | set menu_items {} | |
190 | set idx 0 | |
191 | foreach item $items { | |
192 | lappend menu_items ".$idx. .*$item" | |
193 | incr idx | |
194 | } | |
195 | set menu_overload1arg [join $menu_items {[\r\n]*}] | |
196 | append menu_overload1arg {[\r\n]*> $} | |
c906108c | 197 | |
eae06beb JB |
198 | # Set multiple-symbols to "ask", to allow us to test the use |
199 | # of the multiple-choice menu when breaking on an overloaded method. | |
a8d52276 | 200 | gdb_test_no_output "set multiple-symbols ask" |
c906108c | 201 | |
b2bbed47 | 202 | # Set breakpoints on foo::overload1arg, one by one. |
d3dc44a6 KS |
203 | set bpnum 1 |
204 | set method "foo::overload1arg" | |
205 | for {set idx 0} {$idx < [llength $overloads]} {incr idx} { | |
206 | set type [lindex $overloads $idx] | |
207 | set_bp_overloaded $method $menu_overload1arg \ | |
208 | [expr {$idx + 2}] [incr bpnum] $line($type_map("$type")) | |
209 | } | |
c906108c | 210 | |
b2bbed47 | 211 | # Verify the breakpoints. |
d3dc44a6 KS |
212 | set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*" |
213 | append bptable "\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\[\r\n\]+" | |
214 | append bptable "\[\t \]+breakpoint already hit 1 time\[\r\n\]+" | |
215 | foreach ovld $overloads { | |
216 | append bptable [format "\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(%s\\) at.*$srcfile:%d\[\r\n\]+" $ovld \ | |
217 | $line($type_map("$ovld"))] | |
218 | } | |
219 | gdb_test "info break" $bptable "breakpoint info (after setting one-by-one)" | |
c906108c | 220 | |
b2bbed47 MC |
221 | # Test choice "cancel". |
222 | # This is copy-and-paste from set_bp_overloaded. | |
c906108c SS |
223 | |
224 | send_gdb "break foo::overload1arg\n" | |
225 | gdb_expect { | |
b2bbed47 MC |
226 | -re "$menu_overload1arg" { |
227 | pass "bp menu for foo::overload1arg choice cancel" | |
228 | # Choose cancel. | |
229 | send_gdb "0\n" | |
230 | gdb_expect { | |
231 | -re "canceled\r\n$gdb_prompt $" { | |
232 | pass "set bp on overload1arg canceled" | |
233 | } | |
234 | -re "cancelled\r\n$gdb_prompt $" { | |
235 | pass "set bp on overload1arg canceled" | |
236 | } | |
237 | -re ".*$gdb_prompt $" { | |
238 | fail "set bp on overload1arg canceled (bad message)" | |
239 | } | |
240 | timeout { | |
241 | fail "set bp on overload1arg canceled (timeout)" | |
242 | take_gdb_out_of_choice_menu | |
243 | } | |
244 | } | |
245 | } | |
246 | -re ".*\r\n> " { | |
247 | fail "bp menu for foo::overload1arg choice cancel (bad menu)" | |
248 | take_gdb_out_of_choice_menu | |
249 | } | |
250 | -re ".*$gdb_prompt $" { | |
251 | fail "bp menu for foo::overload1arg choice cancel (no menu)" | |
252 | } | |
253 | timeout { | |
254 | fail "bp menu for foo::overload1arg choice cancel (timeout)" | |
255 | take_gdb_out_of_choice_menu | |
256 | } | |
257 | } | |
c906108c | 258 | |
d3dc44a6 | 259 | gdb_test "info break" $bptable "breakpoint info (after cancel)" |
c906108c | 260 | |
b2bbed47 | 261 | # Delete these breakpoints. |
c906108c SS |
262 | |
263 | send_gdb "delete breakpoints\n" | |
264 | gdb_expect { | |
b2bbed47 | 265 | -re "Delete all breakpoints.* $" { |
c906108c SS |
266 | send_gdb "y\n" |
267 | gdb_expect { | |
268 | -re ".*$gdb_prompt $" { | |
b2bbed47 MC |
269 | pass "delete all breakpoints" |
270 | } | |
271 | timeout { | |
272 | fail "delete all breakpoints (timeout)" | |
c906108c | 273 | } |
c906108c SS |
274 | } |
275 | } | |
b2bbed47 MC |
276 | timeout { |
277 | fail "delete all breakpoints (timeout)" | |
278 | } | |
c906108c SS |
279 | } |
280 | ||
b2bbed47 | 281 | gdb_test "info breakpoints" "No breakpoints or watchpoints." "breakpoint info (after delete)" |
c906108c SS |
282 | |
283 | ||
c906108c | 284 | |
b2bbed47 MC |
285 | # Test choice "all". |
286 | # This is copy-and-paste from set_bp_overloaded. | |
c906108c | 287 | |
b2bbed47 MC |
288 | send_gdb "break foo::overload1arg\n" |
289 | gdb_expect { | |
290 | -re "$menu_overload1arg" { | |
291 | pass "bp menu for foo::overload1arg choice all" | |
292 | # Choose all. | |
293 | send_gdb "1\n" | |
294 | gdb_expect { | |
f8eba3c6 | 295 | -re "Breakpoint $decimal at $hex: foo::overload1arg. .12 locations.\r\n.*$gdb_prompt $" { |
b2bbed47 MC |
296 | pass "set bp on overload1arg all" |
297 | } | |
298 | -re ".*$gdb_prompt $" { | |
299 | fail "set bp on overload1arg all (bad message)" | |
300 | } | |
301 | timeout { | |
302 | fail "set bp on overload1arg all (timeout)" | |
303 | take_gdb_out_of_choice_menu | |
304 | } | |
305 | } | |
306 | } | |
307 | -re ".*\r\n> " { | |
308 | fail "bp menu for foo::overload1arg choice all (bad menu)" | |
309 | take_gdb_out_of_choice_menu | |
310 | } | |
311 | -re ".*$gdb_prompt $" { | |
312 | fail "bp menu for foo::overload1arg choice all (no menu)" | |
313 | } | |
314 | timeout { | |
315 | fail "bp menu for foo::overload1arg choice all (timeout)" | |
316 | take_gdb_out_of_choice_menu | |
317 | } | |
318 | } | |
c906108c | 319 | |
40e084e1 KS |
320 | # Create the breakpoint table for "info breakpoint". |
321 | set bptable "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*\[\r\n]+" | |
322 | append bptable "\[0-9\]+\[\t \]+breakpoint\[\t \]+keep\[\t \]y\[\t \]+<MULTIPLE>.*\[\r\n\]+" | |
323 | foreach ovld {void char signed_char unsigned_char short_int \ | |
324 | unsigned_short_int int unsigned_int long_int \ | |
325 | unsigned_long_int float double} { | |
326 | append bptable [format "\[0-9\]+.\[0-9\]+\[\t \]+y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(%s\\) at.*$srcfile:%d\[\r\n\]+" \ | |
327 | $types($ovld) $line($ovld)] | |
328 | } | |
b2bbed47 | 329 | |
40e084e1 | 330 | gdb_test "info break" $bptable "breakpoint info (after setting on all)" |
c906108c | 331 | |
b2bbed47 | 332 | # Run through each breakpoint. |
d3dc44a6 KS |
333 | proc continue_to_bp_overloaded {bpnumber might_fail line argtype argument} { |
334 | global gdb_prompt hex decimal srcfile | |
335 | ||
336 | if {$argument == ""} { | |
337 | set actuals "" | |
338 | } else { | |
339 | set actuals "arg=$argument" | |
340 | if {[regexp {char} $argtype]} { | |
341 | append actuals " \\'\\\\00$argument\\'" | |
342 | } | |
343 | } | |
b2bbed47 | 344 | |
d3dc44a6 KS |
345 | if {[string match $argtype "void"]} { |
346 | set body "return $decimal;" | |
347 | } else { | |
348 | set body "arg = 0; return $decimal;" | |
349 | } | |
d1fe6965 | 350 | |
d3dc44a6 KS |
351 | gdb_test_multiple "continue" "continue to bp overloaded : $argtype" { |
352 | -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}(, )?$actuals\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" { | |
353 | pass "continue to bp overloaded : $argtype" | |
354 | } | |
b2bbed47 | 355 | |
d3dc44a6 KS |
356 | -re "Continuing.\r\n\r\nBreakpoint $bpnumber, foo::overload1arg \\(this=${hex}, arg=.*\\) at .*$srcfile:$line\r\n$decimal\[\t \]+{ $body }.*$gdb_prompt $" { |
357 | if $might_kfail { | |
358 | kfail "c++/8130" "continue to bp overloaded : $argtype" | |
359 | } else { | |
360 | fail "continue to bp overloaded : $argtype" | |
361 | } | |
362 | } | |
c906108c | 363 | } |
dfcd3bfb | 364 | } |
c906108c | 365 | |
d3dc44a6 KS |
366 | # An array which describes which of these methods might be expected |
367 | # to kfail on GCC 2.95. See C++/8210. | |
368 | array set might_fail { | |
369 | void 0 | |
370 | char 1 | |
371 | signed_char 1 | |
372 | unsigned_char 1 | |
373 | short_int 1 | |
374 | unsigned_short_int 1 | |
375 | int 0 | |
376 | unsigned_int 0 | |
377 | long_int 0 | |
378 | unsigned_long_int 0 | |
379 | float 0 | |
380 | double 1 | |
381 | } | |
382 | ||
383 | foreach type $all_types { | |
384 | continue_to_bp_overloaded 14 $might_fail($type) $line($type) \ | |
385 | $type $arguments($type) | |
386 | } | |
b2bbed47 | 387 | |
eae06beb JB |
388 | # Test breaking on an overloaded function when multiple-symbols |
389 | # is set to "cancel" | |
a8d52276 | 390 | gdb_test_no_output "set multiple-symbols cancel" |
eae06beb JB |
391 | gdb_test "break foo::foofunc" \ |
392 | "canceled.*" | |
393 | ||
394 | # Test breaking on an overloaded function when multiple-symbols | |
395 | # is set to "all" | |
a8d52276 | 396 | gdb_test_no_output "set multiple-symbols all" |
eae06beb | 397 | gdb_test "break foo::foofunc" \ |
f8eba3c6 | 398 | "Breakpoint \[0-9\]+ at ${hex}: foo::foofunc. .2 locations..*" |
dfcd3bfb | 399 | |
b2bbed47 | 400 | # That's all, folks. |
dfcd3bfb | 401 | |
d3dc44a6 | 402 | unset -nocomplain line types |
dfcd3bfb | 403 | gdb_continue_to_end "finish program" |