Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 1998-2016 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 | |
775e0f04 YQ |
42 | # Prevent symbol on address 0x0 being printed. |
43 | gdb_test_no_output "set print symbol off" | |
44 | ||
db144853 | 45 | gdb_test "up" ".*main.*" "up from marker1" |
c906108c | 46 | |
b1379776 MC |
47 | # Print the monster class type. |
48 | # See virtfunc.exp for a discussion of ptype. | |
49 | # | |
50 | # This is hairy to begin with. It is even more hairy because of the | |
51 | # XX_* alternate patterns to catch the KFAIL and XFAIL cases. | |
52 | ||
53 | set re_class "((struct|class) foo \{${ws}public:|struct foo \{)" | |
54 | set re_fields "int ifoo;${ws}const char ?\\* ?ccpfoo;" | |
55 | set XX_fields "int ifoo;${ws}char ?\\* ?ccpfoo;" | |
56 | set re_ctor "foo\\(int\\);${ws}foo\\(int, (char const|const char) ?\\*\\);${ws}foo\\(foo ?&\\);" | |
57 | set re_dtor "~foo\\((void|)\\);" | |
58 | set XX_dtor "~foo\\(int\\);" | |
59 | set re_methods "void foofunc\\(int\\);" | |
60 | set re_methods "${re_methods}${ws}void foofunc\\(int, signed char ?\\*\\);" | |
61 | set re_methods "${re_methods}${ws}int overload1arg\\((void|)\\);" | |
62 | set re_methods "${re_methods}${ws}int overload1arg\\(char\\);" | |
63 | set re_methods "${re_methods}${ws}int overload1arg\\(signed char\\);" | |
64 | set re_methods "${re_methods}${ws}int overload1arg\\(unsigned char\\);" | |
cec808ec KS |
65 | set re_methods "${re_methods}${ws}int overload1arg\\(short( int)?\\);" |
66 | set re_methods "${re_methods}${ws}int overload1arg\\((unsigned short|short unsigned)( int)?\\);" | |
b1379776 MC |
67 | set re_methods "${re_methods}${ws}int overload1arg\\(int\\);" |
68 | set re_methods "${re_methods}${ws}int overload1arg\\(unsigned int\\);" | |
cec808ec KS |
69 | set re_methods "${re_methods}${ws}int overload1arg\\(long( int)?\\);" |
70 | set re_methods "${re_methods}${ws}int overload1arg\\((unsigned long|long unsigned)( int)?\\);" | |
b1379776 MC |
71 | set re_methods "${re_methods}${ws}int overload1arg\\(float\\);" |
72 | set re_methods "${re_methods}${ws}int overload1arg\\(double\\);" | |
7062b0a0 SW |
73 | set re_methods "${re_methods}${ws}int overload1arg\\(int \\*\\);" |
74 | set re_methods "${re_methods}${ws}int overload1arg\\(void \\*\\);" | |
b1379776 MC |
75 | set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);" |
76 | set re_methods "${re_methods}${ws}int overloadfnarg\\(int\\);" | |
77 | set re_methods "${re_methods}${ws}int overloadfnarg\\(int, int ?\\(\\*\\) ?\\(int\\)\\);" | |
78 | set re_methods "${re_methods}${ws}int overloadargs\\(int\\);" | |
79 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int\\);" | |
80 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int\\);" | |
81 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int\\);" | |
82 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int\\);" | |
83 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int\\);" | |
84 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int\\);" | |
85 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int\\);" | |
86 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int\\);" | |
87 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int\\);" | |
88 | set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);" | |
89 | set re_synth "foo & operator=\\(foo const ?&\\);" | |
184ad485 MC |
90 | |
91 | gdb_test "print foo_instance1" "\\$\[0-9\]+ = \{ifoo = 111, ccpfoo = 0x0\}" | |
b1379776 MC |
92 | |
93 | gdb_test_multiple "ptype foo_instance1" "ptype foo_instance1" { | |
184ad485 | 94 | -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 |
95 | # gcc 2.95.3 -gstabs+, no "const" on "const char *" |
96 | # TODO: gdb.base/constvar.exp has XFAILed this kind of problem for a | |
97 | # long time, but an XFAIL really needs an external bug report. | |
98 | # -- chastain 2003-12-31 | |
184ad485 MC |
99 | # setup_xfail "*-*-*" |
100 | # fail "ptype foo_instance1" | |
101 | # TODO: this should be a KFAIL. | |
102 | pass "ptype foo_instance1 (shorter match)" | |
103 | } | |
104 | -re "type = $re_class${ws}$re_fields${ws}$re_synth${ws}$re_dtor${ws}$re_ctor${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
105 | # gcc 2.95.3 -gstabs+ if "const char *" ever gets fixed | |
106 | pass "ptype foo_instance1" | |
b1379776 | 107 | } |
184ad485 | 108 | -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$XX_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" { |
b1379776 | 109 | # gcc 3.3.2 -gdwarf-2, "~foo(int)" |
184ad485 MC |
110 | # TODO: kfail this |
111 | # kfail "gdb/1113" "ptype foo_instance1" | |
112 | pass "ptype foo_instance1 (shorter match)" | |
113 | } | |
114 | -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
115 | # gcc 3.3.2 -gdwarf-2, if the dtor bug gets fixed | |
116 | # gcc HEAD -gdwarf-2 (abi-2) | |
117 | # TODO: just pass this | |
118 | pass "ptype foo_instance1 (shorter match)" | |
119 | } | |
120 | -re "type = $re_class${ws}$re_fields${ws}$re_synth${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" { | |
121 | # gcc 3.3.2 -gstabs+ | |
122 | # TODO: enough with the "shorter match" | |
123 | pass "ptype foo_instance1 (shorter match)" | |
124 | } | |
125 | -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods${ws}$re_synth$nl\}$nl$gdb_prompt $" { | |
126 | # gcc HEAD -gstabs+ (abi-2) | |
8f25f06b | 127 | pass "ptype foo_instance1 (shorter match)" |
b1379776 MC |
128 | } |
129 | } | |
c906108c | 130 | |
b1379776 MC |
131 | # Print variables and method calls. |
132 | # This is a walk in the park. | |
133 | ||
b1379776 MC |
134 | gdb_test "print foo_instance2" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}" |
135 | gdb_test "print foo_instance3" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}" | |
136 | ||
137 | gdb_test "print foo_instance1.overloadargs(1)" "\\$\[0-9\]+ = 1" \ | |
138 | "print call overloaded func 1 arg" | |
9e0b60a8 | 139 | |
9ce98649 TT |
140 | # Regression test for overloading with function pointer type. |
141 | gdb_test "print foo_instance1.overloadfnarg(23, intintfunc)" " = 23" | |
142 | ||
5624293a JB |
143 | # If GDB fails to restore the selected frame properly after the |
144 | # inferior function call above (see GDB PR 1155 for an explanation of | |
145 | # why this might happen), all the subsequent tests will fail. We | |
146 | # should detect and report that failure, but let the marker call | |
147 | # finish so that the rest of the tests can run undisturbed. | |
b1379776 | 148 | |
5624293a JB |
149 | gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" { |
150 | -re "#0 marker1.*$gdb_prompt $" { | |
151 | setup_kfail "gdb/1155" s390-*-linux-gnu | |
152 | fail "re-selected 'main' frame after inferior call" | |
93201743 | 153 | gdb_test "finish" ".*main.*at .*overload.cc:.*// marker1-returns-here.*" \ |
5624293a JB |
154 | "finish call to marker1" |
155 | } | |
156 | -re "#1 ($hex in )?main.*$gdb_prompt $" { | |
157 | pass "re-selected 'main' frame after inferior call" | |
158 | } | |
159 | } | |
160 | ||
b1379776 MC |
161 | gdb_test "print foo_instance1.overloadargs(1, 2)" \ |
162 | "\\$\[0-9\]+ = 2" \ | |
163 | "print call overloaded func 2 args" | |
5624293a | 164 | |
b1379776 MC |
165 | gdb_test "print foo_instance1.overloadargs(1, 2, 3)" \ |
166 | "\\$\[0-9\]+ = 3" \ | |
167 | "print call overloaded func 3 args" | |
c2c6d25f | 168 | |
b1379776 MC |
169 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4)" \ |
170 | "\\$\[0-9\]+ = 4" \ | |
171 | "print call overloaded func 4 args" | |
c2c6d25f | 172 | |
b1379776 MC |
173 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5)" \ |
174 | "\\$\[0-9\]+ = 5" \ | |
175 | "print call overloaded func 5 args" | |
176 | ||
177 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)" \ | |
178 | "\\$\[0-9\]+ = 6" \ | |
179 | "print call overloaded func 6 args" | |
180 | ||
181 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)" \ | |
182 | "\\$\[0-9\]+ = 7" \ | |
183 | "print call overloaded func 7 args" | |
cbfa24cd | 184 | |
b1379776 MC |
185 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)" \ |
186 | "\\$\[0-9\]+ = 8" \ | |
187 | "print call overloaded func 8 args" | |
188 | ||
189 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)" \ | |
190 | "\\$\[0-9\]+ = 9" \ | |
191 | "print call overloaded func 9 args" | |
192 | ||
193 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" \ | |
194 | "\\$\[0-9\]+ = 10" \ | |
195 | "print call overloaded func 10 args" | |
196 | ||
197 | gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)" \ | |
198 | "\\$\[0-9\]+ = 11" \ | |
199 | "print call overloaded func 11 args" | |
200 | ||
201 | gdb_test "print foo_instance1.overload1arg()" \ | |
202 | "\\$\[0-9\]+ = 1" \ | |
203 | "print call overloaded func void arg" | |
204 | ||
205 | gdb_test "print foo_instance1.overload1arg((char)arg2)" \ | |
206 | "\\$\[0-9\]+ = 2" \ | |
207 | "print call overloaded func char arg" | |
208 | ||
209 | gdb_test "print foo_instance1.overload1arg((signed char)arg3)" \ | |
210 | "\\$\[0-9\]+ = 3" \ | |
211 | "print call overloaded func signed char arg" | |
212 | ||
213 | gdb_test "print foo_instance1.overload1arg((unsigned char)arg4)" \ | |
214 | "\\$\[0-9\]+ = 4" \ | |
215 | "print call overloaded func unsigned char arg" | |
216 | ||
217 | gdb_test "print foo_instance1.overload1arg((short)arg5)" \ | |
218 | "\\$\[0-9\]+ = 5" \ | |
219 | "print call overloaded func short arg" | |
220 | ||
221 | gdb_test "print foo_instance1.overload1arg((unsigned short)arg6)" \ | |
222 | "\\$\[0-9\]+ = 6" \ | |
223 | "print call overloaded func unsigned short arg" | |
224 | ||
225 | gdb_test "print foo_instance1.overload1arg((int)arg7)" \ | |
226 | "\\$\[0-9\]+ = 7" \ | |
227 | "print call overloaded func int arg" | |
228 | ||
229 | gdb_test "print foo_instance1.overload1arg((unsigned int)arg8)" \ | |
230 | "\\$\[0-9\]+ = 8" \ | |
231 | "print call overloaded func unsigned int arg" | |
232 | ||
233 | gdb_test "print foo_instance1.overload1arg((long)arg9)" \ | |
234 | "\\$\[0-9\]+ = 9" \ | |
235 | "print call overloaded func long arg" | |
236 | ||
237 | gdb_test "print foo_instance1.overload1arg((unsigned long)arg10)" \ | |
238 | "\\$\[0-9\]+ = 10" \ | |
239 | "print call overloaded func unsigned long arg" | |
240 | ||
241 | gdb_test "print foo_instance1.overload1arg((float)arg11)" \ | |
242 | "\\$\[0-9\]+ = 11" \ | |
243 | "print call overloaded func float arg" | |
244 | ||
245 | gdb_test "print foo_instance1.overload1arg((double)arg12)" \ | |
246 | "\\$\[0-9\]+ = 12" \ | |
247 | "print call overloaded func double arg" | |
248 | ||
7062b0a0 SW |
249 | gdb_test "print foo_instance1.overload1arg(&arg13)" \ |
250 | "\\$\[0-9\]+ = 13" \ | |
251 | "print call overloaded func int\\* arg" | |
252 | ||
253 | gdb_test "print foo_instance1.overload1arg(&arg14)" \ | |
254 | "\\$\[0-9\]+ = 14" \ | |
255 | "print call overloaded func char\\* arg" | |
256 | ||
a9d5ef47 SW |
257 | gdb_test "print bar(a)" "= 11" |
258 | gdb_test "print bar(b)" "= 22" | |
259 | gdb_test "print bar(c)" "= 22" | |
260 | gdb_test "print bar(d)" "= 22" | |
261 | ||
b1379776 MC |
262 | # --- |
263 | ||
264 | # List overloaded functions. | |
265 | ||
266 | # The void case is tricky because some compilers say "(void)" | |
267 | # and some compilers say "()". | |
268 | ||
35ec993f | 269 | gdb_test_no_output "set listsize 1" "" |
b1379776 | 270 | gdb_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 | 285 | gdb_test "list foo::overloadfnarg(int)" \ |
c2c6d25f | 286 | "int foo::overloadfnarg.*\\(int arg\\).*" \ |
cbfa24cd | 287 | "list overloaded function with int arg" |
c2c6d25f JM |
288 | |
289 | gdb_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 |
293 | gdb_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 | |
791dfb64 DJ |
297 | # Test list with filename. |
298 | ||
299 | gdb_test "list ${srcfile}:intToChar" "int intToChar.*" | |
300 | gdb_test "list ${srcfile}:intToChar(char)" "int intToChar.*" | |
301 | gdb_test "list ${srcfile}:'intToChar(char)'" "int intToChar.*" | |
302 | gdb_test "list '${srcfile}:intToChar(char)'" "int intToChar.*" | |
0c199f28 KS |
303 | gdb_test "list '${srcfile}':intToChar(char)" "int intToChar.*" |
304 | gdb_test "list '${srcfile}':'intToChar(char)'" "int intToChar.*" | |
791dfb64 | 305 | |
c26106c4 | 306 | # And with filename and namespace. |
791dfb64 | 307 | |
c26106c4 TT |
308 | gdb_test "list ${srcfile}:foo::overloadfnarg(int)" "int foo::overloadfnarg.*}" |
309 | gdb_test "list ${srcfile}:'foo::overloadfnarg(int)'" "int foo::overloadfnarg.*}" | |
791dfb64 | 310 | |
8d577d32 DC |
311 | # Now some tests to see how overloading and namespaces interact. |
312 | ||
313 | gdb_test "print overloadNamespace(1)" ".\[0-9\]* = 1" | |
314 | gdb_test "print overloadNamespace('a')" ".\[0-9\]* = 1" | |
315 | gdb_test "print overloadNamespace(dummyInstance)" ".\[0-9\]* = 2" | |
316 | ||
714f19d5 TT |
317 | # Static methods. |
318 | gdb_test "print K::staticoverload ()" " = 1" | |
319 | gdb_test "print K::staticoverload (2)" " = 2" | |
320 | gdb_test "print K::staticoverload (2, 3)" " = 5" | |
321 | ||
322 | # Namespace-qualified functions. | |
323 | gdb_test "print N::nsoverload ()" " = 1" | |
324 | gdb_test "print N::nsoverload (2)" " = 2" | |
325 | gdb_test "print N::nsoverload (2, 3)" " = 5" | |
326 | ||
8d577d32 DC |
327 | if ![runto 'XXX::marker2'] then { |
328 | perror "couldn't run to XXX::marker2" | |
329 | continue | |
330 | } | |
331 | ||
332 | gdb_test "print overloadNamespace(1)" ".\[0-9\]* = 3" "print overloadNamespace(1) in XXX" | |
333 | gdb_test "print overloadNamespace('a')" ".\[0-9\]* = 3" "print overloadNamespace('a') in XXX" | |
334 | gdb_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 | ||
339 | gdb_test "print intToChar(1)" "\\$\[0-9\]+ = 297" | |
85feb311 KS |
340 | |
341 | # Test expression evaluation with overloaded methods | |
342 | gdb_test "print foo::overload1arg" \ | |
343 | "non-unique member `overload1arg' requires type instantiation" \ | |
344 | "print foo::overload1arg" | |
345 | ||
346 | gdb_test "print foo::overload1arg(char***)" \ | |
347 | "no member function matches that type instantiation" \ | |
348 | "print foo::overload1arg(char***)" | |
349 | ||
350 | gdb_test "print foo::overload1arg(void)" \ | |
493f3c00 | 351 | "\\$$decimal = {int \\(foo \\*( const|)\\)} $hex <foo::overload1arg\\(\\)>" \ |
85feb311 KS |
352 | "print foo::overload1arg(void)" |
353 | ||
354 | foreach 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 | } |