Home | History | Annotate | Line # | Download | only in gdb.mi
      1  1.11  christos /* Copyright 2012-2024 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.10  christos 	} "list children of ptr.First.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.3  christos 	Base *ptr = 0;
    245   1.3  christos 	struct S {
    246   1.3  christos 		Base* ptr;
    247   1.3  christos 		S ( Base* v ) :
    248   1.3  christos 			ptr ( v ) {}
    249   1.3  christos 	} s ( ptr );
    250   1.1  christos 	Derived d;
    251   1.1  christos   /*:
    252   1.1  christos 	set testname type_update_when_use_rtti
    253   1.1  christos 
    254   1.1  christos 	set_print_object on $testname
    255   1.1  christos 	mi_create_varobj_checked PTR ptr {Base \*} \
    256   1.1  christos 		"create varobj for ptr in $testname"
    257   1.1  christos 	check_derived_children_without_rtti PTR ptr $testname
    258   1.1  christos 
    259   1.1  christos 	mi_create_varobj S s "create varobj for S in $testname"
    260   1.1  christos 	mi_list_varobj_children S {
    261   1.1  christos 	    { S.public public 1 }
    262   1.1  christos 	} "list children of s in $testname"
    263   1.1  christos 	mi_list_varobj_children S.public {
    264   1.1  christos 	    { S.public.ptr ptr 1 {Base \*} }
    265   1.1  christos 	} "list children of s.public in $testname"
    266   1.1  christos 	check_derived_children_without_rtti S.public.ptr s.ptr $testname
    267   1.1  christos   :*/
    268   1.1  christos 
    269   1.3  christos 	ptr = &d;
    270   1.3  christos 	s.ptr = &d;
    271   1.1  christos   /*:
    272   1.1  christos 	mi_varobj_update_with_type_change PTR {Derived \*} 2 \
    273   1.1  christos 		"update ptr to derived in $testname"
    274   1.1  christos 	check_derived_with_rtti PTR ptr $testname
    275   1.1  christos 
    276   1.1  christos 	mi_varobj_update_with_child_type_change S S.public.ptr {Derived \*} 2 \
    277   1.1  christos 		"update s.ptr to derived in $testname"
    278   1.1  christos 	check_derived_with_rtti S.public.ptr s.ptr $testname
    279   1.1  christos   :*/
    280   1.1  christos 
    281   1.1  christos 	ptr = 0;
    282   1.1  christos 	s.ptr = 0;
    283   1.1  christos   /*:
    284   1.1  christos 	mi_varobj_update_with_type_change PTR {Base \*} 1 \
    285   1.1  christos 		"update ptr back to base type in $testname"
    286   1.1  christos 	mi_delete_varobj PTR "delete varobj for ptr in $testname"
    287   1.1  christos 
    288   1.1  christos 	mi_varobj_update_with_child_type_change S S.public.ptr {Base \*} 1 \
    289   1.1  christos 		"update s.ptr back to base type in $testname"
    290   1.1  christos 	mi_delete_varobj S "delete varobj for s in $testname"
    291   1.1  christos   :*/
    292   1.1  christos 	return;
    293   1.1  christos   /*: END: type_update_when_use_rtti :*/
    294   1.1  christos }
    295   1.1  christos 
    296   1.1  christos 
    297   1.1  christos void skip_type_update_when_not_use_rtti_test ()
    298   1.1  christos {
    299   1.1  christos   /*: BEGIN: skip_type_update_when_not_use_rtti :*/
    300   1.3  christos 	Base *ptr = 0;
    301   1.3  christos 	struct S {
    302   1.3  christos 		Base* ptr;
    303   1.3  christos 		S ( Base* v ) :
    304   1.3  christos 			ptr ( v ) {}
    305   1.3  christos 	} s ( ptr );
    306   1.1  christos 	Derived d;
    307   1.1  christos   /*:
    308   1.1  christos 	set testname skip_type_update_when_not_use_rtti
    309   1.1  christos 
    310  1.10  christos 	with_test_prefix "ptr is nullptr" {
    311  1.10  christos 	  set_print_object off $testname
    312  1.10  christos 	  mi_create_varobj_checked PTR ptr {Base \*} \
    313   1.1  christos 		"create varobj for ptr in $testname"
    314  1.10  christos 	  check_derived_children_without_rtti PTR ptr $testname
    315   1.1  christos 
    316  1.10  christos 	  mi_create_varobj S s "create varobj for S in $testname"
    317  1.10  christos 	  mi_list_varobj_children S {
    318  1.10  christos 	      { S.public public 1 }
    319  1.10  christos 	  } "list children of s in $testname"
    320  1.10  christos 	  mi_list_varobj_children S.public {
    321  1.10  christos 	      { S.public.ptr ptr 1 {Base \*} }
    322  1.10  christos 	  } "list children of s.public in $testname"
    323  1.10  christos 	  check_derived_children_without_rtti S.public.ptr s.ptr $testname
    324  1.10  christos 	}
    325   1.1  christos   :*/
    326   1.1  christos 
    327   1.3  christos 	ptr = &d;
    328   1.3  christos 	s.ptr = &d;
    329   1.1  christos   /*:
    330  1.10  christos         with_test_prefix "ptr points at d" {
    331  1.10  christos 	  mi_varobj_update PTR {PTR PTR.public.A} \
    332   1.1  christos 		"update ptr to derived type in $testname"
    333  1.10  christos 	  check_derived_without_rtti PTR ptr $testname
    334   1.1  christos 
    335  1.10  christos 	  mi_varobj_update S {S.public.ptr S.public.ptr.public.A} \
    336   1.1  christos 		"update s to derived type in $testname"
    337  1.10  christos 	  check_derived_without_rtti S.public.ptr s.ptr $testname
    338  1.10  christos 	}
    339   1.1  christos   :*/
    340   1.1  christos 
    341   1.1  christos 	ptr = 0;
    342   1.1  christos 	s.ptr = 0;
    343   1.1  christos   /*:
    344  1.10  christos         with_test_prefix "ptr is nullptr again" {
    345  1.10  christos 	  mi_varobj_update PTR {PTR  PTR.public.A} \
    346   1.1  christos 		"update ptr back to base type in $testname"
    347  1.10  christos 	  mi_delete_varobj PTR "delete varobj for ptr in $testname"
    348   1.1  christos 
    349  1.10  christos 	  mi_varobj_update S {S.public.ptr S.public.ptr.public.A} \
    350   1.1  christos 		"update s back to base type in $testname"
    351  1.10  christos 	  mi_delete_varobj S "delete varobj for s in $testname"
    352  1.10  christos 	}
    353   1.1  christos   :*/
    354   1.1  christos 	return;
    355   1.1  christos   /*: END: skip_type_update_when_not_use_rtti :*/
    356   1.1  christos }
    357   1.1  christos 
    358   1.1  christos 
    359   1.1  christos int main ()
    360   1.1  christos {
    361   1.1  christos 	use_rtti_for_ptr_test();
    362   1.1  christos 	use_rtti_for_ref_test();
    363   1.1  christos 	use_rtti_for_ptr_child_test();
    364   1.1  christos 	use_rtti_for_ref_child_test();
    365   1.1  christos 	use_rtti_with_multiple_inheritence_test();
    366   1.1  christos 	type_update_when_use_rtti_test();
    367   1.1  christos 	skip_type_update_when_not_use_rtti_test();
    368   1.1  christos 	return 0;
    369   1.1  christos }
    370