1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 2002, 2003, 2004, 2005, 2006, 2007 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"
42 /* These variables point to the objects
43 representing the predefined C data types. */
45 struct type
*builtin_type_int0
;
46 struct type
*builtin_type_int8
;
47 struct type
*builtin_type_uint8
;
48 struct type
*builtin_type_int16
;
49 struct type
*builtin_type_uint16
;
50 struct type
*builtin_type_int32
;
51 struct type
*builtin_type_uint32
;
52 struct type
*builtin_type_int64
;
53 struct type
*builtin_type_uint64
;
54 struct type
*builtin_type_int128
;
55 struct type
*builtin_type_uint128
;
57 /* Floatformat pairs. */
58 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
59 &floatformat_ieee_single_big
,
60 &floatformat_ieee_single_little
62 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
63 &floatformat_ieee_double_big
,
64 &floatformat_ieee_double_little
66 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
67 &floatformat_ieee_double_big
,
68 &floatformat_ieee_double_littlebyte_bigword
70 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
71 &floatformat_i387_ext
,
74 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
75 &floatformat_m68881_ext
,
76 &floatformat_m68881_ext
78 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
79 &floatformat_arm_ext_big
,
80 &floatformat_arm_ext_littlebyte_bigword
82 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
83 &floatformat_ia64_spill_big
,
84 &floatformat_ia64_spill_little
86 const struct floatformat
*floatformats_ia64_quad
[BFD_ENDIAN_UNKNOWN
] = {
87 &floatformat_ia64_quad_big
,
88 &floatformat_ia64_quad_little
90 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
94 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
99 struct type
*builtin_type_ieee_single
;
100 struct type
*builtin_type_ieee_double
;
101 struct type
*builtin_type_i387_ext
;
102 struct type
*builtin_type_m68881_ext
;
103 struct type
*builtin_type_arm_ext
;
104 struct type
*builtin_type_ia64_spill
;
105 struct type
*builtin_type_ia64_quad
;
108 int opaque_type_resolution
= 1;
110 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
111 struct cmd_list_element
*c
,
114 fprintf_filtered (file
, _("\
115 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
119 int overload_debug
= 0;
121 show_overload_debug (struct ui_file
*file
, int from_tty
,
122 struct cmd_list_element
*c
, const char *value
)
124 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"),
132 }; /* Maximum extension is 128! FIXME */
134 static void print_bit_vector (B_TYPE
*, int);
135 static void print_arg_types (struct field
*, int, int);
136 static void dump_fn_fieldlists (struct type
*, int);
137 static void print_cplus_stuff (struct type
*, int);
140 /* Alloc a new type structure and fill it with some defaults. If
141 OBJFILE is non-NULL, then allocate the space for the type structure
142 in that objfile's objfile_obstack. Otherwise allocate the new type
143 structure by xmalloc () (for permanent types). */
146 alloc_type (struct objfile
*objfile
)
150 /* Alloc the structure and start off with all fields zeroed. */
154 type
= xmalloc (sizeof (struct type
));
155 memset (type
, 0, sizeof (struct type
));
156 TYPE_MAIN_TYPE (type
) = xmalloc (sizeof (struct main_type
));
160 type
= obstack_alloc (&objfile
->objfile_obstack
,
161 sizeof (struct type
));
162 memset (type
, 0, sizeof (struct type
));
163 TYPE_MAIN_TYPE (type
) = obstack_alloc (&objfile
->objfile_obstack
,
164 sizeof (struct main_type
));
165 OBJSTAT (objfile
, n_types
++);
167 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
169 /* Initialize the fields that might not be zero. */
171 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
172 TYPE_OBJFILE (type
) = objfile
;
173 TYPE_VPTR_FIELDNO (type
) = -1;
174 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
179 /* Alloc a new type instance structure, fill it with some defaults,
180 and point it at OLDTYPE. Allocate the new type instance from the
181 same place as OLDTYPE. */
184 alloc_type_instance (struct type
*oldtype
)
188 /* Allocate the structure. */
190 if (TYPE_OBJFILE (oldtype
) == NULL
)
192 type
= xmalloc (sizeof (struct type
));
193 memset (type
, 0, sizeof (struct type
));
197 type
= obstack_alloc (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
198 sizeof (struct type
));
199 memset (type
, 0, sizeof (struct type
));
201 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
203 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
208 /* Clear all remnants of the previous type at TYPE, in preparation for
209 replacing it with something else. */
211 smash_type (struct type
*type
)
213 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
215 /* For now, delete the rings. */
216 TYPE_CHAIN (type
) = type
;
218 /* For now, leave the pointer/reference types alone. */
221 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
222 to a pointer to memory where the pointer type should be stored.
223 If *TYPEPTR is zero, update it to point to the pointer type we return.
224 We allocate new memory if needed. */
227 make_pointer_type (struct type
*type
, struct type
**typeptr
)
229 struct type
*ntype
; /* New type */
230 struct objfile
*objfile
;
233 ntype
= TYPE_POINTER_TYPE (type
);
238 return ntype
; /* Don't care about alloc,
239 and have new type. */
240 else if (*typeptr
== 0)
242 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
247 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
249 ntype
= alloc_type (TYPE_OBJFILE (type
));
253 else /* We have storage, but need to reset it. */
256 objfile
= TYPE_OBJFILE (ntype
);
257 chain
= TYPE_CHAIN (ntype
);
259 TYPE_CHAIN (ntype
) = chain
;
260 TYPE_OBJFILE (ntype
) = objfile
;
263 TYPE_TARGET_TYPE (ntype
) = type
;
264 TYPE_POINTER_TYPE (type
) = ntype
;
266 /* FIXME! Assume the machine has only one representation for
269 TYPE_LENGTH (ntype
) =
270 gdbarch_ptr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
271 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
273 /* Mark pointers as unsigned. The target converts between pointers
274 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
275 gdbarch_address_to_pointer. */
276 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
278 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
279 TYPE_POINTER_TYPE (type
) = ntype
;
281 /* Update the length of all the other variants of this type. */
282 chain
= TYPE_CHAIN (ntype
);
283 while (chain
!= ntype
)
285 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
286 chain
= TYPE_CHAIN (chain
);
292 /* Given a type TYPE, return a type of pointers to that type.
293 May need to construct such a type if this is the first use. */
296 lookup_pointer_type (struct type
*type
)
298 return make_pointer_type (type
, (struct type
**) 0);
301 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
302 points to a pointer to memory where the reference type should be
303 stored. If *TYPEPTR is zero, update it to point to the reference
304 type we return. We allocate new memory if needed. */
307 make_reference_type (struct type
*type
, struct type
**typeptr
)
309 struct type
*ntype
; /* New type */
310 struct objfile
*objfile
;
313 ntype
= TYPE_REFERENCE_TYPE (type
);
318 return ntype
; /* Don't care about alloc,
319 and have new type. */
320 else if (*typeptr
== 0)
322 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
327 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
329 ntype
= alloc_type (TYPE_OBJFILE (type
));
333 else /* We have storage, but need to reset it. */
336 objfile
= TYPE_OBJFILE (ntype
);
337 chain
= TYPE_CHAIN (ntype
);
339 TYPE_CHAIN (ntype
) = chain
;
340 TYPE_OBJFILE (ntype
) = objfile
;
343 TYPE_TARGET_TYPE (ntype
) = type
;
344 TYPE_REFERENCE_TYPE (type
) = ntype
;
346 /* FIXME! Assume the machine has only one representation for
347 references, and that it matches the (only) representation for
350 TYPE_LENGTH (ntype
) = gdbarch_ptr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
351 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
353 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
354 TYPE_REFERENCE_TYPE (type
) = ntype
;
356 /* Update the length of all the other variants of this type. */
357 chain
= TYPE_CHAIN (ntype
);
358 while (chain
!= ntype
)
360 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
361 chain
= TYPE_CHAIN (chain
);
367 /* Same as above, but caller doesn't care about memory allocation
371 lookup_reference_type (struct type
*type
)
373 return make_reference_type (type
, (struct type
**) 0);
376 /* Lookup a function type that returns type TYPE. TYPEPTR, if
377 nonzero, points to a pointer to memory where the function type
378 should be stored. If *TYPEPTR is zero, update it to point to the
379 function type we return. We allocate new memory if needed. */
382 make_function_type (struct type
*type
, struct type
**typeptr
)
384 struct type
*ntype
; /* New type */
385 struct objfile
*objfile
;
387 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
389 ntype
= alloc_type (TYPE_OBJFILE (type
));
393 else /* We have storage, but need to reset it. */
396 objfile
= TYPE_OBJFILE (ntype
);
398 TYPE_OBJFILE (ntype
) = objfile
;
401 TYPE_TARGET_TYPE (ntype
) = type
;
403 TYPE_LENGTH (ntype
) = 1;
404 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
410 /* Given a type TYPE, return a type of functions that return that type.
411 May need to construct such a type if this is the first use. */
414 lookup_function_type (struct type
*type
)
416 return make_function_type (type
, (struct type
**) 0);
419 /* Identify address space identifier by name --
420 return the integer flag defined in gdbtypes.h. */
422 address_space_name_to_int (char *space_identifier
)
424 struct gdbarch
*gdbarch
= current_gdbarch
;
426 /* Check for known address space delimiters. */
427 if (!strcmp (space_identifier
, "code"))
428 return TYPE_FLAG_CODE_SPACE
;
429 else if (!strcmp (space_identifier
, "data"))
430 return TYPE_FLAG_DATA_SPACE
;
431 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
432 && gdbarch_address_class_name_to_type_flags (gdbarch
,
437 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
440 /* Identify address space identifier by integer flag as defined in
441 gdbtypes.h -- return the string version of the adress space name. */
444 address_space_int_to_name (int space_flag
)
446 struct gdbarch
*gdbarch
= current_gdbarch
;
447 if (space_flag
& TYPE_FLAG_CODE_SPACE
)
449 else if (space_flag
& TYPE_FLAG_DATA_SPACE
)
451 else if ((space_flag
& TYPE_FLAG_ADDRESS_CLASS_ALL
)
452 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
453 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
458 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
460 If STORAGE is non-NULL, create the new type instance there.
461 STORAGE must be in the same obstack as TYPE. */
464 make_qualified_type (struct type
*type
, int new_flags
,
465 struct type
*storage
)
471 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
473 ntype
= TYPE_CHAIN (ntype
);
474 } while (ntype
!= type
);
476 /* Create a new type instance. */
478 ntype
= alloc_type_instance (type
);
481 /* If STORAGE was provided, it had better be in the same objfile
482 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
483 if one objfile is freed and the other kept, we'd have
484 dangling pointers. */
485 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
488 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
489 TYPE_CHAIN (ntype
) = ntype
;
492 /* Pointers or references to the original type are not relevant to
494 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
495 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
497 /* Chain the new qualified type to the old type. */
498 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
499 TYPE_CHAIN (type
) = ntype
;
501 /* Now set the instance flags and return the new type. */
502 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
504 /* Set length of new type to that of the original type. */
505 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
510 /* Make an address-space-delimited variant of a type -- a type that
511 is identical to the one supplied except that it has an address
512 space attribute attached to it (such as "code" or "data").
514 The space attributes "code" and "data" are for Harvard
515 architectures. The address space attributes are for architectures
516 which have alternately sized pointers or pointers with alternate
520 make_type_with_address_space (struct type
*type
, int space_flag
)
523 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
524 & ~(TYPE_FLAG_CODE_SPACE
| TYPE_FLAG_DATA_SPACE
525 | TYPE_FLAG_ADDRESS_CLASS_ALL
))
528 return make_qualified_type (type
, new_flags
, NULL
);
531 /* Make a "c-v" variant of a type -- a type that is identical to the
532 one supplied except that it may have const or volatile attributes
533 CNST is a flag for setting the const attribute
534 VOLTL is a flag for setting the volatile attribute
535 TYPE is the base type whose variant we are creating.
537 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
538 storage to hold the new qualified type; *TYPEPTR and TYPE must be
539 in the same objfile. Otherwise, allocate fresh memory for the new
540 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
541 new type we construct. */
543 make_cv_type (int cnst
, int voltl
,
545 struct type
**typeptr
)
547 struct type
*ntype
; /* New type */
548 struct type
*tmp_type
= type
; /* tmp type */
549 struct objfile
*objfile
;
551 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
552 & ~(TYPE_FLAG_CONST
| TYPE_FLAG_VOLATILE
));
555 new_flags
|= TYPE_FLAG_CONST
;
558 new_flags
|= TYPE_FLAG_VOLATILE
;
560 if (typeptr
&& *typeptr
!= NULL
)
562 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
563 a C-V variant chain that threads across objfiles: if one
564 objfile gets freed, then the other has a broken C-V chain.
566 This code used to try to copy over the main type from TYPE to
567 *TYPEPTR if they were in different objfiles, but that's
568 wrong, too: TYPE may have a field list or member function
569 lists, which refer to types of their own, etc. etc. The
570 whole shebang would need to be copied over recursively; you
571 can't have inter-objfile pointers. The only thing to do is
572 to leave stub types as stub types, and look them up afresh by
573 name each time you encounter them. */
574 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
577 ntype
= make_qualified_type (type
, new_flags
,
578 typeptr
? *typeptr
: NULL
);
586 /* Replace the contents of ntype with the type *type. This changes the
587 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
588 the changes are propogated to all types in the TYPE_CHAIN.
590 In order to build recursive types, it's inevitable that we'll need
591 to update types in place --- but this sort of indiscriminate
592 smashing is ugly, and needs to be replaced with something more
593 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
594 clear if more steps are needed. */
596 replace_type (struct type
*ntype
, struct type
*type
)
600 /* These two types had better be in the same objfile. Otherwise,
601 the assignment of one type's main type structure to the other
602 will produce a type with references to objects (names; field
603 lists; etc.) allocated on an objfile other than its own. */
604 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
606 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
608 /* The type length is not a part of the main type. Update it for
609 each type on the variant chain. */
612 /* Assert that this element of the chain has no address-class bits
613 set in its flags. Such type variants might have type lengths
614 which are supposed to be different from the non-address-class
615 variants. This assertion shouldn't ever be triggered because
616 symbol readers which do construct address-class variants don't
617 call replace_type(). */
618 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
620 TYPE_LENGTH (chain
) = TYPE_LENGTH (type
);
621 chain
= TYPE_CHAIN (chain
);
622 } while (ntype
!= chain
);
624 /* Assert that the two types have equivalent instance qualifiers.
625 This should be true for at least all of our debug readers. */
626 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
629 /* Implement direct support for MEMBER_TYPE in GNU C++.
630 May need to construct such a type if this is the first use.
631 The TYPE is the type of the member. The DOMAIN is the type
632 of the aggregate that the member belongs to. */
635 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
639 mtype
= alloc_type (TYPE_OBJFILE (type
));
640 smash_to_memberptr_type (mtype
, domain
, type
);
644 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
647 lookup_methodptr_type (struct type
*to_type
)
651 mtype
= alloc_type (TYPE_OBJFILE (to_type
));
652 TYPE_TARGET_TYPE (mtype
) = to_type
;
653 TYPE_DOMAIN_TYPE (mtype
) = TYPE_DOMAIN_TYPE (to_type
);
654 TYPE_LENGTH (mtype
) = cplus_method_ptr_size ();
655 TYPE_CODE (mtype
) = TYPE_CODE_METHODPTR
;
659 /* Allocate a stub method whose return type is TYPE. This apparently
660 happens for speed of symbol reading, since parsing out the
661 arguments to the method is cpu-intensive, the way we are doing it.
662 So, we will fill in arguments later. This always returns a fresh
666 allocate_stub_method (struct type
*type
)
670 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
671 TYPE_OBJFILE (type
));
672 TYPE_TARGET_TYPE (mtype
) = type
;
673 /* _DOMAIN_TYPE (mtype) = unknown yet */
677 /* Create a range type using either a blank type supplied in
678 RESULT_TYPE, or creating a new type, inheriting the objfile from
681 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
682 to HIGH_BOUND, inclusive.
684 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
685 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
688 create_range_type (struct type
*result_type
, struct type
*index_type
,
689 int low_bound
, int high_bound
)
691 if (result_type
== NULL
)
693 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
695 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
696 TYPE_TARGET_TYPE (result_type
) = index_type
;
697 if (TYPE_STUB (index_type
))
698 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
700 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
701 TYPE_NFIELDS (result_type
) = 2;
702 TYPE_FIELDS (result_type
) = (struct field
*)
703 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
704 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
705 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
706 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
709 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
711 return (result_type
);
714 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
715 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
716 bounds will fit in LONGEST), or -1 otherwise. */
719 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
721 CHECK_TYPEDEF (type
);
722 switch (TYPE_CODE (type
))
724 case TYPE_CODE_RANGE
:
725 *lowp
= TYPE_LOW_BOUND (type
);
726 *highp
= TYPE_HIGH_BOUND (type
);
729 if (TYPE_NFIELDS (type
) > 0)
731 /* The enums may not be sorted by value, so search all
735 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
736 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
738 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
739 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
740 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
741 *highp
= TYPE_FIELD_BITPOS (type
, i
);
744 /* Set unsigned indicator if warranted. */
747 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
761 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
763 if (!TYPE_UNSIGNED (type
))
765 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
769 /* ... fall through for unsigned ints ... */
772 /* This round-about calculation is to avoid shifting by
773 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
774 if TYPE_LENGTH (type) == sizeof (LONGEST). */
775 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
776 *highp
= (*highp
- 1) | *highp
;
783 /* Create an array type using either a blank type supplied in
784 RESULT_TYPE, or creating a new type, inheriting the objfile from
787 Elements will be of type ELEMENT_TYPE, the indices will be of type
790 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
791 sure it is TYPE_CODE_UNDEF before we bash it into an array
795 create_array_type (struct type
*result_type
,
796 struct type
*element_type
,
797 struct type
*range_type
)
799 LONGEST low_bound
, high_bound
;
801 if (result_type
== NULL
)
803 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
805 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
806 TYPE_TARGET_TYPE (result_type
) = element_type
;
807 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
808 low_bound
= high_bound
= 0;
809 CHECK_TYPEDEF (element_type
);
810 TYPE_LENGTH (result_type
) =
811 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
812 TYPE_NFIELDS (result_type
) = 1;
813 TYPE_FIELDS (result_type
) =
814 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
815 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
816 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
817 TYPE_VPTR_FIELDNO (result_type
) = -1;
819 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
820 if (TYPE_LENGTH (result_type
) == 0)
821 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
823 return (result_type
);
826 /* Create a string type using either a blank type supplied in
827 RESULT_TYPE, or creating a new type. String types are similar
828 enough to array of char types that we can use create_array_type to
829 build the basic type and then bash it into a string type.
831 For fixed length strings, the range type contains 0 as the lower
832 bound and the length of the string minus one as the upper bound.
834 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
835 sure it is TYPE_CODE_UNDEF before we bash it into a string
839 create_string_type (struct type
*result_type
,
840 struct type
*range_type
)
842 struct type
*string_char_type
;
844 string_char_type
= language_string_char_type (current_language
,
846 result_type
= create_array_type (result_type
,
849 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
850 return (result_type
);
854 create_set_type (struct type
*result_type
, struct type
*domain_type
)
856 if (result_type
== NULL
)
858 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
860 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
861 TYPE_NFIELDS (result_type
) = 1;
862 TYPE_FIELDS (result_type
) = (struct field
*)
863 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
864 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
866 if (!TYPE_STUB (domain_type
))
868 LONGEST low_bound
, high_bound
, bit_length
;
869 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
870 low_bound
= high_bound
= 0;
871 bit_length
= high_bound
- low_bound
+ 1;
872 TYPE_LENGTH (result_type
)
873 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
875 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
877 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
879 return (result_type
);
883 append_flags_type_flag (struct type
*type
, int bitpos
, char *name
)
885 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
886 gdb_assert (bitpos
< TYPE_NFIELDS (type
));
887 gdb_assert (bitpos
>= 0);
891 TYPE_FIELD_NAME (type
, bitpos
) = xstrdup (name
);
892 TYPE_FIELD_BITPOS (type
, bitpos
) = bitpos
;
896 /* Don't show this field to the user. */
897 TYPE_FIELD_BITPOS (type
, bitpos
) = -1;
902 init_flags_type (char *name
, int length
)
904 int nfields
= length
* TARGET_CHAR_BIT
;
907 type
= init_type (TYPE_CODE_FLAGS
, length
,
908 TYPE_FLAG_UNSIGNED
, name
, NULL
);
909 TYPE_NFIELDS (type
) = nfields
;
910 TYPE_FIELDS (type
) = TYPE_ALLOC (type
,
911 nfields
* sizeof (struct field
));
912 memset (TYPE_FIELDS (type
), 0, nfields
* sizeof (struct field
));
917 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
918 and any array types nested inside it. */
921 make_vector_type (struct type
*array_type
)
923 struct type
*inner_array
, *elt_type
;
926 /* Find the innermost array type, in case the array is
927 multi-dimensional. */
928 inner_array
= array_type
;
929 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
930 inner_array
= TYPE_TARGET_TYPE (inner_array
);
932 elt_type
= TYPE_TARGET_TYPE (inner_array
);
933 if (TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
935 flags
= TYPE_INSTANCE_FLAGS (elt_type
) | TYPE_FLAG_NOTTEXT
;
936 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
937 TYPE_TARGET_TYPE (inner_array
) = elt_type
;
940 TYPE_FLAGS (array_type
) |= TYPE_FLAG_VECTOR
;
944 init_vector_type (struct type
*elt_type
, int n
)
946 struct type
*array_type
;
948 array_type
= create_array_type (0, elt_type
,
949 create_range_type (0,
952 make_vector_type (array_type
);
956 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
957 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
958 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
959 TYPE doesn't include the offset (that's the value of the MEMBER
960 itself), but does include the structure type into which it points
963 When "smashing" the type, we preserve the objfile that the old type
964 pointed to, since we aren't changing where the type is actually
968 smash_to_memberptr_type (struct type
*type
, struct type
*domain
,
969 struct type
*to_type
)
971 struct objfile
*objfile
;
973 objfile
= TYPE_OBJFILE (type
);
976 TYPE_OBJFILE (type
) = objfile
;
977 TYPE_TARGET_TYPE (type
) = to_type
;
978 TYPE_DOMAIN_TYPE (type
) = domain
;
979 /* Assume that a data member pointer is the same size as a normal
981 TYPE_LENGTH (type
) = gdbarch_ptr_bit (current_gdbarch
) / 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
)
997 struct objfile
*objfile
;
999 objfile
= TYPE_OBJFILE (type
);
1002 TYPE_OBJFILE (type
) = objfile
;
1003 TYPE_TARGET_TYPE (type
) = to_type
;
1004 TYPE_DOMAIN_TYPE (type
) = domain
;
1005 TYPE_FIELDS (type
) = args
;
1006 TYPE_NFIELDS (type
) = nargs
;
1008 TYPE_FLAGS (type
) |= TYPE_FLAG_VARARGS
;
1009 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1010 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1013 /* Return a typename for a struct/union/enum type without "struct ",
1014 "union ", or "enum ". If the type has a NULL name, return NULL. */
1017 type_name_no_tag (const struct type
*type
)
1019 if (TYPE_TAG_NAME (type
) != NULL
)
1020 return TYPE_TAG_NAME (type
);
1022 /* Is there code which expects this to return the name if there is
1023 no tag name? My guess is that this is mainly used for C++ in
1024 cases where the two will always be the same. */
1025 return TYPE_NAME (type
);
1028 /* Lookup a typedef or primitive type named NAME, visible in lexical
1029 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1030 suitably defined. */
1033 lookup_typename (char *name
, struct block
*block
, int noerr
)
1038 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0,
1039 (struct symtab
**) NULL
);
1040 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1042 tmp
= language_lookup_primitive_type_by_name (current_language
,
1049 else if (!tmp
&& noerr
)
1055 error (_("No type named %s."), name
);
1058 return (SYMBOL_TYPE (sym
));
1062 lookup_unsigned_typename (char *name
)
1064 char *uns
= alloca (strlen (name
) + 10);
1066 strcpy (uns
, "unsigned ");
1067 strcpy (uns
+ 9, name
);
1068 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
1072 lookup_signed_typename (char *name
)
1075 char *uns
= alloca (strlen (name
) + 8);
1077 strcpy (uns
, "signed ");
1078 strcpy (uns
+ 7, name
);
1079 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
1080 /* If we don't find "signed FOO" just try again with plain "FOO". */
1083 return lookup_typename (name
, (struct block
*) NULL
, 0);
1086 /* Lookup a structure type named "struct NAME",
1087 visible in lexical block BLOCK. */
1090 lookup_struct (char *name
, struct block
*block
)
1094 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1095 (struct symtab
**) NULL
);
1099 error (_("No struct type named %s."), name
);
1101 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1103 error (_("This context has class, union or enum %s, not a struct."),
1106 return (SYMBOL_TYPE (sym
));
1109 /* Lookup a union type named "union NAME",
1110 visible in lexical block BLOCK. */
1113 lookup_union (char *name
, struct block
*block
)
1118 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1119 (struct symtab
**) NULL
);
1122 error (_("No union type named %s."), name
);
1124 t
= SYMBOL_TYPE (sym
);
1126 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1129 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1130 * a further "declared_type" field to discover it is really a union.
1132 if (HAVE_CPLUS_STRUCT (t
))
1133 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1136 /* If we get here, it's not a union. */
1137 error (_("This context has class, struct or enum %s, not a union."),
1142 /* Lookup an enum type named "enum NAME",
1143 visible in lexical block BLOCK. */
1146 lookup_enum (char *name
, struct block
*block
)
1150 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1151 (struct symtab
**) NULL
);
1154 error (_("No enum type named %s."), name
);
1156 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1158 error (_("This context has class, struct or union %s, not an enum."),
1161 return (SYMBOL_TYPE (sym
));
1164 /* Lookup a template type named "template NAME<TYPE>",
1165 visible in lexical block BLOCK. */
1168 lookup_template_type (char *name
, struct type
*type
,
1169 struct block
*block
)
1172 char *nam
= (char *)
1173 alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1176 strcat (nam
, TYPE_NAME (type
));
1177 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1179 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0,
1180 (struct symtab
**) NULL
);
1184 error (_("No template type named %s."), name
);
1186 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1188 error (_("This context has class, union or enum %s, not a struct."),
1191 return (SYMBOL_TYPE (sym
));
1194 /* Given a type TYPE, lookup the type of the component of type named
1197 TYPE can be either a struct or union, or a pointer or reference to
1198 a struct or union. If it is a pointer or reference, its target
1199 type is automatically used. Thus '.' and '->' are interchangable,
1200 as specified for the definitions of the expression element types
1201 STRUCTOP_STRUCT and STRUCTOP_PTR.
1203 If NOERR is nonzero, return zero if NAME is not suitably defined.
1204 If NAME is the name of a baseclass type, return that type. */
1207 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1213 CHECK_TYPEDEF (type
);
1214 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1215 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1217 type
= TYPE_TARGET_TYPE (type
);
1220 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1221 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1223 target_terminal_ours ();
1224 gdb_flush (gdb_stdout
);
1225 fprintf_unfiltered (gdb_stderr
, "Type ");
1226 type_print (type
, "", gdb_stderr
, -1);
1227 error (_(" is not a structure or union type."));
1231 /* FIXME: This change put in by Michael seems incorrect for the case
1232 where the structure tag name is the same as the member name.
1233 I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
1234 foo; } bell;" Disabled by fnf. */
1238 typename
= type_name_no_tag (type
);
1239 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1244 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1246 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1248 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1250 return TYPE_FIELD_TYPE (type
, i
);
1254 /* OK, it's not in this class. Recursively check the baseclasses. */
1255 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1259 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1271 target_terminal_ours ();
1272 gdb_flush (gdb_stdout
);
1273 fprintf_unfiltered (gdb_stderr
, "Type ");
1274 type_print (type
, "", gdb_stderr
, -1);
1275 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1276 fputs_filtered (name
, gdb_stderr
);
1278 return (struct type
*) -1; /* For lint */
1281 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1282 valid. Callers should be aware that in some cases (for example,
1283 the type or one of its baseclasses is a stub type and we are
1284 debugging a .o file), this function will not be able to find the
1285 virtual function table pointer, and vptr_fieldno will remain -1 and
1286 vptr_basetype will remain NULL. */
1289 fill_in_vptr_fieldno (struct type
*type
)
1291 CHECK_TYPEDEF (type
);
1293 if (TYPE_VPTR_FIELDNO (type
) < 0)
1297 /* We must start at zero in case the first (and only) baseclass
1298 is virtual (and hence we cannot share the table pointer). */
1299 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1301 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
,
1303 fill_in_vptr_fieldno (baseclass
);
1304 if (TYPE_VPTR_FIELDNO (baseclass
) >= 0)
1306 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (baseclass
);
1307 TYPE_VPTR_BASETYPE (type
) = TYPE_VPTR_BASETYPE (baseclass
);
1314 /* Find the method and field indices for the destructor in class type T.
1315 Return 1 if the destructor was found, otherwise, return 0. */
1318 get_destructor_fn_field (struct type
*t
,
1324 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1327 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1329 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1331 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1343 stub_noname_complaint (void)
1345 complaint (&symfile_complaints
, _("stub type has NULL name"));
1348 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1350 If this is a stubbed struct (i.e. declared as struct foo *), see if
1351 we can find a full definition in some other file. If so, copy this
1352 definition, so we can use it in future. There used to be a comment
1353 (but not any code) that if we don't find a full definition, we'd
1354 set a flag so we don't spend time in the future checking the same
1355 type. That would be a mistake, though--we might load in more
1356 symbols which contain a full definition for the type.
1358 This used to be coded as a macro, but I don't think it is called
1359 often enough to merit such treatment. */
1361 /* Find the real type of TYPE. This function returns the real type,
1362 after removing all layers of typedefs and completing opaque or stub
1363 types. Completion changes the TYPE argument, but stripping of
1364 typedefs does not. */
1367 check_typedef (struct type
*type
)
1369 struct type
*orig_type
= type
;
1370 int is_const
, is_volatile
;
1374 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1376 if (!TYPE_TARGET_TYPE (type
))
1381 /* It is dangerous to call lookup_symbol if we are currently
1382 reading a symtab. Infinite recursion is one danger. */
1383 if (currently_reading_symtab
)
1386 name
= type_name_no_tag (type
);
1387 /* FIXME: shouldn't we separately check the TYPE_NAME and
1388 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1389 VAR_DOMAIN as appropriate? (this code was written before
1390 TYPE_NAME and TYPE_TAG_NAME were separate). */
1393 stub_noname_complaint ();
1396 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0,
1397 (struct symtab
**) NULL
);
1399 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1400 else /* TYPE_CODE_UNDEF */
1401 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
);
1403 type
= TYPE_TARGET_TYPE (type
);
1406 is_const
= TYPE_CONST (type
);
1407 is_volatile
= TYPE_VOLATILE (type
);
1409 /* If this is a struct/class/union with no fields, then check
1410 whether a full definition exists somewhere else. This is for
1411 systems where a type definition with no fields is issued for such
1412 types, instead of identifying them as stub types in the first
1415 if (TYPE_IS_OPAQUE (type
)
1416 && opaque_type_resolution
1417 && !currently_reading_symtab
)
1419 char *name
= type_name_no_tag (type
);
1420 struct type
*newtype
;
1423 stub_noname_complaint ();
1426 newtype
= lookup_transparent_type (name
);
1430 /* If the resolved type and the stub are in the same
1431 objfile, then replace the stub type with the real deal.
1432 But if they're in separate objfiles, leave the stub
1433 alone; we'll just look up the transparent type every time
1434 we call check_typedef. We can't create pointers between
1435 types allocated to different objfiles, since they may
1436 have different lifetimes. Trying to copy NEWTYPE over to
1437 TYPE's objfile is pointless, too, since you'll have to
1438 move over any other types NEWTYPE refers to, which could
1439 be an unbounded amount of stuff. */
1440 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1441 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1446 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1448 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1450 char *name
= type_name_no_tag (type
);
1451 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1452 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1453 as appropriate? (this code was written before TYPE_NAME and
1454 TYPE_TAG_NAME were separate). */
1458 stub_noname_complaint ();
1461 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
,
1462 0, (struct symtab
**) NULL
);
1465 /* Same as above for opaque types, we can replace the stub
1466 with the complete type only if they are int the same
1468 if (TYPE_OBJFILE (SYMBOL_TYPE(sym
)) == TYPE_OBJFILE (type
))
1469 make_cv_type (is_const
, is_volatile
,
1470 SYMBOL_TYPE (sym
), &type
);
1472 type
= SYMBOL_TYPE (sym
);
1476 if (TYPE_TARGET_STUB (type
))
1478 struct type
*range_type
;
1479 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1481 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1485 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1486 && TYPE_NFIELDS (type
) == 1
1487 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1488 == TYPE_CODE_RANGE
))
1490 /* Now recompute the length of the array type, based on its
1491 number of elements and the target type's length. */
1492 TYPE_LENGTH (type
) =
1493 ((TYPE_FIELD_BITPOS (range_type
, 1)
1494 - TYPE_FIELD_BITPOS (range_type
, 0) + 1)
1495 * TYPE_LENGTH (target_type
));
1496 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1498 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1500 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1501 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1504 /* Cache TYPE_LENGTH for future use. */
1505 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1509 /* Parse a type expression in the string [P..P+LENGTH). If an error
1510 occurs, silently return builtin_type_void. */
1512 static struct type
*
1513 safe_parse_type (char *p
, int length
)
1515 struct ui_file
*saved_gdb_stderr
;
1518 /* Suppress error messages. */
1519 saved_gdb_stderr
= gdb_stderr
;
1520 gdb_stderr
= ui_file_new ();
1522 /* Call parse_and_eval_type() without fear of longjmp()s. */
1523 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1524 type
= builtin_type_void
;
1526 /* Stop suppressing error messages. */
1527 ui_file_delete (gdb_stderr
);
1528 gdb_stderr
= saved_gdb_stderr
;
1533 /* Ugly hack to convert method stubs into method types.
1535 He ain't kiddin'. This demangles the name of the method into a
1536 string including argument types, parses out each argument type,
1537 generates a string casting a zero to that type, evaluates the
1538 string, and stuffs the resulting type into an argtype vector!!!
1539 Then it knows the type of the whole function (including argument
1540 types for overloading), which info used to be in the stab's but was
1541 removed to hack back the space required for them. */
1544 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1547 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1548 char *demangled_name
= cplus_demangle (mangled_name
,
1549 DMGL_PARAMS
| DMGL_ANSI
);
1550 char *argtypetext
, *p
;
1551 int depth
= 0, argcount
= 1;
1552 struct field
*argtypes
;
1555 /* Make sure we got back a function string that we can use. */
1557 p
= strchr (demangled_name
, '(');
1561 if (demangled_name
== NULL
|| p
== NULL
)
1562 error (_("Internal: Cannot demangle mangled name `%s'."),
1565 /* Now, read in the parameters that define this type. */
1570 if (*p
== '(' || *p
== '<')
1574 else if (*p
== ')' || *p
== '>')
1578 else if (*p
== ',' && depth
== 0)
1586 /* If we read one argument and it was ``void'', don't count it. */
1587 if (strncmp (argtypetext
, "(void)", 6) == 0)
1590 /* We need one extra slot, for the THIS pointer. */
1592 argtypes
= (struct field
*)
1593 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1596 /* Add THIS pointer for non-static methods. */
1597 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1598 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1602 argtypes
[0].type
= lookup_pointer_type (type
);
1606 if (*p
!= ')') /* () means no args, skip while */
1611 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1613 /* Avoid parsing of ellipsis, they will be handled below.
1614 Also avoid ``void'' as above. */
1615 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1616 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1618 argtypes
[argcount
].type
=
1619 safe_parse_type (argtypetext
, p
- argtypetext
);
1622 argtypetext
= p
+ 1;
1625 if (*p
== '(' || *p
== '<')
1629 else if (*p
== ')' || *p
== '>')
1638 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1640 /* Now update the old "stub" type into a real type. */
1641 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1642 TYPE_DOMAIN_TYPE (mtype
) = type
;
1643 TYPE_FIELDS (mtype
) = argtypes
;
1644 TYPE_NFIELDS (mtype
) = argcount
;
1645 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1646 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1648 TYPE_FLAGS (mtype
) |= TYPE_FLAG_VARARGS
;
1650 xfree (demangled_name
);
1653 /* This is the external interface to check_stub_method, above. This
1654 function unstubs all of the signatures for TYPE's METHOD_ID method
1655 name. After calling this function TYPE_FN_FIELD_STUB will be
1656 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1659 This function unfortunately can not die until stabs do. */
1662 check_stub_method_group (struct type
*type
, int method_id
)
1664 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1665 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1666 int j
, found_stub
= 0;
1668 for (j
= 0; j
< len
; j
++)
1669 if (TYPE_FN_FIELD_STUB (f
, j
))
1672 check_stub_method (type
, method_id
, j
);
1675 /* GNU v3 methods with incorrect names were corrected when we read
1676 in type information, because it was cheaper to do it then. The
1677 only GNU v2 methods with incorrect method names are operators and
1678 destructors; destructors were also corrected when we read in type
1681 Therefore the only thing we need to handle here are v2 operator
1683 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1686 char dem_opname
[256];
1688 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1690 dem_opname
, DMGL_ANSI
);
1692 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1696 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1700 const struct cplus_struct_type cplus_struct_default
;
1703 allocate_cplus_struct_type (struct type
*type
)
1705 if (!HAVE_CPLUS_STRUCT (type
))
1707 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1708 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1709 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1713 /* Helper function to initialize the standard scalar types.
1715 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy of
1716 the string pointed to by name in the objfile_obstack for that
1717 objfile, and initialize the type name to that copy. There are
1718 places (mipsread.c in particular, where init_type is called with a
1719 NULL value for NAME). */
1722 init_type (enum type_code code
, int length
, int flags
,
1723 char *name
, struct objfile
*objfile
)
1727 type
= alloc_type (objfile
);
1728 TYPE_CODE (type
) = code
;
1729 TYPE_LENGTH (type
) = length
;
1730 TYPE_FLAGS (type
) |= flags
;
1731 if ((name
!= NULL
) && (objfile
!= NULL
))
1733 TYPE_NAME (type
) = obsavestring (name
, strlen (name
),
1734 &objfile
->objfile_obstack
);
1738 TYPE_NAME (type
) = name
;
1743 if (name
&& strcmp (name
, "char") == 0)
1744 TYPE_FLAGS (type
) |= TYPE_FLAG_NOSIGN
;
1746 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
1747 || code
== TYPE_CODE_NAMESPACE
)
1749 INIT_CPLUS_SPECIFIC (type
);
1754 /* Helper function. Create an empty composite type. */
1757 init_composite_type (char *name
, enum type_code code
)
1760 gdb_assert (code
== TYPE_CODE_STRUCT
1761 || code
== TYPE_CODE_UNION
);
1762 t
= init_type (code
, 0, 0, NULL
, NULL
);
1763 TYPE_TAG_NAME (t
) = name
;
1767 /* Helper function. Append a field to a composite type. */
1770 append_composite_type_field (struct type
*t
, char *name
,
1774 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
1775 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
1776 sizeof (struct field
) * TYPE_NFIELDS (t
));
1777 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
1778 memset (f
, 0, sizeof f
[0]);
1779 FIELD_TYPE (f
[0]) = field
;
1780 FIELD_NAME (f
[0]) = name
;
1781 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1783 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
1784 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
1786 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
1788 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
1789 if (TYPE_NFIELDS (t
) > 1)
1791 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
1792 + TYPE_LENGTH (field
) * TARGET_CHAR_BIT
);
1797 /* Look up a fundamental type for the specified objfile.
1798 May need to construct such a type if this is the first use.
1800 Some object file formats (ELF, COFF, etc) do not define fundamental
1801 types such as "int" or "double". Others (stabs for example), do
1802 define fundamental types.
1804 For the formats which don't provide fundamental types, gdb can
1805 create such types, using defaults reasonable for the current
1806 language and the current target machine.
1808 NOTE: This routine is obsolescent. Each debugging format reader
1809 should manage it's own fundamental types, either creating them from
1810 suitable defaults or reading them from the debugging information,
1811 whichever is appropriate. The DWARF reader has already been fixed
1812 to do this. Once the other readers are fixed, this routine will go
1813 away. Also note that fundamental types should be managed on a
1814 compilation unit basis in a multi-language environment, not on a
1815 linkage unit basis as is done here. */
1819 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1821 struct type
**typep
;
1824 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1826 error (_("internal error - invalid fundamental type id %d"),
1830 /* If this is the first time we need a fundamental type for this
1831 objfile then we need to initialize the vector of type
1834 if (objfile
->fundamental_types
== NULL
)
1836 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1837 objfile
->fundamental_types
= (struct type
**)
1838 obstack_alloc (&objfile
->objfile_obstack
, nbytes
);
1839 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1840 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1843 /* Look for this particular type in the fundamental type vector. If
1844 one is not found, create and install one appropriate for the
1845 current language. */
1847 typep
= objfile
->fundamental_types
+ typeid;
1850 *typep
= create_fundamental_type (objfile
, typeid);
1857 can_dereference (struct type
*t
)
1859 /* FIXME: Should we return true for references as well as
1864 && TYPE_CODE (t
) == TYPE_CODE_PTR
1865 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1869 is_integral_type (struct type
*t
)
1874 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1875 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1876 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
1877 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1878 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1879 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1882 /* Check whether BASE is an ancestor or base class or DCLASS
1883 Return 1 if so, and 0 if not.
1884 Note: callers may want to check for identity of the types before
1885 calling this function -- identical types are considered to satisfy
1886 the ancestor relationship even if they're identical. */
1889 is_ancestor (struct type
*base
, struct type
*dclass
)
1893 CHECK_TYPEDEF (base
);
1894 CHECK_TYPEDEF (dclass
);
1898 if (TYPE_NAME (base
) && TYPE_NAME (dclass
)
1899 && !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1902 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1903 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1911 /* Functions for overload resolution begin here */
1913 /* Compare two badness vectors A and B and return the result.
1914 0 => A and B are identical
1915 1 => A and B are incomparable
1916 2 => A is better than B
1917 3 => A is worse than B */
1920 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
1924 short found_pos
= 0; /* any positives in c? */
1925 short found_neg
= 0; /* any negatives in c? */
1927 /* differing lengths => incomparable */
1928 if (a
->length
!= b
->length
)
1931 /* Subtract b from a */
1932 for (i
= 0; i
< a
->length
; i
++)
1934 tmp
= a
->rank
[i
] - b
->rank
[i
];
1944 return 1; /* incomparable */
1946 return 3; /* A > B */
1952 return 2; /* A < B */
1954 return 0; /* A == B */
1958 /* Rank a function by comparing its parameter types (PARMS, length
1959 NPARMS), to the types of an argument list (ARGS, length NARGS).
1960 Return a pointer to a badness vector. This has NARGS + 1
1963 struct badness_vector
*
1964 rank_function (struct type
**parms
, int nparms
,
1965 struct type
**args
, int nargs
)
1968 struct badness_vector
*bv
;
1969 int min_len
= nparms
< nargs
? nparms
: nargs
;
1971 bv
= xmalloc (sizeof (struct badness_vector
));
1972 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
1973 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
1975 /* First compare the lengths of the supplied lists.
1976 If there is a mismatch, set it to a high value. */
1978 /* pai/1997-06-03 FIXME: when we have debug info about default
1979 arguments and ellipsis parameter lists, we should consider those
1980 and rank the length-match more finely. */
1982 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
1984 /* Now rank all the parameters of the candidate function */
1985 for (i
= 1; i
<= min_len
; i
++)
1986 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
1988 /* If more arguments than parameters, add dummy entries */
1989 for (i
= min_len
+ 1; i
<= nargs
; i
++)
1990 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
1995 /* Compare the names of two integer types, assuming that any sign
1996 qualifiers have been checked already. We do it this way because
1997 there may be an "int" in the name of one of the types. */
2000 integer_types_same_name_p (const char *first
, const char *second
)
2002 int first_p
, second_p
;
2004 /* If both are shorts, return 1; if neither is a short, keep
2006 first_p
= (strstr (first
, "short") != NULL
);
2007 second_p
= (strstr (second
, "short") != NULL
);
2008 if (first_p
&& second_p
)
2010 if (first_p
|| second_p
)
2013 /* Likewise for long. */
2014 first_p
= (strstr (first
, "long") != NULL
);
2015 second_p
= (strstr (second
, "long") != NULL
);
2016 if (first_p
&& second_p
)
2018 if (first_p
|| second_p
)
2021 /* Likewise for char. */
2022 first_p
= (strstr (first
, "char") != NULL
);
2023 second_p
= (strstr (second
, "char") != NULL
);
2024 if (first_p
&& second_p
)
2026 if (first_p
|| second_p
)
2029 /* They must both be ints. */
2033 /* Compare one type (PARM) for compatibility with another (ARG).
2034 * PARM is intended to be the parameter type of a function; and
2035 * ARG is the supplied argument's type. This function tests if
2036 * the latter can be converted to the former.
2038 * Return 0 if they are identical types;
2039 * Otherwise, return an integer which corresponds to how compatible
2040 * PARM is to ARG. The higher the return value, the worse the match.
2041 * Generally the "bad" conversions are all uniformly assigned a 100. */
2044 rank_one_type (struct type
*parm
, struct type
*arg
)
2046 /* Identical type pointers. */
2047 /* However, this still doesn't catch all cases of same type for arg
2048 and param. The reason is that builtin types are different from
2049 the same ones constructed from the object. */
2053 /* Resolve typedefs */
2054 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2055 parm
= check_typedef (parm
);
2056 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2057 arg
= check_typedef (arg
);
2060 Well, damnit, if the names are exactly the same, I'll say they
2061 are exactly the same. This happens when we generate method
2062 stubs. The types won't point to the same address, but they
2063 really are the same.
2066 if (TYPE_NAME (parm
) && TYPE_NAME (arg
)
2067 && !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2070 /* Check if identical after resolving typedefs. */
2074 /* See through references, since we can almost make non-references
2076 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2077 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2078 + REFERENCE_CONVERSION_BADNESS
);
2079 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2080 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2081 + REFERENCE_CONVERSION_BADNESS
);
2083 /* Debugging only. */
2084 fprintf_filtered (gdb_stderr
,
2085 "------ Arg is %s [%d], parm is %s [%d]\n",
2086 TYPE_NAME (arg
), TYPE_CODE (arg
),
2087 TYPE_NAME (parm
), TYPE_CODE (parm
));
2089 /* x -> y means arg of type x being supplied for parameter of type y */
2091 switch (TYPE_CODE (parm
))
2094 switch (TYPE_CODE (arg
))
2097 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2098 return VOID_PTR_CONVERSION_BADNESS
;
2100 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2101 TYPE_TARGET_TYPE (arg
));
2102 case TYPE_CODE_ARRAY
:
2103 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2104 TYPE_TARGET_TYPE (arg
));
2105 case TYPE_CODE_FUNC
:
2106 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2108 case TYPE_CODE_ENUM
:
2109 case TYPE_CODE_FLAGS
:
2110 case TYPE_CODE_CHAR
:
2111 case TYPE_CODE_RANGE
:
2112 case TYPE_CODE_BOOL
:
2113 return POINTER_CONVERSION_BADNESS
;
2115 return INCOMPATIBLE_TYPE_BADNESS
;
2117 case TYPE_CODE_ARRAY
:
2118 switch (TYPE_CODE (arg
))
2121 case TYPE_CODE_ARRAY
:
2122 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2123 TYPE_TARGET_TYPE (arg
));
2125 return INCOMPATIBLE_TYPE_BADNESS
;
2127 case TYPE_CODE_FUNC
:
2128 switch (TYPE_CODE (arg
))
2130 case TYPE_CODE_PTR
: /* funcptr -> func */
2131 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2133 return INCOMPATIBLE_TYPE_BADNESS
;
2136 switch (TYPE_CODE (arg
))
2139 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2141 /* Deal with signed, unsigned, and plain chars and
2142 signed and unsigned ints. */
2143 if (TYPE_NOSIGN (parm
))
2145 /* This case only for character types */
2146 if (TYPE_NOSIGN (arg
))
2147 return 0; /* plain char -> plain char */
2148 else /* signed/unsigned char -> plain char */
2149 return INTEGER_CONVERSION_BADNESS
;
2151 else if (TYPE_UNSIGNED (parm
))
2153 if (TYPE_UNSIGNED (arg
))
2155 /* unsigned int -> unsigned int, or
2156 unsigned long -> unsigned long */
2157 if (integer_types_same_name_p (TYPE_NAME (parm
),
2160 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2162 && integer_types_same_name_p (TYPE_NAME (parm
),
2164 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2166 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2170 if (integer_types_same_name_p (TYPE_NAME (arg
),
2172 && integer_types_same_name_p (TYPE_NAME (parm
),
2174 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2176 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2179 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2181 if (integer_types_same_name_p (TYPE_NAME (parm
),
2184 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2186 && integer_types_same_name_p (TYPE_NAME (parm
),
2188 return INTEGER_PROMOTION_BADNESS
;
2190 return INTEGER_CONVERSION_BADNESS
;
2193 return INTEGER_CONVERSION_BADNESS
;
2195 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2196 return INTEGER_PROMOTION_BADNESS
;
2198 return INTEGER_CONVERSION_BADNESS
;
2199 case TYPE_CODE_ENUM
:
2200 case TYPE_CODE_FLAGS
:
2201 case TYPE_CODE_CHAR
:
2202 case TYPE_CODE_RANGE
:
2203 case TYPE_CODE_BOOL
:
2204 return INTEGER_PROMOTION_BADNESS
;
2206 return INT_FLOAT_CONVERSION_BADNESS
;
2208 return NS_POINTER_CONVERSION_BADNESS
;
2210 return INCOMPATIBLE_TYPE_BADNESS
;
2213 case TYPE_CODE_ENUM
:
2214 switch (TYPE_CODE (arg
))
2217 case TYPE_CODE_CHAR
:
2218 case TYPE_CODE_RANGE
:
2219 case TYPE_CODE_BOOL
:
2220 case TYPE_CODE_ENUM
:
2221 return INTEGER_CONVERSION_BADNESS
;
2223 return INT_FLOAT_CONVERSION_BADNESS
;
2225 return INCOMPATIBLE_TYPE_BADNESS
;
2228 case TYPE_CODE_CHAR
:
2229 switch (TYPE_CODE (arg
))
2231 case TYPE_CODE_RANGE
:
2232 case TYPE_CODE_BOOL
:
2233 case TYPE_CODE_ENUM
:
2234 return INTEGER_CONVERSION_BADNESS
;
2236 return INT_FLOAT_CONVERSION_BADNESS
;
2238 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2239 return INTEGER_CONVERSION_BADNESS
;
2240 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2241 return INTEGER_PROMOTION_BADNESS
;
2242 /* >>> !! else fall through !! <<< */
2243 case TYPE_CODE_CHAR
:
2244 /* Deal with signed, unsigned, and plain chars for C++ and
2245 with int cases falling through from previous case. */
2246 if (TYPE_NOSIGN (parm
))
2248 if (TYPE_NOSIGN (arg
))
2251 return INTEGER_CONVERSION_BADNESS
;
2253 else if (TYPE_UNSIGNED (parm
))
2255 if (TYPE_UNSIGNED (arg
))
2258 return INTEGER_PROMOTION_BADNESS
;
2260 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2263 return INTEGER_CONVERSION_BADNESS
;
2265 return INCOMPATIBLE_TYPE_BADNESS
;
2268 case TYPE_CODE_RANGE
:
2269 switch (TYPE_CODE (arg
))
2272 case TYPE_CODE_CHAR
:
2273 case TYPE_CODE_RANGE
:
2274 case TYPE_CODE_BOOL
:
2275 case TYPE_CODE_ENUM
:
2276 return INTEGER_CONVERSION_BADNESS
;
2278 return INT_FLOAT_CONVERSION_BADNESS
;
2280 return INCOMPATIBLE_TYPE_BADNESS
;
2283 case TYPE_CODE_BOOL
:
2284 switch (TYPE_CODE (arg
))
2287 case TYPE_CODE_CHAR
:
2288 case TYPE_CODE_RANGE
:
2289 case TYPE_CODE_ENUM
:
2292 return BOOLEAN_CONVERSION_BADNESS
;
2293 case TYPE_CODE_BOOL
:
2296 return INCOMPATIBLE_TYPE_BADNESS
;
2300 switch (TYPE_CODE (arg
))
2303 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2304 return FLOAT_PROMOTION_BADNESS
;
2305 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2308 return FLOAT_CONVERSION_BADNESS
;
2310 case TYPE_CODE_BOOL
:
2311 case TYPE_CODE_ENUM
:
2312 case TYPE_CODE_RANGE
:
2313 case TYPE_CODE_CHAR
:
2314 return INT_FLOAT_CONVERSION_BADNESS
;
2316 return INCOMPATIBLE_TYPE_BADNESS
;
2319 case TYPE_CODE_COMPLEX
:
2320 switch (TYPE_CODE (arg
))
2321 { /* Strictly not needed for C++, but... */
2323 return FLOAT_PROMOTION_BADNESS
;
2324 case TYPE_CODE_COMPLEX
:
2327 return INCOMPATIBLE_TYPE_BADNESS
;
2330 case TYPE_CODE_STRUCT
:
2331 /* currently same as TYPE_CODE_CLASS */
2332 switch (TYPE_CODE (arg
))
2334 case TYPE_CODE_STRUCT
:
2335 /* Check for derivation */
2336 if (is_ancestor (parm
, arg
))
2337 return BASE_CONVERSION_BADNESS
;
2338 /* else fall through */
2340 return INCOMPATIBLE_TYPE_BADNESS
;
2343 case TYPE_CODE_UNION
:
2344 switch (TYPE_CODE (arg
))
2346 case TYPE_CODE_UNION
:
2348 return INCOMPATIBLE_TYPE_BADNESS
;
2351 case TYPE_CODE_MEMBERPTR
:
2352 switch (TYPE_CODE (arg
))
2355 return INCOMPATIBLE_TYPE_BADNESS
;
2358 case TYPE_CODE_METHOD
:
2359 switch (TYPE_CODE (arg
))
2363 return INCOMPATIBLE_TYPE_BADNESS
;
2367 switch (TYPE_CODE (arg
))
2371 return INCOMPATIBLE_TYPE_BADNESS
;
2376 switch (TYPE_CODE (arg
))
2380 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0),
2381 TYPE_FIELD_TYPE (arg
, 0));
2383 return INCOMPATIBLE_TYPE_BADNESS
;
2386 case TYPE_CODE_VOID
:
2388 return INCOMPATIBLE_TYPE_BADNESS
;
2389 } /* switch (TYPE_CODE (arg)) */
2393 /* End of functions for overload resolution */
2396 print_bit_vector (B_TYPE
*bits
, int nbits
)
2400 for (bitno
= 0; bitno
< nbits
; bitno
++)
2402 if ((bitno
% 8) == 0)
2404 puts_filtered (" ");
2406 if (B_TST (bits
, bitno
))
2407 printf_filtered (("1"));
2409 printf_filtered (("0"));
2413 /* Note the first arg should be the "this" pointer, we may not want to
2414 include it since we may get into a infinitely recursive
2418 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2424 for (i
= 0; i
< nargs
; i
++)
2425 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2430 dump_fn_fieldlists (struct type
*type
, int spaces
)
2436 printfi_filtered (spaces
, "fn_fieldlists ");
2437 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2438 printf_filtered ("\n");
2439 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2441 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2442 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2444 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2445 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2447 printf_filtered (_(") length %d\n"),
2448 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2449 for (overload_idx
= 0;
2450 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2453 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2455 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2456 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2458 printf_filtered (")\n");
2459 printfi_filtered (spaces
+ 8, "type ");
2460 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2462 printf_filtered ("\n");
2464 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2467 printfi_filtered (spaces
+ 8, "args ");
2468 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2470 printf_filtered ("\n");
2472 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2473 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
,
2476 printfi_filtered (spaces
+ 8, "fcontext ");
2477 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2479 printf_filtered ("\n");
2481 printfi_filtered (spaces
+ 8, "is_const %d\n",
2482 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2483 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2484 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2485 printfi_filtered (spaces
+ 8, "is_private %d\n",
2486 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2487 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2488 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2489 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2490 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2491 printfi_filtered (spaces
+ 8, "voffset %u\n",
2492 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2498 print_cplus_stuff (struct type
*type
, int spaces
)
2500 printfi_filtered (spaces
, "n_baseclasses %d\n",
2501 TYPE_N_BASECLASSES (type
));
2502 printfi_filtered (spaces
, "nfn_fields %d\n",
2503 TYPE_NFN_FIELDS (type
));
2504 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2505 TYPE_NFN_FIELDS_TOTAL (type
));
2506 if (TYPE_N_BASECLASSES (type
) > 0)
2508 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2509 TYPE_N_BASECLASSES (type
));
2510 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
),
2512 printf_filtered (")");
2514 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2515 TYPE_N_BASECLASSES (type
));
2516 puts_filtered ("\n");
2518 if (TYPE_NFIELDS (type
) > 0)
2520 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2522 printfi_filtered (spaces
,
2523 "private_field_bits (%d bits at *",
2524 TYPE_NFIELDS (type
));
2525 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
),
2527 printf_filtered (")");
2528 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2529 TYPE_NFIELDS (type
));
2530 puts_filtered ("\n");
2532 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2534 printfi_filtered (spaces
,
2535 "protected_field_bits (%d bits at *",
2536 TYPE_NFIELDS (type
));
2537 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
),
2539 printf_filtered (")");
2540 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2541 TYPE_NFIELDS (type
));
2542 puts_filtered ("\n");
2545 if (TYPE_NFN_FIELDS (type
) > 0)
2547 dump_fn_fieldlists (type
, spaces
);
2552 print_bound_type (int bt
)
2556 case BOUND_CANNOT_BE_DETERMINED
:
2557 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2559 case BOUND_BY_REF_ON_STACK
:
2560 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2562 case BOUND_BY_VALUE_ON_STACK
:
2563 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2565 case BOUND_BY_REF_IN_REG
:
2566 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2568 case BOUND_BY_VALUE_IN_REG
:
2569 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2572 printf_filtered ("(BOUND_SIMPLE)");
2575 printf_filtered (_("(unknown bound type)"));
2580 static struct obstack dont_print_type_obstack
;
2583 recursive_dump_type (struct type
*type
, int spaces
)
2588 obstack_begin (&dont_print_type_obstack
, 0);
2590 if (TYPE_NFIELDS (type
) > 0
2591 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2593 struct type
**first_dont_print
2594 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2596 int i
= (struct type
**)
2597 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
2601 if (type
== first_dont_print
[i
])
2603 printfi_filtered (spaces
, "type node ");
2604 gdb_print_host_address (type
, gdb_stdout
);
2605 printf_filtered (_(" <same as already seen type>\n"));
2610 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2613 printfi_filtered (spaces
, "type node ");
2614 gdb_print_host_address (type
, gdb_stdout
);
2615 printf_filtered ("\n");
2616 printfi_filtered (spaces
, "name '%s' (",
2617 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2618 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2619 printf_filtered (")\n");
2620 printfi_filtered (spaces
, "tagname '%s' (",
2621 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2622 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2623 printf_filtered (")\n");
2624 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2625 switch (TYPE_CODE (type
))
2627 case TYPE_CODE_UNDEF
:
2628 printf_filtered ("(TYPE_CODE_UNDEF)");
2631 printf_filtered ("(TYPE_CODE_PTR)");
2633 case TYPE_CODE_ARRAY
:
2634 printf_filtered ("(TYPE_CODE_ARRAY)");
2636 case TYPE_CODE_STRUCT
:
2637 printf_filtered ("(TYPE_CODE_STRUCT)");
2639 case TYPE_CODE_UNION
:
2640 printf_filtered ("(TYPE_CODE_UNION)");
2642 case TYPE_CODE_ENUM
:
2643 printf_filtered ("(TYPE_CODE_ENUM)");
2645 case TYPE_CODE_FLAGS
:
2646 printf_filtered ("(TYPE_CODE_FLAGS)");
2648 case TYPE_CODE_FUNC
:
2649 printf_filtered ("(TYPE_CODE_FUNC)");
2652 printf_filtered ("(TYPE_CODE_INT)");
2655 printf_filtered ("(TYPE_CODE_FLT)");
2657 case TYPE_CODE_VOID
:
2658 printf_filtered ("(TYPE_CODE_VOID)");
2661 printf_filtered ("(TYPE_CODE_SET)");
2663 case TYPE_CODE_RANGE
:
2664 printf_filtered ("(TYPE_CODE_RANGE)");
2666 case TYPE_CODE_STRING
:
2667 printf_filtered ("(TYPE_CODE_STRING)");
2669 case TYPE_CODE_BITSTRING
:
2670 printf_filtered ("(TYPE_CODE_BITSTRING)");
2672 case TYPE_CODE_ERROR
:
2673 printf_filtered ("(TYPE_CODE_ERROR)");
2675 case TYPE_CODE_MEMBERPTR
:
2676 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2678 case TYPE_CODE_METHODPTR
:
2679 printf_filtered ("(TYPE_CODE_METHODPTR)");
2681 case TYPE_CODE_METHOD
:
2682 printf_filtered ("(TYPE_CODE_METHOD)");
2685 printf_filtered ("(TYPE_CODE_REF)");
2687 case TYPE_CODE_CHAR
:
2688 printf_filtered ("(TYPE_CODE_CHAR)");
2690 case TYPE_CODE_BOOL
:
2691 printf_filtered ("(TYPE_CODE_BOOL)");
2693 case TYPE_CODE_COMPLEX
:
2694 printf_filtered ("(TYPE_CODE_COMPLEX)");
2696 case TYPE_CODE_TYPEDEF
:
2697 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2699 case TYPE_CODE_TEMPLATE
:
2700 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2702 case TYPE_CODE_TEMPLATE_ARG
:
2703 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2705 case TYPE_CODE_NAMESPACE
:
2706 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2709 printf_filtered ("(UNKNOWN TYPE CODE)");
2712 puts_filtered ("\n");
2713 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2714 printfi_filtered (spaces
, "upper_bound_type 0x%x ",
2715 TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
2716 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
2717 puts_filtered ("\n");
2718 printfi_filtered (spaces
, "lower_bound_type 0x%x ",
2719 TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
2720 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
2721 puts_filtered ("\n");
2722 printfi_filtered (spaces
, "objfile ");
2723 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
2724 printf_filtered ("\n");
2725 printfi_filtered (spaces
, "target_type ");
2726 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2727 printf_filtered ("\n");
2728 if (TYPE_TARGET_TYPE (type
) != NULL
)
2730 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2732 printfi_filtered (spaces
, "pointer_type ");
2733 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2734 printf_filtered ("\n");
2735 printfi_filtered (spaces
, "reference_type ");
2736 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2737 printf_filtered ("\n");
2738 printfi_filtered (spaces
, "type_chain ");
2739 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
2740 printf_filtered ("\n");
2741 printfi_filtered (spaces
, "instance_flags 0x%x",
2742 TYPE_INSTANCE_FLAGS (type
));
2743 if (TYPE_CONST (type
))
2745 puts_filtered (" TYPE_FLAG_CONST");
2747 if (TYPE_VOLATILE (type
))
2749 puts_filtered (" TYPE_FLAG_VOLATILE");
2751 if (TYPE_CODE_SPACE (type
))
2753 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2755 if (TYPE_DATA_SPACE (type
))
2757 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2759 if (TYPE_ADDRESS_CLASS_1 (type
))
2761 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
2763 if (TYPE_ADDRESS_CLASS_2 (type
))
2765 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
2767 puts_filtered ("\n");
2768 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
2769 if (TYPE_UNSIGNED (type
))
2771 puts_filtered (" TYPE_FLAG_UNSIGNED");
2773 if (TYPE_NOSIGN (type
))
2775 puts_filtered (" TYPE_FLAG_NOSIGN");
2777 if (TYPE_STUB (type
))
2779 puts_filtered (" TYPE_FLAG_STUB");
2781 if (TYPE_TARGET_STUB (type
))
2783 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2785 if (TYPE_STATIC (type
))
2787 puts_filtered (" TYPE_FLAG_STATIC");
2789 if (TYPE_PROTOTYPED (type
))
2791 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2793 if (TYPE_INCOMPLETE (type
))
2795 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2797 if (TYPE_VARARGS (type
))
2799 puts_filtered (" TYPE_FLAG_VARARGS");
2801 /* This is used for things like AltiVec registers on ppc. Gcc emits
2802 an attribute for the array type, which tells whether or not we
2803 have a vector, instead of a regular array. */
2804 if (TYPE_VECTOR (type
))
2806 puts_filtered (" TYPE_FLAG_VECTOR");
2808 puts_filtered ("\n");
2809 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2810 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
2811 puts_filtered ("\n");
2812 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2814 printfi_filtered (spaces
+ 2,
2815 "[%d] bitpos %d bitsize %d type ",
2816 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2817 TYPE_FIELD_BITSIZE (type
, idx
));
2818 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2819 printf_filtered (" name '%s' (",
2820 TYPE_FIELD_NAME (type
, idx
) != NULL
2821 ? TYPE_FIELD_NAME (type
, idx
)
2823 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2824 printf_filtered (")\n");
2825 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2827 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2830 printfi_filtered (spaces
, "vptr_basetype ");
2831 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2832 puts_filtered ("\n");
2833 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2835 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2837 printfi_filtered (spaces
, "vptr_fieldno %d\n",
2838 TYPE_VPTR_FIELDNO (type
));
2839 switch (TYPE_CODE (type
))
2841 case TYPE_CODE_STRUCT
:
2842 printfi_filtered (spaces
, "cplus_stuff ");
2843 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
),
2845 puts_filtered ("\n");
2846 print_cplus_stuff (type
, spaces
);
2850 printfi_filtered (spaces
, "floatformat ");
2851 if (TYPE_FLOATFORMAT (type
) == NULL
)
2852 puts_filtered ("(null)");
2855 puts_filtered ("{ ");
2856 if (TYPE_FLOATFORMAT (type
)[0] == NULL
2857 || TYPE_FLOATFORMAT (type
)[0]->name
== NULL
)
2858 puts_filtered ("(null)");
2860 puts_filtered (TYPE_FLOATFORMAT (type
)[0]->name
);
2862 puts_filtered (", ");
2863 if (TYPE_FLOATFORMAT (type
)[1] == NULL
2864 || TYPE_FLOATFORMAT (type
)[1]->name
== NULL
)
2865 puts_filtered ("(null)");
2867 puts_filtered (TYPE_FLOATFORMAT (type
)[1]->name
);
2869 puts_filtered (" }");
2871 puts_filtered ("\n");
2875 /* We have to pick one of the union types to be able print and
2876 test the value. Pick cplus_struct_type, even though we know
2877 it isn't any particular one. */
2878 printfi_filtered (spaces
, "type_specific ");
2879 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2880 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
2882 printf_filtered (_(" (unknown data form)"));
2884 printf_filtered ("\n");
2889 obstack_free (&dont_print_type_obstack
, NULL
);
2892 /* Trivial helpers for the libiberty hash table, for mapping one
2897 struct type
*old
, *new;
2901 type_pair_hash (const void *item
)
2903 const struct type_pair
*pair
= item
;
2904 return htab_hash_pointer (pair
->old
);
2908 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
2910 const struct type_pair
*lhs
= item_lhs
, *rhs
= item_rhs
;
2911 return lhs
->old
== rhs
->old
;
2914 /* Allocate the hash table used by copy_type_recursive to walk
2915 types without duplicates. We use OBJFILE's obstack, because
2916 OBJFILE is about to be deleted. */
2919 create_copied_types_hash (struct objfile
*objfile
)
2921 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
2922 NULL
, &objfile
->objfile_obstack
,
2923 hashtab_obstack_allocate
,
2924 dummy_obstack_deallocate
);
2927 /* Recursively copy (deep copy) TYPE, if it is associated with
2928 OBJFILE. Return a new type allocated using malloc, a saved type if
2929 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
2930 not associated with OBJFILE. */
2933 copy_type_recursive (struct objfile
*objfile
,
2935 htab_t copied_types
)
2937 struct type_pair
*stored
, pair
;
2939 struct type
*new_type
;
2941 if (TYPE_OBJFILE (type
) == NULL
)
2944 /* This type shouldn't be pointing to any types in other objfiles;
2945 if it did, the type might disappear unexpectedly. */
2946 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
2949 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
2951 return ((struct type_pair
*) *slot
)->new;
2953 new_type
= alloc_type (NULL
);
2955 /* We must add the new type to the hash table immediately, in case
2956 we encounter this type again during a recursive call below. */
2957 stored
= xmalloc (sizeof (struct type_pair
));
2959 stored
->new = new_type
;
2962 /* Copy the common fields of types. */
2963 TYPE_CODE (new_type
) = TYPE_CODE (type
);
2964 TYPE_ARRAY_UPPER_BOUND_TYPE (new_type
) =
2965 TYPE_ARRAY_UPPER_BOUND_TYPE (type
);
2966 TYPE_ARRAY_LOWER_BOUND_TYPE (new_type
) =
2967 TYPE_ARRAY_LOWER_BOUND_TYPE (type
);
2968 if (TYPE_NAME (type
))
2969 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
2970 if (TYPE_TAG_NAME (type
))
2971 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
2972 TYPE_FLAGS (new_type
) = TYPE_FLAGS (type
);
2973 TYPE_VPTR_FIELDNO (new_type
) = TYPE_VPTR_FIELDNO (type
);
2975 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
2976 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
2978 /* Copy the fields. */
2979 TYPE_NFIELDS (new_type
) = TYPE_NFIELDS (type
);
2980 if (TYPE_NFIELDS (type
))
2984 nfields
= TYPE_NFIELDS (type
);
2985 TYPE_FIELDS (new_type
) = xmalloc (sizeof (struct field
) * nfields
);
2986 for (i
= 0; i
< nfields
; i
++)
2988 TYPE_FIELD_ARTIFICIAL (new_type
, i
) =
2989 TYPE_FIELD_ARTIFICIAL (type
, i
);
2990 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
2991 if (TYPE_FIELD_TYPE (type
, i
))
2992 TYPE_FIELD_TYPE (new_type
, i
)
2993 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
2995 if (TYPE_FIELD_NAME (type
, i
))
2996 TYPE_FIELD_NAME (new_type
, i
) =
2997 xstrdup (TYPE_FIELD_NAME (type
, i
));
2998 if (TYPE_FIELD_STATIC_HAS_ADDR (type
, i
))
2999 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
3000 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
3001 else if (TYPE_FIELD_STATIC (type
, i
))
3002 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
3003 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
,
3007 TYPE_FIELD_BITPOS (new_type
, i
) =
3008 TYPE_FIELD_BITPOS (type
, i
);
3009 TYPE_FIELD_STATIC_KIND (new_type
, i
) = 0;
3014 /* Copy pointers to other types. */
3015 if (TYPE_TARGET_TYPE (type
))
3016 TYPE_TARGET_TYPE (new_type
) =
3017 copy_type_recursive (objfile
,
3018 TYPE_TARGET_TYPE (type
),
3020 if (TYPE_VPTR_BASETYPE (type
))
3021 TYPE_VPTR_BASETYPE (new_type
) =
3022 copy_type_recursive (objfile
,
3023 TYPE_VPTR_BASETYPE (type
),
3025 /* Maybe copy the type_specific bits.
3027 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3028 base classes and methods. There's no fundamental reason why we
3029 can't, but at the moment it is not needed. */
3031 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
3032 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
3033 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3034 || TYPE_CODE (type
) == TYPE_CODE_UNION
3035 || TYPE_CODE (type
) == TYPE_CODE_TEMPLATE
3036 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
3037 INIT_CPLUS_SPECIFIC (new_type
);
3042 static struct type
*
3043 build_flt (int bit
, char *name
, const struct floatformat
**floatformats
)
3049 gdb_assert (floatformats
!= NULL
);
3050 gdb_assert (floatformats
[0] != NULL
&& floatformats
[1] != NULL
);
3051 bit
= floatformats
[0]->totalsize
;
3053 gdb_assert (bit
>= 0);
3055 t
= init_type (TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
, 0, name
, NULL
);
3056 TYPE_FLOATFORMAT (t
) = floatformats
;
3060 static struct gdbarch_data
*gdbtypes_data
;
3062 const struct builtin_type
*
3063 builtin_type (struct gdbarch
*gdbarch
)
3065 return gdbarch_data (gdbarch
, gdbtypes_data
);
3069 static struct type
*
3070 build_complex (int bit
, char *name
, struct type
*target_type
)
3073 if (bit
<= 0 || target_type
== builtin_type_error
)
3075 gdb_assert (builtin_type_error
!= NULL
);
3076 return builtin_type_error
;
3078 t
= init_type (TYPE_CODE_COMPLEX
, 2 * bit
/ TARGET_CHAR_BIT
,
3079 0, name
, (struct objfile
*) NULL
);
3080 TYPE_TARGET_TYPE (t
) = target_type
;
3085 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3087 struct builtin_type
*builtin_type
3088 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3090 builtin_type
->builtin_void
=
3091 init_type (TYPE_CODE_VOID
, 1,
3093 "void", (struct objfile
*) NULL
);
3094 builtin_type
->builtin_char
=
3095 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3097 | (gdbarch_char_signed (gdbarch
) ? 0 : TYPE_FLAG_UNSIGNED
)),
3098 "char", (struct objfile
*) NULL
);
3099 builtin_type
->builtin_true_char
=
3100 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3102 "true character", (struct objfile
*) NULL
);
3103 builtin_type
->builtin_true_unsigned_char
=
3104 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3106 "true character", (struct objfile
*) NULL
);
3107 builtin_type
->builtin_signed_char
=
3108 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3110 "signed char", (struct objfile
*) NULL
);
3111 builtin_type
->builtin_unsigned_char
=
3112 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3114 "unsigned char", (struct objfile
*) NULL
);
3115 builtin_type
->builtin_short
=
3116 init_type (TYPE_CODE_INT
,
3117 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3118 0, "short", (struct objfile
*) NULL
);
3119 builtin_type
->builtin_unsigned_short
=
3120 init_type (TYPE_CODE_INT
,
3121 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3122 TYPE_FLAG_UNSIGNED
, "unsigned short",
3123 (struct objfile
*) NULL
);
3124 builtin_type
->builtin_int
=
3125 init_type (TYPE_CODE_INT
,
3126 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3127 0, "int", (struct objfile
*) NULL
);
3128 builtin_type
->builtin_unsigned_int
=
3129 init_type (TYPE_CODE_INT
,
3130 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3131 TYPE_FLAG_UNSIGNED
, "unsigned int",
3132 (struct objfile
*) NULL
);
3133 builtin_type
->builtin_long
=
3134 init_type (TYPE_CODE_INT
,
3135 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3136 0, "long", (struct objfile
*) NULL
);
3137 builtin_type
->builtin_unsigned_long
=
3138 init_type (TYPE_CODE_INT
,
3139 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3140 TYPE_FLAG_UNSIGNED
, "unsigned long",
3141 (struct objfile
*) NULL
);
3142 builtin_type
->builtin_long_long
=
3143 init_type (TYPE_CODE_INT
,
3144 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3145 0, "long long", (struct objfile
*) NULL
);
3146 builtin_type
->builtin_unsigned_long_long
=
3147 init_type (TYPE_CODE_INT
,
3148 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3149 TYPE_FLAG_UNSIGNED
, "unsigned long long",
3150 (struct objfile
*) NULL
);
3151 builtin_type
->builtin_float
3152 = build_flt (gdbarch_float_bit (gdbarch
), "float",
3153 gdbarch_float_format (gdbarch
));
3154 builtin_type
->builtin_double
3155 = build_flt (gdbarch_double_bit (gdbarch
), "double",
3156 gdbarch_double_format (gdbarch
));
3157 builtin_type
->builtin_long_double
3158 = build_flt (gdbarch_long_double_bit (gdbarch
), "long double",
3159 gdbarch_long_double_format (gdbarch
));
3160 builtin_type
->builtin_complex
3161 = build_complex (gdbarch_float_bit (gdbarch
), "complex",
3162 builtin_type
->builtin_float
);
3163 builtin_type
->builtin_double_complex
3164 = build_complex (gdbarch_double_bit (gdbarch
), "double complex",
3165 builtin_type
->builtin_double
);
3166 builtin_type
->builtin_string
=
3167 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3169 "string", (struct objfile
*) NULL
);
3170 builtin_type
->builtin_bool
=
3171 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3173 "bool", (struct objfile
*) NULL
);
3175 /* The following three are about decimal floating point types, which
3176 are 32-bits, 64-bits and 128-bits respectively. */
3177 builtin_type
->builtin_decfloat
3178 = init_type (TYPE_CODE_DECFLOAT
, 32 / 8,
3180 "decimal float", (struct objfile
*) NULL
);
3181 builtin_type
->builtin_decdouble
3182 = init_type (TYPE_CODE_DECFLOAT
, 64 / 8,
3184 "decimal double", (struct objfile
*) NULL
);
3185 builtin_type
->builtin_declong
3186 = init_type (TYPE_CODE_DECFLOAT
, 128 / 8,
3188 "decimal long double", (struct objfile
*) NULL
);
3190 /* Pointer/Address types. */
3192 /* NOTE: on some targets, addresses and pointers are not necessarily
3193 the same --- for example, on the D10V, pointers are 16 bits long,
3194 but addresses are 32 bits long. See doc/gdbint.texinfo,
3195 ``Pointers Are Not Always Addresses''.
3198 - gdb's `struct type' always describes the target's
3200 - gdb's `struct value' objects should always hold values in
3202 - gdb's CORE_ADDR values are addresses in the unified virtual
3203 address space that the assembler and linker work with. Thus,
3204 since target_read_memory takes a CORE_ADDR as an argument, it
3205 can access any memory on the target, even if the processor has
3206 separate code and data address spaces.
3209 - If v is a value holding a D10V code pointer, its contents are
3210 in target form: a big-endian address left-shifted two bits.
3211 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3212 sizeof (void *) == 2 on the target.
3214 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3215 target type for a value the target will never see. It's only
3216 used to hold the values of (typeless) linker symbols, which are
3217 indeed in the unified virtual address space. */
3219 builtin_type
->builtin_data_ptr
=
3220 make_pointer_type (builtin_type
->builtin_void
, NULL
);
3221 builtin_type
->builtin_func_ptr
=
3222 lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3223 builtin_type
->builtin_core_addr
=
3224 init_type (TYPE_CODE_INT
,
3225 gdbarch_addr_bit (gdbarch
) / 8,
3227 "__CORE_ADDR", (struct objfile
*) NULL
);
3230 /* The following set of types is used for symbols with no
3231 debug information. */
3232 builtin_type
->nodebug_text_symbol
=
3233 init_type (TYPE_CODE_FUNC
, 1, 0,
3234 "<text variable, no debug info>", NULL
);
3235 TYPE_TARGET_TYPE (builtin_type
->nodebug_text_symbol
) =
3236 builtin_type
->builtin_int
;
3237 builtin_type
->nodebug_data_symbol
=
3238 init_type (TYPE_CODE_INT
,
3239 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3240 "<data variable, no debug info>", NULL
);
3241 builtin_type
->nodebug_unknown_symbol
=
3242 init_type (TYPE_CODE_INT
, 1, 0,
3243 "<variable (not text or data), no debug info>", NULL
);
3244 builtin_type
->nodebug_tls_symbol
=
3245 init_type (TYPE_CODE_INT
,
3246 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3247 "<thread local variable, no debug info>", NULL
);
3249 return builtin_type
;
3252 extern void _initialize_gdbtypes (void);
3254 _initialize_gdbtypes (void)
3256 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
3258 /* FIXME: The following types are architecture-neutral. However,
3259 they contain pointer_type and reference_type fields potentially
3260 caching pointer or reference types that *are* architecture
3264 init_type (TYPE_CODE_INT
, 0 / 8,
3266 "int0_t", (struct objfile
*) NULL
);
3268 init_type (TYPE_CODE_INT
, 8 / 8,
3270 "int8_t", (struct objfile
*) NULL
);
3271 builtin_type_uint8
=
3272 init_type (TYPE_CODE_INT
, 8 / 8,
3273 TYPE_FLAG_UNSIGNED
| TYPE_FLAG_NOTTEXT
,
3274 "uint8_t", (struct objfile
*) NULL
);
3275 builtin_type_int16
=
3276 init_type (TYPE_CODE_INT
, 16 / 8,
3278 "int16_t", (struct objfile
*) NULL
);
3279 builtin_type_uint16
=
3280 init_type (TYPE_CODE_INT
, 16 / 8,
3282 "uint16_t", (struct objfile
*) NULL
);
3283 builtin_type_int32
=
3284 init_type (TYPE_CODE_INT
, 32 / 8,
3286 "int32_t", (struct objfile
*) NULL
);
3287 builtin_type_uint32
=
3288 init_type (TYPE_CODE_INT
, 32 / 8,
3290 "uint32_t", (struct objfile
*) NULL
);
3291 builtin_type_int64
=
3292 init_type (TYPE_CODE_INT
, 64 / 8,
3294 "int64_t", (struct objfile
*) NULL
);
3295 builtin_type_uint64
=
3296 init_type (TYPE_CODE_INT
, 64 / 8,
3298 "uint64_t", (struct objfile
*) NULL
);
3299 builtin_type_int128
=
3300 init_type (TYPE_CODE_INT
, 128 / 8,
3302 "int128_t", (struct objfile
*) NULL
);
3303 builtin_type_uint128
=
3304 init_type (TYPE_CODE_INT
, 128 / 8,
3306 "uint128_t", (struct objfile
*) NULL
);
3308 builtin_type_ieee_single
=
3309 build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single
);
3310 builtin_type_ieee_double
=
3311 build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double
);
3312 builtin_type_i387_ext
=
3313 build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext
);
3314 builtin_type_m68881_ext
=
3315 build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext
);
3316 builtin_type_arm_ext
=
3317 build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext
);
3318 builtin_type_ia64_spill
=
3319 build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill
);
3320 builtin_type_ia64_quad
=
3321 build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad
);
3323 add_setshow_zinteger_cmd ("overload", no_class
, &overload_debug
, _("\
3324 Set debugging of C++ overloading."), _("\
3325 Show debugging of C++ overloading."), _("\
3326 When enabled, ranking of the functions is displayed."),
3328 show_overload_debug
,
3329 &setdebuglist
, &showdebuglist
);
3331 /* Add user knob for controlling resolution of opaque types. */
3332 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
3333 &opaque_type_resolution
, _("\
3334 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3335 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL
,
3337 show_opaque_type_resolution
,
3338 &setlist
, &showlist
);