1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2023 Free Software Foundation, Inc.
5 Contributed by Cygnus Support, using pieces from other GDB modules.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "expression.h"
33 #include "complaints.h"
37 #include "cp-support.h"
39 #include "dwarf2/loc.h"
40 #include "dwarf2/read.h"
42 #include "floatformat.h"
45 #include "gmp-utils.h"
46 #include "rust-lang.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};
80 /* Floatformat pairs. */
81 const struct floatformat
*floatformats_ieee_half
[BFD_ENDIAN_UNKNOWN
] = {
82 &floatformat_ieee_half_big
,
83 &floatformat_ieee_half_little
85 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
86 &floatformat_ieee_single_big
,
87 &floatformat_ieee_single_little
89 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
90 &floatformat_ieee_double_big
,
91 &floatformat_ieee_double_little
93 const struct floatformat
*floatformats_ieee_quad
[BFD_ENDIAN_UNKNOWN
] = {
94 &floatformat_ieee_quad_big
,
95 &floatformat_ieee_quad_little
97 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
98 &floatformat_ieee_double_big
,
99 &floatformat_ieee_double_littlebyte_bigword
101 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
102 &floatformat_i387_ext
,
103 &floatformat_i387_ext
105 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
106 &floatformat_m68881_ext
,
107 &floatformat_m68881_ext
109 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
110 &floatformat_arm_ext_big
,
111 &floatformat_arm_ext_littlebyte_bigword
113 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
114 &floatformat_ia64_spill_big
,
115 &floatformat_ia64_spill_little
117 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
121 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
125 const struct floatformat
*floatformats_ibm_long_double
[BFD_ENDIAN_UNKNOWN
] = {
126 &floatformat_ibm_long_double_big
,
127 &floatformat_ibm_long_double_little
129 const struct floatformat
*floatformats_bfloat16
[BFD_ENDIAN_UNKNOWN
] = {
130 &floatformat_bfloat16_big
,
131 &floatformat_bfloat16_little
134 /* Should opaque types be resolved? */
136 static bool opaque_type_resolution
= true;
138 /* See gdbtypes.h. */
140 unsigned int overload_debug
= 0;
142 /* A flag to enable strict type checking. */
144 static bool strict_type_checking
= true;
146 /* A function to show whether opaque types are resolved. */
149 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
150 struct cmd_list_element
*c
,
153 gdb_printf (file
, _("Resolution of opaque struct/class/union types "
154 "(if set before loading symbols) is %s.\n"),
158 /* A function to show whether C++ overload debugging is enabled. */
161 show_overload_debug (struct ui_file
*file
, int from_tty
,
162 struct cmd_list_element
*c
, const char *value
)
164 gdb_printf (file
, _("Debugging of C++ overloading is %s.\n"),
168 /* A function to show the status of strict type checking. */
171 show_strict_type_checking (struct ui_file
*file
, int from_tty
,
172 struct cmd_list_element
*c
, const char *value
)
174 gdb_printf (file
, _("Strict type checking is %s.\n"), value
);
178 /* Helper function to initialize a newly allocated type. Set type code
179 to CODE and initialize the type-specific fields accordingly. */
182 set_type_code (struct type
*type
, enum type_code code
)
184 type
->set_code (code
);
188 case TYPE_CODE_STRUCT
:
189 case TYPE_CODE_UNION
:
190 case TYPE_CODE_NAMESPACE
:
191 INIT_CPLUS_SPECIFIC (type
);
194 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_FLOATFORMAT
;
197 INIT_FUNC_SPECIFIC (type
);
199 case TYPE_CODE_FIXED_POINT
:
200 INIT_FIXED_POINT_SPECIFIC (type
);
205 /* See gdbtypes.h. */
208 type_allocator::new_type ()
213 obstack
*obstack
= (m_is_objfile
214 ? &m_data
.objfile
->objfile_obstack
215 : gdbarch_obstack (m_data
.gdbarch
));
217 /* Alloc the structure and start off with all fields zeroed. */
218 struct type
*type
= OBSTACK_ZALLOC (obstack
, struct type
);
219 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (obstack
, struct main_type
);
220 TYPE_MAIN_TYPE (type
)->m_lang
= m_lang
;
224 OBJSTAT (m_data
.objfile
, n_types
++);
225 type
->set_owner (m_data
.objfile
);
228 type
->set_owner (m_data
.gdbarch
);
230 /* Initialize the fields that might not be zero. */
231 type
->set_code (TYPE_CODE_UNDEF
);
232 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
237 /* See gdbtypes.h. */
240 type_allocator::new_type (enum type_code code
, int bit
, const char *name
)
242 struct type
*type
= new_type ();
243 set_type_code (type
, code
);
244 gdb_assert ((bit
% TARGET_CHAR_BIT
) == 0);
245 type
->set_length (bit
/ TARGET_CHAR_BIT
);
249 obstack
*obstack
= (m_is_objfile
250 ? &m_data
.objfile
->objfile_obstack
251 : gdbarch_obstack (m_data
.gdbarch
));
252 type
->set_name (obstack_strdup (obstack
, name
));
258 /* See gdbtypes.h. */
261 type_allocator::arch ()
264 return m_data
.type
->arch ();
266 return m_data
.objfile
->arch ();
267 return m_data
.gdbarch
;
270 /* See gdbtypes.h. */
275 struct gdbarch
*arch
;
277 if (this->is_objfile_owned ())
278 arch
= this->objfile_owner ()->arch ();
280 arch
= this->arch_owner ();
282 /* The ARCH can be NULL if TYPE is associated with neither an objfile nor
283 a gdbarch, however, this is very rare, and even then, in most cases
284 that type::arch is called, we assume that a non-NULL value is
286 gdb_assert (arch
!= nullptr);
290 /* See gdbtypes.h. */
293 get_target_type (struct type
*type
)
297 type
= type
->target_type ();
299 type
= check_typedef (type
);
305 /* See gdbtypes.h. */
308 type_length_units (struct type
*type
)
310 int unit_size
= gdbarch_addressable_memory_unit_size (type
->arch ());
312 return type
->length () / unit_size
;
315 /* Alloc a new type instance structure, fill it with some defaults,
316 and point it at OLDTYPE. Allocate the new type instance from the
317 same place as OLDTYPE. */
320 alloc_type_instance (struct type
*oldtype
)
324 /* Allocate the structure. */
326 if (!oldtype
->is_objfile_owned ())
327 type
= GDBARCH_OBSTACK_ZALLOC (oldtype
->arch_owner (), struct type
);
329 type
= OBSTACK_ZALLOC (&oldtype
->objfile_owner ()->objfile_obstack
,
332 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
334 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
339 /* Clear all remnants of the previous type at TYPE, in preparation for
340 replacing it with something else. Preserve owner information. */
343 smash_type (struct type
*type
)
345 bool objfile_owned
= type
->is_objfile_owned ();
346 objfile
*objfile
= type
->objfile_owner ();
347 gdbarch
*arch
= type
->arch_owner ();
349 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
351 /* Restore owner information. */
353 type
->set_owner (objfile
);
355 type
->set_owner (arch
);
357 /* For now, delete the rings. */
358 TYPE_CHAIN (type
) = type
;
360 /* For now, leave the pointer/reference types alone. */
363 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
364 to a pointer to memory where the pointer type should be stored.
365 If *TYPEPTR is zero, update it to point to the pointer type we return.
366 We allocate new memory if needed. */
369 make_pointer_type (struct type
*type
, struct type
**typeptr
)
371 struct type
*ntype
; /* New type */
374 ntype
= TYPE_POINTER_TYPE (type
);
379 return ntype
; /* Don't care about alloc,
380 and have new type. */
381 else if (*typeptr
== 0)
383 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
388 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
390 ntype
= type_allocator (type
).new_type ();
394 else /* We have storage, but need to reset it. */
397 chain
= TYPE_CHAIN (ntype
);
399 TYPE_CHAIN (ntype
) = chain
;
402 ntype
->set_target_type (type
);
403 TYPE_POINTER_TYPE (type
) = ntype
;
405 /* FIXME! Assumes the machine has only one representation for pointers! */
407 ntype
->set_length (gdbarch_ptr_bit (type
->arch ()) / TARGET_CHAR_BIT
);
408 ntype
->set_code (TYPE_CODE_PTR
);
410 /* Mark pointers as unsigned. The target converts between pointers
411 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
412 gdbarch_address_to_pointer. */
413 ntype
->set_is_unsigned (true);
415 /* Update the length of all the other variants of this type. */
416 chain
= TYPE_CHAIN (ntype
);
417 while (chain
!= ntype
)
419 chain
->set_length (ntype
->length ());
420 chain
= TYPE_CHAIN (chain
);
426 /* Given a type TYPE, return a type of pointers to that type.
427 May need to construct such a type if this is the first use. */
430 lookup_pointer_type (struct type
*type
)
432 return make_pointer_type (type
, (struct type
**) 0);
435 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
436 points to a pointer to memory where the reference type should be
437 stored. If *TYPEPTR is zero, update it to point to the reference
438 type we return. We allocate new memory if needed. REFCODE denotes
439 the kind of reference type to lookup (lvalue or rvalue reference). */
442 make_reference_type (struct type
*type
, struct type
**typeptr
,
443 enum type_code refcode
)
445 struct type
*ntype
; /* New type */
446 struct type
**reftype
;
449 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
451 ntype
= (refcode
== TYPE_CODE_REF
? TYPE_REFERENCE_TYPE (type
)
452 : TYPE_RVALUE_REFERENCE_TYPE (type
));
457 return ntype
; /* Don't care about alloc,
458 and have new type. */
459 else if (*typeptr
== 0)
461 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
466 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
468 ntype
= type_allocator (type
).new_type ();
472 else /* We have storage, but need to reset it. */
475 chain
= TYPE_CHAIN (ntype
);
477 TYPE_CHAIN (ntype
) = chain
;
480 ntype
->set_target_type (type
);
481 reftype
= (refcode
== TYPE_CODE_REF
? &TYPE_REFERENCE_TYPE (type
)
482 : &TYPE_RVALUE_REFERENCE_TYPE (type
));
486 /* FIXME! Assume the machine has only one representation for
487 references, and that it matches the (only) representation for
490 ntype
->set_length (gdbarch_ptr_bit (type
->arch ()) / TARGET_CHAR_BIT
);
491 ntype
->set_code (refcode
);
495 /* Update the length of all the other variants of this type. */
496 chain
= TYPE_CHAIN (ntype
);
497 while (chain
!= ntype
)
499 chain
->set_length (ntype
->length ());
500 chain
= TYPE_CHAIN (chain
);
506 /* Same as above, but caller doesn't care about memory allocation
510 lookup_reference_type (struct type
*type
, enum type_code refcode
)
512 return make_reference_type (type
, (struct type
**) 0, refcode
);
515 /* Lookup the lvalue reference type for the type TYPE. */
518 lookup_lvalue_reference_type (struct type
*type
)
520 return lookup_reference_type (type
, TYPE_CODE_REF
);
523 /* Lookup the rvalue reference type for the type TYPE. */
526 lookup_rvalue_reference_type (struct type
*type
)
528 return lookup_reference_type (type
, TYPE_CODE_RVALUE_REF
);
531 /* Lookup a function type that returns type TYPE. TYPEPTR, if
532 nonzero, points to a pointer to memory where the function type
533 should be stored. If *TYPEPTR is zero, update it to point to the
534 function type we return. We allocate new memory if needed. */
537 make_function_type (struct type
*type
, struct type
**typeptr
)
539 struct type
*ntype
; /* New type */
541 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
543 ntype
= type_allocator (type
).new_type ();
547 else /* We have storage, but need to reset it. */
553 ntype
->set_target_type (type
);
555 ntype
->set_length (1);
556 ntype
->set_code (TYPE_CODE_FUNC
);
558 INIT_FUNC_SPECIFIC (ntype
);
563 /* Given a type TYPE, return a type of functions that return that type.
564 May need to construct such a type if this is the first use. */
567 lookup_function_type (struct type
*type
)
569 return make_function_type (type
, (struct type
**) 0);
572 /* Given a type TYPE and argument types, return the appropriate
573 function type. If the final type in PARAM_TYPES is NULL, make a
577 lookup_function_type_with_arguments (struct type
*type
,
579 struct type
**param_types
)
581 struct type
*fn
= make_function_type (type
, (struct type
**) 0);
586 if (param_types
[nparams
- 1] == NULL
)
589 fn
->set_has_varargs (true);
591 else if (check_typedef (param_types
[nparams
- 1])->code ()
595 /* Caller should have ensured this. */
596 gdb_assert (nparams
== 0);
597 fn
->set_is_prototyped (true);
600 fn
->set_is_prototyped (true);
603 fn
->alloc_fields (nparams
);
604 for (i
= 0; i
< nparams
; ++i
)
605 fn
->field (i
).set_type (param_types
[i
]);
610 /* Identify address space identifier by name -- return a
611 type_instance_flags. */
614 address_space_name_to_type_instance_flags (struct gdbarch
*gdbarch
,
615 const char *space_identifier
)
617 type_instance_flags type_flags
;
619 /* Check for known address space delimiters. */
620 if (!strcmp (space_identifier
, "code"))
621 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
622 else if (!strcmp (space_identifier
, "data"))
623 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
624 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
625 && gdbarch_address_class_name_to_type_flags (gdbarch
,
630 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
633 /* Identify address space identifier by type_instance_flags and return
634 the string version of the adress space name. */
637 address_space_type_instance_flags_to_name (struct gdbarch
*gdbarch
,
638 type_instance_flags space_flag
)
640 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
642 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
644 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
645 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
646 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
651 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
653 If STORAGE is non-NULL, create the new type instance there.
654 STORAGE must be in the same obstack as TYPE. */
657 make_qualified_type (struct type
*type
, type_instance_flags new_flags
,
658 struct type
*storage
)
665 if (ntype
->instance_flags () == new_flags
)
667 ntype
= TYPE_CHAIN (ntype
);
669 while (ntype
!= type
);
671 /* Create a new type instance. */
673 ntype
= alloc_type_instance (type
);
676 /* If STORAGE was provided, it had better be in the same objfile
677 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
678 if one objfile is freed and the other kept, we'd have
679 dangling pointers. */
680 gdb_assert (type
->objfile_owner () == storage
->objfile_owner ());
683 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
684 TYPE_CHAIN (ntype
) = ntype
;
687 /* Pointers or references to the original type are not relevant to
689 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
690 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
692 /* Chain the new qualified type to the old type. */
693 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
694 TYPE_CHAIN (type
) = ntype
;
696 /* Now set the instance flags and return the new type. */
697 ntype
->set_instance_flags (new_flags
);
699 /* Set length of new type to that of the original type. */
700 ntype
->set_length (type
->length ());
705 /* Make an address-space-delimited variant of a type -- a type that
706 is identical to the one supplied except that it has an address
707 space attribute attached to it (such as "code" or "data").
709 The space attributes "code" and "data" are for Harvard
710 architectures. The address space attributes are for architectures
711 which have alternately sized pointers or pointers with alternate
715 make_type_with_address_space (struct type
*type
,
716 type_instance_flags space_flag
)
718 type_instance_flags new_flags
= ((type
->instance_flags ()
719 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
720 | TYPE_INSTANCE_FLAG_DATA_SPACE
721 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
724 return make_qualified_type (type
, new_flags
, NULL
);
727 /* Make a "c-v" variant of a type -- a type that is identical to the
728 one supplied except that it may have const or volatile attributes
729 CNST is a flag for setting the const attribute
730 VOLTL is a flag for setting the volatile attribute
731 TYPE is the base type whose variant we are creating.
733 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
734 storage to hold the new qualified type; *TYPEPTR and TYPE must be
735 in the same objfile. Otherwise, allocate fresh memory for the new
736 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
737 new type we construct. */
740 make_cv_type (int cnst
, int voltl
,
742 struct type
**typeptr
)
744 struct type
*ntype
; /* New type */
746 type_instance_flags new_flags
= (type
->instance_flags ()
747 & ~(TYPE_INSTANCE_FLAG_CONST
748 | TYPE_INSTANCE_FLAG_VOLATILE
));
751 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
754 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
756 if (typeptr
&& *typeptr
!= NULL
)
758 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
759 a C-V variant chain that threads across objfiles: if one
760 objfile gets freed, then the other has a broken C-V chain.
762 This code used to try to copy over the main type from TYPE to
763 *TYPEPTR if they were in different objfiles, but that's
764 wrong, too: TYPE may have a field list or member function
765 lists, which refer to types of their own, etc. etc. The
766 whole shebang would need to be copied over recursively; you
767 can't have inter-objfile pointers. The only thing to do is
768 to leave stub types as stub types, and look them up afresh by
769 name each time you encounter them. */
770 gdb_assert ((*typeptr
)->objfile_owner () == type
->objfile_owner ());
773 ntype
= make_qualified_type (type
, new_flags
,
774 typeptr
? *typeptr
: NULL
);
782 /* Make a 'restrict'-qualified version of TYPE. */
785 make_restrict_type (struct type
*type
)
787 return make_qualified_type (type
,
788 (type
->instance_flags ()
789 | TYPE_INSTANCE_FLAG_RESTRICT
),
793 /* Make a type without const, volatile, or restrict. */
796 make_unqualified_type (struct type
*type
)
798 return make_qualified_type (type
,
799 (type
->instance_flags ()
800 & ~(TYPE_INSTANCE_FLAG_CONST
801 | TYPE_INSTANCE_FLAG_VOLATILE
802 | TYPE_INSTANCE_FLAG_RESTRICT
)),
806 /* Make a '_Atomic'-qualified version of TYPE. */
809 make_atomic_type (struct type
*type
)
811 return make_qualified_type (type
,
812 (type
->instance_flags ()
813 | TYPE_INSTANCE_FLAG_ATOMIC
),
817 /* Replace the contents of ntype with the type *type. This changes the
818 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
819 the changes are propogated to all types in the TYPE_CHAIN.
821 In order to build recursive types, it's inevitable that we'll need
822 to update types in place --- but this sort of indiscriminate
823 smashing is ugly, and needs to be replaced with something more
824 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
825 clear if more steps are needed. */
828 replace_type (struct type
*ntype
, struct type
*type
)
832 /* These two types had better be in the same objfile. Otherwise,
833 the assignment of one type's main type structure to the other
834 will produce a type with references to objects (names; field
835 lists; etc.) allocated on an objfile other than its own. */
836 gdb_assert (ntype
->objfile_owner () == type
->objfile_owner ());
838 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
840 /* The type length is not a part of the main type. Update it for
841 each type on the variant chain. */
845 /* Assert that this element of the chain has no address-class bits
846 set in its flags. Such type variants might have type lengths
847 which are supposed to be different from the non-address-class
848 variants. This assertion shouldn't ever be triggered because
849 symbol readers which do construct address-class variants don't
850 call replace_type(). */
851 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
853 chain
->set_length (type
->length ());
854 chain
= TYPE_CHAIN (chain
);
856 while (ntype
!= chain
);
858 /* Assert that the two types have equivalent instance qualifiers.
859 This should be true for at least all of our debug readers. */
860 gdb_assert (ntype
->instance_flags () == type
->instance_flags ());
863 /* Implement direct support for MEMBER_TYPE in GNU C++.
864 May need to construct such a type if this is the first use.
865 The TYPE is the type of the member. The DOMAIN is the type
866 of the aggregate that the member belongs to. */
869 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
873 mtype
= type_allocator (type
).new_type ();
874 smash_to_memberptr_type (mtype
, domain
, type
);
878 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
881 lookup_methodptr_type (struct type
*to_type
)
885 mtype
= type_allocator (to_type
).new_type ();
886 smash_to_methodptr_type (mtype
, to_type
);
890 /* See gdbtypes.h. */
893 operator== (const dynamic_prop
&l
, const dynamic_prop
&r
)
895 if (l
.kind () != r
.kind ())
903 return l
.const_val () == r
.const_val ();
904 case PROP_ADDR_OFFSET
:
907 return l
.baton () == r
.baton ();
908 case PROP_VARIANT_PARTS
:
909 return l
.variant_parts () == r
.variant_parts ();
911 return l
.original_type () == r
.original_type ();
914 gdb_assert_not_reached ("unhandled dynamic_prop kind");
917 /* See gdbtypes.h. */
920 operator== (const range_bounds
&l
, const range_bounds
&r
)
922 #define FIELD_EQ(FIELD) (l.FIELD == r.FIELD)
924 return (FIELD_EQ (low
)
926 && FIELD_EQ (flag_upper_bound_is_count
)
927 && FIELD_EQ (flag_bound_evaluated
)
933 /* See gdbtypes.h. */
936 create_range_type (type_allocator
&alloc
, struct type
*index_type
,
937 const struct dynamic_prop
*low_bound
,
938 const struct dynamic_prop
*high_bound
,
941 /* The INDEX_TYPE should be a type capable of holding the upper and lower
942 bounds, as such a zero sized, or void type makes no sense. */
943 gdb_assert (index_type
->code () != TYPE_CODE_VOID
);
944 gdb_assert (index_type
->length () > 0);
946 struct type
*result_type
= alloc
.new_type ();
947 result_type
->set_code (TYPE_CODE_RANGE
);
948 result_type
->set_target_type (index_type
);
949 if (index_type
->is_stub ())
950 result_type
->set_target_is_stub (true);
952 result_type
->set_length (check_typedef (index_type
)->length ());
955 = (struct range_bounds
*) TYPE_ZALLOC (result_type
, sizeof (range_bounds
));
956 bounds
->low
= *low_bound
;
957 bounds
->high
= *high_bound
;
959 bounds
->stride
.set_const_val (0);
961 result_type
->set_bounds (bounds
);
963 if (index_type
->code () == TYPE_CODE_FIXED_POINT
)
964 result_type
->set_is_unsigned (index_type
->is_unsigned ());
965 else if (index_type
->is_unsigned ())
967 /* If the underlying type is unsigned, then the range
969 result_type
->set_is_unsigned (true);
971 /* Otherwise, the signed-ness of a range type can't simply be copied
972 from the underlying type. Consider a case where the underlying
973 type is 'int', but the range type can hold 0..65535, and where
974 the range is further specified to fit into 16 bits. In this
975 case, if we copy the underlying type's sign, then reading some
976 range values will cause an unwanted sign extension. So, we have
977 some heuristics here instead. */
978 else if (low_bound
->is_constant () && low_bound
->const_val () >= 0)
980 result_type
->set_is_unsigned (true);
981 /* Ada allows the declaration of range types whose upper bound is
982 less than the lower bound, so checking the lower bound is not
983 enough. Make sure we do not mark a range type whose upper bound
984 is negative as unsigned. */
985 if (high_bound
->is_constant () && high_bound
->const_val () < 0)
986 result_type
->set_is_unsigned (false);
989 result_type
->set_endianity_is_not_default
990 (index_type
->endianity_is_not_default ());
995 /* See gdbtypes.h. */
998 create_range_type_with_stride (type_allocator
&alloc
,
999 struct type
*index_type
,
1000 const struct dynamic_prop
*low_bound
,
1001 const struct dynamic_prop
*high_bound
,
1003 const struct dynamic_prop
*stride
,
1006 struct type
*result_type
= create_range_type (alloc
, index_type
, low_bound
,
1009 gdb_assert (stride
!= nullptr);
1010 result_type
->bounds ()->stride
= *stride
;
1011 result_type
->bounds ()->flag_is_byte_stride
= byte_stride_p
;
1016 /* See gdbtypes.h. */
1019 create_static_range_type (type_allocator
&alloc
, struct type
*index_type
,
1020 LONGEST low_bound
, LONGEST high_bound
)
1022 struct dynamic_prop low
, high
;
1024 low
.set_const_val (low_bound
);
1025 high
.set_const_val (high_bound
);
1027 struct type
*result_type
= create_range_type (alloc
, index_type
,
1033 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
1034 are static, otherwise returns 0. */
1037 has_static_range (const struct range_bounds
*bounds
)
1039 /* If the range doesn't have a defined stride then its stride field will
1040 be initialized to the constant 0. */
1041 return (bounds
->low
.is_constant ()
1042 && bounds
->high
.is_constant ()
1043 && bounds
->stride
.is_constant ());
1046 /* See gdbtypes.h. */
1048 gdb::optional
<LONGEST
>
1049 get_discrete_low_bound (struct type
*type
)
1051 type
= check_typedef (type
);
1052 switch (type
->code ())
1054 case TYPE_CODE_RANGE
:
1056 /* This function only works for ranges with a constant low bound. */
1057 if (!type
->bounds ()->low
.is_constant ())
1060 LONGEST low
= type
->bounds ()->low
.const_val ();
1062 if (type
->target_type ()->code () == TYPE_CODE_ENUM
)
1064 gdb::optional
<LONGEST
> low_pos
1065 = discrete_position (type
->target_type (), low
);
1067 if (low_pos
.has_value ())
1074 case TYPE_CODE_ENUM
:
1076 if (type
->num_fields () > 0)
1078 /* The enums may not be sorted by value, so search all
1080 LONGEST low
= type
->field (0).loc_enumval ();
1082 for (int i
= 0; i
< type
->num_fields (); i
++)
1084 if (type
->field (i
).loc_enumval () < low
)
1085 low
= type
->field (i
).loc_enumval ();
1094 case TYPE_CODE_BOOL
:
1098 if (type
->length () > sizeof (LONGEST
)) /* Too big */
1101 if (!type
->is_unsigned ())
1102 return -(1 << (type
->length () * TARGET_CHAR_BIT
- 1));
1105 case TYPE_CODE_CHAR
:
1113 /* See gdbtypes.h. */
1115 gdb::optional
<LONGEST
>
1116 get_discrete_high_bound (struct type
*type
)
1118 type
= check_typedef (type
);
1119 switch (type
->code ())
1121 case TYPE_CODE_RANGE
:
1123 /* This function only works for ranges with a constant high bound. */
1124 if (!type
->bounds ()->high
.is_constant ())
1127 LONGEST high
= type
->bounds ()->high
.const_val ();
1129 if (type
->target_type ()->code () == TYPE_CODE_ENUM
)
1131 gdb::optional
<LONGEST
> high_pos
1132 = discrete_position (type
->target_type (), high
);
1134 if (high_pos
.has_value ())
1141 case TYPE_CODE_ENUM
:
1143 if (type
->num_fields () > 0)
1145 /* The enums may not be sorted by value, so search all
1147 LONGEST high
= type
->field (0).loc_enumval ();
1149 for (int i
= 0; i
< type
->num_fields (); i
++)
1151 if (type
->field (i
).loc_enumval () > high
)
1152 high
= type
->field (i
).loc_enumval ();
1161 case TYPE_CODE_BOOL
:
1165 if (type
->length () > sizeof (LONGEST
)) /* Too big */
1168 if (!type
->is_unsigned ())
1170 LONGEST low
= -(1 << (type
->length () * TARGET_CHAR_BIT
- 1));
1175 case TYPE_CODE_CHAR
:
1177 /* This round-about calculation is to avoid shifting by
1178 type->length () * TARGET_CHAR_BIT, which will not work
1179 if type->length () == sizeof (LONGEST). */
1180 LONGEST high
= 1 << (type
->length () * TARGET_CHAR_BIT
- 1);
1181 return (high
- 1) | high
;
1189 /* See gdbtypes.h. */
1192 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
1194 gdb::optional
<LONGEST
> low
= get_discrete_low_bound (type
);
1195 if (!low
.has_value ())
1198 gdb::optional
<LONGEST
> high
= get_discrete_high_bound (type
);
1199 if (!high
.has_value ())
1208 /* See gdbtypes.h */
1211 get_array_bounds (struct type
*type
, LONGEST
*low_bound
, LONGEST
*high_bound
)
1213 struct type
*index
= type
->index_type ();
1220 if (!get_discrete_bounds (index
, &low
, &high
))
1232 /* Assuming that TYPE is a discrete type and VAL is a valid integer
1233 representation of a value of this type, save the corresponding
1234 position number in POS.
1236 Its differs from VAL only in the case of enumeration types. In
1237 this case, the position number of the value of the first listed
1238 enumeration literal is zero; the position number of the value of
1239 each subsequent enumeration literal is one more than that of its
1240 predecessor in the list.
1242 Return 1 if the operation was successful. Return zero otherwise,
1243 in which case the value of POS is unmodified.
1246 gdb::optional
<LONGEST
>
1247 discrete_position (struct type
*type
, LONGEST val
)
1249 if (type
->code () == TYPE_CODE_RANGE
)
1250 type
= type
->target_type ();
1252 if (type
->code () == TYPE_CODE_ENUM
)
1256 for (i
= 0; i
< type
->num_fields (); i
+= 1)
1258 if (val
== type
->field (i
).loc_enumval ())
1262 /* Invalid enumeration value. */
1269 /* If the array TYPE has static bounds calculate and update its
1270 size, then return true. Otherwise return false and leave TYPE
1274 update_static_array_size (struct type
*type
)
1276 gdb_assert (type
->code () == TYPE_CODE_ARRAY
);
1278 struct type
*range_type
= type
->index_type ();
1280 if (type
->dyn_prop (DYN_PROP_BYTE_STRIDE
) == nullptr
1281 && has_static_range (range_type
->bounds ())
1282 && (!type_not_associated (type
)
1283 && !type_not_allocated (type
)))
1285 LONGEST low_bound
, high_bound
;
1287 struct type
*element_type
;
1289 stride
= type
->bit_stride ();
1291 if (!get_discrete_bounds (range_type
, &low_bound
, &high_bound
))
1292 low_bound
= high_bound
= 0;
1294 element_type
= check_typedef (type
->target_type ());
1295 /* Be careful when setting the array length. Ada arrays can be
1296 empty arrays with the high_bound being smaller than the low_bound.
1297 In such cases, the array length should be zero. */
1298 if (high_bound
< low_bound
)
1299 type
->set_length (0);
1300 else if (stride
!= 0)
1302 /* Ensure that the type length is always positive, even in the
1303 case where (for example in Fortran) we have a negative
1304 stride. It is possible to have a single element array with a
1305 negative stride in Fortran (this doesn't mean anything
1306 special, it's still just a single element array) so do
1307 consider that case when touching this code. */
1308 LONGEST element_count
= std::abs (high_bound
- low_bound
+ 1);
1309 type
->set_length (((std::abs (stride
) * element_count
) + 7) / 8);
1312 type
->set_length (element_type
->length ()
1313 * (high_bound
- low_bound
+ 1));
1315 /* If this array's element is itself an array with a bit stride,
1316 then we want to update this array's bit stride to reflect the
1317 size of the sub-array. Otherwise, we'll end up using the
1318 wrong size when trying to find elements of the outer
1320 if (element_type
->code () == TYPE_CODE_ARRAY
1321 && (stride
!= 0 || element_type
->is_multi_dimensional ())
1322 && element_type
->length () != 0
1323 && element_type
->field (0).bitsize () != 0
1324 && get_array_bounds (element_type
, &low_bound
, &high_bound
)
1325 && high_bound
>= low_bound
)
1326 type
->field (0).set_bitsize
1327 ((high_bound
- low_bound
+ 1)
1328 * element_type
->field (0).bitsize ());
1336 /* See gdbtypes.h. */
1339 create_array_type_with_stride (type_allocator
&alloc
,
1340 struct type
*element_type
,
1341 struct type
*range_type
,
1342 struct dynamic_prop
*byte_stride_prop
,
1343 unsigned int bit_stride
)
1345 if (byte_stride_prop
!= nullptr && byte_stride_prop
->is_constant ())
1347 /* The byte stride is actually not dynamic. Pretend we were
1348 called with bit_stride set instead of byte_stride_prop.
1349 This will give us the same result type, while avoiding
1350 the need to handle this as a special case. */
1351 bit_stride
= byte_stride_prop
->const_val () * 8;
1352 byte_stride_prop
= NULL
;
1355 struct type
*result_type
= alloc
.new_type ();
1357 result_type
->set_code (TYPE_CODE_ARRAY
);
1358 result_type
->set_target_type (element_type
);
1360 result_type
->alloc_fields (1);
1361 result_type
->set_index_type (range_type
);
1362 if (byte_stride_prop
!= NULL
)
1363 result_type
->add_dyn_prop (DYN_PROP_BYTE_STRIDE
, *byte_stride_prop
);
1364 else if (bit_stride
> 0)
1365 result_type
->field (0).set_bitsize (bit_stride
);
1367 if (!update_static_array_size (result_type
))
1369 /* This type is dynamic and its length needs to be computed
1370 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1371 undefined by setting it to zero. Although we are not expected
1372 to trust TYPE_LENGTH in this case, setting the size to zero
1373 allows us to avoid allocating objects of random sizes in case
1374 we accidently do. */
1375 result_type
->set_length (0);
1378 /* TYPE_TARGET_STUB will take care of zero length arrays. */
1379 if (result_type
->length () == 0)
1380 result_type
->set_target_is_stub (true);
1385 /* See gdbtypes.h. */
1388 create_array_type (type_allocator
&alloc
,
1389 struct type
*element_type
,
1390 struct type
*range_type
)
1392 return create_array_type_with_stride (alloc
, element_type
,
1393 range_type
, NULL
, 0);
1397 lookup_array_range_type (struct type
*element_type
,
1398 LONGEST low_bound
, LONGEST high_bound
)
1400 struct type
*index_type
;
1401 struct type
*range_type
;
1403 type_allocator
alloc (element_type
);
1404 index_type
= builtin_type (element_type
->arch ())->builtin_int
;
1406 range_type
= create_static_range_type (alloc
, index_type
,
1407 low_bound
, high_bound
);
1409 return create_array_type (alloc
, element_type
, range_type
);
1412 /* See gdbtypes.h. */
1415 create_string_type (type_allocator
&alloc
,
1416 struct type
*string_char_type
,
1417 struct type
*range_type
)
1419 struct type
*result_type
= create_array_type (alloc
,
1422 result_type
->set_code (TYPE_CODE_STRING
);
1427 lookup_string_range_type (struct type
*string_char_type
,
1428 LONGEST low_bound
, LONGEST high_bound
)
1430 struct type
*result_type
;
1432 result_type
= lookup_array_range_type (string_char_type
,
1433 low_bound
, high_bound
);
1434 result_type
->set_code (TYPE_CODE_STRING
);
1439 create_set_type (type_allocator
&alloc
, struct type
*domain_type
)
1441 struct type
*result_type
= alloc
.new_type ();
1443 result_type
->set_code (TYPE_CODE_SET
);
1444 result_type
->alloc_fields (1);
1446 if (!domain_type
->is_stub ())
1448 LONGEST low_bound
, high_bound
, bit_length
;
1450 if (!get_discrete_bounds (domain_type
, &low_bound
, &high_bound
))
1451 low_bound
= high_bound
= 0;
1453 bit_length
= high_bound
- low_bound
+ 1;
1454 result_type
->set_length ((bit_length
+ TARGET_CHAR_BIT
- 1)
1457 result_type
->set_is_unsigned (true);
1459 result_type
->field (0).set_type (domain_type
);
1464 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1465 and any array types nested inside it. */
1468 make_vector_type (struct type
*array_type
)
1470 struct type
*inner_array
, *elt_type
;
1472 /* Find the innermost array type, in case the array is
1473 multi-dimensional. */
1474 inner_array
= array_type
;
1475 while (inner_array
->target_type ()->code () == TYPE_CODE_ARRAY
)
1476 inner_array
= inner_array
->target_type ();
1478 elt_type
= inner_array
->target_type ();
1479 if (elt_type
->code () == TYPE_CODE_INT
)
1481 type_instance_flags flags
1482 = elt_type
->instance_flags () | TYPE_INSTANCE_FLAG_NOTTEXT
;
1483 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
1484 inner_array
->set_target_type (elt_type
);
1487 array_type
->set_is_vector (true);
1491 init_vector_type (struct type
*elt_type
, int n
)
1493 struct type
*array_type
;
1495 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
1496 make_vector_type (array_type
);
1500 /* Internal routine called by TYPE_SELF_TYPE to return the type that TYPE
1501 belongs to. In c++ this is the class of "this", but TYPE_THIS_TYPE is too
1502 confusing. "self" is a common enough replacement for "this".
1503 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1504 TYPE_CODE_METHOD. */
1507 internal_type_self_type (struct type
*type
)
1509 switch (type
->code ())
1511 case TYPE_CODE_METHODPTR
:
1512 case TYPE_CODE_MEMBERPTR
:
1513 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1515 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1516 return TYPE_MAIN_TYPE (type
)->type_specific
.self_type
;
1517 case TYPE_CODE_METHOD
:
1518 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1520 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1521 return TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
;
1523 gdb_assert_not_reached ("bad type");
1527 /* Set the type of the class that TYPE belongs to.
1528 In c++ this is the class of "this".
1529 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1530 TYPE_CODE_METHOD. */
1533 set_type_self_type (struct type
*type
, struct type
*self_type
)
1535 switch (type
->code ())
1537 case TYPE_CODE_METHODPTR
:
1538 case TYPE_CODE_MEMBERPTR
:
1539 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1540 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_SELF_TYPE
;
1541 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1542 TYPE_MAIN_TYPE (type
)->type_specific
.self_type
= self_type
;
1544 case TYPE_CODE_METHOD
:
1545 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1546 INIT_FUNC_SPECIFIC (type
);
1547 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1548 TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
= self_type
;
1551 gdb_assert_not_reached ("bad type");
1555 /* Smash TYPE to be a type of pointers to members of SELF_TYPE with type
1556 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1557 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1558 TYPE doesn't include the offset (that's the value of the MEMBER
1559 itself), but does include the structure type into which it points
1562 When "smashing" the type, we preserve the objfile that the old type
1563 pointed to, since we aren't changing where the type is actually
1567 smash_to_memberptr_type (struct type
*type
, struct type
*self_type
,
1568 struct type
*to_type
)
1571 type
->set_code (TYPE_CODE_MEMBERPTR
);
1572 type
->set_target_type (to_type
);
1573 set_type_self_type (type
, self_type
);
1574 /* Assume that a data member pointer is the same size as a normal
1576 type
->set_length (gdbarch_ptr_bit (to_type
->arch ()) / TARGET_CHAR_BIT
);
1579 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1581 When "smashing" the type, we preserve the objfile that the old type
1582 pointed to, since we aren't changing where the type is actually
1586 smash_to_methodptr_type (struct type
*type
, struct type
*to_type
)
1589 type
->set_code (TYPE_CODE_METHODPTR
);
1590 type
->set_target_type (to_type
);
1591 set_type_self_type (type
, TYPE_SELF_TYPE (to_type
));
1592 type
->set_length (cplus_method_ptr_size (to_type
));
1595 /* Smash TYPE to be a type of method of SELF_TYPE with type TO_TYPE.
1596 METHOD just means `function that gets an extra "this" argument'.
1598 When "smashing" the type, we preserve the objfile that the old type
1599 pointed to, since we aren't changing where the type is actually
1603 smash_to_method_type (struct type
*type
, struct type
*self_type
,
1604 struct type
*to_type
, struct field
*args
,
1605 int nargs
, int varargs
)
1608 type
->set_code (TYPE_CODE_METHOD
);
1609 type
->set_target_type (to_type
);
1610 set_type_self_type (type
, self_type
);
1611 type
->set_fields (args
);
1612 type
->set_num_fields (nargs
);
1615 type
->set_has_varargs (true);
1617 /* In practice, this is never needed. */
1618 type
->set_length (1);
1621 /* A wrapper of TYPE_NAME which calls error if the type is anonymous.
1622 Since GCC PR debug/47510 DWARF provides associated information to detect the
1623 anonymous class linkage name from its typedef.
1625 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1629 type_name_or_error (struct type
*type
)
1631 struct type
*saved_type
= type
;
1633 struct objfile
*objfile
;
1635 type
= check_typedef (type
);
1637 name
= type
->name ();
1641 name
= saved_type
->name ();
1642 objfile
= saved_type
->objfile_owner ();
1643 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1644 name
? name
: "<anonymous>",
1645 objfile
? objfile_name (objfile
) : "<arch>");
1648 /* See gdbtypes.h. */
1651 lookup_typename (const struct language_defn
*language
,
1653 const struct block
*block
, int noerr
)
1657 sym
= lookup_symbol_in_language (name
, block
, VAR_DOMAIN
,
1658 language
->la_language
, NULL
).symbol
;
1659 if (sym
!= NULL
&& sym
->aclass () == LOC_TYPEDEF
)
1661 struct type
*type
= sym
->type ();
1662 /* Ensure the length of TYPE is valid. */
1663 check_typedef (type
);
1669 error (_("No type named %s."), name
);
1673 lookup_unsigned_typename (const struct language_defn
*language
,
1677 uns
.reserve (strlen (name
) + strlen ("unsigned "));
1681 return lookup_typename (language
, uns
.c_str (), NULL
, 0);
1685 lookup_signed_typename (const struct language_defn
*language
, const char *name
)
1687 /* In C and C++, "char" and "signed char" are distinct types. */
1688 if (streq (name
, "char"))
1689 name
= "signed char";
1690 return lookup_typename (language
, name
, NULL
, 0);
1693 /* Lookup a structure type named "struct NAME",
1694 visible in lexical block BLOCK. */
1697 lookup_struct (const char *name
, const struct block
*block
)
1701 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1705 error (_("No struct type named %s."), name
);
1707 if (sym
->type ()->code () != TYPE_CODE_STRUCT
)
1709 error (_("This context has class, union or enum %s, not a struct."),
1712 return (sym
->type ());
1715 /* Lookup a union type named "union NAME",
1716 visible in lexical block BLOCK. */
1719 lookup_union (const char *name
, const struct block
*block
)
1724 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1727 error (_("No union type named %s."), name
);
1731 if (t
->code () == TYPE_CODE_UNION
)
1734 /* If we get here, it's not a union. */
1735 error (_("This context has class, struct or enum %s, not a union."),
1739 /* Lookup an enum type named "enum NAME",
1740 visible in lexical block BLOCK. */
1743 lookup_enum (const char *name
, const struct block
*block
)
1747 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1750 error (_("No enum type named %s."), name
);
1752 if (sym
->type ()->code () != TYPE_CODE_ENUM
)
1754 error (_("This context has class, struct or union %s, not an enum."),
1757 return (sym
->type ());
1760 /* Lookup a template type named "template NAME<TYPE>",
1761 visible in lexical block BLOCK. */
1764 lookup_template_type (const char *name
, struct type
*type
,
1765 const struct block
*block
)
1768 nam
.reserve (strlen (name
) + strlen (type
->name ()) + strlen ("< >"));
1771 nam
+= type
->name ();
1772 nam
+= " >"; /* FIXME, extra space still introduced in gcc? */
1774 symbol
*sym
= lookup_symbol (nam
.c_str (), block
, VAR_DOMAIN
, 0).symbol
;
1778 error (_("No template type named %s."), name
);
1780 if (sym
->type ()->code () != TYPE_CODE_STRUCT
)
1782 error (_("This context has class, union or enum %s, not a struct."),
1785 return (sym
->type ());
1788 /* See gdbtypes.h. */
1791 lookup_struct_elt (struct type
*type
, const char *name
, int noerr
)
1797 type
= check_typedef (type
);
1798 if (type
->code () != TYPE_CODE_PTR
1799 && type
->code () != TYPE_CODE_REF
)
1801 type
= type
->target_type ();
1804 if (type
->code () != TYPE_CODE_STRUCT
1805 && type
->code () != TYPE_CODE_UNION
)
1807 std::string type_name
= type_to_string (type
);
1808 error (_("Type %s is not a structure or union type."),
1809 type_name
.c_str ());
1812 for (i
= type
->num_fields () - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1814 const char *t_field_name
= type
->field (i
).name ();
1816 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1818 return {&type
->field (i
), type
->field (i
).loc_bitpos ()};
1820 else if (!t_field_name
|| *t_field_name
== '\0')
1823 = lookup_struct_elt (type
->field (i
).type (), name
, 1);
1824 if (elt
.field
!= NULL
)
1826 elt
.offset
+= type
->field (i
).loc_bitpos ();
1832 /* OK, it's not in this class. Recursively check the baseclasses. */
1833 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1835 struct_elt elt
= lookup_struct_elt (TYPE_BASECLASS (type
, i
), name
, 1);
1836 if (elt
.field
!= NULL
)
1841 return {nullptr, 0};
1843 std::string type_name
= type_to_string (type
);
1844 error (_("Type %s has no component named %s."), type_name
.c_str (), name
);
1847 /* See gdbtypes.h. */
1850 lookup_struct_elt_type (struct type
*type
, const char *name
, int noerr
)
1852 struct_elt elt
= lookup_struct_elt (type
, name
, noerr
);
1853 if (elt
.field
!= NULL
)
1854 return elt
.field
->type ();
1859 /* Return the largest number representable by unsigned integer type TYPE. */
1862 get_unsigned_type_max (struct type
*type
)
1866 type
= check_typedef (type
);
1867 gdb_assert (type
->code () == TYPE_CODE_INT
&& type
->is_unsigned ());
1868 gdb_assert (type
->length () <= sizeof (ULONGEST
));
1870 /* Written this way to avoid overflow. */
1871 n
= type
->length () * TARGET_CHAR_BIT
;
1872 return ((((ULONGEST
) 1 << (n
- 1)) - 1) << 1) | 1;
1875 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1876 signed integer type TYPE. */
1879 get_signed_type_minmax (struct type
*type
, LONGEST
*min
, LONGEST
*max
)
1883 type
= check_typedef (type
);
1884 gdb_assert (type
->code () == TYPE_CODE_INT
&& !type
->is_unsigned ());
1885 gdb_assert (type
->length () <= sizeof (LONGEST
));
1887 n
= type
->length () * TARGET_CHAR_BIT
;
1888 *min
= -((ULONGEST
) 1 << (n
- 1));
1889 *max
= ((ULONGEST
) 1 << (n
- 1)) - 1;
1892 /* Return the largest value representable by pointer type TYPE. */
1895 get_pointer_type_max (struct type
*type
)
1899 type
= check_typedef (type
);
1900 gdb_assert (type
->code () == TYPE_CODE_PTR
);
1901 gdb_assert (type
->length () <= sizeof (CORE_ADDR
));
1903 n
= type
->length () * TARGET_CHAR_BIT
;
1904 return ((((CORE_ADDR
) 1 << (n
- 1)) - 1) << 1) | 1;
1907 /* Internal routine called by TYPE_VPTR_FIELDNO to return the value of
1908 cplus_stuff.vptr_fieldno.
1910 cplus_stuff is initialized to cplus_struct_default which does not
1911 set vptr_fieldno to -1 for portability reasons (IWBN to use C99
1912 designated initializers). We cope with that here. */
1915 internal_type_vptr_fieldno (struct type
*type
)
1917 type
= check_typedef (type
);
1918 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1919 || type
->code () == TYPE_CODE_UNION
);
1920 if (!HAVE_CPLUS_STRUCT (type
))
1922 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
;
1925 /* Set the value of cplus_stuff.vptr_fieldno. */
1928 set_type_vptr_fieldno (struct type
*type
, int fieldno
)
1930 type
= check_typedef (type
);
1931 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1932 || type
->code () == TYPE_CODE_UNION
);
1933 if (!HAVE_CPLUS_STRUCT (type
))
1934 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1935 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
= fieldno
;
1938 /* Internal routine called by TYPE_VPTR_BASETYPE to return the value of
1939 cplus_stuff.vptr_basetype. */
1942 internal_type_vptr_basetype (struct type
*type
)
1944 type
= check_typedef (type
);
1945 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1946 || type
->code () == TYPE_CODE_UNION
);
1947 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_CPLUS_STUFF
);
1948 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
;
1951 /* Set the value of cplus_stuff.vptr_basetype. */
1954 set_type_vptr_basetype (struct type
*type
, struct type
*basetype
)
1956 type
= check_typedef (type
);
1957 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1958 || type
->code () == TYPE_CODE_UNION
);
1959 if (!HAVE_CPLUS_STRUCT (type
))
1960 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1961 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
= basetype
;
1964 /* Lookup the vptr basetype/fieldno values for TYPE.
1965 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1966 vptr_fieldno. Also, if found and basetype is from the same objfile,
1968 If not found, return -1 and ignore BASETYPEP.
1969 Callers should be aware that in some cases (for example,
1970 the type or one of its baseclasses is a stub type and we are
1971 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1972 this function will not be able to find the
1973 virtual function table pointer, and vptr_fieldno will remain -1 and
1974 vptr_basetype will remain NULL or incomplete. */
1977 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1979 type
= check_typedef (type
);
1981 if (TYPE_VPTR_FIELDNO (type
) < 0)
1985 /* We must start at zero in case the first (and only) baseclass
1986 is virtual (and hence we cannot share the table pointer). */
1987 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1989 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1991 struct type
*basetype
;
1993 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1996 /* If the type comes from a different objfile we can't cache
1997 it, it may have a different lifetime. PR 2384 */
1998 if (type
->objfile_owner () == basetype
->objfile_owner ())
2000 set_type_vptr_fieldno (type
, fieldno
);
2001 set_type_vptr_basetype (type
, basetype
);
2004 *basetypep
= basetype
;
2015 *basetypep
= TYPE_VPTR_BASETYPE (type
);
2016 return TYPE_VPTR_FIELDNO (type
);
2021 stub_noname_complaint (void)
2023 complaint (_("stub type has NULL name"));
2026 /* Return nonzero if TYPE has a DYN_PROP_BYTE_STRIDE dynamic property
2027 attached to it, and that property has a non-constant value. */
2030 array_type_has_dynamic_stride (struct type
*type
)
2032 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_BYTE_STRIDE
);
2034 return prop
!= nullptr && prop
->is_constant ();
2037 /* Worker for is_dynamic_type. */
2040 is_dynamic_type_internal (struct type
*type
, int top_level
)
2042 type
= check_typedef (type
);
2044 /* We only want to recognize references at the outermost level. */
2045 if (top_level
&& type
->code () == TYPE_CODE_REF
)
2046 type
= check_typedef (type
->target_type ());
2048 /* Types that have a dynamic TYPE_DATA_LOCATION are considered
2049 dynamic, even if the type itself is statically defined.
2050 From a user's point of view, this may appear counter-intuitive;
2051 but it makes sense in this context, because the point is to determine
2052 whether any part of the type needs to be resolved before it can
2054 if (TYPE_DATA_LOCATION (type
) != NULL
2055 && (TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCEXPR
2056 || TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCLIST
))
2059 if (TYPE_ASSOCIATED_PROP (type
))
2062 if (TYPE_ALLOCATED_PROP (type
))
2065 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
2066 if (prop
!= nullptr && prop
->kind () != PROP_TYPE
)
2069 if (TYPE_HAS_DYNAMIC_LENGTH (type
))
2072 switch (type
->code ())
2074 case TYPE_CODE_RANGE
:
2076 /* A range type is obviously dynamic if it has at least one
2077 dynamic bound. But also consider the range type to be
2078 dynamic when its subtype is dynamic, even if the bounds
2079 of the range type are static. It allows us to assume that
2080 the subtype of a static range type is also static. */
2081 return (!has_static_range (type
->bounds ())
2082 || is_dynamic_type_internal (type
->target_type (), 0));
2085 case TYPE_CODE_STRING
:
2086 /* Strings are very much like an array of characters, and can be
2087 treated as one here. */
2088 case TYPE_CODE_ARRAY
:
2090 gdb_assert (type
->num_fields () == 1);
2092 /* The array is dynamic if either the bounds are dynamic... */
2093 if (is_dynamic_type_internal (type
->index_type (), 0))
2095 /* ... or the elements it contains have a dynamic contents... */
2096 if (is_dynamic_type_internal (type
->target_type (), 0))
2098 /* ... or if it has a dynamic stride... */
2099 if (array_type_has_dynamic_stride (type
))
2104 case TYPE_CODE_STRUCT
:
2105 case TYPE_CODE_UNION
:
2109 bool is_cplus
= HAVE_CPLUS_STRUCT (type
);
2111 for (i
= 0; i
< type
->num_fields (); ++i
)
2113 /* Static fields can be ignored here. */
2114 if (type
->field (i
).is_static ())
2116 /* If the field has dynamic type, then so does TYPE. */
2117 if (is_dynamic_type_internal (type
->field (i
).type (), 0))
2119 /* If the field is at a fixed offset, then it is not
2121 if (type
->field (i
).loc_kind () != FIELD_LOC_KIND_DWARF_BLOCK
)
2123 /* Do not consider C++ virtual base types to be dynamic
2124 due to the field's offset being dynamic; these are
2125 handled via other means. */
2126 if (is_cplus
&& BASETYPE_VIA_VIRTUAL (type
, i
))
2137 /* See gdbtypes.h. */
2140 is_dynamic_type (struct type
*type
)
2142 return is_dynamic_type_internal (type
, 1);
2145 static struct type
*resolve_dynamic_type_internal
2146 (struct type
*type
, struct property_addr_info
*addr_stack
,
2147 const frame_info_ptr
&frame
, int top_level
);
2149 /* Given a dynamic range type (dyn_range_type) and a stack of
2150 struct property_addr_info elements, return a static version
2153 When RESOLVE_P is true then the returned static range is created by
2154 actually evaluating any dynamic properties within the range type, while
2155 when RESOLVE_P is false the returned static range has all of the bounds
2156 and stride information set to undefined. The RESOLVE_P set to false
2157 case will be used when evaluating a dynamic array that is not
2158 allocated, or not associated, i.e. the bounds information might not be
2161 RANK is the array rank for which we are resolving this range, and is a
2162 zero based count. The rank should never be negative.
2165 static struct type
*
2166 resolve_dynamic_range (struct type
*dyn_range_type
,
2167 struct property_addr_info
*addr_stack
,
2168 const frame_info_ptr
&frame
,
2169 int rank
, bool resolve_p
= true)
2172 struct type
*static_range_type
, *static_target_type
;
2173 struct dynamic_prop low_bound
, high_bound
, stride
;
2175 gdb_assert (dyn_range_type
->code () == TYPE_CODE_RANGE
);
2176 gdb_assert (rank
>= 0);
2178 const struct dynamic_prop
*prop
= &dyn_range_type
->bounds ()->low
;
2179 if (resolve_p
&& dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
,
2180 { (CORE_ADDR
) rank
}))
2181 low_bound
.set_const_val (value
);
2183 low_bound
.set_undefined ();
2185 prop
= &dyn_range_type
->bounds ()->high
;
2186 if (resolve_p
&& dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
,
2187 { (CORE_ADDR
) rank
}))
2189 high_bound
.set_const_val (value
);
2191 if (dyn_range_type
->bounds ()->flag_upper_bound_is_count
)
2192 high_bound
.set_const_val
2193 (low_bound
.const_val () + high_bound
.const_val () - 1);
2196 high_bound
.set_undefined ();
2198 bool byte_stride_p
= dyn_range_type
->bounds ()->flag_is_byte_stride
;
2199 prop
= &dyn_range_type
->bounds ()->stride
;
2200 if (resolve_p
&& dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
,
2201 { (CORE_ADDR
) rank
}))
2203 stride
.set_const_val (value
);
2205 /* If we have a bit stride that is not an exact number of bytes then
2206 I really don't think this is going to work with current GDB, the
2207 array indexing code in GDB seems to be pretty heavily tied to byte
2208 offsets right now. Assuming 8 bits in a byte. */
2209 struct gdbarch
*gdbarch
= dyn_range_type
->arch ();
2210 int unit_size
= gdbarch_addressable_memory_unit_size (gdbarch
);
2211 if (!byte_stride_p
&& (value
% (unit_size
* 8)) != 0)
2212 error (_("bit strides that are not a multiple of the byte size "
2213 "are currently not supported"));
2217 stride
.set_undefined ();
2218 byte_stride_p
= true;
2222 = resolve_dynamic_type_internal (dyn_range_type
->target_type (),
2223 addr_stack
, frame
, 0);
2224 LONGEST bias
= dyn_range_type
->bounds ()->bias
;
2225 type_allocator
alloc (dyn_range_type
);
2226 static_range_type
= create_range_type_with_stride
2227 (alloc
, static_target_type
,
2228 &low_bound
, &high_bound
, bias
, &stride
, byte_stride_p
);
2229 static_range_type
->set_name (dyn_range_type
->name ());
2230 static_range_type
->bounds ()->flag_bound_evaluated
= 1;
2231 return static_range_type
;
2234 /* Helper function for resolve_dynamic_array_or_string. This function
2235 resolves the properties for a single array at RANK within a nested array
2236 of arrays structure. The RANK value is greater than or equal to 0, and
2237 starts at it's maximum value and goes down by 1 for each recursive call
2238 to this function. So, for a 3-dimensional array, the first call to this
2239 function has RANK == 2, then we call ourselves recursively with RANK ==
2240 1, than again with RANK == 0, and at that point we should return.
2242 TYPE is updated as the dynamic properties are resolved, and so, should
2243 be a copy of the dynamic type, rather than the original dynamic type
2246 ADDR_STACK is a stack of struct property_addr_info to be used if needed
2247 during the dynamic resolution.
2249 When RESOLVE_P is true then the dynamic properties of TYPE are
2250 evaluated, otherwise the dynamic properties of TYPE are not evaluated,
2251 instead we assume the array is not allocated/associated yet. */
2253 static struct type
*
2254 resolve_dynamic_array_or_string_1 (struct type
*type
,
2255 struct property_addr_info
*addr_stack
,
2256 const frame_info_ptr
&frame
,
2257 int rank
, bool resolve_p
)
2260 struct type
*elt_type
;
2261 struct type
*range_type
;
2262 struct type
*ary_dim
;
2263 struct dynamic_prop
*prop
;
2264 unsigned int bit_stride
= 0;
2266 /* For dynamic type resolution strings can be treated like arrays of
2268 gdb_assert (type
->code () == TYPE_CODE_ARRAY
2269 || type
->code () == TYPE_CODE_STRING
);
2271 /* As the rank is a zero based count we expect this to never be
2273 gdb_assert (rank
>= 0);
2275 /* Resolve the allocated and associated properties before doing anything
2276 else. If an array is not allocated or not associated then (at least
2277 for Fortran) there is no guarantee that the data to define the upper
2278 bound, lower bound, or stride will be correct. If RESOLVE_P is
2279 already false at this point then this is not the first dimension of
2280 the array and a more outer dimension has already marked this array as
2281 not allocated/associated, as such we just ignore this property. This
2282 is fine as GDB only checks the allocated/associated on the outer most
2283 dimension of the array. */
2284 prop
= TYPE_ALLOCATED_PROP (type
);
2285 if (prop
!= NULL
&& resolve_p
2286 && dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2288 prop
->set_const_val (value
);
2293 prop
= TYPE_ASSOCIATED_PROP (type
);
2294 if (prop
!= NULL
&& resolve_p
2295 && dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2297 prop
->set_const_val (value
);
2302 range_type
= check_typedef (type
->index_type ());
2304 = resolve_dynamic_range (range_type
, addr_stack
, frame
, rank
, resolve_p
);
2306 ary_dim
= check_typedef (type
->target_type ());
2307 if (ary_dim
!= NULL
&& ary_dim
->code () == TYPE_CODE_ARRAY
)
2309 ary_dim
= copy_type (ary_dim
);
2310 elt_type
= resolve_dynamic_array_or_string_1 (ary_dim
, addr_stack
,
2315 elt_type
= type
->target_type ();
2317 prop
= type
->dyn_prop (DYN_PROP_BYTE_STRIDE
);
2318 if (prop
!= NULL
&& resolve_p
)
2320 if (dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2322 type
->remove_dyn_prop (DYN_PROP_BYTE_STRIDE
);
2323 bit_stride
= (unsigned int) (value
* 8);
2327 /* Could be a bug in our code, but it could also happen
2328 if the DWARF info is not correct. Issue a warning,
2329 and assume no byte/bit stride (leave bit_stride = 0). */
2330 warning (_("cannot determine array stride for type %s"),
2331 type
->name () ? type
->name () : "<no name>");
2335 bit_stride
= type
->field (0).bitsize ();
2337 type_allocator
alloc (type
, type_allocator::SMASH
);
2338 return create_array_type_with_stride (alloc
, elt_type
, range_type
, NULL
,
2342 /* Resolve an array or string type with dynamic properties, return a new
2343 type with the dynamic properties resolved to actual values. The
2344 ADDR_STACK represents the location of the object being resolved. */
2346 static struct type
*
2347 resolve_dynamic_array_or_string (struct type
*type
,
2348 struct property_addr_info
*addr_stack
,
2349 const frame_info_ptr
&frame
)
2354 /* For dynamic type resolution strings can be treated like arrays of
2356 gdb_assert (type
->code () == TYPE_CODE_ARRAY
2357 || type
->code () == TYPE_CODE_STRING
);
2359 type
= copy_type (type
);
2361 /* Resolve the rank property to get rank value. */
2362 struct dynamic_prop
*prop
= TYPE_RANK_PROP (type
);
2363 if (dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2365 prop
->set_const_val (value
);
2370 /* Rank is zero, if a variable is passed as an argument to a
2371 function. In this case the resolved type should not be an
2372 array, but should instead be that of an array element. */
2373 struct type
*dynamic_array_type
= type
;
2374 type
= copy_type (dynamic_array_type
->target_type ());
2375 struct dynamic_prop_list
*prop_list
2376 = TYPE_MAIN_TYPE (dynamic_array_type
)->dyn_prop_list
;
2377 if (prop_list
!= nullptr)
2379 struct obstack
*obstack
2380 = &type
->objfile_owner ()->objfile_obstack
;
2381 TYPE_MAIN_TYPE (type
)->dyn_prop_list
2382 = copy_dynamic_prop_list (obstack
, prop_list
);
2386 else if (type
->code () == TYPE_CODE_STRING
&& rank
!= 1)
2388 /* What would this even mean? A string with a dynamic rank
2390 error (_("unable to handle string with dynamic rank greater than 1"));
2394 /* Arrays with dynamic rank are initially just an array type
2395 with a target type that is the array element.
2397 However, now we know the rank of the array we need to build
2398 the array of arrays structure that GDB expects, that is we
2399 need an array type that has a target which is an array type,
2400 and so on, until eventually, we have the element type at the
2401 end of the chain. Create all the additional array types here
2402 by copying the top level array type. */
2403 struct type
*element_type
= type
->target_type ();
2404 struct type
*rank_type
= type
;
2405 for (int i
= 1; i
< rank
; i
++)
2407 rank_type
->set_target_type (copy_type (rank_type
));
2408 rank_type
= rank_type
->target_type ();
2410 rank_type
->set_target_type (element_type
);
2417 for (struct type
*tmp_type
= check_typedef (type
->target_type ());
2418 tmp_type
->code () == TYPE_CODE_ARRAY
;
2419 tmp_type
= check_typedef (tmp_type
->target_type ()))
2423 /* The rank that we calculated above is actually a count of the number of
2424 ranks. However, when we resolve the type of each individual array
2425 rank we should actually use a rank "offset", e.g. an array with a rank
2426 count of 1 (calculated above) will use the rank offset 0 in order to
2427 resolve the details of the first array dimension. As a result, we
2428 reduce the rank by 1 here. */
2431 return resolve_dynamic_array_or_string_1 (type
, addr_stack
, frame
, rank
,
2435 /* Resolve dynamic bounds of members of the union TYPE to static
2436 bounds. ADDR_STACK is a stack of struct property_addr_info
2437 to be used if needed during the dynamic resolution. */
2439 static struct type
*
2440 resolve_dynamic_union (struct type
*type
,
2441 struct property_addr_info
*addr_stack
,
2442 const frame_info_ptr
&frame
)
2444 struct type
*resolved_type
;
2446 unsigned int max_len
= 0;
2448 gdb_assert (type
->code () == TYPE_CODE_UNION
);
2450 resolved_type
= copy_type (type
);
2451 resolved_type
->copy_fields (type
);
2452 for (i
= 0; i
< resolved_type
->num_fields (); ++i
)
2456 if (type
->field (i
).is_static ())
2459 t
= resolve_dynamic_type_internal (resolved_type
->field (i
).type (),
2460 addr_stack
, frame
, 0);
2461 resolved_type
->field (i
).set_type (t
);
2463 struct type
*real_type
= check_typedef (t
);
2464 if (real_type
->length () > max_len
)
2465 max_len
= real_type
->length ();
2468 resolved_type
->set_length (max_len
);
2469 return resolved_type
;
2472 /* See gdbtypes.h. */
2475 variant::matches (ULONGEST value
, bool is_unsigned
) const
2477 for (const discriminant_range
&range
: discriminants
)
2478 if (range
.contains (value
, is_unsigned
))
2484 compute_variant_fields_inner (struct type
*type
,
2485 struct property_addr_info
*addr_stack
,
2486 const variant_part
&part
,
2487 std::vector
<bool> &flags
);
2489 /* A helper function to determine which variant fields will be active.
2490 This handles both the variant's direct fields, and any variant
2491 parts embedded in this variant. TYPE is the type we're examining.
2492 ADDR_STACK holds information about the concrete object. VARIANT is
2493 the current variant to be handled. FLAGS is where the results are
2494 stored -- this function sets the Nth element in FLAGS if the
2495 corresponding field is enabled. ENABLED is whether this variant is
2499 compute_variant_fields_recurse (struct type
*type
,
2500 struct property_addr_info
*addr_stack
,
2501 const variant
&variant
,
2502 std::vector
<bool> &flags
,
2505 for (int field
= variant
.first_field
; field
< variant
.last_field
; ++field
)
2506 flags
[field
] = enabled
;
2508 for (const variant_part
&new_part
: variant
.parts
)
2511 compute_variant_fields_inner (type
, addr_stack
, new_part
, flags
);
2514 for (const auto &sub_variant
: new_part
.variants
)
2515 compute_variant_fields_recurse (type
, addr_stack
, sub_variant
,
2521 /* A helper function to determine which variant fields will be active.
2522 This evaluates the discriminant, decides which variant (if any) is
2523 active, and then updates FLAGS to reflect which fields should be
2524 available. TYPE is the type we're examining. ADDR_STACK holds
2525 information about the concrete object. VARIANT is the current
2526 variant to be handled. FLAGS is where the results are stored --
2527 this function sets the Nth element in FLAGS if the corresponding
2528 field is enabled. */
2531 compute_variant_fields_inner (struct type
*type
,
2532 struct property_addr_info
*addr_stack
,
2533 const variant_part
&part
,
2534 std::vector
<bool> &flags
)
2536 /* Evaluate the discriminant. */
2537 gdb::optional
<ULONGEST
> discr_value
;
2538 if (part
.discriminant_index
!= -1)
2540 int idx
= part
.discriminant_index
;
2542 if (type
->field (idx
).loc_kind () != FIELD_LOC_KIND_BITPOS
)
2543 error (_("Cannot determine struct field location"
2544 " (invalid location kind)"));
2546 if (addr_stack
->valaddr
.data () != NULL
)
2547 discr_value
= unpack_field_as_long (type
, addr_stack
->valaddr
.data (),
2551 CORE_ADDR addr
= (addr_stack
->addr
2552 + (type
->field (idx
).loc_bitpos ()
2553 / TARGET_CHAR_BIT
));
2555 LONGEST bitsize
= type
->field (idx
).bitsize ();
2556 LONGEST size
= bitsize
/ 8;
2558 size
= type
->field (idx
).type ()->length ();
2560 gdb_byte bits
[sizeof (ULONGEST
)];
2561 read_memory (addr
, bits
, size
);
2563 LONGEST bitpos
= (type
->field (idx
).loc_bitpos ()
2566 discr_value
= unpack_bits_as_long (type
->field (idx
).type (),
2567 bits
, bitpos
, bitsize
);
2571 /* Go through each variant and see which applies. */
2572 const variant
*default_variant
= nullptr;
2573 const variant
*applied_variant
= nullptr;
2574 for (const auto &variant
: part
.variants
)
2576 if (variant
.is_default ())
2577 default_variant
= &variant
;
2578 else if (discr_value
.has_value ()
2579 && variant
.matches (*discr_value
, part
.is_unsigned
))
2581 applied_variant
= &variant
;
2585 if (applied_variant
== nullptr)
2586 applied_variant
= default_variant
;
2588 for (const auto &variant
: part
.variants
)
2589 compute_variant_fields_recurse (type
, addr_stack
, variant
,
2590 flags
, applied_variant
== &variant
);
2593 /* Determine which variant fields are available in TYPE. The enabled
2594 fields are stored in RESOLVED_TYPE. ADDR_STACK holds information
2595 about the concrete object. PARTS describes the top-level variant
2596 parts for this type. */
2599 compute_variant_fields (struct type
*type
,
2600 struct type
*resolved_type
,
2601 struct property_addr_info
*addr_stack
,
2602 const gdb::array_view
<variant_part
> &parts
)
2604 /* Assume all fields are included by default. */
2605 std::vector
<bool> flags (resolved_type
->num_fields (), true);
2607 /* Now disable fields based on the variants that control them. */
2608 for (const auto &part
: parts
)
2609 compute_variant_fields_inner (type
, addr_stack
, part
, flags
);
2611 unsigned int nfields
= std::count (flags
.begin (), flags
.end (), true);
2612 /* No need to zero-initialize the newly allocated fields, they'll be
2613 initialized by the copy in the loop below. */
2614 resolved_type
->alloc_fields (nfields
, false);
2617 for (int i
= 0; i
< type
->num_fields (); ++i
)
2622 resolved_type
->field (out
) = type
->field (i
);
2627 /* Resolve dynamic bounds of members of the struct TYPE to static
2628 bounds. ADDR_STACK is a stack of struct property_addr_info to
2629 be used if needed during the dynamic resolution. */
2631 static struct type
*
2632 resolve_dynamic_struct (struct type
*type
,
2633 struct property_addr_info
*addr_stack
,
2634 const frame_info_ptr
&frame
)
2636 struct type
*resolved_type
;
2638 unsigned resolved_type_bit_length
= 0;
2640 gdb_assert (type
->code () == TYPE_CODE_STRUCT
);
2642 resolved_type
= copy_type (type
);
2644 dynamic_prop
*variant_prop
= resolved_type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
2645 if (variant_prop
!= nullptr && variant_prop
->kind () == PROP_VARIANT_PARTS
)
2647 compute_variant_fields (type
, resolved_type
, addr_stack
,
2648 *variant_prop
->variant_parts ());
2649 /* We want to leave the property attached, so that the Rust code
2650 can tell whether the type was originally an enum. */
2651 variant_prop
->set_original_type (type
);
2655 resolved_type
->copy_fields (type
);
2658 for (i
= 0; i
< resolved_type
->num_fields (); ++i
)
2660 unsigned new_bit_length
;
2661 struct property_addr_info pinfo
;
2663 if (resolved_type
->field (i
).is_static ())
2666 if (resolved_type
->field (i
).loc_kind () == FIELD_LOC_KIND_DWARF_BLOCK
)
2668 struct dwarf2_property_baton baton
;
2670 = lookup_pointer_type (resolved_type
->field (i
).type ());
2671 baton
.locexpr
= *resolved_type
->field (i
).loc_dwarf_block ();
2673 struct dynamic_prop prop
;
2674 prop
.set_locexpr (&baton
);
2677 if (dwarf2_evaluate_property (&prop
, frame
, addr_stack
, &addr
,
2678 {addr_stack
->addr
}))
2679 resolved_type
->field (i
).set_loc_bitpos
2680 (TARGET_CHAR_BIT
* (addr
- addr_stack
->addr
));
2683 /* As we know this field is not a static field, the field's
2684 field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
2685 this is the case, but only trigger a simple error rather
2686 than an internal error if that fails. While failing
2687 that verification indicates a bug in our code, the error
2688 is not severe enough to suggest to the user he stops
2689 his debugging session because of it. */
2690 if (resolved_type
->field (i
).loc_kind () != FIELD_LOC_KIND_BITPOS
)
2691 error (_("Cannot determine struct field location"
2692 " (invalid location kind)"));
2694 pinfo
.type
= check_typedef (resolved_type
->field (i
).type ());
2695 size_t offset
= resolved_type
->field (i
).loc_bitpos () / TARGET_CHAR_BIT
;
2696 pinfo
.valaddr
= addr_stack
->valaddr
;
2697 if (!pinfo
.valaddr
.empty ())
2698 pinfo
.valaddr
= pinfo
.valaddr
.slice (offset
);
2699 pinfo
.addr
= addr_stack
->addr
+ offset
;
2700 pinfo
.next
= addr_stack
;
2702 resolved_type
->field (i
).set_type
2703 (resolve_dynamic_type_internal (resolved_type
->field (i
).type (),
2705 gdb_assert (resolved_type
->field (i
).loc_kind ()
2706 == FIELD_LOC_KIND_BITPOS
);
2708 new_bit_length
= resolved_type
->field (i
).loc_bitpos ();
2709 if (resolved_type
->field (i
).bitsize () != 0)
2710 new_bit_length
+= resolved_type
->field (i
).bitsize ();
2713 struct type
*real_type
2714 = check_typedef (resolved_type
->field (i
).type ());
2716 new_bit_length
+= (real_type
->length () * TARGET_CHAR_BIT
);
2719 /* Normally, we would use the position and size of the last field
2720 to determine the size of the enclosing structure. But GCC seems
2721 to be encoding the position of some fields incorrectly when
2722 the struct contains a dynamic field that is not placed last.
2723 So we compute the struct size based on the field that has
2724 the highest position + size - probably the best we can do. */
2725 if (new_bit_length
> resolved_type_bit_length
)
2726 resolved_type_bit_length
= new_bit_length
;
2729 /* The length of a type won't change for fortran, but it does for C and Ada.
2730 For fortran the size of dynamic fields might change over time but not the
2731 type length of the structure. If we adapt it, we run into problems
2732 when calculating the element offset for arrays of structs. */
2733 if (current_language
->la_language
!= language_fortran
)
2734 resolved_type
->set_length ((resolved_type_bit_length
+ TARGET_CHAR_BIT
- 1)
2737 /* The Ada language uses this field as a cache for static fixed types: reset
2738 it as RESOLVED_TYPE must have its own static fixed type. */
2739 resolved_type
->set_target_type (nullptr);
2741 return resolved_type
;
2744 /* Worker for resolved_dynamic_type. */
2746 static struct type
*
2747 resolve_dynamic_type_internal (struct type
*type
,
2748 struct property_addr_info
*addr_stack
,
2749 const frame_info_ptr
&frame
,
2752 struct type
*real_type
= check_typedef (type
);
2753 struct type
*resolved_type
= nullptr;
2754 struct dynamic_prop
*prop
;
2757 if (!is_dynamic_type_internal (real_type
, top_level
))
2760 gdb::optional
<CORE_ADDR
> type_length
;
2761 prop
= TYPE_DYNAMIC_LENGTH (type
);
2763 && dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2764 type_length
= value
;
2766 if (type
->code () == TYPE_CODE_TYPEDEF
)
2768 resolved_type
= copy_type (type
);
2769 resolved_type
->set_target_type
2770 (resolve_dynamic_type_internal (type
->target_type (), addr_stack
,
2775 /* Before trying to resolve TYPE, make sure it is not a stub. */
2778 switch (type
->code ())
2782 struct property_addr_info pinfo
;
2784 pinfo
.type
= check_typedef (type
->target_type ());
2786 if (addr_stack
->valaddr
.data () != NULL
)
2787 pinfo
.addr
= extract_typed_address (addr_stack
->valaddr
.data (),
2790 pinfo
.addr
= read_memory_typed_address (addr_stack
->addr
, type
);
2791 pinfo
.next
= addr_stack
;
2793 resolved_type
= copy_type (type
);
2794 resolved_type
->set_target_type
2795 (resolve_dynamic_type_internal (type
->target_type (),
2796 &pinfo
, frame
, top_level
));
2800 case TYPE_CODE_STRING
:
2801 /* Strings are very much like an array of characters, and can be
2802 treated as one here. */
2803 case TYPE_CODE_ARRAY
:
2804 resolved_type
= resolve_dynamic_array_or_string (type
, addr_stack
,
2808 case TYPE_CODE_RANGE
:
2809 /* Pass 0 for the rank value here, which indicates this is a
2810 range for the first rank of an array. The assumption is that
2811 this rank value is not actually required for the resolution of
2812 the dynamic range, otherwise, we'd be resolving this range
2813 within the context of a dynamic array. */
2814 resolved_type
= resolve_dynamic_range (type
, addr_stack
, frame
, 0);
2817 case TYPE_CODE_UNION
:
2818 resolved_type
= resolve_dynamic_union (type
, addr_stack
, frame
);
2821 case TYPE_CODE_STRUCT
:
2822 resolved_type
= resolve_dynamic_struct (type
, addr_stack
, frame
);
2827 if (resolved_type
== nullptr)
2830 if (type_length
.has_value ())
2832 resolved_type
->set_length (*type_length
);
2833 resolved_type
->remove_dyn_prop (DYN_PROP_BYTE_SIZE
);
2836 /* Resolve data_location attribute. */
2837 prop
= TYPE_DATA_LOCATION (resolved_type
);
2839 && dwarf2_evaluate_property (prop
, frame
, addr_stack
, &value
))
2841 /* Start of Fortran hack. See comment in f-lang.h for what is going
2843 if (current_language
->la_language
== language_fortran
2844 && resolved_type
->code () == TYPE_CODE_ARRAY
)
2845 value
= fortran_adjust_dynamic_array_base_address_hack (resolved_type
,
2847 /* End of Fortran hack. */
2848 prop
->set_const_val (value
);
2851 return resolved_type
;
2854 /* See gdbtypes.h */
2857 resolve_dynamic_type (struct type
*type
,
2858 gdb::array_view
<const gdb_byte
> valaddr
,
2860 const frame_info_ptr
*in_frame
)
2862 struct property_addr_info pinfo
2863 = {check_typedef (type
), valaddr
, addr
, NULL
};
2865 frame_info_ptr frame
;
2866 if (in_frame
!= nullptr)
2869 return resolve_dynamic_type_internal (type
, &pinfo
, frame
, 1);
2872 /* See gdbtypes.h */
2875 type::dyn_prop (dynamic_prop_node_kind prop_kind
) const
2877 dynamic_prop_list
*node
= this->main_type
->dyn_prop_list
;
2879 while (node
!= NULL
)
2881 if (node
->prop_kind
== prop_kind
)
2888 /* See gdbtypes.h */
2891 type::add_dyn_prop (dynamic_prop_node_kind prop_kind
, dynamic_prop prop
)
2893 struct dynamic_prop_list
*temp
;
2895 gdb_assert (this->is_objfile_owned ());
2897 temp
= XOBNEW (&this->objfile_owner ()->objfile_obstack
,
2898 struct dynamic_prop_list
);
2899 temp
->prop_kind
= prop_kind
;
2901 temp
->next
= this->main_type
->dyn_prop_list
;
2903 this->main_type
->dyn_prop_list
= temp
;
2906 /* See gdbtypes.h. */
2909 type::remove_dyn_prop (dynamic_prop_node_kind kind
)
2911 struct dynamic_prop_list
*prev_node
, *curr_node
;
2913 curr_node
= this->main_type
->dyn_prop_list
;
2916 while (NULL
!= curr_node
)
2918 if (curr_node
->prop_kind
== kind
)
2920 /* Update the linked list but don't free anything.
2921 The property was allocated on objstack and it is not known
2922 if we are on top of it. Nevertheless, everything is released
2923 when the complete objstack is freed. */
2924 if (NULL
== prev_node
)
2925 this->main_type
->dyn_prop_list
= curr_node
->next
;
2927 prev_node
->next
= curr_node
->next
;
2932 prev_node
= curr_node
;
2933 curr_node
= curr_node
->next
;
2937 /* Find the real type of TYPE. This function returns the real type,
2938 after removing all layers of typedefs, and completing opaque or stub
2939 types. Completion changes the TYPE argument, but stripping of
2942 Instance flags (e.g. const/volatile) are preserved as typedefs are
2943 stripped. If necessary a new qualified form of the underlying type
2946 NOTE: This will return a typedef if type::target_type for the typedef has
2947 not been computed and we're either in the middle of reading symbols, or
2948 there was no name for the typedef in the debug info.
2950 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
2951 QUITs in the symbol reading code can also throw.
2952 Thus this function can throw an exception.
2954 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
2957 If this is a stubbed struct (i.e. declared as struct foo *), see if
2958 we can find a full definition in some other file. If so, copy this
2959 definition, so we can use it in future. There used to be a comment
2960 (but not any code) that if we don't find a full definition, we'd
2961 set a flag so we don't spend time in the future checking the same
2962 type. That would be a mistake, though--we might load in more
2963 symbols which contain a full definition for the type. */
2966 check_typedef (struct type
*type
)
2968 struct type
*orig_type
= type
;
2972 /* While we're removing typedefs, we don't want to lose qualifiers.
2973 E.g., const/volatile. */
2974 type_instance_flags instance_flags
= type
->instance_flags ();
2976 while (type
->code () == TYPE_CODE_TYPEDEF
)
2978 if (!type
->target_type ())
2983 /* It is dangerous to call lookup_symbol if we are currently
2984 reading a symtab. Infinite recursion is one danger. */
2985 if (currently_reading_symtab
)
2986 return make_qualified_type (type
, instance_flags
, NULL
);
2988 name
= type
->name ();
2989 /* FIXME: shouldn't we look in STRUCT_DOMAIN and/or
2990 VAR_DOMAIN as appropriate? */
2993 stub_noname_complaint ();
2994 return make_qualified_type (type
, instance_flags
, NULL
);
2996 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0).symbol
;
2998 type
->set_target_type (sym
->type ());
2999 else /* TYPE_CODE_UNDEF */
3000 type
->set_target_type (type_allocator (type
->arch ()).new_type ());
3002 type
= type
->target_type ();
3004 /* Preserve the instance flags as we traverse down the typedef chain.
3006 Handling address spaces/classes is nasty, what do we do if there's a
3008 E.g., what if an outer typedef marks the type as class_1 and an inner
3009 typedef marks the type as class_2?
3010 This is the wrong place to do such error checking. We leave it to
3011 the code that created the typedef in the first place to flag the
3012 error. We just pick the outer address space (akin to letting the
3013 outer cast in a chain of casting win), instead of assuming
3014 "it can't happen". */
3016 const type_instance_flags ALL_SPACES
3017 = (TYPE_INSTANCE_FLAG_CODE_SPACE
3018 | TYPE_INSTANCE_FLAG_DATA_SPACE
);
3019 const type_instance_flags ALL_CLASSES
3020 = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
;
3022 type_instance_flags new_instance_flags
= type
->instance_flags ();
3024 /* Treat code vs data spaces and address classes separately. */
3025 if ((instance_flags
& ALL_SPACES
) != 0)
3026 new_instance_flags
&= ~ALL_SPACES
;
3027 if ((instance_flags
& ALL_CLASSES
) != 0)
3028 new_instance_flags
&= ~ALL_CLASSES
;
3030 instance_flags
|= new_instance_flags
;
3034 /* If this is a struct/class/union with no fields, then check
3035 whether a full definition exists somewhere else. This is for
3036 systems where a type definition with no fields is issued for such
3037 types, instead of identifying them as stub types in the first
3040 if (TYPE_IS_OPAQUE (type
)
3041 && opaque_type_resolution
3042 && !currently_reading_symtab
)
3044 const char *name
= type
->name ();
3045 struct type
*newtype
;
3049 stub_noname_complaint ();
3050 return make_qualified_type (type
, instance_flags
, NULL
);
3052 newtype
= lookup_transparent_type (name
);
3056 /* If the resolved type and the stub are in the same
3057 objfile, then replace the stub type with the real deal.
3058 But if they're in separate objfiles, leave the stub
3059 alone; we'll just look up the transparent type every time
3060 we call check_typedef. We can't create pointers between
3061 types allocated to different objfiles, since they may
3062 have different lifetimes. Trying to copy NEWTYPE over to
3063 TYPE's objfile is pointless, too, since you'll have to
3064 move over any other types NEWTYPE refers to, which could
3065 be an unbounded amount of stuff. */
3066 if (newtype
->objfile_owner () == type
->objfile_owner ())
3067 type
= make_qualified_type (newtype
, type
->instance_flags (), type
);
3072 /* Otherwise, rely on the stub flag being set for opaque/stubbed
3074 else if (type
->is_stub () && !currently_reading_symtab
)
3076 const char *name
= type
->name ();
3077 /* FIXME: shouldn't we look in STRUCT_DOMAIN and/or VAR_DOMAIN
3083 stub_noname_complaint ();
3084 return make_qualified_type (type
, instance_flags
, NULL
);
3086 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0).symbol
;
3089 /* Same as above for opaque types, we can replace the stub
3090 with the complete type only if they are in the same
3092 if (sym
->type ()->objfile_owner () == type
->objfile_owner ())
3093 type
= make_qualified_type (sym
->type (),
3094 type
->instance_flags (), type
);
3096 type
= sym
->type ();
3100 if (type
->target_is_stub ())
3102 struct type
*target_type
= check_typedef (type
->target_type ());
3104 if (target_type
->is_stub () || target_type
->target_is_stub ())
3106 /* Nothing we can do. */
3108 else if (type
->code () == TYPE_CODE_RANGE
)
3110 type
->set_length (target_type
->length ());
3111 type
->set_target_is_stub (false);
3113 else if (type
->code () == TYPE_CODE_ARRAY
3114 && update_static_array_size (type
))
3115 type
->set_target_is_stub (false);
3118 type
= make_qualified_type (type
, instance_flags
, NULL
);
3120 /* Cache TYPE_LENGTH for future use. */
3121 orig_type
->set_length (type
->length ());
3126 /* Parse a type expression in the string [P..P+LENGTH). If an error
3127 occurs, silently return a void type. */
3129 static struct type
*
3130 safe_parse_type (struct gdbarch
*gdbarch
, const char *p
, int length
)
3132 struct type
*type
= NULL
; /* Initialize to keep gcc happy. */
3134 /* Suppress error messages. */
3135 scoped_restore saved_gdb_stderr
= make_scoped_restore (&gdb_stderr
,
3138 /* Call parse_and_eval_type() without fear of longjmp()s. */
3141 type
= parse_and_eval_type (p
, length
);
3143 catch (const gdb_exception_error
&except
)
3145 type
= builtin_type (gdbarch
)->builtin_void
;
3151 /* Ugly hack to convert method stubs into method types.
3153 He ain't kiddin'. This demangles the name of the method into a
3154 string including argument types, parses out each argument type,
3155 generates a string casting a zero to that type, evaluates the
3156 string, and stuffs the resulting type into an argtype vector!!!
3157 Then it knows the type of the whole function (including argument
3158 types for overloading), which info used to be in the stab's but was
3159 removed to hack back the space required for them. */
3162 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
3164 struct gdbarch
*gdbarch
= type
->arch ();
3166 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
3167 gdb::unique_xmalloc_ptr
<char> demangled_name
3168 = gdb_demangle (mangled_name
, DMGL_PARAMS
| DMGL_ANSI
);
3169 char *argtypetext
, *p
;
3170 int depth
= 0, argcount
= 1;
3171 struct field
*argtypes
;
3174 /* Make sure we got back a function string that we can use. */
3176 p
= strchr (demangled_name
.get (), '(');
3180 if (demangled_name
== NULL
|| p
== NULL
)
3181 error (_("Internal: Cannot demangle mangled name `%s'."),
3184 /* Now, read in the parameters that define this type. */
3189 if (*p
== '(' || *p
== '<')
3193 else if (*p
== ')' || *p
== '>')
3197 else if (*p
== ',' && depth
== 0)
3205 /* If we read one argument and it was ``void'', don't count it. */
3206 if (startswith (argtypetext
, "(void)"))
3209 /* We need one extra slot, for the THIS pointer. */
3211 argtypes
= (struct field
*)
3212 TYPE_ZALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
3215 /* Add THIS pointer for non-static methods. */
3216 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
3217 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
3221 argtypes
[0].set_type (lookup_pointer_type (type
));
3225 if (*p
!= ')') /* () means no args, skip while. */
3230 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
3232 /* Avoid parsing of ellipsis, they will be handled below.
3233 Also avoid ``void'' as above. */
3234 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
3235 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
3237 argtypes
[argcount
].set_type
3238 (safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
));
3241 argtypetext
= p
+ 1;
3244 if (*p
== '(' || *p
== '<')
3248 else if (*p
== ')' || *p
== '>')
3257 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
3259 /* Now update the old "stub" type into a real type. */
3260 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
3261 /* MTYPE may currently be a function (TYPE_CODE_FUNC).
3262 We want a method (TYPE_CODE_METHOD). */
3263 smash_to_method_type (mtype
, type
, mtype
->target_type (),
3264 argtypes
, argcount
, p
[-2] == '.');
3265 mtype
->set_is_stub (false);
3266 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
3269 /* This is the external interface to check_stub_method, above. This
3270 function unstubs all of the signatures for TYPE's METHOD_ID method
3271 name. After calling this function TYPE_FN_FIELD_STUB will be
3272 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
3275 This function unfortunately can not die until stabs do. */
3278 check_stub_method_group (struct type
*type
, int method_id
)
3280 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
3281 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
3283 for (int j
= 0; j
< len
; j
++)
3285 if (TYPE_FN_FIELD_STUB (f
, j
))
3286 check_stub_method (type
, method_id
, j
);
3290 /* Ensure it is in .rodata (if available) by working around GCC PR 44690. */
3291 const struct cplus_struct_type cplus_struct_default
= { };
3294 allocate_cplus_struct_type (struct type
*type
)
3296 if (HAVE_CPLUS_STRUCT (type
))
3297 /* Structure was already allocated. Nothing more to do. */
3300 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_CPLUS_STUFF
;
3301 TYPE_RAW_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
3302 TYPE_ZALLOC (type
, sizeof (struct cplus_struct_type
));
3303 *(TYPE_RAW_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
3304 set_type_vptr_fieldno (type
, -1);
3307 const struct gnat_aux_type gnat_aux_default
=
3310 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
3311 and allocate the associated gnat-specific data. The gnat-specific
3312 data is also initialized to gnat_aux_default. */
3315 allocate_gnat_aux_type (struct type
*type
)
3317 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_GNAT_STUFF
;
3318 TYPE_GNAT_SPECIFIC (type
) = (struct gnat_aux_type
*)
3319 TYPE_ZALLOC (type
, sizeof (struct gnat_aux_type
));
3320 *(TYPE_GNAT_SPECIFIC (type
)) = gnat_aux_default
;
3323 /* Helper function to verify floating-point format and size.
3324 BIT is the type size in bits; if BIT equals -1, the size is
3325 determined by the floatformat. Returns size to be used. */
3328 verify_floatformat (int bit
, const struct floatformat
*floatformat
)
3330 gdb_assert (floatformat
!= NULL
);
3333 bit
= floatformat
->totalsize
;
3335 gdb_assert (bit
>= 0);
3336 gdb_assert (bit
>= floatformat
->totalsize
);
3341 /* Return the floating-point format for a floating-point variable of
3344 const struct floatformat
*
3345 floatformat_from_type (const struct type
*type
)
3347 gdb_assert (type
->code () == TYPE_CODE_FLT
);
3348 gdb_assert (TYPE_FLOATFORMAT (type
));
3349 return TYPE_FLOATFORMAT (type
);
3352 /* See gdbtypes.h. */
3355 init_integer_type (type_allocator
&alloc
,
3356 int bit
, int unsigned_p
, const char *name
)
3360 t
= alloc
.new_type (TYPE_CODE_INT
, bit
, name
);
3362 t
->set_is_unsigned (true);
3364 TYPE_SPECIFIC_FIELD (t
) = TYPE_SPECIFIC_INT
;
3365 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_size
= bit
;
3366 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_offset
= 0;
3371 /* See gdbtypes.h. */
3374 init_character_type (type_allocator
&alloc
,
3375 int bit
, int unsigned_p
, const char *name
)
3379 t
= alloc
.new_type (TYPE_CODE_CHAR
, bit
, name
);
3381 t
->set_is_unsigned (true);
3386 /* See gdbtypes.h. */
3389 init_boolean_type (type_allocator
&alloc
,
3390 int bit
, int unsigned_p
, const char *name
)
3394 t
= alloc
.new_type (TYPE_CODE_BOOL
, bit
, name
);
3396 t
->set_is_unsigned (true);
3398 TYPE_SPECIFIC_FIELD (t
) = TYPE_SPECIFIC_INT
;
3399 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_size
= bit
;
3400 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_offset
= 0;
3405 /* See gdbtypes.h. */
3408 init_float_type (type_allocator
&alloc
,
3409 int bit
, const char *name
,
3410 const struct floatformat
**floatformats
,
3411 enum bfd_endian byte_order
)
3413 if (byte_order
== BFD_ENDIAN_UNKNOWN
)
3415 struct gdbarch
*gdbarch
= alloc
.arch ();
3416 byte_order
= gdbarch_byte_order (gdbarch
);
3418 const struct floatformat
*fmt
= floatformats
[byte_order
];
3421 bit
= verify_floatformat (bit
, fmt
);
3422 t
= alloc
.new_type (TYPE_CODE_FLT
, bit
, name
);
3423 TYPE_FLOATFORMAT (t
) = fmt
;
3428 /* See gdbtypes.h. */
3431 init_decfloat_type (type_allocator
&alloc
, int bit
, const char *name
)
3433 return alloc
.new_type (TYPE_CODE_DECFLOAT
, bit
, name
);
3436 /* Return true if init_complex_type can be called with TARGET_TYPE. */
3439 can_create_complex_type (struct type
*target_type
)
3441 return (target_type
->code () == TYPE_CODE_INT
3442 || target_type
->code () == TYPE_CODE_FLT
);
3445 /* Allocate a TYPE_CODE_COMPLEX type structure. NAME is the type
3446 name. TARGET_TYPE is the component type. */
3449 init_complex_type (const char *name
, struct type
*target_type
)
3453 gdb_assert (can_create_complex_type (target_type
));
3455 if (TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
== nullptr)
3457 if (name
== nullptr && target_type
->name () != nullptr)
3459 /* No zero-initialization required, initialized by strcpy/strcat
3462 = (char *) TYPE_ALLOC (target_type
,
3463 strlen (target_type
->name ())
3464 + strlen ("_Complex ") + 1);
3465 strcpy (new_name
, "_Complex ");
3466 strcat (new_name
, target_type
->name ());
3470 t
= type_allocator (target_type
).new_type ();
3471 set_type_code (t
, TYPE_CODE_COMPLEX
);
3472 t
->set_length (2 * target_type
->length ());
3475 t
->set_target_type (target_type
);
3476 TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
= t
;
3479 return TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
;
3482 /* See gdbtypes.h. */
3485 init_pointer_type (type_allocator
&alloc
,
3486 int bit
, const char *name
, struct type
*target_type
)
3490 t
= alloc
.new_type (TYPE_CODE_PTR
, bit
, name
);
3491 t
->set_target_type (target_type
);
3492 t
->set_is_unsigned (true);
3496 /* Allocate a TYPE_CODE_FIXED_POINT type structure associated with OBJFILE.
3497 BIT is the pointer type size in bits.
3498 UNSIGNED_P should be nonzero if the type is unsigned.
3499 NAME is the type name. */
3502 init_fixed_point_type (type_allocator
&alloc
,
3503 int bit
, int unsigned_p
, const char *name
)
3507 t
= alloc
.new_type (TYPE_CODE_FIXED_POINT
, bit
, name
);
3509 t
->set_is_unsigned (true);
3514 /* See gdbtypes.h. */
3517 type_raw_align (struct type
*type
)
3519 if (type
->align_log2
!= 0)
3520 return 1 << (type
->align_log2
- 1);
3524 /* See gdbtypes.h. */
3527 type_align (struct type
*type
)
3529 /* Check alignment provided in the debug information. */
3530 unsigned raw_align
= type_raw_align (type
);
3534 /* Allow the architecture to provide an alignment. */
3535 ULONGEST align
= gdbarch_type_align (type
->arch (), type
);
3539 switch (type
->code ())
3542 case TYPE_CODE_FUNC
:
3543 case TYPE_CODE_FLAGS
:
3545 case TYPE_CODE_RANGE
:
3547 case TYPE_CODE_ENUM
:
3549 case TYPE_CODE_RVALUE_REF
:
3550 case TYPE_CODE_CHAR
:
3551 case TYPE_CODE_BOOL
:
3552 case TYPE_CODE_DECFLOAT
:
3553 case TYPE_CODE_METHODPTR
:
3554 case TYPE_CODE_MEMBERPTR
:
3555 align
= type_length_units (check_typedef (type
));
3558 case TYPE_CODE_ARRAY
:
3559 case TYPE_CODE_COMPLEX
:
3560 case TYPE_CODE_TYPEDEF
:
3561 align
= type_align (type
->target_type ());
3564 case TYPE_CODE_STRUCT
:
3565 case TYPE_CODE_UNION
:
3567 int number_of_non_static_fields
= 0;
3568 for (unsigned i
= 0; i
< type
->num_fields (); ++i
)
3570 if (!type
->field (i
).is_static ())
3572 number_of_non_static_fields
++;
3573 ULONGEST f_align
= type_align (type
->field (i
).type ());
3576 /* Don't pretend we know something we don't. */
3580 if (f_align
> align
)
3584 /* A struct with no fields, or with only static fields has an
3586 if (number_of_non_static_fields
== 0)
3592 case TYPE_CODE_STRING
:
3593 /* Not sure what to do here, and these can't appear in C or C++
3597 case TYPE_CODE_VOID
:
3601 case TYPE_CODE_ERROR
:
3602 case TYPE_CODE_METHOD
:
3607 if ((align
& (align
- 1)) != 0)
3609 /* Not a power of 2, so pass. */
3616 /* See gdbtypes.h. */
3619 set_type_align (struct type
*type
, ULONGEST align
)
3621 /* Must be a power of 2. Zero is ok. */
3622 gdb_assert ((align
& (align
- 1)) == 0);
3624 unsigned result
= 0;
3631 if (result
>= (1 << TYPE_ALIGN_BITS
))
3634 type
->align_log2
= result
;
3639 /* Queries on types. */
3642 can_dereference (struct type
*t
)
3644 /* FIXME: Should we return true for references as well as
3646 t
= check_typedef (t
);
3649 && t
->code () == TYPE_CODE_PTR
3650 && t
->target_type ()->code () != TYPE_CODE_VOID
);
3654 is_integral_type (struct type
*t
)
3656 t
= check_typedef (t
);
3659 && !is_fixed_point_type (t
)
3660 && ((t
->code () == TYPE_CODE_INT
)
3661 || (t
->code () == TYPE_CODE_ENUM
)
3662 || (t
->code () == TYPE_CODE_FLAGS
)
3663 || (t
->code () == TYPE_CODE_CHAR
)
3664 || (t
->code () == TYPE_CODE_RANGE
)
3665 || (t
->code () == TYPE_CODE_BOOL
)));
3669 is_floating_type (struct type
*t
)
3671 t
= check_typedef (t
);
3674 && ((t
->code () == TYPE_CODE_FLT
)
3675 || (t
->code () == TYPE_CODE_DECFLOAT
)));
3678 /* Return true if TYPE is scalar. */
3681 is_scalar_type (struct type
*type
)
3683 type
= check_typedef (type
);
3685 if (is_fixed_point_type (type
))
3686 return 0; /* Implemented as a scalar, but more like a floating point. */
3688 switch (type
->code ())
3690 case TYPE_CODE_ARRAY
:
3691 case TYPE_CODE_STRUCT
:
3692 case TYPE_CODE_UNION
:
3694 case TYPE_CODE_STRING
:
3701 /* Return true if T is scalar, or a composite type which in practice has
3702 the memory layout of a scalar type. E.g., an array or struct with only
3703 one scalar element inside it, or a union with only scalar elements. */
3706 is_scalar_type_recursive (struct type
*t
)
3708 t
= check_typedef (t
);
3710 if (is_scalar_type (t
))
3712 /* Are we dealing with an array or string of known dimensions? */
3713 else if ((t
->code () == TYPE_CODE_ARRAY
3714 || t
->code () == TYPE_CODE_STRING
) && t
->num_fields () == 1
3715 && t
->index_type ()->code () == TYPE_CODE_RANGE
)
3717 LONGEST low_bound
, high_bound
;
3718 struct type
*elt_type
= check_typedef (t
->target_type ());
3720 if (get_discrete_bounds (t
->index_type (), &low_bound
, &high_bound
))
3721 return (high_bound
== low_bound
3722 && is_scalar_type_recursive (elt_type
));
3726 /* Are we dealing with a struct with one element? */
3727 else if (t
->code () == TYPE_CODE_STRUCT
&& t
->num_fields () == 1)
3728 return is_scalar_type_recursive (t
->field (0).type ());
3729 else if (t
->code () == TYPE_CODE_UNION
)
3731 int i
, n
= t
->num_fields ();
3733 /* If all elements of the union are scalar, then the union is scalar. */
3734 for (i
= 0; i
< n
; i
++)
3735 if (!is_scalar_type_recursive (t
->field (i
).type ()))
3744 /* Return true is T is a class or a union. False otherwise. */
3747 class_or_union_p (const struct type
*t
)
3749 return (t
->code () == TYPE_CODE_STRUCT
3750 || t
->code () == TYPE_CODE_UNION
);
3753 /* A helper function which returns true if types A and B represent the
3754 "same" class type. This is true if the types have the same main
3755 type, or the same name. */
3758 class_types_same_p (const struct type
*a
, const struct type
*b
)
3760 return (TYPE_MAIN_TYPE (a
) == TYPE_MAIN_TYPE (b
)
3761 || (a
->name () && b
->name ()
3762 && !strcmp (a
->name (), b
->name ())));
3765 /* If BASE is an ancestor of DCLASS return the distance between them.
3766 otherwise return -1;
3770 class B: public A {};
3771 class C: public B {};
3774 distance_to_ancestor (A, A, 0) = 0
3775 distance_to_ancestor (A, B, 0) = 1
3776 distance_to_ancestor (A, C, 0) = 2
3777 distance_to_ancestor (A, D, 0) = 3
3779 If PUBLIC is 1 then only public ancestors are considered,
3780 and the function returns the distance only if BASE is a public ancestor
3784 distance_to_ancestor (A, D, 1) = -1. */
3787 distance_to_ancestor (struct type
*base
, struct type
*dclass
, int is_public
)
3792 base
= check_typedef (base
);
3793 dclass
= check_typedef (dclass
);
3795 if (class_types_same_p (base
, dclass
))
3798 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
3800 if (is_public
&& ! BASETYPE_VIA_PUBLIC (dclass
, i
))
3803 d
= distance_to_ancestor (base
, TYPE_BASECLASS (dclass
, i
), is_public
);
3811 /* Check whether BASE is an ancestor or base class or DCLASS
3812 Return 1 if so, and 0 if not.
3813 Note: If BASE and DCLASS are of the same type, this function
3814 will return 1. So for some class A, is_ancestor (A, A) will
3818 is_ancestor (struct type
*base
, struct type
*dclass
)
3820 return distance_to_ancestor (base
, dclass
, 0) >= 0;
3823 /* Like is_ancestor, but only returns true when BASE is a public
3824 ancestor of DCLASS. */
3827 is_public_ancestor (struct type
*base
, struct type
*dclass
)
3829 return distance_to_ancestor (base
, dclass
, 1) >= 0;
3832 /* A helper function for is_unique_ancestor. */
3835 is_unique_ancestor_worker (struct type
*base
, struct type
*dclass
,
3837 const gdb_byte
*valaddr
, int embedded_offset
,
3838 CORE_ADDR address
, struct value
*val
)
3842 base
= check_typedef (base
);
3843 dclass
= check_typedef (dclass
);
3845 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
) && count
< 2; ++i
)
3850 iter
= check_typedef (TYPE_BASECLASS (dclass
, i
));
3852 this_offset
= baseclass_offset (dclass
, i
, valaddr
, embedded_offset
,
3855 if (class_types_same_p (base
, iter
))
3857 /* If this is the first subclass, set *OFFSET and set count
3858 to 1. Otherwise, if this is at the same offset as
3859 previous instances, do nothing. Otherwise, increment
3863 *offset
= this_offset
;
3866 else if (this_offset
== *offset
)
3874 count
+= is_unique_ancestor_worker (base
, iter
, offset
,
3876 embedded_offset
+ this_offset
,
3883 /* Like is_ancestor, but only returns true if BASE is a unique base
3884 class of the type of VAL. */
3887 is_unique_ancestor (struct type
*base
, struct value
*val
)
3891 return is_unique_ancestor_worker (base
, val
->type (), &offset
,
3892 val
->contents_for_printing ().data (),
3893 val
->embedded_offset (),
3894 val
->address (), val
) == 1;
3897 /* See gdbtypes.h. */
3900 type_byte_order (const struct type
*type
)
3902 bfd_endian byteorder
= gdbarch_byte_order (type
->arch ());
3903 if (type
->endianity_is_not_default ())
3905 if (byteorder
== BFD_ENDIAN_BIG
)
3906 return BFD_ENDIAN_LITTLE
;
3909 gdb_assert (byteorder
== BFD_ENDIAN_LITTLE
);
3910 return BFD_ENDIAN_BIG
;
3917 /* See gdbtypes.h. */
3920 is_nocall_function (const struct type
*type
)
3922 if (type
->code () != TYPE_CODE_FUNC
&& type
->code () != TYPE_CODE_METHOD
)
3925 return TYPE_CALLING_CONVENTION (type
) == DW_CC_nocall
;
3929 /* Overload resolution. */
3931 /* Return the sum of the rank of A with the rank of B. */
3934 sum_ranks (struct rank a
, struct rank b
)
3937 c
.rank
= a
.rank
+ b
.rank
;
3938 c
.subrank
= a
.subrank
+ b
.subrank
;
3942 /* Compare rank A and B and return:
3944 1 if a is better than b
3945 -1 if b is better than a. */
3948 compare_ranks (struct rank a
, struct rank b
)
3950 if (a
.rank
== b
.rank
)
3952 if (a
.subrank
== b
.subrank
)
3954 if (a
.subrank
< b
.subrank
)
3956 if (a
.subrank
> b
.subrank
)
3960 if (a
.rank
< b
.rank
)
3963 /* a.rank > b.rank */
3967 /* Functions for overload resolution begin here. */
3969 /* Compare two badness vectors A and B and return the result.
3970 0 => A and B are identical
3971 1 => A and B are incomparable
3972 2 => A is better than B
3973 3 => A is worse than B */
3976 compare_badness (const badness_vector
&a
, const badness_vector
&b
)
3980 /* Any positives in comparison? */
3981 bool found_pos
= false;
3982 /* Any negatives in comparison? */
3983 bool found_neg
= false;
3984 /* Did A have any INVALID_CONVERSION entries. */
3985 bool a_invalid
= false;
3986 /* Did B have any INVALID_CONVERSION entries. */
3987 bool b_invalid
= false;
3989 /* differing sizes => incomparable */
3990 if (a
.size () != b
.size ())
3993 /* Subtract b from a */
3994 for (i
= 0; i
< a
.size (); i
++)
3996 tmp
= compare_ranks (b
[i
], a
[i
]);
4001 if (a
[i
].rank
>= INVALID_CONVERSION
)
4003 if (b
[i
].rank
>= INVALID_CONVERSION
)
4007 /* B will only be considered better than or incomparable to A if
4008 they both have invalid entries, or if neither does. That is, if
4009 A has only valid entries, and B has an invalid entry, then A will
4010 be considered better than B, even if B happens to be better for
4012 if (a_invalid
!= b_invalid
)
4015 return 3; /* A > B */
4016 return 2; /* A < B */
4021 return 1; /* incomparable */
4023 return 3; /* A > B */
4029 return 2; /* A < B */
4031 return 0; /* A == B */
4035 /* Rank a function by comparing its parameter types (PARMS), to the
4036 types of an argument list (ARGS). Return the badness vector. This
4037 has ARGS.size() + 1 entries. */
4040 rank_function (gdb::array_view
<type
*> parms
,
4041 gdb::array_view
<value
*> args
)
4043 /* add 1 for the length-match rank. */
4045 bv
.reserve (1 + args
.size ());
4047 /* First compare the lengths of the supplied lists.
4048 If there is a mismatch, set it to a high value. */
4050 /* pai/1997-06-03 FIXME: when we have debug info about default
4051 arguments and ellipsis parameter lists, we should consider those
4052 and rank the length-match more finely. */
4054 bv
.push_back ((args
.size () != parms
.size ())
4055 ? LENGTH_MISMATCH_BADNESS
4056 : EXACT_MATCH_BADNESS
);
4058 /* Now rank all the parameters of the candidate function. */
4059 size_t min_len
= std::min (parms
.size (), args
.size ());
4061 for (size_t i
= 0; i
< min_len
; i
++)
4062 bv
.push_back (rank_one_type (parms
[i
], args
[i
]->type (),
4065 /* If more arguments than parameters, add dummy entries. */
4066 for (size_t i
= min_len
; i
< args
.size (); i
++)
4067 bv
.push_back (TOO_FEW_PARAMS_BADNESS
);
4072 /* Compare the names of two integer types, assuming that any sign
4073 qualifiers have been checked already. We do it this way because
4074 there may be an "int" in the name of one of the types. */
4077 integer_types_same_name_p (const char *first
, const char *second
)
4079 int first_p
, second_p
;
4081 /* If both are shorts, return 1; if neither is a short, keep
4083 first_p
= (strstr (first
, "short") != NULL
);
4084 second_p
= (strstr (second
, "short") != NULL
);
4085 if (first_p
&& second_p
)
4087 if (first_p
|| second_p
)
4090 /* Likewise for long. */
4091 first_p
= (strstr (first
, "long") != NULL
);
4092 second_p
= (strstr (second
, "long") != NULL
);
4093 if (first_p
&& second_p
)
4095 if (first_p
|| second_p
)
4098 /* Likewise for char. */
4099 first_p
= (strstr (first
, "char") != NULL
);
4100 second_p
= (strstr (second
, "char") != NULL
);
4101 if (first_p
&& second_p
)
4103 if (first_p
|| second_p
)
4106 /* They must both be ints. */
4110 /* Compares type A to type B. Returns true if they represent the same
4111 type, false otherwise. */
4114 types_equal (struct type
*a
, struct type
*b
)
4116 /* Identical type pointers. */
4117 /* However, this still doesn't catch all cases of same type for b
4118 and a. The reason is that builtin types are different from
4119 the same ones constructed from the object. */
4123 /* Resolve typedefs */
4124 if (a
->code () == TYPE_CODE_TYPEDEF
)
4125 a
= check_typedef (a
);
4126 if (b
->code () == TYPE_CODE_TYPEDEF
)
4127 b
= check_typedef (b
);
4129 /* Check if identical after resolving typedefs. */
4133 /* If after resolving typedefs a and b are not of the same type
4134 code then they are not equal. */
4135 if (a
->code () != b
->code ())
4138 /* If a and b are both pointers types or both reference types then
4139 they are equal of the same type iff the objects they refer to are
4140 of the same type. */
4141 if (a
->code () == TYPE_CODE_PTR
4142 || a
->code () == TYPE_CODE_REF
)
4143 return types_equal (a
->target_type (),
4146 /* Well, damnit, if the names are exactly the same, I'll say they
4147 are exactly the same. This happens when we generate method
4148 stubs. The types won't point to the same address, but they
4149 really are the same. */
4151 if (a
->name () && b
->name ()
4152 && strcmp (a
->name (), b
->name ()) == 0)
4155 /* Two function types are equal if their argument and return types
4157 if (a
->code () == TYPE_CODE_FUNC
)
4161 if (a
->num_fields () != b
->num_fields ())
4164 if (!types_equal (a
->target_type (), b
->target_type ()))
4167 for (i
= 0; i
< a
->num_fields (); ++i
)
4168 if (!types_equal (a
->field (i
).type (), b
->field (i
).type ()))
4177 /* Deep comparison of types. */
4179 /* An entry in the type-equality bcache. */
4181 struct type_equality_entry
4183 type_equality_entry (struct type
*t1
, struct type
*t2
)
4189 struct type
*type1
, *type2
;
4192 /* A helper function to compare two strings. Returns true if they are
4193 the same, false otherwise. Handles NULLs properly. */
4196 compare_maybe_null_strings (const char *s
, const char *t
)
4198 if (s
== NULL
|| t
== NULL
)
4200 return strcmp (s
, t
) == 0;
4203 /* A helper function for check_types_worklist that checks two types for
4204 "deep" equality. Returns true if the types are considered the
4205 same, false otherwise. */
4208 check_types_equal (struct type
*type1
, struct type
*type2
,
4209 std::vector
<type_equality_entry
> *worklist
)
4211 type1
= check_typedef (type1
);
4212 type2
= check_typedef (type2
);
4217 if (type1
->code () != type2
->code ()
4218 || type1
->length () != type2
->length ()
4219 || type1
->is_unsigned () != type2
->is_unsigned ()
4220 || type1
->has_no_signedness () != type2
->has_no_signedness ()
4221 || type1
->endianity_is_not_default () != type2
->endianity_is_not_default ()
4222 || type1
->has_varargs () != type2
->has_varargs ()
4223 || type1
->is_vector () != type2
->is_vector ()
4224 || TYPE_NOTTEXT (type1
) != TYPE_NOTTEXT (type2
)
4225 || type1
->instance_flags () != type2
->instance_flags ()
4226 || type1
->num_fields () != type2
->num_fields ())
4229 if (!compare_maybe_null_strings (type1
->name (), type2
->name ()))
4231 if (!compare_maybe_null_strings (type1
->name (), type2
->name ()))
4234 if (type1
->code () == TYPE_CODE_RANGE
)
4236 if (*type1
->bounds () != *type2
->bounds ())
4243 for (i
= 0; i
< type1
->num_fields (); ++i
)
4245 const struct field
*field1
= &type1
->field (i
);
4246 const struct field
*field2
= &type2
->field (i
);
4248 if (field1
->is_artificial () != field2
->is_artificial ()
4249 || field1
->bitsize () != field2
->bitsize ()
4250 || field1
->loc_kind () != field2
->loc_kind ())
4252 if (!compare_maybe_null_strings (field1
->name (), field2
->name ()))
4254 switch (field1
->loc_kind ())
4256 case FIELD_LOC_KIND_BITPOS
:
4257 if (field1
->loc_bitpos () != field2
->loc_bitpos ())
4260 case FIELD_LOC_KIND_ENUMVAL
:
4261 if (field1
->loc_enumval () != field2
->loc_enumval ())
4263 /* Don't compare types of enum fields, because they don't
4266 case FIELD_LOC_KIND_PHYSADDR
:
4267 if (field1
->loc_physaddr () != field2
->loc_physaddr ())
4270 case FIELD_LOC_KIND_PHYSNAME
:
4271 if (!compare_maybe_null_strings (field1
->loc_physname (),
4272 field2
->loc_physname ()))
4275 case FIELD_LOC_KIND_DWARF_BLOCK
:
4277 struct dwarf2_locexpr_baton
*block1
, *block2
;
4279 block1
= field1
->loc_dwarf_block ();
4280 block2
= field2
->loc_dwarf_block ();
4281 if (block1
->per_cu
!= block2
->per_cu
4282 || block1
->size
!= block2
->size
4283 || memcmp (block1
->data
, block2
->data
, block1
->size
) != 0)
4288 internal_error (_("Unsupported field kind "
4289 "%d by check_types_equal"),
4290 field1
->loc_kind ());
4293 worklist
->emplace_back (field1
->type (), field2
->type ());
4297 if (type1
->target_type () != NULL
)
4299 if (type2
->target_type () == NULL
)
4302 worklist
->emplace_back (type1
->target_type (),
4303 type2
->target_type ());
4305 else if (type2
->target_type () != NULL
)
4311 /* Check types on a worklist for equality. Returns false if any pair
4312 is not equal, true if they are all considered equal. */
4315 check_types_worklist (std::vector
<type_equality_entry
> *worklist
,
4318 while (!worklist
->empty ())
4322 struct type_equality_entry entry
= std::move (worklist
->back ());
4323 worklist
->pop_back ();
4325 /* If the type pair has already been visited, we know it is
4327 cache
->insert (&entry
, sizeof (entry
), &added
);
4331 if (!check_types_equal (entry
.type1
, entry
.type2
, worklist
))
4338 /* Return true if types TYPE1 and TYPE2 are equal, as determined by a
4339 "deep comparison". Otherwise return false. */
4342 types_deeply_equal (struct type
*type1
, struct type
*type2
)
4344 std::vector
<type_equality_entry
> worklist
;
4346 gdb_assert (type1
!= NULL
&& type2
!= NULL
);
4348 /* Early exit for the simple case. */
4353 worklist
.emplace_back (type1
, type2
);
4354 return check_types_worklist (&worklist
, &cache
);
4357 /* Allocated status of type TYPE. Return zero if type TYPE is allocated.
4358 Otherwise return one. */
4361 type_not_allocated (const struct type
*type
)
4363 struct dynamic_prop
*prop
= TYPE_ALLOCATED_PROP (type
);
4365 return prop
!= nullptr && prop
->is_constant () && prop
->const_val () == 0;
4368 /* Associated status of type TYPE. Return zero if type TYPE is associated.
4369 Otherwise return one. */
4372 type_not_associated (const struct type
*type
)
4374 struct dynamic_prop
*prop
= TYPE_ASSOCIATED_PROP (type
);
4376 return prop
!= nullptr && prop
->is_constant () && prop
->const_val () == 0;
4379 /* rank_one_type helper for when PARM's type code is TYPE_CODE_PTR. */
4382 rank_one_type_parm_ptr (struct type
*parm
, struct type
*arg
, struct value
*value
)
4384 struct rank rank
= {0,0};
4386 switch (arg
->code ())
4390 /* Allowed pointer conversions are:
4391 (a) pointer to void-pointer conversion. */
4392 if (parm
->target_type ()->code () == TYPE_CODE_VOID
)
4393 return VOID_PTR_CONVERSION_BADNESS
;
4395 /* (b) pointer to ancestor-pointer conversion. */
4396 rank
.subrank
= distance_to_ancestor (parm
->target_type (),
4397 arg
->target_type (),
4399 if (rank
.subrank
>= 0)
4400 return sum_ranks (BASE_PTR_CONVERSION_BADNESS
, rank
);
4402 return INCOMPATIBLE_TYPE_BADNESS
;
4403 case TYPE_CODE_ARRAY
:
4405 struct type
*t1
= parm
->target_type ();
4406 struct type
*t2
= arg
->target_type ();
4408 if (types_equal (t1
, t2
))
4410 /* Make sure they are CV equal. */
4411 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
4412 rank
.subrank
|= CV_CONVERSION_CONST
;
4413 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
4414 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
4415 if (rank
.subrank
!= 0)
4416 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
4417 return EXACT_MATCH_BADNESS
;
4419 return INCOMPATIBLE_TYPE_BADNESS
;
4421 case TYPE_CODE_FUNC
:
4422 return rank_one_type (parm
->target_type (), arg
, NULL
);
4424 if (value
!= NULL
&& value
->type ()->code () == TYPE_CODE_INT
)
4426 if (value_as_long (value
) == 0)
4428 /* Null pointer conversion: allow it to be cast to a pointer.
4429 [4.10.1 of C++ standard draft n3290] */
4430 return NULL_POINTER_CONVERSION_BADNESS
;
4434 /* If type checking is disabled, allow the conversion. */
4435 if (!strict_type_checking
)
4436 return NS_INTEGER_POINTER_CONVERSION_BADNESS
;
4440 case TYPE_CODE_ENUM
:
4441 case TYPE_CODE_FLAGS
:
4442 case TYPE_CODE_CHAR
:
4443 case TYPE_CODE_RANGE
:
4444 case TYPE_CODE_BOOL
:
4446 return INCOMPATIBLE_TYPE_BADNESS
;
4450 /* rank_one_type helper for when PARM's type code is TYPE_CODE_ARRAY. */
4453 rank_one_type_parm_array (struct type
*parm
, struct type
*arg
, struct value
*value
)
4455 switch (arg
->code ())
4458 case TYPE_CODE_ARRAY
:
4459 return rank_one_type (parm
->target_type (),
4460 arg
->target_type (), NULL
);
4462 return INCOMPATIBLE_TYPE_BADNESS
;
4466 /* rank_one_type helper for when PARM's type code is TYPE_CODE_FUNC. */
4469 rank_one_type_parm_func (struct type
*parm
, struct type
*arg
, struct value
*value
)
4471 switch (arg
->code ())
4473 case TYPE_CODE_PTR
: /* funcptr -> func */
4474 return rank_one_type (parm
, arg
->target_type (), NULL
);
4476 return INCOMPATIBLE_TYPE_BADNESS
;
4480 /* rank_one_type helper for when PARM's type code is TYPE_CODE_INT. */
4483 rank_one_type_parm_int (struct type
*parm
, struct type
*arg
, struct value
*value
)
4485 switch (arg
->code ())
4488 if (arg
->length () == parm
->length ())
4490 /* Deal with signed, unsigned, and plain chars and
4491 signed and unsigned ints. */
4492 if (parm
->has_no_signedness ())
4494 /* This case only for character types. */
4495 if (arg
->has_no_signedness ())
4496 return EXACT_MATCH_BADNESS
; /* plain char -> plain char */
4497 else /* signed/unsigned char -> plain char */
4498 return INTEGER_CONVERSION_BADNESS
;
4500 else if (parm
->is_unsigned ())
4502 if (arg
->is_unsigned ())
4504 /* unsigned int -> unsigned int, or
4505 unsigned long -> unsigned long */
4506 if (integer_types_same_name_p (parm
->name (),
4508 return EXACT_MATCH_BADNESS
;
4509 else if (integer_types_same_name_p (arg
->name (),
4511 && integer_types_same_name_p (parm
->name (),
4513 /* unsigned int -> unsigned long */
4514 return INTEGER_PROMOTION_BADNESS
;
4516 /* unsigned long -> unsigned int */
4517 return INTEGER_CONVERSION_BADNESS
;
4521 if (integer_types_same_name_p (arg
->name (),
4523 && integer_types_same_name_p (parm
->name (),
4525 /* signed long -> unsigned int */
4526 return INTEGER_CONVERSION_BADNESS
;
4528 /* signed int/long -> unsigned int/long */
4529 return INTEGER_CONVERSION_BADNESS
;
4532 else if (!arg
->has_no_signedness () && !arg
->is_unsigned ())
4534 if (integer_types_same_name_p (parm
->name (),
4536 return EXACT_MATCH_BADNESS
;
4537 else if (integer_types_same_name_p (arg
->name (),
4539 && integer_types_same_name_p (parm
->name (),
4541 return INTEGER_PROMOTION_BADNESS
;
4543 return INTEGER_CONVERSION_BADNESS
;
4546 return INTEGER_CONVERSION_BADNESS
;
4548 else if (arg
->length () < parm
->length ())
4549 return INTEGER_PROMOTION_BADNESS
;
4551 return INTEGER_CONVERSION_BADNESS
;
4552 case TYPE_CODE_ENUM
:
4553 case TYPE_CODE_FLAGS
:
4554 case TYPE_CODE_CHAR
:
4555 case TYPE_CODE_RANGE
:
4556 case TYPE_CODE_BOOL
:
4557 if (arg
->is_declared_class ())
4558 return INCOMPATIBLE_TYPE_BADNESS
;
4559 return INTEGER_PROMOTION_BADNESS
;
4561 return INT_FLOAT_CONVERSION_BADNESS
;
4563 return NS_POINTER_CONVERSION_BADNESS
;
4565 return INCOMPATIBLE_TYPE_BADNESS
;
4569 /* rank_one_type helper for when PARM's type code is TYPE_CODE_ENUM. */
4572 rank_one_type_parm_enum (struct type
*parm
, struct type
*arg
, struct value
*value
)
4574 switch (arg
->code ())
4577 case TYPE_CODE_CHAR
:
4578 case TYPE_CODE_RANGE
:
4579 case TYPE_CODE_BOOL
:
4580 case TYPE_CODE_ENUM
:
4581 if (parm
->is_declared_class () || arg
->is_declared_class ())
4582 return INCOMPATIBLE_TYPE_BADNESS
;
4583 return INTEGER_CONVERSION_BADNESS
;
4585 return INT_FLOAT_CONVERSION_BADNESS
;
4587 return INCOMPATIBLE_TYPE_BADNESS
;
4591 /* rank_one_type helper for when PARM's type code is TYPE_CODE_CHAR. */
4594 rank_one_type_parm_char (struct type
*parm
, struct type
*arg
, struct value
*value
)
4596 switch (arg
->code ())
4598 case TYPE_CODE_RANGE
:
4599 case TYPE_CODE_BOOL
:
4600 case TYPE_CODE_ENUM
:
4601 if (arg
->is_declared_class ())
4602 return INCOMPATIBLE_TYPE_BADNESS
;
4603 return INTEGER_CONVERSION_BADNESS
;
4605 return INT_FLOAT_CONVERSION_BADNESS
;
4607 if (arg
->length () > parm
->length ())
4608 return INTEGER_CONVERSION_BADNESS
;
4609 else if (arg
->length () < parm
->length ())
4610 return INTEGER_PROMOTION_BADNESS
;
4612 case TYPE_CODE_CHAR
:
4613 /* Deal with signed, unsigned, and plain chars for C++ and
4614 with int cases falling through from previous case. */
4615 if (parm
->has_no_signedness ())
4617 if (arg
->has_no_signedness ())
4618 return EXACT_MATCH_BADNESS
;
4620 return INTEGER_CONVERSION_BADNESS
;
4622 else if (parm
->is_unsigned ())
4624 if (arg
->is_unsigned ())
4625 return EXACT_MATCH_BADNESS
;
4627 return INTEGER_PROMOTION_BADNESS
;
4629 else if (!arg
->has_no_signedness () && !arg
->is_unsigned ())
4630 return EXACT_MATCH_BADNESS
;
4632 return INTEGER_CONVERSION_BADNESS
;
4634 return INCOMPATIBLE_TYPE_BADNESS
;
4638 /* rank_one_type helper for when PARM's type code is TYPE_CODE_RANGE. */
4641 rank_one_type_parm_range (struct type
*parm
, struct type
*arg
, struct value
*value
)
4643 switch (arg
->code ())
4646 case TYPE_CODE_CHAR
:
4647 case TYPE_CODE_RANGE
:
4648 case TYPE_CODE_BOOL
:
4649 case TYPE_CODE_ENUM
:
4650 return INTEGER_CONVERSION_BADNESS
;
4652 return INT_FLOAT_CONVERSION_BADNESS
;
4654 return INCOMPATIBLE_TYPE_BADNESS
;
4658 /* rank_one_type helper for when PARM's type code is TYPE_CODE_BOOL. */
4661 rank_one_type_parm_bool (struct type
*parm
, struct type
*arg
, struct value
*value
)
4663 switch (arg
->code ())
4665 /* n3290 draft, section 4.12.1 (conv.bool):
4667 "A prvalue of arithmetic, unscoped enumeration, pointer, or
4668 pointer to member type can be converted to a prvalue of type
4669 bool. A zero value, null pointer value, or null member pointer
4670 value is converted to false; any other value is converted to
4671 true. A prvalue of type std::nullptr_t can be converted to a
4672 prvalue of type bool; the resulting value is false." */
4674 case TYPE_CODE_CHAR
:
4675 case TYPE_CODE_ENUM
:
4677 case TYPE_CODE_MEMBERPTR
:
4679 return BOOL_CONVERSION_BADNESS
;
4680 case TYPE_CODE_RANGE
:
4681 return INCOMPATIBLE_TYPE_BADNESS
;
4682 case TYPE_CODE_BOOL
:
4683 return EXACT_MATCH_BADNESS
;
4685 return INCOMPATIBLE_TYPE_BADNESS
;
4689 /* rank_one_type helper for when PARM's type code is TYPE_CODE_FLOAT. */
4692 rank_one_type_parm_float (struct type
*parm
, struct type
*arg
, struct value
*value
)
4694 switch (arg
->code ())
4697 if (arg
->length () < parm
->length ())
4698 return FLOAT_PROMOTION_BADNESS
;
4699 else if (arg
->length () == parm
->length ())
4700 return EXACT_MATCH_BADNESS
;
4702 return FLOAT_CONVERSION_BADNESS
;
4704 case TYPE_CODE_BOOL
:
4705 case TYPE_CODE_ENUM
:
4706 case TYPE_CODE_RANGE
:
4707 case TYPE_CODE_CHAR
:
4708 return INT_FLOAT_CONVERSION_BADNESS
;
4710 return INCOMPATIBLE_TYPE_BADNESS
;
4714 /* rank_one_type helper for when PARM's type code is TYPE_CODE_COMPLEX. */
4717 rank_one_type_parm_complex (struct type
*parm
, struct type
*arg
, struct value
*value
)
4719 switch (arg
->code ())
4720 { /* Strictly not needed for C++, but... */
4722 return FLOAT_PROMOTION_BADNESS
;
4723 case TYPE_CODE_COMPLEX
:
4724 return EXACT_MATCH_BADNESS
;
4726 return INCOMPATIBLE_TYPE_BADNESS
;
4730 /* rank_one_type helper for when PARM's type code is TYPE_CODE_STRUCT. */
4733 rank_one_type_parm_struct (struct type
*parm
, struct type
*arg
, struct value
*value
)
4735 struct rank rank
= {0, 0};
4737 switch (arg
->code ())
4739 case TYPE_CODE_STRUCT
:
4740 /* Check for derivation */
4741 rank
.subrank
= distance_to_ancestor (parm
, arg
, 0);
4742 if (rank
.subrank
>= 0)
4743 return sum_ranks (BASE_CONVERSION_BADNESS
, rank
);
4746 return INCOMPATIBLE_TYPE_BADNESS
;
4750 /* rank_one_type helper for when PARM's type code is TYPE_CODE_SET. */
4753 rank_one_type_parm_set (struct type
*parm
, struct type
*arg
, struct value
*value
)
4755 switch (arg
->code ())
4759 return rank_one_type (parm
->field (0).type (),
4760 arg
->field (0).type (), NULL
);
4762 return INCOMPATIBLE_TYPE_BADNESS
;
4766 /* Compare one type (PARM) for compatibility with another (ARG).
4767 * PARM is intended to be the parameter type of a function; and
4768 * ARG is the supplied argument's type. This function tests if
4769 * the latter can be converted to the former.
4770 * VALUE is the argument's value or NULL if none (or called recursively)
4772 * Return 0 if they are identical types;
4773 * Otherwise, return an integer which corresponds to how compatible
4774 * PARM is to ARG. The higher the return value, the worse the match.
4775 * Generally the "bad" conversions are all uniformly assigned
4776 * INVALID_CONVERSION. */
4779 rank_one_type (struct type
*parm
, struct type
*arg
, struct value
*value
)
4781 struct rank rank
= {0,0};
4783 /* Resolve typedefs */
4784 if (parm
->code () == TYPE_CODE_TYPEDEF
)
4785 parm
= check_typedef (parm
);
4786 if (arg
->code () == TYPE_CODE_TYPEDEF
)
4787 arg
= check_typedef (arg
);
4789 if (TYPE_IS_REFERENCE (parm
) && value
!= NULL
)
4791 if (value
->lval () == not_lval
)
4793 /* Rvalues should preferably bind to rvalue references or const
4794 lvalue references. */
4795 if (parm
->code () == TYPE_CODE_RVALUE_REF
)
4796 rank
.subrank
= REFERENCE_CONVERSION_RVALUE
;
4797 else if (TYPE_CONST (parm
->target_type ()))
4798 rank
.subrank
= REFERENCE_CONVERSION_CONST_LVALUE
;
4800 return INCOMPATIBLE_TYPE_BADNESS
;
4801 return sum_ranks (rank
, REFERENCE_CONVERSION_BADNESS
);
4805 /* It's illegal to pass an lvalue as an rvalue. */
4806 if (parm
->code () == TYPE_CODE_RVALUE_REF
)
4807 return INCOMPATIBLE_TYPE_BADNESS
;
4811 if (types_equal (parm
, arg
))
4813 struct type
*t1
= parm
;
4814 struct type
*t2
= arg
;
4816 /* For pointers and references, compare target type. */
4817 if (parm
->is_pointer_or_reference ())
4819 t1
= parm
->target_type ();
4820 t2
= arg
->target_type ();
4823 /* Make sure they are CV equal, too. */
4824 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
4825 rank
.subrank
|= CV_CONVERSION_CONST
;
4826 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
4827 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
4828 if (rank
.subrank
!= 0)
4829 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
4830 return EXACT_MATCH_BADNESS
;
4833 /* See through references, since we can almost make non-references
4836 if (TYPE_IS_REFERENCE (arg
))
4837 return (sum_ranks (rank_one_type (parm
, arg
->target_type (), NULL
),
4838 REFERENCE_SEE_THROUGH_BADNESS
));
4839 if (TYPE_IS_REFERENCE (parm
))
4840 return (sum_ranks (rank_one_type (parm
->target_type (), arg
, NULL
),
4841 REFERENCE_SEE_THROUGH_BADNESS
));
4844 /* Debugging only. */
4845 gdb_printf (gdb_stderr
,
4846 "------ Arg is %s [%d], parm is %s [%d]\n",
4847 arg
->name (), arg
->code (),
4848 parm
->name (), parm
->code ());
4851 /* x -> y means arg of type x being supplied for parameter of type y. */
4853 switch (parm
->code ())
4856 return rank_one_type_parm_ptr (parm
, arg
, value
);
4857 case TYPE_CODE_ARRAY
:
4858 return rank_one_type_parm_array (parm
, arg
, value
);
4859 case TYPE_CODE_FUNC
:
4860 return rank_one_type_parm_func (parm
, arg
, value
);
4862 return rank_one_type_parm_int (parm
, arg
, value
);
4863 case TYPE_CODE_ENUM
:
4864 return rank_one_type_parm_enum (parm
, arg
, value
);
4865 case TYPE_CODE_CHAR
:
4866 return rank_one_type_parm_char (parm
, arg
, value
);
4867 case TYPE_CODE_RANGE
:
4868 return rank_one_type_parm_range (parm
, arg
, value
);
4869 case TYPE_CODE_BOOL
:
4870 return rank_one_type_parm_bool (parm
, arg
, value
);
4872 return rank_one_type_parm_float (parm
, arg
, value
);
4873 case TYPE_CODE_COMPLEX
:
4874 return rank_one_type_parm_complex (parm
, arg
, value
);
4875 case TYPE_CODE_STRUCT
:
4876 return rank_one_type_parm_struct (parm
, arg
, value
);
4878 return rank_one_type_parm_set (parm
, arg
, value
);
4880 return INCOMPATIBLE_TYPE_BADNESS
;
4881 } /* switch (arg->code ()) */
4884 /* End of functions for overload resolution. */
4886 /* Routines to pretty-print types. */
4889 print_bit_vector (B_TYPE
*bits
, int nbits
)
4893 for (bitno
= 0; bitno
< nbits
; bitno
++)
4895 if ((bitno
% 8) == 0)
4899 if (B_TST (bits
, bitno
))
4906 /* Note the first arg should be the "this" pointer, we may not want to
4907 include it since we may get into a infinitely recursive
4911 print_args (struct field
*args
, int nargs
, int spaces
)
4917 for (i
= 0; i
< nargs
; i
++)
4920 ("%*s[%d] name '%s'\n", spaces
, "", i
,
4921 args
[i
].name () != NULL
? args
[i
].name () : "<NULL>");
4922 recursive_dump_type (args
[i
].type (), spaces
+ 2);
4928 dump_fn_fieldlists (struct type
*type
, int spaces
)
4934 gdb_printf ("%*sfn_fieldlists %s\n", spaces
, "",
4935 host_address_to_string (TYPE_FN_FIELDLISTS (type
)));
4936 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
4938 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
4940 ("%*s[%d] name '%s' (%s) length %d\n", spaces
+ 2, "",
4942 TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
4943 host_address_to_string (TYPE_FN_FIELDLIST_NAME (type
, method_idx
)),
4944 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
4945 for (overload_idx
= 0;
4946 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
4950 ("%*s[%d] physname '%s' (%s)\n",
4951 spaces
+ 4, "", overload_idx
,
4952 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
4953 host_address_to_string (TYPE_FN_FIELD_PHYSNAME (f
,
4956 ("%*stype %s\n", spaces
+ 8, "",
4957 host_address_to_string (TYPE_FN_FIELD_TYPE (f
, overload_idx
)));
4959 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
4963 ("%*sargs %s\n", spaces
+ 8, "",
4964 host_address_to_string (TYPE_FN_FIELD_ARGS (f
, overload_idx
)));
4965 print_args (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
4966 TYPE_FN_FIELD_TYPE (f
, overload_idx
)->num_fields (),
4969 ("%*sfcontext %s\n", spaces
+ 8, "",
4970 host_address_to_string (TYPE_FN_FIELD_FCONTEXT (f
,
4973 gdb_printf ("%*sis_const %d\n", spaces
+ 8, "",
4974 TYPE_FN_FIELD_CONST (f
, overload_idx
));
4975 gdb_printf ("%*sis_volatile %d\n", spaces
+ 8, "",
4976 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
4977 gdb_printf ("%*sis_private %d\n", spaces
+ 8, "",
4978 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
4979 gdb_printf ("%*sis_protected %d\n", spaces
+ 8, "",
4980 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
4981 gdb_printf ("%*sis_stub %d\n", spaces
+ 8, "",
4982 TYPE_FN_FIELD_STUB (f
, overload_idx
));
4983 gdb_printf ("%*sdefaulted %d\n", spaces
+ 8, "",
4984 TYPE_FN_FIELD_DEFAULTED (f
, overload_idx
));
4985 gdb_printf ("%*sis_deleted %d\n", spaces
+ 8, "",
4986 TYPE_FN_FIELD_DELETED (f
, overload_idx
));
4987 gdb_printf ("%*svoffset %u\n", spaces
+ 8, "",
4988 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
4994 print_cplus_stuff (struct type
*type
, int spaces
)
4996 gdb_printf ("%*svptr_fieldno %d\n", spaces
, "",
4997 TYPE_VPTR_FIELDNO (type
));
4998 gdb_printf ("%*svptr_basetype %s\n", spaces
, "",
4999 host_address_to_string (TYPE_VPTR_BASETYPE (type
)));
5000 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
5001 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
5003 gdb_printf ("%*sn_baseclasses %d\n", spaces
, "",
5004 TYPE_N_BASECLASSES (type
));
5005 gdb_printf ("%*snfn_fields %d\n", spaces
, "",
5006 TYPE_NFN_FIELDS (type
));
5007 if (TYPE_N_BASECLASSES (type
) > 0)
5010 ("%*svirtual_field_bits (%d bits at *%s)",
5011 spaces
, "", TYPE_N_BASECLASSES (type
),
5012 host_address_to_string (TYPE_FIELD_VIRTUAL_BITS (type
)));
5014 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
5015 TYPE_N_BASECLASSES (type
));
5018 if (type
->num_fields () > 0)
5020 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
5023 ("%*sprivate_field_bits (%d bits at *%s)",
5024 spaces
, "", type
->num_fields (),
5025 host_address_to_string (TYPE_FIELD_PRIVATE_BITS (type
)));
5026 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
5027 type
->num_fields ());
5030 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
5033 ("%*sprotected_field_bits (%d bits at *%s",
5034 spaces
, "", type
->num_fields (),
5035 host_address_to_string (TYPE_FIELD_PROTECTED_BITS (type
)));
5036 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
5037 type
->num_fields ());
5041 if (TYPE_NFN_FIELDS (type
) > 0)
5043 dump_fn_fieldlists (type
, spaces
);
5046 gdb_printf ("%*scalling_convention %d\n", spaces
, "",
5047 TYPE_CPLUS_CALLING_CONVENTION (type
));
5050 /* Print the contents of the TYPE's type_specific union, assuming that
5051 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
5054 print_gnat_stuff (struct type
*type
, int spaces
)
5056 struct type
*descriptive_type
= TYPE_DESCRIPTIVE_TYPE (type
);
5058 if (descriptive_type
== NULL
)
5059 gdb_printf ("%*sno descriptive type\n", spaces
+ 2, "");
5062 gdb_printf ("%*sdescriptive type\n", spaces
+ 2, "");
5063 recursive_dump_type (descriptive_type
, spaces
+ 4);
5067 /* Print the contents of the TYPE's type_specific union, assuming that
5068 its type-specific kind is TYPE_SPECIFIC_FIXED_POINT. */
5071 print_fixed_point_type_info (struct type
*type
, int spaces
)
5073 gdb_printf ("%*sscaling factor: %s\n", spaces
+ 2, "",
5074 type
->fixed_point_scaling_factor ().str ().c_str ());
5077 static struct obstack dont_print_type_obstack
;
5079 /* Print the dynamic_prop PROP. */
5082 dump_dynamic_prop (dynamic_prop
const& prop
)
5084 switch (prop
.kind ())
5087 gdb_printf ("%s", plongest (prop
.const_val ()));
5089 case PROP_UNDEFINED
:
5090 gdb_printf ("(undefined)");
5094 gdb_printf ("(dynamic)");
5097 gdb_assert_not_reached ("unhandled prop kind");
5103 recursive_dump_type (struct type
*type
, int spaces
)
5108 obstack_begin (&dont_print_type_obstack
, 0);
5110 if (type
->num_fields () > 0
5111 || (HAVE_CPLUS_STRUCT (type
) && TYPE_NFN_FIELDS (type
) > 0))
5113 struct type
**first_dont_print
5114 = (struct type
**) obstack_base (&dont_print_type_obstack
);
5116 int i
= (struct type
**)
5117 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
5121 if (type
== first_dont_print
[i
])
5123 gdb_printf ("%*stype node %s", spaces
, "",
5124 host_address_to_string (type
));
5125 gdb_printf (_(" <same as already seen type>\n"));
5130 obstack_ptr_grow (&dont_print_type_obstack
, type
);
5133 gdb_printf ("%*stype node %s\n", spaces
, "",
5134 host_address_to_string (type
));
5135 gdb_printf ("%*sname '%s' (%s)\n", spaces
, "",
5136 type
->name () ? type
->name () : "<NULL>",
5137 host_address_to_string (type
->name ()));
5138 gdb_printf ("%*scode 0x%x ", spaces
, "", type
->code ());
5139 switch (type
->code ())
5141 case TYPE_CODE_UNDEF
:
5142 gdb_printf ("(TYPE_CODE_UNDEF)");
5145 gdb_printf ("(TYPE_CODE_PTR)");
5147 case TYPE_CODE_ARRAY
:
5148 gdb_printf ("(TYPE_CODE_ARRAY)");
5150 case TYPE_CODE_STRUCT
:
5151 gdb_printf ("(TYPE_CODE_STRUCT)");
5153 case TYPE_CODE_UNION
:
5154 gdb_printf ("(TYPE_CODE_UNION)");
5156 case TYPE_CODE_ENUM
:
5157 gdb_printf ("(TYPE_CODE_ENUM)");
5159 case TYPE_CODE_FLAGS
:
5160 gdb_printf ("(TYPE_CODE_FLAGS)");
5162 case TYPE_CODE_FUNC
:
5163 gdb_printf ("(TYPE_CODE_FUNC)");
5166 gdb_printf ("(TYPE_CODE_INT)");
5169 gdb_printf ("(TYPE_CODE_FLT)");
5171 case TYPE_CODE_VOID
:
5172 gdb_printf ("(TYPE_CODE_VOID)");
5175 gdb_printf ("(TYPE_CODE_SET)");
5177 case TYPE_CODE_RANGE
:
5178 gdb_printf ("(TYPE_CODE_RANGE)");
5180 case TYPE_CODE_STRING
:
5181 gdb_printf ("(TYPE_CODE_STRING)");
5183 case TYPE_CODE_ERROR
:
5184 gdb_printf ("(TYPE_CODE_ERROR)");
5186 case TYPE_CODE_MEMBERPTR
:
5187 gdb_printf ("(TYPE_CODE_MEMBERPTR)");
5189 case TYPE_CODE_METHODPTR
:
5190 gdb_printf ("(TYPE_CODE_METHODPTR)");
5192 case TYPE_CODE_METHOD
:
5193 gdb_printf ("(TYPE_CODE_METHOD)");
5196 gdb_printf ("(TYPE_CODE_REF)");
5198 case TYPE_CODE_CHAR
:
5199 gdb_printf ("(TYPE_CODE_CHAR)");
5201 case TYPE_CODE_BOOL
:
5202 gdb_printf ("(TYPE_CODE_BOOL)");
5204 case TYPE_CODE_COMPLEX
:
5205 gdb_printf ("(TYPE_CODE_COMPLEX)");
5207 case TYPE_CODE_TYPEDEF
:
5208 gdb_printf ("(TYPE_CODE_TYPEDEF)");
5210 case TYPE_CODE_NAMESPACE
:
5211 gdb_printf ("(TYPE_CODE_NAMESPACE)");
5213 case TYPE_CODE_FIXED_POINT
:
5214 gdb_printf ("(TYPE_CODE_FIXED_POINT)");
5217 gdb_printf ("(UNKNOWN TYPE CODE)");
5221 gdb_printf ("%*slength %s\n", spaces
, "",
5222 pulongest (type
->length ()));
5223 if (type
->is_objfile_owned ())
5224 gdb_printf ("%*sobjfile %s\n", spaces
, "",
5225 host_address_to_string (type
->objfile_owner ()));
5227 gdb_printf ("%*sgdbarch %s\n", spaces
, "",
5228 host_address_to_string (type
->arch_owner ()));
5229 gdb_printf ("%*starget_type %s\n", spaces
, "",
5230 host_address_to_string (type
->target_type ()));
5231 if (type
->target_type () != NULL
)
5233 recursive_dump_type (type
->target_type (), spaces
+ 2);
5235 gdb_printf ("%*spointer_type %s\n", spaces
, "",
5236 host_address_to_string (TYPE_POINTER_TYPE (type
)));
5237 gdb_printf ("%*sreference_type %s\n", spaces
, "",
5238 host_address_to_string (TYPE_REFERENCE_TYPE (type
)));
5239 gdb_printf ("%*stype_chain %s\n", spaces
, "",
5240 host_address_to_string (TYPE_CHAIN (type
)));
5241 gdb_printf ("%*sinstance_flags 0x%x", spaces
, "",
5242 (unsigned) type
->instance_flags ());
5243 if (TYPE_CONST (type
))
5245 gdb_puts (" TYPE_CONST");
5247 if (TYPE_VOLATILE (type
))
5249 gdb_puts (" TYPE_VOLATILE");
5251 if (TYPE_CODE_SPACE (type
))
5253 gdb_puts (" TYPE_CODE_SPACE");
5255 if (TYPE_DATA_SPACE (type
))
5257 gdb_puts (" TYPE_DATA_SPACE");
5259 if (TYPE_ADDRESS_CLASS_1 (type
))
5261 gdb_puts (" TYPE_ADDRESS_CLASS_1");
5263 if (TYPE_ADDRESS_CLASS_2 (type
))
5265 gdb_puts (" TYPE_ADDRESS_CLASS_2");
5267 if (TYPE_RESTRICT (type
))
5269 gdb_puts (" TYPE_RESTRICT");
5271 if (TYPE_ATOMIC (type
))
5273 gdb_puts (" TYPE_ATOMIC");
5277 gdb_printf ("%*sflags", spaces
, "");
5278 if (type
->is_unsigned ())
5280 gdb_puts (" TYPE_UNSIGNED");
5282 if (type
->has_no_signedness ())
5284 gdb_puts (" TYPE_NOSIGN");
5286 if (type
->endianity_is_not_default ())
5288 gdb_puts (" TYPE_ENDIANITY_NOT_DEFAULT");
5290 if (type
->is_stub ())
5292 gdb_puts (" TYPE_STUB");
5294 if (type
->target_is_stub ())
5296 gdb_puts (" TYPE_TARGET_STUB");
5298 if (type
->is_prototyped ())
5300 gdb_puts (" TYPE_PROTOTYPED");
5302 if (type
->has_varargs ())
5304 gdb_puts (" TYPE_VARARGS");
5306 /* This is used for things like AltiVec registers on ppc. Gcc emits
5307 an attribute for the array type, which tells whether or not we
5308 have a vector, instead of a regular array. */
5309 if (type
->is_vector ())
5311 gdb_puts (" TYPE_VECTOR");
5313 if (type
->is_fixed_instance ())
5315 gdb_puts (" TYPE_FIXED_INSTANCE");
5317 if (type
->stub_is_supported ())
5319 gdb_puts (" TYPE_STUB_SUPPORTED");
5321 if (TYPE_NOTTEXT (type
))
5323 gdb_puts (" TYPE_NOTTEXT");
5326 gdb_printf ("%*snfields %d ", spaces
, "", type
->num_fields ());
5327 if (TYPE_ASSOCIATED_PROP (type
) != nullptr
5328 || TYPE_ALLOCATED_PROP (type
) != nullptr)
5330 gdb_printf ("%*s", spaces
, "");
5331 if (TYPE_ASSOCIATED_PROP (type
) != nullptr)
5333 gdb_printf ("associated ");
5334 dump_dynamic_prop (*TYPE_ASSOCIATED_PROP (type
));
5336 if (TYPE_ALLOCATED_PROP (type
) != nullptr)
5338 if (TYPE_ASSOCIATED_PROP (type
) != nullptr)
5340 gdb_printf ("allocated ");
5341 dump_dynamic_prop (*TYPE_ALLOCATED_PROP (type
));
5345 gdb_printf ("%s\n", host_address_to_string (type
->fields ()));
5346 for (idx
= 0; idx
< type
->num_fields (); idx
++)
5348 if (type
->code () == TYPE_CODE_ENUM
)
5349 gdb_printf ("%*s[%d] enumval %s type ", spaces
+ 2, "",
5350 idx
, plongest (type
->field (idx
).loc_enumval ()));
5352 gdb_printf ("%*s[%d] bitpos %s bitsize %d type ", spaces
+ 2, "",
5353 idx
, plongest (type
->field (idx
).loc_bitpos ()),
5354 type
->field (idx
).bitsize ());
5355 gdb_printf ("%s name '%s' (%s)\n",
5356 host_address_to_string (type
->field (idx
).type ()),
5357 type
->field (idx
).name () != NULL
5358 ? type
->field (idx
).name ()
5360 host_address_to_string (type
->field (idx
).name ()));
5361 if (type
->field (idx
).type () != NULL
)
5363 recursive_dump_type (type
->field (idx
).type (), spaces
+ 4);
5366 if (type
->code () == TYPE_CODE_RANGE
)
5368 gdb_printf ("%*slow ", spaces
, "");
5369 dump_dynamic_prop (type
->bounds ()->low
);
5370 gdb_printf (" high ");
5371 dump_dynamic_prop (type
->bounds ()->high
);
5375 switch (TYPE_SPECIFIC_FIELD (type
))
5377 case TYPE_SPECIFIC_CPLUS_STUFF
:
5378 gdb_printf ("%*scplus_stuff %s\n", spaces
, "",
5379 host_address_to_string (TYPE_CPLUS_SPECIFIC (type
)));
5380 print_cplus_stuff (type
, spaces
);
5383 case TYPE_SPECIFIC_GNAT_STUFF
:
5384 gdb_printf ("%*sgnat_stuff %s\n", spaces
, "",
5385 host_address_to_string (TYPE_GNAT_SPECIFIC (type
)));
5386 print_gnat_stuff (type
, spaces
);
5389 case TYPE_SPECIFIC_FLOATFORMAT
:
5390 gdb_printf ("%*sfloatformat ", spaces
, "");
5391 if (TYPE_FLOATFORMAT (type
) == NULL
5392 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
5393 gdb_puts ("(null)");
5395 gdb_puts (TYPE_FLOATFORMAT (type
)->name
);
5399 case TYPE_SPECIFIC_FUNC
:
5400 gdb_printf ("%*scalling_convention %d\n", spaces
, "",
5401 TYPE_CALLING_CONVENTION (type
));
5402 /* tail_call_list is not printed. */
5405 case TYPE_SPECIFIC_SELF_TYPE
:
5406 gdb_printf ("%*sself_type %s\n", spaces
, "",
5407 host_address_to_string (TYPE_SELF_TYPE (type
)));
5410 case TYPE_SPECIFIC_FIXED_POINT
:
5411 gdb_printf ("%*sfixed_point_info ", spaces
, "");
5412 print_fixed_point_type_info (type
, spaces
);
5416 case TYPE_SPECIFIC_INT
:
5417 if (type
->bit_size_differs_p ())
5419 unsigned bit_size
= type
->bit_size ();
5420 unsigned bit_off
= type
->bit_offset ();
5421 gdb_printf ("%*s bit size = %u, bit offset = %u\n", spaces
, "",
5428 obstack_free (&dont_print_type_obstack
, NULL
);
5431 /* Trivial helpers for the libiberty hash table, for mapping one
5436 type_pair (struct type
*old_
, struct type
*newobj_
)
5437 : old (old_
), newobj (newobj_
)
5440 struct type
* const old
, * const newobj
;
5444 type_pair_hash (const void *item
)
5446 const struct type_pair
*pair
= (const struct type_pair
*) item
;
5448 return htab_hash_pointer (pair
->old
);
5452 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
5454 const struct type_pair
*lhs
= (const struct type_pair
*) item_lhs
;
5455 const struct type_pair
*rhs
= (const struct type_pair
*) item_rhs
;
5457 return lhs
->old
== rhs
->old
;
5460 /* Allocate the hash table used by copy_type_recursive to walk
5461 types without duplicates. */
5464 create_copied_types_hash ()
5466 return htab_up (htab_create_alloc (1, type_pair_hash
, type_pair_eq
,
5467 htab_delete_entry
<type_pair
>,
5471 /* Recursively copy (deep copy) a dynamic attribute list of a type. */
5473 static struct dynamic_prop_list
*
5474 copy_dynamic_prop_list (struct obstack
*storage
,
5475 struct dynamic_prop_list
*list
)
5477 struct dynamic_prop_list
*copy
= list
;
5478 struct dynamic_prop_list
**node_ptr
= ©
;
5480 while (*node_ptr
!= NULL
)
5482 struct dynamic_prop_list
*node_copy
;
5484 node_copy
= ((struct dynamic_prop_list
*)
5485 obstack_copy (storage
, *node_ptr
,
5486 sizeof (struct dynamic_prop_list
)));
5487 node_copy
->prop
= (*node_ptr
)->prop
;
5488 *node_ptr
= node_copy
;
5490 node_ptr
= &node_copy
->next
;
5496 /* Recursively copy (deep copy) TYPE, if it is associated with
5497 OBJFILE. Return a new type owned by the gdbarch associated with the type, a
5498 saved type if we have already visited TYPE (using COPIED_TYPES), or TYPE if
5499 it is not associated with OBJFILE. */
5502 copy_type_recursive (struct type
*type
, htab_t copied_types
)
5505 struct type
*new_type
;
5507 if (!type
->is_objfile_owned ())
5510 struct type_pair
pair (type
, nullptr);
5512 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
5514 return ((struct type_pair
*) *slot
)->newobj
;
5516 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 struct type_pair
*stored
= new type_pair (type
, new_type
);
5524 /* Copy the common fields of types. For the main type, we simply
5525 copy the entire thing and then update specific fields as needed. */
5526 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
5528 new_type
->set_owner (type
->arch ());
5531 new_type
->set_name (xstrdup (type
->name ()));
5533 new_type
->set_instance_flags (type
->instance_flags ());
5534 new_type
->set_length (type
->length ());
5536 /* Copy the fields. */
5537 if (type
->num_fields ())
5541 nfields
= type
->num_fields ();
5542 new_type
->alloc_fields (type
->num_fields ());
5544 for (i
= 0; i
< nfields
; i
++)
5546 new_type
->field (i
).set_is_artificial
5547 (type
->field (i
).is_artificial ());
5548 new_type
->field (i
).set_bitsize (type
->field (i
).bitsize ());
5549 if (type
->field (i
).type ())
5550 new_type
->field (i
).set_type
5551 (copy_type_recursive (type
->field (i
).type (), copied_types
));
5552 if (type
->field (i
).name ())
5553 new_type
->field (i
).set_name (xstrdup (type
->field (i
).name ()));
5555 switch (type
->field (i
).loc_kind ())
5557 case FIELD_LOC_KIND_BITPOS
:
5558 new_type
->field (i
).set_loc_bitpos (type
->field (i
).loc_bitpos ());
5560 case FIELD_LOC_KIND_ENUMVAL
:
5561 new_type
->field (i
).set_loc_enumval (type
->field (i
).loc_enumval ());
5563 case FIELD_LOC_KIND_PHYSADDR
:
5564 new_type
->field (i
).set_loc_physaddr
5565 (type
->field (i
).loc_physaddr ());
5567 case FIELD_LOC_KIND_PHYSNAME
:
5568 new_type
->field (i
).set_loc_physname
5569 (xstrdup (type
->field (i
).loc_physname ()));
5571 case FIELD_LOC_KIND_DWARF_BLOCK
:
5572 new_type
->field (i
).set_loc_dwarf_block
5573 (type
->field (i
).loc_dwarf_block ());
5576 internal_error (_("Unexpected type field location kind: %d"),
5577 type
->field (i
).loc_kind ());
5582 /* For range types, copy the bounds information. */
5583 if (type
->code () == TYPE_CODE_RANGE
)
5585 range_bounds
*bounds
5586 = ((struct range_bounds
*) TYPE_ALLOC
5587 (new_type
, sizeof (struct range_bounds
)));
5589 *bounds
= *type
->bounds ();
5590 new_type
->set_bounds (bounds
);
5593 if (type
->main_type
->dyn_prop_list
!= NULL
)
5594 new_type
->main_type
->dyn_prop_list
5595 = copy_dynamic_prop_list (gdbarch_obstack (new_type
->arch_owner ()),
5596 type
->main_type
->dyn_prop_list
);
5599 /* Copy pointers to other types. */
5600 if (type
->target_type ())
5601 new_type
->set_target_type
5602 (copy_type_recursive (type
->target_type (), copied_types
));
5604 /* Maybe copy the type_specific bits.
5606 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
5607 base classes and methods. There's no fundamental reason why we
5608 can't, but at the moment it is not needed. */
5610 switch (TYPE_SPECIFIC_FIELD (type
))
5612 case TYPE_SPECIFIC_NONE
:
5614 case TYPE_SPECIFIC_FUNC
:
5615 INIT_FUNC_SPECIFIC (new_type
);
5616 TYPE_CALLING_CONVENTION (new_type
) = TYPE_CALLING_CONVENTION (type
);
5617 TYPE_NO_RETURN (new_type
) = TYPE_NO_RETURN (type
);
5618 TYPE_TAIL_CALL_LIST (new_type
) = NULL
;
5620 case TYPE_SPECIFIC_FLOATFORMAT
:
5621 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
5623 case TYPE_SPECIFIC_CPLUS_STUFF
:
5624 INIT_CPLUS_SPECIFIC (new_type
);
5626 case TYPE_SPECIFIC_GNAT_STUFF
:
5627 INIT_GNAT_SPECIFIC (new_type
);
5629 case TYPE_SPECIFIC_SELF_TYPE
:
5630 set_type_self_type (new_type
,
5631 copy_type_recursive (TYPE_SELF_TYPE (type
),
5634 case TYPE_SPECIFIC_FIXED_POINT
:
5635 INIT_FIXED_POINT_SPECIFIC (new_type
);
5636 new_type
->fixed_point_info ().scaling_factor
5637 = type
->fixed_point_info ().scaling_factor
;
5639 case TYPE_SPECIFIC_INT
:
5640 TYPE_SPECIFIC_FIELD (new_type
) = TYPE_SPECIFIC_INT
;
5641 TYPE_MAIN_TYPE (new_type
)->type_specific
.int_stuff
5642 = TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
;
5646 gdb_assert_not_reached ("bad type_specific_kind");
5652 /* Make a copy of the given TYPE, except that the pointer & reference
5653 types are not preserved. */
5656 copy_type (const struct type
*type
)
5658 struct type
*new_type
= type_allocator (type
).new_type ();
5659 new_type
->set_instance_flags (type
->instance_flags ());
5660 new_type
->set_length (type
->length ());
5661 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
5662 sizeof (struct main_type
));
5663 if (type
->main_type
->dyn_prop_list
!= NULL
)
5665 struct obstack
*storage
= (type
->is_objfile_owned ()
5666 ? &type
->objfile_owner ()->objfile_obstack
5667 : gdbarch_obstack (type
->arch_owner ()));
5668 new_type
->main_type
->dyn_prop_list
5669 = copy_dynamic_prop_list (storage
, type
->main_type
->dyn_prop_list
);
5675 /* Helper functions to initialize architecture-specific types. */
5677 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
5678 NAME is the type name. BIT is the size of the flag word in bits. */
5681 arch_flags_type (struct gdbarch
*gdbarch
, const char *name
, int bit
)
5685 type
= type_allocator (gdbarch
).new_type (TYPE_CODE_FLAGS
, bit
, name
);
5686 type
->set_is_unsigned (true);
5687 /* Pre-allocate enough space assuming every field is one bit. */
5688 type
->alloc_fields (bit
);
5689 type
->set_num_fields (0);
5694 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5695 position BITPOS is called NAME. Pass NAME as "" for fields that
5696 should not be printed. */
5699 append_flags_type_field (struct type
*type
, int start_bitpos
, int nr_bits
,
5700 struct type
*field_type
, const char *name
)
5702 int type_bitsize
= type
->length () * TARGET_CHAR_BIT
;
5703 int field_nr
= type
->num_fields ();
5705 gdb_assert (type
->code () == TYPE_CODE_FLAGS
);
5706 gdb_assert (type
->num_fields () + 1 <= type_bitsize
);
5707 gdb_assert (start_bitpos
>= 0 && start_bitpos
< type_bitsize
);
5708 gdb_assert (nr_bits
>= 1 && (start_bitpos
+ nr_bits
) <= type_bitsize
);
5709 gdb_assert (name
!= NULL
);
5711 type
->set_num_fields (type
->num_fields () + 1);
5712 type
->field (field_nr
).set_name (xstrdup (name
));
5713 type
->field (field_nr
).set_type (field_type
);
5714 type
->field (field_nr
).set_loc_bitpos (start_bitpos
);
5715 type
->field (field_nr
).set_bitsize (nr_bits
);
5718 /* Special version of append_flags_type_field to add a flag field.
5719 Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5720 position BITPOS is called NAME. */
5723 append_flags_type_flag (struct type
*type
, int bitpos
, const char *name
)
5725 append_flags_type_field (type
, bitpos
, 1,
5726 builtin_type (type
->arch ())->builtin_bool
,
5730 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
5731 specified by CODE) associated with GDBARCH. NAME is the type name. */
5734 arch_composite_type (struct gdbarch
*gdbarch
, const char *name
,
5735 enum type_code code
)
5739 gdb_assert (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
);
5740 t
= type_allocator (gdbarch
).new_type (code
, 0, NULL
);
5742 INIT_CPLUS_SPECIFIC (t
);
5746 /* Add new field with name NAME and type FIELD to composite type T.
5747 Do not set the field's position or adjust the type's length;
5748 the caller should do so. Return the new field. */
5751 append_composite_type_field_raw (struct type
*t
, const char *name
,
5756 t
->set_num_fields (t
->num_fields () + 1);
5757 t
->set_fields (XRESIZEVEC (struct field
, t
->fields (),
5759 f
= &t
->field (t
->num_fields () - 1);
5760 memset (f
, 0, sizeof f
[0]);
5761 f
[0].set_type (field
);
5762 f
[0].set_name (name
);
5766 /* Add new field with name NAME and type FIELD to composite type T.
5767 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
5770 append_composite_type_field_aligned (struct type
*t
, const char *name
,
5771 struct type
*field
, int alignment
)
5773 struct field
*f
= append_composite_type_field_raw (t
, name
, field
);
5775 if (t
->code () == TYPE_CODE_UNION
)
5777 if (t
->length () < field
->length ())
5778 t
->set_length (field
->length ());
5780 else if (t
->code () == TYPE_CODE_STRUCT
)
5782 t
->set_length (t
->length () + field
->length ());
5783 if (t
->num_fields () > 1)
5786 (f
[-1].loc_bitpos ()
5787 + (f
[-1].type ()->length () * TARGET_CHAR_BIT
));
5793 alignment
*= TARGET_CHAR_BIT
;
5794 left
= f
[0].loc_bitpos () % alignment
;
5798 f
->set_loc_bitpos (f
[0].loc_bitpos () + (alignment
- left
));
5800 (t
->length () + (alignment
- left
) / TARGET_CHAR_BIT
);
5807 /* Add new field with name NAME and type FIELD to composite type T. */
5810 append_composite_type_field (struct type
*t
, const char *name
,
5813 append_composite_type_field_aligned (t
, name
, field
, 0);
5818 /* We manage the lifetimes of fixed_point_type_info objects by
5819 attaching them to the objfile. Currently, these objects are
5820 modified during construction, and GMP does not provide a way to
5821 hash the contents of an mpq_t; so it's a bit of a pain to hash-cons
5822 them. If we did do this, they could be moved to the per-BFD and
5823 shared across objfiles. */
5824 typedef std::vector
<std::unique_ptr
<fixed_point_type_info
>>
5825 fixed_point_type_storage
;
5827 /* Key used for managing the storage of fixed-point type info. */
5828 static const struct registry
<objfile
>::key
<fixed_point_type_storage
>
5829 fixed_point_objfile_key
;
5831 /* See gdbtypes.h. */
5834 allocate_fixed_point_type_info (struct type
*type
)
5836 auto up
= gdb::make_unique
<fixed_point_type_info
> ();
5837 fixed_point_type_info
*info
;
5839 if (type
->is_objfile_owned ())
5841 fixed_point_type_storage
*storage
5842 = fixed_point_objfile_key
.get (type
->objfile_owner ());
5843 if (storage
== nullptr)
5844 storage
= fixed_point_objfile_key
.emplace (type
->objfile_owner ());
5846 storage
->push_back (std::move (up
));
5850 /* We just leak the memory, because that's what we do generally
5851 for non-objfile-attached types. */
5852 info
= up
.release ();
5855 type
->set_fixed_point_info (info
);
5858 /* See gdbtypes.h. */
5861 is_fixed_point_type (struct type
*type
)
5863 while (check_typedef (type
)->code () == TYPE_CODE_RANGE
)
5864 type
= check_typedef (type
)->target_type ();
5865 type
= check_typedef (type
);
5867 return type
->code () == TYPE_CODE_FIXED_POINT
;
5870 /* See gdbtypes.h. */
5873 type::fixed_point_type_base_type ()
5875 struct type
*type
= this;
5877 while (check_typedef (type
)->code () == TYPE_CODE_RANGE
)
5878 type
= check_typedef (type
)->target_type ();
5879 type
= check_typedef (type
);
5881 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
);
5885 /* See gdbtypes.h. */
5888 type::fixed_point_scaling_factor ()
5890 struct type
*type
= this->fixed_point_type_base_type ();
5892 return type
->fixed_point_info ().scaling_factor
;
5895 /* See gdbtypes.h. */
5898 type::alloc_fields (unsigned int nfields
, bool init
)
5900 this->set_num_fields (nfields
);
5904 this->main_type
->flds_bnds
.fields
= nullptr;
5908 size_t size
= nfields
* sizeof (*this->fields ());
5909 struct field
*fields
5910 = (struct field
*) (init
5911 ? TYPE_ZALLOC (this, size
)
5912 : TYPE_ALLOC (this, size
));
5914 this->main_type
->flds_bnds
.fields
= fields
;
5917 /* See gdbtypes.h. */
5920 type::copy_fields (struct type
*src
)
5922 unsigned int nfields
= src
->num_fields ();
5923 alloc_fields (nfields
, false);
5927 size_t size
= nfields
* sizeof (*this->fields ());
5928 memcpy (this->fields (), src
->fields (), size
);
5931 /* See gdbtypes.h. */
5934 type::copy_fields (std::vector
<struct field
> &src
)
5936 unsigned int nfields
= src
.size ();
5937 alloc_fields (nfields
, false);
5941 size_t size
= nfields
* sizeof (*this->fields ());
5942 memcpy (this->fields (), src
.data (), size
);
5945 /* See gdbtypes.h. */
5948 type::is_string_like ()
5950 const language_defn
*defn
= language_def (this->language ());
5951 return defn
->is_string_type_p (this);
5954 /* See gdbtypes.h. */
5957 type::is_array_like ()
5959 if (code () == TYPE_CODE_ARRAY
)
5961 const language_defn
*defn
= language_def (this->language ());
5962 return defn
->is_array_like (this);
5967 static const registry
<gdbarch
>::key
<struct builtin_type
> gdbtypes_data
;
5969 static struct builtin_type
*
5970 create_gdbtypes_data (struct gdbarch
*gdbarch
)
5972 struct builtin_type
*builtin_type
= new struct builtin_type
;
5974 type_allocator
alloc (gdbarch
);
5977 builtin_type
->builtin_void
5978 = alloc
.new_type (TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
5979 builtin_type
->builtin_char
5980 = init_integer_type (alloc
, TARGET_CHAR_BIT
,
5981 !gdbarch_char_signed (gdbarch
), "char");
5982 builtin_type
->builtin_char
->set_has_no_signedness (true);
5983 builtin_type
->builtin_signed_char
5984 = init_integer_type (alloc
, TARGET_CHAR_BIT
,
5986 builtin_type
->builtin_unsigned_char
5987 = init_integer_type (alloc
, TARGET_CHAR_BIT
,
5988 1, "unsigned char");
5989 builtin_type
->builtin_short
5990 = init_integer_type (alloc
, gdbarch_short_bit (gdbarch
),
5992 builtin_type
->builtin_unsigned_short
5993 = init_integer_type (alloc
, gdbarch_short_bit (gdbarch
),
5994 1, "unsigned short");
5995 builtin_type
->builtin_int
5996 = init_integer_type (alloc
, gdbarch_int_bit (gdbarch
),
5998 builtin_type
->builtin_unsigned_int
5999 = init_integer_type (alloc
, gdbarch_int_bit (gdbarch
),
6001 builtin_type
->builtin_long
6002 = init_integer_type (alloc
, gdbarch_long_bit (gdbarch
),
6004 builtin_type
->builtin_unsigned_long
6005 = init_integer_type (alloc
, gdbarch_long_bit (gdbarch
),
6006 1, "unsigned long");
6007 builtin_type
->builtin_long_long
6008 = init_integer_type (alloc
, gdbarch_long_long_bit (gdbarch
),
6010 builtin_type
->builtin_unsigned_long_long
6011 = init_integer_type (alloc
, gdbarch_long_long_bit (gdbarch
),
6012 1, "unsigned long long");
6013 builtin_type
->builtin_half
6014 = init_float_type (alloc
, gdbarch_half_bit (gdbarch
),
6015 "half", gdbarch_half_format (gdbarch
));
6016 builtin_type
->builtin_float
6017 = init_float_type (alloc
, gdbarch_float_bit (gdbarch
),
6018 "float", gdbarch_float_format (gdbarch
));
6019 builtin_type
->builtin_bfloat16
6020 = init_float_type (alloc
, gdbarch_bfloat16_bit (gdbarch
),
6021 "bfloat16", gdbarch_bfloat16_format (gdbarch
));
6022 builtin_type
->builtin_double
6023 = init_float_type (alloc
, gdbarch_double_bit (gdbarch
),
6024 "double", gdbarch_double_format (gdbarch
));
6025 builtin_type
->builtin_long_double
6026 = init_float_type (alloc
, gdbarch_long_double_bit (gdbarch
),
6027 "long double", gdbarch_long_double_format (gdbarch
));
6028 builtin_type
->builtin_complex
6029 = init_complex_type ("complex", builtin_type
->builtin_float
);
6030 builtin_type
->builtin_double_complex
6031 = init_complex_type ("double complex", builtin_type
->builtin_double
);
6032 builtin_type
->builtin_string
6033 = alloc
.new_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
, "string");
6034 builtin_type
->builtin_bool
6035 = init_boolean_type (alloc
, TARGET_CHAR_BIT
, 1, "bool");
6037 /* The following three are about decimal floating point types, which
6038 are 32-bits, 64-bits and 128-bits respectively. */
6039 builtin_type
->builtin_decfloat
6040 = init_decfloat_type (alloc
, 32, "_Decimal32");
6041 builtin_type
->builtin_decdouble
6042 = init_decfloat_type (alloc
, 64, "_Decimal64");
6043 builtin_type
->builtin_declong
6044 = init_decfloat_type (alloc
, 128, "_Decimal128");
6046 /* "True" character types. */
6047 builtin_type
->builtin_true_char
6048 = init_character_type (alloc
, TARGET_CHAR_BIT
, 0, "true character");
6049 builtin_type
->builtin_true_unsigned_char
6050 = init_character_type (alloc
, TARGET_CHAR_BIT
, 1, "true character");
6052 /* Fixed-size integer types. */
6053 builtin_type
->builtin_int0
6054 = init_integer_type (alloc
, 0, 0, "int0_t");
6055 builtin_type
->builtin_int8
6056 = init_integer_type (alloc
, 8, 0, "int8_t");
6057 builtin_type
->builtin_uint8
6058 = init_integer_type (alloc
, 8, 1, "uint8_t");
6059 builtin_type
->builtin_int16
6060 = init_integer_type (alloc
, 16, 0, "int16_t");
6061 builtin_type
->builtin_uint16
6062 = init_integer_type (alloc
, 16, 1, "uint16_t");
6063 builtin_type
->builtin_int24
6064 = init_integer_type (alloc
, 24, 0, "int24_t");
6065 builtin_type
->builtin_uint24
6066 = init_integer_type (alloc
, 24, 1, "uint24_t");
6067 builtin_type
->builtin_int32
6068 = init_integer_type (alloc
, 32, 0, "int32_t");
6069 builtin_type
->builtin_uint32
6070 = init_integer_type (alloc
, 32, 1, "uint32_t");
6071 builtin_type
->builtin_int64
6072 = init_integer_type (alloc
, 64, 0, "int64_t");
6073 builtin_type
->builtin_uint64
6074 = init_integer_type (alloc
, 64, 1, "uint64_t");
6075 builtin_type
->builtin_int128
6076 = init_integer_type (alloc
, 128, 0, "int128_t");
6077 builtin_type
->builtin_uint128
6078 = init_integer_type (alloc
, 128, 1, "uint128_t");
6080 builtin_type
->builtin_int8
->set_instance_flags
6081 (builtin_type
->builtin_int8
->instance_flags ()
6082 | TYPE_INSTANCE_FLAG_NOTTEXT
);
6084 builtin_type
->builtin_uint8
->set_instance_flags
6085 (builtin_type
->builtin_uint8
->instance_flags ()
6086 | TYPE_INSTANCE_FLAG_NOTTEXT
);
6088 /* Wide character types. */
6089 builtin_type
->builtin_char16
6090 = init_integer_type (alloc
, 16, 1, "char16_t");
6091 builtin_type
->builtin_char32
6092 = init_integer_type (alloc
, 32, 1, "char32_t");
6093 builtin_type
->builtin_wchar
6094 = init_integer_type (alloc
, gdbarch_wchar_bit (gdbarch
),
6095 !gdbarch_wchar_signed (gdbarch
), "wchar_t");
6097 /* Default data/code pointer types. */
6098 builtin_type
->builtin_data_ptr
6099 = lookup_pointer_type (builtin_type
->builtin_void
);
6100 builtin_type
->builtin_func_ptr
6101 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
6102 builtin_type
->builtin_func_func
6103 = lookup_function_type (builtin_type
->builtin_func_ptr
);
6105 /* This type represents a GDB internal function. */
6106 builtin_type
->internal_fn
6107 = alloc
.new_type (TYPE_CODE_INTERNAL_FUNCTION
, 0,
6108 "<internal function>");
6110 /* This type represents an xmethod. */
6111 builtin_type
->xmethod
6112 = alloc
.new_type (TYPE_CODE_XMETHOD
, 0, "<xmethod>");
6114 /* This type represents a type that was unrecognized in symbol read-in. */
6115 builtin_type
->builtin_error
6116 = alloc
.new_type (TYPE_CODE_ERROR
, 0, "<unknown type>");
6118 /* The following set of types is used for symbols with no
6119 debug information. */
6120 builtin_type
->nodebug_text_symbol
6121 = alloc
.new_type (TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
6122 "<text variable, no debug info>");
6124 builtin_type
->nodebug_text_gnu_ifunc_symbol
6125 = alloc
.new_type (TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
6126 "<text gnu-indirect-function variable, no debug info>");
6127 builtin_type
->nodebug_text_gnu_ifunc_symbol
->set_is_gnu_ifunc (true);
6129 builtin_type
->nodebug_got_plt_symbol
6130 = init_pointer_type (alloc
, gdbarch_addr_bit (gdbarch
),
6131 "<text from jump slot in .got.plt, no debug info>",
6132 builtin_type
->nodebug_text_symbol
);
6133 builtin_type
->nodebug_data_symbol
6134 = alloc
.new_type (TYPE_CODE_ERROR
, 0, "<data variable, no debug info>");
6135 builtin_type
->nodebug_unknown_symbol
6136 = alloc
.new_type (TYPE_CODE_ERROR
, 0,
6137 "<variable (not text or data), no debug info>");
6138 builtin_type
->nodebug_tls_symbol
6139 = alloc
.new_type (TYPE_CODE_ERROR
, 0,
6140 "<thread local variable, no debug info>");
6142 /* NOTE: on some targets, addresses and pointers are not necessarily
6146 - gdb's `struct type' always describes the target's
6148 - gdb's `struct value' objects should always hold values in
6150 - gdb's CORE_ADDR values are addresses in the unified virtual
6151 address space that the assembler and linker work with. Thus,
6152 since target_read_memory takes a CORE_ADDR as an argument, it
6153 can access any memory on the target, even if the processor has
6154 separate code and data address spaces.
6156 In this context, builtin_type->builtin_core_addr is a bit odd:
6157 it's a target type for a value the target will never see. It's
6158 only used to hold the values of (typeless) linker symbols, which
6159 are indeed in the unified virtual address space. */
6161 builtin_type
->builtin_core_addr
6162 = init_integer_type (alloc
, gdbarch_addr_bit (gdbarch
), 1,
6164 return builtin_type
;
6167 const struct builtin_type
*
6168 builtin_type (struct gdbarch
*gdbarch
)
6170 struct builtin_type
*result
= gdbtypes_data
.get (gdbarch
);
6171 if (result
== nullptr)
6173 result
= create_gdbtypes_data (gdbarch
);
6174 gdbtypes_data
.set (gdbarch
, result
);
6179 const struct builtin_type
*
6180 builtin_type (struct objfile
*objfile
)
6182 return builtin_type (objfile
->arch ());
6185 /* See gdbtypes.h. */
6188 call_site::pc () const
6190 return per_objfile
->relocate (m_unrelocated_pc
);
6193 void _initialize_gdbtypes ();
6195 _initialize_gdbtypes ()
6197 add_setshow_zuinteger_cmd ("overload", no_class
, &overload_debug
,
6198 _("Set debugging of C++ overloading."),
6199 _("Show debugging of C++ overloading."),
6200 _("When enabled, ranking of the "
6201 "functions is displayed."),
6203 show_overload_debug
,
6204 &setdebuglist
, &showdebuglist
);
6206 /* Add user knob for controlling resolution of opaque types. */
6207 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
6208 &opaque_type_resolution
,
6209 _("Set resolution of opaque struct/class/union"
6210 " types (if set before loading symbols)."),
6211 _("Show resolution of opaque struct/class/union"
6212 " types (if set before loading symbols)."),
6214 show_opaque_type_resolution
,
6215 &setlist
, &showlist
);
6217 /* Add an option to permit non-strict type checking. */
6218 add_setshow_boolean_cmd ("type", class_support
,
6219 &strict_type_checking
,
6220 _("Set strict type checking."),
6221 _("Show strict type checking."),
6223 show_strict_type_checking
,
6224 &setchecklist
, &showchecklist
);