1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2015 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/>. */
28 #include "expression.h"
33 #include "complaints.h"
37 #include "cp-support.h"
39 #include "dwarf2loc.h"
42 /* Initialize BADNESS constants. */
44 const struct rank LENGTH_MISMATCH_BADNESS = {100,0};
46 const struct rank TOO_FEW_PARAMS_BADNESS = {100,0};
47 const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0};
49 const struct rank EXACT_MATCH_BADNESS = {0,0};
51 const struct rank INTEGER_PROMOTION_BADNESS = {1,0};
52 const struct rank FLOAT_PROMOTION_BADNESS = {1,0};
53 const struct rank BASE_PTR_CONVERSION_BADNESS = {1,0};
54 const struct rank INTEGER_CONVERSION_BADNESS = {2,0};
55 const struct rank FLOAT_CONVERSION_BADNESS = {2,0};
56 const struct rank INT_FLOAT_CONVERSION_BADNESS = {2,0};
57 const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0};
58 const struct rank BOOL_CONVERSION_BADNESS = {3,0};
59 const struct rank BASE_CONVERSION_BADNESS = {2,0};
60 const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
61 const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
62 const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
63 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
65 /* Floatformat pairs. */
66 const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
67 &floatformat_ieee_half_big,
68 &floatformat_ieee_half_little
70 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
71 &floatformat_ieee_single_big,
72 &floatformat_ieee_single_little
74 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
75 &floatformat_ieee_double_big,
76 &floatformat_ieee_double_little
78 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
79 &floatformat_ieee_double_big,
80 &floatformat_ieee_double_littlebyte_bigword
82 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
83 &floatformat_i387_ext,
86 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
87 &floatformat_m68881_ext,
88 &floatformat_m68881_ext
90 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
91 &floatformat_arm_ext_big,
92 &floatformat_arm_ext_littlebyte_bigword
94 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
95 &floatformat_ia64_spill_big,
96 &floatformat_ia64_spill_little
98 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
99 &floatformat_ia64_quad_big,
100 &floatformat_ia64_quad_little
102 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
106 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
110 const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
111 &floatformat_ibm_long_double_big,
112 &floatformat_ibm_long_double_little
115 /* Should opaque types be resolved? */
117 static int opaque_type_resolution = 1;
119 /* A flag to enable printing of debugging information of C++
122 unsigned int overload_debug = 0;
124 /* A flag to enable strict type checking. */
126 static int strict_type_checking = 1;
128 /* A function to show whether opaque types are resolved. */
131 show_opaque_type_resolution (struct ui_file *file, int from_tty,
132 struct cmd_list_element *c,
135 fprintf_filtered (file, _("Resolution of opaque struct/class/union types "
136 "(if set before loading symbols) is %s.\n"),
140 /* A function to show whether C++ overload debugging is enabled. */
143 show_overload_debug (struct ui_file *file, int from_tty,
144 struct cmd_list_element *c, const char *value)
146 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
150 /* A function to show the status of strict type checking. */
153 show_strict_type_checking (struct ui_file *file, int from_tty,
154 struct cmd_list_element *c, const char *value)
156 fprintf_filtered (file, _("Strict type checking is %s.\n"), value);
160 /* Allocate a new OBJFILE-associated type structure and fill it
161 with some defaults. Space for the type structure is allocated
162 on the objfile's objfile_obstack. */
165 alloc_type (struct objfile *objfile)
169 gdb_assert (objfile != NULL);
171 /* Alloc the structure and start off with all fields zeroed. */
172 type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
173 TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
175 OBJSTAT (objfile, n_types++);
177 TYPE_OBJFILE_OWNED (type) = 1;
178 TYPE_OWNER (type).objfile = objfile;
180 /* Initialize the fields that might not be zero. */
182 TYPE_CODE (type) = TYPE_CODE_UNDEF;
183 TYPE_VPTR_FIELDNO (type) = -1;
184 TYPE_CHAIN (type) = type; /* Chain back to itself. */
189 /* Allocate a new GDBARCH-associated type structure and fill it
190 with some defaults. Space for the type structure is allocated
194 alloc_type_arch (struct gdbarch *gdbarch)
198 gdb_assert (gdbarch != NULL);
200 /* Alloc the structure and start off with all fields zeroed. */
202 type = XCNEW (struct type);
203 TYPE_MAIN_TYPE (type) = XCNEW (struct main_type);
205 TYPE_OBJFILE_OWNED (type) = 0;
206 TYPE_OWNER (type).gdbarch = gdbarch;
208 /* Initialize the fields that might not be zero. */
210 TYPE_CODE (type) = TYPE_CODE_UNDEF;
211 TYPE_VPTR_FIELDNO (type) = -1;
212 TYPE_CHAIN (type) = type; /* Chain back to itself. */
217 /* If TYPE is objfile-associated, allocate a new type structure
218 associated with the same objfile. If TYPE is gdbarch-associated,
219 allocate a new type structure associated with the same gdbarch. */
222 alloc_type_copy (const struct type *type)
224 if (TYPE_OBJFILE_OWNED (type))
225 return alloc_type (TYPE_OWNER (type).objfile);
227 return alloc_type_arch (TYPE_OWNER (type).gdbarch);
230 /* If TYPE is gdbarch-associated, return that architecture.
231 If TYPE is objfile-associated, return that objfile's architecture. */
234 get_type_arch (const struct type *type)
236 if (TYPE_OBJFILE_OWNED (type))
237 return get_objfile_arch (TYPE_OWNER (type).objfile);
239 return TYPE_OWNER (type).gdbarch;
242 /* See gdbtypes.h. */
245 get_target_type (struct type *type)
249 type = TYPE_TARGET_TYPE (type);
251 type = check_typedef (type);
257 /* Alloc a new type instance structure, fill it with some defaults,
258 and point it at OLDTYPE. Allocate the new type instance from the
259 same place as OLDTYPE. */
262 alloc_type_instance (struct type *oldtype)
266 /* Allocate the structure. */
268 if (! TYPE_OBJFILE_OWNED (oldtype))
269 type = XCNEW (struct type);
271 type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
274 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
276 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
281 /* Clear all remnants of the previous type at TYPE, in preparation for
282 replacing it with something else. Preserve owner information. */
285 smash_type (struct type *type)
287 int objfile_owned = TYPE_OBJFILE_OWNED (type);
288 union type_owner owner = TYPE_OWNER (type);
290 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
292 /* Restore owner information. */
293 TYPE_OBJFILE_OWNED (type) = objfile_owned;
294 TYPE_OWNER (type) = owner;
296 /* For now, delete the rings. */
297 TYPE_CHAIN (type) = type;
299 /* For now, leave the pointer/reference types alone. */
302 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
303 to a pointer to memory where the pointer type should be stored.
304 If *TYPEPTR is zero, update it to point to the pointer type we return.
305 We allocate new memory if needed. */
308 make_pointer_type (struct type *type, struct type **typeptr)
310 struct type *ntype; /* New type */
313 ntype = TYPE_POINTER_TYPE (type);
318 return ntype; /* Don't care about alloc,
319 and have new type. */
320 else if (*typeptr == 0)
322 *typeptr = ntype; /* Tracking alloc, and have new type. */
327 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
329 ntype = alloc_type_copy (type);
333 else /* We have storage, but need to reset it. */
336 chain = TYPE_CHAIN (ntype);
338 TYPE_CHAIN (ntype) = chain;
341 TYPE_TARGET_TYPE (ntype) = type;
342 TYPE_POINTER_TYPE (type) = ntype;
344 /* FIXME! Assumes the machine has only one representation for pointers! */
347 = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
348 TYPE_CODE (ntype) = TYPE_CODE_PTR;
350 /* Mark pointers as unsigned. The target converts between pointers
351 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
352 gdbarch_address_to_pointer. */
353 TYPE_UNSIGNED (ntype) = 1;
355 /* Update the length of all the other variants of this type. */
356 chain = TYPE_CHAIN (ntype);
357 while (chain != ntype)
359 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
360 chain = TYPE_CHAIN (chain);
366 /* Given a type TYPE, return a type of pointers to that type.
367 May need to construct such a type if this is the first use. */
370 lookup_pointer_type (struct type *type)
372 return make_pointer_type (type, (struct type **) 0);
375 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
376 points to a pointer to memory where the reference type should be
377 stored. If *TYPEPTR is zero, update it to point to the reference
378 type we return. We allocate new memory if needed. */
381 make_reference_type (struct type *type, struct type **typeptr)
383 struct type *ntype; /* New type */
386 ntype = TYPE_REFERENCE_TYPE (type);
391 return ntype; /* Don't care about alloc,
392 and have new type. */
393 else if (*typeptr == 0)
395 *typeptr = ntype; /* Tracking alloc, and have new type. */
400 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
402 ntype = alloc_type_copy (type);
406 else /* We have storage, but need to reset it. */
409 chain = TYPE_CHAIN (ntype);
411 TYPE_CHAIN (ntype) = chain;
414 TYPE_TARGET_TYPE (ntype) = type;
415 TYPE_REFERENCE_TYPE (type) = ntype;
417 /* FIXME! Assume the machine has only one representation for
418 references, and that it matches the (only) representation for
421 TYPE_LENGTH (ntype) =
422 gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
423 TYPE_CODE (ntype) = TYPE_CODE_REF;
425 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
426 TYPE_REFERENCE_TYPE (type) = ntype;
428 /* Update the length of all the other variants of this type. */
429 chain = TYPE_CHAIN (ntype);
430 while (chain != ntype)
432 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
433 chain = TYPE_CHAIN (chain);
439 /* Same as above, but caller doesn't care about memory allocation
443 lookup_reference_type (struct type *type)
445 return make_reference_type (type, (struct type **) 0);
448 /* Lookup a function type that returns type TYPE. TYPEPTR, if
449 nonzero, points to a pointer to memory where the function type
450 should be stored. If *TYPEPTR is zero, update it to point to the
451 function type we return. We allocate new memory if needed. */
454 make_function_type (struct type *type, struct type **typeptr)
456 struct type *ntype; /* New type */
458 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
460 ntype = alloc_type_copy (type);
464 else /* We have storage, but need to reset it. */
470 TYPE_TARGET_TYPE (ntype) = type;
472 TYPE_LENGTH (ntype) = 1;
473 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
475 INIT_FUNC_SPECIFIC (ntype);
480 /* Given a type TYPE, return a type of functions that return that type.
481 May need to construct such a type if this is the first use. */
484 lookup_function_type (struct type *type)
486 return make_function_type (type, (struct type **) 0);
489 /* Given a type TYPE and argument types, return the appropriate
490 function type. If the final type in PARAM_TYPES is NULL, make a
494 lookup_function_type_with_arguments (struct type *type,
496 struct type **param_types)
498 struct type *fn = make_function_type (type, (struct type **) 0);
503 if (param_types[nparams - 1] == NULL)
506 TYPE_VARARGS (fn) = 1;
508 else if (TYPE_CODE (check_typedef (param_types[nparams - 1]))
512 /* Caller should have ensured this. */
513 gdb_assert (nparams == 0);
514 TYPE_PROTOTYPED (fn) = 1;
518 TYPE_NFIELDS (fn) = nparams;
519 TYPE_FIELDS (fn) = TYPE_ZALLOC (fn, nparams * sizeof (struct field));
520 for (i = 0; i < nparams; ++i)
521 TYPE_FIELD_TYPE (fn, i) = param_types[i];
526 /* Identify address space identifier by name --
527 return the integer flag defined in gdbtypes.h. */
530 address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
534 /* Check for known address space delimiters. */
535 if (!strcmp (space_identifier, "code"))
536 return TYPE_INSTANCE_FLAG_CODE_SPACE;
537 else if (!strcmp (space_identifier, "data"))
538 return TYPE_INSTANCE_FLAG_DATA_SPACE;
539 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
540 && gdbarch_address_class_name_to_type_flags (gdbarch,
545 error (_("Unknown address space specifier: \"%s\""), space_identifier);
548 /* Identify address space identifier by integer flag as defined in
549 gdbtypes.h -- return the string version of the adress space name. */
552 address_space_int_to_name (struct gdbarch *gdbarch, int space_flag)
554 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
556 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
558 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
559 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
560 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
565 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
567 If STORAGE is non-NULL, create the new type instance there.
568 STORAGE must be in the same obstack as TYPE. */
571 make_qualified_type (struct type *type, int new_flags,
572 struct type *storage)
579 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
581 ntype = TYPE_CHAIN (ntype);
583 while (ntype != type);
585 /* Create a new type instance. */
587 ntype = alloc_type_instance (type);
590 /* If STORAGE was provided, it had better be in the same objfile
591 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
592 if one objfile is freed and the other kept, we'd have
593 dangling pointers. */
594 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
597 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
598 TYPE_CHAIN (ntype) = ntype;
601 /* Pointers or references to the original type are not relevant to
603 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
604 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
606 /* Chain the new qualified type to the old type. */
607 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
608 TYPE_CHAIN (type) = ntype;
610 /* Now set the instance flags and return the new type. */
611 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
613 /* Set length of new type to that of the original type. */
614 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
619 /* Make an address-space-delimited variant of a type -- a type that
620 is identical to the one supplied except that it has an address
621 space attribute attached to it (such as "code" or "data").
623 The space attributes "code" and "data" are for Harvard
624 architectures. The address space attributes are for architectures
625 which have alternately sized pointers or pointers with alternate
629 make_type_with_address_space (struct type *type, int space_flag)
631 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
632 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
633 | TYPE_INSTANCE_FLAG_DATA_SPACE
634 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
637 return make_qualified_type (type, new_flags, NULL);
640 /* Make a "c-v" variant of a type -- a type that is identical to the
641 one supplied except that it may have const or volatile attributes
642 CNST is a flag for setting the const attribute
643 VOLTL is a flag for setting the volatile attribute
644 TYPE is the base type whose variant we are creating.
646 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
647 storage to hold the new qualified type; *TYPEPTR and TYPE must be
648 in the same objfile. Otherwise, allocate fresh memory for the new
649 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
650 new type we construct. */
653 make_cv_type (int cnst, int voltl,
655 struct type **typeptr)
657 struct type *ntype; /* New type */
659 int new_flags = (TYPE_INSTANCE_FLAGS (type)
660 & ~(TYPE_INSTANCE_FLAG_CONST
661 | TYPE_INSTANCE_FLAG_VOLATILE));
664 new_flags |= TYPE_INSTANCE_FLAG_CONST;
667 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
669 if (typeptr && *typeptr != NULL)
671 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
672 a C-V variant chain that threads across objfiles: if one
673 objfile gets freed, then the other has a broken C-V chain.
675 This code used to try to copy over the main type from TYPE to
676 *TYPEPTR if they were in different objfiles, but that's
677 wrong, too: TYPE may have a field list or member function
678 lists, which refer to types of their own, etc. etc. The
679 whole shebang would need to be copied over recursively; you
680 can't have inter-objfile pointers. The only thing to do is
681 to leave stub types as stub types, and look them up afresh by
682 name each time you encounter them. */
683 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
686 ntype = make_qualified_type (type, new_flags,
687 typeptr ? *typeptr : NULL);
695 /* Make a 'restrict'-qualified version of TYPE. */
698 make_restrict_type (struct type *type)
700 return make_qualified_type (type,
701 (TYPE_INSTANCE_FLAGS (type)
702 | TYPE_INSTANCE_FLAG_RESTRICT),
706 /* Make a type without const, volatile, or restrict. */
709 make_unqualified_type (struct type *type)
711 return make_qualified_type (type,
712 (TYPE_INSTANCE_FLAGS (type)
713 & ~(TYPE_INSTANCE_FLAG_CONST
714 | TYPE_INSTANCE_FLAG_VOLATILE
715 | TYPE_INSTANCE_FLAG_RESTRICT)),
719 /* Replace the contents of ntype with the type *type. This changes the
720 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
721 the changes are propogated to all types in the TYPE_CHAIN.
723 In order to build recursive types, it's inevitable that we'll need
724 to update types in place --- but this sort of indiscriminate
725 smashing is ugly, and needs to be replaced with something more
726 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
727 clear if more steps are needed. */
730 replace_type (struct type *ntype, struct type *type)
734 /* These two types had better be in the same objfile. Otherwise,
735 the assignment of one type's main type structure to the other
736 will produce a type with references to objects (names; field
737 lists; etc.) allocated on an objfile other than its own. */
738 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
740 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
742 /* The type length is not a part of the main type. Update it for
743 each type on the variant chain. */
747 /* Assert that this element of the chain has no address-class bits
748 set in its flags. Such type variants might have type lengths
749 which are supposed to be different from the non-address-class
750 variants. This assertion shouldn't ever be triggered because
751 symbol readers which do construct address-class variants don't
752 call replace_type(). */
753 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
755 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
756 chain = TYPE_CHAIN (chain);
758 while (ntype != chain);
760 /* Assert that the two types have equivalent instance qualifiers.
761 This should be true for at least all of our debug readers. */
762 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
765 /* Implement direct support for MEMBER_TYPE in GNU C++.
766 May need to construct such a type if this is the first use.
767 The TYPE is the type of the member. The DOMAIN is the type
768 of the aggregate that the member belongs to. */
771 lookup_memberptr_type (struct type *type, struct type *domain)
775 mtype = alloc_type_copy (type);
776 smash_to_memberptr_type (mtype, domain, type);
780 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
783 lookup_methodptr_type (struct type *to_type)
787 mtype = alloc_type_copy (to_type);
788 smash_to_methodptr_type (mtype, to_type);
792 /* Allocate a stub method whose return type is TYPE. This apparently
793 happens for speed of symbol reading, since parsing out the
794 arguments to the method is cpu-intensive, the way we are doing it.
795 So, we will fill in arguments later. This always returns a fresh
799 allocate_stub_method (struct type *type)
803 mtype = alloc_type_copy (type);
804 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
805 TYPE_LENGTH (mtype) = 1;
806 TYPE_STUB (mtype) = 1;
807 TYPE_TARGET_TYPE (mtype) = type;
808 /* TYPE_SELF_TYPE (mtype) = unknown yet */
812 /* Create a range type with a dynamic range from LOW_BOUND to
813 HIGH_BOUND, inclusive. See create_range_type for further details. */
816 create_range_type (struct type *result_type, struct type *index_type,
817 const struct dynamic_prop *low_bound,
818 const struct dynamic_prop *high_bound)
820 if (result_type == NULL)
821 result_type = alloc_type_copy (index_type);
822 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
823 TYPE_TARGET_TYPE (result_type) = index_type;
824 if (TYPE_STUB (index_type))
825 TYPE_TARGET_STUB (result_type) = 1;
827 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
829 TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
830 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
831 TYPE_RANGE_DATA (result_type)->low = *low_bound;
832 TYPE_RANGE_DATA (result_type)->high = *high_bound;
834 if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
835 TYPE_UNSIGNED (result_type) = 1;
837 /* Ada allows the declaration of range types whose upper bound is
838 less than the lower bound, so checking the lower bound is not
839 enough. Make sure we do not mark a range type whose upper bound
840 is negative as unsigned. */
841 if (high_bound->kind == PROP_CONST && high_bound->data.const_val < 0)
842 TYPE_UNSIGNED (result_type) = 0;
847 /* Create a range type using either a blank type supplied in
848 RESULT_TYPE, or creating a new type, inheriting the objfile from
851 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
852 to HIGH_BOUND, inclusive.
854 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
855 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
858 create_static_range_type (struct type *result_type, struct type *index_type,
859 LONGEST low_bound, LONGEST high_bound)
861 struct dynamic_prop low, high;
863 low.kind = PROP_CONST;
864 low.data.const_val = low_bound;
866 high.kind = PROP_CONST;
867 high.data.const_val = high_bound;
869 result_type = create_range_type (result_type, index_type, &low, &high);
874 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
875 are static, otherwise returns 0. */
878 has_static_range (const struct range_bounds *bounds)
880 return (bounds->low.kind == PROP_CONST
881 && bounds->high.kind == PROP_CONST);
885 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
886 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
887 bounds will fit in LONGEST), or -1 otherwise. */
890 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
892 CHECK_TYPEDEF (type);
893 switch (TYPE_CODE (type))
895 case TYPE_CODE_RANGE:
896 *lowp = TYPE_LOW_BOUND (type);
897 *highp = TYPE_HIGH_BOUND (type);
900 if (TYPE_NFIELDS (type) > 0)
902 /* The enums may not be sorted by value, so search all
906 *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
907 for (i = 0; i < TYPE_NFIELDS (type); i++)
909 if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
910 *lowp = TYPE_FIELD_ENUMVAL (type, i);
911 if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
912 *highp = TYPE_FIELD_ENUMVAL (type, i);
915 /* Set unsigned indicator if warranted. */
918 TYPE_UNSIGNED (type) = 1;
932 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
934 if (!TYPE_UNSIGNED (type))
936 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
940 /* ... fall through for unsigned ints ... */
943 /* This round-about calculation is to avoid shifting by
944 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
945 if TYPE_LENGTH (type) == sizeof (LONGEST). */
946 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
947 *highp = (*highp - 1) | *highp;
954 /* Assuming TYPE is a simple, non-empty array type, compute its upper
955 and lower bound. Save the low bound into LOW_BOUND if not NULL.
956 Save the high bound into HIGH_BOUND if not NULL.
958 Return 1 if the operation was successful. Return zero otherwise,
959 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
961 We now simply use get_discrete_bounds call to get the values
962 of the low and high bounds.
963 get_discrete_bounds can return three values:
964 1, meaning that index is a range,
965 0, meaning that index is a discrete type,
966 or -1 for failure. */
969 get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
971 struct type *index = TYPE_INDEX_TYPE (type);
979 res = get_discrete_bounds (index, &low, &high);
983 /* Check if the array bounds are undefined. */
985 && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
986 || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
998 /* Create an array type using either a blank type supplied in
999 RESULT_TYPE, or creating a new type, inheriting the objfile from
1002 Elements will be of type ELEMENT_TYPE, the indices will be of type
1005 If BIT_STRIDE is not zero, build a packed array type whose element
1006 size is BIT_STRIDE. Otherwise, ignore this parameter.
1008 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1009 sure it is TYPE_CODE_UNDEF before we bash it into an array
1013 create_array_type_with_stride (struct type *result_type,
1014 struct type *element_type,
1015 struct type *range_type,
1016 unsigned int bit_stride)
1018 if (result_type == NULL)
1019 result_type = alloc_type_copy (range_type);
1021 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
1022 TYPE_TARGET_TYPE (result_type) = element_type;
1023 if (has_static_range (TYPE_RANGE_DATA (range_type)))
1025 LONGEST low_bound, high_bound;
1027 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
1028 low_bound = high_bound = 0;
1029 CHECK_TYPEDEF (element_type);
1030 /* Be careful when setting the array length. Ada arrays can be
1031 empty arrays with the high_bound being smaller than the low_bound.
1032 In such cases, the array length should be zero. */
1033 if (high_bound < low_bound)
1034 TYPE_LENGTH (result_type) = 0;
1035 else if (bit_stride > 0)
1036 TYPE_LENGTH (result_type) =
1037 (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
1039 TYPE_LENGTH (result_type) =
1040 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
1044 /* This type is dynamic and its length needs to be computed
1045 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1046 undefined by setting it to zero. Although we are not expected
1047 to trust TYPE_LENGTH in this case, setting the size to zero
1048 allows us to avoid allocating objects of random sizes in case
1049 we accidently do. */
1050 TYPE_LENGTH (result_type) = 0;
1053 TYPE_NFIELDS (result_type) = 1;
1054 TYPE_FIELDS (result_type) =
1055 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
1056 TYPE_INDEX_TYPE (result_type) = range_type;
1057 TYPE_VPTR_FIELDNO (result_type) = -1;
1059 TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride;
1061 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */
1062 if (TYPE_LENGTH (result_type) == 0)
1063 TYPE_TARGET_STUB (result_type) = 1;
1068 /* Same as create_array_type_with_stride but with no bit_stride
1069 (BIT_STRIDE = 0), thus building an unpacked array. */
1072 create_array_type (struct type *result_type,
1073 struct type *element_type,
1074 struct type *range_type)
1076 return create_array_type_with_stride (result_type, element_type,
1081 lookup_array_range_type (struct type *element_type,
1082 LONGEST low_bound, LONGEST high_bound)
1084 struct gdbarch *gdbarch = get_type_arch (element_type);
1085 struct type *index_type = builtin_type (gdbarch)->builtin_int;
1086 struct type *range_type
1087 = create_static_range_type (NULL, index_type, low_bound, high_bound);
1089 return create_array_type (NULL, element_type, range_type);
1092 /* Create a string type using either a blank type supplied in
1093 RESULT_TYPE, or creating a new type. String types are similar
1094 enough to array of char types that we can use create_array_type to
1095 build the basic type and then bash it into a string type.
1097 For fixed length strings, the range type contains 0 as the lower
1098 bound and the length of the string minus one as the upper bound.
1100 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1101 sure it is TYPE_CODE_UNDEF before we bash it into a string
1105 create_string_type (struct type *result_type,
1106 struct type *string_char_type,
1107 struct type *range_type)
1109 result_type = create_array_type (result_type,
1112 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1117 lookup_string_range_type (struct type *string_char_type,
1118 LONGEST low_bound, LONGEST high_bound)
1120 struct type *result_type;
1122 result_type = lookup_array_range_type (string_char_type,
1123 low_bound, high_bound);
1124 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1129 create_set_type (struct type *result_type, struct type *domain_type)
1131 if (result_type == NULL)
1132 result_type = alloc_type_copy (domain_type);
1134 TYPE_CODE (result_type) = TYPE_CODE_SET;
1135 TYPE_NFIELDS (result_type) = 1;
1136 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
1138 if (!TYPE_STUB (domain_type))
1140 LONGEST low_bound, high_bound, bit_length;
1142 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
1143 low_bound = high_bound = 0;
1144 bit_length = high_bound - low_bound + 1;
1145 TYPE_LENGTH (result_type)
1146 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1148 TYPE_UNSIGNED (result_type) = 1;
1150 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
1155 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1156 and any array types nested inside it. */
1159 make_vector_type (struct type *array_type)
1161 struct type *inner_array, *elt_type;
1164 /* Find the innermost array type, in case the array is
1165 multi-dimensional. */
1166 inner_array = array_type;
1167 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
1168 inner_array = TYPE_TARGET_TYPE (inner_array);
1170 elt_type = TYPE_TARGET_TYPE (inner_array);
1171 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
1173 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT;
1174 elt_type = make_qualified_type (elt_type, flags, NULL);
1175 TYPE_TARGET_TYPE (inner_array) = elt_type;
1178 TYPE_VECTOR (array_type) = 1;
1182 init_vector_type (struct type *elt_type, int n)
1184 struct type *array_type;
1186 array_type = lookup_array_range_type (elt_type, 0, n - 1);
1187 make_vector_type (array_type);
1191 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
1192 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1193 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1194 TYPE doesn't include the offset (that's the value of the MEMBER
1195 itself), but does include the structure type into which it points
1198 When "smashing" the type, we preserve the objfile that the old type
1199 pointed to, since we aren't changing where the type is actually
1203 smash_to_memberptr_type (struct type *type, struct type *domain,
1204 struct type *to_type)
1207 TYPE_TARGET_TYPE (type) = to_type;
1208 TYPE_SELF_TYPE (type) = domain;
1209 /* Assume that a data member pointer is the same size as a normal
1212 = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT;
1213 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
1216 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1218 When "smashing" the type, we preserve the objfile that the old type
1219 pointed to, since we aren't changing where the type is actually
1223 smash_to_methodptr_type (struct type *type, struct type *to_type)
1226 TYPE_TARGET_TYPE (type) = to_type;
1227 TYPE_SELF_TYPE (type) = TYPE_SELF_TYPE (to_type);
1228 TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
1229 TYPE_CODE (type) = TYPE_CODE_METHODPTR;
1232 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1233 METHOD just means `function that gets an extra "this" argument'.
1235 When "smashing" the type, we preserve the objfile that the old type
1236 pointed to, since we aren't changing where the type is actually
1240 smash_to_method_type (struct type *type, struct type *domain,
1241 struct type *to_type, struct field *args,
1242 int nargs, int varargs)
1245 TYPE_TARGET_TYPE (type) = to_type;
1246 TYPE_SELF_TYPE (type) = domain;
1247 TYPE_FIELDS (type) = args;
1248 TYPE_NFIELDS (type) = nargs;
1250 TYPE_VARARGS (type) = 1;
1251 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1252 TYPE_CODE (type) = TYPE_CODE_METHOD;
1255 /* Return a typename for a struct/union/enum type without "struct ",
1256 "union ", or "enum ". If the type has a NULL name, return NULL. */
1259 type_name_no_tag (const struct type *type)
1261 if (TYPE_TAG_NAME (type) != NULL)
1262 return TYPE_TAG_NAME (type);
1264 /* Is there code which expects this to return the name if there is
1265 no tag name? My guess is that this is mainly used for C++ in
1266 cases where the two will always be the same. */
1267 return TYPE_NAME (type);
1270 /* A wrapper of type_name_no_tag which calls error if the type is anonymous.
1271 Since GCC PR debug/47510 DWARF provides associated information to detect the
1272 anonymous class linkage name from its typedef.
1274 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1278 type_name_no_tag_or_error (struct type *type)
1280 struct type *saved_type = type;
1282 struct objfile *objfile;
1284 CHECK_TYPEDEF (type);
1286 name = type_name_no_tag (type);
1290 name = type_name_no_tag (saved_type);
1291 objfile = TYPE_OBJFILE (saved_type);
1292 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1293 name ? name : "<anonymous>",
1294 objfile ? objfile_name (objfile) : "<arch>");
1297 /* Lookup a typedef or primitive type named NAME, visible in lexical
1298 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1299 suitably defined. */
1302 lookup_typename (const struct language_defn *language,
1303 struct gdbarch *gdbarch, const char *name,
1304 const struct block *block, int noerr)
1309 sym = lookup_symbol_in_language (name, block, VAR_DOMAIN,
1310 language->la_language, NULL);
1311 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1312 return SYMBOL_TYPE (sym);
1316 error (_("No type named %s."), name);
1320 lookup_unsigned_typename (const struct language_defn *language,
1321 struct gdbarch *gdbarch, const char *name)
1323 char *uns = alloca (strlen (name) + 10);
1325 strcpy (uns, "unsigned ");
1326 strcpy (uns + 9, name);
1327 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0);
1331 lookup_signed_typename (const struct language_defn *language,
1332 struct gdbarch *gdbarch, const char *name)
1335 char *uns = alloca (strlen (name) + 8);
1337 strcpy (uns, "signed ");
1338 strcpy (uns + 7, name);
1339 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1);
1340 /* If we don't find "signed FOO" just try again with plain "FOO". */
1343 return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0);
1346 /* Lookup a structure type named "struct NAME",
1347 visible in lexical block BLOCK. */
1350 lookup_struct (const char *name, const struct block *block)
1354 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1358 error (_("No struct type named %s."), name);
1360 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1362 error (_("This context has class, union or enum %s, not a struct."),
1365 return (SYMBOL_TYPE (sym));
1368 /* Lookup a union type named "union NAME",
1369 visible in lexical block BLOCK. */
1372 lookup_union (const char *name, const struct block *block)
1377 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1380 error (_("No union type named %s."), name);
1382 t = SYMBOL_TYPE (sym);
1384 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1387 /* If we get here, it's not a union. */
1388 error (_("This context has class, struct or enum %s, not a union."),
1392 /* Lookup an enum type named "enum NAME",
1393 visible in lexical block BLOCK. */
1396 lookup_enum (const char *name, const struct block *block)
1400 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1403 error (_("No enum type named %s."), name);
1405 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1407 error (_("This context has class, struct or union %s, not an enum."),
1410 return (SYMBOL_TYPE (sym));
1413 /* Lookup a template type named "template NAME<TYPE>",
1414 visible in lexical block BLOCK. */
1417 lookup_template_type (char *name, struct type *type,
1418 const struct block *block)
1421 char *nam = (char *)
1422 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1426 strcat (nam, TYPE_NAME (type));
1427 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1429 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0);
1433 error (_("No template type named %s."), name);
1435 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1437 error (_("This context has class, union or enum %s, not a struct."),
1440 return (SYMBOL_TYPE (sym));
1443 /* Given a type TYPE, lookup the type of the component of type named
1446 TYPE can be either a struct or union, or a pointer or reference to
1447 a struct or union. If it is a pointer or reference, its target
1448 type is automatically used. Thus '.' and '->' are interchangable,
1449 as specified for the definitions of the expression element types
1450 STRUCTOP_STRUCT and STRUCTOP_PTR.
1452 If NOERR is nonzero, return zero if NAME is not suitably defined.
1453 If NAME is the name of a baseclass type, return that type. */
1456 lookup_struct_elt_type (struct type *type, const char *name, int noerr)
1463 CHECK_TYPEDEF (type);
1464 if (TYPE_CODE (type) != TYPE_CODE_PTR
1465 && TYPE_CODE (type) != TYPE_CODE_REF)
1467 type = TYPE_TARGET_TYPE (type);
1470 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1471 && TYPE_CODE (type) != TYPE_CODE_UNION)
1473 typename = type_to_string (type);
1474 make_cleanup (xfree, typename);
1475 error (_("Type %s is not a structure or union type."), typename);
1479 /* FIXME: This change put in by Michael seems incorrect for the case
1480 where the structure tag name is the same as the member name.
1481 I.e. when doing "ptype bell->bar" for "struct foo { int bar; int
1482 foo; } bell;" Disabled by fnf. */
1486 typename = type_name_no_tag (type);
1487 if (typename != NULL && strcmp (typename, name) == 0)
1492 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1494 const char *t_field_name = TYPE_FIELD_NAME (type, i);
1496 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1498 return TYPE_FIELD_TYPE (type, i);
1500 else if (!t_field_name || *t_field_name == '\0')
1502 struct type *subtype
1503 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1);
1505 if (subtype != NULL)
1510 /* OK, it's not in this class. Recursively check the baseclasses. */
1511 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1515 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1527 typename = type_to_string (type);
1528 make_cleanup (xfree, typename);
1529 error (_("Type %s has no component named %s."), typename, name);
1532 /* Store in *MAX the largest number representable by unsigned integer type
1536 get_unsigned_type_max (struct type *type, ULONGEST *max)
1540 CHECK_TYPEDEF (type);
1541 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_UNSIGNED (type));
1542 gdb_assert (TYPE_LENGTH (type) <= sizeof (ULONGEST));
1544 /* Written this way to avoid overflow. */
1545 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1546 *max = ((((ULONGEST) 1 << (n - 1)) - 1) << 1) | 1;
1549 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1550 signed integer type TYPE. */
1553 get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max)
1557 CHECK_TYPEDEF (type);
1558 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && !TYPE_UNSIGNED (type));
1559 gdb_assert (TYPE_LENGTH (type) <= sizeof (LONGEST));
1561 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1562 *min = -((ULONGEST) 1 << (n - 1));
1563 *max = ((ULONGEST) 1 << (n - 1)) - 1;
1566 /* Lookup the vptr basetype/fieldno values for TYPE.
1567 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1568 vptr_fieldno. Also, if found and basetype is from the same objfile,
1570 If not found, return -1 and ignore BASETYPEP.
1571 Callers should be aware that in some cases (for example,
1572 the type or one of its baseclasses is a stub type and we are
1573 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1574 this function will not be able to find the
1575 virtual function table pointer, and vptr_fieldno will remain -1 and
1576 vptr_basetype will remain NULL or incomplete. */
1579 get_vptr_fieldno (struct type *type, struct type **basetypep)
1581 CHECK_TYPEDEF (type);
1583 if (TYPE_VPTR_FIELDNO (type) < 0)
1587 /* We must start at zero in case the first (and only) baseclass
1588 is virtual (and hence we cannot share the table pointer). */
1589 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1591 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1593 struct type *basetype;
1595 fieldno = get_vptr_fieldno (baseclass, &basetype);
1598 /* If the type comes from a different objfile we can't cache
1599 it, it may have a different lifetime. PR 2384 */
1600 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
1602 TYPE_VPTR_FIELDNO (type) = fieldno;
1603 TYPE_VPTR_BASETYPE (type) = basetype;
1606 *basetypep = basetype;
1617 *basetypep = TYPE_VPTR_BASETYPE (type);
1618 return TYPE_VPTR_FIELDNO (type);
1623 stub_noname_complaint (void)
1625 complaint (&symfile_complaints, _("stub type has NULL name"));
1628 /* Worker for is_dynamic_type. */
1631 is_dynamic_type_internal (struct type *type, int top_level)
1633 type = check_typedef (type);
1635 /* We only want to recognize references at the outermost level. */
1636 if (top_level && TYPE_CODE (type) == TYPE_CODE_REF)
1637 type = check_typedef (TYPE_TARGET_TYPE (type));
1639 /* Types that have a dynamic TYPE_DATA_LOCATION are considered
1640 dynamic, even if the type itself is statically defined.
1641 From a user's point of view, this may appear counter-intuitive;
1642 but it makes sense in this context, because the point is to determine
1643 whether any part of the type needs to be resolved before it can
1645 if (TYPE_DATA_LOCATION (type) != NULL
1646 && (TYPE_DATA_LOCATION_KIND (type) == PROP_LOCEXPR
1647 || TYPE_DATA_LOCATION_KIND (type) == PROP_LOCLIST))
1650 switch (TYPE_CODE (type))
1652 case TYPE_CODE_RANGE:
1654 /* A range type is obviously dynamic if it has at least one
1655 dynamic bound. But also consider the range type to be
1656 dynamic when its subtype is dynamic, even if the bounds
1657 of the range type are static. It allows us to assume that
1658 the subtype of a static range type is also static. */
1659 return (!has_static_range (TYPE_RANGE_DATA (type))
1660 || is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0));
1663 case TYPE_CODE_ARRAY:
1665 gdb_assert (TYPE_NFIELDS (type) == 1);
1667 /* The array is dynamic if either the bounds are dynamic,
1668 or the elements it contains have a dynamic contents. */
1669 if (is_dynamic_type_internal (TYPE_INDEX_TYPE (type), 0))
1671 return is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0);
1674 case TYPE_CODE_STRUCT:
1675 case TYPE_CODE_UNION:
1679 for (i = 0; i < TYPE_NFIELDS (type); ++i)
1680 if (!field_is_static (&TYPE_FIELD (type, i))
1681 && is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i), 0))
1690 /* See gdbtypes.h. */
1693 is_dynamic_type (struct type *type)
1695 return is_dynamic_type_internal (type, 1);
1698 static struct type *resolve_dynamic_type_internal
1699 (struct type *type, struct property_addr_info *addr_stack, int top_level);
1701 /* Given a dynamic range type (dyn_range_type) and a stack of
1702 struct property_addr_info elements, return a static version
1705 static struct type *
1706 resolve_dynamic_range (struct type *dyn_range_type,
1707 struct property_addr_info *addr_stack)
1710 struct type *static_range_type, *static_target_type;
1711 const struct dynamic_prop *prop;
1712 const struct dwarf2_locexpr_baton *baton;
1713 struct dynamic_prop low_bound, high_bound;
1715 gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
1717 prop = &TYPE_RANGE_DATA (dyn_range_type)->low;
1718 if (dwarf2_evaluate_property (prop, addr_stack, &value))
1720 low_bound.kind = PROP_CONST;
1721 low_bound.data.const_val = value;
1725 low_bound.kind = PROP_UNDEFINED;
1726 low_bound.data.const_val = 0;
1729 prop = &TYPE_RANGE_DATA (dyn_range_type)->high;
1730 if (dwarf2_evaluate_property (prop, addr_stack, &value))
1732 high_bound.kind = PROP_CONST;
1733 high_bound.data.const_val = value;
1735 if (TYPE_RANGE_DATA (dyn_range_type)->flag_upper_bound_is_count)
1736 high_bound.data.const_val
1737 = low_bound.data.const_val + high_bound.data.const_val - 1;
1741 high_bound.kind = PROP_UNDEFINED;
1742 high_bound.data.const_val = 0;
1746 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type),
1748 static_range_type = create_range_type (copy_type (dyn_range_type),
1750 &low_bound, &high_bound);
1751 TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
1752 return static_range_type;
1755 /* Resolves dynamic bound values of an array type TYPE to static ones.
1756 ADDR_STACK is a stack of struct property_addr_info to be used
1757 if needed during the dynamic resolution. */
1759 static struct type *
1760 resolve_dynamic_array (struct type *type,
1761 struct property_addr_info *addr_stack)
1764 struct type *elt_type;
1765 struct type *range_type;
1766 struct type *ary_dim;
1768 gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY);
1771 range_type = check_typedef (TYPE_INDEX_TYPE (elt_type));
1772 range_type = resolve_dynamic_range (range_type, addr_stack);
1774 ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
1776 if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY)
1777 elt_type = resolve_dynamic_array (TYPE_TARGET_TYPE (type), addr_stack);
1779 elt_type = TYPE_TARGET_TYPE (type);
1781 return create_array_type (copy_type (type),
1786 /* Resolve dynamic bounds of members of the union TYPE to static
1787 bounds. ADDR_STACK is a stack of struct property_addr_info
1788 to be used if needed during the dynamic resolution. */
1790 static struct type *
1791 resolve_dynamic_union (struct type *type,
1792 struct property_addr_info *addr_stack)
1794 struct type *resolved_type;
1796 unsigned int max_len = 0;
1798 gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
1800 resolved_type = copy_type (type);
1801 TYPE_FIELDS (resolved_type)
1802 = TYPE_ALLOC (resolved_type,
1803 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1804 memcpy (TYPE_FIELDS (resolved_type),
1806 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1807 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
1811 if (field_is_static (&TYPE_FIELD (type, i)))
1814 t = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
1816 TYPE_FIELD_TYPE (resolved_type, i) = t;
1817 if (TYPE_LENGTH (t) > max_len)
1818 max_len = TYPE_LENGTH (t);
1821 TYPE_LENGTH (resolved_type) = max_len;
1822 return resolved_type;
1825 /* Resolve dynamic bounds of members of the struct TYPE to static
1826 bounds. ADDR_STACK is a stack of struct property_addr_info to
1827 be used if needed during the dynamic resolution. */
1829 static struct type *
1830 resolve_dynamic_struct (struct type *type,
1831 struct property_addr_info *addr_stack)
1833 struct type *resolved_type;
1835 unsigned resolved_type_bit_length = 0;
1837 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
1838 gdb_assert (TYPE_NFIELDS (type) > 0);
1840 resolved_type = copy_type (type);
1841 TYPE_FIELDS (resolved_type)
1842 = TYPE_ALLOC (resolved_type,
1843 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1844 memcpy (TYPE_FIELDS (resolved_type),
1846 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1847 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
1849 unsigned new_bit_length;
1850 struct property_addr_info pinfo;
1852 if (field_is_static (&TYPE_FIELD (type, i)))
1855 /* As we know this field is not a static field, the field's
1856 field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
1857 this is the case, but only trigger a simple error rather
1858 than an internal error if that fails. While failing
1859 that verification indicates a bug in our code, the error
1860 is not severe enough to suggest to the user he stops
1861 his debugging session because of it. */
1862 if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_BITPOS)
1863 error (_("Cannot determine struct field location"
1864 " (invalid location kind)"));
1866 pinfo.type = check_typedef (TYPE_FIELD_TYPE (type, i));
1867 pinfo.addr = addr_stack->addr;
1868 pinfo.next = addr_stack;
1870 TYPE_FIELD_TYPE (resolved_type, i)
1871 = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
1873 gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type, i)
1874 == FIELD_LOC_KIND_BITPOS);
1876 new_bit_length = TYPE_FIELD_BITPOS (resolved_type, i);
1877 if (TYPE_FIELD_BITSIZE (resolved_type, i) != 0)
1878 new_bit_length += TYPE_FIELD_BITSIZE (resolved_type, i);
1880 new_bit_length += (TYPE_LENGTH (TYPE_FIELD_TYPE (resolved_type, i))
1883 /* Normally, we would use the position and size of the last field
1884 to determine the size of the enclosing structure. But GCC seems
1885 to be encoding the position of some fields incorrectly when
1886 the struct contains a dynamic field that is not placed last.
1887 So we compute the struct size based on the field that has
1888 the highest position + size - probably the best we can do. */
1889 if (new_bit_length > resolved_type_bit_length)
1890 resolved_type_bit_length = new_bit_length;
1893 TYPE_LENGTH (resolved_type)
1894 = (resolved_type_bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1896 return resolved_type;
1899 /* Worker for resolved_dynamic_type. */
1901 static struct type *
1902 resolve_dynamic_type_internal (struct type *type,
1903 struct property_addr_info *addr_stack,
1906 struct type *real_type = check_typedef (type);
1907 struct type *resolved_type = type;
1908 const struct dynamic_prop *prop;
1911 if (!is_dynamic_type_internal (real_type, top_level))
1914 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1916 resolved_type = copy_type (type);
1917 TYPE_TARGET_TYPE (resolved_type)
1918 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack,
1923 /* Before trying to resolve TYPE, make sure it is not a stub. */
1926 switch (TYPE_CODE (type))
1930 struct property_addr_info pinfo;
1932 pinfo.type = check_typedef (TYPE_TARGET_TYPE (type));
1933 pinfo.addr = read_memory_typed_address (addr_stack->addr, type);
1934 pinfo.next = addr_stack;
1936 resolved_type = copy_type (type);
1937 TYPE_TARGET_TYPE (resolved_type)
1938 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
1943 case TYPE_CODE_ARRAY:
1944 resolved_type = resolve_dynamic_array (type, addr_stack);
1947 case TYPE_CODE_RANGE:
1948 resolved_type = resolve_dynamic_range (type, addr_stack);
1951 case TYPE_CODE_UNION:
1952 resolved_type = resolve_dynamic_union (type, addr_stack);
1955 case TYPE_CODE_STRUCT:
1956 resolved_type = resolve_dynamic_struct (type, addr_stack);
1961 /* Resolve data_location attribute. */
1962 prop = TYPE_DATA_LOCATION (resolved_type);
1963 if (dwarf2_evaluate_property (prop, addr_stack, &value))
1965 TYPE_DATA_LOCATION_ADDR (resolved_type) = value;
1966 TYPE_DATA_LOCATION_KIND (resolved_type) = PROP_CONST;
1969 TYPE_DATA_LOCATION (resolved_type) = NULL;
1971 return resolved_type;
1974 /* See gdbtypes.h */
1977 resolve_dynamic_type (struct type *type, CORE_ADDR addr)
1979 struct property_addr_info pinfo = {check_typedef (type), addr, NULL};
1981 return resolve_dynamic_type_internal (type, &pinfo, 1);
1984 /* Find the real type of TYPE. This function returns the real type,
1985 after removing all layers of typedefs, and completing opaque or stub
1986 types. Completion changes the TYPE argument, but stripping of
1989 Instance flags (e.g. const/volatile) are preserved as typedefs are
1990 stripped. If necessary a new qualified form of the underlying type
1993 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
1994 not been computed and we're either in the middle of reading symbols, or
1995 there was no name for the typedef in the debug info.
1997 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
1998 QUITs in the symbol reading code can also throw.
1999 Thus this function can throw an exception.
2001 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
2004 If this is a stubbed struct (i.e. declared as struct foo *), see if
2005 we can find a full definition in some other file. If so, copy this
2006 definition, so we can use it in future. There used to be a comment
2007 (but not any code) that if we don't find a full definition, we'd
2008 set a flag so we don't spend time in the future checking the same
2009 type. That would be a mistake, though--we might load in more
2010 symbols which contain a full definition for the type. */
2013 check_typedef (struct type *type)
2015 struct type *orig_type = type;
2016 /* While we're removing typedefs, we don't want to lose qualifiers.
2017 E.g., const/volatile. */
2018 int instance_flags = TYPE_INSTANCE_FLAGS (type);
2022 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
2024 if (!TYPE_TARGET_TYPE (type))
2029 /* It is dangerous to call lookup_symbol if we are currently
2030 reading a symtab. Infinite recursion is one danger. */
2031 if (currently_reading_symtab)
2032 return make_qualified_type (type, instance_flags, NULL);
2034 name = type_name_no_tag (type);
2035 /* FIXME: shouldn't we separately check the TYPE_NAME and
2036 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
2037 VAR_DOMAIN as appropriate? (this code was written before
2038 TYPE_NAME and TYPE_TAG_NAME were separate). */
2041 stub_noname_complaint ();
2042 return make_qualified_type (type, instance_flags, NULL);
2044 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
2046 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
2047 else /* TYPE_CODE_UNDEF */
2048 TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type));
2050 type = TYPE_TARGET_TYPE (type);
2052 /* Preserve the instance flags as we traverse down the typedef chain.
2054 Handling address spaces/classes is nasty, what do we do if there's a
2056 E.g., what if an outer typedef marks the type as class_1 and an inner
2057 typedef marks the type as class_2?
2058 This is the wrong place to do such error checking. We leave it to
2059 the code that created the typedef in the first place to flag the
2060 error. We just pick the outer address space (akin to letting the
2061 outer cast in a chain of casting win), instead of assuming
2062 "it can't happen". */
2064 const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE
2065 | TYPE_INSTANCE_FLAG_DATA_SPACE);
2066 const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
2067 int new_instance_flags = TYPE_INSTANCE_FLAGS (type);
2069 /* Treat code vs data spaces and address classes separately. */
2070 if ((instance_flags & ALL_SPACES) != 0)
2071 new_instance_flags &= ~ALL_SPACES;
2072 if ((instance_flags & ALL_CLASSES) != 0)
2073 new_instance_flags &= ~ALL_CLASSES;
2075 instance_flags |= new_instance_flags;
2079 /* If this is a struct/class/union with no fields, then check
2080 whether a full definition exists somewhere else. This is for
2081 systems where a type definition with no fields is issued for such
2082 types, instead of identifying them as stub types in the first
2085 if (TYPE_IS_OPAQUE (type)
2086 && opaque_type_resolution
2087 && !currently_reading_symtab)
2089 const char *name = type_name_no_tag (type);
2090 struct type *newtype;
2094 stub_noname_complaint ();
2095 return make_qualified_type (type, instance_flags, NULL);
2097 newtype = lookup_transparent_type (name);
2101 /* If the resolved type and the stub are in the same
2102 objfile, then replace the stub type with the real deal.
2103 But if they're in separate objfiles, leave the stub
2104 alone; we'll just look up the transparent type every time
2105 we call check_typedef. We can't create pointers between
2106 types allocated to different objfiles, since they may
2107 have different lifetimes. Trying to copy NEWTYPE over to
2108 TYPE's objfile is pointless, too, since you'll have to
2109 move over any other types NEWTYPE refers to, which could
2110 be an unbounded amount of stuff. */
2111 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
2112 type = make_qualified_type (newtype,
2113 TYPE_INSTANCE_FLAGS (type),
2119 /* Otherwise, rely on the stub flag being set for opaque/stubbed
2121 else if (TYPE_STUB (type) && !currently_reading_symtab)
2123 const char *name = type_name_no_tag (type);
2124 /* FIXME: shouldn't we separately check the TYPE_NAME and the
2125 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
2126 as appropriate? (this code was written before TYPE_NAME and
2127 TYPE_TAG_NAME were separate). */
2132 stub_noname_complaint ();
2133 return make_qualified_type (type, instance_flags, NULL);
2135 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
2138 /* Same as above for opaque types, we can replace the stub
2139 with the complete type only if they are in the same
2141 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
2142 type = make_qualified_type (SYMBOL_TYPE (sym),
2143 TYPE_INSTANCE_FLAGS (type),
2146 type = SYMBOL_TYPE (sym);
2150 if (TYPE_TARGET_STUB (type))
2152 struct type *range_type;
2153 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
2155 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
2157 /* Nothing we can do. */
2159 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
2161 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
2162 TYPE_TARGET_STUB (type) = 0;
2166 type = make_qualified_type (type, instance_flags, NULL);
2168 /* Cache TYPE_LENGTH for future use. */
2169 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
2174 /* Parse a type expression in the string [P..P+LENGTH). If an error
2175 occurs, silently return a void type. */
2177 static struct type *
2178 safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
2180 struct ui_file *saved_gdb_stderr;
2181 struct type *type = NULL; /* Initialize to keep gcc happy. */
2182 volatile struct gdb_exception except;
2184 /* Suppress error messages. */
2185 saved_gdb_stderr = gdb_stderr;
2186 gdb_stderr = ui_file_new ();
2188 /* Call parse_and_eval_type() without fear of longjmp()s. */
2189 TRY_CATCH (except, RETURN_MASK_ERROR)
2191 type = parse_and_eval_type (p, length);
2194 if (except.reason < 0)
2195 type = builtin_type (gdbarch)->builtin_void;
2197 /* Stop suppressing error messages. */
2198 ui_file_delete (gdb_stderr);
2199 gdb_stderr = saved_gdb_stderr;
2204 /* Ugly hack to convert method stubs into method types.
2206 He ain't kiddin'. This demangles the name of the method into a
2207 string including argument types, parses out each argument type,
2208 generates a string casting a zero to that type, evaluates the
2209 string, and stuffs the resulting type into an argtype vector!!!
2210 Then it knows the type of the whole function (including argument
2211 types for overloading), which info used to be in the stab's but was
2212 removed to hack back the space required for them. */
2215 check_stub_method (struct type *type, int method_id, int signature_id)
2217 struct gdbarch *gdbarch = get_type_arch (type);
2219 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
2220 char *demangled_name = gdb_demangle (mangled_name,
2221 DMGL_PARAMS | DMGL_ANSI);
2222 char *argtypetext, *p;
2223 int depth = 0, argcount = 1;
2224 struct field *argtypes;
2227 /* Make sure we got back a function string that we can use. */
2229 p = strchr (demangled_name, '(');
2233 if (demangled_name == NULL || p == NULL)
2234 error (_("Internal: Cannot demangle mangled name `%s'."),
2237 /* Now, read in the parameters that define this type. */
2242 if (*p == '(' || *p == '<')
2246 else if (*p == ')' || *p == '>')
2250 else if (*p == ',' && depth == 0)
2258 /* If we read one argument and it was ``void'', don't count it. */
2259 if (strncmp (argtypetext, "(void)", 6) == 0)
2262 /* We need one extra slot, for the THIS pointer. */
2264 argtypes = (struct field *)
2265 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
2268 /* Add THIS pointer for non-static methods. */
2269 f = TYPE_FN_FIELDLIST1 (type, method_id);
2270 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
2274 argtypes[0].type = lookup_pointer_type (type);
2278 if (*p != ')') /* () means no args, skip while. */
2283 if (depth <= 0 && (*p == ',' || *p == ')'))
2285 /* Avoid parsing of ellipsis, they will be handled below.
2286 Also avoid ``void'' as above. */
2287 if (strncmp (argtypetext, "...", p - argtypetext) != 0
2288 && strncmp (argtypetext, "void", p - argtypetext) != 0)
2290 argtypes[argcount].type =
2291 safe_parse_type (gdbarch, argtypetext, p - argtypetext);
2294 argtypetext = p + 1;
2297 if (*p == '(' || *p == '<')
2301 else if (*p == ')' || *p == '>')
2310 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
2312 /* Now update the old "stub" type into a real type. */
2313 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
2314 TYPE_SELF_TYPE (mtype) = type;
2315 TYPE_FIELDS (mtype) = argtypes;
2316 TYPE_NFIELDS (mtype) = argcount;
2317 TYPE_STUB (mtype) = 0;
2318 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
2320 TYPE_VARARGS (mtype) = 1;
2322 xfree (demangled_name);
2325 /* This is the external interface to check_stub_method, above. This
2326 function unstubs all of the signatures for TYPE's METHOD_ID method
2327 name. After calling this function TYPE_FN_FIELD_STUB will be
2328 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
2331 This function unfortunately can not die until stabs do. */
2334 check_stub_method_group (struct type *type, int method_id)
2336 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
2337 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
2338 int j, found_stub = 0;
2340 for (j = 0; j < len; j++)
2341 if (TYPE_FN_FIELD_STUB (f, j))
2344 check_stub_method (type, method_id, j);
2347 /* GNU v3 methods with incorrect names were corrected when we read
2348 in type information, because it was cheaper to do it then. The
2349 only GNU v2 methods with incorrect method names are operators and
2350 destructors; destructors were also corrected when we read in type
2353 Therefore the only thing we need to handle here are v2 operator
2355 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
2358 char dem_opname[256];
2360 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2362 dem_opname, DMGL_ANSI);
2364 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2368 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
2372 /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
2373 const struct cplus_struct_type cplus_struct_default = { };
2376 allocate_cplus_struct_type (struct type *type)
2378 if (HAVE_CPLUS_STRUCT (type))
2379 /* Structure was already allocated. Nothing more to do. */
2382 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF;
2383 TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
2384 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
2385 *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default;
2388 const struct gnat_aux_type gnat_aux_default =
2391 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
2392 and allocate the associated gnat-specific data. The gnat-specific
2393 data is also initialized to gnat_aux_default. */
2396 allocate_gnat_aux_type (struct type *type)
2398 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF;
2399 TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *)
2400 TYPE_ALLOC (type, sizeof (struct gnat_aux_type));
2401 *(TYPE_GNAT_SPECIFIC (type)) = gnat_aux_default;
2404 /* Helper function to initialize the standard scalar types.
2406 If NAME is non-NULL, then it is used to initialize the type name.
2407 Note that NAME is not copied; it is required to have a lifetime at
2408 least as long as OBJFILE. */
2411 init_type (enum type_code code, int length, int flags,
2412 const char *name, struct objfile *objfile)
2416 type = alloc_type (objfile);
2417 TYPE_CODE (type) = code;
2418 TYPE_LENGTH (type) = length;
2420 gdb_assert (!(flags & (TYPE_FLAG_MIN - 1)));
2421 if (flags & TYPE_FLAG_UNSIGNED)
2422 TYPE_UNSIGNED (type) = 1;
2423 if (flags & TYPE_FLAG_NOSIGN)
2424 TYPE_NOSIGN (type) = 1;
2425 if (flags & TYPE_FLAG_STUB)
2426 TYPE_STUB (type) = 1;
2427 if (flags & TYPE_FLAG_TARGET_STUB)
2428 TYPE_TARGET_STUB (type) = 1;
2429 if (flags & TYPE_FLAG_STATIC)
2430 TYPE_STATIC (type) = 1;
2431 if (flags & TYPE_FLAG_PROTOTYPED)
2432 TYPE_PROTOTYPED (type) = 1;
2433 if (flags & TYPE_FLAG_INCOMPLETE)
2434 TYPE_INCOMPLETE (type) = 1;
2435 if (flags & TYPE_FLAG_VARARGS)
2436 TYPE_VARARGS (type) = 1;
2437 if (flags & TYPE_FLAG_VECTOR)
2438 TYPE_VECTOR (type) = 1;
2439 if (flags & TYPE_FLAG_STUB_SUPPORTED)
2440 TYPE_STUB_SUPPORTED (type) = 1;
2441 if (flags & TYPE_FLAG_FIXED_INSTANCE)
2442 TYPE_FIXED_INSTANCE (type) = 1;
2443 if (flags & TYPE_FLAG_GNU_IFUNC)
2444 TYPE_GNU_IFUNC (type) = 1;
2446 TYPE_NAME (type) = name;
2450 if (name && strcmp (name, "char") == 0)
2451 TYPE_NOSIGN (type) = 1;
2455 case TYPE_CODE_STRUCT:
2456 case TYPE_CODE_UNION:
2457 case TYPE_CODE_NAMESPACE:
2458 INIT_CPLUS_SPECIFIC (type);
2461 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT;
2463 case TYPE_CODE_FUNC:
2464 INIT_FUNC_SPECIFIC (type);
2470 /* Queries on types. */
2473 can_dereference (struct type *t)
2475 /* FIXME: Should we return true for references as well as
2480 && TYPE_CODE (t) == TYPE_CODE_PTR
2481 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
2485 is_integral_type (struct type *t)
2490 && ((TYPE_CODE (t) == TYPE_CODE_INT)
2491 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
2492 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
2493 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
2494 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
2495 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
2498 /* Return true if TYPE is scalar. */
2501 is_scalar_type (struct type *type)
2503 CHECK_TYPEDEF (type);
2505 switch (TYPE_CODE (type))
2507 case TYPE_CODE_ARRAY:
2508 case TYPE_CODE_STRUCT:
2509 case TYPE_CODE_UNION:
2511 case TYPE_CODE_STRING:
2518 /* Return true if T is scalar, or a composite type which in practice has
2519 the memory layout of a scalar type. E.g., an array or struct with only
2520 one scalar element inside it, or a union with only scalar elements. */
2523 is_scalar_type_recursive (struct type *t)
2527 if (is_scalar_type (t))
2529 /* Are we dealing with an array or string of known dimensions? */
2530 else if ((TYPE_CODE (t) == TYPE_CODE_ARRAY
2531 || TYPE_CODE (t) == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1
2532 && TYPE_CODE (TYPE_INDEX_TYPE (t)) == TYPE_CODE_RANGE)
2534 LONGEST low_bound, high_bound;
2535 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (t));
2537 get_discrete_bounds (TYPE_INDEX_TYPE (t), &low_bound, &high_bound);
2539 return high_bound == low_bound && is_scalar_type_recursive (elt_type);
2541 /* Are we dealing with a struct with one element? */
2542 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1)
2543 return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0));
2544 else if (TYPE_CODE (t) == TYPE_CODE_UNION)
2546 int i, n = TYPE_NFIELDS (t);
2548 /* If all elements of the union are scalar, then the union is scalar. */
2549 for (i = 0; i < n; i++)
2550 if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t, i)))
2559 /* Return true is T is a class or a union. False otherwise. */
2562 class_or_union_p (const struct type *t)
2564 return (TYPE_CODE (t) == TYPE_CODE_STRUCT
2565 || TYPE_CODE (t) == TYPE_CODE_UNION);
2568 /* A helper function which returns true if types A and B represent the
2569 "same" class type. This is true if the types have the same main
2570 type, or the same name. */
2573 class_types_same_p (const struct type *a, const struct type *b)
2575 return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b)
2576 || (TYPE_NAME (a) && TYPE_NAME (b)
2577 && !strcmp (TYPE_NAME (a), TYPE_NAME (b))));
2580 /* If BASE is an ancestor of DCLASS return the distance between them.
2581 otherwise return -1;
2585 class B: public A {};
2586 class C: public B {};
2589 distance_to_ancestor (A, A, 0) = 0
2590 distance_to_ancestor (A, B, 0) = 1
2591 distance_to_ancestor (A, C, 0) = 2
2592 distance_to_ancestor (A, D, 0) = 3
2594 If PUBLIC is 1 then only public ancestors are considered,
2595 and the function returns the distance only if BASE is a public ancestor
2599 distance_to_ancestor (A, D, 1) = -1. */
2602 distance_to_ancestor (struct type *base, struct type *dclass, int public)
2607 CHECK_TYPEDEF (base);
2608 CHECK_TYPEDEF (dclass);
2610 if (class_types_same_p (base, dclass))
2613 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2615 if (public && ! BASETYPE_VIA_PUBLIC (dclass, i))
2618 d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), public);
2626 /* Check whether BASE is an ancestor or base class or DCLASS
2627 Return 1 if so, and 0 if not.
2628 Note: If BASE and DCLASS are of the same type, this function
2629 will return 1. So for some class A, is_ancestor (A, A) will
2633 is_ancestor (struct type *base, struct type *dclass)
2635 return distance_to_ancestor (base, dclass, 0) >= 0;
2638 /* Like is_ancestor, but only returns true when BASE is a public
2639 ancestor of DCLASS. */
2642 is_public_ancestor (struct type *base, struct type *dclass)
2644 return distance_to_ancestor (base, dclass, 1) >= 0;
2647 /* A helper function for is_unique_ancestor. */
2650 is_unique_ancestor_worker (struct type *base, struct type *dclass,
2652 const gdb_byte *valaddr, int embedded_offset,
2653 CORE_ADDR address, struct value *val)
2657 CHECK_TYPEDEF (base);
2658 CHECK_TYPEDEF (dclass);
2660 for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
2665 iter = check_typedef (TYPE_BASECLASS (dclass, i));
2667 this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset,
2670 if (class_types_same_p (base, iter))
2672 /* If this is the first subclass, set *OFFSET and set count
2673 to 1. Otherwise, if this is at the same offset as
2674 previous instances, do nothing. Otherwise, increment
2678 *offset = this_offset;
2681 else if (this_offset == *offset)
2689 count += is_unique_ancestor_worker (base, iter, offset,
2691 embedded_offset + this_offset,
2698 /* Like is_ancestor, but only returns true if BASE is a unique base
2699 class of the type of VAL. */
2702 is_unique_ancestor (struct type *base, struct value *val)
2706 return is_unique_ancestor_worker (base, value_type (val), &offset,
2707 value_contents_for_printing (val),
2708 value_embedded_offset (val),
2709 value_address (val), val) == 1;
2713 /* Overload resolution. */
2715 /* Return the sum of the rank of A with the rank of B. */
2718 sum_ranks (struct rank a, struct rank b)
2721 c.rank = a.rank + b.rank;
2722 c.subrank = a.subrank + b.subrank;
2726 /* Compare rank A and B and return:
2728 1 if a is better than b
2729 -1 if b is better than a. */
2732 compare_ranks (struct rank a, struct rank b)
2734 if (a.rank == b.rank)
2736 if (a.subrank == b.subrank)
2738 if (a.subrank < b.subrank)
2740 if (a.subrank > b.subrank)
2744 if (a.rank < b.rank)
2747 /* a.rank > b.rank */
2751 /* Functions for overload resolution begin here. */
2753 /* Compare two badness vectors A and B and return the result.
2754 0 => A and B are identical
2755 1 => A and B are incomparable
2756 2 => A is better than B
2757 3 => A is worse than B */
2760 compare_badness (struct badness_vector *a, struct badness_vector *b)
2764 short found_pos = 0; /* any positives in c? */
2765 short found_neg = 0; /* any negatives in c? */
2767 /* differing lengths => incomparable */
2768 if (a->length != b->length)
2771 /* Subtract b from a */
2772 for (i = 0; i < a->length; i++)
2774 tmp = compare_ranks (b->rank[i], a->rank[i]);
2784 return 1; /* incomparable */
2786 return 3; /* A > B */
2792 return 2; /* A < B */
2794 return 0; /* A == B */
2798 /* Rank a function by comparing its parameter types (PARMS, length
2799 NPARMS), to the types of an argument list (ARGS, length NARGS).
2800 Return a pointer to a badness vector. This has NARGS + 1
2803 struct badness_vector *
2804 rank_function (struct type **parms, int nparms,
2805 struct value **args, int nargs)
2808 struct badness_vector *bv;
2809 int min_len = nparms < nargs ? nparms : nargs;
2811 bv = xmalloc (sizeof (struct badness_vector));
2812 bv->length = nargs + 1; /* add 1 for the length-match rank. */
2813 bv->rank = XNEWVEC (struct rank, nargs + 1);
2815 /* First compare the lengths of the supplied lists.
2816 If there is a mismatch, set it to a high value. */
2818 /* pai/1997-06-03 FIXME: when we have debug info about default
2819 arguments and ellipsis parameter lists, we should consider those
2820 and rank the length-match more finely. */
2822 LENGTH_MATCH (bv) = (nargs != nparms)
2823 ? LENGTH_MISMATCH_BADNESS
2824 : EXACT_MATCH_BADNESS;
2826 /* Now rank all the parameters of the candidate function. */
2827 for (i = 1; i <= min_len; i++)
2828 bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]),
2831 /* If more arguments than parameters, add dummy entries. */
2832 for (i = min_len + 1; i <= nargs; i++)
2833 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2838 /* Compare the names of two integer types, assuming that any sign
2839 qualifiers have been checked already. We do it this way because
2840 there may be an "int" in the name of one of the types. */
2843 integer_types_same_name_p (const char *first, const char *second)
2845 int first_p, second_p;
2847 /* If both are shorts, return 1; if neither is a short, keep
2849 first_p = (strstr (first, "short") != NULL);
2850 second_p = (strstr (second, "short") != NULL);
2851 if (first_p && second_p)
2853 if (first_p || second_p)
2856 /* Likewise for long. */
2857 first_p = (strstr (first, "long") != NULL);
2858 second_p = (strstr (second, "long") != NULL);
2859 if (first_p && second_p)
2861 if (first_p || second_p)
2864 /* Likewise for char. */
2865 first_p = (strstr (first, "char") != NULL);
2866 second_p = (strstr (second, "char") != NULL);
2867 if (first_p && second_p)
2869 if (first_p || second_p)
2872 /* They must both be ints. */
2876 /* Compares type A to type B returns 1 if the represent the same type
2880 types_equal (struct type *a, struct type *b)
2882 /* Identical type pointers. */
2883 /* However, this still doesn't catch all cases of same type for b
2884 and a. The reason is that builtin types are different from
2885 the same ones constructed from the object. */
2889 /* Resolve typedefs */
2890 if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF)
2891 a = check_typedef (a);
2892 if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF)
2893 b = check_typedef (b);
2895 /* If after resolving typedefs a and b are not of the same type
2896 code then they are not equal. */
2897 if (TYPE_CODE (a) != TYPE_CODE (b))
2900 /* If a and b are both pointers types or both reference types then
2901 they are equal of the same type iff the objects they refer to are
2902 of the same type. */
2903 if (TYPE_CODE (a) == TYPE_CODE_PTR
2904 || TYPE_CODE (a) == TYPE_CODE_REF)
2905 return types_equal (TYPE_TARGET_TYPE (a),
2906 TYPE_TARGET_TYPE (b));
2908 /* Well, damnit, if the names are exactly the same, I'll say they
2909 are exactly the same. This happens when we generate method
2910 stubs. The types won't point to the same address, but they
2911 really are the same. */
2913 if (TYPE_NAME (a) && TYPE_NAME (b)
2914 && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0)
2917 /* Check if identical after resolving typedefs. */
2921 /* Two function types are equal if their argument and return types
2923 if (TYPE_CODE (a) == TYPE_CODE_FUNC)
2927 if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
2930 if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
2933 for (i = 0; i < TYPE_NFIELDS (a); ++i)
2934 if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
2943 /* Deep comparison of types. */
2945 /* An entry in the type-equality bcache. */
2947 typedef struct type_equality_entry
2949 struct type *type1, *type2;
2950 } type_equality_entry_d;
2952 DEF_VEC_O (type_equality_entry_d);
2954 /* A helper function to compare two strings. Returns 1 if they are
2955 the same, 0 otherwise. Handles NULLs properly. */
2958 compare_maybe_null_strings (const char *s, const char *t)
2960 if (s == NULL && t != NULL)
2962 else if (s != NULL && t == NULL)
2964 else if (s == NULL && t== NULL)
2966 return strcmp (s, t) == 0;
2969 /* A helper function for check_types_worklist that checks two types for
2970 "deep" equality. Returns non-zero if the types are considered the
2971 same, zero otherwise. */
2974 check_types_equal (struct type *type1, struct type *type2,
2975 VEC (type_equality_entry_d) **worklist)
2977 CHECK_TYPEDEF (type1);
2978 CHECK_TYPEDEF (type2);
2983 if (TYPE_CODE (type1) != TYPE_CODE (type2)
2984 || TYPE_LENGTH (type1) != TYPE_LENGTH (type2)
2985 || TYPE_UNSIGNED (type1) != TYPE_UNSIGNED (type2)
2986 || TYPE_NOSIGN (type1) != TYPE_NOSIGN (type2)
2987 || TYPE_VARARGS (type1) != TYPE_VARARGS (type2)
2988 || TYPE_VECTOR (type1) != TYPE_VECTOR (type2)
2989 || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2)
2990 || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2)
2991 || TYPE_NFIELDS (type1) != TYPE_NFIELDS (type2))
2994 if (!compare_maybe_null_strings (TYPE_TAG_NAME (type1),
2995 TYPE_TAG_NAME (type2)))
2997 if (!compare_maybe_null_strings (TYPE_NAME (type1), TYPE_NAME (type2)))
3000 if (TYPE_CODE (type1) == TYPE_CODE_RANGE)
3002 if (memcmp (TYPE_RANGE_DATA (type1), TYPE_RANGE_DATA (type2),
3003 sizeof (*TYPE_RANGE_DATA (type1))) != 0)
3010 for (i = 0; i < TYPE_NFIELDS (type1); ++i)
3012 const struct field *field1 = &TYPE_FIELD (type1, i);
3013 const struct field *field2 = &TYPE_FIELD (type2, i);
3014 struct type_equality_entry entry;
3016 if (FIELD_ARTIFICIAL (*field1) != FIELD_ARTIFICIAL (*field2)
3017 || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2)
3018 || FIELD_LOC_KIND (*field1) != FIELD_LOC_KIND (*field2))
3020 if (!compare_maybe_null_strings (FIELD_NAME (*field1),
3021 FIELD_NAME (*field2)))
3023 switch (FIELD_LOC_KIND (*field1))
3025 case FIELD_LOC_KIND_BITPOS:
3026 if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2))
3029 case FIELD_LOC_KIND_ENUMVAL:
3030 if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2))
3033 case FIELD_LOC_KIND_PHYSADDR:
3034 if (FIELD_STATIC_PHYSADDR (*field1)
3035 != FIELD_STATIC_PHYSADDR (*field2))
3038 case FIELD_LOC_KIND_PHYSNAME:
3039 if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1),
3040 FIELD_STATIC_PHYSNAME (*field2)))
3043 case FIELD_LOC_KIND_DWARF_BLOCK:
3045 struct dwarf2_locexpr_baton *block1, *block2;
3047 block1 = FIELD_DWARF_BLOCK (*field1);
3048 block2 = FIELD_DWARF_BLOCK (*field2);
3049 if (block1->per_cu != block2->per_cu
3050 || block1->size != block2->size
3051 || memcmp (block1->data, block2->data, block1->size) != 0)
3056 internal_error (__FILE__, __LINE__, _("Unsupported field kind "
3057 "%d by check_types_equal"),
3058 FIELD_LOC_KIND (*field1));
3061 entry.type1 = FIELD_TYPE (*field1);
3062 entry.type2 = FIELD_TYPE (*field2);
3063 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
3067 if (TYPE_TARGET_TYPE (type1) != NULL)
3069 struct type_equality_entry entry;
3071 if (TYPE_TARGET_TYPE (type2) == NULL)
3074 entry.type1 = TYPE_TARGET_TYPE (type1);
3075 entry.type2 = TYPE_TARGET_TYPE (type2);
3076 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
3078 else if (TYPE_TARGET_TYPE (type2) != NULL)
3084 /* Check types on a worklist for equality. Returns zero if any pair
3085 is not equal, non-zero if they are all considered equal. */
3088 check_types_worklist (VEC (type_equality_entry_d) **worklist,
3089 struct bcache *cache)
3091 while (!VEC_empty (type_equality_entry_d, *worklist))
3093 struct type_equality_entry entry;
3096 entry = *VEC_last (type_equality_entry_d, *worklist);
3097 VEC_pop (type_equality_entry_d, *worklist);
3099 /* If the type pair has already been visited, we know it is
3101 bcache_full (&entry, sizeof (entry), cache, &added);
3105 if (check_types_equal (entry.type1, entry.type2, worklist) == 0)
3112 /* Return non-zero if types TYPE1 and TYPE2 are equal, as determined by a
3113 "deep comparison". Otherwise return zero. */
3116 types_deeply_equal (struct type *type1, struct type *type2)
3118 volatile struct gdb_exception except;
3120 struct bcache *cache;
3121 VEC (type_equality_entry_d) *worklist = NULL;
3122 struct type_equality_entry entry;
3124 gdb_assert (type1 != NULL && type2 != NULL);
3126 /* Early exit for the simple case. */
3130 cache = bcache_xmalloc (NULL, NULL);
3132 entry.type1 = type1;
3133 entry.type2 = type2;
3134 VEC_safe_push (type_equality_entry_d, worklist, &entry);
3136 TRY_CATCH (except, RETURN_MASK_ALL)
3138 result = check_types_worklist (&worklist, cache);
3140 /* check_types_worklist calls several nested helper functions,
3141 some of which can raise a GDB Exception, so we just check
3142 and rethrow here. If there is a GDB exception, a comparison
3143 is not capable (or trusted), so exit. */
3144 bcache_xfree (cache);
3145 VEC_free (type_equality_entry_d, worklist);
3146 /* Rethrow if there was a problem. */
3147 if (except.reason < 0)
3148 throw_exception (except);
3153 /* Compare one type (PARM) for compatibility with another (ARG).
3154 * PARM is intended to be the parameter type of a function; and
3155 * ARG is the supplied argument's type. This function tests if
3156 * the latter can be converted to the former.
3157 * VALUE is the argument's value or NULL if none (or called recursively)
3159 * Return 0 if they are identical types;
3160 * Otherwise, return an integer which corresponds to how compatible
3161 * PARM is to ARG. The higher the return value, the worse the match.
3162 * Generally the "bad" conversions are all uniformly assigned a 100. */
3165 rank_one_type (struct type *parm, struct type *arg, struct value *value)
3167 struct rank rank = {0,0};
3169 if (types_equal (parm, arg))
3170 return EXACT_MATCH_BADNESS;
3172 /* Resolve typedefs */
3173 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
3174 parm = check_typedef (parm);
3175 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
3176 arg = check_typedef (arg);
3178 /* See through references, since we can almost make non-references
3180 if (TYPE_CODE (arg) == TYPE_CODE_REF)
3181 return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
3182 REFERENCE_CONVERSION_BADNESS));
3183 if (TYPE_CODE (parm) == TYPE_CODE_REF)
3184 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
3185 REFERENCE_CONVERSION_BADNESS));
3187 /* Debugging only. */
3188 fprintf_filtered (gdb_stderr,
3189 "------ Arg is %s [%d], parm is %s [%d]\n",
3190 TYPE_NAME (arg), TYPE_CODE (arg),
3191 TYPE_NAME (parm), TYPE_CODE (parm));
3193 /* x -> y means arg of type x being supplied for parameter of type y. */
3195 switch (TYPE_CODE (parm))
3198 switch (TYPE_CODE (arg))
3202 /* Allowed pointer conversions are:
3203 (a) pointer to void-pointer conversion. */
3204 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
3205 return VOID_PTR_CONVERSION_BADNESS;
3207 /* (b) pointer to ancestor-pointer conversion. */
3208 rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
3209 TYPE_TARGET_TYPE (arg),
3211 if (rank.subrank >= 0)
3212 return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
3214 return INCOMPATIBLE_TYPE_BADNESS;
3215 case TYPE_CODE_ARRAY:
3216 if (types_equal (TYPE_TARGET_TYPE (parm),
3217 TYPE_TARGET_TYPE (arg)))
3218 return EXACT_MATCH_BADNESS;
3219 return INCOMPATIBLE_TYPE_BADNESS;
3220 case TYPE_CODE_FUNC:
3221 return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
3223 if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
3225 if (value_as_long (value) == 0)
3227 /* Null pointer conversion: allow it to be cast to a pointer.
3228 [4.10.1 of C++ standard draft n3290] */
3229 return NULL_POINTER_CONVERSION_BADNESS;
3233 /* If type checking is disabled, allow the conversion. */
3234 if (!strict_type_checking)
3235 return NS_INTEGER_POINTER_CONVERSION_BADNESS;
3239 case TYPE_CODE_ENUM:
3240 case TYPE_CODE_FLAGS:
3241 case TYPE_CODE_CHAR:
3242 case TYPE_CODE_RANGE:
3243 case TYPE_CODE_BOOL:
3245 return INCOMPATIBLE_TYPE_BADNESS;
3247 case TYPE_CODE_ARRAY:
3248 switch (TYPE_CODE (arg))
3251 case TYPE_CODE_ARRAY:
3252 return rank_one_type (TYPE_TARGET_TYPE (parm),
3253 TYPE_TARGET_TYPE (arg), NULL);
3255 return INCOMPATIBLE_TYPE_BADNESS;
3257 case TYPE_CODE_FUNC:
3258 switch (TYPE_CODE (arg))
3260 case TYPE_CODE_PTR: /* funcptr -> func */
3261 return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
3263 return INCOMPATIBLE_TYPE_BADNESS;
3266 switch (TYPE_CODE (arg))
3269 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3271 /* Deal with signed, unsigned, and plain chars and
3272 signed and unsigned ints. */
3273 if (TYPE_NOSIGN (parm))
3275 /* This case only for character types. */
3276 if (TYPE_NOSIGN (arg))
3277 return EXACT_MATCH_BADNESS; /* plain char -> plain char */
3278 else /* signed/unsigned char -> plain char */
3279 return INTEGER_CONVERSION_BADNESS;
3281 else if (TYPE_UNSIGNED (parm))
3283 if (TYPE_UNSIGNED (arg))
3285 /* unsigned int -> unsigned int, or
3286 unsigned long -> unsigned long */
3287 if (integer_types_same_name_p (TYPE_NAME (parm),
3289 return EXACT_MATCH_BADNESS;
3290 else if (integer_types_same_name_p (TYPE_NAME (arg),
3292 && integer_types_same_name_p (TYPE_NAME (parm),
3294 /* unsigned int -> unsigned long */
3295 return INTEGER_PROMOTION_BADNESS;
3297 /* unsigned long -> unsigned int */
3298 return INTEGER_CONVERSION_BADNESS;
3302 if (integer_types_same_name_p (TYPE_NAME (arg),
3304 && integer_types_same_name_p (TYPE_NAME (parm),
3306 /* signed long -> unsigned int */
3307 return INTEGER_CONVERSION_BADNESS;
3309 /* signed int/long -> unsigned int/long */
3310 return INTEGER_CONVERSION_BADNESS;
3313 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3315 if (integer_types_same_name_p (TYPE_NAME (parm),
3317 return EXACT_MATCH_BADNESS;
3318 else if (integer_types_same_name_p (TYPE_NAME (arg),
3320 && integer_types_same_name_p (TYPE_NAME (parm),
3322 return INTEGER_PROMOTION_BADNESS;
3324 return INTEGER_CONVERSION_BADNESS;
3327 return INTEGER_CONVERSION_BADNESS;
3329 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3330 return INTEGER_PROMOTION_BADNESS;
3332 return INTEGER_CONVERSION_BADNESS;
3333 case TYPE_CODE_ENUM:
3334 case TYPE_CODE_FLAGS:
3335 case TYPE_CODE_CHAR:
3336 case TYPE_CODE_RANGE:
3337 case TYPE_CODE_BOOL:
3338 if (TYPE_DECLARED_CLASS (arg))
3339 return INCOMPATIBLE_TYPE_BADNESS;
3340 return INTEGER_PROMOTION_BADNESS;
3342 return INT_FLOAT_CONVERSION_BADNESS;
3344 return NS_POINTER_CONVERSION_BADNESS;
3346 return INCOMPATIBLE_TYPE_BADNESS;
3349 case TYPE_CODE_ENUM:
3350 switch (TYPE_CODE (arg))
3353 case TYPE_CODE_CHAR:
3354 case TYPE_CODE_RANGE:
3355 case TYPE_CODE_BOOL:
3356 case TYPE_CODE_ENUM:
3357 if (TYPE_DECLARED_CLASS (parm) || TYPE_DECLARED_CLASS (arg))
3358 return INCOMPATIBLE_TYPE_BADNESS;
3359 return INTEGER_CONVERSION_BADNESS;
3361 return INT_FLOAT_CONVERSION_BADNESS;
3363 return INCOMPATIBLE_TYPE_BADNESS;
3366 case TYPE_CODE_CHAR:
3367 switch (TYPE_CODE (arg))
3369 case TYPE_CODE_RANGE:
3370 case TYPE_CODE_BOOL:
3371 case TYPE_CODE_ENUM:
3372 if (TYPE_DECLARED_CLASS (arg))
3373 return INCOMPATIBLE_TYPE_BADNESS;
3374 return INTEGER_CONVERSION_BADNESS;
3376 return INT_FLOAT_CONVERSION_BADNESS;
3378 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
3379 return INTEGER_CONVERSION_BADNESS;
3380 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3381 return INTEGER_PROMOTION_BADNESS;
3382 /* >>> !! else fall through !! <<< */
3383 case TYPE_CODE_CHAR:
3384 /* Deal with signed, unsigned, and plain chars for C++ and
3385 with int cases falling through from previous case. */
3386 if (TYPE_NOSIGN (parm))
3388 if (TYPE_NOSIGN (arg))
3389 return EXACT_MATCH_BADNESS;
3391 return INTEGER_CONVERSION_BADNESS;
3393 else if (TYPE_UNSIGNED (parm))
3395 if (TYPE_UNSIGNED (arg))
3396 return EXACT_MATCH_BADNESS;
3398 return INTEGER_PROMOTION_BADNESS;
3400 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3401 return EXACT_MATCH_BADNESS;
3403 return INTEGER_CONVERSION_BADNESS;
3405 return INCOMPATIBLE_TYPE_BADNESS;
3408 case TYPE_CODE_RANGE:
3409 switch (TYPE_CODE (arg))
3412 case TYPE_CODE_CHAR:
3413 case TYPE_CODE_RANGE:
3414 case TYPE_CODE_BOOL:
3415 case TYPE_CODE_ENUM:
3416 return INTEGER_CONVERSION_BADNESS;
3418 return INT_FLOAT_CONVERSION_BADNESS;
3420 return INCOMPATIBLE_TYPE_BADNESS;
3423 case TYPE_CODE_BOOL:
3424 switch (TYPE_CODE (arg))
3426 /* n3290 draft, section 4.12.1 (conv.bool):
3428 "A prvalue of arithmetic, unscoped enumeration, pointer, or
3429 pointer to member type can be converted to a prvalue of type
3430 bool. A zero value, null pointer value, or null member pointer
3431 value is converted to false; any other value is converted to
3432 true. A prvalue of type std::nullptr_t can be converted to a
3433 prvalue of type bool; the resulting value is false." */
3435 case TYPE_CODE_CHAR:
3436 case TYPE_CODE_ENUM:
3438 case TYPE_CODE_MEMBERPTR:
3440 return BOOL_CONVERSION_BADNESS;
3441 case TYPE_CODE_RANGE:
3442 return INCOMPATIBLE_TYPE_BADNESS;
3443 case TYPE_CODE_BOOL:
3444 return EXACT_MATCH_BADNESS;
3446 return INCOMPATIBLE_TYPE_BADNESS;
3450 switch (TYPE_CODE (arg))
3453 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3454 return FLOAT_PROMOTION_BADNESS;
3455 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3456 return EXACT_MATCH_BADNESS;
3458 return FLOAT_CONVERSION_BADNESS;
3460 case TYPE_CODE_BOOL:
3461 case TYPE_CODE_ENUM:
3462 case TYPE_CODE_RANGE:
3463 case TYPE_CODE_CHAR:
3464 return INT_FLOAT_CONVERSION_BADNESS;
3466 return INCOMPATIBLE_TYPE_BADNESS;
3469 case TYPE_CODE_COMPLEX:
3470 switch (TYPE_CODE (arg))
3471 { /* Strictly not needed for C++, but... */
3473 return FLOAT_PROMOTION_BADNESS;
3474 case TYPE_CODE_COMPLEX:
3475 return EXACT_MATCH_BADNESS;
3477 return INCOMPATIBLE_TYPE_BADNESS;
3480 case TYPE_CODE_STRUCT:
3481 switch (TYPE_CODE (arg))
3483 case TYPE_CODE_STRUCT:
3484 /* Check for derivation */
3485 rank.subrank = distance_to_ancestor (parm, arg, 0);
3486 if (rank.subrank >= 0)
3487 return sum_ranks (BASE_CONVERSION_BADNESS, rank);
3488 /* else fall through */
3490 return INCOMPATIBLE_TYPE_BADNESS;
3493 case TYPE_CODE_UNION:
3494 switch (TYPE_CODE (arg))
3496 case TYPE_CODE_UNION:
3498 return INCOMPATIBLE_TYPE_BADNESS;
3501 case TYPE_CODE_MEMBERPTR:
3502 switch (TYPE_CODE (arg))
3505 return INCOMPATIBLE_TYPE_BADNESS;
3508 case TYPE_CODE_METHOD:
3509 switch (TYPE_CODE (arg))
3513 return INCOMPATIBLE_TYPE_BADNESS;
3517 switch (TYPE_CODE (arg))
3521 return INCOMPATIBLE_TYPE_BADNESS;
3526 switch (TYPE_CODE (arg))
3530 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
3531 TYPE_FIELD_TYPE (arg, 0), NULL);
3533 return INCOMPATIBLE_TYPE_BADNESS;
3536 case TYPE_CODE_VOID:
3538 return INCOMPATIBLE_TYPE_BADNESS;
3539 } /* switch (TYPE_CODE (arg)) */
3542 /* End of functions for overload resolution. */
3544 /* Routines to pretty-print types. */
3547 print_bit_vector (B_TYPE *bits, int nbits)
3551 for (bitno = 0; bitno < nbits; bitno++)
3553 if ((bitno % 8) == 0)
3555 puts_filtered (" ");
3557 if (B_TST (bits, bitno))
3558 printf_filtered (("1"));
3560 printf_filtered (("0"));
3564 /* Note the first arg should be the "this" pointer, we may not want to
3565 include it since we may get into a infinitely recursive
3569 print_args (struct field *args, int nargs, int spaces)
3575 for (i = 0; i < nargs; i++)
3577 printfi_filtered (spaces, "[%d] name '%s'\n", i,
3578 args[i].name != NULL ? args[i].name : "<NULL>");
3579 recursive_dump_type (args[i].type, spaces + 2);
3585 field_is_static (struct field *f)
3587 /* "static" fields are the fields whose location is not relative
3588 to the address of the enclosing struct. It would be nice to
3589 have a dedicated flag that would be set for static fields when
3590 the type is being created. But in practice, checking the field
3591 loc_kind should give us an accurate answer. */
3592 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
3593 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
3597 dump_fn_fieldlists (struct type *type, int spaces)
3603 printfi_filtered (spaces, "fn_fieldlists ");
3604 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
3605 printf_filtered ("\n");
3606 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
3608 f = TYPE_FN_FIELDLIST1 (type, method_idx);
3609 printfi_filtered (spaces + 2, "[%d] name '%s' (",
3611 TYPE_FN_FIELDLIST_NAME (type, method_idx));
3612 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
3614 printf_filtered (_(") length %d\n"),
3615 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
3616 for (overload_idx = 0;
3617 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
3620 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
3622 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
3623 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
3625 printf_filtered (")\n");
3626 printfi_filtered (spaces + 8, "type ");
3627 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
3629 printf_filtered ("\n");
3631 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
3634 printfi_filtered (spaces + 8, "args ");
3635 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
3637 printf_filtered ("\n");
3638 print_args (TYPE_FN_FIELD_ARGS (f, overload_idx),
3639 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
3641 printfi_filtered (spaces + 8, "fcontext ");
3642 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
3644 printf_filtered ("\n");
3646 printfi_filtered (spaces + 8, "is_const %d\n",
3647 TYPE_FN_FIELD_CONST (f, overload_idx));
3648 printfi_filtered (spaces + 8, "is_volatile %d\n",
3649 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
3650 printfi_filtered (spaces + 8, "is_private %d\n",
3651 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
3652 printfi_filtered (spaces + 8, "is_protected %d\n",
3653 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
3654 printfi_filtered (spaces + 8, "is_stub %d\n",
3655 TYPE_FN_FIELD_STUB (f, overload_idx));
3656 printfi_filtered (spaces + 8, "voffset %u\n",
3657 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
3663 print_cplus_stuff (struct type *type, int spaces)
3665 printfi_filtered (spaces, "n_baseclasses %d\n",
3666 TYPE_N_BASECLASSES (type));
3667 printfi_filtered (spaces, "nfn_fields %d\n",
3668 TYPE_NFN_FIELDS (type));
3669 if (TYPE_N_BASECLASSES (type) > 0)
3671 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
3672 TYPE_N_BASECLASSES (type));
3673 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
3675 printf_filtered (")");
3677 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
3678 TYPE_N_BASECLASSES (type));
3679 puts_filtered ("\n");
3681 if (TYPE_NFIELDS (type) > 0)
3683 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
3685 printfi_filtered (spaces,
3686 "private_field_bits (%d bits at *",
3687 TYPE_NFIELDS (type));
3688 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
3690 printf_filtered (")");
3691 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
3692 TYPE_NFIELDS (type));
3693 puts_filtered ("\n");
3695 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
3697 printfi_filtered (spaces,
3698 "protected_field_bits (%d bits at *",
3699 TYPE_NFIELDS (type));
3700 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
3702 printf_filtered (")");
3703 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
3704 TYPE_NFIELDS (type));
3705 puts_filtered ("\n");
3708 if (TYPE_NFN_FIELDS (type) > 0)
3710 dump_fn_fieldlists (type, spaces);
3714 /* Print the contents of the TYPE's type_specific union, assuming that
3715 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
3718 print_gnat_stuff (struct type *type, int spaces)
3720 struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
3722 recursive_dump_type (descriptive_type, spaces + 2);
3725 static struct obstack dont_print_type_obstack;
3728 recursive_dump_type (struct type *type, int spaces)
3733 obstack_begin (&dont_print_type_obstack, 0);
3735 if (TYPE_NFIELDS (type) > 0
3736 || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0))
3738 struct type **first_dont_print
3739 = (struct type **) obstack_base (&dont_print_type_obstack);
3741 int i = (struct type **)
3742 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
3746 if (type == first_dont_print[i])
3748 printfi_filtered (spaces, "type node ");
3749 gdb_print_host_address (type, gdb_stdout);
3750 printf_filtered (_(" <same as already seen type>\n"));
3755 obstack_ptr_grow (&dont_print_type_obstack, type);
3758 printfi_filtered (spaces, "type node ");
3759 gdb_print_host_address (type, gdb_stdout);
3760 printf_filtered ("\n");
3761 printfi_filtered (spaces, "name '%s' (",
3762 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
3763 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
3764 printf_filtered (")\n");
3765 printfi_filtered (spaces, "tagname '%s' (",
3766 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
3767 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
3768 printf_filtered (")\n");
3769 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
3770 switch (TYPE_CODE (type))
3772 case TYPE_CODE_UNDEF:
3773 printf_filtered ("(TYPE_CODE_UNDEF)");
3776 printf_filtered ("(TYPE_CODE_PTR)");
3778 case TYPE_CODE_ARRAY:
3779 printf_filtered ("(TYPE_CODE_ARRAY)");
3781 case TYPE_CODE_STRUCT:
3782 printf_filtered ("(TYPE_CODE_STRUCT)");
3784 case TYPE_CODE_UNION:
3785 printf_filtered ("(TYPE_CODE_UNION)");
3787 case TYPE_CODE_ENUM:
3788 printf_filtered ("(TYPE_CODE_ENUM)");
3790 case TYPE_CODE_FLAGS:
3791 printf_filtered ("(TYPE_CODE_FLAGS)");
3793 case TYPE_CODE_FUNC:
3794 printf_filtered ("(TYPE_CODE_FUNC)");
3797 printf_filtered ("(TYPE_CODE_INT)");
3800 printf_filtered ("(TYPE_CODE_FLT)");
3802 case TYPE_CODE_VOID:
3803 printf_filtered ("(TYPE_CODE_VOID)");
3806 printf_filtered ("(TYPE_CODE_SET)");
3808 case TYPE_CODE_RANGE:
3809 printf_filtered ("(TYPE_CODE_RANGE)");
3811 case TYPE_CODE_STRING:
3812 printf_filtered ("(TYPE_CODE_STRING)");
3814 case TYPE_CODE_ERROR:
3815 printf_filtered ("(TYPE_CODE_ERROR)");
3817 case TYPE_CODE_MEMBERPTR:
3818 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
3820 case TYPE_CODE_METHODPTR:
3821 printf_filtered ("(TYPE_CODE_METHODPTR)");
3823 case TYPE_CODE_METHOD:
3824 printf_filtered ("(TYPE_CODE_METHOD)");
3827 printf_filtered ("(TYPE_CODE_REF)");
3829 case TYPE_CODE_CHAR:
3830 printf_filtered ("(TYPE_CODE_CHAR)");
3832 case TYPE_CODE_BOOL:
3833 printf_filtered ("(TYPE_CODE_BOOL)");
3835 case TYPE_CODE_COMPLEX:
3836 printf_filtered ("(TYPE_CODE_COMPLEX)");
3838 case TYPE_CODE_TYPEDEF:
3839 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3841 case TYPE_CODE_NAMESPACE:
3842 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3845 printf_filtered ("(UNKNOWN TYPE CODE)");
3848 puts_filtered ("\n");
3849 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
3850 if (TYPE_OBJFILE_OWNED (type))
3852 printfi_filtered (spaces, "objfile ");
3853 gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout);
3857 printfi_filtered (spaces, "gdbarch ");
3858 gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout);
3860 printf_filtered ("\n");
3861 printfi_filtered (spaces, "target_type ");
3862 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
3863 printf_filtered ("\n");
3864 if (TYPE_TARGET_TYPE (type) != NULL)
3866 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3868 printfi_filtered (spaces, "pointer_type ");
3869 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
3870 printf_filtered ("\n");
3871 printfi_filtered (spaces, "reference_type ");
3872 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
3873 printf_filtered ("\n");
3874 printfi_filtered (spaces, "type_chain ");
3875 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
3876 printf_filtered ("\n");
3877 printfi_filtered (spaces, "instance_flags 0x%x",
3878 TYPE_INSTANCE_FLAGS (type));
3879 if (TYPE_CONST (type))
3881 puts_filtered (" TYPE_FLAG_CONST");
3883 if (TYPE_VOLATILE (type))
3885 puts_filtered (" TYPE_FLAG_VOLATILE");
3887 if (TYPE_CODE_SPACE (type))
3889 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3891 if (TYPE_DATA_SPACE (type))
3893 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3895 if (TYPE_ADDRESS_CLASS_1 (type))
3897 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3899 if (TYPE_ADDRESS_CLASS_2 (type))
3901 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3903 if (TYPE_RESTRICT (type))
3905 puts_filtered (" TYPE_FLAG_RESTRICT");
3907 puts_filtered ("\n");
3909 printfi_filtered (spaces, "flags");
3910 if (TYPE_UNSIGNED (type))
3912 puts_filtered (" TYPE_FLAG_UNSIGNED");
3914 if (TYPE_NOSIGN (type))
3916 puts_filtered (" TYPE_FLAG_NOSIGN");
3918 if (TYPE_STUB (type))
3920 puts_filtered (" TYPE_FLAG_STUB");
3922 if (TYPE_TARGET_STUB (type))
3924 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3926 if (TYPE_STATIC (type))
3928 puts_filtered (" TYPE_FLAG_STATIC");
3930 if (TYPE_PROTOTYPED (type))
3932 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3934 if (TYPE_INCOMPLETE (type))
3936 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3938 if (TYPE_VARARGS (type))
3940 puts_filtered (" TYPE_FLAG_VARARGS");
3942 /* This is used for things like AltiVec registers on ppc. Gcc emits
3943 an attribute for the array type, which tells whether or not we
3944 have a vector, instead of a regular array. */
3945 if (TYPE_VECTOR (type))
3947 puts_filtered (" TYPE_FLAG_VECTOR");
3949 if (TYPE_FIXED_INSTANCE (type))
3951 puts_filtered (" TYPE_FIXED_INSTANCE");
3953 if (TYPE_STUB_SUPPORTED (type))
3955 puts_filtered (" TYPE_STUB_SUPPORTED");
3957 if (TYPE_NOTTEXT (type))
3959 puts_filtered (" TYPE_NOTTEXT");
3961 puts_filtered ("\n");
3962 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3963 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3964 puts_filtered ("\n");
3965 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3967 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
3968 printfi_filtered (spaces + 2,
3969 "[%d] enumval %s type ",
3970 idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
3972 printfi_filtered (spaces + 2,
3973 "[%d] bitpos %d bitsize %d type ",
3974 idx, TYPE_FIELD_BITPOS (type, idx),
3975 TYPE_FIELD_BITSIZE (type, idx));
3976 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3977 printf_filtered (" name '%s' (",
3978 TYPE_FIELD_NAME (type, idx) != NULL
3979 ? TYPE_FIELD_NAME (type, idx)
3981 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3982 printf_filtered (")\n");
3983 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3985 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3988 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
3990 printfi_filtered (spaces, "low %s%s high %s%s\n",
3991 plongest (TYPE_LOW_BOUND (type)),
3992 TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
3993 plongest (TYPE_HIGH_BOUND (type)),
3994 TYPE_HIGH_BOUND_UNDEFINED (type)
3995 ? " (undefined)" : "");
3997 printfi_filtered (spaces, "vptr_basetype ");
3998 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3999 puts_filtered ("\n");
4000 if (TYPE_VPTR_BASETYPE (type) != NULL)
4002 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
4004 printfi_filtered (spaces, "vptr_fieldno %d\n",
4005 TYPE_VPTR_FIELDNO (type));
4007 switch (TYPE_SPECIFIC_FIELD (type))
4009 case TYPE_SPECIFIC_CPLUS_STUFF:
4010 printfi_filtered (spaces, "cplus_stuff ");
4011 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
4013 puts_filtered ("\n");
4014 print_cplus_stuff (type, spaces);
4017 case TYPE_SPECIFIC_GNAT_STUFF:
4018 printfi_filtered (spaces, "gnat_stuff ");
4019 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type), gdb_stdout);
4020 puts_filtered ("\n");
4021 print_gnat_stuff (type, spaces);
4024 case TYPE_SPECIFIC_FLOATFORMAT:
4025 printfi_filtered (spaces, "floatformat ");
4026 if (TYPE_FLOATFORMAT (type) == NULL)
4027 puts_filtered ("(null)");
4030 puts_filtered ("{ ");
4031 if (TYPE_FLOATFORMAT (type)[0] == NULL
4032 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
4033 puts_filtered ("(null)");
4035 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
4037 puts_filtered (", ");
4038 if (TYPE_FLOATFORMAT (type)[1] == NULL
4039 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
4040 puts_filtered ("(null)");
4042 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
4044 puts_filtered (" }");
4046 puts_filtered ("\n");
4049 case TYPE_SPECIFIC_FUNC:
4050 printfi_filtered (spaces, "calling_convention %d\n",
4051 TYPE_CALLING_CONVENTION (type));
4052 /* tail_call_list is not printed. */
4057 obstack_free (&dont_print_type_obstack, NULL);
4060 /* Trivial helpers for the libiberty hash table, for mapping one
4065 struct type *old, *new;
4069 type_pair_hash (const void *item)
4071 const struct type_pair *pair = item;
4073 return htab_hash_pointer (pair->old);
4077 type_pair_eq (const void *item_lhs, const void *item_rhs)
4079 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
4081 return lhs->old == rhs->old;
4084 /* Allocate the hash table used by copy_type_recursive to walk
4085 types without duplicates. We use OBJFILE's obstack, because
4086 OBJFILE is about to be deleted. */
4089 create_copied_types_hash (struct objfile *objfile)
4091 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
4092 NULL, &objfile->objfile_obstack,
4093 hashtab_obstack_allocate,
4094 dummy_obstack_deallocate);
4097 /* Recursively copy (deep copy) TYPE, if it is associated with
4098 OBJFILE. Return a new type allocated using malloc, a saved type if
4099 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
4100 not associated with OBJFILE. */
4103 copy_type_recursive (struct objfile *objfile,
4105 htab_t copied_types)
4107 struct type_pair *stored, pair;
4109 struct type *new_type;
4111 if (! TYPE_OBJFILE_OWNED (type))
4114 /* This type shouldn't be pointing to any types in other objfiles;
4115 if it did, the type might disappear unexpectedly. */
4116 gdb_assert (TYPE_OBJFILE (type) == objfile);
4119 slot = htab_find_slot (copied_types, &pair, INSERT);
4121 return ((struct type_pair *) *slot)->new;
4123 new_type = alloc_type_arch (get_type_arch (type));
4125 /* We must add the new type to the hash table immediately, in case
4126 we encounter this type again during a recursive call below. */
4128 = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
4130 stored->new = new_type;
4133 /* Copy the common fields of types. For the main type, we simply
4134 copy the entire thing and then update specific fields as needed. */
4135 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
4136 TYPE_OBJFILE_OWNED (new_type) = 0;
4137 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
4139 if (TYPE_NAME (type))
4140 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
4141 if (TYPE_TAG_NAME (type))
4142 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
4144 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4145 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4147 /* Copy the fields. */
4148 if (TYPE_NFIELDS (type))
4152 nfields = TYPE_NFIELDS (type);
4153 TYPE_FIELDS (new_type) = XCNEWVEC (struct field, nfields);
4154 for (i = 0; i < nfields; i++)
4156 TYPE_FIELD_ARTIFICIAL (new_type, i) =
4157 TYPE_FIELD_ARTIFICIAL (type, i);
4158 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
4159 if (TYPE_FIELD_TYPE (type, i))
4160 TYPE_FIELD_TYPE (new_type, i)
4161 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
4163 if (TYPE_FIELD_NAME (type, i))
4164 TYPE_FIELD_NAME (new_type, i) =
4165 xstrdup (TYPE_FIELD_NAME (type, i));
4166 switch (TYPE_FIELD_LOC_KIND (type, i))
4168 case FIELD_LOC_KIND_BITPOS:
4169 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
4170 TYPE_FIELD_BITPOS (type, i));
4172 case FIELD_LOC_KIND_ENUMVAL:
4173 SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i),
4174 TYPE_FIELD_ENUMVAL (type, i));
4176 case FIELD_LOC_KIND_PHYSADDR:
4177 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
4178 TYPE_FIELD_STATIC_PHYSADDR (type, i));
4180 case FIELD_LOC_KIND_PHYSNAME:
4181 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
4182 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
4186 internal_error (__FILE__, __LINE__,
4187 _("Unexpected type field location kind: %d"),
4188 TYPE_FIELD_LOC_KIND (type, i));
4193 /* For range types, copy the bounds information. */
4194 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4196 TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
4197 *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
4200 /* Copy the data location information. */
4201 if (TYPE_DATA_LOCATION (type) != NULL)
4203 TYPE_DATA_LOCATION (new_type)
4204 = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop));
4205 memcpy (TYPE_DATA_LOCATION (new_type), TYPE_DATA_LOCATION (type),
4206 sizeof (struct dynamic_prop));
4209 /* Copy pointers to other types. */
4210 if (TYPE_TARGET_TYPE (type))
4211 TYPE_TARGET_TYPE (new_type) =
4212 copy_type_recursive (objfile,
4213 TYPE_TARGET_TYPE (type),
4215 if (TYPE_VPTR_BASETYPE (type))
4216 TYPE_VPTR_BASETYPE (new_type) =
4217 copy_type_recursive (objfile,
4218 TYPE_VPTR_BASETYPE (type),
4221 /* Maybe copy the type_specific bits.
4223 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
4224 base classes and methods. There's no fundamental reason why we
4225 can't, but at the moment it is not needed. */
4227 switch (TYPE_SPECIFIC_FIELD (type))
4229 case TYPE_SPECIFIC_NONE:
4231 case TYPE_SPECIFIC_FUNC:
4232 INIT_FUNC_SPECIFIC (new_type);
4233 TYPE_CALLING_CONVENTION (new_type) = TYPE_CALLING_CONVENTION (type);
4234 TYPE_NO_RETURN (new_type) = TYPE_NO_RETURN (type);
4235 TYPE_TAIL_CALL_LIST (new_type) = NULL;
4237 case TYPE_SPECIFIC_FLOATFORMAT:
4238 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
4240 case TYPE_SPECIFIC_CPLUS_STUFF:
4241 INIT_CPLUS_SPECIFIC (new_type);
4243 case TYPE_SPECIFIC_GNAT_STUFF:
4244 INIT_GNAT_SPECIFIC (new_type);
4247 gdb_assert_not_reached ("bad type_specific_kind");
4253 /* Make a copy of the given TYPE, except that the pointer & reference
4254 types are not preserved.
4256 This function assumes that the given type has an associated objfile.
4257 This objfile is used to allocate the new type. */
4260 copy_type (const struct type *type)
4262 struct type *new_type;
4264 gdb_assert (TYPE_OBJFILE_OWNED (type));
4266 new_type = alloc_type_copy (type);
4267 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4268 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4269 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
4270 sizeof (struct main_type));
4271 if (TYPE_DATA_LOCATION (type) != NULL)
4273 TYPE_DATA_LOCATION (new_type)
4274 = TYPE_ALLOC (new_type, sizeof (struct dynamic_prop));
4275 memcpy (TYPE_DATA_LOCATION (new_type), TYPE_DATA_LOCATION (type),
4276 sizeof (struct dynamic_prop));
4282 /* Helper functions to initialize architecture-specific types. */
4284 /* Allocate a type structure associated with GDBARCH and set its
4285 CODE, LENGTH, and NAME fields. */
4288 arch_type (struct gdbarch *gdbarch,
4289 enum type_code code, int length, char *name)
4293 type = alloc_type_arch (gdbarch);
4294 TYPE_CODE (type) = code;
4295 TYPE_LENGTH (type) = length;
4298 TYPE_NAME (type) = xstrdup (name);
4303 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
4304 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4305 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4308 arch_integer_type (struct gdbarch *gdbarch,
4309 int bit, int unsigned_p, char *name)
4313 t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
4315 TYPE_UNSIGNED (t) = 1;
4316 if (name && strcmp (name, "char") == 0)
4317 TYPE_NOSIGN (t) = 1;
4322 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
4323 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4324 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4327 arch_character_type (struct gdbarch *gdbarch,
4328 int bit, int unsigned_p, char *name)
4332 t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
4334 TYPE_UNSIGNED (t) = 1;
4339 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
4340 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4341 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4344 arch_boolean_type (struct gdbarch *gdbarch,
4345 int bit, int unsigned_p, char *name)
4349 t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
4351 TYPE_UNSIGNED (t) = 1;
4356 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
4357 BIT is the type size in bits; if BIT equals -1, the size is
4358 determined by the floatformat. NAME is the type name. Set the
4359 TYPE_FLOATFORMAT from FLOATFORMATS. */
4362 arch_float_type (struct gdbarch *gdbarch,
4363 int bit, char *name, const struct floatformat **floatformats)
4369 gdb_assert (floatformats != NULL);
4370 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
4371 bit = floatformats[0]->totalsize;
4373 gdb_assert (bit >= 0);
4375 t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
4376 TYPE_FLOATFORMAT (t) = floatformats;
4380 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
4381 NAME is the type name. TARGET_TYPE is the component float type. */
4384 arch_complex_type (struct gdbarch *gdbarch,
4385 char *name, struct type *target_type)
4389 t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
4390 2 * TYPE_LENGTH (target_type), name);
4391 TYPE_TARGET_TYPE (t) = target_type;
4395 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
4396 NAME is the type name. LENGTH is the size of the flag word in bytes. */
4399 arch_flags_type (struct gdbarch *gdbarch, char *name, int length)
4401 int nfields = length * TARGET_CHAR_BIT;
4404 type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name);
4405 TYPE_UNSIGNED (type) = 1;
4406 TYPE_NFIELDS (type) = nfields;
4407 TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
4412 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
4413 position BITPOS is called NAME. */
4416 append_flags_type_flag (struct type *type, int bitpos, char *name)
4418 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
4419 gdb_assert (bitpos < TYPE_NFIELDS (type));
4420 gdb_assert (bitpos >= 0);
4424 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
4425 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), bitpos);
4429 /* Don't show this field to the user. */
4430 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), -1);
4434 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
4435 specified by CODE) associated with GDBARCH. NAME is the type name. */
4438 arch_composite_type (struct gdbarch *gdbarch, char *name, enum type_code code)
4442 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
4443 t = arch_type (gdbarch, code, 0, NULL);
4444 TYPE_TAG_NAME (t) = name;
4445 INIT_CPLUS_SPECIFIC (t);
4449 /* Add new field with name NAME and type FIELD to composite type T.
4450 Do not set the field's position or adjust the type's length;
4451 the caller should do so. Return the new field. */
4454 append_composite_type_field_raw (struct type *t, char *name,
4459 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
4460 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
4461 sizeof (struct field) * TYPE_NFIELDS (t));
4462 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
4463 memset (f, 0, sizeof f[0]);
4464 FIELD_TYPE (f[0]) = field;
4465 FIELD_NAME (f[0]) = name;
4469 /* Add new field with name NAME and type FIELD to composite type T.
4470 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
4473 append_composite_type_field_aligned (struct type *t, char *name,
4474 struct type *field, int alignment)
4476 struct field *f = append_composite_type_field_raw (t, name, field);
4478 if (TYPE_CODE (t) == TYPE_CODE_UNION)
4480 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
4481 TYPE_LENGTH (t) = TYPE_LENGTH (field);
4483 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
4485 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
4486 if (TYPE_NFIELDS (t) > 1)
4488 SET_FIELD_BITPOS (f[0],
4489 (FIELD_BITPOS (f[-1])
4490 + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
4491 * TARGET_CHAR_BIT)));
4497 alignment *= TARGET_CHAR_BIT;
4498 left = FIELD_BITPOS (f[0]) % alignment;
4502 SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left));
4503 TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
4510 /* Add new field with name NAME and type FIELD to composite type T. */
4513 append_composite_type_field (struct type *t, char *name,
4516 append_composite_type_field_aligned (t, name, field, 0);
4519 static struct gdbarch_data *gdbtypes_data;
4521 const struct builtin_type *
4522 builtin_type (struct gdbarch *gdbarch)
4524 return gdbarch_data (gdbarch, gdbtypes_data);
4528 gdbtypes_post_init (struct gdbarch *gdbarch)
4530 struct builtin_type *builtin_type
4531 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
4534 builtin_type->builtin_void
4535 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
4536 builtin_type->builtin_char
4537 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4538 !gdbarch_char_signed (gdbarch), "char");
4539 builtin_type->builtin_signed_char
4540 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4542 builtin_type->builtin_unsigned_char
4543 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4544 1, "unsigned char");
4545 builtin_type->builtin_short
4546 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
4548 builtin_type->builtin_unsigned_short
4549 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
4550 1, "unsigned short");
4551 builtin_type->builtin_int
4552 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
4554 builtin_type->builtin_unsigned_int
4555 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
4557 builtin_type->builtin_long
4558 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
4560 builtin_type->builtin_unsigned_long
4561 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
4562 1, "unsigned long");
4563 builtin_type->builtin_long_long
4564 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
4566 builtin_type->builtin_unsigned_long_long
4567 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
4568 1, "unsigned long long");
4569 builtin_type->builtin_float
4570 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
4571 "float", gdbarch_float_format (gdbarch));
4572 builtin_type->builtin_double
4573 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
4574 "double", gdbarch_double_format (gdbarch));
4575 builtin_type->builtin_long_double
4576 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
4577 "long double", gdbarch_long_double_format (gdbarch));
4578 builtin_type->builtin_complex
4579 = arch_complex_type (gdbarch, "complex",
4580 builtin_type->builtin_float);
4581 builtin_type->builtin_double_complex
4582 = arch_complex_type (gdbarch, "double complex",
4583 builtin_type->builtin_double);
4584 builtin_type->builtin_string
4585 = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string");
4586 builtin_type->builtin_bool
4587 = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool");
4589 /* The following three are about decimal floating point types, which
4590 are 32-bits, 64-bits and 128-bits respectively. */
4591 builtin_type->builtin_decfloat
4592 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 32 / 8, "_Decimal32");
4593 builtin_type->builtin_decdouble
4594 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 64 / 8, "_Decimal64");
4595 builtin_type->builtin_declong
4596 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 128 / 8, "_Decimal128");
4598 /* "True" character types. */
4599 builtin_type->builtin_true_char
4600 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character");
4601 builtin_type->builtin_true_unsigned_char
4602 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character");
4604 /* Fixed-size integer types. */
4605 builtin_type->builtin_int0
4606 = arch_integer_type (gdbarch, 0, 0, "int0_t");
4607 builtin_type->builtin_int8
4608 = arch_integer_type (gdbarch, 8, 0, "int8_t");
4609 builtin_type->builtin_uint8
4610 = arch_integer_type (gdbarch, 8, 1, "uint8_t");
4611 builtin_type->builtin_int16
4612 = arch_integer_type (gdbarch, 16, 0, "int16_t");
4613 builtin_type->builtin_uint16
4614 = arch_integer_type (gdbarch, 16, 1, "uint16_t");
4615 builtin_type->builtin_int32
4616 = arch_integer_type (gdbarch, 32, 0, "int32_t");
4617 builtin_type->builtin_uint32
4618 = arch_integer_type (gdbarch, 32, 1, "uint32_t");
4619 builtin_type->builtin_int64
4620 = arch_integer_type (gdbarch, 64, 0, "int64_t");
4621 builtin_type->builtin_uint64
4622 = arch_integer_type (gdbarch, 64, 1, "uint64_t");
4623 builtin_type->builtin_int128
4624 = arch_integer_type (gdbarch, 128, 0, "int128_t");
4625 builtin_type->builtin_uint128
4626 = arch_integer_type (gdbarch, 128, 1, "uint128_t");
4627 TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |=
4628 TYPE_INSTANCE_FLAG_NOTTEXT;
4629 TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |=
4630 TYPE_INSTANCE_FLAG_NOTTEXT;
4632 /* Wide character types. */
4633 builtin_type->builtin_char16
4634 = arch_integer_type (gdbarch, 16, 0, "char16_t");
4635 builtin_type->builtin_char32
4636 = arch_integer_type (gdbarch, 32, 0, "char32_t");
4639 /* Default data/code pointer types. */
4640 builtin_type->builtin_data_ptr
4641 = lookup_pointer_type (builtin_type->builtin_void);
4642 builtin_type->builtin_func_ptr
4643 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
4644 builtin_type->builtin_func_func
4645 = lookup_function_type (builtin_type->builtin_func_ptr);
4647 /* This type represents a GDB internal function. */
4648 builtin_type->internal_fn
4649 = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0,
4650 "<internal function>");
4652 /* This type represents an xmethod. */
4653 builtin_type->xmethod
4654 = arch_type (gdbarch, TYPE_CODE_XMETHOD, 0, "<xmethod>");
4656 return builtin_type;
4659 /* This set of objfile-based types is intended to be used by symbol
4660 readers as basic types. */
4662 static const struct objfile_data *objfile_type_data;
4664 const struct objfile_type *
4665 objfile_type (struct objfile *objfile)
4667 struct gdbarch *gdbarch;
4668 struct objfile_type *objfile_type
4669 = objfile_data (objfile, objfile_type_data);
4672 return objfile_type;
4674 objfile_type = OBSTACK_CALLOC (&objfile->objfile_obstack,
4675 1, struct objfile_type);
4677 /* Use the objfile architecture to determine basic type properties. */
4678 gdbarch = get_objfile_arch (objfile);
4681 objfile_type->builtin_void
4682 = init_type (TYPE_CODE_VOID, 1,
4686 objfile_type->builtin_char
4687 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4689 | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
4691 objfile_type->builtin_signed_char
4692 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4694 "signed char", objfile);
4695 objfile_type->builtin_unsigned_char
4696 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4698 "unsigned char", objfile);
4699 objfile_type->builtin_short
4700 = init_type (TYPE_CODE_INT,
4701 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4702 0, "short", objfile);
4703 objfile_type->builtin_unsigned_short
4704 = init_type (TYPE_CODE_INT,
4705 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4706 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
4707 objfile_type->builtin_int
4708 = init_type (TYPE_CODE_INT,
4709 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4711 objfile_type->builtin_unsigned_int
4712 = init_type (TYPE_CODE_INT,
4713 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4714 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
4715 objfile_type->builtin_long
4716 = init_type (TYPE_CODE_INT,
4717 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4718 0, "long", objfile);
4719 objfile_type->builtin_unsigned_long
4720 = init_type (TYPE_CODE_INT,
4721 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4722 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
4723 objfile_type->builtin_long_long
4724 = init_type (TYPE_CODE_INT,
4725 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4726 0, "long long", objfile);
4727 objfile_type->builtin_unsigned_long_long
4728 = init_type (TYPE_CODE_INT,
4729 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4730 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
4732 objfile_type->builtin_float
4733 = init_type (TYPE_CODE_FLT,
4734 gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT,
4735 0, "float", objfile);
4736 TYPE_FLOATFORMAT (objfile_type->builtin_float)
4737 = gdbarch_float_format (gdbarch);
4738 objfile_type->builtin_double
4739 = init_type (TYPE_CODE_FLT,
4740 gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT,
4741 0, "double", objfile);
4742 TYPE_FLOATFORMAT (objfile_type->builtin_double)
4743 = gdbarch_double_format (gdbarch);
4744 objfile_type->builtin_long_double
4745 = init_type (TYPE_CODE_FLT,
4746 gdbarch_long_double_bit (gdbarch) / TARGET_CHAR_BIT,
4747 0, "long double", objfile);
4748 TYPE_FLOATFORMAT (objfile_type->builtin_long_double)
4749 = gdbarch_long_double_format (gdbarch);
4751 /* This type represents a type that was unrecognized in symbol read-in. */
4752 objfile_type->builtin_error
4753 = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>", objfile);
4755 /* The following set of types is used for symbols with no
4756 debug information. */
4757 objfile_type->nodebug_text_symbol
4758 = init_type (TYPE_CODE_FUNC, 1, 0,
4759 "<text variable, no debug info>", objfile);
4760 TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
4761 = objfile_type->builtin_int;
4762 objfile_type->nodebug_text_gnu_ifunc_symbol
4763 = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC,
4764 "<text gnu-indirect-function variable, no debug info>",
4766 TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
4767 = objfile_type->nodebug_text_symbol;
4768 objfile_type->nodebug_got_plt_symbol
4769 = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0,
4770 "<text from jump slot in .got.plt, no debug info>",
4772 TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol)
4773 = objfile_type->nodebug_text_symbol;
4774 objfile_type->nodebug_data_symbol
4775 = init_type (TYPE_CODE_INT,
4776 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4777 "<data variable, no debug info>", objfile);
4778 objfile_type->nodebug_unknown_symbol
4779 = init_type (TYPE_CODE_INT, 1, 0,
4780 "<variable (not text or data), no debug info>", objfile);
4781 objfile_type->nodebug_tls_symbol
4782 = init_type (TYPE_CODE_INT,
4783 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4784 "<thread local variable, no debug info>", objfile);
4786 /* NOTE: on some targets, addresses and pointers are not necessarily
4790 - gdb's `struct type' always describes the target's
4792 - gdb's `struct value' objects should always hold values in
4794 - gdb's CORE_ADDR values are addresses in the unified virtual
4795 address space that the assembler and linker work with. Thus,
4796 since target_read_memory takes a CORE_ADDR as an argument, it
4797 can access any memory on the target, even if the processor has
4798 separate code and data address spaces.
4800 In this context, objfile_type->builtin_core_addr is a bit odd:
4801 it's a target type for a value the target will never see. It's
4802 only used to hold the values of (typeless) linker symbols, which
4803 are indeed in the unified virtual address space. */
4805 objfile_type->builtin_core_addr
4806 = init_type (TYPE_CODE_INT,
4807 gdbarch_addr_bit (gdbarch) / 8,
4808 TYPE_FLAG_UNSIGNED, "__CORE_ADDR", objfile);
4810 set_objfile_data (objfile, objfile_type_data, objfile_type);
4811 return objfile_type;
4814 extern initialize_file_ftype _initialize_gdbtypes;
4817 _initialize_gdbtypes (void)
4819 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
4820 objfile_type_data = register_objfile_data ();
4822 add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug,
4823 _("Set debugging of C++ overloading."),
4824 _("Show debugging of C++ overloading."),
4825 _("When enabled, ranking of the "
4826 "functions is displayed."),
4828 show_overload_debug,
4829 &setdebuglist, &showdebuglist);
4831 /* Add user knob for controlling resolution of opaque types. */
4832 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
4833 &opaque_type_resolution,
4834 _("Set resolution of opaque struct/class/union"
4835 " types (if set before loading symbols)."),
4836 _("Show resolution of opaque struct/class/union"
4837 " types (if set before loading symbols)."),
4839 show_opaque_type_resolution,
4840 &setlist, &showlist);
4842 /* Add an option to permit non-strict type checking. */
4843 add_setshow_boolean_cmd ("type", class_support,
4844 &strict_type_checking,
4845 _("Set strict type checking."),
4846 _("Show strict type checking."),
4848 show_strict_type_checking,
4849 &setchecklist, &showchecklist);