1 # Copyright 1992, 1997, 1999, 2001, 2002, 2003, 2004, 2007, 2008, 2009
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
18 # Adapted for g++ 3.0 ABI by Michael Chastain. (chastain@redhat.com)
24 if { [skip_cplus_tests] } { continue }
26 set testfile "cplusfuncs"
27 set srcfile ${testfile}.cc
28 set binfile ${objdir}/${subdir}/${testfile}
30 if { [get_compiler_info $binfile "c++"] } {
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
35 untested cplusfuncs.exp
40 # g++ changed its ABI between 2.95 and 3.0. gdb has two demanglers
41 # for the two different styles. The two demanglers have some subtle
42 # discrepancies in their output.
44 # old demangler new demangler
45 # --- --------- --- ---------
46 # "operator, " "operator,"
52 # "unsigned int" "unsigned"
55 # I probe for the forms in use.
56 # The defaults are for the v3 demangler (as of 2001-02-13).
59 set dm_operator_comma ","
60 set dm_type_char_star "char*"
61 set dm_type_char_star_quoted "char\\*"
62 set dm_type_foo_ref "foo&"
63 set dm_type_int_star "int*"
64 set dm_type_long_star "long*"
65 set dm_type_unsigned_int "unsigned"
66 set dm_type_void "void"
67 set dm_type_void_star "void*"
69 proc probe_demangler { } {
71 global dm_operator_comma
72 global dm_type_char_star
73 global dm_type_char_star_quoted
74 global dm_type_foo_ref
75 global dm_type_int_star
76 global dm_type_long_star
77 global dm_type_unsigned_int
79 global dm_type_void_star
81 send_gdb "print &foo::operator,(foo&)\n"
83 -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
85 set dm_operator_comma ", "
86 pass "detect dm_operator_comma"
88 -re ".*foo::operator,\\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
90 pass "detect dm_operator_comma"
92 -re ".*$gdb_prompt $" {
93 fail "detect dm_operator_comma"
96 fail "detect dm_operator_comma"
100 send_gdb "print &dm_type_char_star\n"
102 -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
104 set dm_type_char_star "char *"
105 set dm_type_char_star_quoted "char \\*"
106 pass "detect dm_type_char_star"
108 -re ".*dm_type_char_star\\(char\\*\\).*\r\n$gdb_prompt $" {
110 pass "detect dm_type_char_star"
112 -re ".*$gdb_prompt $" {
113 fail "detect dm_type_char_star"
116 fail "detect dm_type_char_star (timeout)"
120 send_gdb "print &dm_type_foo_ref\n"
122 -re ".*dm_type_foo_ref\\(foo &\\).*\r\n$gdb_prompt $" {
124 set dm_type_foo_ref "foo &"
125 pass "detect dm_type_foo_ref"
127 -re ".*dm_type_foo_ref\\(foo&\\).*\r\n$gdb_prompt $" {
129 pass "detect dm_type_foo_ref"
131 -re ".*$gdb_prompt $" {
132 fail "detect dm_type_foo_ref"
135 fail "detect dm_type_foo_ref (timeout)"
139 send_gdb "print &dm_type_int_star\n"
141 -re ".*dm_type_int_star\\(int \\*\\).*\r\n$gdb_prompt $" {
143 set dm_type_int_star "int *"
144 pass "detect dm_type_int_star"
146 -re ".*dm_type_int_star\\(int\\*\\).*\r\n$gdb_prompt $" {
148 pass "detect dm_type_int_star"
150 -re ".*$gdb_prompt $" {
151 fail "detect dm_type_int_star"
154 fail "detect dm_type_int_star (timeout)"
158 send_gdb "print &dm_type_long_star\n"
160 -re ".*dm_type_long_star\\(long \\*\\).*\r\n$gdb_prompt $" {
162 set dm_type_long_star "long *"
163 pass "detect dm_type_long_star"
165 -re ".*dm_type_long_star\\(long\\*\\).*\r\n$gdb_prompt $" {
167 pass "detect dm_type_long_star"
169 -re ".*$gdb_prompt $" {
170 fail "detect dm_type_long_star"
173 fail "detect dm_type_long_star (timeout)"
177 send_gdb "print &dm_type_unsigned_int\n"
179 -re ".*dm_type_unsigned_int\\(unsigned int\\).*\r\n$gdb_prompt $" {
181 set dm_type_unsigned_int "unsigned int"
182 pass "detect dm_type_unsigned_int"
184 -re ".*dm_type_unsigned_int\\(unsigned\\).*\r\n$gdb_prompt $" {
186 pass "detect dm_type_unsigned_int"
188 -re ".*$gdb_prompt $" {
189 fail "detect dm_type_unsigned_int"
192 fail "detect dm_unsigned int (timeout)"
196 send_gdb "print &dm_type_void\n"
198 -re ".*dm_type_void\\(void\\).*\r\n$gdb_prompt $" {
200 set dm_type_void "void"
201 pass "detect dm_type_void"
203 -re ".*dm_type_void\\(\\).*\r\n$gdb_prompt $" {
205 pass "detect dm_type_void"
207 -re ".*$gdb_prompt $" {
208 fail "detect dm_type_void"
211 fail "detect dm_type_void (timeout)"
215 send_gdb "print &dm_type_void_star\n"
217 -re ".*dm_type_void_star\\(void \\*\\).*\r\n$gdb_prompt $" {
219 set dm_type_void_star "void *"
220 pass "detect dm_type_void_star"
222 -re ".*dm_type_void_star\\(void\\*\\).*\r\n$gdb_prompt $" {
224 pass "detect dm_type_void_star"
226 -re ".*$gdb_prompt $" {
227 fail "detect dm_type_void_star"
230 fail "detect dm_type_void_star (timeout)"
236 # Lookup a specific C++ function and print the demangled type.
237 # This form accepts the demangled type as a regexp.
240 proc info_func_regexp { name demangled } {
243 send_gdb "info function $name\n"
244 regsub {\\\(void\\\)} $demangled {\(\)} demangled
246 -re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
247 pass "info function for \"$name\""
249 -re ".*$gdb_prompt $" {
250 fail "info function for \"$name\""
253 fail "info function for \"$name\" (timeout)"
259 # Lookup a specific C++ function and print the demangled type.
260 # This form accepts the demangled type as a literal string.
263 proc info_func { name demangled } {
264 info_func_regexp "$name" [string_to_regexp "$demangled"]
268 # Print the address of a function.
269 # This checks that I can lookup a fully qualified C++ function.
270 # This also checks the argument types on the return string.
272 # Note: carlton/2003-01-16: If you modify this, make a corresponding
273 # modification to print_addr_2_kfail.
275 proc print_addr_2 { name good } {
279 set good_pattern [string_to_regexp $good]
281 send_gdb "print &$name\n"
283 -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
286 -re ".*$gdb_prompt $" {
290 fail "print &$name (timeout)"
295 # NOTE: carlton/2003-01-16: hairyfunc5-6 fail on GCC 3.x (for at least
296 # x=1 and x=2.1). So I'm modifying print_addr_2 to accept a failure
297 # condition. FIXME: It would be nice if the failure condition were
298 # conditional on the compiler version, but I'm not sufficiently
299 # motivated. I did hardwire in the versions of char * and int *,
300 # which will give some compiler-specificity to the failure.
302 proc print_addr_2_kfail { name good bad bugid } {
306 set good_pattern [string_to_regexp $good]
307 set bad_pattern [string_to_regexp $bad]
309 send_gdb "print &$name\n"
311 -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
314 -re ".* = .* $hex <$bad_pattern>\r\n$gdb_prompt $" {
315 kfail $bugid "print &$name"
317 -re ".*$gdb_prompt $" {
321 fail "print &$name (timeout)"
327 # Simple interfaces to print_addr_2.
330 proc print_addr { name } {
331 regsub {\(void\)} $name {()} expected
332 if {[string first "::" $name] == -1} {
333 # C function -- must be qutoed
336 print_addr_2 "$name" $expected
340 # Test name demangling for operators.
342 # The '(' at the end of each regex input pattern is so that we match only
343 # the one we are looking for. I.E. "operator&" would match both
344 # "operator&(foo &)" and "operator&&(foo &)".
346 # gdb-gnats bug gdb/18:
347 # "gdb can't parse "info func operator*" or "info func operator\*".
348 # The star in "operator*" is interpreted as a regexp, but the "\*"
349 # in "operator\*" is not a legal operator.
352 proc test_lookup_operator_functions {} {
353 global dm_operator_comma
354 global dm_type_char_star
355 global dm_type_char_star_quoted
356 global dm_type_foo_ref
358 global dm_type_void_star
360 # operator* requires quoting so that GDB does not treat it as a regexp.
361 info_func "operator\\*(" "void foo::operator*($dm_type_foo_ref);"
362 info_func "operator%(" "void foo::operator%($dm_type_foo_ref);"
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 info_func "operator|(" "void foo::operator|($dm_type_foo_ref);"
369 info_func "operator&&(" "void foo::operator&&($dm_type_foo_ref);"
370 info_func "operator!(" "void foo::operator!($dm_type_void);"
371 info_func "operator++(" "void foo::operator++(int);"
372 info_func "operator=(" "void foo::operator=($dm_type_foo_ref);"
373 info_func "operator+=(" "void foo::operator+=($dm_type_foo_ref);"
374 # operator*= requires quoting so that GDB does not treat it as a regexp.
375 info_func "operator\\*=(" "void foo::operator*=($dm_type_foo_ref);"
376 info_func "operator%=(" "void foo::operator%=($dm_type_foo_ref);"
377 info_func "operator>>=(" "void foo::operator>>=($dm_type_foo_ref);"
378 info_func "operator|=(" "void foo::operator|=($dm_type_foo_ref);"
379 info_func "operator$dm_operator_comma\(" \
380 "void foo::operator$dm_operator_comma\($dm_type_foo_ref);"
381 info_func "operator/(" "void foo::operator/($dm_type_foo_ref);"
382 info_func "operator+(" "void foo::operator+($dm_type_foo_ref);"
383 info_func "operator<<(" "void foo::operator<<($dm_type_foo_ref);"
384 info_func "operator==(" "void foo::operator==($dm_type_foo_ref);"
385 info_func "operator<(" "void foo::operator<($dm_type_foo_ref);"
386 info_func "operator<=(" "void foo::operator<=($dm_type_foo_ref);"
387 info_func "operator&(" "void foo::operator&($dm_type_foo_ref);"
388 info_func "operator^(" "void foo::operator^($dm_type_foo_ref);"
389 info_func "operator||(" "void foo::operator||($dm_type_foo_ref);"
390 info_func "operator~(" "void foo::operator~($dm_type_void);"
391 info_func "operator--(" "void foo::operator--(int);"
392 info_func "operator->(" "foo *foo::operator->($dm_type_void);"
393 info_func "operator-=(" "void foo::operator-=($dm_type_foo_ref);"
394 info_func "operator/=(" "void foo::operator/=($dm_type_foo_ref);"
395 info_func "operator<<=(" "void foo::operator<<=($dm_type_foo_ref);"
396 info_func "operator&=(" "void foo::operator&=($dm_type_foo_ref);"
397 info_func "operator^=(" "void foo::operator^=($dm_type_foo_ref);"
398 # operator->* requires quoting so that GDB does not treat it as a regexp.
399 info_func "operator->\\*(" "void foo::operator->*($dm_type_foo_ref);"
401 # operator[] needs double backslashes, so that a single backslash
402 # will be sent to GDB, preventing the square brackets from being
403 # evaluated as a regular expression.
404 info_func "operator\\\[\\\](" "void foo::operator\[\]($dm_type_foo_ref);"
406 # These are gnarly because they might end with 'static'.
407 set dm_type_void_star_regexp [string_to_regexp $dm_type_void_star]
408 info_func_regexp "operator new(" "void \\*foo::operator new\\(.*\\)(| static);"
409 info_func_regexp "operator delete(" "void foo::operator delete\\($dm_type_void_star_regexp\\)(| static);"
411 info_func "operator int(" "int foo::operator int($dm_type_void);"
412 info_func "operator()(" "void foo::operator()($dm_type_foo_ref);"
413 info_func "operator $dm_type_char_star_quoted\(" \
414 "char *foo::operator $dm_type_char_star\($dm_type_void);"
419 proc test_paddr_operator_functions {} {
421 global hp_aCC_compiler
422 global dm_operator_comma
423 global dm_type_char_star
424 global dm_type_foo_ref
425 global dm_type_long_star
426 global dm_type_unsigned_int
428 global dm_type_void_star
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)"
438 print_addr "foo::operator&&($dm_type_foo_ref)"
439 print_addr "foo::operator!($dm_type_void)"
440 print_addr "foo::operator++(int)"
441 print_addr "foo::operator=($dm_type_foo_ref)"
442 print_addr "foo::operator+=($dm_type_foo_ref)"
443 print_addr "foo::operator*=($dm_type_foo_ref)"
444 print_addr "foo::operator%=($dm_type_foo_ref)"
445 print_addr "foo::operator>>=($dm_type_foo_ref)"
446 print_addr "foo::operator|=($dm_type_foo_ref)"
447 print_addr "foo::operator$dm_operator_comma\($dm_type_foo_ref)"
448 print_addr "foo::operator/($dm_type_foo_ref)"
449 print_addr "foo::operator+($dm_type_foo_ref)"
450 print_addr "foo::operator<<($dm_type_foo_ref)"
451 print_addr "foo::operator==($dm_type_foo_ref)"
452 print_addr "foo::operator<($dm_type_foo_ref)"
453 print_addr "foo::operator<=($dm_type_foo_ref)"
454 print_addr "foo::operator&($dm_type_foo_ref)"
455 print_addr "foo::operator^($dm_type_foo_ref)"
456 print_addr "foo::operator||($dm_type_foo_ref)"
457 print_addr "foo::operator~($dm_type_void)"
458 print_addr "foo::operator--(int)"
459 print_addr "foo::operator->($dm_type_void)"
460 print_addr "foo::operator-=($dm_type_foo_ref)"
461 print_addr "foo::operator/=($dm_type_foo_ref)"
462 print_addr "foo::operator<<=($dm_type_foo_ref)"
463 print_addr "foo::operator&=($dm_type_foo_ref)"
464 print_addr "foo::operator^=($dm_type_foo_ref)"
465 print_addr "foo::operator->*($dm_type_foo_ref)"
466 print_addr "foo::operator\[\]($dm_type_foo_ref)"
467 print_addr "foo::operator()($dm_type_foo_ref)"
469 gdb_test "print &foo::operator new" \
470 " = .* $hex <foo::operator new\\(.*\\)(| static)>"
471 gdb_test "print &foo::operator new\[\]" \
472 " = .* $hex <foo::operator new\\\[\\\]\\(.*\\)(| static)>"
473 if { !$hp_aCC_compiler } {
474 print_addr "foo::operator delete($dm_type_void_star)"
475 print_addr "foo::operator delete[]($dm_type_void_star)"
477 gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
478 " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
481 print_addr "foo::operator int($dm_type_void)"
482 print_addr "foo::operator $dm_type_char_star\($dm_type_void)"
486 # Test overloaded functions (1 arg).
489 proc test_paddr_overloaded_functions {} {
490 global dm_type_unsigned_int
493 print_addr "overload1arg($dm_type_void)"
494 print_addr "overload1arg(char)"
495 print_addr "overload1arg(signed char)"
496 print_addr "overload1arg(unsigned char)"
497 print_addr "overload1arg(short)"
498 print_addr "overload1arg(unsigned short)"
499 print_addr "overload1arg(int)"
500 print_addr "overload1arg($dm_type_unsigned_int)"
501 print_addr "overload1arg(long)"
502 print_addr "overload1arg(unsigned long)"
503 print_addr "overload1arg(float)"
504 print_addr "overload1arg(double)"
506 print_addr "overloadargs(int)"
507 print_addr "overloadargs(int, int)"
508 print_addr "overloadargs(int, int, int)"
509 print_addr "overloadargs(int, int, int, int)"
510 print_addr "overloadargs(int, int, int, int, int)"
511 print_addr "overloadargs(int, int, int, int, int, int)"
512 print_addr "overloadargs(int, int, int, int, int, int, int)"
513 print_addr "overloadargs(int, int, int, int, int, int, int, int)"
514 print_addr "overloadargs(int, int, int, int, int, int, int, int, int)"
515 print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int)"
516 print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int, int)"
519 proc test_paddr_hairy_functions {} {
522 global dm_type_char_star
523 global dm_type_int_star
524 global dm_type_long_star
526 print_addr_2 "hairyfunc1" "hairyfunc1(int)"
527 print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
528 print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
529 print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
531 # gdb-gnats bug gdb/19:
532 # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
533 print_addr_2_kfail "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
534 print_addr_2_kfail "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
535 print_addr_2_kfail "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
546 global dm_type_int_star
551 # Start with a fresh gdb.
555 gdb_reinitialize_dir $srcdir/$subdir
558 send_gdb "set language c++\n"
559 gdb_expect -re "$gdb_prompt $"
560 send_gdb "set width 0\n"
561 gdb_expect -re "$gdb_prompt $"
566 test_paddr_overloaded_functions
567 test_paddr_operator_functions
568 test_paddr_hairy_functions
569 test_lookup_operator_functions
571 # A regression test on errors involving operators
572 gdb_test "list foo::operator $dm_type_int_star" \
573 ".*the class foo does not have any method named operator $dm_type_int_star.*"