]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.c++/derivation.exp
import gdb-1999-09-08 snapshot
[thirdparty/binutils-gdb.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 remote_file build delete ${binfile}.ci
64 if {![istarget "hppa*-*-hpux*"]} {
65 if { [gdb_compile "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci" preprocess ""] != ""
66 } {
67 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will auto
68 matically fail."
69 }
70 } else {
71 if { [gdb_preprocess "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci" "c++"] != "" } {
72 perror "Couldn't make ${binfile}.ci file"
73 return 1;
74 }
75 }
76
77 source ${binfile}.ci
78
79 #
80 # set it up at a breakpoint so we can play with the variable values
81 #
82 if ![runto_main] then {
83 perror "couldn't run to breakpoint"
84 continue
85 }
86
87 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
88
89 send_gdb "cont\n"
90 gdb_expect {
91 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
92 send_gdb "up\n"
93 gdb_expect {
94 -re ".*$gdb_prompt $" {}
95 timeout { fail "up from marker1" }
96 }
97 }
98 -re "$gdb_prompt $" { fail "continue to marker1" }
99 timeout { fail "(timeout) continue to marker1" }
100 }
101
102
103
104 send_gdb "print a_instance\n"
105 gdb_expect {
106 -re ".\[0-9\]* = \{a = 1, aa = 2\}\r\n$gdb_prompt $" {
107 pass "print value of a_instance"
108 }
109 -re ".*$gdb_prompt $" { fail "print value of a_instance" }
110 timeout { fail "(timeout) print value of a_instance" }
111 }
112
113
114 send_gdb "ptype a_instance\n"
115 gdb_expect {
116 -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)" }
117 -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)" }
118 -re ".*$gdb_prompt $" { fail "ptype a_instance" }
119 timeout { fail "(timeout) ptype a_instance" }
120 }
121
122
123 send_gdb "print d_instance\n"
124 gdb_expect {
125 -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 $" {
126 pass "print value of d_instance"
127 }
128 -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 $" {
129 pass "print value of d_instance"
130 }
131 -re ".*$gdb_prompt $" { fail "print value of d_instance" }
132 timeout { fail "(timeout) print value of d_instance" }
133 }
134
135 if {$gcc_compiled} then {
136 send_gdb "ptype d_instance\n"
137 gdb_expect {
138 -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" }
139 -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" }
140 -re ".*$gdb_prompt $" { fail "ptype d_instance" }
141 timeout { fail "(timeout) ptype d_instance" }
142 }
143 } else {
144 send_gdb "ptype d_instance\n"
145 gdb_expect {
146 -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" }
147 -re ".*$gdb_prompt $" { fail "ptype d_instance" }
148 timeout { fail "(timeout) ptype d_instance" }
149 }
150 }
151
152
153 send_gdb "print e_instance\n"
154 gdb_expect {
155 -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 $" {
156 pass "print value of e_instance"
157 }
158 -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 $" {
159 pass "print value of e_instance"
160 }
161 -re ".*$gdb_prompt $" { fail "print value of e_instance" }
162 timeout { fail "(timeout) print value of e_instance" }
163 }
164
165 if {$gcc_compiled} {
166 send_gdb "ptype e_instance\n"
167 gdb_expect {
168 -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" }
169 -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" }
170 -re ".*$gdb_prompt $" { fail "ptype e_instance" }
171 timeout { fail "(timeout) ptype e_instance" }
172 }
173 } else {
174 send_gdb "ptype e_instance\n"
175 gdb_expect {
176 -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" }
177 -re ".*$gdb_prompt $" { fail "ptype e_instance" }
178 timeout { fail "(timeout) ptype e_instance" }
179 }
180 }
181
182
183 send_gdb "print f_instance\n"
184 gdb_expect {
185 -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 $" {
186 pass "print value of f_instance"
187 }
188 -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 $" {
189 pass "print value of f_instance"
190 }
191 -re ".*$gdb_prompt $" { fail "print value of f_instance" }
192 timeout { fail "(timeout) print value of f_instance" }
193 }
194
195 send_gdb "ptype f_instance\n"
196 gdb_expect {
197 -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" }
198 -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" }
199 -re ".*$gdb_prompt $" { fail "ptype f_instance" }
200 timeout { fail "(timeout) ptype f_instance" }
201 }
202
203
204
205 send_gdb "print d_instance.a\n"
206 gdb_expect {
207 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
208 pass "print value of d_instance.a"
209 }
210 -re ".*$gdb_prompt $" { fail "print value of d_instance.a" }
211 timeout { fail "(timeout) print value of d_instance.a" }
212 }
213
214 send_gdb "print d_instance.aa\n"
215 gdb_expect {
216 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
217 pass "print value of d_instance.aa"
218 }
219 -re ".*$gdb_prompt $" { fail "print value of d_instance.aa" }
220 timeout { fail "(timeout) print value of d_instance.aa" }
221 }
222
223 send_gdb "print d_instance.b\n"
224 gdb_expect {
225 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
226 pass "print value of d_instance.b"
227 }
228 -re ".*$gdb_prompt $" { fail "print value of d_instance.b" }
229 timeout { fail "(timeout) print value of d_instance.b" }
230 }
231
232 send_gdb "print d_instance.bb\n"
233 gdb_expect {
234 -re ".\[0-9\]* = 4.*$gdb_prompt $" {
235 pass "print value of d_instance.bb"
236 }
237 -re ".*$gdb_prompt $" { fail "print value of d_instance.bb" }
238 timeout { fail "(timeout) print value of d_instance.bb" }
239 }
240
241 send_gdb "print d_instance.c\n"
242 gdb_expect {
243 -re ".\[0-9\]* = 5.*$gdb_prompt $" {
244 pass "print value of d_instance.c"
245 }
246 -re ".*$gdb_prompt $" { fail "print value of d_instance.c" }
247 timeout { fail "(timeout) print value of d_instance.c" }
248 }
249
250 send_gdb "print d_instance.cc\n"
251 gdb_expect {
252 -re ".\[0-9\]* = 6.*$gdb_prompt $" {
253 pass "print value of d_instance.cc"
254 }
255 -re ".*$gdb_prompt $" { fail "print value of d_instance.cc" }
256 timeout { fail "(timeout) print value of d_instance.cc" }
257 }
258
259 send_gdb "print d_instance.d\n"
260 gdb_expect {
261 -re ".\[0-9\]* = 7.*$gdb_prompt $" {
262 pass "print value of d_instance.d"
263 }
264 -re ".*$gdb_prompt $" { fail "print value of d_instance.d" }
265 timeout { fail "(timeout) print value of d_instance.d" }
266 }
267
268 send_gdb "print d_instance.dd\n"
269 gdb_expect {
270 -re ".\[0-9\]* = 8.*$gdb_prompt $" {
271 pass "print value of d_instance.dd"
272 }
273 -re ".*$gdb_prompt $" { fail "print value of d_instance.dd" }
274 timeout { fail "(timeout) print value of d_instance.dd" }
275 }
276
277 send_gdb "print g_instance.a\n"
278 gdb_expect {
279 -re "warning.*$gdb_prompt $" {
280 # The compiler doesn't think this is ambiguous.
281 fail "print value of g_instance.a"
282 }
283 -re ".\[0-9\]* = 15.*$gdb_prompt $" {
284 pass "print value of g_instance.a"
285 }
286 -re ".*$gdb_prompt $" { fail "print value of g_instance.a" }
287 timeout { fail "(timeout) print value of g_instance.a" }
288 }
289
290 send_gdb "print g_instance.b\n"
291 gdb_expect {
292 -re "warning.*$gdb_prompt $" {
293 # The compiler doesn't think this is ambiguous.
294 fail "print value of g_instance.b"
295 }
296 -re ".\[0-9\]* = 16.*$gdb_prompt $" {
297 pass "print value of g_instance.b"
298 }
299 -re ".*$gdb_prompt $" { fail "print value of g_instance.b" }
300 timeout { fail "(timeout) print value of g_instance.b" }
301 }
302
303 send_gdb "print g_instance.c\n"
304 gdb_expect {
305 -re "warning.*$gdb_prompt $" {
306 # The compiler doesn't think this is ambiguous.
307 fail "print value of g_instance.c"
308 }
309 -re ".\[0-9\]* = 17.*$gdb_prompt $" {
310 pass "print value of g_instance.c"
311 }
312 -re ".*$gdb_prompt $" { fail "print value of g_instance.c" }
313 timeout { fail "(timeout) print value of g_instance.c" }
314 }
315
316 # The following cases always fail with g++ output, and should be fixed
317 # someday. -sts 1999-08-25
318
319 if { $gcc_compiled } { setup_xfail "*-*-*" }
320 send_gdb "print g_instance.afoo()\n"
321 gdb_expect {
322 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
323 pass "print value of g_instance.afoo()"
324 }
325 -re ".*$gdb_prompt $" { fail "print value of g_instance.afoo()" }
326 timeout { fail "(timeout) print value of g_instance.afoo()" }
327 }
328
329 if { $gcc_compiled } { setup_xfail "*-*-*" }
330 send_gdb "print g_instance.bfoo()\n"
331 gdb_expect {
332 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
333 pass "print value of g_instance.bfoo()"
334 }
335 -re ".*$gdb_prompt $" { fail "print value of g_instance.bfoo()" }
336 timeout { fail "(timeout) print value of g_instance.bfoo()" }
337 }
338
339 if { $gcc_compiled } { setup_xfail "*-*-*" }
340 send_gdb "print g_instance.cfoo()\n"
341 gdb_expect {
342 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
343 pass "print value of g_instance.cfoo()"
344 }
345 -re ".*$gdb_prompt $" { fail "print value of g_instance.cfoo()" }
346 timeout { fail "(timeout) print value of g_instance.cfoo()" }
347 }