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