1 # Copyright (C) 1992, 1997, 1999, 2001 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Fred Fish. (fnf@cygnus.com)
21 # Adapted for g++ 3.0 ABI by Michael Chastain. (chastain@redhat.com)
27 if { [skip_cplus_tests] } { continue }
29 set testfile "cplusfuncs"
30 set srcfile ${testfile}.cc
31 set binfile ${objdir}/${subdir}/${testfile}
33 if { [get_compiler_info $binfile "c++"] } {
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
38 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
42 # g++ changed its ABI between 2.95 and 3.0. gdb has two demanglers
43 # for the two different styles. The two demanglers have some subtle
44 # discrepancies in their output.
46 # old demangler new demangler
47 # --- --------- --- ---------
48 # "operator, " "operator,"
54 # "unsigned int" "unsigned"
57 # I probe for the forms in use.
58 # The defaults are for the v3 demangler (as of 2001-02-13).
61 set dm_operator_comma ","
62 set dm_type_char_star "char*"
63 set dm_type_char_star_quoted "char\\*"
64 set dm_type_foo_ref "foo&"
65 set dm_type_int_star "int*"
66 set dm_type_long_star "long*"
67 set dm_type_unsigned_int "unsigned"
69 set dm_type_void_star "void*"
71 proc probe_demangler { } {
73 global dm_operator_comma
74 global dm_type_char_star
75 global dm_type_char_star_quoted
76 global dm_type_foo_ref
77 global dm_type_int_star
78 global dm_type_long_star
79 global dm_type_unsigned_int
81 global dm_type_void_star
83 send_gdb "print &'foo::operator,(foo&)'\n"
85 -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
87 set dm_operator_comma ", "
88 pass "detect dm_operator_comma"
90 -re ".*foo::operator,\\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
92 pass "detect dm_operator_comma"
94 -re ".*$gdb_prompt $" {
95 fail "detect dm_operator_comma"
98 fail "detect dm_operator_comma"
102 send_gdb "print &'dm_type_char_star'\n"
104 -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
106 set dm_type_char_star "char *"
107 set dm_type_char_star_quoted "char \\*"
108 pass "detect dm_type_char_star"
110 -re ".*dm_type_char_star\\(char\\*\\).*\r\n$gdb_prompt $" {
112 pass "detect dm_type_char_star"
114 -re ".*$gdb_prompt $" {
115 fail "detect dm_type_char_star"
118 fail "detect dm_type_char_star (timeout)"
122 send_gdb "print &'dm_type_foo_ref'\n"
124 -re ".*dm_type_foo_ref\\(foo &\\).*\r\n$gdb_prompt $" {
126 set dm_type_foo_ref "foo &"
127 pass "detect dm_type_foo_ref"
129 -re ".*dm_type_foo_ref\\(foo&\\).*\r\n$gdb_prompt $" {
131 pass "detect dm_type_foo_ref"
133 -re ".*$gdb_prompt $" {
134 fail "detect dm_type_foo_ref"
137 fail "detect dm_type_foo_ref (timeout)"
141 send_gdb "print &'dm_type_int_star'\n"
143 -re ".*dm_type_int_star\\(int \\*\\).*\r\n$gdb_prompt $" {
145 set dm_type_int_star "int *"
146 pass "detect dm_type_int_star"
148 -re ".*dm_type_int_star\\(int\\*\\).*\r\n$gdb_prompt $" {
150 pass "detect dm_type_int_star"
152 -re ".*$gdb_prompt $" {
153 fail "detect dm_type_int_star"
156 fail "detect dm_type_int_star (timeout)"
160 send_gdb "print &'dm_type_long_star'\n"
162 -re ".*dm_type_long_star\\(long \\*\\).*\r\n$gdb_prompt $" {
164 set dm_type_long_star "long *"
165 pass "detect dm_type_long_star"
167 -re ".*dm_type_long_star\\(long\\*\\).*\r\n$gdb_prompt $" {
169 pass "detect dm_type_long_star"
171 -re ".*$gdb_prompt $" {
172 fail "detect dm_type_long_star"
175 fail "detect dm_type_long_star (timeout)"
179 send_gdb "print &'dm_type_unsigned_int'\n"
181 -re ".*dm_type_unsigned_int\\(unsigned int\\).*\r\n$gdb_prompt $" {
183 set dm_type_unsigned_int "unsigned int"
184 pass "detect dm_type_unsigned_int"
186 -re ".*dm_type_unsigned_int\\(unsigned\\).*\r\n$gdb_prompt $" {
188 pass "detect dm_type_unsigned_int"
190 -re ".*$gdb_prompt $" {
191 fail "detect dm_type_unsigned_int"
194 fail "detect dm_unsigned int (timeout)"
198 send_gdb "print &'dm_type_void'\n"
200 -re ".*dm_type_void\\(void\\).*\r\n$gdb_prompt $" {
202 set dm_type_void "void"
203 pass "detect dm_type_void"
205 -re ".*dm_type_void\\(\\).*\r\n$gdb_prompt $" {
207 pass "detect dm_type_void"
209 -re ".*$gdb_prompt $" {
210 fail "detect dm_type_void"
213 fail "detect dm_type_void (timeout)"
217 send_gdb "print &'dm_type_void_star'\n"
219 -re ".*dm_type_void_star\\(void \\*\\).*\r\n$gdb_prompt $" {
221 set dm_type_void_star "void *"
222 pass "detect dm_type_void_star"
224 -re ".*dm_type_void_star\\(void\\*\\).*\r\n$gdb_prompt $" {
226 pass "detect dm_type_void_star"
228 -re ".*$gdb_prompt $" {
229 fail "detect dm_type_void_star"
232 fail "detect dm_type_void_star (timeout)"
238 # Lookup a specific C++ function and print the demangled type.
239 # This form accepts the demangled type as a regexp.
242 proc info_func_regexp { name demangled } {
245 send_gdb "info function $name\n"
247 -re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
248 pass "info function for \"$name\""
250 -re ".*$gdb_prompt $" {
251 fail "info function for \"$name\""
254 fail "info function for \"$name\" (timeout)"
260 # Lookup a specific C++ function and print the demangled type.
261 # This form accepts the demangled type as a literal string.
264 proc info_func { name demangled } {
265 info_func_regexp "$name" [string_to_regexp "$demangled"]
269 # Print the address of a function.
270 # This checks that I can lookup a fully qualified C++ function.
271 # This also checks the argument types on the return string.
274 proc print_addr_2 { name good } {
278 set good_pattern [string_to_regexp $good]
280 send_gdb "print &'$name'\n"
282 -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
283 pass "print &'$name'"
285 -re ".*$gdb_prompt $" {
286 fail "print &'$name'"
289 fail "print &'$name' (timeout)"
295 # Simple interfaces to print_addr_2.
298 proc print_addr { name } {
299 print_addr_2 "$name" "$name"
303 # Test name demangling for operators.
305 # The '(' at the end of each regex input pattern is so that we match only
306 # the one we are looking for. I.E. "operator&" would match both
307 # "operator&(foo &)" and "operator&&(foo &)".
309 # gdb-gnats bug gdb/18:
310 # "gdb can't parse "info func operator*" or "info func operator\*".
311 # The star in "operator*" is interpreted as a regexp, but the "\*"
312 # in "operator\*" is not a legal operator.
315 proc test_lookup_operator_functions {} {
316 global dm_operator_comma
317 global dm_type_char_star
318 global dm_type_char_star_quoted
319 global dm_type_foo_ref
321 global dm_type_void_star
323 # OBSOLETE # # These tests don't work for COFF targets; don't even try them
324 # OBSOLETE # if [istarget "a29k-*-udi"] then {
325 # OBSOLETE # setup_xfail "a29k-*-udi"
326 # OBSOLETE # fail "skipping operator tests"
330 # operator* requires quoting so that GDB does not treat it as a regexp.
331 info_func "operator\\*(" "void foo::operator*($dm_type_foo_ref);"
332 info_func "operator%(" "void foo::operator%($dm_type_foo_ref);"
333 info_func "operator-(" "void foo::operator-($dm_type_foo_ref);"
334 info_func "operator>>(" "void foo::operator>>($dm_type_foo_ref);"
335 info_func "operator!=(" "void foo::operator!=($dm_type_foo_ref);"
336 info_func "operator>(" "void foo::operator>($dm_type_foo_ref);"
337 info_func "operator>=(" "void foo::operator>=($dm_type_foo_ref);"
338 info_func "operator|(" "void foo::operator|($dm_type_foo_ref);"
339 info_func "operator&&(" "void foo::operator&&($dm_type_foo_ref);"
340 info_func "operator!(" "void foo::operator!($dm_type_void);"
341 info_func "operator++(" "void foo::operator++(int);"
342 info_func "operator=(" "void foo::operator=($dm_type_foo_ref);"
343 info_func "operator+=(" "void foo::operator+=($dm_type_foo_ref);"
344 # operator*= requires quoting so that GDB does not treat it as a regexp.
345 info_func "operator\\*=(" "void foo::operator*=($dm_type_foo_ref);"
346 info_func "operator%=(" "void foo::operator%=($dm_type_foo_ref);"
347 info_func "operator>>=(" "void foo::operator>>=($dm_type_foo_ref);"
348 info_func "operator|=(" "void foo::operator|=($dm_type_foo_ref);"
349 info_func "operator$dm_operator_comma\(" \
350 "void foo::operator$dm_operator_comma\($dm_type_foo_ref);"
351 info_func "operator/(" "void foo::operator/($dm_type_foo_ref);"
352 info_func "operator+(" "void foo::operator+($dm_type_foo_ref);"
353 info_func "operator<<(" "void foo::operator<<($dm_type_foo_ref);"
354 info_func "operator==(" "void foo::operator==($dm_type_foo_ref);"
355 info_func "operator<(" "void foo::operator<($dm_type_foo_ref);"
356 info_func "operator<=(" "void foo::operator<=($dm_type_foo_ref);"
357 info_func "operator&(" "void foo::operator&($dm_type_foo_ref);"
358 info_func "operator^(" "void foo::operator^($dm_type_foo_ref);"
359 info_func "operator||(" "void foo::operator||($dm_type_foo_ref);"
360 info_func "operator~(" "void foo::operator~($dm_type_void);"
361 info_func "operator--(" "void foo::operator--(int);"
362 info_func "operator->(" "foo *foo::operator->($dm_type_void);"
363 info_func "operator-=(" "void foo::operator-=($dm_type_foo_ref);"
364 info_func "operator/=(" "void foo::operator/=($dm_type_foo_ref);"
365 info_func "operator<<=(" "void foo::operator<<=($dm_type_foo_ref);"
366 info_func "operator&=(" "void foo::operator&=($dm_type_foo_ref);"
367 info_func "operator^=(" "void foo::operator^=($dm_type_foo_ref);"
368 # operator->* requires quoting so that GDB does not treat it as a regexp.
369 info_func "operator->\\*(" "void foo::operator->*($dm_type_foo_ref);"
371 # operator[] needs double backslashes, so that a single backslash
372 # will be sent to GDB, preventing the square brackets from being
373 # evaluated as a regular expression.
374 info_func "operator\\\[\\\](" "void foo::operator\[\]($dm_type_foo_ref);"
376 # These are gnarly because they might end with 'static'.
377 set dm_type_void_star_regexp [string_to_regexp $dm_type_void_star]
378 info_func_regexp "operator new(" "void \\*foo::operator new\\(.*\\)(| static);"
379 info_func_regexp "operator delete(" "void foo::operator delete\\($dm_type_void_star_regexp\\)(| static);"
381 info_func "operator int(" "int foo::operator int($dm_type_void);"
382 info_func "operator()(" "void foo::operator()($dm_type_foo_ref);"
383 info_func "operator $dm_type_char_star_quoted\(" \
384 "char *foo::operator $dm_type_char_star\($dm_type_void);"
389 proc test_paddr_operator_functions {} {
391 global hp_aCC_compiler
392 global dm_operator_comma
393 global dm_type_char_star
394 global dm_type_foo_ref
395 global dm_type_long_star
396 global dm_type_unsigned_int
398 global dm_type_void_star
400 print_addr "foo::operator*($dm_type_foo_ref)"
401 print_addr "foo::operator%($dm_type_foo_ref)"
402 print_addr "foo::operator-($dm_type_foo_ref)"
403 print_addr "foo::operator>>($dm_type_foo_ref)"
404 print_addr "foo::operator!=($dm_type_foo_ref)"
405 print_addr "foo::operator>($dm_type_foo_ref)"
406 print_addr "foo::operator>=($dm_type_foo_ref)"
407 print_addr "foo::operator|($dm_type_foo_ref)"
408 print_addr "foo::operator&&($dm_type_foo_ref)"
409 print_addr "foo::operator!($dm_type_void)"
410 print_addr "foo::operator++(int)"
411 print_addr "foo::operator=($dm_type_foo_ref)"
412 print_addr "foo::operator+=($dm_type_foo_ref)"
413 print_addr "foo::operator*=($dm_type_foo_ref)"
414 print_addr "foo::operator%=($dm_type_foo_ref)"
415 print_addr "foo::operator>>=($dm_type_foo_ref)"
416 print_addr "foo::operator|=($dm_type_foo_ref)"
417 print_addr "foo::operator$dm_operator_comma\($dm_type_foo_ref)"
418 print_addr "foo::operator/($dm_type_foo_ref)"
419 print_addr "foo::operator+($dm_type_foo_ref)"
420 print_addr "foo::operator<<($dm_type_foo_ref)"
421 print_addr "foo::operator==($dm_type_foo_ref)"
422 print_addr "foo::operator<($dm_type_foo_ref)"
423 print_addr "foo::operator<=($dm_type_foo_ref)"
424 print_addr "foo::operator&($dm_type_foo_ref)"
425 print_addr "foo::operator^($dm_type_foo_ref)"
426 print_addr "foo::operator||($dm_type_foo_ref)"
427 print_addr "foo::operator~($dm_type_void)"
428 print_addr "foo::operator--(int)"
429 print_addr "foo::operator->($dm_type_void)"
430 print_addr "foo::operator-=($dm_type_foo_ref)"
431 print_addr "foo::operator/=($dm_type_foo_ref)"
432 print_addr "foo::operator<<=($dm_type_foo_ref)"
433 print_addr "foo::operator&=($dm_type_foo_ref)"
434 print_addr "foo::operator^=($dm_type_foo_ref)"
435 print_addr "foo::operator->*($dm_type_foo_ref)"
436 print_addr "foo::operator\[\]($dm_type_foo_ref)"
437 print_addr "foo::operator()($dm_type_foo_ref)"
439 gdb_test "print &'foo::operator new'" \
440 " = .* $hex <foo::operator new\\(.*\\)(| static)>"
441 if { !$hp_aCC_compiler } {
442 print_addr "foo::operator delete($dm_type_void_star)"
444 gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
445 " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
448 print_addr "foo::operator int($dm_type_void)"
449 print_addr "foo::operator $dm_type_char_star\($dm_type_void)"
453 # Test overloaded functions (1 arg).
456 proc test_paddr_overloaded_functions {} {
457 global dm_type_unsigned_int
460 print_addr "overload1arg($dm_type_void)"
461 print_addr "overload1arg(char)"
462 print_addr "overload1arg(signed char)"
463 print_addr "overload1arg(unsigned char)"
464 print_addr "overload1arg(short)"
465 print_addr "overload1arg(unsigned short)"
466 print_addr "overload1arg(int)"
467 print_addr "overload1arg($dm_type_unsigned_int)"
468 print_addr "overload1arg(long)"
469 print_addr "overload1arg(unsigned long)"
470 print_addr "overload1arg(float)"
471 print_addr "overload1arg(double)"
473 print_addr "overloadargs(int)"
474 print_addr "overloadargs(int, int)"
475 print_addr "overloadargs(int, int, int)"
476 print_addr "overloadargs(int, int, int, int)"
477 print_addr "overloadargs(int, int, int, int, int)"
478 print_addr "overloadargs(int, int, int, int, int, int)"
479 print_addr "overloadargs(int, int, int, int, int, int, int)"
480 print_addr "overloadargs(int, int, int, int, int, int, int, int)"
481 print_addr "overloadargs(int, int, int, int, int, int, int, int, int)"
482 print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int)"
483 print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int, int)"
486 proc test_paddr_hairy_functions {} {
489 global dm_type_char_star
490 global dm_type_int_star
491 global dm_type_long_star
493 print_addr_2 "hairyfunc1" "hairyfunc1(int)"
494 print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
495 print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
496 print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
498 # gdb-gnats bug gdb/19:
499 # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
500 print_addr_2 "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))"
501 print_addr_2 "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))"
502 print_addr_2 "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))"
517 # Start with a fresh gdb.
521 gdb_reinitialize_dir $srcdir/$subdir
524 send_gdb "set language c++\n"
525 gdb_expect -re "$gdb_prompt $"
526 send_gdb "set width 0\n"
527 gdb_expect -re "$gdb_prompt $"
529 # Get the debug format for the compiled test case. If that
530 # format is DWARF 1 then just skip all the tests since none of
533 if [ runto_main] then {
535 if [ setup_xfail_format "DWARF 1" ] then {
536 fail "C++ tests skipped due to limited C++ support in DWARF 1 debug format"
543 test_paddr_overloaded_functions
544 test_paddr_operator_functions
545 test_paddr_hairy_functions
546 test_lookup_operator_functions