Home | History | Annotate | Line # | Download | only in gdb.mi
mi-var-rtti.cc revision 1.1
      1  1.1  christos /* Copyright 2012-2014 Free Software Foundation, Inc.
      2  1.1  christos 
      3  1.1  christos    This program is free software; you can redistribute it and/or modify
      4  1.1  christos    it under the terms of the GNU General Public License as published by
      5  1.1  christos    the Free Software Foundation; either version 3 of the License, or
      6  1.1  christos    (at your option) any later version.
      7  1.1  christos 
      8  1.1  christos    This program is distributed in the hope that it will be useful,
      9  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  1.1  christos    GNU General Public License for more details.
     12  1.1  christos 
     13  1.1  christos    You should have received a copy of the GNU General Public License
     14  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     15  1.1  christos 
     16  1.1  christos struct Base {
     17  1.1  christos     Base() : A(1) {}
     18  1.1  christos     virtual ~Base() {}  // Enforce type to have vtable
     19  1.1  christos     int A;
     20  1.1  christos };
     21  1.1  christos 
     22  1.1  christos struct Derived : public Base {
     23  1.1  christos     Derived() : B(2), C(3) {}
     24  1.1  christos     int B;
     25  1.1  christos     int C;
     26  1.1  christos };
     27  1.1  christos 
     28  1.1  christos 
     29  1.1  christos void use_rtti_for_ptr_test ()
     30  1.1  christos {
     31  1.1  christos   /*: BEGIN: use_rtti_for_ptr :*/
     32  1.1  christos 	Derived d;
     33  1.1  christos 	Base* ptr = &d;
     34  1.1  christos 	const Base* constPtr = &d;
     35  1.1  christos 	Base* const ptrConst = &d;
     36  1.1  christos 	Base const* const constPtrConst = &d;
     37  1.1  christos   /*:
     38  1.1  christos 	set testname use_rtti_for_ptr
     39  1.1  christos 	set_print_object off $testname
     40  1.1  christos 	check_new_derived_without_rtti ptr {Base \*} $testname
     41  1.1  christos 	check_new_derived_without_rtti constPtr {const Base \*} $testname
     42  1.1  christos 	check_new_derived_without_rtti ptrConst {Base \* const} $testname
     43  1.1  christos 	check_new_derived_without_rtti constPtrConst {const Base \* const} \
     44  1.1  christos 		$testname
     45  1.1  christos 
     46  1.1  christos 	set_print_object on $testname
     47  1.1  christos 	check_new_derived_with_rtti ptr {Derived \*} $testname
     48  1.1  christos 	check_new_derived_with_rtti constPtr {const Derived \*} $testname
     49  1.1  christos 	check_new_derived_with_rtti ptrConst {Derived \* const} $testname
     50  1.1  christos 	check_new_derived_with_rtti constPtrConst {const Derived \* const} \
     51  1.1  christos 		$testname
     52  1.1  christos   :*/
     53  1.1  christos 	return;
     54  1.1  christos   /*: END: use_rtti_for_ptr :*/
     55  1.1  christos }
     56  1.1  christos 
     57  1.1  christos 
     58  1.1  christos void use_rtti_for_ref_test ()
     59  1.1  christos {
     60  1.1  christos   /*: BEGIN: use_rtti_for_ref :*/
     61  1.1  christos 	Derived d;
     62  1.1  christos 	Base& ref = d;
     63  1.1  christos 	const Base& constRef = d;
     64  1.1  christos   /*:
     65  1.1  christos 	set testname use_rtti_for_ref
     66  1.1  christos 	set_print_object off $testname
     67  1.1  christos 	check_new_derived_without_rtti ref {Base \&} $testname
     68  1.1  christos 	check_new_derived_without_rtti constRef {const Base \&} $testname
     69  1.1  christos 
     70  1.1  christos 	set_print_object on $testname
     71  1.1  christos 	check_new_derived_with_rtti ref {Derived \&} $testname
     72  1.1  christos 	check_new_derived_with_rtti constRef {const Derived \&} $testname
     73  1.1  christos   :*/
     74  1.1  christos 	return;
     75  1.1  christos   /*: END: use_rtti_for_ref :*/
     76  1.1  christos }
     77  1.1  christos 
     78  1.1  christos 
     79  1.1  christos void use_rtti_for_ptr_child_test ()
     80  1.1  christos {
     81  1.1  christos   /*: BEGIN: use_rtti_for_ptr_child :*/
     82  1.1  christos 	Derived d;
     83  1.1  christos 	struct S {
     84  1.1  christos 		Base* ptr;
     85  1.1  christos 		const Base* constPtr;
     86  1.1  christos 		Base* const ptrConst;
     87  1.1  christos 		Base const* const constPtrConst;
     88  1.1  christos 		S ( Base* v ) :
     89  1.1  christos 			ptr ( v ),
     90  1.1  christos 			constPtr ( v ),
     91  1.1  christos 			ptrConst ( v ),
     92  1.1  christos 			constPtrConst ( v ) {}
     93  1.1  christos 	} s ( &d );
     94  1.1  christos   /*:
     95  1.1  christos 	set testname use_rtti_for_ptr_child
     96  1.1  christos 
     97  1.1  christos 	set_print_object off $testname
     98  1.1  christos 	mi_create_varobj VAR s "create varobj for s (without RTTI) in $testname"
     99  1.1  christos 	mi_list_varobj_children VAR {
    100  1.1  christos 	    { VAR.public public 4 }
    101  1.1  christos 	} "list children of s (without RTTI) in $testname"
    102  1.1  christos 	mi_list_varobj_children VAR.public {
    103  1.1  christos 	    { VAR.public.ptr ptr 1 {Base \*} }
    104  1.1  christos 	    { VAR.public.constPtr constPtr 1 {const Base \*} }
    105  1.1  christos 	    { VAR.public.ptrConst ptrConst 1 {Base \* const} }
    106  1.1  christos 	    { VAR.public.constPtrConst constPtrConst 1 {const Base \* const} }
    107  1.1  christos 	} "list children of s.public (without RTTI) in $testname"
    108  1.1  christos 	check_derived_without_rtti VAR.public.ptr s.ptr $testname
    109  1.1  christos 	check_derived_without_rtti VAR.public.constPtr s.constPtr $testname
    110  1.1  christos 	check_derived_without_rtti VAR.public.ptrConst s.ptrConst $testname
    111  1.1  christos 	check_derived_without_rtti VAR.public.constPtrConst s.constPtrConst \
    112  1.1  christos 		$testname
    113  1.1  christos 	mi_delete_varobj VAR "delete varobj for s (without RTTI) in $testname"
    114  1.1  christos 
    115  1.1  christos 	set_print_object on $testname
    116  1.1  christos 	mi_create_varobj VAR s "create varobj for s (with RTTI) in $testname"
    117  1.1  christos 	mi_list_varobj_children VAR {
    118  1.1  christos 	    { VAR.public public 4 }
    119  1.1  christos 	} "list children of s (with RTTI) in $testname"
    120  1.1  christos 	mi_list_varobj_children VAR.public {
    121  1.1  christos 	    { VAR.public.ptr ptr 2 {Derived \*} }
    122  1.1  christos 	    { VAR.public.constPtr constPtr 2 {const Derived \*} }
    123  1.1  christos 	    { VAR.public.ptrConst ptrConst 2 {Derived \* const} }
    124  1.1  christos 	    { VAR.public.constPtrConst constPtrConst 2 {const Derived \* const}}
    125  1.1  christos 	} "list children of s.public (with RTTI) in $testname"
    126  1.1  christos 	check_derived_with_rtti VAR.public.ptr s.ptr $testname
    127  1.1  christos 	check_derived_with_rtti VAR.public.constPtr s.constPtr $testname
    128  1.1  christos 	check_derived_with_rtti VAR.public.ptrConst s.ptrConst $testname
    129  1.1  christos 	check_derived_with_rtti VAR.public.constPtrConst s.constPtrConst \
    130  1.1  christos 		$testname
    131  1.1  christos 	mi_delete_varobj VAR "delete varobj for s (with RTTI) in $testname"
    132  1.1  christos   :*/
    133  1.1  christos 	return;
    134  1.1  christos   /*: END: use_rtti_for_ptr_child :*/
    135  1.1  christos }
    136  1.1  christos 
    137  1.1  christos 
    138  1.1  christos void use_rtti_for_ref_child_test ()
    139  1.1  christos {
    140  1.1  christos   /*: BEGIN: use_rtti_for_ref_child :*/
    141  1.1  christos 	Derived d;
    142  1.1  christos 	struct S {
    143  1.1  christos 		Base& ref;
    144  1.1  christos 		const Base& constRef;
    145  1.1  christos 		S ( Base& v ) :
    146  1.1  christos 			ref ( v ),
    147  1.1  christos 			constRef ( v ) {}
    148  1.1  christos 	} s ( d );
    149  1.1  christos   /*:
    150  1.1  christos 	set testname use_rtti_for_ref_child
    151  1.1  christos 
    152  1.1  christos 	set_print_object off $testname
    153  1.1  christos 	mi_create_varobj VAR s "create varobj for s (without RTTI) in $testname"
    154  1.1  christos 	mi_list_varobj_children VAR {
    155  1.1  christos 	    { VAR.public public 2 }
    156  1.1  christos 	} "list children of s (without RTTI) in $testname"
    157  1.1  christos 	mi_list_varobj_children VAR.public {
    158  1.1  christos 	    { VAR.public.ref ref 1 {Base \&} }
    159  1.1  christos 	    { VAR.public.constRef constRef 1 {const Base \&} }
    160  1.1  christos 	} "list children of s.public (without RTTI) in $testname"
    161  1.1  christos 	check_derived_without_rtti VAR.public.ref s.ref $testname
    162  1.1  christos 	check_derived_without_rtti VAR.public.constRef s.constRef  $testname
    163  1.1  christos 	mi_delete_varobj VAR "delete varobj for s (without RTTI) in $testname"
    164  1.1  christos 
    165  1.1  christos 	set_print_object on $testname
    166  1.1  christos 	mi_create_varobj VAR s "create varobj for s (with RTTI) in $testname"
    167  1.1  christos 	mi_list_varobj_children VAR {
    168  1.1  christos 	    { VAR.public public 2 }
    169  1.1  christos 	} "list children of s (with RTTI) in $testname"
    170  1.1  christos 	mi_list_varobj_children VAR.public {
    171  1.1  christos 	    { VAR.public.ref ref 2 {Derived \&} }
    172  1.1  christos 	    { VAR.public.constRef constRef 2 {const Derived \&} }
    173  1.1  christos 	} "list children of s.public (with RTTI) in $testname"
    174  1.1  christos 	check_derived_with_rtti VAR.public.ref s.ref $testname
    175  1.1  christos 	check_derived_with_rtti VAR.public.constRef s.constRef $testname
    176  1.1  christos 	mi_delete_varobj VAR "delete varobj for s (with RTTI) in $testname"
    177  1.1  christos   :*/
    178  1.1  christos 	return;
    179  1.1  christos   /*: END: use_rtti_for_ref_child :*/
    180  1.1  christos }
    181  1.1  christos 
    182  1.1  christos 
    183  1.1  christos struct First {
    184  1.1  christos     First() : F(-1) {}
    185  1.1  christos     int F;
    186  1.1  christos };
    187  1.1  christos 
    188  1.1  christos 
    189  1.1  christos struct MultipleDerived : public First, Base {
    190  1.1  christos     MultipleDerived() : B(2), C(3) {}
    191  1.1  christos     int B;
    192  1.1  christos     int C;
    193  1.1  christos };
    194  1.1  christos 
    195  1.1  christos 
    196  1.1  christos void use_rtti_with_multiple_inheritence_test ()
    197  1.1  christos {
    198  1.1  christos   /*: BEGIN: use_rtti_with_multiple_inheritence :*/
    199  1.1  christos 	MultipleDerived d;
    200  1.1  christos 	Base* ptr = &d;
    201  1.1  christos 	Base& ref = d;
    202  1.1  christos   /*:
    203  1.1  christos 	set testname use_rtti_with_multiple_inheritence
    204  1.1  christos 	set_print_object off $testname
    205  1.1  christos 	check_new_derived_without_rtti ptr {Base \*} $testname
    206  1.1  christos 	check_new_derived_without_rtti ref {Base \&} $testname
    207  1.1  christos 
    208  1.1  christos 	set_print_object on $testname
    209  1.1  christos 	mi_create_varobj_checked VAR ptr {MultipleDerived \*} \
    210  1.1  christos 	    "create varobj for ptr (with RTTI) in $testname"
    211  1.1  christos 	mi_list_varobj_children VAR {
    212  1.1  christos 	    { VAR.First First 1 First }
    213  1.1  christos 	    { VAR.Base Base 1 Base }
    214  1.1  christos 	    { VAR.public public 2 }
    215  1.1  christos 	} "list children of ptr (with RTTI) in $testname"
    216  1.1  christos 	mi_list_varobj_children "VAR.First" {
    217  1.1  christos 	    { VAR.First.public public 1 }
    218  1.1  christos 	} "list children of ptr.First (with RTTI) in $testname"
    219  1.1  christos 	mi_list_varobj_children "VAR.First.public" {
    220  1.1  christos 	    { VAR.First.public.F F 0 int }
    221  1.1  christos 	} "list children of ptr.Base.public (with RTTI) in $testname"
    222  1.1  christos 	mi_list_varobj_children "VAR.Base" {
    223  1.1  christos 	    { VAR.Base.public public 1 }
    224  1.1  christos 	} "list children of ptr.Base (with RTTI) in $testname"
    225  1.1  christos 	mi_list_varobj_children "VAR.Base.public" {
    226  1.1  christos 	    { VAR.Base.public.A A 0 int }
    227  1.1  christos 	} "list children of ptr.Base.public (with RTTI) in $testname"
    228  1.1  christos 	mi_list_varobj_children "VAR.public" {
    229  1.1  christos 	    { VAR.public.B B 0 int }
    230  1.1  christos 	    { VAR.public.C C 0 int }
    231  1.1  christos 	} "list children of ptr.public (with RTTI) in $testname"
    232  1.1  christos 
    233  1.1  christos 	mi_delete_varobj VAR \
    234  1.1  christos 	    "delete varobj for ptr (with RTTI) in $testname"
    235  1.1  christos   :*/
    236  1.1  christos 	return;
    237  1.1  christos   /*: END: use_rtti_with_multiple_inheritence :*/
    238  1.1  christos }
    239  1.1  christos 
    240  1.1  christos 
    241  1.1  christos void type_update_when_use_rtti_test ()
    242  1.1  christos {
    243  1.1  christos   /*: BEGIN: type_update_when_use_rtti :*/
    244  1.1  christos 	Derived d;
    245  1.1  christos   /*:
    246  1.1  christos 	set testname type_update_when_use_rtti
    247  1.1  christos 
    248  1.1  christos 	set_print_object on $testname
    249  1.1  christos 	mi_create_varobj_checked PTR ptr {Base \*} \
    250  1.1  christos 		"create varobj for ptr in $testname"
    251  1.1  christos 	check_derived_children_without_rtti PTR ptr $testname
    252  1.1  christos 
    253  1.1  christos 	mi_create_varobj S s "create varobj for S in $testname"
    254  1.1  christos 	mi_list_varobj_children S {
    255  1.1  christos 	    { S.public public 1 }
    256  1.1  christos 	} "list children of s in $testname"
    257  1.1  christos 	mi_list_varobj_children S.public {
    258  1.1  christos 	    { S.public.ptr ptr 1 {Base \*} }
    259  1.1  christos 	} "list children of s.public in $testname"
    260  1.1  christos 	check_derived_children_without_rtti S.public.ptr s.ptr $testname
    261  1.1  christos   :*/
    262  1.1  christos 
    263  1.1  christos 	Base* ptr = &d;
    264  1.1  christos 	struct S {
    265  1.1  christos 		Base* ptr;
    266  1.1  christos 		S ( Base* v ) :
    267  1.1  christos 			ptr ( v ) {}
    268  1.1  christos 	} s ( &d );
    269  1.1  christos   /*:
    270  1.1  christos 	mi_varobj_update_with_type_change PTR {Derived \*} 2 \
    271  1.1  christos 		"update ptr to derived in $testname"
    272  1.1  christos 	check_derived_with_rtti PTR ptr $testname
    273  1.1  christos 
    274  1.1  christos 	mi_varobj_update_with_child_type_change S S.public.ptr {Derived \*} 2 \
    275  1.1  christos 		"update s.ptr to derived in $testname"
    276  1.1  christos 	check_derived_with_rtti S.public.ptr s.ptr $testname
    277  1.1  christos   :*/
    278  1.1  christos 
    279  1.1  christos 	ptr = 0;
    280  1.1  christos 	s.ptr = 0;
    281  1.1  christos   /*:
    282  1.1  christos 	mi_varobj_update_with_type_change PTR {Base \*} 1 \
    283  1.1  christos 		"update ptr back to base type in $testname"
    284  1.1  christos 	mi_delete_varobj PTR "delete varobj for ptr in $testname"
    285  1.1  christos 
    286  1.1  christos 	mi_varobj_update_with_child_type_change S S.public.ptr {Base \*} 1 \
    287  1.1  christos 		"update s.ptr back to base type in $testname"
    288  1.1  christos 	mi_delete_varobj S "delete varobj for s in $testname"
    289  1.1  christos   :*/
    290  1.1  christos 	return;
    291  1.1  christos   /*: END: type_update_when_use_rtti :*/
    292  1.1  christos }
    293  1.1  christos 
    294  1.1  christos 
    295  1.1  christos void skip_type_update_when_not_use_rtti_test ()
    296  1.1  christos {
    297  1.1  christos   /*: BEGIN: skip_type_update_when_not_use_rtti :*/
    298  1.1  christos 	Derived d;
    299  1.1  christos   /*:
    300  1.1  christos 	set testname skip_type_update_when_not_use_rtti
    301  1.1  christos 
    302  1.1  christos 	set_print_object off $testname
    303  1.1  christos 	mi_create_varobj_checked PTR ptr {Base \*} \
    304  1.1  christos 		"create varobj for ptr in $testname"
    305  1.1  christos 	check_derived_children_without_rtti PTR ptr $testname
    306  1.1  christos 
    307  1.1  christos 	mi_create_varobj S s "create varobj for S in $testname"
    308  1.1  christos 	mi_list_varobj_children S {
    309  1.1  christos 	    { S.public public 1 }
    310  1.1  christos 	} "list children of s in $testname"
    311  1.1  christos 	mi_list_varobj_children S.public {
    312  1.1  christos 	    { S.public.ptr ptr 1 {Base \*} }
    313  1.1  christos 	} "list children of s.public in $testname"
    314  1.1  christos 	check_derived_children_without_rtti S.public.ptr s.ptr $testname
    315  1.1  christos   :*/
    316  1.1  christos 
    317  1.1  christos 	Base* ptr = &d;
    318  1.1  christos 	struct S {
    319  1.1  christos 		Base* ptr;
    320  1.1  christos 		S ( Base* v ) :
    321  1.1  christos 			ptr ( v ) {}
    322  1.1  christos 	} s ( &d );
    323  1.1  christos   /*:
    324  1.1  christos 	mi_varobj_update PTR {PTR PTR.public.A} \
    325  1.1  christos 		"update ptr to derived type in $testname"
    326  1.1  christos 	check_derived_without_rtti PTR ptr $testname
    327  1.1  christos 
    328  1.1  christos 	mi_varobj_update S {S.public.ptr S.public.ptr.public.A} \
    329  1.1  christos 		"update s to derived type in $testname"
    330  1.1  christos 	check_derived_without_rtti S.public.ptr s.ptr $testname
    331  1.1  christos   :*/
    332  1.1  christos 
    333  1.1  christos 	ptr = 0;
    334  1.1  christos 	s.ptr = 0;
    335  1.1  christos   /*:
    336  1.1  christos 	mi_varobj_update PTR {PTR  PTR.public.A} \
    337  1.1  christos 		"update ptr back to base type in $testname"
    338  1.1  christos 	mi_delete_varobj PTR "delete varobj for ptr in $testname"
    339  1.1  christos 
    340  1.1  christos 	mi_varobj_update S {S.public.ptr S.public.ptr.public.A} \
    341  1.1  christos 		"update s back to base type in $testname"
    342  1.1  christos 	mi_delete_varobj S "delete varobj for s in $testname"
    343  1.1  christos   :*/
    344  1.1  christos 	return;
    345  1.1  christos   /*: END: skip_type_update_when_not_use_rtti :*/
    346  1.1  christos }
    347  1.1  christos 
    348  1.1  christos 
    349  1.1  christos int main ()
    350  1.1  christos {
    351  1.1  christos 	use_rtti_for_ptr_test();
    352  1.1  christos 	use_rtti_for_ref_test();
    353  1.1  christos 	use_rtti_for_ptr_child_test();
    354  1.1  christos 	use_rtti_for_ref_child_test();
    355  1.1  christos 	use_rtti_with_multiple_inheritence_test();
    356  1.1  christos 	type_update_when_use_rtti_test();
    357  1.1  christos 	skip_type_update_when_not_use_rtti_test();
    358  1.1  christos 	return 0;
    359  1.1  christos }
    360