1 # Copyright (C) 1998, 1999 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
22 # This file is part of the gdb testsuite
26 # tests for inheritance, with several derivations types combinations (private,
28 # classes have simple members and member functions.
37 # test running programs
42 set testfile "derivation"
43 set srcfile ${testfile}.cc
44 set binfile ${objdir}/${subdir}/${testfile}
46 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
47 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
52 gdb_reinitialize_dir $srcdir/$subdir
54 remote_file build delete ${binfile}.ci
55 if {![istarget "hppa*-*-hpux*"]} {
56 if { [gdb_compile "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci" preprocess ""] != ""
58 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will auto
62 if { [gdb_preprocess "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci" "c++"] != "" } {
63 perror "Couldn't make ${binfile}.ci file"
71 # set it up at a breakpoint so we can play with the variable values
73 if ![runto_main] then {
74 perror "couldn't run to breakpoint"
78 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
82 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
85 -re ".*$gdb_prompt $" {}
86 timeout { fail "up from marker1" }
89 -re "$gdb_prompt $" { fail "continue to marker1" }
90 timeout { fail "(timeout) continue to marker1" }
95 send_gdb "print a_instance\n"
97 -re ".\[0-9\]* = \{a = 1, aa = 2\}\r\n$gdb_prompt $" {
98 pass "print value of a_instance"
100 -re ".*$gdb_prompt $" { fail "print value of a_instance" }
101 timeout { fail "(timeout) print value of a_instance" }
105 send_gdb "ptype a_instance\n"
107 -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)" }
108 -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)" }
109 -re ".*$gdb_prompt $" { fail "ptype a_instance" }
110 timeout { fail "(timeout) ptype a_instance" }
114 send_gdb "print d_instance\n"
116 -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 $" {
117 pass "print value of d_instance"
119 -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 $" {
120 pass "print value of d_instance"
122 -re ".*$gdb_prompt $" { fail "print value of d_instance" }
123 timeout { fail "(timeout) print value of d_instance" }
126 if {$gcc_compiled} then {
127 send_gdb "ptype d_instance\n"
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 & 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" }
130 -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" }
131 -re ".*$gdb_prompt $" { fail "ptype d_instance" }
132 timeout { fail "(timeout) ptype d_instance" }
135 send_gdb "ptype d_instance\n"
137 -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" }
138 -re ".*$gdb_prompt $" { fail "ptype d_instance" }
139 timeout { fail "(timeout) ptype d_instance" }
144 send_gdb "print e_instance\n"
146 -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 $" {
147 pass "print value of e_instance"
149 -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 $" {
150 pass "print value of e_instance"
152 -re ".*$gdb_prompt $" { fail "print value of e_instance" }
153 timeout { fail "(timeout) print value of e_instance" }
157 send_gdb "ptype e_instance\n"
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 & 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" }
160 -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" }
161 -re ".*$gdb_prompt $" { fail "ptype e_instance" }
162 timeout { fail "(timeout) ptype e_instance" }
165 send_gdb "ptype e_instance\n"
167 -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" }
168 -re ".*$gdb_prompt $" { fail "ptype e_instance" }
169 timeout { fail "(timeout) ptype e_instance" }
174 send_gdb "print f_instance\n"
176 -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 $" {
177 pass "print value of f_instance"
179 -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 $" {
180 pass "print value of f_instance"
182 -re ".*$gdb_prompt $" { fail "print value of f_instance" }
183 timeout { fail "(timeout) print value of f_instance" }
186 send_gdb "ptype f_instance\n"
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 & 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" }
189 -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" }
190 -re ".*$gdb_prompt $" { fail "ptype f_instance" }
191 timeout { fail "(timeout) ptype f_instance" }
196 send_gdb "print d_instance.a\n"
198 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
199 pass "print value of d_instance.a"
201 -re ".*$gdb_prompt $" { fail "print value of d_instance.a" }
202 timeout { fail "(timeout) print value of d_instance.a" }
205 send_gdb "print d_instance.aa\n"
207 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
208 pass "print value of d_instance.aa"
210 -re ".*$gdb_prompt $" { fail "print value of d_instance.aa" }
211 timeout { fail "(timeout) print value of d_instance.aa" }
214 send_gdb "print d_instance.b\n"
216 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
217 pass "print value of d_instance.b"
219 -re ".*$gdb_prompt $" { fail "print value of d_instance.b" }
220 timeout { fail "(timeout) print value of d_instance.b" }
223 send_gdb "print d_instance.bb\n"
225 -re ".\[0-9\]* = 4.*$gdb_prompt $" {
226 pass "print value of d_instance.bb"
228 -re ".*$gdb_prompt $" { fail "print value of d_instance.bb" }
229 timeout { fail "(timeout) print value of d_instance.bb" }
232 send_gdb "print d_instance.c\n"
234 -re ".\[0-9\]* = 5.*$gdb_prompt $" {
235 pass "print value of d_instance.c"
237 -re ".*$gdb_prompt $" { fail "print value of d_instance.c" }
238 timeout { fail "(timeout) print value of d_instance.c" }
241 send_gdb "print d_instance.cc\n"
243 -re ".\[0-9\]* = 6.*$gdb_prompt $" {
244 pass "print value of d_instance.cc"
246 -re ".*$gdb_prompt $" { fail "print value of d_instance.cc" }
247 timeout { fail "(timeout) print value of d_instance.cc" }
250 send_gdb "print d_instance.d\n"
252 -re ".\[0-9\]* = 7.*$gdb_prompt $" {
253 pass "print value of d_instance.d"
255 -re ".*$gdb_prompt $" { fail "print value of d_instance.d" }
256 timeout { fail "(timeout) print value of d_instance.d" }
259 send_gdb "print d_instance.dd\n"
261 -re ".\[0-9\]* = 8.*$gdb_prompt $" {
262 pass "print value of d_instance.dd"
264 -re ".*$gdb_prompt $" { fail "print value of d_instance.dd" }
265 timeout { fail "(timeout) print value of d_instance.dd" }
268 send_gdb "print g_instance.a\n"
270 -re "warning.*$gdb_prompt $" {
271 # The compiler doesn't think this is ambiguous.
272 fail "print value of g_instance.a"
274 -re ".\[0-9\]* = 15.*$gdb_prompt $" {
275 pass "print value of g_instance.a"
277 -re ".*$gdb_prompt $" { fail "print value of g_instance.a" }
278 timeout { fail "(timeout) print value of g_instance.a" }
281 send_gdb "print g_instance.b\n"
283 -re "warning.*$gdb_prompt $" {
284 # The compiler doesn't think this is ambiguous.
285 fail "print value of g_instance.b"
287 -re ".\[0-9\]* = 16.*$gdb_prompt $" {
288 pass "print value of g_instance.b"
290 -re ".*$gdb_prompt $" { fail "print value of g_instance.b" }
291 timeout { fail "(timeout) print value of g_instance.b" }
294 send_gdb "print g_instance.c\n"
296 -re "warning.*$gdb_prompt $" {
297 # The compiler doesn't think this is ambiguous.
298 fail "print value of g_instance.c"
300 -re ".\[0-9\]* = 17.*$gdb_prompt $" {
301 pass "print value of g_instance.c"
303 -re ".*$gdb_prompt $" { fail "print value of g_instance.c" }
304 timeout { fail "(timeout) print value of g_instance.c" }
307 if { $gcc_compiled } { setup_xfail "hppa*-hp-hpux*" }
308 send_gdb "print g_instance.afoo()\n"
310 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
311 pass "print value of g_instance.afoo()"
313 -re ".*$gdb_prompt $" { fail "print value of g_instance.afoo()" }
314 timeout { fail "(timeout) print value of g_instance.afoo()" }
317 if { $gcc_compiled } { setup_xfail "hppa*-hp-hpux*" }
318 send_gdb "print g_instance.bfoo()\n"
320 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
321 pass "print value of g_instance.bfoo()"
323 -re ".*$gdb_prompt $" { fail "print value of g_instance.bfoo()" }
324 timeout { fail "(timeout) print value of g_instance.bfoo()" }
327 if { $gcc_compiled } { setup_xfail "hppa*-hp-hpux*" }
328 send_gdb "print g_instance.cfoo()\n"
330 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
331 pass "print value of g_instance.cfoo()"
333 -re ".*$gdb_prompt $" { fail "print value of g_instance.cfoo()" }
334 timeout { fail "(timeout) print value of g_instance.cfoo()" }