1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2020 Free Software Foundation, Inc.
5 Contributed by Cygnus Support, using pieces from other GDB modules.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "expression.h"
33 #include "complaints.h"
37 #include "cp-support.h"
39 #include "dwarf2/loc.h"
41 #include "floatformat.h"
43 #include "gmp-utils.h"
45 /* Initialize BADNESS constants. */
47 const struct rank LENGTH_MISMATCH_BADNESS
= {100,0};
49 const struct rank TOO_FEW_PARAMS_BADNESS
= {100,0};
50 const struct rank INCOMPATIBLE_TYPE_BADNESS
= {100,0};
52 const struct rank EXACT_MATCH_BADNESS
= {0,0};
54 const struct rank INTEGER_PROMOTION_BADNESS
= {1,0};
55 const struct rank FLOAT_PROMOTION_BADNESS
= {1,0};
56 const struct rank BASE_PTR_CONVERSION_BADNESS
= {1,0};
57 const struct rank CV_CONVERSION_BADNESS
= {1, 0};
58 const struct rank INTEGER_CONVERSION_BADNESS
= {2,0};
59 const struct rank FLOAT_CONVERSION_BADNESS
= {2,0};
60 const struct rank INT_FLOAT_CONVERSION_BADNESS
= {2,0};
61 const struct rank VOID_PTR_CONVERSION_BADNESS
= {2,0};
62 const struct rank BOOL_CONVERSION_BADNESS
= {3,0};
63 const struct rank BASE_CONVERSION_BADNESS
= {2,0};
64 const struct rank REFERENCE_CONVERSION_BADNESS
= {2,0};
65 const struct rank REFERENCE_SEE_THROUGH_BADNESS
= {0,1};
66 const struct rank NULL_POINTER_CONVERSION_BADNESS
= {2,0};
67 const struct rank NS_POINTER_CONVERSION_BADNESS
= {10,0};
68 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS
= {3,0};
70 /* Floatformat pairs. */
71 const struct floatformat
*floatformats_ieee_half
[BFD_ENDIAN_UNKNOWN
] = {
72 &floatformat_ieee_half_big
,
73 &floatformat_ieee_half_little
75 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
76 &floatformat_ieee_single_big
,
77 &floatformat_ieee_single_little
79 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
80 &floatformat_ieee_double_big
,
81 &floatformat_ieee_double_little
83 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
84 &floatformat_ieee_double_big
,
85 &floatformat_ieee_double_littlebyte_bigword
87 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
88 &floatformat_i387_ext
,
91 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
92 &floatformat_m68881_ext
,
93 &floatformat_m68881_ext
95 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
96 &floatformat_arm_ext_big
,
97 &floatformat_arm_ext_littlebyte_bigword
99 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
100 &floatformat_ia64_spill_big
,
101 &floatformat_ia64_spill_little
103 const struct floatformat
*floatformats_ia64_quad
[BFD_ENDIAN_UNKNOWN
] = {
104 &floatformat_ia64_quad_big
,
105 &floatformat_ia64_quad_little
107 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
111 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
115 const struct floatformat
*floatformats_ibm_long_double
[BFD_ENDIAN_UNKNOWN
] = {
116 &floatformat_ibm_long_double_big
,
117 &floatformat_ibm_long_double_little
119 const struct floatformat
*floatformats_bfloat16
[BFD_ENDIAN_UNKNOWN
] = {
120 &floatformat_bfloat16_big
,
121 &floatformat_bfloat16_little
124 /* Should opaque types be resolved? */
126 static bool opaque_type_resolution
= true;
128 /* See gdbtypes.h. */
130 unsigned int overload_debug
= 0;
132 /* A flag to enable strict type checking. */
134 static bool strict_type_checking
= true;
136 /* A function to show whether opaque types are resolved. */
139 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
140 struct cmd_list_element
*c
,
143 fprintf_filtered (file
, _("Resolution of opaque struct/class/union types "
144 "(if set before loading symbols) is %s.\n"),
148 /* A function to show whether C++ overload debugging is enabled. */
151 show_overload_debug (struct ui_file
*file
, int from_tty
,
152 struct cmd_list_element
*c
, const char *value
)
154 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"),
158 /* A function to show the status of strict type checking. */
161 show_strict_type_checking (struct ui_file
*file
, int from_tty
,
162 struct cmd_list_element
*c
, const char *value
)
164 fprintf_filtered (file
, _("Strict type checking is %s.\n"), value
);
168 /* Allocate a new OBJFILE-associated type structure and fill it
169 with some defaults. Space for the type structure is allocated
170 on the objfile's objfile_obstack. */
173 alloc_type (struct objfile
*objfile
)
177 gdb_assert (objfile
!= NULL
);
179 /* Alloc the structure and start off with all fields zeroed. */
180 type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct type
);
181 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
183 OBJSTAT (objfile
, n_types
++);
185 TYPE_OBJFILE_OWNED (type
) = 1;
186 TYPE_OWNER (type
).objfile
= objfile
;
188 /* Initialize the fields that might not be zero. */
190 type
->set_code (TYPE_CODE_UNDEF
);
191 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
196 /* Allocate a new GDBARCH-associated type structure and fill it
197 with some defaults. Space for the type structure is allocated
198 on the obstack associated with GDBARCH. */
201 alloc_type_arch (struct gdbarch
*gdbarch
)
205 gdb_assert (gdbarch
!= NULL
);
207 /* Alloc the structure and start off with all fields zeroed. */
209 type
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct type
);
210 TYPE_MAIN_TYPE (type
) = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct main_type
);
212 TYPE_OBJFILE_OWNED (type
) = 0;
213 TYPE_OWNER (type
).gdbarch
= gdbarch
;
215 /* Initialize the fields that might not be zero. */
217 type
->set_code (TYPE_CODE_UNDEF
);
218 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
223 /* If TYPE is objfile-associated, allocate a new type structure
224 associated with the same objfile. If TYPE is gdbarch-associated,
225 allocate a new type structure associated with the same gdbarch. */
228 alloc_type_copy (const struct type
*type
)
230 if (TYPE_OBJFILE_OWNED (type
))
231 return alloc_type (TYPE_OWNER (type
).objfile
);
233 return alloc_type_arch (TYPE_OWNER (type
).gdbarch
);
236 /* If TYPE is gdbarch-associated, return that architecture.
237 If TYPE is objfile-associated, return that objfile's architecture. */
240 get_type_arch (const struct type
*type
)
242 struct gdbarch
*arch
;
244 if (TYPE_OBJFILE_OWNED (type
))
245 arch
= TYPE_OWNER (type
).objfile
->arch ();
247 arch
= TYPE_OWNER (type
).gdbarch
;
249 /* The ARCH can be NULL if TYPE is associated with neither an objfile nor
250 a gdbarch, however, this is very rare, and even then, in most cases
251 that get_type_arch is called, we assume that a non-NULL value is
253 gdb_assert (arch
!= NULL
);
257 /* See gdbtypes.h. */
260 get_target_type (struct type
*type
)
264 type
= TYPE_TARGET_TYPE (type
);
266 type
= check_typedef (type
);
272 /* See gdbtypes.h. */
275 type_length_units (struct type
*type
)
277 struct gdbarch
*arch
= get_type_arch (type
);
278 int unit_size
= gdbarch_addressable_memory_unit_size (arch
);
280 return TYPE_LENGTH (type
) / unit_size
;
283 /* Alloc a new type instance structure, fill it with some defaults,
284 and point it at OLDTYPE. Allocate the new type instance from the
285 same place as OLDTYPE. */
288 alloc_type_instance (struct type
*oldtype
)
292 /* Allocate the structure. */
294 if (! TYPE_OBJFILE_OWNED (oldtype
))
295 type
= GDBARCH_OBSTACK_ZALLOC (get_type_arch (oldtype
), struct type
);
297 type
= OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
300 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
302 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
307 /* Clear all remnants of the previous type at TYPE, in preparation for
308 replacing it with something else. Preserve owner information. */
311 smash_type (struct type
*type
)
313 int objfile_owned
= TYPE_OBJFILE_OWNED (type
);
314 union type_owner owner
= TYPE_OWNER (type
);
316 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
318 /* Restore owner information. */
319 TYPE_OBJFILE_OWNED (type
) = objfile_owned
;
320 TYPE_OWNER (type
) = owner
;
322 /* For now, delete the rings. */
323 TYPE_CHAIN (type
) = type
;
325 /* For now, leave the pointer/reference types alone. */
328 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
329 to a pointer to memory where the pointer type should be stored.
330 If *TYPEPTR is zero, update it to point to the pointer type we return.
331 We allocate new memory if needed. */
334 make_pointer_type (struct type
*type
, struct type
**typeptr
)
336 struct type
*ntype
; /* New type */
339 ntype
= TYPE_POINTER_TYPE (type
);
344 return ntype
; /* Don't care about alloc,
345 and have new type. */
346 else if (*typeptr
== 0)
348 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
353 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
355 ntype
= alloc_type_copy (type
);
359 else /* We have storage, but need to reset it. */
362 chain
= TYPE_CHAIN (ntype
);
364 TYPE_CHAIN (ntype
) = chain
;
367 TYPE_TARGET_TYPE (ntype
) = type
;
368 TYPE_POINTER_TYPE (type
) = ntype
;
370 /* FIXME! Assumes the machine has only one representation for pointers! */
373 = gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
374 ntype
->set_code (TYPE_CODE_PTR
);
376 /* Mark pointers as unsigned. The target converts between pointers
377 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
378 gdbarch_address_to_pointer. */
379 ntype
->set_is_unsigned (true);
381 /* Update the length of all the other variants of this type. */
382 chain
= TYPE_CHAIN (ntype
);
383 while (chain
!= ntype
)
385 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
386 chain
= TYPE_CHAIN (chain
);
392 /* Given a type TYPE, return a type of pointers to that type.
393 May need to construct such a type if this is the first use. */
396 lookup_pointer_type (struct type
*type
)
398 return make_pointer_type (type
, (struct type
**) 0);
401 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
402 points to a pointer to memory where the reference type should be
403 stored. If *TYPEPTR is zero, update it to point to the reference
404 type we return. We allocate new memory if needed. REFCODE denotes
405 the kind of reference type to lookup (lvalue or rvalue reference). */
408 make_reference_type (struct type
*type
, struct type
**typeptr
,
409 enum type_code refcode
)
411 struct type
*ntype
; /* New type */
412 struct type
**reftype
;
415 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
417 ntype
= (refcode
== TYPE_CODE_REF
? TYPE_REFERENCE_TYPE (type
)
418 : TYPE_RVALUE_REFERENCE_TYPE (type
));
423 return ntype
; /* Don't care about alloc,
424 and have new type. */
425 else if (*typeptr
== 0)
427 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
432 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
434 ntype
= alloc_type_copy (type
);
438 else /* We have storage, but need to reset it. */
441 chain
= TYPE_CHAIN (ntype
);
443 TYPE_CHAIN (ntype
) = chain
;
446 TYPE_TARGET_TYPE (ntype
) = type
;
447 reftype
= (refcode
== TYPE_CODE_REF
? &TYPE_REFERENCE_TYPE (type
)
448 : &TYPE_RVALUE_REFERENCE_TYPE (type
));
452 /* FIXME! Assume the machine has only one representation for
453 references, and that it matches the (only) representation for
456 TYPE_LENGTH (ntype
) =
457 gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
458 ntype
->set_code (refcode
);
462 /* Update the length of all the other variants of this type. */
463 chain
= TYPE_CHAIN (ntype
);
464 while (chain
!= ntype
)
466 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
467 chain
= TYPE_CHAIN (chain
);
473 /* Same as above, but caller doesn't care about memory allocation
477 lookup_reference_type (struct type
*type
, enum type_code refcode
)
479 return make_reference_type (type
, (struct type
**) 0, refcode
);
482 /* Lookup the lvalue reference type for the type TYPE. */
485 lookup_lvalue_reference_type (struct type
*type
)
487 return lookup_reference_type (type
, TYPE_CODE_REF
);
490 /* Lookup the rvalue reference type for the type TYPE. */
493 lookup_rvalue_reference_type (struct type
*type
)
495 return lookup_reference_type (type
, TYPE_CODE_RVALUE_REF
);
498 /* Lookup a function type that returns type TYPE. TYPEPTR, if
499 nonzero, points to a pointer to memory where the function type
500 should be stored. If *TYPEPTR is zero, update it to point to the
501 function type we return. We allocate new memory if needed. */
504 make_function_type (struct type
*type
, struct type
**typeptr
)
506 struct type
*ntype
; /* New type */
508 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
510 ntype
= alloc_type_copy (type
);
514 else /* We have storage, but need to reset it. */
520 TYPE_TARGET_TYPE (ntype
) = type
;
522 TYPE_LENGTH (ntype
) = 1;
523 ntype
->set_code (TYPE_CODE_FUNC
);
525 INIT_FUNC_SPECIFIC (ntype
);
530 /* Given a type TYPE, return a type of functions that return that type.
531 May need to construct such a type if this is the first use. */
534 lookup_function_type (struct type
*type
)
536 return make_function_type (type
, (struct type
**) 0);
539 /* Given a type TYPE and argument types, return the appropriate
540 function type. If the final type in PARAM_TYPES is NULL, make a
544 lookup_function_type_with_arguments (struct type
*type
,
546 struct type
**param_types
)
548 struct type
*fn
= make_function_type (type
, (struct type
**) 0);
553 if (param_types
[nparams
- 1] == NULL
)
556 fn
->set_has_varargs (true);
558 else if (check_typedef (param_types
[nparams
- 1])->code ()
562 /* Caller should have ensured this. */
563 gdb_assert (nparams
== 0);
564 fn
->set_is_prototyped (true);
567 fn
->set_is_prototyped (true);
570 fn
->set_num_fields (nparams
);
572 ((struct field
*) TYPE_ZALLOC (fn
, nparams
* sizeof (struct field
)));
573 for (i
= 0; i
< nparams
; ++i
)
574 fn
->field (i
).set_type (param_types
[i
]);
579 /* Identify address space identifier by name -- return a
580 type_instance_flags. */
583 address_space_name_to_type_instance_flags (struct gdbarch
*gdbarch
,
584 const char *space_identifier
)
586 type_instance_flags type_flags
;
588 /* Check for known address space delimiters. */
589 if (!strcmp (space_identifier
, "code"))
590 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
591 else if (!strcmp (space_identifier
, "data"))
592 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
593 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
594 && gdbarch_address_class_name_to_type_flags (gdbarch
,
599 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
602 /* Identify address space identifier by type_instance_flags and return
603 the string version of the adress space name. */
606 address_space_type_instance_flags_to_name (struct gdbarch
*gdbarch
,
607 type_instance_flags space_flag
)
609 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
611 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
613 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
614 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
615 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
620 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
622 If STORAGE is non-NULL, create the new type instance there.
623 STORAGE must be in the same obstack as TYPE. */
626 make_qualified_type (struct type
*type
, type_instance_flags new_flags
,
627 struct type
*storage
)
634 if (ntype
->instance_flags () == new_flags
)
636 ntype
= TYPE_CHAIN (ntype
);
638 while (ntype
!= type
);
640 /* Create a new type instance. */
642 ntype
= alloc_type_instance (type
);
645 /* If STORAGE was provided, it had better be in the same objfile
646 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
647 if one objfile is freed and the other kept, we'd have
648 dangling pointers. */
649 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
652 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
653 TYPE_CHAIN (ntype
) = ntype
;
656 /* Pointers or references to the original type are not relevant to
658 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
659 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
661 /* Chain the new qualified type to the old type. */
662 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
663 TYPE_CHAIN (type
) = ntype
;
665 /* Now set the instance flags and return the new type. */
666 ntype
->set_instance_flags (new_flags
);
668 /* Set length of new type to that of the original type. */
669 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
674 /* Make an address-space-delimited variant of a type -- a type that
675 is identical to the one supplied except that it has an address
676 space attribute attached to it (such as "code" or "data").
678 The space attributes "code" and "data" are for Harvard
679 architectures. The address space attributes are for architectures
680 which have alternately sized pointers or pointers with alternate
684 make_type_with_address_space (struct type
*type
,
685 type_instance_flags space_flag
)
687 type_instance_flags new_flags
= ((type
->instance_flags ()
688 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
689 | TYPE_INSTANCE_FLAG_DATA_SPACE
690 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
693 return make_qualified_type (type
, new_flags
, NULL
);
696 /* Make a "c-v" variant of a type -- a type that is identical to the
697 one supplied except that it may have const or volatile attributes
698 CNST is a flag for setting the const attribute
699 VOLTL is a flag for setting the volatile attribute
700 TYPE is the base type whose variant we are creating.
702 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
703 storage to hold the new qualified type; *TYPEPTR and TYPE must be
704 in the same objfile. Otherwise, allocate fresh memory for the new
705 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
706 new type we construct. */
709 make_cv_type (int cnst
, int voltl
,
711 struct type
**typeptr
)
713 struct type
*ntype
; /* New type */
715 type_instance_flags new_flags
= (type
->instance_flags ()
716 & ~(TYPE_INSTANCE_FLAG_CONST
717 | TYPE_INSTANCE_FLAG_VOLATILE
));
720 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
723 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
725 if (typeptr
&& *typeptr
!= NULL
)
727 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
728 a C-V variant chain that threads across objfiles: if one
729 objfile gets freed, then the other has a broken C-V chain.
731 This code used to try to copy over the main type from TYPE to
732 *TYPEPTR if they were in different objfiles, but that's
733 wrong, too: TYPE may have a field list or member function
734 lists, which refer to types of their own, etc. etc. The
735 whole shebang would need to be copied over recursively; you
736 can't have inter-objfile pointers. The only thing to do is
737 to leave stub types as stub types, and look them up afresh by
738 name each time you encounter them. */
739 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
742 ntype
= make_qualified_type (type
, new_flags
,
743 typeptr
? *typeptr
: NULL
);
751 /* Make a 'restrict'-qualified version of TYPE. */
754 make_restrict_type (struct type
*type
)
756 return make_qualified_type (type
,
757 (type
->instance_flags ()
758 | TYPE_INSTANCE_FLAG_RESTRICT
),
762 /* Make a type without const, volatile, or restrict. */
765 make_unqualified_type (struct type
*type
)
767 return make_qualified_type (type
,
768 (type
->instance_flags ()
769 & ~(TYPE_INSTANCE_FLAG_CONST
770 | TYPE_INSTANCE_FLAG_VOLATILE
771 | TYPE_INSTANCE_FLAG_RESTRICT
)),
775 /* Make a '_Atomic'-qualified version of TYPE. */
778 make_atomic_type (struct type
*type
)
780 return make_qualified_type (type
,
781 (type
->instance_flags ()
782 | TYPE_INSTANCE_FLAG_ATOMIC
),
786 /* Replace the contents of ntype with the type *type. This changes the
787 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
788 the changes are propogated to all types in the TYPE_CHAIN.
790 In order to build recursive types, it's inevitable that we'll need
791 to update types in place --- but this sort of indiscriminate
792 smashing is ugly, and needs to be replaced with something more
793 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
794 clear if more steps are needed. */
797 replace_type (struct type
*ntype
, struct type
*type
)
801 /* These two types had better be in the same objfile. Otherwise,
802 the assignment of one type's main type structure to the other
803 will produce a type with references to objects (names; field
804 lists; etc.) allocated on an objfile other than its own. */
805 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (type
));
807 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
809 /* The type length is not a part of the main type. Update it for
810 each type on the variant chain. */
814 /* Assert that this element of the chain has no address-class bits
815 set in its flags. Such type variants might have type lengths
816 which are supposed to be different from the non-address-class
817 variants. This assertion shouldn't ever be triggered because
818 symbol readers which do construct address-class variants don't
819 call replace_type(). */
820 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
822 TYPE_LENGTH (chain
) = TYPE_LENGTH (type
);
823 chain
= TYPE_CHAIN (chain
);
825 while (ntype
!= chain
);
827 /* Assert that the two types have equivalent instance qualifiers.
828 This should be true for at least all of our debug readers. */
829 gdb_assert (ntype
->instance_flags () == type
->instance_flags ());
832 /* Implement direct support for MEMBER_TYPE in GNU C++.
833 May need to construct such a type if this is the first use.
834 The TYPE is the type of the member. The DOMAIN is the type
835 of the aggregate that the member belongs to. */
838 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
842 mtype
= alloc_type_copy (type
);
843 smash_to_memberptr_type (mtype
, domain
, type
);
847 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
850 lookup_methodptr_type (struct type
*to_type
)
854 mtype
= alloc_type_copy (to_type
);
855 smash_to_methodptr_type (mtype
, to_type
);
859 /* Allocate a stub method whose return type is TYPE. This apparently
860 happens for speed of symbol reading, since parsing out the
861 arguments to the method is cpu-intensive, the way we are doing it.
862 So, we will fill in arguments later. This always returns a fresh
866 allocate_stub_method (struct type
*type
)
870 mtype
= alloc_type_copy (type
);
871 mtype
->set_code (TYPE_CODE_METHOD
);
872 TYPE_LENGTH (mtype
) = 1;
873 mtype
->set_is_stub (true);
874 TYPE_TARGET_TYPE (mtype
) = type
;
875 /* TYPE_SELF_TYPE (mtype) = unknown yet */
879 /* See gdbtypes.h. */
882 operator== (const dynamic_prop
&l
, const dynamic_prop
&r
)
884 if (l
.kind () != r
.kind ())
892 return l
.const_val () == r
.const_val ();
893 case PROP_ADDR_OFFSET
:
896 return l
.baton () == r
.baton ();
897 case PROP_VARIANT_PARTS
:
898 return l
.variant_parts () == r
.variant_parts ();
900 return l
.original_type () == r
.original_type ();
903 gdb_assert_not_reached ("unhandled dynamic_prop kind");
906 /* See gdbtypes.h. */
909 operator== (const range_bounds
&l
, const range_bounds
&r
)
911 #define FIELD_EQ(FIELD) (l.FIELD == r.FIELD)
913 return (FIELD_EQ (low
)
915 && FIELD_EQ (flag_upper_bound_is_count
)
916 && FIELD_EQ (flag_bound_evaluated
)
922 /* Create a range type with a dynamic range from LOW_BOUND to
923 HIGH_BOUND, inclusive. See create_range_type for further details. */
926 create_range_type (struct type
*result_type
, struct type
*index_type
,
927 const struct dynamic_prop
*low_bound
,
928 const struct dynamic_prop
*high_bound
,
931 /* The INDEX_TYPE should be a type capable of holding the upper and lower
932 bounds, as such a zero sized, or void type makes no sense. */
933 gdb_assert (index_type
->code () != TYPE_CODE_VOID
);
934 gdb_assert (TYPE_LENGTH (index_type
) > 0);
936 if (result_type
== NULL
)
937 result_type
= alloc_type_copy (index_type
);
938 result_type
->set_code (TYPE_CODE_RANGE
);
939 TYPE_TARGET_TYPE (result_type
) = index_type
;
940 if (index_type
->is_stub ())
941 result_type
->set_target_is_stub (true);
943 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
946 = (struct range_bounds
*) TYPE_ZALLOC (result_type
, sizeof (range_bounds
));
947 bounds
->low
= *low_bound
;
948 bounds
->high
= *high_bound
;
950 bounds
->stride
.set_const_val (0);
952 result_type
->set_bounds (bounds
);
954 if (index_type
->code () == TYPE_CODE_FIXED_POINT
)
955 result_type
->set_is_unsigned (index_type
->is_unsigned ());
956 /* Note that the signed-ness of a range type can't simply be copied
957 from the underlying type. Consider a case where the underlying
958 type is 'int', but the range type can hold 0..65535, and where
959 the range is further specified to fit into 16 bits. In this
960 case, if we copy the underlying type's sign, then reading some
961 range values will cause an unwanted sign extension. So, we have
962 some heuristics here instead. */
963 else if (low_bound
->kind () == PROP_CONST
&& low_bound
->const_val () >= 0)
964 result_type
->set_is_unsigned (true);
965 /* Ada allows the declaration of range types whose upper bound is
966 less than the lower bound, so checking the lower bound is not
967 enough. Make sure we do not mark a range type whose upper bound
968 is negative as unsigned. */
969 if (high_bound
->kind () == PROP_CONST
&& high_bound
->const_val () < 0)
970 result_type
->set_is_unsigned (false);
972 result_type
->set_endianity_is_not_default
973 (index_type
->endianity_is_not_default ());
978 /* See gdbtypes.h. */
981 create_range_type_with_stride (struct type
*result_type
,
982 struct type
*index_type
,
983 const struct dynamic_prop
*low_bound
,
984 const struct dynamic_prop
*high_bound
,
986 const struct dynamic_prop
*stride
,
989 result_type
= create_range_type (result_type
, index_type
, low_bound
,
992 gdb_assert (stride
!= nullptr);
993 result_type
->bounds ()->stride
= *stride
;
994 result_type
->bounds ()->flag_is_byte_stride
= byte_stride_p
;
1001 /* Create a range type using either a blank type supplied in
1002 RESULT_TYPE, or creating a new type, inheriting the objfile from
1005 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
1006 to HIGH_BOUND, inclusive.
1008 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1009 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
1012 create_static_range_type (struct type
*result_type
, struct type
*index_type
,
1013 LONGEST low_bound
, LONGEST high_bound
)
1015 struct dynamic_prop low
, high
;
1017 low
.set_const_val (low_bound
);
1018 high
.set_const_val (high_bound
);
1020 result_type
= create_range_type (result_type
, index_type
, &low
, &high
, 0);
1025 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
1026 are static, otherwise returns 0. */
1029 has_static_range (const struct range_bounds
*bounds
)
1031 /* If the range doesn't have a defined stride then its stride field will
1032 be initialized to the constant 0. */
1033 return (bounds
->low
.kind () == PROP_CONST
1034 && bounds
->high
.kind () == PROP_CONST
1035 && bounds
->stride
.kind () == PROP_CONST
);
1039 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
1042 Return 1 if type is a range type with two defined, constant bounds.
1043 Else, return 0 if it is discrete (and bounds will fit in LONGEST).
1047 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
1049 type
= check_typedef (type
);
1050 switch (type
->code ())
1052 case TYPE_CODE_RANGE
:
1053 /* This function currently only works for ranges with two defined,
1055 if (type
->bounds ()->low
.kind () != PROP_CONST
1056 || type
->bounds ()->high
.kind () != PROP_CONST
)
1059 *lowp
= type
->bounds ()->low
.const_val ();
1060 *highp
= type
->bounds ()->high
.const_val ();
1062 if (TYPE_TARGET_TYPE (type
)->code () == TYPE_CODE_ENUM
)
1064 if (!discrete_position (TYPE_TARGET_TYPE (type
), *lowp
, lowp
)
1065 || ! discrete_position (TYPE_TARGET_TYPE (type
), *highp
, highp
))
1069 case TYPE_CODE_ENUM
:
1070 if (type
->num_fields () > 0)
1072 /* The enums may not be sorted by value, so search all
1076 *lowp
= *highp
= TYPE_FIELD_ENUMVAL (type
, 0);
1077 for (i
= 0; i
< type
->num_fields (); i
++)
1079 if (TYPE_FIELD_ENUMVAL (type
, i
) < *lowp
)
1080 *lowp
= TYPE_FIELD_ENUMVAL (type
, i
);
1081 if (TYPE_FIELD_ENUMVAL (type
, i
) > *highp
)
1082 *highp
= TYPE_FIELD_ENUMVAL (type
, i
);
1085 /* Set unsigned indicator if warranted. */
1087 type
->set_is_unsigned (true);
1095 case TYPE_CODE_BOOL
:
1100 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
1102 if (!type
->is_unsigned ())
1104 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
1105 *highp
= -*lowp
- 1;
1109 case TYPE_CODE_CHAR
:
1111 /* This round-about calculation is to avoid shifting by
1112 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
1113 if TYPE_LENGTH (type) == sizeof (LONGEST). */
1114 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
1115 *highp
= (*highp
- 1) | *highp
;
1122 /* Assuming TYPE is a simple, non-empty array type, compute its upper
1123 and lower bound. Save the low bound into LOW_BOUND if not NULL.
1124 Save the high bound into HIGH_BOUND if not NULL.
1126 Return 1 if the operation was successful. Return zero otherwise,
1127 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified. */
1130 get_array_bounds (struct type
*type
, LONGEST
*low_bound
, LONGEST
*high_bound
)
1132 struct type
*index
= type
->index_type ();
1140 res
= get_discrete_bounds (index
, &low
, &high
);
1153 /* Assuming that TYPE is a discrete type and VAL is a valid integer
1154 representation of a value of this type, save the corresponding
1155 position number in POS.
1157 Its differs from VAL only in the case of enumeration types. In
1158 this case, the position number of the value of the first listed
1159 enumeration literal is zero; the position number of the value of
1160 each subsequent enumeration literal is one more than that of its
1161 predecessor in the list.
1163 Return 1 if the operation was successful. Return zero otherwise,
1164 in which case the value of POS is unmodified.
1168 discrete_position (struct type
*type
, LONGEST val
, LONGEST
*pos
)
1170 if (type
->code () == TYPE_CODE_RANGE
)
1171 type
= TYPE_TARGET_TYPE (type
);
1173 if (type
->code () == TYPE_CODE_ENUM
)
1177 for (i
= 0; i
< type
->num_fields (); i
+= 1)
1179 if (val
== TYPE_FIELD_ENUMVAL (type
, i
))
1185 /* Invalid enumeration value. */
1195 /* If the array TYPE has static bounds calculate and update its
1196 size, then return true. Otherwise return false and leave TYPE
1200 update_static_array_size (struct type
*type
)
1202 gdb_assert (type
->code () == TYPE_CODE_ARRAY
);
1204 struct type
*range_type
= type
->index_type ();
1206 if (type
->dyn_prop (DYN_PROP_BYTE_STRIDE
) == nullptr
1207 && has_static_range (range_type
->bounds ())
1208 && (!type_not_associated (type
)
1209 && !type_not_allocated (type
)))
1211 LONGEST low_bound
, high_bound
;
1213 struct type
*element_type
;
1215 /* If the array itself doesn't provide a stride value then take
1216 whatever stride the range provides. Don't update BIT_STRIDE as
1217 we don't want to place the stride value from the range into this
1218 arrays bit size field. */
1219 stride
= TYPE_FIELD_BITSIZE (type
, 0);
1221 stride
= range_type
->bit_stride ();
1223 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
1224 low_bound
= high_bound
= 0;
1225 element_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1226 /* Be careful when setting the array length. Ada arrays can be
1227 empty arrays with the high_bound being smaller than the low_bound.
1228 In such cases, the array length should be zero. */
1229 if (high_bound
< low_bound
)
1230 TYPE_LENGTH (type
) = 0;
1231 else if (stride
!= 0)
1233 /* Ensure that the type length is always positive, even in the
1234 case where (for example in Fortran) we have a negative
1235 stride. It is possible to have a single element array with a
1236 negative stride in Fortran (this doesn't mean anything
1237 special, it's still just a single element array) so do
1238 consider that case when touching this code. */
1239 LONGEST element_count
= std::abs (high_bound
- low_bound
+ 1);
1241 = ((std::abs (stride
) * element_count
) + 7) / 8;
1244 TYPE_LENGTH (type
) =
1245 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
1247 /* If this array's element is itself an array with a bit stride,
1248 then we want to update this array's bit stride to reflect the
1249 size of the sub-array. Otherwise, we'll end up using the
1250 wrong size when trying to find elements of the outer
1252 if (element_type
->code () == TYPE_CODE_ARRAY
1253 && TYPE_LENGTH (element_type
) != 0
1254 && TYPE_FIELD_BITSIZE (element_type
, 0) != 0
1255 && get_array_bounds (element_type
, &low_bound
, &high_bound
) >= 0
1256 && high_bound
>= low_bound
)
1257 TYPE_FIELD_BITSIZE (type
, 0)
1258 = ((high_bound
- low_bound
+ 1)
1259 * TYPE_FIELD_BITSIZE (element_type
, 0));
1267 /* Create an array type using either a blank type supplied in
1268 RESULT_TYPE, or creating a new type, inheriting the objfile from
1271 Elements will be of type ELEMENT_TYPE, the indices will be of type
1274 BYTE_STRIDE_PROP, when not NULL, provides the array's byte stride.
1275 This byte stride property is added to the resulting array type
1276 as a DYN_PROP_BYTE_STRIDE. As a consequence, the BYTE_STRIDE_PROP
1277 argument can only be used to create types that are objfile-owned
1278 (see add_dyn_prop), meaning that either this function must be called
1279 with an objfile-owned RESULT_TYPE, or an objfile-owned RANGE_TYPE.
1281 BIT_STRIDE is taken into account only when BYTE_STRIDE_PROP is NULL.
1282 If BIT_STRIDE is not zero, build a packed array type whose element
1283 size is BIT_STRIDE. Otherwise, ignore this parameter.
1285 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1286 sure it is TYPE_CODE_UNDEF before we bash it into an array
1290 create_array_type_with_stride (struct type
*result_type
,
1291 struct type
*element_type
,
1292 struct type
*range_type
,
1293 struct dynamic_prop
*byte_stride_prop
,
1294 unsigned int bit_stride
)
1296 if (byte_stride_prop
!= NULL
1297 && byte_stride_prop
->kind () == PROP_CONST
)
1299 /* The byte stride is actually not dynamic. Pretend we were
1300 called with bit_stride set instead of byte_stride_prop.
1301 This will give us the same result type, while avoiding
1302 the need to handle this as a special case. */
1303 bit_stride
= byte_stride_prop
->const_val () * 8;
1304 byte_stride_prop
= NULL
;
1307 if (result_type
== NULL
)
1308 result_type
= alloc_type_copy (range_type
);
1310 result_type
->set_code (TYPE_CODE_ARRAY
);
1311 TYPE_TARGET_TYPE (result_type
) = element_type
;
1313 result_type
->set_num_fields (1);
1314 result_type
->set_fields
1315 ((struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
)));
1316 result_type
->set_index_type (range_type
);
1317 if (byte_stride_prop
!= NULL
)
1318 result_type
->add_dyn_prop (DYN_PROP_BYTE_STRIDE
, *byte_stride_prop
);
1319 else if (bit_stride
> 0)
1320 TYPE_FIELD_BITSIZE (result_type
, 0) = bit_stride
;
1322 if (!update_static_array_size (result_type
))
1324 /* This type is dynamic and its length needs to be computed
1325 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1326 undefined by setting it to zero. Although we are not expected
1327 to trust TYPE_LENGTH in this case, setting the size to zero
1328 allows us to avoid allocating objects of random sizes in case
1329 we accidently do. */
1330 TYPE_LENGTH (result_type
) = 0;
1333 /* TYPE_TARGET_STUB will take care of zero length arrays. */
1334 if (TYPE_LENGTH (result_type
) == 0)
1335 result_type
->set_target_is_stub (true);
1340 /* Same as create_array_type_with_stride but with no bit_stride
1341 (BIT_STRIDE = 0), thus building an unpacked array. */
1344 create_array_type (struct type
*result_type
,
1345 struct type
*element_type
,
1346 struct type
*range_type
)
1348 return create_array_type_with_stride (result_type
, element_type
,
1349 range_type
, NULL
, 0);
1353 lookup_array_range_type (struct type
*element_type
,
1354 LONGEST low_bound
, LONGEST high_bound
)
1356 struct type
*index_type
;
1357 struct type
*range_type
;
1359 if (TYPE_OBJFILE_OWNED (element_type
))
1360 index_type
= objfile_type (TYPE_OWNER (element_type
).objfile
)->builtin_int
;
1362 index_type
= builtin_type (get_type_arch (element_type
))->builtin_int
;
1363 range_type
= create_static_range_type (NULL
, index_type
,
1364 low_bound
, high_bound
);
1366 return create_array_type (NULL
, element_type
, range_type
);
1369 /* Create a string type using either a blank type supplied in
1370 RESULT_TYPE, or creating a new type. String types are similar
1371 enough to array of char types that we can use create_array_type to
1372 build the basic type and then bash it into a string type.
1374 For fixed length strings, the range type contains 0 as the lower
1375 bound and the length of the string minus one as the upper bound.
1377 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1378 sure it is TYPE_CODE_UNDEF before we bash it into a string
1382 create_string_type (struct type
*result_type
,
1383 struct type
*string_char_type
,
1384 struct type
*range_type
)
1386 result_type
= create_array_type (result_type
,
1389 result_type
->set_code (TYPE_CODE_STRING
);
1394 lookup_string_range_type (struct type
*string_char_type
,
1395 LONGEST low_bound
, LONGEST high_bound
)
1397 struct type
*result_type
;
1399 result_type
= lookup_array_range_type (string_char_type
,
1400 low_bound
, high_bound
);
1401 result_type
->set_code (TYPE_CODE_STRING
);
1406 create_set_type (struct type
*result_type
, struct type
*domain_type
)
1408 if (result_type
== NULL
)
1409 result_type
= alloc_type_copy (domain_type
);
1411 result_type
->set_code (TYPE_CODE_SET
);
1412 result_type
->set_num_fields (1);
1413 result_type
->set_fields
1414 ((struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
)));
1416 if (!domain_type
->is_stub ())
1418 LONGEST low_bound
, high_bound
, bit_length
;
1420 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
1421 low_bound
= high_bound
= 0;
1422 bit_length
= high_bound
- low_bound
+ 1;
1423 TYPE_LENGTH (result_type
)
1424 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
1426 result_type
->set_is_unsigned (true);
1428 result_type
->field (0).set_type (domain_type
);
1433 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1434 and any array types nested inside it. */
1437 make_vector_type (struct type
*array_type
)
1439 struct type
*inner_array
, *elt_type
;
1441 /* Find the innermost array type, in case the array is
1442 multi-dimensional. */
1443 inner_array
= array_type
;
1444 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
1445 inner_array
= TYPE_TARGET_TYPE (inner_array
);
1447 elt_type
= TYPE_TARGET_TYPE (inner_array
);
1448 if (elt_type
->code () == TYPE_CODE_INT
)
1450 type_instance_flags flags
1451 = elt_type
->instance_flags () | TYPE_INSTANCE_FLAG_NOTTEXT
;
1452 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
1453 TYPE_TARGET_TYPE (inner_array
) = elt_type
;
1456 array_type
->set_is_vector (true);
1460 init_vector_type (struct type
*elt_type
, int n
)
1462 struct type
*array_type
;
1464 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
1465 make_vector_type (array_type
);
1469 /* Internal routine called by TYPE_SELF_TYPE to return the type that TYPE
1470 belongs to. In c++ this is the class of "this", but TYPE_THIS_TYPE is too
1471 confusing. "self" is a common enough replacement for "this".
1472 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1473 TYPE_CODE_METHOD. */
1476 internal_type_self_type (struct type
*type
)
1478 switch (type
->code ())
1480 case TYPE_CODE_METHODPTR
:
1481 case TYPE_CODE_MEMBERPTR
:
1482 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1484 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1485 return TYPE_MAIN_TYPE (type
)->type_specific
.self_type
;
1486 case TYPE_CODE_METHOD
:
1487 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1489 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1490 return TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
;
1492 gdb_assert_not_reached ("bad type");
1496 /* Set the type of the class that TYPE belongs to.
1497 In c++ this is the class of "this".
1498 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1499 TYPE_CODE_METHOD. */
1502 set_type_self_type (struct type
*type
, struct type
*self_type
)
1504 switch (type
->code ())
1506 case TYPE_CODE_METHODPTR
:
1507 case TYPE_CODE_MEMBERPTR
:
1508 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1509 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_SELF_TYPE
;
1510 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1511 TYPE_MAIN_TYPE (type
)->type_specific
.self_type
= self_type
;
1513 case TYPE_CODE_METHOD
:
1514 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1515 INIT_FUNC_SPECIFIC (type
);
1516 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1517 TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
= self_type
;
1520 gdb_assert_not_reached ("bad type");
1524 /* Smash TYPE to be a type of pointers to members of SELF_TYPE with type
1525 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1526 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1527 TYPE doesn't include the offset (that's the value of the MEMBER
1528 itself), but does include the structure type into which it points
1531 When "smashing" the type, we preserve the objfile that the old type
1532 pointed to, since we aren't changing where the type is actually
1536 smash_to_memberptr_type (struct type
*type
, struct type
*self_type
,
1537 struct type
*to_type
)
1540 type
->set_code (TYPE_CODE_MEMBERPTR
);
1541 TYPE_TARGET_TYPE (type
) = to_type
;
1542 set_type_self_type (type
, self_type
);
1543 /* Assume that a data member pointer is the same size as a normal
1546 = gdbarch_ptr_bit (get_type_arch (to_type
)) / TARGET_CHAR_BIT
;
1549 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1551 When "smashing" the type, we preserve the objfile that the old type
1552 pointed to, since we aren't changing where the type is actually
1556 smash_to_methodptr_type (struct type
*type
, struct type
*to_type
)
1559 type
->set_code (TYPE_CODE_METHODPTR
);
1560 TYPE_TARGET_TYPE (type
) = to_type
;
1561 set_type_self_type (type
, TYPE_SELF_TYPE (to_type
));
1562 TYPE_LENGTH (type
) = cplus_method_ptr_size (to_type
);
1565 /* Smash TYPE to be a type of method of SELF_TYPE with type TO_TYPE.
1566 METHOD just means `function that gets an extra "this" argument'.
1568 When "smashing" the type, we preserve the objfile that the old type
1569 pointed to, since we aren't changing where the type is actually
1573 smash_to_method_type (struct type
*type
, struct type
*self_type
,
1574 struct type
*to_type
, struct field
*args
,
1575 int nargs
, int varargs
)
1578 type
->set_code (TYPE_CODE_METHOD
);
1579 TYPE_TARGET_TYPE (type
) = to_type
;
1580 set_type_self_type (type
, self_type
);
1581 type
->set_fields (args
);
1582 type
->set_num_fields (nargs
);
1584 type
->set_has_varargs (true);
1585 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1588 /* A wrapper of TYPE_NAME which calls error if the type is anonymous.
1589 Since GCC PR debug/47510 DWARF provides associated information to detect the
1590 anonymous class linkage name from its typedef.
1592 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1596 type_name_or_error (struct type
*type
)
1598 struct type
*saved_type
= type
;
1600 struct objfile
*objfile
;
1602 type
= check_typedef (type
);
1604 name
= type
->name ();
1608 name
= saved_type
->name ();
1609 objfile
= TYPE_OBJFILE (saved_type
);
1610 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1611 name
? name
: "<anonymous>",
1612 objfile
? objfile_name (objfile
) : "<arch>");
1615 /* Lookup a typedef or primitive type named NAME, visible in lexical
1616 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1617 suitably defined. */
1620 lookup_typename (const struct language_defn
*language
,
1622 const struct block
*block
, int noerr
)
1626 sym
= lookup_symbol_in_language (name
, block
, VAR_DOMAIN
,
1627 language
->la_language
, NULL
).symbol
;
1628 if (sym
!= NULL
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
1629 return SYMBOL_TYPE (sym
);
1633 error (_("No type named %s."), name
);
1637 lookup_unsigned_typename (const struct language_defn
*language
,
1640 char *uns
= (char *) alloca (strlen (name
) + 10);
1642 strcpy (uns
, "unsigned ");
1643 strcpy (uns
+ 9, name
);
1644 return lookup_typename (language
, uns
, NULL
, 0);
1648 lookup_signed_typename (const struct language_defn
*language
, const char *name
)
1651 char *uns
= (char *) alloca (strlen (name
) + 8);
1653 strcpy (uns
, "signed ");
1654 strcpy (uns
+ 7, name
);
1655 t
= lookup_typename (language
, uns
, NULL
, 1);
1656 /* If we don't find "signed FOO" just try again with plain "FOO". */
1659 return lookup_typename (language
, name
, NULL
, 0);
1662 /* Lookup a structure type named "struct NAME",
1663 visible in lexical block BLOCK. */
1666 lookup_struct (const char *name
, const struct block
*block
)
1670 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1674 error (_("No struct type named %s."), name
);
1676 if (SYMBOL_TYPE (sym
)->code () != TYPE_CODE_STRUCT
)
1678 error (_("This context has class, union or enum %s, not a struct."),
1681 return (SYMBOL_TYPE (sym
));
1684 /* Lookup a union type named "union NAME",
1685 visible in lexical block BLOCK. */
1688 lookup_union (const char *name
, const struct block
*block
)
1693 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1696 error (_("No union type named %s."), name
);
1698 t
= SYMBOL_TYPE (sym
);
1700 if (t
->code () == TYPE_CODE_UNION
)
1703 /* If we get here, it's not a union. */
1704 error (_("This context has class, struct or enum %s, not a union."),
1708 /* Lookup an enum type named "enum NAME",
1709 visible in lexical block BLOCK. */
1712 lookup_enum (const char *name
, const struct block
*block
)
1716 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1719 error (_("No enum type named %s."), name
);
1721 if (SYMBOL_TYPE (sym
)->code () != TYPE_CODE_ENUM
)
1723 error (_("This context has class, struct or union %s, not an enum."),
1726 return (SYMBOL_TYPE (sym
));
1729 /* Lookup a template type named "template NAME<TYPE>",
1730 visible in lexical block BLOCK. */
1733 lookup_template_type (const char *name
, struct type
*type
,
1734 const struct block
*block
)
1737 char *nam
= (char *)
1738 alloca (strlen (name
) + strlen (type
->name ()) + 4);
1742 strcat (nam
, type
->name ());
1743 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1745 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0).symbol
;
1749 error (_("No template type named %s."), name
);
1751 if (SYMBOL_TYPE (sym
)->code () != TYPE_CODE_STRUCT
)
1753 error (_("This context has class, union or enum %s, not a struct."),
1756 return (SYMBOL_TYPE (sym
));
1759 /* See gdbtypes.h. */
1762 lookup_struct_elt (struct type
*type
, const char *name
, int noerr
)
1768 type
= check_typedef (type
);
1769 if (type
->code () != TYPE_CODE_PTR
1770 && type
->code () != TYPE_CODE_REF
)
1772 type
= TYPE_TARGET_TYPE (type
);
1775 if (type
->code () != TYPE_CODE_STRUCT
1776 && type
->code () != TYPE_CODE_UNION
)
1778 std::string type_name
= type_to_string (type
);
1779 error (_("Type %s is not a structure or union type."),
1780 type_name
.c_str ());
1783 for (i
= type
->num_fields () - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1785 const char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1787 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1789 return {&type
->field (i
), TYPE_FIELD_BITPOS (type
, i
)};
1791 else if (!t_field_name
|| *t_field_name
== '\0')
1794 = lookup_struct_elt (type
->field (i
).type (), name
, 1);
1795 if (elt
.field
!= NULL
)
1797 elt
.offset
+= TYPE_FIELD_BITPOS (type
, i
);
1803 /* OK, it's not in this class. Recursively check the baseclasses. */
1804 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1806 struct_elt elt
= lookup_struct_elt (TYPE_BASECLASS (type
, i
), name
, 1);
1807 if (elt
.field
!= NULL
)
1812 return {nullptr, 0};
1814 std::string type_name
= type_to_string (type
);
1815 error (_("Type %s has no component named %s."), type_name
.c_str (), name
);
1818 /* See gdbtypes.h. */
1821 lookup_struct_elt_type (struct type
*type
, const char *name
, int noerr
)
1823 struct_elt elt
= lookup_struct_elt (type
, name
, noerr
);
1824 if (elt
.field
!= NULL
)
1825 return elt
.field
->type ();
1830 /* Store in *MAX the largest number representable by unsigned integer type
1834 get_unsigned_type_max (struct type
*type
, ULONGEST
*max
)
1838 type
= check_typedef (type
);
1839 gdb_assert (type
->code () == TYPE_CODE_INT
&& type
->is_unsigned ());
1840 gdb_assert (TYPE_LENGTH (type
) <= sizeof (ULONGEST
));
1842 /* Written this way to avoid overflow. */
1843 n
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
;
1844 *max
= ((((ULONGEST
) 1 << (n
- 1)) - 1) << 1) | 1;
1847 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1848 signed integer type TYPE. */
1851 get_signed_type_minmax (struct type
*type
, LONGEST
*min
, LONGEST
*max
)
1855 type
= check_typedef (type
);
1856 gdb_assert (type
->code () == TYPE_CODE_INT
&& !type
->is_unsigned ());
1857 gdb_assert (TYPE_LENGTH (type
) <= sizeof (LONGEST
));
1859 n
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
;
1860 *min
= -((ULONGEST
) 1 << (n
- 1));
1861 *max
= ((ULONGEST
) 1 << (n
- 1)) - 1;
1864 /* Internal routine called by TYPE_VPTR_FIELDNO to return the value of
1865 cplus_stuff.vptr_fieldno.
1867 cplus_stuff is initialized to cplus_struct_default which does not
1868 set vptr_fieldno to -1 for portability reasons (IWBN to use C99
1869 designated initializers). We cope with that here. */
1872 internal_type_vptr_fieldno (struct type
*type
)
1874 type
= check_typedef (type
);
1875 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1876 || type
->code () == TYPE_CODE_UNION
);
1877 if (!HAVE_CPLUS_STRUCT (type
))
1879 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
;
1882 /* Set the value of cplus_stuff.vptr_fieldno. */
1885 set_type_vptr_fieldno (struct type
*type
, int fieldno
)
1887 type
= check_typedef (type
);
1888 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1889 || type
->code () == TYPE_CODE_UNION
);
1890 if (!HAVE_CPLUS_STRUCT (type
))
1891 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1892 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
= fieldno
;
1895 /* Internal routine called by TYPE_VPTR_BASETYPE to return the value of
1896 cplus_stuff.vptr_basetype. */
1899 internal_type_vptr_basetype (struct type
*type
)
1901 type
= check_typedef (type
);
1902 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1903 || type
->code () == TYPE_CODE_UNION
);
1904 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_CPLUS_STUFF
);
1905 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
;
1908 /* Set the value of cplus_stuff.vptr_basetype. */
1911 set_type_vptr_basetype (struct type
*type
, struct type
*basetype
)
1913 type
= check_typedef (type
);
1914 gdb_assert (type
->code () == TYPE_CODE_STRUCT
1915 || type
->code () == TYPE_CODE_UNION
);
1916 if (!HAVE_CPLUS_STRUCT (type
))
1917 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1918 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
= basetype
;
1921 /* Lookup the vptr basetype/fieldno values for TYPE.
1922 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1923 vptr_fieldno. Also, if found and basetype is from the same objfile,
1925 If not found, return -1 and ignore BASETYPEP.
1926 Callers should be aware that in some cases (for example,
1927 the type or one of its baseclasses is a stub type and we are
1928 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1929 this function will not be able to find the
1930 virtual function table pointer, and vptr_fieldno will remain -1 and
1931 vptr_basetype will remain NULL or incomplete. */
1934 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1936 type
= check_typedef (type
);
1938 if (TYPE_VPTR_FIELDNO (type
) < 0)
1942 /* We must start at zero in case the first (and only) baseclass
1943 is virtual (and hence we cannot share the table pointer). */
1944 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1946 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1948 struct type
*basetype
;
1950 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1953 /* If the type comes from a different objfile we can't cache
1954 it, it may have a different lifetime. PR 2384 */
1955 if (TYPE_OBJFILE (type
) == TYPE_OBJFILE (basetype
))
1957 set_type_vptr_fieldno (type
, fieldno
);
1958 set_type_vptr_basetype (type
, basetype
);
1961 *basetypep
= basetype
;
1972 *basetypep
= TYPE_VPTR_BASETYPE (type
);
1973 return TYPE_VPTR_FIELDNO (type
);
1978 stub_noname_complaint (void)
1980 complaint (_("stub type has NULL name"));
1983 /* Return nonzero if TYPE has a DYN_PROP_BYTE_STRIDE dynamic property
1984 attached to it, and that property has a non-constant value. */
1987 array_type_has_dynamic_stride (struct type
*type
)
1989 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_BYTE_STRIDE
);
1991 return (prop
!= NULL
&& prop
->kind () != PROP_CONST
);
1994 /* Worker for is_dynamic_type. */
1997 is_dynamic_type_internal (struct type
*type
, int top_level
)
1999 type
= check_typedef (type
);
2001 /* We only want to recognize references at the outermost level. */
2002 if (top_level
&& type
->code () == TYPE_CODE_REF
)
2003 type
= check_typedef (TYPE_TARGET_TYPE (type
));
2005 /* Types that have a dynamic TYPE_DATA_LOCATION are considered
2006 dynamic, even if the type itself is statically defined.
2007 From a user's point of view, this may appear counter-intuitive;
2008 but it makes sense in this context, because the point is to determine
2009 whether any part of the type needs to be resolved before it can
2011 if (TYPE_DATA_LOCATION (type
) != NULL
2012 && (TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCEXPR
2013 || TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCLIST
))
2016 if (TYPE_ASSOCIATED_PROP (type
))
2019 if (TYPE_ALLOCATED_PROP (type
))
2022 struct dynamic_prop
*prop
= type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
2023 if (prop
!= nullptr && prop
->kind () != PROP_TYPE
)
2026 if (TYPE_HAS_DYNAMIC_LENGTH (type
))
2029 switch (type
->code ())
2031 case TYPE_CODE_RANGE
:
2033 /* A range type is obviously dynamic if it has at least one
2034 dynamic bound. But also consider the range type to be
2035 dynamic when its subtype is dynamic, even if the bounds
2036 of the range type are static. It allows us to assume that
2037 the subtype of a static range type is also static. */
2038 return (!has_static_range (type
->bounds ())
2039 || is_dynamic_type_internal (TYPE_TARGET_TYPE (type
), 0));
2042 case TYPE_CODE_STRING
:
2043 /* Strings are very much like an array of characters, and can be
2044 treated as one here. */
2045 case TYPE_CODE_ARRAY
:
2047 gdb_assert (type
->num_fields () == 1);
2049 /* The array is dynamic if either the bounds are dynamic... */
2050 if (is_dynamic_type_internal (type
->index_type (), 0))
2052 /* ... or the elements it contains have a dynamic contents... */
2053 if (is_dynamic_type_internal (TYPE_TARGET_TYPE (type
), 0))
2055 /* ... or if it has a dynamic stride... */
2056 if (array_type_has_dynamic_stride (type
))
2061 case TYPE_CODE_STRUCT
:
2062 case TYPE_CODE_UNION
:
2066 bool is_cplus
= HAVE_CPLUS_STRUCT (type
);
2068 for (i
= 0; i
< type
->num_fields (); ++i
)
2070 /* Static fields can be ignored here. */
2071 if (field_is_static (&type
->field (i
)))
2073 /* If the field has dynamic type, then so does TYPE. */
2074 if (is_dynamic_type_internal (type
->field (i
).type (), 0))
2076 /* If the field is at a fixed offset, then it is not
2078 if (TYPE_FIELD_LOC_KIND (type
, i
) != FIELD_LOC_KIND_DWARF_BLOCK
)
2080 /* Do not consider C++ virtual base types to be dynamic
2081 due to the field's offset being dynamic; these are
2082 handled via other means. */
2083 if (is_cplus
&& BASETYPE_VIA_VIRTUAL (type
, i
))
2094 /* See gdbtypes.h. */
2097 is_dynamic_type (struct type
*type
)
2099 return is_dynamic_type_internal (type
, 1);
2102 static struct type
*resolve_dynamic_type_internal
2103 (struct type
*type
, struct property_addr_info
*addr_stack
, int top_level
);
2105 /* Given a dynamic range type (dyn_range_type) and a stack of
2106 struct property_addr_info elements, return a static version
2109 static struct type
*
2110 resolve_dynamic_range (struct type
*dyn_range_type
,
2111 struct property_addr_info
*addr_stack
)
2114 struct type
*static_range_type
, *static_target_type
;
2115 struct dynamic_prop low_bound
, high_bound
, stride
;
2117 gdb_assert (dyn_range_type
->code () == TYPE_CODE_RANGE
);
2119 const struct dynamic_prop
*prop
= &dyn_range_type
->bounds ()->low
;
2120 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2121 low_bound
.set_const_val (value
);
2123 low_bound
.set_undefined ();
2125 prop
= &dyn_range_type
->bounds ()->high
;
2126 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2128 high_bound
.set_const_val (value
);
2130 if (dyn_range_type
->bounds ()->flag_upper_bound_is_count
)
2131 high_bound
.set_const_val
2132 (low_bound
.const_val () + high_bound
.const_val () - 1);
2135 high_bound
.set_undefined ();
2137 bool byte_stride_p
= dyn_range_type
->bounds ()->flag_is_byte_stride
;
2138 prop
= &dyn_range_type
->bounds ()->stride
;
2139 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2141 stride
.set_const_val (value
);
2143 /* If we have a bit stride that is not an exact number of bytes then
2144 I really don't think this is going to work with current GDB, the
2145 array indexing code in GDB seems to be pretty heavily tied to byte
2146 offsets right now. Assuming 8 bits in a byte. */
2147 struct gdbarch
*gdbarch
= get_type_arch (dyn_range_type
);
2148 int unit_size
= gdbarch_addressable_memory_unit_size (gdbarch
);
2149 if (!byte_stride_p
&& (value
% (unit_size
* 8)) != 0)
2150 error (_("bit strides that are not a multiple of the byte size "
2151 "are currently not supported"));
2155 stride
.set_undefined ();
2156 byte_stride_p
= true;
2160 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type
),
2162 LONGEST bias
= dyn_range_type
->bounds ()->bias
;
2163 static_range_type
= create_range_type_with_stride
2164 (copy_type (dyn_range_type
), static_target_type
,
2165 &low_bound
, &high_bound
, bias
, &stride
, byte_stride_p
);
2166 static_range_type
->bounds ()->flag_bound_evaluated
= 1;
2167 return static_range_type
;
2170 /* Resolves dynamic bound values of an array or string type TYPE to static
2171 ones. ADDR_STACK is a stack of struct property_addr_info to be used if
2172 needed during the dynamic resolution. */
2174 static struct type
*
2175 resolve_dynamic_array_or_string (struct type
*type
,
2176 struct property_addr_info
*addr_stack
)
2179 struct type
*elt_type
;
2180 struct type
*range_type
;
2181 struct type
*ary_dim
;
2182 struct dynamic_prop
*prop
;
2183 unsigned int bit_stride
= 0;
2185 /* For dynamic type resolution strings can be treated like arrays of
2187 gdb_assert (type
->code () == TYPE_CODE_ARRAY
2188 || type
->code () == TYPE_CODE_STRING
);
2190 type
= copy_type (type
);
2193 range_type
= check_typedef (elt_type
->index_type ());
2194 range_type
= resolve_dynamic_range (range_type
, addr_stack
);
2196 /* Resolve allocated/associated here before creating a new array type, which
2197 will update the length of the array accordingly. */
2198 prop
= TYPE_ALLOCATED_PROP (type
);
2199 if (prop
!= NULL
&& dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2200 prop
->set_const_val (value
);
2202 prop
= TYPE_ASSOCIATED_PROP (type
);
2203 if (prop
!= NULL
&& dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2204 prop
->set_const_val (value
);
2206 ary_dim
= check_typedef (TYPE_TARGET_TYPE (elt_type
));
2208 if (ary_dim
!= NULL
&& ary_dim
->code () == TYPE_CODE_ARRAY
)
2209 elt_type
= resolve_dynamic_array_or_string (ary_dim
, addr_stack
);
2211 elt_type
= TYPE_TARGET_TYPE (type
);
2213 prop
= type
->dyn_prop (DYN_PROP_BYTE_STRIDE
);
2216 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2218 type
->remove_dyn_prop (DYN_PROP_BYTE_STRIDE
);
2219 bit_stride
= (unsigned int) (value
* 8);
2223 /* Could be a bug in our code, but it could also happen
2224 if the DWARF info is not correct. Issue a warning,
2225 and assume no byte/bit stride (leave bit_stride = 0). */
2226 warning (_("cannot determine array stride for type %s"),
2227 type
->name () ? type
->name () : "<no name>");
2231 bit_stride
= TYPE_FIELD_BITSIZE (type
, 0);
2233 return create_array_type_with_stride (type
, elt_type
, range_type
, NULL
,
2237 /* Resolve dynamic bounds of members of the union TYPE to static
2238 bounds. ADDR_STACK is a stack of struct property_addr_info
2239 to be used if needed during the dynamic resolution. */
2241 static struct type
*
2242 resolve_dynamic_union (struct type
*type
,
2243 struct property_addr_info
*addr_stack
)
2245 struct type
*resolved_type
;
2247 unsigned int max_len
= 0;
2249 gdb_assert (type
->code () == TYPE_CODE_UNION
);
2251 resolved_type
= copy_type (type
);
2252 resolved_type
->set_fields
2254 TYPE_ALLOC (resolved_type
,
2255 resolved_type
->num_fields () * sizeof (struct field
)));
2256 memcpy (resolved_type
->fields (),
2258 resolved_type
->num_fields () * sizeof (struct field
));
2259 for (i
= 0; i
< resolved_type
->num_fields (); ++i
)
2263 if (field_is_static (&type
->field (i
)))
2266 t
= resolve_dynamic_type_internal (resolved_type
->field (i
).type (),
2268 resolved_type
->field (i
).set_type (t
);
2270 struct type
*real_type
= check_typedef (t
);
2271 if (TYPE_LENGTH (real_type
) > max_len
)
2272 max_len
= TYPE_LENGTH (real_type
);
2275 TYPE_LENGTH (resolved_type
) = max_len
;
2276 return resolved_type
;
2279 /* See gdbtypes.h. */
2282 variant::matches (ULONGEST value
, bool is_unsigned
) const
2284 for (const discriminant_range
&range
: discriminants
)
2285 if (range
.contains (value
, is_unsigned
))
2291 compute_variant_fields_inner (struct type
*type
,
2292 struct property_addr_info
*addr_stack
,
2293 const variant_part
&part
,
2294 std::vector
<bool> &flags
);
2296 /* A helper function to determine which variant fields will be active.
2297 This handles both the variant's direct fields, and any variant
2298 parts embedded in this variant. TYPE is the type we're examining.
2299 ADDR_STACK holds information about the concrete object. VARIANT is
2300 the current variant to be handled. FLAGS is where the results are
2301 stored -- this function sets the Nth element in FLAGS if the
2302 corresponding field is enabled. ENABLED is whether this variant is
2306 compute_variant_fields_recurse (struct type
*type
,
2307 struct property_addr_info
*addr_stack
,
2308 const variant
&variant
,
2309 std::vector
<bool> &flags
,
2312 for (int field
= variant
.first_field
; field
< variant
.last_field
; ++field
)
2313 flags
[field
] = enabled
;
2315 for (const variant_part
&new_part
: variant
.parts
)
2318 compute_variant_fields_inner (type
, addr_stack
, new_part
, flags
);
2321 for (const auto &sub_variant
: new_part
.variants
)
2322 compute_variant_fields_recurse (type
, addr_stack
, sub_variant
,
2328 /* A helper function to determine which variant fields will be active.
2329 This evaluates the discriminant, decides which variant (if any) is
2330 active, and then updates FLAGS to reflect which fields should be
2331 available. TYPE is the type we're examining. ADDR_STACK holds
2332 information about the concrete object. VARIANT is the current
2333 variant to be handled. FLAGS is where the results are stored --
2334 this function sets the Nth element in FLAGS if the corresponding
2335 field is enabled. */
2338 compute_variant_fields_inner (struct type
*type
,
2339 struct property_addr_info
*addr_stack
,
2340 const variant_part
&part
,
2341 std::vector
<bool> &flags
)
2343 /* Evaluate the discriminant. */
2344 gdb::optional
<ULONGEST
> discr_value
;
2345 if (part
.discriminant_index
!= -1)
2347 int idx
= part
.discriminant_index
;
2349 if (TYPE_FIELD_LOC_KIND (type
, idx
) != FIELD_LOC_KIND_BITPOS
)
2350 error (_("Cannot determine struct field location"
2351 " (invalid location kind)"));
2353 if (addr_stack
->valaddr
.data () != NULL
)
2354 discr_value
= unpack_field_as_long (type
, addr_stack
->valaddr
.data (),
2358 CORE_ADDR addr
= (addr_stack
->addr
2359 + (TYPE_FIELD_BITPOS (type
, idx
)
2360 / TARGET_CHAR_BIT
));
2362 LONGEST bitsize
= TYPE_FIELD_BITSIZE (type
, idx
);
2363 LONGEST size
= bitsize
/ 8;
2365 size
= TYPE_LENGTH (type
->field (idx
).type ());
2367 gdb_byte bits
[sizeof (ULONGEST
)];
2368 read_memory (addr
, bits
, size
);
2370 LONGEST bitpos
= (TYPE_FIELD_BITPOS (type
, idx
)
2373 discr_value
= unpack_bits_as_long (type
->field (idx
).type (),
2374 bits
, bitpos
, bitsize
);
2378 /* Go through each variant and see which applies. */
2379 const variant
*default_variant
= nullptr;
2380 const variant
*applied_variant
= nullptr;
2381 for (const auto &variant
: part
.variants
)
2383 if (variant
.is_default ())
2384 default_variant
= &variant
;
2385 else if (discr_value
.has_value ()
2386 && variant
.matches (*discr_value
, part
.is_unsigned
))
2388 applied_variant
= &variant
;
2392 if (applied_variant
== nullptr)
2393 applied_variant
= default_variant
;
2395 for (const auto &variant
: part
.variants
)
2396 compute_variant_fields_recurse (type
, addr_stack
, variant
,
2397 flags
, applied_variant
== &variant
);
2400 /* Determine which variant fields are available in TYPE. The enabled
2401 fields are stored in RESOLVED_TYPE. ADDR_STACK holds information
2402 about the concrete object. PARTS describes the top-level variant
2403 parts for this type. */
2406 compute_variant_fields (struct type
*type
,
2407 struct type
*resolved_type
,
2408 struct property_addr_info
*addr_stack
,
2409 const gdb::array_view
<variant_part
> &parts
)
2411 /* Assume all fields are included by default. */
2412 std::vector
<bool> flags (resolved_type
->num_fields (), true);
2414 /* Now disable fields based on the variants that control them. */
2415 for (const auto &part
: parts
)
2416 compute_variant_fields_inner (type
, addr_stack
, part
, flags
);
2418 resolved_type
->set_num_fields
2419 (std::count (flags
.begin (), flags
.end (), true));
2420 resolved_type
->set_fields
2422 TYPE_ALLOC (resolved_type
,
2423 resolved_type
->num_fields () * sizeof (struct field
)));
2426 for (int i
= 0; i
< type
->num_fields (); ++i
)
2431 resolved_type
->field (out
) = type
->field (i
);
2436 /* Resolve dynamic bounds of members of the struct TYPE to static
2437 bounds. ADDR_STACK is a stack of struct property_addr_info to
2438 be used if needed during the dynamic resolution. */
2440 static struct type
*
2441 resolve_dynamic_struct (struct type
*type
,
2442 struct property_addr_info
*addr_stack
)
2444 struct type
*resolved_type
;
2446 unsigned resolved_type_bit_length
= 0;
2448 gdb_assert (type
->code () == TYPE_CODE_STRUCT
);
2449 gdb_assert (type
->num_fields () > 0);
2451 resolved_type
= copy_type (type
);
2453 dynamic_prop
*variant_prop
= resolved_type
->dyn_prop (DYN_PROP_VARIANT_PARTS
);
2454 if (variant_prop
!= nullptr && variant_prop
->kind () == PROP_VARIANT_PARTS
)
2456 compute_variant_fields (type
, resolved_type
, addr_stack
,
2457 *variant_prop
->variant_parts ());
2458 /* We want to leave the property attached, so that the Rust code
2459 can tell whether the type was originally an enum. */
2460 variant_prop
->set_original_type (type
);
2464 resolved_type
->set_fields
2466 TYPE_ALLOC (resolved_type
,
2467 resolved_type
->num_fields () * sizeof (struct field
)));
2468 memcpy (resolved_type
->fields (),
2470 resolved_type
->num_fields () * sizeof (struct field
));
2473 for (i
= 0; i
< resolved_type
->num_fields (); ++i
)
2475 unsigned new_bit_length
;
2476 struct property_addr_info pinfo
;
2478 if (field_is_static (&resolved_type
->field (i
)))
2481 if (TYPE_FIELD_LOC_KIND (resolved_type
, i
) == FIELD_LOC_KIND_DWARF_BLOCK
)
2483 struct dwarf2_property_baton baton
;
2485 = lookup_pointer_type (resolved_type
->field (i
).type ());
2486 baton
.locexpr
= *TYPE_FIELD_DWARF_BLOCK (resolved_type
, i
);
2488 struct dynamic_prop prop
;
2489 prop
.set_locexpr (&baton
);
2492 if (dwarf2_evaluate_property (&prop
, nullptr, addr_stack
, &addr
,
2494 SET_FIELD_BITPOS (resolved_type
->field (i
),
2495 TARGET_CHAR_BIT
* (addr
- addr_stack
->addr
));
2498 /* As we know this field is not a static field, the field's
2499 field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
2500 this is the case, but only trigger a simple error rather
2501 than an internal error if that fails. While failing
2502 that verification indicates a bug in our code, the error
2503 is not severe enough to suggest to the user he stops
2504 his debugging session because of it. */
2505 if (TYPE_FIELD_LOC_KIND (resolved_type
, i
) != FIELD_LOC_KIND_BITPOS
)
2506 error (_("Cannot determine struct field location"
2507 " (invalid location kind)"));
2509 pinfo
.type
= check_typedef (resolved_type
->field (i
).type ());
2510 pinfo
.valaddr
= addr_stack
->valaddr
;
2513 + (TYPE_FIELD_BITPOS (resolved_type
, i
) / TARGET_CHAR_BIT
));
2514 pinfo
.next
= addr_stack
;
2516 resolved_type
->field (i
).set_type
2517 (resolve_dynamic_type_internal (resolved_type
->field (i
).type (),
2519 gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type
, i
)
2520 == FIELD_LOC_KIND_BITPOS
);
2522 new_bit_length
= TYPE_FIELD_BITPOS (resolved_type
, i
);
2523 if (TYPE_FIELD_BITSIZE (resolved_type
, i
) != 0)
2524 new_bit_length
+= TYPE_FIELD_BITSIZE (resolved_type
, i
);
2527 struct type
*real_type
2528 = check_typedef (resolved_type
->field (i
).type ());
2530 new_bit_length
+= (TYPE_LENGTH (real_type
) * TARGET_CHAR_BIT
);
2533 /* Normally, we would use the position and size of the last field
2534 to determine the size of the enclosing structure. But GCC seems
2535 to be encoding the position of some fields incorrectly when
2536 the struct contains a dynamic field that is not placed last.
2537 So we compute the struct size based on the field that has
2538 the highest position + size - probably the best we can do. */
2539 if (new_bit_length
> resolved_type_bit_length
)
2540 resolved_type_bit_length
= new_bit_length
;
2543 /* The length of a type won't change for fortran, but it does for C and Ada.
2544 For fortran the size of dynamic fields might change over time but not the
2545 type length of the structure. If we adapt it, we run into problems
2546 when calculating the element offset for arrays of structs. */
2547 if (current_language
->la_language
!= language_fortran
)
2548 TYPE_LENGTH (resolved_type
)
2549 = (resolved_type_bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2551 /* The Ada language uses this field as a cache for static fixed types: reset
2552 it as RESOLVED_TYPE must have its own static fixed type. */
2553 TYPE_TARGET_TYPE (resolved_type
) = NULL
;
2555 return resolved_type
;
2558 /* Worker for resolved_dynamic_type. */
2560 static struct type
*
2561 resolve_dynamic_type_internal (struct type
*type
,
2562 struct property_addr_info
*addr_stack
,
2565 struct type
*real_type
= check_typedef (type
);
2566 struct type
*resolved_type
= nullptr;
2567 struct dynamic_prop
*prop
;
2570 if (!is_dynamic_type_internal (real_type
, top_level
))
2573 gdb::optional
<CORE_ADDR
> type_length
;
2574 prop
= TYPE_DYNAMIC_LENGTH (type
);
2576 && dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2577 type_length
= value
;
2579 if (type
->code () == TYPE_CODE_TYPEDEF
)
2581 resolved_type
= copy_type (type
);
2582 TYPE_TARGET_TYPE (resolved_type
)
2583 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type
), addr_stack
,
2588 /* Before trying to resolve TYPE, make sure it is not a stub. */
2591 switch (type
->code ())
2595 struct property_addr_info pinfo
;
2597 pinfo
.type
= check_typedef (TYPE_TARGET_TYPE (type
));
2599 if (addr_stack
->valaddr
.data () != NULL
)
2600 pinfo
.addr
= extract_typed_address (addr_stack
->valaddr
.data (),
2603 pinfo
.addr
= read_memory_typed_address (addr_stack
->addr
, type
);
2604 pinfo
.next
= addr_stack
;
2606 resolved_type
= copy_type (type
);
2607 TYPE_TARGET_TYPE (resolved_type
)
2608 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type
),
2613 case TYPE_CODE_STRING
:
2614 /* Strings are very much like an array of characters, and can be
2615 treated as one here. */
2616 case TYPE_CODE_ARRAY
:
2617 resolved_type
= resolve_dynamic_array_or_string (type
, addr_stack
);
2620 case TYPE_CODE_RANGE
:
2621 resolved_type
= resolve_dynamic_range (type
, addr_stack
);
2624 case TYPE_CODE_UNION
:
2625 resolved_type
= resolve_dynamic_union (type
, addr_stack
);
2628 case TYPE_CODE_STRUCT
:
2629 resolved_type
= resolve_dynamic_struct (type
, addr_stack
);
2634 if (resolved_type
== nullptr)
2637 if (type_length
.has_value ())
2639 TYPE_LENGTH (resolved_type
) = *type_length
;
2640 resolved_type
->remove_dyn_prop (DYN_PROP_BYTE_SIZE
);
2643 /* Resolve data_location attribute. */
2644 prop
= TYPE_DATA_LOCATION (resolved_type
);
2646 && dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2647 prop
->set_const_val (value
);
2649 return resolved_type
;
2652 /* See gdbtypes.h */
2655 resolve_dynamic_type (struct type
*type
,
2656 gdb::array_view
<const gdb_byte
> valaddr
,
2659 struct property_addr_info pinfo
2660 = {check_typedef (type
), valaddr
, addr
, NULL
};
2662 return resolve_dynamic_type_internal (type
, &pinfo
, 1);
2665 /* See gdbtypes.h */
2668 type::dyn_prop (dynamic_prop_node_kind prop_kind
) const
2670 dynamic_prop_list
*node
= this->main_type
->dyn_prop_list
;
2672 while (node
!= NULL
)
2674 if (node
->prop_kind
== prop_kind
)
2681 /* See gdbtypes.h */
2684 type::add_dyn_prop (dynamic_prop_node_kind prop_kind
, dynamic_prop prop
)
2686 struct dynamic_prop_list
*temp
;
2688 gdb_assert (TYPE_OBJFILE_OWNED (this));
2690 temp
= XOBNEW (&TYPE_OBJFILE (this)->objfile_obstack
,
2691 struct dynamic_prop_list
);
2692 temp
->prop_kind
= prop_kind
;
2694 temp
->next
= this->main_type
->dyn_prop_list
;
2696 this->main_type
->dyn_prop_list
= temp
;
2699 /* See gdbtypes.h. */
2702 type::remove_dyn_prop (dynamic_prop_node_kind kind
)
2704 struct dynamic_prop_list
*prev_node
, *curr_node
;
2706 curr_node
= this->main_type
->dyn_prop_list
;
2709 while (NULL
!= curr_node
)
2711 if (curr_node
->prop_kind
== kind
)
2713 /* Update the linked list but don't free anything.
2714 The property was allocated on objstack and it is not known
2715 if we are on top of it. Nevertheless, everything is released
2716 when the complete objstack is freed. */
2717 if (NULL
== prev_node
)
2718 this->main_type
->dyn_prop_list
= curr_node
->next
;
2720 prev_node
->next
= curr_node
->next
;
2725 prev_node
= curr_node
;
2726 curr_node
= curr_node
->next
;
2730 /* Find the real type of TYPE. This function returns the real type,
2731 after removing all layers of typedefs, and completing opaque or stub
2732 types. Completion changes the TYPE argument, but stripping of
2735 Instance flags (e.g. const/volatile) are preserved as typedefs are
2736 stripped. If necessary a new qualified form of the underlying type
2739 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
2740 not been computed and we're either in the middle of reading symbols, or
2741 there was no name for the typedef in the debug info.
2743 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
2744 QUITs in the symbol reading code can also throw.
2745 Thus this function can throw an exception.
2747 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
2750 If this is a stubbed struct (i.e. declared as struct foo *), see if
2751 we can find a full definition in some other file. If so, copy this
2752 definition, so we can use it in future. There used to be a comment
2753 (but not any code) that if we don't find a full definition, we'd
2754 set a flag so we don't spend time in the future checking the same
2755 type. That would be a mistake, though--we might load in more
2756 symbols which contain a full definition for the type. */
2759 check_typedef (struct type
*type
)
2761 struct type
*orig_type
= type
;
2765 /* While we're removing typedefs, we don't want to lose qualifiers.
2766 E.g., const/volatile. */
2767 type_instance_flags instance_flags
= type
->instance_flags ();
2769 while (type
->code () == TYPE_CODE_TYPEDEF
)
2771 if (!TYPE_TARGET_TYPE (type
))
2776 /* It is dangerous to call lookup_symbol if we are currently
2777 reading a symtab. Infinite recursion is one danger. */
2778 if (currently_reading_symtab
)
2779 return make_qualified_type (type
, instance_flags
, NULL
);
2781 name
= type
->name ();
2782 /* FIXME: shouldn't we look in STRUCT_DOMAIN and/or
2783 VAR_DOMAIN as appropriate? */
2786 stub_noname_complaint ();
2787 return make_qualified_type (type
, instance_flags
, NULL
);
2789 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0).symbol
;
2791 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
2792 else /* TYPE_CODE_UNDEF */
2793 TYPE_TARGET_TYPE (type
) = alloc_type_arch (get_type_arch (type
));
2795 type
= TYPE_TARGET_TYPE (type
);
2797 /* Preserve the instance flags as we traverse down the typedef chain.
2799 Handling address spaces/classes is nasty, what do we do if there's a
2801 E.g., what if an outer typedef marks the type as class_1 and an inner
2802 typedef marks the type as class_2?
2803 This is the wrong place to do such error checking. We leave it to
2804 the code that created the typedef in the first place to flag the
2805 error. We just pick the outer address space (akin to letting the
2806 outer cast in a chain of casting win), instead of assuming
2807 "it can't happen". */
2809 const type_instance_flags ALL_SPACES
2810 = (TYPE_INSTANCE_FLAG_CODE_SPACE
2811 | TYPE_INSTANCE_FLAG_DATA_SPACE
);
2812 const type_instance_flags ALL_CLASSES
2813 = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
;
2815 type_instance_flags new_instance_flags
= type
->instance_flags ();
2817 /* Treat code vs data spaces and address classes separately. */
2818 if ((instance_flags
& ALL_SPACES
) != 0)
2819 new_instance_flags
&= ~ALL_SPACES
;
2820 if ((instance_flags
& ALL_CLASSES
) != 0)
2821 new_instance_flags
&= ~ALL_CLASSES
;
2823 instance_flags
|= new_instance_flags
;
2827 /* If this is a struct/class/union with no fields, then check
2828 whether a full definition exists somewhere else. This is for
2829 systems where a type definition with no fields is issued for such
2830 types, instead of identifying them as stub types in the first
2833 if (TYPE_IS_OPAQUE (type
)
2834 && opaque_type_resolution
2835 && !currently_reading_symtab
)
2837 const char *name
= type
->name ();
2838 struct type
*newtype
;
2842 stub_noname_complaint ();
2843 return make_qualified_type (type
, instance_flags
, NULL
);
2845 newtype
= lookup_transparent_type (name
);
2849 /* If the resolved type and the stub are in the same
2850 objfile, then replace the stub type with the real deal.
2851 But if they're in separate objfiles, leave the stub
2852 alone; we'll just look up the transparent type every time
2853 we call check_typedef. We can't create pointers between
2854 types allocated to different objfiles, since they may
2855 have different lifetimes. Trying to copy NEWTYPE over to
2856 TYPE's objfile is pointless, too, since you'll have to
2857 move over any other types NEWTYPE refers to, which could
2858 be an unbounded amount of stuff. */
2859 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
2860 type
= make_qualified_type (newtype
, type
->instance_flags (), type
);
2865 /* Otherwise, rely on the stub flag being set for opaque/stubbed
2867 else if (type
->is_stub () && !currently_reading_symtab
)
2869 const char *name
= type
->name ();
2870 /* FIXME: shouldn't we look in STRUCT_DOMAIN and/or VAR_DOMAIN
2876 stub_noname_complaint ();
2877 return make_qualified_type (type
, instance_flags
, NULL
);
2879 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0).symbol
;
2882 /* Same as above for opaque types, we can replace the stub
2883 with the complete type only if they are in the same
2885 if (TYPE_OBJFILE (SYMBOL_TYPE (sym
)) == TYPE_OBJFILE (type
))
2886 type
= make_qualified_type (SYMBOL_TYPE (sym
),
2887 type
->instance_flags (), type
);
2889 type
= SYMBOL_TYPE (sym
);
2893 if (type
->target_is_stub ())
2895 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
2897 if (target_type
->is_stub () || target_type
->target_is_stub ())
2899 /* Nothing we can do. */
2901 else if (type
->code () == TYPE_CODE_RANGE
)
2903 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
2904 type
->set_target_is_stub (false);
2906 else if (type
->code () == TYPE_CODE_ARRAY
2907 && update_static_array_size (type
))
2908 type
->set_target_is_stub (false);
2911 type
= make_qualified_type (type
, instance_flags
, NULL
);
2913 /* Cache TYPE_LENGTH for future use. */
2914 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
2919 /* Parse a type expression in the string [P..P+LENGTH). If an error
2920 occurs, silently return a void type. */
2922 static struct type
*
2923 safe_parse_type (struct gdbarch
*gdbarch
, char *p
, int length
)
2925 struct ui_file
*saved_gdb_stderr
;
2926 struct type
*type
= NULL
; /* Initialize to keep gcc happy. */
2928 /* Suppress error messages. */
2929 saved_gdb_stderr
= gdb_stderr
;
2930 gdb_stderr
= &null_stream
;
2932 /* Call parse_and_eval_type() without fear of longjmp()s. */
2935 type
= parse_and_eval_type (p
, length
);
2937 catch (const gdb_exception_error
&except
)
2939 type
= builtin_type (gdbarch
)->builtin_void
;
2942 /* Stop suppressing error messages. */
2943 gdb_stderr
= saved_gdb_stderr
;
2948 /* Ugly hack to convert method stubs into method types.
2950 He ain't kiddin'. This demangles the name of the method into a
2951 string including argument types, parses out each argument type,
2952 generates a string casting a zero to that type, evaluates the
2953 string, and stuffs the resulting type into an argtype vector!!!
2954 Then it knows the type of the whole function (including argument
2955 types for overloading), which info used to be in the stab's but was
2956 removed to hack back the space required for them. */
2959 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
2961 struct gdbarch
*gdbarch
= get_type_arch (type
);
2963 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
2964 char *demangled_name
= gdb_demangle (mangled_name
,
2965 DMGL_PARAMS
| DMGL_ANSI
);
2966 char *argtypetext
, *p
;
2967 int depth
= 0, argcount
= 1;
2968 struct field
*argtypes
;
2971 /* Make sure we got back a function string that we can use. */
2973 p
= strchr (demangled_name
, '(');
2977 if (demangled_name
== NULL
|| p
== NULL
)
2978 error (_("Internal: Cannot demangle mangled name `%s'."),
2981 /* Now, read in the parameters that define this type. */
2986 if (*p
== '(' || *p
== '<')
2990 else if (*p
== ')' || *p
== '>')
2994 else if (*p
== ',' && depth
== 0)
3002 /* If we read one argument and it was ``void'', don't count it. */
3003 if (startswith (argtypetext
, "(void)"))
3006 /* We need one extra slot, for the THIS pointer. */
3008 argtypes
= (struct field
*)
3009 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
3012 /* Add THIS pointer for non-static methods. */
3013 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
3014 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
3018 argtypes
[0].set_type (lookup_pointer_type (type
));
3022 if (*p
!= ')') /* () means no args, skip while. */
3027 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
3029 /* Avoid parsing of ellipsis, they will be handled below.
3030 Also avoid ``void'' as above. */
3031 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
3032 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
3034 argtypes
[argcount
].set_type
3035 (safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
));
3038 argtypetext
= p
+ 1;
3041 if (*p
== '(' || *p
== '<')
3045 else if (*p
== ')' || *p
== '>')
3054 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
3056 /* Now update the old "stub" type into a real type. */
3057 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
3058 /* MTYPE may currently be a function (TYPE_CODE_FUNC).
3059 We want a method (TYPE_CODE_METHOD). */
3060 smash_to_method_type (mtype
, type
, TYPE_TARGET_TYPE (mtype
),
3061 argtypes
, argcount
, p
[-2] == '.');
3062 mtype
->set_is_stub (false);
3063 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
3065 xfree (demangled_name
);
3068 /* This is the external interface to check_stub_method, above. This
3069 function unstubs all of the signatures for TYPE's METHOD_ID method
3070 name. After calling this function TYPE_FN_FIELD_STUB will be
3071 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
3074 This function unfortunately can not die until stabs do. */
3077 check_stub_method_group (struct type
*type
, int method_id
)
3079 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
3080 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
3082 for (int j
= 0; j
< len
; j
++)
3084 if (TYPE_FN_FIELD_STUB (f
, j
))
3085 check_stub_method (type
, method_id
, j
);
3089 /* Ensure it is in .rodata (if available) by working around GCC PR 44690. */
3090 const struct cplus_struct_type cplus_struct_default
= { };
3093 allocate_cplus_struct_type (struct type
*type
)
3095 if (HAVE_CPLUS_STRUCT (type
))
3096 /* Structure was already allocated. Nothing more to do. */
3099 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_CPLUS_STUFF
;
3100 TYPE_RAW_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
3101 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
3102 *(TYPE_RAW_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
3103 set_type_vptr_fieldno (type
, -1);
3106 const struct gnat_aux_type gnat_aux_default
=
3109 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
3110 and allocate the associated gnat-specific data. The gnat-specific
3111 data is also initialized to gnat_aux_default. */
3114 allocate_gnat_aux_type (struct type
*type
)
3116 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_GNAT_STUFF
;
3117 TYPE_GNAT_SPECIFIC (type
) = (struct gnat_aux_type
*)
3118 TYPE_ALLOC (type
, sizeof (struct gnat_aux_type
));
3119 *(TYPE_GNAT_SPECIFIC (type
)) = gnat_aux_default
;
3122 /* Helper function to initialize a newly allocated type. Set type code
3123 to CODE and initialize the type-specific fields accordingly. */
3126 set_type_code (struct type
*type
, enum type_code code
)
3128 type
->set_code (code
);
3132 case TYPE_CODE_STRUCT
:
3133 case TYPE_CODE_UNION
:
3134 case TYPE_CODE_NAMESPACE
:
3135 INIT_CPLUS_SPECIFIC (type
);
3138 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_FLOATFORMAT
;
3140 case TYPE_CODE_FUNC
:
3141 INIT_FUNC_SPECIFIC (type
);
3143 case TYPE_CODE_FIXED_POINT
:
3144 INIT_FIXED_POINT_SPECIFIC (type
);
3149 /* Helper function to verify floating-point format and size.
3150 BIT is the type size in bits; if BIT equals -1, the size is
3151 determined by the floatformat. Returns size to be used. */
3154 verify_floatformat (int bit
, const struct floatformat
*floatformat
)
3156 gdb_assert (floatformat
!= NULL
);
3159 bit
= floatformat
->totalsize
;
3161 gdb_assert (bit
>= 0);
3162 gdb_assert (bit
>= floatformat
->totalsize
);
3167 /* Return the floating-point format for a floating-point variable of
3170 const struct floatformat
*
3171 floatformat_from_type (const struct type
*type
)
3173 gdb_assert (type
->code () == TYPE_CODE_FLT
);
3174 gdb_assert (TYPE_FLOATFORMAT (type
));
3175 return TYPE_FLOATFORMAT (type
);
3178 /* Helper function to initialize the standard scalar types.
3180 If NAME is non-NULL, then it is used to initialize the type name.
3181 Note that NAME is not copied; it is required to have a lifetime at
3182 least as long as OBJFILE. */
3185 init_type (struct objfile
*objfile
, enum type_code code
, int bit
,
3190 type
= alloc_type (objfile
);
3191 set_type_code (type
, code
);
3192 gdb_assert ((bit
% TARGET_CHAR_BIT
) == 0);
3193 TYPE_LENGTH (type
) = bit
/ TARGET_CHAR_BIT
;
3194 type
->set_name (name
);
3199 /* Allocate a TYPE_CODE_ERROR type structure associated with OBJFILE,
3200 to use with variables that have no debug info. NAME is the type
3203 static struct type
*
3204 init_nodebug_var_type (struct objfile
*objfile
, const char *name
)
3206 return init_type (objfile
, TYPE_CODE_ERROR
, 0, name
);
3209 /* Allocate a TYPE_CODE_INT type structure associated with OBJFILE.
3210 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3211 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3214 init_integer_type (struct objfile
*objfile
,
3215 int bit
, int unsigned_p
, const char *name
)
3219 t
= init_type (objfile
, TYPE_CODE_INT
, bit
, name
);
3221 t
->set_is_unsigned (true);
3223 TYPE_SPECIFIC_FIELD (t
) = TYPE_SPECIFIC_INT
;
3224 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_size
= bit
;
3225 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_offset
= 0;
3230 /* Allocate a TYPE_CODE_CHAR type structure associated with OBJFILE.
3231 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3232 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3235 init_character_type (struct objfile
*objfile
,
3236 int bit
, int unsigned_p
, const char *name
)
3240 t
= init_type (objfile
, TYPE_CODE_CHAR
, bit
, name
);
3242 t
->set_is_unsigned (true);
3247 /* Allocate a TYPE_CODE_BOOL type structure associated with OBJFILE.
3248 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3249 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3252 init_boolean_type (struct objfile
*objfile
,
3253 int bit
, int unsigned_p
, const char *name
)
3257 t
= init_type (objfile
, TYPE_CODE_BOOL
, bit
, name
);
3259 t
->set_is_unsigned (true);
3261 TYPE_SPECIFIC_FIELD (t
) = TYPE_SPECIFIC_INT
;
3262 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_size
= bit
;
3263 TYPE_MAIN_TYPE (t
)->type_specific
.int_stuff
.bit_offset
= 0;
3268 /* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
3269 BIT is the type size in bits; if BIT equals -1, the size is
3270 determined by the floatformat. NAME is the type name. Set the
3271 TYPE_FLOATFORMAT from FLOATFORMATS. BYTE_ORDER is the byte order
3272 to use. If it is BFD_ENDIAN_UNKNOWN (the default), then the byte
3273 order of the objfile's architecture is used. */
3276 init_float_type (struct objfile
*objfile
,
3277 int bit
, const char *name
,
3278 const struct floatformat
**floatformats
,
3279 enum bfd_endian byte_order
)
3281 if (byte_order
== BFD_ENDIAN_UNKNOWN
)
3283 struct gdbarch
*gdbarch
= objfile
->arch ();
3284 byte_order
= gdbarch_byte_order (gdbarch
);
3286 const struct floatformat
*fmt
= floatformats
[byte_order
];
3289 bit
= verify_floatformat (bit
, fmt
);
3290 t
= init_type (objfile
, TYPE_CODE_FLT
, bit
, name
);
3291 TYPE_FLOATFORMAT (t
) = fmt
;
3296 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with OBJFILE.
3297 BIT is the type size in bits. NAME is the type name. */
3300 init_decfloat_type (struct objfile
*objfile
, int bit
, const char *name
)
3304 t
= init_type (objfile
, TYPE_CODE_DECFLOAT
, bit
, name
);
3308 /* Allocate a TYPE_CODE_COMPLEX type structure. NAME is the type
3309 name. TARGET_TYPE is the component type. */
3312 init_complex_type (const char *name
, struct type
*target_type
)
3316 gdb_assert (target_type
->code () == TYPE_CODE_INT
3317 || target_type
->code () == TYPE_CODE_FLT
);
3319 if (TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
== nullptr)
3321 if (name
== nullptr && target_type
->name () != nullptr)
3324 = (char *) TYPE_ALLOC (target_type
,
3325 strlen (target_type
->name ())
3326 + strlen ("_Complex ") + 1);
3327 strcpy (new_name
, "_Complex ");
3328 strcat (new_name
, target_type
->name ());
3332 t
= alloc_type_copy (target_type
);
3333 set_type_code (t
, TYPE_CODE_COMPLEX
);
3334 TYPE_LENGTH (t
) = 2 * TYPE_LENGTH (target_type
);
3337 TYPE_TARGET_TYPE (t
) = target_type
;
3338 TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
= t
;
3341 return TYPE_MAIN_TYPE (target_type
)->flds_bnds
.complex_type
;
3344 /* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE.
3345 BIT is the pointer type size in bits. NAME is the type name.
3346 TARGET_TYPE is the pointer target type. Always sets the pointer type's
3347 TYPE_UNSIGNED flag. */
3350 init_pointer_type (struct objfile
*objfile
,
3351 int bit
, const char *name
, struct type
*target_type
)
3355 t
= init_type (objfile
, TYPE_CODE_PTR
, bit
, name
);
3356 TYPE_TARGET_TYPE (t
) = target_type
;
3357 t
->set_is_unsigned (true);
3361 /* Allocate a TYPE_CODE_FIXED_POINT type structure associated with OBJFILE.
3362 BIT is the pointer type size in bits.
3363 UNSIGNED_P should be nonzero if the type is unsigned.
3364 NAME is the type name. */
3367 init_fixed_point_type (struct objfile
*objfile
,
3368 int bit
, int unsigned_p
, const char *name
)
3372 t
= init_type (objfile
, TYPE_CODE_FIXED_POINT
, bit
, name
);
3374 t
->set_is_unsigned (true);
3379 /* See gdbtypes.h. */
3382 type_raw_align (struct type
*type
)
3384 if (type
->align_log2
!= 0)
3385 return 1 << (type
->align_log2
- 1);
3389 /* See gdbtypes.h. */
3392 type_align (struct type
*type
)
3394 /* Check alignment provided in the debug information. */
3395 unsigned raw_align
= type_raw_align (type
);
3399 /* Allow the architecture to provide an alignment. */
3400 struct gdbarch
*arch
= get_type_arch (type
);
3401 ULONGEST align
= gdbarch_type_align (arch
, type
);
3405 switch (type
->code ())
3408 case TYPE_CODE_FUNC
:
3409 case TYPE_CODE_FLAGS
:
3411 case TYPE_CODE_RANGE
:
3413 case TYPE_CODE_ENUM
:
3415 case TYPE_CODE_RVALUE_REF
:
3416 case TYPE_CODE_CHAR
:
3417 case TYPE_CODE_BOOL
:
3418 case TYPE_CODE_DECFLOAT
:
3419 case TYPE_CODE_METHODPTR
:
3420 case TYPE_CODE_MEMBERPTR
:
3421 align
= type_length_units (check_typedef (type
));
3424 case TYPE_CODE_ARRAY
:
3425 case TYPE_CODE_COMPLEX
:
3426 case TYPE_CODE_TYPEDEF
:
3427 align
= type_align (TYPE_TARGET_TYPE (type
));
3430 case TYPE_CODE_STRUCT
:
3431 case TYPE_CODE_UNION
:
3433 int number_of_non_static_fields
= 0;
3434 for (unsigned i
= 0; i
< type
->num_fields (); ++i
)
3436 if (!field_is_static (&type
->field (i
)))
3438 number_of_non_static_fields
++;
3439 ULONGEST f_align
= type_align (type
->field (i
).type ());
3442 /* Don't pretend we know something we don't. */
3446 if (f_align
> align
)
3450 /* A struct with no fields, or with only static fields has an
3452 if (number_of_non_static_fields
== 0)
3458 case TYPE_CODE_STRING
:
3459 /* Not sure what to do here, and these can't appear in C or C++
3463 case TYPE_CODE_VOID
:
3467 case TYPE_CODE_ERROR
:
3468 case TYPE_CODE_METHOD
:
3473 if ((align
& (align
- 1)) != 0)
3475 /* Not a power of 2, so pass. */
3482 /* See gdbtypes.h. */
3485 set_type_align (struct type
*type
, ULONGEST align
)
3487 /* Must be a power of 2. Zero is ok. */
3488 gdb_assert ((align
& (align
- 1)) == 0);
3490 unsigned result
= 0;
3497 if (result
>= (1 << TYPE_ALIGN_BITS
))
3500 type
->align_log2
= result
;
3505 /* Queries on types. */
3508 can_dereference (struct type
*t
)
3510 /* FIXME: Should we return true for references as well as
3512 t
= check_typedef (t
);
3515 && t
->code () == TYPE_CODE_PTR
3516 && TYPE_TARGET_TYPE (t
)->code () != TYPE_CODE_VOID
);
3520 is_integral_type (struct type
*t
)
3522 t
= check_typedef (t
);
3525 && !is_fixed_point_type (t
)
3526 && ((t
->code () == TYPE_CODE_INT
)
3527 || (t
->code () == TYPE_CODE_ENUM
)
3528 || (t
->code () == TYPE_CODE_FLAGS
)
3529 || (t
->code () == TYPE_CODE_CHAR
)
3530 || (t
->code () == TYPE_CODE_RANGE
)
3531 || (t
->code () == TYPE_CODE_BOOL
)));
3535 is_floating_type (struct type
*t
)
3537 t
= check_typedef (t
);
3540 && ((t
->code () == TYPE_CODE_FLT
)
3541 || (t
->code () == TYPE_CODE_DECFLOAT
)));
3544 /* Return true if TYPE is scalar. */
3547 is_scalar_type (struct type
*type
)
3549 type
= check_typedef (type
);
3551 if (is_fixed_point_type (type
))
3552 return 0; /* Implemented as a scalar, but more like a floating point. */
3554 switch (type
->code ())
3556 case TYPE_CODE_ARRAY
:
3557 case TYPE_CODE_STRUCT
:
3558 case TYPE_CODE_UNION
:
3560 case TYPE_CODE_STRING
:
3567 /* Return true if T is scalar, or a composite type which in practice has
3568 the memory layout of a scalar type. E.g., an array or struct with only
3569 one scalar element inside it, or a union with only scalar elements. */
3572 is_scalar_type_recursive (struct type
*t
)
3574 t
= check_typedef (t
);
3576 if (is_scalar_type (t
))
3578 /* Are we dealing with an array or string of known dimensions? */
3579 else if ((t
->code () == TYPE_CODE_ARRAY
3580 || t
->code () == TYPE_CODE_STRING
) && t
->num_fields () == 1
3581 && t
->index_type ()->code () == TYPE_CODE_RANGE
)
3583 LONGEST low_bound
, high_bound
;
3584 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (t
));
3586 get_discrete_bounds (t
->index_type (), &low_bound
, &high_bound
);
3588 return high_bound
== low_bound
&& is_scalar_type_recursive (elt_type
);
3590 /* Are we dealing with a struct with one element? */
3591 else if (t
->code () == TYPE_CODE_STRUCT
&& t
->num_fields () == 1)
3592 return is_scalar_type_recursive (t
->field (0).type ());
3593 else if (t
->code () == TYPE_CODE_UNION
)
3595 int i
, n
= t
->num_fields ();
3597 /* If all elements of the union are scalar, then the union is scalar. */
3598 for (i
= 0; i
< n
; i
++)
3599 if (!is_scalar_type_recursive (t
->field (i
).type ()))
3608 /* Return true is T is a class or a union. False otherwise. */
3611 class_or_union_p (const struct type
*t
)
3613 return (t
->code () == TYPE_CODE_STRUCT
3614 || t
->code () == TYPE_CODE_UNION
);
3617 /* A helper function which returns true if types A and B represent the
3618 "same" class type. This is true if the types have the same main
3619 type, or the same name. */
3622 class_types_same_p (const struct type
*a
, const struct type
*b
)
3624 return (TYPE_MAIN_TYPE (a
) == TYPE_MAIN_TYPE (b
)
3625 || (a
->name () && b
->name ()
3626 && !strcmp (a
->name (), b
->name ())));
3629 /* If BASE is an ancestor of DCLASS return the distance between them.
3630 otherwise return -1;
3634 class B: public A {};
3635 class C: public B {};
3638 distance_to_ancestor (A, A, 0) = 0
3639 distance_to_ancestor (A, B, 0) = 1
3640 distance_to_ancestor (A, C, 0) = 2
3641 distance_to_ancestor (A, D, 0) = 3
3643 If PUBLIC is 1 then only public ancestors are considered,
3644 and the function returns the distance only if BASE is a public ancestor
3648 distance_to_ancestor (A, D, 1) = -1. */
3651 distance_to_ancestor (struct type
*base
, struct type
*dclass
, int is_public
)
3656 base
= check_typedef (base
);
3657 dclass
= check_typedef (dclass
);
3659 if (class_types_same_p (base
, dclass
))
3662 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
3664 if (is_public
&& ! BASETYPE_VIA_PUBLIC (dclass
, i
))
3667 d
= distance_to_ancestor (base
, TYPE_BASECLASS (dclass
, i
), is_public
);
3675 /* Check whether BASE is an ancestor or base class or DCLASS
3676 Return 1 if so, and 0 if not.
3677 Note: If BASE and DCLASS are of the same type, this function
3678 will return 1. So for some class A, is_ancestor (A, A) will
3682 is_ancestor (struct type
*base
, struct type
*dclass
)
3684 return distance_to_ancestor (base
, dclass
, 0) >= 0;
3687 /* Like is_ancestor, but only returns true when BASE is a public
3688 ancestor of DCLASS. */
3691 is_public_ancestor (struct type
*base
, struct type
*dclass
)
3693 return distance_to_ancestor (base
, dclass
, 1) >= 0;
3696 /* A helper function for is_unique_ancestor. */
3699 is_unique_ancestor_worker (struct type
*base
, struct type
*dclass
,
3701 const gdb_byte
*valaddr
, int embedded_offset
,
3702 CORE_ADDR address
, struct value
*val
)
3706 base
= check_typedef (base
);
3707 dclass
= check_typedef (dclass
);
3709 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
) && count
< 2; ++i
)
3714 iter
= check_typedef (TYPE_BASECLASS (dclass
, i
));
3716 this_offset
= baseclass_offset (dclass
, i
, valaddr
, embedded_offset
,
3719 if (class_types_same_p (base
, iter
))
3721 /* If this is the first subclass, set *OFFSET and set count
3722 to 1. Otherwise, if this is at the same offset as
3723 previous instances, do nothing. Otherwise, increment
3727 *offset
= this_offset
;
3730 else if (this_offset
== *offset
)
3738 count
+= is_unique_ancestor_worker (base
, iter
, offset
,
3740 embedded_offset
+ this_offset
,
3747 /* Like is_ancestor, but only returns true if BASE is a unique base
3748 class of the type of VAL. */
3751 is_unique_ancestor (struct type
*base
, struct value
*val
)
3755 return is_unique_ancestor_worker (base
, value_type (val
), &offset
,
3756 value_contents_for_printing (val
),
3757 value_embedded_offset (val
),
3758 value_address (val
), val
) == 1;
3761 /* See gdbtypes.h. */
3764 type_byte_order (const struct type
*type
)
3766 bfd_endian byteorder
= gdbarch_byte_order (get_type_arch (type
));
3767 if (type
->endianity_is_not_default ())
3769 if (byteorder
== BFD_ENDIAN_BIG
)
3770 return BFD_ENDIAN_LITTLE
;
3773 gdb_assert (byteorder
== BFD_ENDIAN_LITTLE
);
3774 return BFD_ENDIAN_BIG
;
3782 /* Overload resolution. */
3784 /* Return the sum of the rank of A with the rank of B. */
3787 sum_ranks (struct rank a
, struct rank b
)
3790 c
.rank
= a
.rank
+ b
.rank
;
3791 c
.subrank
= a
.subrank
+ b
.subrank
;
3795 /* Compare rank A and B and return:
3797 1 if a is better than b
3798 -1 if b is better than a. */
3801 compare_ranks (struct rank a
, struct rank b
)
3803 if (a
.rank
== b
.rank
)
3805 if (a
.subrank
== b
.subrank
)
3807 if (a
.subrank
< b
.subrank
)
3809 if (a
.subrank
> b
.subrank
)
3813 if (a
.rank
< b
.rank
)
3816 /* a.rank > b.rank */
3820 /* Functions for overload resolution begin here. */
3822 /* Compare two badness vectors A and B and return the result.
3823 0 => A and B are identical
3824 1 => A and B are incomparable
3825 2 => A is better than B
3826 3 => A is worse than B */
3829 compare_badness (const badness_vector
&a
, const badness_vector
&b
)
3833 short found_pos
= 0; /* any positives in c? */
3834 short found_neg
= 0; /* any negatives in c? */
3836 /* differing sizes => incomparable */
3837 if (a
.size () != b
.size ())
3840 /* Subtract b from a */
3841 for (i
= 0; i
< a
.size (); i
++)
3843 tmp
= compare_ranks (b
[i
], a
[i
]);
3853 return 1; /* incomparable */
3855 return 3; /* A > B */
3861 return 2; /* A < B */
3863 return 0; /* A == B */
3867 /* Rank a function by comparing its parameter types (PARMS), to the
3868 types of an argument list (ARGS). Return the badness vector. This
3869 has ARGS.size() + 1 entries. */
3872 rank_function (gdb::array_view
<type
*> parms
,
3873 gdb::array_view
<value
*> args
)
3875 /* add 1 for the length-match rank. */
3877 bv
.reserve (1 + args
.size ());
3879 /* First compare the lengths of the supplied lists.
3880 If there is a mismatch, set it to a high value. */
3882 /* pai/1997-06-03 FIXME: when we have debug info about default
3883 arguments and ellipsis parameter lists, we should consider those
3884 and rank the length-match more finely. */
3886 bv
.push_back ((args
.size () != parms
.size ())
3887 ? LENGTH_MISMATCH_BADNESS
3888 : EXACT_MATCH_BADNESS
);
3890 /* Now rank all the parameters of the candidate function. */
3891 size_t min_len
= std::min (parms
.size (), args
.size ());
3893 for (size_t i
= 0; i
< min_len
; i
++)
3894 bv
.push_back (rank_one_type (parms
[i
], value_type (args
[i
]),
3897 /* If more arguments than parameters, add dummy entries. */
3898 for (size_t i
= min_len
; i
< args
.size (); i
++)
3899 bv
.push_back (TOO_FEW_PARAMS_BADNESS
);
3904 /* Compare the names of two integer types, assuming that any sign
3905 qualifiers have been checked already. We do it this way because
3906 there may be an "int" in the name of one of the types. */
3909 integer_types_same_name_p (const char *first
, const char *second
)
3911 int first_p
, second_p
;
3913 /* If both are shorts, return 1; if neither is a short, keep
3915 first_p
= (strstr (first
, "short") != NULL
);
3916 second_p
= (strstr (second
, "short") != NULL
);
3917 if (first_p
&& second_p
)
3919 if (first_p
|| second_p
)
3922 /* Likewise for long. */
3923 first_p
= (strstr (first
, "long") != NULL
);
3924 second_p
= (strstr (second
, "long") != NULL
);
3925 if (first_p
&& second_p
)
3927 if (first_p
|| second_p
)
3930 /* Likewise for char. */
3931 first_p
= (strstr (first
, "char") != NULL
);
3932 second_p
= (strstr (second
, "char") != NULL
);
3933 if (first_p
&& second_p
)
3935 if (first_p
|| second_p
)
3938 /* They must both be ints. */
3942 /* Compares type A to type B. Returns true if they represent the same
3943 type, false otherwise. */
3946 types_equal (struct type
*a
, struct type
*b
)
3948 /* Identical type pointers. */
3949 /* However, this still doesn't catch all cases of same type for b
3950 and a. The reason is that builtin types are different from
3951 the same ones constructed from the object. */
3955 /* Resolve typedefs */
3956 if (a
->code () == TYPE_CODE_TYPEDEF
)
3957 a
= check_typedef (a
);
3958 if (b
->code () == TYPE_CODE_TYPEDEF
)
3959 b
= check_typedef (b
);
3961 /* If after resolving typedefs a and b are not of the same type
3962 code then they are not equal. */
3963 if (a
->code () != b
->code ())
3966 /* If a and b are both pointers types or both reference types then
3967 they are equal of the same type iff the objects they refer to are
3968 of the same type. */
3969 if (a
->code () == TYPE_CODE_PTR
3970 || a
->code () == TYPE_CODE_REF
)
3971 return types_equal (TYPE_TARGET_TYPE (a
),
3972 TYPE_TARGET_TYPE (b
));
3974 /* Well, damnit, if the names are exactly the same, I'll say they
3975 are exactly the same. This happens when we generate method
3976 stubs. The types won't point to the same address, but they
3977 really are the same. */
3979 if (a
->name () && b
->name ()
3980 && strcmp (a
->name (), b
->name ()) == 0)
3983 /* Check if identical after resolving typedefs. */
3987 /* Two function types are equal if their argument and return types
3989 if (a
->code () == TYPE_CODE_FUNC
)
3993 if (a
->num_fields () != b
->num_fields ())
3996 if (!types_equal (TYPE_TARGET_TYPE (a
), TYPE_TARGET_TYPE (b
)))
3999 for (i
= 0; i
< a
->num_fields (); ++i
)
4000 if (!types_equal (a
->field (i
).type (), b
->field (i
).type ()))
4009 /* Deep comparison of types. */
4011 /* An entry in the type-equality bcache. */
4013 struct type_equality_entry
4015 type_equality_entry (struct type
*t1
, struct type
*t2
)
4021 struct type
*type1
, *type2
;
4024 /* A helper function to compare two strings. Returns true if they are
4025 the same, false otherwise. Handles NULLs properly. */
4028 compare_maybe_null_strings (const char *s
, const char *t
)
4030 if (s
== NULL
|| t
== NULL
)
4032 return strcmp (s
, t
) == 0;
4035 /* A helper function for check_types_worklist that checks two types for
4036 "deep" equality. Returns true if the types are considered the
4037 same, false otherwise. */
4040 check_types_equal (struct type
*type1
, struct type
*type2
,
4041 std::vector
<type_equality_entry
> *worklist
)
4043 type1
= check_typedef (type1
);
4044 type2
= check_typedef (type2
);
4049 if (type1
->code () != type2
->code ()
4050 || TYPE_LENGTH (type1
) != TYPE_LENGTH (type2
)
4051 || type1
->is_unsigned () != type2
->is_unsigned ()
4052 || type1
->has_no_signedness () != type2
->has_no_signedness ()
4053 || type1
->endianity_is_not_default () != type2
->endianity_is_not_default ()
4054 || type1
->has_varargs () != type2
->has_varargs ()
4055 || type1
->is_vector () != type2
->is_vector ()
4056 || TYPE_NOTTEXT (type1
) != TYPE_NOTTEXT (type2
)
4057 || type1
->instance_flags () != type2
->instance_flags ()
4058 || type1
->num_fields () != type2
->num_fields ())
4061 if (!compare_maybe_null_strings (type1
->name (), type2
->name ()))
4063 if (!compare_maybe_null_strings (type1
->name (), type2
->name ()))
4066 if (type1
->code () == TYPE_CODE_RANGE
)
4068 if (*type1
->bounds () != *type2
->bounds ())
4075 for (i
= 0; i
< type1
->num_fields (); ++i
)
4077 const struct field
*field1
= &type1
->field (i
);
4078 const struct field
*field2
= &type2
->field (i
);
4080 if (FIELD_ARTIFICIAL (*field1
) != FIELD_ARTIFICIAL (*field2
)
4081 || FIELD_BITSIZE (*field1
) != FIELD_BITSIZE (*field2
)
4082 || FIELD_LOC_KIND (*field1
) != FIELD_LOC_KIND (*field2
))
4084 if (!compare_maybe_null_strings (FIELD_NAME (*field1
),
4085 FIELD_NAME (*field2
)))
4087 switch (FIELD_LOC_KIND (*field1
))
4089 case FIELD_LOC_KIND_BITPOS
:
4090 if (FIELD_BITPOS (*field1
) != FIELD_BITPOS (*field2
))
4093 case FIELD_LOC_KIND_ENUMVAL
:
4094 if (FIELD_ENUMVAL (*field1
) != FIELD_ENUMVAL (*field2
))
4097 case FIELD_LOC_KIND_PHYSADDR
:
4098 if (FIELD_STATIC_PHYSADDR (*field1
)
4099 != FIELD_STATIC_PHYSADDR (*field2
))
4102 case FIELD_LOC_KIND_PHYSNAME
:
4103 if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1
),
4104 FIELD_STATIC_PHYSNAME (*field2
)))
4107 case FIELD_LOC_KIND_DWARF_BLOCK
:
4109 struct dwarf2_locexpr_baton
*block1
, *block2
;
4111 block1
= FIELD_DWARF_BLOCK (*field1
);
4112 block2
= FIELD_DWARF_BLOCK (*field2
);
4113 if (block1
->per_cu
!= block2
->per_cu
4114 || block1
->size
!= block2
->size
4115 || memcmp (block1
->data
, block2
->data
, block1
->size
) != 0)
4120 internal_error (__FILE__
, __LINE__
, _("Unsupported field kind "
4121 "%d by check_types_equal"),
4122 FIELD_LOC_KIND (*field1
));
4125 worklist
->emplace_back (field1
->type (), field2
->type ());
4129 if (TYPE_TARGET_TYPE (type1
) != NULL
)
4131 if (TYPE_TARGET_TYPE (type2
) == NULL
)
4134 worklist
->emplace_back (TYPE_TARGET_TYPE (type1
),
4135 TYPE_TARGET_TYPE (type2
));
4137 else if (TYPE_TARGET_TYPE (type2
) != NULL
)
4143 /* Check types on a worklist for equality. Returns false if any pair
4144 is not equal, true if they are all considered equal. */
4147 check_types_worklist (std::vector
<type_equality_entry
> *worklist
,
4150 while (!worklist
->empty ())
4154 struct type_equality_entry entry
= std::move (worklist
->back ());
4155 worklist
->pop_back ();
4157 /* If the type pair has already been visited, we know it is
4159 cache
->insert (&entry
, sizeof (entry
), &added
);
4163 if (!check_types_equal (entry
.type1
, entry
.type2
, worklist
))
4170 /* Return true if types TYPE1 and TYPE2 are equal, as determined by a
4171 "deep comparison". Otherwise return false. */
4174 types_deeply_equal (struct type
*type1
, struct type
*type2
)
4176 std::vector
<type_equality_entry
> worklist
;
4178 gdb_assert (type1
!= NULL
&& type2
!= NULL
);
4180 /* Early exit for the simple case. */
4185 worklist
.emplace_back (type1
, type2
);
4186 return check_types_worklist (&worklist
, &cache
);
4189 /* Allocated status of type TYPE. Return zero if type TYPE is allocated.
4190 Otherwise return one. */
4193 type_not_allocated (const struct type
*type
)
4195 struct dynamic_prop
*prop
= TYPE_ALLOCATED_PROP (type
);
4197 return (prop
!= nullptr && prop
->kind () == PROP_CONST
4198 && prop
->const_val () == 0);
4201 /* Associated status of type TYPE. Return zero if type TYPE is associated.
4202 Otherwise return one. */
4205 type_not_associated (const struct type
*type
)
4207 struct dynamic_prop
*prop
= TYPE_ASSOCIATED_PROP (type
);
4209 return (prop
!= nullptr && prop
->kind () == PROP_CONST
4210 && prop
->const_val () == 0);
4213 /* rank_one_type helper for when PARM's type code is TYPE_CODE_PTR. */
4216 rank_one_type_parm_ptr (struct type
*parm
, struct type
*arg
, struct value
*value
)
4218 struct rank rank
= {0,0};
4220 switch (arg
->code ())
4224 /* Allowed pointer conversions are:
4225 (a) pointer to void-pointer conversion. */
4226 if (TYPE_TARGET_TYPE (parm
)->code () == TYPE_CODE_VOID
)
4227 return VOID_PTR_CONVERSION_BADNESS
;
4229 /* (b) pointer to ancestor-pointer conversion. */
4230 rank
.subrank
= distance_to_ancestor (TYPE_TARGET_TYPE (parm
),
4231 TYPE_TARGET_TYPE (arg
),
4233 if (rank
.subrank
>= 0)
4234 return sum_ranks (BASE_PTR_CONVERSION_BADNESS
, rank
);
4236 return INCOMPATIBLE_TYPE_BADNESS
;
4237 case TYPE_CODE_ARRAY
:
4239 struct type
*t1
= TYPE_TARGET_TYPE (parm
);
4240 struct type
*t2
= TYPE_TARGET_TYPE (arg
);
4242 if (types_equal (t1
, t2
))
4244 /* Make sure they are CV equal. */
4245 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
4246 rank
.subrank
|= CV_CONVERSION_CONST
;
4247 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
4248 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
4249 if (rank
.subrank
!= 0)
4250 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
4251 return EXACT_MATCH_BADNESS
;
4253 return INCOMPATIBLE_TYPE_BADNESS
;
4255 case TYPE_CODE_FUNC
:
4256 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
, NULL
);
4258 if (value
!= NULL
&& value_type (value
)->code () == TYPE_CODE_INT
)
4260 if (value_as_long (value
) == 0)
4262 /* Null pointer conversion: allow it to be cast to a pointer.
4263 [4.10.1 of C++ standard draft n3290] */
4264 return NULL_POINTER_CONVERSION_BADNESS
;
4268 /* If type checking is disabled, allow the conversion. */
4269 if (!strict_type_checking
)
4270 return NS_INTEGER_POINTER_CONVERSION_BADNESS
;
4274 case TYPE_CODE_ENUM
:
4275 case TYPE_CODE_FLAGS
:
4276 case TYPE_CODE_CHAR
:
4277 case TYPE_CODE_RANGE
:
4278 case TYPE_CODE_BOOL
:
4280 return INCOMPATIBLE_TYPE_BADNESS
;
4284 /* rank_one_type helper for when PARM's type code is TYPE_CODE_ARRAY. */
4287 rank_one_type_parm_array (struct type
*parm
, struct type
*arg
, struct value
*value
)
4289 switch (arg
->code ())
4292 case TYPE_CODE_ARRAY
:
4293 return rank_one_type (TYPE_TARGET_TYPE (parm
),
4294 TYPE_TARGET_TYPE (arg
), NULL
);
4296 return INCOMPATIBLE_TYPE_BADNESS
;
4300 /* rank_one_type helper for when PARM's type code is TYPE_CODE_FUNC. */
4303 rank_one_type_parm_func (struct type
*parm
, struct type
*arg
, struct value
*value
)
4305 switch (arg
->code ())
4307 case TYPE_CODE_PTR
: /* funcptr -> func */
4308 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
), NULL
);
4310 return INCOMPATIBLE_TYPE_BADNESS
;
4314 /* rank_one_type helper for when PARM's type code is TYPE_CODE_INT. */
4317 rank_one_type_parm_int (struct type
*parm
, struct type
*arg
, struct value
*value
)
4319 switch (arg
->code ())
4322 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
4324 /* Deal with signed, unsigned, and plain chars and
4325 signed and unsigned ints. */
4326 if (parm
->has_no_signedness ())
4328 /* This case only for character types. */
4329 if (arg
->has_no_signedness ())
4330 return EXACT_MATCH_BADNESS
; /* plain char -> plain char */
4331 else /* signed/unsigned char -> plain char */
4332 return INTEGER_CONVERSION_BADNESS
;
4334 else if (parm
->is_unsigned ())
4336 if (arg
->is_unsigned ())
4338 /* unsigned int -> unsigned int, or
4339 unsigned long -> unsigned long */
4340 if (integer_types_same_name_p (parm
->name (),
4342 return EXACT_MATCH_BADNESS
;
4343 else if (integer_types_same_name_p (arg
->name (),
4345 && integer_types_same_name_p (parm
->name (),
4347 /* unsigned int -> unsigned long */
4348 return INTEGER_PROMOTION_BADNESS
;
4350 /* unsigned long -> unsigned int */
4351 return INTEGER_CONVERSION_BADNESS
;
4355 if (integer_types_same_name_p (arg
->name (),
4357 && integer_types_same_name_p (parm
->name (),
4359 /* signed long -> unsigned int */
4360 return INTEGER_CONVERSION_BADNESS
;
4362 /* signed int/long -> unsigned int/long */
4363 return INTEGER_CONVERSION_BADNESS
;
4366 else if (!arg
->has_no_signedness () && !arg
->is_unsigned ())
4368 if (integer_types_same_name_p (parm
->name (),
4370 return EXACT_MATCH_BADNESS
;
4371 else if (integer_types_same_name_p (arg
->name (),
4373 && integer_types_same_name_p (parm
->name (),
4375 return INTEGER_PROMOTION_BADNESS
;
4377 return INTEGER_CONVERSION_BADNESS
;
4380 return INTEGER_CONVERSION_BADNESS
;
4382 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
4383 return INTEGER_PROMOTION_BADNESS
;
4385 return INTEGER_CONVERSION_BADNESS
;
4386 case TYPE_CODE_ENUM
:
4387 case TYPE_CODE_FLAGS
:
4388 case TYPE_CODE_CHAR
:
4389 case TYPE_CODE_RANGE
:
4390 case TYPE_CODE_BOOL
:
4391 if (TYPE_DECLARED_CLASS (arg
))
4392 return INCOMPATIBLE_TYPE_BADNESS
;
4393 return INTEGER_PROMOTION_BADNESS
;
4395 return INT_FLOAT_CONVERSION_BADNESS
;
4397 return NS_POINTER_CONVERSION_BADNESS
;
4399 return INCOMPATIBLE_TYPE_BADNESS
;
4403 /* rank_one_type helper for when PARM's type code is TYPE_CODE_ENUM. */
4406 rank_one_type_parm_enum (struct type
*parm
, struct type
*arg
, struct value
*value
)
4408 switch (arg
->code ())
4411 case TYPE_CODE_CHAR
:
4412 case TYPE_CODE_RANGE
:
4413 case TYPE_CODE_BOOL
:
4414 case TYPE_CODE_ENUM
:
4415 if (TYPE_DECLARED_CLASS (parm
) || TYPE_DECLARED_CLASS (arg
))
4416 return INCOMPATIBLE_TYPE_BADNESS
;
4417 return INTEGER_CONVERSION_BADNESS
;
4419 return INT_FLOAT_CONVERSION_BADNESS
;
4421 return INCOMPATIBLE_TYPE_BADNESS
;
4425 /* rank_one_type helper for when PARM's type code is TYPE_CODE_CHAR. */
4428 rank_one_type_parm_char (struct type
*parm
, struct type
*arg
, struct value
*value
)
4430 switch (arg
->code ())
4432 case TYPE_CODE_RANGE
:
4433 case TYPE_CODE_BOOL
:
4434 case TYPE_CODE_ENUM
:
4435 if (TYPE_DECLARED_CLASS (arg
))
4436 return INCOMPATIBLE_TYPE_BADNESS
;
4437 return INTEGER_CONVERSION_BADNESS
;
4439 return INT_FLOAT_CONVERSION_BADNESS
;
4441 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
4442 return INTEGER_CONVERSION_BADNESS
;
4443 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
4444 return INTEGER_PROMOTION_BADNESS
;
4446 case TYPE_CODE_CHAR
:
4447 /* Deal with signed, unsigned, and plain chars for C++ and
4448 with int cases falling through from previous case. */
4449 if (parm
->has_no_signedness ())
4451 if (arg
->has_no_signedness ())
4452 return EXACT_MATCH_BADNESS
;
4454 return INTEGER_CONVERSION_BADNESS
;
4456 else if (parm
->is_unsigned ())
4458 if (arg
->is_unsigned ())
4459 return EXACT_MATCH_BADNESS
;
4461 return INTEGER_PROMOTION_BADNESS
;
4463 else if (!arg
->has_no_signedness () && !arg
->is_unsigned ())
4464 return EXACT_MATCH_BADNESS
;
4466 return INTEGER_CONVERSION_BADNESS
;
4468 return INCOMPATIBLE_TYPE_BADNESS
;
4472 /* rank_one_type helper for when PARM's type code is TYPE_CODE_RANGE. */
4475 rank_one_type_parm_range (struct type
*parm
, struct type
*arg
, struct value
*value
)
4477 switch (arg
->code ())
4480 case TYPE_CODE_CHAR
:
4481 case TYPE_CODE_RANGE
:
4482 case TYPE_CODE_BOOL
:
4483 case TYPE_CODE_ENUM
:
4484 return INTEGER_CONVERSION_BADNESS
;
4486 return INT_FLOAT_CONVERSION_BADNESS
;
4488 return INCOMPATIBLE_TYPE_BADNESS
;
4492 /* rank_one_type helper for when PARM's type code is TYPE_CODE_BOOL. */
4495 rank_one_type_parm_bool (struct type
*parm
, struct type
*arg
, struct value
*value
)
4497 switch (arg
->code ())
4499 /* n3290 draft, section 4.12.1 (conv.bool):
4501 "A prvalue of arithmetic, unscoped enumeration, pointer, or
4502 pointer to member type can be converted to a prvalue of type
4503 bool. A zero value, null pointer value, or null member pointer
4504 value is converted to false; any other value is converted to
4505 true. A prvalue of type std::nullptr_t can be converted to a
4506 prvalue of type bool; the resulting value is false." */
4508 case TYPE_CODE_CHAR
:
4509 case TYPE_CODE_ENUM
:
4511 case TYPE_CODE_MEMBERPTR
:
4513 return BOOL_CONVERSION_BADNESS
;
4514 case TYPE_CODE_RANGE
:
4515 return INCOMPATIBLE_TYPE_BADNESS
;
4516 case TYPE_CODE_BOOL
:
4517 return EXACT_MATCH_BADNESS
;
4519 return INCOMPATIBLE_TYPE_BADNESS
;
4523 /* rank_one_type helper for when PARM's type code is TYPE_CODE_FLOAT. */
4526 rank_one_type_parm_float (struct type
*parm
, struct type
*arg
, struct value
*value
)
4528 switch (arg
->code ())
4531 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
4532 return FLOAT_PROMOTION_BADNESS
;
4533 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
4534 return EXACT_MATCH_BADNESS
;
4536 return FLOAT_CONVERSION_BADNESS
;
4538 case TYPE_CODE_BOOL
:
4539 case TYPE_CODE_ENUM
:
4540 case TYPE_CODE_RANGE
:
4541 case TYPE_CODE_CHAR
:
4542 return INT_FLOAT_CONVERSION_BADNESS
;
4544 return INCOMPATIBLE_TYPE_BADNESS
;
4548 /* rank_one_type helper for when PARM's type code is TYPE_CODE_COMPLEX. */
4551 rank_one_type_parm_complex (struct type
*parm
, struct type
*arg
, struct value
*value
)
4553 switch (arg
->code ())
4554 { /* Strictly not needed for C++, but... */
4556 return FLOAT_PROMOTION_BADNESS
;
4557 case TYPE_CODE_COMPLEX
:
4558 return EXACT_MATCH_BADNESS
;
4560 return INCOMPATIBLE_TYPE_BADNESS
;
4564 /* rank_one_type helper for when PARM's type code is TYPE_CODE_STRUCT. */
4567 rank_one_type_parm_struct (struct type
*parm
, struct type
*arg
, struct value
*value
)
4569 struct rank rank
= {0, 0};
4571 switch (arg
->code ())
4573 case TYPE_CODE_STRUCT
:
4574 /* Check for derivation */
4575 rank
.subrank
= distance_to_ancestor (parm
, arg
, 0);
4576 if (rank
.subrank
>= 0)
4577 return sum_ranks (BASE_CONVERSION_BADNESS
, rank
);
4580 return INCOMPATIBLE_TYPE_BADNESS
;
4584 /* rank_one_type helper for when PARM's type code is TYPE_CODE_SET. */
4587 rank_one_type_parm_set (struct type
*parm
, struct type
*arg
, struct value
*value
)
4589 switch (arg
->code ())
4593 return rank_one_type (parm
->field (0).type (),
4594 arg
->field (0).type (), NULL
);
4596 return INCOMPATIBLE_TYPE_BADNESS
;
4600 /* Compare one type (PARM) for compatibility with another (ARG).
4601 * PARM is intended to be the parameter type of a function; and
4602 * ARG is the supplied argument's type. This function tests if
4603 * the latter can be converted to the former.
4604 * VALUE is the argument's value or NULL if none (or called recursively)
4606 * Return 0 if they are identical types;
4607 * Otherwise, return an integer which corresponds to how compatible
4608 * PARM is to ARG. The higher the return value, the worse the match.
4609 * Generally the "bad" conversions are all uniformly assigned a 100. */
4612 rank_one_type (struct type
*parm
, struct type
*arg
, struct value
*value
)
4614 struct rank rank
= {0,0};
4616 /* Resolve typedefs */
4617 if (parm
->code () == TYPE_CODE_TYPEDEF
)
4618 parm
= check_typedef (parm
);
4619 if (arg
->code () == TYPE_CODE_TYPEDEF
)
4620 arg
= check_typedef (arg
);
4622 if (TYPE_IS_REFERENCE (parm
) && value
!= NULL
)
4624 if (VALUE_LVAL (value
) == not_lval
)
4626 /* Rvalues should preferably bind to rvalue references or const
4627 lvalue references. */
4628 if (parm
->code () == TYPE_CODE_RVALUE_REF
)
4629 rank
.subrank
= REFERENCE_CONVERSION_RVALUE
;
4630 else if (TYPE_CONST (TYPE_TARGET_TYPE (parm
)))
4631 rank
.subrank
= REFERENCE_CONVERSION_CONST_LVALUE
;
4633 return INCOMPATIBLE_TYPE_BADNESS
;
4634 return sum_ranks (rank
, REFERENCE_CONVERSION_BADNESS
);
4638 /* It's illegal to pass an lvalue as an rvalue. */
4639 if (parm
->code () == TYPE_CODE_RVALUE_REF
)
4640 return INCOMPATIBLE_TYPE_BADNESS
;
4644 if (types_equal (parm
, arg
))
4646 struct type
*t1
= parm
;
4647 struct type
*t2
= arg
;
4649 /* For pointers and references, compare target type. */
4650 if (parm
->code () == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (parm
))
4652 t1
= TYPE_TARGET_TYPE (parm
);
4653 t2
= TYPE_TARGET_TYPE (arg
);
4656 /* Make sure they are CV equal, too. */
4657 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
4658 rank
.subrank
|= CV_CONVERSION_CONST
;
4659 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
4660 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
4661 if (rank
.subrank
!= 0)
4662 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
4663 return EXACT_MATCH_BADNESS
;
4666 /* See through references, since we can almost make non-references
4669 if (TYPE_IS_REFERENCE (arg
))
4670 return (sum_ranks (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
), NULL
),
4671 REFERENCE_SEE_THROUGH_BADNESS
));
4672 if (TYPE_IS_REFERENCE (parm
))
4673 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
, NULL
),
4674 REFERENCE_SEE_THROUGH_BADNESS
));
4676 /* Debugging only. */
4677 fprintf_filtered (gdb_stderr
,
4678 "------ Arg is %s [%d], parm is %s [%d]\n",
4679 arg
->name (), arg
->code (),
4680 parm
->name (), parm
->code ());
4682 /* x -> y means arg of type x being supplied for parameter of type y. */
4684 switch (parm
->code ())
4687 return rank_one_type_parm_ptr (parm
, arg
, value
);
4688 case TYPE_CODE_ARRAY
:
4689 return rank_one_type_parm_array (parm
, arg
, value
);
4690 case TYPE_CODE_FUNC
:
4691 return rank_one_type_parm_func (parm
, arg
, value
);
4693 return rank_one_type_parm_int (parm
, arg
, value
);
4694 case TYPE_CODE_ENUM
:
4695 return rank_one_type_parm_enum (parm
, arg
, value
);
4696 case TYPE_CODE_CHAR
:
4697 return rank_one_type_parm_char (parm
, arg
, value
);
4698 case TYPE_CODE_RANGE
:
4699 return rank_one_type_parm_range (parm
, arg
, value
);
4700 case TYPE_CODE_BOOL
:
4701 return rank_one_type_parm_bool (parm
, arg
, value
);
4703 return rank_one_type_parm_float (parm
, arg
, value
);
4704 case TYPE_CODE_COMPLEX
:
4705 return rank_one_type_parm_complex (parm
, arg
, value
);
4706 case TYPE_CODE_STRUCT
:
4707 return rank_one_type_parm_struct (parm
, arg
, value
);
4709 return rank_one_type_parm_set (parm
, arg
, value
);
4711 return INCOMPATIBLE_TYPE_BADNESS
;
4712 } /* switch (arg->code ()) */
4715 /* End of functions for overload resolution. */
4717 /* Routines to pretty-print types. */
4720 print_bit_vector (B_TYPE
*bits
, int nbits
)
4724 for (bitno
= 0; bitno
< nbits
; bitno
++)
4726 if ((bitno
% 8) == 0)
4728 puts_filtered (" ");
4730 if (B_TST (bits
, bitno
))
4731 printf_filtered (("1"));
4733 printf_filtered (("0"));
4737 /* Note the first arg should be the "this" pointer, we may not want to
4738 include it since we may get into a infinitely recursive
4742 print_args (struct field
*args
, int nargs
, int spaces
)
4748 for (i
= 0; i
< nargs
; i
++)
4750 printfi_filtered (spaces
, "[%d] name '%s'\n", i
,
4751 args
[i
].name
!= NULL
? args
[i
].name
: "<NULL>");
4752 recursive_dump_type (args
[i
].type (), spaces
+ 2);
4758 field_is_static (struct field
*f
)
4760 /* "static" fields are the fields whose location is not relative
4761 to the address of the enclosing struct. It would be nice to
4762 have a dedicated flag that would be set for static fields when
4763 the type is being created. But in practice, checking the field
4764 loc_kind should give us an accurate answer. */
4765 return (FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSNAME
4766 || FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSADDR
);
4770 dump_fn_fieldlists (struct type
*type
, int spaces
)
4776 printfi_filtered (spaces
, "fn_fieldlists ");
4777 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
4778 printf_filtered ("\n");
4779 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
4781 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
4782 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
4784 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
4785 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
4787 printf_filtered (_(") length %d\n"),
4788 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
4789 for (overload_idx
= 0;
4790 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
4793 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
4795 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
4796 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
4798 printf_filtered (")\n");
4799 printfi_filtered (spaces
+ 8, "type ");
4800 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
4802 printf_filtered ("\n");
4804 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
4807 printfi_filtered (spaces
+ 8, "args ");
4808 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
4810 printf_filtered ("\n");
4811 print_args (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
4812 TYPE_FN_FIELD_TYPE (f
, overload_idx
)->num_fields (),
4814 printfi_filtered (spaces
+ 8, "fcontext ");
4815 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
4817 printf_filtered ("\n");
4819 printfi_filtered (spaces
+ 8, "is_const %d\n",
4820 TYPE_FN_FIELD_CONST (f
, overload_idx
));
4821 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
4822 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
4823 printfi_filtered (spaces
+ 8, "is_private %d\n",
4824 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
4825 printfi_filtered (spaces
+ 8, "is_protected %d\n",
4826 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
4827 printfi_filtered (spaces
+ 8, "is_stub %d\n",
4828 TYPE_FN_FIELD_STUB (f
, overload_idx
));
4829 printfi_filtered (spaces
+ 8, "defaulted %d\n",
4830 TYPE_FN_FIELD_DEFAULTED (f
, overload_idx
));
4831 printfi_filtered (spaces
+ 8, "is_deleted %d\n",
4832 TYPE_FN_FIELD_DELETED (f
, overload_idx
));
4833 printfi_filtered (spaces
+ 8, "voffset %u\n",
4834 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
4840 print_cplus_stuff (struct type
*type
, int spaces
)
4842 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
4843 printfi_filtered (spaces
, "vptr_basetype ");
4844 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
4845 puts_filtered ("\n");
4846 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
4847 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
4849 printfi_filtered (spaces
, "n_baseclasses %d\n",
4850 TYPE_N_BASECLASSES (type
));
4851 printfi_filtered (spaces
, "nfn_fields %d\n",
4852 TYPE_NFN_FIELDS (type
));
4853 if (TYPE_N_BASECLASSES (type
) > 0)
4855 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
4856 TYPE_N_BASECLASSES (type
));
4857 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
),
4859 printf_filtered (")");
4861 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
4862 TYPE_N_BASECLASSES (type
));
4863 puts_filtered ("\n");
4865 if (type
->num_fields () > 0)
4867 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
4869 printfi_filtered (spaces
,
4870 "private_field_bits (%d bits at *",
4871 type
->num_fields ());
4872 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
),
4874 printf_filtered (")");
4875 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
4876 type
->num_fields ());
4877 puts_filtered ("\n");
4879 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
4881 printfi_filtered (spaces
,
4882 "protected_field_bits (%d bits at *",
4883 type
->num_fields ());
4884 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
),
4886 printf_filtered (")");
4887 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
4888 type
->num_fields ());
4889 puts_filtered ("\n");
4892 if (TYPE_NFN_FIELDS (type
) > 0)
4894 dump_fn_fieldlists (type
, spaces
);
4897 printfi_filtered (spaces
, "calling_convention %d\n",
4898 TYPE_CPLUS_CALLING_CONVENTION (type
));
4901 /* Print the contents of the TYPE's type_specific union, assuming that
4902 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
4905 print_gnat_stuff (struct type
*type
, int spaces
)
4907 struct type
*descriptive_type
= TYPE_DESCRIPTIVE_TYPE (type
);
4909 if (descriptive_type
== NULL
)
4910 printfi_filtered (spaces
+ 2, "no descriptive type\n");
4913 printfi_filtered (spaces
+ 2, "descriptive type\n");
4914 recursive_dump_type (descriptive_type
, spaces
+ 4);
4918 /* Print the contents of the TYPE's type_specific union, assuming that
4919 its type-specific kind is TYPE_SPECIFIC_FIXED_POINT. */
4922 print_fixed_point_type_info (struct type
*type
, int spaces
)
4924 printfi_filtered (spaces
+ 2, "scaling factor: %s\n",
4925 fixed_point_scaling_factor (type
).str ().get ());
4928 static struct obstack dont_print_type_obstack
;
4930 /* Print the dynamic_prop PROP. */
4933 dump_dynamic_prop (dynamic_prop
const& prop
)
4935 switch (prop
.kind ())
4938 printf_filtered ("%s", plongest (prop
.const_val ()));
4940 case PROP_UNDEFINED
:
4941 printf_filtered ("(undefined)");
4945 printf_filtered ("(dynamic)");
4948 gdb_assert_not_reached ("unhandled prop kind");
4954 recursive_dump_type (struct type
*type
, int spaces
)
4959 obstack_begin (&dont_print_type_obstack
, 0);
4961 if (type
->num_fields () > 0
4962 || (HAVE_CPLUS_STRUCT (type
) && TYPE_NFN_FIELDS (type
) > 0))
4964 struct type
**first_dont_print
4965 = (struct type
**) obstack_base (&dont_print_type_obstack
);
4967 int i
= (struct type
**)
4968 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
4972 if (type
== first_dont_print
[i
])
4974 printfi_filtered (spaces
, "type node ");
4975 gdb_print_host_address (type
, gdb_stdout
);
4976 printf_filtered (_(" <same as already seen type>\n"));
4981 obstack_ptr_grow (&dont_print_type_obstack
, type
);
4984 printfi_filtered (spaces
, "type node ");
4985 gdb_print_host_address (type
, gdb_stdout
);
4986 printf_filtered ("\n");
4987 printfi_filtered (spaces
, "name '%s' (",
4988 type
->name () ? type
->name () : "<NULL>");
4989 gdb_print_host_address (type
->name (), gdb_stdout
);
4990 printf_filtered (")\n");
4991 printfi_filtered (spaces
, "code 0x%x ", type
->code ());
4992 switch (type
->code ())
4994 case TYPE_CODE_UNDEF
:
4995 printf_filtered ("(TYPE_CODE_UNDEF)");
4998 printf_filtered ("(TYPE_CODE_PTR)");
5000 case TYPE_CODE_ARRAY
:
5001 printf_filtered ("(TYPE_CODE_ARRAY)");
5003 case TYPE_CODE_STRUCT
:
5004 printf_filtered ("(TYPE_CODE_STRUCT)");
5006 case TYPE_CODE_UNION
:
5007 printf_filtered ("(TYPE_CODE_UNION)");
5009 case TYPE_CODE_ENUM
:
5010 printf_filtered ("(TYPE_CODE_ENUM)");
5012 case TYPE_CODE_FLAGS
:
5013 printf_filtered ("(TYPE_CODE_FLAGS)");
5015 case TYPE_CODE_FUNC
:
5016 printf_filtered ("(TYPE_CODE_FUNC)");
5019 printf_filtered ("(TYPE_CODE_INT)");
5022 printf_filtered ("(TYPE_CODE_FLT)");
5024 case TYPE_CODE_VOID
:
5025 printf_filtered ("(TYPE_CODE_VOID)");
5028 printf_filtered ("(TYPE_CODE_SET)");
5030 case TYPE_CODE_RANGE
:
5031 printf_filtered ("(TYPE_CODE_RANGE)");
5033 case TYPE_CODE_STRING
:
5034 printf_filtered ("(TYPE_CODE_STRING)");
5036 case TYPE_CODE_ERROR
:
5037 printf_filtered ("(TYPE_CODE_ERROR)");
5039 case TYPE_CODE_MEMBERPTR
:
5040 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
5042 case TYPE_CODE_METHODPTR
:
5043 printf_filtered ("(TYPE_CODE_METHODPTR)");
5045 case TYPE_CODE_METHOD
:
5046 printf_filtered ("(TYPE_CODE_METHOD)");
5049 printf_filtered ("(TYPE_CODE_REF)");
5051 case TYPE_CODE_CHAR
:
5052 printf_filtered ("(TYPE_CODE_CHAR)");
5054 case TYPE_CODE_BOOL
:
5055 printf_filtered ("(TYPE_CODE_BOOL)");
5057 case TYPE_CODE_COMPLEX
:
5058 printf_filtered ("(TYPE_CODE_COMPLEX)");
5060 case TYPE_CODE_TYPEDEF
:
5061 printf_filtered ("(TYPE_CODE_TYPEDEF)");
5063 case TYPE_CODE_NAMESPACE
:
5064 printf_filtered ("(TYPE_CODE_NAMESPACE)");
5066 case TYPE_CODE_FIXED_POINT
:
5067 printf_filtered ("(TYPE_CODE_FIXED_POINT)");
5070 printf_filtered ("(UNKNOWN TYPE CODE)");
5073 puts_filtered ("\n");
5074 printfi_filtered (spaces
, "length %s\n", pulongest (TYPE_LENGTH (type
)));
5075 if (TYPE_OBJFILE_OWNED (type
))
5077 printfi_filtered (spaces
, "objfile ");
5078 gdb_print_host_address (TYPE_OWNER (type
).objfile
, gdb_stdout
);
5082 printfi_filtered (spaces
, "gdbarch ");
5083 gdb_print_host_address (TYPE_OWNER (type
).gdbarch
, gdb_stdout
);
5085 printf_filtered ("\n");
5086 printfi_filtered (spaces
, "target_type ");
5087 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
5088 printf_filtered ("\n");
5089 if (TYPE_TARGET_TYPE (type
) != NULL
)
5091 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
5093 printfi_filtered (spaces
, "pointer_type ");
5094 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
5095 printf_filtered ("\n");
5096 printfi_filtered (spaces
, "reference_type ");
5097 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
5098 printf_filtered ("\n");
5099 printfi_filtered (spaces
, "type_chain ");
5100 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
5101 printf_filtered ("\n");
5102 printfi_filtered (spaces
, "instance_flags 0x%x",
5103 (unsigned) type
->instance_flags ());
5104 if (TYPE_CONST (type
))
5106 puts_filtered (" TYPE_CONST");
5108 if (TYPE_VOLATILE (type
))
5110 puts_filtered (" TYPE_VOLATILE");
5112 if (TYPE_CODE_SPACE (type
))
5114 puts_filtered (" TYPE_CODE_SPACE");
5116 if (TYPE_DATA_SPACE (type
))
5118 puts_filtered (" TYPE_DATA_SPACE");
5120 if (TYPE_ADDRESS_CLASS_1 (type
))
5122 puts_filtered (" TYPE_ADDRESS_CLASS_1");
5124 if (TYPE_ADDRESS_CLASS_2 (type
))
5126 puts_filtered (" TYPE_ADDRESS_CLASS_2");
5128 if (TYPE_RESTRICT (type
))
5130 puts_filtered (" TYPE_RESTRICT");
5132 if (TYPE_ATOMIC (type
))
5134 puts_filtered (" TYPE_ATOMIC");
5136 puts_filtered ("\n");
5138 printfi_filtered (spaces
, "flags");
5139 if (type
->is_unsigned ())
5141 puts_filtered (" TYPE_UNSIGNED");
5143 if (type
->has_no_signedness ())
5145 puts_filtered (" TYPE_NOSIGN");
5147 if (type
->endianity_is_not_default ())
5149 puts_filtered (" TYPE_ENDIANITY_NOT_DEFAULT");
5151 if (type
->is_stub ())
5153 puts_filtered (" TYPE_STUB");
5155 if (type
->target_is_stub ())
5157 puts_filtered (" TYPE_TARGET_STUB");
5159 if (type
->is_prototyped ())
5161 puts_filtered (" TYPE_PROTOTYPED");
5163 if (type
->has_varargs ())
5165 puts_filtered (" TYPE_VARARGS");
5167 /* This is used for things like AltiVec registers on ppc. Gcc emits
5168 an attribute for the array type, which tells whether or not we
5169 have a vector, instead of a regular array. */
5170 if (type
->is_vector ())
5172 puts_filtered (" TYPE_VECTOR");
5174 if (type
->is_fixed_instance ())
5176 puts_filtered (" TYPE_FIXED_INSTANCE");
5178 if (type
->stub_is_supported ())
5180 puts_filtered (" TYPE_STUB_SUPPORTED");
5182 if (TYPE_NOTTEXT (type
))
5184 puts_filtered (" TYPE_NOTTEXT");
5186 puts_filtered ("\n");
5187 printfi_filtered (spaces
, "nfields %d ", type
->num_fields ());
5188 gdb_print_host_address (type
->fields (), gdb_stdout
);
5189 puts_filtered ("\n");
5190 for (idx
= 0; idx
< type
->num_fields (); idx
++)
5192 if (type
->code () == TYPE_CODE_ENUM
)
5193 printfi_filtered (spaces
+ 2,
5194 "[%d] enumval %s type ",
5195 idx
, plongest (TYPE_FIELD_ENUMVAL (type
, idx
)));
5197 printfi_filtered (spaces
+ 2,
5198 "[%d] bitpos %s bitsize %d type ",
5199 idx
, plongest (TYPE_FIELD_BITPOS (type
, idx
)),
5200 TYPE_FIELD_BITSIZE (type
, idx
));
5201 gdb_print_host_address (type
->field (idx
).type (), gdb_stdout
);
5202 printf_filtered (" name '%s' (",
5203 TYPE_FIELD_NAME (type
, idx
) != NULL
5204 ? TYPE_FIELD_NAME (type
, idx
)
5206 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
5207 printf_filtered (")\n");
5208 if (type
->field (idx
).type () != NULL
)
5210 recursive_dump_type (type
->field (idx
).type (), spaces
+ 4);
5213 if (type
->code () == TYPE_CODE_RANGE
)
5215 printfi_filtered (spaces
, "low ");
5216 dump_dynamic_prop (type
->bounds ()->low
);
5217 printf_filtered (" high ");
5218 dump_dynamic_prop (type
->bounds ()->high
);
5219 printf_filtered ("\n");
5222 switch (TYPE_SPECIFIC_FIELD (type
))
5224 case TYPE_SPECIFIC_CPLUS_STUFF
:
5225 printfi_filtered (spaces
, "cplus_stuff ");
5226 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
),
5228 puts_filtered ("\n");
5229 print_cplus_stuff (type
, spaces
);
5232 case TYPE_SPECIFIC_GNAT_STUFF
:
5233 printfi_filtered (spaces
, "gnat_stuff ");
5234 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type
), gdb_stdout
);
5235 puts_filtered ("\n");
5236 print_gnat_stuff (type
, spaces
);
5239 case TYPE_SPECIFIC_FLOATFORMAT
:
5240 printfi_filtered (spaces
, "floatformat ");
5241 if (TYPE_FLOATFORMAT (type
) == NULL
5242 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
5243 puts_filtered ("(null)");
5245 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
5246 puts_filtered ("\n");
5249 case TYPE_SPECIFIC_FUNC
:
5250 printfi_filtered (spaces
, "calling_convention %d\n",
5251 TYPE_CALLING_CONVENTION (type
));
5252 /* tail_call_list is not printed. */
5255 case TYPE_SPECIFIC_SELF_TYPE
:
5256 printfi_filtered (spaces
, "self_type ");
5257 gdb_print_host_address (TYPE_SELF_TYPE (type
), gdb_stdout
);
5258 puts_filtered ("\n");
5261 case TYPE_SPECIFIC_FIXED_POINT
:
5262 printfi_filtered (spaces
, "fixed_point_info ");
5263 print_fixed_point_type_info (type
, spaces
);
5264 puts_filtered ("\n");
5267 case TYPE_SPECIFIC_INT
:
5268 if (type
->bit_size_differs_p ())
5270 unsigned bit_size
= type
->bit_size ();
5271 unsigned bit_off
= type
->bit_offset ();
5272 printfi_filtered (spaces
, " bit size = %u, bit offset = %u\n",
5279 obstack_free (&dont_print_type_obstack
, NULL
);
5282 /* Trivial helpers for the libiberty hash table, for mapping one
5285 struct type_pair
: public allocate_on_obstack
5287 type_pair (struct type
*old_
, struct type
*newobj_
)
5288 : old (old_
), newobj (newobj_
)
5291 struct type
* const old
, * const newobj
;
5295 type_pair_hash (const void *item
)
5297 const struct type_pair
*pair
= (const struct type_pair
*) item
;
5299 return htab_hash_pointer (pair
->old
);
5303 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
5305 const struct type_pair
*lhs
= (const struct type_pair
*) item_lhs
;
5306 const struct type_pair
*rhs
= (const struct type_pair
*) item_rhs
;
5308 return lhs
->old
== rhs
->old
;
5311 /* Allocate the hash table used by copy_type_recursive to walk
5312 types without duplicates. We use OBJFILE's obstack, because
5313 OBJFILE is about to be deleted. */
5316 create_copied_types_hash (struct objfile
*objfile
)
5318 return htab_up (htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
5319 NULL
, &objfile
->objfile_obstack
,
5320 hashtab_obstack_allocate
,
5321 dummy_obstack_deallocate
));
5324 /* Recursively copy (deep copy) a dynamic attribute list of a type. */
5326 static struct dynamic_prop_list
*
5327 copy_dynamic_prop_list (struct obstack
*objfile_obstack
,
5328 struct dynamic_prop_list
*list
)
5330 struct dynamic_prop_list
*copy
= list
;
5331 struct dynamic_prop_list
**node_ptr
= ©
;
5333 while (*node_ptr
!= NULL
)
5335 struct dynamic_prop_list
*node_copy
;
5337 node_copy
= ((struct dynamic_prop_list
*)
5338 obstack_copy (objfile_obstack
, *node_ptr
,
5339 sizeof (struct dynamic_prop_list
)));
5340 node_copy
->prop
= (*node_ptr
)->prop
;
5341 *node_ptr
= node_copy
;
5343 node_ptr
= &node_copy
->next
;
5349 /* Recursively copy (deep copy) TYPE, if it is associated with
5350 OBJFILE. Return a new type owned by the gdbarch associated with the type, a
5351 saved type if we have already visited TYPE (using COPIED_TYPES), or TYPE if
5352 it is not associated with OBJFILE. */
5355 copy_type_recursive (struct objfile
*objfile
,
5357 htab_t copied_types
)
5360 struct type
*new_type
;
5362 if (! TYPE_OBJFILE_OWNED (type
))
5365 /* This type shouldn't be pointing to any types in other objfiles;
5366 if it did, the type might disappear unexpectedly. */
5367 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
5369 struct type_pair
pair (type
, nullptr);
5371 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
5373 return ((struct type_pair
*) *slot
)->newobj
;
5375 new_type
= alloc_type_arch (get_type_arch (type
));
5377 /* We must add the new type to the hash table immediately, in case
5378 we encounter this type again during a recursive call below. */
5379 struct type_pair
*stored
5380 = new (&objfile
->objfile_obstack
) struct type_pair (type
, new_type
);
5384 /* Copy the common fields of types. For the main type, we simply
5385 copy the entire thing and then update specific fields as needed. */
5386 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
5387 TYPE_OBJFILE_OWNED (new_type
) = 0;
5388 TYPE_OWNER (new_type
).gdbarch
= get_type_arch (type
);
5391 new_type
->set_name (xstrdup (type
->name ()));
5393 new_type
->set_instance_flags (type
->instance_flags ());
5394 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
5396 /* Copy the fields. */
5397 if (type
->num_fields ())
5401 nfields
= type
->num_fields ();
5402 new_type
->set_fields
5404 TYPE_ZALLOC (new_type
, nfields
* sizeof (struct field
)));
5406 for (i
= 0; i
< nfields
; i
++)
5408 TYPE_FIELD_ARTIFICIAL (new_type
, i
) =
5409 TYPE_FIELD_ARTIFICIAL (type
, i
);
5410 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
5411 if (type
->field (i
).type ())
5412 new_type
->field (i
).set_type
5413 (copy_type_recursive (objfile
, type
->field (i
).type (),
5415 if (TYPE_FIELD_NAME (type
, i
))
5416 TYPE_FIELD_NAME (new_type
, i
) =
5417 xstrdup (TYPE_FIELD_NAME (type
, i
));
5418 switch (TYPE_FIELD_LOC_KIND (type
, i
))
5420 case FIELD_LOC_KIND_BITPOS
:
5421 SET_FIELD_BITPOS (new_type
->field (i
),
5422 TYPE_FIELD_BITPOS (type
, i
));
5424 case FIELD_LOC_KIND_ENUMVAL
:
5425 SET_FIELD_ENUMVAL (new_type
->field (i
),
5426 TYPE_FIELD_ENUMVAL (type
, i
));
5428 case FIELD_LOC_KIND_PHYSADDR
:
5429 SET_FIELD_PHYSADDR (new_type
->field (i
),
5430 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
5432 case FIELD_LOC_KIND_PHYSNAME
:
5433 SET_FIELD_PHYSNAME (new_type
->field (i
),
5434 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
,
5438 internal_error (__FILE__
, __LINE__
,
5439 _("Unexpected type field location kind: %d"),
5440 TYPE_FIELD_LOC_KIND (type
, i
));
5445 /* For range types, copy the bounds information. */
5446 if (type
->code () == TYPE_CODE_RANGE
)
5448 range_bounds
*bounds
5449 = ((struct range_bounds
*) TYPE_ALLOC
5450 (new_type
, sizeof (struct range_bounds
)));
5452 *bounds
= *type
->bounds ();
5453 new_type
->set_bounds (bounds
);
5456 if (type
->main_type
->dyn_prop_list
!= NULL
)
5457 new_type
->main_type
->dyn_prop_list
5458 = copy_dynamic_prop_list (&objfile
->objfile_obstack
,
5459 type
->main_type
->dyn_prop_list
);
5462 /* Copy pointers to other types. */
5463 if (TYPE_TARGET_TYPE (type
))
5464 TYPE_TARGET_TYPE (new_type
) =
5465 copy_type_recursive (objfile
,
5466 TYPE_TARGET_TYPE (type
),
5469 /* Maybe copy the type_specific bits.
5471 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
5472 base classes and methods. There's no fundamental reason why we
5473 can't, but at the moment it is not needed. */
5475 switch (TYPE_SPECIFIC_FIELD (type
))
5477 case TYPE_SPECIFIC_NONE
:
5479 case TYPE_SPECIFIC_FUNC
:
5480 INIT_FUNC_SPECIFIC (new_type
);
5481 TYPE_CALLING_CONVENTION (new_type
) = TYPE_CALLING_CONVENTION (type
);
5482 TYPE_NO_RETURN (new_type
) = TYPE_NO_RETURN (type
);
5483 TYPE_TAIL_CALL_LIST (new_type
) = NULL
;
5485 case TYPE_SPECIFIC_FLOATFORMAT
:
5486 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
5488 case TYPE_SPECIFIC_CPLUS_STUFF
:
5489 INIT_CPLUS_SPECIFIC (new_type
);
5491 case TYPE_SPECIFIC_GNAT_STUFF
:
5492 INIT_GNAT_SPECIFIC (new_type
);
5494 case TYPE_SPECIFIC_SELF_TYPE
:
5495 set_type_self_type (new_type
,
5496 copy_type_recursive (objfile
, TYPE_SELF_TYPE (type
),
5499 case TYPE_SPECIFIC_FIXED_POINT
:
5500 INIT_FIXED_POINT_SPECIFIC (new_type
);
5501 TYPE_FIXED_POINT_INFO (new_type
)->scaling_factor
5502 = TYPE_FIXED_POINT_INFO (type
)->scaling_factor
;
5504 case TYPE_SPECIFIC_INT
:
5505 TYPE_SPECIFIC_FIELD (new_type
) = TYPE_SPECIFIC_INT
;
5506 TYPE_MAIN_TYPE (new_type
)->type_specific
.int_stuff
5507 = TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
;
5511 gdb_assert_not_reached ("bad type_specific_kind");
5517 /* Make a copy of the given TYPE, except that the pointer & reference
5518 types are not preserved.
5520 This function assumes that the given type has an associated objfile.
5521 This objfile is used to allocate the new type. */
5524 copy_type (const struct type
*type
)
5526 struct type
*new_type
;
5528 gdb_assert (TYPE_OBJFILE_OWNED (type
));
5530 new_type
= alloc_type_copy (type
);
5531 new_type
->set_instance_flags (type
->instance_flags ());
5532 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
5533 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
5534 sizeof (struct main_type
));
5535 if (type
->main_type
->dyn_prop_list
!= NULL
)
5536 new_type
->main_type
->dyn_prop_list
5537 = copy_dynamic_prop_list (&TYPE_OBJFILE (type
) -> objfile_obstack
,
5538 type
->main_type
->dyn_prop_list
);
5543 /* Helper functions to initialize architecture-specific types. */
5545 /* Allocate a type structure associated with GDBARCH and set its
5546 CODE, LENGTH, and NAME fields. */
5549 arch_type (struct gdbarch
*gdbarch
,
5550 enum type_code code
, int bit
, const char *name
)
5554 type
= alloc_type_arch (gdbarch
);
5555 set_type_code (type
, code
);
5556 gdb_assert ((bit
% TARGET_CHAR_BIT
) == 0);
5557 TYPE_LENGTH (type
) = bit
/ TARGET_CHAR_BIT
;
5560 type
->set_name (gdbarch_obstack_strdup (gdbarch
, name
));
5565 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
5566 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
5567 the type's TYPE_UNSIGNED flag. NAME is the type name. */
5570 arch_integer_type (struct gdbarch
*gdbarch
,
5571 int bit
, int unsigned_p
, const char *name
)
5575 t
= arch_type (gdbarch
, TYPE_CODE_INT
, bit
, name
);
5577 t
->set_is_unsigned (true);
5582 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
5583 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
5584 the type's TYPE_UNSIGNED flag. NAME is the type name. */
5587 arch_character_type (struct gdbarch
*gdbarch
,
5588 int bit
, int unsigned_p
, const char *name
)
5592 t
= arch_type (gdbarch
, TYPE_CODE_CHAR
, bit
, name
);
5594 t
->set_is_unsigned (true);
5599 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
5600 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
5601 the type's TYPE_UNSIGNED flag. NAME is the type name. */
5604 arch_boolean_type (struct gdbarch
*gdbarch
,
5605 int bit
, int unsigned_p
, const char *name
)
5609 t
= arch_type (gdbarch
, TYPE_CODE_BOOL
, bit
, name
);
5611 t
->set_is_unsigned (true);
5616 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
5617 BIT is the type size in bits; if BIT equals -1, the size is
5618 determined by the floatformat. NAME is the type name. Set the
5619 TYPE_FLOATFORMAT from FLOATFORMATS. */
5622 arch_float_type (struct gdbarch
*gdbarch
,
5623 int bit
, const char *name
,
5624 const struct floatformat
**floatformats
)
5626 const struct floatformat
*fmt
= floatformats
[gdbarch_byte_order (gdbarch
)];
5629 bit
= verify_floatformat (bit
, fmt
);
5630 t
= arch_type (gdbarch
, TYPE_CODE_FLT
, bit
, name
);
5631 TYPE_FLOATFORMAT (t
) = fmt
;
5636 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with GDBARCH.
5637 BIT is the type size in bits. NAME is the type name. */
5640 arch_decfloat_type (struct gdbarch
*gdbarch
, int bit
, const char *name
)
5644 t
= arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, bit
, name
);
5648 /* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH.
5649 BIT is the pointer type size in bits. NAME is the type name.
5650 TARGET_TYPE is the pointer target type. Always sets the pointer type's
5651 TYPE_UNSIGNED flag. */
5654 arch_pointer_type (struct gdbarch
*gdbarch
,
5655 int bit
, const char *name
, struct type
*target_type
)
5659 t
= arch_type (gdbarch
, TYPE_CODE_PTR
, bit
, name
);
5660 TYPE_TARGET_TYPE (t
) = target_type
;
5661 t
->set_is_unsigned (true);
5665 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
5666 NAME is the type name. BIT is the size of the flag word in bits. */
5669 arch_flags_type (struct gdbarch
*gdbarch
, const char *name
, int bit
)
5673 type
= arch_type (gdbarch
, TYPE_CODE_FLAGS
, bit
, name
);
5674 type
->set_is_unsigned (true);
5675 type
->set_num_fields (0);
5676 /* Pre-allocate enough space assuming every field is one bit. */
5678 ((struct field
*) TYPE_ZALLOC (type
, bit
* sizeof (struct field
)));
5683 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5684 position BITPOS is called NAME. Pass NAME as "" for fields that
5685 should not be printed. */
5688 append_flags_type_field (struct type
*type
, int start_bitpos
, int nr_bits
,
5689 struct type
*field_type
, const char *name
)
5691 int type_bitsize
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
;
5692 int field_nr
= type
->num_fields ();
5694 gdb_assert (type
->code () == TYPE_CODE_FLAGS
);
5695 gdb_assert (type
->num_fields () + 1 <= type_bitsize
);
5696 gdb_assert (start_bitpos
>= 0 && start_bitpos
< type_bitsize
);
5697 gdb_assert (nr_bits
>= 1 && nr_bits
<= type_bitsize
);
5698 gdb_assert (name
!= NULL
);
5700 TYPE_FIELD_NAME (type
, field_nr
) = xstrdup (name
);
5701 type
->field (field_nr
).set_type (field_type
);
5702 SET_FIELD_BITPOS (type
->field (field_nr
), start_bitpos
);
5703 TYPE_FIELD_BITSIZE (type
, field_nr
) = nr_bits
;
5704 type
->set_num_fields (type
->num_fields () + 1);
5707 /* Special version of append_flags_type_field to add a flag field.
5708 Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5709 position BITPOS is called NAME. */
5712 append_flags_type_flag (struct type
*type
, int bitpos
, const char *name
)
5714 struct gdbarch
*gdbarch
= get_type_arch (type
);
5716 append_flags_type_field (type
, bitpos
, 1,
5717 builtin_type (gdbarch
)->builtin_bool
,
5721 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
5722 specified by CODE) associated with GDBARCH. NAME is the type name. */
5725 arch_composite_type (struct gdbarch
*gdbarch
, const char *name
,
5726 enum type_code code
)
5730 gdb_assert (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
);
5731 t
= arch_type (gdbarch
, code
, 0, NULL
);
5733 INIT_CPLUS_SPECIFIC (t
);
5737 /* Add new field with name NAME and type FIELD to composite type T.
5738 Do not set the field's position or adjust the type's length;
5739 the caller should do so. Return the new field. */
5742 append_composite_type_field_raw (struct type
*t
, const char *name
,
5747 t
->set_num_fields (t
->num_fields () + 1);
5748 t
->set_fields (XRESIZEVEC (struct field
, t
->fields (),
5750 f
= &t
->field (t
->num_fields () - 1);
5751 memset (f
, 0, sizeof f
[0]);
5752 f
[0].set_type (field
);
5753 FIELD_NAME (f
[0]) = name
;
5757 /* Add new field with name NAME and type FIELD to composite type T.
5758 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
5761 append_composite_type_field_aligned (struct type
*t
, const char *name
,
5762 struct type
*field
, int alignment
)
5764 struct field
*f
= append_composite_type_field_raw (t
, name
, field
);
5766 if (t
->code () == TYPE_CODE_UNION
)
5768 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
5769 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
5771 else if (t
->code () == TYPE_CODE_STRUCT
)
5773 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
5774 if (t
->num_fields () > 1)
5776 SET_FIELD_BITPOS (f
[0],
5777 (FIELD_BITPOS (f
[-1])
5778 + (TYPE_LENGTH (f
[-1].type ())
5779 * TARGET_CHAR_BIT
)));
5785 alignment
*= TARGET_CHAR_BIT
;
5786 left
= FIELD_BITPOS (f
[0]) % alignment
;
5790 SET_FIELD_BITPOS (f
[0], FIELD_BITPOS (f
[0]) + (alignment
- left
));
5791 TYPE_LENGTH (t
) += (alignment
- left
) / TARGET_CHAR_BIT
;
5798 /* Add new field with name NAME and type FIELD to composite type T. */
5801 append_composite_type_field (struct type
*t
, const char *name
,
5804 append_composite_type_field_aligned (t
, name
, field
, 0);
5809 /* We manage the lifetimes of fixed_point_type_info objects by
5810 attaching them to the objfile. Currently, these objects are
5811 modified during construction, and GMP does not provide a way to
5812 hash the contents of an mpq_t; so it's a bit of a pain to hash-cons
5813 them. If we did do this, they could be moved to the per-BFD and
5814 shared across objfiles. */
5815 typedef std::vector
<std::unique_ptr
<fixed_point_type_info
>>
5816 fixed_point_type_storage
;
5818 /* Key used for managing the storage of fixed-point type info. */
5819 static const struct objfile_key
<fixed_point_type_storage
>
5820 fixed_point_objfile_key
;
5822 /* See gdbtypes.h. */
5824 fixed_point_type_info
*
5825 allocate_fixed_point_type_info (struct type
*type
)
5827 std::unique_ptr
<fixed_point_type_info
> up (new fixed_point_type_info
);
5828 fixed_point_type_info
*result
;
5830 if (TYPE_OBJFILE_OWNED (type
))
5832 fixed_point_type_storage
*storage
5833 = fixed_point_objfile_key
.get (TYPE_OBJFILE (type
));
5834 if (storage
== nullptr)
5835 storage
= fixed_point_objfile_key
.emplace (TYPE_OBJFILE (type
));
5837 storage
->push_back (std::move (up
));
5841 /* We just leak the memory, because that's what we do generally
5842 for non-objfile-attached types. */
5843 result
= up
.release ();
5849 /* See gdbtypes.h. */
5852 is_fixed_point_type (struct type
*type
)
5854 while (check_typedef (type
)->code () == TYPE_CODE_RANGE
)
5855 type
= TYPE_TARGET_TYPE (check_typedef (type
));
5856 type
= check_typedef (type
);
5858 return type
->code () == TYPE_CODE_FIXED_POINT
;
5861 /* See gdbtypes.h. */
5864 fixed_point_type_base_type (struct type
*type
)
5866 while (check_typedef (type
)->code () == TYPE_CODE_RANGE
)
5867 type
= TYPE_TARGET_TYPE (check_typedef (type
));
5868 type
= check_typedef (type
);
5870 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
);
5874 /* See gdbtypes.h. */
5877 fixed_point_scaling_factor (struct type
*type
)
5879 type
= fixed_point_type_base_type (type
);
5881 return TYPE_FIXED_POINT_INFO (type
)->scaling_factor
;
5886 static struct gdbarch_data
*gdbtypes_data
;
5888 const struct builtin_type
*
5889 builtin_type (struct gdbarch
*gdbarch
)
5891 return (const struct builtin_type
*) gdbarch_data (gdbarch
, gdbtypes_data
);
5895 gdbtypes_post_init (struct gdbarch
*gdbarch
)
5897 struct builtin_type
*builtin_type
5898 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
5901 builtin_type
->builtin_void
5902 = arch_type (gdbarch
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
5903 builtin_type
->builtin_char
5904 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
5905 !gdbarch_char_signed (gdbarch
), "char");
5906 builtin_type
->builtin_char
->set_has_no_signedness (true);
5907 builtin_type
->builtin_signed_char
5908 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
5910 builtin_type
->builtin_unsigned_char
5911 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
5912 1, "unsigned char");
5913 builtin_type
->builtin_short
5914 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
5916 builtin_type
->builtin_unsigned_short
5917 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
5918 1, "unsigned short");
5919 builtin_type
->builtin_int
5920 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
5922 builtin_type
->builtin_unsigned_int
5923 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
5925 builtin_type
->builtin_long
5926 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
5928 builtin_type
->builtin_unsigned_long
5929 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
5930 1, "unsigned long");
5931 builtin_type
->builtin_long_long
5932 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
5934 builtin_type
->builtin_unsigned_long_long
5935 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
5936 1, "unsigned long long");
5937 builtin_type
->builtin_half
5938 = arch_float_type (gdbarch
, gdbarch_half_bit (gdbarch
),
5939 "half", gdbarch_half_format (gdbarch
));
5940 builtin_type
->builtin_float
5941 = arch_float_type (gdbarch
, gdbarch_float_bit (gdbarch
),
5942 "float", gdbarch_float_format (gdbarch
));
5943 builtin_type
->builtin_bfloat16
5944 = arch_float_type (gdbarch
, gdbarch_bfloat16_bit (gdbarch
),
5945 "bfloat16", gdbarch_bfloat16_format (gdbarch
));
5946 builtin_type
->builtin_double
5947 = arch_float_type (gdbarch
, gdbarch_double_bit (gdbarch
),
5948 "double", gdbarch_double_format (gdbarch
));
5949 builtin_type
->builtin_long_double
5950 = arch_float_type (gdbarch
, gdbarch_long_double_bit (gdbarch
),
5951 "long double", gdbarch_long_double_format (gdbarch
));
5952 builtin_type
->builtin_complex
5953 = init_complex_type ("complex", builtin_type
->builtin_float
);
5954 builtin_type
->builtin_double_complex
5955 = init_complex_type ("double complex", builtin_type
->builtin_double
);
5956 builtin_type
->builtin_string
5957 = arch_type (gdbarch
, TYPE_CODE_STRING
, TARGET_CHAR_BIT
, "string");
5958 builtin_type
->builtin_bool
5959 = arch_type (gdbarch
, TYPE_CODE_BOOL
, TARGET_CHAR_BIT
, "bool");
5961 /* The following three are about decimal floating point types, which
5962 are 32-bits, 64-bits and 128-bits respectively. */
5963 builtin_type
->builtin_decfloat
5964 = arch_decfloat_type (gdbarch
, 32, "_Decimal32");
5965 builtin_type
->builtin_decdouble
5966 = arch_decfloat_type (gdbarch
, 64, "_Decimal64");
5967 builtin_type
->builtin_declong
5968 = arch_decfloat_type (gdbarch
, 128, "_Decimal128");
5970 /* "True" character types. */
5971 builtin_type
->builtin_true_char
5972 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 0, "true character");
5973 builtin_type
->builtin_true_unsigned_char
5974 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 1, "true character");
5976 /* Fixed-size integer types. */
5977 builtin_type
->builtin_int0
5978 = arch_integer_type (gdbarch
, 0, 0, "int0_t");
5979 builtin_type
->builtin_int8
5980 = arch_integer_type (gdbarch
, 8, 0, "int8_t");
5981 builtin_type
->builtin_uint8
5982 = arch_integer_type (gdbarch
, 8, 1, "uint8_t");
5983 builtin_type
->builtin_int16
5984 = arch_integer_type (gdbarch
, 16, 0, "int16_t");
5985 builtin_type
->builtin_uint16
5986 = arch_integer_type (gdbarch
, 16, 1, "uint16_t");
5987 builtin_type
->builtin_int24
5988 = arch_integer_type (gdbarch
, 24, 0, "int24_t");
5989 builtin_type
->builtin_uint24
5990 = arch_integer_type (gdbarch
, 24, 1, "uint24_t");
5991 builtin_type
->builtin_int32
5992 = arch_integer_type (gdbarch
, 32, 0, "int32_t");
5993 builtin_type
->builtin_uint32
5994 = arch_integer_type (gdbarch
, 32, 1, "uint32_t");
5995 builtin_type
->builtin_int64
5996 = arch_integer_type (gdbarch
, 64, 0, "int64_t");
5997 builtin_type
->builtin_uint64
5998 = arch_integer_type (gdbarch
, 64, 1, "uint64_t");
5999 builtin_type
->builtin_int128
6000 = arch_integer_type (gdbarch
, 128, 0, "int128_t");
6001 builtin_type
->builtin_uint128
6002 = arch_integer_type (gdbarch
, 128, 1, "uint128_t");
6004 builtin_type
->builtin_int8
->set_instance_flags
6005 (builtin_type
->builtin_int8
->instance_flags ()
6006 | TYPE_INSTANCE_FLAG_NOTTEXT
);
6008 builtin_type
->builtin_uint8
->set_instance_flags
6009 (builtin_type
->builtin_uint8
->instance_flags ()
6010 | TYPE_INSTANCE_FLAG_NOTTEXT
);
6012 /* Wide character types. */
6013 builtin_type
->builtin_char16
6014 = arch_integer_type (gdbarch
, 16, 1, "char16_t");
6015 builtin_type
->builtin_char32
6016 = arch_integer_type (gdbarch
, 32, 1, "char32_t");
6017 builtin_type
->builtin_wchar
6018 = arch_integer_type (gdbarch
, gdbarch_wchar_bit (gdbarch
),
6019 !gdbarch_wchar_signed (gdbarch
), "wchar_t");
6021 /* Default data/code pointer types. */
6022 builtin_type
->builtin_data_ptr
6023 = lookup_pointer_type (builtin_type
->builtin_void
);
6024 builtin_type
->builtin_func_ptr
6025 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
6026 builtin_type
->builtin_func_func
6027 = lookup_function_type (builtin_type
->builtin_func_ptr
);
6029 /* This type represents a GDB internal function. */
6030 builtin_type
->internal_fn
6031 = arch_type (gdbarch
, TYPE_CODE_INTERNAL_FUNCTION
, 0,
6032 "<internal function>");
6034 /* This type represents an xmethod. */
6035 builtin_type
->xmethod
6036 = arch_type (gdbarch
, TYPE_CODE_XMETHOD
, 0, "<xmethod>");
6038 return builtin_type
;
6041 /* This set of objfile-based types is intended to be used by symbol
6042 readers as basic types. */
6044 static const struct objfile_key
<struct objfile_type
,
6045 gdb::noop_deleter
<struct objfile_type
>>
6048 const struct objfile_type
*
6049 objfile_type (struct objfile
*objfile
)
6051 struct gdbarch
*gdbarch
;
6052 struct objfile_type
*objfile_type
= objfile_type_data
.get (objfile
);
6055 return objfile_type
;
6057 objfile_type
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
6058 1, struct objfile_type
);
6060 /* Use the objfile architecture to determine basic type properties. */
6061 gdbarch
= objfile
->arch ();
6064 objfile_type
->builtin_void
6065 = init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
6066 objfile_type
->builtin_char
6067 = init_integer_type (objfile
, TARGET_CHAR_BIT
,
6068 !gdbarch_char_signed (gdbarch
), "char");
6069 objfile_type
->builtin_char
->set_has_no_signedness (true);
6070 objfile_type
->builtin_signed_char
6071 = init_integer_type (objfile
, TARGET_CHAR_BIT
,
6073 objfile_type
->builtin_unsigned_char
6074 = init_integer_type (objfile
, TARGET_CHAR_BIT
,
6075 1, "unsigned char");
6076 objfile_type
->builtin_short
6077 = init_integer_type (objfile
, gdbarch_short_bit (gdbarch
),
6079 objfile_type
->builtin_unsigned_short
6080 = init_integer_type (objfile
, gdbarch_short_bit (gdbarch
),
6081 1, "unsigned short");
6082 objfile_type
->builtin_int
6083 = init_integer_type (objfile
, gdbarch_int_bit (gdbarch
),
6085 objfile_type
->builtin_unsigned_int
6086 = init_integer_type (objfile
, gdbarch_int_bit (gdbarch
),
6088 objfile_type
->builtin_long
6089 = init_integer_type (objfile
, gdbarch_long_bit (gdbarch
),
6091 objfile_type
->builtin_unsigned_long
6092 = init_integer_type (objfile
, gdbarch_long_bit (gdbarch
),
6093 1, "unsigned long");
6094 objfile_type
->builtin_long_long
6095 = init_integer_type (objfile
, gdbarch_long_long_bit (gdbarch
),
6097 objfile_type
->builtin_unsigned_long_long
6098 = init_integer_type (objfile
, gdbarch_long_long_bit (gdbarch
),
6099 1, "unsigned long long");
6100 objfile_type
->builtin_float
6101 = init_float_type (objfile
, gdbarch_float_bit (gdbarch
),
6102 "float", gdbarch_float_format (gdbarch
));
6103 objfile_type
->builtin_double
6104 = init_float_type (objfile
, gdbarch_double_bit (gdbarch
),
6105 "double", gdbarch_double_format (gdbarch
));
6106 objfile_type
->builtin_long_double
6107 = init_float_type (objfile
, gdbarch_long_double_bit (gdbarch
),
6108 "long double", gdbarch_long_double_format (gdbarch
));
6110 /* This type represents a type that was unrecognized in symbol read-in. */
6111 objfile_type
->builtin_error
6112 = init_type (objfile
, TYPE_CODE_ERROR
, 0, "<unknown type>");
6114 /* The following set of types is used for symbols with no
6115 debug information. */
6116 objfile_type
->nodebug_text_symbol
6117 = init_type (objfile
, TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
6118 "<text variable, no debug info>");
6120 objfile_type
->nodebug_text_gnu_ifunc_symbol
6121 = init_type (objfile
, TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
6122 "<text gnu-indirect-function variable, no debug info>");
6123 objfile_type
->nodebug_text_gnu_ifunc_symbol
->set_is_gnu_ifunc (true);
6125 objfile_type
->nodebug_got_plt_symbol
6126 = init_pointer_type (objfile
, gdbarch_addr_bit (gdbarch
),
6127 "<text from jump slot in .got.plt, no debug info>",
6128 objfile_type
->nodebug_text_symbol
);
6129 objfile_type
->nodebug_data_symbol
6130 = init_nodebug_var_type (objfile
, "<data variable, no debug info>");
6131 objfile_type
->nodebug_unknown_symbol
6132 = init_nodebug_var_type (objfile
, "<variable (not text or data), no debug info>");
6133 objfile_type
->nodebug_tls_symbol
6134 = init_nodebug_var_type (objfile
, "<thread local variable, no debug info>");
6136 /* NOTE: on some targets, addresses and pointers are not necessarily
6140 - gdb's `struct type' always describes the target's
6142 - gdb's `struct value' objects should always hold values in
6144 - gdb's CORE_ADDR values are addresses in the unified virtual
6145 address space that the assembler and linker work with. Thus,
6146 since target_read_memory takes a CORE_ADDR as an argument, it
6147 can access any memory on the target, even if the processor has
6148 separate code and data address spaces.
6150 In this context, objfile_type->builtin_core_addr is a bit odd:
6151 it's a target type for a value the target will never see. It's
6152 only used to hold the values of (typeless) linker symbols, which
6153 are indeed in the unified virtual address space. */
6155 objfile_type
->builtin_core_addr
6156 = init_integer_type (objfile
, gdbarch_addr_bit (gdbarch
), 1,
6159 objfile_type_data
.set (objfile
, objfile_type
);
6160 return objfile_type
;
6163 void _initialize_gdbtypes ();
6165 _initialize_gdbtypes ()
6167 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
6169 add_setshow_zuinteger_cmd ("overload", no_class
, &overload_debug
,
6170 _("Set debugging of C++ overloading."),
6171 _("Show debugging of C++ overloading."),
6172 _("When enabled, ranking of the "
6173 "functions is displayed."),
6175 show_overload_debug
,
6176 &setdebuglist
, &showdebuglist
);
6178 /* Add user knob for controlling resolution of opaque types. */
6179 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
6180 &opaque_type_resolution
,
6181 _("Set resolution of opaque struct/class/union"
6182 " types (if set before loading symbols)."),
6183 _("Show resolution of opaque struct/class/union"
6184 " types (if set before loading symbols)."),
6186 show_opaque_type_resolution
,
6187 &setlist
, &showlist
);
6189 /* Add an option to permit non-strict type checking. */
6190 add_setshow_boolean_cmd ("type", class_support
,
6191 &strict_type_checking
,
6192 _("Set strict type checking."),
6193 _("Show strict type checking."),
6195 show_strict_type_checking
,
6196 &setchecklist
, &showchecklist
);