aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.cp/cplusfuncs.exp
blob: 96b57caccf21c52465bdbf31eb59a3d2af2b9eb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
# Copyright 1992, 1997, 1999, 2001, 2002, 2003, 2004, 2007, 2008, 2009, 2010
# Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file was written by Fred Fish. (fnf@cygnus.com)
# Adapted for g++ 3.0 ABI by Michael Chastain. (chastain@redhat.com)

if $tracelevel then {
	strace $tracelevel
}

if { [skip_cplus_tests] } { continue }

set testfile "cplusfuncs"
set srcfile ${testfile}.cc
set binfile ${objdir}/${subdir}/${testfile}

if { [get_compiler_info $binfile "c++"] } {
    return -1
}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
     untested cplusfuncs.exp
     return -1
}

#
# g++ changed its ABI between 2.95 and 3.0.  gdb has two demanglers
# for the two different styles.  The two demanglers have some subtle
# discrepancies in their output.
#
#   old demangler         new demangler
#   --- ---------         --- ---------
#   "operator, "          "operator,"
#   "char *"              "char*"
#   "int *"               "int*"
#   "long *"              "long*"
#   "void *"              "void*"
#   "foo &"               "foo&"
#   "unsigned int"        "unsigned"
#   "void"                ""
#
# I probe for the forms in use.
# The defaults are for the v3 demangler (as of 2001-02-13).
#

set dm_operator_comma		","
set dm_type_char_star		"char*"
set dm_type_char_star_quoted    "char\\*"
set dm_type_foo_ref 		"foo&"
set dm_type_int_star		"int*"
set dm_type_long_star		"long*"
set dm_type_unsigned_int	"unsigned"
set dm_type_void		"void"
set dm_type_void_star		"void*"

# Some other vagaries of GDB's type printing machinery.  The integer types
# may have unsigned before or after their length, and may have "int"
# appended.  The char* conversion operator may have name "char*" even if
# the type is "char *", because the name comes from the debug information
# and the type from GDB.  Function types may not see through typedefs.

set dm_type_short		"short"
set dm_type_long		"long"
set dm_type_unsigned_short	"unsigned short"
set dm_type_unsigned_long	"unsigned long"
set dm_operator_char_star	"char*"
set dm_operator_char_star_quoted	"char\\*"
set dm_type_typedef		0

proc probe_demangler { } {
    global gdb_prompt
    global dm_operator_comma
    global dm_operator_char_star
    global dm_operator_char_star_quoted
    global dm_type_char_star
    global dm_type_char_star_quoted
    global dm_type_foo_ref
    global dm_type_int_star
    global dm_type_long_star
    global dm_type_unsigned_int
    global dm_type_void
    global dm_type_void_star
    global dm_type_short
    global dm_type_unsigned_short
    global dm_type_long
    global dm_type_unsigned_long
    global dm_type_typedef

    send_gdb "print &foo::operator,(foo&)\n"
    gdb_expect {
	-re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
	    # v2 demangler
	    set dm_operator_comma ", "
	    pass "detect dm_operator_comma"
	}
	-re ".*foo::operator,\\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
	    # v3 demangler
	    pass "detect dm_operator_comma"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_operator_comma"
	}
	timeout {
	    fail "detect dm_operator_comma"
	}
    }

    send_gdb "print &foo::operator char*($dm_type_void)\n"
    gdb_expect {
	-re ".*foo::operator char \\*\\(void\\).*\r\n$gdb_prompt $" {
	    # v2 demangler or GDB type printer
	    set dm_operator_char_star "char *"
	    set dm_operator_char_star_quoted "char \\*"
	    pass "detect dm_operator_char_star"
	}
	-re ".*foo::operator char\\*\\(\\).*\r\n$gdb_prompt $" {
	    # v3 demangler
	    pass "detect dm_operator_char_star"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_operator_char_star"
	}
	timeout {
	    fail "detect dm_operator_char_star"
	}
    }

    send_gdb "print &dm_type_char_star\n"
    gdb_expect {
	-re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
	    # v2 demangler
	    set dm_type_char_star "char *"
	    set dm_type_char_star_quoted "char \\*"
	    pass "detect dm_type_char_star"
	}
	-re ".*dm_type_char_star\\(char\\*\\).*\r\n$gdb_prompt $" {
	    # v3 demangler
	    pass "detect dm_type_char_star"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_char_star"
	}
	timeout {
	    fail "detect dm_type_char_star (timeout)"
	}
    }

    send_gdb "print &dm_type_foo_ref\n"
    gdb_expect {
	-re ".*dm_type_foo_ref\\(foo &\\).*\r\n$gdb_prompt $" {
	    # v2 demangler
	    set dm_type_foo_ref "foo &"
	    pass "detect dm_type_foo_ref"
	}
	-re ".*dm_type_foo_ref\\(foo&\\).*\r\n$gdb_prompt $" {
	    # v3 demangler
	    pass "detect dm_type_foo_ref"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_foo_ref"
	}
	timeout {
	    fail "detect dm_type_foo_ref (timeout)"
	}
    }

    send_gdb "print &dm_type_int_star\n"
    gdb_expect {
	-re ".*dm_type_int_star\\(int \\*\\).*\r\n$gdb_prompt $" {
	    # v2 demangler
	    set dm_type_int_star "int *"
	    pass "detect dm_type_int_star"
	}
	-re ".*dm_type_int_star\\(int\\*\\).*\r\n$gdb_prompt $" {
	    # v3 demangler
	    pass "detect dm_type_int_star"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_int_star"
	}
	timeout {
	    fail "detect dm_type_int_star (timeout)"
	}
    }

    send_gdb "print &dm_type_long_star\n"
    gdb_expect {
	-re ".*dm_type_long_star\\(long \\*\\).*\r\n$gdb_prompt $" {
	    # v2 demangler
	    set dm_type_long_star "long *"
	    pass "detect dm_type_long_star"
	}
	-re ".*dm_type_long_star\\(long\\*\\).*\r\n$gdb_prompt $" {
	    # v3 demangler
	    pass "detect dm_type_long_star"
	}
	-re ".*dm_type_long_star\\(long int \\*\\).*\r\n$gdb_prompt $" {
	    # GCC v3 and GDB's type printer
	    set dm_type_long_star "long int *"
	    pass "detect dm_type_long_star"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_long_star"
	}
	timeout {
	    fail "detect dm_type_long_star (timeout)"
	}
    }

    send_gdb "print &dm_type_unsigned_int\n"
    gdb_expect {
	-re ".*dm_type_unsigned_int\\(unsigned int\\).*\r\n$gdb_prompt $" {
	    # v2 demangler
	    set dm_type_unsigned_int "unsigned int"
	    pass "detect dm_type_unsigned_int"
	}
	-re ".*dm_type_unsigned_int\\(unsigned\\).*\r\n$gdb_prompt $" {
	    # v3 demangler
	    pass "detect dm_type_unsigned_int"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_unsigned_int"
	}
	timeout {
	    fail "detect dm_unsigned int (timeout)"
	}
    }

    send_gdb "print &dm_type_void\n"
    gdb_expect {
	-re ".*dm_type_void\\(void\\).*\r\n$gdb_prompt $" {
	    # v2 demangler
	    set dm_type_void "void"
	    pass "detect dm_type_void"
	}
	-re ".*dm_type_void\\(\\).*\r\n$gdb_prompt $" {
	    # v3 demangler
	    pass "detect dm_type_void"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_void"
	}
	timeout {
	    fail "detect dm_type_void (timeout)"
	}
    }

    send_gdb "print &dm_type_void_star\n"
    gdb_expect {
	-re ".*dm_type_void_star\\(void \\*\\).*\r\n$gdb_prompt $" {
	    # v2 demangler
	    set dm_type_void_star "void *"
	    pass "detect dm_type_void_star"
	}
	-re ".*dm_type_void_star\\(void\\*\\).*\r\n$gdb_prompt $" {
	    # v3 demangler
	    pass "detect dm_type_void_star"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_void_star"
	}
	timeout {
	    fail "detect dm_type_void_star (timeout)"
	}
    }

    send_gdb "print &dm_type_short\n"
    gdb_expect {
	-re ".*dm_type_short\\(short\\).*\r\n$gdb_prompt $" {
	    # v2 and v3 demanglers
	    pass "detect dm_type_short"
	}
	-re ".*dm_type_short\\(short int\\).*\r\n$gdb_prompt $" {
	    # GDB type printer
	    set dm_type_short "short int"
	    pass "detect dm_type_short"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_short"
	}
	timeout {
	    fail "detect dm_type_short (timeout)"
	}
    }

    send_gdb "print &dm_type_unsigned_short\n"
    gdb_expect {
	-re ".*dm_type_unsigned_short\\(unsigned short\\).*\r\n$gdb_prompt $" {
	    # v2 and v3 demanglers
	    pass "detect dm_type_unsigned_short"
	}
	-re ".*dm_type_unsigned_short\\(short unsigned int\\).*\r\n$gdb_prompt $" {
	    # GDB type printer
	    set dm_type_unsigned_short "short unsigned int"
	    pass "detect dm_type_unsigned_short"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_unsigned_short"
	}
	timeout {
	    fail "detect dm_type_unsigned_short (timeout)"
	}
    }

    send_gdb "print &dm_type_long\n"
    gdb_expect {
	-re ".*dm_type_long\\(long\\).*\r\n$gdb_prompt $" {
	    # v2 and v3 demanglers
	    pass "detect dm_type_long"
	}
	-re ".*dm_type_long\\(long int\\).*\r\n$gdb_prompt $" {
	    # GDB type printer
	    set dm_type_long "long int"
	    pass "detect dm_type_long"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_long"
	}
	timeout {
	    fail "detect dm_type_long (timeout)"
	}
    }

    send_gdb "print &dm_type_unsigned_long\n"
    gdb_expect {
	-re ".*dm_type_unsigned_long\\(unsigned long\\).*\r\n$gdb_prompt $" {
	    # v2 and v3 demanglers
	    pass "detect dm_type_unsigned_long"
	}
	-re ".*dm_type_unsigned_long\\(long unsigned int\\).*\r\n$gdb_prompt $" {
	    # GDB type printer
	    set dm_type_unsigned_long "long unsigned int"
	    pass "detect dm_type_unsigned_long"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_unsigned_long"
	}
	timeout {
	    fail "detect dm_type_unsigned_long (timeout)"
	}
    }

    send_gdb "print &dm_type_typedef\n"
    gdb_expect {
	-re ".*dm_type_typedef\\(int\\).*\r\n$gdb_prompt $" {
	    # v2 and v3 demanglers
	    pass "detect dm_type_typedef"
	}
	-re ".*dm_type_typedef\\(myint\\).*\r\n$gdb_prompt $" {
	    # GDB type printer
	    set dm_type_typedef 1
	    pass "detect dm_type_typedef"
	}
	-re ".*$gdb_prompt $" {
	    fail "detect dm_type_typedef"
	}
	timeout {
	    fail "detect dm_type_typedef (timeout)"
	}
    }
}

#
#  Lookup a specific C++ function and print the demangled type.
#  This form accepts the demangled type as a regexp.
#

proc info_func_regexp { name demangled } {
    global gdb_prompt

    send_gdb "info function $name\n"
    regsub {\\\(void\\\)} $demangled {\(\)} demangled
    gdb_expect {
	-re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
	    pass "info function for \"$name\""
	}
	-re ".*$gdb_prompt $" {
	    fail "info function for \"$name\""
	}
	timeout {
	    fail "info function for \"$name\" (timeout)"
	}
    }
}

#
#  Lookup a specific C++ function and print the demangled type.
#  This form accepts the demangled type as a literal string.
#

proc info_func { name demangled } {
    info_func_regexp "$name" [string_to_regexp "$demangled"]
}

#
# Print the address of a function.
# This checks that I can lookup a fully qualified C++ function.
# This also checks the argument types on the return string.

# Note: carlton/2003-01-16: If you modify this, make a corresponding
# modification to print_addr_2_kfail.

proc print_addr_2 { name good } {
    global gdb_prompt
    global hex

    set good_pattern [string_to_regexp $good]

    send_gdb "print &$name\n"
    gdb_expect {
	-re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
	    pass "print &$name"
	}
	-re ".*$gdb_prompt $" {
	    fail "print &$name"
	}
	timeout {
	    fail "print &$name (timeout)"
	}
    }
}

# NOTE: carlton/2003-01-16: hairyfunc5-6 fail on GCC 3.x (for at least
# x=1 and x=2.1).  So I'm modifying print_addr_2 to accept a failure
# condition.  FIXME: It would be nice if the failure condition were
# conditional on the compiler version, but I'm not sufficiently
# motivated.  I did hardwire in the versions of char * and int *,
# which will give some compiler-specificity to the failure.

proc print_addr_2_kfail { name good bad bugid } {
    global gdb_prompt
    global hex

    set good_pattern [string_to_regexp $good]
    set bad_pattern [string_to_regexp $bad]

    send_gdb "print &$name\n"
    gdb_expect {
	-re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
	    pass "print &$name"
	}
	-re ".* = .* $hex <$bad_pattern>\r\n$gdb_prompt $" {
	    kfail $bugid "print &$name"
	}
	-re ".*$gdb_prompt $" {
	    fail "print &$name"
	}
	timeout {
	    fail "print &$name (timeout)"
	}
    }
}

#
#  Simple interfaces to print_addr_2.
#

proc print_addr { name } {
    regsub {\(void\)} $name {()} expected
    if {[string first "::" $name] == -1} {
	# C function -- must be qutoed
	set name "'$name'"
    }
    print_addr_2 "$name" $expected
}

#
# Test name demangling for operators.
#
# The '(' at the end of each regex input pattern is so that we match only
# the one we are looking for.  I.E. "operator&" would match both
# "operator&(foo &)" and "operator&&(foo &)".
#
# gdb-gnats bug gdb/18:
#  "gdb can't parse "info func operator*" or "info func operator\*".
#  The star in "operator*" is interpreted as a regexp, but the "\*"
#  in  "operator\*" is not a legal operator.
#

proc test_lookup_operator_functions {} {
    global dm_operator_comma
    global dm_operator_char_star
    global dm_type_char_star
    global dm_operator_char_star_quoted
    global dm_type_foo_ref
    global dm_type_void
    global dm_type_void_star

    # operator* requires quoting so that GDB does not treat it as a regexp.
    info_func "operator\\*("	"void foo::operator*($dm_type_foo_ref);"
    info_func "operator%("	"void foo::operator%($dm_type_foo_ref);"
    info_func "operator-("	"void foo::operator-($dm_type_foo_ref);"
    info_func "operator>>("	"void foo::operator>>($dm_type_foo_ref);"
    info_func "operator!=("	"void foo::operator!=($dm_type_foo_ref);"
    info_func "operator>("	"void foo::operator>($dm_type_foo_ref);"
    info_func "operator>=("	"void foo::operator>=($dm_type_foo_ref);"
    info_func "operator|("	"void foo::operator|($dm_type_foo_ref);"
    info_func "operator&&("	"void foo::operator&&($dm_type_foo_ref);"
    info_func "operator!("	"void foo::operator!($dm_type_void);"
    info_func "operator++("	"void foo::operator++(int);"
    info_func "operator=("	"void foo::operator=($dm_type_foo_ref);"
    info_func "operator+=("	"void foo::operator+=($dm_type_foo_ref);"
    # operator*= requires quoting so that GDB does not treat it as a regexp.
    info_func "operator\\*=("	"void foo::operator*=($dm_type_foo_ref);"
    info_func "operator%=("	"void foo::operator%=($dm_type_foo_ref);"
    info_func "operator>>=("	"void foo::operator>>=($dm_type_foo_ref);"
    info_func "operator|=("	"void foo::operator|=($dm_type_foo_ref);"
    info_func "operator$dm_operator_comma\("	\
    				"void foo::operator$dm_operator_comma\($dm_type_foo_ref);"
    info_func "operator/("	"void foo::operator/($dm_type_foo_ref);"
    info_func "operator+("	"void foo::operator+($dm_type_foo_ref);"
    info_func "operator<<("	"void foo::operator<<($dm_type_foo_ref);"
    info_func "operator==("	"void foo::operator==($dm_type_foo_ref);"
    info_func "operator<("	"void foo::operator<($dm_type_foo_ref);"
    info_func "operator<=("	"void foo::operator<=($dm_type_foo_ref);"
    info_func "operator&("	"void foo::operator&($dm_type_foo_ref);"
    info_func "operator^("	"void foo::operator^($dm_type_foo_ref);"
    info_func "operator||("	"void foo::operator||($dm_type_foo_ref);"
    info_func "operator~("	"void foo::operator~($dm_type_void);"
    info_func "operator--("	"void foo::operator--(int);"
    info_func "operator->("	"foo *foo::operator->($dm_type_void);"
    info_func "operator-=("	"void foo::operator-=($dm_type_foo_ref);"
    info_func "operator/=("	"void foo::operator/=($dm_type_foo_ref);"
    info_func "operator<<=("	"void foo::operator<<=($dm_type_foo_ref);"
    info_func "operator&=("	"void foo::operator&=($dm_type_foo_ref);"
    info_func "operator^=("	"void foo::operator^=($dm_type_foo_ref);"
    # operator->* requires quoting so that GDB does not treat it as a regexp.
    info_func "operator->\\*("	"void foo::operator->*($dm_type_foo_ref);"

    # operator[] needs double backslashes, so that a single backslash
    # will be sent to GDB, preventing the square brackets from being
    # evaluated as a regular expression. 
    info_func "operator\\\[\\\](" "void foo::operator\[\]($dm_type_foo_ref);"

    # These are gnarly because they might end with 'static'.
    set dm_type_void_star_regexp [string_to_regexp $dm_type_void_star]
    info_func_regexp "operator new("     "void \\*foo::operator new\\(.*\\)(| static);"
    info_func_regexp "operator delete("  "void foo::operator delete\\($dm_type_void_star_regexp\\)(| static);"

    info_func "operator int("	"int foo::operator int($dm_type_void);"
    info_func "operator()("	"void foo::operator()($dm_type_foo_ref);"
    info_func "operator $dm_operator_char_star_quoted\(" \
				"char *foo::operator $dm_operator_char_star\($dm_type_void);"

}


proc test_paddr_operator_functions {} {
    global hex
    global hp_aCC_compiler
    global dm_operator_comma
    global dm_type_char_star
    global dm_type_foo_ref
    global dm_type_long_star
    global dm_type_unsigned_int
    global dm_type_void
    global dm_type_void_star
    global dm_operator_char_star

    print_addr "foo::operator*($dm_type_foo_ref)"
    print_addr "foo::operator%($dm_type_foo_ref)"
    print_addr "foo::operator-($dm_type_foo_ref)"
    print_addr "foo::operator>>($dm_type_foo_ref)"
    print_addr "foo::operator!=($dm_type_foo_ref)"
    print_addr "foo::operator>($dm_type_foo_ref)"
    print_addr "foo::operator>=($dm_type_foo_ref)"
    print_addr "foo::operator|($dm_type_foo_ref)"
    print_addr "foo::operator&&($dm_type_foo_ref)"
    print_addr "foo::operator!($dm_type_void)"
    print_addr "foo::operator++(int)"
    print_addr "foo::operator=($dm_type_foo_ref)"
    print_addr "foo::operator+=($dm_type_foo_ref)"
    print_addr "foo::operator*=($dm_type_foo_ref)"
    print_addr "foo::operator%=($dm_type_foo_ref)"
    print_addr "foo::operator>>=($dm_type_foo_ref)"
    print_addr "foo::operator|=($dm_type_foo_ref)"
    print_addr "foo::operator$dm_operator_comma\($dm_type_foo_ref)"
    print_addr "foo::operator/($dm_type_foo_ref)"
    print_addr "foo::operator+($dm_type_foo_ref)"
    print_addr "foo::operator<<($dm_type_foo_ref)"
    print_addr "foo::operator==($dm_type_foo_ref)"
    print_addr "foo::operator<($dm_type_foo_ref)"
    print_addr "foo::operator<=($dm_type_foo_ref)"
    print_addr "foo::operator&($dm_type_foo_ref)"
    print_addr "foo::operator^($dm_type_foo_ref)"
    print_addr "foo::operator||($dm_type_foo_ref)"
    print_addr "foo::operator~($dm_type_void)"
    print_addr "foo::operator--(int)"
    print_addr "foo::operator->($dm_type_void)"
    print_addr "foo::operator-=($dm_type_foo_ref)"
    print_addr "foo::operator/=($dm_type_foo_ref)"
    print_addr "foo::operator<<=($dm_type_foo_ref)"
    print_addr "foo::operator&=($dm_type_foo_ref)"
    print_addr "foo::operator^=($dm_type_foo_ref)"
    print_addr "foo::operator->*($dm_type_foo_ref)"
    print_addr "foo::operator\[\]($dm_type_foo_ref)"
    print_addr "foo::operator()($dm_type_foo_ref)"

    gdb_test "print &foo::operator new" \
	" = .* $hex <foo::operator new\\(.*\\)(| static)>"
    gdb_test "print &foo::operator new\[\]" \
	" = .* $hex <foo::operator new\\\[\\\]\\(.*\\)(| static)>"    
    if { !$hp_aCC_compiler } {
	print_addr "foo::operator delete($dm_type_void_star)"
	print_addr "foo::operator delete[]($dm_type_void_star)"
    } else {
	gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
	    " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
    }

    print_addr "foo::operator int($dm_type_void)"
    print_addr "foo::operator $dm_operator_char_star\($dm_type_void)"
}

#
# Test overloaded functions (1 arg).
#

proc test_paddr_overloaded_functions {} {
    global dm_type_unsigned_int
    global dm_type_void
    global dm_type_short
    global dm_type_unsigned_short
    global dm_type_long
    global dm_type_unsigned_long

    print_addr "overload1arg($dm_type_void)"
    print_addr "overload1arg(char)"
    print_addr "overload1arg(signed char)"
    print_addr "overload1arg(unsigned char)"
    print_addr "overload1arg($dm_type_short)"
    print_addr "overload1arg($dm_type_unsigned_short)"
    print_addr "overload1arg(int)"
    print_addr "overload1arg($dm_type_unsigned_int)"
    print_addr "overload1arg($dm_type_long)"
    print_addr "overload1arg($dm_type_unsigned_long)"
    print_addr "overload1arg(float)"
    print_addr "overload1arg(double)"

    print_addr "overloadargs(int)"
    print_addr "overloadargs(int, int)"
    print_addr "overloadargs(int, int, int)"
    print_addr "overloadargs(int, int, int, int)"
    print_addr "overloadargs(int, int, int, int, int)"
    print_addr "overloadargs(int, int, int, int, int, int)"
    print_addr "overloadargs(int, int, int, int, int, int, int)"
    print_addr "overloadargs(int, int, int, int, int, int, int, int)"
    print_addr "overloadargs(int, int, int, int, int, int, int, int, int)"
    print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int)"
    print_addr "overloadargs(int, int, int, int, int, int, int, int, int, int, int)"
}

proc test_paddr_hairy_functions {} {
    global gdb_prompt
    global hex
    global dm_type_char_star
    global dm_type_int_star
    global dm_type_long_star
    global dm_type_typedef

    print_addr_2 "hairyfunc1" "hairyfunc1(int)"

    if {$dm_type_typedef == 0} {
	print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
	print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
	print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"

	# gdb-gnats bug gdb/19:
	# "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
	print_addr_2_kfail "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
	print_addr_2_kfail "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
	print_addr_2_kfail "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
    } else {
	print_addr_2 "hairyfunc2" "hairyfunc2(PFPc_i)"
	print_addr_2 "hairyfunc3" "hairyfunc3(PFPFPl_s_i)"
	print_addr_2 "hairyfunc4" "hairyfunc4(PFPFPc_s_i)"

	# gdb-gnats bug gdb/19:
	# "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
	print_addr_2 "hairyfunc5" "hairyfunc5(PFPc_PFl_i)"
	print_addr_2 "hairyfunc6" "hairyfunc6(PFPi_PFl_i)"
	print_addr_2 "hairyfunc7" "hairyfunc7(PFPFPc_i_PFl_i)"
    }
}

proc do_tests {} {
    global subdir
    global objdir
    global srcdir
    global binfile
    global gdb_prompt
    global dm_type_int_star


    # Start with a fresh gdb.

    gdb_exit
    gdb_start
    gdb_reinitialize_dir $srcdir/$subdir
    gdb_load $binfile

    send_gdb "set language c++\n"
    gdb_expect -re "$gdb_prompt $"
    send_gdb "set width 0\n"
    gdb_expect -re "$gdb_prompt $"

    runto_main

    probe_demangler
    test_paddr_overloaded_functions
    test_paddr_operator_functions
    test_paddr_hairy_functions
    test_lookup_operator_functions

    # A regression test on errors involving operators
    gdb_test "list foo::operator $dm_type_int_star" \
	".*the class foo does not have any method named operator $dm_type_int_star.*"
}

do_tests