Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / ctf-ptype.c
CommitLineData
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
31char v_char;
32signed char v_signed_char;
33unsigned char v_unsigned_char;
34
35short v_short;
36signed short v_signed_short;
37unsigned short v_unsigned_short;
38
39int v_int;
40signed int v_signed_int;
41unsigned int v_unsigned_int;
42
43long v_long;
44signed long v_signed_long;
45unsigned long v_unsigned_long;
46
47float v_float;
48double v_double;
49
50/**** arrays *******/
51
52char v_char_array[2];
53signed char v_signed_char_array[2];
54unsigned char v_unsigned_char_array[2];
55
56short v_short_array[2];
57signed short v_signed_short_array[2];
58unsigned short v_unsigned_short_array[2];
59
60int v_int_array[2];
61signed int v_signed_int_array[2];
62unsigned int v_unsigned_int_array[2];
63
64long v_long_array[2];
65signed long v_signed_long_array[2];
66unsigned long v_unsigned_long_array[2];
67
68float v_float_array[2];
69double v_double_array[2];
70
71/* PR 3742 */
72typedef char t_char_array[];
73t_char_array *pv_char_array;
74
75/**** pointers *******/
76
77char *v_char_pointer;
78signed char *v_signed_char_pointer;
79unsigned char *v_unsigned_char_pointer;
80
81short *v_short_pointer;
82signed short *v_signed_short_pointer;
83unsigned short *v_unsigned_short_pointer;
84
85int *v_int_pointer;
86signed int *v_signed_int_pointer;
87unsigned int *v_unsigned_int_pointer;
88
89long *v_long_pointer;
90signed long *v_signed_long_pointer;
91unsigned long *v_unsigned_long_pointer;
92
93float *v_float_pointer;
94double *v_double_pointer;
95
96/**** structs *******/
97
98struct 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
107struct t_struct *v_t_struct_p;
108
109struct {
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. */
119typedef 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. */
125t_struct3 v_struct3;
126
dc2b480f
WP
127/**** Some misc more complicated things *******/
128
129struct 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
141union 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
150union {
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. */
160typedef 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. */
166t_union3 v_union3;
167
168/**** Some misc more complicated things *******/
169
170struct 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
183struct 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
195enum
196/* Work around the bug for compilers which don't put out the right stabs. */
197#if __GNUC__ < 2 && !defined (_AIX)
198primary1_tag
199#endif
200{red1, green1, blue1} primary1;
201
202enum {red, green, blue} primary;
203enum colors {yellow, purple, pink} nonprimary;
204
205enum {chevy, ford} clunker;
206enum cars {bmw, porsche} sportscar;
207
208#undef FALSE
209#undef TRUE
210typedef enum {FALSE, TRUE} boolean;
211boolean v_boolean;
212/*note: aCC has bool type predefined with 'false' and 'true'*/
213typedef enum bvals {my_false, my_true} boolean2;
214boolean2 v_boolean2;
215
216enum 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. */
220enum misordered v_misordered = three;
221
222/**** Pointers to functions *******/
223
224typedef int (*func_type) (int (*) (int, float), float);
225double (*old_fptr) ();
226double (*new_fptr) (void);
227int (*fptr) (int, float);
228int *(*fptr2) (int (*) (int, float), float);
229int (*xptr) (int (*) (), int (*) (void), int);
230int (*(*ffptr) (char)) (short);
231int (*(*(*fffptr) (char)) (short)) (long);
232
233func_type v_func_type;
234
235int 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}
This page took 0.330979 seconds and 4 git commands to generate.