1 /* Support routines for manipulating internal types for GDB.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support, using pieces from other GDB modules.
6 This file is part of GDB.
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.
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.
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. */
24 #include "gdb_string.h"
30 #include "expression.h"
35 #include "complaints.h"
39 #include "gdb_assert.h"
41 /* These variables point to the objects
42 representing the predefined C data types. */
44 struct type *builtin_type_void;
45 struct type *builtin_type_char;
46 struct type *builtin_type_true_char;
47 struct type *builtin_type_short;
48 struct type *builtin_type_int;
49 struct type *builtin_type_long;
50 struct type *builtin_type_long_long;
51 struct type *builtin_type_signed_char;
52 struct type *builtin_type_unsigned_char;
53 struct type *builtin_type_unsigned_short;
54 struct type *builtin_type_unsigned_int;
55 struct type *builtin_type_unsigned_long;
56 struct type *builtin_type_unsigned_long_long;
57 struct type *builtin_type_float;
58 struct type *builtin_type_double;
59 struct type *builtin_type_long_double;
60 struct type *builtin_type_complex;
61 struct type *builtin_type_double_complex;
62 struct type *builtin_type_string;
63 struct type *builtin_type_int8;
64 struct type *builtin_type_uint8;
65 struct type *builtin_type_int16;
66 struct type *builtin_type_uint16;
67 struct type *builtin_type_int32;
68 struct type *builtin_type_uint32;
69 struct type *builtin_type_int64;
70 struct type *builtin_type_uint64;
71 struct type *builtin_type_int128;
72 struct type *builtin_type_uint128;
73 struct type *builtin_type_bool;
75 /* 128 bit long vector types */
76 struct type *builtin_type_v2_double;
77 struct type *builtin_type_v4_float;
78 struct type *builtin_type_v2_int64;
79 struct type *builtin_type_v4_int32;
80 struct type *builtin_type_v8_int16;
81 struct type *builtin_type_v16_int8;
82 /* 64 bit long vector types */
83 struct type *builtin_type_v2_float;
84 struct type *builtin_type_v2_int32;
85 struct type *builtin_type_v4_int16;
86 struct type *builtin_type_v8_int8;
88 struct type *builtin_type_v4sf;
89 struct type *builtin_type_v4si;
90 struct type *builtin_type_v16qi;
91 struct type *builtin_type_v8qi;
92 struct type *builtin_type_v8hi;
93 struct type *builtin_type_v4hi;
94 struct type *builtin_type_v2si;
95 struct type *builtin_type_vec64;
96 struct type *builtin_type_vec64i;
97 struct type *builtin_type_vec128;
98 struct type *builtin_type_vec128i;
99 struct type *builtin_type_ieee_single_big;
100 struct type *builtin_type_ieee_single_little;
101 struct type *builtin_type_ieee_double_big;
102 struct type *builtin_type_ieee_double_little;
103 struct type *builtin_type_ieee_double_littlebyte_bigword;
104 struct type *builtin_type_i387_ext;
105 struct type *builtin_type_m68881_ext;
106 struct type *builtin_type_i960_ext;
107 struct type *builtin_type_m88110_ext;
108 struct type *builtin_type_m88110_harris_ext;
109 struct type *builtin_type_arm_ext_big;
110 struct type *builtin_type_arm_ext_littlebyte_bigword;
111 struct type *builtin_type_ia64_spill_big;
112 struct type *builtin_type_ia64_spill_little;
113 struct type *builtin_type_ia64_quad_big;
114 struct type *builtin_type_ia64_quad_little;
115 struct type *builtin_type_void_data_ptr;
116 struct type *builtin_type_void_func_ptr;
117 struct type *builtin_type_CORE_ADDR;
118 struct type *builtin_type_bfd_vma;
120 int opaque_type_resolution = 1;
121 int overload_debug = 0;
127 }; /* maximum extension is 128! FIXME */
129 static void add_name (struct extra *, char *);
130 static void add_mangled_type (struct extra *, struct type *);
132 static void cfront_mangle_name (struct type *, int, int);
134 static void print_bit_vector (B_TYPE *, int);
135 static void print_arg_types (struct field *, int, int);
136 static void dump_fn_fieldlists (struct type *, int);
137 static void print_cplus_stuff (struct type *, int);
138 static void virtual_base_list_aux (struct type *dclass);
141 /* Alloc a new type structure and fill it with some defaults. If
142 OBJFILE is non-NULL, then allocate the space for the type structure
143 in that objfile's type_obstack. Otherwise allocate the new type structure
144 by xmalloc () (for permanent types). */
147 alloc_type (struct objfile *objfile)
149 register struct type *type;
151 /* Alloc the structure and start off with all fields zeroed. */
155 type = xmalloc (sizeof (struct type));
156 memset (type, 0, sizeof (struct type));
157 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
161 type = obstack_alloc (&objfile->type_obstack,
162 sizeof (struct type));
163 memset (type, 0, sizeof (struct type));
164 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->type_obstack,
165 sizeof (struct main_type));
166 OBJSTAT (objfile, n_types++);
168 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
170 /* Initialize the fields that might not be zero. */
172 TYPE_CODE (type) = TYPE_CODE_UNDEF;
173 TYPE_OBJFILE (type) = objfile;
174 TYPE_VPTR_FIELDNO (type) = -1;
175 TYPE_CHAIN (type) = type; /* Chain back to itself. */
180 /* Alloc a new type instance structure, fill it with some defaults,
181 and point it at OLDTYPE. Allocate the new type instance from the
182 same place as OLDTYPE. */
185 alloc_type_instance (struct type *oldtype)
189 /* Allocate the structure. */
191 if (TYPE_OBJFILE (oldtype) == NULL)
193 type = xmalloc (sizeof (struct type));
194 memset (type, 0, sizeof (struct type));
198 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->type_obstack,
199 sizeof (struct type));
200 memset (type, 0, sizeof (struct type));
202 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
204 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
209 /* Clear all remnants of the previous type at TYPE, in preparation for
210 replacing it with something else. */
212 smash_type (struct type *type)
214 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
216 /* For now, delete the rings. */
217 TYPE_CHAIN (type) = type;
219 /* For now, leave the pointer/reference types alone. */
222 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
223 to a pointer to memory where the pointer type should be stored.
224 If *TYPEPTR is zero, update it to point to the pointer type we return.
225 We allocate new memory if needed. */
228 make_pointer_type (struct type *type, struct type **typeptr)
230 register struct type *ntype; /* New type */
231 struct objfile *objfile;
233 ntype = TYPE_POINTER_TYPE (type);
238 return ntype; /* Don't care about alloc, and have new type. */
239 else if (*typeptr == 0)
241 *typeptr = ntype; /* Tracking alloc, and we have new type. */
246 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
248 ntype = alloc_type (TYPE_OBJFILE (type));
253 /* We have storage, but need to reset it. */
256 objfile = TYPE_OBJFILE (ntype);
258 TYPE_OBJFILE (ntype) = objfile;
261 TYPE_TARGET_TYPE (ntype) = type;
262 TYPE_POINTER_TYPE (type) = ntype;
264 /* FIXME! Assume the machine has only one representation for pointers! */
266 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
267 TYPE_CODE (ntype) = TYPE_CODE_PTR;
269 /* Mark pointers as unsigned. The target converts between pointers
270 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
271 ADDRESS_TO_POINTER(). */
272 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
274 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
275 TYPE_POINTER_TYPE (type) = ntype;
280 /* Given a type TYPE, return a type of pointers to that type.
281 May need to construct such a type if this is the first use. */
284 lookup_pointer_type (struct type *type)
286 return make_pointer_type (type, (struct type **) 0);
289 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
290 to a pointer to memory where the reference type should be stored.
291 If *TYPEPTR is zero, update it to point to the reference type we return.
292 We allocate new memory if needed. */
295 make_reference_type (struct type *type, struct type **typeptr)
297 register struct type *ntype; /* New type */
298 struct objfile *objfile;
300 ntype = TYPE_REFERENCE_TYPE (type);
305 return ntype; /* Don't care about alloc, and have new type. */
306 else if (*typeptr == 0)
308 *typeptr = ntype; /* Tracking alloc, and we have new type. */
313 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
315 ntype = alloc_type (TYPE_OBJFILE (type));
320 /* We have storage, but need to reset it. */
323 objfile = TYPE_OBJFILE (ntype);
325 TYPE_OBJFILE (ntype) = objfile;
328 TYPE_TARGET_TYPE (ntype) = type;
329 TYPE_REFERENCE_TYPE (type) = ntype;
331 /* FIXME! Assume the machine has only one representation for references,
332 and that it matches the (only) representation for pointers! */
334 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
335 TYPE_CODE (ntype) = TYPE_CODE_REF;
337 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
338 TYPE_REFERENCE_TYPE (type) = ntype;
343 /* Same as above, but caller doesn't care about memory allocation details. */
346 lookup_reference_type (struct type *type)
348 return make_reference_type (type, (struct type **) 0);
351 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
352 to a pointer to memory where the function type should be stored.
353 If *TYPEPTR is zero, update it to point to the function type we return.
354 We allocate new memory if needed. */
357 make_function_type (struct type *type, struct type **typeptr)
359 register struct type *ntype; /* New type */
360 struct objfile *objfile;
362 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
364 ntype = alloc_type (TYPE_OBJFILE (type));
369 /* We have storage, but need to reset it. */
372 objfile = TYPE_OBJFILE (ntype);
374 TYPE_OBJFILE (ntype) = objfile;
377 TYPE_TARGET_TYPE (ntype) = type;
379 TYPE_LENGTH (ntype) = 1;
380 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
386 /* Given a type TYPE, return a type of functions that return that type.
387 May need to construct such a type if this is the first use. */
390 lookup_function_type (struct type *type)
392 return make_function_type (type, (struct type **) 0);
395 /* Identify address space identifier by name --
396 return the integer flag defined in gdbtypes.h. */
398 address_space_name_to_int (char *space_identifier)
400 /* Check for known address space delimiters. */
401 if (!strcmp (space_identifier, "code"))
402 return TYPE_FLAG_CODE_SPACE;
403 else if (!strcmp (space_identifier, "data"))
404 return TYPE_FLAG_DATA_SPACE;
406 error ("Unknown address space specifier: \"%s\"", space_identifier);
409 /* Identify address space identifier by integer flag as defined in
410 gdbtypes.h -- return the string version of the adress space name. */
413 address_space_int_to_name (int space_flag)
415 if (space_flag & TYPE_FLAG_CODE_SPACE)
417 else if (space_flag & TYPE_FLAG_DATA_SPACE)
423 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
424 If STORAGE is non-NULL, create the new type instance there. */
427 make_qualified_type (struct type *type, int new_flags,
428 struct type *storage)
434 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
436 ntype = TYPE_CHAIN (ntype);
437 } while (ntype != type);
439 /* Create a new type instance. */
441 ntype = alloc_type_instance (type);
445 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
446 TYPE_CHAIN (ntype) = ntype;
449 /* Pointers or references to the original type are not relevant to
451 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
452 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
454 /* Chain the new qualified type to the old type. */
455 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
456 TYPE_CHAIN (type) = ntype;
458 /* Now set the instance flags and return the new type. */
459 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
464 /* Make an address-space-delimited variant of a type -- a type that
465 is identical to the one supplied except that it has an address
466 space attribute attached to it (such as "code" or "data").
468 This is for Harvard architectures. */
471 make_type_with_address_space (struct type *type, int space_flag)
474 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
475 & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE))
478 return make_qualified_type (type, new_flags, NULL);
481 /* Make a "c-v" variant of a type -- a type that is identical to the
482 one supplied except that it may have const or volatile attributes
483 CNST is a flag for setting the const attribute
484 VOLTL is a flag for setting the volatile attribute
485 TYPE is the base type whose variant we are creating.
486 TYPEPTR, if nonzero, points
487 to a pointer to memory where the reference type should be stored.
488 If *TYPEPTR is zero, update it to point to the reference type we return.
489 We allocate new memory if needed. */
492 make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
494 register struct type *ntype; /* New type */
495 register struct type *tmp_type = type; /* tmp type */
496 struct objfile *objfile;
498 int new_flags = (TYPE_INSTANCE_FLAGS (type)
499 & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
502 new_flags |= TYPE_FLAG_CONST;
505 new_flags |= TYPE_FLAG_VOLATILE;
507 if (typeptr && *typeptr != NULL)
509 /* Objfile is per-core-type. This const-qualified type had best
510 belong to the same objfile as the type it is qualifying, unless
511 we are overwriting a stub type, in which case the safest thing
512 to do is to copy the core type into the new objfile. */
514 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)
515 || TYPE_STUB (*typeptr));
516 if (TYPE_OBJFILE (*typeptr) != TYPE_OBJFILE (type))
518 TYPE_MAIN_TYPE (*typeptr)
519 = TYPE_ALLOC (*typeptr, sizeof (struct main_type));
520 *TYPE_MAIN_TYPE (*typeptr)
521 = *TYPE_MAIN_TYPE (type);
525 ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
533 /* Replace the contents of ntype with the type *type. This changes the
534 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
535 the changes are propogated to all types in the TYPE_CHAIN.
537 In order to build recursive types, it's inevitable that we'll need
538 to update types in place --- but this sort of indiscriminate
539 smashing is ugly, and needs to be replaced with something more
540 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
541 clear if more steps are needed. */
543 replace_type (struct type *ntype, struct type *type)
545 struct type *cv_chain, *as_chain, *ptr, *ref;
547 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
549 /* Assert that the two types have equivalent instance qualifiers.
550 This should be true for at least all of our debug readers. */
551 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
554 /* Implement direct support for MEMBER_TYPE in GNU C++.
555 May need to construct such a type if this is the first use.
556 The TYPE is the type of the member. The DOMAIN is the type
557 of the aggregate that the member belongs to. */
560 lookup_member_type (struct type *type, struct type *domain)
562 register struct type *mtype;
564 mtype = alloc_type (TYPE_OBJFILE (type));
565 smash_to_member_type (mtype, domain, type);
569 /* Allocate a stub method whose return type is TYPE.
570 This apparently happens for speed of symbol reading, since parsing
571 out the arguments to the method is cpu-intensive, the way we are doing
572 it. So, we will fill in arguments later.
573 This always returns a fresh type. */
576 allocate_stub_method (struct type *type)
580 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
581 TYPE_OBJFILE (type));
582 TYPE_TARGET_TYPE (mtype) = type;
583 /* _DOMAIN_TYPE (mtype) = unknown yet */
587 /* Create a range type using either a blank type supplied in RESULT_TYPE,
588 or creating a new type, inheriting the objfile from INDEX_TYPE.
590 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
591 HIGH_BOUND, inclusive.
593 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
594 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
597 create_range_type (struct type *result_type, struct type *index_type,
598 int low_bound, int high_bound)
600 if (result_type == NULL)
602 result_type = alloc_type (TYPE_OBJFILE (index_type));
604 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
605 TYPE_TARGET_TYPE (result_type) = index_type;
606 if (TYPE_STUB (index_type))
607 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
609 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
610 TYPE_NFIELDS (result_type) = 2;
611 TYPE_FIELDS (result_type) = (struct field *)
612 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
613 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
614 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
615 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
616 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
617 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
620 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
622 return (result_type);
625 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
626 Return 1 of type is a range type, 0 if it is discrete (and bounds
627 will fit in LONGEST), or -1 otherwise. */
630 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
632 CHECK_TYPEDEF (type);
633 switch (TYPE_CODE (type))
635 case TYPE_CODE_RANGE:
636 *lowp = TYPE_LOW_BOUND (type);
637 *highp = TYPE_HIGH_BOUND (type);
640 if (TYPE_NFIELDS (type) > 0)
642 /* The enums may not be sorted by value, so search all
646 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
647 for (i = 0; i < TYPE_NFIELDS (type); i++)
649 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
650 *lowp = TYPE_FIELD_BITPOS (type, i);
651 if (TYPE_FIELD_BITPOS (type, i) > *highp)
652 *highp = TYPE_FIELD_BITPOS (type, i);
655 /* Set unsigned indicator if warranted. */
658 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
672 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
674 if (!TYPE_UNSIGNED (type))
676 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
680 /* ... fall through for unsigned ints ... */
683 /* This round-about calculation is to avoid shifting by
684 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
685 if TYPE_LENGTH (type) == sizeof (LONGEST). */
686 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
687 *highp = (*highp - 1) | *highp;
694 /* Create an array type using either a blank type supplied in RESULT_TYPE,
695 or creating a new type, inheriting the objfile from RANGE_TYPE.
697 Elements will be of type ELEMENT_TYPE, the indices will be of type
700 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
701 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
704 create_array_type (struct type *result_type, struct type *element_type,
705 struct type *range_type)
707 LONGEST low_bound, high_bound;
709 if (result_type == NULL)
711 result_type = alloc_type (TYPE_OBJFILE (range_type));
713 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
714 TYPE_TARGET_TYPE (result_type) = element_type;
715 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
716 low_bound = high_bound = 0;
717 CHECK_TYPEDEF (element_type);
718 TYPE_LENGTH (result_type) =
719 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
720 TYPE_NFIELDS (result_type) = 1;
721 TYPE_FIELDS (result_type) =
722 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
723 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
724 TYPE_FIELD_TYPE (result_type, 0) = range_type;
725 TYPE_VPTR_FIELDNO (result_type) = -1;
727 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
728 if (TYPE_LENGTH (result_type) == 0)
729 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
731 return (result_type);
734 /* Create a string type using either a blank type supplied in RESULT_TYPE,
735 or creating a new type. String types are similar enough to array of
736 char types that we can use create_array_type to build the basic type
737 and then bash it into a string type.
739 For fixed length strings, the range type contains 0 as the lower
740 bound and the length of the string minus one as the upper bound.
742 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
743 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
746 create_string_type (struct type *result_type, struct type *range_type)
748 result_type = create_array_type (result_type,
749 *current_language->string_char_type,
751 TYPE_CODE (result_type) = TYPE_CODE_STRING;
752 return (result_type);
756 create_set_type (struct type *result_type, struct type *domain_type)
758 LONGEST low_bound, high_bound, bit_length;
759 if (result_type == NULL)
761 result_type = alloc_type (TYPE_OBJFILE (domain_type));
763 TYPE_CODE (result_type) = TYPE_CODE_SET;
764 TYPE_NFIELDS (result_type) = 1;
765 TYPE_FIELDS (result_type) = (struct field *)
766 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
767 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
769 if (!TYPE_STUB (domain_type))
771 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
772 low_bound = high_bound = 0;
773 bit_length = high_bound - low_bound + 1;
774 TYPE_LENGTH (result_type)
775 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
777 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
780 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
782 return (result_type);
785 /* Construct and return a type of the form:
786 struct NAME { ELT_TYPE ELT_NAME[N]; }
787 We use these types for SIMD registers. For example, the type of
788 the SSE registers on the late x86-family processors is:
789 struct __builtin_v4sf { float f[4]; }
790 built by the function call:
791 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
792 The type returned is a permanent type, allocated using malloc; it
793 doesn't live in any objfile's obstack. */
795 init_simd_type (char *name,
796 struct type *elt_type,
800 struct type *simd_type;
801 struct type *array_type;
803 simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
804 array_type = create_array_type (0, elt_type,
805 create_range_type (0, builtin_type_int,
807 append_composite_type_field (simd_type, elt_name, array_type);
812 init_vector_type (struct type *elt_type, int n)
814 struct type *array_type;
816 array_type = create_array_type (0, elt_type,
817 create_range_type (0, builtin_type_int,
819 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
824 build_builtin_type_vec64 (void)
826 /* Construct a type for the 64 bit registers. The type we're
829 union __gdb_builtin_type_vec64
841 t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION);
842 append_composite_type_field (t, "uint64", builtin_type_int64);
843 append_composite_type_field (t, "v2_float", builtin_type_v2_float);
844 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
845 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
846 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
848 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
853 build_builtin_type_vec64i (void)
855 /* Construct a type for the 64 bit registers. The type we're
858 union __gdb_builtin_type_vec64i
869 t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
870 append_composite_type_field (t, "uint64", builtin_type_int64);
871 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
872 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
873 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
875 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
880 build_builtin_type_vec128 (void)
882 /* Construct a type for the 128 bit registers. The type we're
885 union __gdb_builtin_type_vec128
897 t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
898 append_composite_type_field (t, "uint128", builtin_type_int128);
899 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
900 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
901 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
902 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
904 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
909 build_builtin_type_vec128i (void)
911 /* 128-bit Intel SIMD registers */
914 t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
915 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
916 append_composite_type_field (t, "v2_double", builtin_type_v2_double);
917 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
918 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
919 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
920 append_composite_type_field (t, "v2_int64", builtin_type_v2_int64);
921 append_composite_type_field (t, "uint128", builtin_type_int128);
923 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
927 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
928 A MEMBER is a wierd thing -- it amounts to a typed offset into
929 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
930 include the offset (that's the value of the MEMBER itself), but does
931 include the structure type into which it points (for some reason).
933 When "smashing" the type, we preserve the objfile that the
934 old type pointed to, since we aren't changing where the type is actually
938 smash_to_member_type (struct type *type, struct type *domain,
939 struct type *to_type)
941 struct objfile *objfile;
943 objfile = TYPE_OBJFILE (type);
946 TYPE_OBJFILE (type) = objfile;
947 TYPE_TARGET_TYPE (type) = to_type;
948 TYPE_DOMAIN_TYPE (type) = domain;
949 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
950 TYPE_CODE (type) = TYPE_CODE_MEMBER;
953 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
954 METHOD just means `function that gets an extra "this" argument'.
956 When "smashing" the type, we preserve the objfile that the
957 old type pointed to, since we aren't changing where the type is actually
961 smash_to_method_type (struct type *type, struct type *domain,
962 struct type *to_type, struct field *args,
963 int nargs, int varargs)
965 struct objfile *objfile;
967 objfile = TYPE_OBJFILE (type);
970 TYPE_OBJFILE (type) = objfile;
971 TYPE_TARGET_TYPE (type) = to_type;
972 TYPE_DOMAIN_TYPE (type) = domain;
973 TYPE_FIELDS (type) = args;
974 TYPE_NFIELDS (type) = nargs;
976 TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
977 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
978 TYPE_CODE (type) = TYPE_CODE_METHOD;
981 /* Return a typename for a struct/union/enum type without "struct ",
982 "union ", or "enum ". If the type has a NULL name, return NULL. */
985 type_name_no_tag (register const struct type *type)
987 if (TYPE_TAG_NAME (type) != NULL)
988 return TYPE_TAG_NAME (type);
990 /* Is there code which expects this to return the name if there is no
991 tag name? My guess is that this is mainly used for C++ in cases where
992 the two will always be the same. */
993 return TYPE_NAME (type);
996 /* Lookup a primitive type named NAME.
997 Return zero if NAME is not a primitive type. */
1000 lookup_primitive_typename (char *name)
1002 struct type **const *p;
1004 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
1006 if (STREQ (TYPE_NAME (**p), name))
1014 /* Lookup a typedef or primitive type named NAME,
1015 visible in lexical block BLOCK.
1016 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1019 lookup_typename (char *name, struct block *block, int noerr)
1021 register struct symbol *sym;
1022 register struct type *tmp;
1024 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
1025 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1027 tmp = lookup_primitive_typename (name);
1032 else if (!tmp && noerr)
1038 error ("No type named %s.", name);
1041 return (SYMBOL_TYPE (sym));
1045 lookup_unsigned_typename (char *name)
1047 char *uns = alloca (strlen (name) + 10);
1049 strcpy (uns, "unsigned ");
1050 strcpy (uns + 9, name);
1051 return (lookup_typename (uns, (struct block *) NULL, 0));
1055 lookup_signed_typename (char *name)
1058 char *uns = alloca (strlen (name) + 8);
1060 strcpy (uns, "signed ");
1061 strcpy (uns + 7, name);
1062 t = lookup_typename (uns, (struct block *) NULL, 1);
1063 /* If we don't find "signed FOO" just try again with plain "FOO". */
1066 return lookup_typename (name, (struct block *) NULL, 0);
1069 /* Lookup a structure type named "struct NAME",
1070 visible in lexical block BLOCK. */
1073 lookup_struct (char *name, struct block *block)
1075 register struct symbol *sym;
1077 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
1078 (struct symtab **) NULL);
1082 error ("No struct type named %s.", name);
1084 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1086 error ("This context has class, union or enum %s, not a struct.", name);
1088 return (SYMBOL_TYPE (sym));
1091 /* Lookup a union type named "union NAME",
1092 visible in lexical block BLOCK. */
1095 lookup_union (char *name, struct block *block)
1097 register struct symbol *sym;
1100 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
1101 (struct symtab **) NULL);
1104 error ("No union type named %s.", name);
1106 t = SYMBOL_TYPE (sym);
1108 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1111 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1112 * a further "declared_type" field to discover it is really a union.
1114 if (HAVE_CPLUS_STRUCT (t))
1115 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1118 /* If we get here, it's not a union */
1119 error ("This context has class, struct or enum %s, not a union.", name);
1123 /* Lookup an enum type named "enum NAME",
1124 visible in lexical block BLOCK. */
1127 lookup_enum (char *name, struct block *block)
1129 register struct symbol *sym;
1131 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
1132 (struct symtab **) NULL);
1135 error ("No enum type named %s.", name);
1137 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1139 error ("This context has class, struct or union %s, not an enum.", name);
1141 return (SYMBOL_TYPE (sym));
1144 /* Lookup a template type named "template NAME<TYPE>",
1145 visible in lexical block BLOCK. */
1148 lookup_template_type (char *name, struct type *type, struct block *block)
1151 char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1154 strcat (nam, TYPE_NAME (type));
1155 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1157 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
1161 error ("No template type named %s.", name);
1163 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1165 error ("This context has class, union or enum %s, not a struct.", name);
1167 return (SYMBOL_TYPE (sym));
1170 /* Given a type TYPE, lookup the type of the component of type named NAME.
1172 TYPE can be either a struct or union, or a pointer or reference to a struct or
1173 union. If it is a pointer or reference, its target type is automatically used.
1174 Thus '.' and '->' are interchangable, as specified for the definitions of the
1175 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1177 If NOERR is nonzero, return zero if NAME is not suitably defined.
1178 If NAME is the name of a baseclass type, return that type. */
1181 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1187 CHECK_TYPEDEF (type);
1188 if (TYPE_CODE (type) != TYPE_CODE_PTR
1189 && TYPE_CODE (type) != TYPE_CODE_REF)
1191 type = TYPE_TARGET_TYPE (type);
1194 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1195 TYPE_CODE (type) != TYPE_CODE_UNION)
1197 target_terminal_ours ();
1198 gdb_flush (gdb_stdout);
1199 fprintf_unfiltered (gdb_stderr, "Type ");
1200 type_print (type, "", gdb_stderr, -1);
1201 error (" is not a structure or union type.");
1205 /* FIXME: This change put in by Michael seems incorrect for the case where
1206 the structure tag name is the same as the member name. I.E. when doing
1207 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1212 typename = type_name_no_tag (type);
1213 if (typename != NULL && STREQ (typename, name))
1218 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1220 char *t_field_name = TYPE_FIELD_NAME (type, i);
1222 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1224 return TYPE_FIELD_TYPE (type, i);
1228 /* OK, it's not in this class. Recursively check the baseclasses. */
1229 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1233 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1245 target_terminal_ours ();
1246 gdb_flush (gdb_stdout);
1247 fprintf_unfiltered (gdb_stderr, "Type ");
1248 type_print (type, "", gdb_stderr, -1);
1249 fprintf_unfiltered (gdb_stderr, " has no component named ");
1250 fputs_filtered (name, gdb_stderr);
1252 return (struct type *) -1; /* For lint */
1255 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1256 valid. Callers should be aware that in some cases (for example,
1257 the type or one of its baseclasses is a stub type and we are
1258 debugging a .o file), this function will not be able to find the virtual
1259 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1260 will remain NULL. */
1263 fill_in_vptr_fieldno (struct type *type)
1265 CHECK_TYPEDEF (type);
1267 if (TYPE_VPTR_FIELDNO (type) < 0)
1271 /* We must start at zero in case the first (and only) baseclass is
1272 virtual (and hence we cannot share the table pointer). */
1273 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1275 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
1276 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
1278 TYPE_VPTR_FIELDNO (type)
1279 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
1280 TYPE_VPTR_BASETYPE (type)
1281 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
1288 /* Find the method and field indices for the destructor in class type T.
1289 Return 1 if the destructor was found, otherwise, return 0. */
1292 get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
1296 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1299 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1301 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1303 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1314 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1316 If this is a stubbed struct (i.e. declared as struct foo *), see if
1317 we can find a full definition in some other file. If so, copy this
1318 definition, so we can use it in future. There used to be a comment (but
1319 not any code) that if we don't find a full definition, we'd set a flag
1320 so we don't spend time in the future checking the same type. That would
1321 be a mistake, though--we might load in more symbols which contain a
1322 full definition for the type.
1324 This used to be coded as a macro, but I don't think it is called
1325 often enough to merit such treatment. */
1327 struct complaint stub_noname_complaint =
1328 {"stub type has NULL name", 0, 0};
1331 check_typedef (struct type *type)
1333 struct type *orig_type = type;
1334 int is_const, is_volatile;
1336 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1338 if (!TYPE_TARGET_TYPE (type))
1343 /* It is dangerous to call lookup_symbol if we are currently
1344 reading a symtab. Infinite recursion is one danger. */
1345 if (currently_reading_symtab)
1348 name = type_name_no_tag (type);
1349 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1350 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1351 as appropriate? (this code was written before TYPE_NAME and
1352 TYPE_TAG_NAME were separate). */
1355 complain (&stub_noname_complaint);
1358 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
1359 (struct symtab **) NULL);
1361 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1363 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1365 type = TYPE_TARGET_TYPE (type);
1368 is_const = TYPE_CONST (type);
1369 is_volatile = TYPE_VOLATILE (type);
1371 /* If this is a struct/class/union with no fields, then check whether a
1372 full definition exists somewhere else. This is for systems where a
1373 type definition with no fields is issued for such types, instead of
1374 identifying them as stub types in the first place */
1376 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1378 char *name = type_name_no_tag (type);
1379 struct type *newtype;
1382 complain (&stub_noname_complaint);
1385 newtype = lookup_transparent_type (name);
1387 make_cv_type (is_const, is_volatile, newtype, &type);
1389 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1390 else if (TYPE_STUB (type) && !currently_reading_symtab)
1392 char *name = type_name_no_tag (type);
1393 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1394 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1395 as appropriate? (this code was written before TYPE_NAME and
1396 TYPE_TAG_NAME were separate). */
1400 complain (&stub_noname_complaint);
1403 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL);
1405 make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type);
1408 if (TYPE_TARGET_STUB (type))
1410 struct type *range_type;
1411 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1413 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1416 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1417 && TYPE_NFIELDS (type) == 1
1418 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1419 == TYPE_CODE_RANGE))
1421 /* Now recompute the length of the array type, based on its
1422 number of elements and the target type's length. */
1423 TYPE_LENGTH (type) =
1424 ((TYPE_FIELD_BITPOS (range_type, 1)
1425 - TYPE_FIELD_BITPOS (range_type, 0)
1427 * TYPE_LENGTH (target_type));
1428 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1430 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1432 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1433 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1436 /* Cache TYPE_LENGTH for future use. */
1437 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1441 /* New code added to support parsing of Cfront stabs strings */
1442 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1443 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1446 add_name (struct extra *pextras, char *n)
1450 if ((nlen = (n ? strlen (n) : 0)) == 0)
1452 sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1453 pextras->len = strlen (pextras->str);
1457 add_mangled_type (struct extra *pextras, struct type *t)
1459 enum type_code tcode;
1463 tcode = TYPE_CODE (t);
1464 tlen = TYPE_LENGTH (t);
1465 tflags = TYPE_FLAGS (t);
1466 tname = TYPE_NAME (t);
1467 /* args of "..." seem to get mangled as "e" */
1485 if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1498 static struct complaint msg =
1499 {"Bad int type code length x%x\n", 0, 0};
1501 complain (&msg, tlen);
1520 static struct complaint msg =
1521 {"Bad float type code length x%x\n", 0, 0};
1522 complain (&msg, tlen);
1528 /* followed by what it's a ref to */
1532 /* followed by what it's a ptr to */
1534 case TYPE_CODE_TYPEDEF:
1536 static struct complaint msg =
1537 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1540 /* followed by type bytes & name */
1542 case TYPE_CODE_FUNC:
1544 /* followed by func's arg '_' & ret types */
1546 case TYPE_CODE_VOID:
1549 case TYPE_CODE_METHOD:
1551 /* followed by name of class and func's arg '_' & ret types */
1552 add_name (pextras, tname);
1553 ADD_EXTRA ('F'); /* then mangle function */
1555 case TYPE_CODE_STRUCT: /* C struct */
1556 case TYPE_CODE_UNION: /* C union */
1557 case TYPE_CODE_ENUM: /* Enumeration type */
1558 /* followed by name of type */
1559 add_name (pextras, tname);
1562 /* errors possible types/not supported */
1563 case TYPE_CODE_CHAR:
1564 case TYPE_CODE_ARRAY: /* Array type */
1565 case TYPE_CODE_MEMBER: /* Member type */
1566 case TYPE_CODE_BOOL:
1567 case TYPE_CODE_COMPLEX: /* Complex float */
1568 case TYPE_CODE_UNDEF:
1569 case TYPE_CODE_SET: /* Pascal sets */
1570 case TYPE_CODE_RANGE:
1571 case TYPE_CODE_STRING:
1572 case TYPE_CODE_BITSTRING:
1573 case TYPE_CODE_ERROR:
1576 static struct complaint msg =
1577 {"Unknown type code x%x\n", 0, 0};
1578 complain (&msg, tcode);
1581 if (TYPE_TARGET_TYPE (t))
1582 add_mangled_type (pextras, TYPE_TARGET_TYPE (t));
1587 cfront_mangle_name (struct type *type, int i, int j)
1590 char *mangled_name = gdb_mangle_name (type, i, j);
1592 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1594 /* kludge to support cfront methods - gdb expects to find "F" for
1595 ARM_mangled names, so when we mangle, we have to add it here */
1599 char *arm_mangled_name;
1600 struct fn_field *method = &f[j];
1601 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1602 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1603 char *newname = type_name_no_tag (type);
1605 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1606 int nargs = TYPE_NFIELDS (ftype); /* number of args */
1607 struct extra extras, *pextras = &extras;
1610 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1613 /* add args here! */
1614 if (nargs <= 1) /* no args besides this */
1618 for (k = 1; k < nargs; k++)
1621 t = TYPE_FIELD_TYPE (ftype, k);
1622 add_mangled_type (pextras, t);
1626 printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1627 xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str);
1628 xfree (mangled_name);
1629 mangled_name = arm_mangled_name;
1635 /* End of new code added to support parsing of Cfront stabs strings */
1637 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1638 silently return builtin_type_void. */
1641 safe_parse_type (char *p, int length)
1643 struct ui_file *saved_gdb_stderr;
1646 /* Suppress error messages. */
1647 saved_gdb_stderr = gdb_stderr;
1648 gdb_stderr = ui_file_new ();
1650 /* Call parse_and_eval_type() without fear of longjmp()s. */
1651 if (!gdb_parse_and_eval_type (p, length, &type))
1652 type = builtin_type_void;
1654 /* Stop suppressing error messages. */
1655 ui_file_delete (gdb_stderr);
1656 gdb_stderr = saved_gdb_stderr;
1661 /* Ugly hack to convert method stubs into method types.
1663 He ain't kiddin'. This demangles the name of the method into a string
1664 including argument types, parses out each argument type, generates
1665 a string casting a zero to that type, evaluates the string, and stuffs
1666 the resulting type into an argtype vector!!! Then it knows the type
1667 of the whole function (including argument types for overloading),
1668 which info used to be in the stab's but was removed to hack back
1669 the space required for them. */
1672 check_stub_method (struct type *type, int method_id, int signature_id)
1675 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1676 char *demangled_name = cplus_demangle (mangled_name,
1677 DMGL_PARAMS | DMGL_ANSI);
1678 char *argtypetext, *p;
1679 int depth = 0, argcount = 1;
1680 struct field *argtypes;
1683 /* Make sure we got back a function string that we can use. */
1685 p = strchr (demangled_name, '(');
1689 if (demangled_name == NULL || p == NULL)
1690 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1692 /* Now, read in the parameters that define this type. */
1697 if (*p == '(' || *p == '<')
1701 else if (*p == ')' || *p == '>')
1705 else if (*p == ',' && depth == 0)
1713 /* If we read one argument and it was ``void'', don't count it. */
1714 if (strncmp (argtypetext, "(void)", 6) == 0)
1717 /* We need one extra slot, for the THIS pointer. */
1719 argtypes = (struct field *)
1720 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1723 /* Add THIS pointer for non-static methods. */
1724 f = TYPE_FN_FIELDLIST1 (type, method_id);
1725 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1729 argtypes[0].type = lookup_pointer_type (type);
1733 if (*p != ')') /* () means no args, skip while */
1738 if (depth <= 0 && (*p == ',' || *p == ')'))
1740 /* Avoid parsing of ellipsis, they will be handled below.
1741 Also avoid ``void'' as above. */
1742 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1743 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1745 argtypes[argcount].type =
1746 safe_parse_type (argtypetext, p - argtypetext);
1749 argtypetext = p + 1;
1752 if (*p == '(' || *p == '<')
1756 else if (*p == ')' || *p == '>')
1765 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1767 /* Now update the old "stub" type into a real type. */
1768 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1769 TYPE_DOMAIN_TYPE (mtype) = type;
1770 TYPE_FIELDS (mtype) = argtypes;
1771 TYPE_NFIELDS (mtype) = argcount;
1772 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1773 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1775 TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1777 xfree (demangled_name);
1780 const struct cplus_struct_type cplus_struct_default;
1783 allocate_cplus_struct_type (struct type *type)
1785 if (!HAVE_CPLUS_STRUCT (type))
1787 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1788 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1789 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1793 /* Helper function to initialize the standard scalar types.
1795 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1796 of the string pointed to by name in the type_obstack for that objfile,
1797 and initialize the type name to that copy. There are places (mipsread.c
1798 in particular, where init_type is called with a NULL value for NAME). */
1801 init_type (enum type_code code, int length, int flags, char *name,
1802 struct objfile *objfile)
1804 register struct type *type;
1806 type = alloc_type (objfile);
1807 TYPE_CODE (type) = code;
1808 TYPE_LENGTH (type) = length;
1809 TYPE_FLAGS (type) |= flags;
1810 if ((name != NULL) && (objfile != NULL))
1813 obsavestring (name, strlen (name), &objfile->type_obstack);
1817 TYPE_NAME (type) = name;
1822 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1824 INIT_CPLUS_SPECIFIC (type);
1829 /* Helper function. Create an empty composite type. */
1832 init_composite_type (char *name, enum type_code code)
1835 gdb_assert (code == TYPE_CODE_STRUCT
1836 || code == TYPE_CODE_UNION);
1837 t = init_type (code, 0, 0, NULL, NULL);
1838 TYPE_TAG_NAME (t) = name;
1842 /* Helper function. Append a field to a composite type. */
1845 append_composite_type_field (struct type *t, char *name, struct type *field)
1848 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1849 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1850 sizeof (struct field) * TYPE_NFIELDS (t));
1851 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1852 memset (f, 0, sizeof f[0]);
1853 FIELD_TYPE (f[0]) = field;
1854 FIELD_NAME (f[0]) = name;
1855 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1857 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1858 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1860 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1862 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1863 if (TYPE_NFIELDS (t) > 1)
1865 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1866 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1871 /* Look up a fundamental type for the specified objfile.
1872 May need to construct such a type if this is the first use.
1874 Some object file formats (ELF, COFF, etc) do not define fundamental
1875 types such as "int" or "double". Others (stabs for example), do
1876 define fundamental types.
1878 For the formats which don't provide fundamental types, gdb can create
1879 such types, using defaults reasonable for the current language and
1880 the current target machine.
1882 NOTE: This routine is obsolescent. Each debugging format reader
1883 should manage it's own fundamental types, either creating them from
1884 suitable defaults or reading them from the debugging information,
1885 whichever is appropriate. The DWARF reader has already been
1886 fixed to do this. Once the other readers are fixed, this routine
1887 will go away. Also note that fundamental types should be managed
1888 on a compilation unit basis in a multi-language environment, not
1889 on a linkage unit basis as is done here. */
1893 lookup_fundamental_type (struct objfile *objfile, int typeid)
1895 register struct type **typep;
1896 register int nbytes;
1898 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1900 error ("internal error - invalid fundamental type id %d", typeid);
1903 /* If this is the first time we need a fundamental type for this objfile
1904 then we need to initialize the vector of type pointers. */
1906 if (objfile->fundamental_types == NULL)
1908 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1909 objfile->fundamental_types = (struct type **)
1910 obstack_alloc (&objfile->type_obstack, nbytes);
1911 memset ((char *) objfile->fundamental_types, 0, nbytes);
1912 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1915 /* Look for this particular type in the fundamental type vector. If one is
1916 not found, create and install one appropriate for the current language. */
1918 typep = objfile->fundamental_types + typeid;
1921 *typep = create_fundamental_type (objfile, typeid);
1928 can_dereference (struct type *t)
1930 /* FIXME: Should we return true for references as well as pointers? */
1934 && TYPE_CODE (t) == TYPE_CODE_PTR
1935 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1939 is_integral_type (struct type *t)
1944 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1945 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1946 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1947 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1948 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1951 /* (OBSOLETE) Chill (OBSOLETE) varying string and arrays are
1952 represented as follows:
1954 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1956 Return true if TYPE is such a (OBSOLETE) Chill (OBSOLETE) varying
1960 /* OBSOLETE chill_varying_type (struct type *type) */
1962 /* OBSOLETE if (TYPE_CODE (type) != TYPE_CODE_STRUCT */
1963 /* OBSOLETE || TYPE_NFIELDS (type) != 2 */
1964 /* OBSOLETE || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0) */
1965 /* OBSOLETE return 0; */
1966 /* OBSOLETE return 1; */
1969 /* Check whether BASE is an ancestor or base class or DCLASS
1970 Return 1 if so, and 0 if not.
1971 Note: callers may want to check for identity of the types before
1972 calling this function -- identical types are considered to satisfy
1973 the ancestor relationship even if they're identical */
1976 is_ancestor (struct type *base, struct type *dclass)
1980 CHECK_TYPEDEF (base);
1981 CHECK_TYPEDEF (dclass);
1985 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
1986 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1989 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1990 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1998 /* See whether DCLASS has a virtual table. This routine is aimed at
1999 the HP/Taligent ANSI C++ runtime model, and may not work with other
2000 runtime models. Return 1 => Yes, 0 => No. */
2003 has_vtable (struct type *dclass)
2005 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
2006 has virtual functions or virtual bases. */
2010 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
2013 /* First check for the presence of virtual bases */
2014 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
2015 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2016 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
2019 /* Next check for virtual functions */
2020 if (TYPE_FN_FIELDLISTS (dclass))
2021 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
2022 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
2025 /* Recurse on non-virtual bases to see if any of them needs a vtable */
2026 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
2027 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2028 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
2029 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
2032 /* Well, maybe we don't need a virtual table */
2036 /* Return a pointer to the "primary base class" of DCLASS.
2038 A NULL return indicates that DCLASS has no primary base, or that it
2039 couldn't be found (insufficient information).
2041 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2042 and may not work with other runtime models. */
2045 primary_base_class (struct type *dclass)
2047 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
2048 is the first directly inherited, non-virtual base class that
2049 requires a virtual table */
2053 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
2056 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2057 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
2058 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
2059 return TYPE_FIELD_TYPE (dclass, i);
2064 /* Global manipulated by virtual_base_list[_aux]() */
2066 static struct vbase *current_vbase_list = NULL;
2068 /* Return a pointer to a null-terminated list of struct vbase
2069 items. The vbasetype pointer of each item in the list points to the
2070 type information for a virtual base of the argument DCLASS.
2072 Helper function for virtual_base_list().
2073 Note: the list goes backward, right-to-left. virtual_base_list()
2074 copies the items out in reverse order. */
2077 virtual_base_list_aux (struct type *dclass)
2079 struct vbase *tmp_vbase;
2082 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
2085 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2087 /* Recurse on this ancestor, first */
2088 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
2090 /* If this current base is itself virtual, add it to the list */
2091 if (BASETYPE_VIA_VIRTUAL (dclass, i))
2093 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
2095 /* Check if base already recorded */
2096 tmp_vbase = current_vbase_list;
2099 if (tmp_vbase->vbasetype == basetype)
2100 break; /* found it */
2101 tmp_vbase = tmp_vbase->next;
2104 if (!tmp_vbase) /* normal exit from loop */
2106 /* Allocate new item for this virtual base */
2107 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
2109 /* Stick it on at the end of the list */
2110 tmp_vbase->vbasetype = basetype;
2111 tmp_vbase->next = current_vbase_list;
2112 current_vbase_list = tmp_vbase;
2115 } /* for loop over bases */
2119 /* Compute the list of virtual bases in the right order. Virtual
2120 bases are laid out in the object's memory area in order of their
2121 occurrence in a depth-first, left-to-right search through the
2124 Argument DCLASS is the type whose virtual bases are required.
2125 Return value is the address of a null-terminated array of pointers
2126 to struct type items.
2128 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2129 and may not work with other runtime models.
2131 This routine merely hands off the argument to virtual_base_list_aux()
2132 and then copies the result into an array to save space. */
2135 virtual_base_list (struct type *dclass)
2137 register struct vbase *tmp_vbase;
2138 register struct vbase *tmp_vbase_2;
2141 struct type **vbase_array;
2143 current_vbase_list = NULL;
2144 virtual_base_list_aux (dclass);
2146 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2151 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
2153 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
2154 vbase_array[i] = tmp_vbase->vbasetype;
2156 /* Get rid of constructed chain */
2157 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2160 tmp_vbase = tmp_vbase->next;
2161 xfree (tmp_vbase_2);
2162 tmp_vbase_2 = tmp_vbase;
2165 vbase_array[count] = NULL;
2169 /* Return the length of the virtual base list of the type DCLASS. */
2172 virtual_base_list_length (struct type *dclass)
2175 register struct vbase *tmp_vbase;
2177 current_vbase_list = NULL;
2178 virtual_base_list_aux (dclass);
2180 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2185 /* Return the number of elements of the virtual base list of the type
2186 DCLASS, ignoring those appearing in the primary base (and its
2187 primary base, recursively). */
2190 virtual_base_list_length_skip_primaries (struct type *dclass)
2193 register struct vbase *tmp_vbase;
2194 struct type *primary;
2196 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2199 return virtual_base_list_length (dclass);
2201 current_vbase_list = NULL;
2202 virtual_base_list_aux (dclass);
2204 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
2206 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
2214 /* Return the index (position) of type BASE, which is a virtual base
2215 class of DCLASS, in the latter's virtual base list. A return of -1
2216 indicates "not found" or a problem. */
2219 virtual_base_index (struct type *base, struct type *dclass)
2221 register struct type *vbase;
2224 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2225 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2229 vbase = virtual_base_list (dclass)[0];
2234 vbase = virtual_base_list (dclass)[++i];
2237 return vbase ? i : -1;
2242 /* Return the index (position) of type BASE, which is a virtual base
2243 class of DCLASS, in the latter's virtual base list. Skip over all
2244 bases that may appear in the virtual base list of the primary base
2245 class of DCLASS (recursively). A return of -1 indicates "not
2246 found" or a problem. */
2249 virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
2251 register struct type *vbase;
2253 struct type *primary;
2255 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2256 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2259 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2263 vbase = virtual_base_list (dclass)[0];
2266 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2270 vbase = virtual_base_list (dclass)[++i];
2273 return vbase ? j : -1;
2276 /* Return position of a derived class DCLASS in the list of
2277 * primary bases starting with the remotest ancestor.
2278 * Position returned is 0-based. */
2281 class_index_in_primary_list (struct type *dclass)
2283 struct type *pbc; /* primary base class */
2285 /* Simply recurse on primary base */
2286 pbc = TYPE_PRIMARY_BASE (dclass);
2288 return 1 + class_index_in_primary_list (pbc);
2293 /* Return a count of the number of virtual functions a type has.
2294 * This includes all the virtual functions it inherits from its
2298 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2299 * functions only once (latest redefinition)
2303 count_virtual_fns (struct type *dclass)
2305 int fn, oi; /* function and overloaded instance indices */
2306 int vfuncs; /* count to return */
2308 /* recurse on bases that can share virtual table */
2309 struct type *pbc = primary_base_class (dclass);
2311 vfuncs = count_virtual_fns (pbc);
2315 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2316 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2317 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2325 /* Functions for overload resolution begin here */
2327 /* Compare two badness vectors A and B and return the result.
2328 * 0 => A and B are identical
2329 * 1 => A and B are incomparable
2330 * 2 => A is better than B
2331 * 3 => A is worse than B */
2334 compare_badness (struct badness_vector *a, struct badness_vector *b)
2338 short found_pos = 0; /* any positives in c? */
2339 short found_neg = 0; /* any negatives in c? */
2341 /* differing lengths => incomparable */
2342 if (a->length != b->length)
2345 /* Subtract b from a */
2346 for (i = 0; i < a->length; i++)
2348 tmp = a->rank[i] - b->rank[i];
2358 return 1; /* incomparable */
2360 return 3; /* A > B */
2366 return 2; /* A < B */
2368 return 0; /* A == B */
2372 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2373 * to the types of an argument list (ARGS, length NARGS).
2374 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2376 struct badness_vector *
2377 rank_function (struct type **parms, int nparms, struct type **args, int nargs)
2380 struct badness_vector *bv;
2381 int min_len = nparms < nargs ? nparms : nargs;
2383 bv = xmalloc (sizeof (struct badness_vector));
2384 bv->length = nargs + 1; /* add 1 for the length-match rank */
2385 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2387 /* First compare the lengths of the supplied lists.
2388 * If there is a mismatch, set it to a high value. */
2390 /* pai/1997-06-03 FIXME: when we have debug info about default
2391 * arguments and ellipsis parameter lists, we should consider those
2392 * and rank the length-match more finely. */
2394 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2396 /* Now rank all the parameters of the candidate function */
2397 for (i = 1; i <= min_len; i++)
2398 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2400 /* If more arguments than parameters, add dummy entries */
2401 for (i = min_len + 1; i <= nargs; i++)
2402 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2407 /* Compare one type (PARM) for compatibility with another (ARG).
2408 * PARM is intended to be the parameter type of a function; and
2409 * ARG is the supplied argument's type. This function tests if
2410 * the latter can be converted to the former.
2412 * Return 0 if they are identical types;
2413 * Otherwise, return an integer which corresponds to how compatible
2414 * PARM is to ARG. The higher the return value, the worse the match.
2415 * Generally the "bad" conversions are all uniformly assigned a 100 */
2418 rank_one_type (struct type *parm, struct type *arg)
2420 /* Identical type pointers */
2421 /* However, this still doesn't catch all cases of same type for arg
2422 * and param. The reason is that builtin types are different from
2423 * the same ones constructed from the object. */
2427 /* Resolve typedefs */
2428 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2429 parm = check_typedef (parm);
2430 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2431 arg = check_typedef (arg);
2434 Well, damnit, if the names are exactly the same,
2435 i'll say they are exactly the same. This happens when we generate
2436 method stubs. The types won't point to the same address, but they
2437 really are the same.
2440 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2441 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2444 /* Check if identical after resolving typedefs */
2448 /* See through references, since we can almost make non-references
2450 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2451 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2452 + REFERENCE_CONVERSION_BADNESS);
2453 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2454 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2455 + REFERENCE_CONVERSION_BADNESS);
2457 /* Debugging only. */
2458 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2459 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2461 /* x -> y means arg of type x being supplied for parameter of type y */
2463 switch (TYPE_CODE (parm))
2466 switch (TYPE_CODE (arg))
2469 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2470 return VOID_PTR_CONVERSION_BADNESS;
2472 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2473 case TYPE_CODE_ARRAY:
2474 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2475 case TYPE_CODE_FUNC:
2476 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2478 case TYPE_CODE_ENUM:
2479 case TYPE_CODE_CHAR:
2480 case TYPE_CODE_RANGE:
2481 case TYPE_CODE_BOOL:
2482 return POINTER_CONVERSION_BADNESS;
2484 return INCOMPATIBLE_TYPE_BADNESS;
2486 case TYPE_CODE_ARRAY:
2487 switch (TYPE_CODE (arg))
2490 case TYPE_CODE_ARRAY:
2491 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2493 return INCOMPATIBLE_TYPE_BADNESS;
2495 case TYPE_CODE_FUNC:
2496 switch (TYPE_CODE (arg))
2498 case TYPE_CODE_PTR: /* funcptr -> func */
2499 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2501 return INCOMPATIBLE_TYPE_BADNESS;
2504 switch (TYPE_CODE (arg))
2507 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2509 /* Deal with signed, unsigned, and plain chars and
2510 signed and unsigned ints */
2511 if (TYPE_NOSIGN (parm))
2513 /* This case only for character types */
2514 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2517 return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */
2519 else if (TYPE_UNSIGNED (parm))
2521 if (TYPE_UNSIGNED (arg))
2523 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2524 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2525 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2526 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2528 return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
2532 if (!strcmp_iw (TYPE_NAME (arg), "long") && !strcmp_iw (TYPE_NAME (parm), "int"))
2533 return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
2535 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2538 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2540 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2542 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2543 return INTEGER_PROMOTION_BADNESS;
2545 return INTEGER_COERCION_BADNESS;
2548 return INTEGER_COERCION_BADNESS;
2550 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2551 return INTEGER_PROMOTION_BADNESS;
2553 return INTEGER_COERCION_BADNESS;
2554 case TYPE_CODE_ENUM:
2555 case TYPE_CODE_CHAR:
2556 case TYPE_CODE_RANGE:
2557 case TYPE_CODE_BOOL:
2558 return INTEGER_PROMOTION_BADNESS;
2560 return INT_FLOAT_CONVERSION_BADNESS;
2562 return NS_POINTER_CONVERSION_BADNESS;
2564 return INCOMPATIBLE_TYPE_BADNESS;
2567 case TYPE_CODE_ENUM:
2568 switch (TYPE_CODE (arg))
2571 case TYPE_CODE_CHAR:
2572 case TYPE_CODE_RANGE:
2573 case TYPE_CODE_BOOL:
2574 case TYPE_CODE_ENUM:
2575 return INTEGER_COERCION_BADNESS;
2577 return INT_FLOAT_CONVERSION_BADNESS;
2579 return INCOMPATIBLE_TYPE_BADNESS;
2582 case TYPE_CODE_CHAR:
2583 switch (TYPE_CODE (arg))
2585 case TYPE_CODE_RANGE:
2586 case TYPE_CODE_BOOL:
2587 case TYPE_CODE_ENUM:
2588 return INTEGER_COERCION_BADNESS;
2590 return INT_FLOAT_CONVERSION_BADNESS;
2592 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2593 return INTEGER_COERCION_BADNESS;
2594 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2595 return INTEGER_PROMOTION_BADNESS;
2596 /* >>> !! else fall through !! <<< */
2597 case TYPE_CODE_CHAR:
2598 /* Deal with signed, unsigned, and plain chars for C++
2599 and with int cases falling through from previous case */
2600 if (TYPE_NOSIGN (parm))
2602 if (TYPE_NOSIGN (arg))
2605 return INTEGER_COERCION_BADNESS;
2607 else if (TYPE_UNSIGNED (parm))
2609 if (TYPE_UNSIGNED (arg))
2612 return INTEGER_PROMOTION_BADNESS;
2614 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2617 return INTEGER_COERCION_BADNESS;
2619 return INCOMPATIBLE_TYPE_BADNESS;
2622 case TYPE_CODE_RANGE:
2623 switch (TYPE_CODE (arg))
2626 case TYPE_CODE_CHAR:
2627 case TYPE_CODE_RANGE:
2628 case TYPE_CODE_BOOL:
2629 case TYPE_CODE_ENUM:
2630 return INTEGER_COERCION_BADNESS;
2632 return INT_FLOAT_CONVERSION_BADNESS;
2634 return INCOMPATIBLE_TYPE_BADNESS;
2637 case TYPE_CODE_BOOL:
2638 switch (TYPE_CODE (arg))
2641 case TYPE_CODE_CHAR:
2642 case TYPE_CODE_RANGE:
2643 case TYPE_CODE_ENUM:
2646 return BOOLEAN_CONVERSION_BADNESS;
2647 case TYPE_CODE_BOOL:
2650 return INCOMPATIBLE_TYPE_BADNESS;
2654 switch (TYPE_CODE (arg))
2657 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2658 return FLOAT_PROMOTION_BADNESS;
2659 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2662 return FLOAT_CONVERSION_BADNESS;
2664 case TYPE_CODE_BOOL:
2665 case TYPE_CODE_ENUM:
2666 case TYPE_CODE_RANGE:
2667 case TYPE_CODE_CHAR:
2668 return INT_FLOAT_CONVERSION_BADNESS;
2670 return INCOMPATIBLE_TYPE_BADNESS;
2673 case TYPE_CODE_COMPLEX:
2674 switch (TYPE_CODE (arg))
2675 { /* Strictly not needed for C++, but... */
2677 return FLOAT_PROMOTION_BADNESS;
2678 case TYPE_CODE_COMPLEX:
2681 return INCOMPATIBLE_TYPE_BADNESS;
2684 case TYPE_CODE_STRUCT:
2685 /* currently same as TYPE_CODE_CLASS */
2686 switch (TYPE_CODE (arg))
2688 case TYPE_CODE_STRUCT:
2689 /* Check for derivation */
2690 if (is_ancestor (parm, arg))
2691 return BASE_CONVERSION_BADNESS;
2692 /* else fall through */
2694 return INCOMPATIBLE_TYPE_BADNESS;
2697 case TYPE_CODE_UNION:
2698 switch (TYPE_CODE (arg))
2700 case TYPE_CODE_UNION:
2702 return INCOMPATIBLE_TYPE_BADNESS;
2705 case TYPE_CODE_MEMBER:
2706 switch (TYPE_CODE (arg))
2709 return INCOMPATIBLE_TYPE_BADNESS;
2712 case TYPE_CODE_METHOD:
2713 switch (TYPE_CODE (arg))
2717 return INCOMPATIBLE_TYPE_BADNESS;
2721 switch (TYPE_CODE (arg))
2725 return INCOMPATIBLE_TYPE_BADNESS;
2730 switch (TYPE_CODE (arg))
2734 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2736 return INCOMPATIBLE_TYPE_BADNESS;
2739 case TYPE_CODE_VOID:
2741 return INCOMPATIBLE_TYPE_BADNESS;
2742 } /* switch (TYPE_CODE (arg)) */
2746 /* End of functions for overload resolution */
2749 print_bit_vector (B_TYPE *bits, int nbits)
2753 for (bitno = 0; bitno < nbits; bitno++)
2755 if ((bitno % 8) == 0)
2757 puts_filtered (" ");
2759 if (B_TST (bits, bitno))
2761 printf_filtered ("1");
2765 printf_filtered ("0");
2770 /* Note the first arg should be the "this" pointer, we may not want to
2771 include it since we may get into a infinitely recursive situation. */
2774 print_arg_types (struct field *args, int nargs, int spaces)
2780 for (i = 0; i < nargs; i++)
2781 recursive_dump_type (args[i].type, spaces + 2);
2786 dump_fn_fieldlists (struct type *type, int spaces)
2792 printfi_filtered (spaces, "fn_fieldlists ");
2793 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2794 printf_filtered ("\n");
2795 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2797 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2798 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2800 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2801 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2803 printf_filtered (") length %d\n",
2804 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2805 for (overload_idx = 0;
2806 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2809 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2811 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2812 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2814 printf_filtered (")\n");
2815 printfi_filtered (spaces + 8, "type ");
2816 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2817 printf_filtered ("\n");
2819 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2822 printfi_filtered (spaces + 8, "args ");
2823 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2824 printf_filtered ("\n");
2826 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2827 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2829 printfi_filtered (spaces + 8, "fcontext ");
2830 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2832 printf_filtered ("\n");
2834 printfi_filtered (spaces + 8, "is_const %d\n",
2835 TYPE_FN_FIELD_CONST (f, overload_idx));
2836 printfi_filtered (spaces + 8, "is_volatile %d\n",
2837 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2838 printfi_filtered (spaces + 8, "is_private %d\n",
2839 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2840 printfi_filtered (spaces + 8, "is_protected %d\n",
2841 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2842 printfi_filtered (spaces + 8, "is_stub %d\n",
2843 TYPE_FN_FIELD_STUB (f, overload_idx));
2844 printfi_filtered (spaces + 8, "voffset %u\n",
2845 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2851 print_cplus_stuff (struct type *type, int spaces)
2853 printfi_filtered (spaces, "n_baseclasses %d\n",
2854 TYPE_N_BASECLASSES (type));
2855 printfi_filtered (spaces, "nfn_fields %d\n",
2856 TYPE_NFN_FIELDS (type));
2857 printfi_filtered (spaces, "nfn_fields_total %d\n",
2858 TYPE_NFN_FIELDS_TOTAL (type));
2859 if (TYPE_N_BASECLASSES (type) > 0)
2861 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2862 TYPE_N_BASECLASSES (type));
2863 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2864 printf_filtered (")");
2866 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2867 TYPE_N_BASECLASSES (type));
2868 puts_filtered ("\n");
2870 if (TYPE_NFIELDS (type) > 0)
2872 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2874 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2875 TYPE_NFIELDS (type));
2876 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2877 printf_filtered (")");
2878 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2879 TYPE_NFIELDS (type));
2880 puts_filtered ("\n");
2882 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2884 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2885 TYPE_NFIELDS (type));
2886 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2887 printf_filtered (")");
2888 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2889 TYPE_NFIELDS (type));
2890 puts_filtered ("\n");
2893 if (TYPE_NFN_FIELDS (type) > 0)
2895 dump_fn_fieldlists (type, spaces);
2900 print_bound_type (int bt)
2904 case BOUND_CANNOT_BE_DETERMINED:
2905 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2907 case BOUND_BY_REF_ON_STACK:
2908 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2910 case BOUND_BY_VALUE_ON_STACK:
2911 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2913 case BOUND_BY_REF_IN_REG:
2914 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2916 case BOUND_BY_VALUE_IN_REG:
2917 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2920 printf_filtered ("(BOUND_SIMPLE)");
2923 printf_filtered ("(unknown bound type)");
2928 static struct obstack dont_print_type_obstack;
2931 recursive_dump_type (struct type *type, int spaces)
2936 obstack_begin (&dont_print_type_obstack, 0);
2938 if (TYPE_NFIELDS (type) > 0
2939 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2941 struct type **first_dont_print
2942 = (struct type **) obstack_base (&dont_print_type_obstack);
2944 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2949 if (type == first_dont_print[i])
2951 printfi_filtered (spaces, "type node ");
2952 gdb_print_host_address (type, gdb_stdout);
2953 printf_filtered (" <same as already seen type>\n");
2958 obstack_ptr_grow (&dont_print_type_obstack, type);
2961 printfi_filtered (spaces, "type node ");
2962 gdb_print_host_address (type, gdb_stdout);
2963 printf_filtered ("\n");
2964 printfi_filtered (spaces, "name '%s' (",
2965 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2966 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2967 printf_filtered (")\n");
2968 printfi_filtered (spaces, "tagname '%s' (",
2969 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2970 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2971 printf_filtered (")\n");
2972 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2973 switch (TYPE_CODE (type))
2975 case TYPE_CODE_UNDEF:
2976 printf_filtered ("(TYPE_CODE_UNDEF)");
2979 printf_filtered ("(TYPE_CODE_PTR)");
2981 case TYPE_CODE_ARRAY:
2982 printf_filtered ("(TYPE_CODE_ARRAY)");
2984 case TYPE_CODE_STRUCT:
2985 printf_filtered ("(TYPE_CODE_STRUCT)");
2987 case TYPE_CODE_UNION:
2988 printf_filtered ("(TYPE_CODE_UNION)");
2990 case TYPE_CODE_ENUM:
2991 printf_filtered ("(TYPE_CODE_ENUM)");
2993 case TYPE_CODE_FUNC:
2994 printf_filtered ("(TYPE_CODE_FUNC)");
2997 printf_filtered ("(TYPE_CODE_INT)");
3000 printf_filtered ("(TYPE_CODE_FLT)");
3002 case TYPE_CODE_VOID:
3003 printf_filtered ("(TYPE_CODE_VOID)");
3006 printf_filtered ("(TYPE_CODE_SET)");
3008 case TYPE_CODE_RANGE:
3009 printf_filtered ("(TYPE_CODE_RANGE)");
3011 case TYPE_CODE_STRING:
3012 printf_filtered ("(TYPE_CODE_STRING)");
3014 case TYPE_CODE_BITSTRING:
3015 printf_filtered ("(TYPE_CODE_BITSTRING)");
3017 case TYPE_CODE_ERROR:
3018 printf_filtered ("(TYPE_CODE_ERROR)");
3020 case TYPE_CODE_MEMBER:
3021 printf_filtered ("(TYPE_CODE_MEMBER)");
3023 case TYPE_CODE_METHOD:
3024 printf_filtered ("(TYPE_CODE_METHOD)");
3027 printf_filtered ("(TYPE_CODE_REF)");
3029 case TYPE_CODE_CHAR:
3030 printf_filtered ("(TYPE_CODE_CHAR)");
3032 case TYPE_CODE_BOOL:
3033 printf_filtered ("(TYPE_CODE_BOOL)");
3035 case TYPE_CODE_COMPLEX:
3036 printf_filtered ("(TYPE_CODE_COMPLEX)");
3038 case TYPE_CODE_TYPEDEF:
3039 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3041 case TYPE_CODE_TEMPLATE:
3042 printf_filtered ("(TYPE_CODE_TEMPLATE)");
3044 case TYPE_CODE_TEMPLATE_ARG:
3045 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
3048 printf_filtered ("(UNKNOWN TYPE CODE)");
3051 puts_filtered ("\n");
3052 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
3053 printfi_filtered (spaces, "upper_bound_type 0x%x ",
3054 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
3055 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
3056 puts_filtered ("\n");
3057 printfi_filtered (spaces, "lower_bound_type 0x%x ",
3058 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
3059 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
3060 puts_filtered ("\n");
3061 printfi_filtered (spaces, "objfile ");
3062 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
3063 printf_filtered ("\n");
3064 printfi_filtered (spaces, "target_type ");
3065 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
3066 printf_filtered ("\n");
3067 if (TYPE_TARGET_TYPE (type) != NULL)
3069 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3071 printfi_filtered (spaces, "pointer_type ");
3072 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
3073 printf_filtered ("\n");
3074 printfi_filtered (spaces, "reference_type ");
3075 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
3076 printf_filtered ("\n");
3077 printfi_filtered (spaces, "type_chain ");
3078 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
3079 printf_filtered ("\n");
3080 printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
3081 if (TYPE_CONST (type))
3083 puts_filtered (" TYPE_FLAG_CONST");
3085 if (TYPE_VOLATILE (type))
3087 puts_filtered (" TYPE_FLAG_VOLATILE");
3089 if (TYPE_CODE_SPACE (type))
3091 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3093 if (TYPE_DATA_SPACE (type))
3095 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3097 puts_filtered ("\n");
3098 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
3099 if (TYPE_UNSIGNED (type))
3101 puts_filtered (" TYPE_FLAG_UNSIGNED");
3103 if (TYPE_NOSIGN (type))
3105 puts_filtered (" TYPE_FLAG_NOSIGN");
3107 if (TYPE_STUB (type))
3109 puts_filtered (" TYPE_FLAG_STUB");
3111 if (TYPE_TARGET_STUB (type))
3113 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3115 if (TYPE_STATIC (type))
3117 puts_filtered (" TYPE_FLAG_STATIC");
3119 if (TYPE_PROTOTYPED (type))
3121 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3123 if (TYPE_INCOMPLETE (type))
3125 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3127 if (TYPE_VARARGS (type))
3129 puts_filtered (" TYPE_FLAG_VARARGS");
3131 /* This is used for things like AltiVec registers on ppc. Gcc emits
3132 an attribute for the array type, which tells whether or not we
3133 have a vector, instead of a regular array. */
3134 if (TYPE_VECTOR (type))
3136 puts_filtered (" TYPE_FLAG_VECTOR");
3138 puts_filtered ("\n");
3139 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3140 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3141 puts_filtered ("\n");
3142 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3144 printfi_filtered (spaces + 2,
3145 "[%d] bitpos %d bitsize %d type ",
3146 idx, TYPE_FIELD_BITPOS (type, idx),
3147 TYPE_FIELD_BITSIZE (type, idx));
3148 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3149 printf_filtered (" name '%s' (",
3150 TYPE_FIELD_NAME (type, idx) != NULL
3151 ? TYPE_FIELD_NAME (type, idx)
3153 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3154 printf_filtered (")\n");
3155 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3157 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3160 printfi_filtered (spaces, "vptr_basetype ");
3161 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3162 puts_filtered ("\n");
3163 if (TYPE_VPTR_BASETYPE (type) != NULL)
3165 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3167 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3168 switch (TYPE_CODE (type))
3170 case TYPE_CODE_STRUCT:
3171 printfi_filtered (spaces, "cplus_stuff ");
3172 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3173 puts_filtered ("\n");
3174 print_cplus_stuff (type, spaces);
3178 printfi_filtered (spaces, "floatformat ");
3179 if (TYPE_FLOATFORMAT (type) == NULL
3180 || TYPE_FLOATFORMAT (type)->name == NULL)
3181 puts_filtered ("(null)");
3183 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3184 puts_filtered ("\n");
3188 /* We have to pick one of the union types to be able print and test
3189 the value. Pick cplus_struct_type, even though we know it isn't
3190 any particular one. */
3191 printfi_filtered (spaces, "type_specific ");
3192 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3193 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3195 printf_filtered (" (unknown data form)");
3197 printf_filtered ("\n");
3202 obstack_free (&dont_print_type_obstack, NULL);
3205 static void build_gdbtypes (void);
3207 build_gdbtypes (void)
3210 init_type (TYPE_CODE_VOID, 1,
3212 "void", (struct objfile *) NULL);
3214 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3216 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
3217 "char", (struct objfile *) NULL);
3218 builtin_type_true_char =
3219 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3221 "true character", (struct objfile *) NULL);
3222 builtin_type_signed_char =
3223 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3225 "signed char", (struct objfile *) NULL);
3226 builtin_type_unsigned_char =
3227 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3229 "unsigned char", (struct objfile *) NULL);
3230 builtin_type_short =
3231 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3233 "short", (struct objfile *) NULL);
3234 builtin_type_unsigned_short =
3235 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3237 "unsigned short", (struct objfile *) NULL);
3239 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3241 "int", (struct objfile *) NULL);
3242 builtin_type_unsigned_int =
3243 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3245 "unsigned int", (struct objfile *) NULL);
3247 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3249 "long", (struct objfile *) NULL);
3250 builtin_type_unsigned_long =
3251 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3253 "unsigned long", (struct objfile *) NULL);
3254 builtin_type_long_long =
3255 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3257 "long long", (struct objfile *) NULL);
3258 builtin_type_unsigned_long_long =
3259 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3261 "unsigned long long", (struct objfile *) NULL);
3262 builtin_type_float =
3263 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3265 "float", (struct objfile *) NULL);
3267 The below lines are disabled since they are doing the wrong
3268 thing for non-multiarch targets. They are setting the correct
3269 type of floats for the target but while on multiarch targets
3270 this is done everytime the architecture changes, it's done on
3271 non-multiarch targets only on startup, leaving the wrong values
3272 in even if the architecture changes (eg. from big-endian to
3275 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
3277 builtin_type_double =
3278 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3280 "double", (struct objfile *) NULL);
3282 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
3284 builtin_type_long_double =
3285 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3287 "long double", (struct objfile *) NULL);
3289 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
3291 builtin_type_complex =
3292 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3294 "complex", (struct objfile *) NULL);
3295 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3296 builtin_type_double_complex =
3297 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3299 "double complex", (struct objfile *) NULL);
3300 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3301 builtin_type_string =
3302 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3304 "string", (struct objfile *) NULL);
3306 init_type (TYPE_CODE_INT, 8 / 8,
3308 "int8_t", (struct objfile *) NULL);
3309 builtin_type_uint8 =
3310 init_type (TYPE_CODE_INT, 8 / 8,
3312 "uint8_t", (struct objfile *) NULL);
3313 builtin_type_int16 =
3314 init_type (TYPE_CODE_INT, 16 / 8,
3316 "int16_t", (struct objfile *) NULL);
3317 builtin_type_uint16 =
3318 init_type (TYPE_CODE_INT, 16 / 8,
3320 "uint16_t", (struct objfile *) NULL);
3321 builtin_type_int32 =
3322 init_type (TYPE_CODE_INT, 32 / 8,
3324 "int32_t", (struct objfile *) NULL);
3325 builtin_type_uint32 =
3326 init_type (TYPE_CODE_INT, 32 / 8,
3328 "uint32_t", (struct objfile *) NULL);
3329 builtin_type_int64 =
3330 init_type (TYPE_CODE_INT, 64 / 8,
3332 "int64_t", (struct objfile *) NULL);
3333 builtin_type_uint64 =
3334 init_type (TYPE_CODE_INT, 64 / 8,
3336 "uint64_t", (struct objfile *) NULL);
3337 builtin_type_int128 =
3338 init_type (TYPE_CODE_INT, 128 / 8,
3340 "int128_t", (struct objfile *) NULL);
3341 builtin_type_uint128 =
3342 init_type (TYPE_CODE_INT, 128 / 8,
3344 "uint128_t", (struct objfile *) NULL);
3346 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3348 "bool", (struct objfile *) NULL);
3350 /* Add user knob for controlling resolution of opaque types */
3352 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
3353 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3356 opaque_type_resolution = 1;
3358 /* Build SIMD types. */
3360 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
3362 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
3364 = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
3366 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
3368 = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
3370 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3372 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
3374 /* 128 bit vectors. */
3375 builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
3376 builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3377 builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
3378 builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3379 builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3380 builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3381 /* 64 bit vectors. */
3382 builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
3383 builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3384 builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3385 builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
3388 builtin_type_vec64 = build_builtin_type_vec64 ();
3389 builtin_type_vec64i = build_builtin_type_vec64i ();
3390 builtin_type_vec128 = build_builtin_type_vec128 ();
3391 builtin_type_vec128i = build_builtin_type_vec128i ();
3393 /* Pointer/Address types. */
3395 /* NOTE: on some targets, addresses and pointers are not necessarily
3396 the same --- for example, on the D10V, pointers are 16 bits long,
3397 but addresses are 32 bits long. See doc/gdbint.texinfo,
3398 ``Pointers Are Not Always Addresses''.
3401 - gdb's `struct type' always describes the target's
3403 - gdb's `struct value' objects should always hold values in
3405 - gdb's CORE_ADDR values are addresses in the unified virtual
3406 address space that the assembler and linker work with. Thus,
3407 since target_read_memory takes a CORE_ADDR as an argument, it
3408 can access any memory on the target, even if the processor has
3409 separate code and data address spaces.
3412 - If v is a value holding a D10V code pointer, its contents are
3413 in target form: a big-endian address left-shifted two bits.
3414 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3415 sizeof (void *) == 2 on the target.
3417 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3418 target type for a value the target will never see. It's only
3419 used to hold the values of (typeless) linker symbols, which are
3420 indeed in the unified virtual address space. */
3421 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
3422 builtin_type_void_func_ptr
3423 = lookup_pointer_type (lookup_function_type (builtin_type_void));
3424 builtin_type_CORE_ADDR =
3425 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
3427 "__CORE_ADDR", (struct objfile *) NULL);
3428 builtin_type_bfd_vma =
3429 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3431 "__bfd_vma", (struct objfile *) NULL);
3435 extern void _initialize_gdbtypes (void);
3437 _initialize_gdbtypes (void)
3439 struct cmd_list_element *c;
3442 /* FIXME - For the moment, handle types by swapping them in and out.
3443 Should be using the per-architecture data-pointer and a large
3445 register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL);
3446 register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL);
3447 register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL);
3448 register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL);
3449 register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL);
3450 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL);
3451 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL);
3452 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL);
3453 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL);
3454 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL);
3455 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL);
3456 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL);
3457 register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL);
3458 register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL);
3459 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL);
3460 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL);
3461 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL);
3462 register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL);
3463 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL);
3464 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL);
3465 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL);
3466 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL);
3467 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL);
3468 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
3469 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
3470 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
3471 register_gdbarch_swap (&builtin_type_int128, sizeof (struct type *), NULL);
3472 register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type *), NULL);
3473 register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
3474 register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL);
3475 register_gdbarch_swap (&builtin_type_v16qi, sizeof (struct type *), NULL);
3476 register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL);
3477 register_gdbarch_swap (&builtin_type_v8hi, sizeof (struct type *), NULL);
3478 register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
3479 register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
3480 register_gdbarch_swap (&builtin_type_v2_double, sizeof (struct type *), NULL);
3481 register_gdbarch_swap (&builtin_type_v4_float, sizeof (struct type *), NULL);
3482 register_gdbarch_swap (&builtin_type_v2_int64, sizeof (struct type *), NULL);
3483 register_gdbarch_swap (&builtin_type_v4_int32, sizeof (struct type *), NULL);
3484 register_gdbarch_swap (&builtin_type_v8_int16, sizeof (struct type *), NULL);
3485 register_gdbarch_swap (&builtin_type_v16_int8, sizeof (struct type *), NULL);
3486 register_gdbarch_swap (&builtin_type_v2_float, sizeof (struct type *), NULL);
3487 register_gdbarch_swap (&builtin_type_v2_int32, sizeof (struct type *), NULL);
3488 register_gdbarch_swap (&builtin_type_v8_int8, sizeof (struct type *), NULL);
3489 register_gdbarch_swap (&builtin_type_v4_int16, sizeof (struct type *), NULL);
3490 register_gdbarch_swap (&builtin_type_vec128, sizeof (struct type *), NULL);
3491 register_gdbarch_swap (&builtin_type_vec128i, sizeof (struct type *), NULL);
3492 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3493 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3494 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3495 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3496 register_gdbarch_swap (NULL, 0, build_gdbtypes);
3498 /* Note: These types do not need to be swapped - they are target
3500 builtin_type_ieee_single_big =
3501 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3502 0, "builtin_type_ieee_single_big", NULL);
3503 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3504 builtin_type_ieee_single_little =
3505 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3506 0, "builtin_type_ieee_single_little", NULL);
3507 TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
3508 builtin_type_ieee_double_big =
3509 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3510 0, "builtin_type_ieee_double_big", NULL);
3511 TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
3512 builtin_type_ieee_double_little =
3513 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3514 0, "builtin_type_ieee_double_little", NULL);
3515 TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
3516 builtin_type_ieee_double_littlebyte_bigword =
3517 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3518 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
3519 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
3520 builtin_type_i387_ext =
3521 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3522 0, "builtin_type_i387_ext", NULL);
3523 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
3524 builtin_type_m68881_ext =
3525 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3526 0, "builtin_type_m68881_ext", NULL);
3527 TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
3528 builtin_type_i960_ext =
3529 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3530 0, "builtin_type_i960_ext", NULL);
3531 TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
3532 builtin_type_m88110_ext =
3533 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3534 0, "builtin_type_m88110_ext", NULL);
3535 TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
3536 builtin_type_m88110_harris_ext =
3537 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3538 0, "builtin_type_m88110_harris_ext", NULL);
3539 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
3540 builtin_type_arm_ext_big =
3541 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3542 0, "builtin_type_arm_ext_big", NULL);
3543 TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
3544 builtin_type_arm_ext_littlebyte_bigword =
3545 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3546 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
3547 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
3548 builtin_type_ia64_spill_big =
3549 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3550 0, "builtin_type_ia64_spill_big", NULL);
3551 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
3552 builtin_type_ia64_spill_little =
3553 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3554 0, "builtin_type_ia64_spill_little", NULL);
3555 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
3556 builtin_type_ia64_quad_big =
3557 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3558 0, "builtin_type_ia64_quad_big", NULL);
3559 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
3560 builtin_type_ia64_quad_little =
3561 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3562 0, "builtin_type_ia64_quad_little", NULL);
3563 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
3566 add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
3567 "Set debugging of C++ overloading.\n\
3568 When enabled, ranking of the functions\n\
3569 is displayed.", &setdebuglist),