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