Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | /* Copyright 1999, 2004, 2007, 2008 Free Software Foundation, Inc. |
7c27f15b MC |
2 | |
3 | This file is part of GDB. | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
7 | the Free Software Foundation; either version 3 of the License, or |
8 | (at your option) any later version. | |
7c27f15b | 9 | |
a9762ec7 JB |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
7c27f15b MC |
14 | |
15 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
7c27f15b | 17 | |
5a2e8882 | 18 | #include <stdlib.h> |
17f62551 | 19 | #include <string.h> |
5a2e8882 | 20 | |
fb40c209 AC |
21 | struct _simple_struct { |
22 | int integer; | |
23 | unsigned int unsigned_integer; | |
24 | char character; | |
25 | signed char signed_character; | |
26 | char *char_ptr; | |
27 | int array_of_10[10]; | |
28 | }; | |
29 | ||
30 | typedef struct _simple_struct simpleton; | |
31 | ||
32 | simpleton global_simple; | |
33 | ||
34 | enum foo { | |
35 | bar = 1, | |
36 | baz | |
37 | }; | |
38 | ||
39 | typedef enum foo efoo; | |
40 | ||
41 | union named_union | |
42 | { | |
43 | int integer; | |
44 | char *char_ptr; | |
45 | }; | |
46 | ||
47 | typedef struct _struct_decl { | |
48 | int integer; | |
49 | char character; | |
50 | char *char_ptr; | |
51 | long long_int; | |
52 | int **int_ptr_ptr; | |
8be260b6 | 53 | long long_array[10]; |
fb40c209 AC |
54 | |
55 | void (*func_ptr) (void); | |
56 | struct _struct_decl (*func_ptr_struct) (int, char *, long); | |
57 | struct _struct_decl *(*func_ptr_ptr) (int, char *, long); | |
58 | union { | |
59 | int a; | |
60 | char *b; | |
61 | long c; | |
62 | enum foo d; | |
63 | } u1; | |
64 | ||
65 | struct { | |
66 | union { | |
67 | struct { | |
68 | int d; | |
69 | char e[10]; | |
70 | int *(*func) (void); | |
71 | efoo foo; | |
72 | } u1s1; | |
73 | ||
74 | long f; | |
75 | struct { | |
76 | char array_ptr[2]; | |
77 | int (*func) (int, char *); | |
78 | } u1s2; | |
79 | } u2; | |
80 | ||
81 | int g; | |
82 | char h; | |
83 | long i[10]; | |
84 | } s2; | |
85 | } weird_struct; | |
86 | ||
87 | struct _struct_n_pointer { | |
88 | char ****char_ptr; | |
89 | long ****long_ptr; | |
90 | struct _struct_n_pointer *ptrs[3]; | |
91 | struct _struct_n_pointer *next; | |
92 | }; | |
93 | ||
94 | void do_locals_tests (void); | |
95 | void do_block_tests (void); | |
96 | void subroutine1 (int, long *); | |
97 | void nothing (void); | |
98 | void do_children_tests (void); | |
99 | void do_special_tests (void); | |
100 | void incr_a (char); | |
101 | ||
102 | void incr_a (char a) | |
103 | { | |
104 | int b; | |
105 | b = a; | |
106 | } | |
107 | ||
acd65feb VP |
108 | int array[] = {1,2,3}; |
109 | int array2[] = {4,5,6}; | |
110 | int *array_ptr = array; | |
111 | ||
fb40c209 AC |
112 | void |
113 | do_locals_tests () | |
114 | { | |
a73bafbc VP |
115 | int linteger = 0; |
116 | int *lpinteger = 0; | |
fef8a650 | 117 | char lcharacter[2] = { 0, 0 }; |
a73bafbc VP |
118 | char *lpcharacter = 0; |
119 | long llong = 0; | |
120 | long *lplong = 0; | |
121 | float lfloat = 0; | |
122 | float *lpfloat = 0; | |
123 | double ldouble = 0; | |
124 | double *lpdouble = 0; | |
fb40c209 AC |
125 | struct _simple_struct lsimple; |
126 | struct _simple_struct *lpsimple; | |
127 | void (*func) (void); | |
128 | ||
129 | /* Simple assignments */ | |
130 | linteger = 1234; | |
131 | lpinteger = &linteger; | |
fef8a650 DJ |
132 | lcharacter[0] = 'a'; |
133 | lpcharacter = lcharacter; | |
fb40c209 AC |
134 | llong = 2121L; |
135 | lplong = &llong; | |
136 | lfloat = 2.1; | |
137 | lpfloat = &lfloat; | |
138 | ldouble = 2.718281828459045; | |
139 | lpdouble = &ldouble; | |
140 | lsimple.integer = 1234; | |
141 | lsimple.unsigned_integer = 255; | |
142 | lsimple.character = 'a'; | |
143 | lsimple.signed_character = 21; | |
fef8a650 | 144 | lsimple.char_ptr = lcharacter; |
fb40c209 AC |
145 | lpsimple = &lsimple; |
146 | func = nothing; | |
147 | ||
148 | /* Check pointers */ | |
149 | linteger = 4321; | |
fef8a650 | 150 | lcharacter[0] = 'b'; |
fb40c209 AC |
151 | llong = 1212L; |
152 | lfloat = 1.2; | |
153 | ldouble = 5.498548281828172; | |
154 | lsimple.integer = 255; | |
155 | lsimple.unsigned_integer = 4321; | |
156 | lsimple.character = 'b'; | |
157 | lsimple.signed_character = 0; | |
158 | ||
159 | subroutine1 (linteger, &llong); | |
160 | } | |
161 | ||
162 | void | |
163 | nothing () | |
164 | { | |
165 | } | |
166 | ||
167 | void | |
168 | subroutine1 (int i, long *l) | |
169 | { | |
170 | global_simple.integer = i + 3; | |
171 | i = 212; | |
172 | *l = 12; | |
173 | } | |
174 | ||
175 | void | |
176 | do_block_tests () | |
177 | { | |
178 | int cb = 12; | |
179 | ||
180 | { | |
181 | int foo; | |
182 | foo = 123; | |
183 | { | |
184 | int foo2; | |
185 | foo2 = 123; | |
186 | { | |
187 | int foo; | |
188 | foo = 321; | |
189 | } | |
190 | foo2 = 0; | |
191 | } | |
192 | foo = 0; | |
193 | } | |
194 | ||
195 | cb = 21; | |
196 | } | |
197 | ||
198 | void | |
199 | do_children_tests (void) | |
200 | { | |
201 | weird_struct *weird; | |
202 | struct _struct_n_pointer *psnp; | |
203 | struct _struct_n_pointer snp0, snp1, snp2; | |
a73bafbc VP |
204 | char a0[2] = {}, *a1, **a2, ***a3; |
205 | char b0[2] = {}, *b1, **b2, ***b3; | |
206 | char c0[2] = {}, *c1, **c2, ***c3; | |
fb40c209 AC |
207 | long z0, *z1, **z2, ***z3; |
208 | long y0, *y1, **y2, ***y3; | |
209 | long x0, *x1, **x2, ***x3; | |
210 | int *foo; | |
211 | int bar; | |
212 | ||
213 | struct _struct_decl struct_declarations; | |
17f62551 | 214 | memset (&struct_declarations, 0, sizeof (struct_declarations)); |
fb40c209 AC |
215 | weird = &struct_declarations; |
216 | ||
217 | struct_declarations.integer = 123; | |
218 | weird->char_ptr = "hello"; | |
219 | bar = 2121; | |
220 | foo = &bar; | |
221 | struct_declarations.int_ptr_ptr = &foo; | |
222 | weird->long_array[0] = 1234; | |
223 | struct_declarations.long_array[1] = 2345; | |
224 | weird->long_array[2] = 3456; | |
225 | struct_declarations.long_array[3] = 4567; | |
226 | weird->long_array[4] = 5678; | |
227 | struct_declarations.long_array[5] = 6789; | |
228 | weird->long_array[6] = 7890; | |
229 | struct_declarations.long_array[7] = 8901; | |
230 | weird->long_array[8] = 9012; | |
231 | struct_declarations.long_array[9] = 1234; | |
232 | ||
233 | weird->func_ptr = nothing; | |
234 | ||
235 | /* Struct/pointer/array tests */ | |
a73bafbc VP |
236 | a0[0] = '0'; |
237 | a1 = a0; | |
fb40c209 AC |
238 | a2 = &a1; |
239 | a3 = &a2; | |
a73bafbc VP |
240 | b0[0] = '1'; |
241 | b1 = b0; | |
fb40c209 AC |
242 | b2 = &b1; |
243 | b3 = &b2; | |
a73bafbc VP |
244 | c0[0] = '2'; |
245 | c1 = c0; | |
fb40c209 AC |
246 | c2 = &c1; |
247 | c3 = &c2; | |
248 | z0 = 0xdead + 0; | |
249 | z1 = &z0; | |
250 | z2 = &z1; | |
251 | z3 = &z2; | |
252 | y0 = 0xdead + 1; | |
253 | y1 = &y0; | |
254 | y2 = &y1; | |
255 | y3 = &y2; | |
256 | x0 = 0xdead + 2; | |
257 | x1 = &x0; | |
258 | x2 = &x1; | |
259 | x3 = &x2; | |
260 | snp0.char_ptr = &a3; | |
261 | snp0.long_ptr = &z3; | |
262 | snp0.ptrs[0] = &snp0; | |
263 | snp0.ptrs[1] = &snp1; | |
264 | snp0.ptrs[2] = &snp2; | |
265 | snp0.next = &snp1; | |
266 | snp1.char_ptr = &b3; | |
267 | snp1.long_ptr = &y3; | |
268 | snp1.ptrs[0] = &snp0; | |
269 | snp1.ptrs[1] = &snp1; | |
270 | snp1.ptrs[2] = &snp2; | |
271 | snp1.next = &snp2; | |
272 | snp2.char_ptr = &c3; | |
273 | snp2.long_ptr = &x3; | |
274 | snp2.ptrs[0] = &snp0; | |
275 | snp2.ptrs[1] = &snp1; | |
276 | snp2.ptrs[2] = &snp2; | |
277 | snp2.next = 0x0; | |
278 | psnp = &snp0; | |
279 | snp0.char_ptr = &b3; | |
280 | snp1.char_ptr = &c3; | |
281 | snp2.char_ptr = &a3; | |
282 | snp0.long_ptr = &y3; | |
283 | snp1.long_ptr = &x3; | |
284 | snp2.long_ptr = &z3; | |
e1c2defa | 285 | {int a = 0;} |
fb40c209 AC |
286 | } |
287 | ||
288 | void | |
289 | do_special_tests (void) | |
290 | { | |
291 | union named_union u; | |
292 | union { | |
293 | int a; | |
294 | char b; | |
295 | long c; | |
296 | } anonu; | |
297 | struct _simple_struct s; | |
298 | struct { | |
299 | int a; | |
300 | char b; | |
301 | long c; | |
302 | } anons; | |
303 | enum foo e; | |
304 | enum { A, B, C } anone; | |
305 | int array[21]; | |
306 | int a; | |
307 | ||
308 | a = 1; | |
c7e64c9a DJ |
309 | u.integer = a; |
310 | anonu.a = a; | |
311 | s.integer = a; | |
312 | anons.a = a; | |
313 | e = bar; | |
314 | anone = A; | |
fb40c209 AC |
315 | incr_a(2); |
316 | } | |
317 | ||
25d5ea92 VP |
318 | void do_frozen_tests () |
319 | { | |
320 | /*: BEGIN: frozen :*/ | |
321 | struct { | |
322 | int i; | |
323 | struct { | |
324 | int j; | |
325 | int k; | |
326 | } nested; | |
327 | } v1 = {1, {2, 3}}; | |
328 | ||
329 | int v2 = 4; | |
330 | /*: | |
331 | mi_create_varobj V1 v1 "create varobj for v1" | |
332 | mi_create_varobj V2 v2 "create varobj for v2" | |
333 | ||
334 | mi_list_varobj_children "V1" { | |
335 | {"V1.i" "i" "0" "int"} | |
336 | {"V1.nested" "nested" "2" "struct {...}"} | |
337 | } "list children of v1" | |
338 | ||
339 | mi_list_varobj_children "V1.nested" { | |
340 | {"V1.nested.j" "j" "0" "int"} | |
341 | {"V1.nested.k" "k" "0" "int"} | |
342 | } "list children of v1.nested" | |
343 | ||
344 | mi_check_varobj_value V1.i 1 "check V1.i: 1" | |
345 | mi_check_varobj_value V1.nested.j 2 "check V1.nested.j: 2" | |
346 | mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3" | |
347 | mi_check_varobj_value V2 4 "check V2: 4" | |
348 | :*/ | |
349 | v2 = 5; | |
350 | /*: | |
351 | mi_varobj_update * {V2} "update varobjs: V2 changed" | |
352 | set_frozen V2 1 | |
353 | :*/ | |
354 | v2 = 6; | |
355 | /*: | |
356 | mi_varobj_update * {} "update varobjs: nothing changed" | |
357 | mi_check_varobj_value V2 5 "check V2: 5" | |
358 | mi_varobj_update V2 {V2} "update V2 explicitly" | |
359 | mi_check_varobj_value V2 6 "check V2: 6" | |
360 | :*/ | |
361 | v1.i = 7; | |
362 | v1.nested.j = 8; | |
363 | v1.nested.k = 9; | |
364 | /*: | |
365 | set_frozen V1 1 | |
366 | mi_varobj_update * {} "update varobjs: nothing changed" | |
367 | mi_check_varobj_value V1.i 1 "check V1.i: 1" | |
368 | mi_check_varobj_value V1.nested.j 2 "check V1.nested.j: 2" | |
369 | mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3" | |
370 | # Check that explicit update for elements of structures | |
371 | # works. | |
372 | # Update v1.j | |
373 | mi_varobj_update V1.nested.j {V1.nested.j} "update V1.nested.j" | |
374 | mi_check_varobj_value V1.i 1 "check V1.i: 1" | |
375 | mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8" | |
376 | mi_check_varobj_value V1.nested.k 3 "check V1.nested.k: 3" | |
377 | # Update v1.nested, check that children is updated. | |
378 | mi_varobj_update V1.nested {V1.nested.k} "update V1.nested" | |
379 | mi_check_varobj_value V1.i 1 "check V1.i: 1" | |
380 | mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8" | |
381 | mi_check_varobj_value V1.nested.k 9 "check V1.nested.k: 9" | |
382 | # Update v1.i | |
383 | mi_varobj_update V1.i {V1.i} "update V1.i" | |
384 | mi_check_varobj_value V1.i 7 "check V1.i: 7" | |
385 | :*/ | |
386 | v1.i = 10; | |
387 | v1.nested.j = 11; | |
388 | v1.nested.k = 12; | |
389 | /*: | |
390 | # Check that unfreeze itself does not updates the values. | |
391 | set_frozen V1 0 | |
392 | mi_check_varobj_value V1.i 7 "check V1.i: 7" | |
393 | mi_check_varobj_value V1.nested.j 8 "check V1.nested.j: 8" | |
394 | mi_check_varobj_value V1.nested.k 9 "check V1.nested.k: 9" | |
395 | mi_varobj_update V1 {V1.i V1.nested.j V1.nested.k} "update V1" | |
396 | mi_check_varobj_value V1.i 10 "check V1.i: 10" | |
397 | mi_check_varobj_value V1.nested.j 11 "check V1.nested.j: 11" | |
398 | mi_check_varobj_value V1.nested.k 12 "check V1.nested.k: 12" | |
399 | :*/ | |
400 | ||
401 | /*: END: frozen :*/ | |
402 | } | |
403 | ||
fb40c209 AC |
404 | int |
405 | main (int argc, char *argv []) | |
406 | { | |
407 | do_locals_tests (); | |
408 | do_block_tests (); | |
409 | do_children_tests (); | |
410 | do_special_tests (); | |
25d5ea92 | 411 | do_frozen_tests (); |
fb40c209 AC |
412 | exit (0); |
413 | } | |
414 | ||
415 |