]>
Commit | Line | Data |
---|---|---|
40f235b7 | 1 | # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
184ad485 | 2 | # 2003, 2004 Free Software Foundation, Inc. |
c906108c SS |
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) | |
1cd3489f | 22 | # And rewritten by Michael Chastain <mec.gnu@mindspring.com>. |
c906108c SS |
23 | |
24 | set ws "\[\r\n\t \]+" | |
25 | set nl "\[\r\n\]+" | |
26 | ||
27 | if $tracelevel then { | |
1cd3489f | 28 | strace $tracelevel |
c906108c SS |
29 | } |
30 | ||
d4f3574e | 31 | if { [skip_cplus_tests] } { continue } |
c906108c SS |
32 | |
33 | set testfile "misc" | |
34 | set srcfile ${testfile}.cc | |
35 | set binfile ${objdir}/${subdir}/${testfile} | |
36 | ||
c906108c SS |
37 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { |
38 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
39 | } | |
40 | ||
c906108c SS |
41 | # Test ptype of class objects. |
42 | # | |
1cd3489f MC |
43 | # This code accepts the output of gcc v2 and v3, dwarf-2 and stabs+. |
44 | # It could use some expansion with other compilers such as hp-ux ac++. | |
45 | # | |
46 | # There are lots of variations in the output: | |
47 | # | |
48 | # . gcc -stabs+ emits debug info for implicit member functions: | |
49 | # operator=, copy ctor, ctor. gcc -gdwarf-2 does not. | |
50 | # | |
51 | # . gcc with abi version 1 puts the implicit member functions | |
52 | # at the beginning of the member function list; with abi version 2, | |
53 | # the implicit member functions are at the end of the member function | |
54 | # list. This appears as an output difference with -gstabs+. | |
55 | # gcc 3.3.X defaults to abi version 1, and gcc 3.4 will default | |
56 | # to abi version 2. | |
57 | # | |
58 | # . gcc v2 shows data members for virtual base pointers. | |
59 | # gcc v3 does not. | |
60 | # | |
61 | # . gdb always prints "class" for both "class" and "struct". | |
62 | # In the future, I should accept "struct" in case gdb improves. | |
c906108c SS |
63 | |
64 | proc test_ptype_class_objects {} { | |
65 | global gdb_prompt | |
66 | global ws | |
67 | global nl | |
68 | ||
1cd3489f | 69 | # Simple type. |
c906108c | 70 | |
1cd3489f MC |
71 | gdb_test_multiple "ptype struct default_public_struct" "ptype struct default_public_struct" { |
72 | -re "type = class default_public_struct \{${ws}public:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" { | |
73 | # gcc 2.95.3 -gdwarf-2 | |
74 | # gcc 3.3.2 -gdwarf-2 | |
75 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
c906108c SS |
76 | pass "ptype struct default_public_struct" |
77 | } | |
1cd3489f MC |
78 | -re "type = class default_public_struct \{${ws}public:${ws}int a;${ws}int b;${ws}default_public_struct ?& ?operator ?=\\(default_public_struct const ?&\\);${ws}default_public_struct\\(default_public_struct const ?&\\);${ws}default_public_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
79 | # gcc 2.95.3 -gstabs+ | |
80 | # gcc 3.3.2 -gstabs+ | |
81 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
f683e100 | 82 | pass "ptype struct default_public_struct" |
c906108c | 83 | } |
c906108c SS |
84 | } |
85 | ||
1cd3489f | 86 | # Same test, slightly different type. |
c906108c | 87 | |
1cd3489f MC |
88 | gdb_test_multiple "ptype struct explicit_public_struct" "ptype struct explicit_public_struct" { |
89 | -re "type = class explicit_public_struct \{${ws}public:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" { | |
90 | # gcc 2.95.3 -gdwarf-2 | |
91 | # gcc 3.3.2 -gdwarf-2 | |
92 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
c906108c SS |
93 | pass "ptype struct explicit_public_struct" |
94 | } | |
1cd3489f MC |
95 | -re "type = class explicit_public_struct \{${ws}public:${ws}int a;${ws}int b;${ws}explicit_public_struct ?& ?operator ?=\\(explicit_public_struct const ?&\\);${ws}explicit_public_struct\\(explicit_public_struct const ?&\\);${ws}explicit_public_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
96 | # gcc 2.95.3 -gstabs+ | |
97 | # gcc 3.3.2 -gstabs+ | |
98 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
f683e100 | 99 | pass "ptype struct explicit_public_struct" |
c906108c | 100 | } |
c906108c SS |
101 | } |
102 | ||
1cd3489f | 103 | # Same test, slightly different type. |
c906108c | 104 | |
1cd3489f MC |
105 | gdb_test_multiple "ptype struct protected_struct" "ptype struct protected_struct" { |
106 | -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" { | |
107 | # gcc 2.95.3 -gdwarf-2 | |
108 | # gcc 3.3.2 -gdwarf-2 | |
109 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
f683e100 | 110 | pass "ptype struct protected_struct" |
c906108c | 111 | } |
1cd3489f MC |
112 | -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;${ws}public:${ws}protected_struct ?& ?operator ?=\\(protected_struct const ?&\\);${ws}protected_struct\\(protected_struct const ?&\\);${ws}protected_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
113 | # gcc 2.95.3 -gstabs+ | |
114 | # gcc 3.3.2 -gstabs+ | |
115 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
f683e100 | 116 | pass "ptype struct protected_struct" |
c906108c | 117 | } |
c906108c SS |
118 | } |
119 | ||
1cd3489f | 120 | # Same test, slightly different type. |
c906108c | 121 | |
1cd3489f MC |
122 | gdb_test_multiple "ptype struct private_struct" "ptype struct private_struct" { |
123 | -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" { | |
124 | # gcc 2.95.3 -gdwarf-2 | |
125 | # gcc 3.3.2 -gdwarf-2 | |
126 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
f683e100 | 127 | pass "ptype struct private_struct" |
c906108c | 128 | } |
1cd3489f MC |
129 | -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;${ws}public:${ws}private_struct ?& ?operator ?=\\(private_struct const ?&\\);${ws}private_struct\\(private_struct const ?&\\);${ws}private_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
130 | # gcc 2.95.3 -gstabs+ | |
131 | # gcc 3.3.2 -gstabs+ | |
132 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
f683e100 | 133 | pass "ptype struct private_struct" |
c906108c | 134 | } |
c906108c SS |
135 | } |
136 | ||
1cd3489f | 137 | # Similar test, bigger type. |
c906108c | 138 | |
1cd3489f MC |
139 | gdb_test_multiple "ptype struct mixed_protection_struct" "ptype struct mixed_protection_struct" { |
140 | -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 $" { | |
141 | # gcc 2.95.3 -gdwarf-2 | |
142 | # gcc 3.3.2 -gdwarf-2 | |
143 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
f683e100 | 144 | pass "ptype struct mixed_protection_struct" |
c906108c | 145 | } |
1cd3489f MC |
146 | -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;${ws}public:${ws}mixed_protection_struct ?& ?operator ?=\\(mixed_protection_struct const ?&\\);${ws}mixed_protection_struct\\(mixed_protection_struct const ?&\\);${ws}mixed_protection_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
147 | # gcc 2.95.3 -gstabs+ | |
148 | # gcc 3.3.2 -gstabs+ | |
149 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
f683e100 | 150 | pass "ptype struct mixed_protection_struct" |
c906108c | 151 | } |
c906108c SS |
152 | } |
153 | ||
1cd3489f MC |
154 | # All that again with "class" instead of "struct". |
155 | # gdb does not care about the difference anyways. | |
c906108c | 156 | |
1cd3489f MC |
157 | gdb_test_multiple "ptype class public_class" "ptype class public_class" { |
158 | -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" { | |
159 | # gcc 2.95.3 -gdwarf-2 | |
160 | # gcc 3.3.2 -gdwarf-2 | |
161 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
f683e100 | 162 | pass "ptype class public_class" |
c906108c | 163 | } |
1cd3489f MC |
164 | -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;${ws}public_class ?& ?operator ?=\\(public_class const ?&\\);${ws}public_class\\(public_class const ?&\\);${ws}public_class\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
165 | # gcc 2.95.3 -gstabs+ | |
166 | # gcc 3.3.2 -gstabs+ | |
167 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
8a151ee0 | 168 | pass "ptype class public_class" |
c906108c | 169 | } |
c906108c SS |
170 | } |
171 | ||
1cd3489f MC |
172 | # Same test, slightly different type. |
173 | ||
174 | gdb_test_multiple "ptype class protected_class" "ptype class protected_class" { | |
175 | -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" { | |
176 | # gcc 2.95.3 -gdwarf-2 | |
177 | # gcc 3.3.2 -gdwarf-2 | |
178 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
c906108c SS |
179 | pass "ptype class protected_class" |
180 | } | |
1cd3489f MC |
181 | -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;${ws}public:${ws}protected_class ?& ?operator ?=\\(protected_class const ?&\\);${ws}protected_class\\(protected_class const ?&\\);${ws}protected_class\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
182 | # gcc 2.95.3 -gstabs+ | |
183 | # gcc 3.3.2 -gstabs+ | |
184 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
185 | pass "ptype class protected_class" | |
c906108c | 186 | } |
c906108c SS |
187 | } |
188 | ||
1cd3489f MC |
189 | # Same test, slightly different type. |
190 | # The 'private' is optional but gdb always prints it. | |
c906108c | 191 | |
1cd3489f MC |
192 | gdb_test_multiple "ptype class default_private_class" "ptype class default_private_class" { |
193 | -re "type = class default_private_class \{${ws}(private:${ws}|)int a;${ws}int b;$nl\}$nl$gdb_prompt $" { | |
194 | # gcc 2.95.3 -gdwarf-2 | |
195 | # gcc 3.3.2 -gdwarf-2 | |
196 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
f683e100 | 197 | pass "ptype class default_private_class" |
c906108c | 198 | } |
1cd3489f MC |
199 | -re "type = class default_private_class \{${ws}(private:${ws}|)int a;${ws}int b;${ws}public:${ws}default_private_class ?& ?operator ?=\\(default_private_class const ?&\\);${ws}default_private_class\\(default_private_class const ?&\\);${ws}default_private_class\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
200 | # gcc 2.95.3 -gstabs+ | |
201 | # gcc 3.3.2 -gstabs+ | |
202 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
f683e100 | 203 | pass "ptype class default_private_class" |
c906108c | 204 | } |
c906108c SS |
205 | } |
206 | ||
1cd3489f MC |
207 | # Same test, slightly different type. |
208 | ||
209 | gdb_test_multiple "ptype class explicit_private_class" "ptype class explicit_private_class" { | |
210 | -re "type = class explicit_private_class \{${ws}(private:${ws}|)int a;${ws}int b;$nl\}$nl$gdb_prompt $" { | |
211 | # gcc 2.95.3 -gdwarf-2 | |
212 | # gcc 3.3.2 -gdwarf-2 | |
213 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
c906108c SS |
214 | pass "ptype class explicit_private_class" |
215 | } | |
1cd3489f MC |
216 | -re "type = class explicit_private_class \{${ws}(private:${ws}|)int a;${ws}int b;${ws}public:${ws}explicit_private_class ?& ?operator ?=\\(explicit_private_class const ?&\\);${ws}explicit_private_class\\(explicit_private_class const ?&\\);${ws}explicit_private_class\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
217 | # gcc 2.95.3 -gstabs+ | |
218 | # gcc 3.3.2 -gstabs+ | |
219 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
220 | pass "ptype class explicit_private_class" | |
c906108c | 221 | } |
c906108c SS |
222 | } |
223 | ||
1cd3489f MC |
224 | # Similar test, bigger type. |
225 | ||
226 | gdb_test_multiple "ptype class mixed_protection_class" "ptype struct mixed_protection_class" { | |
227 | -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 $" { | |
228 | # gcc 2.95.3 -gdwarf-2 | |
229 | # gcc 3.3.2 -gdwarf-2 | |
230 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
c906108c SS |
231 | pass "ptype class mixed_protection_class" |
232 | } | |
1cd3489f MC |
233 | -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;${ws}public:${ws}mixed_protection_class ?& ?operator ?=\\(mixed_protection_class const ?&\\);${ws}mixed_protection_class\\(mixed_protection_class const ?&\\);${ws}mixed_protection_class\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
234 | # gcc 2.95.3 -gstabs+ | |
235 | # gcc 3.3.2 -gstabs+ | |
236 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
237 | pass "ptype class mixed_protection_class" | |
c906108c | 238 | } |
c906108c SS |
239 | } |
240 | ||
1cd3489f MC |
241 | # Here are some classes with inheritance. |
242 | ||
243 | # Base class. | |
244 | ||
245 | gdb_test_multiple "ptype class A" "ptype class A" { | |
246 | -re "type = class A \{${ws}public:${ws}int a;${ws}int x;$nl\}$nl$gdb_prompt $" { | |
247 | # gcc 2.95.3 -gdwarf-2 | |
248 | # gcc 3.3.2 -gdwarf-2 | |
249 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
c906108c SS |
250 | pass "ptype class A" |
251 | } | |
1cd3489f MC |
252 | -re "type = class A \{${ws}public:${ws}int a;${ws}int x;${ws}A ?& ?operator ?=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
253 | # gcc 2.95.3 -gstabs+ | |
254 | # gcc 3.3.2 -gstabs+ | |
255 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
256 | pass "ptype class A" | |
c906108c SS |
257 | } |
258 | } | |
259 | ||
1cd3489f MC |
260 | # Derived class. |
261 | ||
262 | gdb_test_multiple "ptype class B" "ptype class B" { | |
263 | -re "type = class B : public A \{${ws}public:${ws}int b;${ws}int x;$nl\}$nl$gdb_prompt $" { | |
264 | # gcc 2.95.3 -gdwarf-2 | |
265 | # gcc 3.3.2 -gdwarf-2 | |
266 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
9939d2a8 | 267 | pass "ptype class B" |
c906108c | 268 | } |
1cd3489f MC |
269 | -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|)\\);$nl\}$nl$gdb_prompt $" { |
270 | # gcc 2.95.3 -gstabs+ | |
271 | # gcc 3.3.2 -gstabs+ | |
272 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
273 | pass "ptype class B" | |
c906108c SS |
274 | } |
275 | } | |
276 | ||
1cd3489f MC |
277 | # Derived class. |
278 | ||
279 | gdb_test_multiple "ptype class C" "ptype class C" { | |
280 | -re "type = class C : public A \{${ws}public:${ws}int c;${ws}int x;$nl\}$nl$gdb_prompt $" { | |
281 | # gcc 2.95.3 -gdwarf-2 | |
282 | # gcc 3.3.2 -gdwarf-2 | |
283 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
9939d2a8 | 284 | pass "ptype class C" |
c906108c | 285 | } |
1cd3489f MC |
286 | -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|)\\);$nl\}$nl$gdb_prompt $" { |
287 | # gcc 2.95.3 -gstabs+ | |
288 | # gcc 3.3.2 -gstabs+ | |
289 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
290 | pass "ptype class C" | |
c906108c SS |
291 | } |
292 | } | |
293 | ||
1cd3489f MC |
294 | # Derived class, multiple inheritance. |
295 | ||
296 | gdb_test_multiple "ptype class D" "ptype class D" { | |
297 | -re "type = class D : public B, public C \{${ws}public:${ws}int d;${ws}int x;$nl\}$nl$gdb_prompt $" { | |
298 | # gcc 2.95.3 -gdwarf-2 | |
299 | # gcc 3.3.2 -gdwarf-2 | |
300 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
9939d2a8 | 301 | pass "ptype class D" |
c906108c | 302 | } |
1cd3489f MC |
303 | -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|)\\);$nl\}$nl$gdb_prompt $" { |
304 | # gcc 2.95.3 -gstabs+ | |
305 | # gcc 3.3.2 -gstabs+ | |
306 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
307 | pass "ptype class D" | |
c906108c SS |
308 | } |
309 | } | |
310 | ||
1cd3489f MC |
311 | # Derived class. |
312 | ||
313 | gdb_test_multiple "ptype class E" "ptype class E" { | |
314 | -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;$nl\}$nl$gdb_prompt $" { | |
315 | # gcc 2.95.3 -gdwarf-2 | |
316 | # gcc 3.3.2 -gdwarf-2 | |
317 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
c906108c SS |
318 | pass "ptype class E" |
319 | } | |
1cd3489f MC |
320 | -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|)\\);$nl\}$nl$gdb_prompt $" { |
321 | # gcc 2.95.3 -gstabs+ | |
322 | # gcc 3.3.2 -gstabs+ | |
323 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
c906108c SS |
324 | pass "ptype class E" |
325 | } | |
c906108c SS |
326 | } |
327 | ||
1cd3489f MC |
328 | # This is a break from inheritance tests. |
329 | # | |
330 | # gcc 2.X with stabs (stabs or stabs+?) used to have a problem with | |
331 | # static methods whose name is the same as their argument mangling. | |
332 | ||
333 | gdb_test_multiple "ptype class Static" "ptype class Static" { | |
334 | -re "type = class Static \{${ws}public:${ws}static void ii\\(int, int\\);$nl\}$nl$gdb_prompt $" { | |
335 | # gcc 2.95.3 -gdwarf-2 | |
336 | # gcc 3.3.2 -gdwarf-2 | |
337 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
af890c52 DJ |
338 | pass "ptype class Static" |
339 | } | |
1cd3489f MC |
340 | -re "type = class Static \{${ws}public:${ws}Static ?& ?operator ?=\\(Static const ?&\\);${ws}Static\\(Static const ?&\\);${ws}Static\\((void|)\\);${ws}static void ii\\(int, int\\);$nl\}$nl$gdb_prompt $" { |
341 | # gcc 2.95.3 -gstabs+ | |
342 | # gcc 3.3.2 -gstabs+ | |
3e36a0f4 DJ |
343 | pass "ptype class Static" |
344 | } | |
1cd3489f MC |
345 | -re "type = class Static \{${ws}public:${ws}static void ii\\(int, int\\);${ws}Static ?& ?operator ?=\\(Static const ?&\\);${ws}Static\\(Static const ?&\\);${ws}Static\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
346 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
8f25f06b | 347 | pass "ptype class Static" |
af890c52 DJ |
348 | } |
349 | } | |
350 | ||
1cd3489f MC |
351 | # Here are some virtual inheritance tests. |
352 | ||
353 | gdb_test_multiple "ptype class vA" "ptype class vA" { | |
354 | -re "type = class vA \{${ws}public:${ws}int va;${ws}int vx;$nl\}$nl$gdb_prompt $" { | |
355 | # gcc 2.95.3 -gdwarf-2 | |
356 | # gcc 3.3.2 -gdwarf-2 | |
357 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
3e36a0f4 DJ |
358 | pass "ptype class vA" |
359 | } | |
1cd3489f MC |
360 | -re "type = class vA \{${ws}public:${ws}int va;${ws}int vx;${ws}vA ?& ?operator ?=\\(vA const ?&\\);${ws}vA\\(vA const ?&\\);${ws}vA\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
361 | # gcc 2.95.3 -gstabs+ | |
362 | # gcc 3.3.2 -gstabs+ | |
363 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
c906108c SS |
364 | pass "ptype class vA" |
365 | } | |
c906108c SS |
366 | } |
367 | ||
184ad485 | 368 | # With gcc 2, gdb prints the virtual base pointer. |
1cd3489f | 369 | # With gcc 3, gdb does not print the virtual base pointer. |
184ad485 | 370 | # drow considers it a gdb bug if gdb prints the vbptr. |
c906108c | 371 | |
1cd3489f MC |
372 | gdb_test_multiple "ptype class vB" "ptype class vB" { |
373 | -re "type = class vB : public virtual vA \{${ws}private:${ws}vA ?\\* ?_vb.2vA;${ws}public:${ws}int vb;${ws}int vx;$nl\}$nl$gdb_prompt $" { | |
374 | # gcc 2.95.3 -gdwarf-2 | |
184ad485 MC |
375 | # TODO: kfail this |
376 | fail "ptype class vB" | |
5178b9d6 | 377 | } |
1cd3489f MC |
378 | -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;$nl\}$nl$gdb_prompt $" { |
379 | # gcc 3.3.2 -gdwarf-2 | |
380 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
381 | pass "ptype class vB" | |
c906108c | 382 | } |
1cd3489f MC |
383 | -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\\);$nl\}$nl$gdb_prompt $" { |
384 | # gcc 2.95.3 -gstabs+ | |
385 | # See the hidden "in-charge" ctor parameter! | |
184ad485 MC |
386 | # TODO: kfail this |
387 | setup_xfail "*-*-*" | |
388 | fail "ptype class vB (FIXME: non-portable virtual table constructs)" | |
c906108c | 389 | } |
1cd3489f MC |
390 | -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}vB ?& ?operator ?=\\(vB const ?&\\);${ws}vB\\(vB const ?&\\);${ws}vB\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
391 | # gcc 3.3.2 -gstabs+ | |
392 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
393 | pass "ptype class vB" | |
c906108c SS |
394 | } |
395 | } | |
396 | ||
1cd3489f | 397 | # Another class with a virtual base. |
c906108c | 398 | |
1cd3489f MC |
399 | gdb_test_multiple "ptype class vC" "ptype class vC" { |
400 | -re "type = class vC : public virtual vA \{${ws}private:${ws}vA ?\\* ?_vb.2vA;${ws}public:${ws}int vc;${ws}int vx;$nl\}$nl$gdb_prompt $" { | |
401 | # gcc 2.95.3 -gdwarf-2 | |
184ad485 MC |
402 | # TODO: kfail |
403 | fail "ptype class vC" | |
5178b9d6 | 404 | } |
1cd3489f MC |
405 | -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;$nl\}$nl$gdb_prompt $" { |
406 | # gcc 3.3.2 -gdwarf-2 | |
407 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
408 | pass "ptype class vC" | |
c906108c | 409 | } |
1cd3489f MC |
410 | -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\\);$nl\}$nl$gdb_prompt $" { |
411 | # gcc 2.95.3 -gstabs+ | |
412 | # See the hidden "in-charge" ctor parameter! | |
184ad485 MC |
413 | # TODO: kfail |
414 | setup_xfail "*-*-*" | |
415 | fail "ptype class vC (FIXME: non-portable virtual table constructs)" | |
c906108c | 416 | } |
1cd3489f MC |
417 | -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}vC ?& ?operator ?=\\(vC const ?&\\);${ws}vC\\(vC const ?&\\);${ws}vC\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
418 | # gcc 3.3.2 -gstabs+ | |
419 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
420 | pass "ptype class vC" | |
c906108c SS |
421 | } |
422 | } | |
423 | ||
1cd3489f | 424 | # The classic diamond inheritance. |
c906108c | 425 | |
1cd3489f MC |
426 | gdb_test_multiple "ptype class vD" "ptype class vD" { |
427 | -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC ?\\* ?_vb.2vC;${ws}vB ?\\* ?_vb.2vB;${ws}public:${ws}int vd;${ws}int vx;$nl\}$nl$gdb_prompt $" { | |
428 | # gcc 2.95.3 -gdwarf-2 | |
184ad485 MC |
429 | # TODO: kfail |
430 | fail "ptype class vD" | |
5178b9d6 | 431 | } |
1cd3489f MC |
432 | -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;$nl\}$nl$gdb_prompt $" { |
433 | # gcc 3.3.2 -gdwarf-2 | |
434 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
435 | pass "ptype class vD" | |
c906108c | 436 | } |
1cd3489f MC |
437 | -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\\);$nl\}$nl$gdb_prompt $" { |
438 | # gcc 2.95.3 -gstabs+ | |
439 | # See the hidden "in-charge" ctor parameter! | |
184ad485 MC |
440 | # TODO: kfail |
441 | setup_xfail "*-*-*" | |
442 | fail "ptype class vD (FIXME: non-portable virtual table constructs)" | |
c906108c | 443 | } |
1cd3489f MC |
444 | -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 ?&\\);${ws}vD\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
445 | # gcc 3.3.2 -gstabs+ | |
446 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
447 | pass "ptype class vD" | |
c906108c SS |
448 | } |
449 | } | |
450 | ||
1cd3489f | 451 | # One more case of virtual derivation. |
c906108c | 452 | |
1cd3489f MC |
453 | gdb_test_multiple "ptype class vE" "ptype class vE" { |
454 | -re "type = class vE : public virtual vD \{${ws}private:${ws}vD ?\\* ?_vb.2vD;${ws}public:${ws}int ve;${ws}int vx;$nl\}$nl$gdb_prompt $" { | |
455 | # gcc 2.95.3 -gdwarf-2 | |
184ad485 MC |
456 | # TODO: kfail |
457 | fail "ptype class vE" | |
5178b9d6 | 458 | } |
1cd3489f MC |
459 | -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;$nl\}$nl$gdb_prompt $" { |
460 | # gcc 3.3.2 -gdwarf-2 | |
461 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
462 | pass "ptype class vE" | |
c906108c | 463 | } |
1cd3489f MC |
464 | -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\\);$nl\}$nl$gdb_prompt $" { |
465 | # gcc 2.95.3 -gstabs+ | |
466 | # See the hidden "in-charge" ctor parameter! | |
184ad485 MC |
467 | # TODO: kfail |
468 | setup_xfail "*-*-*" | |
469 | fail "ptype class vE (FIXME: non-portable virtual table constructs)" | |
c906108c | 470 | } |
1cd3489f MC |
471 | -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}vE ?& ?operator ?=\\(vE const ?&\\);${ws}vE\\(vE const ?&\\);${ws}vE\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
472 | # gcc 3.3.2 -gstabs+ | |
473 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
474 | pass "ptype class vE" | |
c906108c SS |
475 | } |
476 | } | |
477 | ||
1cd3489f MC |
478 | # Another inheritance series. |
479 | ||
480 | gdb_test_multiple "ptype class Base1" "ptype class Base1" { | |
481 | -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1\\(int\\);$nl\}$nl$gdb_prompt $" { | |
482 | # gcc 2.95.3 -gdwarf-2 | |
483 | # gcc 3.3.2 -gdwarf-2 | |
484 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
c906108c SS |
485 | pass "ptype class Base1" |
486 | } | |
1cd3489f MC |
487 | -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1 ?& ?operator ?=\\(Base1 const ?&\\);${ws}Base1\\(Base1 const ?&\\);${ws}Base1\\(int\\);$nl\}$nl$gdb_prompt $" { |
488 | # gcc 2.95.3 -gstabs+ | |
489 | # gcc 3.3.2 -gstabs+ | |
3e36a0f4 DJ |
490 | pass "ptype class Base1" |
491 | } | |
1cd3489f MC |
492 | -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1\\(int\\);${ws}Base1 ?& ?operator ?=\\(Base1 const ?&\\);${ws}Base1\\(Base1 const ?&\\);$nl\}$nl$gdb_prompt $" { |
493 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
8f25f06b | 494 | pass "ptype class Base1" |
c906108c SS |
495 | } |
496 | } | |
497 | ||
1cd3489f MC |
498 | # The second base class. |
499 | ||
500 | gdb_test_multiple "ptype class Foo" "ptype class Foo" { | |
501 | -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;${ws}Foo\\(int, int\\);${ws}int operator ?!\\((void|)\\);${ws}operator int\\((void|)\\);${ws}int times\\(int\\);$nl\}$nl$gdb_prompt $" { | |
502 | # gcc 2.95.3 -gdwarf-2 | |
503 | # gcc 3.3.2 -gdwarf-2 | |
504 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
c906108c SS |
505 | pass "ptype class Foo" |
506 | } | |
1cd3489f MC |
507 | -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\\);$nl\}$nl$gdb_prompt $" { |
508 | # gcc 2.95.3 -gstabs+ | |
184ad485 | 509 | # TODO: "int operator int()" is a bug |
184ad485 | 510 | # kfail "gdb/1497" "ptype class Foo" |
9939d2a8 | 511 | pass "ptype class Foo" |
c906108c | 512 | } |
1cd3489f MC |
513 | -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\\);$nl\}$nl$gdb_prompt $" { |
514 | # gcc 3.3.2 -gstabs+ | |
515 | pass "ptype class Foo" | |
c906108c | 516 | } |
1cd3489f MC |
517 | -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;${ws}Foo\\(int, int\\);${ws}int operator ?!\\((void|)\\);${ws}operator int\\((void|)\\);${ws}int times\\(int\\);${ws}Foo ?& ?operator ?=\\(Foo const ?&\\);${ws}Foo\\(Foo const ?&\\);$nl\}$nl$gdb_prompt $" { |
518 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
8f25f06b | 519 | pass "ptype class Foo" |
c906108c SS |
520 | } |
521 | } | |
522 | ||
1cd3489f MC |
523 | # A multiple inheritance derived class. |
524 | ||
525 | gdb_test_multiple "ptype class Bar" "ptype class Bar" { | |
526 | -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;${ws}Bar\\(int, int, int\\);$nl\}$nl$gdb_prompt $" { | |
527 | # gcc 2.95.3 -gdwarf-2 | |
528 | # gcc 3.3.2 -gdwarf-2 | |
529 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
9939d2a8 | 530 | pass "ptype class Bar" |
c906108c | 531 | } |
1cd3489f MC |
532 | -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\\);$nl\}$nl$gdb_prompt $" { |
533 | # gcc 2.95.3 -gstabs+ | |
534 | # gcc 3.3.2 -gstabs+ | |
535 | pass "ptype class Bar" | |
c906108c | 536 | } |
1cd3489f MC |
537 | -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;${ws}Bar\\(int, int, int\\);${ws}Bar ?& ?operator ?=\\(Bar const ?&\\);${ws}Bar\\(Bar const ?&\\);$nl\}$nl$gdb_prompt $" { |
538 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
8f25f06b | 539 | pass "ptype class Bar" |
c906108c SS |
540 | } |
541 | } | |
542 | } | |
543 | ||
c906108c | 544 | # Test simple access to class members. |
1cd3489f MC |
545 | # TODO: these test names are gross! |
546 | # Just let the test name default. | |
c906108c SS |
547 | |
548 | proc test_non_inherited_member_access {} { | |
549 | global gdb_prompt | |
550 | ||
551 | # Print non-inherited members of g_A. | |
c906108c | 552 | gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect" |
c906108c SS |
553 | gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect" |
554 | ||
555 | # Print non-inherited members of g_B. | |
c906108c | 556 | gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect" |
c906108c SS |
557 | gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect" |
558 | ||
559 | # Print non-inherited members of g_C. | |
c906108c | 560 | gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect" |
c906108c SS |
561 | gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect" |
562 | ||
563 | # Print non-inherited members of g_D. | |
c906108c | 564 | gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect" |
c906108c SS |
565 | gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect" |
566 | ||
567 | # Print non-inherited members of g_E. | |
c906108c | 568 | gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect" |
c906108c SS |
569 | gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect" |
570 | } | |
571 | ||
1cd3489f MC |
572 | # Test access to members of other classes. |
573 | # gdb should refuse to print them. | |
574 | # (I feel old -- I remember when this was legal in C -- chastain). | |
575 | # TODO: Again, change the silly test names. | |
c906108c SS |
576 | |
577 | proc test_wrong_class_members {} { | |
578 | global gdb_prompt | |
579 | ||
580 | gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error" | |
c906108c | 581 | gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error" |
c906108c | 582 | gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error" |
c906108c | 583 | gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error" |
c906108c | 584 | gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error" |
c906108c SS |
585 | gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error" |
586 | } | |
587 | ||
1cd3489f MC |
588 | # Test access to names that are not members of any class. |
589 | # TODO: test names again. | |
c906108c | 590 | |
2bec0572 | 591 | proc test_nonexistent_members {} { |
c906108c SS |
592 | global gdb_prompt |
593 | ||
594 | gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error" | |
c906108c | 595 | gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error" |
c906108c | 596 | gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error" |
c906108c SS |
597 | gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error" |
598 | } | |
599 | ||
54602222 ND |
600 | # Call a method that expects a base class parameter with base, inherited, |
601 | # and unrelated class arguments. | |
54602222 ND |
602 | |
603 | proc test_method_param_class {} { | |
604 | gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" "base class param->a" | |
605 | gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" "base class param->x" | |
606 | gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" "inherited class param->a" | |
607 | gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" "inherited class param->x" | |
608 | gdb_test "call class_param.Aref_a (g_A)" ".* = 1" "base class (¶m)->a" | |
609 | gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (¶m)->x" | |
610 | gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (¶m)->a" | |
611 | gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (¶m)->x" | |
612 | gdb_test "call class_param.Aval_a (g_A)" ".* = 1" "base class param.a" | |
613 | gdb_test "call class_param.Aval_x (g_A)" ".* = 2" "base class param.x" | |
614 | gdb_test "call class_param.Aval_a (g_B)" ".* = 3" "inherited class param.a" | |
615 | gdb_test "call class_param.Aval_x (g_B)" ".* = 4" "inherited class param.x" | |
616 | ||
617 | gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param" | |
618 | gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class ¶m" | |
619 | gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param" | |
620 | } | |
621 | ||
2bec0572 | 622 | # Examine a class with an enum field. |
2bec0572 ND |
623 | |
624 | proc test_enums {} { | |
625 | global gdb_prompt | |
1cd3489f MC |
626 | global nl |
627 | global ws | |
2bec0572 ND |
628 | |
629 | # print the object | |
2bec0572 | 630 | |
1cd3489f MC |
631 | gdb_test "print obj_with_enum" \ |
632 | "\\$\[0-9\]+ = \{priv_enum = red, x = 0\}" \ | |
633 | "print obj_with_enum (1)" | |
634 | ||
635 | # advance one line | |
636 | ||
637 | gdb_test "next" "" | |
638 | ||
639 | # TODO: with gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2, | |
640 | # gdb says that obj_with_enum is out of scope here and the | |
641 | # tests after this FAIL. This needs investigation. | |
642 | # -- chastain 2003-12-30 | |
2bec0572 ND |
643 | |
644 | # print the object again | |
2bec0572 | 645 | |
1cd3489f MC |
646 | gdb_test "print obj_with_enum" \ |
647 | "\\$\[0-9\]+ = \{priv_enum = green, x = 0\}" \ | |
648 | "print obj_with_enum (2)" | |
649 | ||
650 | # print the enum member | |
651 | ||
652 | gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = green" | |
2bec0572 ND |
653 | |
654 | # ptype on the enum member | |
1cd3489f MC |
655 | |
656 | gdb_test_multiple "ptype obj_with_enum.priv_enum" "ptype obj_with_enum.priv_enum" { | |
657 | -re "type = enum ClassWithEnum::PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" { | |
658 | pass "ptype obj_with_enum.priv_enum" | |
659 | } | |
660 | -re "type = enum PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" { | |
661 | # gcc 2.95.3 -gdwarf-2 | |
662 | # gcc 3.3.2 -gdwarf-2 | |
663 | pass "ptype obj_with_enum.priv_enum" | |
664 | } | |
665 | -re "type = enum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" { | |
666 | # This case case is a little dubious, but it's not clear what | |
667 | # ought to be required of a ptype on a private enum... | |
668 | # -sts 19990324 | |
669 | # | |
670 | # It bugs me that this happens with gcc 3. | |
671 | # -- chastain 2003-12-30 | |
672 | # | |
673 | # gcc 2.95.3 -gstabs+ | |
674 | # gcc 3.3.2 -gstabs+ | |
675 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
676 | pass "ptype obj_with_enum.priv_enum" | |
677 | } | |
2bec0572 ND |
678 | } |
679 | ||
680 | # ptype on the object | |
1cd3489f MC |
681 | gdb_test_multiple "ptype obj_with_enum" "ptype obj_with_enum" { |
682 | -re "type = class ClassWithEnum \{${ws}public:${ws}(enum |)ClassWithEnum::PrivEnum priv_enum;${ws}int x;$nl\}$nl$gdb_prompt $" { | |
683 | pass "ptype obj_with_enum" | |
684 | } | |
685 | -re "type = class ClassWithEnum \{${ws}public:${ws}(enum |)PrivEnum priv_enum;${ws}int x;$nl\}$nl$gdb_prompt $" { | |
6ece72da DC |
686 | # NOTE: carlton/2003-02-28: One could certainly argue that |
687 | # this output is acceptable: PrivEnum is a member of | |
688 | # ClassWithEnum, so there's no need to explicitly qualify | |
689 | # its name with "ClassWithEnum::". The truth, though, is | |
690 | # that GDB is simply forgetting that PrivEnum is a member | |
691 | # of ClassWithEnum, so we do that output for a bad reason | |
692 | # instead of a good reason. Under stabs, we probably | |
693 | # can't get this right; under DWARF-2, we can. | |
1cd3489f MC |
694 | # |
695 | # gcc 2.95.3 -gdwarf-2 | |
696 | # gcc 3.3.2 -gdwarf-2 | |
697 | kfail "gdb/57" "ptype obj_with_enum" | |
698 | } | |
699 | -re "type = class ClassWithEnum \{${ws}public:${ws}(enum |)PrivEnum priv_enum;${ws}int x;${ws}ClassWithEnum ?& ?operator ?=\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\((void|)\\);$nl\}$nl$gdb_prompt $" { | |
700 | # gcc 2.95.3 -gstabs+ | |
6ece72da DC |
701 | kfail "gdb/57" "ptype obj_with_enum" |
702 | } | |
1cd3489f MC |
703 | -re "type = class ClassWithEnum \{${ws}public:${ws}(enum |)ClassWithEnum::PrivEnum priv_enum;${ws}int x;${ws}ClassWithEnum ?& ?operator ?=\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\((void|)\\);$nl\}$nl$gdb_prompt $" { |
704 | # I think this is a PASS, but only carlton knows for sure. | |
705 | # -- chastain 2003-12-30 | |
706 | # | |
707 | # gcc 3.3.2 -gstabs+ | |
708 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
184ad485 | 709 | fail "ptype obj_with_enum" |
1cd3489f | 710 | } |
2bec0572 ND |
711 | } |
712 | ||
1cd3489f MC |
713 | # I'll do this test two different ways, because of a parser bug. |
714 | # See PR gdb/826. | |
6ece72da | 715 | |
1cd3489f MC |
716 | gdb_test_multiple "print (ClassWithEnum::PrivEnum) 42" "print (ClassWithEnum::PrivEnum) 42" { |
717 | -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" { | |
718 | pass "print (ClassWithEnum::PrivEnum) 42" | |
d8a2d9e7 | 719 | } |
1cd3489f MC |
720 | -re "A (parse|syntax) error in expression, near `42'.$nl$gdb_prompt $" { |
721 | # "parse error" is bison 1.35. | |
722 | # "syntax error" is bison 1.875. | |
d8a2d9e7 MC |
723 | kfail "gdb/826" "print (ClassWithEnum::PrivEnum) 42" |
724 | } | |
2bec0572 | 725 | } |
6ece72da | 726 | |
1cd3489f MC |
727 | gdb_test_multiple "print ('ClassWithEnum::PrivEnum') 42" "print ('ClassWithEnum::PrivEnum') 42" { |
728 | -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" { | |
729 | # gcc 3.3.2 -gstabs+ | |
730 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
731 | pass "print ('ClassWithEnum::PrivEnum') 42" | |
732 | } | |
733 | -re "No symbol \"ClassWithEnum::PrivEnum\" in current context.$nl$gdb_prompt $" { | |
734 | # gcc 2.95.3 -gdwarf-2 | |
735 | # gcc 3.3.2 -gdwarf-2 | |
736 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
737 | # gcc 2.95.3 -gstabs+ | |
738 | kfail "gdb/57" "print ('ClassWithEnum::PrivEnum') 42" | |
739 | } | |
6ece72da | 740 | } |
2bec0572 ND |
741 | } |
742 | ||
c906108c | 743 | # Pointers to class members |
c906108c SS |
744 | |
745 | proc test_pointers_to_class_members {} { | |
746 | global gdb_prompt | |
c906108c | 747 | |
1cd3489f MC |
748 | gdb_test "print Bar::z" "\\$\[0-9\]+ = \\(int ?\\( ?Bar::& ?\\) ?\\) ?Bar::z" |
749 | gdb_test "print &Foo::x" "\\$\[0-9\]+ = \\(int ?\\( ?Foo::\\* ?\\) ?\\) ?&Foo::x" | |
750 | gdb_test "print (int)&Foo::x" "\\$\[0-9\]+ = 0" | |
751 | gdb_test "print (int)&Bar::y == 2*sizeof(int)" "\\$\[0-9\]+ = true" | |
184ad485 MC |
752 | |
753 | # TODO: this is a bogus test. It's looking at a variable that | |
754 | # has not even been declared yet, so it's accessing random junk | |
755 | # on the stack and comparing that it's NOT equal to a specific | |
756 | # value. It's been like this since gdb 4.10 in 1993! | |
757 | # -- chastain 2004-01-01 | |
758 | gdb_test "print (int)pmi == sizeof(int)" ".* = false" | |
c906108c SS |
759 | } |
760 | ||
c906108c | 761 | # Test static members. |
c906108c SS |
762 | |
763 | proc test_static_members {} { | |
764 | global gdb_prompt | |
765 | global hex | |
c906108c | 766 | |
1cd3489f | 767 | gdb_test "print Foo::st" "\\$\[0-9\]+ = 100" |
184ad485 | 768 | gdb_test "set foo.st = 200" "" "" |
1cd3489f MC |
769 | gdb_test "print bar.st" "\\$\[0-9\]+ = 200" |
770 | gdb_test "print &foo.st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex" | |
771 | gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex" | |
772 | gdb_test "print *\$" "\\$\[0-9\]+ = 200" | |
c906108c SS |
773 | |
774 | gdb_test "set print static-members off" "" | |
775 | gdb_test "print csi" \ | |
776 | "{x = 10, y = 20}" \ | |
777 | "print csi without static members" | |
778 | gdb_test "print cnsi" \ | |
779 | "{x = 30, y = 40}" \ | |
780 | "print cnsi without static members" | |
781 | ||
782 | gdb_test "set print static-members on" "" | |
c906108c SS |
783 | gdb_test "print csi" \ |
784 | "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \ | |
785 | "print csi with static members" | |
c906108c SS |
786 | gdb_test "print cnsi" \ |
787 | "{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>}" \ | |
788 | "print cnsi with static members" | |
789 | } | |
790 | ||
791 | proc do_tests {} { | |
792 | global prms_id | |
793 | global bug_id | |
794 | global subdir | |
795 | global objdir | |
796 | global srcdir | |
797 | global binfile | |
798 | global gdb_prompt | |
1cd3489f | 799 | global nl |
c906108c SS |
800 | |
801 | set prms_id 0 | |
802 | set bug_id 0 | |
803 | ||
804 | # Start with a fresh gdb. | |
805 | ||
806 | gdb_exit | |
807 | gdb_start | |
808 | gdb_reinitialize_dir $srcdir/$subdir | |
809 | gdb_load $binfile | |
810 | ||
1cd3489f MC |
811 | gdb_test "set language c++" "" "" |
812 | gdb_test "set width 0" "" "" | |
c906108c | 813 | |
1cd3489f MC |
814 | if ![runto_main ] then { |
815 | perror "couldn't run to breakpoint" | |
816 | return | |
2bec0572 ND |
817 | } |
818 | ||
1cd3489f MC |
819 | gdb_breakpoint inheritance2 |
820 | gdb_test "continue" ".*Breakpoint .* inheritance2.*" "" | |
c906108c | 821 | |
1cd3489f MC |
822 | test_ptype_class_objects |
823 | test_non_inherited_member_access | |
824 | test_wrong_class_members | |
825 | test_nonexistent_members | |
826 | test_method_param_class | |
c906108c | 827 | |
1cd3489f | 828 | gdb_breakpoint enums2 |
184ad485 | 829 | gdb_test "continue" ".*Breakpoint .* enums2.*" "continue to enums2(\\(\\)|)" |
1cd3489f MC |
830 | gdb_test "finish" "" "" |
831 | test_enums | |
832 | ||
184ad485 MC |
833 | gdb_test "finish" "" "" |
834 | test_pointers_to_class_members | |
835 | test_static_members | |
836 | ||
1cd3489f MC |
837 | # Now some random tests that were just thrown in here. |
838 | ||
839 | gdb_breakpoint marker_reg1 | |
840 | gdb_test "continue" ".*Breakpoint .* marker_reg1.*" "" | |
841 | gdb_test "finish" "Run till exit from.*" "finish from marker_reg1" | |
842 | ||
843 | # This class is so small that an instance of it can fit in a register. | |
844 | # When gdb tries to call a method, it gets embarrassed about taking | |
845 | # the address of a register. | |
846 | # | |
847 | # TODO: I think that message should be a PASS, not an XFAIL. | |
848 | # gdb prints an informative message and declines to do something | |
849 | # impossible. | |
850 | # | |
851 | # The method call actually succeeds if the compiler allocates very | |
852 | # small classes in memory instead of registers. So this test does | |
853 | # not tell us anything interesting if the call succeeds. | |
854 | # | |
855 | # -- chastain 2003-12-31 | |
856 | gdb_test_multiple "print v.method ()" "calling method for small class" { | |
857 | -re "\\$\[0-9\]+ = 82$nl$gdb_prompt $" { | |
858 | # gcc 3.3.2 -gdwarf-2 | |
859 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
860 | # gcc 3.3.2 -gstabs+ | |
861 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
862 | pass "calling method for small class" | |
863 | } | |
864 | -re "Address requested for identifier \"v\" which is in register .*$nl$gdb_prompt $" { | |
865 | # gcc 2.95.3 -gdwarf-2 | |
866 | # gcc 2.95.3 -gstabs+ | |
867 | setup_xfail "*-*-*" 2972 | |
868 | fail "calling method for small class" | |
c906108c SS |
869 | } |
870 | } | |
184ad485 MC |
871 | |
872 | # This is a random v2 demangling test. | |
873 | # This is redundant with existing tests in demangle.exp. | |
874 | # TODO: Just remove this. | |
875 | gdb_test "maint demangle inheritance1__Fv" "inheritance1\\(void\\)" "demangle" | |
c906108c SS |
876 | } |
877 | ||
878 | do_tests |