00df5c06d3a6aed5e6896561c58776f0c1b12e76
[binutils-gdb.git] / gdb / testsuite / gdb.c++ / derivation.exp
1 # Copyright 1998, 1999, 2000 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 ".*main.*$gdb_prompt $" {
80 pass "up from marker1"
81 }
82 -re ".*$gdb_prompt $" {
83 fail "up from marker1"
84 }
85 timeout { fail "up from marker1 (timeout)" }
86 }
87 }
88 -re "$gdb_prompt $" { fail "continue to marker1" }
89 timeout { fail "(timeout) continue to marker1" }
90 }
91
92
93
94 send_gdb "print a_instance\n"
95 gdb_expect {
96 -re ".\[0-9\]* = \{a = 1, aa = 2\}\r\n$gdb_prompt $" {
97 pass "print value of a_instance"
98 }
99 -re ".*$gdb_prompt $" { fail "print value of a_instance" }
100 timeout { fail "(timeout) print value of a_instance" }
101 }
102
103
104 send_gdb "ptype a_instance\n"
105 gdb_expect {
106 -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)" }
107 -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)" }
108 -re ".*$gdb_prompt $" { fail "ptype a_instance" }
109 timeout { fail "(timeout) ptype a_instance" }
110 }
111
112
113 send_gdb "print d_instance\n"
114 gdb_expect {
115 -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 $" {
116 pass "print value of d_instance"
117 }
118 -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 $" {
119 pass "print value of d_instance"
120 }
121 -re ".*$gdb_prompt $" { fail "print value of d_instance" }
122 timeout { fail "(timeout) print value of d_instance" }
123 }
124
125 if {$gcc_compiled} then {
126 send_gdb "ptype d_instance\n"
127 gdb_expect {
128 -re "type = class D : private A, public B, (protected|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" }
129 -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" }
130 -re ".*$gdb_prompt $" { fail "ptype d_instance" }
131 timeout { fail "(timeout) ptype d_instance" }
132 }
133 } else {
134 send_gdb "ptype d_instance\n"
135 gdb_expect {
136 -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" }
137 -re ".*$gdb_prompt $" { fail "ptype d_instance" }
138 timeout { fail "(timeout) ptype d_instance" }
139 }
140 }
141
142
143 send_gdb "print e_instance\n"
144 gdb_expect {
145 -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 $" {
146 pass "print value of e_instance"
147 }
148 -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 $" {
149 pass "print value of e_instance"
150 }
151 -re ".*$gdb_prompt $" { fail "print value of e_instance" }
152 timeout { fail "(timeout) print value of e_instance" }
153 }
154
155 if {$gcc_compiled} {
156 send_gdb "ptype e_instance\n"
157 gdb_expect {
158 -re "type = class E : public A, private B, (protected|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" }
159 -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" }
160 -re ".*$gdb_prompt $" { fail "ptype e_instance" }
161 timeout { fail "(timeout) ptype e_instance" }
162 }
163 } else {
164 send_gdb "ptype e_instance\n"
165 gdb_expect {
166 -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" }
167 -re ".*$gdb_prompt $" { fail "ptype e_instance" }
168 timeout { fail "(timeout) ptype e_instance" }
169 }
170 }
171
172
173 send_gdb "print f_instance\n"
174 gdb_expect {
175 -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 $" {
176 pass "print value of f_instance"
177 }
178 -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 $" {
179 pass "print value of f_instance"
180 }
181 -re ".*$gdb_prompt $" { fail "print value of f_instance" }
182 timeout { fail "(timeout) print value of f_instance" }
183 }
184
185 send_gdb "ptype f_instance\n"
186 gdb_expect {
187 -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" }
188 -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" }
189 -re ".*$gdb_prompt $" { fail "ptype f_instance" }
190 timeout { fail "(timeout) ptype f_instance" }
191 }
192
193
194
195 send_gdb "print d_instance.a\n"
196 gdb_expect {
197 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
198 pass "print value of d_instance.a"
199 }
200 -re ".*$gdb_prompt $" { fail "print value of d_instance.a" }
201 timeout { fail "(timeout) print value of d_instance.a" }
202 }
203
204 send_gdb "print d_instance.aa\n"
205 gdb_expect {
206 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
207 pass "print value of d_instance.aa"
208 }
209 -re ".*$gdb_prompt $" { fail "print value of d_instance.aa" }
210 timeout { fail "(timeout) print value of d_instance.aa" }
211 }
212
213 send_gdb "print d_instance.b\n"
214 gdb_expect {
215 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
216 pass "print value of d_instance.b"
217 }
218 -re ".*$gdb_prompt $" { fail "print value of d_instance.b" }
219 timeout { fail "(timeout) print value of d_instance.b" }
220 }
221
222 send_gdb "print d_instance.bb\n"
223 gdb_expect {
224 -re ".\[0-9\]* = 4.*$gdb_prompt $" {
225 pass "print value of d_instance.bb"
226 }
227 -re ".*$gdb_prompt $" { fail "print value of d_instance.bb" }
228 timeout { fail "(timeout) print value of d_instance.bb" }
229 }
230
231 send_gdb "print d_instance.c\n"
232 gdb_expect {
233 -re ".\[0-9\]* = 5.*$gdb_prompt $" {
234 pass "print value of d_instance.c"
235 }
236 -re ".*$gdb_prompt $" { fail "print value of d_instance.c" }
237 timeout { fail "(timeout) print value of d_instance.c" }
238 }
239
240 send_gdb "print d_instance.cc\n"
241 gdb_expect {
242 -re ".\[0-9\]* = 6.*$gdb_prompt $" {
243 pass "print value of d_instance.cc"
244 }
245 -re ".*$gdb_prompt $" { fail "print value of d_instance.cc" }
246 timeout { fail "(timeout) print value of d_instance.cc" }
247 }
248
249 send_gdb "print d_instance.d\n"
250 gdb_expect {
251 -re ".\[0-9\]* = 7.*$gdb_prompt $" {
252 pass "print value of d_instance.d"
253 }
254 -re ".*$gdb_prompt $" { fail "print value of d_instance.d" }
255 timeout { fail "(timeout) print value of d_instance.d" }
256 }
257
258 send_gdb "print d_instance.dd\n"
259 gdb_expect {
260 -re ".\[0-9\]* = 8.*$gdb_prompt $" {
261 pass "print value of d_instance.dd"
262 }
263 -re ".*$gdb_prompt $" { fail "print value of d_instance.dd" }
264 timeout { fail "(timeout) print value of d_instance.dd" }
265 }
266
267 send_gdb "print g_instance.a\n"
268 gdb_expect {
269 -re "warning.*$gdb_prompt $" {
270 # The compiler doesn't think this is ambiguous.
271 fail "print value of g_instance.a"
272 }
273 -re ".\[0-9\]* = 15.*$gdb_prompt $" {
274 pass "print value of g_instance.a"
275 }
276 -re ".*$gdb_prompt $" { fail "print value of g_instance.a" }
277 timeout { fail "(timeout) print value of g_instance.a" }
278 }
279
280 send_gdb "print g_instance.b\n"
281 gdb_expect {
282 -re "warning.*$gdb_prompt $" {
283 # The compiler doesn't think this is ambiguous.
284 fail "print value of g_instance.b"
285 }
286 -re ".\[0-9\]* = 16.*$gdb_prompt $" {
287 pass "print value of g_instance.b"
288 }
289 -re ".*$gdb_prompt $" { fail "print value of g_instance.b" }
290 timeout { fail "(timeout) print value of g_instance.b" }
291 }
292
293 send_gdb "print g_instance.c\n"
294 gdb_expect {
295 -re "warning.*$gdb_prompt $" {
296 # The compiler doesn't think this is ambiguous.
297 fail "print value of g_instance.c"
298 }
299 -re ".\[0-9\]* = 17.*$gdb_prompt $" {
300 pass "print value of g_instance.c"
301 }
302 -re ".*$gdb_prompt $" { fail "print value of g_instance.c" }
303 timeout { fail "(timeout) print value of g_instance.c" }
304 }
305
306 # The following cases always fail with g++ output, and should be fixed
307 # someday. -sts 1999-08-25
308
309 if { $gcc_compiled } { setup_xfail "*-*-*" }
310 send_gdb "print g_instance.afoo()\n"
311 gdb_expect {
312 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
313 pass "print value of g_instance.afoo()"
314 }
315 -re ".*$gdb_prompt $" { fail "print value of g_instance.afoo()" }
316 timeout { fail "(timeout) print value of g_instance.afoo()" }
317 }
318
319 if { $gcc_compiled } { setup_xfail "*-*-*" }
320 send_gdb "print g_instance.bfoo()\n"
321 gdb_expect {
322 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
323 pass "print value of g_instance.bfoo()"
324 }
325 -re ".*$gdb_prompt $" { fail "print value of g_instance.bfoo()" }
326 timeout { fail "(timeout) print value of g_instance.bfoo()" }
327 }
328
329 if { $gcc_compiled } { setup_xfail "*-*-*" }
330 send_gdb "print g_instance.cfoo()\n"
331 gdb_expect {
332 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
333 pass "print value of g_instance.cfoo()"
334 }
335 -re ".*$gdb_prompt $" { fail "print value of g_instance.cfoo()" }
336 timeout { fail "(timeout) print value of g_instance.cfoo()" }
337 }