aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.c++/cplusfuncs.exp
blob: d3783a308ed924e30571a7dacc3ede69b90b1472 (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
# Copyright (C) 1992, 1997, 1999 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

# This file was written by Fred Fish. (fnf@cygnus.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++}] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}

#
#  Cause gdb to lookup a specific C++ function and print the demangled
#  form.
#

proc info_func { regex demangled } {
    global gdb_prompt

    send_gdb "info function $regex\n"
    gdb_expect {
	-re "File .*:\r\n$demangled\r\n.*$gdb_prompt $" {
	    pass "info function for \"$regex\""
	}
	-re "File .*:\r\nclass $demangled\r\n.*$gdb_prompt $" {
	    pass "info function for \"$regex\""
	}
	-re ".*$gdb_prompt $" {
	    fail "info function for \"$regex\""
	}
	timeout {
	    fail "info function for \"$regex\" (timeout)"
	}
    }
}

#
#  Run print &'$arg' on the input arg and verify that we can correctly
#  lookup the fully qualified C++ function.
#  We ignore the return type of the function since we are only interested
#  in the rootname and arguments part.
#

proc print_addr_of { arg } {
    global gdb_prompt
    global hex

    set pattern [string_to_regexp $arg]
    send_gdb "print &'$arg'\n"
    gdb_expect {
	-re ".* = .* $hex <$pattern>\r\n$gdb_prompt $" { pass "print &'$arg'" }
	-re ".*$gdb_prompt $" {
	    fail "print &'$arg'"
	}
	timeout {
	    fail "print &'$arg' (timeout)"
	}
    }
}

#
# 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 &)".
#

proc test_lookup_operator_functions {} {

    # These tests don't work for COFF targets; don't even try them
    if [istarget "a29k-*-udi"] then {
	setup_xfail "a29k-*-udi"
	fail "skipping operator tests"
	return
    }

    info_func "operator&&("  "void foo::operator&&\\(foo &\\);"
    info_func "operator&=("  "void foo::operator&=\\(foo &\\);"
    info_func "operator&("  "void foo::operator&\\(foo &\\);"
    info_func "operator/=("  "void foo::operator/=\\(foo &\\);"
    info_func "operator^=("  "void foo::operator.=\\(foo &\\);"
    info_func "operator<<=("  "void foo::operator<<=\\(foo &\\);"
    info_func "operator%=("  "void foo::operator%=\\(foo &\\);"
    info_func "operator-=("  "void foo::operator-=\\(foo &\\);"

    # There doesn't appear to be any way to get GDB to treat '*' as a
    # character to match, rather than as a regex special character.
    setup_xfail "*-*-*"
    info_func "operator\*=("  "void foo::operator\\*=\\(foo &\\);"

    info_func "operator|=("  "void foo::operator\\|=\\(foo &\\);"
    info_func "operator+=("  "void foo::operator.=\\(foo &\\);"
    info_func "operator>>=("  "void foo::operator\>\>=\\(foo &\\);"
    info_func "operator=("  "void foo::operator=\\(foo &\\);"
    info_func "operator()("  "void foo::operator\\(\\)\\(foo &\\);"

    # The function should be "operator," not "operator, ".  (note space)
    # This test will work; I've commented it out because it should not
    # count as a pass, since it is incorrect.  Ian Taylor.
    # info_func "operator, ("  "void foo::operator, \\(foo &\\);"
    setup_xfail "*-*-*"
    info_func "operator,("  "void foo::operator,\\(foo &\\);"

    info_func "operator~("  "void foo::operator~\\(void\\);"
    info_func "operator delete("  "void foo::operator delete\\(void \\*\\)(| static);"
    info_func "operator/("  "void foo::operator/\\(foo &\\);"
    info_func "operator==("  "void foo::operator==\\(foo &\\);"
    info_func "operator^("  "void foo::operator\\^\\(foo &\\);"

    info_func "operator>=("  "void foo::operator>=\\(foo &\\);"
    info_func "operator>("  "void foo::operator>\\(foo &\\);"
    info_func "operator<=("  "void foo::operator<=\\(foo &\\);"
    info_func "operator<<("  "void foo::operator<<\\(foo &\\);"
    info_func "operator<("  "void foo::operator<\\(foo &\\);"
    info_func "operator%("  "void foo::operator%\\(foo &\\);"
    info_func "operator-("  "void foo::operator-\\(foo &\\);"

    # There doesn't appear to be anyway to get '*' treated as a character
    # to match, rather than as a regex special character.
    setup_xfail "*-*-*"
    info_func "operator\*("  "void foo::operator\\*\\(foo &\\);"

    info_func "operator--("  "void foo::operator--\\(int\\);"
    info_func "operator!=("  "void foo::operator!=\\(foo &\\);"
    info_func "operator!("  "void foo::operator!\\(void\\);"
    info_func "operator new("  "void \\*foo::operator new\\(.*\\)(| static);"
    info_func "operator||("  "void foo::operator\\|\\|\\(foo &\\);"
    info_func "operator char \\*("  "char \\*foo::operator char \\*\\(void\\);"
    info_func "operator int("  "int foo::operator int\\(void\\);"
    info_func "operator|("  "void foo::operator\\|\\(foo &\\);"
    info_func "operator+("  "void foo::operator\\+\\(foo &\\);"
    info_func "operator++("  "void foo::operator\\+\\+\\(int\\);"
    info_func "operator->("  "foo \\*foo::operator->\\(void\\);"
    info_func "operator->\\*("  "void foo::operator->\\*\\(foo &\\);"
    info_func "operator>>("  "void foo::operator\>\>\\(foo &\\);"

    # GDB says "`operator \[\](' not supported".  I don't know why.
    setup_xfail "*-*-*"
    info_func "operator\\\[\\\](" "void foo::operator\\\[\\\]\\(foo &\\);"
    # But this works, for some reason.
    info_func ".perator\\\[\\\](" "void foo::operator\\\[\\\]\\(foo &\\);"
}


proc test_paddr_operator_functions {} {
    global hex
    global hp_aCC_compiler

    print_addr_of "foo::operator&&(foo &)"
    print_addr_of "foo::operator&=(foo &)"
    print_addr_of "foo::operator&(foo &)"
    print_addr_of "foo::operator/=(foo &)"
    print_addr_of "foo::operator^=(foo &)"
    print_addr_of "foo::operator<<=(foo &)"
    print_addr_of "foo::operator%=(foo &)"
    print_addr_of "foo::operator-=(foo &)"
    print_addr_of "foo::operator*=(foo &)"
    print_addr_of "foo::operator|=(foo &)"
    print_addr_of "foo::operator+=(foo &)"
    print_addr_of "foo::operator>>=(foo &)"
    print_addr_of "foo::operator=(foo &)"
    print_addr_of "foo::operator()(foo &)"
    print_addr_of "foo::operator, (foo &)"
    print_addr_of "foo::operator~(void)"
    if { !$hp_aCC_compiler } {
	print_addr_of "foo::operator delete(void *)"
    } else {
	gdb_test "print &'foo::operator delete(void *) static'" \
	    " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
    }
    print_addr_of "foo::operator/(foo &)"
    print_addr_of "foo::operator==(foo &)"
    print_addr_of "foo::operator^(foo &)"
    print_addr_of "foo::operator>=(foo &)"
    print_addr_of "foo::operator>(foo &)"
    print_addr_of "foo::operator<=(foo &)"
    print_addr_of "foo::operator<<(foo &)"
    print_addr_of "foo::operator<(foo &)"
    print_addr_of "foo::operator%(foo &)"
    print_addr_of "foo::operator-(foo &)"
    print_addr_of "foo::operator*(foo &)"
    print_addr_of "foo::operator--(int)"
    print_addr_of "foo::operator!=(foo &)"
    print_addr_of "foo::operator!(void)"
    gdb_test "print &'foo::operator new'" \
	" = .* $hex <foo::operator new\\(.*\\)(| static)>"
    print_addr_of "foo::operator||(foo &)"
    print_addr_of "foo::operator char *(void)"
    print_addr_of "foo::operator int(void)"
    print_addr_of "foo::operator|(foo &)"
    print_addr_of "foo::operator+(foo &)"
    print_addr_of "foo::operator++(int)"
    print_addr_of "foo::operator->(void)"
    print_addr_of "foo::operator->*(foo &)"
    print_addr_of "foo::operator>>(foo &)"
    gdb_test "print &'foo::operator\[\](foo &)'" \
	" = .*0x\[0-9a-f\]+ <foo::operator\\\[\\\]\\(foo &\\)>"
}

#
# Test overloaded functions (1 arg).
#

proc test_paddr_overloaded_functions {} {
    print_addr_of "overload1arg(signed char)"
    print_addr_of "overload1arg(unsigned char)"
    print_addr_of "overload1arg(unsigned int)"
    print_addr_of "overload1arg(unsigned long)"
    print_addr_of "overload1arg(unsigned short)"
    print_addr_of "overload1arg(char)"
    print_addr_of "overload1arg(double)"
    print_addr_of "overload1arg(float)"
    print_addr_of "overload1arg(int)"
    print_addr_of "overload1arg(long)"
    print_addr_of "overload1arg(short)"
    print_addr_of "overload1arg(void)"
    print_addr_of "overloadargs(int)"
    print_addr_of "overloadargs(int, int)"
    print_addr_of "overloadargs(int, int, int)"
    print_addr_of "overloadargs(int, int, int, int)"
    print_addr_of "overloadargs(int, int, int, int, int)"
    print_addr_of "overloadargs(int, int, int, int, int, int)"
    print_addr_of "overloadargs(int, int, int, int, int, int, int)"
    print_addr_of "overloadargs(int, int, int, int, int, int, int, int)"
    print_addr_of "overloadargs(int, int, int, int, int, int, int, int, int)"
    print_addr_of "overloadargs(int, int, int, int, int, int, int, int, int, int)"
    print_addr_of "overloadargs(int, int, int, int, int, int, int, int, int, int, int)"
}

proc test_paddr_hairy_functions {} {
    print_addr_of "hairyfunc1(int)"
    print_addr_of "hairyfunc2(int (*)(char *))"
    print_addr_of "hairyfunc3(int (*)(short (*)(long *)))"
    print_addr_of "hairyfunc4(int (*)(short (*)(char *)))"
    print_addr_of "hairyfunc5(int (*(*)(char *))(long))"
    print_addr_of "hairyfunc6(int (*(*)(int *))(long))"
    print_addr_of "hairyfunc7(int (*(*)(int (*)(char *)))(long))"
}

proc do_tests {} {
    global prms_id
    global bug_id
    global subdir
    global objdir
    global srcdir
    global binfile
    global gdb_prompt

    set prms_id 0
    set bug_id 0

    # 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 $"

    # Get the debug format for the compiled test case.  If that
    # format is DWARF 1 then just skip all the tests since none of
    # them will pass.

    if [ runto_main] then {
	get_debug_format
	if [ setup_xfail_format "DWARF 1" ] then {
	    fail "C++ tests skipped due to limited C++ support in DWARF 1 debug format"
	    return
	}
	clear_xfail "*-*-*"
    }

    test_paddr_overloaded_functions
    test_paddr_operator_functions
    test_paddr_hairy_functions
    test_lookup_operator_functions
}

do_tests