1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 Contributed by Cygnus Support, using pieces from other GDB modules.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "gdb_string.h"
31 #include "expression.h"
36 #include "complaints.h"
40 #include "gdb_assert.h"
44 /* Floatformat pairs. */
45 const struct floatformat
*floatformats_ieee_half
[BFD_ENDIAN_UNKNOWN
] = {
46 &floatformat_ieee_half_big
,
47 &floatformat_ieee_half_little
49 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
50 &floatformat_ieee_single_big
,
51 &floatformat_ieee_single_little
53 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
54 &floatformat_ieee_double_big
,
55 &floatformat_ieee_double_little
57 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
58 &floatformat_ieee_double_big
,
59 &floatformat_ieee_double_littlebyte_bigword
61 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
62 &floatformat_i387_ext
,
65 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
66 &floatformat_m68881_ext
,
67 &floatformat_m68881_ext
69 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
70 &floatformat_arm_ext_big
,
71 &floatformat_arm_ext_littlebyte_bigword
73 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
74 &floatformat_ia64_spill_big
,
75 &floatformat_ia64_spill_little
77 const struct floatformat
*floatformats_ia64_quad
[BFD_ENDIAN_UNKNOWN
] = {
78 &floatformat_ia64_quad_big
,
79 &floatformat_ia64_quad_little
81 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
85 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
89 const struct floatformat
*floatformats_ibm_long_double
[BFD_ENDIAN_UNKNOWN
] = {
90 &floatformat_ibm_long_double
,
91 &floatformat_ibm_long_double
95 int opaque_type_resolution
= 1;
97 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
98 struct cmd_list_element
*c
,
101 fprintf_filtered (file
, _("\
102 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
106 int overload_debug
= 0;
108 show_overload_debug (struct ui_file
*file
, int from_tty
,
109 struct cmd_list_element
*c
, const char *value
)
111 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"),
119 }; /* Maximum extension is 128! FIXME */
121 static void print_bit_vector (B_TYPE
*, int);
122 static void print_arg_types (struct field
*, int, int);
123 static void dump_fn_fieldlists (struct type
*, int);
124 static void print_cplus_stuff (struct type
*, int);
127 /* Allocate a new OBJFILE-associated type structure and fill it
128 with some defaults. Space for the type structure is allocated
129 on the objfile's objfile_obstack. */
132 alloc_type (struct objfile
*objfile
)
136 gdb_assert (objfile
!= NULL
);
138 /* Alloc the structure and start off with all fields zeroed. */
139 type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct type
);
140 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
142 OBJSTAT (objfile
, n_types
++);
144 TYPE_OBJFILE_OWNED (type
) = 1;
145 TYPE_OWNER (type
).objfile
= objfile
;
147 /* Initialize the fields that might not be zero. */
149 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
150 TYPE_VPTR_FIELDNO (type
) = -1;
151 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
156 /* Allocate a new GDBARCH-associated type structure and fill it
157 with some defaults. Space for the type structure is allocated
161 alloc_type_arch (struct gdbarch
*gdbarch
)
165 gdb_assert (gdbarch
!= NULL
);
167 /* Alloc the structure and start off with all fields zeroed. */
169 type
= XZALLOC (struct type
);
170 TYPE_MAIN_TYPE (type
) = XZALLOC (struct main_type
);
172 TYPE_OBJFILE_OWNED (type
) = 0;
173 TYPE_OWNER (type
).gdbarch
= gdbarch
;
175 /* Initialize the fields that might not be zero. */
177 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
178 TYPE_VPTR_FIELDNO (type
) = -1;
179 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
184 /* If TYPE is objfile-associated, allocate a new type structure
185 associated with the same objfile. If TYPE is gdbarch-associated,
186 allocate a new type structure associated with the same gdbarch. */
189 alloc_type_copy (const struct type
*type
)
191 if (TYPE_OBJFILE_OWNED (type
))
192 return alloc_type (TYPE_OWNER (type
).objfile
);
194 return alloc_type_arch (TYPE_OWNER (type
).gdbarch
);
197 /* If TYPE is gdbarch-associated, return that architecture.
198 If TYPE is objfile-associated, return that objfile's architecture. */
201 get_type_arch (const struct type
*type
)
203 if (TYPE_OBJFILE_OWNED (type
))
204 return get_objfile_arch (TYPE_OWNER (type
).objfile
);
206 return TYPE_OWNER (type
).gdbarch
;
210 /* Alloc a new type instance structure, fill it with some defaults,
211 and point it at OLDTYPE. Allocate the new type instance from the
212 same place as OLDTYPE. */
215 alloc_type_instance (struct type
*oldtype
)
219 /* Allocate the structure. */
221 if (! TYPE_OBJFILE_OWNED (oldtype
))
222 type
= XZALLOC (struct type
);
224 type
= OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
227 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
229 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
234 /* Clear all remnants of the previous type at TYPE, in preparation for
235 replacing it with something else. Preserve owner information. */
237 smash_type (struct type
*type
)
239 int objfile_owned
= TYPE_OBJFILE_OWNED (type
);
240 union type_owner owner
= TYPE_OWNER (type
);
242 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
244 /* Restore owner information. */
245 TYPE_OBJFILE_OWNED (type
) = objfile_owned
;
246 TYPE_OWNER (type
) = owner
;
248 /* For now, delete the rings. */
249 TYPE_CHAIN (type
) = type
;
251 /* For now, leave the pointer/reference types alone. */
254 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
255 to a pointer to memory where the pointer type should be stored.
256 If *TYPEPTR is zero, update it to point to the pointer type we return.
257 We allocate new memory if needed. */
260 make_pointer_type (struct type
*type
, struct type
**typeptr
)
262 struct type
*ntype
; /* New type */
265 ntype
= TYPE_POINTER_TYPE (type
);
270 return ntype
; /* Don't care about alloc,
271 and have new type. */
272 else if (*typeptr
== 0)
274 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
279 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
281 ntype
= alloc_type_copy (type
);
285 else /* We have storage, but need to reset it. */
288 chain
= TYPE_CHAIN (ntype
);
290 TYPE_CHAIN (ntype
) = chain
;
293 TYPE_TARGET_TYPE (ntype
) = type
;
294 TYPE_POINTER_TYPE (type
) = ntype
;
296 /* FIXME! Assume the machine has only one representation for
300 = gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
301 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
303 /* Mark pointers as unsigned. The target converts between pointers
304 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
305 gdbarch_address_to_pointer. */
306 TYPE_UNSIGNED (ntype
) = 1;
308 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
309 TYPE_POINTER_TYPE (type
) = ntype
;
311 /* Update the length of all the other variants of this type. */
312 chain
= TYPE_CHAIN (ntype
);
313 while (chain
!= ntype
)
315 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
316 chain
= TYPE_CHAIN (chain
);
322 /* Given a type TYPE, return a type of pointers to that type.
323 May need to construct such a type if this is the first use. */
326 lookup_pointer_type (struct type
*type
)
328 return make_pointer_type (type
, (struct type
**) 0);
331 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
332 points to a pointer to memory where the reference type should be
333 stored. If *TYPEPTR is zero, update it to point to the reference
334 type we return. We allocate new memory if needed. */
337 make_reference_type (struct type
*type
, struct type
**typeptr
)
339 struct type
*ntype
; /* New type */
342 ntype
= TYPE_REFERENCE_TYPE (type
);
347 return ntype
; /* Don't care about alloc,
348 and have new type. */
349 else if (*typeptr
== 0)
351 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
356 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
358 ntype
= alloc_type_copy (type
);
362 else /* We have storage, but need to reset it. */
365 chain
= TYPE_CHAIN (ntype
);
367 TYPE_CHAIN (ntype
) = chain
;
370 TYPE_TARGET_TYPE (ntype
) = type
;
371 TYPE_REFERENCE_TYPE (type
) = ntype
;
373 /* FIXME! Assume the machine has only one representation for
374 references, and that it matches the (only) representation for
377 TYPE_LENGTH (ntype
) =
378 gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
379 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
381 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
382 TYPE_REFERENCE_TYPE (type
) = ntype
;
384 /* Update the length of all the other variants of this type. */
385 chain
= TYPE_CHAIN (ntype
);
386 while (chain
!= ntype
)
388 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
389 chain
= TYPE_CHAIN (chain
);
395 /* Same as above, but caller doesn't care about memory allocation
399 lookup_reference_type (struct type
*type
)
401 return make_reference_type (type
, (struct type
**) 0);
404 /* Lookup a function type that returns type TYPE. TYPEPTR, if
405 nonzero, points to a pointer to memory where the function type
406 should be stored. If *TYPEPTR is zero, update it to point to the
407 function type we return. We allocate new memory if needed. */
410 make_function_type (struct type
*type
, struct type
**typeptr
)
412 struct type
*ntype
; /* New type */
414 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
416 ntype
= alloc_type_copy (type
);
420 else /* We have storage, but need to reset it. */
426 TYPE_TARGET_TYPE (ntype
) = type
;
428 TYPE_LENGTH (ntype
) = 1;
429 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
435 /* Given a type TYPE, return a type of functions that return that type.
436 May need to construct such a type if this is the first use. */
439 lookup_function_type (struct type
*type
)
441 return make_function_type (type
, (struct type
**) 0);
444 /* Identify address space identifier by name --
445 return the integer flag defined in gdbtypes.h. */
447 address_space_name_to_int (struct gdbarch
*gdbarch
, char *space_identifier
)
451 /* Check for known address space delimiters. */
452 if (!strcmp (space_identifier
, "code"))
453 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
454 else if (!strcmp (space_identifier
, "data"))
455 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
456 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
457 && gdbarch_address_class_name_to_type_flags (gdbarch
,
462 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
465 /* Identify address space identifier by integer flag as defined in
466 gdbtypes.h -- return the string version of the adress space name. */
469 address_space_int_to_name (struct gdbarch
*gdbarch
, int space_flag
)
471 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
473 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
475 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
476 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
477 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
482 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
484 If STORAGE is non-NULL, create the new type instance there.
485 STORAGE must be in the same obstack as TYPE. */
488 make_qualified_type (struct type
*type
, int new_flags
,
489 struct type
*storage
)
496 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
498 ntype
= TYPE_CHAIN (ntype
);
500 while (ntype
!= type
);
502 /* Create a new type instance. */
504 ntype
= alloc_type_instance (type
);
507 /* If STORAGE was provided, it had better be in the same objfile
508 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
509 if one objfile is freed and the other kept, we'd have
510 dangling pointers. */
511 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
514 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
515 TYPE_CHAIN (ntype
) = ntype
;
518 /* Pointers or references to the original type are not relevant to
520 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
521 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
523 /* Chain the new qualified type to the old type. */
524 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
525 TYPE_CHAIN (type
) = ntype
;
527 /* Now set the instance flags and return the new type. */
528 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
530 /* Set length of new type to that of the original type. */
531 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
536 /* Make an address-space-delimited variant of a type -- a type that
537 is identical to the one supplied except that it has an address
538 space attribute attached to it (such as "code" or "data").
540 The space attributes "code" and "data" are for Harvard
541 architectures. The address space attributes are for architectures
542 which have alternately sized pointers or pointers with alternate
546 make_type_with_address_space (struct type
*type
, int space_flag
)
548 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
549 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
550 | TYPE_INSTANCE_FLAG_DATA_SPACE
551 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
554 return make_qualified_type (type
, new_flags
, NULL
);
557 /* Make a "c-v" variant of a type -- a type that is identical to the
558 one supplied except that it may have const or volatile attributes
559 CNST is a flag for setting the const attribute
560 VOLTL is a flag for setting the volatile attribute
561 TYPE is the base type whose variant we are creating.
563 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
564 storage to hold the new qualified type; *TYPEPTR and TYPE must be
565 in the same objfile. Otherwise, allocate fresh memory for the new
566 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
567 new type we construct. */
569 make_cv_type (int cnst
, int voltl
,
571 struct type
**typeptr
)
573 struct type
*ntype
; /* New type */
575 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
576 & ~(TYPE_INSTANCE_FLAG_CONST
577 | TYPE_INSTANCE_FLAG_VOLATILE
));
580 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
583 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
585 if (typeptr
&& *typeptr
!= NULL
)
587 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
588 a C-V variant chain that threads across objfiles: if one
589 objfile gets freed, then the other has a broken C-V chain.
591 This code used to try to copy over the main type from TYPE to
592 *TYPEPTR if they were in different objfiles, but that's
593 wrong, too: TYPE may have a field list or member function
594 lists, which refer to types of their own, etc. etc. The
595 whole shebang would need to be copied over recursively; you
596 can't have inter-objfile pointers. The only thing to do is
597 to leave stub types as stub types, and look them up afresh by
598 name each time you encounter them. */
599 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
602 ntype
= make_qualified_type (type
, new_flags
,
603 typeptr
? *typeptr
: NULL
);
611 /* Replace the contents of ntype with the type *type. This changes the
612 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
613 the changes are propogated to all types in the TYPE_CHAIN.
615 In order to build recursive types, it's inevitable that we'll need
616 to update types in place --- but this sort of indiscriminate
617 smashing is ugly, and needs to be replaced with something more
618 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
619 clear if more steps are needed. */
621 replace_type (struct type
*ntype
, struct type
*type
)
625 /* These two types had better be in the same objfile. Otherwise,
626 the assignment of one type's main type structure to the other
627 will produce a type with references to objects (names; field
628 lists; etc.) allocated on an objfile other than its own. */
629 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
631 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
633 /* The type length is not a part of the main type. Update it for
634 each type on the variant chain. */
638 /* Assert that this element of the chain has no address-class bits
639 set in its flags. Such type variants might have type lengths
640 which are supposed to be different from the non-address-class
641 variants. This assertion shouldn't ever be triggered because
642 symbol readers which do construct address-class variants don't
643 call replace_type(). */
644 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
646 TYPE_LENGTH (chain
) = TYPE_LENGTH (type
);
647 chain
= TYPE_CHAIN (chain
);
649 while (ntype
!= chain
);
651 /* Assert that the two types have equivalent instance qualifiers.
652 This should be true for at least all of our debug readers. */
653 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
656 /* Implement direct support for MEMBER_TYPE in GNU C++.
657 May need to construct such a type if this is the first use.
658 The TYPE is the type of the member. The DOMAIN is the type
659 of the aggregate that the member belongs to. */
662 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
666 mtype
= alloc_type_copy (type
);
667 smash_to_memberptr_type (mtype
, domain
, type
);
671 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
674 lookup_methodptr_type (struct type
*to_type
)
678 mtype
= alloc_type_copy (to_type
);
679 smash_to_methodptr_type (mtype
, to_type
);
683 /* Allocate a stub method whose return type is TYPE. This apparently
684 happens for speed of symbol reading, since parsing out the
685 arguments to the method is cpu-intensive, the way we are doing it.
686 So, we will fill in arguments later. This always returns a fresh
690 allocate_stub_method (struct type
*type
)
694 mtype
= alloc_type_copy (type
);
695 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
696 TYPE_LENGTH (mtype
) = 1;
697 TYPE_STUB (mtype
) = 1;
698 TYPE_TARGET_TYPE (mtype
) = type
;
699 /* _DOMAIN_TYPE (mtype) = unknown yet */
703 /* Create a range type using either a blank type supplied in
704 RESULT_TYPE, or creating a new type, inheriting the objfile from
707 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
708 to HIGH_BOUND, inclusive.
710 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
711 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
714 create_range_type (struct type
*result_type
, struct type
*index_type
,
715 LONGEST low_bound
, LONGEST high_bound
)
717 if (result_type
== NULL
)
718 result_type
= alloc_type_copy (index_type
);
719 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
720 TYPE_TARGET_TYPE (result_type
) = index_type
;
721 if (TYPE_STUB (index_type
))
722 TYPE_TARGET_STUB (result_type
) = 1;
724 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
725 TYPE_RANGE_DATA (result_type
) = (struct range_bounds
*)
726 TYPE_ZALLOC (result_type
, sizeof (struct range_bounds
));
727 TYPE_LOW_BOUND (result_type
) = low_bound
;
728 TYPE_HIGH_BOUND (result_type
) = high_bound
;
731 TYPE_UNSIGNED (result_type
) = 1;
736 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
737 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
738 bounds will fit in LONGEST), or -1 otherwise. */
741 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
743 CHECK_TYPEDEF (type
);
744 switch (TYPE_CODE (type
))
746 case TYPE_CODE_RANGE
:
747 *lowp
= TYPE_LOW_BOUND (type
);
748 *highp
= TYPE_HIGH_BOUND (type
);
751 if (TYPE_NFIELDS (type
) > 0)
753 /* The enums may not be sorted by value, so search all
757 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
758 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
760 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
761 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
762 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
763 *highp
= TYPE_FIELD_BITPOS (type
, i
);
766 /* Set unsigned indicator if warranted. */
769 TYPE_UNSIGNED (type
) = 1;
783 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
785 if (!TYPE_UNSIGNED (type
))
787 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
791 /* ... fall through for unsigned ints ... */
794 /* This round-about calculation is to avoid shifting by
795 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
796 if TYPE_LENGTH (type) == sizeof (LONGEST). */
797 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
798 *highp
= (*highp
- 1) | *highp
;
805 /* Create an array type using either a blank type supplied in
806 RESULT_TYPE, or creating a new type, inheriting the objfile from
809 Elements will be of type ELEMENT_TYPE, the indices will be of type
812 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
813 sure it is TYPE_CODE_UNDEF before we bash it into an array
817 create_array_type (struct type
*result_type
,
818 struct type
*element_type
,
819 struct type
*range_type
)
821 LONGEST low_bound
, high_bound
;
823 if (result_type
== NULL
)
824 result_type
= alloc_type_copy (range_type
);
826 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
827 TYPE_TARGET_TYPE (result_type
) = element_type
;
828 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
829 low_bound
= high_bound
= 0;
830 CHECK_TYPEDEF (element_type
);
831 /* Be careful when setting the array length. Ada arrays can be
832 empty arrays with the high_bound being smaller than the low_bound.
833 In such cases, the array length should be zero. */
834 if (high_bound
< low_bound
)
835 TYPE_LENGTH (result_type
) = 0;
837 TYPE_LENGTH (result_type
) =
838 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
839 TYPE_NFIELDS (result_type
) = 1;
840 TYPE_FIELDS (result_type
) =
841 (struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
));
842 TYPE_INDEX_TYPE (result_type
) = range_type
;
843 TYPE_VPTR_FIELDNO (result_type
) = -1;
845 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
846 if (TYPE_LENGTH (result_type
) == 0)
847 TYPE_TARGET_STUB (result_type
) = 1;
853 lookup_array_range_type (struct type
*element_type
,
854 int low_bound
, int high_bound
)
856 struct gdbarch
*gdbarch
= get_type_arch (element_type
);
857 struct type
*index_type
= builtin_type (gdbarch
)->builtin_int
;
858 struct type
*range_type
859 = create_range_type (NULL
, index_type
, low_bound
, high_bound
);
861 return create_array_type (NULL
, element_type
, range_type
);
864 /* Create a string type using either a blank type supplied in
865 RESULT_TYPE, or creating a new type. String types are similar
866 enough to array of char types that we can use create_array_type to
867 build the basic type and then bash it into a string type.
869 For fixed length strings, the range type contains 0 as the lower
870 bound and the length of the string minus one as the upper bound.
872 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
873 sure it is TYPE_CODE_UNDEF before we bash it into a string
877 create_string_type (struct type
*result_type
,
878 struct type
*string_char_type
,
879 struct type
*range_type
)
881 result_type
= create_array_type (result_type
,
884 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
889 lookup_string_range_type (struct type
*string_char_type
,
890 int low_bound
, int high_bound
)
892 struct type
*result_type
;
894 result_type
= lookup_array_range_type (string_char_type
,
895 low_bound
, high_bound
);
896 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
901 create_set_type (struct type
*result_type
, struct type
*domain_type
)
903 if (result_type
== NULL
)
904 result_type
= alloc_type_copy (domain_type
);
906 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
907 TYPE_NFIELDS (result_type
) = 1;
908 TYPE_FIELDS (result_type
) = TYPE_ZALLOC (result_type
, sizeof (struct field
));
910 if (!TYPE_STUB (domain_type
))
912 LONGEST low_bound
, high_bound
, bit_length
;
914 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
915 low_bound
= high_bound
= 0;
916 bit_length
= high_bound
- low_bound
+ 1;
917 TYPE_LENGTH (result_type
)
918 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
920 TYPE_UNSIGNED (result_type
) = 1;
922 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
927 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
928 and any array types nested inside it. */
931 make_vector_type (struct type
*array_type
)
933 struct type
*inner_array
, *elt_type
;
936 /* Find the innermost array type, in case the array is
937 multi-dimensional. */
938 inner_array
= array_type
;
939 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
940 inner_array
= TYPE_TARGET_TYPE (inner_array
);
942 elt_type
= TYPE_TARGET_TYPE (inner_array
);
943 if (TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
945 flags
= TYPE_INSTANCE_FLAGS (elt_type
) | TYPE_INSTANCE_FLAG_NOTTEXT
;
946 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
947 TYPE_TARGET_TYPE (inner_array
) = elt_type
;
950 TYPE_VECTOR (array_type
) = 1;
954 init_vector_type (struct type
*elt_type
, int n
)
956 struct type
*array_type
;
958 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
959 make_vector_type (array_type
);
963 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
964 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
965 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
966 TYPE doesn't include the offset (that's the value of the MEMBER
967 itself), but does include the structure type into which it points
970 When "smashing" the type, we preserve the objfile that the old type
971 pointed to, since we aren't changing where the type is actually
975 smash_to_memberptr_type (struct type
*type
, struct type
*domain
,
976 struct type
*to_type
)
979 TYPE_TARGET_TYPE (type
) = to_type
;
980 TYPE_DOMAIN_TYPE (type
) = domain
;
981 /* Assume that a data member pointer is the same size as a normal
984 = gdbarch_ptr_bit (get_type_arch (to_type
)) / TARGET_CHAR_BIT
;
985 TYPE_CODE (type
) = TYPE_CODE_MEMBERPTR
;
988 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
990 When "smashing" the type, we preserve the objfile that the old type
991 pointed to, since we aren't changing where the type is actually
995 smash_to_methodptr_type (struct type
*type
, struct type
*to_type
)
998 TYPE_TARGET_TYPE (type
) = to_type
;
999 TYPE_DOMAIN_TYPE (type
) = TYPE_DOMAIN_TYPE (to_type
);
1000 TYPE_LENGTH (type
) = cplus_method_ptr_size (to_type
);
1001 TYPE_CODE (type
) = TYPE_CODE_METHODPTR
;
1004 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1005 METHOD just means `function that gets an extra "this" argument'.
1007 When "smashing" the type, we preserve the objfile that the old type
1008 pointed to, since we aren't changing where the type is actually
1012 smash_to_method_type (struct type
*type
, struct type
*domain
,
1013 struct type
*to_type
, struct field
*args
,
1014 int nargs
, int varargs
)
1017 TYPE_TARGET_TYPE (type
) = to_type
;
1018 TYPE_DOMAIN_TYPE (type
) = domain
;
1019 TYPE_FIELDS (type
) = args
;
1020 TYPE_NFIELDS (type
) = nargs
;
1022 TYPE_VARARGS (type
) = 1;
1023 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1024 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1027 /* Return a typename for a struct/union/enum type without "struct ",
1028 "union ", or "enum ". If the type has a NULL name, return NULL. */
1031 type_name_no_tag (const struct type
*type
)
1033 if (TYPE_TAG_NAME (type
) != NULL
)
1034 return TYPE_TAG_NAME (type
);
1036 /* Is there code which expects this to return the name if there is
1037 no tag name? My guess is that this is mainly used for C++ in
1038 cases where the two will always be the same. */
1039 return TYPE_NAME (type
);
1042 /* Lookup a typedef or primitive type named NAME, visible in lexical
1043 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1044 suitably defined. */
1047 lookup_typename (const struct language_defn
*language
,
1048 struct gdbarch
*gdbarch
, char *name
,
1049 const struct block
*block
, int noerr
)
1054 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0);
1055 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1057 tmp
= language_lookup_primitive_type_by_name (language
, gdbarch
, name
);
1062 else if (!tmp
&& noerr
)
1068 error (_("No type named %s."), name
);
1071 return (SYMBOL_TYPE (sym
));
1075 lookup_unsigned_typename (const struct language_defn
*language
,
1076 struct gdbarch
*gdbarch
, char *name
)
1078 char *uns
= alloca (strlen (name
) + 10);
1080 strcpy (uns
, "unsigned ");
1081 strcpy (uns
+ 9, name
);
1082 return lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 0);
1086 lookup_signed_typename (const struct language_defn
*language
,
1087 struct gdbarch
*gdbarch
, char *name
)
1090 char *uns
= alloca (strlen (name
) + 8);
1092 strcpy (uns
, "signed ");
1093 strcpy (uns
+ 7, name
);
1094 t
= lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 1);
1095 /* If we don't find "signed FOO" just try again with plain "FOO". */
1098 return lookup_typename (language
, gdbarch
, name
, (struct block
*) NULL
, 0);
1101 /* Lookup a structure type named "struct NAME",
1102 visible in lexical block BLOCK. */
1105 lookup_struct (char *name
, struct block
*block
)
1109 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1113 error (_("No struct type named %s."), name
);
1115 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1117 error (_("This context has class, union or enum %s, not a struct."),
1120 return (SYMBOL_TYPE (sym
));
1123 /* Lookup a union type named "union NAME",
1124 visible in lexical block BLOCK. */
1127 lookup_union (char *name
, struct block
*block
)
1132 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1135 error (_("No union type named %s."), name
);
1137 t
= SYMBOL_TYPE (sym
);
1139 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1142 /* If we get here, it's not a union. */
1143 error (_("This context has class, struct or enum %s, not a union."),
1148 /* Lookup an enum type named "enum NAME",
1149 visible in lexical block BLOCK. */
1152 lookup_enum (char *name
, struct block
*block
)
1156 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1159 error (_("No enum type named %s."), name
);
1161 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1163 error (_("This context has class, struct or union %s, not an enum."),
1166 return (SYMBOL_TYPE (sym
));
1169 /* Lookup a template type named "template NAME<TYPE>",
1170 visible in lexical block BLOCK. */
1173 lookup_template_type (char *name
, struct type
*type
,
1174 struct block
*block
)
1177 char *nam
= (char *)
1178 alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1182 strcat (nam
, TYPE_NAME (type
));
1183 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1185 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0);
1189 error (_("No template type named %s."), name
);
1191 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1193 error (_("This context has class, union or enum %s, not a struct."),
1196 return (SYMBOL_TYPE (sym
));
1199 /* Given a type TYPE, lookup the type of the component of type named
1202 TYPE can be either a struct or union, or a pointer or reference to
1203 a struct or union. If it is a pointer or reference, its target
1204 type is automatically used. Thus '.' and '->' are interchangable,
1205 as specified for the definitions of the expression element types
1206 STRUCTOP_STRUCT and STRUCTOP_PTR.
1208 If NOERR is nonzero, return zero if NAME is not suitably defined.
1209 If NAME is the name of a baseclass type, return that type. */
1212 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1219 CHECK_TYPEDEF (type
);
1220 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1221 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1223 type
= TYPE_TARGET_TYPE (type
);
1226 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1227 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1229 typename
= type_to_string (type
);
1230 make_cleanup (xfree
, typename
);
1231 error (_("Type %s is not a structure or union type."), typename
);
1235 /* FIXME: This change put in by Michael seems incorrect for the case
1236 where the structure tag name is the same as the member name.
1237 I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
1238 foo; } bell;" Disabled by fnf. */
1242 typename
= type_name_no_tag (type
);
1243 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1248 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1250 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1252 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1254 return TYPE_FIELD_TYPE (type
, i
);
1256 else if (!t_field_name
|| *t_field_name
== '\0')
1258 struct type
*subtype
1259 = lookup_struct_elt_type (TYPE_FIELD_TYPE (type
, i
), name
, 1);
1261 if (subtype
!= NULL
)
1266 /* OK, it's not in this class. Recursively check the baseclasses. */
1267 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1271 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1283 typename
= type_to_string (type
);
1284 make_cleanup (xfree
, typename
);
1285 error (_("Type %s has no component named %s."), typename
, name
);
1288 /* Lookup the vptr basetype/fieldno values for TYPE.
1289 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1290 vptr_fieldno. Also, if found and basetype is from the same objfile,
1292 If not found, return -1 and ignore BASETYPEP.
1293 Callers should be aware that in some cases (for example,
1294 the type or one of its baseclasses is a stub type and we are
1295 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1296 this function will not be able to find the
1297 virtual function table pointer, and vptr_fieldno will remain -1 and
1298 vptr_basetype will remain NULL or incomplete. */
1301 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1303 CHECK_TYPEDEF (type
);
1305 if (TYPE_VPTR_FIELDNO (type
) < 0)
1309 /* We must start at zero in case the first (and only) baseclass
1310 is virtual (and hence we cannot share the table pointer). */
1311 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1313 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1315 struct type
*basetype
;
1317 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1320 /* If the type comes from a different objfile we can't cache
1321 it, it may have a different lifetime. PR 2384 */
1322 if (TYPE_OBJFILE (type
) == TYPE_OBJFILE (basetype
))
1324 TYPE_VPTR_FIELDNO (type
) = fieldno
;
1325 TYPE_VPTR_BASETYPE (type
) = basetype
;
1328 *basetypep
= basetype
;
1339 *basetypep
= TYPE_VPTR_BASETYPE (type
);
1340 return TYPE_VPTR_FIELDNO (type
);
1345 stub_noname_complaint (void)
1347 complaint (&symfile_complaints
, _("stub type has NULL name"));
1350 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1352 If this is a stubbed struct (i.e. declared as struct foo *), see if
1353 we can find a full definition in some other file. If so, copy this
1354 definition, so we can use it in future. There used to be a comment
1355 (but not any code) that if we don't find a full definition, we'd
1356 set a flag so we don't spend time in the future checking the same
1357 type. That would be a mistake, though--we might load in more
1358 symbols which contain a full definition for the type.
1360 This used to be coded as a macro, but I don't think it is called
1361 often enough to merit such treatment.
1363 Find the real type of TYPE. This function returns the real type,
1364 after removing all layers of typedefs and completing opaque or stub
1365 types. Completion changes the TYPE argument, but stripping of
1368 If TYPE is a TYPE_CODE_TYPEDEF, its length is (also) set to the length of
1369 the target type instead of zero. However, in the case of TYPE_CODE_TYPEDEF
1370 check_typedef can still return different type than the original TYPE
1374 check_typedef (struct type
*type
)
1376 struct type
*orig_type
= type
;
1377 int is_const
, is_volatile
;
1381 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1383 if (!TYPE_TARGET_TYPE (type
))
1388 /* It is dangerous to call lookup_symbol if we are currently
1389 reading a symtab. Infinite recursion is one danger. */
1390 if (currently_reading_symtab
)
1393 name
= type_name_no_tag (type
);
1394 /* FIXME: shouldn't we separately check the TYPE_NAME and
1395 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1396 VAR_DOMAIN as appropriate? (this code was written before
1397 TYPE_NAME and TYPE_TAG_NAME were separate). */
1400 stub_noname_complaint ();
1403 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1405 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1406 else /* TYPE_CODE_UNDEF */
1407 TYPE_TARGET_TYPE (type
) = alloc_type_arch (get_type_arch (type
));
1409 type
= TYPE_TARGET_TYPE (type
);
1412 is_const
= TYPE_CONST (type
);
1413 is_volatile
= TYPE_VOLATILE (type
);
1415 /* If this is a struct/class/union with no fields, then check
1416 whether a full definition exists somewhere else. This is for
1417 systems where a type definition with no fields is issued for such
1418 types, instead of identifying them as stub types in the first
1421 if (TYPE_IS_OPAQUE (type
)
1422 && opaque_type_resolution
1423 && !currently_reading_symtab
)
1425 char *name
= type_name_no_tag (type
);
1426 struct type
*newtype
;
1430 stub_noname_complaint ();
1433 newtype
= lookup_transparent_type (name
);
1437 /* If the resolved type and the stub are in the same
1438 objfile, then replace the stub type with the real deal.
1439 But if they're in separate objfiles, leave the stub
1440 alone; we'll just look up the transparent type every time
1441 we call check_typedef. We can't create pointers between
1442 types allocated to different objfiles, since they may
1443 have different lifetimes. Trying to copy NEWTYPE over to
1444 TYPE's objfile is pointless, too, since you'll have to
1445 move over any other types NEWTYPE refers to, which could
1446 be an unbounded amount of stuff. */
1447 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1448 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1453 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1455 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1457 char *name
= type_name_no_tag (type
);
1458 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1459 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1460 as appropriate? (this code was written before TYPE_NAME and
1461 TYPE_TAG_NAME were separate). */
1466 stub_noname_complaint ();
1469 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1472 /* Same as above for opaque types, we can replace the stub
1473 with the complete type only if they are int the same
1475 if (TYPE_OBJFILE (SYMBOL_TYPE(sym
)) == TYPE_OBJFILE (type
))
1476 make_cv_type (is_const
, is_volatile
,
1477 SYMBOL_TYPE (sym
), &type
);
1479 type
= SYMBOL_TYPE (sym
);
1483 if (TYPE_TARGET_STUB (type
))
1485 struct type
*range_type
;
1486 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1488 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1492 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1493 && TYPE_NFIELDS (type
) == 1
1494 && (TYPE_CODE (range_type
= TYPE_INDEX_TYPE (type
))
1495 == TYPE_CODE_RANGE
))
1497 /* Now recompute the length of the array type, based on its
1498 number of elements and the target type's length.
1499 Watch out for Ada null Ada arrays where the high bound
1500 is smaller than the low bound. */
1501 const LONGEST low_bound
= TYPE_LOW_BOUND (range_type
);
1502 const LONGEST high_bound
= TYPE_HIGH_BOUND (range_type
);
1505 if (high_bound
< low_bound
)
1509 /* For now, we conservatively take the array length to be 0
1510 if its length exceeds UINT_MAX. The code below assumes
1511 that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
1512 which is technically not guaranteed by C, but is usually true
1513 (because it would be true if x were unsigned with its
1514 high-order bit on). It uses the fact that
1515 high_bound-low_bound is always representable in
1516 ULONGEST and that if high_bound-low_bound+1 overflows,
1517 it overflows to 0. We must change these tests if we
1518 decide to increase the representation of TYPE_LENGTH
1519 from unsigned int to ULONGEST. */
1520 ULONGEST ulow
= low_bound
, uhigh
= high_bound
;
1521 ULONGEST tlen
= TYPE_LENGTH (target_type
);
1523 len
= tlen
* (uhigh
- ulow
+ 1);
1524 if (tlen
== 0 || (len
/ tlen
- 1 + ulow
) != uhigh
1528 TYPE_LENGTH (type
) = len
;
1529 TYPE_TARGET_STUB (type
) = 0;
1531 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1533 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1534 TYPE_TARGET_STUB (type
) = 0;
1537 /* Cache TYPE_LENGTH for future use. */
1538 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1542 /* Parse a type expression in the string [P..P+LENGTH). If an error
1543 occurs, silently return a void type. */
1545 static struct type
*
1546 safe_parse_type (struct gdbarch
*gdbarch
, char *p
, int length
)
1548 struct ui_file
*saved_gdb_stderr
;
1551 /* Suppress error messages. */
1552 saved_gdb_stderr
= gdb_stderr
;
1553 gdb_stderr
= ui_file_new ();
1555 /* Call parse_and_eval_type() without fear of longjmp()s. */
1556 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1557 type
= builtin_type (gdbarch
)->builtin_void
;
1559 /* Stop suppressing error messages. */
1560 ui_file_delete (gdb_stderr
);
1561 gdb_stderr
= saved_gdb_stderr
;
1566 /* Ugly hack to convert method stubs into method types.
1568 He ain't kiddin'. This demangles the name of the method into a
1569 string including argument types, parses out each argument type,
1570 generates a string casting a zero to that type, evaluates the
1571 string, and stuffs the resulting type into an argtype vector!!!
1572 Then it knows the type of the whole function (including argument
1573 types for overloading), which info used to be in the stab's but was
1574 removed to hack back the space required for them. */
1577 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1579 struct gdbarch
*gdbarch
= get_type_arch (type
);
1581 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1582 char *demangled_name
= cplus_demangle (mangled_name
,
1583 DMGL_PARAMS
| DMGL_ANSI
);
1584 char *argtypetext
, *p
;
1585 int depth
= 0, argcount
= 1;
1586 struct field
*argtypes
;
1589 /* Make sure we got back a function string that we can use. */
1591 p
= strchr (demangled_name
, '(');
1595 if (demangled_name
== NULL
|| p
== NULL
)
1596 error (_("Internal: Cannot demangle mangled name `%s'."),
1599 /* Now, read in the parameters that define this type. */
1604 if (*p
== '(' || *p
== '<')
1608 else if (*p
== ')' || *p
== '>')
1612 else if (*p
== ',' && depth
== 0)
1620 /* If we read one argument and it was ``void'', don't count it. */
1621 if (strncmp (argtypetext
, "(void)", 6) == 0)
1624 /* We need one extra slot, for the THIS pointer. */
1626 argtypes
= (struct field
*)
1627 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1630 /* Add THIS pointer for non-static methods. */
1631 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1632 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1636 argtypes
[0].type
= lookup_pointer_type (type
);
1640 if (*p
!= ')') /* () means no args, skip while */
1645 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1647 /* Avoid parsing of ellipsis, they will be handled below.
1648 Also avoid ``void'' as above. */
1649 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1650 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1652 argtypes
[argcount
].type
=
1653 safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
);
1656 argtypetext
= p
+ 1;
1659 if (*p
== '(' || *p
== '<')
1663 else if (*p
== ')' || *p
== '>')
1672 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1674 /* Now update the old "stub" type into a real type. */
1675 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1676 TYPE_DOMAIN_TYPE (mtype
) = type
;
1677 TYPE_FIELDS (mtype
) = argtypes
;
1678 TYPE_NFIELDS (mtype
) = argcount
;
1679 TYPE_STUB (mtype
) = 0;
1680 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1682 TYPE_VARARGS (mtype
) = 1;
1684 xfree (demangled_name
);
1687 /* This is the external interface to check_stub_method, above. This
1688 function unstubs all of the signatures for TYPE's METHOD_ID method
1689 name. After calling this function TYPE_FN_FIELD_STUB will be
1690 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1693 This function unfortunately can not die until stabs do. */
1696 check_stub_method_group (struct type
*type
, int method_id
)
1698 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1699 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1700 int j
, found_stub
= 0;
1702 for (j
= 0; j
< len
; j
++)
1703 if (TYPE_FN_FIELD_STUB (f
, j
))
1706 check_stub_method (type
, method_id
, j
);
1709 /* GNU v3 methods with incorrect names were corrected when we read
1710 in type information, because it was cheaper to do it then. The
1711 only GNU v2 methods with incorrect method names are operators and
1712 destructors; destructors were also corrected when we read in type
1715 Therefore the only thing we need to handle here are v2 operator
1717 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1720 char dem_opname
[256];
1722 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1724 dem_opname
, DMGL_ANSI
);
1726 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1730 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1734 /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */
1735 const struct cplus_struct_type cplus_struct_default
= { };
1738 allocate_cplus_struct_type (struct type
*type
)
1740 if (HAVE_CPLUS_STRUCT (type
))
1741 /* Structure was already allocated. Nothing more to do. */
1744 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_CPLUS_STUFF
;
1745 TYPE_RAW_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1746 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1747 *(TYPE_RAW_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1750 const struct gnat_aux_type gnat_aux_default
=
1753 /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF,
1754 and allocate the associated gnat-specific data. The gnat-specific
1755 data is also initialized to gnat_aux_default. */
1757 allocate_gnat_aux_type (struct type
*type
)
1759 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_GNAT_STUFF
;
1760 TYPE_GNAT_SPECIFIC (type
) = (struct gnat_aux_type
*)
1761 TYPE_ALLOC (type
, sizeof (struct gnat_aux_type
));
1762 *(TYPE_GNAT_SPECIFIC (type
)) = gnat_aux_default
;
1766 /* Helper function to initialize the standard scalar types.
1768 If NAME is non-NULL, then we make a copy of the string pointed
1769 to by name in the objfile_obstack for that objfile, and initialize
1770 the type name to that copy. There are places (mipsread.c in particular),
1771 where init_type is called with a NULL value for NAME). */
1774 init_type (enum type_code code
, int length
, int flags
,
1775 char *name
, struct objfile
*objfile
)
1779 type
= alloc_type (objfile
);
1780 TYPE_CODE (type
) = code
;
1781 TYPE_LENGTH (type
) = length
;
1783 gdb_assert (!(flags
& (TYPE_FLAG_MIN
- 1)));
1784 if (flags
& TYPE_FLAG_UNSIGNED
)
1785 TYPE_UNSIGNED (type
) = 1;
1786 if (flags
& TYPE_FLAG_NOSIGN
)
1787 TYPE_NOSIGN (type
) = 1;
1788 if (flags
& TYPE_FLAG_STUB
)
1789 TYPE_STUB (type
) = 1;
1790 if (flags
& TYPE_FLAG_TARGET_STUB
)
1791 TYPE_TARGET_STUB (type
) = 1;
1792 if (flags
& TYPE_FLAG_STATIC
)
1793 TYPE_STATIC (type
) = 1;
1794 if (flags
& TYPE_FLAG_PROTOTYPED
)
1795 TYPE_PROTOTYPED (type
) = 1;
1796 if (flags
& TYPE_FLAG_INCOMPLETE
)
1797 TYPE_INCOMPLETE (type
) = 1;
1798 if (flags
& TYPE_FLAG_VARARGS
)
1799 TYPE_VARARGS (type
) = 1;
1800 if (flags
& TYPE_FLAG_VECTOR
)
1801 TYPE_VECTOR (type
) = 1;
1802 if (flags
& TYPE_FLAG_STUB_SUPPORTED
)
1803 TYPE_STUB_SUPPORTED (type
) = 1;
1804 if (flags
& TYPE_FLAG_FIXED_INSTANCE
)
1805 TYPE_FIXED_INSTANCE (type
) = 1;
1808 TYPE_NAME (type
) = obsavestring (name
, strlen (name
),
1809 &objfile
->objfile_obstack
);
1813 if (name
&& strcmp (name
, "char") == 0)
1814 TYPE_NOSIGN (type
) = 1;
1818 case TYPE_CODE_STRUCT
:
1819 case TYPE_CODE_UNION
:
1820 case TYPE_CODE_NAMESPACE
:
1821 INIT_CPLUS_SPECIFIC (type
);
1824 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_FLOATFORMAT
;
1826 case TYPE_CODE_FUNC
:
1827 TYPE_SPECIFIC_FIELD (type
) = TYPE_SPECIFIC_CALLING_CONVENTION
;
1834 can_dereference (struct type
*t
)
1836 /* FIXME: Should we return true for references as well as
1841 && TYPE_CODE (t
) == TYPE_CODE_PTR
1842 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1846 is_integral_type (struct type
*t
)
1851 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1852 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1853 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
1854 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1855 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1856 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1859 /* A helper function which returns true if types A and B represent the
1860 "same" class type. This is true if the types have the same main
1861 type, or the same name. */
1864 class_types_same_p (const struct type
*a
, const struct type
*b
)
1866 return (TYPE_MAIN_TYPE (a
) == TYPE_MAIN_TYPE (b
)
1867 || (TYPE_NAME (a
) && TYPE_NAME (b
)
1868 && !strcmp (TYPE_NAME (a
), TYPE_NAME (b
))));
1871 /* Check whether BASE is an ancestor or base class of DCLASS
1872 Return 1 if so, and 0 if not. If PUBLIC is 1 then only public
1873 ancestors are considered, and the function returns 1 only if
1874 BASE is a public ancestor of DCLASS. */
1877 do_is_ancestor (struct type
*base
, struct type
*dclass
, int public)
1881 CHECK_TYPEDEF (base
);
1882 CHECK_TYPEDEF (dclass
);
1884 if (class_types_same_p (base
, dclass
))
1887 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1889 if (public && ! BASETYPE_VIA_PUBLIC (dclass
, i
))
1892 if (do_is_ancestor (base
, TYPE_BASECLASS (dclass
, i
), public))
1899 /* Check whether BASE is an ancestor or base class or DCLASS
1900 Return 1 if so, and 0 if not.
1901 Note: If BASE and DCLASS are of the same type, this function
1902 will return 1. So for some class A, is_ancestor (A, A) will
1906 is_ancestor (struct type
*base
, struct type
*dclass
)
1908 return do_is_ancestor (base
, dclass
, 0);
1911 /* Like is_ancestor, but only returns true when BASE is a public
1912 ancestor of DCLASS. */
1915 is_public_ancestor (struct type
*base
, struct type
*dclass
)
1917 return do_is_ancestor (base
, dclass
, 1);
1920 /* A helper function for is_unique_ancestor. */
1923 is_unique_ancestor_worker (struct type
*base
, struct type
*dclass
,
1925 const bfd_byte
*contents
, CORE_ADDR address
)
1929 CHECK_TYPEDEF (base
);
1930 CHECK_TYPEDEF (dclass
);
1932 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
) && count
< 2; ++i
)
1934 struct type
*iter
= check_typedef (TYPE_BASECLASS (dclass
, i
));
1935 int this_offset
= baseclass_offset (dclass
, i
, contents
, address
);
1937 if (this_offset
== -1)
1938 error (_("virtual baseclass botch"));
1940 if (class_types_same_p (base
, iter
))
1942 /* If this is the first subclass, set *OFFSET and set count
1943 to 1. Otherwise, if this is at the same offset as
1944 previous instances, do nothing. Otherwise, increment
1948 *offset
= this_offset
;
1951 else if (this_offset
== *offset
)
1959 count
+= is_unique_ancestor_worker (base
, iter
, offset
,
1960 contents
+ this_offset
,
1961 address
+ this_offset
);
1967 /* Like is_ancestor, but only returns true if BASE is a unique base
1968 class of the type of VAL. */
1971 is_unique_ancestor (struct type
*base
, struct value
*val
)
1975 return is_unique_ancestor_worker (base
, value_type (val
), &offset
,
1976 value_contents (val
),
1977 value_address (val
)) == 1;
1983 /* Functions for overload resolution begin here */
1985 /* Compare two badness vectors A and B and return the result.
1986 0 => A and B are identical
1987 1 => A and B are incomparable
1988 2 => A is better than B
1989 3 => A is worse than B */
1992 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
1996 short found_pos
= 0; /* any positives in c? */
1997 short found_neg
= 0; /* any negatives in c? */
1999 /* differing lengths => incomparable */
2000 if (a
->length
!= b
->length
)
2003 /* Subtract b from a */
2004 for (i
= 0; i
< a
->length
; i
++)
2006 tmp
= a
->rank
[i
] - b
->rank
[i
];
2016 return 1; /* incomparable */
2018 return 3; /* A > B */
2024 return 2; /* A < B */
2026 return 0; /* A == B */
2030 /* Rank a function by comparing its parameter types (PARMS, length
2031 NPARMS), to the types of an argument list (ARGS, length NARGS).
2032 Return a pointer to a badness vector. This has NARGS + 1
2035 struct badness_vector
*
2036 rank_function (struct type
**parms
, int nparms
,
2037 struct type
**args
, int nargs
)
2040 struct badness_vector
*bv
;
2041 int min_len
= nparms
< nargs
? nparms
: nargs
;
2043 bv
= xmalloc (sizeof (struct badness_vector
));
2044 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2045 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2047 /* First compare the lengths of the supplied lists.
2048 If there is a mismatch, set it to a high value. */
2050 /* pai/1997-06-03 FIXME: when we have debug info about default
2051 arguments and ellipsis parameter lists, we should consider those
2052 and rank the length-match more finely. */
2054 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2056 /* Now rank all the parameters of the candidate function */
2057 for (i
= 1; i
<= min_len
; i
++)
2058 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2060 /* If more arguments than parameters, add dummy entries */
2061 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2062 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2067 /* Compare the names of two integer types, assuming that any sign
2068 qualifiers have been checked already. We do it this way because
2069 there may be an "int" in the name of one of the types. */
2072 integer_types_same_name_p (const char *first
, const char *second
)
2074 int first_p
, second_p
;
2076 /* If both are shorts, return 1; if neither is a short, keep
2078 first_p
= (strstr (first
, "short") != NULL
);
2079 second_p
= (strstr (second
, "short") != NULL
);
2080 if (first_p
&& second_p
)
2082 if (first_p
|| second_p
)
2085 /* Likewise for long. */
2086 first_p
= (strstr (first
, "long") != NULL
);
2087 second_p
= (strstr (second
, "long") != NULL
);
2088 if (first_p
&& second_p
)
2090 if (first_p
|| second_p
)
2093 /* Likewise for char. */
2094 first_p
= (strstr (first
, "char") != NULL
);
2095 second_p
= (strstr (second
, "char") != NULL
);
2096 if (first_p
&& second_p
)
2098 if (first_p
|| second_p
)
2101 /* They must both be ints. */
2105 /* Compares type A to type B returns 1 if the represent the same type
2109 types_equal (struct type
*a
, struct type
*b
)
2111 /* Identical type pointers. */
2112 /* However, this still doesn't catch all cases of same type for b
2113 and a. The reason is that builtin types are different from
2114 the same ones constructed from the object. */
2118 /* Resolve typedefs */
2119 if (TYPE_CODE (a
) == TYPE_CODE_TYPEDEF
)
2120 a
= check_typedef (a
);
2121 if (TYPE_CODE (b
) == TYPE_CODE_TYPEDEF
)
2122 b
= check_typedef (b
);
2124 /* If after resolving typedefs a and b are not of the same type
2125 code then they are not equal. */
2126 if (TYPE_CODE (a
) != TYPE_CODE (b
))
2129 /* If a and b are both pointers types or both reference types then
2130 they are equal of the same type iff the objects they refer to are
2131 of the same type. */
2132 if (TYPE_CODE (a
) == TYPE_CODE_PTR
2133 || TYPE_CODE (a
) == TYPE_CODE_REF
)
2134 return types_equal (TYPE_TARGET_TYPE (a
),
2135 TYPE_TARGET_TYPE (b
));
2138 Well, damnit, if the names are exactly the same, I'll say they
2139 are exactly the same. This happens when we generate method
2140 stubs. The types won't point to the same address, but they
2141 really are the same.
2144 if (TYPE_NAME (a
) && TYPE_NAME (b
)
2145 && strcmp (TYPE_NAME (a
), TYPE_NAME (b
)) == 0)
2148 /* Check if identical after resolving typedefs. */
2155 /* Compare one type (PARM) for compatibility with another (ARG).
2156 * PARM is intended to be the parameter type of a function; and
2157 * ARG is the supplied argument's type. This function tests if
2158 * the latter can be converted to the former.
2160 * Return 0 if they are identical types;
2161 * Otherwise, return an integer which corresponds to how compatible
2162 * PARM is to ARG. The higher the return value, the worse the match.
2163 * Generally the "bad" conversions are all uniformly assigned a 100. */
2166 rank_one_type (struct type
*parm
, struct type
*arg
)
2169 if (types_equal (parm
, arg
))
2172 /* Resolve typedefs */
2173 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2174 parm
= check_typedef (parm
);
2175 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2176 arg
= check_typedef (arg
);
2178 /* See through references, since we can almost make non-references
2180 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2181 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2182 + REFERENCE_CONVERSION_BADNESS
);
2183 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2184 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2185 + REFERENCE_CONVERSION_BADNESS
);
2187 /* Debugging only. */
2188 fprintf_filtered (gdb_stderr
,
2189 "------ Arg is %s [%d], parm is %s [%d]\n",
2190 TYPE_NAME (arg
), TYPE_CODE (arg
),
2191 TYPE_NAME (parm
), TYPE_CODE (parm
));
2193 /* x -> y means arg of type x being supplied for parameter of type y */
2195 switch (TYPE_CODE (parm
))
2198 switch (TYPE_CODE (arg
))
2202 /* Allowed pointer conversions are:
2203 (a) pointer to void-pointer conversion. */
2204 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2205 return VOID_PTR_CONVERSION_BADNESS
;
2207 /* (b) pointer to ancestor-pointer conversion. */
2208 if (is_ancestor (TYPE_TARGET_TYPE (parm
),
2209 TYPE_TARGET_TYPE (arg
)))
2210 return BASE_PTR_CONVERSION_BADNESS
;
2212 return INCOMPATIBLE_TYPE_BADNESS
;
2213 case TYPE_CODE_ARRAY
:
2214 if (types_equal (TYPE_TARGET_TYPE (parm
),
2215 TYPE_TARGET_TYPE (arg
)))
2217 return INCOMPATIBLE_TYPE_BADNESS
;
2218 case TYPE_CODE_FUNC
:
2219 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2221 case TYPE_CODE_ENUM
:
2222 case TYPE_CODE_FLAGS
:
2223 case TYPE_CODE_CHAR
:
2224 case TYPE_CODE_RANGE
:
2225 case TYPE_CODE_BOOL
:
2226 return POINTER_CONVERSION_BADNESS
;
2228 return INCOMPATIBLE_TYPE_BADNESS
;
2230 case TYPE_CODE_ARRAY
:
2231 switch (TYPE_CODE (arg
))
2234 case TYPE_CODE_ARRAY
:
2235 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2236 TYPE_TARGET_TYPE (arg
));
2238 return INCOMPATIBLE_TYPE_BADNESS
;
2240 case TYPE_CODE_FUNC
:
2241 switch (TYPE_CODE (arg
))
2243 case TYPE_CODE_PTR
: /* funcptr -> func */
2244 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2246 return INCOMPATIBLE_TYPE_BADNESS
;
2249 switch (TYPE_CODE (arg
))
2252 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2254 /* Deal with signed, unsigned, and plain chars and
2255 signed and unsigned ints. */
2256 if (TYPE_NOSIGN (parm
))
2258 /* This case only for character types */
2259 if (TYPE_NOSIGN (arg
))
2260 return 0; /* plain char -> plain char */
2261 else /* signed/unsigned char -> plain char */
2262 return INTEGER_CONVERSION_BADNESS
;
2264 else if (TYPE_UNSIGNED (parm
))
2266 if (TYPE_UNSIGNED (arg
))
2268 /* unsigned int -> unsigned int, or
2269 unsigned long -> unsigned long */
2270 if (integer_types_same_name_p (TYPE_NAME (parm
),
2273 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2275 && integer_types_same_name_p (TYPE_NAME (parm
),
2277 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2279 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2283 if (integer_types_same_name_p (TYPE_NAME (arg
),
2285 && integer_types_same_name_p (TYPE_NAME (parm
),
2287 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2289 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2292 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2294 if (integer_types_same_name_p (TYPE_NAME (parm
),
2297 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2299 && integer_types_same_name_p (TYPE_NAME (parm
),
2301 return INTEGER_PROMOTION_BADNESS
;
2303 return INTEGER_CONVERSION_BADNESS
;
2306 return INTEGER_CONVERSION_BADNESS
;
2308 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2309 return INTEGER_PROMOTION_BADNESS
;
2311 return INTEGER_CONVERSION_BADNESS
;
2312 case TYPE_CODE_ENUM
:
2313 case TYPE_CODE_FLAGS
:
2314 case TYPE_CODE_CHAR
:
2315 case TYPE_CODE_RANGE
:
2316 case TYPE_CODE_BOOL
:
2317 return INTEGER_PROMOTION_BADNESS
;
2319 return INT_FLOAT_CONVERSION_BADNESS
;
2321 return NS_POINTER_CONVERSION_BADNESS
;
2323 return INCOMPATIBLE_TYPE_BADNESS
;
2326 case TYPE_CODE_ENUM
:
2327 switch (TYPE_CODE (arg
))
2330 case TYPE_CODE_CHAR
:
2331 case TYPE_CODE_RANGE
:
2332 case TYPE_CODE_BOOL
:
2333 case TYPE_CODE_ENUM
:
2334 return INTEGER_CONVERSION_BADNESS
;
2336 return INT_FLOAT_CONVERSION_BADNESS
;
2338 return INCOMPATIBLE_TYPE_BADNESS
;
2341 case TYPE_CODE_CHAR
:
2342 switch (TYPE_CODE (arg
))
2344 case TYPE_CODE_RANGE
:
2345 case TYPE_CODE_BOOL
:
2346 case TYPE_CODE_ENUM
:
2347 return INTEGER_CONVERSION_BADNESS
;
2349 return INT_FLOAT_CONVERSION_BADNESS
;
2351 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2352 return INTEGER_CONVERSION_BADNESS
;
2353 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2354 return INTEGER_PROMOTION_BADNESS
;
2355 /* >>> !! else fall through !! <<< */
2356 case TYPE_CODE_CHAR
:
2357 /* Deal with signed, unsigned, and plain chars for C++ and
2358 with int cases falling through from previous case. */
2359 if (TYPE_NOSIGN (parm
))
2361 if (TYPE_NOSIGN (arg
))
2364 return INTEGER_CONVERSION_BADNESS
;
2366 else if (TYPE_UNSIGNED (parm
))
2368 if (TYPE_UNSIGNED (arg
))
2371 return INTEGER_PROMOTION_BADNESS
;
2373 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2376 return INTEGER_CONVERSION_BADNESS
;
2378 return INCOMPATIBLE_TYPE_BADNESS
;
2381 case TYPE_CODE_RANGE
:
2382 switch (TYPE_CODE (arg
))
2385 case TYPE_CODE_CHAR
:
2386 case TYPE_CODE_RANGE
:
2387 case TYPE_CODE_BOOL
:
2388 case TYPE_CODE_ENUM
:
2389 return INTEGER_CONVERSION_BADNESS
;
2391 return INT_FLOAT_CONVERSION_BADNESS
;
2393 return INCOMPATIBLE_TYPE_BADNESS
;
2396 case TYPE_CODE_BOOL
:
2397 switch (TYPE_CODE (arg
))
2400 case TYPE_CODE_CHAR
:
2401 case TYPE_CODE_RANGE
:
2402 case TYPE_CODE_ENUM
:
2405 return BOOLEAN_CONVERSION_BADNESS
;
2406 case TYPE_CODE_BOOL
:
2409 return INCOMPATIBLE_TYPE_BADNESS
;
2413 switch (TYPE_CODE (arg
))
2416 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2417 return FLOAT_PROMOTION_BADNESS
;
2418 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2421 return FLOAT_CONVERSION_BADNESS
;
2423 case TYPE_CODE_BOOL
:
2424 case TYPE_CODE_ENUM
:
2425 case TYPE_CODE_RANGE
:
2426 case TYPE_CODE_CHAR
:
2427 return INT_FLOAT_CONVERSION_BADNESS
;
2429 return INCOMPATIBLE_TYPE_BADNESS
;
2432 case TYPE_CODE_COMPLEX
:
2433 switch (TYPE_CODE (arg
))
2434 { /* Strictly not needed for C++, but... */
2436 return FLOAT_PROMOTION_BADNESS
;
2437 case TYPE_CODE_COMPLEX
:
2440 return INCOMPATIBLE_TYPE_BADNESS
;
2443 case TYPE_CODE_STRUCT
:
2444 /* currently same as TYPE_CODE_CLASS */
2445 switch (TYPE_CODE (arg
))
2447 case TYPE_CODE_STRUCT
:
2448 /* Check for derivation */
2449 if (is_ancestor (parm
, arg
))
2450 return BASE_CONVERSION_BADNESS
;
2451 /* else fall through */
2453 return INCOMPATIBLE_TYPE_BADNESS
;
2456 case TYPE_CODE_UNION
:
2457 switch (TYPE_CODE (arg
))
2459 case TYPE_CODE_UNION
:
2461 return INCOMPATIBLE_TYPE_BADNESS
;
2464 case TYPE_CODE_MEMBERPTR
:
2465 switch (TYPE_CODE (arg
))
2468 return INCOMPATIBLE_TYPE_BADNESS
;
2471 case TYPE_CODE_METHOD
:
2472 switch (TYPE_CODE (arg
))
2476 return INCOMPATIBLE_TYPE_BADNESS
;
2480 switch (TYPE_CODE (arg
))
2484 return INCOMPATIBLE_TYPE_BADNESS
;
2489 switch (TYPE_CODE (arg
))
2493 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0),
2494 TYPE_FIELD_TYPE (arg
, 0));
2496 return INCOMPATIBLE_TYPE_BADNESS
;
2499 case TYPE_CODE_VOID
:
2501 return INCOMPATIBLE_TYPE_BADNESS
;
2502 } /* switch (TYPE_CODE (arg)) */
2506 /* End of functions for overload resolution */
2509 print_bit_vector (B_TYPE
*bits
, int nbits
)
2513 for (bitno
= 0; bitno
< nbits
; bitno
++)
2515 if ((bitno
% 8) == 0)
2517 puts_filtered (" ");
2519 if (B_TST (bits
, bitno
))
2520 printf_filtered (("1"));
2522 printf_filtered (("0"));
2526 /* Note the first arg should be the "this" pointer, we may not want to
2527 include it since we may get into a infinitely recursive
2531 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2537 for (i
= 0; i
< nargs
; i
++)
2538 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2543 field_is_static (struct field
*f
)
2545 /* "static" fields are the fields whose location is not relative
2546 to the address of the enclosing struct. It would be nice to
2547 have a dedicated flag that would be set for static fields when
2548 the type is being created. But in practice, checking the field
2549 loc_kind should give us an accurate answer. */
2550 return (FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSNAME
2551 || FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSADDR
);
2555 dump_fn_fieldlists (struct type
*type
, int spaces
)
2561 printfi_filtered (spaces
, "fn_fieldlists ");
2562 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2563 printf_filtered ("\n");
2564 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2566 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2567 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2569 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2570 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2572 printf_filtered (_(") length %d\n"),
2573 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2574 for (overload_idx
= 0;
2575 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2578 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2580 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2581 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2583 printf_filtered (")\n");
2584 printfi_filtered (spaces
+ 8, "type ");
2585 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2587 printf_filtered ("\n");
2589 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2592 printfi_filtered (spaces
+ 8, "args ");
2593 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2595 printf_filtered ("\n");
2597 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2598 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
,
2601 printfi_filtered (spaces
+ 8, "fcontext ");
2602 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2604 printf_filtered ("\n");
2606 printfi_filtered (spaces
+ 8, "is_const %d\n",
2607 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2608 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2609 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2610 printfi_filtered (spaces
+ 8, "is_private %d\n",
2611 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2612 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2613 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2614 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2615 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2616 printfi_filtered (spaces
+ 8, "voffset %u\n",
2617 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2623 print_cplus_stuff (struct type
*type
, int spaces
)
2625 printfi_filtered (spaces
, "n_baseclasses %d\n",
2626 TYPE_N_BASECLASSES (type
));
2627 printfi_filtered (spaces
, "nfn_fields %d\n",
2628 TYPE_NFN_FIELDS (type
));
2629 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2630 TYPE_NFN_FIELDS_TOTAL (type
));
2631 if (TYPE_N_BASECLASSES (type
) > 0)
2633 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2634 TYPE_N_BASECLASSES (type
));
2635 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
),
2637 printf_filtered (")");
2639 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2640 TYPE_N_BASECLASSES (type
));
2641 puts_filtered ("\n");
2643 if (TYPE_NFIELDS (type
) > 0)
2645 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2647 printfi_filtered (spaces
,
2648 "private_field_bits (%d bits at *",
2649 TYPE_NFIELDS (type
));
2650 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
),
2652 printf_filtered (")");
2653 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2654 TYPE_NFIELDS (type
));
2655 puts_filtered ("\n");
2657 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2659 printfi_filtered (spaces
,
2660 "protected_field_bits (%d bits at *",
2661 TYPE_NFIELDS (type
));
2662 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
),
2664 printf_filtered (")");
2665 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2666 TYPE_NFIELDS (type
));
2667 puts_filtered ("\n");
2670 if (TYPE_NFN_FIELDS (type
) > 0)
2672 dump_fn_fieldlists (type
, spaces
);
2676 /* Print the contents of the TYPE's type_specific union, assuming that
2677 its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */
2680 print_gnat_stuff (struct type
*type
, int spaces
)
2682 struct type
*descriptive_type
= TYPE_DESCRIPTIVE_TYPE (type
);
2684 recursive_dump_type (descriptive_type
, spaces
+ 2);
2687 static struct obstack dont_print_type_obstack
;
2690 recursive_dump_type (struct type
*type
, int spaces
)
2695 obstack_begin (&dont_print_type_obstack
, 0);
2697 if (TYPE_NFIELDS (type
) > 0
2698 || (HAVE_CPLUS_STRUCT (type
) && TYPE_NFN_FIELDS (type
) > 0))
2700 struct type
**first_dont_print
2701 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2703 int i
= (struct type
**)
2704 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
2708 if (type
== first_dont_print
[i
])
2710 printfi_filtered (spaces
, "type node ");
2711 gdb_print_host_address (type
, gdb_stdout
);
2712 printf_filtered (_(" <same as already seen type>\n"));
2717 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2720 printfi_filtered (spaces
, "type node ");
2721 gdb_print_host_address (type
, gdb_stdout
);
2722 printf_filtered ("\n");
2723 printfi_filtered (spaces
, "name '%s' (",
2724 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2725 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2726 printf_filtered (")\n");
2727 printfi_filtered (spaces
, "tagname '%s' (",
2728 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2729 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2730 printf_filtered (")\n");
2731 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2732 switch (TYPE_CODE (type
))
2734 case TYPE_CODE_UNDEF
:
2735 printf_filtered ("(TYPE_CODE_UNDEF)");
2738 printf_filtered ("(TYPE_CODE_PTR)");
2740 case TYPE_CODE_ARRAY
:
2741 printf_filtered ("(TYPE_CODE_ARRAY)");
2743 case TYPE_CODE_STRUCT
:
2744 printf_filtered ("(TYPE_CODE_STRUCT)");
2746 case TYPE_CODE_UNION
:
2747 printf_filtered ("(TYPE_CODE_UNION)");
2749 case TYPE_CODE_ENUM
:
2750 printf_filtered ("(TYPE_CODE_ENUM)");
2752 case TYPE_CODE_FLAGS
:
2753 printf_filtered ("(TYPE_CODE_FLAGS)");
2755 case TYPE_CODE_FUNC
:
2756 printf_filtered ("(TYPE_CODE_FUNC)");
2759 printf_filtered ("(TYPE_CODE_INT)");
2762 printf_filtered ("(TYPE_CODE_FLT)");
2764 case TYPE_CODE_VOID
:
2765 printf_filtered ("(TYPE_CODE_VOID)");
2768 printf_filtered ("(TYPE_CODE_SET)");
2770 case TYPE_CODE_RANGE
:
2771 printf_filtered ("(TYPE_CODE_RANGE)");
2773 case TYPE_CODE_STRING
:
2774 printf_filtered ("(TYPE_CODE_STRING)");
2776 case TYPE_CODE_BITSTRING
:
2777 printf_filtered ("(TYPE_CODE_BITSTRING)");
2779 case TYPE_CODE_ERROR
:
2780 printf_filtered ("(TYPE_CODE_ERROR)");
2782 case TYPE_CODE_MEMBERPTR
:
2783 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2785 case TYPE_CODE_METHODPTR
:
2786 printf_filtered ("(TYPE_CODE_METHODPTR)");
2788 case TYPE_CODE_METHOD
:
2789 printf_filtered ("(TYPE_CODE_METHOD)");
2792 printf_filtered ("(TYPE_CODE_REF)");
2794 case TYPE_CODE_CHAR
:
2795 printf_filtered ("(TYPE_CODE_CHAR)");
2797 case TYPE_CODE_BOOL
:
2798 printf_filtered ("(TYPE_CODE_BOOL)");
2800 case TYPE_CODE_COMPLEX
:
2801 printf_filtered ("(TYPE_CODE_COMPLEX)");
2803 case TYPE_CODE_TYPEDEF
:
2804 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2806 case TYPE_CODE_NAMESPACE
:
2807 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2810 printf_filtered ("(UNKNOWN TYPE CODE)");
2813 puts_filtered ("\n");
2814 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2815 if (TYPE_OBJFILE_OWNED (type
))
2817 printfi_filtered (spaces
, "objfile ");
2818 gdb_print_host_address (TYPE_OWNER (type
).objfile
, gdb_stdout
);
2822 printfi_filtered (spaces
, "gdbarch ");
2823 gdb_print_host_address (TYPE_OWNER (type
).gdbarch
, gdb_stdout
);
2825 printf_filtered ("\n");
2826 printfi_filtered (spaces
, "target_type ");
2827 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2828 printf_filtered ("\n");
2829 if (TYPE_TARGET_TYPE (type
) != NULL
)
2831 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2833 printfi_filtered (spaces
, "pointer_type ");
2834 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2835 printf_filtered ("\n");
2836 printfi_filtered (spaces
, "reference_type ");
2837 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2838 printf_filtered ("\n");
2839 printfi_filtered (spaces
, "type_chain ");
2840 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
2841 printf_filtered ("\n");
2842 printfi_filtered (spaces
, "instance_flags 0x%x",
2843 TYPE_INSTANCE_FLAGS (type
));
2844 if (TYPE_CONST (type
))
2846 puts_filtered (" TYPE_FLAG_CONST");
2848 if (TYPE_VOLATILE (type
))
2850 puts_filtered (" TYPE_FLAG_VOLATILE");
2852 if (TYPE_CODE_SPACE (type
))
2854 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2856 if (TYPE_DATA_SPACE (type
))
2858 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2860 if (TYPE_ADDRESS_CLASS_1 (type
))
2862 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
2864 if (TYPE_ADDRESS_CLASS_2 (type
))
2866 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
2868 puts_filtered ("\n");
2870 printfi_filtered (spaces
, "flags");
2871 if (TYPE_UNSIGNED (type
))
2873 puts_filtered (" TYPE_FLAG_UNSIGNED");
2875 if (TYPE_NOSIGN (type
))
2877 puts_filtered (" TYPE_FLAG_NOSIGN");
2879 if (TYPE_STUB (type
))
2881 puts_filtered (" TYPE_FLAG_STUB");
2883 if (TYPE_TARGET_STUB (type
))
2885 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2887 if (TYPE_STATIC (type
))
2889 puts_filtered (" TYPE_FLAG_STATIC");
2891 if (TYPE_PROTOTYPED (type
))
2893 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2895 if (TYPE_INCOMPLETE (type
))
2897 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2899 if (TYPE_VARARGS (type
))
2901 puts_filtered (" TYPE_FLAG_VARARGS");
2903 /* This is used for things like AltiVec registers on ppc. Gcc emits
2904 an attribute for the array type, which tells whether or not we
2905 have a vector, instead of a regular array. */
2906 if (TYPE_VECTOR (type
))
2908 puts_filtered (" TYPE_FLAG_VECTOR");
2910 if (TYPE_FIXED_INSTANCE (type
))
2912 puts_filtered (" TYPE_FIXED_INSTANCE");
2914 if (TYPE_STUB_SUPPORTED (type
))
2916 puts_filtered (" TYPE_STUB_SUPPORTED");
2918 if (TYPE_NOTTEXT (type
))
2920 puts_filtered (" TYPE_NOTTEXT");
2922 puts_filtered ("\n");
2923 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2924 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
2925 puts_filtered ("\n");
2926 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2928 printfi_filtered (spaces
+ 2,
2929 "[%d] bitpos %d bitsize %d type ",
2930 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2931 TYPE_FIELD_BITSIZE (type
, idx
));
2932 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2933 printf_filtered (" name '%s' (",
2934 TYPE_FIELD_NAME (type
, idx
) != NULL
2935 ? TYPE_FIELD_NAME (type
, idx
)
2937 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2938 printf_filtered (")\n");
2939 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2941 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2944 if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
2946 printfi_filtered (spaces
, "low %s%s high %s%s\n",
2947 plongest (TYPE_LOW_BOUND (type
)),
2948 TYPE_LOW_BOUND_UNDEFINED (type
) ? " (undefined)" : "",
2949 plongest (TYPE_HIGH_BOUND (type
)),
2950 TYPE_HIGH_BOUND_UNDEFINED (type
) ? " (undefined)" : "");
2952 printfi_filtered (spaces
, "vptr_basetype ");
2953 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2954 puts_filtered ("\n");
2955 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2957 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2959 printfi_filtered (spaces
, "vptr_fieldno %d\n",
2960 TYPE_VPTR_FIELDNO (type
));
2962 switch (TYPE_SPECIFIC_FIELD (type
))
2964 case TYPE_SPECIFIC_CPLUS_STUFF
:
2965 printfi_filtered (spaces
, "cplus_stuff ");
2966 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
),
2968 puts_filtered ("\n");
2969 print_cplus_stuff (type
, spaces
);
2972 case TYPE_SPECIFIC_GNAT_STUFF
:
2973 printfi_filtered (spaces
, "gnat_stuff ");
2974 gdb_print_host_address (TYPE_GNAT_SPECIFIC (type
), gdb_stdout
);
2975 puts_filtered ("\n");
2976 print_gnat_stuff (type
, spaces
);
2979 case TYPE_SPECIFIC_FLOATFORMAT
:
2980 printfi_filtered (spaces
, "floatformat ");
2981 if (TYPE_FLOATFORMAT (type
) == NULL
)
2982 puts_filtered ("(null)");
2985 puts_filtered ("{ ");
2986 if (TYPE_FLOATFORMAT (type
)[0] == NULL
2987 || TYPE_FLOATFORMAT (type
)[0]->name
== NULL
)
2988 puts_filtered ("(null)");
2990 puts_filtered (TYPE_FLOATFORMAT (type
)[0]->name
);
2992 puts_filtered (", ");
2993 if (TYPE_FLOATFORMAT (type
)[1] == NULL
2994 || TYPE_FLOATFORMAT (type
)[1]->name
== NULL
)
2995 puts_filtered ("(null)");
2997 puts_filtered (TYPE_FLOATFORMAT (type
)[1]->name
);
2999 puts_filtered (" }");
3001 puts_filtered ("\n");
3004 case TYPE_SPECIFIC_CALLING_CONVENTION
:
3005 printfi_filtered (spaces
, "calling_convention %d\n",
3006 TYPE_CALLING_CONVENTION (type
));
3011 obstack_free (&dont_print_type_obstack
, NULL
);
3014 /* Trivial helpers for the libiberty hash table, for mapping one
3019 struct type
*old
, *new;
3023 type_pair_hash (const void *item
)
3025 const struct type_pair
*pair
= item
;
3027 return htab_hash_pointer (pair
->old
);
3031 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
3033 const struct type_pair
*lhs
= item_lhs
, *rhs
= item_rhs
;
3035 return lhs
->old
== rhs
->old
;
3038 /* Allocate the hash table used by copy_type_recursive to walk
3039 types without duplicates. We use OBJFILE's obstack, because
3040 OBJFILE is about to be deleted. */
3043 create_copied_types_hash (struct objfile
*objfile
)
3045 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
3046 NULL
, &objfile
->objfile_obstack
,
3047 hashtab_obstack_allocate
,
3048 dummy_obstack_deallocate
);
3051 /* Recursively copy (deep copy) TYPE, if it is associated with
3052 OBJFILE. Return a new type allocated using malloc, a saved type if
3053 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
3054 not associated with OBJFILE. */
3057 copy_type_recursive (struct objfile
*objfile
,
3059 htab_t copied_types
)
3061 struct type_pair
*stored
, pair
;
3063 struct type
*new_type
;
3065 if (! TYPE_OBJFILE_OWNED (type
))
3068 /* This type shouldn't be pointing to any types in other objfiles;
3069 if it did, the type might disappear unexpectedly. */
3070 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
3073 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
3075 return ((struct type_pair
*) *slot
)->new;
3077 new_type
= alloc_type_arch (get_type_arch (type
));
3079 /* We must add the new type to the hash table immediately, in case
3080 we encounter this type again during a recursive call below. */
3081 stored
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct type_pair
));
3083 stored
->new = new_type
;
3086 /* Copy the common fields of types. For the main type, we simply
3087 copy the entire thing and then update specific fields as needed. */
3088 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
3089 TYPE_OBJFILE_OWNED (new_type
) = 0;
3090 TYPE_OWNER (new_type
).gdbarch
= get_type_arch (type
);
3092 if (TYPE_NAME (type
))
3093 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
3094 if (TYPE_TAG_NAME (type
))
3095 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
3097 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
3098 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
3100 /* Copy the fields. */
3101 if (TYPE_NFIELDS (type
))
3105 nfields
= TYPE_NFIELDS (type
);
3106 TYPE_FIELDS (new_type
) = XCALLOC (nfields
, struct field
);
3107 for (i
= 0; i
< nfields
; i
++)
3109 TYPE_FIELD_ARTIFICIAL (new_type
, i
) =
3110 TYPE_FIELD_ARTIFICIAL (type
, i
);
3111 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
3112 if (TYPE_FIELD_TYPE (type
, i
))
3113 TYPE_FIELD_TYPE (new_type
, i
)
3114 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
3116 if (TYPE_FIELD_NAME (type
, i
))
3117 TYPE_FIELD_NAME (new_type
, i
) =
3118 xstrdup (TYPE_FIELD_NAME (type
, i
));
3119 switch (TYPE_FIELD_LOC_KIND (type
, i
))
3121 case FIELD_LOC_KIND_BITPOS
:
3122 SET_FIELD_BITPOS (TYPE_FIELD (new_type
, i
),
3123 TYPE_FIELD_BITPOS (type
, i
));
3125 case FIELD_LOC_KIND_PHYSADDR
:
3126 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
3127 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
3129 case FIELD_LOC_KIND_PHYSNAME
:
3130 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
3131 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
,
3135 internal_error (__FILE__
, __LINE__
,
3136 _("Unexpected type field location kind: %d"),
3137 TYPE_FIELD_LOC_KIND (type
, i
));
3142 /* For range types, copy the bounds information. */
3143 if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
3145 TYPE_RANGE_DATA (new_type
) = xmalloc (sizeof (struct range_bounds
));
3146 *TYPE_RANGE_DATA (new_type
) = *TYPE_RANGE_DATA (type
);
3149 /* Copy pointers to other types. */
3150 if (TYPE_TARGET_TYPE (type
))
3151 TYPE_TARGET_TYPE (new_type
) =
3152 copy_type_recursive (objfile
,
3153 TYPE_TARGET_TYPE (type
),
3155 if (TYPE_VPTR_BASETYPE (type
))
3156 TYPE_VPTR_BASETYPE (new_type
) =
3157 copy_type_recursive (objfile
,
3158 TYPE_VPTR_BASETYPE (type
),
3160 /* Maybe copy the type_specific bits.
3162 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3163 base classes and methods. There's no fundamental reason why we
3164 can't, but at the moment it is not needed. */
3166 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
3167 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
3168 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3169 || TYPE_CODE (type
) == TYPE_CODE_UNION
3170 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
3171 INIT_CPLUS_SPECIFIC (new_type
);
3176 /* Make a copy of the given TYPE, except that the pointer & reference
3177 types are not preserved.
3179 This function assumes that the given type has an associated objfile.
3180 This objfile is used to allocate the new type. */
3183 copy_type (const struct type
*type
)
3185 struct type
*new_type
;
3187 gdb_assert (TYPE_OBJFILE_OWNED (type
));
3189 new_type
= alloc_type_copy (type
);
3190 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
3191 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
3192 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
3193 sizeof (struct main_type
));
3199 /* Helper functions to initialize architecture-specific types. */
3201 /* Allocate a type structure associated with GDBARCH and set its
3202 CODE, LENGTH, and NAME fields. */
3204 arch_type (struct gdbarch
*gdbarch
,
3205 enum type_code code
, int length
, char *name
)
3209 type
= alloc_type_arch (gdbarch
);
3210 TYPE_CODE (type
) = code
;
3211 TYPE_LENGTH (type
) = length
;
3214 TYPE_NAME (type
) = xstrdup (name
);
3219 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
3220 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3221 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3223 arch_integer_type (struct gdbarch
*gdbarch
,
3224 int bit
, int unsigned_p
, char *name
)
3228 t
= arch_type (gdbarch
, TYPE_CODE_INT
, bit
/ TARGET_CHAR_BIT
, name
);
3230 TYPE_UNSIGNED (t
) = 1;
3231 if (name
&& strcmp (name
, "char") == 0)
3232 TYPE_NOSIGN (t
) = 1;
3237 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
3238 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3239 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3241 arch_character_type (struct gdbarch
*gdbarch
,
3242 int bit
, int unsigned_p
, char *name
)
3246 t
= arch_type (gdbarch
, TYPE_CODE_CHAR
, bit
/ TARGET_CHAR_BIT
, name
);
3248 TYPE_UNSIGNED (t
) = 1;
3253 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
3254 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3255 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3257 arch_boolean_type (struct gdbarch
*gdbarch
,
3258 int bit
, int unsigned_p
, char *name
)
3262 t
= arch_type (gdbarch
, TYPE_CODE_BOOL
, bit
/ TARGET_CHAR_BIT
, name
);
3264 TYPE_UNSIGNED (t
) = 1;
3269 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
3270 BIT is the type size in bits; if BIT equals -1, the size is
3271 determined by the floatformat. NAME is the type name. Set the
3272 TYPE_FLOATFORMAT from FLOATFORMATS. */
3274 arch_float_type (struct gdbarch
*gdbarch
,
3275 int bit
, char *name
, const struct floatformat
**floatformats
)
3281 gdb_assert (floatformats
!= NULL
);
3282 gdb_assert (floatformats
[0] != NULL
&& floatformats
[1] != NULL
);
3283 bit
= floatformats
[0]->totalsize
;
3285 gdb_assert (bit
>= 0);
3287 t
= arch_type (gdbarch
, TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
, name
);
3288 TYPE_FLOATFORMAT (t
) = floatformats
;
3292 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
3293 NAME is the type name. TARGET_TYPE is the component float type. */
3295 arch_complex_type (struct gdbarch
*gdbarch
,
3296 char *name
, struct type
*target_type
)
3300 t
= arch_type (gdbarch
, TYPE_CODE_COMPLEX
,
3301 2 * TYPE_LENGTH (target_type
), name
);
3302 TYPE_TARGET_TYPE (t
) = target_type
;
3306 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
3307 NAME is the type name. LENGTH is the size of the flag word in bytes. */
3309 arch_flags_type (struct gdbarch
*gdbarch
, char *name
, int length
)
3311 int nfields
= length
* TARGET_CHAR_BIT
;
3314 type
= arch_type (gdbarch
, TYPE_CODE_FLAGS
, length
, name
);
3315 TYPE_UNSIGNED (type
) = 1;
3316 TYPE_NFIELDS (type
) = nfields
;
3317 TYPE_FIELDS (type
) = TYPE_ZALLOC (type
, nfields
* sizeof (struct field
));
3322 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
3323 position BITPOS is called NAME. */
3325 append_flags_type_flag (struct type
*type
, int bitpos
, char *name
)
3327 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
3328 gdb_assert (bitpos
< TYPE_NFIELDS (type
));
3329 gdb_assert (bitpos
>= 0);
3333 TYPE_FIELD_NAME (type
, bitpos
) = xstrdup (name
);
3334 TYPE_FIELD_BITPOS (type
, bitpos
) = bitpos
;
3338 /* Don't show this field to the user. */
3339 TYPE_FIELD_BITPOS (type
, bitpos
) = -1;
3343 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
3344 specified by CODE) associated with GDBARCH. NAME is the type name. */
3346 arch_composite_type (struct gdbarch
*gdbarch
, char *name
, enum type_code code
)
3350 gdb_assert (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
);
3351 t
= arch_type (gdbarch
, code
, 0, NULL
);
3352 TYPE_TAG_NAME (t
) = name
;
3353 INIT_CPLUS_SPECIFIC (t
);
3357 /* Add new field with name NAME and type FIELD to composite type T.
3358 Do not set the field's position or adjust the type's length;
3359 the caller should do so. Return the new field. */
3361 append_composite_type_field_raw (struct type
*t
, char *name
,
3366 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
3367 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
3368 sizeof (struct field
) * TYPE_NFIELDS (t
));
3369 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
3370 memset (f
, 0, sizeof f
[0]);
3371 FIELD_TYPE (f
[0]) = field
;
3372 FIELD_NAME (f
[0]) = name
;
3376 /* Add new field with name NAME and type FIELD to composite type T.
3377 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
3379 append_composite_type_field_aligned (struct type
*t
, char *name
,
3380 struct type
*field
, int alignment
)
3382 struct field
*f
= append_composite_type_field_raw (t
, name
, field
);
3384 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
3386 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
3387 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
3389 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
3391 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
3392 if (TYPE_NFIELDS (t
) > 1)
3394 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
3395 + (TYPE_LENGTH (FIELD_TYPE (f
[-1]))
3396 * TARGET_CHAR_BIT
));
3400 int left
= FIELD_BITPOS (f
[0]) % (alignment
* TARGET_CHAR_BIT
);
3404 FIELD_BITPOS (f
[0]) += left
;
3405 TYPE_LENGTH (t
) += left
/ TARGET_CHAR_BIT
;
3412 /* Add new field with name NAME and type FIELD to composite type T. */
3414 append_composite_type_field (struct type
*t
, char *name
,
3417 append_composite_type_field_aligned (t
, name
, field
, 0);
3421 static struct gdbarch_data
*gdbtypes_data
;
3423 const struct builtin_type
*
3424 builtin_type (struct gdbarch
*gdbarch
)
3426 return gdbarch_data (gdbarch
, gdbtypes_data
);
3430 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3432 struct builtin_type
*builtin_type
3433 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3436 builtin_type
->builtin_void
3437 = arch_type (gdbarch
, TYPE_CODE_VOID
, 1, "void");
3438 builtin_type
->builtin_char
3439 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
3440 !gdbarch_char_signed (gdbarch
), "char");
3441 builtin_type
->builtin_signed_char
3442 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
3444 builtin_type
->builtin_unsigned_char
3445 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
3446 1, "unsigned char");
3447 builtin_type
->builtin_short
3448 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
3450 builtin_type
->builtin_unsigned_short
3451 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
3452 1, "unsigned short");
3453 builtin_type
->builtin_int
3454 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
3456 builtin_type
->builtin_unsigned_int
3457 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
3459 builtin_type
->builtin_long
3460 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
3462 builtin_type
->builtin_unsigned_long
3463 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
3464 1, "unsigned long");
3465 builtin_type
->builtin_long_long
3466 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
3468 builtin_type
->builtin_unsigned_long_long
3469 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
3470 1, "unsigned long long");
3471 builtin_type
->builtin_float
3472 = arch_float_type (gdbarch
, gdbarch_float_bit (gdbarch
),
3473 "float", gdbarch_float_format (gdbarch
));
3474 builtin_type
->builtin_double
3475 = arch_float_type (gdbarch
, gdbarch_double_bit (gdbarch
),
3476 "double", gdbarch_double_format (gdbarch
));
3477 builtin_type
->builtin_long_double
3478 = arch_float_type (gdbarch
, gdbarch_long_double_bit (gdbarch
),
3479 "long double", gdbarch_long_double_format (gdbarch
));
3480 builtin_type
->builtin_complex
3481 = arch_complex_type (gdbarch
, "complex",
3482 builtin_type
->builtin_float
);
3483 builtin_type
->builtin_double_complex
3484 = arch_complex_type (gdbarch
, "double complex",
3485 builtin_type
->builtin_double
);
3486 builtin_type
->builtin_string
3487 = arch_type (gdbarch
, TYPE_CODE_STRING
, 1, "string");
3488 builtin_type
->builtin_bool
3489 = arch_type (gdbarch
, TYPE_CODE_BOOL
, 1, "bool");
3491 /* The following three are about decimal floating point types, which
3492 are 32-bits, 64-bits and 128-bits respectively. */
3493 builtin_type
->builtin_decfloat
3494 = arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, 32 / 8, "_Decimal32");
3495 builtin_type
->builtin_decdouble
3496 = arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, 64 / 8, "_Decimal64");
3497 builtin_type
->builtin_declong
3498 = arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, 128 / 8, "_Decimal128");
3500 /* "True" character types. */
3501 builtin_type
->builtin_true_char
3502 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 0, "true character");
3503 builtin_type
->builtin_true_unsigned_char
3504 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 1, "true character");
3506 /* Fixed-size integer types. */
3507 builtin_type
->builtin_int0
3508 = arch_integer_type (gdbarch
, 0, 0, "int0_t");
3509 builtin_type
->builtin_int8
3510 = arch_integer_type (gdbarch
, 8, 0, "int8_t");
3511 builtin_type
->builtin_uint8
3512 = arch_integer_type (gdbarch
, 8, 1, "uint8_t");
3513 builtin_type
->builtin_int16
3514 = arch_integer_type (gdbarch
, 16, 0, "int16_t");
3515 builtin_type
->builtin_uint16
3516 = arch_integer_type (gdbarch
, 16, 1, "uint16_t");
3517 builtin_type
->builtin_int32
3518 = arch_integer_type (gdbarch
, 32, 0, "int32_t");
3519 builtin_type
->builtin_uint32
3520 = arch_integer_type (gdbarch
, 32, 1, "uint32_t");
3521 builtin_type
->builtin_int64
3522 = arch_integer_type (gdbarch
, 64, 0, "int64_t");
3523 builtin_type
->builtin_uint64
3524 = arch_integer_type (gdbarch
, 64, 1, "uint64_t");
3525 builtin_type
->builtin_int128
3526 = arch_integer_type (gdbarch
, 128, 0, "int128_t");
3527 builtin_type
->builtin_uint128
3528 = arch_integer_type (gdbarch
, 128, 1, "uint128_t");
3529 TYPE_INSTANCE_FLAGS (builtin_type
->builtin_int8
) |=
3530 TYPE_INSTANCE_FLAG_NOTTEXT
;
3531 TYPE_INSTANCE_FLAGS (builtin_type
->builtin_uint8
) |=
3532 TYPE_INSTANCE_FLAG_NOTTEXT
;
3534 /* Wide character types. */
3535 builtin_type
->builtin_char16
3536 = arch_integer_type (gdbarch
, 16, 0, "char16_t");
3537 builtin_type
->builtin_char32
3538 = arch_integer_type (gdbarch
, 32, 0, "char32_t");
3541 /* Default data/code pointer types. */
3542 builtin_type
->builtin_data_ptr
3543 = lookup_pointer_type (builtin_type
->builtin_void
);
3544 builtin_type
->builtin_func_ptr
3545 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3547 /* This type represents a GDB internal function. */
3548 builtin_type
->internal_fn
3549 = arch_type (gdbarch
, TYPE_CODE_INTERNAL_FUNCTION
, 0,
3550 "<internal function>");
3552 return builtin_type
;
3556 /* This set of objfile-based types is intended to be used by symbol
3557 readers as basic types. */
3559 static const struct objfile_data
*objfile_type_data
;
3561 const struct objfile_type
*
3562 objfile_type (struct objfile
*objfile
)
3564 struct gdbarch
*gdbarch
;
3565 struct objfile_type
*objfile_type
3566 = objfile_data (objfile
, objfile_type_data
);
3569 return objfile_type
;
3571 objfile_type
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3572 1, struct objfile_type
);
3574 /* Use the objfile architecture to determine basic type properties. */
3575 gdbarch
= get_objfile_arch (objfile
);
3578 objfile_type
->builtin_void
3579 = init_type (TYPE_CODE_VOID
, 1,
3583 objfile_type
->builtin_char
3584 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3586 | (gdbarch_char_signed (gdbarch
) ? 0 : TYPE_FLAG_UNSIGNED
)),
3588 objfile_type
->builtin_signed_char
3589 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3591 "signed char", objfile
);
3592 objfile_type
->builtin_unsigned_char
3593 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3595 "unsigned char", objfile
);
3596 objfile_type
->builtin_short
3597 = init_type (TYPE_CODE_INT
,
3598 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3599 0, "short", objfile
);
3600 objfile_type
->builtin_unsigned_short
3601 = init_type (TYPE_CODE_INT
,
3602 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3603 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
3604 objfile_type
->builtin_int
3605 = init_type (TYPE_CODE_INT
,
3606 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3608 objfile_type
->builtin_unsigned_int
3609 = init_type (TYPE_CODE_INT
,
3610 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3611 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
3612 objfile_type
->builtin_long
3613 = init_type (TYPE_CODE_INT
,
3614 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3615 0, "long", objfile
);
3616 objfile_type
->builtin_unsigned_long
3617 = init_type (TYPE_CODE_INT
,
3618 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3619 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
3620 objfile_type
->builtin_long_long
3621 = init_type (TYPE_CODE_INT
,
3622 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3623 0, "long long", objfile
);
3624 objfile_type
->builtin_unsigned_long_long
3625 = init_type (TYPE_CODE_INT
,
3626 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3627 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
3629 objfile_type
->builtin_float
3630 = init_type (TYPE_CODE_FLT
,
3631 gdbarch_float_bit (gdbarch
) / TARGET_CHAR_BIT
,
3632 0, "float", objfile
);
3633 TYPE_FLOATFORMAT (objfile_type
->builtin_float
)
3634 = gdbarch_float_format (gdbarch
);
3635 objfile_type
->builtin_double
3636 = init_type (TYPE_CODE_FLT
,
3637 gdbarch_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
3638 0, "double", objfile
);
3639 TYPE_FLOATFORMAT (objfile_type
->builtin_double
)
3640 = gdbarch_double_format (gdbarch
);
3641 objfile_type
->builtin_long_double
3642 = init_type (TYPE_CODE_FLT
,
3643 gdbarch_long_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
3644 0, "long double", objfile
);
3645 TYPE_FLOATFORMAT (objfile_type
->builtin_long_double
)
3646 = gdbarch_long_double_format (gdbarch
);
3648 /* This type represents a type that was unrecognized in symbol read-in. */
3649 objfile_type
->builtin_error
3650 = init_type (TYPE_CODE_ERROR
, 0, 0, "<unknown type>", objfile
);
3652 /* The following set of types is used for symbols with no
3653 debug information. */
3654 objfile_type
->nodebug_text_symbol
3655 = init_type (TYPE_CODE_FUNC
, 1, 0,
3656 "<text variable, no debug info>", objfile
);
3657 TYPE_TARGET_TYPE (objfile_type
->nodebug_text_symbol
)
3658 = objfile_type
->builtin_int
;
3659 objfile_type
->nodebug_data_symbol
3660 = init_type (TYPE_CODE_INT
,
3661 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3662 "<data variable, no debug info>", objfile
);
3663 objfile_type
->nodebug_unknown_symbol
3664 = init_type (TYPE_CODE_INT
, 1, 0,
3665 "<variable (not text or data), no debug info>", objfile
);
3666 objfile_type
->nodebug_tls_symbol
3667 = init_type (TYPE_CODE_INT
,
3668 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3669 "<thread local variable, no debug info>", objfile
);
3671 /* NOTE: on some targets, addresses and pointers are not necessarily
3672 the same --- for example, on the D10V, pointers are 16 bits long,
3673 but addresses are 32 bits long. See doc/gdbint.texinfo,
3674 ``Pointers Are Not Always Addresses''.
3677 - gdb's `struct type' always describes the target's
3679 - gdb's `struct value' objects should always hold values in
3681 - gdb's CORE_ADDR values are addresses in the unified virtual
3682 address space that the assembler and linker work with. Thus,
3683 since target_read_memory takes a CORE_ADDR as an argument, it
3684 can access any memory on the target, even if the processor has
3685 separate code and data address spaces.
3688 - If v is a value holding a D10V code pointer, its contents are
3689 in target form: a big-endian address left-shifted two bits.
3690 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3691 sizeof (void *) == 2 on the target.
3693 In this context, objfile_type->builtin_core_addr is a bit odd:
3694 it's a target type for a value the target will never see. It's
3695 only used to hold the values of (typeless) linker symbols, which
3696 are indeed in the unified virtual address space. */
3698 objfile_type
->builtin_core_addr
3699 = init_type (TYPE_CODE_INT
,
3700 gdbarch_addr_bit (gdbarch
) / 8,
3701 TYPE_FLAG_UNSIGNED
, "__CORE_ADDR", objfile
);
3703 set_objfile_data (objfile
, objfile_type_data
, objfile_type
);
3704 return objfile_type
;
3708 extern void _initialize_gdbtypes (void);
3710 _initialize_gdbtypes (void)
3712 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
3713 objfile_type_data
= register_objfile_data ();
3715 add_setshow_zinteger_cmd ("overload", no_class
, &overload_debug
, _("\
3716 Set debugging of C++ overloading."), _("\
3717 Show debugging of C++ overloading."), _("\
3718 When enabled, ranking of the functions is displayed."),
3720 show_overload_debug
,
3721 &setdebuglist
, &showdebuglist
);
3723 /* Add user knob for controlling resolution of opaque types. */
3724 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
3725 &opaque_type_resolution
, _("\
3726 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3727 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL
,
3729 show_opaque_type_resolution
,
3730 &setlist
, &showlist
);