1 /* Copyright 2006-2021 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/>. */
16 void reference_update_tests ()
18 /*: BEGIN: reference_update :*/
20 /*: mi_create_varobj "RX" "rx" "create varobj for rx" :*/
22 /*: mi_varobj_update RX {RX} "update RX (1)"
23 mi_check_varobj_value RX 167 "check RX: expect 167"
26 /*: mi_varobj_update RX {RX} "update RX (2)"
27 mi_check_varobj_value RX 567 "check RX: expect 567"
30 /*: mi_varobj_update RX {} "update RX (3)"
31 mi_delete_varobj RX "delete RX"
33 /* Dummy assignment to keep 'x' in scope. */
36 /*: END: reference_update :*/
39 struct S
{ int i
; int j
; };
42 int base_in_reference_test (S2
& s2
)
44 /*: BEGIN: base_in_reference :*/
47 mi_create_varobj "S2" "s2" "create varobj for s2"
48 mi_list_varobj_children "S2" {
50 } "list children of s2"
51 mi_list_varobj_children "S2.S" {
52 {"S2.S.public" "public" "2"}
53 } "list children of s2.s"
54 mi_list_varobj_children "S2.S.public" {
55 {"S2.S.public.i" "i" "0" "int"}
56 {"S2.S.public.j" "j" "0" "int"}
57 } "list children of s2.s.public"
59 mi_check_varobj_value "S2.S.public.i" "67" "check S2.S.public.i"
60 mi_check_varobj_value "S2.S.public.j" "89" "check S2.S.public.j"
61 mi_delete_varobj S2 "delete S2"
64 /*: END: base_in_reference :*/
67 void base_in_reference_test_main ()
72 base_in_reference_test (s
);
75 int reference_to_pointer ()
77 /*: BEGIN: reference_to_pointer :*/
78 S s
, *ptr_s
, *& rptr_s
= ptr_s
;
83 mi_create_varobj RPTR rptr_s "create varobj for rptr_s"
85 mi_list_varobj_children RPTR {{RPTR.public public 2}} \
86 "list public child of RPTR"
88 mi_list_varobj_children RPTR.public \
89 {{RPTR.public.i i 0 int}
90 {RPTR.public.j j 0 int}} "list children of reference to pointer"
92 mi_check_varobj_value RPTR.public.i 67 "check i member"
93 mi_check_varobj_value RPTR.public.j 89 "check j member"
94 mi_delete_varobj RPTR "delete RPTR"
97 /*: END: reference_to_pointer :*/
100 int reference_to_struct ()
102 /*: BEGIN: reference_to_struct :*/
106 mi_create_varobj S s "create varobj for s"
107 mi_create_varobj R r "create varobj for s"
108 mi_gdb_test "-var-show-attributes S" \
109 "\\^done,attr=\"noneditable\"" \
110 "check attributes of S"
111 mi_gdb_test "-var-show-attributes R" \
112 "\\^done,attr=\"noneditable\"" \
113 "check attributes of R"
116 /*: mi_varobj_update * [] "-var-update should not list structure varobjs"
119 /*: END: reference_to_struct :*/
132 struct Derived
: public Base1
, public Base2
137 /* Test for the -var-info-path-expression command. Although
138 said command is not specific to C++, it's of more importance
139 to C++ than to C, so we test it in mi-var-cp test. */
140 int path_expression ()
142 /*: BEGIN: path_expression :*/
145 /*: mi_create_varobj IP ip "create varobj for ip"
146 mi_list_varobj_children IP {{IP.\\*ip \\*ip 0 int}} "list children of IP"
147 mi_gdb_test "-var-info-path-expression IP.*ip" \
148 "\\^done,path_expr=\"\\*\\(ip\\)\"" \
149 "-var-info-path-expression IP.*ip"
153 /*: mi_create_varobj DP dp "create varobj for dp"
154 mi_list_varobj_children DP \
155 {{DP.Base1 Base1 1 Base1} \
156 {DP.Base2 Base2 1 Base2} \
157 {DP.public public 1}} "list children of DP"
158 mi_gdb_test "-var-info-path-expression DP.Base1" \
159 "\\^done,path_expr=\"\\(\\*\\(class Base1\\*\\) dp\\)\"" \
160 "-var-info-path-expression DP.Base1"
161 mi_list_varobj_children DP.public { \
162 {DP.public.i i 0 int} \
163 } "list children of DP.public"
164 mi_gdb_test "-var-info-path-expression DP.public.i" \
165 "\\^done,path_expr=\"\\(\\(dp\\)->i\\)\"" \
166 "-var-info-path-expression DP.public.i"
167 mi_list_varobj_children DP.Base1 { \
168 {DP.Base1.public public 1} \
169 } "list children of DP.Base1"
170 mi_list_varobj_children DP.Base1.public { \
171 {DP.Base1.public.i i 0 int} \
172 } "list children of DP.Base1.public"
173 mi_gdb_test "-var-info-path-expression DP.Base1.public.i" \
174 "\\^done,path_expr=\"\\(\\(\\(\\*\\(class Base1\\*\\) dp\\)\\).i\\)\"" \
175 "-var-info-path-expression DP.Base1.public.i"
177 mi_gdb_test "-var-info-path-expression DP.public" \
178 "\\^done,path_expr=\"\"" \
179 "-var-info-path-expression DP.public"
181 mi_create_varobj D d "create varobj for d"
182 mi_list_varobj_children D \
183 {{D.Base1 Base1 1 Base1} \
184 {D.Base2 Base2 1 Base2} \
185 {D.public public 1}} "list children of D"
186 mi_gdb_test "-var-info-path-expression D.Base1" \
187 "\\^done,path_expr=\"\\(\\(class Base1\\) d\\)\"" \
188 "-var-info-path-expression D.Base1"
190 int array
[4] = {1,2,3};
192 /*: mi_create_varobj A array "create varobj for array"
193 mi_list_varobj_children A { \
197 {A.3 3 0 int}} "list children of A"
198 mi_gdb_test "-var-info-path-expression A.2" \
199 "\\^done,path_expr=\"\\(array\\)\\\[2\\\]\"" \
200 "-var-info-path-expression A.2"
204 /*: END: path_expression :*/
210 struct { /* index: 0 */
213 struct { /* index: 1 */
216 struct { /* index: 2 */
218 struct { /* index: 1 */
220 struct { /* index: 0 */
222 union { /* index: 0 */
227 union { /* index: 0 */
235 /* Test anonymous structs and unions. */
237 anonymous_structs_and_unions (void)
249 return 0; /* anonymous_structs_and_unions */
254 reference_update_tests ();
255 base_in_reference_test_main ();
256 reference_to_pointer ();
257 reference_to_struct ();
259 anonymous_structs_and_unions ();