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