1 # Copyright
1992, 1997, 1999, 2001, 2002, 2003, 2004
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
2 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
, write to the Free Software
16 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
18 # This file was written by Fred Fish.
(fnf@cygnus.com
)
19 # Adapted
for g
++ 3.0 ABI by Michael Chastain.
(chastain@redhat.com
)
25 if { [skip_cplus_tests
] } { continue }
27 set testfile
"cplusfuncs"
28 set srcfile $
{testfile
}.cc
29 set binfile $
{objdir
}/$
{subdir
}/$
{testfile
}
31 if { [get_compiler_info $binfile
"c++"] } {
35 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
36 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
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"
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"
245 -re
".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
246 pass
"info function for \"$name\""
248 -re
".*$gdb_prompt $" {
249 fail
"info function for \"$name\""
252 fail
"info function for \"$name\" (timeout)"
258 # Lookup a specific C
++ function and print the demangled type.
259 # This form accepts the demangled type as a literal string.
262 proc info_func
{ name demangled
} {
263 info_func_regexp
"$name" [string_to_regexp "$demangled"]
267 # Print the address of a function.
268 # This checks that I can lookup a fully qualified C
++ function.
269 # This also checks the
argument types
on the
return string.
271 # Note
: carlton
/2003-01-16: If you modify this
, make a corresponding
272 # modification to print_addr_2_kfail.
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)"
294 # NOTE
: carlton
/2003-01-16: hairyfunc5
-6 fail
on GCC
3.x
(for at least
295 # x
=1 and x
=2.1). So I
'm modifying print_addr_2 to accept a failure
296 # condition. FIXME: It would be nice if the failure condition were
297 # conditional on the compiler version, but I'm not sufficiently
298 # motivated. I did hardwire in the versions of char
* and
int *,
299 # which will give some compiler
-specificity to the failure.
301 proc print_addr_2_kfail
{ name good bad bugid
} {
305 set good_pattern
[string_to_regexp $good
]
306 set bad_pattern
[string_to_regexp $bad
]
308 send_gdb
"print &'$name'\n"
310 -re
".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
311 pass
"print &'$name'"
313 -re
".* = .* $hex <$bad_pattern>\r\n$gdb_prompt $" {
314 kfail $bugid
"print &'$name'"
316 -re
".*$gdb_prompt $" {
317 fail
"print &'$name'"
320 fail
"print &'$name' (timeout)"
326 # Simple interfaces to print_addr_2.
329 proc print_addr
{ name } {
330 print_addr_2
"$name" "$name"
334 # Test
name demangling
for operators.
336 # The
'(' at the end of each regex input pattern is so that we match only
337 # the one we are looking
for. I.E.
"operator&" would match both
338 #
"operator&(foo &)" and "operator&&(foo &)".
340 # gdb
-gnats bug gdb
/18:
341 #
"gdb can't parse "info func operator*" or "info func operator\*".
342 # The star in
"operator*" is interpreted as a regexp, but the "\*"
343 # in
"operator\*" is not a legal operator.
346 proc test_lookup_operator_functions
{} {
347 global dm_operator_comma
348 global dm_type_char_star
349 global dm_type_char_star_quoted
350 global dm_type_foo_ref
352 global dm_type_void_star
354 # operator
* requires quoting so that GDB does not treat it as a regexp.
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_foo_ref);"
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_void);"
365 info_func
"operator++(" "void foo::operator++(int);"
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);"
370 info_func
"operator%=(" "void foo::operator%=($dm_type_foo_ref);"
371 info_func
"operator>>=(" "void foo::operator>>=($dm_type_foo_ref);"
372 info_func
"operator|=(" "void foo::operator|=($dm_type_foo_ref);"
373 info_func
"operator$dm_operator_comma\(" \
374 "void foo::operator$dm_operator_comma\($dm_type_foo_ref);"
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<(" "void foo::operator<($dm_type_foo_ref);"
380 info_func
"operator<=(" "void foo::operator<=($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_void);"
385 info_func
"operator--(" "void foo::operator--(int);"
386 info_func
"operator->(" "foo *foo::operator->($dm_type_void);"
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_foo_ref);"
391 info_func
"operator^=(" "void foo::operator^=($dm_type_foo_ref);"
392 # operator
->* requires quoting so that GDB does not treat it as a regexp.
393 info_func
"operator->\\*(" "void foo::operator->*($dm_type_foo_ref);"
395 # operator
[] needs double backslashes
, so that a single backslash
396 # will be sent to GDB
, preventing the square brackets from being
397 # evaluated as a regular expression.
398 info_func
"operator\\\[\\\](" "void foo::operator\[\]($dm_type_foo_ref);"
400 # These are gnarly because they might end with
'static'.
401 set dm_type_void_star_regexp
[string_to_regexp $dm_type_void_star
]
402 info_func_regexp
"operator new(" "void \\*foo::operator new\\(.*\\)(| static);"
403 info_func_regexp
"operator delete(" "void foo::operator delete\\($dm_type_void_star_regexp\\)(| static);"
405 info_func
"operator int(" "int foo::operator int($dm_type_void);"
406 info_func
"operator()(" "void foo::operator()($dm_type_foo_ref);"
407 info_func
"operator $dm_type_char_star_quoted\(" \
408 "char *foo::operator $dm_type_char_star\($dm_type_void);"
413 proc test_paddr_operator_functions
{} {
415 global hp_aCC_compiler
416 global dm_operator_comma
417 global dm_type_char_star
418 global dm_type_foo_ref
419 global dm_type_long_star
420 global dm_type_unsigned_int
422 global dm_type_void_star
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)"
429 print_addr
"foo::operator>($dm_type_foo_ref)"
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_void)"
434 print_addr
"foo::operator++(int)"
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_foo_ref)"
440 print_addr
"foo::operator|=($dm_type_foo_ref)"
441 print_addr
"foo::operator$dm_operator_comma\($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_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_void)"
452 print_addr
"foo::operator--(int)"
453 print_addr
"foo::operator->($dm_type_void)"
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_foo_ref)"
458 print_addr
"foo::operator^=($dm_type_foo_ref)"
459 print_addr
"foo::operator->*($dm_type_foo_ref)"
460 print_addr
"foo::operator\[\]($dm_type_foo_ref)"
461 print_addr
"foo::operator()($dm_type_foo_ref)"
463 gdb_test
"print &'foo::operator new'" \
464 " = .* $hex <foo::operator new\\(.*\\)(| static)>"
465 if { !$hp_aCC_compiler
} {
466 print_addr
"foo::operator delete($dm_type_void_star)"
468 gdb_test
"print &'foo::operator delete($dm_type_void_star) static'" \
469 " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
472 print_addr
"foo::operator int($dm_type_void)"
473 print_addr
"foo::operator $dm_type_char_star\($dm_type_void)"
477 # Test overloaded functions
(1 arg).
480 proc test_paddr_overloaded_functions
{} {
481 global dm_type_unsigned_int
484 print_addr
"overload1arg($dm_type_void)"
485 print_addr
"overload1arg(char)"
486 print_addr
"overload1arg(signed char)"
487 print_addr
"overload1arg(unsigned char)"
488 print_addr
"overload1arg(short)"
489 print_addr
"overload1arg(unsigned short)"
490 print_addr
"overload1arg(int)"
491 print_addr
"overload1arg($dm_type_unsigned_int)"
492 print_addr
"overload1arg(long)"
493 print_addr
"overload1arg(unsigned long)"
494 print_addr
"overload1arg(float)"
495 print_addr
"overload1arg(double)"
497 print_addr
"overloadargs(int)"
498 print_addr
"overloadargs(int, int)"
499 print_addr
"overloadargs(int, int, int)"
500 print_addr
"overloadargs(int, int, int, int)"
501 print_addr
"overloadargs(int, int, int, int, int)"
502 print_addr
"overloadargs(int, int, int, int, int, int)"
503 print_addr
"overloadargs(int, int, int, int, int, int, int)"
504 print_addr
"overloadargs(int, int, int, int, int, int, int, int)"
505 print_addr
"overloadargs(int, int, int, int, int, int, int, int, int)"
506 print_addr
"overloadargs(int, int, int, int, int, int, int, int, int, int)"
507 print_addr
"overloadargs(int, int, int, int, int, int, int, int, int, int, int)"
510 proc test_paddr_hairy_functions
{} {
513 global dm_type_char_star
514 global dm_type_int_star
515 global dm_type_long_star
517 print_addr_2
"hairyfunc1" "hairyfunc1(int)"
518 print_addr_2
"hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
519 print_addr_2
"hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
520 print_addr_2
"hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
522 # gdb
-gnats bug gdb
/19:
523 #
"gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
524 print_addr_2_kfail
"hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
525 print_addr_2_kfail
"hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
526 print_addr_2_kfail
"hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
541 # Start with a fresh gdb.
545 gdb_reinitialize_dir $srcdir
/$subdir
548 send_gdb
"set language c++\n"
549 gdb_expect
-re
"$gdb_prompt $"
550 send_gdb
"set width 0\n"
551 gdb_expect
-re
"$gdb_prompt $"
556 test_paddr_overloaded_functions
557 test_paddr_operator_functions
558 test_paddr_hairy_functions
559 test_lookup_operator_functions