1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2014 Free Software Foundation, Inc.
5 Contributed by Cygnus Support, using pieces from other GDB modules.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 #include "expression.h"
34 #include "complaints.h"
38 #include "exceptions.h"
39 #include "cp-support.h"
41 #include "dwarf2loc.h"
44 /* Initialize BADNESS constants. */
46 const struct rank LENGTH_MISMATCH_BADNESS = {100,0};
48 const struct rank TOO_FEW_PARAMS_BADNESS = {100,0};
49 const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0};
51 const struct rank EXACT_MATCH_BADNESS = {0,0};
53 const struct rank INTEGER_PROMOTION_BADNESS = {1,0};
54 const struct rank FLOAT_PROMOTION_BADNESS = {1,0};
55 const struct rank BASE_PTR_CONVERSION_BADNESS = {1,0};
56 const struct rank INTEGER_CONVERSION_BADNESS = {2,0};
57 const struct rank FLOAT_CONVERSION_BADNESS = {2,0};
58 const struct rank INT_FLOAT_CONVERSION_BADNESS = {2,0};
59 const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0};
60 const struct rank BOOL_CONVERSION_BADNESS = {3,0};
61 const struct rank BASE_CONVERSION_BADNESS = {2,0};
62 const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
63 const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
64 const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
65 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
67 /* Floatformat pairs. */
68 const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
69 &floatformat_ieee_half_big,
70 &floatformat_ieee_half_little
72 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
73 &floatformat_ieee_single_big,
74 &floatformat_ieee_single_little
76 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
77 &floatformat_ieee_double_big,
78 &floatformat_ieee_double_little
80 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
81 &floatformat_ieee_double_big,
82 &floatformat_ieee_double_littlebyte_bigword
84 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
85 &floatformat_i387_ext,
88 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
89 &floatformat_m68881_ext,
90 &floatformat_m68881_ext
92 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
93 &floatformat_arm_ext_big,
94 &floatformat_arm_ext_littlebyte_bigword
96 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
97 &floatformat_ia64_spill_big,
98 &floatformat_ia64_spill_little
100 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
101 &floatformat_ia64_quad_big,
102 &floatformat_ia64_quad_little
104 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
108 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
112 const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
113 &floatformat_ibm_long_double_big,
114 &floatformat_ibm_long_double_little
117 /* Should opaque types be resolved? */
119 static int opaque_type_resolution = 1;
121 /* A flag to enable printing of debugging information of C++
124 unsigned int overload_debug = 0;
126 /* A flag to enable strict type checking. */
128 static int strict_type_checking = 1;
130 /* A function to show whether opaque types are resolved. */
133 show_opaque_type_resolution (struct ui_file *file, int from_tty,
134 struct cmd_list_element *c,
137 fprintf_filtered (file, _("Resolution of opaque struct/class/union types "
138 "(if set before loading symbols) is %s.\n"),
142 /* A function to show whether C++ overload debugging is enabled. */
145 show_overload_debug (struct ui_file *file, int from_tty,
146 struct cmd_list_element *c, const char *value)
148 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
152 /* A function to show the status of strict type checking. */
155 show_strict_type_checking (struct ui_file *file, int from_tty,
156 struct cmd_list_element *c, const char *value)
158 fprintf_filtered (file, _("Strict type checking is %s.\n"), value);
162 /* Allocate a new OBJFILE-associated type structure and fill it
163 with some defaults. Space for the type structure is allocated
164 on the objfile's objfile_obstack. */
167 alloc_type (struct objfile *objfile)
171 gdb_assert (objfile != NULL);
173 /* Alloc the structure and start off with all fields zeroed. */
174 type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
175 TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
177 OBJSTAT (objfile, n_types++);
179 TYPE_OBJFILE_OWNED (type) = 1;
180 TYPE_OWNER (type).objfile = objfile;
182 /* Initialize the fields that might not be zero. */
184 TYPE_CODE (type) = TYPE_CODE_UNDEF;
185 TYPE_VPTR_FIELDNO (type) = -1;
186 TYPE_CHAIN (type) = type; /* Chain back to itself. */
191 /* Allocate a new GDBARCH-associated type structure and fill it
192 with some defaults. Space for the type structure is allocated
196 alloc_type_arch (struct gdbarch *gdbarch)
200 gdb_assert (gdbarch != NULL);
202 /* Alloc the structure and start off with all fields zeroed. */
204 type = XCNEW (struct type);
205 TYPE_MAIN_TYPE (type) = XCNEW (struct main_type);
207 TYPE_OBJFILE_OWNED (type) = 0;
208 TYPE_OWNER (type).gdbarch = gdbarch;
210 /* Initialize the fields that might not be zero. */
212 TYPE_CODE (type) = TYPE_CODE_UNDEF;
213 TYPE_VPTR_FIELDNO (type) = -1;
214 TYPE_CHAIN (type) = type; /* Chain back to itself. */
219 /* If TYPE is objfile-associated, allocate a new type structure
220 associated with the same objfile. If TYPE is gdbarch-associated,
221 allocate a new type structure associated with the same gdbarch. */
224 alloc_type_copy (const struct type *type)
226 if (TYPE_OBJFILE_OWNED (type))
227 return alloc_type (TYPE_OWNER (type).objfile);
229 return alloc_type_arch (TYPE_OWNER (type).gdbarch);
232 /* If TYPE is gdbarch-associated, return that architecture.
233 If TYPE is objfile-associated, return that objfile's architecture. */
236 get_type_arch (const struct type *type)
238 if (TYPE_OBJFILE_OWNED (type))
239 return get_objfile_arch (TYPE_OWNER (type).objfile);
241 return TYPE_OWNER (type).gdbarch;
244 /* See gdbtypes.h. */
247 get_target_type (struct type *type)
251 type = TYPE_TARGET_TYPE (type);
253 type = check_typedef (type);
259 /* Alloc a new type instance structure, fill it with some defaults,
260 and point it at OLDTYPE. Allocate the new type instance from the
261 same place as OLDTYPE. */
264 alloc_type_instance (struct type *oldtype)
268 /* Allocate the structure. */
270 if (! TYPE_OBJFILE_OWNED (oldtype))
271 type = XCNEW (struct type);
273 type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
276 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
278 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
283 /* Clear all remnants of the previous type at TYPE, in preparation for
284 replacing it with something else. Preserve owner information. */
287 smash_type (struct type *type)
289 int objfile_owned = TYPE_OBJFILE_OWNED (type);
290 union type_owner owner = TYPE_OWNER (type);
292 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
294 /* Restore owner information. */
295 TYPE_OBJFILE_OWNED (type) = objfile_owned;
296 TYPE_OWNER (type) = owner;
298 /* For now, delete the rings. */
299 TYPE_CHAIN (type) = type;
301 /* For now, leave the pointer/reference types alone. */
304 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
305 to a pointer to memory where the pointer type should be stored.
306 If *TYPEPTR is zero, update it to point to the pointer type we return.
307 We allocate new memory if needed. */
310 make_pointer_type (struct type *type, struct type **typeptr)
312 struct type *ntype; /* New type */
315 ntype = TYPE_POINTER_TYPE (type);
320 return ntype; /* Don't care about alloc,
321 and have new type. */
322 else if (*typeptr == 0)
324 *typeptr = ntype; /* Tracking alloc, and have new type. */
329 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
331 ntype = alloc_type_copy (type);
335 else /* We have storage, but need to reset it. */
338 chain = TYPE_CHAIN (ntype);
340 TYPE_CHAIN (ntype) = chain;
343 TYPE_TARGET_TYPE (ntype) = type;
344 TYPE_POINTER_TYPE (type) = ntype;
346 /* FIXME! Assumes the machine has only one representation for pointers! */
349 = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
350 TYPE_CODE (ntype) = TYPE_CODE_PTR;
352 /* Mark pointers as unsigned. The target converts between pointers
353 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
354 gdbarch_address_to_pointer. */
355 TYPE_UNSIGNED (ntype) = 1;
357 /* Update the length of all the other variants of this type. */
358 chain = TYPE_CHAIN (ntype);
359 while (chain != ntype)
361 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
362 chain = TYPE_CHAIN (chain);
368 /* Given a type TYPE, return a type of pointers to that type.
369 May need to construct such a type if this is the first use. */
372 lookup_pointer_type (struct type *type)
374 return make_pointer_type (type, (struct type **) 0);
377 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
378 points to a pointer to memory where the reference type should be
379 stored. If *TYPEPTR is zero, update it to point to the reference
380 type we return. We allocate new memory if needed. */
383 make_reference_type (struct type *type, struct type **typeptr)
385 struct type *ntype; /* New type */
388 ntype = TYPE_REFERENCE_TYPE (type);
393 return ntype; /* Don't care about alloc,
394 and have new type. */
395 else if (*typeptr == 0)
397 *typeptr = ntype; /* Tracking alloc, and have new type. */
402 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
404 ntype = alloc_type_copy (type);
408 else /* We have storage, but need to reset it. */
411 chain = TYPE_CHAIN (ntype);
413 TYPE_CHAIN (ntype) = chain;
416 TYPE_TARGET_TYPE (ntype) = type;
417 TYPE_REFERENCE_TYPE (type) = ntype;
419 /* FIXME! Assume the machine has only one representation for
420 references, and that it matches the (only) representation for
423 TYPE_LENGTH (ntype) =
424 gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
425 TYPE_CODE (ntype) = TYPE_CODE_REF;
427 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
428 TYPE_REFERENCE_TYPE (type) = ntype;
430 /* Update the length of all the other variants of this type. */
431 chain = TYPE_CHAIN (ntype);
432 while (chain != ntype)
434 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
435 chain = TYPE_CHAIN (chain);
441 /* Same as above, but caller doesn't care about memory allocation
445 lookup_reference_type (struct type *type)
447 return make_reference_type (type, (struct type **) 0);
450 /* Lookup a function type that returns type TYPE. TYPEPTR, if
451 nonzero, points to a pointer to memory where the function type
452 should be stored. If *TYPEPTR is zero, update it to point to the
453 function type we return. We allocate new memory if needed. */
456 make_function_type (struct type *type, struct type **typeptr)
458 struct type *ntype; /* New type */
460 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
462 ntype = alloc_type_copy (type);
466 else /* We have storage, but need to reset it. */
472 TYPE_TARGET_TYPE (ntype) = type;
474 TYPE_LENGTH (ntype) = 1;
475 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
477 INIT_FUNC_SPECIFIC (ntype);
482 /* Given a type TYPE, return a type of functions that return that type.
483 May need to construct such a type if this is the first use. */
486 lookup_function_type (struct type *type)
488 return make_function_type (type, (struct type **) 0);
491 /* Given a type TYPE and argument types, return the appropriate
492 function type. If the final type in PARAM_TYPES is NULL, make a
496 lookup_function_type_with_arguments (struct type *type,
498 struct type **param_types)
500 struct type *fn = make_function_type (type, (struct type **) 0);
505 if (param_types[nparams - 1] == NULL)
508 TYPE_VARARGS (fn) = 1;
510 else if (TYPE_CODE (check_typedef (param_types[nparams - 1]))
514 /* Caller should have ensured this. */
515 gdb_assert (nparams == 0);
516 TYPE_PROTOTYPED (fn) = 1;
520 TYPE_NFIELDS (fn) = nparams;
521 TYPE_FIELDS (fn) = TYPE_ZALLOC (fn, nparams * sizeof (struct field));
522 for (i = 0; i < nparams; ++i)
523 TYPE_FIELD_TYPE (fn, i) = param_types[i];
528 /* Identify address space identifier by name --
529 return the integer flag defined in gdbtypes.h. */
532 address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
536 /* Check for known address space delimiters. */
537 if (!strcmp (space_identifier, "code"))
538 return TYPE_INSTANCE_FLAG_CODE_SPACE;
539 else if (!strcmp (space_identifier, "data"))
540 return TYPE_INSTANCE_FLAG_DATA_SPACE;
541 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
542 && gdbarch_address_class_name_to_type_flags (gdbarch,
547 error (_("Unknown address space specifier: \"%s\""), space_identifier);
550 /* Identify address space identifier by integer flag as defined in
551 gdbtypes.h -- return the string version of the adress space name. */
554 address_space_int_to_name (struct gdbarch *gdbarch, int space_flag)
556 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
558 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
560 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
561 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
562 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
567 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
569 If STORAGE is non-NULL, create the new type instance there.
570 STORAGE must be in the same obstack as TYPE. */
573 make_qualified_type (struct type *type, int new_flags,
574 struct type *storage)
581 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
583 ntype = TYPE_CHAIN (ntype);
585 while (ntype != type);
587 /* Create a new type instance. */
589 ntype = alloc_type_instance (type);
592 /* If STORAGE was provided, it had better be in the same objfile
593 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
594 if one objfile is freed and the other kept, we'd have
595 dangling pointers. */
596 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
599 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
600 TYPE_CHAIN (ntype) = ntype;
603 /* Pointers or references to the original type are not relevant to
605 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
606 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
608 /* Chain the new qualified type to the old type. */
609 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
610 TYPE_CHAIN (type) = ntype;
612 /* Now set the instance flags and return the new type. */
613 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
615 /* Set length of new type to that of the original type. */
616 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
621 /* Make an address-space-delimited variant of a type -- a type that
622 is identical to the one supplied except that it has an address
623 space attribute attached to it (such as "code" or "data").
625 The space attributes "code" and "data" are for Harvard
626 architectures. The address space attributes are for architectures
627 which have alternately sized pointers or pointers with alternate
631 make_type_with_address_space (struct type *type, int space_flag)
633 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
634 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
635 | TYPE_INSTANCE_FLAG_DATA_SPACE
636 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
639 return make_qualified_type (type, new_flags, NULL);
642 /* Make a "c-v" variant of a type -- a type that is identical to the
643 one supplied except that it may have const or volatile attributes
644 CNST is a flag for setting the const attribute
645 VOLTL is a flag for setting the volatile attribute
646 TYPE is the base type whose variant we are creating.
648 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
649 storage to hold the new qualified type; *TYPEPTR and TYPE must be
650 in the same objfile. Otherwise, allocate fresh memory for the new
651 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
652 new type we construct. */
655 make_cv_type (int cnst, int voltl,
657 struct type **typeptr)
659 struct type *ntype; /* New type */
661 int new_flags = (TYPE_INSTANCE_FLAGS (type)
662 & ~(TYPE_INSTANCE_FLAG_CONST
663 | TYPE_INSTANCE_FLAG_VOLATILE));
666 new_flags |= TYPE_INSTANCE_FLAG_CONST;
669 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
671 if (typeptr && *typeptr != NULL)
673 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
674 a C-V variant chain that threads across objfiles: if one
675 objfile gets freed, then the other has a broken C-V chain.
677 This code used to try to copy over the main type from TYPE to
678 *TYPEPTR if they were in different objfiles, but that's
679 wrong, too: TYPE may have a field list or member function
680 lists, which refer to types of their own, etc. etc. The
681 whole shebang would need to be copied over recursively; you
682 can't have inter-objfile pointers. The only thing to do is
683 to leave stub types as stub types, and look them up afresh by
684 name each time you encounter them. */
685 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
688 ntype = make_qualified_type (type, new_flags,
689 typeptr ? *typeptr : NULL);
697 /* Make a 'restrict'-qualified version of TYPE. */
700 make_restrict_type (struct type *type)
702 return make_qualified_type (type,
703 (TYPE_INSTANCE_FLAGS (type)
704 | TYPE_INSTANCE_FLAG_RESTRICT),
708 /* Replace the contents of ntype with the type *type. This changes the
709 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
710 the changes are propogated to all types in the TYPE_CHAIN.
712 In order to build recursive types, it's inevitable that we'll need
713 to update types in place --- but this sort of indiscriminate
714 smashing is ugly, and needs to be replaced with something more
715 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
716 clear if more steps are needed. */
719 replace_type (struct type *ntype, struct type *type)
723 /* These two types had better be in the same objfile. Otherwise,
724 the assignment of one type's main type structure to the other
725 will produce a type with references to objects (names; field
726 lists; etc.) allocated on an objfile other than its own. */
727 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
729 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
731 /* The type length is not a part of the main type. Update it for
732 each type on the variant chain. */
736 /* Assert that this element of the chain has no address-class bits
737 set in its flags. Such type variants might have type lengths
738 which are supposed to be different from the non-address-class
739 variants. This assertion shouldn't ever be triggered because
740 symbol readers which do construct address-class variants don't
741 call replace_type(). */
742 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
744 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
745 chain = TYPE_CHAIN (chain);
747 while (ntype != chain);
749 /* Assert that the two types have equivalent instance qualifiers.
750 This should be true for at least all of our debug readers. */
751 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
754 /* Implement direct support for MEMBER_TYPE in GNU C++.
755 May need to construct such a type if this is the first use.
756 The TYPE is the type of the member. The DOMAIN is the type
757 of the aggregate that the member belongs to. */
760 lookup_memberptr_type (struct type *type, struct type *domain)
764 mtype = alloc_type_copy (type);
765 smash_to_memberptr_type (mtype, domain, type);
769 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
772 lookup_methodptr_type (struct type *to_type)
776 mtype = alloc_type_copy (to_type);
777 smash_to_methodptr_type (mtype, to_type);
781 /* Allocate a stub method whose return type is TYPE. This apparently
782 happens for speed of symbol reading, since parsing out the
783 arguments to the method is cpu-intensive, the way we are doing it.
784 So, we will fill in arguments later. This always returns a fresh
788 allocate_stub_method (struct type *type)
792 mtype = alloc_type_copy (type);
793 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
794 TYPE_LENGTH (mtype) = 1;
795 TYPE_STUB (mtype) = 1;
796 TYPE_TARGET_TYPE (mtype) = type;
797 /* _DOMAIN_TYPE (mtype) = unknown yet */
801 /* Create a range type with a dynamic range from LOW_BOUND to
802 HIGH_BOUND, inclusive. See create_range_type for further details. */
805 create_range_type (struct type *result_type, struct type *index_type,
806 const struct dynamic_prop *low_bound,
807 const struct dynamic_prop *high_bound)
809 if (result_type == NULL)
810 result_type = alloc_type_copy (index_type);
811 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
812 TYPE_TARGET_TYPE (result_type) = index_type;
813 if (TYPE_STUB (index_type))
814 TYPE_TARGET_STUB (result_type) = 1;
816 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
818 TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
819 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
820 TYPE_RANGE_DATA (result_type)->low = *low_bound;
821 TYPE_RANGE_DATA (result_type)->high = *high_bound;
823 if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
824 TYPE_UNSIGNED (result_type) = 1;
829 /* Create a range type using either a blank type supplied in
830 RESULT_TYPE, or creating a new type, inheriting the objfile from
833 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
834 to HIGH_BOUND, inclusive.
836 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
837 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
840 create_static_range_type (struct type *result_type, struct type *index_type,
841 LONGEST low_bound, LONGEST high_bound)
843 struct dynamic_prop low, high;
845 low.kind = PROP_CONST;
846 low.data.const_val = low_bound;
848 high.kind = PROP_CONST;
849 high.data.const_val = high_bound;
851 result_type = create_range_type (result_type, index_type, &low, &high);
856 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
857 are static, otherwise returns 0. */
860 has_static_range (const struct range_bounds *bounds)
862 return (bounds->low.kind == PROP_CONST
863 && bounds->high.kind == PROP_CONST);
867 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
868 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
869 bounds will fit in LONGEST), or -1 otherwise. */
872 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
874 CHECK_TYPEDEF (type);
875 switch (TYPE_CODE (type))
877 case TYPE_CODE_RANGE:
878 *lowp = TYPE_LOW_BOUND (type);
879 *highp = TYPE_HIGH_BOUND (type);
882 if (TYPE_NFIELDS (type) > 0)
884 /* The enums may not be sorted by value, so search all
888 *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
889 for (i = 0; i < TYPE_NFIELDS (type); i++)
891 if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
892 *lowp = TYPE_FIELD_ENUMVAL (type, i);
893 if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
894 *highp = TYPE_FIELD_ENUMVAL (type, i);
897 /* Set unsigned indicator if warranted. */
900 TYPE_UNSIGNED (type) = 1;
914 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
916 if (!TYPE_UNSIGNED (type))
918 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
922 /* ... fall through for unsigned ints ... */
925 /* This round-about calculation is to avoid shifting by
926 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
927 if TYPE_LENGTH (type) == sizeof (LONGEST). */
928 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
929 *highp = (*highp - 1) | *highp;
936 /* Assuming TYPE is a simple, non-empty array type, compute its upper
937 and lower bound. Save the low bound into LOW_BOUND if not NULL.
938 Save the high bound into HIGH_BOUND if not NULL.
940 Return 1 if the operation was successful. Return zero otherwise,
941 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
943 We now simply use get_discrete_bounds call to get the values
944 of the low and high bounds.
945 get_discrete_bounds can return three values:
946 1, meaning that index is a range,
947 0, meaning that index is a discrete type,
948 or -1 for failure. */
951 get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
953 struct type *index = TYPE_INDEX_TYPE (type);
961 res = get_discrete_bounds (index, &low, &high);
965 /* Check if the array bounds are undefined. */
967 && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
968 || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
980 /* Create an array type using either a blank type supplied in
981 RESULT_TYPE, or creating a new type, inheriting the objfile from
984 Elements will be of type ELEMENT_TYPE, the indices will be of type
987 If BIT_STRIDE is not zero, build a packed array type whose element
988 size is BIT_STRIDE. Otherwise, ignore this parameter.
990 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
991 sure it is TYPE_CODE_UNDEF before we bash it into an array
995 create_array_type_with_stride (struct type *result_type,
996 struct type *element_type,
997 struct type *range_type,
998 unsigned int bit_stride)
1000 if (result_type == NULL)
1001 result_type = alloc_type_copy (range_type);
1003 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
1004 TYPE_TARGET_TYPE (result_type) = element_type;
1005 if (has_static_range (TYPE_RANGE_DATA (range_type)))
1007 LONGEST low_bound, high_bound;
1009 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
1010 low_bound = high_bound = 0;
1011 CHECK_TYPEDEF (element_type);
1012 /* Be careful when setting the array length. Ada arrays can be
1013 empty arrays with the high_bound being smaller than the low_bound.
1014 In such cases, the array length should be zero. */
1015 if (high_bound < low_bound)
1016 TYPE_LENGTH (result_type) = 0;
1017 else if (bit_stride > 0)
1018 TYPE_LENGTH (result_type) =
1019 (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
1021 TYPE_LENGTH (result_type) =
1022 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
1026 /* This type is dynamic and its length needs to be computed
1027 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1028 undefined by setting it to zero. Although we are not expected
1029 to trust TYPE_LENGTH in this case, setting the size to zero
1030 allows us to avoid allocating objects of random sizes in case
1031 we accidently do. */
1032 TYPE_LENGTH (result_type) = 0;
1035 TYPE_NFIELDS (result_type) = 1;
1036 TYPE_FIELDS (result_type) =
1037 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
1038 TYPE_INDEX_TYPE (result_type) = range_type;
1039 TYPE_VPTR_FIELDNO (result_type) = -1;
1041 TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride;
1043 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */
1044 if (TYPE_LENGTH (result_type) == 0)
1045 TYPE_TARGET_STUB (result_type) = 1;
1050 /* Same as create_array_type_with_stride but with no bit_stride
1051 (BIT_STRIDE = 0), thus building an unpacked array. */
1054 create_array_type (struct type *result_type,
1055 struct type *element_type,
1056 struct type *range_type)
1058 return create_array_type_with_stride (result_type, element_type,
1063 lookup_array_range_type (struct type *element_type,
1064 LONGEST low_bound, LONGEST high_bound)
1066 struct gdbarch *gdbarch = get_type_arch (element_type);
1067 struct type *index_type = builtin_type (gdbarch)->builtin_int;
1068 struct type *range_type
1069 = create_static_range_type (NULL, index_type, low_bound, high_bound);
1071 return create_array_type (NULL, element_type, range_type);
1074 /* Create a string type using either a blank type supplied in
1075 RESULT_TYPE, or creating a new type. String types are similar
1076 enough to array of char types that we can use create_array_type to
1077 build the basic type and then bash it into a string type.
1079 For fixed length strings, the range type contains 0 as the lower
1080 bound and the length of the string minus one as the upper bound.
1082 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1083 sure it is TYPE_CODE_UNDEF before we bash it into a string
1087 create_string_type (struct type *result_type,
1088 struct type *string_char_type,
1089 struct type *range_type)
1091 result_type = create_array_type (result_type,
1094 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1099 lookup_string_range_type (struct type *string_char_type,
1100 LONGEST low_bound, LONGEST high_bound)
1102 struct type *result_type;
1104 result_type = lookup_array_range_type (string_char_type,
1105 low_bound, high_bound);
1106 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1111 create_set_type (struct type *result_type, struct type *domain_type)
1113 if (result_type == NULL)
1114 result_type = alloc_type_copy (domain_type);
1116 TYPE_CODE (result_type) = TYPE_CODE_SET;
1117 TYPE_NFIELDS (result_type) = 1;
1118 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
1120 if (!TYPE_STUB (domain_type))
1122 LONGEST low_bound, high_bound, bit_length;
1124 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
1125 low_bound = high_bound = 0;
1126 bit_length = high_bound - low_bound + 1;
1127 TYPE_LENGTH (result_type)
1128 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1130 TYPE_UNSIGNED (result_type) = 1;
1132 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
1137 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1138 and any array types nested inside it. */
1141 make_vector_type (struct type *array_type)
1143 struct type *inner_array, *elt_type;
1146 /* Find the innermost array type, in case the array is
1147 multi-dimensional. */
1148 inner_array = array_type;
1149 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
1150 inner_array = TYPE_TARGET_TYPE (inner_array);
1152 elt_type = TYPE_TARGET_TYPE (inner_array);
1153 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
1155 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT;
1156 elt_type = make_qualified_type (elt_type, flags, NULL);
1157 TYPE_TARGET_TYPE (inner_array) = elt_type;
1160 TYPE_VECTOR (array_type) = 1;
1164 init_vector_type (struct type *elt_type, int n)
1166 struct type *array_type;
1168 array_type = lookup_array_range_type (elt_type, 0, n - 1);
1169 make_vector_type (array_type);
1173 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
1174 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1175 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1176 TYPE doesn't include the offset (that's the value of the MEMBER
1177 itself), but does include the structure type into which it points
1180 When "smashing" the type, we preserve the objfile that the old type
1181 pointed to, since we aren't changing where the type is actually
1185 smash_to_memberptr_type (struct type *type, struct type *domain,
1186 struct type *to_type)
1189 TYPE_TARGET_TYPE (type) = to_type;
1190 TYPE_DOMAIN_TYPE (type) = domain;
1191 /* Assume that a data member pointer is the same size as a normal
1194 = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT;
1195 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
1198 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1200 When "smashing" the type, we preserve the objfile that the old type
1201 pointed to, since we aren't changing where the type is actually
1205 smash_to_methodptr_type (struct type *type, struct type *to_type)
1208 TYPE_TARGET_TYPE (type) = to_type;
1209 TYPE_DOMAIN_TYPE (type) = TYPE_DOMAIN_TYPE (to_type);
1210 TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
1211 TYPE_CODE (type) = TYPE_CODE_METHODPTR;
1214 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1215 METHOD just means `function that gets an extra "this" argument'.
1217 When "smashing" the type, we preserve the objfile that the old type
1218 pointed to, since we aren't changing where the type is actually
1222 smash_to_method_type (struct type *type, struct type *domain,
1223 struct type *to_type, struct field *args,
1224 int nargs, int varargs)
1227 TYPE_TARGET_TYPE (type) = to_type;
1228 TYPE_DOMAIN_TYPE (type) = domain;
1229 TYPE_FIELDS (type) = args;
1230 TYPE_NFIELDS (type) = nargs;
1232 TYPE_VARARGS (type) = 1;
1233 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1234 TYPE_CODE (type) = TYPE_CODE_METHOD;
1237 /* Return a typename for a struct/union/enum type without "struct ",
1238 "union ", or "enum ". If the type has a NULL name, return NULL. */
1241 type_name_no_tag (const struct type *type)
1243 if (TYPE_TAG_NAME (type) != NULL)
1244 return TYPE_TAG_NAME (type);
1246 /* Is there code which expects this to return the name if there is
1247 no tag name? My guess is that this is mainly used for C++ in
1248 cases where the two will always be the same. */
1249 return TYPE_NAME (type);
1252 /* A wrapper of type_name_no_tag which calls error if the type is anonymous.
1253 Since GCC PR debug/47510 DWARF provides associated information to detect the
1254 anonymous class linkage name from its typedef.
1256 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1260 type_name_no_tag_or_error (struct type *type)
1262 struct type *saved_type = type;
1264 struct objfile *objfile;
1266 CHECK_TYPEDEF (type);
1268 name = type_name_no_tag (type);
1272 name = type_name_no_tag (saved_type);
1273 objfile = TYPE_OBJFILE (saved_type);
1274 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1275 name ? name : "<anonymous>",
1276 objfile ? objfile_name (objfile) : "<arch>");
1279 /* Lookup a typedef or primitive type named NAME, visible in lexical
1280 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1281 suitably defined. */
1284 lookup_typename (const struct language_defn *language,
1285 struct gdbarch *gdbarch, const char *name,
1286 const struct block *block, int noerr)
1291 sym = lookup_symbol (name, block, VAR_DOMAIN, 0);
1292 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1293 return SYMBOL_TYPE (sym);
1295 type = language_lookup_primitive_type_by_name (language, gdbarch, name);
1301 error (_("No type named %s."), name);
1305 lookup_unsigned_typename (const struct language_defn *language,
1306 struct gdbarch *gdbarch, const char *name)
1308 char *uns = alloca (strlen (name) + 10);
1310 strcpy (uns, "unsigned ");
1311 strcpy (uns + 9, name);
1312 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0);
1316 lookup_signed_typename (const struct language_defn *language,
1317 struct gdbarch *gdbarch, const char *name)
1320 char *uns = alloca (strlen (name) + 8);
1322 strcpy (uns, "signed ");
1323 strcpy (uns + 7, name);
1324 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1);
1325 /* If we don't find "signed FOO" just try again with plain "FOO". */
1328 return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0);
1331 /* Lookup a structure type named "struct NAME",
1332 visible in lexical block BLOCK. */
1335 lookup_struct (const char *name, const struct block *block)
1339 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1343 error (_("No struct type named %s."), name);
1345 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1347 error (_("This context has class, union or enum %s, not a struct."),
1350 return (SYMBOL_TYPE (sym));
1353 /* Lookup a union type named "union NAME",
1354 visible in lexical block BLOCK. */
1357 lookup_union (const char *name, const struct block *block)
1362 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1365 error (_("No union type named %s."), name);
1367 t = SYMBOL_TYPE (sym);
1369 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1372 /* If we get here, it's not a union. */
1373 error (_("This context has class, struct or enum %s, not a union."),
1377 /* Lookup an enum type named "enum NAME",
1378 visible in lexical block BLOCK. */
1381 lookup_enum (const char *name, const struct block *block)
1385 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1388 error (_("No enum type named %s."), name);
1390 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1392 error (_("This context has class, struct or union %s, not an enum."),
1395 return (SYMBOL_TYPE (sym));
1398 /* Lookup a template type named "template NAME<TYPE>",
1399 visible in lexical block BLOCK. */
1402 lookup_template_type (char *name, struct type *type,
1403 const struct block *block)
1406 char *nam = (char *)
1407 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1411 strcat (nam, TYPE_NAME (type));
1412 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1414 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0);
1418 error (_("No template type named %s."), name);
1420 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1422 error (_("This context has class, union or enum %s, not a struct."),
1425 return (SYMBOL_TYPE (sym));
1428 /* Given a type TYPE, lookup the type of the component of type named
1431 TYPE can be either a struct or union, or a pointer or reference to
1432 a struct or union. If it is a pointer or reference, its target
1433 type is automatically used. Thus '.' and '->' are interchangable,
1434 as specified for the definitions of the expression element types
1435 STRUCTOP_STRUCT and STRUCTOP_PTR.
1437 If NOERR is nonzero, return zero if NAME is not suitably defined.
1438 If NAME is the name of a baseclass type, return that type. */
1441 lookup_struct_elt_type (struct type *type, const char *name, int noerr)
1448 CHECK_TYPEDEF (type);
1449 if (TYPE_CODE (type) != TYPE_CODE_PTR
1450 && TYPE_CODE (type) != TYPE_CODE_REF)
1452 type = TYPE_TARGET_TYPE (type);
1455 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1456 && TYPE_CODE (type) != TYPE_CODE_UNION)
1458 typename = type_to_string (type);
1459 make_cleanup (xfree, typename);
1460 error (_("Type %s is not a structure or union type."), typename);
1464 /* FIXME: This change put in by Michael seems incorrect for the case
1465 where the structure tag name is the same as the member name.
1466 I.e. when doing "ptype bell->bar" for "struct foo { int bar; int
1467 foo; } bell;" Disabled by fnf. */
1471 typename = type_name_no_tag (type);
1472 if (typename != NULL && strcmp (typename, name) == 0)
1477 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1479 const char *t_field_name = TYPE_FIELD_NAME (type, i);
1481 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1483 return TYPE_FIELD_TYPE (type, i);
1485 else if (!t_field_name || *t_field_name == '\0')
1487 struct type *subtype
1488 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1);
1490 if (subtype != NULL)
1495 /* OK, it's not in this class. Recursively check the baseclasses. */
1496 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1500 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1512 typename = type_to_string (type);
1513 make_cleanup (xfree, typename);
1514 error (_("Type %s has no component named %s."), typename, name);
1517 /* Store in *MAX the largest number representable by unsigned integer type
1521 get_unsigned_type_max (struct type *type, ULONGEST *max)
1525 CHECK_TYPEDEF (type);
1526 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_UNSIGNED (type));
1527 gdb_assert (TYPE_LENGTH (type) <= sizeof (ULONGEST));
1529 /* Written this way to avoid overflow. */
1530 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1531 *max = ((((ULONGEST) 1 << (n - 1)) - 1) << 1) | 1;
1534 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1535 signed integer type TYPE. */
1538 get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max)
1542 CHECK_TYPEDEF (type);
1543 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && !TYPE_UNSIGNED (type));
1544 gdb_assert (TYPE_LENGTH (type) <= sizeof (LONGEST));
1546 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1547 *min = -((ULONGEST) 1 << (n - 1));
1548 *max = ((ULONGEST) 1 << (n - 1)) - 1;
1551 /* Lookup the vptr basetype/fieldno values for TYPE.
1552 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1553 vptr_fieldno. Also, if found and basetype is from the same objfile,
1555 If not found, return -1 and ignore BASETYPEP.
1556 Callers should be aware that in some cases (for example,
1557 the type or one of its baseclasses is a stub type and we are
1558 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1559 this function will not be able to find the
1560 virtual function table pointer, and vptr_fieldno will remain -1 and
1561 vptr_basetype will remain NULL or incomplete. */
1564 get_vptr_fieldno (struct type *type, struct type **basetypep)
1566 CHECK_TYPEDEF (type);
1568 if (TYPE_VPTR_FIELDNO (type) < 0)
1572 /* We must start at zero in case the first (and only) baseclass
1573 is virtual (and hence we cannot share the table pointer). */
1574 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1576 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1578 struct type *basetype;
1580 fieldno = get_vptr_fieldno (baseclass, &basetype);
1583 /* If the type comes from a different objfile we can't cache
1584 it, it may have a different lifetime. PR 2384 */
1585 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
1587 TYPE_VPTR_FIELDNO (type) = fieldno;
1588 TYPE_VPTR_BASETYPE (type) = basetype;
1591 *basetypep = basetype;
1602 *basetypep = TYPE_VPTR_BASETYPE (type);
1603 return TYPE_VPTR_FIELDNO (type);
1608 stub_noname_complaint (void)
1610 complaint (&symfile_complaints, _("stub type has NULL name"));
1613 /* Worker for is_dynamic_type. */
1616 is_dynamic_type_internal (struct type *type, int top_level)
1618 type = check_typedef (type);
1620 /* We only want to recognize references at the outermost level. */
1621 if (top_level && TYPE_CODE (type) == TYPE_CODE_REF)
1622 type = check_typedef (TYPE_TARGET_TYPE (type));
1624 switch (TYPE_CODE (type))
1626 case TYPE_CODE_RANGE:
1627 return !has_static_range (TYPE_RANGE_DATA (type));
1629 case TYPE_CODE_ARRAY:
1631 gdb_assert (TYPE_NFIELDS (type) == 1);
1633 /* The array is dynamic if either the bounds are dynamic,
1634 or the elements it contains have a dynamic contents. */
1635 if (is_dynamic_type_internal (TYPE_INDEX_TYPE (type), 0))
1637 return is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0);
1640 case TYPE_CODE_STRUCT:
1641 case TYPE_CODE_UNION:
1645 for (i = 0; i < TYPE_NFIELDS (type); ++i)
1646 if (!field_is_static (&TYPE_FIELD (type, i))
1647 && is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i), 0))
1656 /* See gdbtypes.h. */
1659 is_dynamic_type (struct type *type)
1661 return is_dynamic_type_internal (type, 1);
1664 static struct type *resolve_dynamic_type_internal (struct type *type,
1668 /* Given a dynamic range type (dyn_range_type), return a static version
1671 static struct type *
1672 resolve_dynamic_range (struct type *dyn_range_type)
1675 struct type *static_range_type;
1676 const struct dynamic_prop *prop;
1677 const struct dwarf2_locexpr_baton *baton;
1678 struct dynamic_prop low_bound, high_bound;
1680 gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
1682 prop = &TYPE_RANGE_DATA (dyn_range_type)->low;
1683 if (dwarf2_evaluate_property (prop, &value))
1685 low_bound.kind = PROP_CONST;
1686 low_bound.data.const_val = value;
1690 low_bound.kind = PROP_UNDEFINED;
1691 low_bound.data.const_val = 0;
1694 prop = &TYPE_RANGE_DATA (dyn_range_type)->high;
1695 if (dwarf2_evaluate_property (prop, &value))
1697 high_bound.kind = PROP_CONST;
1698 high_bound.data.const_val = value;
1700 if (TYPE_RANGE_DATA (dyn_range_type)->flag_upper_bound_is_count)
1701 high_bound.data.const_val
1702 = low_bound.data.const_val + high_bound.data.const_val - 1;
1706 high_bound.kind = PROP_UNDEFINED;
1707 high_bound.data.const_val = 0;
1710 static_range_type = create_range_type (copy_type (dyn_range_type),
1711 TYPE_TARGET_TYPE (dyn_range_type),
1712 &low_bound, &high_bound);
1713 TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
1714 return static_range_type;
1717 /* Resolves dynamic bound values of an array type TYPE to static ones.
1718 ADDRESS might be needed to resolve the subrange bounds, it is the location
1719 of the associated array. */
1721 static struct type *
1722 resolve_dynamic_array (struct type *type)
1725 struct type *elt_type;
1726 struct type *range_type;
1727 struct type *ary_dim;
1729 gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY);
1732 range_type = check_typedef (TYPE_INDEX_TYPE (elt_type));
1733 range_type = resolve_dynamic_range (range_type);
1735 ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
1737 if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY)
1738 elt_type = resolve_dynamic_array (TYPE_TARGET_TYPE (type));
1740 elt_type = TYPE_TARGET_TYPE (type);
1742 return create_array_type (copy_type (type),
1747 /* Resolve dynamic bounds of members of the union TYPE to static
1750 static struct type *
1751 resolve_dynamic_union (struct type *type, CORE_ADDR addr)
1753 struct type *resolved_type;
1755 unsigned int max_len = 0;
1757 gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
1759 resolved_type = copy_type (type);
1760 TYPE_FIELDS (resolved_type)
1761 = TYPE_ALLOC (resolved_type,
1762 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1763 memcpy (TYPE_FIELDS (resolved_type),
1765 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1766 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
1770 if (field_is_static (&TYPE_FIELD (type, i)))
1773 t = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
1775 TYPE_FIELD_TYPE (resolved_type, i) = t;
1776 if (TYPE_LENGTH (t) > max_len)
1777 max_len = TYPE_LENGTH (t);
1780 TYPE_LENGTH (resolved_type) = max_len;
1781 return resolved_type;
1784 /* Resolve dynamic bounds of members of the struct TYPE to static
1787 static struct type *
1788 resolve_dynamic_struct (struct type *type, CORE_ADDR addr)
1790 struct type *resolved_type;
1792 unsigned resolved_type_bit_length = 0;
1794 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
1795 gdb_assert (TYPE_NFIELDS (type) > 0);
1797 resolved_type = copy_type (type);
1798 TYPE_FIELDS (resolved_type)
1799 = TYPE_ALLOC (resolved_type,
1800 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1801 memcpy (TYPE_FIELDS (resolved_type),
1803 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1804 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
1806 unsigned new_bit_length;
1808 if (field_is_static (&TYPE_FIELD (type, i)))
1811 TYPE_FIELD_TYPE (resolved_type, i)
1812 = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
1815 /* As we know this field is not a static field, the field's
1816 field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
1817 this is the case, but only trigger a simple error rather
1818 than an internal error if that fails. While failing
1819 that verification indicates a bug in our code, the error
1820 is not severe enough to suggest to the user he stops
1821 his debugging session because of it. */
1822 if (TYPE_FIELD_LOC_KIND (resolved_type, i) != FIELD_LOC_KIND_BITPOS)
1823 error (_("Cannot determine struct field location"
1824 " (invalid location kind)"));
1825 new_bit_length = TYPE_FIELD_BITPOS (resolved_type, i);
1826 if (TYPE_FIELD_BITSIZE (resolved_type, i) != 0)
1827 new_bit_length += TYPE_FIELD_BITSIZE (resolved_type, i);
1829 new_bit_length += (TYPE_LENGTH (TYPE_FIELD_TYPE (resolved_type, i))
1832 /* Normally, we would use the position and size of the last field
1833 to determine the size of the enclosing structure. But GCC seems
1834 to be encoding the position of some fields incorrectly when
1835 the struct contains a dynamic field that is not placed last.
1836 So we compute the struct size based on the field that has
1837 the highest position + size - probably the best we can do. */
1838 if (new_bit_length > resolved_type_bit_length)
1839 resolved_type_bit_length = new_bit_length;
1842 TYPE_LENGTH (resolved_type)
1843 = (resolved_type_bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1845 return resolved_type;
1848 /* Worker for resolved_dynamic_type. */
1850 static struct type *
1851 resolve_dynamic_type_internal (struct type *type, CORE_ADDR addr,
1854 struct type *real_type = check_typedef (type);
1855 struct type *resolved_type = type;
1857 if (!is_dynamic_type_internal (real_type, top_level))
1860 switch (TYPE_CODE (type))
1862 case TYPE_CODE_TYPEDEF:
1863 resolved_type = copy_type (type);
1864 TYPE_TARGET_TYPE (resolved_type)
1865 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr,
1871 CORE_ADDR target_addr = read_memory_typed_address (addr, type);
1873 resolved_type = copy_type (type);
1874 TYPE_TARGET_TYPE (resolved_type)
1875 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
1876 target_addr, top_level);
1880 case TYPE_CODE_ARRAY:
1881 resolved_type = resolve_dynamic_array (type);
1884 case TYPE_CODE_RANGE:
1885 resolved_type = resolve_dynamic_range (type);
1888 case TYPE_CODE_UNION:
1889 resolved_type = resolve_dynamic_union (type, addr);
1892 case TYPE_CODE_STRUCT:
1893 resolved_type = resolve_dynamic_struct (type, addr);
1897 return resolved_type;
1900 /* See gdbtypes.h */
1903 resolve_dynamic_type (struct type *type, CORE_ADDR addr)
1905 return resolve_dynamic_type_internal (type, addr, 1);
1908 /* Find the real type of TYPE. This function returns the real type,
1909 after removing all layers of typedefs, and completing opaque or stub
1910 types. Completion changes the TYPE argument, but stripping of
1913 Instance flags (e.g. const/volatile) are preserved as typedefs are
1914 stripped. If necessary a new qualified form of the underlying type
1917 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
1918 not been computed and we're either in the middle of reading symbols, or
1919 there was no name for the typedef in the debug info.
1921 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
1922 QUITs in the symbol reading code can also throw.
1923 Thus this function can throw an exception.
1925 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
1928 If this is a stubbed struct (i.e. declared as struct foo *), see if
1929 we can find a full definition in some other file. If so, copy this
1930 definition, so we can use it in future. There used to be a comment
1931 (but not any code) that if we don't find a full definition, we'd
1932 set a flag so we don't spend time in the future checking the same
1933 type. That would be a mistake, though--we might load in more
1934 symbols which contain a full definition for the type. */
1937 check_typedef (struct type *type)
1939 struct type *orig_type = type;
1940 /* While we're removing typedefs, we don't want to lose qualifiers.
1941 E.g., const/volatile. */
1942 int instance_flags = TYPE_INSTANCE_FLAGS (type);
1946 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1948 if (!TYPE_TARGET_TYPE (type))
1953 /* It is dangerous to call lookup_symbol if we are currently
1954 reading a symtab. Infinite recursion is one danger. */
1955 if (currently_reading_symtab)
1956 return make_qualified_type (type, instance_flags, NULL);
1958 name = type_name_no_tag (type);
1959 /* FIXME: shouldn't we separately check the TYPE_NAME and
1960 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1961 VAR_DOMAIN as appropriate? (this code was written before
1962 TYPE_NAME and TYPE_TAG_NAME were separate). */
1965 stub_noname_complaint ();
1966 return make_qualified_type (type, instance_flags, NULL);
1968 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1970 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1971 else /* TYPE_CODE_UNDEF */
1972 TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type));
1974 type = TYPE_TARGET_TYPE (type);
1976 /* Preserve the instance flags as we traverse down the typedef chain.
1978 Handling address spaces/classes is nasty, what do we do if there's a
1980 E.g., what if an outer typedef marks the type as class_1 and an inner
1981 typedef marks the type as class_2?
1982 This is the wrong place to do such error checking. We leave it to
1983 the code that created the typedef in the first place to flag the
1984 error. We just pick the outer address space (akin to letting the
1985 outer cast in a chain of casting win), instead of assuming
1986 "it can't happen". */
1988 const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE
1989 | TYPE_INSTANCE_FLAG_DATA_SPACE);
1990 const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
1991 int new_instance_flags = TYPE_INSTANCE_FLAGS (type);
1993 /* Treat code vs data spaces and address classes separately. */
1994 if ((instance_flags & ALL_SPACES) != 0)
1995 new_instance_flags &= ~ALL_SPACES;
1996 if ((instance_flags & ALL_CLASSES) != 0)
1997 new_instance_flags &= ~ALL_CLASSES;
1999 instance_flags |= new_instance_flags;
2003 /* If this is a struct/class/union with no fields, then check
2004 whether a full definition exists somewhere else. This is for
2005 systems where a type definition with no fields is issued for such
2006 types, instead of identifying them as stub types in the first
2009 if (TYPE_IS_OPAQUE (type)
2010 && opaque_type_resolution
2011 && !currently_reading_symtab)
2013 const char *name = type_name_no_tag (type);
2014 struct type *newtype;
2018 stub_noname_complaint ();
2019 return make_qualified_type (type, instance_flags, NULL);
2021 newtype = lookup_transparent_type (name);
2025 /* If the resolved type and the stub are in the same
2026 objfile, then replace the stub type with the real deal.
2027 But if they're in separate objfiles, leave the stub
2028 alone; we'll just look up the transparent type every time
2029 we call check_typedef. We can't create pointers between
2030 types allocated to different objfiles, since they may
2031 have different lifetimes. Trying to copy NEWTYPE over to
2032 TYPE's objfile is pointless, too, since you'll have to
2033 move over any other types NEWTYPE refers to, which could
2034 be an unbounded amount of stuff. */
2035 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
2036 type = make_qualified_type (newtype,
2037 TYPE_INSTANCE_FLAGS (type),
2043 /* Otherwise, rely on the stub flag being set for opaque/stubbed
2045 else if (TYPE_STUB (type) && !currently_reading_symtab)
2047 const char *name = type_name_no_tag (type);
2048 /* FIXME: shouldn't we separately check the TYPE_NAME and the
2049 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
2050 as appropriate? (this code was written before TYPE_NAME and
2051 TYPE_TAG_NAME were separate). */
2056 stub_noname_complaint ();
2057 return make_qualified_type (type, instance_flags, NULL);
2059 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
2062 /* Same as above for opaque types, we can replace the stub
2063 with the complete type only if they are in the same
2065 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
2066 type = make_qualified_type (SYMBOL_TYPE (sym),
2067 TYPE_INSTANCE_FLAGS (type),
2070 type = SYMBOL_TYPE (sym);
2074 if (TYPE_TARGET_STUB (type))
2076 struct type *range_type;
2077 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
2079 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
2081 /* Nothing we can do. */
2083 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
2085 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
2086 TYPE_TARGET_STUB (type) = 0;
2090 type = make_qualified_type (type, instance_flags, NULL);
2092 /* Cache TYPE_LENGTH for future use. */
2093 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
2098 /* Parse a type expression in the string [P..P+LENGTH). If an error
2099 occurs, silently return a void type. */
2101 static struct type *
2102 safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
2104 struct ui_file *saved_gdb_stderr;
2105 struct type *type = NULL; /* Initialize to keep gcc happy. */
2106 volatile struct gdb_exception except;
2108 /* Suppress error messages. */
2109 saved_gdb_stderr = gdb_stderr;
2110 gdb_stderr = ui_file_new ();
2112 /* Call parse_and_eval_type() without fear of longjmp()s. */
2113 TRY_CATCH (except, RETURN_MASK_ERROR)
2115 type = parse_and_eval_type (p, length);
2118 if (except.reason < 0)
2119 type = builtin_type (gdbarch)->builtin_void;
2121 /* Stop suppressing error messages. */
2122 ui_file_delete (gdb_stderr);
2123 gdb_stderr = saved_gdb_stderr;
2128 /* Ugly hack to convert method stubs into method types.
2130 He ain't kiddin'. This demangles the name of the method into a
2131 string including argument types, parses out each argument type,
2132 generates a string casting a zero to that type, evaluates the
2133 string, and stuffs the resulting type into an argtype vector!!!
2134 Then it knows the type of the whole function (including argument
2135 types for overloading), which info used to be in the stab's but was
2136 removed to hack back the space required for them. */
2139 check_stub_method (struct type *type, int method_id, int signature_id)
2141 struct gdbarch *gdbarch = get_type_arch (type);
2143 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
2144 char *demangled_name = gdb_demangle (mangled_name,
2145 DMGL_PARAMS | DMGL_ANSI);
2146 char *argtypetext, *p;
2147 int depth = 0, argcount = 1;
2148 struct field *argtypes;
2151 /* Make sure we got back a function string that we can use. */
2153 p = strchr (demangled_name, '(');
2157 if (demangled_name == NULL || p == NULL)
2158 error (_("Internal: Cannot demangle mangled name `%s'."),
2161 /* Now, read in the parameters that define this type. */
2166 if (*p == '(' || *p == '<')
2170 else if (*p == ')' || *p == '>')
2174 else if (*p == ',' && depth == 0)
2182 /* If we read one argument and it was ``void'', don't count it. */
2183 if (strncmp (argtypetext, "(void)", 6) == 0)
2186 /* We need one extra slot, for the THIS pointer. */
2188 argtypes = (struct field *)
2189 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
2192 /* Add THIS pointer for non-static methods. */
2193 f = TYPE_FN_FIELDLIST1 (type, method_id);
2194 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
2198 argtypes[0].type = lookup_pointer_type (type);
2202 if (*p != ')') /* () means no args, skip while. */
2207 if (depth <= 0 && (*p == ',' || *p == ')'))
2209 /* Avoid parsing of ellipsis, they will be handled below.
2210 Also avoid ``void'' as above. */
2211 if (strncmp (argtypetext, "...", p - argtypetext) != 0
2212 && strncmp (argtypetext, "void", p - argtypetext) != 0)
2214 argtypes[argcount].type =
2215 safe_parse_type (gdbarch, argtypetext, p - argtypetext);
2218 argtypetext = p + 1;
2221 if (*p == '(' || *p == '<')
2225 else if (*p == ')' || *p == '>')
2234 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
2236 /* Now update the old "stub" type into a real type. */
2237 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
2238 TYPE_DOMAIN_TYPE (mtype) = type;
2239 TYPE_FIELDS (mtype) = argtypes;
2240 TYPE_NFIELDS (mtype) = argcount;
2241 TYPE_STUB (mtype) = 0;
2242 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
2244 TYPE_VARARGS (mtype) = 1;
2246 xfree (demangled_name);
2249 /* This is the external interface to check_stub_method, above. This
2250 function unstubs all of the signatures for TYPE's METHOD_ID method
2251 name. After calling this function TYPE_FN_FIELD_STUB will be
2252 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
2255 This function unfortunately can not die until stabs do. */
2258 check_stub_method_group (struct type *type, int method_id)
2260 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
2261 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
2262 int j, found_stub = 0;
2264 for (j = 0; j < len; j++)
2265 if (TYPE_FN_FIELD_STUB (f, j))
2268 check_stub_method (type, method_id, j);
2271 /* GNU v3 methods with incorrect names were corrected when we read
2272 in type information, because it was cheaper to do it then. The
2273 only GNU v2 methods with incorrect method names are operators and
2274 destructors; destructors were also corrected when we read in type
2277 Therefore the only thing we need to handle here are v2 operator
2279 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
2282 char dem_opname[256];
2284 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2286 dem_opname, DMGL_ANSI);
2288 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2292 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
2296 /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
2297 const struct cplus_struct_type cplus_struct_default = { };
2300 allocate_cplus_struct_type (struct type *type)
2302 if (HAVE_CPLUS_STRUCT (type))
2303 /* Structure was already allocated. Nothing more to do. */
2306 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF;
2307 TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
2308 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
2309 *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default;
2312 const struct gnat_aux_type gnat_aux_default =
2315 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
2316 and allocate the associated gnat-specific data. The gnat-specific
2317 data is also initialized to gnat_aux_default. */
2320 allocate_gnat_aux_type (struct type *type)
2322 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF;
2323 TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *)
2324 TYPE_ALLOC (type, sizeof (struct gnat_aux_type));
2325 *(TYPE_GNAT_SPECIFIC (type)) = gnat_aux_default;
2328 /* Helper function to initialize the standard scalar types.
2330 If NAME is non-NULL, then it is used to initialize the type name.
2331 Note that NAME is not copied; it is required to have a lifetime at
2332 least as long as OBJFILE. */
2335 init_type (enum type_code code, int length, int flags,
2336 const char *name, struct objfile *objfile)
2340 type = alloc_type (objfile);
2341 TYPE_CODE (type) = code;
2342 TYPE_LENGTH (type) = length;
2344 gdb_assert (!(flags & (TYPE_FLAG_MIN - 1)));
2345 if (flags & TYPE_FLAG_UNSIGNED)
2346 TYPE_UNSIGNED (type) = 1;
2347 if (flags & TYPE_FLAG_NOSIGN)
2348 TYPE_NOSIGN (type) = 1;
2349 if (flags & TYPE_FLAG_STUB)
2350 TYPE_STUB (type) = 1;
2351 if (flags & TYPE_FLAG_TARGET_STUB)
2352 TYPE_TARGET_STUB (type) = 1;
2353 if (flags & TYPE_FLAG_STATIC)
2354 TYPE_STATIC (type) = 1;
2355 if (flags & TYPE_FLAG_PROTOTYPED)
2356 TYPE_PROTOTYPED (type) = 1;
2357 if (flags & TYPE_FLAG_INCOMPLETE)
2358 TYPE_INCOMPLETE (type) = 1;
2359 if (flags & TYPE_FLAG_VARARGS)
2360 TYPE_VARARGS (type) = 1;
2361 if (flags & TYPE_FLAG_VECTOR)
2362 TYPE_VECTOR (type) = 1;
2363 if (flags & TYPE_FLAG_STUB_SUPPORTED)
2364 TYPE_STUB_SUPPORTED (type) = 1;
2365 if (flags & TYPE_FLAG_FIXED_INSTANCE)
2366 TYPE_FIXED_INSTANCE (type) = 1;
2367 if (flags & TYPE_FLAG_GNU_IFUNC)
2368 TYPE_GNU_IFUNC (type) = 1;
2370 TYPE_NAME (type) = name;
2374 if (name && strcmp (name, "char") == 0)
2375 TYPE_NOSIGN (type) = 1;
2379 case TYPE_CODE_STRUCT:
2380 case TYPE_CODE_UNION:
2381 case TYPE_CODE_NAMESPACE:
2382 INIT_CPLUS_SPECIFIC (type);
2385 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT;
2387 case TYPE_CODE_FUNC:
2388 INIT_FUNC_SPECIFIC (type);
2394 /* Queries on types. */
2397 can_dereference (struct type *t)
2399 /* FIXME: Should we return true for references as well as
2404 && TYPE_CODE (t) == TYPE_CODE_PTR
2405 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
2409 is_integral_type (struct type *t)
2414 && ((TYPE_CODE (t) == TYPE_CODE_INT)
2415 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
2416 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
2417 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
2418 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
2419 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
2422 /* Return true if TYPE is scalar. */
2425 is_scalar_type (struct type *type)
2427 CHECK_TYPEDEF (type);
2429 switch (TYPE_CODE (type))
2431 case TYPE_CODE_ARRAY:
2432 case TYPE_CODE_STRUCT:
2433 case TYPE_CODE_UNION:
2435 case TYPE_CODE_STRING:
2442 /* Return true if T is scalar, or a composite type which in practice has
2443 the memory layout of a scalar type. E.g., an array or struct with only
2444 one scalar element inside it, or a union with only scalar elements. */
2447 is_scalar_type_recursive (struct type *t)
2451 if (is_scalar_type (t))
2453 /* Are we dealing with an array or string of known dimensions? */
2454 else if ((TYPE_CODE (t) == TYPE_CODE_ARRAY
2455 || TYPE_CODE (t) == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1
2456 && TYPE_CODE (TYPE_INDEX_TYPE (t)) == TYPE_CODE_RANGE)
2458 LONGEST low_bound, high_bound;
2459 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (t));
2461 get_discrete_bounds (TYPE_INDEX_TYPE (t), &low_bound, &high_bound);
2463 return high_bound == low_bound && is_scalar_type_recursive (elt_type);
2465 /* Are we dealing with a struct with one element? */
2466 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1)
2467 return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0));
2468 else if (TYPE_CODE (t) == TYPE_CODE_UNION)
2470 int i, n = TYPE_NFIELDS (t);
2472 /* If all elements of the union are scalar, then the union is scalar. */
2473 for (i = 0; i < n; i++)
2474 if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t, i)))
2483 /* A helper function which returns true if types A and B represent the
2484 "same" class type. This is true if the types have the same main
2485 type, or the same name. */
2488 class_types_same_p (const struct type *a, const struct type *b)
2490 return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b)
2491 || (TYPE_NAME (a) && TYPE_NAME (b)
2492 && !strcmp (TYPE_NAME (a), TYPE_NAME (b))));
2495 /* If BASE is an ancestor of DCLASS return the distance between them.
2496 otherwise return -1;
2500 class B: public A {};
2501 class C: public B {};
2504 distance_to_ancestor (A, A, 0) = 0
2505 distance_to_ancestor (A, B, 0) = 1
2506 distance_to_ancestor (A, C, 0) = 2
2507 distance_to_ancestor (A, D, 0) = 3
2509 If PUBLIC is 1 then only public ancestors are considered,
2510 and the function returns the distance only if BASE is a public ancestor
2514 distance_to_ancestor (A, D, 1) = -1. */
2517 distance_to_ancestor (struct type *base, struct type *dclass, int public)
2522 CHECK_TYPEDEF (base);
2523 CHECK_TYPEDEF (dclass);
2525 if (class_types_same_p (base, dclass))
2528 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2530 if (public && ! BASETYPE_VIA_PUBLIC (dclass, i))
2533 d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), public);
2541 /* Check whether BASE is an ancestor or base class or DCLASS
2542 Return 1 if so, and 0 if not.
2543 Note: If BASE and DCLASS are of the same type, this function
2544 will return 1. So for some class A, is_ancestor (A, A) will
2548 is_ancestor (struct type *base, struct type *dclass)
2550 return distance_to_ancestor (base, dclass, 0) >= 0;
2553 /* Like is_ancestor, but only returns true when BASE is a public
2554 ancestor of DCLASS. */
2557 is_public_ancestor (struct type *base, struct type *dclass)
2559 return distance_to_ancestor (base, dclass, 1) >= 0;
2562 /* A helper function for is_unique_ancestor. */
2565 is_unique_ancestor_worker (struct type *base, struct type *dclass,
2567 const gdb_byte *valaddr, int embedded_offset,
2568 CORE_ADDR address, struct value *val)
2572 CHECK_TYPEDEF (base);
2573 CHECK_TYPEDEF (dclass);
2575 for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
2580 iter = check_typedef (TYPE_BASECLASS (dclass, i));
2582 this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset,
2585 if (class_types_same_p (base, iter))
2587 /* If this is the first subclass, set *OFFSET and set count
2588 to 1. Otherwise, if this is at the same offset as
2589 previous instances, do nothing. Otherwise, increment
2593 *offset = this_offset;
2596 else if (this_offset == *offset)
2604 count += is_unique_ancestor_worker (base, iter, offset,
2606 embedded_offset + this_offset,
2613 /* Like is_ancestor, but only returns true if BASE is a unique base
2614 class of the type of VAL. */
2617 is_unique_ancestor (struct type *base, struct value *val)
2621 return is_unique_ancestor_worker (base, value_type (val), &offset,
2622 value_contents_for_printing (val),
2623 value_embedded_offset (val),
2624 value_address (val), val) == 1;
2628 /* Overload resolution. */
2630 /* Return the sum of the rank of A with the rank of B. */
2633 sum_ranks (struct rank a, struct rank b)
2636 c.rank = a.rank + b.rank;
2637 c.subrank = a.subrank + b.subrank;
2641 /* Compare rank A and B and return:
2643 1 if a is better than b
2644 -1 if b is better than a. */
2647 compare_ranks (struct rank a, struct rank b)
2649 if (a.rank == b.rank)
2651 if (a.subrank == b.subrank)
2653 if (a.subrank < b.subrank)
2655 if (a.subrank > b.subrank)
2659 if (a.rank < b.rank)
2662 /* a.rank > b.rank */
2666 /* Functions for overload resolution begin here. */
2668 /* Compare two badness vectors A and B and return the result.
2669 0 => A and B are identical
2670 1 => A and B are incomparable
2671 2 => A is better than B
2672 3 => A is worse than B */
2675 compare_badness (struct badness_vector *a, struct badness_vector *b)
2679 short found_pos = 0; /* any positives in c? */
2680 short found_neg = 0; /* any negatives in c? */
2682 /* differing lengths => incomparable */
2683 if (a->length != b->length)
2686 /* Subtract b from a */
2687 for (i = 0; i < a->length; i++)
2689 tmp = compare_ranks (b->rank[i], a->rank[i]);
2699 return 1; /* incomparable */
2701 return 3; /* A > B */
2707 return 2; /* A < B */
2709 return 0; /* A == B */
2713 /* Rank a function by comparing its parameter types (PARMS, length
2714 NPARMS), to the types of an argument list (ARGS, length NARGS).
2715 Return a pointer to a badness vector. This has NARGS + 1
2718 struct badness_vector *
2719 rank_function (struct type **parms, int nparms,
2720 struct value **args, int nargs)
2723 struct badness_vector *bv;
2724 int min_len = nparms < nargs ? nparms : nargs;
2726 bv = xmalloc (sizeof (struct badness_vector));
2727 bv->length = nargs + 1; /* add 1 for the length-match rank. */
2728 bv->rank = XNEWVEC (struct rank, nargs + 1);
2730 /* First compare the lengths of the supplied lists.
2731 If there is a mismatch, set it to a high value. */
2733 /* pai/1997-06-03 FIXME: when we have debug info about default
2734 arguments and ellipsis parameter lists, we should consider those
2735 and rank the length-match more finely. */
2737 LENGTH_MATCH (bv) = (nargs != nparms)
2738 ? LENGTH_MISMATCH_BADNESS
2739 : EXACT_MATCH_BADNESS;
2741 /* Now rank all the parameters of the candidate function. */
2742 for (i = 1; i <= min_len; i++)
2743 bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]),
2746 /* If more arguments than parameters, add dummy entries. */
2747 for (i = min_len + 1; i <= nargs; i++)
2748 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2753 /* Compare the names of two integer types, assuming that any sign
2754 qualifiers have been checked already. We do it this way because
2755 there may be an "int" in the name of one of the types. */
2758 integer_types_same_name_p (const char *first, const char *second)
2760 int first_p, second_p;
2762 /* If both are shorts, return 1; if neither is a short, keep
2764 first_p = (strstr (first, "short") != NULL);
2765 second_p = (strstr (second, "short") != NULL);
2766 if (first_p && second_p)
2768 if (first_p || second_p)
2771 /* Likewise for long. */
2772 first_p = (strstr (first, "long") != NULL);
2773 second_p = (strstr (second, "long") != NULL);
2774 if (first_p && second_p)
2776 if (first_p || second_p)
2779 /* Likewise for char. */
2780 first_p = (strstr (first, "char") != NULL);
2781 second_p = (strstr (second, "char") != NULL);
2782 if (first_p && second_p)
2784 if (first_p || second_p)
2787 /* They must both be ints. */
2791 /* Compares type A to type B returns 1 if the represent the same type
2795 types_equal (struct type *a, struct type *b)
2797 /* Identical type pointers. */
2798 /* However, this still doesn't catch all cases of same type for b
2799 and a. The reason is that builtin types are different from
2800 the same ones constructed from the object. */
2804 /* Resolve typedefs */
2805 if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF)
2806 a = check_typedef (a);
2807 if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF)
2808 b = check_typedef (b);
2810 /* If after resolving typedefs a and b are not of the same type
2811 code then they are not equal. */
2812 if (TYPE_CODE (a) != TYPE_CODE (b))
2815 /* If a and b are both pointers types or both reference types then
2816 they are equal of the same type iff the objects they refer to are
2817 of the same type. */
2818 if (TYPE_CODE (a) == TYPE_CODE_PTR
2819 || TYPE_CODE (a) == TYPE_CODE_REF)
2820 return types_equal (TYPE_TARGET_TYPE (a),
2821 TYPE_TARGET_TYPE (b));
2823 /* Well, damnit, if the names are exactly the same, I'll say they
2824 are exactly the same. This happens when we generate method
2825 stubs. The types won't point to the same address, but they
2826 really are the same. */
2828 if (TYPE_NAME (a) && TYPE_NAME (b)
2829 && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0)
2832 /* Check if identical after resolving typedefs. */
2836 /* Two function types are equal if their argument and return types
2838 if (TYPE_CODE (a) == TYPE_CODE_FUNC)
2842 if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
2845 if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
2848 for (i = 0; i < TYPE_NFIELDS (a); ++i)
2849 if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
2858 /* Deep comparison of types. */
2860 /* An entry in the type-equality bcache. */
2862 typedef struct type_equality_entry
2864 struct type *type1, *type2;
2865 } type_equality_entry_d;
2867 DEF_VEC_O (type_equality_entry_d);
2869 /* A helper function to compare two strings. Returns 1 if they are
2870 the same, 0 otherwise. Handles NULLs properly. */
2873 compare_maybe_null_strings (const char *s, const char *t)
2875 if (s == NULL && t != NULL)
2877 else if (s != NULL && t == NULL)
2879 else if (s == NULL && t== NULL)
2881 return strcmp (s, t) == 0;
2884 /* A helper function for check_types_worklist that checks two types for
2885 "deep" equality. Returns non-zero if the types are considered the
2886 same, zero otherwise. */
2889 check_types_equal (struct type *type1, struct type *type2,
2890 VEC (type_equality_entry_d) **worklist)
2892 CHECK_TYPEDEF (type1);
2893 CHECK_TYPEDEF (type2);
2898 if (TYPE_CODE (type1) != TYPE_CODE (type2)
2899 || TYPE_LENGTH (type1) != TYPE_LENGTH (type2)
2900 || TYPE_UNSIGNED (type1) != TYPE_UNSIGNED (type2)
2901 || TYPE_NOSIGN (type1) != TYPE_NOSIGN (type2)
2902 || TYPE_VARARGS (type1) != TYPE_VARARGS (type2)
2903 || TYPE_VECTOR (type1) != TYPE_VECTOR (type2)
2904 || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2)
2905 || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2)
2906 || TYPE_NFIELDS (type1) != TYPE_NFIELDS (type2))
2909 if (!compare_maybe_null_strings (TYPE_TAG_NAME (type1),
2910 TYPE_TAG_NAME (type2)))
2912 if (!compare_maybe_null_strings (TYPE_NAME (type1), TYPE_NAME (type2)))
2915 if (TYPE_CODE (type1) == TYPE_CODE_RANGE)
2917 if (memcmp (TYPE_RANGE_DATA (type1), TYPE_RANGE_DATA (type2),
2918 sizeof (*TYPE_RANGE_DATA (type1))) != 0)
2925 for (i = 0; i < TYPE_NFIELDS (type1); ++i)
2927 const struct field *field1 = &TYPE_FIELD (type1, i);
2928 const struct field *field2 = &TYPE_FIELD (type2, i);
2929 struct type_equality_entry entry;
2931 if (FIELD_ARTIFICIAL (*field1) != FIELD_ARTIFICIAL (*field2)
2932 || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2)
2933 || FIELD_LOC_KIND (*field1) != FIELD_LOC_KIND (*field2))
2935 if (!compare_maybe_null_strings (FIELD_NAME (*field1),
2936 FIELD_NAME (*field2)))
2938 switch (FIELD_LOC_KIND (*field1))
2940 case FIELD_LOC_KIND_BITPOS:
2941 if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2))
2944 case FIELD_LOC_KIND_ENUMVAL:
2945 if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2))
2948 case FIELD_LOC_KIND_PHYSADDR:
2949 if (FIELD_STATIC_PHYSADDR (*field1)
2950 != FIELD_STATIC_PHYSADDR (*field2))
2953 case FIELD_LOC_KIND_PHYSNAME:
2954 if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1),
2955 FIELD_STATIC_PHYSNAME (*field2)))
2958 case FIELD_LOC_KIND_DWARF_BLOCK:
2960 struct dwarf2_locexpr_baton *block1, *block2;
2962 block1 = FIELD_DWARF_BLOCK (*field1);
2963 block2 = FIELD_DWARF_BLOCK (*field2);
2964 if (block1->per_cu != block2->per_cu
2965 || block1->size != block2->size
2966 || memcmp (block1->data, block2->data, block1->size) != 0)
2971 internal_error (__FILE__, __LINE__, _("Unsupported field kind "
2972 "%d by check_types_equal"),
2973 FIELD_LOC_KIND (*field1));
2976 entry.type1 = FIELD_TYPE (*field1);
2977 entry.type2 = FIELD_TYPE (*field2);
2978 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
2982 if (TYPE_TARGET_TYPE (type1) != NULL)
2984 struct type_equality_entry entry;
2986 if (TYPE_TARGET_TYPE (type2) == NULL)
2989 entry.type1 = TYPE_TARGET_TYPE (type1);
2990 entry.type2 = TYPE_TARGET_TYPE (type2);
2991 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
2993 else if (TYPE_TARGET_TYPE (type2) != NULL)
2999 /* Check types on a worklist for equality. Returns zero if any pair
3000 is not equal, non-zero if they are all considered equal. */
3003 check_types_worklist (VEC (type_equality_entry_d) **worklist,
3004 struct bcache *cache)
3006 while (!VEC_empty (type_equality_entry_d, *worklist))
3008 struct type_equality_entry entry;
3011 entry = *VEC_last (type_equality_entry_d, *worklist);
3012 VEC_pop (type_equality_entry_d, *worklist);
3014 /* If the type pair has already been visited, we know it is
3016 bcache_full (&entry, sizeof (entry), cache, &added);
3020 if (check_types_equal (entry.type1, entry.type2, worklist) == 0)
3027 /* Return non-zero if types TYPE1 and TYPE2 are equal, as determined by a
3028 "deep comparison". Otherwise return zero. */
3031 types_deeply_equal (struct type *type1, struct type *type2)
3033 volatile struct gdb_exception except;
3035 struct bcache *cache;
3036 VEC (type_equality_entry_d) *worklist = NULL;
3037 struct type_equality_entry entry;
3039 gdb_assert (type1 != NULL && type2 != NULL);
3041 /* Early exit for the simple case. */
3045 cache = bcache_xmalloc (NULL, NULL);
3047 entry.type1 = type1;
3048 entry.type2 = type2;
3049 VEC_safe_push (type_equality_entry_d, worklist, &entry);
3051 TRY_CATCH (except, RETURN_MASK_ALL)
3053 result = check_types_worklist (&worklist, cache);
3055 /* check_types_worklist calls several nested helper functions,
3056 some of which can raise a GDB Exception, so we just check
3057 and rethrow here. If there is a GDB exception, a comparison
3058 is not capable (or trusted), so exit. */
3059 bcache_xfree (cache);
3060 VEC_free (type_equality_entry_d, worklist);
3061 /* Rethrow if there was a problem. */
3062 if (except.reason < 0)
3063 throw_exception (except);
3068 /* Compare one type (PARM) for compatibility with another (ARG).
3069 * PARM is intended to be the parameter type of a function; and
3070 * ARG is the supplied argument's type. This function tests if
3071 * the latter can be converted to the former.
3072 * VALUE is the argument's value or NULL if none (or called recursively)
3074 * Return 0 if they are identical types;
3075 * Otherwise, return an integer which corresponds to how compatible
3076 * PARM is to ARG. The higher the return value, the worse the match.
3077 * Generally the "bad" conversions are all uniformly assigned a 100. */
3080 rank_one_type (struct type *parm, struct type *arg, struct value *value)
3082 struct rank rank = {0,0};
3084 if (types_equal (parm, arg))
3085 return EXACT_MATCH_BADNESS;
3087 /* Resolve typedefs */
3088 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
3089 parm = check_typedef (parm);
3090 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
3091 arg = check_typedef (arg);
3093 /* See through references, since we can almost make non-references
3095 if (TYPE_CODE (arg) == TYPE_CODE_REF)
3096 return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
3097 REFERENCE_CONVERSION_BADNESS));
3098 if (TYPE_CODE (parm) == TYPE_CODE_REF)
3099 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
3100 REFERENCE_CONVERSION_BADNESS));
3102 /* Debugging only. */
3103 fprintf_filtered (gdb_stderr,
3104 "------ Arg is %s [%d], parm is %s [%d]\n",
3105 TYPE_NAME (arg), TYPE_CODE (arg),
3106 TYPE_NAME (parm), TYPE_CODE (parm));
3108 /* x -> y means arg of type x being supplied for parameter of type y. */
3110 switch (TYPE_CODE (parm))
3113 switch (TYPE_CODE (arg))
3117 /* Allowed pointer conversions are:
3118 (a) pointer to void-pointer conversion. */
3119 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
3120 return VOID_PTR_CONVERSION_BADNESS;
3122 /* (b) pointer to ancestor-pointer conversion. */
3123 rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
3124 TYPE_TARGET_TYPE (arg),
3126 if (rank.subrank >= 0)
3127 return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
3129 return INCOMPATIBLE_TYPE_BADNESS;
3130 case TYPE_CODE_ARRAY:
3131 if (types_equal (TYPE_TARGET_TYPE (parm),
3132 TYPE_TARGET_TYPE (arg)))
3133 return EXACT_MATCH_BADNESS;
3134 return INCOMPATIBLE_TYPE_BADNESS;
3135 case TYPE_CODE_FUNC:
3136 return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
3138 if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
3140 if (value_as_long (value) == 0)
3142 /* Null pointer conversion: allow it to be cast to a pointer.
3143 [4.10.1 of C++ standard draft n3290] */
3144 return NULL_POINTER_CONVERSION_BADNESS;
3148 /* If type checking is disabled, allow the conversion. */
3149 if (!strict_type_checking)
3150 return NS_INTEGER_POINTER_CONVERSION_BADNESS;
3154 case TYPE_CODE_ENUM:
3155 case TYPE_CODE_FLAGS:
3156 case TYPE_CODE_CHAR:
3157 case TYPE_CODE_RANGE:
3158 case TYPE_CODE_BOOL:
3160 return INCOMPATIBLE_TYPE_BADNESS;
3162 case TYPE_CODE_ARRAY:
3163 switch (TYPE_CODE (arg))
3166 case TYPE_CODE_ARRAY:
3167 return rank_one_type (TYPE_TARGET_TYPE (parm),
3168 TYPE_TARGET_TYPE (arg), NULL);
3170 return INCOMPATIBLE_TYPE_BADNESS;
3172 case TYPE_CODE_FUNC:
3173 switch (TYPE_CODE (arg))
3175 case TYPE_CODE_PTR: /* funcptr -> func */
3176 return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
3178 return INCOMPATIBLE_TYPE_BADNESS;
3181 switch (TYPE_CODE (arg))
3184 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3186 /* Deal with signed, unsigned, and plain chars and
3187 signed and unsigned ints. */
3188 if (TYPE_NOSIGN (parm))
3190 /* This case only for character types. */
3191 if (TYPE_NOSIGN (arg))
3192 return EXACT_MATCH_BADNESS; /* plain char -> plain char */
3193 else /* signed/unsigned char -> plain char */
3194 return INTEGER_CONVERSION_BADNESS;
3196 else if (TYPE_UNSIGNED (parm))
3198 if (TYPE_UNSIGNED (arg))
3200 /* unsigned int -> unsigned int, or
3201 unsigned long -> unsigned long */
3202 if (integer_types_same_name_p (TYPE_NAME (parm),
3204 return EXACT_MATCH_BADNESS;
3205 else if (integer_types_same_name_p (TYPE_NAME (arg),
3207 && integer_types_same_name_p (TYPE_NAME (parm),
3209 /* unsigned int -> unsigned long */
3210 return INTEGER_PROMOTION_BADNESS;
3212 /* unsigned long -> unsigned int */
3213 return INTEGER_CONVERSION_BADNESS;
3217 if (integer_types_same_name_p (TYPE_NAME (arg),
3219 && integer_types_same_name_p (TYPE_NAME (parm),
3221 /* signed long -> unsigned int */
3222 return INTEGER_CONVERSION_BADNESS;
3224 /* signed int/long -> unsigned int/long */
3225 return INTEGER_CONVERSION_BADNESS;
3228 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3230 if (integer_types_same_name_p (TYPE_NAME (parm),
3232 return EXACT_MATCH_BADNESS;
3233 else if (integer_types_same_name_p (TYPE_NAME (arg),
3235 && integer_types_same_name_p (TYPE_NAME (parm),
3237 return INTEGER_PROMOTION_BADNESS;
3239 return INTEGER_CONVERSION_BADNESS;
3242 return INTEGER_CONVERSION_BADNESS;
3244 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3245 return INTEGER_PROMOTION_BADNESS;
3247 return INTEGER_CONVERSION_BADNESS;
3248 case TYPE_CODE_ENUM:
3249 case TYPE_CODE_FLAGS:
3250 case TYPE_CODE_CHAR:
3251 case TYPE_CODE_RANGE:
3252 case TYPE_CODE_BOOL:
3253 if (TYPE_DECLARED_CLASS (arg))
3254 return INCOMPATIBLE_TYPE_BADNESS;
3255 return INTEGER_PROMOTION_BADNESS;
3257 return INT_FLOAT_CONVERSION_BADNESS;
3259 return NS_POINTER_CONVERSION_BADNESS;
3261 return INCOMPATIBLE_TYPE_BADNESS;
3264 case TYPE_CODE_ENUM:
3265 switch (TYPE_CODE (arg))
3268 case TYPE_CODE_CHAR:
3269 case TYPE_CODE_RANGE:
3270 case TYPE_CODE_BOOL:
3271 case TYPE_CODE_ENUM:
3272 if (TYPE_DECLARED_CLASS (parm) || TYPE_DECLARED_CLASS (arg))
3273 return INCOMPATIBLE_TYPE_BADNESS;
3274 return INTEGER_CONVERSION_BADNESS;
3276 return INT_FLOAT_CONVERSION_BADNESS;
3278 return INCOMPATIBLE_TYPE_BADNESS;
3281 case TYPE_CODE_CHAR:
3282 switch (TYPE_CODE (arg))
3284 case TYPE_CODE_RANGE:
3285 case TYPE_CODE_BOOL:
3286 case TYPE_CODE_ENUM:
3287 if (TYPE_DECLARED_CLASS (arg))
3288 return INCOMPATIBLE_TYPE_BADNESS;
3289 return INTEGER_CONVERSION_BADNESS;
3291 return INT_FLOAT_CONVERSION_BADNESS;
3293 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
3294 return INTEGER_CONVERSION_BADNESS;
3295 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3296 return INTEGER_PROMOTION_BADNESS;
3297 /* >>> !! else fall through !! <<< */
3298 case TYPE_CODE_CHAR:
3299 /* Deal with signed, unsigned, and plain chars for C++ and
3300 with int cases falling through from previous case. */
3301 if (TYPE_NOSIGN (parm))
3303 if (TYPE_NOSIGN (arg))
3304 return EXACT_MATCH_BADNESS;
3306 return INTEGER_CONVERSION_BADNESS;
3308 else if (TYPE_UNSIGNED (parm))
3310 if (TYPE_UNSIGNED (arg))
3311 return EXACT_MATCH_BADNESS;
3313 return INTEGER_PROMOTION_BADNESS;
3315 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3316 return EXACT_MATCH_BADNESS;
3318 return INTEGER_CONVERSION_BADNESS;
3320 return INCOMPATIBLE_TYPE_BADNESS;
3323 case TYPE_CODE_RANGE:
3324 switch (TYPE_CODE (arg))
3327 case TYPE_CODE_CHAR:
3328 case TYPE_CODE_RANGE:
3329 case TYPE_CODE_BOOL:
3330 case TYPE_CODE_ENUM:
3331 return INTEGER_CONVERSION_BADNESS;
3333 return INT_FLOAT_CONVERSION_BADNESS;
3335 return INCOMPATIBLE_TYPE_BADNESS;
3338 case TYPE_CODE_BOOL:
3339 switch (TYPE_CODE (arg))
3341 /* n3290 draft, section 4.12.1 (conv.bool):
3343 "A prvalue of arithmetic, unscoped enumeration, pointer, or
3344 pointer to member type can be converted to a prvalue of type
3345 bool. A zero value, null pointer value, or null member pointer
3346 value is converted to false; any other value is converted to
3347 true. A prvalue of type std::nullptr_t can be converted to a
3348 prvalue of type bool; the resulting value is false." */
3350 case TYPE_CODE_CHAR:
3351 case TYPE_CODE_ENUM:
3353 case TYPE_CODE_MEMBERPTR:
3355 return BOOL_CONVERSION_BADNESS;
3356 case TYPE_CODE_RANGE:
3357 return INCOMPATIBLE_TYPE_BADNESS;
3358 case TYPE_CODE_BOOL:
3359 return EXACT_MATCH_BADNESS;
3361 return INCOMPATIBLE_TYPE_BADNESS;
3365 switch (TYPE_CODE (arg))
3368 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3369 return FLOAT_PROMOTION_BADNESS;
3370 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3371 return EXACT_MATCH_BADNESS;
3373 return FLOAT_CONVERSION_BADNESS;
3375 case TYPE_CODE_BOOL:
3376 case TYPE_CODE_ENUM:
3377 case TYPE_CODE_RANGE:
3378 case TYPE_CODE_CHAR:
3379 return INT_FLOAT_CONVERSION_BADNESS;
3381 return INCOMPATIBLE_TYPE_BADNESS;
3384 case TYPE_CODE_COMPLEX:
3385 switch (TYPE_CODE (arg))
3386 { /* Strictly not needed for C++, but... */
3388 return FLOAT_PROMOTION_BADNESS;
3389 case TYPE_CODE_COMPLEX:
3390 return EXACT_MATCH_BADNESS;
3392 return INCOMPATIBLE_TYPE_BADNESS;
3395 case TYPE_CODE_STRUCT:
3396 /* currently same as TYPE_CODE_CLASS. */
3397 switch (TYPE_CODE (arg))
3399 case TYPE_CODE_STRUCT:
3400 /* Check for derivation */
3401 rank.subrank = distance_to_ancestor (parm, arg, 0);
3402 if (rank.subrank >= 0)
3403 return sum_ranks (BASE_CONVERSION_BADNESS, rank);
3404 /* else fall through */
3406 return INCOMPATIBLE_TYPE_BADNESS;
3409 case TYPE_CODE_UNION:
3410 switch (TYPE_CODE (arg))
3412 case TYPE_CODE_UNION:
3414 return INCOMPATIBLE_TYPE_BADNESS;
3417 case TYPE_CODE_MEMBERPTR:
3418 switch (TYPE_CODE (arg))
3421 return INCOMPATIBLE_TYPE_BADNESS;
3424 case TYPE_CODE_METHOD:
3425 switch (TYPE_CODE (arg))
3429 return INCOMPATIBLE_TYPE_BADNESS;
3433 switch (TYPE_CODE (arg))
3437 return INCOMPATIBLE_TYPE_BADNESS;
3442 switch (TYPE_CODE (arg))
3446 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
3447 TYPE_FIELD_TYPE (arg, 0), NULL);
3449 return INCOMPATIBLE_TYPE_BADNESS;
3452 case TYPE_CODE_VOID:
3454 return INCOMPATIBLE_TYPE_BADNESS;
3455 } /* switch (TYPE_CODE (arg)) */
3458 /* End of functions for overload resolution. */
3460 /* Routines to pretty-print types. */
3463 print_bit_vector (B_TYPE *bits, int nbits)
3467 for (bitno = 0; bitno < nbits; bitno++)
3469 if ((bitno % 8) == 0)
3471 puts_filtered (" ");
3473 if (B_TST (bits, bitno))
3474 printf_filtered (("1"));
3476 printf_filtered (("0"));
3480 /* Note the first arg should be the "this" pointer, we may not want to
3481 include it since we may get into a infinitely recursive
3485 print_arg_types (struct field *args, int nargs, int spaces)
3491 for (i = 0; i < nargs; i++)
3492 recursive_dump_type (args[i].type, spaces + 2);
3497 field_is_static (struct field *f)
3499 /* "static" fields are the fields whose location is not relative
3500 to the address of the enclosing struct. It would be nice to
3501 have a dedicated flag that would be set for static fields when
3502 the type is being created. But in practice, checking the field
3503 loc_kind should give us an accurate answer. */
3504 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
3505 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
3509 dump_fn_fieldlists (struct type *type, int spaces)
3515 printfi_filtered (spaces, "fn_fieldlists ");
3516 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
3517 printf_filtered ("\n");
3518 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
3520 f = TYPE_FN_FIELDLIST1 (type, method_idx);
3521 printfi_filtered (spaces + 2, "[%d] name '%s' (",
3523 TYPE_FN_FIELDLIST_NAME (type, method_idx));
3524 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
3526 printf_filtered (_(") length %d\n"),
3527 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
3528 for (overload_idx = 0;
3529 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
3532 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
3534 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
3535 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
3537 printf_filtered (")\n");
3538 printfi_filtered (spaces + 8, "type ");
3539 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
3541 printf_filtered ("\n");
3543 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
3546 printfi_filtered (spaces + 8, "args ");
3547 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
3549 printf_filtered ("\n");
3551 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
3552 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f,
3555 printfi_filtered (spaces + 8, "fcontext ");
3556 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
3558 printf_filtered ("\n");
3560 printfi_filtered (spaces + 8, "is_const %d\n",
3561 TYPE_FN_FIELD_CONST (f, overload_idx));
3562 printfi_filtered (spaces + 8, "is_volatile %d\n",
3563 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
3564 printfi_filtered (spaces + 8, "is_private %d\n",
3565 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
3566 printfi_filtered (spaces + 8, "is_protected %d\n",
3567 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
3568 printfi_filtered (spaces + 8, "is_stub %d\n",
3569 TYPE_FN_FIELD_STUB (f, overload_idx));
3570 printfi_filtered (spaces + 8, "voffset %u\n",
3571 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
3577 print_cplus_stuff (struct type *type, int spaces)
3579 printfi_filtered (spaces, "n_baseclasses %d\n",
3580 TYPE_N_BASECLASSES (type));
3581 printfi_filtered (spaces, "nfn_fields %d\n",
3582 TYPE_NFN_FIELDS (type));
3583 if (TYPE_N_BASECLASSES (type) > 0)
3585 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
3586 TYPE_N_BASECLASSES (type));
3587 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
3589 printf_filtered (")");
3591 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
3592 TYPE_N_BASECLASSES (type));
3593 puts_filtered ("\n");
3595 if (TYPE_NFIELDS (type) > 0)
3597 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
3599 printfi_filtered (spaces,
3600 "private_field_bits (%d bits at *",
3601 TYPE_NFIELDS (type));
3602 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
3604 printf_filtered (")");
3605 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
3606 TYPE_NFIELDS (type));
3607 puts_filtered ("\n");
3609 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
3611 printfi_filtered (spaces,
3612 "protected_field_bits (%d bits at *",
3613 TYPE_NFIELDS (type));
3614 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
3616 printf_filtered (")");
3617 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
3618 TYPE_NFIELDS (type));
3619 puts_filtered ("\n");
3622 if (TYPE_NFN_FIELDS (type) > 0)
3624 dump_fn_fieldlists (type, spaces);
3628 /* Print the contents of the TYPE's type_specific union, assuming that
3629 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
3632 print_gnat_stuff (struct type *type, int spaces)
3634 struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
3636 recursive_dump_type (descriptive_type, spaces + 2);
3639 static struct obstack dont_print_type_obstack;
3642 recursive_dump_type (struct type *type, int spaces)
3647 obstack_begin (&dont_print_type_obstack, 0);
3649 if (TYPE_NFIELDS (type) > 0
3650 || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0))
3652 struct type **first_dont_print
3653 = (struct type **) obstack_base (&dont_print_type_obstack);
3655 int i = (struct type **)
3656 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
3660 if (type == first_dont_print[i])
3662 printfi_filtered (spaces, "type node ");
3663 gdb_print_host_address (type, gdb_stdout);
3664 printf_filtered (_(" <same as already seen type>\n"));
3669 obstack_ptr_grow (&dont_print_type_obstack, type);
3672 printfi_filtered (spaces, "type node ");
3673 gdb_print_host_address (type, gdb_stdout);
3674 printf_filtered ("\n");
3675 printfi_filtered (spaces, "name '%s' (",
3676 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
3677 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
3678 printf_filtered (")\n");
3679 printfi_filtered (spaces, "tagname '%s' (",
3680 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
3681 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
3682 printf_filtered (")\n");
3683 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
3684 switch (TYPE_CODE (type))
3686 case TYPE_CODE_UNDEF:
3687 printf_filtered ("(TYPE_CODE_UNDEF)");
3690 printf_filtered ("(TYPE_CODE_PTR)");
3692 case TYPE_CODE_ARRAY:
3693 printf_filtered ("(TYPE_CODE_ARRAY)");
3695 case TYPE_CODE_STRUCT:
3696 printf_filtered ("(TYPE_CODE_STRUCT)");
3698 case TYPE_CODE_UNION:
3699 printf_filtered ("(TYPE_CODE_UNION)");
3701 case TYPE_CODE_ENUM:
3702 printf_filtered ("(TYPE_CODE_ENUM)");
3704 case TYPE_CODE_FLAGS:
3705 printf_filtered ("(TYPE_CODE_FLAGS)");
3707 case TYPE_CODE_FUNC:
3708 printf_filtered ("(TYPE_CODE_FUNC)");
3711 printf_filtered ("(TYPE_CODE_INT)");
3714 printf_filtered ("(TYPE_CODE_FLT)");
3716 case TYPE_CODE_VOID:
3717 printf_filtered ("(TYPE_CODE_VOID)");
3720 printf_filtered ("(TYPE_CODE_SET)");
3722 case TYPE_CODE_RANGE:
3723 printf_filtered ("(TYPE_CODE_RANGE)");
3725 case TYPE_CODE_STRING:
3726 printf_filtered ("(TYPE_CODE_STRING)");
3728 case TYPE_CODE_ERROR:
3729 printf_filtered ("(TYPE_CODE_ERROR)");
3731 case TYPE_CODE_MEMBERPTR:
3732 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
3734 case TYPE_CODE_METHODPTR:
3735 printf_filtered ("(TYPE_CODE_METHODPTR)");
3737 case TYPE_CODE_METHOD:
3738 printf_filtered ("(TYPE_CODE_METHOD)");
3741 printf_filtered ("(TYPE_CODE_REF)");
3743 case TYPE_CODE_CHAR:
3744 printf_filtered ("(TYPE_CODE_CHAR)");
3746 case TYPE_CODE_BOOL:
3747 printf_filtered ("(TYPE_CODE_BOOL)");
3749 case TYPE_CODE_COMPLEX:
3750 printf_filtered ("(TYPE_CODE_COMPLEX)");
3752 case TYPE_CODE_TYPEDEF:
3753 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3755 case TYPE_CODE_NAMESPACE:
3756 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3759 printf_filtered ("(UNKNOWN TYPE CODE)");
3762 puts_filtered ("\n");
3763 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
3764 if (TYPE_OBJFILE_OWNED (type))
3766 printfi_filtered (spaces, "objfile ");
3767 gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout);
3771 printfi_filtered (spaces, "gdbarch ");
3772 gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout);
3774 printf_filtered ("\n");
3775 printfi_filtered (spaces, "target_type ");
3776 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
3777 printf_filtered ("\n");
3778 if (TYPE_TARGET_TYPE (type) != NULL)
3780 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3782 printfi_filtered (spaces, "pointer_type ");
3783 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
3784 printf_filtered ("\n");
3785 printfi_filtered (spaces, "reference_type ");
3786 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
3787 printf_filtered ("\n");
3788 printfi_filtered (spaces, "type_chain ");
3789 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
3790 printf_filtered ("\n");
3791 printfi_filtered (spaces, "instance_flags 0x%x",
3792 TYPE_INSTANCE_FLAGS (type));
3793 if (TYPE_CONST (type))
3795 puts_filtered (" TYPE_FLAG_CONST");
3797 if (TYPE_VOLATILE (type))
3799 puts_filtered (" TYPE_FLAG_VOLATILE");
3801 if (TYPE_CODE_SPACE (type))
3803 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3805 if (TYPE_DATA_SPACE (type))
3807 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3809 if (TYPE_ADDRESS_CLASS_1 (type))
3811 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3813 if (TYPE_ADDRESS_CLASS_2 (type))
3815 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3817 if (TYPE_RESTRICT (type))
3819 puts_filtered (" TYPE_FLAG_RESTRICT");
3821 puts_filtered ("\n");
3823 printfi_filtered (spaces, "flags");
3824 if (TYPE_UNSIGNED (type))
3826 puts_filtered (" TYPE_FLAG_UNSIGNED");
3828 if (TYPE_NOSIGN (type))
3830 puts_filtered (" TYPE_FLAG_NOSIGN");
3832 if (TYPE_STUB (type))
3834 puts_filtered (" TYPE_FLAG_STUB");
3836 if (TYPE_TARGET_STUB (type))
3838 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3840 if (TYPE_STATIC (type))
3842 puts_filtered (" TYPE_FLAG_STATIC");
3844 if (TYPE_PROTOTYPED (type))
3846 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3848 if (TYPE_INCOMPLETE (type))
3850 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3852 if (TYPE_VARARGS (type))
3854 puts_filtered (" TYPE_FLAG_VARARGS");
3856 /* This is used for things like AltiVec registers on ppc. Gcc emits
3857 an attribute for the array type, which tells whether or not we
3858 have a vector, instead of a regular array. */
3859 if (TYPE_VECTOR (type))
3861 puts_filtered (" TYPE_FLAG_VECTOR");
3863 if (TYPE_FIXED_INSTANCE (type))
3865 puts_filtered (" TYPE_FIXED_INSTANCE");
3867 if (TYPE_STUB_SUPPORTED (type))
3869 puts_filtered (" TYPE_STUB_SUPPORTED");
3871 if (TYPE_NOTTEXT (type))
3873 puts_filtered (" TYPE_NOTTEXT");
3875 puts_filtered ("\n");
3876 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3877 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3878 puts_filtered ("\n");
3879 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3881 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
3882 printfi_filtered (spaces + 2,
3883 "[%d] enumval %s type ",
3884 idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
3886 printfi_filtered (spaces + 2,
3887 "[%d] bitpos %d bitsize %d type ",
3888 idx, TYPE_FIELD_BITPOS (type, idx),
3889 TYPE_FIELD_BITSIZE (type, idx));
3890 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3891 printf_filtered (" name '%s' (",
3892 TYPE_FIELD_NAME (type, idx) != NULL
3893 ? TYPE_FIELD_NAME (type, idx)
3895 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3896 printf_filtered (")\n");
3897 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3899 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3902 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
3904 printfi_filtered (spaces, "low %s%s high %s%s\n",
3905 plongest (TYPE_LOW_BOUND (type)),
3906 TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
3907 plongest (TYPE_HIGH_BOUND (type)),
3908 TYPE_HIGH_BOUND_UNDEFINED (type)
3909 ? " (undefined)" : "");
3911 printfi_filtered (spaces, "vptr_basetype ");
3912 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3913 puts_filtered ("\n");
3914 if (TYPE_VPTR_BASETYPE (type) != NULL)
3916 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3918 printfi_filtered (spaces, "vptr_fieldno %d\n",
3919 TYPE_VPTR_FIELDNO (type));
3921 switch (TYPE_SPECIFIC_FIELD (type))
3923 case TYPE_SPECIFIC_CPLUS_STUFF:
3924 printfi_filtered (spaces, "cplus_stuff ");
3925 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
3927 puts_filtered ("\n");
3928 print_cplus_stuff (type, spaces);
3931 case TYPE_SPECIFIC_GNAT_STUFF:
3932 printfi_filtered (spaces, "gnat_stuff ");
3933 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type), gdb_stdout);
3934 puts_filtered ("\n");
3935 print_gnat_stuff (type, spaces);
3938 case TYPE_SPECIFIC_FLOATFORMAT:
3939 printfi_filtered (spaces, "floatformat ");
3940 if (TYPE_FLOATFORMAT (type) == NULL)
3941 puts_filtered ("(null)");
3944 puts_filtered ("{ ");
3945 if (TYPE_FLOATFORMAT (type)[0] == NULL
3946 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
3947 puts_filtered ("(null)");
3949 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
3951 puts_filtered (", ");
3952 if (TYPE_FLOATFORMAT (type)[1] == NULL
3953 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
3954 puts_filtered ("(null)");
3956 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
3958 puts_filtered (" }");
3960 puts_filtered ("\n");
3963 case TYPE_SPECIFIC_FUNC:
3964 printfi_filtered (spaces, "calling_convention %d\n",
3965 TYPE_CALLING_CONVENTION (type));
3966 /* tail_call_list is not printed. */
3971 obstack_free (&dont_print_type_obstack, NULL);
3974 /* Trivial helpers for the libiberty hash table, for mapping one
3979 struct type *old, *new;
3983 type_pair_hash (const void *item)
3985 const struct type_pair *pair = item;
3987 return htab_hash_pointer (pair->old);
3991 type_pair_eq (const void *item_lhs, const void *item_rhs)
3993 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
3995 return lhs->old == rhs->old;
3998 /* Allocate the hash table used by copy_type_recursive to walk
3999 types without duplicates. We use OBJFILE's obstack, because
4000 OBJFILE is about to be deleted. */
4003 create_copied_types_hash (struct objfile *objfile)
4005 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
4006 NULL, &objfile->objfile_obstack,
4007 hashtab_obstack_allocate,
4008 dummy_obstack_deallocate);
4011 /* Recursively copy (deep copy) TYPE, if it is associated with
4012 OBJFILE. Return a new type allocated using malloc, a saved type if
4013 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
4014 not associated with OBJFILE. */
4017 copy_type_recursive (struct objfile *objfile,
4019 htab_t copied_types)
4021 struct type_pair *stored, pair;
4023 struct type *new_type;
4025 if (! TYPE_OBJFILE_OWNED (type))
4028 /* This type shouldn't be pointing to any types in other objfiles;
4029 if it did, the type might disappear unexpectedly. */
4030 gdb_assert (TYPE_OBJFILE (type) == objfile);
4033 slot = htab_find_slot (copied_types, &pair, INSERT);
4035 return ((struct type_pair *) *slot)->new;
4037 new_type = alloc_type_arch (get_type_arch (type));
4039 /* We must add the new type to the hash table immediately, in case
4040 we encounter this type again during a recursive call below. */
4042 = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
4044 stored->new = new_type;
4047 /* Copy the common fields of types. For the main type, we simply
4048 copy the entire thing and then update specific fields as needed. */
4049 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
4050 TYPE_OBJFILE_OWNED (new_type) = 0;
4051 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
4053 if (TYPE_NAME (type))
4054 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
4055 if (TYPE_TAG_NAME (type))
4056 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
4058 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4059 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4061 /* Copy the fields. */
4062 if (TYPE_NFIELDS (type))
4066 nfields = TYPE_NFIELDS (type);
4067 TYPE_FIELDS (new_type) = XCNEWVEC (struct field, nfields);
4068 for (i = 0; i < nfields; i++)
4070 TYPE_FIELD_ARTIFICIAL (new_type, i) =
4071 TYPE_FIELD_ARTIFICIAL (type, i);
4072 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
4073 if (TYPE_FIELD_TYPE (type, i))
4074 TYPE_FIELD_TYPE (new_type, i)
4075 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
4077 if (TYPE_FIELD_NAME (type, i))
4078 TYPE_FIELD_NAME (new_type, i) =
4079 xstrdup (TYPE_FIELD_NAME (type, i));
4080 switch (TYPE_FIELD_LOC_KIND (type, i))
4082 case FIELD_LOC_KIND_BITPOS:
4083 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
4084 TYPE_FIELD_BITPOS (type, i));
4086 case FIELD_LOC_KIND_ENUMVAL:
4087 SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i),
4088 TYPE_FIELD_ENUMVAL (type, i));
4090 case FIELD_LOC_KIND_PHYSADDR:
4091 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
4092 TYPE_FIELD_STATIC_PHYSADDR (type, i));
4094 case FIELD_LOC_KIND_PHYSNAME:
4095 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
4096 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
4100 internal_error (__FILE__, __LINE__,
4101 _("Unexpected type field location kind: %d"),
4102 TYPE_FIELD_LOC_KIND (type, i));
4107 /* For range types, copy the bounds information. */
4108 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4110 TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
4111 *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
4114 /* Copy pointers to other types. */
4115 if (TYPE_TARGET_TYPE (type))
4116 TYPE_TARGET_TYPE (new_type) =
4117 copy_type_recursive (objfile,
4118 TYPE_TARGET_TYPE (type),
4120 if (TYPE_VPTR_BASETYPE (type))
4121 TYPE_VPTR_BASETYPE (new_type) =
4122 copy_type_recursive (objfile,
4123 TYPE_VPTR_BASETYPE (type),
4125 /* Maybe copy the type_specific bits.
4127 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
4128 base classes and methods. There's no fundamental reason why we
4129 can't, but at the moment it is not needed. */
4131 if (TYPE_CODE (type) == TYPE_CODE_FLT)
4132 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
4133 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4134 || TYPE_CODE (type) == TYPE_CODE_UNION
4135 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
4136 INIT_CPLUS_SPECIFIC (new_type);
4141 /* Make a copy of the given TYPE, except that the pointer & reference
4142 types are not preserved.
4144 This function assumes that the given type has an associated objfile.
4145 This objfile is used to allocate the new type. */
4148 copy_type (const struct type *type)
4150 struct type *new_type;
4152 gdb_assert (TYPE_OBJFILE_OWNED (type));
4154 new_type = alloc_type_copy (type);
4155 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4156 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4157 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
4158 sizeof (struct main_type));
4163 /* Helper functions to initialize architecture-specific types. */
4165 /* Allocate a type structure associated with GDBARCH and set its
4166 CODE, LENGTH, and NAME fields. */
4169 arch_type (struct gdbarch *gdbarch,
4170 enum type_code code, int length, char *name)
4174 type = alloc_type_arch (gdbarch);
4175 TYPE_CODE (type) = code;
4176 TYPE_LENGTH (type) = length;
4179 TYPE_NAME (type) = xstrdup (name);
4184 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
4185 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4186 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4189 arch_integer_type (struct gdbarch *gdbarch,
4190 int bit, int unsigned_p, char *name)
4194 t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
4196 TYPE_UNSIGNED (t) = 1;
4197 if (name && strcmp (name, "char") == 0)
4198 TYPE_NOSIGN (t) = 1;
4203 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
4204 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4205 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4208 arch_character_type (struct gdbarch *gdbarch,
4209 int bit, int unsigned_p, char *name)
4213 t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
4215 TYPE_UNSIGNED (t) = 1;
4220 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
4221 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4222 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4225 arch_boolean_type (struct gdbarch *gdbarch,
4226 int bit, int unsigned_p, char *name)
4230 t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
4232 TYPE_UNSIGNED (t) = 1;
4237 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
4238 BIT is the type size in bits; if BIT equals -1, the size is
4239 determined by the floatformat. NAME is the type name. Set the
4240 TYPE_FLOATFORMAT from FLOATFORMATS. */
4243 arch_float_type (struct gdbarch *gdbarch,
4244 int bit, char *name, const struct floatformat **floatformats)
4250 gdb_assert (floatformats != NULL);
4251 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
4252 bit = floatformats[0]->totalsize;
4254 gdb_assert (bit >= 0);
4256 t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
4257 TYPE_FLOATFORMAT (t) = floatformats;
4261 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
4262 NAME is the type name. TARGET_TYPE is the component float type. */
4265 arch_complex_type (struct gdbarch *gdbarch,
4266 char *name, struct type *target_type)
4270 t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
4271 2 * TYPE_LENGTH (target_type), name);
4272 TYPE_TARGET_TYPE (t) = target_type;
4276 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
4277 NAME is the type name. LENGTH is the size of the flag word in bytes. */
4280 arch_flags_type (struct gdbarch *gdbarch, char *name, int length)
4282 int nfields = length * TARGET_CHAR_BIT;
4285 type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name);
4286 TYPE_UNSIGNED (type) = 1;
4287 TYPE_NFIELDS (type) = nfields;
4288 TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
4293 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
4294 position BITPOS is called NAME. */
4297 append_flags_type_flag (struct type *type, int bitpos, char *name)
4299 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
4300 gdb_assert (bitpos < TYPE_NFIELDS (type));
4301 gdb_assert (bitpos >= 0);
4305 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
4306 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), bitpos);
4310 /* Don't show this field to the user. */
4311 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), -1);
4315 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
4316 specified by CODE) associated with GDBARCH. NAME is the type name. */
4319 arch_composite_type (struct gdbarch *gdbarch, char *name, enum type_code code)
4323 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
4324 t = arch_type (gdbarch, code, 0, NULL);
4325 TYPE_TAG_NAME (t) = name;
4326 INIT_CPLUS_SPECIFIC (t);
4330 /* Add new field with name NAME and type FIELD to composite type T.
4331 Do not set the field's position or adjust the type's length;
4332 the caller should do so. Return the new field. */
4335 append_composite_type_field_raw (struct type *t, char *name,
4340 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
4341 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
4342 sizeof (struct field) * TYPE_NFIELDS (t));
4343 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
4344 memset (f, 0, sizeof f[0]);
4345 FIELD_TYPE (f[0]) = field;
4346 FIELD_NAME (f[0]) = name;
4350 /* Add new field with name NAME and type FIELD to composite type T.
4351 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
4354 append_composite_type_field_aligned (struct type *t, char *name,
4355 struct type *field, int alignment)
4357 struct field *f = append_composite_type_field_raw (t, name, field);
4359 if (TYPE_CODE (t) == TYPE_CODE_UNION)
4361 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
4362 TYPE_LENGTH (t) = TYPE_LENGTH (field);
4364 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
4366 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
4367 if (TYPE_NFIELDS (t) > 1)
4369 SET_FIELD_BITPOS (f[0],
4370 (FIELD_BITPOS (f[-1])
4371 + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
4372 * TARGET_CHAR_BIT)));
4378 alignment *= TARGET_CHAR_BIT;
4379 left = FIELD_BITPOS (f[0]) % alignment;
4383 SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left));
4384 TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
4391 /* Add new field with name NAME and type FIELD to composite type T. */
4394 append_composite_type_field (struct type *t, char *name,
4397 append_composite_type_field_aligned (t, name, field, 0);
4400 static struct gdbarch_data *gdbtypes_data;
4402 const struct builtin_type *
4403 builtin_type (struct gdbarch *gdbarch)
4405 return gdbarch_data (gdbarch, gdbtypes_data);
4409 gdbtypes_post_init (struct gdbarch *gdbarch)
4411 struct builtin_type *builtin_type
4412 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
4415 builtin_type->builtin_void
4416 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
4417 builtin_type->builtin_char
4418 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4419 !gdbarch_char_signed (gdbarch), "char");
4420 builtin_type->builtin_signed_char
4421 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4423 builtin_type->builtin_unsigned_char
4424 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4425 1, "unsigned char");
4426 builtin_type->builtin_short
4427 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
4429 builtin_type->builtin_unsigned_short
4430 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
4431 1, "unsigned short");
4432 builtin_type->builtin_int
4433 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
4435 builtin_type->builtin_unsigned_int
4436 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
4438 builtin_type->builtin_long
4439 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
4441 builtin_type->builtin_unsigned_long
4442 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
4443 1, "unsigned long");
4444 builtin_type->builtin_long_long
4445 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
4447 builtin_type->builtin_unsigned_long_long
4448 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
4449 1, "unsigned long long");
4450 builtin_type->builtin_float
4451 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
4452 "float", gdbarch_float_format (gdbarch));
4453 builtin_type->builtin_double
4454 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
4455 "double", gdbarch_double_format (gdbarch));
4456 builtin_type->builtin_long_double
4457 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
4458 "long double", gdbarch_long_double_format (gdbarch));
4459 builtin_type->builtin_complex
4460 = arch_complex_type (gdbarch, "complex",
4461 builtin_type->builtin_float);
4462 builtin_type->builtin_double_complex
4463 = arch_complex_type (gdbarch, "double complex",
4464 builtin_type->builtin_double);
4465 builtin_type->builtin_string
4466 = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string");
4467 builtin_type->builtin_bool
4468 = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool");
4470 /* The following three are about decimal floating point types, which
4471 are 32-bits, 64-bits and 128-bits respectively. */
4472 builtin_type->builtin_decfloat
4473 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 32 / 8, "_Decimal32");
4474 builtin_type->builtin_decdouble
4475 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 64 / 8, "_Decimal64");
4476 builtin_type->builtin_declong
4477 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 128 / 8, "_Decimal128");
4479 /* "True" character types. */
4480 builtin_type->builtin_true_char
4481 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character");
4482 builtin_type->builtin_true_unsigned_char
4483 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character");
4485 /* Fixed-size integer types. */
4486 builtin_type->builtin_int0
4487 = arch_integer_type (gdbarch, 0, 0, "int0_t");
4488 builtin_type->builtin_int8
4489 = arch_integer_type (gdbarch, 8, 0, "int8_t");
4490 builtin_type->builtin_uint8
4491 = arch_integer_type (gdbarch, 8, 1, "uint8_t");
4492 builtin_type->builtin_int16
4493 = arch_integer_type (gdbarch, 16, 0, "int16_t");
4494 builtin_type->builtin_uint16
4495 = arch_integer_type (gdbarch, 16, 1, "uint16_t");
4496 builtin_type->builtin_int32
4497 = arch_integer_type (gdbarch, 32, 0, "int32_t");
4498 builtin_type->builtin_uint32
4499 = arch_integer_type (gdbarch, 32, 1, "uint32_t");
4500 builtin_type->builtin_int64
4501 = arch_integer_type (gdbarch, 64, 0, "int64_t");
4502 builtin_type->builtin_uint64
4503 = arch_integer_type (gdbarch, 64, 1, "uint64_t");
4504 builtin_type->builtin_int128
4505 = arch_integer_type (gdbarch, 128, 0, "int128_t");
4506 builtin_type->builtin_uint128
4507 = arch_integer_type (gdbarch, 128, 1, "uint128_t");
4508 TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |=
4509 TYPE_INSTANCE_FLAG_NOTTEXT;
4510 TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |=
4511 TYPE_INSTANCE_FLAG_NOTTEXT;
4513 /* Wide character types. */
4514 builtin_type->builtin_char16
4515 = arch_integer_type (gdbarch, 16, 0, "char16_t");
4516 builtin_type->builtin_char32
4517 = arch_integer_type (gdbarch, 32, 0, "char32_t");
4520 /* Default data/code pointer types. */
4521 builtin_type->builtin_data_ptr
4522 = lookup_pointer_type (builtin_type->builtin_void);
4523 builtin_type->builtin_func_ptr
4524 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
4525 builtin_type->builtin_func_func
4526 = lookup_function_type (builtin_type->builtin_func_ptr);
4528 /* This type represents a GDB internal function. */
4529 builtin_type->internal_fn
4530 = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0,
4531 "<internal function>");
4533 /* This type represents an xmethod. */
4534 builtin_type->xmethod
4535 = arch_type (gdbarch, TYPE_CODE_XMETHOD, 0, "<xmethod>");
4537 return builtin_type;
4540 /* This set of objfile-based types is intended to be used by symbol
4541 readers as basic types. */
4543 static const struct objfile_data *objfile_type_data;
4545 const struct objfile_type *
4546 objfile_type (struct objfile *objfile)
4548 struct gdbarch *gdbarch;
4549 struct objfile_type *objfile_type
4550 = objfile_data (objfile, objfile_type_data);
4553 return objfile_type;
4555 objfile_type = OBSTACK_CALLOC (&objfile->objfile_obstack,
4556 1, struct objfile_type);
4558 /* Use the objfile architecture to determine basic type properties. */
4559 gdbarch = get_objfile_arch (objfile);
4562 objfile_type->builtin_void
4563 = init_type (TYPE_CODE_VOID, 1,
4567 objfile_type->builtin_char
4568 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4570 | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
4572 objfile_type->builtin_signed_char
4573 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4575 "signed char", objfile);
4576 objfile_type->builtin_unsigned_char
4577 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4579 "unsigned char", objfile);
4580 objfile_type->builtin_short
4581 = init_type (TYPE_CODE_INT,
4582 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4583 0, "short", objfile);
4584 objfile_type->builtin_unsigned_short
4585 = init_type (TYPE_CODE_INT,
4586 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4587 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
4588 objfile_type->builtin_int
4589 = init_type (TYPE_CODE_INT,
4590 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4592 objfile_type->builtin_unsigned_int
4593 = init_type (TYPE_CODE_INT,
4594 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4595 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
4596 objfile_type->builtin_long
4597 = init_type (TYPE_CODE_INT,
4598 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4599 0, "long", objfile);
4600 objfile_type->builtin_unsigned_long
4601 = init_type (TYPE_CODE_INT,
4602 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4603 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
4604 objfile_type->builtin_long_long
4605 = init_type (TYPE_CODE_INT,
4606 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4607 0, "long long", objfile);
4608 objfile_type->builtin_unsigned_long_long
4609 = init_type (TYPE_CODE_INT,
4610 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4611 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
4613 objfile_type->builtin_float
4614 = init_type (TYPE_CODE_FLT,
4615 gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT,
4616 0, "float", objfile);
4617 TYPE_FLOATFORMAT (objfile_type->builtin_float)
4618 = gdbarch_float_format (gdbarch);
4619 objfile_type->builtin_double
4620 = init_type (TYPE_CODE_FLT,
4621 gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT,
4622 0, "double", objfile);
4623 TYPE_FLOATFORMAT (objfile_type->builtin_double)
4624 = gdbarch_double_format (gdbarch);
4625 objfile_type->builtin_long_double
4626 = init_type (TYPE_CODE_FLT,
4627 gdbarch_long_double_bit (gdbarch) / TARGET_CHAR_BIT,
4628 0, "long double", objfile);
4629 TYPE_FLOATFORMAT (objfile_type->builtin_long_double)
4630 = gdbarch_long_double_format (gdbarch);
4632 /* This type represents a type that was unrecognized in symbol read-in. */
4633 objfile_type->builtin_error
4634 = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>", objfile);
4636 /* The following set of types is used for symbols with no
4637 debug information. */
4638 objfile_type->nodebug_text_symbol
4639 = init_type (TYPE_CODE_FUNC, 1, 0,
4640 "<text variable, no debug info>", objfile);
4641 TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
4642 = objfile_type->builtin_int;
4643 objfile_type->nodebug_text_gnu_ifunc_symbol
4644 = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC,
4645 "<text gnu-indirect-function variable, no debug info>",
4647 TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
4648 = objfile_type->nodebug_text_symbol;
4649 objfile_type->nodebug_got_plt_symbol
4650 = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0,
4651 "<text from jump slot in .got.plt, no debug info>",
4653 TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol)
4654 = objfile_type->nodebug_text_symbol;
4655 objfile_type->nodebug_data_symbol
4656 = init_type (TYPE_CODE_INT,
4657 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4658 "<data variable, no debug info>", objfile);
4659 objfile_type->nodebug_unknown_symbol
4660 = init_type (TYPE_CODE_INT, 1, 0,
4661 "<variable (not text or data), no debug info>", objfile);
4662 objfile_type->nodebug_tls_symbol
4663 = init_type (TYPE_CODE_INT,
4664 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4665 "<thread local variable, no debug info>", objfile);
4667 /* NOTE: on some targets, addresses and pointers are not necessarily
4671 - gdb's `struct type' always describes the target's
4673 - gdb's `struct value' objects should always hold values in
4675 - gdb's CORE_ADDR values are addresses in the unified virtual
4676 address space that the assembler and linker work with. Thus,
4677 since target_read_memory takes a CORE_ADDR as an argument, it
4678 can access any memory on the target, even if the processor has
4679 separate code and data address spaces.
4681 In this context, objfile_type->builtin_core_addr is a bit odd:
4682 it's a target type for a value the target will never see. It's
4683 only used to hold the values of (typeless) linker symbols, which
4684 are indeed in the unified virtual address space. */
4686 objfile_type->builtin_core_addr
4687 = init_type (TYPE_CODE_INT,
4688 gdbarch_addr_bit (gdbarch) / 8,
4689 TYPE_FLAG_UNSIGNED, "__CORE_ADDR", objfile);
4691 set_objfile_data (objfile, objfile_type_data, objfile_type);
4692 return objfile_type;
4695 extern initialize_file_ftype _initialize_gdbtypes;
4698 _initialize_gdbtypes (void)
4700 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
4701 objfile_type_data = register_objfile_data ();
4703 add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug,
4704 _("Set debugging of C++ overloading."),
4705 _("Show debugging of C++ overloading."),
4706 _("When enabled, ranking of the "
4707 "functions is displayed."),
4709 show_overload_debug,
4710 &setdebuglist, &showdebuglist);
4712 /* Add user knob for controlling resolution of opaque types. */
4713 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
4714 &opaque_type_resolution,
4715 _("Set resolution of opaque struct/class/union"
4716 " types (if set before loading symbols)."),
4717 _("Show resolution of opaque struct/class/union"
4718 " types (if set before loading symbols)."),
4720 show_opaque_type_resolution,
4721 &setlist, &showlist);
4723 /* Add an option to permit non-strict type checking. */
4724 add_setshow_boolean_cmd ("type", class_support,
4725 &strict_type_checking,
4726 _("Set strict type checking."),
4727 _("Show strict type checking."),
4729 show_strict_type_checking,
4730 &setchecklist, &showchecklist);