GDB copyright headers update after running GDB's copyright.py script.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-var-cp.cc
1 /* Copyright 2006-2016 Free Software Foundation, Inc.
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
5 the Free Software Foundation; either version 3 of the License, or
6 (at your option) any later version.
7
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.
12
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/>. */
15
16 void reference_update_tests ()
17 {
18 /*: BEGIN: reference_update :*/
19 int x = 167;
20 /*: mi_create_varobj "RX" "rx" "create varobj for rx" :*/
21 int& rx = x;
22 /*: mi_varobj_update RX {RX} "update RX (1)"
23 mi_check_varobj_value RX 167 "check RX: expect 167"
24 :*/
25 x = 567;
26 /*: mi_varobj_update RX {RX} "update RX (2)"
27 mi_check_varobj_value RX 567 "check RX: expect 567"
28 :*/
29 x = 567;
30 /*: mi_varobj_update RX {} "update RX (3)"
31 mi_delete_varobj RX "delete RX"
32 :*/
33 /* Dummy assignment to keep 'x' in scope. */
34 x = 444;
35
36 /*: END: reference_update :*/
37 }
38
39 struct S { int i; int j; };
40 struct S2 : S {};
41
42 int base_in_reference_test (S2& s2)
43 {
44 /*: BEGIN: base_in_reference :*/
45 return s2.i;
46 /*:
47 mi_create_varobj "S2" "s2" "create varobj for s2"
48 mi_list_varobj_children "S2" {
49 {"S2.S" "S" "1" "S"}
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"
58
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"
62
63 :*/
64 /*: END: base_in_reference :*/
65 }
66
67 void base_in_reference_test_main ()
68 {
69 S2 s;
70 s.i = 67;
71 s.j = 89;
72 base_in_reference_test (s);
73 }
74
75 int reference_to_pointer ()
76 {
77 /*: BEGIN: reference_to_pointer :*/
78 S s, *ptr_s, *& rptr_s = ptr_s;
79 s.i = 67;
80 s.j = 89;
81 ptr_s = &s;
82 /*:
83 mi_create_varobj RPTR rptr_s "create varobj for rptr_s"
84
85 mi_list_varobj_children RPTR {{RPTR.public public 2}} \
86 "list public child of RPTR"
87
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"
91
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"
95 :*/
96 return 99;
97 /*: END: reference_to_pointer :*/
98 }
99
100 int reference_to_struct ()
101 {
102 /*: BEGIN: reference_to_struct :*/
103 S s = {7, 8};
104 S& r = s;
105 /*:
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"
114 :*/
115 s.i = 56;
116 /*: mi_varobj_update * [] "-var-update should not list structure varobjs"
117 :*/
118 return 99;
119 /*: END: reference_to_struct :*/
120 }
121
122 struct Base1
123 {
124 int i;
125 };
126
127 struct Base2
128 {
129 int i;
130 };
131
132 struct Derived : public Base1, public Base2
133 {
134 int i;
135 };
136
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 ()
141 {
142 /*: BEGIN: path_expression :*/
143 int i = 10;
144 int *ip = &i;
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"
150 :*/
151 Derived d;
152 Derived *dp = &d;
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"
176
177 mi_gdb_test "-var-info-path-expression DP.public" \
178 "\\^done,path_expr=\"\"" \
179 "-var-info-path-expression DP.public"
180
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"
189 :*/
190 int array[4] = {1,2,3};
191 array[3] = 10;
192 /*: mi_create_varobj A array "create varobj for array"
193 mi_list_varobj_children A { \
194 {A.0 0 0 int}
195 {A.1 1 0 int}
196 {A.2 2 0 int}
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"
201 :*/
202
203 return 99;
204 /*: END: path_expression :*/
205 }
206
207 class Anonymous
208 {
209 public:
210 struct { /* index: 0 */
211 int b;
212 };
213 struct { /* index: 1 */
214 int c;
215 };
216 struct { /* index: 2 */
217 int d;
218 struct { /* index: 1 */
219 int e;
220 struct { /* index: 0 */
221 int f;
222 union { /* index: 0 */
223 int g;
224 char h;
225 };
226 };
227 union { /* index: 0 */
228 int i;
229 char j;
230 };
231 };
232 };
233 };
234
235 /* Test anonymous structs and unions. */
236 int
237 anonymous_structs_and_unions (void)
238 {
239 Anonymous a;
240 a.b = 1;
241 a.c = 2;
242 a.d = 3;
243 a.e = 4;
244 a.f = 5;
245 a.g = 6;
246 a.h = '7';
247 a.i = 8;
248 a.j = '8';
249 return 0; /* anonymous_structs_and_unions */
250 }
251
252 int main ()
253 {
254 reference_update_tests ();
255 base_in_reference_test_main ();
256 reference_to_pointer ();
257 reference_to_struct ();
258 path_expression ();
259 anonymous_structs_and_unions ();
260 return 0;
261 }
This page took 0.046032 seconds and 4 git commands to generate.