1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2020 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 "dwarf2/loc.h"
41 #include "floatformat.h"
44 /* Initialize BADNESS constants. */
46 const struct rank LENGTH_MISMATCH_BADNESS
= {100,0};
48 const struct rank TOO_FEW_PARAMS_BADNESS
= {100,0};
49 const struct rank INCOMPATIBLE_TYPE_BADNESS
= {100,0};
51 const struct rank EXACT_MATCH_BADNESS
= {0,0};
53 const struct rank INTEGER_PROMOTION_BADNESS
= {1,0};
54 const struct rank FLOAT_PROMOTION_BADNESS
= {1,0};
55 const struct rank BASE_PTR_CONVERSION_BADNESS
= {1,0};
56 const struct rank CV_CONVERSION_BADNESS
= {1, 0};
57 const struct rank INTEGER_CONVERSION_BADNESS
= {2,0};
58 const struct rank FLOAT_CONVERSION_BADNESS
= {2,0};
59 const struct rank INT_FLOAT_CONVERSION_BADNESS
= {2,0};
60 const struct rank VOID_PTR_CONVERSION_BADNESS
= {2,0};
61 const struct rank BOOL_CONVERSION_BADNESS
= {3,0};
62 const struct rank BASE_CONVERSION_BADNESS
= {2,0};
63 const struct rank REFERENCE_CONVERSION_BADNESS
= {2,0};
64 const struct rank REFERENCE_SEE_THROUGH_BADNESS
= {0,1};
65 const struct rank NULL_POINTER_CONVERSION_BADNESS
= {2,0};
66 const struct rank NS_POINTER_CONVERSION_BADNESS
= {10,0};
67 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS
= {3,0};
69 /* Floatformat pairs. */
70 const struct floatformat
*floatformats_ieee_half
[BFD_ENDIAN_UNKNOWN
] = {
71 &floatformat_ieee_half_big
,
72 &floatformat_ieee_half_little
74 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
75 &floatformat_ieee_single_big
,
76 &floatformat_ieee_single_little
78 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
79 &floatformat_ieee_double_big
,
80 &floatformat_ieee_double_little
82 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
83 &floatformat_ieee_double_big
,
84 &floatformat_ieee_double_littlebyte_bigword
86 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
87 &floatformat_i387_ext
,
90 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
91 &floatformat_m68881_ext
,
92 &floatformat_m68881_ext
94 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
95 &floatformat_arm_ext_big
,
96 &floatformat_arm_ext_littlebyte_bigword
98 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
99 &floatformat_ia64_spill_big
,
100 &floatformat_ia64_spill_little
102 const struct floatformat
*floatformats_ia64_quad
[BFD_ENDIAN_UNKNOWN
] = {
103 &floatformat_ia64_quad_big
,
104 &floatformat_ia64_quad_little
106 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
110 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
114 const struct floatformat
*floatformats_ibm_long_double
[BFD_ENDIAN_UNKNOWN
] = {
115 &floatformat_ibm_long_double_big
,
116 &floatformat_ibm_long_double_little
118 const struct floatformat
*floatformats_bfloat16
[BFD_ENDIAN_UNKNOWN
] = {
119 &floatformat_bfloat16_big
,
120 &floatformat_bfloat16_little
123 /* Should opaque types be resolved? */
125 static bool opaque_type_resolution
= true;
127 /* See gdbtypes.h. */
129 unsigned int overload_debug
= 0;
131 /* A flag to enable strict type checking. */
133 static bool strict_type_checking
= true;
135 /* A function to show whether opaque types are resolved. */
138 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
139 struct cmd_list_element
*c
,
142 fprintf_filtered (file
, _("Resolution of opaque struct/class/union types "
143 "(if set before loading symbols) is %s.\n"),
147 /* A function to show whether C++ overload debugging is enabled. */
150 show_overload_debug (struct ui_file
*file
, int from_tty
,
151 struct cmd_list_element
*c
, const char *value
)
153 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"),
157 /* A function to show the status of strict type checking. */
160 show_strict_type_checking (struct ui_file
*file
, int from_tty
,
161 struct cmd_list_element
*c
, const char *value
)
163 fprintf_filtered (file
, _("Strict type checking is %s.\n"), value
);
167 /* Allocate a new OBJFILE-associated type structure and fill it
168 with some defaults. Space for the type structure is allocated
169 on the objfile's objfile_obstack. */
172 alloc_type (struct objfile
*objfile
)
176 gdb_assert (objfile
!= NULL
);
178 /* Alloc the structure and start off with all fields zeroed. */
179 type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct type
);
180 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
182 OBJSTAT (objfile
, n_types
++);
184 TYPE_OBJFILE_OWNED (type
) = 1;
185 TYPE_OWNER (type
).objfile
= objfile
;
187 /* Initialize the fields that might not be zero. */
189 type
->set_code (TYPE_CODE_UNDEF
);
190 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
195 /* Allocate a new GDBARCH-associated type structure and fill it
196 with some defaults. Space for the type structure is allocated
197 on the obstack associated with GDBARCH. */
200 alloc_type_arch (struct gdbarch
*gdbarch
)
204 gdb_assert (gdbarch
!= NULL
);
206 /* Alloc the structure and start off with all fields zeroed. */
208 type
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct type
);
209 TYPE_MAIN_TYPE (type
) = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct main_type
);
211 TYPE_OBJFILE_OWNED (type
) = 0;
212 TYPE_OWNER (type
).gdbarch
= gdbarch
;
214 /* Initialize the fields that might not be zero. */
216 type
->set_code (TYPE_CODE_UNDEF
);
217 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
222 /* If TYPE is objfile-associated, allocate a new type structure
223 associated with the same objfile. If TYPE is gdbarch-associated,
224 allocate a new type structure associated with the same gdbarch. */
227 alloc_type_copy (const struct type
*type
)
229 if (TYPE_OBJFILE_OWNED (type
))
230 return alloc_type (TYPE_OWNER (type
).objfile
);
232 return alloc_type_arch (TYPE_OWNER (type
).gdbarch
);
235 /* If TYPE is gdbarch-associated, return that architecture.
236 If TYPE is objfile-associated, return that objfile's architecture. */
239 get_type_arch (const struct type
*type
)
241 struct gdbarch
*arch
;
243 if (TYPE_OBJFILE_OWNED (type
))
244 arch
= TYPE_OWNER (type
).objfile
->arch ();
246 arch
= TYPE_OWNER (type
).gdbarch
;
248 /* The ARCH can be NULL if TYPE is associated with neither an objfile nor
249 a gdbarch, however, this is very rare, and even then, in most cases
250 that get_type_arch is called, we assume that a non-NULL value is
252 gdb_assert (arch
!= NULL
);
256 /* See gdbtypes.h. */
259 get_target_type (struct type
*type
)
263 type
= TYPE_TARGET_TYPE (type
);
265 type
= check_typedef (type
);
271 /* See gdbtypes.h. */
274 type_length_units (struct type
*type
)
276 struct gdbarch
*arch
= get_type_arch (type
);
277 int unit_size
= gdbarch_addressable_memory_unit_size (arch
);
279 return TYPE_LENGTH (type
) / unit_size
;
282 /* Alloc a new type instance structure, fill it with some defaults,
283 and point it at OLDTYPE. Allocate the new type instance from the
284 same place as OLDTYPE. */
287 alloc_type_instance (struct type
*oldtype
)
291 /* Allocate the structure. */
293 if (! TYPE_OBJFILE_OWNED (oldtype
))
294 type
= GDBARCH_OBSTACK_ZALLOC (get_type_arch (oldtype
), struct type
);
296 type
= OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
299 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
301 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
306 /* Clear all remnants of the previous type at TYPE, in preparation for
307 replacing it with something else. Preserve owner information. */
310 smash_type (struct type
*type
)
312 int objfile_owned
= TYPE_OBJFILE_OWNED (type
);
313 union type_owner owner
= TYPE_OWNER (type
);
315 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
317 /* Restore owner information. */
318 TYPE_OBJFILE_OWNED (type
) = objfile_owned
;
319 TYPE_OWNER (type
) = owner
;
321 /* For now, delete the rings. */
322 TYPE_CHAIN (type
) = type
;
324 /* For now, leave the pointer/reference types alone. */
327 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
328 to a pointer to memory where the pointer type should be stored.
329 If *TYPEPTR is zero, update it to point to the pointer type we return.
330 We allocate new memory if needed. */
333 make_pointer_type (struct type
*type
, struct type
**typeptr
)
335 struct type
*ntype
; /* New type */
338 ntype
= TYPE_POINTER_TYPE (type
);
343 return ntype
; /* Don't care about alloc,
344 and have new type. */
345 else if (*typeptr
== 0)
347 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
352 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
354 ntype
= alloc_type_copy (type
);
358 else /* We have storage, but need to reset it. */
361 chain
= TYPE_CHAIN (ntype
);
363 TYPE_CHAIN (ntype
) = chain
;
366 TYPE_TARGET_TYPE (ntype
) = type
;
367 TYPE_POINTER_TYPE (type
) = ntype
;
369 /* FIXME! Assumes the machine has only one representation for pointers! */
372 = gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
373 ntype
->set_code (TYPE_CODE_PTR
);
375 /* Mark pointers as unsigned. The target converts between pointers
376 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
377 gdbarch_address_to_pointer. */
378 ntype
->set_is_unsigned (true);
380 /* Update the length of all the other variants of this type. */
381 chain
= TYPE_CHAIN (ntype
);
382 while (chain
!= ntype
)
384 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
385 chain
= TYPE_CHAIN (chain
);
391 /* Given a type TYPE, return a type of pointers to that type.
392 May need to construct such a type if this is the first use. */
395 lookup_pointer_type (struct type
*type
)
397 return make_pointer_type (type
, (struct type
**) 0);
400 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
401 points to a pointer to memory where the reference type should be
402 stored. If *TYPEPTR is zero, update it to point to the reference
403 type we return. We allocate new memory if needed. REFCODE denotes
404 the kind of reference type to lookup (lvalue or rvalue reference). */
407 make_reference_type (struct type
*type
, struct type
**typeptr
,
408 enum type_code refcode
)
410 struct type
*ntype
; /* New type */
411 struct type
**reftype
;
414 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
416 ntype
= (refcode
== TYPE_CODE_REF
? TYPE_REFERENCE_TYPE (type
)
417 : TYPE_RVALUE_REFERENCE_TYPE (type
));
422 return ntype
; /* Don't care about alloc,
423 and have new type. */
424 else if (*typeptr
== 0)
426 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
431 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
433 ntype
= alloc_type_copy (type
);
437 else /* We have storage, but need to reset it. */
440 chain
= TYPE_CHAIN (ntype
);
442 TYPE_CHAIN (ntype
) = chain
;
445 TYPE_TARGET_TYPE (ntype
) = type
;
446 reftype
= (refcode
== TYPE_CODE_REF
? &TYPE_REFERENCE_TYPE (type
)
447 : &TYPE_RVALUE_REFERENCE_TYPE (type
));
451 /* FIXME! Assume the machine has only one representation for
452 references, and that it matches the (only) representation for
455 TYPE_LENGTH (ntype
) =
456 gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
457 ntype
->set_code (refcode
);
461 /* Update the length of all the other variants of this type. */
462 chain
= TYPE_CHAIN (ntype
);
463 while (chain
!= ntype
)
465 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
466 chain
= TYPE_CHAIN (chain
);
472 /* Same as above, but caller doesn't care about memory allocation
476 lookup_reference_type (struct type
*type
, enum type_code refcode
)
478 return make_reference_type (type
, (struct type
**) 0, refcode
);
481 /* Lookup the lvalue reference type for the type TYPE. */
484 lookup_lvalue_reference_type (struct type
*type
)
486 return lookup_reference_type (type
, TYPE_CODE_REF
);
489 /* Lookup the rvalue reference type for the type TYPE. */
492 lookup_rvalue_reference_type (struct type
*type
)
494 return lookup_reference_type (type
, TYPE_CODE_RVALUE_REF
);
497 /* Lookup a function type that returns type TYPE. TYPEPTR, if
498 nonzero, points to a pointer to memory where the function type
499 should be stored. If *TYPEPTR is zero, update it to point to the
500 function type we return. We allocate new memory if needed. */
503 make_function_type (struct type
*type
, struct type
**typeptr
)
505 struct type
*ntype
; /* New type */
507 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
509 ntype
= alloc_type_copy (type
);
513 else /* We have storage, but need to reset it. */
519 TYPE_TARGET_TYPE (ntype
) = type
;
521 TYPE_LENGTH (ntype
) = 1;
522 ntype
->set_code (TYPE_CODE_FUNC
);
524 INIT_FUNC_SPECIFIC (ntype
);
529 /* Given a type TYPE, return a type of functions that return that type.
530 May need to construct such a type if this is the first use. */
533 lookup_function_type (struct type
*type
)
535 return make_function_type (type
, (struct type
**) 0);
538 /* Given a type TYPE and argument types, return the appropriate
539 function type. If the final type in PARAM_TYPES is NULL, make a
543 lookup_function_type_with_arguments (struct type
*type
,
545 struct type
**param_types
)
547 struct type
*fn
= make_function_type (type
, (struct type
**) 0);
552 if (param_types
[nparams
- 1] == NULL
)
555 fn
->set_has_varargs (true);
557 else if (check_typedef (param_types
[nparams
- 1])->code ()
561 /* Caller should have ensured this. */
562 gdb_assert (nparams
== 0);
563 fn
->set_is_prototyped (true);
566 fn
->set_is_prototyped (true);
569 fn
->set_num_fields (nparams
);
571 ((struct field
*) TYPE_ZALLOC (fn
, nparams
* sizeof (struct field
)));
572 for (i
= 0; i
< nparams
; ++i
)
573 fn
->field (i
).set_type (param_types
[i
]);
578 /* Identify address space identifier by name --
579 return the integer flag defined in gdbtypes.h. */
582 address_space_name_to_int (struct gdbarch
*gdbarch
,
583 const char *space_identifier
)
587 /* Check for known address space delimiters. */
588 if (!strcmp (space_identifier
, "code"))
589 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
590 else if (!strcmp (space_identifier
, "data"))
591 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
592 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
593 && gdbarch_address_class_name_to_type_flags (gdbarch
,
598 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
601 /* Identify address space identifier by integer flag as defined in
602 gdbtypes.h -- return the string version of the adress space name. */
605 address_space_int_to_name (struct gdbarch
*gdbarch
, int space_flag
)
607 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
609 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
611 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
612 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
613 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
618 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
620 If STORAGE is non-NULL, create the new type instance there.
621 STORAGE must be in the same obstack as TYPE. */
624 make_qualified_type (struct type
*type
, int new_flags
,
625 struct type
*storage
)
632 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
634 ntype
= TYPE_CHAIN (ntype
);
636 while (ntype
!= type
);
638 /* Create a new type instance. */
640 ntype
= alloc_type_instance (type
);
643 /* If STORAGE was provided, it had better be in the same objfile
644 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
645 if one objfile is freed and the other kept, we'd have
646 dangling pointers. */
647 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
650 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
651 TYPE_CHAIN (ntype
) = ntype
;
654 /* Pointers or references to the original type are not relevant to
656 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
657 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
659 /* Chain the new qualified type to the old type. */
660 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
661 TYPE_CHAIN (type
) = ntype
;
663 /* Now set the instance flags and return the new type. */
664 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
666 /* Set length of new type to that of the original type. */
667 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
672 /* Make an address-space-delimited variant of a type -- a type that
673 is identical to the one supplied except that it has an address
674 space attribute attached to it (such as "code" or "data").
676 The space attributes "code" and "data" are for Harvard
677 architectures. The address space attributes are for architectures
678 which have alternately sized pointers or pointers with alternate
682 make_type_with_address_space (struct type
*type
, int space_flag
)
684 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
685 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
686 | TYPE_INSTANCE_FLAG_DATA_SPACE
687 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
690 return make_qualified_type (type
, new_flags
, NULL
);
693 /* Make a "c-v" variant of a type -- a type that is identical to the
694 one supplied except that it may have const or volatile attributes
695 CNST is a flag for setting the const attribute
696 VOLTL is a flag for setting the volatile attribute
697 TYPE is the base type whose variant we are creating.
699 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
700 storage to hold the new qualified type; *TYPEPTR and TYPE must be
701 in the same objfile. Otherwise, allocate fresh memory for the new
702 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
703 new type we construct. */
706 make_cv_type (int cnst
, int voltl
,
708 struct type
**typeptr
)
710 struct type
*ntype
; /* New type */
712 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
713 & ~(TYPE_INSTANCE_FLAG_CONST
714 | TYPE_INSTANCE_FLAG_VOLATILE
));
717 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
720 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
722 if (typeptr
&& *typeptr
!= NULL
)
724 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
725 a C-V variant chain that threads across objfiles: if one
726 objfile gets freed, then the other has a broken C-V chain.
728 This code used to try to copy over the main type from TYPE to
729 *TYPEPTR if they were in different objfiles, but that's
730 wrong, too: TYPE may have a field list or member function
731 lists, which refer to types of their own, etc. etc. The
732 whole shebang would need to be copied over recursively; you
733 can't have inter-objfile pointers. The only thing to do is
734 to leave stub types as stub types, and look them up afresh by
735 name each time you encounter them. */
736 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
739 ntype
= make_qualified_type (type
, new_flags
,
740 typeptr
? *typeptr
: NULL
);
748 /* Make a 'restrict'-qualified version of TYPE. */
751 make_restrict_type (struct type
*type
)
753 return make_qualified_type (type
,
754 (TYPE_INSTANCE_FLAGS (type
)
755 | TYPE_INSTANCE_FLAG_RESTRICT
),
759 /* Make a type without const, volatile, or restrict. */
762 make_unqualified_type (struct type
*type
)
764 return make_qualified_type (type
,
765 (TYPE_INSTANCE_FLAGS (type
)
766 & ~(TYPE_INSTANCE_FLAG_CONST
767 | TYPE_INSTANCE_FLAG_VOLATILE
768 | TYPE_INSTANCE_FLAG_RESTRICT
)),
772 /* Make a '_Atomic'-qualified version of TYPE. */
775 make_atomic_type (struct type
*type
)
777 return make_qualified_type (type
,
778 (TYPE_INSTANCE_FLAGS (type
)
779 | TYPE_INSTANCE_FLAG_ATOMIC
),
783 /* Replace the contents of ntype with the type *type. This changes the
784 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
785 the changes are propogated to all types in the TYPE_CHAIN.
787 In order to build recursive types, it's inevitable that we'll need
788 to update types in place --- but this sort of indiscriminate
789 smashing is ugly, and needs to be replaced with something more
790 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
791 clear if more steps are needed. */
794 replace_type (struct type
*ntype
, struct type
*type
)
798 /* These two types had better be in the same objfile. Otherwise,
799 the assignment of one type's main type structure to the other
800 will produce a type with references to objects (names; field
801 lists; etc.) allocated on an objfile other than its own. */
802 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (type
));
804 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
806 /* The type length is not a part of the main type. Update it for
807 each type on the variant chain. */
811 /* Assert that this element of the chain has no address-class bits
812 set in its flags. Such type variants might have type lengths
813 which are supposed to be different from the non-address-class
814 variants. This assertion shouldn't ever be triggered because
815 symbol readers which do construct address-class variants don't
816 call replace_type(). */
817 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
819 TYPE_LENGTH (chain
) = TYPE_LENGTH (type
);
820 chain
= TYPE_CHAIN (chain
);
822 while (ntype
!= chain
);
824 /* Assert that the two types have equivalent instance qualifiers.
825 This should be true for at least all of our debug readers. */
826 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
829 /* Implement direct support for MEMBER_TYPE in GNU C++.
830 May need to construct such a type if this is the first use.
831 The TYPE is the type of the member. The DOMAIN is the type
832 of the aggregate that the member belongs to. */
835 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
839 mtype
= alloc_type_copy (type
);
840 smash_to_memberptr_type (mtype
, domain
, type
);
844 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
847 lookup_methodptr_type (struct type
*to_type
)
851 mtype
= alloc_type_copy (to_type
);
852 smash_to_methodptr_type (mtype
, to_type
);
856 /* Allocate a stub method whose return type is TYPE. This apparently
857 happens for speed of symbol reading, since parsing out the
858 arguments to the method is cpu-intensive, the way we are doing it.
859 So, we will fill in arguments later. This always returns a fresh
863 allocate_stub_method (struct type
*type
)
867 mtype
= alloc_type_copy (type
);
868 mtype
->set_code (TYPE_CODE_METHOD
);
869 TYPE_LENGTH (mtype
) = 1;
870 mtype
->set_is_stub (true);
871 TYPE_TARGET_TYPE (mtype
) = type
;
872 /* TYPE_SELF_TYPE (mtype) = unknown yet */
876 /* See gdbtypes.h. */
879 operator== (const dynamic_prop
&l
, const dynamic_prop
&r
)
881 if (l
.kind () != r
.kind ())
889 return l
.const_val () == r
.const_val ();
890 case PROP_ADDR_OFFSET
:
893 return l
.baton () == r
.baton ();
894 case PROP_VARIANT_PARTS
:
895 return l
.variant_parts () == r
.variant_parts ();
897 return l
.original_type () == r
.original_type ();
900 gdb_assert_not_reached ("unhandled dynamic_prop kind");
903 /* See gdbtypes.h. */
906 operator== (const range_bounds
&l
, const range_bounds
&r
)
908 #define FIELD_EQ(FIELD) (l.FIELD == r.FIELD)
910 return (FIELD_EQ (low
)
912 && FIELD_EQ (flag_upper_bound_is_count
)
913 && FIELD_EQ (flag_bound_evaluated
)
919 /* Create a range type with a dynamic range from LOW_BOUND to
920 HIGH_BOUND, inclusive. See create_range_type for further details. */
923 create_range_type (struct type
*result_type
, struct type
*index_type
,
924 const struct dynamic_prop
*low_bound
,
925 const struct dynamic_prop
*high_bound
,
928 /* The INDEX_TYPE should be a type capable of holding the upper and lower
929 bounds, as such a zero sized, or void type makes no sense. */
930 gdb_assert (index_type
->code () != TYPE_CODE_VOID
);
931 gdb_assert (TYPE_LENGTH (index_type
) > 0);
933 if (result_type
== NULL
)
934 result_type
= alloc_type_copy (index_type
);
935 result_type
->set_code (TYPE_CODE_RANGE
);
936 TYPE_TARGET_TYPE (result_type
) = index_type
;
937 if (index_type
->is_stub ())
938 result_type
->set_target_is_stub (true);
940 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
943 = (struct range_bounds
*) TYPE_ZALLOC (result_type
, sizeof (range_bounds
));
944 bounds
->low
= *low_bound
;
945 bounds
->high
= *high_bound
;
947 bounds
->stride
.set_const_val (0);
949 result_type
->set_bounds (bounds
);
951 if (low_bound
->kind () == PROP_CONST
&& low_bound
->const_val () >= 0)
952 result_type
->set_is_unsigned (true);
954 /* Ada allows the declaration of range types whose upper bound is
955 less than the lower bound, so checking the lower bound is not
956 enough. Make sure we do not mark a range type whose upper bound
957 is negative as unsigned. */
958 if (high_bound
->kind () == PROP_CONST
&& high_bound
->const_val () < 0)
959 result_type
->set_is_unsigned (false);
961 TYPE_ENDIANITY_NOT_DEFAULT (result_type
)
962 = TYPE_ENDIANITY_NOT_DEFAULT (index_type
);
967 /* See gdbtypes.h. */
970 create_range_type_with_stride (struct type
*result_type
,
971 struct type
*index_type
,
972 const struct dynamic_prop
*low_bound
,
973 const struct dynamic_prop
*high_bound
,
975 const struct dynamic_prop
*stride
,
978 result_type
= create_range_type (result_type
, index_type
, low_bound
,
981 gdb_assert (stride
!= nullptr);
982 result_type
->bounds ()->stride
= *stride
;
983 result_type
->bounds ()->flag_is_byte_stride
= byte_stride_p
;
990 /* Create a range type using either a blank type supplied in
991 RESULT_TYPE, or creating a new type, inheriting the objfile from
994 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
995 to HIGH_BOUND, inclusive.
997 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
998 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
1001 create_static_range_type (struct type
*result_type
, struct type
*index_type
,
1002 LONGEST low_bound
, LONGEST high_bound
)
1004 struct dynamic_prop low
, high
;
1006 low
.set_const_val (low_bound
);
1007 high
.set_const_val (high_bound
);
1009 result_type
= create_range_type (result_type
, index_type
, &low
, &high
, 0);
1014 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
1015 are static, otherwise returns 0. */
1018 has_static_range (const struct range_bounds
*bounds
)
1020 /* If the range doesn't have a defined stride then its stride field will
1021 be initialized to the constant 0. */
1022 return (bounds
->low
.kind () == PROP_CONST
1023 && bounds
->high
.kind () == PROP_CONST
1024 && bounds
->stride
.kind () == PROP_CONST
);
1028 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
1031 Return 1 if type is a range type with two defined, constant bounds.
1032 Else, return 0 if it is discrete (and bounds will fit in LONGEST).
1036 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
1038 type
= check_typedef (type
);
1039 switch (type
->code ())
1041 case TYPE_CODE_RANGE
:
1042 /* This function currently only works for ranges with two defined,
1044 if (type
->bounds ()->low
.kind () != PROP_CONST
1045 || type
->bounds ()->high
.kind () != PROP_CONST
)
1048 *lowp
= type
->bounds ()->low
.const_val ();
1049 *highp
= type
->bounds ()->high
.const_val ();
1051 if (TYPE_TARGET_TYPE (type
)->code () == TYPE_CODE_ENUM
)
1053 if (!discrete_position (TYPE_TARGET_TYPE (type
), *lowp
, lowp
)
1054 || ! discrete_position (TYPE_TARGET_TYPE (type
), *highp
, highp
))
1058 case TYPE_CODE_ENUM
:
1059 if (type
->num_fields () > 0)
1061 /* The enums may not be sorted by value, so search all
1065 *lowp
= *highp
= TYPE_FIELD_ENUMVAL (type
, 0);
1066 for (i
= 0; i
< type
->num_fields (); i
++)
1068 if (TYPE_FIELD_ENUMVAL (type
, i
) < *lowp
)
1069 *lowp
= TYPE_FIELD_ENUMVAL (type
, i
);
1070 if (TYPE_FIELD_ENUMVAL (type
, i
) > *highp
)
1071 *highp
= TYPE_FIELD_ENUMVAL (type
, i
);
1074 /* Set unsigned indicator if warranted. */
1076 type
->set_is_unsigned (true);
1084 case TYPE_CODE_BOOL
:
1089 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
1091 if (!type
->is_unsigned ())
1093 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
1094 *highp
= -*lowp
- 1;
1098 case TYPE_CODE_CHAR
:
1100 /* This round-about calculation is to avoid shifting by
1101 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
1102 if TYPE_LENGTH (type) == sizeof (LONGEST). */
1103 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
1104 *highp
= (*highp
- 1) | *highp
;
1111 /* Assuming TYPE is a simple, non-empty array type, compute its upper
1112 and lower bound. Save the low bound into LOW_BOUND if not NULL.
1113 Save the high bound into HIGH_BOUND if not NULL.
1115 Return 1 if the operation was successful. Return zero otherwise,
1116 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified. */
1119 get_array_bounds (struct type
*type
, LONGEST
*low_bound
, LONGEST
*high_bound
)
1121 struct type
*index
= type
->index_type ();
1129 res
= get_discrete_bounds (index
, &low
, &high
);
1142 /* Assuming that TYPE is a discrete type and VAL is a valid integer
1143 representation of a value of this type, save the corresponding
1144 position number in POS.
1146 Its differs from VAL only in the case of enumeration types. In
1147 this case, the position number of the value of the first listed
1148 enumeration literal is zero; the position number of the value of
1149 each subsequent enumeration literal is one more than that of its
1150 predecessor in the list.
1152 Return 1 if the operation was successful. Return zero otherwise,
1153 in which case the value of POS is unmodified.
1157 discrete_position (struct type
*type
, LONGEST val
, LONGEST
*pos
)
1159 if (type
->code () == TYPE_CODE_RANGE
)
1160 type
= TYPE_TARGET_TYPE (type
);
1162 if (type
->code () == TYPE_CODE_ENUM
)
1166 for (i
= 0; i
< type
->num_fields (); i
+= 1)
1168 if (val
== TYPE_FIELD_ENUMVAL (type
, i
))
1174 /* Invalid enumeration value. */
1184 /* If the array TYPE has static bounds calculate and update its
1185 size, then return true. Otherwise return false and leave TYPE
1189 update_static_array_size (struct type
*type
)
1191 gdb_assert (type
->code () == TYPE_CODE_ARRAY
);
1193 struct type
*range_type
= type
->index_type ();
1195 if (type
->dyn_prop (DYN_PROP_BYTE_STRIDE
) == nullptr
1196 && has_static_range (range_type
->bounds ())
1197 && (!type_not_associated (type
)
1198 && !type_not_allocated (type
)))
1200 LONGEST low_bound
, high_bound
;
1202 struct type
*element_type
;
1204 /* If the array itself doesn't provide a stride value then take
1205 whatever stride the range provides. Don't update BIT_STRIDE as
1206 we don't want to place the stride value from the range into this
1207 arrays bit size field. */
1208 stride
= TYPE_FIELD_BITSIZE (type
, 0);
1210 stride
= range_type
->bit_stride ();
1212 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
1213 low_bound
= high_bound
= 0;
1214 element_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1215 /* Be careful when setting the array length. Ada arrays can be
1216 empty arrays with the high_bound being smaller than the low_bound.
1217 In such cases, the array length should be zero. */
1218 if (high_bound
< low_bound
)
1219 TYPE_LENGTH (type
) = 0;
1220 else if (stride
!= 0)
1222 /* Ensure that the type length is always positive, even in the
1223 case where (for example in Fortran) we have a negative
1224 stride. It is possible to have a single element array with a
1225 negative stride in Fortran (this doesn't mean anything
1226 special, it's still just a single element array) so do
1227 consider that case when touching this code. */
1228 LONGEST element_count
= std::abs (high_bound
- low_bound
+ 1);
1230 = ((std::abs (stride
) * element_count
) + 7) / 8;
1233 TYPE_LENGTH (type
) =
1234 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
1242 /* Create an array type using either a blank type supplied in
1243 RESULT_TYPE, or creating a new type, inheriting the objfile from
1246 Elements will be of type ELEMENT_TYPE, the indices will be of type
1249 BYTE_STRIDE_PROP, when not NULL, provides the array's byte stride.
1250 This byte stride property is added to the resulting array type
1251 as a DYN_PROP_BYTE_STRIDE. As a consequence, the BYTE_STRIDE_PROP
1252 argument can only be used to create types that are objfile-owned
1253 (see add_dyn_prop), meaning that either this function must be called
1254 with an objfile-owned RESULT_TYPE, or an objfile-owned RANGE_TYPE.
1256 BIT_STRIDE is taken into account only when BYTE_STRIDE_PROP is NULL.
1257 If BIT_STRIDE is not zero, build a packed array type whose element
1258 size is BIT_STRIDE. Otherwise, ignore this parameter.
1260 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1261 sure it is TYPE_CODE_UNDEF before we bash it into an array
1265 create_array_type_with_stride (struct type
*result_type
,
1266 struct type
*element_type
,
1267 struct type
*range_type
,
1268 struct dynamic_prop
*byte_stride_prop
,
1269 unsigned int bit_stride
)
1271 if (byte_stride_prop
!= NULL
1272 && byte_stride_prop
->kind () == PROP_CONST
)
1274 /* The byte stride is actually not dynamic. Pretend we were
1275 called with bit_stride set instead of byte_stride_prop.
1276 This will give us the same result type, while avoiding
1277 the need to handle this as a special case. */
1278 bit_stride
= byte_stride_prop
->const_val () * 8;
1279 byte_stride_prop
= NULL
;
1282 if (result_type
== NULL
)
1283 result_type
= alloc_type_copy (range_type
);
1285 result_type
->set_code (TYPE_CODE_ARRAY
);
1286 TYPE_TARGET_TYPE (result_type
) = element_type
;
1288 result_type
->set_num_fields (1);
1289 result_type
->set_fields
1290 ((struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
)));
1291 result_type
->set_index_type (range_type
);
1292 if (byte_stride_prop
!= NULL
)
1293 result_type
->add_dyn_prop (DYN_PROP_BYTE_STRIDE
, *byte_stride_prop
);
1294 else if (bit_stride
> 0)
1295 TYPE_FIELD_BITSIZE (result_type
, 0) = bit_stride
;
1297 if (!update_static_array_size (result_type
))
1299 /* This type is dynamic and its length needs to be computed
1300 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1301 undefined by setting it to zero. Although we are not expected
1302 to trust TYPE_LENGTH in this case, setting the size to zero
1303 allows us to avoid allocating objects of random sizes in case
1304 we accidently do. */
1305 TYPE_LENGTH (result_type
) = 0;
1308 /* TYPE_TARGET_STUB will take care of zero length arrays. */
1309 if (TYPE_LENGTH (result_type
) == 0)
1310 result_type
->set_target_is_stub (true);
1315 /* Same as create_array_type_with_stride but with no bit_stride
1316 (BIT_STRIDE = 0), thus building an unpacked array. */
1319 create_array_type (struct type
*result_type
,
1320 struct type
*element_type
,
1321 struct type
*range_type
)
1323 return create_array_type_with_stride (result_type
, element_type
,
1324 range_type
, NULL
, 0);
1328 lookup_array_range_type (struct type
*element_type
,
1329 LONGEST low_bound
, LONGEST high_bound
)
1331 struct type
*index_type
;
1332 struct type
*range_type
;
1334 if (TYPE_OBJFILE_OWNED (element_type
))
1335 index_type
= objfile_type (TYPE_OWNER (element_type
).objfile
)->builtin_int
;
1337 index_type
= builtin_type (get_type_arch (element_type
))->builtin_int
;
1338 range_type
= create_static_range_type (NULL
, index_type
,
1339 low_bound
, high_bound
);
1341 return create_array_type (NULL
, element_type
, range_type
);
1344 /* Create a string type using either a blank type supplied in
1345 RESULT_TYPE, or creating a new type. String types are similar
1346 enough to array of char types that we can use create_array_type to
1347 build the basic type and then bash it into a string type.
1349 For fixed length strings, the range type contains 0 as the lower
1350 bound and the length of the string minus one as the upper bound.
1352 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1353 sure it is TYPE_CODE_UNDEF before we bash it into a string
1357 create_string_type (struct type
*result_type
,
1358 struct type
*string_char_type
,
1359 struct type
*range_type
)
1361 result_type
= create_array_type (result_type
,
1364 result_type
->set_code (TYPE_CODE_STRING
);
1369 lookup_string_range_type (struct type
*string_char_type
,
1370 LONGEST low_bound
, LONGEST high_bound
)
1372 struct type
*result_type
;
1374 result_type
= lookup_array_range_type (string_char_type
,
1375 low_bound
, high_bound
);
1376 result_type
->set_code (TYPE_CODE_STRING
);
1381 create_set_type (struct type
*result_type
, struct type
*domain_type
)
1383 if (result_type
== NULL
)
1384 result_type
= alloc_type_copy (domain_type
);
1386 result_type
->set_code (TYPE_CODE_SET
);
1387 result_type
->set_num_fields (1);
1388 result_type
->set_fields
1389 ((struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
)));
1391 if (!domain_type
->is_stub ())
1393 LONGEST low_bound
, high_bound
, bit_length
;
1395 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
1396 low_bound
= high_bound
= 0;
1397 bit_length
= high_bound
- low_bound
+ 1;
1398 TYPE_LENGTH (result_type
)
1399 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
1401 result_type
->set_is_unsigned (true);
1403 result_type
->field (0).set_type (domain_type
);
1408 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1409 and any array types nested inside it. */
1412 make_vector_type (struct type
*array_type
)
1414 struct type
*inner_array
, *elt_type
;
1417 /* Find the innermost array type, in case the array is
1418 multi-dimensional. */
1419 inner_array
= array_type
;
1420 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
1421 inner_array
= TYPE_TARGET_TYPE (inner_array
);
1423 elt_type
= TYPE_TARGET_TYPE (inner_array
);
1424 if (elt_type
->code () == TYPE_CODE_INT
)
1426 flags
= TYPE_INSTANCE_FLAGS (elt_type
) | TYPE_INSTANCE_FLAG_NOTTEXT
;
1427 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
1428 TYPE_TARGET_TYPE (inner_array
) = elt_type
;
1431 array_type
->set_is_vector (true);
1435 init_vector_type (struct type
*elt_type
, int n
)
1437 struct type
*array_type
;
1439 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
1440 make_vector_type (array_type
);
1444 /* Internal routine called by TYPE_SELF_TYPE to return the type that TYPE
1445 belongs to. In c++ this is the class of "this", but TYPE_THIS_TYPE is too
1446 confusing. "self" is a common enough replacement for "this".
1447 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1448 TYPE_CODE_METHOD. */
1451 internal_type_self_type (struct type
*type
)
1453 switch (type
->code ())
1455 case TYPE_CODE_METHODPTR
:
1456 case TYPE_CODE_MEMBERPTR
:
1457 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1459 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1460 return TYPE_MAIN_TYPE (type
)->type_specific
.self_type
;
1461 case TYPE_CODE_METHOD
:
1462 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1464 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1465 return TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
;
1467 gdb_assert_not_reached ("bad type");
1471 /* Set the type of the class that TYPE belongs to.
1472 In c++ this is the class of "this".
1473 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1474 TYPE_CODE_METHOD. */
1477 set_type_self_type (struct type
*type
, struct type
*self_type
)
1479 switch (type
->code ())
1481 case TYPE_CODE_METHODPTR
:
1482 case TYPE_CODE_MEMBERPTR
:
1483 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1484 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_SELF_TYPE
;
1485 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1486 TYPE_MAIN_TYPE (type
)->type_specific
.self_type
= self_type
;
1488 case TYPE_CODE_METHOD
:
1489 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1490 INIT_FUNC_SPECIFIC (type
);
1491 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1492 TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
= self_type
;
1495 gdb_assert_not_reached ("bad type");
1499 /* Smash TYPE to be a type of pointers to members of SELF_TYPE with type
1500 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1501 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1502 TYPE doesn't include the offset (that's the value of the MEMBER
1503 itself), but does include the structure type into which it points
1506 When "smashing" the type, we preserve the objfile that the old type
1507 pointed to, since we aren't changing where the type is actually
1511 smash_to_memberptr_type (struct type
*type
, struct type
*self_type
,
1512 struct type
*to_type
)
1515 type
->set_code (TYPE_CODE_MEMBERPTR
);
1516 TYPE_TARGET_TYPE (type
) = to_type
;
1517 set_type_self_type (type
, self_type
);
1518 /* Assume that a data member pointer is the same size as a normal
1521 = gdbarch_ptr_bit (get_type_arch (to_type
)) / TARGET_CHAR_BIT
;
1524 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1526 When "smashing" the type, we preserve the objfile that the old type
1527 pointed to, since we aren't changing where the type is actually
1531 smash_to_methodptr_type (struct type
*type
, struct type
*to_type
)
1534 type
->set_code (TYPE_CODE_METHODPTR
);
1535 TYPE_TARGET_TYPE (type
) = to_type
;
1536 set_type_self_type (type
, TYPE_SELF_TYPE (to_type
));
1537 TYPE_LENGTH (type
) = cplus_method_ptr_size (to_type
);
1540 /* Smash TYPE to be a type of method of SELF_TYPE with type TO_TYPE.
1541 METHOD just means `function that gets an extra "this" argument'.
1543 When "smashing" the type, we preserve the objfile that the old type
1544 pointed to, since we aren't changing where the type is actually
1548 smash_to_method_type (struct type
*type
, struct type
*self_type
,
1549 struct type
*to_type
, struct field
*args
,
1550 int nargs
, int varargs
)
1553 type
->set_code (TYPE_CODE_METHOD
);
1554 TYPE_TARGET_TYPE (type
) = to_type
;
1555 set_type_self_type (type
, self_type
);
1556 type
->set_fields (args
);
1557 type
->set_num_fields (nargs
);
1559 type
->set_has_varargs (true);
1560 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1563 /* A wrapper of TYPE_NAME which calls error if the type is anonymous.
1564 Since GCC PR debug/47510 DWARF provides associated information to detect the
1565 anonymous class linkage name from its typedef.
1567 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1571 type_name_or_error (struct type
*type
)
1573 struct type
*saved_type
= type
;
1575 struct objfile
*objfile
;
1577 type
= check_typedef (type
);
1579 name
= type
->name ();
1583 name
= saved_type
->name ();
1584 objfile
= TYPE_OBJFILE (saved_type
);
1585 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1586 name
? name
: "<anonymous>",
1587 objfile
? objfile_name (objfile
) : "<arch>");
1590 /* Lookup a typedef or primitive type named NAME, visible in lexical
1591 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1592 suitably defined. */
1595 lookup_typename (const struct language_defn
*language
,
1597 const struct block
*block
, int noerr
)
1601 sym
= lookup_symbol_in_language (name
, block
, VAR_DOMAIN
,
1602 language
->la_language
, NULL
).symbol
;
1603 if (sym
!= NULL
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
1604 return SYMBOL_TYPE (sym
);
1608 error (_("No type named %s."), name
);
1612 lookup_unsigned_typename (const struct language_defn
*language
,
1615 char *uns
= (char *) alloca (strlen (name
) + 10);
1617 strcpy (uns
, "unsigned ");
1618 strcpy (uns
+ 9, name
);
1619 return lookup_typename (language
, uns
, NULL
, 0);
1623 lookup_signed_typename (const struct language_defn
*language
, const char *name
)
1626 char *uns
= (char *) alloca (strlen (name
) + 8);
1628 strcpy (uns
, "signed ");
1629 strcpy (uns
+ 7, name
);
1630 t
= lookup_typename (language
, uns
, NULL
, 1);
1631 /* If we don't find "signed FOO" just try again with plain "FOO". */
1634 return lookup_typename (language
, name
, NULL
, 0);
1637 /* Lookup a structure type named "struct NAME",
1638 visible in lexical block BLOCK. */
1641 lookup_struct (const char *name
, const struct block
*block
)
1645 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1649 error (_("No struct type named %s."), name
);
1651 if (SYMBOL_TYPE (sym
)->code () != TYPE_CODE_STRUCT
)
1653 error (_("This context has class, union or enum %s, not a struct."),
1656 return (SYMBOL_TYPE (sym
));
1659 /* Lookup a union type named "union NAME",
1660 visible in lexical block BLOCK. */
1663 lookup_union (const char *name
, const struct block
*block
)
1668 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1671 error (_("No union type named %s."), name
);
1673 t
= SYMBOL_TYPE (sym
);
1675 if (t
->code () == TYPE_CODE_UNION
)
1678 /* If we get here, it's not a union. */
1679 error (_("This context has class, struct or enum %s, not a union."),
1683 /* Lookup an enum type named "enum NAME",
1684 visible in lexical block BLOCK. */
1687 lookup_enum (const char *name
, const struct block
*block
)
1691 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1694 error (_("No enum type named %s."), name
);
1696 if (SYMBOL_TYPE (sym
)->code () != TYPE_CODE_ENUM
)
1698 error (_("This context has class, struct or union %s, not an enum."),
1701 return (SYMBOL_TYPE (sym
));
1704 /* Lookup a template type named "template NAME<TYPE>",
1705 visible in lexical block BLOCK. */
1708 lookup_template_type (const char *name
, struct type
*type
,
1709 const struct block
*block
)
1712 char *nam
= (char *)
1713 alloca (strlen (name
) + strlen (type
->name ()) + 4);
1717 strcat (nam
, type
->name ());
1718 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1720 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0).symbol
;
1724 error (_("No template type named %s."), name
);
1726 if (SYMBOL_TYPE (sym
)->code () != TYPE_CODE_STRUCT
)
1728 error (_("This context has class, union or enum %s, not a struct."),
1731 return (SYMBOL_TYPE (sym
));
1734 /* See gdbtypes.h. */
1737 lookup_struct_elt (struct type
*type
, const char *name
, int noerr
)
1743 type
= check_typedef (type
);
1744 if (type
->code () != TYPE_CODE_PTR
1745 && type
->code () != TYPE_CODE_REF
)
1747 type
= TYPE_TARGET_TYPE (type
);
1750 if (type
->code () != TYPE_CODE_STRUCT
1751 && type
->code () != TYPE_CODE_UNION
)
1753 std::string type_name
= type_to_string (type
);
1754 error (_("Type %s is not a structure or union type."),
1755 type_name
.c_str ());
1758 for (i
= type
->num_fields () - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1760 const char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1762 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1764 return {&type
->field (i
), TYPE_FIELD_BITPOS (type
, i
)};
1766 else if (!t_field_name
|| *t_field_name
== '\0')
1769 = lookup_struct_elt (type
->field (i
).type (), name
, 1);
1770 if (elt
.field
!= NULL
)
1772 elt
.offset
+= TYPE_FIELD_BITPOS (type
, i
);
1778 /* OK, it's not in this class. Recursively check the baseclasses. */
1779 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1781 struct_elt elt
= lookup_struct_elt (TYPE_BASECLASS (type
, i
), name
, 1);
1782 if (elt
.field
!= NULL
)
1787 return {nullptr, 0};
1789 std::string type_name
= type_to_string (type
);
1790 error (_("Type %s has no component named %s."), type_name
.c_str (), name
);
1793 /* See gdbtypes.h. */
1796 lookup_struct_elt_type (struct type
*type
, const char *name
, int noerr
)
1798 struct_elt elt
= lookup_struct_elt (type
, name
, noerr
);
1799 if (elt
.field
!= NULL
)
1800 return elt
.field
->type ();
1805 /* Store in *MAX the largest number representable by unsigned integer type
1809 get_unsigned_type_max (struct type
*type
, ULONGEST
*max
)
1813 type
= check_typedef (type
);
1814 gdb_assert (type
->code () == TYPE_CODE_INT
&& type
->is_unsigned ());
1815 gdb_assert (TYPE_LENGTH (type
) <= sizeof (ULONGEST
));
1817 /* Written this way to avoid overflow. */
1818 n
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
;
1819 *max
= ((((ULONGEST
) 1 << (n
- 1)) - 1) << 1) | 1;
1822 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1823 signed integer type TYPE. */
1826 get_signed_type_minmax (struct type
*type
, LONGEST
*min
, LONGEST
*max
)
1830 type
= check_typedef (type
);
1831 gdb_assert (type
->code () == TYPE_CODE_INT
&& !type
->is_unsigned ());
1832 gdb_assert (TYPE_LENGTH (type
) <= sizeof (LONGEST
));
1834 n
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
;
1835 *min
= -((ULONGEST
) 1 << (n
- 1));
1836 *max
= ((ULONGEST
) 1 << (n
- 1)) - 1;
1839 /* Internal routine called by TYPE_VPTR_FIELDNO to return the value of
1840 cplus_stuff.vptr_fieldno.
1842 cplus_stuff is initialized to cplus_struct_default which does not
1843 set vptr_fieldno to -1 for portability reasons (IWBN to use C99
1844 designated initializers). We cope with that here. */
1847 internal_type_vptr_fieldno (struct type
*type
)
1849 type
= check_typedef (type
);
1850 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1851 || type
->code () == TYPE_CODE_UNION
);
1852 if (!HAVE_CPLUS_STRUCT (type
))
1854 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
;
1857 /* Set the value of cplus_stuff.vptr_fieldno. */
1860 set_type_vptr_fieldno (struct type
*type
, int fieldno
)
1862 type
= check_typedef (type
);
1863 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1864 || type
->code () == TYPE_CODE_UNION
);
1865 if (!HAVE_CPLUS_STRUCT (type
))
1866 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1867 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
= fieldno
;
1870 /* Internal routine called by TYPE_VPTR_BASETYPE to return the value of
1871 cplus_stuff.vptr_basetype. */
1874 internal_type_vptr_basetype (struct type
*type
)
1876 type
= check_typedef (type
);
1877 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1878 || type
->code () == TYPE_CODE_UNION
);
1879 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_CPLUS_STUFF
);
1880 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
;
1883 /* Set the value of cplus_stuff.vptr_basetype. */
1886 set_type_vptr_basetype (struct type
*type
, struct type
*basetype
)
1888 type
= check_typedef (type
);
1889 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1890 || type
->code () == TYPE_CODE_UNION
);
1891 if (!HAVE_CPLUS_STRUCT (type
))
1892 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1893 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
= basetype
;
1896 /* Lookup the vptr basetype/fieldno values for TYPE.
1897 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1898 vptr_fieldno. Also, if found and basetype is from the same objfile,
1900 If not found, return -1 and ignore BASETYPEP.
1901 Callers should be aware that in some cases (for example,
1902 the type or one of its baseclasses is a stub type and we are
1903 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1904 this function will not be able to find the
1905 virtual function table pointer, and vptr_fieldno will remain -1 and
1906 vptr_basetype will remain NULL or incomplete. */
1909 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1911 type
= check_typedef (type
);
1913 if (TYPE_VPTR_FIELDNO (type
) < 0)
1917 /* We must start at zero in case the first (and only) baseclass
1918 is virtual (and hence we cannot share the table pointer). */
1919 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1921 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1923 struct type
*basetype
;
1925 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1928 /* If the type comes from a different objfile we can't cache
1929 it, it may have a different lifetime. PR 2384 */
1930 if (TYPE_OBJFILE (type
) == TYPE_OBJFILE (basetype
))
1932 set_type_vptr_fieldno (type
, fieldno
);
1933 set_type_vptr_basetype (type
, basetype
);
1936 *basetypep
= basetype
;
1947 *basetypep
= TYPE_VPTR_BASETYPE (type
);
1948 return TYPE_VPTR_FIELDNO (type
);
1953 stub_noname_complaint (void)
1955 complaint (_("stub type has NULL name"));
1958 /* Return nonzero if TYPE has a DYN_PROP_BYTE_STRIDE dynamic property
1959 attached to it, and that property has a non-constant value. */
1962 array_type_has_dynamic_stride (struct type
*type
)
1964 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_BYTE_STRIDE
);
1966 return (prop
!= NULL
&& prop
->kind () != PROP_CONST
);
1969 /* Worker for is_dynamic_type. */
1972 is_dynamic_type_internal (struct type
*type
, int top_level
)
1974 type
= check_typedef (type
);
1976 /* We only want to recognize references at the outermost level. */
1977 if (top_level
&& type
->code () == TYPE_CODE_REF
)
1978 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1980 /* Types that have a dynamic TYPE_DATA_LOCATION are considered
1981 dynamic, even if the type itself is statically defined.
1982 From a user's point of view, this may appear counter-intuitive;
1983 but it makes sense in this context, because the point is to determine
1984 whether any part of the type needs to be resolved before it can
1986 if (TYPE_DATA_LOCATION (type
) != NULL
1987 && (TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCEXPR
1988 || TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCLIST
))
1991 if (TYPE_ASSOCIATED_PROP (type
))
1994 if (TYPE_ALLOCATED_PROP (type
))
1997 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
1998 if (prop
!= nullptr && prop
->kind () != PROP_TYPE
)
2001 if (TYPE_HAS_DYNAMIC_LENGTH (type
))
2004 switch (type
->code ())
2006 case TYPE_CODE_RANGE
:
2008 /* A range type is obviously dynamic if it has at least one
2009 dynamic bound. But also consider the range type to be
2010 dynamic when its subtype is dynamic, even if the bounds
2011 of the range type are static. It allows us to assume that
2012 the subtype of a static range type is also static. */
2013 return (!has_static_range (type
->bounds ())
2014 || is_dynamic_type_internal (TYPE_TARGET_TYPE (type
), 0));
2017 case TYPE_CODE_STRING
:
2018 /* Strings are very much like an array of characters, and can be
2019 treated as one here. */
2020 case TYPE_CODE_ARRAY
:
2022 gdb_assert (type
->num_fields () == 1);
2024 /* The array is dynamic if either the bounds are dynamic... */
2025 if (is_dynamic_type_internal (type
->index_type (), 0))
2027 /* ... or the elements it contains have a dynamic contents... */
2028 if (is_dynamic_type_internal (TYPE_TARGET_TYPE (type
), 0))
2030 /* ... or if it has a dynamic stride... */
2031 if (array_type_has_dynamic_stride (type
))
2036 case TYPE_CODE_STRUCT
:
2037 case TYPE_CODE_UNION
:
2041 bool is_cplus
= HAVE_CPLUS_STRUCT (type
);
2043 for (i
= 0; i
< type
->num_fields (); ++i
)
2045 /* Static fields can be ignored here. */
2046 if (field_is_static (&type
->field (i
)))
2048 /* If the field has dynamic type, then so does TYPE. */
2049 if (is_dynamic_type_internal (type
->field (i
).type (), 0))
2051 /* If the field is at a fixed offset, then it is not
2053 if (TYPE_FIELD_LOC_KIND (type
, i
) != FIELD_LOC_KIND_DWARF_BLOCK
)
2055 /* Do not consider C++ virtual base types to be dynamic
2056 due to the field's offset being dynamic; these are
2057 handled via other means. */
2058 if (is_cplus
&& BASETYPE_VIA_VIRTUAL (type
, i
))
2069 /* See gdbtypes.h. */
2072 is_dynamic_type (struct type
*type
)
2074 return is_dynamic_type_internal (type
, 1);
2077 static struct type
*resolve_dynamic_type_internal
2078 (struct type
*type
, struct property_addr_info
*addr_stack
, int top_level
);
2080 /* Given a dynamic range type (dyn_range_type) and a stack of
2081 struct property_addr_info elements, return a static version
2084 static struct type
*
2085 resolve_dynamic_range (struct type
*dyn_range_type
,
2086 struct property_addr_info
*addr_stack
)
2089 struct type
*static_range_type
, *static_target_type
;
2090 struct dynamic_prop low_bound
, high_bound
, stride
;
2092 gdb_assert (dyn_range_type
->code () == TYPE_CODE_RANGE
);
2094 const struct dynamic_prop
*prop
= &dyn_range_type
->bounds ()->low
;
2095 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2096 low_bound
.set_const_val (value
);
2098 low_bound
.set_undefined ();
2100 prop
= &dyn_range_type
->bounds ()->high
;
2101 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2103 high_bound
.set_const_val (value
);
2105 if (dyn_range_type
->bounds ()->flag_upper_bound_is_count
)
2106 high_bound
.set_const_val
2107 (low_bound
.const_val () + high_bound
.const_val () - 1);
2110 high_bound
.set_undefined ();
2112 bool byte_stride_p
= dyn_range_type
->bounds ()->flag_is_byte_stride
;
2113 prop
= &dyn_range_type
->bounds ()->stride
;
2114 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2116 stride
.set_const_val (value
);
2118 /* If we have a bit stride that is not an exact number of bytes then
2119 I really don't think this is going to work with current GDB, the
2120 array indexing code in GDB seems to be pretty heavily tied to byte
2121 offsets right now. Assuming 8 bits in a byte. */
2122 struct gdbarch
*gdbarch
= get_type_arch (dyn_range_type
);
2123 int unit_size
= gdbarch_addressable_memory_unit_size (gdbarch
);
2124 if (!byte_stride_p
&& (value
% (unit_size
* 8)) != 0)
2125 error (_("bit strides that are not a multiple of the byte size "
2126 "are currently not supported"));
2130 stride
.set_undefined ();
2131 byte_stride_p
= true;
2135 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type
),
2137 LONGEST bias
= dyn_range_type
->bounds ()->bias
;
2138 static_range_type
= create_range_type_with_stride
2139 (copy_type (dyn_range_type
), static_target_type
,
2140 &low_bound
, &high_bound
, bias
, &stride
, byte_stride_p
);
2141 static_range_type
->bounds ()->flag_bound_evaluated
= 1;
2142 return static_range_type
;
2145 /* Resolves dynamic bound values of an array or string type TYPE to static
2146 ones. ADDR_STACK is a stack of struct property_addr_info to be used if
2147 needed during the dynamic resolution. */
2149 static struct type
*
2150 resolve_dynamic_array_or_string (struct type
*type
,
2151 struct property_addr_info
*addr_stack
)
2154 struct type
*elt_type
;
2155 struct type
*range_type
;
2156 struct type
*ary_dim
;
2157 struct dynamic_prop
*prop
;
2158 unsigned int bit_stride
= 0;
2160 /* For dynamic type resolution strings can be treated like arrays of
2162 gdb_assert (type
->code () == TYPE_CODE_ARRAY
2163 || type
->code () == TYPE_CODE_STRING
);
2165 type
= copy_type (type
);
2168 range_type
= check_typedef (elt_type
->index_type ());
2169 range_type
= resolve_dynamic_range (range_type
, addr_stack
);
2171 /* Resolve allocated/associated here before creating a new array type, which
2172 will update the length of the array accordingly. */
2173 prop
= TYPE_ALLOCATED_PROP (type
);
2174 if (prop
!= NULL
&& dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2175 prop
->set_const_val (value
);
2177 prop
= TYPE_ASSOCIATED_PROP (type
);
2178 if (prop
!= NULL
&& dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2179 prop
->set_const_val (value
);
2181 ary_dim
= check_typedef (TYPE_TARGET_TYPE (elt_type
));
2183 if (ary_dim
!= NULL
&& ary_dim
->code () == TYPE_CODE_ARRAY
)
2184 elt_type
= resolve_dynamic_array_or_string (ary_dim
, addr_stack
);
2186 elt_type
= TYPE_TARGET_TYPE (type
);
2188 prop
= type
->dyn_prop (DYN_PROP_BYTE_STRIDE
);
2191 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2193 type
->remove_dyn_prop (DYN_PROP_BYTE_STRIDE
);
2194 bit_stride
= (unsigned int) (value
* 8);
2198 /* Could be a bug in our code, but it could also happen
2199 if the DWARF info is not correct. Issue a warning,
2200 and assume no byte/bit stride (leave bit_stride = 0). */
2201 warning (_("cannot determine array stride for type %s"),
2202 type
->name () ? type
->name () : "<no name>");
2206 bit_stride
= TYPE_FIELD_BITSIZE (type
, 0);
2208 return create_array_type_with_stride (type
, elt_type
, range_type
, NULL
,
2212 /* Resolve dynamic bounds of members of the union TYPE to static
2213 bounds. ADDR_STACK is a stack of struct property_addr_info
2214 to be used if needed during the dynamic resolution. */
2216 static struct type
*
2217 resolve_dynamic_union (struct type
*type
,
2218 struct property_addr_info
*addr_stack
)
2220 struct type
*resolved_type
;
2222 unsigned int max_len
= 0;
2224 gdb_assert (type
->code () == TYPE_CODE_UNION
);
2226 resolved_type
= copy_type (type
);
2227 resolved_type
->set_fields
2229 TYPE_ALLOC (resolved_type
,
2230 resolved_type
->num_fields () * sizeof (struct field
)));
2231 memcpy (resolved_type
->fields (),
2233 resolved_type
->num_fields () * sizeof (struct field
));
2234 for (i
= 0; i
< resolved_type
->num_fields (); ++i
)
2238 if (field_is_static (&type
->field (i
)))
2241 t
= resolve_dynamic_type_internal (resolved_type
->field (i
).type (),
2243 resolved_type
->field (i
).set_type (t
);
2245 struct type
*real_type
= check_typedef (t
);
2246 if (TYPE_LENGTH (real_type
) > max_len
)
2247 max_len
= TYPE_LENGTH (real_type
);
2250 TYPE_LENGTH (resolved_type
) = max_len
;
2251 return resolved_type
;
2254 /* See gdbtypes.h. */
2257 variant::matches (ULONGEST value
, bool is_unsigned
) const
2259 for (const discriminant_range
&range
: discriminants
)
2260 if (range
.contains (value
, is_unsigned
))
2266 compute_variant_fields_inner (struct type
*type
,
2267 struct property_addr_info
*addr_stack
,
2268 const variant_part
&part
,
2269 std::vector
<bool> &flags
);
2271 /* A helper function to determine which variant fields will be active.
2272 This handles both the variant's direct fields, and any variant
2273 parts embedded in this variant. TYPE is the type we're examining.
2274 ADDR_STACK holds information about the concrete object. VARIANT is
2275 the current variant to be handled. FLAGS is where the results are
2276 stored -- this function sets the Nth element in FLAGS if the
2277 corresponding field is enabled. ENABLED is whether this variant is
2281 compute_variant_fields_recurse (struct type
*type
,
2282 struct property_addr_info
*addr_stack
,
2283 const variant
&variant
,
2284 std::vector
<bool> &flags
,
2287 for (int field
= variant
.first_field
; field
< variant
.last_field
; ++field
)
2288 flags
[field
] = enabled
;
2290 for (const variant_part
&new_part
: variant
.parts
)
2293 compute_variant_fields_inner (type
, addr_stack
, new_part
, flags
);
2296 for (const auto &sub_variant
: new_part
.variants
)
2297 compute_variant_fields_recurse (type
, addr_stack
, sub_variant
,
2303 /* A helper function to determine which variant fields will be active.
2304 This evaluates the discriminant, decides which variant (if any) is
2305 active, and then updates FLAGS to reflect which fields should be
2306 available. TYPE is the type we're examining. ADDR_STACK holds
2307 information about the concrete object. VARIANT is the current
2308 variant to be handled. FLAGS is where the results are stored --
2309 this function sets the Nth element in FLAGS if the corresponding
2310 field is enabled. */
2313 compute_variant_fields_inner (struct type
*type
,
2314 struct property_addr_info
*addr_stack
,
2315 const variant_part
&part
,
2316 std::vector
<bool> &flags
)
2318 /* Evaluate the discriminant. */
2319 gdb::optional
<ULONGEST
> discr_value
;
2320 if (part
.discriminant_index
!= -1)
2322 int idx
= part
.discriminant_index
;
2324 if (TYPE_FIELD_LOC_KIND (type
, idx
) != FIELD_LOC_KIND_BITPOS
)
2325 error (_("Cannot determine struct field location"
2326 " (invalid location kind)"));
2328 if (addr_stack
->valaddr
.data () != NULL
)
2329 discr_value
= unpack_field_as_long (type
, addr_stack
->valaddr
.data (),
2333 CORE_ADDR addr
= (addr_stack
->addr
2334 + (TYPE_FIELD_BITPOS (type
, idx
)
2335 / TARGET_CHAR_BIT
));
2337 LONGEST bitsize
= TYPE_FIELD_BITSIZE (type
, idx
);
2338 LONGEST size
= bitsize
/ 8;
2340 size
= TYPE_LENGTH (type
->field (idx
).type ());
2342 gdb_byte bits
[sizeof (ULONGEST
)];
2343 read_memory (addr
, bits
, size
);
2345 LONGEST bitpos
= (TYPE_FIELD_BITPOS (type
, idx
)
2348 discr_value
= unpack_bits_as_long (type
->field (idx
).type (),
2349 bits
, bitpos
, bitsize
);
2353 /* Go through each variant and see which applies. */
2354 const variant
*default_variant
= nullptr;
2355 const variant
*applied_variant
= nullptr;
2356 for (const auto &variant
: part
.variants
)
2358 if (variant
.is_default ())
2359 default_variant
= &variant
;
2360 else if (discr_value
.has_value ()
2361 && variant
.matches (*discr_value
, part
.is_unsigned
))
2363 applied_variant
= &variant
;
2367 if (applied_variant
== nullptr)
2368 applied_variant
= default_variant
;
2370 for (const auto &variant
: part
.variants
)
2371 compute_variant_fields_recurse (type
, addr_stack
, variant
,
2372 flags
, applied_variant
== &variant
);
2375 /* Determine which variant fields are available in TYPE. The enabled
2376 fields are stored in RESOLVED_TYPE. ADDR_STACK holds information
2377 about the concrete object. PARTS describes the top-level variant
2378 parts for this type. */
2381 compute_variant_fields (struct type
*type
,
2382 struct type
*resolved_type
,
2383 struct property_addr_info
*addr_stack
,
2384 const gdb::array_view
<variant_part
> &parts
)
2386 /* Assume all fields are included by default. */
2387 std::vector
<bool> flags (resolved_type
->num_fields (), true);
2389 /* Now disable fields based on the variants that control them. */
2390 for (const auto &part
: parts
)
2391 compute_variant_fields_inner (type
, addr_stack
, part
, flags
);
2393 resolved_type
->set_num_fields
2394 (std::count (flags
.begin (), flags
.end (), true));
2395 resolved_type
->set_fields
2397 TYPE_ALLOC (resolved_type
,
2398 resolved_type
->num_fields () * sizeof (struct field
)));
2401 for (int i
= 0; i
< type
->num_fields (); ++i
)
2406 resolved_type
->field (out
) = type
->field (i
);
2411 /* Resolve dynamic bounds of members of the struct TYPE to static
2412 bounds. ADDR_STACK is a stack of struct property_addr_info to
2413 be used if needed during the dynamic resolution. */
2415 static struct type
*
2416 resolve_dynamic_struct (struct type
*type
,
2417 struct property_addr_info
*addr_stack
)
2419 struct type
*resolved_type
;
2421 unsigned resolved_type_bit_length
= 0;
2423 gdb_assert (type
->code () == TYPE_CODE_STRUCT
);
2424 gdb_assert (type
->num_fields () > 0);
2426 resolved_type
= copy_type (type
);
2428 dynamic_prop
*variant_prop
= resolved_type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
2429 if (variant_prop
!= nullptr && variant_prop
->kind () == PROP_VARIANT_PARTS
)
2431 compute_variant_fields (type
, resolved_type
, addr_stack
,
2432 *variant_prop
->variant_parts ());
2433 /* We want to leave the property attached, so that the Rust code
2434 can tell whether the type was originally an enum. */
2435 variant_prop
->set_original_type (type
);
2439 resolved_type
->set_fields
2441 TYPE_ALLOC (resolved_type
,
2442 resolved_type
->num_fields () * sizeof (struct field
)));
2443 memcpy (resolved_type
->fields (),
2445 resolved_type
->num_fields () * sizeof (struct field
));
2448 for (i
= 0; i
< resolved_type
->num_fields (); ++i
)
2450 unsigned new_bit_length
;
2451 struct property_addr_info pinfo
;
2453 if (field_is_static (&resolved_type
->field (i
)))
2456 if (TYPE_FIELD_LOC_KIND (resolved_type
, i
) == FIELD_LOC_KIND_DWARF_BLOCK
)
2458 struct dwarf2_property_baton baton
;
2460 = lookup_pointer_type (resolved_type
->field (i
).type ());
2461 baton
.locexpr
= *TYPE_FIELD_DWARF_BLOCK (resolved_type
, i
);
2463 struct dynamic_prop prop
;
2464 prop
.set_locexpr (&baton
);
2467 if (dwarf2_evaluate_property (&prop
, nullptr, addr_stack
, &addr
,
2469 SET_FIELD_BITPOS (resolved_type
->field (i
),
2470 TARGET_CHAR_BIT
* (addr
- addr_stack
->addr
));
2473 /* As we know this field is not a static field, the field's
2474 field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
2475 this is the case, but only trigger a simple error rather
2476 than an internal error if that fails. While failing
2477 that verification indicates a bug in our code, the error
2478 is not severe enough to suggest to the user he stops
2479 his debugging session because of it. */
2480 if (TYPE_FIELD_LOC_KIND (resolved_type
, i
) != FIELD_LOC_KIND_BITPOS
)
2481 error (_("Cannot determine struct field location"
2482 " (invalid location kind)"));
2484 pinfo
.type
= check_typedef (resolved_type
->field (i
).type ());
2485 pinfo
.valaddr
= addr_stack
->valaddr
;
2488 + (TYPE_FIELD_BITPOS (resolved_type
, i
) / TARGET_CHAR_BIT
));
2489 pinfo
.next
= addr_stack
;
2491 resolved_type
->field (i
).set_type
2492 (resolve_dynamic_type_internal (resolved_type
->field (i
).type (),
2494 gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type
, i
)
2495 == FIELD_LOC_KIND_BITPOS
);
2497 new_bit_length
= TYPE_FIELD_BITPOS (resolved_type
, i
);
2498 if (TYPE_FIELD_BITSIZE (resolved_type
, i
) != 0)
2499 new_bit_length
+= TYPE_FIELD_BITSIZE (resolved_type
, i
);
2502 struct type
*real_type
2503 = check_typedef (resolved_type
->field (i
).type ());
2505 new_bit_length
+= (TYPE_LENGTH (real_type
) * TARGET_CHAR_BIT
);
2508 /* Normally, we would use the position and size of the last field
2509 to determine the size of the enclosing structure. But GCC seems
2510 to be encoding the position of some fields incorrectly when
2511 the struct contains a dynamic field that is not placed last.
2512 So we compute the struct size based on the field that has
2513 the highest position + size - probably the best we can do. */
2514 if (new_bit_length
> resolved_type_bit_length
)
2515 resolved_type_bit_length
= new_bit_length
;
2518 /* The length of a type won't change for fortran, but it does for C and Ada.
2519 For fortran the size of dynamic fields might change over time but not the
2520 type length of the structure. If we adapt it, we run into problems
2521 when calculating the element offset for arrays of structs. */
2522 if (current_language
->la_language
!= language_fortran
)
2523 TYPE_LENGTH (resolved_type
)
2524 = (resolved_type_bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2526 /* The Ada language uses this field as a cache for static fixed types: reset
2527 it as RESOLVED_TYPE must have its own static fixed type. */
2528 TYPE_TARGET_TYPE (resolved_type
) = NULL
;
2530 return resolved_type
;
2533 /* Worker for resolved_dynamic_type. */
2535 static struct type
*
2536 resolve_dynamic_type_internal (struct type
*type
,
2537 struct property_addr_info
*addr_stack
,
2540 struct type
*real_type
= check_typedef (type
);
2541 struct type
*resolved_type
= nullptr;
2542 struct dynamic_prop
*prop
;
2545 if (!is_dynamic_type_internal (real_type
, top_level
))
2548 gdb::optional
<CORE_ADDR
> type_length
;
2549 prop
= TYPE_DYNAMIC_LENGTH (type
);
2551 && dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2552 type_length
= value
;
2554 if (type
->code () == TYPE_CODE_TYPEDEF
)
2556 resolved_type
= copy_type (type
);
2557 TYPE_TARGET_TYPE (resolved_type
)
2558 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type
), addr_stack
,
2563 /* Before trying to resolve TYPE, make sure it is not a stub. */
2566 switch (type
->code ())
2570 struct property_addr_info pinfo
;
2572 pinfo
.type
= check_typedef (TYPE_TARGET_TYPE (type
));
2574 if (addr_stack
->valaddr
.data () != NULL
)
2575 pinfo
.addr
= extract_typed_address (addr_stack
->valaddr
.data (),
2578 pinfo
.addr
= read_memory_typed_address (addr_stack
->addr
, type
);
2579 pinfo
.next
= addr_stack
;
2581 resolved_type
= copy_type (type
);
2582 TYPE_TARGET_TYPE (resolved_type
)
2583 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type
),
2588 case TYPE_CODE_STRING
:
2589 /* Strings are very much like an array of characters, and can be
2590 treated as one here. */
2591 case TYPE_CODE_ARRAY
:
2592 resolved_type
= resolve_dynamic_array_or_string (type
, addr_stack
);
2595 case TYPE_CODE_RANGE
:
2596 resolved_type
= resolve_dynamic_range (type
, addr_stack
);
2599 case TYPE_CODE_UNION
:
2600 resolved_type
= resolve_dynamic_union (type
, addr_stack
);
2603 case TYPE_CODE_STRUCT
:
2604 resolved_type
= resolve_dynamic_struct (type
, addr_stack
);
2609 if (resolved_type
== nullptr)
2612 if (type_length
.has_value ())
2614 TYPE_LENGTH (resolved_type
) = *type_length
;
2615 resolved_type
->remove_dyn_prop (DYN_PROP_BYTE_SIZE
);
2618 /* Resolve data_location attribute. */
2619 prop
= TYPE_DATA_LOCATION (resolved_type
);
2621 && dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2622 prop
->set_const_val (value
);
2624 return resolved_type
;
2627 /* See gdbtypes.h */
2630 resolve_dynamic_type (struct type
*type
,
2631 gdb::array_view
<const gdb_byte
> valaddr
,
2634 struct property_addr_info pinfo
2635 = {check_typedef (type
), valaddr
, addr
, NULL
};
2637 return resolve_dynamic_type_internal (type
, &pinfo
, 1);
2640 /* See gdbtypes.h */
2643 type::dyn_prop (dynamic_prop_node_kind prop_kind
) const
2645 dynamic_prop_list
*node
= this->main_type
->dyn_prop_list
;
2647 while (node
!= NULL
)
2649 if (node
->prop_kind
== prop_kind
)
2656 /* See gdbtypes.h */
2659 type::add_dyn_prop (dynamic_prop_node_kind prop_kind
, dynamic_prop prop
)
2661 struct dynamic_prop_list
*temp
;
2663 gdb_assert (TYPE_OBJFILE_OWNED (this));
2665 temp
= XOBNEW (&TYPE_OBJFILE (this)->objfile_obstack
,
2666 struct dynamic_prop_list
);
2667 temp
->prop_kind
= prop_kind
;
2669 temp
->next
= this->main_type
->dyn_prop_list
;
2671 this->main_type
->dyn_prop_list
= temp
;
2674 /* See gdbtypes.h. */
2677 type::remove_dyn_prop (dynamic_prop_node_kind kind
)
2679 struct dynamic_prop_list
*prev_node
, *curr_node
;
2681 curr_node
= this->main_type
->dyn_prop_list
;
2684 while (NULL
!= curr_node
)
2686 if (curr_node
->prop_kind
== kind
)
2688 /* Update the linked list but don't free anything.
2689 The property was allocated on objstack and it is not known
2690 if we are on top of it. Nevertheless, everything is released
2691 when the complete objstack is freed. */
2692 if (NULL
== prev_node
)
2693 this->main_type
->dyn_prop_list
= curr_node
->next
;
2695 prev_node
->next
= curr_node
->next
;
2700 prev_node
= curr_node
;
2701 curr_node
= curr_node
->next
;
2705 /* Find the real type of TYPE. This function returns the real type,
2706 after removing all layers of typedefs, and completing opaque or stub
2707 types. Completion changes the TYPE argument, but stripping of
2710 Instance flags (e.g. const/volatile) are preserved as typedefs are
2711 stripped. If necessary a new qualified form of the underlying type
2714 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
2715 not been computed and we're either in the middle of reading symbols, or
2716 there was no name for the typedef in the debug info.
2718 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
2719 QUITs in the symbol reading code can also throw.
2720 Thus this function can throw an exception.
2722 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
2725 If this is a stubbed struct (i.e. declared as struct foo *), see if
2726 we can find a full definition in some other file. If so, copy this
2727 definition, so we can use it in future. There used to be a comment
2728 (but not any code) that if we don't find a full definition, we'd
2729 set a flag so we don't spend time in the future checking the same
2730 type. That would be a mistake, though--we might load in more
2731 symbols which contain a full definition for the type. */
2734 check_typedef (struct type
*type
)
2736 struct type
*orig_type
= type
;
2737 /* While we're removing typedefs, we don't want to lose qualifiers.
2738 E.g., const/volatile. */
2739 int instance_flags
= TYPE_INSTANCE_FLAGS (type
);
2743 while (type
->code () == TYPE_CODE_TYPEDEF
)
2745 if (!TYPE_TARGET_TYPE (type
))
2750 /* It is dangerous to call lookup_symbol if we are currently
2751 reading a symtab. Infinite recursion is one danger. */
2752 if (currently_reading_symtab
)
2753 return make_qualified_type (type
, instance_flags
, NULL
);
2755 name
= type
->name ();
2756 /* FIXME: shouldn't we look in STRUCT_DOMAIN and/or
2757 VAR_DOMAIN as appropriate? */
2760 stub_noname_complaint ();
2761 return make_qualified_type (type
, instance_flags
, NULL
);
2763 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0).symbol
;
2765 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
2766 else /* TYPE_CODE_UNDEF */
2767 TYPE_TARGET_TYPE (type
) = alloc_type_arch (get_type_arch (type
));
2769 type
= TYPE_TARGET_TYPE (type
);
2771 /* Preserve the instance flags as we traverse down the typedef chain.
2773 Handling address spaces/classes is nasty, what do we do if there's a
2775 E.g., what if an outer typedef marks the type as class_1 and an inner
2776 typedef marks the type as class_2?
2777 This is the wrong place to do such error checking. We leave it to
2778 the code that created the typedef in the first place to flag the
2779 error. We just pick the outer address space (akin to letting the
2780 outer cast in a chain of casting win), instead of assuming
2781 "it can't happen". */
2783 const int ALL_SPACES
= (TYPE_INSTANCE_FLAG_CODE_SPACE
2784 | TYPE_INSTANCE_FLAG_DATA_SPACE
);
2785 const int ALL_CLASSES
= TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
;
2786 int new_instance_flags
= TYPE_INSTANCE_FLAGS (type
);
2788 /* Treat code vs data spaces and address classes separately. */
2789 if ((instance_flags
& ALL_SPACES
) != 0)
2790 new_instance_flags
&= ~ALL_SPACES
;
2791 if ((instance_flags
& ALL_CLASSES
) != 0)
2792 new_instance_flags
&= ~ALL_CLASSES
;
2794 instance_flags
|= new_instance_flags
;
2798 /* If this is a struct/class/union with no fields, then check
2799 whether a full definition exists somewhere else. This is for
2800 systems where a type definition with no fields is issued for such
2801 types, instead of identifying them as stub types in the first
2804 if (TYPE_IS_OPAQUE (type
)
2805 && opaque_type_resolution
2806 && !currently_reading_symtab
)
2808 const char *name
= type
->name ();
2809 struct type
*newtype
;
2813 stub_noname_complaint ();
2814 return make_qualified_type (type
, instance_flags
, NULL
);
2816 newtype
= lookup_transparent_type (name
);
2820 /* If the resolved type and the stub are in the same
2821 objfile, then replace the stub type with the real deal.
2822 But if they're in separate objfiles, leave the stub
2823 alone; we'll just look up the transparent type every time
2824 we call check_typedef. We can't create pointers between
2825 types allocated to different objfiles, since they may
2826 have different lifetimes. Trying to copy NEWTYPE over to
2827 TYPE's objfile is pointless, too, since you'll have to
2828 move over any other types NEWTYPE refers to, which could
2829 be an unbounded amount of stuff. */
2830 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
2831 type
= make_qualified_type (newtype
,
2832 TYPE_INSTANCE_FLAGS (type
),
2838 /* Otherwise, rely on the stub flag being set for opaque/stubbed
2840 else if (type
->is_stub () && !currently_reading_symtab
)
2842 const char *name
= type
->name ();
2843 /* FIXME: shouldn't we look in STRUCT_DOMAIN and/or VAR_DOMAIN
2849 stub_noname_complaint ();
2850 return make_qualified_type (type
, instance_flags
, NULL
);
2852 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0).symbol
;
2855 /* Same as above for opaque types, we can replace the stub
2856 with the complete type only if they are in the same
2858 if (TYPE_OBJFILE (SYMBOL_TYPE (sym
)) == TYPE_OBJFILE (type
))
2859 type
= make_qualified_type (SYMBOL_TYPE (sym
),
2860 TYPE_INSTANCE_FLAGS (type
),
2863 type
= SYMBOL_TYPE (sym
);
2867 if (type
->target_is_stub ())
2869 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
2871 if (target_type
->is_stub () || target_type
->target_is_stub ())
2873 /* Nothing we can do. */
2875 else if (type
->code () == TYPE_CODE_RANGE
)
2877 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
2878 type
->set_target_is_stub (false);
2880 else if (type
->code () == TYPE_CODE_ARRAY
2881 && update_static_array_size (type
))
2882 type
->set_target_is_stub (false);
2885 type
= make_qualified_type (type
, instance_flags
, NULL
);
2887 /* Cache TYPE_LENGTH for future use. */
2888 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
2893 /* Parse a type expression in the string [P..P+LENGTH). If an error
2894 occurs, silently return a void type. */
2896 static struct type
*
2897 safe_parse_type (struct gdbarch
*gdbarch
, char *p
, int length
)
2899 struct ui_file
*saved_gdb_stderr
;
2900 struct type
*type
= NULL
; /* Initialize to keep gcc happy. */
2902 /* Suppress error messages. */
2903 saved_gdb_stderr
= gdb_stderr
;
2904 gdb_stderr
= &null_stream
;
2906 /* Call parse_and_eval_type() without fear of longjmp()s. */
2909 type
= parse_and_eval_type (p
, length
);
2911 catch (const gdb_exception_error
&except
)
2913 type
= builtin_type (gdbarch
)->builtin_void
;
2916 /* Stop suppressing error messages. */
2917 gdb_stderr
= saved_gdb_stderr
;
2922 /* Ugly hack to convert method stubs into method types.
2924 He ain't kiddin'. This demangles the name of the method into a
2925 string including argument types, parses out each argument type,
2926 generates a string casting a zero to that type, evaluates the
2927 string, and stuffs the resulting type into an argtype vector!!!
2928 Then it knows the type of the whole function (including argument
2929 types for overloading), which info used to be in the stab's but was
2930 removed to hack back the space required for them. */
2933 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
2935 struct gdbarch
*gdbarch
= get_type_arch (type
);
2937 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
2938 char *demangled_name
= gdb_demangle (mangled_name
,
2939 DMGL_PARAMS
| DMGL_ANSI
);
2940 char *argtypetext
, *p
;
2941 int depth
= 0, argcount
= 1;
2942 struct field
*argtypes
;
2945 /* Make sure we got back a function string that we can use. */
2947 p
= strchr (demangled_name
, '(');
2951 if (demangled_name
== NULL
|| p
== NULL
)
2952 error (_("Internal: Cannot demangle mangled name `%s'."),
2955 /* Now, read in the parameters that define this type. */
2960 if (*p
== '(' || *p
== '<')
2964 else if (*p
== ')' || *p
== '>')
2968 else if (*p
== ',' && depth
== 0)
2976 /* If we read one argument and it was ``void'', don't count it. */
2977 if (startswith (argtypetext
, "(void)"))
2980 /* We need one extra slot, for the THIS pointer. */
2982 argtypes
= (struct field
*)
2983 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
2986 /* Add THIS pointer for non-static methods. */
2987 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
2988 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
2992 argtypes
[0].set_type (lookup_pointer_type (type
));
2996 if (*p
!= ')') /* () means no args, skip while. */
3001 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
3003 /* Avoid parsing of ellipsis, they will be handled below.
3004 Also avoid ``void'' as above. */
3005 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
3006 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
3008 argtypes
[argcount
].set_type
3009 (safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
));
3012 argtypetext
= p
+ 1;
3015 if (*p
== '(' || *p
== '<')
3019 else if (*p
== ')' || *p
== '>')
3028 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
3030 /* Now update the old "stub" type into a real type. */
3031 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
3032 /* MTYPE may currently be a function (TYPE_CODE_FUNC).
3033 We want a method (TYPE_CODE_METHOD). */
3034 smash_to_method_type (mtype
, type
, TYPE_TARGET_TYPE (mtype
),
3035 argtypes
, argcount
, p
[-2] == '.');
3036 mtype
->set_is_stub (false);
3037 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
3039 xfree (demangled_name
);
3042 /* This is the external interface to check_stub_method, above. This
3043 function unstubs all of the signatures for TYPE's METHOD_ID method
3044 name. After calling this function TYPE_FN_FIELD_STUB will be
3045 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
3048 This function unfortunately can not die until stabs do. */
3051 check_stub_method_group (struct type
*type
, int method_id
)
3053 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
3054 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
3056 for (int j
= 0; j
< len
; j
++)
3058 if (TYPE_FN_FIELD_STUB (f
, j
))
3059 check_stub_method (type
, method_id
, j
);
3063 /* Ensure it is in .rodata (if available) by working around GCC PR 44690. */
3064 const struct cplus_struct_type cplus_struct_default
= { };
3067 allocate_cplus_struct_type (struct type
*type
)
3069 if (HAVE_CPLUS_STRUCT (type
))
3070 /* Structure was already allocated. Nothing more to do. */
3073 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_CPLUS_STUFF
;
3074 TYPE_RAW_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
3075 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
3076 *(TYPE_RAW_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
3077 set_type_vptr_fieldno (type
, -1);
3080 const struct gnat_aux_type gnat_aux_default
=
3083 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
3084 and allocate the associated gnat-specific data. The gnat-specific
3085 data is also initialized to gnat_aux_default. */
3088 allocate_gnat_aux_type (struct type
*type
)
3090 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_GNAT_STUFF
;
3091 TYPE_GNAT_SPECIFIC (type
) = (struct gnat_aux_type
*)
3092 TYPE_ALLOC (type
, sizeof (struct gnat_aux_type
));
3093 *(TYPE_GNAT_SPECIFIC (type
)) = gnat_aux_default
;
3096 /* Helper function to initialize a newly allocated type. Set type code
3097 to CODE and initialize the type-specific fields accordingly. */
3100 set_type_code (struct type
*type
, enum type_code code
)
3102 type
->set_code (code
);
3106 case TYPE_CODE_STRUCT
:
3107 case TYPE_CODE_UNION
:
3108 case TYPE_CODE_NAMESPACE
:
3109 INIT_CPLUS_SPECIFIC (type
);
3112 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_FLOATFORMAT
;
3114 case TYPE_CODE_FUNC
:
3115 INIT_FUNC_SPECIFIC (type
);
3120 /* Helper function to verify floating-point format and size.
3121 BIT is the type size in bits; if BIT equals -1, the size is
3122 determined by the floatformat. Returns size to be used. */
3125 verify_floatformat (int bit
, const struct floatformat
*floatformat
)
3127 gdb_assert (floatformat
!= NULL
);
3130 bit
= floatformat
->totalsize
;
3132 gdb_assert (bit
>= 0);
3133 gdb_assert (bit
>= floatformat
->totalsize
);
3138 /* Return the floating-point format for a floating-point variable of
3141 const struct floatformat
*
3142 floatformat_from_type (const struct type
*type
)
3144 gdb_assert (type
->code () == TYPE_CODE_FLT
);
3145 gdb_assert (TYPE_FLOATFORMAT (type
));
3146 return TYPE_FLOATFORMAT (type
);
3149 /* Helper function to initialize the standard scalar types.
3151 If NAME is non-NULL, then it is used to initialize the type name.
3152 Note that NAME is not copied; it is required to have a lifetime at
3153 least as long as OBJFILE. */
3156 init_type (struct objfile
*objfile
, enum type_code code
, int bit
,
3161 type
= alloc_type (objfile
);
3162 set_type_code (type
, code
);
3163 gdb_assert ((bit
% TARGET_CHAR_BIT
) == 0);
3164 TYPE_LENGTH (type
) = bit
/ TARGET_CHAR_BIT
;
3165 type
->set_name (name
);
3170 /* Allocate a TYPE_CODE_ERROR type structure associated with OBJFILE,
3171 to use with variables that have no debug info. NAME is the type
3174 static struct type
*
3175 init_nodebug_var_type (struct objfile
*objfile
, const char *name
)
3177 return init_type (objfile
, TYPE_CODE_ERROR
, 0, name
);
3180 /* Allocate a TYPE_CODE_INT type structure associated with OBJFILE.
3181 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3182 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3185 init_integer_type (struct objfile
*objfile
,
3186 int bit
, int unsigned_p
, const char *name
)
3190 t
= init_type (objfile
, TYPE_CODE_INT
, bit
, name
);
3192 t
->set_is_unsigned (true);
3197 /* Allocate a TYPE_CODE_CHAR type structure associated with OBJFILE.
3198 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3199 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3202 init_character_type (struct objfile
*objfile
,
3203 int bit
, int unsigned_p
, const char *name
)
3207 t
= init_type (objfile
, TYPE_CODE_CHAR
, bit
, name
);
3209 t
->set_is_unsigned (true);
3214 /* Allocate a TYPE_CODE_BOOL type structure associated with OBJFILE.
3215 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3216 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3219 init_boolean_type (struct objfile
*objfile
,
3220 int bit
, int unsigned_p
, const char *name
)
3224 t
= init_type (objfile
, TYPE_CODE_BOOL
, bit
, name
);
3226 t
->set_is_unsigned (true);
3231 /* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
3232 BIT is the type size in bits; if BIT equals -1, the size is
3233 determined by the floatformat. NAME is the type name. Set the
3234 TYPE_FLOATFORMAT from FLOATFORMATS. BYTE_ORDER is the byte order
3235 to use. If it is BFD_ENDIAN_UNKNOWN (the default), then the byte
3236 order of the objfile's architecture is used. */
3239 init_float_type (struct objfile
*objfile
,
3240 int bit
, const char *name
,
3241 const struct floatformat
**floatformats
,
3242 enum bfd_endian byte_order
)
3244 if (byte_order
== BFD_ENDIAN_UNKNOWN
)
3246 struct gdbarch
*gdbarch
= objfile
->arch ();
3247 byte_order
= gdbarch_byte_order (gdbarch
);
3249 const struct floatformat
*fmt
= floatformats
[byte_order
];
3252 bit
= verify_floatformat (bit
, fmt
);
3253 t
= init_type (objfile
, TYPE_CODE_FLT
, bit
, name
);
3254 TYPE_FLOATFORMAT (t
) = fmt
;
3259 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with OBJFILE.
3260 BIT is the type size in bits. NAME is the type name. */
3263 init_decfloat_type (struct objfile
*objfile
, int bit
, const char *name
)
3267 t
= init_type (objfile
, TYPE_CODE_DECFLOAT
, bit
, name
);
3271 /* Allocate a TYPE_CODE_COMPLEX type structure. NAME is the type
3272 name. TARGET_TYPE is the component type. */
3275 init_complex_type (const char *name
, struct type
*target_type
)
3279 gdb_assert (target_type
->code () == TYPE_CODE_INT
3280 || target_type
->code () == TYPE_CODE_FLT
);
3282 if (TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
== nullptr)
3284 if (name
== nullptr)
3287 = (char *) TYPE_ALLOC (target_type
,
3288 strlen (target_type
->name ())
3289 + strlen ("_Complex ") + 1);
3290 strcpy (new_name
, "_Complex ");
3291 strcat (new_name
, target_type
->name ());
3295 t
= alloc_type_copy (target_type
);
3296 set_type_code (t
, TYPE_CODE_COMPLEX
);
3297 TYPE_LENGTH (t
) = 2 * TYPE_LENGTH (target_type
);
3300 TYPE_TARGET_TYPE (t
) = target_type
;
3301 TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
= t
;
3304 return TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
;
3307 /* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE.
3308 BIT is the pointer type size in bits. NAME is the type name.
3309 TARGET_TYPE is the pointer target type. Always sets the pointer type's
3310 TYPE_UNSIGNED flag. */
3313 init_pointer_type (struct objfile
*objfile
,
3314 int bit
, const char *name
, struct type
*target_type
)
3318 t
= init_type (objfile
, TYPE_CODE_PTR
, bit
, name
);
3319 TYPE_TARGET_TYPE (t
) = target_type
;
3320 t
->set_is_unsigned (true);
3324 /* See gdbtypes.h. */
3327 type_raw_align (struct type
*type
)
3329 if (type
->align_log2
!= 0)
3330 return 1 << (type
->align_log2
- 1);
3334 /* See gdbtypes.h. */
3337 type_align (struct type
*type
)
3339 /* Check alignment provided in the debug information. */
3340 unsigned raw_align
= type_raw_align (type
);
3344 /* Allow the architecture to provide an alignment. */
3345 struct gdbarch
*arch
= get_type_arch (type
);
3346 ULONGEST align
= gdbarch_type_align (arch
, type
);
3350 switch (type
->code ())
3353 case TYPE_CODE_FUNC
:
3354 case TYPE_CODE_FLAGS
:
3356 case TYPE_CODE_RANGE
:
3358 case TYPE_CODE_ENUM
:
3360 case TYPE_CODE_RVALUE_REF
:
3361 case TYPE_CODE_CHAR
:
3362 case TYPE_CODE_BOOL
:
3363 case TYPE_CODE_DECFLOAT
:
3364 case TYPE_CODE_METHODPTR
:
3365 case TYPE_CODE_MEMBERPTR
:
3366 align
= type_length_units (check_typedef (type
));
3369 case TYPE_CODE_ARRAY
:
3370 case TYPE_CODE_COMPLEX
:
3371 case TYPE_CODE_TYPEDEF
:
3372 align
= type_align (TYPE_TARGET_TYPE (type
));
3375 case TYPE_CODE_STRUCT
:
3376 case TYPE_CODE_UNION
:
3378 int number_of_non_static_fields
= 0;
3379 for (unsigned i
= 0; i
< type
->num_fields (); ++i
)
3381 if (!field_is_static (&type
->field (i
)))
3383 number_of_non_static_fields
++;
3384 ULONGEST f_align
= type_align (type
->field (i
).type ());
3387 /* Don't pretend we know something we don't. */
3391 if (f_align
> align
)
3395 /* A struct with no fields, or with only static fields has an
3397 if (number_of_non_static_fields
== 0)
3403 case TYPE_CODE_STRING
:
3404 /* Not sure what to do here, and these can't appear in C or C++
3408 case TYPE_CODE_VOID
:
3412 case TYPE_CODE_ERROR
:
3413 case TYPE_CODE_METHOD
:
3418 if ((align
& (align
- 1)) != 0)
3420 /* Not a power of 2, so pass. */
3427 /* See gdbtypes.h. */
3430 set_type_align (struct type
*type
, ULONGEST align
)
3432 /* Must be a power of 2. Zero is ok. */
3433 gdb_assert ((align
& (align
- 1)) == 0);
3435 unsigned result
= 0;
3442 if (result
>= (1 << TYPE_ALIGN_BITS
))
3445 type
->align_log2
= result
;
3450 /* Queries on types. */
3453 can_dereference (struct type
*t
)
3455 /* FIXME: Should we return true for references as well as
3457 t
= check_typedef (t
);
3460 && t
->code () == TYPE_CODE_PTR
3461 && TYPE_TARGET_TYPE (t
)->code () != TYPE_CODE_VOID
);
3465 is_integral_type (struct type
*t
)
3467 t
= check_typedef (t
);
3470 && ((t
->code () == TYPE_CODE_INT
)
3471 || (t
->code () == TYPE_CODE_ENUM
)
3472 || (t
->code () == TYPE_CODE_FLAGS
)
3473 || (t
->code () == TYPE_CODE_CHAR
)
3474 || (t
->code () == TYPE_CODE_RANGE
)
3475 || (t
->code () == TYPE_CODE_BOOL
)));
3479 is_floating_type (struct type
*t
)
3481 t
= check_typedef (t
);
3484 && ((t
->code () == TYPE_CODE_FLT
)
3485 || (t
->code () == TYPE_CODE_DECFLOAT
)));
3488 /* Return true if TYPE is scalar. */
3491 is_scalar_type (struct type
*type
)
3493 type
= check_typedef (type
);
3495 switch (type
->code ())
3497 case TYPE_CODE_ARRAY
:
3498 case TYPE_CODE_STRUCT
:
3499 case TYPE_CODE_UNION
:
3501 case TYPE_CODE_STRING
:
3508 /* Return true if T is scalar, or a composite type which in practice has
3509 the memory layout of a scalar type. E.g., an array or struct with only
3510 one scalar element inside it, or a union with only scalar elements. */
3513 is_scalar_type_recursive (struct type
*t
)
3515 t
= check_typedef (t
);
3517 if (is_scalar_type (t
))
3519 /* Are we dealing with an array or string of known dimensions? */
3520 else if ((t
->code () == TYPE_CODE_ARRAY
3521 || t
->code () == TYPE_CODE_STRING
) && t
->num_fields () == 1
3522 && t
->index_type ()->code () == TYPE_CODE_RANGE
)
3524 LONGEST low_bound
, high_bound
;
3525 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (t
));
3527 get_discrete_bounds (t
->index_type (), &low_bound
, &high_bound
);
3529 return high_bound
== low_bound
&& is_scalar_type_recursive (elt_type
);
3531 /* Are we dealing with a struct with one element? */
3532 else if (t
->code () == TYPE_CODE_STRUCT
&& t
->num_fields () == 1)
3533 return is_scalar_type_recursive (t
->field (0).type ());
3534 else if (t
->code () == TYPE_CODE_UNION
)
3536 int i
, n
= t
->num_fields ();
3538 /* If all elements of the union are scalar, then the union is scalar. */
3539 for (i
= 0; i
< n
; i
++)
3540 if (!is_scalar_type_recursive (t
->field (i
).type ()))
3549 /* Return true is T is a class or a union. False otherwise. */
3552 class_or_union_p (const struct type
*t
)
3554 return (t
->code () == TYPE_CODE_STRUCT
3555 || t
->code () == TYPE_CODE_UNION
);
3558 /* A helper function which returns true if types A and B represent the
3559 "same" class type. This is true if the types have the same main
3560 type, or the same name. */
3563 class_types_same_p (const struct type
*a
, const struct type
*b
)
3565 return (TYPE_MAIN_TYPE (a
) == TYPE_MAIN_TYPE (b
)
3566 || (a
->name () && b
->name ()
3567 && !strcmp (a
->name (), b
->name ())));
3570 /* If BASE is an ancestor of DCLASS return the distance between them.
3571 otherwise return -1;
3575 class B: public A {};
3576 class C: public B {};
3579 distance_to_ancestor (A, A, 0) = 0
3580 distance_to_ancestor (A, B, 0) = 1
3581 distance_to_ancestor (A, C, 0) = 2
3582 distance_to_ancestor (A, D, 0) = 3
3584 If PUBLIC is 1 then only public ancestors are considered,
3585 and the function returns the distance only if BASE is a public ancestor
3589 distance_to_ancestor (A, D, 1) = -1. */
3592 distance_to_ancestor (struct type
*base
, struct type
*dclass
, int is_public
)
3597 base
= check_typedef (base
);
3598 dclass
= check_typedef (dclass
);
3600 if (class_types_same_p (base
, dclass
))
3603 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
3605 if (is_public
&& ! BASETYPE_VIA_PUBLIC (dclass
, i
))
3608 d
= distance_to_ancestor (base
, TYPE_BASECLASS (dclass
, i
), is_public
);
3616 /* Check whether BASE is an ancestor or base class or DCLASS
3617 Return 1 if so, and 0 if not.
3618 Note: If BASE and DCLASS are of the same type, this function
3619 will return 1. So for some class A, is_ancestor (A, A) will
3623 is_ancestor (struct type
*base
, struct type
*dclass
)
3625 return distance_to_ancestor (base
, dclass
, 0) >= 0;
3628 /* Like is_ancestor, but only returns true when BASE is a public
3629 ancestor of DCLASS. */
3632 is_public_ancestor (struct type
*base
, struct type
*dclass
)
3634 return distance_to_ancestor (base
, dclass
, 1) >= 0;
3637 /* A helper function for is_unique_ancestor. */
3640 is_unique_ancestor_worker (struct type
*base
, struct type
*dclass
,
3642 const gdb_byte
*valaddr
, int embedded_offset
,
3643 CORE_ADDR address
, struct value
*val
)
3647 base
= check_typedef (base
);
3648 dclass
= check_typedef (dclass
);
3650 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
) && count
< 2; ++i
)
3655 iter
= check_typedef (TYPE_BASECLASS (dclass
, i
));
3657 this_offset
= baseclass_offset (dclass
, i
, valaddr
, embedded_offset
,
3660 if (class_types_same_p (base
, iter
))
3662 /* If this is the first subclass, set *OFFSET and set count
3663 to 1. Otherwise, if this is at the same offset as
3664 previous instances, do nothing. Otherwise, increment
3668 *offset
= this_offset
;
3671 else if (this_offset
== *offset
)
3679 count
+= is_unique_ancestor_worker (base
, iter
, offset
,
3681 embedded_offset
+ this_offset
,
3688 /* Like is_ancestor, but only returns true if BASE is a unique base
3689 class of the type of VAL. */
3692 is_unique_ancestor (struct type
*base
, struct value
*val
)
3696 return is_unique_ancestor_worker (base
, value_type (val
), &offset
,
3697 value_contents_for_printing (val
),
3698 value_embedded_offset (val
),
3699 value_address (val
), val
) == 1;
3702 /* See gdbtypes.h. */
3705 type_byte_order (const struct type
*type
)
3707 bfd_endian byteorder
= gdbarch_byte_order (get_type_arch (type
));
3708 if (TYPE_ENDIANITY_NOT_DEFAULT (type
))
3710 if (byteorder
== BFD_ENDIAN_BIG
)
3711 return BFD_ENDIAN_LITTLE
;
3714 gdb_assert (byteorder
== BFD_ENDIAN_LITTLE
);
3715 return BFD_ENDIAN_BIG
;
3723 /* Overload resolution. */
3725 /* Return the sum of the rank of A with the rank of B. */
3728 sum_ranks (struct rank a
, struct rank b
)
3731 c
.rank
= a
.rank
+ b
.rank
;
3732 c
.subrank
= a
.subrank
+ b
.subrank
;
3736 /* Compare rank A and B and return:
3738 1 if a is better than b
3739 -1 if b is better than a. */
3742 compare_ranks (struct rank a
, struct rank b
)
3744 if (a
.rank
== b
.rank
)
3746 if (a
.subrank
== b
.subrank
)
3748 if (a
.subrank
< b
.subrank
)
3750 if (a
.subrank
> b
.subrank
)
3754 if (a
.rank
< b
.rank
)
3757 /* a.rank > b.rank */
3761 /* Functions for overload resolution begin here. */
3763 /* Compare two badness vectors A and B and return the result.
3764 0 => A and B are identical
3765 1 => A and B are incomparable
3766 2 => A is better than B
3767 3 => A is worse than B */
3770 compare_badness (const badness_vector
&a
, const badness_vector
&b
)
3774 short found_pos
= 0; /* any positives in c? */
3775 short found_neg
= 0; /* any negatives in c? */
3777 /* differing sizes => incomparable */
3778 if (a
.size () != b
.size ())
3781 /* Subtract b from a */
3782 for (i
= 0; i
< a
.size (); i
++)
3784 tmp
= compare_ranks (b
[i
], a
[i
]);
3794 return 1; /* incomparable */
3796 return 3; /* A > B */
3802 return 2; /* A < B */
3804 return 0; /* A == B */
3808 /* Rank a function by comparing its parameter types (PARMS), to the
3809 types of an argument list (ARGS). Return the badness vector. This
3810 has ARGS.size() + 1 entries. */
3813 rank_function (gdb::array_view
<type
*> parms
,
3814 gdb::array_view
<value
*> args
)
3816 /* add 1 for the length-match rank. */
3818 bv
.reserve (1 + args
.size ());
3820 /* First compare the lengths of the supplied lists.
3821 If there is a mismatch, set it to a high value. */
3823 /* pai/1997-06-03 FIXME: when we have debug info about default
3824 arguments and ellipsis parameter lists, we should consider those
3825 and rank the length-match more finely. */
3827 bv
.push_back ((args
.size () != parms
.size ())
3828 ? LENGTH_MISMATCH_BADNESS
3829 : EXACT_MATCH_BADNESS
);
3831 /* Now rank all the parameters of the candidate function. */
3832 size_t min_len
= std::min (parms
.size (), args
.size ());
3834 for (size_t i
= 0; i
< min_len
; i
++)
3835 bv
.push_back (rank_one_type (parms
[i
], value_type (args
[i
]),
3838 /* If more arguments than parameters, add dummy entries. */
3839 for (size_t i
= min_len
; i
< args
.size (); i
++)
3840 bv
.push_back (TOO_FEW_PARAMS_BADNESS
);
3845 /* Compare the names of two integer types, assuming that any sign
3846 qualifiers have been checked already. We do it this way because
3847 there may be an "int" in the name of one of the types. */
3850 integer_types_same_name_p (const char *first
, const char *second
)
3852 int first_p
, second_p
;
3854 /* If both are shorts, return 1; if neither is a short, keep
3856 first_p
= (strstr (first
, "short") != NULL
);
3857 second_p
= (strstr (second
, "short") != NULL
);
3858 if (first_p
&& second_p
)
3860 if (first_p
|| second_p
)
3863 /* Likewise for long. */
3864 first_p
= (strstr (first
, "long") != NULL
);
3865 second_p
= (strstr (second
, "long") != NULL
);
3866 if (first_p
&& second_p
)
3868 if (first_p
|| second_p
)
3871 /* Likewise for char. */
3872 first_p
= (strstr (first
, "char") != NULL
);
3873 second_p
= (strstr (second
, "char") != NULL
);
3874 if (first_p
&& second_p
)
3876 if (first_p
|| second_p
)
3879 /* They must both be ints. */
3883 /* Compares type A to type B. Returns true if they represent the same
3884 type, false otherwise. */
3887 types_equal (struct type
*a
, struct type
*b
)
3889 /* Identical type pointers. */
3890 /* However, this still doesn't catch all cases of same type for b
3891 and a. The reason is that builtin types are different from
3892 the same ones constructed from the object. */
3896 /* Resolve typedefs */
3897 if (a
->code () == TYPE_CODE_TYPEDEF
)
3898 a
= check_typedef (a
);
3899 if (b
->code () == TYPE_CODE_TYPEDEF
)
3900 b
= check_typedef (b
);
3902 /* If after resolving typedefs a and b are not of the same type
3903 code then they are not equal. */
3904 if (a
->code () != b
->code ())
3907 /* If a and b are both pointers types or both reference types then
3908 they are equal of the same type iff the objects they refer to are
3909 of the same type. */
3910 if (a
->code () == TYPE_CODE_PTR
3911 || a
->code () == TYPE_CODE_REF
)
3912 return types_equal (TYPE_TARGET_TYPE (a
),
3913 TYPE_TARGET_TYPE (b
));
3915 /* Well, damnit, if the names are exactly the same, I'll say they
3916 are exactly the same. This happens when we generate method
3917 stubs. The types won't point to the same address, but they
3918 really are the same. */
3920 if (a
->name () && b
->name ()
3921 && strcmp (a
->name (), b
->name ()) == 0)
3924 /* Check if identical after resolving typedefs. */
3928 /* Two function types are equal if their argument and return types
3930 if (a
->code () == TYPE_CODE_FUNC
)
3934 if (a
->num_fields () != b
->num_fields ())
3937 if (!types_equal (TYPE_TARGET_TYPE (a
), TYPE_TARGET_TYPE (b
)))
3940 for (i
= 0; i
< a
->num_fields (); ++i
)
3941 if (!types_equal (a
->field (i
).type (), b
->field (i
).type ()))
3950 /* Deep comparison of types. */
3952 /* An entry in the type-equality bcache. */
3954 struct type_equality_entry
3956 type_equality_entry (struct type
*t1
, struct type
*t2
)
3962 struct type
*type1
, *type2
;
3965 /* A helper function to compare two strings. Returns true if they are
3966 the same, false otherwise. Handles NULLs properly. */
3969 compare_maybe_null_strings (const char *s
, const char *t
)
3971 if (s
== NULL
|| t
== NULL
)
3973 return strcmp (s
, t
) == 0;
3976 /* A helper function for check_types_worklist that checks two types for
3977 "deep" equality. Returns true if the types are considered the
3978 same, false otherwise. */
3981 check_types_equal (struct type
*type1
, struct type
*type2
,
3982 std::vector
<type_equality_entry
> *worklist
)
3984 type1
= check_typedef (type1
);
3985 type2
= check_typedef (type2
);
3990 if (type1
->code () != type2
->code ()
3991 || TYPE_LENGTH (type1
) != TYPE_LENGTH (type2
)
3992 || type1
->is_unsigned () != type2
->is_unsigned ()
3993 || type1
->has_no_signedness () != type2
->has_no_signedness ()
3994 || TYPE_ENDIANITY_NOT_DEFAULT (type1
) != TYPE_ENDIANITY_NOT_DEFAULT (type2
)
3995 || type1
->has_varargs () != type2
->has_varargs ()
3996 || type1
->is_vector () != type2
->is_vector ()
3997 || TYPE_NOTTEXT (type1
) != TYPE_NOTTEXT (type2
)
3998 || TYPE_INSTANCE_FLAGS (type1
) != TYPE_INSTANCE_FLAGS (type2
)
3999 || type1
->num_fields () != type2
->num_fields ())
4002 if (!compare_maybe_null_strings (type1
->name (), type2
->name ()))
4004 if (!compare_maybe_null_strings (type1
->name (), type2
->name ()))
4007 if (type1
->code () == TYPE_CODE_RANGE
)
4009 if (*type1
->bounds () != *type2
->bounds ())
4016 for (i
= 0; i
< type1
->num_fields (); ++i
)
4018 const struct field
*field1
= &type1
->field (i
);
4019 const struct field
*field2
= &type2
->field (i
);
4021 if (FIELD_ARTIFICIAL (*field1
) != FIELD_ARTIFICIAL (*field2
)
4022 || FIELD_BITSIZE (*field1
) != FIELD_BITSIZE (*field2
)
4023 || FIELD_LOC_KIND (*field1
) != FIELD_LOC_KIND (*field2
))
4025 if (!compare_maybe_null_strings (FIELD_NAME (*field1
),
4026 FIELD_NAME (*field2
)))
4028 switch (FIELD_LOC_KIND (*field1
))
4030 case FIELD_LOC_KIND_BITPOS
:
4031 if (FIELD_BITPOS (*field1
) != FIELD_BITPOS (*field2
))
4034 case FIELD_LOC_KIND_ENUMVAL
:
4035 if (FIELD_ENUMVAL (*field1
) != FIELD_ENUMVAL (*field2
))
4038 case FIELD_LOC_KIND_PHYSADDR
:
4039 if (FIELD_STATIC_PHYSADDR (*field1
)
4040 != FIELD_STATIC_PHYSADDR (*field2
))
4043 case FIELD_LOC_KIND_PHYSNAME
:
4044 if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1
),
4045 FIELD_STATIC_PHYSNAME (*field2
)))
4048 case FIELD_LOC_KIND_DWARF_BLOCK
:
4050 struct dwarf2_locexpr_baton
*block1
, *block2
;
4052 block1
= FIELD_DWARF_BLOCK (*field1
);
4053 block2
= FIELD_DWARF_BLOCK (*field2
);
4054 if (block1
->per_cu
!= block2
->per_cu
4055 || block1
->size
!= block2
->size
4056 || memcmp (block1
->data
, block2
->data
, block1
->size
) != 0)
4061 internal_error (__FILE__
, __LINE__
, _("Unsupported field kind "
4062 "%d by check_types_equal"),
4063 FIELD_LOC_KIND (*field1
));
4066 worklist
->emplace_back (field1
->type (), field2
->type ());
4070 if (TYPE_TARGET_TYPE (type1
) != NULL
)
4072 if (TYPE_TARGET_TYPE (type2
) == NULL
)
4075 worklist
->emplace_back (TYPE_TARGET_TYPE (type1
),
4076 TYPE_TARGET_TYPE (type2
));
4078 else if (TYPE_TARGET_TYPE (type2
) != NULL
)
4084 /* Check types on a worklist for equality. Returns false if any pair
4085 is not equal, true if they are all considered equal. */
4088 check_types_worklist (std::vector
<type_equality_entry
> *worklist
,
4091 while (!worklist
->empty ())
4095 struct type_equality_entry entry
= std::move (worklist
->back ());
4096 worklist
->pop_back ();
4098 /* If the type pair has already been visited, we know it is
4100 cache
->insert (&entry
, sizeof (entry
), &added
);
4104 if (!check_types_equal (entry
.type1
, entry
.type2
, worklist
))
4111 /* Return true if types TYPE1 and TYPE2 are equal, as determined by a
4112 "deep comparison". Otherwise return false. */
4115 types_deeply_equal (struct type
*type1
, struct type
*type2
)
4117 std::vector
<type_equality_entry
> worklist
;
4119 gdb_assert (type1
!= NULL
&& type2
!= NULL
);
4121 /* Early exit for the simple case. */
4125 gdb::bcache
cache (nullptr, nullptr);
4126 worklist
.emplace_back (type1
, type2
);
4127 return check_types_worklist (&worklist
, &cache
);
4130 /* Allocated status of type TYPE. Return zero if type TYPE is allocated.
4131 Otherwise return one. */
4134 type_not_allocated (const struct type
*type
)
4136 struct dynamic_prop
*prop
= TYPE_ALLOCATED_PROP (type
);
4138 return (prop
!= nullptr && prop
->kind () == PROP_CONST
4139 && prop
->const_val () == 0);
4142 /* Associated status of type TYPE. Return zero if type TYPE is associated.
4143 Otherwise return one. */
4146 type_not_associated (const struct type
*type
)
4148 struct dynamic_prop
*prop
= TYPE_ASSOCIATED_PROP (type
);
4150 return (prop
!= nullptr && prop
->kind () == PROP_CONST
4151 && prop
->const_val () == 0);
4154 /* rank_one_type helper for when PARM's type code is TYPE_CODE_PTR. */
4157 rank_one_type_parm_ptr (struct type
*parm
, struct type
*arg
, struct value
*value
)
4159 struct rank rank
= {0,0};
4161 switch (arg
->code ())
4165 /* Allowed pointer conversions are:
4166 (a) pointer to void-pointer conversion. */
4167 if (TYPE_TARGET_TYPE (parm
)->code () == TYPE_CODE_VOID
)
4168 return VOID_PTR_CONVERSION_BADNESS
;
4170 /* (b) pointer to ancestor-pointer conversion. */
4171 rank
.subrank
= distance_to_ancestor (TYPE_TARGET_TYPE (parm
),
4172 TYPE_TARGET_TYPE (arg
),
4174 if (rank
.subrank
>= 0)
4175 return sum_ranks (BASE_PTR_CONVERSION_BADNESS
, rank
);
4177 return INCOMPATIBLE_TYPE_BADNESS
;
4178 case TYPE_CODE_ARRAY
:
4180 struct type
*t1
= TYPE_TARGET_TYPE (parm
);
4181 struct type
*t2
= TYPE_TARGET_TYPE (arg
);
4183 if (types_equal (t1
, t2
))
4185 /* Make sure they are CV equal. */
4186 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
4187 rank
.subrank
|= CV_CONVERSION_CONST
;
4188 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
4189 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
4190 if (rank
.subrank
!= 0)
4191 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
4192 return EXACT_MATCH_BADNESS
;
4194 return INCOMPATIBLE_TYPE_BADNESS
;
4196 case TYPE_CODE_FUNC
:
4197 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
, NULL
);
4199 if (value
!= NULL
&& value_type (value
)->code () == TYPE_CODE_INT
)
4201 if (value_as_long (value
) == 0)
4203 /* Null pointer conversion: allow it to be cast to a pointer.
4204 [4.10.1 of C++ standard draft n3290] */
4205 return NULL_POINTER_CONVERSION_BADNESS
;
4209 /* If type checking is disabled, allow the conversion. */
4210 if (!strict_type_checking
)
4211 return NS_INTEGER_POINTER_CONVERSION_BADNESS
;
4215 case TYPE_CODE_ENUM
:
4216 case TYPE_CODE_FLAGS
:
4217 case TYPE_CODE_CHAR
:
4218 case TYPE_CODE_RANGE
:
4219 case TYPE_CODE_BOOL
:
4221 return INCOMPATIBLE_TYPE_BADNESS
;
4225 /* rank_one_type helper for when PARM's type code is TYPE_CODE_ARRAY. */
4228 rank_one_type_parm_array (struct type
*parm
, struct type
*arg
, struct value
*value
)
4230 switch (arg
->code ())
4233 case TYPE_CODE_ARRAY
:
4234 return rank_one_type (TYPE_TARGET_TYPE (parm
),
4235 TYPE_TARGET_TYPE (arg
), NULL
);
4237 return INCOMPATIBLE_TYPE_BADNESS
;
4241 /* rank_one_type helper for when PARM's type code is TYPE_CODE_FUNC. */
4244 rank_one_type_parm_func (struct type
*parm
, struct type
*arg
, struct value
*value
)
4246 switch (arg
->code ())
4248 case TYPE_CODE_PTR
: /* funcptr -> func */
4249 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
), NULL
);
4251 return INCOMPATIBLE_TYPE_BADNESS
;
4255 /* rank_one_type helper for when PARM's type code is TYPE_CODE_INT. */
4258 rank_one_type_parm_int (struct type
*parm
, struct type
*arg
, struct value
*value
)
4260 switch (arg
->code ())
4263 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
4265 /* Deal with signed, unsigned, and plain chars and
4266 signed and unsigned ints. */
4267 if (parm
->has_no_signedness ())
4269 /* This case only for character types. */
4270 if (arg
->has_no_signedness ())
4271 return EXACT_MATCH_BADNESS
; /* plain char -> plain char */
4272 else /* signed/unsigned char -> plain char */
4273 return INTEGER_CONVERSION_BADNESS
;
4275 else if (parm
->is_unsigned ())
4277 if (arg
->is_unsigned ())
4279 /* unsigned int -> unsigned int, or
4280 unsigned long -> unsigned long */
4281 if (integer_types_same_name_p (parm
->name (),
4283 return EXACT_MATCH_BADNESS
;
4284 else if (integer_types_same_name_p (arg
->name (),
4286 && integer_types_same_name_p (parm
->name (),
4288 /* unsigned int -> unsigned long */
4289 return INTEGER_PROMOTION_BADNESS
;
4291 /* unsigned long -> unsigned int */
4292 return INTEGER_CONVERSION_BADNESS
;
4296 if (integer_types_same_name_p (arg
->name (),
4298 && integer_types_same_name_p (parm
->name (),
4300 /* signed long -> unsigned int */
4301 return INTEGER_CONVERSION_BADNESS
;
4303 /* signed int/long -> unsigned int/long */
4304 return INTEGER_CONVERSION_BADNESS
;
4307 else if (!arg
->has_no_signedness () && !arg
->is_unsigned ())
4309 if (integer_types_same_name_p (parm
->name (),
4311 return EXACT_MATCH_BADNESS
;
4312 else if (integer_types_same_name_p (arg
->name (),
4314 && integer_types_same_name_p (parm
->name (),
4316 return INTEGER_PROMOTION_BADNESS
;
4318 return INTEGER_CONVERSION_BADNESS
;
4321 return INTEGER_CONVERSION_BADNESS
;
4323 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
4324 return INTEGER_PROMOTION_BADNESS
;
4326 return INTEGER_CONVERSION_BADNESS
;
4327 case TYPE_CODE_ENUM
:
4328 case TYPE_CODE_FLAGS
:
4329 case TYPE_CODE_CHAR
:
4330 case TYPE_CODE_RANGE
:
4331 case TYPE_CODE_BOOL
:
4332 if (TYPE_DECLARED_CLASS (arg
))
4333 return INCOMPATIBLE_TYPE_BADNESS
;
4334 return INTEGER_PROMOTION_BADNESS
;
4336 return INT_FLOAT_CONVERSION_BADNESS
;
4338 return NS_POINTER_CONVERSION_BADNESS
;
4340 return INCOMPATIBLE_TYPE_BADNESS
;
4344 /* rank_one_type helper for when PARM's type code is TYPE_CODE_ENUM. */
4347 rank_one_type_parm_enum (struct type
*parm
, struct type
*arg
, struct value
*value
)
4349 switch (arg
->code ())
4352 case TYPE_CODE_CHAR
:
4353 case TYPE_CODE_RANGE
:
4354 case TYPE_CODE_BOOL
:
4355 case TYPE_CODE_ENUM
:
4356 if (TYPE_DECLARED_CLASS (parm
) || TYPE_DECLARED_CLASS (arg
))
4357 return INCOMPATIBLE_TYPE_BADNESS
;
4358 return INTEGER_CONVERSION_BADNESS
;
4360 return INT_FLOAT_CONVERSION_BADNESS
;
4362 return INCOMPATIBLE_TYPE_BADNESS
;
4366 /* rank_one_type helper for when PARM's type code is TYPE_CODE_CHAR. */
4369 rank_one_type_parm_char (struct type
*parm
, struct type
*arg
, struct value
*value
)
4371 switch (arg
->code ())
4373 case TYPE_CODE_RANGE
:
4374 case TYPE_CODE_BOOL
:
4375 case TYPE_CODE_ENUM
:
4376 if (TYPE_DECLARED_CLASS (arg
))
4377 return INCOMPATIBLE_TYPE_BADNESS
;
4378 return INTEGER_CONVERSION_BADNESS
;
4380 return INT_FLOAT_CONVERSION_BADNESS
;
4382 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
4383 return INTEGER_CONVERSION_BADNESS
;
4384 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
4385 return INTEGER_PROMOTION_BADNESS
;
4387 case TYPE_CODE_CHAR
:
4388 /* Deal with signed, unsigned, and plain chars for C++ and
4389 with int cases falling through from previous case. */
4390 if (parm
->has_no_signedness ())
4392 if (arg
->has_no_signedness ())
4393 return EXACT_MATCH_BADNESS
;
4395 return INTEGER_CONVERSION_BADNESS
;
4397 else if (parm
->is_unsigned ())
4399 if (arg
->is_unsigned ())
4400 return EXACT_MATCH_BADNESS
;
4402 return INTEGER_PROMOTION_BADNESS
;
4404 else if (!arg
->has_no_signedness () && !arg
->is_unsigned ())
4405 return EXACT_MATCH_BADNESS
;
4407 return INTEGER_CONVERSION_BADNESS
;
4409 return INCOMPATIBLE_TYPE_BADNESS
;
4413 /* rank_one_type helper for when PARM's type code is TYPE_CODE_RANGE. */
4416 rank_one_type_parm_range (struct type
*parm
, struct type
*arg
, struct value
*value
)
4418 switch (arg
->code ())
4421 case TYPE_CODE_CHAR
:
4422 case TYPE_CODE_RANGE
:
4423 case TYPE_CODE_BOOL
:
4424 case TYPE_CODE_ENUM
:
4425 return INTEGER_CONVERSION_BADNESS
;
4427 return INT_FLOAT_CONVERSION_BADNESS
;
4429 return INCOMPATIBLE_TYPE_BADNESS
;
4433 /* rank_one_type helper for when PARM's type code is TYPE_CODE_BOOL. */
4436 rank_one_type_parm_bool (struct type
*parm
, struct type
*arg
, struct value
*value
)
4438 switch (arg
->code ())
4440 /* n3290 draft, section 4.12.1 (conv.bool):
4442 "A prvalue of arithmetic, unscoped enumeration, pointer, or
4443 pointer to member type can be converted to a prvalue of type
4444 bool. A zero value, null pointer value, or null member pointer
4445 value is converted to false; any other value is converted to
4446 true. A prvalue of type std::nullptr_t can be converted to a
4447 prvalue of type bool; the resulting value is false." */
4449 case TYPE_CODE_CHAR
:
4450 case TYPE_CODE_ENUM
:
4452 case TYPE_CODE_MEMBERPTR
:
4454 return BOOL_CONVERSION_BADNESS
;
4455 case TYPE_CODE_RANGE
:
4456 return INCOMPATIBLE_TYPE_BADNESS
;
4457 case TYPE_CODE_BOOL
:
4458 return EXACT_MATCH_BADNESS
;
4460 return INCOMPATIBLE_TYPE_BADNESS
;
4464 /* rank_one_type helper for when PARM's type code is TYPE_CODE_FLOAT. */
4467 rank_one_type_parm_float (struct type
*parm
, struct type
*arg
, struct value
*value
)
4469 switch (arg
->code ())
4472 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
4473 return FLOAT_PROMOTION_BADNESS
;
4474 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
4475 return EXACT_MATCH_BADNESS
;
4477 return FLOAT_CONVERSION_BADNESS
;
4479 case TYPE_CODE_BOOL
:
4480 case TYPE_CODE_ENUM
:
4481 case TYPE_CODE_RANGE
:
4482 case TYPE_CODE_CHAR
:
4483 return INT_FLOAT_CONVERSION_BADNESS
;
4485 return INCOMPATIBLE_TYPE_BADNESS
;
4489 /* rank_one_type helper for when PARM's type code is TYPE_CODE_COMPLEX. */
4492 rank_one_type_parm_complex (struct type
*parm
, struct type
*arg
, struct value
*value
)
4494 switch (arg
->code ())
4495 { /* Strictly not needed for C++, but... */
4497 return FLOAT_PROMOTION_BADNESS
;
4498 case TYPE_CODE_COMPLEX
:
4499 return EXACT_MATCH_BADNESS
;
4501 return INCOMPATIBLE_TYPE_BADNESS
;
4505 /* rank_one_type helper for when PARM's type code is TYPE_CODE_STRUCT. */
4508 rank_one_type_parm_struct (struct type
*parm
, struct type
*arg
, struct value
*value
)
4510 struct rank rank
= {0, 0};
4512 switch (arg
->code ())
4514 case TYPE_CODE_STRUCT
:
4515 /* Check for derivation */
4516 rank
.subrank
= distance_to_ancestor (parm
, arg
, 0);
4517 if (rank
.subrank
>= 0)
4518 return sum_ranks (BASE_CONVERSION_BADNESS
, rank
);
4521 return INCOMPATIBLE_TYPE_BADNESS
;
4525 /* rank_one_type helper for when PARM's type code is TYPE_CODE_SET. */
4528 rank_one_type_parm_set (struct type
*parm
, struct type
*arg
, struct value
*value
)
4530 switch (arg
->code ())
4534 return rank_one_type (parm
->field (0).type (),
4535 arg
->field (0).type (), NULL
);
4537 return INCOMPATIBLE_TYPE_BADNESS
;
4541 /* Compare one type (PARM) for compatibility with another (ARG).
4542 * PARM is intended to be the parameter type of a function; and
4543 * ARG is the supplied argument's type. This function tests if
4544 * the latter can be converted to the former.
4545 * VALUE is the argument's value or NULL if none (or called recursively)
4547 * Return 0 if they are identical types;
4548 * Otherwise, return an integer which corresponds to how compatible
4549 * PARM is to ARG. The higher the return value, the worse the match.
4550 * Generally the "bad" conversions are all uniformly assigned a 100. */
4553 rank_one_type (struct type
*parm
, struct type
*arg
, struct value
*value
)
4555 struct rank rank
= {0,0};
4557 /* Resolve typedefs */
4558 if (parm
->code () == TYPE_CODE_TYPEDEF
)
4559 parm
= check_typedef (parm
);
4560 if (arg
->code () == TYPE_CODE_TYPEDEF
)
4561 arg
= check_typedef (arg
);
4563 if (TYPE_IS_REFERENCE (parm
) && value
!= NULL
)
4565 if (VALUE_LVAL (value
) == not_lval
)
4567 /* Rvalues should preferably bind to rvalue references or const
4568 lvalue references. */
4569 if (parm
->code () == TYPE_CODE_RVALUE_REF
)
4570 rank
.subrank
= REFERENCE_CONVERSION_RVALUE
;
4571 else if (TYPE_CONST (TYPE_TARGET_TYPE (parm
)))
4572 rank
.subrank
= REFERENCE_CONVERSION_CONST_LVALUE
;
4574 return INCOMPATIBLE_TYPE_BADNESS
;
4575 return sum_ranks (rank
, REFERENCE_CONVERSION_BADNESS
);
4579 /* It's illegal to pass an lvalue as an rvalue. */
4580 if (parm
->code () == TYPE_CODE_RVALUE_REF
)
4581 return INCOMPATIBLE_TYPE_BADNESS
;
4585 if (types_equal (parm
, arg
))
4587 struct type
*t1
= parm
;
4588 struct type
*t2
= arg
;
4590 /* For pointers and references, compare target type. */
4591 if (parm
->code () == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (parm
))
4593 t1
= TYPE_TARGET_TYPE (parm
);
4594 t2
= TYPE_TARGET_TYPE (arg
);
4597 /* Make sure they are CV equal, too. */
4598 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
4599 rank
.subrank
|= CV_CONVERSION_CONST
;
4600 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
4601 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
4602 if (rank
.subrank
!= 0)
4603 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
4604 return EXACT_MATCH_BADNESS
;
4607 /* See through references, since we can almost make non-references
4610 if (TYPE_IS_REFERENCE (arg
))
4611 return (sum_ranks (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
), NULL
),
4612 REFERENCE_SEE_THROUGH_BADNESS
));
4613 if (TYPE_IS_REFERENCE (parm
))
4614 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
, NULL
),
4615 REFERENCE_SEE_THROUGH_BADNESS
));
4617 /* Debugging only. */
4618 fprintf_filtered (gdb_stderr
,
4619 "------ Arg is %s [%d], parm is %s [%d]\n",
4620 arg
->name (), arg
->code (),
4621 parm
->name (), parm
->code ());
4623 /* x -> y means arg of type x being supplied for parameter of type y. */
4625 switch (parm
->code ())
4628 return rank_one_type_parm_ptr (parm
, arg
, value
);
4629 case TYPE_CODE_ARRAY
:
4630 return rank_one_type_parm_array (parm
, arg
, value
);
4631 case TYPE_CODE_FUNC
:
4632 return rank_one_type_parm_func (parm
, arg
, value
);
4634 return rank_one_type_parm_int (parm
, arg
, value
);
4635 case TYPE_CODE_ENUM
:
4636 return rank_one_type_parm_enum (parm
, arg
, value
);
4637 case TYPE_CODE_CHAR
:
4638 return rank_one_type_parm_char (parm
, arg
, value
);
4639 case TYPE_CODE_RANGE
:
4640 return rank_one_type_parm_range (parm
, arg
, value
);
4641 case TYPE_CODE_BOOL
:
4642 return rank_one_type_parm_bool (parm
, arg
, value
);
4644 return rank_one_type_parm_float (parm
, arg
, value
);
4645 case TYPE_CODE_COMPLEX
:
4646 return rank_one_type_parm_complex (parm
, arg
, value
);
4647 case TYPE_CODE_STRUCT
:
4648 return rank_one_type_parm_struct (parm
, arg
, value
);
4650 return rank_one_type_parm_set (parm
, arg
, value
);
4652 return INCOMPATIBLE_TYPE_BADNESS
;
4653 } /* switch (arg->code ()) */
4656 /* End of functions for overload resolution. */
4658 /* Routines to pretty-print types. */
4661 print_bit_vector (B_TYPE
*bits
, int nbits
)
4665 for (bitno
= 0; bitno
< nbits
; bitno
++)
4667 if ((bitno
% 8) == 0)
4669 puts_filtered (" ");
4671 if (B_TST (bits
, bitno
))
4672 printf_filtered (("1"));
4674 printf_filtered (("0"));
4678 /* Note the first arg should be the "this" pointer, we may not want to
4679 include it since we may get into a infinitely recursive
4683 print_args (struct field
*args
, int nargs
, int spaces
)
4689 for (i
= 0; i
< nargs
; i
++)
4691 printfi_filtered (spaces
, "[%d] name '%s'\n", i
,
4692 args
[i
].name
!= NULL
? args
[i
].name
: "<NULL>");
4693 recursive_dump_type (args
[i
].type (), spaces
+ 2);
4699 field_is_static (struct field
*f
)
4701 /* "static" fields are the fields whose location is not relative
4702 to the address of the enclosing struct. It would be nice to
4703 have a dedicated flag that would be set for static fields when
4704 the type is being created. But in practice, checking the field
4705 loc_kind should give us an accurate answer. */
4706 return (FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSNAME
4707 || FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSADDR
);
4711 dump_fn_fieldlists (struct type
*type
, int spaces
)
4717 printfi_filtered (spaces
, "fn_fieldlists ");
4718 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
4719 printf_filtered ("\n");
4720 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
4722 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
4723 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
4725 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
4726 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
4728 printf_filtered (_(") length %d\n"),
4729 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
4730 for (overload_idx
= 0;
4731 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
4734 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
4736 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
4737 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
4739 printf_filtered (")\n");
4740 printfi_filtered (spaces
+ 8, "type ");
4741 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
4743 printf_filtered ("\n");
4745 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
4748 printfi_filtered (spaces
+ 8, "args ");
4749 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
4751 printf_filtered ("\n");
4752 print_args (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
4753 TYPE_FN_FIELD_TYPE (f
, overload_idx
)->num_fields (),
4755 printfi_filtered (spaces
+ 8, "fcontext ");
4756 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
4758 printf_filtered ("\n");
4760 printfi_filtered (spaces
+ 8, "is_const %d\n",
4761 TYPE_FN_FIELD_CONST (f
, overload_idx
));
4762 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
4763 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
4764 printfi_filtered (spaces
+ 8, "is_private %d\n",
4765 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
4766 printfi_filtered (spaces
+ 8, "is_protected %d\n",
4767 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
4768 printfi_filtered (spaces
+ 8, "is_stub %d\n",
4769 TYPE_FN_FIELD_STUB (f
, overload_idx
));
4770 printfi_filtered (spaces
+ 8, "defaulted %d\n",
4771 TYPE_FN_FIELD_DEFAULTED (f
, overload_idx
));
4772 printfi_filtered (spaces
+ 8, "is_deleted %d\n",
4773 TYPE_FN_FIELD_DELETED (f
, overload_idx
));
4774 printfi_filtered (spaces
+ 8, "voffset %u\n",
4775 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
4781 print_cplus_stuff (struct type
*type
, int spaces
)
4783 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
4784 printfi_filtered (spaces
, "vptr_basetype ");
4785 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
4786 puts_filtered ("\n");
4787 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
4788 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
4790 printfi_filtered (spaces
, "n_baseclasses %d\n",
4791 TYPE_N_BASECLASSES (type
));
4792 printfi_filtered (spaces
, "nfn_fields %d\n",
4793 TYPE_NFN_FIELDS (type
));
4794 if (TYPE_N_BASECLASSES (type
) > 0)
4796 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
4797 TYPE_N_BASECLASSES (type
));
4798 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
),
4800 printf_filtered (")");
4802 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
4803 TYPE_N_BASECLASSES (type
));
4804 puts_filtered ("\n");
4806 if (type
->num_fields () > 0)
4808 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
4810 printfi_filtered (spaces
,
4811 "private_field_bits (%d bits at *",
4812 type
->num_fields ());
4813 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
),
4815 printf_filtered (")");
4816 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
4817 type
->num_fields ());
4818 puts_filtered ("\n");
4820 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
4822 printfi_filtered (spaces
,
4823 "protected_field_bits (%d bits at *",
4824 type
->num_fields ());
4825 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
),
4827 printf_filtered (")");
4828 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
4829 type
->num_fields ());
4830 puts_filtered ("\n");
4833 if (TYPE_NFN_FIELDS (type
) > 0)
4835 dump_fn_fieldlists (type
, spaces
);
4838 printfi_filtered (spaces
, "calling_convention %d\n",
4839 TYPE_CPLUS_CALLING_CONVENTION (type
));
4842 /* Print the contents of the TYPE's type_specific union, assuming that
4843 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
4846 print_gnat_stuff (struct type
*type
, int spaces
)
4848 struct type
*descriptive_type
= TYPE_DESCRIPTIVE_TYPE (type
);
4850 if (descriptive_type
== NULL
)
4851 printfi_filtered (spaces
+ 2, "no descriptive type\n");
4854 printfi_filtered (spaces
+ 2, "descriptive type\n");
4855 recursive_dump_type (descriptive_type
, spaces
+ 4);
4859 static struct obstack dont_print_type_obstack
;
4861 /* Print the dynamic_prop PROP. */
4864 dump_dynamic_prop (dynamic_prop
const& prop
)
4866 switch (prop
.kind ())
4869 printf_filtered ("%s", plongest (prop
.const_val ()));
4871 case PROP_UNDEFINED
:
4872 printf_filtered ("(undefined)");
4876 printf_filtered ("(dynamic)");
4879 gdb_assert_not_reached ("unhandled prop kind");
4885 recursive_dump_type (struct type
*type
, int spaces
)
4890 obstack_begin (&dont_print_type_obstack
, 0);
4892 if (type
->num_fields () > 0
4893 || (HAVE_CPLUS_STRUCT (type
) && TYPE_NFN_FIELDS (type
) > 0))
4895 struct type
**first_dont_print
4896 = (struct type
**) obstack_base (&dont_print_type_obstack
);
4898 int i
= (struct type
**)
4899 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
4903 if (type
== first_dont_print
[i
])
4905 printfi_filtered (spaces
, "type node ");
4906 gdb_print_host_address (type
, gdb_stdout
);
4907 printf_filtered (_(" <same as already seen type>\n"));
4912 obstack_ptr_grow (&dont_print_type_obstack
, type
);
4915 printfi_filtered (spaces
, "type node ");
4916 gdb_print_host_address (type
, gdb_stdout
);
4917 printf_filtered ("\n");
4918 printfi_filtered (spaces
, "name '%s' (",
4919 type
->name () ? type
->name () : "<NULL>");
4920 gdb_print_host_address (type
->name (), gdb_stdout
);
4921 printf_filtered (")\n");
4922 printfi_filtered (spaces
, "code 0x%x ", type
->code ());
4923 switch (type
->code ())
4925 case TYPE_CODE_UNDEF
:
4926 printf_filtered ("(TYPE_CODE_UNDEF)");
4929 printf_filtered ("(TYPE_CODE_PTR)");
4931 case TYPE_CODE_ARRAY
:
4932 printf_filtered ("(TYPE_CODE_ARRAY)");
4934 case TYPE_CODE_STRUCT
:
4935 printf_filtered ("(TYPE_CODE_STRUCT)");
4937 case TYPE_CODE_UNION
:
4938 printf_filtered ("(TYPE_CODE_UNION)");
4940 case TYPE_CODE_ENUM
:
4941 printf_filtered ("(TYPE_CODE_ENUM)");
4943 case TYPE_CODE_FLAGS
:
4944 printf_filtered ("(TYPE_CODE_FLAGS)");
4946 case TYPE_CODE_FUNC
:
4947 printf_filtered ("(TYPE_CODE_FUNC)");
4950 printf_filtered ("(TYPE_CODE_INT)");
4953 printf_filtered ("(TYPE_CODE_FLT)");
4955 case TYPE_CODE_VOID
:
4956 printf_filtered ("(TYPE_CODE_VOID)");
4959 printf_filtered ("(TYPE_CODE_SET)");
4961 case TYPE_CODE_RANGE
:
4962 printf_filtered ("(TYPE_CODE_RANGE)");
4964 case TYPE_CODE_STRING
:
4965 printf_filtered ("(TYPE_CODE_STRING)");
4967 case TYPE_CODE_ERROR
:
4968 printf_filtered ("(TYPE_CODE_ERROR)");
4970 case TYPE_CODE_MEMBERPTR
:
4971 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
4973 case TYPE_CODE_METHODPTR
:
4974 printf_filtered ("(TYPE_CODE_METHODPTR)");
4976 case TYPE_CODE_METHOD
:
4977 printf_filtered ("(TYPE_CODE_METHOD)");
4980 printf_filtered ("(TYPE_CODE_REF)");
4982 case TYPE_CODE_CHAR
:
4983 printf_filtered ("(TYPE_CODE_CHAR)");
4985 case TYPE_CODE_BOOL
:
4986 printf_filtered ("(TYPE_CODE_BOOL)");
4988 case TYPE_CODE_COMPLEX
:
4989 printf_filtered ("(TYPE_CODE_COMPLEX)");
4991 case TYPE_CODE_TYPEDEF
:
4992 printf_filtered ("(TYPE_CODE_TYPEDEF)");
4994 case TYPE_CODE_NAMESPACE
:
4995 printf_filtered ("(TYPE_CODE_NAMESPACE)");
4998 printf_filtered ("(UNKNOWN TYPE CODE)");
5001 puts_filtered ("\n");
5002 printfi_filtered (spaces
, "length %s\n", pulongest (TYPE_LENGTH (type
)));
5003 if (TYPE_OBJFILE_OWNED (type
))
5005 printfi_filtered (spaces
, "objfile ");
5006 gdb_print_host_address (TYPE_OWNER (type
).objfile
, gdb_stdout
);
5010 printfi_filtered (spaces
, "gdbarch ");
5011 gdb_print_host_address (TYPE_OWNER (type
).gdbarch
, gdb_stdout
);
5013 printf_filtered ("\n");
5014 printfi_filtered (spaces
, "target_type ");
5015 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
5016 printf_filtered ("\n");
5017 if (TYPE_TARGET_TYPE (type
) != NULL
)
5019 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
5021 printfi_filtered (spaces
, "pointer_type ");
5022 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
5023 printf_filtered ("\n");
5024 printfi_filtered (spaces
, "reference_type ");
5025 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
5026 printf_filtered ("\n");
5027 printfi_filtered (spaces
, "type_chain ");
5028 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
5029 printf_filtered ("\n");
5030 printfi_filtered (spaces
, "instance_flags 0x%x",
5031 TYPE_INSTANCE_FLAGS (type
));
5032 if (TYPE_CONST (type
))
5034 puts_filtered (" TYPE_CONST");
5036 if (TYPE_VOLATILE (type
))
5038 puts_filtered (" TYPE_VOLATILE");
5040 if (TYPE_CODE_SPACE (type
))
5042 puts_filtered (" TYPE_CODE_SPACE");
5044 if (TYPE_DATA_SPACE (type
))
5046 puts_filtered (" TYPE_DATA_SPACE");
5048 if (TYPE_ADDRESS_CLASS_1 (type
))
5050 puts_filtered (" TYPE_ADDRESS_CLASS_1");
5052 if (TYPE_ADDRESS_CLASS_2 (type
))
5054 puts_filtered (" TYPE_ADDRESS_CLASS_2");
5056 if (TYPE_RESTRICT (type
))
5058 puts_filtered (" TYPE_RESTRICT");
5060 if (TYPE_ATOMIC (type
))
5062 puts_filtered (" TYPE_ATOMIC");
5064 puts_filtered ("\n");
5066 printfi_filtered (spaces
, "flags");
5067 if (type
->is_unsigned ())
5069 puts_filtered (" TYPE_UNSIGNED");
5071 if (type
->has_no_signedness ())
5073 puts_filtered (" TYPE_NOSIGN");
5075 if (TYPE_ENDIANITY_NOT_DEFAULT (type
))
5077 puts_filtered (" TYPE_ENDIANITY_NOT_DEFAULT");
5079 if (type
->is_stub ())
5081 puts_filtered (" TYPE_STUB");
5083 if (type
->target_is_stub ())
5085 puts_filtered (" TYPE_TARGET_STUB");
5087 if (type
->is_prototyped ())
5089 puts_filtered (" TYPE_PROTOTYPED");
5091 if (type
->has_varargs ())
5093 puts_filtered (" TYPE_VARARGS");
5095 /* This is used for things like AltiVec registers on ppc. Gcc emits
5096 an attribute for the array type, which tells whether or not we
5097 have a vector, instead of a regular array. */
5098 if (type
->is_vector ())
5100 puts_filtered (" TYPE_VECTOR");
5102 if (type
->is_fixed_instance ())
5104 puts_filtered (" TYPE_FIXED_INSTANCE");
5106 if (type
->stub_is_supported ())
5108 puts_filtered (" TYPE_STUB_SUPPORTED");
5110 if (TYPE_NOTTEXT (type
))
5112 puts_filtered (" TYPE_NOTTEXT");
5114 puts_filtered ("\n");
5115 printfi_filtered (spaces
, "nfields %d ", type
->num_fields ());
5116 gdb_print_host_address (type
->fields (), gdb_stdout
);
5117 puts_filtered ("\n");
5118 for (idx
= 0; idx
< type
->num_fields (); idx
++)
5120 if (type
->code () == TYPE_CODE_ENUM
)
5121 printfi_filtered (spaces
+ 2,
5122 "[%d] enumval %s type ",
5123 idx
, plongest (TYPE_FIELD_ENUMVAL (type
, idx
)));
5125 printfi_filtered (spaces
+ 2,
5126 "[%d] bitpos %s bitsize %d type ",
5127 idx
, plongest (TYPE_FIELD_BITPOS (type
, idx
)),
5128 TYPE_FIELD_BITSIZE (type
, idx
));
5129 gdb_print_host_address (type
->field (idx
).type (), gdb_stdout
);
5130 printf_filtered (" name '%s' (",
5131 TYPE_FIELD_NAME (type
, idx
) != NULL
5132 ? TYPE_FIELD_NAME (type
, idx
)
5134 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
5135 printf_filtered (")\n");
5136 if (type
->field (idx
).type () != NULL
)
5138 recursive_dump_type (type
->field (idx
).type (), spaces
+ 4);
5141 if (type
->code () == TYPE_CODE_RANGE
)
5143 printfi_filtered (spaces
, "low ");
5144 dump_dynamic_prop (type
->bounds ()->low
);
5145 printf_filtered (" high ");
5146 dump_dynamic_prop (type
->bounds ()->high
);
5147 printf_filtered ("\n");
5150 switch (TYPE_SPECIFIC_FIELD (type
))
5152 case TYPE_SPECIFIC_CPLUS_STUFF
:
5153 printfi_filtered (spaces
, "cplus_stuff ");
5154 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
),
5156 puts_filtered ("\n");
5157 print_cplus_stuff (type
, spaces
);
5160 case TYPE_SPECIFIC_GNAT_STUFF
:
5161 printfi_filtered (spaces
, "gnat_stuff ");
5162 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type
), gdb_stdout
);
5163 puts_filtered ("\n");
5164 print_gnat_stuff (type
, spaces
);
5167 case TYPE_SPECIFIC_FLOATFORMAT
:
5168 printfi_filtered (spaces
, "floatformat ");
5169 if (TYPE_FLOATFORMAT (type
) == NULL
5170 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
5171 puts_filtered ("(null)");
5173 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
5174 puts_filtered ("\n");
5177 case TYPE_SPECIFIC_FUNC
:
5178 printfi_filtered (spaces
, "calling_convention %d\n",
5179 TYPE_CALLING_CONVENTION (type
));
5180 /* tail_call_list is not printed. */
5183 case TYPE_SPECIFIC_SELF_TYPE
:
5184 printfi_filtered (spaces
, "self_type ");
5185 gdb_print_host_address (TYPE_SELF_TYPE (type
), gdb_stdout
);
5186 puts_filtered ("\n");
5191 obstack_free (&dont_print_type_obstack
, NULL
);
5194 /* Trivial helpers for the libiberty hash table, for mapping one
5197 struct type_pair
: public allocate_on_obstack
5199 type_pair (struct type
*old_
, struct type
*newobj_
)
5200 : old (old_
), newobj (newobj_
)
5203 struct type
* const old
, * const newobj
;
5207 type_pair_hash (const void *item
)
5209 const struct type_pair
*pair
= (const struct type_pair
*) item
;
5211 return htab_hash_pointer (pair
->old
);
5215 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
5217 const struct type_pair
*lhs
= (const struct type_pair
*) item_lhs
;
5218 const struct type_pair
*rhs
= (const struct type_pair
*) item_rhs
;
5220 return lhs
->old
== rhs
->old
;
5223 /* Allocate the hash table used by copy_type_recursive to walk
5224 types without duplicates. We use OBJFILE's obstack, because
5225 OBJFILE is about to be deleted. */
5228 create_copied_types_hash (struct objfile
*objfile
)
5230 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
5231 NULL
, &objfile
->objfile_obstack
,
5232 hashtab_obstack_allocate
,
5233 dummy_obstack_deallocate
);
5236 /* Recursively copy (deep copy) a dynamic attribute list of a type. */
5238 static struct dynamic_prop_list
*
5239 copy_dynamic_prop_list (struct obstack
*objfile_obstack
,
5240 struct dynamic_prop_list
*list
)
5242 struct dynamic_prop_list
*copy
= list
;
5243 struct dynamic_prop_list
**node_ptr
= ©
;
5245 while (*node_ptr
!= NULL
)
5247 struct dynamic_prop_list
*node_copy
;
5249 node_copy
= ((struct dynamic_prop_list
*)
5250 obstack_copy (objfile_obstack
, *node_ptr
,
5251 sizeof (struct dynamic_prop_list
)));
5252 node_copy
->prop
= (*node_ptr
)->prop
;
5253 *node_ptr
= node_copy
;
5255 node_ptr
= &node_copy
->next
;
5261 /* Recursively copy (deep copy) TYPE, if it is associated with
5262 OBJFILE. Return a new type owned by the gdbarch associated with the type, a
5263 saved type if we have already visited TYPE (using COPIED_TYPES), or TYPE if
5264 it is not associated with OBJFILE. */
5267 copy_type_recursive (struct objfile
*objfile
,
5269 htab_t copied_types
)
5272 struct type
*new_type
;
5274 if (! TYPE_OBJFILE_OWNED (type
))
5277 /* This type shouldn't be pointing to any types in other objfiles;
5278 if it did, the type might disappear unexpectedly. */
5279 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
5281 struct type_pair
pair (type
, nullptr);
5283 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
5285 return ((struct type_pair
*) *slot
)->newobj
;
5287 new_type
= alloc_type_arch (get_type_arch (type
));
5289 /* We must add the new type to the hash table immediately, in case
5290 we encounter this type again during a recursive call below. */
5291 struct type_pair
*stored
5292 = new (&objfile
->objfile_obstack
) struct type_pair (type
, new_type
);
5296 /* Copy the common fields of types. For the main type, we simply
5297 copy the entire thing and then update specific fields as needed. */
5298 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
5299 TYPE_OBJFILE_OWNED (new_type
) = 0;
5300 TYPE_OWNER (new_type
).gdbarch
= get_type_arch (type
);
5303 new_type
->set_name (xstrdup (type
->name ()));
5305 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
5306 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
5308 /* Copy the fields. */
5309 if (type
->num_fields ())
5313 nfields
= type
->num_fields ();
5314 new_type
->set_fields
5316 TYPE_ZALLOC (new_type
, nfields
* sizeof (struct field
)));
5318 for (i
= 0; i
< nfields
; i
++)
5320 TYPE_FIELD_ARTIFICIAL (new_type
, i
) =
5321 TYPE_FIELD_ARTIFICIAL (type
, i
);
5322 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
5323 if (type
->field (i
).type ())
5324 new_type
->field (i
).set_type
5325 (copy_type_recursive (objfile
, type
->field (i
).type (),
5327 if (TYPE_FIELD_NAME (type
, i
))
5328 TYPE_FIELD_NAME (new_type
, i
) =
5329 xstrdup (TYPE_FIELD_NAME (type
, i
));
5330 switch (TYPE_FIELD_LOC_KIND (type
, i
))
5332 case FIELD_LOC_KIND_BITPOS
:
5333 SET_FIELD_BITPOS (new_type
->field (i
),
5334 TYPE_FIELD_BITPOS (type
, i
));
5336 case FIELD_LOC_KIND_ENUMVAL
:
5337 SET_FIELD_ENUMVAL (new_type
->field (i
),
5338 TYPE_FIELD_ENUMVAL (type
, i
));
5340 case FIELD_LOC_KIND_PHYSADDR
:
5341 SET_FIELD_PHYSADDR (new_type
->field (i
),
5342 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
5344 case FIELD_LOC_KIND_PHYSNAME
:
5345 SET_FIELD_PHYSNAME (new_type
->field (i
),
5346 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
,
5350 internal_error (__FILE__
, __LINE__
,
5351 _("Unexpected type field location kind: %d"),
5352 TYPE_FIELD_LOC_KIND (type
, i
));
5357 /* For range types, copy the bounds information. */
5358 if (type
->code () == TYPE_CODE_RANGE
)
5360 range_bounds
*bounds
5361 = ((struct range_bounds
*) TYPE_ALLOC
5362 (new_type
, sizeof (struct range_bounds
)));
5364 *bounds
= *type
->bounds ();
5365 new_type
->set_bounds (bounds
);
5368 if (type
->main_type
->dyn_prop_list
!= NULL
)
5369 new_type
->main_type
->dyn_prop_list
5370 = copy_dynamic_prop_list (&objfile
->objfile_obstack
,
5371 type
->main_type
->dyn_prop_list
);
5374 /* Copy pointers to other types. */
5375 if (TYPE_TARGET_TYPE (type
))
5376 TYPE_TARGET_TYPE (new_type
) =
5377 copy_type_recursive (objfile
,
5378 TYPE_TARGET_TYPE (type
),
5381 /* Maybe copy the type_specific bits.
5383 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
5384 base classes and methods. There's no fundamental reason why we
5385 can't, but at the moment it is not needed. */
5387 switch (TYPE_SPECIFIC_FIELD (type
))
5389 case TYPE_SPECIFIC_NONE
:
5391 case TYPE_SPECIFIC_FUNC
:
5392 INIT_FUNC_SPECIFIC (new_type
);
5393 TYPE_CALLING_CONVENTION (new_type
) = TYPE_CALLING_CONVENTION (type
);
5394 TYPE_NO_RETURN (new_type
) = TYPE_NO_RETURN (type
);
5395 TYPE_TAIL_CALL_LIST (new_type
) = NULL
;
5397 case TYPE_SPECIFIC_FLOATFORMAT
:
5398 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
5400 case TYPE_SPECIFIC_CPLUS_STUFF
:
5401 INIT_CPLUS_SPECIFIC (new_type
);
5403 case TYPE_SPECIFIC_GNAT_STUFF
:
5404 INIT_GNAT_SPECIFIC (new_type
);
5406 case TYPE_SPECIFIC_SELF_TYPE
:
5407 set_type_self_type (new_type
,
5408 copy_type_recursive (objfile
, TYPE_SELF_TYPE (type
),
5412 gdb_assert_not_reached ("bad type_specific_kind");
5418 /* Make a copy of the given TYPE, except that the pointer & reference
5419 types are not preserved.
5421 This function assumes that the given type has an associated objfile.
5422 This objfile is used to allocate the new type. */
5425 copy_type (const struct type
*type
)
5427 struct type
*new_type
;
5429 gdb_assert (TYPE_OBJFILE_OWNED (type
));
5431 new_type
= alloc_type_copy (type
);
5432 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
5433 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
5434 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
5435 sizeof (struct main_type
));
5436 if (type
->main_type
->dyn_prop_list
!= NULL
)
5437 new_type
->main_type
->dyn_prop_list
5438 = copy_dynamic_prop_list (&TYPE_OBJFILE (type
) -> objfile_obstack
,
5439 type
->main_type
->dyn_prop_list
);
5444 /* Helper functions to initialize architecture-specific types. */
5446 /* Allocate a type structure associated with GDBARCH and set its
5447 CODE, LENGTH, and NAME fields. */
5450 arch_type (struct gdbarch
*gdbarch
,
5451 enum type_code code
, int bit
, const char *name
)
5455 type
= alloc_type_arch (gdbarch
);
5456 set_type_code (type
, code
);
5457 gdb_assert ((bit
% TARGET_CHAR_BIT
) == 0);
5458 TYPE_LENGTH (type
) = bit
/ TARGET_CHAR_BIT
;
5461 type
->set_name (gdbarch_obstack_strdup (gdbarch
, name
));
5466 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
5467 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
5468 the type's TYPE_UNSIGNED flag. NAME is the type name. */
5471 arch_integer_type (struct gdbarch
*gdbarch
,
5472 int bit
, int unsigned_p
, const char *name
)
5476 t
= arch_type (gdbarch
, TYPE_CODE_INT
, bit
, name
);
5478 t
->set_is_unsigned (true);
5483 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
5484 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
5485 the type's TYPE_UNSIGNED flag. NAME is the type name. */
5488 arch_character_type (struct gdbarch
*gdbarch
,
5489 int bit
, int unsigned_p
, const char *name
)
5493 t
= arch_type (gdbarch
, TYPE_CODE_CHAR
, bit
, name
);
5495 t
->set_is_unsigned (true);
5500 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
5501 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
5502 the type's TYPE_UNSIGNED flag. NAME is the type name. */
5505 arch_boolean_type (struct gdbarch
*gdbarch
,
5506 int bit
, int unsigned_p
, const char *name
)
5510 t
= arch_type (gdbarch
, TYPE_CODE_BOOL
, bit
, name
);
5512 t
->set_is_unsigned (true);
5517 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
5518 BIT is the type size in bits; if BIT equals -1, the size is
5519 determined by the floatformat. NAME is the type name. Set the
5520 TYPE_FLOATFORMAT from FLOATFORMATS. */
5523 arch_float_type (struct gdbarch
*gdbarch
,
5524 int bit
, const char *name
,
5525 const struct floatformat
**floatformats
)
5527 const struct floatformat
*fmt
= floatformats
[gdbarch_byte_order (gdbarch
)];
5530 bit
= verify_floatformat (bit
, fmt
);
5531 t
= arch_type (gdbarch
, TYPE_CODE_FLT
, bit
, name
);
5532 TYPE_FLOATFORMAT (t
) = fmt
;
5537 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with GDBARCH.
5538 BIT is the type size in bits. NAME is the type name. */
5541 arch_decfloat_type (struct gdbarch
*gdbarch
, int bit
, const char *name
)
5545 t
= arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, bit
, name
);
5549 /* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH.
5550 BIT is the pointer type size in bits. NAME is the type name.
5551 TARGET_TYPE is the pointer target type. Always sets the pointer type's
5552 TYPE_UNSIGNED flag. */
5555 arch_pointer_type (struct gdbarch
*gdbarch
,
5556 int bit
, const char *name
, struct type
*target_type
)
5560 t
= arch_type (gdbarch
, TYPE_CODE_PTR
, bit
, name
);
5561 TYPE_TARGET_TYPE (t
) = target_type
;
5562 t
->set_is_unsigned (true);
5566 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
5567 NAME is the type name. BIT is the size of the flag word in bits. */
5570 arch_flags_type (struct gdbarch
*gdbarch
, const char *name
, int bit
)
5574 type
= arch_type (gdbarch
, TYPE_CODE_FLAGS
, bit
, name
);
5575 type
->set_is_unsigned (true);
5576 type
->set_num_fields (0);
5577 /* Pre-allocate enough space assuming every field is one bit. */
5579 ((struct field
*) TYPE_ZALLOC (type
, bit
* sizeof (struct field
)));
5584 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5585 position BITPOS is called NAME. Pass NAME as "" for fields that
5586 should not be printed. */
5589 append_flags_type_field (struct type
*type
, int start_bitpos
, int nr_bits
,
5590 struct type
*field_type
, const char *name
)
5592 int type_bitsize
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
;
5593 int field_nr
= type
->num_fields ();
5595 gdb_assert (type
->code () == TYPE_CODE_FLAGS
);
5596 gdb_assert (type
->num_fields () + 1 <= type_bitsize
);
5597 gdb_assert (start_bitpos
>= 0 && start_bitpos
< type_bitsize
);
5598 gdb_assert (nr_bits
>= 1 && nr_bits
<= type_bitsize
);
5599 gdb_assert (name
!= NULL
);
5601 TYPE_FIELD_NAME (type
, field_nr
) = xstrdup (name
);
5602 type
->field (field_nr
).set_type (field_type
);
5603 SET_FIELD_BITPOS (type
->field (field_nr
), start_bitpos
);
5604 TYPE_FIELD_BITSIZE (type
, field_nr
) = nr_bits
;
5605 type
->set_num_fields (type
->num_fields () + 1);
5608 /* Special version of append_flags_type_field to add a flag field.
5609 Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5610 position BITPOS is called NAME. */
5613 append_flags_type_flag (struct type
*type
, int bitpos
, const char *name
)
5615 struct gdbarch
*gdbarch
= get_type_arch (type
);
5617 append_flags_type_field (type
, bitpos
, 1,
5618 builtin_type (gdbarch
)->builtin_bool
,
5622 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
5623 specified by CODE) associated with GDBARCH. NAME is the type name. */
5626 arch_composite_type (struct gdbarch
*gdbarch
, const char *name
,
5627 enum type_code code
)
5631 gdb_assert (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
);
5632 t
= arch_type (gdbarch
, code
, 0, NULL
);
5634 INIT_CPLUS_SPECIFIC (t
);
5638 /* Add new field with name NAME and type FIELD to composite type T.
5639 Do not set the field's position or adjust the type's length;
5640 the caller should do so. Return the new field. */
5643 append_composite_type_field_raw (struct type
*t
, const char *name
,
5648 t
->set_num_fields (t
->num_fields () + 1);
5649 t
->set_fields (XRESIZEVEC (struct field
, t
->fields (),
5651 f
= &t
->field (t
->num_fields () - 1);
5652 memset (f
, 0, sizeof f
[0]);
5653 f
[0].set_type (field
);
5654 FIELD_NAME (f
[0]) = name
;
5658 /* Add new field with name NAME and type FIELD to composite type T.
5659 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
5662 append_composite_type_field_aligned (struct type
*t
, const char *name
,
5663 struct type
*field
, int alignment
)
5665 struct field
*f
= append_composite_type_field_raw (t
, name
, field
);
5667 if (t
->code () == TYPE_CODE_UNION
)
5669 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
5670 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
5672 else if (t
->code () == TYPE_CODE_STRUCT
)
5674 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
5675 if (t
->num_fields () > 1)
5677 SET_FIELD_BITPOS (f
[0],
5678 (FIELD_BITPOS (f
[-1])
5679 + (TYPE_LENGTH (f
[-1].type ())
5680 * TARGET_CHAR_BIT
)));
5686 alignment
*= TARGET_CHAR_BIT
;
5687 left
= FIELD_BITPOS (f
[0]) % alignment
;
5691 SET_FIELD_BITPOS (f
[0], FIELD_BITPOS (f
[0]) + (alignment
- left
));
5692 TYPE_LENGTH (t
) += (alignment
- left
) / TARGET_CHAR_BIT
;
5699 /* Add new field with name NAME and type FIELD to composite type T. */
5702 append_composite_type_field (struct type
*t
, const char *name
,
5705 append_composite_type_field_aligned (t
, name
, field
, 0);
5708 static struct gdbarch_data
*gdbtypes_data
;
5710 const struct builtin_type
*
5711 builtin_type (struct gdbarch
*gdbarch
)
5713 return (const struct builtin_type
*) gdbarch_data (gdbarch
, gdbtypes_data
);
5717 gdbtypes_post_init (struct gdbarch
*gdbarch
)
5719 struct builtin_type
*builtin_type
5720 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
5723 builtin_type
->builtin_void
5724 = arch_type (gdbarch
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
5725 builtin_type
->builtin_char
5726 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
5727 !gdbarch_char_signed (gdbarch
), "char");
5728 builtin_type
->builtin_char
->set_has_no_signedness (true);
5729 builtin_type
->builtin_signed_char
5730 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
5732 builtin_type
->builtin_unsigned_char
5733 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
5734 1, "unsigned char");
5735 builtin_type
->builtin_short
5736 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
5738 builtin_type
->builtin_unsigned_short
5739 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
5740 1, "unsigned short");
5741 builtin_type
->builtin_int
5742 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
5744 builtin_type
->builtin_unsigned_int
5745 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
5747 builtin_type
->builtin_long
5748 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
5750 builtin_type
->builtin_unsigned_long
5751 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
5752 1, "unsigned long");
5753 builtin_type
->builtin_long_long
5754 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
5756 builtin_type
->builtin_unsigned_long_long
5757 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
5758 1, "unsigned long long");
5759 builtin_type
->builtin_half
5760 = arch_float_type (gdbarch
, gdbarch_half_bit (gdbarch
),
5761 "half", gdbarch_half_format (gdbarch
));
5762 builtin_type
->builtin_float
5763 = arch_float_type (gdbarch
, gdbarch_float_bit (gdbarch
),
5764 "float", gdbarch_float_format (gdbarch
));
5765 builtin_type
->builtin_bfloat16
5766 = arch_float_type (gdbarch
, gdbarch_bfloat16_bit (gdbarch
),
5767 "bfloat16", gdbarch_bfloat16_format (gdbarch
));
5768 builtin_type
->builtin_double
5769 = arch_float_type (gdbarch
, gdbarch_double_bit (gdbarch
),
5770 "double", gdbarch_double_format (gdbarch
));
5771 builtin_type
->builtin_long_double
5772 = arch_float_type (gdbarch
, gdbarch_long_double_bit (gdbarch
),
5773 "long double", gdbarch_long_double_format (gdbarch
));
5774 builtin_type
->builtin_complex
5775 = init_complex_type ("complex", builtin_type
->builtin_float
);
5776 builtin_type
->builtin_double_complex
5777 = init_complex_type ("double complex", builtin_type
->builtin_double
);
5778 builtin_type
->builtin_string
5779 = arch_type (gdbarch
, TYPE_CODE_STRING
, TARGET_CHAR_BIT
, "string");
5780 builtin_type
->builtin_bool
5781 = arch_type (gdbarch
, TYPE_CODE_BOOL
, TARGET_CHAR_BIT
, "bool");
5783 /* The following three are about decimal floating point types, which
5784 are 32-bits, 64-bits and 128-bits respectively. */
5785 builtin_type
->builtin_decfloat
5786 = arch_decfloat_type (gdbarch
, 32, "_Decimal32");
5787 builtin_type
->builtin_decdouble
5788 = arch_decfloat_type (gdbarch
, 64, "_Decimal64");
5789 builtin_type
->builtin_declong
5790 = arch_decfloat_type (gdbarch
, 128, "_Decimal128");
5792 /* "True" character types. */
5793 builtin_type
->builtin_true_char
5794 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 0, "true character");
5795 builtin_type
->builtin_true_unsigned_char
5796 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 1, "true character");
5798 /* Fixed-size integer types. */
5799 builtin_type
->builtin_int0
5800 = arch_integer_type (gdbarch
, 0, 0, "int0_t");
5801 builtin_type
->builtin_int8
5802 = arch_integer_type (gdbarch
, 8, 0, "int8_t");
5803 builtin_type
->builtin_uint8
5804 = arch_integer_type (gdbarch
, 8, 1, "uint8_t");
5805 builtin_type
->builtin_int16
5806 = arch_integer_type (gdbarch
, 16, 0, "int16_t");
5807 builtin_type
->builtin_uint16
5808 = arch_integer_type (gdbarch
, 16, 1, "uint16_t");
5809 builtin_type
->builtin_int24
5810 = arch_integer_type (gdbarch
, 24, 0, "int24_t");
5811 builtin_type
->builtin_uint24
5812 = arch_integer_type (gdbarch
, 24, 1, "uint24_t");
5813 builtin_type
->builtin_int32
5814 = arch_integer_type (gdbarch
, 32, 0, "int32_t");
5815 builtin_type
->builtin_uint32
5816 = arch_integer_type (gdbarch
, 32, 1, "uint32_t");
5817 builtin_type
->builtin_int64
5818 = arch_integer_type (gdbarch
, 64, 0, "int64_t");
5819 builtin_type
->builtin_uint64
5820 = arch_integer_type (gdbarch
, 64, 1, "uint64_t");
5821 builtin_type
->builtin_int128
5822 = arch_integer_type (gdbarch
, 128, 0, "int128_t");
5823 builtin_type
->builtin_uint128
5824 = arch_integer_type (gdbarch
, 128, 1, "uint128_t");
5825 TYPE_INSTANCE_FLAGS (builtin_type
->builtin_int8
) |=
5826 TYPE_INSTANCE_FLAG_NOTTEXT
;
5827 TYPE_INSTANCE_FLAGS (builtin_type
->builtin_uint8
) |=
5828 TYPE_INSTANCE_FLAG_NOTTEXT
;
5830 /* Wide character types. */
5831 builtin_type
->builtin_char16
5832 = arch_integer_type (gdbarch
, 16, 1, "char16_t");
5833 builtin_type
->builtin_char32
5834 = arch_integer_type (gdbarch
, 32, 1, "char32_t");
5835 builtin_type
->builtin_wchar
5836 = arch_integer_type (gdbarch
, gdbarch_wchar_bit (gdbarch
),
5837 !gdbarch_wchar_signed (gdbarch
), "wchar_t");
5839 /* Default data/code pointer types. */
5840 builtin_type
->builtin_data_ptr
5841 = lookup_pointer_type (builtin_type
->builtin_void
);
5842 builtin_type
->builtin_func_ptr
5843 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
5844 builtin_type
->builtin_func_func
5845 = lookup_function_type (builtin_type
->builtin_func_ptr
);
5847 /* This type represents a GDB internal function. */
5848 builtin_type
->internal_fn
5849 = arch_type (gdbarch
, TYPE_CODE_INTERNAL_FUNCTION
, 0,
5850 "<internal function>");
5852 /* This type represents an xmethod. */
5853 builtin_type
->xmethod
5854 = arch_type (gdbarch
, TYPE_CODE_XMETHOD
, 0, "<xmethod>");
5856 return builtin_type
;
5859 /* This set of objfile-based types is intended to be used by symbol
5860 readers as basic types. */
5862 static const struct objfile_key
<struct objfile_type
,
5863 gdb::noop_deleter
<struct objfile_type
>>
5866 const struct objfile_type
*
5867 objfile_type (struct objfile
*objfile
)
5869 struct gdbarch
*gdbarch
;
5870 struct objfile_type
*objfile_type
= objfile_type_data
.get (objfile
);
5873 return objfile_type
;
5875 objfile_type
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
5876 1, struct objfile_type
);
5878 /* Use the objfile architecture to determine basic type properties. */
5879 gdbarch
= objfile
->arch ();
5882 objfile_type
->builtin_void
5883 = init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
5884 objfile_type
->builtin_char
5885 = init_integer_type (objfile
, TARGET_CHAR_BIT
,
5886 !gdbarch_char_signed (gdbarch
), "char");
5887 objfile_type
->builtin_char
->set_has_no_signedness (true);
5888 objfile_type
->builtin_signed_char
5889 = init_integer_type (objfile
, TARGET_CHAR_BIT
,
5891 objfile_type
->builtin_unsigned_char
5892 = init_integer_type (objfile
, TARGET_CHAR_BIT
,
5893 1, "unsigned char");
5894 objfile_type
->builtin_short
5895 = init_integer_type (objfile
, gdbarch_short_bit (gdbarch
),
5897 objfile_type
->builtin_unsigned_short
5898 = init_integer_type (objfile
, gdbarch_short_bit (gdbarch
),
5899 1, "unsigned short");
5900 objfile_type
->builtin_int
5901 = init_integer_type (objfile
, gdbarch_int_bit (gdbarch
),
5903 objfile_type
->builtin_unsigned_int
5904 = init_integer_type (objfile
, gdbarch_int_bit (gdbarch
),
5906 objfile_type
->builtin_long
5907 = init_integer_type (objfile
, gdbarch_long_bit (gdbarch
),
5909 objfile_type
->builtin_unsigned_long
5910 = init_integer_type (objfile
, gdbarch_long_bit (gdbarch
),
5911 1, "unsigned long");
5912 objfile_type
->builtin_long_long
5913 = init_integer_type (objfile
, gdbarch_long_long_bit (gdbarch
),
5915 objfile_type
->builtin_unsigned_long_long
5916 = init_integer_type (objfile
, gdbarch_long_long_bit (gdbarch
),
5917 1, "unsigned long long");
5918 objfile_type
->builtin_float
5919 = init_float_type (objfile
, gdbarch_float_bit (gdbarch
),
5920 "float", gdbarch_float_format (gdbarch
));
5921 objfile_type
->builtin_double
5922 = init_float_type (objfile
, gdbarch_double_bit (gdbarch
),
5923 "double", gdbarch_double_format (gdbarch
));
5924 objfile_type
->builtin_long_double
5925 = init_float_type (objfile
, gdbarch_long_double_bit (gdbarch
),
5926 "long double", gdbarch_long_double_format (gdbarch
));
5928 /* This type represents a type that was unrecognized in symbol read-in. */
5929 objfile_type
->builtin_error
5930 = init_type (objfile
, TYPE_CODE_ERROR
, 0, "<unknown type>");
5932 /* The following set of types is used for symbols with no
5933 debug information. */
5934 objfile_type
->nodebug_text_symbol
5935 = init_type (objfile
, TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
5936 "<text variable, no debug info>");
5938 objfile_type
->nodebug_text_gnu_ifunc_symbol
5939 = init_type (objfile
, TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
5940 "<text gnu-indirect-function variable, no debug info>");
5941 objfile_type
->nodebug_text_gnu_ifunc_symbol
->set_is_gnu_ifunc (true);
5943 objfile_type
->nodebug_got_plt_symbol
5944 = init_pointer_type (objfile
, gdbarch_addr_bit (gdbarch
),
5945 "<text from jump slot in .got.plt, no debug info>",
5946 objfile_type
->nodebug_text_symbol
);
5947 objfile_type
->nodebug_data_symbol
5948 = init_nodebug_var_type (objfile
, "<data variable, no debug info>");
5949 objfile_type
->nodebug_unknown_symbol
5950 = init_nodebug_var_type (objfile
, "<variable (not text or data), no debug info>");
5951 objfile_type
->nodebug_tls_symbol
5952 = init_nodebug_var_type (objfile
, "<thread local variable, no debug info>");
5954 /* NOTE: on some targets, addresses and pointers are not necessarily
5958 - gdb's `struct type' always describes the target's
5960 - gdb's `struct value' objects should always hold values in
5962 - gdb's CORE_ADDR values are addresses in the unified virtual
5963 address space that the assembler and linker work with. Thus,
5964 since target_read_memory takes a CORE_ADDR as an argument, it
5965 can access any memory on the target, even if the processor has
5966 separate code and data address spaces.
5968 In this context, objfile_type->builtin_core_addr is a bit odd:
5969 it's a target type for a value the target will never see. It's
5970 only used to hold the values of (typeless) linker symbols, which
5971 are indeed in the unified virtual address space. */
5973 objfile_type
->builtin_core_addr
5974 = init_integer_type (objfile
, gdbarch_addr_bit (gdbarch
), 1,
5977 objfile_type_data
.set (objfile
, objfile_type
);
5978 return objfile_type
;
5981 void _initialize_gdbtypes ();
5983 _initialize_gdbtypes ()
5985 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
5987 add_setshow_zuinteger_cmd ("overload", no_class
, &overload_debug
,
5988 _("Set debugging of C++ overloading."),
5989 _("Show debugging of C++ overloading."),
5990 _("When enabled, ranking of the "
5991 "functions is displayed."),
5993 show_overload_debug
,
5994 &setdebuglist
, &showdebuglist
);
5996 /* Add user knob for controlling resolution of opaque types. */
5997 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
5998 &opaque_type_resolution
,
5999 _("Set resolution of opaque struct/class/union"
6000 " types (if set before loading symbols)."),
6001 _("Show resolution of opaque struct/class/union"
6002 " types (if set before loading symbols)."),
6004 show_opaque_type_resolution
,
6005 &setlist
, &showlist
);
6007 /* Add an option to permit non-strict type checking. */
6008 add_setshow_boolean_cmd ("type", class_support
,
6009 &strict_type_checking
,
6010 _("Set strict type checking."),
6011 _("Show strict type checking."),
6013 show_strict_type_checking
,
6014 &setchecklist
, &showchecklist
);