* config/tc-mips.c (warn_nops): Remove static variable.
[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.
184ad485 67# TODO: And then hair^3 to reutrn the same results as the old tests.
b1379776
MC
68
69set re_class "((struct|class) foo \{${ws}public:|struct foo \{)"
70set re_fields "int ifoo;${ws}const char ?\\* ?ccpfoo;"
71set XX_fields "int ifoo;${ws}char ?\\* ?ccpfoo;"
72set re_ctor "foo\\(int\\);${ws}foo\\(int, (char const|const char) ?\\*\\);${ws}foo\\(foo ?&\\);"
73set re_dtor "~foo\\((void|)\\);"
74set XX_dtor "~foo\\(int\\);"
75set re_methods "void foofunc\\(int\\);"
76set re_methods "${re_methods}${ws}void foofunc\\(int, signed char ?\\*\\);"
77set re_methods "${re_methods}${ws}int overload1arg\\((void|)\\);"
78set re_methods "${re_methods}${ws}int overload1arg\\(char\\);"
79set re_methods "${re_methods}${ws}int overload1arg\\(signed char\\);"
80set re_methods "${re_methods}${ws}int overload1arg\\(unsigned char\\);"
81set re_methods "${re_methods}${ws}int overload1arg\\(short\\);"
82set re_methods "${re_methods}${ws}int overload1arg\\(unsigned short\\);"
83set re_methods "${re_methods}${ws}int overload1arg\\(int\\);"
84set re_methods "${re_methods}${ws}int overload1arg\\(unsigned int\\);"
85set re_methods "${re_methods}${ws}int overload1arg\\(long\\);"
86set re_methods "${re_methods}${ws}int overload1arg\\(unsigned long\\);"
87set re_methods "${re_methods}${ws}int overload1arg\\(float\\);"
88set re_methods "${re_methods}${ws}int overload1arg\\(double\\);"
89set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);"
90set re_methods "${re_methods}${ws}int overloadfnarg\\(int\\);"
91set re_methods "${re_methods}${ws}int overloadfnarg\\(int, int ?\\(\\*\\) ?\\(int\\)\\);"
92set re_methods "${re_methods}${ws}int overloadargs\\(int\\);"
93set re_methods "${re_methods}${ws}int overloadargs\\(int, int\\);"
94set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int\\);"
95set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int\\);"
96set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int\\);"
97set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int\\);"
98set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int\\);"
99set re_methods "${re_methods}${ws}int overloadargs\\(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\\);"
101set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int\\);"
102set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);"
103set re_synth "foo & operator=\\(foo const ?&\\);"
184ad485
MC
104
105gdb_test "print foo_instance1" "\\$\[0-9\]+ = \{ifoo = 111, ccpfoo = 0x0\}"
b1379776
MC
106
107gdb_test_multiple "ptype foo_instance1" "ptype foo_instance1" {
184ad485
MC
108 -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
109 # gcc 2.95.3 -gdwarf-2
110 # TODO: this is not a quirk!
111 pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)"
9e0b60a8 112 }
184ad485 113 -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
114 # gcc 2.95.3 -gstabs+, no "const" on "const char *"
115 # TODO: gdb.base/constvar.exp has XFAILed this kind of problem for a
116 # long time, but an XFAIL really needs an external bug report.
117 # -- chastain 2003-12-31
184ad485
MC
118 # setup_xfail "*-*-*"
119 # fail "ptype foo_instance1"
120 # TODO: this should be a KFAIL.
121 pass "ptype foo_instance1 (shorter match)"
122 }
123 -re "type = $re_class${ws}$re_fields${ws}$re_synth${ws}$re_dtor${ws}$re_ctor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
124 # gcc 2.95.3 -gstabs+ if "const char *" ever gets fixed
125 pass "ptype foo_instance1"
b1379776 126 }
184ad485 127 -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$XX_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
b1379776 128 # gcc 3.3.2 -gdwarf-2, "~foo(int)"
184ad485
MC
129 # TODO: kfail this
130 # kfail "gdb/1113" "ptype foo_instance1"
131 pass "ptype foo_instance1 (shorter match)"
132 }
133 -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
134 # gcc 3.3.2 -gdwarf-2, if the dtor bug gets fixed
135 # gcc HEAD -gdwarf-2 (abi-2)
136 # TODO: just pass this
137 pass "ptype foo_instance1 (shorter match)"
138 }
139 -re "type = $re_class${ws}$re_fields${ws}$re_synth${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
140 # gcc 3.3.2 -gstabs+
141 # TODO: enough with the "shorter match"
142 pass "ptype foo_instance1 (shorter match)"
143 }
144 -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods${ws}$re_synth$nl\}$nl$gdb_prompt $" {
145 # gcc HEAD -gstabs+ (abi-2)
146 # TODO: just pass this
147 # pass "ptype foo_instance1"
148 fail "ptype foo_instance1"
b1379776
MC
149 }
150}
c906108c 151
b1379776
MC
152# Print variables and method calls.
153# This is a walk in the park.
154
b1379776
MC
155gdb_test "print foo_instance2" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}"
156gdb_test "print foo_instance3" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}"
157
158gdb_test "print foo_instance1.overloadargs(1)" "\\$\[0-9\]+ = 1" \
159 "print call overloaded func 1 arg"
9e0b60a8 160
5624293a
JB
161# If GDB fails to restore the selected frame properly after the
162# inferior function call above (see GDB PR 1155 for an explanation of
163# why this might happen), all the subsequent tests will fail. We
164# should detect and report that failure, but let the marker call
165# finish so that the rest of the tests can run undisturbed.
b1379776 166
5624293a
JB
167gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
168 -re "#0 marker1.*$gdb_prompt $" {
169 setup_kfail "gdb/1155" s390-*-linux-gnu
170 fail "re-selected 'main' frame after inferior call"
93201743 171 gdb_test "finish" ".*main.*at .*overload.cc:.*// marker1-returns-here.*" \
5624293a
JB
172 "finish call to marker1"
173 }
174 -re "#1 ($hex in )?main.*$gdb_prompt $" {
175 pass "re-selected 'main' frame after inferior call"
176 }
177}
178
b1379776
MC
179gdb_test "print foo_instance1.overloadargs(1, 2)" \
180 "\\$\[0-9\]+ = 2" \
181 "print call overloaded func 2 args"
5624293a 182
b1379776
MC
183gdb_test "print foo_instance1.overloadargs(1, 2, 3)" \
184 "\\$\[0-9\]+ = 3" \
185 "print call overloaded func 3 args"
c2c6d25f 186
b1379776
MC
187gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4)" \
188 "\\$\[0-9\]+ = 4" \
189 "print call overloaded func 4 args"
c2c6d25f 190
b1379776
MC
191gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5)" \
192 "\\$\[0-9\]+ = 5" \
193 "print call overloaded func 5 args"
194
195gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)" \
196 "\\$\[0-9\]+ = 6" \
197 "print call overloaded func 6 args"
198
199gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)" \
200 "\\$\[0-9\]+ = 7" \
201 "print call overloaded func 7 args"
cbfa24cd 202
b1379776
MC
203gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)" \
204 "\\$\[0-9\]+ = 8" \
205 "print call overloaded func 8 args"
206
207gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)" \
208 "\\$\[0-9\]+ = 9" \
209 "print call overloaded func 9 args"
210
211gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" \
212 "\\$\[0-9\]+ = 10" \
213 "print call overloaded func 10 args"
214
215gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)" \
216 "\\$\[0-9\]+ = 11" \
217 "print call overloaded func 11 args"
218
219gdb_test "print foo_instance1.overload1arg()" \
220 "\\$\[0-9\]+ = 1" \
221 "print call overloaded func void arg"
222
223gdb_test "print foo_instance1.overload1arg((char)arg2)" \
224 "\\$\[0-9\]+ = 2" \
225 "print call overloaded func char arg"
226
227gdb_test "print foo_instance1.overload1arg((signed char)arg3)" \
228 "\\$\[0-9\]+ = 3" \
229 "print call overloaded func signed char arg"
230
231gdb_test "print foo_instance1.overload1arg((unsigned char)arg4)" \
232 "\\$\[0-9\]+ = 4" \
233 "print call overloaded func unsigned char arg"
234
235gdb_test "print foo_instance1.overload1arg((short)arg5)" \
236 "\\$\[0-9\]+ = 5" \
237 "print call overloaded func short arg"
238
239gdb_test "print foo_instance1.overload1arg((unsigned short)arg6)" \
240 "\\$\[0-9\]+ = 6" \
241 "print call overloaded func unsigned short arg"
242
243gdb_test "print foo_instance1.overload1arg((int)arg7)" \
244 "\\$\[0-9\]+ = 7" \
245 "print call overloaded func int arg"
246
247gdb_test "print foo_instance1.overload1arg((unsigned int)arg8)" \
248 "\\$\[0-9\]+ = 8" \
249 "print call overloaded func unsigned int arg"
250
251gdb_test "print foo_instance1.overload1arg((long)arg9)" \
252 "\\$\[0-9\]+ = 9" \
253 "print call overloaded func long arg"
254
255gdb_test "print foo_instance1.overload1arg((unsigned long)arg10)" \
256 "\\$\[0-9\]+ = 10" \
257 "print call overloaded func unsigned long arg"
258
259gdb_test "print foo_instance1.overload1arg((float)arg11)" \
260 "\\$\[0-9\]+ = 11" \
261 "print call overloaded func float arg"
262
263gdb_test "print foo_instance1.overload1arg((double)arg12)" \
264 "\\$\[0-9\]+ = 12" \
265 "print call overloaded func double arg"
266
267# ---
268
269# List overloaded functions.
270
271# The void case is tricky because some compilers say "(void)"
272# and some compilers say "()".
273
274gdb_test "set listsize 1" "" ""
275gdb_test_multiple "info func overloadfnarg" "list overloaded function with no args" {
cbfa24cd 276 -re ".*overloadfnarg\\(void\\).*$gdb_prompt $" {
b1379776 277 # gcc 2
cbfa24cd
MS
278 gdb_test "list foo::overloadfnarg(void)"\
279 ".*int foo::overloadfnarg.*\\(void\\).*" \
280 "list overloaded function with no args"
281 }
282 -re ".*overloadfnarg\\(\\).*$gdb_prompt $" {
b1379776 283 # gcc 3
cbfa24cd
MS
284 gdb_test "list foo::overloadfnarg()"\
285 ".*int foo::overloadfnarg.*\\(void\\).*" \
286 "list overloaded function with no args"
287 }
cbfa24cd 288}
c2c6d25f 289
b1379776 290gdb_test "list foo::overloadfnarg(int)" \
c2c6d25f 291 "int foo::overloadfnarg.*\\(int arg\\).*" \
cbfa24cd 292 "list overloaded function with int arg"
c2c6d25f
JM
293
294gdb_test "list foo::overloadfnarg(int, int (*)(int))" \
295 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
cbfa24cd 296 "list overloaded function with function ptr args"
c2c6d25f 297
c2c6d25f
JM
298gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
299 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
cbfa24cd 300 "list overloaded function with function ptr args - quotes around argument"
1c5cb38e 301
b1379776
MC
302# One last mysterious test.
303# I wonder what this is for?
304
305gdb_test "print intToChar(1)" "\\$\[0-9\]+ = 297"
This page took 0.408037 seconds and 4 git commands to generate.