OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [testsuite/] [gdb.c++/] [cplusfuncs.exp] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Copyright (C) 1992, 1997, 1999, 2001 Free Software Foundation, Inc.
2
 
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.
7
#
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.
12
#
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.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-gdb@prep.ai.mit.edu
19
 
20
# This file was written by Fred Fish. (fnf@cygnus.com)
21
# Adapted for g++ 3.0 ABI by Michael Chastain. (chastain@redhat.com)
22
 
23
if $tracelevel then {
24
        strace $tracelevel
25
}
26
 
27
if { [skip_cplus_tests] } { continue }
28
 
29
set testfile "cplusfuncs"
30
set srcfile ${testfile}.cc
31
set binfile ${objdir}/${subdir}/${testfile}
32
 
33
if { [get_compiler_info $binfile "c++"] } {
34
    return -1
35
}
36
 
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."
39
}
40
 
41
#
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.
45
#
46
#   old demangler         new demangler
47
#   --- ---------         --- ---------
48
#   "operator, "          "operator,"
49
#   "char *"              "char*"
50
#   "int *"               "int*"
51
#   "long *"              "long*"
52
#   "void *"              "void*"
53
#   "foo &"               "foo&"
54
#   "unsigned int"        "unsigned"
55
#   "void"                ""
56
#
57
# I probe for the forms in use.
58
# The defaults are for the v3 demangler (as of 2001-02-13).
59
#
60
 
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"
67
set dm_type_void                ""
68
set dm_type_void_star           "void*"
69
 
70
proc probe_demangler { } {
71
    global gdb_prompt
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
78
    global dm_type_void
79
    global dm_type_void_star
80
 
81
    send_gdb "print &'foo::operator,(foo&)'\n"
82
    gdb_expect {
83
        -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
84
            # v2 demangler
85
            set dm_operator_comma ", "
86
            pass "detect dm_operator_comma"
87
        }
88
        -re ".*foo::operator,\\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
89
            # v3 demangler
90
            pass "detect dm_operator_comma"
91
        }
92
        -re ".*$gdb_prompt $" {
93
            fail "detect dm_operator_comma"
94
        }
95
        timeout {
96
            fail "detect dm_operator_comma"
97
        }
98
    }
99
 
100
    send_gdb "print &'dm_type_char_star'\n"
101
    gdb_expect {
102
        -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
103
            # v2 demangler
104
            set dm_type_char_star "char *"
105
            pass "detect dm_type_char_star"
106
        }
107
        -re ".*dm_type_char_star\\(char\\*\\).*\r\n$gdb_prompt $" {
108
            # v3 demangler
109
            pass "detect dm_type_char_star"
110
        }
111
        -re ".*$gdb_prompt $" {
112
            fail "detect dm_type_char_star"
113
        }
114
        timeout {
115
            fail "detect dm_type_char_star (timeout)"
116
        }
117
    }
118
 
119
    send_gdb "print &'dm_type_foo_ref'\n"
120
    gdb_expect {
121
        -re ".*dm_type_foo_ref\\(foo &\\).*\r\n$gdb_prompt $" {
122
            # v2 demangler
123
            set dm_type_foo_ref "foo &"
124
            pass "detect dm_type_foo_ref"
125
        }
126
        -re ".*dm_type_foo_ref\\(foo&\\).*\r\n$gdb_prompt $" {
127
            # v3 demangler
128
            pass "detect dm_type_foo_ref"
129
        }
130
        -re ".*$gdb_prompt $" {
131
            fail "detect dm_type_foo_ref"
132
        }
133
        timeout {
134
            fail "detect dm_type_foo_ref (timeout)"
135
        }
136
    }
137
 
138
    send_gdb "print &'dm_type_int_star'\n"
139
    gdb_expect {
140
        -re ".*dm_type_int_star\\(int \\*\\).*\r\n$gdb_prompt $" {
141
            # v2 demangler
142
            set dm_type_int_star "int *"
143
            pass "detect dm_type_int_star"
144
        }
145
        -re ".*dm_type_int_star\\(int\\*\\).*\r\n$gdb_prompt $" {
146
            # v3 demangler
147
            pass "detect dm_type_int_star"
148
        }
149
        -re ".*$gdb_prompt $" {
150
            fail "detect dm_type_int_star"
151
        }
152
        timeout {
153
            fail "detect dm_type_int_star (timeout)"
154
        }
155
    }
156
 
157
    send_gdb "print &'dm_type_long_star'\n"
158
    gdb_expect {
159
        -re ".*dm_type_long_star\\(long \\*\\).*\r\n$gdb_prompt $" {
160
            # v2 demangler
161
            set dm_type_long_star "long *"
162
            pass "detect dm_type_long_star"
163
        }
164
        -re ".*dm_type_long_star\\(long\\*\\).*\r\n$gdb_prompt $" {
165
            # v3 demangler
166
            pass "detect dm_type_long_star"
167
        }
168
        -re ".*$gdb_prompt $" {
169
            fail "detect dm_type_long_star"
170
        }
171
        timeout {
172
            fail "detect dm_type_long_star (timeout)"
173
        }
174
    }
175
 
176
    send_gdb "print &'dm_type_unsigned_int'\n"
177
    gdb_expect {
178
        -re ".*dm_type_unsigned_int\\(unsigned int\\).*\r\n$gdb_prompt $" {
179
            # v2 demangler
180
            set dm_type_unsigned_int "unsigned int"
181
            pass "detect dm_type_unsigned_int"
182
        }
183
        -re ".*dm_type_unsigned_int\\(unsigned\\).*\r\n$gdb_prompt $" {
184
            # v3 demangler
185
            pass "detect dm_type_unsigned_int"
186
        }
187
        -re ".*$gdb_prompt $" {
188
            fail "detect dm_type_unsigned_int"
189
        }
190
        timeout {
191
            fail "detect dm_unsigned int (timeout)"
192
        }
193
    }
194
 
195
    send_gdb "print &'dm_type_void'\n"
196
    gdb_expect {
197
        -re ".*dm_type_void\\(void\\).*\r\n$gdb_prompt $" {
198
            # v2 demangler
199
            set dm_type_void "void"
200
            pass "detect dm_type_void"
201
        }
202
        -re ".*dm_type_void\\(\\).*\r\n$gdb_prompt $" {
203
            # v3 demangler
204
            pass "detect dm_type_void"
205
        }
206
        -re ".*$gdb_prompt $" {
207
            fail "detect dm_type_void"
208
        }
209
        timeout {
210
            fail "detect dm_type_void (timeout)"
211
        }
212
    }
213
 
214
    send_gdb "print &'dm_type_void_star'\n"
215
    gdb_expect {
216
        -re ".*dm_type_void_star\\(void \\*\\).*\r\n$gdb_prompt $" {
217
            # v2 demangler
218
            set dm_type_void_star "void *"
219
            pass "detect dm_type_void_star"
220
        }
221
        -re ".*dm_type_void_star\\(void\\*\\).*\r\n$gdb_prompt $" {
222
            # v3 demangler
223
            pass "detect dm_type_void_star"
224
        }
225
        -re ".*$gdb_prompt $" {
226
            fail "detect dm_type_void_star"
227
        }
228
        timeout {
229
            fail "detect dm_type_void_star (timeout)"
230
        }
231
    }
232
}
233
 
234
#
235
#  Lookup a specific C++ function and print the demangled type.
236
#  This form accepts the demangled type as a regexp.
237
#
238
 
239
proc info_func_regexp { name demangled } {
240
    global gdb_prompt
241
 
242
    send_gdb "info function $name\n"
243
    gdb_expect {
244
        -re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
245
            pass "info function for \"$name\""
246
        }
247
        -re ".*$gdb_prompt $" {
248
            fail "info function for \"$name\""
249
        }
250
        timeout {
251
            fail "info function for \"$name\" (timeout)"
252
        }
253
    }
254
}
255
 
256
#
257
#  Lookup a specific C++ function and print the demangled type.
258
#  This form accepts the demangled type as a literal string.
259
#
260
 
261
proc info_func { name demangled } {
262
    info_func_regexp "$name" [string_to_regexp "$demangled"]
263
}
264
 
265
#
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.
269
#
270
 
271
proc print_addr_2 { name good } {
272
    global gdb_prompt
273
    global hex
274
 
275
    set good_pattern [string_to_regexp $good]
276
 
277
    send_gdb "print &'$name'\n"
278
    gdb_expect {
279
        -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
280
            pass "print &'$name'"
281
        }
282
        -re ".*$gdb_prompt $" {
283
            fail "print &'$name'"
284
        }
285
        timeout {
286
            fail "print &'$name' (timeout)"
287
        }
288
    }
289
}
290
 
291
#
292
#  Simple interfaces to print_addr_2.
293
#
294
 
295
proc print_addr { name } {
296
    print_addr_2 "$name" "$name"
297
}
298
 
299
#
300
# Test name demangling for operators.
301
#
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 &)".
305
#
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.
310
#
311
 
312
proc test_lookup_operator_functions {} {
313
    global dm_operator_comma
314
    global dm_type_char_star
315
    global dm_type_foo_ref
316
    global dm_type_void
317
    global dm_type_void_star
318
 
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"
323
        return
324
    }
325
 
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);"
363
 
364
    # operator[] needs backslashes to protect against TCL evaluation.
365
    info_func "operator\[\]("   "void foo::operator\[\]($dm_type_foo_ref);"
366
 
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);"
371
 
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);"
376
 
377
}
378
 
379
 
380
proc test_paddr_operator_functions {} {
381
    global hex
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
388
    global dm_type_void
389
    global dm_type_void_star
390
 
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)"
429
 
430
    gdb_test "print &'foo::operator new'" \
431
        " = .* $hex "
432
    if { !$hp_aCC_compiler } {
433
        print_addr "foo::operator delete($dm_type_void_star)"
434
    } else {
435
        gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
436
            " = .*(0x\[0-9a-f\]+|) "
437
    }
438
 
439
    print_addr "foo::operator int($dm_type_void)"
440
    print_addr "foo::operator $dm_type_char_star\($dm_type_void)"
441
}
442
 
443
#
444
# Test overloaded functions (1 arg).
445
#
446
 
447
proc test_paddr_overloaded_functions {} {
448
    global dm_type_unsigned_int
449
    global dm_type_void
450
 
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)"
463
 
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)"
475
}
476
 
477
proc test_paddr_hairy_functions {} {
478
    global gdb_prompt
479
    global hex
480
    global dm_type_char_star
481
    global dm_type_int_star
482
    global dm_type_long_star
483
 
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)))"
488
 
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))"
494
}
495
 
496
proc do_tests {} {
497
    global prms_id
498
    global bug_id
499
    global subdir
500
    global objdir
501
    global srcdir
502
    global binfile
503
    global gdb_prompt
504
 
505
    set prms_id 0
506
    set bug_id 0
507
 
508
    # Start with a fresh gdb.
509
 
510
    gdb_exit
511
    gdb_start
512
    gdb_reinitialize_dir $srcdir/$subdir
513
    gdb_load $binfile
514
 
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 $"
519
 
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
522
    # them will pass.
523
 
524
    if [ runto_main] then {
525
        get_debug_format
526
        if [ setup_xfail_format "DWARF 1" ] then {
527
            fail "C++ tests skipped due to limited C++ support in DWARF 1 debug format"
528
            return
529
        }
530
        clear_xfail "*-*-*"
531
    }
532
 
533
    probe_demangler
534
    test_paddr_overloaded_functions
535
    test_paddr_operator_functions
536
    test_paddr_hairy_functions
537
    test_lookup_operator_functions
538
}
539
 
540
do_tests

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.