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