Fix memory leaks for IA-64 opcode idescs.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.c++ / classes.exp
CommitLineData
c2d11a7d 1# Copyright (C) 1992, 1994, 1995, 1997, 1999 Free Software Foundation, Inc.
c906108c
SS
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
22set ws "\[\r\n\t \]+"
23set nl "\[\r\n\]+"
24
25if $tracelevel then {
26 strace $tracelevel
27}
28
d4f3574e 29if { [skip_cplus_tests] } { continue }
c906108c
SS
30
31set testfile "misc"
32set srcfile ${testfile}.cc
33set 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
38if [get_compiler_info ${binfile} "c++"] {
39 return -1
40}
41
c906108c
SS
42if { [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
50proc 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 }
a0b3c4fd
JM
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 }
c906108c
SS
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 }
a0b3c4fd
JM
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 }
c906108c
SS
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
c2d11a7d
JM
331 # The format of a g++ virtual base pointer.
332 set vbptr "(_vb\[$.\]|__vb_)\[0-9\]?"
333
c906108c
SS
334 setup_xfail_format "DWARF 1"
335 send_gdb "ptype class vB\n"
336 gdb_expect {
c2d11a7d 337 -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 $" {
c906108c
SS
338 setup_xfail "*-*-*"
339 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
340 }
a0b3c4fd
JM
341 -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
342 pass "ptype class vB (aCC)"
343 }
c906108c
SS
344 -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 $" {
345 setup_xfail "*-*-*"
346 fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
347 }
348 -re ".*$gdb_prompt $" {
349 fail "ptype class vB"
350 }
351 timeout {
352 fail "ptype class vB (timeout)"
353 return
354 }
355 }
356
357 # Accept the form with embedded GNU style mangled virtual table constructs
358 # for now, but with a FIXME. At some future point, gdb should use a
359 # portable representation for the virtual table constructs.
360
361 setup_xfail_format "DWARF 1"
362 send_gdb "ptype class vC\n"
363 gdb_expect {
c2d11a7d 364 -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 $" {
c906108c
SS
365 setup_xfail "*-*-*"
366 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
367 }
a0b3c4fd
JM
368 -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
369 pass "ptype class vC (aCC)"
370 }
c906108c
SS
371 -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 $" {
372 setup_xfail "*-*-*"
373 fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
374 }
375 -re ".*$gdb_prompt $" {
376 fail "ptype class vC"
377 }
378 timeout {
379 fail "ptype class vC (timeout)"
380 return
381 }
382 }
383
384 # Accept the form with embedded GNU style mangled virtual table constructs
385 # for now, but with a FIXME. At some future point, gdb should use a
386 # portable representation for the virtual table constructs.
387
388 setup_xfail_format "DWARF 1"
389 send_gdb "ptype class vD\n"
390 gdb_expect {
c2d11a7d 391 -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 $" {
c906108c
SS
392 setup_xfail "*-*-*"
393 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
394 }
a0b3c4fd
JM
395 -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
396 pass "ptype class vD (aCC)"
397 }
c906108c
SS
398 -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 $" {
399 setup_xfail "*-*-*"
400 fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
401 }
402 -re ".*$gdb_prompt $" {
403 fail "ptype class vD"
404 }
405 timeout {
406 fail "ptype class vD (timeout)"
407 return
408 }
409 }
410
411 # Accept the form with embedded GNU style mangled virtual table constructs
412 # for now, but with a FIXME. At some future point, gdb should use a
413 # portable representation for the virtual table constructs.
414
415 setup_xfail_format "DWARF 1"
416 send_gdb "ptype class vE\n"
417 gdb_expect {
c2d11a7d 418 -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 $" {
c906108c
SS
419 setup_xfail "*-*-*"
420 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
421 }
a0b3c4fd
JM
422 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
423 pass "ptype class vE (aCC)"
424 }
c906108c
SS
425 -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 $" {
426 setup_xfail "*-*-*"
427 fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
428 }
429 -re ".*$gdb_prompt $" {
430 fail "ptype class vE"
431 }
432 timeout {
433 fail "ptype class vE (timeout)"
434 return
435 }
436 }
437
438 setup_xfail_format "DWARF 1"
439 send_gdb "ptype class Base1\n"
440 gdb_expect {
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"
443 }
444 -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 $" {
445 pass "ptype class Base1 (obsolescent gcc or gdb)"
446 }
447 -re ".*$gdb_prompt $" {
448 fail "ptype class Base1"
449 }
450 timeout {
451 fail "ptype class Base1 (timeout)"
452 return
453 }
454 }
455
456 setup_xfail_format "DWARF 1"
457 send_gdb "ptype class Foo\n"
458 gdb_expect {
a0b3c4fd
JM
459 -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 $" {
460 pass "ptype class Foo(aCC)"
461 }
c2d11a7d 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}operator int\\(void\\);${ws}int times\\(int\\);${ws}\}$nl$gdb_prompt $" {
c906108c
SS
463 pass "ptype class Foo"
464 }
465 -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 $" {
466 pass "ptype class Foo (obsolescent gcc or gdb)"
467 }
468 -re ".*$gdb_prompt $" {
469 fail "ptype class Foo"
470 }
471 timeout {
472 fail "ptype class Foo (timeout)"
473 return
474 }
475 }
476
477 setup_xfail_format "DWARF 1"
478 send_gdb "ptype class Bar\n"
479 gdb_expect {
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"
482 }
483 -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 $" {
484 pass "ptype class Bar (obsolescent gcc or gdb)"
485 }
486 -re ".*$gdb_prompt $" {
487 fail "ptype class Bar"
488 }
489 timeout {
490 fail "ptype class Bar (timeout)"
491 return
492 }
493 }
494}
495
496#
497# Test simple access to class members.
498#
499
500proc test_non_inherited_member_access {} {
501 global gdb_prompt
502
503 # Print non-inherited members of g_A.
504
505 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
506
507 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
508
509 # Print non-inherited members of g_B.
510
511 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
512
513 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
514
515 # Print non-inherited members of g_C.
516
517 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
518
519 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
520
521 # Print non-inherited members of g_D.
522
523 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
524
525 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
526
527 # Print non-inherited members of g_E.
528
529 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
530
531 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
532}
533
534#
535# Try access to non-members that are members of another class.
536# Should give errors.
537#
538
539proc test_wrong_class_members {} {
540 global gdb_prompt
541
542 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
543
544 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
545
546 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
547
548 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
549
550 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
551
552 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
553}
554
555#
556# Try access to non-members that are not members of any class.
557# Should give errors.
558#
559
2bec0572 560proc test_nonexistent_members {} {
c906108c
SS
561 global gdb_prompt
562
563 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
564
565 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
566
567 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
568
569 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
570}
571
54602222
ND
572#
573# Call a method that expects a base class parameter with base, inherited,
574# and unrelated class arguments.
575#
576
577proc test_method_param_class {} {
578 gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" "base class param->a"
579 gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" "base class param->x"
580 gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" "inherited class param->a"
581 gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" "inherited class param->x"
582 gdb_test "call class_param.Aref_a (g_A)" ".* = 1" "base class (&param)->a"
583 gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (&param)->x"
584 gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (&param)->a"
585 gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (&param)->x"
586 gdb_test "call class_param.Aval_a (g_A)" ".* = 1" "base class param.a"
587 gdb_test "call class_param.Aval_x (g_A)" ".* = 2" "base class param.x"
588 gdb_test "call class_param.Aval_a (g_B)" ".* = 3" "inherited class param.a"
589 gdb_test "call class_param.Aval_x (g_B)" ".* = 4" "inherited class param.x"
590
591 gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param"
592 gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class &param"
593 gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"
594}
595
2bec0572
ND
596#
597# Examine a class with an enum field.
598#
599
600proc test_enums {} {
601 global gdb_prompt
602 global hp_aCC_compiler
603
604 # print the object
605 send_gdb "print obj_with_enum\n"
606 gdb_expect {
607 -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
608 -re "$gdb_prompt $" { fail "print obj_with_enum (1)" }
609 timeout { fail "(timeout) print obj_with_enum (1)" }
610 }
611
612 send_gdb "next\n"
613 gdb_expect {
614 -re "$gdb_prompt $" { pass "next" }
615 timeout { fail "(timeout) next" }
616 }
617
618 # print the object again
619 send_gdb "print obj_with_enum\n"
620 gdb_expect {
621 -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
622 -re "$gdb_prompt $" { fail "print obj_with_enum (2)" }
623 timeout { fail "(timeout) print obj_with_enum (2)" }
624 }
625
626 # print out the enum member
627 send_gdb "print obj_with_enum.priv_enum\n"
628 gdb_expect {
629 -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
630 -re "$gdb_prompt $" { fail "print obj_with_enum.priv_enum" }
631 timeout { fail "(timeout) print obj_with_enum.priv_enum" }
632 }
633
634 # ptype on the enum member
635 # The third success case is a little dubious, but it's not clear what
636 # ought to be required of a ptype on a private enum... -sts 19990324
637 send_gdb "ptype obj_with_enum.priv_enum\n"
638 gdb_expect {
639 -re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
640 -re "type = enum PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
641 -re "type = enum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
642 -re "$gdb_prompt $" { fail "ptype obj_with_enum.priv_enum" }
643 timeout { fail "(timeout) ptype obj_with_enum.priv_enum" }
644 }
645
646 # ptype on the object
647 # g++ is putting out the wrong debug info. This works with aCC
648 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
649 send_gdb "ptype obj_with_enum\n"
650 gdb_expect {
651 -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" }
652 -re "$gdb_prompt $" { fail "ptype obj_with_enum" }
653 timeout { fail "(timeout) ptype obj_with_enum" }
654 }
655
656 # g++ is putting out the wrong debug info. This works with aCC
657 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
658 send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
659 gdb_expect {
660 -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
661 -re "$gdb_prompt $" { fail "print (ClassWithEnum::PrivEnum) 42" }
662 timeout { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
663 }
664}
665
c906108c
SS
666#
667# Pointers to class members
668#
669
670proc test_pointers_to_class_members {} {
671 global gdb_prompt
672 global decimal
673 global nl
674
675 gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
676
677 gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
678
679 gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
680
681 send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
682 gdb_expect {
683 -re ".* = true$nl$gdb_prompt $" {
684 pass "print (int)&Bar::y == 2*sizeof(int)"
685 }
686 -re "There is no field named y.*$gdb_prompt $" {
687 setup_xfail "*-*-*"
688 fail "print (int)&Bar::y == 2*sizeof(int)"
689 }
690 -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
691 timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
692 }
693
a0b3c4fd 694 send_gdb "next 2\n"
c906108c
SS
695 setup_xfail "*-*-*"
696 gdb_expect {
697 -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
698 -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
699 }
700 clear_xfail "*-*-*"
701
702 setup_xfail_format "DWARF 1"
703 gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
704}
705
706#
707# Test static members.
708#
709
710proc test_static_members {} {
711 global gdb_prompt
712 global hex
713 global nl
714
715 send_gdb "print Foo::st\n"
716 gdb_expect {
717 -re ".* = 100$nl$gdb_prompt $" {
718 pass "print Foo::st"
719 }
720 -re "There is no field named st.*$gdb_prompt $" {
721 setup_xfail "*-*-*"
722 fail "print Foo::st"
723 }
724 -re ".*$gdb_prompt $" { fail "print Foo::st" }
725 timeout { fail "print Foo::st (timeout)" ; return }
726 }
727
728 send_gdb "set foo.st = 200\n"
729 gdb_expect {
730 -re ".*$gdb_prompt $" {}
731 }
732
733 send_gdb "print bar.st\n"
734 gdb_expect {
735 -re ".* = 200$nl$gdb_prompt $" {
736 pass "print bar.st"
737 }
738 -re "There is no member( or method|) named st.*$gdb_prompt $" {
739 setup_xfail "*-*-*"
740 fail "print bar.st"
741 }
742 -re ".*$gdb_prompt $" { fail "print bar.st" }
743 timeout { fail "print bar.st (timeout)" ; return }
744 }
745
746 send_gdb "print &foo.st\n"
747 gdb_expect {
748 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
749 pass "print &foo.st"
750 }
751 -re "There is no member( or method|) named st.*$gdb_prompt $" {
752 setup_xfail "*-*-*"
753 fail "print &foo.st"
754 }
755 -re ".*$gdb_prompt $" { fail "print &foo.st" }
756 timeout { fail "print &foo.st (timeout)" ; return }
757 }
758
759 set got_bar_st 0
760 send_gdb "print &Bar::st\n"
761 gdb_expect {
762 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
763 pass "print &Bar::st"
764 set got_bar_st 1
765 }
766 -re "There is no field named st.*$gdb_prompt $" {
767 setup_xfail "*-*-*"
768 fail "print &Bar::st"
769 }
770 -re ".*$gdb_prompt $" { fail "print &Bar::st" }
771 timeout { fail "print &Bar::st (timeout)" ; return }
772 }
773
774 if $got_bar_st then {
775 gdb_test "print *\$" ".* = 200" "print *\$"
776 }
777
778 gdb_test "set print static-members off" ""
779 gdb_test "print csi" \
780 "{x = 10, y = 20}" \
781 "print csi without static members"
782 gdb_test "print cnsi" \
783 "{x = 30, y = 40}" \
784 "print cnsi without static members"
785
786 gdb_test "set print static-members on" ""
787 setup_xfail_format "DWARF 1"
788 gdb_test "print csi" \
789 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
790 "print csi with static members"
791 setup_xfail_format "DWARF 1"
792 gdb_test "print cnsi" \
793 "{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>}" \
794 "print cnsi with static members"
795}
796
797proc do_tests {} {
798 global prms_id
799 global bug_id
800 global subdir
801 global objdir
802 global srcdir
803 global binfile
804 global gdb_prompt
805
806 set prms_id 0
807 set bug_id 0
808
809 # Start with a fresh gdb.
810
811 gdb_exit
812 gdb_start
813 gdb_reinitialize_dir $srcdir/$subdir
814 gdb_load $binfile
815
816 send_gdb "set language c++\n"
817 gdb_expect -re "$gdb_prompt $"
818 send_gdb "set width 0\n"
819 gdb_expect -re "$gdb_prompt $"
820
821 # Get the debug format for the compiled test case.
822
823 if [ runto_main ] then {
824 get_debug_format
825 }
826
827 test_ptype_class_objects
828
829 if [ runto 'inheritance2(void)' ] then {
830 test_non_inherited_member_access
831 test_wrong_class_members
2bec0572 832 test_nonexistent_members
54602222 833 test_method_param_class
2bec0572
ND
834 }
835
836 gdb_breakpoint enums2
837 if [ gdb_continue enums2 ]==0 then {
838 send_gdb "finish\n"
839 test_enums
c906108c
SS
840 }
841
842 if [istarget "mips-idt-*"] then {
843 # Restart because IDT/SIM runs out of file descriptors.
844 gdb_exit
845 gdb_start
846 gdb_reinitialize_dir $srcdir/$subdir
847 gdb_load $binfile
848 }
849
850 if [ runto_main ] then {
851 test_pointers_to_class_members
852 test_static_members
853 }
854
855 if [istarget "mips-idt-*"] then {
856 # Restart because IDT/SIM runs out of file descriptors.
857 gdb_exit
858 gdb_start
859 gdb_reinitialize_dir $srcdir/$subdir
860 gdb_load $binfile
861 }
2bec0572 862
c906108c
SS
863 if [ runto marker_reg1 ] then {
864
865 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
866
867 send_gdb "print v.method ()\n"
868 gdb_expect {
869 -re "= 82.*$gdb_prompt $" {
870 pass "calling method for small class"
871 }
872 -re "Address requested for identifier .v. which is in a register.*$gdb_prompt $" {
873 setup_xfail "*-*-*" 2972
874 fail "calling method for small class"
875 }
876 -re ".*$gdb_prompt $" { fail "calling method for small class" }
877 timeout { fail "calling method for small class (timeout)" }
878 eof { fail "calling method for small class (eof)" }
879 }
880 }
881
882}
883
884do_tests
885
c906108c
SS
886send_gdb "maint demangle inheritance1__Fv\n"
887gdb_expect {
888 -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
889 -re ".*$gdb_prompt $" { fail "demangle" }
890 timeout { fail "(timeout) demangle" }
891}
This page took 0.108344 seconds and 4 git commands to generate.