]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/ctf-ptype.c
Update copyright year range in all GDB files
[thirdparty/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
3666a048 3 Copyright 2019-2021 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
127/**** unions *******/
128
129union t_union {
130 char v_char_member;
131 short v_short_member;
132 int v_int_member;
133 long v_long_member;
134 float v_float_member;
135 double v_double_member;
136} v_union;
137
138union {
139 char v_char_member;
140 short v_short_member;
141 int v_int_member;
142 long v_long_member;
143 float v_float_member;
144 double v_double_member;
145} v_union2;
146
147/* typedef'd union without a tag. */
148typedef union {
149 double v_double_member;
150 int v_int_member;
151} t_union3;
152/* GCC seems to want a variable of this type, or else it won't put out
153 a symbol. */
154t_union3 v_union3;
155
156/**** Some misc more complicated things *******/
157
158struct outer_struct {
159 int outer_int;
160 struct inner_struct {
161 int inner_int;
162 long inner_long;
163 }inner_struct_instance;
164 union inner_union {
165 int inner_union_int;
166 long inner_union_long;
167 }inner_union_instance;
168 long outer_long;
169} nested_su;
170
171struct highest
172{
173 int a;
174 struct
175 {
176 int b;
177 struct { int c; } anonymous_level_2;
178 } anonymous_level_1;
179} the_highest;
180
181/**** Enumerations *******/
182
183enum
184/* Work around the bug for compilers which don't put out the right stabs. */
185#if __GNUC__ < 2 && !defined (_AIX)
186primary1_tag
187#endif
188{red1, green1, blue1} primary1;
189
190enum {red, green, blue} primary;
191enum colors {yellow, purple, pink} nonprimary;
192
193enum {chevy, ford} clunker;
194enum cars {bmw, porsche} sportscar;
195
196#undef FALSE
197#undef TRUE
198typedef enum {FALSE, TRUE} boolean;
199boolean v_boolean;
200/*note: aCC has bool type predefined with 'false' and 'true'*/
201typedef enum bvals {my_false, my_true} boolean2;
202boolean2 v_boolean2;
203
204enum misordered {two = 2, one = 1, zero = 0, three = 3};
205
206/* Seems like we need a variable of this type to get the type to be put
207 in the executable, at least for AIX xlc. */
208enum misordered v_misordered = three;
209
210/**** Pointers to functions *******/
211
212typedef int (*func_type) (int (*) (int, float), float);
213double (*old_fptr) ();
214double (*new_fptr) (void);
215int (*fptr) (int, float);
216int *(*fptr2) (int (*) (int, float), float);
217int (*xptr) (int (*) (), int (*) (void), int);
218int (*(*ffptr) (char)) (short);
219int (*(*(*fffptr) (char)) (short)) (long);
220
221func_type v_func_type;
222
223int main ()
224{
225 /* Ensure that malloc is a pointer type; avoid use of "void" and any include files. */
226/* extern char *malloc();*/
227
228 /* Some of the tests in ptype.exp require invoking malloc, so make
229 sure it is linked in to this program. */
230 v_char_pointer = (char *) malloc (1);
231
232 /* Some linkers (e.g. on AIX) remove unreferenced variables,
233 so make sure to reference them. */
234 primary = blue;
235 primary1 = blue1;
236 nonprimary = pink;
237 sportscar = porsche;
238 clunker = ford;
239 v_struct1.v_int_member = 5;
240 v_struct2.v_int_member = 6;
241 v_struct3.v_int_member = 7;
242
243 v_char = 0;
244 v_signed_char = 0;
245 v_unsigned_char = 0;
246
247 v_short = 0;
248 v_signed_short = 0;
249 v_unsigned_short = 0;
250
251 v_int = 0;
252 v_signed_int = 0;
253 v_unsigned_int = 0;
254
255 v_long = 0;
256 v_signed_long = 0;
257 v_unsigned_long = 0;
258
259 v_float = 0;
260 v_double = 0;
261
262 v_char_array[0] = 0;
263 v_signed_char_array[0] = 0;
264 v_unsigned_char_array[0] = 0;
265
266 v_short_array[0] = 0;
267 v_signed_short_array[0] = 0;
268 v_unsigned_short_array[0] = 0;
269
270 v_int_array[0] = 0;
271 v_signed_int_array[0] = 0;
272 v_unsigned_int_array[0] = 0;
273
274 v_long_array[0] = 0;
275 v_signed_long_array[0] = 0;
276 v_unsigned_long_array[0] = 0;
277
278 v_float_array[0] = 0;
279 v_double_array[0] = 0;
280
281 v_char_pointer = 0;
282 v_signed_char_pointer = 0;
283 v_unsigned_char_pointer = 0;
284
285 v_short_pointer = 0;
286 v_signed_short_pointer = 0;
287 v_unsigned_short_pointer = 0;
288
289 v_int_pointer = 0;
290 v_signed_int_pointer = 0;
291 v_unsigned_int_pointer = 0;
292
293 v_long_pointer = 0;
294 v_signed_long_pointer = 0;
295 v_unsigned_long_pointer = 0;
296
297 v_float_pointer = 0;
298 v_double_pointer = 0;
299
300 nested_su.outer_int = 0;
301 v_t_struct_p = 0;
302
303 the_highest.a = 0;
304 return 0;
305}