1 /* Support routines for manipulating internal types for GDB.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003
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_int0;
64 struct type *builtin_type_int8;
65 struct type *builtin_type_uint8;
66 struct type *builtin_type_int16;
67 struct type *builtin_type_uint16;
68 struct type *builtin_type_int32;
69 struct type *builtin_type_uint32;
70 struct type *builtin_type_int64;
71 struct type *builtin_type_uint64;
72 struct type *builtin_type_int128;
73 struct type *builtin_type_uint128;
74 struct type *builtin_type_bool;
76 /* 128 bit long vector types */
77 struct type *builtin_type_v2_double;
78 struct type *builtin_type_v4_float;
79 struct type *builtin_type_v2_int64;
80 struct type *builtin_type_v4_int32;
81 struct type *builtin_type_v8_int16;
82 struct type *builtin_type_v16_int8;
83 /* 64 bit long vector types */
84 struct type *builtin_type_v2_float;
85 struct type *builtin_type_v2_int32;
86 struct type *builtin_type_v4_int16;
87 struct type *builtin_type_v8_int8;
89 struct type *builtin_type_v4sf;
90 struct type *builtin_type_v4si;
91 struct type *builtin_type_v16qi;
92 struct type *builtin_type_v8qi;
93 struct type *builtin_type_v8hi;
94 struct type *builtin_type_v4hi;
95 struct type *builtin_type_v2si;
96 struct type *builtin_type_vec64;
97 struct type *builtin_type_vec64i;
98 struct type *builtin_type_vec128;
99 struct type *builtin_type_vec128i;
100 struct type *builtin_type_ieee_single_big;
101 struct type *builtin_type_ieee_single_little;
102 struct type *builtin_type_ieee_double_big;
103 struct type *builtin_type_ieee_double_little;
104 struct type *builtin_type_ieee_double_littlebyte_bigword;
105 struct type *builtin_type_i387_ext;
106 struct type *builtin_type_m68881_ext;
107 struct type *builtin_type_i960_ext;
108 struct type *builtin_type_m88110_ext;
109 struct type *builtin_type_m88110_harris_ext;
110 struct type *builtin_type_arm_ext_big;
111 struct type *builtin_type_arm_ext_littlebyte_bigword;
112 struct type *builtin_type_ia64_spill_big;
113 struct type *builtin_type_ia64_spill_little;
114 struct type *builtin_type_ia64_quad_big;
115 struct type *builtin_type_ia64_quad_little;
116 struct type *builtin_type_void_data_ptr;
117 struct type *builtin_type_void_func_ptr;
118 struct type *builtin_type_CORE_ADDR;
119 struct type *builtin_type_bfd_vma;
121 int opaque_type_resolution = 1;
122 int overload_debug = 0;
128 }; /* maximum extension is 128! FIXME */
130 static void add_name (struct extra *, char *);
131 static void add_mangled_type (struct extra *, struct type *);
132 static void print_bit_vector (B_TYPE *, int);
133 static void print_arg_types (struct field *, int, int);
134 static void dump_fn_fieldlists (struct type *, int);
135 static void print_cplus_stuff (struct type *, int);
136 static void virtual_base_list_aux (struct type *dclass);
139 /* Alloc a new type structure and fill it with some defaults. If
140 OBJFILE is non-NULL, then allocate the space for the type structure
141 in that objfile's type_obstack. Otherwise allocate the new type structure
142 by xmalloc () (for permanent types). */
145 alloc_type (struct objfile *objfile)
149 /* Alloc the structure and start off with all fields zeroed. */
153 type = xmalloc (sizeof (struct type));
154 memset (type, 0, sizeof (struct type));
155 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
159 type = obstack_alloc (&objfile->type_obstack,
160 sizeof (struct type));
161 memset (type, 0, sizeof (struct type));
162 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->type_obstack,
163 sizeof (struct main_type));
164 OBJSTAT (objfile, n_types++);
166 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
168 /* Initialize the fields that might not be zero. */
170 TYPE_CODE (type) = TYPE_CODE_UNDEF;
171 TYPE_OBJFILE (type) = objfile;
172 TYPE_VPTR_FIELDNO (type) = -1;
173 TYPE_CHAIN (type) = type; /* Chain back to itself. */
178 /* Alloc a new type instance structure, fill it with some defaults,
179 and point it at OLDTYPE. Allocate the new type instance from the
180 same place as OLDTYPE. */
183 alloc_type_instance (struct type *oldtype)
187 /* Allocate the structure. */
189 if (TYPE_OBJFILE (oldtype) == NULL)
191 type = xmalloc (sizeof (struct type));
192 memset (type, 0, sizeof (struct type));
196 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->type_obstack,
197 sizeof (struct type));
198 memset (type, 0, sizeof (struct type));
200 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
202 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
207 /* Clear all remnants of the previous type at TYPE, in preparation for
208 replacing it with something else. */
210 smash_type (struct type *type)
212 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
214 /* For now, delete the rings. */
215 TYPE_CHAIN (type) = type;
217 /* For now, leave the pointer/reference types alone. */
220 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
221 to a pointer to memory where the pointer type should be stored.
222 If *TYPEPTR is zero, update it to point to the pointer type we return.
223 We allocate new memory if needed. */
226 make_pointer_type (struct type *type, struct type **typeptr)
228 struct type *ntype; /* New type */
229 struct objfile *objfile;
231 ntype = TYPE_POINTER_TYPE (type);
236 return ntype; /* Don't care about alloc, and have new type. */
237 else if (*typeptr == 0)
239 *typeptr = ntype; /* Tracking alloc, and we have new type. */
244 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
246 ntype = alloc_type (TYPE_OBJFILE (type));
251 /* We have storage, but need to reset it. */
254 objfile = TYPE_OBJFILE (ntype);
256 TYPE_OBJFILE (ntype) = objfile;
259 TYPE_TARGET_TYPE (ntype) = type;
260 TYPE_POINTER_TYPE (type) = ntype;
262 /* FIXME! Assume the machine has only one representation for pointers! */
264 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
265 TYPE_CODE (ntype) = TYPE_CODE_PTR;
267 /* Mark pointers as unsigned. The target converts between pointers
268 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
269 ADDRESS_TO_POINTER(). */
270 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
272 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
273 TYPE_POINTER_TYPE (type) = ntype;
278 /* Given a type TYPE, return a type of pointers to that type.
279 May need to construct such a type if this is the first use. */
282 lookup_pointer_type (struct type *type)
284 return make_pointer_type (type, (struct type **) 0);
287 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
288 to a pointer to memory where the reference type should be stored.
289 If *TYPEPTR is zero, update it to point to the reference type we return.
290 We allocate new memory if needed. */
293 make_reference_type (struct type *type, struct type **typeptr)
295 struct type *ntype; /* New type */
296 struct objfile *objfile;
298 ntype = TYPE_REFERENCE_TYPE (type);
303 return ntype; /* Don't care about alloc, and have new type. */
304 else if (*typeptr == 0)
306 *typeptr = ntype; /* Tracking alloc, and we have new type. */
311 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
313 ntype = alloc_type (TYPE_OBJFILE (type));
318 /* We have storage, but need to reset it. */
321 objfile = TYPE_OBJFILE (ntype);
323 TYPE_OBJFILE (ntype) = objfile;
326 TYPE_TARGET_TYPE (ntype) = type;
327 TYPE_REFERENCE_TYPE (type) = ntype;
329 /* FIXME! Assume the machine has only one representation for references,
330 and that it matches the (only) representation for pointers! */
332 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
333 TYPE_CODE (ntype) = TYPE_CODE_REF;
335 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
336 TYPE_REFERENCE_TYPE (type) = ntype;
341 /* Same as above, but caller doesn't care about memory allocation details. */
344 lookup_reference_type (struct type *type)
346 return make_reference_type (type, (struct type **) 0);
349 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
350 to a pointer to memory where the function type should be stored.
351 If *TYPEPTR is zero, update it to point to the function type we return.
352 We allocate new memory if needed. */
355 make_function_type (struct type *type, struct type **typeptr)
357 struct type *ntype; /* New type */
358 struct objfile *objfile;
360 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
362 ntype = alloc_type (TYPE_OBJFILE (type));
367 /* We have storage, but need to reset it. */
370 objfile = TYPE_OBJFILE (ntype);
372 TYPE_OBJFILE (ntype) = objfile;
375 TYPE_TARGET_TYPE (ntype) = type;
377 TYPE_LENGTH (ntype) = 1;
378 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
384 /* Given a type TYPE, return a type of functions that return that type.
385 May need to construct such a type if this is the first use. */
388 lookup_function_type (struct type *type)
390 return make_function_type (type, (struct type **) 0);
393 /* Identify address space identifier by name --
394 return the integer flag defined in gdbtypes.h. */
396 address_space_name_to_int (char *space_identifier)
398 struct gdbarch *gdbarch = current_gdbarch;
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;
405 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
406 && gdbarch_address_class_name_to_type_flags (gdbarch,
411 error ("Unknown address space specifier: \"%s\"", space_identifier);
414 /* Identify address space identifier by integer flag as defined in
415 gdbtypes.h -- return the string version of the adress space name. */
418 address_space_int_to_name (int space_flag)
420 struct gdbarch *gdbarch = current_gdbarch;
421 if (space_flag & TYPE_FLAG_CODE_SPACE)
423 else if (space_flag & TYPE_FLAG_DATA_SPACE)
425 else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL)
426 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
427 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
432 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
433 If STORAGE is non-NULL, create the new type instance there. */
436 make_qualified_type (struct type *type, int new_flags,
437 struct type *storage)
443 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
445 ntype = TYPE_CHAIN (ntype);
446 } while (ntype != type);
448 /* Create a new type instance. */
450 ntype = alloc_type_instance (type);
454 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
455 TYPE_CHAIN (ntype) = ntype;
458 /* Pointers or references to the original type are not relevant to
460 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
461 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
463 /* Chain the new qualified type to the old type. */
464 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
465 TYPE_CHAIN (type) = ntype;
467 /* Now set the instance flags and return the new type. */
468 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
470 /* Set length of new type to that of the original type. */
471 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
476 /* Make an address-space-delimited variant of a type -- a type that
477 is identical to the one supplied except that it has an address
478 space attribute attached to it (such as "code" or "data").
480 The space attributes "code" and "data" are for Harvard architectures.
481 The address space attributes are for architectures which have
482 alternately sized pointers or pointers with alternate representations. */
485 make_type_with_address_space (struct type *type, int space_flag)
488 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
489 & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE
490 | TYPE_FLAG_ADDRESS_CLASS_ALL))
493 return make_qualified_type (type, new_flags, NULL);
496 /* Make a "c-v" variant of a type -- a type that is identical to the
497 one supplied except that it may have const or volatile attributes
498 CNST is a flag for setting the const attribute
499 VOLTL is a flag for setting the volatile attribute
500 TYPE is the base type whose variant we are creating.
501 TYPEPTR, if nonzero, points
502 to a pointer to memory where the reference type should be stored.
503 If *TYPEPTR is zero, update it to point to the reference type we return.
504 We allocate new memory if needed. */
507 make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
509 struct type *ntype; /* New type */
510 struct type *tmp_type = type; /* tmp type */
511 struct objfile *objfile;
513 int new_flags = (TYPE_INSTANCE_FLAGS (type)
514 & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
517 new_flags |= TYPE_FLAG_CONST;
520 new_flags |= TYPE_FLAG_VOLATILE;
522 if (typeptr && *typeptr != NULL)
524 /* Objfile is per-core-type. This const-qualified type had best
525 belong to the same objfile as the type it is qualifying, unless
526 we are overwriting a stub type, in which case the safest thing
527 to do is to copy the core type into the new objfile. */
529 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)
530 || TYPE_STUB (*typeptr));
531 if (TYPE_OBJFILE (*typeptr) != TYPE_OBJFILE (type))
533 TYPE_MAIN_TYPE (*typeptr)
534 = TYPE_ALLOC (*typeptr, sizeof (struct main_type));
535 *TYPE_MAIN_TYPE (*typeptr)
536 = *TYPE_MAIN_TYPE (type);
540 ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
548 /* Replace the contents of ntype with the type *type. This changes the
549 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
550 the changes are propogated to all types in the TYPE_CHAIN.
552 In order to build recursive types, it's inevitable that we'll need
553 to update types in place --- but this sort of indiscriminate
554 smashing is ugly, and needs to be replaced with something more
555 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
556 clear if more steps are needed. */
558 replace_type (struct type *ntype, struct type *type)
562 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
564 /* The type length is not a part of the main type. Update it for each
565 type on the variant chain. */
568 /* Assert that this element of the chain has no address-class bits
569 set in its flags. Such type variants might have type lengths
570 which are supposed to be different from the non-address-class
571 variants. This assertion shouldn't ever be triggered because
572 symbol readers which do construct address-class variants don't
573 call replace_type(). */
574 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
576 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
577 chain = TYPE_CHAIN (chain);
578 } while (ntype != chain);
580 /* Assert that the two types have equivalent instance qualifiers.
581 This should be true for at least all of our debug readers. */
582 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
585 /* Implement direct support for MEMBER_TYPE in GNU C++.
586 May need to construct such a type if this is the first use.
587 The TYPE is the type of the member. The DOMAIN is the type
588 of the aggregate that the member belongs to. */
591 lookup_member_type (struct type *type, struct type *domain)
595 mtype = alloc_type (TYPE_OBJFILE (type));
596 smash_to_member_type (mtype, domain, type);
600 /* Allocate a stub method whose return type is TYPE.
601 This apparently happens for speed of symbol reading, since parsing
602 out the arguments to the method is cpu-intensive, the way we are doing
603 it. So, we will fill in arguments later.
604 This always returns a fresh type. */
607 allocate_stub_method (struct type *type)
611 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
612 TYPE_OBJFILE (type));
613 TYPE_TARGET_TYPE (mtype) = type;
614 /* _DOMAIN_TYPE (mtype) = unknown yet */
618 /* Create a range type using either a blank type supplied in RESULT_TYPE,
619 or creating a new type, inheriting the objfile from INDEX_TYPE.
621 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
622 HIGH_BOUND, inclusive.
624 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
625 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
628 create_range_type (struct type *result_type, struct type *index_type,
629 int low_bound, int high_bound)
631 if (result_type == NULL)
633 result_type = alloc_type (TYPE_OBJFILE (index_type));
635 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
636 TYPE_TARGET_TYPE (result_type) = index_type;
637 if (TYPE_STUB (index_type))
638 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
640 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
641 TYPE_NFIELDS (result_type) = 2;
642 TYPE_FIELDS (result_type) = (struct field *)
643 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
644 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
645 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
646 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
647 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
648 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
651 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
653 return (result_type);
656 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
657 Return 1 of type is a range type, 0 if it is discrete (and bounds
658 will fit in LONGEST), or -1 otherwise. */
661 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
663 CHECK_TYPEDEF (type);
664 switch (TYPE_CODE (type))
666 case TYPE_CODE_RANGE:
667 *lowp = TYPE_LOW_BOUND (type);
668 *highp = TYPE_HIGH_BOUND (type);
671 if (TYPE_NFIELDS (type) > 0)
673 /* The enums may not be sorted by value, so search all
677 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
678 for (i = 0; i < TYPE_NFIELDS (type); i++)
680 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
681 *lowp = TYPE_FIELD_BITPOS (type, i);
682 if (TYPE_FIELD_BITPOS (type, i) > *highp)
683 *highp = TYPE_FIELD_BITPOS (type, i);
686 /* Set unsigned indicator if warranted. */
689 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
703 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
705 if (!TYPE_UNSIGNED (type))
707 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
711 /* ... fall through for unsigned ints ... */
714 /* This round-about calculation is to avoid shifting by
715 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
716 if TYPE_LENGTH (type) == sizeof (LONGEST). */
717 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
718 *highp = (*highp - 1) | *highp;
725 /* Create an array type using either a blank type supplied in RESULT_TYPE,
726 or creating a new type, inheriting the objfile from RANGE_TYPE.
728 Elements will be of type ELEMENT_TYPE, the indices will be of type
731 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
732 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
735 create_array_type (struct type *result_type, struct type *element_type,
736 struct type *range_type)
738 LONGEST low_bound, high_bound;
740 if (result_type == NULL)
742 result_type = alloc_type (TYPE_OBJFILE (range_type));
744 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
745 TYPE_TARGET_TYPE (result_type) = element_type;
746 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
747 low_bound = high_bound = 0;
748 CHECK_TYPEDEF (element_type);
749 TYPE_LENGTH (result_type) =
750 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
751 TYPE_NFIELDS (result_type) = 1;
752 TYPE_FIELDS (result_type) =
753 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
754 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
755 TYPE_FIELD_TYPE (result_type, 0) = range_type;
756 TYPE_VPTR_FIELDNO (result_type) = -1;
758 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
759 if (TYPE_LENGTH (result_type) == 0)
760 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
762 return (result_type);
765 /* Create a string type using either a blank type supplied in RESULT_TYPE,
766 or creating a new type. String types are similar enough to array of
767 char types that we can use create_array_type to build the basic type
768 and then bash it into a string type.
770 For fixed length strings, the range type contains 0 as the lower
771 bound and the length of the string minus one as the upper bound.
773 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
774 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
777 create_string_type (struct type *result_type, struct type *range_type)
779 result_type = create_array_type (result_type,
780 *current_language->string_char_type,
782 TYPE_CODE (result_type) = TYPE_CODE_STRING;
783 return (result_type);
787 create_set_type (struct type *result_type, struct type *domain_type)
789 LONGEST low_bound, high_bound, bit_length;
790 if (result_type == NULL)
792 result_type = alloc_type (TYPE_OBJFILE (domain_type));
794 TYPE_CODE (result_type) = TYPE_CODE_SET;
795 TYPE_NFIELDS (result_type) = 1;
796 TYPE_FIELDS (result_type) = (struct field *)
797 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
798 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
800 if (!TYPE_STUB (domain_type))
802 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
803 low_bound = high_bound = 0;
804 bit_length = high_bound - low_bound + 1;
805 TYPE_LENGTH (result_type)
806 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
808 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
811 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
813 return (result_type);
816 /* Construct and return a type of the form:
817 struct NAME { ELT_TYPE ELT_NAME[N]; }
818 We use these types for SIMD registers. For example, the type of
819 the SSE registers on the late x86-family processors is:
820 struct __builtin_v4sf { float f[4]; }
821 built by the function call:
822 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
823 The type returned is a permanent type, allocated using malloc; it
824 doesn't live in any objfile's obstack. */
826 init_simd_type (char *name,
827 struct type *elt_type,
831 struct type *simd_type;
832 struct type *array_type;
834 simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
835 array_type = create_array_type (0, elt_type,
836 create_range_type (0, builtin_type_int,
838 append_composite_type_field (simd_type, elt_name, array_type);
843 init_vector_type (struct type *elt_type, int n)
845 struct type *array_type;
847 array_type = create_array_type (0, elt_type,
848 create_range_type (0, builtin_type_int,
850 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
855 build_builtin_type_vec64 (void)
857 /* Construct a type for the 64 bit registers. The type we're
860 union __gdb_builtin_type_vec64
872 t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION);
873 append_composite_type_field (t, "uint64", builtin_type_int64);
874 append_composite_type_field (t, "v2_float", builtin_type_v2_float);
875 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
876 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
877 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
879 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
880 TYPE_NAME (t) = "builtin_type_vec64";
885 build_builtin_type_vec64i (void)
887 /* Construct a type for the 64 bit registers. The type we're
890 union __gdb_builtin_type_vec64i
901 t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
902 append_composite_type_field (t, "uint64", builtin_type_int64);
903 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
904 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
905 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
907 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
908 TYPE_NAME (t) = "builtin_type_vec64i";
913 build_builtin_type_vec128 (void)
915 /* Construct a type for the 128 bit registers. The type we're
918 union __gdb_builtin_type_vec128
930 t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
931 append_composite_type_field (t, "uint128", builtin_type_int128);
932 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
933 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
934 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
935 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
937 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
938 TYPE_NAME (t) = "builtin_type_vec128";
943 build_builtin_type_vec128i (void)
945 /* 128-bit Intel SIMD registers */
948 t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
949 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
950 append_composite_type_field (t, "v2_double", builtin_type_v2_double);
951 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
952 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
953 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
954 append_composite_type_field (t, "v2_int64", builtin_type_v2_int64);
955 append_composite_type_field (t, "uint128", builtin_type_int128);
957 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
958 TYPE_NAME (t) = "builtin_type_vec128i";
962 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
963 A MEMBER is a wierd thing -- it amounts to a typed offset into
964 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
965 include the offset (that's the value of the MEMBER itself), but does
966 include the structure type into which it points (for some reason).
968 When "smashing" the type, we preserve the objfile that the
969 old type pointed to, since we aren't changing where the type is actually
973 smash_to_member_type (struct type *type, struct type *domain,
974 struct type *to_type)
976 struct objfile *objfile;
978 objfile = TYPE_OBJFILE (type);
981 TYPE_OBJFILE (type) = objfile;
982 TYPE_TARGET_TYPE (type) = to_type;
983 TYPE_DOMAIN_TYPE (type) = domain;
984 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
985 TYPE_CODE (type) = TYPE_CODE_MEMBER;
988 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
989 METHOD just means `function that gets an extra "this" argument'.
991 When "smashing" the type, we preserve the objfile that the
992 old type pointed to, since we aren't changing where the type is actually
996 smash_to_method_type (struct type *type, struct type *domain,
997 struct type *to_type, struct field *args,
998 int nargs, int varargs)
1000 struct objfile *objfile;
1002 objfile = TYPE_OBJFILE (type);
1005 TYPE_OBJFILE (type) = objfile;
1006 TYPE_TARGET_TYPE (type) = to_type;
1007 TYPE_DOMAIN_TYPE (type) = domain;
1008 TYPE_FIELDS (type) = args;
1009 TYPE_NFIELDS (type) = nargs;
1011 TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
1012 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1013 TYPE_CODE (type) = TYPE_CODE_METHOD;
1016 /* Return a typename for a struct/union/enum type without "struct ",
1017 "union ", or "enum ". If the type has a NULL name, return NULL. */
1020 type_name_no_tag (const struct type *type)
1022 if (TYPE_TAG_NAME (type) != NULL)
1023 return TYPE_TAG_NAME (type);
1025 /* Is there code which expects this to return the name if there is no
1026 tag name? My guess is that this is mainly used for C++ in cases where
1027 the two will always be the same. */
1028 return TYPE_NAME (type);
1031 /* Lookup a primitive type named NAME.
1032 Return zero if NAME is not a primitive type. */
1035 lookup_primitive_typename (char *name)
1037 struct type **const *p;
1039 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
1041 if (strcmp (TYPE_NAME (**p), name) == 0)
1049 /* Lookup a typedef or primitive type named NAME,
1050 visible in lexical block BLOCK.
1051 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1054 lookup_typename (char *name, struct block *block, int noerr)
1059 sym = lookup_symbol (name, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
1060 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1062 tmp = lookup_primitive_typename (name);
1067 else if (!tmp && noerr)
1073 error ("No type named %s.", name);
1076 return (SYMBOL_TYPE (sym));
1080 lookup_unsigned_typename (char *name)
1082 char *uns = alloca (strlen (name) + 10);
1084 strcpy (uns, "unsigned ");
1085 strcpy (uns + 9, name);
1086 return (lookup_typename (uns, (struct block *) NULL, 0));
1090 lookup_signed_typename (char *name)
1093 char *uns = alloca (strlen (name) + 8);
1095 strcpy (uns, "signed ");
1096 strcpy (uns + 7, name);
1097 t = lookup_typename (uns, (struct block *) NULL, 1);
1098 /* If we don't find "signed FOO" just try again with plain "FOO". */
1101 return lookup_typename (name, (struct block *) NULL, 0);
1104 /* Lookup a structure type named "struct NAME",
1105 visible in lexical block BLOCK. */
1108 lookup_struct (char *name, struct block *block)
1112 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1113 (struct symtab **) NULL);
1117 error ("No struct type named %s.", name);
1119 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1121 error ("This context has class, union or enum %s, not a struct.", name);
1123 return (SYMBOL_TYPE (sym));
1126 /* Lookup a union type named "union NAME",
1127 visible in lexical block BLOCK. */
1130 lookup_union (char *name, struct block *block)
1135 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1136 (struct symtab **) NULL);
1139 error ("No union type named %s.", name);
1141 t = SYMBOL_TYPE (sym);
1143 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1146 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1147 * a further "declared_type" field to discover it is really a union.
1149 if (HAVE_CPLUS_STRUCT (t))
1150 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1153 /* If we get here, it's not a union */
1154 error ("This context has class, struct or enum %s, not a union.", name);
1158 /* Lookup an enum type named "enum NAME",
1159 visible in lexical block BLOCK. */
1162 lookup_enum (char *name, struct block *block)
1166 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1167 (struct symtab **) NULL);
1170 error ("No enum type named %s.", name);
1172 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1174 error ("This context has class, struct or union %s, not an enum.", name);
1176 return (SYMBOL_TYPE (sym));
1179 /* Lookup a template type named "template NAME<TYPE>",
1180 visible in lexical block BLOCK. */
1183 lookup_template_type (char *name, struct type *type, struct block *block)
1186 char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1189 strcat (nam, TYPE_NAME (type));
1190 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1192 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
1196 error ("No template type named %s.", name);
1198 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1200 error ("This context has class, union or enum %s, not a struct.", name);
1202 return (SYMBOL_TYPE (sym));
1205 /* Given a type TYPE, lookup the type of the component of type named NAME.
1207 TYPE can be either a struct or union, or a pointer or reference to a struct or
1208 union. If it is a pointer or reference, its target type is automatically used.
1209 Thus '.' and '->' are interchangable, as specified for the definitions of the
1210 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1212 If NOERR is nonzero, return zero if NAME is not suitably defined.
1213 If NAME is the name of a baseclass type, return that type. */
1216 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1222 CHECK_TYPEDEF (type);
1223 if (TYPE_CODE (type) != TYPE_CODE_PTR
1224 && TYPE_CODE (type) != TYPE_CODE_REF)
1226 type = TYPE_TARGET_TYPE (type);
1229 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1230 TYPE_CODE (type) != TYPE_CODE_UNION)
1232 target_terminal_ours ();
1233 gdb_flush (gdb_stdout);
1234 fprintf_unfiltered (gdb_stderr, "Type ");
1235 type_print (type, "", gdb_stderr, -1);
1236 error (" is not a structure or union type.");
1240 /* FIXME: This change put in by Michael seems incorrect for the case where
1241 the structure tag name is the same as the member name. I.E. when doing
1242 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1247 typename = type_name_no_tag (type);
1248 if (typename != NULL && strcmp (typename, name) == 0)
1253 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1255 char *t_field_name = TYPE_FIELD_NAME (type, i);
1257 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1259 return TYPE_FIELD_TYPE (type, i);
1263 /* OK, it's not in this class. Recursively check the baseclasses. */
1264 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1268 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1280 target_terminal_ours ();
1281 gdb_flush (gdb_stdout);
1282 fprintf_unfiltered (gdb_stderr, "Type ");
1283 type_print (type, "", gdb_stderr, -1);
1284 fprintf_unfiltered (gdb_stderr, " has no component named ");
1285 fputs_filtered (name, gdb_stderr);
1287 return (struct type *) -1; /* For lint */
1290 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1291 valid. Callers should be aware that in some cases (for example,
1292 the type or one of its baseclasses is a stub type and we are
1293 debugging a .o file), this function will not be able to find the virtual
1294 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1295 will remain NULL. */
1298 fill_in_vptr_fieldno (struct type *type)
1300 CHECK_TYPEDEF (type);
1302 if (TYPE_VPTR_FIELDNO (type) < 0)
1306 /* We must start at zero in case the first (and only) baseclass is
1307 virtual (and hence we cannot share the table pointer). */
1308 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1310 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1311 fill_in_vptr_fieldno (baseclass);
1312 if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
1314 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
1315 TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
1322 /* Find the method and field indices for the destructor in class type T.
1323 Return 1 if the destructor was found, otherwise, return 0. */
1326 get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
1330 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1333 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1335 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1337 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1348 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1350 If this is a stubbed struct (i.e. declared as struct foo *), see if
1351 we can find a full definition in some other file. If so, copy this
1352 definition, so we can use it in future. There used to be a comment (but
1353 not any code) that if we don't find a full definition, we'd set a flag
1354 so we don't spend time in the future checking the same type. That would
1355 be a mistake, though--we might load in more symbols which contain a
1356 full definition for the type.
1358 This used to be coded as a macro, but I don't think it is called
1359 often enough to merit such treatment. */
1362 stub_noname_complaint (void)
1364 complaint (&symfile_complaints, "stub type has NULL name");
1368 check_typedef (struct type *type)
1370 struct type *orig_type = type;
1371 int is_const, is_volatile;
1373 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1375 if (!TYPE_TARGET_TYPE (type))
1380 /* It is dangerous to call lookup_symbol if we are currently
1381 reading a symtab. Infinite recursion is one danger. */
1382 if (currently_reading_symtab)
1385 name = type_name_no_tag (type);
1386 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1387 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1388 as appropriate? (this code was written before TYPE_NAME and
1389 TYPE_TAG_NAME were separate). */
1392 stub_noname_complaint ();
1395 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
1396 (struct symtab **) NULL);
1398 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1400 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1402 type = TYPE_TARGET_TYPE (type);
1405 is_const = TYPE_CONST (type);
1406 is_volatile = TYPE_VOLATILE (type);
1408 /* If this is a struct/class/union with no fields, then check whether a
1409 full definition exists somewhere else. This is for systems where a
1410 type definition with no fields is issued for such types, instead of
1411 identifying them as stub types in the first place */
1413 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1415 char *name = type_name_no_tag (type);
1416 struct type *newtype;
1419 stub_noname_complaint ();
1422 newtype = lookup_transparent_type (name);
1424 make_cv_type (is_const, is_volatile, newtype, &type);
1426 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1427 else if (TYPE_STUB (type) && !currently_reading_symtab)
1429 char *name = type_name_no_tag (type);
1430 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1431 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1432 as appropriate? (this code was written before TYPE_NAME and
1433 TYPE_TAG_NAME were separate). */
1437 stub_noname_complaint ();
1440 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL);
1442 make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type);
1445 if (TYPE_TARGET_STUB (type))
1447 struct type *range_type;
1448 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1450 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1453 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1454 && TYPE_NFIELDS (type) == 1
1455 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1456 == TYPE_CODE_RANGE))
1458 /* Now recompute the length of the array type, based on its
1459 number of elements and the target type's length. */
1460 TYPE_LENGTH (type) =
1461 ((TYPE_FIELD_BITPOS (range_type, 1)
1462 - TYPE_FIELD_BITPOS (range_type, 0)
1464 * TYPE_LENGTH (target_type));
1465 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1467 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1469 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1470 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1473 /* Cache TYPE_LENGTH for future use. */
1474 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1478 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1479 silently return builtin_type_void. */
1481 static struct type *
1482 safe_parse_type (char *p, int length)
1484 struct ui_file *saved_gdb_stderr;
1487 /* Suppress error messages. */
1488 saved_gdb_stderr = gdb_stderr;
1489 gdb_stderr = ui_file_new ();
1491 /* Call parse_and_eval_type() without fear of longjmp()s. */
1492 if (!gdb_parse_and_eval_type (p, length, &type))
1493 type = builtin_type_void;
1495 /* Stop suppressing error messages. */
1496 ui_file_delete (gdb_stderr);
1497 gdb_stderr = saved_gdb_stderr;
1502 /* Ugly hack to convert method stubs into method types.
1504 He ain't kiddin'. This demangles the name of the method into a string
1505 including argument types, parses out each argument type, generates
1506 a string casting a zero to that type, evaluates the string, and stuffs
1507 the resulting type into an argtype vector!!! Then it knows the type
1508 of the whole function (including argument types for overloading),
1509 which info used to be in the stab's but was removed to hack back
1510 the space required for them. */
1513 check_stub_method (struct type *type, int method_id, int signature_id)
1516 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1517 char *demangled_name = cplus_demangle (mangled_name,
1518 DMGL_PARAMS | DMGL_ANSI);
1519 char *argtypetext, *p;
1520 int depth = 0, argcount = 1;
1521 struct field *argtypes;
1524 /* Make sure we got back a function string that we can use. */
1526 p = strchr (demangled_name, '(');
1530 if (demangled_name == NULL || p == NULL)
1531 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1533 /* Now, read in the parameters that define this type. */
1538 if (*p == '(' || *p == '<')
1542 else if (*p == ')' || *p == '>')
1546 else if (*p == ',' && depth == 0)
1554 /* If we read one argument and it was ``void'', don't count it. */
1555 if (strncmp (argtypetext, "(void)", 6) == 0)
1558 /* We need one extra slot, for the THIS pointer. */
1560 argtypes = (struct field *)
1561 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1564 /* Add THIS pointer for non-static methods. */
1565 f = TYPE_FN_FIELDLIST1 (type, method_id);
1566 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1570 argtypes[0].type = lookup_pointer_type (type);
1574 if (*p != ')') /* () means no args, skip while */
1579 if (depth <= 0 && (*p == ',' || *p == ')'))
1581 /* Avoid parsing of ellipsis, they will be handled below.
1582 Also avoid ``void'' as above. */
1583 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1584 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1586 argtypes[argcount].type =
1587 safe_parse_type (argtypetext, p - argtypetext);
1590 argtypetext = p + 1;
1593 if (*p == '(' || *p == '<')
1597 else if (*p == ')' || *p == '>')
1606 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1608 /* Now update the old "stub" type into a real type. */
1609 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1610 TYPE_DOMAIN_TYPE (mtype) = type;
1611 TYPE_FIELDS (mtype) = argtypes;
1612 TYPE_NFIELDS (mtype) = argcount;
1613 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1614 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1616 TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1618 xfree (demangled_name);
1621 /* This is the external interface to check_stub_method, above. This function
1622 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1623 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1624 and TYPE_FN_FIELDLIST_NAME will be correct.
1626 This function unfortunately can not die until stabs do. */
1629 check_stub_method_group (struct type *type, int method_id)
1631 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1632 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1633 int j, found_stub = 0;
1635 for (j = 0; j < len; j++)
1636 if (TYPE_FN_FIELD_STUB (f, j))
1639 check_stub_method (type, method_id, j);
1642 /* GNU v3 methods with incorrect names were corrected when we read in
1643 type information, because it was cheaper to do it then. The only GNU v2
1644 methods with incorrect method names are operators and destructors;
1645 destructors were also corrected when we read in type information.
1647 Therefore the only thing we need to handle here are v2 operator
1649 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1652 char dem_opname[256];
1654 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1655 dem_opname, DMGL_ANSI);
1657 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1660 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1664 const struct cplus_struct_type cplus_struct_default;
1667 allocate_cplus_struct_type (struct type *type)
1669 if (!HAVE_CPLUS_STRUCT (type))
1671 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1672 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1673 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1677 /* Helper function to initialize the standard scalar types.
1679 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1680 of the string pointed to by name in the type_obstack for that objfile,
1681 and initialize the type name to that copy. There are places (mipsread.c
1682 in particular, where init_type is called with a NULL value for NAME). */
1685 init_type (enum type_code code, int length, int flags, char *name,
1686 struct objfile *objfile)
1690 type = alloc_type (objfile);
1691 TYPE_CODE (type) = code;
1692 TYPE_LENGTH (type) = length;
1693 TYPE_FLAGS (type) |= flags;
1694 if ((name != NULL) && (objfile != NULL))
1697 obsavestring (name, strlen (name), &objfile->type_obstack);
1701 TYPE_NAME (type) = name;
1706 if (name && strcmp (name, "char") == 0)
1707 TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
1709 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1710 || code == TYPE_CODE_NAMESPACE)
1712 INIT_CPLUS_SPECIFIC (type);
1717 /* Helper function. Create an empty composite type. */
1720 init_composite_type (char *name, enum type_code code)
1723 gdb_assert (code == TYPE_CODE_STRUCT
1724 || code == TYPE_CODE_UNION);
1725 t = init_type (code, 0, 0, NULL, NULL);
1726 TYPE_TAG_NAME (t) = name;
1730 /* Helper function. Append a field to a composite type. */
1733 append_composite_type_field (struct type *t, char *name, struct type *field)
1736 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1737 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1738 sizeof (struct field) * TYPE_NFIELDS (t));
1739 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1740 memset (f, 0, sizeof f[0]);
1741 FIELD_TYPE (f[0]) = field;
1742 FIELD_NAME (f[0]) = name;
1743 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1745 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1746 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1748 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1750 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1751 if (TYPE_NFIELDS (t) > 1)
1753 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1754 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1759 /* Look up a fundamental type for the specified objfile.
1760 May need to construct such a type if this is the first use.
1762 Some object file formats (ELF, COFF, etc) do not define fundamental
1763 types such as "int" or "double". Others (stabs for example), do
1764 define fundamental types.
1766 For the formats which don't provide fundamental types, gdb can create
1767 such types, using defaults reasonable for the current language and
1768 the current target machine.
1770 NOTE: This routine is obsolescent. Each debugging format reader
1771 should manage it's own fundamental types, either creating them from
1772 suitable defaults or reading them from the debugging information,
1773 whichever is appropriate. The DWARF reader has already been
1774 fixed to do this. Once the other readers are fixed, this routine
1775 will go away. Also note that fundamental types should be managed
1776 on a compilation unit basis in a multi-language environment, not
1777 on a linkage unit basis as is done here. */
1781 lookup_fundamental_type (struct objfile *objfile, int typeid)
1783 struct type **typep;
1786 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1788 error ("internal error - invalid fundamental type id %d", typeid);
1791 /* If this is the first time we need a fundamental type for this objfile
1792 then we need to initialize the vector of type pointers. */
1794 if (objfile->fundamental_types == NULL)
1796 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1797 objfile->fundamental_types = (struct type **)
1798 obstack_alloc (&objfile->type_obstack, nbytes);
1799 memset ((char *) objfile->fundamental_types, 0, nbytes);
1800 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1803 /* Look for this particular type in the fundamental type vector. If one is
1804 not found, create and install one appropriate for the current language. */
1806 typep = objfile->fundamental_types + typeid;
1809 *typep = create_fundamental_type (objfile, typeid);
1816 can_dereference (struct type *t)
1818 /* FIXME: Should we return true for references as well as pointers? */
1822 && TYPE_CODE (t) == TYPE_CODE_PTR
1823 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1827 is_integral_type (struct type *t)
1832 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1833 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1834 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1835 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1836 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1839 /* Check whether BASE is an ancestor or base class or DCLASS
1840 Return 1 if so, and 0 if not.
1841 Note: callers may want to check for identity of the types before
1842 calling this function -- identical types are considered to satisfy
1843 the ancestor relationship even if they're identical */
1846 is_ancestor (struct type *base, struct type *dclass)
1850 CHECK_TYPEDEF (base);
1851 CHECK_TYPEDEF (dclass);
1855 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
1856 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1859 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1860 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1868 /* See whether DCLASS has a virtual table. This routine is aimed at
1869 the HP/Taligent ANSI C++ runtime model, and may not work with other
1870 runtime models. Return 1 => Yes, 0 => No. */
1873 has_vtable (struct type *dclass)
1875 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1876 has virtual functions or virtual bases. */
1880 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1883 /* First check for the presence of virtual bases */
1884 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1885 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1886 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1889 /* Next check for virtual functions */
1890 if (TYPE_FN_FIELDLISTS (dclass))
1891 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1892 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1895 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1896 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1897 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1898 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1899 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1902 /* Well, maybe we don't need a virtual table */
1906 /* Return a pointer to the "primary base class" of DCLASS.
1908 A NULL return indicates that DCLASS has no primary base, or that it
1909 couldn't be found (insufficient information).
1911 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1912 and may not work with other runtime models. */
1915 primary_base_class (struct type *dclass)
1917 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1918 is the first directly inherited, non-virtual base class that
1919 requires a virtual table */
1923 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1926 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1927 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1928 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1929 return TYPE_FIELD_TYPE (dclass, i);
1934 /* Global manipulated by virtual_base_list[_aux]() */
1936 static struct vbase *current_vbase_list = NULL;
1938 /* Return a pointer to a null-terminated list of struct vbase
1939 items. The vbasetype pointer of each item in the list points to the
1940 type information for a virtual base of the argument DCLASS.
1942 Helper function for virtual_base_list().
1943 Note: the list goes backward, right-to-left. virtual_base_list()
1944 copies the items out in reverse order. */
1947 virtual_base_list_aux (struct type *dclass)
1949 struct vbase *tmp_vbase;
1952 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1955 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1957 /* Recurse on this ancestor, first */
1958 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
1960 /* If this current base is itself virtual, add it to the list */
1961 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1963 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1965 /* Check if base already recorded */
1966 tmp_vbase = current_vbase_list;
1969 if (tmp_vbase->vbasetype == basetype)
1970 break; /* found it */
1971 tmp_vbase = tmp_vbase->next;
1974 if (!tmp_vbase) /* normal exit from loop */
1976 /* Allocate new item for this virtual base */
1977 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
1979 /* Stick it on at the end of the list */
1980 tmp_vbase->vbasetype = basetype;
1981 tmp_vbase->next = current_vbase_list;
1982 current_vbase_list = tmp_vbase;
1985 } /* for loop over bases */
1989 /* Compute the list of virtual bases in the right order. Virtual
1990 bases are laid out in the object's memory area in order of their
1991 occurrence in a depth-first, left-to-right search through the
1994 Argument DCLASS is the type whose virtual bases are required.
1995 Return value is the address of a null-terminated array of pointers
1996 to struct type items.
1998 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1999 and may not work with other runtime models.
2001 This routine merely hands off the argument to virtual_base_list_aux()
2002 and then copies the result into an array to save space. */
2005 virtual_base_list (struct type *dclass)
2007 struct vbase *tmp_vbase;
2008 struct vbase *tmp_vbase_2;
2011 struct type **vbase_array;
2013 current_vbase_list = NULL;
2014 virtual_base_list_aux (dclass);
2016 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2021 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
2023 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
2024 vbase_array[i] = tmp_vbase->vbasetype;
2026 /* Get rid of constructed chain */
2027 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2030 tmp_vbase = tmp_vbase->next;
2031 xfree (tmp_vbase_2);
2032 tmp_vbase_2 = tmp_vbase;
2035 vbase_array[count] = NULL;
2039 /* Return the length of the virtual base list of the type DCLASS. */
2042 virtual_base_list_length (struct type *dclass)
2045 struct vbase *tmp_vbase;
2047 current_vbase_list = NULL;
2048 virtual_base_list_aux (dclass);
2050 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2055 /* Return the number of elements of the virtual base list of the type
2056 DCLASS, ignoring those appearing in the primary base (and its
2057 primary base, recursively). */
2060 virtual_base_list_length_skip_primaries (struct type *dclass)
2063 struct vbase *tmp_vbase;
2064 struct type *primary;
2066 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2069 return virtual_base_list_length (dclass);
2071 current_vbase_list = NULL;
2072 virtual_base_list_aux (dclass);
2074 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
2076 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
2084 /* Return the index (position) of type BASE, which is a virtual base
2085 class of DCLASS, in the latter's virtual base list. A return of -1
2086 indicates "not found" or a problem. */
2089 virtual_base_index (struct type *base, struct type *dclass)
2094 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2095 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2099 vbase = virtual_base_list (dclass)[0];
2104 vbase = virtual_base_list (dclass)[++i];
2107 return vbase ? i : -1;
2112 /* Return the index (position) of type BASE, which is a virtual base
2113 class of DCLASS, in the latter's virtual base list. Skip over all
2114 bases that may appear in the virtual base list of the primary base
2115 class of DCLASS (recursively). A return of -1 indicates "not
2116 found" or a problem. */
2119 virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
2123 struct type *primary;
2125 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2126 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2129 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2133 vbase = virtual_base_list (dclass)[0];
2136 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2140 vbase = virtual_base_list (dclass)[++i];
2143 return vbase ? j : -1;
2146 /* Return position of a derived class DCLASS in the list of
2147 * primary bases starting with the remotest ancestor.
2148 * Position returned is 0-based. */
2151 class_index_in_primary_list (struct type *dclass)
2153 struct type *pbc; /* primary base class */
2155 /* Simply recurse on primary base */
2156 pbc = TYPE_PRIMARY_BASE (dclass);
2158 return 1 + class_index_in_primary_list (pbc);
2163 /* Return a count of the number of virtual functions a type has.
2164 * This includes all the virtual functions it inherits from its
2168 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2169 * functions only once (latest redefinition)
2173 count_virtual_fns (struct type *dclass)
2175 int fn, oi; /* function and overloaded instance indices */
2176 int vfuncs; /* count to return */
2178 /* recurse on bases that can share virtual table */
2179 struct type *pbc = primary_base_class (dclass);
2181 vfuncs = count_virtual_fns (pbc);
2185 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2186 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2187 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2195 /* Functions for overload resolution begin here */
2197 /* Compare two badness vectors A and B and return the result.
2198 * 0 => A and B are identical
2199 * 1 => A and B are incomparable
2200 * 2 => A is better than B
2201 * 3 => A is worse than B */
2204 compare_badness (struct badness_vector *a, struct badness_vector *b)
2208 short found_pos = 0; /* any positives in c? */
2209 short found_neg = 0; /* any negatives in c? */
2211 /* differing lengths => incomparable */
2212 if (a->length != b->length)
2215 /* Subtract b from a */
2216 for (i = 0; i < a->length; i++)
2218 tmp = a->rank[i] - b->rank[i];
2228 return 1; /* incomparable */
2230 return 3; /* A > B */
2236 return 2; /* A < B */
2238 return 0; /* A == B */
2242 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2243 * to the types of an argument list (ARGS, length NARGS).
2244 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2246 struct badness_vector *
2247 rank_function (struct type **parms, int nparms, struct type **args, int nargs)
2250 struct badness_vector *bv;
2251 int min_len = nparms < nargs ? nparms : nargs;
2253 bv = xmalloc (sizeof (struct badness_vector));
2254 bv->length = nargs + 1; /* add 1 for the length-match rank */
2255 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2257 /* First compare the lengths of the supplied lists.
2258 * If there is a mismatch, set it to a high value. */
2260 /* pai/1997-06-03 FIXME: when we have debug info about default
2261 * arguments and ellipsis parameter lists, we should consider those
2262 * and rank the length-match more finely. */
2264 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2266 /* Now rank all the parameters of the candidate function */
2267 for (i = 1; i <= min_len; i++)
2268 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2270 /* If more arguments than parameters, add dummy entries */
2271 for (i = min_len + 1; i <= nargs; i++)
2272 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2277 /* Compare the names of two integer types, assuming that any sign
2278 qualifiers have been checked already. We do it this way because
2279 there may be an "int" in the name of one of the types. */
2282 integer_types_same_name_p (const char *first, const char *second)
2284 int first_p, second_p;
2286 /* If both are shorts, return 1; if neither is a short, keep checking. */
2287 first_p = (strstr (first, "short") != NULL);
2288 second_p = (strstr (second, "short") != NULL);
2289 if (first_p && second_p)
2291 if (first_p || second_p)
2294 /* Likewise for long. */
2295 first_p = (strstr (first, "long") != NULL);
2296 second_p = (strstr (second, "long") != NULL);
2297 if (first_p && second_p)
2299 if (first_p || second_p)
2302 /* Likewise for char. */
2303 first_p = (strstr (first, "char") != NULL);
2304 second_p = (strstr (second, "char") != NULL);
2305 if (first_p && second_p)
2307 if (first_p || second_p)
2310 /* They must both be ints. */
2314 /* Compare one type (PARM) for compatibility with another (ARG).
2315 * PARM is intended to be the parameter type of a function; and
2316 * ARG is the supplied argument's type. This function tests if
2317 * the latter can be converted to the former.
2319 * Return 0 if they are identical types;
2320 * Otherwise, return an integer which corresponds to how compatible
2321 * PARM is to ARG. The higher the return value, the worse the match.
2322 * Generally the "bad" conversions are all uniformly assigned a 100 */
2325 rank_one_type (struct type *parm, struct type *arg)
2327 /* Identical type pointers */
2328 /* However, this still doesn't catch all cases of same type for arg
2329 * and param. The reason is that builtin types are different from
2330 * the same ones constructed from the object. */
2334 /* Resolve typedefs */
2335 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2336 parm = check_typedef (parm);
2337 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2338 arg = check_typedef (arg);
2341 Well, damnit, if the names are exactly the same,
2342 i'll say they are exactly the same. This happens when we generate
2343 method stubs. The types won't point to the same address, but they
2344 really are the same.
2347 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2348 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2351 /* Check if identical after resolving typedefs */
2355 /* See through references, since we can almost make non-references
2357 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2358 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2359 + REFERENCE_CONVERSION_BADNESS);
2360 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2361 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2362 + REFERENCE_CONVERSION_BADNESS);
2364 /* Debugging only. */
2365 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2366 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2368 /* x -> y means arg of type x being supplied for parameter of type y */
2370 switch (TYPE_CODE (parm))
2373 switch (TYPE_CODE (arg))
2376 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2377 return VOID_PTR_CONVERSION_BADNESS;
2379 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2380 case TYPE_CODE_ARRAY:
2381 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2382 case TYPE_CODE_FUNC:
2383 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2385 case TYPE_CODE_ENUM:
2386 case TYPE_CODE_CHAR:
2387 case TYPE_CODE_RANGE:
2388 case TYPE_CODE_BOOL:
2389 return POINTER_CONVERSION_BADNESS;
2391 return INCOMPATIBLE_TYPE_BADNESS;
2393 case TYPE_CODE_ARRAY:
2394 switch (TYPE_CODE (arg))
2397 case TYPE_CODE_ARRAY:
2398 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2400 return INCOMPATIBLE_TYPE_BADNESS;
2402 case TYPE_CODE_FUNC:
2403 switch (TYPE_CODE (arg))
2405 case TYPE_CODE_PTR: /* funcptr -> func */
2406 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2408 return INCOMPATIBLE_TYPE_BADNESS;
2411 switch (TYPE_CODE (arg))
2414 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2416 /* Deal with signed, unsigned, and plain chars and
2417 signed and unsigned ints */
2418 if (TYPE_NOSIGN (parm))
2420 /* This case only for character types */
2421 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2424 return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */
2426 else if (TYPE_UNSIGNED (parm))
2428 if (TYPE_UNSIGNED (arg))
2430 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2431 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2433 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2434 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
2435 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2437 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
2441 if (integer_types_same_name_p (TYPE_NAME (arg), "long")
2442 && integer_types_same_name_p (TYPE_NAME (parm), "int"))
2443 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
2445 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2448 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2450 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2452 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2453 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
2454 return INTEGER_PROMOTION_BADNESS;
2456 return INTEGER_CONVERSION_BADNESS;
2459 return INTEGER_CONVERSION_BADNESS;
2461 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2462 return INTEGER_PROMOTION_BADNESS;
2464 return INTEGER_CONVERSION_BADNESS;
2465 case TYPE_CODE_ENUM:
2466 case TYPE_CODE_CHAR:
2467 case TYPE_CODE_RANGE:
2468 case TYPE_CODE_BOOL:
2469 return INTEGER_PROMOTION_BADNESS;
2471 return INT_FLOAT_CONVERSION_BADNESS;
2473 return NS_POINTER_CONVERSION_BADNESS;
2475 return INCOMPATIBLE_TYPE_BADNESS;
2478 case TYPE_CODE_ENUM:
2479 switch (TYPE_CODE (arg))
2482 case TYPE_CODE_CHAR:
2483 case TYPE_CODE_RANGE:
2484 case TYPE_CODE_BOOL:
2485 case TYPE_CODE_ENUM:
2486 return INTEGER_CONVERSION_BADNESS;
2488 return INT_FLOAT_CONVERSION_BADNESS;
2490 return INCOMPATIBLE_TYPE_BADNESS;
2493 case TYPE_CODE_CHAR:
2494 switch (TYPE_CODE (arg))
2496 case TYPE_CODE_RANGE:
2497 case TYPE_CODE_BOOL:
2498 case TYPE_CODE_ENUM:
2499 return INTEGER_CONVERSION_BADNESS;
2501 return INT_FLOAT_CONVERSION_BADNESS;
2503 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2504 return INTEGER_CONVERSION_BADNESS;
2505 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2506 return INTEGER_PROMOTION_BADNESS;
2507 /* >>> !! else fall through !! <<< */
2508 case TYPE_CODE_CHAR:
2509 /* Deal with signed, unsigned, and plain chars for C++
2510 and with int cases falling through from previous case */
2511 if (TYPE_NOSIGN (parm))
2513 if (TYPE_NOSIGN (arg))
2516 return INTEGER_CONVERSION_BADNESS;
2518 else if (TYPE_UNSIGNED (parm))
2520 if (TYPE_UNSIGNED (arg))
2523 return INTEGER_PROMOTION_BADNESS;
2525 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2528 return INTEGER_CONVERSION_BADNESS;
2530 return INCOMPATIBLE_TYPE_BADNESS;
2533 case TYPE_CODE_RANGE:
2534 switch (TYPE_CODE (arg))
2537 case TYPE_CODE_CHAR:
2538 case TYPE_CODE_RANGE:
2539 case TYPE_CODE_BOOL:
2540 case TYPE_CODE_ENUM:
2541 return INTEGER_CONVERSION_BADNESS;
2543 return INT_FLOAT_CONVERSION_BADNESS;
2545 return INCOMPATIBLE_TYPE_BADNESS;
2548 case TYPE_CODE_BOOL:
2549 switch (TYPE_CODE (arg))
2552 case TYPE_CODE_CHAR:
2553 case TYPE_CODE_RANGE:
2554 case TYPE_CODE_ENUM:
2557 return BOOLEAN_CONVERSION_BADNESS;
2558 case TYPE_CODE_BOOL:
2561 return INCOMPATIBLE_TYPE_BADNESS;
2565 switch (TYPE_CODE (arg))
2568 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2569 return FLOAT_PROMOTION_BADNESS;
2570 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2573 return FLOAT_CONVERSION_BADNESS;
2575 case TYPE_CODE_BOOL:
2576 case TYPE_CODE_ENUM:
2577 case TYPE_CODE_RANGE:
2578 case TYPE_CODE_CHAR:
2579 return INT_FLOAT_CONVERSION_BADNESS;
2581 return INCOMPATIBLE_TYPE_BADNESS;
2584 case TYPE_CODE_COMPLEX:
2585 switch (TYPE_CODE (arg))
2586 { /* Strictly not needed for C++, but... */
2588 return FLOAT_PROMOTION_BADNESS;
2589 case TYPE_CODE_COMPLEX:
2592 return INCOMPATIBLE_TYPE_BADNESS;
2595 case TYPE_CODE_STRUCT:
2596 /* currently same as TYPE_CODE_CLASS */
2597 switch (TYPE_CODE (arg))
2599 case TYPE_CODE_STRUCT:
2600 /* Check for derivation */
2601 if (is_ancestor (parm, arg))
2602 return BASE_CONVERSION_BADNESS;
2603 /* else fall through */
2605 return INCOMPATIBLE_TYPE_BADNESS;
2608 case TYPE_CODE_UNION:
2609 switch (TYPE_CODE (arg))
2611 case TYPE_CODE_UNION:
2613 return INCOMPATIBLE_TYPE_BADNESS;
2616 case TYPE_CODE_MEMBER:
2617 switch (TYPE_CODE (arg))
2620 return INCOMPATIBLE_TYPE_BADNESS;
2623 case TYPE_CODE_METHOD:
2624 switch (TYPE_CODE (arg))
2628 return INCOMPATIBLE_TYPE_BADNESS;
2632 switch (TYPE_CODE (arg))
2636 return INCOMPATIBLE_TYPE_BADNESS;
2641 switch (TYPE_CODE (arg))
2645 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2647 return INCOMPATIBLE_TYPE_BADNESS;
2650 case TYPE_CODE_VOID:
2652 return INCOMPATIBLE_TYPE_BADNESS;
2653 } /* switch (TYPE_CODE (arg)) */
2657 /* End of functions for overload resolution */
2660 print_bit_vector (B_TYPE *bits, int nbits)
2664 for (bitno = 0; bitno < nbits; bitno++)
2666 if ((bitno % 8) == 0)
2668 puts_filtered (" ");
2670 if (B_TST (bits, bitno))
2672 printf_filtered ("1");
2676 printf_filtered ("0");
2681 /* Note the first arg should be the "this" pointer, we may not want to
2682 include it since we may get into a infinitely recursive situation. */
2685 print_arg_types (struct field *args, int nargs, int spaces)
2691 for (i = 0; i < nargs; i++)
2692 recursive_dump_type (args[i].type, spaces + 2);
2697 dump_fn_fieldlists (struct type *type, int spaces)
2703 printfi_filtered (spaces, "fn_fieldlists ");
2704 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2705 printf_filtered ("\n");
2706 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2708 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2709 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2711 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2712 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2714 printf_filtered (") length %d\n",
2715 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2716 for (overload_idx = 0;
2717 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2720 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2722 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2723 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2725 printf_filtered (")\n");
2726 printfi_filtered (spaces + 8, "type ");
2727 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2728 printf_filtered ("\n");
2730 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2733 printfi_filtered (spaces + 8, "args ");
2734 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2735 printf_filtered ("\n");
2737 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2738 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2740 printfi_filtered (spaces + 8, "fcontext ");
2741 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2743 printf_filtered ("\n");
2745 printfi_filtered (spaces + 8, "is_const %d\n",
2746 TYPE_FN_FIELD_CONST (f, overload_idx));
2747 printfi_filtered (spaces + 8, "is_volatile %d\n",
2748 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2749 printfi_filtered (spaces + 8, "is_private %d\n",
2750 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2751 printfi_filtered (spaces + 8, "is_protected %d\n",
2752 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2753 printfi_filtered (spaces + 8, "is_stub %d\n",
2754 TYPE_FN_FIELD_STUB (f, overload_idx));
2755 printfi_filtered (spaces + 8, "voffset %u\n",
2756 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2762 print_cplus_stuff (struct type *type, int spaces)
2764 printfi_filtered (spaces, "n_baseclasses %d\n",
2765 TYPE_N_BASECLASSES (type));
2766 printfi_filtered (spaces, "nfn_fields %d\n",
2767 TYPE_NFN_FIELDS (type));
2768 printfi_filtered (spaces, "nfn_fields_total %d\n",
2769 TYPE_NFN_FIELDS_TOTAL (type));
2770 if (TYPE_N_BASECLASSES (type) > 0)
2772 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2773 TYPE_N_BASECLASSES (type));
2774 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2775 printf_filtered (")");
2777 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2778 TYPE_N_BASECLASSES (type));
2779 puts_filtered ("\n");
2781 if (TYPE_NFIELDS (type) > 0)
2783 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2785 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2786 TYPE_NFIELDS (type));
2787 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2788 printf_filtered (")");
2789 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2790 TYPE_NFIELDS (type));
2791 puts_filtered ("\n");
2793 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2795 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2796 TYPE_NFIELDS (type));
2797 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2798 printf_filtered (")");
2799 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2800 TYPE_NFIELDS (type));
2801 puts_filtered ("\n");
2804 if (TYPE_NFN_FIELDS (type) > 0)
2806 dump_fn_fieldlists (type, spaces);
2811 print_bound_type (int bt)
2815 case BOUND_CANNOT_BE_DETERMINED:
2816 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2818 case BOUND_BY_REF_ON_STACK:
2819 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2821 case BOUND_BY_VALUE_ON_STACK:
2822 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2824 case BOUND_BY_REF_IN_REG:
2825 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2827 case BOUND_BY_VALUE_IN_REG:
2828 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2831 printf_filtered ("(BOUND_SIMPLE)");
2834 printf_filtered ("(unknown bound type)");
2839 static struct obstack dont_print_type_obstack;
2842 recursive_dump_type (struct type *type, int spaces)
2847 obstack_begin (&dont_print_type_obstack, 0);
2849 if (TYPE_NFIELDS (type) > 0
2850 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2852 struct type **first_dont_print
2853 = (struct type **) obstack_base (&dont_print_type_obstack);
2855 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2860 if (type == first_dont_print[i])
2862 printfi_filtered (spaces, "type node ");
2863 gdb_print_host_address (type, gdb_stdout);
2864 printf_filtered (" <same as already seen type>\n");
2869 obstack_ptr_grow (&dont_print_type_obstack, type);
2872 printfi_filtered (spaces, "type node ");
2873 gdb_print_host_address (type, gdb_stdout);
2874 printf_filtered ("\n");
2875 printfi_filtered (spaces, "name '%s' (",
2876 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2877 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2878 printf_filtered (")\n");
2879 printfi_filtered (spaces, "tagname '%s' (",
2880 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2881 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2882 printf_filtered (")\n");
2883 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2884 switch (TYPE_CODE (type))
2886 case TYPE_CODE_UNDEF:
2887 printf_filtered ("(TYPE_CODE_UNDEF)");
2890 printf_filtered ("(TYPE_CODE_PTR)");
2892 case TYPE_CODE_ARRAY:
2893 printf_filtered ("(TYPE_CODE_ARRAY)");
2895 case TYPE_CODE_STRUCT:
2896 printf_filtered ("(TYPE_CODE_STRUCT)");
2898 case TYPE_CODE_UNION:
2899 printf_filtered ("(TYPE_CODE_UNION)");
2901 case TYPE_CODE_ENUM:
2902 printf_filtered ("(TYPE_CODE_ENUM)");
2904 case TYPE_CODE_FUNC:
2905 printf_filtered ("(TYPE_CODE_FUNC)");
2908 printf_filtered ("(TYPE_CODE_INT)");
2911 printf_filtered ("(TYPE_CODE_FLT)");
2913 case TYPE_CODE_VOID:
2914 printf_filtered ("(TYPE_CODE_VOID)");
2917 printf_filtered ("(TYPE_CODE_SET)");
2919 case TYPE_CODE_RANGE:
2920 printf_filtered ("(TYPE_CODE_RANGE)");
2922 case TYPE_CODE_STRING:
2923 printf_filtered ("(TYPE_CODE_STRING)");
2925 case TYPE_CODE_BITSTRING:
2926 printf_filtered ("(TYPE_CODE_BITSTRING)");
2928 case TYPE_CODE_ERROR:
2929 printf_filtered ("(TYPE_CODE_ERROR)");
2931 case TYPE_CODE_MEMBER:
2932 printf_filtered ("(TYPE_CODE_MEMBER)");
2934 case TYPE_CODE_METHOD:
2935 printf_filtered ("(TYPE_CODE_METHOD)");
2938 printf_filtered ("(TYPE_CODE_REF)");
2940 case TYPE_CODE_CHAR:
2941 printf_filtered ("(TYPE_CODE_CHAR)");
2943 case TYPE_CODE_BOOL:
2944 printf_filtered ("(TYPE_CODE_BOOL)");
2946 case TYPE_CODE_COMPLEX:
2947 printf_filtered ("(TYPE_CODE_COMPLEX)");
2949 case TYPE_CODE_TYPEDEF:
2950 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2952 case TYPE_CODE_TEMPLATE:
2953 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2955 case TYPE_CODE_TEMPLATE_ARG:
2956 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2958 case TYPE_CODE_NAMESPACE:
2959 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2962 printf_filtered ("(UNKNOWN TYPE CODE)");
2965 puts_filtered ("\n");
2966 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2967 printfi_filtered (spaces, "upper_bound_type 0x%x ",
2968 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2969 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2970 puts_filtered ("\n");
2971 printfi_filtered (spaces, "lower_bound_type 0x%x ",
2972 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2973 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2974 puts_filtered ("\n");
2975 printfi_filtered (spaces, "objfile ");
2976 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2977 printf_filtered ("\n");
2978 printfi_filtered (spaces, "target_type ");
2979 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2980 printf_filtered ("\n");
2981 if (TYPE_TARGET_TYPE (type) != NULL)
2983 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2985 printfi_filtered (spaces, "pointer_type ");
2986 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2987 printf_filtered ("\n");
2988 printfi_filtered (spaces, "reference_type ");
2989 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2990 printf_filtered ("\n");
2991 printfi_filtered (spaces, "type_chain ");
2992 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
2993 printf_filtered ("\n");
2994 printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
2995 if (TYPE_CONST (type))
2997 puts_filtered (" TYPE_FLAG_CONST");
2999 if (TYPE_VOLATILE (type))
3001 puts_filtered (" TYPE_FLAG_VOLATILE");
3003 if (TYPE_CODE_SPACE (type))
3005 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3007 if (TYPE_DATA_SPACE (type))
3009 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3011 if (TYPE_ADDRESS_CLASS_1 (type))
3013 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3015 if (TYPE_ADDRESS_CLASS_2 (type))
3017 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3019 puts_filtered ("\n");
3020 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
3021 if (TYPE_UNSIGNED (type))
3023 puts_filtered (" TYPE_FLAG_UNSIGNED");
3025 if (TYPE_NOSIGN (type))
3027 puts_filtered (" TYPE_FLAG_NOSIGN");
3029 if (TYPE_STUB (type))
3031 puts_filtered (" TYPE_FLAG_STUB");
3033 if (TYPE_TARGET_STUB (type))
3035 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3037 if (TYPE_STATIC (type))
3039 puts_filtered (" TYPE_FLAG_STATIC");
3041 if (TYPE_PROTOTYPED (type))
3043 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3045 if (TYPE_INCOMPLETE (type))
3047 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3049 if (TYPE_VARARGS (type))
3051 puts_filtered (" TYPE_FLAG_VARARGS");
3053 /* This is used for things like AltiVec registers on ppc. Gcc emits
3054 an attribute for the array type, which tells whether or not we
3055 have a vector, instead of a regular array. */
3056 if (TYPE_VECTOR (type))
3058 puts_filtered (" TYPE_FLAG_VECTOR");
3060 puts_filtered ("\n");
3061 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3062 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3063 puts_filtered ("\n");
3064 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3066 printfi_filtered (spaces + 2,
3067 "[%d] bitpos %d bitsize %d type ",
3068 idx, TYPE_FIELD_BITPOS (type, idx),
3069 TYPE_FIELD_BITSIZE (type, idx));
3070 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3071 printf_filtered (" name '%s' (",
3072 TYPE_FIELD_NAME (type, idx) != NULL
3073 ? TYPE_FIELD_NAME (type, idx)
3075 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3076 printf_filtered (")\n");
3077 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3079 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3082 printfi_filtered (spaces, "vptr_basetype ");
3083 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3084 puts_filtered ("\n");
3085 if (TYPE_VPTR_BASETYPE (type) != NULL)
3087 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3089 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3090 switch (TYPE_CODE (type))
3092 case TYPE_CODE_STRUCT:
3093 printfi_filtered (spaces, "cplus_stuff ");
3094 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3095 puts_filtered ("\n");
3096 print_cplus_stuff (type, spaces);
3100 printfi_filtered (spaces, "floatformat ");
3101 if (TYPE_FLOATFORMAT (type) == NULL
3102 || TYPE_FLOATFORMAT (type)->name == NULL)
3103 puts_filtered ("(null)");
3105 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3106 puts_filtered ("\n");
3110 /* We have to pick one of the union types to be able print and test
3111 the value. Pick cplus_struct_type, even though we know it isn't
3112 any particular one. */
3113 printfi_filtered (spaces, "type_specific ");
3114 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3115 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3117 printf_filtered (" (unknown data form)");
3119 printf_filtered ("\n");
3124 obstack_free (&dont_print_type_obstack, NULL);
3127 static void build_gdbtypes (void);
3129 build_gdbtypes (void)
3132 init_type (TYPE_CODE_VOID, 1,
3134 "void", (struct objfile *) NULL);
3136 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3138 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
3139 "char", (struct objfile *) NULL);
3140 builtin_type_true_char =
3141 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3143 "true character", (struct objfile *) NULL);
3144 builtin_type_signed_char =
3145 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3147 "signed char", (struct objfile *) NULL);
3148 builtin_type_unsigned_char =
3149 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3151 "unsigned char", (struct objfile *) NULL);
3152 builtin_type_short =
3153 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3155 "short", (struct objfile *) NULL);
3156 builtin_type_unsigned_short =
3157 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3159 "unsigned short", (struct objfile *) NULL);
3161 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3163 "int", (struct objfile *) NULL);
3164 builtin_type_unsigned_int =
3165 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3167 "unsigned int", (struct objfile *) NULL);
3169 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3171 "long", (struct objfile *) NULL);
3172 builtin_type_unsigned_long =
3173 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3175 "unsigned long", (struct objfile *) NULL);
3176 builtin_type_long_long =
3177 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3179 "long long", (struct objfile *) NULL);
3180 builtin_type_unsigned_long_long =
3181 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3183 "unsigned long long", (struct objfile *) NULL);
3184 builtin_type_float =
3185 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3187 "float", (struct objfile *) NULL);
3189 The below lines are disabled since they are doing the wrong
3190 thing for non-multiarch targets. They are setting the correct
3191 type of floats for the target but while on multiarch targets
3192 this is done everytime the architecture changes, it's done on
3193 non-multiarch targets only on startup, leaving the wrong values
3194 in even if the architecture changes (eg. from big-endian to
3197 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
3199 builtin_type_double =
3200 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3202 "double", (struct objfile *) NULL);
3204 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
3206 builtin_type_long_double =
3207 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3209 "long double", (struct objfile *) NULL);
3211 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
3213 builtin_type_complex =
3214 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3216 "complex", (struct objfile *) NULL);
3217 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3218 builtin_type_double_complex =
3219 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3221 "double complex", (struct objfile *) NULL);
3222 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3223 builtin_type_string =
3224 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3226 "string", (struct objfile *) NULL);
3228 init_type (TYPE_CODE_INT, 0 / 8,
3230 "int0_t", (struct objfile *) NULL);
3232 init_type (TYPE_CODE_INT, 8 / 8,
3234 "int8_t", (struct objfile *) NULL);
3235 builtin_type_uint8 =
3236 init_type (TYPE_CODE_INT, 8 / 8,
3238 "uint8_t", (struct objfile *) NULL);
3239 builtin_type_int16 =
3240 init_type (TYPE_CODE_INT, 16 / 8,
3242 "int16_t", (struct objfile *) NULL);
3243 builtin_type_uint16 =
3244 init_type (TYPE_CODE_INT, 16 / 8,
3246 "uint16_t", (struct objfile *) NULL);
3247 builtin_type_int32 =
3248 init_type (TYPE_CODE_INT, 32 / 8,
3250 "int32_t", (struct objfile *) NULL);
3251 builtin_type_uint32 =
3252 init_type (TYPE_CODE_INT, 32 / 8,
3254 "uint32_t", (struct objfile *) NULL);
3255 builtin_type_int64 =
3256 init_type (TYPE_CODE_INT, 64 / 8,
3258 "int64_t", (struct objfile *) NULL);
3259 builtin_type_uint64 =
3260 init_type (TYPE_CODE_INT, 64 / 8,
3262 "uint64_t", (struct objfile *) NULL);
3263 builtin_type_int128 =
3264 init_type (TYPE_CODE_INT, 128 / 8,
3266 "int128_t", (struct objfile *) NULL);
3267 builtin_type_uint128 =
3268 init_type (TYPE_CODE_INT, 128 / 8,
3270 "uint128_t", (struct objfile *) NULL);
3272 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3274 "bool", (struct objfile *) NULL);
3276 /* Add user knob for controlling resolution of opaque types */
3278 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
3279 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3282 opaque_type_resolution = 1;
3284 /* Build SIMD types. */
3286 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
3288 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
3290 = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
3292 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
3294 = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
3296 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3298 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
3300 /* 128 bit vectors. */
3301 builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
3302 builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3303 builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
3304 builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3305 builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3306 builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3307 /* 64 bit vectors. */
3308 builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
3309 builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3310 builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3311 builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
3314 builtin_type_vec64 = build_builtin_type_vec64 ();
3315 builtin_type_vec64i = build_builtin_type_vec64i ();
3316 builtin_type_vec128 = build_builtin_type_vec128 ();
3317 builtin_type_vec128i = build_builtin_type_vec128i ();
3319 /* Pointer/Address types. */
3321 /* NOTE: on some targets, addresses and pointers are not necessarily
3322 the same --- for example, on the D10V, pointers are 16 bits long,
3323 but addresses are 32 bits long. See doc/gdbint.texinfo,
3324 ``Pointers Are Not Always Addresses''.
3327 - gdb's `struct type' always describes the target's
3329 - gdb's `struct value' objects should always hold values in
3331 - gdb's CORE_ADDR values are addresses in the unified virtual
3332 address space that the assembler and linker work with. Thus,
3333 since target_read_memory takes a CORE_ADDR as an argument, it
3334 can access any memory on the target, even if the processor has
3335 separate code and data address spaces.
3338 - If v is a value holding a D10V code pointer, its contents are
3339 in target form: a big-endian address left-shifted two bits.
3340 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3341 sizeof (void *) == 2 on the target.
3343 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3344 target type for a value the target will never see. It's only
3345 used to hold the values of (typeless) linker symbols, which are
3346 indeed in the unified virtual address space. */
3347 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
3348 builtin_type_void_func_ptr
3349 = lookup_pointer_type (lookup_function_type (builtin_type_void));
3350 builtin_type_CORE_ADDR =
3351 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
3353 "__CORE_ADDR", (struct objfile *) NULL);
3354 builtin_type_bfd_vma =
3355 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3357 "__bfd_vma", (struct objfile *) NULL);
3360 extern void _initialize_gdbtypes (void);
3362 _initialize_gdbtypes (void)
3364 struct cmd_list_element *c;
3367 /* FIXME - For the moment, handle types by swapping them in and out.
3368 Should be using the per-architecture data-pointer and a large
3370 register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL);
3371 register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL);
3372 register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL);
3373 register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL);
3374 register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL);
3375 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL);
3376 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL);
3377 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL);
3378 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL);
3379 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL);
3380 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL);
3381 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL);
3382 register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL);
3383 register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL);
3384 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL);
3385 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL);
3386 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL);
3387 register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL);
3388 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL);
3389 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL);
3390 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL);
3391 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL);
3392 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL);
3393 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
3394 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
3395 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
3396 register_gdbarch_swap (&builtin_type_int128, sizeof (struct type *), NULL);
3397 register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type *), NULL);
3398 register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
3399 register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL);
3400 register_gdbarch_swap (&builtin_type_v16qi, sizeof (struct type *), NULL);
3401 register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL);
3402 register_gdbarch_swap (&builtin_type_v8hi, sizeof (struct type *), NULL);
3403 register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
3404 register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
3405 register_gdbarch_swap (&builtin_type_v2_double, sizeof (struct type *), NULL);
3406 register_gdbarch_swap (&builtin_type_v4_float, sizeof (struct type *), NULL);
3407 register_gdbarch_swap (&builtin_type_v2_int64, sizeof (struct type *), NULL);
3408 register_gdbarch_swap (&builtin_type_v4_int32, sizeof (struct type *), NULL);
3409 register_gdbarch_swap (&builtin_type_v8_int16, sizeof (struct type *), NULL);
3410 register_gdbarch_swap (&builtin_type_v16_int8, sizeof (struct type *), NULL);
3411 register_gdbarch_swap (&builtin_type_v2_float, sizeof (struct type *), NULL);
3412 register_gdbarch_swap (&builtin_type_v2_int32, sizeof (struct type *), NULL);
3413 register_gdbarch_swap (&builtin_type_v8_int8, sizeof (struct type *), NULL);
3414 register_gdbarch_swap (&builtin_type_v4_int16, sizeof (struct type *), NULL);
3415 register_gdbarch_swap (&builtin_type_vec128, sizeof (struct type *), NULL);
3416 register_gdbarch_swap (&builtin_type_vec128i, sizeof (struct type *), NULL);
3417 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3418 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3419 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3420 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3421 register_gdbarch_swap (NULL, 0, build_gdbtypes);
3423 /* Note: These types do not need to be swapped - they are target
3425 builtin_type_ieee_single_big =
3426 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3427 0, "builtin_type_ieee_single_big", NULL);
3428 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3429 builtin_type_ieee_single_little =
3430 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3431 0, "builtin_type_ieee_single_little", NULL);
3432 TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
3433 builtin_type_ieee_double_big =
3434 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3435 0, "builtin_type_ieee_double_big", NULL);
3436 TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
3437 builtin_type_ieee_double_little =
3438 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3439 0, "builtin_type_ieee_double_little", NULL);
3440 TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
3441 builtin_type_ieee_double_littlebyte_bigword =
3442 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3443 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
3444 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
3445 builtin_type_i387_ext =
3446 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3447 0, "builtin_type_i387_ext", NULL);
3448 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
3449 builtin_type_m68881_ext =
3450 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3451 0, "builtin_type_m68881_ext", NULL);
3452 TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
3453 builtin_type_i960_ext =
3454 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3455 0, "builtin_type_i960_ext", NULL);
3456 TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
3457 builtin_type_m88110_ext =
3458 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3459 0, "builtin_type_m88110_ext", NULL);
3460 TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
3461 builtin_type_m88110_harris_ext =
3462 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3463 0, "builtin_type_m88110_harris_ext", NULL);
3464 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
3465 builtin_type_arm_ext_big =
3466 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3467 0, "builtin_type_arm_ext_big", NULL);
3468 TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
3469 builtin_type_arm_ext_littlebyte_bigword =
3470 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3471 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
3472 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
3473 builtin_type_ia64_spill_big =
3474 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3475 0, "builtin_type_ia64_spill_big", NULL);
3476 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
3477 builtin_type_ia64_spill_little =
3478 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3479 0, "builtin_type_ia64_spill_little", NULL);
3480 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
3481 builtin_type_ia64_quad_big =
3482 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3483 0, "builtin_type_ia64_quad_big", NULL);
3484 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
3485 builtin_type_ia64_quad_little =
3486 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3487 0, "builtin_type_ia64_quad_little", NULL);
3488 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
3491 add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
3492 "Set debugging of C++ overloading.\n\
3493 When enabled, ranking of the functions\n\
3494 is displayed.", &setdebuglist),