1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2017 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 CV_CONVERSION_BADNESS = {1, 0};
55 const struct rank INTEGER_CONVERSION_BADNESS = {2,0};
56 const struct rank FLOAT_CONVERSION_BADNESS = {2,0};
57 const struct rank INT_FLOAT_CONVERSION_BADNESS = {2,0};
58 const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0};
59 const struct rank BOOL_CONVERSION_BADNESS = {3,0};
60 const struct rank BASE_CONVERSION_BADNESS = {2,0};
61 const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
62 const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
63 const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
64 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
66 /* Floatformat pairs. */
67 const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
68 &floatformat_ieee_half_big,
69 &floatformat_ieee_half_little
71 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
72 &floatformat_ieee_single_big,
73 &floatformat_ieee_single_little
75 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
76 &floatformat_ieee_double_big,
77 &floatformat_ieee_double_little
79 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
80 &floatformat_ieee_double_big,
81 &floatformat_ieee_double_littlebyte_bigword
83 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
84 &floatformat_i387_ext,
87 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
88 &floatformat_m68881_ext,
89 &floatformat_m68881_ext
91 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
92 &floatformat_arm_ext_big,
93 &floatformat_arm_ext_littlebyte_bigword
95 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
96 &floatformat_ia64_spill_big,
97 &floatformat_ia64_spill_little
99 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
100 &floatformat_ia64_quad_big,
101 &floatformat_ia64_quad_little
103 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
107 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
111 const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
112 &floatformat_ibm_long_double_big,
113 &floatformat_ibm_long_double_little
116 /* Should opaque types be resolved? */
118 static int opaque_type_resolution = 1;
120 /* A flag to enable printing of debugging information of C++
123 unsigned int overload_debug = 0;
125 /* A flag to enable strict type checking. */
127 static int strict_type_checking = 1;
129 /* A function to show whether opaque types are resolved. */
132 show_opaque_type_resolution (struct ui_file *file, int from_tty,
133 struct cmd_list_element *c,
136 fprintf_filtered (file, _("Resolution of opaque struct/class/union types "
137 "(if set before loading symbols) is %s.\n"),
141 /* A function to show whether C++ overload debugging is enabled. */
144 show_overload_debug (struct ui_file *file, int from_tty,
145 struct cmd_list_element *c, const char *value)
147 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
151 /* A function to show the status of strict type checking. */
154 show_strict_type_checking (struct ui_file *file, int from_tty,
155 struct cmd_list_element *c, const char *value)
157 fprintf_filtered (file, _("Strict type checking is %s.\n"), value);
161 /* Allocate a new OBJFILE-associated type structure and fill it
162 with some defaults. Space for the type structure is allocated
163 on the objfile's objfile_obstack. */
166 alloc_type (struct objfile *objfile)
170 gdb_assert (objfile != NULL);
172 /* Alloc the structure and start off with all fields zeroed. */
173 type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
174 TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
176 OBJSTAT (objfile, n_types++);
178 TYPE_OBJFILE_OWNED (type) = 1;
179 TYPE_OWNER (type).objfile = objfile;
181 /* Initialize the fields that might not be zero. */
183 TYPE_CODE (type) = TYPE_CODE_UNDEF;
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
191 on the obstack associated with GDBARCH. */
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 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct type);
203 TYPE_MAIN_TYPE (type) = GDBARCH_OBSTACK_ZALLOC (gdbarch, 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_CHAIN (type) = type; /* Chain back to itself. */
216 /* If TYPE is objfile-associated, allocate a new type structure
217 associated with the same objfile. If TYPE is gdbarch-associated,
218 allocate a new type structure associated with the same gdbarch. */
221 alloc_type_copy (const struct type *type)
223 if (TYPE_OBJFILE_OWNED (type))
224 return alloc_type (TYPE_OWNER (type).objfile);
226 return alloc_type_arch (TYPE_OWNER (type).gdbarch);
229 /* If TYPE is gdbarch-associated, return that architecture.
230 If TYPE is objfile-associated, return that objfile's architecture. */
233 get_type_arch (const struct type *type)
235 if (TYPE_OBJFILE_OWNED (type))
236 return get_objfile_arch (TYPE_OWNER (type).objfile);
238 return TYPE_OWNER (type).gdbarch;
241 /* See gdbtypes.h. */
244 get_target_type (struct type *type)
248 type = TYPE_TARGET_TYPE (type);
250 type = check_typedef (type);
256 /* See gdbtypes.h. */
259 type_length_units (struct type *type)
261 struct gdbarch *arch = get_type_arch (type);
262 int unit_size = gdbarch_addressable_memory_unit_size (arch);
264 return TYPE_LENGTH (type) / unit_size;
267 /* Alloc a new type instance structure, fill it with some defaults,
268 and point it at OLDTYPE. Allocate the new type instance from the
269 same place as OLDTYPE. */
272 alloc_type_instance (struct type *oldtype)
276 /* Allocate the structure. */
278 if (! TYPE_OBJFILE_OWNED (oldtype))
279 type = XCNEW (struct type);
281 type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
284 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
286 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
291 /* Clear all remnants of the previous type at TYPE, in preparation for
292 replacing it with something else. Preserve owner information. */
295 smash_type (struct type *type)
297 int objfile_owned = TYPE_OBJFILE_OWNED (type);
298 union type_owner owner = TYPE_OWNER (type);
300 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
302 /* Restore owner information. */
303 TYPE_OBJFILE_OWNED (type) = objfile_owned;
304 TYPE_OWNER (type) = owner;
306 /* For now, delete the rings. */
307 TYPE_CHAIN (type) = type;
309 /* For now, leave the pointer/reference types alone. */
312 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
313 to a pointer to memory where the pointer type should be stored.
314 If *TYPEPTR is zero, update it to point to the pointer type we return.
315 We allocate new memory if needed. */
318 make_pointer_type (struct type *type, struct type **typeptr)
320 struct type *ntype; /* New type */
323 ntype = TYPE_POINTER_TYPE (type);
328 return ntype; /* Don't care about alloc,
329 and have new type. */
330 else if (*typeptr == 0)
332 *typeptr = ntype; /* Tracking alloc, and have new type. */
337 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
339 ntype = alloc_type_copy (type);
343 else /* We have storage, but need to reset it. */
346 chain = TYPE_CHAIN (ntype);
348 TYPE_CHAIN (ntype) = chain;
351 TYPE_TARGET_TYPE (ntype) = type;
352 TYPE_POINTER_TYPE (type) = ntype;
354 /* FIXME! Assumes the machine has only one representation for pointers! */
357 = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
358 TYPE_CODE (ntype) = TYPE_CODE_PTR;
360 /* Mark pointers as unsigned. The target converts between pointers
361 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
362 gdbarch_address_to_pointer. */
363 TYPE_UNSIGNED (ntype) = 1;
365 /* Update the length of all the other variants of this type. */
366 chain = TYPE_CHAIN (ntype);
367 while (chain != ntype)
369 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
370 chain = TYPE_CHAIN (chain);
376 /* Given a type TYPE, return a type of pointers to that type.
377 May need to construct such a type if this is the first use. */
380 lookup_pointer_type (struct type *type)
382 return make_pointer_type (type, (struct type **) 0);
385 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
386 points to a pointer to memory where the reference type should be
387 stored. If *TYPEPTR is zero, update it to point to the reference
388 type we return. We allocate new memory if needed. REFCODE denotes
389 the kind of reference type to lookup (lvalue or rvalue reference). */
392 make_reference_type (struct type *type, struct type **typeptr,
393 enum type_code refcode)
395 struct type *ntype; /* New type */
396 struct type **reftype;
399 gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
401 ntype = (refcode == TYPE_CODE_REF ? TYPE_REFERENCE_TYPE (type)
402 : TYPE_RVALUE_REFERENCE_TYPE (type));
407 return ntype; /* Don't care about alloc,
408 and have new type. */
409 else if (*typeptr == 0)
411 *typeptr = ntype; /* Tracking alloc, and have new type. */
416 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
418 ntype = alloc_type_copy (type);
422 else /* We have storage, but need to reset it. */
425 chain = TYPE_CHAIN (ntype);
427 TYPE_CHAIN (ntype) = chain;
430 TYPE_TARGET_TYPE (ntype) = type;
431 reftype = (refcode == TYPE_CODE_REF ? &TYPE_REFERENCE_TYPE (type)
432 : &TYPE_RVALUE_REFERENCE_TYPE (type));
436 /* FIXME! Assume the machine has only one representation for
437 references, and that it matches the (only) representation for
440 TYPE_LENGTH (ntype) =
441 gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
442 TYPE_CODE (ntype) = refcode;
446 /* Update the length of all the other variants of this type. */
447 chain = TYPE_CHAIN (ntype);
448 while (chain != ntype)
450 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
451 chain = TYPE_CHAIN (chain);
457 /* Same as above, but caller doesn't care about memory allocation
461 lookup_reference_type (struct type *type, enum type_code refcode)
463 return make_reference_type (type, (struct type **) 0, refcode);
466 /* Lookup the lvalue reference type for the type TYPE. */
469 lookup_lvalue_reference_type (struct type *type)
471 return lookup_reference_type (type, TYPE_CODE_REF);
474 /* Lookup the rvalue reference type for the type TYPE. */
477 lookup_rvalue_reference_type (struct type *type)
479 return lookup_reference_type (type, TYPE_CODE_RVALUE_REF);
482 /* Lookup a function type that returns type TYPE. TYPEPTR, if
483 nonzero, points to a pointer to memory where the function type
484 should be stored. If *TYPEPTR is zero, update it to point to the
485 function type we return. We allocate new memory if needed. */
488 make_function_type (struct type *type, struct type **typeptr)
490 struct type *ntype; /* New type */
492 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
494 ntype = alloc_type_copy (type);
498 else /* We have storage, but need to reset it. */
504 TYPE_TARGET_TYPE (ntype) = type;
506 TYPE_LENGTH (ntype) = 1;
507 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
509 INIT_FUNC_SPECIFIC (ntype);
514 /* Given a type TYPE, return a type of functions that return that type.
515 May need to construct such a type if this is the first use. */
518 lookup_function_type (struct type *type)
520 return make_function_type (type, (struct type **) 0);
523 /* Given a type TYPE and argument types, return the appropriate
524 function type. If the final type in PARAM_TYPES is NULL, make a
528 lookup_function_type_with_arguments (struct type *type,
530 struct type **param_types)
532 struct type *fn = make_function_type (type, (struct type **) 0);
537 if (param_types[nparams - 1] == NULL)
540 TYPE_VARARGS (fn) = 1;
542 else if (TYPE_CODE (check_typedef (param_types[nparams - 1]))
546 /* Caller should have ensured this. */
547 gdb_assert (nparams == 0);
548 TYPE_PROTOTYPED (fn) = 1;
551 TYPE_PROTOTYPED (fn) = 1;
554 TYPE_NFIELDS (fn) = nparams;
556 = (struct field *) TYPE_ZALLOC (fn, nparams * sizeof (struct field));
557 for (i = 0; i < nparams; ++i)
558 TYPE_FIELD_TYPE (fn, i) = param_types[i];
563 /* Identify address space identifier by name --
564 return the integer flag defined in gdbtypes.h. */
567 address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
571 /* Check for known address space delimiters. */
572 if (!strcmp (space_identifier, "code"))
573 return TYPE_INSTANCE_FLAG_CODE_SPACE;
574 else if (!strcmp (space_identifier, "data"))
575 return TYPE_INSTANCE_FLAG_DATA_SPACE;
576 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
577 && gdbarch_address_class_name_to_type_flags (gdbarch,
582 error (_("Unknown address space specifier: \"%s\""), space_identifier);
585 /* Identify address space identifier by integer flag as defined in
586 gdbtypes.h -- return the string version of the adress space name. */
589 address_space_int_to_name (struct gdbarch *gdbarch, int space_flag)
591 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
593 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
595 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
596 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
597 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
602 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
604 If STORAGE is non-NULL, create the new type instance there.
605 STORAGE must be in the same obstack as TYPE. */
608 make_qualified_type (struct type *type, int new_flags,
609 struct type *storage)
616 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
618 ntype = TYPE_CHAIN (ntype);
620 while (ntype != type);
622 /* Create a new type instance. */
624 ntype = alloc_type_instance (type);
627 /* If STORAGE was provided, it had better be in the same objfile
628 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
629 if one objfile is freed and the other kept, we'd have
630 dangling pointers. */
631 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
634 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
635 TYPE_CHAIN (ntype) = ntype;
638 /* Pointers or references to the original type are not relevant to
640 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
641 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
643 /* Chain the new qualified type to the old type. */
644 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
645 TYPE_CHAIN (type) = ntype;
647 /* Now set the instance flags and return the new type. */
648 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
650 /* Set length of new type to that of the original type. */
651 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
656 /* Make an address-space-delimited variant of a type -- a type that
657 is identical to the one supplied except that it has an address
658 space attribute attached to it (such as "code" or "data").
660 The space attributes "code" and "data" are for Harvard
661 architectures. The address space attributes are for architectures
662 which have alternately sized pointers or pointers with alternate
666 make_type_with_address_space (struct type *type, int space_flag)
668 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
669 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
670 | TYPE_INSTANCE_FLAG_DATA_SPACE
671 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
674 return make_qualified_type (type, new_flags, NULL);
677 /* Make a "c-v" variant of a type -- a type that is identical to the
678 one supplied except that it may have const or volatile attributes
679 CNST is a flag for setting the const attribute
680 VOLTL is a flag for setting the volatile attribute
681 TYPE is the base type whose variant we are creating.
683 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
684 storage to hold the new qualified type; *TYPEPTR and TYPE must be
685 in the same objfile. Otherwise, allocate fresh memory for the new
686 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
687 new type we construct. */
690 make_cv_type (int cnst, int voltl,
692 struct type **typeptr)
694 struct type *ntype; /* New type */
696 int new_flags = (TYPE_INSTANCE_FLAGS (type)
697 & ~(TYPE_INSTANCE_FLAG_CONST
698 | TYPE_INSTANCE_FLAG_VOLATILE));
701 new_flags |= TYPE_INSTANCE_FLAG_CONST;
704 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
706 if (typeptr && *typeptr != NULL)
708 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
709 a C-V variant chain that threads across objfiles: if one
710 objfile gets freed, then the other has a broken C-V chain.
712 This code used to try to copy over the main type from TYPE to
713 *TYPEPTR if they were in different objfiles, but that's
714 wrong, too: TYPE may have a field list or member function
715 lists, which refer to types of their own, etc. etc. The
716 whole shebang would need to be copied over recursively; you
717 can't have inter-objfile pointers. The only thing to do is
718 to leave stub types as stub types, and look them up afresh by
719 name each time you encounter them. */
720 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
723 ntype = make_qualified_type (type, new_flags,
724 typeptr ? *typeptr : NULL);
732 /* Make a 'restrict'-qualified version of TYPE. */
735 make_restrict_type (struct type *type)
737 return make_qualified_type (type,
738 (TYPE_INSTANCE_FLAGS (type)
739 | TYPE_INSTANCE_FLAG_RESTRICT),
743 /* Make a type without const, volatile, or restrict. */
746 make_unqualified_type (struct type *type)
748 return make_qualified_type (type,
749 (TYPE_INSTANCE_FLAGS (type)
750 & ~(TYPE_INSTANCE_FLAG_CONST
751 | TYPE_INSTANCE_FLAG_VOLATILE
752 | TYPE_INSTANCE_FLAG_RESTRICT)),
756 /* Make a '_Atomic'-qualified version of TYPE. */
759 make_atomic_type (struct type *type)
761 return make_qualified_type (type,
762 (TYPE_INSTANCE_FLAGS (type)
763 | TYPE_INSTANCE_FLAG_ATOMIC),
767 /* Replace the contents of ntype with the type *type. This changes the
768 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
769 the changes are propogated to all types in the TYPE_CHAIN.
771 In order to build recursive types, it's inevitable that we'll need
772 to update types in place --- but this sort of indiscriminate
773 smashing is ugly, and needs to be replaced with something more
774 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
775 clear if more steps are needed. */
778 replace_type (struct type *ntype, struct type *type)
782 /* These two types had better be in the same objfile. Otherwise,
783 the assignment of one type's main type structure to the other
784 will produce a type with references to objects (names; field
785 lists; etc.) allocated on an objfile other than its own. */
786 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (type));
788 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
790 /* The type length is not a part of the main type. Update it for
791 each type on the variant chain. */
795 /* Assert that this element of the chain has no address-class bits
796 set in its flags. Such type variants might have type lengths
797 which are supposed to be different from the non-address-class
798 variants. This assertion shouldn't ever be triggered because
799 symbol readers which do construct address-class variants don't
800 call replace_type(). */
801 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
803 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
804 chain = TYPE_CHAIN (chain);
806 while (ntype != chain);
808 /* Assert that the two types have equivalent instance qualifiers.
809 This should be true for at least all of our debug readers. */
810 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
813 /* Implement direct support for MEMBER_TYPE in GNU C++.
814 May need to construct such a type if this is the first use.
815 The TYPE is the type of the member. The DOMAIN is the type
816 of the aggregate that the member belongs to. */
819 lookup_memberptr_type (struct type *type, struct type *domain)
823 mtype = alloc_type_copy (type);
824 smash_to_memberptr_type (mtype, domain, type);
828 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
831 lookup_methodptr_type (struct type *to_type)
835 mtype = alloc_type_copy (to_type);
836 smash_to_methodptr_type (mtype, to_type);
840 /* Allocate a stub method whose return type is TYPE. This apparently
841 happens for speed of symbol reading, since parsing out the
842 arguments to the method is cpu-intensive, the way we are doing it.
843 So, we will fill in arguments later. This always returns a fresh
847 allocate_stub_method (struct type *type)
851 mtype = alloc_type_copy (type);
852 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
853 TYPE_LENGTH (mtype) = 1;
854 TYPE_STUB (mtype) = 1;
855 TYPE_TARGET_TYPE (mtype) = type;
856 /* TYPE_SELF_TYPE (mtype) = unknown yet */
860 /* Create a range type with a dynamic range from LOW_BOUND to
861 HIGH_BOUND, inclusive. See create_range_type for further details. */
864 create_range_type (struct type *result_type, struct type *index_type,
865 const struct dynamic_prop *low_bound,
866 const struct dynamic_prop *high_bound)
868 if (result_type == NULL)
869 result_type = alloc_type_copy (index_type);
870 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
871 TYPE_TARGET_TYPE (result_type) = index_type;
872 if (TYPE_STUB (index_type))
873 TYPE_TARGET_STUB (result_type) = 1;
875 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
877 TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
878 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
879 TYPE_RANGE_DATA (result_type)->low = *low_bound;
880 TYPE_RANGE_DATA (result_type)->high = *high_bound;
882 if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
883 TYPE_UNSIGNED (result_type) = 1;
885 /* Ada allows the declaration of range types whose upper bound is
886 less than the lower bound, so checking the lower bound is not
887 enough. Make sure we do not mark a range type whose upper bound
888 is negative as unsigned. */
889 if (high_bound->kind == PROP_CONST && high_bound->data.const_val < 0)
890 TYPE_UNSIGNED (result_type) = 0;
895 /* Create a range type using either a blank type supplied in
896 RESULT_TYPE, or creating a new type, inheriting the objfile from
899 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
900 to HIGH_BOUND, inclusive.
902 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
903 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
906 create_static_range_type (struct type *result_type, struct type *index_type,
907 LONGEST low_bound, LONGEST high_bound)
909 struct dynamic_prop low, high;
911 low.kind = PROP_CONST;
912 low.data.const_val = low_bound;
914 high.kind = PROP_CONST;
915 high.data.const_val = high_bound;
917 result_type = create_range_type (result_type, index_type, &low, &high);
922 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
923 are static, otherwise returns 0. */
926 has_static_range (const struct range_bounds *bounds)
928 return (bounds->low.kind == PROP_CONST
929 && bounds->high.kind == PROP_CONST);
933 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
934 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
935 bounds will fit in LONGEST), or -1 otherwise. */
938 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
940 type = check_typedef (type);
941 switch (TYPE_CODE (type))
943 case TYPE_CODE_RANGE:
944 *lowp = TYPE_LOW_BOUND (type);
945 *highp = TYPE_HIGH_BOUND (type);
948 if (TYPE_NFIELDS (type) > 0)
950 /* The enums may not be sorted by value, so search all
954 *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
955 for (i = 0; i < TYPE_NFIELDS (type); i++)
957 if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
958 *lowp = TYPE_FIELD_ENUMVAL (type, i);
959 if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
960 *highp = TYPE_FIELD_ENUMVAL (type, i);
963 /* Set unsigned indicator if warranted. */
966 TYPE_UNSIGNED (type) = 1;
980 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
982 if (!TYPE_UNSIGNED (type))
984 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
988 /* ... fall through for unsigned ints ... */
991 /* This round-about calculation is to avoid shifting by
992 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
993 if TYPE_LENGTH (type) == sizeof (LONGEST). */
994 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
995 *highp = (*highp - 1) | *highp;
1002 /* Assuming TYPE is a simple, non-empty array type, compute its upper
1003 and lower bound. Save the low bound into LOW_BOUND if not NULL.
1004 Save the high bound into HIGH_BOUND if not NULL.
1006 Return 1 if the operation was successful. Return zero otherwise,
1007 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
1009 We now simply use get_discrete_bounds call to get the values
1010 of the low and high bounds.
1011 get_discrete_bounds can return three values:
1012 1, meaning that index is a range,
1013 0, meaning that index is a discrete type,
1014 or -1 for failure. */
1017 get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
1019 struct type *index = TYPE_INDEX_TYPE (type);
1027 res = get_discrete_bounds (index, &low, &high);
1031 /* Check if the array bounds are undefined. */
1033 && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
1034 || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
1046 /* Assuming that TYPE is a discrete type and VAL is a valid integer
1047 representation of a value of this type, save the corresponding
1048 position number in POS.
1050 Its differs from VAL only in the case of enumeration types. In
1051 this case, the position number of the value of the first listed
1052 enumeration literal is zero; the position number of the value of
1053 each subsequent enumeration literal is one more than that of its
1054 predecessor in the list.
1056 Return 1 if the operation was successful. Return zero otherwise,
1057 in which case the value of POS is unmodified.
1061 discrete_position (struct type *type, LONGEST val, LONGEST *pos)
1063 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
1067 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
1069 if (val == TYPE_FIELD_ENUMVAL (type, i))
1075 /* Invalid enumeration value. */
1085 /* Create an array type using either a blank type supplied in
1086 RESULT_TYPE, or creating a new type, inheriting the objfile from
1089 Elements will be of type ELEMENT_TYPE, the indices will be of type
1092 If BIT_STRIDE is not zero, build a packed array type whose element
1093 size is BIT_STRIDE. Otherwise, ignore this parameter.
1095 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1096 sure it is TYPE_CODE_UNDEF before we bash it into an array
1100 create_array_type_with_stride (struct type *result_type,
1101 struct type *element_type,
1102 struct type *range_type,
1103 unsigned int bit_stride)
1105 if (result_type == NULL)
1106 result_type = alloc_type_copy (range_type);
1108 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
1109 TYPE_TARGET_TYPE (result_type) = element_type;
1110 if (has_static_range (TYPE_RANGE_DATA (range_type))
1111 && (!type_not_associated (result_type)
1112 && !type_not_allocated (result_type)))
1114 LONGEST low_bound, high_bound;
1116 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
1117 low_bound = high_bound = 0;
1118 element_type = check_typedef (element_type);
1119 /* Be careful when setting the array length. Ada arrays can be
1120 empty arrays with the high_bound being smaller than the low_bound.
1121 In such cases, the array length should be zero. */
1122 if (high_bound < low_bound)
1123 TYPE_LENGTH (result_type) = 0;
1124 else if (bit_stride > 0)
1125 TYPE_LENGTH (result_type) =
1126 (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
1128 TYPE_LENGTH (result_type) =
1129 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
1133 /* This type is dynamic and its length needs to be computed
1134 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1135 undefined by setting it to zero. Although we are not expected
1136 to trust TYPE_LENGTH in this case, setting the size to zero
1137 allows us to avoid allocating objects of random sizes in case
1138 we accidently do. */
1139 TYPE_LENGTH (result_type) = 0;
1142 TYPE_NFIELDS (result_type) = 1;
1143 TYPE_FIELDS (result_type) =
1144 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
1145 TYPE_INDEX_TYPE (result_type) = range_type;
1147 TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride;
1149 /* TYPE_TARGET_STUB will take care of zero length arrays. */
1150 if (TYPE_LENGTH (result_type) == 0)
1151 TYPE_TARGET_STUB (result_type) = 1;
1156 /* Same as create_array_type_with_stride but with no bit_stride
1157 (BIT_STRIDE = 0), thus building an unpacked array. */
1160 create_array_type (struct type *result_type,
1161 struct type *element_type,
1162 struct type *range_type)
1164 return create_array_type_with_stride (result_type, element_type,
1169 lookup_array_range_type (struct type *element_type,
1170 LONGEST low_bound, LONGEST high_bound)
1172 struct gdbarch *gdbarch = get_type_arch (element_type);
1173 struct type *index_type = builtin_type (gdbarch)->builtin_int;
1174 struct type *range_type
1175 = create_static_range_type (NULL, index_type, low_bound, high_bound);
1177 return create_array_type (NULL, element_type, range_type);
1180 /* Create a string type using either a blank type supplied in
1181 RESULT_TYPE, or creating a new type. String types are similar
1182 enough to array of char types that we can use create_array_type to
1183 build the basic type and then bash it into a string type.
1185 For fixed length strings, the range type contains 0 as the lower
1186 bound and the length of the string minus one as the upper bound.
1188 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1189 sure it is TYPE_CODE_UNDEF before we bash it into a string
1193 create_string_type (struct type *result_type,
1194 struct type *string_char_type,
1195 struct type *range_type)
1197 result_type = create_array_type (result_type,
1200 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1205 lookup_string_range_type (struct type *string_char_type,
1206 LONGEST low_bound, LONGEST high_bound)
1208 struct type *result_type;
1210 result_type = lookup_array_range_type (string_char_type,
1211 low_bound, high_bound);
1212 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1217 create_set_type (struct type *result_type, struct type *domain_type)
1219 if (result_type == NULL)
1220 result_type = alloc_type_copy (domain_type);
1222 TYPE_CODE (result_type) = TYPE_CODE_SET;
1223 TYPE_NFIELDS (result_type) = 1;
1224 TYPE_FIELDS (result_type)
1225 = (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
1227 if (!TYPE_STUB (domain_type))
1229 LONGEST low_bound, high_bound, bit_length;
1231 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
1232 low_bound = high_bound = 0;
1233 bit_length = high_bound - low_bound + 1;
1234 TYPE_LENGTH (result_type)
1235 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1237 TYPE_UNSIGNED (result_type) = 1;
1239 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
1244 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1245 and any array types nested inside it. */
1248 make_vector_type (struct type *array_type)
1250 struct type *inner_array, *elt_type;
1253 /* Find the innermost array type, in case the array is
1254 multi-dimensional. */
1255 inner_array = array_type;
1256 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
1257 inner_array = TYPE_TARGET_TYPE (inner_array);
1259 elt_type = TYPE_TARGET_TYPE (inner_array);
1260 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
1262 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT;
1263 elt_type = make_qualified_type (elt_type, flags, NULL);
1264 TYPE_TARGET_TYPE (inner_array) = elt_type;
1267 TYPE_VECTOR (array_type) = 1;
1271 init_vector_type (struct type *elt_type, int n)
1273 struct type *array_type;
1275 array_type = lookup_array_range_type (elt_type, 0, n - 1);
1276 make_vector_type (array_type);
1280 /* Internal routine called by TYPE_SELF_TYPE to return the type that TYPE
1281 belongs to. In c++ this is the class of "this", but TYPE_THIS_TYPE is too
1282 confusing. "self" is a common enough replacement for "this".
1283 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1284 TYPE_CODE_METHOD. */
1287 internal_type_self_type (struct type *type)
1289 switch (TYPE_CODE (type))
1291 case TYPE_CODE_METHODPTR:
1292 case TYPE_CODE_MEMBERPTR:
1293 if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE)
1295 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_SELF_TYPE);
1296 return TYPE_MAIN_TYPE (type)->type_specific.self_type;
1297 case TYPE_CODE_METHOD:
1298 if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE)
1300 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC);
1301 return TYPE_MAIN_TYPE (type)->type_specific.func_stuff->self_type;
1303 gdb_assert_not_reached ("bad type");
1307 /* Set the type of the class that TYPE belongs to.
1308 In c++ this is the class of "this".
1309 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1310 TYPE_CODE_METHOD. */
1313 set_type_self_type (struct type *type, struct type *self_type)
1315 switch (TYPE_CODE (type))
1317 case TYPE_CODE_METHODPTR:
1318 case TYPE_CODE_MEMBERPTR:
1319 if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE)
1320 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_SELF_TYPE;
1321 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_SELF_TYPE);
1322 TYPE_MAIN_TYPE (type)->type_specific.self_type = self_type;
1324 case TYPE_CODE_METHOD:
1325 if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE)
1326 INIT_FUNC_SPECIFIC (type);
1327 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC);
1328 TYPE_MAIN_TYPE (type)->type_specific.func_stuff->self_type = self_type;
1331 gdb_assert_not_reached ("bad type");
1335 /* Smash TYPE to be a type of pointers to members of SELF_TYPE with type
1336 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1337 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1338 TYPE doesn't include the offset (that's the value of the MEMBER
1339 itself), but does include the structure type into which it points
1342 When "smashing" the type, we preserve the objfile that the old type
1343 pointed to, since we aren't changing where the type is actually
1347 smash_to_memberptr_type (struct type *type, struct type *self_type,
1348 struct type *to_type)
1351 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
1352 TYPE_TARGET_TYPE (type) = to_type;
1353 set_type_self_type (type, self_type);
1354 /* Assume that a data member pointer is the same size as a normal
1357 = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT;
1360 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1362 When "smashing" the type, we preserve the objfile that the old type
1363 pointed to, since we aren't changing where the type is actually
1367 smash_to_methodptr_type (struct type *type, struct type *to_type)
1370 TYPE_CODE (type) = TYPE_CODE_METHODPTR;
1371 TYPE_TARGET_TYPE (type) = to_type;
1372 set_type_self_type (type, TYPE_SELF_TYPE (to_type));
1373 TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
1376 /* Smash TYPE to be a type of method of SELF_TYPE with type TO_TYPE.
1377 METHOD just means `function that gets an extra "this" argument'.
1379 When "smashing" the type, we preserve the objfile that the old type
1380 pointed to, since we aren't changing where the type is actually
1384 smash_to_method_type (struct type *type, struct type *self_type,
1385 struct type *to_type, struct field *args,
1386 int nargs, int varargs)
1389 TYPE_CODE (type) = TYPE_CODE_METHOD;
1390 TYPE_TARGET_TYPE (type) = to_type;
1391 set_type_self_type (type, self_type);
1392 TYPE_FIELDS (type) = args;
1393 TYPE_NFIELDS (type) = nargs;
1395 TYPE_VARARGS (type) = 1;
1396 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1399 /* Return a typename for a struct/union/enum type without "struct ",
1400 "union ", or "enum ". If the type has a NULL name, return NULL. */
1403 type_name_no_tag (const struct type *type)
1405 if (TYPE_TAG_NAME (type) != NULL)
1406 return TYPE_TAG_NAME (type);
1408 /* Is there code which expects this to return the name if there is
1409 no tag name? My guess is that this is mainly used for C++ in
1410 cases where the two will always be the same. */
1411 return TYPE_NAME (type);
1414 /* A wrapper of type_name_no_tag which calls error if the type is anonymous.
1415 Since GCC PR debug/47510 DWARF provides associated information to detect the
1416 anonymous class linkage name from its typedef.
1418 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1422 type_name_no_tag_or_error (struct type *type)
1424 struct type *saved_type = type;
1426 struct objfile *objfile;
1428 type = check_typedef (type);
1430 name = type_name_no_tag (type);
1434 name = type_name_no_tag (saved_type);
1435 objfile = TYPE_OBJFILE (saved_type);
1436 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1437 name ? name : "<anonymous>",
1438 objfile ? objfile_name (objfile) : "<arch>");
1441 /* Lookup a typedef or primitive type named NAME, visible in lexical
1442 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1443 suitably defined. */
1446 lookup_typename (const struct language_defn *language,
1447 struct gdbarch *gdbarch, const char *name,
1448 const struct block *block, int noerr)
1452 sym = lookup_symbol_in_language (name, block, VAR_DOMAIN,
1453 language->la_language, NULL).symbol;
1454 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1455 return SYMBOL_TYPE (sym);
1459 error (_("No type named %s."), name);
1463 lookup_unsigned_typename (const struct language_defn *language,
1464 struct gdbarch *gdbarch, const char *name)
1466 char *uns = (char *) alloca (strlen (name) + 10);
1468 strcpy (uns, "unsigned ");
1469 strcpy (uns + 9, name);
1470 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0);
1474 lookup_signed_typename (const struct language_defn *language,
1475 struct gdbarch *gdbarch, const char *name)
1478 char *uns = (char *) alloca (strlen (name) + 8);
1480 strcpy (uns, "signed ");
1481 strcpy (uns + 7, name);
1482 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1);
1483 /* If we don't find "signed FOO" just try again with plain "FOO". */
1486 return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0);
1489 /* Lookup a structure type named "struct NAME",
1490 visible in lexical block BLOCK. */
1493 lookup_struct (const char *name, const struct block *block)
1497 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
1501 error (_("No struct type named %s."), name);
1503 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1505 error (_("This context has class, union or enum %s, not a struct."),
1508 return (SYMBOL_TYPE (sym));
1511 /* Lookup a union type named "union NAME",
1512 visible in lexical block BLOCK. */
1515 lookup_union (const char *name, const struct block *block)
1520 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
1523 error (_("No union type named %s."), name);
1525 t = SYMBOL_TYPE (sym);
1527 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1530 /* If we get here, it's not a union. */
1531 error (_("This context has class, struct or enum %s, not a union."),
1535 /* Lookup an enum type named "enum NAME",
1536 visible in lexical block BLOCK. */
1539 lookup_enum (const char *name, const struct block *block)
1543 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
1546 error (_("No enum type named %s."), name);
1548 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1550 error (_("This context has class, struct or union %s, not an enum."),
1553 return (SYMBOL_TYPE (sym));
1556 /* Lookup a template type named "template NAME<TYPE>",
1557 visible in lexical block BLOCK. */
1560 lookup_template_type (char *name, struct type *type,
1561 const struct block *block)
1564 char *nam = (char *)
1565 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1569 strcat (nam, TYPE_NAME (type));
1570 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1572 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0).symbol;
1576 error (_("No template type named %s."), name);
1578 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1580 error (_("This context has class, union or enum %s, not a struct."),
1583 return (SYMBOL_TYPE (sym));
1586 /* Given a type TYPE, lookup the type of the component of type named
1589 TYPE can be either a struct or union, or a pointer or reference to
1590 a struct or union. If it is a pointer or reference, its target
1591 type is automatically used. Thus '.' and '->' are interchangable,
1592 as specified for the definitions of the expression element types
1593 STRUCTOP_STRUCT and STRUCTOP_PTR.
1595 If NOERR is nonzero, return zero if NAME is not suitably defined.
1596 If NAME is the name of a baseclass type, return that type. */
1599 lookup_struct_elt_type (struct type *type, const char *name, int noerr)
1605 type = check_typedef (type);
1606 if (TYPE_CODE (type) != TYPE_CODE_PTR
1607 && TYPE_CODE (type) != TYPE_CODE_REF)
1609 type = TYPE_TARGET_TYPE (type);
1612 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1613 && TYPE_CODE (type) != TYPE_CODE_UNION)
1615 std::string type_name = type_to_string (type);
1616 error (_("Type %s is not a structure or union type."),
1617 type_name.c_str ());
1621 /* FIXME: This change put in by Michael seems incorrect for the case
1622 where the structure tag name is the same as the member name.
1623 I.e. when doing "ptype bell->bar" for "struct foo { int bar; int
1624 foo; } bell;" Disabled by fnf. */
1628 type_name = type_name_no_tag (type);
1629 if (type_name != NULL && strcmp (type_name, name) == 0)
1634 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1636 const char *t_field_name = TYPE_FIELD_NAME (type, i);
1638 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1640 return TYPE_FIELD_TYPE (type, i);
1642 else if (!t_field_name || *t_field_name == '\0')
1644 struct type *subtype
1645 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1);
1647 if (subtype != NULL)
1652 /* OK, it's not in this class. Recursively check the baseclasses. */
1653 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1657 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1669 std::string type_name = type_to_string (type);
1670 error (_("Type %s has no component named %s."), type_name.c_str (), name);
1673 /* Store in *MAX the largest number representable by unsigned integer type
1677 get_unsigned_type_max (struct type *type, ULONGEST *max)
1681 type = check_typedef (type);
1682 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_UNSIGNED (type));
1683 gdb_assert (TYPE_LENGTH (type) <= sizeof (ULONGEST));
1685 /* Written this way to avoid overflow. */
1686 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1687 *max = ((((ULONGEST) 1 << (n - 1)) - 1) << 1) | 1;
1690 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1691 signed integer type TYPE. */
1694 get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max)
1698 type = check_typedef (type);
1699 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && !TYPE_UNSIGNED (type));
1700 gdb_assert (TYPE_LENGTH (type) <= sizeof (LONGEST));
1702 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1703 *min = -((ULONGEST) 1 << (n - 1));
1704 *max = ((ULONGEST) 1 << (n - 1)) - 1;
1707 /* Internal routine called by TYPE_VPTR_FIELDNO to return the value of
1708 cplus_stuff.vptr_fieldno.
1710 cplus_stuff is initialized to cplus_struct_default which does not
1711 set vptr_fieldno to -1 for portability reasons (IWBN to use C99
1712 designated initializers). We cope with that here. */
1715 internal_type_vptr_fieldno (struct type *type)
1717 type = check_typedef (type);
1718 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1719 || TYPE_CODE (type) == TYPE_CODE_UNION);
1720 if (!HAVE_CPLUS_STRUCT (type))
1722 return TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno;
1725 /* Set the value of cplus_stuff.vptr_fieldno. */
1728 set_type_vptr_fieldno (struct type *type, int fieldno)
1730 type = check_typedef (type);
1731 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1732 || TYPE_CODE (type) == TYPE_CODE_UNION);
1733 if (!HAVE_CPLUS_STRUCT (type))
1734 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1735 TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno = fieldno;
1738 /* Internal routine called by TYPE_VPTR_BASETYPE to return the value of
1739 cplus_stuff.vptr_basetype. */
1742 internal_type_vptr_basetype (struct type *type)
1744 type = check_typedef (type);
1745 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1746 || TYPE_CODE (type) == TYPE_CODE_UNION);
1747 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_CPLUS_STUFF);
1748 return TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_basetype;
1751 /* Set the value of cplus_stuff.vptr_basetype. */
1754 set_type_vptr_basetype (struct type *type, struct type *basetype)
1756 type = check_typedef (type);
1757 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1758 || TYPE_CODE (type) == TYPE_CODE_UNION);
1759 if (!HAVE_CPLUS_STRUCT (type))
1760 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1761 TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_basetype = basetype;
1764 /* Lookup the vptr basetype/fieldno values for TYPE.
1765 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1766 vptr_fieldno. Also, if found and basetype is from the same objfile,
1768 If not found, return -1 and ignore BASETYPEP.
1769 Callers should be aware that in some cases (for example,
1770 the type or one of its baseclasses is a stub type and we are
1771 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1772 this function will not be able to find the
1773 virtual function table pointer, and vptr_fieldno will remain -1 and
1774 vptr_basetype will remain NULL or incomplete. */
1777 get_vptr_fieldno (struct type *type, struct type **basetypep)
1779 type = check_typedef (type);
1781 if (TYPE_VPTR_FIELDNO (type) < 0)
1785 /* We must start at zero in case the first (and only) baseclass
1786 is virtual (and hence we cannot share the table pointer). */
1787 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1789 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1791 struct type *basetype;
1793 fieldno = get_vptr_fieldno (baseclass, &basetype);
1796 /* If the type comes from a different objfile we can't cache
1797 it, it may have a different lifetime. PR 2384 */
1798 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
1800 set_type_vptr_fieldno (type, fieldno);
1801 set_type_vptr_basetype (type, basetype);
1804 *basetypep = basetype;
1815 *basetypep = TYPE_VPTR_BASETYPE (type);
1816 return TYPE_VPTR_FIELDNO (type);
1821 stub_noname_complaint (void)
1823 complaint (&symfile_complaints, _("stub type has NULL name"));
1826 /* Worker for is_dynamic_type. */
1829 is_dynamic_type_internal (struct type *type, int top_level)
1831 type = check_typedef (type);
1833 /* We only want to recognize references at the outermost level. */
1834 if (top_level && TYPE_CODE (type) == TYPE_CODE_REF)
1835 type = check_typedef (TYPE_TARGET_TYPE (type));
1837 /* Types that have a dynamic TYPE_DATA_LOCATION are considered
1838 dynamic, even if the type itself is statically defined.
1839 From a user's point of view, this may appear counter-intuitive;
1840 but it makes sense in this context, because the point is to determine
1841 whether any part of the type needs to be resolved before it can
1843 if (TYPE_DATA_LOCATION (type) != NULL
1844 && (TYPE_DATA_LOCATION_KIND (type) == PROP_LOCEXPR
1845 || TYPE_DATA_LOCATION_KIND (type) == PROP_LOCLIST))
1848 if (TYPE_ASSOCIATED_PROP (type))
1851 if (TYPE_ALLOCATED_PROP (type))
1854 switch (TYPE_CODE (type))
1856 case TYPE_CODE_RANGE:
1858 /* A range type is obviously dynamic if it has at least one
1859 dynamic bound. But also consider the range type to be
1860 dynamic when its subtype is dynamic, even if the bounds
1861 of the range type are static. It allows us to assume that
1862 the subtype of a static range type is also static. */
1863 return (!has_static_range (TYPE_RANGE_DATA (type))
1864 || is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0));
1867 case TYPE_CODE_ARRAY:
1869 gdb_assert (TYPE_NFIELDS (type) == 1);
1871 /* The array is dynamic if either the bounds are dynamic,
1872 or the elements it contains have a dynamic contents. */
1873 if (is_dynamic_type_internal (TYPE_INDEX_TYPE (type), 0))
1875 return is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0);
1878 case TYPE_CODE_STRUCT:
1879 case TYPE_CODE_UNION:
1883 for (i = 0; i < TYPE_NFIELDS (type); ++i)
1884 if (!field_is_static (&TYPE_FIELD (type, i))
1885 && is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i), 0))
1894 /* See gdbtypes.h. */
1897 is_dynamic_type (struct type *type)
1899 return is_dynamic_type_internal (type, 1);
1902 static struct type *resolve_dynamic_type_internal
1903 (struct type *type, struct property_addr_info *addr_stack, int top_level);
1905 /* Given a dynamic range type (dyn_range_type) and a stack of
1906 struct property_addr_info elements, return a static version
1909 static struct type *
1910 resolve_dynamic_range (struct type *dyn_range_type,
1911 struct property_addr_info *addr_stack)
1914 struct type *static_range_type, *static_target_type;
1915 const struct dynamic_prop *prop;
1916 struct dynamic_prop low_bound, high_bound;
1918 gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
1920 prop = &TYPE_RANGE_DATA (dyn_range_type)->low;
1921 if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
1923 low_bound.kind = PROP_CONST;
1924 low_bound.data.const_val = value;
1928 low_bound.kind = PROP_UNDEFINED;
1929 low_bound.data.const_val = 0;
1932 prop = &TYPE_RANGE_DATA (dyn_range_type)->high;
1933 if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
1935 high_bound.kind = PROP_CONST;
1936 high_bound.data.const_val = value;
1938 if (TYPE_RANGE_DATA (dyn_range_type)->flag_upper_bound_is_count)
1939 high_bound.data.const_val
1940 = low_bound.data.const_val + high_bound.data.const_val - 1;
1944 high_bound.kind = PROP_UNDEFINED;
1945 high_bound.data.const_val = 0;
1949 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type),
1951 static_range_type = create_range_type (copy_type (dyn_range_type),
1953 &low_bound, &high_bound);
1954 TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
1955 return static_range_type;
1958 /* Resolves dynamic bound values of an array type TYPE to static ones.
1959 ADDR_STACK is a stack of struct property_addr_info to be used
1960 if needed during the dynamic resolution. */
1962 static struct type *
1963 resolve_dynamic_array (struct type *type,
1964 struct property_addr_info *addr_stack)
1967 struct type *elt_type;
1968 struct type *range_type;
1969 struct type *ary_dim;
1970 struct dynamic_prop *prop;
1972 gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY);
1974 type = copy_type (type);
1977 range_type = check_typedef (TYPE_INDEX_TYPE (elt_type));
1978 range_type = resolve_dynamic_range (range_type, addr_stack);
1980 /* Resolve allocated/associated here before creating a new array type, which
1981 will update the length of the array accordingly. */
1982 prop = TYPE_ALLOCATED_PROP (type);
1983 if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
1985 TYPE_DYN_PROP_ADDR (prop) = value;
1986 TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
1988 prop = TYPE_ASSOCIATED_PROP (type);
1989 if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
1991 TYPE_DYN_PROP_ADDR (prop) = value;
1992 TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
1995 ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
1997 if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY)
1998 elt_type = resolve_dynamic_array (ary_dim, addr_stack);
2000 elt_type = TYPE_TARGET_TYPE (type);
2002 return create_array_type_with_stride (type, elt_type, range_type,
2003 TYPE_FIELD_BITSIZE (type, 0));
2006 /* Resolve dynamic bounds of members of the union TYPE to static
2007 bounds. ADDR_STACK is a stack of struct property_addr_info
2008 to be used if needed during the dynamic resolution. */
2010 static struct type *
2011 resolve_dynamic_union (struct type *type,
2012 struct property_addr_info *addr_stack)
2014 struct type *resolved_type;
2016 unsigned int max_len = 0;
2018 gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
2020 resolved_type = copy_type (type);
2021 TYPE_FIELDS (resolved_type)
2022 = (struct field *) TYPE_ALLOC (resolved_type,
2023 TYPE_NFIELDS (resolved_type)
2024 * sizeof (struct field));
2025 memcpy (TYPE_FIELDS (resolved_type),
2027 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
2028 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
2032 if (field_is_static (&TYPE_FIELD (type, i)))
2035 t = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
2037 TYPE_FIELD_TYPE (resolved_type, i) = t;
2038 if (TYPE_LENGTH (t) > max_len)
2039 max_len = TYPE_LENGTH (t);
2042 TYPE_LENGTH (resolved_type) = max_len;
2043 return resolved_type;
2046 /* Resolve dynamic bounds of members of the struct TYPE to static
2047 bounds. ADDR_STACK is a stack of struct property_addr_info to
2048 be used if needed during the dynamic resolution. */
2050 static struct type *
2051 resolve_dynamic_struct (struct type *type,
2052 struct property_addr_info *addr_stack)
2054 struct type *resolved_type;
2056 unsigned resolved_type_bit_length = 0;
2058 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
2059 gdb_assert (TYPE_NFIELDS (type) > 0);
2061 resolved_type = copy_type (type);
2062 TYPE_FIELDS (resolved_type)
2063 = (struct field *) TYPE_ALLOC (resolved_type,
2064 TYPE_NFIELDS (resolved_type)
2065 * sizeof (struct field));
2066 memcpy (TYPE_FIELDS (resolved_type),
2068 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
2069 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
2071 unsigned new_bit_length;
2072 struct property_addr_info pinfo;
2074 if (field_is_static (&TYPE_FIELD (type, i)))
2077 /* As we know this field is not a static field, the field's
2078 field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
2079 this is the case, but only trigger a simple error rather
2080 than an internal error if that fails. While failing
2081 that verification indicates a bug in our code, the error
2082 is not severe enough to suggest to the user he stops
2083 his debugging session because of it. */
2084 if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_BITPOS)
2085 error (_("Cannot determine struct field location"
2086 " (invalid location kind)"));
2088 pinfo.type = check_typedef (TYPE_FIELD_TYPE (type, i));
2089 pinfo.valaddr = addr_stack->valaddr;
2092 + (TYPE_FIELD_BITPOS (resolved_type, i) / TARGET_CHAR_BIT));
2093 pinfo.next = addr_stack;
2095 TYPE_FIELD_TYPE (resolved_type, i)
2096 = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
2098 gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type, i)
2099 == FIELD_LOC_KIND_BITPOS);
2101 new_bit_length = TYPE_FIELD_BITPOS (resolved_type, i);
2102 if (TYPE_FIELD_BITSIZE (resolved_type, i) != 0)
2103 new_bit_length += TYPE_FIELD_BITSIZE (resolved_type, i);
2105 new_bit_length += (TYPE_LENGTH (TYPE_FIELD_TYPE (resolved_type, i))
2108 /* Normally, we would use the position and size of the last field
2109 to determine the size of the enclosing structure. But GCC seems
2110 to be encoding the position of some fields incorrectly when
2111 the struct contains a dynamic field that is not placed last.
2112 So we compute the struct size based on the field that has
2113 the highest position + size - probably the best we can do. */
2114 if (new_bit_length > resolved_type_bit_length)
2115 resolved_type_bit_length = new_bit_length;
2118 /* The length of a type won't change for fortran, but it does for C and Ada.
2119 For fortran the size of dynamic fields might change over time but not the
2120 type length of the structure. If we adapt it, we run into problems
2121 when calculating the element offset for arrays of structs. */
2122 if (current_language->la_language != language_fortran)
2123 TYPE_LENGTH (resolved_type)
2124 = (resolved_type_bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2126 /* The Ada language uses this field as a cache for static fixed types: reset
2127 it as RESOLVED_TYPE must have its own static fixed type. */
2128 TYPE_TARGET_TYPE (resolved_type) = NULL;
2130 return resolved_type;
2133 /* Worker for resolved_dynamic_type. */
2135 static struct type *
2136 resolve_dynamic_type_internal (struct type *type,
2137 struct property_addr_info *addr_stack,
2140 struct type *real_type = check_typedef (type);
2141 struct type *resolved_type = type;
2142 struct dynamic_prop *prop;
2145 if (!is_dynamic_type_internal (real_type, top_level))
2148 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
2150 resolved_type = copy_type (type);
2151 TYPE_TARGET_TYPE (resolved_type)
2152 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack,
2157 /* Before trying to resolve TYPE, make sure it is not a stub. */
2160 switch (TYPE_CODE (type))
2164 struct property_addr_info pinfo;
2166 pinfo.type = check_typedef (TYPE_TARGET_TYPE (type));
2167 pinfo.valaddr = NULL;
2168 if (addr_stack->valaddr != NULL)
2169 pinfo.addr = extract_typed_address (addr_stack->valaddr, type);
2171 pinfo.addr = read_memory_typed_address (addr_stack->addr, type);
2172 pinfo.next = addr_stack;
2174 resolved_type = copy_type (type);
2175 TYPE_TARGET_TYPE (resolved_type)
2176 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
2181 case TYPE_CODE_ARRAY:
2182 resolved_type = resolve_dynamic_array (type, addr_stack);
2185 case TYPE_CODE_RANGE:
2186 resolved_type = resolve_dynamic_range (type, addr_stack);
2189 case TYPE_CODE_UNION:
2190 resolved_type = resolve_dynamic_union (type, addr_stack);
2193 case TYPE_CODE_STRUCT:
2194 resolved_type = resolve_dynamic_struct (type, addr_stack);
2199 /* Resolve data_location attribute. */
2200 prop = TYPE_DATA_LOCATION (resolved_type);
2202 && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
2204 TYPE_DYN_PROP_ADDR (prop) = value;
2205 TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
2208 return resolved_type;
2211 /* See gdbtypes.h */
2214 resolve_dynamic_type (struct type *type, const gdb_byte *valaddr,
2217 struct property_addr_info pinfo
2218 = {check_typedef (type), valaddr, addr, NULL};
2220 return resolve_dynamic_type_internal (type, &pinfo, 1);
2223 /* See gdbtypes.h */
2225 struct dynamic_prop *
2226 get_dyn_prop (enum dynamic_prop_node_kind prop_kind, const struct type *type)
2228 struct dynamic_prop_list *node = TYPE_DYN_PROP_LIST (type);
2230 while (node != NULL)
2232 if (node->prop_kind == prop_kind)
2239 /* See gdbtypes.h */
2242 add_dyn_prop (enum dynamic_prop_node_kind prop_kind, struct dynamic_prop prop,
2243 struct type *type, struct objfile *objfile)
2245 struct dynamic_prop_list *temp;
2247 gdb_assert (TYPE_OBJFILE_OWNED (type));
2249 temp = XOBNEW (&objfile->objfile_obstack, struct dynamic_prop_list);
2250 temp->prop_kind = prop_kind;
2252 temp->next = TYPE_DYN_PROP_LIST (type);
2254 TYPE_DYN_PROP_LIST (type) = temp;
2257 /* Remove dynamic property from TYPE in case it exists. */
2260 remove_dyn_prop (enum dynamic_prop_node_kind prop_kind,
2263 struct dynamic_prop_list *prev_node, *curr_node;
2265 curr_node = TYPE_DYN_PROP_LIST (type);
2268 while (NULL != curr_node)
2270 if (curr_node->prop_kind == prop_kind)
2272 /* Update the linked list but don't free anything.
2273 The property was allocated on objstack and it is not known
2274 if we are on top of it. Nevertheless, everything is released
2275 when the complete objstack is freed. */
2276 if (NULL == prev_node)
2277 TYPE_DYN_PROP_LIST (type) = curr_node->next;
2279 prev_node->next = curr_node->next;
2284 prev_node = curr_node;
2285 curr_node = curr_node->next;
2289 /* Find the real type of TYPE. This function returns the real type,
2290 after removing all layers of typedefs, and completing opaque or stub
2291 types. Completion changes the TYPE argument, but stripping of
2294 Instance flags (e.g. const/volatile) are preserved as typedefs are
2295 stripped. If necessary a new qualified form of the underlying type
2298 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
2299 not been computed and we're either in the middle of reading symbols, or
2300 there was no name for the typedef in the debug info.
2302 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
2303 QUITs in the symbol reading code can also throw.
2304 Thus this function can throw an exception.
2306 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
2309 If this is a stubbed struct (i.e. declared as struct foo *), see if
2310 we can find a full definition in some other file. If so, copy this
2311 definition, so we can use it in future. There used to be a comment
2312 (but not any code) that if we don't find a full definition, we'd
2313 set a flag so we don't spend time in the future checking the same
2314 type. That would be a mistake, though--we might load in more
2315 symbols which contain a full definition for the type. */
2318 check_typedef (struct type *type)
2320 struct type *orig_type = type;
2321 /* While we're removing typedefs, we don't want to lose qualifiers.
2322 E.g., const/volatile. */
2323 int instance_flags = TYPE_INSTANCE_FLAGS (type);
2327 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
2329 if (!TYPE_TARGET_TYPE (type))
2334 /* It is dangerous to call lookup_symbol if we are currently
2335 reading a symtab. Infinite recursion is one danger. */
2336 if (currently_reading_symtab)
2337 return make_qualified_type (type, instance_flags, NULL);
2339 name = type_name_no_tag (type);
2340 /* FIXME: shouldn't we separately check the TYPE_NAME and
2341 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
2342 VAR_DOMAIN as appropriate? (this code was written before
2343 TYPE_NAME and TYPE_TAG_NAME were separate). */
2346 stub_noname_complaint ();
2347 return make_qualified_type (type, instance_flags, NULL);
2349 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
2351 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
2352 else /* TYPE_CODE_UNDEF */
2353 TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type));
2355 type = TYPE_TARGET_TYPE (type);
2357 /* Preserve the instance flags as we traverse down the typedef chain.
2359 Handling address spaces/classes is nasty, what do we do if there's a
2361 E.g., what if an outer typedef marks the type as class_1 and an inner
2362 typedef marks the type as class_2?
2363 This is the wrong place to do such error checking. We leave it to
2364 the code that created the typedef in the first place to flag the
2365 error. We just pick the outer address space (akin to letting the
2366 outer cast in a chain of casting win), instead of assuming
2367 "it can't happen". */
2369 const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE
2370 | TYPE_INSTANCE_FLAG_DATA_SPACE);
2371 const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
2372 int new_instance_flags = TYPE_INSTANCE_FLAGS (type);
2374 /* Treat code vs data spaces and address classes separately. */
2375 if ((instance_flags & ALL_SPACES) != 0)
2376 new_instance_flags &= ~ALL_SPACES;
2377 if ((instance_flags & ALL_CLASSES) != 0)
2378 new_instance_flags &= ~ALL_CLASSES;
2380 instance_flags |= new_instance_flags;
2384 /* If this is a struct/class/union with no fields, then check
2385 whether a full definition exists somewhere else. This is for
2386 systems where a type definition with no fields is issued for such
2387 types, instead of identifying them as stub types in the first
2390 if (TYPE_IS_OPAQUE (type)
2391 && opaque_type_resolution
2392 && !currently_reading_symtab)
2394 const char *name = type_name_no_tag (type);
2395 struct type *newtype;
2399 stub_noname_complaint ();
2400 return make_qualified_type (type, instance_flags, NULL);
2402 newtype = lookup_transparent_type (name);
2406 /* If the resolved type and the stub are in the same
2407 objfile, then replace the stub type with the real deal.
2408 But if they're in separate objfiles, leave the stub
2409 alone; we'll just look up the transparent type every time
2410 we call check_typedef. We can't create pointers between
2411 types allocated to different objfiles, since they may
2412 have different lifetimes. Trying to copy NEWTYPE over to
2413 TYPE's objfile is pointless, too, since you'll have to
2414 move over any other types NEWTYPE refers to, which could
2415 be an unbounded amount of stuff. */
2416 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
2417 type = make_qualified_type (newtype,
2418 TYPE_INSTANCE_FLAGS (type),
2424 /* Otherwise, rely on the stub flag being set for opaque/stubbed
2426 else if (TYPE_STUB (type) && !currently_reading_symtab)
2428 const char *name = type_name_no_tag (type);
2429 /* FIXME: shouldn't we separately check the TYPE_NAME and the
2430 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
2431 as appropriate? (this code was written before TYPE_NAME and
2432 TYPE_TAG_NAME were separate). */
2437 stub_noname_complaint ();
2438 return make_qualified_type (type, instance_flags, NULL);
2440 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
2443 /* Same as above for opaque types, we can replace the stub
2444 with the complete type only if they are in the same
2446 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
2447 type = make_qualified_type (SYMBOL_TYPE (sym),
2448 TYPE_INSTANCE_FLAGS (type),
2451 type = SYMBOL_TYPE (sym);
2455 if (TYPE_TARGET_STUB (type))
2457 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
2459 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
2461 /* Nothing we can do. */
2463 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
2465 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
2466 TYPE_TARGET_STUB (type) = 0;
2470 type = make_qualified_type (type, instance_flags, NULL);
2472 /* Cache TYPE_LENGTH for future use. */
2473 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
2478 /* Parse a type expression in the string [P..P+LENGTH). If an error
2479 occurs, silently return a void type. */
2481 static struct type *
2482 safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
2484 struct ui_file *saved_gdb_stderr;
2485 struct type *type = NULL; /* Initialize to keep gcc happy. */
2487 /* Suppress error messages. */
2488 saved_gdb_stderr = gdb_stderr;
2489 gdb_stderr = &null_stream;
2491 /* Call parse_and_eval_type() without fear of longjmp()s. */
2494 type = parse_and_eval_type (p, length);
2496 CATCH (except, RETURN_MASK_ERROR)
2498 type = builtin_type (gdbarch)->builtin_void;
2502 /* Stop suppressing error messages. */
2503 gdb_stderr = saved_gdb_stderr;
2508 /* Ugly hack to convert method stubs into method types.
2510 He ain't kiddin'. This demangles the name of the method into a
2511 string including argument types, parses out each argument type,
2512 generates a string casting a zero to that type, evaluates the
2513 string, and stuffs the resulting type into an argtype vector!!!
2514 Then it knows the type of the whole function (including argument
2515 types for overloading), which info used to be in the stab's but was
2516 removed to hack back the space required for them. */
2519 check_stub_method (struct type *type, int method_id, int signature_id)
2521 struct gdbarch *gdbarch = get_type_arch (type);
2523 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
2524 char *demangled_name = gdb_demangle (mangled_name,
2525 DMGL_PARAMS | DMGL_ANSI);
2526 char *argtypetext, *p;
2527 int depth = 0, argcount = 1;
2528 struct field *argtypes;
2531 /* Make sure we got back a function string that we can use. */
2533 p = strchr (demangled_name, '(');
2537 if (demangled_name == NULL || p == NULL)
2538 error (_("Internal: Cannot demangle mangled name `%s'."),
2541 /* Now, read in the parameters that define this type. */
2546 if (*p == '(' || *p == '<')
2550 else if (*p == ')' || *p == '>')
2554 else if (*p == ',' && depth == 0)
2562 /* If we read one argument and it was ``void'', don't count it. */
2563 if (startswith (argtypetext, "(void)"))
2566 /* We need one extra slot, for the THIS pointer. */
2568 argtypes = (struct field *)
2569 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
2572 /* Add THIS pointer for non-static methods. */
2573 f = TYPE_FN_FIELDLIST1 (type, method_id);
2574 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
2578 argtypes[0].type = lookup_pointer_type (type);
2582 if (*p != ')') /* () means no args, skip while. */
2587 if (depth <= 0 && (*p == ',' || *p == ')'))
2589 /* Avoid parsing of ellipsis, they will be handled below.
2590 Also avoid ``void'' as above. */
2591 if (strncmp (argtypetext, "...", p - argtypetext) != 0
2592 && strncmp (argtypetext, "void", p - argtypetext) != 0)
2594 argtypes[argcount].type =
2595 safe_parse_type (gdbarch, argtypetext, p - argtypetext);
2598 argtypetext = p + 1;
2601 if (*p == '(' || *p == '<')
2605 else if (*p == ')' || *p == '>')
2614 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
2616 /* Now update the old "stub" type into a real type. */
2617 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
2618 /* MTYPE may currently be a function (TYPE_CODE_FUNC).
2619 We want a method (TYPE_CODE_METHOD). */
2620 smash_to_method_type (mtype, type, TYPE_TARGET_TYPE (mtype),
2621 argtypes, argcount, p[-2] == '.');
2622 TYPE_STUB (mtype) = 0;
2623 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
2625 xfree (demangled_name);
2628 /* This is the external interface to check_stub_method, above. This
2629 function unstubs all of the signatures for TYPE's METHOD_ID method
2630 name. After calling this function TYPE_FN_FIELD_STUB will be
2631 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
2634 This function unfortunately can not die until stabs do. */
2637 check_stub_method_group (struct type *type, int method_id)
2639 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
2640 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
2641 int j, found_stub = 0;
2643 for (j = 0; j < len; j++)
2644 if (TYPE_FN_FIELD_STUB (f, j))
2647 check_stub_method (type, method_id, j);
2650 /* GNU v3 methods with incorrect names were corrected when we read
2651 in type information, because it was cheaper to do it then. The
2652 only GNU v2 methods with incorrect method names are operators and
2653 destructors; destructors were also corrected when we read in type
2656 Therefore the only thing we need to handle here are v2 operator
2658 if (found_stub && !startswith (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z"))
2661 char dem_opname[256];
2663 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2665 dem_opname, DMGL_ANSI);
2667 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2671 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
2675 /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
2676 const struct cplus_struct_type cplus_struct_default = { };
2679 allocate_cplus_struct_type (struct type *type)
2681 if (HAVE_CPLUS_STRUCT (type))
2682 /* Structure was already allocated. Nothing more to do. */
2685 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF;
2686 TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
2687 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
2688 *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default;
2689 set_type_vptr_fieldno (type, -1);
2692 const struct gnat_aux_type gnat_aux_default =
2695 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
2696 and allocate the associated gnat-specific data. The gnat-specific
2697 data is also initialized to gnat_aux_default. */
2700 allocate_gnat_aux_type (struct type *type)
2702 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF;
2703 TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *)
2704 TYPE_ALLOC (type, sizeof (struct gnat_aux_type));
2705 *(TYPE_GNAT_SPECIFIC (type)) = gnat_aux_default;
2708 /* Helper function to initialize a newly allocated type. Set type code
2709 to CODE and initialize the type-specific fields accordingly. */
2712 set_type_code (struct type *type, enum type_code code)
2714 TYPE_CODE (type) = code;
2718 case TYPE_CODE_STRUCT:
2719 case TYPE_CODE_UNION:
2720 case TYPE_CODE_NAMESPACE:
2721 INIT_CPLUS_SPECIFIC (type);
2724 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT;
2726 case TYPE_CODE_FUNC:
2727 INIT_FUNC_SPECIFIC (type);
2732 /* Helper function to verify floating-point format and size.
2733 BIT is the type size in bits; if BIT equals -1, the size is
2734 determined by the floatformat. Returns size to be used. */
2737 verify_floatformat (int bit, const struct floatformat *floatformat)
2739 gdb_assert (floatformat != NULL);
2742 bit = floatformat->totalsize;
2744 gdb_assert (bit >= 0);
2745 gdb_assert (bit >= floatformat->totalsize);
2750 /* Return the floating-point format for a floating-point variable of
2753 const struct floatformat *
2754 floatformat_from_type (const struct type *type)
2756 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
2757 gdb_assert (TYPE_FLOATFORMAT (type));
2758 return TYPE_FLOATFORMAT (type);
2761 /* Helper function to initialize the standard scalar types.
2763 If NAME is non-NULL, then it is used to initialize the type name.
2764 Note that NAME is not copied; it is required to have a lifetime at
2765 least as long as OBJFILE. */
2768 init_type (struct objfile *objfile, enum type_code code, int bit,
2773 type = alloc_type (objfile);
2774 set_type_code (type, code);
2775 gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
2776 TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
2777 TYPE_NAME (type) = name;
2782 /* Allocate a TYPE_CODE_ERROR type structure associated with OBJFILE,
2783 to use with variables that have no debug info. NAME is the type
2786 static struct type *
2787 init_nodebug_var_type (struct objfile *objfile, const char *name)
2789 return init_type (objfile, TYPE_CODE_ERROR, 0, name);
2792 /* Allocate a TYPE_CODE_INT type structure associated with OBJFILE.
2793 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
2794 the type's TYPE_UNSIGNED flag. NAME is the type name. */
2797 init_integer_type (struct objfile *objfile,
2798 int bit, int unsigned_p, const char *name)
2802 t = init_type (objfile, TYPE_CODE_INT, bit, name);
2804 TYPE_UNSIGNED (t) = 1;
2809 /* Allocate a TYPE_CODE_CHAR type structure associated with OBJFILE.
2810 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
2811 the type's TYPE_UNSIGNED flag. NAME is the type name. */
2814 init_character_type (struct objfile *objfile,
2815 int bit, int unsigned_p, const char *name)
2819 t = init_type (objfile, TYPE_CODE_CHAR, bit, name);
2821 TYPE_UNSIGNED (t) = 1;
2826 /* Allocate a TYPE_CODE_BOOL type structure associated with OBJFILE.
2827 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
2828 the type's TYPE_UNSIGNED flag. NAME is the type name. */
2831 init_boolean_type (struct objfile *objfile,
2832 int bit, int unsigned_p, const char *name)
2836 t = init_type (objfile, TYPE_CODE_BOOL, bit, name);
2838 TYPE_UNSIGNED (t) = 1;
2843 /* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
2844 BIT is the type size in bits; if BIT equals -1, the size is
2845 determined by the floatformat. NAME is the type name. Set the
2846 TYPE_FLOATFORMAT from FLOATFORMATS. */
2849 init_float_type (struct objfile *objfile,
2850 int bit, const char *name,
2851 const struct floatformat **floatformats)
2853 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2854 const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
2857 bit = verify_floatformat (bit, fmt);
2858 t = init_type (objfile, TYPE_CODE_FLT, bit, name);
2859 TYPE_FLOATFORMAT (t) = fmt;
2864 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with OBJFILE.
2865 BIT is the type size in bits. NAME is the type name. */
2868 init_decfloat_type (struct objfile *objfile, int bit, const char *name)
2872 t = init_type (objfile, TYPE_CODE_DECFLOAT, bit, name);
2876 /* Allocate a TYPE_CODE_COMPLEX type structure associated with OBJFILE.
2877 NAME is the type name. TARGET_TYPE is the component float type. */
2880 init_complex_type (struct objfile *objfile,
2881 const char *name, struct type *target_type)
2885 t = init_type (objfile, TYPE_CODE_COMPLEX,
2886 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
2887 TYPE_TARGET_TYPE (t) = target_type;
2891 /* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE.
2892 BIT is the pointer type size in bits. NAME is the type name.
2893 TARGET_TYPE is the pointer target type. Always sets the pointer type's
2894 TYPE_UNSIGNED flag. */
2897 init_pointer_type (struct objfile *objfile,
2898 int bit, const char *name, struct type *target_type)
2902 t = init_type (objfile, TYPE_CODE_PTR, bit, name);
2903 TYPE_TARGET_TYPE (t) = target_type;
2904 TYPE_UNSIGNED (t) = 1;
2909 /* Queries on types. */
2912 can_dereference (struct type *t)
2914 /* FIXME: Should we return true for references as well as
2916 t = check_typedef (t);
2919 && TYPE_CODE (t) == TYPE_CODE_PTR
2920 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
2924 is_integral_type (struct type *t)
2926 t = check_typedef (t);
2929 && ((TYPE_CODE (t) == TYPE_CODE_INT)
2930 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
2931 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
2932 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
2933 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
2934 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
2937 /* Return true if TYPE is scalar. */
2940 is_scalar_type (struct type *type)
2942 type = check_typedef (type);
2944 switch (TYPE_CODE (type))
2946 case TYPE_CODE_ARRAY:
2947 case TYPE_CODE_STRUCT:
2948 case TYPE_CODE_UNION:
2950 case TYPE_CODE_STRING:
2957 /* Return true if T is scalar, or a composite type which in practice has
2958 the memory layout of a scalar type. E.g., an array or struct with only
2959 one scalar element inside it, or a union with only scalar elements. */
2962 is_scalar_type_recursive (struct type *t)
2964 t = check_typedef (t);
2966 if (is_scalar_type (t))
2968 /* Are we dealing with an array or string of known dimensions? */
2969 else if ((TYPE_CODE (t) == TYPE_CODE_ARRAY
2970 || TYPE_CODE (t) == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1
2971 && TYPE_CODE (TYPE_INDEX_TYPE (t)) == TYPE_CODE_RANGE)
2973 LONGEST low_bound, high_bound;
2974 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (t));
2976 get_discrete_bounds (TYPE_INDEX_TYPE (t), &low_bound, &high_bound);
2978 return high_bound == low_bound && is_scalar_type_recursive (elt_type);
2980 /* Are we dealing with a struct with one element? */
2981 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1)
2982 return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0));
2983 else if (TYPE_CODE (t) == TYPE_CODE_UNION)
2985 int i, n = TYPE_NFIELDS (t);
2987 /* If all elements of the union are scalar, then the union is scalar. */
2988 for (i = 0; i < n; i++)
2989 if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t, i)))
2998 /* Return true is T is a class or a union. False otherwise. */
3001 class_or_union_p (const struct type *t)
3003 return (TYPE_CODE (t) == TYPE_CODE_STRUCT
3004 || TYPE_CODE (t) == TYPE_CODE_UNION);
3007 /* A helper function which returns true if types A and B represent the
3008 "same" class type. This is true if the types have the same main
3009 type, or the same name. */
3012 class_types_same_p (const struct type *a, const struct type *b)
3014 return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b)
3015 || (TYPE_NAME (a) && TYPE_NAME (b)
3016 && !strcmp (TYPE_NAME (a), TYPE_NAME (b))));
3019 /* If BASE is an ancestor of DCLASS return the distance between them.
3020 otherwise return -1;
3024 class B: public A {};
3025 class C: public B {};
3028 distance_to_ancestor (A, A, 0) = 0
3029 distance_to_ancestor (A, B, 0) = 1
3030 distance_to_ancestor (A, C, 0) = 2
3031 distance_to_ancestor (A, D, 0) = 3
3033 If PUBLIC is 1 then only public ancestors are considered,
3034 and the function returns the distance only if BASE is a public ancestor
3038 distance_to_ancestor (A, D, 1) = -1. */
3041 distance_to_ancestor (struct type *base, struct type *dclass, int is_public)
3046 base = check_typedef (base);
3047 dclass = check_typedef (dclass);
3049 if (class_types_same_p (base, dclass))
3052 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
3054 if (is_public && ! BASETYPE_VIA_PUBLIC (dclass, i))
3057 d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), is_public);
3065 /* Check whether BASE is an ancestor or base class or DCLASS
3066 Return 1 if so, and 0 if not.
3067 Note: If BASE and DCLASS are of the same type, this function
3068 will return 1. So for some class A, is_ancestor (A, A) will
3072 is_ancestor (struct type *base, struct type *dclass)
3074 return distance_to_ancestor (base, dclass, 0) >= 0;
3077 /* Like is_ancestor, but only returns true when BASE is a public
3078 ancestor of DCLASS. */
3081 is_public_ancestor (struct type *base, struct type *dclass)
3083 return distance_to_ancestor (base, dclass, 1) >= 0;
3086 /* A helper function for is_unique_ancestor. */
3089 is_unique_ancestor_worker (struct type *base, struct type *dclass,
3091 const gdb_byte *valaddr, int embedded_offset,
3092 CORE_ADDR address, struct value *val)
3096 base = check_typedef (base);
3097 dclass = check_typedef (dclass);
3099 for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
3104 iter = check_typedef (TYPE_BASECLASS (dclass, i));
3106 this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset,
3109 if (class_types_same_p (base, iter))
3111 /* If this is the first subclass, set *OFFSET and set count
3112 to 1. Otherwise, if this is at the same offset as
3113 previous instances, do nothing. Otherwise, increment
3117 *offset = this_offset;
3120 else if (this_offset == *offset)
3128 count += is_unique_ancestor_worker (base, iter, offset,
3130 embedded_offset + this_offset,
3137 /* Like is_ancestor, but only returns true if BASE is a unique base
3138 class of the type of VAL. */
3141 is_unique_ancestor (struct type *base, struct value *val)
3145 return is_unique_ancestor_worker (base, value_type (val), &offset,
3146 value_contents_for_printing (val),
3147 value_embedded_offset (val),
3148 value_address (val), val) == 1;
3152 /* Overload resolution. */
3154 /* Return the sum of the rank of A with the rank of B. */
3157 sum_ranks (struct rank a, struct rank b)
3160 c.rank = a.rank + b.rank;
3161 c.subrank = a.subrank + b.subrank;
3165 /* Compare rank A and B and return:
3167 1 if a is better than b
3168 -1 if b is better than a. */
3171 compare_ranks (struct rank a, struct rank b)
3173 if (a.rank == b.rank)
3175 if (a.subrank == b.subrank)
3177 if (a.subrank < b.subrank)
3179 if (a.subrank > b.subrank)
3183 if (a.rank < b.rank)
3186 /* a.rank > b.rank */
3190 /* Functions for overload resolution begin here. */
3192 /* Compare two badness vectors A and B and return the result.
3193 0 => A and B are identical
3194 1 => A and B are incomparable
3195 2 => A is better than B
3196 3 => A is worse than B */
3199 compare_badness (struct badness_vector *a, struct badness_vector *b)
3203 short found_pos = 0; /* any positives in c? */
3204 short found_neg = 0; /* any negatives in c? */
3206 /* differing lengths => incomparable */
3207 if (a->length != b->length)
3210 /* Subtract b from a */
3211 for (i = 0; i < a->length; i++)
3213 tmp = compare_ranks (b->rank[i], a->rank[i]);
3223 return 1; /* incomparable */
3225 return 3; /* A > B */
3231 return 2; /* A < B */
3233 return 0; /* A == B */
3237 /* Rank a function by comparing its parameter types (PARMS, length
3238 NPARMS), to the types of an argument list (ARGS, length NARGS).
3239 Return a pointer to a badness vector. This has NARGS + 1
3242 struct badness_vector *
3243 rank_function (struct type **parms, int nparms,
3244 struct value **args, int nargs)
3247 struct badness_vector *bv = XNEW (struct badness_vector);
3248 int min_len = nparms < nargs ? nparms : nargs;
3250 bv->length = nargs + 1; /* add 1 for the length-match rank. */
3251 bv->rank = XNEWVEC (struct rank, nargs + 1);
3253 /* First compare the lengths of the supplied lists.
3254 If there is a mismatch, set it to a high value. */
3256 /* pai/1997-06-03 FIXME: when we have debug info about default
3257 arguments and ellipsis parameter lists, we should consider those
3258 and rank the length-match more finely. */
3260 LENGTH_MATCH (bv) = (nargs != nparms)
3261 ? LENGTH_MISMATCH_BADNESS
3262 : EXACT_MATCH_BADNESS;
3264 /* Now rank all the parameters of the candidate function. */
3265 for (i = 1; i <= min_len; i++)
3266 bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]),
3269 /* If more arguments than parameters, add dummy entries. */
3270 for (i = min_len + 1; i <= nargs; i++)
3271 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
3276 /* Compare the names of two integer types, assuming that any sign
3277 qualifiers have been checked already. We do it this way because
3278 there may be an "int" in the name of one of the types. */
3281 integer_types_same_name_p (const char *first, const char *second)
3283 int first_p, second_p;
3285 /* If both are shorts, return 1; if neither is a short, keep
3287 first_p = (strstr (first, "short") != NULL);
3288 second_p = (strstr (second, "short") != NULL);
3289 if (first_p && second_p)
3291 if (first_p || second_p)
3294 /* Likewise for long. */
3295 first_p = (strstr (first, "long") != NULL);
3296 second_p = (strstr (second, "long") != NULL);
3297 if (first_p && second_p)
3299 if (first_p || second_p)
3302 /* Likewise for char. */
3303 first_p = (strstr (first, "char") != NULL);
3304 second_p = (strstr (second, "char") != NULL);
3305 if (first_p && second_p)
3307 if (first_p || second_p)
3310 /* They must both be ints. */
3314 /* Compares type A to type B returns 1 if the represent the same type
3318 types_equal (struct type *a, struct type *b)
3320 /* Identical type pointers. */
3321 /* However, this still doesn't catch all cases of same type for b
3322 and a. The reason is that builtin types are different from
3323 the same ones constructed from the object. */
3327 /* Resolve typedefs */
3328 if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF)
3329 a = check_typedef (a);
3330 if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF)
3331 b = check_typedef (b);
3333 /* If after resolving typedefs a and b are not of the same type
3334 code then they are not equal. */
3335 if (TYPE_CODE (a) != TYPE_CODE (b))
3338 /* If a and b are both pointers types or both reference types then
3339 they are equal of the same type iff the objects they refer to are
3340 of the same type. */
3341 if (TYPE_CODE (a) == TYPE_CODE_PTR
3342 || TYPE_CODE (a) == TYPE_CODE_REF)
3343 return types_equal (TYPE_TARGET_TYPE (a),
3344 TYPE_TARGET_TYPE (b));
3346 /* Well, damnit, if the names are exactly the same, I'll say they
3347 are exactly the same. This happens when we generate method
3348 stubs. The types won't point to the same address, but they
3349 really are the same. */
3351 if (TYPE_NAME (a) && TYPE_NAME (b)
3352 && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0)
3355 /* Check if identical after resolving typedefs. */
3359 /* Two function types are equal if their argument and return types
3361 if (TYPE_CODE (a) == TYPE_CODE_FUNC)
3365 if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
3368 if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
3371 for (i = 0; i < TYPE_NFIELDS (a); ++i)
3372 if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
3381 /* Deep comparison of types. */
3383 /* An entry in the type-equality bcache. */
3385 typedef struct type_equality_entry
3387 struct type *type1, *type2;
3388 } type_equality_entry_d;
3390 DEF_VEC_O (type_equality_entry_d);
3392 /* A helper function to compare two strings. Returns 1 if they are
3393 the same, 0 otherwise. Handles NULLs properly. */
3396 compare_maybe_null_strings (const char *s, const char *t)
3398 if (s == NULL && t != NULL)
3400 else if (s != NULL && t == NULL)
3402 else if (s == NULL && t== NULL)
3404 return strcmp (s, t) == 0;
3407 /* A helper function for check_types_worklist that checks two types for
3408 "deep" equality. Returns non-zero if the types are considered the
3409 same, zero otherwise. */
3412 check_types_equal (struct type *type1, struct type *type2,
3413 VEC (type_equality_entry_d) **worklist)
3415 type1 = check_typedef (type1);
3416 type2 = check_typedef (type2);
3421 if (TYPE_CODE (type1) != TYPE_CODE (type2)
3422 || TYPE_LENGTH (type1) != TYPE_LENGTH (type2)
3423 || TYPE_UNSIGNED (type1) != TYPE_UNSIGNED (type2)
3424 || TYPE_NOSIGN (type1) != TYPE_NOSIGN (type2)
3425 || TYPE_VARARGS (type1) != TYPE_VARARGS (type2)
3426 || TYPE_VECTOR (type1) != TYPE_VECTOR (type2)
3427 || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2)
3428 || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2)
3429 || TYPE_NFIELDS (type1) != TYPE_NFIELDS (type2))
3432 if (!compare_maybe_null_strings (TYPE_TAG_NAME (type1),
3433 TYPE_TAG_NAME (type2)))
3435 if (!compare_maybe_null_strings (TYPE_NAME (type1), TYPE_NAME (type2)))
3438 if (TYPE_CODE (type1) == TYPE_CODE_RANGE)
3440 if (memcmp (TYPE_RANGE_DATA (type1), TYPE_RANGE_DATA (type2),
3441 sizeof (*TYPE_RANGE_DATA (type1))) != 0)
3448 for (i = 0; i < TYPE_NFIELDS (type1); ++i)
3450 const struct field *field1 = &TYPE_FIELD (type1, i);
3451 const struct field *field2 = &TYPE_FIELD (type2, i);
3452 struct type_equality_entry entry;
3454 if (FIELD_ARTIFICIAL (*field1) != FIELD_ARTIFICIAL (*field2)
3455 || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2)
3456 || FIELD_LOC_KIND (*field1) != FIELD_LOC_KIND (*field2))
3458 if (!compare_maybe_null_strings (FIELD_NAME (*field1),
3459 FIELD_NAME (*field2)))
3461 switch (FIELD_LOC_KIND (*field1))
3463 case FIELD_LOC_KIND_BITPOS:
3464 if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2))
3467 case FIELD_LOC_KIND_ENUMVAL:
3468 if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2))
3471 case FIELD_LOC_KIND_PHYSADDR:
3472 if (FIELD_STATIC_PHYSADDR (*field1)
3473 != FIELD_STATIC_PHYSADDR (*field2))
3476 case FIELD_LOC_KIND_PHYSNAME:
3477 if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1),
3478 FIELD_STATIC_PHYSNAME (*field2)))
3481 case FIELD_LOC_KIND_DWARF_BLOCK:
3483 struct dwarf2_locexpr_baton *block1, *block2;
3485 block1 = FIELD_DWARF_BLOCK (*field1);
3486 block2 = FIELD_DWARF_BLOCK (*field2);
3487 if (block1->per_cu != block2->per_cu
3488 || block1->size != block2->size
3489 || memcmp (block1->data, block2->data, block1->size) != 0)
3494 internal_error (__FILE__, __LINE__, _("Unsupported field kind "
3495 "%d by check_types_equal"),
3496 FIELD_LOC_KIND (*field1));
3499 entry.type1 = FIELD_TYPE (*field1);
3500 entry.type2 = FIELD_TYPE (*field2);
3501 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
3505 if (TYPE_TARGET_TYPE (type1) != NULL)
3507 struct type_equality_entry entry;
3509 if (TYPE_TARGET_TYPE (type2) == NULL)
3512 entry.type1 = TYPE_TARGET_TYPE (type1);
3513 entry.type2 = TYPE_TARGET_TYPE (type2);
3514 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
3516 else if (TYPE_TARGET_TYPE (type2) != NULL)
3522 /* Check types on a worklist for equality. Returns zero if any pair
3523 is not equal, non-zero if they are all considered equal. */
3526 check_types_worklist (VEC (type_equality_entry_d) **worklist,
3527 struct bcache *cache)
3529 while (!VEC_empty (type_equality_entry_d, *worklist))
3531 struct type_equality_entry entry;
3534 entry = *VEC_last (type_equality_entry_d, *worklist);
3535 VEC_pop (type_equality_entry_d, *worklist);
3537 /* If the type pair has already been visited, we know it is
3539 bcache_full (&entry, sizeof (entry), cache, &added);
3543 if (check_types_equal (entry.type1, entry.type2, worklist) == 0)
3550 /* Return non-zero if types TYPE1 and TYPE2 are equal, as determined by a
3551 "deep comparison". Otherwise return zero. */
3554 types_deeply_equal (struct type *type1, struct type *type2)
3556 struct gdb_exception except = exception_none;
3558 struct bcache *cache;
3559 VEC (type_equality_entry_d) *worklist = NULL;
3560 struct type_equality_entry entry;
3562 gdb_assert (type1 != NULL && type2 != NULL);
3564 /* Early exit for the simple case. */
3568 cache = bcache_xmalloc (NULL, NULL);
3570 entry.type1 = type1;
3571 entry.type2 = type2;
3572 VEC_safe_push (type_equality_entry_d, worklist, &entry);
3574 /* check_types_worklist calls several nested helper functions, some
3575 of which can raise a GDB exception, so we just check and rethrow
3576 here. If there is a GDB exception, a comparison is not capable
3577 (or trusted), so exit. */
3580 result = check_types_worklist (&worklist, cache);
3582 CATCH (ex, RETURN_MASK_ALL)
3588 bcache_xfree (cache);
3589 VEC_free (type_equality_entry_d, worklist);
3591 /* Rethrow if there was a problem. */
3592 if (except.reason < 0)
3593 throw_exception (except);
3598 /* Allocated status of type TYPE. Return zero if type TYPE is allocated.
3599 Otherwise return one. */
3602 type_not_allocated (const struct type *type)
3604 struct dynamic_prop *prop = TYPE_ALLOCATED_PROP (type);
3606 return (prop && TYPE_DYN_PROP_KIND (prop) == PROP_CONST
3607 && !TYPE_DYN_PROP_ADDR (prop));
3610 /* Associated status of type TYPE. Return zero if type TYPE is associated.
3611 Otherwise return one. */
3614 type_not_associated (const struct type *type)
3616 struct dynamic_prop *prop = TYPE_ASSOCIATED_PROP (type);
3618 return (prop && TYPE_DYN_PROP_KIND (prop) == PROP_CONST
3619 && !TYPE_DYN_PROP_ADDR (prop));
3622 /* Compare one type (PARM) for compatibility with another (ARG).
3623 * PARM is intended to be the parameter type of a function; and
3624 * ARG is the supplied argument's type. This function tests if
3625 * the latter can be converted to the former.
3626 * VALUE is the argument's value or NULL if none (or called recursively)
3628 * Return 0 if they are identical types;
3629 * Otherwise, return an integer which corresponds to how compatible
3630 * PARM is to ARG. The higher the return value, the worse the match.
3631 * Generally the "bad" conversions are all uniformly assigned a 100. */
3634 rank_one_type (struct type *parm, struct type *arg, struct value *value)
3636 struct rank rank = {0,0};
3638 /* Resolve typedefs */
3639 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
3640 parm = check_typedef (parm);
3641 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
3642 arg = check_typedef (arg);
3644 if (TYPE_IS_REFERENCE (parm) && value != NULL)
3646 if (VALUE_LVAL (value) == not_lval)
3648 /* Rvalues should preferably bind to rvalue references or const
3649 lvalue references. */
3650 if (TYPE_CODE (parm) == TYPE_CODE_RVALUE_REF)
3651 rank.subrank = REFERENCE_CONVERSION_RVALUE;
3652 else if (TYPE_CONST (TYPE_TARGET_TYPE (parm)))
3653 rank.subrank = REFERENCE_CONVERSION_CONST_LVALUE;
3655 return INCOMPATIBLE_TYPE_BADNESS;
3656 return sum_ranks (rank, REFERENCE_CONVERSION_BADNESS);
3660 /* Lvalues should prefer lvalue overloads. */
3661 if (TYPE_CODE (parm) == TYPE_CODE_RVALUE_REF)
3663 rank.subrank = REFERENCE_CONVERSION_RVALUE;
3664 return sum_ranks (rank, REFERENCE_CONVERSION_BADNESS);
3669 if (types_equal (parm, arg))
3671 struct type *t1 = parm;
3672 struct type *t2 = arg;
3674 /* For pointers and references, compare target type. */
3675 if (TYPE_CODE (parm) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (parm))
3677 t1 = TYPE_TARGET_TYPE (parm);
3678 t2 = TYPE_TARGET_TYPE (arg);
3681 /* Make sure they are CV equal, too. */
3682 if (TYPE_CONST (t1) != TYPE_CONST (t2))
3683 rank.subrank |= CV_CONVERSION_CONST;
3684 if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
3685 rank.subrank |= CV_CONVERSION_VOLATILE;
3686 if (rank.subrank != 0)
3687 return sum_ranks (CV_CONVERSION_BADNESS, rank);
3688 return EXACT_MATCH_BADNESS;
3691 /* See through references, since we can almost make non-references
3694 if (TYPE_IS_REFERENCE (arg))
3695 return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
3696 REFERENCE_CONVERSION_BADNESS));
3697 if (TYPE_IS_REFERENCE (parm))
3698 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
3699 REFERENCE_CONVERSION_BADNESS));
3701 /* Debugging only. */
3702 fprintf_filtered (gdb_stderr,
3703 "------ Arg is %s [%d], parm is %s [%d]\n",
3704 TYPE_NAME (arg), TYPE_CODE (arg),
3705 TYPE_NAME (parm), TYPE_CODE (parm));
3707 /* x -> y means arg of type x being supplied for parameter of type y. */
3709 switch (TYPE_CODE (parm))
3712 switch (TYPE_CODE (arg))
3716 /* Allowed pointer conversions are:
3717 (a) pointer to void-pointer conversion. */
3718 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
3719 return VOID_PTR_CONVERSION_BADNESS;
3721 /* (b) pointer to ancestor-pointer conversion. */
3722 rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
3723 TYPE_TARGET_TYPE (arg),
3725 if (rank.subrank >= 0)
3726 return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
3728 return INCOMPATIBLE_TYPE_BADNESS;
3729 case TYPE_CODE_ARRAY:
3731 struct type *t1 = TYPE_TARGET_TYPE (parm);
3732 struct type *t2 = TYPE_TARGET_TYPE (arg);
3734 if (types_equal (t1, t2))
3736 /* Make sure they are CV equal. */
3737 if (TYPE_CONST (t1) != TYPE_CONST (t2))
3738 rank.subrank |= CV_CONVERSION_CONST;
3739 if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
3740 rank.subrank |= CV_CONVERSION_VOLATILE;
3741 if (rank.subrank != 0)
3742 return sum_ranks (CV_CONVERSION_BADNESS, rank);
3743 return EXACT_MATCH_BADNESS;
3745 return INCOMPATIBLE_TYPE_BADNESS;
3747 case TYPE_CODE_FUNC:
3748 return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
3750 if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
3752 if (value_as_long (value) == 0)
3754 /* Null pointer conversion: allow it to be cast to a pointer.
3755 [4.10.1 of C++ standard draft n3290] */
3756 return NULL_POINTER_CONVERSION_BADNESS;
3760 /* If type checking is disabled, allow the conversion. */
3761 if (!strict_type_checking)
3762 return NS_INTEGER_POINTER_CONVERSION_BADNESS;
3766 case TYPE_CODE_ENUM:
3767 case TYPE_CODE_FLAGS:
3768 case TYPE_CODE_CHAR:
3769 case TYPE_CODE_RANGE:
3770 case TYPE_CODE_BOOL:
3772 return INCOMPATIBLE_TYPE_BADNESS;
3774 case TYPE_CODE_ARRAY:
3775 switch (TYPE_CODE (arg))
3778 case TYPE_CODE_ARRAY:
3779 return rank_one_type (TYPE_TARGET_TYPE (parm),
3780 TYPE_TARGET_TYPE (arg), NULL);
3782 return INCOMPATIBLE_TYPE_BADNESS;
3784 case TYPE_CODE_FUNC:
3785 switch (TYPE_CODE (arg))
3787 case TYPE_CODE_PTR: /* funcptr -> func */
3788 return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
3790 return INCOMPATIBLE_TYPE_BADNESS;
3793 switch (TYPE_CODE (arg))
3796 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3798 /* Deal with signed, unsigned, and plain chars and
3799 signed and unsigned ints. */
3800 if (TYPE_NOSIGN (parm))
3802 /* This case only for character types. */
3803 if (TYPE_NOSIGN (arg))
3804 return EXACT_MATCH_BADNESS; /* plain char -> plain char */
3805 else /* signed/unsigned char -> plain char */
3806 return INTEGER_CONVERSION_BADNESS;
3808 else if (TYPE_UNSIGNED (parm))
3810 if (TYPE_UNSIGNED (arg))
3812 /* unsigned int -> unsigned int, or
3813 unsigned long -> unsigned long */
3814 if (integer_types_same_name_p (TYPE_NAME (parm),
3816 return EXACT_MATCH_BADNESS;
3817 else if (integer_types_same_name_p (TYPE_NAME (arg),
3819 && integer_types_same_name_p (TYPE_NAME (parm),
3821 /* unsigned int -> unsigned long */
3822 return INTEGER_PROMOTION_BADNESS;
3824 /* unsigned long -> unsigned int */
3825 return INTEGER_CONVERSION_BADNESS;
3829 if (integer_types_same_name_p (TYPE_NAME (arg),
3831 && integer_types_same_name_p (TYPE_NAME (parm),
3833 /* signed long -> unsigned int */
3834 return INTEGER_CONVERSION_BADNESS;
3836 /* signed int/long -> unsigned int/long */
3837 return INTEGER_CONVERSION_BADNESS;
3840 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3842 if (integer_types_same_name_p (TYPE_NAME (parm),
3844 return EXACT_MATCH_BADNESS;
3845 else if (integer_types_same_name_p (TYPE_NAME (arg),
3847 && integer_types_same_name_p (TYPE_NAME (parm),
3849 return INTEGER_PROMOTION_BADNESS;
3851 return INTEGER_CONVERSION_BADNESS;
3854 return INTEGER_CONVERSION_BADNESS;
3856 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3857 return INTEGER_PROMOTION_BADNESS;
3859 return INTEGER_CONVERSION_BADNESS;
3860 case TYPE_CODE_ENUM:
3861 case TYPE_CODE_FLAGS:
3862 case TYPE_CODE_CHAR:
3863 case TYPE_CODE_RANGE:
3864 case TYPE_CODE_BOOL:
3865 if (TYPE_DECLARED_CLASS (arg))
3866 return INCOMPATIBLE_TYPE_BADNESS;
3867 return INTEGER_PROMOTION_BADNESS;
3869 return INT_FLOAT_CONVERSION_BADNESS;
3871 return NS_POINTER_CONVERSION_BADNESS;
3873 return INCOMPATIBLE_TYPE_BADNESS;
3876 case TYPE_CODE_ENUM:
3877 switch (TYPE_CODE (arg))
3880 case TYPE_CODE_CHAR:
3881 case TYPE_CODE_RANGE:
3882 case TYPE_CODE_BOOL:
3883 case TYPE_CODE_ENUM:
3884 if (TYPE_DECLARED_CLASS (parm) || TYPE_DECLARED_CLASS (arg))
3885 return INCOMPATIBLE_TYPE_BADNESS;
3886 return INTEGER_CONVERSION_BADNESS;
3888 return INT_FLOAT_CONVERSION_BADNESS;
3890 return INCOMPATIBLE_TYPE_BADNESS;
3893 case TYPE_CODE_CHAR:
3894 switch (TYPE_CODE (arg))
3896 case TYPE_CODE_RANGE:
3897 case TYPE_CODE_BOOL:
3898 case TYPE_CODE_ENUM:
3899 if (TYPE_DECLARED_CLASS (arg))
3900 return INCOMPATIBLE_TYPE_BADNESS;
3901 return INTEGER_CONVERSION_BADNESS;
3903 return INT_FLOAT_CONVERSION_BADNESS;
3905 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
3906 return INTEGER_CONVERSION_BADNESS;
3907 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3908 return INTEGER_PROMOTION_BADNESS;
3909 /* >>> !! else fall through !! <<< */
3910 case TYPE_CODE_CHAR:
3911 /* Deal with signed, unsigned, and plain chars for C++ and
3912 with int cases falling through from previous case. */
3913 if (TYPE_NOSIGN (parm))
3915 if (TYPE_NOSIGN (arg))
3916 return EXACT_MATCH_BADNESS;
3918 return INTEGER_CONVERSION_BADNESS;
3920 else if (TYPE_UNSIGNED (parm))
3922 if (TYPE_UNSIGNED (arg))
3923 return EXACT_MATCH_BADNESS;
3925 return INTEGER_PROMOTION_BADNESS;
3927 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3928 return EXACT_MATCH_BADNESS;
3930 return INTEGER_CONVERSION_BADNESS;
3932 return INCOMPATIBLE_TYPE_BADNESS;
3935 case TYPE_CODE_RANGE:
3936 switch (TYPE_CODE (arg))
3939 case TYPE_CODE_CHAR:
3940 case TYPE_CODE_RANGE:
3941 case TYPE_CODE_BOOL:
3942 case TYPE_CODE_ENUM:
3943 return INTEGER_CONVERSION_BADNESS;
3945 return INT_FLOAT_CONVERSION_BADNESS;
3947 return INCOMPATIBLE_TYPE_BADNESS;
3950 case TYPE_CODE_BOOL:
3951 switch (TYPE_CODE (arg))
3953 /* n3290 draft, section 4.12.1 (conv.bool):
3955 "A prvalue of arithmetic, unscoped enumeration, pointer, or
3956 pointer to member type can be converted to a prvalue of type
3957 bool. A zero value, null pointer value, or null member pointer
3958 value is converted to false; any other value is converted to
3959 true. A prvalue of type std::nullptr_t can be converted to a
3960 prvalue of type bool; the resulting value is false." */
3962 case TYPE_CODE_CHAR:
3963 case TYPE_CODE_ENUM:
3965 case TYPE_CODE_MEMBERPTR:
3967 return BOOL_CONVERSION_BADNESS;
3968 case TYPE_CODE_RANGE:
3969 return INCOMPATIBLE_TYPE_BADNESS;
3970 case TYPE_CODE_BOOL:
3971 return EXACT_MATCH_BADNESS;
3973 return INCOMPATIBLE_TYPE_BADNESS;
3977 switch (TYPE_CODE (arg))
3980 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3981 return FLOAT_PROMOTION_BADNESS;
3982 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3983 return EXACT_MATCH_BADNESS;
3985 return FLOAT_CONVERSION_BADNESS;
3987 case TYPE_CODE_BOOL:
3988 case TYPE_CODE_ENUM:
3989 case TYPE_CODE_RANGE:
3990 case TYPE_CODE_CHAR:
3991 return INT_FLOAT_CONVERSION_BADNESS;
3993 return INCOMPATIBLE_TYPE_BADNESS;
3996 case TYPE_CODE_COMPLEX:
3997 switch (TYPE_CODE (arg))
3998 { /* Strictly not needed for C++, but... */
4000 return FLOAT_PROMOTION_BADNESS;
4001 case TYPE_CODE_COMPLEX:
4002 return EXACT_MATCH_BADNESS;
4004 return INCOMPATIBLE_TYPE_BADNESS;
4007 case TYPE_CODE_STRUCT:
4008 switch (TYPE_CODE (arg))
4010 case TYPE_CODE_STRUCT:
4011 /* Check for derivation */
4012 rank.subrank = distance_to_ancestor (parm, arg, 0);
4013 if (rank.subrank >= 0)
4014 return sum_ranks (BASE_CONVERSION_BADNESS, rank);
4015 /* else fall through */
4017 return INCOMPATIBLE_TYPE_BADNESS;
4020 case TYPE_CODE_UNION:
4021 switch (TYPE_CODE (arg))
4023 case TYPE_CODE_UNION:
4025 return INCOMPATIBLE_TYPE_BADNESS;
4028 case TYPE_CODE_MEMBERPTR:
4029 switch (TYPE_CODE (arg))
4032 return INCOMPATIBLE_TYPE_BADNESS;
4035 case TYPE_CODE_METHOD:
4036 switch (TYPE_CODE (arg))
4040 return INCOMPATIBLE_TYPE_BADNESS;
4044 switch (TYPE_CODE (arg))
4048 return INCOMPATIBLE_TYPE_BADNESS;
4053 switch (TYPE_CODE (arg))
4057 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
4058 TYPE_FIELD_TYPE (arg, 0), NULL);
4060 return INCOMPATIBLE_TYPE_BADNESS;
4063 case TYPE_CODE_VOID:
4065 return INCOMPATIBLE_TYPE_BADNESS;
4066 } /* switch (TYPE_CODE (arg)) */
4069 /* End of functions for overload resolution. */
4071 /* Routines to pretty-print types. */
4074 print_bit_vector (B_TYPE *bits, int nbits)
4078 for (bitno = 0; bitno < nbits; bitno++)
4080 if ((bitno % 8) == 0)
4082 puts_filtered (" ");
4084 if (B_TST (bits, bitno))
4085 printf_filtered (("1"));
4087 printf_filtered (("0"));
4091 /* Note the first arg should be the "this" pointer, we may not want to
4092 include it since we may get into a infinitely recursive
4096 print_args (struct field *args, int nargs, int spaces)
4102 for (i = 0; i < nargs; i++)
4104 printfi_filtered (spaces, "[%d] name '%s'\n", i,
4105 args[i].name != NULL ? args[i].name : "<NULL>");
4106 recursive_dump_type (args[i].type, spaces + 2);
4112 field_is_static (struct field *f)
4114 /* "static" fields are the fields whose location is not relative
4115 to the address of the enclosing struct. It would be nice to
4116 have a dedicated flag that would be set for static fields when
4117 the type is being created. But in practice, checking the field
4118 loc_kind should give us an accurate answer. */
4119 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
4120 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
4124 dump_fn_fieldlists (struct type *type, int spaces)
4130 printfi_filtered (spaces, "fn_fieldlists ");
4131 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
4132 printf_filtered ("\n");
4133 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
4135 f = TYPE_FN_FIELDLIST1 (type, method_idx);
4136 printfi_filtered (spaces + 2, "[%d] name '%s' (",
4138 TYPE_FN_FIELDLIST_NAME (type, method_idx));
4139 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
4141 printf_filtered (_(") length %d\n"),
4142 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
4143 for (overload_idx = 0;
4144 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
4147 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
4149 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
4150 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
4152 printf_filtered (")\n");
4153 printfi_filtered (spaces + 8, "type ");
4154 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
4156 printf_filtered ("\n");
4158 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
4161 printfi_filtered (spaces + 8, "args ");
4162 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
4164 printf_filtered ("\n");
4165 print_args (TYPE_FN_FIELD_ARGS (f, overload_idx),
4166 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
4168 printfi_filtered (spaces + 8, "fcontext ");
4169 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
4171 printf_filtered ("\n");
4173 printfi_filtered (spaces + 8, "is_const %d\n",
4174 TYPE_FN_FIELD_CONST (f, overload_idx));
4175 printfi_filtered (spaces + 8, "is_volatile %d\n",
4176 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
4177 printfi_filtered (spaces + 8, "is_private %d\n",
4178 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
4179 printfi_filtered (spaces + 8, "is_protected %d\n",
4180 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
4181 printfi_filtered (spaces + 8, "is_stub %d\n",
4182 TYPE_FN_FIELD_STUB (f, overload_idx));
4183 printfi_filtered (spaces + 8, "voffset %u\n",
4184 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
4190 print_cplus_stuff (struct type *type, int spaces)
4192 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
4193 printfi_filtered (spaces, "vptr_basetype ");
4194 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
4195 puts_filtered ("\n");
4196 if (TYPE_VPTR_BASETYPE (type) != NULL)
4197 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
4199 printfi_filtered (spaces, "n_baseclasses %d\n",
4200 TYPE_N_BASECLASSES (type));
4201 printfi_filtered (spaces, "nfn_fields %d\n",
4202 TYPE_NFN_FIELDS (type));
4203 if (TYPE_N_BASECLASSES (type) > 0)
4205 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
4206 TYPE_N_BASECLASSES (type));
4207 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
4209 printf_filtered (")");
4211 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
4212 TYPE_N_BASECLASSES (type));
4213 puts_filtered ("\n");
4215 if (TYPE_NFIELDS (type) > 0)
4217 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
4219 printfi_filtered (spaces,
4220 "private_field_bits (%d bits at *",
4221 TYPE_NFIELDS (type));
4222 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
4224 printf_filtered (")");
4225 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
4226 TYPE_NFIELDS (type));
4227 puts_filtered ("\n");
4229 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
4231 printfi_filtered (spaces,
4232 "protected_field_bits (%d bits at *",
4233 TYPE_NFIELDS (type));
4234 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
4236 printf_filtered (")");
4237 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
4238 TYPE_NFIELDS (type));
4239 puts_filtered ("\n");
4242 if (TYPE_NFN_FIELDS (type) > 0)
4244 dump_fn_fieldlists (type, spaces);
4248 /* Print the contents of the TYPE's type_specific union, assuming that
4249 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
4252 print_gnat_stuff (struct type *type, int spaces)
4254 struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
4256 if (descriptive_type == NULL)
4257 printfi_filtered (spaces + 2, "no descriptive type\n");
4260 printfi_filtered (spaces + 2, "descriptive type\n");
4261 recursive_dump_type (descriptive_type, spaces + 4);
4265 static struct obstack dont_print_type_obstack;
4268 recursive_dump_type (struct type *type, int spaces)
4273 obstack_begin (&dont_print_type_obstack, 0);
4275 if (TYPE_NFIELDS (type) > 0
4276 || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0))
4278 struct type **first_dont_print
4279 = (struct type **) obstack_base (&dont_print_type_obstack);
4281 int i = (struct type **)
4282 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
4286 if (type == first_dont_print[i])
4288 printfi_filtered (spaces, "type node ");
4289 gdb_print_host_address (type, gdb_stdout);
4290 printf_filtered (_(" <same as already seen type>\n"));
4295 obstack_ptr_grow (&dont_print_type_obstack, type);
4298 printfi_filtered (spaces, "type node ");
4299 gdb_print_host_address (type, gdb_stdout);
4300 printf_filtered ("\n");
4301 printfi_filtered (spaces, "name '%s' (",
4302 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
4303 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
4304 printf_filtered (")\n");
4305 printfi_filtered (spaces, "tagname '%s' (",
4306 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
4307 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
4308 printf_filtered (")\n");
4309 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
4310 switch (TYPE_CODE (type))
4312 case TYPE_CODE_UNDEF:
4313 printf_filtered ("(TYPE_CODE_UNDEF)");
4316 printf_filtered ("(TYPE_CODE_PTR)");
4318 case TYPE_CODE_ARRAY:
4319 printf_filtered ("(TYPE_CODE_ARRAY)");
4321 case TYPE_CODE_STRUCT:
4322 printf_filtered ("(TYPE_CODE_STRUCT)");
4324 case TYPE_CODE_UNION:
4325 printf_filtered ("(TYPE_CODE_UNION)");
4327 case TYPE_CODE_ENUM:
4328 printf_filtered ("(TYPE_CODE_ENUM)");
4330 case TYPE_CODE_FLAGS:
4331 printf_filtered ("(TYPE_CODE_FLAGS)");
4333 case TYPE_CODE_FUNC:
4334 printf_filtered ("(TYPE_CODE_FUNC)");
4337 printf_filtered ("(TYPE_CODE_INT)");
4340 printf_filtered ("(TYPE_CODE_FLT)");
4342 case TYPE_CODE_VOID:
4343 printf_filtered ("(TYPE_CODE_VOID)");
4346 printf_filtered ("(TYPE_CODE_SET)");
4348 case TYPE_CODE_RANGE:
4349 printf_filtered ("(TYPE_CODE_RANGE)");
4351 case TYPE_CODE_STRING:
4352 printf_filtered ("(TYPE_CODE_STRING)");
4354 case TYPE_CODE_ERROR:
4355 printf_filtered ("(TYPE_CODE_ERROR)");
4357 case TYPE_CODE_MEMBERPTR:
4358 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
4360 case TYPE_CODE_METHODPTR:
4361 printf_filtered ("(TYPE_CODE_METHODPTR)");
4363 case TYPE_CODE_METHOD:
4364 printf_filtered ("(TYPE_CODE_METHOD)");
4367 printf_filtered ("(TYPE_CODE_REF)");
4369 case TYPE_CODE_CHAR:
4370 printf_filtered ("(TYPE_CODE_CHAR)");
4372 case TYPE_CODE_BOOL:
4373 printf_filtered ("(TYPE_CODE_BOOL)");
4375 case TYPE_CODE_COMPLEX:
4376 printf_filtered ("(TYPE_CODE_COMPLEX)");
4378 case TYPE_CODE_TYPEDEF:
4379 printf_filtered ("(TYPE_CODE_TYPEDEF)");
4381 case TYPE_CODE_NAMESPACE:
4382 printf_filtered ("(TYPE_CODE_NAMESPACE)");
4385 printf_filtered ("(UNKNOWN TYPE CODE)");
4388 puts_filtered ("\n");
4389 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
4390 if (TYPE_OBJFILE_OWNED (type))
4392 printfi_filtered (spaces, "objfile ");
4393 gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout);
4397 printfi_filtered (spaces, "gdbarch ");
4398 gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout);
4400 printf_filtered ("\n");
4401 printfi_filtered (spaces, "target_type ");
4402 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
4403 printf_filtered ("\n");
4404 if (TYPE_TARGET_TYPE (type) != NULL)
4406 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
4408 printfi_filtered (spaces, "pointer_type ");
4409 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
4410 printf_filtered ("\n");
4411 printfi_filtered (spaces, "reference_type ");
4412 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
4413 printf_filtered ("\n");
4414 printfi_filtered (spaces, "type_chain ");
4415 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
4416 printf_filtered ("\n");
4417 printfi_filtered (spaces, "instance_flags 0x%x",
4418 TYPE_INSTANCE_FLAGS (type));
4419 if (TYPE_CONST (type))
4421 puts_filtered (" TYPE_CONST");
4423 if (TYPE_VOLATILE (type))
4425 puts_filtered (" TYPE_VOLATILE");
4427 if (TYPE_CODE_SPACE (type))
4429 puts_filtered (" TYPE_CODE_SPACE");
4431 if (TYPE_DATA_SPACE (type))
4433 puts_filtered (" TYPE_DATA_SPACE");
4435 if (TYPE_ADDRESS_CLASS_1 (type))
4437 puts_filtered (" TYPE_ADDRESS_CLASS_1");
4439 if (TYPE_ADDRESS_CLASS_2 (type))
4441 puts_filtered (" TYPE_ADDRESS_CLASS_2");
4443 if (TYPE_RESTRICT (type))
4445 puts_filtered (" TYPE_RESTRICT");
4447 if (TYPE_ATOMIC (type))
4449 puts_filtered (" TYPE_ATOMIC");
4451 puts_filtered ("\n");
4453 printfi_filtered (spaces, "flags");
4454 if (TYPE_UNSIGNED (type))
4456 puts_filtered (" TYPE_UNSIGNED");
4458 if (TYPE_NOSIGN (type))
4460 puts_filtered (" TYPE_NOSIGN");
4462 if (TYPE_STUB (type))
4464 puts_filtered (" TYPE_STUB");
4466 if (TYPE_TARGET_STUB (type))
4468 puts_filtered (" TYPE_TARGET_STUB");
4470 if (TYPE_PROTOTYPED (type))
4472 puts_filtered (" TYPE_PROTOTYPED");
4474 if (TYPE_INCOMPLETE (type))
4476 puts_filtered (" TYPE_INCOMPLETE");
4478 if (TYPE_VARARGS (type))
4480 puts_filtered (" TYPE_VARARGS");
4482 /* This is used for things like AltiVec registers on ppc. Gcc emits
4483 an attribute for the array type, which tells whether or not we
4484 have a vector, instead of a regular array. */
4485 if (TYPE_VECTOR (type))
4487 puts_filtered (" TYPE_VECTOR");
4489 if (TYPE_FIXED_INSTANCE (type))
4491 puts_filtered (" TYPE_FIXED_INSTANCE");
4493 if (TYPE_STUB_SUPPORTED (type))
4495 puts_filtered (" TYPE_STUB_SUPPORTED");
4497 if (TYPE_NOTTEXT (type))
4499 puts_filtered (" TYPE_NOTTEXT");
4501 puts_filtered ("\n");
4502 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
4503 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
4504 puts_filtered ("\n");
4505 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
4507 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
4508 printfi_filtered (spaces + 2,
4509 "[%d] enumval %s type ",
4510 idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
4512 printfi_filtered (spaces + 2,
4513 "[%d] bitpos %s bitsize %d type ",
4514 idx, plongest (TYPE_FIELD_BITPOS (type, idx)),
4515 TYPE_FIELD_BITSIZE (type, idx));
4516 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
4517 printf_filtered (" name '%s' (",
4518 TYPE_FIELD_NAME (type, idx) != NULL
4519 ? TYPE_FIELD_NAME (type, idx)
4521 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
4522 printf_filtered (")\n");
4523 if (TYPE_FIELD_TYPE (type, idx) != NULL)
4525 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
4528 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4530 printfi_filtered (spaces, "low %s%s high %s%s\n",
4531 plongest (TYPE_LOW_BOUND (type)),
4532 TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
4533 plongest (TYPE_HIGH_BOUND (type)),
4534 TYPE_HIGH_BOUND_UNDEFINED (type)
4535 ? " (undefined)" : "");
4538 switch (TYPE_SPECIFIC_FIELD (type))
4540 case TYPE_SPECIFIC_CPLUS_STUFF:
4541 printfi_filtered (spaces, "cplus_stuff ");
4542 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
4544 puts_filtered ("\n");
4545 print_cplus_stuff (type, spaces);
4548 case TYPE_SPECIFIC_GNAT_STUFF:
4549 printfi_filtered (spaces, "gnat_stuff ");
4550 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type), gdb_stdout);
4551 puts_filtered ("\n");
4552 print_gnat_stuff (type, spaces);
4555 case TYPE_SPECIFIC_FLOATFORMAT:
4556 printfi_filtered (spaces, "floatformat ");
4557 if (TYPE_FLOATFORMAT (type) == NULL
4558 || TYPE_FLOATFORMAT (type)->name == NULL)
4559 puts_filtered ("(null)");
4561 puts_filtered (TYPE_FLOATFORMAT (type)->name);
4562 puts_filtered ("\n");
4565 case TYPE_SPECIFIC_FUNC:
4566 printfi_filtered (spaces, "calling_convention %d\n",
4567 TYPE_CALLING_CONVENTION (type));
4568 /* tail_call_list is not printed. */
4571 case TYPE_SPECIFIC_SELF_TYPE:
4572 printfi_filtered (spaces, "self_type ");
4573 gdb_print_host_address (TYPE_SELF_TYPE (type), gdb_stdout);
4574 puts_filtered ("\n");
4579 obstack_free (&dont_print_type_obstack, NULL);
4582 /* Trivial helpers for the libiberty hash table, for mapping one
4587 struct type *old, *newobj;
4591 type_pair_hash (const void *item)
4593 const struct type_pair *pair = (const struct type_pair *) item;
4595 return htab_hash_pointer (pair->old);
4599 type_pair_eq (const void *item_lhs, const void *item_rhs)
4601 const struct type_pair *lhs = (const struct type_pair *) item_lhs;
4602 const struct type_pair *rhs = (const struct type_pair *) item_rhs;
4604 return lhs->old == rhs->old;
4607 /* Allocate the hash table used by copy_type_recursive to walk
4608 types without duplicates. We use OBJFILE's obstack, because
4609 OBJFILE is about to be deleted. */
4612 create_copied_types_hash (struct objfile *objfile)
4614 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
4615 NULL, &objfile->objfile_obstack,
4616 hashtab_obstack_allocate,
4617 dummy_obstack_deallocate);
4620 /* Recursively copy (deep copy) a dynamic attribute list of a type. */
4622 static struct dynamic_prop_list *
4623 copy_dynamic_prop_list (struct obstack *objfile_obstack,
4624 struct dynamic_prop_list *list)
4626 struct dynamic_prop_list *copy = list;
4627 struct dynamic_prop_list **node_ptr = ©
4629 while (*node_ptr != NULL)
4631 struct dynamic_prop_list *node_copy;
4633 node_copy = ((struct dynamic_prop_list *)
4634 obstack_copy (objfile_obstack, *node_ptr,
4635 sizeof (struct dynamic_prop_list)));
4636 node_copy->prop = (*node_ptr)->prop;
4637 *node_ptr = node_copy;
4639 node_ptr = &node_copy->next;
4645 /* Recursively copy (deep copy) TYPE, if it is associated with
4646 OBJFILE. Return a new type owned by the gdbarch associated with the type, a
4647 saved type if we have already visited TYPE (using COPIED_TYPES), or TYPE if
4648 it is not associated with OBJFILE. */
4651 copy_type_recursive (struct objfile *objfile,
4653 htab_t copied_types)
4655 struct type_pair *stored, pair;
4657 struct type *new_type;
4659 if (! TYPE_OBJFILE_OWNED (type))
4662 /* This type shouldn't be pointing to any types in other objfiles;
4663 if it did, the type might disappear unexpectedly. */
4664 gdb_assert (TYPE_OBJFILE (type) == objfile);
4667 slot = htab_find_slot (copied_types, &pair, INSERT);
4669 return ((struct type_pair *) *slot)->newobj;
4671 new_type = alloc_type_arch (get_type_arch (type));
4673 /* We must add the new type to the hash table immediately, in case
4674 we encounter this type again during a recursive call below. */
4675 stored = XOBNEW (&objfile->objfile_obstack, struct type_pair);
4677 stored->newobj = new_type;
4680 /* Copy the common fields of types. For the main type, we simply
4681 copy the entire thing and then update specific fields as needed. */
4682 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
4683 TYPE_OBJFILE_OWNED (new_type) = 0;
4684 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
4686 if (TYPE_NAME (type))
4687 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
4688 if (TYPE_TAG_NAME (type))
4689 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
4691 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4692 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4694 /* Copy the fields. */
4695 if (TYPE_NFIELDS (type))
4699 nfields = TYPE_NFIELDS (type);
4700 TYPE_FIELDS (new_type) = XCNEWVEC (struct field, nfields);
4701 for (i = 0; i < nfields; i++)
4703 TYPE_FIELD_ARTIFICIAL (new_type, i) =
4704 TYPE_FIELD_ARTIFICIAL (type, i);
4705 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
4706 if (TYPE_FIELD_TYPE (type, i))
4707 TYPE_FIELD_TYPE (new_type, i)
4708 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
4710 if (TYPE_FIELD_NAME (type, i))
4711 TYPE_FIELD_NAME (new_type, i) =
4712 xstrdup (TYPE_FIELD_NAME (type, i));
4713 switch (TYPE_FIELD_LOC_KIND (type, i))
4715 case FIELD_LOC_KIND_BITPOS:
4716 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
4717 TYPE_FIELD_BITPOS (type, i));
4719 case FIELD_LOC_KIND_ENUMVAL:
4720 SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i),
4721 TYPE_FIELD_ENUMVAL (type, i));
4723 case FIELD_LOC_KIND_PHYSADDR:
4724 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
4725 TYPE_FIELD_STATIC_PHYSADDR (type, i));
4727 case FIELD_LOC_KIND_PHYSNAME:
4728 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
4729 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
4733 internal_error (__FILE__, __LINE__,
4734 _("Unexpected type field location kind: %d"),
4735 TYPE_FIELD_LOC_KIND (type, i));
4740 /* For range types, copy the bounds information. */
4741 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4743 TYPE_RANGE_DATA (new_type) = XNEW (struct range_bounds);
4744 *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
4747 if (TYPE_DYN_PROP_LIST (type) != NULL)
4748 TYPE_DYN_PROP_LIST (new_type)
4749 = copy_dynamic_prop_list (&objfile->objfile_obstack,
4750 TYPE_DYN_PROP_LIST (type));
4753 /* Copy pointers to other types. */
4754 if (TYPE_TARGET_TYPE (type))
4755 TYPE_TARGET_TYPE (new_type) =
4756 copy_type_recursive (objfile,
4757 TYPE_TARGET_TYPE (type),
4760 /* Maybe copy the type_specific bits.
4762 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
4763 base classes and methods. There's no fundamental reason why we
4764 can't, but at the moment it is not needed. */
4766 switch (TYPE_SPECIFIC_FIELD (type))
4768 case TYPE_SPECIFIC_NONE:
4770 case TYPE_SPECIFIC_FUNC:
4771 INIT_FUNC_SPECIFIC (new_type);
4772 TYPE_CALLING_CONVENTION (new_type) = TYPE_CALLING_CONVENTION (type);
4773 TYPE_NO_RETURN (new_type) = TYPE_NO_RETURN (type);
4774 TYPE_TAIL_CALL_LIST (new_type) = NULL;
4776 case TYPE_SPECIFIC_FLOATFORMAT:
4777 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
4779 case TYPE_SPECIFIC_CPLUS_STUFF:
4780 INIT_CPLUS_SPECIFIC (new_type);
4782 case TYPE_SPECIFIC_GNAT_STUFF:
4783 INIT_GNAT_SPECIFIC (new_type);
4785 case TYPE_SPECIFIC_SELF_TYPE:
4786 set_type_self_type (new_type,
4787 copy_type_recursive (objfile, TYPE_SELF_TYPE (type),
4791 gdb_assert_not_reached ("bad type_specific_kind");
4797 /* Make a copy of the given TYPE, except that the pointer & reference
4798 types are not preserved.
4800 This function assumes that the given type has an associated objfile.
4801 This objfile is used to allocate the new type. */
4804 copy_type (const struct type *type)
4806 struct type *new_type;
4808 gdb_assert (TYPE_OBJFILE_OWNED (type));
4810 new_type = alloc_type_copy (type);
4811 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4812 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4813 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
4814 sizeof (struct main_type));
4815 if (TYPE_DYN_PROP_LIST (type) != NULL)
4816 TYPE_DYN_PROP_LIST (new_type)
4817 = copy_dynamic_prop_list (&TYPE_OBJFILE (type) -> objfile_obstack,
4818 TYPE_DYN_PROP_LIST (type));
4823 /* Helper functions to initialize architecture-specific types. */
4825 /* Allocate a type structure associated with GDBARCH and set its
4826 CODE, LENGTH, and NAME fields. */
4829 arch_type (struct gdbarch *gdbarch,
4830 enum type_code code, int bit, const char *name)
4834 type = alloc_type_arch (gdbarch);
4835 set_type_code (type, code);
4836 gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
4837 TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
4840 TYPE_NAME (type) = gdbarch_obstack_strdup (gdbarch, name);
4845 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
4846 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4847 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4850 arch_integer_type (struct gdbarch *gdbarch,
4851 int bit, int unsigned_p, const char *name)
4855 t = arch_type (gdbarch, TYPE_CODE_INT, bit, name);
4857 TYPE_UNSIGNED (t) = 1;
4862 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
4863 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4864 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4867 arch_character_type (struct gdbarch *gdbarch,
4868 int bit, int unsigned_p, const char *name)
4872 t = arch_type (gdbarch, TYPE_CODE_CHAR, bit, name);
4874 TYPE_UNSIGNED (t) = 1;
4879 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
4880 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4881 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4884 arch_boolean_type (struct gdbarch *gdbarch,
4885 int bit, int unsigned_p, const char *name)
4889 t = arch_type (gdbarch, TYPE_CODE_BOOL, bit, name);
4891 TYPE_UNSIGNED (t) = 1;
4896 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
4897 BIT is the type size in bits; if BIT equals -1, the size is
4898 determined by the floatformat. NAME is the type name. Set the
4899 TYPE_FLOATFORMAT from FLOATFORMATS. */
4902 arch_float_type (struct gdbarch *gdbarch,
4903 int bit, const char *name,
4904 const struct floatformat **floatformats)
4906 const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
4909 bit = verify_floatformat (bit, fmt);
4910 t = arch_type (gdbarch, TYPE_CODE_FLT, bit, name);
4911 TYPE_FLOATFORMAT (t) = fmt;
4916 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with GDBARCH.
4917 BIT is the type size in bits. NAME is the type name. */
4920 arch_decfloat_type (struct gdbarch *gdbarch, int bit, const char *name)
4924 t = arch_type (gdbarch, TYPE_CODE_DECFLOAT, bit, name);
4928 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
4929 NAME is the type name. TARGET_TYPE is the component float type. */
4932 arch_complex_type (struct gdbarch *gdbarch,
4933 const char *name, struct type *target_type)
4937 t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
4938 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
4939 TYPE_TARGET_TYPE (t) = target_type;
4943 /* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH.
4944 BIT is the pointer type size in bits. NAME is the type name.
4945 TARGET_TYPE is the pointer target type. Always sets the pointer type's
4946 TYPE_UNSIGNED flag. */
4949 arch_pointer_type (struct gdbarch *gdbarch,
4950 int bit, const char *name, struct type *target_type)
4954 t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name);
4955 TYPE_TARGET_TYPE (t) = target_type;
4956 TYPE_UNSIGNED (t) = 1;
4960 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
4961 NAME is the type name. BIT is the size of the flag word in bits. */
4964 arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit)
4968 type = arch_type (gdbarch, TYPE_CODE_FLAGS, bit, name);
4969 TYPE_UNSIGNED (type) = 1;
4970 TYPE_NFIELDS (type) = 0;
4971 /* Pre-allocate enough space assuming every field is one bit. */
4973 = (struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field));
4978 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
4979 position BITPOS is called NAME. Pass NAME as "" for fields that
4980 should not be printed. */
4983 append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
4984 struct type *field_type, const char *name)
4986 int type_bitsize = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
4987 int field_nr = TYPE_NFIELDS (type);
4989 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
4990 gdb_assert (TYPE_NFIELDS (type) + 1 <= type_bitsize);
4991 gdb_assert (start_bitpos >= 0 && start_bitpos < type_bitsize);
4992 gdb_assert (nr_bits >= 1 && nr_bits <= type_bitsize);
4993 gdb_assert (name != NULL);
4995 TYPE_FIELD_NAME (type, field_nr) = xstrdup (name);
4996 TYPE_FIELD_TYPE (type, field_nr) = field_type;
4997 SET_FIELD_BITPOS (TYPE_FIELD (type, field_nr), start_bitpos);
4998 TYPE_FIELD_BITSIZE (type, field_nr) = nr_bits;
4999 ++TYPE_NFIELDS (type);
5002 /* Special version of append_flags_type_field to add a flag field.
5003 Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5004 position BITPOS is called NAME. */
5007 append_flags_type_flag (struct type *type, int bitpos, const char *name)
5009 struct gdbarch *gdbarch = get_type_arch (type);
5011 append_flags_type_field (type, bitpos, 1,
5012 builtin_type (gdbarch)->builtin_bool,
5016 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
5017 specified by CODE) associated with GDBARCH. NAME is the type name. */
5020 arch_composite_type (struct gdbarch *gdbarch, const char *name,
5021 enum type_code code)
5025 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
5026 t = arch_type (gdbarch, code, 0, NULL);
5027 TYPE_TAG_NAME (t) = name;
5028 INIT_CPLUS_SPECIFIC (t);
5032 /* Add new field with name NAME and type FIELD to composite type T.
5033 Do not set the field's position or adjust the type's length;
5034 the caller should do so. Return the new field. */
5037 append_composite_type_field_raw (struct type *t, const char *name,
5042 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
5043 TYPE_FIELDS (t) = XRESIZEVEC (struct field, TYPE_FIELDS (t),
5045 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
5046 memset (f, 0, sizeof f[0]);
5047 FIELD_TYPE (f[0]) = field;
5048 FIELD_NAME (f[0]) = name;
5052 /* Add new field with name NAME and type FIELD to composite type T.
5053 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
5056 append_composite_type_field_aligned (struct type *t, const char *name,
5057 struct type *field, int alignment)
5059 struct field *f = append_composite_type_field_raw (t, name, field);
5061 if (TYPE_CODE (t) == TYPE_CODE_UNION)
5063 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
5064 TYPE_LENGTH (t) = TYPE_LENGTH (field);
5066 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
5068 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
5069 if (TYPE_NFIELDS (t) > 1)
5071 SET_FIELD_BITPOS (f[0],
5072 (FIELD_BITPOS (f[-1])
5073 + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
5074 * TARGET_CHAR_BIT)));
5080 alignment *= TARGET_CHAR_BIT;
5081 left = FIELD_BITPOS (f[0]) % alignment;
5085 SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left));
5086 TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
5093 /* Add new field with name NAME and type FIELD to composite type T. */
5096 append_composite_type_field (struct type *t, const char *name,
5099 append_composite_type_field_aligned (t, name, field, 0);
5102 static struct gdbarch_data *gdbtypes_data;
5104 const struct builtin_type *
5105 builtin_type (struct gdbarch *gdbarch)
5107 return (const struct builtin_type *) gdbarch_data (gdbarch, gdbtypes_data);
5111 gdbtypes_post_init (struct gdbarch *gdbarch)
5113 struct builtin_type *builtin_type
5114 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
5117 builtin_type->builtin_void
5118 = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
5119 builtin_type->builtin_char
5120 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
5121 !gdbarch_char_signed (gdbarch), "char");
5122 TYPE_NOSIGN (builtin_type->builtin_char) = 1;
5123 builtin_type->builtin_signed_char
5124 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
5126 builtin_type->builtin_unsigned_char
5127 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
5128 1, "unsigned char");
5129 builtin_type->builtin_short
5130 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
5132 builtin_type->builtin_unsigned_short
5133 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
5134 1, "unsigned short");
5135 builtin_type->builtin_int
5136 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
5138 builtin_type->builtin_unsigned_int
5139 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
5141 builtin_type->builtin_long
5142 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
5144 builtin_type->builtin_unsigned_long
5145 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
5146 1, "unsigned long");
5147 builtin_type->builtin_long_long
5148 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
5150 builtin_type->builtin_unsigned_long_long
5151 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
5152 1, "unsigned long long");
5153 builtin_type->builtin_float
5154 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
5155 "float", gdbarch_float_format (gdbarch));
5156 builtin_type->builtin_double
5157 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
5158 "double", gdbarch_double_format (gdbarch));
5159 builtin_type->builtin_long_double
5160 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
5161 "long double", gdbarch_long_double_format (gdbarch));
5162 builtin_type->builtin_complex
5163 = arch_complex_type (gdbarch, "complex",
5164 builtin_type->builtin_float);
5165 builtin_type->builtin_double_complex
5166 = arch_complex_type (gdbarch, "double complex",
5167 builtin_type->builtin_double);
5168 builtin_type->builtin_string
5169 = arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
5170 builtin_type->builtin_bool
5171 = arch_type (gdbarch, TYPE_CODE_BOOL, TARGET_CHAR_BIT, "bool");
5173 /* The following three are about decimal floating point types, which
5174 are 32-bits, 64-bits and 128-bits respectively. */
5175 builtin_type->builtin_decfloat
5176 = arch_decfloat_type (gdbarch, 32, "_Decimal32");
5177 builtin_type->builtin_decdouble
5178 = arch_decfloat_type (gdbarch, 64, "_Decimal64");
5179 builtin_type->builtin_declong
5180 = arch_decfloat_type (gdbarch, 128, "_Decimal128");
5182 /* "True" character types. */
5183 builtin_type->builtin_true_char
5184 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character");
5185 builtin_type->builtin_true_unsigned_char
5186 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character");
5188 /* Fixed-size integer types. */
5189 builtin_type->builtin_int0
5190 = arch_integer_type (gdbarch, 0, 0, "int0_t");
5191 builtin_type->builtin_int8
5192 = arch_integer_type (gdbarch, 8, 0, "int8_t");
5193 builtin_type->builtin_uint8
5194 = arch_integer_type (gdbarch, 8, 1, "uint8_t");
5195 builtin_type->builtin_int16
5196 = arch_integer_type (gdbarch, 16, 0, "int16_t");
5197 builtin_type->builtin_uint16
5198 = arch_integer_type (gdbarch, 16, 1, "uint16_t");
5199 builtin_type->builtin_int32
5200 = arch_integer_type (gdbarch, 32, 0, "int32_t");
5201 builtin_type->builtin_uint32
5202 = arch_integer_type (gdbarch, 32, 1, "uint32_t");
5203 builtin_type->builtin_int64
5204 = arch_integer_type (gdbarch, 64, 0, "int64_t");
5205 builtin_type->builtin_uint64
5206 = arch_integer_type (gdbarch, 64, 1, "uint64_t");
5207 builtin_type->builtin_int128
5208 = arch_integer_type (gdbarch, 128, 0, "int128_t");
5209 builtin_type->builtin_uint128
5210 = arch_integer_type (gdbarch, 128, 1, "uint128_t");
5211 TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |=
5212 TYPE_INSTANCE_FLAG_NOTTEXT;
5213 TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |=
5214 TYPE_INSTANCE_FLAG_NOTTEXT;
5216 /* Wide character types. */
5217 builtin_type->builtin_char16
5218 = arch_integer_type (gdbarch, 16, 1, "char16_t");
5219 builtin_type->builtin_char32
5220 = arch_integer_type (gdbarch, 32, 1, "char32_t");
5221 builtin_type->builtin_wchar
5222 = arch_integer_type (gdbarch, gdbarch_wchar_bit (gdbarch),
5223 !gdbarch_wchar_signed (gdbarch), "wchar_t");
5225 /* Default data/code pointer types. */
5226 builtin_type->builtin_data_ptr
5227 = lookup_pointer_type (builtin_type->builtin_void);
5228 builtin_type->builtin_func_ptr
5229 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
5230 builtin_type->builtin_func_func
5231 = lookup_function_type (builtin_type->builtin_func_ptr);
5233 /* This type represents a GDB internal function. */
5234 builtin_type->internal_fn
5235 = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0,
5236 "<internal function>");
5238 /* This type represents an xmethod. */
5239 builtin_type->xmethod
5240 = arch_type (gdbarch, TYPE_CODE_XMETHOD, 0, "<xmethod>");
5242 return builtin_type;
5245 /* This set of objfile-based types is intended to be used by symbol
5246 readers as basic types. */
5248 static const struct objfile_data *objfile_type_data;
5250 const struct objfile_type *
5251 objfile_type (struct objfile *objfile)
5253 struct gdbarch *gdbarch;
5254 struct objfile_type *objfile_type
5255 = (struct objfile_type *) objfile_data (objfile, objfile_type_data);
5258 return objfile_type;
5260 objfile_type = OBSTACK_CALLOC (&objfile->objfile_obstack,
5261 1, struct objfile_type);
5263 /* Use the objfile architecture to determine basic type properties. */
5264 gdbarch = get_objfile_arch (objfile);
5267 objfile_type->builtin_void
5268 = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
5269 objfile_type->builtin_char
5270 = init_integer_type (objfile, TARGET_CHAR_BIT,
5271 !gdbarch_char_signed (gdbarch), "char");
5272 TYPE_NOSIGN (objfile_type->builtin_char) = 1;
5273 objfile_type->builtin_signed_char
5274 = init_integer_type (objfile, TARGET_CHAR_BIT,
5276 objfile_type->builtin_unsigned_char
5277 = init_integer_type (objfile, TARGET_CHAR_BIT,
5278 1, "unsigned char");
5279 objfile_type->builtin_short
5280 = init_integer_type (objfile, gdbarch_short_bit (gdbarch),
5282 objfile_type->builtin_unsigned_short
5283 = init_integer_type (objfile, gdbarch_short_bit (gdbarch),
5284 1, "unsigned short");
5285 objfile_type->builtin_int
5286 = init_integer_type (objfile, gdbarch_int_bit (gdbarch),
5288 objfile_type->builtin_unsigned_int
5289 = init_integer_type (objfile, gdbarch_int_bit (gdbarch),
5291 objfile_type->builtin_long
5292 = init_integer_type (objfile, gdbarch_long_bit (gdbarch),
5294 objfile_type->builtin_unsigned_long
5295 = init_integer_type (objfile, gdbarch_long_bit (gdbarch),
5296 1, "unsigned long");
5297 objfile_type->builtin_long_long
5298 = init_integer_type (objfile, gdbarch_long_long_bit (gdbarch),
5300 objfile_type->builtin_unsigned_long_long
5301 = init_integer_type (objfile, gdbarch_long_long_bit (gdbarch),
5302 1, "unsigned long long");
5303 objfile_type->builtin_float
5304 = init_float_type (objfile, gdbarch_float_bit (gdbarch),
5305 "float", gdbarch_float_format (gdbarch));
5306 objfile_type->builtin_double
5307 = init_float_type (objfile, gdbarch_double_bit (gdbarch),
5308 "double", gdbarch_double_format (gdbarch));
5309 objfile_type->builtin_long_double
5310 = init_float_type (objfile, gdbarch_long_double_bit (gdbarch),
5311 "long double", gdbarch_long_double_format (gdbarch));
5313 /* This type represents a type that was unrecognized in symbol read-in. */
5314 objfile_type->builtin_error
5315 = init_type (objfile, TYPE_CODE_ERROR, 0, "<unknown type>");
5317 /* The following set of types is used for symbols with no
5318 debug information. */
5319 objfile_type->nodebug_text_symbol
5320 = init_type (objfile, TYPE_CODE_FUNC, TARGET_CHAR_BIT,
5321 "<text variable, no debug info>");
5322 objfile_type->nodebug_text_gnu_ifunc_symbol
5323 = init_type (objfile, TYPE_CODE_FUNC, TARGET_CHAR_BIT,
5324 "<text gnu-indirect-function variable, no debug info>");
5325 /* Ifunc resolvers return a function address. */
5326 TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
5327 = init_integer_type (objfile, gdbarch_addr_bit (gdbarch), 1,
5328 "__IFUNC_RESOLVER_RET");
5329 TYPE_GNU_IFUNC (objfile_type->nodebug_text_gnu_ifunc_symbol) = 1;
5330 objfile_type->nodebug_got_plt_symbol
5331 = init_pointer_type (objfile, gdbarch_addr_bit (gdbarch),
5332 "<text from jump slot in .got.plt, no debug info>",
5333 objfile_type->nodebug_text_symbol);
5334 objfile_type->nodebug_data_symbol
5335 = init_nodebug_var_type (objfile, "<data variable, no debug info>");
5336 objfile_type->nodebug_unknown_symbol
5337 = init_nodebug_var_type (objfile, "<variable (not text or data), no debug info>");
5338 objfile_type->nodebug_tls_symbol
5339 = init_nodebug_var_type (objfile, "<thread local variable, no debug info>");
5341 /* NOTE: on some targets, addresses and pointers are not necessarily
5345 - gdb's `struct type' always describes the target's
5347 - gdb's `struct value' objects should always hold values in
5349 - gdb's CORE_ADDR values are addresses in the unified virtual
5350 address space that the assembler and linker work with. Thus,
5351 since target_read_memory takes a CORE_ADDR as an argument, it
5352 can access any memory on the target, even if the processor has
5353 separate code and data address spaces.
5355 In this context, objfile_type->builtin_core_addr is a bit odd:
5356 it's a target type for a value the target will never see. It's
5357 only used to hold the values of (typeless) linker symbols, which
5358 are indeed in the unified virtual address space. */
5360 objfile_type->builtin_core_addr
5361 = init_integer_type (objfile, gdbarch_addr_bit (gdbarch), 1,
5364 set_objfile_data (objfile, objfile_type_data, objfile_type);
5365 return objfile_type;
5369 _initialize_gdbtypes (void)
5371 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
5372 objfile_type_data = register_objfile_data ();
5374 add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug,
5375 _("Set debugging of C++ overloading."),
5376 _("Show debugging of C++ overloading."),
5377 _("When enabled, ranking of the "
5378 "functions is displayed."),
5380 show_overload_debug,
5381 &setdebuglist, &showdebuglist);
5383 /* Add user knob for controlling resolution of opaque types. */
5384 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
5385 &opaque_type_resolution,
5386 _("Set resolution of opaque struct/class/union"
5387 " types (if set before loading symbols)."),
5388 _("Show resolution of opaque struct/class/union"
5389 " types (if set before loading symbols)."),
5391 show_opaque_type_resolution,
5392 &setlist, &showlist);
5394 /* Add an option to permit non-strict type checking. */
5395 add_setshow_boolean_cmd ("type", class_support,
5396 &strict_type_checking,
5397 _("Set strict type checking."),
5398 _("Show strict type checking."),
5400 show_strict_type_checking,
5401 &setchecklist, &showchecklist);