2004-08-24 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / var-cmd.c
1 /* Copyright 1999 Free Software Foundation, Inc.
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
7 the Free Software Foundation; either version 2 of the License, or (at
8 your option) any later version.
9
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 struct _simple_struct {
21 int integer;
22 unsigned int unsigned_integer;
23 char character;
24 signed char signed_character;
25 char *char_ptr;
26 int array_of_10[10];
27 };
28
29 typedef struct _simple_struct simpleton;
30
31 simpleton global_simple;
32
33 enum foo {
34 bar = 1,
35 baz
36 };
37
38 typedef enum foo efoo;
39
40 union named_union
41 {
42 int integer;
43 char *char_ptr;
44 };
45
46 typedef struct _struct_decl {
47 int integer;
48 char character;
49 char *char_ptr;
50 long long_int;
51 int **int_ptr_ptr;
52 long long_array[10];
53
54 void (*func_ptr) (void);
55 struct _struct_decl (*func_ptr_struct) (int, char *, long);
56 struct _struct_decl *(*func_ptr_ptr) (int, char *, long);
57 union {
58 int a;
59 char *b;
60 long c;
61 enum foo d;
62 } u1;
63
64 struct {
65 union {
66 struct {
67 int d;
68 char e[10];
69 int *(*func) (void);
70 efoo foo;
71 } u1s1;
72
73 long f;
74 struct {
75 char array_ptr[2];
76 int (*func) (int, char *);
77 } u1s2;
78 } u2;
79
80 int g;
81 char h;
82 long i[10];
83 } s2;
84 } weird_struct;
85
86 struct _struct_n_pointer {
87 char ****char_ptr;
88 long ****long_ptr;
89 struct _struct_n_pointer *ptrs[3];
90 struct _struct_n_pointer *next;
91 };
92
93 void do_locals_tests (void);
94 void do_block_tests (void);
95 void subroutine1 (int, long *);
96 void nothing (void);
97 void do_children_tests (void);
98 void do_special_tests (void);
99 void incr_a (char);
100
101 void incr_a (char a)
102 {
103 int b;
104 b = a;
105 }
106
107 void
108 do_locals_tests ()
109 {
110 int linteger;
111 int *lpinteger;
112 char lcharacter;
113 char *lpcharacter;
114 long llong;
115 long *lplong;
116 float lfloat;
117 float *lpfloat;
118 double ldouble;
119 double *lpdouble;
120 struct _simple_struct lsimple;
121 struct _simple_struct *lpsimple;
122 void (*func) (void);
123
124 /* Simple assignments */
125 linteger = 1234;
126 lpinteger = &linteger;
127 lcharacter = 'a';
128 lpcharacter = &lcharacter;
129 llong = 2121L;
130 lplong = &llong;
131 lfloat = 2.1;
132 lpfloat = &lfloat;
133 ldouble = 2.718281828459045;
134 lpdouble = &ldouble;
135 lsimple.integer = 1234;
136 lsimple.unsigned_integer = 255;
137 lsimple.character = 'a';
138 lsimple.signed_character = 21;
139 lsimple.char_ptr = &lcharacter;
140 lpsimple = &lsimple;
141 func = nothing;
142
143 /* Check pointers */
144 linteger = 4321;
145 lcharacter = 'b';
146 llong = 1212L;
147 lfloat = 1.2;
148 ldouble = 5.498548281828172;
149 lsimple.integer = 255;
150 lsimple.unsigned_integer = 4321;
151 lsimple.character = 'b';
152 lsimple.signed_character = 0;
153
154 subroutine1 (linteger, &llong);
155 }
156
157 void
158 nothing ()
159 {
160 }
161
162 void
163 subroutine1 (int i, long *l)
164 {
165 global_simple.integer = i + 3;
166 i = 212;
167 *l = 12;
168 }
169
170 void
171 do_block_tests ()
172 {
173 int cb = 12;
174
175 {
176 int foo;
177 foo = 123;
178 {
179 int foo2;
180 foo2 = 123;
181 {
182 int foo;
183 foo = 321;
184 }
185 foo2 = 0;
186 }
187 foo = 0;
188 }
189
190 cb = 21;
191 }
192
193 void
194 do_children_tests (void)
195 {
196 weird_struct *weird;
197 struct _struct_n_pointer *psnp;
198 struct _struct_n_pointer snp0, snp1, snp2;
199 char a0, *a1, **a2, ***a3;
200 char b0, *b1, **b2, ***b3;
201 char c0, *c1, **c2, ***c3;
202 long z0, *z1, **z2, ***z3;
203 long y0, *y1, **y2, ***y3;
204 long x0, *x1, **x2, ***x3;
205 int *foo;
206 int bar;
207
208 struct _struct_decl struct_declarations;
209 weird = &struct_declarations;
210
211 struct_declarations.integer = 123;
212 weird->char_ptr = "hello";
213 bar = 2121;
214 foo = &bar;
215 struct_declarations.int_ptr_ptr = &foo;
216 weird->long_array[0] = 1234;
217 struct_declarations.long_array[1] = 2345;
218 weird->long_array[2] = 3456;
219 struct_declarations.long_array[3] = 4567;
220 weird->long_array[4] = 5678;
221 struct_declarations.long_array[5] = 6789;
222 weird->long_array[6] = 7890;
223 struct_declarations.long_array[7] = 8901;
224 weird->long_array[8] = 9012;
225 struct_declarations.long_array[9] = 1234;
226
227 weird->func_ptr = nothing;
228
229 /* Struct/pointer/array tests */
230 a0 = '0';
231 a1 = &a0;
232 a2 = &a1;
233 a3 = &a2;
234 b0 = '1';
235 b1 = &b0;
236 b2 = &b1;
237 b3 = &b2;
238 c0 = '2';
239 c1 = &c0;
240 c2 = &c1;
241 c3 = &c2;
242 z0 = 0xdead + 0;
243 z1 = &z0;
244 z2 = &z1;
245 z3 = &z2;
246 y0 = 0xdead + 1;
247 y1 = &y0;
248 y2 = &y1;
249 y3 = &y2;
250 x0 = 0xdead + 2;
251 x1 = &x0;
252 x2 = &x1;
253 x3 = &x2;
254 snp0.char_ptr = &a3;
255 snp0.long_ptr = &z3;
256 snp0.ptrs[0] = &snp0;
257 snp0.ptrs[1] = &snp1;
258 snp0.ptrs[2] = &snp2;
259 snp0.next = &snp1;
260 snp1.char_ptr = &b3;
261 snp1.long_ptr = &y3;
262 snp1.ptrs[0] = &snp0;
263 snp1.ptrs[1] = &snp1;
264 snp1.ptrs[2] = &snp2;
265 snp1.next = &snp2;
266 snp2.char_ptr = &c3;
267 snp2.long_ptr = &x3;
268 snp2.ptrs[0] = &snp0;
269 snp2.ptrs[1] = &snp1;
270 snp2.ptrs[2] = &snp2;
271 snp2.next = 0x0;
272 psnp = &snp0;
273 snp0.char_ptr = &b3;
274 snp1.char_ptr = &c3;
275 snp2.char_ptr = &a3;
276 snp0.long_ptr = &y3;
277 snp1.long_ptr = &x3;
278 snp2.long_ptr = &z3;
279 }
280
281 void
282 do_special_tests (void)
283 {
284 union named_union u;
285 union {
286 int a;
287 char b;
288 long c;
289 } anonu;
290 struct _simple_struct s;
291 struct {
292 int a;
293 char b;
294 long c;
295 } anons;
296 enum foo e;
297 enum { A, B, C } anone;
298 int array[21];
299 int a;
300
301 a = 1;
302 incr_a(2);
303 }
304
305 int
306 main (int argc, char *argv [])
307 {
308 do_locals_tests ();
309 do_block_tests ();
310 do_children_tests ();
311 do_special_tests ();
312 exit (0);
313 }
314
315
This page took 0.046475 seconds and 4 git commands to generate.