[gdb/testsuite] Factor out lib/valgrind.exp
[external/binutils.git] / gdb / testsuite / gdb.base / whatis.c
1 /* This test program is part of GDB, the GNU debugger.
2
3    Copyright 1992-2018 Free Software Foundation, Inc.
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
20  *      "whatis" command.
21  */
22
23 /*
24  *      First the basic C types.
25  */
26
27 char            v_char;
28 signed char     v_signed_char;
29 unsigned char   v_unsigned_char;
30
31 short           v_short;
32 signed short    v_signed_short;
33 unsigned short  v_unsigned_short;
34
35 int             v_int;
36 signed int      v_signed_int;
37 unsigned int    v_unsigned_int;
38
39 long            v_long;
40 signed long     v_signed_long;
41 unsigned long   v_unsigned_long;
42
43 #ifndef NO_LONG_LONG
44 long long               v_long_long;
45 signed long long        v_signed_long_long;
46 unsigned long long      v_unsigned_long_long;
47 #endif
48
49 float           v_float;
50 double          v_double;
51
52 /*
53  *      Now some derived types, which are arrays, functions-returning,
54  *      pointers, structures, unions, and enumerations.
55  */
56
57 /**** arrays *******/
58
59 char            v_char_array[2];
60 signed char     v_signed_char_array[2];
61 unsigned char   v_unsigned_char_array[2];
62
63 short           v_short_array[2];
64 signed short    v_signed_short_array[2];
65 unsigned short  v_unsigned_short_array[2];
66
67 int             v_int_array[2];
68 signed int      v_signed_int_array[2];
69 unsigned int    v_unsigned_int_array[2];
70
71 long            v_long_array[2];
72 signed long     v_signed_long_array[2];
73 unsigned long   v_unsigned_long_array[2];
74
75 #ifndef NO_LONG_LONG
76 long long               v_long_long_array[2];
77 signed long long        v_signed_long_long_array[2];
78 unsigned long long      v_unsigned_long_long_array[2];
79 #endif
80
81 float           v_float_array[2];
82 double          v_double_array[2];
83
84 /**** pointers *******/
85
86 /* Make sure they still print as pointer to foo even there is a typedef
87    for that type.  Test this not just for char *, which might be
88    a special case kludge in GDB (Unix system include files like to define
89    caddr_t), but for a variety of types.  */
90 typedef char *char_addr;
91 char_addr a_char_addr;
92 typedef unsigned short *ushort_addr;
93 ushort_addr a_ushort_addr;
94 typedef signed long *slong_addr;
95 slong_addr a_slong_addr;
96 #ifndef NO_LONG_LONG
97 typedef signed long long *slong_long_addr;
98 slong_long_addr a_slong_long_addr;
99 #endif
100
101 char            *v_char_pointer;
102 signed char     *v_signed_char_pointer;
103 unsigned char   *v_unsigned_char_pointer;
104
105 short           *v_short_pointer;
106 signed short    *v_signed_short_pointer;
107 unsigned short  *v_unsigned_short_pointer;
108
109 int             *v_int_pointer;
110 signed int      *v_signed_int_pointer;
111 unsigned int    *v_unsigned_int_pointer;
112
113 long            *v_long_pointer;
114 signed long     *v_signed_long_pointer;
115 unsigned long   *v_unsigned_long_pointer;
116
117 #ifndef NO_LONG_LONG
118 long long               *v_long_long_pointer;
119 signed long long        *v_signed_long_long_pointer;
120 unsigned long long      *v_unsigned_long_long_pointer;
121 #endif
122
123 float           *v_float_pointer;
124 double          *v_double_pointer;
125
126 /**** structs *******/
127
128 struct t_struct {
129     char        v_char_member;
130     short       v_short_member;
131     int         v_int_member;
132     long        v_long_member;
133 #ifndef NO_LONG_LONG
134     long long   v_long_long_member;
135 #endif
136     float       v_float_member;
137     double      v_double_member;
138 } v_struct1, *v_struct_ptr1;
139
140 struct {
141     char        v_char_member;
142     short       v_short_member;
143     int         v_int_member;
144     long        v_long_member;
145 #ifndef NO_LONG_LONG
146     long long   v_long_long_member;
147 #endif
148     float       v_float_member;
149     double      v_double_member;
150 } v_struct2, *v_struct_ptr2;
151
152 /**** unions *******/
153
154 union t_union {
155     char        v_char_member;
156     short       v_short_member;
157     int         v_int_member;
158     long        v_long_member;
159 #ifndef NO_LONG_LONG
160     long long   v_long_long_member;
161 #endif
162     float       v_float_member;
163     double      v_double_member;
164 } v_union, *v_union_ptr;
165
166 union {
167     char        v_char_member;
168     short       v_short_member;
169     int         v_int_member;
170     long        v_long_member;
171 #ifndef NO_LONG_LONG
172     long long   v_long_long_member;
173 #endif
174     float       v_float_member;
175     double      v_double_member;
176 } v_union2, *v_union_ptr2;
177
178 /*** Functions returning type ********/
179
180 char            v_char_func () { return(0); }
181 signed char     v_signed_char_func () { return (0); }
182 unsigned char   v_unsigned_char_func () { return (0); }
183
184 short           v_short_func () { return (0); }
185 signed short    v_signed_short_func () { return (0); }
186 unsigned short  v_unsigned_short_func () { return (0); }
187
188 int             v_int_func () { return (0); }
189 signed int      v_signed_int_func () { return (0); }
190 unsigned int    v_unsigned_int_func () { return (0); }
191
192 long            v_long_func () { return (0); }
193 signed long     v_signed_long_func () { return (0); }
194 unsigned long   v_unsigned_long_func () { return (0); }
195
196 #ifndef NO_LONG_LONG
197 long long               v_long_long_func () { return (0); }
198 signed long long        v_signed_long_long_func () { return (0); }
199 unsigned long long      v_unsigned_long_long_func () { return (0); }
200 #endif
201
202 float           v_float_func () { return (0.0); }
203 double          v_double_func () { return (0.0); }
204
205 /**** Some misc more complicated things *******/
206
207 struct link {
208         struct link *next;
209 #ifdef __STDC__
210         struct link *(*linkfunc) (struct link *this, int flags);
211 #else
212         struct link *(*linkfunc) ();
213 #endif
214         struct t_struct stuff[1][2][3];
215 } *s_link;
216
217 union tu_link {
218         struct link *next;
219 #ifdef __STDC__
220         struct link *(*linkfunc) (struct link *this, int flags);
221 #else
222         struct link *(*linkfunc) ();
223 #endif
224         struct t_struct stuff[1][2][3];
225 } u_link;
226
227 struct outer_struct {
228         int outer_int;
229         struct inner_struct {
230                 int inner_int;
231                 long inner_long;
232         }inner_struct_instance;
233         union inner_union {
234                 int inner_union_int;
235                 long inner_union_long;
236         }inner_union_instance;
237         long outer_long;
238 } nested_su;
239
240 /**** Enumerations *******/
241
242 enum colors {red, green, blue} color;
243 enum cars {chevy, ford, porsche} clunker;
244
245 /***********/
246
247 int main ()
248 {
249   /* Some linkers (e.g. on AIX) remove unreferenced variables,
250      so make sure to reference them. */
251   v_char = 0;
252   v_signed_char = 1;
253   v_unsigned_char = 2;
254
255   v_short = 3;
256   v_signed_short = 4;
257   v_unsigned_short = 5;    
258
259   v_int = 6;
260   v_signed_int = 7;
261   v_unsigned_int = 8;    
262
263   v_long = 9;
264   v_signed_long = 10;
265   v_unsigned_long = 11;    
266
267 #ifndef NO_LONG_LONG
268   v_long_long = 12;
269   v_signed_long_long = 13;
270   v_unsigned_long_long = 14;
271 #endif
272
273   v_float = 100.0;
274   v_double = 200.0;
275
276
277   v_char_array[0] = v_char;
278   v_signed_char_array[0] = v_signed_char;
279   v_unsigned_char_array[0] = v_unsigned_char;
280
281   v_short_array[0] = v_short;
282   v_signed_short_array[0] = v_signed_short;
283   v_unsigned_short_array[0] = v_unsigned_short;
284
285   v_int_array[0] = v_int;
286   v_signed_int_array[0] = v_signed_int;
287   v_unsigned_int_array[0] = v_unsigned_int;
288
289   v_long_array[0] = v_long;
290   v_signed_long_array[0] = v_signed_long;
291   v_unsigned_long_array[0] = v_unsigned_long;
292
293 #ifndef NO_LONG_LONG
294   v_long_long_array[0] = v_long_long;
295   v_signed_long_long_array[0] = v_signed_long_long;
296   v_unsigned_long_long_array[0] = v_unsigned_long_long;
297 #endif
298
299   v_float_array[0] = v_float;
300   v_double_array[0] = v_double;
301
302   v_char_pointer = &v_char;
303   v_signed_char_pointer = &v_signed_char;
304   v_unsigned_char_pointer = &v_unsigned_char;
305
306   v_short_pointer = &v_short;
307   v_signed_short_pointer = &v_signed_short;
308   v_unsigned_short_pointer = &v_unsigned_short;
309
310   v_int_pointer = &v_int;
311   v_signed_int_pointer = &v_signed_int;
312   v_unsigned_int_pointer = &v_unsigned_int;
313
314   v_long_pointer = &v_long;
315   v_signed_long_pointer = &v_signed_long;
316   v_unsigned_long_pointer = &v_unsigned_long;
317
318 #ifndef NO_LONG_LONG
319   v_long_long_pointer = &v_long_long;
320   v_signed_long_long_pointer = &v_signed_long_long;
321   v_unsigned_long_long_pointer = &v_unsigned_long_long;
322 #endif
323
324   v_float_pointer = &v_float;
325   v_double_pointer = &v_double;
326
327   color = red;
328   clunker = porsche;
329
330   u_link.next = s_link;
331
332   v_union2.v_short_member = v_union.v_short_member;
333
334   v_struct1.v_char_member = 0;
335   v_struct2.v_char_member = 0;
336
337   nested_su.outer_int = 0;
338   return 0;
339 }