]>
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 | ||
c906108c | 18 | # This file was written by Fred Fish. (fnf@cygnus.com) |
1cd3489f | 19 | # And rewritten by Michael Chastain <mec.gnu@mindspring.com>. |
c906108c | 20 | |
c906108c SS |
21 | set nl "\[\r\n\]+" |
22 | ||
23 | if $tracelevel then { | |
1cd3489f | 24 | strace $tracelevel |
c906108c SS |
25 | } |
26 | ||
d4f3574e | 27 | if { [skip_cplus_tests] } { continue } |
c906108c | 28 | |
2d3a7986 MC |
29 | load_lib "cp-support.exp" |
30 | ||
ed69573c | 31 | set testfile "classes" |
c906108c SS |
32 | set srcfile ${testfile}.cc |
33 | set binfile ${objdir}/${subdir}/${testfile} | |
34 | ||
c906108c | 35 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { |
b60f0898 JB |
36 | untested classes.exp |
37 | return -1 | |
c906108c SS |
38 | } |
39 | ||
c906108c | 40 | # Test ptype of class objects. |
c906108c SS |
41 | |
42 | proc test_ptype_class_objects {} { | |
c906108c | 43 | |
1cd3489f | 44 | # Simple type. |
c906108c | 45 | |
2d3a7986 MC |
46 | cp_test_ptype_class \ |
47 | "ptype struct default_public_struct" "" "struct" "default_public_struct" \ | |
48 | { | |
49 | { field public "int a;" } | |
50 | { field public "int b;" } | |
c906108c | 51 | } |
c906108c | 52 | |
2d3a7986 | 53 | # Another simple type. |
c906108c | 54 | |
2d3a7986 MC |
55 | cp_test_ptype_class \ |
56 | "ptype struct explicit_public_struct" "" "struct" "explicit_public_struct" \ | |
57 | { | |
58 | { field public "int a;" } | |
59 | { field public "int b;" } | |
c906108c | 60 | } |
c906108c | 61 | |
2d3a7986 | 62 | # Another simple type. |
2fc1f950 | 63 | |
2d3a7986 MC |
64 | cp_test_ptype_class \ |
65 | "ptype struct protected_struct" "" "struct" "protected_struct" \ | |
66 | { | |
67 | { field protected "int a;" } | |
68 | { field protected "int b;" } | |
c906108c | 69 | } |
c906108c | 70 | |
2d3a7986 | 71 | # Another simple type. |
2fc1f950 | 72 | |
2d3a7986 MC |
73 | cp_test_ptype_class \ |
74 | "ptype struct private_struct" "" "struct" "private_struct" \ | |
75 | { | |
76 | { field private "int a;" } | |
77 | { field private "int b;" } | |
c906108c | 78 | } |
c906108c | 79 | |
2d3a7986 | 80 | # A bigger type. |
2fc1f950 | 81 | |
2d3a7986 MC |
82 | cp_test_ptype_class \ |
83 | "ptype struct mixed_protection_struct" "" "struct" "mixed_protection_struct" \ | |
84 | { | |
85 | { field public "int a;" } | |
86 | { field public "int b;" } | |
87 | { field private "int c;" } | |
88 | { field private "int d;" } | |
89 | { field protected "int e;" } | |
90 | { field protected "int f;" } | |
91 | { field public "int g;" } | |
92 | { field private "int h;" } | |
93 | { field protected "int i;" } | |
c906108c | 94 | } |
c906108c | 95 | |
1cd3489f MC |
96 | # All that again with "class" instead of "struct". |
97 | # gdb does not care about the difference anyways. | |
c906108c | 98 | |
2d3a7986 MC |
99 | cp_test_ptype_class \ |
100 | "ptype class public_class" "" "class" "public_class" \ | |
101 | { | |
102 | { field public "int a;" } | |
103 | { field public "int b;" } | |
c906108c | 104 | } |
1cd3489f | 105 | |
2d3a7986 | 106 | # Another simple type. |
2fc1f950 | 107 | |
2d3a7986 MC |
108 | cp_test_ptype_class \ |
109 | "ptype class protected_class" "" "class" "protected_class" \ | |
110 | { | |
111 | { field protected "int a;" } | |
112 | { field protected "int b;" } | |
c906108c | 113 | } |
c906108c | 114 | |
2d3a7986 | 115 | # Another simple type. |
2fc1f950 | 116 | |
2d3a7986 MC |
117 | cp_test_ptype_class \ |
118 | "ptype class default_private_class" "" "class" "default_private_class" \ | |
119 | { | |
120 | { field private "int a;" } | |
121 | { field private "int b;" } | |
c906108c | 122 | } |
1cd3489f | 123 | |
2d3a7986 | 124 | # Another simple type. |
2fc1f950 | 125 | |
2d3a7986 MC |
126 | cp_test_ptype_class \ |
127 | "ptype class explicit_private_class" "" "class" "explicit_private_class" \ | |
128 | { | |
129 | { field private "int a;" } | |
130 | { field private "int b;" } | |
c906108c | 131 | } |
c906108c | 132 | |
2d3a7986 | 133 | # A bigger type. |
1cd3489f | 134 | |
2d3a7986 MC |
135 | cp_test_ptype_class \ |
136 | "ptype class mixed_protection_class" "" "class" "mixed_protection_class" \ | |
137 | { | |
2fc1f950 | 138 | |
2d3a7986 MC |
139 | { field public "int a;" } |
140 | { field public "int b;" } | |
141 | { field private "int c;" } | |
142 | { field private "int d;" } | |
143 | { field protected "int e;" } | |
144 | { field protected "int f;" } | |
145 | { field public "int g;" } | |
146 | { field private "int h;" } | |
147 | { field protected "int i;" } | |
c906108c | 148 | } |
c906108c | 149 | |
1cd3489f MC |
150 | # Here are some classes with inheritance. |
151 | ||
152 | # Base class. | |
153 | ||
2d3a7986 MC |
154 | cp_test_ptype_class \ |
155 | "ptype class A" "" "class" "A" \ | |
156 | { | |
157 | { field public "int a;" } | |
158 | { field public "int x;" } | |
c906108c | 159 | } |
c906108c | 160 | |
1cd3489f MC |
161 | # Derived class. |
162 | ||
2d3a7986 MC |
163 | cp_test_ptype_class \ |
164 | "ptype class B" "" "class" "B" \ | |
165 | { | |
166 | { base "public A" } | |
167 | { field public "int b;" } | |
168 | { field public "int x;" } | |
c906108c | 169 | } |
c906108c | 170 | |
1cd3489f MC |
171 | # Derived class. |
172 | ||
2d3a7986 MC |
173 | cp_test_ptype_class \ |
174 | "ptype class C" "" "class" "C" \ | |
175 | { | |
176 | { base "public A" } | |
177 | { field public "int c;" } | |
178 | { field public "int x;" } | |
c906108c | 179 | } |
c906108c | 180 | |
1cd3489f MC |
181 | # Derived class, multiple inheritance. |
182 | ||
2d3a7986 MC |
183 | cp_test_ptype_class \ |
184 | "ptype class D" "" "class" "D" \ | |
185 | { | |
186 | { base "public B" } | |
187 | { base "public C" } | |
188 | { field public "int d;" } | |
189 | { field public "int x;" } | |
c906108c | 190 | } |
c906108c | 191 | |
1cd3489f MC |
192 | # Derived class. |
193 | ||
2d3a7986 MC |
194 | cp_test_ptype_class \ |
195 | "ptype class E" "" "class" "E" \ | |
196 | { | |
197 | { base "public D" } | |
198 | { field public "int e;" } | |
199 | { field public "int x;" } | |
c906108c | 200 | } |
c906108c | 201 | |
1cd3489f MC |
202 | # This is a break from inheritance tests. |
203 | # | |
204 | # gcc 2.X with stabs (stabs or stabs+?) used to have a problem with | |
205 | # static methods whose name is the same as their argument mangling. | |
206 | ||
2d3a7986 MC |
207 | cp_test_ptype_class \ |
208 | "ptype class Static" "" "class" "Static" \ | |
209 | { | |
210 | { method public "static void ii(int, int);" } | |
3e36a0f4 | 211 | } |
af890c52 | 212 | |
1cd3489f MC |
213 | # Here are some virtual inheritance tests. |
214 | ||
2d3a7986 | 215 | # A virtual base class. |
2fc1f950 | 216 | |
2d3a7986 MC |
217 | cp_test_ptype_class \ |
218 | "ptype class vA" "" "class" "vA" \ | |
219 | { | |
220 | { field public "int va;" } | |
221 | { field public "int vx;" } | |
c906108c | 222 | } |
c906108c | 223 | |
2d3a7986 | 224 | # A derived class with a virtual base. |
2fc1f950 | 225 | |
2d3a7986 MC |
226 | cp_test_ptype_class \ |
227 | "ptype class vB" "" "class" "vB" \ | |
228 | { | |
229 | { base "public virtual vA" } | |
230 | { vbase "vA" } | |
231 | { field public "int vb;" } | |
232 | { field public "int vx;" } | |
2fc1f950 | 233 | } |
c906108c | 234 | |
2d3a7986 | 235 | # Another derived class with a virtual base. |
c906108c | 236 | |
2d3a7986 MC |
237 | cp_test_ptype_class \ |
238 | "ptype class vC" "" "class" "vC" \ | |
239 | { | |
240 | { base "public virtual vA" } | |
241 | { vbase "vA" } | |
242 | { field public "int vc;" } | |
243 | { field public "int vx;" } | |
c906108c | 244 | } |
c906108c | 245 | |
2d3a7986 | 246 | # A classic diamond class. |
2fc1f950 | 247 | |
2d3a7986 MC |
248 | cp_test_ptype_class \ |
249 | "ptype class vD" "" "class" "vD" \ | |
250 | { | |
251 | { base "public virtual vB" } | |
252 | { base "public virtual vC" } | |
253 | { vbase "vC" } | |
254 | { vbase "vB" } | |
255 | { field public "int vd;" } | |
256 | { field public "int vx;" } | |
c906108c | 257 | } |
c906108c | 258 | |
2d3a7986 | 259 | # A class derived from a diamond class. |
c906108c | 260 | |
2d3a7986 MC |
261 | cp_test_ptype_class \ |
262 | "ptype class vE" "" "class" "vE" \ | |
263 | { | |
264 | { base "public virtual vD" } | |
265 | { vbase "vD" } | |
266 | { field public "int ve;" } | |
267 | { field public "int vx;" } | |
5178b9d6 | 268 | } |
c906108c | 269 | |
1cd3489f MC |
270 | # Another inheritance series. |
271 | ||
2d3a7986 MC |
272 | # A base class. |
273 | ||
274 | cp_test_ptype_class \ | |
275 | "ptype class Base1" "" "class" "Base1" \ | |
276 | { | |
277 | { field public "int x;" } | |
278 | { method public "Base1(int);" } | |
279 | } | |
280 | ||
281 | # Another base class. | |
282 | ||
283 | cp_test_ptype_class \ | |
284 | "ptype class Foo" "" "class" "Foo" \ | |
285 | { | |
286 | { field public "int x;" } | |
287 | { field public "int y;" } | |
288 | { field public "static int st;" } | |
289 | { method public "Foo(int, int);" } | |
290 | { method public "int operator!();" } | |
291 | { method public "operator int();" } | |
292 | { method public "int times(int);" } | |
293 | } \ | |
294 | "" \ | |
295 | { | |
296 | { | |
297 | "operator int();" | |
298 | "int operator int();" | |
299 | { setup_kfail "gdb/1497" "*-*-*" } | |
300 | } | |
301 | { | |
302 | "operator int();" | |
303 | "int operator int(void);" | |
304 | { setup_kfail "gdb/1497" "*-*-*" } | |
305 | } | |
3e36a0f4 | 306 | } |
c906108c | 307 | |
1cd3489f MC |
308 | # A multiple inheritance derived class. |
309 | ||
2d3a7986 MC |
310 | cp_test_ptype_class \ |
311 | "ptype class Bar" "" "class" "Bar" \ | |
312 | { | |
313 | { base "public Base1" } | |
314 | { base "public Foo" } | |
315 | { field public "int z;" } | |
316 | { method public "Bar(int, int, int);" } | |
c906108c | 317 | } |
2d3a7986 | 318 | |
c906108c SS |
319 | } |
320 | ||
c906108c | 321 | # Test simple access to class members. |
c906108c SS |
322 | |
323 | proc test_non_inherited_member_access {} { | |
c906108c SS |
324 | |
325 | # Print non-inherited members of g_A. | |
226a8d71 MC |
326 | gdb_test "print g_A.a" ".* = 1" |
327 | gdb_test "print g_A.x" ".* = 2" | |
c906108c SS |
328 | |
329 | # Print non-inherited members of g_B. | |
226a8d71 MC |
330 | gdb_test "print g_B.b" ".* = 5" |
331 | gdb_test "print g_B.x" ".* = 6" | |
c906108c SS |
332 | |
333 | # Print non-inherited members of g_C. | |
226a8d71 MC |
334 | gdb_test "print g_C.c" ".* = 9" |
335 | gdb_test "print g_C.x" ".* = 10" | |
c906108c SS |
336 | |
337 | # Print non-inherited members of g_D. | |
226a8d71 MC |
338 | gdb_test "print g_D.d" ".* = 19" |
339 | gdb_test "print g_D.x" ".* = 20" | |
c906108c SS |
340 | |
341 | # Print non-inherited members of g_E. | |
226a8d71 MC |
342 | gdb_test "print g_E.e" ".* = 31" |
343 | gdb_test "print g_E.x" ".* = 32" | |
c906108c SS |
344 | } |
345 | ||
1cd3489f MC |
346 | # Test access to members of other classes. |
347 | # gdb should refuse to print them. | |
348 | # (I feel old -- I remember when this was legal in C -- chastain). | |
c906108c SS |
349 | |
350 | proc test_wrong_class_members {} { | |
226a8d71 MC |
351 | gdb_test "print g_A.b" "There is no member( or method|) named b." |
352 | gdb_test "print g_B.c" "There is no member( or method|) named c." | |
353 | gdb_test "print g_B.d" "There is no member( or method|) named d." | |
354 | gdb_test "print g_C.b" "There is no member( or method|) named b." | |
355 | gdb_test "print g_C.d" "There is no member( or method|) named d." | |
356 | gdb_test "print g_D.e" "There is no member( or method|) named e." | |
c906108c SS |
357 | } |
358 | ||
1cd3489f | 359 | # Test access to names that are not members of any class. |
c906108c | 360 | |
2bec0572 | 361 | proc test_nonexistent_members {} { |
226a8d71 MC |
362 | gdb_test "print g_A.y" "There is no member( or method|) named y." |
363 | gdb_test "print g_B.z" "There is no member( or method|) named z." | |
364 | gdb_test "print g_C.q" "There is no member( or method|) named q." | |
365 | gdb_test "print g_D.p" "There is no member( or method|) named p." | |
c906108c SS |
366 | } |
367 | ||
54602222 ND |
368 | # Call a method that expects a base class parameter with base, inherited, |
369 | # and unrelated class arguments. | |
54602222 ND |
370 | |
371 | proc test_method_param_class {} { | |
226a8d71 MC |
372 | gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" |
373 | gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" | |
374 | gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" | |
375 | gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" | |
376 | gdb_test "call class_param.Aref_a (g_A)" ".* = 1" | |
377 | gdb_test "call class_param.Aref_x (g_A)" ".* = 2" | |
378 | gdb_test "call class_param.Aref_a (g_B)" ".* = 3" | |
379 | gdb_test "call class_param.Aref_x (g_B)" ".* = 4" | |
380 | gdb_test "call class_param.Aval_a (g_A)" ".* = 1" | |
381 | gdb_test "call class_param.Aval_x (g_A)" ".* = 2" | |
382 | gdb_test "call class_param.Aval_a (g_B)" ".* = 3" | |
383 | gdb_test "call class_param.Aval_x (g_B)" ".* = 4" | |
54602222 ND |
384 | |
385 | gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param" | |
386 | gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class ¶m" | |
387 | gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param" | |
388 | } | |
389 | ||
2bec0572 | 390 | # Examine a class with an enum field. |
2bec0572 ND |
391 | |
392 | proc test_enums {} { | |
393 | global gdb_prompt | |
1cd3489f | 394 | global nl |
2bec0572 ND |
395 | |
396 | # print the object | |
2bec0572 | 397 | |
1cd3489f MC |
398 | gdb_test "print obj_with_enum" \ |
399 | "\\$\[0-9\]+ = \{priv_enum = red, x = 0\}" \ | |
400 | "print obj_with_enum (1)" | |
401 | ||
402 | # advance one line | |
403 | ||
404 | gdb_test "next" "" | |
405 | ||
2bec0572 | 406 | # print the object again |
2bec0572 | 407 | |
1cd3489f MC |
408 | gdb_test "print obj_with_enum" \ |
409 | "\\$\[0-9\]+ = \{priv_enum = green, x = 0\}" \ | |
410 | "print obj_with_enum (2)" | |
411 | ||
412 | # print the enum member | |
413 | ||
414 | gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = green" | |
2bec0572 ND |
415 | |
416 | # ptype on the enum member | |
1cd3489f MC |
417 | |
418 | gdb_test_multiple "ptype obj_with_enum.priv_enum" "ptype obj_with_enum.priv_enum" { | |
419 | -re "type = enum ClassWithEnum::PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" { | |
420 | pass "ptype obj_with_enum.priv_enum" | |
421 | } | |
422 | -re "type = enum PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" { | |
423 | # gcc 2.95.3 -gdwarf-2 | |
424 | # gcc 3.3.2 -gdwarf-2 | |
425 | pass "ptype obj_with_enum.priv_enum" | |
426 | } | |
427 | -re "type = enum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" { | |
428 | # This case case is a little dubious, but it's not clear what | |
429 | # ought to be required of a ptype on a private enum... | |
430 | # -sts 19990324 | |
431 | # | |
432 | # It bugs me that this happens with gcc 3. | |
433 | # -- chastain 2003-12-30 | |
434 | # | |
435 | # gcc 2.95.3 -gstabs+ | |
436 | # gcc 3.3.2 -gstabs+ | |
437 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
438 | pass "ptype obj_with_enum.priv_enum" | |
439 | } | |
2bec0572 ND |
440 | } |
441 | ||
442 | # ptype on the object | |
2fc1f950 | 443 | |
2d3a7986 MC |
444 | # NOTE: carlton/2003-02-28: One could certainly argue that plain |
445 | # "PrivEnum" | |
446 | # is acceptable: PrivEnum is a member of ClassWithEnum, so | |
447 | # there's no need to explicitly qualify its name with | |
448 | # "ClassWithEnum::". The truth, though, is that GDB is simply | |
449 | # forgetting that PrivEnum is a member of ClassWithEnum, so we do | |
450 | # that output for a bad reason instead of a good reason. Under | |
451 | # stabs, we probably can't get this right; under DWARF-2, we can. | |
452 | ||
453 | cp_test_ptype_class \ | |
454 | "ptype obj_with_enum" "" "class" "ClassWithEnum" \ | |
455 | { | |
456 | { field public "ClassWithEnum::PrivEnum priv_enum;" } | |
457 | { field public "int x;" } | |
458 | } \ | |
459 | "" \ | |
460 | { | |
461 | { | |
462 | "ClassWithEnum::PrivEnum priv_enum;" | |
463 | "PrivEnum priv_enum;" | |
464 | { setup_kfail "gdb/57" "*-*-*" } | |
465 | } | |
1cd3489f | 466 | } |
2bec0572 | 467 | |
1cd3489f | 468 | # I'll do this test two different ways, because of a parser bug. |
23c73aa3 | 469 | # See PR gdb/1588. |
6ece72da | 470 | |
1cd3489f MC |
471 | gdb_test_multiple "print (ClassWithEnum::PrivEnum) 42" "print (ClassWithEnum::PrivEnum) 42" { |
472 | -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" { | |
473 | pass "print (ClassWithEnum::PrivEnum) 42" | |
d8a2d9e7 | 474 | } |
1cd3489f MC |
475 | -re "A (parse|syntax) error in expression, near `42'.$nl$gdb_prompt $" { |
476 | # "parse error" is bison 1.35. | |
477 | # "syntax error" is bison 1.875. | |
23c73aa3 | 478 | kfail "gdb/1588" "print (ClassWithEnum::PrivEnum) 42" |
d8a2d9e7 | 479 | } |
2bec0572 | 480 | } |
6ece72da | 481 | |
1cd3489f MC |
482 | gdb_test_multiple "print ('ClassWithEnum::PrivEnum') 42" "print ('ClassWithEnum::PrivEnum') 42" { |
483 | -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" { | |
484 | # gcc 3.3.2 -gstabs+ | |
485 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
486 | pass "print ('ClassWithEnum::PrivEnum') 42" | |
487 | } | |
488 | -re "No symbol \"ClassWithEnum::PrivEnum\" in current context.$nl$gdb_prompt $" { | |
489 | # gcc 2.95.3 -gdwarf-2 | |
490 | # gcc 3.3.2 -gdwarf-2 | |
491 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
492 | # gcc 2.95.3 -gstabs+ | |
493 | kfail "gdb/57" "print ('ClassWithEnum::PrivEnum') 42" | |
494 | } | |
6ece72da | 495 | } |
2bec0572 ND |
496 | } |
497 | ||
c906108c | 498 | # Pointers to class members |
c906108c SS |
499 | |
500 | proc test_pointers_to_class_members {} { | |
1cd3489f MC |
501 | gdb_test "print Bar::z" "\\$\[0-9\]+ = \\(int ?\\( ?Bar::& ?\\) ?\\) ?Bar::z" |
502 | gdb_test "print &Foo::x" "\\$\[0-9\]+ = \\(int ?\\( ?Foo::\\* ?\\) ?\\) ?&Foo::x" | |
503 | gdb_test "print (int)&Foo::x" "\\$\[0-9\]+ = 0" | |
504 | gdb_test "print (int)&Bar::y == 2*sizeof(int)" "\\$\[0-9\]+ = true" | |
184ad485 MC |
505 | |
506 | # TODO: this is a bogus test. It's looking at a variable that | |
507 | # has not even been declared yet, so it's accessing random junk | |
508 | # on the stack and comparing that it's NOT equal to a specific | |
509 | # value. It's been like this since gdb 4.10 in 1993! | |
510 | # -- chastain 2004-01-01 | |
511 | gdb_test "print (int)pmi == sizeof(int)" ".* = false" | |
c906108c SS |
512 | } |
513 | ||
c906108c | 514 | # Test static members. |
c906108c SS |
515 | |
516 | proc test_static_members {} { | |
c906108c | 517 | global hex |
c906108c | 518 | |
1cd3489f | 519 | gdb_test "print Foo::st" "\\$\[0-9\]+ = 100" |
184ad485 | 520 | gdb_test "set foo.st = 200" "" "" |
1cd3489f MC |
521 | gdb_test "print bar.st" "\\$\[0-9\]+ = 200" |
522 | gdb_test "print &foo.st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex" | |
523 | gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex" | |
524 | gdb_test "print *\$" "\\$\[0-9\]+ = 200" | |
c906108c SS |
525 | |
526 | gdb_test "set print static-members off" "" | |
527 | gdb_test "print csi" \ | |
528 | "{x = 10, y = 20}" \ | |
529 | "print csi without static members" | |
530 | gdb_test "print cnsi" \ | |
531 | "{x = 30, y = 40}" \ | |
532 | "print cnsi without static members" | |
533 | ||
534 | gdb_test "set print static-members on" "" | |
c906108c SS |
535 | gdb_test "print csi" \ |
536 | "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \ | |
537 | "print csi with static members" | |
c906108c SS |
538 | gdb_test "print cnsi" \ |
539 | "{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>}" \ | |
540 | "print cnsi with static members" | |
541 | } | |
542 | ||
543 | proc do_tests {} { | |
544 | global prms_id | |
545 | global bug_id | |
546 | global subdir | |
547 | global objdir | |
548 | global srcdir | |
549 | global binfile | |
550 | global gdb_prompt | |
1cd3489f | 551 | global nl |
c906108c SS |
552 | |
553 | set prms_id 0 | |
554 | set bug_id 0 | |
555 | ||
556 | # Start with a fresh gdb. | |
557 | ||
558 | gdb_exit | |
559 | gdb_start | |
560 | gdb_reinitialize_dir $srcdir/$subdir | |
561 | gdb_load $binfile | |
562 | ||
1cd3489f MC |
563 | gdb_test "set language c++" "" "" |
564 | gdb_test "set width 0" "" "" | |
c906108c | 565 | |
1cd3489f MC |
566 | if ![runto_main ] then { |
567 | perror "couldn't run to breakpoint" | |
568 | return | |
2bec0572 ND |
569 | } |
570 | ||
1cd3489f MC |
571 | gdb_breakpoint inheritance2 |
572 | gdb_test "continue" ".*Breakpoint .* inheritance2.*" "" | |
c906108c | 573 | |
1cd3489f MC |
574 | test_ptype_class_objects |
575 | test_non_inherited_member_access | |
576 | test_wrong_class_members | |
577 | test_nonexistent_members | |
578 | test_method_param_class | |
c906108c | 579 | |
1cd3489f | 580 | gdb_breakpoint enums2 |
184ad485 | 581 | gdb_test "continue" ".*Breakpoint .* enums2.*" "continue to enums2(\\(\\)|)" |
1cd3489f MC |
582 | gdb_test "finish" "" "" |
583 | test_enums | |
584 | ||
184ad485 MC |
585 | gdb_test "finish" "" "" |
586 | test_pointers_to_class_members | |
587 | test_static_members | |
588 | ||
1cd3489f MC |
589 | # Now some random tests that were just thrown in here. |
590 | ||
591 | gdb_breakpoint marker_reg1 | |
592 | gdb_test "continue" ".*Breakpoint .* marker_reg1.*" "" | |
593 | gdb_test "finish" "Run till exit from.*" "finish from marker_reg1" | |
594 | ||
595 | # This class is so small that an instance of it can fit in a register. | |
596 | # When gdb tries to call a method, it gets embarrassed about taking | |
597 | # the address of a register. | |
598 | # | |
599 | # TODO: I think that message should be a PASS, not an XFAIL. | |
600 | # gdb prints an informative message and declines to do something | |
601 | # impossible. | |
602 | # | |
603 | # The method call actually succeeds if the compiler allocates very | |
604 | # small classes in memory instead of registers. So this test does | |
605 | # not tell us anything interesting if the call succeeds. | |
606 | # | |
607 | # -- chastain 2003-12-31 | |
608 | gdb_test_multiple "print v.method ()" "calling method for small class" { | |
609 | -re "\\$\[0-9\]+ = 82$nl$gdb_prompt $" { | |
610 | # gcc 3.3.2 -gdwarf-2 | |
611 | # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2 | |
612 | # gcc 3.3.2 -gstabs+ | |
613 | # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+ | |
614 | pass "calling method for small class" | |
615 | } | |
616 | -re "Address requested for identifier \"v\" which is in register .*$nl$gdb_prompt $" { | |
617 | # gcc 2.95.3 -gdwarf-2 | |
618 | # gcc 2.95.3 -gstabs+ | |
619 | setup_xfail "*-*-*" 2972 | |
620 | fail "calling method for small class" | |
c906108c SS |
621 | } |
622 | } | |
c906108c SS |
623 | } |
624 | ||
625 | do_tests |