e4e3c43653cb91552072e9184b9de752388eb00a
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / overload.exp
1 # Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
2 # Free Software Foundation, Inc.
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)
22 # Rewritten by Michael Chastain <mec.gnu@mindspring.com>
23
24 # This file is part of the gdb testsuite
25
26 # Tests for overloaded member functions.
27
28 if $tracelevel then {
29 strace $tracelevel
30 }
31
32 set ws "\[\r\n\t \]+"
33 set nl "\[\r\n\]+"
34
35 set prms_id 0
36 set bug_id 0
37
38 if { [skip_cplus_tests] } { continue }
39
40 set testfile "overload"
41 set srcfile ${testfile}.cc
42 set binfile ${objdir}/${subdir}/${testfile}
43
44 if { [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
48 gdb_exit
49 gdb_start
50 gdb_reinitialize_dir $srcdir/$subdir
51 gdb_load ${binfile}
52
53 # Set it up at a breakpoint so we can play with the variable values.
54
55 if ![runto 'marker1'] then {
56 perror "couldn't run to marker1"
57 continue
58 }
59
60 gdb_test "up" ".*main.*" "up from marker1"
61
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.
67
68 set re_class "((struct|class) foo \{${ws}public:|struct foo \{)"
69 set re_fields "int ifoo;${ws}const char ?\\* ?ccpfoo;"
70 set XX_fields "int ifoo;${ws}char ?\\* ?ccpfoo;"
71 set re_ctor "foo\\(int\\);${ws}foo\\(int, (char const|const char) ?\\*\\);${ws}foo\\(foo ?&\\);"
72 set re_dtor "~foo\\((void|)\\);"
73 set XX_dtor "~foo\\(int\\);"
74 set re_methods "void foofunc\\(int\\);"
75 set re_methods "${re_methods}${ws}void foofunc\\(int, signed char ?\\*\\);"
76 set re_methods "${re_methods}${ws}int overload1arg\\((void|)\\);"
77 set re_methods "${re_methods}${ws}int overload1arg\\(char\\);"
78 set re_methods "${re_methods}${ws}int overload1arg\\(signed char\\);"
79 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned char\\);"
80 set re_methods "${re_methods}${ws}int overload1arg\\(short\\);"
81 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned short\\);"
82 set re_methods "${re_methods}${ws}int overload1arg\\(int\\);"
83 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned int\\);"
84 set re_methods "${re_methods}${ws}int overload1arg\\(long\\);"
85 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned long\\);"
86 set re_methods "${re_methods}${ws}int overload1arg\\(float\\);"
87 set re_methods "${re_methods}${ws}int overload1arg\\(double\\);"
88 set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);"
89 set re_methods "${re_methods}${ws}int overloadfnarg\\(int\\);"
90 set re_methods "${re_methods}${ws}int overloadfnarg\\(int, int ?\\(\\*\\) ?\\(int\\)\\);"
91 set re_methods "${re_methods}${ws}int overloadargs\\(int\\);"
92 set re_methods "${re_methods}${ws}int overloadargs\\(int, int\\);"
93 set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int\\);"
94 set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int\\);"
95 set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int\\);"
96 set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int\\);"
97 set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int\\);"
98 set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int\\);"
99 set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int\\);"
100 set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int\\);"
101 set re_methods "${re_methods}${ws}int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);"
102 set re_synth "foo & operator=\\(foo const ?&\\);"
103 set re_all_m "($re_ctor${ws}$re_dtor${ws}$re_methods"
104 set re_all_m "$re_all_m|$re_ctor${ws}$re_dtor${ws}$re_methods${ws}$re_synth"
105 set re_all_m "$re_all_m|$re_synth${ws}$re_ctor${ws}$re_dtor${ws}$re_methods"
106 set re_all_m "$re_all_m|$re_synth${ws}$re_dtor${ws}$re_ctor${ws}$re_methods"
107 set re_all_m "$re_all_m)"
108 set XX_all_m "$re_ctor${ws}$XX_dtor${ws}$re_methods"
109
110 gdb_test_multiple "ptype foo_instance1" "ptype foo_instance1" {
111 -re "type = $re_class${ws}$re_fields${ws}$re_all_m$nl\}$nl$gdb_prompt $" {
112 pass "ptype foo_instance1"
113 }
114 -re "type = $re_class${ws}$XX_fields${ws}$re_all_m$nl\}$nl$gdb_prompt $" {
115 # gcc 2.95.3 -gstabs+, no "const" on "const char *"
116 # TODO: gdb.base/constvar.exp has XFAILed this kind of problem for a
117 # long time, but an XFAIL really needs an external bug report.
118 # -- chastain 2003-12-31
119 setup_xfail "*-*-*"
120 fail "ptype foo_instance1"
121 }
122 -re "type = $re_class${ws}$re_fields${ws}$XX_all_m$nl\}$nl$gdb_prompt $" {
123 # gcc 3.3.2 -gdwarf-2, "~foo(int)"
124 kfail "gdb/1113" "ptype foo_instance1"
125 }
126 }
127
128 # Print variables and method calls.
129 # This is a walk in the park.
130
131 gdb_test "print foo_instance1" "\\$\[0-9\]+ = \{ifoo = 111, ccpfoo = 0x0\}"
132 gdb_test "print foo_instance2" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}"
133 gdb_test "print foo_instance3" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\}"
134
135 gdb_test "print foo_instance1.overloadargs(1)" "\\$\[0-9\]+ = 1" \
136 "print call overloaded func 1 arg"
137
138 # If GDB fails to restore the selected frame properly after the
139 # inferior function call above (see GDB PR 1155 for an explanation of
140 # why this might happen), all the subsequent tests will fail. We
141 # should detect and report that failure, but let the marker call
142 # finish so that the rest of the tests can run undisturbed.
143
144 gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
145 -re "#0 marker1.*$gdb_prompt $" {
146 setup_kfail "gdb/1155" s390-*-linux-gnu
147 fail "re-selected 'main' frame after inferior call"
148 gdb_test "finish" ".*main.*at .*overload.cc:.*// marker1-returns-here.*" \
149 "finish call to marker1"
150 }
151 -re "#1 ($hex in )?main.*$gdb_prompt $" {
152 pass "re-selected 'main' frame after inferior call"
153 }
154 }
155
156 gdb_test "print foo_instance1.overloadargs(1, 2)" \
157 "\\$\[0-9\]+ = 2" \
158 "print call overloaded func 2 args"
159
160 gdb_test "print foo_instance1.overloadargs(1, 2, 3)" \
161 "\\$\[0-9\]+ = 3" \
162 "print call overloaded func 3 args"
163
164 gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4)" \
165 "\\$\[0-9\]+ = 4" \
166 "print call overloaded func 4 args"
167
168 gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5)" \
169 "\\$\[0-9\]+ = 5" \
170 "print call overloaded func 5 args"
171
172 gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)" \
173 "\\$\[0-9\]+ = 6" \
174 "print call overloaded func 6 args"
175
176 gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)" \
177 "\\$\[0-9\]+ = 7" \
178 "print call overloaded func 7 args"
179
180 gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)" \
181 "\\$\[0-9\]+ = 8" \
182 "print call overloaded func 8 args"
183
184 gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)" \
185 "\\$\[0-9\]+ = 9" \
186 "print call overloaded func 9 args"
187
188 gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" \
189 "\\$\[0-9\]+ = 10" \
190 "print call overloaded func 10 args"
191
192 gdb_test "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)" \
193 "\\$\[0-9\]+ = 11" \
194 "print call overloaded func 11 args"
195
196 gdb_test "print foo_instance1.overload1arg()" \
197 "\\$\[0-9\]+ = 1" \
198 "print call overloaded func void arg"
199
200 gdb_test "print foo_instance1.overload1arg((char)arg2)" \
201 "\\$\[0-9\]+ = 2" \
202 "print call overloaded func char arg"
203
204 gdb_test "print foo_instance1.overload1arg((signed char)arg3)" \
205 "\\$\[0-9\]+ = 3" \
206 "print call overloaded func signed char arg"
207
208 gdb_test "print foo_instance1.overload1arg((unsigned char)arg4)" \
209 "\\$\[0-9\]+ = 4" \
210 "print call overloaded func unsigned char arg"
211
212 gdb_test "print foo_instance1.overload1arg((short)arg5)" \
213 "\\$\[0-9\]+ = 5" \
214 "print call overloaded func short arg"
215
216 gdb_test "print foo_instance1.overload1arg((unsigned short)arg6)" \
217 "\\$\[0-9\]+ = 6" \
218 "print call overloaded func unsigned short arg"
219
220 gdb_test "print foo_instance1.overload1arg((int)arg7)" \
221 "\\$\[0-9\]+ = 7" \
222 "print call overloaded func int arg"
223
224 gdb_test "print foo_instance1.overload1arg((unsigned int)arg8)" \
225 "\\$\[0-9\]+ = 8" \
226 "print call overloaded func unsigned int arg"
227
228 gdb_test "print foo_instance1.overload1arg((long)arg9)" \
229 "\\$\[0-9\]+ = 9" \
230 "print call overloaded func long arg"
231
232 gdb_test "print foo_instance1.overload1arg((unsigned long)arg10)" \
233 "\\$\[0-9\]+ = 10" \
234 "print call overloaded func unsigned long arg"
235
236 gdb_test "print foo_instance1.overload1arg((float)arg11)" \
237 "\\$\[0-9\]+ = 11" \
238 "print call overloaded func float arg"
239
240 gdb_test "print foo_instance1.overload1arg((double)arg12)" \
241 "\\$\[0-9\]+ = 12" \
242 "print call overloaded func double arg"
243
244 # ---
245
246 # List overloaded functions.
247
248 # The void case is tricky because some compilers say "(void)"
249 # and some compilers say "()".
250
251 gdb_test "set listsize 1" "" ""
252 gdb_test_multiple "info func overloadfnarg" "list overloaded function with no args" {
253 -re ".*overloadfnarg\\(void\\).*$gdb_prompt $" {
254 # gcc 2
255 gdb_test "list foo::overloadfnarg(void)"\
256 ".*int foo::overloadfnarg.*\\(void\\).*" \
257 "list overloaded function with no args"
258 }
259 -re ".*overloadfnarg\\(\\).*$gdb_prompt $" {
260 # gcc 3
261 gdb_test "list foo::overloadfnarg()"\
262 ".*int foo::overloadfnarg.*\\(void\\).*" \
263 "list overloaded function with no args"
264 }
265 }
266
267 gdb_test "list foo::overloadfnarg(int)" \
268 "int foo::overloadfnarg.*\\(int arg\\).*" \
269 "list overloaded function with int arg"
270
271 gdb_test "list foo::overloadfnarg(int, int (*)(int))" \
272 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
273 "list overloaded function with function ptr args"
274
275 gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
276 "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
277 "list overloaded function with function ptr args - quotes around argument"
278
279 # One last mysterious test.
280 # I wonder what this is for?
281
282 gdb_test "print intToChar(1)" "\\$\[0-9\]+ = 297"
This page took 0.044421 seconds and 4 git commands to generate.