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_foo_ref "foo&"
64 set dm_type_int_star "int*"
65 set dm_type_long_star "long*"
66 set dm_type_unsigned_int "unsigned"
68 set dm_type_void_star "void*"
70 proc probe_demangler { } {
72 global dm_operator_comma
73 global dm_type_char_star
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 pass "detect dm_type_char_star"
107 -re ".*dm_type_char_star\\(char\\*\\).*\r\n$gdb_prompt $" {
109 pass "detect dm_type_char_star"
111 -re ".*$gdb_prompt $" {
112 fail "detect dm_type_char_star"
115 fail "detect dm_type_char_star (timeout)"
119 send_gdb "print &'dm_type_foo_ref'\n"
121 -re ".*dm_type_foo_ref\\(foo &\\).*\r\n$gdb_prompt $" {
123 set dm_type_foo_ref "foo &"
124 pass "detect dm_type_foo_ref"
126 -re ".*dm_type_foo_ref\\(foo&\\).*\r\n$gdb_prompt $" {
128 pass "detect dm_type_foo_ref"
130 -re ".*$gdb_prompt $" {
131 fail "detect dm_type_foo_ref"
134 fail "detect dm_type_foo_ref (timeout)"
138 send_gdb "print &'dm_type_int_star'\n"
140 -re ".*dm_type_int_star\\(int \\*\\).*\r\n$gdb_prompt $" {
142 set dm_type_int_star "int *"
143 pass "detect dm_type_int_star"
145 -re ".*dm_type_int_star\\(int\\*\\).*\r\n$gdb_prompt $" {
147 pass "detect dm_type_int_star"
149 -re ".*$gdb_prompt $" {
150 fail "detect dm_type_int_star"
153 fail "detect dm_type_int_star (timeout)"
157 send_gdb "print &'dm_type_long_star'\n"
159 -re ".*dm_type_long_star\\(long \\*\\).*\r\n$gdb_prompt $" {
161 set dm_type_long_star "long *"
162 pass "detect dm_type_long_star"
164 -re ".*dm_type_long_star\\(long\\*\\).*\r\n$gdb_prompt $" {
166 pass "detect dm_type_long_star"
168 -re ".*$gdb_prompt $" {
169 fail "detect dm_type_long_star"
172 fail "detect dm_type_long_star (timeout)"
176 send_gdb "print &'dm_type_unsigned_int'\n"
178 -re ".*dm_type_unsigned_int\\(unsigned int\\).*\r\n$gdb_prompt $" {
180 set dm_type_unsigned_int "unsigned int"
181 pass "detect dm_type_unsigned_int"
183 -re ".*dm_type_unsigned_int\\(unsigned\\).*\r\n$gdb_prompt $" {
185 pass "detect dm_type_unsigned_int"
187 -re ".*$gdb_prompt $" {
188 fail "detect dm_type_unsigned_int"
191 fail "detect dm_unsigned int (timeout)"
195 send_gdb "print &'dm_type_void'\n"
197 -re ".*dm_type_void\\(void\\).*\r\n$gdb_prompt $" {
199 set dm_type_void "void"
200 pass "detect dm_type_void"
202 -re ".*dm_type_void\\(\\).*\r\n$gdb_prompt $" {
204 pass "detect dm_type_void"
206 -re ".*$gdb_prompt $" {
207 fail "detect dm_type_void"
210 fail "detect dm_type_void (timeout)"
214 send_gdb "print &'dm_type_void_star'\n"
216 -re ".*dm_type_void_star\\(void \\*\\).*\r\n$gdb_prompt $" {
218 set dm_type_void_star "void *"
219 pass "detect dm_type_void_star"
221 -re ".*dm_type_void_star\\(void\\*\\).*\r\n$gdb_prompt $" {
223 pass "detect dm_type_void_star"
225 -re ".*$gdb_prompt $" {
226 fail "detect dm_type_void_star"
229 fail "detect dm_type_void_star (timeout)"
235 # Lookup a specific C++ function and print the demangled type.
236 # This form accepts the demangled type as a regexp.
239 proc info_func_regexp { name demangled } {
242 send_gdb "info function $name\n"
244 -re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
245 pass "info function for \"$name\""
247 -re ".*$gdb_prompt $" {
248 fail "info function for \"$name\""
251 fail "info function for \"$name\" (timeout)"
257 # Lookup a specific C++ function and print the demangled type.
258 # This form accepts the demangled type as a literal string.
261 proc info_func { name demangled } {
262 info_func_regexp "$name" [string_to_regexp "$demangled"]
266 # Print the address of a function.
267 # This checks that I can lookup a fully qualified C++ function.
268 # This also checks the argument types on the return string.
271 proc print_addr_2 { name good } {
275 set good_pattern [string_to_regexp $good]
277 send_gdb "print &'$name'\n"
279 -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
280 pass "print &'$name'"
282 -re ".*$gdb_prompt $" {
283 fail "print &'$name'"
286 fail "print &'$name' (timeout)"
292 # Simple interfaces to print_addr_2.
295 proc print_addr { name } {
296 print_addr_2 "$name" "$name"
300 # Test name demangling for operators.
302 # The '(' at the end of each regex input pattern is so that we match only
303 # the one we are looking for. I.E. "operator&" would match both
304 # "operator&(foo &)" and "operator&&(foo &)".
306 # gdb-gnats bug gdb/18:
307 # "gdb can't parse "info func operator*" or "info func operator\*".
308 # The star in "operator*" is interpreted as a regexp, but the "\*"
309 # in "operator\*" is not a legal operator.
312 proc test_lookup_operator_functions {} {
313 global dm_operator_comma
314 global dm_type_char_star
315 global dm_type_foo_ref
317 global dm_type_void_star
319 # These tests don't work for COFF targets; don't even try them
320 if [istarget "a29k-*-udi"] then {
321 setup_xfail "a29k-*-udi"
322 fail "skipping operator tests"
326 info_func "operator*(" "void foo::operator*($dm_type_foo_ref);"
327 info_func "operator%(" "void foo::operator%($dm_type_foo_ref);"
328 info_func "operator-(" "void foo::operator-($dm_type_foo_ref);"
329 info_func "operator>>(" "void foo::operator>>($dm_type_foo_ref);"
330 info_func "operator!=(" "void foo::operator!=($dm_type_foo_ref);"
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_void);"
336 info_func "operator++(" "void foo::operator++(int);"
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_foo_ref);"
341 info_func "operator>>=(" "void foo::operator>>=($dm_type_foo_ref);"
342 info_func "operator|=(" "void foo::operator|=($dm_type_foo_ref);"
343 info_func "operator$dm_operator_comma\(" \
344 "void foo::operator$dm_operator_comma\($dm_type_foo_ref);"
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<(" "void foo::operator<($dm_type_foo_ref);"
350 info_func "operator<=(" "void foo::operator<=($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_void);"
355 info_func "operator--(" "void foo::operator--(int);"
356 info_func "operator->(" "foo *foo::operator->($dm_type_void);"
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_foo_ref);"
361 info_func "operator^=(" "void foo::operator^=($dm_type_foo_ref);"
362 info_func "operator->*(" "void foo::operator->*($dm_type_foo_ref);"
364 # operator[] needs backslashes to protect against TCL evaluation.
365 info_func "operator\[\](" "void foo::operator\[\]($dm_type_foo_ref);"
367 # These are gnarly because they might end with 'static'.
368 set dm_type_void_star_regexp [string_to_regexp $dm_type_void_star]
369 info_func_regexp "operator new(" "void \\*foo::operator new\\(.*\\)(| static);"
370 info_func_regexp "operator delete(" "void foo::operator delete\\($dm_type_void_star_regexp\\)(| static);"
372 info_func "operator int(" "int foo::operator int($dm_type_void);"
373 info_func "operator()(" "void foo::operator()($dm_type_foo_ref);"
374 info_func "operator $dm_type_char_star\(" \
375 "char *foo::operator $dm_type_char_star\($dm_type_void);"
380 proc test_paddr_operator_functions {} {
382 global hp_aCC_compiler
383 global dm_operator_comma
384 global dm_type_char_star
385 global dm_type_foo_ref
386 global dm_type_long_star
387 global dm_type_unsigned_int
389 global dm_type_void_star
391 print_addr "foo::operator*($dm_type_foo_ref)"
392 print_addr "foo::operator%($dm_type_foo_ref)"
393 print_addr "foo::operator-($dm_type_foo_ref)"
394 print_addr "foo::operator>>($dm_type_foo_ref)"
395 print_addr "foo::operator!=($dm_type_foo_ref)"
396 print_addr "foo::operator>($dm_type_foo_ref)"
397 print_addr "foo::operator>=($dm_type_foo_ref)"
398 print_addr "foo::operator|($dm_type_foo_ref)"
399 print_addr "foo::operator&&($dm_type_foo_ref)"
400 print_addr "foo::operator!($dm_type_void)"
401 print_addr "foo::operator++(int)"
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_operator_comma\($dm_type_foo_ref)"
409 print_addr "foo::operator/($dm_type_foo_ref)"
410 print_addr "foo::operator+($dm_type_foo_ref)"
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_type_foo_ref)"
418 print_addr "foo::operator~($dm_type_void)"
419 print_addr "foo::operator--(int)"
420 print_addr "foo::operator->($dm_type_void)"
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_foo_ref)"
428 print_addr "foo::operator()($dm_type_foo_ref)"
430 gdb_test "print &'foo::operator new'" \
431 " = .* $hex <foo::operator new\\(.*\\)(| static)>"
432 if { !$hp_aCC_compiler } {
433 print_addr "foo::operator delete($dm_type_void_star)"
435 gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
436 " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
439 print_addr "foo::operator int($dm_type_void)"
440 print_addr "foo::operator $dm_type_char_star\($dm_type_void)"
444 # Test overloaded functions (1 arg).
447 proc test_paddr_overloaded_functions {} {
448 global dm_type_unsigned_int
451 print_addr "overload1arg($dm_type_void)"
452 print_addr "overload1arg(char)"
453 print_addr "overload1arg(signed char)"
454 print_addr "overload1arg(unsigned char)"
455 print_addr "overload1arg(short)"
456 print_addr "overload1arg(unsigned short)"
457 print_addr "overload1arg(int)"
458 print_addr "overload1arg($dm_type_unsigned_int)"
459 print_addr "overload1arg(long)"
460 print_addr "overload1arg(unsigned long)"
461 print_addr "overload1arg(float)"
462 print_addr "overload1arg(double)"
464 print_addr "overloadargs(int)"
465 print_addr "overloadargs(int, int)"
466 print_addr "overloadargs(int, int, int)"
467 print_addr "overloadargs(int, int, int, int)"
468 print_addr "overloadargs(int, int, int, int, int)"
469 print_addr "overloadargs(int, int, int, int, int, int)"
470 print_addr "overloadargs(int, int, int, int, int, int, int)"
471 print_addr "overloadargs(int, int, int, int, int, int, int, int)"
472 print_addr "overloadargs(int, int, int, int, int, int, int, int, int)"
473 print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int)"
474 print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int, int)"
477 proc test_paddr_hairy_functions {} {
480 global dm_type_char_star
481 global dm_type_int_star
482 global dm_type_long_star
484 print_addr_2 "hairyfunc1" "hairyfunc1(int)"
485 print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
486 print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
487 print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
489 # gdb-gnats bug gdb/19:
490 # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
491 print_addr_2 "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))"
492 print_addr_2 "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))"
493 print_addr_2 "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))"
508 # Start with a fresh gdb.
512 gdb_reinitialize_dir $srcdir/$subdir
515 send_gdb "set language c++\n"
516 gdb_expect -re "$gdb_prompt $"
517 send_gdb "set width 0\n"
518 gdb_expect -re "$gdb_prompt $"
520 # Get the debug format for the compiled test case. If that
521 # format is DWARF 1 then just skip all the tests since none of
524 if [ runto_main] then {
526 if [ setup_xfail_format "DWARF 1" ] then {
527 fail "C++ tests skipped due to limited C++ support in DWARF 1 debug format"
534 test_paddr_overloaded_functions
535 test_paddr_operator_functions
536 test_paddr_hairy_functions
537 test_lookup_operator_functions