1 # Copyright (C) 1998, 1999 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # written by Elena Zannoni (ezannoni@cygnus.com)
22 # This file is part of the gdb testsuite
24 # tests for overloaded member functions. Command Line calls
33 # test running programs
38 if { [skip_cplus_tests] } { continue }
40 set testfile "overload"
41 set srcfile ${testfile}.cc
42 set binfile ${objdir}/${subdir}/${testfile}
44 if { [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."
48 if [get_compiler_info ${binfile} "c++"] {
54 gdb_reinitialize_dir $srcdir/$subdir
57 # set it up at a breakpoint so we can play with the variable values
59 if ![runto_main] then {
60 perror "couldn't run to breakpoint"
64 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
68 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
71 -re ".*$gdb_prompt $" {}
72 timeout { fail "up from marker1" }
75 -re "$gdb_prompt $" { fail "continue to marker1" }
76 timeout { fail "(timeout) continue to marker1" }
80 send_gdb "print foo_instance1\n"
82 -re ".\[0-9\]* = \{ifoo = 111, ccpfoo = 0x0\}\r\n$gdb_prompt $" {
83 pass "print foo_instance1"
85 -re ".*$gdb_prompt $" { fail "print foo_instance1" }
86 timeout { fail "(timeout) print foo_instance1" }
90 setup_xfail "hppa*-*-*" CLLbs16901
91 send_gdb "ptype foo_instance1\n"
93 -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 $" {
94 pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)"
96 -re "type = class foo .*int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);\r\n\}\r\n$gdb_prompt $" {
97 pass "ptype foo_instance1 (shorter match)"
99 -re ".*$gdb_prompt $" { fail "ptype foo_instance1" }
100 timeout { fail "(timeout) ptype foo_instance1" }
103 send_gdb "print foo_instance2\n"
105 -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
106 pass "print foo_instance2"
108 -re ".*$gdb_prompt $" { fail "print foo_instance2" }
109 timeout { fail "(timeout) print foo_instance2" }
112 send_gdb "print foo_instance3\n"
114 -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
115 pass "print foo_instance3"
117 -re ".*$gdb_prompt $" { fail "print foo_instance3" }
118 timeout { fail "(timeout) print foo_instance3" }
122 # The overload resolver added by HP (valops.c:find_overload_match) doesn't
123 # work right for G++ output, since the list of parameters seems not to
124 # be filled in correctly. Until this gets fixed, don't expect to pass
127 setup_xfail "*-*-*" CLLbs16901
128 send_gdb "print foo_instance1.overloadargs(1)\n"
130 -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
131 pass "print call overloaded func 1 arg"
133 -re ".*$gdb_prompt $" { fail "print call overloaded func 1 arg" }
134 timeout { fail "(timeout) print call overloaded func 1 arg" }
138 setup_xfail "*-*-*" CLLbs16901
140 send_gdb "print foo_instance1.overloadargs(1, 2)\n"
142 -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
143 pass "print call overloaded func 2 args"
145 -re ".*$gdb_prompt $" { fail "print call overloaded func 2 args" }
146 timeout { fail "(timeout) print call overloaded func 2 args" }
150 setup_xfail "*-*-*" CLLbs16901
152 send_gdb "print foo_instance1.overloadargs(1, 2, 3)\n"
154 -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
155 pass "print call overloaded func 3 args"
157 -re ".*$gdb_prompt $" { fail "print call overloaded func 3 args" }
158 timeout { fail "(timeout) print call overloaded func 3 args" }
162 setup_xfail "*-*-*" CLLbs16901
164 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4)\n"
166 -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
167 pass "print call overloaded func 4 args"
169 -re ".*$gdb_prompt $" { fail "print call overloaded func 4 args" }
170 timeout { fail "(timeout) print call overloaded func 4 args" }
174 setup_xfail "*-*-*" CLLbs16901
176 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5)\n"
178 -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
179 pass "print call overloaded func 5 args"
181 -re ".*$gdb_prompt $" { fail "print call overloaded func 5 args" }
182 timeout { fail "(timeout) print call overloaded func 5 args" }
186 setup_xfail "*-*-*" CLLbs16901
188 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)\n"
190 -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
191 pass "print call overloaded func 6 args"
193 -re ".*$gdb_prompt $" { fail "print call overloaded func 6 args" }
194 timeout { fail "(timeout) print call overloaded func 6 args" }
198 setup_xfail "*-*-*" CLLbs16901
200 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)\n"
202 -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
203 pass "print call overloaded func 7 args"
205 -re ".*$gdb_prompt $" { fail "print call overloaded func 7 args" }
206 timeout { fail "(timeout) print call overloaded func 7 args" }
210 setup_xfail "*-*-*" CLLbs16901
212 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)\n"
214 -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
215 pass "print call overloaded func 8 args"
217 -re ".*$gdb_prompt $" { fail "print call overloaded func 8 args" }
218 timeout { fail "(timeout) print call overloaded func 8 args" }
222 setup_xfail "*-*-*" CLLbs16901
224 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)\n"
226 -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
227 pass "print call overloaded func 9 args"
229 -re ".*$gdb_prompt $" { fail "print call overloaded func 9 args" }
230 timeout { fail "(timeout) print call overloaded func 9 args" }
234 setup_xfail "*-*-*" CLLbs16901
236 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n"
238 -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
239 pass "print call overloaded func 10 args"
241 -re ".*$gdb_prompt $" { fail "print call overloaded func 10 args" }
242 timeout { fail "(timeout) print call overloaded func 10 args" }
246 setup_xfail "*-*-*" CLLbs16901
248 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)\n"
250 -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
251 pass "print call overloaded func 11 args"
253 -re ".*$gdb_prompt $" { fail "print call overloaded func 11 args" }
254 timeout { fail "(timeout) print call overloaded func 11 args" }
258 setup_xfail "*-*-*" CLLbs16901
260 send_gdb "print foo_instance1.overload1arg()\n"
262 -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
263 pass "print call overloaded func void arg"
265 -re ".*$gdb_prompt $" { fail "print call overloaded func void arg" }
266 timeout { fail "(timeout) print call overloaded func void arg" }
270 setup_xfail "*-*-*" CLLbs16901
272 send_gdb "print foo_instance1.overload1arg((char)arg2)\n"
274 -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
275 pass "print call overloaded func char arg"
277 -re ".*$gdb_prompt $" { fail "print call overloaded func char arg" }
278 timeout { fail "(timeout) print call overloaded func char arg" }
282 setup_xfail "*-*-*" CLLbs16901
284 send_gdb "print foo_instance1.overload1arg((signed char)arg3)\n"
286 -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
287 pass "print call overloaded func signed char arg"
289 -re ".*$gdb_prompt $" { fail "print call overloaded func signed char arg" }
290 timeout { fail "(timeout) print call overloaded func signed char arg" }
294 setup_xfail "*-*-*" CLLbs16901
296 send_gdb "print foo_instance1.overload1arg((unsigned char)arg4)\n"
298 -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
299 pass "print call overloaded func unsigned char arg"
301 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned char arg" }
302 timeout { fail "(timeout) print call overloaded func unsigned char arg" }
306 setup_xfail "*-*-*" CLLbs16901
308 send_gdb "print foo_instance1.overload1arg((short)arg5)\n"
310 -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
311 pass "print call overloaded func short arg"
313 -re ".*$gdb_prompt $" { fail "print call overloaded func short arg" }
314 timeout { fail "(timeout) print call overloaded func short arg" }
318 setup_xfail "*-*-*" CLLbs16901
320 send_gdb "print foo_instance1.overload1arg((unsigned short)arg6)\n"
322 -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
323 pass "print call overloaded func unsigned short arg"
325 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned short arg" }
326 timeout { fail "(timeout) print call overloaded func unsigned short arg" }
330 setup_xfail "*-*-*" CLLbs16901
332 send_gdb "print foo_instance1.overload1arg((int)arg7)\n"
334 -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
335 pass "print call overloaded func int arg"
337 -re ".*$gdb_prompt $" { fail "print call overloaded func int arg" }
338 timeout { fail "(timeout) print call overloaded func int arg" }
342 setup_xfail "*-*-*" CLLbs16901
344 send_gdb "print foo_instance1.overload1arg((unsigned int)arg8)\n"
346 -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
347 pass "print call overloaded func unsigned int arg"
349 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned int arg" }
350 timeout { fail "(timeout) print call overloaded func unsigned int arg" }
354 setup_xfail "*-*-*" CLLbs16901
356 send_gdb "print foo_instance1.overload1arg((long)arg9)\n"
358 -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
359 pass "print call overloaded func long arg"
361 -re ".*$gdb_prompt $" { fail "print call overloaded func long arg" }
362 timeout { fail "(timeout) print call overloaded func long arg" }
366 setup_xfail "*-*-*" CLLbs16901
368 send_gdb "print foo_instance1.overload1arg((unsigned long)arg10)\n"
370 -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
371 pass "print call overloaded func unsigned long arg"
373 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned long arg" }
374 timeout { fail "(timeout) print call overloaded func unsigned long arg" }
378 setup_xfail "*-*-*" CLLbs16901
380 send_gdb "print foo_instance1.overload1arg((float)arg11)\n"
382 -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
383 pass "print call overloaded func float arg"
385 -re ".*$gdb_prompt $" { fail "print call overloaded func float arg" }
386 timeout { fail "(timeout) print call overloaded func float arg" }
390 setup_xfail "*-*-*" CLLbs16901
392 send_gdb "print foo_instance1.overload1arg((double)arg12)\n"
394 -re ".\[0-9\]* = 12\r\n$gdb_prompt $" {
395 pass "print call overloaded func double arg"
397 -re ".*$gdb_prompt $" { fail "print call overloaded func double arg" }
398 timeout { fail "(timeout) print call overloaded func double arg" }
401 # Now some tests to see if we can list overloaded functions properly:
403 send_gdb "set listsize 1\n"
404 gdb_expect -re ".*$gdb_prompt $"
406 gdb_test "list foo::overloadfnarg(void)"\
407 ".*int foo::overloadfnarg.*\\(void\\).*" \
408 "print overloaded function with no args"
410 gdb_test "list foo::overloadfnarg(int)"\
411 "int foo::overloadfnarg.*\\(int arg\\).*" \
412 "print overloaded function with int arg"
414 gdb_test "list foo::overloadfnarg(int, int (*)(int))" \
415 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
416 "print overloaded function with function ptr args"
418 # This one crashes GDB. Don't know why yet.
419 gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
420 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
421 "print overloaded function with function ptr args - quotes around argument"