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 Free Software Foundation, Inc.
6 Contributed by Cygnus Support, using pieces from other GDB modules.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
30 #include "expression.h"
35 #include "complaints.h"
39 #include "gdb_assert.h"
43 /* Floatformat pairs. */
44 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
45 &floatformat_ieee_single_big
,
46 &floatformat_ieee_single_little
48 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
49 &floatformat_ieee_double_big
,
50 &floatformat_ieee_double_little
52 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
53 &floatformat_ieee_double_big
,
54 &floatformat_ieee_double_littlebyte_bigword
56 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
57 &floatformat_i387_ext
,
60 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
61 &floatformat_m68881_ext
,
62 &floatformat_m68881_ext
64 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
65 &floatformat_arm_ext_big
,
66 &floatformat_arm_ext_littlebyte_bigword
68 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
69 &floatformat_ia64_spill_big
,
70 &floatformat_ia64_spill_little
72 const struct floatformat
*floatformats_ia64_quad
[BFD_ENDIAN_UNKNOWN
] = {
73 &floatformat_ia64_quad_big
,
74 &floatformat_ia64_quad_little
76 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
80 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
84 const struct floatformat
*floatformats_ibm_long_double
[BFD_ENDIAN_UNKNOWN
] = {
85 &floatformat_ibm_long_double
,
86 &floatformat_ibm_long_double
90 int opaque_type_resolution
= 1;
92 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
93 struct cmd_list_element
*c
,
96 fprintf_filtered (file
, _("\
97 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
101 int overload_debug
= 0;
103 show_overload_debug (struct ui_file
*file
, int from_tty
,
104 struct cmd_list_element
*c
, const char *value
)
106 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"),
114 }; /* Maximum extension is 128! FIXME */
116 static void print_bit_vector (B_TYPE
*, int);
117 static void print_arg_types (struct field
*, int, int);
118 static void dump_fn_fieldlists (struct type
*, int);
119 static void print_cplus_stuff (struct type
*, int);
122 /* Allocate a new OBJFILE-associated type structure and fill it
123 with some defaults. Space for the type structure is allocated
124 on the objfile's objfile_obstack. */
127 alloc_type (struct objfile
*objfile
)
131 gdb_assert (objfile
!= NULL
);
133 /* Alloc the structure and start off with all fields zeroed. */
134 type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct type
);
135 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
137 OBJSTAT (objfile
, n_types
++);
139 TYPE_OBJFILE_OWNED (type
) = 1;
140 TYPE_OWNER (type
).objfile
= objfile
;
142 /* Initialize the fields that might not be zero. */
144 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
145 TYPE_VPTR_FIELDNO (type
) = -1;
146 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
151 /* Allocate a new GDBARCH-associated type structure and fill it
152 with some defaults. Space for the type structure is allocated
156 alloc_type_arch (struct gdbarch
*gdbarch
)
160 gdb_assert (gdbarch
!= NULL
);
162 /* Alloc the structure and start off with all fields zeroed. */
164 type
= XZALLOC (struct type
);
165 TYPE_MAIN_TYPE (type
) = XZALLOC (struct main_type
);
167 TYPE_OBJFILE_OWNED (type
) = 0;
168 TYPE_OWNER (type
).gdbarch
= gdbarch
;
170 /* Initialize the fields that might not be zero. */
172 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
173 TYPE_VPTR_FIELDNO (type
) = -1;
174 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
179 /* If TYPE is objfile-associated, allocate a new type structure
180 associated with the same objfile. If TYPE is gdbarch-associated,
181 allocate a new type structure associated with the same gdbarch. */
184 alloc_type_copy (const struct type
*type
)
186 if (TYPE_OBJFILE_OWNED (type
))
187 return alloc_type (TYPE_OWNER (type
).objfile
);
189 return alloc_type_arch (TYPE_OWNER (type
).gdbarch
);
192 /* If TYPE is gdbarch-associated, return that architecture.
193 If TYPE is objfile-associated, return that objfile's architecture. */
196 get_type_arch (const struct type
*type
)
198 if (TYPE_OBJFILE_OWNED (type
))
199 return get_objfile_arch (TYPE_OWNER (type
).objfile
);
201 return TYPE_OWNER (type
).gdbarch
;
205 /* Alloc a new type instance structure, fill it with some defaults,
206 and point it at OLDTYPE. Allocate the new type instance from the
207 same place as OLDTYPE. */
210 alloc_type_instance (struct type
*oldtype
)
214 /* Allocate the structure. */
216 if (! TYPE_OBJFILE_OWNED (oldtype
))
217 type
= XZALLOC (struct type
);
219 type
= OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
222 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
224 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
229 /* Clear all remnants of the previous type at TYPE, in preparation for
230 replacing it with something else. Preserve owner information. */
232 smash_type (struct type
*type
)
234 int objfile_owned
= TYPE_OBJFILE_OWNED (type
);
235 union type_owner owner
= TYPE_OWNER (type
);
237 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
239 /* Restore owner information. */
240 TYPE_OBJFILE_OWNED (type
) = objfile_owned
;
241 TYPE_OWNER (type
) = owner
;
243 /* For now, delete the rings. */
244 TYPE_CHAIN (type
) = type
;
246 /* For now, leave the pointer/reference types alone. */
249 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
250 to a pointer to memory where the pointer type should be stored.
251 If *TYPEPTR is zero, update it to point to the pointer type we return.
252 We allocate new memory if needed. */
255 make_pointer_type (struct type
*type
, struct type
**typeptr
)
257 struct type
*ntype
; /* New type */
260 ntype
= TYPE_POINTER_TYPE (type
);
265 return ntype
; /* Don't care about alloc,
266 and have new type. */
267 else if (*typeptr
== 0)
269 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
274 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
276 ntype
= alloc_type_copy (type
);
280 else /* We have storage, but need to reset it. */
283 chain
= TYPE_CHAIN (ntype
);
285 TYPE_CHAIN (ntype
) = chain
;
288 TYPE_TARGET_TYPE (ntype
) = type
;
289 TYPE_POINTER_TYPE (type
) = ntype
;
291 /* FIXME! Assume the machine has only one representation for
295 = gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
296 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
298 /* Mark pointers as unsigned. The target converts between pointers
299 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
300 gdbarch_address_to_pointer. */
301 TYPE_UNSIGNED (ntype
) = 1;
303 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
304 TYPE_POINTER_TYPE (type
) = ntype
;
306 /* Update the length of all the other variants of this type. */
307 chain
= TYPE_CHAIN (ntype
);
308 while (chain
!= ntype
)
310 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
311 chain
= TYPE_CHAIN (chain
);
317 /* Given a type TYPE, return a type of pointers to that type.
318 May need to construct such a type if this is the first use. */
321 lookup_pointer_type (struct type
*type
)
323 return make_pointer_type (type
, (struct type
**) 0);
326 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
327 points to a pointer to memory where the reference type should be
328 stored. If *TYPEPTR is zero, update it to point to the reference
329 type we return. We allocate new memory if needed. */
332 make_reference_type (struct type
*type
, struct type
**typeptr
)
334 struct type
*ntype
; /* New type */
337 ntype
= TYPE_REFERENCE_TYPE (type
);
342 return ntype
; /* Don't care about alloc,
343 and have new type. */
344 else if (*typeptr
== 0)
346 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
351 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
353 ntype
= alloc_type_copy (type
);
357 else /* We have storage, but need to reset it. */
360 chain
= TYPE_CHAIN (ntype
);
362 TYPE_CHAIN (ntype
) = chain
;
365 TYPE_TARGET_TYPE (ntype
) = type
;
366 TYPE_REFERENCE_TYPE (type
) = ntype
;
368 /* FIXME! Assume the machine has only one representation for
369 references, and that it matches the (only) representation for
372 TYPE_LENGTH (ntype
) =
373 gdbarch_ptr_bit (get_type_arch (type
)) / TARGET_CHAR_BIT
;
374 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
376 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
377 TYPE_REFERENCE_TYPE (type
) = ntype
;
379 /* Update the length of all the other variants of this type. */
380 chain
= TYPE_CHAIN (ntype
);
381 while (chain
!= ntype
)
383 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
384 chain
= TYPE_CHAIN (chain
);
390 /* Same as above, but caller doesn't care about memory allocation
394 lookup_reference_type (struct type
*type
)
396 return make_reference_type (type
, (struct type
**) 0);
399 /* Lookup a function type that returns type TYPE. TYPEPTR, if
400 nonzero, points to a pointer to memory where the function type
401 should be stored. If *TYPEPTR is zero, update it to point to the
402 function type we return. We allocate new memory if needed. */
405 make_function_type (struct type
*type
, struct type
**typeptr
)
407 struct type
*ntype
; /* New type */
409 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
411 ntype
= alloc_type_copy (type
);
415 else /* We have storage, but need to reset it. */
421 TYPE_TARGET_TYPE (ntype
) = type
;
423 TYPE_LENGTH (ntype
) = 1;
424 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
430 /* Given a type TYPE, return a type of functions that return that type.
431 May need to construct such a type if this is the first use. */
434 lookup_function_type (struct type
*type
)
436 return make_function_type (type
, (struct type
**) 0);
439 /* Identify address space identifier by name --
440 return the integer flag defined in gdbtypes.h. */
442 address_space_name_to_int (struct gdbarch
*gdbarch
, char *space_identifier
)
445 /* Check for known address space delimiters. */
446 if (!strcmp (space_identifier
, "code"))
447 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
448 else if (!strcmp (space_identifier
, "data"))
449 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
450 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
451 && gdbarch_address_class_name_to_type_flags (gdbarch
,
456 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
459 /* Identify address space identifier by integer flag as defined in
460 gdbtypes.h -- return the string version of the adress space name. */
463 address_space_int_to_name (struct gdbarch
*gdbarch
, int space_flag
)
465 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
467 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
469 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
470 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
471 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
476 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
478 If STORAGE is non-NULL, create the new type instance there.
479 STORAGE must be in the same obstack as TYPE. */
482 make_qualified_type (struct type
*type
, int new_flags
,
483 struct type
*storage
)
490 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
492 ntype
= TYPE_CHAIN (ntype
);
494 while (ntype
!= type
);
496 /* Create a new type instance. */
498 ntype
= alloc_type_instance (type
);
501 /* If STORAGE was provided, it had better be in the same objfile
502 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
503 if one objfile is freed and the other kept, we'd have
504 dangling pointers. */
505 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
508 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
509 TYPE_CHAIN (ntype
) = ntype
;
512 /* Pointers or references to the original type are not relevant to
514 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
515 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
517 /* Chain the new qualified type to the old type. */
518 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
519 TYPE_CHAIN (type
) = ntype
;
521 /* Now set the instance flags and return the new type. */
522 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
524 /* Set length of new type to that of the original type. */
525 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
530 /* Make an address-space-delimited variant of a type -- a type that
531 is identical to the one supplied except that it has an address
532 space attribute attached to it (such as "code" or "data").
534 The space attributes "code" and "data" are for Harvard
535 architectures. The address space attributes are for architectures
536 which have alternately sized pointers or pointers with alternate
540 make_type_with_address_space (struct type
*type
, int space_flag
)
543 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
544 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
545 | TYPE_INSTANCE_FLAG_DATA_SPACE
546 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
549 return make_qualified_type (type
, new_flags
, NULL
);
552 /* Make a "c-v" variant of a type -- a type that is identical to the
553 one supplied except that it may have const or volatile attributes
554 CNST is a flag for setting the const attribute
555 VOLTL is a flag for setting the volatile attribute
556 TYPE is the base type whose variant we are creating.
558 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
559 storage to hold the new qualified type; *TYPEPTR and TYPE must be
560 in the same objfile. Otherwise, allocate fresh memory for the new
561 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
562 new type we construct. */
564 make_cv_type (int cnst
, int voltl
,
566 struct type
**typeptr
)
568 struct type
*ntype
; /* New type */
569 struct type
*tmp_type
= type
; /* tmp type */
570 struct objfile
*objfile
;
572 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
573 & ~(TYPE_INSTANCE_FLAG_CONST
| TYPE_INSTANCE_FLAG_VOLATILE
));
576 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
579 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
581 if (typeptr
&& *typeptr
!= NULL
)
583 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
584 a C-V variant chain that threads across objfiles: if one
585 objfile gets freed, then the other has a broken C-V chain.
587 This code used to try to copy over the main type from TYPE to
588 *TYPEPTR if they were in different objfiles, but that's
589 wrong, too: TYPE may have a field list or member function
590 lists, which refer to types of their own, etc. etc. The
591 whole shebang would need to be copied over recursively; you
592 can't have inter-objfile pointers. The only thing to do is
593 to leave stub types as stub types, and look them up afresh by
594 name each time you encounter them. */
595 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
598 ntype
= make_qualified_type (type
, new_flags
,
599 typeptr
? *typeptr
: NULL
);
607 /* Replace the contents of ntype with the type *type. This changes the
608 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
609 the changes are propogated to all types in the TYPE_CHAIN.
611 In order to build recursive types, it's inevitable that we'll need
612 to update types in place --- but this sort of indiscriminate
613 smashing is ugly, and needs to be replaced with something more
614 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
615 clear if more steps are needed. */
617 replace_type (struct type
*ntype
, struct type
*type
)
621 /* These two types had better be in the same objfile. Otherwise,
622 the assignment of one type's main type structure to the other
623 will produce a type with references to objects (names; field
624 lists; etc.) allocated on an objfile other than its own. */
625 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
627 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
629 /* The type length is not a part of the main type. Update it for
630 each type on the variant chain. */
634 /* Assert that this element of the chain has no address-class bits
635 set in its flags. Such type variants might have type lengths
636 which are supposed to be different from the non-address-class
637 variants. This assertion shouldn't ever be triggered because
638 symbol readers which do construct address-class variants don't
639 call replace_type(). */
640 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
642 TYPE_LENGTH (chain
) = TYPE_LENGTH (type
);
643 chain
= TYPE_CHAIN (chain
);
645 while (ntype
!= chain
);
647 /* Assert that the two types have equivalent instance qualifiers.
648 This should be true for at least all of our debug readers. */
649 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
652 /* Implement direct support for MEMBER_TYPE in GNU C++.
653 May need to construct such a type if this is the first use.
654 The TYPE is the type of the member. The DOMAIN is the type
655 of the aggregate that the member belongs to. */
658 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
662 mtype
= alloc_type_copy (type
);
663 smash_to_memberptr_type (mtype
, domain
, type
);
667 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
670 lookup_methodptr_type (struct type
*to_type
)
674 mtype
= alloc_type_copy (to_type
);
675 TYPE_TARGET_TYPE (mtype
) = to_type
;
676 TYPE_DOMAIN_TYPE (mtype
) = TYPE_DOMAIN_TYPE (to_type
);
677 TYPE_LENGTH (mtype
) = cplus_method_ptr_size (to_type
);
678 TYPE_CODE (mtype
) = TYPE_CODE_METHODPTR
;
682 /* Allocate a stub method whose return type is TYPE. This apparently
683 happens for speed of symbol reading, since parsing out the
684 arguments to the method is cpu-intensive, the way we are doing it.
685 So, we will fill in arguments later. This always returns a fresh
689 allocate_stub_method (struct type
*type
)
693 mtype
= alloc_type_copy (type
);
694 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
695 TYPE_LENGTH (mtype
) = 1;
696 TYPE_STUB (mtype
) = 1;
697 TYPE_TARGET_TYPE (mtype
) = type
;
698 /* _DOMAIN_TYPE (mtype) = unknown yet */
702 /* Create a range type using either a blank type supplied in
703 RESULT_TYPE, or creating a new type, inheriting the objfile from
706 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
707 to HIGH_BOUND, inclusive.
709 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
710 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
713 create_range_type (struct type
*result_type
, struct type
*index_type
,
714 int low_bound
, int high_bound
)
716 if (result_type
== NULL
)
717 result_type
= alloc_type_copy (index_type
);
718 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
719 TYPE_TARGET_TYPE (result_type
) = index_type
;
720 if (TYPE_STUB (index_type
))
721 TYPE_TARGET_STUB (result_type
) = 1;
723 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
724 TYPE_NFIELDS (result_type
) = 2;
725 TYPE_FIELDS (result_type
) = TYPE_ZALLOC (result_type
,
726 TYPE_NFIELDS (result_type
)
727 * sizeof (struct field
));
728 TYPE_LOW_BOUND (result_type
) = low_bound
;
729 TYPE_HIGH_BOUND (result_type
) = high_bound
;
732 TYPE_UNSIGNED (result_type
) = 1;
737 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
738 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
739 bounds will fit in LONGEST), or -1 otherwise. */
742 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
744 CHECK_TYPEDEF (type
);
745 switch (TYPE_CODE (type
))
747 case TYPE_CODE_RANGE
:
748 *lowp
= TYPE_LOW_BOUND (type
);
749 *highp
= TYPE_HIGH_BOUND (type
);
752 if (TYPE_NFIELDS (type
) > 0)
754 /* The enums may not be sorted by value, so search all
758 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
759 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
761 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
762 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
763 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
764 *highp
= TYPE_FIELD_BITPOS (type
, i
);
767 /* Set unsigned indicator if warranted. */
770 TYPE_UNSIGNED (type
) = 1;
784 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
786 if (!TYPE_UNSIGNED (type
))
788 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
792 /* ... fall through for unsigned ints ... */
795 /* This round-about calculation is to avoid shifting by
796 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
797 if TYPE_LENGTH (type) == sizeof (LONGEST). */
798 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
799 *highp
= (*highp
- 1) | *highp
;
806 /* Create an array type using either a blank type supplied in
807 RESULT_TYPE, or creating a new type, inheriting the objfile from
810 Elements will be of type ELEMENT_TYPE, the indices will be of type
813 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
814 sure it is TYPE_CODE_UNDEF before we bash it into an array
818 create_array_type (struct type
*result_type
,
819 struct type
*element_type
,
820 struct type
*range_type
)
822 LONGEST low_bound
, high_bound
;
824 if (result_type
== NULL
)
825 result_type
= alloc_type_copy (range_type
);
827 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
828 TYPE_TARGET_TYPE (result_type
) = element_type
;
829 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
830 low_bound
= high_bound
= 0;
831 CHECK_TYPEDEF (element_type
);
832 /* Be careful when setting the array length. Ada arrays can be
833 empty arrays with the high_bound being smaller than the low_bound.
834 In such cases, the array length should be zero. */
835 if (high_bound
< low_bound
)
836 TYPE_LENGTH (result_type
) = 0;
838 TYPE_LENGTH (result_type
) =
839 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
840 TYPE_NFIELDS (result_type
) = 1;
841 TYPE_FIELDS (result_type
) =
842 (struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
));
843 TYPE_INDEX_TYPE (result_type
) = range_type
;
844 TYPE_VPTR_FIELDNO (result_type
) = -1;
846 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
847 if (TYPE_LENGTH (result_type
) == 0)
848 TYPE_TARGET_STUB (result_type
) = 1;
854 lookup_array_range_type (struct type
*element_type
,
855 int low_bound
, int high_bound
)
857 struct gdbarch
*gdbarch
= get_type_arch (element_type
);
858 struct type
*index_type
= builtin_type (gdbarch
)->builtin_int
;
859 struct type
*range_type
860 = 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
;
893 result_type
= lookup_array_range_type (string_char_type
,
894 low_bound
, high_bound
);
895 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
900 create_set_type (struct type
*result_type
, struct type
*domain_type
)
902 if (result_type
== NULL
)
903 result_type
= alloc_type_copy (domain_type
);
905 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
906 TYPE_NFIELDS (result_type
) = 1;
907 TYPE_FIELDS (result_type
) = TYPE_ZALLOC (result_type
, sizeof (struct field
));
909 if (!TYPE_STUB (domain_type
))
911 LONGEST low_bound
, high_bound
, bit_length
;
912 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
913 low_bound
= high_bound
= 0;
914 bit_length
= high_bound
- low_bound
+ 1;
915 TYPE_LENGTH (result_type
)
916 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
918 TYPE_UNSIGNED (result_type
) = 1;
920 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
925 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
926 and any array types nested inside it. */
929 make_vector_type (struct type
*array_type
)
931 struct type
*inner_array
, *elt_type
;
934 /* Find the innermost array type, in case the array is
935 multi-dimensional. */
936 inner_array
= array_type
;
937 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
938 inner_array
= TYPE_TARGET_TYPE (inner_array
);
940 elt_type
= TYPE_TARGET_TYPE (inner_array
);
941 if (TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
943 flags
= TYPE_INSTANCE_FLAGS (elt_type
) | TYPE_FLAG_NOTTEXT
;
944 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
945 TYPE_TARGET_TYPE (inner_array
) = elt_type
;
948 TYPE_VECTOR (array_type
) = 1;
952 init_vector_type (struct type
*elt_type
, int n
)
954 struct type
*array_type
;
955 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
956 make_vector_type (array_type
);
960 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
961 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
962 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
963 TYPE doesn't include the offset (that's the value of the MEMBER
964 itself), but does include the structure type into which it points
967 When "smashing" the type, we preserve the objfile that the old type
968 pointed to, since we aren't changing where the type is actually
972 smash_to_memberptr_type (struct type
*type
, struct type
*domain
,
973 struct type
*to_type
)
976 TYPE_TARGET_TYPE (type
) = to_type
;
977 TYPE_DOMAIN_TYPE (type
) = domain
;
978 /* Assume that a data member pointer is the same size as a normal
981 = gdbarch_ptr_bit (get_type_arch (to_type
)) / TARGET_CHAR_BIT
;
982 TYPE_CODE (type
) = TYPE_CODE_MEMBERPTR
;
985 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
986 METHOD just means `function that gets an extra "this" argument'.
988 When "smashing" the type, we preserve the objfile that the old type
989 pointed to, since we aren't changing where the type is actually
993 smash_to_method_type (struct type
*type
, struct type
*domain
,
994 struct type
*to_type
, struct field
*args
,
995 int nargs
, int varargs
)
998 TYPE_TARGET_TYPE (type
) = to_type
;
999 TYPE_DOMAIN_TYPE (type
) = domain
;
1000 TYPE_FIELDS (type
) = args
;
1001 TYPE_NFIELDS (type
) = nargs
;
1003 TYPE_VARARGS (type
) = 1;
1004 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1005 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1008 /* Return a typename for a struct/union/enum type without "struct ",
1009 "union ", or "enum ". If the type has a NULL name, return NULL. */
1012 type_name_no_tag (const struct type
*type
)
1014 if (TYPE_TAG_NAME (type
) != NULL
)
1015 return TYPE_TAG_NAME (type
);
1017 /* Is there code which expects this to return the name if there is
1018 no tag name? My guess is that this is mainly used for C++ in
1019 cases where the two will always be the same. */
1020 return TYPE_NAME (type
);
1023 /* Lookup a typedef or primitive type named NAME, visible in lexical
1024 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1025 suitably defined. */
1028 lookup_typename (const struct language_defn
*language
,
1029 struct gdbarch
*gdbarch
, char *name
,
1030 struct block
*block
, int noerr
)
1035 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0);
1036 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1038 tmp
= language_lookup_primitive_type_by_name (language
, gdbarch
, name
);
1043 else if (!tmp
&& noerr
)
1049 error (_("No type named %s."), name
);
1052 return (SYMBOL_TYPE (sym
));
1056 lookup_unsigned_typename (const struct language_defn
*language
,
1057 struct gdbarch
*gdbarch
, char *name
)
1059 char *uns
= alloca (strlen (name
) + 10);
1061 strcpy (uns
, "unsigned ");
1062 strcpy (uns
+ 9, name
);
1063 return lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 0);
1067 lookup_signed_typename (const struct language_defn
*language
,
1068 struct gdbarch
*gdbarch
, char *name
)
1071 char *uns
= alloca (strlen (name
) + 8);
1073 strcpy (uns
, "signed ");
1074 strcpy (uns
+ 7, name
);
1075 t
= lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 1);
1076 /* If we don't find "signed FOO" just try again with plain "FOO". */
1079 return lookup_typename (language
, gdbarch
, name
, (struct block
*) NULL
, 0);
1082 /* Lookup a structure type named "struct NAME",
1083 visible in lexical block BLOCK. */
1086 lookup_struct (char *name
, struct block
*block
)
1090 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1094 error (_("No struct type named %s."), name
);
1096 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1098 error (_("This context has class, union or enum %s, not a struct."),
1101 return (SYMBOL_TYPE (sym
));
1104 /* Lookup a union type named "union NAME",
1105 visible in lexical block BLOCK. */
1108 lookup_union (char *name
, struct block
*block
)
1113 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1116 error (_("No union type named %s."), name
);
1118 t
= SYMBOL_TYPE (sym
);
1120 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1123 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1124 * a further "declared_type" field to discover it is really a union.
1126 if (HAVE_CPLUS_STRUCT (t
))
1127 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1130 /* If we get here, it's not a union. */
1131 error (_("This context has class, struct or enum %s, not a union."),
1136 /* Lookup an enum type named "enum NAME",
1137 visible in lexical block BLOCK. */
1140 lookup_enum (char *name
, struct block
*block
)
1144 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1147 error (_("No enum type named %s."), name
);
1149 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1151 error (_("This context has class, struct or union %s, not an enum."),
1154 return (SYMBOL_TYPE (sym
));
1157 /* Lookup a template type named "template NAME<TYPE>",
1158 visible in lexical block BLOCK. */
1161 lookup_template_type (char *name
, struct type
*type
,
1162 struct block
*block
)
1165 char *nam
= (char *)
1166 alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1169 strcat (nam
, TYPE_NAME (type
));
1170 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1172 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0);
1176 error (_("No template type named %s."), name
);
1178 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1180 error (_("This context has class, union or enum %s, not a struct."),
1183 return (SYMBOL_TYPE (sym
));
1186 /* Given a type TYPE, lookup the type of the component of type named
1189 TYPE can be either a struct or union, or a pointer or reference to
1190 a struct or union. If it is a pointer or reference, its target
1191 type is automatically used. Thus '.' and '->' are interchangable,
1192 as specified for the definitions of the expression element types
1193 STRUCTOP_STRUCT and STRUCTOP_PTR.
1195 If NOERR is nonzero, return zero if NAME is not suitably defined.
1196 If NAME is the name of a baseclass type, return that type. */
1199 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1205 CHECK_TYPEDEF (type
);
1206 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1207 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1209 type
= TYPE_TARGET_TYPE (type
);
1212 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1213 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1215 target_terminal_ours ();
1216 gdb_flush (gdb_stdout
);
1217 fprintf_unfiltered (gdb_stderr
, "Type ");
1218 type_print (type
, "", gdb_stderr
, -1);
1219 error (_(" is not a structure or union type."));
1223 /* FIXME: This change put in by Michael seems incorrect for the case
1224 where the structure tag name is the same as the member name.
1225 I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
1226 foo; } bell;" Disabled by fnf. */
1230 typename
= type_name_no_tag (type
);
1231 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1236 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1238 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1240 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1242 return TYPE_FIELD_TYPE (type
, i
);
1246 /* OK, it's not in this class. Recursively check the baseclasses. */
1247 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1251 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1263 target_terminal_ours ();
1264 gdb_flush (gdb_stdout
);
1265 fprintf_unfiltered (gdb_stderr
, "Type ");
1266 type_print (type
, "", gdb_stderr
, -1);
1267 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1268 fputs_filtered (name
, gdb_stderr
);
1270 return (struct type
*) -1; /* For lint */
1273 /* Lookup the vptr basetype/fieldno values for TYPE.
1274 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1275 vptr_fieldno. Also, if found and basetype is from the same objfile,
1277 If not found, return -1 and ignore BASETYPEP.
1278 Callers should be aware that in some cases (for example,
1279 the type or one of its baseclasses is a stub type and we are
1280 debugging a .o file, or the compiler uses DWARF-2 and is not GCC),
1281 this function will not be able to find the
1282 virtual function table pointer, and vptr_fieldno will remain -1 and
1283 vptr_basetype will remain NULL or incomplete. */
1286 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1288 CHECK_TYPEDEF (type
);
1290 if (TYPE_VPTR_FIELDNO (type
) < 0)
1294 /* We must start at zero in case the first (and only) baseclass
1295 is virtual (and hence we cannot share the table pointer). */
1296 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1298 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1300 struct type
*basetype
;
1302 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1305 /* If the type comes from a different objfile we can't cache
1306 it, it may have a different lifetime. PR 2384 */
1307 if (TYPE_OBJFILE (type
) == TYPE_OBJFILE (basetype
))
1309 TYPE_VPTR_FIELDNO (type
) = fieldno
;
1310 TYPE_VPTR_BASETYPE (type
) = basetype
;
1313 *basetypep
= basetype
;
1324 *basetypep
= TYPE_VPTR_BASETYPE (type
);
1325 return TYPE_VPTR_FIELDNO (type
);
1330 stub_noname_complaint (void)
1332 complaint (&symfile_complaints
, _("stub type has NULL name"));
1335 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1337 If this is a stubbed struct (i.e. declared as struct foo *), see if
1338 we can find a full definition in some other file. If so, copy this
1339 definition, so we can use it in future. There used to be a comment
1340 (but not any code) that if we don't find a full definition, we'd
1341 set a flag so we don't spend time in the future checking the same
1342 type. That would be a mistake, though--we might load in more
1343 symbols which contain a full definition for the type.
1345 This used to be coded as a macro, but I don't think it is called
1346 often enough to merit such treatment. */
1348 /* Find the real type of TYPE. This function returns the real type,
1349 after removing all layers of typedefs and completing opaque or stub
1350 types. Completion changes the TYPE argument, but stripping of
1351 typedefs does not. */
1354 check_typedef (struct type
*type
)
1356 struct type
*orig_type
= type
;
1357 int is_const
, is_volatile
;
1361 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1363 if (!TYPE_TARGET_TYPE (type
))
1368 /* It is dangerous to call lookup_symbol if we are currently
1369 reading a symtab. Infinite recursion is one danger. */
1370 if (currently_reading_symtab
)
1373 name
= type_name_no_tag (type
);
1374 /* FIXME: shouldn't we separately check the TYPE_NAME and
1375 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1376 VAR_DOMAIN as appropriate? (this code was written before
1377 TYPE_NAME and TYPE_TAG_NAME were separate). */
1380 stub_noname_complaint ();
1383 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1385 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1386 else /* TYPE_CODE_UNDEF */
1387 TYPE_TARGET_TYPE (type
) = alloc_type_arch (get_type_arch (type
));
1389 type
= TYPE_TARGET_TYPE (type
);
1392 is_const
= TYPE_CONST (type
);
1393 is_volatile
= TYPE_VOLATILE (type
);
1395 /* If this is a struct/class/union with no fields, then check
1396 whether a full definition exists somewhere else. This is for
1397 systems where a type definition with no fields is issued for such
1398 types, instead of identifying them as stub types in the first
1401 if (TYPE_IS_OPAQUE (type
)
1402 && opaque_type_resolution
1403 && !currently_reading_symtab
)
1405 char *name
= type_name_no_tag (type
);
1406 struct type
*newtype
;
1409 stub_noname_complaint ();
1412 newtype
= lookup_transparent_type (name
);
1416 /* If the resolved type and the stub are in the same
1417 objfile, then replace the stub type with the real deal.
1418 But if they're in separate objfiles, leave the stub
1419 alone; we'll just look up the transparent type every time
1420 we call check_typedef. We can't create pointers between
1421 types allocated to different objfiles, since they may
1422 have different lifetimes. Trying to copy NEWTYPE over to
1423 TYPE's objfile is pointless, too, since you'll have to
1424 move over any other types NEWTYPE refers to, which could
1425 be an unbounded amount of stuff. */
1426 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1427 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1432 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1434 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1436 char *name
= type_name_no_tag (type
);
1437 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1438 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1439 as appropriate? (this code was written before TYPE_NAME and
1440 TYPE_TAG_NAME were separate). */
1444 stub_noname_complaint ();
1447 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1450 /* Same as above for opaque types, we can replace the stub
1451 with the complete type only if they are int the same
1453 if (TYPE_OBJFILE (SYMBOL_TYPE(sym
)) == TYPE_OBJFILE (type
))
1454 make_cv_type (is_const
, is_volatile
,
1455 SYMBOL_TYPE (sym
), &type
);
1457 type
= SYMBOL_TYPE (sym
);
1461 if (TYPE_TARGET_STUB (type
))
1463 struct type
*range_type
;
1464 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1466 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1470 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1471 && TYPE_NFIELDS (type
) == 1
1472 && (TYPE_CODE (range_type
= TYPE_INDEX_TYPE (type
))
1473 == TYPE_CODE_RANGE
))
1475 /* Now recompute the length of the array type, based on its
1476 number of elements and the target type's length.
1477 Watch out for Ada null Ada arrays where the high bound
1478 is smaller than the low bound. */
1479 const int low_bound
= TYPE_LOW_BOUND (range_type
);
1480 const int high_bound
= TYPE_HIGH_BOUND (range_type
);
1483 if (high_bound
< low_bound
)
1486 nb_elements
= high_bound
- low_bound
+ 1;
1488 TYPE_LENGTH (type
) = nb_elements
* TYPE_LENGTH (target_type
);
1489 TYPE_TARGET_STUB (type
) = 0;
1491 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1493 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1494 TYPE_TARGET_STUB (type
) = 0;
1497 /* Cache TYPE_LENGTH for future use. */
1498 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1502 /* Parse a type expression in the string [P..P+LENGTH). If an error
1503 occurs, silently return a void type. */
1505 static struct type
*
1506 safe_parse_type (struct gdbarch
*gdbarch
, char *p
, int length
)
1508 struct ui_file
*saved_gdb_stderr
;
1511 /* Suppress error messages. */
1512 saved_gdb_stderr
= gdb_stderr
;
1513 gdb_stderr
= ui_file_new ();
1515 /* Call parse_and_eval_type() without fear of longjmp()s. */
1516 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1517 type
= builtin_type (gdbarch
)->builtin_void
;
1519 /* Stop suppressing error messages. */
1520 ui_file_delete (gdb_stderr
);
1521 gdb_stderr
= saved_gdb_stderr
;
1526 /* Ugly hack to convert method stubs into method types.
1528 He ain't kiddin'. This demangles the name of the method into a
1529 string including argument types, parses out each argument type,
1530 generates a string casting a zero to that type, evaluates the
1531 string, and stuffs the resulting type into an argtype vector!!!
1532 Then it knows the type of the whole function (including argument
1533 types for overloading), which info used to be in the stab's but was
1534 removed to hack back the space required for them. */
1537 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1539 struct gdbarch
*gdbarch
= get_type_arch (type
);
1541 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1542 char *demangled_name
= cplus_demangle (mangled_name
,
1543 DMGL_PARAMS
| DMGL_ANSI
);
1544 char *argtypetext
, *p
;
1545 int depth
= 0, argcount
= 1;
1546 struct field
*argtypes
;
1549 /* Make sure we got back a function string that we can use. */
1551 p
= strchr (demangled_name
, '(');
1555 if (demangled_name
== NULL
|| p
== NULL
)
1556 error (_("Internal: Cannot demangle mangled name `%s'."),
1559 /* Now, read in the parameters that define this type. */
1564 if (*p
== '(' || *p
== '<')
1568 else if (*p
== ')' || *p
== '>')
1572 else if (*p
== ',' && depth
== 0)
1580 /* If we read one argument and it was ``void'', don't count it. */
1581 if (strncmp (argtypetext
, "(void)", 6) == 0)
1584 /* We need one extra slot, for the THIS pointer. */
1586 argtypes
= (struct field
*)
1587 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1590 /* Add THIS pointer for non-static methods. */
1591 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1592 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1596 argtypes
[0].type
= lookup_pointer_type (type
);
1600 if (*p
!= ')') /* () means no args, skip while */
1605 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1607 /* Avoid parsing of ellipsis, they will be handled below.
1608 Also avoid ``void'' as above. */
1609 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1610 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1612 argtypes
[argcount
].type
=
1613 safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
);
1616 argtypetext
= p
+ 1;
1619 if (*p
== '(' || *p
== '<')
1623 else if (*p
== ')' || *p
== '>')
1632 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1634 /* Now update the old "stub" type into a real type. */
1635 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1636 TYPE_DOMAIN_TYPE (mtype
) = type
;
1637 TYPE_FIELDS (mtype
) = argtypes
;
1638 TYPE_NFIELDS (mtype
) = argcount
;
1639 TYPE_STUB (mtype
) = 0;
1640 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1642 TYPE_VARARGS (mtype
) = 1;
1644 xfree (demangled_name
);
1647 /* This is the external interface to check_stub_method, above. This
1648 function unstubs all of the signatures for TYPE's METHOD_ID method
1649 name. After calling this function TYPE_FN_FIELD_STUB will be
1650 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1653 This function unfortunately can not die until stabs do. */
1656 check_stub_method_group (struct type
*type
, int method_id
)
1658 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1659 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1660 int j
, found_stub
= 0;
1662 for (j
= 0; j
< len
; j
++)
1663 if (TYPE_FN_FIELD_STUB (f
, j
))
1666 check_stub_method (type
, method_id
, j
);
1669 /* GNU v3 methods with incorrect names were corrected when we read
1670 in type information, because it was cheaper to do it then. The
1671 only GNU v2 methods with incorrect method names are operators and
1672 destructors; destructors were also corrected when we read in type
1675 Therefore the only thing we need to handle here are v2 operator
1677 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1680 char dem_opname
[256];
1682 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1684 dem_opname
, DMGL_ANSI
);
1686 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1690 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1694 const struct cplus_struct_type cplus_struct_default
;
1697 allocate_cplus_struct_type (struct type
*type
)
1699 if (!HAVE_CPLUS_STRUCT (type
))
1701 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1702 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1703 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1707 /* Helper function to initialize the standard scalar types.
1709 If NAME is non-NULL, then we make a copy of the string pointed
1710 to by name in the objfile_obstack for that objfile, and initialize
1711 the type name to that copy. There are places (mipsread.c in particular),
1712 where init_type is called with a NULL value for NAME). */
1715 init_type (enum type_code code
, int length
, int flags
,
1716 char *name
, struct objfile
*objfile
)
1720 type
= alloc_type (objfile
);
1721 TYPE_CODE (type
) = code
;
1722 TYPE_LENGTH (type
) = length
;
1724 gdb_assert (!(flags
& (TYPE_FLAG_MIN
- 1)));
1725 if (flags
& TYPE_FLAG_UNSIGNED
)
1726 TYPE_UNSIGNED (type
) = 1;
1727 if (flags
& TYPE_FLAG_NOSIGN
)
1728 TYPE_NOSIGN (type
) = 1;
1729 if (flags
& TYPE_FLAG_STUB
)
1730 TYPE_STUB (type
) = 1;
1731 if (flags
& TYPE_FLAG_TARGET_STUB
)
1732 TYPE_TARGET_STUB (type
) = 1;
1733 if (flags
& TYPE_FLAG_STATIC
)
1734 TYPE_STATIC (type
) = 1;
1735 if (flags
& TYPE_FLAG_PROTOTYPED
)
1736 TYPE_PROTOTYPED (type
) = 1;
1737 if (flags
& TYPE_FLAG_INCOMPLETE
)
1738 TYPE_INCOMPLETE (type
) = 1;
1739 if (flags
& TYPE_FLAG_VARARGS
)
1740 TYPE_VARARGS (type
) = 1;
1741 if (flags
& TYPE_FLAG_VECTOR
)
1742 TYPE_VECTOR (type
) = 1;
1743 if (flags
& TYPE_FLAG_STUB_SUPPORTED
)
1744 TYPE_STUB_SUPPORTED (type
) = 1;
1745 if (flags
& TYPE_FLAG_NOTTEXT
)
1746 TYPE_NOTTEXT (type
) = 1;
1747 if (flags
& TYPE_FLAG_FIXED_INSTANCE
)
1748 TYPE_FIXED_INSTANCE (type
) = 1;
1751 TYPE_NAME (type
) = obsavestring (name
, strlen (name
),
1752 &objfile
->objfile_obstack
);
1756 if (name
&& strcmp (name
, "char") == 0)
1757 TYPE_NOSIGN (type
) = 1;
1759 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
1760 || code
== TYPE_CODE_NAMESPACE
)
1762 INIT_CPLUS_SPECIFIC (type
);
1768 can_dereference (struct type
*t
)
1770 /* FIXME: Should we return true for references as well as
1775 && TYPE_CODE (t
) == TYPE_CODE_PTR
1776 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1780 is_integral_type (struct type
*t
)
1785 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1786 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1787 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
1788 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1789 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1790 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1793 /* Check whether BASE is an ancestor or base class or DCLASS
1794 Return 1 if so, and 0 if not.
1795 Note: callers may want to check for identity of the types before
1796 calling this function -- identical types are considered to satisfy
1797 the ancestor relationship even if they're identical. */
1800 is_ancestor (struct type
*base
, struct type
*dclass
)
1804 CHECK_TYPEDEF (base
);
1805 CHECK_TYPEDEF (dclass
);
1809 if (TYPE_NAME (base
) && TYPE_NAME (dclass
)
1810 && !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1813 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1814 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1822 /* Functions for overload resolution begin here */
1824 /* Compare two badness vectors A and B and return the result.
1825 0 => A and B are identical
1826 1 => A and B are incomparable
1827 2 => A is better than B
1828 3 => A is worse than B */
1831 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
1835 short found_pos
= 0; /* any positives in c? */
1836 short found_neg
= 0; /* any negatives in c? */
1838 /* differing lengths => incomparable */
1839 if (a
->length
!= b
->length
)
1842 /* Subtract b from a */
1843 for (i
= 0; i
< a
->length
; i
++)
1845 tmp
= a
->rank
[i
] - b
->rank
[i
];
1855 return 1; /* incomparable */
1857 return 3; /* A > B */
1863 return 2; /* A < B */
1865 return 0; /* A == B */
1869 /* Rank a function by comparing its parameter types (PARMS, length
1870 NPARMS), to the types of an argument list (ARGS, length NARGS).
1871 Return a pointer to a badness vector. This has NARGS + 1
1874 struct badness_vector
*
1875 rank_function (struct type
**parms
, int nparms
,
1876 struct type
**args
, int nargs
)
1879 struct badness_vector
*bv
;
1880 int min_len
= nparms
< nargs
? nparms
: nargs
;
1882 bv
= xmalloc (sizeof (struct badness_vector
));
1883 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
1884 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
1886 /* First compare the lengths of the supplied lists.
1887 If there is a mismatch, set it to a high value. */
1889 /* pai/1997-06-03 FIXME: when we have debug info about default
1890 arguments and ellipsis parameter lists, we should consider those
1891 and rank the length-match more finely. */
1893 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
1895 /* Now rank all the parameters of the candidate function */
1896 for (i
= 1; i
<= min_len
; i
++)
1897 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
1899 /* If more arguments than parameters, add dummy entries */
1900 for (i
= min_len
+ 1; i
<= nargs
; i
++)
1901 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
1906 /* Compare the names of two integer types, assuming that any sign
1907 qualifiers have been checked already. We do it this way because
1908 there may be an "int" in the name of one of the types. */
1911 integer_types_same_name_p (const char *first
, const char *second
)
1913 int first_p
, second_p
;
1915 /* If both are shorts, return 1; if neither is a short, keep
1917 first_p
= (strstr (first
, "short") != NULL
);
1918 second_p
= (strstr (second
, "short") != NULL
);
1919 if (first_p
&& second_p
)
1921 if (first_p
|| second_p
)
1924 /* Likewise for long. */
1925 first_p
= (strstr (first
, "long") != NULL
);
1926 second_p
= (strstr (second
, "long") != NULL
);
1927 if (first_p
&& second_p
)
1929 if (first_p
|| second_p
)
1932 /* Likewise for char. */
1933 first_p
= (strstr (first
, "char") != NULL
);
1934 second_p
= (strstr (second
, "char") != NULL
);
1935 if (first_p
&& second_p
)
1937 if (first_p
|| second_p
)
1940 /* They must both be ints. */
1944 /* Compare one type (PARM) for compatibility with another (ARG).
1945 * PARM is intended to be the parameter type of a function; and
1946 * ARG is the supplied argument's type. This function tests if
1947 * the latter can be converted to the former.
1949 * Return 0 if they are identical types;
1950 * Otherwise, return an integer which corresponds to how compatible
1951 * PARM is to ARG. The higher the return value, the worse the match.
1952 * Generally the "bad" conversions are all uniformly assigned a 100. */
1955 rank_one_type (struct type
*parm
, struct type
*arg
)
1957 /* Identical type pointers. */
1958 /* However, this still doesn't catch all cases of same type for arg
1959 and param. The reason is that builtin types are different from
1960 the same ones constructed from the object. */
1964 /* Resolve typedefs */
1965 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
1966 parm
= check_typedef (parm
);
1967 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
1968 arg
= check_typedef (arg
);
1971 Well, damnit, if the names are exactly the same, I'll say they
1972 are exactly the same. This happens when we generate method
1973 stubs. The types won't point to the same address, but they
1974 really are the same.
1977 if (TYPE_NAME (parm
) && TYPE_NAME (arg
)
1978 && !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
1981 /* Check if identical after resolving typedefs. */
1985 /* See through references, since we can almost make non-references
1987 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
1988 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
1989 + REFERENCE_CONVERSION_BADNESS
);
1990 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
1991 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
1992 + REFERENCE_CONVERSION_BADNESS
);
1994 /* Debugging only. */
1995 fprintf_filtered (gdb_stderr
,
1996 "------ Arg is %s [%d], parm is %s [%d]\n",
1997 TYPE_NAME (arg
), TYPE_CODE (arg
),
1998 TYPE_NAME (parm
), TYPE_CODE (parm
));
2000 /* x -> y means arg of type x being supplied for parameter of type y */
2002 switch (TYPE_CODE (parm
))
2005 switch (TYPE_CODE (arg
))
2008 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
2009 && TYPE_CODE (TYPE_TARGET_TYPE (arg
)) != TYPE_CODE_VOID
)
2010 return VOID_PTR_CONVERSION_BADNESS
;
2012 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2013 TYPE_TARGET_TYPE (arg
));
2014 case TYPE_CODE_ARRAY
:
2015 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2016 TYPE_TARGET_TYPE (arg
));
2017 case TYPE_CODE_FUNC
:
2018 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2020 case TYPE_CODE_ENUM
:
2021 case TYPE_CODE_FLAGS
:
2022 case TYPE_CODE_CHAR
:
2023 case TYPE_CODE_RANGE
:
2024 case TYPE_CODE_BOOL
:
2025 return POINTER_CONVERSION_BADNESS
;
2027 return INCOMPATIBLE_TYPE_BADNESS
;
2029 case TYPE_CODE_ARRAY
:
2030 switch (TYPE_CODE (arg
))
2033 case TYPE_CODE_ARRAY
:
2034 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2035 TYPE_TARGET_TYPE (arg
));
2037 return INCOMPATIBLE_TYPE_BADNESS
;
2039 case TYPE_CODE_FUNC
:
2040 switch (TYPE_CODE (arg
))
2042 case TYPE_CODE_PTR
: /* funcptr -> func */
2043 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2045 return INCOMPATIBLE_TYPE_BADNESS
;
2048 switch (TYPE_CODE (arg
))
2051 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2053 /* Deal with signed, unsigned, and plain chars and
2054 signed and unsigned ints. */
2055 if (TYPE_NOSIGN (parm
))
2057 /* This case only for character types */
2058 if (TYPE_NOSIGN (arg
))
2059 return 0; /* plain char -> plain char */
2060 else /* signed/unsigned char -> plain char */
2061 return INTEGER_CONVERSION_BADNESS
;
2063 else if (TYPE_UNSIGNED (parm
))
2065 if (TYPE_UNSIGNED (arg
))
2067 /* unsigned int -> unsigned int, or
2068 unsigned long -> unsigned long */
2069 if (integer_types_same_name_p (TYPE_NAME (parm
),
2072 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2074 && integer_types_same_name_p (TYPE_NAME (parm
),
2076 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2078 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2082 if (integer_types_same_name_p (TYPE_NAME (arg
),
2084 && integer_types_same_name_p (TYPE_NAME (parm
),
2086 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2088 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2091 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2093 if (integer_types_same_name_p (TYPE_NAME (parm
),
2096 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2098 && integer_types_same_name_p (TYPE_NAME (parm
),
2100 return INTEGER_PROMOTION_BADNESS
;
2102 return INTEGER_CONVERSION_BADNESS
;
2105 return INTEGER_CONVERSION_BADNESS
;
2107 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2108 return INTEGER_PROMOTION_BADNESS
;
2110 return INTEGER_CONVERSION_BADNESS
;
2111 case TYPE_CODE_ENUM
:
2112 case TYPE_CODE_FLAGS
:
2113 case TYPE_CODE_CHAR
:
2114 case TYPE_CODE_RANGE
:
2115 case TYPE_CODE_BOOL
:
2116 return INTEGER_PROMOTION_BADNESS
;
2118 return INT_FLOAT_CONVERSION_BADNESS
;
2120 return NS_POINTER_CONVERSION_BADNESS
;
2122 return INCOMPATIBLE_TYPE_BADNESS
;
2125 case TYPE_CODE_ENUM
:
2126 switch (TYPE_CODE (arg
))
2129 case TYPE_CODE_CHAR
:
2130 case TYPE_CODE_RANGE
:
2131 case TYPE_CODE_BOOL
:
2132 case TYPE_CODE_ENUM
:
2133 return INTEGER_CONVERSION_BADNESS
;
2135 return INT_FLOAT_CONVERSION_BADNESS
;
2137 return INCOMPATIBLE_TYPE_BADNESS
;
2140 case TYPE_CODE_CHAR
:
2141 switch (TYPE_CODE (arg
))
2143 case TYPE_CODE_RANGE
:
2144 case TYPE_CODE_BOOL
:
2145 case TYPE_CODE_ENUM
:
2146 return INTEGER_CONVERSION_BADNESS
;
2148 return INT_FLOAT_CONVERSION_BADNESS
;
2150 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2151 return INTEGER_CONVERSION_BADNESS
;
2152 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2153 return INTEGER_PROMOTION_BADNESS
;
2154 /* >>> !! else fall through !! <<< */
2155 case TYPE_CODE_CHAR
:
2156 /* Deal with signed, unsigned, and plain chars for C++ and
2157 with int cases falling through from previous case. */
2158 if (TYPE_NOSIGN (parm
))
2160 if (TYPE_NOSIGN (arg
))
2163 return INTEGER_CONVERSION_BADNESS
;
2165 else if (TYPE_UNSIGNED (parm
))
2167 if (TYPE_UNSIGNED (arg
))
2170 return INTEGER_PROMOTION_BADNESS
;
2172 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2175 return INTEGER_CONVERSION_BADNESS
;
2177 return INCOMPATIBLE_TYPE_BADNESS
;
2180 case TYPE_CODE_RANGE
:
2181 switch (TYPE_CODE (arg
))
2184 case TYPE_CODE_CHAR
:
2185 case TYPE_CODE_RANGE
:
2186 case TYPE_CODE_BOOL
:
2187 case TYPE_CODE_ENUM
:
2188 return INTEGER_CONVERSION_BADNESS
;
2190 return INT_FLOAT_CONVERSION_BADNESS
;
2192 return INCOMPATIBLE_TYPE_BADNESS
;
2195 case TYPE_CODE_BOOL
:
2196 switch (TYPE_CODE (arg
))
2199 case TYPE_CODE_CHAR
:
2200 case TYPE_CODE_RANGE
:
2201 case TYPE_CODE_ENUM
:
2204 return BOOLEAN_CONVERSION_BADNESS
;
2205 case TYPE_CODE_BOOL
:
2208 return INCOMPATIBLE_TYPE_BADNESS
;
2212 switch (TYPE_CODE (arg
))
2215 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2216 return FLOAT_PROMOTION_BADNESS
;
2217 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2220 return FLOAT_CONVERSION_BADNESS
;
2222 case TYPE_CODE_BOOL
:
2223 case TYPE_CODE_ENUM
:
2224 case TYPE_CODE_RANGE
:
2225 case TYPE_CODE_CHAR
:
2226 return INT_FLOAT_CONVERSION_BADNESS
;
2228 return INCOMPATIBLE_TYPE_BADNESS
;
2231 case TYPE_CODE_COMPLEX
:
2232 switch (TYPE_CODE (arg
))
2233 { /* Strictly not needed for C++, but... */
2235 return FLOAT_PROMOTION_BADNESS
;
2236 case TYPE_CODE_COMPLEX
:
2239 return INCOMPATIBLE_TYPE_BADNESS
;
2242 case TYPE_CODE_STRUCT
:
2243 /* currently same as TYPE_CODE_CLASS */
2244 switch (TYPE_CODE (arg
))
2246 case TYPE_CODE_STRUCT
:
2247 /* Check for derivation */
2248 if (is_ancestor (parm
, arg
))
2249 return BASE_CONVERSION_BADNESS
;
2250 /* else fall through */
2252 return INCOMPATIBLE_TYPE_BADNESS
;
2255 case TYPE_CODE_UNION
:
2256 switch (TYPE_CODE (arg
))
2258 case TYPE_CODE_UNION
:
2260 return INCOMPATIBLE_TYPE_BADNESS
;
2263 case TYPE_CODE_MEMBERPTR
:
2264 switch (TYPE_CODE (arg
))
2267 return INCOMPATIBLE_TYPE_BADNESS
;
2270 case TYPE_CODE_METHOD
:
2271 switch (TYPE_CODE (arg
))
2275 return INCOMPATIBLE_TYPE_BADNESS
;
2279 switch (TYPE_CODE (arg
))
2283 return INCOMPATIBLE_TYPE_BADNESS
;
2288 switch (TYPE_CODE (arg
))
2292 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0),
2293 TYPE_FIELD_TYPE (arg
, 0));
2295 return INCOMPATIBLE_TYPE_BADNESS
;
2298 case TYPE_CODE_VOID
:
2300 return INCOMPATIBLE_TYPE_BADNESS
;
2301 } /* switch (TYPE_CODE (arg)) */
2305 /* End of functions for overload resolution */
2308 print_bit_vector (B_TYPE
*bits
, int nbits
)
2312 for (bitno
= 0; bitno
< nbits
; bitno
++)
2314 if ((bitno
% 8) == 0)
2316 puts_filtered (" ");
2318 if (B_TST (bits
, bitno
))
2319 printf_filtered (("1"));
2321 printf_filtered (("0"));
2325 /* Note the first arg should be the "this" pointer, we may not want to
2326 include it since we may get into a infinitely recursive
2330 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2336 for (i
= 0; i
< nargs
; i
++)
2337 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2342 field_is_static (struct field
*f
)
2344 /* "static" fields are the fields whose location is not relative
2345 to the address of the enclosing struct. It would be nice to
2346 have a dedicated flag that would be set for static fields when
2347 the type is being created. But in practice, checking the field
2348 loc_kind should give us an accurate answer (at least as long as
2349 we assume that DWARF block locations are not going to be used
2350 for static fields). FIXME? */
2351 return (FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSNAME
2352 || FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSADDR
);
2356 dump_fn_fieldlists (struct type
*type
, int spaces
)
2362 printfi_filtered (spaces
, "fn_fieldlists ");
2363 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2364 printf_filtered ("\n");
2365 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2367 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2368 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2370 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2371 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2373 printf_filtered (_(") length %d\n"),
2374 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2375 for (overload_idx
= 0;
2376 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2379 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2381 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2382 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2384 printf_filtered (")\n");
2385 printfi_filtered (spaces
+ 8, "type ");
2386 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2388 printf_filtered ("\n");
2390 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2393 printfi_filtered (spaces
+ 8, "args ");
2394 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2396 printf_filtered ("\n");
2398 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2399 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
,
2402 printfi_filtered (spaces
+ 8, "fcontext ");
2403 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2405 printf_filtered ("\n");
2407 printfi_filtered (spaces
+ 8, "is_const %d\n",
2408 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2409 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2410 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2411 printfi_filtered (spaces
+ 8, "is_private %d\n",
2412 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2413 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2414 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2415 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2416 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2417 printfi_filtered (spaces
+ 8, "voffset %u\n",
2418 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2424 print_cplus_stuff (struct type
*type
, int spaces
)
2426 printfi_filtered (spaces
, "n_baseclasses %d\n",
2427 TYPE_N_BASECLASSES (type
));
2428 printfi_filtered (spaces
, "nfn_fields %d\n",
2429 TYPE_NFN_FIELDS (type
));
2430 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2431 TYPE_NFN_FIELDS_TOTAL (type
));
2432 if (TYPE_N_BASECLASSES (type
) > 0)
2434 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2435 TYPE_N_BASECLASSES (type
));
2436 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
),
2438 printf_filtered (")");
2440 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2441 TYPE_N_BASECLASSES (type
));
2442 puts_filtered ("\n");
2444 if (TYPE_NFIELDS (type
) > 0)
2446 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2448 printfi_filtered (spaces
,
2449 "private_field_bits (%d bits at *",
2450 TYPE_NFIELDS (type
));
2451 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
),
2453 printf_filtered (")");
2454 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2455 TYPE_NFIELDS (type
));
2456 puts_filtered ("\n");
2458 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2460 printfi_filtered (spaces
,
2461 "protected_field_bits (%d bits at *",
2462 TYPE_NFIELDS (type
));
2463 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
),
2465 printf_filtered (")");
2466 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2467 TYPE_NFIELDS (type
));
2468 puts_filtered ("\n");
2471 if (TYPE_NFN_FIELDS (type
) > 0)
2473 dump_fn_fieldlists (type
, spaces
);
2477 static struct obstack dont_print_type_obstack
;
2480 recursive_dump_type (struct type
*type
, int spaces
)
2485 obstack_begin (&dont_print_type_obstack
, 0);
2487 if (TYPE_NFIELDS (type
) > 0
2488 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2490 struct type
**first_dont_print
2491 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2493 int i
= (struct type
**)
2494 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
2498 if (type
== first_dont_print
[i
])
2500 printfi_filtered (spaces
, "type node ");
2501 gdb_print_host_address (type
, gdb_stdout
);
2502 printf_filtered (_(" <same as already seen type>\n"));
2507 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2510 printfi_filtered (spaces
, "type node ");
2511 gdb_print_host_address (type
, gdb_stdout
);
2512 printf_filtered ("\n");
2513 printfi_filtered (spaces
, "name '%s' (",
2514 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2515 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2516 printf_filtered (")\n");
2517 printfi_filtered (spaces
, "tagname '%s' (",
2518 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2519 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2520 printf_filtered (")\n");
2521 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2522 switch (TYPE_CODE (type
))
2524 case TYPE_CODE_UNDEF
:
2525 printf_filtered ("(TYPE_CODE_UNDEF)");
2528 printf_filtered ("(TYPE_CODE_PTR)");
2530 case TYPE_CODE_ARRAY
:
2531 printf_filtered ("(TYPE_CODE_ARRAY)");
2533 case TYPE_CODE_STRUCT
:
2534 printf_filtered ("(TYPE_CODE_STRUCT)");
2536 case TYPE_CODE_UNION
:
2537 printf_filtered ("(TYPE_CODE_UNION)");
2539 case TYPE_CODE_ENUM
:
2540 printf_filtered ("(TYPE_CODE_ENUM)");
2542 case TYPE_CODE_FLAGS
:
2543 printf_filtered ("(TYPE_CODE_FLAGS)");
2545 case TYPE_CODE_FUNC
:
2546 printf_filtered ("(TYPE_CODE_FUNC)");
2549 printf_filtered ("(TYPE_CODE_INT)");
2552 printf_filtered ("(TYPE_CODE_FLT)");
2554 case TYPE_CODE_VOID
:
2555 printf_filtered ("(TYPE_CODE_VOID)");
2558 printf_filtered ("(TYPE_CODE_SET)");
2560 case TYPE_CODE_RANGE
:
2561 printf_filtered ("(TYPE_CODE_RANGE)");
2563 case TYPE_CODE_STRING
:
2564 printf_filtered ("(TYPE_CODE_STRING)");
2566 case TYPE_CODE_BITSTRING
:
2567 printf_filtered ("(TYPE_CODE_BITSTRING)");
2569 case TYPE_CODE_ERROR
:
2570 printf_filtered ("(TYPE_CODE_ERROR)");
2572 case TYPE_CODE_MEMBERPTR
:
2573 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2575 case TYPE_CODE_METHODPTR
:
2576 printf_filtered ("(TYPE_CODE_METHODPTR)");
2578 case TYPE_CODE_METHOD
:
2579 printf_filtered ("(TYPE_CODE_METHOD)");
2582 printf_filtered ("(TYPE_CODE_REF)");
2584 case TYPE_CODE_CHAR
:
2585 printf_filtered ("(TYPE_CODE_CHAR)");
2587 case TYPE_CODE_BOOL
:
2588 printf_filtered ("(TYPE_CODE_BOOL)");
2590 case TYPE_CODE_COMPLEX
:
2591 printf_filtered ("(TYPE_CODE_COMPLEX)");
2593 case TYPE_CODE_TYPEDEF
:
2594 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2596 case TYPE_CODE_TEMPLATE
:
2597 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2599 case TYPE_CODE_TEMPLATE_ARG
:
2600 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2602 case TYPE_CODE_NAMESPACE
:
2603 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2606 printf_filtered ("(UNKNOWN TYPE CODE)");
2609 puts_filtered ("\n");
2610 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2611 if (TYPE_OBJFILE_OWNED (type
))
2613 printfi_filtered (spaces
, "objfile ");
2614 gdb_print_host_address (TYPE_OWNER (type
).objfile
, gdb_stdout
);
2618 printfi_filtered (spaces
, "gdbarch ");
2619 gdb_print_host_address (TYPE_OWNER (type
).gdbarch
, gdb_stdout
);
2621 printf_filtered ("\n");
2622 printfi_filtered (spaces
, "target_type ");
2623 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2624 printf_filtered ("\n");
2625 if (TYPE_TARGET_TYPE (type
) != NULL
)
2627 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2629 printfi_filtered (spaces
, "pointer_type ");
2630 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2631 printf_filtered ("\n");
2632 printfi_filtered (spaces
, "reference_type ");
2633 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2634 printf_filtered ("\n");
2635 printfi_filtered (spaces
, "type_chain ");
2636 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
2637 printf_filtered ("\n");
2638 printfi_filtered (spaces
, "instance_flags 0x%x",
2639 TYPE_INSTANCE_FLAGS (type
));
2640 if (TYPE_CONST (type
))
2642 puts_filtered (" TYPE_FLAG_CONST");
2644 if (TYPE_VOLATILE (type
))
2646 puts_filtered (" TYPE_FLAG_VOLATILE");
2648 if (TYPE_CODE_SPACE (type
))
2650 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2652 if (TYPE_DATA_SPACE (type
))
2654 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2656 if (TYPE_ADDRESS_CLASS_1 (type
))
2658 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
2660 if (TYPE_ADDRESS_CLASS_2 (type
))
2662 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
2664 puts_filtered ("\n");
2666 printfi_filtered (spaces
, "flags");
2667 if (TYPE_UNSIGNED (type
))
2669 puts_filtered (" TYPE_FLAG_UNSIGNED");
2671 if (TYPE_NOSIGN (type
))
2673 puts_filtered (" TYPE_FLAG_NOSIGN");
2675 if (TYPE_STUB (type
))
2677 puts_filtered (" TYPE_FLAG_STUB");
2679 if (TYPE_TARGET_STUB (type
))
2681 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2683 if (TYPE_STATIC (type
))
2685 puts_filtered (" TYPE_FLAG_STATIC");
2687 if (TYPE_PROTOTYPED (type
))
2689 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2691 if (TYPE_INCOMPLETE (type
))
2693 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2695 if (TYPE_VARARGS (type
))
2697 puts_filtered (" TYPE_FLAG_VARARGS");
2699 /* This is used for things like AltiVec registers on ppc. Gcc emits
2700 an attribute for the array type, which tells whether or not we
2701 have a vector, instead of a regular array. */
2702 if (TYPE_VECTOR (type
))
2704 puts_filtered (" TYPE_FLAG_VECTOR");
2706 if (TYPE_FIXED_INSTANCE (type
))
2708 puts_filtered (" TYPE_FIXED_INSTANCE");
2710 if (TYPE_STUB_SUPPORTED (type
))
2712 puts_filtered (" TYPE_STUB_SUPPORTED");
2714 if (TYPE_NOTTEXT (type
))
2716 puts_filtered (" TYPE_NOTTEXT");
2718 puts_filtered ("\n");
2719 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2720 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
2721 puts_filtered ("\n");
2722 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2724 printfi_filtered (spaces
+ 2,
2725 "[%d] bitpos %d bitsize %d type ",
2726 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2727 TYPE_FIELD_BITSIZE (type
, idx
));
2728 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2729 printf_filtered (" name '%s' (",
2730 TYPE_FIELD_NAME (type
, idx
) != NULL
2731 ? TYPE_FIELD_NAME (type
, idx
)
2733 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2734 printf_filtered (")\n");
2735 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2737 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2740 printfi_filtered (spaces
, "vptr_basetype ");
2741 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2742 puts_filtered ("\n");
2743 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2745 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2747 printfi_filtered (spaces
, "vptr_fieldno %d\n",
2748 TYPE_VPTR_FIELDNO (type
));
2749 switch (TYPE_CODE (type
))
2751 case TYPE_CODE_STRUCT
:
2752 printfi_filtered (spaces
, "cplus_stuff ");
2753 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
),
2755 puts_filtered ("\n");
2756 print_cplus_stuff (type
, spaces
);
2760 printfi_filtered (spaces
, "floatformat ");
2761 if (TYPE_FLOATFORMAT (type
) == NULL
)
2762 puts_filtered ("(null)");
2765 puts_filtered ("{ ");
2766 if (TYPE_FLOATFORMAT (type
)[0] == NULL
2767 || TYPE_FLOATFORMAT (type
)[0]->name
== NULL
)
2768 puts_filtered ("(null)");
2770 puts_filtered (TYPE_FLOATFORMAT (type
)[0]->name
);
2772 puts_filtered (", ");
2773 if (TYPE_FLOATFORMAT (type
)[1] == NULL
2774 || TYPE_FLOATFORMAT (type
)[1]->name
== NULL
)
2775 puts_filtered ("(null)");
2777 puts_filtered (TYPE_FLOATFORMAT (type
)[1]->name
);
2779 puts_filtered (" }");
2781 puts_filtered ("\n");
2785 /* We have to pick one of the union types to be able print and
2786 test the value. Pick cplus_struct_type, even though we know
2787 it isn't any particular one. */
2788 printfi_filtered (spaces
, "type_specific ");
2789 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2790 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
2792 printf_filtered (_(" (unknown data form)"));
2794 printf_filtered ("\n");
2799 obstack_free (&dont_print_type_obstack
, NULL
);
2802 /* Trivial helpers for the libiberty hash table, for mapping one
2807 struct type
*old
, *new;
2811 type_pair_hash (const void *item
)
2813 const struct type_pair
*pair
= item
;
2814 return htab_hash_pointer (pair
->old
);
2818 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
2820 const struct type_pair
*lhs
= item_lhs
, *rhs
= item_rhs
;
2821 return lhs
->old
== rhs
->old
;
2824 /* Allocate the hash table used by copy_type_recursive to walk
2825 types without duplicates. We use OBJFILE's obstack, because
2826 OBJFILE is about to be deleted. */
2829 create_copied_types_hash (struct objfile
*objfile
)
2831 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
2832 NULL
, &objfile
->objfile_obstack
,
2833 hashtab_obstack_allocate
,
2834 dummy_obstack_deallocate
);
2837 /* Recursively copy (deep copy) TYPE, if it is associated with
2838 OBJFILE. Return a new type allocated using malloc, a saved type if
2839 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
2840 not associated with OBJFILE. */
2843 copy_type_recursive (struct objfile
*objfile
,
2845 htab_t copied_types
)
2847 struct type_pair
*stored
, pair
;
2849 struct type
*new_type
;
2851 if (! TYPE_OBJFILE_OWNED (type
))
2854 /* This type shouldn't be pointing to any types in other objfiles;
2855 if it did, the type might disappear unexpectedly. */
2856 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
2859 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
2861 return ((struct type_pair
*) *slot
)->new;
2863 new_type
= alloc_type_arch (get_type_arch (type
));
2865 /* We must add the new type to the hash table immediately, in case
2866 we encounter this type again during a recursive call below. */
2867 stored
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct type_pair
));
2869 stored
->new = new_type
;
2872 /* Copy the common fields of types. For the main type, we simply
2873 copy the entire thing and then update specific fields as needed. */
2874 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
2875 TYPE_OBJFILE_OWNED (new_type
) = 0;
2876 TYPE_OWNER (new_type
).gdbarch
= get_type_arch (type
);
2878 if (TYPE_NAME (type
))
2879 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
2880 if (TYPE_TAG_NAME (type
))
2881 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
2883 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
2884 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
2886 /* Copy the fields. */
2887 if (TYPE_NFIELDS (type
))
2891 nfields
= TYPE_NFIELDS (type
);
2892 TYPE_FIELDS (new_type
) = XCALLOC (nfields
, struct field
);
2893 for (i
= 0; i
< nfields
; i
++)
2895 TYPE_FIELD_ARTIFICIAL (new_type
, i
) =
2896 TYPE_FIELD_ARTIFICIAL (type
, i
);
2897 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
2898 if (TYPE_FIELD_TYPE (type
, i
))
2899 TYPE_FIELD_TYPE (new_type
, i
)
2900 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
2902 if (TYPE_FIELD_NAME (type
, i
))
2903 TYPE_FIELD_NAME (new_type
, i
) =
2904 xstrdup (TYPE_FIELD_NAME (type
, i
));
2905 switch (TYPE_FIELD_LOC_KIND (type
, i
))
2907 case FIELD_LOC_KIND_BITPOS
:
2908 SET_FIELD_BITPOS (TYPE_FIELD (new_type
, i
),
2909 TYPE_FIELD_BITPOS (type
, i
));
2911 case FIELD_LOC_KIND_PHYSADDR
:
2912 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
2913 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
2915 case FIELD_LOC_KIND_PHYSNAME
:
2916 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
2917 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
,
2921 internal_error (__FILE__
, __LINE__
,
2922 _("Unexpected type field location kind: %d"),
2923 TYPE_FIELD_LOC_KIND (type
, i
));
2928 /* Copy pointers to other types. */
2929 if (TYPE_TARGET_TYPE (type
))
2930 TYPE_TARGET_TYPE (new_type
) =
2931 copy_type_recursive (objfile
,
2932 TYPE_TARGET_TYPE (type
),
2934 if (TYPE_VPTR_BASETYPE (type
))
2935 TYPE_VPTR_BASETYPE (new_type
) =
2936 copy_type_recursive (objfile
,
2937 TYPE_VPTR_BASETYPE (type
),
2939 /* Maybe copy the type_specific bits.
2941 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
2942 base classes and methods. There's no fundamental reason why we
2943 can't, but at the moment it is not needed. */
2945 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2946 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
2947 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
2948 || TYPE_CODE (type
) == TYPE_CODE_UNION
2949 || TYPE_CODE (type
) == TYPE_CODE_TEMPLATE
2950 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
2951 INIT_CPLUS_SPECIFIC (new_type
);
2956 /* Make a copy of the given TYPE, except that the pointer & reference
2957 types are not preserved.
2959 This function assumes that the given type has an associated objfile.
2960 This objfile is used to allocate the new type. */
2963 copy_type (const struct type
*type
)
2965 struct type
*new_type
;
2967 gdb_assert (TYPE_OBJFILE_OWNED (type
));
2969 new_type
= alloc_type_copy (type
);
2970 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
2971 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
2972 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
2973 sizeof (struct main_type
));
2979 /* Helper functions to initialize architecture-specific types. */
2981 /* Allocate a type structure associated with GDBARCH and set its
2982 CODE, LENGTH, and NAME fields. */
2984 arch_type (struct gdbarch
*gdbarch
,
2985 enum type_code code
, int length
, char *name
)
2989 type
= alloc_type_arch (gdbarch
);
2990 TYPE_CODE (type
) = code
;
2991 TYPE_LENGTH (type
) = length
;
2994 TYPE_NAME (type
) = xstrdup (name
);
2999 /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH.
3000 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3001 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3003 arch_integer_type (struct gdbarch
*gdbarch
,
3004 int bit
, int unsigned_p
, char *name
)
3008 t
= arch_type (gdbarch
, TYPE_CODE_INT
, bit
/ TARGET_CHAR_BIT
, name
);
3010 TYPE_UNSIGNED (t
) = 1;
3011 if (name
&& strcmp (name
, "char") == 0)
3012 TYPE_NOSIGN (t
) = 1;
3017 /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH.
3018 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3019 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3021 arch_character_type (struct gdbarch
*gdbarch
,
3022 int bit
, int unsigned_p
, char *name
)
3026 t
= arch_type (gdbarch
, TYPE_CODE_CHAR
, bit
/ TARGET_CHAR_BIT
, name
);
3028 TYPE_UNSIGNED (t
) = 1;
3033 /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH.
3034 BIT is the type size in bits. If UNSIGNED_P is non-zero, set
3035 the type's TYPE_UNSIGNED flag. NAME is the type name. */
3037 arch_boolean_type (struct gdbarch
*gdbarch
,
3038 int bit
, int unsigned_p
, char *name
)
3042 t
= arch_type (gdbarch
, TYPE_CODE_BOOL
, bit
/ TARGET_CHAR_BIT
, name
);
3044 TYPE_UNSIGNED (t
) = 1;
3049 /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH.
3050 BIT is the type size in bits; if BIT equals -1, the size is
3051 determined by the floatformat. NAME is the type name. Set the
3052 TYPE_FLOATFORMAT from FLOATFORMATS. */
3054 arch_float_type (struct gdbarch
*gdbarch
,
3055 int bit
, char *name
, const struct floatformat
**floatformats
)
3061 gdb_assert (floatformats
!= NULL
);
3062 gdb_assert (floatformats
[0] != NULL
&& floatformats
[1] != NULL
);
3063 bit
= floatformats
[0]->totalsize
;
3065 gdb_assert (bit
>= 0);
3067 t
= arch_type (gdbarch
, TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
, name
);
3068 TYPE_FLOATFORMAT (t
) = floatformats
;
3072 /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
3073 NAME is the type name. TARGET_TYPE is the component float type. */
3075 arch_complex_type (struct gdbarch
*gdbarch
,
3076 char *name
, struct type
*target_type
)
3079 t
= arch_type (gdbarch
, TYPE_CODE_COMPLEX
,
3080 2 * TYPE_LENGTH (target_type
), name
);
3081 TYPE_TARGET_TYPE (t
) = target_type
;
3085 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
3086 NAME is the type name. LENGTH is the number of flag bits. */
3088 arch_flags_type (struct gdbarch
*gdbarch
, char *name
, int length
)
3090 int nfields
= length
* TARGET_CHAR_BIT
;
3093 type
= arch_type (gdbarch
, TYPE_CODE_FLAGS
, length
, name
);
3094 TYPE_UNSIGNED (type
) = 1;
3095 TYPE_NFIELDS (type
) = nfields
;
3096 TYPE_FIELDS (type
) = TYPE_ZALLOC (type
, nfields
* sizeof (struct field
));
3101 /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at
3102 position BITPOS is called NAME. */
3104 append_flags_type_flag (struct type
*type
, int bitpos
, char *name
)
3106 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
3107 gdb_assert (bitpos
< TYPE_NFIELDS (type
));
3108 gdb_assert (bitpos
>= 0);
3112 TYPE_FIELD_NAME (type
, bitpos
) = xstrdup (name
);
3113 TYPE_FIELD_BITPOS (type
, bitpos
) = bitpos
;
3117 /* Don't show this field to the user. */
3118 TYPE_FIELD_BITPOS (type
, bitpos
) = -1;
3122 /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as
3123 specified by CODE) associated with GDBARCH. NAME is the type name. */
3125 arch_composite_type (struct gdbarch
*gdbarch
, char *name
, enum type_code code
)
3128 gdb_assert (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
);
3129 t
= arch_type (gdbarch
, code
, 0, NULL
);
3130 TYPE_TAG_NAME (t
) = name
;
3131 INIT_CPLUS_SPECIFIC (t
);
3135 /* Add new field with name NAME and type FIELD to composite type T.
3136 ALIGNMENT (if non-zero) specifies the minimum field alignment. */
3138 append_composite_type_field_aligned (struct type
*t
, char *name
,
3139 struct type
*field
, int alignment
)
3142 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
3143 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
3144 sizeof (struct field
) * TYPE_NFIELDS (t
));
3145 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
3146 memset (f
, 0, sizeof f
[0]);
3147 FIELD_TYPE (f
[0]) = field
;
3148 FIELD_NAME (f
[0]) = name
;
3149 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
3151 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
3152 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
3154 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
3156 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
3157 if (TYPE_NFIELDS (t
) > 1)
3159 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
3160 + (TYPE_LENGTH (FIELD_TYPE (f
[-1]))
3161 * TARGET_CHAR_BIT
));
3165 int left
= FIELD_BITPOS (f
[0]) % (alignment
* TARGET_CHAR_BIT
);
3168 FIELD_BITPOS (f
[0]) += left
;
3169 TYPE_LENGTH (t
) += left
/ TARGET_CHAR_BIT
;
3176 /* Add new field with name NAME and type FIELD to composite type T. */
3178 append_composite_type_field (struct type
*t
, char *name
,
3181 append_composite_type_field_aligned (t
, name
, field
, 0);
3185 static struct gdbarch_data
*gdbtypes_data
;
3187 const struct builtin_type
*
3188 builtin_type (struct gdbarch
*gdbarch
)
3190 return gdbarch_data (gdbarch
, gdbtypes_data
);
3194 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3196 struct builtin_type
*builtin_type
3197 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3200 builtin_type
->builtin_void
3201 = arch_type (gdbarch
, TYPE_CODE_VOID
, 1, "void");
3202 builtin_type
->builtin_char
3203 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
3204 !gdbarch_char_signed (gdbarch
), "char");
3205 builtin_type
->builtin_signed_char
3206 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
3208 builtin_type
->builtin_unsigned_char
3209 = arch_integer_type (gdbarch
, TARGET_CHAR_BIT
,
3210 1, "unsigned char");
3211 builtin_type
->builtin_short
3212 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
3214 builtin_type
->builtin_unsigned_short
3215 = arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
3216 1, "unsigned short");
3217 builtin_type
->builtin_int
3218 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
3220 builtin_type
->builtin_unsigned_int
3221 = arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
3223 builtin_type
->builtin_long
3224 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
3226 builtin_type
->builtin_unsigned_long
3227 = arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
3228 1, "unsigned long");
3229 builtin_type
->builtin_long_long
3230 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
3232 builtin_type
->builtin_unsigned_long_long
3233 = arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
3234 1, "unsigned long long");
3235 builtin_type
->builtin_float
3236 = arch_float_type (gdbarch
, gdbarch_float_bit (gdbarch
),
3237 "float", gdbarch_float_format (gdbarch
));
3238 builtin_type
->builtin_double
3239 = arch_float_type (gdbarch
, gdbarch_double_bit (gdbarch
),
3240 "double", gdbarch_double_format (gdbarch
));
3241 builtin_type
->builtin_long_double
3242 = arch_float_type (gdbarch
, gdbarch_long_double_bit (gdbarch
),
3243 "long double", gdbarch_long_double_format (gdbarch
));
3244 builtin_type
->builtin_complex
3245 = arch_complex_type (gdbarch
, "complex",
3246 builtin_type
->builtin_float
);
3247 builtin_type
->builtin_double_complex
3248 = arch_complex_type (gdbarch
, "double complex",
3249 builtin_type
->builtin_double
);
3250 builtin_type
->builtin_string
3251 = arch_type (gdbarch
, TYPE_CODE_STRING
, 1, "string");
3252 builtin_type
->builtin_bool
3253 = arch_type (gdbarch
, TYPE_CODE_BOOL
, 1, "bool");
3255 /* The following three are about decimal floating point types, which
3256 are 32-bits, 64-bits and 128-bits respectively. */
3257 builtin_type
->builtin_decfloat
3258 = arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, 32 / 8, "_Decimal32");
3259 builtin_type
->builtin_decdouble
3260 = arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, 64 / 8, "_Decimal64");
3261 builtin_type
->builtin_declong
3262 = arch_type (gdbarch
, TYPE_CODE_DECFLOAT
, 128 / 8, "_Decimal128");
3264 /* "True" character types. */
3265 builtin_type
->builtin_true_char
3266 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 0, "true character");
3267 builtin_type
->builtin_true_unsigned_char
3268 = arch_character_type (gdbarch
, TARGET_CHAR_BIT
, 1, "true character");
3270 /* Fixed-size integer types. */
3271 builtin_type
->builtin_int0
3272 = arch_integer_type (gdbarch
, 0, 0, "int0_t");
3273 builtin_type
->builtin_int8
3274 = arch_integer_type (gdbarch
, 8, 0, "int8_t");
3275 builtin_type
->builtin_uint8
3276 = arch_integer_type (gdbarch
, 8, 1, "uint8_t");
3277 builtin_type
->builtin_int16
3278 = arch_integer_type (gdbarch
, 16, 0, "int16_t");
3279 builtin_type
->builtin_uint16
3280 = arch_integer_type (gdbarch
, 16, 1, "uint16_t");
3281 builtin_type
->builtin_int32
3282 = arch_integer_type (gdbarch
, 32, 0, "int32_t");
3283 builtin_type
->builtin_uint32
3284 = arch_integer_type (gdbarch
, 32, 1, "uint32_t");
3285 builtin_type
->builtin_int64
3286 = arch_integer_type (gdbarch
, 64, 0, "int64_t");
3287 builtin_type
->builtin_uint64
3288 = arch_integer_type (gdbarch
, 64, 1, "uint64_t");
3289 builtin_type
->builtin_int128
3290 = arch_integer_type (gdbarch
, 128, 0, "int128_t");
3291 builtin_type
->builtin_uint128
3292 = arch_integer_type (gdbarch
, 128, 1, "uint128_t");
3293 TYPE_NOTTEXT (builtin_type
->builtin_int8
) = 1;
3294 TYPE_NOTTEXT (builtin_type
->builtin_uint8
) = 1;
3296 /* Default data/code pointer types. */
3297 builtin_type
->builtin_data_ptr
3298 = lookup_pointer_type (builtin_type
->builtin_void
);
3299 builtin_type
->builtin_func_ptr
3300 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3302 /* This type represents a GDB internal function. */
3303 builtin_type
->internal_fn
3304 = arch_type (gdbarch
, TYPE_CODE_INTERNAL_FUNCTION
, 0,
3305 "<internal function>");
3307 return builtin_type
;
3311 /* This set of objfile-based types is intended to be used by symbol
3312 readers as basic types. */
3314 static const struct objfile_data
*objfile_type_data
;
3316 const struct objfile_type
*
3317 objfile_type (struct objfile
*objfile
)
3319 struct gdbarch
*gdbarch
;
3320 struct objfile_type
*objfile_type
3321 = objfile_data (objfile
, objfile_type_data
);
3324 return objfile_type
;
3326 objfile_type
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3327 1, struct objfile_type
);
3329 /* Use the objfile architecture to determine basic type properties. */
3330 gdbarch
= get_objfile_arch (objfile
);
3333 objfile_type
->builtin_void
3334 = init_type (TYPE_CODE_VOID
, 1,
3338 objfile_type
->builtin_char
3339 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3341 | (gdbarch_char_signed (gdbarch
) ? 0 : TYPE_FLAG_UNSIGNED
)),
3343 objfile_type
->builtin_signed_char
3344 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3346 "signed char", objfile
);
3347 objfile_type
->builtin_unsigned_char
3348 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3350 "unsigned char", objfile
);
3351 objfile_type
->builtin_short
3352 = init_type (TYPE_CODE_INT
,
3353 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3354 0, "short", objfile
);
3355 objfile_type
->builtin_unsigned_short
3356 = init_type (TYPE_CODE_INT
,
3357 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3358 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
3359 objfile_type
->builtin_int
3360 = init_type (TYPE_CODE_INT
,
3361 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3363 objfile_type
->builtin_unsigned_int
3364 = init_type (TYPE_CODE_INT
,
3365 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3366 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
3367 objfile_type
->builtin_long
3368 = init_type (TYPE_CODE_INT
,
3369 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3370 0, "long", objfile
);
3371 objfile_type
->builtin_unsigned_long
3372 = init_type (TYPE_CODE_INT
,
3373 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3374 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
3375 objfile_type
->builtin_long_long
3376 = init_type (TYPE_CODE_INT
,
3377 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3378 0, "long long", objfile
);
3379 objfile_type
->builtin_unsigned_long_long
3380 = init_type (TYPE_CODE_INT
,
3381 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3382 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
3384 objfile_type
->builtin_float
3385 = init_type (TYPE_CODE_FLT
,
3386 gdbarch_float_bit (gdbarch
) / TARGET_CHAR_BIT
,
3387 0, "float", objfile
);
3388 TYPE_FLOATFORMAT (objfile_type
->builtin_float
)
3389 = gdbarch_float_format (gdbarch
);
3390 objfile_type
->builtin_double
3391 = init_type (TYPE_CODE_FLT
,
3392 gdbarch_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
3393 0, "double", objfile
);
3394 TYPE_FLOATFORMAT (objfile_type
->builtin_double
)
3395 = gdbarch_double_format (gdbarch
);
3396 objfile_type
->builtin_long_double
3397 = init_type (TYPE_CODE_FLT
,
3398 gdbarch_long_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
3399 0, "long double", objfile
);
3400 TYPE_FLOATFORMAT (objfile_type
->builtin_long_double
)
3401 = gdbarch_long_double_format (gdbarch
);
3403 /* This type represents a type that was unrecognized in symbol read-in. */
3404 objfile_type
->builtin_error
3405 = init_type (TYPE_CODE_ERROR
, 0, 0, "<unknown type>", objfile
);
3407 /* The following set of types is used for symbols with no
3408 debug information. */
3409 objfile_type
->nodebug_text_symbol
3410 = init_type (TYPE_CODE_FUNC
, 1, 0,
3411 "<text variable, no debug info>", objfile
);
3412 TYPE_TARGET_TYPE (objfile_type
->nodebug_text_symbol
)
3413 = objfile_type
->builtin_int
;
3414 objfile_type
->nodebug_data_symbol
3415 = init_type (TYPE_CODE_INT
,
3416 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3417 "<data variable, no debug info>", objfile
);
3418 objfile_type
->nodebug_unknown_symbol
3419 = init_type (TYPE_CODE_INT
, 1, 0,
3420 "<variable (not text or data), no debug info>", objfile
);
3421 objfile_type
->nodebug_tls_symbol
3422 = init_type (TYPE_CODE_INT
,
3423 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3424 "<thread local variable, no debug info>", objfile
);
3426 /* NOTE: on some targets, addresses and pointers are not necessarily
3427 the same --- for example, on the D10V, pointers are 16 bits long,
3428 but addresses are 32 bits long. See doc/gdbint.texinfo,
3429 ``Pointers Are Not Always Addresses''.
3432 - gdb's `struct type' always describes the target's
3434 - gdb's `struct value' objects should always hold values in
3436 - gdb's CORE_ADDR values are addresses in the unified virtual
3437 address space that the assembler and linker work with. Thus,
3438 since target_read_memory takes a CORE_ADDR as an argument, it
3439 can access any memory on the target, even if the processor has
3440 separate code and data address spaces.
3443 - If v is a value holding a D10V code pointer, its contents are
3444 in target form: a big-endian address left-shifted two bits.
3445 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3446 sizeof (void *) == 2 on the target.
3448 In this context, objfile_type->builtin_core_addr is a bit odd:
3449 it's a target type for a value the target will never see. It's
3450 only used to hold the values of (typeless) linker symbols, which
3451 are indeed in the unified virtual address space. */
3453 objfile_type
->builtin_core_addr
3454 = init_type (TYPE_CODE_INT
,
3455 gdbarch_addr_bit (gdbarch
) / 8,
3456 TYPE_FLAG_UNSIGNED
, "__CORE_ADDR", objfile
);
3458 set_objfile_data (objfile
, objfile_type_data
, objfile_type
);
3459 return objfile_type
;
3463 extern void _initialize_gdbtypes (void);
3465 _initialize_gdbtypes (void)
3467 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
3468 objfile_type_data
= register_objfile_data ();
3470 add_setshow_zinteger_cmd ("overload", no_class
, &overload_debug
, _("\
3471 Set debugging of C++ overloading."), _("\
3472 Show debugging of C++ overloading."), _("\
3473 When enabled, ranking of the functions is displayed."),
3475 show_overload_debug
,
3476 &setdebuglist
, &showdebuglist
);
3478 /* Add user knob for controlling resolution of opaque types. */
3479 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
3480 &opaque_type_resolution
, _("\
3481 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3482 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL
,
3484 show_opaque_type_resolution
,
3485 &setlist
, &showlist
);