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