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