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