1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2013 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/>. */
23 #include "gdb_string.h"
29 #include "expression.h"
34 #include "complaints.h"
37 #include "gdb_assert.h"
39 #include "exceptions.h"
40 #include "cp-support.h"
42 /* Initialize BADNESS constants. */
44 const struct rank LENGTH_MISMATCH_BADNESS = {100,0};
46 const struct rank TOO_FEW_PARAMS_BADNESS = {100,0};
47 const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0};
49 const struct rank EXACT_MATCH_BADNESS = {0,0};
51 const struct rank INTEGER_PROMOTION_BADNESS = {1,0};
52 const struct rank FLOAT_PROMOTION_BADNESS = {1,0};
53 const struct rank BASE_PTR_CONVERSION_BADNESS = {1,0};
54 const struct rank INTEGER_CONVERSION_BADNESS = {2,0};
55 const struct rank FLOAT_CONVERSION_BADNESS = {2,0};
56 const struct rank INT_FLOAT_CONVERSION_BADNESS = {2,0};
57 const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0};
58 const struct rank BOOL_CONVERSION_BADNESS = {3,0};
59 const struct rank BASE_CONVERSION_BADNESS = {2,0};
60 const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
61 const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
62 const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
63 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
65 /* Floatformat pairs. */
66 const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
67 &floatformat_ieee_half_big,
68 &floatformat_ieee_half_little
70 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
71 &floatformat_ieee_single_big,
72 &floatformat_ieee_single_little
74 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
75 &floatformat_ieee_double_big,
76 &floatformat_ieee_double_little
78 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
79 &floatformat_ieee_double_big,
80 &floatformat_ieee_double_littlebyte_bigword
82 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
83 &floatformat_i387_ext,
86 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
87 &floatformat_m68881_ext,
88 &floatformat_m68881_ext
90 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
91 &floatformat_arm_ext_big,
92 &floatformat_arm_ext_littlebyte_bigword
94 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
95 &floatformat_ia64_spill_big,
96 &floatformat_ia64_spill_little
98 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
99 &floatformat_ia64_quad_big,
100 &floatformat_ia64_quad_little
102 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
106 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
110 const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
111 &floatformat_ibm_long_double_big,
112 &floatformat_ibm_long_double_little
115 /* Should opaque types be resolved? */
117 static int opaque_type_resolution = 1;
119 /* A flag to enable printing of debugging information of C++
122 unsigned int overload_debug = 0;
124 /* A flag to enable strict type checking. */
126 static int strict_type_checking = 1;
128 /* A function to show whether opaque types are resolved. */
131 show_opaque_type_resolution (struct ui_file *file, int from_tty,
132 struct cmd_list_element *c,
135 fprintf_filtered (file, _("Resolution of opaque struct/class/union types "
136 "(if set before loading symbols) is %s.\n"),
140 /* A function to show whether C++ overload debugging is enabled. */
143 show_overload_debug (struct ui_file *file, int from_tty,
144 struct cmd_list_element *c, const char *value)
146 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
150 /* A function to show the status of strict type checking. */
153 show_strict_type_checking (struct ui_file *file, int from_tty,
154 struct cmd_list_element *c, const char *value)
156 fprintf_filtered (file, _("Strict type checking is %s.\n"), value);
160 /* Allocate a new OBJFILE-associated type structure and fill it
161 with some defaults. Space for the type structure is allocated
162 on the objfile's objfile_obstack. */
165 alloc_type (struct objfile *objfile)
169 gdb_assert (objfile != NULL);
171 /* Alloc the structure and start off with all fields zeroed. */
172 type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
173 TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
175 OBJSTAT (objfile, n_types++);
177 TYPE_OBJFILE_OWNED (type) = 1;
178 TYPE_OWNER (type).objfile = objfile;
180 /* Initialize the fields that might not be zero. */
182 TYPE_CODE (type) = TYPE_CODE_UNDEF;
183 TYPE_VPTR_FIELDNO (type) = -1;
184 TYPE_CHAIN (type) = type; /* Chain back to itself. */
189 /* Allocate a new GDBARCH-associated type structure and fill it
190 with some defaults. Space for the type structure is allocated
194 alloc_type_arch (struct gdbarch *gdbarch)
198 gdb_assert (gdbarch != NULL);
200 /* Alloc the structure and start off with all fields zeroed. */
202 type = XZALLOC (struct type);
203 TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
205 TYPE_OBJFILE_OWNED (type) = 0;
206 TYPE_OWNER (type).gdbarch = gdbarch;
208 /* Initialize the fields that might not be zero. */
210 TYPE_CODE (type) = TYPE_CODE_UNDEF;
211 TYPE_VPTR_FIELDNO (type) = -1;
212 TYPE_CHAIN (type) = type; /* Chain back to itself. */
217 /* If TYPE is objfile-associated, allocate a new type structure
218 associated with the same objfile. If TYPE is gdbarch-associated,
219 allocate a new type structure associated with the same gdbarch. */
222 alloc_type_copy (const struct type *type)
224 if (TYPE_OBJFILE_OWNED (type))
225 return alloc_type (TYPE_OWNER (type).objfile);
227 return alloc_type_arch (TYPE_OWNER (type).gdbarch);
230 /* If TYPE is gdbarch-associated, return that architecture.
231 If TYPE is objfile-associated, return that objfile's architecture. */
234 get_type_arch (const struct type *type)
236 if (TYPE_OBJFILE_OWNED (type))
237 return get_objfile_arch (TYPE_OWNER (type).objfile);
239 return TYPE_OWNER (type).gdbarch;
242 /* See gdbtypes.h. */
245 get_target_type (struct type *type)
249 type = TYPE_TARGET_TYPE (type);
251 type = check_typedef (type);
257 /* Alloc a new type instance structure, fill it with some defaults,
258 and point it at OLDTYPE. Allocate the new type instance from the
259 same place as OLDTYPE. */
262 alloc_type_instance (struct type *oldtype)
266 /* Allocate the structure. */
268 if (! TYPE_OBJFILE_OWNED (oldtype))
269 type = XZALLOC (struct type);
271 type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
274 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
276 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
281 /* Clear all remnants of the previous type at TYPE, in preparation for
282 replacing it with something else. Preserve owner information. */
285 smash_type (struct type *type)
287 int objfile_owned = TYPE_OBJFILE_OWNED (type);
288 union type_owner owner = TYPE_OWNER (type);
290 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
292 /* Restore owner information. */
293 TYPE_OBJFILE_OWNED (type) = objfile_owned;
294 TYPE_OWNER (type) = owner;
296 /* For now, delete the rings. */
297 TYPE_CHAIN (type) = type;
299 /* For now, leave the pointer/reference types alone. */
302 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
303 to a pointer to memory where the pointer type should be stored.
304 If *TYPEPTR is zero, update it to point to the pointer type we return.
305 We allocate new memory if needed. */
308 make_pointer_type (struct type *type, struct type **typeptr)
310 struct type *ntype; /* New type */
313 ntype = TYPE_POINTER_TYPE (type);
318 return ntype; /* Don't care about alloc,
319 and have new type. */
320 else if (*typeptr == 0)
322 *typeptr = ntype; /* Tracking alloc, and have new type. */
327 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
329 ntype = alloc_type_copy (type);
333 else /* We have storage, but need to reset it. */
336 chain = TYPE_CHAIN (ntype);
338 TYPE_CHAIN (ntype) = chain;
341 TYPE_TARGET_TYPE (ntype) = type;
342 TYPE_POINTER_TYPE (type) = ntype;
344 /* FIXME! Assumes the machine has only one representation for pointers! */
347 = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
348 TYPE_CODE (ntype) = TYPE_CODE_PTR;
350 /* Mark pointers as unsigned. The target converts between pointers
351 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
352 gdbarch_address_to_pointer. */
353 TYPE_UNSIGNED (ntype) = 1;
355 /* Update the length of all the other variants of this type. */
356 chain = TYPE_CHAIN (ntype);
357 while (chain != ntype)
359 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
360 chain = TYPE_CHAIN (chain);
366 /* Given a type TYPE, return a type of pointers to that type.
367 May need to construct such a type if this is the first use. */
370 lookup_pointer_type (struct type *type)
372 return make_pointer_type (type, (struct type **) 0);
375 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
376 points to a pointer to memory where the reference type should be
377 stored. If *TYPEPTR is zero, update it to point to the reference
378 type we return. We allocate new memory if needed. */
381 make_reference_type (struct type *type, struct type **typeptr)
383 struct type *ntype; /* New type */
386 ntype = TYPE_REFERENCE_TYPE (type);
391 return ntype; /* Don't care about alloc,
392 and have new type. */
393 else if (*typeptr == 0)
395 *typeptr = ntype; /* Tracking alloc, and have new type. */
400 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
402 ntype = alloc_type_copy (type);
406 else /* We have storage, but need to reset it. */
409 chain = TYPE_CHAIN (ntype);
411 TYPE_CHAIN (ntype) = chain;
414 TYPE_TARGET_TYPE (ntype) = type;
415 TYPE_REFERENCE_TYPE (type) = ntype;
417 /* FIXME! Assume the machine has only one representation for
418 references, and that it matches the (only) representation for
421 TYPE_LENGTH (ntype) =
422 gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
423 TYPE_CODE (ntype) = TYPE_CODE_REF;
425 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
426 TYPE_REFERENCE_TYPE (type) = ntype;
428 /* Update the length of all the other variants of this type. */
429 chain = TYPE_CHAIN (ntype);
430 while (chain != ntype)
432 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
433 chain = TYPE_CHAIN (chain);
439 /* Same as above, but caller doesn't care about memory allocation
443 lookup_reference_type (struct type *type)
445 return make_reference_type (type, (struct type **) 0);
448 /* Lookup a function type that returns type TYPE. TYPEPTR, if
449 nonzero, points to a pointer to memory where the function type
450 should be stored. If *TYPEPTR is zero, update it to point to the
451 function type we return. We allocate new memory if needed. */
454 make_function_type (struct type *type, struct type **typeptr)
456 struct type *ntype; /* New type */
458 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
460 ntype = alloc_type_copy (type);
464 else /* We have storage, but need to reset it. */
470 TYPE_TARGET_TYPE (ntype) = type;
472 TYPE_LENGTH (ntype) = 1;
473 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
475 INIT_FUNC_SPECIFIC (ntype);
480 /* Given a type TYPE, return a type of functions that return that type.
481 May need to construct such a type if this is the first use. */
484 lookup_function_type (struct type *type)
486 return make_function_type (type, (struct type **) 0);
489 /* Given a type TYPE and argument types, return the appropriate
490 function type. If the final type in PARAM_TYPES is NULL, make a
494 lookup_function_type_with_arguments (struct type *type,
496 struct type **param_types)
498 struct type *fn = make_function_type (type, (struct type **) 0);
503 if (param_types[nparams - 1] == NULL)
506 TYPE_VARARGS (fn) = 1;
508 else if (TYPE_CODE (check_typedef (param_types[nparams - 1]))
512 /* Caller should have ensured this. */
513 gdb_assert (nparams == 0);
514 TYPE_PROTOTYPED (fn) = 1;
518 TYPE_NFIELDS (fn) = nparams;
519 TYPE_FIELDS (fn) = TYPE_ZALLOC (fn, nparams * sizeof (struct field));
520 for (i = 0; i < nparams; ++i)
521 TYPE_FIELD_TYPE (fn, i) = param_types[i];
526 /* Identify address space identifier by name --
527 return the integer flag defined in gdbtypes.h. */
530 address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
534 /* Check for known address space delimiters. */
535 if (!strcmp (space_identifier, "code"))
536 return TYPE_INSTANCE_FLAG_CODE_SPACE;
537 else if (!strcmp (space_identifier, "data"))
538 return TYPE_INSTANCE_FLAG_DATA_SPACE;
539 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
540 && gdbarch_address_class_name_to_type_flags (gdbarch,
545 error (_("Unknown address space specifier: \"%s\""), space_identifier);
548 /* Identify address space identifier by integer flag as defined in
549 gdbtypes.h -- return the string version of the adress space name. */
552 address_space_int_to_name (struct gdbarch *gdbarch, int space_flag)
554 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
556 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
558 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
559 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
560 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
565 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
567 If STORAGE is non-NULL, create the new type instance there.
568 STORAGE must be in the same obstack as TYPE. */
571 make_qualified_type (struct type *type, int new_flags,
572 struct type *storage)
579 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
581 ntype = TYPE_CHAIN (ntype);
583 while (ntype != type);
585 /* Create a new type instance. */
587 ntype = alloc_type_instance (type);
590 /* If STORAGE was provided, it had better be in the same objfile
591 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
592 if one objfile is freed and the other kept, we'd have
593 dangling pointers. */
594 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
597 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
598 TYPE_CHAIN (ntype) = ntype;
601 /* Pointers or references to the original type are not relevant to
603 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
604 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
606 /* Chain the new qualified type to the old type. */
607 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
608 TYPE_CHAIN (type) = ntype;
610 /* Now set the instance flags and return the new type. */
611 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
613 /* Set length of new type to that of the original type. */
614 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
619 /* Make an address-space-delimited variant of a type -- a type that
620 is identical to the one supplied except that it has an address
621 space attribute attached to it (such as "code" or "data").
623 The space attributes "code" and "data" are for Harvard
624 architectures. The address space attributes are for architectures
625 which have alternately sized pointers or pointers with alternate
629 make_type_with_address_space (struct type *type, int space_flag)
631 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
632 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
633 | TYPE_INSTANCE_FLAG_DATA_SPACE
634 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
637 return make_qualified_type (type, new_flags, NULL);
640 /* Make a "c-v" variant of a type -- a type that is identical to the
641 one supplied except that it may have const or volatile attributes
642 CNST is a flag for setting the const attribute
643 VOLTL is a flag for setting the volatile attribute
644 TYPE is the base type whose variant we are creating.
646 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
647 storage to hold the new qualified type; *TYPEPTR and TYPE must be
648 in the same objfile. Otherwise, allocate fresh memory for the new
649 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
650 new type we construct. */
653 make_cv_type (int cnst, int voltl,
655 struct type **typeptr)
657 struct type *ntype; /* New type */
659 int new_flags = (TYPE_INSTANCE_FLAGS (type)
660 & ~(TYPE_INSTANCE_FLAG_CONST
661 | TYPE_INSTANCE_FLAG_VOLATILE));
664 new_flags |= TYPE_INSTANCE_FLAG_CONST;
667 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
669 if (typeptr && *typeptr != NULL)
671 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
672 a C-V variant chain that threads across objfiles: if one
673 objfile gets freed, then the other has a broken C-V chain.
675 This code used to try to copy over the main type from TYPE to
676 *TYPEPTR if they were in different objfiles, but that's
677 wrong, too: TYPE may have a field list or member function
678 lists, which refer to types of their own, etc. etc. The
679 whole shebang would need to be copied over recursively; you
680 can't have inter-objfile pointers. The only thing to do is
681 to leave stub types as stub types, and look them up afresh by
682 name each time you encounter them. */
683 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
686 ntype = make_qualified_type (type, new_flags,
687 typeptr ? *typeptr : NULL);
695 /* Make a 'restrict'-qualified version of TYPE. */
698 make_restrict_type (struct type *type)
700 return make_qualified_type (type,
701 (TYPE_INSTANCE_FLAGS (type)
702 | TYPE_INSTANCE_FLAG_RESTRICT),
706 /* Replace the contents of ntype with the type *type. This changes the
707 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
708 the changes are propogated to all types in the TYPE_CHAIN.
710 In order to build recursive types, it's inevitable that we'll need
711 to update types in place --- but this sort of indiscriminate
712 smashing is ugly, and needs to be replaced with something more
713 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
714 clear if more steps are needed. */
717 replace_type (struct type *ntype, struct type *type)
721 /* These two types had better be in the same objfile. Otherwise,
722 the assignment of one type's main type structure to the other
723 will produce a type with references to objects (names; field
724 lists; etc.) allocated on an objfile other than its own. */
725 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
727 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
729 /* The type length is not a part of the main type. Update it for
730 each type on the variant chain. */
734 /* Assert that this element of the chain has no address-class bits
735 set in its flags. Such type variants might have type lengths
736 which are supposed to be different from the non-address-class
737 variants. This assertion shouldn't ever be triggered because
738 symbol readers which do construct address-class variants don't
739 call replace_type(). */
740 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
742 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
743 chain = TYPE_CHAIN (chain);
745 while (ntype != chain);
747 /* Assert that the two types have equivalent instance qualifiers.
748 This should be true for at least all of our debug readers. */
749 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
752 /* Implement direct support for MEMBER_TYPE in GNU C++.
753 May need to construct such a type if this is the first use.
754 The TYPE is the type of the member. The DOMAIN is the type
755 of the aggregate that the member belongs to. */
758 lookup_memberptr_type (struct type *type, struct type *domain)
762 mtype = alloc_type_copy (type);
763 smash_to_memberptr_type (mtype, domain, type);
767 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
770 lookup_methodptr_type (struct type *to_type)
774 mtype = alloc_type_copy (to_type);
775 smash_to_methodptr_type (mtype, to_type);
779 /* Allocate a stub method whose return type is TYPE. This apparently
780 happens for speed of symbol reading, since parsing out the
781 arguments to the method is cpu-intensive, the way we are doing it.
782 So, we will fill in arguments later. This always returns a fresh
786 allocate_stub_method (struct type *type)
790 mtype = alloc_type_copy (type);
791 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
792 TYPE_LENGTH (mtype) = 1;
793 TYPE_STUB (mtype) = 1;
794 TYPE_TARGET_TYPE (mtype) = type;
795 /* _DOMAIN_TYPE (mtype) = unknown yet */
799 /* Create a range type using either a blank type supplied in
800 RESULT_TYPE, or creating a new type, inheriting the objfile from
803 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
804 to HIGH_BOUND, inclusive.
806 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
807 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
810 create_range_type (struct type *result_type, struct type *index_type,
811 LONGEST low_bound, LONGEST high_bound)
813 if (result_type == NULL)
814 result_type = alloc_type_copy (index_type);
815 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
816 TYPE_TARGET_TYPE (result_type) = index_type;
817 if (TYPE_STUB (index_type))
818 TYPE_TARGET_STUB (result_type) = 1;
820 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
821 TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
822 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
823 TYPE_LOW_BOUND (result_type) = low_bound;
824 TYPE_HIGH_BOUND (result_type) = high_bound;
827 TYPE_UNSIGNED (result_type) = 1;
832 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
833 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
834 bounds will fit in LONGEST), or -1 otherwise. */
837 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
839 CHECK_TYPEDEF (type);
840 switch (TYPE_CODE (type))
842 case TYPE_CODE_RANGE:
843 *lowp = TYPE_LOW_BOUND (type);
844 *highp = TYPE_HIGH_BOUND (type);
847 if (TYPE_NFIELDS (type) > 0)
849 /* The enums may not be sorted by value, so search all
853 *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
854 for (i = 0; i < TYPE_NFIELDS (type); i++)
856 if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
857 *lowp = TYPE_FIELD_ENUMVAL (type, i);
858 if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
859 *highp = TYPE_FIELD_ENUMVAL (type, i);
862 /* Set unsigned indicator if warranted. */
865 TYPE_UNSIGNED (type) = 1;
879 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
881 if (!TYPE_UNSIGNED (type))
883 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
887 /* ... fall through for unsigned ints ... */
890 /* This round-about calculation is to avoid shifting by
891 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
892 if TYPE_LENGTH (type) == sizeof (LONGEST). */
893 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
894 *highp = (*highp - 1) | *highp;
901 /* Assuming TYPE is a simple, non-empty array type, compute its upper
902 and lower bound. Save the low bound into LOW_BOUND if not NULL.
903 Save the high bound into HIGH_BOUND if not NULL.
905 Return 1 if the operation was successful. Return zero otherwise,
906 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
908 We now simply use get_discrete_bounds call to get the values
909 of the low and high bounds.
910 get_discrete_bounds can return three values:
911 1, meaning that index is a range,
912 0, meaning that index is a discrete type,
913 or -1 for failure. */
916 get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
918 struct type *index = TYPE_INDEX_TYPE (type);
926 res = get_discrete_bounds (index, &low, &high);
930 /* Check if the array bounds are undefined. */
932 && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
933 || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
945 /* Create an array type using either a blank type supplied in
946 RESULT_TYPE, or creating a new type, inheriting the objfile from
949 Elements will be of type ELEMENT_TYPE, the indices will be of type
952 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
953 sure it is TYPE_CODE_UNDEF before we bash it into an array
957 create_array_type (struct type *result_type,
958 struct type *element_type,
959 struct type *range_type)
961 LONGEST low_bound, high_bound;
963 if (result_type == NULL)
964 result_type = alloc_type_copy (range_type);
966 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
967 TYPE_TARGET_TYPE (result_type) = element_type;
968 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
969 low_bound = high_bound = 0;
970 CHECK_TYPEDEF (element_type);
971 /* Be careful when setting the array length. Ada arrays can be
972 empty arrays with the high_bound being smaller than the low_bound.
973 In such cases, the array length should be zero. */
974 if (high_bound < low_bound)
975 TYPE_LENGTH (result_type) = 0;
977 TYPE_LENGTH (result_type) =
978 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
979 TYPE_NFIELDS (result_type) = 1;
980 TYPE_FIELDS (result_type) =
981 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
982 TYPE_INDEX_TYPE (result_type) = range_type;
983 TYPE_VPTR_FIELDNO (result_type) = -1;
985 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */
986 if (TYPE_LENGTH (result_type) == 0)
987 TYPE_TARGET_STUB (result_type) = 1;
993 lookup_array_range_type (struct type *element_type,
994 LONGEST low_bound, LONGEST high_bound)
996 struct gdbarch *gdbarch = get_type_arch (element_type);
997 struct type *index_type = builtin_type (gdbarch)->builtin_int;
998 struct type *range_type
999 = create_range_type (NULL, index_type, low_bound, high_bound);
1001 return create_array_type (NULL, element_type, range_type);
1004 /* Create a string type using either a blank type supplied in
1005 RESULT_TYPE, or creating a new type. String types are similar
1006 enough to array of char types that we can use create_array_type to
1007 build the basic type and then bash it into a string type.
1009 For fixed length strings, the range type contains 0 as the lower
1010 bound and the length of the string minus one as the upper bound.
1012 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1013 sure it is TYPE_CODE_UNDEF before we bash it into a string
1017 create_string_type (struct type *result_type,
1018 struct type *string_char_type,
1019 struct type *range_type)
1021 result_type = create_array_type (result_type,
1024 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1029 lookup_string_range_type (struct type *string_char_type,
1030 LONGEST low_bound, LONGEST high_bound)
1032 struct type *result_type;
1034 result_type = lookup_array_range_type (string_char_type,
1035 low_bound, high_bound);
1036 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1041 create_set_type (struct type *result_type, struct type *domain_type)
1043 if (result_type == NULL)
1044 result_type = alloc_type_copy (domain_type);
1046 TYPE_CODE (result_type) = TYPE_CODE_SET;
1047 TYPE_NFIELDS (result_type) = 1;
1048 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
1050 if (!TYPE_STUB (domain_type))
1052 LONGEST low_bound, high_bound, bit_length;
1054 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
1055 low_bound = high_bound = 0;
1056 bit_length = high_bound - low_bound + 1;
1057 TYPE_LENGTH (result_type)
1058 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1060 TYPE_UNSIGNED (result_type) = 1;
1062 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
1067 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1068 and any array types nested inside it. */
1071 make_vector_type (struct type *array_type)
1073 struct type *inner_array, *elt_type;
1076 /* Find the innermost array type, in case the array is
1077 multi-dimensional. */
1078 inner_array = array_type;
1079 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
1080 inner_array = TYPE_TARGET_TYPE (inner_array);
1082 elt_type = TYPE_TARGET_TYPE (inner_array);
1083 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
1085 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT;
1086 elt_type = make_qualified_type (elt_type, flags, NULL);
1087 TYPE_TARGET_TYPE (inner_array) = elt_type;
1090 TYPE_VECTOR (array_type) = 1;
1094 init_vector_type (struct type *elt_type, int n)
1096 struct type *array_type;
1098 array_type = lookup_array_range_type (elt_type, 0, n - 1);
1099 make_vector_type (array_type);
1103 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
1104 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1105 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1106 TYPE doesn't include the offset (that's the value of the MEMBER
1107 itself), but does include the structure type into which it points
1110 When "smashing" the type, we preserve the objfile that the old type
1111 pointed to, since we aren't changing where the type is actually
1115 smash_to_memberptr_type (struct type *type, struct type *domain,
1116 struct type *to_type)
1119 TYPE_TARGET_TYPE (type) = to_type;
1120 TYPE_DOMAIN_TYPE (type) = domain;
1121 /* Assume that a data member pointer is the same size as a normal
1124 = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT;
1125 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
1128 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1130 When "smashing" the type, we preserve the objfile that the old type
1131 pointed to, since we aren't changing where the type is actually
1135 smash_to_methodptr_type (struct type *type, struct type *to_type)
1138 TYPE_TARGET_TYPE (type) = to_type;
1139 TYPE_DOMAIN_TYPE (type) = TYPE_DOMAIN_TYPE (to_type);
1140 TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
1141 TYPE_CODE (type) = TYPE_CODE_METHODPTR;
1144 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1145 METHOD just means `function that gets an extra "this" argument'.
1147 When "smashing" the type, we preserve the objfile that the old type
1148 pointed to, since we aren't changing where the type is actually
1152 smash_to_method_type (struct type *type, struct type *domain,
1153 struct type *to_type, struct field *args,
1154 int nargs, int varargs)
1157 TYPE_TARGET_TYPE (type) = to_type;
1158 TYPE_DOMAIN_TYPE (type) = domain;
1159 TYPE_FIELDS (type) = args;
1160 TYPE_NFIELDS (type) = nargs;
1162 TYPE_VARARGS (type) = 1;
1163 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1164 TYPE_CODE (type) = TYPE_CODE_METHOD;
1167 /* Return a typename for a struct/union/enum type without "struct ",
1168 "union ", or "enum ". If the type has a NULL name, return NULL. */
1171 type_name_no_tag (const struct type *type)
1173 if (TYPE_TAG_NAME (type) != NULL)
1174 return TYPE_TAG_NAME (type);
1176 /* Is there code which expects this to return the name if there is
1177 no tag name? My guess is that this is mainly used for C++ in
1178 cases where the two will always be the same. */
1179 return TYPE_NAME (type);
1182 /* A wrapper of type_name_no_tag which calls error if the type is anonymous.
1183 Since GCC PR debug/47510 DWARF provides associated information to detect the
1184 anonymous class linkage name from its typedef.
1186 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1190 type_name_no_tag_or_error (struct type *type)
1192 struct type *saved_type = type;
1194 struct objfile *objfile;
1196 CHECK_TYPEDEF (type);
1198 name = type_name_no_tag (type);
1202 name = type_name_no_tag (saved_type);
1203 objfile = TYPE_OBJFILE (saved_type);
1204 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1205 name ? name : "<anonymous>",
1206 objfile ? objfile_name (objfile) : "<arch>");
1209 /* Lookup a typedef or primitive type named NAME, visible in lexical
1210 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1211 suitably defined. */
1214 lookup_typename (const struct language_defn *language,
1215 struct gdbarch *gdbarch, const char *name,
1216 const struct block *block, int noerr)
1221 sym = lookup_symbol (name, block, VAR_DOMAIN, 0);
1222 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1223 return SYMBOL_TYPE (sym);
1225 type = language_lookup_primitive_type_by_name (language, gdbarch, name);
1231 error (_("No type named %s."), name);
1235 lookup_unsigned_typename (const struct language_defn *language,
1236 struct gdbarch *gdbarch, const char *name)
1238 char *uns = alloca (strlen (name) + 10);
1240 strcpy (uns, "unsigned ");
1241 strcpy (uns + 9, name);
1242 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0);
1246 lookup_signed_typename (const struct language_defn *language,
1247 struct gdbarch *gdbarch, const char *name)
1250 char *uns = alloca (strlen (name) + 8);
1252 strcpy (uns, "signed ");
1253 strcpy (uns + 7, name);
1254 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1);
1255 /* If we don't find "signed FOO" just try again with plain "FOO". */
1258 return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0);
1261 /* Lookup a structure type named "struct NAME",
1262 visible in lexical block BLOCK. */
1265 lookup_struct (const char *name, const struct block *block)
1269 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1273 error (_("No struct type named %s."), name);
1275 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1277 error (_("This context has class, union or enum %s, not a struct."),
1280 return (SYMBOL_TYPE (sym));
1283 /* Lookup a union type named "union NAME",
1284 visible in lexical block BLOCK. */
1287 lookup_union (const char *name, const struct block *block)
1292 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1295 error (_("No union type named %s."), name);
1297 t = SYMBOL_TYPE (sym);
1299 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1302 /* If we get here, it's not a union. */
1303 error (_("This context has class, struct or enum %s, not a union."),
1307 /* Lookup an enum type named "enum NAME",
1308 visible in lexical block BLOCK. */
1311 lookup_enum (const char *name, const struct block *block)
1315 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1318 error (_("No enum type named %s."), name);
1320 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1322 error (_("This context has class, struct or union %s, not an enum."),
1325 return (SYMBOL_TYPE (sym));
1328 /* Lookup a template type named "template NAME<TYPE>",
1329 visible in lexical block BLOCK. */
1332 lookup_template_type (char *name, struct type *type,
1333 const struct block *block)
1336 char *nam = (char *)
1337 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1341 strcat (nam, TYPE_NAME (type));
1342 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1344 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0);
1348 error (_("No template type named %s."), name);
1350 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1352 error (_("This context has class, union or enum %s, not a struct."),
1355 return (SYMBOL_TYPE (sym));
1358 /* Given a type TYPE, lookup the type of the component of type named
1361 TYPE can be either a struct or union, or a pointer or reference to
1362 a struct or union. If it is a pointer or reference, its target
1363 type is automatically used. Thus '.' and '->' are interchangable,
1364 as specified for the definitions of the expression element types
1365 STRUCTOP_STRUCT and STRUCTOP_PTR.
1367 If NOERR is nonzero, return zero if NAME is not suitably defined.
1368 If NAME is the name of a baseclass type, return that type. */
1371 lookup_struct_elt_type (struct type *type, const char *name, int noerr)
1378 CHECK_TYPEDEF (type);
1379 if (TYPE_CODE (type) != TYPE_CODE_PTR
1380 && TYPE_CODE (type) != TYPE_CODE_REF)
1382 type = TYPE_TARGET_TYPE (type);
1385 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1386 && TYPE_CODE (type) != TYPE_CODE_UNION)
1388 typename = type_to_string (type);
1389 make_cleanup (xfree, typename);
1390 error (_("Type %s is not a structure or union type."), typename);
1394 /* FIXME: This change put in by Michael seems incorrect for the case
1395 where the structure tag name is the same as the member name.
1396 I.e. when doing "ptype bell->bar" for "struct foo { int bar; int
1397 foo; } bell;" Disabled by fnf. */
1401 typename = type_name_no_tag (type);
1402 if (typename != NULL && strcmp (typename, name) == 0)
1407 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1409 const char *t_field_name = TYPE_FIELD_NAME (type, i);
1411 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1413 return TYPE_FIELD_TYPE (type, i);
1415 else if (!t_field_name || *t_field_name == '\0')
1417 struct type *subtype
1418 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1);
1420 if (subtype != NULL)
1425 /* OK, it's not in this class. Recursively check the baseclasses. */
1426 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1430 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1442 typename = type_to_string (type);
1443 make_cleanup (xfree, typename);
1444 error (_("Type %s has no component named %s."), typename, name);
1447 /* Lookup the vptr basetype/fieldno values for TYPE.
1448 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1449 vptr_fieldno. Also, if found and basetype is from the same objfile,
1451 If not found, return -1 and ignore BASETYPEP.
1452 Callers should be aware that in some cases (for example,
1453 the type or one of its baseclasses is a stub type and we are
1454 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1455 this function will not be able to find the
1456 virtual function table pointer, and vptr_fieldno will remain -1 and
1457 vptr_basetype will remain NULL or incomplete. */
1460 get_vptr_fieldno (struct type *type, struct type **basetypep)
1462 CHECK_TYPEDEF (type);
1464 if (TYPE_VPTR_FIELDNO (type) < 0)
1468 /* We must start at zero in case the first (and only) baseclass
1469 is virtual (and hence we cannot share the table pointer). */
1470 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1472 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1474 struct type *basetype;
1476 fieldno = get_vptr_fieldno (baseclass, &basetype);
1479 /* If the type comes from a different objfile we can't cache
1480 it, it may have a different lifetime. PR 2384 */
1481 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
1483 TYPE_VPTR_FIELDNO (type) = fieldno;
1484 TYPE_VPTR_BASETYPE (type) = basetype;
1487 *basetypep = basetype;
1498 *basetypep = TYPE_VPTR_BASETYPE (type);
1499 return TYPE_VPTR_FIELDNO (type);
1504 stub_noname_complaint (void)
1506 complaint (&symfile_complaints, _("stub type has NULL name"));
1509 /* Find the real type of TYPE. This function returns the real type,
1510 after removing all layers of typedefs, and completing opaque or stub
1511 types. Completion changes the TYPE argument, but stripping of
1514 Instance flags (e.g. const/volatile) are preserved as typedefs are
1515 stripped. If necessary a new qualified form of the underlying type
1518 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
1519 not been computed and we're either in the middle of reading symbols, or
1520 there was no name for the typedef in the debug info.
1522 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
1523 QUITs in the symbol reading code can also throw.
1524 Thus this function can throw an exception.
1526 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
1529 If this is a stubbed struct (i.e. declared as struct foo *), see if
1530 we can find a full definition in some other file. If so, copy this
1531 definition, so we can use it in future. There used to be a comment
1532 (but not any code) that if we don't find a full definition, we'd
1533 set a flag so we don't spend time in the future checking the same
1534 type. That would be a mistake, though--we might load in more
1535 symbols which contain a full definition for the type. */
1538 check_typedef (struct type *type)
1540 struct type *orig_type = type;
1541 /* While we're removing typedefs, we don't want to lose qualifiers.
1542 E.g., const/volatile. */
1543 int instance_flags = TYPE_INSTANCE_FLAGS (type);
1547 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1549 if (!TYPE_TARGET_TYPE (type))
1554 /* It is dangerous to call lookup_symbol if we are currently
1555 reading a symtab. Infinite recursion is one danger. */
1556 if (currently_reading_symtab)
1557 return make_qualified_type (type, instance_flags, NULL);
1559 name = type_name_no_tag (type);
1560 /* FIXME: shouldn't we separately check the TYPE_NAME and
1561 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1562 VAR_DOMAIN as appropriate? (this code was written before
1563 TYPE_NAME and TYPE_TAG_NAME were separate). */
1566 stub_noname_complaint ();
1567 return make_qualified_type (type, instance_flags, NULL);
1569 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1571 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1572 else /* TYPE_CODE_UNDEF */
1573 TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type));
1575 type = TYPE_TARGET_TYPE (type);
1577 /* Preserve the instance flags as we traverse down the typedef chain.
1579 Handling address spaces/classes is nasty, what do we do if there's a
1581 E.g., what if an outer typedef marks the type as class_1 and an inner
1582 typedef marks the type as class_2?
1583 This is the wrong place to do such error checking. We leave it to
1584 the code that created the typedef in the first place to flag the
1585 error. We just pick the outer address space (akin to letting the
1586 outer cast in a chain of casting win), instead of assuming
1587 "it can't happen". */
1589 const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE
1590 | TYPE_INSTANCE_FLAG_DATA_SPACE);
1591 const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
1592 int new_instance_flags = TYPE_INSTANCE_FLAGS (type);
1594 /* Treat code vs data spaces and address classes separately. */
1595 if ((instance_flags & ALL_SPACES) != 0)
1596 new_instance_flags &= ~ALL_SPACES;
1597 if ((instance_flags & ALL_CLASSES) != 0)
1598 new_instance_flags &= ~ALL_CLASSES;
1600 instance_flags |= new_instance_flags;
1604 /* If this is a struct/class/union with no fields, then check
1605 whether a full definition exists somewhere else. This is for
1606 systems where a type definition with no fields is issued for such
1607 types, instead of identifying them as stub types in the first
1610 if (TYPE_IS_OPAQUE (type)
1611 && opaque_type_resolution
1612 && !currently_reading_symtab)
1614 const char *name = type_name_no_tag (type);
1615 struct type *newtype;
1619 stub_noname_complaint ();
1620 return make_qualified_type (type, instance_flags, NULL);
1622 newtype = lookup_transparent_type (name);
1626 /* If the resolved type and the stub are in the same
1627 objfile, then replace the stub type with the real deal.
1628 But if they're in separate objfiles, leave the stub
1629 alone; we'll just look up the transparent type every time
1630 we call check_typedef. We can't create pointers between
1631 types allocated to different objfiles, since they may
1632 have different lifetimes. Trying to copy NEWTYPE over to
1633 TYPE's objfile is pointless, too, since you'll have to
1634 move over any other types NEWTYPE refers to, which could
1635 be an unbounded amount of stuff. */
1636 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
1637 type = make_qualified_type (newtype,
1638 TYPE_INSTANCE_FLAGS (type),
1644 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1646 else if (TYPE_STUB (type) && !currently_reading_symtab)
1648 const char *name = type_name_no_tag (type);
1649 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1650 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1651 as appropriate? (this code was written before TYPE_NAME and
1652 TYPE_TAG_NAME were separate). */
1657 stub_noname_complaint ();
1658 return make_qualified_type (type, instance_flags, NULL);
1660 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1663 /* Same as above for opaque types, we can replace the stub
1664 with the complete type only if they are in the same
1666 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
1667 type = make_qualified_type (SYMBOL_TYPE (sym),
1668 TYPE_INSTANCE_FLAGS (type),
1671 type = SYMBOL_TYPE (sym);
1675 if (TYPE_TARGET_STUB (type))
1677 struct type *range_type;
1678 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1680 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1682 /* Nothing we can do. */
1684 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1685 && TYPE_NFIELDS (type) == 1
1686 && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
1687 == TYPE_CODE_RANGE))
1689 /* Now recompute the length of the array type, based on its
1690 number of elements and the target type's length.
1691 Watch out for Ada null Ada arrays where the high bound
1692 is smaller than the low bound. */
1693 const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
1694 const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
1697 if (high_bound < low_bound)
1701 /* For now, we conservatively take the array length to be 0
1702 if its length exceeds UINT_MAX. The code below assumes
1703 that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
1704 which is technically not guaranteed by C, but is usually true
1705 (because it would be true if x were unsigned with its
1706 high-order bit on). It uses the fact that
1707 high_bound-low_bound is always representable in
1708 ULONGEST and that if high_bound-low_bound+1 overflows,
1709 it overflows to 0. We must change these tests if we
1710 decide to increase the representation of TYPE_LENGTH
1711 from unsigned int to ULONGEST. */
1712 ULONGEST ulow = low_bound, uhigh = high_bound;
1713 ULONGEST tlen = TYPE_LENGTH (target_type);
1715 len = tlen * (uhigh - ulow + 1);
1716 if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh
1720 TYPE_LENGTH (type) = len;
1721 TYPE_TARGET_STUB (type) = 0;
1723 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1725 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1726 TYPE_TARGET_STUB (type) = 0;
1730 type = make_qualified_type (type, instance_flags, NULL);
1732 /* Cache TYPE_LENGTH for future use. */
1733 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1738 /* Parse a type expression in the string [P..P+LENGTH). If an error
1739 occurs, silently return a void type. */
1741 static struct type *
1742 safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
1744 struct ui_file *saved_gdb_stderr;
1745 struct type *type = NULL; /* Initialize to keep gcc happy. */
1746 volatile struct gdb_exception except;
1748 /* Suppress error messages. */
1749 saved_gdb_stderr = gdb_stderr;
1750 gdb_stderr = ui_file_new ();
1752 /* Call parse_and_eval_type() without fear of longjmp()s. */
1753 TRY_CATCH (except, RETURN_MASK_ERROR)
1755 type = parse_and_eval_type (p, length);
1758 if (except.reason < 0)
1759 type = builtin_type (gdbarch)->builtin_void;
1761 /* Stop suppressing error messages. */
1762 ui_file_delete (gdb_stderr);
1763 gdb_stderr = saved_gdb_stderr;
1768 /* Ugly hack to convert method stubs into method types.
1770 He ain't kiddin'. This demangles the name of the method into a
1771 string including argument types, parses out each argument type,
1772 generates a string casting a zero to that type, evaluates the
1773 string, and stuffs the resulting type into an argtype vector!!!
1774 Then it knows the type of the whole function (including argument
1775 types for overloading), which info used to be in the stab's but was
1776 removed to hack back the space required for them. */
1779 check_stub_method (struct type *type, int method_id, int signature_id)
1781 struct gdbarch *gdbarch = get_type_arch (type);
1783 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1784 char *demangled_name = gdb_demangle (mangled_name,
1785 DMGL_PARAMS | DMGL_ANSI);
1786 char *argtypetext, *p;
1787 int depth = 0, argcount = 1;
1788 struct field *argtypes;
1791 /* Make sure we got back a function string that we can use. */
1793 p = strchr (demangled_name, '(');
1797 if (demangled_name == NULL || p == NULL)
1798 error (_("Internal: Cannot demangle mangled name `%s'."),
1801 /* Now, read in the parameters that define this type. */
1806 if (*p == '(' || *p == '<')
1810 else if (*p == ')' || *p == '>')
1814 else if (*p == ',' && depth == 0)
1822 /* If we read one argument and it was ``void'', don't count it. */
1823 if (strncmp (argtypetext, "(void)", 6) == 0)
1826 /* We need one extra slot, for the THIS pointer. */
1828 argtypes = (struct field *)
1829 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1832 /* Add THIS pointer for non-static methods. */
1833 f = TYPE_FN_FIELDLIST1 (type, method_id);
1834 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1838 argtypes[0].type = lookup_pointer_type (type);
1842 if (*p != ')') /* () means no args, skip while. */
1847 if (depth <= 0 && (*p == ',' || *p == ')'))
1849 /* Avoid parsing of ellipsis, they will be handled below.
1850 Also avoid ``void'' as above. */
1851 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1852 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1854 argtypes[argcount].type =
1855 safe_parse_type (gdbarch, argtypetext, p - argtypetext);
1858 argtypetext = p + 1;
1861 if (*p == '(' || *p == '<')
1865 else if (*p == ')' || *p == '>')
1874 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1876 /* Now update the old "stub" type into a real type. */
1877 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1878 TYPE_DOMAIN_TYPE (mtype) = type;
1879 TYPE_FIELDS (mtype) = argtypes;
1880 TYPE_NFIELDS (mtype) = argcount;
1881 TYPE_STUB (mtype) = 0;
1882 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1884 TYPE_VARARGS (mtype) = 1;
1886 xfree (demangled_name);
1889 /* This is the external interface to check_stub_method, above. This
1890 function unstubs all of the signatures for TYPE's METHOD_ID method
1891 name. After calling this function TYPE_FN_FIELD_STUB will be
1892 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1895 This function unfortunately can not die until stabs do. */
1898 check_stub_method_group (struct type *type, int method_id)
1900 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1901 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1902 int j, found_stub = 0;
1904 for (j = 0; j < len; j++)
1905 if (TYPE_FN_FIELD_STUB (f, j))
1908 check_stub_method (type, method_id, j);
1911 /* GNU v3 methods with incorrect names were corrected when we read
1912 in type information, because it was cheaper to do it then. The
1913 only GNU v2 methods with incorrect method names are operators and
1914 destructors; destructors were also corrected when we read in type
1917 Therefore the only thing we need to handle here are v2 operator
1919 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1922 char dem_opname[256];
1924 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1926 dem_opname, DMGL_ANSI);
1928 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1932 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1936 /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
1937 const struct cplus_struct_type cplus_struct_default = { };
1940 allocate_cplus_struct_type (struct type *type)
1942 if (HAVE_CPLUS_STRUCT (type))
1943 /* Structure was already allocated. Nothing more to do. */
1946 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF;
1947 TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1948 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1949 *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1952 const struct gnat_aux_type gnat_aux_default =
1955 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
1956 and allocate the associated gnat-specific data. The gnat-specific
1957 data is also initialized to gnat_aux_default. */
1960 allocate_gnat_aux_type (struct type *type)
1962 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF;
1963 TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *)
1964 TYPE_ALLOC (type, sizeof (struct gnat_aux_type));
1965 *(TYPE_GNAT_SPECIFIC (type)) = gnat_aux_default;
1968 /* Helper function to initialize the standard scalar types.
1970 If NAME is non-NULL, then it is used to initialize the type name.
1971 Note that NAME is not copied; it is required to have a lifetime at
1972 least as long as OBJFILE. */
1975 init_type (enum type_code code, int length, int flags,
1976 const char *name, struct objfile *objfile)
1980 type = alloc_type (objfile);
1981 TYPE_CODE (type) = code;
1982 TYPE_LENGTH (type) = length;
1984 gdb_assert (!(flags & (TYPE_FLAG_MIN - 1)));
1985 if (flags & TYPE_FLAG_UNSIGNED)
1986 TYPE_UNSIGNED (type) = 1;
1987 if (flags & TYPE_FLAG_NOSIGN)
1988 TYPE_NOSIGN (type) = 1;
1989 if (flags & TYPE_FLAG_STUB)
1990 TYPE_STUB (type) = 1;
1991 if (flags & TYPE_FLAG_TARGET_STUB)
1992 TYPE_TARGET_STUB (type) = 1;
1993 if (flags & TYPE_FLAG_STATIC)
1994 TYPE_STATIC (type) = 1;
1995 if (flags & TYPE_FLAG_PROTOTYPED)
1996 TYPE_PROTOTYPED (type) = 1;
1997 if (flags & TYPE_FLAG_INCOMPLETE)
1998 TYPE_INCOMPLETE (type) = 1;
1999 if (flags & TYPE_FLAG_VARARGS)
2000 TYPE_VARARGS (type) = 1;
2001 if (flags & TYPE_FLAG_VECTOR)
2002 TYPE_VECTOR (type) = 1;
2003 if (flags & TYPE_FLAG_STUB_SUPPORTED)
2004 TYPE_STUB_SUPPORTED (type) = 1;
2005 if (flags & TYPE_FLAG_FIXED_INSTANCE)
2006 TYPE_FIXED_INSTANCE (type) = 1;
2007 if (flags & TYPE_FLAG_GNU_IFUNC)
2008 TYPE_GNU_IFUNC (type) = 1;
2010 TYPE_NAME (type) = name;
2014 if (name && strcmp (name, "char") == 0)
2015 TYPE_NOSIGN (type) = 1;
2019 case TYPE_CODE_STRUCT:
2020 case TYPE_CODE_UNION:
2021 case TYPE_CODE_NAMESPACE:
2022 INIT_CPLUS_SPECIFIC (type);
2025 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT;
2027 case TYPE_CODE_FUNC:
2028 INIT_FUNC_SPECIFIC (type);
2034 /* Queries on types. */
2037 can_dereference (struct type *t)
2039 /* FIXME: Should we return true for references as well as
2044 && TYPE_CODE (t) == TYPE_CODE_PTR
2045 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
2049 is_integral_type (struct type *t)
2054 && ((TYPE_CODE (t) == TYPE_CODE_INT)
2055 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
2056 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
2057 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
2058 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
2059 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
2062 /* Return true if TYPE is scalar. */
2065 is_scalar_type (struct type *type)
2067 CHECK_TYPEDEF (type);
2069 switch (TYPE_CODE (type))
2071 case TYPE_CODE_ARRAY:
2072 case TYPE_CODE_STRUCT:
2073 case TYPE_CODE_UNION:
2075 case TYPE_CODE_STRING:
2082 /* Return true if T is scalar, or a composite type which in practice has
2083 the memory layout of a scalar type. E.g., an array or struct with only
2084 one scalar element inside it, or a union with only scalar elements. */
2087 is_scalar_type_recursive (struct type *t)
2091 if (is_scalar_type (t))
2093 /* Are we dealing with an array or string of known dimensions? */
2094 else if ((TYPE_CODE (t) == TYPE_CODE_ARRAY
2095 || TYPE_CODE (t) == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1
2096 && TYPE_CODE (TYPE_INDEX_TYPE (t)) == TYPE_CODE_RANGE)
2098 LONGEST low_bound, high_bound;
2099 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (t));
2101 get_discrete_bounds (TYPE_INDEX_TYPE (t), &low_bound, &high_bound);
2103 return high_bound == low_bound && is_scalar_type_recursive (elt_type);
2105 /* Are we dealing with a struct with one element? */
2106 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1)
2107 return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0));
2108 else if (TYPE_CODE (t) == TYPE_CODE_UNION)
2110 int i, n = TYPE_NFIELDS (t);
2112 /* If all elements of the union are scalar, then the union is scalar. */
2113 for (i = 0; i < n; i++)
2114 if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t, i)))
2123 /* A helper function which returns true if types A and B represent the
2124 "same" class type. This is true if the types have the same main
2125 type, or the same name. */
2128 class_types_same_p (const struct type *a, const struct type *b)
2130 return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b)
2131 || (TYPE_NAME (a) && TYPE_NAME (b)
2132 && !strcmp (TYPE_NAME (a), TYPE_NAME (b))));
2135 /* If BASE is an ancestor of DCLASS return the distance between them.
2136 otherwise return -1;
2140 class B: public A {};
2141 class C: public B {};
2144 distance_to_ancestor (A, A, 0) = 0
2145 distance_to_ancestor (A, B, 0) = 1
2146 distance_to_ancestor (A, C, 0) = 2
2147 distance_to_ancestor (A, D, 0) = 3
2149 If PUBLIC is 1 then only public ancestors are considered,
2150 and the function returns the distance only if BASE is a public ancestor
2154 distance_to_ancestor (A, D, 1) = -1. */
2157 distance_to_ancestor (struct type *base, struct type *dclass, int public)
2162 CHECK_TYPEDEF (base);
2163 CHECK_TYPEDEF (dclass);
2165 if (class_types_same_p (base, dclass))
2168 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2170 if (public && ! BASETYPE_VIA_PUBLIC (dclass, i))
2173 d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), public);
2181 /* Check whether BASE is an ancestor or base class or DCLASS
2182 Return 1 if so, and 0 if not.
2183 Note: If BASE and DCLASS are of the same type, this function
2184 will return 1. So for some class A, is_ancestor (A, A) will
2188 is_ancestor (struct type *base, struct type *dclass)
2190 return distance_to_ancestor (base, dclass, 0) >= 0;
2193 /* Like is_ancestor, but only returns true when BASE is a public
2194 ancestor of DCLASS. */
2197 is_public_ancestor (struct type *base, struct type *dclass)
2199 return distance_to_ancestor (base, dclass, 1) >= 0;
2202 /* A helper function for is_unique_ancestor. */
2205 is_unique_ancestor_worker (struct type *base, struct type *dclass,
2207 const gdb_byte *valaddr, int embedded_offset,
2208 CORE_ADDR address, struct value *val)
2212 CHECK_TYPEDEF (base);
2213 CHECK_TYPEDEF (dclass);
2215 for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
2220 iter = check_typedef (TYPE_BASECLASS (dclass, i));
2222 this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset,
2225 if (class_types_same_p (base, iter))
2227 /* If this is the first subclass, set *OFFSET and set count
2228 to 1. Otherwise, if this is at the same offset as
2229 previous instances, do nothing. Otherwise, increment
2233 *offset = this_offset;
2236 else if (this_offset == *offset)
2244 count += is_unique_ancestor_worker (base, iter, offset,
2246 embedded_offset + this_offset,
2253 /* Like is_ancestor, but only returns true if BASE is a unique base
2254 class of the type of VAL. */
2257 is_unique_ancestor (struct type *base, struct value *val)
2261 return is_unique_ancestor_worker (base, value_type (val), &offset,
2262 value_contents_for_printing (val),
2263 value_embedded_offset (val),
2264 value_address (val), val) == 1;
2268 /* Overload resolution. */
2270 /* Return the sum of the rank of A with the rank of B. */
2273 sum_ranks (struct rank a, struct rank b)
2276 c.rank = a.rank + b.rank;
2277 c.subrank = a.subrank + b.subrank;
2281 /* Compare rank A and B and return:
2283 1 if a is better than b
2284 -1 if b is better than a. */
2287 compare_ranks (struct rank a, struct rank b)
2289 if (a.rank == b.rank)
2291 if (a.subrank == b.subrank)
2293 if (a.subrank < b.subrank)
2295 if (a.subrank > b.subrank)
2299 if (a.rank < b.rank)
2302 /* a.rank > b.rank */
2306 /* Functions for overload resolution begin here. */
2308 /* Compare two badness vectors A and B and return the result.
2309 0 => A and B are identical
2310 1 => A and B are incomparable
2311 2 => A is better than B
2312 3 => A is worse than B */
2315 compare_badness (struct badness_vector *a, struct badness_vector *b)
2319 short found_pos = 0; /* any positives in c? */
2320 short found_neg = 0; /* any negatives in c? */
2322 /* differing lengths => incomparable */
2323 if (a->length != b->length)
2326 /* Subtract b from a */
2327 for (i = 0; i < a->length; i++)
2329 tmp = compare_ranks (b->rank[i], a->rank[i]);
2339 return 1; /* incomparable */
2341 return 3; /* A > B */
2347 return 2; /* A < B */
2349 return 0; /* A == B */
2353 /* Rank a function by comparing its parameter types (PARMS, length
2354 NPARMS), to the types of an argument list (ARGS, length NARGS).
2355 Return a pointer to a badness vector. This has NARGS + 1
2358 struct badness_vector *
2359 rank_function (struct type **parms, int nparms,
2360 struct value **args, int nargs)
2363 struct badness_vector *bv;
2364 int min_len = nparms < nargs ? nparms : nargs;
2366 bv = xmalloc (sizeof (struct badness_vector));
2367 bv->length = nargs + 1; /* add 1 for the length-match rank. */
2368 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2370 /* First compare the lengths of the supplied lists.
2371 If there is a mismatch, set it to a high value. */
2373 /* pai/1997-06-03 FIXME: when we have debug info about default
2374 arguments and ellipsis parameter lists, we should consider those
2375 and rank the length-match more finely. */
2377 LENGTH_MATCH (bv) = (nargs != nparms)
2378 ? LENGTH_MISMATCH_BADNESS
2379 : EXACT_MATCH_BADNESS;
2381 /* Now rank all the parameters of the candidate function. */
2382 for (i = 1; i <= min_len; i++)
2383 bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]),
2386 /* If more arguments than parameters, add dummy entries. */
2387 for (i = min_len + 1; i <= nargs; i++)
2388 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2393 /* Compare the names of two integer types, assuming that any sign
2394 qualifiers have been checked already. We do it this way because
2395 there may be an "int" in the name of one of the types. */
2398 integer_types_same_name_p (const char *first, const char *second)
2400 int first_p, second_p;
2402 /* If both are shorts, return 1; if neither is a short, keep
2404 first_p = (strstr (first, "short") != NULL);
2405 second_p = (strstr (second, "short") != NULL);
2406 if (first_p && second_p)
2408 if (first_p || second_p)
2411 /* Likewise for long. */
2412 first_p = (strstr (first, "long") != NULL);
2413 second_p = (strstr (second, "long") != NULL);
2414 if (first_p && second_p)
2416 if (first_p || second_p)
2419 /* Likewise for char. */
2420 first_p = (strstr (first, "char") != NULL);
2421 second_p = (strstr (second, "char") != NULL);
2422 if (first_p && second_p)
2424 if (first_p || second_p)
2427 /* They must both be ints. */
2431 /* Compares type A to type B returns 1 if the represent the same type
2435 types_equal (struct type *a, struct type *b)
2437 /* Identical type pointers. */
2438 /* However, this still doesn't catch all cases of same type for b
2439 and a. The reason is that builtin types are different from
2440 the same ones constructed from the object. */
2444 /* Resolve typedefs */
2445 if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF)
2446 a = check_typedef (a);
2447 if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF)
2448 b = check_typedef (b);
2450 /* If after resolving typedefs a and b are not of the same type
2451 code then they are not equal. */
2452 if (TYPE_CODE (a) != TYPE_CODE (b))
2455 /* If a and b are both pointers types or both reference types then
2456 they are equal of the same type iff the objects they refer to are
2457 of the same type. */
2458 if (TYPE_CODE (a) == TYPE_CODE_PTR
2459 || TYPE_CODE (a) == TYPE_CODE_REF)
2460 return types_equal (TYPE_TARGET_TYPE (a),
2461 TYPE_TARGET_TYPE (b));
2463 /* Well, damnit, if the names are exactly the same, I'll say they
2464 are exactly the same. This happens when we generate method
2465 stubs. The types won't point to the same address, but they
2466 really are the same. */
2468 if (TYPE_NAME (a) && TYPE_NAME (b)
2469 && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0)
2472 /* Check if identical after resolving typedefs. */
2476 /* Two function types are equal if their argument and return types
2478 if (TYPE_CODE (a) == TYPE_CODE_FUNC)
2482 if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
2485 if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
2488 for (i = 0; i < TYPE_NFIELDS (a); ++i)
2489 if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
2498 /* Compare one type (PARM) for compatibility with another (ARG).
2499 * PARM is intended to be the parameter type of a function; and
2500 * ARG is the supplied argument's type. This function tests if
2501 * the latter can be converted to the former.
2502 * VALUE is the argument's value or NULL if none (or called recursively)
2504 * Return 0 if they are identical types;
2505 * Otherwise, return an integer which corresponds to how compatible
2506 * PARM is to ARG. The higher the return value, the worse the match.
2507 * Generally the "bad" conversions are all uniformly assigned a 100. */
2510 rank_one_type (struct type *parm, struct type *arg, struct value *value)
2512 struct rank rank = {0,0};
2514 if (types_equal (parm, arg))
2515 return EXACT_MATCH_BADNESS;
2517 /* Resolve typedefs */
2518 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2519 parm = check_typedef (parm);
2520 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2521 arg = check_typedef (arg);
2523 /* See through references, since we can almost make non-references
2525 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2526 return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
2527 REFERENCE_CONVERSION_BADNESS));
2528 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2529 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
2530 REFERENCE_CONVERSION_BADNESS));
2532 /* Debugging only. */
2533 fprintf_filtered (gdb_stderr,
2534 "------ Arg is %s [%d], parm is %s [%d]\n",
2535 TYPE_NAME (arg), TYPE_CODE (arg),
2536 TYPE_NAME (parm), TYPE_CODE (parm));
2538 /* x -> y means arg of type x being supplied for parameter of type y. */
2540 switch (TYPE_CODE (parm))
2543 switch (TYPE_CODE (arg))
2547 /* Allowed pointer conversions are:
2548 (a) pointer to void-pointer conversion. */
2549 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2550 return VOID_PTR_CONVERSION_BADNESS;
2552 /* (b) pointer to ancestor-pointer conversion. */
2553 rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
2554 TYPE_TARGET_TYPE (arg),
2556 if (rank.subrank >= 0)
2557 return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
2559 return INCOMPATIBLE_TYPE_BADNESS;
2560 case TYPE_CODE_ARRAY:
2561 if (types_equal (TYPE_TARGET_TYPE (parm),
2562 TYPE_TARGET_TYPE (arg)))
2563 return EXACT_MATCH_BADNESS;
2564 return INCOMPATIBLE_TYPE_BADNESS;
2565 case TYPE_CODE_FUNC:
2566 return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
2568 if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
2570 if (value_as_long (value) == 0)
2572 /* Null pointer conversion: allow it to be cast to a pointer.
2573 [4.10.1 of C++ standard draft n3290] */
2574 return NULL_POINTER_CONVERSION_BADNESS;
2578 /* If type checking is disabled, allow the conversion. */
2579 if (!strict_type_checking)
2580 return NS_INTEGER_POINTER_CONVERSION_BADNESS;
2584 case TYPE_CODE_ENUM:
2585 case TYPE_CODE_FLAGS:
2586 case TYPE_CODE_CHAR:
2587 case TYPE_CODE_RANGE:
2588 case TYPE_CODE_BOOL:
2590 return INCOMPATIBLE_TYPE_BADNESS;
2592 case TYPE_CODE_ARRAY:
2593 switch (TYPE_CODE (arg))
2596 case TYPE_CODE_ARRAY:
2597 return rank_one_type (TYPE_TARGET_TYPE (parm),
2598 TYPE_TARGET_TYPE (arg), NULL);
2600 return INCOMPATIBLE_TYPE_BADNESS;
2602 case TYPE_CODE_FUNC:
2603 switch (TYPE_CODE (arg))
2605 case TYPE_CODE_PTR: /* funcptr -> func */
2606 return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
2608 return INCOMPATIBLE_TYPE_BADNESS;
2611 switch (TYPE_CODE (arg))
2614 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2616 /* Deal with signed, unsigned, and plain chars and
2617 signed and unsigned ints. */
2618 if (TYPE_NOSIGN (parm))
2620 /* This case only for character types. */
2621 if (TYPE_NOSIGN (arg))
2622 return EXACT_MATCH_BADNESS; /* plain char -> plain char */
2623 else /* signed/unsigned char -> plain char */
2624 return INTEGER_CONVERSION_BADNESS;
2626 else if (TYPE_UNSIGNED (parm))
2628 if (TYPE_UNSIGNED (arg))
2630 /* unsigned int -> unsigned int, or
2631 unsigned long -> unsigned long */
2632 if (integer_types_same_name_p (TYPE_NAME (parm),
2634 return EXACT_MATCH_BADNESS;
2635 else if (integer_types_same_name_p (TYPE_NAME (arg),
2637 && integer_types_same_name_p (TYPE_NAME (parm),
2639 /* unsigned int -> unsigned long */
2640 return INTEGER_PROMOTION_BADNESS;
2642 /* unsigned long -> unsigned int */
2643 return INTEGER_CONVERSION_BADNESS;
2647 if (integer_types_same_name_p (TYPE_NAME (arg),
2649 && integer_types_same_name_p (TYPE_NAME (parm),
2651 /* signed long -> unsigned int */
2652 return INTEGER_CONVERSION_BADNESS;
2654 /* signed int/long -> unsigned int/long */
2655 return INTEGER_CONVERSION_BADNESS;
2658 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2660 if (integer_types_same_name_p (TYPE_NAME (parm),
2662 return EXACT_MATCH_BADNESS;
2663 else if (integer_types_same_name_p (TYPE_NAME (arg),
2665 && integer_types_same_name_p (TYPE_NAME (parm),
2667 return INTEGER_PROMOTION_BADNESS;
2669 return INTEGER_CONVERSION_BADNESS;
2672 return INTEGER_CONVERSION_BADNESS;
2674 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2675 return INTEGER_PROMOTION_BADNESS;
2677 return INTEGER_CONVERSION_BADNESS;
2678 case TYPE_CODE_ENUM:
2679 case TYPE_CODE_FLAGS:
2680 case TYPE_CODE_CHAR:
2681 case TYPE_CODE_RANGE:
2682 case TYPE_CODE_BOOL:
2683 return INTEGER_PROMOTION_BADNESS;
2685 return INT_FLOAT_CONVERSION_BADNESS;
2687 return NS_POINTER_CONVERSION_BADNESS;
2689 return INCOMPATIBLE_TYPE_BADNESS;
2692 case TYPE_CODE_ENUM:
2693 switch (TYPE_CODE (arg))
2696 case TYPE_CODE_CHAR:
2697 case TYPE_CODE_RANGE:
2698 case TYPE_CODE_BOOL:
2699 case TYPE_CODE_ENUM:
2700 return INTEGER_CONVERSION_BADNESS;
2702 return INT_FLOAT_CONVERSION_BADNESS;
2704 return INCOMPATIBLE_TYPE_BADNESS;
2707 case TYPE_CODE_CHAR:
2708 switch (TYPE_CODE (arg))
2710 case TYPE_CODE_RANGE:
2711 case TYPE_CODE_BOOL:
2712 case TYPE_CODE_ENUM:
2713 return INTEGER_CONVERSION_BADNESS;
2715 return INT_FLOAT_CONVERSION_BADNESS;
2717 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2718 return INTEGER_CONVERSION_BADNESS;
2719 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2720 return INTEGER_PROMOTION_BADNESS;
2721 /* >>> !! else fall through !! <<< */
2722 case TYPE_CODE_CHAR:
2723 /* Deal with signed, unsigned, and plain chars for C++ and
2724 with int cases falling through from previous case. */
2725 if (TYPE_NOSIGN (parm))
2727 if (TYPE_NOSIGN (arg))
2728 return EXACT_MATCH_BADNESS;
2730 return INTEGER_CONVERSION_BADNESS;
2732 else if (TYPE_UNSIGNED (parm))
2734 if (TYPE_UNSIGNED (arg))
2735 return EXACT_MATCH_BADNESS;
2737 return INTEGER_PROMOTION_BADNESS;
2739 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2740 return EXACT_MATCH_BADNESS;
2742 return INTEGER_CONVERSION_BADNESS;
2744 return INCOMPATIBLE_TYPE_BADNESS;
2747 case TYPE_CODE_RANGE:
2748 switch (TYPE_CODE (arg))
2751 case TYPE_CODE_CHAR:
2752 case TYPE_CODE_RANGE:
2753 case TYPE_CODE_BOOL:
2754 case TYPE_CODE_ENUM:
2755 return INTEGER_CONVERSION_BADNESS;
2757 return INT_FLOAT_CONVERSION_BADNESS;
2759 return INCOMPATIBLE_TYPE_BADNESS;
2762 case TYPE_CODE_BOOL:
2763 switch (TYPE_CODE (arg))
2765 /* n3290 draft, section 4.12.1 (conv.bool):
2767 "A prvalue of arithmetic, unscoped enumeration, pointer, or
2768 pointer to member type can be converted to a prvalue of type
2769 bool. A zero value, null pointer value, or null member pointer
2770 value is converted to false; any other value is converted to
2771 true. A prvalue of type std::nullptr_t can be converted to a
2772 prvalue of type bool; the resulting value is false." */
2774 case TYPE_CODE_CHAR:
2775 case TYPE_CODE_ENUM:
2777 case TYPE_CODE_MEMBERPTR:
2779 return BOOL_CONVERSION_BADNESS;
2780 case TYPE_CODE_RANGE:
2781 return INCOMPATIBLE_TYPE_BADNESS;
2782 case TYPE_CODE_BOOL:
2783 return EXACT_MATCH_BADNESS;
2785 return INCOMPATIBLE_TYPE_BADNESS;
2789 switch (TYPE_CODE (arg))
2792 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2793 return FLOAT_PROMOTION_BADNESS;
2794 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2795 return EXACT_MATCH_BADNESS;
2797 return FLOAT_CONVERSION_BADNESS;
2799 case TYPE_CODE_BOOL:
2800 case TYPE_CODE_ENUM:
2801 case TYPE_CODE_RANGE:
2802 case TYPE_CODE_CHAR:
2803 return INT_FLOAT_CONVERSION_BADNESS;
2805 return INCOMPATIBLE_TYPE_BADNESS;
2808 case TYPE_CODE_COMPLEX:
2809 switch (TYPE_CODE (arg))
2810 { /* Strictly not needed for C++, but... */
2812 return FLOAT_PROMOTION_BADNESS;
2813 case TYPE_CODE_COMPLEX:
2814 return EXACT_MATCH_BADNESS;
2816 return INCOMPATIBLE_TYPE_BADNESS;
2819 case TYPE_CODE_STRUCT:
2820 /* currently same as TYPE_CODE_CLASS. */
2821 switch (TYPE_CODE (arg))
2823 case TYPE_CODE_STRUCT:
2824 /* Check for derivation */
2825 rank.subrank = distance_to_ancestor (parm, arg, 0);
2826 if (rank.subrank >= 0)
2827 return sum_ranks (BASE_CONVERSION_BADNESS, rank);
2828 /* else fall through */
2830 return INCOMPATIBLE_TYPE_BADNESS;
2833 case TYPE_CODE_UNION:
2834 switch (TYPE_CODE (arg))
2836 case TYPE_CODE_UNION:
2838 return INCOMPATIBLE_TYPE_BADNESS;
2841 case TYPE_CODE_MEMBERPTR:
2842 switch (TYPE_CODE (arg))
2845 return INCOMPATIBLE_TYPE_BADNESS;
2848 case TYPE_CODE_METHOD:
2849 switch (TYPE_CODE (arg))
2853 return INCOMPATIBLE_TYPE_BADNESS;
2857 switch (TYPE_CODE (arg))
2861 return INCOMPATIBLE_TYPE_BADNESS;
2866 switch (TYPE_CODE (arg))
2870 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
2871 TYPE_FIELD_TYPE (arg, 0), NULL);
2873 return INCOMPATIBLE_TYPE_BADNESS;
2876 case TYPE_CODE_VOID:
2878 return INCOMPATIBLE_TYPE_BADNESS;
2879 } /* switch (TYPE_CODE (arg)) */
2882 /* End of functions for overload resolution. */
2884 /* Routines to pretty-print types. */
2887 print_bit_vector (B_TYPE *bits, int nbits)
2891 for (bitno = 0; bitno < nbits; bitno++)
2893 if ((bitno % 8) == 0)
2895 puts_filtered (" ");
2897 if (B_TST (bits, bitno))
2898 printf_filtered (("1"));
2900 printf_filtered (("0"));
2904 /* Note the first arg should be the "this" pointer, we may not want to
2905 include it since we may get into a infinitely recursive
2909 print_arg_types (struct field *args, int nargs, int spaces)
2915 for (i = 0; i < nargs; i++)
2916 recursive_dump_type (args[i].type, spaces + 2);
2921 field_is_static (struct field *f)
2923 /* "static" fields are the fields whose location is not relative
2924 to the address of the enclosing struct. It would be nice to
2925 have a dedicated flag that would be set for static fields when
2926 the type is being created. But in practice, checking the field
2927 loc_kind should give us an accurate answer. */
2928 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
2929 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
2933 dump_fn_fieldlists (struct type *type, int spaces)
2939 printfi_filtered (spaces, "fn_fieldlists ");
2940 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2941 printf_filtered ("\n");
2942 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2944 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2945 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2947 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2948 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2950 printf_filtered (_(") length %d\n"),
2951 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2952 for (overload_idx = 0;
2953 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2956 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2958 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2959 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2961 printf_filtered (")\n");
2962 printfi_filtered (spaces + 8, "type ");
2963 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
2965 printf_filtered ("\n");
2967 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2970 printfi_filtered (spaces + 8, "args ");
2971 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
2973 printf_filtered ("\n");
2975 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2976 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f,
2979 printfi_filtered (spaces + 8, "fcontext ");
2980 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2982 printf_filtered ("\n");
2984 printfi_filtered (spaces + 8, "is_const %d\n",
2985 TYPE_FN_FIELD_CONST (f, overload_idx));
2986 printfi_filtered (spaces + 8, "is_volatile %d\n",
2987 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2988 printfi_filtered (spaces + 8, "is_private %d\n",
2989 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2990 printfi_filtered (spaces + 8, "is_protected %d\n",
2991 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2992 printfi_filtered (spaces + 8, "is_stub %d\n",
2993 TYPE_FN_FIELD_STUB (f, overload_idx));
2994 printfi_filtered (spaces + 8, "voffset %u\n",
2995 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
3001 print_cplus_stuff (struct type *type, int spaces)
3003 printfi_filtered (spaces, "n_baseclasses %d\n",
3004 TYPE_N_BASECLASSES (type));
3005 printfi_filtered (spaces, "nfn_fields %d\n",
3006 TYPE_NFN_FIELDS (type));
3007 if (TYPE_N_BASECLASSES (type) > 0)
3009 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
3010 TYPE_N_BASECLASSES (type));
3011 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
3013 printf_filtered (")");
3015 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
3016 TYPE_N_BASECLASSES (type));
3017 puts_filtered ("\n");
3019 if (TYPE_NFIELDS (type) > 0)
3021 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
3023 printfi_filtered (spaces,
3024 "private_field_bits (%d bits at *",
3025 TYPE_NFIELDS (type));
3026 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
3028 printf_filtered (")");
3029 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
3030 TYPE_NFIELDS (type));
3031 puts_filtered ("\n");
3033 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
3035 printfi_filtered (spaces,
3036 "protected_field_bits (%d bits at *",
3037 TYPE_NFIELDS (type));
3038 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
3040 printf_filtered (")");
3041 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
3042 TYPE_NFIELDS (type));
3043 puts_filtered ("\n");
3046 if (TYPE_NFN_FIELDS (type) > 0)
3048 dump_fn_fieldlists (type, spaces);
3052 /* Print the contents of the TYPE's type_specific union, assuming that
3053 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
3056 print_gnat_stuff (struct type *type, int spaces)
3058 struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
3060 recursive_dump_type (descriptive_type, spaces + 2);
3063 static struct obstack dont_print_type_obstack;
3066 recursive_dump_type (struct type *type, int spaces)
3071 obstack_begin (&dont_print_type_obstack, 0);
3073 if (TYPE_NFIELDS (type) > 0
3074 || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0))
3076 struct type **first_dont_print
3077 = (struct type **) obstack_base (&dont_print_type_obstack);
3079 int i = (struct type **)
3080 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
3084 if (type == first_dont_print[i])
3086 printfi_filtered (spaces, "type node ");
3087 gdb_print_host_address (type, gdb_stdout);
3088 printf_filtered (_(" <same as already seen type>\n"));
3093 obstack_ptr_grow (&dont_print_type_obstack, type);
3096 printfi_filtered (spaces, "type node ");
3097 gdb_print_host_address (type, gdb_stdout);
3098 printf_filtered ("\n");
3099 printfi_filtered (spaces, "name '%s' (",
3100 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
3101 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
3102 printf_filtered (")\n");
3103 printfi_filtered (spaces, "tagname '%s' (",
3104 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
3105 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
3106 printf_filtered (")\n");
3107 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
3108 switch (TYPE_CODE (type))
3110 case TYPE_CODE_UNDEF:
3111 printf_filtered ("(TYPE_CODE_UNDEF)");
3114 printf_filtered ("(TYPE_CODE_PTR)");
3116 case TYPE_CODE_ARRAY:
3117 printf_filtered ("(TYPE_CODE_ARRAY)");
3119 case TYPE_CODE_STRUCT:
3120 printf_filtered ("(TYPE_CODE_STRUCT)");
3122 case TYPE_CODE_UNION:
3123 printf_filtered ("(TYPE_CODE_UNION)");
3125 case TYPE_CODE_ENUM:
3126 printf_filtered ("(TYPE_CODE_ENUM)");
3128 case TYPE_CODE_FLAGS:
3129 printf_filtered ("(TYPE_CODE_FLAGS)");
3131 case TYPE_CODE_FUNC:
3132 printf_filtered ("(TYPE_CODE_FUNC)");
3135 printf_filtered ("(TYPE_CODE_INT)");
3138 printf_filtered ("(TYPE_CODE_FLT)");
3140 case TYPE_CODE_VOID:
3141 printf_filtered ("(TYPE_CODE_VOID)");
3144 printf_filtered ("(TYPE_CODE_SET)");
3146 case TYPE_CODE_RANGE:
3147 printf_filtered ("(TYPE_CODE_RANGE)");
3149 case TYPE_CODE_STRING:
3150 printf_filtered ("(TYPE_CODE_STRING)");
3152 case TYPE_CODE_ERROR:
3153 printf_filtered ("(TYPE_CODE_ERROR)");
3155 case TYPE_CODE_MEMBERPTR:
3156 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
3158 case TYPE_CODE_METHODPTR:
3159 printf_filtered ("(TYPE_CODE_METHODPTR)");
3161 case TYPE_CODE_METHOD:
3162 printf_filtered ("(TYPE_CODE_METHOD)");
3165 printf_filtered ("(TYPE_CODE_REF)");
3167 case TYPE_CODE_CHAR:
3168 printf_filtered ("(TYPE_CODE_CHAR)");
3170 case TYPE_CODE_BOOL:
3171 printf_filtered ("(TYPE_CODE_BOOL)");
3173 case TYPE_CODE_COMPLEX:
3174 printf_filtered ("(TYPE_CODE_COMPLEX)");
3176 case TYPE_CODE_TYPEDEF:
3177 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3179 case TYPE_CODE_NAMESPACE:
3180 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3183 printf_filtered ("(UNKNOWN TYPE CODE)");
3186 puts_filtered ("\n");
3187 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
3188 if (TYPE_OBJFILE_OWNED (type))
3190 printfi_filtered (spaces, "objfile ");
3191 gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout);
3195 printfi_filtered (spaces, "gdbarch ");
3196 gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout);
3198 printf_filtered ("\n");
3199 printfi_filtered (spaces, "target_type ");
3200 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
3201 printf_filtered ("\n");
3202 if (TYPE_TARGET_TYPE (type) != NULL)
3204 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3206 printfi_filtered (spaces, "pointer_type ");
3207 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
3208 printf_filtered ("\n");
3209 printfi_filtered (spaces, "reference_type ");
3210 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
3211 printf_filtered ("\n");
3212 printfi_filtered (spaces, "type_chain ");
3213 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
3214 printf_filtered ("\n");
3215 printfi_filtered (spaces, "instance_flags 0x%x",
3216 TYPE_INSTANCE_FLAGS (type));
3217 if (TYPE_CONST (type))
3219 puts_filtered (" TYPE_FLAG_CONST");
3221 if (TYPE_VOLATILE (type))
3223 puts_filtered (" TYPE_FLAG_VOLATILE");
3225 if (TYPE_CODE_SPACE (type))
3227 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3229 if (TYPE_DATA_SPACE (type))
3231 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3233 if (TYPE_ADDRESS_CLASS_1 (type))
3235 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3237 if (TYPE_ADDRESS_CLASS_2 (type))
3239 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3241 if (TYPE_RESTRICT (type))
3243 puts_filtered (" TYPE_FLAG_RESTRICT");
3245 puts_filtered ("\n");
3247 printfi_filtered (spaces, "flags");
3248 if (TYPE_UNSIGNED (type))
3250 puts_filtered (" TYPE_FLAG_UNSIGNED");
3252 if (TYPE_NOSIGN (type))
3254 puts_filtered (" TYPE_FLAG_NOSIGN");
3256 if (TYPE_STUB (type))
3258 puts_filtered (" TYPE_FLAG_STUB");
3260 if (TYPE_TARGET_STUB (type))
3262 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3264 if (TYPE_STATIC (type))
3266 puts_filtered (" TYPE_FLAG_STATIC");
3268 if (TYPE_PROTOTYPED (type))
3270 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3272 if (TYPE_INCOMPLETE (type))
3274 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3276 if (TYPE_VARARGS (type))
3278 puts_filtered (" TYPE_FLAG_VARARGS");
3280 /* This is used for things like AltiVec registers on ppc. Gcc emits
3281 an attribute for the array type, which tells whether or not we
3282 have a vector, instead of a regular array. */
3283 if (TYPE_VECTOR (type))
3285 puts_filtered (" TYPE_FLAG_VECTOR");
3287 if (TYPE_FIXED_INSTANCE (type))
3289 puts_filtered (" TYPE_FIXED_INSTANCE");
3291 if (TYPE_STUB_SUPPORTED (type))
3293 puts_filtered (" TYPE_STUB_SUPPORTED");
3295 if (TYPE_NOTTEXT (type))
3297 puts_filtered (" TYPE_NOTTEXT");
3299 puts_filtered ("\n");
3300 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3301 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3302 puts_filtered ("\n");
3303 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3305 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
3306 printfi_filtered (spaces + 2,
3307 "[%d] enumval %s type ",
3308 idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
3310 printfi_filtered (spaces + 2,
3311 "[%d] bitpos %d bitsize %d type ",
3312 idx, TYPE_FIELD_BITPOS (type, idx),
3313 TYPE_FIELD_BITSIZE (type, idx));
3314 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3315 printf_filtered (" name '%s' (",
3316 TYPE_FIELD_NAME (type, idx) != NULL
3317 ? TYPE_FIELD_NAME (type, idx)
3319 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3320 printf_filtered (")\n");
3321 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3323 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3326 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
3328 printfi_filtered (spaces, "low %s%s high %s%s\n",
3329 plongest (TYPE_LOW_BOUND (type)),
3330 TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
3331 plongest (TYPE_HIGH_BOUND (type)),
3332 TYPE_HIGH_BOUND_UNDEFINED (type)
3333 ? " (undefined)" : "");
3335 printfi_filtered (spaces, "vptr_basetype ");
3336 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3337 puts_filtered ("\n");
3338 if (TYPE_VPTR_BASETYPE (type) != NULL)
3340 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3342 printfi_filtered (spaces, "vptr_fieldno %d\n",
3343 TYPE_VPTR_FIELDNO (type));
3345 switch (TYPE_SPECIFIC_FIELD (type))
3347 case TYPE_SPECIFIC_CPLUS_STUFF:
3348 printfi_filtered (spaces, "cplus_stuff ");
3349 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
3351 puts_filtered ("\n");
3352 print_cplus_stuff (type, spaces);
3355 case TYPE_SPECIFIC_GNAT_STUFF:
3356 printfi_filtered (spaces, "gnat_stuff ");
3357 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type), gdb_stdout);
3358 puts_filtered ("\n");
3359 print_gnat_stuff (type, spaces);
3362 case TYPE_SPECIFIC_FLOATFORMAT:
3363 printfi_filtered (spaces, "floatformat ");
3364 if (TYPE_FLOATFORMAT (type) == NULL)
3365 puts_filtered ("(null)");
3368 puts_filtered ("{ ");
3369 if (TYPE_FLOATFORMAT (type)[0] == NULL
3370 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
3371 puts_filtered ("(null)");
3373 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
3375 puts_filtered (", ");
3376 if (TYPE_FLOATFORMAT (type)[1] == NULL
3377 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
3378 puts_filtered ("(null)");
3380 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
3382 puts_filtered (" }");
3384 puts_filtered ("\n");
3387 case TYPE_SPECIFIC_FUNC:
3388 printfi_filtered (spaces, "calling_convention %d\n",
3389 TYPE_CALLING_CONVENTION (type));
3390 /* tail_call_list is not printed. */
3395 obstack_free (&dont_print_type_obstack, NULL);
3398 /* Trivial helpers for the libiberty hash table, for mapping one
3403 struct type *old, *new;
3407 type_pair_hash (const void *item)
3409 const struct type_pair *pair = item;
3411 return htab_hash_pointer (pair->old);
3415 type_pair_eq (const void *item_lhs, const void *item_rhs)
3417 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
3419 return lhs->old == rhs->old;
3422 /* Allocate the hash table used by copy_type_recursive to walk
3423 types without duplicates. We use OBJFILE's obstack, because
3424 OBJFILE is about to be deleted. */
3427 create_copied_types_hash (struct objfile *objfile)
3429 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
3430 NULL, &objfile->objfile_obstack,
3431 hashtab_obstack_allocate,
3432 dummy_obstack_deallocate);
3435 /* Recursively copy (deep copy) TYPE, if it is associated with
3436 OBJFILE. Return a new type allocated using malloc, a saved type if
3437 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
3438 not associated with OBJFILE. */
3441 copy_type_recursive (struct objfile *objfile,
3443 htab_t copied_types)
3445 struct type_pair *stored, pair;
3447 struct type *new_type;
3449 if (! TYPE_OBJFILE_OWNED (type))
3452 /* This type shouldn't be pointing to any types in other objfiles;
3453 if it did, the type might disappear unexpectedly. */
3454 gdb_assert (TYPE_OBJFILE (type) == objfile);
3457 slot = htab_find_slot (copied_types, &pair, INSERT);
3459 return ((struct type_pair *) *slot)->new;
3461 new_type = alloc_type_arch (get_type_arch (type));
3463 /* We must add the new type to the hash table immediately, in case
3464 we encounter this type again during a recursive call below. */
3466 = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
3468 stored->new = new_type;
3471 /* Copy the common fields of types. For the main type, we simply
3472 copy the entire thing and then update specific fields as needed. */
3473 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
3474 TYPE_OBJFILE_OWNED (new_type) = 0;
3475 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
3477 if (TYPE_NAME (type))
3478 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
3479 if (TYPE_TAG_NAME (type))
3480 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
3482 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
3483 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
3485 /* Copy the fields. */
3486 if (TYPE_NFIELDS (type))
3490 nfields = TYPE_NFIELDS (type);
3491 TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
3492 for (i = 0; i < nfields; i++)
3494 TYPE_FIELD_ARTIFICIAL (new_type, i) =
3495 TYPE_FIELD_ARTIFICIAL (type, i);
3496 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
3497 if (TYPE_FIELD_TYPE (type, i))
3498 TYPE_FIELD_TYPE (new_type, i)
3499 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
3501 if (TYPE_FIELD_NAME (type, i))
3502 TYPE_FIELD_NAME (new_type, i) =
3503 xstrdup (TYPE_FIELD_NAME (type, i));
3504 switch (TYPE_FIELD_LOC_KIND (type, i))
3506 case FIELD_LOC_KIND_BITPOS:
3507 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
3508 TYPE_FIELD_BITPOS (type, i));
3510 case FIELD_LOC_KIND_ENUMVAL:
3511 SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i),
3512 TYPE_FIELD_ENUMVAL (type, i));
3514 case FIELD_LOC_KIND_PHYSADDR:
3515 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
3516 TYPE_FIELD_STATIC_PHYSADDR (type, i));
3518 case FIELD_LOC_KIND_PHYSNAME:
3519 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
3520 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
3524 internal_error (__FILE__, __LINE__,
3525 _("Unexpected type field location kind: %d"),
3526 TYPE_FIELD_LOC_KIND (type, i));
3531 /* For range types, copy the bounds information. */
3532 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
3534 TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
3535 *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
3538 /* Copy pointers to other types. */
3539 if (TYPE_TARGET_TYPE (type))
3540 TYPE_TARGET_TYPE (new_type) =
3541 copy_type_recursive (objfile,
3542 TYPE_TARGET_TYPE (type),
3544 if (TYPE_VPTR_BASETYPE (type))
3545 TYPE_VPTR_BASETYPE (new_type) =
3546 copy_type_recursive (objfile,
3547 TYPE_VPTR_BASETYPE (type),
3549 /* Maybe copy the type_specific bits.
3551 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3552 base classes and methods. There's no fundamental reason why we
3553 can't, but at the moment it is not needed. */
3555 if (TYPE_CODE (type) == TYPE_CODE_FLT)
3556 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
3557 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3558 || TYPE_CODE (type) == TYPE_CODE_UNION
3559 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
3560 INIT_CPLUS_SPECIFIC (new_type);
3565 /* Make a copy of the given TYPE, except that the pointer & reference
3566 types are not preserved.
3568 This function assumes that the given type has an associated objfile.
3569 This objfile is used to allocate the new type. */
3572 copy_type (const struct type *type)
3574 struct type *new_type;
3576 gdb_assert (TYPE_OBJFILE_OWNED (type));
3578 new_type = alloc_type_copy (type);
3579 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
3580 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
3581 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
3582 sizeof (struct main_type));
3587 /* Helper functions to initialize architecture-specific types. */
3589 /* Allocate a type structure associated with GDBARCH and set its
3590 CODE, LENGTH, and NAME fields. */
3593 arch_type (struct gdbarch *gdbarch,
3594 enum type_code code, int length, char *name)
3598 type = alloc_type_arch (gdbarch);
3599 TYPE_CODE (type) = code;
3600 TYPE_LENGTH (type) = length;
3603 TYPE_NAME (type) = xstrdup (name);
3608 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
3609 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3610 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3613 arch_integer_type (struct gdbarch *gdbarch,
3614 int bit, int unsigned_p, char *name)
3618 t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
3620 TYPE_UNSIGNED (t) = 1;
3621 if (name && strcmp (name, "char") == 0)
3622 TYPE_NOSIGN (t) = 1;
3627 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
3628 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3629 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3632 arch_character_type (struct gdbarch *gdbarch,
3633 int bit, int unsigned_p, char *name)
3637 t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
3639 TYPE_UNSIGNED (t) = 1;
3644 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
3645 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3646 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3649 arch_boolean_type (struct gdbarch *gdbarch,
3650 int bit, int unsigned_p, char *name)
3654 t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
3656 TYPE_UNSIGNED (t) = 1;
3661 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
3662 BIT is the type size in bits; if BIT equals -1, the size is
3663 determined by the floatformat. NAME is the type name. Set the
3664 TYPE_FLOATFORMAT from FLOATFORMATS. */
3667 arch_float_type (struct gdbarch *gdbarch,
3668 int bit, char *name, const struct floatformat **floatformats)
3674 gdb_assert (floatformats != NULL);
3675 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
3676 bit = floatformats[0]->totalsize;
3678 gdb_assert (bit >= 0);
3680 t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
3681 TYPE_FLOATFORMAT (t) = floatformats;
3685 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
3686 NAME is the type name. TARGET_TYPE is the component float type. */
3689 arch_complex_type (struct gdbarch *gdbarch,
3690 char *name, struct type *target_type)
3694 t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
3695 2 * TYPE_LENGTH (target_type), name);
3696 TYPE_TARGET_TYPE (t) = target_type;
3700 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
3701 NAME is the type name. LENGTH is the size of the flag word in bytes. */
3704 arch_flags_type (struct gdbarch *gdbarch, char *name, int length)
3706 int nfields = length * TARGET_CHAR_BIT;
3709 type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name);
3710 TYPE_UNSIGNED (type) = 1;
3711 TYPE_NFIELDS (type) = nfields;
3712 TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
3717 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
3718 position BITPOS is called NAME. */
3721 append_flags_type_flag (struct type *type, int bitpos, char *name)
3723 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
3724 gdb_assert (bitpos < TYPE_NFIELDS (type));
3725 gdb_assert (bitpos >= 0);
3729 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
3730 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), bitpos);
3734 /* Don't show this field to the user. */
3735 SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), -1);
3739 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
3740 specified by CODE) associated with GDBARCH. NAME is the type name. */
3743 arch_composite_type (struct gdbarch *gdbarch, char *name, enum type_code code)
3747 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
3748 t = arch_type (gdbarch, code, 0, NULL);
3749 TYPE_TAG_NAME (t) = name;
3750 INIT_CPLUS_SPECIFIC (t);
3754 /* Add new field with name NAME and type FIELD to composite type T.
3755 Do not set the field's position or adjust the type's length;
3756 the caller should do so. Return the new field. */
3759 append_composite_type_field_raw (struct type *t, char *name,
3764 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
3765 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
3766 sizeof (struct field) * TYPE_NFIELDS (t));
3767 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
3768 memset (f, 0, sizeof f[0]);
3769 FIELD_TYPE (f[0]) = field;
3770 FIELD_NAME (f[0]) = name;
3774 /* Add new field with name NAME and type FIELD to composite type T.
3775 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
3778 append_composite_type_field_aligned (struct type *t, char *name,
3779 struct type *field, int alignment)
3781 struct field *f = append_composite_type_field_raw (t, name, field);
3783 if (TYPE_CODE (t) == TYPE_CODE_UNION)
3785 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
3786 TYPE_LENGTH (t) = TYPE_LENGTH (field);
3788 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
3790 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
3791 if (TYPE_NFIELDS (t) > 1)
3793 SET_FIELD_BITPOS (f[0],
3794 (FIELD_BITPOS (f[-1])
3795 + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
3796 * TARGET_CHAR_BIT)));
3802 alignment *= TARGET_CHAR_BIT;
3803 left = FIELD_BITPOS (f[0]) % alignment;
3807 SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left));
3808 TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
3815 /* Add new field with name NAME and type FIELD to composite type T. */
3818 append_composite_type_field (struct type *t, char *name,
3821 append_composite_type_field_aligned (t, name, field, 0);
3824 static struct gdbarch_data *gdbtypes_data;
3826 const struct builtin_type *
3827 builtin_type (struct gdbarch *gdbarch)
3829 return gdbarch_data (gdbarch, gdbtypes_data);
3833 gdbtypes_post_init (struct gdbarch *gdbarch)
3835 struct builtin_type *builtin_type
3836 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
3839 builtin_type->builtin_void
3840 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
3841 builtin_type->builtin_char
3842 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
3843 !gdbarch_char_signed (gdbarch), "char");
3844 builtin_type->builtin_signed_char
3845 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
3847 builtin_type->builtin_unsigned_char
3848 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
3849 1, "unsigned char");
3850 builtin_type->builtin_short
3851 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
3853 builtin_type->builtin_unsigned_short
3854 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
3855 1, "unsigned short");
3856 builtin_type->builtin_int
3857 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
3859 builtin_type->builtin_unsigned_int
3860 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
3862 builtin_type->builtin_long
3863 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
3865 builtin_type->builtin_unsigned_long
3866 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
3867 1, "unsigned long");
3868 builtin_type->builtin_long_long
3869 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
3871 builtin_type->builtin_unsigned_long_long
3872 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
3873 1, "unsigned long long");
3874 builtin_type->builtin_float
3875 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
3876 "float", gdbarch_float_format (gdbarch));
3877 builtin_type->builtin_double
3878 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
3879 "double", gdbarch_double_format (gdbarch));
3880 builtin_type->builtin_long_double
3881 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
3882 "long double", gdbarch_long_double_format (gdbarch));
3883 builtin_type->builtin_complex
3884 = arch_complex_type (gdbarch, "complex",
3885 builtin_type->builtin_float);
3886 builtin_type->builtin_double_complex
3887 = arch_complex_type (gdbarch, "double complex",
3888 builtin_type->builtin_double);
3889 builtin_type->builtin_string
3890 = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string");
3891 builtin_type->builtin_bool
3892 = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool");
3894 /* The following three are about decimal floating point types, which
3895 are 32-bits, 64-bits and 128-bits respectively. */
3896 builtin_type->builtin_decfloat
3897 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 32 / 8, "_Decimal32");
3898 builtin_type->builtin_decdouble
3899 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 64 / 8, "_Decimal64");
3900 builtin_type->builtin_declong
3901 = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 128 / 8, "_Decimal128");
3903 /* "True" character types. */
3904 builtin_type->builtin_true_char
3905 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character");
3906 builtin_type->builtin_true_unsigned_char
3907 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character");
3909 /* Fixed-size integer types. */
3910 builtin_type->builtin_int0
3911 = arch_integer_type (gdbarch, 0, 0, "int0_t");
3912 builtin_type->builtin_int8
3913 = arch_integer_type (gdbarch, 8, 0, "int8_t");
3914 builtin_type->builtin_uint8
3915 = arch_integer_type (gdbarch, 8, 1, "uint8_t");
3916 builtin_type->builtin_int16
3917 = arch_integer_type (gdbarch, 16, 0, "int16_t");
3918 builtin_type->builtin_uint16
3919 = arch_integer_type (gdbarch, 16, 1, "uint16_t");
3920 builtin_type->builtin_int32
3921 = arch_integer_type (gdbarch, 32, 0, "int32_t");
3922 builtin_type->builtin_uint32
3923 = arch_integer_type (gdbarch, 32, 1, "uint32_t");
3924 builtin_type->builtin_int64
3925 = arch_integer_type (gdbarch, 64, 0, "int64_t");
3926 builtin_type->builtin_uint64
3927 = arch_integer_type (gdbarch, 64, 1, "uint64_t");
3928 builtin_type->builtin_int128
3929 = arch_integer_type (gdbarch, 128, 0, "int128_t");
3930 builtin_type->builtin_uint128
3931 = arch_integer_type (gdbarch, 128, 1, "uint128_t");
3932 TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |=
3933 TYPE_INSTANCE_FLAG_NOTTEXT;
3934 TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |=
3935 TYPE_INSTANCE_FLAG_NOTTEXT;
3937 /* Wide character types. */
3938 builtin_type->builtin_char16
3939 = arch_integer_type (gdbarch, 16, 0, "char16_t");
3940 builtin_type->builtin_char32
3941 = arch_integer_type (gdbarch, 32, 0, "char32_t");
3944 /* Default data/code pointer types. */
3945 builtin_type->builtin_data_ptr
3946 = lookup_pointer_type (builtin_type->builtin_void);
3947 builtin_type->builtin_func_ptr
3948 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
3949 builtin_type->builtin_func_func
3950 = lookup_function_type (builtin_type->builtin_func_ptr);
3952 /* This type represents a GDB internal function. */
3953 builtin_type->internal_fn
3954 = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0,
3955 "<internal function>");
3957 return builtin_type;
3960 /* This set of objfile-based types is intended to be used by symbol
3961 readers as basic types. */
3963 static const struct objfile_data *objfile_type_data;
3965 const struct objfile_type *
3966 objfile_type (struct objfile *objfile)
3968 struct gdbarch *gdbarch;
3969 struct objfile_type *objfile_type
3970 = objfile_data (objfile, objfile_type_data);
3973 return objfile_type;
3975 objfile_type = OBSTACK_CALLOC (&objfile->objfile_obstack,
3976 1, struct objfile_type);
3978 /* Use the objfile architecture to determine basic type properties. */
3979 gdbarch = get_objfile_arch (objfile);
3982 objfile_type->builtin_void
3983 = init_type (TYPE_CODE_VOID, 1,
3987 objfile_type->builtin_char
3988 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3990 | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
3992 objfile_type->builtin_signed_char
3993 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3995 "signed char", objfile);
3996 objfile_type->builtin_unsigned_char
3997 = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3999 "unsigned char", objfile);
4000 objfile_type->builtin_short
4001 = init_type (TYPE_CODE_INT,
4002 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4003 0, "short", objfile);
4004 objfile_type->builtin_unsigned_short
4005 = init_type (TYPE_CODE_INT,
4006 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
4007 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
4008 objfile_type->builtin_int
4009 = init_type (TYPE_CODE_INT,
4010 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4012 objfile_type->builtin_unsigned_int
4013 = init_type (TYPE_CODE_INT,
4014 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
4015 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
4016 objfile_type->builtin_long
4017 = init_type (TYPE_CODE_INT,
4018 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4019 0, "long", objfile);
4020 objfile_type->builtin_unsigned_long
4021 = init_type (TYPE_CODE_INT,
4022 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
4023 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
4024 objfile_type->builtin_long_long
4025 = init_type (TYPE_CODE_INT,
4026 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4027 0, "long long", objfile);
4028 objfile_type->builtin_unsigned_long_long
4029 = init_type (TYPE_CODE_INT,
4030 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
4031 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
4033 objfile_type->builtin_float
4034 = init_type (TYPE_CODE_FLT,
4035 gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT,
4036 0, "float", objfile);
4037 TYPE_FLOATFORMAT (objfile_type->builtin_float)
4038 = gdbarch_float_format (gdbarch);
4039 objfile_type->builtin_double
4040 = init_type (TYPE_CODE_FLT,
4041 gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT,
4042 0, "double", objfile);
4043 TYPE_FLOATFORMAT (objfile_type->builtin_double)
4044 = gdbarch_double_format (gdbarch);
4045 objfile_type->builtin_long_double
4046 = init_type (TYPE_CODE_FLT,
4047 gdbarch_long_double_bit (gdbarch) / TARGET_CHAR_BIT,
4048 0, "long double", objfile);
4049 TYPE_FLOATFORMAT (objfile_type->builtin_long_double)
4050 = gdbarch_long_double_format (gdbarch);
4052 /* This type represents a type that was unrecognized in symbol read-in. */
4053 objfile_type->builtin_error
4054 = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>", objfile);
4056 /* The following set of types is used for symbols with no
4057 debug information. */
4058 objfile_type->nodebug_text_symbol
4059 = init_type (TYPE_CODE_FUNC, 1, 0,
4060 "<text variable, no debug info>", objfile);
4061 TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
4062 = objfile_type->builtin_int;
4063 objfile_type->nodebug_text_gnu_ifunc_symbol
4064 = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC,
4065 "<text gnu-indirect-function variable, no debug info>",
4067 TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
4068 = objfile_type->nodebug_text_symbol;
4069 objfile_type->nodebug_got_plt_symbol
4070 = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0,
4071 "<text from jump slot in .got.plt, no debug info>",
4073 TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol)
4074 = objfile_type->nodebug_text_symbol;
4075 objfile_type->nodebug_data_symbol
4076 = init_type (TYPE_CODE_INT,
4077 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4078 "<data variable, no debug info>", objfile);
4079 objfile_type->nodebug_unknown_symbol
4080 = init_type (TYPE_CODE_INT, 1, 0,
4081 "<variable (not text or data), no debug info>", objfile);
4082 objfile_type->nodebug_tls_symbol
4083 = init_type (TYPE_CODE_INT,
4084 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
4085 "<thread local variable, no debug info>", objfile);
4087 /* NOTE: on some targets, addresses and pointers are not necessarily
4091 - gdb's `struct type' always describes the target's
4093 - gdb's `struct value' objects should always hold values in
4095 - gdb's CORE_ADDR values are addresses in the unified virtual
4096 address space that the assembler and linker work with. Thus,
4097 since target_read_memory takes a CORE_ADDR as an argument, it
4098 can access any memory on the target, even if the processor has
4099 separate code and data address spaces.
4101 In this context, objfile_type->builtin_core_addr is a bit odd:
4102 it's a target type for a value the target will never see. It's
4103 only used to hold the values of (typeless) linker symbols, which
4104 are indeed in the unified virtual address space. */
4106 objfile_type->builtin_core_addr
4107 = init_type (TYPE_CODE_INT,
4108 gdbarch_addr_bit (gdbarch) / 8,
4109 TYPE_FLAG_UNSIGNED, "__CORE_ADDR", objfile);
4111 set_objfile_data (objfile, objfile_type_data, objfile_type);
4112 return objfile_type;
4115 extern initialize_file_ftype _initialize_gdbtypes;
4118 _initialize_gdbtypes (void)
4120 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
4121 objfile_type_data = register_objfile_data ();
4123 add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug,
4124 _("Set debugging of C++ overloading."),
4125 _("Show debugging of C++ overloading."),
4126 _("When enabled, ranking of the "
4127 "functions is displayed."),
4129 show_overload_debug,
4130 &setdebuglist, &showdebuglist);
4132 /* Add user knob for controlling resolution of opaque types. */
4133 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
4134 &opaque_type_resolution,
4135 _("Set resolution of opaque struct/class/union"
4136 " types (if set before loading symbols)."),
4137 _("Show resolution of opaque struct/class/union"
4138 " types (if set before loading symbols)."),
4140 show_opaque_type_resolution,
4141 &setlist, &showlist);
4143 /* Add an option to permit non-strict type checking. */
4144 add_setshow_boolean_cmd ("type", class_support,
4145 &strict_type_checking,
4146 _("Set strict type checking."),
4147 _("Show strict type checking."),
4149 show_strict_type_checking,
4150 &setchecklist, &showchecklist);