/:
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / cplusfuncs.exp
CommitLineData
4c38e0a4 1# Copyright 1992, 1997, 1999, 2001, 2002, 2003, 2004, 2007, 2008, 2009, 2010
6e19e2bf 2# Free Software Foundation, Inc.
c906108c
SS
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c 17# This file was written by Fred Fish. (fnf@cygnus.com)
99f78f56 18# Adapted for g++ 3.0 ABI by Michael Chastain. (chastain@redhat.com)
c906108c
SS
19
20if $tracelevel then {
21 strace $tracelevel
22}
23
d4f3574e 24if { [skip_cplus_tests] } { continue }
c906108c
SS
25
26set testfile "cplusfuncs"
27set srcfile ${testfile}.cc
28set binfile ${objdir}/${subdir}/${testfile}
c906108c 29
d4f3574e 30if { [get_compiler_info $binfile "c++"] } {
a0b3c4fd
JM
31 return -1
32}
33
d4f3574e 34if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
35 untested cplusfuncs.exp
36 return -1
d4f3574e
SS
37}
38
c906108c 39#
99f78f56
MC
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.
43#
44# old demangler new demangler
45# --- --------- --- ---------
46# "operator, " "operator,"
47# "char *" "char*"
48# "int *" "int*"
49# "long *" "long*"
50# "void *" "void*"
51# "foo &" "foo&"
52# "unsigned int" "unsigned"
53# "void" ""
54#
55# I probe for the forms in use.
56# The defaults are for the v3 demangler (as of 2001-02-13).
c906108c
SS
57#
58
99f78f56
MC
59set dm_operator_comma ","
60set dm_type_char_star "char*"
3f08ced9 61set dm_type_char_star_quoted "char\\*"
99f78f56
MC
62set dm_type_foo_ref "foo&"
63set dm_type_int_star "int*"
64set dm_type_long_star "long*"
65set dm_type_unsigned_int "unsigned"
a4216f37 66set dm_type_void "void"
99f78f56
MC
67set dm_type_void_star "void*"
68
cec808ec
KS
69# Some other vagaries of GDB's type printing machinery. The integer types
70# may have unsigned before or after their length, and may have "int"
71# appended. The char* conversion operator may have name "char*" even if
72# the type is "char *", because the name comes from the debug information
73# and the type from GDB. Function types may not see through typedefs.
74
75set dm_type_short "short"
76set dm_type_long "long"
77set dm_type_unsigned_short "unsigned short"
78set dm_type_unsigned_long "unsigned long"
79set dm_operator_char_star "char*"
80set dm_operator_char_star_quoted "char\\*"
81set dm_type_typedef 0
82
99f78f56 83proc probe_demangler { } {
c906108c 84 global gdb_prompt
99f78f56 85 global dm_operator_comma
cec808ec
KS
86 global dm_operator_char_star
87 global dm_operator_char_star_quoted
99f78f56 88 global dm_type_char_star
3f08ced9 89 global dm_type_char_star_quoted
99f78f56
MC
90 global dm_type_foo_ref
91 global dm_type_int_star
92 global dm_type_long_star
93 global dm_type_unsigned_int
94 global dm_type_void
95 global dm_type_void_star
cec808ec
KS
96 global dm_type_short
97 global dm_type_unsigned_short
98 global dm_type_long
99 global dm_type_unsigned_long
100 global dm_type_typedef
99f78f56 101
a4216f37 102 send_gdb "print &foo::operator,(foo&)\n"
99f78f56
MC
103 gdb_expect {
104 -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
105 # v2 demangler
106 set dm_operator_comma ", "
107 pass "detect dm_operator_comma"
108 }
109 -re ".*foo::operator,\\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
110 # v3 demangler
111 pass "detect dm_operator_comma"
112 }
113 -re ".*$gdb_prompt $" {
114 fail "detect dm_operator_comma"
115 }
116 timeout {
117 fail "detect dm_operator_comma"
118 }
119 }
120
cec808ec
KS
121 send_gdb "print &foo::operator char*($dm_type_void)\n"
122 gdb_expect {
123 -re ".*foo::operator char \\*\\(void\\).*\r\n$gdb_prompt $" {
124 # v2 demangler or GDB type printer
125 set dm_operator_char_star "char *"
126 set dm_operator_char_star_quoted "char \\*"
127 pass "detect dm_operator_char_star"
128 }
129 -re ".*foo::operator char\\*\\(\\).*\r\n$gdb_prompt $" {
130 # v3 demangler
131 pass "detect dm_operator_char_star"
132 }
133 -re ".*$gdb_prompt $" {
134 fail "detect dm_operator_char_star"
135 }
136 timeout {
137 fail "detect dm_operator_char_star"
138 }
139 }
140
a4216f37 141 send_gdb "print &dm_type_char_star\n"
99f78f56
MC
142 gdb_expect {
143 -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
144 # v2 demangler
145 set dm_type_char_star "char *"
3f08ced9 146 set dm_type_char_star_quoted "char \\*"
99f78f56
MC
147 pass "detect dm_type_char_star"
148 }
149 -re ".*dm_type_char_star\\(char\\*\\).*\r\n$gdb_prompt $" {
150 # v3 demangler
151 pass "detect dm_type_char_star"
152 }
153 -re ".*$gdb_prompt $" {
154 fail "detect dm_type_char_star"
155 }
156 timeout {
157 fail "detect dm_type_char_star (timeout)"
158 }
159 }
160
a4216f37 161 send_gdb "print &dm_type_foo_ref\n"
99f78f56
MC
162 gdb_expect {
163 -re ".*dm_type_foo_ref\\(foo &\\).*\r\n$gdb_prompt $" {
164 # v2 demangler
165 set dm_type_foo_ref "foo &"
166 pass "detect dm_type_foo_ref"
167 }
168 -re ".*dm_type_foo_ref\\(foo&\\).*\r\n$gdb_prompt $" {
169 # v3 demangler
170 pass "detect dm_type_foo_ref"
171 }
172 -re ".*$gdb_prompt $" {
173 fail "detect dm_type_foo_ref"
174 }
175 timeout {
176 fail "detect dm_type_foo_ref (timeout)"
177 }
178 }
179
a4216f37 180 send_gdb "print &dm_type_int_star\n"
99f78f56
MC
181 gdb_expect {
182 -re ".*dm_type_int_star\\(int \\*\\).*\r\n$gdb_prompt $" {
183 # v2 demangler
184 set dm_type_int_star "int *"
185 pass "detect dm_type_int_star"
186 }
187 -re ".*dm_type_int_star\\(int\\*\\).*\r\n$gdb_prompt $" {
188 # v3 demangler
189 pass "detect dm_type_int_star"
190 }
191 -re ".*$gdb_prompt $" {
192 fail "detect dm_type_int_star"
193 }
194 timeout {
195 fail "detect dm_type_int_star (timeout)"
196 }
197 }
198
a4216f37 199 send_gdb "print &dm_type_long_star\n"
99f78f56
MC
200 gdb_expect {
201 -re ".*dm_type_long_star\\(long \\*\\).*\r\n$gdb_prompt $" {
202 # v2 demangler
203 set dm_type_long_star "long *"
204 pass "detect dm_type_long_star"
205 }
206 -re ".*dm_type_long_star\\(long\\*\\).*\r\n$gdb_prompt $" {
207 # v3 demangler
208 pass "detect dm_type_long_star"
209 }
cec808ec
KS
210 -re ".*dm_type_long_star\\(long int \\*\\).*\r\n$gdb_prompt $" {
211 # GCC v3 and GDB's type printer
212 set dm_type_long_star "long int *"
213 pass "detect dm_type_long_star"
214 }
99f78f56
MC
215 -re ".*$gdb_prompt $" {
216 fail "detect dm_type_long_star"
217 }
218 timeout {
219 fail "detect dm_type_long_star (timeout)"
220 }
221 }
222
a4216f37 223 send_gdb "print &dm_type_unsigned_int\n"
99f78f56
MC
224 gdb_expect {
225 -re ".*dm_type_unsigned_int\\(unsigned int\\).*\r\n$gdb_prompt $" {
226 # v2 demangler
227 set dm_type_unsigned_int "unsigned int"
228 pass "detect dm_type_unsigned_int"
229 }
230 -re ".*dm_type_unsigned_int\\(unsigned\\).*\r\n$gdb_prompt $" {
231 # v3 demangler
232 pass "detect dm_type_unsigned_int"
233 }
234 -re ".*$gdb_prompt $" {
235 fail "detect dm_type_unsigned_int"
236 }
237 timeout {
238 fail "detect dm_unsigned int (timeout)"
239 }
240 }
c906108c 241
a4216f37 242 send_gdb "print &dm_type_void\n"
c906108c 243 gdb_expect {
99f78f56
MC
244 -re ".*dm_type_void\\(void\\).*\r\n$gdb_prompt $" {
245 # v2 demangler
246 set dm_type_void "void"
247 pass "detect dm_type_void"
248 }
249 -re ".*dm_type_void\\(\\).*\r\n$gdb_prompt $" {
250 # v3 demangler
251 pass "detect dm_type_void"
a0b3c4fd 252 }
99f78f56
MC
253 -re ".*$gdb_prompt $" {
254 fail "detect dm_type_void"
255 }
256 timeout {
257 fail "detect dm_type_void (timeout)"
258 }
259 }
260
a4216f37 261 send_gdb "print &dm_type_void_star\n"
99f78f56
MC
262 gdb_expect {
263 -re ".*dm_type_void_star\\(void \\*\\).*\r\n$gdb_prompt $" {
264 # v2 demangler
265 set dm_type_void_star "void *"
266 pass "detect dm_type_void_star"
267 }
268 -re ".*dm_type_void_star\\(void\\*\\).*\r\n$gdb_prompt $" {
269 # v3 demangler
270 pass "detect dm_type_void_star"
271 }
272 -re ".*$gdb_prompt $" {
273 fail "detect dm_type_void_star"
274 }
275 timeout {
276 fail "detect dm_type_void_star (timeout)"
277 }
278 }
cec808ec
KS
279
280 send_gdb "print &dm_type_short\n"
281 gdb_expect {
282 -re ".*dm_type_short\\(short\\).*\r\n$gdb_prompt $" {
283 # v2 and v3 demanglers
284 pass "detect dm_type_short"
285 }
286 -re ".*dm_type_short\\(short int\\).*\r\n$gdb_prompt $" {
287 # GDB type printer
288 set dm_type_short "short int"
289 pass "detect dm_type_short"
290 }
291 -re ".*$gdb_prompt $" {
292 fail "detect dm_type_short"
293 }
294 timeout {
295 fail "detect dm_type_short (timeout)"
296 }
297 }
298
299 send_gdb "print &dm_type_unsigned_short\n"
300 gdb_expect {
301 -re ".*dm_type_unsigned_short\\(unsigned short\\).*\r\n$gdb_prompt $" {
302 # v2 and v3 demanglers
303 pass "detect dm_type_unsigned_short"
304 }
305 -re ".*dm_type_unsigned_short\\(short unsigned int\\).*\r\n$gdb_prompt $" {
306 # GDB type printer
307 set dm_type_unsigned_short "short unsigned int"
308 pass "detect dm_type_unsigned_short"
309 }
310 -re ".*$gdb_prompt $" {
311 fail "detect dm_type_unsigned_short"
312 }
313 timeout {
314 fail "detect dm_type_unsigned_short (timeout)"
315 }
316 }
317
318 send_gdb "print &dm_type_long\n"
319 gdb_expect {
320 -re ".*dm_type_long\\(long\\).*\r\n$gdb_prompt $" {
321 # v2 and v3 demanglers
322 pass "detect dm_type_long"
323 }
324 -re ".*dm_type_long\\(long int\\).*\r\n$gdb_prompt $" {
325 # GDB type printer
326 set dm_type_long "long int"
327 pass "detect dm_type_long"
328 }
329 -re ".*$gdb_prompt $" {
330 fail "detect dm_type_long"
331 }
332 timeout {
333 fail "detect dm_type_long (timeout)"
334 }
335 }
336
337 send_gdb "print &dm_type_unsigned_long\n"
338 gdb_expect {
339 -re ".*dm_type_unsigned_long\\(unsigned long\\).*\r\n$gdb_prompt $" {
340 # v2 and v3 demanglers
341 pass "detect dm_type_unsigned_long"
342 }
343 -re ".*dm_type_unsigned_long\\(long unsigned int\\).*\r\n$gdb_prompt $" {
344 # GDB type printer
345 set dm_type_unsigned_long "long unsigned int"
346 pass "detect dm_type_unsigned_long"
347 }
348 -re ".*$gdb_prompt $" {
349 fail "detect dm_type_unsigned_long"
350 }
351 timeout {
352 fail "detect dm_type_unsigned_long (timeout)"
353 }
354 }
355
356 send_gdb "print &dm_type_typedef\n"
357 gdb_expect {
358 -re ".*dm_type_typedef\\(int\\).*\r\n$gdb_prompt $" {
359 # v2 and v3 demanglers
360 pass "detect dm_type_typedef"
361 }
362 -re ".*dm_type_typedef\\(myint\\).*\r\n$gdb_prompt $" {
363 # GDB type printer
364 set dm_type_typedef 1
365 pass "detect dm_type_typedef"
366 }
367 -re ".*$gdb_prompt $" {
368 fail "detect dm_type_typedef"
369 }
370 timeout {
371 fail "detect dm_type_typedef (timeout)"
372 }
373 }
99f78f56
MC
374}
375
376#
377# Lookup a specific C++ function and print the demangled type.
378# This form accepts the demangled type as a regexp.
379#
380
381proc info_func_regexp { name demangled } {
382 global gdb_prompt
383
384 send_gdb "info function $name\n"
8c2fb5de 385 regsub {\\\(void\\\)} $demangled {\(\)} demangled
99f78f56
MC
386 gdb_expect {
387 -re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
388 pass "info function for \"$name\""
c906108c
SS
389 }
390 -re ".*$gdb_prompt $" {
99f78f56 391 fail "info function for \"$name\""
c906108c
SS
392 }
393 timeout {
99f78f56 394 fail "info function for \"$name\" (timeout)"
c906108c
SS
395 }
396 }
397}
398
399#
99f78f56
MC
400# Lookup a specific C++ function and print the demangled type.
401# This form accepts the demangled type as a literal string.
c906108c
SS
402#
403
99f78f56
MC
404proc info_func { name demangled } {
405 info_func_regexp "$name" [string_to_regexp "$demangled"]
406}
407
408#
409# Print the address of a function.
410# This checks that I can lookup a fully qualified C++ function.
411# This also checks the argument types on the return string.
d2b29e01
DC
412
413# Note: carlton/2003-01-16: If you modify this, make a corresponding
414# modification to print_addr_2_kfail.
99f78f56
MC
415
416proc print_addr_2 { name good } {
c906108c
SS
417 global gdb_prompt
418 global hex
419
99f78f56
MC
420 set good_pattern [string_to_regexp $good]
421
a4216f37 422 send_gdb "print &$name\n"
c906108c 423 gdb_expect {
99f78f56 424 -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
a4216f37 425 pass "print &$name"
99f78f56 426 }
c906108c 427 -re ".*$gdb_prompt $" {
a4216f37 428 fail "print &$name"
c906108c
SS
429 }
430 timeout {
a4216f37 431 fail "print &$name (timeout)"
c906108c
SS
432 }
433 }
434}
435
d2b29e01
DC
436# NOTE: carlton/2003-01-16: hairyfunc5-6 fail on GCC 3.x (for at least
437# x=1 and x=2.1). So I'm modifying print_addr_2 to accept a failure
438# condition. FIXME: It would be nice if the failure condition were
439# conditional on the compiler version, but I'm not sufficiently
440# motivated. I did hardwire in the versions of char * and int *,
441# which will give some compiler-specificity to the failure.
442
443proc print_addr_2_kfail { name good bad bugid } {
444 global gdb_prompt
445 global hex
446
447 set good_pattern [string_to_regexp $good]
448 set bad_pattern [string_to_regexp $bad]
449
a4216f37 450 send_gdb "print &$name\n"
d2b29e01
DC
451 gdb_expect {
452 -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
a4216f37 453 pass "print &$name"
d2b29e01
DC
454 }
455 -re ".* = .* $hex <$bad_pattern>\r\n$gdb_prompt $" {
a4216f37 456 kfail $bugid "print &$name"
d2b29e01
DC
457 }
458 -re ".*$gdb_prompt $" {
a4216f37 459 fail "print &$name"
d2b29e01
DC
460 }
461 timeout {
a4216f37 462 fail "print &$name (timeout)"
d2b29e01
DC
463 }
464 }
465}
466
99f78f56
MC
467#
468# Simple interfaces to print_addr_2.
469#
470
471proc print_addr { name } {
8c2fb5de 472 regsub {\(void\)} $name {()} expected
a4216f37
KS
473 if {[string first "::" $name] == -1} {
474 # C function -- must be qutoed
475 set name "'$name'"
476 }
477 print_addr_2 "$name" $expected
99f78f56
MC
478}
479
c906108c
SS
480#
481# Test name demangling for operators.
482#
483# The '(' at the end of each regex input pattern is so that we match only
484# the one we are looking for. I.E. "operator&" would match both
485# "operator&(foo &)" and "operator&&(foo &)".
486#
99f78f56
MC
487# gdb-gnats bug gdb/18:
488# "gdb can't parse "info func operator*" or "info func operator\*".
489# The star in "operator*" is interpreted as a regexp, but the "\*"
490# in "operator\*" is not a legal operator.
491#
c906108c
SS
492
493proc test_lookup_operator_functions {} {
99f78f56 494 global dm_operator_comma
cec808ec 495 global dm_operator_char_star
99f78f56 496 global dm_type_char_star
cec808ec 497 global dm_operator_char_star_quoted
99f78f56
MC
498 global dm_type_foo_ref
499 global dm_type_void
500 global dm_type_void_star
c906108c 501
3f08ced9
MS
502 # operator* requires quoting so that GDB does not treat it as a regexp.
503 info_func "operator\\*(" "void foo::operator*($dm_type_foo_ref);"
99f78f56
MC
504 info_func "operator%(" "void foo::operator%($dm_type_foo_ref);"
505 info_func "operator-(" "void foo::operator-($dm_type_foo_ref);"
506 info_func "operator>>(" "void foo::operator>>($dm_type_foo_ref);"
507 info_func "operator!=(" "void foo::operator!=($dm_type_foo_ref);"
508 info_func "operator>(" "void foo::operator>($dm_type_foo_ref);"
509 info_func "operator>=(" "void foo::operator>=($dm_type_foo_ref);"
510 info_func "operator|(" "void foo::operator|($dm_type_foo_ref);"
511 info_func "operator&&(" "void foo::operator&&($dm_type_foo_ref);"
512 info_func "operator!(" "void foo::operator!($dm_type_void);"
513 info_func "operator++(" "void foo::operator++(int);"
514 info_func "operator=(" "void foo::operator=($dm_type_foo_ref);"
515 info_func "operator+=(" "void foo::operator+=($dm_type_foo_ref);"
3f08ced9
MS
516 # operator*= requires quoting so that GDB does not treat it as a regexp.
517 info_func "operator\\*=(" "void foo::operator*=($dm_type_foo_ref);"
99f78f56
MC
518 info_func "operator%=(" "void foo::operator%=($dm_type_foo_ref);"
519 info_func "operator>>=(" "void foo::operator>>=($dm_type_foo_ref);"
520 info_func "operator|=(" "void foo::operator|=($dm_type_foo_ref);"
521 info_func "operator$dm_operator_comma\(" \
522 "void foo::operator$dm_operator_comma\($dm_type_foo_ref);"
523 info_func "operator/(" "void foo::operator/($dm_type_foo_ref);"
524 info_func "operator+(" "void foo::operator+($dm_type_foo_ref);"
525 info_func "operator<<(" "void foo::operator<<($dm_type_foo_ref);"
526 info_func "operator==(" "void foo::operator==($dm_type_foo_ref);"
527 info_func "operator<(" "void foo::operator<($dm_type_foo_ref);"
528 info_func "operator<=(" "void foo::operator<=($dm_type_foo_ref);"
529 info_func "operator&(" "void foo::operator&($dm_type_foo_ref);"
530 info_func "operator^(" "void foo::operator^($dm_type_foo_ref);"
531 info_func "operator||(" "void foo::operator||($dm_type_foo_ref);"
532 info_func "operator~(" "void foo::operator~($dm_type_void);"
533 info_func "operator--(" "void foo::operator--(int);"
534 info_func "operator->(" "foo *foo::operator->($dm_type_void);"
535 info_func "operator-=(" "void foo::operator-=($dm_type_foo_ref);"
536 info_func "operator/=(" "void foo::operator/=($dm_type_foo_ref);"
537 info_func "operator<<=(" "void foo::operator<<=($dm_type_foo_ref);"
538 info_func "operator&=(" "void foo::operator&=($dm_type_foo_ref);"
539 info_func "operator^=(" "void foo::operator^=($dm_type_foo_ref);"
3f08ced9
MS
540 # operator->* requires quoting so that GDB does not treat it as a regexp.
541 info_func "operator->\\*(" "void foo::operator->*($dm_type_foo_ref);"
99f78f56 542
3f08ced9
MS
543 # operator[] needs double backslashes, so that a single backslash
544 # will be sent to GDB, preventing the square brackets from being
545 # evaluated as a regular expression.
546 info_func "operator\\\[\\\](" "void foo::operator\[\]($dm_type_foo_ref);"
99f78f56
MC
547
548 # These are gnarly because they might end with 'static'.
549 set dm_type_void_star_regexp [string_to_regexp $dm_type_void_star]
550 info_func_regexp "operator new(" "void \\*foo::operator new\\(.*\\)(| static);"
551 info_func_regexp "operator delete(" "void foo::operator delete\\($dm_type_void_star_regexp\\)(| static);"
552
553 info_func "operator int(" "int foo::operator int($dm_type_void);"
554 info_func "operator()(" "void foo::operator()($dm_type_foo_ref);"
cec808ec
KS
555 info_func "operator $dm_operator_char_star_quoted\(" \
556 "char *foo::operator $dm_operator_char_star\($dm_type_void);"
99f78f56 557
c906108c
SS
558}
559
560
561proc test_paddr_operator_functions {} {
562 global hex
a0b3c4fd 563 global hp_aCC_compiler
99f78f56
MC
564 global dm_operator_comma
565 global dm_type_char_star
566 global dm_type_foo_ref
567 global dm_type_long_star
568 global dm_type_unsigned_int
569 global dm_type_void
570 global dm_type_void_star
cec808ec 571 global dm_operator_char_star
99f78f56
MC
572
573 print_addr "foo::operator*($dm_type_foo_ref)"
574 print_addr "foo::operator%($dm_type_foo_ref)"
575 print_addr "foo::operator-($dm_type_foo_ref)"
576 print_addr "foo::operator>>($dm_type_foo_ref)"
577 print_addr "foo::operator!=($dm_type_foo_ref)"
578 print_addr "foo::operator>($dm_type_foo_ref)"
579 print_addr "foo::operator>=($dm_type_foo_ref)"
580 print_addr "foo::operator|($dm_type_foo_ref)"
581 print_addr "foo::operator&&($dm_type_foo_ref)"
582 print_addr "foo::operator!($dm_type_void)"
583 print_addr "foo::operator++(int)"
584 print_addr "foo::operator=($dm_type_foo_ref)"
585 print_addr "foo::operator+=($dm_type_foo_ref)"
586 print_addr "foo::operator*=($dm_type_foo_ref)"
587 print_addr "foo::operator%=($dm_type_foo_ref)"
588 print_addr "foo::operator>>=($dm_type_foo_ref)"
589 print_addr "foo::operator|=($dm_type_foo_ref)"
590 print_addr "foo::operator$dm_operator_comma\($dm_type_foo_ref)"
591 print_addr "foo::operator/($dm_type_foo_ref)"
592 print_addr "foo::operator+($dm_type_foo_ref)"
593 print_addr "foo::operator<<($dm_type_foo_ref)"
594 print_addr "foo::operator==($dm_type_foo_ref)"
595 print_addr "foo::operator<($dm_type_foo_ref)"
596 print_addr "foo::operator<=($dm_type_foo_ref)"
597 print_addr "foo::operator&($dm_type_foo_ref)"
598 print_addr "foo::operator^($dm_type_foo_ref)"
599 print_addr "foo::operator||($dm_type_foo_ref)"
600 print_addr "foo::operator~($dm_type_void)"
601 print_addr "foo::operator--(int)"
602 print_addr "foo::operator->($dm_type_void)"
603 print_addr "foo::operator-=($dm_type_foo_ref)"
604 print_addr "foo::operator/=($dm_type_foo_ref)"
605 print_addr "foo::operator<<=($dm_type_foo_ref)"
606 print_addr "foo::operator&=($dm_type_foo_ref)"
607 print_addr "foo::operator^=($dm_type_foo_ref)"
608 print_addr "foo::operator->*($dm_type_foo_ref)"
609 print_addr "foo::operator\[\]($dm_type_foo_ref)"
610 print_addr "foo::operator()($dm_type_foo_ref)"
c906108c 611
a4216f37 612 gdb_test "print &foo::operator new" \
99f78f56 613 " = .* $hex <foo::operator new\\(.*\\)(| static)>"
a4216f37
KS
614 gdb_test "print &foo::operator new\[\]" \
615 " = .* $hex <foo::operator new\\\[\\\]\\(.*\\)(| static)>"
a0b3c4fd 616 if { !$hp_aCC_compiler } {
99f78f56 617 print_addr "foo::operator delete($dm_type_void_star)"
a4216f37 618 print_addr "foo::operator delete[]($dm_type_void_star)"
a0b3c4fd 619 } else {
99f78f56 620 gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
a0b3c4fd
JM
621 " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
622 }
99f78f56
MC
623
624 print_addr "foo::operator int($dm_type_void)"
cec808ec 625 print_addr "foo::operator $dm_operator_char_star\($dm_type_void)"
c906108c
SS
626}
627
628#
629# Test overloaded functions (1 arg).
630#
631
632proc test_paddr_overloaded_functions {} {
99f78f56
MC
633 global dm_type_unsigned_int
634 global dm_type_void
cec808ec
KS
635 global dm_type_short
636 global dm_type_unsigned_short
637 global dm_type_long
638 global dm_type_unsigned_long
99f78f56
MC
639
640 print_addr "overload1arg($dm_type_void)"
641 print_addr "overload1arg(char)"
642 print_addr "overload1arg(signed char)"
643 print_addr "overload1arg(unsigned char)"
cec808ec
KS
644 print_addr "overload1arg($dm_type_short)"
645 print_addr "overload1arg($dm_type_unsigned_short)"
99f78f56
MC
646 print_addr "overload1arg(int)"
647 print_addr "overload1arg($dm_type_unsigned_int)"
cec808ec
KS
648 print_addr "overload1arg($dm_type_long)"
649 print_addr "overload1arg($dm_type_unsigned_long)"
99f78f56
MC
650 print_addr "overload1arg(float)"
651 print_addr "overload1arg(double)"
652
653 print_addr "overloadargs(int)"
654 print_addr "overloadargs(int, int)"
655 print_addr "overloadargs(int, int, int)"
656 print_addr "overloadargs(int, int, int, int)"
657 print_addr "overloadargs(int, int, int, int, int)"
658 print_addr "overloadargs(int, int, int, int, int, int)"
659 print_addr "overloadargs(int, int, int, int, int, int, int)"
660 print_addr "overloadargs(int, int, int, int, int, int, int, int)"
661 print_addr "overloadargs(int, int, int, int, int, int, int, int, int)"
662 print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int)"
663 print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int, int)"
c906108c
SS
664}
665
666proc test_paddr_hairy_functions {} {
99f78f56
MC
667 global gdb_prompt
668 global hex
669 global dm_type_char_star
670 global dm_type_int_star
671 global dm_type_long_star
cec808ec 672 global dm_type_typedef
99f78f56
MC
673
674 print_addr_2 "hairyfunc1" "hairyfunc1(int)"
cec808ec
KS
675
676 if {$dm_type_typedef == 0} {
677 print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
678 print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
679 print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
680
681 # gdb-gnats bug gdb/19:
682 # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
683 print_addr_2_kfail "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
684 print_addr_2_kfail "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
685 print_addr_2_kfail "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
686 } else {
687 print_addr_2 "hairyfunc2" "hairyfunc2(PFPc_i)"
688 print_addr_2 "hairyfunc3" "hairyfunc3(PFPFPl_s_i)"
689 print_addr_2 "hairyfunc4" "hairyfunc4(PFPFPc_s_i)"
690
691 # gdb-gnats bug gdb/19:
692 # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
693 print_addr_2 "hairyfunc5" "hairyfunc5(PFPc_PFl_i)"
694 print_addr_2 "hairyfunc6" "hairyfunc6(PFPi_PFl_i)"
695 print_addr_2 "hairyfunc7" "hairyfunc7(PFPFPc_i_PFl_i)"
696 }
c906108c
SS
697}
698
699proc do_tests {} {
c906108c
SS
700 global subdir
701 global objdir
702 global srcdir
703 global binfile
704 global gdb_prompt
11ef0d76 705 global dm_type_int_star
c906108c 706
c906108c
SS
707
708 # Start with a fresh gdb.
709
710 gdb_exit
711 gdb_start
712 gdb_reinitialize_dir $srcdir/$subdir
713 gdb_load $binfile
714
715 send_gdb "set language c++\n"
716 gdb_expect -re "$gdb_prompt $"
717 send_gdb "set width 0\n"
718 gdb_expect -re "$gdb_prompt $"
719
40f235b7 720 runto_main
c906108c 721
99f78f56 722 probe_demangler
c906108c
SS
723 test_paddr_overloaded_functions
724 test_paddr_operator_functions
725 test_paddr_hairy_functions
726 test_lookup_operator_functions
11ef0d76
KS
727
728 # A regression test on errors involving operators
729 gdb_test "list foo::operator $dm_type_int_star" \
730 ".*the class foo does not have any method named operator $dm_type_int_star.*"
c906108c
SS
731}
732
733do_tests
This page took 0.974878 seconds and 4 git commands to generate.