1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992-2013 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/>. */
23 #include "gdb_string.h"
29 #include "expression.h"
34 #include "complaints.h"
37 #include "gdb_assert.h"
39 #include "exceptions.h"
40 #include "cp-support.h"
42 /* Initialize BADNESS constants. */
44 const struct rank LENGTH_MISMATCH_BADNESS
= {100,0};
46 const struct rank TOO_FEW_PARAMS_BADNESS
= {100,0};
47 const struct rank INCOMPATIBLE_TYPE_BADNESS
= {100,0};
49 const struct rank EXACT_MATCH_BADNESS
= {0,0};
51 const struct rank INTEGER_PROMOTION_BADNESS
= {1,0};
52 const struct rank FLOAT_PROMOTION_BADNESS
= {1,0};
53 const struct rank BASE_PTR_CONVERSION_BADNESS
= {1,0};
54 const struct rank INTEGER_CONVERSION_BADNESS
= {2,0};
55 const struct rank FLOAT_CONVERSION_BADNESS
= {2,0};
56 const struct rank INT_FLOAT_CONVERSION_BADNESS
= {2,0};
57 const struct rank VOID_PTR_CONVERSION_BADNESS
= {2,0};
58 const struct rank BOOL_CONVERSION_BADNESS
= {3,0};
59 const struct rank BASE_CONVERSION_BADNESS
= {2,0};
60 const struct rank REFERENCE_CONVERSION_BADNESS
= {2,0};
61 const struct rank NULL_POINTER_CONVERSION_BADNESS
= {2,0};
62 const struct rank NS_POINTER_CONVERSION_BADNESS
= {10,0};
63 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS
= {3,0};
65 /* Floatformat pairs. */
66 const struct floatformat
*floatformats_ieee_half
[BFD_ENDIAN_UNKNOWN
] = {
67 &floatformat_ieee_half_big
,
68 &floatformat_ieee_half_little
70 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
71 &floatformat_ieee_single_big
,
72 &floatformat_ieee_single_little
74 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
75 &floatformat_ieee_double_big
,
76 &floatformat_ieee_double_little
78 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
79 &floatformat_ieee_double_big
,
80 &floatformat_ieee_double_littlebyte_bigword
82 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
83 &floatformat_i387_ext
,
86 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
87 &floatformat_m68881_ext
,
88 &floatformat_m68881_ext
90 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
91 &floatformat_arm_ext_big
,
92 &floatformat_arm_ext_littlebyte_bigword
94 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
95 &floatformat_ia64_spill_big
,
96 &floatformat_ia64_spill_little
98 const struct floatformat
*floatformats_ia64_quad
[BFD_ENDIAN_UNKNOWN
] = {
99 &floatformat_ia64_quad_big
,
100 &floatformat_ia64_quad_little
102 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
106 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
110 const struct floatformat
*floatformats_ibm_long_double
[BFD_ENDIAN_UNKNOWN
] = {
111 &floatformat_ibm_long_double_big
,
112 &floatformat_ibm_long_double_little
115 /* Should opaque types be resolved? */
117 static int opaque_type_resolution
= 1;
119 /* A flag to enable printing of debugging information of C++
122 unsigned int overload_debug
= 0;
124 /* A flag to enable strict type checking. */
126 static int strict_type_checking
= 1;
128 /* A function to show whether opaque types are resolved. */
131 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
132 struct cmd_list_element
*c
,
135 fprintf_filtered (file
, _("Resolution of opaque struct/class/union types "
136 "(if set before loading symbols) is %s.\n"),
140 /* A function to show whether C++ overload debugging is enabled. */
143 show_overload_debug (struct ui_file
*file
, int from_tty
,
144 struct cmd_list_element
*c
, const char *value
)
146 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"),
150 /* A function to show the status of strict type checking. */
153 show_strict_type_checking (struct ui_file
*file
, int from_tty
,
154 struct cmd_list_element
*c
, const char *value
)
156 fprintf_filtered (file
, _("Strict type checking is %s.\n"), value
);
160 /* Allocate a new OBJFILE-associated type structure and fill it
161 with some defaults. Space for the type structure is allocated
162 on the objfile's objfile_obstack. */
165 alloc_type (struct objfile
*objfile
)
169 gdb_assert (objfile
!= NULL
);
171 /* Alloc the structure and start off with all fields zeroed. */
172 type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct type
);
173 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
175 OBJSTAT (objfile
, n_types
++);
177 TYPE_OBJFILE_OWNED (type
) = 1;
178 TYPE_OWNER (type
).objfile
= objfile
;
180 /* Initialize the fields that might not be zero. */
182 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
183 TYPE_VPTR_FIELDNO (type
) = -1;
184 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
189 /* Allocate a new GDBARCH-associated type structure and fill it
190 with some defaults. Space for the type structure is allocated
194 alloc_type_arch (struct gdbarch
*gdbarch
)
198 gdb_assert (gdbarch
!= NULL
);
200 /* Alloc the structure and start off with all fields zeroed. */
202 type
= XZALLOC (struct type
);
203 TYPE_MAIN_TYPE (type
) = XZALLOC (struct main_type
);
205 TYPE_OBJFILE_OWNED (type
) = 0;
206 TYPE_OWNER (type
).gdbarch
= gdbarch
;
208 /* Initialize the fields that might not be zero. */
210 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
211 TYPE_VPTR_FIELDNO (type
) = -1;
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 /* Alloc a new type instance structure, fill it with some defaults,
243 and point it at OLDTYPE. Allocate the new type instance from the
244 same place as OLDTYPE. */
247 alloc_type_instance (struct type
*oldtype
)
251 /* Allocate the structure. */
253 if (! TYPE_OBJFILE_OWNED (oldtype
))
254 type
= XZALLOC (struct type
);
256 type
= OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
259 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
261 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
266 /* Clear all remnants of the previous type at TYPE, in preparation for
267 replacing it with something else. Preserve owner information. */
270 smash_type (struct type
*type
)
272 int objfile_owned
= TYPE_OBJFILE_OWNED (type
);
273 union type_owner owner
= TYPE_OWNER (type
);
275 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
277 /* Restore owner information. */
278 TYPE_OBJFILE_OWNED (type
) = objfile_owned
;
279 TYPE_OWNER (type
) = owner
;
281 /* For now, delete the rings. */
282 TYPE_CHAIN (type
) = type
;
284 /* For now, leave the pointer/reference types alone. */
287 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
288 to a pointer to memory where the pointer type should be stored.
289 If *TYPEPTR is zero, update it to point to the pointer type we return.
290 We allocate new memory if needed. */
293 make_pointer_type (struct type
*type
, struct type
**typeptr
)
295 struct type
*ntype
; /* New type */
298 ntype
= TYPE_POINTER_TYPE (type
);
303 return ntype
; /* Don't care about alloc,
304 and have new type. */
305 else if (*typeptr
== 0)
307 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
312 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
314 ntype
= alloc_type_copy (type
);
318 else /* We have storage, but need to reset it. */
321 chain
= TYPE_CHAIN (ntype
);
323 TYPE_CHAIN (ntype
) = chain
;
326 TYPE_TARGET_TYPE (ntype
) = type
;
327 TYPE_POINTER_TYPE (type
) = ntype
;
329 /* FIXME! Assumes the machine has only one representation for pointers! */
332 = gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
333 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
335 /* Mark pointers as unsigned. The target converts between pointers
336 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
337 gdbarch_address_to_pointer. */
338 TYPE_UNSIGNED (ntype
) = 1;
340 /* Update the length of all the other variants of this type. */
341 chain
= TYPE_CHAIN (ntype
);
342 while (chain
!= ntype
)
344 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
345 chain
= TYPE_CHAIN (chain
);
351 /* Given a type TYPE, return a type of pointers to that type.
352 May need to construct such a type if this is the first use. */
355 lookup_pointer_type (struct type
*type
)
357 return make_pointer_type (type
, (struct type
**) 0);
360 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
361 points to a pointer to memory where the reference type should be
362 stored. If *TYPEPTR is zero, update it to point to the reference
363 type we return. We allocate new memory if needed. */
366 make_reference_type (struct type
*type
, struct type
**typeptr
)
368 struct type
*ntype
; /* New type */
371 ntype
= TYPE_REFERENCE_TYPE (type
);
376 return ntype
; /* Don't care about alloc,
377 and have new type. */
378 else if (*typeptr
== 0)
380 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
385 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
387 ntype
= alloc_type_copy (type
);
391 else /* We have storage, but need to reset it. */
394 chain
= TYPE_CHAIN (ntype
);
396 TYPE_CHAIN (ntype
) = chain
;
399 TYPE_TARGET_TYPE (ntype
) = type
;
400 TYPE_REFERENCE_TYPE (type
) = ntype
;
402 /* FIXME! Assume the machine has only one representation for
403 references, and that it matches the (only) representation for
406 TYPE_LENGTH (ntype
) =
407 gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
408 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
410 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
411 TYPE_REFERENCE_TYPE (type
) = ntype
;
413 /* Update the length of all the other variants of this type. */
414 chain
= TYPE_CHAIN (ntype
);
415 while (chain
!= ntype
)
417 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
418 chain
= TYPE_CHAIN (chain
);
424 /* Same as above, but caller doesn't care about memory allocation
428 lookup_reference_type (struct type
*type
)
430 return make_reference_type (type
, (struct type
**) 0);
433 /* Lookup a function type that returns type TYPE. TYPEPTR, if
434 nonzero, points to a pointer to memory where the function type
435 should be stored. If *TYPEPTR is zero, update it to point to the
436 function type we return. We allocate new memory if needed. */
439 make_function_type (struct type
*type
, struct type
**typeptr
)
441 struct type
*ntype
; /* New type */
443 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
445 ntype
= alloc_type_copy (type
);
449 else /* We have storage, but need to reset it. */
455 TYPE_TARGET_TYPE (ntype
) = type
;
457 TYPE_LENGTH (ntype
) = 1;
458 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
460 INIT_FUNC_SPECIFIC (ntype
);
465 /* Given a type TYPE, return a type of functions that return that type.
466 May need to construct such a type if this is the first use. */
469 lookup_function_type (struct type
*type
)
471 return make_function_type (type
, (struct type
**) 0);
474 /* Given a type TYPE and argument types, return the appropriate
475 function type. If the final type in PARAM_TYPES is NULL, make a
479 lookup_function_type_with_arguments (struct type
*type
,
481 struct type
**param_types
)
483 struct type
*fn
= make_function_type (type
, (struct type
**) 0);
488 if (param_types
[nparams
- 1] == NULL
)
491 TYPE_VARARGS (fn
) = 1;
493 else if (TYPE_CODE (check_typedef (param_types
[nparams
- 1]))
497 /* Caller should have ensured this. */
498 gdb_assert (nparams
== 0);
499 TYPE_PROTOTYPED (fn
) = 1;
503 TYPE_NFIELDS (fn
) = nparams
;
504 TYPE_FIELDS (fn
) = TYPE_ZALLOC (fn
, nparams
* sizeof (struct field
));
505 for (i
= 0; i
< nparams
; ++i
)
506 TYPE_FIELD_TYPE (fn
, i
) = param_types
[i
];
511 /* Identify address space identifier by name --
512 return the integer flag defined in gdbtypes.h. */
515 address_space_name_to_int (struct gdbarch
*gdbarch
, char *space_identifier
)
519 /* Check for known address space delimiters. */
520 if (!strcmp (space_identifier
, "code"))
521 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
522 else if (!strcmp (space_identifier
, "data"))
523 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
524 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
525 && gdbarch_address_class_name_to_type_flags (gdbarch
,
530 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
533 /* Identify address space identifier by integer flag as defined in
534 gdbtypes.h -- return the string version of the adress space name. */
537 address_space_int_to_name (struct gdbarch
*gdbarch
, int space_flag
)
539 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
541 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
543 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
544 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
545 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
550 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
552 If STORAGE is non-NULL, create the new type instance there.
553 STORAGE must be in the same obstack as TYPE. */
556 make_qualified_type (struct type
*type
, int new_flags
,
557 struct type
*storage
)
564 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
566 ntype
= TYPE_CHAIN (ntype
);
568 while (ntype
!= type
);
570 /* Create a new type instance. */
572 ntype
= alloc_type_instance (type
);
575 /* If STORAGE was provided, it had better be in the same objfile
576 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
577 if one objfile is freed and the other kept, we'd have
578 dangling pointers. */
579 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
582 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
583 TYPE_CHAIN (ntype
) = ntype
;
586 /* Pointers or references to the original type are not relevant to
588 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
589 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
591 /* Chain the new qualified type to the old type. */
592 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
593 TYPE_CHAIN (type
) = ntype
;
595 /* Now set the instance flags and return the new type. */
596 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
598 /* Set length of new type to that of the original type. */
599 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
604 /* Make an address-space-delimited variant of a type -- a type that
605 is identical to the one supplied except that it has an address
606 space attribute attached to it (such as "code" or "data").
608 The space attributes "code" and "data" are for Harvard
609 architectures. The address space attributes are for architectures
610 which have alternately sized pointers or pointers with alternate
614 make_type_with_address_space (struct type
*type
, int space_flag
)
616 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
617 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
618 | TYPE_INSTANCE_FLAG_DATA_SPACE
619 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
622 return make_qualified_type (type
, new_flags
, NULL
);
625 /* Make a "c-v" variant of a type -- a type that is identical to the
626 one supplied except that it may have const or volatile attributes
627 CNST is a flag for setting the const attribute
628 VOLTL is a flag for setting the volatile attribute
629 TYPE is the base type whose variant we are creating.
631 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
632 storage to hold the new qualified type; *TYPEPTR and TYPE must be
633 in the same objfile. Otherwise, allocate fresh memory for the new
634 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
635 new type we construct. */
638 make_cv_type (int cnst
, int voltl
,
640 struct type
**typeptr
)
642 struct type
*ntype
; /* New type */
644 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
645 & ~(TYPE_INSTANCE_FLAG_CONST
646 | TYPE_INSTANCE_FLAG_VOLATILE
));
649 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
652 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
654 if (typeptr
&& *typeptr
!= NULL
)
656 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
657 a C-V variant chain that threads across objfiles: if one
658 objfile gets freed, then the other has a broken C-V chain.
660 This code used to try to copy over the main type from TYPE to
661 *TYPEPTR if they were in different objfiles, but that's
662 wrong, too: TYPE may have a field list or member function
663 lists, which refer to types of their own, etc. etc. The
664 whole shebang would need to be copied over recursively; you
665 can't have inter-objfile pointers. The only thing to do is
666 to leave stub types as stub types, and look them up afresh by
667 name each time you encounter them. */
668 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
671 ntype
= make_qualified_type (type
, new_flags
,
672 typeptr
? *typeptr
: NULL
);
680 /* Make a 'restrict'-qualified version of TYPE. */
683 make_restrict_type (struct type
*type
)
685 return make_qualified_type (type
,
686 (TYPE_INSTANCE_FLAGS (type
)
687 | TYPE_INSTANCE_FLAG_RESTRICT
),
691 /* Replace the contents of ntype with the type *type. This changes the
692 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
693 the changes are propogated to all types in the TYPE_CHAIN.
695 In order to build recursive types, it's inevitable that we'll need
696 to update types in place --- but this sort of indiscriminate
697 smashing is ugly, and needs to be replaced with something more
698 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
699 clear if more steps are needed. */
702 replace_type (struct type
*ntype
, struct type
*type
)
706 /* These two types had better be in the same objfile. Otherwise,
707 the assignment of one type's main type structure to the other
708 will produce a type with references to objects (names; field
709 lists; etc.) allocated on an objfile other than its own. */
710 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
712 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
714 /* The type length is not a part of the main type. Update it for
715 each type on the variant chain. */
719 /* Assert that this element of the chain has no address-class bits
720 set in its flags. Such type variants might have type lengths
721 which are supposed to be different from the non-address-class
722 variants. This assertion shouldn't ever be triggered because
723 symbol readers which do construct address-class variants don't
724 call replace_type(). */
725 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
727 TYPE_LENGTH (chain
) = TYPE_LENGTH (type
);
728 chain
= TYPE_CHAIN (chain
);
730 while (ntype
!= chain
);
732 /* Assert that the two types have equivalent instance qualifiers.
733 This should be true for at least all of our debug readers. */
734 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
737 /* Implement direct support for MEMBER_TYPE in GNU C++.
738 May need to construct such a type if this is the first use.
739 The TYPE is the type of the member. The DOMAIN is the type
740 of the aggregate that the member belongs to. */
743 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
747 mtype
= alloc_type_copy (type
);
748 smash_to_memberptr_type (mtype
, domain
, type
);
752 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
755 lookup_methodptr_type (struct type
*to_type
)
759 mtype
= alloc_type_copy (to_type
);
760 smash_to_methodptr_type (mtype
, to_type
);
764 /* Allocate a stub method whose return type is TYPE. This apparently
765 happens for speed of symbol reading, since parsing out the
766 arguments to the method is cpu-intensive, the way we are doing it.
767 So, we will fill in arguments later. This always returns a fresh
771 allocate_stub_method (struct type
*type
)
775 mtype
= alloc_type_copy (type
);
776 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
777 TYPE_LENGTH (mtype
) = 1;
778 TYPE_STUB (mtype
) = 1;
779 TYPE_TARGET_TYPE (mtype
) = type
;
780 /* _DOMAIN_TYPE (mtype) = unknown yet */
784 /* Create a range type using either a blank type supplied in
785 RESULT_TYPE, or creating a new type, inheriting the objfile from
788 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
789 to HIGH_BOUND, inclusive.
791 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
792 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
795 create_range_type (struct type
*result_type
, struct type
*index_type
,
796 LONGEST low_bound
, LONGEST high_bound
)
798 if (result_type
== NULL
)
799 result_type
= alloc_type_copy (index_type
);
800 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
801 TYPE_TARGET_TYPE (result_type
) = index_type
;
802 if (TYPE_STUB (index_type
))
803 TYPE_TARGET_STUB (result_type
) = 1;
805 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
806 TYPE_RANGE_DATA (result_type
) = (struct range_bounds
*)
807 TYPE_ZALLOC (result_type
, sizeof (struct range_bounds
));
808 TYPE_LOW_BOUND (result_type
) = low_bound
;
809 TYPE_HIGH_BOUND (result_type
) = high_bound
;
812 TYPE_UNSIGNED (result_type
) = 1;
817 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
818 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
819 bounds will fit in LONGEST), or -1 otherwise. */
822 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
824 CHECK_TYPEDEF (type
);
825 switch (TYPE_CODE (type
))
827 case TYPE_CODE_RANGE
:
828 *lowp
= TYPE_LOW_BOUND (type
);
829 *highp
= TYPE_HIGH_BOUND (type
);
832 if (TYPE_NFIELDS (type
) > 0)
834 /* The enums may not be sorted by value, so search all
838 *lowp
= *highp
= TYPE_FIELD_ENUMVAL (type
, 0);
839 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
841 if (TYPE_FIELD_ENUMVAL (type
, i
) < *lowp
)
842 *lowp
= TYPE_FIELD_ENUMVAL (type
, i
);
843 if (TYPE_FIELD_ENUMVAL (type
, i
) > *highp
)
844 *highp
= TYPE_FIELD_ENUMVAL (type
, i
);
847 /* Set unsigned indicator if warranted. */
850 TYPE_UNSIGNED (type
) = 1;
864 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
866 if (!TYPE_UNSIGNED (type
))
868 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
872 /* ... fall through for unsigned ints ... */
875 /* This round-about calculation is to avoid shifting by
876 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
877 if TYPE_LENGTH (type) == sizeof (LONGEST). */
878 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
879 *highp
= (*highp
- 1) | *highp
;
886 /* Assuming TYPE is a simple, non-empty array type, compute its upper
887 and lower bound. Save the low bound into LOW_BOUND if not NULL.
888 Save the high bound into HIGH_BOUND if not NULL.
890 Return 1 if the operation was successful. Return zero otherwise,
891 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
893 We now simply use get_discrete_bounds call to get the values
894 of the low and high bounds.
895 get_discrete_bounds can return three values:
896 1, meaning that index is a range,
897 0, meaning that index is a discrete type,
898 or -1 for failure. */
901 get_array_bounds (struct type
*type
, LONGEST
*low_bound
, LONGEST
*high_bound
)
903 struct type
*index
= TYPE_INDEX_TYPE (type
);
911 res
= get_discrete_bounds (index
, &low
, &high
);
915 /* Check if the array bounds are undefined. */
917 && ((low_bound
&& TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type
))
918 || (high_bound
&& TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type
))))
930 /* Create an array type using either a blank type supplied in
931 RESULT_TYPE, or creating a new type, inheriting the objfile from
934 Elements will be of type ELEMENT_TYPE, the indices will be of type
937 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
938 sure it is TYPE_CODE_UNDEF before we bash it into an array
942 create_array_type (struct type
*result_type
,
943 struct type
*element_type
,
944 struct type
*range_type
)
946 LONGEST low_bound
, high_bound
;
948 if (result_type
== NULL
)
949 result_type
= alloc_type_copy (range_type
);
951 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
952 TYPE_TARGET_TYPE (result_type
) = element_type
;
953 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
954 low_bound
= high_bound
= 0;
955 CHECK_TYPEDEF (element_type
);
956 /* Be careful when setting the array length. Ada arrays can be
957 empty arrays with the high_bound being smaller than the low_bound.
958 In such cases, the array length should be zero. */
959 if (high_bound
< low_bound
)
960 TYPE_LENGTH (result_type
) = 0;
962 TYPE_LENGTH (result_type
) =
963 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
964 TYPE_NFIELDS (result_type
) = 1;
965 TYPE_FIELDS (result_type
) =
966 (struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
));
967 TYPE_INDEX_TYPE (result_type
) = range_type
;
968 TYPE_VPTR_FIELDNO (result_type
) = -1;
970 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */
971 if (TYPE_LENGTH (result_type
) == 0)
972 TYPE_TARGET_STUB (result_type
) = 1;
978 lookup_array_range_type (struct type
*element_type
,
979 LONGEST low_bound
, LONGEST high_bound
)
981 struct gdbarch
*gdbarch
= get_type_arch (element_type
);
982 struct type
*index_type
= builtin_type (gdbarch
)->builtin_int
;
983 struct type
*range_type
984 = create_range_type (NULL
, index_type
, low_bound
, high_bound
);
986 return create_array_type (NULL
, element_type
, range_type
);
989 /* Create a string type using either a blank type supplied in
990 RESULT_TYPE, or creating a new type. String types are similar
991 enough to array of char types that we can use create_array_type to
992 build the basic type and then bash it into a string type.
994 For fixed length strings, the range type contains 0 as the lower
995 bound and the length of the string minus one as the upper bound.
997 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
998 sure it is TYPE_CODE_UNDEF before we bash it into a string
1002 create_string_type (struct type
*result_type
,
1003 struct type
*string_char_type
,
1004 struct type
*range_type
)
1006 result_type
= create_array_type (result_type
,
1009 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
1014 lookup_string_range_type (struct type
*string_char_type
,
1015 LONGEST low_bound
, LONGEST high_bound
)
1017 struct type
*result_type
;
1019 result_type
= lookup_array_range_type (string_char_type
,
1020 low_bound
, high_bound
);
1021 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
1026 create_set_type (struct type
*result_type
, struct type
*domain_type
)
1028 if (result_type
== NULL
)
1029 result_type
= alloc_type_copy (domain_type
);
1031 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
1032 TYPE_NFIELDS (result_type
) = 1;
1033 TYPE_FIELDS (result_type
) = TYPE_ZALLOC (result_type
, sizeof (struct field
));
1035 if (!TYPE_STUB (domain_type
))
1037 LONGEST low_bound
, high_bound
, bit_length
;
1039 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
1040 low_bound
= high_bound
= 0;
1041 bit_length
= high_bound
- low_bound
+ 1;
1042 TYPE_LENGTH (result_type
)
1043 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
1045 TYPE_UNSIGNED (result_type
) = 1;
1047 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
1052 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
1053 and any array types nested inside it. */
1056 make_vector_type (struct type
*array_type
)
1058 struct type
*inner_array
, *elt_type
;
1061 /* Find the innermost array type, in case the array is
1062 multi-dimensional. */
1063 inner_array
= array_type
;
1064 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
1065 inner_array
= TYPE_TARGET_TYPE (inner_array
);
1067 elt_type
= TYPE_TARGET_TYPE (inner_array
);
1068 if (TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
1070 flags
= TYPE_INSTANCE_FLAGS (elt_type
) | TYPE_INSTANCE_FLAG_NOTTEXT
;
1071 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
1072 TYPE_TARGET_TYPE (inner_array
) = elt_type
;
1075 TYPE_VECTOR (array_type
) = 1;
1079 init_vector_type (struct type
*elt_type
, int n
)
1081 struct type
*array_type
;
1083 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
1084 make_vector_type (array_type
);
1088 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
1089 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1090 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1091 TYPE doesn't include the offset (that's the value of the MEMBER
1092 itself), but does include the structure type into which it points
1095 When "smashing" the type, we preserve the objfile that the old type
1096 pointed to, since we aren't changing where the type is actually
1100 smash_to_memberptr_type (struct type
*type
, struct type
*domain
,
1101 struct type
*to_type
)
1104 TYPE_TARGET_TYPE (type
) = to_type
;
1105 TYPE_DOMAIN_TYPE (type
) = domain
;
1106 /* Assume that a data member pointer is the same size as a normal
1109 = gdbarch_ptr_bit (get_type_arch (to_type
)) / TARGET_CHAR_BIT
;
1110 TYPE_CODE (type
) = TYPE_CODE_MEMBERPTR
;
1113 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
1115 When "smashing" the type, we preserve the objfile that the old type
1116 pointed to, since we aren't changing where the type is actually
1120 smash_to_methodptr_type (struct type
*type
, struct type
*to_type
)
1123 TYPE_TARGET_TYPE (type
) = to_type
;
1124 TYPE_DOMAIN_TYPE (type
) = TYPE_DOMAIN_TYPE (to_type
);
1125 TYPE_LENGTH (type
) = cplus_method_ptr_size (to_type
);
1126 TYPE_CODE (type
) = TYPE_CODE_METHODPTR
;
1129 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1130 METHOD just means `function that gets an extra "this" argument'.
1132 When "smashing" the type, we preserve the objfile that the old type
1133 pointed to, since we aren't changing where the type is actually
1137 smash_to_method_type (struct type
*type
, struct type
*domain
,
1138 struct type
*to_type
, struct field
*args
,
1139 int nargs
, int varargs
)
1142 TYPE_TARGET_TYPE (type
) = to_type
;
1143 TYPE_DOMAIN_TYPE (type
) = domain
;
1144 TYPE_FIELDS (type
) = args
;
1145 TYPE_NFIELDS (type
) = nargs
;
1147 TYPE_VARARGS (type
) = 1;
1148 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1149 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1152 /* Return a typename for a struct/union/enum type without "struct ",
1153 "union ", or "enum ". If the type has a NULL name, return NULL. */
1156 type_name_no_tag (const struct type
*type
)
1158 if (TYPE_TAG_NAME (type
) != NULL
)
1159 return TYPE_TAG_NAME (type
);
1161 /* Is there code which expects this to return the name if there is
1162 no tag name? My guess is that this is mainly used for C++ in
1163 cases where the two will always be the same. */
1164 return TYPE_NAME (type
);
1167 /* A wrapper of type_name_no_tag which calls error if the type is anonymous.
1168 Since GCC PR debug/47510 DWARF provides associated information to detect the
1169 anonymous class linkage name from its typedef.
1171 Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
1175 type_name_no_tag_or_error (struct type
*type
)
1177 struct type
*saved_type
= type
;
1179 struct objfile
*objfile
;
1181 CHECK_TYPEDEF (type
);
1183 name
= type_name_no_tag (type
);
1187 name
= type_name_no_tag (saved_type
);
1188 objfile
= TYPE_OBJFILE (saved_type
);
1189 error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
1190 name
? name
: "<anonymous>", objfile
? objfile
->name
: "<arch>");
1193 /* Lookup a typedef or primitive type named NAME, visible in lexical
1194 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1195 suitably defined. */
1198 lookup_typename (const struct language_defn
*language
,
1199 struct gdbarch
*gdbarch
, const char *name
,
1200 const struct block
*block
, int noerr
)
1205 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0);
1206 if (sym
!= NULL
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
1207 return SYMBOL_TYPE (sym
);
1209 type
= language_lookup_primitive_type_by_name (language
, gdbarch
, name
);
1215 error (_("No type named %s."), name
);
1219 lookup_unsigned_typename (const struct language_defn
*language
,
1220 struct gdbarch
*gdbarch
, const char *name
)
1222 char *uns
= alloca (strlen (name
) + 10);
1224 strcpy (uns
, "unsigned ");
1225 strcpy (uns
+ 9, name
);
1226 return lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 0);
1230 lookup_signed_typename (const struct language_defn
*language
,
1231 struct gdbarch
*gdbarch
, const char *name
)
1234 char *uns
= alloca (strlen (name
) + 8);
1236 strcpy (uns
, "signed ");
1237 strcpy (uns
+ 7, name
);
1238 t
= lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 1);
1239 /* If we don't find "signed FOO" just try again with plain "FOO". */
1242 return lookup_typename (language
, gdbarch
, name
, (struct block
*) NULL
, 0);
1245 /* Lookup a structure type named "struct NAME",
1246 visible in lexical block BLOCK. */
1249 lookup_struct (const char *name
, const struct block
*block
)
1253 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1257 error (_("No struct type named %s."), name
);
1259 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1261 error (_("This context has class, union or enum %s, not a struct."),
1264 return (SYMBOL_TYPE (sym
));
1267 /* Lookup a union type named "union NAME",
1268 visible in lexical block BLOCK. */
1271 lookup_union (const char *name
, const struct block
*block
)
1276 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1279 error (_("No union type named %s."), name
);
1281 t
= SYMBOL_TYPE (sym
);
1283 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1286 /* If we get here, it's not a union. */
1287 error (_("This context has class, struct or enum %s, not a union."),
1291 /* Lookup an enum type named "enum NAME",
1292 visible in lexical block BLOCK. */
1295 lookup_enum (const char *name
, const struct block
*block
)
1299 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1302 error (_("No enum type named %s."), name
);
1304 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1306 error (_("This context has class, struct or union %s, not an enum."),
1309 return (SYMBOL_TYPE (sym
));
1312 /* Lookup a template type named "template NAME<TYPE>",
1313 visible in lexical block BLOCK. */
1316 lookup_template_type (char *name
, struct type
*type
,
1317 const struct block
*block
)
1320 char *nam
= (char *)
1321 alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1325 strcat (nam
, TYPE_NAME (type
));
1326 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1328 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0);
1332 error (_("No template type named %s."), name
);
1334 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1336 error (_("This context has class, union or enum %s, not a struct."),
1339 return (SYMBOL_TYPE (sym
));
1342 /* Given a type TYPE, lookup the type of the component of type named
1345 TYPE can be either a struct or union, or a pointer or reference to
1346 a struct or union. If it is a pointer or reference, its target
1347 type is automatically used. Thus '.' and '->' are interchangable,
1348 as specified for the definitions of the expression element types
1349 STRUCTOP_STRUCT and STRUCTOP_PTR.
1351 If NOERR is nonzero, return zero if NAME is not suitably defined.
1352 If NAME is the name of a baseclass type, return that type. */
1355 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1362 CHECK_TYPEDEF (type
);
1363 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1364 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1366 type
= TYPE_TARGET_TYPE (type
);
1369 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1370 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1372 typename
= type_to_string (type
);
1373 make_cleanup (xfree
, typename
);
1374 error (_("Type %s is not a structure or union type."), typename
);
1378 /* FIXME: This change put in by Michael seems incorrect for the case
1379 where the structure tag name is the same as the member name.
1380 I.e. when doing "ptype bell->bar" for "struct foo { int bar; int
1381 foo; } bell;" Disabled by fnf. */
1385 typename
= type_name_no_tag (type
);
1386 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1391 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1393 const char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1395 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1397 return TYPE_FIELD_TYPE (type
, i
);
1399 else if (!t_field_name
|| *t_field_name
== '\0')
1401 struct type
*subtype
1402 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type
, i
), name
, 1);
1404 if (subtype
!= NULL
)
1409 /* OK, it's not in this class. Recursively check the baseclasses. */
1410 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1414 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1426 typename
= type_to_string (type
);
1427 make_cleanup (xfree
, typename
);
1428 error (_("Type %s has no component named %s."), typename
, name
);
1431 /* Lookup the vptr basetype/fieldno values for TYPE.
1432 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1433 vptr_fieldno. Also, if found and basetype is from the same objfile,
1435 If not found, return -1 and ignore BASETYPEP.
1436 Callers should be aware that in some cases (for example,
1437 the type or one of its baseclasses is a stub type and we are
1438 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1439 this function will not be able to find the
1440 virtual function table pointer, and vptr_fieldno will remain -1 and
1441 vptr_basetype will remain NULL or incomplete. */
1444 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1446 CHECK_TYPEDEF (type
);
1448 if (TYPE_VPTR_FIELDNO (type
) < 0)
1452 /* We must start at zero in case the first (and only) baseclass
1453 is virtual (and hence we cannot share the table pointer). */
1454 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1456 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1458 struct type
*basetype
;
1460 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1463 /* If the type comes from a different objfile we can't cache
1464 it, it may have a different lifetime. PR 2384 */
1465 if (TYPE_OBJFILE (type
) == TYPE_OBJFILE (basetype
))
1467 TYPE_VPTR_FIELDNO (type
) = fieldno
;
1468 TYPE_VPTR_BASETYPE (type
) = basetype
;
1471 *basetypep
= basetype
;
1482 *basetypep
= TYPE_VPTR_BASETYPE (type
);
1483 return TYPE_VPTR_FIELDNO (type
);
1488 stub_noname_complaint (void)
1490 complaint (&symfile_complaints
, _("stub type has NULL name"));
1493 /* Find the real type of TYPE. This function returns the real type,
1494 after removing all layers of typedefs, and completing opaque or stub
1495 types. Completion changes the TYPE argument, but stripping of
1498 Instance flags (e.g. const/volatile) are preserved as typedefs are
1499 stripped. If necessary a new qualified form of the underlying type
1502 NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has
1503 not been computed and we're either in the middle of reading symbols, or
1504 there was no name for the typedef in the debug info.
1506 NOTE: Lookup of opaque types can throw errors for invalid symbol files.
1507 QUITs in the symbol reading code can also throw.
1508 Thus this function can throw an exception.
1510 If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
1513 If this is a stubbed struct (i.e. declared as struct foo *), see if
1514 we can find a full definition in some other file. If so, copy this
1515 definition, so we can use it in future. There used to be a comment
1516 (but not any code) that if we don't find a full definition, we'd
1517 set a flag so we don't spend time in the future checking the same
1518 type. That would be a mistake, though--we might load in more
1519 symbols which contain a full definition for the type. */
1522 check_typedef (struct type
*type
)
1524 struct type
*orig_type
= type
;
1525 /* While we're removing typedefs, we don't want to lose qualifiers.
1526 E.g., const/volatile. */
1527 int instance_flags
= TYPE_INSTANCE_FLAGS (type
);
1531 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1533 if (!TYPE_TARGET_TYPE (type
))
1538 /* It is dangerous to call lookup_symbol if we are currently
1539 reading a symtab. Infinite recursion is one danger. */
1540 if (currently_reading_symtab
)
1541 return make_qualified_type (type
, instance_flags
, NULL
);
1543 name
= type_name_no_tag (type
);
1544 /* FIXME: shouldn't we separately check the TYPE_NAME and
1545 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1546 VAR_DOMAIN as appropriate? (this code was written before
1547 TYPE_NAME and TYPE_TAG_NAME were separate). */
1550 stub_noname_complaint ();
1551 return make_qualified_type (type
, instance_flags
, NULL
);
1553 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1555 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1556 else /* TYPE_CODE_UNDEF */
1557 TYPE_TARGET_TYPE (type
) = alloc_type_arch (get_type_arch (type
));
1559 type
= TYPE_TARGET_TYPE (type
);
1561 /* Preserve the instance flags as we traverse down the typedef chain.
1563 Handling address spaces/classes is nasty, what do we do if there's a
1565 E.g., what if an outer typedef marks the type as class_1 and an inner
1566 typedef marks the type as class_2?
1567 This is the wrong place to do such error checking. We leave it to
1568 the code that created the typedef in the first place to flag the
1569 error. We just pick the outer address space (akin to letting the
1570 outer cast in a chain of casting win), instead of assuming
1571 "it can't happen". */
1573 const int ALL_SPACES
= (TYPE_INSTANCE_FLAG_CODE_SPACE
1574 | TYPE_INSTANCE_FLAG_DATA_SPACE
);
1575 const int ALL_CLASSES
= TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
;
1576 int new_instance_flags
= TYPE_INSTANCE_FLAGS (type
);
1578 /* Treat code vs data spaces and address classes separately. */
1579 if ((instance_flags
& ALL_SPACES
) != 0)
1580 new_instance_flags
&= ~ALL_SPACES
;
1581 if ((instance_flags
& ALL_CLASSES
) != 0)
1582 new_instance_flags
&= ~ALL_CLASSES
;
1584 instance_flags
|= new_instance_flags
;
1588 /* If this is a struct/class/union with no fields, then check
1589 whether a full definition exists somewhere else. This is for
1590 systems where a type definition with no fields is issued for such
1591 types, instead of identifying them as stub types in the first
1594 if (TYPE_IS_OPAQUE (type
)
1595 && opaque_type_resolution
1596 && !currently_reading_symtab
)
1598 const char *name
= type_name_no_tag (type
);
1599 struct type
*newtype
;
1603 stub_noname_complaint ();
1604 return make_qualified_type (type
, instance_flags
, NULL
);
1606 newtype
= lookup_transparent_type (name
);
1610 /* If the resolved type and the stub are in the same
1611 objfile, then replace the stub type with the real deal.
1612 But if they're in separate objfiles, leave the stub
1613 alone; we'll just look up the transparent type every time
1614 we call check_typedef. We can't create pointers between
1615 types allocated to different objfiles, since they may
1616 have different lifetimes. Trying to copy NEWTYPE over to
1617 TYPE's objfile is pointless, too, since you'll have to
1618 move over any other types NEWTYPE refers to, which could
1619 be an unbounded amount of stuff. */
1620 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1621 type
= make_qualified_type (newtype
,
1622 TYPE_INSTANCE_FLAGS (type
),
1628 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1630 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1632 const char *name
= type_name_no_tag (type
);
1633 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1634 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1635 as appropriate? (this code was written before TYPE_NAME and
1636 TYPE_TAG_NAME were separate). */
1641 stub_noname_complaint ();
1642 return make_qualified_type (type
, instance_flags
, NULL
);
1644 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1647 /* Same as above for opaque types, we can replace the stub
1648 with the complete type only if they are in the same
1650 if (TYPE_OBJFILE (SYMBOL_TYPE(sym
)) == TYPE_OBJFILE (type
))
1651 type
= make_qualified_type (SYMBOL_TYPE (sym
),
1652 TYPE_INSTANCE_FLAGS (type
),
1655 type
= SYMBOL_TYPE (sym
);
1659 if (TYPE_TARGET_STUB (type
))
1661 struct type
*range_type
;
1662 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1664 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1666 /* Nothing we can do. */
1668 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1669 && TYPE_NFIELDS (type
) == 1
1670 && (TYPE_CODE (range_type
= TYPE_INDEX_TYPE (type
))
1671 == TYPE_CODE_RANGE
))
1673 /* Now recompute the length of the array type, based on its
1674 number of elements and the target type's length.
1675 Watch out for Ada null Ada arrays where the high bound
1676 is smaller than the low bound. */
1677 const LONGEST low_bound
= TYPE_LOW_BOUND (range_type
);
1678 const LONGEST high_bound
= TYPE_HIGH_BOUND (range_type
);
1681 if (high_bound
< low_bound
)
1685 /* For now, we conservatively take the array length to be 0
1686 if its length exceeds UINT_MAX. The code below assumes
1687 that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
1688 which is technically not guaranteed by C, but is usually true
1689 (because it would be true if x were unsigned with its
1690 high-order bit on). It uses the fact that
1691 high_bound-low_bound is always representable in
1692 ULONGEST and that if high_bound-low_bound+1 overflows,
1693 it overflows to 0. We must change these tests if we
1694 decide to increase the representation of TYPE_LENGTH
1695 from unsigned int to ULONGEST. */
1696 ULONGEST ulow
= low_bound
, uhigh
= high_bound
;
1697 ULONGEST tlen
= TYPE_LENGTH (target_type
);
1699 len
= tlen
* (uhigh
- ulow
+ 1);
1700 if (tlen
== 0 || (len
/ tlen
- 1 + ulow
) != uhigh
1704 TYPE_LENGTH (type
) = len
;
1705 TYPE_TARGET_STUB (type
) = 0;
1707 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1709 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1710 TYPE_TARGET_STUB (type
) = 0;
1714 type
= make_qualified_type (type
, instance_flags
, NULL
);
1716 /* Cache TYPE_LENGTH for future use. */
1717 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1722 /* Parse a type expression in the string [P..P+LENGTH). If an error
1723 occurs, silently return a void type. */
1725 static struct type
*
1726 safe_parse_type (struct gdbarch
*gdbarch
, char *p
, int length
)
1728 struct ui_file
*saved_gdb_stderr
;
1729 struct type
*type
= NULL
; /* Initialize to keep gcc happy. */
1730 volatile struct gdb_exception except
;
1732 /* Suppress error messages. */
1733 saved_gdb_stderr
= gdb_stderr
;
1734 gdb_stderr
= ui_file_new ();
1736 /* Call parse_and_eval_type() without fear of longjmp()s. */
1737 TRY_CATCH (except
, RETURN_MASK_ERROR
)
1739 type
= parse_and_eval_type (p
, length
);
1742 if (except
.reason
< 0)
1743 type
= builtin_type (gdbarch
)->builtin_void
;
1745 /* Stop suppressing error messages. */
1746 ui_file_delete (gdb_stderr
);
1747 gdb_stderr
= saved_gdb_stderr
;
1752 /* Ugly hack to convert method stubs into method types.
1754 He ain't kiddin'. This demangles the name of the method into a
1755 string including argument types, parses out each argument type,
1756 generates a string casting a zero to that type, evaluates the
1757 string, and stuffs the resulting type into an argtype vector!!!
1758 Then it knows the type of the whole function (including argument
1759 types for overloading), which info used to be in the stab's but was
1760 removed to hack back the space required for them. */
1763 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1765 struct gdbarch
*gdbarch
= get_type_arch (type
);
1767 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1768 char *demangled_name
= gdb_demangle (mangled_name
,
1769 DMGL_PARAMS
| DMGL_ANSI
);
1770 char *argtypetext
, *p
;
1771 int depth
= 0, argcount
= 1;
1772 struct field
*argtypes
;
1775 /* Make sure we got back a function string that we can use. */
1777 p
= strchr (demangled_name
, '(');
1781 if (demangled_name
== NULL
|| p
== NULL
)
1782 error (_("Internal: Cannot demangle mangled name `%s'."),
1785 /* Now, read in the parameters that define this type. */
1790 if (*p
== '(' || *p
== '<')
1794 else if (*p
== ')' || *p
== '>')
1798 else if (*p
== ',' && depth
== 0)
1806 /* If we read one argument and it was ``void'', don't count it. */
1807 if (strncmp (argtypetext
, "(void)", 6) == 0)
1810 /* We need one extra slot, for the THIS pointer. */
1812 argtypes
= (struct field
*)
1813 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1816 /* Add THIS pointer for non-static methods. */
1817 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1818 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1822 argtypes
[0].type
= lookup_pointer_type (type
);
1826 if (*p
!= ')') /* () means no args, skip while. */
1831 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1833 /* Avoid parsing of ellipsis, they will be handled below.
1834 Also avoid ``void'' as above. */
1835 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1836 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1838 argtypes
[argcount
].type
=
1839 safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
);
1842 argtypetext
= p
+ 1;
1845 if (*p
== '(' || *p
== '<')
1849 else if (*p
== ')' || *p
== '>')
1858 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1860 /* Now update the old "stub" type into a real type. */
1861 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1862 TYPE_DOMAIN_TYPE (mtype
) = type
;
1863 TYPE_FIELDS (mtype
) = argtypes
;
1864 TYPE_NFIELDS (mtype
) = argcount
;
1865 TYPE_STUB (mtype
) = 0;
1866 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1868 TYPE_VARARGS (mtype
) = 1;
1870 xfree (demangled_name
);
1873 /* This is the external interface to check_stub_method, above. This
1874 function unstubs all of the signatures for TYPE's METHOD_ID method
1875 name. After calling this function TYPE_FN_FIELD_STUB will be
1876 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1879 This function unfortunately can not die until stabs do. */
1882 check_stub_method_group (struct type
*type
, int method_id
)
1884 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1885 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1886 int j
, found_stub
= 0;
1888 for (j
= 0; j
< len
; j
++)
1889 if (TYPE_FN_FIELD_STUB (f
, j
))
1892 check_stub_method (type
, method_id
, j
);
1895 /* GNU v3 methods with incorrect names were corrected when we read
1896 in type information, because it was cheaper to do it then. The
1897 only GNU v2 methods with incorrect method names are operators and
1898 destructors; destructors were also corrected when we read in type
1901 Therefore the only thing we need to handle here are v2 operator
1903 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1906 char dem_opname
[256];
1908 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1910 dem_opname
, DMGL_ANSI
);
1912 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1916 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1920 /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
1921 const struct cplus_struct_type cplus_struct_default
= { };
1924 allocate_cplus_struct_type (struct type
*type
)
1926 if (HAVE_CPLUS_STRUCT (type
))
1927 /* Structure was already allocated. Nothing more to do. */
1930 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_CPLUS_STUFF
;
1931 TYPE_RAW_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1932 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1933 *(TYPE_RAW_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1936 const struct gnat_aux_type gnat_aux_default
=
1939 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
1940 and allocate the associated gnat-specific data. The gnat-specific
1941 data is also initialized to gnat_aux_default. */
1944 allocate_gnat_aux_type (struct type
*type
)
1946 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_GNAT_STUFF
;
1947 TYPE_GNAT_SPECIFIC (type
) = (struct gnat_aux_type
*)
1948 TYPE_ALLOC (type
, sizeof (struct gnat_aux_type
));
1949 *(TYPE_GNAT_SPECIFIC (type
)) = gnat_aux_default
;
1952 /* Helper function to initialize the standard scalar types.
1954 If NAME is non-NULL, then it is used to initialize the type name.
1955 Note that NAME is not copied; it is required to have a lifetime at
1956 least as long as OBJFILE. */
1959 init_type (enum type_code code
, int length
, int flags
,
1960 const char *name
, struct objfile
*objfile
)
1964 type
= alloc_type (objfile
);
1965 TYPE_CODE (type
) = code
;
1966 TYPE_LENGTH (type
) = length
;
1968 gdb_assert (!(flags
& (TYPE_FLAG_MIN
- 1)));
1969 if (flags
& TYPE_FLAG_UNSIGNED
)
1970 TYPE_UNSIGNED (type
) = 1;
1971 if (flags
& TYPE_FLAG_NOSIGN
)
1972 TYPE_NOSIGN (type
) = 1;
1973 if (flags
& TYPE_FLAG_STUB
)
1974 TYPE_STUB (type
) = 1;
1975 if (flags
& TYPE_FLAG_TARGET_STUB
)
1976 TYPE_TARGET_STUB (type
) = 1;
1977 if (flags
& TYPE_FLAG_STATIC
)
1978 TYPE_STATIC (type
) = 1;
1979 if (flags
& TYPE_FLAG_PROTOTYPED
)
1980 TYPE_PROTOTYPED (type
) = 1;
1981 if (flags
& TYPE_FLAG_INCOMPLETE
)
1982 TYPE_INCOMPLETE (type
) = 1;
1983 if (flags
& TYPE_FLAG_VARARGS
)
1984 TYPE_VARARGS (type
) = 1;
1985 if (flags
& TYPE_FLAG_VECTOR
)
1986 TYPE_VECTOR (type
) = 1;
1987 if (flags
& TYPE_FLAG_STUB_SUPPORTED
)
1988 TYPE_STUB_SUPPORTED (type
) = 1;
1989 if (flags
& TYPE_FLAG_FIXED_INSTANCE
)
1990 TYPE_FIXED_INSTANCE (type
) = 1;
1991 if (flags
& TYPE_FLAG_GNU_IFUNC
)
1992 TYPE_GNU_IFUNC (type
) = 1;
1994 TYPE_NAME (type
) = name
;
1998 if (name
&& strcmp (name
, "char") == 0)
1999 TYPE_NOSIGN (type
) = 1;
2003 case TYPE_CODE_STRUCT
:
2004 case TYPE_CODE_UNION
:
2005 case TYPE_CODE_NAMESPACE
:
2006 INIT_CPLUS_SPECIFIC (type
);
2009 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_FLOATFORMAT
;
2011 case TYPE_CODE_FUNC
:
2012 INIT_FUNC_SPECIFIC (type
);
2018 /* Queries on types. */
2021 can_dereference (struct type
*t
)
2023 /* FIXME: Should we return true for references as well as
2028 && TYPE_CODE (t
) == TYPE_CODE_PTR
2029 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
2033 is_integral_type (struct type
*t
)
2038 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
2039 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
2040 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
2041 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
2042 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
2043 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
2046 /* Return true if TYPE is scalar. */
2049 is_scalar_type (struct type
*type
)
2051 CHECK_TYPEDEF (type
);
2053 switch (TYPE_CODE (type
))
2055 case TYPE_CODE_ARRAY
:
2056 case TYPE_CODE_STRUCT
:
2057 case TYPE_CODE_UNION
:
2059 case TYPE_CODE_STRING
:
2066 /* Return true if T is scalar, or a composite type which in practice has
2067 the memory layout of a scalar type. E.g., an array or struct with only
2068 one scalar element inside it, or a union with only scalar elements. */
2071 is_scalar_type_recursive (struct type
*t
)
2075 if (is_scalar_type (t
))
2077 /* Are we dealing with an array or string of known dimensions? */
2078 else if ((TYPE_CODE (t
) == TYPE_CODE_ARRAY
2079 || TYPE_CODE (t
) == TYPE_CODE_STRING
) && TYPE_NFIELDS (t
) == 1
2080 && TYPE_CODE (TYPE_INDEX_TYPE (t
)) == TYPE_CODE_RANGE
)
2082 LONGEST low_bound
, high_bound
;
2083 struct type
*elt_type
= check_typedef (TYPE_TARGET_TYPE (t
));
2085 get_discrete_bounds (TYPE_INDEX_TYPE (t
), &low_bound
, &high_bound
);
2087 return high_bound
== low_bound
&& is_scalar_type_recursive (elt_type
);
2089 /* Are we dealing with a struct with one element? */
2090 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
&& TYPE_NFIELDS (t
) == 1)
2091 return is_scalar_type_recursive (TYPE_FIELD_TYPE (t
, 0));
2092 else if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
2094 int i
, n
= TYPE_NFIELDS (t
);
2096 /* If all elements of the union are scalar, then the union is scalar. */
2097 for (i
= 0; i
< n
; i
++)
2098 if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t
, i
)))
2107 /* A helper function which returns true if types A and B represent the
2108 "same" class type. This is true if the types have the same main
2109 type, or the same name. */
2112 class_types_same_p (const struct type
*a
, const struct type
*b
)
2114 return (TYPE_MAIN_TYPE (a
) == TYPE_MAIN_TYPE (b
)
2115 || (TYPE_NAME (a
) && TYPE_NAME (b
)
2116 && !strcmp (TYPE_NAME (a
), TYPE_NAME (b
))));
2119 /* If BASE is an ancestor of DCLASS return the distance between them.
2120 otherwise return -1;
2124 class B: public A {};
2125 class C: public B {};
2128 distance_to_ancestor (A, A, 0) = 0
2129 distance_to_ancestor (A, B, 0) = 1
2130 distance_to_ancestor (A, C, 0) = 2
2131 distance_to_ancestor (A, D, 0) = 3
2133 If PUBLIC is 1 then only public ancestors are considered,
2134 and the function returns the distance only if BASE is a public ancestor
2138 distance_to_ancestor (A, D, 1) = -1. */
2141 distance_to_ancestor (struct type
*base
, struct type
*dclass
, int public)
2146 CHECK_TYPEDEF (base
);
2147 CHECK_TYPEDEF (dclass
);
2149 if (class_types_same_p (base
, dclass
))
2152 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2154 if (public && ! BASETYPE_VIA_PUBLIC (dclass
, i
))
2157 d
= distance_to_ancestor (base
, TYPE_BASECLASS (dclass
, i
), public);
2165 /* Check whether BASE is an ancestor or base class or DCLASS
2166 Return 1 if so, and 0 if not.
2167 Note: If BASE and DCLASS are of the same type, this function
2168 will return 1. So for some class A, is_ancestor (A, A) will
2172 is_ancestor (struct type
*base
, struct type
*dclass
)
2174 return distance_to_ancestor (base
, dclass
, 0) >= 0;
2177 /* Like is_ancestor, but only returns true when BASE is a public
2178 ancestor of DCLASS. */
2181 is_public_ancestor (struct type
*base
, struct type
*dclass
)
2183 return distance_to_ancestor (base
, dclass
, 1) >= 0;
2186 /* A helper function for is_unique_ancestor. */
2189 is_unique_ancestor_worker (struct type
*base
, struct type
*dclass
,
2191 const gdb_byte
*valaddr
, int embedded_offset
,
2192 CORE_ADDR address
, struct value
*val
)
2196 CHECK_TYPEDEF (base
);
2197 CHECK_TYPEDEF (dclass
);
2199 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
) && count
< 2; ++i
)
2204 iter
= check_typedef (TYPE_BASECLASS (dclass
, i
));
2206 this_offset
= baseclass_offset (dclass
, i
, valaddr
, embedded_offset
,
2209 if (class_types_same_p (base
, iter
))
2211 /* If this is the first subclass, set *OFFSET and set count
2212 to 1. Otherwise, if this is at the same offset as
2213 previous instances, do nothing. Otherwise, increment
2217 *offset
= this_offset
;
2220 else if (this_offset
== *offset
)
2228 count
+= is_unique_ancestor_worker (base
, iter
, offset
,
2230 embedded_offset
+ this_offset
,
2237 /* Like is_ancestor, but only returns true if BASE is a unique base
2238 class of the type of VAL. */
2241 is_unique_ancestor (struct type
*base
, struct value
*val
)
2245 return is_unique_ancestor_worker (base
, value_type (val
), &offset
,
2246 value_contents_for_printing (val
),
2247 value_embedded_offset (val
),
2248 value_address (val
), val
) == 1;
2252 /* Overload resolution. */
2254 /* Return the sum of the rank of A with the rank of B. */
2257 sum_ranks (struct rank a
, struct rank b
)
2260 c
.rank
= a
.rank
+ b
.rank
;
2261 c
.subrank
= a
.subrank
+ b
.subrank
;
2265 /* Compare rank A and B and return:
2267 1 if a is better than b
2268 -1 if b is better than a. */
2271 compare_ranks (struct rank a
, struct rank b
)
2273 if (a
.rank
== b
.rank
)
2275 if (a
.subrank
== b
.subrank
)
2277 if (a
.subrank
< b
.subrank
)
2279 if (a
.subrank
> b
.subrank
)
2283 if (a
.rank
< b
.rank
)
2286 /* a.rank > b.rank */
2290 /* Functions for overload resolution begin here. */
2292 /* Compare two badness vectors A and B and return the result.
2293 0 => A and B are identical
2294 1 => A and B are incomparable
2295 2 => A is better than B
2296 3 => A is worse than B */
2299 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2303 short found_pos
= 0; /* any positives in c? */
2304 short found_neg
= 0; /* any negatives in c? */
2306 /* differing lengths => incomparable */
2307 if (a
->length
!= b
->length
)
2310 /* Subtract b from a */
2311 for (i
= 0; i
< a
->length
; i
++)
2313 tmp
= compare_ranks (b
->rank
[i
], a
->rank
[i
]);
2323 return 1; /* incomparable */
2325 return 3; /* A > B */
2331 return 2; /* A < B */
2333 return 0; /* A == B */
2337 /* Rank a function by comparing its parameter types (PARMS, length
2338 NPARMS), to the types of an argument list (ARGS, length NARGS).
2339 Return a pointer to a badness vector. This has NARGS + 1
2342 struct badness_vector
*
2343 rank_function (struct type
**parms
, int nparms
,
2344 struct value
**args
, int nargs
)
2347 struct badness_vector
*bv
;
2348 int min_len
= nparms
< nargs
? nparms
: nargs
;
2350 bv
= xmalloc (sizeof (struct badness_vector
));
2351 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank. */
2352 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2354 /* First compare the lengths of the supplied lists.
2355 If there is a mismatch, set it to a high value. */
2357 /* pai/1997-06-03 FIXME: when we have debug info about default
2358 arguments and ellipsis parameter lists, we should consider those
2359 and rank the length-match more finely. */
2361 LENGTH_MATCH (bv
) = (nargs
!= nparms
)
2362 ? LENGTH_MISMATCH_BADNESS
2363 : EXACT_MATCH_BADNESS
;
2365 /* Now rank all the parameters of the candidate function. */
2366 for (i
= 1; i
<= min_len
; i
++)
2367 bv
->rank
[i
] = rank_one_type (parms
[i
- 1], value_type (args
[i
- 1]),
2370 /* If more arguments than parameters, add dummy entries. */
2371 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2372 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2377 /* Compare the names of two integer types, assuming that any sign
2378 qualifiers have been checked already. We do it this way because
2379 there may be an "int" in the name of one of the types. */
2382 integer_types_same_name_p (const char *first
, const char *second
)
2384 int first_p
, second_p
;
2386 /* If both are shorts, return 1; if neither is a short, keep
2388 first_p
= (strstr (first
, "short") != NULL
);
2389 second_p
= (strstr (second
, "short") != NULL
);
2390 if (first_p
&& second_p
)
2392 if (first_p
|| second_p
)
2395 /* Likewise for long. */
2396 first_p
= (strstr (first
, "long") != NULL
);
2397 second_p
= (strstr (second
, "long") != NULL
);
2398 if (first_p
&& second_p
)
2400 if (first_p
|| second_p
)
2403 /* Likewise for char. */
2404 first_p
= (strstr (first
, "char") != NULL
);
2405 second_p
= (strstr (second
, "char") != NULL
);
2406 if (first_p
&& second_p
)
2408 if (first_p
|| second_p
)
2411 /* They must both be ints. */
2415 /* Compares type A to type B returns 1 if the represent the same type
2419 types_equal (struct type
*a
, struct type
*b
)
2421 /* Identical type pointers. */
2422 /* However, this still doesn't catch all cases of same type for b
2423 and a. The reason is that builtin types are different from
2424 the same ones constructed from the object. */
2428 /* Resolve typedefs */
2429 if (TYPE_CODE (a
) == TYPE_CODE_TYPEDEF
)
2430 a
= check_typedef (a
);
2431 if (TYPE_CODE (b
) == TYPE_CODE_TYPEDEF
)
2432 b
= check_typedef (b
);
2434 /* If after resolving typedefs a and b are not of the same type
2435 code then they are not equal. */
2436 if (TYPE_CODE (a
) != TYPE_CODE (b
))
2439 /* If a and b are both pointers types or both reference types then
2440 they are equal of the same type iff the objects they refer to are
2441 of the same type. */
2442 if (TYPE_CODE (a
) == TYPE_CODE_PTR
2443 || TYPE_CODE (a
) == TYPE_CODE_REF
)
2444 return types_equal (TYPE_TARGET_TYPE (a
),
2445 TYPE_TARGET_TYPE (b
));
2447 /* Well, damnit, if the names are exactly the same, I'll say they
2448 are exactly the same. This happens when we generate method
2449 stubs. The types won't point to the same address, but they
2450 really are the same. */
2452 if (TYPE_NAME (a
) && TYPE_NAME (b
)
2453 && strcmp (TYPE_NAME (a
), TYPE_NAME (b
)) == 0)
2456 /* Check if identical after resolving typedefs. */
2460 /* Two function types are equal if their argument and return types
2462 if (TYPE_CODE (a
) == TYPE_CODE_FUNC
)
2466 if (TYPE_NFIELDS (a
) != TYPE_NFIELDS (b
))
2469 if (!types_equal (TYPE_TARGET_TYPE (a
), TYPE_TARGET_TYPE (b
)))
2472 for (i
= 0; i
< TYPE_NFIELDS (a
); ++i
)
2473 if (!types_equal (TYPE_FIELD_TYPE (a
, i
), TYPE_FIELD_TYPE (b
, i
)))
2482 /* Compare one type (PARM) for compatibility with another (ARG).
2483 * PARM is intended to be the parameter type of a function; and
2484 * ARG is the supplied argument's type. This function tests if
2485 * the latter can be converted to the former.
2486 * VALUE is the argument's value or NULL if none (or called recursively)
2488 * Return 0 if they are identical types;
2489 * Otherwise, return an integer which corresponds to how compatible
2490 * PARM is to ARG. The higher the return value, the worse the match.
2491 * Generally the "bad" conversions are all uniformly assigned a 100. */
2494 rank_one_type (struct type
*parm
, struct type
*arg
, struct value
*value
)
2496 struct rank rank
= {0,0};
2498 if (types_equal (parm
, arg
))
2499 return EXACT_MATCH_BADNESS
;
2501 /* Resolve typedefs */
2502 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2503 parm
= check_typedef (parm
);
2504 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2505 arg
= check_typedef (arg
);
2507 /* See through references, since we can almost make non-references
2509 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2510 return (sum_ranks (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
), NULL
),
2511 REFERENCE_CONVERSION_BADNESS
));
2512 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2513 return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
, NULL
),
2514 REFERENCE_CONVERSION_BADNESS
));
2516 /* Debugging only. */
2517 fprintf_filtered (gdb_stderr
,
2518 "------ Arg is %s [%d], parm is %s [%d]\n",
2519 TYPE_NAME (arg
), TYPE_CODE (arg
),
2520 TYPE_NAME (parm
), TYPE_CODE (parm
));
2522 /* x -> y means arg of type x being supplied for parameter of type y. */
2524 switch (TYPE_CODE (parm
))
2527 switch (TYPE_CODE (arg
))
2531 /* Allowed pointer conversions are:
2532 (a) pointer to void-pointer conversion. */
2533 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2534 return VOID_PTR_CONVERSION_BADNESS
;
2536 /* (b) pointer to ancestor-pointer conversion. */
2537 rank
.subrank
= distance_to_ancestor (TYPE_TARGET_TYPE (parm
),
2538 TYPE_TARGET_TYPE (arg
),
2540 if (rank
.subrank
>= 0)
2541 return sum_ranks (BASE_PTR_CONVERSION_BADNESS
, rank
);
2543 return INCOMPATIBLE_TYPE_BADNESS
;
2544 case TYPE_CODE_ARRAY
:
2545 if (types_equal (TYPE_TARGET_TYPE (parm
),
2546 TYPE_TARGET_TYPE (arg
)))
2547 return EXACT_MATCH_BADNESS
;
2548 return INCOMPATIBLE_TYPE_BADNESS
;
2549 case TYPE_CODE_FUNC
:
2550 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
, NULL
);
2552 if (value
!= NULL
&& TYPE_CODE (value_type (value
)) == TYPE_CODE_INT
)
2554 if (value_as_long (value
) == 0)
2556 /* Null pointer conversion: allow it to be cast to a pointer.
2557 [4.10.1 of C++ standard draft n3290] */
2558 return NULL_POINTER_CONVERSION_BADNESS
;
2562 /* If type checking is disabled, allow the conversion. */
2563 if (!strict_type_checking
)
2564 return NS_INTEGER_POINTER_CONVERSION_BADNESS
;
2568 case TYPE_CODE_ENUM
:
2569 case TYPE_CODE_FLAGS
:
2570 case TYPE_CODE_CHAR
:
2571 case TYPE_CODE_RANGE
:
2572 case TYPE_CODE_BOOL
:
2574 return INCOMPATIBLE_TYPE_BADNESS
;
2576 case TYPE_CODE_ARRAY
:
2577 switch (TYPE_CODE (arg
))
2580 case TYPE_CODE_ARRAY
:
2581 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2582 TYPE_TARGET_TYPE (arg
), NULL
);
2584 return INCOMPATIBLE_TYPE_BADNESS
;
2586 case TYPE_CODE_FUNC
:
2587 switch (TYPE_CODE (arg
))
2589 case TYPE_CODE_PTR
: /* funcptr -> func */
2590 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
), NULL
);
2592 return INCOMPATIBLE_TYPE_BADNESS
;
2595 switch (TYPE_CODE (arg
))
2598 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2600 /* Deal with signed, unsigned, and plain chars and
2601 signed and unsigned ints. */
2602 if (TYPE_NOSIGN (parm
))
2604 /* This case only for character types. */
2605 if (TYPE_NOSIGN (arg
))
2606 return EXACT_MATCH_BADNESS
; /* plain char -> plain char */
2607 else /* signed/unsigned char -> plain char */
2608 return INTEGER_CONVERSION_BADNESS
;
2610 else if (TYPE_UNSIGNED (parm
))
2612 if (TYPE_UNSIGNED (arg
))
2614 /* unsigned int -> unsigned int, or
2615 unsigned long -> unsigned long */
2616 if (integer_types_same_name_p (TYPE_NAME (parm
),
2618 return EXACT_MATCH_BADNESS
;
2619 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2621 && integer_types_same_name_p (TYPE_NAME (parm
),
2623 /* unsigned int -> unsigned long */
2624 return INTEGER_PROMOTION_BADNESS
;
2626 /* unsigned long -> unsigned int */
2627 return INTEGER_CONVERSION_BADNESS
;
2631 if (integer_types_same_name_p (TYPE_NAME (arg
),
2633 && integer_types_same_name_p (TYPE_NAME (parm
),
2635 /* signed long -> unsigned int */
2636 return INTEGER_CONVERSION_BADNESS
;
2638 /* signed int/long -> unsigned int/long */
2639 return INTEGER_CONVERSION_BADNESS
;
2642 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2644 if (integer_types_same_name_p (TYPE_NAME (parm
),
2646 return EXACT_MATCH_BADNESS
;
2647 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2649 && integer_types_same_name_p (TYPE_NAME (parm
),
2651 return INTEGER_PROMOTION_BADNESS
;
2653 return INTEGER_CONVERSION_BADNESS
;
2656 return INTEGER_CONVERSION_BADNESS
;
2658 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2659 return INTEGER_PROMOTION_BADNESS
;
2661 return INTEGER_CONVERSION_BADNESS
;
2662 case TYPE_CODE_ENUM
:
2663 case TYPE_CODE_FLAGS
:
2664 case TYPE_CODE_CHAR
:
2665 case TYPE_CODE_RANGE
:
2666 case TYPE_CODE_BOOL
:
2667 return INTEGER_PROMOTION_BADNESS
;
2669 return INT_FLOAT_CONVERSION_BADNESS
;
2671 return NS_POINTER_CONVERSION_BADNESS
;
2673 return INCOMPATIBLE_TYPE_BADNESS
;
2676 case TYPE_CODE_ENUM
:
2677 switch (TYPE_CODE (arg
))
2680 case TYPE_CODE_CHAR
:
2681 case TYPE_CODE_RANGE
:
2682 case TYPE_CODE_BOOL
:
2683 case TYPE_CODE_ENUM
:
2684 return INTEGER_CONVERSION_BADNESS
;
2686 return INT_FLOAT_CONVERSION_BADNESS
;
2688 return INCOMPATIBLE_TYPE_BADNESS
;
2691 case TYPE_CODE_CHAR
:
2692 switch (TYPE_CODE (arg
))
2694 case TYPE_CODE_RANGE
:
2695 case TYPE_CODE_BOOL
:
2696 case TYPE_CODE_ENUM
:
2697 return INTEGER_CONVERSION_BADNESS
;
2699 return INT_FLOAT_CONVERSION_BADNESS
;
2701 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2702 return INTEGER_CONVERSION_BADNESS
;
2703 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2704 return INTEGER_PROMOTION_BADNESS
;
2705 /* >>> !! else fall through !! <<< */
2706 case TYPE_CODE_CHAR
:
2707 /* Deal with signed, unsigned, and plain chars for C++ and
2708 with int cases falling through from previous case. */
2709 if (TYPE_NOSIGN (parm
))
2711 if (TYPE_NOSIGN (arg
))
2712 return EXACT_MATCH_BADNESS
;
2714 return INTEGER_CONVERSION_BADNESS
;
2716 else if (TYPE_UNSIGNED (parm
))
2718 if (TYPE_UNSIGNED (arg
))
2719 return EXACT_MATCH_BADNESS
;
2721 return INTEGER_PROMOTION_BADNESS
;
2723 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2724 return EXACT_MATCH_BADNESS
;
2726 return INTEGER_CONVERSION_BADNESS
;
2728 return INCOMPATIBLE_TYPE_BADNESS
;
2731 case TYPE_CODE_RANGE
:
2732 switch (TYPE_CODE (arg
))
2735 case TYPE_CODE_CHAR
:
2736 case TYPE_CODE_RANGE
:
2737 case TYPE_CODE_BOOL
:
2738 case TYPE_CODE_ENUM
:
2739 return INTEGER_CONVERSION_BADNESS
;
2741 return INT_FLOAT_CONVERSION_BADNESS
;
2743 return INCOMPATIBLE_TYPE_BADNESS
;
2746 case TYPE_CODE_BOOL
:
2747 switch (TYPE_CODE (arg
))
2749 /* n3290 draft, section 4.12.1 (conv.bool):
2751 "A prvalue of arithmetic, unscoped enumeration, pointer, or
2752 pointer to member type can be converted to a prvalue of type
2753 bool. A zero value, null pointer value, or null member pointer
2754 value is converted to false; any other value is converted to
2755 true. A prvalue of type std::nullptr_t can be converted to a
2756 prvalue of type bool; the resulting value is false." */
2758 case TYPE_CODE_CHAR
:
2759 case TYPE_CODE_ENUM
:
2761 case TYPE_CODE_MEMBERPTR
:
2763 return BOOL_CONVERSION_BADNESS
;
2764 case TYPE_CODE_RANGE
:
2765 return INCOMPATIBLE_TYPE_BADNESS
;
2766 case TYPE_CODE_BOOL
:
2767 return EXACT_MATCH_BADNESS
;
2769 return INCOMPATIBLE_TYPE_BADNESS
;
2773 switch (TYPE_CODE (arg
))
2776 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2777 return FLOAT_PROMOTION_BADNESS
;
2778 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2779 return EXACT_MATCH_BADNESS
;
2781 return FLOAT_CONVERSION_BADNESS
;
2783 case TYPE_CODE_BOOL
:
2784 case TYPE_CODE_ENUM
:
2785 case TYPE_CODE_RANGE
:
2786 case TYPE_CODE_CHAR
:
2787 return INT_FLOAT_CONVERSION_BADNESS
;
2789 return INCOMPATIBLE_TYPE_BADNESS
;
2792 case TYPE_CODE_COMPLEX
:
2793 switch (TYPE_CODE (arg
))
2794 { /* Strictly not needed for C++, but... */
2796 return FLOAT_PROMOTION_BADNESS
;
2797 case TYPE_CODE_COMPLEX
:
2798 return EXACT_MATCH_BADNESS
;
2800 return INCOMPATIBLE_TYPE_BADNESS
;
2803 case TYPE_CODE_STRUCT
:
2804 /* currently same as TYPE_CODE_CLASS. */
2805 switch (TYPE_CODE (arg
))
2807 case TYPE_CODE_STRUCT
:
2808 /* Check for derivation */
2809 rank
.subrank
= distance_to_ancestor (parm
, arg
, 0);
2810 if (rank
.subrank
>= 0)
2811 return sum_ranks (BASE_CONVERSION_BADNESS
, rank
);
2812 /* else fall through */
2814 return INCOMPATIBLE_TYPE_BADNESS
;
2817 case TYPE_CODE_UNION
:
2818 switch (TYPE_CODE (arg
))
2820 case TYPE_CODE_UNION
:
2822 return INCOMPATIBLE_TYPE_BADNESS
;
2825 case TYPE_CODE_MEMBERPTR
:
2826 switch (TYPE_CODE (arg
))
2829 return INCOMPATIBLE_TYPE_BADNESS
;
2832 case TYPE_CODE_METHOD
:
2833 switch (TYPE_CODE (arg
))
2837 return INCOMPATIBLE_TYPE_BADNESS
;
2841 switch (TYPE_CODE (arg
))
2845 return INCOMPATIBLE_TYPE_BADNESS
;
2850 switch (TYPE_CODE (arg
))
2854 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0),
2855 TYPE_FIELD_TYPE (arg
, 0), NULL
);
2857 return INCOMPATIBLE_TYPE_BADNESS
;
2860 case TYPE_CODE_VOID
:
2862 return INCOMPATIBLE_TYPE_BADNESS
;
2863 } /* switch (TYPE_CODE (arg)) */
2866 /* End of functions for overload resolution. */
2868 /* Routines to pretty-print types. */
2871 print_bit_vector (B_TYPE
*bits
, int nbits
)
2875 for (bitno
= 0; bitno
< nbits
; bitno
++)
2877 if ((bitno
% 8) == 0)
2879 puts_filtered (" ");
2881 if (B_TST (bits
, bitno
))
2882 printf_filtered (("1"));
2884 printf_filtered (("0"));
2888 /* Note the first arg should be the "this" pointer, we may not want to
2889 include it since we may get into a infinitely recursive
2893 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2899 for (i
= 0; i
< nargs
; i
++)
2900 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2905 field_is_static (struct field
*f
)
2907 /* "static" fields are the fields whose location is not relative
2908 to the address of the enclosing struct. It would be nice to
2909 have a dedicated flag that would be set for static fields when
2910 the type is being created. But in practice, checking the field
2911 loc_kind should give us an accurate answer. */
2912 return (FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSNAME
2913 || FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSADDR
);
2917 dump_fn_fieldlists (struct type
*type
, int spaces
)
2923 printfi_filtered (spaces
, "fn_fieldlists ");
2924 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2925 printf_filtered ("\n");
2926 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2928 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2929 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2931 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2932 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2934 printf_filtered (_(") length %d\n"),
2935 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2936 for (overload_idx
= 0;
2937 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2940 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2942 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2943 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2945 printf_filtered (")\n");
2946 printfi_filtered (spaces
+ 8, "type ");
2947 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2949 printf_filtered ("\n");
2951 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2954 printfi_filtered (spaces
+ 8, "args ");
2955 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2957 printf_filtered ("\n");
2959 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2960 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
,
2963 printfi_filtered (spaces
+ 8, "fcontext ");
2964 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2966 printf_filtered ("\n");
2968 printfi_filtered (spaces
+ 8, "is_const %d\n",
2969 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2970 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2971 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2972 printfi_filtered (spaces
+ 8, "is_private %d\n",
2973 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2974 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2975 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2976 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2977 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2978 printfi_filtered (spaces
+ 8, "voffset %u\n",
2979 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2985 print_cplus_stuff (struct type
*type
, int spaces
)
2987 printfi_filtered (spaces
, "n_baseclasses %d\n",
2988 TYPE_N_BASECLASSES (type
));
2989 printfi_filtered (spaces
, "nfn_fields %d\n",
2990 TYPE_NFN_FIELDS (type
));
2991 if (TYPE_N_BASECLASSES (type
) > 0)
2993 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2994 TYPE_N_BASECLASSES (type
));
2995 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
),
2997 printf_filtered (")");
2999 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
3000 TYPE_N_BASECLASSES (type
));
3001 puts_filtered ("\n");
3003 if (TYPE_NFIELDS (type
) > 0)
3005 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
3007 printfi_filtered (spaces
,
3008 "private_field_bits (%d bits at *",
3009 TYPE_NFIELDS (type
));
3010 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
),
3012 printf_filtered (")");
3013 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
3014 TYPE_NFIELDS (type
));
3015 puts_filtered ("\n");
3017 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
3019 printfi_filtered (spaces
,
3020 "protected_field_bits (%d bits at *",
3021 TYPE_NFIELDS (type
));
3022 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
),
3024 printf_filtered (")");
3025 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
3026 TYPE_NFIELDS (type
));
3027 puts_filtered ("\n");
3030 if (TYPE_NFN_FIELDS (type
) > 0)
3032 dump_fn_fieldlists (type
, spaces
);
3036 /* Print the contents of the TYPE's type_specific union, assuming that
3037 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
3040 print_gnat_stuff (struct type
*type
, int spaces
)
3042 struct type
*descriptive_type
= TYPE_DESCRIPTIVE_TYPE (type
);
3044 recursive_dump_type (descriptive_type
, spaces
+ 2);
3047 static struct obstack dont_print_type_obstack
;
3050 recursive_dump_type (struct type
*type
, int spaces
)
3055 obstack_begin (&dont_print_type_obstack
, 0);
3057 if (TYPE_NFIELDS (type
) > 0
3058 || (HAVE_CPLUS_STRUCT (type
) && TYPE_NFN_FIELDS (type
) > 0))
3060 struct type
**first_dont_print
3061 = (struct type
**) obstack_base (&dont_print_type_obstack
);
3063 int i
= (struct type
**)
3064 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
3068 if (type
== first_dont_print
[i
])
3070 printfi_filtered (spaces
, "type node ");
3071 gdb_print_host_address (type
, gdb_stdout
);
3072 printf_filtered (_(" <same as already seen type>\n"));
3077 obstack_ptr_grow (&dont_print_type_obstack
, type
);
3080 printfi_filtered (spaces
, "type node ");
3081 gdb_print_host_address (type
, gdb_stdout
);
3082 printf_filtered ("\n");
3083 printfi_filtered (spaces
, "name '%s' (",
3084 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
3085 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
3086 printf_filtered (")\n");
3087 printfi_filtered (spaces
, "tagname '%s' (",
3088 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
3089 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
3090 printf_filtered (")\n");
3091 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
3092 switch (TYPE_CODE (type
))
3094 case TYPE_CODE_UNDEF
:
3095 printf_filtered ("(TYPE_CODE_UNDEF)");
3098 printf_filtered ("(TYPE_CODE_PTR)");
3100 case TYPE_CODE_ARRAY
:
3101 printf_filtered ("(TYPE_CODE_ARRAY)");
3103 case TYPE_CODE_STRUCT
:
3104 printf_filtered ("(TYPE_CODE_STRUCT)");
3106 case TYPE_CODE_UNION
:
3107 printf_filtered ("(TYPE_CODE_UNION)");
3109 case TYPE_CODE_ENUM
:
3110 printf_filtered ("(TYPE_CODE_ENUM)");
3112 case TYPE_CODE_FLAGS
:
3113 printf_filtered ("(TYPE_CODE_FLAGS)");
3115 case TYPE_CODE_FUNC
:
3116 printf_filtered ("(TYPE_CODE_FUNC)");
3119 printf_filtered ("(TYPE_CODE_INT)");
3122 printf_filtered ("(TYPE_CODE_FLT)");
3124 case TYPE_CODE_VOID
:
3125 printf_filtered ("(TYPE_CODE_VOID)");
3128 printf_filtered ("(TYPE_CODE_SET)");
3130 case TYPE_CODE_RANGE
:
3131 printf_filtered ("(TYPE_CODE_RANGE)");
3133 case TYPE_CODE_STRING
:
3134 printf_filtered ("(TYPE_CODE_STRING)");
3136 case TYPE_CODE_ERROR
:
3137 printf_filtered ("(TYPE_CODE_ERROR)");
3139 case TYPE_CODE_MEMBERPTR
:
3140 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
3142 case TYPE_CODE_METHODPTR
:
3143 printf_filtered ("(TYPE_CODE_METHODPTR)");
3145 case TYPE_CODE_METHOD
:
3146 printf_filtered ("(TYPE_CODE_METHOD)");
3149 printf_filtered ("(TYPE_CODE_REF)");
3151 case TYPE_CODE_CHAR
:
3152 printf_filtered ("(TYPE_CODE_CHAR)");
3154 case TYPE_CODE_BOOL
:
3155 printf_filtered ("(TYPE_CODE_BOOL)");
3157 case TYPE_CODE_COMPLEX
:
3158 printf_filtered ("(TYPE_CODE_COMPLEX)");
3160 case TYPE_CODE_TYPEDEF
:
3161 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3163 case TYPE_CODE_NAMESPACE
:
3164 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3167 printf_filtered ("(UNKNOWN TYPE CODE)");
3170 puts_filtered ("\n");
3171 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
3172 if (TYPE_OBJFILE_OWNED (type
))
3174 printfi_filtered (spaces
, "objfile ");
3175 gdb_print_host_address (TYPE_OWNER (type
).objfile
, gdb_stdout
);
3179 printfi_filtered (spaces
, "gdbarch ");
3180 gdb_print_host_address (TYPE_OWNER (type
).gdbarch
, gdb_stdout
);
3182 printf_filtered ("\n");
3183 printfi_filtered (spaces
, "target_type ");
3184 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
3185 printf_filtered ("\n");
3186 if (TYPE_TARGET_TYPE (type
) != NULL
)
3188 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
3190 printfi_filtered (spaces
, "pointer_type ");
3191 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
3192 printf_filtered ("\n");
3193 printfi_filtered (spaces
, "reference_type ");
3194 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
3195 printf_filtered ("\n");
3196 printfi_filtered (spaces
, "type_chain ");
3197 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
3198 printf_filtered ("\n");
3199 printfi_filtered (spaces
, "instance_flags 0x%x",
3200 TYPE_INSTANCE_FLAGS (type
));
3201 if (TYPE_CONST (type
))
3203 puts_filtered (" TYPE_FLAG_CONST");
3205 if (TYPE_VOLATILE (type
))
3207 puts_filtered (" TYPE_FLAG_VOLATILE");
3209 if (TYPE_CODE_SPACE (type
))
3211 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3213 if (TYPE_DATA_SPACE (type
))
3215 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3217 if (TYPE_ADDRESS_CLASS_1 (type
))
3219 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3221 if (TYPE_ADDRESS_CLASS_2 (type
))
3223 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3225 if (TYPE_RESTRICT (type
))
3227 puts_filtered (" TYPE_FLAG_RESTRICT");
3229 puts_filtered ("\n");
3231 printfi_filtered (spaces
, "flags");
3232 if (TYPE_UNSIGNED (type
))
3234 puts_filtered (" TYPE_FLAG_UNSIGNED");
3236 if (TYPE_NOSIGN (type
))
3238 puts_filtered (" TYPE_FLAG_NOSIGN");
3240 if (TYPE_STUB (type
))
3242 puts_filtered (" TYPE_FLAG_STUB");
3244 if (TYPE_TARGET_STUB (type
))
3246 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3248 if (TYPE_STATIC (type
))
3250 puts_filtered (" TYPE_FLAG_STATIC");
3252 if (TYPE_PROTOTYPED (type
))
3254 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3256 if (TYPE_INCOMPLETE (type
))
3258 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3260 if (TYPE_VARARGS (type
))
3262 puts_filtered (" TYPE_FLAG_VARARGS");
3264 /* This is used for things like AltiVec registers on ppc. Gcc emits
3265 an attribute for the array type, which tells whether or not we
3266 have a vector, instead of a regular array. */
3267 if (TYPE_VECTOR (type
))
3269 puts_filtered (" TYPE_FLAG_VECTOR");
3271 if (TYPE_FIXED_INSTANCE (type
))
3273 puts_filtered (" TYPE_FIXED_INSTANCE");
3275 if (TYPE_STUB_SUPPORTED (type
))
3277 puts_filtered (" TYPE_STUB_SUPPORTED");
3279 if (TYPE_NOTTEXT (type
))
3281 puts_filtered (" TYPE_NOTTEXT");
3283 puts_filtered ("\n");
3284 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
3285 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
3286 puts_filtered ("\n");
3287 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
3289 if (TYPE_CODE (type
) == TYPE_CODE_ENUM
)
3290 printfi_filtered (spaces
+ 2,
3291 "[%d] enumval %s type ",
3292 idx
, plongest (TYPE_FIELD_ENUMVAL (type
, idx
)));
3294 printfi_filtered (spaces
+ 2,
3295 "[%d] bitpos %d bitsize %d type ",
3296 idx
, TYPE_FIELD_BITPOS (type
, idx
),
3297 TYPE_FIELD_BITSIZE (type
, idx
));
3298 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
3299 printf_filtered (" name '%s' (",
3300 TYPE_FIELD_NAME (type
, idx
) != NULL
3301 ? TYPE_FIELD_NAME (type
, idx
)
3303 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
3304 printf_filtered (")\n");
3305 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
3307 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
3310 if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
3312 printfi_filtered (spaces
, "low %s%s high %s%s\n",
3313 plongest (TYPE_LOW_BOUND (type
)),
3314 TYPE_LOW_BOUND_UNDEFINED (type
) ? " (undefined)" : "",
3315 plongest (TYPE_HIGH_BOUND (type
)),
3316 TYPE_HIGH_BOUND_UNDEFINED (type
)
3317 ? " (undefined)" : "");
3319 printfi_filtered (spaces
, "vptr_basetype ");
3320 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
3321 puts_filtered ("\n");
3322 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
3324 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
3326 printfi_filtered (spaces
, "vptr_fieldno %d\n",
3327 TYPE_VPTR_FIELDNO (type
));
3329 switch (TYPE_SPECIFIC_FIELD (type
))
3331 case TYPE_SPECIFIC_CPLUS_STUFF
:
3332 printfi_filtered (spaces
, "cplus_stuff ");
3333 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
),
3335 puts_filtered ("\n");
3336 print_cplus_stuff (type
, spaces
);
3339 case TYPE_SPECIFIC_GNAT_STUFF
:
3340 printfi_filtered (spaces
, "gnat_stuff ");
3341 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type
), gdb_stdout
);
3342 puts_filtered ("\n");
3343 print_gnat_stuff (type
, spaces
);
3346 case TYPE_SPECIFIC_FLOATFORMAT
:
3347 printfi_filtered (spaces
, "floatformat ");
3348 if (TYPE_FLOATFORMAT (type
) == NULL
)
3349 puts_filtered ("(null)");
3352 puts_filtered ("{ ");
3353 if (TYPE_FLOATFORMAT (type
)[0] == NULL
3354 || TYPE_FLOATFORMAT (type
)[0]->name
== NULL
)
3355 puts_filtered ("(null)");
3357 puts_filtered (TYPE_FLOATFORMAT (type
)[0]->name
);
3359 puts_filtered (", ");
3360 if (TYPE_FLOATFORMAT (type
)[1] == NULL
3361 || TYPE_FLOATFORMAT (type
)[1]->name
== NULL
)
3362 puts_filtered ("(null)");
3364 puts_filtered (TYPE_FLOATFORMAT (type
)[1]->name
);
3366 puts_filtered (" }");
3368 puts_filtered ("\n");
3371 case TYPE_SPECIFIC_FUNC
:
3372 printfi_filtered (spaces
, "calling_convention %d\n",
3373 TYPE_CALLING_CONVENTION (type
));
3374 /* tail_call_list is not printed. */
3379 obstack_free (&dont_print_type_obstack
, NULL
);
3382 /* Trivial helpers for the libiberty hash table, for mapping one
3387 struct type
*old
, *new;
3391 type_pair_hash (const void *item
)
3393 const struct type_pair
*pair
= item
;
3395 return htab_hash_pointer (pair
->old
);
3399 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
3401 const struct type_pair
*lhs
= item_lhs
, *rhs
= item_rhs
;
3403 return lhs
->old
== rhs
->old
;
3406 /* Allocate the hash table used by copy_type_recursive to walk
3407 types without duplicates. We use OBJFILE's obstack, because
3408 OBJFILE is about to be deleted. */
3411 create_copied_types_hash (struct objfile
*objfile
)
3413 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
3414 NULL
, &objfile
->objfile_obstack
,
3415 hashtab_obstack_allocate
,
3416 dummy_obstack_deallocate
);
3419 /* Recursively copy (deep copy) TYPE, if it is associated with
3420 OBJFILE. Return a new type allocated using malloc, a saved type if
3421 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
3422 not associated with OBJFILE. */
3425 copy_type_recursive (struct objfile
*objfile
,
3427 htab_t copied_types
)
3429 struct type_pair
*stored
, pair
;
3431 struct type
*new_type
;
3433 if (! TYPE_OBJFILE_OWNED (type
))
3436 /* This type shouldn't be pointing to any types in other objfiles;
3437 if it did, the type might disappear unexpectedly. */
3438 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
3441 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
3443 return ((struct type_pair
*) *slot
)->new;
3445 new_type
= alloc_type_arch (get_type_arch (type
));
3447 /* We must add the new type to the hash table immediately, in case
3448 we encounter this type again during a recursive call below. */
3450 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct type_pair
));
3452 stored
->new = new_type
;
3455 /* Copy the common fields of types. For the main type, we simply
3456 copy the entire thing and then update specific fields as needed. */
3457 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
3458 TYPE_OBJFILE_OWNED (new_type
) = 0;
3459 TYPE_OWNER (new_type
).gdbarch
= get_type_arch (type
);
3461 if (TYPE_NAME (type
))
3462 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
3463 if (TYPE_TAG_NAME (type
))
3464 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
3466 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
3467 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
3469 /* Copy the fields. */
3470 if (TYPE_NFIELDS (type
))
3474 nfields
= TYPE_NFIELDS (type
);
3475 TYPE_FIELDS (new_type
) = XCALLOC (nfields
, struct field
);
3476 for (i
= 0; i
< nfields
; i
++)
3478 TYPE_FIELD_ARTIFICIAL (new_type
, i
) =
3479 TYPE_FIELD_ARTIFICIAL (type
, i
);
3480 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
3481 if (TYPE_FIELD_TYPE (type
, i
))
3482 TYPE_FIELD_TYPE (new_type
, i
)
3483 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
3485 if (TYPE_FIELD_NAME (type
, i
))
3486 TYPE_FIELD_NAME (new_type
, i
) =
3487 xstrdup (TYPE_FIELD_NAME (type
, i
));
3488 switch (TYPE_FIELD_LOC_KIND (type
, i
))
3490 case FIELD_LOC_KIND_BITPOS
:
3491 SET_FIELD_BITPOS (TYPE_FIELD (new_type
, i
),
3492 TYPE_FIELD_BITPOS (type
, i
));
3494 case FIELD_LOC_KIND_ENUMVAL
:
3495 SET_FIELD_ENUMVAL (TYPE_FIELD (new_type
, i
),
3496 TYPE_FIELD_ENUMVAL (type
, i
));
3498 case FIELD_LOC_KIND_PHYSADDR
:
3499 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
3500 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
3502 case FIELD_LOC_KIND_PHYSNAME
:
3503 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
3504 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
,
3508 internal_error (__FILE__
, __LINE__
,
3509 _("Unexpected type field location kind: %d"),
3510 TYPE_FIELD_LOC_KIND (type
, i
));
3515 /* For range types, copy the bounds information. */
3516 if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
3518 TYPE_RANGE_DATA (new_type
) = xmalloc (sizeof (struct range_bounds
));
3519 *TYPE_RANGE_DATA (new_type
) = *TYPE_RANGE_DATA (type
);
3522 /* Copy pointers to other types. */
3523 if (TYPE_TARGET_TYPE (type
))
3524 TYPE_TARGET_TYPE (new_type
) =
3525 copy_type_recursive (objfile
,
3526 TYPE_TARGET_TYPE (type
),
3528 if (TYPE_VPTR_BASETYPE (type
))
3529 TYPE_VPTR_BASETYPE (new_type
) =
3530 copy_type_recursive (objfile
,
3531 TYPE_VPTR_BASETYPE (type
),
3533 /* Maybe copy the type_specific bits.
3535 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3536 base classes and methods. There's no fundamental reason why we
3537 can't, but at the moment it is not needed. */
3539 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
3540 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
3541 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3542 || TYPE_CODE (type
) == TYPE_CODE_UNION
3543 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
3544 INIT_CPLUS_SPECIFIC (new_type
);
3549 /* Make a copy of the given TYPE, except that the pointer & reference
3550 types are not preserved.
3552 This function assumes that the given type has an associated objfile.
3553 This objfile is used to allocate the new type. */
3556 copy_type (const struct type
*type
)
3558 struct type
*new_type
;
3560 gdb_assert (TYPE_OBJFILE_OWNED (type
));
3562 new_type
= alloc_type_copy (type
);
3563 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
3564 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
3565 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
3566 sizeof (struct main_type
));
3571 /* Helper functions to initialize architecture-specific types. */
3573 /* Allocate a type structure associated with GDBARCH and set its
3574 CODE, LENGTH, and NAME fields. */
3577 arch_type (struct gdbarch
*gdbarch
,
3578 enum type_code code
, int length
, char *name
)
3582 type
= alloc_type_arch (gdbarch
);
3583 TYPE_CODE (type
) = code
;
3584 TYPE_LENGTH (type
) = length
;
3587 TYPE_NAME (type
) = xstrdup (name
);
3592 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
3593 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3594 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3597 arch_integer_type (struct gdbarch
*gdbarch
,
3598 int bit
, int unsigned_p
, char *name
)
3602 t
= arch_type (gdbarch
, TYPE_CODE_INT
, bit
/ TARGET_CHAR_BIT
, name
);
3604 TYPE_UNSIGNED (t
) = 1;
3605 if (name
&& strcmp (name
, "char") == 0)
3606 TYPE_NOSIGN (t
) = 1;
3611 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
3612 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3613 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3616 arch_character_type (struct gdbarch
*gdbarch
,
3617 int bit
, int unsigned_p
, char *name
)
3621 t
= arch_type (gdbarch
, TYPE_CODE_CHAR
, bit
/ TARGET_CHAR_BIT
, name
);
3623 TYPE_UNSIGNED (t
) = 1;
3628 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
3629 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3630 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3633 arch_boolean_type (struct gdbarch
*gdbarch
,
3634 int bit
, int unsigned_p
, char *name
)
3638 t
= arch_type (gdbarch
, TYPE_CODE_BOOL
, bit
/ TARGET_CHAR_BIT
, name
);
3640 TYPE_UNSIGNED (t
) = 1;
3645 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
3646 BIT is the type size in bits; if BIT equals -1, the size is
3647 determined by the floatformat. NAME is the type name. Set the
3648 TYPE_FLOATFORMAT from FLOATFORMATS. */
3651 arch_float_type (struct gdbarch
*gdbarch
,
3652 int bit
, char *name
, const struct floatformat
**floatformats
)
3658 gdb_assert (floatformats
!= NULL
);
3659 gdb_assert (floatformats
[0] != NULL
&& floatformats
[1] != NULL
);
3660 bit
= floatformats
[0]->totalsize
;
3662 gdb_assert (bit
>= 0);
3664 t
= arch_type (gdbarch
, TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
, name
);
3665 TYPE_FLOATFORMAT (t
) = floatformats
;
3669 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
3670 NAME is the type name. TARGET_TYPE is the component float type. */
3673 arch_complex_type (struct gdbarch
*gdbarch
,
3674 char *name
, struct type
*target_type
)
3678 t
= arch_type (gdbarch
, TYPE_CODE_COMPLEX
,
3679 2 * TYPE_LENGTH (target_type
), name
);
3680 TYPE_TARGET_TYPE (t
) = target_type
;
3684 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
3685 NAME is the type name. LENGTH is the size of the flag word in bytes. */
3688 arch_flags_type (struct gdbarch
*gdbarch
, char *name
, int length
)
3690 int nfields
= length
* TARGET_CHAR_BIT
;
3693 type
= arch_type (gdbarch
, TYPE_CODE_FLAGS
, length
, name
);
3694 TYPE_UNSIGNED (type
) = 1;
3695 TYPE_NFIELDS (type
) = nfields
;
3696 TYPE_FIELDS (type
) = TYPE_ZALLOC (type
, nfields
* sizeof (struct field
));
3701 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
3702 position BITPOS is called NAME. */
3705 append_flags_type_flag (struct type
*type
, int bitpos
, char *name
)
3707 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
3708 gdb_assert (bitpos
< TYPE_NFIELDS (type
));
3709 gdb_assert (bitpos
>= 0);
3713 TYPE_FIELD_NAME (type
, bitpos
) = xstrdup (name
);
3714 SET_FIELD_BITPOS (TYPE_FIELD (type
, bitpos
), bitpos
);
3718 /* Don't show this field to the user. */
3719 SET_FIELD_BITPOS (TYPE_FIELD (type
, bitpos
), -1);
3723 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
3724 specified by CODE) associated with GDBARCH. NAME is the type name. */
3727 arch_composite_type (struct gdbarch
*gdbarch
, char *name
, enum type_code code
)
3731 gdb_assert (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
);
3732 t
= arch_type (gdbarch
, code
, 0, NULL
);
3733 TYPE_TAG_NAME (t
) = name
;
3734 INIT_CPLUS_SPECIFIC (t
);
3738 /* Add new field with name NAME and type FIELD to composite type T.
3739 Do not set the field's position or adjust the type's length;
3740 the caller should do so. Return the new field. */
3743 append_composite_type_field_raw (struct type
*t
, char *name
,
3748 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
3749 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
3750 sizeof (struct field
) * TYPE_NFIELDS (t
));
3751 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
3752 memset (f
, 0, sizeof f
[0]);
3753 FIELD_TYPE (f
[0]) = field
;
3754 FIELD_NAME (f
[0]) = name
;
3758 /* Add new field with name NAME and type FIELD to composite type T.
3759 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
3762 append_composite_type_field_aligned (struct type
*t
, char *name
,
3763 struct type
*field
, int alignment
)
3765 struct field
*f
= append_composite_type_field_raw (t
, name
, field
);
3767 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
3769 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
3770 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
3772 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
3774 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
3775 if (TYPE_NFIELDS (t
) > 1)
3777 SET_FIELD_BITPOS (f
[0],
3778 (FIELD_BITPOS (f
[-1])
3779 + (TYPE_LENGTH (FIELD_TYPE (f
[-1]))
3780 * TARGET_CHAR_BIT
)));
3786 alignment
*= TARGET_CHAR_BIT
;
3787 left
= FIELD_BITPOS (f
[0]) % alignment
;
3791 SET_FIELD_BITPOS (f
[0], FIELD_BITPOS (f
[0]) + (alignment
- left
));
3792 TYPE_LENGTH (t
) += (alignment
- left
) / TARGET_CHAR_BIT
;
3799 /* Add new field with name NAME and type FIELD to composite type T. */
3802 append_composite_type_field (struct type
*t
, char *name
,
3805 append_composite_type_field_aligned (t
, name
, field
, 0);
3808 static struct gdbarch_data
*gdbtypes_data
;
3810 const struct builtin_type
*
3811 builtin_type (struct gdbarch
*gdbarch
)
3813 return gdbarch_data (gdbarch
, gdbtypes_data
);
3817 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3819 struct builtin_type
*builtin_type
3820 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3823 builtin_type
->builtin_void
3824 = arch_type (gdbarch
, TYPE_CODE_VOID
, 1, "void");
3825 builtin_type
->builtin_char
3826 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
3827 !gdbarch_char_signed (gdbarch
), "char");
3828 builtin_type
->builtin_signed_char
3829 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
3831 builtin_type
->builtin_unsigned_char
3832 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
3833 1, "unsigned char");
3834 builtin_type
->builtin_short
3835 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
3837 builtin_type
->builtin_unsigned_short
3838 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
3839 1, "unsigned short");
3840 builtin_type
->builtin_int
3841 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
3843 builtin_type
->builtin_unsigned_int
3844 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
3846 builtin_type
->builtin_long
3847 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
3849 builtin_type
->builtin_unsigned_long
3850 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
3851 1, "unsigned long");
3852 builtin_type
->builtin_long_long
3853 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
3855 builtin_type
->builtin_unsigned_long_long
3856 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
3857 1, "unsigned long long");
3858 builtin_type
->builtin_float
3859 = arch_float_type (gdbarch
, gdbarch_float_bit (gdbarch
),
3860 "float", gdbarch_float_format (gdbarch
));
3861 builtin_type
->builtin_double
3862 = arch_float_type (gdbarch
, gdbarch_double_bit (gdbarch
),
3863 "double", gdbarch_double_format (gdbarch
));
3864 builtin_type
->builtin_long_double
3865 = arch_float_type (gdbarch
, gdbarch_long_double_bit (gdbarch
),
3866 "long double", gdbarch_long_double_format (gdbarch
));
3867 builtin_type
->builtin_complex
3868 = arch_complex_type (gdbarch
, "complex",
3869 builtin_type
->builtin_float
);
3870 builtin_type
->builtin_double_complex
3871 = arch_complex_type (gdbarch
, "double complex",
3872 builtin_type
->builtin_double
);
3873 builtin_type
->builtin_string
3874 = arch_type (gdbarch
, TYPE_CODE_STRING
, 1, "string");
3875 builtin_type
->builtin_bool
3876 = arch_type (gdbarch
, TYPE_CODE_BOOL
, 1, "bool");
3878 /* The following three are about decimal floating point types, which
3879 are 32-bits, 64-bits and 128-bits respectively. */
3880 builtin_type
->builtin_decfloat
3881 = arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, 32 / 8, "_Decimal32");
3882 builtin_type
->builtin_decdouble
3883 = arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, 64 / 8, "_Decimal64");
3884 builtin_type
->builtin_declong
3885 = arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, 128 / 8, "_Decimal128");
3887 /* "True" character types. */
3888 builtin_type
->builtin_true_char
3889 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 0, "true character");
3890 builtin_type
->builtin_true_unsigned_char
3891 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 1, "true character");
3893 /* Fixed-size integer types. */
3894 builtin_type
->builtin_int0
3895 = arch_integer_type (gdbarch
, 0, 0, "int0_t");
3896 builtin_type
->builtin_int8
3897 = arch_integer_type (gdbarch
, 8, 0, "int8_t");
3898 builtin_type
->builtin_uint8
3899 = arch_integer_type (gdbarch
, 8, 1, "uint8_t");
3900 builtin_type
->builtin_int16
3901 = arch_integer_type (gdbarch
, 16, 0, "int16_t");
3902 builtin_type
->builtin_uint16
3903 = arch_integer_type (gdbarch
, 16, 1, "uint16_t");
3904 builtin_type
->builtin_int32
3905 = arch_integer_type (gdbarch
, 32, 0, "int32_t");
3906 builtin_type
->builtin_uint32
3907 = arch_integer_type (gdbarch
, 32, 1, "uint32_t");
3908 builtin_type
->builtin_int64
3909 = arch_integer_type (gdbarch
, 64, 0, "int64_t");
3910 builtin_type
->builtin_uint64
3911 = arch_integer_type (gdbarch
, 64, 1, "uint64_t");
3912 builtin_type
->builtin_int128
3913 = arch_integer_type (gdbarch
, 128, 0, "int128_t");
3914 builtin_type
->builtin_uint128
3915 = arch_integer_type (gdbarch
, 128, 1, "uint128_t");
3916 TYPE_INSTANCE_FLAGS (builtin_type
->builtin_int8
) |=
3917 TYPE_INSTANCE_FLAG_NOTTEXT
;
3918 TYPE_INSTANCE_FLAGS (builtin_type
->builtin_uint8
) |=
3919 TYPE_INSTANCE_FLAG_NOTTEXT
;
3921 /* Wide character types. */
3922 builtin_type
->builtin_char16
3923 = arch_integer_type (gdbarch
, 16, 0, "char16_t");
3924 builtin_type
->builtin_char32
3925 = arch_integer_type (gdbarch
, 32, 0, "char32_t");
3928 /* Default data/code pointer types. */
3929 builtin_type
->builtin_data_ptr
3930 = lookup_pointer_type (builtin_type
->builtin_void
);
3931 builtin_type
->builtin_func_ptr
3932 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3933 builtin_type
->builtin_func_func
3934 = lookup_function_type (builtin_type
->builtin_func_ptr
);
3936 /* This type represents a GDB internal function. */
3937 builtin_type
->internal_fn
3938 = arch_type (gdbarch
, TYPE_CODE_INTERNAL_FUNCTION
, 0,
3939 "<internal function>");
3941 return builtin_type
;
3944 /* This set of objfile-based types is intended to be used by symbol
3945 readers as basic types. */
3947 static const struct objfile_data
*objfile_type_data
;
3949 const struct objfile_type
*
3950 objfile_type (struct objfile
*objfile
)
3952 struct gdbarch
*gdbarch
;
3953 struct objfile_type
*objfile_type
3954 = objfile_data (objfile
, objfile_type_data
);
3957 return objfile_type
;
3959 objfile_type
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3960 1, struct objfile_type
);
3962 /* Use the objfile architecture to determine basic type properties. */
3963 gdbarch
= get_objfile_arch (objfile
);
3966 objfile_type
->builtin_void
3967 = init_type (TYPE_CODE_VOID
, 1,
3971 objfile_type
->builtin_char
3972 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3974 | (gdbarch_char_signed (gdbarch
) ? 0 : TYPE_FLAG_UNSIGNED
)),
3976 objfile_type
->builtin_signed_char
3977 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3979 "signed char", objfile
);
3980 objfile_type
->builtin_unsigned_char
3981 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3983 "unsigned char", objfile
);
3984 objfile_type
->builtin_short
3985 = init_type (TYPE_CODE_INT
,
3986 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3987 0, "short", objfile
);
3988 objfile_type
->builtin_unsigned_short
3989 = init_type (TYPE_CODE_INT
,
3990 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3991 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
3992 objfile_type
->builtin_int
3993 = init_type (TYPE_CODE_INT
,
3994 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3996 objfile_type
->builtin_unsigned_int
3997 = init_type (TYPE_CODE_INT
,
3998 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3999 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
4000 objfile_type
->builtin_long
4001 = init_type (TYPE_CODE_INT
,
4002 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
4003 0, "long", objfile
);
4004 objfile_type
->builtin_unsigned_long
4005 = init_type (TYPE_CODE_INT
,
4006 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
4007 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
4008 objfile_type
->builtin_long_long
4009 = init_type (TYPE_CODE_INT
,
4010 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
4011 0, "long long", objfile
);
4012 objfile_type
->builtin_unsigned_long_long
4013 = init_type (TYPE_CODE_INT
,
4014 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
4015 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
4017 objfile_type
->builtin_float
4018 = init_type (TYPE_CODE_FLT
,
4019 gdbarch_float_bit (gdbarch
) / TARGET_CHAR_BIT
,
4020 0, "float", objfile
);
4021 TYPE_FLOATFORMAT (objfile_type
->builtin_float
)
4022 = gdbarch_float_format (gdbarch
);
4023 objfile_type
->builtin_double
4024 = init_type (TYPE_CODE_FLT
,
4025 gdbarch_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
4026 0, "double", objfile
);
4027 TYPE_FLOATFORMAT (objfile_type
->builtin_double
)
4028 = gdbarch_double_format (gdbarch
);
4029 objfile_type
->builtin_long_double
4030 = init_type (TYPE_CODE_FLT
,
4031 gdbarch_long_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
4032 0, "long double", objfile
);
4033 TYPE_FLOATFORMAT (objfile_type
->builtin_long_double
)
4034 = gdbarch_long_double_format (gdbarch
);
4036 /* This type represents a type that was unrecognized in symbol read-in. */
4037 objfile_type
->builtin_error
4038 = init_type (TYPE_CODE_ERROR
, 0, 0, "<unknown type>", objfile
);
4040 /* The following set of types is used for symbols with no
4041 debug information. */
4042 objfile_type
->nodebug_text_symbol
4043 = init_type (TYPE_CODE_FUNC
, 1, 0,
4044 "<text variable, no debug info>", objfile
);
4045 TYPE_TARGET_TYPE (objfile_type
->nodebug_text_symbol
)
4046 = objfile_type
->builtin_int
;
4047 objfile_type
->nodebug_text_gnu_ifunc_symbol
4048 = init_type (TYPE_CODE_FUNC
, 1, TYPE_FLAG_GNU_IFUNC
,
4049 "<text gnu-indirect-function variable, no debug info>",
4051 TYPE_TARGET_TYPE (objfile_type
->nodebug_text_gnu_ifunc_symbol
)
4052 = objfile_type
->nodebug_text_symbol
;
4053 objfile_type
->nodebug_got_plt_symbol
4054 = init_type (TYPE_CODE_PTR
, gdbarch_addr_bit (gdbarch
) / 8, 0,
4055 "<text from jump slot in .got.plt, no debug info>",
4057 TYPE_TARGET_TYPE (objfile_type
->nodebug_got_plt_symbol
)
4058 = objfile_type
->nodebug_text_symbol
;
4059 objfile_type
->nodebug_data_symbol
4060 = init_type (TYPE_CODE_INT
,
4061 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
4062 "<data variable, no debug info>", objfile
);
4063 objfile_type
->nodebug_unknown_symbol
4064 = init_type (TYPE_CODE_INT
, 1, 0,
4065 "<variable (not text or data), no debug info>", objfile
);
4066 objfile_type
->nodebug_tls_symbol
4067 = init_type (TYPE_CODE_INT
,
4068 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
4069 "<thread local variable, no debug info>", objfile
);
4071 /* NOTE: on some targets, addresses and pointers are not necessarily
4075 - gdb's `struct type' always describes the target's
4077 - gdb's `struct value' objects should always hold values in
4079 - gdb's CORE_ADDR values are addresses in the unified virtual
4080 address space that the assembler and linker work with. Thus,
4081 since target_read_memory takes a CORE_ADDR as an argument, it
4082 can access any memory on the target, even if the processor has
4083 separate code and data address spaces.
4085 In this context, objfile_type->builtin_core_addr is a bit odd:
4086 it's a target type for a value the target will never see. It's
4087 only used to hold the values of (typeless) linker symbols, which
4088 are indeed in the unified virtual address space. */
4090 objfile_type
->builtin_core_addr
4091 = init_type (TYPE_CODE_INT
,
4092 gdbarch_addr_bit (gdbarch
) / 8,
4093 TYPE_FLAG_UNSIGNED
, "__CORE_ADDR", objfile
);
4095 set_objfile_data (objfile
, objfile_type_data
, objfile_type
);
4096 return objfile_type
;
4099 extern initialize_file_ftype _initialize_gdbtypes
;
4102 _initialize_gdbtypes (void)
4104 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
4105 objfile_type_data
= register_objfile_data ();
4107 add_setshow_zuinteger_cmd ("overload", no_class
, &overload_debug
,
4108 _("Set debugging of C++ overloading."),
4109 _("Show debugging of C++ overloading."),
4110 _("When enabled, ranking of the "
4111 "functions is displayed."),
4113 show_overload_debug
,
4114 &setdebuglist
, &showdebuglist
);
4116 /* Add user knob for controlling resolution of opaque types. */
4117 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
4118 &opaque_type_resolution
,
4119 _("Set resolution of opaque struct/class/union"
4120 " types (if set before loading symbols)."),
4121 _("Show resolution of opaque struct/class/union"
4122 " types (if set before loading symbols)."),
4124 show_opaque_type_resolution
,
4125 &setlist
, &showlist
);
4127 /* Add an option to permit non-strict type checking. */
4128 add_setshow_boolean_cmd ("type", class_support
,
4129 &strict_type_checking
,
4130 _("Set strict type checking."),
4131 _("Show strict type checking."),
4133 show_strict_type_checking
,
4134 &setchecklist
, &showchecklist
);