1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2017 Free Software Foundation, Inc.
5 Contributed by Cygnus Support, using pieces from other GDB modules.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "expression.h"
33 #include "complaints.h"
37 #include "cp-support.h"
39 #include "dwarf2loc.h"
42 /* Initialize BADNESS constants. */
44 const struct rank LENGTH_MISMATCH_BADNESS = {100,0};
46 const struct rank TOO_FEW_PARAMS_BADNESS = {100,0};
47 const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0};
49 const struct rank EXACT_MATCH_BADNESS = {0,0};
51 const struct rank INTEGER_PROMOTION_BADNESS = {1,0};
52 const struct rank FLOAT_PROMOTION_BADNESS = {1,0};
53 const struct rank BASE_PTR_CONVERSION_BADNESS = {1,0};
54 const struct rank 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 LVALUE_REFERENCE_TO_RVALUE_BINDING_BADNESS = {5,0};
62 const struct rank DIFFERENT_REFERENCE_TYPE_BADNESS = {6,0};
63 const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
64 const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
65 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
67 /* Floatformat pairs. */
68 const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
69 &floatformat_ieee_half_big,
70 &floatformat_ieee_half_little
72 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
73 &floatformat_ieee_single_big,
74 &floatformat_ieee_single_little
76 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
77 &floatformat_ieee_double_big,
78 &floatformat_ieee_double_little
80 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
81 &floatformat_ieee_double_big,
82 &floatformat_ieee_double_littlebyte_bigword
84 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
85 &floatformat_i387_ext,
88 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
89 &floatformat_m68881_ext,
90 &floatformat_m68881_ext
92 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
93 &floatformat_arm_ext_big,
94 &floatformat_arm_ext_littlebyte_bigword
96 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
97 &floatformat_ia64_spill_big,
98 &floatformat_ia64_spill_little
100 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
101 &floatformat_ia64_quad_big,
102 &floatformat_ia64_quad_little
104 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
108 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
112 const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
113 &floatformat_ibm_long_double_big,
114 &floatformat_ibm_long_double_little
117 /* Should opaque types be resolved? */
119 static int opaque_type_resolution = 1;
121 /* A flag to enable printing of debugging information of C++
124 unsigned int overload_debug = 0;
126 /* A flag to enable strict type checking. */
128 static int strict_type_checking = 1;
130 /* A function to show whether opaque types are resolved. */
133 show_opaque_type_resolution (struct ui_file *file, int from_tty,
134 struct cmd_list_element *c,
137 fprintf_filtered (file, _("Resolution of opaque struct/class/union types "
138 "(if set before loading symbols) is %s.\n"),
142 /* A function to show whether C++ overload debugging is enabled. */
145 show_overload_debug (struct ui_file *file, int from_tty,
146 struct cmd_list_element *c, const char *value)
148 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
152 /* A function to show the status of strict type checking. */
155 show_strict_type_checking (struct ui_file *file, int from_tty,
156 struct cmd_list_element *c, const char *value)
158 fprintf_filtered (file, _("Strict type checking is %s.\n"), value);
162 /* Allocate a new OBJFILE-associated type structure and fill it
163 with some defaults. Space for the type structure is allocated
164 on the objfile's objfile_obstack. */
167 alloc_type (struct objfile *objfile)
171 gdb_assert (objfile != NULL);
173 /* Alloc the structure and start off with all fields zeroed. */
174 type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
175 TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
177 OBJSTAT (objfile, n_types++);
179 TYPE_OBJFILE_OWNED (type) = 1;
180 TYPE_OWNER (type).objfile = objfile;
182 /* Initialize the fields that might not be zero. */
184 TYPE_CODE (type) = TYPE_CODE_UNDEF;
185 TYPE_CHAIN (type) = type; /* Chain back to itself. */
190 /* Allocate a new GDBARCH-associated type structure and fill it
191 with some defaults. Space for the type structure is allocated
192 on the obstack associated with GDBARCH. */
195 alloc_type_arch (struct gdbarch *gdbarch)
199 gdb_assert (gdbarch != NULL);
201 /* Alloc the structure and start off with all fields zeroed. */
203 type = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct type);
204 TYPE_MAIN_TYPE (type) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct main_type);
206 TYPE_OBJFILE_OWNED (type) = 0;
207 TYPE_OWNER (type).gdbarch = gdbarch;
209 /* Initialize the fields that might not be zero. */
211 TYPE_CODE (type) = TYPE_CODE_UNDEF;
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 /* See gdbtypes.h. */
260 type_length_units (struct type *type)
262 struct gdbarch *arch = get_type_arch (type);
263 int unit_size = gdbarch_addressable_memory_unit_size (arch);
265 return TYPE_LENGTH (type) / unit_size;
268 /* Alloc a new type instance structure, fill it with some defaults,
269 and point it at OLDTYPE. Allocate the new type instance from the
270 same place as OLDTYPE. */
273 alloc_type_instance (struct type *oldtype)
277 /* Allocate the structure. */
279 if (! TYPE_OBJFILE_OWNED (oldtype))
280 type = XCNEW (struct type);
282 type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
285 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
287 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
292 /* Clear all remnants of the previous type at TYPE, in preparation for
293 replacing it with something else. Preserve owner information. */
296 smash_type (struct type *type)
298 int objfile_owned = TYPE_OBJFILE_OWNED (type);
299 union type_owner owner = TYPE_OWNER (type);
301 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
303 /* Restore owner information. */
304 TYPE_OBJFILE_OWNED (type) = objfile_owned;
305 TYPE_OWNER (type) = owner;
307 /* For now, delete the rings. */
308 TYPE_CHAIN (type) = type;
310 /* For now, leave the pointer/reference types alone. */
313 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
314 to a pointer to memory where the pointer type should be stored.
315 If *TYPEPTR is zero, update it to point to the pointer type we return.
316 We allocate new memory if needed. */
319 make_pointer_type (struct type *type, struct type **typeptr)
321 struct type *ntype; /* New type */
324 ntype = TYPE_POINTER_TYPE (type);
329 return ntype; /* Don't care about alloc,
330 and have new type. */
331 else if (*typeptr == 0)
333 *typeptr = ntype; /* Tracking alloc, and have new type. */
338 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
340 ntype = alloc_type_copy (type);
344 else /* We have storage, but need to reset it. */
347 chain = TYPE_CHAIN (ntype);
349 TYPE_CHAIN (ntype) = chain;
352 TYPE_TARGET_TYPE (ntype) = type;
353 TYPE_POINTER_TYPE (type) = ntype;
355 /* FIXME! Assumes the machine has only one representation for pointers! */
358 = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
359 TYPE_CODE (ntype) = TYPE_CODE_PTR;
361 /* Mark pointers as unsigned. The target converts between pointers
362 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
363 gdbarch_address_to_pointer. */
364 TYPE_UNSIGNED (ntype) = 1;
366 /* Update the length of all the other variants of this type. */
367 chain = TYPE_CHAIN (ntype);
368 while (chain != ntype)
370 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
371 chain = TYPE_CHAIN (chain);
377 /* Given a type TYPE, return a type of pointers to that type.
378 May need to construct such a type if this is the first use. */
381 lookup_pointer_type (struct type *type)
383 return make_pointer_type (type, (struct type **) 0);
386 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
387 points to a pointer to memory where the reference type should be
388 stored. If *TYPEPTR is zero, update it to point to the reference
389 type we return. We allocate new memory if needed. REFCODE denotes
390 the kind of reference type to lookup (lvalue or rvalue reference). */
393 make_reference_type (struct type *type, struct type **typeptr,
394 enum type_code refcode)
396 struct type *ntype; /* New type */
397 struct type **reftype;
400 gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
402 ntype = (refcode == TYPE_CODE_REF ? TYPE_REFERENCE_TYPE (type)
403 : TYPE_RVALUE_REFERENCE_TYPE (type));
408 return ntype; /* Don't care about alloc,
409 and have new type. */
410 else if (*typeptr == 0)
412 *typeptr = ntype; /* Tracking alloc, and have new type. */
417 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
419 ntype = alloc_type_copy (type);
423 else /* We have storage, but need to reset it. */
426 chain = TYPE_CHAIN (ntype);
428 TYPE_CHAIN (ntype) = chain;
431 TYPE_TARGET_TYPE (ntype) = type;
432 reftype = (refcode == TYPE_CODE_REF ? &TYPE_REFERENCE_TYPE (type)
433 : &TYPE_RVALUE_REFERENCE_TYPE (type));
437 /* FIXME! Assume the machine has only one representation for
438 references, and that it matches the (only) representation for
441 TYPE_LENGTH (ntype) =
442 gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
443 TYPE_CODE (ntype) = refcode;
447 /* Update the length of all the other variants of this type. */
448 chain = TYPE_CHAIN (ntype);
449 while (chain != ntype)
451 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
452 chain = TYPE_CHAIN (chain);
458 /* Same as above, but caller doesn't care about memory allocation
462 lookup_reference_type (struct type *type, enum type_code refcode)
464 return make_reference_type (type, (struct type **) 0, refcode);
467 /* Lookup the lvalue reference type for the type TYPE. */
470 lookup_lvalue_reference_type (struct type *type)
472 return lookup_reference_type (type, TYPE_CODE_REF);
475 /* Lookup the rvalue reference type for the type TYPE. */
478 lookup_rvalue_reference_type (struct type *type)
480 return lookup_reference_type (type, TYPE_CODE_RVALUE_REF);
483 /* Lookup a function type that returns type TYPE. TYPEPTR, if
484 nonzero, points to a pointer to memory where the function type
485 should be stored. If *TYPEPTR is zero, update it to point to the
486 function type we return. We allocate new memory if needed. */
489 make_function_type (struct type *type, struct type **typeptr)
491 struct type *ntype; /* New type */
493 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
495 ntype = alloc_type_copy (type);
499 else /* We have storage, but need to reset it. */
505 TYPE_TARGET_TYPE (ntype) = type;
507 TYPE_LENGTH (ntype) = 1;
508 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
510 INIT_FUNC_SPECIFIC (ntype);
515 /* Given a type TYPE, return a type of functions that return that type.
516 May need to construct such a type if this is the first use. */
519 lookup_function_type (struct type *type)
521 return make_function_type (type, (struct type **) 0);
524 /* Given a type TYPE and argument types, return the appropriate
525 function type. If the final type in PARAM_TYPES is NULL, make a
529 lookup_function_type_with_arguments (struct type *type,
531 struct type **param_types)
533 struct type *fn = make_function_type (type, (struct type **) 0);
538 if (param_types[nparams - 1] == NULL)
541 TYPE_VARARGS (fn) = 1;
543 else if (TYPE_CODE (check_typedef (param_types[nparams - 1]))
547 /* Caller should have ensured this. */
548 gdb_assert (nparams == 0);
549 TYPE_PROTOTYPED (fn) = 1;
553 TYPE_NFIELDS (fn) = nparams;
555 = (struct field *) TYPE_ZALLOC (fn, nparams * sizeof (struct field));
556 for (i = 0; i < nparams; ++i)
557 TYPE_FIELD_TYPE (fn, i) = param_types[i];
562 /* Identify address space identifier by name --
563 return the integer flag defined in gdbtypes.h. */
566 address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier)
570 /* Check for known address space delimiters. */
571 if (!strcmp (space_identifier, "code"))
572 return TYPE_INSTANCE_FLAG_CODE_SPACE;
573 else if (!strcmp (space_identifier, "data"))
574 return TYPE_INSTANCE_FLAG_DATA_SPACE;
575 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
576 && gdbarch_address_class_name_to_type_flags (gdbarch,
581 error (_("Unknown address space specifier: \"%s\""), space_identifier);
584 /* Identify address space identifier by integer flag as defined in
585 gdbtypes.h -- return the string version of the adress space name. */
588 address_space_int_to_name (struct gdbarch *gdbarch, int space_flag)
590 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
592 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
594 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
595 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
596 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
601 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
603 If STORAGE is non-NULL, create the new type instance there.
604 STORAGE must be in the same obstack as TYPE. */
607 make_qualified_type (struct type *type, int new_flags,
608 struct type *storage)
615 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
617 ntype = TYPE_CHAIN (ntype);
619 while (ntype != type);
621 /* Create a new type instance. */
623 ntype = alloc_type_instance (type);
626 /* If STORAGE was provided, it had better be in the same objfile
627 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
628 if one objfile is freed and the other kept, we'd have
629 dangling pointers. */
630 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
633 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
634 TYPE_CHAIN (ntype) = ntype;
637 /* Pointers or references to the original type are not relevant to
639 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
640 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
642 /* Chain the new qualified type to the old type. */
643 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
644 TYPE_CHAIN (type) = ntype;
646 /* Now set the instance flags and return the new type. */
647 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
649 /* Set length of new type to that of the original type. */
650 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
655 /* Make an address-space-delimited variant of a type -- a type that
656 is identical to the one supplied except that it has an address
657 space attribute attached to it (such as "code" or "data").
659 The space attributes "code" and "data" are for Harvard
660 architectures. The address space attributes are for architectures
661 which have alternately sized pointers or pointers with alternate
665 make_type_with_address_space (struct type *type, int space_flag)
667 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
668 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
669 | TYPE_INSTANCE_FLAG_DATA_SPACE
670 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
673 return make_qualified_type (type, new_flags, NULL);
676 /* Make a "c-v" variant of a type -- a type that is identical to the
677 one supplied except that it may have const or volatile attributes
678 CNST is a flag for setting the const attribute
679 VOLTL is a flag for setting the volatile attribute
680 TYPE is the base type whose variant we are creating.
682 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
683 storage to hold the new qualified type; *TYPEPTR and TYPE must be
684 in the same objfile. Otherwise, allocate fresh memory for the new
685 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
686 new type we construct. */
689 make_cv_type (int cnst, int voltl,
691 struct type **typeptr)
693 struct type *ntype; /* New type */
695 int new_flags = (TYPE_INSTANCE_FLAGS (type)
696 & ~(TYPE_INSTANCE_FLAG_CONST
697 | TYPE_INSTANCE_FLAG_VOLATILE));
700 new_flags |= TYPE_INSTANCE_FLAG_CONST;
703 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
705 if (typeptr && *typeptr != NULL)
707 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
708 a C-V variant chain that threads across objfiles: if one
709 objfile gets freed, then the other has a broken C-V chain.
711 This code used to try to copy over the main type from TYPE to
712 *TYPEPTR if they were in different objfiles, but that's
713 wrong, too: TYPE may have a field list or member function
714 lists, which refer to types of their own, etc. etc. The
715 whole shebang would need to be copied over recursively; you
716 can't have inter-objfile pointers. The only thing to do is
717 to leave stub types as stub types, and look them up afresh by
718 name each time you encounter them. */
719 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
722 ntype = make_qualified_type (type, new_flags,
723 typeptr ? *typeptr : NULL);
731 /* Make a 'restrict'-qualified version of TYPE. */
734 make_restrict_type (struct type *type)
736 return make_qualified_type (type,
737 (TYPE_INSTANCE_FLAGS (type)
738 | TYPE_INSTANCE_FLAG_RESTRICT),
742 /* Make a type without const, volatile, or restrict. */
745 make_unqualified_type (struct type *type)
747 return make_qualified_type (type,
748 (TYPE_INSTANCE_FLAGS (type)
749 & ~(TYPE_INSTANCE_FLAG_CONST
750 | TYPE_INSTANCE_FLAG_VOLATILE
751 | TYPE_INSTANCE_FLAG_RESTRICT)),
755 /* Make a '_Atomic'-qualified version of TYPE. */
758 make_atomic_type (struct type *type)
760 return make_qualified_type (type,
761 (TYPE_INSTANCE_FLAGS (type)
762 | TYPE_INSTANCE_FLAG_ATOMIC),
766 /* Replace the contents of ntype with the type *type. This changes the
767 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
768 the changes are propogated to all types in the TYPE_CHAIN.
770 In order to build recursive types, it's inevitable that we'll need
771 to update types in place --- but this sort of indiscriminate
772 smashing is ugly, and needs to be replaced with something more
773 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
774 clear if more steps are needed. */
777 replace_type (struct type *ntype, struct type *type)
781 /* These two types had better be in the same objfile. Otherwise,
782 the assignment of one type's main type structure to the other
783 will produce a type with references to objects (names; field
784 lists; etc.) allocated on an objfile other than its own. */
785 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (type));
787 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
789 /* The type length is not a part of the main type. Update it for
790 each type on the variant chain. */
794 /* Assert that this element of the chain has no address-class bits
795 set in its flags. Such type variants might have type lengths
796 which are supposed to be different from the non-address-class
797 variants. This assertion shouldn't ever be triggered because
798 symbol readers which do construct address-class variants don't
799 call replace_type(). */
800 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
802 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
803 chain = TYPE_CHAIN (chain);
805 while (ntype != chain);
807 /* Assert that the two types have equivalent instance qualifiers.
808 This should be true for at least all of our debug readers. */
809 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
812 /* Implement direct support for MEMBER_TYPE in GNU C++.
813 May need to construct such a type if this is the first use.
814 The TYPE is the type of the member. The DOMAIN is the type
815 of the aggregate that the member belongs to. */
818 lookup_memberptr_type (struct type *type, struct type *domain)
822 mtype = alloc_type_copy (type);
823 smash_to_memberptr_type (mtype, domain, type);
827 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
830 lookup_methodptr_type (struct type *to_type)
834 mtype = alloc_type_copy (to_type);
835 smash_to_methodptr_type (mtype, to_type);
839 /* Allocate a stub method whose return type is TYPE. This apparently
840 happens for speed of symbol reading, since parsing out the
841 arguments to the method is cpu-intensive, the way we are doing it.
842 So, we will fill in arguments later. This always returns a fresh
846 allocate_stub_method (struct type *type)
850 mtype = alloc_type_copy (type);
851 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
852 TYPE_LENGTH (mtype) = 1;
853 TYPE_STUB (mtype) = 1;
854 TYPE_TARGET_TYPE (mtype) = type;
855 /* TYPE_SELF_TYPE (mtype) = unknown yet */
859 /* Create a range type with a dynamic range from LOW_BOUND to
860 HIGH_BOUND, inclusive. See create_range_type for further details. */
863 create_range_type (struct type *result_type, struct type *index_type,
864 const struct dynamic_prop *low_bound,
865 const struct dynamic_prop *high_bound)
867 if (result_type == NULL)
868 result_type = alloc_type_copy (index_type);
869 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
870 TYPE_TARGET_TYPE (result_type) = index_type;
871 if (TYPE_STUB (index_type))
872 TYPE_TARGET_STUB (result_type) = 1;
874 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
876 TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
877 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
878 TYPE_RANGE_DATA (result_type)->low = *low_bound;
879 TYPE_RANGE_DATA (result_type)->high = *high_bound;
881 if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
882 TYPE_UNSIGNED (result_type) = 1;
884 /* Ada allows the declaration of range types whose upper bound is
885 less than the lower bound, so checking the lower bound is not
886 enough. Make sure we do not mark a range type whose upper bound
887 is negative as unsigned. */
888 if (high_bound->kind == PROP_CONST && high_bound->data.const_val < 0)
889 TYPE_UNSIGNED (result_type) = 0;
894 /* Create a range type using either a blank type supplied in
895 RESULT_TYPE, or creating a new type, inheriting the objfile from
898 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
899 to HIGH_BOUND, inclusive.
901 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
902 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
905 create_static_range_type (struct type *result_type, struct type *index_type,
906 LONGEST low_bound, LONGEST high_bound)
908 struct dynamic_prop low, high;
910 low.kind = PROP_CONST;
911 low.data.const_val = low_bound;
913 high.kind = PROP_CONST;
914 high.data.const_val = high_bound;
916 result_type = create_range_type (result_type, index_type, &low, &high);
921 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
922 are static, otherwise returns 0. */
925 has_static_range (const struct range_bounds *bounds)
927 return (bounds->low.kind == PROP_CONST
928 && bounds->high.kind == PROP_CONST);
932 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
933 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
934 bounds will fit in LONGEST), or -1 otherwise. */
937 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
939 type = check_typedef (type);
940 switch (TYPE_CODE (type))
942 case TYPE_CODE_RANGE:
943 *lowp = TYPE_LOW_BOUND (type);
944 *highp = TYPE_HIGH_BOUND (type);
947 if (TYPE_NFIELDS (type) > 0)
949 /* The enums may not be sorted by value, so search all
953 *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
954 for (i = 0; i < TYPE_NFIELDS (type); i++)
956 if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
957 *lowp = TYPE_FIELD_ENUMVAL (type, i);
958 if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
959 *highp = TYPE_FIELD_ENUMVAL (type, i);
962 /* Set unsigned indicator if warranted. */
965 TYPE_UNSIGNED (type) = 1;
979 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
981 if (!TYPE_UNSIGNED (type))
983 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
987 /* ... fall through for unsigned ints ... */
990 /* This round-about calculation is to avoid shifting by
991 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
992 if TYPE_LENGTH (type) == sizeof (LONGEST). */
993 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
994 *highp = (*highp - 1) | *highp;
1001 /* Assuming TYPE is a simple, non-empty array type, compute its upper
1002 and lower bound. Save the low bound into LOW_BOUND if not NULL.
1003 Save the high bound into HIGH_BOUND if not NULL.
1005 Return 1 if the operation was successful. Return zero otherwise,
1006 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
1008 We now simply use get_discrete_bounds call to get the values
1009 of the low and high bounds.
1010 get_discrete_bounds can return three values:
1011 1, meaning that index is a range,
1012 0, meaning that index is a discrete type,
1013 or -1 for failure. */
1016 get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
1018 struct type *index = TYPE_INDEX_TYPE (type);
1026 res = get_discrete_bounds (index, &low, &high);
1030 /* Check if the array bounds are undefined. */
1032 && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
1033 || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
1045 /* Assuming that TYPE is a discrete type and VAL is a valid integer
1046 representation of a value of this type, save the corresponding
1047 position number in POS.
1049 Its differs from VAL only in the case of enumeration types. In
1050 this case, the position number of the value of the first listed
1051 enumeration literal is zero; the position number of the value of
1052 each subsequent enumeration literal is one more than that of its
1053 predecessor in the list.
1055 Return 1 if the operation was successful. Return zero otherwise,
1056 in which case the value of POS is unmodified.
1060 discrete_position (struct type *type, LONGEST val, LONGEST *pos)
1062 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
1066 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
1068 if (val == TYPE_FIELD_ENUMVAL (type, i))
1074 /* Invalid enumeration value. */
1084 /* Create an array type using either a blank type supplied in
1085 RESULT_TYPE, or creating a new type, inheriting the objfile from
1088 Elements will be of type ELEMENT_TYPE, the indices will be of type
1091 If BIT_STRIDE is not zero, build a packed array type whose element
1092 size is BIT_STRIDE. Otherwise, ignore this parameter.
1094 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1095 sure it is TYPE_CODE_UNDEF before we bash it into an array
1099 create_array_type_with_stride (struct type *result_type,
1100 struct type *element_type,
1101 struct type *range_type,
1102 unsigned int bit_stride)
1104 if (result_type == NULL)
1105 result_type = alloc_type_copy (range_type);
1107 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
1108 TYPE_TARGET_TYPE (result_type) = element_type;
1109 if (has_static_range (TYPE_RANGE_DATA (range_type))
1110 && (!type_not_associated (result_type)
1111 && !type_not_allocated (result_type)))
1113 LONGEST low_bound, high_bound;
1115 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
1116 low_bound = high_bound = 0;
1117 element_type = check_typedef (element_type);
1118 /* Be careful when setting the array length. Ada arrays can be
1119 empty arrays with the high_bound being smaller than the low_bound.
1120 In such cases, the array length should be zero. */
1121 if (high_bound < low_bound)
1122 TYPE_LENGTH (result_type) = 0;
1123 else if (bit_stride > 0)
1124 TYPE_LENGTH (result_type) =
1125 (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
1127 TYPE_LENGTH (result_type) =
1128 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
1132 /* This type is dynamic and its length needs to be computed
1133 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1134 undefined by setting it to zero. Although we are not expected
1135 to trust TYPE_LENGTH in this case, setting the size to zero
1136 allows us to avoid allocating objects of random sizes in case
1137 we accidently do. */
1138 TYPE_LENGTH (result_type) = 0;
1141 TYPE_NFIELDS (result_type) = 1;
1142 TYPE_FIELDS (result_type) =
1143 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
1144 TYPE_INDEX_TYPE (result_type) = range_type;
1146 TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride;
1148 /* TYPE_TARGET_STUB will take care of zero length arrays. */
1149 if (TYPE_LENGTH (result_type) == 0)
1150 TYPE_TARGET_STUB (result_type) = 1;
1155 /* Same as create_array_type_with_stride but with no bit_stride
1156 (BIT_STRIDE = 0), thus building an unpacked array. */
1159 create_array_type (struct type *result_type,
1160 struct type *element_type,
1161 struct type *range_type)
1163 return create_array_type_with_stride (result_type, element_type,
1168 lookup_array_range_type (struct type *element_type,
1169 LONGEST low_bound, LONGEST high_bound)
1171 struct gdbarch *gdbarch = get_type_arch (element_type);
1172 struct type *index_type = builtin_type (gdbarch)->builtin_int;
1173 struct type *range_type
1174 = create_static_range_type (NULL, index_type, low_bound, high_bound);
1176 return create_array_type (NULL, element_type, range_type);
1179 /* Create a string type using either a blank type supplied in
1180 RESULT_TYPE, or creating a new type. String types are similar
1181 enough to array of char types that we can use create_array_type to
1182 build the basic type and then bash it into a string type.
1184 For fixed length strings, the range type contains 0 as the lower
1185 bound and the length of the string minus one as the upper bound.
1187 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1188 sure it is TYPE_CODE_UNDEF before we bash it into a string
1192 create_string_type (struct type *result_type,
1193 struct type *string_char_type,
1194 struct type *range_type)
1196 result_type = create_array_type (result_type,
1199 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1204 lookup_string_range_type (struct type *string_char_type,
1205 LONGEST low_bound, LONGEST high_bound)
1207 struct type *result_type;
1209 result_type = lookup_array_range_type (string_char_type,
1210 low_bound, high_bound);
1211 TYPE_CODE (result_type) = TYPE_CODE_STRING;
1216 create_set_type (struct type *result_type, struct type *domain_type)
1218 if (result_type == NULL)
1219 result_type = alloc_type_copy (domain_type);
1221 TYPE_CODE (result_type) = TYPE_CODE_SET;
1222 TYPE_NFIELDS (result_type) = 1;
1223 TYPE_FIELDS (result_type)
1224 = (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
1226 if (!TYPE_STUB (domain_type))
1228 LONGEST low_bound, high_bound, bit_length;
1230 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
1231 low_bound = high_bound = 0;
1232 bit_length = high_bound - low_bound + 1;
1233 TYPE_LENGTH (result_type)
1234 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1236 TYPE_UNSIGNED (result_type) = 1;
1238 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
1243 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1244 and any array types nested inside it. */
1247 make_vector_type (struct type *array_type)
1249 struct type *inner_array, *elt_type;
1252 /* Find the innermost array type, in case the array is
1253 multi-dimensional. */
1254 inner_array = array_type;
1255 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
1256 inner_array = TYPE_TARGET_TYPE (inner_array);
1258 elt_type = TYPE_TARGET_TYPE (inner_array);
1259 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
1261 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT;
1262 elt_type = make_qualified_type (elt_type, flags, NULL);
1263 TYPE_TARGET_TYPE (inner_array) = elt_type;
1266 TYPE_VECTOR (array_type) = 1;
1270 init_vector_type (struct type *elt_type, int n)
1272 struct type *array_type;
1274 array_type = lookup_array_range_type (elt_type, 0, n - 1);
1275 make_vector_type (array_type);
1279 /* Internal routine called by TYPE_SELF_TYPE to return the type that TYPE
1280 belongs to. In c++ this is the class of "this", but TYPE_THIS_TYPE is too
1281 confusing. "self" is a common enough replacement for "this".
1282 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1283 TYPE_CODE_METHOD. */
1286 internal_type_self_type (struct type *type)
1288 switch (TYPE_CODE (type))
1290 case TYPE_CODE_METHODPTR:
1291 case TYPE_CODE_MEMBERPTR:
1292 if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE)
1294 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_SELF_TYPE);
1295 return TYPE_MAIN_TYPE (type)->type_specific.self_type;
1296 case TYPE_CODE_METHOD:
1297 if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE)
1299 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC);
1300 return TYPE_MAIN_TYPE (type)->type_specific.func_stuff->self_type;
1302 gdb_assert_not_reached ("bad type");
1306 /* Set the type of the class that TYPE belongs to.
1307 In c++ this is the class of "this".
1308 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1309 TYPE_CODE_METHOD. */
1312 set_type_self_type (struct type *type, struct type *self_type)
1314 switch (TYPE_CODE (type))
1316 case TYPE_CODE_METHODPTR:
1317 case TYPE_CODE_MEMBERPTR:
1318 if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE)
1319 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_SELF_TYPE;
1320 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_SELF_TYPE);
1321 TYPE_MAIN_TYPE (type)->type_specific.self_type = self_type;
1323 case TYPE_CODE_METHOD:
1324 if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE)
1325 INIT_FUNC_SPECIFIC (type);
1326 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC);
1327 TYPE_MAIN_TYPE (type)->type_specific.func_stuff->self_type = self_type;
1330 gdb_assert_not_reached ("bad type");
1334 /* Smash TYPE to be a type of pointers to members of SELF_TYPE with type
1335 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1336 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1337 TYPE doesn't include the offset (that's the value of the MEMBER
1338 itself), but does include the structure type into which it points
1341 When "smashing" the type, we preserve the objfile that the old type
1342 pointed to, since we aren't changing where the type is actually
1346 smash_to_memberptr_type (struct type *type, struct type *self_type,
1347 struct type *to_type)
1350 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
1351 TYPE_TARGET_TYPE (type) = to_type;
1352 set_type_self_type (type, self_type);
1353 /* Assume that a data member pointer is the same size as a normal
1356 = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT;
1359 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1361 When "smashing" the type, we preserve the objfile that the old type
1362 pointed to, since we aren't changing where the type is actually
1366 smash_to_methodptr_type (struct type *type, struct type *to_type)
1369 TYPE_CODE (type) = TYPE_CODE_METHODPTR;
1370 TYPE_TARGET_TYPE (type) = to_type;
1371 set_type_self_type (type, TYPE_SELF_TYPE (to_type));
1372 TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
1375 /* Smash TYPE to be a type of method of SELF_TYPE with type TO_TYPE.
1376 METHOD just means `function that gets an extra "this" argument'.
1378 When "smashing" the type, we preserve the objfile that the old type
1379 pointed to, since we aren't changing where the type is actually
1383 smash_to_method_type (struct type *type, struct type *self_type,
1384 struct type *to_type, struct field *args,
1385 int nargs, int varargs)
1388 TYPE_CODE (type) = TYPE_CODE_METHOD;
1389 TYPE_TARGET_TYPE (type) = to_type;
1390 set_type_self_type (type, self_type);
1391 TYPE_FIELDS (type) = args;
1392 TYPE_NFIELDS (type) = nargs;
1394 TYPE_VARARGS (type) = 1;
1395 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1398 /* Return a typename for a struct/union/enum type without "struct ",
1399 "union ", or "enum ". If the type has a NULL name, return NULL. */
1402 type_name_no_tag (const struct type *type)
1404 if (TYPE_TAG_NAME (type) != NULL)
1405 return TYPE_TAG_NAME (type);
1407 /* Is there code which expects this to return the name if there is
1408 no tag name? My guess is that this is mainly used for C++ in
1409 cases where the two will always be the same. */
1410 return TYPE_NAME (type);
1413 /* A wrapper of type_name_no_tag which calls error if the type is anonymous.
1414 Since GCC PR debug/47510 DWARF provides associated information to detect the
1415 anonymous class linkage name from its typedef.
1417 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1421 type_name_no_tag_or_error (struct type *type)
1423 struct type *saved_type = type;
1425 struct objfile *objfile;
1427 type = check_typedef (type);
1429 name = type_name_no_tag (type);
1433 name = type_name_no_tag (saved_type);
1434 objfile = TYPE_OBJFILE (saved_type);
1435 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1436 name ? name : "<anonymous>",
1437 objfile ? objfile_name (objfile) : "<arch>");
1440 /* Lookup a typedef or primitive type named NAME, visible in lexical
1441 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1442 suitably defined. */
1445 lookup_typename (const struct language_defn *language,
1446 struct gdbarch *gdbarch, const char *name,
1447 const struct block *block, int noerr)
1451 sym = lookup_symbol_in_language (name, block, VAR_DOMAIN,
1452 language->la_language, NULL).symbol;
1453 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1454 return SYMBOL_TYPE (sym);
1458 error (_("No type named %s."), name);
1462 lookup_unsigned_typename (const struct language_defn *language,
1463 struct gdbarch *gdbarch, const char *name)
1465 char *uns = (char *) alloca (strlen (name) + 10);
1467 strcpy (uns, "unsigned ");
1468 strcpy (uns + 9, name);
1469 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0);
1473 lookup_signed_typename (const struct language_defn *language,
1474 struct gdbarch *gdbarch, const char *name)
1477 char *uns = (char *) alloca (strlen (name) + 8);
1479 strcpy (uns, "signed ");
1480 strcpy (uns + 7, name);
1481 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1);
1482 /* If we don't find "signed FOO" just try again with plain "FOO". */
1485 return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0);
1488 /* Lookup a structure type named "struct NAME",
1489 visible in lexical block BLOCK. */
1492 lookup_struct (const char *name, const struct block *block)
1496 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
1500 error (_("No struct type named %s."), name);
1502 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1504 error (_("This context has class, union or enum %s, not a struct."),
1507 return (SYMBOL_TYPE (sym));
1510 /* Lookup a union type named "union NAME",
1511 visible in lexical block BLOCK. */
1514 lookup_union (const char *name, const struct block *block)
1519 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
1522 error (_("No union type named %s."), name);
1524 t = SYMBOL_TYPE (sym);
1526 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1529 /* If we get here, it's not a union. */
1530 error (_("This context has class, struct or enum %s, not a union."),
1534 /* Lookup an enum type named "enum NAME",
1535 visible in lexical block BLOCK. */
1538 lookup_enum (const char *name, const struct block *block)
1542 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
1545 error (_("No enum type named %s."), name);
1547 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1549 error (_("This context has class, struct or union %s, not an enum."),
1552 return (SYMBOL_TYPE (sym));
1555 /* Lookup a template type named "template NAME<TYPE>",
1556 visible in lexical block BLOCK. */
1559 lookup_template_type (char *name, struct type *type,
1560 const struct block *block)
1563 char *nam = (char *)
1564 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1568 strcat (nam, TYPE_NAME (type));
1569 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1571 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0).symbol;
1575 error (_("No template type named %s."), name);
1577 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1579 error (_("This context has class, union or enum %s, not a struct."),
1582 return (SYMBOL_TYPE (sym));
1585 /* Given a type TYPE, lookup the type of the component of type named
1588 TYPE can be either a struct or union, or a pointer or reference to
1589 a struct or union. If it is a pointer or reference, its target
1590 type is automatically used. Thus '.' and '->' are interchangable,
1591 as specified for the definitions of the expression element types
1592 STRUCTOP_STRUCT and STRUCTOP_PTR.
1594 If NOERR is nonzero, return zero if NAME is not suitably defined.
1595 If NAME is the name of a baseclass type, return that type. */
1598 lookup_struct_elt_type (struct type *type, const char *name, int noerr)
1604 type = check_typedef (type);
1605 if (TYPE_CODE (type) != TYPE_CODE_PTR
1606 && TYPE_CODE (type) != TYPE_CODE_REF)
1608 type = TYPE_TARGET_TYPE (type);
1611 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1612 && TYPE_CODE (type) != TYPE_CODE_UNION)
1614 std::string type_name = type_to_string (type);
1615 error (_("Type %s is not a structure or union type."),
1616 type_name.c_str ());
1620 /* FIXME: This change put in by Michael seems incorrect for the case
1621 where the structure tag name is the same as the member name.
1622 I.e. when doing "ptype bell->bar" for "struct foo { int bar; int
1623 foo; } bell;" Disabled by fnf. */
1627 type_name = type_name_no_tag (type);
1628 if (type_name != NULL && strcmp (type_name, name) == 0)
1633 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1635 const char *t_field_name = TYPE_FIELD_NAME (type, i);
1637 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1639 return TYPE_FIELD_TYPE (type, i);
1641 else if (!t_field_name || *t_field_name == '\0')
1643 struct type *subtype
1644 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1);
1646 if (subtype != NULL)
1651 /* OK, it's not in this class. Recursively check the baseclasses. */
1652 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1656 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1668 std::string type_name = type_to_string (type);
1669 error (_("Type %s has no component named %s."), type_name.c_str (), name);
1672 /* Store in *MAX the largest number representable by unsigned integer type
1676 get_unsigned_type_max (struct type *type, ULONGEST *max)
1680 type = check_typedef (type);
1681 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_UNSIGNED (type));
1682 gdb_assert (TYPE_LENGTH (type) <= sizeof (ULONGEST));
1684 /* Written this way to avoid overflow. */
1685 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1686 *max = ((((ULONGEST) 1 << (n - 1)) - 1) << 1) | 1;
1689 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1690 signed integer type TYPE. */
1693 get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max)
1697 type = check_typedef (type);
1698 gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && !TYPE_UNSIGNED (type));
1699 gdb_assert (TYPE_LENGTH (type) <= sizeof (LONGEST));
1701 n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
1702 *min = -((ULONGEST) 1 << (n - 1));
1703 *max = ((ULONGEST) 1 << (n - 1)) - 1;
1706 /* Internal routine called by TYPE_VPTR_FIELDNO to return the value of
1707 cplus_stuff.vptr_fieldno.
1709 cplus_stuff is initialized to cplus_struct_default which does not
1710 set vptr_fieldno to -1 for portability reasons (IWBN to use C99
1711 designated initializers). We cope with that here. */
1714 internal_type_vptr_fieldno (struct type *type)
1716 type = check_typedef (type);
1717 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1718 || TYPE_CODE (type) == TYPE_CODE_UNION);
1719 if (!HAVE_CPLUS_STRUCT (type))
1721 return TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno;
1724 /* Set the value of cplus_stuff.vptr_fieldno. */
1727 set_type_vptr_fieldno (struct type *type, int fieldno)
1729 type = check_typedef (type);
1730 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1731 || TYPE_CODE (type) == TYPE_CODE_UNION);
1732 if (!HAVE_CPLUS_STRUCT (type))
1733 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1734 TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno = fieldno;
1737 /* Internal routine called by TYPE_VPTR_BASETYPE to return the value of
1738 cplus_stuff.vptr_basetype. */
1741 internal_type_vptr_basetype (struct type *type)
1743 type = check_typedef (type);
1744 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1745 || TYPE_CODE (type) == TYPE_CODE_UNION);
1746 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_CPLUS_STUFF);
1747 return TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_basetype;
1750 /* Set the value of cplus_stuff.vptr_basetype. */
1753 set_type_vptr_basetype (struct type *type, struct type *basetype)
1755 type = check_typedef (type);
1756 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1757 || TYPE_CODE (type) == TYPE_CODE_UNION);
1758 if (!HAVE_CPLUS_STRUCT (type))
1759 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1760 TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_basetype = basetype;
1763 /* Lookup the vptr basetype/fieldno values for TYPE.
1764 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1765 vptr_fieldno. Also, if found and basetype is from the same objfile,
1767 If not found, return -1 and ignore BASETYPEP.
1768 Callers should be aware that in some cases (for example,
1769 the type or one of its baseclasses is a stub type and we are
1770 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1771 this function will not be able to find the
1772 virtual function table pointer, and vptr_fieldno will remain -1 and
1773 vptr_basetype will remain NULL or incomplete. */
1776 get_vptr_fieldno (struct type *type, struct type **basetypep)
1778 type = check_typedef (type);
1780 if (TYPE_VPTR_FIELDNO (type) < 0)
1784 /* We must start at zero in case the first (and only) baseclass
1785 is virtual (and hence we cannot share the table pointer). */
1786 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1788 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1790 struct type *basetype;
1792 fieldno = get_vptr_fieldno (baseclass, &basetype);
1795 /* If the type comes from a different objfile we can't cache
1796 it, it may have a different lifetime. PR 2384 */
1797 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
1799 set_type_vptr_fieldno (type, fieldno);
1800 set_type_vptr_basetype (type, basetype);
1803 *basetypep = basetype;
1814 *basetypep = TYPE_VPTR_BASETYPE (type);
1815 return TYPE_VPTR_FIELDNO (type);
1820 stub_noname_complaint (void)
1822 complaint (&symfile_complaints, _("stub type has NULL name"));
1825 /* Worker for is_dynamic_type. */
1828 is_dynamic_type_internal (struct type *type, int top_level)
1830 type = check_typedef (type);
1832 /* We only want to recognize references at the outermost level. */
1833 if (top_level && TYPE_CODE (type) == TYPE_CODE_REF)
1834 type = check_typedef (TYPE_TARGET_TYPE (type));
1836 /* Types that have a dynamic TYPE_DATA_LOCATION are considered
1837 dynamic, even if the type itself is statically defined.
1838 From a user's point of view, this may appear counter-intuitive;
1839 but it makes sense in this context, because the point is to determine
1840 whether any part of the type needs to be resolved before it can
1842 if (TYPE_DATA_LOCATION (type) != NULL
1843 && (TYPE_DATA_LOCATION_KIND (type) == PROP_LOCEXPR
1844 || TYPE_DATA_LOCATION_KIND (type) == PROP_LOCLIST))
1847 if (TYPE_ASSOCIATED_PROP (type))
1850 if (TYPE_ALLOCATED_PROP (type))
1853 switch (TYPE_CODE (type))
1855 case TYPE_CODE_RANGE:
1857 /* A range type is obviously dynamic if it has at least one
1858 dynamic bound. But also consider the range type to be
1859 dynamic when its subtype is dynamic, even if the bounds
1860 of the range type are static. It allows us to assume that
1861 the subtype of a static range type is also static. */
1862 return (!has_static_range (TYPE_RANGE_DATA (type))
1863 || is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0));
1866 case TYPE_CODE_ARRAY:
1868 gdb_assert (TYPE_NFIELDS (type) == 1);
1870 /* The array is dynamic if either the bounds are dynamic,
1871 or the elements it contains have a dynamic contents. */
1872 if (is_dynamic_type_internal (TYPE_INDEX_TYPE (type), 0))
1874 return is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0);
1877 case TYPE_CODE_STRUCT:
1878 case TYPE_CODE_UNION:
1882 for (i = 0; i < TYPE_NFIELDS (type); ++i)
1883 if (!field_is_static (&TYPE_FIELD (type, i))
1884 && is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i), 0))
1893 /* See gdbtypes.h. */
1896 is_dynamic_type (struct type *type)
1898 return is_dynamic_type_internal (type, 1);
1901 static struct type *resolve_dynamic_type_internal
1902 (struct type *type, struct property_addr_info *addr_stack, int top_level);
1904 /* Given a dynamic range type (dyn_range_type) and a stack of
1905 struct property_addr_info elements, return a static version
1908 static struct type *
1909 resolve_dynamic_range (struct type *dyn_range_type,
1910 struct property_addr_info *addr_stack)
1913 struct type *static_range_type, *static_target_type;
1914 const struct dynamic_prop *prop;
1915 struct dynamic_prop low_bound, high_bound;
1917 gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
1919 prop = &TYPE_RANGE_DATA (dyn_range_type)->low;
1920 if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
1922 low_bound.kind = PROP_CONST;
1923 low_bound.data.const_val = value;
1927 low_bound.kind = PROP_UNDEFINED;
1928 low_bound.data.const_val = 0;
1931 prop = &TYPE_RANGE_DATA (dyn_range_type)->high;
1932 if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
1934 high_bound.kind = PROP_CONST;
1935 high_bound.data.const_val = value;
1937 if (TYPE_RANGE_DATA (dyn_range_type)->flag_upper_bound_is_count)
1938 high_bound.data.const_val
1939 = low_bound.data.const_val + high_bound.data.const_val - 1;
1943 high_bound.kind = PROP_UNDEFINED;
1944 high_bound.data.const_val = 0;
1948 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type),
1950 static_range_type = create_range_type (copy_type (dyn_range_type),
1952 &low_bound, &high_bound);
1953 TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
1954 return static_range_type;
1957 /* Resolves dynamic bound values of an array type TYPE to static ones.
1958 ADDR_STACK is a stack of struct property_addr_info to be used
1959 if needed during the dynamic resolution. */
1961 static struct type *
1962 resolve_dynamic_array (struct type *type,
1963 struct property_addr_info *addr_stack)
1966 struct type *elt_type;
1967 struct type *range_type;
1968 struct type *ary_dim;
1969 struct dynamic_prop *prop;
1971 gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY);
1973 type = copy_type (type);
1976 range_type = check_typedef (TYPE_INDEX_TYPE (elt_type));
1977 range_type = resolve_dynamic_range (range_type, addr_stack);
1979 /* Resolve allocated/associated here before creating a new array type, which
1980 will update the length of the array accordingly. */
1981 prop = TYPE_ALLOCATED_PROP (type);
1982 if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
1984 TYPE_DYN_PROP_ADDR (prop) = value;
1985 TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
1987 prop = TYPE_ASSOCIATED_PROP (type);
1988 if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
1990 TYPE_DYN_PROP_ADDR (prop) = value;
1991 TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
1994 ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
1996 if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY)
1997 elt_type = resolve_dynamic_array (ary_dim, addr_stack);
1999 elt_type = TYPE_TARGET_TYPE (type);
2001 return create_array_type_with_stride (type, elt_type, range_type,
2002 TYPE_FIELD_BITSIZE (type, 0));
2005 /* Resolve dynamic bounds of members of the union TYPE to static
2006 bounds. ADDR_STACK is a stack of struct property_addr_info
2007 to be used if needed during the dynamic resolution. */
2009 static struct type *
2010 resolve_dynamic_union (struct type *type,
2011 struct property_addr_info *addr_stack)
2013 struct type *resolved_type;
2015 unsigned int max_len = 0;
2017 gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
2019 resolved_type = copy_type (type);
2020 TYPE_FIELDS (resolved_type)
2021 = (struct field *) TYPE_ALLOC (resolved_type,
2022 TYPE_NFIELDS (resolved_type)
2023 * sizeof (struct field));
2024 memcpy (TYPE_FIELDS (resolved_type),
2026 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
2027 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
2031 if (field_is_static (&TYPE_FIELD (type, i)))
2034 t = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
2036 TYPE_FIELD_TYPE (resolved_type, i) = t;
2037 if (TYPE_LENGTH (t) > max_len)
2038 max_len = TYPE_LENGTH (t);
2041 TYPE_LENGTH (resolved_type) = max_len;
2042 return resolved_type;
2045 /* Resolve dynamic bounds of members of the struct TYPE to static
2046 bounds. ADDR_STACK is a stack of struct property_addr_info to
2047 be used if needed during the dynamic resolution. */
2049 static struct type *
2050 resolve_dynamic_struct (struct type *type,
2051 struct property_addr_info *addr_stack)
2053 struct type *resolved_type;
2055 unsigned resolved_type_bit_length = 0;
2057 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
2058 gdb_assert (TYPE_NFIELDS (type) > 0);
2060 resolved_type = copy_type (type);
2061 TYPE_FIELDS (resolved_type)
2062 = (struct field *) TYPE_ALLOC (resolved_type,
2063 TYPE_NFIELDS (resolved_type)
2064 * sizeof (struct field));
2065 memcpy (TYPE_FIELDS (resolved_type),
2067 TYPE_NFIELDS (resolved_type) * sizeof (struct field));
2068 for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
2070 unsigned new_bit_length;
2071 struct property_addr_info pinfo;
2073 if (field_is_static (&TYPE_FIELD (type, i)))
2076 /* As we know this field is not a static field, the field's
2077 field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
2078 this is the case, but only trigger a simple error rather
2079 than an internal error if that fails. While failing
2080 that verification indicates a bug in our code, the error
2081 is not severe enough to suggest to the user he stops
2082 his debugging session because of it. */
2083 if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_BITPOS)
2084 error (_("Cannot determine struct field location"
2085 " (invalid location kind)"));
2087 pinfo.type = check_typedef (TYPE_FIELD_TYPE (type, i));
2088 pinfo.valaddr = addr_stack->valaddr;
2091 + (TYPE_FIELD_BITPOS (resolved_type, i) / TARGET_CHAR_BIT));
2092 pinfo.next = addr_stack;
2094 TYPE_FIELD_TYPE (resolved_type, i)
2095 = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
2097 gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type, i)
2098 == FIELD_LOC_KIND_BITPOS);
2100 new_bit_length = TYPE_FIELD_BITPOS (resolved_type, i);
2101 if (TYPE_FIELD_BITSIZE (resolved_type, i) != 0)
2102 new_bit_length += TYPE_FIELD_BITSIZE (resolved_type, i);
2104 new_bit_length += (TYPE_LENGTH (TYPE_FIELD_TYPE (resolved_type, i))
2107 /* Normally, we would use the position and size of the last field
2108 to determine the size of the enclosing structure. But GCC seems
2109 to be encoding the position of some fields incorrectly when
2110 the struct contains a dynamic field that is not placed last.
2111 So we compute the struct size based on the field that has
2112 the highest position + size - probably the best we can do. */
2113 if (new_bit_length > resolved_type_bit_length)
2114 resolved_type_bit_length = new_bit_length;
2117 /* The length of a type won't change for fortran, but it does for C and Ada.
2118 For fortran the size of dynamic fields might change over time but not the
2119 type length of the structure. If we adapt it, we run into problems
2120 when calculating the element offset for arrays of structs. */
2121 if (current_language->la_language != language_fortran)
2122 TYPE_LENGTH (resolved_type)
2123 = (resolved_type_bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2125 /* The Ada language uses this field as a cache for static fixed types: reset
2126 it as RESOLVED_TYPE must have its own static fixed type. */
2127 TYPE_TARGET_TYPE (resolved_type) = NULL;
2129 return resolved_type;
2132 /* Worker for resolved_dynamic_type. */
2134 static struct type *
2135 resolve_dynamic_type_internal (struct type *type,
2136 struct property_addr_info *addr_stack,
2139 struct type *real_type = check_typedef (type);
2140 struct type *resolved_type = type;
2141 struct dynamic_prop *prop;
2144 if (!is_dynamic_type_internal (real_type, top_level))
2147 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
2149 resolved_type = copy_type (type);
2150 TYPE_TARGET_TYPE (resolved_type)
2151 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack,
2156 /* Before trying to resolve TYPE, make sure it is not a stub. */
2159 switch (TYPE_CODE (type))
2163 struct property_addr_info pinfo;
2165 pinfo.type = check_typedef (TYPE_TARGET_TYPE (type));
2166 pinfo.valaddr = NULL;
2167 if (addr_stack->valaddr != NULL)
2168 pinfo.addr = extract_typed_address (addr_stack->valaddr, type);
2170 pinfo.addr = read_memory_typed_address (addr_stack->addr, type);
2171 pinfo.next = addr_stack;
2173 resolved_type = copy_type (type);
2174 TYPE_TARGET_TYPE (resolved_type)
2175 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
2180 case TYPE_CODE_ARRAY:
2181 resolved_type = resolve_dynamic_array (type, addr_stack);
2184 case TYPE_CODE_RANGE:
2185 resolved_type = resolve_dynamic_range (type, addr_stack);
2188 case TYPE_CODE_UNION:
2189 resolved_type = resolve_dynamic_union (type, addr_stack);
2192 case TYPE_CODE_STRUCT:
2193 resolved_type = resolve_dynamic_struct (type, addr_stack);
2198 /* Resolve data_location attribute. */
2199 prop = TYPE_DATA_LOCATION (resolved_type);
2201 && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
2203 TYPE_DYN_PROP_ADDR (prop) = value;
2204 TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
2207 return resolved_type;
2210 /* See gdbtypes.h */
2213 resolve_dynamic_type (struct type *type, const gdb_byte *valaddr,
2216 struct property_addr_info pinfo
2217 = {check_typedef (type), valaddr, addr, NULL};
2219 return resolve_dynamic_type_internal (type, &pinfo, 1);
2222 /* See gdbtypes.h */
2224 struct dynamic_prop *
2225 get_dyn_prop (enum dynamic_prop_node_kind prop_kind, const struct type *type)
2227 struct dynamic_prop_list *node = TYPE_DYN_PROP_LIST (type);
2229 while (node != NULL)
2231 if (node->prop_kind == prop_kind)
2238 /* See gdbtypes.h */
2241 add_dyn_prop (enum dynamic_prop_node_kind prop_kind, struct dynamic_prop prop,
2242 struct type *type, struct objfile *objfile)
2244 struct dynamic_prop_list *temp;
2246 gdb_assert (TYPE_OBJFILE_OWNED (type));
2248 temp = XOBNEW (&objfile->objfile_obstack, struct dynamic_prop_list);
2249 temp->prop_kind = prop_kind;
2251 temp->next = TYPE_DYN_PROP_LIST (type);
2253 TYPE_DYN_PROP_LIST (type) = temp;
2256 /* Remove dynamic property from TYPE in case it exists. */
2259 remove_dyn_prop (enum dynamic_prop_node_kind prop_kind,
2262 struct dynamic_prop_list *prev_node, *curr_node;
2264 curr_node = TYPE_DYN_PROP_LIST (type);
2267 while (NULL != curr_node)
2269 if (curr_node->prop_kind == prop_kind)
2271 /* Update the linked list but don't free anything.
2272 The property was allocated on objstack and it is not known
2273 if we are on top of it. Nevertheless, everything is released
2274 when the complete objstack is freed. */
2275 if (NULL == prev_node)
2276 TYPE_DYN_PROP_LIST (type) = curr_node->next;
2278 prev_node->next = curr_node->next;
2283 prev_node = curr_node;
2284 curr_node = curr_node->next;
2288 /* Find the real type of TYPE. This function returns the real type,
2289 after removing all layers of typedefs, and completing opaque or stub
2290 types. Completion changes the TYPE argument, but stripping of
2293 Instance flags (e.g. const/volatile) are preserved as typedefs are
2294 stripped. If necessary a new qualified form of the underlying type
2297 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
2298 not been computed and we're either in the middle of reading symbols, or
2299 there was no name for the typedef in the debug info.
2301 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
2302 QUITs in the symbol reading code can also throw.
2303 Thus this function can throw an exception.
2305 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
2308 If this is a stubbed struct (i.e. declared as struct foo *), see if
2309 we can find a full definition in some other file. If so, copy this
2310 definition, so we can use it in future. There used to be a comment
2311 (but not any code) that if we don't find a full definition, we'd
2312 set a flag so we don't spend time in the future checking the same
2313 type. That would be a mistake, though--we might load in more
2314 symbols which contain a full definition for the type. */
2317 check_typedef (struct type *type)
2319 struct type *orig_type = type;
2320 /* While we're removing typedefs, we don't want to lose qualifiers.
2321 E.g., const/volatile. */
2322 int instance_flags = TYPE_INSTANCE_FLAGS (type);
2326 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
2328 if (!TYPE_TARGET_TYPE (type))
2333 /* It is dangerous to call lookup_symbol if we are currently
2334 reading a symtab. Infinite recursion is one danger. */
2335 if (currently_reading_symtab)
2336 return make_qualified_type (type, instance_flags, NULL);
2338 name = type_name_no_tag (type);
2339 /* FIXME: shouldn't we separately check the TYPE_NAME and
2340 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
2341 VAR_DOMAIN as appropriate? (this code was written before
2342 TYPE_NAME and TYPE_TAG_NAME were separate). */
2345 stub_noname_complaint ();
2346 return make_qualified_type (type, instance_flags, NULL);
2348 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
2350 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
2351 else /* TYPE_CODE_UNDEF */
2352 TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type));
2354 type = TYPE_TARGET_TYPE (type);
2356 /* Preserve the instance flags as we traverse down the typedef chain.
2358 Handling address spaces/classes is nasty, what do we do if there's a
2360 E.g., what if an outer typedef marks the type as class_1 and an inner
2361 typedef marks the type as class_2?
2362 This is the wrong place to do such error checking. We leave it to
2363 the code that created the typedef in the first place to flag the
2364 error. We just pick the outer address space (akin to letting the
2365 outer cast in a chain of casting win), instead of assuming
2366 "it can't happen". */
2368 const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE
2369 | TYPE_INSTANCE_FLAG_DATA_SPACE);
2370 const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
2371 int new_instance_flags = TYPE_INSTANCE_FLAGS (type);
2373 /* Treat code vs data spaces and address classes separately. */
2374 if ((instance_flags & ALL_SPACES) != 0)
2375 new_instance_flags &= ~ALL_SPACES;
2376 if ((instance_flags & ALL_CLASSES) != 0)
2377 new_instance_flags &= ~ALL_CLASSES;
2379 instance_flags |= new_instance_flags;
2383 /* If this is a struct/class/union with no fields, then check
2384 whether a full definition exists somewhere else. This is for
2385 systems where a type definition with no fields is issued for such
2386 types, instead of identifying them as stub types in the first
2389 if (TYPE_IS_OPAQUE (type)
2390 && opaque_type_resolution
2391 && !currently_reading_symtab)
2393 const char *name = type_name_no_tag (type);
2394 struct type *newtype;
2398 stub_noname_complaint ();
2399 return make_qualified_type (type, instance_flags, NULL);
2401 newtype = lookup_transparent_type (name);
2405 /* If the resolved type and the stub are in the same
2406 objfile, then replace the stub type with the real deal.
2407 But if they're in separate objfiles, leave the stub
2408 alone; we'll just look up the transparent type every time
2409 we call check_typedef. We can't create pointers between
2410 types allocated to different objfiles, since they may
2411 have different lifetimes. Trying to copy NEWTYPE over to
2412 TYPE's objfile is pointless, too, since you'll have to
2413 move over any other types NEWTYPE refers to, which could
2414 be an unbounded amount of stuff. */
2415 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
2416 type = make_qualified_type (newtype,
2417 TYPE_INSTANCE_FLAGS (type),
2423 /* Otherwise, rely on the stub flag being set for opaque/stubbed
2425 else if (TYPE_STUB (type) && !currently_reading_symtab)
2427 const char *name = type_name_no_tag (type);
2428 /* FIXME: shouldn't we separately check the TYPE_NAME and the
2429 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
2430 as appropriate? (this code was written before TYPE_NAME and
2431 TYPE_TAG_NAME were separate). */
2436 stub_noname_complaint ();
2437 return make_qualified_type (type, instance_flags, NULL);
2439 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
2442 /* Same as above for opaque types, we can replace the stub
2443 with the complete type only if they are in the same
2445 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
2446 type = make_qualified_type (SYMBOL_TYPE (sym),
2447 TYPE_INSTANCE_FLAGS (type),
2450 type = SYMBOL_TYPE (sym);
2454 if (TYPE_TARGET_STUB (type))
2456 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
2458 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
2460 /* Nothing we can do. */
2462 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
2464 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
2465 TYPE_TARGET_STUB (type) = 0;
2469 type = make_qualified_type (type, instance_flags, NULL);
2471 /* Cache TYPE_LENGTH for future use. */
2472 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
2477 /* Parse a type expression in the string [P..P+LENGTH). If an error
2478 occurs, silently return a void type. */
2480 static struct type *
2481 safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
2483 struct ui_file *saved_gdb_stderr;
2484 struct type *type = NULL; /* Initialize to keep gcc happy. */
2486 /* Suppress error messages. */
2487 saved_gdb_stderr = gdb_stderr;
2488 gdb_stderr = &null_stream;
2490 /* Call parse_and_eval_type() without fear of longjmp()s. */
2493 type = parse_and_eval_type (p, length);
2495 CATCH (except, RETURN_MASK_ERROR)
2497 type = builtin_type (gdbarch)->builtin_void;
2501 /* Stop suppressing error messages. */
2502 gdb_stderr = saved_gdb_stderr;
2507 /* Ugly hack to convert method stubs into method types.
2509 He ain't kiddin'. This demangles the name of the method into a
2510 string including argument types, parses out each argument type,
2511 generates a string casting a zero to that type, evaluates the
2512 string, and stuffs the resulting type into an argtype vector!!!
2513 Then it knows the type of the whole function (including argument
2514 types for overloading), which info used to be in the stab's but was
2515 removed to hack back the space required for them. */
2518 check_stub_method (struct type *type, int method_id, int signature_id)
2520 struct gdbarch *gdbarch = get_type_arch (type);
2522 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
2523 char *demangled_name = gdb_demangle (mangled_name,
2524 DMGL_PARAMS | DMGL_ANSI);
2525 char *argtypetext, *p;
2526 int depth = 0, argcount = 1;
2527 struct field *argtypes;
2530 /* Make sure we got back a function string that we can use. */
2532 p = strchr (demangled_name, '(');
2536 if (demangled_name == NULL || p == NULL)
2537 error (_("Internal: Cannot demangle mangled name `%s'."),
2540 /* Now, read in the parameters that define this type. */
2545 if (*p == '(' || *p == '<')
2549 else if (*p == ')' || *p == '>')
2553 else if (*p == ',' && depth == 0)
2561 /* If we read one argument and it was ``void'', don't count it. */
2562 if (startswith (argtypetext, "(void)"))
2565 /* We need one extra slot, for the THIS pointer. */
2567 argtypes = (struct field *)
2568 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
2571 /* Add THIS pointer for non-static methods. */
2572 f = TYPE_FN_FIELDLIST1 (type, method_id);
2573 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
2577 argtypes[0].type = lookup_pointer_type (type);
2581 if (*p != ')') /* () means no args, skip while. */
2586 if (depth <= 0 && (*p == ',' || *p == ')'))
2588 /* Avoid parsing of ellipsis, they will be handled below.
2589 Also avoid ``void'' as above. */
2590 if (strncmp (argtypetext, "...", p - argtypetext) != 0
2591 && strncmp (argtypetext, "void", p - argtypetext) != 0)
2593 argtypes[argcount].type =
2594 safe_parse_type (gdbarch, argtypetext, p - argtypetext);
2597 argtypetext = p + 1;
2600 if (*p == '(' || *p == '<')
2604 else if (*p == ')' || *p == '>')
2613 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
2615 /* Now update the old "stub" type into a real type. */
2616 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
2617 /* MTYPE may currently be a function (TYPE_CODE_FUNC).
2618 We want a method (TYPE_CODE_METHOD). */
2619 smash_to_method_type (mtype, type, TYPE_TARGET_TYPE (mtype),
2620 argtypes, argcount, p[-2] == '.');
2621 TYPE_STUB (mtype) = 0;
2622 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
2624 xfree (demangled_name);
2627 /* This is the external interface to check_stub_method, above. This
2628 function unstubs all of the signatures for TYPE's METHOD_ID method
2629 name. After calling this function TYPE_FN_FIELD_STUB will be
2630 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
2633 This function unfortunately can not die until stabs do. */
2636 check_stub_method_group (struct type *type, int method_id)
2638 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
2639 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
2640 int j, found_stub = 0;
2642 for (j = 0; j < len; j++)
2643 if (TYPE_FN_FIELD_STUB (f, j))
2646 check_stub_method (type, method_id, j);
2649 /* GNU v3 methods with incorrect names were corrected when we read
2650 in type information, because it was cheaper to do it then. The
2651 only GNU v2 methods with incorrect method names are operators and
2652 destructors; destructors were also corrected when we read in type
2655 Therefore the only thing we need to handle here are v2 operator
2657 if (found_stub && !startswith (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z"))
2660 char dem_opname[256];
2662 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2664 dem_opname, DMGL_ANSI);
2666 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
2670 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
2674 /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
2675 const struct cplus_struct_type cplus_struct_default = { };
2678 allocate_cplus_struct_type (struct type *type)
2680 if (HAVE_CPLUS_STRUCT (type))
2681 /* Structure was already allocated. Nothing more to do. */
2684 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF;
2685 TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
2686 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
2687 *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default;
2688 set_type_vptr_fieldno (type, -1);
2691 const struct gnat_aux_type gnat_aux_default =
2694 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
2695 and allocate the associated gnat-specific data. The gnat-specific
2696 data is also initialized to gnat_aux_default. */
2699 allocate_gnat_aux_type (struct type *type)
2701 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF;
2702 TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *)
2703 TYPE_ALLOC (type, sizeof (struct gnat_aux_type));
2704 *(TYPE_GNAT_SPECIFIC (type)) = gnat_aux_default;
2707 /* Helper function to initialize a newly allocated type. Set type code
2708 to CODE and initialize the type-specific fields accordingly. */
2711 set_type_code (struct type *type, enum type_code code)
2713 TYPE_CODE (type) = code;
2717 case TYPE_CODE_STRUCT:
2718 case TYPE_CODE_UNION:
2719 case TYPE_CODE_NAMESPACE:
2720 INIT_CPLUS_SPECIFIC (type);
2723 TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT;
2725 case TYPE_CODE_FUNC:
2726 INIT_FUNC_SPECIFIC (type);
2731 /* Helper function to verify floating-point format and size.
2732 BIT is the type size in bits; if BIT equals -1, the size is
2733 determined by the floatformat. Returns size to be used. */
2736 verify_floatformat (int bit, const struct floatformat **floatformats)
2738 gdb_assert (floatformats != NULL);
2739 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
2742 bit = floatformats[0]->totalsize;
2743 gdb_assert (bit >= 0);
2745 size_t len = bit / TARGET_CHAR_BIT;
2746 gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0]));
2747 gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1]));
2752 /* Helper function to initialize the standard scalar types.
2754 If NAME is non-NULL, then it is used to initialize the type name.
2755 Note that NAME is not copied; it is required to have a lifetime at
2756 least as long as OBJFILE. */
2759 init_type (struct objfile *objfile, enum type_code code, int length,
2764 type = alloc_type (objfile);
2765 set_type_code (type, code);
2766 TYPE_LENGTH (type) = length;
2767 TYPE_NAME (type) = name;
2772 /* Allocate a TYPE_CODE_INT type structure associated with OBJFILE.
2773 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
2774 the type's TYPE_UNSIGNED flag. NAME is the type name. */
2777 init_integer_type (struct objfile *objfile,
2778 int bit, int unsigned_p, const char *name)
2782 t = init_type (objfile, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
2784 TYPE_UNSIGNED (t) = 1;
2789 /* Allocate a TYPE_CODE_CHAR type structure associated with OBJFILE.
2790 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
2791 the type's TYPE_UNSIGNED flag. NAME is the type name. */
2794 init_character_type (struct objfile *objfile,
2795 int bit, int unsigned_p, const char *name)
2799 t = init_type (objfile, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
2801 TYPE_UNSIGNED (t) = 1;
2806 /* Allocate a TYPE_CODE_BOOL type structure associated with OBJFILE.
2807 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
2808 the type's TYPE_UNSIGNED flag. NAME is the type name. */
2811 init_boolean_type (struct objfile *objfile,
2812 int bit, int unsigned_p, const char *name)
2816 t = init_type (objfile, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
2818 TYPE_UNSIGNED (t) = 1;
2823 /* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
2824 BIT is the type size in bits; if BIT equals -1, the size is
2825 determined by the floatformat. NAME is the type name. Set the
2826 TYPE_FLOATFORMAT from FLOATFORMATS. */
2829 init_float_type (struct objfile *objfile,
2830 int bit, const char *name,
2831 const struct floatformat **floatformats)
2835 bit = verify_floatformat (bit, floatformats);
2836 t = init_type (objfile, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
2837 TYPE_FLOATFORMAT (t) = floatformats;
2842 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with OBJFILE.
2843 BIT is the type size in bits. NAME is the type name. */
2846 init_decfloat_type (struct objfile *objfile, int bit, const char *name)
2850 t = init_type (objfile, TYPE_CODE_DECFLOAT, bit / TARGET_CHAR_BIT, name);
2854 /* Allocate a TYPE_CODE_COMPLEX type structure associated with OBJFILE.
2855 NAME is the type name. TARGET_TYPE is the component float type. */
2858 init_complex_type (struct objfile *objfile,
2859 const char *name, struct type *target_type)
2863 t = init_type (objfile, TYPE_CODE_COMPLEX,
2864 2 * TYPE_LENGTH (target_type), name);
2865 TYPE_TARGET_TYPE (t) = target_type;
2869 /* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE.
2870 BIT is the pointer type size in bits. NAME is the type name.
2871 TARGET_TYPE is the pointer target type. Always sets the pointer type's
2872 TYPE_UNSIGNED flag. */
2875 init_pointer_type (struct objfile *objfile,
2876 int bit, const char *name, struct type *target_type)
2880 t = init_type (objfile, TYPE_CODE_PTR, bit / TARGET_CHAR_BIT, name);
2881 TYPE_TARGET_TYPE (t) = target_type;
2882 TYPE_UNSIGNED (t) = 1;
2887 /* Queries on types. */
2890 can_dereference (struct type *t)
2892 /* FIXME: Should we return true for references as well as
2894 t = check_typedef (t);
2897 && TYPE_CODE (t) == TYPE_CODE_PTR
2898 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
2902 is_integral_type (struct type *t)
2904 t = check_typedef (t);
2907 && ((TYPE_CODE (t) == TYPE_CODE_INT)
2908 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
2909 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
2910 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
2911 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
2912 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
2915 /* Return true if TYPE is scalar. */
2918 is_scalar_type (struct type *type)
2920 type = check_typedef (type);
2922 switch (TYPE_CODE (type))
2924 case TYPE_CODE_ARRAY:
2925 case TYPE_CODE_STRUCT:
2926 case TYPE_CODE_UNION:
2928 case TYPE_CODE_STRING:
2935 /* Return true if T is scalar, or a composite type which in practice has
2936 the memory layout of a scalar type. E.g., an array or struct with only
2937 one scalar element inside it, or a union with only scalar elements. */
2940 is_scalar_type_recursive (struct type *t)
2942 t = check_typedef (t);
2944 if (is_scalar_type (t))
2946 /* Are we dealing with an array or string of known dimensions? */
2947 else if ((TYPE_CODE (t) == TYPE_CODE_ARRAY
2948 || TYPE_CODE (t) == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1
2949 && TYPE_CODE (TYPE_INDEX_TYPE (t)) == TYPE_CODE_RANGE)
2951 LONGEST low_bound, high_bound;
2952 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (t));
2954 get_discrete_bounds (TYPE_INDEX_TYPE (t), &low_bound, &high_bound);
2956 return high_bound == low_bound && is_scalar_type_recursive (elt_type);
2958 /* Are we dealing with a struct with one element? */
2959 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1)
2960 return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0));
2961 else if (TYPE_CODE (t) == TYPE_CODE_UNION)
2963 int i, n = TYPE_NFIELDS (t);
2965 /* If all elements of the union are scalar, then the union is scalar. */
2966 for (i = 0; i < n; i++)
2967 if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t, i)))
2976 /* Return true is T is a class or a union. False otherwise. */
2979 class_or_union_p (const struct type *t)
2981 return (TYPE_CODE (t) == TYPE_CODE_STRUCT
2982 || TYPE_CODE (t) == TYPE_CODE_UNION);
2985 /* A helper function which returns true if types A and B represent the
2986 "same" class type. This is true if the types have the same main
2987 type, or the same name. */
2990 class_types_same_p (const struct type *a, const struct type *b)
2992 return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b)
2993 || (TYPE_NAME (a) && TYPE_NAME (b)
2994 && !strcmp (TYPE_NAME (a), TYPE_NAME (b))));
2997 /* If BASE is an ancestor of DCLASS return the distance between them.
2998 otherwise return -1;
3002 class B: public A {};
3003 class C: public B {};
3006 distance_to_ancestor (A, A, 0) = 0
3007 distance_to_ancestor (A, B, 0) = 1
3008 distance_to_ancestor (A, C, 0) = 2
3009 distance_to_ancestor (A, D, 0) = 3
3011 If PUBLIC is 1 then only public ancestors are considered,
3012 and the function returns the distance only if BASE is a public ancestor
3016 distance_to_ancestor (A, D, 1) = -1. */
3019 distance_to_ancestor (struct type *base, struct type *dclass, int is_public)
3024 base = check_typedef (base);
3025 dclass = check_typedef (dclass);
3027 if (class_types_same_p (base, dclass))
3030 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
3032 if (is_public && ! BASETYPE_VIA_PUBLIC (dclass, i))
3035 d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), is_public);
3043 /* Check whether BASE is an ancestor or base class or DCLASS
3044 Return 1 if so, and 0 if not.
3045 Note: If BASE and DCLASS are of the same type, this function
3046 will return 1. So for some class A, is_ancestor (A, A) will
3050 is_ancestor (struct type *base, struct type *dclass)
3052 return distance_to_ancestor (base, dclass, 0) >= 0;
3055 /* Like is_ancestor, but only returns true when BASE is a public
3056 ancestor of DCLASS. */
3059 is_public_ancestor (struct type *base, struct type *dclass)
3061 return distance_to_ancestor (base, dclass, 1) >= 0;
3064 /* A helper function for is_unique_ancestor. */
3067 is_unique_ancestor_worker (struct type *base, struct type *dclass,
3069 const gdb_byte *valaddr, int embedded_offset,
3070 CORE_ADDR address, struct value *val)
3074 base = check_typedef (base);
3075 dclass = check_typedef (dclass);
3077 for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
3082 iter = check_typedef (TYPE_BASECLASS (dclass, i));
3084 this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset,
3087 if (class_types_same_p (base, iter))
3089 /* If this is the first subclass, set *OFFSET and set count
3090 to 1. Otherwise, if this is at the same offset as
3091 previous instances, do nothing. Otherwise, increment
3095 *offset = this_offset;
3098 else if (this_offset == *offset)
3106 count += is_unique_ancestor_worker (base, iter, offset,
3108 embedded_offset + this_offset,
3115 /* Like is_ancestor, but only returns true if BASE is a unique base
3116 class of the type of VAL. */
3119 is_unique_ancestor (struct type *base, struct value *val)
3123 return is_unique_ancestor_worker (base, value_type (val), &offset,
3124 value_contents_for_printing (val),
3125 value_embedded_offset (val),
3126 value_address (val), val) == 1;
3130 /* Overload resolution. */
3132 /* Return the sum of the rank of A with the rank of B. */
3135 sum_ranks (struct rank a, struct rank b)
3138 c.rank = a.rank + b.rank;
3139 c.subrank = a.subrank + b.subrank;
3143 /* Compare rank A and B and return:
3145 1 if a is better than b
3146 -1 if b is better than a. */
3149 compare_ranks (struct rank a, struct rank b)
3151 if (a.rank == b.rank)
3153 if (a.subrank == b.subrank)
3155 if (a.subrank < b.subrank)
3157 if (a.subrank > b.subrank)
3161 if (a.rank < b.rank)
3164 /* a.rank > b.rank */
3168 /* Functions for overload resolution begin here. */
3170 /* Compare two badness vectors A and B and return the result.
3171 0 => A and B are identical
3172 1 => A and B are incomparable
3173 2 => A is better than B
3174 3 => A is worse than B */
3177 compare_badness (struct badness_vector *a, struct badness_vector *b)
3181 short found_pos = 0; /* any positives in c? */
3182 short found_neg = 0; /* any negatives in c? */
3184 /* differing lengths => incomparable */
3185 if (a->length != b->length)
3188 /* Subtract b from a */
3189 for (i = 0; i < a->length; i++)
3191 tmp = compare_ranks (b->rank[i], a->rank[i]);
3201 return 1; /* incomparable */
3203 return 3; /* A > B */
3209 return 2; /* A < B */
3211 return 0; /* A == B */
3215 /* Rank a function by comparing its parameter types (PARMS, length
3216 NPARMS), to the types of an argument list (ARGS, length NARGS).
3217 Return a pointer to a badness vector. This has NARGS + 1
3220 struct badness_vector *
3221 rank_function (struct type **parms, int nparms,
3222 struct value **args, int nargs)
3225 struct badness_vector *bv = XNEW (struct badness_vector);
3226 int min_len = nparms < nargs ? nparms : nargs;
3228 bv->length = nargs + 1; /* add 1 for the length-match rank. */
3229 bv->rank = XNEWVEC (struct rank, nargs + 1);
3231 /* First compare the lengths of the supplied lists.
3232 If there is a mismatch, set it to a high value. */
3234 /* pai/1997-06-03 FIXME: when we have debug info about default
3235 arguments and ellipsis parameter lists, we should consider those
3236 and rank the length-match more finely. */
3238 LENGTH_MATCH (bv) = (nargs != nparms)
3239 ? LENGTH_MISMATCH_BADNESS
3240 : EXACT_MATCH_BADNESS;
3242 /* Now rank all the parameters of the candidate function. */
3243 for (i = 1; i <= min_len; i++)
3244 bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]),
3247 /* If more arguments than parameters, add dummy entries. */
3248 for (i = min_len + 1; i <= nargs; i++)
3249 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
3254 /* Compare the names of two integer types, assuming that any sign
3255 qualifiers have been checked already. We do it this way because
3256 there may be an "int" in the name of one of the types. */
3259 integer_types_same_name_p (const char *first, const char *second)
3261 int first_p, second_p;
3263 /* If both are shorts, return 1; if neither is a short, keep
3265 first_p = (strstr (first, "short") != NULL);
3266 second_p = (strstr (second, "short") != NULL);
3267 if (first_p && second_p)
3269 if (first_p || second_p)
3272 /* Likewise for long. */
3273 first_p = (strstr (first, "long") != NULL);
3274 second_p = (strstr (second, "long") != NULL);
3275 if (first_p && second_p)
3277 if (first_p || second_p)
3280 /* Likewise for char. */
3281 first_p = (strstr (first, "char") != NULL);
3282 second_p = (strstr (second, "char") != NULL);
3283 if (first_p && second_p)
3285 if (first_p || second_p)
3288 /* They must both be ints. */
3292 /* Compares type A to type B returns 1 if the represent the same type
3296 types_equal (struct type *a, struct type *b)
3298 /* Identical type pointers. */
3299 /* However, this still doesn't catch all cases of same type for b
3300 and a. The reason is that builtin types are different from
3301 the same ones constructed from the object. */
3305 /* Resolve typedefs */
3306 if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF)
3307 a = check_typedef (a);
3308 if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF)
3309 b = check_typedef (b);
3311 /* If after resolving typedefs a and b are not of the same type
3312 code then they are not equal. */
3313 if (TYPE_CODE (a) != TYPE_CODE (b))
3316 /* If a and b are both pointers types or both reference types then
3317 they are equal of the same type iff the objects they refer to are
3318 of the same type. */
3319 if (TYPE_CODE (a) == TYPE_CODE_PTR
3320 || TYPE_CODE (a) == TYPE_CODE_REF)
3321 return types_equal (TYPE_TARGET_TYPE (a),
3322 TYPE_TARGET_TYPE (b));
3324 /* Well, damnit, if the names are exactly the same, I'll say they
3325 are exactly the same. This happens when we generate method
3326 stubs. The types won't point to the same address, but they
3327 really are the same. */
3329 if (TYPE_NAME (a) && TYPE_NAME (b)
3330 && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0)
3333 /* Check if identical after resolving typedefs. */
3337 /* Two function types are equal if their argument and return types
3339 if (TYPE_CODE (a) == TYPE_CODE_FUNC)
3343 if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
3346 if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
3349 for (i = 0; i < TYPE_NFIELDS (a); ++i)
3350 if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
3359 /* Deep comparison of types. */
3361 /* An entry in the type-equality bcache. */
3363 typedef struct type_equality_entry
3365 struct type *type1, *type2;
3366 } type_equality_entry_d;
3368 DEF_VEC_O (type_equality_entry_d);
3370 /* A helper function to compare two strings. Returns 1 if they are
3371 the same, 0 otherwise. Handles NULLs properly. */
3374 compare_maybe_null_strings (const char *s, const char *t)
3376 if (s == NULL && t != NULL)
3378 else if (s != NULL && t == NULL)
3380 else if (s == NULL && t== NULL)
3382 return strcmp (s, t) == 0;
3385 /* A helper function for check_types_worklist that checks two types for
3386 "deep" equality. Returns non-zero if the types are considered the
3387 same, zero otherwise. */
3390 check_types_equal (struct type *type1, struct type *type2,
3391 VEC (type_equality_entry_d) **worklist)
3393 type1 = check_typedef (type1);
3394 type2 = check_typedef (type2);
3399 if (TYPE_CODE (type1) != TYPE_CODE (type2)
3400 || TYPE_LENGTH (type1) != TYPE_LENGTH (type2)
3401 || TYPE_UNSIGNED (type1) != TYPE_UNSIGNED (type2)
3402 || TYPE_NOSIGN (type1) != TYPE_NOSIGN (type2)
3403 || TYPE_VARARGS (type1) != TYPE_VARARGS (type2)
3404 || TYPE_VECTOR (type1) != TYPE_VECTOR (type2)
3405 || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2)
3406 || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2)
3407 || TYPE_NFIELDS (type1) != TYPE_NFIELDS (type2))
3410 if (!compare_maybe_null_strings (TYPE_TAG_NAME (type1),
3411 TYPE_TAG_NAME (type2)))
3413 if (!compare_maybe_null_strings (TYPE_NAME (type1), TYPE_NAME (type2)))
3416 if (TYPE_CODE (type1) == TYPE_CODE_RANGE)
3418 if (memcmp (TYPE_RANGE_DATA (type1), TYPE_RANGE_DATA (type2),
3419 sizeof (*TYPE_RANGE_DATA (type1))) != 0)
3426 for (i = 0; i < TYPE_NFIELDS (type1); ++i)
3428 const struct field *field1 = &TYPE_FIELD (type1, i);
3429 const struct field *field2 = &TYPE_FIELD (type2, i);
3430 struct type_equality_entry entry;
3432 if (FIELD_ARTIFICIAL (*field1) != FIELD_ARTIFICIAL (*field2)
3433 || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2)
3434 || FIELD_LOC_KIND (*field1) != FIELD_LOC_KIND (*field2))
3436 if (!compare_maybe_null_strings (FIELD_NAME (*field1),
3437 FIELD_NAME (*field2)))
3439 switch (FIELD_LOC_KIND (*field1))
3441 case FIELD_LOC_KIND_BITPOS:
3442 if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2))
3445 case FIELD_LOC_KIND_ENUMVAL:
3446 if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2))
3449 case FIELD_LOC_KIND_PHYSADDR:
3450 if (FIELD_STATIC_PHYSADDR (*field1)
3451 != FIELD_STATIC_PHYSADDR (*field2))
3454 case FIELD_LOC_KIND_PHYSNAME:
3455 if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1),
3456 FIELD_STATIC_PHYSNAME (*field2)))
3459 case FIELD_LOC_KIND_DWARF_BLOCK:
3461 struct dwarf2_locexpr_baton *block1, *block2;
3463 block1 = FIELD_DWARF_BLOCK (*field1);
3464 block2 = FIELD_DWARF_BLOCK (*field2);
3465 if (block1->per_cu != block2->per_cu
3466 || block1->size != block2->size
3467 || memcmp (block1->data, block2->data, block1->size) != 0)
3472 internal_error (__FILE__, __LINE__, _("Unsupported field kind "
3473 "%d by check_types_equal"),
3474 FIELD_LOC_KIND (*field1));
3477 entry.type1 = FIELD_TYPE (*field1);
3478 entry.type2 = FIELD_TYPE (*field2);
3479 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
3483 if (TYPE_TARGET_TYPE (type1) != NULL)
3485 struct type_equality_entry entry;
3487 if (TYPE_TARGET_TYPE (type2) == NULL)
3490 entry.type1 = TYPE_TARGET_TYPE (type1);
3491 entry.type2 = TYPE_TARGET_TYPE (type2);
3492 VEC_safe_push (type_equality_entry_d, *worklist, &entry);
3494 else if (TYPE_TARGET_TYPE (type2) != NULL)
3500 /* Check types on a worklist for equality. Returns zero if any pair
3501 is not equal, non-zero if they are all considered equal. */
3504 check_types_worklist (VEC (type_equality_entry_d) **worklist,
3505 struct bcache *cache)
3507 while (!VEC_empty (type_equality_entry_d, *worklist))
3509 struct type_equality_entry entry;
3512 entry = *VEC_last (type_equality_entry_d, *worklist);
3513 VEC_pop (type_equality_entry_d, *worklist);
3515 /* If the type pair has already been visited, we know it is
3517 bcache_full (&entry, sizeof (entry), cache, &added);
3521 if (check_types_equal (entry.type1, entry.type2, worklist) == 0)
3528 /* Return non-zero if types TYPE1 and TYPE2 are equal, as determined by a
3529 "deep comparison". Otherwise return zero. */
3532 types_deeply_equal (struct type *type1, struct type *type2)
3534 struct gdb_exception except = exception_none;
3536 struct bcache *cache;
3537 VEC (type_equality_entry_d) *worklist = NULL;
3538 struct type_equality_entry entry;
3540 gdb_assert (type1 != NULL && type2 != NULL);
3542 /* Early exit for the simple case. */
3546 cache = bcache_xmalloc (NULL, NULL);
3548 entry.type1 = type1;
3549 entry.type2 = type2;
3550 VEC_safe_push (type_equality_entry_d, worklist, &entry);
3552 /* check_types_worklist calls several nested helper functions, some
3553 of which can raise a GDB exception, so we just check and rethrow
3554 here. If there is a GDB exception, a comparison is not capable
3555 (or trusted), so exit. */
3558 result = check_types_worklist (&worklist, cache);
3560 CATCH (ex, RETURN_MASK_ALL)
3566 bcache_xfree (cache);
3567 VEC_free (type_equality_entry_d, worklist);
3569 /* Rethrow if there was a problem. */
3570 if (except.reason < 0)
3571 throw_exception (except);
3576 /* Allocated status of type TYPE. Return zero if type TYPE is allocated.
3577 Otherwise return one. */
3580 type_not_allocated (const struct type *type)
3582 struct dynamic_prop *prop = TYPE_ALLOCATED_PROP (type);
3584 return (prop && TYPE_DYN_PROP_KIND (prop) == PROP_CONST
3585 && !TYPE_DYN_PROP_ADDR (prop));
3588 /* Associated status of type TYPE. Return zero if type TYPE is associated.
3589 Otherwise return one. */
3592 type_not_associated (const struct type *type)
3594 struct dynamic_prop *prop = TYPE_ASSOCIATED_PROP (type);
3596 return (prop && TYPE_DYN_PROP_KIND (prop) == PROP_CONST
3597 && !TYPE_DYN_PROP_ADDR (prop));
3600 /* Compare one type (PARM) for compatibility with another (ARG).
3601 * PARM is intended to be the parameter type of a function; and
3602 * ARG is the supplied argument's type. This function tests if
3603 * the latter can be converted to the former.
3604 * VALUE is the argument's value or NULL if none (or called recursively)
3606 * Return 0 if they are identical types;
3607 * Otherwise, return an integer which corresponds to how compatible
3608 * PARM is to ARG. The higher the return value, the worse the match.
3609 * Generally the "bad" conversions are all uniformly assigned a 100. */
3612 rank_one_type (struct type *parm, struct type *arg, struct value *value)
3614 struct rank rank = {0,0};
3616 /* Resolve typedefs */
3617 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
3618 parm = check_typedef (parm);
3619 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
3620 arg = check_typedef (arg);
3624 /* An rvalue argument cannot be bound to a non-const lvalue
3625 reference parameter... */
3626 if (VALUE_LVAL (value) == not_lval
3627 && TYPE_CODE (parm) == TYPE_CODE_REF
3628 && !TYPE_CONST (parm->main_type->target_type))
3629 return INCOMPATIBLE_TYPE_BADNESS;
3631 /* ... and an lvalue argument cannot be bound to an rvalue
3632 reference parameter. [C++ 13.3.3.1.4p3] */
3633 if (VALUE_LVAL (value) != not_lval
3634 && TYPE_CODE (parm) == TYPE_CODE_RVALUE_REF)
3635 return INCOMPATIBLE_TYPE_BADNESS;
3638 if (types_equal (parm, arg))
3639 return EXACT_MATCH_BADNESS;
3641 /* An lvalue reference to a function should get higher priority than an
3642 rvalue reference to a function. */
3644 if (value != NULL && TYPE_CODE (arg) == TYPE_CODE_RVALUE_REF
3645 && TYPE_CODE (TYPE_TARGET_TYPE (arg)) == TYPE_CODE_FUNC)
3647 return (sum_ranks (rank_one_type (parm,
3648 lookup_pointer_type (TYPE_TARGET_TYPE (arg)), NULL),
3649 DIFFERENT_REFERENCE_TYPE_BADNESS));
3652 /* If a conversion to one type of reference is an identity conversion, and a
3653 conversion to the second type of reference is a non-identity conversion,
3654 choose the first type. */
3656 if (value != NULL && TYPE_IS_REFERENCE (parm) && TYPE_IS_REFERENCE (arg)
3657 && TYPE_CODE (parm) != TYPE_CODE (arg))
3659 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm),
3660 TYPE_TARGET_TYPE (arg), NULL), DIFFERENT_REFERENCE_TYPE_BADNESS));
3663 /* An rvalue should be first tried to bind to an rvalue reference, and then to
3664 an lvalue reference. */
3666 if (value != NULL && TYPE_CODE (parm) == TYPE_CODE_REF
3667 && VALUE_LVAL (value) == not_lval)
3669 if (TYPE_IS_REFERENCE (arg))
3670 arg = TYPE_TARGET_TYPE (arg);
3671 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
3672 LVALUE_REFERENCE_TO_RVALUE_BINDING_BADNESS));
3675 /* See through references, since we can almost make non-references
3678 if (TYPE_IS_REFERENCE (arg))
3679 return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
3680 REFERENCE_CONVERSION_BADNESS));
3681 if (TYPE_IS_REFERENCE (parm))
3682 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
3683 REFERENCE_CONVERSION_BADNESS));
3685 /* Debugging only. */
3686 fprintf_filtered (gdb_stderr,
3687 "------ Arg is %s [%d], parm is %s [%d]\n",
3688 TYPE_NAME (arg), TYPE_CODE (arg),
3689 TYPE_NAME (parm), TYPE_CODE (parm));
3691 /* x -> y means arg of type x being supplied for parameter of type y. */
3693 switch (TYPE_CODE (parm))
3696 switch (TYPE_CODE (arg))
3700 /* Allowed pointer conversions are:
3701 (a) pointer to void-pointer conversion. */
3702 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
3703 return VOID_PTR_CONVERSION_BADNESS;
3705 /* (b) pointer to ancestor-pointer conversion. */
3706 rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
3707 TYPE_TARGET_TYPE (arg),
3709 if (rank.subrank >= 0)
3710 return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
3712 return INCOMPATIBLE_TYPE_BADNESS;
3713 case TYPE_CODE_ARRAY:
3714 if (types_equal (TYPE_TARGET_TYPE (parm),
3715 TYPE_TARGET_TYPE (arg)))
3716 return EXACT_MATCH_BADNESS;
3717 return INCOMPATIBLE_TYPE_BADNESS;
3718 case TYPE_CODE_FUNC:
3719 return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
3721 if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
3723 if (value_as_long (value) == 0)
3725 /* Null pointer conversion: allow it to be cast to a pointer.
3726 [4.10.1 of C++ standard draft n3290] */
3727 return NULL_POINTER_CONVERSION_BADNESS;
3731 /* If type checking is disabled, allow the conversion. */
3732 if (!strict_type_checking)
3733 return NS_INTEGER_POINTER_CONVERSION_BADNESS;
3737 case TYPE_CODE_ENUM:
3738 case TYPE_CODE_FLAGS:
3739 case TYPE_CODE_CHAR:
3740 case TYPE_CODE_RANGE:
3741 case TYPE_CODE_BOOL:
3743 return INCOMPATIBLE_TYPE_BADNESS;
3745 case TYPE_CODE_ARRAY:
3746 switch (TYPE_CODE (arg))
3749 case TYPE_CODE_ARRAY:
3750 return rank_one_type (TYPE_TARGET_TYPE (parm),
3751 TYPE_TARGET_TYPE (arg), NULL);
3753 return INCOMPATIBLE_TYPE_BADNESS;
3755 case TYPE_CODE_FUNC:
3756 switch (TYPE_CODE (arg))
3758 case TYPE_CODE_PTR: /* funcptr -> func */
3759 return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
3761 return INCOMPATIBLE_TYPE_BADNESS;
3764 switch (TYPE_CODE (arg))
3767 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3769 /* Deal with signed, unsigned, and plain chars and
3770 signed and unsigned ints. */
3771 if (TYPE_NOSIGN (parm))
3773 /* This case only for character types. */
3774 if (TYPE_NOSIGN (arg))
3775 return EXACT_MATCH_BADNESS; /* plain char -> plain char */
3776 else /* signed/unsigned char -> plain char */
3777 return INTEGER_CONVERSION_BADNESS;
3779 else if (TYPE_UNSIGNED (parm))
3781 if (TYPE_UNSIGNED (arg))
3783 /* unsigned int -> unsigned int, or
3784 unsigned long -> unsigned long */
3785 if (integer_types_same_name_p (TYPE_NAME (parm),
3787 return EXACT_MATCH_BADNESS;
3788 else if (integer_types_same_name_p (TYPE_NAME (arg),
3790 && integer_types_same_name_p (TYPE_NAME (parm),
3792 /* unsigned int -> unsigned long */
3793 return INTEGER_PROMOTION_BADNESS;
3795 /* unsigned long -> unsigned int */
3796 return INTEGER_CONVERSION_BADNESS;
3800 if (integer_types_same_name_p (TYPE_NAME (arg),
3802 && integer_types_same_name_p (TYPE_NAME (parm),
3804 /* signed long -> unsigned int */
3805 return INTEGER_CONVERSION_BADNESS;
3807 /* signed int/long -> unsigned int/long */
3808 return INTEGER_CONVERSION_BADNESS;
3811 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3813 if (integer_types_same_name_p (TYPE_NAME (parm),
3815 return EXACT_MATCH_BADNESS;
3816 else if (integer_types_same_name_p (TYPE_NAME (arg),
3818 && integer_types_same_name_p (TYPE_NAME (parm),
3820 return INTEGER_PROMOTION_BADNESS;
3822 return INTEGER_CONVERSION_BADNESS;
3825 return INTEGER_CONVERSION_BADNESS;
3827 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3828 return INTEGER_PROMOTION_BADNESS;
3830 return INTEGER_CONVERSION_BADNESS;
3831 case TYPE_CODE_ENUM:
3832 case TYPE_CODE_FLAGS:
3833 case TYPE_CODE_CHAR:
3834 case TYPE_CODE_RANGE:
3835 case TYPE_CODE_BOOL:
3836 if (TYPE_DECLARED_CLASS (arg))
3837 return INCOMPATIBLE_TYPE_BADNESS;
3838 return INTEGER_PROMOTION_BADNESS;
3840 return INT_FLOAT_CONVERSION_BADNESS;
3842 return NS_POINTER_CONVERSION_BADNESS;
3844 return INCOMPATIBLE_TYPE_BADNESS;
3847 case TYPE_CODE_ENUM:
3848 switch (TYPE_CODE (arg))
3851 case TYPE_CODE_CHAR:
3852 case TYPE_CODE_RANGE:
3853 case TYPE_CODE_BOOL:
3854 case TYPE_CODE_ENUM:
3855 if (TYPE_DECLARED_CLASS (parm) || TYPE_DECLARED_CLASS (arg))
3856 return INCOMPATIBLE_TYPE_BADNESS;
3857 return INTEGER_CONVERSION_BADNESS;
3859 return INT_FLOAT_CONVERSION_BADNESS;
3861 return INCOMPATIBLE_TYPE_BADNESS;
3864 case TYPE_CODE_CHAR:
3865 switch (TYPE_CODE (arg))
3867 case TYPE_CODE_RANGE:
3868 case TYPE_CODE_BOOL:
3869 case TYPE_CODE_ENUM:
3870 if (TYPE_DECLARED_CLASS (arg))
3871 return INCOMPATIBLE_TYPE_BADNESS;
3872 return INTEGER_CONVERSION_BADNESS;
3874 return INT_FLOAT_CONVERSION_BADNESS;
3876 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
3877 return INTEGER_CONVERSION_BADNESS;
3878 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3879 return INTEGER_PROMOTION_BADNESS;
3880 /* >>> !! else fall through !! <<< */
3881 case TYPE_CODE_CHAR:
3882 /* Deal with signed, unsigned, and plain chars for C++ and
3883 with int cases falling through from previous case. */
3884 if (TYPE_NOSIGN (parm))
3886 if (TYPE_NOSIGN (arg))
3887 return EXACT_MATCH_BADNESS;
3889 return INTEGER_CONVERSION_BADNESS;
3891 else if (TYPE_UNSIGNED (parm))
3893 if (TYPE_UNSIGNED (arg))
3894 return EXACT_MATCH_BADNESS;
3896 return INTEGER_PROMOTION_BADNESS;
3898 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
3899 return EXACT_MATCH_BADNESS;
3901 return INTEGER_CONVERSION_BADNESS;
3903 return INCOMPATIBLE_TYPE_BADNESS;
3906 case TYPE_CODE_RANGE:
3907 switch (TYPE_CODE (arg))
3910 case TYPE_CODE_CHAR:
3911 case TYPE_CODE_RANGE:
3912 case TYPE_CODE_BOOL:
3913 case TYPE_CODE_ENUM:
3914 return INTEGER_CONVERSION_BADNESS;
3916 return INT_FLOAT_CONVERSION_BADNESS;
3918 return INCOMPATIBLE_TYPE_BADNESS;
3921 case TYPE_CODE_BOOL:
3922 switch (TYPE_CODE (arg))
3924 /* n3290 draft, section 4.12.1 (conv.bool):
3926 "A prvalue of arithmetic, unscoped enumeration, pointer, or
3927 pointer to member type can be converted to a prvalue of type
3928 bool. A zero value, null pointer value, or null member pointer
3929 value is converted to false; any other value is converted to
3930 true. A prvalue of type std::nullptr_t can be converted to a
3931 prvalue of type bool; the resulting value is false." */
3933 case TYPE_CODE_CHAR:
3934 case TYPE_CODE_ENUM:
3936 case TYPE_CODE_MEMBERPTR:
3938 return BOOL_CONVERSION_BADNESS;
3939 case TYPE_CODE_RANGE:
3940 return INCOMPATIBLE_TYPE_BADNESS;
3941 case TYPE_CODE_BOOL:
3942 return EXACT_MATCH_BADNESS;
3944 return INCOMPATIBLE_TYPE_BADNESS;
3948 switch (TYPE_CODE (arg))
3951 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
3952 return FLOAT_PROMOTION_BADNESS;
3953 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
3954 return EXACT_MATCH_BADNESS;
3956 return FLOAT_CONVERSION_BADNESS;
3958 case TYPE_CODE_BOOL:
3959 case TYPE_CODE_ENUM:
3960 case TYPE_CODE_RANGE:
3961 case TYPE_CODE_CHAR:
3962 return INT_FLOAT_CONVERSION_BADNESS;
3964 return INCOMPATIBLE_TYPE_BADNESS;
3967 case TYPE_CODE_COMPLEX:
3968 switch (TYPE_CODE (arg))
3969 { /* Strictly not needed for C++, but... */
3971 return FLOAT_PROMOTION_BADNESS;
3972 case TYPE_CODE_COMPLEX:
3973 return EXACT_MATCH_BADNESS;
3975 return INCOMPATIBLE_TYPE_BADNESS;
3978 case TYPE_CODE_STRUCT:
3979 switch (TYPE_CODE (arg))
3981 case TYPE_CODE_STRUCT:
3982 /* Check for derivation */
3983 rank.subrank = distance_to_ancestor (parm, arg, 0);
3984 if (rank.subrank >= 0)
3985 return sum_ranks (BASE_CONVERSION_BADNESS, rank);
3986 /* else fall through */
3988 return INCOMPATIBLE_TYPE_BADNESS;
3991 case TYPE_CODE_UNION:
3992 switch (TYPE_CODE (arg))
3994 case TYPE_CODE_UNION:
3996 return INCOMPATIBLE_TYPE_BADNESS;
3999 case TYPE_CODE_MEMBERPTR:
4000 switch (TYPE_CODE (arg))
4003 return INCOMPATIBLE_TYPE_BADNESS;
4006 case TYPE_CODE_METHOD:
4007 switch (TYPE_CODE (arg))
4011 return INCOMPATIBLE_TYPE_BADNESS;
4015 switch (TYPE_CODE (arg))
4019 return INCOMPATIBLE_TYPE_BADNESS;
4024 switch (TYPE_CODE (arg))
4028 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
4029 TYPE_FIELD_TYPE (arg, 0), NULL);
4031 return INCOMPATIBLE_TYPE_BADNESS;
4034 case TYPE_CODE_VOID:
4036 return INCOMPATIBLE_TYPE_BADNESS;
4037 } /* switch (TYPE_CODE (arg)) */
4040 /* End of functions for overload resolution. */
4042 /* Routines to pretty-print types. */
4045 print_bit_vector (B_TYPE *bits, int nbits)
4049 for (bitno = 0; bitno < nbits; bitno++)
4051 if ((bitno % 8) == 0)
4053 puts_filtered (" ");
4055 if (B_TST (bits, bitno))
4056 printf_filtered (("1"));
4058 printf_filtered (("0"));
4062 /* Note the first arg should be the "this" pointer, we may not want to
4063 include it since we may get into a infinitely recursive
4067 print_args (struct field *args, int nargs, int spaces)
4073 for (i = 0; i < nargs; i++)
4075 printfi_filtered (spaces, "[%d] name '%s'\n", i,
4076 args[i].name != NULL ? args[i].name : "<NULL>");
4077 recursive_dump_type (args[i].type, spaces + 2);
4083 field_is_static (struct field *f)
4085 /* "static" fields are the fields whose location is not relative
4086 to the address of the enclosing struct. It would be nice to
4087 have a dedicated flag that would be set for static fields when
4088 the type is being created. But in practice, checking the field
4089 loc_kind should give us an accurate answer. */
4090 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
4091 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
4095 dump_fn_fieldlists (struct type *type, int spaces)
4101 printfi_filtered (spaces, "fn_fieldlists ");
4102 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
4103 printf_filtered ("\n");
4104 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
4106 f = TYPE_FN_FIELDLIST1 (type, method_idx);
4107 printfi_filtered (spaces + 2, "[%d] name '%s' (",
4109 TYPE_FN_FIELDLIST_NAME (type, method_idx));
4110 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
4112 printf_filtered (_(") length %d\n"),
4113 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
4114 for (overload_idx = 0;
4115 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
4118 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
4120 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
4121 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
4123 printf_filtered (")\n");
4124 printfi_filtered (spaces + 8, "type ");
4125 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
4127 printf_filtered ("\n");
4129 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
4132 printfi_filtered (spaces + 8, "args ");
4133 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
4135 printf_filtered ("\n");
4136 print_args (TYPE_FN_FIELD_ARGS (f, overload_idx),
4137 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
4139 printfi_filtered (spaces + 8, "fcontext ");
4140 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
4142 printf_filtered ("\n");
4144 printfi_filtered (spaces + 8, "is_const %d\n",
4145 TYPE_FN_FIELD_CONST (f, overload_idx));
4146 printfi_filtered (spaces + 8, "is_volatile %d\n",
4147 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
4148 printfi_filtered (spaces + 8, "is_private %d\n",
4149 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
4150 printfi_filtered (spaces + 8, "is_protected %d\n",
4151 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
4152 printfi_filtered (spaces + 8, "is_stub %d\n",
4153 TYPE_FN_FIELD_STUB (f, overload_idx));
4154 printfi_filtered (spaces + 8, "voffset %u\n",
4155 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
4161 print_cplus_stuff (struct type *type, int spaces)
4163 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
4164 printfi_filtered (spaces, "vptr_basetype ");
4165 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
4166 puts_filtered ("\n");
4167 if (TYPE_VPTR_BASETYPE (type) != NULL)
4168 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
4170 printfi_filtered (spaces, "n_baseclasses %d\n",
4171 TYPE_N_BASECLASSES (type));
4172 printfi_filtered (spaces, "nfn_fields %d\n",
4173 TYPE_NFN_FIELDS (type));
4174 if (TYPE_N_BASECLASSES (type) > 0)
4176 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
4177 TYPE_N_BASECLASSES (type));
4178 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
4180 printf_filtered (")");
4182 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
4183 TYPE_N_BASECLASSES (type));
4184 puts_filtered ("\n");
4186 if (TYPE_NFIELDS (type) > 0)
4188 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
4190 printfi_filtered (spaces,
4191 "private_field_bits (%d bits at *",
4192 TYPE_NFIELDS (type));
4193 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
4195 printf_filtered (")");
4196 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
4197 TYPE_NFIELDS (type));
4198 puts_filtered ("\n");
4200 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
4202 printfi_filtered (spaces,
4203 "protected_field_bits (%d bits at *",
4204 TYPE_NFIELDS (type));
4205 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
4207 printf_filtered (")");
4208 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
4209 TYPE_NFIELDS (type));
4210 puts_filtered ("\n");
4213 if (TYPE_NFN_FIELDS (type) > 0)
4215 dump_fn_fieldlists (type, spaces);
4219 /* Print the contents of the TYPE's type_specific union, assuming that
4220 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
4223 print_gnat_stuff (struct type *type, int spaces)
4225 struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
4227 if (descriptive_type == NULL)
4228 printfi_filtered (spaces + 2, "no descriptive type\n");
4231 printfi_filtered (spaces + 2, "descriptive type\n");
4232 recursive_dump_type (descriptive_type, spaces + 4);
4236 static struct obstack dont_print_type_obstack;
4239 recursive_dump_type (struct type *type, int spaces)
4244 obstack_begin (&dont_print_type_obstack, 0);
4246 if (TYPE_NFIELDS (type) > 0
4247 || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0))
4249 struct type **first_dont_print
4250 = (struct type **) obstack_base (&dont_print_type_obstack);
4252 int i = (struct type **)
4253 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
4257 if (type == first_dont_print[i])
4259 printfi_filtered (spaces, "type node ");
4260 gdb_print_host_address (type, gdb_stdout);
4261 printf_filtered (_(" <same as already seen type>\n"));
4266 obstack_ptr_grow (&dont_print_type_obstack, type);
4269 printfi_filtered (spaces, "type node ");
4270 gdb_print_host_address (type, gdb_stdout);
4271 printf_filtered ("\n");
4272 printfi_filtered (spaces, "name '%s' (",
4273 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
4274 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
4275 printf_filtered (")\n");
4276 printfi_filtered (spaces, "tagname '%s' (",
4277 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
4278 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
4279 printf_filtered (")\n");
4280 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
4281 switch (TYPE_CODE (type))
4283 case TYPE_CODE_UNDEF:
4284 printf_filtered ("(TYPE_CODE_UNDEF)");
4287 printf_filtered ("(TYPE_CODE_PTR)");
4289 case TYPE_CODE_ARRAY:
4290 printf_filtered ("(TYPE_CODE_ARRAY)");
4292 case TYPE_CODE_STRUCT:
4293 printf_filtered ("(TYPE_CODE_STRUCT)");
4295 case TYPE_CODE_UNION:
4296 printf_filtered ("(TYPE_CODE_UNION)");
4298 case TYPE_CODE_ENUM:
4299 printf_filtered ("(TYPE_CODE_ENUM)");
4301 case TYPE_CODE_FLAGS:
4302 printf_filtered ("(TYPE_CODE_FLAGS)");
4304 case TYPE_CODE_FUNC:
4305 printf_filtered ("(TYPE_CODE_FUNC)");
4308 printf_filtered ("(TYPE_CODE_INT)");
4311 printf_filtered ("(TYPE_CODE_FLT)");
4313 case TYPE_CODE_VOID:
4314 printf_filtered ("(TYPE_CODE_VOID)");
4317 printf_filtered ("(TYPE_CODE_SET)");
4319 case TYPE_CODE_RANGE:
4320 printf_filtered ("(TYPE_CODE_RANGE)");
4322 case TYPE_CODE_STRING:
4323 printf_filtered ("(TYPE_CODE_STRING)");
4325 case TYPE_CODE_ERROR:
4326 printf_filtered ("(TYPE_CODE_ERROR)");
4328 case TYPE_CODE_MEMBERPTR:
4329 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
4331 case TYPE_CODE_METHODPTR:
4332 printf_filtered ("(TYPE_CODE_METHODPTR)");
4334 case TYPE_CODE_METHOD:
4335 printf_filtered ("(TYPE_CODE_METHOD)");
4338 printf_filtered ("(TYPE_CODE_REF)");
4340 case TYPE_CODE_CHAR:
4341 printf_filtered ("(TYPE_CODE_CHAR)");
4343 case TYPE_CODE_BOOL:
4344 printf_filtered ("(TYPE_CODE_BOOL)");
4346 case TYPE_CODE_COMPLEX:
4347 printf_filtered ("(TYPE_CODE_COMPLEX)");
4349 case TYPE_CODE_TYPEDEF:
4350 printf_filtered ("(TYPE_CODE_TYPEDEF)");
4352 case TYPE_CODE_NAMESPACE:
4353 printf_filtered ("(TYPE_CODE_NAMESPACE)");
4356 printf_filtered ("(UNKNOWN TYPE CODE)");
4359 puts_filtered ("\n");
4360 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
4361 if (TYPE_OBJFILE_OWNED (type))
4363 printfi_filtered (spaces, "objfile ");
4364 gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout);
4368 printfi_filtered (spaces, "gdbarch ");
4369 gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout);
4371 printf_filtered ("\n");
4372 printfi_filtered (spaces, "target_type ");
4373 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
4374 printf_filtered ("\n");
4375 if (TYPE_TARGET_TYPE (type) != NULL)
4377 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
4379 printfi_filtered (spaces, "pointer_type ");
4380 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
4381 printf_filtered ("\n");
4382 printfi_filtered (spaces, "reference_type ");
4383 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
4384 printf_filtered ("\n");
4385 printfi_filtered (spaces, "type_chain ");
4386 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
4387 printf_filtered ("\n");
4388 printfi_filtered (spaces, "instance_flags 0x%x",
4389 TYPE_INSTANCE_FLAGS (type));
4390 if (TYPE_CONST (type))
4392 puts_filtered (" TYPE_CONST");
4394 if (TYPE_VOLATILE (type))
4396 puts_filtered (" TYPE_VOLATILE");
4398 if (TYPE_CODE_SPACE (type))
4400 puts_filtered (" TYPE_CODE_SPACE");
4402 if (TYPE_DATA_SPACE (type))
4404 puts_filtered (" TYPE_DATA_SPACE");
4406 if (TYPE_ADDRESS_CLASS_1 (type))
4408 puts_filtered (" TYPE_ADDRESS_CLASS_1");
4410 if (TYPE_ADDRESS_CLASS_2 (type))
4412 puts_filtered (" TYPE_ADDRESS_CLASS_2");
4414 if (TYPE_RESTRICT (type))
4416 puts_filtered (" TYPE_RESTRICT");
4418 if (TYPE_ATOMIC (type))
4420 puts_filtered (" TYPE_ATOMIC");
4422 puts_filtered ("\n");
4424 printfi_filtered (spaces, "flags");
4425 if (TYPE_UNSIGNED (type))
4427 puts_filtered (" TYPE_UNSIGNED");
4429 if (TYPE_NOSIGN (type))
4431 puts_filtered (" TYPE_NOSIGN");
4433 if (TYPE_STUB (type))
4435 puts_filtered (" TYPE_STUB");
4437 if (TYPE_TARGET_STUB (type))
4439 puts_filtered (" TYPE_TARGET_STUB");
4441 if (TYPE_STATIC (type))
4443 puts_filtered (" TYPE_STATIC");
4445 if (TYPE_PROTOTYPED (type))
4447 puts_filtered (" TYPE_PROTOTYPED");
4449 if (TYPE_INCOMPLETE (type))
4451 puts_filtered (" TYPE_INCOMPLETE");
4453 if (TYPE_VARARGS (type))
4455 puts_filtered (" TYPE_VARARGS");
4457 /* This is used for things like AltiVec registers on ppc. Gcc emits
4458 an attribute for the array type, which tells whether or not we
4459 have a vector, instead of a regular array. */
4460 if (TYPE_VECTOR (type))
4462 puts_filtered (" TYPE_VECTOR");
4464 if (TYPE_FIXED_INSTANCE (type))
4466 puts_filtered (" TYPE_FIXED_INSTANCE");
4468 if (TYPE_STUB_SUPPORTED (type))
4470 puts_filtered (" TYPE_STUB_SUPPORTED");
4472 if (TYPE_NOTTEXT (type))
4474 puts_filtered (" TYPE_NOTTEXT");
4476 puts_filtered ("\n");
4477 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
4478 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
4479 puts_filtered ("\n");
4480 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
4482 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
4483 printfi_filtered (spaces + 2,
4484 "[%d] enumval %s type ",
4485 idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
4487 printfi_filtered (spaces + 2,
4488 "[%d] bitpos %s bitsize %d type ",
4489 idx, plongest (TYPE_FIELD_BITPOS (type, idx)),
4490 TYPE_FIELD_BITSIZE (type, idx));
4491 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
4492 printf_filtered (" name '%s' (",
4493 TYPE_FIELD_NAME (type, idx) != NULL
4494 ? TYPE_FIELD_NAME (type, idx)
4496 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
4497 printf_filtered (")\n");
4498 if (TYPE_FIELD_TYPE (type, idx) != NULL)
4500 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
4503 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4505 printfi_filtered (spaces, "low %s%s high %s%s\n",
4506 plongest (TYPE_LOW_BOUND (type)),
4507 TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
4508 plongest (TYPE_HIGH_BOUND (type)),
4509 TYPE_HIGH_BOUND_UNDEFINED (type)
4510 ? " (undefined)" : "");
4513 switch (TYPE_SPECIFIC_FIELD (type))
4515 case TYPE_SPECIFIC_CPLUS_STUFF:
4516 printfi_filtered (spaces, "cplus_stuff ");
4517 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
4519 puts_filtered ("\n");
4520 print_cplus_stuff (type, spaces);
4523 case TYPE_SPECIFIC_GNAT_STUFF:
4524 printfi_filtered (spaces, "gnat_stuff ");
4525 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type), gdb_stdout);
4526 puts_filtered ("\n");
4527 print_gnat_stuff (type, spaces);
4530 case TYPE_SPECIFIC_FLOATFORMAT:
4531 printfi_filtered (spaces, "floatformat ");
4532 if (TYPE_FLOATFORMAT (type) == NULL)
4533 puts_filtered ("(null)");
4536 puts_filtered ("{ ");
4537 if (TYPE_FLOATFORMAT (type)[0] == NULL
4538 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
4539 puts_filtered ("(null)");
4541 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
4543 puts_filtered (", ");
4544 if (TYPE_FLOATFORMAT (type)[1] == NULL
4545 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
4546 puts_filtered ("(null)");
4548 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
4550 puts_filtered (" }");
4552 puts_filtered ("\n");
4555 case TYPE_SPECIFIC_FUNC:
4556 printfi_filtered (spaces, "calling_convention %d\n",
4557 TYPE_CALLING_CONVENTION (type));
4558 /* tail_call_list is not printed. */
4561 case TYPE_SPECIFIC_SELF_TYPE:
4562 printfi_filtered (spaces, "self_type ");
4563 gdb_print_host_address (TYPE_SELF_TYPE (type), gdb_stdout);
4564 puts_filtered ("\n");
4569 obstack_free (&dont_print_type_obstack, NULL);
4572 /* Trivial helpers for the libiberty hash table, for mapping one
4577 struct type *old, *newobj;
4581 type_pair_hash (const void *item)
4583 const struct type_pair *pair = (const struct type_pair *) item;
4585 return htab_hash_pointer (pair->old);
4589 type_pair_eq (const void *item_lhs, const void *item_rhs)
4591 const struct type_pair *lhs = (const struct type_pair *) item_lhs;
4592 const struct type_pair *rhs = (const struct type_pair *) item_rhs;
4594 return lhs->old == rhs->old;
4597 /* Allocate the hash table used by copy_type_recursive to walk
4598 types without duplicates. We use OBJFILE's obstack, because
4599 OBJFILE is about to be deleted. */
4602 create_copied_types_hash (struct objfile *objfile)
4604 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
4605 NULL, &objfile->objfile_obstack,
4606 hashtab_obstack_allocate,
4607 dummy_obstack_deallocate);
4610 /* Recursively copy (deep copy) a dynamic attribute list of a type. */
4612 static struct dynamic_prop_list *
4613 copy_dynamic_prop_list (struct obstack *objfile_obstack,
4614 struct dynamic_prop_list *list)
4616 struct dynamic_prop_list *copy = list;
4617 struct dynamic_prop_list **node_ptr = ©
4619 while (*node_ptr != NULL)
4621 struct dynamic_prop_list *node_copy;
4623 node_copy = ((struct dynamic_prop_list *)
4624 obstack_copy (objfile_obstack, *node_ptr,
4625 sizeof (struct dynamic_prop_list)));
4626 node_copy->prop = (*node_ptr)->prop;
4627 *node_ptr = node_copy;
4629 node_ptr = &node_copy->next;
4635 /* Recursively copy (deep copy) TYPE, if it is associated with
4636 OBJFILE. Return a new type owned by the gdbarch associated with the type, a
4637 saved type if we have already visited TYPE (using COPIED_TYPES), or TYPE if
4638 it is not associated with OBJFILE. */
4641 copy_type_recursive (struct objfile *objfile,
4643 htab_t copied_types)
4645 struct type_pair *stored, pair;
4647 struct type *new_type;
4649 if (! TYPE_OBJFILE_OWNED (type))
4652 /* This type shouldn't be pointing to any types in other objfiles;
4653 if it did, the type might disappear unexpectedly. */
4654 gdb_assert (TYPE_OBJFILE (type) == objfile);
4657 slot = htab_find_slot (copied_types, &pair, INSERT);
4659 return ((struct type_pair *) *slot)->newobj;
4661 new_type = alloc_type_arch (get_type_arch (type));
4663 /* We must add the new type to the hash table immediately, in case
4664 we encounter this type again during a recursive call below. */
4665 stored = XOBNEW (&objfile->objfile_obstack, struct type_pair);
4667 stored->newobj = new_type;
4670 /* Copy the common fields of types. For the main type, we simply
4671 copy the entire thing and then update specific fields as needed. */
4672 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
4673 TYPE_OBJFILE_OWNED (new_type) = 0;
4674 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
4676 if (TYPE_NAME (type))
4677 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
4678 if (TYPE_TAG_NAME (type))
4679 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
4681 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4682 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4684 /* Copy the fields. */
4685 if (TYPE_NFIELDS (type))
4689 nfields = TYPE_NFIELDS (type);
4690 TYPE_FIELDS (new_type) = XCNEWVEC (struct field, nfields);
4691 for (i = 0; i < nfields; i++)
4693 TYPE_FIELD_ARTIFICIAL (new_type, i) =
4694 TYPE_FIELD_ARTIFICIAL (type, i);
4695 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
4696 if (TYPE_FIELD_TYPE (type, i))
4697 TYPE_FIELD_TYPE (new_type, i)
4698 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
4700 if (TYPE_FIELD_NAME (type, i))
4701 TYPE_FIELD_NAME (new_type, i) =
4702 xstrdup (TYPE_FIELD_NAME (type, i));
4703 switch (TYPE_FIELD_LOC_KIND (type, i))
4705 case FIELD_LOC_KIND_BITPOS:
4706 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
4707 TYPE_FIELD_BITPOS (type, i));
4709 case FIELD_LOC_KIND_ENUMVAL:
4710 SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i),
4711 TYPE_FIELD_ENUMVAL (type, i));
4713 case FIELD_LOC_KIND_PHYSADDR:
4714 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
4715 TYPE_FIELD_STATIC_PHYSADDR (type, i));
4717 case FIELD_LOC_KIND_PHYSNAME:
4718 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
4719 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
4723 internal_error (__FILE__, __LINE__,
4724 _("Unexpected type field location kind: %d"),
4725 TYPE_FIELD_LOC_KIND (type, i));
4730 /* For range types, copy the bounds information. */
4731 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
4733 TYPE_RANGE_DATA (new_type) = XNEW (struct range_bounds);
4734 *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
4737 if (TYPE_DYN_PROP_LIST (type) != NULL)
4738 TYPE_DYN_PROP_LIST (new_type)
4739 = copy_dynamic_prop_list (&objfile->objfile_obstack,
4740 TYPE_DYN_PROP_LIST (type));
4743 /* Copy pointers to other types. */
4744 if (TYPE_TARGET_TYPE (type))
4745 TYPE_TARGET_TYPE (new_type) =
4746 copy_type_recursive (objfile,
4747 TYPE_TARGET_TYPE (type),
4750 /* Maybe copy the type_specific bits.
4752 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
4753 base classes and methods. There's no fundamental reason why we
4754 can't, but at the moment it is not needed. */
4756 switch (TYPE_SPECIFIC_FIELD (type))
4758 case TYPE_SPECIFIC_NONE:
4760 case TYPE_SPECIFIC_FUNC:
4761 INIT_FUNC_SPECIFIC (new_type);
4762 TYPE_CALLING_CONVENTION (new_type) = TYPE_CALLING_CONVENTION (type);
4763 TYPE_NO_RETURN (new_type) = TYPE_NO_RETURN (type);
4764 TYPE_TAIL_CALL_LIST (new_type) = NULL;
4766 case TYPE_SPECIFIC_FLOATFORMAT:
4767 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
4769 case TYPE_SPECIFIC_CPLUS_STUFF:
4770 INIT_CPLUS_SPECIFIC (new_type);
4772 case TYPE_SPECIFIC_GNAT_STUFF:
4773 INIT_GNAT_SPECIFIC (new_type);
4775 case TYPE_SPECIFIC_SELF_TYPE:
4776 set_type_self_type (new_type,
4777 copy_type_recursive (objfile, TYPE_SELF_TYPE (type),
4781 gdb_assert_not_reached ("bad type_specific_kind");
4787 /* Make a copy of the given TYPE, except that the pointer & reference
4788 types are not preserved.
4790 This function assumes that the given type has an associated objfile.
4791 This objfile is used to allocate the new type. */
4794 copy_type (const struct type *type)
4796 struct type *new_type;
4798 gdb_assert (TYPE_OBJFILE_OWNED (type));
4800 new_type = alloc_type_copy (type);
4801 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
4802 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
4803 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
4804 sizeof (struct main_type));
4805 if (TYPE_DYN_PROP_LIST (type) != NULL)
4806 TYPE_DYN_PROP_LIST (new_type)
4807 = copy_dynamic_prop_list (&TYPE_OBJFILE (type) -> objfile_obstack,
4808 TYPE_DYN_PROP_LIST (type));
4813 /* Helper functions to initialize architecture-specific types. */
4815 /* Allocate a type structure associated with GDBARCH and set its
4816 CODE, LENGTH, and NAME fields. */
4819 arch_type (struct gdbarch *gdbarch,
4820 enum type_code code, int length, const char *name)
4824 type = alloc_type_arch (gdbarch);
4825 set_type_code (type, code);
4826 TYPE_LENGTH (type) = length;
4829 TYPE_NAME (type) = gdbarch_obstack_strdup (gdbarch, name);
4834 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
4835 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4836 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4839 arch_integer_type (struct gdbarch *gdbarch,
4840 int bit, int unsigned_p, const char *name)
4844 t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
4846 TYPE_UNSIGNED (t) = 1;
4851 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
4852 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4853 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4856 arch_character_type (struct gdbarch *gdbarch,
4857 int bit, int unsigned_p, const char *name)
4861 t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
4863 TYPE_UNSIGNED (t) = 1;
4868 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
4869 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4870 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4873 arch_boolean_type (struct gdbarch *gdbarch,
4874 int bit, int unsigned_p, const char *name)
4878 t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
4880 TYPE_UNSIGNED (t) = 1;
4885 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
4886 BIT is the type size in bits; if BIT equals -1, the size is
4887 determined by the floatformat. NAME is the type name. Set the
4888 TYPE_FLOATFORMAT from FLOATFORMATS. */
4891 arch_float_type (struct gdbarch *gdbarch,
4892 int bit, const char *name,
4893 const struct floatformat **floatformats)
4897 bit = verify_floatformat (bit, floatformats);
4898 t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
4899 TYPE_FLOATFORMAT (t) = floatformats;
4904 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with GDBARCH.
4905 BIT is the type size in bits. NAME is the type name. */
4908 arch_decfloat_type (struct gdbarch *gdbarch, int bit, const char *name)
4912 t = arch_type (gdbarch, TYPE_CODE_DECFLOAT, bit / TARGET_CHAR_BIT, name);
4916 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
4917 NAME is the type name. TARGET_TYPE is the component float type. */
4920 arch_complex_type (struct gdbarch *gdbarch,
4921 const char *name, struct type *target_type)
4925 t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
4926 2 * TYPE_LENGTH (target_type), name);
4927 TYPE_TARGET_TYPE (t) = target_type;
4931 /* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH.
4932 BIT is the pointer type size in bits. NAME is the type name.
4933 TARGET_TYPE is the pointer target type. Always sets the pointer type's
4934 TYPE_UNSIGNED flag. */
4937 arch_pointer_type (struct gdbarch *gdbarch,
4938 int bit, const char *name, struct type *target_type)
4942 t = arch_type (gdbarch, TYPE_CODE_PTR, bit / TARGET_CHAR_BIT, name);
4943 TYPE_TARGET_TYPE (t) = target_type;
4944 TYPE_UNSIGNED (t) = 1;
4948 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
4949 NAME is the type name. LENGTH is the size of the flag word in bytes. */
4952 arch_flags_type (struct gdbarch *gdbarch, const char *name, int length)
4954 int max_nfields = length * TARGET_CHAR_BIT;
4957 type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name);
4958 TYPE_UNSIGNED (type) = 1;
4959 TYPE_NFIELDS (type) = 0;
4960 /* Pre-allocate enough space assuming every field is one bit. */
4962 = (struct field *) TYPE_ZALLOC (type, max_nfields * sizeof (struct field));
4967 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
4968 position BITPOS is called NAME. Pass NAME as "" for fields that
4969 should not be printed. */
4972 append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
4973 struct type *field_type, const char *name)
4975 int type_bitsize = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
4976 int field_nr = TYPE_NFIELDS (type);
4978 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
4979 gdb_assert (TYPE_NFIELDS (type) + 1 <= type_bitsize);
4980 gdb_assert (start_bitpos >= 0 && start_bitpos < type_bitsize);
4981 gdb_assert (nr_bits >= 1 && nr_bits <= type_bitsize);
4982 gdb_assert (name != NULL);
4984 TYPE_FIELD_NAME (type, field_nr) = xstrdup (name);
4985 TYPE_FIELD_TYPE (type, field_nr) = field_type;
4986 SET_FIELD_BITPOS (TYPE_FIELD (type, field_nr), start_bitpos);
4987 TYPE_FIELD_BITSIZE (type, field_nr) = nr_bits;
4988 ++TYPE_NFIELDS (type);
4991 /* Special version of append_flags_type_field to add a flag field.
4992 Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
4993 position BITPOS is called NAME. */
4996 append_flags_type_flag (struct type *type, int bitpos, const char *name)
4998 struct gdbarch *gdbarch = get_type_arch (type);
5000 append_flags_type_field (type, bitpos, 1,
5001 builtin_type (gdbarch)->builtin_bool,
5005 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
5006 specified by CODE) associated with GDBARCH. NAME is the type name. */
5009 arch_composite_type (struct gdbarch *gdbarch, const char *name,
5010 enum type_code code)
5014 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
5015 t = arch_type (gdbarch, code, 0, NULL);
5016 TYPE_TAG_NAME (t) = name;
5017 INIT_CPLUS_SPECIFIC (t);
5021 /* Add new field with name NAME and type FIELD to composite type T.
5022 Do not set the field's position or adjust the type's length;
5023 the caller should do so. Return the new field. */
5026 append_composite_type_field_raw (struct type *t, const char *name,
5031 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
5032 TYPE_FIELDS (t) = XRESIZEVEC (struct field, TYPE_FIELDS (t),
5034 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
5035 memset (f, 0, sizeof f[0]);
5036 FIELD_TYPE (f[0]) = field;
5037 FIELD_NAME (f[0]) = name;
5041 /* Add new field with name NAME and type FIELD to composite type T.
5042 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
5045 append_composite_type_field_aligned (struct type *t, const char *name,
5046 struct type *field, int alignment)
5048 struct field *f = append_composite_type_field_raw (t, name, field);
5050 if (TYPE_CODE (t) == TYPE_CODE_UNION)
5052 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
5053 TYPE_LENGTH (t) = TYPE_LENGTH (field);
5055 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
5057 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
5058 if (TYPE_NFIELDS (t) > 1)
5060 SET_FIELD_BITPOS (f[0],
5061 (FIELD_BITPOS (f[-1])
5062 + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
5063 * TARGET_CHAR_BIT)));
5069 alignment *= TARGET_CHAR_BIT;
5070 left = FIELD_BITPOS (f[0]) % alignment;
5074 SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left));
5075 TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
5082 /* Add new field with name NAME and type FIELD to composite type T. */
5085 append_composite_type_field (struct type *t, const char *name,
5088 append_composite_type_field_aligned (t, name, field, 0);
5091 static struct gdbarch_data *gdbtypes_data;
5093 const struct builtin_type *
5094 builtin_type (struct gdbarch *gdbarch)
5096 return (const struct builtin_type *) gdbarch_data (gdbarch, gdbtypes_data);
5100 gdbtypes_post_init (struct gdbarch *gdbarch)
5102 struct builtin_type *builtin_type
5103 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
5106 builtin_type->builtin_void
5107 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
5108 builtin_type->builtin_char
5109 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
5110 !gdbarch_char_signed (gdbarch), "char");
5111 TYPE_NOSIGN (builtin_type->builtin_char) = 1;
5112 builtin_type->builtin_signed_char
5113 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
5115 builtin_type->builtin_unsigned_char
5116 = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
5117 1, "unsigned char");
5118 builtin_type->builtin_short
5119 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
5121 builtin_type->builtin_unsigned_short
5122 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
5123 1, "unsigned short");
5124 builtin_type->builtin_int
5125 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
5127 builtin_type->builtin_unsigned_int
5128 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
5130 builtin_type->builtin_long
5131 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
5133 builtin_type->builtin_unsigned_long
5134 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
5135 1, "unsigned long");
5136 builtin_type->builtin_long_long
5137 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
5139 builtin_type->builtin_unsigned_long_long
5140 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
5141 1, "unsigned long long");
5142 builtin_type->builtin_float
5143 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
5144 "float", gdbarch_float_format (gdbarch));
5145 builtin_type->builtin_double
5146 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
5147 "double", gdbarch_double_format (gdbarch));
5148 builtin_type->builtin_long_double
5149 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
5150 "long double", gdbarch_long_double_format (gdbarch));
5151 builtin_type->builtin_complex
5152 = arch_complex_type (gdbarch, "complex",
5153 builtin_type->builtin_float);
5154 builtin_type->builtin_double_complex
5155 = arch_complex_type (gdbarch, "double complex",
5156 builtin_type->builtin_double);
5157 builtin_type->builtin_string
5158 = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string");
5159 builtin_type->builtin_bool
5160 = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool");
5162 /* The following three are about decimal floating point types, which
5163 are 32-bits, 64-bits and 128-bits respectively. */
5164 builtin_type->builtin_decfloat
5165 = arch_decfloat_type (gdbarch, 32, "_Decimal32");
5166 builtin_type->builtin_decdouble
5167 = arch_decfloat_type (gdbarch, 64, "_Decimal64");
5168 builtin_type->builtin_declong
5169 = arch_decfloat_type (gdbarch, 128, "_Decimal128");
5171 /* "True" character types. */
5172 builtin_type->builtin_true_char
5173 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character");
5174 builtin_type->builtin_true_unsigned_char
5175 = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character");
5177 /* Fixed-size integer types. */
5178 builtin_type->builtin_int0
5179 = arch_integer_type (gdbarch, 0, 0, "int0_t");
5180 builtin_type->builtin_int8
5181 = arch_integer_type (gdbarch, 8, 0, "int8_t");
5182 builtin_type->builtin_uint8
5183 = arch_integer_type (gdbarch, 8, 1, "uint8_t");
5184 builtin_type->builtin_int16
5185 = arch_integer_type (gdbarch, 16, 0, "int16_t");
5186 builtin_type->builtin_uint16
5187 = arch_integer_type (gdbarch, 16, 1, "uint16_t");
5188 builtin_type->builtin_int32
5189 = arch_integer_type (gdbarch, 32, 0, "int32_t");
5190 builtin_type->builtin_uint32
5191 = arch_integer_type (gdbarch, 32, 1, "uint32_t");
5192 builtin_type->builtin_int64
5193 = arch_integer_type (gdbarch, 64, 0, "int64_t");
5194 builtin_type->builtin_uint64
5195 = arch_integer_type (gdbarch, 64, 1, "uint64_t");
5196 builtin_type->builtin_int128
5197 = arch_integer_type (gdbarch, 128, 0, "int128_t");
5198 builtin_type->builtin_uint128
5199 = arch_integer_type (gdbarch, 128, 1, "uint128_t");
5200 TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |=
5201 TYPE_INSTANCE_FLAG_NOTTEXT;
5202 TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |=
5203 TYPE_INSTANCE_FLAG_NOTTEXT;
5205 /* Wide character types. */
5206 builtin_type->builtin_char16
5207 = arch_integer_type (gdbarch, 16, 1, "char16_t");
5208 builtin_type->builtin_char32
5209 = arch_integer_type (gdbarch, 32, 1, "char32_t");
5211 /* Default data/code pointer types. */
5212 builtin_type->builtin_data_ptr
5213 = lookup_pointer_type (builtin_type->builtin_void);
5214 builtin_type->builtin_func_ptr
5215 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
5216 builtin_type->builtin_func_func
5217 = lookup_function_type (builtin_type->builtin_func_ptr);
5219 /* This type represents a GDB internal function. */
5220 builtin_type->internal_fn
5221 = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0,
5222 "<internal function>");
5224 /* This type represents an xmethod. */
5225 builtin_type->xmethod
5226 = arch_type (gdbarch, TYPE_CODE_XMETHOD, 0, "<xmethod>");
5228 return builtin_type;
5231 /* This set of objfile-based types is intended to be used by symbol
5232 readers as basic types. */
5234 static const struct objfile_data *objfile_type_data;
5236 const struct objfile_type *
5237 objfile_type (struct objfile *objfile)
5239 struct gdbarch *gdbarch;
5240 struct objfile_type *objfile_type
5241 = (struct objfile_type *) objfile_data (objfile, objfile_type_data);
5244 return objfile_type;
5246 objfile_type = OBSTACK_CALLOC (&objfile->objfile_obstack,
5247 1, struct objfile_type);
5249 /* Use the objfile architecture to determine basic type properties. */
5250 gdbarch = get_objfile_arch (objfile);
5253 objfile_type->builtin_void
5254 = init_type (objfile, TYPE_CODE_VOID, 1, "void");
5255 objfile_type->builtin_char
5256 = init_integer_type (objfile, TARGET_CHAR_BIT,
5257 !gdbarch_char_signed (gdbarch), "char");
5258 TYPE_NOSIGN (objfile_type->builtin_char) = 1;
5259 objfile_type->builtin_signed_char
5260 = init_integer_type (objfile, TARGET_CHAR_BIT,
5262 objfile_type->builtin_unsigned_char
5263 = init_integer_type (objfile, TARGET_CHAR_BIT,
5264 1, "unsigned char");
5265 objfile_type->builtin_short
5266 = init_integer_type (objfile, gdbarch_short_bit (gdbarch),
5268 objfile_type->builtin_unsigned_short
5269 = init_integer_type (objfile, gdbarch_short_bit (gdbarch),
5270 1, "unsigned short");
5271 objfile_type->builtin_int
5272 = init_integer_type (objfile, gdbarch_int_bit (gdbarch),
5274 objfile_type->builtin_unsigned_int
5275 = init_integer_type (objfile, gdbarch_int_bit (gdbarch),
5277 objfile_type->builtin_long
5278 = init_integer_type (objfile, gdbarch_long_bit (gdbarch),
5280 objfile_type->builtin_unsigned_long
5281 = init_integer_type (objfile, gdbarch_long_bit (gdbarch),
5282 1, "unsigned long");
5283 objfile_type->builtin_long_long
5284 = init_integer_type (objfile, gdbarch_long_long_bit (gdbarch),
5286 objfile_type->builtin_unsigned_long_long
5287 = init_integer_type (objfile, gdbarch_long_long_bit (gdbarch),
5288 1, "unsigned long long");
5289 objfile_type->builtin_float
5290 = init_float_type (objfile, gdbarch_float_bit (gdbarch),
5291 "float", gdbarch_float_format (gdbarch));
5292 objfile_type->builtin_double
5293 = init_float_type (objfile, gdbarch_double_bit (gdbarch),
5294 "double", gdbarch_double_format (gdbarch));
5295 objfile_type->builtin_long_double
5296 = init_float_type (objfile, gdbarch_long_double_bit (gdbarch),
5297 "long double", gdbarch_long_double_format (gdbarch));
5299 /* This type represents a type that was unrecognized in symbol read-in. */
5300 objfile_type->builtin_error
5301 = init_type (objfile, TYPE_CODE_ERROR, 0, "<unknown type>");
5303 /* The following set of types is used for symbols with no
5304 debug information. */
5305 objfile_type->nodebug_text_symbol
5306 = init_type (objfile, TYPE_CODE_FUNC, 1,
5307 "<text variable, no debug info>");
5308 TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
5309 = objfile_type->builtin_int;
5310 objfile_type->nodebug_text_gnu_ifunc_symbol
5311 = init_type (objfile, TYPE_CODE_FUNC, 1,
5312 "<text gnu-indirect-function variable, no debug info>");
5313 TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
5314 = objfile_type->nodebug_text_symbol;
5315 TYPE_GNU_IFUNC (objfile_type->nodebug_text_gnu_ifunc_symbol) = 1;
5316 objfile_type->nodebug_got_plt_symbol
5317 = init_pointer_type (objfile, gdbarch_addr_bit (gdbarch),
5318 "<text from jump slot in .got.plt, no debug info>",
5319 objfile_type->nodebug_text_symbol);
5320 objfile_type->nodebug_data_symbol
5321 = init_integer_type (objfile, gdbarch_int_bit (gdbarch), 0,
5322 "<data variable, no debug info>");
5323 objfile_type->nodebug_unknown_symbol
5324 = init_integer_type (objfile, TARGET_CHAR_BIT, 0,
5325 "<variable (not text or data), no debug info>");
5326 objfile_type->nodebug_tls_symbol
5327 = init_integer_type (objfile, gdbarch_int_bit (gdbarch), 0,
5328 "<thread local variable, no debug info>");
5330 /* NOTE: on some targets, addresses and pointers are not necessarily
5334 - gdb's `struct type' always describes the target's
5336 - gdb's `struct value' objects should always hold values in
5338 - gdb's CORE_ADDR values are addresses in the unified virtual
5339 address space that the assembler and linker work with. Thus,
5340 since target_read_memory takes a CORE_ADDR as an argument, it
5341 can access any memory on the target, even if the processor has
5342 separate code and data address spaces.
5344 In this context, objfile_type->builtin_core_addr is a bit odd:
5345 it's a target type for a value the target will never see. It's
5346 only used to hold the values of (typeless) linker symbols, which
5347 are indeed in the unified virtual address space. */
5349 objfile_type->builtin_core_addr
5350 = init_integer_type (objfile, gdbarch_addr_bit (gdbarch), 1,
5353 set_objfile_data (objfile, objfile_type_data, objfile_type);
5354 return objfile_type;
5357 extern initialize_file_ftype _initialize_gdbtypes;
5360 _initialize_gdbtypes (void)
5362 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
5363 objfile_type_data = register_objfile_data ();
5365 add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug,
5366 _("Set debugging of C++ overloading."),
5367 _("Show debugging of C++ overloading."),
5368 _("When enabled, ranking of the "
5369 "functions is displayed."),
5371 show_overload_debug,
5372 &setdebuglist, &showdebuglist);
5374 /* Add user knob for controlling resolution of opaque types. */
5375 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
5376 &opaque_type_resolution,
5377 _("Set resolution of opaque struct/class/union"
5378 " types (if set before loading symbols)."),
5379 _("Show resolution of opaque struct/class/union"
5380 " types (if set before loading symbols)."),
5382 show_opaque_type_resolution,
5383 &setlist, &showlist);
5385 /* Add an option to permit non-strict type checking. */
5386 add_setshow_boolean_cmd ("type", class_support,
5387 &strict_type_checking,
5388 _("Set strict type checking."),
5389 _("Show strict type checking."),
5391 show_strict_type_checking,
5392 &setchecklist, &showchecklist);