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