OSDN Git Service

2003-08-22 Michael Chastain <mec@shout.net>
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.cp / overload.exp
1 # Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7
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.
12
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # written by Elena Zannoni (ezannoni@cygnus.com)
21
22 # This file is part of the gdb testsuite
23 #
24 # tests for overloaded member functions. Command Line calls
25 #
26
27
28 if $tracelevel then {
29         strace $tracelevel
30         }
31
32 #
33 # test running programs
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 if [get_compiler_info ${binfile} "c++"] {
49     return -1
50 }
51
52 gdb_exit
53 gdb_start
54 gdb_reinitialize_dir $srcdir/$subdir
55 gdb_load ${binfile}
56
57 # set it up at a breakpoint so we can play with the variable values
58 #
59 if ![runto_main] then {
60     perror "couldn't run to breakpoint"
61     continue
62 }
63
64 if ![runto 'marker1'] then {
65     perror "couldn't run to marker1"
66     continue
67 }
68
69 gdb_test "up" ".*main.*" "up from marker1"
70
71 send_gdb "print foo_instance1\n"
72 gdb_expect {
73     -re ".\[0-9\]* = \{ifoo = 111, ccpfoo = 0x0\}\r\n$gdb_prompt $" {
74         pass "print foo_instance1"
75       }
76     -re ".*$gdb_prompt $" { fail "print foo_instance1" }
77     timeout           { fail "(timeout) print foo_instance1" }
78   }
79
80
81 setup_xfail "hppa*-*-*" CLLbs16901
82 send_gdb "ptype foo_instance1\n"
83 gdb_expect {
84   -re "type = class foo \{.*public:.*int ifoo;.*const char \\*ccpfoo;.*foo\\(int\\);.*foo\\(int, (const char|char const) \\*\\);.*foo\\(foo &\\);.*~foo\\(void\\);.*void foofunc\\(int\\);.*void foofunc\\(int, signed char \\*\\);.*int overload1arg\\(void\\);.*int overload1arg\\(char\\);.*int overload1arg\\(signed char\\);.*int overload1arg\\(unsigned char\\);.*int overload1arg\\(short\\);.*int overload1arg\\(unsigned short\\);.*int overload1arg\\(int\\);.*int overload1arg\\(unsigned int\\);.*int overload1arg\\(long\\);.*int overload1arg\\(unsigned long\\);.*int overload1arg\\(float\\);.*int overload1arg\\(double\\);.*int overloadargs\\(int\\);.*int overloadargs\\(int, int\\);.*int overloadargs\\(int, int, int\\);.*int overloadargs\\(int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int, int, int\\);.*int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);\r\n\}\r\n$gdb_prompt $" {
85         pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)"
86       }
87     -re "type = class foo .*int overloadargs\\(int, int, int, int, int, int, int, int, int, int, int\\);\r\n\}\r\n$gdb_prompt $" {
88         pass "ptype foo_instance1 (shorter match)"
89     }
90     -re ".*$gdb_prompt $" { fail "ptype foo_instance1" }
91     timeout           { fail "(timeout) ptype foo_instance1" }
92   }
93
94 send_gdb "print foo_instance2\n"
95 gdb_expect {
96     -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
97         pass "print foo_instance2"
98       }
99     -re ".*$gdb_prompt $" { fail "print foo_instance2" }
100     timeout           { fail "(timeout) print foo_instance2" }
101   }
102
103 send_gdb "print foo_instance3\n"
104 gdb_expect {
105     -re ".\[0-9\]* = \{ifoo = 222, ccpfoo = $hex \"A\"\}\r\n$gdb_prompt $" {
106         pass "print foo_instance3"
107       }
108     -re ".*$gdb_prompt $" { fail "print foo_instance3" }
109     timeout           { fail "(timeout) print foo_instance3" }
110   }
111
112
113 send_gdb "print foo_instance1.overloadargs(1)\n"
114 gdb_expect {
115     -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
116         pass "print call overloaded func 1 arg"
117       }
118     -re ".*$gdb_prompt $" { fail "print call overloaded func 1 arg" }
119     timeout           { fail "(timeout) print call overloaded func 1 arg" }
120   }
121
122
123 # If GDB fails to restore the selected frame properly after the
124 # inferior function call above (see GDB PR 1155 for an explanation of
125 # why this might happen), all the subsequent tests will fail.  We
126 # should detect and report that failure, but let the marker call
127 # finish so that the rest of the tests can run undisturbed.
128 gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
129     -re "#0  marker1.*$gdb_prompt $" {
130         setup_kfail "gdb/1155" s390-*-linux-gnu
131         fail "re-selected 'main' frame after inferior call"
132         gdb_test "finish" ".*main.*at .*overload.cc:.*// marker1-returns-here.*" \
133             "finish call to marker1"
134     }
135     -re "#1  ($hex in )?main.*$gdb_prompt $" {
136         pass "re-selected 'main' frame after inferior call"
137     }
138 }
139
140
141 send_gdb "print foo_instance1.overloadargs(1, 2)\n"
142 gdb_expect {
143     -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
144         pass "print call overloaded func 2 args"
145       }
146     -re ".*$gdb_prompt $" { fail "print call overloaded func 2 args" }
147     timeout           { fail "(timeout) print call overloaded func 2  args" }
148   }
149
150
151 send_gdb "print foo_instance1.overloadargs(1, 2, 3)\n"
152 gdb_expect {
153     -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
154         pass "print call overloaded func 3 args"
155       }
156     -re ".*$gdb_prompt $" { fail "print call overloaded func 3 args" }
157     timeout           { fail "(timeout) print call overloaded func 3 args" }
158   }
159
160
161 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4)\n"
162 gdb_expect {
163     -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
164         pass "print call overloaded func 4 args"
165       }
166     -re ".*$gdb_prompt $" { fail "print call overloaded func 4 args" }
167     timeout           { fail "(timeout) print call overloaded func 4 args" }
168   }
169
170
171 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5)\n"
172 gdb_expect {
173     -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
174         pass "print call overloaded func 5 args"
175       }
176     -re ".*$gdb_prompt $" { fail "print call overloaded func 5 args" }
177     timeout           { fail "(timeout) print call overloaded func 5 args" }
178   }
179
180
181 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6)\n"
182 gdb_expect {
183     -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
184         pass "print call overloaded func 6 args"
185       }
186     -re ".*$gdb_prompt $" { fail "print call overloaded func 6 args" }
187     timeout           { fail "(timeout) print call overloaded func 6 args" }
188   }
189
190
191 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7)\n"
192 gdb_expect {
193     -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
194         pass "print call overloaded func 7 args"
195       }
196     -re ".*$gdb_prompt $" { fail "print call overloaded func 7 args" }
197     timeout           { fail "(timeout) print call overloaded func 7 args" }
198   }
199
200
201 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8)\n"
202 gdb_expect {
203     -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
204         pass "print call overloaded func 8 args"
205       }
206     -re ".*$gdb_prompt $" { fail "print call overloaded func 8 args" }
207     timeout           { fail "(timeout) print call overloaded func 8 args" }
208   }
209
210
211 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9)\n"
212 gdb_expect {
213     -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
214         pass "print call overloaded func 9 args"
215       }
216     -re ".*$gdb_prompt $" { fail "print call overloaded func 9 args" }
217     timeout           { fail "(timeout) print call overloaded func 9 args" }
218   }
219
220
221 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)\n"
222 gdb_expect {
223     -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
224         pass "print call overloaded func 10 args"
225       }
226     -re ".*$gdb_prompt $" { fail "print call overloaded func 10 args" }
227     timeout           { fail "(timeout) print call overloaded func 10 args" }
228   }
229
230
231 send_gdb "print foo_instance1.overloadargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)\n"
232 gdb_expect {
233     -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
234         pass "print call overloaded func 11 args"
235       }
236     -re ".*$gdb_prompt $" { fail "print call overloaded func 11 args" }
237     timeout           { fail "(timeout) print call overloaded func 11 args" }
238   }
239
240
241 send_gdb "print foo_instance1.overload1arg()\n"
242 gdb_expect {
243     -re ".\[0-9\]* = 1\r\n$gdb_prompt $" {
244         pass "print call overloaded func void arg"
245       }
246     -re ".*$gdb_prompt $" { fail "print call overloaded func void arg" }
247     timeout           { fail "(timeout) print call overloaded func void arg" }
248   }
249
250
251 send_gdb "print foo_instance1.overload1arg((char)arg2)\n"
252 gdb_expect {
253     -re ".\[0-9\]* = 2\r\n$gdb_prompt $" {
254         pass "print call overloaded func char arg"
255       }
256     -re ".*$gdb_prompt $" { fail "print call overloaded func char arg" }
257     timeout           { fail "(timeout) print call overloaded func char arg" }
258   }
259
260
261 send_gdb "print foo_instance1.overload1arg((signed char)arg3)\n"
262 gdb_expect {
263     -re ".\[0-9\]* = 3\r\n$gdb_prompt $" {
264         pass "print call overloaded func signed char arg"
265       }
266     -re ".*$gdb_prompt $" { fail "print call overloaded func signed char arg" }
267     timeout           { fail "(timeout) print call overloaded func signed char arg" }
268   }
269
270
271 send_gdb "print foo_instance1.overload1arg((unsigned char)arg4)\n"
272 gdb_expect {
273     -re ".\[0-9\]* = 4\r\n$gdb_prompt $" {
274         pass "print call overloaded func unsigned char arg"
275       }
276     -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned char arg" }
277     timeout           { fail "(timeout) print call overloaded func unsigned char arg" }
278   }
279
280
281 send_gdb "print foo_instance1.overload1arg((short)arg5)\n"
282 gdb_expect {
283     -re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
284         pass "print call overloaded func short arg"
285       }
286     -re ".*$gdb_prompt $" { fail "print call overloaded func short arg" }
287     timeout           { fail "(timeout) print call overloaded func short arg" }
288   }
289
290
291 send_gdb "print foo_instance1.overload1arg((unsigned short)arg6)\n"
292 gdb_expect {
293     -re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
294         pass "print call overloaded func unsigned short arg"
295       }
296     -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned short  arg" }
297     timeout           { fail "(timeout) print call overloaded func unsigned short arg" }
298   }
299
300
301 send_gdb "print foo_instance1.overload1arg((int)arg7)\n"
302 gdb_expect {
303     -re ".\[0-9\]* = 7\r\n$gdb_prompt $" {
304         pass "print call overloaded func int arg"
305       }
306     -re ".*$gdb_prompt $" { fail "print call overloaded func int arg" }
307     timeout           { fail "(timeout) print call overloaded func int arg" }
308   }
309
310
311 send_gdb "print foo_instance1.overload1arg((unsigned int)arg8)\n"
312 gdb_expect {
313     -re ".\[0-9\]* = 8\r\n$gdb_prompt $" {
314         pass "print call overloaded func unsigned int arg"
315       }
316     -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned int arg" }
317     timeout           { fail "(timeout) print call overloaded func unsigned int arg" }
318   }
319
320
321 send_gdb "print foo_instance1.overload1arg((long)arg9)\n"
322 gdb_expect {
323     -re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
324         pass "print call overloaded func long arg"
325       }
326     -re ".*$gdb_prompt $" { fail "print call overloaded func long arg" }
327     timeout           { fail "(timeout) print call overloaded func long arg" }
328   }
329
330
331 send_gdb "print foo_instance1.overload1arg((unsigned long)arg10)\n"
332 gdb_expect {
333     -re ".\[0-9\]* = 10\r\n$gdb_prompt $" {
334         pass "print call overloaded func unsigned long arg"
335       }
336     -re ".*$gdb_prompt $" { fail "print call overloaded func unsigned long arg" }
337     timeout           { fail "(timeout) print call overloaded func unsigned long arg" }
338   }
339
340
341 send_gdb "print foo_instance1.overload1arg((float)arg11)\n"
342 gdb_expect {
343     -re ".\[0-9\]* = 11\r\n$gdb_prompt $" {
344         pass "print call overloaded func float arg"
345       }
346     -re ".*$gdb_prompt $" { fail "print call overloaded func float arg" }
347     timeout           { fail "(timeout) print call overloaded func float arg" }
348   }
349
350
351 send_gdb "print foo_instance1.overload1arg((double)arg12)\n"
352 gdb_expect {
353     -re ".\[0-9\]* = 12\r\n$gdb_prompt $" {
354         pass "print call overloaded func double arg"
355       }
356     -re ".*$gdb_prompt $" { fail "print call overloaded func double arg" }
357     timeout           { fail "(timeout) print call overloaded func double arg" }
358   }
359
360 # Now some tests to see if we can list overloaded functions properly:
361
362 gdb_test "set listsize 1" "" ""
363 # send_gdb "set listsize 1\n"
364 # gdb_expect -re ".*$gdb_prompt $"
365
366 #
367 # Decide whether to use "()" or "(void)"
368 #
369
370 send_gdb "info func overloadfnarg\n" 
371 gdb_expect {
372     -re ".*overloadfnarg\\(void\\).*$gdb_prompt $" {
373         gdb_test "list foo::overloadfnarg(void)"\
374                 ".*int foo::overloadfnarg.*\\(void\\).*" \
375                 "list overloaded function with no args"
376     }
377     -re ".*overloadfnarg\\(\\).*$gdb_prompt $" {
378         gdb_test "list foo::overloadfnarg()"\
379                 ".*int foo::overloadfnarg.*\\(void\\).*" \
380                 "list overloaded function with no args"
381     }
382     -re ".*$gdb_prompt $" {
383         fail "list overloaded function with no args (no matching symbol)"
384     }
385 }
386
387 gdb_test "list foo::overloadfnarg(int)"\
388     "int foo::overloadfnarg.*\\(int arg\\).*" \
389    "list overloaded function with int arg"
390
391 gdb_test "list foo::overloadfnarg(int, int (*)(int))" \
392    "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
393    "list overloaded function with function ptr args"
394
395 # This one crashes GDB.  Don't know why yet.
396 gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
397    "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
398    "list overloaded function with function ptr args - quotes around argument"
399
400 gdb_test "print intToChar(1)" ".\[0-9\]* = 297"