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