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