1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2025 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/>. */
27 #include "expression.h"
32 #include "complaints.h"
33 #include "cli/cli-cmds.h"
36 #include "cp-support.h"
38 #include "dwarf2/loc.h"
39 #include "dwarf2/read.h"
41 #include "floatformat.h"
44 #include "gmp-utils.h"
45 #include "rust-lang.h"
47 #include "extract-store-integer.h"
49 /* The value of an invalid conversion badness. */
50 #define INVALID_CONVERSION 100
52 static struct dynamic_prop_list
*
53 copy_dynamic_prop_list (struct obstack
*, struct dynamic_prop_list
*);
55 /* Initialize BADNESS constants. */
57 const struct rank LENGTH_MISMATCH_BADNESS
= {INVALID_CONVERSION
,0};
59 const struct rank TOO_FEW_PARAMS_BADNESS
= {INVALID_CONVERSION
,0};
60 const struct rank INCOMPATIBLE_TYPE_BADNESS
= {INVALID_CONVERSION
,0};
62 const struct rank EXACT_MATCH_BADNESS
= {0,0};
64 const struct rank INTEGER_PROMOTION_BADNESS
= {1,0};
65 const struct rank FLOAT_PROMOTION_BADNESS
= {1,0};
66 const struct rank BASE_PTR_CONVERSION_BADNESS
= {1,0};
67 const struct rank CV_CONVERSION_BADNESS
= {1, 0};
68 const struct rank INTEGER_CONVERSION_BADNESS
= {2,0};
69 const struct rank FLOAT_CONVERSION_BADNESS
= {2,0};
70 const struct rank INT_FLOAT_CONVERSION_BADNESS
= {2,0};
71 const struct rank VOID_PTR_CONVERSION_BADNESS
= {2,0};
72 const struct rank BOOL_CONVERSION_BADNESS
= {3,0};
73 const struct rank BASE_CONVERSION_BADNESS
= {2,0};
74 const struct rank REFERENCE_CONVERSION_BADNESS
= {2,0};
75 const struct rank REFERENCE_SEE_THROUGH_BADNESS
= {0,1};
76 const struct rank NULL_POINTER_CONVERSION_BADNESS
= {2,0};
77 const struct rank NS_POINTER_CONVERSION_BADNESS
= {10,0};
78 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS
= {3,0};
79 const struct rank VARARG_BADNESS
= {4, 0};
81 /* Floatformat pairs. */
82 const struct floatformat
*floatformats_ieee_half
[BFD_ENDIAN_UNKNOWN
] = {
83 &floatformat_ieee_half_big
,
84 &floatformat_ieee_half_little
86 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
87 &floatformat_ieee_single_big
,
88 &floatformat_ieee_single_little
90 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
91 &floatformat_ieee_double_big
,
92 &floatformat_ieee_double_little
94 const struct floatformat
*floatformats_ieee_quad
[BFD_ENDIAN_UNKNOWN
] = {
95 &floatformat_ieee_quad_big
,
96 &floatformat_ieee_quad_little
98 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
99 &floatformat_ieee_double_big
,
100 &floatformat_ieee_double_littlebyte_bigword
102 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
103 &floatformat_i387_ext
,
104 &floatformat_i387_ext
106 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
107 &floatformat_m68881_ext
,
108 &floatformat_m68881_ext
110 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
111 &floatformat_arm_ext_big
,
112 &floatformat_arm_ext_littlebyte_bigword
114 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
115 &floatformat_ia64_spill_big
,
116 &floatformat_ia64_spill_little
118 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
122 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
126 const struct floatformat
*floatformats_ibm_long_double
[BFD_ENDIAN_UNKNOWN
] = {
127 &floatformat_ibm_long_double_big
,
128 &floatformat_ibm_long_double_little
130 const struct floatformat
*floatformats_bfloat16
[BFD_ENDIAN_UNKNOWN
] = {
131 &floatformat_bfloat16_big
,
132 &floatformat_bfloat16_little
135 /* Should opaque types be resolved? */
137 static bool opaque_type_resolution
= true;
139 /* See gdbtypes.h. */
141 unsigned int overload_debug
= 0;
143 /* A flag to enable strict type checking. */
145 static bool strict_type_checking
= true;
147 /* A function to show whether opaque types are resolved. */
150 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
151 struct cmd_list_element
*c
,
154 gdb_printf (file
, _("Resolution of opaque struct/class/union types "
155 "(if set before loading symbols) is %s.\n"),
159 /* A function to show whether C++ overload debugging is enabled. */
162 show_overload_debug (struct ui_file
*file
, int from_tty
,
163 struct cmd_list_element
*c
, const char *value
)
165 gdb_printf (file
, _("Debugging of C++ overloading is %s.\n"),
169 /* A function to show the status of strict type checking. */
172 show_strict_type_checking (struct ui_file
*file
, int from_tty
,
173 struct cmd_list_element
*c
, const char *value
)
175 gdb_printf (file
, _("Strict type checking is %s.\n"), value
);
179 /* Helper function to initialize a newly allocated type. Set type code
180 to CODE and initialize the type-specific fields accordingly. */
183 set_type_code (struct type
*type
, enum type_code code
)
185 type
->set_code (code
);
189 case TYPE_CODE_STRUCT
:
190 case TYPE_CODE_UNION
:
191 case TYPE_CODE_NAMESPACE
:
192 INIT_CPLUS_SPECIFIC (type
);
195 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_FLOATFORMAT
;
198 INIT_FUNC_SPECIFIC (type
);
200 case TYPE_CODE_FIXED_POINT
:
201 INIT_FIXED_POINT_SPECIFIC (type
);
206 /* See gdbtypes.h. */
209 type_allocator::new_type ()
214 obstack
*obstack
= (m_is_objfile
215 ? &m_data
.objfile
->objfile_obstack
216 : gdbarch_obstack (m_data
.gdbarch
));
218 /* Alloc the structure and start off with all fields zeroed. */
219 struct type
*type
= OBSTACK_ZALLOC (obstack
, struct type
);
220 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (obstack
, struct main_type
);
221 TYPE_MAIN_TYPE (type
)->m_lang
= m_lang
;
225 OBJSTAT (m_data
.objfile
, n_types
++);
226 type
->set_owner (m_data
.objfile
);
229 type
->set_owner (m_data
.gdbarch
);
231 /* Initialize the fields that might not be zero. */
232 type
->set_code (TYPE_CODE_UNDEF
);
233 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
238 /* See gdbtypes.h. */
241 type_allocator::new_type (enum type_code code
, int bit
, const char *name
)
243 struct type
*type
= new_type ();
244 set_type_code (type
, code
);
245 gdb_assert ((bit
% TARGET_CHAR_BIT
) == 0);
246 type
->set_length (bit
/ TARGET_CHAR_BIT
);
250 obstack
*obstack
= (m_is_objfile
251 ? &m_data
.objfile
->objfile_obstack
252 : gdbarch_obstack (m_data
.gdbarch
));
253 type
->set_name (obstack_strdup (obstack
, name
));
259 /* See gdbtypes.h. */
262 type_allocator::arch ()
265 return m_data
.type
->arch ();
267 return m_data
.objfile
->arch ();
268 return m_data
.gdbarch
;
271 /* See gdbtypes.h. */
276 struct gdbarch
*arch
;
278 if (this->is_objfile_owned ())
279 arch
= this->objfile_owner ()->arch ();
281 arch
= this->arch_owner ();
283 /* The ARCH can be NULL if TYPE is associated with neither an objfile nor
284 a gdbarch, however, this is very rare, and even then, in most cases
285 that type::arch is called, we assume that a non-NULL value is
287 gdb_assert (arch
!= nullptr);
291 /* See gdbtypes.h. */
294 get_target_type (struct type
*type
)
298 type
= type
->target_type ();
300 type
= check_typedef (type
);
306 /* See gdbtypes.h. */
309 type_length_units (struct type
*type
)
311 int unit_size
= gdbarch_addressable_memory_unit_size (type
->arch ());
313 return type
->length () / unit_size
;
316 /* Alloc a new type instance structure, fill it with some defaults,
317 and point it at OLDTYPE. Allocate the new type instance from the
318 same place as OLDTYPE. */
321 alloc_type_instance (struct type
*oldtype
)
325 /* Allocate the structure. */
327 if (!oldtype
->is_objfile_owned ())
328 type
= GDBARCH_OBSTACK_ZALLOC (oldtype
->arch_owner (), struct type
);
330 type
= OBSTACK_ZALLOC (&oldtype
->objfile_owner ()->objfile_obstack
,
333 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
335 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
340 /* Clear all remnants of the previous type at TYPE, in preparation for
341 replacing it with something else. Preserve owner information. */
344 smash_type (struct type
*type
)
346 bool objfile_owned
= type
->is_objfile_owned ();
347 objfile
*objfile
= type
->objfile_owner ();
348 gdbarch
*arch
= type
->arch_owner ();
350 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
352 /* Restore owner information. */
354 type
->set_owner (objfile
);
356 type
->set_owner (arch
);
358 /* For now, delete the rings. */
359 TYPE_CHAIN (type
) = type
;
361 /* For now, leave the pointer/reference types alone. */
364 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
365 to a pointer to memory where the pointer type should be stored.
366 If *TYPEPTR is zero, update it to point to the pointer type we return.
367 We allocate new memory if needed. */
370 make_pointer_type (struct type
*type
, struct type
**typeptr
)
372 struct type
*ntype
; /* New type */
375 ntype
= TYPE_POINTER_TYPE (type
);
380 return ntype
; /* Don't care about alloc,
381 and have new type. */
382 else if (*typeptr
== 0)
384 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
389 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
391 ntype
= type_allocator (type
).new_type ();
395 else /* We have storage, but need to reset it. */
398 chain
= TYPE_CHAIN (ntype
);
400 TYPE_CHAIN (ntype
) = chain
;
403 ntype
->set_target_type (type
);
404 TYPE_POINTER_TYPE (type
) = ntype
;
406 /* FIXME! Assumes the machine has only one representation for pointers! */
408 ntype
->set_length (gdbarch_ptr_bit (type
->arch ()) / TARGET_CHAR_BIT
);
409 ntype
->set_code (TYPE_CODE_PTR
);
411 /* Mark pointers as unsigned. The target converts between pointers
412 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
413 gdbarch_address_to_pointer. */
414 ntype
->set_is_unsigned (true);
416 /* Update the length of all the other variants of this type. */
417 chain
= TYPE_CHAIN (ntype
);
418 while (chain
!= ntype
)
420 chain
->set_length (ntype
->length ());
421 chain
= TYPE_CHAIN (chain
);
427 /* Given a type TYPE, return a type of pointers to that type.
428 May need to construct such a type if this is the first use. */
431 lookup_pointer_type (struct type
*type
)
433 return make_pointer_type (type
, (struct type
**) 0);
436 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
437 points to a pointer to memory where the reference type should be
438 stored. If *TYPEPTR is zero, update it to point to the reference
439 type we return. We allocate new memory if needed. REFCODE denotes
440 the kind of reference type to lookup (lvalue or rvalue reference). */
443 make_reference_type (struct type
*type
, struct type
**typeptr
,
444 enum type_code refcode
)
446 struct type
*ntype
; /* New type */
447 struct type
**reftype
;
450 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
452 ntype
= (refcode
== TYPE_CODE_REF
? TYPE_REFERENCE_TYPE (type
)
453 : TYPE_RVALUE_REFERENCE_TYPE (type
));
458 return ntype
; /* Don't care about alloc,
459 and have new type. */
460 else if (*typeptr
== 0)
462 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
467 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
469 ntype
= type_allocator (type
).new_type ();
473 else /* We have storage, but need to reset it. */
476 chain
= TYPE_CHAIN (ntype
);
478 TYPE_CHAIN (ntype
) = chain
;
481 ntype
->set_target_type (type
);
482 reftype
= (refcode
== TYPE_CODE_REF
? &TYPE_REFERENCE_TYPE (type
)
483 : &TYPE_RVALUE_REFERENCE_TYPE (type
));
487 /* FIXME! Assume the machine has only one representation for
488 references, and that it matches the (only) representation for
491 ntype
->set_length (gdbarch_ptr_bit (type
->arch ()) / TARGET_CHAR_BIT
);
492 ntype
->set_code (refcode
);
496 /* Update the length of all the other variants of this type. */
497 chain
= TYPE_CHAIN (ntype
);
498 while (chain
!= ntype
)
500 chain
->set_length (ntype
->length ());
501 chain
= TYPE_CHAIN (chain
);
507 /* Same as above, but caller doesn't care about memory allocation
511 lookup_reference_type (struct type
*type
, enum type_code refcode
)
513 return make_reference_type (type
, (struct type
**) 0, refcode
);
516 /* Lookup the lvalue reference type for the type TYPE. */
519 lookup_lvalue_reference_type (struct type
*type
)
521 return lookup_reference_type (type
, TYPE_CODE_REF
);
524 /* Lookup the rvalue reference type for the type TYPE. */
527 lookup_rvalue_reference_type (struct type
*type
)
529 return lookup_reference_type (type
, TYPE_CODE_RVALUE_REF
);
532 /* Lookup a function type that returns type TYPE. TYPEPTR, if
533 nonzero, points to a pointer to memory where the function type
534 should be stored. If *TYPEPTR is zero, update it to point to the
535 function type we return. We allocate new memory if needed. */
538 make_function_type (struct type
*type
, struct type
**typeptr
)
540 struct type
*ntype
; /* New type */
542 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
544 ntype
= type_allocator (type
).new_type ();
548 else /* We have storage, but need to reset it. */
554 ntype
->set_target_type (type
);
556 ntype
->set_length (1);
557 ntype
->set_code (TYPE_CODE_FUNC
);
559 INIT_FUNC_SPECIFIC (ntype
);
564 /* Given a type TYPE, return a type of functions that return that type.
565 May need to construct such a type if this is the first use. */
568 lookup_function_type (struct type
*type
)
570 return make_function_type (type
, (struct type
**) 0);
573 /* Given a type TYPE and argument types, return the appropriate
574 function type. If the final type in PARAM_TYPES is NULL, make a
578 lookup_function_type_with_arguments (struct type
*type
,
580 struct type
**param_types
)
582 struct type
*fn
= make_function_type (type
, (struct type
**) 0);
587 if (param_types
[nparams
- 1] == NULL
)
590 fn
->set_has_varargs (true);
592 else if (check_typedef (param_types
[nparams
- 1])->code ()
596 /* Caller should have ensured this. */
597 gdb_assert (nparams
== 0);
598 fn
->set_is_prototyped (true);
601 fn
->set_is_prototyped (true);
604 fn
->alloc_fields (nparams
);
605 for (i
= 0; i
< nparams
; ++i
)
606 fn
->field (i
).set_type (param_types
[i
]);
611 /* Identify address space identifier by name -- return a
612 type_instance_flags. */
615 address_space_name_to_type_instance_flags (struct gdbarch
*gdbarch
,
616 const char *space_identifier
)
618 type_instance_flags type_flags
;
620 /* Check for known address space delimiters. */
621 if (!strcmp (space_identifier
, "code"))
622 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
623 else if (!strcmp (space_identifier
, "data"))
624 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
625 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
626 && gdbarch_address_class_name_to_type_flags (gdbarch
,
631 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
634 /* Identify address space identifier by type_instance_flags and return
635 the string version of the address space name. */
638 address_space_type_instance_flags_to_name (struct gdbarch
*gdbarch
,
639 type_instance_flags space_flag
)
641 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
643 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
645 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
646 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
647 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
652 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
654 If STORAGE is non-NULL, create the new type instance there.
655 STORAGE must be in the same obstack as TYPE. */
658 make_qualified_type (struct type
*type
, type_instance_flags new_flags
,
659 struct type
*storage
)
666 if (ntype
->instance_flags () == new_flags
)
668 ntype
= TYPE_CHAIN (ntype
);
670 while (ntype
!= type
);
672 /* Create a new type instance. */
674 ntype
= alloc_type_instance (type
);
677 /* If STORAGE was provided, it had better be in the same objfile
678 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
679 if one objfile is freed and the other kept, we'd have
680 dangling pointers. */
681 gdb_assert (type
->objfile_owner () == storage
->objfile_owner ());
684 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
685 TYPE_CHAIN (ntype
) = ntype
;
688 /* Pointers or references to the original type are not relevant to
690 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
691 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
693 /* Chain the new qualified type to the old type. */
694 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
695 TYPE_CHAIN (type
) = ntype
;
697 /* Now set the instance flags and return the new type. */
698 ntype
->set_instance_flags (new_flags
);
700 /* Set length of new type to that of the original type. */
701 ntype
->set_length (type
->length ());
706 /* Make an address-space-delimited variant of a type -- a type that
707 is identical to the one supplied except that it has an address
708 space attribute attached to it (such as "code" or "data").
710 The space attributes "code" and "data" are for Harvard
711 architectures. The address space attributes are for architectures
712 which have alternately sized pointers or pointers with alternate
716 make_type_with_address_space (struct type
*type
,
717 type_instance_flags space_flag
)
719 type_instance_flags new_flags
= ((type
->instance_flags ()
720 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
721 | TYPE_INSTANCE_FLAG_DATA_SPACE
722 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
725 return make_qualified_type (type
, new_flags
, NULL
);
728 /* Make a "c-v" variant of a type -- a type that is identical to the
729 one supplied except that it may have const or volatile attributes
730 CNST is a flag for setting the const attribute
731 VOLTL is a flag for setting the volatile attribute
732 TYPE is the base type whose variant we are creating.
734 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
735 storage to hold the new qualified type; *TYPEPTR and TYPE must be
736 in the same objfile. Otherwise, allocate fresh memory for the new
737 type wherever TYPE lives. If TYPEPTR is non-zero, set it to the
738 new type we construct. */
741 make_cv_type (int cnst
, int voltl
,
743 struct type
**typeptr
)
745 struct type
*ntype
; /* New type */
747 type_instance_flags new_flags
= (type
->instance_flags ()
748 & ~(TYPE_INSTANCE_FLAG_CONST
749 | TYPE_INSTANCE_FLAG_VOLATILE
));
752 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
755 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
757 if (typeptr
&& *typeptr
!= NULL
)
759 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
760 a C-V variant chain that threads across objfiles: if one
761 objfile gets freed, then the other has a broken C-V chain.
763 This code used to try to copy over the main type from TYPE to
764 *TYPEPTR if they were in different objfiles, but that's
765 wrong, too: TYPE may have a field list or member function
766 lists, which refer to types of their own, etc. etc. The
767 whole shebang would need to be copied over recursively; you
768 can't have inter-objfile pointers. The only thing to do is
769 to leave stub types as stub types, and look them up afresh by
770 name each time you encounter them. */
771 gdb_assert ((*typeptr
)->objfile_owner () == type
->objfile_owner ());
774 ntype
= make_qualified_type (type
, new_flags
,
775 typeptr
? *typeptr
: NULL
);
783 /* Make a 'restrict'-qualified version of TYPE. */
786 make_restrict_type (struct type
*type
)
788 return make_qualified_type (type
,
789 (type
->instance_flags ()
790 | TYPE_INSTANCE_FLAG_RESTRICT
),
794 /* Make a type without const, volatile, or restrict. */
797 make_unqualified_type (struct type
*type
)
799 return make_qualified_type (type
,
800 (type
->instance_flags ()
801 & ~(TYPE_INSTANCE_FLAG_CONST
802 | TYPE_INSTANCE_FLAG_VOLATILE
803 | TYPE_INSTANCE_FLAG_RESTRICT
)),
807 /* Make a '_Atomic'-qualified version of TYPE. */
810 make_atomic_type (struct type
*type
)
812 return make_qualified_type (type
,
813 (type
->instance_flags ()
814 | TYPE_INSTANCE_FLAG_ATOMIC
),
818 /* Replace the contents of ntype with the type *type. This changes the
819 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
820 the changes are propagated to all types in the TYPE_CHAIN.
822 In order to build recursive types, it's inevitable that we'll need
823 to update types in place --- but this sort of indiscriminate
824 smashing is ugly, and needs to be replaced with something more
825 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
826 clear if more steps are needed. */
829 replace_type (struct type
*ntype
, struct type
*type
)
833 /* These two types had better be in the same objfile. Otherwise,
834 the assignment of one type's main type structure to the other
835 will produce a type with references to objects (names; field
836 lists; etc.) allocated on an objfile other than its own. */
837 gdb_assert (ntype
->objfile_owner () == type
->objfile_owner ());
839 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
841 /* The type length is not a part of the main type. Update it for
842 each type on the variant chain. */
846 /* Assert that this element of the chain has no address-class bits
847 set in its flags. Such type variants might have type lengths
848 which are supposed to be different from the non-address-class
849 variants. This assertion shouldn't ever be triggered because
850 symbol readers which do construct address-class variants don't
851 call replace_type(). */
852 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
854 chain
->set_length (type
->length ());
855 chain
= TYPE_CHAIN (chain
);
857 while (ntype
!= chain
);
859 /* Assert that the two types have equivalent instance qualifiers.
860 This should be true for at least all of our debug readers. */
861 gdb_assert (ntype
->instance_flags () == type
->instance_flags ());
864 /* Implement direct support for MEMBER_TYPE in GNU C++.
865 May need to construct such a type if this is the first use.
866 The TYPE is the type of the member. The DOMAIN is the type
867 of the aggregate that the member belongs to. */
870 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
874 mtype
= type_allocator (type
).new_type ();
875 smash_to_memberptr_type (mtype
, domain
, type
);
879 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
882 lookup_methodptr_type (struct type
*to_type
)
886 mtype
= type_allocator (to_type
).new_type ();
887 smash_to_methodptr_type (mtype
, to_type
);
891 /* See gdbtypes.h. */
894 operator== (const dynamic_prop
&l
, const dynamic_prop
&r
)
896 if (l
.kind () != r
.kind ())
904 return l
.const_val () == r
.const_val ();
908 return l
.baton () == r
.baton ();
909 case PROP_VARIANT_PARTS
:
910 return l
.variant_parts () == r
.variant_parts ();
912 return l
.original_type () == r
.original_type ();
915 gdb_assert_not_reached ("unhandled dynamic_prop kind");
918 /* See gdbtypes.h. */
921 operator== (const range_bounds
&l
, const range_bounds
&r
)
923 #define FIELD_EQ(FIELD) (l.FIELD == r.FIELD)
925 return (FIELD_EQ (low
)
927 && FIELD_EQ (flag_upper_bound_is_count
)
928 && FIELD_EQ (flag_bound_evaluated
)
934 /* See gdbtypes.h. */
937 create_range_type (type_allocator
&alloc
, struct type
*index_type
,
938 const struct dynamic_prop
*low_bound
,
939 const struct dynamic_prop
*high_bound
,
942 /* The INDEX_TYPE should be a type capable of holding the upper and lower
943 bounds, as such a zero sized, or void type makes no sense. */
944 gdb_assert (index_type
->code () != TYPE_CODE_VOID
);
945 gdb_assert (index_type
->length () > 0);
947 struct type
*result_type
= alloc
.new_type ();
948 result_type
->set_code (TYPE_CODE_RANGE
);
949 result_type
->set_target_type (index_type
);
950 if (index_type
->is_stub ())
951 result_type
->set_target_is_stub (true);
953 result_type
->set_length (check_typedef (index_type
)->length ());
956 = (struct range_bounds
*) TYPE_ZALLOC (result_type
, sizeof (range_bounds
));
957 bounds
->low
= *low_bound
;
958 bounds
->high
= *high_bound
;
960 bounds
->stride
.set_const_val (0);
962 result_type
->set_bounds (bounds
);
964 if (index_type
->code () == TYPE_CODE_FIXED_POINT
)
965 result_type
->set_is_unsigned (index_type
->is_unsigned ());
966 else if (index_type
->is_unsigned ())
968 /* If the underlying type is unsigned, then the range
970 result_type
->set_is_unsigned (true);
972 /* Otherwise, the signed-ness of a range type can't simply be copied
973 from the underlying type. Consider a case where the underlying
974 type is 'int', but the range type can hold 0..65535, and where
975 the range is further specified to fit into 16 bits. In this
976 case, if we copy the underlying type's sign, then reading some
977 range values will cause an unwanted sign extension. So, we have
978 some heuristics here instead. */
979 else if (low_bound
->is_constant () && low_bound
->const_val () >= 0)
981 result_type
->set_is_unsigned (true);
982 /* Ada allows the declaration of range types whose upper bound is
983 less than the lower bound, so checking the lower bound is not
984 enough. Make sure we do not mark a range type whose upper bound
985 is negative as unsigned. */
986 if (high_bound
->is_constant () && high_bound
->const_val () < 0)
987 result_type
->set_is_unsigned (false);
990 result_type
->set_endianity_is_not_default
991 (index_type
->endianity_is_not_default ());
996 /* See gdbtypes.h. */
999 create_range_type_with_stride (type_allocator
&alloc
,
1000 struct type
*index_type
,
1001 const struct dynamic_prop
*low_bound
,
1002 const struct dynamic_prop
*high_bound
,
1004 const struct dynamic_prop
*stride
,
1007 struct type
*result_type
= create_range_type (alloc
, index_type
, low_bound
,
1010 gdb_assert (stride
!= nullptr);
1011 result_type
->bounds ()->stride
= *stride
;
1012 result_type
->bounds ()->flag_is_byte_stride
= byte_stride_p
;
1017 /* See gdbtypes.h. */
1020 create_static_range_type (type_allocator
&alloc
, struct type
*index_type
,
1021 LONGEST low_bound
, LONGEST high_bound
)
1023 struct dynamic_prop low
, high
;
1025 low
.set_const_val (low_bound
);
1026 high
.set_const_val (high_bound
);
1028 struct type
*result_type
= create_range_type (alloc
, index_type
,
1034 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
1035 are static, otherwise returns 0. */
1038 has_static_range (const struct range_bounds
*bounds
)
1040 /* If the range doesn't have a defined stride then its stride field will
1041 be initialized to the constant 0. */
1042 return (bounds
->low
.is_constant ()
1043 && bounds
->high
.is_constant ()
1044 && bounds
->stride
.is_constant ());
1047 /* See gdbtypes.h. */
1049 std::optional
<LONGEST
>
1050 get_discrete_low_bound (struct type
*type
)
1052 type
= check_typedef (type
);
1053 switch (type
->code ())
1055 case TYPE_CODE_RANGE
:
1057 /* This function only works for ranges with a constant low bound. */
1058 if (!type
->bounds ()->low
.is_constant ())
1061 LONGEST low
= type
->bounds ()->low
.const_val ();
1063 if (type
->target_type ()->code () == TYPE_CODE_ENUM
)
1065 std::optional
<LONGEST
> low_pos
1066 = discrete_position (type
->target_type (), low
);
1068 if (low_pos
.has_value ())
1075 case TYPE_CODE_ENUM
:
1077 if (type
->num_fields () > 0)
1079 /* The enums may not be sorted by value, so search all
1081 LONGEST low
= type
->field (0).loc_enumval ();
1083 for (int i
= 0; i
< type
->num_fields (); i
++)
1085 if (type
->field (i
).loc_enumval () < low
)
1086 low
= type
->field (i
).loc_enumval ();
1095 case TYPE_CODE_BOOL
:
1099 if (type
->length () > sizeof (LONGEST
)) /* Too big */
1102 if (!type
->is_unsigned ())
1103 return -(1 << (type
->length () * TARGET_CHAR_BIT
- 1));
1106 case TYPE_CODE_CHAR
:
1114 /* See gdbtypes.h. */
1116 std::optional
<LONGEST
>
1117 get_discrete_high_bound (struct type
*type
)
1119 type
= check_typedef (type
);
1120 switch (type
->code ())
1122 case TYPE_CODE_RANGE
:
1124 /* This function only works for ranges with a constant high bound. */
1125 if (!type
->bounds ()->high
.is_constant ())
1128 LONGEST high
= type
->bounds ()->high
.const_val ();
1130 if (type
->target_type ()->code () == TYPE_CODE_ENUM
)
1132 std::optional
<LONGEST
> high_pos
1133 = discrete_position (type
->target_type (), high
);
1135 if (high_pos
.has_value ())
1142 case TYPE_CODE_ENUM
:
1144 if (type
->num_fields () > 0)
1146 /* The enums may not be sorted by value, so search all
1148 LONGEST high
= type
->field (0).loc_enumval ();
1150 for (int i
= 0; i
< type
->num_fields (); i
++)
1152 if (type
->field (i
).loc_enumval () > high
)
1153 high
= type
->field (i
).loc_enumval ();
1162 case TYPE_CODE_BOOL
:
1166 if (type
->length () > sizeof (LONGEST
)) /* Too big */
1169 if (!type
->is_unsigned ())
1171 LONGEST low
= -(1 << (type
->length () * TARGET_CHAR_BIT
- 1));
1176 case TYPE_CODE_CHAR
:
1178 /* This round-about calculation is to avoid shifting by
1179 type->length () * TARGET_CHAR_BIT, which will not work
1180 if type->length () == sizeof (LONGEST). */
1181 LONGEST high
= 1 << (type
->length () * TARGET_CHAR_BIT
- 1);
1182 return (high
- 1) | high
;
1190 /* See gdbtypes.h. */
1193 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
1195 std::optional
<LONGEST
> low
= get_discrete_low_bound (type
);
1196 if (!low
.has_value ())
1199 std::optional
<LONGEST
> high
= get_discrete_high_bound (type
);
1200 if (!high
.has_value ())
1209 /* See gdbtypes.h */
1212 get_array_bounds (struct type
*type
, LONGEST
*low_bound
, LONGEST
*high_bound
)
1214 struct type
*index
= type
->index_type ();
1221 if (!get_discrete_bounds (index
, &low
, &high
))
1233 /* Assuming that TYPE is a discrete type and VAL is a valid integer
1234 representation of a value of this type, save the corresponding
1235 position number in POS.
1237 Its differs from VAL only in the case of enumeration types. In
1238 this case, the position number of the value of the first listed
1239 enumeration literal is zero; the position number of the value of
1240 each subsequent enumeration literal is one more than that of its
1241 predecessor in the list.
1243 Return 1 if the operation was successful. Return zero otherwise,
1244 in which case the value of POS is unmodified.
1247 std::optional
<LONGEST
>
1248 discrete_position (struct type
*type
, LONGEST val
)
1250 if (type
->code () == TYPE_CODE_RANGE
)
1251 type
= type
->target_type ();
1253 if (type
->code () == TYPE_CODE_ENUM
)
1257 for (i
= 0; i
< type
->num_fields (); i
+= 1)
1259 if (val
== type
->field (i
).loc_enumval ())
1263 /* Invalid enumeration value. */
1270 /* If the array TYPE has static bounds calculate and update its
1271 size, then return true. Otherwise return false and leave TYPE
1275 update_static_array_size (struct type
*type
)
1277 gdb_assert (type
->code () == TYPE_CODE_ARRAY
);
1279 struct type
*range_type
= type
->index_type ();
1281 if (type
->dyn_prop (DYN_PROP_BYTE_STRIDE
) == nullptr
1282 && has_static_range (range_type
->bounds ())
1283 && (!type_not_associated (type
)
1284 && !type_not_allocated (type
)))
1286 LONGEST low_bound
, high_bound
;
1288 struct type
*element_type
;
1290 stride
= type
->bit_stride ();
1292 if (!get_discrete_bounds (range_type
, &low_bound
, &high_bound
))
1293 low_bound
= high_bound
= 0;
1295 element_type
= check_typedef (type
->target_type ());
1296 /* Be careful when setting the array length. Ada arrays can be
1297 empty arrays with the high_bound being smaller than the low_bound.
1298 In such cases, the array length should be zero. */
1299 if (high_bound
< low_bound
)
1300 type
->set_length (0);
1301 else if (stride
!= 0)
1303 /* Ensure that the type length is always positive, even in the
1304 case where (for example in Fortran) we have a negative
1305 stride. It is possible to have a single element array with a
1306 negative stride in Fortran (this doesn't mean anything
1307 special, it's still just a single element array) so do
1308 consider that case when touching this code. */
1309 LONGEST element_count
= std::abs (high_bound
- low_bound
+ 1);
1310 type
->set_length (((std::abs (stride
) * element_count
) + 7) / 8);
1313 type
->set_length (element_type
->length ()
1314 * (high_bound
- low_bound
+ 1));
1316 /* If this array's element is itself an array with a bit stride,
1317 then we want to update this array's bit stride to reflect the
1318 size of the sub-array. Otherwise, we'll end up using the
1319 wrong size when trying to find elements of the outer
1321 if (element_type
->code () == TYPE_CODE_ARRAY
1322 && (stride
!= 0 || element_type
->is_multi_dimensional ())
1323 && element_type
->length () != 0
1324 && element_type
->field (0).bitsize () != 0
1325 && get_array_bounds (element_type
, &low_bound
, &high_bound
)
1326 && high_bound
>= low_bound
)
1327 type
->field (0).set_bitsize
1328 ((high_bound
- low_bound
+ 1)
1329 * element_type
->field (0).bitsize ());
1337 /* See gdbtypes.h. */
1340 create_array_type_with_stride (type_allocator
&alloc
,
1341 struct type
*element_type
,
1342 struct type
*range_type
,
1343 struct dynamic_prop
*byte_stride_prop
,
1344 unsigned int bit_stride
)
1346 if (byte_stride_prop
!= nullptr && byte_stride_prop
->is_constant ())
1348 /* The byte stride is actually not dynamic. Pretend we were
1349 called with bit_stride set instead of byte_stride_prop.
1350 This will give us the same result type, while avoiding
1351 the need to handle this as a special case. */
1352 bit_stride
= byte_stride_prop
->const_val () * 8;
1353 byte_stride_prop
= NULL
;
1356 struct type
*result_type
= alloc
.new_type ();
1358 result_type
->set_code (TYPE_CODE_ARRAY
);
1359 result_type
->set_target_type (element_type
);
1361 result_type
->alloc_fields (1);
1362 result_type
->set_index_type (range_type
);
1363 if (byte_stride_prop
!= NULL
)
1364 result_type
->add_dyn_prop (DYN_PROP_BYTE_STRIDE
, *byte_stride_prop
);
1365 else if (bit_stride
> 0)
1366 result_type
->field (0).set_bitsize (bit_stride
);
1368 if (!update_static_array_size (result_type
))
1370 /* This type is dynamic and its length needs to be computed
1371 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1372 undefined by setting it to zero. Although we are not expected
1373 to trust TYPE_LENGTH in this case, setting the size to zero
1374 allows us to avoid allocating objects of random sizes in case
1375 we accidentally do. */
1376 result_type
->set_length (0);
1379 /* TYPE_TARGET_STUB will take care of zero length arrays. */
1380 if (result_type
->length () == 0)
1381 result_type
->set_target_is_stub (true);
1386 /* See gdbtypes.h. */
1389 create_array_type (type_allocator
&alloc
,
1390 struct type
*element_type
,
1391 struct type
*range_type
)
1393 return create_array_type_with_stride (alloc
, element_type
,
1394 range_type
, NULL
, 0);
1398 lookup_array_range_type (struct type
*element_type
,
1399 LONGEST low_bound
, LONGEST high_bound
)
1401 struct type
*index_type
;
1402 struct type
*range_type
;
1404 type_allocator
alloc (element_type
);
1405 index_type
= builtin_type (element_type
->arch ())->builtin_int
;
1407 range_type
= create_static_range_type (alloc
, index_type
,
1408 low_bound
, high_bound
);
1410 return create_array_type (alloc
, element_type
, range_type
);
1413 /* See gdbtypes.h. */
1416 create_string_type (type_allocator
&alloc
,
1417 struct type
*string_char_type
,
1418 struct type
*range_type
)
1420 struct type
*result_type
= create_array_type (alloc
,
1423 result_type
->set_code (TYPE_CODE_STRING
);
1428 lookup_string_range_type (struct type
*string_char_type
,
1429 LONGEST low_bound
, LONGEST high_bound
)
1431 struct type
*result_type
;
1433 result_type
= lookup_array_range_type (string_char_type
,
1434 low_bound
, high_bound
);
1435 result_type
->set_code (TYPE_CODE_STRING
);
1440 create_set_type (type_allocator
&alloc
, struct type
*domain_type
)
1442 struct type
*result_type
= alloc
.new_type ();
1444 result_type
->set_code (TYPE_CODE_SET
);
1445 result_type
->alloc_fields (1);
1447 if (!domain_type
->is_stub ())
1449 LONGEST low_bound
, high_bound
, bit_length
;
1451 if (!get_discrete_bounds (domain_type
, &low_bound
, &high_bound
))
1452 low_bound
= high_bound
= 0;
1454 bit_length
= high_bound
- low_bound
+ 1;
1455 result_type
->set_length ((bit_length
+ TARGET_CHAR_BIT
- 1)
1458 result_type
->set_is_unsigned (true);
1460 result_type
->field (0).set_type (domain_type
);
1465 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1466 and any array types nested inside it. */
1469 make_vector_type (struct type
*array_type
)
1471 struct type
*inner_array
, *elt_type
;
1473 /* Find the innermost array type, in case the array is
1474 multi-dimensional. */
1475 inner_array
= array_type
;
1476 while (inner_array
->target_type ()->code () == TYPE_CODE_ARRAY
)
1477 inner_array
= inner_array
->target_type ();
1479 elt_type
= inner_array
->target_type ();
1480 if (elt_type
->code () == TYPE_CODE_INT
)
1482 type_instance_flags flags
1483 = elt_type
->instance_flags () | TYPE_INSTANCE_FLAG_NOTTEXT
;
1484 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
1485 inner_array
->set_target_type (elt_type
);
1488 array_type
->set_is_vector (true);
1492 init_vector_type (struct type
*elt_type
, int n
)
1494 struct type
*array_type
;
1496 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
1497 make_vector_type (array_type
);
1501 /* Internal routine called by TYPE_SELF_TYPE to return the type that TYPE
1502 belongs to. In c++ this is the class of "this", but TYPE_THIS_TYPE is too
1503 confusing. "self" is a common enough replacement for "this".
1504 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1505 TYPE_CODE_METHOD. */
1508 internal_type_self_type (struct type
*type
)
1510 switch (type
->code ())
1512 case TYPE_CODE_METHODPTR
:
1513 case TYPE_CODE_MEMBERPTR
:
1514 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1516 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1517 return TYPE_MAIN_TYPE (type
)->type_specific
.self_type
;
1518 case TYPE_CODE_METHOD
:
1519 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1521 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1522 return TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
;
1524 gdb_assert_not_reached ("bad type");
1528 /* Set the type of the class that TYPE belongs to.
1529 In c++ this is the class of "this".
1530 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1531 TYPE_CODE_METHOD. */
1534 set_type_self_type (struct type
*type
, struct type
*self_type
)
1536 switch (type
->code ())
1538 case TYPE_CODE_METHODPTR
:
1539 case TYPE_CODE_MEMBERPTR
:
1540 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1541 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_SELF_TYPE
;
1542 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1543 TYPE_MAIN_TYPE (type
)->type_specific
.self_type
= self_type
;
1545 case TYPE_CODE_METHOD
:
1546 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1547 INIT_FUNC_SPECIFIC (type
);
1548 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1549 TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
= self_type
;
1552 gdb_assert_not_reached ("bad type");
1556 /* Smash TYPE to be a type of pointers to members of SELF_TYPE with type
1557 TO_TYPE. A member pointer is a weird thing -- it amounts to a
1558 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1559 TYPE doesn't include the offset (that's the value of the MEMBER
1560 itself), but does include the structure type into which it points
1563 When "smashing" the type, we preserve the objfile that the old type
1564 pointed to, since we aren't changing where the type is actually
1568 smash_to_memberptr_type (struct type
*type
, struct type
*self_type
,
1569 struct type
*to_type
)
1572 type
->set_code (TYPE_CODE_MEMBERPTR
);
1573 type
->set_target_type (to_type
);
1574 set_type_self_type (type
, self_type
);
1575 /* Assume that a data member pointer is the same size as a normal
1577 type
->set_length (gdbarch_ptr_bit (to_type
->arch ()) / TARGET_CHAR_BIT
);
1580 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1582 When "smashing" the type, we preserve the objfile that the old type
1583 pointed to, since we aren't changing where the type is actually
1587 smash_to_methodptr_type (struct type
*type
, struct type
*to_type
)
1590 type
->set_code (TYPE_CODE_METHODPTR
);
1591 type
->set_target_type (to_type
);
1592 set_type_self_type (type
, TYPE_SELF_TYPE (to_type
));
1593 type
->set_length (cplus_method_ptr_size (to_type
));
1596 /* Smash TYPE to be a type of method of SELF_TYPE with type TO_TYPE.
1597 METHOD just means `function that gets an extra "this" argument'.
1599 When "smashing" the type, we preserve the objfile that the old type
1600 pointed to, since we aren't changing where the type is actually
1604 smash_to_method_type (struct type
*type
, struct type
*self_type
,
1605 struct type
*to_type
, struct field
*args
,
1606 int nargs
, int varargs
)
1609 type
->set_code (TYPE_CODE_METHOD
);
1610 type
->set_target_type (to_type
);
1611 set_type_self_type (type
, self_type
);
1612 type
->set_fields (args
);
1613 type
->set_num_fields (nargs
);
1616 type
->set_has_varargs (true);
1618 /* In practice, this is never needed. */
1619 type
->set_length (1);
1622 /* A wrapper of TYPE_NAME which calls error if the type is anonymous.
1623 Since GCC PR debug/47510 DWARF provides associated information to detect the
1624 anonymous class linkage name from its typedef.
1626 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1630 type_name_or_error (struct type
*type
)
1632 struct type
*saved_type
= type
;
1634 struct objfile
*objfile
;
1636 type
= check_typedef (type
);
1638 name
= type
->name ();
1642 name
= saved_type
->name ();
1643 objfile
= saved_type
->objfile_owner ();
1644 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1645 name
? name
: "<anonymous>",
1646 objfile
? objfile_name (objfile
) : "<arch>");
1649 /* See gdbtypes.h. */
1652 lookup_typename (const struct language_defn
*language
,
1654 const struct block
*block
, int noerr
)
1658 sym
= lookup_symbol_in_language (name
, block
, SEARCH_TYPE_DOMAIN
,
1659 language
->la_language
, NULL
).symbol
;
1662 struct type
*type
= sym
->type ();
1663 /* Ensure the length of TYPE is valid. */
1664 check_typedef (type
);
1670 error (_("No type named %s."), name
);
1674 lookup_unsigned_typename (const struct language_defn
*language
,
1678 uns
.reserve (strlen (name
) + strlen ("unsigned "));
1682 return lookup_typename (language
, uns
.c_str (), NULL
, 0);
1686 lookup_signed_typename (const struct language_defn
*language
, const char *name
)
1688 /* In C and C++, "char" and "signed char" are distinct types. */
1689 if (streq (name
, "char"))
1690 name
= "signed char";
1691 return lookup_typename (language
, name
, NULL
, 0);
1694 /* Lookup a structure type named "struct NAME",
1695 visible in lexical block BLOCK. */
1698 lookup_struct (const char *name
, const struct block
*block
)
1702 sym
= lookup_symbol (name
, block
, SEARCH_STRUCT_DOMAIN
, 0).symbol
;
1706 error (_("No struct type named %s."), name
);
1708 if (sym
->type ()->code () != TYPE_CODE_STRUCT
)
1710 error (_("This context has class, union or enum %s, not a struct."),
1713 return (sym
->type ());
1716 /* Lookup a union type named "union NAME",
1717 visible in lexical block BLOCK. */
1720 lookup_union (const char *name
, const struct block
*block
)
1725 sym
= lookup_symbol (name
, block
, SEARCH_STRUCT_DOMAIN
, 0).symbol
;
1728 error (_("No union type named %s."), name
);
1732 if (t
->code () == TYPE_CODE_UNION
)
1735 /* If we get here, it's not a union. */
1736 error (_("This context has class, struct or enum %s, not a union."),
1740 /* Lookup an enum type named "enum NAME",
1741 visible in lexical block BLOCK. */
1744 lookup_enum (const char *name
, const struct block
*block
)
1748 sym
= lookup_symbol (name
, block
, SEARCH_STRUCT_DOMAIN
, 0).symbol
;
1751 error (_("No enum type named %s."), name
);
1753 if (sym
->type ()->code () != TYPE_CODE_ENUM
)
1755 error (_("This context has class, struct or union %s, not an enum."),
1758 return (sym
->type ());
1761 /* Lookup a template type named "template NAME<TYPE>",
1762 visible in lexical block BLOCK. */
1765 lookup_template_type (const char *name
, struct type
*type
,
1766 const struct block
*block
)
1769 nam
.reserve (strlen (name
) + strlen (type
->name ()) + strlen ("< >"));
1772 nam
+= type
->name ();
1773 nam
+= " >"; /* FIXME, extra space still introduced in gcc? */
1775 symbol
*sym
= lookup_symbol (nam
.c_str (), block
,
1776 SEARCH_STRUCT_DOMAIN
, 0).symbol
;
1780 error (_("No template type named %s."), name
);
1782 if (sym
->type ()->code () != TYPE_CODE_STRUCT
)
1784 error (_("This context has class, union or enum %s, not a struct."),
1787 return (sym
->type ());
1790 /* See gdbtypes.h. */
1793 lookup_struct_elt (struct type
*type
, const char *name
, int noerr
)
1799 type
= check_typedef (type
);
1800 if (type
->code () != TYPE_CODE_PTR
1801 && type
->code () != TYPE_CODE_REF
)
1803 type
= type
->target_type ();
1806 if (type
->code () != TYPE_CODE_STRUCT
1807 && type
->code () != TYPE_CODE_UNION
)
1809 std::string type_name
= type_to_string (type
);
1810 error (_("Type %s is not a structure or union type."),
1811 type_name
.c_str ());
1814 for (i
= type
->num_fields () - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1816 const char *t_field_name
= type
->field (i
).name ();
1818 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1820 return {&type
->field (i
), type
->field (i
).loc_bitpos ()};
1822 else if (!t_field_name
|| *t_field_name
== '\0')
1825 = lookup_struct_elt (type
->field (i
).type (), name
, 1);
1826 if (elt
.field
!= NULL
)
1828 elt
.offset
+= type
->field (i
).loc_bitpos ();
1834 /* OK, it's not in this class. Recursively check the baseclasses. */
1835 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1837 struct_elt elt
= lookup_struct_elt (TYPE_BASECLASS (type
, i
), name
, 1);
1838 if (elt
.field
!= NULL
)
1843 return {nullptr, 0};
1845 std::string type_name
= type_to_string (type
);
1846 error (_("Type %s has no component named %s."), type_name
.c_str (), name
);
1849 /* See gdbtypes.h. */
1852 lookup_struct_elt_type (struct type
*type
, const char *name
, int noerr
)
1854 struct_elt elt
= lookup_struct_elt (type
, name
, noerr
);
1855 if (elt
.field
!= NULL
)
1856 return elt
.field
->type ();
1861 /* Return the largest number representable by unsigned integer type TYPE. */
1864 get_unsigned_type_max (struct type
*type
)
1868 type
= check_typedef (type
);
1869 gdb_assert (type
->code () == TYPE_CODE_INT
&& type
->is_unsigned ());
1870 gdb_assert (type
->length () <= sizeof (ULONGEST
));
1872 /* Written this way to avoid overflow. */
1873 n
= type
->length () * TARGET_CHAR_BIT
;
1874 return ((((ULONGEST
) 1 << (n
- 1)) - 1) << 1) | 1;
1877 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1878 signed integer type TYPE. */
1881 get_signed_type_minmax (struct type
*type
, LONGEST
*min
, LONGEST
*max
)
1885 type
= check_typedef (type
);
1886 gdb_assert (type
->code () == TYPE_CODE_INT
&& !type
->is_unsigned ());
1887 gdb_assert (type
->length () <= sizeof (LONGEST
));
1889 n
= type
->length () * TARGET_CHAR_BIT
;
1890 *min
= -((ULONGEST
) 1 << (n
- 1));
1891 *max
= ((ULONGEST
) 1 << (n
- 1)) - 1;
1894 /* Return the largest value representable by pointer type TYPE. */
1897 get_pointer_type_max (struct type
*type
)
1901 type
= check_typedef (type
);
1902 gdb_assert (type
->code () == TYPE_CODE_PTR
);
1903 gdb_assert (type
->length () <= sizeof (CORE_ADDR
));
1905 n
= type
->length () * TARGET_CHAR_BIT
;
1906 return ((((CORE_ADDR
) 1 << (n
- 1)) - 1) << 1) | 1;
1909 /* Internal routine called by TYPE_VPTR_FIELDNO to return the value of
1910 cplus_stuff.vptr_fieldno.
1912 cplus_stuff is initialized to cplus_struct_default which does not
1913 set vptr_fieldno to -1 for portability reasons (IWBN to use C99
1914 designated initializers). We cope with that here. */
1917 internal_type_vptr_fieldno (struct type
*type
)
1919 type
= check_typedef (type
);
1920 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1921 || type
->code () == TYPE_CODE_UNION
);
1922 if (!HAVE_CPLUS_STRUCT (type
))
1924 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
;
1927 /* Set the value of cplus_stuff.vptr_fieldno. */
1930 set_type_vptr_fieldno (struct type
*type
, int fieldno
)
1932 type
= check_typedef (type
);
1933 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1934 || type
->code () == TYPE_CODE_UNION
);
1935 if (!HAVE_CPLUS_STRUCT (type
))
1936 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1937 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
= fieldno
;
1940 /* Internal routine called by TYPE_VPTR_BASETYPE to return the value of
1941 cplus_stuff.vptr_basetype. */
1944 internal_type_vptr_basetype (struct type
*type
)
1946 type
= check_typedef (type
);
1947 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1948 || type
->code () == TYPE_CODE_UNION
);
1949 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_CPLUS_STUFF
);
1950 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
;
1953 /* Set the value of cplus_stuff.vptr_basetype. */
1956 set_type_vptr_basetype (struct type
*type
, struct type
*basetype
)
1958 type
= check_typedef (type
);
1959 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1960 || type
->code () == TYPE_CODE_UNION
);
1961 if (!HAVE_CPLUS_STRUCT (type
))
1962 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1963 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
= basetype
;
1966 /* Lookup the vptr basetype/fieldno values for TYPE.
1967 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1968 vptr_fieldno. Also, if found and basetype is from the same objfile,
1970 If not found, return -1 and ignore BASETYPEP.
1971 Callers should be aware that in some cases (for example,
1972 the type or one of its baseclasses is a stub type and we are
1973 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1974 this function will not be able to find the
1975 virtual function table pointer, and vptr_fieldno will remain -1 and
1976 vptr_basetype will remain NULL or incomplete. */
1979 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1981 type
= check_typedef (type
);
1983 if (TYPE_VPTR_FIELDNO (type
) < 0)
1987 /* We must start at zero in case the first (and only) baseclass
1988 is virtual (and hence we cannot share the table pointer). */
1989 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1991 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1993 struct type
*basetype
;
1995 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1998 /* If the type comes from a different objfile we can't cache
1999 it, it may have a different lifetime. PR 2384 */
2000 if (type
->objfile_owner () == basetype
->objfile_owner ())
2002 set_type_vptr_fieldno (type
, fieldno
);
2003 set_type_vptr_basetype (type
, basetype
);
2006 *basetypep
= basetype
;
2017 *basetypep
= TYPE_VPTR_BASETYPE (type
);
2018 return TYPE_VPTR_FIELDNO (type
);
2023 stub_noname_complaint (void)
2025 complaint (_("stub type has NULL name"));
2028 /* Return nonzero if TYPE has a DYN_PROP_BYTE_STRIDE dynamic property
2029 attached to it, and that property has a non-constant value. */
2032 array_type_has_dynamic_stride (struct type
*type
)
2034 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_BYTE_STRIDE
);
2036 return prop
!= nullptr && prop
->is_constant ();
2039 /* Worker for is_dynamic_type. */
2042 is_dynamic_type_internal (struct type
*type
, bool top_level
)
2044 type
= check_typedef (type
);
2046 /* We only want to recognize references and pointers at the outermost
2048 if (top_level
&& type
->is_pointer_or_reference ())
2049 type
= check_typedef (type
->target_type ());
2051 /* Types that have a dynamic TYPE_DATA_LOCATION are considered
2052 dynamic, even if the type itself is statically defined.
2053 From a user's point of view, this may appear counter-intuitive;
2054 but it makes sense in this context, because the point is to determine
2055 whether any part of the type needs to be resolved before it can
2057 if (TYPE_DATA_LOCATION (type
) != NULL
2058 && (TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCEXPR
2059 || TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCLIST
))
2062 if (TYPE_ASSOCIATED_PROP (type
))
2065 if (TYPE_ALLOCATED_PROP (type
))
2068 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
2069 if (prop
!= nullptr && prop
->kind () != PROP_TYPE
)
2072 if (TYPE_HAS_DYNAMIC_LENGTH (type
))
2075 switch (type
->code ())
2077 case TYPE_CODE_RANGE
:
2079 /* A range type is obviously dynamic if it has at least one
2080 dynamic bound. But also consider the range type to be
2081 dynamic when its subtype is dynamic, even if the bounds
2082 of the range type are static. It allows us to assume that
2083 the subtype of a static range type is also static. */
2084 return (!has_static_range (type
->bounds ())
2085 || is_dynamic_type_internal (type
->target_type (), false));
2088 case TYPE_CODE_STRING
:
2089 /* Strings are very much like an array of characters, and can be
2090 treated as one here. */
2091 case TYPE_CODE_ARRAY
:
2093 gdb_assert (type
->num_fields () == 1);
2095 /* The array is dynamic if either the bounds are dynamic... */
2096 if (is_dynamic_type_internal (type
->index_type (), false))
2098 /* ... or the elements it contains have a dynamic contents... */
2099 if (is_dynamic_type_internal (type
->target_type (), false))
2101 /* ... or if it has a dynamic stride... */
2102 if (array_type_has_dynamic_stride (type
))
2107 case TYPE_CODE_STRUCT
:
2108 case TYPE_CODE_UNION
:
2112 bool is_cplus
= HAVE_CPLUS_STRUCT (type
);
2114 for (i
= 0; i
< type
->num_fields (); ++i
)
2116 /* Static fields can be ignored here. */
2117 if (type
->field (i
).is_static ())
2119 /* If the field has dynamic type, then so does TYPE. */
2120 if (is_dynamic_type_internal (type
->field (i
).type (), false))
2122 /* If the field is at a fixed offset, then it is not
2124 if (!type
->field (i
).loc_is_dwarf_block ())
2126 /* Do not consider C++ virtual base types to be dynamic
2127 due to the field's offset being dynamic; these are
2128 handled via other means. */
2129 if (is_cplus
&& BASETYPE_VIA_VIRTUAL (type
, i
))
2140 /* See gdbtypes.h. */
2143 is_dynamic_type (struct type
*type
)
2145 return is_dynamic_type_internal (type
, true);
2148 static struct type
*resolve_dynamic_type_internal
2149 (struct type
*type
, const property_addr_info
*addr_stack
,
2150 const frame_info_ptr
&frame
, bool top_level
);
2152 /* Given a dynamic range type (dyn_range_type) and a stack of
2153 struct property_addr_info elements, return a static version
2156 When RESOLVE_P is true then the returned static range is created by
2157 actually evaluating any dynamic properties within the range type, while
2158 when RESOLVE_P is false the returned static range has all of the bounds
2159 and stride information set to undefined. The RESOLVE_P set to false
2160 case will be used when evaluating a dynamic array that is not
2161 allocated, or not associated, i.e. the bounds information might not be
2164 RANK is the array rank for which we are resolving this range, and is a
2165 zero based count. The rank should never be negative.
2168 static struct type
*
2169 resolve_dynamic_range (struct type
*dyn_range_type
,
2170 const property_addr_info
*addr_stack
,
2171 const frame_info_ptr
&frame
,
2172 int rank
, bool resolve_p
= true)
2175 struct type
*static_range_type
, *static_target_type
;
2176 struct dynamic_prop low_bound
, high_bound
, stride
;
2178 gdb_assert (dyn_range_type
->code () == TYPE_CODE_RANGE
);
2179 gdb_assert (rank
>= 0);
2181 const struct dynamic_prop
*prop
= &dyn_range_type
->bounds ()->low
;
2184 if (dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
,
2185 { (CORE_ADDR
) rank
}))
2186 low_bound
.set_const_val (value
);
2187 else if (prop
->kind () == PROP_UNDEFINED
)
2188 low_bound
.set_undefined ();
2190 low_bound
.set_optimized_out ();
2193 low_bound
.set_undefined ();
2195 prop
= &dyn_range_type
->bounds ()->high
;
2198 if (dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
,
2199 { (CORE_ADDR
) rank
}))
2201 high_bound
.set_const_val (value
);
2203 if (dyn_range_type
->bounds ()->flag_upper_bound_is_count
)
2204 high_bound
.set_const_val
2205 (low_bound
.const_val () + high_bound
.const_val () - 1);
2207 else if (prop
->kind () == PROP_UNDEFINED
)
2208 high_bound
.set_undefined ();
2210 high_bound
.set_optimized_out ();
2213 high_bound
.set_undefined ();
2215 bool byte_stride_p
= dyn_range_type
->bounds ()->flag_is_byte_stride
;
2216 prop
= &dyn_range_type
->bounds ()->stride
;
2217 if (resolve_p
&& dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
,
2218 { (CORE_ADDR
) rank
}))
2220 stride
.set_const_val (value
);
2222 /* If we have a bit stride that is not an exact number of bytes then
2223 I really don't think this is going to work with current GDB, the
2224 array indexing code in GDB seems to be pretty heavily tied to byte
2225 offsets right now. Assuming 8 bits in a byte. */
2226 struct gdbarch
*gdbarch
= dyn_range_type
->arch ();
2227 int unit_size
= gdbarch_addressable_memory_unit_size (gdbarch
);
2228 if (!byte_stride_p
&& (value
% (unit_size
* 8)) != 0)
2229 error (_("bit strides that are not a multiple of the byte size "
2230 "are currently not supported"));
2234 stride
.set_undefined ();
2235 byte_stride_p
= true;
2239 = resolve_dynamic_type_internal (dyn_range_type
->target_type (),
2240 addr_stack
, frame
, false);
2241 LONGEST bias
= dyn_range_type
->bounds ()->bias
;
2242 type_allocator
alloc (dyn_range_type
);
2243 static_range_type
= create_range_type_with_stride
2244 (alloc
, static_target_type
,
2245 &low_bound
, &high_bound
, bias
, &stride
, byte_stride_p
);
2246 static_range_type
->set_name (dyn_range_type
->name ());
2247 static_range_type
->bounds ()->flag_bound_evaluated
= 1;
2248 return static_range_type
;
2251 /* Helper function for resolve_dynamic_array_or_string. This function
2252 resolves the properties for a single array at RANK within a nested array
2253 of arrays structure. The RANK value is greater than or equal to 0, and
2254 starts at it's maximum value and goes down by 1 for each recursive call
2255 to this function. So, for a 3-dimensional array, the first call to this
2256 function has RANK == 2, then we call ourselves recursively with RANK ==
2257 1, than again with RANK == 0, and at that point we should return.
2259 TYPE is updated as the dynamic properties are resolved, and so, should
2260 be a copy of the dynamic type, rather than the original dynamic type
2263 ADDR_STACK is a stack of struct property_addr_info to be used if needed
2264 during the dynamic resolution.
2266 When RESOLVE_P is true then the dynamic properties of TYPE are
2267 evaluated, otherwise the dynamic properties of TYPE are not evaluated,
2268 instead we assume the array is not allocated/associated yet. */
2270 static struct type
*
2271 resolve_dynamic_array_or_string_1 (struct type
*type
,
2272 const property_addr_info
*addr_stack
,
2273 const frame_info_ptr
&frame
,
2274 int rank
, bool resolve_p
)
2277 struct type
*elt_type
;
2278 struct type
*range_type
;
2279 struct type
*ary_dim
;
2280 struct dynamic_prop
*prop
;
2281 unsigned int bit_stride
= 0;
2283 /* For dynamic type resolution strings can be treated like arrays of
2285 gdb_assert (type
->code () == TYPE_CODE_ARRAY
2286 || type
->code () == TYPE_CODE_STRING
);
2288 /* As the rank is a zero based count we expect this to never be
2290 gdb_assert (rank
>= 0);
2292 /* Resolve the allocated and associated properties before doing anything
2293 else. If an array is not allocated or not associated then (at least
2294 for Fortran) there is no guarantee that the data to define the upper
2295 bound, lower bound, or stride will be correct. If RESOLVE_P is
2296 already false at this point then this is not the first dimension of
2297 the array and a more outer dimension has already marked this array as
2298 not allocated/associated, as such we just ignore this property. This
2299 is fine as GDB only checks the allocated/associated on the outer most
2300 dimension of the array. */
2301 prop
= TYPE_ALLOCATED_PROP (type
);
2302 if (prop
!= NULL
&& resolve_p
2303 && dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2305 prop
->set_const_val (value
);
2310 prop
= TYPE_ASSOCIATED_PROP (type
);
2311 if (prop
!= NULL
&& resolve_p
2312 && dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2314 prop
->set_const_val (value
);
2319 range_type
= check_typedef (type
->index_type ());
2321 = resolve_dynamic_range (range_type
, addr_stack
, frame
, rank
, resolve_p
);
2323 ary_dim
= check_typedef (type
->target_type ());
2324 if (ary_dim
!= NULL
&& ary_dim
->code () == TYPE_CODE_ARRAY
)
2326 ary_dim
= copy_type (ary_dim
);
2327 elt_type
= resolve_dynamic_array_or_string_1 (ary_dim
, addr_stack
,
2331 else if (ary_dim
!= nullptr && ary_dim
->code () == TYPE_CODE_STRING
)
2333 /* The following special case for TYPE_CODE_STRING should not be
2334 needed, ideally we would defer resolving the dynamic type of the
2335 array elements until needed later, and indeed, the resolved type
2336 of each array element might be different, so attempting to resolve
2337 the type here makes no sense.
2339 However, in Fortran, for arrays of strings, each element must be
2340 the same type, as such, the DWARF for the string length relies on
2341 the object address of the array itself.
2343 The problem here is that, when we create values from the dynamic
2344 array type, we resolve the data location, and use that as the
2345 value address, this completely discards the original value
2346 address, and it is this original value address that is the
2347 descriptor for the dynamic array, the very address that the DWARF
2348 needs us to push in order to resolve the dynamic string length.
2350 What this means then, is that, given the current state of GDB, if
2351 we don't resolve the string length now, then we will have lost
2352 access to the address of the dynamic object descriptor, and so we
2353 will not be able to resolve the dynamic string later.
2355 For now then, we handle special case TYPE_CODE_STRING on behalf of
2356 Fortran, and hope that this doesn't cause problems for anyone
2358 elt_type
= resolve_dynamic_type_internal (type
->target_type (),
2359 addr_stack
, frame
, 0);
2362 elt_type
= type
->target_type ();
2364 prop
= type
->dyn_prop (DYN_PROP_BYTE_STRIDE
);
2365 if (prop
!= nullptr && type
->code () == TYPE_CODE_STRING
)
2367 if (prop
!= NULL
&& resolve_p
)
2369 if (dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2371 type
->remove_dyn_prop (DYN_PROP_BYTE_STRIDE
);
2372 bit_stride
= (unsigned int) (value
* 8);
2376 /* Could be a bug in our code, but it could also happen
2377 if the DWARF info is not correct. Issue a warning,
2378 and assume no byte/bit stride (leave bit_stride = 0). */
2379 warning (_("cannot determine array stride for type %s"),
2380 type
->name () ? type
->name () : "<no name>");
2384 bit_stride
= type
->field (0).bitsize ();
2386 type_allocator
alloc (type
, type_allocator::SMASH
);
2387 if (type
->code () == TYPE_CODE_STRING
)
2388 return create_string_type (alloc
, elt_type
, range_type
);
2390 return create_array_type_with_stride (alloc
, elt_type
, range_type
, NULL
,
2394 /* Resolve an array or string type with dynamic properties, return a new
2395 type with the dynamic properties resolved to actual values. The
2396 ADDR_STACK represents the location of the object being resolved. */
2398 static struct type
*
2399 resolve_dynamic_array_or_string (struct type
*type
,
2400 const property_addr_info
*addr_stack
,
2401 const frame_info_ptr
&frame
)
2406 /* For dynamic type resolution strings can be treated like arrays of
2408 gdb_assert (type
->code () == TYPE_CODE_ARRAY
2409 || type
->code () == TYPE_CODE_STRING
);
2411 type
= copy_type (type
);
2413 /* Resolve the rank property to get rank value. */
2414 struct dynamic_prop
*prop
= TYPE_RANK_PROP (type
);
2415 if (dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2417 prop
->set_const_val (value
);
2422 /* Rank is zero, if a variable is passed as an argument to a
2423 function. In this case the resolved type should not be an
2424 array, but should instead be that of an array element. */
2425 struct type
*dynamic_array_type
= type
;
2426 type
= copy_type (dynamic_array_type
->target_type ());
2427 struct dynamic_prop_list
*prop_list
2428 = TYPE_MAIN_TYPE (dynamic_array_type
)->dyn_prop_list
;
2429 if (prop_list
!= nullptr)
2431 struct obstack
*obstack
2432 = &type
->objfile_owner ()->objfile_obstack
;
2433 TYPE_MAIN_TYPE (type
)->dyn_prop_list
2434 = copy_dynamic_prop_list (obstack
, prop_list
);
2438 else if (type
->code () == TYPE_CODE_STRING
&& rank
!= 1)
2440 /* What would this even mean? A string with a dynamic rank
2442 error (_("unable to handle string with dynamic rank greater than 1"));
2446 /* Arrays with dynamic rank are initially just an array type
2447 with a target type that is the array element.
2449 However, now we know the rank of the array we need to build
2450 the array of arrays structure that GDB expects, that is we
2451 need an array type that has a target which is an array type,
2452 and so on, until eventually, we have the element type at the
2453 end of the chain. Create all the additional array types here
2454 by copying the top level array type. */
2455 struct type
*element_type
= type
->target_type ();
2456 struct type
*rank_type
= type
;
2457 for (int i
= 1; i
< rank
; i
++)
2459 rank_type
->set_target_type (copy_type (rank_type
));
2460 rank_type
= rank_type
->target_type ();
2462 rank_type
->set_target_type (element_type
);
2469 for (struct type
*tmp_type
= check_typedef (type
->target_type ());
2470 tmp_type
->code () == TYPE_CODE_ARRAY
;
2471 tmp_type
= check_typedef (tmp_type
->target_type ()))
2475 /* The rank that we calculated above is actually a count of the number of
2476 ranks. However, when we resolve the type of each individual array
2477 rank we should actually use a rank "offset", e.g. an array with a rank
2478 count of 1 (calculated above) will use the rank offset 0 in order to
2479 resolve the details of the first array dimension. As a result, we
2480 reduce the rank by 1 here. */
2483 return resolve_dynamic_array_or_string_1 (type
, addr_stack
, frame
, rank
,
2487 /* Resolve dynamic bounds of members of the union TYPE to static
2488 bounds. ADDR_STACK is a stack of struct property_addr_info
2489 to be used if needed during the dynamic resolution. */
2491 static struct type
*
2492 resolve_dynamic_union (struct type
*type
,
2493 const property_addr_info
*addr_stack
,
2494 const frame_info_ptr
&frame
)
2496 struct type
*resolved_type
;
2498 unsigned int max_len
= 0;
2500 gdb_assert (type
->code () == TYPE_CODE_UNION
);
2502 resolved_type
= copy_type (type
);
2503 resolved_type
->copy_fields (type
);
2504 for (i
= 0; i
< resolved_type
->num_fields (); ++i
)
2508 if (type
->field (i
).is_static ())
2511 t
= resolve_dynamic_type_internal (resolved_type
->field (i
).type (),
2512 addr_stack
, frame
, false);
2513 resolved_type
->field (i
).set_type (t
);
2515 struct type
*real_type
= check_typedef (t
);
2516 if (real_type
->length () > max_len
)
2517 max_len
= real_type
->length ();
2520 resolved_type
->set_length (max_len
);
2521 return resolved_type
;
2524 /* See gdbtypes.h. */
2527 variant::matches (ULONGEST value
, bool is_unsigned
) const
2529 for (const discriminant_range
&range
: discriminants
)
2530 if (range
.contains (value
, is_unsigned
))
2536 compute_variant_fields_inner (struct type
*type
,
2537 const property_addr_info
*addr_stack
,
2538 const variant_part
&part
,
2539 std::vector
<bool> &flags
);
2541 /* A helper function to determine which variant fields will be active.
2542 This handles both the variant's direct fields, and any variant
2543 parts embedded in this variant. TYPE is the type we're examining.
2544 ADDR_STACK holds information about the concrete object. VARIANT is
2545 the current variant to be handled. FLAGS is where the results are
2546 stored -- this function sets the Nth element in FLAGS if the
2547 corresponding field is enabled. ENABLED is whether this variant is
2551 compute_variant_fields_recurse (struct type
*type
,
2552 const property_addr_info
*addr_stack
,
2553 const variant
&variant
,
2554 std::vector
<bool> &flags
,
2557 for (int field
= variant
.first_field
; field
< variant
.last_field
; ++field
)
2558 flags
[field
] = enabled
;
2560 for (const variant_part
&new_part
: variant
.parts
)
2563 compute_variant_fields_inner (type
, addr_stack
, new_part
, flags
);
2566 for (const auto &sub_variant
: new_part
.variants
)
2567 compute_variant_fields_recurse (type
, addr_stack
, sub_variant
,
2573 /* A helper function to determine which variant fields will be active.
2574 This evaluates the discriminant, decides which variant (if any) is
2575 active, and then updates FLAGS to reflect which fields should be
2576 available. TYPE is the type we're examining. ADDR_STACK holds
2577 information about the concrete object. VARIANT is the current
2578 variant to be handled. FLAGS is where the results are stored --
2579 this function sets the Nth element in FLAGS if the corresponding
2580 field is enabled. */
2583 compute_variant_fields_inner (struct type
*type
,
2584 const property_addr_info
*addr_stack
,
2585 const variant_part
&part
,
2586 std::vector
<bool> &flags
)
2588 /* Evaluate the discriminant. */
2589 std::optional
<ULONGEST
> discr_value
;
2590 if (part
.discriminant_index
!= -1)
2592 int idx
= part
.discriminant_index
;
2594 if (type
->field (idx
).loc_kind () != FIELD_LOC_KIND_BITPOS
)
2595 error (_("Cannot determine struct field location"
2596 " (invalid location kind)"));
2598 if (addr_stack
->valaddr
.data () != NULL
)
2599 discr_value
= unpack_field_as_long (type
, addr_stack
->valaddr
.data (),
2603 CORE_ADDR addr
= (addr_stack
->addr
2604 + (type
->field (idx
).loc_bitpos ()
2605 / TARGET_CHAR_BIT
));
2607 LONGEST bitsize
= type
->field (idx
).bitsize ();
2608 LONGEST size
= bitsize
/ 8;
2610 size
= type
->field (idx
).type ()->length ();
2612 gdb_byte bits
[sizeof (ULONGEST
)];
2613 read_memory (addr
, bits
, size
);
2615 LONGEST bitpos
= (type
->field (idx
).loc_bitpos ()
2618 discr_value
= unpack_bits_as_long (type
->field (idx
).type (),
2619 bits
, bitpos
, bitsize
);
2623 /* Go through each variant and see which applies. */
2624 const variant
*default_variant
= nullptr;
2625 const variant
*applied_variant
= nullptr;
2626 for (const auto &variant
: part
.variants
)
2628 if (variant
.is_default ())
2629 default_variant
= &variant
;
2630 else if (discr_value
.has_value ()
2631 && variant
.matches (*discr_value
, part
.is_unsigned
))
2633 applied_variant
= &variant
;
2637 if (applied_variant
== nullptr)
2638 applied_variant
= default_variant
;
2640 for (const auto &variant
: part
.variants
)
2641 compute_variant_fields_recurse (type
, addr_stack
, variant
,
2642 flags
, applied_variant
== &variant
);
2645 /* Determine which variant fields are available in TYPE. The enabled
2646 fields are stored in RESOLVED_TYPE. ADDR_STACK holds information
2647 about the concrete object. PARTS describes the top-level variant
2648 parts for this type. */
2651 compute_variant_fields (struct type
*type
,
2652 struct type
*resolved_type
,
2653 const property_addr_info
*addr_stack
,
2654 const gdb::array_view
<variant_part
> &parts
)
2656 /* Assume all fields are included by default. */
2657 std::vector
<bool> flags (resolved_type
->num_fields (), true);
2659 /* Now disable fields based on the variants that control them. */
2660 for (const auto &part
: parts
)
2661 compute_variant_fields_inner (type
, addr_stack
, part
, flags
);
2663 unsigned int nfields
= std::count (flags
.begin (), flags
.end (), true);
2664 /* No need to zero-initialize the newly allocated fields, they'll be
2665 initialized by the copy in the loop below. */
2666 resolved_type
->alloc_fields (nfields
, false);
2669 for (int i
= 0; i
< type
->num_fields (); ++i
)
2674 resolved_type
->field (out
) = type
->field (i
);
2679 /* See gdbtypes.h. */
2682 apply_bit_offset_to_field (struct field
&field
, LONGEST bit_offset
,
2683 LONGEST explicit_byte_size
)
2685 struct type
*field_type
= field
.type ();
2686 struct gdbarch
*gdbarch
= field_type
->arch ();
2687 LONGEST current_bitpos
= field
.loc_bitpos ();
2689 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
2691 /* For big endian bits, the DW_AT_bit_offset gives the
2692 additional bit offset from the MSB of the containing
2693 anonymous object to the MSB of the field. We don't
2694 have to do anything special since we don't need to
2695 know the size of the anonymous object. */
2696 field
.set_loc_bitpos (current_bitpos
+ bit_offset
);
2700 /* For little endian bits, compute the bit offset to the
2701 MSB of the anonymous object, subtract off the number of
2702 bits from the MSB of the field to the MSB of the
2703 object, and then subtract off the number of bits of
2704 the field itself. The result is the bit offset of
2705 the LSB of the field. */
2706 LONGEST object_size
= explicit_byte_size
;
2707 if (object_size
== 0)
2708 object_size
= field_type
->length ();
2710 field
.set_loc_bitpos (current_bitpos
2713 - field
.bitsize ());
2717 /* See gdbtypes.h. */
2720 resolve_dynamic_field (struct field
&field
,
2721 const property_addr_info
*addr_stack
,
2722 const frame_info_ptr
&frame
)
2724 gdb_assert (!field
.is_static ());
2726 if (field
.loc_is_dwarf_block ())
2728 dwarf2_locexpr_baton
*field_loc
2729 = field
.loc_dwarf_block ();
2731 struct dwarf2_property_baton baton
;
2732 baton
.property_type
= lookup_pointer_type (field
.type ());
2733 baton
.locexpr
= *field_loc
;
2735 struct dynamic_prop prop
;
2736 prop
.set_locexpr (&baton
);
2738 CORE_ADDR vals
[1] = {addr_stack
->addr
};
2739 CORE_ADDR addr_or_bitpos
;
2740 if (dwarf2_evaluate_property (&prop
, frame
, addr_stack
,
2741 &addr_or_bitpos
, vals
))
2743 if (field
.loc_kind () == FIELD_LOC_KIND_DWARF_BLOCK_ADDR
)
2744 field
.set_loc_bitpos (TARGET_CHAR_BIT
2745 * (addr_or_bitpos
- addr_stack
->addr
));
2747 field
.set_loc_bitpos (addr_or_bitpos
);
2749 if (field_loc
->is_field_location
)
2751 dwarf2_field_location_baton
*fl_baton
2752 = static_cast<dwarf2_field_location_baton
*> (field_loc
);
2753 apply_bit_offset_to_field (field
, fl_baton
->bit_offset
,
2754 fl_baton
->explicit_byte_size
);
2759 /* As we know this field is not a static field, the field's
2760 field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
2761 this is the case, but only trigger a simple error rather
2762 than an internal error if that fails. While failing
2763 that verification indicates a bug in our code, the error
2764 is not severe enough to suggest to the user he stops
2765 his debugging session because of it. */
2766 if (field
.loc_kind () != FIELD_LOC_KIND_BITPOS
)
2767 error (_("Cannot determine struct field location"
2768 " (invalid location kind)"));
2770 struct property_addr_info pinfo
;
2771 pinfo
.type
= check_typedef (field
.type ());
2772 size_t offset
= field
.loc_bitpos () / TARGET_CHAR_BIT
;
2773 pinfo
.valaddr
= addr_stack
->valaddr
;
2774 if (!pinfo
.valaddr
.empty ())
2775 pinfo
.valaddr
= pinfo
.valaddr
.slice (offset
);
2776 pinfo
.addr
= addr_stack
->addr
+ offset
;
2777 pinfo
.next
= addr_stack
;
2779 field
.set_type (resolve_dynamic_type_internal (field
.type (),
2780 &pinfo
, frame
, false));
2781 gdb_assert (field
.loc_kind () == FIELD_LOC_KIND_BITPOS
);
2784 /* Resolve dynamic bounds of members of the struct TYPE to static
2785 bounds. ADDR_STACK is a stack of struct property_addr_info to
2786 be used if needed during the dynamic resolution. */
2788 static struct type
*
2789 resolve_dynamic_struct (struct type
*type
,
2790 const property_addr_info
*addr_stack
,
2791 const frame_info_ptr
&frame
)
2793 struct type
*resolved_type
;
2795 unsigned resolved_type_bit_length
= 0;
2797 gdb_assert (type
->code () == TYPE_CODE_STRUCT
);
2799 resolved_type
= copy_type (type
);
2801 dynamic_prop
*variant_prop
= resolved_type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
2802 if (variant_prop
!= nullptr && variant_prop
->kind () == PROP_VARIANT_PARTS
)
2804 compute_variant_fields (type
, resolved_type
, addr_stack
,
2805 *variant_prop
->variant_parts ());
2806 /* We want to leave the property attached, so that the Rust code
2807 can tell whether the type was originally an enum. */
2808 variant_prop
->set_original_type (type
);
2812 resolved_type
->copy_fields (type
);
2815 for (i
= 0; i
< resolved_type
->num_fields (); ++i
)
2817 unsigned new_bit_length
;
2819 if (resolved_type
->field (i
).is_static ())
2822 resolve_dynamic_field (resolved_type
->field (i
), addr_stack
, frame
);
2824 new_bit_length
= resolved_type
->field (i
).loc_bitpos ();
2825 if (resolved_type
->field (i
).bitsize () != 0)
2826 new_bit_length
+= resolved_type
->field (i
).bitsize ();
2829 struct type
*real_type
2830 = check_typedef (resolved_type
->field (i
).type ());
2832 new_bit_length
+= (real_type
->length () * TARGET_CHAR_BIT
);
2835 /* Normally, we would use the position and size of the last field
2836 to determine the size of the enclosing structure. But GCC seems
2837 to be encoding the position of some fields incorrectly when
2838 the struct contains a dynamic field that is not placed last.
2839 So we compute the struct size based on the field that has
2840 the highest position + size - probably the best we can do. */
2841 if (new_bit_length
> resolved_type_bit_length
)
2842 resolved_type_bit_length
= new_bit_length
;
2845 /* The length of a type won't change for fortran, but it does for C and Ada.
2846 For fortran the size of dynamic fields might change over time but not the
2847 type length of the structure. If we adapt it, we run into problems
2848 when calculating the element offset for arrays of structs. */
2849 if (current_language
->la_language
!= language_fortran
)
2850 resolved_type
->set_length ((resolved_type_bit_length
+ TARGET_CHAR_BIT
- 1)
2853 /* The Ada language uses this field as a cache for static fixed types: reset
2854 it as RESOLVED_TYPE must have its own static fixed type. */
2855 resolved_type
->set_target_type (nullptr);
2857 return resolved_type
;
2860 /* Worker for resolved_dynamic_type. */
2862 static struct type
*
2863 resolve_dynamic_type_internal (struct type
*type
,
2864 const property_addr_info
*addr_stack
,
2865 const frame_info_ptr
&frame
,
2868 struct type
*real_type
= check_typedef (type
);
2869 struct type
*resolved_type
= nullptr;
2870 struct dynamic_prop
*prop
;
2873 if (!is_dynamic_type_internal (real_type
, top_level
))
2876 std::optional
<CORE_ADDR
> type_length
;
2877 prop
= TYPE_DYNAMIC_LENGTH (type
);
2879 && dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2880 type_length
= value
;
2882 if (type
->code () == TYPE_CODE_TYPEDEF
)
2884 resolved_type
= copy_type (type
);
2885 resolved_type
->set_target_type
2886 (resolve_dynamic_type_internal (type
->target_type (), addr_stack
,
2891 /* Before trying to resolve TYPE, make sure it is not a stub. */
2894 switch (type
->code ())
2898 case TYPE_CODE_RVALUE_REF
:
2900 struct property_addr_info pinfo
;
2902 pinfo
.type
= check_typedef (type
->target_type ());
2904 if (addr_stack
->valaddr
.data () != NULL
)
2905 pinfo
.addr
= extract_typed_address (addr_stack
->valaddr
.data (),
2908 pinfo
.addr
= read_memory_typed_address (addr_stack
->addr
, type
);
2909 pinfo
.next
= addr_stack
;
2911 /* Special case a NULL pointer here -- we don't want to
2913 if (pinfo
.addr
!= 0)
2915 resolved_type
= copy_type (type
);
2916 resolved_type
->set_target_type
2917 (resolve_dynamic_type_internal (type
->target_type (),
2918 &pinfo
, frame
, true));
2923 case TYPE_CODE_STRING
:
2924 /* Strings are very much like an array of characters, and can be
2925 treated as one here. */
2926 case TYPE_CODE_ARRAY
:
2927 resolved_type
= resolve_dynamic_array_or_string (type
, addr_stack
,
2931 case TYPE_CODE_RANGE
:
2932 /* Pass 0 for the rank value here, which indicates this is a
2933 range for the first rank of an array. The assumption is that
2934 this rank value is not actually required for the resolution of
2935 the dynamic range, otherwise, we'd be resolving this range
2936 within the context of a dynamic array. */
2937 resolved_type
= resolve_dynamic_range (type
, addr_stack
, frame
, 0);
2940 case TYPE_CODE_UNION
:
2941 resolved_type
= resolve_dynamic_union (type
, addr_stack
, frame
);
2944 case TYPE_CODE_STRUCT
:
2945 resolved_type
= resolve_dynamic_struct (type
, addr_stack
, frame
);
2950 if (resolved_type
== nullptr)
2953 if (type_length
.has_value ())
2955 resolved_type
->set_length (*type_length
);
2956 resolved_type
->remove_dyn_prop (DYN_PROP_BYTE_SIZE
);
2959 /* Resolve data_location attribute. */
2960 prop
= TYPE_DATA_LOCATION (resolved_type
);
2962 && dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2964 /* Start of Fortran hack. See comment in f-lang.h for what is going
2966 if (current_language
->la_language
== language_fortran
2967 && resolved_type
->code () == TYPE_CODE_ARRAY
)
2968 value
= fortran_adjust_dynamic_array_base_address_hack (resolved_type
,
2970 /* End of Fortran hack. */
2971 prop
->set_const_val (value
);
2974 return resolved_type
;
2977 /* See gdbtypes.h */
2980 resolve_dynamic_type (struct type
*type
,
2981 gdb::array_view
<const gdb_byte
> valaddr
,
2983 const frame_info_ptr
*in_frame
)
2985 struct property_addr_info pinfo
2986 = {check_typedef (type
), valaddr
, addr
, NULL
};
2988 frame_info_ptr frame
;
2989 if (in_frame
!= nullptr)
2992 return resolve_dynamic_type_internal (type
, &pinfo
, frame
, true);
2995 /* See gdbtypes.h */
2998 type::dyn_prop (dynamic_prop_node_kind prop_kind
) const
3000 dynamic_prop_list
*node
= this->main_type
->dyn_prop_list
;
3002 while (node
!= NULL
)
3004 if (node
->prop_kind
== prop_kind
)
3011 /* See gdbtypes.h */
3014 type::add_dyn_prop (dynamic_prop_node_kind prop_kind
, dynamic_prop prop
)
3016 struct dynamic_prop_list
*temp
;
3018 gdb_assert (this->is_objfile_owned ());
3020 temp
= XOBNEW (&this->objfile_owner ()->objfile_obstack
,
3021 struct dynamic_prop_list
);
3022 temp
->prop_kind
= prop_kind
;
3024 temp
->next
= this->main_type
->dyn_prop_list
;
3026 this->main_type
->dyn_prop_list
= temp
;
3029 /* See gdbtypes.h. */
3032 type::remove_dyn_prop (dynamic_prop_node_kind kind
)
3034 struct dynamic_prop_list
*prev_node
, *curr_node
;
3036 curr_node
= this->main_type
->dyn_prop_list
;
3039 while (NULL
!= curr_node
)
3041 if (curr_node
->prop_kind
== kind
)
3043 /* Update the linked list but don't free anything.
3044 The property was allocated on obstack and it is not known
3045 if we are on top of it. Nevertheless, everything is released
3046 when the complete obstack is freed. */
3047 if (NULL
== prev_node
)
3048 this->main_type
->dyn_prop_list
= curr_node
->next
;
3050 prev_node
->next
= curr_node
->next
;
3055 prev_node
= curr_node
;
3056 curr_node
= curr_node
->next
;
3060 /* Find the real type of TYPE. This function returns the real type,
3061 after removing all layers of typedefs, and completing opaque or stub
3062 types. Completion changes the TYPE argument, but stripping of
3065 Instance flags (e.g. const/volatile) are preserved as typedefs are
3066 stripped. If necessary a new qualified form of the underlying type
3069 NOTE: This will return a typedef if type::target_type for the typedef has
3070 not been computed and we're either in the middle of reading symbols, or
3071 there was no name for the typedef in the debug info.
3073 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
3074 QUITs in the symbol reading code can also throw.
3075 Thus this function can throw an exception.
3077 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
3080 If this is a stubbed struct (i.e. declared as struct foo *), see if
3081 we can find a full definition in some other file. If so, copy this
3082 definition, so we can use it in future. There used to be a comment
3083 (but not any code) that if we don't find a full definition, we'd
3084 set a flag so we don't spend time in the future checking the same
3085 type. That would be a mistake, though--we might load in more
3086 symbols which contain a full definition for the type. */
3089 check_typedef (struct type
*type
)
3091 struct type
*orig_type
= type
;
3095 /* While we're removing typedefs, we don't want to lose qualifiers.
3096 E.g., const/volatile. */
3097 type_instance_flags instance_flags
= type
->instance_flags ();
3099 while (type
->code () == TYPE_CODE_TYPEDEF
)
3101 if (!type
->target_type ())
3106 /* It is dangerous to call lookup_symbol if we are currently
3107 reading a symtab. Infinite recursion is one danger. */
3108 if (currently_reading_symtab
)
3109 return make_qualified_type (type
, instance_flags
, NULL
);
3111 name
= type
->name ();
3114 stub_noname_complaint ();
3115 return make_qualified_type (type
, instance_flags
, NULL
);
3117 domain_search_flag flag
3118 = ((type
->language () == language_c
3119 || type
->language () == language_objc
3120 || type
->language () == language_opencl
3121 || type
->language () == language_minimal
)
3122 ? SEARCH_STRUCT_DOMAIN
3123 : SEARCH_TYPE_DOMAIN
);
3124 sym
= lookup_symbol (name
, nullptr, flag
, nullptr).symbol
;
3126 type
->set_target_type (sym
->type ());
3127 else /* TYPE_CODE_UNDEF */
3128 type
->set_target_type (type_allocator (type
->arch ()).new_type ());
3130 type
= type
->target_type ();
3132 /* Preserve the instance flags as we traverse down the typedef chain.
3134 Handling address spaces/classes is nasty, what do we do if there's a
3136 E.g., what if an outer typedef marks the type as class_1 and an inner
3137 typedef marks the type as class_2?
3138 This is the wrong place to do such error checking. We leave it to
3139 the code that created the typedef in the first place to flag the
3140 error. We just pick the outer address space (akin to letting the
3141 outer cast in a chain of casting win), instead of assuming
3142 "it can't happen". */
3144 const type_instance_flags ALL_SPACES
3145 = (TYPE_INSTANCE_FLAG_CODE_SPACE
3146 | TYPE_INSTANCE_FLAG_DATA_SPACE
);
3147 const type_instance_flags ALL_CLASSES
3148 = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
;
3150 type_instance_flags new_instance_flags
= type
->instance_flags ();
3152 /* Treat code vs data spaces and address classes separately. */
3153 if ((instance_flags
& ALL_SPACES
) != 0)
3154 new_instance_flags
&= ~ALL_SPACES
;
3155 if ((instance_flags
& ALL_CLASSES
) != 0)
3156 new_instance_flags
&= ~ALL_CLASSES
;
3158 instance_flags
|= new_instance_flags
;
3162 /* If this is a struct/class/union with no fields, then check
3163 whether a full definition exists somewhere else. This is for
3164 systems where a type definition with no fields is issued for such
3165 types, instead of identifying them as stub types in the first
3168 if (TYPE_IS_OPAQUE (type
)
3169 && opaque_type_resolution
3170 && !currently_reading_symtab
)
3172 const char *name
= type
->name ();
3173 struct type
*newtype
;
3177 stub_noname_complaint ();
3178 return make_qualified_type (type
, instance_flags
, NULL
);
3180 newtype
= lookup_transparent_type (name
);
3184 /* If the resolved type and the stub are in the same
3185 objfile, then replace the stub type with the real deal.
3186 But if they're in separate objfiles, leave the stub
3187 alone; we'll just look up the transparent type every time
3188 we call check_typedef. We can't create pointers between
3189 types allocated to different objfiles, since they may
3190 have different lifetimes. Trying to copy NEWTYPE over to
3191 TYPE's objfile is pointless, too, since you'll have to
3192 move over any other types NEWTYPE refers to, which could
3193 be an unbounded amount of stuff. */
3194 if (newtype
->objfile_owner () == type
->objfile_owner ())
3195 type
= make_qualified_type (newtype
, type
->instance_flags (), type
);
3200 /* Otherwise, rely on the stub flag being set for opaque/stubbed
3202 else if (type
->is_stub () && !currently_reading_symtab
)
3204 const char *name
= type
->name ();
3209 stub_noname_complaint ();
3210 return make_qualified_type (type
, instance_flags
, NULL
);
3212 domain_search_flag flag
3213 = ((type
->language () == language_c
3214 || type
->language () == language_objc
3215 || type
->language () == language_opencl
3216 || type
->language () == language_minimal
)
3217 ? SEARCH_STRUCT_DOMAIN
3218 : SEARCH_TYPE_DOMAIN
);
3219 sym
= lookup_symbol (name
, nullptr, flag
, nullptr).symbol
;
3222 /* Same as above for opaque types, we can replace the stub
3223 with the complete type only if they are in the same
3225 if (sym
->type ()->objfile_owner () == type
->objfile_owner ())
3226 type
= make_qualified_type (sym
->type (),
3227 type
->instance_flags (), type
);
3229 type
= sym
->type ();
3233 if (type
->target_is_stub ())
3235 struct type
*target_type
= check_typedef (type
->target_type ());
3237 if (target_type
->is_stub () || target_type
->target_is_stub ())
3239 /* Nothing we can do. */
3241 else if (type
->code () == TYPE_CODE_RANGE
)
3243 type
->set_length (target_type
->length ());
3244 type
->set_target_is_stub (false);
3246 else if (type
->code () == TYPE_CODE_ARRAY
3247 && update_static_array_size (type
))
3248 type
->set_target_is_stub (false);
3251 type
= make_qualified_type (type
, instance_flags
, NULL
);
3253 /* Cache TYPE_LENGTH for future use. */
3254 orig_type
->set_length (type
->length ());
3259 /* Parse a type expression in the string [P..P+LENGTH). If an error
3260 occurs, silently return a void type. */
3262 static struct type
*
3263 safe_parse_type (struct gdbarch
*gdbarch
, const char *p
, int length
)
3265 struct type
*type
= NULL
; /* Initialize to keep gcc happy. */
3267 /* Suppress error messages. */
3268 scoped_restore saved_gdb_stderr
= make_scoped_restore (&gdb_stderr
,
3271 /* Call parse_and_eval_type() without fear of longjmp()s. */
3274 type
= parse_and_eval_type (p
, length
);
3276 catch (const gdb_exception_error
&except
)
3278 type
= builtin_type (gdbarch
)->builtin_void
;
3284 /* Ugly hack to convert method stubs into method types.
3286 He ain't kiddin'. This demangles the name of the method into a
3287 string including argument types, parses out each argument type,
3288 generates a string casting a zero to that type, evaluates the
3289 string, and stuffs the resulting type into an argtype vector!!!
3290 Then it knows the type of the whole function (including argument
3291 types for overloading), which info used to be in the stab's but was
3292 removed to hack back the space required for them. */
3295 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
3297 struct gdbarch
*gdbarch
= type
->arch ();
3299 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
3300 gdb::unique_xmalloc_ptr
<char> demangled_name
3301 = gdb_demangle (mangled_name
, DMGL_PARAMS
| DMGL_ANSI
);
3302 char *argtypetext
, *p
;
3303 int depth
= 0, argcount
= 1;
3304 struct field
*argtypes
;
3307 /* Make sure we got back a function string that we can use. */
3309 p
= strchr (demangled_name
.get (), '(');
3313 if (demangled_name
== NULL
|| p
== NULL
)
3314 error (_("Internal: Cannot demangle mangled name `%s'."),
3317 /* Now, read in the parameters that define this type. */
3322 if (*p
== '(' || *p
== '<')
3326 else if (*p
== ')' || *p
== '>')
3330 else if (*p
== ',' && depth
== 0)
3338 /* If we read one argument and it was ``void'', don't count it. */
3339 if (startswith (argtypetext
, "(void)"))
3342 /* We need one extra slot, for the THIS pointer. */
3344 argtypes
= (struct field
*)
3345 TYPE_ZALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
3348 /* Add THIS pointer for non-static methods. */
3349 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
3350 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
3354 argtypes
[0].set_type (lookup_pointer_type (type
));
3358 if (*p
!= ')') /* () means no args, skip while. */
3363 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
3365 /* Avoid parsing of ellipsis, they will be handled below.
3366 Also avoid ``void'' as above. */
3367 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
3368 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
3370 argtypes
[argcount
].set_type
3371 (safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
));
3374 argtypetext
= p
+ 1;
3377 if (*p
== '(' || *p
== '<')
3381 else if (*p
== ')' || *p
== '>')
3390 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
3392 /* Now update the old "stub" type into a real type. */
3393 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
3394 /* MTYPE may currently be a function (TYPE_CODE_FUNC).
3395 We want a method (TYPE_CODE_METHOD). */
3396 smash_to_method_type (mtype
, type
, mtype
->target_type (),
3397 argtypes
, argcount
, p
[-2] == '.');
3398 mtype
->set_is_stub (false);
3399 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
3402 /* This is the external interface to check_stub_method, above. This
3403 function unstubs all of the signatures for TYPE's METHOD_ID method
3404 name. After calling this function TYPE_FN_FIELD_STUB will be
3405 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
3408 This function unfortunately can not die until stabs do. */
3411 check_stub_method_group (struct type
*type
, int method_id
)
3413 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
3414 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
3416 for (int j
= 0; j
< len
; j
++)
3418 if (TYPE_FN_FIELD_STUB (f
, j
))
3419 check_stub_method (type
, method_id
, j
);
3423 /* Ensure it is in .rodata (if available) by working around GCC PR 44690. */
3424 const struct cplus_struct_type cplus_struct_default
= { };
3427 allocate_cplus_struct_type (struct type
*type
)
3429 if (HAVE_CPLUS_STRUCT (type
))
3430 /* Structure was already allocated. Nothing more to do. */
3433 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_CPLUS_STUFF
;
3434 TYPE_RAW_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
3435 TYPE_ZALLOC (type
, sizeof (struct cplus_struct_type
));
3436 *(TYPE_RAW_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
3437 set_type_vptr_fieldno (type
, -1);
3440 const struct gnat_aux_type gnat_aux_default
=
3443 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
3444 and allocate the associated gnat-specific data. The gnat-specific
3445 data is also initialized to gnat_aux_default. */
3448 allocate_gnat_aux_type (struct type
*type
)
3450 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_GNAT_STUFF
;
3451 TYPE_GNAT_SPECIFIC (type
) = (struct gnat_aux_type
*)
3452 TYPE_ZALLOC (type
, sizeof (struct gnat_aux_type
));
3453 *(TYPE_GNAT_SPECIFIC (type
)) = gnat_aux_default
;
3456 /* Helper function to verify floating-point format and size.
3457 BIT is the type size in bits; if BIT equals -1, the size is
3458 determined by the floatformat. Returns size to be used. */
3461 verify_floatformat (int bit
, const struct floatformat
*floatformat
)
3463 gdb_assert (floatformat
!= NULL
);
3466 bit
= floatformat
->totalsize
;
3468 gdb_assert (bit
>= 0);
3469 gdb_assert (bit
>= floatformat
->totalsize
);
3474 /* Return the floating-point format for a floating-point variable of
3477 const struct floatformat
*
3478 floatformat_from_type (const struct type
*type
)
3480 gdb_assert (type
->code () == TYPE_CODE_FLT
);
3481 gdb_assert (TYPE_FLOATFORMAT (type
));
3482 return TYPE_FLOATFORMAT (type
);
3485 /* See gdbtypes.h. */
3488 init_integer_type (type_allocator
&alloc
,
3489 int bit
, int unsigned_p
, const char *name
)
3493 t
= alloc
.new_type (TYPE_CODE_INT
, bit
, name
);
3495 t
->set_is_unsigned (true);
3497 TYPE_SPECIFIC_FIELD (t
) = TYPE_SPECIFIC_INT
;
3498 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_size
= bit
;
3499 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_offset
= 0;
3504 /* See gdbtypes.h. */
3507 init_character_type (type_allocator
&alloc
,
3508 int bit
, int unsigned_p
, const char *name
)
3512 t
= alloc
.new_type (TYPE_CODE_CHAR
, bit
, name
);
3514 t
->set_is_unsigned (true);
3519 /* See gdbtypes.h. */
3522 init_boolean_type (type_allocator
&alloc
,
3523 int bit
, int unsigned_p
, const char *name
)
3527 t
= alloc
.new_type (TYPE_CODE_BOOL
, bit
, name
);
3529 t
->set_is_unsigned (true);
3531 TYPE_SPECIFIC_FIELD (t
) = TYPE_SPECIFIC_INT
;
3532 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_size
= bit
;
3533 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_offset
= 0;
3538 /* See gdbtypes.h. */
3541 init_float_type (type_allocator
&alloc
,
3542 int bit
, const char *name
,
3543 const struct floatformat
**floatformats
,
3544 enum bfd_endian byte_order
)
3546 if (byte_order
== BFD_ENDIAN_UNKNOWN
)
3548 struct gdbarch
*gdbarch
= alloc
.arch ();
3549 byte_order
= gdbarch_byte_order (gdbarch
);
3551 const struct floatformat
*fmt
= floatformats
[byte_order
];
3554 bit
= verify_floatformat (bit
, fmt
);
3555 t
= alloc
.new_type (TYPE_CODE_FLT
, bit
, name
);
3556 TYPE_FLOATFORMAT (t
) = fmt
;
3561 /* See gdbtypes.h. */
3564 init_decfloat_type (type_allocator
&alloc
, int bit
, const char *name
)
3566 return alloc
.new_type (TYPE_CODE_DECFLOAT
, bit
, name
);
3569 /* Return true if init_complex_type can be called with TARGET_TYPE. */
3572 can_create_complex_type (struct type
*target_type
)
3574 return (target_type
->code () == TYPE_CODE_INT
3575 || target_type
->code () == TYPE_CODE_FLT
);
3578 /* Allocate a TYPE_CODE_COMPLEX type structure. NAME is the type
3579 name. TARGET_TYPE is the component type. */
3582 init_complex_type (const char *name
, struct type
*target_type
)
3586 gdb_assert (can_create_complex_type (target_type
));
3588 if (TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
== nullptr)
3590 if (name
== nullptr && target_type
->name () != nullptr)
3592 /* No zero-initialization required, initialized by strcpy/strcat
3595 = (char *) TYPE_ALLOC (target_type
,
3596 strlen (target_type
->name ())
3597 + strlen ("_Complex ") + 1);
3598 strcpy (new_name
, "_Complex ");
3599 strcat (new_name
, target_type
->name ());
3603 t
= type_allocator (target_type
).new_type ();
3604 set_type_code (t
, TYPE_CODE_COMPLEX
);
3605 t
->set_length (2 * target_type
->length ());
3608 t
->set_target_type (target_type
);
3609 TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
= t
;
3612 return TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
;
3615 /* See gdbtypes.h. */
3618 init_pointer_type (type_allocator
&alloc
,
3619 int bit
, const char *name
, struct type
*target_type
)
3623 t
= alloc
.new_type (TYPE_CODE_PTR
, bit
, name
);
3624 t
->set_target_type (target_type
);
3625 t
->set_is_unsigned (true);
3629 /* Allocate a TYPE_CODE_FIXED_POINT type structure associated with OBJFILE.
3630 BIT is the pointer type size in bits.
3631 UNSIGNED_P should be nonzero if the type is unsigned.
3632 NAME is the type name. */
3635 init_fixed_point_type (type_allocator
&alloc
,
3636 int bit
, int unsigned_p
, const char *name
)
3640 t
= alloc
.new_type (TYPE_CODE_FIXED_POINT
, bit
, name
);
3642 t
->set_is_unsigned (true);
3647 /* See gdbtypes.h. */
3650 type_raw_align (struct type
*type
)
3652 if (type
->align_log2
!= 0)
3653 return 1 << (type
->align_log2
- 1);
3657 /* See gdbtypes.h. */
3660 type_align (struct type
*type
)
3662 /* Check alignment provided in the debug information. */
3663 unsigned raw_align
= type_raw_align (type
);
3667 /* Allow the architecture to provide an alignment. */
3668 ULONGEST align
= gdbarch_type_align (type
->arch (), type
);
3672 switch (type
->code ())
3675 case TYPE_CODE_FUNC
:
3676 case TYPE_CODE_FLAGS
:
3678 case TYPE_CODE_RANGE
:
3680 case TYPE_CODE_ENUM
:
3682 case TYPE_CODE_RVALUE_REF
:
3683 case TYPE_CODE_CHAR
:
3684 case TYPE_CODE_BOOL
:
3685 case TYPE_CODE_DECFLOAT
:
3686 case TYPE_CODE_METHODPTR
:
3687 case TYPE_CODE_MEMBERPTR
:
3688 align
= type_length_units (check_typedef (type
));
3691 case TYPE_CODE_ARRAY
:
3692 case TYPE_CODE_COMPLEX
:
3693 case TYPE_CODE_TYPEDEF
:
3694 align
= type_align (type
->target_type ());
3697 case TYPE_CODE_STRUCT
:
3698 case TYPE_CODE_UNION
:
3700 int number_of_non_static_fields
= 0;
3701 for (unsigned i
= 0; i
< type
->num_fields (); ++i
)
3703 if (!type
->field (i
).is_static ())
3705 number_of_non_static_fields
++;
3706 ULONGEST f_align
= type_align (type
->field (i
).type ());
3709 /* Don't pretend we know something we don't. */
3713 if (f_align
> align
)
3717 /* A struct with no fields, or with only static fields has an
3719 if (number_of_non_static_fields
== 0)
3725 case TYPE_CODE_STRING
:
3726 /* Not sure what to do here, and these can't appear in C or C++
3730 case TYPE_CODE_VOID
:
3734 case TYPE_CODE_ERROR
:
3735 case TYPE_CODE_METHOD
:
3740 if ((align
& (align
- 1)) != 0)
3742 /* Not a power of 2, so pass. */
3749 /* See gdbtypes.h. */
3752 set_type_align (struct type
*type
, ULONGEST align
)
3754 /* Must be a power of 2. Zero is ok. */
3755 gdb_assert ((align
& (align
- 1)) == 0);
3757 unsigned result
= 0;
3764 if (result
>= (1 << TYPE_ALIGN_BITS
))
3767 type
->align_log2
= result
;
3772 /* Queries on types. */
3775 can_dereference (struct type
*t
)
3777 /* FIXME: Should we return true for references as well as
3779 t
= check_typedef (t
);
3782 && t
->code () == TYPE_CODE_PTR
3783 && t
->target_type ()->code () != TYPE_CODE_VOID
);
3787 is_integral_type (struct type
*t
)
3789 t
= check_typedef (t
);
3792 && !is_fixed_point_type (t
)
3793 && ((t
->code () == TYPE_CODE_INT
)
3794 || (t
->code () == TYPE_CODE_ENUM
)
3795 || (t
->code () == TYPE_CODE_FLAGS
)
3796 || (t
->code () == TYPE_CODE_CHAR
)
3797 || (t
->code () == TYPE_CODE_RANGE
)
3798 || (t
->code () == TYPE_CODE_BOOL
)));
3802 is_floating_type (struct type
*t
)
3804 t
= check_typedef (t
);
3807 && ((t
->code () == TYPE_CODE_FLT
)
3808 || (t
->code () == TYPE_CODE_DECFLOAT
)));
3811 /* Return true if TYPE is scalar. */
3814 is_scalar_type (struct type
*type
)
3816 type
= check_typedef (type
);
3818 if (is_fixed_point_type (type
))
3819 return 0; /* Implemented as a scalar, but more like a floating point. */
3821 switch (type
->code ())
3823 case TYPE_CODE_ARRAY
:
3824 case TYPE_CODE_STRUCT
:
3825 case TYPE_CODE_UNION
:
3827 case TYPE_CODE_STRING
:
3834 /* Return true if T is scalar, or a composite type which in practice has
3835 the memory layout of a scalar type. E.g., an array or struct with only
3836 one scalar element inside it, or a union with only scalar elements. */
3839 is_scalar_type_recursive (struct type
*t
)
3841 t
= check_typedef (t
);
3843 if (is_scalar_type (t
))
3845 /* Are we dealing with an array or string of known dimensions? */
3846 else if ((t
->code () == TYPE_CODE_ARRAY
3847 || t
->code () == TYPE_CODE_STRING
) && t
->num_fields () == 1
3848 && t
->index_type ()->code () == TYPE_CODE_RANGE
)
3850 LONGEST low_bound
, high_bound
;
3851 struct type
*elt_type
= check_typedef (t
->target_type ());
3853 if (get_discrete_bounds (t
->index_type (), &low_bound
, &high_bound
))
3854 return (high_bound
== low_bound
3855 && is_scalar_type_recursive (elt_type
));
3859 /* Are we dealing with a struct with one element? */
3860 else if (t
->code () == TYPE_CODE_STRUCT
&& t
->num_fields () == 1)
3861 return is_scalar_type_recursive (t
->field (0).type ());
3862 else if (t
->code () == TYPE_CODE_UNION
)
3864 int i
, n
= t
->num_fields ();
3866 /* If all elements of the union are scalar, then the union is scalar. */
3867 for (i
= 0; i
< n
; i
++)
3868 if (!is_scalar_type_recursive (t
->field (i
).type ()))
3877 /* Return true is T is a class or a union. False otherwise. */
3880 class_or_union_p (const struct type
*t
)
3882 return (t
->code () == TYPE_CODE_STRUCT
3883 || t
->code () == TYPE_CODE_UNION
);
3886 /* A helper function which returns true if types A and B represent the
3887 "same" class type. This is true if the types have the same main
3888 type, or the same name. */
3891 class_types_same_p (const struct type
*a
, const struct type
*b
)
3893 return (TYPE_MAIN_TYPE (a
) == TYPE_MAIN_TYPE (b
)
3894 || (a
->name () && b
->name ()
3895 && !strcmp (a
->name (), b
->name ())));
3898 /* If BASE is an ancestor of DCLASS return the distance between them.
3899 otherwise return -1;
3903 class B: public A {};
3904 class C: public B {};
3907 distance_to_ancestor (A, A, 0) = 0
3908 distance_to_ancestor (A, B, 0) = 1
3909 distance_to_ancestor (A, C, 0) = 2
3910 distance_to_ancestor (A, D, 0) = 3
3912 If PUBLIC is 1 then only public ancestors are considered,
3913 and the function returns the distance only if BASE is a public ancestor
3917 distance_to_ancestor (A, D, 1) = -1. */
3920 distance_to_ancestor (struct type
*base
, struct type
*dclass
, int is_public
)
3925 base
= check_typedef (base
);
3926 dclass
= check_typedef (dclass
);
3928 if (class_types_same_p (base
, dclass
))
3931 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
3933 if (is_public
&& ! BASETYPE_VIA_PUBLIC (dclass
, i
))
3936 d
= distance_to_ancestor (base
, TYPE_BASECLASS (dclass
, i
), is_public
);
3944 /* Check whether BASE is an ancestor or base class or DCLASS
3945 Return 1 if so, and 0 if not.
3946 Note: If BASE and DCLASS are of the same type, this function
3947 will return 1. So for some class A, is_ancestor (A, A) will
3951 is_ancestor (struct type
*base
, struct type
*dclass
)
3953 return distance_to_ancestor (base
, dclass
, 0) >= 0;
3956 /* Like is_ancestor, but only returns true when BASE is a public
3957 ancestor of DCLASS. */
3960 is_public_ancestor (struct type
*base
, struct type
*dclass
)
3962 return distance_to_ancestor (base
, dclass
, 1) >= 0;
3965 /* A helper function for is_unique_ancestor. */
3968 is_unique_ancestor_worker (struct type
*base
, struct type
*dclass
,
3970 const gdb_byte
*valaddr
, int embedded_offset
,
3971 CORE_ADDR address
, struct value
*val
)
3975 base
= check_typedef (base
);
3976 dclass
= check_typedef (dclass
);
3978 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
) && count
< 2; ++i
)
3983 iter
= check_typedef (TYPE_BASECLASS (dclass
, i
));
3985 this_offset
= baseclass_offset (dclass
, i
, valaddr
, embedded_offset
,
3988 if (class_types_same_p (base
, iter
))
3990 /* If this is the first subclass, set *OFFSET and set count
3991 to 1. Otherwise, if this is at the same offset as
3992 previous instances, do nothing. Otherwise, increment
3996 *offset
= this_offset
;
3999 else if (this_offset
== *offset
)
4007 count
+= is_unique_ancestor_worker (base
, iter
, offset
,
4009 embedded_offset
+ this_offset
,
4016 /* Like is_ancestor, but only returns true if BASE is a unique base
4017 class of the type of VAL. */
4020 is_unique_ancestor (struct type
*base
, struct value
*val
)
4024 return is_unique_ancestor_worker (base
, val
->type (), &offset
,
4025 val
->contents_for_printing ().data (),
4026 val
->embedded_offset (),
4027 val
->address (), val
) == 1;
4030 /* See gdbtypes.h. */
4033 type_byte_order (const struct type
*type
)
4035 bfd_endian byteorder
= gdbarch_byte_order (type
->arch ());
4036 if (type
->endianity_is_not_default ())
4038 if (byteorder
== BFD_ENDIAN_BIG
)
4039 return BFD_ENDIAN_LITTLE
;
4042 gdb_assert (byteorder
== BFD_ENDIAN_LITTLE
);
4043 return BFD_ENDIAN_BIG
;
4050 /* See gdbtypes.h. */
4053 is_nocall_function (const struct type
*type
)
4055 if (type
->code () != TYPE_CODE_FUNC
&& type
->code () != TYPE_CODE_METHOD
)
4058 return TYPE_CALLING_CONVENTION (type
) == DW_CC_nocall
;
4062 /* Overload resolution. */
4064 /* Return the sum of the rank of A with the rank of B. */
4067 sum_ranks (struct rank a
, struct rank b
)
4070 c
.rank
= a
.rank
+ b
.rank
;
4071 c
.subrank
= a
.subrank
+ b
.subrank
;
4075 /* Compare rank A and B and return:
4077 1 if a is better than b
4078 -1 if b is better than a. */
4081 compare_ranks (struct rank a
, struct rank b
)
4083 if (a
.rank
== b
.rank
)
4085 if (a
.subrank
== b
.subrank
)
4087 if (a
.subrank
< b
.subrank
)
4089 if (a
.subrank
> b
.subrank
)
4093 if (a
.rank
< b
.rank
)
4096 /* a.rank > b.rank */
4100 /* Functions for overload resolution begin here. */
4102 /* Compare two badness vectors A and B and return the result.
4103 0 => A and B are identical
4104 1 => A and B are incomparable
4105 2 => A is better than B
4106 3 => A is worse than B */
4109 compare_badness (const badness_vector
&a
, const badness_vector
&b
)
4113 /* Any positives in comparison? */
4114 bool found_pos
= false;
4115 /* Any negatives in comparison? */
4116 bool found_neg
= false;
4117 /* Did A have any INVALID_CONVERSION entries. */
4118 bool a_invalid
= false;
4119 /* Did B have any INVALID_CONVERSION entries. */
4120 bool b_invalid
= false;
4122 /* differing sizes => incomparable */
4123 if (a
.size () != b
.size ())
4126 /* Subtract b from a */
4127 for (i
= 0; i
< a
.size (); i
++)
4129 tmp
= compare_ranks (b
[i
], a
[i
]);
4134 if (a
[i
].rank
>= INVALID_CONVERSION
)
4136 if (b
[i
].rank
>= INVALID_CONVERSION
)
4140 /* B will only be considered better than or incomparable to A if
4141 they both have invalid entries, or if neither does. That is, if
4142 A has only valid entries, and B has an invalid entry, then A will
4143 be considered better than B, even if B happens to be better for
4145 if (a_invalid
!= b_invalid
)
4148 return 3; /* A > B */
4149 return 2; /* A < B */
4154 return 1; /* incomparable */
4156 return 3; /* A > B */
4162 return 2; /* A < B */
4164 return 0; /* A == B */
4168 /* Rank a function by comparing its parameter types (PARMS), to the
4169 types of an argument list (ARGS). Return the badness vector. This
4170 has ARGS.size() + 1 entries. */
4173 rank_function (gdb::array_view
<type
*> parms
,
4174 gdb::array_view
<value
*> args
,
4177 /* add 1 for the length-match rank. */
4179 bv
.reserve (1 + args
.size ());
4181 /* First compare the lengths of the supplied lists.
4182 If there is a mismatch, set it to a high value. */
4184 /* pai/1997-06-03 FIXME: when we have debug info about default
4185 arguments and ellipsis parameter lists, we should consider those
4186 and rank the length-match more finely. */
4188 bv
.push_back ((args
.size () != parms
.size ()
4189 && (! varargs
|| args
.size () < parms
.size ()))
4190 ? LENGTH_MISMATCH_BADNESS
4191 : EXACT_MATCH_BADNESS
);
4193 /* Now rank all the parameters of the candidate function. */
4194 size_t min_len
= std::min (parms
.size (), args
.size ());
4196 for (size_t i
= 0; i
< min_len
; i
++)
4197 bv
.push_back (rank_one_type (parms
[i
], args
[i
]->type (),
4200 /* If more arguments than parameters, add dummy entries. */
4201 for (size_t i
= min_len
; i
< args
.size (); i
++)
4202 bv
.push_back (varargs
? VARARG_BADNESS
: TOO_FEW_PARAMS_BADNESS
);
4207 /* Compare the names of two integer types, assuming that any sign
4208 qualifiers have been checked already. We do it this way because
4209 there may be an "int" in the name of one of the types. */
4212 integer_types_same_name_p (const char *first
, const char *second
)
4214 int first_p
, second_p
;
4216 /* If both are shorts, return 1; if neither is a short, keep
4218 first_p
= (strstr (first
, "short") != NULL
);
4219 second_p
= (strstr (second
, "short") != NULL
);
4220 if (first_p
&& second_p
)
4222 if (first_p
|| second_p
)
4225 /* Likewise for long. */
4226 first_p
= (strstr (first
, "long") != NULL
);
4227 second_p
= (strstr (second
, "long") != NULL
);
4228 if (first_p
&& second_p
)
4230 if (first_p
|| second_p
)
4233 /* Likewise for char. */
4234 first_p
= (strstr (first
, "char") != NULL
);
4235 second_p
= (strstr (second
, "char") != NULL
);
4236 if (first_p
&& second_p
)
4238 if (first_p
|| second_p
)
4241 /* They must both be ints. */
4245 /* Compares type A to type B. Returns true if they represent the same
4246 type, false otherwise. */
4249 types_equal (struct type
*a
, struct type
*b
)
4251 /* Identical type pointers. */
4252 /* However, this still doesn't catch all cases of same type for b
4253 and a. The reason is that builtin types are different from
4254 the same ones constructed from the object. */
4258 /* Resolve typedefs */
4259 if (a
->code () == TYPE_CODE_TYPEDEF
)
4260 a
= check_typedef (a
);
4261 if (b
->code () == TYPE_CODE_TYPEDEF
)
4262 b
= check_typedef (b
);
4264 /* Check if identical after resolving typedefs. */
4268 /* If after resolving typedefs a and b are not of the same type
4269 code then they are not equal. */
4270 if (a
->code () != b
->code ())
4273 /* If a and b are both pointers types or both reference types then
4274 they are equal of the same type iff the objects they refer to are
4275 of the same type. */
4276 if (a
->code () == TYPE_CODE_PTR
4277 || a
->code () == TYPE_CODE_REF
)
4278 return types_equal (a
->target_type (),
4281 /* Well, damnit, if the names are exactly the same, I'll say they
4282 are exactly the same. This happens when we generate method
4283 stubs. The types won't point to the same address, but they
4284 really are the same. */
4286 if (a
->name () && b
->name ()
4287 && strcmp (a
->name (), b
->name ()) == 0)
4290 /* Two function types are equal if their argument and return types
4292 if (a
->code () == TYPE_CODE_FUNC
)
4296 if (a
->num_fields () != b
->num_fields ())
4299 if (!types_equal (a
->target_type (), b
->target_type ()))
4302 for (i
= 0; i
< a
->num_fields (); ++i
)
4303 if (!types_equal (a
->field (i
).type (), b
->field (i
).type ()))
4309 /* Two array types are the same if they have the same element types
4310 and array bounds. */
4311 if (a
->code () == TYPE_CODE_ARRAY
)
4313 if (!types_equal (a
->target_type (), b
->target_type ()))
4316 if (*a
->bounds () != *b
->bounds ())
4325 /* Deep comparison of types. */
4327 /* An entry in the type-equality bcache. */
4329 struct type_equality_entry
4331 type_equality_entry (struct type
*t1
, struct type
*t2
)
4337 struct type
*type1
, *type2
;
4340 /* A helper function to compare two strings. Returns true if they are
4341 the same, false otherwise. Handles NULLs properly. */
4344 compare_maybe_null_strings (const char *s
, const char *t
)
4346 if (s
== NULL
|| t
== NULL
)
4348 return strcmp (s
, t
) == 0;
4351 /* A helper function for check_types_worklist that checks two types for
4352 "deep" equality. Returns true if the types are considered the
4353 same, false otherwise. */
4356 check_types_equal (struct type
*type1
, struct type
*type2
,
4357 std::vector
<type_equality_entry
> *worklist
)
4359 type1
= check_typedef (type1
);
4360 type2
= check_typedef (type2
);
4365 if (type1
->code () != type2
->code ()
4366 || type1
->length () != type2
->length ()
4367 || type1
->is_unsigned () != type2
->is_unsigned ()
4368 || type1
->has_no_signedness () != type2
->has_no_signedness ()
4369 || type1
->endianity_is_not_default () != type2
->endianity_is_not_default ()
4370 || type1
->has_varargs () != type2
->has_varargs ()
4371 || type1
->is_vector () != type2
->is_vector ()
4372 || TYPE_NOTTEXT (type1
) != TYPE_NOTTEXT (type2
)
4373 || type1
->instance_flags () != type2
->instance_flags ()
4374 || type1
->num_fields () != type2
->num_fields ())
4377 if (!compare_maybe_null_strings (type1
->name (), type2
->name ()))
4379 if (!compare_maybe_null_strings (type1
->name (), type2
->name ()))
4382 if (type1
->code () == TYPE_CODE_RANGE
)
4384 if (*type1
->bounds () != *type2
->bounds ())
4391 for (i
= 0; i
< type1
->num_fields (); ++i
)
4393 const struct field
*field1
= &type1
->field (i
);
4394 const struct field
*field2
= &type2
->field (i
);
4396 if (field1
->is_artificial () != field2
->is_artificial ()
4397 || field1
->bitsize () != field2
->bitsize ()
4398 || field1
->loc_kind () != field2
->loc_kind ())
4400 if (!compare_maybe_null_strings (field1
->name (), field2
->name ()))
4402 switch (field1
->loc_kind ())
4404 case FIELD_LOC_KIND_BITPOS
:
4405 if (field1
->loc_bitpos () != field2
->loc_bitpos ())
4408 case FIELD_LOC_KIND_ENUMVAL
:
4409 if (field1
->loc_enumval () != field2
->loc_enumval ())
4411 /* Don't compare types of enum fields, because they don't
4414 case FIELD_LOC_KIND_PHYSADDR
:
4415 if (field1
->loc_physaddr () != field2
->loc_physaddr ())
4418 case FIELD_LOC_KIND_PHYSNAME
:
4419 if (!compare_maybe_null_strings (field1
->loc_physname (),
4420 field2
->loc_physname ()))
4423 case FIELD_LOC_KIND_DWARF_BLOCK_ADDR
:
4424 case FIELD_LOC_KIND_DWARF_BLOCK_BITPOS
:
4426 struct dwarf2_locexpr_baton
*block1
, *block2
;
4428 block1
= field1
->loc_dwarf_block ();
4429 block2
= field2
->loc_dwarf_block ();
4430 if (block1
->per_cu
!= block2
->per_cu
4431 || block1
->size
!= block2
->size
4432 || memcmp (block1
->data
, block2
->data
, block1
->size
) != 0)
4437 internal_error (_("Unsupported field kind "
4438 "%d by check_types_equal"),
4439 field1
->loc_kind ());
4442 worklist
->emplace_back (field1
->type (), field2
->type ());
4446 if (type1
->target_type () != NULL
)
4448 if (type2
->target_type () == NULL
)
4451 worklist
->emplace_back (type1
->target_type (),
4452 type2
->target_type ());
4454 else if (type2
->target_type () != NULL
)
4460 /* Check types on a worklist for equality. Returns false if any pair
4461 is not equal, true if they are all considered equal. */
4464 check_types_worklist (std::vector
<type_equality_entry
> *worklist
,
4467 while (!worklist
->empty ())
4471 struct type_equality_entry entry
= std::move (worklist
->back ());
4472 worklist
->pop_back ();
4474 /* If the type pair has already been visited, we know it is
4476 cache
->insert (entry
, &added
);
4480 if (!check_types_equal (entry
.type1
, entry
.type2
, worklist
))
4487 /* Return true if types TYPE1 and TYPE2 are equal, as determined by a
4488 "deep comparison". Otherwise return false. */
4491 types_deeply_equal (struct type
*type1
, struct type
*type2
)
4493 std::vector
<type_equality_entry
> worklist
;
4495 gdb_assert (type1
!= NULL
&& type2
!= NULL
);
4497 /* Early exit for the simple case. */
4502 worklist
.emplace_back (type1
, type2
);
4503 return check_types_worklist (&worklist
, &cache
);
4506 /* Allocated status of type TYPE. Return zero if type TYPE is allocated.
4507 Otherwise return one. */
4510 type_not_allocated (const struct type
*type
)
4512 struct dynamic_prop
*prop
= TYPE_ALLOCATED_PROP (type
);
4514 return prop
!= nullptr && prop
->is_constant () && prop
->const_val () == 0;
4517 /* Associated status of type TYPE. Return zero if type TYPE is associated.
4518 Otherwise return one. */
4521 type_not_associated (const struct type
*type
)
4523 struct dynamic_prop
*prop
= TYPE_ASSOCIATED_PROP (type
);
4525 return prop
!= nullptr && prop
->is_constant () && prop
->const_val () == 0;
4528 /* rank_one_type helper for when PARM's type code is TYPE_CODE_PTR. */
4531 rank_one_type_parm_ptr (struct type
*parm
, struct type
*arg
, struct value
*value
)
4533 struct rank rank
= {0,0};
4535 switch (arg
->code ())
4539 /* Allowed pointer conversions are:
4540 (a) pointer to void-pointer conversion. */
4541 if (parm
->target_type ()->code () == TYPE_CODE_VOID
)
4542 return VOID_PTR_CONVERSION_BADNESS
;
4544 /* (b) pointer to ancestor-pointer conversion. */
4545 rank
.subrank
= distance_to_ancestor (parm
->target_type (),
4546 arg
->target_type (),
4548 if (rank
.subrank
>= 0)
4549 return sum_ranks (BASE_PTR_CONVERSION_BADNESS
, rank
);
4551 return INCOMPATIBLE_TYPE_BADNESS
;
4552 case TYPE_CODE_ARRAY
:
4554 struct type
*t1
= parm
->target_type ();
4555 struct type
*t2
= arg
->target_type ();
4557 if (types_equal (t1
, t2
))
4559 /* Make sure they are CV equal. */
4560 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
4561 rank
.subrank
|= CV_CONVERSION_CONST
;
4562 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
4563 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
4564 if (rank
.subrank
!= 0)
4565 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
4566 return EXACT_MATCH_BADNESS
;
4568 return INCOMPATIBLE_TYPE_BADNESS
;
4570 case TYPE_CODE_FUNC
:
4571 return rank_one_type (parm
->target_type (), arg
, NULL
);
4573 if (value
!= NULL
&& value
->type ()->code () == TYPE_CODE_INT
)
4575 if (value_as_long (value
) == 0)
4577 /* Null pointer conversion: allow it to be cast to a pointer.
4578 [4.10.1 of C++ standard draft n3290] */
4579 return NULL_POINTER_CONVERSION_BADNESS
;
4583 /* If type checking is disabled, allow the conversion. */
4584 if (!strict_type_checking
)
4585 return NS_INTEGER_POINTER_CONVERSION_BADNESS
;
4589 case TYPE_CODE_ENUM
:
4590 case TYPE_CODE_FLAGS
:
4591 case TYPE_CODE_CHAR
:
4592 case TYPE_CODE_RANGE
:
4593 case TYPE_CODE_BOOL
:
4595 return INCOMPATIBLE_TYPE_BADNESS
;
4599 /* rank_one_type helper for when PARM's type code is TYPE_CODE_ARRAY. */
4602 rank_one_type_parm_array (struct type
*parm
, struct type
*arg
, struct value
*value
)
4604 switch (arg
->code ())
4607 case TYPE_CODE_ARRAY
:
4608 return rank_one_type (parm
->target_type (),
4609 arg
->target_type (), NULL
);
4611 return INCOMPATIBLE_TYPE_BADNESS
;
4615 /* rank_one_type helper for when PARM's type code is TYPE_CODE_FUNC. */
4618 rank_one_type_parm_func (struct type
*parm
, struct type
*arg
, struct value
*value
)
4620 switch (arg
->code ())
4622 case TYPE_CODE_PTR
: /* funcptr -> func */
4623 return rank_one_type (parm
, arg
->target_type (), NULL
);
4625 return INCOMPATIBLE_TYPE_BADNESS
;
4629 /* rank_one_type helper for when PARM's type code is TYPE_CODE_INT. */
4632 rank_one_type_parm_int (struct type
*parm
, struct type
*arg
, struct value
*value
)
4634 switch (arg
->code ())
4637 if (arg
->length () == parm
->length ())
4639 /* Deal with signed, unsigned, and plain chars and
4640 signed and unsigned ints. */
4641 if (parm
->has_no_signedness ())
4643 /* This case only for character types. */
4644 if (arg
->has_no_signedness ())
4645 return EXACT_MATCH_BADNESS
; /* plain char -> plain char */
4646 else /* signed/unsigned char -> plain char */
4647 return INTEGER_CONVERSION_BADNESS
;
4649 else if (parm
->is_unsigned ())
4651 if (arg
->is_unsigned ())
4653 /* unsigned int -> unsigned int, or
4654 unsigned long -> unsigned long */
4655 if (integer_types_same_name_p (parm
->name (),
4657 return EXACT_MATCH_BADNESS
;
4658 else if (integer_types_same_name_p (arg
->name (),
4660 && integer_types_same_name_p (parm
->name (),
4662 /* unsigned int -> unsigned long */
4663 return INTEGER_PROMOTION_BADNESS
;
4665 /* unsigned long -> unsigned int */
4666 return INTEGER_CONVERSION_BADNESS
;
4670 if (integer_types_same_name_p (arg
->name (),
4672 && integer_types_same_name_p (parm
->name (),
4674 /* signed long -> unsigned int */
4675 return INTEGER_CONVERSION_BADNESS
;
4677 /* signed int/long -> unsigned int/long */
4678 return INTEGER_CONVERSION_BADNESS
;
4681 else if (!arg
->has_no_signedness () && !arg
->is_unsigned ())
4683 if (integer_types_same_name_p (parm
->name (),
4685 return EXACT_MATCH_BADNESS
;
4686 else if (integer_types_same_name_p (arg
->name (),
4688 && integer_types_same_name_p (parm
->name (),
4690 return INTEGER_PROMOTION_BADNESS
;
4692 return INTEGER_CONVERSION_BADNESS
;
4695 return INTEGER_CONVERSION_BADNESS
;
4697 else if (arg
->length () < parm
->length ())
4698 return INTEGER_PROMOTION_BADNESS
;
4700 return INTEGER_CONVERSION_BADNESS
;
4701 case TYPE_CODE_ENUM
:
4702 case TYPE_CODE_FLAGS
:
4703 case TYPE_CODE_CHAR
:
4704 case TYPE_CODE_RANGE
:
4705 case TYPE_CODE_BOOL
:
4706 if (arg
->is_declared_class ())
4707 return INCOMPATIBLE_TYPE_BADNESS
;
4708 return INTEGER_PROMOTION_BADNESS
;
4710 return INT_FLOAT_CONVERSION_BADNESS
;
4712 return NS_POINTER_CONVERSION_BADNESS
;
4714 return INCOMPATIBLE_TYPE_BADNESS
;
4718 /* rank_one_type helper for when PARM's type code is TYPE_CODE_ENUM. */
4721 rank_one_type_parm_enum (struct type
*parm
, struct type
*arg
, struct value
*value
)
4723 switch (arg
->code ())
4726 case TYPE_CODE_CHAR
:
4727 case TYPE_CODE_RANGE
:
4728 case TYPE_CODE_BOOL
:
4729 case TYPE_CODE_ENUM
:
4730 if (parm
->is_declared_class () || arg
->is_declared_class ())
4731 return INCOMPATIBLE_TYPE_BADNESS
;
4732 return INTEGER_CONVERSION_BADNESS
;
4734 return INT_FLOAT_CONVERSION_BADNESS
;
4736 return INCOMPATIBLE_TYPE_BADNESS
;
4740 /* rank_one_type helper for when PARM's type code is TYPE_CODE_CHAR. */
4743 rank_one_type_parm_char (struct type
*parm
, struct type
*arg
, struct value
*value
)
4745 switch (arg
->code ())
4747 case TYPE_CODE_RANGE
:
4748 case TYPE_CODE_BOOL
:
4749 case TYPE_CODE_ENUM
:
4750 if (arg
->is_declared_class ())
4751 return INCOMPATIBLE_TYPE_BADNESS
;
4752 return INTEGER_CONVERSION_BADNESS
;
4754 return INT_FLOAT_CONVERSION_BADNESS
;
4756 if (arg
->length () > parm
->length ())
4757 return INTEGER_CONVERSION_BADNESS
;
4758 else if (arg
->length () < parm
->length ())
4759 return INTEGER_PROMOTION_BADNESS
;
4761 case TYPE_CODE_CHAR
:
4762 /* Deal with signed, unsigned, and plain chars for C++ and
4763 with int cases falling through from previous case. */
4764 if (parm
->has_no_signedness ())
4766 if (arg
->has_no_signedness ())
4767 return EXACT_MATCH_BADNESS
;
4769 return INTEGER_CONVERSION_BADNESS
;
4771 else if (parm
->is_unsigned ())
4773 if (arg
->is_unsigned ())
4774 return EXACT_MATCH_BADNESS
;
4776 return INTEGER_PROMOTION_BADNESS
;
4778 else if (!arg
->has_no_signedness () && !arg
->is_unsigned ())
4779 return EXACT_MATCH_BADNESS
;
4781 return INTEGER_CONVERSION_BADNESS
;
4783 return INCOMPATIBLE_TYPE_BADNESS
;
4787 /* rank_one_type helper for when PARM's type code is TYPE_CODE_RANGE. */
4790 rank_one_type_parm_range (struct type
*parm
, struct type
*arg
, struct value
*value
)
4792 switch (arg
->code ())
4795 case TYPE_CODE_CHAR
:
4796 case TYPE_CODE_RANGE
:
4797 case TYPE_CODE_BOOL
:
4798 case TYPE_CODE_ENUM
:
4799 return INTEGER_CONVERSION_BADNESS
;
4801 return INT_FLOAT_CONVERSION_BADNESS
;
4803 return INCOMPATIBLE_TYPE_BADNESS
;
4807 /* rank_one_type helper for when PARM's type code is TYPE_CODE_BOOL. */
4810 rank_one_type_parm_bool (struct type
*parm
, struct type
*arg
, struct value
*value
)
4812 switch (arg
->code ())
4814 /* n3290 draft, section 4.12.1 (conv.bool):
4816 "A prvalue of arithmetic, unscoped enumeration, pointer, or
4817 pointer to member type can be converted to a prvalue of type
4818 bool. A zero value, null pointer value, or null member pointer
4819 value is converted to false; any other value is converted to
4820 true. A prvalue of type std::nullptr_t can be converted to a
4821 prvalue of type bool; the resulting value is false." */
4823 case TYPE_CODE_CHAR
:
4824 case TYPE_CODE_ENUM
:
4826 case TYPE_CODE_MEMBERPTR
:
4828 return BOOL_CONVERSION_BADNESS
;
4829 case TYPE_CODE_RANGE
:
4830 return INCOMPATIBLE_TYPE_BADNESS
;
4831 case TYPE_CODE_BOOL
:
4832 return EXACT_MATCH_BADNESS
;
4834 return INCOMPATIBLE_TYPE_BADNESS
;
4838 /* rank_one_type helper for when PARM's type code is TYPE_CODE_FLOAT. */
4841 rank_one_type_parm_float (struct type
*parm
, struct type
*arg
, struct value
*value
)
4843 switch (arg
->code ())
4846 if (arg
->length () < parm
->length ())
4847 return FLOAT_PROMOTION_BADNESS
;
4848 else if (arg
->length () == parm
->length ())
4849 return EXACT_MATCH_BADNESS
;
4851 return FLOAT_CONVERSION_BADNESS
;
4853 case TYPE_CODE_BOOL
:
4854 case TYPE_CODE_ENUM
:
4855 case TYPE_CODE_RANGE
:
4856 case TYPE_CODE_CHAR
:
4857 return INT_FLOAT_CONVERSION_BADNESS
;
4859 return INCOMPATIBLE_TYPE_BADNESS
;
4863 /* rank_one_type helper for when PARM's type code is TYPE_CODE_COMPLEX. */
4866 rank_one_type_parm_complex (struct type
*parm
, struct type
*arg
, struct value
*value
)
4868 switch (arg
->code ())
4869 { /* Strictly not needed for C++, but... */
4871 return FLOAT_PROMOTION_BADNESS
;
4872 case TYPE_CODE_COMPLEX
:
4873 return EXACT_MATCH_BADNESS
;
4875 return INCOMPATIBLE_TYPE_BADNESS
;
4879 /* rank_one_type helper for when PARM's type code is TYPE_CODE_STRUCT. */
4882 rank_one_type_parm_struct (struct type
*parm
, struct type
*arg
, struct value
*value
)
4884 struct rank rank
= {0, 0};
4886 switch (arg
->code ())
4888 case TYPE_CODE_STRUCT
:
4889 /* Check for derivation */
4890 rank
.subrank
= distance_to_ancestor (parm
, arg
, 0);
4891 if (rank
.subrank
>= 0)
4892 return sum_ranks (BASE_CONVERSION_BADNESS
, rank
);
4895 return INCOMPATIBLE_TYPE_BADNESS
;
4899 /* rank_one_type helper for when PARM's type code is TYPE_CODE_SET. */
4902 rank_one_type_parm_set (struct type
*parm
, struct type
*arg
, struct value
*value
)
4904 switch (arg
->code ())
4908 return rank_one_type (parm
->field (0).type (),
4909 arg
->field (0).type (), NULL
);
4911 return INCOMPATIBLE_TYPE_BADNESS
;
4915 /* Compare one type (PARM) for compatibility with another (ARG).
4916 * PARM is intended to be the parameter type of a function; and
4917 * ARG is the supplied argument's type. This function tests if
4918 * the latter can be converted to the former.
4919 * VALUE is the argument's value or NULL if none (or called recursively)
4921 * Return 0 if they are identical types;
4922 * Otherwise, return an integer which corresponds to how compatible
4923 * PARM is to ARG. The higher the return value, the worse the match.
4924 * Generally the "bad" conversions are all uniformly assigned
4925 * INVALID_CONVERSION. */
4928 rank_one_type (struct type
*parm
, struct type
*arg
, struct value
*value
)
4930 struct rank rank
= {0,0};
4932 /* Resolve typedefs */
4933 if (parm
->code () == TYPE_CODE_TYPEDEF
)
4934 parm
= check_typedef (parm
);
4935 if (arg
->code () == TYPE_CODE_TYPEDEF
)
4936 arg
= check_typedef (arg
);
4938 if (TYPE_IS_REFERENCE (parm
) && value
!= NULL
)
4940 if (value
->lval () == not_lval
)
4942 /* Rvalues should preferably bind to rvalue references or const
4943 lvalue references. */
4944 if (parm
->code () == TYPE_CODE_RVALUE_REF
)
4945 rank
.subrank
= REFERENCE_CONVERSION_RVALUE
;
4946 else if (TYPE_CONST (parm
->target_type ()))
4947 rank
.subrank
= REFERENCE_CONVERSION_CONST_LVALUE
;
4949 return INCOMPATIBLE_TYPE_BADNESS
;
4950 return sum_ranks (rank
, REFERENCE_CONVERSION_BADNESS
);
4954 /* It's illegal to pass an lvalue as an rvalue. */
4955 if (parm
->code () == TYPE_CODE_RVALUE_REF
)
4956 return INCOMPATIBLE_TYPE_BADNESS
;
4960 if (types_equal (parm
, arg
))
4962 struct type
*t1
= parm
;
4963 struct type
*t2
= arg
;
4965 /* For pointers and references, compare target type. */
4966 if (parm
->is_pointer_or_reference ())
4968 t1
= parm
->target_type ();
4969 t2
= arg
->target_type ();
4972 /* Make sure they are CV equal, too. */
4973 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
4974 rank
.subrank
|= CV_CONVERSION_CONST
;
4975 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
4976 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
4977 if (rank
.subrank
!= 0)
4978 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
4979 return EXACT_MATCH_BADNESS
;
4982 /* See through references, since we can almost make non-references
4985 if (TYPE_IS_REFERENCE (arg
))
4986 return (sum_ranks (rank_one_type (parm
, arg
->target_type (), NULL
),
4987 REFERENCE_SEE_THROUGH_BADNESS
));
4988 if (TYPE_IS_REFERENCE (parm
))
4989 return (sum_ranks (rank_one_type (parm
->target_type (), arg
, NULL
),
4990 REFERENCE_SEE_THROUGH_BADNESS
));
4993 /* Debugging only. */
4994 gdb_printf (gdb_stderr
,
4995 "------ Arg is %s [%d], parm is %s [%d]\n",
4996 arg
->name (), arg
->code (),
4997 parm
->name (), parm
->code ());
5000 /* x -> y means arg of type x being supplied for parameter of type y. */
5002 switch (parm
->code ())
5005 return rank_one_type_parm_ptr (parm
, arg
, value
);
5006 case TYPE_CODE_ARRAY
:
5007 return rank_one_type_parm_array (parm
, arg
, value
);
5008 case TYPE_CODE_FUNC
:
5009 return rank_one_type_parm_func (parm
, arg
, value
);
5011 return rank_one_type_parm_int (parm
, arg
, value
);
5012 case TYPE_CODE_ENUM
:
5013 return rank_one_type_parm_enum (parm
, arg
, value
);
5014 case TYPE_CODE_CHAR
:
5015 return rank_one_type_parm_char (parm
, arg
, value
);
5016 case TYPE_CODE_RANGE
:
5017 return rank_one_type_parm_range (parm
, arg
, value
);
5018 case TYPE_CODE_BOOL
:
5019 return rank_one_type_parm_bool (parm
, arg
, value
);
5021 return rank_one_type_parm_float (parm
, arg
, value
);
5022 case TYPE_CODE_COMPLEX
:
5023 return rank_one_type_parm_complex (parm
, arg
, value
);
5024 case TYPE_CODE_STRUCT
:
5025 return rank_one_type_parm_struct (parm
, arg
, value
);
5027 return rank_one_type_parm_set (parm
, arg
, value
);
5029 return INCOMPATIBLE_TYPE_BADNESS
;
5030 } /* switch (arg->code ()) */
5033 /* End of functions for overload resolution. */
5036 /* Note the first arg should be the "this" pointer, we may not want to
5037 include it since we may get into a infinitely recursive
5041 print_args (struct field
*args
, int nargs
, int spaces
)
5047 for (i
= 0; i
< nargs
; i
++)
5050 ("%*s[%d] name '%s'\n", spaces
, "", i
,
5051 args
[i
].name () != NULL
? args
[i
].name () : "<NULL>");
5052 recursive_dump_type (args
[i
].type (), spaces
+ 2);
5058 dump_fn_fieldlists (struct type
*type
, int spaces
)
5064 gdb_printf ("%*sfn_fieldlists %s\n", spaces
, "",
5065 host_address_to_string (TYPE_FN_FIELDLISTS (type
)));
5066 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
5068 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
5070 ("%*s[%d] name '%s' (%s) length %d\n", spaces
+ 2, "",
5072 TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
5073 host_address_to_string (TYPE_FN_FIELDLIST_NAME (type
, method_idx
)),
5074 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
5075 for (overload_idx
= 0;
5076 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
5080 ("%*s[%d] physname '%s' (%s)\n",
5081 spaces
+ 4, "", overload_idx
,
5082 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
5083 host_address_to_string (TYPE_FN_FIELD_PHYSNAME (f
,
5086 ("%*stype %s\n", spaces
+ 8, "",
5087 host_address_to_string (TYPE_FN_FIELD_TYPE (f
, overload_idx
)));
5089 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
5093 ("%*sargs %s\n", spaces
+ 8, "",
5094 host_address_to_string (TYPE_FN_FIELD_ARGS (f
, overload_idx
)));
5095 print_args (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
5096 TYPE_FN_FIELD_TYPE (f
, overload_idx
)->num_fields (),
5099 ("%*sfcontext %s\n", spaces
+ 8, "",
5100 host_address_to_string (TYPE_FN_FIELD_FCONTEXT (f
,
5103 gdb_printf ("%*sis_const %d\n", spaces
+ 8, "",
5104 TYPE_FN_FIELD_CONST (f
, overload_idx
));
5105 gdb_printf ("%*sis_volatile %d\n", spaces
+ 8, "",
5106 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
5107 gdb_printf ("%*sis_private %d\n", spaces
+ 8, "",
5108 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
5109 gdb_printf ("%*sis_protected %d\n", spaces
+ 8, "",
5110 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
5111 gdb_printf ("%*sis_stub %d\n", spaces
+ 8, "",
5112 TYPE_FN_FIELD_STUB (f
, overload_idx
));
5113 gdb_printf ("%*sdefaulted %d\n", spaces
+ 8, "",
5114 TYPE_FN_FIELD_DEFAULTED (f
, overload_idx
));
5115 gdb_printf ("%*sis_deleted %d\n", spaces
+ 8, "",
5116 TYPE_FN_FIELD_DELETED (f
, overload_idx
));
5117 gdb_printf ("%*svoffset %u\n", spaces
+ 8, "",
5118 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
5124 print_cplus_stuff (struct type
*type
, int spaces
)
5126 gdb_printf ("%*svptr_fieldno %d\n", spaces
, "",
5127 TYPE_VPTR_FIELDNO (type
));
5128 gdb_printf ("%*svptr_basetype %s\n", spaces
, "",
5129 host_address_to_string (TYPE_VPTR_BASETYPE (type
)));
5130 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
5131 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
5133 gdb_printf ("%*sn_baseclasses %d\n", spaces
, "",
5134 TYPE_N_BASECLASSES (type
));
5135 gdb_printf ("%*snfn_fields %d\n", spaces
, "",
5136 TYPE_NFN_FIELDS (type
));
5137 if (TYPE_NFN_FIELDS (type
) > 0)
5139 dump_fn_fieldlists (type
, spaces
);
5142 gdb_printf ("%*scalling_convention %d\n", spaces
, "",
5143 TYPE_CPLUS_CALLING_CONVENTION (type
));
5146 /* Print the contents of the TYPE's type_specific union, assuming that
5147 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
5150 print_gnat_stuff (struct type
*type
, int spaces
)
5152 struct type
*descriptive_type
= TYPE_DESCRIPTIVE_TYPE (type
);
5154 if (descriptive_type
== NULL
)
5155 gdb_printf ("%*sno descriptive type\n", spaces
+ 2, "");
5158 gdb_printf ("%*sdescriptive type\n", spaces
+ 2, "");
5159 recursive_dump_type (descriptive_type
, spaces
+ 4);
5163 /* Print the contents of the TYPE's type_specific union, assuming that
5164 its type-specific kind is TYPE_SPECIFIC_FIXED_POINT. */
5167 print_fixed_point_type_info (struct type
*type
, int spaces
)
5169 gdb_printf ("%*sscaling factor: %s\n", spaces
+ 2, "",
5170 type
->fixed_point_scaling_factor ().str ().c_str ());
5173 static struct obstack dont_print_type_obstack
;
5175 /* Print the dynamic_prop PROP. */
5178 dump_dynamic_prop (dynamic_prop
const& prop
)
5180 switch (prop
.kind ())
5183 gdb_printf ("%s", plongest (prop
.const_val ()));
5185 case PROP_UNDEFINED
:
5186 gdb_printf ("(undefined)");
5190 gdb_printf ("(dynamic)");
5193 gdb_assert_not_reached ("unhandled prop kind");
5198 /* Return a string that represents a type code. */
5200 type_code_name (type_code code
)
5204 #define OP(X) case X: return # X;
5205 #include "type-codes.def"
5208 case TYPE_CODE_UNDEF
:
5209 return "TYPE_CODE_UNDEF";
5212 gdb_assert_not_reached ("unhandled type_code");
5216 recursive_dump_type (struct type
*type
, int spaces
)
5221 obstack_begin (&dont_print_type_obstack
, 0);
5223 if (type
->num_fields () > 0
5224 || (HAVE_CPLUS_STRUCT (type
) && TYPE_NFN_FIELDS (type
) > 0))
5226 struct type
**first_dont_print
5227 = (struct type
**) obstack_base (&dont_print_type_obstack
);
5229 int i
= (struct type
**)
5230 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
5234 if (type
== first_dont_print
[i
])
5236 gdb_printf ("%*stype node %s", spaces
, "",
5237 host_address_to_string (type
));
5238 gdb_printf (_(" <same as already seen type>\n"));
5243 obstack_ptr_grow (&dont_print_type_obstack
, type
);
5246 gdb_printf ("%*stype node %s\n", spaces
, "",
5247 host_address_to_string (type
));
5248 gdb_printf ("%*sname '%s' (%s)\n", spaces
, "",
5249 type
->name () ? type
->name () : "<NULL>",
5250 host_address_to_string (type
->name ()));
5251 gdb_printf ("%*scode 0x%x ", spaces
, "", type
->code ());
5252 gdb_printf ("(%s)", type_code_name (type
->code ()));
5254 gdb_printf ("%*slength %s\n", spaces
, "",
5255 pulongest (type
->length ()));
5256 if (type
->is_objfile_owned ())
5257 gdb_printf ("%*sobjfile %s\n", spaces
, "",
5258 host_address_to_string (type
->objfile_owner ()));
5260 gdb_printf ("%*sgdbarch %s\n", spaces
, "",
5261 host_address_to_string (type
->arch_owner ()));
5262 gdb_printf ("%*starget_type %s\n", spaces
, "",
5263 host_address_to_string (type
->target_type ()));
5264 if (type
->target_type () != NULL
)
5266 recursive_dump_type (type
->target_type (), spaces
+ 2);
5268 gdb_printf ("%*spointer_type %s\n", spaces
, "",
5269 host_address_to_string (TYPE_POINTER_TYPE (type
)));
5270 gdb_printf ("%*sreference_type %s\n", spaces
, "",
5271 host_address_to_string (TYPE_REFERENCE_TYPE (type
)));
5272 gdb_printf ("%*stype_chain %s\n", spaces
, "",
5273 host_address_to_string (TYPE_CHAIN (type
)));
5274 gdb_printf ("%*sinstance_flags 0x%x", spaces
, "",
5275 (unsigned) type
->instance_flags ());
5276 if (TYPE_CONST (type
))
5278 gdb_puts (" TYPE_CONST");
5280 if (TYPE_VOLATILE (type
))
5282 gdb_puts (" TYPE_VOLATILE");
5284 if (TYPE_CODE_SPACE (type
))
5286 gdb_puts (" TYPE_CODE_SPACE");
5288 if (TYPE_DATA_SPACE (type
))
5290 gdb_puts (" TYPE_DATA_SPACE");
5292 if (TYPE_ADDRESS_CLASS_1 (type
))
5294 gdb_puts (" TYPE_ADDRESS_CLASS_1");
5296 if (TYPE_ADDRESS_CLASS_2 (type
))
5298 gdb_puts (" TYPE_ADDRESS_CLASS_2");
5300 if (TYPE_RESTRICT (type
))
5302 gdb_puts (" TYPE_RESTRICT");
5304 if (TYPE_ATOMIC (type
))
5306 gdb_puts (" TYPE_ATOMIC");
5310 gdb_printf ("%*sflags", spaces
, "");
5311 if (type
->is_unsigned ())
5313 gdb_puts (" TYPE_UNSIGNED");
5315 if (type
->has_no_signedness ())
5317 gdb_puts (" TYPE_NOSIGN");
5319 if (type
->endianity_is_not_default ())
5321 gdb_puts (" TYPE_ENDIANITY_NOT_DEFAULT");
5323 if (type
->is_stub ())
5325 gdb_puts (" TYPE_STUB");
5327 if (type
->target_is_stub ())
5329 gdb_puts (" TYPE_TARGET_STUB");
5331 if (type
->is_prototyped ())
5333 gdb_puts (" TYPE_PROTOTYPED");
5335 if (type
->has_varargs ())
5337 gdb_puts (" TYPE_VARARGS");
5339 /* This is used for things like AltiVec registers on ppc. Gcc emits
5340 an attribute for the array type, which tells whether or not we
5341 have a vector, instead of a regular array. */
5342 if (type
->is_vector ())
5344 gdb_puts (" TYPE_VECTOR");
5346 if (type
->is_fixed_instance ())
5348 gdb_puts (" TYPE_FIXED_INSTANCE");
5350 if (type
->stub_is_supported ())
5352 gdb_puts (" TYPE_STUB_SUPPORTED");
5354 if (TYPE_NOTTEXT (type
))
5356 gdb_puts (" TYPE_NOTTEXT");
5359 gdb_printf ("%*snfields %d ", spaces
, "", type
->num_fields ());
5360 if (TYPE_ASSOCIATED_PROP (type
) != nullptr
5361 || TYPE_ALLOCATED_PROP (type
) != nullptr)
5363 gdb_printf ("%*s", spaces
, "");
5364 if (TYPE_ASSOCIATED_PROP (type
) != nullptr)
5366 gdb_printf ("associated ");
5367 dump_dynamic_prop (*TYPE_ASSOCIATED_PROP (type
));
5369 if (TYPE_ALLOCATED_PROP (type
) != nullptr)
5371 if (TYPE_ASSOCIATED_PROP (type
) != nullptr)
5373 gdb_printf ("allocated ");
5374 dump_dynamic_prop (*TYPE_ALLOCATED_PROP (type
));
5378 gdb_printf ("%s\n", host_address_to_string (type
->fields ()));
5379 for (idx
= 0; idx
< type
->num_fields (); idx
++)
5381 field
&fld
= type
->field (idx
);
5382 if (type
->code () == TYPE_CODE_ENUM
)
5383 gdb_printf ("%*s[%d] enumval %s type ", spaces
+ 2, "",
5384 idx
, plongest (fld
.loc_enumval ()));
5386 gdb_printf ("%*s[%d] bitpos %s bitsize %d type ", spaces
+ 2, "",
5387 idx
, plongest (fld
.loc_bitpos ()),
5389 gdb_printf ("%s name '%s' (%s)",
5390 host_address_to_string (fld
.type ()),
5394 host_address_to_string (fld
.name ()));
5395 if (fld
.is_virtual ())
5396 gdb_printf (" virtual");
5398 if (fld
.is_private ())
5399 gdb_printf (" private");
5400 else if (fld
.is_protected ())
5401 gdb_printf (" protected");
5402 else if (fld
.is_ignored ())
5403 gdb_printf (" ignored");
5406 if (fld
.type () != NULL
)
5408 recursive_dump_type (fld
.type (), spaces
+ 4);
5411 if (type
->code () == TYPE_CODE_RANGE
)
5413 gdb_printf ("%*slow ", spaces
, "");
5414 dump_dynamic_prop (type
->bounds ()->low
);
5415 gdb_printf (" high ");
5416 dump_dynamic_prop (type
->bounds ()->high
);
5420 switch (TYPE_SPECIFIC_FIELD (type
))
5422 case TYPE_SPECIFIC_CPLUS_STUFF
:
5423 gdb_printf ("%*scplus_stuff %s\n", spaces
, "",
5424 host_address_to_string (TYPE_CPLUS_SPECIFIC (type
)));
5425 print_cplus_stuff (type
, spaces
);
5428 case TYPE_SPECIFIC_GNAT_STUFF
:
5429 gdb_printf ("%*sgnat_stuff %s\n", spaces
, "",
5430 host_address_to_string (TYPE_GNAT_SPECIFIC (type
)));
5431 print_gnat_stuff (type
, spaces
);
5434 case TYPE_SPECIFIC_FLOATFORMAT
:
5435 gdb_printf ("%*sfloatformat ", spaces
, "");
5436 if (TYPE_FLOATFORMAT (type
) == NULL
5437 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
5438 gdb_puts ("(null)");
5440 gdb_puts (TYPE_FLOATFORMAT (type
)->name
);
5444 case TYPE_SPECIFIC_FUNC
:
5445 gdb_printf ("%*scalling_convention %d\n", spaces
, "",
5446 TYPE_CALLING_CONVENTION (type
));
5447 /* tail_call_list is not printed. */
5450 case TYPE_SPECIFIC_SELF_TYPE
:
5451 gdb_printf ("%*sself_type %s\n", spaces
, "",
5452 host_address_to_string (TYPE_SELF_TYPE (type
)));
5455 case TYPE_SPECIFIC_FIXED_POINT
:
5456 gdb_printf ("%*sfixed_point_info ", spaces
, "");
5457 print_fixed_point_type_info (type
, spaces
);
5461 case TYPE_SPECIFIC_INT
:
5462 if (type
->bit_size_differs_p ())
5464 unsigned bit_size
= type
->bit_size ();
5465 unsigned bit_off
= type
->bit_offset ();
5466 gdb_printf ("%*s bit size = %u, bit offset = %u\n", spaces
, "",
5473 obstack_free (&dont_print_type_obstack
, NULL
);
5476 /* Recursively copy (deep copy) a dynamic attribute list of a type. */
5478 static struct dynamic_prop_list
*
5479 copy_dynamic_prop_list (struct obstack
*storage
,
5480 struct dynamic_prop_list
*list
)
5482 struct dynamic_prop_list
*copy
= list
;
5483 struct dynamic_prop_list
**node_ptr
= ©
;
5485 while (*node_ptr
!= NULL
)
5487 struct dynamic_prop_list
*node_copy
;
5489 node_copy
= ((struct dynamic_prop_list
*)
5490 obstack_copy (storage
, *node_ptr
,
5491 sizeof (struct dynamic_prop_list
)));
5492 node_copy
->prop
= (*node_ptr
)->prop
;
5493 *node_ptr
= node_copy
;
5495 node_ptr
= &node_copy
->next
;
5501 /* Recursively copy (deep copy) TYPE, if it is associated with
5502 OBJFILE. Return a new type owned by the gdbarch associated with the type, a
5503 saved type if we have already visited TYPE (using COPIED_TYPES), or TYPE if
5504 it is not associated with OBJFILE. */
5507 copy_type_recursive (struct type
*type
, copied_types_hash_t
&copied_types
)
5509 if (!type
->is_objfile_owned ())
5512 if (auto iter
= copied_types
.find (type
);
5513 iter
!= copied_types
.end ())
5514 return iter
->second
;
5516 struct type
*new_type
= type_allocator (type
->arch ()).new_type ();
5518 /* We must add the new type to the hash table immediately, in case
5519 we encounter this type again during a recursive call below. */
5520 copied_types
.emplace (type
, new_type
);
5522 /* Copy the common fields of types. For the main type, we simply
5523 copy the entire thing and then update specific fields as needed. */
5524 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
5526 new_type
->set_owner (type
->arch ());
5529 new_type
->set_name (xstrdup (type
->name ()));
5531 new_type
->set_instance_flags (type
->instance_flags ());
5532 new_type
->set_length (type
->length ());
5534 /* Copy the fields. */
5535 if (type
->num_fields ())
5539 nfields
= type
->num_fields ();
5540 new_type
->alloc_fields (type
->num_fields ());
5542 for (i
= 0; i
< nfields
; i
++)
5544 new_type
->field (i
).set_is_artificial
5545 (type
->field (i
).is_artificial ());
5546 new_type
->field (i
).set_bitsize (type
->field (i
).bitsize ());
5547 if (type
->field (i
).type ())
5548 new_type
->field (i
).set_type
5549 (copy_type_recursive (type
->field (i
).type (), copied_types
));
5550 if (type
->field (i
).name ())
5551 new_type
->field (i
).set_name (xstrdup (type
->field (i
).name ()));
5553 switch (type
->field (i
).loc_kind ())
5555 case FIELD_LOC_KIND_BITPOS
:
5556 new_type
->field (i
).set_loc_bitpos (type
->field (i
).loc_bitpos ());
5558 case FIELD_LOC_KIND_ENUMVAL
:
5559 new_type
->field (i
).set_loc_enumval (type
->field (i
).loc_enumval ());
5561 case FIELD_LOC_KIND_PHYSADDR
:
5562 new_type
->field (i
).set_loc_physaddr
5563 (type
->field (i
).loc_physaddr ());
5565 case FIELD_LOC_KIND_PHYSNAME
:
5566 new_type
->field (i
).set_loc_physname
5567 (xstrdup (type
->field (i
).loc_physname ()));
5569 case FIELD_LOC_KIND_DWARF_BLOCK_ADDR
:
5570 new_type
->field (i
).set_loc_dwarf_block_addr
5571 (type
->field (i
).loc_dwarf_block ());
5573 case FIELD_LOC_KIND_DWARF_BLOCK_BITPOS
:
5574 new_type
->field (i
).set_loc_dwarf_block_bitpos
5575 (type
->field (i
).loc_dwarf_block ());
5578 internal_error (_("Unexpected type field location kind: %d"),
5579 type
->field (i
).loc_kind ());
5584 /* For range types, copy the bounds information. */
5585 if (type
->code () == TYPE_CODE_RANGE
)
5587 range_bounds
*bounds
5588 = ((struct range_bounds
*) TYPE_ALLOC
5589 (new_type
, sizeof (struct range_bounds
)));
5591 *bounds
= *type
->bounds ();
5592 new_type
->set_bounds (bounds
);
5595 if (type
->main_type
->dyn_prop_list
!= NULL
)
5596 new_type
->main_type
->dyn_prop_list
5597 = copy_dynamic_prop_list (gdbarch_obstack (new_type
->arch_owner ()),
5598 type
->main_type
->dyn_prop_list
);
5601 /* Copy pointers to other types. */
5602 if (type
->target_type ())
5603 new_type
->set_target_type
5604 (copy_type_recursive (type
->target_type (), copied_types
));
5606 /* Maybe copy the type_specific bits.
5608 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
5609 base classes and methods. There's no fundamental reason why we
5610 can't, but at the moment it is not needed. */
5612 switch (TYPE_SPECIFIC_FIELD (type
))
5614 case TYPE_SPECIFIC_NONE
:
5616 case TYPE_SPECIFIC_FUNC
:
5617 INIT_FUNC_SPECIFIC (new_type
);
5618 TYPE_CALLING_CONVENTION (new_type
) = TYPE_CALLING_CONVENTION (type
);
5619 TYPE_NO_RETURN (new_type
) = TYPE_NO_RETURN (type
);
5620 TYPE_TAIL_CALL_LIST (new_type
) = NULL
;
5622 case TYPE_SPECIFIC_FLOATFORMAT
:
5623 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
5625 case TYPE_SPECIFIC_CPLUS_STUFF
:
5626 INIT_CPLUS_SPECIFIC (new_type
);
5628 case TYPE_SPECIFIC_GNAT_STUFF
:
5629 INIT_GNAT_SPECIFIC (new_type
);
5631 case TYPE_SPECIFIC_SELF_TYPE
:
5632 set_type_self_type (new_type
,
5633 copy_type_recursive (TYPE_SELF_TYPE (type
),
5636 case TYPE_SPECIFIC_FIXED_POINT
:
5637 INIT_FIXED_POINT_SPECIFIC (new_type
);
5638 new_type
->fixed_point_info ().scaling_factor
5639 = type
->fixed_point_info ().scaling_factor
;
5641 case TYPE_SPECIFIC_INT
:
5642 TYPE_SPECIFIC_FIELD (new_type
) = TYPE_SPECIFIC_INT
;
5643 TYPE_MAIN_TYPE (new_type
)->type_specific
.int_stuff
5644 = TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
;
5648 gdb_assert_not_reached ("bad type_specific_kind");
5654 /* Make a copy of the given TYPE, except that the pointer & reference
5655 types are not preserved. */
5658 copy_type (const struct type
*type
)
5660 struct type
*new_type
= type_allocator (type
).new_type ();
5661 new_type
->set_instance_flags (type
->instance_flags ());
5662 new_type
->set_length (type
->length ());
5663 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
5664 sizeof (struct main_type
));
5665 if (type
->main_type
->dyn_prop_list
!= NULL
)
5667 struct obstack
*storage
= (type
->is_objfile_owned ()
5668 ? &type
->objfile_owner ()->objfile_obstack
5669 : gdbarch_obstack (type
->arch_owner ()));
5670 new_type
->main_type
->dyn_prop_list
5671 = copy_dynamic_prop_list (storage
, type
->main_type
->dyn_prop_list
);
5677 /* Helper functions to initialize architecture-specific types. */
5679 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
5680 NAME is the type name. BIT is the size of the flag word in bits. */
5683 arch_flags_type (struct gdbarch
*gdbarch
, const char *name
, int bit
)
5687 type
= type_allocator (gdbarch
).new_type (TYPE_CODE_FLAGS
, bit
, name
);
5688 type
->set_is_unsigned (true);
5689 /* Pre-allocate enough space assuming every field is one bit. */
5690 type
->alloc_fields (bit
);
5691 type
->set_num_fields (0);
5696 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5697 position BITPOS is called NAME. Pass NAME as "" for fields that
5698 should not be printed. */
5701 append_flags_type_field (struct type
*type
, int start_bitpos
, int nr_bits
,
5702 struct type
*field_type
, const char *name
)
5704 int type_bitsize
= type
->length () * TARGET_CHAR_BIT
;
5705 int field_nr
= type
->num_fields ();
5707 gdb_assert (type
->code () == TYPE_CODE_FLAGS
);
5708 gdb_assert (type
->num_fields () + 1 <= type_bitsize
);
5709 gdb_assert (start_bitpos
>= 0 && start_bitpos
< type_bitsize
);
5710 gdb_assert (nr_bits
>= 1 && (start_bitpos
+ nr_bits
) <= type_bitsize
);
5711 gdb_assert (name
!= NULL
);
5713 type
->set_num_fields (type
->num_fields () + 1);
5714 type
->field (field_nr
).set_name (xstrdup (name
));
5715 type
->field (field_nr
).set_type (field_type
);
5716 type
->field (field_nr
).set_loc_bitpos (start_bitpos
);
5717 type
->field (field_nr
).set_bitsize (nr_bits
);
5720 /* Special version of append_flags_type_field to add a flag field.
5721 Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5722 position BITPOS is called NAME. */
5725 append_flags_type_flag (struct type
*type
, int bitpos
, const char *name
)
5727 append_flags_type_field (type
, bitpos
, 1,
5728 builtin_type (type
->arch ())->builtin_bool
,
5732 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
5733 specified by CODE) associated with GDBARCH. NAME is the type name. */
5736 arch_composite_type (struct gdbarch
*gdbarch
, const char *name
,
5737 enum type_code code
)
5741 gdb_assert (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
);
5742 t
= type_allocator (gdbarch
).new_type (code
, 0, NULL
);
5744 INIT_CPLUS_SPECIFIC (t
);
5748 /* Add new field with name NAME and type FIELD to composite type T.
5749 Do not set the field's position or adjust the type's length;
5750 the caller should do so. Return the new field. */
5753 append_composite_type_field_raw (struct type
*t
, const char *name
,
5758 t
->set_num_fields (t
->num_fields () + 1);
5759 t
->set_fields (XRESIZEVEC (struct field
, t
->fields (),
5761 f
= &t
->field (t
->num_fields () - 1);
5762 memset (f
, 0, sizeof f
[0]);
5763 f
[0].set_type (field
);
5764 f
[0].set_name (name
);
5768 /* Add new field with name NAME and type FIELD to composite type T.
5769 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
5772 append_composite_type_field_aligned (struct type
*t
, const char *name
,
5773 struct type
*field
, int alignment
)
5775 struct field
*f
= append_composite_type_field_raw (t
, name
, field
);
5777 if (t
->code () == TYPE_CODE_UNION
)
5779 if (t
->length () < field
->length ())
5780 t
->set_length (field
->length ());
5782 else if (t
->code () == TYPE_CODE_STRUCT
)
5784 t
->set_length (t
->length () + field
->length ());
5785 if (t
->num_fields () > 1)
5788 (f
[-1].loc_bitpos ()
5789 + (f
[-1].type ()->length () * TARGET_CHAR_BIT
));
5795 alignment
*= TARGET_CHAR_BIT
;
5796 left
= f
[0].loc_bitpos () % alignment
;
5800 f
->set_loc_bitpos (f
[0].loc_bitpos () + (alignment
- left
));
5802 (t
->length () + (alignment
- left
) / TARGET_CHAR_BIT
);
5809 /* Add new field with name NAME and type FIELD to composite type T. */
5812 append_composite_type_field (struct type
*t
, const char *name
,
5815 append_composite_type_field_aligned (t
, name
, field
, 0);
5820 /* We manage the lifetimes of fixed_point_type_info objects by
5821 attaching them to the objfile. Currently, these objects are
5822 modified during construction, and GMP does not provide a way to
5823 hash the contents of an mpq_t; so it's a bit of a pain to hash-cons
5824 them. If we did do this, they could be moved to the per-BFD and
5825 shared across objfiles. */
5826 typedef std::vector
<std::unique_ptr
<fixed_point_type_info
>>
5827 fixed_point_type_storage
;
5829 /* Key used for managing the storage of fixed-point type info. */
5830 static const struct registry
<objfile
>::key
<fixed_point_type_storage
>
5831 fixed_point_objfile_key
;
5833 /* See gdbtypes.h. */
5836 allocate_fixed_point_type_info (struct type
*type
)
5838 auto up
= std::make_unique
<fixed_point_type_info
> ();
5839 fixed_point_type_info
*info
;
5841 if (type
->is_objfile_owned ())
5843 fixed_point_type_storage
*storage
5844 = fixed_point_objfile_key
.get (type
->objfile_owner ());
5845 if (storage
== nullptr)
5846 storage
= fixed_point_objfile_key
.emplace (type
->objfile_owner ());
5848 storage
->push_back (std::move (up
));
5852 /* We just leak the memory, because that's what we do generally
5853 for non-objfile-attached types. */
5854 info
= up
.release ();
5857 type
->set_fixed_point_info (info
);
5860 /* See gdbtypes.h. */
5863 is_fixed_point_type (struct type
*type
)
5865 while (check_typedef (type
)->code () == TYPE_CODE_RANGE
)
5866 type
= check_typedef (type
)->target_type ();
5867 type
= check_typedef (type
);
5869 return type
->code () == TYPE_CODE_FIXED_POINT
;
5872 /* See gdbtypes.h. */
5875 type::fixed_point_type_base_type ()
5877 struct type
*type
= this;
5879 while (check_typedef (type
)->code () == TYPE_CODE_RANGE
)
5880 type
= check_typedef (type
)->target_type ();
5881 type
= check_typedef (type
);
5883 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
);
5887 /* See gdbtypes.h. */
5890 type::fixed_point_scaling_factor ()
5892 struct type
*type
= this->fixed_point_type_base_type ();
5894 return type
->fixed_point_info ().scaling_factor
;
5897 /* See gdbtypes.h. */
5900 type::alloc_fields (unsigned int nfields
, bool init
)
5902 this->set_num_fields (nfields
);
5906 this->main_type
->flds_bnds
.fields
= nullptr;
5910 size_t size
= nfields
* sizeof (*this->fields ());
5911 struct field
*fields
5912 = (struct field
*) (init
5913 ? TYPE_ZALLOC (this, size
)
5914 : TYPE_ALLOC (this, size
));
5916 this->main_type
->flds_bnds
.fields
= fields
;
5919 /* See gdbtypes.h. */
5922 type::copy_fields (struct type
*src
)
5924 unsigned int nfields
= src
->num_fields ();
5925 alloc_fields (nfields
, false);
5929 size_t size
= nfields
* sizeof (*this->fields ());
5930 memcpy (this->fields (), src
->fields (), size
);
5933 /* See gdbtypes.h. */
5936 type::copy_fields (std::vector
<struct field
> &src
)
5938 unsigned int nfields
= src
.size ();
5939 alloc_fields (nfields
, false);
5943 size_t size
= nfields
* sizeof (*this->fields ());
5944 memcpy (this->fields (), src
.data (), size
);
5947 /* See gdbtypes.h. */
5950 type::is_string_like ()
5952 const language_defn
*defn
= language_def (this->language ());
5953 return defn
->is_string_type_p (this);
5956 /* See gdbtypes.h. */
5959 type::is_array_like ()
5961 if (code () == TYPE_CODE_ARRAY
)
5963 const language_defn
*defn
= language_def (this->language ());
5964 return defn
->is_array_like (this);
5969 static const registry
<gdbarch
>::key
<struct builtin_type
> gdbtypes_data
;
5971 static struct builtin_type
*
5972 create_gdbtypes_data (struct gdbarch
*gdbarch
)
5974 struct builtin_type
*builtin_type
= new struct builtin_type
;
5976 type_allocator
alloc (gdbarch
);
5979 builtin_type
->builtin_void
5980 = alloc
.new_type (TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
5981 builtin_type
->builtin_char
5982 = init_integer_type (alloc
, TARGET_CHAR_BIT
,
5983 !gdbarch_char_signed (gdbarch
), "char");
5984 builtin_type
->builtin_char
->set_has_no_signedness (true);
5985 builtin_type
->builtin_signed_char
5986 = init_integer_type (alloc
, TARGET_CHAR_BIT
,
5988 builtin_type
->builtin_unsigned_char
5989 = init_integer_type (alloc
, TARGET_CHAR_BIT
,
5990 1, "unsigned char");
5991 builtin_type
->builtin_short
5992 = init_integer_type (alloc
, gdbarch_short_bit (gdbarch
),
5994 builtin_type
->builtin_unsigned_short
5995 = init_integer_type (alloc
, gdbarch_short_bit (gdbarch
),
5996 1, "unsigned short");
5997 builtin_type
->builtin_int
5998 = init_integer_type (alloc
, gdbarch_int_bit (gdbarch
),
6000 builtin_type
->builtin_unsigned_int
6001 = init_integer_type (alloc
, gdbarch_int_bit (gdbarch
),
6003 builtin_type
->builtin_long
6004 = init_integer_type (alloc
, gdbarch_long_bit (gdbarch
),
6006 builtin_type
->builtin_unsigned_long
6007 = init_integer_type (alloc
, gdbarch_long_bit (gdbarch
),
6008 1, "unsigned long");
6009 builtin_type
->builtin_long_long
6010 = init_integer_type (alloc
, gdbarch_long_long_bit (gdbarch
),
6012 builtin_type
->builtin_unsigned_long_long
6013 = init_integer_type (alloc
, gdbarch_long_long_bit (gdbarch
),
6014 1, "unsigned long long");
6015 builtin_type
->builtin_half
6016 = init_float_type (alloc
, gdbarch_half_bit (gdbarch
),
6017 "half", gdbarch_half_format (gdbarch
));
6018 builtin_type
->builtin_float
6019 = init_float_type (alloc
, gdbarch_float_bit (gdbarch
),
6020 "float", gdbarch_float_format (gdbarch
));
6021 builtin_type
->builtin_bfloat16
6022 = init_float_type (alloc
, gdbarch_bfloat16_bit (gdbarch
),
6023 "bfloat16", gdbarch_bfloat16_format (gdbarch
));
6024 builtin_type
->builtin_double
6025 = init_float_type (alloc
, gdbarch_double_bit (gdbarch
),
6026 "double", gdbarch_double_format (gdbarch
));
6027 builtin_type
->builtin_long_double
6028 = init_float_type (alloc
, gdbarch_long_double_bit (gdbarch
),
6029 "long double", gdbarch_long_double_format (gdbarch
));
6030 builtin_type
->builtin_complex
6031 = init_complex_type ("complex", builtin_type
->builtin_float
);
6032 builtin_type
->builtin_double_complex
6033 = init_complex_type ("double complex", builtin_type
->builtin_double
);
6034 builtin_type
->builtin_string
6035 = alloc
.new_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
, "string");
6036 builtin_type
->builtin_bool
6037 = init_boolean_type (alloc
, TARGET_CHAR_BIT
, 1, "bool");
6039 /* The following three are about decimal floating point types, which
6040 are 32-bits, 64-bits and 128-bits respectively. */
6041 builtin_type
->builtin_decfloat
6042 = init_decfloat_type (alloc
, 32, "_Decimal32");
6043 builtin_type
->builtin_decdouble
6044 = init_decfloat_type (alloc
, 64, "_Decimal64");
6045 builtin_type
->builtin_declong
6046 = init_decfloat_type (alloc
, 128, "_Decimal128");
6048 /* "True" character types. */
6049 builtin_type
->builtin_true_char
6050 = init_character_type (alloc
, TARGET_CHAR_BIT
, 0, "true character");
6051 builtin_type
->builtin_true_unsigned_char
6052 = init_character_type (alloc
, TARGET_CHAR_BIT
, 1, "true character");
6054 /* Fixed-size integer types. */
6055 builtin_type
->builtin_int0
6056 = init_integer_type (alloc
, 0, 0, "int0_t");
6057 builtin_type
->builtin_int8
6058 = init_integer_type (alloc
, 8, 0, "int8_t");
6059 builtin_type
->builtin_uint8
6060 = init_integer_type (alloc
, 8, 1, "uint8_t");
6061 builtin_type
->builtin_int16
6062 = init_integer_type (alloc
, 16, 0, "int16_t");
6063 builtin_type
->builtin_uint16
6064 = init_integer_type (alloc
, 16, 1, "uint16_t");
6065 builtin_type
->builtin_int24
6066 = init_integer_type (alloc
, 24, 0, "int24_t");
6067 builtin_type
->builtin_uint24
6068 = init_integer_type (alloc
, 24, 1, "uint24_t");
6069 builtin_type
->builtin_int32
6070 = init_integer_type (alloc
, 32, 0, "int32_t");
6071 builtin_type
->builtin_uint32
6072 = init_integer_type (alloc
, 32, 1, "uint32_t");
6073 builtin_type
->builtin_int64
6074 = init_integer_type (alloc
, 64, 0, "int64_t");
6075 builtin_type
->builtin_uint64
6076 = init_integer_type (alloc
, 64, 1, "uint64_t");
6077 builtin_type
->builtin_int128
6078 = init_integer_type (alloc
, 128, 0, "int128_t");
6079 builtin_type
->builtin_uint128
6080 = init_integer_type (alloc
, 128, 1, "uint128_t");
6082 builtin_type
->builtin_int8
->set_instance_flags
6083 (builtin_type
->builtin_int8
->instance_flags ()
6084 | TYPE_INSTANCE_FLAG_NOTTEXT
);
6086 builtin_type
->builtin_uint8
->set_instance_flags
6087 (builtin_type
->builtin_uint8
->instance_flags ()
6088 | TYPE_INSTANCE_FLAG_NOTTEXT
);
6090 /* Wide character types. */
6091 builtin_type
->builtin_char16
6092 = init_integer_type (alloc
, 16, 1, "char16_t");
6093 builtin_type
->builtin_char32
6094 = init_integer_type (alloc
, 32, 1, "char32_t");
6095 builtin_type
->builtin_wchar
6096 = init_integer_type (alloc
, gdbarch_wchar_bit (gdbarch
),
6097 !gdbarch_wchar_signed (gdbarch
), "wchar_t");
6099 /* Default data/code pointer types. */
6100 builtin_type
->builtin_data_ptr
6101 = lookup_pointer_type (builtin_type
->builtin_void
);
6102 builtin_type
->builtin_func_ptr
6103 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
6104 builtin_type
->builtin_func_func
6105 = lookup_function_type (builtin_type
->builtin_func_ptr
);
6107 /* This type represents a GDB internal function. */
6108 builtin_type
->internal_fn
6109 = alloc
.new_type (TYPE_CODE_INTERNAL_FUNCTION
, 0,
6110 "<internal function>");
6112 /* This type represents an xmethod. */
6113 builtin_type
->xmethod
6114 = alloc
.new_type (TYPE_CODE_XMETHOD
, 0, "<xmethod>");
6116 /* This type represents a type that was unrecognized in symbol read-in. */
6117 builtin_type
->builtin_error
6118 = alloc
.new_type (TYPE_CODE_ERROR
, 0, "<unknown type>");
6120 /* The following set of types is used for symbols with no
6121 debug information. */
6122 builtin_type
->nodebug_text_symbol
6123 = alloc
.new_type (TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
6124 "<text variable, no debug info>");
6126 builtin_type
->nodebug_text_gnu_ifunc_symbol
6127 = alloc
.new_type (TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
6128 "<text gnu-indirect-function variable, no debug info>");
6129 builtin_type
->nodebug_text_gnu_ifunc_symbol
->set_is_gnu_ifunc (true);
6131 builtin_type
->nodebug_got_plt_symbol
6132 = init_pointer_type (alloc
, gdbarch_addr_bit (gdbarch
),
6133 "<text from jump slot in .got.plt, no debug info>",
6134 builtin_type
->nodebug_text_symbol
);
6135 builtin_type
->nodebug_data_symbol
6136 = alloc
.new_type (TYPE_CODE_ERROR
, 0, "<data variable, no debug info>");
6137 builtin_type
->nodebug_unknown_symbol
6138 = alloc
.new_type (TYPE_CODE_ERROR
, 0,
6139 "<variable (not text or data), no debug info>");
6140 builtin_type
->nodebug_tls_symbol
6141 = alloc
.new_type (TYPE_CODE_ERROR
, 0,
6142 "<thread local variable, no debug info>");
6144 /* NOTE: on some targets, addresses and pointers are not necessarily
6148 - gdb's `struct type' always describes the target's
6150 - gdb's `struct value' objects should always hold values in
6152 - gdb's CORE_ADDR values are addresses in the unified virtual
6153 address space that the assembler and linker work with. Thus,
6154 since target_read_memory takes a CORE_ADDR as an argument, it
6155 can access any memory on the target, even if the processor has
6156 separate code and data address spaces.
6158 In this context, builtin_type->builtin_core_addr is a bit odd:
6159 it's a target type for a value the target will never see. It's
6160 only used to hold the values of (typeless) linker symbols, which
6161 are indeed in the unified virtual address space. */
6163 builtin_type
->builtin_core_addr
6164 = init_integer_type (alloc
, gdbarch_addr_bit (gdbarch
), 1,
6166 return builtin_type
;
6169 const struct builtin_type
*
6170 builtin_type (struct gdbarch
*gdbarch
)
6172 struct builtin_type
*result
= gdbtypes_data
.get (gdbarch
);
6173 if (result
== nullptr)
6175 result
= create_gdbtypes_data (gdbarch
);
6176 gdbtypes_data
.set (gdbarch
, result
);
6181 const struct builtin_type
*
6182 builtin_type (struct objfile
*objfile
)
6184 return builtin_type (objfile
->arch ());
6187 /* See dwarf2/call-site.h. */
6190 call_site::pc () const
6192 /* dwarf2_per_objfile is defined in dwarf/read.c, so if that is disabled
6193 at configure time, we won't be able to use this relocate function.
6194 This is dwarf-specific, and would ideally be in call-site.h, but
6195 including dwarf2/read.h in dwarf2/call-site.h will lead to things being
6196 included in the wrong order and many compilation errors will happen.
6197 This is the next best thing. */
6198 #if defined(DWARF_FORMAT_AVAILABLE)
6199 return per_objfile
->relocate (m_unrelocated_pc
);
6201 gdb_assert_not_reached ("unexpected call_site object found");
6205 INIT_GDB_FILE (gdbtypes
)
6207 add_setshow_zuinteger_cmd ("overload", no_class
, &overload_debug
,
6208 _("Set debugging of C++ overloading."),
6209 _("Show debugging of C++ overloading."),
6210 _("When enabled, ranking of the "
6211 "functions is displayed."),
6213 show_overload_debug
,
6214 &setdebuglist
, &showdebuglist
);
6216 /* Add user knob for controlling resolution of opaque types. */
6217 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
6218 &opaque_type_resolution
,
6220 Set resolution of opaque struct/class/union types."),
6222 Show resolution of opaque struct/class/union types."),
6224 show_opaque_type_resolution
,
6225 &setlist
, &showlist
);
6227 /* Add an option to permit non-strict type checking. */
6228 add_setshow_boolean_cmd ("type", class_support
,
6229 &strict_type_checking
,
6230 _("Set strict type checking."),
6231 _("Show strict type checking."),
6233 show_strict_type_checking
,
6234 &setchecklist
, &showchecklist
);