]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/ptype.c
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ptype.c
1 /*
2 * Test file with lots of different types, for testing the
3 * "ptype" command.
4 */
5
6 /*
7 * First the basic C types.
8 */
9
10 #if !defined (__STDC__) && !defined (_AIX)
11 #define signed /**/
12 #endif
13
14 char v_char;
15 signed char v_signed_char;
16 unsigned char v_unsigned_char;
17
18 short v_short;
19 signed short v_signed_short;
20 unsigned short v_unsigned_short;
21
22 int v_int;
23 signed int v_signed_int;
24 unsigned int v_unsigned_int;
25
26 long v_long;
27 signed long v_signed_long;
28 unsigned long v_unsigned_long;
29
30 float v_float;
31 double v_double;
32
33 /*
34 * Now some derived types, which are arrays, functions-returning,
35 * pointers, structures, unions, and enumerations.
36 */
37
38 /**** arrays *******/
39
40 char v_char_array[2];
41 signed char v_signed_char_array[2];
42 unsigned char v_unsigned_char_array[2];
43
44 short v_short_array[2];
45 signed short v_signed_short_array[2];
46 unsigned short v_unsigned_short_array[2];
47
48 int v_int_array[2];
49 signed int v_signed_int_array[2];
50 unsigned int v_unsigned_int_array[2];
51
52 long v_long_array[2];
53 signed long v_signed_long_array[2];
54 unsigned long v_unsigned_long_array[2];
55
56 float v_float_array[2];
57 double v_double_array[2];
58
59 /* PR 3742 */
60 typedef char t_char_array[];
61
62 /**** pointers *******/
63
64 char *v_char_pointer;
65 signed char *v_signed_char_pointer;
66 unsigned char *v_unsigned_char_pointer;
67
68 short *v_short_pointer;
69 signed short *v_signed_short_pointer;
70 unsigned short *v_unsigned_short_pointer;
71
72 int *v_int_pointer;
73 signed int *v_signed_int_pointer;
74 unsigned int *v_unsigned_int_pointer;
75
76 long *v_long_pointer;
77 signed long *v_signed_long_pointer;
78 unsigned long *v_unsigned_long_pointer;
79
80 float *v_float_pointer;
81 double *v_double_pointer;
82
83 /**** structs *******/
84
85 struct t_struct {
86 char v_char_member;
87 short v_short_member;
88 int v_int_member;
89 long v_long_member;
90 float v_float_member;
91 double v_double_member;
92 } v_struct1;
93
94 struct t_struct *v_t_struct_p;
95
96 struct {
97 char v_char_member;
98 short v_short_member;
99 int v_int_member;
100 long v_long_member;
101 float v_float_member;
102 double v_double_member;
103 } v_struct2;
104
105 /* typedef'd struct without a tag. */
106 typedef struct {
107 double v_double_member;
108 int v_int_member;
109 } t_struct3;
110 /* GCC seems to want a variable of this type, or else it won't put out
111 a symbol. */
112 t_struct3 v_struct3;
113
114 /**** unions *******/
115
116 union t_union {
117 char v_char_member;
118 short v_short_member;
119 int v_int_member;
120 long v_long_member;
121 float v_float_member;
122 double v_double_member;
123 } v_union;
124
125 union {
126 char v_char_member;
127 short v_short_member;
128 int v_int_member;
129 long v_long_member;
130 float v_float_member;
131 double v_double_member;
132 } v_union2;
133
134 /* typedef'd union without a tag. */
135 typedef union {
136 double v_double_member;
137 int v_int_member;
138 } t_union3;
139 /* GCC seems to want a variable of this type, or else it won't put out
140 a symbol. */
141 t_union3 v_union3;
142
143 /*** Functions returning type ********/
144
145 char v_char_func () { return(0); }
146 signed char v_signed_char_func () { return (0); }
147 unsigned char v_unsigned_char_func () { return (0); }
148
149 short v_short_func () { return (0); }
150 signed short v_signed_short_func () { return (0); }
151 unsigned short v_unsigned_short_func () { return (0); }
152
153 int v_int_func () { return (0); }
154 signed int v_signed_int_func () { return (0); }
155 unsigned int v_unsigned_int_func () { return (0); }
156
157 long v_long_func () { return (0); }
158 signed long v_signed_long_func () { return (0); }
159 unsigned long v_unsigned_long_func () { return (0); }
160
161 float v_float_func () { return (0.0); }
162 double v_double_func () { return (0.0); }
163
164 /**** Some misc more complicated things *******/
165
166 struct link {
167 struct link *next;
168 #ifdef __STDC__
169 struct link *(*linkfunc) (struct link *this, int flags);
170 #else
171 struct link *(*linkfunc) ();
172 #endif
173 struct t_struct stuff[1][2][3];
174 } *s_link;
175
176 union tu_link {
177 struct link *next;
178 #ifdef __STDC__
179 struct link *(*linkfunc) (struct link *this, int flags);
180 #else
181 struct link *(*linkfunc) ();
182 #endif
183 struct t_struct stuff[1][2][3];
184 } u_link;
185
186 struct outer_struct {
187 int outer_int;
188 struct inner_struct {
189 int inner_int;
190 long inner_long;
191 }inner_struct_instance;
192 union inner_union {
193 int inner_union_int;
194 long inner_union_long;
195 }inner_union_instance;
196 long outer_long;
197 } nested_su;
198
199 /**** Enumerations *******/
200
201 enum
202 /* Work around the bug for compilers which don't put out the right stabs. */
203 #if __GNUC__ < 2 && !defined (_AIX)
204 primary1_tag
205 #endif
206 {red1, green1, blue1} primary1;
207
208 enum {red, green, blue} primary;
209 enum colors {yellow, purple, pink} nonprimary;
210
211 enum {chevy, ford} clunker;
212 enum cars {bmw, porsche} sportscar;
213
214 typedef enum {FALSE, TRUE} boolean;
215 boolean v_boolean;
216 typedef enum bvals {false, true} boolean2;
217 boolean2 v_boolean2;
218
219 enum misordered {two = 2, one = 1, zero = 0, three = 3};
220
221 /***********/
222
223 main ()
224 {
225 /* Ensure that malloc is a pointer type; avoid use of "void" and any include files. */
226 extern char *malloc();
227
228 /* Seems like we need a variable of this type to get the type to be put
229 in the executable, at least for AIX xlc. */
230 enum misordered v_misordered = three;
231
232 /* Some of the tests in ptype.exp require invoking malloc, so make
233 sure it is linked in to this program. */
234 v_char_pointer = (char *) malloc (1);
235
236 #ifdef usestubs
237 set_debug_traps();
238 breakpoint();
239 #endif
240 /* Some linkers (e.g. on AIX) remove unreferenced variables,
241 so make sure to reference them. */
242 primary = blue;
243 primary1 = blue1;
244 nonprimary = pink;
245 sportscar = porsche;
246 clunker = ford;
247 v_struct1.v_int_member = 5;
248 v_struct2.v_int_member = 6;
249 v_struct3.v_int_member = 7;
250
251 v_char = 0;
252 v_signed_char = 0;
253 v_unsigned_char = 0;
254
255 v_short = 0;
256 v_signed_short = 0;
257 v_unsigned_short = 0;
258
259 v_int = 0;
260 v_signed_int = 0;
261 v_unsigned_int = 0;
262
263 v_long = 0;
264 v_signed_long = 0;
265 v_unsigned_long = 0;
266
267 v_float = 0;
268 v_double = 0;
269
270 v_char_array[0] = 0;
271 v_signed_char_array[0] = 0;
272 v_unsigned_char_array[0] = 0;
273
274 v_short_array[0] = 0;
275 v_signed_short_array[0] = 0;
276 v_unsigned_short_array[0] = 0;
277
278 v_int_array[0] = 0;
279 v_signed_int_array[0] = 0;
280 v_unsigned_int_array[0] = 0;
281
282 v_long_array[0] = 0;
283 v_signed_long_array[0] = 0;
284 v_unsigned_long_array[0] = 0;
285
286 v_float_array[0] = 0;
287 v_double_array[0] = 0;
288
289 v_char_pointer = 0;
290 v_signed_char_pointer = 0;
291 v_unsigned_char_pointer = 0;
292
293 v_short_pointer = 0;
294 v_signed_short_pointer = 0;
295 v_unsigned_short_pointer = 0;
296
297 v_int_pointer = 0;
298 v_signed_int_pointer = 0;
299 v_unsigned_int_pointer = 0;
300
301 v_long_pointer = 0;
302 v_signed_long_pointer = 0;
303 v_unsigned_long_pointer = 0;
304
305 v_float_pointer = 0;
306 v_double_pointer = 0;
307
308 nested_su.outer_int = 0;
309 v_t_struct_p = 0;
310
311 v_boolean = FALSE;
312 v_boolean2 = false;
313 }