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