Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1992-2020 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) |
ebac27b4 | 17 | # And rewritten by Michael Chastain. (mec.gnu@mindspring.com) |
c906108c | 18 | |
ebac27b4 MC |
19 | set ws "\[\r\n\t \]+" |
20 | set nl "\[\r\n\]+" | |
21 | set vhn "\\$\[0-9\]+" | |
c2d11a7d | 22 | |
d4f3574e SS |
23 | if { [skip_cplus_tests] } { continue } |
24 | ||
25808999 MC |
25 | load_lib "cp-support.exp" |
26 | ||
f5f3a911 | 27 | standard_testfile misc.cc |
c906108c | 28 | |
09fe663e GB |
29 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ |
30 | {debug c++ additional_flags=-Wno-deprecated-register}]} { | |
f5f3a911 | 31 | return -1 |
c906108c SS |
32 | } |
33 | ||
c906108c | 34 | # Single inheritance, print type definitions. |
c906108c | 35 | |
ebac27b4 | 36 | proc test_ptype_si { } { |
c906108c SS |
37 | global gdb_prompt |
38 | global ws | |
39 | global nl | |
40 | ||
25808999 | 41 | # A simple class. |
c906108c | 42 | |
25808999 | 43 | cp_test_ptype_class \ |
b3720c3a | 44 | "A" "ptype A (FIXME)" "class" "A" \ |
25808999 MC |
45 | { |
46 | { field public "int a;" } | |
47 | { field public "int x;" } | |
ebac27b4 | 48 | } |
b3720c3a TT |
49 | cp_test_ptype_class "class A" "ptype class A (FIXME)" "class" "A" ibid |
50 | cp_test_ptype_class "g_A" "ptype g_A (FIXME)" "class" "A" ibid | |
c906108c | 51 | |
25808999 | 52 | # A derived class. |
c906108c | 53 | |
25808999 | 54 | cp_test_ptype_class \ |
b3720c3a | 55 | "B" "" "class" "B" \ |
25808999 MC |
56 | { |
57 | { base "public A" } | |
58 | { field public "int b;" } | |
59 | { field public "int x;" } | |
ebac27b4 | 60 | } |
b3720c3a TT |
61 | cp_test_ptype_class "class B" "" "class" "B" ibid |
62 | cp_test_ptype_class "g_B" "" "class" "B" ibid | |
c906108c | 63 | |
25808999 | 64 | # Another derived class. |
c906108c | 65 | |
25808999 | 66 | cp_test_ptype_class \ |
b3720c3a | 67 | "C" "" "class" "C" \ |
25808999 MC |
68 | { |
69 | { base "public A" } | |
70 | { field public "int c;" } | |
71 | { field public "int x;" } | |
ebac27b4 | 72 | } |
b3720c3a TT |
73 | cp_test_ptype_class "class C" "" "class" "C" ibid |
74 | cp_test_ptype_class "g_C" "" "class" "C" ibid | |
c906108c | 75 | |
25808999 MC |
76 | # A structure with no tag. |
77 | # TODO: move this mess into a separate file, and re-specify | |
78 | # which results are PASS, KFAIL, XFAIL, and FAIL. | |
ebac27b4 MC |
79 | |
80 | set re_tag "tagless_struct" | |
81 | set XX_tag "\\._1" | |
82 | set re_class "(class $re_tag \{${ws}public:|class \{${ws}public:|struct $re_tag \{|struct \{)" | |
83 | set XX_class "(class $XX_tag \{${ws}public:|struct $XX_tag \{)" | |
84 | set re_fields "int one;${ws}int two;" | |
85 | set re_synth_gcc_23 "$re_tag & operator=\\($re_tag const ?&\\);${ws}$re_tag\\($re_tag const ?&\\);${ws}$re_tag\\((void|)\\);" | |
86 | set XX_synth_gcc_23 "($re_tag|$XX_tag) & operator=\\($XX_tag const ?&\\);${ws}$XX_tag\\($XX_tag const ?&\\);${ws}$XX_tag\\((void|)\\);" | |
87 | ||
88 | set name "ptype tagless struct" | |
89 | gdb_test_multiple "ptype tagless_struct" $name { | |
90 | -re "type = $XX_class${ws}$re_fields$nl\}$nl$gdb_prompt $" { | |
91 | # gcc 2.95.3 -gdwarf-2 | |
9366563b | 92 | pass "$name" |
c906108c | 93 | } |
ebac27b4 MC |
94 | -re "type = $re_class${ws}$re_fields${ws}$XX_synth_gcc_23$nl\}$nl$gdb_prompt $" { |
95 | # gcc 2.95.3 -gstabs+ | |
9366563b | 96 | pass "$name" |
c906108c | 97 | } |
ebac27b4 | 98 | -re "type = $re_class${ws}$re_fields$nl\}$nl$gdb_prompt $" { |
9366563b MC |
99 | # gcc 3.3.4 -gdwarf-2 |
100 | # gcc 3.4.1 -gdwarf-2 | |
101 | # gcc HEAD 2004-07-31 -gdwarf-2 | |
102 | # gcc HEAD 2004-07-31 -gstabs+ | |
103 | pass "$name" | |
c906108c | 104 | } |
ebac27b4 | 105 | -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" { |
9366563b MC |
106 | # gcc 3.3.4 -gstabs+ |
107 | # gcc 3.4.1 -gstabs+ | |
ebac27b4 | 108 | pass "$name" |
c906108c | 109 | } |
907af001 UW |
110 | -re "No symbol \"tagless_struct\" in current context.$nl$gdb_prompt $" { |
111 | # Several GCC 4.x versions provide neither a DW_TAG_typedef DIE | |
112 | # nor use the typedef name as struct tag name. | |
113 | xfail "$name" | |
114 | } | |
c906108c SS |
115 | } |
116 | ||
ebac27b4 MC |
117 | set name "ptype variable of type tagless struct" |
118 | gdb_test_multiple "ptype v_tagless" $name { | |
119 | -re "type = $XX_class${ws}$re_fields$nl\}$nl$gdb_prompt $" { | |
120 | # gcc 2.95.3 -gdwarf-2 | |
9366563b | 121 | pass "$name" |
3e36a0f4 | 122 | } |
ebac27b4 MC |
123 | -re "type = $re_class${ws}$re_fields${ws}$XX_synth_gcc_23$nl\}$nl$gdb_prompt $" { |
124 | # gcc 2.95.3 -gstabs+ | |
9366563b | 125 | pass "$name" |
c906108c | 126 | } |
ebac27b4 | 127 | -re "type = $re_class${ws}$re_fields$nl\}$nl$gdb_prompt $" { |
9366563b MC |
128 | # gcc 3.3.4 -gdwarf-2 |
129 | # gcc 3.4.1 -gdwarf-2 | |
130 | # gcc HEAD 2004-07-31 -gdwarf-2 | |
131 | # gcc HEAD 2004-07-31 -gstabs+ | |
132 | pass "$name" | |
c906108c | 133 | } |
ebac27b4 | 134 | -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" { |
9366563b MC |
135 | # gcc 3.3.4 -gstabs+ |
136 | # gcc 3.4.1 -gstabs+ | |
ebac27b4 | 137 | pass "$name" |
c906108c SS |
138 | } |
139 | } | |
140 | } | |
141 | ||
ebac27b4 | 142 | # Multiple inheritance, print type definitions. |
c906108c | 143 | |
ebac27b4 | 144 | proc test_ptype_mi { } { |
ebac27b4 | 145 | |
25808999 | 146 | # A class with two bases. |
ebac27b4 | 147 | |
25808999 | 148 | cp_test_ptype_class \ |
b3720c3a | 149 | "D" "" "class" "D" \ |
25808999 MC |
150 | { |
151 | { base "public B" } | |
152 | { base "public C" } | |
153 | { field public "int d;" } | |
154 | { field public "int x;" } | |
c906108c | 155 | } |
b3720c3a TT |
156 | cp_test_ptype_class "class D" "" "class" "D" ibid |
157 | cp_test_ptype_class "g_D" "" "class" "D" ibid | |
ebac27b4 | 158 | |
25808999 | 159 | # A class derived from the previous class. |
ebac27b4 | 160 | |
25808999 | 161 | cp_test_ptype_class \ |
b3720c3a | 162 | "E" "" "class" "E" \ |
25808999 MC |
163 | { |
164 | { base "public D" } | |
165 | { field public "int e;" } | |
166 | { field public "int x;" } | |
3e36a0f4 | 167 | } |
b3720c3a TT |
168 | cp_test_ptype_class "class E" "" "class" "E" ibid |
169 | cp_test_ptype_class "g_E" "" "class" "E" ibid | |
c906108c SS |
170 | } |
171 | ||
ebac27b4 | 172 | # Single virtual inheritance, print type definitions. |
c906108c | 173 | |
ebac27b4 | 174 | proc test_ptype_vi { } { |
c906108c | 175 | |
25808999 | 176 | # class vA |
c906108c | 177 | |
25808999 | 178 | cp_test_ptype_class \ |
b3720c3a | 179 | "vA" "" "class" "vA" \ |
25808999 MC |
180 | { |
181 | { field public "int va;" } | |
182 | { field public "int vx;" } | |
ebac27b4 | 183 | } |
b3720c3a TT |
184 | cp_test_ptype_class "class vA" "" "class" "vA" ibid |
185 | cp_test_ptype_class "g_vA" "" "class" "vA" ibid | |
c906108c | 186 | |
25808999 | 187 | # class vB |
c906108c | 188 | |
25808999 | 189 | cp_test_ptype_class \ |
b3720c3a | 190 | "vB" "" "class" "vB" \ |
25808999 MC |
191 | { |
192 | { base "public virtual vA" } | |
193 | { vbase "vA" } | |
194 | { field public "int vb;" } | |
195 | { field public "int vx;" } | |
ebac27b4 | 196 | } |
b3720c3a TT |
197 | cp_test_ptype_class "class vB" "" "class" "vB" ibid |
198 | cp_test_ptype_class "g_vB" "" "class" "vB" ibid | |
c906108c | 199 | |
25808999 | 200 | # class vC |
c906108c | 201 | |
25808999 | 202 | cp_test_ptype_class \ |
b3720c3a | 203 | "vC" "" "class" "vC" \ |
25808999 MC |
204 | { |
205 | { base "public virtual vA" } | |
206 | { vbase "vA" } | |
207 | { field public "int vc;" } | |
208 | { field public "int vx;" } | |
ebac27b4 | 209 | } |
b3720c3a TT |
210 | cp_test_ptype_class "class vC" "" "class" "vC" ibid |
211 | cp_test_ptype_class "g_vC" "" "class" "vC" ibid | |
c906108c | 212 | |
ebac27b4 | 213 | } |
c906108c | 214 | |
ebac27b4 | 215 | # Multiple virtual inheritance, print type definitions. |
c906108c | 216 | |
ebac27b4 | 217 | proc test_ptype_mvi { } { |
c906108c | 218 | |
25808999 | 219 | # class vD |
c906108c | 220 | |
25808999 | 221 | cp_test_ptype_class \ |
b3720c3a | 222 | "vD" "" "class" "vD" \ |
25808999 MC |
223 | { |
224 | { base "public virtual vB" } | |
225 | { base "public virtual vC" } | |
226 | { vbase "vC" } | |
227 | { vbase "vB" } | |
228 | { field public "int vd;" } | |
229 | { field public "int vx;" } | |
ebac27b4 | 230 | } |
b3720c3a TT |
231 | cp_test_ptype_class "class vD" "" "class" "vD" ibid |
232 | cp_test_ptype_class "g_vD" "" "class" "vD" ibid | |
c906108c | 233 | |
25808999 | 234 | # class vE |
c906108c | 235 | |
25808999 | 236 | cp_test_ptype_class \ |
b3720c3a | 237 | "vE" "" "class" "vE" \ |
25808999 MC |
238 | { |
239 | { base "public virtual vD" } | |
240 | { vbase "vD" } | |
241 | { field public "int ve;" } | |
242 | { field public "int vx;" } | |
ebac27b4 | 243 | } |
b3720c3a TT |
244 | cp_test_ptype_class "class vE" "" "class" "vE" ibid |
245 | cp_test_ptype_class "g_vE" "" "class" "vE" ibid | |
c906108c | 246 | |
c906108c SS |
247 | } |
248 | ||
ebac27b4 | 249 | # Single inheritance, print individual members. |
c906108c | 250 | |
ebac27b4 MC |
251 | proc test_print_si_members { } { |
252 | global vhn | |
c906108c | 253 | |
ebac27b4 MC |
254 | # Print all members of g_A using fully qualified form. |
255 | gdb_test "print g_A.A::a" "$vhn = 1" | |
256 | gdb_test "print g_A.A::x" "$vhn = 2" | |
c906108c | 257 | |
ebac27b4 MC |
258 | # Print members of g_A using nonambiguous compact form. |
259 | gdb_test "print g_A.a" "$vhn = 1" | |
260 | gdb_test "print g_A.x" "$vhn = 2" | |
c906108c | 261 | |
ebac27b4 MC |
262 | # Print all members of g_B using fully qualified form. |
263 | gdb_test "print g_B.A::a" "$vhn = 3" | |
264 | gdb_test "print g_B.A::x" "$vhn = 4" | |
265 | gdb_test "print g_B.B::b" "$vhn = 5" | |
266 | gdb_test "print g_B.B::x" "$vhn = 6" | |
c906108c | 267 | |
ebac27b4 MC |
268 | # Print members of g_B using nonambiguous compact form. |
269 | gdb_test "print g_B.a" "$vhn = 3" | |
270 | gdb_test "print g_B.b" "$vhn = 5" | |
271 | gdb_test "print g_B.x" "$vhn = 6" | |
c906108c | 272 | |
ebac27b4 MC |
273 | # Print all members of g_C using fully qualified form. |
274 | gdb_test "print g_C.A::a" "$vhn = 7" | |
275 | gdb_test "print g_C.A::x" "$vhn = 8" | |
276 | gdb_test "print g_C.C::c" "$vhn = 9" | |
277 | gdb_test "print g_C.C::x" "$vhn = 10" | |
c906108c | 278 | |
ebac27b4 MC |
279 | # Print members of g_C using nonambiguous compact form. |
280 | gdb_test "print g_C.a" "$vhn = 7" | |
281 | gdb_test "print g_C.c" "$vhn = 9" | |
282 | gdb_test "print g_C.x" "$vhn = 10" | |
c906108c SS |
283 | } |
284 | ||
ebac27b4 | 285 | # Single inheritance, print complete classes. |
c906108c | 286 | |
ebac27b4 MC |
287 | proc test_print_si_classes { } { |
288 | global vhn | |
c906108c | 289 | |
ebac27b4 MC |
290 | # Print all members of g_A, g_B, g_C. |
291 | gdb_test "print g_A" "$vhn = \{a = 1, x = 2\}" | |
292 | gdb_test "print g_B" "$vhn = \{<(class A|A)> = \{a = 3, x = 4\}, b = 5, x = 6\}" | |
293 | gdb_test "print g_C" "$vhn = \{<(class A|A)> = \{a = 7, x = 8\}, c = 9, x = 10\}" | |
c906108c SS |
294 | } |
295 | ||
ebac27b4 | 296 | # Multiple inheritance, print individual members. |
c906108c | 297 | |
ebac27b4 | 298 | proc test_print_mi_members {} { |
c906108c | 299 | global gdb_prompt |
c906108c | 300 | global nl |
ebac27b4 | 301 | global vhn |
c906108c | 302 | |
ebac27b4 MC |
303 | # Print all members of g_A. |
304 | gdb_test "print g_A.A::a" "$vhn = 1" | |
305 | gdb_test "print g_A.A::x" "$vhn = 2" | |
c906108c | 306 | |
ebac27b4 MC |
307 | # Print all members of g_B. |
308 | gdb_test "print g_B.A::a" "$vhn = 3" | |
309 | gdb_test "print g_B.A::x" "$vhn = 4" | |
310 | gdb_test "print g_B.B::b" "$vhn = 5" | |
311 | gdb_test "print g_B.B::x" "$vhn = 6" | |
c906108c | 312 | |
ebac27b4 MC |
313 | # Print all members of g_C. |
314 | gdb_test "print g_C.A::a" "$vhn = 7" | |
315 | gdb_test "print g_C.A::x" "$vhn = 8" | |
316 | gdb_test "print g_C.C::c" "$vhn = 9" | |
317 | gdb_test "print g_C.C::x" "$vhn = 10" | |
c906108c | 318 | |
ebac27b4 MC |
319 | # Print all members of g_D. |
320 | # | |
b1af9e97 TT |
321 | # g_D.A::a and g_D.A::x are ambiguous member accesses. |
322 | gdb_test "print g_D.A::a" "base class 'A' is ambiguous in type 'D'" | |
323 | gdb_test "print g_D.C::a" "$vhn = 15" | |
324 | gdb_test "print g_D.B::a" "$vhn = 11" | |
325 | gdb_test "print g_D.A::x" "base class 'A' is ambiguous in type 'D'" | |
ebac27b4 MC |
326 | gdb_test "print g_D.B::b" "$vhn = 13" |
327 | gdb_test "print g_D.B::x" "$vhn = 14" | |
328 | gdb_test "print g_D.C::c" "$vhn = 17" | |
329 | gdb_test "print g_D.C::x" "$vhn = 18" | |
330 | gdb_test "print g_D.D::d" "$vhn = 19" | |
331 | gdb_test "print g_D.D::x" "$vhn = 20" | |
c906108c | 332 | |
ebac27b4 MC |
333 | # Print all members of g_E. |
334 | # g_E.A::a and g_E.A::x are ambiguous. | |
c906108c | 335 | |
b1af9e97 TT |
336 | gdb_test "print g_E.A::a" "base class 'A' is ambiguous in type 'E'" |
337 | gdb_test "print g_E.A::x" "base class 'A' is ambiguous in type 'E'" | |
ebac27b4 MC |
338 | gdb_test "print g_E.B::b" "$vhn = 23" |
339 | gdb_test "print g_E.B::x" "$vhn = 24" | |
340 | gdb_test "print g_E.C::c" "$vhn = 27" | |
341 | gdb_test "print g_E.C::x" "$vhn = 28" | |
342 | gdb_test "print g_E.D::d" "$vhn = 29" | |
343 | gdb_test "print g_E.D::x" "$vhn = 30" | |
344 | gdb_test "print g_E.E::e" "$vhn = 31" | |
345 | gdb_test "print g_E.E::x" "$vhn = 32" | |
346 | } | |
c906108c | 347 | |
9733fc94 DJ |
348 | # Multiple inheritance, print individual member types. |
349 | ||
350 | proc test_print_mi_member_types {} { | |
351 | global gdb_prompt | |
352 | global nl | |
353 | global vhn | |
354 | ||
355 | # Print the types of some members of g_D without qualifying them. | |
356 | gdb_test "ptype g_D.b" "type = int" | |
357 | gdb_test "ptype g_D.c" "type = int" | |
358 | gdb_test "ptype g_D.d" "type = int" | |
359 | ||
360 | # Print the types of qualified members; none of these tests pass today. | |
361 | ||
362 | # Print all members of g_A. | |
9733fc94 | 363 | gdb_test "ptype g_A.A::a" "type = int" |
9733fc94 DJ |
364 | gdb_test "ptype g_A.A::x" "type = int" |
365 | ||
366 | # Print all members of g_B. | |
9733fc94 | 367 | gdb_test "ptype g_B.A::a" "type = int" |
9733fc94 | 368 | gdb_test "ptype g_B.A::x" "type = int" |
9733fc94 | 369 | gdb_test "ptype g_B.B::b" "type = int" |
9733fc94 DJ |
370 | gdb_test "ptype g_B.B::x" "type = int" |
371 | ||
372 | # Print all members of g_C. | |
9733fc94 | 373 | gdb_test "ptype g_C.A::a" "type = int" |
9733fc94 | 374 | gdb_test "ptype g_C.A::x" "type = int" |
9733fc94 | 375 | gdb_test "ptype g_C.C::c" "type = int" |
9733fc94 DJ |
376 | gdb_test "ptype g_C.C::x" "type = int" |
377 | ||
378 | # Print all members of g_D. | |
379 | # | |
b1af9e97 | 380 | # g_D.A::a and g_D.A::x are ambiguous member accesses. |
9733fc94 | 381 | |
b1af9e97 TT |
382 | gdb_test "ptype g_D.A::a" "base class 'A' is ambiguous in type 'D'" |
383 | gdb_test "ptype g_D.A::x" "base class 'A' is ambiguous in type 'D'" | |
9733fc94 | 384 | gdb_test "ptype g_D.B::b" "type = int" |
9733fc94 | 385 | gdb_test "ptype g_D.B::x" "type = int" |
9733fc94 | 386 | gdb_test "ptype g_D.C::c" "type = int" |
9733fc94 | 387 | gdb_test "ptype g_D.C::x" "type = int" |
9733fc94 | 388 | gdb_test "ptype g_D.D::d" "type = int" |
9733fc94 DJ |
389 | gdb_test "ptype g_D.D::x" "type = int" |
390 | ||
391 | # Print all members of g_E. | |
392 | # g_E.A::a and g_E.A::x are ambiguous. | |
393 | ||
b1af9e97 TT |
394 | gdb_test "ptype g_E.A::a" "base class 'A' is ambiguous in type 'E'" |
395 | gdb_test "ptype g_E.A::x" "base class 'A' is ambiguous in type 'E'" | |
9733fc94 | 396 | gdb_test "ptype g_E.B::b" "type = int" |
9733fc94 | 397 | gdb_test "ptype g_E.B::x" "type = int" |
9733fc94 | 398 | gdb_test "ptype g_E.C::c" "type = int" |
9733fc94 | 399 | gdb_test "ptype g_E.C::x" "type = int" |
9733fc94 | 400 | gdb_test "ptype g_E.D::d" "type = int" |
9733fc94 | 401 | gdb_test "ptype g_E.D::x" "type = int" |
9733fc94 | 402 | gdb_test "ptype g_E.E::e" "type = int" |
9733fc94 DJ |
403 | gdb_test "ptype g_E.E::x" "type = int" |
404 | } | |
405 | ||
ebac27b4 | 406 | # Multiple inheritance, print complete classes. |
c906108c | 407 | |
ebac27b4 MC |
408 | proc test_print_mi_classes { } { |
409 | global vhn | |
c906108c | 410 | |
ebac27b4 MC |
411 | # Print all members of g_D. |
412 | gdb_test "print g_D" "$vhn = \{\<(class |)B\> = \{\<(class |)A\> = \{a = 11, x = 12\}, b = 13, x = 14\}, \<(class |)C\> = \{\<(class |)A\> = \{a = 15, x = 16\}, c = 17, x = 18\}, d = 19, x = 20\}" | |
c906108c | 413 | |
ebac27b4 MC |
414 | # Print all members of g_E. |
415 | gdb_test "print g_E" "$vhn = \{\<(class |)D\> = \{\<(class |)B\> = \{\<(class |)A\> = \{a = 21, x = 22\}, b = 23, x = 24\}, \<(class |)C\> = \{\<(class |)A\> = \{a = 25, x = 26\}, c = 27, x = 28\}, d = 29, x = 30\}, e = 31, x = 32\}" | |
c906108c SS |
416 | } |
417 | ||
ebac27b4 MC |
418 | # Single inheritance, print anonymous unions. |
419 | # GDB versions prior to 4.14 entered an infinite loop when printing | |
420 | # the type of a class containing an anonymous union, and they were also | |
421 | # incapable of printing the member of an anonymous union. | |
422 | # We test the printing of the member first, and perform the other tests | |
423 | # only if the test succeeds, to avoid the infinite loop. | |
c906108c | 424 | |
ebac27b4 | 425 | proc test_print_anon_union {} { |
c906108c | 426 | global gdb_prompt |
a0b3c4fd | 427 | global ws |
c906108c | 428 | global nl |
ebac27b4 | 429 | global vhn |
c906108c | 430 | |
ebac27b4 | 431 | gdb_test "print g_anon_union.a" "$vhn = 2" "print anonymous union member" |
c906108c | 432 | |
ebac27b4 MC |
433 | set name "print variable of type anonymous union" |
434 | gdb_test_multiple "print g_anon_union" $name { | |
907af001 | 435 | -re "$vhn = \{one = 1, \{a = 2, b = \[0-9\]+\}\}$nl$gdb_prompt $" { |
ebac27b4 | 436 | pass $name |
c906108c | 437 | } |
c906108c SS |
438 | } |
439 | ||
907af001 UW |
440 | set name "print type of anonymous union" |
441 | set re_tag "class_with_anon_union" | |
5984a431 | 442 | set re_class "(class $re_tag \{${ws}public:|struct $re_tag \{)" |
907af001 UW |
443 | set re_fields "int one;${ws}union \{${ws}int a;${ws}long( int)? b;${ws}\};" |
444 | gdb_test_multiple "ptype g_anon_union" $name { | |
445 | -re "type = $re_class${ws}$re_fields$nl\}$nl$gdb_prompt $" { | |
446 | pass $name | |
a0b3c4fd | 447 | } |
907af001 | 448 | } |
ebac27b4 | 449 | } |
c906108c | 450 | |
c906108c | 451 | |
ebac27b4 | 452 | # Single virtual inheritance, print individual members. |
c906108c | 453 | |
ebac27b4 MC |
454 | proc test_print_svi_members { } { |
455 | global vhn | |
c906108c | 456 | |
ebac27b4 MC |
457 | # Print all members of g_vA. |
458 | gdb_test "print g_vA.vA::va" "$vhn = 1" | |
459 | gdb_test "print g_vA.vA::vx" "$vhn = 2" | |
c906108c | 460 | |
ebac27b4 MC |
461 | # Print members of g_vA using compact form. |
462 | gdb_test "print g_vA.va" "$vhn = 1" | |
463 | gdb_test "print g_vA.vx" "$vhn = 2" | |
464 | ||
465 | # Print all members of g_vB. | |
466 | gdb_test "print g_vB.vA::va" "$vhn = 3" | |
467 | gdb_test "print g_vB.vA::vx" "$vhn = 4" | |
468 | gdb_test "print g_vB.vB::vb" "$vhn = 5" | |
469 | gdb_test "print g_vB.vB::vx" "$vhn = 6" | |
470 | ||
471 | # Print members of g_vB using compact form. | |
472 | gdb_test "print g_vB.va" "$vhn = 3" | |
473 | gdb_test "print g_vB.vb" "$vhn = 5" | |
474 | gdb_test "print g_vB.vx" "$vhn = 6" | |
475 | ||
476 | # Print all members of g_vC. | |
477 | gdb_test "print g_vC.vA::va" "$vhn = 7" | |
478 | gdb_test "print g_vC.vA::vx" "$vhn = 8" | |
479 | gdb_test "print g_vC.vC::vc" "$vhn = 9" | |
480 | gdb_test "print g_vC.vC::vx" "$vhn = 10" | |
481 | ||
482 | # Print members of g_vC using compact form. | |
e96ec2ba TV |
483 | gdb_test "print g_vC.va" "$vhn = 7" |
484 | gdb_test "print g_vC.vc" "$vhn = 9" | |
485 | gdb_test "print g_vC.vx" "$vhn = 10" | |
c906108c SS |
486 | } |
487 | ||
c906108c | 488 | # Single virtual inheritance, print complete classes. |
c906108c | 489 | |
ebac27b4 | 490 | proc test_print_svi_classes { } { |
c906108c SS |
491 | global gdb_prompt |
492 | global hex | |
c906108c | 493 | global nl |
ebac27b4 | 494 | global vhn |
c906108c SS |
495 | |
496 | # Print all members of g_vA. | |
ebac27b4 | 497 | gdb_test "print g_vA" "$vhn = \{va = 1, vx = 2\}" |
c906108c SS |
498 | |
499 | # Print all members of g_vB. | |
ebac27b4 MC |
500 | set re_vbptr_2 "(_vb.2vA|_vb.vA)" |
501 | set re_vbptr_3 "_vptr.vB" | |
502 | ||
503 | set name "print g_vB" | |
504 | gdb_test_multiple "print g_vB" $name { | |
505 | -re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_2 = $hex, vb = 5, vx = 6\}$nl$gdb_prompt $" { | |
506 | # gcc 2.95.3 -gdwarf-2 | |
507 | # gcc 2.95.3 -gstabs+ | |
508 | pass $name | |
509 | } | |
510 | -re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = $hex, vb = 5, vx = 6\}$nl$gdb_prompt $" { | |
9366563b MC |
511 | # gcc 3.3.4 -gdwarf-2 |
512 | # gcc 3.4.1 -gdwarf-2 | |
513 | # gcc 3.4.1 -gstabs+ | |
514 | # gcc HEAD 2004-07-31 -gdwarf-2 | |
ebac27b4 MC |
515 | pass "$name (FIXME v3 vtbl ptr)" |
516 | } | |
517 | -re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = $hex <VTT for vB>, vb = 5, vx = 6\}$nl$gdb_prompt $" { | |
9366563b MC |
518 | # gcc 3.3.4 -gstabs+ |
519 | pass $name | |
520 | } | |
521 | -re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = $hex <typeinfo for vB>, vb = 5, vx = 6\}$nl$gdb_prompt $" { | |
522 | # gcc HEAD 2004-07-31 -gstabs+ | |
ebac27b4 | 523 | pass $name |
5178b9d6 | 524 | } |
b32b93c6 AS |
525 | -re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = ${hex}( <\[^>]*>)?, vb = 5, vx = 6\}$nl$gdb_prompt $" { |
526 | # gcc HEAD 2015?+ | |
527 | # the vptr is set to the address *after* the vtable, | |
65808c96 | 528 | # so the # symbol shown is unpredictable. |
b32b93c6 AS |
529 | pass "$name (symbols ignored)" |
530 | } | |
c906108c SS |
531 | } |
532 | ||
533 | # Print all members of g_vC. | |
ebac27b4 MC |
534 | set re_vbptr_2 "(_vb.2vA|_vb.vA)" |
535 | set re_vbptr_3 "_vptr.vC" | |
536 | ||
537 | set name "print g_vC" | |
538 | gdb_test_multiple "print g_vC" $name { | |
539 | -re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_2 = $hex, vc = 9, vx = 10\}$nl$gdb_prompt $" { | |
540 | # gcc 2.95.3 -gdwarf-2 | |
541 | # gcc 2.95.3 -gstabs+ | |
542 | pass $name | |
543 | } | |
544 | -re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = $hex, vc = 9, vx = 10\}$nl$gdb_prompt $" { | |
9366563b MC |
545 | # gcc 3.3.4 -gdwarf-2 |
546 | # gcc 3.4.1 -gdwarf-2 | |
547 | # gcc 3.4.1 -gstabs+ | |
548 | # gcc HEAD 2004-07-31 -gdwarf-2 | |
ebac27b4 MC |
549 | pass "$name (FIXME v3 vtbl ptr)" |
550 | } | |
551 | -re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = $hex <VTT for vC>, vc = 9, vx = 10\}$nl$gdb_prompt $" { | |
9366563b MC |
552 | # gcc 3.3.4 -gstabs+ |
553 | pass $name | |
554 | } | |
555 | -re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = $hex <typeinfo for vC>, vc = 9, vx = 10\}$nl$gdb_prompt $" { | |
556 | # gcc HEAD 2004-07-31 -gstabs+ | |
ebac27b4 | 557 | pass $name |
a0b3c4fd | 558 | } |
b32b93c6 AS |
559 | -re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = ${hex}( <\[^>]*>)?, vc = 9, vx = 10\}$nl$gdb_prompt $" { |
560 | # gcc HEAD 2015?+ | |
561 | # the vptr is set to the address *after* the vtable, | |
65808c96 | 562 | # so the symbol shown is unpredictable. |
b32b93c6 AS |
563 | pass "$name (symbols ignored)" |
564 | } | |
a0b3c4fd | 565 | } |
c906108c SS |
566 | } |
567 | ||
c906108c | 568 | # Multiple virtual inheritance, print individual members. |
c906108c | 569 | |
ebac27b4 MC |
570 | proc test_print_mvi_members { } { |
571 | global vhn | |
c906108c SS |
572 | |
573 | # Print all members of g_vD. | |
ebac27b4 MC |
574 | gdb_test "print g_vD.vA::va" "$vhn = 19" |
575 | gdb_test "print g_vD.vA::vx" "$vhn = 20" | |
576 | gdb_test "print g_vD.vB::vb" "$vhn = 21" | |
577 | gdb_test "print g_vD.vB::vx" "$vhn = 22" | |
578 | gdb_test "print g_vD.vC::vc" "$vhn = 23" | |
579 | gdb_test "print g_vD.vC::vx" "$vhn = 24" | |
580 | gdb_test "print g_vD.vD::vd" "$vhn = 25" | |
581 | gdb_test "print g_vD.vD::vx" "$vhn = 26" | |
c906108c SS |
582 | |
583 | # Print all members of g_vE. | |
ebac27b4 MC |
584 | gdb_test "print g_vE.vA::va" "$vhn = 0" |
585 | gdb_test "print g_vE.vA::vx" "$vhn = 0" | |
586 | gdb_test "print g_vE.vB::vb" "$vhn = 0" | |
587 | gdb_test "print g_vE.vB::vx" "$vhn = 0" | |
588 | gdb_test "print g_vE.vC::vc" "$vhn = 0" | |
589 | gdb_test "print g_vE.vC::vx" "$vhn = 0" | |
590 | gdb_test "print g_vE.vD::vd" "$vhn = 0" | |
591 | gdb_test "print g_vE.vD::vx" "$vhn = 0" | |
592 | gdb_test "print g_vE.vE::ve" "$vhn = 27" | |
593 | gdb_test "print g_vE.vE::vx" "$vhn = 28" | |
c906108c SS |
594 | } |
595 | ||
ebac27b4 | 596 | # Multiple virtual inheritance, print complete classes. |
c906108c | 597 | |
ebac27b4 | 598 | proc test_print_mvi_classes { } { |
a0b3c4fd | 599 | global gdb_prompt |
ebac27b4 | 600 | global hex |
a0b3c4fd | 601 | global ws |
c906108c | 602 | global nl |
ebac27b4 | 603 | global vhn |
c906108c | 604 | |
ebac27b4 | 605 | # Virtual base pointers for everybody. |
c906108c | 606 | |
ebac27b4 MC |
607 | set re_vbptr_2_vA "(_vb.2vA|_vb.vA)" |
608 | set re_vbptr_2_vB "(_vb.2vB|_vb.vB)" | |
609 | set re_vbptr_2_vC "(_vb.2vC|_vb.vC)" | |
610 | set re_vbptr_2_vD "(_vb.2vD|_vb.vD)" | |
611 | set re_vbptr_3_vA "_vptr.vA" | |
612 | set re_vbptr_3_vB "_vptr.vB" | |
613 | set re_vbptr_3_vC "_vptr.vC" | |
614 | set re_vbptr_3_vD "_vptr.vD" | |
615 | set re_vbptr_3_vE "_vptr.vE" | |
c906108c SS |
616 | |
617 | # Print all members of g_vD. | |
618 | ||
ebac27b4 MC |
619 | set name "print g_vD" |
620 | gdb_test_multiple "print g_vD" $name { | |
621 | -re "$vhn = \{<vB> = \{<vA> = \{va = 19, vx = 20\}, $re_vbptr_2_vA = $hex, vb = 21, vx = 22\}, <vC> = \{$re_vbptr_2_vA = $hex, vc = 23, vx = 24\}, $re_vbptr_2_vC = $hex, $re_vbptr_2_vB = $hex, vd = 25, vx = 26\}$nl$gdb_prompt $" { | |
622 | # gcc 2.95.3 -gdwarf-2 | |
623 | # gcc 2.95.3 -gstabs+ | |
624 | pass $name | |
c906108c | 625 | } |
410528f0 | 626 | -re "$vhn = \{<vB> = \{<vA> = \{va = 19, vx = 20\}, $re_vbptr_3_vB = ${hex}( <vtable for vD.*>)?, vb = 21, vx = 22\}, <vC> = \{$re_vbptr_3_vC = ${hex}( <vtable for vC.*>)?, vc = 23, vx = 24\}, $re_vbptr_3_vD = ${hex}( <vtable for vD.*>)?, vd = 25, vx = 26\}$nl$gdb_prompt $" { |
ebac27b4 MC |
627 | # gcc 3.3.2 -gdwarf-2 |
628 | # gcc HEAD 2004-01-21 -gdwarf-2 | |
629 | # gcc HEAD 2004-01-21 -gstabs+ | |
630 | pass "$name (FIXME v3 vtbl ptr)" | |
5178b9d6 | 631 | } |
ebac27b4 MC |
632 | -re "$vhn = \{<vB> = \{<vA> = \{va = 19, vx = 20\}, $re_vbptr_3_vB = $hex, vb = 21, vx = 22\}, <vC> = \{$re_vbptr_3_vC = $hex <VTT for vD>, vc = 23, vx = 24\}, $re_vbptr_3_vD = $hex, vd = 25, vx = 26\}$nl$gdb_prompt $" { |
633 | # gcc 3.3.2 -gstabs+ | |
634 | pass "$name" | |
3c6cb4a1 | 635 | } |
b32b93c6 AS |
636 | -re "$vhn = \{<vB> = \{<vA> = \{va = 19, vx = 20\}, $re_vbptr_3_vB = ${hex}( <\[^>]*>)?, vb = 21, vx = 22\}, <vC> = \{$re_vbptr_3_vC = ${hex}( <\[^>]*>)?, vc = 23, vx = 24\}, $re_vbptr_3_vD = ${hex}( <\[^>]*>)?, vd = 25, vx = 26\}$nl$gdb_prompt $" { |
637 | # gcc HEAD 2015?+ | |
638 | # the vptr is set to the address *after* the vtable, | |
65808c96 | 639 | # so the symbol shown is unpredictable. |
b32b93c6 AS |
640 | pass "$name (symbols ignored)" |
641 | } | |
c906108c SS |
642 | } |
643 | ||
644 | # Print all members of g_vE. | |
645 | ||
ebac27b4 MC |
646 | set name "print g_vE" |
647 | gdb_test_multiple "print g_vE" $name { | |
648 | -re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_2_vA = $hex, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_2_vA = $hex, vc = 0, vx = 0\}, $re_vbptr_2_vC = $hex, $re_vbptr_2_vB = $hex, vd = 0, vx = 0\}, $re_vbptr_2_vD = $hex, ve = 27, vx = 28\}$nl$gdb_prompt $" { | |
649 | # gcc 2.95.3 -gdwarf-2 | |
650 | # gcc 2.95.3 -gstabs+ | |
651 | pass $name | |
a0b3c4fd | 652 | } |
410528f0 | 653 | -re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_3_vB = ${hex}( <vtable for vE.*>)?, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_3_vC = ${hex}( <vtable for vE.*>)?, vc = 0, vx = 0\}, $re_vbptr_3_vD = ${hex}( <vtable for vE.*>)?, vd = 0, vx = 0\}, $re_vbptr_3_vE = ${hex}( <vtable for vE.*>)?, ve = 27, vx = 28\}$nl$gdb_prompt $" { |
9366563b MC |
654 | # gcc 3.3.4 -gdwarf-2 |
655 | # gcc 3.3.4 -gstabs+ | |
656 | # gcc 3.4.1 -gdwarf-2 | |
657 | # gcc 3.4.1 -gstabs+ | |
658 | # gcc HEAD 2004-07-31 -gdwarf-2 | |
ebac27b4 | 659 | pass "$name (FIXME v3 vtbl ptr)" |
5178b9d6 | 660 | } |
ec4646ef MC |
661 | -re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_3_vB = $hex, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_3_vC = $hex <VTT for vD>, vc = 0, vx = 0\}, $re_vbptr_3_vD = $hex, vd = 0, vx = 0\}, $re_vbptr_3_vE = $hex, ve = 27, vx = 28\}$nl$gdb_prompt $" { |
662 | # gcc 3.2.7-rh -gstabs+ | |
9366563b MC |
663 | pass $name |
664 | } | |
665 | -re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_3_vB = $hex, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_3_vC = $hex <typeinfo for vE>, vc = 0, vx = 0\}, $re_vbptr_3_vD = $hex, vd = 0, vx = 0\}, $re_vbptr_3_vE = $hex, ve = 27, vx = 28\}$nl$gdb_prompt $" { | |
666 | # gcc HEAD 2004-07-31 -gstabs+ | |
667 | pass $name | |
ec4646ef | 668 | } |
b32b93c6 AS |
669 | -re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_3_vB = ${hex}( <\[^>]*>)?, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_3_vC = ${hex}( <\[^>]*>)?, vc = 0, vx = 0\}, $re_vbptr_3_vD = ${hex}( <\[^>]*>)?, vd = 0, vx = 0\}, $re_vbptr_3_vE = ${hex}( <\[^>]*>)?, ve = 27, vx = 28\}$nl$gdb_prompt $" { |
670 | # gcc HEAD 2015?+ | |
671 | # the vptr is set to the address *after* the vtable, | |
65808c96 | 672 | # so the symbol shown is unpredictable. |
b32b93c6 AS |
673 | pass "$name (symbols ignored)" |
674 | } | |
a0b3c4fd | 675 | } |
c906108c SS |
676 | } |
677 | ||
ebac27b4 | 678 | proc do_tests { } { |
a8d52276 | 679 | gdb_test_no_output "set width 0" |
c906108c | 680 | |
ebac27b4 MC |
681 | if { ![runto_main] } then { |
682 | perror "couldn't run to main" | |
683 | return | |
c906108c SS |
684 | } |
685 | ||
1cf0e11f | 686 | gdb_test_no_output "set language c++" |
c906108c SS |
687 | test_ptype_si |
688 | test_ptype_mi | |
689 | test_ptype_vi | |
690 | test_ptype_mvi | |
691 | ||
ebac27b4 MC |
692 | if { ![runto 'inheritance2'] } then { |
693 | perror "couldn't run to inheritance2" | |
694 | return | |
c906108c SS |
695 | } |
696 | ||
c2b75043 LM |
697 | with_test_prefix "single inheritance" { |
698 | test_print_si_members | |
699 | } | |
700 | ||
c906108c | 701 | test_print_si_classes |
c2b75043 LM |
702 | |
703 | with_test_prefix "multiple inheritance" { | |
704 | test_print_mi_members | |
705 | } | |
706 | ||
9733fc94 | 707 | test_print_mi_member_types |
c906108c SS |
708 | test_print_mi_classes |
709 | test_print_anon_union | |
710 | ||
ebac27b4 MC |
711 | if { ![runto 'inheritance4'] } { |
712 | perror "couldn't run to inheritance4" | |
713 | return | |
c906108c SS |
714 | } |
715 | ||
716 | test_print_svi_members | |
717 | test_print_svi_classes | |
718 | test_print_mvi_members | |
719 | test_print_mvi_classes | |
720 | } | |
721 | ||
722 | do_tests |