2000-12-05 Michael Snyder <msnyder@mvstp600e.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.c++ / overload.exp
CommitLineData
d4f3574e 1# Copyright (C) 1998, 1999 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
64send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
65
66 send_gdb "cont\n"
67 gdb_expect {
68 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
69 send_gdb "up\n"
70 gdb_expect {
3c077de9
MS
71 -re ".*main.*$gdb_prompt $" {
72 pass "up from marker1"
73 }
660fd469
MS
74 -re ".*$gdb_prompt $" {
75 fail "up from marker1"
76 }
77 timeout { fail "up from marker1 (timeout)" }
c906108c
SS
78 }
79 }
80 -re "$gdb_prompt $" { fail "continue to marker1" }
81 timeout { fail "(timeout) continue to marker1" }
82 }
83
84
85send_gdb "print foo_instance1\n"
86gdb_expect {
87 -re ".\[0-9\]* = \{ifoo = 111, ccpfoo = 0x0\}\r\n$gdb_prompt $" {
88 pass "print foo_instance1"
89 }
90 -re ".*$gdb_prompt $" { fail "print foo_instance1" }
91 timeout { fail "(timeout) print foo_instance1" }
92 }
93
94
a0b3c4fd 95setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
96send_gdb "ptype foo_instance1\n"
97gdb_expect {
98 -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 $" {
99 pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)"
100 }
9e0b60a8
JM
101 -re "type = class foo .*int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);\r\n\}\r\n$gdb_prompt $" {
102 pass "ptype foo_instance1 (shorter match)"
103 }
c906108c
SS
104 -re ".*$gdb_prompt $" { fail "ptype foo_instance1" }
105 timeout { fail "(timeout) ptype foo_instance1" }
106 }
107
108send_gdb "print foo_instance2\n"
109gdb_expect {
110 -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
111 pass "print foo_instance2"
112 }
113 -re ".*$gdb_prompt $" { fail "print foo_instance2" }
114 timeout { fail "(timeout) print foo_instance2" }
115 }
116
117send_gdb "print foo_instance3\n"
118gdb_expect {
119 -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
120 pass "print foo_instance3"
121 }
122 -re ".*$gdb_prompt $" { fail "print foo_instance3" }
123 timeout { fail "(timeout) print foo_instance3" }
124 }
125
126
9e0b60a8
JM
127# The overload resolver added by HP (valops.c:find_overload_match) doesn't
128# work right for G++ output, since the list of parameters seems not to
129# be filled in correctly. Until this gets fixed, don't expect to pass
130# these tests.
c906108c 131
a0b3c4fd 132setup_xfail "*-*-*" CLLbs16901
c906108c
SS
133send_gdb "print foo_instance1.overloadargs(1)\n"
134gdb_expect {
135 -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
136 pass "print call overloaded func 1 arg"
137 }
138 -re ".*$gdb_prompt $" { fail "print call overloaded func 1 arg" }
139 timeout { fail "(timeout) print call overloaded func 1 arg" }
140 }
141
9e0b60a8 142
a0b3c4fd 143setup_xfail "*-*-*" CLLbs16901
9e0b60a8 144
c906108c
SS
145send_gdb "print foo_instance1.overloadargs(1, 2)\n"
146gdb_expect {
147 -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
148 pass "print call overloaded func 2 args"
149 }
150 -re ".*$gdb_prompt $" { fail "print call overloaded func 2 args" }
151 timeout { fail "(timeout) print call overloaded func 2 args" }
152 }
153
154
a0b3c4fd 155setup_xfail "*-*-*" CLLbs16901
9e0b60a8 156
c906108c
SS
157send_gdb "print foo_instance1.overloadargs(1, 2, 3)\n"
158gdb_expect {
159 -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
160 pass "print call overloaded func 3 args"
161 }
162 -re ".*$gdb_prompt $" { fail "print call overloaded func 3 args" }
163 timeout { fail "(timeout) print call overloaded func 3 args" }
164 }
165
166
a0b3c4fd 167setup_xfail "*-*-*" CLLbs16901
9e0b60a8 168
c906108c
SS
169send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4)\n"
170gdb_expect {
171 -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
172 pass "print call overloaded func 4 args"
173 }
174 -re ".*$gdb_prompt $" { fail "print call overloaded func 4 args" }
175 timeout { fail "(timeout) print call overloaded func 4 args" }
176 }
177
178
a0b3c4fd 179setup_xfail "*-*-*" CLLbs16901
9e0b60a8 180
c906108c
SS
181send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5)\n"
182gdb_expect {
183 -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
184 pass "print call overloaded func 5 args"
185 }
186 -re ".*$gdb_prompt $" { fail "print call overloaded func 5 args" }
187 timeout { fail "(timeout) print call overloaded func 5 args" }
188 }
189
190
a0b3c4fd 191setup_xfail "*-*-*" CLLbs16901
9e0b60a8 192
c906108c
SS
193send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)\n"
194gdb_expect {
195 -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
196 pass "print call overloaded func 6 args"
197 }
198 -re ".*$gdb_prompt $" { fail "print call overloaded func 6 args" }
199 timeout { fail "(timeout) print call overloaded func 6 args" }
200 }
201
202
a0b3c4fd 203setup_xfail "*-*-*" CLLbs16901
9e0b60a8 204
c906108c
SS
205send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)\n"
206gdb_expect {
207 -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
208 pass "print call overloaded func 7 args"
209 }
210 -re ".*$gdb_prompt $" { fail "print call overloaded func 7 args" }
211 timeout { fail "(timeout) print call overloaded func 7 args" }
212 }
213
214
a0b3c4fd 215setup_xfail "*-*-*" CLLbs16901
9e0b60a8 216
c906108c
SS
217send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)\n"
218gdb_expect {
219 -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
220 pass "print call overloaded func 8 args"
221 }
222 -re ".*$gdb_prompt $" { fail "print call overloaded func 8 args" }
223 timeout { fail "(timeout) print call overloaded func 8 args" }
224 }
225
226
a0b3c4fd 227setup_xfail "*-*-*" CLLbs16901
9e0b60a8 228
c906108c
SS
229send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)\n"
230gdb_expect {
231 -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
232 pass "print call overloaded func 9 args"
233 }
234 -re ".*$gdb_prompt $" { fail "print call overloaded func 9 args" }
235 timeout { fail "(timeout) print call overloaded func 9 args" }
236 }
237
238
a0b3c4fd 239setup_xfail "*-*-*" CLLbs16901
9e0b60a8 240
c906108c
SS
241send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n"
242gdb_expect {
243 -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
244 pass "print call overloaded func 10 args"
245 }
246 -re ".*$gdb_prompt $" { fail "print call overloaded func 10 args" }
247 timeout { fail "(timeout) print call overloaded func 10 args" }
248 }
249
250
a0b3c4fd 251setup_xfail "*-*-*" CLLbs16901
9e0b60a8 252
c906108c
SS
253send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)\n"
254gdb_expect {
255 -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
256 pass "print call overloaded func 11 args"
257 }
258 -re ".*$gdb_prompt $" { fail "print call overloaded func 11 args" }
259 timeout { fail "(timeout) print call overloaded func 11 args" }
260 }
261
262
a0b3c4fd 263setup_xfail "*-*-*" CLLbs16901
9e0b60a8 264
c906108c
SS
265send_gdb "print foo_instance1.overload1arg()\n"
266gdb_expect {
267 -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
268 pass "print call overloaded func void arg"
269 }
270 -re ".*$gdb_prompt $" { fail "print call overloaded func void arg" }
271 timeout { fail "(timeout) print call overloaded func void arg" }
272 }
273
9e0b60a8 274
a0b3c4fd 275setup_xfail "*-*-*" CLLbs16901
9e0b60a8 276
c906108c
SS
277send_gdb "print foo_instance1.overload1arg((char)arg2)\n"
278gdb_expect {
279 -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
280 pass "print call overloaded func char arg"
281 }
282 -re ".*$gdb_prompt $" { fail "print call overloaded func char arg" }
283 timeout { fail "(timeout) print call overloaded func char arg" }
284 }
285
9e0b60a8 286
a0b3c4fd 287setup_xfail "*-*-*" CLLbs16901
9e0b60a8 288
c906108c
SS
289send_gdb "print foo_instance1.overload1arg((signed char)arg3)\n"
290gdb_expect {
291 -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
292 pass "print call overloaded func signed char arg"
293 }
294 -re ".*$gdb_prompt $" { fail "print call overloaded func signed char arg" }
295 timeout { fail "(timeout) print call overloaded func signed char arg" }
296 }
297
298
a0b3c4fd 299setup_xfail "*-*-*" CLLbs16901
9e0b60a8 300
c906108c
SS
301send_gdb "print foo_instance1.overload1arg((unsigned char)arg4)\n"
302gdb_expect {
303 -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
304 pass "print call overloaded func unsigned char arg"
305 }
306 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned char arg" }
307 timeout { fail "(timeout) print call overloaded func unsigned char arg" }
308 }
309
310
a0b3c4fd 311setup_xfail "*-*-*" CLLbs16901
9e0b60a8 312
c906108c
SS
313send_gdb "print foo_instance1.overload1arg((short)arg5)\n"
314gdb_expect {
315 -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
316 pass "print call overloaded func short arg"
317 }
318 -re ".*$gdb_prompt $" { fail "print call overloaded func short arg" }
319 timeout { fail "(timeout) print call overloaded func short arg" }
320 }
321
322
a0b3c4fd 323setup_xfail "*-*-*" CLLbs16901
9e0b60a8 324
c906108c
SS
325send_gdb "print foo_instance1.overload1arg((unsigned short)arg6)\n"
326gdb_expect {
327 -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
328 pass "print call overloaded func unsigned short arg"
329 }
330 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned short arg" }
331 timeout { fail "(timeout) print call overloaded func unsigned short arg" }
332 }
333
334
a0b3c4fd 335setup_xfail "*-*-*" CLLbs16901
9e0b60a8 336
c906108c
SS
337send_gdb "print foo_instance1.overload1arg((int)arg7)\n"
338gdb_expect {
339 -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
340 pass "print call overloaded func int arg"
341 }
342 -re ".*$gdb_prompt $" { fail "print call overloaded func int arg" }
343 timeout { fail "(timeout) print call overloaded func int arg" }
344 }
345
346
a0b3c4fd 347setup_xfail "*-*-*" CLLbs16901
9e0b60a8 348
c906108c
SS
349send_gdb "print foo_instance1.overload1arg((unsigned int)arg8)\n"
350gdb_expect {
351 -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
352 pass "print call overloaded func unsigned int arg"
353 }
354 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned int arg" }
355 timeout { fail "(timeout) print call overloaded func unsigned int arg" }
356 }
357
358
a0b3c4fd 359setup_xfail "*-*-*" CLLbs16901
9e0b60a8 360
c906108c
SS
361send_gdb "print foo_instance1.overload1arg((long)arg9)\n"
362gdb_expect {
363 -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
364 pass "print call overloaded func long arg"
365 }
366 -re ".*$gdb_prompt $" { fail "print call overloaded func long arg" }
367 timeout { fail "(timeout) print call overloaded func long arg" }
368 }
369
370
a0b3c4fd 371setup_xfail "*-*-*" CLLbs16901
9e0b60a8 372
c906108c
SS
373send_gdb "print foo_instance1.overload1arg((unsigned long)arg10)\n"
374gdb_expect {
375 -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
376 pass "print call overloaded func unsigned long arg"
377 }
378 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned long arg" }
379 timeout { fail "(timeout) print call overloaded func unsigned long arg" }
380 }
381
382
a0b3c4fd 383setup_xfail "*-*-*" CLLbs16901
9e0b60a8 384
c906108c
SS
385send_gdb "print foo_instance1.overload1arg((float)arg11)\n"
386gdb_expect {
387 -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
388 pass "print call overloaded func float arg"
389 }
390 -re ".*$gdb_prompt $" { fail "print call overloaded func float arg" }
391 timeout { fail "(timeout) print call overloaded func float arg" }
392 }
393
394
a0b3c4fd 395setup_xfail "*-*-*" CLLbs16901
9e0b60a8 396
c906108c
SS
397send_gdb "print foo_instance1.overload1arg((double)arg12)\n"
398gdb_expect {
399 -re ".\[0-9\]* = 12\r\n$gdb_prompt $" {
400 pass "print call overloaded func double arg"
401 }
402 -re ".*$gdb_prompt $" { fail "print call overloaded func double arg" }
403 timeout { fail "(timeout) print call overloaded func double arg" }
404 }
c2c6d25f
JM
405
406# Now some tests to see if we can list overloaded functions properly:
407
408send_gdb "set listsize 1\n"
409gdb_expect -re ".*$gdb_prompt $"
410
411gdb_test "list foo::overloadfnarg(void)"\
412 ".*int foo::overloadfnarg.*\\(void\\).*" \
413 "print overloaded function with no args"
414
415gdb_test "list foo::overloadfnarg(int)"\
416 "int foo::overloadfnarg.*\\(int arg\\).*" \
417 "print overloaded function with int arg"
418
419gdb_test "list foo::overloadfnarg(int, int (*)(int))" \
420 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
421 "print overloaded function with function ptr args"
422
423# This one crashes GDB. Don't know why yet.
424gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
425 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
426 "print overloaded function with function ptr args - quotes around argument"
This page took 0.122286 seconds and 4 git commands to generate.