3a4a307670702a95fb23d01091a266180bad235d
[external/binutils.git] / gdb / testsuite / gdb.c++ / derivation.exp
1 # Copyright (C) 1998, 1999 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 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
21
22 # This file is part of the gdb testsuite
23 #
24
25 #
26 # tests for inheritance, with several derivations types combinations (private,
27 # public, protected) 
28 # classes have simple members and member functions.
29
30
31
32 if $tracelevel then {
33         strace $tracelevel
34         }
35
36 #
37 # test running programs
38 #
39 set prms_id 0
40 set bug_id 0
41
42 if { [skip_cplus_tests] } { continue }
43
44 set testfile "derivation"
45 set srcfile ${testfile}.cc
46 set binfile ${objdir}/${subdir}/${testfile}
47
48 # Create and source the file that provides information about the compiler
49 # used to compile the test case.
50
51 if [get_compiler_info ${binfile} "c++"] {
52     return -1
53 }
54
55 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
56      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
57 }
58
59 gdb_exit
60 gdb_start
61 gdb_reinitialize_dir $srcdir/$subdir
62 gdb_load ${binfile}
63
64 #
65 # set it up at a breakpoint so we can play with the variable values
66 #
67 if ![runto_main] then {
68     perror "couldn't run to breakpoint"
69     continue
70 }
71
72 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
73
74     send_gdb "cont\n"
75     gdb_expect {
76         -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
77             send_gdb "up\n"
78             gdb_expect {
79                 -re ".*$gdb_prompt $" {}
80                 timeout { fail "up from marker1" }
81             }
82         }
83         -re "$gdb_prompt $" { fail "continue to marker1"  }
84         timeout { fail "(timeout) continue to marker1"  }
85     }
86
87
88
89 send_gdb "print a_instance\n"
90 gdb_expect {
91     -re ".\[0-9\]* = \{a = 1, aa = 2\}\r\n$gdb_prompt $" {
92         pass "print value of a_instance"
93       }
94     -re ".*$gdb_prompt $" { fail "print value of a_instance" }
95     timeout           { fail "(timeout) print value of a_instance" }
96   }
97
98
99 send_gdb "ptype a_instance\n"
100 gdb_expect {
101     -re "type = class A \{\r\n\[\t \]*public:\r\n\[\t \]*int a;\r\n\[\t \]*int aa;\[\r\n\t ]+A & operator=\\(A const &\\);\[\r\n\t ]+A\\(A const &\\);\[\r\n\t ]+A\\(void\\);\r\n\[\t \]*int afoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype a_instance (with synth ops)" }
102     -re "type = class A \{\r\n\[\t \]*public:\r\n\[\t \]*int a;\r\n\[\t \]*int aa;\[\r\n\t \]+A\\(void\\);\r\n\[\t \]*int afoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype a_instance (no synth ops)" }
103     -re ".*$gdb_prompt $"   {  fail "ptype a_instance" }
104     timeout             { fail "(timeout) ptype a_instance" }
105 }
106
107
108 send_gdb "print d_instance\n"
109 gdb_expect {
110     -re ".\[0-9\]* = \{<A> = \{a = 1, aa = 2\}, <B> = \{b = 3, bb = 4\}, <C> = \{c = 5, cc = 6\}, d = 7, dd = 8\}\r\n$gdb_prompt $" {
111         pass "print value of d_instance"
112       }
113     -re ".\[0-9\]* = \{<class A> = \{a = 1, aa = 2\}, <class B> = \{b = 3, bb = 4\}, <class C> = \{c = 5, cc = 6\}, d = 7, dd = 8\}\r\n$gdb_prompt $" {
114         pass "print value of d_instance"
115       }
116     -re ".*$gdb_prompt $" { fail "print value of d_instance" }
117     timeout           { fail "(timeout) print value of d_instance" }
118   }
119
120   if {$gcc_compiled} then {
121       send_gdb "ptype d_instance\n"
122       gdb_expect {
123           -re "type = class D : private A, public B, private C \{\r\n\[\t \]*public:\r\n\[\t \]*int d;\r\n\[\t \]*int dd;\[\r\n\t ]+D & operator=\\(D const &\\);\[\r\n\t ]+D\\(D const &\\);\[\r\n\t \]+D\\(void\\);\r\n\[\t \]*int dfoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype d_instance" }
124           -re "type = class D : private A, public B, private C \{\r\n\[\t \]*public:\r\n\[\t \]*int d;\r\n\[\t \]*int dd;\[\r\n\t \]+D\\(void\\);\r\n\[\t \]*int dfoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype d_instance" }
125           -re ".*$gdb_prompt $"   {  fail "ptype d_instance" }
126           timeout             { fail "(timeout) ptype d_instance" }
127       }
128   } else {
129       send_gdb "ptype d_instance\n"
130       gdb_expect {
131           -re "type = class D : private A, public B, protected C \{\r\n\[\t \]*public:\r\n\[\t \]*int d;\r\n\[\t \]*int dd;\[\r\n\t \]+D\\(void\\);\r\n\[\t \]*int dfoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype d_instance" }
132           -re ".*$gdb_prompt $"   {  fail "ptype d_instance" }
133           timeout             { fail "(timeout) ptype d_instance" }
134       }
135   }
136
137
138 send_gdb "print e_instance\n"
139 gdb_expect {
140     -re ".\[0-9\]* = \{<A> = \{a = 1, aa = 2\}, <B> = \{b = 3, bb = 4\}, <C> = \{c = 5, cc = 6\}, e = 9, ee = 10\}\r\n$gdb_prompt $" {
141         pass "print value of e_instance"
142       }
143     -re ".\[0-9\]* = \{<class A> = \{a = 1, aa = 2\}, <class B> = \{b = 3, bb = 4\}, <class C> = \{c = 5, cc = 6\}, e = 9, ee = 10\}\r\n$gdb_prompt $" {
144         pass "print value of e_instance"
145       }
146     -re ".*$gdb_prompt $" { fail "print value of e_instance" }
147     timeout           { fail "(timeout) print value of e_instance" }
148   }
149
150   if {$gcc_compiled} {
151       send_gdb "ptype e_instance\n"
152       gdb_expect {
153           -re "type = class E : public A, private B, private C \{\r\n\[\t \]*public:\r\n\[\t \]*int e;\r\n\[\t \]*int ee;\[\r\n\t ]+E & operator=\\(E const &\\);\[\r\n\t ]+E\\(E const &\\);\[\r\n\t \]+E\\(void\\);\r\n\[\t \]*int efoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype e_instance" }
154           -re "type = class E : public A, private B, private C \{\r\n\[\t \]*public:\r\n\[\t \]*int e;\r\n\[\t \]*int ee;\[\r\n\t \]+E\\(void\\);\r\n\[\t \]*int efoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype e_instance" }
155           -re ".*$gdb_prompt $"   {  fail "ptype e_instance" }
156           timeout             { fail "(timeout) ptype e_instance" }
157       }
158   } else {
159       send_gdb "ptype e_instance\n"
160       gdb_expect {
161           -re "type = class E : public A, private B, protected C \{\r\n\[\t \]*public:\r\n\[\t \]*int e;\r\n\[\t \]*int ee;\[\r\n\t \]+E\\(void\\);\r\n\[\t \]*int efoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype e_instance" }
162           -re ".*$gdb_prompt $"   {  fail "ptype e_instance" }
163           timeout             { fail "(timeout) ptype e_instance" }
164       }
165   }
166
167
168 send_gdb "print f_instance\n"
169 gdb_expect {
170     -re ".\[0-9\]* = \{<A> = \{a = 1, aa = 2\}, <B> = \{b = 3, bb = 4\}, <C> = \{c = 5, cc = 6\}, f = 11, ff = 12\}\r\n$gdb_prompt $" {
171         pass "print value of f_instance"
172       }
173     -re ".\[0-9\]* = \{<class A> = \{a = 1, aa = 2\}, <class B> = \{b = 3, bb = 4\}, <class C> = \{c = 5, cc = 6\}, f = 11, ff = 12\}\r\n$gdb_prompt $" {
174         pass "print value of f_instance"
175       }
176     -re ".*$gdb_prompt $" { fail "print value of f_instance" }
177     timeout           { fail "(timeout) print value of f_instance" }
178   }
179
180 send_gdb "ptype f_instance\n"
181 gdb_expect {
182     -re "type = class F : private A, public B, private C \{\r\n\[\t \]*public:\r\n\[\t \]*int f;\r\n\[\t \]*int ff;\[\r\n\t ]+F & operator=\\(F const &\\);\[\r\n\t ]+F\\(F const &\\);\[\r\n\t \]+F\\(void\\);\r\n\[\t \]*int ffoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype f_instance" }
183     -re "type = class F : private A, public B, private C \{\r\n\[\t \]*public:\r\n\[\t \]*int f;\r\n\[\t \]*int ff;\[\r\n\t \]+F\\(void\\);\r\n\[\t \]*int ffoo\\(void\\);\r\n\[\t \]*int foo\\(void\\);\r\n\}.*$gdb_prompt $"  { pass "ptype f_instance" }
184     -re ".*$gdb_prompt $"   {  fail "ptype f_instance" }
185     timeout             { fail "(timeout) ptype f_instance" }
186 }
187
188
189
190 send_gdb "print d_instance.a\n"
191 gdb_expect {
192     -re ".\[0-9\]* = 1.*$gdb_prompt $" {
193         pass "print value of d_instance.a"
194       }
195     -re ".*$gdb_prompt $" { fail "print value of d_instance.a" }
196     timeout           { fail "(timeout) print value of d_instance.a" }
197   }
198
199 send_gdb "print d_instance.aa\n"
200 gdb_expect {
201     -re ".\[0-9\]* = 2.*$gdb_prompt $" {
202         pass "print value of d_instance.aa"
203       }
204     -re ".*$gdb_prompt $" { fail "print value of d_instance.aa" }
205     timeout           { fail "(timeout) print value of d_instance.aa" }
206   }
207
208 send_gdb "print d_instance.b\n"
209 gdb_expect {
210     -re ".\[0-9\]* = 3.*$gdb_prompt $" {
211         pass "print value of d_instance.b"
212       }
213     -re ".*$gdb_prompt $" { fail "print value of d_instance.b" }
214     timeout           { fail "(timeout) print value of d_instance.b" }
215   }
216
217 send_gdb "print d_instance.bb\n"
218 gdb_expect {
219     -re ".\[0-9\]* = 4.*$gdb_prompt $" {
220         pass "print value of d_instance.bb"
221       }
222     -re ".*$gdb_prompt $" { fail "print value of d_instance.bb" }
223     timeout           { fail "(timeout) print value of d_instance.bb" }
224   }
225
226 send_gdb "print d_instance.c\n"
227 gdb_expect {
228     -re ".\[0-9\]* = 5.*$gdb_prompt $" {
229         pass "print value of d_instance.c"
230       }
231     -re ".*$gdb_prompt $" { fail "print value of d_instance.c" }
232     timeout           { fail "(timeout) print value of d_instance.c" }
233   }
234
235 send_gdb "print d_instance.cc\n"
236 gdb_expect {
237     -re ".\[0-9\]* = 6.*$gdb_prompt $" {
238         pass "print value of d_instance.cc"
239       }
240     -re ".*$gdb_prompt $" { fail "print value of d_instance.cc" }
241     timeout           { fail "(timeout) print value of d_instance.cc" }
242   }
243
244 send_gdb "print d_instance.d\n"
245 gdb_expect {
246     -re ".\[0-9\]* = 7.*$gdb_prompt $" {
247         pass "print value of d_instance.d"
248       }
249     -re ".*$gdb_prompt $" { fail "print value of d_instance.d" }
250     timeout           { fail "(timeout) print value of d_instance.d" }
251   }
252
253 send_gdb "print d_instance.dd\n"
254 gdb_expect {
255     -re ".\[0-9\]* = 8.*$gdb_prompt $" {
256         pass "print value of d_instance.dd"
257       }
258     -re ".*$gdb_prompt $" { fail "print value of d_instance.dd" }
259     timeout           { fail "(timeout) print value of d_instance.dd" }
260   }
261
262 send_gdb "print g_instance.a\n"
263 gdb_expect {
264     -re "warning.*$gdb_prompt $" {
265         # The compiler doesn't think this is ambiguous.
266         fail "print value of g_instance.a"
267     }
268     -re ".\[0-9\]* = 15.*$gdb_prompt $" {
269         pass "print value of g_instance.a"
270       }
271     -re ".*$gdb_prompt $" { fail "print value of g_instance.a" }
272     timeout           { fail "(timeout) print value of g_instance.a" }
273   }
274
275 send_gdb "print g_instance.b\n"
276 gdb_expect {
277     -re "warning.*$gdb_prompt $" {
278         # The compiler doesn't think this is ambiguous.
279         fail "print value of g_instance.b"
280     }
281     -re ".\[0-9\]* = 16.*$gdb_prompt $" {
282         pass "print value of g_instance.b"
283       }
284     -re ".*$gdb_prompt $" { fail "print value of g_instance.b" }
285     timeout           { fail "(timeout) print value of g_instance.b" }
286   }
287
288 send_gdb "print g_instance.c\n"
289 gdb_expect {
290     -re "warning.*$gdb_prompt $" {
291         # The compiler doesn't think this is ambiguous.
292         fail "print value of g_instance.c"
293     }
294     -re ".\[0-9\]* = 17.*$gdb_prompt $" {
295         pass "print value of g_instance.c"
296       }
297     -re ".*$gdb_prompt $" { fail "print value of g_instance.c" }
298     timeout           { fail "(timeout) print value of g_instance.c" }
299   }
300
301 # The following cases always fail with g++ output, and should be fixed
302 # someday. -sts 1999-08-25
303
304 if { $gcc_compiled } { setup_xfail "*-*-*" }
305 send_gdb "print g_instance.afoo()\n"
306 gdb_expect {
307     -re ".\[0-9\]* = 1.*$gdb_prompt $" {
308         pass "print value of g_instance.afoo()"
309       }
310     -re ".*$gdb_prompt $" { fail "print value of g_instance.afoo()" }
311     timeout           { fail "(timeout) print value of g_instance.afoo()" }
312   }
313
314 if { $gcc_compiled } { setup_xfail "*-*-*" }
315 send_gdb "print g_instance.bfoo()\n"
316 gdb_expect {
317     -re ".\[0-9\]* = 2.*$gdb_prompt $" {
318         pass "print value of g_instance.bfoo()"
319       }
320     -re ".*$gdb_prompt $" { fail "print value of g_instance.bfoo()" }
321     timeout           { fail "(timeout) print value of g_instance.bfoo()" }
322   }
323
324 if { $gcc_compiled } { setup_xfail "*-*-*" }
325 send_gdb "print g_instance.cfoo()\n"
326 gdb_expect {
327     -re ".\[0-9\]* = 3.*$gdb_prompt $" {
328         pass "print value of g_instance.cfoo()"
329       }
330     -re ".*$gdb_prompt $" { fail "print value of g_instance.cfoo()" }
331     timeout           { fail "(timeout) print value of g_instance.cfoo()" }
332   }