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