91a0400d47e36b491d525ce4b2f1e81425dad318
[external/binutils.git] / gdb / testsuite / gdb.c++ / classes.exp
1 # Copyright (C) 1992, 1994, 1995, 1997 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 Fred Fish. (fnf@cygnus.com)
21
22 set ws "\[\r\n\t \]+"
23 set nl "\[\r\n\]+"
24
25 if $tracelevel then {
26         strace $tracelevel
27 }
28
29 if { [skip_cplus_tests] } { continue }
30
31 set testfile "misc"
32 set srcfile ${testfile}.cc
33 set binfile ${objdir}/${subdir}/${testfile}
34
35 # Create and source the file that provides information about the compiler
36 # used to compile the test case.
37
38 if [get_compiler_info ${binfile} "c++"] {
39     return -1
40 }
41
42 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
43      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
44 }
45
46 #
47 # Test ptype of class objects.
48 #
49
50 proc test_ptype_class_objects {} {
51     global gdb_prompt
52     global ws
53     global nl
54
55     # Note that struct members are public by default, so we don't print
56     # "public:" for the public members of structs.
57     # Accept it as an expected failure if gdb just fails to distinguish between
58     # class and struct, and everything else is OK.
59
60     send_gdb "ptype struct default_public_struct\n"
61     gdb_expect {
62         -re "type = struct default_public_struct \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
63             pass "ptype struct default_public_struct"
64         }
65         -re "type = class default_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
66             setup_xfail "*-*-*"
67             fail "ptype struct default_public_struct"
68         }
69         -re ".*$gdb_prompt $" { fail "ptype struct default_public_struct" }
70         timeout { fail "ptype struct default_public_struct (timeout)" ; return }
71     }
72
73     # Note that struct members are public by default, so we don't print
74     # "public:" for the public members of structs.
75     # Accept it as an expected failure if gdb just fails to distinguish between
76     # class and struct, and everything else is OK.
77
78     send_gdb "ptype struct explicit_public_struct\n"
79     gdb_expect {
80         -re "type = struct explicit_public_struct \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
81             pass "ptype struct explicit_public_struct"
82         }
83         -re "type = class explicit_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
84             setup_xfail "*-*-*"
85             fail "ptype struct explicit_public_struct"
86         }
87         -re ".*$gdb_prompt $" { fail "ptype struct explicit_public_struct" }
88         timeout { fail "ptype struct explicit_public_struct (timeout)" ; return }
89     }
90
91     # Accept it as an expected failure if gdb just fails to distinguish between
92     # class and struct, and everything else is OK.
93
94     setup_xfail_format "DWARF 1"
95     send_gdb "ptype struct protected_struct\n"
96     gdb_expect {
97         -re "type = struct protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
98             pass "ptype struct protected_struct (FIXME)"
99         }
100         -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
101             setup_xfail "*-*-*"
102             fail "ptype struct protected_struct (FIXME)"
103         }
104         -re ".*$gdb_prompt $" { fail "ptype struct protected_struct" }
105         timeout { fail "ptype struct protected_struct (timeout)" ; return }
106     }
107
108     # Accept it as an expected failure if gdb just fails to distinguish between
109     # class and struct, and everything else is OK.
110
111     setup_xfail_format "DWARF 1"
112     send_gdb "ptype struct private_struct\n"
113     gdb_expect {
114         -re "type = struct private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
115             pass "ptype struct private_struct (FIXME)"
116         }
117         -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" { 
118             setup_xfail "*-*-*"
119             fail "ptype struct private_struct (FIXME)"
120         }
121         -re ".*$gdb_prompt $" { fail "ptype struct private_struct" }
122         timeout { fail "ptype struct private_struct (timeout)" ; return }
123     }
124
125     # Accept it as an expected failure if gdb just fails to distinguish between
126     # class and struct, and everything else is OK.
127
128     setup_xfail_format "DWARF 1"
129     send_gdb "ptype struct mixed_protection_struct\n"
130     gdb_expect {
131         -re "type = struct mixed_protection_struct \{${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl\}$nl$gdb_prompt $" {
132             pass "ptype struct mixed_protection_struct (FIXME)"
133         }
134         -re "type = struct mixed_protection_struct \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl.*\}$nl$gdb_prompt $" {
135             pass "ptype struct mixed_protection_struct (extra public)"
136         }
137         -re "type = class mixed_protection_struct \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl.*\}$nl$gdb_prompt $" {
138             setup_xfail "*-*-*"
139             fail "ptype struct mixed_protection_struct (FIXME)"
140         }
141         -re ".*$gdb_prompt $" { fail "ptype struct mixed_protection_struct" }
142         timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
143     }
144
145     # Accept it as an expected failure if gdb just fails to distinguish between
146     # class and struct, and everything else is OK.
147
148     send_gdb "ptype class public_class\n"
149     gdb_expect {
150         -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
151             pass "ptype class public_class (FIXME)"
152         }
153         -re "type = struct public_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
154             setup_xfail "*-*-*"
155             fail "ptype class public_class (FIXME)"
156         }
157         -re ".*$gdb_prompt $" { fail "ptype class public_class" }
158         timeout { fail "ptype class public_class (timeout)" ; return }
159     }
160
161     send_gdb "ptype class protected_class\n"
162     gdb_expect {
163         -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
164             pass "ptype class protected_class"
165         }
166         -re "type = struct protected_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
167             setup_xfail "*-*-*"
168             fail "ptype class protected_class"
169         }
170         -re ".*$gdb_prompt $" { fail "ptype class protected_class" }
171         timeout { fail "ptype class protected_class (timeout)" ; return }
172     }
173
174     # Accept it as an expected failure if gdb just emits a superflous "private:"
175     # attribute, since classes default to private and for consistency with
176     # structs (where we don't print the "public:" attribute) we don't print
177     # the "private:" attribute.
178
179     setup_xfail_format "DWARF 1"
180     send_gdb "ptype class default_private_class\n"
181     gdb_expect {
182         -re "type = class default_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
183             pass "ptype class default_private_class (FIXME)"
184         }
185         -re "type = class default_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
186             setup_xfail "*-*-*"
187             fail "ptype class default_private_class (FIXME)"
188         }
189         -re ".*$gdb_prompt $" { fail "ptype class default_private_class" }
190         timeout { fail "ptype class default_private_class (timeout)" ; return }
191     }
192
193     send_gdb "ptype class explicit_private_class\n"
194     gdb_expect {
195         -re "type = class explicit_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
196             pass "ptype class explicit_private_class"
197         }
198         -re "type = class explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
199             pass "ptype class explicit_private_class (OK for HP aCC)"
200         }
201         -re "type = struct explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
202             setup_xfail "*-*-*"
203             fail "ptype class explicit_private_class"
204         }
205         -re ".*$gdb_prompt $" { fail "ptype class explicit_private_class" }
206         timeout { fail "ptype class explicit_private_class (timeout)" ; return }
207     }
208
209     send_gdb "ptype class mixed_protection_class\n"
210     gdb_expect {
211         -re "type = class mixed_protection_class \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl.*\}$nl$gdb_prompt $" {
212             pass "ptype class mixed_protection_class"
213         }
214         -re "type = struct mixed_protection_class \{${ws}int a;${ws}int b;${ws}int c;${ws}int d;${ws}int e;${ws}int f;${ws}int g;${ws}int h;${ws}int i;$nl.*\}$nl$gdb_prompt $" {
215             setup_xfail "*-*-*"
216             fail "ptype class mixed_protection_class"
217         }
218         -re ".*$gdb_prompt $" { fail "ptype class mixed_protection_class" }
219         timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
220     }
221
222     # This class does not use any C++-specific features, so it's fine for
223     # it to print as "struct".
224     send_gdb "ptype class A\n"
225     gdb_expect {
226         -re "type = (class|struct) A \{(${ws}public:|)${ws}int a;${ws}int x;((${ws}A & operator=\\(A const &\\);)|(${ws}A\\(A const &\\);)|(${ws}A\\(void\\);))*${ws}\}$nl$gdb_prompt $" {
227             pass "ptype class A"
228         }
229         -re ".*$gdb_prompt $" {
230             fail "ptype class A"
231         }
232         timeout {
233             fail "ptype class A (timeout)"
234             return
235         }
236     }
237
238     setup_xfail_format "DWARF 1"
239     send_gdb "ptype class B\n"
240     gdb_expect {
241         -re "type = class B : public A \{${ws}public:${ws}int b;${ws}int x;${ws}B & operator=\\(B const &\\);${ws}B\\(B const &\\);${ws}B\\(void\\);${ws}\}$nl$gdb_prompt $" {
242             pass "ptype class B"
243         }
244         -re "type = class B : public A \{${ws}public:${ws}int b;${ws}int x;((${ws}B & operator=\\(B const &\\);)|(${ws}B\\(B const &\\);)|(${ws}B\\(void\\);))*${ws}\}$nl$gdb_prompt $" {
245             pass "ptype class B (obsolescent gcc or gdb)"
246         }
247         -re ".*$gdb_prompt $" {
248             fail "ptype class B"
249         }
250         timeout {
251             fail "ptype class B (timeout)"
252             return
253         }
254     }
255
256     setup_xfail_format "DWARF 1"
257     send_gdb "ptype class C\n"
258     gdb_expect {
259         -re "type = class C : public A \{${ws}public:${ws}int c;${ws}int x;${ws}C & operator=\\(C const &\\);${ws}C\\(C const &\\);${ws}C\\(void\\);${ws}\}$nl$gdb_prompt $" {
260             pass "ptype class C"
261         }
262         -re "type = class C : public A \{${ws}public:${ws}int c;${ws}int x;((${ws}C & operator=\\(C const &\\);)|(${ws}C\\(C const &\\);)|(${ws}C\\(void\\);))*${ws}\}$nl$gdb_prompt $" {
263             pass "ptype class C (obsolescent gcc or gdb)"
264         }
265         -re ".*$gdb_prompt $" {
266             fail "ptype class C"
267         }
268         timeout {
269             fail "ptype class C (timeout)"
270             return
271         }
272     }
273
274     setup_xfail_format "DWARF 1"
275     send_gdb "ptype class D\n"
276     gdb_expect {
277         -re "type = class D : public B, public C \{${ws}public:${ws}int d;${ws}int x;${ws}D & operator=\\(D const &\\);${ws}D\\(D const &\\);${ws}D\\(void\\);${ws}\}$nl$gdb_prompt $" {
278             pass "ptype class D"
279         }
280         -re "type = class D : public B, public C \{${ws}public:${ws}int d;${ws}int x;((${ws}D & operator=\\(D const &\\);)|(${ws}D\\(D const &\\);)|(${ws}D\\(void\\);))*${ws}\}$nl$gdb_prompt $" {
281             pass "ptype class D (obsolescent gcc or gdb)"
282         }
283         -re ".*$gdb_prompt $" {
284             fail "ptype class D"
285         }
286         timeout {
287             fail "ptype class D (timeout)"
288             return
289         }
290     }
291
292     setup_xfail_format "DWARF 1"
293     send_gdb "ptype class E\n"
294     gdb_expect {
295         -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;${ws}E & operator=\\(E const &\\);${ws}E\\(E const &\\);${ws}E\\(void\\);${ws}\}$nl$gdb_prompt $" {
296             pass "ptype class E"
297         }
298         -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;((${ws}E & operator=\\(E const &\\);)|(${ws}E\\(E const &\\);)|(${ws}E\\(void\\);))*${ws}\}$nl$gdb_prompt $" {
299             pass "ptype class E"
300         }
301         -re ".*$gdb_prompt $" {
302             fail "ptype class E"
303         }
304         timeout {
305             fail "ptype class E (timeout)"
306             return
307         }
308     }
309
310     send_gdb "ptype class vA\n"
311     gdb_expect {
312         -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;${ws}vA & operator=\\(vA const &\\);${ws}vA\\(vA const &\\);${ws}vA\\(void\\);${ws}\}$nl$gdb_prompt $" {
313             pass "ptype class vA"
314         }
315         -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;((${ws}vA & operator=\\(vA const &\\);)|(${ws}vA\\(vA const &\\);)|(${ws}vA\\(void\\);))*${ws}\}$nl$gdb_prompt $" {
316             pass "ptype class vA (obsolescent gcc or gdb)"
317         }
318         -re ".*$gdb_prompt $" {
319             fail "ptype class vA"
320         }
321         timeout {
322             fail "ptype class vA (timeout)"
323             return
324         }
325     }
326
327     # Accept the form with embedded GNU style mangled virtual table constructs
328     # for now, but with a FIXME.  At some future point, gdb should use a
329     # portable representation for the virtual table constructs.
330
331     setup_xfail_format "DWARF 1"
332     send_gdb "ptype class vB\n"
333     gdb_expect {
334         -re "type = class vB : public virtual vA \{${ws}private:${ws}vA \\*_vb.vA;${ws}public:${ws}int vb;${ws}int vx;${ws}vB & operator=\\(vB const &\\);${ws}vB\\(int, vB const &\\);${ws}vB\\(int\\);${ws}\}$nl$gdb_prompt $" {
335             setup_xfail "*-*-*"
336             fail "ptype class vB (FIXME: non-portable virtual table constructs)"
337         }
338         -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
339             pass "ptype class vB (aCC)"
340         }
341         -re "type = class vB : public virtual vA \{${ws}private:${ws}vA \\*_vb.vA;${ws}public:${ws}int vb;${ws}int vx;((${ws}vB & operator=\\(vB const &\\);)|(${ws}vB\\(int, vB const &\\);)|(${ws}vB\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
342             setup_xfail "*-*-*"
343             fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
344         }
345         -re ".*$gdb_prompt $" {
346             fail "ptype class vB"
347         }
348         timeout {
349             fail "ptype class vB (timeout)"
350             return
351         }
352     }
353
354     # Accept the form with embedded GNU style mangled virtual table constructs
355     # for now, but with a FIXME.  At some future point, gdb should use a
356     # portable representation for the virtual table constructs.
357
358     setup_xfail_format "DWARF 1"
359     send_gdb "ptype class vC\n"
360     gdb_expect {
361         -re "type = class vC : public virtual vA \{${ws}private:${ws}vA \\*_vb.vA;${ws}public:${ws}int vc;${ws}int vx;${ws}vC & operator=\\(vC const &\\);${ws}vC\\(int, vC const &\\);${ws}vC\\(int\\);${ws}\}$nl$gdb_prompt $" {
362             setup_xfail "*-*-*"
363             fail "ptype class vC (FIXME: non-portable virtual table constructs)"
364         }
365         -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
366             pass "ptype class vC (aCC)"
367         }
368         -re "type = class vC : public virtual vA \{${ws}private:${ws}vA \\*_vb.vA;${ws}public:${ws}int vc;${ws}int vx;((${ws}vC & operator=\\(vC const &\\);)|(${ws}vC\\(int, vC const &\\);)|(${ws}vC\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
369             setup_xfail "*-*-*"
370             fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
371         }
372         -re ".*$gdb_prompt $" {
373             fail "ptype class vC"
374         }
375         timeout {
376             fail "ptype class vC (timeout)"
377             return
378         }
379     }
380
381     # Accept the form with embedded GNU style mangled virtual table constructs
382     # for now, but with a FIXME.  At some future point, gdb should use a
383     # portable representation for the virtual table constructs.
384
385     setup_xfail_format "DWARF 1"
386     send_gdb "ptype class vD\n"
387     gdb_expect {
388         -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC \\*_vb.vC;${ws}vB \\*_vb.vB;${ws}public:${ws}int vd;${ws}int vx;${ws}vD & operator=\\(vD const &\\);${ws}vD\\(int, vD const &\\);${ws}vD\\(int\\);${ws}\}$nl$gdb_prompt $" {
389             setup_xfail "*-*-*"
390             fail "ptype class vD (FIXME: non-portable virtual table constructs)"
391         }
392         -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
393             pass "ptype class vD (aCC)"
394         }
395         -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC \\*_vb.vC;${ws}vB \\*_vb.vB;${ws}public:${ws}int vd;${ws}int vx;((${ws}vD & operator=\\(vD const &\\);)|(${ws}vD\\(int, vD const &\\);)|(${ws}vD\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
396             setup_xfail "*-*-*"
397             fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
398         }
399         -re ".*$gdb_prompt $" {
400             fail "ptype class vD"
401         }
402         timeout {
403             fail "ptype class vD (timeout)"
404             return
405         }
406     }
407
408     # Accept the form with embedded GNU style mangled virtual table constructs
409     # for now, but with a FIXME.  At some future point, gdb should use a
410     # portable representation for the virtual table constructs.
411
412     setup_xfail_format "DWARF 1"
413     send_gdb "ptype class vE\n"
414     gdb_expect {
415         -re "type = class vE : public virtual vD \{${ws}private:${ws}vD \\*_vb.vD;${ws}public:${ws}int ve;${ws}int vx;${ws}vE & operator=\\(vE const &\\);${ws}vE\\(int, vE const &\\);${ws}vE\\(int\\);${ws}\}$nl$gdb_prompt $" {
416             setup_xfail "*-*-*"
417             fail "ptype class vE (FIXME: non-portable virtual table constructs)"
418         }
419         -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
420             pass "ptype class vE (aCC)"
421         }
422         -re "type = class vE : public virtual vD \{${ws}private:${ws}vD \\*_vb.vD;${ws}public:${ws}int ve;${ws}int vx;((${ws}vE & operator=\\(vE const &\\);)|(${ws}vE\\(int, vE const &\\);)|(${ws}vE\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
423             setup_xfail "*-*-*"
424             fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
425         }
426         -re ".*$gdb_prompt $" {
427             fail "ptype class vE"
428         }
429         timeout {
430             fail "ptype class vE (timeout)"
431             return
432         }
433     }
434
435     setup_xfail_format "DWARF 1"
436     send_gdb "ptype class Base1\n"
437     gdb_expect {
438         -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1 & operator=\\(Base1 const &\\);${ws}Base1\\(Base1 const &\\);${ws}Base1\\(int\\);${ws}\}$nl$gdb_prompt $" {
439             pass "ptype class Base1"
440         }
441         -re "type = class Base1 \{${ws}public:${ws}int x;((${ws}Base1 & operator=\\(Base1 const &\\);)|(${ws}Base1\\(Base1 const &\\);)|(${ws}Base1\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
442             pass "ptype class Base1 (obsolescent gcc or gdb)"
443         }
444         -re ".*$gdb_prompt $" {
445             fail "ptype class Base1"
446         }
447         timeout {
448             fail "ptype class Base1 (timeout)"
449             return
450         }
451     }
452
453     setup_xfail_format "DWARF 1"
454     send_gdb "ptype class Foo\n"
455     gdb_expect {
456         -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;\r\n${ws}Foo\\(int, int\\);${ws}int operator!.void.;${ws}operator int.void.;${ws}int times.int.;$nl\}$nl$gdb_prompt $" {
457             pass "ptype class Foo(aCC)"
458         }
459         -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;${ws}Foo & operator=\\(Foo const &\\);${ws}Foo\\(Foo const &\\);${ws}Foo\\(int, int\\);${ws}int operator!\\(void\\);${ws}int operator int\\(void\\);${ws}int times\\(int\\);${ws}\}$nl$gdb_prompt $" {
460             pass "ptype class Foo"
461         }
462         -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;((${ws}Foo & operator=\\(Foo const &\\);)|(${ws}Foo\\(Foo const &\\);)|(${ws}Foo\\(int, int\\);)|(${ws}int operator!\\(void\\);)|(${ws}int operator int\\(void\\);)|(${ws}int times\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
463             pass "ptype class Foo (obsolescent gcc or gdb)"
464         }
465         -re ".*$gdb_prompt $" {
466             fail "ptype class Foo"
467         }
468         timeout {
469             fail "ptype class Foo (timeout)"
470             return
471         }
472     }
473
474     setup_xfail_format "DWARF 1"
475     send_gdb "ptype class Bar\n"
476     gdb_expect {
477         -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;${ws}Bar & operator=\\(Bar const &\\);${ws}Bar\\(Bar const &\\);${ws}Bar\\(int, int, int\\);${ws}\}$nl$gdb_prompt $" {
478             pass "ptype class Bar"
479         }
480         -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;((${ws}Bar & operator=\\(Bar const &\\);)|(${ws}Bar\\(Bar const &\\);)|(${ws}Bar\\(int, int, int\\);))*${ws}\}$nl$gdb_prompt $" {
481             pass "ptype class Bar (obsolescent gcc or gdb)"
482         }
483         -re ".*$gdb_prompt $" {
484             fail "ptype class Bar"
485         }
486         timeout {
487             fail "ptype class Bar (timeout)"
488             return
489         }
490     }
491 }
492
493 #
494 # Test simple access to class members.
495 #
496
497 proc test_non_inherited_member_access {} {
498     global gdb_prompt
499     
500     # Print non-inherited members of g_A.
501
502     gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
503
504     gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
505
506     # Print non-inherited members of g_B.
507
508     gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
509
510     gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
511
512     # Print non-inherited members of g_C.
513
514     gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
515
516     gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
517
518     # Print non-inherited members of g_D.
519
520     gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
521
522     gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
523
524     # Print non-inherited members of g_E.
525
526     gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
527
528     gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
529 }
530
531 #
532 # Try access to non-members that are members of another class.
533 # Should give errors.
534 #
535
536 proc test_wrong_class_members {} {
537     global gdb_prompt
538
539     gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
540
541     gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
542
543     gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
544
545     gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
546
547     gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
548
549     gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
550 }
551
552 #
553 # Try access to non-members that are not members of any class.
554 # Should give errors.
555 #
556
557 proc test_nonexistant_members {} {
558     global gdb_prompt
559
560     gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
561
562     gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
563
564     gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
565
566     gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
567 }
568
569 #
570 # Pointers to class members
571 #
572
573 proc test_pointers_to_class_members {} {
574     global gdb_prompt
575     global decimal
576     global nl
577
578     gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
579
580     gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
581
582     gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
583
584     send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
585     gdb_expect {
586         -re ".* = true$nl$gdb_prompt $" {
587             pass "print (int)&Bar::y == 2*sizeof(int)"
588         }
589         -re "There is no field named y.*$gdb_prompt $" {
590             setup_xfail "*-*-*"
591             fail "print (int)&Bar::y == 2*sizeof(int)"
592         }
593         -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
594         timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
595     }
596
597     send_gdb "next 2\n"
598     setup_xfail "*-*-*"
599     gdb_expect {
600         -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
601         -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
602     }
603     clear_xfail "*-*-*"
604
605     setup_xfail_format "DWARF 1"
606     gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
607 }
608
609 #
610 # Test static members.
611 #
612
613 proc test_static_members {} {
614     global gdb_prompt
615     global hex
616     global nl
617
618     send_gdb "print Foo::st\n"
619     gdb_expect {
620         -re ".* = 100$nl$gdb_prompt $" {
621             pass "print Foo::st"
622         }
623         -re "There is no field named st.*$gdb_prompt $" {
624             setup_xfail "*-*-*"
625             fail "print Foo::st"
626         }
627         -re ".*$gdb_prompt $" { fail "print Foo::st" }
628        timeout { fail "print Foo::st (timeout)" ; return }
629     }
630
631     send_gdb "set foo.st = 200\n"
632     gdb_expect {
633         -re ".*$gdb_prompt $" {}
634     }
635
636     send_gdb "print bar.st\n"
637     gdb_expect {
638         -re ".* = 200$nl$gdb_prompt $" {
639             pass "print bar.st"
640         }
641         -re "There is no member( or method|) named st.*$gdb_prompt $" {
642             setup_xfail "*-*-*"
643             fail "print bar.st"
644         }
645         -re ".*$gdb_prompt $" { fail "print bar.st" }
646        timeout { fail "print bar.st (timeout)" ; return }
647     }
648
649     send_gdb "print &foo.st\n"
650     gdb_expect {
651         -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
652             pass "print &foo.st"
653         }
654         -re "There is no member( or method|) named st.*$gdb_prompt $" {
655             setup_xfail "*-*-*"
656             fail "print &foo.st"
657         }
658         -re ".*$gdb_prompt $" { fail "print &foo.st" }
659        timeout { fail "print &foo.st (timeout)" ; return }
660     }
661
662     set got_bar_st 0
663     send_gdb "print &Bar::st\n"
664     gdb_expect {
665         -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
666             pass "print &Bar::st"
667             set got_bar_st 1
668         }
669         -re "There is no field named st.*$gdb_prompt $" {
670             setup_xfail "*-*-*"
671             fail "print &Bar::st"
672         }
673         -re ".*$gdb_prompt $" { fail "print &Bar::st" }
674        timeout { fail "print &Bar::st (timeout)" ; return }
675     }
676
677     if $got_bar_st then {
678         gdb_test "print *\$" ".* = 200" "print *\$"
679     }
680
681     gdb_test "set print static-members off" ""
682     gdb_test "print csi" \
683         "{x = 10, y = 20}" \
684         "print csi without static members"
685     gdb_test "print cnsi" \
686         "{x = 30, y = 40}" \
687         "print cnsi without static members"
688
689     gdb_test "set print static-members on" ""
690     setup_xfail_format "DWARF 1"
691     gdb_test "print csi" \
692         "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
693         "print csi with static members"
694     setup_xfail_format "DWARF 1"
695     gdb_test "print cnsi" \
696         "{x = 30, y = 40, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>, static yy = {z = 5, static xx = {x = 1, y = 2, static null = <same as static member of an already seen type>, static yy = <same as static member of an already seen type>}}}, static yy = <same as static member of an already seen type>}" \
697         "print cnsi with static members"
698 }
699
700 proc do_tests {} {
701     global prms_id
702     global bug_id
703     global subdir
704     global objdir
705     global srcdir
706     global binfile
707     global gdb_prompt
708
709     set prms_id 0
710     set bug_id 0
711
712     # Start with a fresh gdb.
713
714     gdb_exit
715     gdb_start
716     gdb_reinitialize_dir $srcdir/$subdir
717     gdb_load $binfile
718
719     send_gdb "set language c++\n"
720     gdb_expect -re "$gdb_prompt $"
721     send_gdb "set width 0\n"
722     gdb_expect -re "$gdb_prompt $"
723
724     # Get the debug format for the compiled test case.
725
726     if [ runto_main ] then {
727         get_debug_format
728     }
729
730     test_ptype_class_objects
731
732     if [ runto 'inheritance2(void)' ] then {
733         test_non_inherited_member_access
734         test_wrong_class_members
735         test_nonexistant_members
736     }
737
738     if [istarget "mips-idt-*"] then {
739         # Restart because IDT/SIM runs out of file descriptors.
740         gdb_exit
741         gdb_start
742         gdb_reinitialize_dir $srcdir/$subdir
743         gdb_load $binfile
744     }
745
746     if [ runto_main ] then {
747         test_pointers_to_class_members
748         test_static_members
749     }
750
751     if [istarget "mips-idt-*"] then {
752         # Restart because IDT/SIM runs out of file descriptors.
753         gdb_exit
754         gdb_start
755         gdb_reinitialize_dir $srcdir/$subdir
756         gdb_load $binfile
757     }
758  
759     if [ runto marker_reg1 ] then {
760
761         gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
762
763         send_gdb "print v.method ()\n"
764         gdb_expect {
765             -re "= 82.*$gdb_prompt $" {
766                 pass "calling method for small class"
767             }
768             -re "Address requested for identifier .v. which is in a register.*$gdb_prompt $" {
769                 setup_xfail "*-*-*" 2972
770                 fail "calling method for small class"
771             }
772             -re ".*$gdb_prompt $" { fail "calling method for small class" }
773             timeout { fail "calling method for small class (timeout)" }
774             eof { fail "calling method for small class (eof)" }
775         }
776     }
777
778 }
779
780 do_tests
781
782
783 # Some additional tests for enums inside classes
784
785
786 # set a breakpoint and go there
787 send_gdb "break 516\n"   
788 gdb_expect {   
789    -re "Breakpoint \[0-9\] at.*$gdb_prompt $" { pass "set break 516" }
790    -re "$gdb_prompt $"                     { fail "set break 516" }
791    timeout                             { fail "(timeout) set break 516" }
792 }
793 send_gdb "continue\n"   
794 gdb_expect {   
795    -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, main....at.*misc\\.cc:516\r\n516.*\r\n$gdb_prompt $" { pass "continue" }
796    -re "$gdb_prompt $"                     { fail "continue" }
797    timeout                             { fail "(timeout) continue" }
798 }
799
800 # print the object
801 send_gdb "print obj_with_enum\n"   
802 gdb_expect {   
803    -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
804    -re "$gdb_prompt $"                     { fail "print obj_with_enum (1)" }
805    timeout                             { fail "(timeout) print obj_with_enum (1)" }
806 }
807
808 send_gdb "next\n"   
809 gdb_expect {   
810    -re "$gdb_prompt $"                     { pass "next" }
811    timeout                             { fail "(timeout) next" }
812 }
813
814 # print the object again
815 send_gdb "print obj_with_enum\n"   
816 gdb_expect {   
817    -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
818    -re "$gdb_prompt $"                     { fail "print obj_with_enum (2)" }
819    timeout                             { fail "(timeout) print obj_with_enum (2)" }
820 }
821
822 # print out the enum member
823 send_gdb "print obj_with_enum.priv_enum\n"   
824 gdb_expect {   
825    -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
826    -re "$gdb_prompt $"                     { fail "print obj_with_enum.priv_enum" }
827    timeout                             { fail "(timeout) print obj_with_enum.priv_enum" }
828 }
829
830 # ptype on the enum member
831 # The second success case is a little dubious, but it's not clear what
832 # ought to be required of a ptype on a private enum... -sts 19990324
833 send_gdb "ptype obj_with_enum.priv_enum\n"   
834 gdb_expect {   
835    -re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
836    -re "type = enum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
837    -re "$gdb_prompt $"                     { fail "ptype obj_with_enum.priv_enum" }
838    timeout                             { fail "(timeout) ptype obj_with_enum.priv_enum" }
839 }
840
841 # ptype on the object
842 # g++ is putting out the wrong debug info.  This works with aCC
843 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
844 send_gdb "ptype obj_with_enum\n"   
845 gdb_expect {   
846    -re "type = class ClassWithEnum \\{\r\n\[ \t\]*public:\r\n\[ \t\]*(enum |)ClassWithEnum::PrivEnum priv_enum;\r\n\[ \t\]*int x;\r\n\\}\r\n$gdb_prompt $" { pass "ptype obj_with_enum" }
847    -re "$gdb_prompt $"                     { fail "ptype obj_with_enum" }
848    timeout                             { fail "(timeout) ptype obj_with_enum" }
849 }
850
851 # g++ is putting out the wrong debug info.  This works with aCC
852 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
853 send_gdb "print (ClassWithEnum::PrivEnum) 42\n"   
854 gdb_expect {   
855    -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
856    -re "$gdb_prompt $"                     { fail "print (ClassWithEnum::PrivEnum) 42" }
857    timeout                             { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
858 }
859
860
861 send_gdb "maint demangle inheritance1__Fv\n"
862 gdb_expect {
863    -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
864    -re ".*$gdb_prompt $"   { fail "demangle" }
865    timeout           { fail "(timeout) demangle" }
866 }
867