]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.mi/var-cmd.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / var-cmd.c
CommitLineData
6aba47ca 1/* Copyright 1999, 2004, 2007 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
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
5a2e8882
MC
20#include <stdlib.h>
21
fb40c209
AC
22struct _simple_struct {
23 int integer;
24 unsigned int unsigned_integer;
25 char character;
26 signed char signed_character;
27 char *char_ptr;
28 int array_of_10[10];
29};
30
31typedef struct _simple_struct simpleton;
32
33simpleton global_simple;
34
35enum foo {
36 bar = 1,
37 baz
38};
39
40typedef enum foo efoo;
41
42union named_union
43{
44 int integer;
45 char *char_ptr;
46};
47
48typedef struct _struct_decl {
49 int integer;
50 char character;
51 char *char_ptr;
52 long long_int;
53 int **int_ptr_ptr;
8be260b6 54 long long_array[10];
fb40c209
AC
55
56 void (*func_ptr) (void);
57 struct _struct_decl (*func_ptr_struct) (int, char *, long);
58 struct _struct_decl *(*func_ptr_ptr) (int, char *, long);
59 union {
60 int a;
61 char *b;
62 long c;
63 enum foo d;
64 } u1;
65
66 struct {
67 union {
68 struct {
69 int d;
70 char e[10];
71 int *(*func) (void);
72 efoo foo;
73 } u1s1;
74
75 long f;
76 struct {
77 char array_ptr[2];
78 int (*func) (int, char *);
79 } u1s2;
80 } u2;
81
82 int g;
83 char h;
84 long i[10];
85 } s2;
86} weird_struct;
87
88struct _struct_n_pointer {
89 char ****char_ptr;
90 long ****long_ptr;
91 struct _struct_n_pointer *ptrs[3];
92 struct _struct_n_pointer *next;
93};
94
95void do_locals_tests (void);
96void do_block_tests (void);
97void subroutine1 (int, long *);
98void nothing (void);
99void do_children_tests (void);
100void do_special_tests (void);
101void incr_a (char);
102
103void incr_a (char a)
104{
105 int b;
106 b = a;
107}
108
acd65feb
VP
109int array[] = {1,2,3};
110int array2[] = {4,5,6};
111int *array_ptr = array;
112
fb40c209
AC
113void
114do_locals_tests ()
115{
116 int linteger;
117 int *lpinteger;
118 char lcharacter;
119 char *lpcharacter;
120 long llong;
121 long *lplong;
122 float lfloat;
123 float *lpfloat;
124 double ldouble;
125 double *lpdouble;
126 struct _simple_struct lsimple;
127 struct _simple_struct *lpsimple;
128 void (*func) (void);
129
130 /* Simple assignments */
131 linteger = 1234;
132 lpinteger = &linteger;
133 lcharacter = 'a';
134 lpcharacter = &lcharacter;
135 llong = 2121L;
136 lplong = &llong;
137 lfloat = 2.1;
138 lpfloat = &lfloat;
139 ldouble = 2.718281828459045;
140 lpdouble = &ldouble;
141 lsimple.integer = 1234;
142 lsimple.unsigned_integer = 255;
143 lsimple.character = 'a';
144 lsimple.signed_character = 21;
145 lsimple.char_ptr = &lcharacter;
146 lpsimple = &lsimple;
147 func = nothing;
148
149 /* Check pointers */
150 linteger = 4321;
151 lcharacter = 'b';
152 llong = 1212L;
153 lfloat = 1.2;
154 ldouble = 5.498548281828172;
155 lsimple.integer = 255;
156 lsimple.unsigned_integer = 4321;
157 lsimple.character = 'b';
158 lsimple.signed_character = 0;
159
160 subroutine1 (linteger, &llong);
161}
162
163void
164nothing ()
165{
166}
167
168void
169subroutine1 (int i, long *l)
170{
171 global_simple.integer = i + 3;
172 i = 212;
173 *l = 12;
174}
175
176void
177do_block_tests ()
178{
179 int cb = 12;
180
181 {
182 int foo;
183 foo = 123;
184 {
185 int foo2;
186 foo2 = 123;
187 {
188 int foo;
189 foo = 321;
190 }
191 foo2 = 0;
192 }
193 foo = 0;
194 }
195
196 cb = 21;
197}
198
199void
200do_children_tests (void)
201{
202 weird_struct *weird;
203 struct _struct_n_pointer *psnp;
204 struct _struct_n_pointer snp0, snp1, snp2;
205 char a0, *a1, **a2, ***a3;
206 char b0, *b1, **b2, ***b3;
207 char c0, *c1, **c2, ***c3;
208 long z0, *z1, **z2, ***z3;
209 long y0, *y1, **y2, ***y3;
210 long x0, *x1, **x2, ***x3;
211 int *foo;
212 int bar;
213
214 struct _struct_decl struct_declarations;
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 */
236 a0 = '0';
237 a1 = &a0;
238 a2 = &a1;
239 a3 = &a2;
240 b0 = '1';
241 b1 = &b0;
242 b2 = &b1;
243 b3 = &b2;
244 c0 = '2';
245 c1 = &c0;
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
288void
289do_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
318int
319main (int argc, char *argv [])
320{
321 do_locals_tests ();
322 do_block_tests ();
323 do_children_tests ();
324 do_special_tests ();
325 exit (0);
326}
327
328