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