]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.mi/mi-var-child.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-var-child.c
CommitLineData
6aba47ca 1/* Copyright 1999, 2004, 2005, 2007 Free Software Foundation, Inc.
8be260b6
DJ
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#include <stdlib.h>
3c7385ec 21#include <string.h>
8be260b6
DJ
22
23struct _simple_struct {
24 int integer;
25 unsigned int unsigned_integer;
26 char character;
27 signed char signed_character;
28 char *char_ptr;
29 int array_of_10[10];
30};
31
32typedef struct _simple_struct simpleton;
33
34simpleton global_simple;
35
36enum foo {
37 bar = 1,
38 baz
39};
40
41typedef enum foo efoo;
42
43union named_union
44{
45 int integer;
46 char *char_ptr;
47};
48
49typedef struct _struct_decl {
50 int integer;
51 char character;
52 char *char_ptr;
53 long long_int;
54 int **int_ptr_ptr;
55 long long_array[12];
56
57 void (*func_ptr) (void);
58 struct _struct_decl (*func_ptr_struct) (int, char *, long);
59 struct _struct_decl *(*func_ptr_ptr) (int, char *, long);
60 union {
61 int a;
62 char *b;
63 long c;
64 enum foo d;
65 } u1;
66
67 struct {
68 union {
69 struct {
70 int d;
71 char e[10];
72 int *(*func) (void);
73 efoo foo;
74 } u1s1;
75
76 long f;
77 struct {
78 char array_ptr[2];
79 int (*func) (int, char *);
80 } u1s2;
81 } u2;
82
83 int g;
84 char h;
85 long i[10];
86 } s2;
87} weird_struct;
88
89struct _struct_n_pointer {
90 char ****char_ptr;
91 long ****long_ptr;
92 struct _struct_n_pointer *ptrs[3];
93 struct _struct_n_pointer *next;
94};
95
96void do_locals_tests (void);
97void do_block_tests (void);
98void subroutine1 (int, long *);
99void nothing (void);
100void do_children_tests (void);
101void do_special_tests (void);
102void incr_a (char);
103
104void incr_a (char a)
105{
106 int b;
107 b = a;
108}
109
110void
111do_locals_tests ()
112{
113 int linteger;
114 int *lpinteger;
115 char lcharacter;
116 char *lpcharacter;
117 long llong;
118 long *lplong;
119 float lfloat;
120 float *lpfloat;
121 double ldouble;
122 double *lpdouble;
123 struct _simple_struct lsimple;
124 struct _simple_struct *lpsimple;
125 void (*func) (void);
126
127 /* Simple assignments */
128 linteger = 1234;
129 lpinteger = &linteger;
130 lcharacter = 'a';
131 lpcharacter = &lcharacter;
132 llong = 2121L;
133 lplong = &llong;
134 lfloat = 2.1;
135 lpfloat = &lfloat;
136 ldouble = 2.718281828459045;
137 lpdouble = &ldouble;
138 lsimple.integer = 1234;
139 lsimple.unsigned_integer = 255;
140 lsimple.character = 'a';
141 lsimple.signed_character = 21;
142 lsimple.char_ptr = &lcharacter;
143 lpsimple = &lsimple;
144 func = nothing;
145
146 /* Check pointers */
147 linteger = 4321;
148 lcharacter = 'b';
149 llong = 1212L;
150 lfloat = 1.2;
151 ldouble = 5.498548281828172;
152 lsimple.integer = 255;
153 lsimple.unsigned_integer = 4321;
154 lsimple.character = 'b';
155 lsimple.signed_character = 0;
156
157 subroutine1 (linteger, &llong);
158}
159
160void
161nothing ()
162{
163}
164
165void
166subroutine1 (int i, long *l)
167{
168 global_simple.integer = i + 3;
169 i = 212;
170 *l = 12;
171}
172
173void
174do_block_tests ()
175{
176 int cb = 12;
177
178 {
179 int foo;
180 foo = 123;
181 {
182 int foo2;
183 foo2 = 123;
184 {
185 int foo;
186 foo = 321;
187 }
188 foo2 = 0;
189 }
190 foo = 0;
191 }
192
193 cb = 21;
194}
195
196void
197do_children_tests (void)
198{
199 weird_struct *weird;
200 struct _struct_n_pointer *psnp;
201 struct _struct_n_pointer snp0, snp1, snp2;
202 char a0, *a1, **a2, ***a3;
203 char b0, *b1, **b2, ***b3;
204 char c0, *c1, **c2, ***c3;
205 long z0, *z1, **z2, ***z3;
206 long y0, *y1, **y2, ***y3;
207 long x0, *x1, **x2, ***x3;
208 int *foo;
209 int bar;
210
211 struct _struct_decl struct_declarations;
6e650a67 212 memset (&struct_declarations, 0, sizeof (struct_declarations));
8be260b6
DJ
213 weird = &struct_declarations;
214
215 struct_declarations.integer = 123;
216 weird->char_ptr = "hello";
217 bar = 2121;
218 foo = &bar;
219 struct_declarations.int_ptr_ptr = &foo;
220 weird->long_array[0] = 1234;
221 struct_declarations.long_array[1] = 2345;
222 weird->long_array[2] = 3456;
223 struct_declarations.long_array[3] = 4567;
224 weird->long_array[4] = 5678;
225 struct_declarations.long_array[5] = 6789;
226 weird->long_array[6] = 7890;
227 struct_declarations.long_array[7] = 8901;
228 weird->long_array[8] = 9012;
229 struct_declarations.long_array[9] = 1234;
230
231 weird->func_ptr = nothing;
232 struct_declarations.long_array[10] = 3456;
233 struct_declarations.long_array[11] = 5678;
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;
285}
286
287void
288do_special_tests (void)
289{
290 union named_union u;
291 union {
292 int a;
293 char b;
294 long c;
295 } anonu;
296 struct _simple_struct s;
297 struct {
298 int a;
299 char b;
300 long c;
301 } anons;
302 enum foo e;
303 enum { A, B, C } anone;
304 int array[21];
305 int a;
306
307 a = 1;
308 incr_a(2);
309}
310
311int
312main (int argc, char *argv [])
313{
314 do_locals_tests ();
315 do_block_tests ();
316 do_children_tests ();
317 do_special_tests ();
318 exit (0);
319}
320
321