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