Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support routines for manipulating internal types for GDB. |
b6ba6518 KB |
2 | Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000 |
3 | Free Software Foundation, Inc. | |
c906108c SS |
4 | Contributed by Cygnus Support, using pieces from other GDB modules. |
5 | ||
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | #include "defs.h" | |
24 | #include "gdb_string.h" | |
25 | #include "bfd.h" | |
26 | #include "symtab.h" | |
27 | #include "symfile.h" | |
28 | #include "objfiles.h" | |
29 | #include "gdbtypes.h" | |
30 | #include "expression.h" | |
31 | #include "language.h" | |
32 | #include "target.h" | |
33 | #include "value.h" | |
34 | #include "demangle.h" | |
35 | #include "complaints.h" | |
36 | #include "gdbcmd.h" | |
c91ecb25 | 37 | #include "wrapper.h" |
c906108c SS |
38 | |
39 | /* These variables point to the objects | |
40 | representing the predefined C data types. */ | |
41 | ||
42 | struct type *builtin_type_void; | |
43 | struct type *builtin_type_char; | |
9e0b60a8 | 44 | struct type *builtin_type_true_char; |
c906108c SS |
45 | struct type *builtin_type_short; |
46 | struct type *builtin_type_int; | |
47 | struct type *builtin_type_long; | |
48 | struct type *builtin_type_long_long; | |
49 | struct type *builtin_type_signed_char; | |
50 | struct type *builtin_type_unsigned_char; | |
51 | struct type *builtin_type_unsigned_short; | |
52 | struct type *builtin_type_unsigned_int; | |
53 | struct type *builtin_type_unsigned_long; | |
54 | struct type *builtin_type_unsigned_long_long; | |
55 | struct type *builtin_type_float; | |
56 | struct type *builtin_type_double; | |
57 | struct type *builtin_type_long_double; | |
58 | struct type *builtin_type_complex; | |
59 | struct type *builtin_type_double_complex; | |
60 | struct type *builtin_type_string; | |
61 | struct type *builtin_type_int8; | |
62 | struct type *builtin_type_uint8; | |
63 | struct type *builtin_type_int16; | |
64 | struct type *builtin_type_uint16; | |
65 | struct type *builtin_type_int32; | |
66 | struct type *builtin_type_uint32; | |
67 | struct type *builtin_type_int64; | |
68 | struct type *builtin_type_uint64; | |
69 | struct type *builtin_type_bool; | |
917317f4 | 70 | struct type *builtin_type_v4sf; |
c2d11a7d JM |
71 | struct type *builtin_type_v4si; |
72 | struct type *builtin_type_v8qi; | |
73 | struct type *builtin_type_v4hi; | |
74 | struct type *builtin_type_v2si; | |
c4093a6a JM |
75 | struct type *builtin_type_ptr; |
76 | struct type *builtin_type_CORE_ADDR; | |
77 | struct type *builtin_type_bfd_vma; | |
c906108c SS |
78 | |
79 | int opaque_type_resolution = 1; | |
5d161b24 | 80 | int overload_debug = 0; |
c906108c | 81 | |
c5aa993b JM |
82 | struct extra |
83 | { | |
84 | char str[128]; | |
85 | int len; | |
8c990f3c | 86 | }; /* maximum extension is 128! FIXME */ |
c906108c | 87 | |
a14ed312 KB |
88 | static void add_name (struct extra *, char *); |
89 | static void add_mangled_type (struct extra *, struct type *); | |
c906108c | 90 | #if 0 |
a14ed312 | 91 | static void cfront_mangle_name (struct type *, int, int); |
c906108c | 92 | #endif |
a14ed312 KB |
93 | static void print_bit_vector (B_TYPE *, int); |
94 | static void print_arg_types (struct type **, int); | |
95 | static void dump_fn_fieldlists (struct type *, int); | |
96 | static void print_cplus_stuff (struct type *, int); | |
97 | static void virtual_base_list_aux (struct type *dclass); | |
7a292a7a | 98 | |
c906108c SS |
99 | |
100 | /* Alloc a new type structure and fill it with some defaults. If | |
101 | OBJFILE is non-NULL, then allocate the space for the type structure | |
102 | in that objfile's type_obstack. */ | |
103 | ||
104 | struct type * | |
fba45db2 | 105 | alloc_type (struct objfile *objfile) |
c906108c SS |
106 | { |
107 | register struct type *type; | |
108 | ||
109 | /* Alloc the structure and start off with all fields zeroed. */ | |
110 | ||
111 | if (objfile == NULL) | |
112 | { | |
c5aa993b | 113 | type = (struct type *) xmalloc (sizeof (struct type)); |
c906108c SS |
114 | } |
115 | else | |
116 | { | |
c5aa993b JM |
117 | type = (struct type *) obstack_alloc (&objfile->type_obstack, |
118 | sizeof (struct type)); | |
c906108c SS |
119 | OBJSTAT (objfile, n_types++); |
120 | } | |
121 | memset ((char *) type, 0, sizeof (struct type)); | |
122 | ||
123 | /* Initialize the fields that might not be zero. */ | |
124 | ||
125 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
126 | TYPE_OBJFILE (type) = objfile; | |
127 | TYPE_VPTR_FIELDNO (type) = -1; | |
c5aa993b | 128 | TYPE_CV_TYPE (type) = type; /* chain back to itself */ |
c906108c SS |
129 | |
130 | return (type); | |
131 | } | |
132 | ||
133 | /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points | |
134 | to a pointer to memory where the pointer type should be stored. | |
135 | If *TYPEPTR is zero, update it to point to the pointer type we return. | |
136 | We allocate new memory if needed. */ | |
137 | ||
138 | struct type * | |
fba45db2 | 139 | make_pointer_type (struct type *type, struct type **typeptr) |
c906108c | 140 | { |
c5aa993b | 141 | register struct type *ntype; /* New type */ |
c906108c SS |
142 | struct objfile *objfile; |
143 | ||
144 | ntype = TYPE_POINTER_TYPE (type); | |
145 | ||
c5aa993b | 146 | if (ntype) |
c906108c | 147 | { |
c5aa993b JM |
148 | if (typeptr == 0) |
149 | return ntype; /* Don't care about alloc, and have new type. */ | |
c906108c | 150 | else if (*typeptr == 0) |
c5aa993b | 151 | { |
c906108c SS |
152 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
153 | return ntype; | |
c5aa993b | 154 | } |
c906108c SS |
155 | } |
156 | ||
157 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
158 | { | |
159 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
160 | if (typeptr) | |
161 | *typeptr = ntype; | |
162 | } | |
c5aa993b JM |
163 | else |
164 | /* We have storage, but need to reset it. */ | |
c906108c SS |
165 | { |
166 | ntype = *typeptr; | |
167 | objfile = TYPE_OBJFILE (ntype); | |
168 | memset ((char *) ntype, 0, sizeof (struct type)); | |
169 | TYPE_OBJFILE (ntype) = objfile; | |
170 | } | |
171 | ||
172 | TYPE_TARGET_TYPE (ntype) = type; | |
173 | TYPE_POINTER_TYPE (type) = ntype; | |
174 | ||
175 | /* FIXME! Assume the machine has only one representation for pointers! */ | |
176 | ||
177 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; | |
178 | TYPE_CODE (ntype) = TYPE_CODE_PTR; | |
179 | ||
67b2adb2 AC |
180 | /* Mark pointers as unsigned. The target converts between pointers |
181 | and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and | |
182 | ADDRESS_TO_POINTER(). */ | |
c906108c | 183 | TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED; |
c5aa993b | 184 | |
c906108c SS |
185 | if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */ |
186 | TYPE_POINTER_TYPE (type) = ntype; | |
187 | ||
188 | return ntype; | |
189 | } | |
190 | ||
191 | /* Given a type TYPE, return a type of pointers to that type. | |
192 | May need to construct such a type if this is the first use. */ | |
193 | ||
194 | struct type * | |
fba45db2 | 195 | lookup_pointer_type (struct type *type) |
c906108c | 196 | { |
c5aa993b | 197 | return make_pointer_type (type, (struct type **) 0); |
c906108c SS |
198 | } |
199 | ||
200 | /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points | |
201 | to a pointer to memory where the reference type should be stored. | |
202 | If *TYPEPTR is zero, update it to point to the reference type we return. | |
203 | We allocate new memory if needed. */ | |
204 | ||
205 | struct type * | |
fba45db2 | 206 | make_reference_type (struct type *type, struct type **typeptr) |
c906108c | 207 | { |
c5aa993b | 208 | register struct type *ntype; /* New type */ |
c906108c SS |
209 | struct objfile *objfile; |
210 | ||
211 | ntype = TYPE_REFERENCE_TYPE (type); | |
212 | ||
c5aa993b | 213 | if (ntype) |
c906108c | 214 | { |
c5aa993b JM |
215 | if (typeptr == 0) |
216 | return ntype; /* Don't care about alloc, and have new type. */ | |
c906108c | 217 | else if (*typeptr == 0) |
c5aa993b | 218 | { |
c906108c SS |
219 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
220 | return ntype; | |
c5aa993b | 221 | } |
c906108c SS |
222 | } |
223 | ||
224 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
225 | { | |
226 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
227 | if (typeptr) | |
228 | *typeptr = ntype; | |
229 | } | |
c5aa993b JM |
230 | else |
231 | /* We have storage, but need to reset it. */ | |
c906108c SS |
232 | { |
233 | ntype = *typeptr; | |
234 | objfile = TYPE_OBJFILE (ntype); | |
235 | memset ((char *) ntype, 0, sizeof (struct type)); | |
236 | TYPE_OBJFILE (ntype) = objfile; | |
237 | } | |
238 | ||
239 | TYPE_TARGET_TYPE (ntype) = type; | |
240 | TYPE_REFERENCE_TYPE (type) = ntype; | |
241 | ||
242 | /* FIXME! Assume the machine has only one representation for references, | |
243 | and that it matches the (only) representation for pointers! */ | |
244 | ||
245 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; | |
246 | TYPE_CODE (ntype) = TYPE_CODE_REF; | |
c5aa993b | 247 | |
c906108c SS |
248 | if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ |
249 | TYPE_REFERENCE_TYPE (type) = ntype; | |
250 | ||
251 | return ntype; | |
252 | } | |
253 | ||
254 | /* Same as above, but caller doesn't care about memory allocation details. */ | |
255 | ||
256 | struct type * | |
fba45db2 | 257 | lookup_reference_type (struct type *type) |
c906108c | 258 | { |
c5aa993b | 259 | return make_reference_type (type, (struct type **) 0); |
c906108c SS |
260 | } |
261 | ||
262 | /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points | |
263 | to a pointer to memory where the function type should be stored. | |
264 | If *TYPEPTR is zero, update it to point to the function type we return. | |
265 | We allocate new memory if needed. */ | |
266 | ||
267 | struct type * | |
fba45db2 | 268 | make_function_type (struct type *type, struct type **typeptr) |
c906108c | 269 | { |
c5aa993b | 270 | register struct type *ntype; /* New type */ |
c906108c SS |
271 | struct objfile *objfile; |
272 | ||
273 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
274 | { | |
275 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
276 | if (typeptr) | |
277 | *typeptr = ntype; | |
278 | } | |
c5aa993b JM |
279 | else |
280 | /* We have storage, but need to reset it. */ | |
c906108c SS |
281 | { |
282 | ntype = *typeptr; | |
283 | objfile = TYPE_OBJFILE (ntype); | |
284 | memset ((char *) ntype, 0, sizeof (struct type)); | |
285 | TYPE_OBJFILE (ntype) = objfile; | |
286 | } | |
287 | ||
288 | TYPE_TARGET_TYPE (ntype) = type; | |
289 | ||
290 | TYPE_LENGTH (ntype) = 1; | |
291 | TYPE_CODE (ntype) = TYPE_CODE_FUNC; | |
c5aa993b | 292 | |
c906108c SS |
293 | return ntype; |
294 | } | |
295 | ||
296 | ||
297 | /* Given a type TYPE, return a type of functions that return that type. | |
298 | May need to construct such a type if this is the first use. */ | |
299 | ||
300 | struct type * | |
fba45db2 | 301 | lookup_function_type (struct type *type) |
c906108c | 302 | { |
c5aa993b | 303 | return make_function_type (type, (struct type **) 0); |
c906108c SS |
304 | } |
305 | ||
306 | ||
307 | /* Make a "c-v" variant of a type -- a type that is identical to the | |
308 | one supplied except that it may have const or volatile attributes | |
309 | CNST is a flag for setting the const attribute | |
310 | VOLTL is a flag for setting the volatile attribute | |
311 | TYPE is the base type whose variant we are creating. | |
312 | TYPEPTR, if nonzero, points | |
313 | to a pointer to memory where the reference type should be stored. | |
314 | If *TYPEPTR is zero, update it to point to the reference type we return. | |
315 | We allocate new memory if needed. */ | |
316 | ||
317 | struct type * | |
fba45db2 | 318 | make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr) |
c906108c | 319 | { |
c5aa993b JM |
320 | register struct type *ntype; /* New type */ |
321 | register struct type *tmp_type = type; /* tmp type */ | |
c906108c SS |
322 | struct objfile *objfile; |
323 | ||
324 | ntype = TYPE_CV_TYPE (type); | |
325 | ||
326 | while (ntype != type) | |
327 | { | |
328 | if ((TYPE_CONST (ntype) == cnst) && | |
c5aa993b JM |
329 | (TYPE_VOLATILE (ntype) == voltl)) |
330 | { | |
331 | if (typeptr == 0) | |
332 | return ntype; | |
333 | else if (*typeptr == 0) | |
334 | { | |
335 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ | |
336 | return ntype; | |
337 | } | |
338 | } | |
c906108c SS |
339 | tmp_type = ntype; |
340 | ntype = TYPE_CV_TYPE (ntype); | |
341 | } | |
342 | ||
343 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
344 | { | |
345 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
346 | if (typeptr) | |
347 | *typeptr = ntype; | |
348 | } | |
c5aa993b JM |
349 | else |
350 | /* We have storage, but need to reset it. */ | |
c906108c SS |
351 | { |
352 | ntype = *typeptr; | |
353 | objfile = TYPE_OBJFILE (ntype); | |
354 | /* memset ((char *) ntype, 0, sizeof (struct type)); */ | |
355 | TYPE_OBJFILE (ntype) = objfile; | |
356 | } | |
357 | ||
c5aa993b | 358 | /* Copy original type */ |
c906108c SS |
359 | memcpy ((char *) ntype, (char *) type, sizeof (struct type)); |
360 | /* But zero out fields that shouldn't be copied */ | |
c5aa993b JM |
361 | TYPE_POINTER_TYPE (ntype) = (struct type *) 0; /* Need new pointer kind */ |
362 | TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; /* Need new referene kind */ | |
c906108c SS |
363 | /* Note: TYPE_TARGET_TYPE can be left as is */ |
364 | ||
365 | /* Set flags appropriately */ | |
366 | if (cnst) | |
c5aa993b | 367 | TYPE_FLAGS (ntype) |= TYPE_FLAG_CONST; |
c906108c | 368 | else |
c5aa993b | 369 | TYPE_FLAGS (ntype) &= ~TYPE_FLAG_CONST; |
c906108c SS |
370 | |
371 | if (voltl) | |
c5aa993b | 372 | TYPE_FLAGS (ntype) |= TYPE_FLAG_VOLATILE; |
c906108c | 373 | else |
c5aa993b | 374 | TYPE_FLAGS (ntype) &= ~TYPE_FLAG_VOLATILE; |
c906108c SS |
375 | |
376 | /* Fix the chain of cv variants */ | |
377 | TYPE_CV_TYPE (ntype) = type; | |
378 | TYPE_CV_TYPE (tmp_type) = ntype; | |
379 | ||
380 | return ntype; | |
381 | } | |
382 | ||
383 | ||
384 | ||
385 | ||
386 | /* Implement direct support for MEMBER_TYPE in GNU C++. | |
387 | May need to construct such a type if this is the first use. | |
388 | The TYPE is the type of the member. The DOMAIN is the type | |
389 | of the aggregate that the member belongs to. */ | |
390 | ||
391 | struct type * | |
fba45db2 | 392 | lookup_member_type (struct type *type, struct type *domain) |
c906108c SS |
393 | { |
394 | register struct type *mtype; | |
395 | ||
396 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
397 | smash_to_member_type (mtype, domain, type); | |
398 | return (mtype); | |
399 | } | |
400 | ||
7b83ea04 | 401 | /* Allocate a stub method whose return type is TYPE. |
c906108c SS |
402 | This apparently happens for speed of symbol reading, since parsing |
403 | out the arguments to the method is cpu-intensive, the way we are doing | |
404 | it. So, we will fill in arguments later. | |
405 | This always returns a fresh type. */ | |
406 | ||
407 | struct type * | |
fba45db2 | 408 | allocate_stub_method (struct type *type) |
c906108c SS |
409 | { |
410 | struct type *mtype; | |
411 | ||
412 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
413 | TYPE_TARGET_TYPE (mtype) = type; | |
414 | /* _DOMAIN_TYPE (mtype) = unknown yet */ | |
415 | /* _ARG_TYPES (mtype) = unknown yet */ | |
416 | TYPE_FLAGS (mtype) = TYPE_FLAG_STUB; | |
417 | TYPE_CODE (mtype) = TYPE_CODE_METHOD; | |
418 | TYPE_LENGTH (mtype) = 1; | |
419 | return (mtype); | |
420 | } | |
421 | ||
422 | /* Create a range type using either a blank type supplied in RESULT_TYPE, | |
423 | or creating a new type, inheriting the objfile from INDEX_TYPE. | |
424 | ||
425 | Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to | |
426 | HIGH_BOUND, inclusive. | |
427 | ||
428 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
429 | sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ | |
430 | ||
431 | struct type * | |
fba45db2 KB |
432 | create_range_type (struct type *result_type, struct type *index_type, |
433 | int low_bound, int high_bound) | |
c906108c SS |
434 | { |
435 | if (result_type == NULL) | |
436 | { | |
437 | result_type = alloc_type (TYPE_OBJFILE (index_type)); | |
438 | } | |
439 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; | |
440 | TYPE_TARGET_TYPE (result_type) = index_type; | |
441 | if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB) | |
442 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; | |
443 | else | |
444 | TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); | |
445 | TYPE_NFIELDS (result_type) = 2; | |
446 | TYPE_FIELDS (result_type) = (struct field *) | |
447 | TYPE_ALLOC (result_type, 2 * sizeof (struct field)); | |
448 | memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field)); | |
449 | TYPE_FIELD_BITPOS (result_type, 0) = low_bound; | |
450 | TYPE_FIELD_BITPOS (result_type, 1) = high_bound; | |
c5aa993b JM |
451 | TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */ |
452 | TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */ | |
c906108c | 453 | |
c5aa993b | 454 | if (low_bound >= 0) |
c906108c SS |
455 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
456 | ||
457 | return (result_type); | |
458 | } | |
459 | ||
460 | /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE. | |
461 | Return 1 of type is a range type, 0 if it is discrete (and bounds | |
462 | will fit in LONGEST), or -1 otherwise. */ | |
463 | ||
464 | int | |
fba45db2 | 465 | get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) |
c906108c SS |
466 | { |
467 | CHECK_TYPEDEF (type); | |
468 | switch (TYPE_CODE (type)) | |
469 | { | |
470 | case TYPE_CODE_RANGE: | |
471 | *lowp = TYPE_LOW_BOUND (type); | |
472 | *highp = TYPE_HIGH_BOUND (type); | |
473 | return 1; | |
474 | case TYPE_CODE_ENUM: | |
475 | if (TYPE_NFIELDS (type) > 0) | |
476 | { | |
477 | /* The enums may not be sorted by value, so search all | |
478 | entries */ | |
479 | int i; | |
480 | ||
481 | *lowp = *highp = TYPE_FIELD_BITPOS (type, 0); | |
482 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
483 | { | |
484 | if (TYPE_FIELD_BITPOS (type, i) < *lowp) | |
485 | *lowp = TYPE_FIELD_BITPOS (type, i); | |
486 | if (TYPE_FIELD_BITPOS (type, i) > *highp) | |
487 | *highp = TYPE_FIELD_BITPOS (type, i); | |
488 | } | |
489 | ||
490 | /* Set unsigned indicator if warranted. */ | |
c5aa993b | 491 | if (*lowp >= 0) |
c906108c SS |
492 | { |
493 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; | |
494 | } | |
495 | } | |
496 | else | |
497 | { | |
498 | *lowp = 0; | |
499 | *highp = -1; | |
500 | } | |
501 | return 0; | |
502 | case TYPE_CODE_BOOL: | |
503 | *lowp = 0; | |
504 | *highp = 1; | |
505 | return 0; | |
506 | case TYPE_CODE_INT: | |
c5aa993b | 507 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ |
c906108c SS |
508 | return -1; |
509 | if (!TYPE_UNSIGNED (type)) | |
510 | { | |
c5aa993b | 511 | *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); |
c906108c SS |
512 | *highp = -*lowp - 1; |
513 | return 0; | |
514 | } | |
515 | /* ... fall through for unsigned ints ... */ | |
516 | case TYPE_CODE_CHAR: | |
517 | *lowp = 0; | |
518 | /* This round-about calculation is to avoid shifting by | |
7b83ea04 AC |
519 | TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work |
520 | if TYPE_LENGTH (type) == sizeof (LONGEST). */ | |
c906108c SS |
521 | *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); |
522 | *highp = (*highp - 1) | *highp; | |
523 | return 0; | |
524 | default: | |
525 | return -1; | |
526 | } | |
527 | } | |
528 | ||
529 | /* Create an array type using either a blank type supplied in RESULT_TYPE, | |
530 | or creating a new type, inheriting the objfile from RANGE_TYPE. | |
531 | ||
532 | Elements will be of type ELEMENT_TYPE, the indices will be of type | |
533 | RANGE_TYPE. | |
534 | ||
535 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
536 | sure it is TYPE_CODE_UNDEF before we bash it into an array type? */ | |
537 | ||
538 | struct type * | |
fba45db2 KB |
539 | create_array_type (struct type *result_type, struct type *element_type, |
540 | struct type *range_type) | |
c906108c SS |
541 | { |
542 | LONGEST low_bound, high_bound; | |
543 | ||
544 | if (result_type == NULL) | |
545 | { | |
546 | result_type = alloc_type (TYPE_OBJFILE (range_type)); | |
547 | } | |
548 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; | |
549 | TYPE_TARGET_TYPE (result_type) = element_type; | |
550 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) | |
551 | low_bound = high_bound = 0; | |
552 | CHECK_TYPEDEF (element_type); | |
553 | TYPE_LENGTH (result_type) = | |
554 | TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); | |
555 | TYPE_NFIELDS (result_type) = 1; | |
556 | TYPE_FIELDS (result_type) = | |
557 | (struct field *) TYPE_ALLOC (result_type, sizeof (struct field)); | |
558 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); | |
559 | TYPE_FIELD_TYPE (result_type, 0) = range_type; | |
560 | TYPE_VPTR_FIELDNO (result_type) = -1; | |
561 | ||
562 | /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */ | |
563 | if (TYPE_LENGTH (result_type) == 0) | |
564 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; | |
565 | ||
566 | return (result_type); | |
567 | } | |
568 | ||
569 | /* Create a string type using either a blank type supplied in RESULT_TYPE, | |
570 | or creating a new type. String types are similar enough to array of | |
571 | char types that we can use create_array_type to build the basic type | |
572 | and then bash it into a string type. | |
573 | ||
574 | For fixed length strings, the range type contains 0 as the lower | |
575 | bound and the length of the string minus one as the upper bound. | |
576 | ||
577 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
578 | sure it is TYPE_CODE_UNDEF before we bash it into a string type? */ | |
579 | ||
580 | struct type * | |
fba45db2 | 581 | create_string_type (struct type *result_type, struct type *range_type) |
c906108c SS |
582 | { |
583 | result_type = create_array_type (result_type, | |
584 | *current_language->string_char_type, | |
585 | range_type); | |
586 | TYPE_CODE (result_type) = TYPE_CODE_STRING; | |
587 | return (result_type); | |
588 | } | |
589 | ||
590 | struct type * | |
fba45db2 | 591 | create_set_type (struct type *result_type, struct type *domain_type) |
c906108c SS |
592 | { |
593 | LONGEST low_bound, high_bound, bit_length; | |
594 | if (result_type == NULL) | |
595 | { | |
596 | result_type = alloc_type (TYPE_OBJFILE (domain_type)); | |
597 | } | |
598 | TYPE_CODE (result_type) = TYPE_CODE_SET; | |
599 | TYPE_NFIELDS (result_type) = 1; | |
600 | TYPE_FIELDS (result_type) = (struct field *) | |
601 | TYPE_ALLOC (result_type, 1 * sizeof (struct field)); | |
602 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); | |
603 | ||
c5aa993b | 604 | if (!(TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB)) |
c906108c SS |
605 | { |
606 | if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) | |
607 | low_bound = high_bound = 0; | |
608 | bit_length = high_bound - low_bound + 1; | |
609 | TYPE_LENGTH (result_type) | |
610 | = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; | |
611 | } | |
612 | TYPE_FIELD_TYPE (result_type, 0) = domain_type; | |
613 | ||
c5aa993b | 614 | if (low_bound >= 0) |
c906108c SS |
615 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
616 | ||
617 | return (result_type); | |
618 | } | |
619 | ||
917317f4 JM |
620 | |
621 | /* Construct and return a type of the form: | |
622 | struct NAME { ELT_TYPE ELT_NAME[N]; } | |
623 | We use these types for SIMD registers. For example, the type of | |
624 | the SSE registers on the late x86-family processors is: | |
625 | struct __builtin_v4sf { float f[4]; } | |
626 | built by the function call: | |
627 | init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4) | |
628 | The type returned is a permanent type, allocated using malloc; it | |
629 | doesn't live in any objfile's obstack. */ | |
c2d11a7d | 630 | static struct type * |
917317f4 JM |
631 | init_simd_type (char *name, |
632 | struct type *elt_type, | |
633 | char *elt_name, | |
634 | int n) | |
635 | { | |
636 | struct type *t; | |
637 | struct field *f; | |
638 | ||
639 | /* Build the field structure. */ | |
640 | f = xmalloc (sizeof (*f)); | |
641 | memset (f, 0, sizeof (*f)); | |
642 | f->loc.bitpos = 0; | |
643 | f->type = create_array_type (0, elt_type, | |
5c44784c JM |
644 | create_range_type (0, builtin_type_int, |
645 | 0, n-1)); | |
917317f4 JM |
646 | f->name = elt_name; |
647 | ||
648 | /* Build a struct type with that field. */ | |
649 | t = init_type (TYPE_CODE_STRUCT, n * TYPE_LENGTH (elt_type), 0, 0, 0); | |
650 | t->nfields = 1; | |
651 | t->fields = f; | |
652 | t->tag_name = name; | |
653 | ||
654 | return t; | |
655 | } | |
656 | ||
657 | ||
7b83ea04 | 658 | /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. |
c906108c SS |
659 | A MEMBER is a wierd thing -- it amounts to a typed offset into |
660 | a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't | |
661 | include the offset (that's the value of the MEMBER itself), but does | |
662 | include the structure type into which it points (for some reason). | |
663 | ||
664 | When "smashing" the type, we preserve the objfile that the | |
665 | old type pointed to, since we aren't changing where the type is actually | |
666 | allocated. */ | |
667 | ||
668 | void | |
fba45db2 KB |
669 | smash_to_member_type (struct type *type, struct type *domain, |
670 | struct type *to_type) | |
c906108c SS |
671 | { |
672 | struct objfile *objfile; | |
673 | ||
674 | objfile = TYPE_OBJFILE (type); | |
675 | ||
676 | memset ((char *) type, 0, sizeof (struct type)); | |
677 | TYPE_OBJFILE (type) = objfile; | |
678 | TYPE_TARGET_TYPE (type) = to_type; | |
679 | TYPE_DOMAIN_TYPE (type) = domain; | |
680 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ | |
681 | TYPE_CODE (type) = TYPE_CODE_MEMBER; | |
682 | } | |
683 | ||
684 | /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. | |
685 | METHOD just means `function that gets an extra "this" argument'. | |
686 | ||
687 | When "smashing" the type, we preserve the objfile that the | |
688 | old type pointed to, since we aren't changing where the type is actually | |
689 | allocated. */ | |
690 | ||
691 | void | |
fba45db2 KB |
692 | smash_to_method_type (struct type *type, struct type *domain, |
693 | struct type *to_type, struct type **args) | |
c906108c SS |
694 | { |
695 | struct objfile *objfile; | |
696 | ||
697 | objfile = TYPE_OBJFILE (type); | |
698 | ||
699 | memset ((char *) type, 0, sizeof (struct type)); | |
700 | TYPE_OBJFILE (type) = objfile; | |
701 | TYPE_TARGET_TYPE (type) = to_type; | |
702 | TYPE_DOMAIN_TYPE (type) = domain; | |
703 | TYPE_ARG_TYPES (type) = args; | |
704 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ | |
705 | TYPE_CODE (type) = TYPE_CODE_METHOD; | |
706 | } | |
707 | ||
708 | /* Return a typename for a struct/union/enum type without "struct ", | |
709 | "union ", or "enum ". If the type has a NULL name, return NULL. */ | |
710 | ||
711 | char * | |
fba45db2 | 712 | type_name_no_tag (register const struct type *type) |
c906108c SS |
713 | { |
714 | if (TYPE_TAG_NAME (type) != NULL) | |
715 | return TYPE_TAG_NAME (type); | |
716 | ||
717 | /* Is there code which expects this to return the name if there is no | |
718 | tag name? My guess is that this is mainly used for C++ in cases where | |
719 | the two will always be the same. */ | |
720 | return TYPE_NAME (type); | |
721 | } | |
722 | ||
7b83ea04 | 723 | /* Lookup a primitive type named NAME. |
c5aa993b | 724 | Return zero if NAME is not a primitive type. */ |
c906108c SS |
725 | |
726 | struct type * | |
fba45db2 | 727 | lookup_primitive_typename (char *name) |
c906108c | 728 | { |
c5aa993b JM |
729 | struct type **const *p; |
730 | ||
731 | for (p = current_language->la_builtin_type_vector; *p != NULL; p++) | |
732 | { | |
733 | if (STREQ ((**p)->name, name)) | |
734 | { | |
735 | return (**p); | |
736 | } | |
737 | } | |
738 | return (NULL); | |
c906108c SS |
739 | } |
740 | ||
741 | /* Lookup a typedef or primitive type named NAME, | |
742 | visible in lexical block BLOCK. | |
743 | If NOERR is nonzero, return zero if NAME is not suitably defined. */ | |
744 | ||
745 | struct type * | |
fba45db2 | 746 | lookup_typename (char *name, struct block *block, int noerr) |
c906108c SS |
747 | { |
748 | register struct symbol *sym; | |
749 | register struct type *tmp; | |
750 | ||
751 | sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL); | |
752 | if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF) | |
753 | { | |
754 | tmp = lookup_primitive_typename (name); | |
755 | if (tmp) | |
756 | { | |
757 | return (tmp); | |
758 | } | |
759 | else if (!tmp && noerr) | |
760 | { | |
761 | return (NULL); | |
762 | } | |
763 | else | |
764 | { | |
765 | error ("No type named %s.", name); | |
766 | } | |
767 | } | |
768 | return (SYMBOL_TYPE (sym)); | |
769 | } | |
770 | ||
771 | struct type * | |
fba45db2 | 772 | lookup_unsigned_typename (char *name) |
c906108c SS |
773 | { |
774 | char *uns = alloca (strlen (name) + 10); | |
775 | ||
776 | strcpy (uns, "unsigned "); | |
777 | strcpy (uns + 9, name); | |
778 | return (lookup_typename (uns, (struct block *) NULL, 0)); | |
779 | } | |
780 | ||
781 | struct type * | |
fba45db2 | 782 | lookup_signed_typename (char *name) |
c906108c SS |
783 | { |
784 | struct type *t; | |
785 | char *uns = alloca (strlen (name) + 8); | |
786 | ||
787 | strcpy (uns, "signed "); | |
788 | strcpy (uns + 7, name); | |
789 | t = lookup_typename (uns, (struct block *) NULL, 1); | |
790 | /* If we don't find "signed FOO" just try again with plain "FOO". */ | |
791 | if (t != NULL) | |
792 | return t; | |
793 | return lookup_typename (name, (struct block *) NULL, 0); | |
794 | } | |
795 | ||
796 | /* Lookup a structure type named "struct NAME", | |
797 | visible in lexical block BLOCK. */ | |
798 | ||
799 | struct type * | |
fba45db2 | 800 | lookup_struct (char *name, struct block *block) |
c906108c SS |
801 | { |
802 | register struct symbol *sym; | |
803 | ||
804 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
805 | (struct symtab **) NULL); | |
806 | ||
807 | if (sym == NULL) | |
808 | { | |
809 | error ("No struct type named %s.", name); | |
810 | } | |
811 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
812 | { | |
813 | error ("This context has class, union or enum %s, not a struct.", name); | |
814 | } | |
815 | return (SYMBOL_TYPE (sym)); | |
816 | } | |
817 | ||
818 | /* Lookup a union type named "union NAME", | |
819 | visible in lexical block BLOCK. */ | |
820 | ||
821 | struct type * | |
fba45db2 | 822 | lookup_union (char *name, struct block *block) |
c906108c SS |
823 | { |
824 | register struct symbol *sym; | |
c5aa993b | 825 | struct type *t; |
c906108c SS |
826 | |
827 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, | |
828 | (struct symtab **) NULL); | |
829 | ||
830 | if (sym == NULL) | |
831 | error ("No union type named %s.", name); | |
832 | ||
c5aa993b | 833 | t = SYMBOL_TYPE (sym); |
c906108c SS |
834 | |
835 | if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
836 | return (t); | |
837 | ||
838 | /* C++ unions may come out with TYPE_CODE_CLASS, but we look at | |
839 | * a further "declared_type" field to discover it is really a union. | |
840 | */ | |
c5aa993b JM |
841 | if (HAVE_CPLUS_STRUCT (t)) |
842 | if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION) | |
c906108c SS |
843 | return (t); |
844 | ||
845 | /* If we get here, it's not a union */ | |
846 | error ("This context has class, struct or enum %s, not a union.", name); | |
847 | } | |
848 | ||
849 | ||
850 | /* Lookup an enum type named "enum NAME", | |
851 | visible in lexical block BLOCK. */ | |
852 | ||
853 | struct type * | |
fba45db2 | 854 | lookup_enum (char *name, struct block *block) |
c906108c SS |
855 | { |
856 | register struct symbol *sym; | |
857 | ||
c5aa993b | 858 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, |
c906108c SS |
859 | (struct symtab **) NULL); |
860 | if (sym == NULL) | |
861 | { | |
862 | error ("No enum type named %s.", name); | |
863 | } | |
864 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) | |
865 | { | |
866 | error ("This context has class, struct or union %s, not an enum.", name); | |
867 | } | |
868 | return (SYMBOL_TYPE (sym)); | |
869 | } | |
870 | ||
871 | /* Lookup a template type named "template NAME<TYPE>", | |
872 | visible in lexical block BLOCK. */ | |
873 | ||
874 | struct type * | |
fba45db2 | 875 | lookup_template_type (char *name, struct type *type, struct block *block) |
c906108c SS |
876 | { |
877 | struct symbol *sym; | |
c5aa993b | 878 | char *nam = (char *) alloca (strlen (name) + strlen (type->name) + 4); |
c906108c SS |
879 | strcpy (nam, name); |
880 | strcat (nam, "<"); | |
881 | strcat (nam, type->name); | |
c5aa993b | 882 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ |
c906108c | 883 | |
c5aa993b | 884 | sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **) NULL); |
c906108c SS |
885 | |
886 | if (sym == NULL) | |
887 | { | |
888 | error ("No template type named %s.", name); | |
889 | } | |
890 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
891 | { | |
892 | error ("This context has class, union or enum %s, not a struct.", name); | |
893 | } | |
894 | return (SYMBOL_TYPE (sym)); | |
895 | } | |
896 | ||
7b83ea04 | 897 | /* Given a type TYPE, lookup the type of the component of type named NAME. |
c906108c SS |
898 | |
899 | TYPE can be either a struct or union, or a pointer or reference to a struct or | |
900 | union. If it is a pointer or reference, its target type is automatically used. | |
901 | Thus '.' and '->' are interchangable, as specified for the definitions of the | |
902 | expression element types STRUCTOP_STRUCT and STRUCTOP_PTR. | |
903 | ||
904 | If NOERR is nonzero, return zero if NAME is not suitably defined. | |
905 | If NAME is the name of a baseclass type, return that type. */ | |
906 | ||
907 | struct type * | |
fba45db2 | 908 | lookup_struct_elt_type (struct type *type, char *name, int noerr) |
c906108c SS |
909 | { |
910 | int i; | |
911 | ||
912 | for (;;) | |
913 | { | |
914 | CHECK_TYPEDEF (type); | |
915 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
916 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
917 | break; | |
918 | type = TYPE_TARGET_TYPE (type); | |
919 | } | |
920 | ||
921 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT && | |
922 | TYPE_CODE (type) != TYPE_CODE_UNION) | |
923 | { | |
924 | target_terminal_ours (); | |
925 | gdb_flush (gdb_stdout); | |
926 | fprintf_unfiltered (gdb_stderr, "Type "); | |
927 | type_print (type, "", gdb_stderr, -1); | |
928 | error (" is not a structure or union type."); | |
929 | } | |
930 | ||
931 | #if 0 | |
932 | /* FIXME: This change put in by Michael seems incorrect for the case where | |
933 | the structure tag name is the same as the member name. I.E. when doing | |
934 | "ptype bell->bar" for "struct foo { int bar; int foo; } bell;" | |
935 | Disabled by fnf. */ | |
936 | { | |
937 | char *typename; | |
938 | ||
939 | typename = type_name_no_tag (type); | |
940 | if (typename != NULL && STREQ (typename, name)) | |
941 | return type; | |
942 | } | |
943 | #endif | |
944 | ||
945 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | |
946 | { | |
947 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
948 | ||
db577aea | 949 | if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) |
c906108c SS |
950 | { |
951 | return TYPE_FIELD_TYPE (type, i); | |
952 | } | |
953 | } | |
954 | ||
955 | /* OK, it's not in this class. Recursively check the baseclasses. */ | |
956 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
957 | { | |
958 | struct type *t; | |
959 | ||
960 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr); | |
961 | if (t != NULL) | |
962 | { | |
963 | return t; | |
964 | } | |
965 | } | |
966 | ||
967 | if (noerr) | |
968 | { | |
969 | return NULL; | |
970 | } | |
c5aa993b | 971 | |
c906108c SS |
972 | target_terminal_ours (); |
973 | gdb_flush (gdb_stdout); | |
974 | fprintf_unfiltered (gdb_stderr, "Type "); | |
975 | type_print (type, "", gdb_stderr, -1); | |
976 | fprintf_unfiltered (gdb_stderr, " has no component named "); | |
977 | fputs_filtered (name, gdb_stderr); | |
978 | error ("."); | |
c5aa993b | 979 | return (struct type *) -1; /* For lint */ |
c906108c SS |
980 | } |
981 | ||
982 | /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE | |
983 | valid. Callers should be aware that in some cases (for example, | |
984 | the type or one of its baseclasses is a stub type and we are | |
985 | debugging a .o file), this function will not be able to find the virtual | |
986 | function table pointer, and vptr_fieldno will remain -1 and vptr_basetype | |
987 | will remain NULL. */ | |
988 | ||
989 | void | |
fba45db2 | 990 | fill_in_vptr_fieldno (struct type *type) |
c906108c SS |
991 | { |
992 | CHECK_TYPEDEF (type); | |
993 | ||
994 | if (TYPE_VPTR_FIELDNO (type) < 0) | |
995 | { | |
996 | int i; | |
997 | ||
998 | /* We must start at zero in case the first (and only) baseclass is | |
7b83ea04 | 999 | virtual (and hence we cannot share the table pointer). */ |
c906108c SS |
1000 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
1001 | { | |
1002 | fill_in_vptr_fieldno (TYPE_BASECLASS (type, i)); | |
1003 | if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0) | |
1004 | { | |
1005 | TYPE_VPTR_FIELDNO (type) | |
1006 | = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)); | |
1007 | TYPE_VPTR_BASETYPE (type) | |
1008 | = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i)); | |
1009 | break; | |
1010 | } | |
1011 | } | |
1012 | } | |
1013 | } | |
1014 | ||
1015 | /* Find the method and field indices for the destructor in class type T. | |
1016 | Return 1 if the destructor was found, otherwise, return 0. */ | |
1017 | ||
1018 | int | |
fba45db2 | 1019 | get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp) |
c906108c SS |
1020 | { |
1021 | int i; | |
1022 | ||
1023 | for (i = 0; i < TYPE_NFN_FIELDS (t); i++) | |
1024 | { | |
1025 | int j; | |
1026 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); | |
1027 | ||
1028 | for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++) | |
1029 | { | |
1030 | if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j))) | |
1031 | { | |
1032 | *method_indexp = i; | |
1033 | *field_indexp = j; | |
1034 | return 1; | |
1035 | } | |
1036 | } | |
1037 | } | |
1038 | return 0; | |
1039 | } | |
1040 | ||
1041 | /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989. | |
1042 | ||
1043 | If this is a stubbed struct (i.e. declared as struct foo *), see if | |
1044 | we can find a full definition in some other file. If so, copy this | |
1045 | definition, so we can use it in future. There used to be a comment (but | |
1046 | not any code) that if we don't find a full definition, we'd set a flag | |
1047 | so we don't spend time in the future checking the same type. That would | |
1048 | be a mistake, though--we might load in more symbols which contain a | |
1049 | full definition for the type. | |
1050 | ||
7b83ea04 | 1051 | This used to be coded as a macro, but I don't think it is called |
c906108c SS |
1052 | often enough to merit such treatment. */ |
1053 | ||
1054 | struct complaint stub_noname_complaint = | |
c5aa993b | 1055 | {"stub type has NULL name", 0, 0}; |
c906108c SS |
1056 | |
1057 | struct type * | |
fba45db2 | 1058 | check_typedef (register struct type *type) |
c906108c SS |
1059 | { |
1060 | struct type *orig_type = type; | |
1061 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) | |
1062 | { | |
1063 | if (!TYPE_TARGET_TYPE (type)) | |
1064 | { | |
c5aa993b | 1065 | char *name; |
c906108c SS |
1066 | struct symbol *sym; |
1067 | ||
1068 | /* It is dangerous to call lookup_symbol if we are currently | |
1069 | reading a symtab. Infinite recursion is one danger. */ | |
1070 | if (currently_reading_symtab) | |
1071 | return type; | |
1072 | ||
1073 | name = type_name_no_tag (type); | |
1074 | /* FIXME: shouldn't we separately check the TYPE_NAME and the | |
1075 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE | |
1076 | as appropriate? (this code was written before TYPE_NAME and | |
1077 | TYPE_TAG_NAME were separate). */ | |
1078 | if (name == NULL) | |
1079 | { | |
1080 | complain (&stub_noname_complaint); | |
1081 | return type; | |
1082 | } | |
c5aa993b | 1083 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, |
c906108c SS |
1084 | (struct symtab **) NULL); |
1085 | if (sym) | |
1086 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); | |
1087 | else | |
c5aa993b | 1088 | TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */ |
c906108c SS |
1089 | } |
1090 | type = TYPE_TARGET_TYPE (type); | |
1091 | } | |
1092 | ||
1093 | /* If this is a struct/class/union with no fields, then check whether a | |
1094 | full definition exists somewhere else. This is for systems where a | |
1095 | type definition with no fields is issued for such types, instead of | |
c5aa993b JM |
1096 | identifying them as stub types in the first place */ |
1097 | ||
c906108c SS |
1098 | if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab) |
1099 | { | |
c5aa993b JM |
1100 | char *name = type_name_no_tag (type); |
1101 | struct type *newtype; | |
c906108c SS |
1102 | if (name == NULL) |
1103 | { | |
1104 | complain (&stub_noname_complaint); | |
1105 | return type; | |
1106 | } | |
1107 | newtype = lookup_transparent_type (name); | |
1108 | if (newtype) | |
1109 | { | |
1110 | memcpy ((char *) type, (char *) newtype, sizeof (struct type)); | |
1111 | } | |
1112 | } | |
1113 | /* Otherwise, rely on the stub flag being set for opaque/stubbed types */ | |
c5aa993b | 1114 | else if ((TYPE_FLAGS (type) & TYPE_FLAG_STUB) && !currently_reading_symtab) |
c906108c | 1115 | { |
c5aa993b | 1116 | char *name = type_name_no_tag (type); |
c906108c | 1117 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
7b83ea04 AC |
1118 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE |
1119 | as appropriate? (this code was written before TYPE_NAME and | |
1120 | TYPE_TAG_NAME were separate). */ | |
c906108c SS |
1121 | struct symbol *sym; |
1122 | if (name == NULL) | |
1123 | { | |
1124 | complain (&stub_noname_complaint); | |
1125 | return type; | |
1126 | } | |
1127 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL); | |
1128 | if (sym) | |
1129 | { | |
c5aa993b | 1130 | memcpy ((char *) type, (char *) SYMBOL_TYPE (sym), sizeof (struct type)); |
c906108c SS |
1131 | } |
1132 | } | |
1133 | ||
1134 | if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB) | |
1135 | { | |
1136 | struct type *range_type; | |
1137 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); | |
1138 | ||
1139 | if (TYPE_FLAGS (target_type) & (TYPE_FLAG_STUB | TYPE_FLAG_TARGET_STUB)) | |
c5aa993b JM |
1140 | { |
1141 | } | |
c906108c SS |
1142 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
1143 | && TYPE_NFIELDS (type) == 1 | |
1144 | && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0)) | |
1145 | == TYPE_CODE_RANGE)) | |
1146 | { | |
1147 | /* Now recompute the length of the array type, based on its | |
1148 | number of elements and the target type's length. */ | |
1149 | TYPE_LENGTH (type) = | |
1150 | ((TYPE_FIELD_BITPOS (range_type, 1) | |
1151 | - TYPE_FIELD_BITPOS (range_type, 0) | |
1152 | + 1) | |
1153 | * TYPE_LENGTH (target_type)); | |
1154 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1155 | } | |
1156 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) | |
1157 | { | |
1158 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); | |
1159 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1160 | } | |
1161 | } | |
1162 | /* Cache TYPE_LENGTH for future use. */ | |
1163 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); | |
1164 | return type; | |
1165 | } | |
1166 | ||
1167 | /* New code added to support parsing of Cfront stabs strings */ | |
1168 | #include <ctype.h> | |
1169 | #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; } | |
1170 | #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; } | |
1171 | ||
c5aa993b | 1172 | static void |
fba45db2 | 1173 | add_name (struct extra *pextras, char *n) |
c906108c SS |
1174 | { |
1175 | int nlen; | |
1176 | ||
c5aa993b | 1177 | if ((nlen = (n ? strlen (n) : 0)) == 0) |
c906108c | 1178 | return; |
c5aa993b JM |
1179 | sprintf (pextras->str + pextras->len, "%d%s", nlen, n); |
1180 | pextras->len = strlen (pextras->str); | |
c906108c SS |
1181 | } |
1182 | ||
c5aa993b | 1183 | static void |
fba45db2 | 1184 | add_mangled_type (struct extra *pextras, struct type *t) |
c906108c SS |
1185 | { |
1186 | enum type_code tcode; | |
1187 | int tlen, tflags; | |
c5aa993b | 1188 | char *tname; |
c906108c | 1189 | |
c5aa993b JM |
1190 | tcode = TYPE_CODE (t); |
1191 | tlen = TYPE_LENGTH (t); | |
1192 | tflags = TYPE_FLAGS (t); | |
1193 | tname = TYPE_NAME (t); | |
c906108c SS |
1194 | /* args of "..." seem to get mangled as "e" */ |
1195 | ||
c5aa993b JM |
1196 | switch (tcode) |
1197 | { | |
1198 | case TYPE_CODE_INT: | |
1199 | if (tflags == 1) | |
1200 | ADD_EXTRA ('U'); | |
1201 | switch (tlen) | |
1202 | { | |
1203 | case 1: | |
1204 | ADD_EXTRA ('c'); | |
1205 | break; | |
1206 | case 2: | |
1207 | ADD_EXTRA ('s'); | |
1208 | break; | |
1209 | case 4: | |
1210 | { | |
1211 | char *pname; | |
1212 | if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long")) | |
9846de1b JM |
1213 | { |
1214 | ADD_EXTRA ('l'); | |
1215 | } | |
1216 | else | |
1217 | { | |
1218 | ADD_EXTRA ('i'); | |
1219 | } | |
c5aa993b JM |
1220 | } |
1221 | break; | |
1222 | default: | |
1223 | { | |
1224 | ||
1225 | static struct complaint msg = | |
1226 | {"Bad int type code length x%x\n", 0, 0}; | |
1227 | ||
1228 | complain (&msg, tlen); | |
1229 | ||
1230 | } | |
1231 | } | |
1232 | break; | |
1233 | case TYPE_CODE_FLT: | |
1234 | switch (tlen) | |
1235 | { | |
1236 | case 4: | |
1237 | ADD_EXTRA ('f'); | |
1238 | break; | |
1239 | case 8: | |
1240 | ADD_EXTRA ('d'); | |
1241 | break; | |
1242 | case 16: | |
1243 | ADD_EXTRA ('r'); | |
1244 | break; | |
1245 | default: | |
1246 | { | |
1247 | static struct complaint msg = | |
1248 | {"Bad float type code length x%x\n", 0, 0}; | |
1249 | complain (&msg, tlen); | |
1250 | } | |
1251 | } | |
1252 | break; | |
1253 | case TYPE_CODE_REF: | |
1254 | ADD_EXTRA ('R'); | |
1255 | /* followed by what it's a ref to */ | |
1256 | break; | |
1257 | case TYPE_CODE_PTR: | |
1258 | ADD_EXTRA ('P'); | |
1259 | /* followed by what it's a ptr to */ | |
1260 | break; | |
1261 | case TYPE_CODE_TYPEDEF: | |
1262 | { | |
1263 | static struct complaint msg = | |
1264 | {"Typedefs in overloaded functions not yet supported\n", 0, 0}; | |
1265 | complain (&msg); | |
1266 | } | |
c906108c SS |
1267 | /* followed by type bytes & name */ |
1268 | break; | |
1269 | case TYPE_CODE_FUNC: | |
c5aa993b | 1270 | ADD_EXTRA ('F'); |
c906108c SS |
1271 | /* followed by func's arg '_' & ret types */ |
1272 | break; | |
1273 | case TYPE_CODE_VOID: | |
c5aa993b | 1274 | ADD_EXTRA ('v'); |
c906108c SS |
1275 | break; |
1276 | case TYPE_CODE_METHOD: | |
c5aa993b | 1277 | ADD_EXTRA ('M'); |
c906108c | 1278 | /* followed by name of class and func's arg '_' & ret types */ |
c5aa993b JM |
1279 | add_name (pextras, tname); |
1280 | ADD_EXTRA ('F'); /* then mangle function */ | |
c906108c | 1281 | break; |
c5aa993b JM |
1282 | case TYPE_CODE_STRUCT: /* C struct */ |
1283 | case TYPE_CODE_UNION: /* C union */ | |
1284 | case TYPE_CODE_ENUM: /* Enumeration type */ | |
c906108c | 1285 | /* followed by name of type */ |
c5aa993b | 1286 | add_name (pextras, tname); |
c906108c SS |
1287 | break; |
1288 | ||
c5aa993b JM |
1289 | /* errors possible types/not supported */ |
1290 | case TYPE_CODE_CHAR: | |
1291 | case TYPE_CODE_ARRAY: /* Array type */ | |
1292 | case TYPE_CODE_MEMBER: /* Member type */ | |
c906108c | 1293 | case TYPE_CODE_BOOL: |
c5aa993b | 1294 | case TYPE_CODE_COMPLEX: /* Complex float */ |
c906108c | 1295 | case TYPE_CODE_UNDEF: |
c5aa993b JM |
1296 | case TYPE_CODE_SET: /* Pascal sets */ |
1297 | case TYPE_CODE_RANGE: | |
c906108c SS |
1298 | case TYPE_CODE_STRING: |
1299 | case TYPE_CODE_BITSTRING: | |
1300 | case TYPE_CODE_ERROR: | |
c5aa993b | 1301 | default: |
c906108c | 1302 | { |
c5aa993b JM |
1303 | static struct complaint msg = |
1304 | {"Unknown type code x%x\n", 0, 0}; | |
1305 | complain (&msg, tcode); | |
c906108c SS |
1306 | } |
1307 | } | |
1308 | if (t->target_type) | |
c5aa993b | 1309 | add_mangled_type (pextras, t->target_type); |
c906108c SS |
1310 | } |
1311 | ||
1312 | #if 0 | |
1313 | void | |
fba45db2 | 1314 | cfront_mangle_name (struct type *type, int i, int j) |
c906108c | 1315 | { |
c5aa993b JM |
1316 | struct fn_field *f; |
1317 | char *mangled_name = gdb_mangle_name (type, i, j); | |
1318 | ||
1319 | f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */ | |
1320 | ||
7b83ea04 | 1321 | /* kludge to support cfront methods - gdb expects to find "F" for |
c5aa993b JM |
1322 | ARM_mangled names, so when we mangle, we have to add it here */ |
1323 | if (ARM_DEMANGLING) | |
1324 | { | |
1325 | int k; | |
1326 | char *arm_mangled_name; | |
1327 | struct fn_field *method = &f[j]; | |
1328 | char *field_name = TYPE_FN_FIELDLIST_NAME (type, i); | |
1329 | char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); | |
1330 | char *newname = type_name_no_tag (type); | |
1331 | ||
1332 | struct type *ftype = TYPE_FN_FIELD_TYPE (f, j); | |
1333 | int nargs = TYPE_NFIELDS (ftype); /* number of args */ | |
1334 | struct extra extras, *pextras = &extras; | |
1335 | INIT_EXTRA | |
c906108c SS |
1336 | |
1337 | if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */ | |
c5aa993b JM |
1338 | ADD_EXTRA ('S') |
1339 | ADD_EXTRA ('F') | |
c906108c | 1340 | /* add args here! */ |
c5aa993b JM |
1341 | if (nargs <= 1) /* no args besides this */ |
1342 | ADD_EXTRA ('v') | |
1343 | else | |
1344 | { | |
1345 | for (k = 1; k < nargs; k++) | |
1346 | { | |
1347 | struct type *t; | |
1348 | t = TYPE_FIELD_TYPE (ftype, k); | |
1349 | add_mangled_type (pextras, t); | |
1350 | } | |
1351 | } | |
1352 | ADD_EXTRA ('\0') | |
1353 | printf ("add_mangled_type: %s\n", extras.str); /* FIXME */ | |
1354 | arm_mangled_name = malloc (strlen (mangled_name) + extras.len); | |
1355 | sprintf (arm_mangled_name, "%s%s", mangled_name, extras.str); | |
b8c9b27d | 1356 | xfree (mangled_name); |
c5aa993b JM |
1357 | mangled_name = arm_mangled_name; |
1358 | } | |
c906108c | 1359 | } |
c5aa993b | 1360 | #endif /* 0 */ |
c906108c SS |
1361 | |
1362 | #undef ADD_EXTRA | |
1363 | /* End of new code added to support parsing of Cfront stabs strings */ | |
1364 | ||
c91ecb25 ND |
1365 | /* Parse a type expression in the string [P..P+LENGTH). If an error occurs, |
1366 | silently return builtin_type_void. */ | |
1367 | ||
1368 | struct type * | |
1369 | safe_parse_type (char *p, int length) | |
1370 | { | |
1371 | struct ui_file *saved_gdb_stderr; | |
1372 | struct type *type; | |
1373 | ||
1374 | /* Suppress error messages. */ | |
1375 | saved_gdb_stderr = gdb_stderr; | |
1376 | gdb_stderr = ui_file_new (); | |
1377 | ||
1378 | /* Call parse_and_eval_type() without fear of longjmp()s. */ | |
1379 | if (!gdb_parse_and_eval_type (p, length, &type)) | |
1380 | type = builtin_type_void; | |
1381 | ||
1382 | /* Stop suppressing error messages. */ | |
1383 | ui_file_delete (gdb_stderr); | |
1384 | gdb_stderr = saved_gdb_stderr; | |
1385 | ||
1386 | return type; | |
1387 | } | |
1388 | ||
c906108c SS |
1389 | /* Ugly hack to convert method stubs into method types. |
1390 | ||
1391 | He ain't kiddin'. This demangles the name of the method into a string | |
1392 | including argument types, parses out each argument type, generates | |
1393 | a string casting a zero to that type, evaluates the string, and stuffs | |
1394 | the resulting type into an argtype vector!!! Then it knows the type | |
1395 | of the whole function (including argument types for overloading), | |
1396 | which info used to be in the stab's but was removed to hack back | |
1397 | the space required for them. */ | |
1398 | ||
1399 | void | |
fba45db2 | 1400 | check_stub_method (struct type *type, int method_id, int signature_id) |
c906108c SS |
1401 | { |
1402 | struct fn_field *f; | |
1403 | char *mangled_name = gdb_mangle_name (type, method_id, signature_id); | |
1404 | char *demangled_name = cplus_demangle (mangled_name, | |
1405 | DMGL_PARAMS | DMGL_ANSI); | |
1406 | char *argtypetext, *p; | |
1407 | int depth = 0, argcount = 1; | |
1408 | struct type **argtypes; | |
1409 | struct type *mtype; | |
1410 | ||
1411 | /* Make sure we got back a function string that we can use. */ | |
1412 | if (demangled_name) | |
1413 | p = strchr (demangled_name, '('); | |
1414 | ||
1415 | if (demangled_name == NULL || p == NULL) | |
1416 | error ("Internal: Cannot demangle mangled name `%s'.", mangled_name); | |
1417 | ||
1418 | /* Now, read in the parameters that define this type. */ | |
1419 | p += 1; | |
1420 | argtypetext = p; | |
1421 | while (*p) | |
1422 | { | |
070ad9f0 | 1423 | if (*p == '(' || *p == '<') |
c906108c SS |
1424 | { |
1425 | depth += 1; | |
1426 | } | |
070ad9f0 | 1427 | else if (*p == ')' || *p == '>') |
c906108c SS |
1428 | { |
1429 | depth -= 1; | |
1430 | } | |
1431 | else if (*p == ',' && depth == 0) | |
1432 | { | |
1433 | argcount += 1; | |
1434 | } | |
1435 | ||
1436 | p += 1; | |
1437 | } | |
1438 | ||
1439 | /* We need two more slots: one for the THIS pointer, and one for the | |
1440 | NULL [...] or void [end of arglist]. */ | |
1441 | ||
1442 | argtypes = (struct type **) | |
1443 | TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *)); | |
1444 | p = argtypetext; | |
1445 | /* FIXME: This is wrong for static member functions. */ | |
1446 | argtypes[0] = lookup_pointer_type (type); | |
1447 | argcount = 1; | |
1448 | ||
c5aa993b | 1449 | if (*p != ')') /* () means no args, skip while */ |
c906108c SS |
1450 | { |
1451 | depth = 0; | |
1452 | while (*p) | |
1453 | { | |
1454 | if (depth <= 0 && (*p == ',' || *p == ')')) | |
1455 | { | |
1456 | /* Avoid parsing of ellipsis, they will be handled below. */ | |
1457 | if (strncmp (argtypetext, "...", p - argtypetext) != 0) | |
1458 | { | |
1459 | argtypes[argcount] = | |
c91ecb25 | 1460 | safe_parse_type (argtypetext, p - argtypetext); |
c906108c SS |
1461 | argcount += 1; |
1462 | } | |
1463 | argtypetext = p + 1; | |
1464 | } | |
1465 | ||
070ad9f0 | 1466 | if (*p == '(' || *p == '<') |
c906108c SS |
1467 | { |
1468 | depth += 1; | |
1469 | } | |
070ad9f0 | 1470 | else if (*p == ')' || *p == '>') |
c906108c SS |
1471 | { |
1472 | depth -= 1; | |
1473 | } | |
1474 | ||
1475 | p += 1; | |
1476 | } | |
1477 | } | |
1478 | ||
c5aa993b | 1479 | if (p[-2] != '.') /* Not '...' */ |
c906108c SS |
1480 | { |
1481 | argtypes[argcount] = builtin_type_void; /* List terminator */ | |
1482 | } | |
1483 | else | |
1484 | { | |
c5aa993b | 1485 | argtypes[argcount] = NULL; /* Ellist terminator */ |
c906108c SS |
1486 | } |
1487 | ||
b8c9b27d | 1488 | xfree (demangled_name); |
c906108c | 1489 | |
c5aa993b | 1490 | f = TYPE_FN_FIELDLIST1 (type, method_id); |
c906108c SS |
1491 | |
1492 | TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name; | |
1493 | ||
1494 | /* Now update the old "stub" type into a real type. */ | |
1495 | mtype = TYPE_FN_FIELD_TYPE (f, signature_id); | |
1496 | TYPE_DOMAIN_TYPE (mtype) = type; | |
1497 | TYPE_ARG_TYPES (mtype) = argtypes; | |
1498 | TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB; | |
1499 | TYPE_FN_FIELD_STUB (f, signature_id) = 0; | |
1500 | } | |
1501 | ||
1502 | const struct cplus_struct_type cplus_struct_default; | |
1503 | ||
1504 | void | |
fba45db2 | 1505 | allocate_cplus_struct_type (struct type *type) |
c906108c SS |
1506 | { |
1507 | if (!HAVE_CPLUS_STRUCT (type)) | |
1508 | { | |
1509 | TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) | |
1510 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); | |
c5aa993b | 1511 | *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default; |
c906108c SS |
1512 | } |
1513 | } | |
1514 | ||
1515 | /* Helper function to initialize the standard scalar types. | |
1516 | ||
1517 | If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy | |
1518 | of the string pointed to by name in the type_obstack for that objfile, | |
1519 | and initialize the type name to that copy. There are places (mipsread.c | |
1520 | in particular, where init_type is called with a NULL value for NAME). */ | |
1521 | ||
1522 | struct type * | |
fba45db2 KB |
1523 | init_type (enum type_code code, int length, int flags, char *name, |
1524 | struct objfile *objfile) | |
c906108c SS |
1525 | { |
1526 | register struct type *type; | |
1527 | ||
1528 | type = alloc_type (objfile); | |
1529 | TYPE_CODE (type) = code; | |
1530 | TYPE_LENGTH (type) = length; | |
1531 | TYPE_FLAGS (type) |= flags; | |
1532 | if ((name != NULL) && (objfile != NULL)) | |
1533 | { | |
1534 | TYPE_NAME (type) = | |
c5aa993b | 1535 | obsavestring (name, strlen (name), &objfile->type_obstack); |
c906108c SS |
1536 | } |
1537 | else | |
1538 | { | |
1539 | TYPE_NAME (type) = name; | |
1540 | } | |
1541 | ||
1542 | /* C++ fancies. */ | |
1543 | ||
1544 | if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION) | |
1545 | { | |
1546 | INIT_CPLUS_SPECIFIC (type); | |
1547 | } | |
1548 | return (type); | |
1549 | } | |
1550 | ||
1551 | /* Look up a fundamental type for the specified objfile. | |
1552 | May need to construct such a type if this is the first use. | |
1553 | ||
1554 | Some object file formats (ELF, COFF, etc) do not define fundamental | |
1555 | types such as "int" or "double". Others (stabs for example), do | |
1556 | define fundamental types. | |
1557 | ||
1558 | For the formats which don't provide fundamental types, gdb can create | |
1559 | such types, using defaults reasonable for the current language and | |
1560 | the current target machine. | |
1561 | ||
1562 | NOTE: This routine is obsolescent. Each debugging format reader | |
1563 | should manage it's own fundamental types, either creating them from | |
1564 | suitable defaults or reading them from the debugging information, | |
1565 | whichever is appropriate. The DWARF reader has already been | |
1566 | fixed to do this. Once the other readers are fixed, this routine | |
1567 | will go away. Also note that fundamental types should be managed | |
1568 | on a compilation unit basis in a multi-language environment, not | |
1569 | on a linkage unit basis as is done here. */ | |
1570 | ||
1571 | ||
1572 | struct type * | |
fba45db2 | 1573 | lookup_fundamental_type (struct objfile *objfile, int typeid) |
c906108c SS |
1574 | { |
1575 | register struct type **typep; | |
1576 | register int nbytes; | |
1577 | ||
1578 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
1579 | { | |
1580 | error ("internal error - invalid fundamental type id %d", typeid); | |
1581 | } | |
1582 | ||
1583 | /* If this is the first time we need a fundamental type for this objfile | |
1584 | then we need to initialize the vector of type pointers. */ | |
c5aa993b JM |
1585 | |
1586 | if (objfile->fundamental_types == NULL) | |
c906108c SS |
1587 | { |
1588 | nbytes = FT_NUM_MEMBERS * sizeof (struct type *); | |
c5aa993b JM |
1589 | objfile->fundamental_types = (struct type **) |
1590 | obstack_alloc (&objfile->type_obstack, nbytes); | |
1591 | memset ((char *) objfile->fundamental_types, 0, nbytes); | |
c906108c SS |
1592 | OBJSTAT (objfile, n_types += FT_NUM_MEMBERS); |
1593 | } | |
1594 | ||
1595 | /* Look for this particular type in the fundamental type vector. If one is | |
1596 | not found, create and install one appropriate for the current language. */ | |
1597 | ||
c5aa993b | 1598 | typep = objfile->fundamental_types + typeid; |
c906108c SS |
1599 | if (*typep == NULL) |
1600 | { | |
1601 | *typep = create_fundamental_type (objfile, typeid); | |
1602 | } | |
1603 | ||
1604 | return (*typep); | |
1605 | } | |
1606 | ||
1607 | int | |
fba45db2 | 1608 | can_dereference (struct type *t) |
c906108c SS |
1609 | { |
1610 | /* FIXME: Should we return true for references as well as pointers? */ | |
1611 | CHECK_TYPEDEF (t); | |
1612 | return | |
1613 | (t != NULL | |
1614 | && TYPE_CODE (t) == TYPE_CODE_PTR | |
1615 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); | |
1616 | } | |
1617 | ||
adf40b2e | 1618 | int |
fba45db2 | 1619 | is_integral_type (struct type *t) |
adf40b2e JM |
1620 | { |
1621 | CHECK_TYPEDEF (t); | |
1622 | return | |
1623 | ((t != NULL) | |
d4f3574e SS |
1624 | && ((TYPE_CODE (t) == TYPE_CODE_INT) |
1625 | || (TYPE_CODE (t) == TYPE_CODE_ENUM) | |
1626 | || (TYPE_CODE (t) == TYPE_CODE_CHAR) | |
1627 | || (TYPE_CODE (t) == TYPE_CODE_RANGE) | |
1628 | || (TYPE_CODE (t) == TYPE_CODE_BOOL))); | |
adf40b2e JM |
1629 | } |
1630 | ||
c906108c SS |
1631 | /* Chill varying string and arrays are represented as follows: |
1632 | ||
1633 | struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data}; | |
1634 | ||
1635 | Return true if TYPE is such a Chill varying type. */ | |
1636 | ||
1637 | int | |
fba45db2 | 1638 | chill_varying_type (struct type *type) |
c906108c SS |
1639 | { |
1640 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT | |
1641 | || TYPE_NFIELDS (type) != 2 | |
1642 | || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0) | |
1643 | return 0; | |
1644 | return 1; | |
1645 | } | |
1646 | ||
7b83ea04 | 1647 | /* Check whether BASE is an ancestor or base class or DCLASS |
c906108c SS |
1648 | Return 1 if so, and 0 if not. |
1649 | Note: callers may want to check for identity of the types before | |
1650 | calling this function -- identical types are considered to satisfy | |
1651 | the ancestor relationship even if they're identical */ | |
1652 | ||
1653 | int | |
fba45db2 | 1654 | is_ancestor (struct type *base, struct type *dclass) |
c906108c SS |
1655 | { |
1656 | int i; | |
c5aa993b | 1657 | |
c906108c SS |
1658 | CHECK_TYPEDEF (base); |
1659 | CHECK_TYPEDEF (dclass); | |
1660 | ||
1661 | if (base == dclass) | |
1662 | return 1; | |
6b1ba9a0 ND |
1663 | if (TYPE_NAME (base) && TYPE_NAME (dclass) && |
1664 | !strcmp (TYPE_NAME (base), TYPE_NAME (dclass))) | |
1665 | return 1; | |
c906108c SS |
1666 | |
1667 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1668 | if (is_ancestor (base, TYPE_BASECLASS (dclass, i))) | |
1669 | return 1; | |
1670 | ||
1671 | return 0; | |
1672 | } | |
1673 | ||
1674 | ||
1675 | ||
1676 | /* See whether DCLASS has a virtual table. This routine is aimed at | |
1677 | the HP/Taligent ANSI C++ runtime model, and may not work with other | |
1678 | runtime models. Return 1 => Yes, 0 => No. */ | |
1679 | ||
1680 | int | |
fba45db2 | 1681 | has_vtable (struct type *dclass) |
c906108c SS |
1682 | { |
1683 | /* In the HP ANSI C++ runtime model, a class has a vtable only if it | |
1684 | has virtual functions or virtual bases. */ | |
1685 | ||
1686 | register int i; | |
1687 | ||
c5aa993b | 1688 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c | 1689 | return 0; |
c5aa993b | 1690 | |
c906108c | 1691 | /* First check for the presence of virtual bases */ |
c5aa993b JM |
1692 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) |
1693 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1694 | if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) | |
1695 | return 1; | |
1696 | ||
c906108c | 1697 | /* Next check for virtual functions */ |
c5aa993b JM |
1698 | if (TYPE_FN_FIELDLISTS (dclass)) |
1699 | for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++) | |
1700 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0)) | |
c906108c | 1701 | return 1; |
c5aa993b JM |
1702 | |
1703 | /* Recurse on non-virtual bases to see if any of them needs a vtable */ | |
1704 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) | |
1705 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1706 | if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) && | |
1707 | (has_vtable (TYPE_FIELD_TYPE (dclass, i)))) | |
1708 | return 1; | |
1709 | ||
1710 | /* Well, maybe we don't need a virtual table */ | |
c906108c SS |
1711 | return 0; |
1712 | } | |
1713 | ||
1714 | /* Return a pointer to the "primary base class" of DCLASS. | |
c5aa993b | 1715 | |
c906108c SS |
1716 | A NULL return indicates that DCLASS has no primary base, or that it |
1717 | couldn't be found (insufficient information). | |
c5aa993b | 1718 | |
c906108c SS |
1719 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
1720 | and may not work with other runtime models. */ | |
1721 | ||
1722 | struct type * | |
fba45db2 | 1723 | primary_base_class (struct type *dclass) |
c906108c SS |
1724 | { |
1725 | /* In HP ANSI C++'s runtime model, a "primary base class" of a class | |
1726 | is the first directly inherited, non-virtual base class that | |
1727 | requires a virtual table */ | |
1728 | ||
1729 | register int i; | |
1730 | ||
c5aa993b | 1731 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c SS |
1732 | return NULL; |
1733 | ||
c5aa993b JM |
1734 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
1735 | if (!TYPE_FIELD_VIRTUAL (dclass, i) && | |
1736 | has_vtable (TYPE_FIELD_TYPE (dclass, i))) | |
1737 | return TYPE_FIELD_TYPE (dclass, i); | |
c906108c SS |
1738 | |
1739 | return NULL; | |
1740 | } | |
1741 | ||
1742 | /* Global manipulated by virtual_base_list[_aux]() */ | |
1743 | ||
c5aa993b | 1744 | static struct vbase *current_vbase_list = NULL; |
c906108c SS |
1745 | |
1746 | /* Return a pointer to a null-terminated list of struct vbase | |
1747 | items. The vbasetype pointer of each item in the list points to the | |
1748 | type information for a virtual base of the argument DCLASS. | |
c5aa993b | 1749 | |
7b83ea04 | 1750 | Helper function for virtual_base_list(). |
c906108c SS |
1751 | Note: the list goes backward, right-to-left. virtual_base_list() |
1752 | copies the items out in reverse order. */ | |
1753 | ||
7a292a7a | 1754 | static void |
fba45db2 | 1755 | virtual_base_list_aux (struct type *dclass) |
c906108c | 1756 | { |
c5aa993b | 1757 | struct vbase *tmp_vbase; |
c906108c SS |
1758 | register int i; |
1759 | ||
c5aa993b | 1760 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
7a292a7a | 1761 | return; |
c906108c SS |
1762 | |
1763 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1764 | { | |
1765 | /* Recurse on this ancestor, first */ | |
c5aa993b | 1766 | virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i)); |
c906108c SS |
1767 | |
1768 | /* If this current base is itself virtual, add it to the list */ | |
c5aa993b JM |
1769 | if (BASETYPE_VIA_VIRTUAL (dclass, i)) |
1770 | { | |
1771 | struct type *basetype = TYPE_FIELD_TYPE (dclass, i); | |
1772 | ||
1773 | /* Check if base already recorded */ | |
1774 | tmp_vbase = current_vbase_list; | |
1775 | while (tmp_vbase) | |
1776 | { | |
1777 | if (tmp_vbase->vbasetype == basetype) | |
1778 | break; /* found it */ | |
1779 | tmp_vbase = tmp_vbase->next; | |
1780 | } | |
1781 | ||
1782 | if (!tmp_vbase) /* normal exit from loop */ | |
1783 | { | |
1784 | /* Allocate new item for this virtual base */ | |
1785 | tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase)); | |
1786 | ||
1787 | /* Stick it on at the end of the list */ | |
1788 | tmp_vbase->vbasetype = basetype; | |
1789 | tmp_vbase->next = current_vbase_list; | |
1790 | current_vbase_list = tmp_vbase; | |
1791 | } | |
1792 | } /* if virtual */ | |
1793 | } /* for loop over bases */ | |
c906108c SS |
1794 | } |
1795 | ||
1796 | ||
1797 | /* Compute the list of virtual bases in the right order. Virtual | |
1798 | bases are laid out in the object's memory area in order of their | |
1799 | occurrence in a depth-first, left-to-right search through the | |
1800 | ancestors. | |
c5aa993b | 1801 | |
c906108c SS |
1802 | Argument DCLASS is the type whose virtual bases are required. |
1803 | Return value is the address of a null-terminated array of pointers | |
1804 | to struct type items. | |
c5aa993b | 1805 | |
c906108c SS |
1806 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
1807 | and may not work with other runtime models. | |
c5aa993b | 1808 | |
c906108c SS |
1809 | This routine merely hands off the argument to virtual_base_list_aux() |
1810 | and then copies the result into an array to save space. */ | |
1811 | ||
1812 | struct type ** | |
fba45db2 | 1813 | virtual_base_list (struct type *dclass) |
c906108c | 1814 | { |
c5aa993b JM |
1815 | register struct vbase *tmp_vbase; |
1816 | register struct vbase *tmp_vbase_2; | |
c906108c SS |
1817 | register int i; |
1818 | int count; | |
c5aa993b | 1819 | struct type **vbase_array; |
c906108c SS |
1820 | |
1821 | current_vbase_list = NULL; | |
c5aa993b | 1822 | virtual_base_list_aux (dclass); |
c906108c | 1823 | |
c5aa993b | 1824 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
c906108c SS |
1825 | /* no body */ ; |
1826 | ||
1827 | count = i; | |
1828 | ||
c5aa993b | 1829 | vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *)); |
c906108c | 1830 | |
c5aa993b | 1831 | for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next) |
c906108c SS |
1832 | vbase_array[i] = tmp_vbase->vbasetype; |
1833 | ||
1834 | /* Get rid of constructed chain */ | |
1835 | tmp_vbase_2 = tmp_vbase = current_vbase_list; | |
1836 | while (tmp_vbase) | |
1837 | { | |
1838 | tmp_vbase = tmp_vbase->next; | |
b8c9b27d | 1839 | xfree (tmp_vbase_2); |
c906108c SS |
1840 | tmp_vbase_2 = tmp_vbase; |
1841 | } | |
c5aa993b | 1842 | |
c906108c SS |
1843 | vbase_array[count] = NULL; |
1844 | return vbase_array; | |
1845 | } | |
1846 | ||
1847 | /* Return the length of the virtual base list of the type DCLASS. */ | |
1848 | ||
1849 | int | |
fba45db2 | 1850 | virtual_base_list_length (struct type *dclass) |
c906108c SS |
1851 | { |
1852 | register int i; | |
c5aa993b JM |
1853 | register struct vbase *tmp_vbase; |
1854 | ||
c906108c | 1855 | current_vbase_list = NULL; |
c5aa993b | 1856 | virtual_base_list_aux (dclass); |
c906108c | 1857 | |
c5aa993b | 1858 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
c906108c SS |
1859 | /* no body */ ; |
1860 | return i; | |
1861 | } | |
1862 | ||
1863 | /* Return the number of elements of the virtual base list of the type | |
1864 | DCLASS, ignoring those appearing in the primary base (and its | |
1865 | primary base, recursively). */ | |
1866 | ||
1867 | int | |
fba45db2 | 1868 | virtual_base_list_length_skip_primaries (struct type *dclass) |
c906108c SS |
1869 | { |
1870 | register int i; | |
c5aa993b JM |
1871 | register struct vbase *tmp_vbase; |
1872 | struct type *primary; | |
c906108c SS |
1873 | |
1874 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; | |
1875 | ||
1876 | if (!primary) | |
1877 | return virtual_base_list_length (dclass); | |
1878 | ||
1879 | current_vbase_list = NULL; | |
c5aa993b | 1880 | virtual_base_list_aux (dclass); |
c906108c | 1881 | |
c5aa993b | 1882 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next) |
c906108c SS |
1883 | { |
1884 | if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0) | |
c5aa993b | 1885 | continue; |
c906108c SS |
1886 | i++; |
1887 | } | |
1888 | return i; | |
1889 | } | |
1890 | ||
1891 | ||
1892 | /* Return the index (position) of type BASE, which is a virtual base | |
1893 | class of DCLASS, in the latter's virtual base list. A return of -1 | |
1894 | indicates "not found" or a problem. */ | |
1895 | ||
1896 | int | |
fba45db2 | 1897 | virtual_base_index (struct type *base, struct type *dclass) |
c906108c | 1898 | { |
c5aa993b | 1899 | register struct type *vbase; |
c906108c SS |
1900 | register int i; |
1901 | ||
c5aa993b JM |
1902 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
1903 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
1904 | return -1; |
1905 | ||
1906 | i = 0; | |
c5aa993b | 1907 | vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0]; |
c906108c SS |
1908 | while (vbase) |
1909 | { | |
1910 | if (vbase == base) | |
c5aa993b JM |
1911 | break; |
1912 | vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i]; | |
c906108c SS |
1913 | } |
1914 | ||
1915 | return vbase ? i : -1; | |
1916 | } | |
1917 | ||
1918 | ||
1919 | ||
1920 | /* Return the index (position) of type BASE, which is a virtual base | |
1921 | class of DCLASS, in the latter's virtual base list. Skip over all | |
1922 | bases that may appear in the virtual base list of the primary base | |
1923 | class of DCLASS (recursively). A return of -1 indicates "not | |
1924 | found" or a problem. */ | |
1925 | ||
1926 | int | |
fba45db2 | 1927 | virtual_base_index_skip_primaries (struct type *base, struct type *dclass) |
c906108c | 1928 | { |
c5aa993b | 1929 | register struct type *vbase; |
c906108c | 1930 | register int i, j; |
c5aa993b | 1931 | struct type *primary; |
c906108c | 1932 | |
c5aa993b JM |
1933 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
1934 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
1935 | return -1; |
1936 | ||
c5aa993b | 1937 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; |
c906108c SS |
1938 | |
1939 | j = -1; | |
1940 | i = 0; | |
c5aa993b | 1941 | vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0]; |
c906108c SS |
1942 | while (vbase) |
1943 | { | |
c5aa993b JM |
1944 | if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0)) |
1945 | j++; | |
c906108c | 1946 | if (vbase == base) |
c5aa993b JM |
1947 | break; |
1948 | vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i]; | |
c906108c SS |
1949 | } |
1950 | ||
1951 | return vbase ? j : -1; | |
1952 | } | |
1953 | ||
1954 | /* Return position of a derived class DCLASS in the list of | |
1955 | * primary bases starting with the remotest ancestor. | |
1956 | * Position returned is 0-based. */ | |
1957 | ||
1958 | int | |
fba45db2 | 1959 | class_index_in_primary_list (struct type *dclass) |
c906108c | 1960 | { |
c5aa993b | 1961 | struct type *pbc; /* primary base class */ |
c906108c | 1962 | |
c5aa993b | 1963 | /* Simply recurse on primary base */ |
c906108c SS |
1964 | pbc = TYPE_PRIMARY_BASE (dclass); |
1965 | if (pbc) | |
1966 | return 1 + class_index_in_primary_list (pbc); | |
1967 | else | |
1968 | return 0; | |
1969 | } | |
1970 | ||
1971 | /* Return a count of the number of virtual functions a type has. | |
1972 | * This includes all the virtual functions it inherits from its | |
1973 | * base classes too. | |
1974 | */ | |
1975 | ||
1976 | /* pai: FIXME This doesn't do the right thing: count redefined virtual | |
1977 | * functions only once (latest redefinition) | |
1978 | */ | |
1979 | ||
1980 | int | |
fba45db2 | 1981 | count_virtual_fns (struct type *dclass) |
c906108c | 1982 | { |
c5aa993b | 1983 | int fn, oi; /* function and overloaded instance indices */ |
c5aa993b JM |
1984 | int vfuncs; /* count to return */ |
1985 | ||
1986 | /* recurse on bases that can share virtual table */ | |
1987 | struct type *pbc = primary_base_class (dclass); | |
c906108c SS |
1988 | if (pbc) |
1989 | vfuncs = count_virtual_fns (pbc); | |
7f7e9482 AC |
1990 | else |
1991 | vfuncs = 0; | |
c5aa993b | 1992 | |
c906108c SS |
1993 | for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++) |
1994 | for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++) | |
1995 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi)) | |
c5aa993b | 1996 | vfuncs++; |
c906108c SS |
1997 | |
1998 | return vfuncs; | |
1999 | } | |
c906108c SS |
2000 | \f |
2001 | ||
c5aa993b | 2002 | |
c906108c SS |
2003 | /* Functions for overload resolution begin here */ |
2004 | ||
2005 | /* Compare two badness vectors A and B and return the result. | |
2006 | * 0 => A and B are identical | |
2007 | * 1 => A and B are incomparable | |
2008 | * 2 => A is better than B | |
2009 | * 3 => A is worse than B */ | |
2010 | ||
2011 | int | |
fba45db2 | 2012 | compare_badness (struct badness_vector *a, struct badness_vector *b) |
c906108c SS |
2013 | { |
2014 | int i; | |
2015 | int tmp; | |
c5aa993b JM |
2016 | short found_pos = 0; /* any positives in c? */ |
2017 | short found_neg = 0; /* any negatives in c? */ | |
2018 | ||
2019 | /* differing lengths => incomparable */ | |
c906108c SS |
2020 | if (a->length != b->length) |
2021 | return 1; | |
2022 | ||
c5aa993b JM |
2023 | /* Subtract b from a */ |
2024 | for (i = 0; i < a->length; i++) | |
c906108c SS |
2025 | { |
2026 | tmp = a->rank[i] - b->rank[i]; | |
2027 | if (tmp > 0) | |
c5aa993b | 2028 | found_pos = 1; |
c906108c | 2029 | else if (tmp < 0) |
c5aa993b | 2030 | found_neg = 1; |
c906108c SS |
2031 | } |
2032 | ||
2033 | if (found_pos) | |
2034 | { | |
2035 | if (found_neg) | |
c5aa993b | 2036 | return 1; /* incomparable */ |
c906108c | 2037 | else |
c5aa993b | 2038 | return 3; /* A > B */ |
c906108c | 2039 | } |
c5aa993b JM |
2040 | else |
2041 | /* no positives */ | |
c906108c SS |
2042 | { |
2043 | if (found_neg) | |
c5aa993b | 2044 | return 2; /* A < B */ |
c906108c | 2045 | else |
c5aa993b | 2046 | return 0; /* A == B */ |
c906108c SS |
2047 | } |
2048 | } | |
2049 | ||
2050 | /* Rank a function by comparing its parameter types (PARMS, length NPARMS), | |
2051 | * to the types of an argument list (ARGS, length NARGS). | |
2052 | * Return a pointer to a badness vector. This has NARGS + 1 entries. */ | |
2053 | ||
2054 | struct badness_vector * | |
fba45db2 | 2055 | rank_function (struct type **parms, int nparms, struct type **args, int nargs) |
c906108c SS |
2056 | { |
2057 | int i; | |
c5aa993b | 2058 | struct badness_vector *bv; |
c906108c SS |
2059 | int min_len = nparms < nargs ? nparms : nargs; |
2060 | ||
2061 | bv = xmalloc (sizeof (struct badness_vector)); | |
c5aa993b | 2062 | bv->length = nargs + 1; /* add 1 for the length-match rank */ |
c906108c SS |
2063 | bv->rank = xmalloc ((nargs + 1) * sizeof (int)); |
2064 | ||
2065 | /* First compare the lengths of the supplied lists. | |
2066 | * If there is a mismatch, set it to a high value. */ | |
c5aa993b | 2067 | |
c906108c SS |
2068 | /* pai/1997-06-03 FIXME: when we have debug info about default |
2069 | * arguments and ellipsis parameter lists, we should consider those | |
2070 | * and rank the length-match more finely. */ | |
2071 | ||
2072 | LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0; | |
2073 | ||
2074 | /* Now rank all the parameters of the candidate function */ | |
74cc24b0 DB |
2075 | for (i = 1; i <= min_len; i++) |
2076 | bv->rank[i] = rank_one_type (parms[i-1], args[i-1]); | |
c906108c | 2077 | |
c5aa993b JM |
2078 | /* If more arguments than parameters, add dummy entries */ |
2079 | for (i = min_len + 1; i <= nargs; i++) | |
c906108c SS |
2080 | bv->rank[i] = TOO_FEW_PARAMS_BADNESS; |
2081 | ||
2082 | return bv; | |
2083 | } | |
2084 | ||
2085 | /* Compare one type (PARM) for compatibility with another (ARG). | |
2086 | * PARM is intended to be the parameter type of a function; and | |
2087 | * ARG is the supplied argument's type. This function tests if | |
2088 | * the latter can be converted to the former. | |
2089 | * | |
2090 | * Return 0 if they are identical types; | |
2091 | * Otherwise, return an integer which corresponds to how compatible | |
2092 | * PARM is to ARG. The higher the return value, the worse the match. | |
2093 | * Generally the "bad" conversions are all uniformly assigned a 100 */ | |
2094 | ||
2095 | int | |
fba45db2 | 2096 | rank_one_type (struct type *parm, struct type *arg) |
c906108c SS |
2097 | { |
2098 | /* Identical type pointers */ | |
2099 | /* However, this still doesn't catch all cases of same type for arg | |
2100 | * and param. The reason is that builtin types are different from | |
2101 | * the same ones constructed from the object. */ | |
2102 | if (parm == arg) | |
2103 | return 0; | |
2104 | ||
2105 | /* Resolve typedefs */ | |
2106 | if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) | |
2107 | parm = check_typedef (parm); | |
2108 | if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) | |
2109 | arg = check_typedef (arg); | |
2110 | ||
070ad9f0 DB |
2111 | /* |
2112 | Well, damnit, if the names are exactly the same, | |
2113 | i'll say they are exactly the same. This happens when we generate | |
2114 | method stubs. The types won't point to the same address, but they | |
2115 | really are the same. | |
2116 | */ | |
2117 | ||
6b1ba9a0 ND |
2118 | if (TYPE_NAME (parm) && TYPE_NAME (arg) && |
2119 | !strcmp (TYPE_NAME (parm), TYPE_NAME (arg))) | |
070ad9f0 DB |
2120 | return 0; |
2121 | ||
c906108c SS |
2122 | /* Check if identical after resolving typedefs */ |
2123 | if (parm == arg) | |
2124 | return 0; | |
2125 | ||
db577aea AC |
2126 | /* See through references, since we can almost make non-references |
2127 | references. */ | |
2128 | if (TYPE_CODE (arg) == TYPE_CODE_REF) | |
6b1ba9a0 | 2129 | return (rank_one_type (parm, TYPE_TARGET_TYPE (arg)) |
db577aea AC |
2130 | + REFERENCE_CONVERSION_BADNESS); |
2131 | if (TYPE_CODE (parm) == TYPE_CODE_REF) | |
6b1ba9a0 | 2132 | return (rank_one_type (TYPE_TARGET_TYPE (parm), arg) |
db577aea | 2133 | + REFERENCE_CONVERSION_BADNESS); |
5d161b24 | 2134 | if (overload_debug) |
db577aea | 2135 | /* Debugging only. */ |
5d161b24 DB |
2136 | fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n", |
2137 | TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm)); | |
c906108c SS |
2138 | |
2139 | /* x -> y means arg of type x being supplied for parameter of type y */ | |
2140 | ||
2141 | switch (TYPE_CODE (parm)) | |
2142 | { | |
c5aa993b JM |
2143 | case TYPE_CODE_PTR: |
2144 | switch (TYPE_CODE (arg)) | |
2145 | { | |
2146 | case TYPE_CODE_PTR: | |
2147 | if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) | |
2148 | return VOID_PTR_CONVERSION_BADNESS; | |
2149 | else | |
2150 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2151 | case TYPE_CODE_ARRAY: | |
2152 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2153 | case TYPE_CODE_FUNC: | |
2154 | return rank_one_type (TYPE_TARGET_TYPE (parm), arg); | |
2155 | case TYPE_CODE_INT: | |
2156 | case TYPE_CODE_ENUM: | |
2157 | case TYPE_CODE_CHAR: | |
2158 | case TYPE_CODE_RANGE: | |
2159 | case TYPE_CODE_BOOL: | |
2160 | return POINTER_CONVERSION_BADNESS; | |
2161 | default: | |
2162 | return INCOMPATIBLE_TYPE_BADNESS; | |
2163 | } | |
2164 | case TYPE_CODE_ARRAY: | |
2165 | switch (TYPE_CODE (arg)) | |
2166 | { | |
2167 | case TYPE_CODE_PTR: | |
2168 | case TYPE_CODE_ARRAY: | |
2169 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2170 | default: | |
2171 | return INCOMPATIBLE_TYPE_BADNESS; | |
2172 | } | |
2173 | case TYPE_CODE_FUNC: | |
2174 | switch (TYPE_CODE (arg)) | |
2175 | { | |
2176 | case TYPE_CODE_PTR: /* funcptr -> func */ | |
2177 | return rank_one_type (parm, TYPE_TARGET_TYPE (arg)); | |
2178 | default: | |
2179 | return INCOMPATIBLE_TYPE_BADNESS; | |
2180 | } | |
2181 | case TYPE_CODE_INT: | |
2182 | switch (TYPE_CODE (arg)) | |
2183 | { | |
2184 | case TYPE_CODE_INT: | |
2185 | if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2186 | { | |
2187 | /* Deal with signed, unsigned, and plain chars and | |
7b83ea04 | 2188 | signed and unsigned ints */ |
c5aa993b JM |
2189 | if (TYPE_NOSIGN (parm)) |
2190 | { | |
2191 | /* This case only for character types */ | |
2192 | if (TYPE_NOSIGN (arg)) /* plain char -> plain char */ | |
2193 | return 0; | |
2194 | else | |
2195 | return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */ | |
2196 | } | |
2197 | else if (TYPE_UNSIGNED (parm)) | |
2198 | { | |
2199 | if (TYPE_UNSIGNED (arg)) | |
2200 | { | |
db577aea | 2201 | if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg))) |
c5aa993b | 2202 | return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */ |
db577aea | 2203 | else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long")) |
c5aa993b JM |
2204 | return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */ |
2205 | else | |
2206 | return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */ | |
2207 | } | |
2208 | else | |
2209 | { | |
db577aea | 2210 | if (!strcmp_iw (TYPE_NAME (arg), "long") && !strcmp_iw (TYPE_NAME (parm), "int")) |
c5aa993b JM |
2211 | return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */ |
2212 | else | |
2213 | return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */ | |
2214 | } | |
2215 | } | |
2216 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2217 | { | |
db577aea | 2218 | if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg))) |
c5aa993b | 2219 | return 0; |
db577aea | 2220 | else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long")) |
c5aa993b JM |
2221 | return INTEGER_PROMOTION_BADNESS; |
2222 | else | |
2223 | return INTEGER_COERCION_BADNESS; | |
2224 | } | |
2225 | else | |
2226 | return INTEGER_COERCION_BADNESS; | |
2227 | } | |
2228 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2229 | return INTEGER_PROMOTION_BADNESS; | |
2230 | else | |
2231 | return INTEGER_COERCION_BADNESS; | |
2232 | case TYPE_CODE_ENUM: | |
2233 | case TYPE_CODE_CHAR: | |
2234 | case TYPE_CODE_RANGE: | |
2235 | case TYPE_CODE_BOOL: | |
2236 | return INTEGER_PROMOTION_BADNESS; | |
2237 | case TYPE_CODE_FLT: | |
2238 | return INT_FLOAT_CONVERSION_BADNESS; | |
2239 | case TYPE_CODE_PTR: | |
2240 | return NS_POINTER_CONVERSION_BADNESS; | |
2241 | default: | |
2242 | return INCOMPATIBLE_TYPE_BADNESS; | |
2243 | } | |
2244 | break; | |
2245 | case TYPE_CODE_ENUM: | |
2246 | switch (TYPE_CODE (arg)) | |
2247 | { | |
2248 | case TYPE_CODE_INT: | |
2249 | case TYPE_CODE_CHAR: | |
2250 | case TYPE_CODE_RANGE: | |
2251 | case TYPE_CODE_BOOL: | |
2252 | case TYPE_CODE_ENUM: | |
2253 | return INTEGER_COERCION_BADNESS; | |
2254 | case TYPE_CODE_FLT: | |
2255 | return INT_FLOAT_CONVERSION_BADNESS; | |
2256 | default: | |
2257 | return INCOMPATIBLE_TYPE_BADNESS; | |
2258 | } | |
2259 | break; | |
2260 | case TYPE_CODE_CHAR: | |
2261 | switch (TYPE_CODE (arg)) | |
2262 | { | |
2263 | case TYPE_CODE_RANGE: | |
2264 | case TYPE_CODE_BOOL: | |
2265 | case TYPE_CODE_ENUM: | |
2266 | return INTEGER_COERCION_BADNESS; | |
2267 | case TYPE_CODE_FLT: | |
2268 | return INT_FLOAT_CONVERSION_BADNESS; | |
2269 | case TYPE_CODE_INT: | |
2270 | if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm)) | |
2271 | return INTEGER_COERCION_BADNESS; | |
2272 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2273 | return INTEGER_PROMOTION_BADNESS; | |
2274 | /* >>> !! else fall through !! <<< */ | |
2275 | case TYPE_CODE_CHAR: | |
2276 | /* Deal with signed, unsigned, and plain chars for C++ | |
2277 | and with int cases falling through from previous case */ | |
2278 | if (TYPE_NOSIGN (parm)) | |
2279 | { | |
2280 | if (TYPE_NOSIGN (arg)) | |
2281 | return 0; | |
2282 | else | |
2283 | return INTEGER_COERCION_BADNESS; | |
2284 | } | |
2285 | else if (TYPE_UNSIGNED (parm)) | |
2286 | { | |
2287 | if (TYPE_UNSIGNED (arg)) | |
2288 | return 0; | |
2289 | else | |
2290 | return INTEGER_PROMOTION_BADNESS; | |
2291 | } | |
2292 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2293 | return 0; | |
2294 | else | |
2295 | return INTEGER_COERCION_BADNESS; | |
2296 | default: | |
2297 | return INCOMPATIBLE_TYPE_BADNESS; | |
2298 | } | |
2299 | break; | |
2300 | case TYPE_CODE_RANGE: | |
2301 | switch (TYPE_CODE (arg)) | |
2302 | { | |
2303 | case TYPE_CODE_INT: | |
2304 | case TYPE_CODE_CHAR: | |
2305 | case TYPE_CODE_RANGE: | |
2306 | case TYPE_CODE_BOOL: | |
2307 | case TYPE_CODE_ENUM: | |
2308 | return INTEGER_COERCION_BADNESS; | |
2309 | case TYPE_CODE_FLT: | |
2310 | return INT_FLOAT_CONVERSION_BADNESS; | |
2311 | default: | |
2312 | return INCOMPATIBLE_TYPE_BADNESS; | |
2313 | } | |
2314 | break; | |
2315 | case TYPE_CODE_BOOL: | |
2316 | switch (TYPE_CODE (arg)) | |
2317 | { | |
2318 | case TYPE_CODE_INT: | |
2319 | case TYPE_CODE_CHAR: | |
2320 | case TYPE_CODE_RANGE: | |
2321 | case TYPE_CODE_ENUM: | |
2322 | case TYPE_CODE_FLT: | |
2323 | case TYPE_CODE_PTR: | |
2324 | return BOOLEAN_CONVERSION_BADNESS; | |
2325 | case TYPE_CODE_BOOL: | |
2326 | return 0; | |
2327 | default: | |
2328 | return INCOMPATIBLE_TYPE_BADNESS; | |
2329 | } | |
2330 | break; | |
2331 | case TYPE_CODE_FLT: | |
2332 | switch (TYPE_CODE (arg)) | |
2333 | { | |
2334 | case TYPE_CODE_FLT: | |
2335 | if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2336 | return FLOAT_PROMOTION_BADNESS; | |
2337 | else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2338 | return 0; | |
2339 | else | |
2340 | return FLOAT_CONVERSION_BADNESS; | |
2341 | case TYPE_CODE_INT: | |
2342 | case TYPE_CODE_BOOL: | |
2343 | case TYPE_CODE_ENUM: | |
2344 | case TYPE_CODE_RANGE: | |
2345 | case TYPE_CODE_CHAR: | |
2346 | return INT_FLOAT_CONVERSION_BADNESS; | |
2347 | default: | |
2348 | return INCOMPATIBLE_TYPE_BADNESS; | |
2349 | } | |
2350 | break; | |
2351 | case TYPE_CODE_COMPLEX: | |
2352 | switch (TYPE_CODE (arg)) | |
2353 | { /* Strictly not needed for C++, but... */ | |
2354 | case TYPE_CODE_FLT: | |
2355 | return FLOAT_PROMOTION_BADNESS; | |
2356 | case TYPE_CODE_COMPLEX: | |
2357 | return 0; | |
2358 | default: | |
2359 | return INCOMPATIBLE_TYPE_BADNESS; | |
2360 | } | |
2361 | break; | |
2362 | case TYPE_CODE_STRUCT: | |
c906108c | 2363 | /* currently same as TYPE_CODE_CLASS */ |
c5aa993b JM |
2364 | switch (TYPE_CODE (arg)) |
2365 | { | |
2366 | case TYPE_CODE_STRUCT: | |
2367 | /* Check for derivation */ | |
2368 | if (is_ancestor (parm, arg)) | |
2369 | return BASE_CONVERSION_BADNESS; | |
2370 | /* else fall through */ | |
2371 | default: | |
2372 | return INCOMPATIBLE_TYPE_BADNESS; | |
2373 | } | |
2374 | break; | |
2375 | case TYPE_CODE_UNION: | |
2376 | switch (TYPE_CODE (arg)) | |
2377 | { | |
2378 | case TYPE_CODE_UNION: | |
2379 | default: | |
2380 | return INCOMPATIBLE_TYPE_BADNESS; | |
2381 | } | |
2382 | break; | |
2383 | case TYPE_CODE_MEMBER: | |
2384 | switch (TYPE_CODE (arg)) | |
2385 | { | |
2386 | default: | |
2387 | return INCOMPATIBLE_TYPE_BADNESS; | |
2388 | } | |
2389 | break; | |
2390 | case TYPE_CODE_METHOD: | |
2391 | switch (TYPE_CODE (arg)) | |
2392 | { | |
2393 | ||
2394 | default: | |
2395 | return INCOMPATIBLE_TYPE_BADNESS; | |
2396 | } | |
2397 | break; | |
2398 | case TYPE_CODE_REF: | |
2399 | switch (TYPE_CODE (arg)) | |
2400 | { | |
2401 | ||
2402 | default: | |
2403 | return INCOMPATIBLE_TYPE_BADNESS; | |
2404 | } | |
2405 | ||
2406 | break; | |
2407 | case TYPE_CODE_SET: | |
2408 | switch (TYPE_CODE (arg)) | |
2409 | { | |
2410 | /* Not in C++ */ | |
2411 | case TYPE_CODE_SET: | |
2412 | return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0)); | |
2413 | default: | |
2414 | return INCOMPATIBLE_TYPE_BADNESS; | |
2415 | } | |
2416 | break; | |
2417 | case TYPE_CODE_VOID: | |
2418 | default: | |
2419 | return INCOMPATIBLE_TYPE_BADNESS; | |
2420 | } /* switch (TYPE_CODE (arg)) */ | |
c906108c SS |
2421 | } |
2422 | ||
c5aa993b JM |
2423 | |
2424 | /* End of functions for overload resolution */ | |
c906108c | 2425 | |
c906108c | 2426 | static void |
fba45db2 | 2427 | print_bit_vector (B_TYPE *bits, int nbits) |
c906108c SS |
2428 | { |
2429 | int bitno; | |
2430 | ||
2431 | for (bitno = 0; bitno < nbits; bitno++) | |
2432 | { | |
2433 | if ((bitno % 8) == 0) | |
2434 | { | |
2435 | puts_filtered (" "); | |
2436 | } | |
2437 | if (B_TST (bits, bitno)) | |
2438 | { | |
2439 | printf_filtered ("1"); | |
2440 | } | |
2441 | else | |
2442 | { | |
2443 | printf_filtered ("0"); | |
2444 | } | |
2445 | } | |
2446 | } | |
2447 | ||
2448 | /* The args list is a strange beast. It is either terminated by a NULL | |
2449 | pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID | |
2450 | type for normal fixed argcount functions. (FIXME someday) | |
2451 | Also note the first arg should be the "this" pointer, we may not want to | |
2452 | include it since we may get into a infinitely recursive situation. */ | |
2453 | ||
2454 | static void | |
fba45db2 | 2455 | print_arg_types (struct type **args, int spaces) |
c906108c SS |
2456 | { |
2457 | if (args != NULL) | |
2458 | { | |
2459 | while (*args != NULL) | |
2460 | { | |
2461 | recursive_dump_type (*args, spaces + 2); | |
c5aa993b | 2462 | if ((*args++)->code == TYPE_CODE_VOID) |
c906108c SS |
2463 | { |
2464 | break; | |
2465 | } | |
2466 | } | |
2467 | } | |
2468 | } | |
2469 | ||
2470 | static void | |
fba45db2 | 2471 | dump_fn_fieldlists (struct type *type, int spaces) |
c906108c SS |
2472 | { |
2473 | int method_idx; | |
2474 | int overload_idx; | |
2475 | struct fn_field *f; | |
2476 | ||
2477 | printfi_filtered (spaces, "fn_fieldlists "); | |
d4f3574e | 2478 | gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); |
c906108c SS |
2479 | printf_filtered ("\n"); |
2480 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) | |
2481 | { | |
2482 | f = TYPE_FN_FIELDLIST1 (type, method_idx); | |
2483 | printfi_filtered (spaces + 2, "[%d] name '%s' (", | |
2484 | method_idx, | |
2485 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); | |
d4f3574e SS |
2486 | gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), |
2487 | gdb_stdout); | |
c906108c SS |
2488 | printf_filtered (") length %d\n", |
2489 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); | |
2490 | for (overload_idx = 0; | |
2491 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); | |
2492 | overload_idx++) | |
2493 | { | |
2494 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", | |
2495 | overload_idx, | |
2496 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); | |
d4f3574e SS |
2497 | gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
2498 | gdb_stdout); | |
c906108c SS |
2499 | printf_filtered (")\n"); |
2500 | printfi_filtered (spaces + 8, "type "); | |
d4f3574e | 2501 | gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout); |
c906108c SS |
2502 | printf_filtered ("\n"); |
2503 | ||
2504 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), | |
2505 | spaces + 8 + 2); | |
2506 | ||
2507 | printfi_filtered (spaces + 8, "args "); | |
d4f3574e | 2508 | gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout); |
c906108c SS |
2509 | printf_filtered ("\n"); |
2510 | ||
2511 | print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces); | |
2512 | printfi_filtered (spaces + 8, "fcontext "); | |
d4f3574e SS |
2513 | gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), |
2514 | gdb_stdout); | |
c906108c SS |
2515 | printf_filtered ("\n"); |
2516 | ||
2517 | printfi_filtered (spaces + 8, "is_const %d\n", | |
2518 | TYPE_FN_FIELD_CONST (f, overload_idx)); | |
2519 | printfi_filtered (spaces + 8, "is_volatile %d\n", | |
2520 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); | |
2521 | printfi_filtered (spaces + 8, "is_private %d\n", | |
2522 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); | |
2523 | printfi_filtered (spaces + 8, "is_protected %d\n", | |
2524 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); | |
2525 | printfi_filtered (spaces + 8, "is_stub %d\n", | |
2526 | TYPE_FN_FIELD_STUB (f, overload_idx)); | |
2527 | printfi_filtered (spaces + 8, "voffset %u\n", | |
2528 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); | |
2529 | } | |
2530 | } | |
2531 | } | |
2532 | ||
2533 | static void | |
fba45db2 | 2534 | print_cplus_stuff (struct type *type, int spaces) |
c906108c SS |
2535 | { |
2536 | printfi_filtered (spaces, "n_baseclasses %d\n", | |
2537 | TYPE_N_BASECLASSES (type)); | |
2538 | printfi_filtered (spaces, "nfn_fields %d\n", | |
2539 | TYPE_NFN_FIELDS (type)); | |
2540 | printfi_filtered (spaces, "nfn_fields_total %d\n", | |
2541 | TYPE_NFN_FIELDS_TOTAL (type)); | |
2542 | if (TYPE_N_BASECLASSES (type) > 0) | |
2543 | { | |
2544 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", | |
2545 | TYPE_N_BASECLASSES (type)); | |
d4f3574e | 2546 | gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout); |
c906108c SS |
2547 | printf_filtered (")"); |
2548 | ||
2549 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), | |
2550 | TYPE_N_BASECLASSES (type)); | |
2551 | puts_filtered ("\n"); | |
2552 | } | |
2553 | if (TYPE_NFIELDS (type) > 0) | |
2554 | { | |
2555 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) | |
2556 | { | |
2557 | printfi_filtered (spaces, "private_field_bits (%d bits at *", | |
2558 | TYPE_NFIELDS (type)); | |
d4f3574e | 2559 | gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout); |
c906108c SS |
2560 | printf_filtered (")"); |
2561 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), | |
2562 | TYPE_NFIELDS (type)); | |
2563 | puts_filtered ("\n"); | |
2564 | } | |
2565 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) | |
2566 | { | |
2567 | printfi_filtered (spaces, "protected_field_bits (%d bits at *", | |
2568 | TYPE_NFIELDS (type)); | |
d4f3574e | 2569 | gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout); |
c906108c SS |
2570 | printf_filtered (")"); |
2571 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), | |
2572 | TYPE_NFIELDS (type)); | |
2573 | puts_filtered ("\n"); | |
2574 | } | |
2575 | } | |
2576 | if (TYPE_NFN_FIELDS (type) > 0) | |
2577 | { | |
2578 | dump_fn_fieldlists (type, spaces); | |
2579 | } | |
2580 | } | |
2581 | ||
2582 | static struct obstack dont_print_type_obstack; | |
2583 | ||
2584 | void | |
fba45db2 | 2585 | recursive_dump_type (struct type *type, int spaces) |
c906108c SS |
2586 | { |
2587 | int idx; | |
2588 | ||
2589 | if (spaces == 0) | |
2590 | obstack_begin (&dont_print_type_obstack, 0); | |
2591 | ||
2592 | if (TYPE_NFIELDS (type) > 0 | |
2593 | || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0)) | |
2594 | { | |
2595 | struct type **first_dont_print | |
c5aa993b | 2596 | = (struct type **) obstack_base (&dont_print_type_obstack); |
c906108c | 2597 | |
c5aa993b JM |
2598 | int i = (struct type **) obstack_next_free (&dont_print_type_obstack) |
2599 | - first_dont_print; | |
c906108c SS |
2600 | |
2601 | while (--i >= 0) | |
2602 | { | |
2603 | if (type == first_dont_print[i]) | |
2604 | { | |
2605 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 2606 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
2607 | printf_filtered (" <same as already seen type>\n"); |
2608 | return; | |
2609 | } | |
2610 | } | |
2611 | ||
2612 | obstack_ptr_grow (&dont_print_type_obstack, type); | |
2613 | } | |
2614 | ||
2615 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 2616 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
2617 | printf_filtered ("\n"); |
2618 | printfi_filtered (spaces, "name '%s' (", | |
2619 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); | |
d4f3574e | 2620 | gdb_print_host_address (TYPE_NAME (type), gdb_stdout); |
c906108c SS |
2621 | printf_filtered (")\n"); |
2622 | if (TYPE_TAG_NAME (type) != NULL) | |
2623 | { | |
2624 | printfi_filtered (spaces, "tagname '%s' (", | |
2625 | TYPE_TAG_NAME (type)); | |
d4f3574e | 2626 | gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout); |
c906108c SS |
2627 | printf_filtered (")\n"); |
2628 | } | |
2629 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); | |
2630 | switch (TYPE_CODE (type)) | |
2631 | { | |
c5aa993b JM |
2632 | case TYPE_CODE_UNDEF: |
2633 | printf_filtered ("(TYPE_CODE_UNDEF)"); | |
2634 | break; | |
2635 | case TYPE_CODE_PTR: | |
2636 | printf_filtered ("(TYPE_CODE_PTR)"); | |
2637 | break; | |
2638 | case TYPE_CODE_ARRAY: | |
2639 | printf_filtered ("(TYPE_CODE_ARRAY)"); | |
2640 | break; | |
2641 | case TYPE_CODE_STRUCT: | |
2642 | printf_filtered ("(TYPE_CODE_STRUCT)"); | |
2643 | break; | |
2644 | case TYPE_CODE_UNION: | |
2645 | printf_filtered ("(TYPE_CODE_UNION)"); | |
2646 | break; | |
2647 | case TYPE_CODE_ENUM: | |
2648 | printf_filtered ("(TYPE_CODE_ENUM)"); | |
2649 | break; | |
2650 | case TYPE_CODE_FUNC: | |
2651 | printf_filtered ("(TYPE_CODE_FUNC)"); | |
2652 | break; | |
2653 | case TYPE_CODE_INT: | |
2654 | printf_filtered ("(TYPE_CODE_INT)"); | |
2655 | break; | |
2656 | case TYPE_CODE_FLT: | |
2657 | printf_filtered ("(TYPE_CODE_FLT)"); | |
2658 | break; | |
2659 | case TYPE_CODE_VOID: | |
2660 | printf_filtered ("(TYPE_CODE_VOID)"); | |
2661 | break; | |
2662 | case TYPE_CODE_SET: | |
2663 | printf_filtered ("(TYPE_CODE_SET)"); | |
2664 | break; | |
2665 | case TYPE_CODE_RANGE: | |
2666 | printf_filtered ("(TYPE_CODE_RANGE)"); | |
2667 | break; | |
2668 | case TYPE_CODE_STRING: | |
2669 | printf_filtered ("(TYPE_CODE_STRING)"); | |
2670 | break; | |
2671 | case TYPE_CODE_ERROR: | |
2672 | printf_filtered ("(TYPE_CODE_ERROR)"); | |
2673 | break; | |
2674 | case TYPE_CODE_MEMBER: | |
2675 | printf_filtered ("(TYPE_CODE_MEMBER)"); | |
2676 | break; | |
2677 | case TYPE_CODE_METHOD: | |
2678 | printf_filtered ("(TYPE_CODE_METHOD)"); | |
2679 | break; | |
2680 | case TYPE_CODE_REF: | |
2681 | printf_filtered ("(TYPE_CODE_REF)"); | |
2682 | break; | |
2683 | case TYPE_CODE_CHAR: | |
2684 | printf_filtered ("(TYPE_CODE_CHAR)"); | |
2685 | break; | |
2686 | case TYPE_CODE_BOOL: | |
2687 | printf_filtered ("(TYPE_CODE_BOOL)"); | |
2688 | break; | |
2689 | case TYPE_CODE_TYPEDEF: | |
2690 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); | |
2691 | break; | |
2692 | default: | |
2693 | printf_filtered ("(UNKNOWN TYPE CODE)"); | |
2694 | break; | |
c906108c SS |
2695 | } |
2696 | puts_filtered ("\n"); | |
2697 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); | |
2698 | printfi_filtered (spaces, "objfile "); | |
d4f3574e | 2699 | gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout); |
c906108c SS |
2700 | printf_filtered ("\n"); |
2701 | printfi_filtered (spaces, "target_type "); | |
d4f3574e | 2702 | gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout); |
c906108c SS |
2703 | printf_filtered ("\n"); |
2704 | if (TYPE_TARGET_TYPE (type) != NULL) | |
2705 | { | |
2706 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); | |
2707 | } | |
2708 | printfi_filtered (spaces, "pointer_type "); | |
d4f3574e | 2709 | gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout); |
c906108c SS |
2710 | printf_filtered ("\n"); |
2711 | printfi_filtered (spaces, "reference_type "); | |
d4f3574e | 2712 | gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); |
c906108c SS |
2713 | printf_filtered ("\n"); |
2714 | printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type)); | |
2715 | if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED) | |
2716 | { | |
2717 | puts_filtered (" TYPE_FLAG_UNSIGNED"); | |
2718 | } | |
2719 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
2720 | { | |
2721 | puts_filtered (" TYPE_FLAG_STUB"); | |
2722 | } | |
2723 | puts_filtered ("\n"); | |
2724 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); | |
d4f3574e | 2725 | gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout); |
c906108c SS |
2726 | puts_filtered ("\n"); |
2727 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) | |
2728 | { | |
2729 | printfi_filtered (spaces + 2, | |
2730 | "[%d] bitpos %d bitsize %d type ", | |
2731 | idx, TYPE_FIELD_BITPOS (type, idx), | |
2732 | TYPE_FIELD_BITSIZE (type, idx)); | |
d4f3574e | 2733 | gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); |
c906108c SS |
2734 | printf_filtered (" name '%s' (", |
2735 | TYPE_FIELD_NAME (type, idx) != NULL | |
2736 | ? TYPE_FIELD_NAME (type, idx) | |
2737 | : "<NULL>"); | |
d4f3574e | 2738 | gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
c906108c SS |
2739 | printf_filtered (")\n"); |
2740 | if (TYPE_FIELD_TYPE (type, idx) != NULL) | |
2741 | { | |
2742 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); | |
2743 | } | |
2744 | } | |
2745 | printfi_filtered (spaces, "vptr_basetype "); | |
d4f3574e | 2746 | gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); |
c906108c SS |
2747 | puts_filtered ("\n"); |
2748 | if (TYPE_VPTR_BASETYPE (type) != NULL) | |
2749 | { | |
2750 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); | |
2751 | } | |
2752 | printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type)); | |
2753 | switch (TYPE_CODE (type)) | |
2754 | { | |
c5aa993b JM |
2755 | case TYPE_CODE_METHOD: |
2756 | case TYPE_CODE_FUNC: | |
2757 | printfi_filtered (spaces, "arg_types "); | |
d4f3574e | 2758 | gdb_print_host_address (TYPE_ARG_TYPES (type), gdb_stdout); |
c5aa993b JM |
2759 | puts_filtered ("\n"); |
2760 | print_arg_types (TYPE_ARG_TYPES (type), spaces); | |
2761 | break; | |
c906108c | 2762 | |
c5aa993b JM |
2763 | case TYPE_CODE_STRUCT: |
2764 | printfi_filtered (spaces, "cplus_stuff "); | |
d4f3574e | 2765 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
c5aa993b JM |
2766 | puts_filtered ("\n"); |
2767 | print_cplus_stuff (type, spaces); | |
2768 | break; | |
c906108c | 2769 | |
c5aa993b JM |
2770 | default: |
2771 | /* We have to pick one of the union types to be able print and test | |
7b83ea04 AC |
2772 | the value. Pick cplus_struct_type, even though we know it isn't |
2773 | any particular one. */ | |
c5aa993b | 2774 | printfi_filtered (spaces, "type_specific "); |
d4f3574e | 2775 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
c5aa993b JM |
2776 | if (TYPE_CPLUS_SPECIFIC (type) != NULL) |
2777 | { | |
2778 | printf_filtered (" (unknown data form)"); | |
2779 | } | |
2780 | printf_filtered ("\n"); | |
2781 | break; | |
c906108c SS |
2782 | |
2783 | } | |
2784 | if (spaces == 0) | |
2785 | obstack_free (&dont_print_type_obstack, NULL); | |
2786 | } | |
2787 | ||
a14ed312 | 2788 | static void build_gdbtypes (void); |
c906108c | 2789 | static void |
fba45db2 | 2790 | build_gdbtypes (void) |
c906108c SS |
2791 | { |
2792 | builtin_type_void = | |
2793 | init_type (TYPE_CODE_VOID, 1, | |
2794 | 0, | |
2795 | "void", (struct objfile *) NULL); | |
2796 | builtin_type_char = | |
2797 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2798 | 0, | |
2799 | "char", (struct objfile *) NULL); | |
2800 | TYPE_FLAGS (builtin_type_char) |= TYPE_FLAG_NOSIGN; | |
c5aa993b | 2801 | builtin_type_true_char = |
9e0b60a8 JM |
2802 | init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
2803 | 0, | |
2804 | "true character", (struct objfile *) NULL); | |
c906108c SS |
2805 | builtin_type_signed_char = |
2806 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2807 | 0, | |
2808 | "signed char", (struct objfile *) NULL); | |
2809 | builtin_type_unsigned_char = | |
2810 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2811 | TYPE_FLAG_UNSIGNED, | |
2812 | "unsigned char", (struct objfile *) NULL); | |
2813 | builtin_type_short = | |
2814 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
2815 | 0, | |
2816 | "short", (struct objfile *) NULL); | |
2817 | builtin_type_unsigned_short = | |
2818 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
2819 | TYPE_FLAG_UNSIGNED, | |
2820 | "unsigned short", (struct objfile *) NULL); | |
2821 | builtin_type_int = | |
2822 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
2823 | 0, | |
2824 | "int", (struct objfile *) NULL); | |
2825 | builtin_type_unsigned_int = | |
2826 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
2827 | TYPE_FLAG_UNSIGNED, | |
2828 | "unsigned int", (struct objfile *) NULL); | |
2829 | builtin_type_long = | |
2830 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
2831 | 0, | |
2832 | "long", (struct objfile *) NULL); | |
2833 | builtin_type_unsigned_long = | |
2834 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
2835 | TYPE_FLAG_UNSIGNED, | |
2836 | "unsigned long", (struct objfile *) NULL); | |
2837 | builtin_type_long_long = | |
2838 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
2839 | 0, | |
2840 | "long long", (struct objfile *) NULL); | |
c5aa993b | 2841 | builtin_type_unsigned_long_long = |
c906108c SS |
2842 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
2843 | TYPE_FLAG_UNSIGNED, | |
2844 | "unsigned long long", (struct objfile *) NULL); | |
2845 | builtin_type_float = | |
2846 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
2847 | 0, | |
2848 | "float", (struct objfile *) NULL); | |
2849 | builtin_type_double = | |
2850 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
2851 | 0, | |
2852 | "double", (struct objfile *) NULL); | |
2853 | builtin_type_long_double = | |
2854 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
2855 | 0, | |
2856 | "long double", (struct objfile *) NULL); | |
2857 | builtin_type_complex = | |
2858 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
2859 | 0, | |
2860 | "complex", (struct objfile *) NULL); | |
2861 | TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float; | |
2862 | builtin_type_double_complex = | |
2863 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
2864 | 0, | |
2865 | "double complex", (struct objfile *) NULL); | |
2866 | TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double; | |
2867 | builtin_type_string = | |
2868 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2869 | 0, | |
2870 | "string", (struct objfile *) NULL); | |
2871 | builtin_type_int8 = | |
2872 | init_type (TYPE_CODE_INT, 8 / 8, | |
2873 | 0, | |
2874 | "int8_t", (struct objfile *) NULL); | |
2875 | builtin_type_uint8 = | |
2876 | init_type (TYPE_CODE_INT, 8 / 8, | |
2877 | TYPE_FLAG_UNSIGNED, | |
2878 | "uint8_t", (struct objfile *) NULL); | |
2879 | builtin_type_int16 = | |
2880 | init_type (TYPE_CODE_INT, 16 / 8, | |
2881 | 0, | |
2882 | "int16_t", (struct objfile *) NULL); | |
2883 | builtin_type_uint16 = | |
2884 | init_type (TYPE_CODE_INT, 16 / 8, | |
2885 | TYPE_FLAG_UNSIGNED, | |
2886 | "uint16_t", (struct objfile *) NULL); | |
2887 | builtin_type_int32 = | |
2888 | init_type (TYPE_CODE_INT, 32 / 8, | |
2889 | 0, | |
2890 | "int32_t", (struct objfile *) NULL); | |
2891 | builtin_type_uint32 = | |
2892 | init_type (TYPE_CODE_INT, 32 / 8, | |
2893 | TYPE_FLAG_UNSIGNED, | |
2894 | "uint32_t", (struct objfile *) NULL); | |
2895 | builtin_type_int64 = | |
2896 | init_type (TYPE_CODE_INT, 64 / 8, | |
2897 | 0, | |
2898 | "int64_t", (struct objfile *) NULL); | |
2899 | builtin_type_uint64 = | |
2900 | init_type (TYPE_CODE_INT, 64 / 8, | |
2901 | TYPE_FLAG_UNSIGNED, | |
2902 | "uint64_t", (struct objfile *) NULL); | |
2903 | builtin_type_bool = | |
2904 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
2905 | 0, | |
2906 | "bool", (struct objfile *) NULL); | |
2907 | ||
c5aa993b | 2908 | /* Add user knob for controlling resolution of opaque types */ |
c906108c | 2909 | add_show_from_set |
c5aa993b | 2910 | (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution, |
c906108c SS |
2911 | "Set resolution of opaque struct/class/union types (if set before loading symbols).", |
2912 | &setlist), | |
2913 | &showlist); | |
2914 | opaque_type_resolution = 1; | |
2915 | ||
917317f4 JM |
2916 | |
2917 | /* Build SIMD types. */ | |
2918 | builtin_type_v4sf | |
2919 | = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4); | |
c2d11a7d JM |
2920 | builtin_type_v4si |
2921 | = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4); | |
2922 | builtin_type_v8qi | |
2923 | = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8); | |
2924 | builtin_type_v4hi | |
2925 | = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4); | |
2926 | builtin_type_v2si | |
2927 | = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2); | |
c4093a6a JM |
2928 | |
2929 | /* Pointer/Address types. */ | |
2930 | /* NOTE: At present there is no way of differentiating between at | |
2931 | target address and the target C language pointer type type even | |
2932 | though the two can be different (cf d10v) */ | |
67b2adb2 | 2933 | builtin_type_ptr = make_pointer_type (builtin_type_void, NULL); |
c4093a6a | 2934 | builtin_type_CORE_ADDR = |
52204a0b | 2935 | init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8, |
c4093a6a JM |
2936 | TYPE_FLAG_UNSIGNED, |
2937 | "__CORE_ADDR", (struct objfile *) NULL); | |
2938 | builtin_type_bfd_vma = | |
2939 | init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8, | |
2940 | TYPE_FLAG_UNSIGNED, | |
2941 | "__bfd_vma", (struct objfile *) NULL); | |
c906108c SS |
2942 | } |
2943 | ||
2944 | ||
a14ed312 | 2945 | extern void _initialize_gdbtypes (void); |
c906108c | 2946 | void |
fba45db2 | 2947 | _initialize_gdbtypes (void) |
c906108c | 2948 | { |
5d161b24 | 2949 | struct cmd_list_element *c; |
c906108c | 2950 | build_gdbtypes (); |
0f71a2f6 JM |
2951 | |
2952 | /* FIXME - For the moment, handle types by swapping them in and out. | |
2953 | Should be using the per-architecture data-pointer and a large | |
2954 | struct. */ | |
c5aa993b JM |
2955 | register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL); |
2956 | register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL); | |
2957 | register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL); | |
2958 | register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL); | |
2959 | register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL); | |
2960 | register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL); | |
2961 | register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL); | |
2962 | register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL); | |
2963 | register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL); | |
2964 | register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL); | |
2965 | register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL); | |
2966 | register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL); | |
2967 | register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL); | |
2968 | register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL); | |
2969 | register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL); | |
2970 | register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL); | |
2971 | register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL); | |
2972 | register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL); | |
2973 | register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL); | |
2974 | register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL); | |
2975 | register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL); | |
2976 | register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL); | |
2977 | register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL); | |
2978 | register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL); | |
2979 | register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL); | |
2980 | register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL); | |
917317f4 | 2981 | register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL); |
c2d11a7d JM |
2982 | register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL); |
2983 | register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL); | |
2984 | register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL); | |
2985 | register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL); | |
c4093a6a JM |
2986 | REGISTER_GDBARCH_SWAP (builtin_type_ptr); |
2987 | REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR); | |
2988 | REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma); | |
0f71a2f6 | 2989 | register_gdbarch_swap (NULL, 0, build_gdbtypes); |
5d161b24 DB |
2990 | |
2991 | add_show_from_set ( | |
2992 | add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug, | |
2993 | "Set debugging of C++ overloading.\n\ | |
2994 | When enabled, ranking of the functions\n\ | |
2995 | is displayed.", &setdebuglist), | |
2996 | &showdebuglist); | |
c906108c | 2997 | } |