]>
Commit | Line | Data |
---|---|---|
1ab3bf1b | 1 | /* Support routines for manipulating internal types for GDB. |
2447e9af | 2 | Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. |
1ab3bf1b JG |
3 | Contributed by Cygnus Support, using pieces from other GDB modules. |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
6c9638b4 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
1ab3bf1b | 20 | |
1ab3bf1b | 21 | #include "defs.h" |
2b576293 | 22 | #include "gdb_string.h" |
1ab3bf1b JG |
23 | #include "bfd.h" |
24 | #include "symtab.h" | |
25 | #include "symfile.h" | |
5e2e79f8 | 26 | #include "objfiles.h" |
1ab3bf1b JG |
27 | #include "gdbtypes.h" |
28 | #include "expression.h" | |
29 | #include "language.h" | |
30 | #include "target.h" | |
31 | #include "value.h" | |
8f793aa5 | 32 | #include "demangle.h" |
51b80b00 | 33 | #include "complaints.h" |
1ab3bf1b | 34 | |
c4413e2c FF |
35 | /* These variables point to the objects |
36 | representing the predefined C data types. */ | |
37 | ||
38 | struct type *builtin_type_void; | |
39 | struct type *builtin_type_char; | |
40 | struct type *builtin_type_short; | |
41 | struct type *builtin_type_int; | |
42 | struct type *builtin_type_long; | |
43 | struct type *builtin_type_long_long; | |
44 | struct type *builtin_type_signed_char; | |
45 | struct type *builtin_type_unsigned_char; | |
46 | struct type *builtin_type_unsigned_short; | |
47 | struct type *builtin_type_unsigned_int; | |
48 | struct type *builtin_type_unsigned_long; | |
49 | struct type *builtin_type_unsigned_long_long; | |
50 | struct type *builtin_type_float; | |
51 | struct type *builtin_type_double; | |
52 | struct type *builtin_type_long_double; | |
53 | struct type *builtin_type_complex; | |
54 | struct type *builtin_type_double_complex; | |
55 | struct type *builtin_type_string; | |
56 | ||
b607efe7 FF |
57 | struct extra { char str[128]; int len; }; /* maximum extention is 128! FIXME */ |
58 | ||
59 | static void add_name PARAMS ((struct extra *, char *)); | |
60 | static void add_mangled_type PARAMS ((struct extra *, struct type *)); | |
61 | #if 0 | |
62 | static void cfront_mangle_name PARAMS ((struct type *, int, int)); | |
63 | #endif | |
64 | static void print_bit_vector PARAMS ((B_TYPE *, int)); | |
65 | static void print_arg_types PARAMS ((struct type **, int)); | |
66 | static void dump_fn_fieldlists PARAMS ((struct type *, int)); | |
67 | static void print_cplus_stuff PARAMS ((struct type *, int)); | |
68 | ||
1ab3bf1b JG |
69 | /* Alloc a new type structure and fill it with some defaults. If |
70 | OBJFILE is non-NULL, then allocate the space for the type structure | |
71 | in that objfile's type_obstack. */ | |
72 | ||
73 | struct type * | |
74 | alloc_type (objfile) | |
75 | struct objfile *objfile; | |
76 | { | |
77 | register struct type *type; | |
78 | ||
79 | /* Alloc the structure and start off with all fields zeroed. */ | |
80 | ||
81 | if (objfile == NULL) | |
82 | { | |
83 | type = (struct type *) xmalloc (sizeof (struct type)); | |
84 | } | |
85 | else | |
86 | { | |
87 | type = (struct type *) obstack_alloc (&objfile -> type_obstack, | |
88 | sizeof (struct type)); | |
2dd30c72 | 89 | OBJSTAT (objfile, n_types++); |
1ab3bf1b | 90 | } |
dac9734e | 91 | memset ((char *) type, 0, sizeof (struct type)); |
1ab3bf1b JG |
92 | |
93 | /* Initialize the fields that might not be zero. */ | |
94 | ||
95 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
96 | TYPE_OBJFILE (type) = objfile; | |
97 | TYPE_VPTR_FIELDNO (type) = -1; | |
98 | ||
99 | return (type); | |
100 | } | |
101 | ||
ea1549b3 JG |
102 | /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points |
103 | to a pointer to memory where the pointer type should be stored. | |
104 | If *TYPEPTR is zero, update it to point to the pointer type we return. | |
105 | We allocate new memory if needed. */ | |
106 | ||
107 | struct type * | |
108 | make_pointer_type (type, typeptr) | |
109 | struct type *type; | |
110 | struct type **typeptr; | |
111 | { | |
112 | register struct type *ntype; /* New type */ | |
113 | struct objfile *objfile; | |
114 | ||
115 | ntype = TYPE_POINTER_TYPE (type); | |
116 | ||
117 | if (ntype) | |
118 | if (typeptr == 0) | |
119 | return ntype; /* Don't care about alloc, and have new type. */ | |
120 | else if (*typeptr == 0) | |
121 | { | |
122 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ | |
123 | return ntype; | |
124 | } | |
125 | ||
126 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
127 | { | |
128 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
129 | if (typeptr) | |
130 | *typeptr = ntype; | |
131 | } | |
132 | else /* We have storage, but need to reset it. */ | |
133 | { | |
134 | ntype = *typeptr; | |
135 | objfile = TYPE_OBJFILE (ntype); | |
dac9734e | 136 | memset ((char *) ntype, 0, sizeof (struct type)); |
ea1549b3 JG |
137 | TYPE_OBJFILE (ntype) = objfile; |
138 | } | |
139 | ||
140 | TYPE_TARGET_TYPE (ntype) = type; | |
141 | TYPE_POINTER_TYPE (type) = ntype; | |
142 | ||
143 | /* FIXME! Assume the machine has only one representation for pointers! */ | |
144 | ||
145 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; | |
146 | TYPE_CODE (ntype) = TYPE_CODE_PTR; | |
147 | ||
148 | /* pointers are unsigned */ | |
149 | TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED; | |
150 | ||
151 | if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */ | |
152 | TYPE_POINTER_TYPE (type) = ntype; | |
153 | ||
154 | return ntype; | |
155 | } | |
156 | ||
1ab3bf1b JG |
157 | /* Given a type TYPE, return a type of pointers to that type. |
158 | May need to construct such a type if this is the first use. */ | |
159 | ||
160 | struct type * | |
161 | lookup_pointer_type (type) | |
162 | struct type *type; | |
163 | { | |
ea1549b3 JG |
164 | return make_pointer_type (type, (struct type **)0); |
165 | } | |
166 | ||
167 | /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points | |
168 | to a pointer to memory where the reference type should be stored. | |
169 | If *TYPEPTR is zero, update it to point to the reference type we return. | |
170 | We allocate new memory if needed. */ | |
171 | ||
172 | struct type * | |
173 | make_reference_type (type, typeptr) | |
174 | struct type *type; | |
175 | struct type **typeptr; | |
176 | { | |
177 | register struct type *ntype; /* New type */ | |
178 | struct objfile *objfile; | |
179 | ||
180 | ntype = TYPE_REFERENCE_TYPE (type); | |
1ab3bf1b | 181 | |
ea1549b3 JG |
182 | if (ntype) |
183 | if (typeptr == 0) | |
184 | return ntype; /* Don't care about alloc, and have new type. */ | |
185 | else if (*typeptr == 0) | |
186 | { | |
187 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ | |
188 | return ntype; | |
189 | } | |
190 | ||
191 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
192 | { | |
193 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
194 | if (typeptr) | |
195 | *typeptr = ntype; | |
196 | } | |
197 | else /* We have storage, but need to reset it. */ | |
1ab3bf1b | 198 | { |
ea1549b3 JG |
199 | ntype = *typeptr; |
200 | objfile = TYPE_OBJFILE (ntype); | |
dac9734e | 201 | memset ((char *) ntype, 0, sizeof (struct type)); |
ea1549b3 | 202 | TYPE_OBJFILE (ntype) = objfile; |
1ab3bf1b | 203 | } |
ea1549b3 JG |
204 | |
205 | TYPE_TARGET_TYPE (ntype) = type; | |
206 | TYPE_REFERENCE_TYPE (type) = ntype; | |
207 | ||
208 | /* FIXME! Assume the machine has only one representation for references, | |
209 | and that it matches the (only) representation for pointers! */ | |
210 | ||
211 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; | |
212 | TYPE_CODE (ntype) = TYPE_CODE_REF; | |
213 | ||
214 | if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ | |
215 | TYPE_REFERENCE_TYPE (type) = ntype; | |
216 | ||
217 | return ntype; | |
1ab3bf1b JG |
218 | } |
219 | ||
ea1549b3 JG |
220 | /* Same as above, but caller doesn't care about memory allocation details. */ |
221 | ||
1ab3bf1b JG |
222 | struct type * |
223 | lookup_reference_type (type) | |
224 | struct type *type; | |
225 | { | |
ea1549b3 JG |
226 | return make_reference_type (type, (struct type **)0); |
227 | } | |
228 | ||
229 | /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points | |
230 | to a pointer to memory where the function type should be stored. | |
231 | If *TYPEPTR is zero, update it to point to the function type we return. | |
232 | We allocate new memory if needed. */ | |
1ab3bf1b | 233 | |
ea1549b3 JG |
234 | struct type * |
235 | make_function_type (type, typeptr) | |
236 | struct type *type; | |
237 | struct type **typeptr; | |
238 | { | |
239 | register struct type *ntype; /* New type */ | |
240 | struct objfile *objfile; | |
241 | ||
ea1549b3 | 242 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ |
1ab3bf1b | 243 | { |
ea1549b3 JG |
244 | ntype = alloc_type (TYPE_OBJFILE (type)); |
245 | if (typeptr) | |
246 | *typeptr = ntype; | |
1ab3bf1b | 247 | } |
ea1549b3 JG |
248 | else /* We have storage, but need to reset it. */ |
249 | { | |
250 | ntype = *typeptr; | |
251 | objfile = TYPE_OBJFILE (ntype); | |
dac9734e | 252 | memset ((char *) ntype, 0, sizeof (struct type)); |
ea1549b3 JG |
253 | TYPE_OBJFILE (ntype) = objfile; |
254 | } | |
255 | ||
256 | TYPE_TARGET_TYPE (ntype) = type; | |
ea1549b3 JG |
257 | |
258 | TYPE_LENGTH (ntype) = 1; | |
259 | TYPE_CODE (ntype) = TYPE_CODE_FUNC; | |
260 | ||
ea1549b3 | 261 | return ntype; |
1ab3bf1b JG |
262 | } |
263 | ||
ea1549b3 | 264 | |
1ab3bf1b JG |
265 | /* Given a type TYPE, return a type of functions that return that type. |
266 | May need to construct such a type if this is the first use. */ | |
267 | ||
268 | struct type * | |
269 | lookup_function_type (type) | |
270 | struct type *type; | |
271 | { | |
ea1549b3 | 272 | return make_function_type (type, (struct type **)0); |
1ab3bf1b JG |
273 | } |
274 | ||
275 | /* Implement direct support for MEMBER_TYPE in GNU C++. | |
276 | May need to construct such a type if this is the first use. | |
277 | The TYPE is the type of the member. The DOMAIN is the type | |
278 | of the aggregate that the member belongs to. */ | |
279 | ||
280 | struct type * | |
281 | lookup_member_type (type, domain) | |
282 | struct type *type; | |
283 | struct type *domain; | |
284 | { | |
285 | register struct type *mtype; | |
286 | ||
287 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
288 | smash_to_member_type (mtype, domain, type); | |
289 | return (mtype); | |
290 | } | |
291 | ||
292 | /* Allocate a stub method whose return type is TYPE. | |
293 | This apparently happens for speed of symbol reading, since parsing | |
294 | out the arguments to the method is cpu-intensive, the way we are doing | |
295 | it. So, we will fill in arguments later. | |
296 | This always returns a fresh type. */ | |
297 | ||
298 | struct type * | |
299 | allocate_stub_method (type) | |
300 | struct type *type; | |
301 | { | |
302 | struct type *mtype; | |
303 | ||
304 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
305 | TYPE_TARGET_TYPE (mtype) = type; | |
306 | /* _DOMAIN_TYPE (mtype) = unknown yet */ | |
307 | /* _ARG_TYPES (mtype) = unknown yet */ | |
308 | TYPE_FLAGS (mtype) = TYPE_FLAG_STUB; | |
309 | TYPE_CODE (mtype) = TYPE_CODE_METHOD; | |
310 | TYPE_LENGTH (mtype) = 1; | |
311 | return (mtype); | |
312 | } | |
313 | ||
a8a69e63 | 314 | /* Create a range type using either a blank type supplied in RESULT_TYPE, |
ec16f701 FF |
315 | or creating a new type, inheriting the objfile from INDEX_TYPE. |
316 | ||
317 | Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to | |
318 | HIGH_BOUND, inclusive. | |
a8a69e63 FF |
319 | |
320 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
321 | sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ | |
322 | ||
323 | struct type * | |
324 | create_range_type (result_type, index_type, low_bound, high_bound) | |
325 | struct type *result_type; | |
326 | struct type *index_type; | |
327 | int low_bound; | |
328 | int high_bound; | |
329 | { | |
330 | if (result_type == NULL) | |
331 | { | |
332 | result_type = alloc_type (TYPE_OBJFILE (index_type)); | |
333 | } | |
334 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; | |
335 | TYPE_TARGET_TYPE (result_type) = index_type; | |
e55a5796 PB |
336 | if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB) |
337 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; | |
338 | else | |
d1f4065e | 339 | TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); |
a8a69e63 FF |
340 | TYPE_NFIELDS (result_type) = 2; |
341 | TYPE_FIELDS (result_type) = (struct field *) | |
342 | TYPE_ALLOC (result_type, 2 * sizeof (struct field)); | |
343 | memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field)); | |
344 | TYPE_FIELD_BITPOS (result_type, 0) = low_bound; | |
345 | TYPE_FIELD_BITPOS (result_type, 1) = high_bound; | |
346 | TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */ | |
347 | TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */ | |
348 | ||
349 | return (result_type); | |
350 | } | |
351 | ||
706bfe5a PB |
352 | /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE. |
353 | Return 1 of type is a range type, 0 if it is discrete (and bounds | |
354 | will fit in LONGEST), or -1 otherwise. */ | |
355 | ||
356 | int | |
357 | get_discrete_bounds (type, lowp, highp) | |
358 | struct type *type; | |
359 | LONGEST *lowp, *highp; | |
360 | { | |
d1f4065e | 361 | CHECK_TYPEDEF (type); |
706bfe5a PB |
362 | switch (TYPE_CODE (type)) |
363 | { | |
4dda8ef3 | 364 | case TYPE_CODE_RANGE: |
706bfe5a PB |
365 | *lowp = TYPE_LOW_BOUND (type); |
366 | *highp = TYPE_HIGH_BOUND (type); | |
367 | return 1; | |
368 | case TYPE_CODE_ENUM: | |
d1f4065e PB |
369 | if (TYPE_NFIELDS (type) > 0) |
370 | { | |
d221b17e WM |
371 | /* The enums may not be sorted by value, so search all |
372 | entries */ | |
373 | int i; | |
374 | ||
375 | *lowp = *highp = TYPE_FIELD_BITPOS (type, 0); | |
376 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
377 | { | |
378 | if (TYPE_FIELD_BITPOS (type, i) < *lowp) | |
379 | *lowp = TYPE_FIELD_BITPOS (type, i); | |
380 | if (TYPE_FIELD_BITPOS (type, i) > *highp) | |
381 | *highp = TYPE_FIELD_BITPOS (type, i); | |
382 | } | |
d1f4065e PB |
383 | } |
384 | else | |
385 | { | |
386 | *lowp = 0; | |
387 | *highp = -1; | |
388 | } | |
706bfe5a PB |
389 | return 0; |
390 | case TYPE_CODE_BOOL: | |
391 | *lowp = 0; | |
392 | *highp = 1; | |
393 | return 0; | |
394 | case TYPE_CODE_INT: | |
f6d16585 | 395 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ |
706bfe5a PB |
396 | return -1; |
397 | if (!TYPE_UNSIGNED (type)) | |
398 | { | |
399 | *lowp = - (1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); | |
400 | *highp = -*lowp - 1; | |
401 | return 0; | |
402 | } | |
403 | /* ... fall through for unsigned ints ... */ | |
404 | case TYPE_CODE_CHAR: | |
405 | *lowp = 0; | |
f6d16585 PB |
406 | /* This round-about calculation is to avoid shifting by |
407 | TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work | |
408 | if TYPE_LENGTH (type) == sizeof (LONGEST). */ | |
409 | *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); | |
410 | *highp = (*highp - 1) | *highp; | |
706bfe5a PB |
411 | return 0; |
412 | default: | |
413 | return -1; | |
414 | } | |
415 | } | |
416 | ||
85f0a848 | 417 | /* Create an array type using either a blank type supplied in RESULT_TYPE, |
ec16f701 FF |
418 | or creating a new type, inheriting the objfile from RANGE_TYPE. |
419 | ||
420 | Elements will be of type ELEMENT_TYPE, the indices will be of type | |
421 | RANGE_TYPE. | |
1ab3bf1b | 422 | |
85f0a848 FF |
423 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
424 | sure it is TYPE_CODE_UNDEF before we bash it into an array type? */ | |
1ab3bf1b JG |
425 | |
426 | struct type * | |
a8a69e63 | 427 | create_array_type (result_type, element_type, range_type) |
85f0a848 | 428 | struct type *result_type; |
1ab3bf1b | 429 | struct type *element_type; |
a8a69e63 | 430 | struct type *range_type; |
1ab3bf1b | 431 | { |
d1f4065e | 432 | LONGEST low_bound, high_bound; |
1ab3bf1b | 433 | |
85f0a848 FF |
434 | if (result_type == NULL) |
435 | { | |
ec16f701 | 436 | result_type = alloc_type (TYPE_OBJFILE (range_type)); |
85f0a848 | 437 | } |
1ab3bf1b JG |
438 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; |
439 | TYPE_TARGET_TYPE (result_type) = element_type; | |
d1f4065e PB |
440 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) |
441 | low_bound = high_bound = 0; | |
442 | CHECK_TYPEDEF (element_type); | |
85f0a848 FF |
443 | TYPE_LENGTH (result_type) = |
444 | TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); | |
1ab3bf1b | 445 | TYPE_NFIELDS (result_type) = 1; |
a8a69e63 FF |
446 | TYPE_FIELDS (result_type) = |
447 | (struct field *) TYPE_ALLOC (result_type, sizeof (struct field)); | |
85f0a848 | 448 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); |
8050a57b | 449 | TYPE_FIELD_TYPE (result_type, 0) = range_type; |
1ab3bf1b JG |
450 | TYPE_VPTR_FIELDNO (result_type) = -1; |
451 | ||
81508b27 WM |
452 | /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */ |
453 | if (TYPE_LENGTH (result_type) == 0) | |
454 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; | |
455 | ||
1ab3bf1b JG |
456 | return (result_type); |
457 | } | |
458 | ||
c4413e2c FF |
459 | /* Create a string type using either a blank type supplied in RESULT_TYPE, |
460 | or creating a new type. String types are similar enough to array of | |
461 | char types that we can use create_array_type to build the basic type | |
462 | and then bash it into a string type. | |
463 | ||
464 | For fixed length strings, the range type contains 0 as the lower | |
465 | bound and the length of the string minus one as the upper bound. | |
466 | ||
467 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
468 | sure it is TYPE_CODE_UNDEF before we bash it into a string type? */ | |
469 | ||
470 | struct type * | |
471 | create_string_type (result_type, range_type) | |
472 | struct type *result_type; | |
473 | struct type *range_type; | |
474 | { | |
ead95f8a PB |
475 | result_type = create_array_type (result_type, |
476 | *current_language->string_char_type, | |
477 | range_type); | |
c4413e2c FF |
478 | TYPE_CODE (result_type) = TYPE_CODE_STRING; |
479 | return (result_type); | |
480 | } | |
1ab3bf1b | 481 | |
e909f287 PB |
482 | struct type * |
483 | create_set_type (result_type, domain_type) | |
484 | struct type *result_type; | |
485 | struct type *domain_type; | |
486 | { | |
d1f4065e | 487 | LONGEST low_bound, high_bound, bit_length; |
e909f287 PB |
488 | if (result_type == NULL) |
489 | { | |
490 | result_type = alloc_type (TYPE_OBJFILE (domain_type)); | |
491 | } | |
492 | TYPE_CODE (result_type) = TYPE_CODE_SET; | |
493 | TYPE_NFIELDS (result_type) = 1; | |
494 | TYPE_FIELDS (result_type) = (struct field *) | |
495 | TYPE_ALLOC (result_type, 1 * sizeof (struct field)); | |
496 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); | |
576f9770 PB |
497 | |
498 | if (! (TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB)) | |
499 | { | |
d1f4065e PB |
500 | if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) |
501 | low_bound = high_bound = 0; | |
576f9770 PB |
502 | bit_length = high_bound - low_bound + 1; |
503 | TYPE_LENGTH (result_type) | |
b4680522 | 504 | = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; |
576f9770 | 505 | } |
e909f287 | 506 | TYPE_FIELD_TYPE (result_type, 0) = domain_type; |
e909f287 PB |
507 | return (result_type); |
508 | } | |
509 | ||
1ab3bf1b JG |
510 | /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. |
511 | A MEMBER is a wierd thing -- it amounts to a typed offset into | |
512 | a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't | |
513 | include the offset (that's the value of the MEMBER itself), but does | |
514 | include the structure type into which it points (for some reason). | |
515 | ||
c2e4669f | 516 | When "smashing" the type, we preserve the objfile that the |
1ab3bf1b | 517 | old type pointed to, since we aren't changing where the type is actually |
c2e4669f | 518 | allocated. */ |
1ab3bf1b JG |
519 | |
520 | void | |
521 | smash_to_member_type (type, domain, to_type) | |
522 | struct type *type; | |
523 | struct type *domain; | |
524 | struct type *to_type; | |
525 | { | |
526 | struct objfile *objfile; | |
527 | ||
528 | objfile = TYPE_OBJFILE (type); | |
529 | ||
dac9734e | 530 | memset ((char *) type, 0, sizeof (struct type)); |
1ab3bf1b JG |
531 | TYPE_OBJFILE (type) = objfile; |
532 | TYPE_TARGET_TYPE (type) = to_type; | |
533 | TYPE_DOMAIN_TYPE (type) = domain; | |
534 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ | |
535 | TYPE_CODE (type) = TYPE_CODE_MEMBER; | |
536 | } | |
537 | ||
538 | /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. | |
539 | METHOD just means `function that gets an extra "this" argument'. | |
540 | ||
c2e4669f | 541 | When "smashing" the type, we preserve the objfile that the |
1ab3bf1b | 542 | old type pointed to, since we aren't changing where the type is actually |
c2e4669f | 543 | allocated. */ |
1ab3bf1b JG |
544 | |
545 | void | |
546 | smash_to_method_type (type, domain, to_type, args) | |
547 | struct type *type; | |
548 | struct type *domain; | |
549 | struct type *to_type; | |
550 | struct type **args; | |
551 | { | |
552 | struct objfile *objfile; | |
553 | ||
554 | objfile = TYPE_OBJFILE (type); | |
555 | ||
dac9734e | 556 | memset ((char *) type, 0, sizeof (struct type)); |
1ab3bf1b JG |
557 | TYPE_OBJFILE (type) = objfile; |
558 | TYPE_TARGET_TYPE (type) = to_type; | |
559 | TYPE_DOMAIN_TYPE (type) = domain; | |
560 | TYPE_ARG_TYPES (type) = args; | |
561 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ | |
562 | TYPE_CODE (type) = TYPE_CODE_METHOD; | |
563 | } | |
564 | ||
b2bebdb0 JK |
565 | /* Return a typename for a struct/union/enum type without "struct ", |
566 | "union ", or "enum ". If the type has a NULL name, return NULL. */ | |
1ab3bf1b JG |
567 | |
568 | char * | |
569 | type_name_no_tag (type) | |
570 | register const struct type *type; | |
571 | { | |
b2bebdb0 JK |
572 | if (TYPE_TAG_NAME (type) != NULL) |
573 | return TYPE_TAG_NAME (type); | |
1ab3bf1b | 574 | |
b2bebdb0 JK |
575 | /* Is there code which expects this to return the name if there is no |
576 | tag name? My guess is that this is mainly used for C++ in cases where | |
577 | the two will always be the same. */ | |
578 | return TYPE_NAME (type); | |
1ab3bf1b JG |
579 | } |
580 | ||
581 | /* Lookup a primitive type named NAME. | |
582 | Return zero if NAME is not a primitive type.*/ | |
583 | ||
584 | struct type * | |
585 | lookup_primitive_typename (name) | |
586 | char *name; | |
587 | { | |
588 | struct type ** const *p; | |
589 | ||
590 | for (p = current_language -> la_builtin_type_vector; *p != NULL; p++) | |
591 | { | |
2e4964ad | 592 | if (STREQ ((**p) -> name, name)) |
1ab3bf1b JG |
593 | { |
594 | return (**p); | |
595 | } | |
596 | } | |
597 | return (NULL); | |
598 | } | |
599 | ||
600 | /* Lookup a typedef or primitive type named NAME, | |
601 | visible in lexical block BLOCK. | |
602 | If NOERR is nonzero, return zero if NAME is not suitably defined. */ | |
603 | ||
604 | struct type * | |
605 | lookup_typename (name, block, noerr) | |
606 | char *name; | |
607 | struct block *block; | |
608 | int noerr; | |
609 | { | |
610 | register struct symbol *sym; | |
611 | register struct type *tmp; | |
612 | ||
613 | sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL); | |
614 | if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF) | |
615 | { | |
616 | tmp = lookup_primitive_typename (name); | |
617 | if (tmp) | |
618 | { | |
619 | return (tmp); | |
620 | } | |
621 | else if (!tmp && noerr) | |
622 | { | |
623 | return (NULL); | |
624 | } | |
625 | else | |
626 | { | |
627 | error ("No type named %s.", name); | |
628 | } | |
629 | } | |
630 | return (SYMBOL_TYPE (sym)); | |
631 | } | |
632 | ||
633 | struct type * | |
634 | lookup_unsigned_typename (name) | |
635 | char *name; | |
636 | { | |
637 | char *uns = alloca (strlen (name) + 10); | |
638 | ||
639 | strcpy (uns, "unsigned "); | |
640 | strcpy (uns + 9, name); | |
641 | return (lookup_typename (uns, (struct block *) NULL, 0)); | |
642 | } | |
643 | ||
a252e715 PB |
644 | struct type * |
645 | lookup_signed_typename (name) | |
646 | char *name; | |
647 | { | |
648 | struct type *t; | |
649 | char *uns = alloca (strlen (name) + 8); | |
650 | ||
651 | strcpy (uns, "signed "); | |
652 | strcpy (uns + 7, name); | |
653 | t = lookup_typename (uns, (struct block *) NULL, 1); | |
654 | /* If we don't find "signed FOO" just try again with plain "FOO". */ | |
655 | if (t != NULL) | |
656 | return t; | |
657 | return lookup_typename (name, (struct block *) NULL, 0); | |
658 | } | |
659 | ||
1ab3bf1b JG |
660 | /* Lookup a structure type named "struct NAME", |
661 | visible in lexical block BLOCK. */ | |
662 | ||
663 | struct type * | |
664 | lookup_struct (name, block) | |
665 | char *name; | |
666 | struct block *block; | |
667 | { | |
668 | register struct symbol *sym; | |
669 | ||
670 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
671 | (struct symtab **) NULL); | |
672 | ||
673 | if (sym == NULL) | |
674 | { | |
675 | error ("No struct type named %s.", name); | |
676 | } | |
2640f7e1 JG |
677 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) |
678 | { | |
679 | error ("This context has class, union or enum %s, not a struct.", name); | |
680 | } | |
681 | return (SYMBOL_TYPE (sym)); | |
1ab3bf1b JG |
682 | } |
683 | ||
684 | /* Lookup a union type named "union NAME", | |
685 | visible in lexical block BLOCK. */ | |
686 | ||
687 | struct type * | |
688 | lookup_union (name, block) | |
689 | char *name; | |
690 | struct block *block; | |
691 | { | |
692 | register struct symbol *sym; | |
693 | ||
694 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
695 | (struct symtab **) NULL); | |
696 | ||
697 | if (sym == NULL) | |
698 | { | |
699 | error ("No union type named %s.", name); | |
700 | } | |
2640f7e1 JG |
701 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION) |
702 | { | |
703 | error ("This context has class, struct or enum %s, not a union.", name); | |
704 | } | |
705 | return (SYMBOL_TYPE (sym)); | |
1ab3bf1b JG |
706 | } |
707 | ||
708 | /* Lookup an enum type named "enum NAME", | |
709 | visible in lexical block BLOCK. */ | |
710 | ||
711 | struct type * | |
712 | lookup_enum (name, block) | |
713 | char *name; | |
714 | struct block *block; | |
715 | { | |
716 | register struct symbol *sym; | |
717 | ||
718 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
719 | (struct symtab **) NULL); | |
720 | if (sym == NULL) | |
721 | { | |
722 | error ("No enum type named %s.", name); | |
723 | } | |
2640f7e1 JG |
724 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) |
725 | { | |
726 | error ("This context has class, struct or union %s, not an enum.", name); | |
727 | } | |
728 | return (SYMBOL_TYPE (sym)); | |
1ab3bf1b JG |
729 | } |
730 | ||
731 | /* Lookup a template type named "template NAME<TYPE>", | |
732 | visible in lexical block BLOCK. */ | |
733 | ||
734 | struct type * | |
735 | lookup_template_type (name, type, block) | |
736 | char *name; | |
737 | struct type *type; | |
738 | struct block *block; | |
739 | { | |
740 | struct symbol *sym; | |
741 | char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4); | |
742 | strcpy (nam, name); | |
743 | strcat (nam, "<"); | |
744 | strcat (nam, type->name); | |
745 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ | |
746 | ||
747 | sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL); | |
748 | ||
749 | if (sym == NULL) | |
750 | { | |
751 | error ("No template type named %s.", name); | |
752 | } | |
753 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
754 | { | |
755 | error ("This context has class, union or enum %s, not a struct.", name); | |
756 | } | |
757 | return (SYMBOL_TYPE (sym)); | |
758 | } | |
759 | ||
edf67bd1 | 760 | /* Given a type TYPE, lookup the type of the component of type named NAME. |
45364c8a FF |
761 | |
762 | TYPE can be either a struct or union, or a pointer or reference to a struct or | |
763 | union. If it is a pointer or reference, its target type is automatically used. | |
764 | Thus '.' and '->' are interchangable, as specified for the definitions of the | |
765 | expression element types STRUCTOP_STRUCT and STRUCTOP_PTR. | |
766 | ||
edf67bd1 MT |
767 | If NOERR is nonzero, return zero if NAME is not suitably defined. |
768 | If NAME is the name of a baseclass type, return that type. */ | |
1ab3bf1b JG |
769 | |
770 | struct type * | |
771 | lookup_struct_elt_type (type, name, noerr) | |
772 | struct type *type; | |
773 | char *name; | |
774 | int noerr; | |
775 | { | |
776 | int i; | |
777 | ||
d1f4065e PB |
778 | for (;;) |
779 | { | |
780 | CHECK_TYPEDEF (type); | |
781 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
782 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
783 | break; | |
5c5b5d4b | 784 | type = TYPE_TARGET_TYPE (type); |
d1f4065e | 785 | } |
5c5b5d4b | 786 | |
1ab3bf1b JG |
787 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT && |
788 | TYPE_CODE (type) != TYPE_CODE_UNION) | |
789 | { | |
790 | target_terminal_ours (); | |
199b2450 TL |
791 | gdb_flush (gdb_stdout); |
792 | fprintf_unfiltered (gdb_stderr, "Type "); | |
793 | type_print (type, "", gdb_stderr, -1); | |
1ab3bf1b JG |
794 | error (" is not a structure or union type."); |
795 | } | |
796 | ||
45364c8a FF |
797 | #if 0 |
798 | /* FIXME: This change put in by Michael seems incorrect for the case where | |
799 | the structure tag name is the same as the member name. I.E. when doing | |
800 | "ptype bell->bar" for "struct foo { int bar; int foo; } bell;" | |
801 | Disabled by fnf. */ | |
e7bf1152 RP |
802 | { |
803 | char *typename; | |
804 | ||
805 | typename = type_name_no_tag (type); | |
806 | if (typename != NULL && STREQ (typename, name)) | |
807 | return type; | |
808 | } | |
45364c8a | 809 | #endif |
edf67bd1 | 810 | |
1ab3bf1b JG |
811 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) |
812 | { | |
813 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
814 | ||
2e4964ad | 815 | if (t_field_name && STREQ (t_field_name, name)) |
1ab3bf1b JG |
816 | { |
817 | return TYPE_FIELD_TYPE (type, i); | |
818 | } | |
819 | } | |
820 | ||
821 | /* OK, it's not in this class. Recursively check the baseclasses. */ | |
822 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
823 | { | |
824 | struct type *t; | |
825 | ||
d112a0c6 | 826 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr); |
1ab3bf1b JG |
827 | if (t != NULL) |
828 | { | |
829 | return t; | |
830 | } | |
831 | } | |
832 | ||
833 | if (noerr) | |
834 | { | |
835 | return NULL; | |
836 | } | |
837 | ||
838 | target_terminal_ours (); | |
199b2450 TL |
839 | gdb_flush (gdb_stdout); |
840 | fprintf_unfiltered (gdb_stderr, "Type "); | |
841 | type_print (type, "", gdb_stderr, -1); | |
842 | fprintf_unfiltered (gdb_stderr, " has no component named "); | |
843 | fputs_filtered (name, gdb_stderr); | |
1ab3bf1b JG |
844 | error ("."); |
845 | return (struct type *)-1; /* For lint */ | |
846 | } | |
847 | ||
ac88287f JK |
848 | /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE |
849 | valid. Callers should be aware that in some cases (for example, | |
850 | the type or one of its baseclasses is a stub type and we are | |
851 | debugging a .o file), this function will not be able to find the virtual | |
852 | function table pointer, and vptr_fieldno will remain -1 and vptr_basetype | |
853 | will remain NULL. */ | |
1ab3bf1b JG |
854 | |
855 | void | |
856 | fill_in_vptr_fieldno (type) | |
857 | struct type *type; | |
858 | { | |
d1f4065e | 859 | CHECK_TYPEDEF (type); |
ac88287f | 860 | |
1ab3bf1b JG |
861 | if (TYPE_VPTR_FIELDNO (type) < 0) |
862 | { | |
863 | int i; | |
edf67bd1 MT |
864 | |
865 | /* We must start at zero in case the first (and only) baseclass is | |
866 | virtual (and hence we cannot share the table pointer). */ | |
867 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) | |
1ab3bf1b JG |
868 | { |
869 | fill_in_vptr_fieldno (TYPE_BASECLASS (type, i)); | |
870 | if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0) | |
871 | { | |
872 | TYPE_VPTR_FIELDNO (type) | |
873 | = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)); | |
874 | TYPE_VPTR_BASETYPE (type) | |
875 | = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i)); | |
876 | break; | |
877 | } | |
878 | } | |
879 | } | |
880 | } | |
881 | ||
882 | /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989. | |
883 | ||
884 | If this is a stubbed struct (i.e. declared as struct foo *), see if | |
885 | we can find a full definition in some other file. If so, copy this | |
dda398c3 JK |
886 | definition, so we can use it in future. There used to be a comment (but |
887 | not any code) that if we don't find a full definition, we'd set a flag | |
888 | so we don't spend time in the future checking the same type. That would | |
889 | be a mistake, though--we might load in more symbols which contain a | |
890 | full definition for the type. | |
1ab3bf1b JG |
891 | |
892 | This used to be coded as a macro, but I don't think it is called | |
dda398c3 | 893 | often enough to merit such treatment. */ |
1ab3bf1b JG |
894 | |
895 | struct complaint stub_noname_complaint = | |
896 | {"stub type has NULL name", 0, 0}; | |
897 | ||
d1f4065e PB |
898 | struct type * |
899 | check_typedef (type) | |
900 | register struct type *type; | |
901 | { | |
902 | struct type *orig_type = type; | |
903 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) | |
904 | { | |
905 | if (!TYPE_TARGET_TYPE (type)) | |
906 | { | |
7ef89313 PB |
907 | char* name; |
908 | struct symbol *sym; | |
909 | ||
910 | /* It is dangerous to call lookup_symbol if we are currently | |
911 | reading a symtab. Infinite recursion is one danger. */ | |
912 | if (currently_reading_symtab) | |
913 | return type; | |
914 | ||
915 | name = type_name_no_tag (type); | |
d1f4065e PB |
916 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
917 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE | |
918 | as appropriate? (this code was written before TYPE_NAME and | |
919 | TYPE_TAG_NAME were separate). */ | |
d1f4065e PB |
920 | if (name == NULL) |
921 | { | |
922 | complain (&stub_noname_complaint); | |
923 | return type; | |
924 | } | |
925 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, | |
926 | (struct symtab **) NULL); | |
927 | if (sym) | |
928 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); | |
929 | else | |
930 | TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */ | |
931 | } | |
932 | type = TYPE_TARGET_TYPE (type); | |
933 | } | |
934 | ||
7ef89313 | 935 | if ((TYPE_FLAGS(type) & TYPE_FLAG_STUB) && ! currently_reading_symtab) |
1ab3bf1b JG |
936 | { |
937 | char* name = type_name_no_tag (type); | |
065525e3 JK |
938 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
939 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE | |
940 | as appropriate? (this code was written before TYPE_NAME and | |
941 | TYPE_TAG_NAME were separate). */ | |
1ab3bf1b JG |
942 | struct symbol *sym; |
943 | if (name == NULL) | |
944 | { | |
51b80b00 | 945 | complain (&stub_noname_complaint); |
d1f4065e | 946 | return type; |
1ab3bf1b JG |
947 | } |
948 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, | |
949 | (struct symtab **) NULL); | |
950 | if (sym) | |
951 | { | |
dda398c3 JK |
952 | memcpy ((char *)type, |
953 | (char *)SYMBOL_TYPE(sym), | |
954 | sizeof (struct type)); | |
955 | } | |
956 | } | |
957 | ||
958 | if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB) | |
959 | { | |
960 | struct type *range_type; | |
d1f4065e | 961 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); |
dda398c3 | 962 | |
d1f4065e | 963 | if (TYPE_FLAGS (target_type) & TYPE_FLAG_STUB) |
e55a5796 PB |
964 | { } |
965 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY | |
966 | && TYPE_NFIELDS (type) == 1 | |
967 | && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0)) | |
968 | == TYPE_CODE_RANGE)) | |
dda398c3 JK |
969 | { |
970 | /* Now recompute the length of the array type, based on its | |
971 | number of elements and the target type's length. */ | |
972 | TYPE_LENGTH (type) = | |
973 | ((TYPE_FIELD_BITPOS (range_type, 1) | |
974 | - TYPE_FIELD_BITPOS (range_type, 0) | |
975 | + 1) | |
d1f4065e | 976 | * TYPE_LENGTH (target_type)); |
dda398c3 | 977 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; |
1ab3bf1b | 978 | } |
e55a5796 PB |
979 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) |
980 | { | |
d1f4065e | 981 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); |
e55a5796 PB |
982 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; |
983 | } | |
1ab3bf1b | 984 | } |
d1f4065e PB |
985 | /* Cache TYPE_LENGTH for future use. */ |
986 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); | |
987 | return type; | |
1ab3bf1b JG |
988 | } |
989 | ||
94f5a25f DP |
990 | /* New code added to support parsing of Cfront stabs strings */ |
991 | #include <ctype.h> | |
992 | #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; } | |
993 | #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; } | |
b607efe7 FF |
994 | |
995 | static void | |
94f5a25f DP |
996 | add_name(pextras,n) |
997 | struct extra * pextras; | |
998 | char * n; | |
999 | { | |
b607efe7 FF |
1000 | int nlen; |
1001 | ||
94f5a25f DP |
1002 | if ((nlen = (n ? strlen(n) : 0))==0) |
1003 | return; | |
1004 | sprintf(pextras->str+pextras->len,"%d%s",nlen,n); | |
1005 | pextras->len=strlen(pextras->str); | |
1006 | } | |
1007 | ||
b607efe7 | 1008 | static void |
94f5a25f DP |
1009 | add_mangled_type(pextras,t) |
1010 | struct extra * pextras; | |
1011 | struct type * t; | |
1012 | { | |
1013 | enum type_code tcode; | |
1014 | int tlen, tflags; | |
1015 | char * tname; | |
1016 | ||
1017 | tcode = TYPE_CODE(t); | |
1018 | tlen = TYPE_LENGTH(t); | |
1019 | tflags = TYPE_FLAGS(t); | |
1020 | tname = TYPE_NAME(t); | |
1021 | /* args of "..." seem to get mangled as "e" */ | |
1022 | ||
1023 | switch (tcode) | |
1024 | { | |
1025 | case TYPE_CODE_INT: | |
1026 | if (tflags==1) | |
1027 | ADD_EXTRA('U'); | |
1028 | switch (tlen) | |
1029 | { | |
1030 | case 1: | |
1031 | ADD_EXTRA('c'); | |
1032 | break; | |
1033 | case 2: | |
1034 | ADD_EXTRA('s'); | |
1035 | break; | |
1036 | case 4: | |
1037 | { | |
1038 | char* pname; | |
1039 | if ((pname=strrchr(tname,'l'),pname) && !strcmp(pname,"long")) | |
1040 | ADD_EXTRA('l') | |
1041 | else | |
1042 | ADD_EXTRA('i') | |
1043 | } | |
1044 | break; | |
1045 | default: | |
1046 | { | |
1047 | ||
1048 | static struct complaint msg = {"Bad int type code length x%x\n",0,0}; | |
1049 | ||
1050 | complain (&msg, tlen); | |
1051 | ||
1052 | } | |
1053 | } | |
1054 | break; | |
1055 | case TYPE_CODE_FLT: | |
1056 | switch (tlen) | |
1057 | { | |
1058 | case 4: | |
1059 | ADD_EXTRA('f'); | |
1060 | break; | |
1061 | case 8: | |
1062 | ADD_EXTRA('d'); | |
1063 | break; | |
1064 | case 16: | |
1065 | ADD_EXTRA('r'); | |
1066 | break; | |
1067 | default: | |
1068 | { | |
1069 | static struct complaint msg = {"Bad float type code length x%x\n",0,0}; | |
1070 | complain (&msg, tlen); | |
1071 | } | |
1072 | } | |
1073 | break; | |
1074 | case TYPE_CODE_REF: | |
1075 | ADD_EXTRA('R'); | |
1076 | /* followed by what it's a ref to */ | |
1077 | break; | |
1078 | case TYPE_CODE_PTR: | |
1079 | ADD_EXTRA('P'); | |
1080 | /* followed by what it's a ptr to */ | |
1081 | break; | |
1082 | case TYPE_CODE_TYPEDEF: | |
1083 | { | |
1084 | static struct complaint msg = {"Typedefs in overloaded functions not yet supported\n",0,0}; | |
1085 | complain (&msg); | |
1086 | } | |
1087 | /* followed by type bytes & name */ | |
1088 | break; | |
1089 | case TYPE_CODE_FUNC: | |
1090 | ADD_EXTRA('F'); | |
1091 | /* followed by func's arg '_' & ret types */ | |
1092 | break; | |
1093 | case TYPE_CODE_VOID: | |
1094 | ADD_EXTRA('v'); | |
1095 | break; | |
1096 | case TYPE_CODE_METHOD: | |
1097 | ADD_EXTRA('M'); | |
1098 | /* followed by name of class and func's arg '_' & ret types */ | |
1099 | add_name(pextras,tname); | |
1100 | ADD_EXTRA('F'); /* then mangle function */ | |
1101 | break; | |
1102 | case TYPE_CODE_STRUCT: /* C struct */ | |
1103 | case TYPE_CODE_UNION: /* C union */ | |
1104 | case TYPE_CODE_ENUM: /* Enumeration type */ | |
1105 | /* followed by name of type */ | |
1106 | add_name(pextras,tname); | |
1107 | break; | |
1108 | ||
1109 | /* errors possible types/not supported */ | |
1110 | case TYPE_CODE_CHAR: | |
1111 | case TYPE_CODE_ARRAY: /* Array type */ | |
1112 | case TYPE_CODE_MEMBER: /* Member type */ | |
1113 | case TYPE_CODE_BOOL: | |
1114 | case TYPE_CODE_COMPLEX: /* Complex float */ | |
1115 | case TYPE_CODE_UNDEF: | |
1116 | case TYPE_CODE_SET: /* Pascal sets */ | |
1117 | case TYPE_CODE_RANGE: | |
1118 | case TYPE_CODE_STRING: | |
1119 | case TYPE_CODE_BITSTRING: | |
1120 | case TYPE_CODE_ERROR: | |
1121 | default: | |
1122 | { | |
1123 | static struct complaint msg = {"Unknown type code x%x\n",0,0}; | |
1124 | complain (&msg, tcode); | |
1125 | } | |
1126 | } | |
1127 | if (t->target_type) | |
1128 | add_mangled_type(pextras,t->target_type); | |
1129 | } | |
1130 | ||
b607efe7 FF |
1131 | #if 0 |
1132 | void | |
94f5a25f DP |
1133 | cfront_mangle_name(type, i, j) |
1134 | struct type *type; | |
1135 | int i; | |
1136 | int j; | |
1137 | { | |
1138 | struct fn_field *f; | |
1139 | char *mangled_name = gdb_mangle_name (type, i, j); | |
1140 | ||
1141 | f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */ | |
1142 | ||
1143 | /* kludge to support cfront methods - gdb expects to find "F" for | |
1144 | ARM_mangled names, so when we mangle, we have to add it here */ | |
1145 | if (ARM_DEMANGLING) | |
1146 | { | |
1147 | int k; | |
1148 | char * arm_mangled_name; | |
1149 | struct fn_field *method = &f[j]; | |
1150 | char *field_name = TYPE_FN_FIELDLIST_NAME (type, i); | |
1151 | char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); | |
1152 | char *newname = type_name_no_tag (type); | |
1153 | ||
1154 | struct type *ftype = TYPE_FN_FIELD_TYPE (f, j); | |
1155 | int nargs = TYPE_NFIELDS(ftype); /* number of args */ | |
1156 | struct extra extras, * pextras = &extras; | |
1157 | INIT_EXTRA | |
1158 | ||
1159 | if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */ | |
1160 | ADD_EXTRA('S') | |
1161 | ADD_EXTRA('F') | |
1162 | /* add args here! */ | |
1163 | if (nargs <= 1) /* no args besides this */ | |
1164 | ADD_EXTRA('v') | |
1165 | else { | |
1166 | for (k=1; k<nargs; k++) | |
1167 | { | |
1168 | struct type * t; | |
1169 | t = TYPE_FIELD_TYPE(ftype,k); | |
1170 | add_mangled_type(pextras,t); | |
1171 | } | |
1172 | } | |
1173 | ADD_EXTRA('\0') | |
1174 | printf("add_mangled_type: %s\n",extras.str); /* FIXME */ | |
1175 | arm_mangled_name = malloc(strlen(mangled_name)+extras.len); | |
1176 | sprintf(arm_mangled_name,"%s%s",mangled_name,extras.str); | |
1177 | free(mangled_name); | |
1178 | mangled_name = arm_mangled_name; | |
1179 | } | |
1180 | } | |
b607efe7 FF |
1181 | #endif /* 0 */ |
1182 | ||
94f5a25f DP |
1183 | #undef ADD_EXTRA |
1184 | /* End of new code added to support parsing of Cfront stabs strings */ | |
1185 | ||
1ab3bf1b JG |
1186 | /* Ugly hack to convert method stubs into method types. |
1187 | ||
1188 | He ain't kiddin'. This demangles the name of the method into a string | |
1189 | including argument types, parses out each argument type, generates | |
1190 | a string casting a zero to that type, evaluates the string, and stuffs | |
1191 | the resulting type into an argtype vector!!! Then it knows the type | |
1192 | of the whole function (including argument types for overloading), | |
1193 | which info used to be in the stab's but was removed to hack back | |
1194 | the space required for them. */ | |
1195 | ||
1196 | void | |
1197 | check_stub_method (type, i, j) | |
1198 | struct type *type; | |
1199 | int i; | |
1200 | int j; | |
1201 | { | |
1202 | struct fn_field *f; | |
1203 | char *mangled_name = gdb_mangle_name (type, i, j); | |
8050a57b FF |
1204 | char *demangled_name = cplus_demangle (mangled_name, |
1205 | DMGL_PARAMS | DMGL_ANSI); | |
1ab3bf1b JG |
1206 | char *argtypetext, *p; |
1207 | int depth = 0, argcount = 1; | |
1208 | struct type **argtypes; | |
1209 | struct type *mtype; | |
1210 | ||
e045712f BK |
1211 | /* Make sure we got back a function string that we can use. */ |
1212 | if (demangled_name) | |
1213 | p = strchr (demangled_name, '('); | |
1214 | ||
1215 | if (demangled_name == NULL || p == NULL) | |
1216 | error ("Internal: Cannot demangle mangled name `%s'.", mangled_name); | |
1ab3bf1b JG |
1217 | |
1218 | /* Now, read in the parameters that define this type. */ | |
e045712f BK |
1219 | p += 1; |
1220 | argtypetext = p; | |
1ab3bf1b JG |
1221 | while (*p) |
1222 | { | |
1223 | if (*p == '(') | |
1224 | { | |
1225 | depth += 1; | |
1226 | } | |
1227 | else if (*p == ')') | |
1228 | { | |
1229 | depth -= 1; | |
1230 | } | |
1231 | else if (*p == ',' && depth == 0) | |
1232 | { | |
1233 | argcount += 1; | |
1234 | } | |
1235 | ||
1236 | p += 1; | |
1237 | } | |
1238 | ||
1239 | /* We need two more slots: one for the THIS pointer, and one for the | |
1240 | NULL [...] or void [end of arglist]. */ | |
1241 | ||
1242 | argtypes = (struct type **) | |
dac9734e | 1243 | TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *)); |
1ab3bf1b | 1244 | p = argtypetext; |
e552788b | 1245 | /* FIXME: This is wrong for static member functions. */ |
1ab3bf1b JG |
1246 | argtypes[0] = lookup_pointer_type (type); |
1247 | argcount = 1; | |
1248 | ||
1249 | if (*p != ')') /* () means no args, skip while */ | |
1250 | { | |
1251 | depth = 0; | |
1252 | while (*p) | |
1253 | { | |
1254 | if (depth <= 0 && (*p == ',' || *p == ')')) | |
1255 | { | |
393e55ba JK |
1256 | /* Avoid parsing of ellipsis, they will be handled below. */ |
1257 | if (strncmp (argtypetext, "...", p - argtypetext) != 0) | |
1258 | { | |
1259 | argtypes[argcount] = | |
1260 | parse_and_eval_type (argtypetext, p - argtypetext); | |
1261 | argcount += 1; | |
1262 | } | |
1ab3bf1b JG |
1263 | argtypetext = p + 1; |
1264 | } | |
1265 | ||
1266 | if (*p == '(') | |
1267 | { | |
1268 | depth += 1; | |
1269 | } | |
1270 | else if (*p == ')') | |
1271 | { | |
1272 | depth -= 1; | |
1273 | } | |
1274 | ||
1275 | p += 1; | |
1276 | } | |
1277 | } | |
1278 | ||
c0f1085b | 1279 | if (p[-2] != '.') /* Not '...' */ |
1ab3bf1b | 1280 | { |
c0f1085b | 1281 | argtypes[argcount] = builtin_type_void; /* List terminator */ |
1ab3bf1b JG |
1282 | } |
1283 | else | |
1284 | { | |
c0f1085b | 1285 | argtypes[argcount] = NULL; /* Ellist terminator */ |
1ab3bf1b JG |
1286 | } |
1287 | ||
1288 | free (demangled_name); | |
1289 | ||
94f5a25f DP |
1290 | f = TYPE_FN_FIELDLIST1 (type, i); |
1291 | ||
1ab3bf1b JG |
1292 | TYPE_FN_FIELD_PHYSNAME (f, j) = mangled_name; |
1293 | ||
1294 | /* Now update the old "stub" type into a real type. */ | |
1295 | mtype = TYPE_FN_FIELD_TYPE (f, j); | |
1296 | TYPE_DOMAIN_TYPE (mtype) = type; | |
1297 | TYPE_ARG_TYPES (mtype) = argtypes; | |
1298 | TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB; | |
1299 | TYPE_FN_FIELD_STUB (f, j) = 0; | |
1300 | } | |
1301 | ||
0213d96f | 1302 | const struct cplus_struct_type cplus_struct_default; |
1ab3bf1b JG |
1303 | |
1304 | void | |
1305 | allocate_cplus_struct_type (type) | |
1306 | struct type *type; | |
1307 | { | |
1308 | if (!HAVE_CPLUS_STRUCT (type)) | |
1309 | { | |
1310 | TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) | |
dac9734e | 1311 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); |
1ab3bf1b JG |
1312 | *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default; |
1313 | } | |
1314 | } | |
1315 | ||
50e0dc41 FF |
1316 | /* Helper function to initialize the standard scalar types. |
1317 | ||
1318 | If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy | |
1319 | of the string pointed to by name in the type_obstack for that objfile, | |
1320 | and initialize the type name to that copy. There are places (mipsread.c | |
1321 | in particular, where init_type is called with a NULL value for NAME). */ | |
1ab3bf1b JG |
1322 | |
1323 | struct type * | |
1324 | init_type (code, length, flags, name, objfile) | |
1325 | enum type_code code; | |
1326 | int length; | |
1327 | int flags; | |
1328 | char *name; | |
1329 | struct objfile *objfile; | |
1330 | { | |
1331 | register struct type *type; | |
1332 | ||
1333 | type = alloc_type (objfile); | |
1334 | TYPE_CODE (type) = code; | |
1335 | TYPE_LENGTH (type) = length; | |
1336 | TYPE_FLAGS (type) |= flags; | |
50e0dc41 FF |
1337 | if ((name != NULL) && (objfile != NULL)) |
1338 | { | |
1339 | TYPE_NAME (type) = | |
1340 | obsavestring (name, strlen (name), &objfile -> type_obstack); | |
1341 | } | |
1342 | else | |
1343 | { | |
1344 | TYPE_NAME (type) = name; | |
1345 | } | |
1ab3bf1b JG |
1346 | |
1347 | /* C++ fancies. */ | |
1348 | ||
1349 | if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION) | |
1350 | { | |
1351 | INIT_CPLUS_SPECIFIC (type); | |
1352 | } | |
1353 | return (type); | |
1354 | } | |
1355 | ||
1356 | /* Look up a fundamental type for the specified objfile. | |
1357 | May need to construct such a type if this is the first use. | |
1358 | ||
1359 | Some object file formats (ELF, COFF, etc) do not define fundamental | |
1360 | types such as "int" or "double". Others (stabs for example), do | |
1361 | define fundamental types. | |
1362 | ||
1363 | For the formats which don't provide fundamental types, gdb can create | |
bf229b4e FF |
1364 | such types, using defaults reasonable for the current language and |
1365 | the current target machine. | |
1366 | ||
1367 | NOTE: This routine is obsolescent. Each debugging format reader | |
1368 | should manage it's own fundamental types, either creating them from | |
1369 | suitable defaults or reading them from the debugging information, | |
1370 | whichever is appropriate. The DWARF reader has already been | |
1371 | fixed to do this. Once the other readers are fixed, this routine | |
1372 | will go away. Also note that fundamental types should be managed | |
1373 | on a compilation unit basis in a multi-language environment, not | |
1374 | on a linkage unit basis as is done here. */ | |
1375 | ||
1ab3bf1b JG |
1376 | |
1377 | struct type * | |
1378 | lookup_fundamental_type (objfile, typeid) | |
1379 | struct objfile *objfile; | |
1380 | int typeid; | |
1381 | { | |
1ab3bf1b JG |
1382 | register struct type **typep; |
1383 | register int nbytes; | |
1384 | ||
1385 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
1386 | { | |
1387 | error ("internal error - invalid fundamental type id %d", typeid); | |
1388 | } | |
bf229b4e FF |
1389 | |
1390 | /* If this is the first time we need a fundamental type for this objfile | |
1391 | then we need to initialize the vector of type pointers. */ | |
1392 | ||
1393 | if (objfile -> fundamental_types == NULL) | |
1ab3bf1b | 1394 | { |
bf229b4e FF |
1395 | nbytes = FT_NUM_MEMBERS * sizeof (struct type *); |
1396 | objfile -> fundamental_types = (struct type **) | |
1397 | obstack_alloc (&objfile -> type_obstack, nbytes); | |
1398 | memset ((char *) objfile -> fundamental_types, 0, nbytes); | |
2dd30c72 | 1399 | OBJSTAT (objfile, n_types += FT_NUM_MEMBERS); |
1ab3bf1b | 1400 | } |
bf229b4e FF |
1401 | |
1402 | /* Look for this particular type in the fundamental type vector. If one is | |
1403 | not found, create and install one appropriate for the current language. */ | |
1404 | ||
1405 | typep = objfile -> fundamental_types + typeid; | |
1406 | if (*typep == NULL) | |
1407 | { | |
1408 | *typep = create_fundamental_type (objfile, typeid); | |
1409 | } | |
1410 | ||
1411 | return (*typep); | |
1ab3bf1b JG |
1412 | } |
1413 | ||
9c036bd8 JK |
1414 | int |
1415 | can_dereference (t) | |
1416 | struct type *t; | |
1417 | { | |
1418 | /* FIXME: Should we return true for references as well as pointers? */ | |
d1f4065e | 1419 | CHECK_TYPEDEF (t); |
9c036bd8 JK |
1420 | return |
1421 | (t != NULL | |
1422 | && TYPE_CODE (t) == TYPE_CODE_PTR | |
1423 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); | |
1424 | } | |
1425 | ||
f91a9e05 PB |
1426 | /* Chill varying string and arrays are represented as follows: |
1427 | ||
1428 | struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data}; | |
1429 | ||
1430 | Return true if TYPE is such a Chill varying type. */ | |
1431 | ||
1432 | int | |
1433 | chill_varying_type (type) | |
1434 | struct type *type; | |
1435 | { | |
1436 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT | |
1437 | || TYPE_NFIELDS (type) != 2 | |
1438 | || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0) | |
1439 | return 0; | |
1440 | return 1; | |
1441 | } | |
1442 | ||
0239d9b3 FF |
1443 | #if MAINTENANCE_CMDS |
1444 | ||
8050a57b FF |
1445 | static void |
1446 | print_bit_vector (bits, nbits) | |
1447 | B_TYPE *bits; | |
1448 | int nbits; | |
0239d9b3 | 1449 | { |
8050a57b FF |
1450 | int bitno; |
1451 | ||
1452 | for (bitno = 0; bitno < nbits; bitno++) | |
0239d9b3 | 1453 | { |
8050a57b FF |
1454 | if ((bitno % 8) == 0) |
1455 | { | |
1456 | puts_filtered (" "); | |
1457 | } | |
1458 | if (B_TST (bits, bitno)) | |
1459 | { | |
1460 | printf_filtered ("1"); | |
1461 | } | |
1462 | else | |
1463 | { | |
1464 | printf_filtered ("0"); | |
1465 | } | |
0239d9b3 | 1466 | } |
8050a57b FF |
1467 | } |
1468 | ||
c0f1085b FF |
1469 | /* The args list is a strange beast. It is either terminated by a NULL |
1470 | pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID | |
1471 | type for normal fixed argcount functions. (FIXME someday) | |
1472 | Also note the first arg should be the "this" pointer, we may not want to | |
1473 | include it since we may get into a infinitely recursive situation. */ | |
1474 | ||
1475 | static void | |
1476 | print_arg_types (args, spaces) | |
1477 | struct type **args; | |
1478 | int spaces; | |
1479 | { | |
1480 | if (args != NULL) | |
1481 | { | |
1482 | while (*args != NULL) | |
1483 | { | |
1484 | recursive_dump_type (*args, spaces + 2); | |
1485 | if ((*args++) -> code == TYPE_CODE_VOID) | |
1486 | { | |
1487 | break; | |
1488 | } | |
1489 | } | |
1490 | } | |
1491 | } | |
1492 | ||
1493 | static void | |
1494 | dump_fn_fieldlists (type, spaces) | |
1495 | struct type *type; | |
1496 | int spaces; | |
1497 | { | |
1498 | int method_idx; | |
1499 | int overload_idx; | |
1500 | struct fn_field *f; | |
1501 | ||
833e0d94 JK |
1502 | printfi_filtered (spaces, "fn_fieldlists "); |
1503 | gdb_print_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); | |
1504 | printf_filtered ("\n"); | |
c0f1085b FF |
1505 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) |
1506 | { | |
1507 | f = TYPE_FN_FIELDLIST1 (type, method_idx); | |
833e0d94 | 1508 | printfi_filtered (spaces + 2, "[%d] name '%s' (", |
c0f1085b | 1509 | method_idx, |
833e0d94 JK |
1510 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); |
1511 | gdb_print_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), | |
1512 | gdb_stdout); | |
1513 | printf_filtered (") length %d\n", | |
1514 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); | |
c0f1085b FF |
1515 | for (overload_idx = 0; |
1516 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); | |
1517 | overload_idx++) | |
1518 | { | |
833e0d94 | 1519 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", |
c0f1085b | 1520 | overload_idx, |
833e0d94 | 1521 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); |
5e678752 JK |
1522 | gdb_print_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
1523 | gdb_stdout); | |
833e0d94 JK |
1524 | printf_filtered (")\n"); |
1525 | printfi_filtered (spaces + 8, "type "); | |
1526 | gdb_print_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout); | |
1527 | printf_filtered ("\n"); | |
1528 | ||
c0f1085b FF |
1529 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), |
1530 | spaces + 8 + 2); | |
833e0d94 JK |
1531 | |
1532 | printfi_filtered (spaces + 8, "args "); | |
1533 | gdb_print_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout); | |
1534 | printf_filtered ("\n"); | |
1535 | ||
c0f1085b | 1536 | print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces); |
833e0d94 JK |
1537 | printfi_filtered (spaces + 8, "fcontext "); |
1538 | gdb_print_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), | |
1539 | gdb_stdout); | |
1540 | printf_filtered ("\n"); | |
1541 | ||
c0f1085b FF |
1542 | printfi_filtered (spaces + 8, "is_const %d\n", |
1543 | TYPE_FN_FIELD_CONST (f, overload_idx)); | |
1544 | printfi_filtered (spaces + 8, "is_volatile %d\n", | |
1545 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); | |
1546 | printfi_filtered (spaces + 8, "is_private %d\n", | |
1547 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); | |
1548 | printfi_filtered (spaces + 8, "is_protected %d\n", | |
1549 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); | |
1550 | printfi_filtered (spaces + 8, "is_stub %d\n", | |
1551 | TYPE_FN_FIELD_STUB (f, overload_idx)); | |
d07734e3 | 1552 | printfi_filtered (spaces + 8, "voffset %u\n", |
c0f1085b FF |
1553 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); |
1554 | } | |
1555 | } | |
1556 | } | |
1557 | ||
8050a57b FF |
1558 | static void |
1559 | print_cplus_stuff (type, spaces) | |
1560 | struct type *type; | |
1561 | int spaces; | |
1562 | { | |
c0f1085b | 1563 | printfi_filtered (spaces, "n_baseclasses %d\n", |
8050a57b | 1564 | TYPE_N_BASECLASSES (type)); |
c0f1085b FF |
1565 | printfi_filtered (spaces, "nfn_fields %d\n", |
1566 | TYPE_NFN_FIELDS (type)); | |
1567 | printfi_filtered (spaces, "nfn_fields_total %d\n", | |
1568 | TYPE_NFN_FIELDS_TOTAL (type)); | |
8050a57b | 1569 | if (TYPE_N_BASECLASSES (type) > 0) |
0239d9b3 | 1570 | { |
833e0d94 JK |
1571 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", |
1572 | TYPE_N_BASECLASSES (type)); | |
1573 | gdb_print_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout); | |
1574 | printf_filtered (")"); | |
1575 | ||
8050a57b FF |
1576 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), |
1577 | TYPE_N_BASECLASSES (type)); | |
1578 | puts_filtered ("\n"); | |
0239d9b3 | 1579 | } |
8050a57b | 1580 | if (TYPE_NFIELDS (type) > 0) |
0239d9b3 | 1581 | { |
8050a57b FF |
1582 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) |
1583 | { | |
833e0d94 JK |
1584 | printfi_filtered (spaces, "private_field_bits (%d bits at *", |
1585 | TYPE_NFIELDS (type)); | |
1586 | gdb_print_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout); | |
1587 | printf_filtered (")"); | |
8050a57b FF |
1588 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), |
1589 | TYPE_NFIELDS (type)); | |
1590 | puts_filtered ("\n"); | |
1591 | } | |
1592 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) | |
0239d9b3 | 1593 | { |
833e0d94 JK |
1594 | printfi_filtered (spaces, "protected_field_bits (%d bits at *", |
1595 | TYPE_NFIELDS (type)); | |
1596 | gdb_print_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout); | |
1597 | printf_filtered (")"); | |
8050a57b FF |
1598 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), |
1599 | TYPE_NFIELDS (type)); | |
1600 | puts_filtered ("\n"); | |
0239d9b3 FF |
1601 | } |
1602 | } | |
c0f1085b FF |
1603 | if (TYPE_NFN_FIELDS (type) > 0) |
1604 | { | |
1605 | dump_fn_fieldlists (type, spaces); | |
1606 | } | |
8050a57b FF |
1607 | } |
1608 | ||
2447e9af PS |
1609 | static struct obstack dont_print_type_obstack; |
1610 | ||
8050a57b FF |
1611 | void |
1612 | recursive_dump_type (type, spaces) | |
1613 | struct type *type; | |
1614 | int spaces; | |
1615 | { | |
1616 | int idx; | |
0239d9b3 | 1617 | |
2447e9af PS |
1618 | if (spaces == 0) |
1619 | obstack_begin (&dont_print_type_obstack, 0); | |
1620 | ||
1621 | if (TYPE_NFIELDS (type) > 0 | |
1622 | || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0)) | |
1623 | { | |
1624 | struct type **first_dont_print | |
1625 | = (struct type **)obstack_base (&dont_print_type_obstack); | |
1626 | ||
1627 | int i = (struct type **)obstack_next_free (&dont_print_type_obstack) | |
1628 | - first_dont_print; | |
1629 | ||
1630 | while (--i >= 0) | |
1631 | { | |
1632 | if (type == first_dont_print[i]) | |
1633 | { | |
1634 | printfi_filtered (spaces, "type node "); | |
1635 | gdb_print_address (type, gdb_stdout); | |
1636 | printf_filtered (" <same as already seen type>\n"); | |
1637 | return; | |
1638 | } | |
1639 | } | |
1640 | ||
1641 | obstack_ptr_grow (&dont_print_type_obstack, type); | |
1642 | } | |
1643 | ||
833e0d94 JK |
1644 | printfi_filtered (spaces, "type node "); |
1645 | gdb_print_address (type, gdb_stdout); | |
1646 | printf_filtered ("\n"); | |
1647 | printfi_filtered (spaces, "name '%s' (", | |
1648 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); | |
1649 | gdb_print_address (TYPE_NAME (type), gdb_stdout); | |
1650 | printf_filtered (")\n"); | |
85999c05 | 1651 | if (TYPE_TAG_NAME (type) != NULL) |
833e0d94 JK |
1652 | { |
1653 | printfi_filtered (spaces, "tagname '%s' (", | |
1654 | TYPE_TAG_NAME (type)); | |
1655 | gdb_print_address (TYPE_TAG_NAME (type), gdb_stdout); | |
1656 | printf_filtered (")\n"); | |
1657 | } | |
c0f1085b | 1658 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); |
8050a57b | 1659 | switch (TYPE_CODE (type)) |
0239d9b3 | 1660 | { |
8050a57b | 1661 | case TYPE_CODE_UNDEF: |
c0f1085b | 1662 | printf_filtered ("(TYPE_CODE_UNDEF)"); |
8050a57b FF |
1663 | break; |
1664 | case TYPE_CODE_PTR: | |
c0f1085b | 1665 | printf_filtered ("(TYPE_CODE_PTR)"); |
8050a57b FF |
1666 | break; |
1667 | case TYPE_CODE_ARRAY: | |
c0f1085b | 1668 | printf_filtered ("(TYPE_CODE_ARRAY)"); |
8050a57b FF |
1669 | break; |
1670 | case TYPE_CODE_STRUCT: | |
c0f1085b | 1671 | printf_filtered ("(TYPE_CODE_STRUCT)"); |
8050a57b FF |
1672 | break; |
1673 | case TYPE_CODE_UNION: | |
c0f1085b | 1674 | printf_filtered ("(TYPE_CODE_UNION)"); |
8050a57b FF |
1675 | break; |
1676 | case TYPE_CODE_ENUM: | |
c0f1085b | 1677 | printf_filtered ("(TYPE_CODE_ENUM)"); |
8050a57b FF |
1678 | break; |
1679 | case TYPE_CODE_FUNC: | |
c0f1085b | 1680 | printf_filtered ("(TYPE_CODE_FUNC)"); |
8050a57b FF |
1681 | break; |
1682 | case TYPE_CODE_INT: | |
c0f1085b | 1683 | printf_filtered ("(TYPE_CODE_INT)"); |
8050a57b FF |
1684 | break; |
1685 | case TYPE_CODE_FLT: | |
c0f1085b | 1686 | printf_filtered ("(TYPE_CODE_FLT)"); |
8050a57b FF |
1687 | break; |
1688 | case TYPE_CODE_VOID: | |
c0f1085b | 1689 | printf_filtered ("(TYPE_CODE_VOID)"); |
8050a57b FF |
1690 | break; |
1691 | case TYPE_CODE_SET: | |
c0f1085b | 1692 | printf_filtered ("(TYPE_CODE_SET)"); |
8050a57b FF |
1693 | break; |
1694 | case TYPE_CODE_RANGE: | |
c0f1085b | 1695 | printf_filtered ("(TYPE_CODE_RANGE)"); |
8050a57b | 1696 | break; |
c4413e2c FF |
1697 | case TYPE_CODE_STRING: |
1698 | printf_filtered ("(TYPE_CODE_STRING)"); | |
8050a57b FF |
1699 | break; |
1700 | case TYPE_CODE_ERROR: | |
c0f1085b | 1701 | printf_filtered ("(TYPE_CODE_ERROR)"); |
8050a57b FF |
1702 | break; |
1703 | case TYPE_CODE_MEMBER: | |
c0f1085b | 1704 | printf_filtered ("(TYPE_CODE_MEMBER)"); |
8050a57b FF |
1705 | break; |
1706 | case TYPE_CODE_METHOD: | |
c0f1085b | 1707 | printf_filtered ("(TYPE_CODE_METHOD)"); |
8050a57b FF |
1708 | break; |
1709 | case TYPE_CODE_REF: | |
c0f1085b | 1710 | printf_filtered ("(TYPE_CODE_REF)"); |
8050a57b FF |
1711 | break; |
1712 | case TYPE_CODE_CHAR: | |
c0f1085b | 1713 | printf_filtered ("(TYPE_CODE_CHAR)"); |
8050a57b FF |
1714 | break; |
1715 | case TYPE_CODE_BOOL: | |
c0f1085b | 1716 | printf_filtered ("(TYPE_CODE_BOOL)"); |
8050a57b | 1717 | break; |
d1f4065e PB |
1718 | case TYPE_CODE_TYPEDEF: |
1719 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); | |
1720 | break; | |
8050a57b | 1721 | default: |
c0f1085b | 1722 | printf_filtered ("(UNKNOWN TYPE CODE)"); |
8050a57b | 1723 | break; |
0239d9b3 | 1724 | } |
8050a57b | 1725 | puts_filtered ("\n"); |
c0f1085b | 1726 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); |
833e0d94 JK |
1727 | printfi_filtered (spaces, "objfile "); |
1728 | gdb_print_address (TYPE_OBJFILE (type), gdb_stdout); | |
1729 | printf_filtered ("\n"); | |
1730 | printfi_filtered (spaces, "target_type "); | |
1731 | gdb_print_address (TYPE_TARGET_TYPE (type), gdb_stdout); | |
1732 | printf_filtered ("\n"); | |
8050a57b FF |
1733 | if (TYPE_TARGET_TYPE (type) != NULL) |
1734 | { | |
1735 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); | |
1736 | } | |
833e0d94 JK |
1737 | printfi_filtered (spaces, "pointer_type "); |
1738 | gdb_print_address (TYPE_POINTER_TYPE (type), gdb_stdout); | |
1739 | printf_filtered ("\n"); | |
1740 | printfi_filtered (spaces, "reference_type "); | |
1741 | gdb_print_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); | |
1742 | printf_filtered ("\n"); | |
c0f1085b | 1743 | printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type)); |
8050a57b FF |
1744 | if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED) |
1745 | { | |
1746 | puts_filtered (" TYPE_FLAG_UNSIGNED"); | |
1747 | } | |
8050a57b FF |
1748 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) |
1749 | { | |
1750 | puts_filtered (" TYPE_FLAG_STUB"); | |
1751 | } | |
1752 | puts_filtered ("\n"); | |
833e0d94 | 1753 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); |
5e678752 | 1754 | gdb_print_address (TYPE_FIELDS (type), gdb_stdout); |
833e0d94 | 1755 | puts_filtered ("\n"); |
8050a57b FF |
1756 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) |
1757 | { | |
1758 | printfi_filtered (spaces + 2, | |
5e678752 | 1759 | "[%d] bitpos %d bitsize %d type ", |
8050a57b | 1760 | idx, TYPE_FIELD_BITPOS (type, idx), |
833e0d94 JK |
1761 | TYPE_FIELD_BITSIZE (type, idx)); |
1762 | gdb_print_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); | |
1763 | printf_filtered (" name '%s' (", | |
1764 | TYPE_FIELD_NAME (type, idx) != NULL | |
1765 | ? TYPE_FIELD_NAME (type, idx) | |
1766 | : "<NULL>"); | |
5e678752 | 1767 | gdb_print_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
833e0d94 | 1768 | printf_filtered (")\n"); |
8050a57b FF |
1769 | if (TYPE_FIELD_TYPE (type, idx) != NULL) |
1770 | { | |
1771 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); | |
1772 | } | |
1773 | } | |
833e0d94 JK |
1774 | printfi_filtered (spaces, "vptr_basetype "); |
1775 | gdb_print_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); | |
1776 | puts_filtered ("\n"); | |
8050a57b FF |
1777 | if (TYPE_VPTR_BASETYPE (type) != NULL) |
1778 | { | |
1779 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); | |
1780 | } | |
c0f1085b | 1781 | printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type)); |
8050a57b | 1782 | switch (TYPE_CODE (type)) |
0239d9b3 FF |
1783 | { |
1784 | case TYPE_CODE_METHOD: | |
1785 | case TYPE_CODE_FUNC: | |
833e0d94 | 1786 | printfi_filtered (spaces, "arg_types "); |
5e678752 | 1787 | gdb_print_address (TYPE_ARG_TYPES (type), gdb_stdout); |
833e0d94 | 1788 | puts_filtered ("\n"); |
c0f1085b | 1789 | print_arg_types (TYPE_ARG_TYPES (type), spaces); |
0239d9b3 FF |
1790 | break; |
1791 | ||
1792 | case TYPE_CODE_STRUCT: | |
833e0d94 | 1793 | printfi_filtered (spaces, "cplus_stuff "); |
5e678752 | 1794 | gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
833e0d94 | 1795 | puts_filtered ("\n"); |
8050a57b | 1796 | print_cplus_stuff (type, spaces); |
0239d9b3 | 1797 | break; |
d07734e3 FF |
1798 | |
1799 | default: | |
1800 | /* We have to pick one of the union types to be able print and test | |
1801 | the value. Pick cplus_struct_type, even though we know it isn't | |
1802 | any particular one. */ | |
833e0d94 | 1803 | printfi_filtered (spaces, "type_specific "); |
5e678752 | 1804 | gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
d07734e3 FF |
1805 | if (TYPE_CPLUS_SPECIFIC (type) != NULL) |
1806 | { | |
1807 | printf_filtered (" (unknown data form)"); | |
1808 | } | |
1809 | printf_filtered ("\n"); | |
1810 | break; | |
1811 | ||
0239d9b3 | 1812 | } |
2447e9af PS |
1813 | if (spaces == 0) |
1814 | obstack_free (&dont_print_type_obstack, NULL); | |
0239d9b3 FF |
1815 | } |
1816 | ||
1817 | #endif /* MAINTENANCE_CMDS */ | |
c4413e2c FF |
1818 | |
1819 | void | |
1820 | _initialize_gdbtypes () | |
1821 | { | |
1822 | builtin_type_void = | |
1823 | init_type (TYPE_CODE_VOID, 1, | |
1824 | 0, | |
1825 | "void", (struct objfile *) NULL); | |
1826 | builtin_type_char = | |
1827 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
1828 | 0, | |
1829 | "char", (struct objfile *) NULL); | |
1830 | builtin_type_signed_char = | |
1831 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
dda398c3 | 1832 | 0, |
c4413e2c FF |
1833 | "signed char", (struct objfile *) NULL); |
1834 | builtin_type_unsigned_char = | |
1835 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
1836 | TYPE_FLAG_UNSIGNED, | |
1837 | "unsigned char", (struct objfile *) NULL); | |
1838 | builtin_type_short = | |
1839 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
1840 | 0, | |
1841 | "short", (struct objfile *) NULL); | |
1842 | builtin_type_unsigned_short = | |
1843 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
1844 | TYPE_FLAG_UNSIGNED, | |
1845 | "unsigned short", (struct objfile *) NULL); | |
1846 | builtin_type_int = | |
1847 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
1848 | 0, | |
1849 | "int", (struct objfile *) NULL); | |
1850 | builtin_type_unsigned_int = | |
1851 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
1852 | TYPE_FLAG_UNSIGNED, | |
1853 | "unsigned int", (struct objfile *) NULL); | |
1854 | builtin_type_long = | |
1855 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
1856 | 0, | |
1857 | "long", (struct objfile *) NULL); | |
1858 | builtin_type_unsigned_long = | |
1859 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
1860 | TYPE_FLAG_UNSIGNED, | |
1861 | "unsigned long", (struct objfile *) NULL); | |
1862 | builtin_type_long_long = | |
1863 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
1864 | 0, | |
1865 | "long long", (struct objfile *) NULL); | |
1866 | builtin_type_unsigned_long_long = | |
1867 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
1868 | TYPE_FLAG_UNSIGNED, | |
1869 | "unsigned long long", (struct objfile *) NULL); | |
1870 | builtin_type_float = | |
1871 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
1872 | 0, | |
1873 | "float", (struct objfile *) NULL); | |
1874 | builtin_type_double = | |
1875 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
1876 | 0, | |
1877 | "double", (struct objfile *) NULL); | |
1878 | builtin_type_long_double = | |
1879 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
1880 | 0, | |
1881 | "long double", (struct objfile *) NULL); | |
1882 | builtin_type_complex = | |
ead95f8a | 1883 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
c4413e2c FF |
1884 | 0, |
1885 | "complex", (struct objfile *) NULL); | |
ead95f8a | 1886 | TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float; |
c4413e2c | 1887 | builtin_type_double_complex = |
ead95f8a | 1888 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
c4413e2c FF |
1889 | 0, |
1890 | "double complex", (struct objfile *) NULL); | |
ead95f8a | 1891 | TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double; |
c4413e2c FF |
1892 | builtin_type_string = |
1893 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
1894 | 0, | |
1895 | "string", (struct objfile *) NULL); | |
1896 | } |