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