1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2018 Free Software Foundation, Inc.
5 Contributed by Cygnus Support, using pieces from other GDB modules.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "expression.h"
33 #include "complaints.h"
37 #include "cp-support.h"
39 #include "dwarf2loc.h"
41 #include "floatformat.h"
43 /* Initialize BADNESS constants. */
45 const struct rank LENGTH_MISMATCH_BADNESS
= {100,0};
47 const struct rank TOO_FEW_PARAMS_BADNESS
= {100,0};
48 const struct rank INCOMPATIBLE_TYPE_BADNESS
= {100,0};
50 const struct rank EXACT_MATCH_BADNESS
= {0,0};
52 const struct rank INTEGER_PROMOTION_BADNESS
= {1,0};
53 const struct rank FLOAT_PROMOTION_BADNESS
= {1,0};
54 const struct rank BASE_PTR_CONVERSION_BADNESS
= {1,0};
55 const struct rank CV_CONVERSION_BADNESS
= {1, 0};
56 const struct rank INTEGER_CONVERSION_BADNESS
= {2,0};
57 const struct rank FLOAT_CONVERSION_BADNESS
= {2,0};
58 const struct rank INT_FLOAT_CONVERSION_BADNESS
= {2,0};
59 const struct rank VOID_PTR_CONVERSION_BADNESS
= {2,0};
60 const struct rank BOOL_CONVERSION_BADNESS
= {3,0};
61 const struct rank BASE_CONVERSION_BADNESS
= {2,0};
62 const struct rank REFERENCE_CONVERSION_BADNESS
= {2,0};
63 const struct rank NULL_POINTER_CONVERSION_BADNESS
= {2,0};
64 const struct rank NS_POINTER_CONVERSION_BADNESS
= {10,0};
65 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS
= {3,0};
67 /* Floatformat pairs. */
68 const struct floatformat
*floatformats_ieee_half
[BFD_ENDIAN_UNKNOWN
] = {
69 &floatformat_ieee_half_big
,
70 &floatformat_ieee_half_little
72 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
73 &floatformat_ieee_single_big
,
74 &floatformat_ieee_single_little
76 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
77 &floatformat_ieee_double_big
,
78 &floatformat_ieee_double_little
80 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
81 &floatformat_ieee_double_big
,
82 &floatformat_ieee_double_littlebyte_bigword
84 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
85 &floatformat_i387_ext
,
88 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
89 &floatformat_m68881_ext
,
90 &floatformat_m68881_ext
92 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
93 &floatformat_arm_ext_big
,
94 &floatformat_arm_ext_littlebyte_bigword
96 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
97 &floatformat_ia64_spill_big
,
98 &floatformat_ia64_spill_little
100 const struct floatformat
*floatformats_ia64_quad
[BFD_ENDIAN_UNKNOWN
] = {
101 &floatformat_ia64_quad_big
,
102 &floatformat_ia64_quad_little
104 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
108 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
112 const struct floatformat
*floatformats_ibm_long_double
[BFD_ENDIAN_UNKNOWN
] = {
113 &floatformat_ibm_long_double_big
,
114 &floatformat_ibm_long_double_little
117 /* Should opaque types be resolved? */
119 static int opaque_type_resolution
= 1;
121 /* A flag to enable printing of debugging information of C++
124 unsigned int overload_debug
= 0;
126 /* A flag to enable strict type checking. */
128 static int strict_type_checking
= 1;
130 /* A function to show whether opaque types are resolved. */
133 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
134 struct cmd_list_element
*c
,
137 fprintf_filtered (file
, _("Resolution of opaque struct/class/union types "
138 "(if set before loading symbols) is %s.\n"),
142 /* A function to show whether C++ overload debugging is enabled. */
145 show_overload_debug (struct ui_file
*file
, int from_tty
,
146 struct cmd_list_element
*c
, const char *value
)
148 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"),
152 /* A function to show the status of strict type checking. */
155 show_strict_type_checking (struct ui_file
*file
, int from_tty
,
156 struct cmd_list_element
*c
, const char *value
)
158 fprintf_filtered (file
, _("Strict type checking is %s.\n"), value
);
162 /* Allocate a new OBJFILE-associated type structure and fill it
163 with some defaults. Space for the type structure is allocated
164 on the objfile's objfile_obstack. */
167 alloc_type (struct objfile
*objfile
)
171 gdb_assert (objfile
!= NULL
);
173 /* Alloc the structure and start off with all fields zeroed. */
174 type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct type
);
175 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
177 OBJSTAT (objfile
, n_types
++);
179 TYPE_OBJFILE_OWNED (type
) = 1;
180 TYPE_OWNER (type
).objfile
= objfile
;
182 /* Initialize the fields that might not be zero. */
184 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
185 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
190 /* Allocate a new GDBARCH-associated type structure and fill it
191 with some defaults. Space for the type structure is allocated
192 on the obstack associated with GDBARCH. */
195 alloc_type_arch (struct gdbarch
*gdbarch
)
199 gdb_assert (gdbarch
!= NULL
);
201 /* Alloc the structure and start off with all fields zeroed. */
203 type
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct type
);
204 TYPE_MAIN_TYPE (type
) = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct main_type
);
206 TYPE_OBJFILE_OWNED (type
) = 0;
207 TYPE_OWNER (type
).gdbarch
= gdbarch
;
209 /* Initialize the fields that might not be zero. */
211 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
212 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
217 /* If TYPE is objfile-associated, allocate a new type structure
218 associated with the same objfile. If TYPE is gdbarch-associated,
219 allocate a new type structure associated with the same gdbarch. */
222 alloc_type_copy (const struct type
*type
)
224 if (TYPE_OBJFILE_OWNED (type
))
225 return alloc_type (TYPE_OWNER (type
).objfile
);
227 return alloc_type_arch (TYPE_OWNER (type
).gdbarch
);
230 /* If TYPE is gdbarch-associated, return that architecture.
231 If TYPE is objfile-associated, return that objfile's architecture. */
234 get_type_arch (const struct type
*type
)
236 if (TYPE_OBJFILE_OWNED (type
))
237 return get_objfile_arch (TYPE_OWNER (type
).objfile
);
239 return TYPE_OWNER (type
).gdbarch
;
242 /* See gdbtypes.h. */
245 get_target_type (struct type
*type
)
249 type
= TYPE_TARGET_TYPE (type
);
251 type
= check_typedef (type
);
257 /* See gdbtypes.h. */
260 type_length_units (struct type
*type
)
262 struct gdbarch
*arch
= get_type_arch (type
);
263 int unit_size
= gdbarch_addressable_memory_unit_size (arch
);
265 return TYPE_LENGTH (type
) / unit_size
;
268 /* Alloc a new type instance structure, fill it with some defaults,
269 and point it at OLDTYPE. Allocate the new type instance from the
270 same place as OLDTYPE. */
273 alloc_type_instance (struct type
*oldtype
)
277 /* Allocate the structure. */
279 if (! TYPE_OBJFILE_OWNED (oldtype
))
280 type
= XCNEW (struct type
);
282 type
= OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
285 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
287 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
292 /* Clear all remnants of the previous type at TYPE, in preparation for
293 replacing it with something else. Preserve owner information. */
296 smash_type (struct type
*type
)
298 int objfile_owned
= TYPE_OBJFILE_OWNED (type
);
299 union type_owner owner
= TYPE_OWNER (type
);
301 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
303 /* Restore owner information. */
304 TYPE_OBJFILE_OWNED (type
) = objfile_owned
;
305 TYPE_OWNER (type
) = owner
;
307 /* For now, delete the rings. */
308 TYPE_CHAIN (type
) = type
;
310 /* For now, leave the pointer/reference types alone. */
313 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
314 to a pointer to memory where the pointer type should be stored.
315 If *TYPEPTR is zero, update it to point to the pointer type we return.
316 We allocate new memory if needed. */
319 make_pointer_type (struct type
*type
, struct type
**typeptr
)
321 struct type
*ntype
; /* New type */
324 ntype
= TYPE_POINTER_TYPE (type
);
329 return ntype
; /* Don't care about alloc,
330 and have new type. */
331 else if (*typeptr
== 0)
333 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
338 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
340 ntype
= alloc_type_copy (type
);
344 else /* We have storage, but need to reset it. */
347 chain
= TYPE_CHAIN (ntype
);
349 TYPE_CHAIN (ntype
) = chain
;
352 TYPE_TARGET_TYPE (ntype
) = type
;
353 TYPE_POINTER_TYPE (type
) = ntype
;
355 /* FIXME! Assumes the machine has only one representation for pointers! */
358 = gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
359 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
361 /* Mark pointers as unsigned. The target converts between pointers
362 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
363 gdbarch_address_to_pointer. */
364 TYPE_UNSIGNED (ntype
) = 1;
366 /* Update the length of all the other variants of this type. */
367 chain
= TYPE_CHAIN (ntype
);
368 while (chain
!= ntype
)
370 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
371 chain
= TYPE_CHAIN (chain
);
377 /* Given a type TYPE, return a type of pointers to that type.
378 May need to construct such a type if this is the first use. */
381 lookup_pointer_type (struct type
*type
)
383 return make_pointer_type (type
, (struct type
**) 0);
386 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
387 points to a pointer to memory where the reference type should be
388 stored. If *TYPEPTR is zero, update it to point to the reference
389 type we return. We allocate new memory if needed. REFCODE denotes
390 the kind of reference type to lookup (lvalue or rvalue reference). */
393 make_reference_type (struct type
*type
, struct type
**typeptr
,
394 enum type_code refcode
)
396 struct type
*ntype
; /* New type */
397 struct type
**reftype
;
400 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
402 ntype
= (refcode
== TYPE_CODE_REF
? TYPE_REFERENCE_TYPE (type
)
403 : TYPE_RVALUE_REFERENCE_TYPE (type
));
408 return ntype
; /* Don't care about alloc,
409 and have new type. */
410 else if (*typeptr
== 0)
412 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
417 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
419 ntype
= alloc_type_copy (type
);
423 else /* We have storage, but need to reset it. */
426 chain
= TYPE_CHAIN (ntype
);
428 TYPE_CHAIN (ntype
) = chain
;
431 TYPE_TARGET_TYPE (ntype
) = type
;
432 reftype
= (refcode
== TYPE_CODE_REF
? &TYPE_REFERENCE_TYPE (type
)
433 : &TYPE_RVALUE_REFERENCE_TYPE (type
));
437 /* FIXME! Assume the machine has only one representation for
438 references, and that it matches the (only) representation for
441 TYPE_LENGTH (ntype
) =
442 gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
443 TYPE_CODE (ntype
) = refcode
;
447 /* Update the length of all the other variants of this type. */
448 chain
= TYPE_CHAIN (ntype
);
449 while (chain
!= ntype
)
451 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
452 chain
= TYPE_CHAIN (chain
);
458 /* Same as above, but caller doesn't care about memory allocation
462 lookup_reference_type (struct type
*type
, enum type_code refcode
)
464 return make_reference_type (type
, (struct type
**) 0, refcode
);
467 /* Lookup the lvalue reference type for the type TYPE. */
470 lookup_lvalue_reference_type (struct type
*type
)
472 return lookup_reference_type (type
, TYPE_CODE_REF
);
475 /* Lookup the rvalue reference type for the type TYPE. */
478 lookup_rvalue_reference_type (struct type
*type
)
480 return lookup_reference_type (type
, TYPE_CODE_RVALUE_REF
);
483 /* Lookup a function type that returns type TYPE. TYPEPTR, if
484 nonzero, points to a pointer to memory where the function type
485 should be stored. If *TYPEPTR is zero, update it to point to the
486 function type we return. We allocate new memory if needed. */
489 make_function_type (struct type
*type
, struct type
**typeptr
)
491 struct type
*ntype
; /* New type */
493 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
495 ntype
= alloc_type_copy (type
);
499 else /* We have storage, but need to reset it. */
505 TYPE_TARGET_TYPE (ntype
) = type
;
507 TYPE_LENGTH (ntype
) = 1;
508 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
510 INIT_FUNC_SPECIFIC (ntype
);
515 /* Given a type TYPE, return a type of functions that return that type.
516 May need to construct such a type if this is the first use. */
519 lookup_function_type (struct type
*type
)
521 return make_function_type (type
, (struct type
**) 0);
524 /* Given a type TYPE and argument types, return the appropriate
525 function type. If the final type in PARAM_TYPES is NULL, make a
529 lookup_function_type_with_arguments (struct type
*type
,
531 struct type
**param_types
)
533 struct type
*fn
= make_function_type (type
, (struct type
**) 0);
538 if (param_types
[nparams
- 1] == NULL
)
541 TYPE_VARARGS (fn
) = 1;
543 else if (TYPE_CODE (check_typedef (param_types
[nparams
- 1]))
547 /* Caller should have ensured this. */
548 gdb_assert (nparams
== 0);
549 TYPE_PROTOTYPED (fn
) = 1;
552 TYPE_PROTOTYPED (fn
) = 1;
555 TYPE_NFIELDS (fn
) = nparams
;
557 = (struct field
*) TYPE_ZALLOC (fn
, nparams
* sizeof (struct field
));
558 for (i
= 0; i
< nparams
; ++i
)
559 TYPE_FIELD_TYPE (fn
, i
) = param_types
[i
];
564 /* Identify address space identifier by name --
565 return the integer flag defined in gdbtypes.h. */
568 address_space_name_to_int (struct gdbarch
*gdbarch
, char *space_identifier
)
572 /* Check for known address space delimiters. */
573 if (!strcmp (space_identifier
, "code"))
574 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
575 else if (!strcmp (space_identifier
, "data"))
576 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
577 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
578 && gdbarch_address_class_name_to_type_flags (gdbarch
,
583 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
586 /* Identify address space identifier by integer flag as defined in
587 gdbtypes.h -- return the string version of the adress space name. */
590 address_space_int_to_name (struct gdbarch
*gdbarch
, int space_flag
)
592 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
594 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
596 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
597 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
598 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
603 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
605 If STORAGE is non-NULL, create the new type instance there.
606 STORAGE must be in the same obstack as TYPE. */
609 make_qualified_type (struct type
*type
, int new_flags
,
610 struct type
*storage
)
617 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
619 ntype
= TYPE_CHAIN (ntype
);
621 while (ntype
!= type
);
623 /* Create a new type instance. */
625 ntype
= alloc_type_instance (type
);
628 /* If STORAGE was provided, it had better be in the same objfile
629 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
630 if one objfile is freed and the other kept, we'd have
631 dangling pointers. */
632 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
635 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
636 TYPE_CHAIN (ntype
) = ntype
;
639 /* Pointers or references to the original type are not relevant to
641 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
642 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
644 /* Chain the new qualified type to the old type. */
645 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
646 TYPE_CHAIN (type
) = ntype
;
648 /* Now set the instance flags and return the new type. */
649 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
651 /* Set length of new type to that of the original type. */
652 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
657 /* Make an address-space-delimited variant of a type -- a type that
658 is identical to the one supplied except that it has an address
659 space attribute attached to it (such as "code" or "data").
661 The space attributes "code" and "data" are for Harvard
662 architectures. The address space attributes are for architectures
663 which have alternately sized pointers or pointers with alternate
667 make_type_with_address_space (struct type
*type
, int space_flag
)
669 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
670 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
671 | TYPE_INSTANCE_FLAG_DATA_SPACE
672 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
675 return make_qualified_type (type
, new_flags
, NULL
);
678 /* Make a "c-v" variant of a type -- a type that is identical to the
679 one supplied except that it may have const or volatile attributes
680 CNST is a flag for setting the const attribute
681 VOLTL is a flag for setting the volatile attribute
682 TYPE is the base type whose variant we are creating.
684 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
685 storage to hold the new qualified type; *TYPEPTR and TYPE must be
686 in the same objfile. Otherwise, allocate fresh memory for the new
687 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
688 new type we construct. */
691 make_cv_type (int cnst
, int voltl
,
693 struct type
**typeptr
)
695 struct type
*ntype
; /* New type */
697 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
698 & ~(TYPE_INSTANCE_FLAG_CONST
699 | TYPE_INSTANCE_FLAG_VOLATILE
));
702 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
705 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
707 if (typeptr
&& *typeptr
!= NULL
)
709 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
710 a C-V variant chain that threads across objfiles: if one
711 objfile gets freed, then the other has a broken C-V chain.
713 This code used to try to copy over the main type from TYPE to
714 *TYPEPTR if they were in different objfiles, but that's
715 wrong, too: TYPE may have a field list or member function
716 lists, which refer to types of their own, etc. etc. The
717 whole shebang would need to be copied over recursively; you
718 can't have inter-objfile pointers. The only thing to do is
719 to leave stub types as stub types, and look them up afresh by
720 name each time you encounter them. */
721 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
724 ntype
= make_qualified_type (type
, new_flags
,
725 typeptr
? *typeptr
: NULL
);
733 /* Make a 'restrict'-qualified version of TYPE. */
736 make_restrict_type (struct type
*type
)
738 return make_qualified_type (type
,
739 (TYPE_INSTANCE_FLAGS (type
)
740 | TYPE_INSTANCE_FLAG_RESTRICT
),
744 /* Make a type without const, volatile, or restrict. */
747 make_unqualified_type (struct type
*type
)
749 return make_qualified_type (type
,
750 (TYPE_INSTANCE_FLAGS (type
)
751 & ~(TYPE_INSTANCE_FLAG_CONST
752 | TYPE_INSTANCE_FLAG_VOLATILE
753 | TYPE_INSTANCE_FLAG_RESTRICT
)),
757 /* Make a '_Atomic'-qualified version of TYPE. */
760 make_atomic_type (struct type
*type
)
762 return make_qualified_type (type
,
763 (TYPE_INSTANCE_FLAGS (type
)
764 | TYPE_INSTANCE_FLAG_ATOMIC
),
768 /* Replace the contents of ntype with the type *type. This changes the
769 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
770 the changes are propogated to all types in the TYPE_CHAIN.
772 In order to build recursive types, it's inevitable that we'll need
773 to update types in place --- but this sort of indiscriminate
774 smashing is ugly, and needs to be replaced with something more
775 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
776 clear if more steps are needed. */
779 replace_type (struct type
*ntype
, struct type
*type
)
783 /* These two types had better be in the same objfile. Otherwise,
784 the assignment of one type's main type structure to the other
785 will produce a type with references to objects (names; field
786 lists; etc.) allocated on an objfile other than its own. */
787 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (type
));
789 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
791 /* The type length is not a part of the main type. Update it for
792 each type on the variant chain. */
796 /* Assert that this element of the chain has no address-class bits
797 set in its flags. Such type variants might have type lengths
798 which are supposed to be different from the non-address-class
799 variants. This assertion shouldn't ever be triggered because
800 symbol readers which do construct address-class variants don't
801 call replace_type(). */
802 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
804 TYPE_LENGTH (chain
) = TYPE_LENGTH (type
);
805 chain
= TYPE_CHAIN (chain
);
807 while (ntype
!= chain
);
809 /* Assert that the two types have equivalent instance qualifiers.
810 This should be true for at least all of our debug readers. */
811 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
814 /* Implement direct support for MEMBER_TYPE in GNU C++.
815 May need to construct such a type if this is the first use.
816 The TYPE is the type of the member. The DOMAIN is the type
817 of the aggregate that the member belongs to. */
820 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
824 mtype
= alloc_type_copy (type
);
825 smash_to_memberptr_type (mtype
, domain
, type
);
829 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
832 lookup_methodptr_type (struct type
*to_type
)
836 mtype
= alloc_type_copy (to_type
);
837 smash_to_methodptr_type (mtype
, to_type
);
841 /* Allocate a stub method whose return type is TYPE. This apparently
842 happens for speed of symbol reading, since parsing out the
843 arguments to the method is cpu-intensive, the way we are doing it.
844 So, we will fill in arguments later. This always returns a fresh
848 allocate_stub_method (struct type
*type
)
852 mtype
= alloc_type_copy (type
);
853 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
854 TYPE_LENGTH (mtype
) = 1;
855 TYPE_STUB (mtype
) = 1;
856 TYPE_TARGET_TYPE (mtype
) = type
;
857 /* TYPE_SELF_TYPE (mtype) = unknown yet */
861 /* Create a range type with a dynamic range from LOW_BOUND to
862 HIGH_BOUND, inclusive. See create_range_type for further details. */
865 create_range_type (struct type
*result_type
, struct type
*index_type
,
866 const struct dynamic_prop
*low_bound
,
867 const struct dynamic_prop
*high_bound
)
869 if (result_type
== NULL
)
870 result_type
= alloc_type_copy (index_type
);
871 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
872 TYPE_TARGET_TYPE (result_type
) = index_type
;
873 if (TYPE_STUB (index_type
))
874 TYPE_TARGET_STUB (result_type
) = 1;
876 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
878 TYPE_RANGE_DATA (result_type
) = (struct range_bounds
*)
879 TYPE_ZALLOC (result_type
, sizeof (struct range_bounds
));
880 TYPE_RANGE_DATA (result_type
)->low
= *low_bound
;
881 TYPE_RANGE_DATA (result_type
)->high
= *high_bound
;
883 if (low_bound
->kind
== PROP_CONST
&& low_bound
->data
.const_val
>= 0)
884 TYPE_UNSIGNED (result_type
) = 1;
886 /* Ada allows the declaration of range types whose upper bound is
887 less than the lower bound, so checking the lower bound is not
888 enough. Make sure we do not mark a range type whose upper bound
889 is negative as unsigned. */
890 if (high_bound
->kind
== PROP_CONST
&& high_bound
->data
.const_val
< 0)
891 TYPE_UNSIGNED (result_type
) = 0;
896 /* Create a range type using either a blank type supplied in
897 RESULT_TYPE, or creating a new type, inheriting the objfile from
900 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
901 to HIGH_BOUND, inclusive.
903 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
904 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
907 create_static_range_type (struct type
*result_type
, struct type
*index_type
,
908 LONGEST low_bound
, LONGEST high_bound
)
910 struct dynamic_prop low
, high
;
912 low
.kind
= PROP_CONST
;
913 low
.data
.const_val
= low_bound
;
915 high
.kind
= PROP_CONST
;
916 high
.data
.const_val
= high_bound
;
918 result_type
= create_range_type (result_type
, index_type
, &low
, &high
);
923 /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values
924 are static, otherwise returns 0. */
927 has_static_range (const struct range_bounds
*bounds
)
929 return (bounds
->low
.kind
== PROP_CONST
930 && bounds
->high
.kind
== PROP_CONST
);
934 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
935 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
936 bounds will fit in LONGEST), or -1 otherwise. */
939 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
941 type
= check_typedef (type
);
942 switch (TYPE_CODE (type
))
944 case TYPE_CODE_RANGE
:
945 *lowp
= TYPE_LOW_BOUND (type
);
946 *highp
= TYPE_HIGH_BOUND (type
);
949 if (TYPE_NFIELDS (type
) > 0)
951 /* The enums may not be sorted by value, so search all
955 *lowp
= *highp
= TYPE_FIELD_ENUMVAL (type
, 0);
956 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
958 if (TYPE_FIELD_ENUMVAL (type
, i
) < *lowp
)
959 *lowp
= TYPE_FIELD_ENUMVAL (type
, i
);
960 if (TYPE_FIELD_ENUMVAL (type
, i
) > *highp
)
961 *highp
= TYPE_FIELD_ENUMVAL (type
, i
);
964 /* Set unsigned indicator if warranted. */
967 TYPE_UNSIGNED (type
) = 1;
981 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
983 if (!TYPE_UNSIGNED (type
))
985 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
989 /* ... fall through for unsigned ints ... */
992 /* This round-about calculation is to avoid shifting by
993 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
994 if TYPE_LENGTH (type) == sizeof (LONGEST). */
995 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
996 *highp
= (*highp
- 1) | *highp
;
1003 /* Assuming TYPE is a simple, non-empty array type, compute its upper
1004 and lower bound. Save the low bound into LOW_BOUND if not NULL.
1005 Save the high bound into HIGH_BOUND if not NULL.
1007 Return 1 if the operation was successful. Return zero otherwise,
1008 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
1010 We now simply use get_discrete_bounds call to get the values
1011 of the low and high bounds.
1012 get_discrete_bounds can return three values:
1013 1, meaning that index is a range,
1014 0, meaning that index is a discrete type,
1015 or -1 for failure. */
1018 get_array_bounds (struct type
*type
, LONGEST
*low_bound
, LONGEST
*high_bound
)
1020 struct type
*index
= TYPE_INDEX_TYPE (type
);
1028 res
= get_discrete_bounds (index
, &low
, &high
);
1032 /* Check if the array bounds are undefined. */
1034 && ((low_bound
&& TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type
))
1035 || (high_bound
&& TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))))
1047 /* Assuming that TYPE is a discrete type and VAL is a valid integer
1048 representation of a value of this type, save the corresponding
1049 position number in POS.
1051 Its differs from VAL only in the case of enumeration types. In
1052 this case, the position number of the value of the first listed
1053 enumeration literal is zero; the position number of the value of
1054 each subsequent enumeration literal is one more than that of its
1055 predecessor in the list.
1057 Return 1 if the operation was successful. Return zero otherwise,
1058 in which case the value of POS is unmodified.
1062 discrete_position (struct type
*type
, LONGEST val
, LONGEST
*pos
)
1064 if (TYPE_CODE (type
) == TYPE_CODE_ENUM
)
1068 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
1070 if (val
== TYPE_FIELD_ENUMVAL (type
, i
))
1076 /* Invalid enumeration value. */
1086 /* Create an array type using either a blank type supplied in
1087 RESULT_TYPE, or creating a new type, inheriting the objfile from
1090 Elements will be of type ELEMENT_TYPE, the indices will be of type
1093 BYTE_STRIDE_PROP, when not NULL, provides the array's byte stride.
1094 This byte stride property is added to the resulting array type
1095 as a DYN_PROP_BYTE_STRIDE. As a consequence, the BYTE_STRIDE_PROP
1096 argument can only be used to create types that are objfile-owned
1097 (see add_dyn_prop), meaning that either this function must be called
1098 with an objfile-owned RESULT_TYPE, or an objfile-owned RANGE_TYPE.
1100 BIT_STRIDE is taken into account only when BYTE_STRIDE_PROP is NULL.
1101 If BIT_STRIDE is not zero, build a packed array type whose element
1102 size is BIT_STRIDE. Otherwise, ignore this parameter.
1104 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1105 sure it is TYPE_CODE_UNDEF before we bash it into an array
1109 create_array_type_with_stride (struct type
*result_type
,
1110 struct type
*element_type
,
1111 struct type
*range_type
,
1112 struct dynamic_prop
*byte_stride_prop
,
1113 unsigned int bit_stride
)
1115 if (byte_stride_prop
!= NULL
1116 && byte_stride_prop
->kind
== PROP_CONST
)
1118 /* The byte stride is actually not dynamic. Pretend we were
1119 called with bit_stride set instead of byte_stride_prop.
1120 This will give us the same result type, while avoiding
1121 the need to handle this as a special case. */
1122 bit_stride
= byte_stride_prop
->data
.const_val
* 8;
1123 byte_stride_prop
= NULL
;
1126 if (result_type
== NULL
)
1127 result_type
= alloc_type_copy (range_type
);
1129 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
1130 TYPE_TARGET_TYPE (result_type
) = element_type
;
1131 if (byte_stride_prop
== NULL
1132 && has_static_range (TYPE_RANGE_DATA (range_type
))
1133 && (!type_not_associated (result_type
)
1134 && !type_not_allocated (result_type
)))
1136 LONGEST low_bound
, high_bound
;
1138 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
1139 low_bound
= high_bound
= 0;
1140 element_type
= check_typedef (element_type
);
1141 /* Be careful when setting the array length. Ada arrays can be
1142 empty arrays with the high_bound being smaller than the low_bound.
1143 In such cases, the array length should be zero. */
1144 if (high_bound
< low_bound
)
1145 TYPE_LENGTH (result_type
) = 0;
1146 else if (bit_stride
> 0)
1147 TYPE_LENGTH (result_type
) =
1148 (bit_stride
* (high_bound
- low_bound
+ 1) + 7) / 8;
1150 TYPE_LENGTH (result_type
) =
1151 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
1155 /* This type is dynamic and its length needs to be computed
1156 on demand. In the meantime, avoid leaving the TYPE_LENGTH
1157 undefined by setting it to zero. Although we are not expected
1158 to trust TYPE_LENGTH in this case, setting the size to zero
1159 allows us to avoid allocating objects of random sizes in case
1160 we accidently do. */
1161 TYPE_LENGTH (result_type
) = 0;
1164 TYPE_NFIELDS (result_type
) = 1;
1165 TYPE_FIELDS (result_type
) =
1166 (struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
));
1167 TYPE_INDEX_TYPE (result_type
) = range_type
;
1168 if (byte_stride_prop
!= NULL
)
1169 add_dyn_prop (DYN_PROP_BYTE_STRIDE
, *byte_stride_prop
, result_type
);
1170 else if (bit_stride
> 0)
1171 TYPE_FIELD_BITSIZE (result_type
, 0) = bit_stride
;
1173 /* TYPE_TARGET_STUB will take care of zero length arrays. */
1174 if (TYPE_LENGTH (result_type
) == 0)
1175 TYPE_TARGET_STUB (result_type
) = 1;
1180 /* Same as create_array_type_with_stride but with no bit_stride
1181 (BIT_STRIDE = 0), thus building an unpacked array. */
1184 create_array_type (struct type
*result_type
,
1185 struct type
*element_type
,
1186 struct type
*range_type
)
1188 return create_array_type_with_stride (result_type
, element_type
,
1189 range_type
, NULL
, 0);
1193 lookup_array_range_type (struct type
*element_type
,
1194 LONGEST low_bound
, LONGEST high_bound
)
1196 struct gdbarch
*gdbarch
= get_type_arch (element_type
);
1197 struct type
*index_type
= builtin_type (gdbarch
)->builtin_int
;
1198 struct type
*range_type
1199 = create_static_range_type (NULL
, index_type
, low_bound
, high_bound
);
1201 return create_array_type (NULL
, element_type
, range_type
);
1204 /* Create a string type using either a blank type supplied in
1205 RESULT_TYPE, or creating a new type. String types are similar
1206 enough to array of char types that we can use create_array_type to
1207 build the basic type and then bash it into a string type.
1209 For fixed length strings, the range type contains 0 as the lower
1210 bound and the length of the string minus one as the upper bound.
1212 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
1213 sure it is TYPE_CODE_UNDEF before we bash it into a string
1217 create_string_type (struct type
*result_type
,
1218 struct type
*string_char_type
,
1219 struct type
*range_type
)
1221 result_type
= create_array_type (result_type
,
1224 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
1229 lookup_string_range_type (struct type
*string_char_type
,
1230 LONGEST low_bound
, LONGEST high_bound
)
1232 struct type
*result_type
;
1234 result_type
= lookup_array_range_type (string_char_type
,
1235 low_bound
, high_bound
);
1236 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
1241 create_set_type (struct type
*result_type
, struct type
*domain_type
)
1243 if (result_type
== NULL
)
1244 result_type
= alloc_type_copy (domain_type
);
1246 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
1247 TYPE_NFIELDS (result_type
) = 1;
1248 TYPE_FIELDS (result_type
)
1249 = (struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
));
1251 if (!TYPE_STUB (domain_type
))
1253 LONGEST low_bound
, high_bound
, bit_length
;
1255 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
1256 low_bound
= high_bound
= 0;
1257 bit_length
= high_bound
- low_bound
+ 1;
1258 TYPE_LENGTH (result_type
)
1259 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
1261 TYPE_UNSIGNED (result_type
) = 1;
1263 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
1268 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1269 and any array types nested inside it. */
1272 make_vector_type (struct type
*array_type
)
1274 struct type
*inner_array
, *elt_type
;
1277 /* Find the innermost array type, in case the array is
1278 multi-dimensional. */
1279 inner_array
= array_type
;
1280 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
1281 inner_array
= TYPE_TARGET_TYPE (inner_array
);
1283 elt_type
= TYPE_TARGET_TYPE (inner_array
);
1284 if (TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
1286 flags
= TYPE_INSTANCE_FLAGS (elt_type
) | TYPE_INSTANCE_FLAG_NOTTEXT
;
1287 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
1288 TYPE_TARGET_TYPE (inner_array
) = elt_type
;
1291 TYPE_VECTOR (array_type
) = 1;
1295 init_vector_type (struct type
*elt_type
, int n
)
1297 struct type
*array_type
;
1299 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
1300 make_vector_type (array_type
);
1304 /* Internal routine called by TYPE_SELF_TYPE to return the type that TYPE
1305 belongs to. In c++ this is the class of "this", but TYPE_THIS_TYPE is too
1306 confusing. "self" is a common enough replacement for "this".
1307 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1308 TYPE_CODE_METHOD. */
1311 internal_type_self_type (struct type
*type
)
1313 switch (TYPE_CODE (type
))
1315 case TYPE_CODE_METHODPTR
:
1316 case TYPE_CODE_MEMBERPTR
:
1317 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1319 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1320 return TYPE_MAIN_TYPE (type
)->type_specific
.self_type
;
1321 case TYPE_CODE_METHOD
:
1322 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1324 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1325 return TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
;
1327 gdb_assert_not_reached ("bad type");
1331 /* Set the type of the class that TYPE belongs to.
1332 In c++ this is the class of "this".
1333 TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or
1334 TYPE_CODE_METHOD. */
1337 set_type_self_type (struct type
*type
, struct type
*self_type
)
1339 switch (TYPE_CODE (type
))
1341 case TYPE_CODE_METHODPTR
:
1342 case TYPE_CODE_MEMBERPTR
:
1343 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1344 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_SELF_TYPE
;
1345 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_SELF_TYPE
);
1346 TYPE_MAIN_TYPE (type
)->type_specific
.self_type
= self_type
;
1348 case TYPE_CODE_METHOD
:
1349 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_NONE
)
1350 INIT_FUNC_SPECIFIC (type
);
1351 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1352 TYPE_MAIN_TYPE (type
)->type_specific
.func_stuff
->self_type
= self_type
;
1355 gdb_assert_not_reached ("bad type");
1359 /* Smash TYPE to be a type of pointers to members of SELF_TYPE with type
1360 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1361 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1362 TYPE doesn't include the offset (that's the value of the MEMBER
1363 itself), but does include the structure type into which it points
1366 When "smashing" the type, we preserve the objfile that the old type
1367 pointed to, since we aren't changing where the type is actually
1371 smash_to_memberptr_type (struct type
*type
, struct type
*self_type
,
1372 struct type
*to_type
)
1375 TYPE_CODE (type
) = TYPE_CODE_MEMBERPTR
;
1376 TYPE_TARGET_TYPE (type
) = to_type
;
1377 set_type_self_type (type
, self_type
);
1378 /* Assume that a data member pointer is the same size as a normal
1381 = gdbarch_ptr_bit (get_type_arch (to_type
)) / TARGET_CHAR_BIT
;
1384 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1386 When "smashing" the type, we preserve the objfile that the old type
1387 pointed to, since we aren't changing where the type is actually
1391 smash_to_methodptr_type (struct type
*type
, struct type
*to_type
)
1394 TYPE_CODE (type
) = TYPE_CODE_METHODPTR
;
1395 TYPE_TARGET_TYPE (type
) = to_type
;
1396 set_type_self_type (type
, TYPE_SELF_TYPE (to_type
));
1397 TYPE_LENGTH (type
) = cplus_method_ptr_size (to_type
);
1400 /* Smash TYPE to be a type of method of SELF_TYPE with type TO_TYPE.
1401 METHOD just means `function that gets an extra "this" argument'.
1403 When "smashing" the type, we preserve the objfile that the old type
1404 pointed to, since we aren't changing where the type is actually
1408 smash_to_method_type (struct type
*type
, struct type
*self_type
,
1409 struct type
*to_type
, struct field
*args
,
1410 int nargs
, int varargs
)
1413 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1414 TYPE_TARGET_TYPE (type
) = to_type
;
1415 set_type_self_type (type
, self_type
);
1416 TYPE_FIELDS (type
) = args
;
1417 TYPE_NFIELDS (type
) = nargs
;
1419 TYPE_VARARGS (type
) = 1;
1420 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1423 /* Return a typename for a struct/union/enum type without "struct ",
1424 "union ", or "enum ". If the type has a NULL name, return NULL. */
1427 type_name_no_tag (const struct type
*type
)
1429 if (TYPE_TAG_NAME (type
) != NULL
)
1430 return TYPE_TAG_NAME (type
);
1432 /* Is there code which expects this to return the name if there is
1433 no tag name? My guess is that this is mainly used for C++ in
1434 cases where the two will always be the same. */
1435 return TYPE_NAME (type
);
1438 /* A wrapper of type_name_no_tag which calls error if the type is anonymous.
1439 Since GCC PR debug/47510 DWARF provides associated information to detect the
1440 anonymous class linkage name from its typedef.
1442 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1446 type_name_no_tag_or_error (struct type
*type
)
1448 struct type
*saved_type
= type
;
1450 struct objfile
*objfile
;
1452 type
= check_typedef (type
);
1454 name
= type_name_no_tag (type
);
1458 name
= type_name_no_tag (saved_type
);
1459 objfile
= TYPE_OBJFILE (saved_type
);
1460 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1461 name
? name
: "<anonymous>",
1462 objfile
? objfile_name (objfile
) : "<arch>");
1465 /* Lookup a typedef or primitive type named NAME, visible in lexical
1466 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1467 suitably defined. */
1470 lookup_typename (const struct language_defn
*language
,
1471 struct gdbarch
*gdbarch
, const char *name
,
1472 const struct block
*block
, int noerr
)
1476 sym
= lookup_symbol_in_language (name
, block
, VAR_DOMAIN
,
1477 language
->la_language
, NULL
).symbol
;
1478 if (sym
!= NULL
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
1479 return SYMBOL_TYPE (sym
);
1483 error (_("No type named %s."), name
);
1487 lookup_unsigned_typename (const struct language_defn
*language
,
1488 struct gdbarch
*gdbarch
, const char *name
)
1490 char *uns
= (char *) alloca (strlen (name
) + 10);
1492 strcpy (uns
, "unsigned ");
1493 strcpy (uns
+ 9, name
);
1494 return lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 0);
1498 lookup_signed_typename (const struct language_defn
*language
,
1499 struct gdbarch
*gdbarch
, const char *name
)
1502 char *uns
= (char *) alloca (strlen (name
) + 8);
1504 strcpy (uns
, "signed ");
1505 strcpy (uns
+ 7, name
);
1506 t
= lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 1);
1507 /* If we don't find "signed FOO" just try again with plain "FOO". */
1510 return lookup_typename (language
, gdbarch
, name
, (struct block
*) NULL
, 0);
1513 /* Lookup a structure type named "struct NAME",
1514 visible in lexical block BLOCK. */
1517 lookup_struct (const char *name
, const struct block
*block
)
1521 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1525 error (_("No struct type named %s."), name
);
1527 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1529 error (_("This context has class, union or enum %s, not a struct."),
1532 return (SYMBOL_TYPE (sym
));
1535 /* Lookup a union type named "union NAME",
1536 visible in lexical block BLOCK. */
1539 lookup_union (const char *name
, const struct block
*block
)
1544 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1547 error (_("No union type named %s."), name
);
1549 t
= SYMBOL_TYPE (sym
);
1551 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1554 /* If we get here, it's not a union. */
1555 error (_("This context has class, struct or enum %s, not a union."),
1559 /* Lookup an enum type named "enum NAME",
1560 visible in lexical block BLOCK. */
1563 lookup_enum (const char *name
, const struct block
*block
)
1567 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0).symbol
;
1570 error (_("No enum type named %s."), name
);
1572 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1574 error (_("This context has class, struct or union %s, not an enum."),
1577 return (SYMBOL_TYPE (sym
));
1580 /* Lookup a template type named "template NAME<TYPE>",
1581 visible in lexical block BLOCK. */
1584 lookup_template_type (char *name
, struct type
*type
,
1585 const struct block
*block
)
1588 char *nam
= (char *)
1589 alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1593 strcat (nam
, TYPE_NAME (type
));
1594 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1596 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0).symbol
;
1600 error (_("No template type named %s."), name
);
1602 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1604 error (_("This context has class, union or enum %s, not a struct."),
1607 return (SYMBOL_TYPE (sym
));
1610 /* Given a type TYPE, lookup the type of the component of type named
1613 TYPE can be either a struct or union, or a pointer or reference to
1614 a struct or union. If it is a pointer or reference, its target
1615 type is automatically used. Thus '.' and '->' are interchangable,
1616 as specified for the definitions of the expression element types
1617 STRUCTOP_STRUCT and STRUCTOP_PTR.
1619 If NOERR is nonzero, return zero if NAME is not suitably defined.
1620 If NAME is the name of a baseclass type, return that type. */
1623 lookup_struct_elt_type (struct type
*type
, const char *name
, int noerr
)
1629 type
= check_typedef (type
);
1630 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1631 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1633 type
= TYPE_TARGET_TYPE (type
);
1636 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1637 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1639 std::string type_name
= type_to_string (type
);
1640 error (_("Type %s is not a structure or union type."),
1641 type_name
.c_str ());
1645 /* FIXME: This change put in by Michael seems incorrect for the case
1646 where the structure tag name is the same as the member name.
1647 I.e. when doing "ptype bell->bar" for "struct foo { int bar; int
1648 foo; } bell;" Disabled by fnf. */
1652 type_name
= type_name_no_tag (type
);
1653 if (type_name
!= NULL
&& strcmp (type_name
, name
) == 0)
1658 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1660 const char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1662 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1664 return TYPE_FIELD_TYPE (type
, i
);
1666 else if (!t_field_name
|| *t_field_name
== '\0')
1668 struct type
*subtype
1669 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type
, i
), name
, 1);
1671 if (subtype
!= NULL
)
1676 /* OK, it's not in this class. Recursively check the baseclasses. */
1677 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1681 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1693 std::string type_name
= type_to_string (type
);
1694 error (_("Type %s has no component named %s."), type_name
.c_str (), name
);
1697 /* Store in *MAX the largest number representable by unsigned integer type
1701 get_unsigned_type_max (struct type
*type
, ULONGEST
*max
)
1705 type
= check_typedef (type
);
1706 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_INT
&& TYPE_UNSIGNED (type
));
1707 gdb_assert (TYPE_LENGTH (type
) <= sizeof (ULONGEST
));
1709 /* Written this way to avoid overflow. */
1710 n
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
;
1711 *max
= ((((ULONGEST
) 1 << (n
- 1)) - 1) << 1) | 1;
1714 /* Store in *MIN, *MAX the smallest and largest numbers representable by
1715 signed integer type TYPE. */
1718 get_signed_type_minmax (struct type
*type
, LONGEST
*min
, LONGEST
*max
)
1722 type
= check_typedef (type
);
1723 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_INT
&& !TYPE_UNSIGNED (type
));
1724 gdb_assert (TYPE_LENGTH (type
) <= sizeof (LONGEST
));
1726 n
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
;
1727 *min
= -((ULONGEST
) 1 << (n
- 1));
1728 *max
= ((ULONGEST
) 1 << (n
- 1)) - 1;
1731 /* Internal routine called by TYPE_VPTR_FIELDNO to return the value of
1732 cplus_stuff.vptr_fieldno.
1734 cplus_stuff is initialized to cplus_struct_default which does not
1735 set vptr_fieldno to -1 for portability reasons (IWBN to use C99
1736 designated initializers). We cope with that here. */
1739 internal_type_vptr_fieldno (struct type
*type
)
1741 type
= check_typedef (type
);
1742 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1743 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
1744 if (!HAVE_CPLUS_STRUCT (type
))
1746 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
;
1749 /* Set the value of cplus_stuff.vptr_fieldno. */
1752 set_type_vptr_fieldno (struct type
*type
, int fieldno
)
1754 type
= check_typedef (type
);
1755 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1756 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
1757 if (!HAVE_CPLUS_STRUCT (type
))
1758 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1759 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_fieldno
= fieldno
;
1762 /* Internal routine called by TYPE_VPTR_BASETYPE to return the value of
1763 cplus_stuff.vptr_basetype. */
1766 internal_type_vptr_basetype (struct type
*type
)
1768 type
= check_typedef (type
);
1769 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1770 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
1771 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_CPLUS_STUFF
);
1772 return TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
;
1775 /* Set the value of cplus_stuff.vptr_basetype. */
1778 set_type_vptr_basetype (struct type
*type
, struct type
*basetype
)
1780 type
= check_typedef (type
);
1781 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1782 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
1783 if (!HAVE_CPLUS_STRUCT (type
))
1784 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1785 TYPE_RAW_CPLUS_SPECIFIC (type
)->vptr_basetype
= basetype
;
1788 /* Lookup the vptr basetype/fieldno values for TYPE.
1789 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1790 vptr_fieldno. Also, if found and basetype is from the same objfile,
1792 If not found, return -1 and ignore BASETYPEP.
1793 Callers should be aware that in some cases (for example,
1794 the type or one of its baseclasses is a stub type and we are
1795 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1796 this function will not be able to find the
1797 virtual function table pointer, and vptr_fieldno will remain -1 and
1798 vptr_basetype will remain NULL or incomplete. */
1801 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1803 type
= check_typedef (type
);
1805 if (TYPE_VPTR_FIELDNO (type
) < 0)
1809 /* We must start at zero in case the first (and only) baseclass
1810 is virtual (and hence we cannot share the table pointer). */
1811 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1813 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1815 struct type
*basetype
;
1817 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1820 /* If the type comes from a different objfile we can't cache
1821 it, it may have a different lifetime. PR 2384 */
1822 if (TYPE_OBJFILE (type
) == TYPE_OBJFILE (basetype
))
1824 set_type_vptr_fieldno (type
, fieldno
);
1825 set_type_vptr_basetype (type
, basetype
);
1828 *basetypep
= basetype
;
1839 *basetypep
= TYPE_VPTR_BASETYPE (type
);
1840 return TYPE_VPTR_FIELDNO (type
);
1845 stub_noname_complaint (void)
1847 complaint (&symfile_complaints
, _("stub type has NULL name"));
1850 /* Return nonzero if TYPE has a DYN_PROP_BYTE_STRIDE dynamic property
1851 attached to it, and that property has a non-constant value. */
1854 array_type_has_dynamic_stride (struct type
*type
)
1856 struct dynamic_prop
*prop
= get_dyn_prop (DYN_PROP_BYTE_STRIDE
, type
);
1858 return (prop
!= NULL
&& prop
->kind
!= PROP_CONST
);
1861 /* Worker for is_dynamic_type. */
1864 is_dynamic_type_internal (struct type
*type
, int top_level
)
1866 type
= check_typedef (type
);
1868 /* We only want to recognize references at the outermost level. */
1869 if (top_level
&& TYPE_CODE (type
) == TYPE_CODE_REF
)
1870 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1872 /* Types that have a dynamic TYPE_DATA_LOCATION are considered
1873 dynamic, even if the type itself is statically defined.
1874 From a user's point of view, this may appear counter-intuitive;
1875 but it makes sense in this context, because the point is to determine
1876 whether any part of the type needs to be resolved before it can
1878 if (TYPE_DATA_LOCATION (type
) != NULL
1879 && (TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCEXPR
1880 || TYPE_DATA_LOCATION_KIND (type
) == PROP_LOCLIST
))
1883 if (TYPE_ASSOCIATED_PROP (type
))
1886 if (TYPE_ALLOCATED_PROP (type
))
1889 switch (TYPE_CODE (type
))
1891 case TYPE_CODE_RANGE
:
1893 /* A range type is obviously dynamic if it has at least one
1894 dynamic bound. But also consider the range type to be
1895 dynamic when its subtype is dynamic, even if the bounds
1896 of the range type are static. It allows us to assume that
1897 the subtype of a static range type is also static. */
1898 return (!has_static_range (TYPE_RANGE_DATA (type
))
1899 || is_dynamic_type_internal (TYPE_TARGET_TYPE (type
), 0));
1902 case TYPE_CODE_ARRAY
:
1904 gdb_assert (TYPE_NFIELDS (type
) == 1);
1906 /* The array is dynamic if either the bounds are dynamic... */
1907 if (is_dynamic_type_internal (TYPE_INDEX_TYPE (type
), 0))
1909 /* ... or the elements it contains have a dynamic contents... */
1910 if (is_dynamic_type_internal (TYPE_TARGET_TYPE (type
), 0))
1912 /* ... or if it has a dynamic stride... */
1913 if (array_type_has_dynamic_stride (type
))
1918 case TYPE_CODE_STRUCT
:
1919 case TYPE_CODE_UNION
:
1923 for (i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
1924 if (!field_is_static (&TYPE_FIELD (type
, i
))
1925 && is_dynamic_type_internal (TYPE_FIELD_TYPE (type
, i
), 0))
1934 /* See gdbtypes.h. */
1937 is_dynamic_type (struct type
*type
)
1939 return is_dynamic_type_internal (type
, 1);
1942 static struct type
*resolve_dynamic_type_internal
1943 (struct type
*type
, struct property_addr_info
*addr_stack
, int top_level
);
1945 /* Given a dynamic range type (dyn_range_type) and a stack of
1946 struct property_addr_info elements, return a static version
1949 static struct type
*
1950 resolve_dynamic_range (struct type
*dyn_range_type
,
1951 struct property_addr_info
*addr_stack
)
1954 struct type
*static_range_type
, *static_target_type
;
1955 const struct dynamic_prop
*prop
;
1956 struct dynamic_prop low_bound
, high_bound
;
1958 gdb_assert (TYPE_CODE (dyn_range_type
) == TYPE_CODE_RANGE
);
1960 prop
= &TYPE_RANGE_DATA (dyn_range_type
)->low
;
1961 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
1963 low_bound
.kind
= PROP_CONST
;
1964 low_bound
.data
.const_val
= value
;
1968 low_bound
.kind
= PROP_UNDEFINED
;
1969 low_bound
.data
.const_val
= 0;
1972 prop
= &TYPE_RANGE_DATA (dyn_range_type
)->high
;
1973 if (dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
1975 high_bound
.kind
= PROP_CONST
;
1976 high_bound
.data
.const_val
= value
;
1978 if (TYPE_RANGE_DATA (dyn_range_type
)->flag_upper_bound_is_count
)
1979 high_bound
.data
.const_val
1980 = low_bound
.data
.const_val
+ high_bound
.data
.const_val
- 1;
1984 high_bound
.kind
= PROP_UNDEFINED
;
1985 high_bound
.data
.const_val
= 0;
1989 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type
),
1991 static_range_type
= create_range_type (copy_type (dyn_range_type
),
1993 &low_bound
, &high_bound
);
1994 TYPE_RANGE_DATA (static_range_type
)->flag_bound_evaluated
= 1;
1995 return static_range_type
;
1998 /* Resolves dynamic bound values of an array type TYPE to static ones.
1999 ADDR_STACK is a stack of struct property_addr_info to be used
2000 if needed during the dynamic resolution. */
2002 static struct type
*
2003 resolve_dynamic_array (struct type
*type
,
2004 struct property_addr_info
*addr_stack
)
2007 struct type
*elt_type
;
2008 struct type
*range_type
;
2009 struct type
*ary_dim
;
2010 struct dynamic_prop
*prop
;
2011 unsigned int bit_stride
= 0;
2013 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
2015 type
= copy_type (type
);
2018 range_type
= check_typedef (TYPE_INDEX_TYPE (elt_type
));
2019 range_type
= resolve_dynamic_range (range_type
, addr_stack
);
2021 /* Resolve allocated/associated here before creating a new array type, which
2022 will update the length of the array accordingly. */
2023 prop
= TYPE_ALLOCATED_PROP (type
);
2024 if (prop
!= NULL
&& dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2026 TYPE_DYN_PROP_ADDR (prop
) = value
;
2027 TYPE_DYN_PROP_KIND (prop
) = PROP_CONST
;
2029 prop
= TYPE_ASSOCIATED_PROP (type
);
2030 if (prop
!= NULL
&& dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2032 TYPE_DYN_PROP_ADDR (prop
) = value
;
2033 TYPE_DYN_PROP_KIND (prop
) = PROP_CONST
;
2036 ary_dim
= check_typedef (TYPE_TARGET_TYPE (elt_type
));
2038 if (ary_dim
!= NULL
&& TYPE_CODE (ary_dim
) == TYPE_CODE_ARRAY
)
2039 elt_type
= resolve_dynamic_array (ary_dim
, addr_stack
);
2041 elt_type
= TYPE_TARGET_TYPE (type
);
2043 prop
= get_dyn_prop (DYN_PROP_BYTE_STRIDE
, type
);
2047 = dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
);
2051 remove_dyn_prop (DYN_PROP_BYTE_STRIDE
, type
);
2052 bit_stride
= (unsigned int) (value
* 8);
2056 /* Could be a bug in our code, but it could also happen
2057 if the DWARF info is not correct. Issue a warning,
2058 and assume no byte/bit stride (leave bit_stride = 0). */
2059 warning (_("cannot determine array stride for type %s"),
2060 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<no name>");
2064 bit_stride
= TYPE_FIELD_BITSIZE (type
, 0);
2066 return create_array_type_with_stride (type
, elt_type
, range_type
, NULL
,
2070 /* Resolve dynamic bounds of members of the union TYPE to static
2071 bounds. ADDR_STACK is a stack of struct property_addr_info
2072 to be used if needed during the dynamic resolution. */
2074 static struct type
*
2075 resolve_dynamic_union (struct type
*type
,
2076 struct property_addr_info
*addr_stack
)
2078 struct type
*resolved_type
;
2080 unsigned int max_len
= 0;
2082 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
2084 resolved_type
= copy_type (type
);
2085 TYPE_FIELDS (resolved_type
)
2086 = (struct field
*) TYPE_ALLOC (resolved_type
,
2087 TYPE_NFIELDS (resolved_type
)
2088 * sizeof (struct field
));
2089 memcpy (TYPE_FIELDS (resolved_type
),
2091 TYPE_NFIELDS (resolved_type
) * sizeof (struct field
));
2092 for (i
= 0; i
< TYPE_NFIELDS (resolved_type
); ++i
)
2096 if (field_is_static (&TYPE_FIELD (type
, i
)))
2099 t
= resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type
, i
),
2101 TYPE_FIELD_TYPE (resolved_type
, i
) = t
;
2102 if (TYPE_LENGTH (t
) > max_len
)
2103 max_len
= TYPE_LENGTH (t
);
2106 TYPE_LENGTH (resolved_type
) = max_len
;
2107 return resolved_type
;
2110 /* Resolve dynamic bounds of members of the struct TYPE to static
2111 bounds. ADDR_STACK is a stack of struct property_addr_info to
2112 be used if needed during the dynamic resolution. */
2114 static struct type
*
2115 resolve_dynamic_struct (struct type
*type
,
2116 struct property_addr_info
*addr_stack
)
2118 struct type
*resolved_type
;
2120 unsigned resolved_type_bit_length
= 0;
2122 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
);
2123 gdb_assert (TYPE_NFIELDS (type
) > 0);
2125 resolved_type
= copy_type (type
);
2126 TYPE_FIELDS (resolved_type
)
2127 = (struct field
*) TYPE_ALLOC (resolved_type
,
2128 TYPE_NFIELDS (resolved_type
)
2129 * sizeof (struct field
));
2130 memcpy (TYPE_FIELDS (resolved_type
),
2132 TYPE_NFIELDS (resolved_type
) * sizeof (struct field
));
2133 for (i
= 0; i
< TYPE_NFIELDS (resolved_type
); ++i
)
2135 unsigned new_bit_length
;
2136 struct property_addr_info pinfo
;
2138 if (field_is_static (&TYPE_FIELD (type
, i
)))
2141 /* As we know this field is not a static field, the field's
2142 field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
2143 this is the case, but only trigger a simple error rather
2144 than an internal error if that fails. While failing
2145 that verification indicates a bug in our code, the error
2146 is not severe enough to suggest to the user he stops
2147 his debugging session because of it. */
2148 if (TYPE_FIELD_LOC_KIND (type
, i
) != FIELD_LOC_KIND_BITPOS
)
2149 error (_("Cannot determine struct field location"
2150 " (invalid location kind)"));
2152 pinfo
.type
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
2153 pinfo
.valaddr
= addr_stack
->valaddr
;
2156 + (TYPE_FIELD_BITPOS (resolved_type
, i
) / TARGET_CHAR_BIT
));
2157 pinfo
.next
= addr_stack
;
2159 TYPE_FIELD_TYPE (resolved_type
, i
)
2160 = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type
, i
),
2162 gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type
, i
)
2163 == FIELD_LOC_KIND_BITPOS
);
2165 new_bit_length
= TYPE_FIELD_BITPOS (resolved_type
, i
);
2166 if (TYPE_FIELD_BITSIZE (resolved_type
, i
) != 0)
2167 new_bit_length
+= TYPE_FIELD_BITSIZE (resolved_type
, i
);
2169 new_bit_length
+= (TYPE_LENGTH (TYPE_FIELD_TYPE (resolved_type
, i
))
2172 /* Normally, we would use the position and size of the last field
2173 to determine the size of the enclosing structure. But GCC seems
2174 to be encoding the position of some fields incorrectly when
2175 the struct contains a dynamic field that is not placed last.
2176 So we compute the struct size based on the field that has
2177 the highest position + size - probably the best we can do. */
2178 if (new_bit_length
> resolved_type_bit_length
)
2179 resolved_type_bit_length
= new_bit_length
;
2182 /* The length of a type won't change for fortran, but it does for C and Ada.
2183 For fortran the size of dynamic fields might change over time but not the
2184 type length of the structure. If we adapt it, we run into problems
2185 when calculating the element offset for arrays of structs. */
2186 if (current_language
->la_language
!= language_fortran
)
2187 TYPE_LENGTH (resolved_type
)
2188 = (resolved_type_bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2190 /* The Ada language uses this field as a cache for static fixed types: reset
2191 it as RESOLVED_TYPE must have its own static fixed type. */
2192 TYPE_TARGET_TYPE (resolved_type
) = NULL
;
2194 return resolved_type
;
2197 /* Worker for resolved_dynamic_type. */
2199 static struct type
*
2200 resolve_dynamic_type_internal (struct type
*type
,
2201 struct property_addr_info
*addr_stack
,
2204 struct type
*real_type
= check_typedef (type
);
2205 struct type
*resolved_type
= type
;
2206 struct dynamic_prop
*prop
;
2209 if (!is_dynamic_type_internal (real_type
, top_level
))
2212 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
2214 resolved_type
= copy_type (type
);
2215 TYPE_TARGET_TYPE (resolved_type
)
2216 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type
), addr_stack
,
2221 /* Before trying to resolve TYPE, make sure it is not a stub. */
2224 switch (TYPE_CODE (type
))
2228 struct property_addr_info pinfo
;
2230 pinfo
.type
= check_typedef (TYPE_TARGET_TYPE (type
));
2231 pinfo
.valaddr
= NULL
;
2232 if (addr_stack
->valaddr
!= NULL
)
2233 pinfo
.addr
= extract_typed_address (addr_stack
->valaddr
, type
);
2235 pinfo
.addr
= read_memory_typed_address (addr_stack
->addr
, type
);
2236 pinfo
.next
= addr_stack
;
2238 resolved_type
= copy_type (type
);
2239 TYPE_TARGET_TYPE (resolved_type
)
2240 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type
),
2245 case TYPE_CODE_ARRAY
:
2246 resolved_type
= resolve_dynamic_array (type
, addr_stack
);
2249 case TYPE_CODE_RANGE
:
2250 resolved_type
= resolve_dynamic_range (type
, addr_stack
);
2253 case TYPE_CODE_UNION
:
2254 resolved_type
= resolve_dynamic_union (type
, addr_stack
);
2257 case TYPE_CODE_STRUCT
:
2258 resolved_type
= resolve_dynamic_struct (type
, addr_stack
);
2263 /* Resolve data_location attribute. */
2264 prop
= TYPE_DATA_LOCATION (resolved_type
);
2266 && dwarf2_evaluate_property (prop
, NULL
, addr_stack
, &value
))
2268 TYPE_DYN_PROP_ADDR (prop
) = value
;
2269 TYPE_DYN_PROP_KIND (prop
) = PROP_CONST
;
2272 return resolved_type
;
2275 /* See gdbtypes.h */
2278 resolve_dynamic_type (struct type
*type
, const gdb_byte
*valaddr
,
2281 struct property_addr_info pinfo
2282 = {check_typedef (type
), valaddr
, addr
, NULL
};
2284 return resolve_dynamic_type_internal (type
, &pinfo
, 1);
2287 /* See gdbtypes.h */
2289 struct dynamic_prop
*
2290 get_dyn_prop (enum dynamic_prop_node_kind prop_kind
, const struct type
*type
)
2292 struct dynamic_prop_list
*node
= TYPE_DYN_PROP_LIST (type
);
2294 while (node
!= NULL
)
2296 if (node
->prop_kind
== prop_kind
)
2303 /* See gdbtypes.h */
2306 add_dyn_prop (enum dynamic_prop_node_kind prop_kind
, struct dynamic_prop prop
,
2309 struct dynamic_prop_list
*temp
;
2311 gdb_assert (TYPE_OBJFILE_OWNED (type
));
2313 temp
= XOBNEW (&TYPE_OBJFILE (type
)->objfile_obstack
,
2314 struct dynamic_prop_list
);
2315 temp
->prop_kind
= prop_kind
;
2317 temp
->next
= TYPE_DYN_PROP_LIST (type
);
2319 TYPE_DYN_PROP_LIST (type
) = temp
;
2322 /* Remove dynamic property from TYPE in case it exists. */
2325 remove_dyn_prop (enum dynamic_prop_node_kind prop_kind
,
2328 struct dynamic_prop_list
*prev_node
, *curr_node
;
2330 curr_node
= TYPE_DYN_PROP_LIST (type
);
2333 while (NULL
!= curr_node
)
2335 if (curr_node
->prop_kind
== prop_kind
)
2337 /* Update the linked list but don't free anything.
2338 The property was allocated on objstack and it is not known
2339 if we are on top of it. Nevertheless, everything is released
2340 when the complete objstack is freed. */
2341 if (NULL
== prev_node
)
2342 TYPE_DYN_PROP_LIST (type
) = curr_node
->next
;
2344 prev_node
->next
= curr_node
->next
;
2349 prev_node
= curr_node
;
2350 curr_node
= curr_node
->next
;
2354 /* Find the real type of TYPE. This function returns the real type,
2355 after removing all layers of typedefs, and completing opaque or stub
2356 types. Completion changes the TYPE argument, but stripping of
2359 Instance flags (e.g. const/volatile) are preserved as typedefs are
2360 stripped. If necessary a new qualified form of the underlying type
2363 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
2364 not been computed and we're either in the middle of reading symbols, or
2365 there was no name for the typedef in the debug info.
2367 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
2368 QUITs in the symbol reading code can also throw.
2369 Thus this function can throw an exception.
2371 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
2374 If this is a stubbed struct (i.e. declared as struct foo *), see if
2375 we can find a full definition in some other file. If so, copy this
2376 definition, so we can use it in future. There used to be a comment
2377 (but not any code) that if we don't find a full definition, we'd
2378 set a flag so we don't spend time in the future checking the same
2379 type. That would be a mistake, though--we might load in more
2380 symbols which contain a full definition for the type. */
2383 check_typedef (struct type
*type
)
2385 struct type
*orig_type
= type
;
2386 /* While we're removing typedefs, we don't want to lose qualifiers.
2387 E.g., const/volatile. */
2388 int instance_flags
= TYPE_INSTANCE_FLAGS (type
);
2392 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
2394 if (!TYPE_TARGET_TYPE (type
))
2399 /* It is dangerous to call lookup_symbol if we are currently
2400 reading a symtab. Infinite recursion is one danger. */
2401 if (currently_reading_symtab
)
2402 return make_qualified_type (type
, instance_flags
, NULL
);
2404 name
= type_name_no_tag (type
);
2405 /* FIXME: shouldn't we separately check the TYPE_NAME and
2406 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
2407 VAR_DOMAIN as appropriate? (this code was written before
2408 TYPE_NAME and TYPE_TAG_NAME were separate). */
2411 stub_noname_complaint ();
2412 return make_qualified_type (type
, instance_flags
, NULL
);
2414 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0).symbol
;
2416 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
2417 else /* TYPE_CODE_UNDEF */
2418 TYPE_TARGET_TYPE (type
) = alloc_type_arch (get_type_arch (type
));
2420 type
= TYPE_TARGET_TYPE (type
);
2422 /* Preserve the instance flags as we traverse down the typedef chain.
2424 Handling address spaces/classes is nasty, what do we do if there's a
2426 E.g., what if an outer typedef marks the type as class_1 and an inner
2427 typedef marks the type as class_2?
2428 This is the wrong place to do such error checking. We leave it to
2429 the code that created the typedef in the first place to flag the
2430 error. We just pick the outer address space (akin to letting the
2431 outer cast in a chain of casting win), instead of assuming
2432 "it can't happen". */
2434 const int ALL_SPACES
= (TYPE_INSTANCE_FLAG_CODE_SPACE
2435 | TYPE_INSTANCE_FLAG_DATA_SPACE
);
2436 const int ALL_CLASSES
= TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
;
2437 int new_instance_flags
= TYPE_INSTANCE_FLAGS (type
);
2439 /* Treat code vs data spaces and address classes separately. */
2440 if ((instance_flags
& ALL_SPACES
) != 0)
2441 new_instance_flags
&= ~ALL_SPACES
;
2442 if ((instance_flags
& ALL_CLASSES
) != 0)
2443 new_instance_flags
&= ~ALL_CLASSES
;
2445 instance_flags
|= new_instance_flags
;
2449 /* If this is a struct/class/union with no fields, then check
2450 whether a full definition exists somewhere else. This is for
2451 systems where a type definition with no fields is issued for such
2452 types, instead of identifying them as stub types in the first
2455 if (TYPE_IS_OPAQUE (type
)
2456 && opaque_type_resolution
2457 && !currently_reading_symtab
)
2459 const char *name
= type_name_no_tag (type
);
2460 struct type
*newtype
;
2464 stub_noname_complaint ();
2465 return make_qualified_type (type
, instance_flags
, NULL
);
2467 newtype
= lookup_transparent_type (name
);
2471 /* If the resolved type and the stub are in the same
2472 objfile, then replace the stub type with the real deal.
2473 But if they're in separate objfiles, leave the stub
2474 alone; we'll just look up the transparent type every time
2475 we call check_typedef. We can't create pointers between
2476 types allocated to different objfiles, since they may
2477 have different lifetimes. Trying to copy NEWTYPE over to
2478 TYPE's objfile is pointless, too, since you'll have to
2479 move over any other types NEWTYPE refers to, which could
2480 be an unbounded amount of stuff. */
2481 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
2482 type
= make_qualified_type (newtype
,
2483 TYPE_INSTANCE_FLAGS (type
),
2489 /* Otherwise, rely on the stub flag being set for opaque/stubbed
2491 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
2493 const char *name
= type_name_no_tag (type
);
2494 /* FIXME: shouldn't we separately check the TYPE_NAME and the
2495 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
2496 as appropriate? (this code was written before TYPE_NAME and
2497 TYPE_TAG_NAME were separate). */
2502 stub_noname_complaint ();
2503 return make_qualified_type (type
, instance_flags
, NULL
);
2505 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0).symbol
;
2508 /* Same as above for opaque types, we can replace the stub
2509 with the complete type only if they are in the same
2511 if (TYPE_OBJFILE (SYMBOL_TYPE(sym
)) == TYPE_OBJFILE (type
))
2512 type
= make_qualified_type (SYMBOL_TYPE (sym
),
2513 TYPE_INSTANCE_FLAGS (type
),
2516 type
= SYMBOL_TYPE (sym
);
2520 if (TYPE_TARGET_STUB (type
))
2522 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
2524 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
2526 /* Nothing we can do. */
2528 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
2530 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
2531 TYPE_TARGET_STUB (type
) = 0;
2535 type
= make_qualified_type (type
, instance_flags
, NULL
);
2537 /* Cache TYPE_LENGTH for future use. */
2538 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
2543 /* Parse a type expression in the string [P..P+LENGTH). If an error
2544 occurs, silently return a void type. */
2546 static struct type
*
2547 safe_parse_type (struct gdbarch
*gdbarch
, char *p
, int length
)
2549 struct ui_file
*saved_gdb_stderr
;
2550 struct type
*type
= NULL
; /* Initialize to keep gcc happy. */
2552 /* Suppress error messages. */
2553 saved_gdb_stderr
= gdb_stderr
;
2554 gdb_stderr
= &null_stream
;
2556 /* Call parse_and_eval_type() without fear of longjmp()s. */
2559 type
= parse_and_eval_type (p
, length
);
2561 CATCH (except
, RETURN_MASK_ERROR
)
2563 type
= builtin_type (gdbarch
)->builtin_void
;
2567 /* Stop suppressing error messages. */
2568 gdb_stderr
= saved_gdb_stderr
;
2573 /* Ugly hack to convert method stubs into method types.
2575 He ain't kiddin'. This demangles the name of the method into a
2576 string including argument types, parses out each argument type,
2577 generates a string casting a zero to that type, evaluates the
2578 string, and stuffs the resulting type into an argtype vector!!!
2579 Then it knows the type of the whole function (including argument
2580 types for overloading), which info used to be in the stab's but was
2581 removed to hack back the space required for them. */
2584 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
2586 struct gdbarch
*gdbarch
= get_type_arch (type
);
2588 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
2589 char *demangled_name
= gdb_demangle (mangled_name
,
2590 DMGL_PARAMS
| DMGL_ANSI
);
2591 char *argtypetext
, *p
;
2592 int depth
= 0, argcount
= 1;
2593 struct field
*argtypes
;
2596 /* Make sure we got back a function string that we can use. */
2598 p
= strchr (demangled_name
, '(');
2602 if (demangled_name
== NULL
|| p
== NULL
)
2603 error (_("Internal: Cannot demangle mangled name `%s'."),
2606 /* Now, read in the parameters that define this type. */
2611 if (*p
== '(' || *p
== '<')
2615 else if (*p
== ')' || *p
== '>')
2619 else if (*p
== ',' && depth
== 0)
2627 /* If we read one argument and it was ``void'', don't count it. */
2628 if (startswith (argtypetext
, "(void)"))
2631 /* We need one extra slot, for the THIS pointer. */
2633 argtypes
= (struct field
*)
2634 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
2637 /* Add THIS pointer for non-static methods. */
2638 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
2639 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
2643 argtypes
[0].type
= lookup_pointer_type (type
);
2647 if (*p
!= ')') /* () means no args, skip while. */
2652 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
2654 /* Avoid parsing of ellipsis, they will be handled below.
2655 Also avoid ``void'' as above. */
2656 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
2657 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
2659 argtypes
[argcount
].type
=
2660 safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
);
2663 argtypetext
= p
+ 1;
2666 if (*p
== '(' || *p
== '<')
2670 else if (*p
== ')' || *p
== '>')
2679 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
2681 /* Now update the old "stub" type into a real type. */
2682 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
2683 /* MTYPE may currently be a function (TYPE_CODE_FUNC).
2684 We want a method (TYPE_CODE_METHOD). */
2685 smash_to_method_type (mtype
, type
, TYPE_TARGET_TYPE (mtype
),
2686 argtypes
, argcount
, p
[-2] == '.');
2687 TYPE_STUB (mtype
) = 0;
2688 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
2690 xfree (demangled_name
);
2693 /* This is the external interface to check_stub_method, above. This
2694 function unstubs all of the signatures for TYPE's METHOD_ID method
2695 name. After calling this function TYPE_FN_FIELD_STUB will be
2696 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
2699 This function unfortunately can not die until stabs do. */
2702 check_stub_method_group (struct type
*type
, int method_id
)
2704 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
2705 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
2706 int j
, found_stub
= 0;
2708 for (j
= 0; j
< len
; j
++)
2709 if (TYPE_FN_FIELD_STUB (f
, j
))
2712 check_stub_method (type
, method_id
, j
);
2715 /* GNU v3 methods with incorrect names were corrected when we read
2716 in type information, because it was cheaper to do it then. The
2717 only GNU v2 methods with incorrect method names are operators and
2718 destructors; destructors were also corrected when we read in type
2721 Therefore the only thing we need to handle here are v2 operator
2723 if (found_stub
&& !startswith (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z"))
2726 char dem_opname
[256];
2728 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
2730 dem_opname
, DMGL_ANSI
);
2732 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
2736 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
2740 /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
2741 const struct cplus_struct_type cplus_struct_default
= { };
2744 allocate_cplus_struct_type (struct type
*type
)
2746 if (HAVE_CPLUS_STRUCT (type
))
2747 /* Structure was already allocated. Nothing more to do. */
2750 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_CPLUS_STUFF
;
2751 TYPE_RAW_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
2752 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
2753 *(TYPE_RAW_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
2754 set_type_vptr_fieldno (type
, -1);
2757 const struct gnat_aux_type gnat_aux_default
=
2760 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
2761 and allocate the associated gnat-specific data. The gnat-specific
2762 data is also initialized to gnat_aux_default. */
2765 allocate_gnat_aux_type (struct type
*type
)
2767 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_GNAT_STUFF
;
2768 TYPE_GNAT_SPECIFIC (type
) = (struct gnat_aux_type
*)
2769 TYPE_ALLOC (type
, sizeof (struct gnat_aux_type
));
2770 *(TYPE_GNAT_SPECIFIC (type
)) = gnat_aux_default
;
2773 /* Helper function to initialize a newly allocated type. Set type code
2774 to CODE and initialize the type-specific fields accordingly. */
2777 set_type_code (struct type
*type
, enum type_code code
)
2779 TYPE_CODE (type
) = code
;
2783 case TYPE_CODE_STRUCT
:
2784 case TYPE_CODE_UNION
:
2785 case TYPE_CODE_NAMESPACE
:
2786 INIT_CPLUS_SPECIFIC (type
);
2789 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_FLOATFORMAT
;
2791 case TYPE_CODE_FUNC
:
2792 INIT_FUNC_SPECIFIC (type
);
2797 /* Helper function to verify floating-point format and size.
2798 BIT is the type size in bits; if BIT equals -1, the size is
2799 determined by the floatformat. Returns size to be used. */
2802 verify_floatformat (int bit
, const struct floatformat
*floatformat
)
2804 gdb_assert (floatformat
!= NULL
);
2807 bit
= floatformat
->totalsize
;
2809 gdb_assert (bit
>= 0);
2810 gdb_assert (bit
>= floatformat
->totalsize
);
2815 /* Return the floating-point format for a floating-point variable of
2818 const struct floatformat
*
2819 floatformat_from_type (const struct type
*type
)
2821 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLT
);
2822 gdb_assert (TYPE_FLOATFORMAT (type
));
2823 return TYPE_FLOATFORMAT (type
);
2826 /* Helper function to initialize the standard scalar types.
2828 If NAME is non-NULL, then it is used to initialize the type name.
2829 Note that NAME is not copied; it is required to have a lifetime at
2830 least as long as OBJFILE. */
2833 init_type (struct objfile
*objfile
, enum type_code code
, int bit
,
2838 type
= alloc_type (objfile
);
2839 set_type_code (type
, code
);
2840 gdb_assert ((bit
% TARGET_CHAR_BIT
) == 0);
2841 TYPE_LENGTH (type
) = bit
/ TARGET_CHAR_BIT
;
2842 TYPE_NAME (type
) = name
;
2847 /* Allocate a TYPE_CODE_ERROR type structure associated with OBJFILE,
2848 to use with variables that have no debug info. NAME is the type
2851 static struct type
*
2852 init_nodebug_var_type (struct objfile
*objfile
, const char *name
)
2854 return init_type (objfile
, TYPE_CODE_ERROR
, 0, name
);
2857 /* Allocate a TYPE_CODE_INT type structure associated with OBJFILE.
2858 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
2859 the type's TYPE_UNSIGNED flag. NAME is the type name. */
2862 init_integer_type (struct objfile
*objfile
,
2863 int bit
, int unsigned_p
, const char *name
)
2867 t
= init_type (objfile
, TYPE_CODE_INT
, bit
, name
);
2869 TYPE_UNSIGNED (t
) = 1;
2874 /* Allocate a TYPE_CODE_CHAR type structure associated with OBJFILE.
2875 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
2876 the type's TYPE_UNSIGNED flag. NAME is the type name. */
2879 init_character_type (struct objfile
*objfile
,
2880 int bit
, int unsigned_p
, const char *name
)
2884 t
= init_type (objfile
, TYPE_CODE_CHAR
, bit
, name
);
2886 TYPE_UNSIGNED (t
) = 1;
2891 /* Allocate a TYPE_CODE_BOOL type structure associated with OBJFILE.
2892 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
2893 the type's TYPE_UNSIGNED flag. NAME is the type name. */
2896 init_boolean_type (struct objfile
*objfile
,
2897 int bit
, int unsigned_p
, const char *name
)
2901 t
= init_type (objfile
, TYPE_CODE_BOOL
, bit
, name
);
2903 TYPE_UNSIGNED (t
) = 1;
2908 /* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
2909 BIT is the type size in bits; if BIT equals -1, the size is
2910 determined by the floatformat. NAME is the type name. Set the
2911 TYPE_FLOATFORMAT from FLOATFORMATS. */
2914 init_float_type (struct objfile
*objfile
,
2915 int bit
, const char *name
,
2916 const struct floatformat
**floatformats
)
2918 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2919 const struct floatformat
*fmt
= floatformats
[gdbarch_byte_order (gdbarch
)];
2922 bit
= verify_floatformat (bit
, fmt
);
2923 t
= init_type (objfile
, TYPE_CODE_FLT
, bit
, name
);
2924 TYPE_FLOATFORMAT (t
) = fmt
;
2929 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with OBJFILE.
2930 BIT is the type size in bits. NAME is the type name. */
2933 init_decfloat_type (struct objfile
*objfile
, int bit
, const char *name
)
2937 t
= init_type (objfile
, TYPE_CODE_DECFLOAT
, bit
, name
);
2941 /* Allocate a TYPE_CODE_COMPLEX type structure associated with OBJFILE.
2942 NAME is the type name. TARGET_TYPE is the component float type. */
2945 init_complex_type (struct objfile
*objfile
,
2946 const char *name
, struct type
*target_type
)
2950 t
= init_type (objfile
, TYPE_CODE_COMPLEX
,
2951 2 * TYPE_LENGTH (target_type
) * TARGET_CHAR_BIT
, name
);
2952 TYPE_TARGET_TYPE (t
) = target_type
;
2956 /* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE.
2957 BIT is the pointer type size in bits. NAME is the type name.
2958 TARGET_TYPE is the pointer target type. Always sets the pointer type's
2959 TYPE_UNSIGNED flag. */
2962 init_pointer_type (struct objfile
*objfile
,
2963 int bit
, const char *name
, struct type
*target_type
)
2967 t
= init_type (objfile
, TYPE_CODE_PTR
, bit
, name
);
2968 TYPE_TARGET_TYPE (t
) = target_type
;
2969 TYPE_UNSIGNED (t
) = 1;
2974 /* Queries on types. */
2977 can_dereference (struct type
*t
)
2979 /* FIXME: Should we return true for references as well as
2981 t
= check_typedef (t
);
2984 && TYPE_CODE (t
) == TYPE_CODE_PTR
2985 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
2989 is_integral_type (struct type
*t
)
2991 t
= check_typedef (t
);
2994 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
2995 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
2996 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
2997 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
2998 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
2999 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
3003 is_floating_type (struct type
*t
)
3005 t
= check_typedef (t
);
3008 && ((TYPE_CODE (t
) == TYPE_CODE_FLT
)
3009 || (TYPE_CODE (t
) == TYPE_CODE_DECFLOAT
)));
3012 /* Return true if TYPE is scalar. */
3015 is_scalar_type (struct type
*type
)
3017 type
= check_typedef (type
);
3019 switch (TYPE_CODE (type
))
3021 case TYPE_CODE_ARRAY
:
3022 case TYPE_CODE_STRUCT
:
3023 case TYPE_CODE_UNION
:
3025 case TYPE_CODE_STRING
:
3032 /* Return true if T is scalar, or a composite type which in practice has
3033 the memory layout of a scalar type. E.g., an array or struct with only
3034 one scalar element inside it, or a union with only scalar elements. */
3037 is_scalar_type_recursive (struct type
*t
)
3039 t
= check_typedef (t
);
3041 if (is_scalar_type (t
))
3043 /* Are we dealing with an array or string of known dimensions? */
3044 else if ((TYPE_CODE (t
) == TYPE_CODE_ARRAY
3045 || TYPE_CODE (t
) == TYPE_CODE_STRING
) && TYPE_NFIELDS (t
) == 1
3046 && TYPE_CODE (TYPE_INDEX_TYPE (t
)) == TYPE_CODE_RANGE
)
3048 LONGEST low_bound
, high_bound
;
3049 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (t
));
3051 get_discrete_bounds (TYPE_INDEX_TYPE (t
), &low_bound
, &high_bound
);
3053 return high_bound
== low_bound
&& is_scalar_type_recursive (elt_type
);
3055 /* Are we dealing with a struct with one element? */
3056 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
&& TYPE_NFIELDS (t
) == 1)
3057 return is_scalar_type_recursive (TYPE_FIELD_TYPE (t
, 0));
3058 else if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
3060 int i
, n
= TYPE_NFIELDS (t
);
3062 /* If all elements of the union are scalar, then the union is scalar. */
3063 for (i
= 0; i
< n
; i
++)
3064 if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t
, i
)))
3073 /* Return true is T is a class or a union. False otherwise. */
3076 class_or_union_p (const struct type
*t
)
3078 return (TYPE_CODE (t
) == TYPE_CODE_STRUCT
3079 || TYPE_CODE (t
) == TYPE_CODE_UNION
);
3082 /* A helper function which returns true if types A and B represent the
3083 "same" class type. This is true if the types have the same main
3084 type, or the same name. */
3087 class_types_same_p (const struct type
*a
, const struct type
*b
)
3089 return (TYPE_MAIN_TYPE (a
) == TYPE_MAIN_TYPE (b
)
3090 || (TYPE_NAME (a
) && TYPE_NAME (b
)
3091 && !strcmp (TYPE_NAME (a
), TYPE_NAME (b
))));
3094 /* If BASE is an ancestor of DCLASS return the distance between them.
3095 otherwise return -1;
3099 class B: public A {};
3100 class C: public B {};
3103 distance_to_ancestor (A, A, 0) = 0
3104 distance_to_ancestor (A, B, 0) = 1
3105 distance_to_ancestor (A, C, 0) = 2
3106 distance_to_ancestor (A, D, 0) = 3
3108 If PUBLIC is 1 then only public ancestors are considered,
3109 and the function returns the distance only if BASE is a public ancestor
3113 distance_to_ancestor (A, D, 1) = -1. */
3116 distance_to_ancestor (struct type
*base
, struct type
*dclass
, int is_public
)
3121 base
= check_typedef (base
);
3122 dclass
= check_typedef (dclass
);
3124 if (class_types_same_p (base
, dclass
))
3127 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
3129 if (is_public
&& ! BASETYPE_VIA_PUBLIC (dclass
, i
))
3132 d
= distance_to_ancestor (base
, TYPE_BASECLASS (dclass
, i
), is_public
);
3140 /* Check whether BASE is an ancestor or base class or DCLASS
3141 Return 1 if so, and 0 if not.
3142 Note: If BASE and DCLASS are of the same type, this function
3143 will return 1. So for some class A, is_ancestor (A, A) will
3147 is_ancestor (struct type
*base
, struct type
*dclass
)
3149 return distance_to_ancestor (base
, dclass
, 0) >= 0;
3152 /* Like is_ancestor, but only returns true when BASE is a public
3153 ancestor of DCLASS. */
3156 is_public_ancestor (struct type
*base
, struct type
*dclass
)
3158 return distance_to_ancestor (base
, dclass
, 1) >= 0;
3161 /* A helper function for is_unique_ancestor. */
3164 is_unique_ancestor_worker (struct type
*base
, struct type
*dclass
,
3166 const gdb_byte
*valaddr
, int embedded_offset
,
3167 CORE_ADDR address
, struct value
*val
)
3171 base
= check_typedef (base
);
3172 dclass
= check_typedef (dclass
);
3174 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
) && count
< 2; ++i
)
3179 iter
= check_typedef (TYPE_BASECLASS (dclass
, i
));
3181 this_offset
= baseclass_offset (dclass
, i
, valaddr
, embedded_offset
,
3184 if (class_types_same_p (base
, iter
))
3186 /* If this is the first subclass, set *OFFSET and set count
3187 to 1. Otherwise, if this is at the same offset as
3188 previous instances, do nothing. Otherwise, increment
3192 *offset
= this_offset
;
3195 else if (this_offset
== *offset
)
3203 count
+= is_unique_ancestor_worker (base
, iter
, offset
,
3205 embedded_offset
+ this_offset
,
3212 /* Like is_ancestor, but only returns true if BASE is a unique base
3213 class of the type of VAL. */
3216 is_unique_ancestor (struct type
*base
, struct value
*val
)
3220 return is_unique_ancestor_worker (base
, value_type (val
), &offset
,
3221 value_contents_for_printing (val
),
3222 value_embedded_offset (val
),
3223 value_address (val
), val
) == 1;
3227 /* Overload resolution. */
3229 /* Return the sum of the rank of A with the rank of B. */
3232 sum_ranks (struct rank a
, struct rank b
)
3235 c
.rank
= a
.rank
+ b
.rank
;
3236 c
.subrank
= a
.subrank
+ b
.subrank
;
3240 /* Compare rank A and B and return:
3242 1 if a is better than b
3243 -1 if b is better than a. */
3246 compare_ranks (struct rank a
, struct rank b
)
3248 if (a
.rank
== b
.rank
)
3250 if (a
.subrank
== b
.subrank
)
3252 if (a
.subrank
< b
.subrank
)
3254 if (a
.subrank
> b
.subrank
)
3258 if (a
.rank
< b
.rank
)
3261 /* a.rank > b.rank */
3265 /* Functions for overload resolution begin here. */
3267 /* Compare two badness vectors A and B and return the result.
3268 0 => A and B are identical
3269 1 => A and B are incomparable
3270 2 => A is better than B
3271 3 => A is worse than B */
3274 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
3278 short found_pos
= 0; /* any positives in c? */
3279 short found_neg
= 0; /* any negatives in c? */
3281 /* differing lengths => incomparable */
3282 if (a
->length
!= b
->length
)
3285 /* Subtract b from a */
3286 for (i
= 0; i
< a
->length
; i
++)
3288 tmp
= compare_ranks (b
->rank
[i
], a
->rank
[i
]);
3298 return 1; /* incomparable */
3300 return 3; /* A > B */
3306 return 2; /* A < B */
3308 return 0; /* A == B */
3312 /* Rank a function by comparing its parameter types (PARMS, length
3313 NPARMS), to the types of an argument list (ARGS, length NARGS).
3314 Return a pointer to a badness vector. This has NARGS + 1
3317 struct badness_vector
*
3318 rank_function (struct type
**parms
, int nparms
,
3319 struct value
**args
, int nargs
)
3322 struct badness_vector
*bv
= XNEW (struct badness_vector
);
3323 int min_len
= nparms
< nargs
? nparms
: nargs
;
3325 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank. */
3326 bv
->rank
= XNEWVEC (struct rank
, nargs
+ 1);
3328 /* First compare the lengths of the supplied lists.
3329 If there is a mismatch, set it to a high value. */
3331 /* pai/1997-06-03 FIXME: when we have debug info about default
3332 arguments and ellipsis parameter lists, we should consider those
3333 and rank the length-match more finely. */
3335 LENGTH_MATCH (bv
) = (nargs
!= nparms
)
3336 ? LENGTH_MISMATCH_BADNESS
3337 : EXACT_MATCH_BADNESS
;
3339 /* Now rank all the parameters of the candidate function. */
3340 for (i
= 1; i
<= min_len
; i
++)
3341 bv
->rank
[i
] = rank_one_type (parms
[i
- 1], value_type (args
[i
- 1]),
3344 /* If more arguments than parameters, add dummy entries. */
3345 for (i
= min_len
+ 1; i
<= nargs
; i
++)
3346 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
3351 /* Compare the names of two integer types, assuming that any sign
3352 qualifiers have been checked already. We do it this way because
3353 there may be an "int" in the name of one of the types. */
3356 integer_types_same_name_p (const char *first
, const char *second
)
3358 int first_p
, second_p
;
3360 /* If both are shorts, return 1; if neither is a short, keep
3362 first_p
= (strstr (first
, "short") != NULL
);
3363 second_p
= (strstr (second
, "short") != NULL
);
3364 if (first_p
&& second_p
)
3366 if (first_p
|| second_p
)
3369 /* Likewise for long. */
3370 first_p
= (strstr (first
, "long") != NULL
);
3371 second_p
= (strstr (second
, "long") != NULL
);
3372 if (first_p
&& second_p
)
3374 if (first_p
|| second_p
)
3377 /* Likewise for char. */
3378 first_p
= (strstr (first
, "char") != NULL
);
3379 second_p
= (strstr (second
, "char") != NULL
);
3380 if (first_p
&& second_p
)
3382 if (first_p
|| second_p
)
3385 /* They must both be ints. */
3389 /* Compares type A to type B returns 1 if the represent the same type
3393 types_equal (struct type
*a
, struct type
*b
)
3395 /* Identical type pointers. */
3396 /* However, this still doesn't catch all cases of same type for b
3397 and a. The reason is that builtin types are different from
3398 the same ones constructed from the object. */
3402 /* Resolve typedefs */
3403 if (TYPE_CODE (a
) == TYPE_CODE_TYPEDEF
)
3404 a
= check_typedef (a
);
3405 if (TYPE_CODE (b
) == TYPE_CODE_TYPEDEF
)
3406 b
= check_typedef (b
);
3408 /* If after resolving typedefs a and b are not of the same type
3409 code then they are not equal. */
3410 if (TYPE_CODE (a
) != TYPE_CODE (b
))
3413 /* If a and b are both pointers types or both reference types then
3414 they are equal of the same type iff the objects they refer to are
3415 of the same type. */
3416 if (TYPE_CODE (a
) == TYPE_CODE_PTR
3417 || TYPE_CODE (a
) == TYPE_CODE_REF
)
3418 return types_equal (TYPE_TARGET_TYPE (a
),
3419 TYPE_TARGET_TYPE (b
));
3421 /* Well, damnit, if the names are exactly the same, I'll say they
3422 are exactly the same. This happens when we generate method
3423 stubs. The types won't point to the same address, but they
3424 really are the same. */
3426 if (TYPE_NAME (a
) && TYPE_NAME (b
)
3427 && strcmp (TYPE_NAME (a
), TYPE_NAME (b
)) == 0)
3430 /* Check if identical after resolving typedefs. */
3434 /* Two function types are equal if their argument and return types
3436 if (TYPE_CODE (a
) == TYPE_CODE_FUNC
)
3440 if (TYPE_NFIELDS (a
) != TYPE_NFIELDS (b
))
3443 if (!types_equal (TYPE_TARGET_TYPE (a
), TYPE_TARGET_TYPE (b
)))
3446 for (i
= 0; i
< TYPE_NFIELDS (a
); ++i
)
3447 if (!types_equal (TYPE_FIELD_TYPE (a
, i
), TYPE_FIELD_TYPE (b
, i
)))
3456 /* Deep comparison of types. */
3458 /* An entry in the type-equality bcache. */
3460 typedef struct type_equality_entry
3462 struct type
*type1
, *type2
;
3463 } type_equality_entry_d
;
3465 DEF_VEC_O (type_equality_entry_d
);
3467 /* A helper function to compare two strings. Returns 1 if they are
3468 the same, 0 otherwise. Handles NULLs properly. */
3471 compare_maybe_null_strings (const char *s
, const char *t
)
3473 if (s
== NULL
&& t
!= NULL
)
3475 else if (s
!= NULL
&& t
== NULL
)
3477 else if (s
== NULL
&& t
== NULL
)
3479 return strcmp (s
, t
) == 0;
3482 /* A helper function for check_types_worklist that checks two types for
3483 "deep" equality. Returns non-zero if the types are considered the
3484 same, zero otherwise. */
3487 check_types_equal (struct type
*type1
, struct type
*type2
,
3488 VEC (type_equality_entry_d
) **worklist
)
3490 type1
= check_typedef (type1
);
3491 type2
= check_typedef (type2
);
3496 if (TYPE_CODE (type1
) != TYPE_CODE (type2
)
3497 || TYPE_LENGTH (type1
) != TYPE_LENGTH (type2
)
3498 || TYPE_UNSIGNED (type1
) != TYPE_UNSIGNED (type2
)
3499 || TYPE_NOSIGN (type1
) != TYPE_NOSIGN (type2
)
3500 || TYPE_VARARGS (type1
) != TYPE_VARARGS (type2
)
3501 || TYPE_VECTOR (type1
) != TYPE_VECTOR (type2
)
3502 || TYPE_NOTTEXT (type1
) != TYPE_NOTTEXT (type2
)
3503 || TYPE_INSTANCE_FLAGS (type1
) != TYPE_INSTANCE_FLAGS (type2
)
3504 || TYPE_NFIELDS (type1
) != TYPE_NFIELDS (type2
))
3507 if (!compare_maybe_null_strings (TYPE_TAG_NAME (type1
),
3508 TYPE_TAG_NAME (type2
)))
3510 if (!compare_maybe_null_strings (TYPE_NAME (type1
), TYPE_NAME (type2
)))
3513 if (TYPE_CODE (type1
) == TYPE_CODE_RANGE
)
3515 if (memcmp (TYPE_RANGE_DATA (type1
), TYPE_RANGE_DATA (type2
),
3516 sizeof (*TYPE_RANGE_DATA (type1
))) != 0)
3523 for (i
= 0; i
< TYPE_NFIELDS (type1
); ++i
)
3525 const struct field
*field1
= &TYPE_FIELD (type1
, i
);
3526 const struct field
*field2
= &TYPE_FIELD (type2
, i
);
3527 struct type_equality_entry entry
;
3529 if (FIELD_ARTIFICIAL (*field1
) != FIELD_ARTIFICIAL (*field2
)
3530 || FIELD_BITSIZE (*field1
) != FIELD_BITSIZE (*field2
)
3531 || FIELD_LOC_KIND (*field1
) != FIELD_LOC_KIND (*field2
))
3533 if (!compare_maybe_null_strings (FIELD_NAME (*field1
),
3534 FIELD_NAME (*field2
)))
3536 switch (FIELD_LOC_KIND (*field1
))
3538 case FIELD_LOC_KIND_BITPOS
:
3539 if (FIELD_BITPOS (*field1
) != FIELD_BITPOS (*field2
))
3542 case FIELD_LOC_KIND_ENUMVAL
:
3543 if (FIELD_ENUMVAL (*field1
) != FIELD_ENUMVAL (*field2
))
3546 case FIELD_LOC_KIND_PHYSADDR
:
3547 if (FIELD_STATIC_PHYSADDR (*field1
)
3548 != FIELD_STATIC_PHYSADDR (*field2
))
3551 case FIELD_LOC_KIND_PHYSNAME
:
3552 if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1
),
3553 FIELD_STATIC_PHYSNAME (*field2
)))
3556 case FIELD_LOC_KIND_DWARF_BLOCK
:
3558 struct dwarf2_locexpr_baton
*block1
, *block2
;
3560 block1
= FIELD_DWARF_BLOCK (*field1
);
3561 block2
= FIELD_DWARF_BLOCK (*field2
);
3562 if (block1
->per_cu
!= block2
->per_cu
3563 || block1
->size
!= block2
->size
3564 || memcmp (block1
->data
, block2
->data
, block1
->size
) != 0)
3569 internal_error (__FILE__
, __LINE__
, _("Unsupported field kind "
3570 "%d by check_types_equal"),
3571 FIELD_LOC_KIND (*field1
));
3574 entry
.type1
= FIELD_TYPE (*field1
);
3575 entry
.type2
= FIELD_TYPE (*field2
);
3576 VEC_safe_push (type_equality_entry_d
, *worklist
, &entry
);
3580 if (TYPE_TARGET_TYPE (type1
) != NULL
)
3582 struct type_equality_entry entry
;
3584 if (TYPE_TARGET_TYPE (type2
) == NULL
)
3587 entry
.type1
= TYPE_TARGET_TYPE (type1
);
3588 entry
.type2
= TYPE_TARGET_TYPE (type2
);
3589 VEC_safe_push (type_equality_entry_d
, *worklist
, &entry
);
3591 else if (TYPE_TARGET_TYPE (type2
) != NULL
)
3597 /* Check types on a worklist for equality. Returns zero if any pair
3598 is not equal, non-zero if they are all considered equal. */
3601 check_types_worklist (VEC (type_equality_entry_d
) **worklist
,
3602 struct bcache
*cache
)
3604 while (!VEC_empty (type_equality_entry_d
, *worklist
))
3606 struct type_equality_entry entry
;
3609 entry
= *VEC_last (type_equality_entry_d
, *worklist
);
3610 VEC_pop (type_equality_entry_d
, *worklist
);
3612 /* If the type pair has already been visited, we know it is
3614 bcache_full (&entry
, sizeof (entry
), cache
, &added
);
3618 if (check_types_equal (entry
.type1
, entry
.type2
, worklist
) == 0)
3625 /* Return non-zero if types TYPE1 and TYPE2 are equal, as determined by a
3626 "deep comparison". Otherwise return zero. */
3629 types_deeply_equal (struct type
*type1
, struct type
*type2
)
3631 struct gdb_exception except
= exception_none
;
3633 struct bcache
*cache
;
3634 VEC (type_equality_entry_d
) *worklist
= NULL
;
3635 struct type_equality_entry entry
;
3637 gdb_assert (type1
!= NULL
&& type2
!= NULL
);
3639 /* Early exit for the simple case. */
3643 cache
= bcache_xmalloc (NULL
, NULL
);
3645 entry
.type1
= type1
;
3646 entry
.type2
= type2
;
3647 VEC_safe_push (type_equality_entry_d
, worklist
, &entry
);
3649 /* check_types_worklist calls several nested helper functions, some
3650 of which can raise a GDB exception, so we just check and rethrow
3651 here. If there is a GDB exception, a comparison is not capable
3652 (or trusted), so exit. */
3655 result
= check_types_worklist (&worklist
, cache
);
3657 CATCH (ex
, RETURN_MASK_ALL
)
3663 bcache_xfree (cache
);
3664 VEC_free (type_equality_entry_d
, worklist
);
3666 /* Rethrow if there was a problem. */
3667 if (except
.reason
< 0)
3668 throw_exception (except
);
3673 /* Allocated status of type TYPE. Return zero if type TYPE is allocated.
3674 Otherwise return one. */
3677 type_not_allocated (const struct type
*type
)
3679 struct dynamic_prop
*prop
= TYPE_ALLOCATED_PROP (type
);
3681 return (prop
&& TYPE_DYN_PROP_KIND (prop
) == PROP_CONST
3682 && !TYPE_DYN_PROP_ADDR (prop
));
3685 /* Associated status of type TYPE. Return zero if type TYPE is associated.
3686 Otherwise return one. */
3689 type_not_associated (const struct type
*type
)
3691 struct dynamic_prop
*prop
= TYPE_ASSOCIATED_PROP (type
);
3693 return (prop
&& TYPE_DYN_PROP_KIND (prop
) == PROP_CONST
3694 && !TYPE_DYN_PROP_ADDR (prop
));
3697 /* Compare one type (PARM) for compatibility with another (ARG).
3698 * PARM is intended to be the parameter type of a function; and
3699 * ARG is the supplied argument's type. This function tests if
3700 * the latter can be converted to the former.
3701 * VALUE is the argument's value or NULL if none (or called recursively)
3703 * Return 0 if they are identical types;
3704 * Otherwise, return an integer which corresponds to how compatible
3705 * PARM is to ARG. The higher the return value, the worse the match.
3706 * Generally the "bad" conversions are all uniformly assigned a 100. */
3709 rank_one_type (struct type
*parm
, struct type
*arg
, struct value
*value
)
3711 struct rank rank
= {0,0};
3713 /* Resolve typedefs */
3714 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
3715 parm
= check_typedef (parm
);
3716 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
3717 arg
= check_typedef (arg
);
3719 if (TYPE_IS_REFERENCE (parm
) && value
!= NULL
)
3721 if (VALUE_LVAL (value
) == not_lval
)
3723 /* Rvalues should preferably bind to rvalue references or const
3724 lvalue references. */
3725 if (TYPE_CODE (parm
) == TYPE_CODE_RVALUE_REF
)
3726 rank
.subrank
= REFERENCE_CONVERSION_RVALUE
;
3727 else if (TYPE_CONST (TYPE_TARGET_TYPE (parm
)))
3728 rank
.subrank
= REFERENCE_CONVERSION_CONST_LVALUE
;
3730 return INCOMPATIBLE_TYPE_BADNESS
;
3731 return sum_ranks (rank
, REFERENCE_CONVERSION_BADNESS
);
3735 /* Lvalues should prefer lvalue overloads. */
3736 if (TYPE_CODE (parm
) == TYPE_CODE_RVALUE_REF
)
3738 rank
.subrank
= REFERENCE_CONVERSION_RVALUE
;
3739 return sum_ranks (rank
, REFERENCE_CONVERSION_BADNESS
);
3744 if (types_equal (parm
, arg
))
3746 struct type
*t1
= parm
;
3747 struct type
*t2
= arg
;
3749 /* For pointers and references, compare target type. */
3750 if (TYPE_CODE (parm
) == TYPE_CODE_PTR
|| TYPE_IS_REFERENCE (parm
))
3752 t1
= TYPE_TARGET_TYPE (parm
);
3753 t2
= TYPE_TARGET_TYPE (arg
);
3756 /* Make sure they are CV equal, too. */
3757 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
3758 rank
.subrank
|= CV_CONVERSION_CONST
;
3759 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
3760 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
3761 if (rank
.subrank
!= 0)
3762 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
3763 return EXACT_MATCH_BADNESS
;
3766 /* See through references, since we can almost make non-references
3769 if (TYPE_IS_REFERENCE (arg
))
3770 return (sum_ranks (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
), NULL
),
3771 REFERENCE_CONVERSION_BADNESS
));
3772 if (TYPE_IS_REFERENCE (parm
))
3773 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
, NULL
),
3774 REFERENCE_CONVERSION_BADNESS
));
3776 /* Debugging only. */
3777 fprintf_filtered (gdb_stderr
,
3778 "------ Arg is %s [%d], parm is %s [%d]\n",
3779 TYPE_NAME (arg
), TYPE_CODE (arg
),
3780 TYPE_NAME (parm
), TYPE_CODE (parm
));
3782 /* x -> y means arg of type x being supplied for parameter of type y. */
3784 switch (TYPE_CODE (parm
))
3787 switch (TYPE_CODE (arg
))
3791 /* Allowed pointer conversions are:
3792 (a) pointer to void-pointer conversion. */
3793 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
3794 return VOID_PTR_CONVERSION_BADNESS
;
3796 /* (b) pointer to ancestor-pointer conversion. */
3797 rank
.subrank
= distance_to_ancestor (TYPE_TARGET_TYPE (parm
),
3798 TYPE_TARGET_TYPE (arg
),
3800 if (rank
.subrank
>= 0)
3801 return sum_ranks (BASE_PTR_CONVERSION_BADNESS
, rank
);
3803 return INCOMPATIBLE_TYPE_BADNESS
;
3804 case TYPE_CODE_ARRAY
:
3806 struct type
*t1
= TYPE_TARGET_TYPE (parm
);
3807 struct type
*t2
= TYPE_TARGET_TYPE (arg
);
3809 if (types_equal (t1
, t2
))
3811 /* Make sure they are CV equal. */
3812 if (TYPE_CONST (t1
) != TYPE_CONST (t2
))
3813 rank
.subrank
|= CV_CONVERSION_CONST
;
3814 if (TYPE_VOLATILE (t1
) != TYPE_VOLATILE (t2
))
3815 rank
.subrank
|= CV_CONVERSION_VOLATILE
;
3816 if (rank
.subrank
!= 0)
3817 return sum_ranks (CV_CONVERSION_BADNESS
, rank
);
3818 return EXACT_MATCH_BADNESS
;
3820 return INCOMPATIBLE_TYPE_BADNESS
;
3822 case TYPE_CODE_FUNC
:
3823 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
, NULL
);
3825 if (value
!= NULL
&& TYPE_CODE (value_type (value
)) == TYPE_CODE_INT
)
3827 if (value_as_long (value
) == 0)
3829 /* Null pointer conversion: allow it to be cast to a pointer.
3830 [4.10.1 of C++ standard draft n3290] */
3831 return NULL_POINTER_CONVERSION_BADNESS
;
3835 /* If type checking is disabled, allow the conversion. */
3836 if (!strict_type_checking
)
3837 return NS_INTEGER_POINTER_CONVERSION_BADNESS
;
3841 case TYPE_CODE_ENUM
:
3842 case TYPE_CODE_FLAGS
:
3843 case TYPE_CODE_CHAR
:
3844 case TYPE_CODE_RANGE
:
3845 case TYPE_CODE_BOOL
:
3847 return INCOMPATIBLE_TYPE_BADNESS
;
3849 case TYPE_CODE_ARRAY
:
3850 switch (TYPE_CODE (arg
))
3853 case TYPE_CODE_ARRAY
:
3854 return rank_one_type (TYPE_TARGET_TYPE (parm
),
3855 TYPE_TARGET_TYPE (arg
), NULL
);
3857 return INCOMPATIBLE_TYPE_BADNESS
;
3859 case TYPE_CODE_FUNC
:
3860 switch (TYPE_CODE (arg
))
3862 case TYPE_CODE_PTR
: /* funcptr -> func */
3863 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
), NULL
);
3865 return INCOMPATIBLE_TYPE_BADNESS
;
3868 switch (TYPE_CODE (arg
))
3871 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
3873 /* Deal with signed, unsigned, and plain chars and
3874 signed and unsigned ints. */
3875 if (TYPE_NOSIGN (parm
))
3877 /* This case only for character types. */
3878 if (TYPE_NOSIGN (arg
))
3879 return EXACT_MATCH_BADNESS
; /* plain char -> plain char */
3880 else /* signed/unsigned char -> plain char */
3881 return INTEGER_CONVERSION_BADNESS
;
3883 else if (TYPE_UNSIGNED (parm
))
3885 if (TYPE_UNSIGNED (arg
))
3887 /* unsigned int -> unsigned int, or
3888 unsigned long -> unsigned long */
3889 if (integer_types_same_name_p (TYPE_NAME (parm
),
3891 return EXACT_MATCH_BADNESS
;
3892 else if (integer_types_same_name_p (TYPE_NAME (arg
),
3894 && integer_types_same_name_p (TYPE_NAME (parm
),
3896 /* unsigned int -> unsigned long */
3897 return INTEGER_PROMOTION_BADNESS
;
3899 /* unsigned long -> unsigned int */
3900 return INTEGER_CONVERSION_BADNESS
;
3904 if (integer_types_same_name_p (TYPE_NAME (arg
),
3906 && integer_types_same_name_p (TYPE_NAME (parm
),
3908 /* signed long -> unsigned int */
3909 return INTEGER_CONVERSION_BADNESS
;
3911 /* signed int/long -> unsigned int/long */
3912 return INTEGER_CONVERSION_BADNESS
;
3915 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
3917 if (integer_types_same_name_p (TYPE_NAME (parm
),
3919 return EXACT_MATCH_BADNESS
;
3920 else if (integer_types_same_name_p (TYPE_NAME (arg
),
3922 && integer_types_same_name_p (TYPE_NAME (parm
),
3924 return INTEGER_PROMOTION_BADNESS
;
3926 return INTEGER_CONVERSION_BADNESS
;
3929 return INTEGER_CONVERSION_BADNESS
;
3931 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
3932 return INTEGER_PROMOTION_BADNESS
;
3934 return INTEGER_CONVERSION_BADNESS
;
3935 case TYPE_CODE_ENUM
:
3936 case TYPE_CODE_FLAGS
:
3937 case TYPE_CODE_CHAR
:
3938 case TYPE_CODE_RANGE
:
3939 case TYPE_CODE_BOOL
:
3940 if (TYPE_DECLARED_CLASS (arg
))
3941 return INCOMPATIBLE_TYPE_BADNESS
;
3942 return INTEGER_PROMOTION_BADNESS
;
3944 return INT_FLOAT_CONVERSION_BADNESS
;
3946 return NS_POINTER_CONVERSION_BADNESS
;
3948 return INCOMPATIBLE_TYPE_BADNESS
;
3951 case TYPE_CODE_ENUM
:
3952 switch (TYPE_CODE (arg
))
3955 case TYPE_CODE_CHAR
:
3956 case TYPE_CODE_RANGE
:
3957 case TYPE_CODE_BOOL
:
3958 case TYPE_CODE_ENUM
:
3959 if (TYPE_DECLARED_CLASS (parm
) || TYPE_DECLARED_CLASS (arg
))
3960 return INCOMPATIBLE_TYPE_BADNESS
;
3961 return INTEGER_CONVERSION_BADNESS
;
3963 return INT_FLOAT_CONVERSION_BADNESS
;
3965 return INCOMPATIBLE_TYPE_BADNESS
;
3968 case TYPE_CODE_CHAR
:
3969 switch (TYPE_CODE (arg
))
3971 case TYPE_CODE_RANGE
:
3972 case TYPE_CODE_BOOL
:
3973 case TYPE_CODE_ENUM
:
3974 if (TYPE_DECLARED_CLASS (arg
))
3975 return INCOMPATIBLE_TYPE_BADNESS
;
3976 return INTEGER_CONVERSION_BADNESS
;
3978 return INT_FLOAT_CONVERSION_BADNESS
;
3980 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
3981 return INTEGER_CONVERSION_BADNESS
;
3982 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
3983 return INTEGER_PROMOTION_BADNESS
;
3984 /* >>> !! else fall through !! <<< */
3985 case TYPE_CODE_CHAR
:
3986 /* Deal with signed, unsigned, and plain chars for C++ and
3987 with int cases falling through from previous case. */
3988 if (TYPE_NOSIGN (parm
))
3990 if (TYPE_NOSIGN (arg
))
3991 return EXACT_MATCH_BADNESS
;
3993 return INTEGER_CONVERSION_BADNESS
;
3995 else if (TYPE_UNSIGNED (parm
))
3997 if (TYPE_UNSIGNED (arg
))
3998 return EXACT_MATCH_BADNESS
;
4000 return INTEGER_PROMOTION_BADNESS
;
4002 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
4003 return EXACT_MATCH_BADNESS
;
4005 return INTEGER_CONVERSION_BADNESS
;
4007 return INCOMPATIBLE_TYPE_BADNESS
;
4010 case TYPE_CODE_RANGE
:
4011 switch (TYPE_CODE (arg
))
4014 case TYPE_CODE_CHAR
:
4015 case TYPE_CODE_RANGE
:
4016 case TYPE_CODE_BOOL
:
4017 case TYPE_CODE_ENUM
:
4018 return INTEGER_CONVERSION_BADNESS
;
4020 return INT_FLOAT_CONVERSION_BADNESS
;
4022 return INCOMPATIBLE_TYPE_BADNESS
;
4025 case TYPE_CODE_BOOL
:
4026 switch (TYPE_CODE (arg
))
4028 /* n3290 draft, section 4.12.1 (conv.bool):
4030 "A prvalue of arithmetic, unscoped enumeration, pointer, or
4031 pointer to member type can be converted to a prvalue of type
4032 bool. A zero value, null pointer value, or null member pointer
4033 value is converted to false; any other value is converted to
4034 true. A prvalue of type std::nullptr_t can be converted to a
4035 prvalue of type bool; the resulting value is false." */
4037 case TYPE_CODE_CHAR
:
4038 case TYPE_CODE_ENUM
:
4040 case TYPE_CODE_MEMBERPTR
:
4042 return BOOL_CONVERSION_BADNESS
;
4043 case TYPE_CODE_RANGE
:
4044 return INCOMPATIBLE_TYPE_BADNESS
;
4045 case TYPE_CODE_BOOL
:
4046 return EXACT_MATCH_BADNESS
;
4048 return INCOMPATIBLE_TYPE_BADNESS
;
4052 switch (TYPE_CODE (arg
))
4055 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
4056 return FLOAT_PROMOTION_BADNESS
;
4057 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
4058 return EXACT_MATCH_BADNESS
;
4060 return FLOAT_CONVERSION_BADNESS
;
4062 case TYPE_CODE_BOOL
:
4063 case TYPE_CODE_ENUM
:
4064 case TYPE_CODE_RANGE
:
4065 case TYPE_CODE_CHAR
:
4066 return INT_FLOAT_CONVERSION_BADNESS
;
4068 return INCOMPATIBLE_TYPE_BADNESS
;
4071 case TYPE_CODE_COMPLEX
:
4072 switch (TYPE_CODE (arg
))
4073 { /* Strictly not needed for C++, but... */
4075 return FLOAT_PROMOTION_BADNESS
;
4076 case TYPE_CODE_COMPLEX
:
4077 return EXACT_MATCH_BADNESS
;
4079 return INCOMPATIBLE_TYPE_BADNESS
;
4082 case TYPE_CODE_STRUCT
:
4083 switch (TYPE_CODE (arg
))
4085 case TYPE_CODE_STRUCT
:
4086 /* Check for derivation */
4087 rank
.subrank
= distance_to_ancestor (parm
, arg
, 0);
4088 if (rank
.subrank
>= 0)
4089 return sum_ranks (BASE_CONVERSION_BADNESS
, rank
);
4090 /* else fall through */
4092 return INCOMPATIBLE_TYPE_BADNESS
;
4095 case TYPE_CODE_UNION
:
4096 switch (TYPE_CODE (arg
))
4098 case TYPE_CODE_UNION
:
4100 return INCOMPATIBLE_TYPE_BADNESS
;
4103 case TYPE_CODE_MEMBERPTR
:
4104 switch (TYPE_CODE (arg
))
4107 return INCOMPATIBLE_TYPE_BADNESS
;
4110 case TYPE_CODE_METHOD
:
4111 switch (TYPE_CODE (arg
))
4115 return INCOMPATIBLE_TYPE_BADNESS
;
4119 switch (TYPE_CODE (arg
))
4123 return INCOMPATIBLE_TYPE_BADNESS
;
4128 switch (TYPE_CODE (arg
))
4132 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0),
4133 TYPE_FIELD_TYPE (arg
, 0), NULL
);
4135 return INCOMPATIBLE_TYPE_BADNESS
;
4138 case TYPE_CODE_VOID
:
4140 return INCOMPATIBLE_TYPE_BADNESS
;
4141 } /* switch (TYPE_CODE (arg)) */
4144 /* End of functions for overload resolution. */
4146 /* Routines to pretty-print types. */
4149 print_bit_vector (B_TYPE
*bits
, int nbits
)
4153 for (bitno
= 0; bitno
< nbits
; bitno
++)
4155 if ((bitno
% 8) == 0)
4157 puts_filtered (" ");
4159 if (B_TST (bits
, bitno
))
4160 printf_filtered (("1"));
4162 printf_filtered (("0"));
4166 /* Note the first arg should be the "this" pointer, we may not want to
4167 include it since we may get into a infinitely recursive
4171 print_args (struct field
*args
, int nargs
, int spaces
)
4177 for (i
= 0; i
< nargs
; i
++)
4179 printfi_filtered (spaces
, "[%d] name '%s'\n", i
,
4180 args
[i
].name
!= NULL
? args
[i
].name
: "<NULL>");
4181 recursive_dump_type (args
[i
].type
, spaces
+ 2);
4187 field_is_static (struct field
*f
)
4189 /* "static" fields are the fields whose location is not relative
4190 to the address of the enclosing struct. It would be nice to
4191 have a dedicated flag that would be set for static fields when
4192 the type is being created. But in practice, checking the field
4193 loc_kind should give us an accurate answer. */
4194 return (FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSNAME
4195 || FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSADDR
);
4199 dump_fn_fieldlists (struct type
*type
, int spaces
)
4205 printfi_filtered (spaces
, "fn_fieldlists ");
4206 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
4207 printf_filtered ("\n");
4208 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
4210 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
4211 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
4213 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
4214 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
4216 printf_filtered (_(") length %d\n"),
4217 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
4218 for (overload_idx
= 0;
4219 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
4222 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
4224 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
4225 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
4227 printf_filtered (")\n");
4228 printfi_filtered (spaces
+ 8, "type ");
4229 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
4231 printf_filtered ("\n");
4233 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
4236 printfi_filtered (spaces
+ 8, "args ");
4237 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
4239 printf_filtered ("\n");
4240 print_args (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
4241 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
, overload_idx
)),
4243 printfi_filtered (spaces
+ 8, "fcontext ");
4244 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
4246 printf_filtered ("\n");
4248 printfi_filtered (spaces
+ 8, "is_const %d\n",
4249 TYPE_FN_FIELD_CONST (f
, overload_idx
));
4250 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
4251 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
4252 printfi_filtered (spaces
+ 8, "is_private %d\n",
4253 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
4254 printfi_filtered (spaces
+ 8, "is_protected %d\n",
4255 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
4256 printfi_filtered (spaces
+ 8, "is_stub %d\n",
4257 TYPE_FN_FIELD_STUB (f
, overload_idx
));
4258 printfi_filtered (spaces
+ 8, "voffset %u\n",
4259 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
4265 print_cplus_stuff (struct type
*type
, int spaces
)
4267 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
4268 printfi_filtered (spaces
, "vptr_basetype ");
4269 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
4270 puts_filtered ("\n");
4271 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
4272 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
4274 printfi_filtered (spaces
, "n_baseclasses %d\n",
4275 TYPE_N_BASECLASSES (type
));
4276 printfi_filtered (spaces
, "nfn_fields %d\n",
4277 TYPE_NFN_FIELDS (type
));
4278 if (TYPE_N_BASECLASSES (type
) > 0)
4280 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
4281 TYPE_N_BASECLASSES (type
));
4282 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
),
4284 printf_filtered (")");
4286 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
4287 TYPE_N_BASECLASSES (type
));
4288 puts_filtered ("\n");
4290 if (TYPE_NFIELDS (type
) > 0)
4292 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
4294 printfi_filtered (spaces
,
4295 "private_field_bits (%d bits at *",
4296 TYPE_NFIELDS (type
));
4297 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
),
4299 printf_filtered (")");
4300 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
4301 TYPE_NFIELDS (type
));
4302 puts_filtered ("\n");
4304 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
4306 printfi_filtered (spaces
,
4307 "protected_field_bits (%d bits at *",
4308 TYPE_NFIELDS (type
));
4309 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
),
4311 printf_filtered (")");
4312 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
4313 TYPE_NFIELDS (type
));
4314 puts_filtered ("\n");
4317 if (TYPE_NFN_FIELDS (type
) > 0)
4319 dump_fn_fieldlists (type
, spaces
);
4323 /* Print the contents of the TYPE's type_specific union, assuming that
4324 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
4327 print_gnat_stuff (struct type
*type
, int spaces
)
4329 struct type
*descriptive_type
= TYPE_DESCRIPTIVE_TYPE (type
);
4331 if (descriptive_type
== NULL
)
4332 printfi_filtered (spaces
+ 2, "no descriptive type\n");
4335 printfi_filtered (spaces
+ 2, "descriptive type\n");
4336 recursive_dump_type (descriptive_type
, spaces
+ 4);
4340 static struct obstack dont_print_type_obstack
;
4343 recursive_dump_type (struct type
*type
, int spaces
)
4348 obstack_begin (&dont_print_type_obstack
, 0);
4350 if (TYPE_NFIELDS (type
) > 0
4351 || (HAVE_CPLUS_STRUCT (type
) && TYPE_NFN_FIELDS (type
) > 0))
4353 struct type
**first_dont_print
4354 = (struct type
**) obstack_base (&dont_print_type_obstack
);
4356 int i
= (struct type
**)
4357 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
4361 if (type
== first_dont_print
[i
])
4363 printfi_filtered (spaces
, "type node ");
4364 gdb_print_host_address (type
, gdb_stdout
);
4365 printf_filtered (_(" <same as already seen type>\n"));
4370 obstack_ptr_grow (&dont_print_type_obstack
, type
);
4373 printfi_filtered (spaces
, "type node ");
4374 gdb_print_host_address (type
, gdb_stdout
);
4375 printf_filtered ("\n");
4376 printfi_filtered (spaces
, "name '%s' (",
4377 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
4378 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
4379 printf_filtered (")\n");
4380 printfi_filtered (spaces
, "tagname '%s' (",
4381 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
4382 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
4383 printf_filtered (")\n");
4384 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
4385 switch (TYPE_CODE (type
))
4387 case TYPE_CODE_UNDEF
:
4388 printf_filtered ("(TYPE_CODE_UNDEF)");
4391 printf_filtered ("(TYPE_CODE_PTR)");
4393 case TYPE_CODE_ARRAY
:
4394 printf_filtered ("(TYPE_CODE_ARRAY)");
4396 case TYPE_CODE_STRUCT
:
4397 printf_filtered ("(TYPE_CODE_STRUCT)");
4399 case TYPE_CODE_UNION
:
4400 printf_filtered ("(TYPE_CODE_UNION)");
4402 case TYPE_CODE_ENUM
:
4403 printf_filtered ("(TYPE_CODE_ENUM)");
4405 case TYPE_CODE_FLAGS
:
4406 printf_filtered ("(TYPE_CODE_FLAGS)");
4408 case TYPE_CODE_FUNC
:
4409 printf_filtered ("(TYPE_CODE_FUNC)");
4412 printf_filtered ("(TYPE_CODE_INT)");
4415 printf_filtered ("(TYPE_CODE_FLT)");
4417 case TYPE_CODE_VOID
:
4418 printf_filtered ("(TYPE_CODE_VOID)");
4421 printf_filtered ("(TYPE_CODE_SET)");
4423 case TYPE_CODE_RANGE
:
4424 printf_filtered ("(TYPE_CODE_RANGE)");
4426 case TYPE_CODE_STRING
:
4427 printf_filtered ("(TYPE_CODE_STRING)");
4429 case TYPE_CODE_ERROR
:
4430 printf_filtered ("(TYPE_CODE_ERROR)");
4432 case TYPE_CODE_MEMBERPTR
:
4433 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
4435 case TYPE_CODE_METHODPTR
:
4436 printf_filtered ("(TYPE_CODE_METHODPTR)");
4438 case TYPE_CODE_METHOD
:
4439 printf_filtered ("(TYPE_CODE_METHOD)");
4442 printf_filtered ("(TYPE_CODE_REF)");
4444 case TYPE_CODE_CHAR
:
4445 printf_filtered ("(TYPE_CODE_CHAR)");
4447 case TYPE_CODE_BOOL
:
4448 printf_filtered ("(TYPE_CODE_BOOL)");
4450 case TYPE_CODE_COMPLEX
:
4451 printf_filtered ("(TYPE_CODE_COMPLEX)");
4453 case TYPE_CODE_TYPEDEF
:
4454 printf_filtered ("(TYPE_CODE_TYPEDEF)");
4456 case TYPE_CODE_NAMESPACE
:
4457 printf_filtered ("(TYPE_CODE_NAMESPACE)");
4460 printf_filtered ("(UNKNOWN TYPE CODE)");
4463 puts_filtered ("\n");
4464 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
4465 if (TYPE_OBJFILE_OWNED (type
))
4467 printfi_filtered (spaces
, "objfile ");
4468 gdb_print_host_address (TYPE_OWNER (type
).objfile
, gdb_stdout
);
4472 printfi_filtered (spaces
, "gdbarch ");
4473 gdb_print_host_address (TYPE_OWNER (type
).gdbarch
, gdb_stdout
);
4475 printf_filtered ("\n");
4476 printfi_filtered (spaces
, "target_type ");
4477 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
4478 printf_filtered ("\n");
4479 if (TYPE_TARGET_TYPE (type
) != NULL
)
4481 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
4483 printfi_filtered (spaces
, "pointer_type ");
4484 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
4485 printf_filtered ("\n");
4486 printfi_filtered (spaces
, "reference_type ");
4487 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
4488 printf_filtered ("\n");
4489 printfi_filtered (spaces
, "type_chain ");
4490 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
4491 printf_filtered ("\n");
4492 printfi_filtered (spaces
, "instance_flags 0x%x",
4493 TYPE_INSTANCE_FLAGS (type
));
4494 if (TYPE_CONST (type
))
4496 puts_filtered (" TYPE_CONST");
4498 if (TYPE_VOLATILE (type
))
4500 puts_filtered (" TYPE_VOLATILE");
4502 if (TYPE_CODE_SPACE (type
))
4504 puts_filtered (" TYPE_CODE_SPACE");
4506 if (TYPE_DATA_SPACE (type
))
4508 puts_filtered (" TYPE_DATA_SPACE");
4510 if (TYPE_ADDRESS_CLASS_1 (type
))
4512 puts_filtered (" TYPE_ADDRESS_CLASS_1");
4514 if (TYPE_ADDRESS_CLASS_2 (type
))
4516 puts_filtered (" TYPE_ADDRESS_CLASS_2");
4518 if (TYPE_RESTRICT (type
))
4520 puts_filtered (" TYPE_RESTRICT");
4522 if (TYPE_ATOMIC (type
))
4524 puts_filtered (" TYPE_ATOMIC");
4526 puts_filtered ("\n");
4528 printfi_filtered (spaces
, "flags");
4529 if (TYPE_UNSIGNED (type
))
4531 puts_filtered (" TYPE_UNSIGNED");
4533 if (TYPE_NOSIGN (type
))
4535 puts_filtered (" TYPE_NOSIGN");
4537 if (TYPE_STUB (type
))
4539 puts_filtered (" TYPE_STUB");
4541 if (TYPE_TARGET_STUB (type
))
4543 puts_filtered (" TYPE_TARGET_STUB");
4545 if (TYPE_PROTOTYPED (type
))
4547 puts_filtered (" TYPE_PROTOTYPED");
4549 if (TYPE_INCOMPLETE (type
))
4551 puts_filtered (" TYPE_INCOMPLETE");
4553 if (TYPE_VARARGS (type
))
4555 puts_filtered (" TYPE_VARARGS");
4557 /* This is used for things like AltiVec registers on ppc. Gcc emits
4558 an attribute for the array type, which tells whether or not we
4559 have a vector, instead of a regular array. */
4560 if (TYPE_VECTOR (type
))
4562 puts_filtered (" TYPE_VECTOR");
4564 if (TYPE_FIXED_INSTANCE (type
))
4566 puts_filtered (" TYPE_FIXED_INSTANCE");
4568 if (TYPE_STUB_SUPPORTED (type
))
4570 puts_filtered (" TYPE_STUB_SUPPORTED");
4572 if (TYPE_NOTTEXT (type
))
4574 puts_filtered (" TYPE_NOTTEXT");
4576 puts_filtered ("\n");
4577 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
4578 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
4579 puts_filtered ("\n");
4580 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
4582 if (TYPE_CODE (type
) == TYPE_CODE_ENUM
)
4583 printfi_filtered (spaces
+ 2,
4584 "[%d] enumval %s type ",
4585 idx
, plongest (TYPE_FIELD_ENUMVAL (type
, idx
)));
4587 printfi_filtered (spaces
+ 2,
4588 "[%d] bitpos %s bitsize %d type ",
4589 idx
, plongest (TYPE_FIELD_BITPOS (type
, idx
)),
4590 TYPE_FIELD_BITSIZE (type
, idx
));
4591 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
4592 printf_filtered (" name '%s' (",
4593 TYPE_FIELD_NAME (type
, idx
) != NULL
4594 ? TYPE_FIELD_NAME (type
, idx
)
4596 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
4597 printf_filtered (")\n");
4598 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
4600 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
4603 if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
4605 printfi_filtered (spaces
, "low %s%s high %s%s\n",
4606 plongest (TYPE_LOW_BOUND (type
)),
4607 TYPE_LOW_BOUND_UNDEFINED (type
) ? " (undefined)" : "",
4608 plongest (TYPE_HIGH_BOUND (type
)),
4609 TYPE_HIGH_BOUND_UNDEFINED (type
)
4610 ? " (undefined)" : "");
4613 switch (TYPE_SPECIFIC_FIELD (type
))
4615 case TYPE_SPECIFIC_CPLUS_STUFF
:
4616 printfi_filtered (spaces
, "cplus_stuff ");
4617 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
),
4619 puts_filtered ("\n");
4620 print_cplus_stuff (type
, spaces
);
4623 case TYPE_SPECIFIC_GNAT_STUFF
:
4624 printfi_filtered (spaces
, "gnat_stuff ");
4625 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type
), gdb_stdout
);
4626 puts_filtered ("\n");
4627 print_gnat_stuff (type
, spaces
);
4630 case TYPE_SPECIFIC_FLOATFORMAT
:
4631 printfi_filtered (spaces
, "floatformat ");
4632 if (TYPE_FLOATFORMAT (type
) == NULL
4633 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
4634 puts_filtered ("(null)");
4636 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
4637 puts_filtered ("\n");
4640 case TYPE_SPECIFIC_FUNC
:
4641 printfi_filtered (spaces
, "calling_convention %d\n",
4642 TYPE_CALLING_CONVENTION (type
));
4643 /* tail_call_list is not printed. */
4646 case TYPE_SPECIFIC_SELF_TYPE
:
4647 printfi_filtered (spaces
, "self_type ");
4648 gdb_print_host_address (TYPE_SELF_TYPE (type
), gdb_stdout
);
4649 puts_filtered ("\n");
4654 obstack_free (&dont_print_type_obstack
, NULL
);
4657 /* Trivial helpers for the libiberty hash table, for mapping one
4662 struct type
*old
, *newobj
;
4666 type_pair_hash (const void *item
)
4668 const struct type_pair
*pair
= (const struct type_pair
*) item
;
4670 return htab_hash_pointer (pair
->old
);
4674 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
4676 const struct type_pair
*lhs
= (const struct type_pair
*) item_lhs
;
4677 const struct type_pair
*rhs
= (const struct type_pair
*) item_rhs
;
4679 return lhs
->old
== rhs
->old
;
4682 /* Allocate the hash table used by copy_type_recursive to walk
4683 types without duplicates. We use OBJFILE's obstack, because
4684 OBJFILE is about to be deleted. */
4687 create_copied_types_hash (struct objfile
*objfile
)
4689 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
4690 NULL
, &objfile
->objfile_obstack
,
4691 hashtab_obstack_allocate
,
4692 dummy_obstack_deallocate
);
4695 /* Recursively copy (deep copy) a dynamic attribute list of a type. */
4697 static struct dynamic_prop_list
*
4698 copy_dynamic_prop_list (struct obstack
*objfile_obstack
,
4699 struct dynamic_prop_list
*list
)
4701 struct dynamic_prop_list
*copy
= list
;
4702 struct dynamic_prop_list
**node_ptr
= ©
;
4704 while (*node_ptr
!= NULL
)
4706 struct dynamic_prop_list
*node_copy
;
4708 node_copy
= ((struct dynamic_prop_list
*)
4709 obstack_copy (objfile_obstack
, *node_ptr
,
4710 sizeof (struct dynamic_prop_list
)));
4711 node_copy
->prop
= (*node_ptr
)->prop
;
4712 *node_ptr
= node_copy
;
4714 node_ptr
= &node_copy
->next
;
4720 /* Recursively copy (deep copy) TYPE, if it is associated with
4721 OBJFILE. Return a new type owned by the gdbarch associated with the type, a
4722 saved type if we have already visited TYPE (using COPIED_TYPES), or TYPE if
4723 it is not associated with OBJFILE. */
4726 copy_type_recursive (struct objfile
*objfile
,
4728 htab_t copied_types
)
4730 struct type_pair
*stored
, pair
;
4732 struct type
*new_type
;
4734 if (! TYPE_OBJFILE_OWNED (type
))
4737 /* This type shouldn't be pointing to any types in other objfiles;
4738 if it did, the type might disappear unexpectedly. */
4739 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
4742 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
4744 return ((struct type_pair
*) *slot
)->newobj
;
4746 new_type
= alloc_type_arch (get_type_arch (type
));
4748 /* We must add the new type to the hash table immediately, in case
4749 we encounter this type again during a recursive call below. */
4750 stored
= XOBNEW (&objfile
->objfile_obstack
, struct type_pair
);
4752 stored
->newobj
= new_type
;
4755 /* Copy the common fields of types. For the main type, we simply
4756 copy the entire thing and then update specific fields as needed. */
4757 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
4758 TYPE_OBJFILE_OWNED (new_type
) = 0;
4759 TYPE_OWNER (new_type
).gdbarch
= get_type_arch (type
);
4761 if (TYPE_NAME (type
))
4762 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
4763 if (TYPE_TAG_NAME (type
))
4764 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
4766 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
4767 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
4769 /* Copy the fields. */
4770 if (TYPE_NFIELDS (type
))
4774 nfields
= TYPE_NFIELDS (type
);
4775 TYPE_FIELDS (new_type
) = XCNEWVEC (struct field
, nfields
);
4776 for (i
= 0; i
< nfields
; i
++)
4778 TYPE_FIELD_ARTIFICIAL (new_type
, i
) =
4779 TYPE_FIELD_ARTIFICIAL (type
, i
);
4780 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
4781 if (TYPE_FIELD_TYPE (type
, i
))
4782 TYPE_FIELD_TYPE (new_type
, i
)
4783 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
4785 if (TYPE_FIELD_NAME (type
, i
))
4786 TYPE_FIELD_NAME (new_type
, i
) =
4787 xstrdup (TYPE_FIELD_NAME (type
, i
));
4788 switch (TYPE_FIELD_LOC_KIND (type
, i
))
4790 case FIELD_LOC_KIND_BITPOS
:
4791 SET_FIELD_BITPOS (TYPE_FIELD (new_type
, i
),
4792 TYPE_FIELD_BITPOS (type
, i
));
4794 case FIELD_LOC_KIND_ENUMVAL
:
4795 SET_FIELD_ENUMVAL (TYPE_FIELD (new_type
, i
),
4796 TYPE_FIELD_ENUMVAL (type
, i
));
4798 case FIELD_LOC_KIND_PHYSADDR
:
4799 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
4800 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
4802 case FIELD_LOC_KIND_PHYSNAME
:
4803 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
4804 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
,
4808 internal_error (__FILE__
, __LINE__
,
4809 _("Unexpected type field location kind: %d"),
4810 TYPE_FIELD_LOC_KIND (type
, i
));
4815 /* For range types, copy the bounds information. */
4816 if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
4818 TYPE_RANGE_DATA (new_type
) = XNEW (struct range_bounds
);
4819 *TYPE_RANGE_DATA (new_type
) = *TYPE_RANGE_DATA (type
);
4822 if (TYPE_DYN_PROP_LIST (type
) != NULL
)
4823 TYPE_DYN_PROP_LIST (new_type
)
4824 = copy_dynamic_prop_list (&objfile
->objfile_obstack
,
4825 TYPE_DYN_PROP_LIST (type
));
4828 /* Copy pointers to other types. */
4829 if (TYPE_TARGET_TYPE (type
))
4830 TYPE_TARGET_TYPE (new_type
) =
4831 copy_type_recursive (objfile
,
4832 TYPE_TARGET_TYPE (type
),
4835 /* Maybe copy the type_specific bits.
4837 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
4838 base classes and methods. There's no fundamental reason why we
4839 can't, but at the moment it is not needed. */
4841 switch (TYPE_SPECIFIC_FIELD (type
))
4843 case TYPE_SPECIFIC_NONE
:
4845 case TYPE_SPECIFIC_FUNC
:
4846 INIT_FUNC_SPECIFIC (new_type
);
4847 TYPE_CALLING_CONVENTION (new_type
) = TYPE_CALLING_CONVENTION (type
);
4848 TYPE_NO_RETURN (new_type
) = TYPE_NO_RETURN (type
);
4849 TYPE_TAIL_CALL_LIST (new_type
) = NULL
;
4851 case TYPE_SPECIFIC_FLOATFORMAT
:
4852 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
4854 case TYPE_SPECIFIC_CPLUS_STUFF
:
4855 INIT_CPLUS_SPECIFIC (new_type
);
4857 case TYPE_SPECIFIC_GNAT_STUFF
:
4858 INIT_GNAT_SPECIFIC (new_type
);
4860 case TYPE_SPECIFIC_SELF_TYPE
:
4861 set_type_self_type (new_type
,
4862 copy_type_recursive (objfile
, TYPE_SELF_TYPE (type
),
4866 gdb_assert_not_reached ("bad type_specific_kind");
4872 /* Make a copy of the given TYPE, except that the pointer & reference
4873 types are not preserved.
4875 This function assumes that the given type has an associated objfile.
4876 This objfile is used to allocate the new type. */
4879 copy_type (const struct type
*type
)
4881 struct type
*new_type
;
4883 gdb_assert (TYPE_OBJFILE_OWNED (type
));
4885 new_type
= alloc_type_copy (type
);
4886 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
4887 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
4888 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
4889 sizeof (struct main_type
));
4890 if (TYPE_DYN_PROP_LIST (type
) != NULL
)
4891 TYPE_DYN_PROP_LIST (new_type
)
4892 = copy_dynamic_prop_list (&TYPE_OBJFILE (type
) -> objfile_obstack
,
4893 TYPE_DYN_PROP_LIST (type
));
4898 /* Helper functions to initialize architecture-specific types. */
4900 /* Allocate a type structure associated with GDBARCH and set its
4901 CODE, LENGTH, and NAME fields. */
4904 arch_type (struct gdbarch
*gdbarch
,
4905 enum type_code code
, int bit
, const char *name
)
4909 type
= alloc_type_arch (gdbarch
);
4910 set_type_code (type
, code
);
4911 gdb_assert ((bit
% TARGET_CHAR_BIT
) == 0);
4912 TYPE_LENGTH (type
) = bit
/ TARGET_CHAR_BIT
;
4915 TYPE_NAME (type
) = gdbarch_obstack_strdup (gdbarch
, name
);
4920 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
4921 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4922 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4925 arch_integer_type (struct gdbarch
*gdbarch
,
4926 int bit
, int unsigned_p
, const char *name
)
4930 t
= arch_type (gdbarch
, TYPE_CODE_INT
, bit
, name
);
4932 TYPE_UNSIGNED (t
) = 1;
4937 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
4938 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4939 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4942 arch_character_type (struct gdbarch
*gdbarch
,
4943 int bit
, int unsigned_p
, const char *name
)
4947 t
= arch_type (gdbarch
, TYPE_CODE_CHAR
, bit
, name
);
4949 TYPE_UNSIGNED (t
) = 1;
4954 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
4955 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
4956 the type's TYPE_UNSIGNED flag. NAME is the type name. */
4959 arch_boolean_type (struct gdbarch
*gdbarch
,
4960 int bit
, int unsigned_p
, const char *name
)
4964 t
= arch_type (gdbarch
, TYPE_CODE_BOOL
, bit
, name
);
4966 TYPE_UNSIGNED (t
) = 1;
4971 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
4972 BIT is the type size in bits; if BIT equals -1, the size is
4973 determined by the floatformat. NAME is the type name. Set the
4974 TYPE_FLOATFORMAT from FLOATFORMATS. */
4977 arch_float_type (struct gdbarch
*gdbarch
,
4978 int bit
, const char *name
,
4979 const struct floatformat
**floatformats
)
4981 const struct floatformat
*fmt
= floatformats
[gdbarch_byte_order (gdbarch
)];
4984 bit
= verify_floatformat (bit
, fmt
);
4985 t
= arch_type (gdbarch
, TYPE_CODE_FLT
, bit
, name
);
4986 TYPE_FLOATFORMAT (t
) = fmt
;
4991 /* Allocate a TYPE_CODE_DECFLOAT type structure associated with GDBARCH.
4992 BIT is the type size in bits. NAME is the type name. */
4995 arch_decfloat_type (struct gdbarch
*gdbarch
, int bit
, const char *name
)
4999 t
= arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, bit
, name
);
5003 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
5004 NAME is the type name. TARGET_TYPE is the component float type. */
5007 arch_complex_type (struct gdbarch
*gdbarch
,
5008 const char *name
, struct type
*target_type
)
5012 t
= arch_type (gdbarch
, TYPE_CODE_COMPLEX
,
5013 2 * TYPE_LENGTH (target_type
) * TARGET_CHAR_BIT
, name
);
5014 TYPE_TARGET_TYPE (t
) = target_type
;
5018 /* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH.
5019 BIT is the pointer type size in bits. NAME is the type name.
5020 TARGET_TYPE is the pointer target type. Always sets the pointer type's
5021 TYPE_UNSIGNED flag. */
5024 arch_pointer_type (struct gdbarch
*gdbarch
,
5025 int bit
, const char *name
, struct type
*target_type
)
5029 t
= arch_type (gdbarch
, TYPE_CODE_PTR
, bit
, name
);
5030 TYPE_TARGET_TYPE (t
) = target_type
;
5031 TYPE_UNSIGNED (t
) = 1;
5035 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
5036 NAME is the type name. BIT is the size of the flag word in bits. */
5039 arch_flags_type (struct gdbarch
*gdbarch
, const char *name
, int bit
)
5043 type
= arch_type (gdbarch
, TYPE_CODE_FLAGS
, bit
, name
);
5044 TYPE_UNSIGNED (type
) = 1;
5045 TYPE_NFIELDS (type
) = 0;
5046 /* Pre-allocate enough space assuming every field is one bit. */
5048 = (struct field
*) TYPE_ZALLOC (type
, bit
* sizeof (struct field
));
5053 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5054 position BITPOS is called NAME. Pass NAME as "" for fields that
5055 should not be printed. */
5058 append_flags_type_field (struct type
*type
, int start_bitpos
, int nr_bits
,
5059 struct type
*field_type
, const char *name
)
5061 int type_bitsize
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
;
5062 int field_nr
= TYPE_NFIELDS (type
);
5064 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
5065 gdb_assert (TYPE_NFIELDS (type
) + 1 <= type_bitsize
);
5066 gdb_assert (start_bitpos
>= 0 && start_bitpos
< type_bitsize
);
5067 gdb_assert (nr_bits
>= 1 && nr_bits
<= type_bitsize
);
5068 gdb_assert (name
!= NULL
);
5070 TYPE_FIELD_NAME (type
, field_nr
) = xstrdup (name
);
5071 TYPE_FIELD_TYPE (type
, field_nr
) = field_type
;
5072 SET_FIELD_BITPOS (TYPE_FIELD (type
, field_nr
), start_bitpos
);
5073 TYPE_FIELD_BITSIZE (type
, field_nr
) = nr_bits
;
5074 ++TYPE_NFIELDS (type
);
5077 /* Special version of append_flags_type_field to add a flag field.
5078 Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
5079 position BITPOS is called NAME. */
5082 append_flags_type_flag (struct type
*type
, int bitpos
, const char *name
)
5084 struct gdbarch
*gdbarch
= get_type_arch (type
);
5086 append_flags_type_field (type
, bitpos
, 1,
5087 builtin_type (gdbarch
)->builtin_bool
,
5091 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
5092 specified by CODE) associated with GDBARCH. NAME is the type name. */
5095 arch_composite_type (struct gdbarch
*gdbarch
, const char *name
,
5096 enum type_code code
)
5100 gdb_assert (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
);
5101 t
= arch_type (gdbarch
, code
, 0, NULL
);
5102 TYPE_TAG_NAME (t
) = name
;
5103 INIT_CPLUS_SPECIFIC (t
);
5107 /* Add new field with name NAME and type FIELD to composite type T.
5108 Do not set the field's position or adjust the type's length;
5109 the caller should do so. Return the new field. */
5112 append_composite_type_field_raw (struct type
*t
, const char *name
,
5117 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
5118 TYPE_FIELDS (t
) = XRESIZEVEC (struct field
, TYPE_FIELDS (t
),
5120 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
5121 memset (f
, 0, sizeof f
[0]);
5122 FIELD_TYPE (f
[0]) = field
;
5123 FIELD_NAME (f
[0]) = name
;
5127 /* Add new field with name NAME and type FIELD to composite type T.
5128 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
5131 append_composite_type_field_aligned (struct type
*t
, const char *name
,
5132 struct type
*field
, int alignment
)
5134 struct field
*f
= append_composite_type_field_raw (t
, name
, field
);
5136 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
5138 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
5139 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
5141 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
5143 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
5144 if (TYPE_NFIELDS (t
) > 1)
5146 SET_FIELD_BITPOS (f
[0],
5147 (FIELD_BITPOS (f
[-1])
5148 + (TYPE_LENGTH (FIELD_TYPE (f
[-1]))
5149 * TARGET_CHAR_BIT
)));
5155 alignment
*= TARGET_CHAR_BIT
;
5156 left
= FIELD_BITPOS (f
[0]) % alignment
;
5160 SET_FIELD_BITPOS (f
[0], FIELD_BITPOS (f
[0]) + (alignment
- left
));
5161 TYPE_LENGTH (t
) += (alignment
- left
) / TARGET_CHAR_BIT
;
5168 /* Add new field with name NAME and type FIELD to composite type T. */
5171 append_composite_type_field (struct type
*t
, const char *name
,
5174 append_composite_type_field_aligned (t
, name
, field
, 0);
5177 static struct gdbarch_data
*gdbtypes_data
;
5179 const struct builtin_type
*
5180 builtin_type (struct gdbarch
*gdbarch
)
5182 return (const struct builtin_type
*) gdbarch_data (gdbarch
, gdbtypes_data
);
5186 gdbtypes_post_init (struct gdbarch
*gdbarch
)
5188 struct builtin_type
*builtin_type
5189 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
5192 builtin_type
->builtin_void
5193 = arch_type (gdbarch
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
5194 builtin_type
->builtin_char
5195 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
5196 !gdbarch_char_signed (gdbarch
), "char");
5197 TYPE_NOSIGN (builtin_type
->builtin_char
) = 1;
5198 builtin_type
->builtin_signed_char
5199 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
5201 builtin_type
->builtin_unsigned_char
5202 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
5203 1, "unsigned char");
5204 builtin_type
->builtin_short
5205 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
5207 builtin_type
->builtin_unsigned_short
5208 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
5209 1, "unsigned short");
5210 builtin_type
->builtin_int
5211 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
5213 builtin_type
->builtin_unsigned_int
5214 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
5216 builtin_type
->builtin_long
5217 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
5219 builtin_type
->builtin_unsigned_long
5220 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
5221 1, "unsigned long");
5222 builtin_type
->builtin_long_long
5223 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
5225 builtin_type
->builtin_unsigned_long_long
5226 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
5227 1, "unsigned long long");
5228 builtin_type
->builtin_float
5229 = arch_float_type (gdbarch
, gdbarch_float_bit (gdbarch
),
5230 "float", gdbarch_float_format (gdbarch
));
5231 builtin_type
->builtin_double
5232 = arch_float_type (gdbarch
, gdbarch_double_bit (gdbarch
),
5233 "double", gdbarch_double_format (gdbarch
));
5234 builtin_type
->builtin_long_double
5235 = arch_float_type (gdbarch
, gdbarch_long_double_bit (gdbarch
),
5236 "long double", gdbarch_long_double_format (gdbarch
));
5237 builtin_type
->builtin_complex
5238 = arch_complex_type (gdbarch
, "complex",
5239 builtin_type
->builtin_float
);
5240 builtin_type
->builtin_double_complex
5241 = arch_complex_type (gdbarch
, "double complex",
5242 builtin_type
->builtin_double
);
5243 builtin_type
->builtin_string
5244 = arch_type (gdbarch
, TYPE_CODE_STRING
, TARGET_CHAR_BIT
, "string");
5245 builtin_type
->builtin_bool
5246 = arch_type (gdbarch
, TYPE_CODE_BOOL
, TARGET_CHAR_BIT
, "bool");
5248 /* The following three are about decimal floating point types, which
5249 are 32-bits, 64-bits and 128-bits respectively. */
5250 builtin_type
->builtin_decfloat
5251 = arch_decfloat_type (gdbarch
, 32, "_Decimal32");
5252 builtin_type
->builtin_decdouble
5253 = arch_decfloat_type (gdbarch
, 64, "_Decimal64");
5254 builtin_type
->builtin_declong
5255 = arch_decfloat_type (gdbarch
, 128, "_Decimal128");
5257 /* "True" character types. */
5258 builtin_type
->builtin_true_char
5259 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 0, "true character");
5260 builtin_type
->builtin_true_unsigned_char
5261 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 1, "true character");
5263 /* Fixed-size integer types. */
5264 builtin_type
->builtin_int0
5265 = arch_integer_type (gdbarch
, 0, 0, "int0_t");
5266 builtin_type
->builtin_int8
5267 = arch_integer_type (gdbarch
, 8, 0, "int8_t");
5268 builtin_type
->builtin_uint8
5269 = arch_integer_type (gdbarch
, 8, 1, "uint8_t");
5270 builtin_type
->builtin_int16
5271 = arch_integer_type (gdbarch
, 16, 0, "int16_t");
5272 builtin_type
->builtin_uint16
5273 = arch_integer_type (gdbarch
, 16, 1, "uint16_t");
5274 builtin_type
->builtin_int32
5275 = arch_integer_type (gdbarch
, 32, 0, "int32_t");
5276 builtin_type
->builtin_uint32
5277 = arch_integer_type (gdbarch
, 32, 1, "uint32_t");
5278 builtin_type
->builtin_int64
5279 = arch_integer_type (gdbarch
, 64, 0, "int64_t");
5280 builtin_type
->builtin_uint64
5281 = arch_integer_type (gdbarch
, 64, 1, "uint64_t");
5282 builtin_type
->builtin_int128
5283 = arch_integer_type (gdbarch
, 128, 0, "int128_t");
5284 builtin_type
->builtin_uint128
5285 = arch_integer_type (gdbarch
, 128, 1, "uint128_t");
5286 TYPE_INSTANCE_FLAGS (builtin_type
->builtin_int8
) |=
5287 TYPE_INSTANCE_FLAG_NOTTEXT
;
5288 TYPE_INSTANCE_FLAGS (builtin_type
->builtin_uint8
) |=
5289 TYPE_INSTANCE_FLAG_NOTTEXT
;
5291 /* Wide character types. */
5292 builtin_type
->builtin_char16
5293 = arch_integer_type (gdbarch
, 16, 1, "char16_t");
5294 builtin_type
->builtin_char32
5295 = arch_integer_type (gdbarch
, 32, 1, "char32_t");
5296 builtin_type
->builtin_wchar
5297 = arch_integer_type (gdbarch
, gdbarch_wchar_bit (gdbarch
),
5298 !gdbarch_wchar_signed (gdbarch
), "wchar_t");
5300 /* Default data/code pointer types. */
5301 builtin_type
->builtin_data_ptr
5302 = lookup_pointer_type (builtin_type
->builtin_void
);
5303 builtin_type
->builtin_func_ptr
5304 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
5305 builtin_type
->builtin_func_func
5306 = lookup_function_type (builtin_type
->builtin_func_ptr
);
5308 /* This type represents a GDB internal function. */
5309 builtin_type
->internal_fn
5310 = arch_type (gdbarch
, TYPE_CODE_INTERNAL_FUNCTION
, 0,
5311 "<internal function>");
5313 /* This type represents an xmethod. */
5314 builtin_type
->xmethod
5315 = arch_type (gdbarch
, TYPE_CODE_XMETHOD
, 0, "<xmethod>");
5317 return builtin_type
;
5320 /* This set of objfile-based types is intended to be used by symbol
5321 readers as basic types. */
5323 static const struct objfile_data
*objfile_type_data
;
5325 const struct objfile_type
*
5326 objfile_type (struct objfile
*objfile
)
5328 struct gdbarch
*gdbarch
;
5329 struct objfile_type
*objfile_type
5330 = (struct objfile_type
*) objfile_data (objfile
, objfile_type_data
);
5333 return objfile_type
;
5335 objfile_type
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
5336 1, struct objfile_type
);
5338 /* Use the objfile architecture to determine basic type properties. */
5339 gdbarch
= get_objfile_arch (objfile
);
5342 objfile_type
->builtin_void
5343 = init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, "void");
5344 objfile_type
->builtin_char
5345 = init_integer_type (objfile
, TARGET_CHAR_BIT
,
5346 !gdbarch_char_signed (gdbarch
), "char");
5347 TYPE_NOSIGN (objfile_type
->builtin_char
) = 1;
5348 objfile_type
->builtin_signed_char
5349 = init_integer_type (objfile
, TARGET_CHAR_BIT
,
5351 objfile_type
->builtin_unsigned_char
5352 = init_integer_type (objfile
, TARGET_CHAR_BIT
,
5353 1, "unsigned char");
5354 objfile_type
->builtin_short
5355 = init_integer_type (objfile
, gdbarch_short_bit (gdbarch
),
5357 objfile_type
->builtin_unsigned_short
5358 = init_integer_type (objfile
, gdbarch_short_bit (gdbarch
),
5359 1, "unsigned short");
5360 objfile_type
->builtin_int
5361 = init_integer_type (objfile
, gdbarch_int_bit (gdbarch
),
5363 objfile_type
->builtin_unsigned_int
5364 = init_integer_type (objfile
, gdbarch_int_bit (gdbarch
),
5366 objfile_type
->builtin_long
5367 = init_integer_type (objfile
, gdbarch_long_bit (gdbarch
),
5369 objfile_type
->builtin_unsigned_long
5370 = init_integer_type (objfile
, gdbarch_long_bit (gdbarch
),
5371 1, "unsigned long");
5372 objfile_type
->builtin_long_long
5373 = init_integer_type (objfile
, gdbarch_long_long_bit (gdbarch
),
5375 objfile_type
->builtin_unsigned_long_long
5376 = init_integer_type (objfile
, gdbarch_long_long_bit (gdbarch
),
5377 1, "unsigned long long");
5378 objfile_type
->builtin_float
5379 = init_float_type (objfile
, gdbarch_float_bit (gdbarch
),
5380 "float", gdbarch_float_format (gdbarch
));
5381 objfile_type
->builtin_double
5382 = init_float_type (objfile
, gdbarch_double_bit (gdbarch
),
5383 "double", gdbarch_double_format (gdbarch
));
5384 objfile_type
->builtin_long_double
5385 = init_float_type (objfile
, gdbarch_long_double_bit (gdbarch
),
5386 "long double", gdbarch_long_double_format (gdbarch
));
5388 /* This type represents a type that was unrecognized in symbol read-in. */
5389 objfile_type
->builtin_error
5390 = init_type (objfile
, TYPE_CODE_ERROR
, 0, "<unknown type>");
5392 /* The following set of types is used for symbols with no
5393 debug information. */
5394 objfile_type
->nodebug_text_symbol
5395 = init_type (objfile
, TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
5396 "<text variable, no debug info>");
5397 objfile_type
->nodebug_text_gnu_ifunc_symbol
5398 = init_type (objfile
, TYPE_CODE_FUNC
, TARGET_CHAR_BIT
,
5399 "<text gnu-indirect-function variable, no debug info>");
5400 /* Ifunc resolvers return a function address. */
5401 TYPE_TARGET_TYPE (objfile_type
->nodebug_text_gnu_ifunc_symbol
)
5402 = init_integer_type (objfile
, gdbarch_addr_bit (gdbarch
), 1,
5403 "__IFUNC_RESOLVER_RET");
5404 TYPE_GNU_IFUNC (objfile_type
->nodebug_text_gnu_ifunc_symbol
) = 1;
5405 objfile_type
->nodebug_got_plt_symbol
5406 = init_pointer_type (objfile
, gdbarch_addr_bit (gdbarch
),
5407 "<text from jump slot in .got.plt, no debug info>",
5408 objfile_type
->nodebug_text_symbol
);
5409 objfile_type
->nodebug_data_symbol
5410 = init_nodebug_var_type (objfile
, "<data variable, no debug info>");
5411 objfile_type
->nodebug_unknown_symbol
5412 = init_nodebug_var_type (objfile
, "<variable (not text or data), no debug info>");
5413 objfile_type
->nodebug_tls_symbol
5414 = init_nodebug_var_type (objfile
, "<thread local variable, no debug info>");
5416 /* NOTE: on some targets, addresses and pointers are not necessarily
5420 - gdb's `struct type' always describes the target's
5422 - gdb's `struct value' objects should always hold values in
5424 - gdb's CORE_ADDR values are addresses in the unified virtual
5425 address space that the assembler and linker work with. Thus,
5426 since target_read_memory takes a CORE_ADDR as an argument, it
5427 can access any memory on the target, even if the processor has
5428 separate code and data address spaces.
5430 In this context, objfile_type->builtin_core_addr is a bit odd:
5431 it's a target type for a value the target will never see. It's
5432 only used to hold the values of (typeless) linker symbols, which
5433 are indeed in the unified virtual address space. */
5435 objfile_type
->builtin_core_addr
5436 = init_integer_type (objfile
, gdbarch_addr_bit (gdbarch
), 1,
5439 set_objfile_data (objfile
, objfile_type_data
, objfile_type
);
5440 return objfile_type
;
5444 _initialize_gdbtypes (void)
5446 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
5447 objfile_type_data
= register_objfile_data ();
5449 add_setshow_zuinteger_cmd ("overload", no_class
, &overload_debug
,
5450 _("Set debugging of C++ overloading."),
5451 _("Show debugging of C++ overloading."),
5452 _("When enabled, ranking of the "
5453 "functions is displayed."),
5455 show_overload_debug
,
5456 &setdebuglist
, &showdebuglist
);
5458 /* Add user knob for controlling resolution of opaque types. */
5459 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
5460 &opaque_type_resolution
,
5461 _("Set resolution of opaque struct/class/union"
5462 " types (if set before loading symbols)."),
5463 _("Show resolution of opaque struct/class/union"
5464 " types (if set before loading symbols)."),
5466 show_opaque_type_resolution
,
5467 &setlist
, &showlist
);
5469 /* Add an option to permit non-strict type checking. */
5470 add_setshow_boolean_cmd ("type", class_support
,
5471 &strict_type_checking
,
5472 _("Set strict type checking."),
5473 _("Show strict type checking."),
5475 show_strict_type_checking
,
5476 &setchecklist
, &showchecklist
);