2004-02-02 David Carlton <carlton@kealia.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / overload.exp
CommitLineData
b1379776
MC
1# Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
2# Free Software Foundation, Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-gdb@prep.ai.mit.edu
20
21# written by Elena Zannoni (ezannoni@cygnus.com)
b1379776 22# Rewritten by Michael Chastain <mec.gnu@mindspring.com>
c906108c
SS
23
24# This file is part of the gdb testsuite
c906108c 25
b1379776 26# Tests for overloaded member functions.
c906108c
SS
27
28if $tracelevel then {
b1379776
MC
29 strace $tracelevel
30}
31
32set ws "\[\r\n\t \]+"
33set nl "\[\r\n\]+"
c906108c 34
c906108c
SS
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
c906108c
SS
48gdb_exit
49gdb_start
50gdb_reinitialize_dir $srcdir/$subdir
51gdb_load ${binfile}
52
b1379776 53# Set it up at a breakpoint so we can play with the variable values.
c906108c 54
db144853
MC
55if ![runto 'marker1'] then {
56 perror "couldn't run to marker1"
57 continue
58}
c906108c 59
db144853 60gdb_test "up" ".*main.*" "up from marker1"
c906108c 61
b1379776
MC
62# Print the monster class type.
63# See virtfunc.exp for a discussion of ptype.
64#
65# This is hairy to begin with. It is even more hairy because of the
66# XX_* alternate patterns to catch the KFAIL and XFAIL cases.
67
68set re_class "((struct|class) foo \{${ws}public:|struct foo \{)"
69set re_fields "int ifoo;${ws}const char ?\\* ?ccpfoo;"
70set XX_fields "int ifoo;${ws}char ?\\* ?ccpfoo;"
71set re_ctor "foo\\(int\\);${ws}foo\\(int, (char const|const char) ?\\*\\);${ws}foo\\(foo ?&\\);"
72set re_dtor "~foo\\((void|)\\);"
73set XX_dtor "~foo\\(int\\);"
74set re_methods "void foofunc\\(int\\);"
75set re_methods "${re_methods}${ws}void foofunc\\(int, signed char ?\\*\\);"
76set re_methods "${re_methods}${ws}int overload1arg\\((void|)\\);"
77set re_methods "${re_methods}${ws}int overload1arg\\(char\\);"
78set re_methods "${re_methods}${ws}int overload1arg\\(signed char\\);"
79set re_methods "${re_methods}${ws}int overload1arg\\(unsigned char\\);"
80set re_methods "${re_methods}${ws}int overload1arg\\(short\\);"
81set re_methods "${re_methods}${ws}int overload1arg\\(unsigned short\\);"
82set re_methods "${re_methods}${ws}int overload1arg\\(int\\);"
83set re_methods "${re_methods}${ws}int overload1arg\\(unsigned int\\);"
84set re_methods "${re_methods}${ws}int overload1arg\\(long\\);"
85set re_methods "${re_methods}${ws}int overload1arg\\(unsigned long\\);"
86set re_methods "${re_methods}${ws}int overload1arg\\(float\\);"
87set re_methods "${re_methods}${ws}int overload1arg\\(double\\);"
88set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);"
89set re_methods "${re_methods}${ws}int overloadfnarg\\(int\\);"
90set re_methods "${re_methods}${ws}int overloadfnarg\\(int, int ?\\(\\*\\) ?\\(int\\)\\);"
91set re_methods "${re_methods}${ws}int overloadargs\\(int\\);"
92set re_methods "${re_methods}${ws}int overloadargs\\(int, int\\);"
93set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int\\);"
94set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int\\);"
95set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int\\);"
96set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int\\);"
97set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int\\);"
98set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int\\);"
99set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int\\);"
100set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int\\);"
101set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);"
102set re_synth "foo & operator=\\(foo const ?&\\);"
184ad485
MC
103
104gdb_test "print foo_instance1" "\\$\[0-9\]+ = \{ifoo = 111, ccpfoo = 0x0\}"
b1379776
MC
105
106gdb_test_multiple "ptype foo_instance1" "ptype foo_instance1" {
184ad485
MC
107 -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
108 # gcc 2.95.3 -gdwarf-2
109 # TODO: this is not a quirk!
110 pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)"
9e0b60a8 111 }
184ad485 112 -re "type = $re_class${ws}$XX_fields${ws}$re_synth${ws}$re_dtor${ws}$re_ctor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
b1379776
MC
113 # gcc 2.95.3 -gstabs+, no "const" on "const char *"
114 # TODO: gdb.base/constvar.exp has XFAILed this kind of problem for a
115 # long time, but an XFAIL really needs an external bug report.
116 # -- chastain 2003-12-31
184ad485
MC
117 # setup_xfail "*-*-*"
118 # fail "ptype foo_instance1"
119 # TODO: this should be a KFAIL.
120 pass "ptype foo_instance1 (shorter match)"
121 }
122 -re "type = $re_class${ws}$re_fields${ws}$re_synth${ws}$re_dtor${ws}$re_ctor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
123 # gcc 2.95.3 -gstabs+ if "const char *" ever gets fixed
124 pass "ptype foo_instance1"
b1379776 125 }
184ad485 126 -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$XX_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
b1379776 127 # gcc 3.3.2 -gdwarf-2, "~foo(int)"
184ad485
MC
128 # TODO: kfail this
129 # kfail "gdb/1113" "ptype foo_instance1"
130 pass "ptype foo_instance1 (shorter match)"
131 }
132 -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
133 # gcc 3.3.2 -gdwarf-2, if the dtor bug gets fixed
134 # gcc HEAD -gdwarf-2 (abi-2)
135 # TODO: just pass this
136 pass "ptype foo_instance1 (shorter match)"
137 }
138 -re "type = $re_class${ws}$re_fields${ws}$re_synth${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
139 # gcc 3.3.2 -gstabs+
140 # TODO: enough with the "shorter match"
141 pass "ptype foo_instance1 (shorter match)"
142 }
143 -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods${ws}$re_synth$nl\}$nl$gdb_prompt $" {
144 # gcc HEAD -gstabs+ (abi-2)
8f25f06b 145 pass "ptype foo_instance1 (shorter match)"
b1379776
MC
146 }
147}
c906108c 148
b1379776
MC
149# Print variables and method calls.
150# This is a walk in the park.
151
b1379776
MC
152gdb_test "print foo_instance2" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}"
153gdb_test "print foo_instance3" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}"
154
155gdb_test "print foo_instance1.overloadargs(1)" "\\$\[0-9\]+ = 1" \
156 "print call overloaded func 1 arg"
9e0b60a8 157
5624293a
JB
158# If GDB fails to restore the selected frame properly after the
159# inferior function call above (see GDB PR 1155 for an explanation of
160# why this might happen), all the subsequent tests will fail. We
161# should detect and report that failure, but let the marker call
162# finish so that the rest of the tests can run undisturbed.
b1379776 163
5624293a
JB
164gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
165 -re "#0 marker1.*$gdb_prompt $" {
166 setup_kfail "gdb/1155" s390-*-linux-gnu
167 fail "re-selected 'main' frame after inferior call"
93201743 168 gdb_test "finish" ".*main.*at .*overload.cc:.*// marker1-returns-here.*" \
5624293a
JB
169 "finish call to marker1"
170 }
171 -re "#1 ($hex in )?main.*$gdb_prompt $" {
172 pass "re-selected 'main' frame after inferior call"
173 }
174}
175
b1379776
MC
176gdb_test "print foo_instance1.overloadargs(1, 2)" \
177 "\\$\[0-9\]+ = 2" \
178 "print call overloaded func 2 args"
5624293a 179
b1379776
MC
180gdb_test "print foo_instance1.overloadargs(1, 2, 3)" \
181 "\\$\[0-9\]+ = 3" \
182 "print call overloaded func 3 args"
c2c6d25f 183
b1379776
MC
184gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4)" \
185 "\\$\[0-9\]+ = 4" \
186 "print call overloaded func 4 args"
c2c6d25f 187
b1379776
MC
188gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5)" \
189 "\\$\[0-9\]+ = 5" \
190 "print call overloaded func 5 args"
191
192gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)" \
193 "\\$\[0-9\]+ = 6" \
194 "print call overloaded func 6 args"
195
196gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)" \
197 "\\$\[0-9\]+ = 7" \
198 "print call overloaded func 7 args"
cbfa24cd 199
b1379776
MC
200gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)" \
201 "\\$\[0-9\]+ = 8" \
202 "print call overloaded func 8 args"
203
204gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)" \
205 "\\$\[0-9\]+ = 9" \
206 "print call overloaded func 9 args"
207
208gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" \
209 "\\$\[0-9\]+ = 10" \
210 "print call overloaded func 10 args"
211
212gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)" \
213 "\\$\[0-9\]+ = 11" \
214 "print call overloaded func 11 args"
215
216gdb_test "print foo_instance1.overload1arg()" \
217 "\\$\[0-9\]+ = 1" \
218 "print call overloaded func void arg"
219
220gdb_test "print foo_instance1.overload1arg((char)arg2)" \
221 "\\$\[0-9\]+ = 2" \
222 "print call overloaded func char arg"
223
224gdb_test "print foo_instance1.overload1arg((signed char)arg3)" \
225 "\\$\[0-9\]+ = 3" \
226 "print call overloaded func signed char arg"
227
228gdb_test "print foo_instance1.overload1arg((unsigned char)arg4)" \
229 "\\$\[0-9\]+ = 4" \
230 "print call overloaded func unsigned char arg"
231
232gdb_test "print foo_instance1.overload1arg((short)arg5)" \
233 "\\$\[0-9\]+ = 5" \
234 "print call overloaded func short arg"
235
236gdb_test "print foo_instance1.overload1arg((unsigned short)arg6)" \
237 "\\$\[0-9\]+ = 6" \
238 "print call overloaded func unsigned short arg"
239
240gdb_test "print foo_instance1.overload1arg((int)arg7)" \
241 "\\$\[0-9\]+ = 7" \
242 "print call overloaded func int arg"
243
244gdb_test "print foo_instance1.overload1arg((unsigned int)arg8)" \
245 "\\$\[0-9\]+ = 8" \
246 "print call overloaded func unsigned int arg"
247
248gdb_test "print foo_instance1.overload1arg((long)arg9)" \
249 "\\$\[0-9\]+ = 9" \
250 "print call overloaded func long arg"
251
252gdb_test "print foo_instance1.overload1arg((unsigned long)arg10)" \
253 "\\$\[0-9\]+ = 10" \
254 "print call overloaded func unsigned long arg"
255
256gdb_test "print foo_instance1.overload1arg((float)arg11)" \
257 "\\$\[0-9\]+ = 11" \
258 "print call overloaded func float arg"
259
260gdb_test "print foo_instance1.overload1arg((double)arg12)" \
261 "\\$\[0-9\]+ = 12" \
262 "print call overloaded func double arg"
263
264# ---
265
266# List overloaded functions.
267
268# The void case is tricky because some compilers say "(void)"
269# and some compilers say "()".
270
271gdb_test "set listsize 1" "" ""
272gdb_test_multiple "info func overloadfnarg" "list overloaded function with no args" {
cbfa24cd 273 -re ".*overloadfnarg\\(void\\).*$gdb_prompt $" {
b1379776 274 # gcc 2
cbfa24cd
MS
275 gdb_test "list foo::overloadfnarg(void)"\
276 ".*int foo::overloadfnarg.*\\(void\\).*" \
277 "list overloaded function with no args"
278 }
279 -re ".*overloadfnarg\\(\\).*$gdb_prompt $" {
b1379776 280 # gcc 3
cbfa24cd
MS
281 gdb_test "list foo::overloadfnarg()"\
282 ".*int foo::overloadfnarg.*\\(void\\).*" \
283 "list overloaded function with no args"
284 }
cbfa24cd 285}
c2c6d25f 286
b1379776 287gdb_test "list foo::overloadfnarg(int)" \
c2c6d25f 288 "int foo::overloadfnarg.*\\(int arg\\).*" \
cbfa24cd 289 "list overloaded function with int arg"
c2c6d25f
JM
290
291gdb_test "list foo::overloadfnarg(int, int (*)(int))" \
292 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
cbfa24cd 293 "list overloaded function with function ptr args"
c2c6d25f 294
c2c6d25f
JM
295gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
296 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
cbfa24cd 297 "list overloaded function with function ptr args - quotes around argument"
1c5cb38e 298
8d577d32
DC
299# Now some tests to see how overloading and namespaces interact.
300
301gdb_test "print overloadNamespace(1)" ".\[0-9\]* = 1"
302gdb_test "print overloadNamespace('a')" ".\[0-9\]* = 1"
303gdb_test "print overloadNamespace(dummyInstance)" ".\[0-9\]* = 2"
304
305if ![runto 'XXX::marker2'] then {
306 perror "couldn't run to XXX::marker2"
307 continue
308}
309
310gdb_test "print overloadNamespace(1)" ".\[0-9\]* = 3" "print overloadNamespace(1) in XXX"
311gdb_test "print overloadNamespace('a')" ".\[0-9\]* = 3" "print overloadNamespace('a') in XXX"
312gdb_test "print overloadNamespace(dummyInstance)" ".\[0-9\]* = 2" "print overloadNamespace(dummyInstance) in XXX"
313
b1379776
MC
314# One last mysterious test.
315# I wonder what this is for?
316
317gdb_test "print intToChar(1)" "\\$\[0-9\]+ = 297"
This page took 0.475895 seconds and 4 git commands to generate.