1 /* Copyright 2012-2013 Free Software Foundation, Inc.
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
5 the Free Software Foundation; either version 3 of the License, or
6 (at your option) any later version.
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.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 virtual ~Base() {} // Enforce type to have vtable
22 struct Derived : public Base {
23 Derived() : B(2), C(3) {}
29 void use_rtti_for_ptr_test ()
31 /*: BEGIN: use_rtti_for_ptr :*/
34 const Base* constPtr = &d;
35 Base* const ptrConst = &d;
36 Base const* const constPtrConst = &d;
38 set testname use_rtti_for_ptr
39 set_print_object off $testname
40 check_new_derived_without_rtti ptr {Base \*} $testname
41 check_new_derived_without_rtti constPtr {const Base \*} $testname
42 check_new_derived_without_rtti ptrConst {Base \* const} $testname
43 check_new_derived_without_rtti constPtrConst {const Base \* const} \
46 set_print_object on $testname
47 check_new_derived_with_rtti ptr {Derived \*} $testname
48 check_new_derived_with_rtti constPtr {const Derived \*} $testname
49 check_new_derived_with_rtti ptrConst {Derived \* const} $testname
50 check_new_derived_with_rtti constPtrConst {const Derived \* const} \
54 /*: END: use_rtti_for_ptr :*/
58 void use_rtti_for_ref_test ()
60 /*: BEGIN: use_rtti_for_ref :*/
63 const Base& constRef = d;
65 set testname use_rtti_for_ref
66 set_print_object off $testname
67 check_new_derived_without_rtti ref {Base \&} $testname
68 check_new_derived_without_rtti constRef {const Base \&} $testname
70 set_print_object on $testname
71 check_new_derived_with_rtti ref {Derived \&} $testname
72 check_new_derived_with_rtti constRef {const Derived \&} $testname
75 /*: END: use_rtti_for_ref :*/
79 void use_rtti_for_ptr_child_test ()
81 /*: BEGIN: use_rtti_for_ptr_child :*/
87 Base const* const constPtrConst;
92 constPtrConst ( v ) {}
95 set testname use_rtti_for_ptr_child
97 set_print_object off $testname
98 mi_create_varobj VAR s "create varobj for s (without RTTI) in $testname"
99 mi_list_varobj_children VAR {
100 { VAR.public public 4 }
101 } "list children of s (without RTTI) in $testname"
102 mi_list_varobj_children VAR.public {
103 { VAR.public.ptr ptr 1 {Base \*} }
104 { VAR.public.constPtr constPtr 1 {const Base \*} }
105 { VAR.public.ptrConst ptrConst 1 {Base \* const} }
106 { VAR.public.constPtrConst constPtrConst 1 {const Base \* const} }
107 } "list children of s.public (without RTTI) in $testname"
108 check_derived_without_rtti VAR.public.ptr s.ptr $testname
109 check_derived_without_rtti VAR.public.constPtr s.constPtr $testname
110 check_derived_without_rtti VAR.public.ptrConst s.ptrConst $testname
111 check_derived_without_rtti VAR.public.constPtrConst s.constPtrConst \
113 mi_delete_varobj VAR "delete varobj for s (without RTTI) in $testname"
115 set_print_object on $testname
116 mi_create_varobj VAR s "create varobj for s (with RTTI) in $testname"
117 mi_list_varobj_children VAR {
118 { VAR.public public 4 }
119 } "list children of s (with RTTI) in $testname"
120 mi_list_varobj_children VAR.public {
121 { VAR.public.ptr ptr 2 {Derived \*} }
122 { VAR.public.constPtr constPtr 2 {const Derived \*} }
123 { VAR.public.ptrConst ptrConst 2 {Derived \* const} }
124 { VAR.public.constPtrConst constPtrConst 2 {const Derived \* const}}
125 } "list children of s.public (with RTTI) in $testname"
126 check_derived_with_rtti VAR.public.ptr s.ptr $testname
127 check_derived_with_rtti VAR.public.constPtr s.constPtr $testname
128 check_derived_with_rtti VAR.public.ptrConst s.ptrConst $testname
129 check_derived_with_rtti VAR.public.constPtrConst s.constPtrConst \
131 mi_delete_varobj VAR "delete varobj for s (with RTTI) in $testname"
134 /*: END: use_rtti_for_ptr_child :*/
138 void use_rtti_for_ref_child_test ()
140 /*: BEGIN: use_rtti_for_ref_child :*/
144 const Base& constRef;
150 set testname use_rtti_for_ref_child
152 set_print_object off $testname
153 mi_create_varobj VAR s "create varobj for s (without RTTI) in $testname"
154 mi_list_varobj_children VAR {
155 { VAR.public public 2 }
156 } "list children of s (without RTTI) in $testname"
157 mi_list_varobj_children VAR.public {
158 { VAR.public.ref ref 1 {Base \&} }
159 { VAR.public.constRef constRef 1 {const Base \&} }
160 } "list children of s.public (without RTTI) in $testname"
161 check_derived_without_rtti VAR.public.ref s.ref $testname
162 check_derived_without_rtti VAR.public.constRef s.constRef $testname
163 mi_delete_varobj VAR "delete varobj for s (without RTTI) in $testname"
165 set_print_object on $testname
166 mi_create_varobj VAR s "create varobj for s (with RTTI) in $testname"
167 mi_list_varobj_children VAR {
168 { VAR.public public 2 }
169 } "list children of s (with RTTI) in $testname"
170 mi_list_varobj_children VAR.public {
171 { VAR.public.ref ref 2 {Derived \&} }
172 { VAR.public.constRef constRef 2 {const Derived \&} }
173 } "list children of s.public (with RTTI) in $testname"
174 check_derived_with_rtti VAR.public.ref s.ref $testname
175 check_derived_with_rtti VAR.public.constRef s.constRef $testname
176 mi_delete_varobj VAR "delete varobj for s (with RTTI) in $testname"
179 /*: END: use_rtti_for_ref_child :*/
189 struct MultipleDerived : public First, Base {
190 MultipleDerived() : B(2), C(3) {}
196 void use_rtti_with_multiple_inheritence_test ()
198 /*: BEGIN: use_rtti_with_multiple_inheritence :*/
203 set testname use_rtti_with_multiple_inheritence
204 set_print_object off $testname
205 check_new_derived_without_rtti ptr {Base \*} $testname
206 check_new_derived_without_rtti ref {Base \&} $testname
208 set_print_object on $testname
209 mi_create_varobj_checked VAR ptr {MultipleDerived \*} \
210 "create varobj for ptr (with RTTI) in $testname"
211 mi_list_varobj_children VAR {
212 { VAR.First First 1 First }
213 { VAR.Base Base 1 Base }
214 { VAR.public public 2 }
215 } "list children of ptr (with RTTI) in $testname"
216 mi_list_varobj_children "VAR.First" {
217 { VAR.First.public public 1 }
218 } "list children of ptr.First (with RTTI) in $testname"
219 mi_list_varobj_children "VAR.First.public" {
220 { VAR.First.public.F F 0 int }
221 } "list children of ptr.Base.public (with RTTI) in $testname"
222 mi_list_varobj_children "VAR.Base" {
223 { VAR.Base.public public 1 }
224 } "list children of ptr.Base (with RTTI) in $testname"
225 mi_list_varobj_children "VAR.Base.public" {
226 { VAR.Base.public.A A 0 int }
227 } "list children of ptr.Base.public (with RTTI) in $testname"
228 mi_list_varobj_children "VAR.public" {
229 { VAR.public.B B 0 int }
230 { VAR.public.C C 0 int }
231 } "list children of ptr.public (with RTTI) in $testname"
233 mi_delete_varobj VAR \
234 "delete varobj for ptr (with RTTI) in $testname"
237 /*: END: use_rtti_with_multiple_inheritence :*/
241 void type_update_when_use_rtti_test ()
243 /*: BEGIN: type_update_when_use_rtti :*/
246 set testname type_update_when_use_rtti
248 set_print_object on $testname
249 mi_create_varobj_checked PTR ptr {Base \*} \
250 "create varobj for ptr in $testname"
251 check_derived_children_without_rtti PTR ptr $testname
253 mi_create_varobj S s "create varobj for S in $testname"
254 mi_list_varobj_children S {
255 { S.public public 1 }
256 } "list children of s in $testname"
257 mi_list_varobj_children S.public {
258 { S.public.ptr ptr 1 {Base \*} }
259 } "list children of s.public in $testname"
260 check_derived_children_without_rtti S.public.ptr s.ptr $testname
270 mi_varobj_update_with_type_change PTR {Derived \*} 2 \
271 "update ptr to derived in $testname"
272 check_derived_with_rtti PTR ptr $testname
274 mi_varobj_update_with_child_type_change S S.public.ptr {Derived \*} 2 \
275 "update s.ptr to derived in $testname"
276 check_derived_with_rtti S.public.ptr s.ptr $testname
282 mi_varobj_update_with_type_change PTR {Base \*} 1 \
283 "update ptr back to base type in $testname"
284 mi_delete_varobj PTR "delete varobj for ptr in $testname"
286 mi_varobj_update_with_child_type_change S S.public.ptr {Base \*} 1 \
287 "update s.ptr back to base type in $testname"
288 mi_delete_varobj S "delete varobj for s in $testname"
291 /*: END: type_update_when_use_rtti :*/
295 void skip_type_update_when_not_use_rtti_test ()
297 /*: BEGIN: skip_type_update_when_not_use_rtti :*/
300 set testname skip_type_update_when_not_use_rtti
302 set_print_object off $testname
303 mi_create_varobj_checked PTR ptr {Base \*} \
304 "create varobj for ptr in $testname"
305 check_derived_children_without_rtti PTR ptr $testname
307 mi_create_varobj S s "create varobj for S in $testname"
308 mi_list_varobj_children S {
309 { S.public public 1 }
310 } "list children of s in $testname"
311 mi_list_varobj_children S.public {
312 { S.public.ptr ptr 1 {Base \*} }
313 } "list children of s.public in $testname"
314 check_derived_children_without_rtti S.public.ptr s.ptr $testname
324 mi_varobj_update PTR {PTR PTR.public.A} \
325 "update ptr to derived type in $testname"
326 check_derived_without_rtti PTR ptr $testname
328 mi_varobj_update S {S.public.ptr S.public.ptr.public.A} \
329 "update s to derived type in $testname"
330 check_derived_without_rtti S.public.ptr s.ptr $testname
336 mi_varobj_update PTR {PTR PTR.public.A} \
337 "update ptr back to base type in $testname"
338 mi_delete_varobj PTR "delete varobj for ptr in $testname"
340 mi_varobj_update S {S.public.ptr S.public.ptr.public.A} \
341 "update s back to base type in $testname"
342 mi_delete_varobj S "delete varobj for s in $testname"
345 /*: END: skip_type_update_when_not_use_rtti :*/
351 use_rtti_for_ptr_test();
352 use_rtti_for_ref_test();
353 use_rtti_for_ptr_child_test();
354 use_rtti_for_ref_child_test();
355 use_rtti_with_multiple_inheritence_test();
356 type_update_when_use_rtti_test();
357 skip_type_update_when_not_use_rtti_test();