Commit | Line | Data |
---|---|---|
d8d83e9b | 1 | /* Copyright 1999, 2004, 2005 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 |
22 | struct _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 | ||
31 | typedef struct _simple_struct simpleton; | |
32 | ||
33 | simpleton global_simple; | |
34 | ||
35 | enum foo { | |
36 | bar = 1, | |
37 | baz | |
38 | }; | |
39 | ||
40 | typedef enum foo efoo; | |
41 | ||
42 | union named_union | |
43 | { | |
44 | int integer; | |
45 | char *char_ptr; | |
46 | }; | |
47 | ||
48 | typedef struct _struct_decl { | |
49 | int integer; | |
50 | char character; | |
51 | char *char_ptr; | |
52 | long long_int; | |
53 | int **int_ptr_ptr; | |
d8d83e9b | 54 | long long_array[12]; |
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 | ||
88 | struct _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 | ||
95 | void do_locals_tests (void); | |
96 | void do_block_tests (void); | |
97 | void subroutine1 (int, long *); | |
98 | void nothing (void); | |
99 | void do_children_tests (void); | |
100 | void do_special_tests (void); | |
101 | void incr_a (char); | |
102 | ||
103 | void incr_a (char a) | |
104 | { | |
105 | int b; | |
106 | b = a; | |
107 | } | |
108 | ||
109 | void | |
110 | do_locals_tests () | |
111 | { | |
112 | int linteger; | |
113 | int *lpinteger; | |
114 | char lcharacter; | |
115 | char *lpcharacter; | |
116 | long llong; | |
117 | long *lplong; | |
118 | float lfloat; | |
119 | float *lpfloat; | |
120 | double ldouble; | |
121 | double *lpdouble; | |
122 | struct _simple_struct lsimple; | |
123 | struct _simple_struct *lpsimple; | |
124 | void (*func) (void); | |
125 | ||
126 | /* Simple assignments */ | |
127 | linteger = 1234; | |
128 | lpinteger = &linteger; | |
129 | lcharacter = 'a'; | |
130 | lpcharacter = &lcharacter; | |
131 | llong = 2121L; | |
132 | lplong = &llong; | |
133 | lfloat = 2.1; | |
134 | lpfloat = &lfloat; | |
135 | ldouble = 2.718281828459045; | |
136 | lpdouble = &ldouble; | |
137 | lsimple.integer = 1234; | |
138 | lsimple.unsigned_integer = 255; | |
139 | lsimple.character = 'a'; | |
140 | lsimple.signed_character = 21; | |
141 | lsimple.char_ptr = &lcharacter; | |
142 | lpsimple = &lsimple; | |
143 | func = nothing; | |
144 | ||
145 | /* Check pointers */ | |
146 | linteger = 4321; | |
147 | lcharacter = 'b'; | |
148 | llong = 1212L; | |
149 | lfloat = 1.2; | |
150 | ldouble = 5.498548281828172; | |
151 | lsimple.integer = 255; | |
152 | lsimple.unsigned_integer = 4321; | |
153 | lsimple.character = 'b'; | |
154 | lsimple.signed_character = 0; | |
155 | ||
156 | subroutine1 (linteger, &llong); | |
157 | } | |
158 | ||
159 | void | |
160 | nothing () | |
161 | { | |
162 | } | |
163 | ||
164 | void | |
165 | subroutine1 (int i, long *l) | |
166 | { | |
167 | global_simple.integer = i + 3; | |
168 | i = 212; | |
169 | *l = 12; | |
170 | } | |
171 | ||
172 | void | |
173 | do_block_tests () | |
174 | { | |
175 | int cb = 12; | |
176 | ||
177 | { | |
178 | int foo; | |
179 | foo = 123; | |
180 | { | |
181 | int foo2; | |
182 | foo2 = 123; | |
183 | { | |
184 | int foo; | |
185 | foo = 321; | |
186 | } | |
187 | foo2 = 0; | |
188 | } | |
189 | foo = 0; | |
190 | } | |
191 | ||
192 | cb = 21; | |
193 | } | |
194 | ||
195 | void | |
196 | do_children_tests (void) | |
197 | { | |
198 | weird_struct *weird; | |
199 | struct _struct_n_pointer *psnp; | |
200 | struct _struct_n_pointer snp0, snp1, snp2; | |
201 | char a0, *a1, **a2, ***a3; | |
202 | char b0, *b1, **b2, ***b3; | |
203 | char c0, *c1, **c2, ***c3; | |
204 | long z0, *z1, **z2, ***z3; | |
205 | long y0, *y1, **y2, ***y3; | |
206 | long x0, *x1, **x2, ***x3; | |
207 | int *foo; | |
208 | int bar; | |
209 | ||
210 | struct _struct_decl struct_declarations; | |
211 | weird = &struct_declarations; | |
212 | ||
213 | struct_declarations.integer = 123; | |
214 | weird->char_ptr = "hello"; | |
215 | bar = 2121; | |
216 | foo = &bar; | |
217 | struct_declarations.int_ptr_ptr = &foo; | |
218 | weird->long_array[0] = 1234; | |
219 | struct_declarations.long_array[1] = 2345; | |
220 | weird->long_array[2] = 3456; | |
221 | struct_declarations.long_array[3] = 4567; | |
222 | weird->long_array[4] = 5678; | |
223 | struct_declarations.long_array[5] = 6789; | |
224 | weird->long_array[6] = 7890; | |
225 | struct_declarations.long_array[7] = 8901; | |
226 | weird->long_array[8] = 9012; | |
227 | struct_declarations.long_array[9] = 1234; | |
228 | ||
229 | weird->func_ptr = nothing; | |
d8d83e9b NR |
230 | struct_declarations.long_array[10] = 3456; |
231 | struct_declarations.long_array[11] = 5678; | |
fb40c209 AC |
232 | |
233 | /* Struct/pointer/array tests */ | |
234 | a0 = '0'; | |
235 | a1 = &a0; | |
236 | a2 = &a1; | |
237 | a3 = &a2; | |
238 | b0 = '1'; | |
239 | b1 = &b0; | |
240 | b2 = &b1; | |
241 | b3 = &b2; | |
242 | c0 = '2'; | |
243 | c1 = &c0; | |
244 | c2 = &c1; | |
245 | c3 = &c2; | |
246 | z0 = 0xdead + 0; | |
247 | z1 = &z0; | |
248 | z2 = &z1; | |
249 | z3 = &z2; | |
250 | y0 = 0xdead + 1; | |
251 | y1 = &y0; | |
252 | y2 = &y1; | |
253 | y3 = &y2; | |
254 | x0 = 0xdead + 2; | |
255 | x1 = &x0; | |
256 | x2 = &x1; | |
257 | x3 = &x2; | |
258 | snp0.char_ptr = &a3; | |
259 | snp0.long_ptr = &z3; | |
260 | snp0.ptrs[0] = &snp0; | |
261 | snp0.ptrs[1] = &snp1; | |
262 | snp0.ptrs[2] = &snp2; | |
263 | snp0.next = &snp1; | |
264 | snp1.char_ptr = &b3; | |
265 | snp1.long_ptr = &y3; | |
266 | snp1.ptrs[0] = &snp0; | |
267 | snp1.ptrs[1] = &snp1; | |
268 | snp1.ptrs[2] = &snp2; | |
269 | snp1.next = &snp2; | |
270 | snp2.char_ptr = &c3; | |
271 | snp2.long_ptr = &x3; | |
272 | snp2.ptrs[0] = &snp0; | |
273 | snp2.ptrs[1] = &snp1; | |
274 | snp2.ptrs[2] = &snp2; | |
275 | snp2.next = 0x0; | |
276 | psnp = &snp0; | |
277 | snp0.char_ptr = &b3; | |
278 | snp1.char_ptr = &c3; | |
279 | snp2.char_ptr = &a3; | |
280 | snp0.long_ptr = &y3; | |
281 | snp1.long_ptr = &x3; | |
282 | snp2.long_ptr = &z3; | |
283 | } | |
284 | ||
285 | void | |
286 | do_special_tests (void) | |
287 | { | |
288 | union named_union u; | |
289 | union { | |
290 | int a; | |
291 | char b; | |
292 | long c; | |
293 | } anonu; | |
294 | struct _simple_struct s; | |
295 | struct { | |
296 | int a; | |
297 | char b; | |
298 | long c; | |
299 | } anons; | |
300 | enum foo e; | |
301 | enum { A, B, C } anone; | |
302 | int array[21]; | |
303 | int a; | |
304 | ||
305 | a = 1; | |
306 | incr_a(2); | |
307 | } | |
308 | ||
309 | int | |
310 | main (int argc, char *argv []) | |
311 | { | |
312 | do_locals_tests (); | |
313 | do_block_tests (); | |
314 | do_children_tests (); | |
315 | do_special_tests (); | |
316 | exit (0); | |
317 | } | |
318 | ||
319 |