]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.mi/mi-var-cp.cc
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-var-cp.cc
CommitLineData
8acc9f48 1/* Copyright 2006-2013 Free Software Foundation, Inc.
b26ed50d
VP
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
a9762ec7 5 the Free Software Foundation; either version 3 of the License, or
b26ed50d 6 (at your option) any later version.
a9762ec7 7
b26ed50d
VP
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.
a9762ec7 12
b26ed50d 13 You should have received a copy of the GNU General Public License
a9762ec7 14 along with this program. If not, see <http://www.gnu.org/licenses/>.
b26ed50d
VP
15*/
16
17void reference_update_tests ()
18{
2d0720d9 19 /*: BEGIN: reference_update :*/
b26ed50d 20 int x = 167;
2d0720d9 21 /*: mi_create_varobj "RX" "rx" "create varobj for rx" :*/
b26ed50d 22 int& rx = x;
2d0720d9
VP
23 /*: mi_varobj_update RX {RX} "update RX (1)"
24 mi_check_varobj_value RX 167 "check RX: expect 167"
25 :*/
b26ed50d 26 x = 567;
2d0720d9
VP
27 /*: mi_varobj_update RX {RX} "update RX (2)"
28 mi_check_varobj_value RX 567 "check RX: expect 567"
29 :*/
b26ed50d 30 x = 567;
2d0720d9 31 /*: mi_varobj_update RX {} "update RX (3)"
6e2a9270 32 mi_delete_varobj RX "delete RX"
2d0720d9 33 :*/
81121995
VP
34 /* Dummy assignment to keep 'x' in scope. */
35 x = 444;
2d0720d9
VP
36
37 /*: END: reference_update :*/
b26ed50d
VP
38}
39
038224f6
VP
40struct S { int i; int j; };
41struct S2 : S {};
42
43int base_in_reference_test (S2& s2)
44{
2d0720d9 45 /*: BEGIN: base_in_reference :*/
038224f6 46 return s2.i;
2d0720d9
VP
47 /*:
48 mi_create_varobj "S2" "s2" "create varobj for s2"
49 mi_list_varobj_children "S2" {
50 {"S2.S" "S" "1" "S"}
51 } "list children of s2"
52 mi_list_varobj_children "S2.S" {
53 {"S2.S.public" "public" "2"}
54 } "list children of s2.s"
55 mi_list_varobj_children "S2.S.public" {
56 {"S2.S.public.i" "i" "0" "int"}
57 {"S2.S.public.j" "j" "0" "int"}
58 } "list children of s2.s.public"
59
60 mi_check_varobj_value "S2.S.public.i" "67" "check S2.S.public.i"
61 mi_check_varobj_value "S2.S.public.j" "89" "check S2.S.public.j"
6e2a9270
VP
62 mi_delete_varobj S2 "delete S2"
63
2d0720d9
VP
64 :*/
65 /*: END: base_in_reference :*/
038224f6
VP
66}
67
68void base_in_reference_test_main ()
69{
70 S2 s;
71 s.i = 67;
72 s.j = 89;
73 base_in_reference_test (s);
74}
75
986d03be
NR
76int reference_to_pointer ()
77{
81121995 78 /*: BEGIN: reference_to_pointer :*/
986d03be
NR
79 S s, *ptr_s, *& rptr_s = ptr_s;
80 s.i = 67;
81 s.j = 89;
82 ptr_s = &s;
986d03be
NR
83 /*:
84 mi_create_varobj RPTR rptr_s "create varobj for rptr_s"
85
86 mi_list_varobj_children RPTR {{RPTR.public public 2}} \
87 "list public child of RPTR"
88
89 mi_list_varobj_children RPTR.public \
90 {{RPTR.public.i i 0 int}
91 {RPTR.public.j j 0 int}} "list children of reference to pointer"
92
93 mi_check_varobj_value RPTR.public.i 67 "check i member"
94 mi_check_varobj_value RPTR.public.j 89 "check j member"
6e2a9270 95 mi_delete_varobj RPTR "delete RPTR"
986d03be 96 :*/
81121995 97 return 99;
986d03be
NR
98 /*: END: reference_to_pointer :*/
99}
038224f6 100
6e2a9270
VP
101int reference_to_struct ()
102{
103 /*: BEGIN: reference_to_struct :*/
104 S s = {7, 8};
105 S& r = s;
106 /*:
107 mi_create_varobj S s "create varobj for s"
108 mi_create_varobj R r "create varobj for s"
109 mi_gdb_test "-var-show-attributes S" \
110 "\\^done,attr=\"noneditable\"" \
111 "check attributes of S"
112 mi_gdb_test "-var-show-attributes R" \
113 "\\^done,attr=\"noneditable\"" \
114 "check attributes of R"
115 :*/
116 s.i = 56;
117 /*: mi_varobj_update * [] "-var-update should not list structure varobjs"
118 :*/
119 return 99;
120 /*: END: reference_to_struct :*/
121}
122
02142340
VP
123struct Base1
124{
125 int i;
126};
127
128struct Base2
129{
130 int i;
131};
132
133struct Derived : public Base1, public Base2
134{
135 int i;
136};
137
138/* Test for the -var-info-path-expression command. Although
139 said command is not specific to C++, it's of more importance
140 to C++ than to C, so we test it in mi-var-cp test. */
141int path_expression ()
142{
143 /*: BEGIN: path_expression :*/
144 int i = 10;
145 int *ip = &i;
146 /*: mi_create_varobj IP ip "create varobj for ip"
147 mi_list_varobj_children IP {{IP.\\*ip \\*ip 0 int}} "list children of IP"
148 mi_gdb_test "-var-info-path-expression IP.*ip" \
149 "\\^done,path_expr=\"\\*\\(ip\\)\"" \
150 "-var-info-path-expression IP.*ip"
151 :*/
152 Derived d;
153 Derived *dp = &d;
154 /*: mi_create_varobj DP dp "create varobj for dp"
155 mi_list_varobj_children DP \
156 {{DP.Base1 Base1 1 Base1} \
157 {DP.Base2 Base2 1 Base2} \
158 {DP.public public 1}} "list children of DP"
159 mi_gdb_test "-var-info-path-expression DP.Base1" \
0d932b2f 160 "\\^done,path_expr=\"\\(\\*\\(class Base1\\*\\) dp\\)\"" \
02142340
VP
161 "-var-info-path-expression DP.Base1"
162 mi_list_varobj_children DP.public { \
163 {DP.public.i i 0 int} \
164 } "list children of DP.public"
165 mi_gdb_test "-var-info-path-expression DP.public.i" \
166 "\\^done,path_expr=\"\\(\\(dp\\)->i\\)\"" \
167 "-var-info-path-expression DP.public.i"
168 mi_list_varobj_children DP.Base1 { \
169 {DP.Base1.public public 1} \
170 } "list children of DP.Base1"
171 mi_list_varobj_children DP.Base1.public { \
172 {DP.Base1.public.i i 0 int} \
173 } "list children of DP.Base1.public"
174 mi_gdb_test "-var-info-path-expression DP.Base1.public.i" \
0d932b2f 175 "\\^done,path_expr=\"\\(\\(\\(\\*\\(class Base1\\*\\) dp\\)\\).i\\)\"" \
02142340
VP
176 "-var-info-path-expression DP.Base1.public.i"
177
178 mi_gdb_test "-var-info-path-expression DP.public" \
179 "\\^done,path_expr=\"\"" \
180 "-var-info-path-expression DP.public"
181
182 mi_create_varobj D d "create varobj for d"
183 mi_list_varobj_children D \
184 {{D.Base1 Base1 1 Base1} \
185 {D.Base2 Base2 1 Base2} \
186 {D.public public 1}} "list children of D"
187 mi_gdb_test "-var-info-path-expression D.Base1" \
0d932b2f 188 "\\^done,path_expr=\"\\(\\(class Base1\\) d\\)\"" \
02142340
VP
189 "-var-info-path-expression D.Base1"
190 :*/
191 int array[4] = {1,2,3};
192 array[3] = 10;
193 /*: mi_create_varobj A array "create varobj for array"
194 mi_list_varobj_children A { \
195 {A.0 0 0 int}
196 {A.1 1 0 int}
197 {A.2 2 0 int}
198 {A.3 3 0 int}} "list children of A"
199 mi_gdb_test "-var-info-path-expression A.2" \
200 "\\^done,path_expr=\"\\(array\\)\\\[2\\\]\"" \
201 "-var-info-path-expression A.2"
202 :*/
203
204 return 99;
205 /*: END: path_expression :*/
206}
207
3848a17f
KS
208class Anonymous
209{
210public:
211 struct { /* index: 0 */
212 int b;
213 };
214 struct { /* index: 1 */
215 int c;
216 };
217 struct { /* index: 2 */
218 int d;
219 struct { /* index: 1 */
220 int e;
221 struct { /* index: 0 */
222 int f;
223 union { /* index: 0 */
224 int g;
225 char h;
226 };
227 };
228 union { /* index: 0 */
229 int i;
230 char j;
231 };
232 };
233 };
234};
235
236/* Test anonymous structs and unions. */
237int
238anonymous_structs_and_unions (void)
239{
240 Anonymous a;
241 a.b = 1;
242 a.c = 2;
243 a.d = 3;
244 a.e = 4;
245 a.f = 5;
246 a.g = 6;
247 a.h = '7';
248 a.i = 8;
249 a.j = '8';
250 return 0; /* anonymous_structs_and_unions */
251}
252
b26ed50d
VP
253int main ()
254{
255 reference_update_tests ();
038224f6 256 base_in_reference_test_main ();
986d03be 257 reference_to_pointer ();
6e2a9270 258 reference_to_struct ();
02142340 259 path_expression ();
3848a17f 260 anonymous_structs_and_unions ();
b26ed50d
VP
261 return 0;
262}