1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2014 Free Software Foundation, Inc.
5 Contributed by Cygnus Support, using pieces from other GDB modules.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 #include "expression.h"
34 #include "complaints.h"
37 #include "gdb_assert.h"
39 #include "exceptions.h"
40 #include "cp-support.h"
42 #include "dwarf2loc.h"
45 /* Initialize BADNESS constants. */
47 const struct rank LENGTH_MISMATCH_BADNESS = {100,0};
49 const struct rank TOO_FEW_PARAMS_BADNESS = {100,0};
50 const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0};
52 const struct rank EXACT_MATCH_BADNESS = {0,0};
54 const struct rank INTEGER_PROMOTION_BADNESS = {1,0};
55 const struct rank FLOAT_PROMOTION_BADNESS = {1,0};
56 const struct rank BASE_PTR_CONVERSION_BADNESS = {1,0};
57 const struct rank INTEGER_CONVERSION_BADNESS = {2,0};
58 const struct rank FLOAT_CONVERSION_BADNESS = {2,0};
59 const struct rank INT_FLOAT_CONVERSION_BADNESS = {2,0};
60 const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0};
61 const struct rank BOOL_CONVERSION_BADNESS = {3,0};
62 const struct rank BASE_CONVERSION_BADNESS = {2,0};
63 const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
64 const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
65 const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
66 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
68 /* Floatformat pairs. */
69 const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
70 &floatformat_ieee_half_big,
71 &floatformat_ieee_half_little
73 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
74 &floatformat_ieee_single_big,
75 &floatformat_ieee_single_little
77 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
78 &floatformat_ieee_double_big,
79 &floatformat_ieee_double_little
81 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
82 &floatformat_ieee_double_big,
83 &floatformat_ieee_double_littlebyte_bigword
85 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
86 &floatformat_i387_ext,
89 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
90 &floatformat_m68881_ext,
91 &floatformat_m68881_ext
93 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
94 &floatformat_arm_ext_big,
95 &floatformat_arm_ext_littlebyte_bigword
97 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
98 &floatformat_ia64_spill_big,
99 &floatformat_ia64_spill_little
101 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
102 &floatformat_ia64_quad_big,
103 &floatformat_ia64_quad_little
105 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
109 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
113 const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
114 &floatformat_ibm_long_double_big,
115 &floatformat_ibm_long_double_little
118 /* Should opaque types be resolved? */
120 static int opaque_type_resolution = 1;
122 /* A flag to enable printing of debugging information of C++
125 unsigned int overload_debug = 0;
127 /* A flag to enable strict type checking. */
129 static int strict_type_checking = 1;
131 /* A function to show whether opaque types are resolved. */
134 show_opaque_type_resolution (struct ui_file *file, int from_tty,
135 struct cmd_list_element *c,
138 fprintf_filtered (file, _("Resolution of opaque struct/class/union types "
139 "(if set before loading symbols) is %s.\n"),
143 /* A function to show whether C++ overload debugging is enabled. */
146 show_overload_debug (struct ui_file *file, int from_tty,
147 struct cmd_list_element *c, const char *value)
149 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
153 /* A function to show the status of strict type checking. */
156 show_strict_type_checking (struct ui_file *file, int from_tty,
157 struct cmd_list_element *c, const char *value)
159 fprintf_filtered (file, _("Strict type checking is %s.\n"), value);
163 /* Allocate a new OBJFILE-associated type structure and fill it
164 with some defaults. Space for the type structure is allocated
165 on the objfile's objfile_obstack. */
168 alloc_type (struct objfile *objfile)
172 gdb_assert (objfile != NULL);
174 /* Alloc the structure and start off with all fields zeroed. */
175 type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
176 TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
178 OBJSTAT (objfile, n_types++);
180 TYPE_OBJFILE_OWNED (type) = 1;
181 TYPE_OWNER (type).objfile = objfile;
183 /* Initialize the fields that might not be zero. */
185 TYPE_CODE (type) = TYPE_CODE_UNDEF;
186 TYPE_VPTR_FIELDNO (type) = -1;
187 TYPE_CHAIN (type) = type; /* Chain back to itself. */
192 /* Allocate a new GDBARCH-associated type structure and fill it
193 with some defaults. Space for the type structure is allocated
197 alloc_type_arch (struct gdbarch *gdbarch)
201 gdb_assert (gdbarch != NULL);
203 /* Alloc the structure and start off with all fields zeroed. */
205 type = XCNEW (struct type);
206 TYPE_MAIN_TYPE (type) = XCNEW (struct main_type);
208 TYPE_OBJFILE_OWNED (type) = 0;
209 TYPE_OWNER (type).gdbarch = gdbarch;
211 /* Initialize the fields that might not be zero. */
213 TYPE_CODE (type) = TYPE_CODE_UNDEF;
214 TYPE_VPTR_FIELDNO (type) = -1;
215 TYPE_CHAIN (type) = type; /* Chain back to itself. */
220 /* If TYPE is objfile-associated, allocate a new type structure
221 associated with the same objfile. If TYPE is gdbarch-associated,
222 allocate a new type structure associated with the same gdbarch. */
225 alloc_type_copy (const struct type *type)
227 if (TYPE_OBJFILE_OWNED (type))
228 return alloc_type (TYPE_OWNER (type).objfile);
230 return alloc_type_arch (TYPE_OWNER (type).gdbarch);
233 /* If TYPE is gdbarch-associated, return that architecture.
234 If TYPE is objfile-associated, return that objfile's architecture. */
237 get_type_arch (const struct type *type)
239 if (TYPE_OBJFILE_OWNED (type))
240 return get_objfile_arch (TYPE_OWNER (type).objfile);
242 return TYPE_OWNER (type).gdbarch;
245 /* See gdbtypes.h. */
248 get_target_type (struct type *type)
252 type = TYPE_TARGET_TYPE (type);
254 type = check_typedef (type);
260 /* Alloc a new type instance structure, fill it with some defaults,
261 and point it at OLDTYPE. Allocate the new type instance from the
262 same place as OLDTYPE. */
265 alloc_type_instance (struct type *oldtype)
269 /* Allocate the structure. */
271 if (! TYPE_OBJFILE_OWNED (oldtype))
272 type = XCNEW (struct type);
274 type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
277 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
279 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
284 /* Clear all remnants of the previous type at TYPE, in preparation for
285 replacing it with something else. Preserve owner information. */
288 smash_type (struct type *type)
290 int objfile_owned = TYPE_OBJFILE_OWNED (type);
291 union type_owner owner = TYPE_OWNER (type);
293 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
295 /* Restore owner information. */
296 TYPE_OBJFILE_OWNED (type) = objfile_owned;
297 TYPE_OWNER (type) = owner;
299 /* For now, delete the rings. */
300 TYPE_CHAIN (type) = type;
302 /* For now, leave the pointer/reference types alone. */
305 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
306 to a pointer to memory where the pointer type should be stored.
307 If *TYPEPTR is zero, update it to point to the pointer type we return.
308 We allocate new memory if needed. */
311 make_pointer_type (struct type *type, struct type **typeptr)
313 struct type *ntype; /* New type */
316 ntype = TYPE_POINTER_TYPE (type);
321 return ntype; /* Don't care about alloc,
322 and have new type. */
323 else if (*typeptr == 0)
325 *typeptr = ntype; /* Tracking alloc, and have new type. */
330 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
332 ntype = alloc_type_copy (type);
336 else /* We have storage, but need to reset it. */
339 chain = TYPE_CHAIN (ntype);
341 TYPE_CHAIN (ntype) = chain;
344 TYPE_TARGET_TYPE (ntype) = type;
345 TYPE_POINTER_TYPE (type) = ntype;
347 /* FIXME! Assumes the machine has only one representation for pointers! */
350 = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
351 TYPE_CODE (ntype) = TYPE_CODE_PTR;
353 /* Mark pointers as unsigned. The target converts between pointers
354 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
355 gdbarch_address_to_pointer. */
356 TYPE_UNSIGNED (ntype) = 1;
358 /* Update the length of all the other variants of this type. */
359 chain = TYPE_CHAIN (ntype);
360 while (chain != ntype)
362 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
363 chain = TYPE_CHAIN (chain);
369 /* Given a type TYPE, return a type of pointers to that type.
370 May need to construct such a type if this is the first use. */
373 lookup_pointer_type (struct type *type)
375 return make_pointer_type (type, (struct type **) 0);
378 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
379 points to a pointer to memory where the reference type should be
380 stored. If *TYPEPTR is zero, update it to point to the reference
381 type we return. We allocate new memory if needed. */
384 make_reference_type (struct type *type, struct type **typeptr)
386 struct type *ntype; /* New type */
389 ntype = TYPE_REFERENCE_TYPE (type);
394 return ntype; /* Don't care about alloc,
395 and have new type. */
396 else if (*typeptr == 0)
398 *typeptr = ntype; /* Tracking alloc, and have new type. */
403 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
405 ntype = alloc_type_copy (type);
409 else /* We have storage, but need to reset it. */
412 chain = TYPE_CHAIN (ntype);
414 TYPE_CHAIN (ntype) = chain;
417 TYPE_TARGET_TYPE (ntype) = type;
418 TYPE_REFERENCE_TYPE (type) = ntype;
420 /* FIXME! Assume the machine has only one representation for
421 references, and that it matches the (only) representation for
424 TYPE_LENGTH (ntype) =
425 gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
426 TYPE_CODE (ntype) = TYPE_CODE_REF;
428 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
429 TYPE_REFERENCE_TYPE (type) = ntype;
431 /* Update the length of all the other variants of this type. */
432 chain = TYPE_CHAIN (ntype);
433 while (chain != ntype)
435 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
436 chain = TYPE_CHAIN (chain);
442 /* Same as above, but caller doesn't care about memory allocation
446 lookup_reference_type (struct type *type)
448 return make_reference_type (type, (struct type **) 0);
451 /* Lookup a function type that returns type TYPE. TYPEPTR, if
452 nonzero, points to a pointer to memory where the function type
453 should be stored. If *TYPEPTR is zero, update it to point to the
454 function type we return. We allocate new memory if needed. */
457 make_function_type (struct type *type, struct type **typeptr)
459 struct type *ntype; /* New type */
461 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
463 ntype = alloc_type_copy (type);
467 else /* We have storage, but need to reset it. */
473 TYPE_TARGET_TYPE (ntype) = type;
475 TYPE_LENGTH (ntype) = 1;
476 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
478 INIT_FUNC_SPECIFIC (ntype);
483 /* Given a type TYPE, return a type of functions that return that type.
484 May need to construct such a type if this is the first use. */
487 lookup_function_type (struct type *type)
489 return make_function_type (type, (struct type **) 0);
492 /* Given a type TYPE and argument types, return the appropriate
493 function type. If the final type in PARAM_TYPES is NULL, make a
497 lookup_function_type_with_arguments (struct type *type,
499 struct type **param_types)
501 struct type *fn = make_function_type (type, (struct type **) 0);
506 if (param_types[nparams - 1] == NULL)
509 TYPE_VARARGS (fn) = 1;
511 else if (TYPE_CODE (check_typedef (param_types[nparams - 1]))
515 /* Caller should have ensured this. */
516 gdb_assert (nparams == 0);
517 TYPE_PROTOTYPED (fn) = 1;
521 TYPE_NFIELDS (fn) = nparams;
522 TYPE_FIELDS (fn) = TYPE_ZALLOC (fn, nparams * sizeof (struct field));
523 for (i = 0; i < nparams; ++i)
524 TYPE_FIELD_TYPE (fn, i) = param_types[i];
529 /* Identify address space identifier by name --
530 return the integer flag defined in gdbtypes.h. */
533 address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
537 /* Check for known address space delimiters. */
538 if (!strcmp (space_identifier, "code"))
539 return TYPE_INSTANCE_FLAG_CODE_SPACE;
540 else if (!strcmp (space_identifier, "data"))
541 return TYPE_INSTANCE_FLAG_DATA_SPACE;
542 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
543 && gdbarch_address_class_name_to_type_flags (gdbarch,
548 error (_("Unknown address space specifier: \"%s\""), space_identifier);
551 /* Identify address space identifier by integer flag as defined in
552 gdbtypes.h -- return the string version of the adress space name. */
555 address_space_int_to_name (struct gdbarch *gdbarch, int space_flag)
557 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
559 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
561 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
562 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
563 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
568 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
570 If STORAGE is non-NULL, create the new type instance there.
571 STORAGE must be in the same obstack as TYPE. */
574 make_qualified_type (struct type *type, int new_flags,
575 struct type *storage)
582 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
584 ntype = TYPE_CHAIN (ntype);
586 while (ntype != type);
588 /* Create a new type instance. */
590 ntype = alloc_type_instance (type);
593 /* If STORAGE was provided, it had better be in the same objfile
594 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
595 if one objfile is freed and the other kept, we'd have
596 dangling pointers. */
597 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
600 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
601 TYPE_CHAIN (ntype) = ntype;
604 /* Pointers or references to the original type are not relevant to
606 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
607 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
609 /* Chain the new qualified type to the old type. */
610 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
611 TYPE_CHAIN (type) = ntype;
613 /* Now set the instance flags and return the new type. */
614 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
616 /* Set length of new type to that of the original type. */
617 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
622 /* Make an address-space-delimited variant of a type -- a type that
623 is identical to the one supplied except that it has an address
624 space attribute attached to it (such as "code" or "data").
626 The space attributes "code" and "data" are for Harvard
627 architectures. The address space attributes are for architectures
628 which have alternately sized pointers or pointers with alternate
632 make_type_with_address_space (struct type *type, int space_flag)
634 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
635 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
636 | TYPE_INSTANCE_FLAG_DATA_SPACE
637 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
640 return make_qualified_type (type, new_flags, NULL);
643 /* Make a "c-v" variant of a type -- a type that is identical to the
644 one supplied except that it may have const or volatile attributes
645 CNST is a flag for setting the const attribute
646 VOLTL is a flag for setting the volatile attribute
647 TYPE is the base type whose variant we are creating.
649 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
650 storage to hold the new qualified type; *TYPEPTR and TYPE must be
651 in the same objfile. Otherwise, allocate fresh memory for the new
652 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
653 new type we construct. */
656 make_cv_type (int cnst, int voltl,
658 struct type **typeptr)
660 struct type *ntype; /* New type */
662 int new_flags = (TYPE_INSTANCE_FLAGS (type)
663 & ~(TYPE_INSTANCE_FLAG_CONST
664 | TYPE_INSTANCE_FLAG_VOLATILE));
667 new_flags |= TYPE_INSTANCE_FLAG_CONST;
670 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
672 if (typeptr && *typeptr != NULL)
674 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
675 a C-V variant chain that threads across objfiles: if one
676 objfile gets freed, then the other has a broken C-V chain.
678 This code used to try to copy over the main type from TYPE to
679 *TYPEPTR if they were in different objfiles, but that's
680 wrong, too: TYPE may have a field list or member function
681 lists, which refer to types of their own, etc. etc. The
682 whole shebang would need to be copied over recursively; you
683 can't have inter-objfile pointers. The only thing to do is
684 to leave stub types as stub types, and look them up afresh by
685 name each time you encounter them. */
686 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
689 ntype = make_qualified_type (type, new_flags,
690 typeptr ? *typeptr : NULL);
698 /* Make a 'restrict'-qualified version of TYPE. */
701 make_restrict_type (struct type *type)
703 return make_qualified_type (type,
704 (TYPE_INSTANCE_FLAGS (type)
705 | TYPE_INSTANCE_FLAG_RESTRICT),
709 /* Replace the contents of ntype with the type *type. This changes the
710 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
711 the changes are propogated to all types in the TYPE_CHAIN.
713 In order to build recursive types, it's inevitable that we'll need
714 to update types in place --- but this sort of indiscriminate
715 smashing is ugly, and needs to be replaced with something more
716 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
717 clear if more steps are needed. */
720 replace_type (struct type *ntype, struct type *type)
724 /* These two types had better be in the same objfile. Otherwise,
725 the assignment of one type's main type structure to the other
726 will produce a type with references to objects (names; field
727 lists; etc.) allocated on an objfile other than its own. */
728 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
730 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
732 /* The type length is not a part of the main type. Update it for
733 each type on the variant chain. */
737 /* Assert that this element of the chain has no address-class bits
738 set in its flags. Such type variants might have type lengths
739 which are supposed to be different from the non-address-class
740 variants. This assertion shouldn't ever be triggered because
741 symbol readers which do construct address-class variants don't
742 call replace_type(). */
743 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
745 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
746 chain = TYPE_CHAIN (chain);
748 while (ntype != chain);
750 /* Assert that the two types have equivalent instance qualifiers.
751 This should be true for at least all of our debug readers. */
752 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
755 /* Implement direct support for MEMBER_TYPE in GNU C++.
756 May need to construct such a type if this is the first use.
757 The TYPE is the type of the member. The DOMAIN is the type
758 of the aggregate that the member belongs to. */
761 lookup_memberptr_type (struct type *type, struct type *domain)
765 mtype = alloc_type_copy (type);
766 smash_to_memberptr_type (mtype, domain, type);
770 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
773 lookup_methodptr_type (struct type *to_type)
777 mtype = alloc_type_copy (to_type);
778 smash_to_methodptr_type (mtype, to_type);
782 /* Allocate a stub method whose return type is TYPE. This apparently
783 happens for speed of symbol reading, since parsing out the
784 arguments to the method is cpu-intensive, the way we are doing it.
785 So, we will fill in arguments later. This always returns a fresh
789 allocate_stub_method (struct type *type)
793 mtype = alloc_type_copy (type);
794 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
795 TYPE_LENGTH (mtype) = 1;
796 TYPE_STUB (mtype) = 1;
797 TYPE_TARGET_TYPE (mtype) = type;
798 /* _DOMAIN_TYPE (mtype) = unknown yet */
802 /* Create a range type with a dynamic range from LOW_BOUND to
803 HIGH_BOUND, inclusive. See create_range_type for further details. */
806 create_range_type (struct type *result_type, struct type *index_type,
807 const struct dynamic_prop *low_bound,
808 const struct dynamic_prop *high_bound)
810 if (result_type == NULL)
811 result_type = alloc_type_copy (index_type);
812 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
813 TYPE_TARGET_TYPE (result_type) = index_type;
814 if (TYPE_STUB (index_type))
815 TYPE_TARGET_STUB (result_type) = 1;
817 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
819 TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
820 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
821 TYPE_RANGE_DATA (result_type)->low = *low_bound;
822 TYPE_RANGE_DATA (result_type)->high = *high_bound;
824 if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
825 TYPE_UNSIGNED (result_type) = 1;
830 /* Create a range type using either a blank type supplied in
831 RESULT_TYPE, or creating a new type, inheriting the objfile from
834 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
835 to HIGH_BOUND, inclusive.
837 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
838 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
841 create_static_range_type (struct type *result_type, struct type *index_type,
842 LONGEST low_bound, LONGEST high_bound)
844 struct dynamic_prop low, high;
846 low.kind = PROP_CONST;
847 low.data.const_val = low_bound;
849 high.kind = PROP_CONST;
850 high.data.const_val = high_bound;
852 result_type = create_range_type (result_type, index_type, &low, &high);
857 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
858 are static, otherwise returns 0. */
861 has_static_range (const struct range_bounds *bounds)
863 return (bounds->low.kind == PROP_CONST
864 && bounds->high.kind == PROP_CONST);
868 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
869 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
870 bounds will fit in LONGEST), or -1 otherwise. */
873 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
875 CHECK_TYPEDEF (type);
876 switch (TYPE_CODE (type))
878 case TYPE_CODE_RANGE:
879 *lowp = TYPE_LOW_BOUND (type);
880 *highp = TYPE_HIGH_BOUND (type);
883 if (TYPE_NFIELDS (type) > 0)
885 /* The enums may not be sorted by value, so search all
889 *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
890 for (i = 0; i < TYPE_NFIELDS (type); i++)
892 if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
893 *lowp = TYPE_FIELD_ENUMVAL (type, i);
894 if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
895 *highp = TYPE_FIELD_ENUMVAL (type, i);
898 /* Set unsigned indicator if warranted. */
901 TYPE_UNSIGNED (type) = 1;
915 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
917 if (!TYPE_UNSIGNED (type))
919 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
923 /* ... fall through for unsigned ints ... */
926 /* This round-about calculation is to avoid shifting by
927 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
928 if TYPE_LENGTH (type) == sizeof (LONGEST). */
929 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
930 *highp = (*highp - 1) | *highp;
937 /* Assuming TYPE is a simple, non-empty array type, compute its upper
938 and lower bound. Save the low bound into LOW_BOUND if not NULL.
939 Save the high bound into HIGH_BOUND if not NULL.
941 Return 1 if the operation was successful. Return zero otherwise,
942 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
944 We now simply use get_discrete_bounds call to get the values
945 of the low and high bounds.
946 get_discrete_bounds can return three values:
947 1, meaning that index is a range,
948 0, meaning that index is a discrete type,
949 or -1 for failure. */
952 get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
954 struct type *index = TYPE_INDEX_TYPE (type);
962 res = get_discrete_bounds (index, &low, &high);
966 /* Check if the array bounds are undefined. */
968 && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
969 || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
981 /* Create an array type using either a blank type supplied in
982 RESULT_TYPE, or creating a new type, inheriting the objfile from
985 Elements will be of type ELEMENT_TYPE, the indices will be of type
988 If BIT_STRIDE is not zero, build a packed array type whose element
989 size is BIT_STRIDE. Otherwise, ignore this parameter.
991 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
992 sure it is TYPE_CODE_UNDEF before we bash it into an array
996 create_array_type_with_stride (struct type *result_type,
997 struct type *element_type,
998 struct type *range_type,
999 unsigned int bit_stride)
1001 if (result_type == NULL)
1002 result_type = alloc_type_copy (range_type);
1004 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
1005 TYPE_TARGET_TYPE (result_type) = element_type;
1006 if (has_static_range (TYPE_RANGE_DATA (range_type)))
1008 LONGEST low_bound, high_bound;
1010 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
1011 low_bound = high_bound = 0;
1012 CHECK_TYPEDEF (element_type);
1013 /* Be careful when setting the array length. Ada arrays can be
1014 empty arrays with the high_bound being smaller than the low_bound.
1015 In such cases, the array length should be zero. */
1016 if (high_bound < low_bound)
1017 TYPE_LENGTH (result_type) = 0;
1018 else if (bit_stride > 0)
1019 TYPE_LENGTH (result_type) =
1020 (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
1022 TYPE_LENGTH (result_type) =
1023 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
1027 /* This type is dynamic and its length needs to be computed
1028 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1029 undefined by setting it to zero. Although we are not expected
1030 to trust TYPE_LENGTH in this case, setting the size to zero
1031 allows us to avoid allocating objects of random sizes in case
1032 we accidently do. */
1033 TYPE_LENGTH (result_type) = 0;
1036 TYPE_NFIELDS (result_type) = 1;
1037 TYPE_FIELDS (result_type) =
1038 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
1039 TYPE_INDEX_TYPE (result_type) = range_type;
1040 TYPE_VPTR_FIELDNO (result_type) = -1;
1042 TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride;
1044 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */
1045 if (TYPE_LENGTH (result_type) == 0)
1046 TYPE_TARGET_STUB (result_type) = 1;
1051 /* Same as create_array_type_with_stride but with no bit_stride
1052 (BIT_STRIDE = 0), thus building an unpacked array. */
1055 create_array_type (struct type *result_type,
1056 struct type *element_type,
1057 struct type *range_type)
1059 return create_array_type_with_stride (result_type, element_type,
1064 lookup_array_range_type (struct type *element_type,
1065 LONGEST low_bound, LONGEST high_bound)
1067 struct gdbarch *gdbarch = get_type_arch (element_type);
1068 struct type *index_type = builtin_type (gdbarch)->builtin_int;
1069 struct type *range_type
1070 = create_static_range_type (NULL, index_type, low_bound, high_bound);
1072 return create_array_type (NULL, element_type, range_type);
1075 /* Create a string type using either a blank type supplied in
1076 RESULT_TYPE, or creating a new type. String types are similar
1077 enough to array of char types that we can use create_array_type to
1078 build the basic type and then bash it into a string type.
1080 For fixed length strings, the range type contains 0 as the lower
1081 bound and the length of the string minus one as the upper bound.
1083 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1084 sure it is TYPE_CODE_UNDEF before we bash it into a string
1088 create_string_type (struct type *result_type,
1089 struct type *string_char_type,
1090 struct type *range_type)
1092 result_type = create_array_type (result_type,
1095 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1100 lookup_string_range_type (struct type *string_char_type,
1101 LONGEST low_bound, LONGEST high_bound)
1103 struct type *result_type;
1105 result_type = lookup_array_range_type (string_char_type,
1106 low_bound, high_bound);
1107 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1112 create_set_type (struct type *result_type, struct type *domain_type)
1114 if (result_type == NULL)
1115 result_type = alloc_type_copy (domain_type);
1117 TYPE_CODE (result_type) = TYPE_CODE_SET;
1118 TYPE_NFIELDS (result_type) = 1;
1119 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
1121 if (!TYPE_STUB (domain_type))
1123 LONGEST low_bound, high_bound, bit_length;
1125 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
1126 low_bound = high_bound = 0;
1127 bit_length = high_bound - low_bound + 1;
1128 TYPE_LENGTH (result_type)
1129 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1131 TYPE_UNSIGNED (result_type) = 1;
1133 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
1138 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1139 and any array types nested inside it. */
1142 make_vector_type (struct type *array_type)
1144 struct type *inner_array, *elt_type;
1147 /* Find the innermost array type, in case the array is
1148 multi-dimensional. */
1149 inner_array = array_type;
1150 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
1151 inner_array = TYPE_TARGET_TYPE (inner_array);
1153 elt_type = TYPE_TARGET_TYPE (inner_array);
1154 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
1156 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT;
1157 elt_type = make_qualified_type (elt_type, flags, NULL);
1158 TYPE_TARGET_TYPE (inner_array) = elt_type;
1161 TYPE_VECTOR (array_type) = 1;
1165 init_vector_type (struct type *elt_type, int n)
1167 struct type *array_type;
1169 array_type = lookup_array_range_type (elt_type, 0, n - 1);
1170 make_vector_type (array_type);
1174 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
1175 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1176 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1177 TYPE doesn't include the offset (that's the value of the MEMBER
1178 itself), but does include the structure type into which it points
1181 When "smashing" the type, we preserve the objfile that the old type
1182 pointed to, since we aren't changing where the type is actually
1186 smash_to_memberptr_type (struct type *type, struct type *domain,
1187 struct type *to_type)
1190 TYPE_TARGET_TYPE (type) = to_type;
1191 TYPE_DOMAIN_TYPE (type) = domain;
1192 /* Assume that a data member pointer is the same size as a normal
1195 = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT;
1196 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
1199 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1201 When "smashing" the type, we preserve the objfile that the old type
1202 pointed to, since we aren't changing where the type is actually
1206 smash_to_methodptr_type (struct type *type, struct type *to_type)
1209 TYPE_TARGET_TYPE (type) = to_type;
1210 TYPE_DOMAIN_TYPE (type) = TYPE_DOMAIN_TYPE (to_type);
1211 TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
1212 TYPE_CODE (type) = TYPE_CODE_METHODPTR;
1215 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1216 METHOD just means `function that gets an extra "this" argument'.
1218 When "smashing" the type, we preserve the objfile that the old type
1219 pointed to, since we aren't changing where the type is actually
1223 smash_to_method_type (struct type *type, struct type *domain,
1224 struct type *to_type, struct field *args,
1225 int nargs, int varargs)
1228 TYPE_TARGET_TYPE (type) = to_type;
1229 TYPE_DOMAIN_TYPE (type) = domain;
1230 TYPE_FIELDS (type) = args;
1231 TYPE_NFIELDS (type) = nargs;
1233 TYPE_VARARGS (type) = 1;
1234 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1235 TYPE_CODE (type) = TYPE_CODE_METHOD;
1238 /* Return a typename for a struct/union/enum type without "struct ",
1239 "union ", or "enum ". If the type has a NULL name, return NULL. */
1242 type_name_no_tag (const struct type *type)
1244 if (TYPE_TAG_NAME (type) != NULL)
1245 return TYPE_TAG_NAME (type);
1247 /* Is there code which expects this to return the name if there is
1248 no tag name? My guess is that this is mainly used for C++ in
1249 cases where the two will always be the same. */
1250 return TYPE_NAME (type);
1253 /* A wrapper of type_name_no_tag which calls error if the type is anonymous.
1254 Since GCC PR debug/47510 DWARF provides associated information to detect the
1255 anonymous class linkage name from its typedef.
1257 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1261 type_name_no_tag_or_error (struct type *type)
1263 struct type *saved_type = type;
1265 struct objfile *objfile;
1267 CHECK_TYPEDEF (type);
1269 name = type_name_no_tag (type);
1273 name = type_name_no_tag (saved_type);
1274 objfile = TYPE_OBJFILE (saved_type);
1275 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1276 name ? name : "<anonymous>",
1277 objfile ? objfile_name (objfile) : "<arch>");
1280 /* Lookup a typedef or primitive type named NAME, visible in lexical
1281 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1282 suitably defined. */
1285 lookup_typename (const struct language_defn *language,
1286 struct gdbarch *gdbarch, const char *name,
1287 const struct block *block, int noerr)
1292 sym = lookup_symbol (name, block, VAR_DOMAIN, 0);
1293 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1294 return SYMBOL_TYPE (sym);
1296 type = language_lookup_primitive_type_by_name (language, gdbarch, name);
1302 error (_("No type named %s."), name);
1306 lookup_unsigned_typename (const struct language_defn *language,
1307 struct gdbarch *gdbarch, const char *name)
1309 char *uns = alloca (strlen (name) + 10);
1311 strcpy (uns, "unsigned ");
1312 strcpy (uns + 9, name);
1313 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0);
1317 lookup_signed_typename (const struct language_defn *language,
1318 struct gdbarch *gdbarch, const char *name)
1321 char *uns = alloca (strlen (name) + 8);
1323 strcpy (uns, "signed ");
1324 strcpy (uns + 7, name);
1325 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1);
1326 /* If we don't find "signed FOO" just try again with plain "FOO". */
1329 return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0);
1332 /* Lookup a structure type named "struct NAME",
1333 visible in lexical block BLOCK. */
1336 lookup_struct (const char *name, const struct block *block)
1340 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1344 error (_("No struct type named %s."), name);
1346 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1348 error (_("This context has class, union or enum %s, not a struct."),
1351 return (SYMBOL_TYPE (sym));
1354 /* Lookup a union type named "union NAME",
1355 visible in lexical block BLOCK. */
1358 lookup_union (const char *name, const struct block *block)
1363 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1366 error (_("No union type named %s."), name);
1368 t = SYMBOL_TYPE (sym);
1370 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1373 /* If we get here, it's not a union. */
1374 error (_("This context has class, struct or enum %s, not a union."),
1378 /* Lookup an enum type named "enum NAME",
1379 visible in lexical block BLOCK. */
1382 lookup_enum (const char *name, const struct block *block)
1386 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1389 error (_("No enum type named %s."), name);
1391 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1393 error (_("This context has class, struct or union %s, not an enum."),
1396 return (SYMBOL_TYPE (sym));
1399 /* Lookup a template type named "template NAME<TYPE>",
1400 visible in lexical block BLOCK. */
1403 lookup_template_type (char *name, struct type *type,
1404 const struct block *block)
1407 char *nam = (char *)
1408 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1412 strcat (nam, TYPE_NAME (type));
1413 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1415 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0);
1419 error (_("No template type named %s."), name);
1421 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1423 error (_("This context has class, union or enum %s, not a struct."),
1426 return (SYMBOL_TYPE (sym));
1429 /* Given a type TYPE, lookup the type of the component of type named
1432 TYPE can be either a struct or union, or a pointer or reference to
1433 a struct or union. If it is a pointer or reference, its target
1434 type is automatically used. Thus '.' and '->' are interchangable,
1435 as specified for the definitions of the expression element types
1436 STRUCTOP_STRUCT and STRUCTOP_PTR.
1438 If NOERR is nonzero, return zero if NAME is not suitably defined.
1439 If NAME is the name of a baseclass type, return that type. */
1442 lookup_struct_elt_type (struct type *type, const char *name, int noerr)
1449 CHECK_TYPEDEF (type);
1450 if (TYPE_CODE (type) != TYPE_CODE_PTR
1451 && TYPE_CODE (type) != TYPE_CODE_REF)
1453 type = TYPE_TARGET_TYPE (type);
1456 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1457 && TYPE_CODE (type) != TYPE_CODE_UNION)
1459 typename = type_to_string (type);
1460 make_cleanup (xfree, typename);
1461 error (_("Type %s is not a structure or union type."), typename);
1465 /* FIXME: This change put in by Michael seems incorrect for the case
1466 where the structure tag name is the same as the member name.
1467 I.e. when doing "ptype bell->bar" for "struct foo { int bar; int
1468 foo; } bell;" Disabled by fnf. */
1472 typename = type_name_no_tag (type);
1473 if (typename != NULL && strcmp (typename, name) == 0)
1478 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1480 const char *t_field_name = TYPE_FIELD_NAME (type, i);
1482 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1484 return TYPE_FIELD_TYPE (type, i);
1486 else if (!t_field_name || *t_field_name == '\0')
1488 struct type *subtype
1489 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1);
1491 if (subtype != NULL)
1496 /* OK, it's not in this class. Recursively check the baseclasses. */
1497 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1501 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1513 typename = type_to_string (type);
1514 make_cleanup (xfree, typename);
1515 error (_("Type %s has no component named %s."), typename, name);
1518 /* Store in *MAX the largest number representable by unsigned integer type
1522 get_unsigned_type_max (struct type *type, ULONGEST *max)
1526 CHECK_TYPEDEF (type);
1527 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_UNSIGNED (type));
1528 gdb_assert (TYPE_LENGTH (type) <= sizeof (ULONGEST));
1530 /* Written this way to avoid overflow. */
1531 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1532 *max = ((((ULONGEST) 1 << (n - 1)) - 1) << 1) | 1;
1535 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1536 signed integer type TYPE. */
1539 get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max)
1543 CHECK_TYPEDEF (type);
1544 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && !TYPE_UNSIGNED (type));
1545 gdb_assert (TYPE_LENGTH (type) <= sizeof (LONGEST));
1547 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1548 *min = -((ULONGEST) 1 << (n - 1));
1549 *max = ((ULONGEST) 1 << (n - 1)) - 1;
1552 /* Lookup the vptr basetype/fieldno values for TYPE.
1553 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1554 vptr_fieldno. Also, if found and basetype is from the same objfile,
1556 If not found, return -1 and ignore BASETYPEP.
1557 Callers should be aware that in some cases (for example,
1558 the type or one of its baseclasses is a stub type and we are
1559 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1560 this function will not be able to find the
1561 virtual function table pointer, and vptr_fieldno will remain -1 and
1562 vptr_basetype will remain NULL or incomplete. */
1565 get_vptr_fieldno (struct type *type, struct type **basetypep)
1567 CHECK_TYPEDEF (type);
1569 if (TYPE_VPTR_FIELDNO (type) < 0)
1573 /* We must start at zero in case the first (and only) baseclass
1574 is virtual (and hence we cannot share the table pointer). */
1575 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1577 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1579 struct type *basetype;
1581 fieldno = get_vptr_fieldno (baseclass, &basetype);
1584 /* If the type comes from a different objfile we can't cache
1585 it, it may have a different lifetime. PR 2384 */
1586 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
1588 TYPE_VPTR_FIELDNO (type) = fieldno;
1589 TYPE_VPTR_BASETYPE (type) = basetype;
1592 *basetypep = basetype;
1603 *basetypep = TYPE_VPTR_BASETYPE (type);
1604 return TYPE_VPTR_FIELDNO (type);
1609 stub_noname_complaint (void)
1611 complaint (&symfile_complaints, _("stub type has NULL name"));
1614 /* See gdbtypes.h. */
1617 is_dynamic_type (struct type *type)
1619 type = check_typedef (type);
1621 if (TYPE_CODE (type) == TYPE_CODE_REF)
1622 type = check_typedef (TYPE_TARGET_TYPE (type));
1624 switch (TYPE_CODE (type))
1626 case TYPE_CODE_RANGE:
1627 return !has_static_range (TYPE_RANGE_DATA (type));
1629 case TYPE_CODE_ARRAY:
1631 gdb_assert (TYPE_NFIELDS (type) == 1);
1633 /* The array is dynamic if either the bounds are dynamic,
1634 or the elements it contains have a dynamic contents. */
1635 if (is_dynamic_type (TYPE_INDEX_TYPE (type)))
1637 return is_dynamic_type (TYPE_TARGET_TYPE (type));
1640 case TYPE_CODE_STRUCT:
1641 case TYPE_CODE_UNION:
1645 for (i = 0; i < TYPE_NFIELDS (type); ++i)
1646 if (!field_is_static (&TYPE_FIELD (type, i))
1647 && is_dynamic_type (TYPE_FIELD_TYPE (type, i)))
1656 static struct type *
1657 resolve_dynamic_range (struct type *dyn_range_type)
1660 struct type *static_range_type;
1661 const struct dynamic_prop *prop;
1662 const struct dwarf2_locexpr_baton *baton;
1663 struct dynamic_prop low_bound, high_bound;
1665 gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
1667 prop = &TYPE_RANGE_DATA (dyn_range_type)->low;
1668 if (dwarf2_evaluate_property (prop, &value))
1670 low_bound.kind = PROP_CONST;
1671 low_bound.data.const_val = value;
1675 low_bound.kind = PROP_UNDEFINED;
1676 low_bound.data.const_val = 0;
1679 prop = &TYPE_RANGE_DATA (dyn_range_type)->high;
1680 if (dwarf2_evaluate_property (prop, &value))
1682 high_bound.kind = PROP_CONST;
1683 high_bound.data.const_val = value;
1685 if (TYPE_RANGE_DATA (dyn_range_type)->flag_upper_bound_is_count)
1686 high_bound.data.const_val
1687 = low_bound.data.const_val + high_bound.data.const_val - 1;
1691 high_bound.kind = PROP_UNDEFINED;
1692 high_bound.data.const_val = 0;
1695 static_range_type = create_range_type (copy_type (dyn_range_type),
1696 TYPE_TARGET_TYPE (dyn_range_type),
1697 &low_bound, &high_bound);
1698 TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
1699 return static_range_type;
1702 /* Resolves dynamic bound values of an array type TYPE to static ones.
1703 ADDRESS might be needed to resolve the subrange bounds, it is the location
1704 of the associated array. */
1706 static struct type *
1707 resolve_dynamic_array (struct type *type)
1710 struct type *elt_type;
1711 struct type *range_type;
1712 struct type *ary_dim;
1714 gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY);
1717 range_type = check_typedef (TYPE_INDEX_TYPE (elt_type));
1718 range_type = resolve_dynamic_range (range_type);
1720 ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
1722 if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY)
1723 elt_type = resolve_dynamic_array (TYPE_TARGET_TYPE (type));
1725 elt_type = TYPE_TARGET_TYPE (type);
1727 return create_array_type (copy_type (type),
1732 /* Resolve dynamic bounds of members of the union TYPE to static
1735 static struct type *
1736 resolve_dynamic_union (struct type *type, CORE_ADDR addr)
1738 struct type *resolved_type;
1740 unsigned int max_len = 0;
1742 gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
1744 resolved_type = copy_type (type);
1745 TYPE_FIELDS (resolved_type)
1746 = TYPE_ALLOC (resolved_type,
1747 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1748 memcpy (TYPE_FIELDS (resolved_type),
1750 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1751 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
1755 if (field_is_static (&TYPE_FIELD (type, i)))
1758 t = resolve_dynamic_type (TYPE_FIELD_TYPE (resolved_type, i), addr);
1759 TYPE_FIELD_TYPE (resolved_type, i) = t;
1760 if (TYPE_LENGTH (t) > max_len)
1761 max_len = TYPE_LENGTH (t);
1764 TYPE_LENGTH (resolved_type) = max_len;
1765 return resolved_type;
1768 /* Resolve dynamic bounds of members of the struct TYPE to static
1771 static struct type *
1772 resolve_dynamic_struct (struct type *type, CORE_ADDR addr)
1774 struct type *resolved_type;
1776 int vla_field = TYPE_NFIELDS (type) - 1;
1778 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
1779 gdb_assert (TYPE_NFIELDS (type) > 0);
1781 resolved_type = copy_type (type);
1782 TYPE_FIELDS (resolved_type)
1783 = TYPE_ALLOC (resolved_type,
1784 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1785 memcpy (TYPE_FIELDS (resolved_type),
1787 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
1788 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
1792 if (field_is_static (&TYPE_FIELD (type, i)))
1795 t = resolve_dynamic_type (TYPE_FIELD_TYPE (resolved_type, i), addr);
1797 /* This is a bit odd. We do not support a VLA in any position
1798 of a struct except for the last. GCC does have an extension
1799 that allows a VLA in the middle of a structure, but the DWARF
1800 it emits is relatively useless to us, so we can't represent
1801 such a type properly -- and even if we could, we do not have
1802 enough information to redo structure layout anyway.
1803 Nevertheless, we check all the fields in case something odd
1804 slips through, since it's better to see an error than
1805 incorrect results. */
1806 if (t != TYPE_FIELD_TYPE (resolved_type, i)
1808 error (_("Attempt to resolve a variably-sized type which appears "
1809 "in the interior of a structure type"));
1811 TYPE_FIELD_TYPE (resolved_type, i) = t;
1814 /* Due to the above restrictions we can successfully compute
1815 the size of the resulting structure here, as the offset of
1816 the final field plus its size. */
1817 TYPE_LENGTH (resolved_type)
1818 = (TYPE_FIELD_BITPOS (resolved_type, vla_field) / TARGET_CHAR_BIT
1819 + TYPE_LENGTH (TYPE_FIELD_TYPE (resolved_type, vla_field)));
1820 return resolved_type;
1823 /* See gdbtypes.h */
1826 resolve_dynamic_type (struct type *type, CORE_ADDR addr)
1828 struct type *real_type = check_typedef (type);
1829 struct type *resolved_type = type;
1831 if (!is_dynamic_type (real_type))
1834 switch (TYPE_CODE (type))
1836 case TYPE_CODE_TYPEDEF:
1837 resolved_type = copy_type (type);
1838 TYPE_TARGET_TYPE (resolved_type)
1839 = resolve_dynamic_type (TYPE_TARGET_TYPE (type), addr);
1844 CORE_ADDR target_addr = read_memory_typed_address (addr, type);
1846 resolved_type = copy_type (type);
1847 TYPE_TARGET_TYPE (resolved_type)
1848 = resolve_dynamic_type (TYPE_TARGET_TYPE (type), target_addr);
1852 case TYPE_CODE_ARRAY:
1853 resolved_type = resolve_dynamic_array (type);
1856 case TYPE_CODE_RANGE:
1857 resolved_type = resolve_dynamic_range (type);
1860 case TYPE_CODE_UNION:
1861 resolved_type = resolve_dynamic_union (type, addr);
1864 case TYPE_CODE_STRUCT:
1865 resolved_type = resolve_dynamic_struct (type, addr);
1869 return resolved_type;
1872 /* Find the real type of TYPE. This function returns the real type,
1873 after removing all layers of typedefs, and completing opaque or stub
1874 types. Completion changes the TYPE argument, but stripping of
1877 Instance flags (e.g. const/volatile) are preserved as typedefs are
1878 stripped. If necessary a new qualified form of the underlying type
1881 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
1882 not been computed and we're either in the middle of reading symbols, or
1883 there was no name for the typedef in the debug info.
1885 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
1886 QUITs in the symbol reading code can also throw.
1887 Thus this function can throw an exception.
1889 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
1892 If this is a stubbed struct (i.e. declared as struct foo *), see if
1893 we can find a full definition in some other file. If so, copy this
1894 definition, so we can use it in future. There used to be a comment
1895 (but not any code) that if we don't find a full definition, we'd
1896 set a flag so we don't spend time in the future checking the same
1897 type. That would be a mistake, though--we might load in more
1898 symbols which contain a full definition for the type. */
1901 check_typedef (struct type *type)
1903 struct type *orig_type = type;
1904 /* While we're removing typedefs, we don't want to lose qualifiers.
1905 E.g., const/volatile. */
1906 int instance_flags = TYPE_INSTANCE_FLAGS (type);
1910 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1912 if (!TYPE_TARGET_TYPE (type))
1917 /* It is dangerous to call lookup_symbol if we are currently
1918 reading a symtab. Infinite recursion is one danger. */
1919 if (currently_reading_symtab)
1920 return make_qualified_type (type, instance_flags, NULL);
1922 name = type_name_no_tag (type);
1923 /* FIXME: shouldn't we separately check the TYPE_NAME and
1924 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1925 VAR_DOMAIN as appropriate? (this code was written before
1926 TYPE_NAME and TYPE_TAG_NAME were separate). */
1929 stub_noname_complaint ();
1930 return make_qualified_type (type, instance_flags, NULL);
1932 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1934 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1935 else /* TYPE_CODE_UNDEF */
1936 TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type));
1938 type = TYPE_TARGET_TYPE (type);
1940 /* Preserve the instance flags as we traverse down the typedef chain.
1942 Handling address spaces/classes is nasty, what do we do if there's a
1944 E.g., what if an outer typedef marks the type as class_1 and an inner
1945 typedef marks the type as class_2?
1946 This is the wrong place to do such error checking. We leave it to
1947 the code that created the typedef in the first place to flag the
1948 error. We just pick the outer address space (akin to letting the
1949 outer cast in a chain of casting win), instead of assuming
1950 "it can't happen". */
1952 const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE
1953 | TYPE_INSTANCE_FLAG_DATA_SPACE);
1954 const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
1955 int new_instance_flags = TYPE_INSTANCE_FLAGS (type);
1957 /* Treat code vs data spaces and address classes separately. */
1958 if ((instance_flags & ALL_SPACES) != 0)
1959 new_instance_flags &= ~ALL_SPACES;
1960 if ((instance_flags & ALL_CLASSES) != 0)
1961 new_instance_flags &= ~ALL_CLASSES;
1963 instance_flags |= new_instance_flags;
1967 /* If this is a struct/class/union with no fields, then check
1968 whether a full definition exists somewhere else. This is for
1969 systems where a type definition with no fields is issued for such
1970 types, instead of identifying them as stub types in the first
1973 if (TYPE_IS_OPAQUE (type)
1974 && opaque_type_resolution
1975 && !currently_reading_symtab)
1977 const char *name = type_name_no_tag (type);
1978 struct type *newtype;
1982 stub_noname_complaint ();
1983 return make_qualified_type (type, instance_flags, NULL);
1985 newtype = lookup_transparent_type (name);
1989 /* If the resolved type and the stub are in the same
1990 objfile, then replace the stub type with the real deal.
1991 But if they're in separate objfiles, leave the stub
1992 alone; we'll just look up the transparent type every time
1993 we call check_typedef. We can't create pointers between
1994 types allocated to different objfiles, since they may
1995 have different lifetimes. Trying to copy NEWTYPE over to
1996 TYPE's objfile is pointless, too, since you'll have to
1997 move over any other types NEWTYPE refers to, which could
1998 be an unbounded amount of stuff. */
1999 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
2000 type = make_qualified_type (newtype,
2001 TYPE_INSTANCE_FLAGS (type),
2007 /* Otherwise, rely on the stub flag being set for opaque/stubbed
2009 else if (TYPE_STUB (type) && !currently_reading_symtab)
2011 const char *name = type_name_no_tag (type);
2012 /* FIXME: shouldn't we separately check the TYPE_NAME and the
2013 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
2014 as appropriate? (this code was written before TYPE_NAME and
2015 TYPE_TAG_NAME were separate). */
2020 stub_noname_complaint ();
2021 return make_qualified_type (type, instance_flags, NULL);
2023 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
2026 /* Same as above for opaque types, we can replace the stub
2027 with the complete type only if they are in the same
2029 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
2030 type = make_qualified_type (SYMBOL_TYPE (sym),
2031 TYPE_INSTANCE_FLAGS (type),
2034 type = SYMBOL_TYPE (sym);
2038 if (TYPE_TARGET_STUB (type))
2040 struct type *range_type;
2041 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
2043 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
2045 /* Nothing we can do. */
2047 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
2049 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
2050 TYPE_TARGET_STUB (type) = 0;
2054 type = make_qualified_type (type, instance_flags, NULL);
2056 /* Cache TYPE_LENGTH for future use. */
2057 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
2062 /* Parse a type expression in the string [P..P+LENGTH). If an error
2063 occurs, silently return a void type. */
2065 static struct type *
2066 safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
2068 struct ui_file *saved_gdb_stderr;
2069 struct type *type = NULL; /* Initialize to keep gcc happy. */
2070 volatile struct gdb_exception except;
2072 /* Suppress error messages. */
2073 saved_gdb_stderr = gdb_stderr;
2074 gdb_stderr = ui_file_new ();
2076 /* Call parse_and_eval_type() without fear of longjmp()s. */
2077 TRY_CATCH (except, RETURN_MASK_ERROR)
2079 type = parse_and_eval_type (p, length);
2082 if (except.reason < 0)
2083 type = builtin_type (gdbarch)->builtin_void;
2085 /* Stop suppressing error messages. */
2086 ui_file_delete (gdb_stderr);
2087 gdb_stderr = saved_gdb_stderr;
2092 /* Ugly hack to convert method stubs into method types.
2094 He ain't kiddin'. This demangles the name of the method into a
2095 string including argument types, parses out each argument type,
2096 generates a string casting a zero to that type, evaluates the
2097 string, and stuffs the resulting type into an argtype vector!!!
2098 Then it knows the type of the whole function (including argument
2099 types for overloading), which info used to be in the stab's but was
2100 removed to hack back the space required for them. */
2103 check_stub_method (struct type *type, int method_id, int signature_id)
2105 struct gdbarch *gdbarch = get_type_arch (type);
2107 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
2108 char *demangled_name = gdb_demangle (mangled_name,
2109 DMGL_PARAMS | DMGL_ANSI);
2110 char *argtypetext, *p;
2111 int depth = 0, argcount = 1;
2112 struct field *argtypes;
2115 /* Make sure we got back a function string that we can use. */
2117 p = strchr (demangled_name, '(');
2121 if (demangled_name == NULL || p == NULL)
2122 error (_("Internal: Cannot demangle mangled name `%s'."),
2125 /* Now, read in the parameters that define this type. */
2130 if (*p == '(' || *p == '<')
2134 else if (*p == ')' || *p == '>')
2138 else if (*p == ',' && depth == 0)
2146 /* If we read one argument and it was ``void'', don't count it. */
2147 if (strncmp (argtypetext, "(void)", 6) == 0)
2150 /* We need one extra slot, for the THIS pointer. */
2152 argtypes = (struct field *)
2153 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
2156 /* Add THIS pointer for non-static methods. */
2157 f = TYPE_FN_FIELDLIST1 (type, method_id);
2158 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
2162 argtypes[0].type = lookup_pointer_type (type);
2166 if (*p != ')') /* () means no args, skip while. */
2171 if (depth <= 0 && (*p == ',' || *p == ')'))
2173 /* Avoid parsing of ellipsis, they will be handled below.
2174 Also avoid ``void'' as above. */
2175 if (strncmp (argtypetext, "...", p - argtypetext) != 0
2176 && strncmp (argtypetext, "void", p - argtypetext) != 0)
2178 argtypes[argcount].type =
2179 safe_parse_type (gdbarch, argtypetext, p - argtypetext);
2182 argtypetext = p + 1;
2185 if (*p == '(' || *p == '<')
2189 else if (*p == ')' || *p == '>')
2198 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
2200 /* Now update the old "stub" type into a real type. */
2201 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
2202 TYPE_DOMAIN_TYPE (mtype) = type;
2203 TYPE_FIELDS (mtype) = argtypes;
2204 TYPE_NFIELDS (mtype) = argcount;
2205 TYPE_STUB (mtype) = 0;
2206 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
2208 TYPE_VARARGS (mtype) = 1;
2210 xfree (demangled_name);
2213 /* This is the external interface to check_stub_method, above. This
2214 function unstubs all of the signatures for TYPE's METHOD_ID method
2215 name. After calling this function TYPE_FN_FIELD_STUB will be
2216 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
2219 This function unfortunately can not die until stabs do. */
2222 check_stub_method_group (struct type *type, int method_id)
2224 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
2225 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
2226 int j, found_stub = 0;
2228 for (j = 0; j < len; j++)
2229 if (TYPE_FN_FIELD_STUB (f, j))
2232 check_stub_method (type, method_id, j);
2235 /* GNU v3 methods with incorrect names were corrected when we read
2236 in type information, because it was cheaper to do it then. The
2237 only GNU v2 methods with incorrect method names are operators and
2238 destructors; destructors were also corrected when we read in type
2241 Therefore the only thing we need to handle here are v2 operator
2243 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
2246 char dem_opname[256];
2248 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2250 dem_opname, DMGL_ANSI);
2252 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2256 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
2260 /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
2261 const struct cplus_struct_type cplus_struct_default = { };
2264 allocate_cplus_struct_type (struct type *type)
2266 if (HAVE_CPLUS_STRUCT (type))
2267 /* Structure was already allocated. Nothing more to do. */
2270 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF;
2271 TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
2272 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
2273 *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default;
2276 const struct gnat_aux_type gnat_aux_default =
2279 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
2280 and allocate the associated gnat-specific data. The gnat-specific
2281 data is also initialized to gnat_aux_default. */
2284 allocate_gnat_aux_type (struct type *type)
2286 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF;
2287 TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *)
2288 TYPE_ALLOC (type, sizeof (struct gnat_aux_type));
2289 *(TYPE_GNAT_SPECIFIC (type)) = gnat_aux_default;
2292 /* Helper function to initialize the standard scalar types.
2294 If NAME is non-NULL, then it is used to initialize the type name.
2295 Note that NAME is not copied; it is required to have a lifetime at
2296 least as long as OBJFILE. */
2299 init_type (enum type_code code, int length, int flags,
2300 const char *name, struct objfile *objfile)
2304 type = alloc_type (objfile);
2305 TYPE_CODE (type) = code;
2306 TYPE_LENGTH (type) = length;
2308 gdb_assert (!(flags & (TYPE_FLAG_MIN - 1)));
2309 if (flags & TYPE_FLAG_UNSIGNED)
2310 TYPE_UNSIGNED (type) = 1;
2311 if (flags & TYPE_FLAG_NOSIGN)
2312 TYPE_NOSIGN (type) = 1;
2313 if (flags & TYPE_FLAG_STUB)
2314 TYPE_STUB (type) = 1;
2315 if (flags & TYPE_FLAG_TARGET_STUB)
2316 TYPE_TARGET_STUB (type) = 1;
2317 if (flags & TYPE_FLAG_STATIC)
2318 TYPE_STATIC (type) = 1;
2319 if (flags & TYPE_FLAG_PROTOTYPED)
2320 TYPE_PROTOTYPED (type) = 1;
2321 if (flags & TYPE_FLAG_INCOMPLETE)
2322 TYPE_INCOMPLETE (type) = 1;
2323 if (flags & TYPE_FLAG_VARARGS)
2324 TYPE_VARARGS (type) = 1;
2325 if (flags & TYPE_FLAG_VECTOR)
2326 TYPE_VECTOR (type) = 1;
2327 if (flags & TYPE_FLAG_STUB_SUPPORTED)
2328 TYPE_STUB_SUPPORTED (type) = 1;
2329 if (flags & TYPE_FLAG_FIXED_INSTANCE)
2330 TYPE_FIXED_INSTANCE (type) = 1;
2331 if (flags & TYPE_FLAG_GNU_IFUNC)
2332 TYPE_GNU_IFUNC (type) = 1;
2334 TYPE_NAME (type) = name;
2338 if (name && strcmp (name, "char") == 0)
2339 TYPE_NOSIGN (type) = 1;
2343 case TYPE_CODE_STRUCT:
2344 case TYPE_CODE_UNION:
2345 case TYPE_CODE_NAMESPACE:
2346 INIT_CPLUS_SPECIFIC (type);
2349 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT;
2351 case TYPE_CODE_FUNC:
2352 INIT_FUNC_SPECIFIC (type);
2358 /* Queries on types. */
2361 can_dereference (struct type *t)
2363 /* FIXME: Should we return true for references as well as
2368 && TYPE_CODE (t) == TYPE_CODE_PTR
2369 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
2373 is_integral_type (struct type *t)
2378 && ((TYPE_CODE (t) == TYPE_CODE_INT)
2379 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
2380 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
2381 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
2382 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
2383 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
2386 /* Return true if TYPE is scalar. */
2389 is_scalar_type (struct type *type)
2391 CHECK_TYPEDEF (type);
2393 switch (TYPE_CODE (type))
2395 case TYPE_CODE_ARRAY:
2396 case TYPE_CODE_STRUCT:
2397 case TYPE_CODE_UNION:
2399 case TYPE_CODE_STRING:
2406 /* Return true if T is scalar, or a composite type which in practice has
2407 the memory layout of a scalar type. E.g., an array or struct with only
2408 one scalar element inside it, or a union with only scalar elements. */
2411 is_scalar_type_recursive (struct type *t)
2415 if (is_scalar_type (t))
2417 /* Are we dealing with an array or string of known dimensions? */
2418 else if ((TYPE_CODE (t) == TYPE_CODE_ARRAY
2419 || TYPE_CODE (t) == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1
2420 && TYPE_CODE (TYPE_INDEX_TYPE (t)) == TYPE_CODE_RANGE)
2422 LONGEST low_bound, high_bound;
2423 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (t));
2425 get_discrete_bounds (TYPE_INDEX_TYPE (t), &low_bound, &high_bound);
2427 return high_bound == low_bound && is_scalar_type_recursive (elt_type);
2429 /* Are we dealing with a struct with one element? */
2430 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1)
2431 return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0));
2432 else if (TYPE_CODE (t) == TYPE_CODE_UNION)
2434 int i, n = TYPE_NFIELDS (t);
2436 /* If all elements of the union are scalar, then the union is scalar. */
2437 for (i = 0; i < n; i++)
2438 if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t, i)))
2447 /* A helper function which returns true if types A and B represent the
2448 "same" class type. This is true if the types have the same main
2449 type, or the same name. */
2452 class_types_same_p (const struct type *a, const struct type *b)
2454 return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b)
2455 || (TYPE_NAME (a) && TYPE_NAME (b)
2456 && !strcmp (TYPE_NAME (a), TYPE_NAME (b))));
2459 /* If BASE is an ancestor of DCLASS return the distance between them.
2460 otherwise return -1;
2464 class B: public A {};
2465 class C: public B {};
2468 distance_to_ancestor (A, A, 0) = 0
2469 distance_to_ancestor (A, B, 0) = 1
2470 distance_to_ancestor (A, C, 0) = 2
2471 distance_to_ancestor (A, D, 0) = 3
2473 If PUBLIC is 1 then only public ancestors are considered,
2474 and the function returns the distance only if BASE is a public ancestor
2478 distance_to_ancestor (A, D, 1) = -1. */
2481 distance_to_ancestor (struct type *base, struct type *dclass, int public)
2486 CHECK_TYPEDEF (base);
2487 CHECK_TYPEDEF (dclass);
2489 if (class_types_same_p (base, dclass))
2492 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2494 if (public && ! BASETYPE_VIA_PUBLIC (dclass, i))
2497 d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), public);
2505 /* Check whether BASE is an ancestor or base class or DCLASS
2506 Return 1 if so, and 0 if not.
2507 Note: If BASE and DCLASS are of the same type, this function
2508 will return 1. So for some class A, is_ancestor (A, A) will
2512 is_ancestor (struct type *base, struct type *dclass)
2514 return distance_to_ancestor (base, dclass, 0) >= 0;
2517 /* Like is_ancestor, but only returns true when BASE is a public
2518 ancestor of DCLASS. */
2521 is_public_ancestor (struct type *base, struct type *dclass)
2523 return distance_to_ancestor (base, dclass, 1) >= 0;
2526 /* A helper function for is_unique_ancestor. */
2529 is_unique_ancestor_worker (struct type *base, struct type *dclass,
2531 const gdb_byte *valaddr, int embedded_offset,
2532 CORE_ADDR address, struct value *val)
2536 CHECK_TYPEDEF (base);
2537 CHECK_TYPEDEF (dclass);
2539 for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
2544 iter = check_typedef (TYPE_BASECLASS (dclass, i));
2546 this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset,
2549 if (class_types_same_p (base, iter))
2551 /* If this is the first subclass, set *OFFSET and set count
2552 to 1. Otherwise, if this is at the same offset as
2553 previous instances, do nothing. Otherwise, increment
2557 *offset = this_offset;
2560 else if (this_offset == *offset)
2568 count += is_unique_ancestor_worker (base, iter, offset,
2570 embedded_offset + this_offset,
2577 /* Like is_ancestor, but only returns true if BASE is a unique base
2578 class of the type of VAL. */
2581 is_unique_ancestor (struct type *base, struct value *val)
2585 return is_unique_ancestor_worker (base, value_type (val), &offset,
2586 value_contents_for_printing (val),
2587 value_embedded_offset (val),
2588 value_address (val), val) == 1;
2592 /* Overload resolution. */
2594 /* Return the sum of the rank of A with the rank of B. */
2597 sum_ranks (struct rank a, struct rank b)
2600 c.rank = a.rank + b.rank;
2601 c.subrank = a.subrank + b.subrank;
2605 /* Compare rank A and B and return:
2607 1 if a is better than b
2608 -1 if b is better than a. */
2611 compare_ranks (struct rank a, struct rank b)
2613 if (a.rank == b.rank)
2615 if (a.subrank == b.subrank)
2617 if (a.subrank < b.subrank)
2619 if (a.subrank > b.subrank)
2623 if (a.rank < b.rank)
2626 /* a.rank > b.rank */
2630 /* Functions for overload resolution begin here. */
2632 /* Compare two badness vectors A and B and return the result.
2633 0 => A and B are identical
2634 1 => A and B are incomparable
2635 2 => A is better than B
2636 3 => A is worse than B */
2639 compare_badness (struct badness_vector *a, struct badness_vector *b)
2643 short found_pos = 0; /* any positives in c? */
2644 short found_neg = 0; /* any negatives in c? */
2646 /* differing lengths => incomparable */
2647 if (a->length != b->length)
2650 /* Subtract b from a */
2651 for (i = 0; i < a->length; i++)
2653 tmp = compare_ranks (b->rank[i], a->rank[i]);
2663 return 1; /* incomparable */
2665 return 3; /* A > B */
2671 return 2; /* A < B */
2673 return 0; /* A == B */
2677 /* Rank a function by comparing its parameter types (PARMS, length
2678 NPARMS), to the types of an argument list (ARGS, length NARGS).
2679 Return a pointer to a badness vector. This has NARGS + 1
2682 struct badness_vector *
2683 rank_function (struct type **parms, int nparms,
2684 struct value **args, int nargs)
2687 struct badness_vector *bv;
2688 int min_len = nparms < nargs ? nparms : nargs;
2690 bv = xmalloc (sizeof (struct badness_vector));
2691 bv->length = nargs + 1; /* add 1 for the length-match rank. */
2692 bv->rank = XNEWVEC (struct rank, nargs + 1);
2694 /* First compare the lengths of the supplied lists.
2695 If there is a mismatch, set it to a high value. */
2697 /* pai/1997-06-03 FIXME: when we have debug info about default
2698 arguments and ellipsis parameter lists, we should consider those
2699 and rank the length-match more finely. */
2701 LENGTH_MATCH (bv) = (nargs != nparms)
2702 ? LENGTH_MISMATCH_BADNESS
2703 : EXACT_MATCH_BADNESS;
2705 /* Now rank all the parameters of the candidate function. */
2706 for (i = 1; i <= min_len; i++)
2707 bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]),
2710 /* If more arguments than parameters, add dummy entries. */
2711 for (i = min_len + 1; i <= nargs; i++)
2712 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2717 /* Compare the names of two integer types, assuming that any sign
2718 qualifiers have been checked already. We do it this way because
2719 there may be an "int" in the name of one of the types. */
2722 integer_types_same_name_p (const char *first, const char *second)
2724 int first_p, second_p;
2726 /* If both are shorts, return 1; if neither is a short, keep
2728 first_p = (strstr (first, "short") != NULL);
2729 second_p = (strstr (second, "short") != NULL);
2730 if (first_p && second_p)
2732 if (first_p || second_p)
2735 /* Likewise for long. */
2736 first_p = (strstr (first, "long") != NULL);
2737 second_p = (strstr (second, "long") != NULL);
2738 if (first_p && second_p)
2740 if (first_p || second_p)
2743 /* Likewise for char. */
2744 first_p = (strstr (first, "char") != NULL);
2745 second_p = (strstr (second, "char") != NULL);
2746 if (first_p && second_p)
2748 if (first_p || second_p)
2751 /* They must both be ints. */
2755 /* Compares type A to type B returns 1 if the represent the same type
2759 types_equal (struct type *a, struct type *b)
2761 /* Identical type pointers. */
2762 /* However, this still doesn't catch all cases of same type for b
2763 and a. The reason is that builtin types are different from
2764 the same ones constructed from the object. */
2768 /* Resolve typedefs */
2769 if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF)
2770 a = check_typedef (a);
2771 if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF)
2772 b = check_typedef (b);
2774 /* If after resolving typedefs a and b are not of the same type
2775 code then they are not equal. */
2776 if (TYPE_CODE (a) != TYPE_CODE (b))
2779 /* If a and b are both pointers types or both reference types then
2780 they are equal of the same type iff the objects they refer to are
2781 of the same type. */
2782 if (TYPE_CODE (a) == TYPE_CODE_PTR
2783 || TYPE_CODE (a) == TYPE_CODE_REF)
2784 return types_equal (TYPE_TARGET_TYPE (a),
2785 TYPE_TARGET_TYPE (b));
2787 /* Well, damnit, if the names are exactly the same, I'll say they
2788 are exactly the same. This happens when we generate method
2789 stubs. The types won't point to the same address, but they
2790 really are the same. */
2792 if (TYPE_NAME (a) && TYPE_NAME (b)
2793 && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0)
2796 /* Check if identical after resolving typedefs. */
2800 /* Two function types are equal if their argument and return types
2802 if (TYPE_CODE (a) == TYPE_CODE_FUNC)
2806 if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
2809 if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
2812 for (i = 0; i < TYPE_NFIELDS (a); ++i)
2813 if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
2822 /* Deep comparison of types. */
2824 /* An entry in the type-equality bcache. */
2826 typedef struct type_equality_entry
2828 struct type *type1, *type2;
2829 } type_equality_entry_d;
2831 DEF_VEC_O (type_equality_entry_d);
2833 /* A helper function to compare two strings. Returns 1 if they are
2834 the same, 0 otherwise. Handles NULLs properly. */
2837 compare_maybe_null_strings (const char *s, const char *t)
2839 if (s == NULL && t != NULL)
2841 else if (s != NULL && t == NULL)
2843 else if (s == NULL && t== NULL)
2845 return strcmp (s, t) == 0;
2848 /* A helper function for check_types_worklist that checks two types for
2849 "deep" equality. Returns non-zero if the types are considered the
2850 same, zero otherwise. */
2853 check_types_equal (struct type *type1, struct type *type2,
2854 VEC (type_equality_entry_d) **worklist)
2856 CHECK_TYPEDEF (type1);
2857 CHECK_TYPEDEF (type2);
2862 if (TYPE_CODE (type1) != TYPE_CODE (type2)
2863 || TYPE_LENGTH (type1) != TYPE_LENGTH (type2)
2864 || TYPE_UNSIGNED (type1) != TYPE_UNSIGNED (type2)
2865 || TYPE_NOSIGN (type1) != TYPE_NOSIGN (type2)
2866 || TYPE_VARARGS (type1) != TYPE_VARARGS (type2)
2867 || TYPE_VECTOR (type1) != TYPE_VECTOR (type2)
2868 || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2)
2869 || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2)
2870 || TYPE_NFIELDS (type1) != TYPE_NFIELDS (type2))
2873 if (!compare_maybe_null_strings (TYPE_TAG_NAME (type1),
2874 TYPE_TAG_NAME (type2)))
2876 if (!compare_maybe_null_strings (TYPE_NAME (type1), TYPE_NAME (type2)))
2879 if (TYPE_CODE (type1) == TYPE_CODE_RANGE)
2881 if (memcmp (TYPE_RANGE_DATA (type1), TYPE_RANGE_DATA (type2),
2882 sizeof (*TYPE_RANGE_DATA (type1))) != 0)
2889 for (i = 0; i < TYPE_NFIELDS (type1); ++i)
2891 const struct field *field1 = &TYPE_FIELD (type1, i);
2892 const struct field *field2 = &TYPE_FIELD (type2, i);
2893 struct type_equality_entry entry;
2895 if (FIELD_ARTIFICIAL (*field1) != FIELD_ARTIFICIAL (*field2)
2896 || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2)
2897 || FIELD_LOC_KIND (*field1) != FIELD_LOC_KIND (*field2))
2899 if (!compare_maybe_null_strings (FIELD_NAME (*field1),
2900 FIELD_NAME (*field2)))
2902 switch (FIELD_LOC_KIND (*field1))
2904 case FIELD_LOC_KIND_BITPOS:
2905 if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2))
2908 case FIELD_LOC_KIND_ENUMVAL:
2909 if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2))
2912 case FIELD_LOC_KIND_PHYSADDR:
2913 if (FIELD_STATIC_PHYSADDR (*field1)
2914 != FIELD_STATIC_PHYSADDR (*field2))
2917 case FIELD_LOC_KIND_PHYSNAME:
2918 if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1),
2919 FIELD_STATIC_PHYSNAME (*field2)))
2922 case FIELD_LOC_KIND_DWARF_BLOCK:
2924 struct dwarf2_locexpr_baton *block1, *block2;
2926 block1 = FIELD_DWARF_BLOCK (*field1);
2927 block2 = FIELD_DWARF_BLOCK (*field2);
2928 if (block1->per_cu != block2->per_cu
2929 || block1->size != block2->size
2930 || memcmp (block1->data, block2->data, block1->size) != 0)
2935 internal_error (__FILE__, __LINE__, _("Unsupported field kind "
2936 "%d by check_types_equal"),
2937 FIELD_LOC_KIND (*field1));
2940 entry.type1 = FIELD_TYPE (*field1);
2941 entry.type2 = FIELD_TYPE (*field2);
2942 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
2946 if (TYPE_TARGET_TYPE (type1) != NULL)
2948 struct type_equality_entry entry;
2950 if (TYPE_TARGET_TYPE (type2) == NULL)
2953 entry.type1 = TYPE_TARGET_TYPE (type1);
2954 entry.type2 = TYPE_TARGET_TYPE (type2);
2955 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
2957 else if (TYPE_TARGET_TYPE (type2) != NULL)
2963 /* Check types on a worklist for equality. Returns zero if any pair
2964 is not equal, non-zero if they are all considered equal. */
2967 check_types_worklist (VEC (type_equality_entry_d) **worklist,
2968 struct bcache *cache)
2970 while (!VEC_empty (type_equality_entry_d, *worklist))
2972 struct type_equality_entry entry;
2975 entry = *VEC_last (type_equality_entry_d, *worklist);
2976 VEC_pop (type_equality_entry_d, *worklist);
2978 /* If the type pair has already been visited, we know it is
2980 bcache_full (&entry, sizeof (entry), cache, &added);
2984 if (check_types_equal (entry.type1, entry.type2, worklist) == 0)
2991 /* Return non-zero if types TYPE1 and TYPE2 are equal, as determined by a
2992 "deep comparison". Otherwise return zero. */
2995 types_deeply_equal (struct type *type1, struct type *type2)
2997 volatile struct gdb_exception except;
2999 struct bcache *cache;
3000 VEC (type_equality_entry_d) *worklist = NULL;
3001 struct type_equality_entry entry;
3003 gdb_assert (type1 != NULL && type2 != NULL);
3005 /* Early exit for the simple case. */
3009 cache = bcache_xmalloc (NULL, NULL);
3011 entry.type1 = type1;
3012 entry.type2 = type2;
3013 VEC_safe_push (type_equality_entry_d, worklist, &entry);
3015 TRY_CATCH (except, RETURN_MASK_ALL)
3017 result = check_types_worklist (&worklist, cache);
3019 /* check_types_worklist calls several nested helper functions,
3020 some of which can raise a GDB Exception, so we just check
3021 and rethrow here. If there is a GDB exception, a comparison
3022 is not capable (or trusted), so exit. */
3023 bcache_xfree (cache);
3024 VEC_free (type_equality_entry_d, worklist);
3025 /* Rethrow if there was a problem. */
3026 if (except.reason < 0)
3027 throw_exception (except);
3032 /* Compare one type (PARM) for compatibility with another (ARG).
3033 * PARM is intended to be the parameter type of a function; and
3034 * ARG is the supplied argument's type. This function tests if
3035 * the latter can be converted to the former.
3036 * VALUE is the argument's value or NULL if none (or called recursively)
3038 * Return 0 if they are identical types;
3039 * Otherwise, return an integer which corresponds to how compatible
3040 * PARM is to ARG. The higher the return value, the worse the match.
3041 * Generally the "bad" conversions are all uniformly assigned a 100. */
3044 rank_one_type (struct type *parm, struct type *arg, struct value *value)
3046 struct rank rank = {0,0};
3048 if (types_equal (parm, arg))
3049 return EXACT_MATCH_BADNESS;
3051 /* Resolve typedefs */
3052 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
3053 parm = check_typedef (parm);
3054 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
3055 arg = check_typedef (arg);
3057 /* See through references, since we can almost make non-references
3059 if (TYPE_CODE (arg) == TYPE_CODE_REF)
3060 return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
3061 REFERENCE_CONVERSION_BADNESS));
3062 if (TYPE_CODE (parm) == TYPE_CODE_REF)
3063 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
3064 REFERENCE_CONVERSION_BADNESS));
3066 /* Debugging only. */
3067 fprintf_filtered (gdb_stderr,
3068 "------ Arg is %s [%d], parm is %s [%d]\n",
3069 TYPE_NAME (arg), TYPE_CODE (arg),
3070 TYPE_NAME (parm), TYPE_CODE (parm));
3072 /* x -> y means arg of type x being supplied for parameter of type y. */
3074 switch (TYPE_CODE (parm))
3077 switch (TYPE_CODE (arg))
3081 /* Allowed pointer conversions are:
3082 (a) pointer to void-pointer conversion. */
3083 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
3084 return VOID_PTR_CONVERSION_BADNESS;
3086 /* (b) pointer to ancestor-pointer conversion. */
3087 rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
3088 TYPE_TARGET_TYPE (arg),
3090 if (rank.subrank >= 0)
3091 return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
3093 return INCOMPATIBLE_TYPE_BADNESS;
3094 case TYPE_CODE_ARRAY:
3095 if (types_equal (TYPE_TARGET_TYPE (parm),
3096 TYPE_TARGET_TYPE (arg)))
3097 return EXACT_MATCH_BADNESS;
3098 return INCOMPATIBLE_TYPE_BADNESS;
3099 case TYPE_CODE_FUNC:
3100 return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
3102 if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
3104 if (value_as_long (value) == 0)
3106 /* Null pointer conversion: allow it to be cast to a pointer.
3107 [4.10.1 of C++ standard draft n3290] */
3108 return NULL_POINTER_CONVERSION_BADNESS;
3112 /* If type checking is disabled, allow the conversion. */
3113 if (!strict_type_checking)
3114 return NS_INTEGER_POINTER_CONVERSION_BADNESS;
3118 case TYPE_CODE_ENUM:
3119 case TYPE_CODE_FLAGS:
3120 case TYPE_CODE_CHAR:
3121 case TYPE_CODE_RANGE:
3122 case TYPE_CODE_BOOL:
3124 return INCOMPATIBLE_TYPE_BADNESS;
3126 case TYPE_CODE_ARRAY:
3127 switch (TYPE_CODE (arg))
3130 case TYPE_CODE_ARRAY:
3131 return rank_one_type (TYPE_TARGET_TYPE (parm),
3132 TYPE_TARGET_TYPE (arg), NULL);
3134 return INCOMPATIBLE_TYPE_BADNESS;
3136 case TYPE_CODE_FUNC:
3137 switch (TYPE_CODE (arg))
3139 case TYPE_CODE_PTR: /* funcptr -> func */
3140 return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
3142 return INCOMPATIBLE_TYPE_BADNESS;
3145 switch (TYPE_CODE (arg))
3148 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3150 /* Deal with signed, unsigned, and plain chars and
3151 signed and unsigned ints. */
3152 if (TYPE_NOSIGN (parm))
3154 /* This case only for character types. */
3155 if (TYPE_NOSIGN (arg))
3156 return EXACT_MATCH_BADNESS; /* plain char -> plain char */
3157 else /* signed/unsigned char -> plain char */
3158 return INTEGER_CONVERSION_BADNESS;
3160 else if (TYPE_UNSIGNED (parm))
3162 if (TYPE_UNSIGNED (arg))
3164 /* unsigned int -> unsigned int, or
3165 unsigned long -> unsigned long */
3166 if (integer_types_same_name_p (TYPE_NAME (parm),
3168 return EXACT_MATCH_BADNESS;
3169 else if (integer_types_same_name_p (TYPE_NAME (arg),
3171 && integer_types_same_name_p (TYPE_NAME (parm),
3173 /* unsigned int -> unsigned long */
3174 return INTEGER_PROMOTION_BADNESS;
3176 /* unsigned long -> unsigned int */
3177 return INTEGER_CONVERSION_BADNESS;
3181 if (integer_types_same_name_p (TYPE_NAME (arg),
3183 && integer_types_same_name_p (TYPE_NAME (parm),
3185 /* signed long -> unsigned int */
3186 return INTEGER_CONVERSION_BADNESS;
3188 /* signed int/long -> unsigned int/long */
3189 return INTEGER_CONVERSION_BADNESS;
3192 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3194 if (integer_types_same_name_p (TYPE_NAME (parm),
3196 return EXACT_MATCH_BADNESS;
3197 else if (integer_types_same_name_p (TYPE_NAME (arg),
3199 && integer_types_same_name_p (TYPE_NAME (parm),
3201 return INTEGER_PROMOTION_BADNESS;
3203 return INTEGER_CONVERSION_BADNESS;
3206 return INTEGER_CONVERSION_BADNESS;
3208 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3209 return INTEGER_PROMOTION_BADNESS;
3211 return INTEGER_CONVERSION_BADNESS;
3212 case TYPE_CODE_ENUM:
3213 case TYPE_CODE_FLAGS:
3214 case TYPE_CODE_CHAR:
3215 case TYPE_CODE_RANGE:
3216 case TYPE_CODE_BOOL:
3217 if (TYPE_DECLARED_CLASS (arg))
3218 return INCOMPATIBLE_TYPE_BADNESS;
3219 return INTEGER_PROMOTION_BADNESS;
3221 return INT_FLOAT_CONVERSION_BADNESS;
3223 return NS_POINTER_CONVERSION_BADNESS;
3225 return INCOMPATIBLE_TYPE_BADNESS;
3228 case TYPE_CODE_ENUM:
3229 switch (TYPE_CODE (arg))
3232 case TYPE_CODE_CHAR:
3233 case TYPE_CODE_RANGE:
3234 case TYPE_CODE_BOOL:
3235 case TYPE_CODE_ENUM:
3236 if (TYPE_DECLARED_CLASS (parm) || TYPE_DECLARED_CLASS (arg))
3237 return INCOMPATIBLE_TYPE_BADNESS;
3238 return INTEGER_CONVERSION_BADNESS;
3240 return INT_FLOAT_CONVERSION_BADNESS;
3242 return INCOMPATIBLE_TYPE_BADNESS;
3245 case TYPE_CODE_CHAR:
3246 switch (TYPE_CODE (arg))
3248 case TYPE_CODE_RANGE:
3249 case TYPE_CODE_BOOL:
3250 case TYPE_CODE_ENUM:
3251 if (TYPE_DECLARED_CLASS (arg))
3252 return INCOMPATIBLE_TYPE_BADNESS;
3253 return INTEGER_CONVERSION_BADNESS;
3255 return INT_FLOAT_CONVERSION_BADNESS;
3257 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
3258 return INTEGER_CONVERSION_BADNESS;
3259 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3260 return INTEGER_PROMOTION_BADNESS;
3261 /* >>> !! else fall through !! <<< */
3262 case TYPE_CODE_CHAR:
3263 /* Deal with signed, unsigned, and plain chars for C++ and
3264 with int cases falling through from previous case. */
3265 if (TYPE_NOSIGN (parm))
3267 if (TYPE_NOSIGN (arg))
3268 return EXACT_MATCH_BADNESS;
3270 return INTEGER_CONVERSION_BADNESS;
3272 else if (TYPE_UNSIGNED (parm))
3274 if (TYPE_UNSIGNED (arg))
3275 return EXACT_MATCH_BADNESS;
3277 return INTEGER_PROMOTION_BADNESS;
3279 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3280 return EXACT_MATCH_BADNESS;
3282 return INTEGER_CONVERSION_BADNESS;
3284 return INCOMPATIBLE_TYPE_BADNESS;
3287 case TYPE_CODE_RANGE:
3288 switch (TYPE_CODE (arg))
3291 case TYPE_CODE_CHAR:
3292 case TYPE_CODE_RANGE:
3293 case TYPE_CODE_BOOL:
3294 case TYPE_CODE_ENUM:
3295 return INTEGER_CONVERSION_BADNESS;
3297 return INT_FLOAT_CONVERSION_BADNESS;
3299 return INCOMPATIBLE_TYPE_BADNESS;
3302 case TYPE_CODE_BOOL:
3303 switch (TYPE_CODE (arg))
3305 /* n3290 draft, section 4.12.1 (conv.bool):
3307 "A prvalue of arithmetic, unscoped enumeration, pointer, or
3308 pointer to member type can be converted to a prvalue of type
3309 bool. A zero value, null pointer value, or null member pointer
3310 value is converted to false; any other value is converted to
3311 true. A prvalue of type std::nullptr_t can be converted to a
3312 prvalue of type bool; the resulting value is false." */
3314 case TYPE_CODE_CHAR:
3315 case TYPE_CODE_ENUM:
3317 case TYPE_CODE_MEMBERPTR:
3319 return BOOL_CONVERSION_BADNESS;
3320 case TYPE_CODE_RANGE:
3321 return INCOMPATIBLE_TYPE_BADNESS;
3322 case TYPE_CODE_BOOL:
3323 return EXACT_MATCH_BADNESS;
3325 return INCOMPATIBLE_TYPE_BADNESS;
3329 switch (TYPE_CODE (arg))
3332 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3333 return FLOAT_PROMOTION_BADNESS;
3334 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3335 return EXACT_MATCH_BADNESS;
3337 return FLOAT_CONVERSION_BADNESS;
3339 case TYPE_CODE_BOOL:
3340 case TYPE_CODE_ENUM:
3341 case TYPE_CODE_RANGE:
3342 case TYPE_CODE_CHAR:
3343 return INT_FLOAT_CONVERSION_BADNESS;
3345 return INCOMPATIBLE_TYPE_BADNESS;
3348 case TYPE_CODE_COMPLEX:
3349 switch (TYPE_CODE (arg))
3350 { /* Strictly not needed for C++, but... */
3352 return FLOAT_PROMOTION_BADNESS;
3353 case TYPE_CODE_COMPLEX:
3354 return EXACT_MATCH_BADNESS;
3356 return INCOMPATIBLE_TYPE_BADNESS;
3359 case TYPE_CODE_STRUCT:
3360 /* currently same as TYPE_CODE_CLASS. */
3361 switch (TYPE_CODE (arg))
3363 case TYPE_CODE_STRUCT:
3364 /* Check for derivation */
3365 rank.subrank = distance_to_ancestor (parm, arg, 0);
3366 if (rank.subrank >= 0)
3367 return sum_ranks (BASE_CONVERSION_BADNESS, rank);
3368 /* else fall through */
3370 return INCOMPATIBLE_TYPE_BADNESS;
3373 case TYPE_CODE_UNION:
3374 switch (TYPE_CODE (arg))
3376 case TYPE_CODE_UNION:
3378 return INCOMPATIBLE_TYPE_BADNESS;
3381 case TYPE_CODE_MEMBERPTR:
3382 switch (TYPE_CODE (arg))
3385 return INCOMPATIBLE_TYPE_BADNESS;
3388 case TYPE_CODE_METHOD:
3389 switch (TYPE_CODE (arg))
3393 return INCOMPATIBLE_TYPE_BADNESS;
3397 switch (TYPE_CODE (arg))
3401 return INCOMPATIBLE_TYPE_BADNESS;
3406 switch (TYPE_CODE (arg))
3410 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
3411 TYPE_FIELD_TYPE (arg, 0), NULL);
3413 return INCOMPATIBLE_TYPE_BADNESS;
3416 case TYPE_CODE_VOID:
3418 return INCOMPATIBLE_TYPE_BADNESS;
3419 } /* switch (TYPE_CODE (arg)) */
3422 /* End of functions for overload resolution. */
3424 /* Routines to pretty-print types. */
3427 print_bit_vector (B_TYPE *bits, int nbits)
3431 for (bitno = 0; bitno < nbits; bitno++)
3433 if ((bitno % 8) == 0)
3435 puts_filtered (" ");
3437 if (B_TST (bits, bitno))
3438 printf_filtered (("1"));
3440 printf_filtered (("0"));
3444 /* Note the first arg should be the "this" pointer, we may not want to
3445 include it since we may get into a infinitely recursive
3449 print_arg_types (struct field *args, int nargs, int spaces)
3455 for (i = 0; i < nargs; i++)
3456 recursive_dump_type (args[i].type, spaces + 2);
3461 field_is_static (struct field *f)
3463 /* "static" fields are the fields whose location is not relative
3464 to the address of the enclosing struct. It would be nice to
3465 have a dedicated flag that would be set for static fields when
3466 the type is being created. But in practice, checking the field
3467 loc_kind should give us an accurate answer. */
3468 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
3469 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
3473 dump_fn_fieldlists (struct type *type, int spaces)
3479 printfi_filtered (spaces, "fn_fieldlists ");
3480 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
3481 printf_filtered ("\n");
3482 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
3484 f = TYPE_FN_FIELDLIST1 (type, method_idx);
3485 printfi_filtered (spaces + 2, "[%d] name '%s' (",
3487 TYPE_FN_FIELDLIST_NAME (type, method_idx));
3488 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
3490 printf_filtered (_(") length %d\n"),
3491 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
3492 for (overload_idx = 0;
3493 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
3496 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
3498 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
3499 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
3501 printf_filtered (")\n");
3502 printfi_filtered (spaces + 8, "type ");
3503 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
3505 printf_filtered ("\n");
3507 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
3510 printfi_filtered (spaces + 8, "args ");
3511 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
3513 printf_filtered ("\n");
3515 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
3516 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f,
3519 printfi_filtered (spaces + 8, "fcontext ");
3520 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
3522 printf_filtered ("\n");
3524 printfi_filtered (spaces + 8, "is_const %d\n",
3525 TYPE_FN_FIELD_CONST (f, overload_idx));
3526 printfi_filtered (spaces + 8, "is_volatile %d\n",
3527 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
3528 printfi_filtered (spaces + 8, "is_private %d\n",
3529 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
3530 printfi_filtered (spaces + 8, "is_protected %d\n",
3531 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
3532 printfi_filtered (spaces + 8, "is_stub %d\n",
3533 TYPE_FN_FIELD_STUB (f, overload_idx));
3534 printfi_filtered (spaces + 8, "voffset %u\n",
3535 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
3541 print_cplus_stuff (struct type *type, int spaces)
3543 printfi_filtered (spaces, "n_baseclasses %d\n",
3544 TYPE_N_BASECLASSES (type));
3545 printfi_filtered (spaces, "nfn_fields %d\n",
3546 TYPE_NFN_FIELDS (type));
3547 if (TYPE_N_BASECLASSES (type) > 0)
3549 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
3550 TYPE_N_BASECLASSES (type));
3551 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
3553 printf_filtered (")");
3555 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
3556 TYPE_N_BASECLASSES (type));
3557 puts_filtered ("\n");
3559 if (TYPE_NFIELDS (type) > 0)
3561 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
3563 printfi_filtered (spaces,
3564 "private_field_bits (%d bits at *",
3565 TYPE_NFIELDS (type));
3566 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
3568 printf_filtered (")");
3569 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
3570 TYPE_NFIELDS (type));
3571 puts_filtered ("\n");
3573 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
3575 printfi_filtered (spaces,
3576 "protected_field_bits (%d bits at *",
3577 TYPE_NFIELDS (type));
3578 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
3580 printf_filtered (")");
3581 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
3582 TYPE_NFIELDS (type));
3583 puts_filtered ("\n");
3586 if (TYPE_NFN_FIELDS (type) > 0)
3588 dump_fn_fieldlists (type, spaces);
3592 /* Print the contents of the TYPE's type_specific union, assuming that
3593 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
3596 print_gnat_stuff (struct type *type, int spaces)
3598 struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
3600 recursive_dump_type (descriptive_type, spaces + 2);
3603 static struct obstack dont_print_type_obstack;
3606 recursive_dump_type (struct type *type, int spaces)
3611 obstack_begin (&dont_print_type_obstack, 0);
3613 if (TYPE_NFIELDS (type) > 0
3614 || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0))
3616 struct type **first_dont_print
3617 = (struct type **) obstack_base (&dont_print_type_obstack);
3619 int i = (struct type **)
3620 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
3624 if (type == first_dont_print[i])
3626 printfi_filtered (spaces, "type node ");
3627 gdb_print_host_address (type, gdb_stdout);
3628 printf_filtered (_(" <same as already seen type>\n"));
3633 obstack_ptr_grow (&dont_print_type_obstack, type);
3636 printfi_filtered (spaces, "type node ");
3637 gdb_print_host_address (type, gdb_stdout);
3638 printf_filtered ("\n");
3639 printfi_filtered (spaces, "name '%s' (",
3640 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
3641 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
3642 printf_filtered (")\n");
3643 printfi_filtered (spaces, "tagname '%s' (",
3644 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
3645 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
3646 printf_filtered (")\n");
3647 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
3648 switch (TYPE_CODE (type))
3650 case TYPE_CODE_UNDEF:
3651 printf_filtered ("(TYPE_CODE_UNDEF)");
3654 printf_filtered ("(TYPE_CODE_PTR)");
3656 case TYPE_CODE_ARRAY:
3657 printf_filtered ("(TYPE_CODE_ARRAY)");
3659 case TYPE_CODE_STRUCT:
3660 printf_filtered ("(TYPE_CODE_STRUCT)");
3662 case TYPE_CODE_UNION:
3663 printf_filtered ("(TYPE_CODE_UNION)");
3665 case TYPE_CODE_ENUM:
3666 printf_filtered ("(TYPE_CODE_ENUM)");
3668 case TYPE_CODE_FLAGS:
3669 printf_filtered ("(TYPE_CODE_FLAGS)");
3671 case TYPE_CODE_FUNC:
3672 printf_filtered ("(TYPE_CODE_FUNC)");
3675 printf_filtered ("(TYPE_CODE_INT)");
3678 printf_filtered ("(TYPE_CODE_FLT)");
3680 case TYPE_CODE_VOID:
3681 printf_filtered ("(TYPE_CODE_VOID)");
3684 printf_filtered ("(TYPE_CODE_SET)");
3686 case TYPE_CODE_RANGE:
3687 printf_filtered ("(TYPE_CODE_RANGE)");
3689 case TYPE_CODE_STRING:
3690 printf_filtered ("(TYPE_CODE_STRING)");
3692 case TYPE_CODE_ERROR:
3693 printf_filtered ("(TYPE_CODE_ERROR)");
3695 case TYPE_CODE_MEMBERPTR:
3696 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
3698 case TYPE_CODE_METHODPTR:
3699 printf_filtered ("(TYPE_CODE_METHODPTR)");
3701 case TYPE_CODE_METHOD:
3702 printf_filtered ("(TYPE_CODE_METHOD)");
3705 printf_filtered ("(TYPE_CODE_REF)");
3707 case TYPE_CODE_CHAR:
3708 printf_filtered ("(TYPE_CODE_CHAR)");
3710 case TYPE_CODE_BOOL:
3711 printf_filtered ("(TYPE_CODE_BOOL)");
3713 case TYPE_CODE_COMPLEX:
3714 printf_filtered ("(TYPE_CODE_COMPLEX)");
3716 case TYPE_CODE_TYPEDEF:
3717 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3719 case TYPE_CODE_NAMESPACE:
3720 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3723 printf_filtered ("(UNKNOWN TYPE CODE)");
3726 puts_filtered ("\n");
3727 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
3728 if (TYPE_OBJFILE_OWNED (type))
3730 printfi_filtered (spaces, "objfile ");
3731 gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout);
3735 printfi_filtered (spaces, "gdbarch ");
3736 gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout);
3738 printf_filtered ("\n");
3739 printfi_filtered (spaces, "target_type ");
3740 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
3741 printf_filtered ("\n");
3742 if (TYPE_TARGET_TYPE (type) != NULL)
3744 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3746 printfi_filtered (spaces, "pointer_type ");
3747 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
3748 printf_filtered ("\n");
3749 printfi_filtered (spaces, "reference_type ");
3750 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
3751 printf_filtered ("\n");
3752 printfi_filtered (spaces, "type_chain ");
3753 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
3754 printf_filtered ("\n");
3755 printfi_filtered (spaces, "instance_flags 0x%x",
3756 TYPE_INSTANCE_FLAGS (type));
3757 if (TYPE_CONST (type))
3759 puts_filtered (" TYPE_FLAG_CONST");
3761 if (TYPE_VOLATILE (type))
3763 puts_filtered (" TYPE_FLAG_VOLATILE");
3765 if (TYPE_CODE_SPACE (type))
3767 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3769 if (TYPE_DATA_SPACE (type))
3771 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3773 if (TYPE_ADDRESS_CLASS_1 (type))
3775 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3777 if (TYPE_ADDRESS_CLASS_2 (type))
3779 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3781 if (TYPE_RESTRICT (type))
3783 puts_filtered (" TYPE_FLAG_RESTRICT");
3785 puts_filtered ("\n");
3787 printfi_filtered (spaces, "flags");
3788 if (TYPE_UNSIGNED (type))
3790 puts_filtered (" TYPE_FLAG_UNSIGNED");
3792 if (TYPE_NOSIGN (type))
3794 puts_filtered (" TYPE_FLAG_NOSIGN");
3796 if (TYPE_STUB (type))
3798 puts_filtered (" TYPE_FLAG_STUB");
3800 if (TYPE_TARGET_STUB (type))
3802 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3804 if (TYPE_STATIC (type))
3806 puts_filtered (" TYPE_FLAG_STATIC");
3808 if (TYPE_PROTOTYPED (type))
3810 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3812 if (TYPE_INCOMPLETE (type))
3814 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3816 if (TYPE_VARARGS (type))
3818 puts_filtered (" TYPE_FLAG_VARARGS");
3820 /* This is used for things like AltiVec registers on ppc. Gcc emits
3821 an attribute for the array type, which tells whether or not we
3822 have a vector, instead of a regular array. */
3823 if (TYPE_VECTOR (type))
3825 puts_filtered (" TYPE_FLAG_VECTOR");
3827 if (TYPE_FIXED_INSTANCE (type))
3829 puts_filtered (" TYPE_FIXED_INSTANCE");
3831 if (TYPE_STUB_SUPPORTED (type))
3833 puts_filtered (" TYPE_STUB_SUPPORTED");
3835 if (TYPE_NOTTEXT (type))
3837 puts_filtered (" TYPE_NOTTEXT");
3839 puts_filtered ("\n");
3840 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3841 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3842 puts_filtered ("\n");
3843 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3845 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
3846 printfi_filtered (spaces + 2,
3847 "[%d] enumval %s type ",
3848 idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
3850 printfi_filtered (spaces + 2,
3851 "[%d] bitpos %d bitsize %d type ",
3852 idx, TYPE_FIELD_BITPOS (type, idx),
3853 TYPE_FIELD_BITSIZE (type, idx));
3854 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3855 printf_filtered (" name '%s' (",
3856 TYPE_FIELD_NAME (type, idx) != NULL
3857 ? TYPE_FIELD_NAME (type, idx)
3859 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3860 printf_filtered (")\n");
3861 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3863 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3866 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
3868 printfi_filtered (spaces, "low %s%s high %s%s\n",
3869 plongest (TYPE_LOW_BOUND (type)),
3870 TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
3871 plongest (TYPE_HIGH_BOUND (type)),
3872 TYPE_HIGH_BOUND_UNDEFINED (type)
3873 ? " (undefined)" : "");
3875 printfi_filtered (spaces, "vptr_basetype ");
3876 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3877 puts_filtered ("\n");
3878 if (TYPE_VPTR_BASETYPE (type) != NULL)
3880 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3882 printfi_filtered (spaces, "vptr_fieldno %d\n",
3883 TYPE_VPTR_FIELDNO (type));
3885 switch (TYPE_SPECIFIC_FIELD (type))
3887 case TYPE_SPECIFIC_CPLUS_STUFF:
3888 printfi_filtered (spaces, "cplus_stuff ");
3889 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
3891 puts_filtered ("\n");
3892 print_cplus_stuff (type, spaces);
3895 case TYPE_SPECIFIC_GNAT_STUFF:
3896 printfi_filtered (spaces, "gnat_stuff ");
3897 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type), gdb_stdout);
3898 puts_filtered ("\n");
3899 print_gnat_stuff (type, spaces);
3902 case TYPE_SPECIFIC_FLOATFORMAT:
3903 printfi_filtered (spaces, "floatformat ");
3904 if (TYPE_FLOATFORMAT (type) == NULL)
3905 puts_filtered ("(null)");
3908 puts_filtered ("{ ");
3909 if (TYPE_FLOATFORMAT (type)[0] == NULL
3910 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
3911 puts_filtered ("(null)");
3913 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
3915 puts_filtered (", ");
3916 if (TYPE_FLOATFORMAT (type)[1] == NULL
3917 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
3918 puts_filtered ("(null)");
3920 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
3922 puts_filtered (" }");
3924 puts_filtered ("\n");
3927 case TYPE_SPECIFIC_FUNC:
3928 printfi_filtered (spaces, "calling_convention %d\n",
3929 TYPE_CALLING_CONVENTION (type));
3930 /* tail_call_list is not printed. */
3935 obstack_free (&dont_print_type_obstack, NULL);
3938 /* Trivial helpers for the libiberty hash table, for mapping one
3943 struct type *old, *new;
3947 type_pair_hash (const void *item)
3949 const struct type_pair *pair = item;
3951 return htab_hash_pointer (pair->old);
3955 type_pair_eq (const void *item_lhs, const void *item_rhs)
3957 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
3959 return lhs->old == rhs->old;
3962 /* Allocate the hash table used by copy_type_recursive to walk
3963 types without duplicates. We use OBJFILE's obstack, because
3964 OBJFILE is about to be deleted. */
3967 create_copied_types_hash (struct objfile *objfile)
3969 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
3970 NULL, &objfile->objfile_obstack,
3971 hashtab_obstack_allocate,
3972 dummy_obstack_deallocate);
3975 /* Recursively copy (deep copy) TYPE, if it is associated with
3976 OBJFILE. Return a new type allocated using malloc, a saved type if
3977 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
3978 not associated with OBJFILE. */
3981 copy_type_recursive (struct objfile *objfile,
3983 htab_t copied_types)
3985 struct type_pair *stored, pair;
3987 struct type *new_type;
3989 if (! TYPE_OBJFILE_OWNED (type))
3992 /* This type shouldn't be pointing to any types in other objfiles;
3993 if it did, the type might disappear unexpectedly. */
3994 gdb_assert (TYPE_OBJFILE (type) == objfile);
3997 slot = htab_find_slot (copied_types, &pair, INSERT);
3999 return ((struct type_pair *) *slot)->new;
4001 new_type = alloc_type_arch (get_type_arch (type));
4003 /* We must add the new type to the hash table immediately, in case
4004 we encounter this type again during a recursive call below. */
4006 = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
4008 stored->new = new_type;
4011 /* Copy the common fields of types. For the main type, we simply
4012 copy the entire thing and then update specific fields as needed. */
4013 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
4014 TYPE_OBJFILE_OWNED (new_type) = 0;
4015 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
4017 if (TYPE_NAME (type))
4018 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
4019 if (TYPE_TAG_NAME (type))
4020 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
4022 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4023 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4025 /* Copy the fields. */
4026 if (TYPE_NFIELDS (type))
4030 nfields = TYPE_NFIELDS (type);
4031 TYPE_FIELDS (new_type) = XCNEWVEC (struct field, nfields);
4032 for (i = 0; i < nfields; i++)
4034 TYPE_FIELD_ARTIFICIAL (new_type, i) =
4035 TYPE_FIELD_ARTIFICIAL (type, i);
4036 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
4037 if (TYPE_FIELD_TYPE (type, i))
4038 TYPE_FIELD_TYPE (new_type, i)
4039 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
4041 if (TYPE_FIELD_NAME (type, i))
4042 TYPE_FIELD_NAME (new_type, i) =
4043 xstrdup (TYPE_FIELD_NAME (type, i));
4044 switch (TYPE_FIELD_LOC_KIND (type, i))
4046 case FIELD_LOC_KIND_BITPOS:
4047 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
4048 TYPE_FIELD_BITPOS (type, i));
4050 case FIELD_LOC_KIND_ENUMVAL:
4051 SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i),
4052 TYPE_FIELD_ENUMVAL (type, i));
4054 case FIELD_LOC_KIND_PHYSADDR:
4055 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
4056 TYPE_FIELD_STATIC_PHYSADDR (type, i));
4058 case FIELD_LOC_KIND_PHYSNAME:
4059 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
4060 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
4064 internal_error (__FILE__, __LINE__,
4065 _("Unexpected type field location kind: %d"),
4066 TYPE_FIELD_LOC_KIND (type, i));
4071 /* For range types, copy the bounds information. */
4072 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4074 TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
4075 *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
4078 /* Copy pointers to other types. */
4079 if (TYPE_TARGET_TYPE (type))
4080 TYPE_TARGET_TYPE (new_type) =
4081 copy_type_recursive (objfile,
4082 TYPE_TARGET_TYPE (type),
4084 if (TYPE_VPTR_BASETYPE (type))
4085 TYPE_VPTR_BASETYPE (new_type) =
4086 copy_type_recursive (objfile,
4087 TYPE_VPTR_BASETYPE (type),
4089 /* Maybe copy the type_specific bits.
4091 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
4092 base classes and methods. There's no fundamental reason why we
4093 can't, but at the moment it is not needed. */
4095 if (TYPE_CODE (type) == TYPE_CODE_FLT)
4096 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
4097 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4098 || TYPE_CODE (type) == TYPE_CODE_UNION
4099 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
4100 INIT_CPLUS_SPECIFIC (new_type);
4105 /* Make a copy of the given TYPE, except that the pointer & reference
4106 types are not preserved.
4108 This function assumes that the given type has an associated objfile.
4109 This objfile is used to allocate the new type. */
4112 copy_type (const struct type *type)
4114 struct type *new_type;
4116 gdb_assert (TYPE_OBJFILE_OWNED (type));
4118 new_type = alloc_type_copy (type);
4119 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4120 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4121 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
4122 sizeof (struct main_type));
4127 /* Helper functions to initialize architecture-specific types. */
4129 /* Allocate a type structure associated with GDBARCH and set its
4130 CODE, LENGTH, and NAME fields. */
4133 arch_type (struct gdbarch *gdbarch,
4134 enum type_code code, int length, char *name)
4138 type = alloc_type_arch (gdbarch);
4139 TYPE_CODE (type) = code;
4140 TYPE_LENGTH (type) = length;
4143 TYPE_NAME (type) = xstrdup (name);
4148 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
4149 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4150 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4153 arch_integer_type (struct gdbarch *gdbarch,
4154 int bit, int unsigned_p, char *name)
4158 t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
4160 TYPE_UNSIGNED (t) = 1;
4161 if (name && strcmp (name, "char") == 0)
4162 TYPE_NOSIGN (t) = 1;
4167 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
4168 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4169 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4172 arch_character_type (struct gdbarch *gdbarch,
4173 int bit, int unsigned_p, char *name)
4177 t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
4179 TYPE_UNSIGNED (t) = 1;
4184 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
4185 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4186 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4189 arch_boolean_type (struct gdbarch *gdbarch,
4190 int bit, int unsigned_p, char *name)
4194 t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
4196 TYPE_UNSIGNED (t) = 1;
4201 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
4202 BIT is the type size in bits; if BIT equals -1, the size is
4203 determined by the floatformat. NAME is the type name. Set the
4204 TYPE_FLOATFORMAT from FLOATFORMATS. */
4207 arch_float_type (struct gdbarch *gdbarch,
4208 int bit, char *name, const struct floatformat **floatformats)
4214 gdb_assert (floatformats != NULL);
4215 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
4216 bit = floatformats[0]->totalsize;
4218 gdb_assert (bit >= 0);
4220 t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
4221 TYPE_FLOATFORMAT (t) = floatformats;
4225 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
4226 NAME is the type name. TARGET_TYPE is the component float type. */
4229 arch_complex_type (struct gdbarch *gdbarch,
4230 char *name, struct type *target_type)
4234 t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
4235 2 * TYPE_LENGTH (target_type), name);
4236 TYPE_TARGET_TYPE (t) = target_type;
4240 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
4241 NAME is the type name. LENGTH is the size of the flag word in bytes. */
4244 arch_flags_type (struct gdbarch *gdbarch, char *name, int length)
4246 int nfields = length * TARGET_CHAR_BIT;
4249 type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name);
4250 TYPE_UNSIGNED (type) = 1;
4251 TYPE_NFIELDS (type) = nfields;
4252 TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
4257 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
4258 position BITPOS is called NAME. */
4261 append_flags_type_flag (struct type *type, int bitpos, char *name)
4263 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
4264 gdb_assert (bitpos < TYPE_NFIELDS (type));
4265 gdb_assert (bitpos >= 0);
4269 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
4270 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), bitpos);
4274 /* Don't show this field to the user. */
4275 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), -1);
4279 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
4280 specified by CODE) associated with GDBARCH. NAME is the type name. */
4283 arch_composite_type (struct gdbarch *gdbarch, char *name, enum type_code code)
4287 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
4288 t = arch_type (gdbarch, code, 0, NULL);
4289 TYPE_TAG_NAME (t) = name;
4290 INIT_CPLUS_SPECIFIC (t);
4294 /* Add new field with name NAME and type FIELD to composite type T.
4295 Do not set the field's position or adjust the type's length;
4296 the caller should do so. Return the new field. */
4299 append_composite_type_field_raw (struct type *t, char *name,
4304 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
4305 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
4306 sizeof (struct field) * TYPE_NFIELDS (t));
4307 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
4308 memset (f, 0, sizeof f[0]);
4309 FIELD_TYPE (f[0]) = field;
4310 FIELD_NAME (f[0]) = name;
4314 /* Add new field with name NAME and type FIELD to composite type T.
4315 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
4318 append_composite_type_field_aligned (struct type *t, char *name,
4319 struct type *field, int alignment)
4321 struct field *f = append_composite_type_field_raw (t, name, field);
4323 if (TYPE_CODE (t) == TYPE_CODE_UNION)
4325 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
4326 TYPE_LENGTH (t) = TYPE_LENGTH (field);
4328 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
4330 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
4331 if (TYPE_NFIELDS (t) > 1)
4333 SET_FIELD_BITPOS (f[0],
4334 (FIELD_BITPOS (f[-1])
4335 + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
4336 * TARGET_CHAR_BIT)));
4342 alignment *= TARGET_CHAR_BIT;
4343 left = FIELD_BITPOS (f[0]) % alignment;
4347 SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left));
4348 TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
4355 /* Add new field with name NAME and type FIELD to composite type T. */
4358 append_composite_type_field (struct type *t, char *name,
4361 append_composite_type_field_aligned (t, name, field, 0);
4364 static struct gdbarch_data *gdbtypes_data;
4366 const struct builtin_type *
4367 builtin_type (struct gdbarch *gdbarch)
4369 return gdbarch_data (gdbarch, gdbtypes_data);
4373 gdbtypes_post_init (struct gdbarch *gdbarch)
4375 struct builtin_type *builtin_type
4376 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
4379 builtin_type->builtin_void
4380 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
4381 builtin_type->builtin_char
4382 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4383 !gdbarch_char_signed (gdbarch), "char");
4384 builtin_type->builtin_signed_char
4385 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4387 builtin_type->builtin_unsigned_char
4388 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
4389 1, "unsigned char");
4390 builtin_type->builtin_short
4391 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
4393 builtin_type->builtin_unsigned_short
4394 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
4395 1, "unsigned short");
4396 builtin_type->builtin_int
4397 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
4399 builtin_type->builtin_unsigned_int
4400 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
4402 builtin_type->builtin_long
4403 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
4405 builtin_type->builtin_unsigned_long
4406 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
4407 1, "unsigned long");
4408 builtin_type->builtin_long_long
4409 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
4411 builtin_type->builtin_unsigned_long_long
4412 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
4413 1, "unsigned long long");
4414 builtin_type->builtin_float
4415 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
4416 "float", gdbarch_float_format (gdbarch));
4417 builtin_type->builtin_double
4418 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
4419 "double", gdbarch_double_format (gdbarch));
4420 builtin_type->builtin_long_double
4421 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
4422 "long double", gdbarch_long_double_format (gdbarch));
4423 builtin_type->builtin_complex
4424 = arch_complex_type (gdbarch, "complex",
4425 builtin_type->builtin_float);
4426 builtin_type->builtin_double_complex
4427 = arch_complex_type (gdbarch, "double complex",
4428 builtin_type->builtin_double);
4429 builtin_type->builtin_string
4430 = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string");
4431 builtin_type->builtin_bool
4432 = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool");
4434 /* The following three are about decimal floating point types, which
4435 are 32-bits, 64-bits and 128-bits respectively. */
4436 builtin_type->builtin_decfloat
4437 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 32 / 8, "_Decimal32");
4438 builtin_type->builtin_decdouble
4439 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 64 / 8, "_Decimal64");
4440 builtin_type->builtin_declong
4441 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 128 / 8, "_Decimal128");
4443 /* "True" character types. */
4444 builtin_type->builtin_true_char
4445 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character");
4446 builtin_type->builtin_true_unsigned_char
4447 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character");
4449 /* Fixed-size integer types. */
4450 builtin_type->builtin_int0
4451 = arch_integer_type (gdbarch, 0, 0, "int0_t");
4452 builtin_type->builtin_int8
4453 = arch_integer_type (gdbarch, 8, 0, "int8_t");
4454 builtin_type->builtin_uint8
4455 = arch_integer_type (gdbarch, 8, 1, "uint8_t");
4456 builtin_type->builtin_int16
4457 = arch_integer_type (gdbarch, 16, 0, "int16_t");
4458 builtin_type->builtin_uint16
4459 = arch_integer_type (gdbarch, 16, 1, "uint16_t");
4460 builtin_type->builtin_int32
4461 = arch_integer_type (gdbarch, 32, 0, "int32_t");
4462 builtin_type->builtin_uint32
4463 = arch_integer_type (gdbarch, 32, 1, "uint32_t");
4464 builtin_type->builtin_int64
4465 = arch_integer_type (gdbarch, 64, 0, "int64_t");
4466 builtin_type->builtin_uint64
4467 = arch_integer_type (gdbarch, 64, 1, "uint64_t");
4468 builtin_type->builtin_int128
4469 = arch_integer_type (gdbarch, 128, 0, "int128_t");
4470 builtin_type->builtin_uint128
4471 = arch_integer_type (gdbarch, 128, 1, "uint128_t");
4472 TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |=
4473 TYPE_INSTANCE_FLAG_NOTTEXT;
4474 TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |=
4475 TYPE_INSTANCE_FLAG_NOTTEXT;
4477 /* Wide character types. */
4478 builtin_type->builtin_char16
4479 = arch_integer_type (gdbarch, 16, 0, "char16_t");
4480 builtin_type->builtin_char32
4481 = arch_integer_type (gdbarch, 32, 0, "char32_t");
4484 /* Default data/code pointer types. */
4485 builtin_type->builtin_data_ptr
4486 = lookup_pointer_type (builtin_type->builtin_void);
4487 builtin_type->builtin_func_ptr
4488 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
4489 builtin_type->builtin_func_func
4490 = lookup_function_type (builtin_type->builtin_func_ptr);
4492 /* This type represents a GDB internal function. */
4493 builtin_type->internal_fn
4494 = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0,
4495 "<internal function>");
4497 /* This type represents an xmethod. */
4498 builtin_type->xmethod
4499 = arch_type (gdbarch, TYPE_CODE_XMETHOD, 0, "<xmethod>");
4501 return builtin_type;
4504 /* This set of objfile-based types is intended to be used by symbol
4505 readers as basic types. */
4507 static const struct objfile_data *objfile_type_data;
4509 const struct objfile_type *
4510 objfile_type (struct objfile *objfile)
4512 struct gdbarch *gdbarch;
4513 struct objfile_type *objfile_type
4514 = objfile_data (objfile, objfile_type_data);
4517 return objfile_type;
4519 objfile_type = OBSTACK_CALLOC (&objfile->objfile_obstack,
4520 1, struct objfile_type);
4522 /* Use the objfile architecture to determine basic type properties. */
4523 gdbarch = get_objfile_arch (objfile);
4526 objfile_type->builtin_void
4527 = init_type (TYPE_CODE_VOID, 1,
4531 objfile_type->builtin_char
4532 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4534 | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
4536 objfile_type->builtin_signed_char
4537 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4539 "signed char", objfile);
4540 objfile_type->builtin_unsigned_char
4541 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4543 "unsigned char", objfile);
4544 objfile_type->builtin_short
4545 = init_type (TYPE_CODE_INT,
4546 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4547 0, "short", objfile);
4548 objfile_type->builtin_unsigned_short
4549 = init_type (TYPE_CODE_INT,
4550 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4551 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
4552 objfile_type->builtin_int
4553 = init_type (TYPE_CODE_INT,
4554 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4556 objfile_type->builtin_unsigned_int
4557 = init_type (TYPE_CODE_INT,
4558 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4559 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
4560 objfile_type->builtin_long
4561 = init_type (TYPE_CODE_INT,
4562 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4563 0, "long", objfile);
4564 objfile_type->builtin_unsigned_long
4565 = init_type (TYPE_CODE_INT,
4566 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4567 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
4568 objfile_type->builtin_long_long
4569 = init_type (TYPE_CODE_INT,
4570 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4571 0, "long long", objfile);
4572 objfile_type->builtin_unsigned_long_long
4573 = init_type (TYPE_CODE_INT,
4574 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4575 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
4577 objfile_type->builtin_float
4578 = init_type (TYPE_CODE_FLT,
4579 gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT,
4580 0, "float", objfile);
4581 TYPE_FLOATFORMAT (objfile_type->builtin_float)
4582 = gdbarch_float_format (gdbarch);
4583 objfile_type->builtin_double
4584 = init_type (TYPE_CODE_FLT,
4585 gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT,
4586 0, "double", objfile);
4587 TYPE_FLOATFORMAT (objfile_type->builtin_double)
4588 = gdbarch_double_format (gdbarch);
4589 objfile_type->builtin_long_double
4590 = init_type (TYPE_CODE_FLT,
4591 gdbarch_long_double_bit (gdbarch) / TARGET_CHAR_BIT,
4592 0, "long double", objfile);
4593 TYPE_FLOATFORMAT (objfile_type->builtin_long_double)
4594 = gdbarch_long_double_format (gdbarch);
4596 /* This type represents a type that was unrecognized in symbol read-in. */
4597 objfile_type->builtin_error
4598 = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>", objfile);
4600 /* The following set of types is used for symbols with no
4601 debug information. */
4602 objfile_type->nodebug_text_symbol
4603 = init_type (TYPE_CODE_FUNC, 1, 0,
4604 "<text variable, no debug info>", objfile);
4605 TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
4606 = objfile_type->builtin_int;
4607 objfile_type->nodebug_text_gnu_ifunc_symbol
4608 = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC,
4609 "<text gnu-indirect-function variable, no debug info>",
4611 TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
4612 = objfile_type->nodebug_text_symbol;
4613 objfile_type->nodebug_got_plt_symbol
4614 = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0,
4615 "<text from jump slot in .got.plt, no debug info>",
4617 TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol)
4618 = objfile_type->nodebug_text_symbol;
4619 objfile_type->nodebug_data_symbol
4620 = init_type (TYPE_CODE_INT,
4621 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4622 "<data variable, no debug info>", objfile);
4623 objfile_type->nodebug_unknown_symbol
4624 = init_type (TYPE_CODE_INT, 1, 0,
4625 "<variable (not text or data), no debug info>", objfile);
4626 objfile_type->nodebug_tls_symbol
4627 = init_type (TYPE_CODE_INT,
4628 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4629 "<thread local variable, no debug info>", objfile);
4631 /* NOTE: on some targets, addresses and pointers are not necessarily
4635 - gdb's `struct type' always describes the target's
4637 - gdb's `struct value' objects should always hold values in
4639 - gdb's CORE_ADDR values are addresses in the unified virtual
4640 address space that the assembler and linker work with. Thus,
4641 since target_read_memory takes a CORE_ADDR as an argument, it
4642 can access any memory on the target, even if the processor has
4643 separate code and data address spaces.
4645 In this context, objfile_type->builtin_core_addr is a bit odd:
4646 it's a target type for a value the target will never see. It's
4647 only used to hold the values of (typeless) linker symbols, which
4648 are indeed in the unified virtual address space. */
4650 objfile_type->builtin_core_addr
4651 = init_type (TYPE_CODE_INT,
4652 gdbarch_addr_bit (gdbarch) / 8,
4653 TYPE_FLAG_UNSIGNED, "__CORE_ADDR", objfile);
4655 set_objfile_data (objfile, objfile_type_data, objfile_type);
4656 return objfile_type;
4659 extern initialize_file_ftype _initialize_gdbtypes;
4662 _initialize_gdbtypes (void)
4664 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
4665 objfile_type_data = register_objfile_data ();
4667 add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug,
4668 _("Set debugging of C++ overloading."),
4669 _("Show debugging of C++ overloading."),
4670 _("When enabled, ranking of the "
4671 "functions is displayed."),
4673 show_overload_debug,
4674 &setdebuglist, &showdebuglist);
4676 /* Add user knob for controlling resolution of opaque types. */
4677 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
4678 &opaque_type_resolution,
4679 _("Set resolution of opaque struct/class/union"
4680 " types (if set before loading symbols)."),
4681 _("Show resolution of opaque struct/class/union"
4682 " types (if set before loading symbols)."),
4684 show_opaque_type_resolution,
4685 &setlist, &showlist);
4687 /* Add an option to permit non-strict type checking. */
4688 add_setshow_boolean_cmd ("type", class_support,
4689 &strict_type_checking,
4690 _("Set strict type checking."),
4691 _("Show strict type checking."),
4693 show_strict_type_checking,
4694 &setchecklist, &showchecklist);