]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.c++/overload.exp
2001-10-31 Michael Snyder <msnyder@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.c++ / overload.exp
CommitLineData
db144853 1# Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
c906108c
SS
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# written by Elena Zannoni (ezannoni@cygnus.com)
21
22# This file is part of the gdb testsuite
23#
24# tests for overloaded member functions. Command Line calls
25#
26
27
28if $tracelevel then {
29 strace $tracelevel
30 }
31
32#
33# test running programs
34#
35set prms_id 0
36set bug_id 0
37
d4f3574e
SS
38if { [skip_cplus_tests] } { continue }
39
c906108c
SS
40set testfile "overload"
41set srcfile ${testfile}.cc
42set binfile ${objdir}/${subdir}/${testfile}
43
44if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
45 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
46}
47
9e0b60a8
JM
48if [get_compiler_info ${binfile} "c++"] {
49 return -1
50}
c906108c
SS
51
52gdb_exit
53gdb_start
54gdb_reinitialize_dir $srcdir/$subdir
55gdb_load ${binfile}
56
57# set it up at a breakpoint so we can play with the variable values
58#
59if ![runto_main] then {
60 perror "couldn't run to breakpoint"
61 continue
62}
63
db144853
MC
64if ![runto 'marker1'] then {
65 perror "couldn't run to marker1"
66 continue
67}
c906108c 68
db144853 69gdb_test "up" ".*main.*" "up from marker1"
c906108c
SS
70
71send_gdb "print foo_instance1\n"
72gdb_expect {
73 -re ".\[0-9\]* = \{ifoo = 111, ccpfoo = 0x0\}\r\n$gdb_prompt $" {
74 pass "print foo_instance1"
75 }
76 -re ".*$gdb_prompt $" { fail "print foo_instance1" }
77 timeout { fail "(timeout) print foo_instance1" }
78 }
79
80
a0b3c4fd 81setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
82send_gdb "ptype foo_instance1\n"
83gdb_expect {
84 -re "type = class foo \{.*public:.*int ifoo;.*const char \\*ccpfoo;.*foo\\(int\\);.*foo\\(int, (const char|char const) \\*\\);.*foo\\(foo &\\);.*~foo\\(void\\);.*void foofunc\\(int\\);.*void foofunc\\(int, signed char \\*\\);.*int overload1arg\\(void\\);.*int overload1arg\\(char\\);.*int overload1arg\\(signed char\\);.*int overload1arg\\(unsigned char\\);.*int overload1arg\\(short\\);.*int overload1arg\\(unsigned short\\);.*int overload1arg\\(int\\);.*int overload1arg\\(unsigned int\\);.*int overload1arg\\(long\\);.*int overload1arg\\(unsigned long\\);.*int overload1arg\\(float\\);.*int overload1arg\\(double\\);.*int overloadargs\\(int\\);.*int overloadargs\\(int, int\\);.*int overloadargs\\(int, int, int\\);.*int overloadargs\\(int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);\r\n\}\r\n$gdb_prompt $" {
85 pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)"
86 }
9e0b60a8
JM
87 -re "type = class foo .*int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);\r\n\}\r\n$gdb_prompt $" {
88 pass "ptype foo_instance1 (shorter match)"
89 }
c906108c
SS
90 -re ".*$gdb_prompt $" { fail "ptype foo_instance1" }
91 timeout { fail "(timeout) ptype foo_instance1" }
92 }
93
94send_gdb "print foo_instance2\n"
95gdb_expect {
96 -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
97 pass "print foo_instance2"
98 }
99 -re ".*$gdb_prompt $" { fail "print foo_instance2" }
100 timeout { fail "(timeout) print foo_instance2" }
101 }
102
103send_gdb "print foo_instance3\n"
104gdb_expect {
105 -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
106 pass "print foo_instance3"
107 }
108 -re ".*$gdb_prompt $" { fail "print foo_instance3" }
109 timeout { fail "(timeout) print foo_instance3" }
110 }
111
112
9e0b60a8
JM
113# The overload resolver added by HP (valops.c:find_overload_match) doesn't
114# work right for G++ output, since the list of parameters seems not to
115# be filled in correctly. Until this gets fixed, don't expect to pass
116# these tests.
c906108c 117
a0b3c4fd 118setup_xfail "*-*-*" CLLbs16901
c906108c
SS
119send_gdb "print foo_instance1.overloadargs(1)\n"
120gdb_expect {
121 -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
122 pass "print call overloaded func 1 arg"
123 }
124 -re ".*$gdb_prompt $" { fail "print call overloaded func 1 arg" }
125 timeout { fail "(timeout) print call overloaded func 1 arg" }
126 }
127
9e0b60a8 128
a0b3c4fd 129setup_xfail "*-*-*" CLLbs16901
9e0b60a8 130
c906108c
SS
131send_gdb "print foo_instance1.overloadargs(1, 2)\n"
132gdb_expect {
133 -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
134 pass "print call overloaded func 2 args"
135 }
136 -re ".*$gdb_prompt $" { fail "print call overloaded func 2 args" }
137 timeout { fail "(timeout) print call overloaded func 2 args" }
138 }
139
140
a0b3c4fd 141setup_xfail "*-*-*" CLLbs16901
9e0b60a8 142
c906108c
SS
143send_gdb "print foo_instance1.overloadargs(1, 2, 3)\n"
144gdb_expect {
145 -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
146 pass "print call overloaded func 3 args"
147 }
148 -re ".*$gdb_prompt $" { fail "print call overloaded func 3 args" }
149 timeout { fail "(timeout) print call overloaded func 3 args" }
150 }
151
152
a0b3c4fd 153setup_xfail "*-*-*" CLLbs16901
9e0b60a8 154
c906108c
SS
155send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4)\n"
156gdb_expect {
157 -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
158 pass "print call overloaded func 4 args"
159 }
160 -re ".*$gdb_prompt $" { fail "print call overloaded func 4 args" }
161 timeout { fail "(timeout) print call overloaded func 4 args" }
162 }
163
164
a0b3c4fd 165setup_xfail "*-*-*" CLLbs16901
9e0b60a8 166
c906108c
SS
167send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5)\n"
168gdb_expect {
169 -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
170 pass "print call overloaded func 5 args"
171 }
172 -re ".*$gdb_prompt $" { fail "print call overloaded func 5 args" }
173 timeout { fail "(timeout) print call overloaded func 5 args" }
174 }
175
176
a0b3c4fd 177setup_xfail "*-*-*" CLLbs16901
9e0b60a8 178
c906108c
SS
179send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)\n"
180gdb_expect {
181 -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
182 pass "print call overloaded func 6 args"
183 }
184 -re ".*$gdb_prompt $" { fail "print call overloaded func 6 args" }
185 timeout { fail "(timeout) print call overloaded func 6 args" }
186 }
187
188
a0b3c4fd 189setup_xfail "*-*-*" CLLbs16901
9e0b60a8 190
c906108c
SS
191send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)\n"
192gdb_expect {
193 -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
194 pass "print call overloaded func 7 args"
195 }
196 -re ".*$gdb_prompt $" { fail "print call overloaded func 7 args" }
197 timeout { fail "(timeout) print call overloaded func 7 args" }
198 }
199
200
a0b3c4fd 201setup_xfail "*-*-*" CLLbs16901
9e0b60a8 202
c906108c
SS
203send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)\n"
204gdb_expect {
205 -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
206 pass "print call overloaded func 8 args"
207 }
208 -re ".*$gdb_prompt $" { fail "print call overloaded func 8 args" }
209 timeout { fail "(timeout) print call overloaded func 8 args" }
210 }
211
212
a0b3c4fd 213setup_xfail "*-*-*" CLLbs16901
9e0b60a8 214
c906108c
SS
215send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)\n"
216gdb_expect {
217 -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
218 pass "print call overloaded func 9 args"
219 }
220 -re ".*$gdb_prompt $" { fail "print call overloaded func 9 args" }
221 timeout { fail "(timeout) print call overloaded func 9 args" }
222 }
223
224
a0b3c4fd 225setup_xfail "*-*-*" CLLbs16901
9e0b60a8 226
c906108c
SS
227send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n"
228gdb_expect {
229 -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
230 pass "print call overloaded func 10 args"
231 }
232 -re ".*$gdb_prompt $" { fail "print call overloaded func 10 args" }
233 timeout { fail "(timeout) print call overloaded func 10 args" }
234 }
235
236
a0b3c4fd 237setup_xfail "*-*-*" CLLbs16901
9e0b60a8 238
c906108c
SS
239send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)\n"
240gdb_expect {
241 -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
242 pass "print call overloaded func 11 args"
243 }
244 -re ".*$gdb_prompt $" { fail "print call overloaded func 11 args" }
245 timeout { fail "(timeout) print call overloaded func 11 args" }
246 }
247
248
a0b3c4fd 249setup_xfail "*-*-*" CLLbs16901
9e0b60a8 250
c906108c
SS
251send_gdb "print foo_instance1.overload1arg()\n"
252gdb_expect {
253 -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
254 pass "print call overloaded func void arg"
255 }
256 -re ".*$gdb_prompt $" { fail "print call overloaded func void arg" }
257 timeout { fail "(timeout) print call overloaded func void arg" }
258 }
259
9e0b60a8 260
a0b3c4fd 261setup_xfail "*-*-*" CLLbs16901
9e0b60a8 262
c906108c
SS
263send_gdb "print foo_instance1.overload1arg((char)arg2)\n"
264gdb_expect {
265 -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
266 pass "print call overloaded func char arg"
267 }
268 -re ".*$gdb_prompt $" { fail "print call overloaded func char arg" }
269 timeout { fail "(timeout) print call overloaded func char arg" }
270 }
271
9e0b60a8 272
a0b3c4fd 273setup_xfail "*-*-*" CLLbs16901
9e0b60a8 274
c906108c
SS
275send_gdb "print foo_instance1.overload1arg((signed char)arg3)\n"
276gdb_expect {
277 -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
278 pass "print call overloaded func signed char arg"
279 }
280 -re ".*$gdb_prompt $" { fail "print call overloaded func signed char arg" }
281 timeout { fail "(timeout) print call overloaded func signed char arg" }
282 }
283
284
a0b3c4fd 285setup_xfail "*-*-*" CLLbs16901
9e0b60a8 286
c906108c
SS
287send_gdb "print foo_instance1.overload1arg((unsigned char)arg4)\n"
288gdb_expect {
289 -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
290 pass "print call overloaded func unsigned char arg"
291 }
292 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned char arg" }
293 timeout { fail "(timeout) print call overloaded func unsigned char arg" }
294 }
295
296
a0b3c4fd 297setup_xfail "*-*-*" CLLbs16901
9e0b60a8 298
c906108c
SS
299send_gdb "print foo_instance1.overload1arg((short)arg5)\n"
300gdb_expect {
301 -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
302 pass "print call overloaded func short arg"
303 }
304 -re ".*$gdb_prompt $" { fail "print call overloaded func short arg" }
305 timeout { fail "(timeout) print call overloaded func short arg" }
306 }
307
308
a0b3c4fd 309setup_xfail "*-*-*" CLLbs16901
9e0b60a8 310
c906108c
SS
311send_gdb "print foo_instance1.overload1arg((unsigned short)arg6)\n"
312gdb_expect {
313 -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
314 pass "print call overloaded func unsigned short arg"
315 }
316 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned short arg" }
317 timeout { fail "(timeout) print call overloaded func unsigned short arg" }
318 }
319
320
a0b3c4fd 321setup_xfail "*-*-*" CLLbs16901
9e0b60a8 322
c906108c
SS
323send_gdb "print foo_instance1.overload1arg((int)arg7)\n"
324gdb_expect {
325 -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
326 pass "print call overloaded func int arg"
327 }
328 -re ".*$gdb_prompt $" { fail "print call overloaded func int arg" }
329 timeout { fail "(timeout) print call overloaded func int arg" }
330 }
331
332
a0b3c4fd 333setup_xfail "*-*-*" CLLbs16901
9e0b60a8 334
c906108c
SS
335send_gdb "print foo_instance1.overload1arg((unsigned int)arg8)\n"
336gdb_expect {
337 -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
338 pass "print call overloaded func unsigned int arg"
339 }
340 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned int arg" }
341 timeout { fail "(timeout) print call overloaded func unsigned int arg" }
342 }
343
344
a0b3c4fd 345setup_xfail "*-*-*" CLLbs16901
9e0b60a8 346
c906108c
SS
347send_gdb "print foo_instance1.overload1arg((long)arg9)\n"
348gdb_expect {
349 -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
350 pass "print call overloaded func long arg"
351 }
352 -re ".*$gdb_prompt $" { fail "print call overloaded func long arg" }
353 timeout { fail "(timeout) print call overloaded func long arg" }
354 }
355
356
a0b3c4fd 357setup_xfail "*-*-*" CLLbs16901
9e0b60a8 358
c906108c
SS
359send_gdb "print foo_instance1.overload1arg((unsigned long)arg10)\n"
360gdb_expect {
361 -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
362 pass "print call overloaded func unsigned long arg"
363 }
364 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned long arg" }
365 timeout { fail "(timeout) print call overloaded func unsigned long arg" }
366 }
367
368
a0b3c4fd 369setup_xfail "*-*-*" CLLbs16901
9e0b60a8 370
c906108c
SS
371send_gdb "print foo_instance1.overload1arg((float)arg11)\n"
372gdb_expect {
373 -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
374 pass "print call overloaded func float arg"
375 }
376 -re ".*$gdb_prompt $" { fail "print call overloaded func float arg" }
377 timeout { fail "(timeout) print call overloaded func float arg" }
378 }
379
380
a0b3c4fd 381setup_xfail "*-*-*" CLLbs16901
9e0b60a8 382
c906108c
SS
383send_gdb "print foo_instance1.overload1arg((double)arg12)\n"
384gdb_expect {
385 -re ".\[0-9\]* = 12\r\n$gdb_prompt $" {
386 pass "print call overloaded func double arg"
387 }
388 -re ".*$gdb_prompt $" { fail "print call overloaded func double arg" }
389 timeout { fail "(timeout) print call overloaded func double arg" }
390 }
c2c6d25f
JM
391
392# Now some tests to see if we can list overloaded functions properly:
393
cbfa24cd
MS
394gdb_test "set listsize 1" "" ""
395# send_gdb "set listsize 1\n"
396# gdb_expect -re ".*$gdb_prompt $"
c2c6d25f 397
cbfa24cd
MS
398#
399# Decide whether to use "()" or "(void)"
400#
401
402send_gdb "info func overloadfnarg\n"
403gdb_expect {
404 -re ".*overloadfnarg\\(void\\).*$gdb_prompt $" {
405 gdb_test "list foo::overloadfnarg(void)"\
406 ".*int foo::overloadfnarg.*\\(void\\).*" \
407 "list overloaded function with no args"
408 }
409 -re ".*overloadfnarg\\(\\).*$gdb_prompt $" {
410 gdb_test "list foo::overloadfnarg()"\
411 ".*int foo::overloadfnarg.*\\(void\\).*" \
412 "list overloaded function with no args"
413 }
414 -re ".*$gdb_prompt $" {
415 fail "list overloaded function with no args (no matching symbol)"
416 }
417}
c2c6d25f
JM
418
419gdb_test "list foo::overloadfnarg(int)"\
420 "int foo::overloadfnarg.*\\(int arg\\).*" \
cbfa24cd 421 "list overloaded function with int arg"
c2c6d25f
JM
422
423gdb_test "list foo::overloadfnarg(int, int (*)(int))" \
424 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
cbfa24cd 425 "list overloaded function with function ptr args"
c2c6d25f
JM
426
427# This one crashes GDB. Don't know why yet.
428gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
429 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
cbfa24cd 430 "list overloaded function with function ptr args - quotes around argument"