OSDN Git Service

2004-08-23 Michael Chastain <mec.gnu@mindspring.com>
[pf3gnuchains/pf3gnuchains4x.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
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 2 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, write to the Free Software
18    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19    */
20
21 /*
22  *      Test file with lots of different types, for testing the
23  *      "whatis" command.
24  */
25
26 /*
27  *      First the basic C types.
28  */
29
30 #if !(defined (__STDC__) || defined (_AIX))
31 #define signed  /**/
32 #endif
33
34 char            v_char;
35 signed char     v_signed_char;
36 unsigned char   v_unsigned_char;
37
38 short           v_short;
39 signed short    v_signed_short;
40 unsigned short  v_unsigned_short;
41
42 int             v_int;
43 signed int      v_signed_int;
44 unsigned int    v_unsigned_int;
45
46 long            v_long;
47 signed long     v_signed_long;
48 unsigned long   v_unsigned_long;
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 float           v_float_array[2];
77 double          v_double_array[2];
78
79 /**** pointers *******/
80
81 /* Make sure they still print as pointer to foo even there is a typedef
82    for that type.  Test this not just for char *, which might be
83    a special case kludge in GDB (Unix system include files like to define
84    caddr_t), but for a variety of types.  */
85 typedef char *char_addr;
86 typedef unsigned short *ushort_addr;
87 typedef signed long *slong_addr;
88
89 char            *v_char_pointer;
90 signed char     *v_signed_char_pointer;
91 unsigned char   *v_unsigned_char_pointer;
92
93 short           *v_short_pointer;
94 signed short    *v_signed_short_pointer;
95 unsigned short  *v_unsigned_short_pointer;
96
97 int             *v_int_pointer;
98 signed int      *v_signed_int_pointer;
99 unsigned int    *v_unsigned_int_pointer;
100
101 long            *v_long_pointer;
102 signed long     *v_signed_long_pointer;
103 unsigned long   *v_unsigned_long_pointer;
104
105 float           *v_float_pointer;
106 double          *v_double_pointer;
107
108 /**** structs *******/
109
110 struct t_struct {
111     char        v_char_member;
112     short       v_short_member;
113     int         v_int_member;
114     long        v_long_member;
115     float       v_float_member;
116     double      v_double_member;
117 } v_struct1;
118
119 struct {
120     char        v_char_member;
121     short       v_short_member;
122     int         v_int_member;
123     long        v_long_member;
124     float       v_float_member;
125     double      v_double_member;
126 } v_struct2;
127
128 /**** unions *******/
129
130 union t_union {
131     char        v_char_member;
132     short       v_short_member;
133     int         v_int_member;
134     long        v_long_member;
135     float       v_float_member;
136     double      v_double_member;
137 } v_union;
138
139 union {
140     char        v_char_member;
141     short       v_short_member;
142     int         v_int_member;
143     long        v_long_member;
144     float       v_float_member;
145     double      v_double_member;
146 } v_union2;
147
148 /*** Functions returning type ********/
149
150 char            v_char_func () { return(0); }
151 signed char     v_signed_char_func () { return (0); }
152 unsigned char   v_unsigned_char_func () { return (0); }
153
154 short           v_short_func () { return (0); }
155 signed short    v_signed_short_func () { return (0); }
156 unsigned short  v_unsigned_short_func () { return (0); }
157
158 int             v_int_func () { return (0); }
159 signed int      v_signed_int_func () { return (0); }
160 unsigned int    v_unsigned_int_func () { return (0); }
161
162 long            v_long_func () { return (0); }
163 signed long     v_signed_long_func () { return (0); }
164 unsigned long   v_unsigned_long_func () { return (0); }
165
166 float           v_float_func () { return (0.0); }
167 double          v_double_func () { return (0.0); }
168
169 /**** Some misc more complicated things *******/
170
171 struct link {
172         struct link *next;
173 #ifdef __STDC__
174         struct link *(*linkfunc) (struct link *this, int flags);
175 #else
176         struct link *(*linkfunc) ();
177 #endif
178         struct t_struct stuff[1][2][3];
179 } *s_link;
180
181 union tu_link {
182         struct link *next;
183 #ifdef __STDC__
184         struct link *(*linkfunc) (struct link *this, int flags);
185 #else
186         struct link *(*linkfunc) ();
187 #endif
188         struct t_struct stuff[1][2][3];
189 } u_link;
190
191 struct outer_struct {
192         int outer_int;
193         struct inner_struct {
194                 int inner_int;
195                 long inner_long;
196         }inner_struct_instance;
197         union inner_union {
198                 int inner_union_int;
199                 long inner_union_long;
200         }inner_union_instance;
201         long outer_long;
202 } nested_su;
203
204 /**** Enumerations *******/
205
206 enum colors {red, green, blue} color;
207 enum cars {chevy, ford, porsche} clunker;
208
209 /***********/
210
211 int main ()
212 {
213 #ifdef usestubs
214   set_debug_traps();
215   breakpoint();
216 #endif
217   /* Some linkers (e.g. on AIX) remove unreferenced variables,
218      so make sure to reference them. */
219   v_char = 0;
220   v_signed_char = 1;
221   v_unsigned_char = 2;
222
223   v_short = 3;
224   v_signed_short = 4;
225   v_unsigned_short = 5;    
226
227   v_int = 6;
228   v_signed_int = 7;
229   v_unsigned_int = 8;    
230
231   v_long = 9;
232   v_signed_long = 10;
233   v_unsigned_long = 11;    
234   
235   v_float = 100.0;
236   v_double = 200.0;
237
238
239   v_char_array[0] = v_char;
240   v_signed_char_array[0] = v_signed_char;
241   v_unsigned_char_array[0] = v_unsigned_char;
242
243   v_short_array[0] = v_short;
244   v_signed_short_array[0] = v_signed_short;
245   v_unsigned_short_array[0] = v_unsigned_short;
246
247   v_int_array[0] = v_int;
248   v_signed_int_array[0] = v_signed_int;
249   v_unsigned_int_array[0] = v_unsigned_int;
250
251   v_long_array[0] = v_long;
252   v_signed_long_array[0] = v_signed_long;
253   v_unsigned_long_array[0] = v_unsigned_long;
254
255   v_float_array[0] = v_float;
256   v_double_array[0] = v_double;
257
258   v_char_pointer = &v_char;
259   v_signed_char_pointer = &v_signed_char;
260   v_unsigned_char_pointer = &v_unsigned_char;
261
262   v_short_pointer = &v_short;
263   v_signed_short_pointer = &v_signed_short;
264   v_unsigned_short_pointer = &v_unsigned_short;
265
266   v_int_pointer = &v_int;
267   v_signed_int_pointer = &v_signed_int;
268   v_unsigned_int_pointer = &v_unsigned_int;
269
270   v_long_pointer = &v_long;
271   v_signed_long_pointer = &v_signed_long;
272   v_unsigned_long_pointer = &v_unsigned_long;
273
274   v_float_pointer = &v_float;
275   v_double_pointer = &v_double;
276
277   color = red;
278   clunker = porsche;
279
280   u_link.next = s_link;
281
282   v_union2.v_short_member = v_union.v_short_member;
283
284   v_struct1.v_char_member = 0;
285   v_struct2.v_char_member = 0;
286
287   nested_su.outer_int = 0;
288   return 0;
289 }