1 # Copyright 1998, 1999, 2000, 2001 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 if ![runto 'marker1'] then {
65 perror "couldn't run to marker1"
69 gdb_test "up" ".*main.*" "up from marker1"
71 send_gdb "print foo_instance1\n"
73 -re ".\[0-9\]* = \{ifoo = 111, ccpfoo = 0x0\}\r\n$gdb_prompt $" {
74 pass "print foo_instance1"
76 -re ".*$gdb_prompt $" { fail "print foo_instance1" }
77 timeout { fail "(timeout) print foo_instance1" }
81 setup_xfail "hppa*-*-*" CLLbs16901
82 send_gdb "ptype foo_instance1\n"
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)"
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)"
90 -re ".*$gdb_prompt $" { fail "ptype foo_instance1" }
91 timeout { fail "(timeout) ptype foo_instance1" }
94 send_gdb "print foo_instance2\n"
96 -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
97 pass "print foo_instance2"
99 -re ".*$gdb_prompt $" { fail "print foo_instance2" }
100 timeout { fail "(timeout) print foo_instance2" }
103 send_gdb "print foo_instance3\n"
105 -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
106 pass "print foo_instance3"
108 -re ".*$gdb_prompt $" { fail "print foo_instance3" }
109 timeout { fail "(timeout) print foo_instance3" }
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
118 setup_xfail "*-*-*" CLLbs16901
119 send_gdb "print foo_instance1.overloadargs(1)\n"
121 -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
122 pass "print call overloaded func 1 arg"
124 -re ".*$gdb_prompt $" { fail "print call overloaded func 1 arg" }
125 timeout { fail "(timeout) print call overloaded func 1 arg" }
129 setup_xfail "*-*-*" CLLbs16901
131 send_gdb "print foo_instance1.overloadargs(1, 2)\n"
133 -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
134 pass "print call overloaded func 2 args"
136 -re ".*$gdb_prompt $" { fail "print call overloaded func 2 args" }
137 timeout { fail "(timeout) print call overloaded func 2 args" }
141 setup_xfail "*-*-*" CLLbs16901
143 send_gdb "print foo_instance1.overloadargs(1, 2, 3)\n"
145 -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
146 pass "print call overloaded func 3 args"
148 -re ".*$gdb_prompt $" { fail "print call overloaded func 3 args" }
149 timeout { fail "(timeout) print call overloaded func 3 args" }
153 setup_xfail "*-*-*" CLLbs16901
155 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4)\n"
157 -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
158 pass "print call overloaded func 4 args"
160 -re ".*$gdb_prompt $" { fail "print call overloaded func 4 args" }
161 timeout { fail "(timeout) print call overloaded func 4 args" }
165 setup_xfail "*-*-*" CLLbs16901
167 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5)\n"
169 -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
170 pass "print call overloaded func 5 args"
172 -re ".*$gdb_prompt $" { fail "print call overloaded func 5 args" }
173 timeout { fail "(timeout) print call overloaded func 5 args" }
177 setup_xfail "*-*-*" CLLbs16901
179 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)\n"
181 -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
182 pass "print call overloaded func 6 args"
184 -re ".*$gdb_prompt $" { fail "print call overloaded func 6 args" }
185 timeout { fail "(timeout) print call overloaded func 6 args" }
189 setup_xfail "*-*-*" CLLbs16901
191 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)\n"
193 -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
194 pass "print call overloaded func 7 args"
196 -re ".*$gdb_prompt $" { fail "print call overloaded func 7 args" }
197 timeout { fail "(timeout) print call overloaded func 7 args" }
201 setup_xfail "*-*-*" CLLbs16901
203 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)\n"
205 -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
206 pass "print call overloaded func 8 args"
208 -re ".*$gdb_prompt $" { fail "print call overloaded func 8 args" }
209 timeout { fail "(timeout) print call overloaded func 8 args" }
213 setup_xfail "*-*-*" CLLbs16901
215 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)\n"
217 -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
218 pass "print call overloaded func 9 args"
220 -re ".*$gdb_prompt $" { fail "print call overloaded func 9 args" }
221 timeout { fail "(timeout) print call overloaded func 9 args" }
225 setup_xfail "*-*-*" CLLbs16901
227 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n"
229 -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
230 pass "print call overloaded func 10 args"
232 -re ".*$gdb_prompt $" { fail "print call overloaded func 10 args" }
233 timeout { fail "(timeout) print call overloaded func 10 args" }
237 setup_xfail "*-*-*" CLLbs16901
239 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)\n"
241 -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
242 pass "print call overloaded func 11 args"
244 -re ".*$gdb_prompt $" { fail "print call overloaded func 11 args" }
245 timeout { fail "(timeout) print call overloaded func 11 args" }
249 setup_xfail "*-*-*" CLLbs16901
251 send_gdb "print foo_instance1.overload1arg()\n"
253 -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
254 pass "print call overloaded func void arg"
256 -re ".*$gdb_prompt $" { fail "print call overloaded func void arg" }
257 timeout { fail "(timeout) print call overloaded func void arg" }
261 setup_xfail "*-*-*" CLLbs16901
263 send_gdb "print foo_instance1.overload1arg((char)arg2)\n"
265 -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
266 pass "print call overloaded func char arg"
268 -re ".*$gdb_prompt $" { fail "print call overloaded func char arg" }
269 timeout { fail "(timeout) print call overloaded func char arg" }
273 setup_xfail "*-*-*" CLLbs16901
275 send_gdb "print foo_instance1.overload1arg((signed char)arg3)\n"
277 -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
278 pass "print call overloaded func signed char arg"
280 -re ".*$gdb_prompt $" { fail "print call overloaded func signed char arg" }
281 timeout { fail "(timeout) print call overloaded func signed char arg" }
285 setup_xfail "*-*-*" CLLbs16901
287 send_gdb "print foo_instance1.overload1arg((unsigned char)arg4)\n"
289 -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
290 pass "print call overloaded func unsigned char arg"
292 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned char arg" }
293 timeout { fail "(timeout) print call overloaded func unsigned char arg" }
297 setup_xfail "*-*-*" CLLbs16901
299 send_gdb "print foo_instance1.overload1arg((short)arg5)\n"
301 -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
302 pass "print call overloaded func short arg"
304 -re ".*$gdb_prompt $" { fail "print call overloaded func short arg" }
305 timeout { fail "(timeout) print call overloaded func short arg" }
309 setup_xfail "*-*-*" CLLbs16901
311 send_gdb "print foo_instance1.overload1arg((unsigned short)arg6)\n"
313 -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
314 pass "print call overloaded func unsigned short arg"
316 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned short arg" }
317 timeout { fail "(timeout) print call overloaded func unsigned short arg" }
321 setup_xfail "*-*-*" CLLbs16901
323 send_gdb "print foo_instance1.overload1arg((int)arg7)\n"
325 -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
326 pass "print call overloaded func int arg"
328 -re ".*$gdb_prompt $" { fail "print call overloaded func int arg" }
329 timeout { fail "(timeout) print call overloaded func int arg" }
333 setup_xfail "*-*-*" CLLbs16901
335 send_gdb "print foo_instance1.overload1arg((unsigned int)arg8)\n"
337 -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
338 pass "print call overloaded func unsigned int arg"
340 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned int arg" }
341 timeout { fail "(timeout) print call overloaded func unsigned int arg" }
345 setup_xfail "*-*-*" CLLbs16901
347 send_gdb "print foo_instance1.overload1arg((long)arg9)\n"
349 -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
350 pass "print call overloaded func long arg"
352 -re ".*$gdb_prompt $" { fail "print call overloaded func long arg" }
353 timeout { fail "(timeout) print call overloaded func long arg" }
357 setup_xfail "*-*-*" CLLbs16901
359 send_gdb "print foo_instance1.overload1arg((unsigned long)arg10)\n"
361 -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
362 pass "print call overloaded func unsigned long arg"
364 -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned long arg" }
365 timeout { fail "(timeout) print call overloaded func unsigned long arg" }
369 setup_xfail "*-*-*" CLLbs16901
371 send_gdb "print foo_instance1.overload1arg((float)arg11)\n"
373 -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
374 pass "print call overloaded func float arg"
376 -re ".*$gdb_prompt $" { fail "print call overloaded func float arg" }
377 timeout { fail "(timeout) print call overloaded func float arg" }
381 setup_xfail "*-*-*" CLLbs16901
383 send_gdb "print foo_instance1.overload1arg((double)arg12)\n"
385 -re ".\[0-9\]* = 12\r\n$gdb_prompt $" {
386 pass "print call overloaded func double arg"
388 -re ".*$gdb_prompt $" { fail "print call overloaded func double arg" }
389 timeout { fail "(timeout) print call overloaded func double arg" }
392 # Now some tests to see if we can list overloaded functions properly:
394 send_gdb "set listsize 1\n"
395 gdb_expect -re ".*$gdb_prompt $"
397 gdb_test "list foo::overloadfnarg(void)"\
398 ".*int foo::overloadfnarg.*\\(void\\).*" \
399 "print overloaded function with no args"
401 gdb_test "list foo::overloadfnarg(int)"\
402 "int foo::overloadfnarg.*\\(int arg\\).*" \
403 "print overloaded function with int arg"
405 gdb_test "list foo::overloadfnarg(int, int (*)(int))" \
406 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
407 "print overloaded function with function ptr args"
409 # This one crashes GDB. Don't know why yet.
410 gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
411 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
412 "print overloaded function with function ptr args - quotes around argument"