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 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 2 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, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
26 #include "gdb_string.h"
32 #include "expression.h"
37 #include "complaints.h"
41 #include "gdb_assert.h"
44 /* These variables point to the objects
45 representing the predefined C data types. */
47 struct type *builtin_type_void;
48 struct type *builtin_type_char;
49 struct type *builtin_type_true_char;
50 struct type *builtin_type_short;
51 struct type *builtin_type_int;
52 struct type *builtin_type_long;
53 struct type *builtin_type_long_long;
54 struct type *builtin_type_signed_char;
55 struct type *builtin_type_unsigned_char;
56 struct type *builtin_type_unsigned_short;
57 struct type *builtin_type_unsigned_int;
58 struct type *builtin_type_unsigned_long;
59 struct type *builtin_type_unsigned_long_long;
60 struct type *builtin_type_float;
61 struct type *builtin_type_double;
62 struct type *builtin_type_long_double;
63 struct type *builtin_type_complex;
64 struct type *builtin_type_double_complex;
65 struct type *builtin_type_string;
66 struct type *builtin_type_int0;
67 struct type *builtin_type_int8;
68 struct type *builtin_type_uint8;
69 struct type *builtin_type_int16;
70 struct type *builtin_type_uint16;
71 struct type *builtin_type_int32;
72 struct type *builtin_type_uint32;
73 struct type *builtin_type_int64;
74 struct type *builtin_type_uint64;
75 struct type *builtin_type_int128;
76 struct type *builtin_type_uint128;
77 struct type *builtin_type_bool;
79 /* Floatformat pairs. */
80 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
81 &floatformat_ieee_single_big,
82 &floatformat_ieee_single_little
84 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
85 &floatformat_ieee_double_big,
86 &floatformat_ieee_double_little
88 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
89 &floatformat_ieee_double_big,
90 &floatformat_ieee_double_littlebyte_bigword
92 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
93 &floatformat_i387_ext,
96 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
97 &floatformat_m68881_ext,
98 &floatformat_m68881_ext
100 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
101 &floatformat_arm_ext_big,
102 &floatformat_arm_ext_littlebyte_bigword
104 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
105 &floatformat_ia64_spill_big,
106 &floatformat_ia64_spill_little
108 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
109 &floatformat_ia64_quad_big,
110 &floatformat_ia64_quad_little
112 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
116 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
121 struct type *builtin_type_ieee_single;
122 struct type *builtin_type_ieee_double;
123 struct type *builtin_type_i387_ext;
124 struct type *builtin_type_m68881_ext;
125 struct type *builtin_type_arm_ext;
126 struct type *builtin_type_ia64_spill;
127 struct type *builtin_type_ia64_quad;
129 struct type *builtin_type_void_data_ptr;
130 struct type *builtin_type_void_func_ptr;
131 struct type *builtin_type_CORE_ADDR;
132 struct type *builtin_type_bfd_vma;
134 int opaque_type_resolution = 1;
136 show_opaque_type_resolution (struct ui_file *file, int from_tty,
137 struct cmd_list_element *c, const char *value)
139 fprintf_filtered (file, _("\
140 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
144 int overload_debug = 0;
146 show_overload_debug (struct ui_file *file, int from_tty,
147 struct cmd_list_element *c, const char *value)
149 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"), value);
156 }; /* maximum extension is 128! FIXME */
158 static void print_bit_vector (B_TYPE *, int);
159 static void print_arg_types (struct field *, int, int);
160 static void dump_fn_fieldlists (struct type *, int);
161 static void print_cplus_stuff (struct type *, int);
162 static void virtual_base_list_aux (struct type *dclass);
165 /* Alloc a new type structure and fill it with some defaults. If
166 OBJFILE is non-NULL, then allocate the space for the type structure
167 in that objfile's objfile_obstack. Otherwise allocate the new type structure
168 by xmalloc () (for permanent types). */
171 alloc_type (struct objfile *objfile)
175 /* Alloc the structure and start off with all fields zeroed. */
179 type = xmalloc (sizeof (struct type));
180 memset (type, 0, sizeof (struct type));
181 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
185 type = obstack_alloc (&objfile->objfile_obstack,
186 sizeof (struct type));
187 memset (type, 0, sizeof (struct type));
188 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
189 sizeof (struct main_type));
190 OBJSTAT (objfile, n_types++);
192 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
194 /* Initialize the fields that might not be zero. */
196 TYPE_CODE (type) = TYPE_CODE_UNDEF;
197 TYPE_OBJFILE (type) = objfile;
198 TYPE_VPTR_FIELDNO (type) = -1;
199 TYPE_CHAIN (type) = type; /* Chain back to itself. */
204 /* Alloc a new type instance structure, fill it with some defaults,
205 and point it at OLDTYPE. Allocate the new type instance from the
206 same place as OLDTYPE. */
209 alloc_type_instance (struct type *oldtype)
213 /* Allocate the structure. */
215 if (TYPE_OBJFILE (oldtype) == NULL)
217 type = xmalloc (sizeof (struct type));
218 memset (type, 0, sizeof (struct type));
222 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
223 sizeof (struct type));
224 memset (type, 0, sizeof (struct type));
226 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
228 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
233 /* Clear all remnants of the previous type at TYPE, in preparation for
234 replacing it with something else. */
236 smash_type (struct type *type)
238 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
240 /* For now, delete the rings. */
241 TYPE_CHAIN (type) = type;
243 /* For now, leave the pointer/reference types alone. */
246 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
247 to a pointer to memory where the pointer type should be stored.
248 If *TYPEPTR is zero, update it to point to the pointer type we return.
249 We allocate new memory if needed. */
252 make_pointer_type (struct type *type, struct type **typeptr)
254 struct type *ntype; /* New type */
255 struct objfile *objfile;
258 ntype = TYPE_POINTER_TYPE (type);
263 return ntype; /* Don't care about alloc, and have new type. */
264 else if (*typeptr == 0)
266 *typeptr = ntype; /* Tracking alloc, and we have new type. */
271 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
273 ntype = alloc_type (TYPE_OBJFILE (type));
278 /* We have storage, but need to reset it. */
281 objfile = TYPE_OBJFILE (ntype);
282 chain = TYPE_CHAIN (ntype);
284 TYPE_CHAIN (ntype) = chain;
285 TYPE_OBJFILE (ntype) = objfile;
288 TYPE_TARGET_TYPE (ntype) = type;
289 TYPE_POINTER_TYPE (type) = ntype;
291 /* FIXME! Assume the machine has only one representation for pointers! */
293 TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
294 TYPE_CODE (ntype) = TYPE_CODE_PTR;
296 /* Mark pointers as unsigned. The target converts between pointers
297 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
298 gdbarch_address_to_pointer. */
299 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
301 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
302 TYPE_POINTER_TYPE (type) = ntype;
304 /* Update the length of all the other variants of this type. */
305 chain = TYPE_CHAIN (ntype);
306 while (chain != ntype)
308 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
309 chain = TYPE_CHAIN (chain);
315 /* Given a type TYPE, return a type of pointers to that type.
316 May need to construct such a type if this is the first use. */
319 lookup_pointer_type (struct type *type)
321 return make_pointer_type (type, (struct type **) 0);
324 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
325 to a pointer to memory where the reference type should be stored.
326 If *TYPEPTR is zero, update it to point to the reference type we return.
327 We allocate new memory if needed. */
330 make_reference_type (struct type *type, struct type **typeptr)
332 struct type *ntype; /* New type */
333 struct objfile *objfile;
336 ntype = TYPE_REFERENCE_TYPE (type);
341 return ntype; /* Don't care about alloc, and have new type. */
342 else if (*typeptr == 0)
344 *typeptr = ntype; /* Tracking alloc, and we have new type. */
349 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
351 ntype = alloc_type (TYPE_OBJFILE (type));
356 /* We have storage, but need to reset it. */
359 objfile = TYPE_OBJFILE (ntype);
360 chain = TYPE_CHAIN (ntype);
362 TYPE_CHAIN (ntype) = chain;
363 TYPE_OBJFILE (ntype) = objfile;
366 TYPE_TARGET_TYPE (ntype) = type;
367 TYPE_REFERENCE_TYPE (type) = ntype;
369 /* FIXME! Assume the machine has only one representation for references,
370 and that it matches the (only) representation for pointers! */
372 TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
373 TYPE_CODE (ntype) = TYPE_CODE_REF;
375 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
376 TYPE_REFERENCE_TYPE (type) = ntype;
378 /* Update the length of all the other variants of this type. */
379 chain = TYPE_CHAIN (ntype);
380 while (chain != ntype)
382 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
383 chain = TYPE_CHAIN (chain);
389 /* Same as above, but caller doesn't care about memory allocation details. */
392 lookup_reference_type (struct type *type)
394 return make_reference_type (type, (struct type **) 0);
397 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
398 to a pointer to memory where the function type should be stored.
399 If *TYPEPTR is zero, update it to point to the function type we return.
400 We allocate new memory if needed. */
403 make_function_type (struct type *type, struct type **typeptr)
405 struct type *ntype; /* New type */
406 struct objfile *objfile;
408 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
410 ntype = alloc_type (TYPE_OBJFILE (type));
415 /* We have storage, but need to reset it. */
418 objfile = TYPE_OBJFILE (ntype);
420 TYPE_OBJFILE (ntype) = objfile;
423 TYPE_TARGET_TYPE (ntype) = type;
425 TYPE_LENGTH (ntype) = 1;
426 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
432 /* Given a type TYPE, return a type of functions that return that type.
433 May need to construct such a type if this is the first use. */
436 lookup_function_type (struct type *type)
438 return make_function_type (type, (struct type **) 0);
441 /* Identify address space identifier by name --
442 return the integer flag defined in gdbtypes.h. */
444 address_space_name_to_int (char *space_identifier)
446 struct gdbarch *gdbarch = current_gdbarch;
448 /* Check for known address space delimiters. */
449 if (!strcmp (space_identifier, "code"))
450 return TYPE_FLAG_CODE_SPACE;
451 else if (!strcmp (space_identifier, "data"))
452 return TYPE_FLAG_DATA_SPACE;
453 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
454 && gdbarch_address_class_name_to_type_flags (gdbarch,
459 error (_("Unknown address space specifier: \"%s\""), space_identifier);
462 /* Identify address space identifier by integer flag as defined in
463 gdbtypes.h -- return the string version of the adress space name. */
466 address_space_int_to_name (int space_flag)
468 struct gdbarch *gdbarch = current_gdbarch;
469 if (space_flag & TYPE_FLAG_CODE_SPACE)
471 else if (space_flag & TYPE_FLAG_DATA_SPACE)
473 else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL)
474 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
475 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
480 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
482 If STORAGE is non-NULL, create the new type instance there.
483 STORAGE must be in the same obstack as TYPE. */
486 make_qualified_type (struct type *type, int new_flags,
487 struct type *storage)
493 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
495 ntype = TYPE_CHAIN (ntype);
496 } while (ntype != type);
498 /* Create a new type instance. */
500 ntype = alloc_type_instance (type);
503 /* If STORAGE was provided, it had better be in the same objfile as
504 TYPE. Otherwise, we can't link it into TYPE's cv chain: if one
505 objfile is freed and the other kept, we'd have dangling
507 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
510 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
511 TYPE_CHAIN (ntype) = ntype;
514 /* Pointers or references to the original type are not relevant to
516 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
517 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
519 /* Chain the new qualified type to the old type. */
520 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
521 TYPE_CHAIN (type) = ntype;
523 /* Now set the instance flags and return the new type. */
524 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
526 /* Set length of new type to that of the original type. */
527 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
532 /* Make an address-space-delimited variant of a type -- a type that
533 is identical to the one supplied except that it has an address
534 space attribute attached to it (such as "code" or "data").
536 The space attributes "code" and "data" are for Harvard architectures.
537 The address space attributes are for architectures which have
538 alternately sized pointers or pointers with alternate representations. */
541 make_type_with_address_space (struct type *type, int space_flag)
544 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
545 & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE
546 | TYPE_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, struct type *type, struct type **typeptr)
566 struct type *ntype; /* New type */
567 struct type *tmp_type = type; /* tmp type */
568 struct objfile *objfile;
570 int new_flags = (TYPE_INSTANCE_FLAGS (type)
571 & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
574 new_flags |= TYPE_FLAG_CONST;
577 new_flags |= TYPE_FLAG_VOLATILE;
579 if (typeptr && *typeptr != NULL)
581 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
582 a C-V variant chain that threads across objfiles: if one
583 objfile gets freed, then the other has a broken C-V chain.
585 This code used to try to copy over the main type from TYPE to
586 *TYPEPTR if they were in different objfiles, but that's
587 wrong, too: TYPE may have a field list or member function
588 lists, which refer to types of their own, etc. etc. The
589 whole shebang would need to be copied over recursively; you
590 can't have inter-objfile pointers. The only thing to do is
591 to leave stub types as stub types, and look them up afresh by
592 name each time you encounter them. */
593 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
596 ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
604 /* Replace the contents of ntype with the type *type. This changes the
605 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
606 the changes are propogated to all types in the TYPE_CHAIN.
608 In order to build recursive types, it's inevitable that we'll need
609 to update types in place --- but this sort of indiscriminate
610 smashing is ugly, and needs to be replaced with something more
611 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
612 clear if more steps are needed. */
614 replace_type (struct type *ntype, struct type *type)
618 /* These two types had better be in the same objfile. Otherwise,
619 the assignment of one type's main type structure to the other
620 will produce a type with references to objects (names; field
621 lists; etc.) allocated on an objfile other than its own. */
622 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
624 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
626 /* The type length is not a part of the main type. Update it for each
627 type on the variant chain. */
630 /* Assert that this element of the chain has no address-class bits
631 set in its flags. Such type variants might have type lengths
632 which are supposed to be different from the non-address-class
633 variants. This assertion shouldn't ever be triggered because
634 symbol readers which do construct address-class variants don't
635 call replace_type(). */
636 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
638 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
639 chain = TYPE_CHAIN (chain);
640 } while (ntype != chain);
642 /* Assert that the two types have equivalent instance qualifiers.
643 This should be true for at least all of our debug readers. */
644 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
647 /* Implement direct support for MEMBER_TYPE in GNU C++.
648 May need to construct such a type if this is the first use.
649 The TYPE is the type of the member. The DOMAIN is the type
650 of the aggregate that the member belongs to. */
653 lookup_memberptr_type (struct type *type, struct type *domain)
657 mtype = alloc_type (TYPE_OBJFILE (type));
658 smash_to_memberptr_type (mtype, domain, type);
662 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
665 lookup_methodptr_type (struct type *to_type)
669 mtype = alloc_type (TYPE_OBJFILE (to_type));
670 TYPE_TARGET_TYPE (mtype) = to_type;
671 TYPE_DOMAIN_TYPE (mtype) = TYPE_DOMAIN_TYPE (to_type);
672 TYPE_LENGTH (mtype) = cplus_method_ptr_size ();
673 TYPE_CODE (mtype) = TYPE_CODE_METHODPTR;
677 /* Allocate a stub method whose return type is TYPE.
678 This apparently happens for speed of symbol reading, since parsing
679 out the arguments to the method is cpu-intensive, the way we are doing
680 it. So, we will fill in arguments later.
681 This always returns a fresh type. */
684 allocate_stub_method (struct type *type)
688 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
689 TYPE_OBJFILE (type));
690 TYPE_TARGET_TYPE (mtype) = type;
691 /* _DOMAIN_TYPE (mtype) = unknown yet */
695 /* Create a range type using either a blank type supplied in RESULT_TYPE,
696 or creating a new type, inheriting the objfile from INDEX_TYPE.
698 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
699 HIGH_BOUND, inclusive.
701 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
702 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
705 create_range_type (struct type *result_type, struct type *index_type,
706 int low_bound, int high_bound)
708 if (result_type == NULL)
710 result_type = alloc_type (TYPE_OBJFILE (index_type));
712 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
713 TYPE_TARGET_TYPE (result_type) = index_type;
714 if (TYPE_STUB (index_type))
715 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
717 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
718 TYPE_NFIELDS (result_type) = 2;
719 TYPE_FIELDS (result_type) = (struct field *)
720 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
721 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
722 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
723 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
724 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
725 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
728 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
730 return (result_type);
733 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
734 Return 1 if type is a range type, 0 if it is discrete (and bounds
735 will fit in LONGEST), or -1 otherwise. */
738 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
740 CHECK_TYPEDEF (type);
741 switch (TYPE_CODE (type))
743 case TYPE_CODE_RANGE:
744 *lowp = TYPE_LOW_BOUND (type);
745 *highp = TYPE_HIGH_BOUND (type);
748 if (TYPE_NFIELDS (type) > 0)
750 /* The enums may not be sorted by value, so search all
754 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
755 for (i = 0; i < TYPE_NFIELDS (type); i++)
757 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
758 *lowp = TYPE_FIELD_BITPOS (type, i);
759 if (TYPE_FIELD_BITPOS (type, i) > *highp)
760 *highp = TYPE_FIELD_BITPOS (type, i);
763 /* Set unsigned indicator if warranted. */
766 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
780 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
782 if (!TYPE_UNSIGNED (type))
784 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
788 /* ... fall through for unsigned ints ... */
791 /* This round-about calculation is to avoid shifting by
792 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
793 if TYPE_LENGTH (type) == sizeof (LONGEST). */
794 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
795 *highp = (*highp - 1) | *highp;
802 /* Create an array type using either a blank type supplied in RESULT_TYPE,
803 or creating a new type, inheriting the objfile from RANGE_TYPE.
805 Elements will be of type ELEMENT_TYPE, the indices will be of type
808 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
809 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
812 create_array_type (struct type *result_type, struct type *element_type,
813 struct type *range_type)
815 LONGEST low_bound, high_bound;
817 if (result_type == NULL)
819 result_type = alloc_type (TYPE_OBJFILE (range_type));
821 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
822 TYPE_TARGET_TYPE (result_type) = element_type;
823 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
824 low_bound = high_bound = 0;
825 CHECK_TYPEDEF (element_type);
826 TYPE_LENGTH (result_type) =
827 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
828 TYPE_NFIELDS (result_type) = 1;
829 TYPE_FIELDS (result_type) =
830 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
831 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
832 TYPE_FIELD_TYPE (result_type, 0) = range_type;
833 TYPE_VPTR_FIELDNO (result_type) = -1;
835 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
836 if (TYPE_LENGTH (result_type) == 0)
837 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
839 return (result_type);
842 /* Create a string type using either a blank type supplied in RESULT_TYPE,
843 or creating a new type. String types are similar enough to array of
844 char types that we can use create_array_type to build the basic type
845 and then bash it into a string type.
847 For fixed length strings, the range type contains 0 as the lower
848 bound and the length of the string minus one as the upper bound.
850 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
851 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
854 create_string_type (struct type *result_type, struct type *range_type)
856 struct type *string_char_type;
858 string_char_type = language_string_char_type (current_language,
860 result_type = create_array_type (result_type,
863 TYPE_CODE (result_type) = TYPE_CODE_STRING;
864 return (result_type);
868 create_set_type (struct type *result_type, struct type *domain_type)
870 LONGEST low_bound, high_bound, bit_length;
871 if (result_type == NULL)
873 result_type = alloc_type (TYPE_OBJFILE (domain_type));
875 TYPE_CODE (result_type) = TYPE_CODE_SET;
876 TYPE_NFIELDS (result_type) = 1;
877 TYPE_FIELDS (result_type) = (struct field *)
878 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
879 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
881 if (!TYPE_STUB (domain_type))
883 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
884 low_bound = high_bound = 0;
885 bit_length = high_bound - low_bound + 1;
886 TYPE_LENGTH (result_type)
887 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
889 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
892 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
894 return (result_type);
898 append_flags_type_flag (struct type *type, int bitpos, char *name)
900 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
901 gdb_assert (bitpos < TYPE_NFIELDS (type));
902 gdb_assert (bitpos >= 0);
906 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
907 TYPE_FIELD_BITPOS (type, bitpos) = bitpos;
911 /* Don't show this field to the user. */
912 TYPE_FIELD_BITPOS (type, bitpos) = -1;
917 init_flags_type (char *name, int length)
919 int nfields = length * TARGET_CHAR_BIT;
922 type = init_type (TYPE_CODE_FLAGS, length, TYPE_FLAG_UNSIGNED, name, NULL);
923 TYPE_NFIELDS (type) = nfields;
924 TYPE_FIELDS (type) = TYPE_ALLOC (type, nfields * sizeof (struct field));
925 memset (TYPE_FIELDS (type), 0, nfields * sizeof (struct field));
931 init_vector_type (struct type *elt_type, int n)
933 struct type *array_type;
935 array_type = create_array_type (0, elt_type,
936 create_range_type (0, builtin_type_int,
938 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
942 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
943 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
944 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
945 TYPE doesn't include the offset (that's the value of the MEMBER
946 itself), but does include the structure type into which it points
949 When "smashing" the type, we preserve the objfile that the
950 old type pointed to, since we aren't changing where the type is actually
954 smash_to_memberptr_type (struct type *type, struct type *domain,
955 struct type *to_type)
957 struct objfile *objfile;
959 objfile = TYPE_OBJFILE (type);
962 TYPE_OBJFILE (type) = objfile;
963 TYPE_TARGET_TYPE (type) = to_type;
964 TYPE_DOMAIN_TYPE (type) = domain;
965 /* Assume that a data member pointer is the same size as a normal
967 TYPE_LENGTH (type) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
968 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
971 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
972 METHOD just means `function that gets an extra "this" argument'.
974 When "smashing" the type, we preserve the objfile that the
975 old type pointed to, since we aren't changing where the type is actually
979 smash_to_method_type (struct type *type, struct type *domain,
980 struct type *to_type, struct field *args,
981 int nargs, int varargs)
983 struct objfile *objfile;
985 objfile = TYPE_OBJFILE (type);
988 TYPE_OBJFILE (type) = objfile;
989 TYPE_TARGET_TYPE (type) = to_type;
990 TYPE_DOMAIN_TYPE (type) = domain;
991 TYPE_FIELDS (type) = args;
992 TYPE_NFIELDS (type) = nargs;
994 TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
995 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
996 TYPE_CODE (type) = TYPE_CODE_METHOD;
999 /* Return a typename for a struct/union/enum type without "struct ",
1000 "union ", or "enum ". If the type has a NULL name, return NULL. */
1003 type_name_no_tag (const struct type *type)
1005 if (TYPE_TAG_NAME (type) != NULL)
1006 return TYPE_TAG_NAME (type);
1008 /* Is there code which expects this to return the name if there is no
1009 tag name? My guess is that this is mainly used for C++ in cases where
1010 the two will always be the same. */
1011 return TYPE_NAME (type);
1014 /* Lookup a typedef or primitive type named NAME,
1015 visible in lexical block BLOCK.
1016 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1019 lookup_typename (char *name, struct block *block, int noerr)
1024 sym = lookup_symbol (name, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
1025 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1027 tmp = language_lookup_primitive_type_by_name (current_language,
1034 else if (!tmp && noerr)
1040 error (_("No type named %s."), name);
1043 return (SYMBOL_TYPE (sym));
1047 lookup_unsigned_typename (char *name)
1049 char *uns = alloca (strlen (name) + 10);
1051 strcpy (uns, "unsigned ");
1052 strcpy (uns + 9, name);
1053 return (lookup_typename (uns, (struct block *) NULL, 0));
1057 lookup_signed_typename (char *name)
1060 char *uns = alloca (strlen (name) + 8);
1062 strcpy (uns, "signed ");
1063 strcpy (uns + 7, name);
1064 t = lookup_typename (uns, (struct block *) NULL, 1);
1065 /* If we don't find "signed FOO" just try again with plain "FOO". */
1068 return lookup_typename (name, (struct block *) NULL, 0);
1071 /* Lookup a structure type named "struct NAME",
1072 visible in lexical block BLOCK. */
1075 lookup_struct (char *name, struct block *block)
1079 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1080 (struct symtab **) NULL);
1084 error (_("No struct type named %s."), name);
1086 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1088 error (_("This context has class, union or enum %s, not a struct."), name);
1090 return (SYMBOL_TYPE (sym));
1093 /* Lookup a union type named "union NAME",
1094 visible in lexical block BLOCK. */
1097 lookup_union (char *name, struct block *block)
1102 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1103 (struct symtab **) NULL);
1106 error (_("No union type named %s."), name);
1108 t = SYMBOL_TYPE (sym);
1110 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1113 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1114 * a further "declared_type" field to discover it is really a union.
1116 if (HAVE_CPLUS_STRUCT (t))
1117 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1120 /* If we get here, it's not a union */
1121 error (_("This context has class, struct or enum %s, not a union."), name);
1125 /* Lookup an enum type named "enum NAME",
1126 visible in lexical block BLOCK. */
1129 lookup_enum (char *name, struct block *block)
1133 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1134 (struct symtab **) NULL);
1137 error (_("No enum type named %s."), name);
1139 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1141 error (_("This context has class, struct or union %s, not an enum."), name);
1143 return (SYMBOL_TYPE (sym));
1146 /* Lookup a template type named "template NAME<TYPE>",
1147 visible in lexical block BLOCK. */
1150 lookup_template_type (char *name, struct type *type, struct block *block)
1153 char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1156 strcat (nam, TYPE_NAME (type));
1157 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1159 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
1163 error (_("No template type named %s."), name);
1165 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1167 error (_("This context has class, union or enum %s, not a struct."), name);
1169 return (SYMBOL_TYPE (sym));
1172 /* Given a type TYPE, lookup the type of the component of type named NAME.
1174 TYPE can be either a struct or union, or a pointer or reference to a struct or
1175 union. If it is a pointer or reference, its target type is automatically used.
1176 Thus '.' and '->' are interchangable, as specified for the definitions of the
1177 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1179 If NOERR is nonzero, return zero if NAME is not suitably defined.
1180 If NAME is the name of a baseclass type, return that type. */
1183 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1189 CHECK_TYPEDEF (type);
1190 if (TYPE_CODE (type) != TYPE_CODE_PTR
1191 && TYPE_CODE (type) != TYPE_CODE_REF)
1193 type = TYPE_TARGET_TYPE (type);
1196 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1197 TYPE_CODE (type) != TYPE_CODE_UNION)
1199 target_terminal_ours ();
1200 gdb_flush (gdb_stdout);
1201 fprintf_unfiltered (gdb_stderr, "Type ");
1202 type_print (type, "", gdb_stderr, -1);
1203 error (_(" is not a structure or union type."));
1207 /* FIXME: This change put in by Michael seems incorrect for the case where
1208 the structure tag name is the same as the member name. I.E. when doing
1209 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1214 typename = type_name_no_tag (type);
1215 if (typename != NULL && strcmp (typename, name) == 0)
1220 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1222 char *t_field_name = TYPE_FIELD_NAME (type, i);
1224 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1226 return TYPE_FIELD_TYPE (type, i);
1230 /* OK, it's not in this class. Recursively check the baseclasses. */
1231 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1235 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1247 target_terminal_ours ();
1248 gdb_flush (gdb_stdout);
1249 fprintf_unfiltered (gdb_stderr, "Type ");
1250 type_print (type, "", gdb_stderr, -1);
1251 fprintf_unfiltered (gdb_stderr, " has no component named ");
1252 fputs_filtered (name, gdb_stderr);
1254 return (struct type *) -1; /* For lint */
1257 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1258 valid. Callers should be aware that in some cases (for example,
1259 the type or one of its baseclasses is a stub type and we are
1260 debugging a .o file), this function will not be able to find the virtual
1261 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1262 will remain NULL. */
1265 fill_in_vptr_fieldno (struct type *type)
1267 CHECK_TYPEDEF (type);
1269 if (TYPE_VPTR_FIELDNO (type) < 0)
1273 /* We must start at zero in case the first (and only) baseclass is
1274 virtual (and hence we cannot share the table pointer). */
1275 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1277 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1278 fill_in_vptr_fieldno (baseclass);
1279 if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
1281 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
1282 TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
1289 /* Find the method and field indices for the destructor in class type T.
1290 Return 1 if the destructor was found, otherwise, return 0. */
1293 get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
1297 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1300 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1302 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1304 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1316 stub_noname_complaint (void)
1318 complaint (&symfile_complaints, _("stub type has NULL name"));
1321 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1323 If this is a stubbed struct (i.e. declared as struct foo *), see if
1324 we can find a full definition in some other file. If so, copy this
1325 definition, so we can use it in future. There used to be a comment (but
1326 not any code) that if we don't find a full definition, we'd set a flag
1327 so we don't spend time in the future checking the same type. That would
1328 be a mistake, though--we might load in more symbols which contain a
1329 full definition for the type.
1331 This used to be coded as a macro, but I don't think it is called
1332 often enough to merit such treatment. */
1334 /* Find the real type of TYPE. This function returns the real type, after
1335 removing all layers of typedefs and completing opaque or stub types.
1336 Completion changes the TYPE argument, but stripping of typedefs does
1340 check_typedef (struct type *type)
1342 struct type *orig_type = type;
1343 int is_const, is_volatile;
1345 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1347 if (!TYPE_TARGET_TYPE (type))
1352 /* It is dangerous to call lookup_symbol if we are currently
1353 reading a symtab. Infinite recursion is one danger. */
1354 if (currently_reading_symtab)
1357 name = type_name_no_tag (type);
1358 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1359 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1360 as appropriate? (this code was written before TYPE_NAME and
1361 TYPE_TAG_NAME were separate). */
1364 stub_noname_complaint ();
1367 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
1368 (struct symtab **) NULL);
1370 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1372 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1374 type = TYPE_TARGET_TYPE (type);
1377 is_const = TYPE_CONST (type);
1378 is_volatile = TYPE_VOLATILE (type);
1380 /* If this is a struct/class/union with no fields, then check whether a
1381 full definition exists somewhere else. This is for systems where a
1382 type definition with no fields is issued for such types, instead of
1383 identifying them as stub types in the first place */
1385 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1387 char *name = type_name_no_tag (type);
1388 struct type *newtype;
1391 stub_noname_complaint ();
1394 newtype = lookup_transparent_type (name);
1398 /* If the resolved type and the stub are in the same objfile,
1399 then replace the stub type with the real deal. But if
1400 they're in separate objfiles, leave the stub alone; we'll
1401 just look up the transparent type every time we call
1402 check_typedef. We can't create pointers between types
1403 allocated to different objfiles, since they may have
1404 different lifetimes. Trying to copy NEWTYPE over to TYPE's
1405 objfile is pointless, too, since you'll have to move over any
1406 other types NEWTYPE refers to, which could be an unbounded
1408 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
1409 make_cv_type (is_const, is_volatile, newtype, &type);
1414 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1415 else if (TYPE_STUB (type) && !currently_reading_symtab)
1417 char *name = type_name_no_tag (type);
1418 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1419 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1420 as appropriate? (this code was written before TYPE_NAME and
1421 TYPE_TAG_NAME were separate). */
1425 stub_noname_complaint ();
1428 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL);
1431 /* Same as above for opaque types, we can replace the stub
1432 with the complete type only if they are int the same
1434 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
1435 make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type);
1437 type = SYMBOL_TYPE (sym);
1441 if (TYPE_TARGET_STUB (type))
1443 struct type *range_type;
1444 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1446 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1449 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1450 && TYPE_NFIELDS (type) == 1
1451 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1452 == TYPE_CODE_RANGE))
1454 /* Now recompute the length of the array type, based on its
1455 number of elements and the target type's length. */
1456 TYPE_LENGTH (type) =
1457 ((TYPE_FIELD_BITPOS (range_type, 1)
1458 - TYPE_FIELD_BITPOS (range_type, 0)
1460 * TYPE_LENGTH (target_type));
1461 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1463 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1465 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1466 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1469 /* Cache TYPE_LENGTH for future use. */
1470 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1474 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1475 silently return builtin_type_void. */
1477 static struct type *
1478 safe_parse_type (char *p, int length)
1480 struct ui_file *saved_gdb_stderr;
1483 /* Suppress error messages. */
1484 saved_gdb_stderr = gdb_stderr;
1485 gdb_stderr = ui_file_new ();
1487 /* Call parse_and_eval_type() without fear of longjmp()s. */
1488 if (!gdb_parse_and_eval_type (p, length, &type))
1489 type = builtin_type_void;
1491 /* Stop suppressing error messages. */
1492 ui_file_delete (gdb_stderr);
1493 gdb_stderr = saved_gdb_stderr;
1498 /* Ugly hack to convert method stubs into method types.
1500 He ain't kiddin'. This demangles the name of the method into a string
1501 including argument types, parses out each argument type, generates
1502 a string casting a zero to that type, evaluates the string, and stuffs
1503 the resulting type into an argtype vector!!! Then it knows the type
1504 of the whole function (including argument types for overloading),
1505 which info used to be in the stab's but was removed to hack back
1506 the space required for them. */
1509 check_stub_method (struct type *type, int method_id, int signature_id)
1512 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1513 char *demangled_name = cplus_demangle (mangled_name,
1514 DMGL_PARAMS | DMGL_ANSI);
1515 char *argtypetext, *p;
1516 int depth = 0, argcount = 1;
1517 struct field *argtypes;
1520 /* Make sure we got back a function string that we can use. */
1522 p = strchr (demangled_name, '(');
1526 if (demangled_name == NULL || p == NULL)
1527 error (_("Internal: Cannot demangle mangled name `%s'."), mangled_name);
1529 /* Now, read in the parameters that define this type. */
1534 if (*p == '(' || *p == '<')
1538 else if (*p == ')' || *p == '>')
1542 else if (*p == ',' && depth == 0)
1550 /* If we read one argument and it was ``void'', don't count it. */
1551 if (strncmp (argtypetext, "(void)", 6) == 0)
1554 /* We need one extra slot, for the THIS pointer. */
1556 argtypes = (struct field *)
1557 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1560 /* Add THIS pointer for non-static methods. */
1561 f = TYPE_FN_FIELDLIST1 (type, method_id);
1562 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1566 argtypes[0].type = lookup_pointer_type (type);
1570 if (*p != ')') /* () means no args, skip while */
1575 if (depth <= 0 && (*p == ',' || *p == ')'))
1577 /* Avoid parsing of ellipsis, they will be handled below.
1578 Also avoid ``void'' as above. */
1579 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1580 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1582 argtypes[argcount].type =
1583 safe_parse_type (argtypetext, p - argtypetext);
1586 argtypetext = p + 1;
1589 if (*p == '(' || *p == '<')
1593 else if (*p == ')' || *p == '>')
1602 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1604 /* Now update the old "stub" type into a real type. */
1605 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1606 TYPE_DOMAIN_TYPE (mtype) = type;
1607 TYPE_FIELDS (mtype) = argtypes;
1608 TYPE_NFIELDS (mtype) = argcount;
1609 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1610 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1612 TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1614 xfree (demangled_name);
1617 /* This is the external interface to check_stub_method, above. This function
1618 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1619 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1620 and TYPE_FN_FIELDLIST_NAME will be correct.
1622 This function unfortunately can not die until stabs do. */
1625 check_stub_method_group (struct type *type, int method_id)
1627 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1628 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1629 int j, found_stub = 0;
1631 for (j = 0; j < len; j++)
1632 if (TYPE_FN_FIELD_STUB (f, j))
1635 check_stub_method (type, method_id, j);
1638 /* GNU v3 methods with incorrect names were corrected when we read in
1639 type information, because it was cheaper to do it then. The only GNU v2
1640 methods with incorrect method names are operators and destructors;
1641 destructors were also corrected when we read in type information.
1643 Therefore the only thing we need to handle here are v2 operator
1645 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1648 char dem_opname[256];
1650 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1651 dem_opname, DMGL_ANSI);
1653 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1656 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1660 const struct cplus_struct_type cplus_struct_default;
1663 allocate_cplus_struct_type (struct type *type)
1665 if (!HAVE_CPLUS_STRUCT (type))
1667 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1668 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1669 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1673 /* Helper function to initialize the standard scalar types.
1675 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1676 of the string pointed to by name in the objfile_obstack for that objfile,
1677 and initialize the type name to that copy. There are places (mipsread.c
1678 in particular, where init_type is called with a NULL value for NAME). */
1681 init_type (enum type_code code, int length, int flags, char *name,
1682 struct objfile *objfile)
1686 type = alloc_type (objfile);
1687 TYPE_CODE (type) = code;
1688 TYPE_LENGTH (type) = length;
1689 TYPE_FLAGS (type) |= flags;
1690 if ((name != NULL) && (objfile != NULL))
1693 obsavestring (name, strlen (name), &objfile->objfile_obstack);
1697 TYPE_NAME (type) = name;
1702 if (name && strcmp (name, "char") == 0)
1703 TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
1705 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1706 || code == TYPE_CODE_NAMESPACE)
1708 INIT_CPLUS_SPECIFIC (type);
1713 /* Helper function. Create an empty composite type. */
1716 init_composite_type (char *name, enum type_code code)
1719 gdb_assert (code == TYPE_CODE_STRUCT
1720 || code == TYPE_CODE_UNION);
1721 t = init_type (code, 0, 0, NULL, NULL);
1722 TYPE_TAG_NAME (t) = name;
1726 /* Helper function. Append a field to a composite type. */
1729 append_composite_type_field (struct type *t, char *name, struct type *field)
1732 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1733 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1734 sizeof (struct field) * TYPE_NFIELDS (t));
1735 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1736 memset (f, 0, sizeof f[0]);
1737 FIELD_TYPE (f[0]) = field;
1738 FIELD_NAME (f[0]) = name;
1739 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1741 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1742 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1744 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1746 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1747 if (TYPE_NFIELDS (t) > 1)
1749 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1750 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1755 /* Look up a fundamental type for the specified objfile.
1756 May need to construct such a type if this is the first use.
1758 Some object file formats (ELF, COFF, etc) do not define fundamental
1759 types such as "int" or "double". Others (stabs for example), do
1760 define fundamental types.
1762 For the formats which don't provide fundamental types, gdb can create
1763 such types, using defaults reasonable for the current language and
1764 the current target machine.
1766 NOTE: This routine is obsolescent. Each debugging format reader
1767 should manage it's own fundamental types, either creating them from
1768 suitable defaults or reading them from the debugging information,
1769 whichever is appropriate. The DWARF reader has already been
1770 fixed to do this. Once the other readers are fixed, this routine
1771 will go away. Also note that fundamental types should be managed
1772 on a compilation unit basis in a multi-language environment, not
1773 on a linkage unit basis as is done here. */
1777 lookup_fundamental_type (struct objfile *objfile, int typeid)
1779 struct type **typep;
1782 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1784 error (_("internal error - invalid fundamental type id %d"), typeid);
1787 /* If this is the first time we need a fundamental type for this objfile
1788 then we need to initialize the vector of type pointers. */
1790 if (objfile->fundamental_types == NULL)
1792 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1793 objfile->fundamental_types = (struct type **)
1794 obstack_alloc (&objfile->objfile_obstack, nbytes);
1795 memset ((char *) objfile->fundamental_types, 0, nbytes);
1796 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1799 /* Look for this particular type in the fundamental type vector. If one is
1800 not found, create and install one appropriate for the current language. */
1802 typep = objfile->fundamental_types + typeid;
1805 *typep = create_fundamental_type (objfile, typeid);
1812 can_dereference (struct type *t)
1814 /* FIXME: Should we return true for references as well as pointers? */
1818 && TYPE_CODE (t) == TYPE_CODE_PTR
1819 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1823 is_integral_type (struct type *t)
1828 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1829 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1830 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
1831 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1832 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1833 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1836 /* Check whether BASE is an ancestor or base class or DCLASS
1837 Return 1 if so, and 0 if not.
1838 Note: callers may want to check for identity of the types before
1839 calling this function -- identical types are considered to satisfy
1840 the ancestor relationship even if they're identical */
1843 is_ancestor (struct type *base, struct type *dclass)
1847 CHECK_TYPEDEF (base);
1848 CHECK_TYPEDEF (dclass);
1852 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
1853 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1856 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1857 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1865 /* See whether DCLASS has a virtual table. This routine is aimed at
1866 the HP/Taligent ANSI C++ runtime model, and may not work with other
1867 runtime models. Return 1 => Yes, 0 => No. */
1870 has_vtable (struct type *dclass)
1872 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1873 has virtual functions or virtual bases. */
1877 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1880 /* First check for the presence of virtual bases */
1881 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1882 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1883 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1886 /* Next check for virtual functions */
1887 if (TYPE_FN_FIELDLISTS (dclass))
1888 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1889 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1892 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1893 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1894 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1895 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1896 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1899 /* Well, maybe we don't need a virtual table */
1903 /* Return a pointer to the "primary base class" of DCLASS.
1905 A NULL return indicates that DCLASS has no primary base, or that it
1906 couldn't be found (insufficient information).
1908 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1909 and may not work with other runtime models. */
1912 primary_base_class (struct type *dclass)
1914 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1915 is the first directly inherited, non-virtual base class that
1916 requires a virtual table */
1920 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1923 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1924 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1925 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1926 return TYPE_FIELD_TYPE (dclass, i);
1931 /* Global manipulated by virtual_base_list[_aux]() */
1933 static struct vbase *current_vbase_list = NULL;
1935 /* Return a pointer to a null-terminated list of struct vbase
1936 items. The vbasetype pointer of each item in the list points to the
1937 type information for a virtual base of the argument DCLASS.
1939 Helper function for virtual_base_list().
1940 Note: the list goes backward, right-to-left. virtual_base_list()
1941 copies the items out in reverse order. */
1944 virtual_base_list_aux (struct type *dclass)
1946 struct vbase *tmp_vbase;
1949 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1952 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1954 /* Recurse on this ancestor, first */
1955 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
1957 /* If this current base is itself virtual, add it to the list */
1958 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1960 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1962 /* Check if base already recorded */
1963 tmp_vbase = current_vbase_list;
1966 if (tmp_vbase->vbasetype == basetype)
1967 break; /* found it */
1968 tmp_vbase = tmp_vbase->next;
1971 if (!tmp_vbase) /* normal exit from loop */
1973 /* Allocate new item for this virtual base */
1974 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
1976 /* Stick it on at the end of the list */
1977 tmp_vbase->vbasetype = basetype;
1978 tmp_vbase->next = current_vbase_list;
1979 current_vbase_list = tmp_vbase;
1982 } /* for loop over bases */
1986 /* Compute the list of virtual bases in the right order. Virtual
1987 bases are laid out in the object's memory area in order of their
1988 occurrence in a depth-first, left-to-right search through the
1991 Argument DCLASS is the type whose virtual bases are required.
1992 Return value is the address of a null-terminated array of pointers
1993 to struct type items.
1995 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1996 and may not work with other runtime models.
1998 This routine merely hands off the argument to virtual_base_list_aux()
1999 and then copies the result into an array to save space. */
2002 virtual_base_list (struct type *dclass)
2004 struct vbase *tmp_vbase;
2005 struct vbase *tmp_vbase_2;
2008 struct type **vbase_array;
2010 current_vbase_list = NULL;
2011 virtual_base_list_aux (dclass);
2013 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2018 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
2020 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
2021 vbase_array[i] = tmp_vbase->vbasetype;
2023 /* Get rid of constructed chain */
2024 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2027 tmp_vbase = tmp_vbase->next;
2028 xfree (tmp_vbase_2);
2029 tmp_vbase_2 = tmp_vbase;
2032 vbase_array[count] = NULL;
2036 /* Return the length of the virtual base list of the type DCLASS. */
2039 virtual_base_list_length (struct type *dclass)
2042 struct vbase *tmp_vbase;
2044 current_vbase_list = NULL;
2045 virtual_base_list_aux (dclass);
2047 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2052 /* Return the number of elements of the virtual base list of the type
2053 DCLASS, ignoring those appearing in the primary base (and its
2054 primary base, recursively). */
2057 virtual_base_list_length_skip_primaries (struct type *dclass)
2060 struct vbase *tmp_vbase;
2061 struct type *primary;
2063 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2066 return virtual_base_list_length (dclass);
2068 current_vbase_list = NULL;
2069 virtual_base_list_aux (dclass);
2071 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
2073 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
2081 /* Return the index (position) of type BASE, which is a virtual base
2082 class of DCLASS, in the latter's virtual base list. A return of -1
2083 indicates "not found" or a problem. */
2086 virtual_base_index (struct type *base, struct type *dclass)
2091 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2092 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2096 vbase = virtual_base_list (dclass)[0];
2101 vbase = virtual_base_list (dclass)[++i];
2104 return vbase ? i : -1;
2109 /* Return the index (position) of type BASE, which is a virtual base
2110 class of DCLASS, in the latter's virtual base list. Skip over all
2111 bases that may appear in the virtual base list of the primary base
2112 class of DCLASS (recursively). A return of -1 indicates "not
2113 found" or a problem. */
2116 virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
2120 struct type *primary;
2122 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2123 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2126 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2130 vbase = virtual_base_list (dclass)[0];
2133 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2137 vbase = virtual_base_list (dclass)[++i];
2140 return vbase ? j : -1;
2143 /* Return position of a derived class DCLASS in the list of
2144 * primary bases starting with the remotest ancestor.
2145 * Position returned is 0-based. */
2148 class_index_in_primary_list (struct type *dclass)
2150 struct type *pbc; /* primary base class */
2152 /* Simply recurse on primary base */
2153 pbc = TYPE_PRIMARY_BASE (dclass);
2155 return 1 + class_index_in_primary_list (pbc);
2160 /* Return a count of the number of virtual functions a type has.
2161 * This includes all the virtual functions it inherits from its
2165 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2166 * functions only once (latest redefinition)
2170 count_virtual_fns (struct type *dclass)
2172 int fn, oi; /* function and overloaded instance indices */
2173 int vfuncs; /* count to return */
2175 /* recurse on bases that can share virtual table */
2176 struct type *pbc = primary_base_class (dclass);
2178 vfuncs = count_virtual_fns (pbc);
2182 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2183 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2184 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2192 /* Functions for overload resolution begin here */
2194 /* Compare two badness vectors A and B and return the result.
2195 * 0 => A and B are identical
2196 * 1 => A and B are incomparable
2197 * 2 => A is better than B
2198 * 3 => A is worse than B */
2201 compare_badness (struct badness_vector *a, struct badness_vector *b)
2205 short found_pos = 0; /* any positives in c? */
2206 short found_neg = 0; /* any negatives in c? */
2208 /* differing lengths => incomparable */
2209 if (a->length != b->length)
2212 /* Subtract b from a */
2213 for (i = 0; i < a->length; i++)
2215 tmp = a->rank[i] - b->rank[i];
2225 return 1; /* incomparable */
2227 return 3; /* A > B */
2233 return 2; /* A < B */
2235 return 0; /* A == B */
2239 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2240 * to the types of an argument list (ARGS, length NARGS).
2241 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2243 struct badness_vector *
2244 rank_function (struct type **parms, int nparms, struct type **args, int nargs)
2247 struct badness_vector *bv;
2248 int min_len = nparms < nargs ? nparms : nargs;
2250 bv = xmalloc (sizeof (struct badness_vector));
2251 bv->length = nargs + 1; /* add 1 for the length-match rank */
2252 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2254 /* First compare the lengths of the supplied lists.
2255 * If there is a mismatch, set it to a high value. */
2257 /* pai/1997-06-03 FIXME: when we have debug info about default
2258 * arguments and ellipsis parameter lists, we should consider those
2259 * and rank the length-match more finely. */
2261 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2263 /* Now rank all the parameters of the candidate function */
2264 for (i = 1; i <= min_len; i++)
2265 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2267 /* If more arguments than parameters, add dummy entries */
2268 for (i = min_len + 1; i <= nargs; i++)
2269 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2274 /* Compare the names of two integer types, assuming that any sign
2275 qualifiers have been checked already. We do it this way because
2276 there may be an "int" in the name of one of the types. */
2279 integer_types_same_name_p (const char *first, const char *second)
2281 int first_p, second_p;
2283 /* If both are shorts, return 1; if neither is a short, keep checking. */
2284 first_p = (strstr (first, "short") != NULL);
2285 second_p = (strstr (second, "short") != NULL);
2286 if (first_p && second_p)
2288 if (first_p || second_p)
2291 /* Likewise for long. */
2292 first_p = (strstr (first, "long") != NULL);
2293 second_p = (strstr (second, "long") != NULL);
2294 if (first_p && second_p)
2296 if (first_p || second_p)
2299 /* Likewise for char. */
2300 first_p = (strstr (first, "char") != NULL);
2301 second_p = (strstr (second, "char") != NULL);
2302 if (first_p && second_p)
2304 if (first_p || second_p)
2307 /* They must both be ints. */
2311 /* Compare one type (PARM) for compatibility with another (ARG).
2312 * PARM is intended to be the parameter type of a function; and
2313 * ARG is the supplied argument's type. This function tests if
2314 * the latter can be converted to the former.
2316 * Return 0 if they are identical types;
2317 * Otherwise, return an integer which corresponds to how compatible
2318 * PARM is to ARG. The higher the return value, the worse the match.
2319 * Generally the "bad" conversions are all uniformly assigned a 100 */
2322 rank_one_type (struct type *parm, struct type *arg)
2324 /* Identical type pointers */
2325 /* However, this still doesn't catch all cases of same type for arg
2326 * and param. The reason is that builtin types are different from
2327 * the same ones constructed from the object. */
2331 /* Resolve typedefs */
2332 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2333 parm = check_typedef (parm);
2334 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2335 arg = check_typedef (arg);
2338 Well, damnit, if the names are exactly the same,
2339 i'll say they are exactly the same. This happens when we generate
2340 method stubs. The types won't point to the same address, but they
2341 really are the same.
2344 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2345 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2348 /* Check if identical after resolving typedefs */
2352 /* See through references, since we can almost make non-references
2354 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2355 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2356 + REFERENCE_CONVERSION_BADNESS);
2357 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2358 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2359 + REFERENCE_CONVERSION_BADNESS);
2361 /* Debugging only. */
2362 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2363 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2365 /* x -> y means arg of type x being supplied for parameter of type y */
2367 switch (TYPE_CODE (parm))
2370 switch (TYPE_CODE (arg))
2373 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2374 return VOID_PTR_CONVERSION_BADNESS;
2376 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2377 case TYPE_CODE_ARRAY:
2378 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2379 case TYPE_CODE_FUNC:
2380 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2382 case TYPE_CODE_ENUM:
2383 case TYPE_CODE_FLAGS:
2384 case TYPE_CODE_CHAR:
2385 case TYPE_CODE_RANGE:
2386 case TYPE_CODE_BOOL:
2387 return POINTER_CONVERSION_BADNESS;
2389 return INCOMPATIBLE_TYPE_BADNESS;
2391 case TYPE_CODE_ARRAY:
2392 switch (TYPE_CODE (arg))
2395 case TYPE_CODE_ARRAY:
2396 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2398 return INCOMPATIBLE_TYPE_BADNESS;
2400 case TYPE_CODE_FUNC:
2401 switch (TYPE_CODE (arg))
2403 case TYPE_CODE_PTR: /* funcptr -> func */
2404 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2406 return INCOMPATIBLE_TYPE_BADNESS;
2409 switch (TYPE_CODE (arg))
2412 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2414 /* Deal with signed, unsigned, and plain chars and
2415 signed and unsigned ints */
2416 if (TYPE_NOSIGN (parm))
2418 /* This case only for character types */
2419 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2422 return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */
2424 else if (TYPE_UNSIGNED (parm))
2426 if (TYPE_UNSIGNED (arg))
2428 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2429 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2431 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2432 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
2433 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2435 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
2439 if (integer_types_same_name_p (TYPE_NAME (arg), "long")
2440 && integer_types_same_name_p (TYPE_NAME (parm), "int"))
2441 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
2443 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2446 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2448 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2450 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2451 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
2452 return INTEGER_PROMOTION_BADNESS;
2454 return INTEGER_CONVERSION_BADNESS;
2457 return INTEGER_CONVERSION_BADNESS;
2459 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2460 return INTEGER_PROMOTION_BADNESS;
2462 return INTEGER_CONVERSION_BADNESS;
2463 case TYPE_CODE_ENUM:
2464 case TYPE_CODE_FLAGS:
2465 case TYPE_CODE_CHAR:
2466 case TYPE_CODE_RANGE:
2467 case TYPE_CODE_BOOL:
2468 return INTEGER_PROMOTION_BADNESS;
2470 return INT_FLOAT_CONVERSION_BADNESS;
2472 return NS_POINTER_CONVERSION_BADNESS;
2474 return INCOMPATIBLE_TYPE_BADNESS;
2477 case TYPE_CODE_ENUM:
2478 switch (TYPE_CODE (arg))
2481 case TYPE_CODE_CHAR:
2482 case TYPE_CODE_RANGE:
2483 case TYPE_CODE_BOOL:
2484 case TYPE_CODE_ENUM:
2485 return INTEGER_CONVERSION_BADNESS;
2487 return INT_FLOAT_CONVERSION_BADNESS;
2489 return INCOMPATIBLE_TYPE_BADNESS;
2492 case TYPE_CODE_CHAR:
2493 switch (TYPE_CODE (arg))
2495 case TYPE_CODE_RANGE:
2496 case TYPE_CODE_BOOL:
2497 case TYPE_CODE_ENUM:
2498 return INTEGER_CONVERSION_BADNESS;
2500 return INT_FLOAT_CONVERSION_BADNESS;
2502 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2503 return INTEGER_CONVERSION_BADNESS;
2504 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2505 return INTEGER_PROMOTION_BADNESS;
2506 /* >>> !! else fall through !! <<< */
2507 case TYPE_CODE_CHAR:
2508 /* Deal with signed, unsigned, and plain chars for C++
2509 and with int cases falling through from previous case */
2510 if (TYPE_NOSIGN (parm))
2512 if (TYPE_NOSIGN (arg))
2515 return INTEGER_CONVERSION_BADNESS;
2517 else if (TYPE_UNSIGNED (parm))
2519 if (TYPE_UNSIGNED (arg))
2522 return INTEGER_PROMOTION_BADNESS;
2524 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2527 return INTEGER_CONVERSION_BADNESS;
2529 return INCOMPATIBLE_TYPE_BADNESS;
2532 case TYPE_CODE_RANGE:
2533 switch (TYPE_CODE (arg))
2536 case TYPE_CODE_CHAR:
2537 case TYPE_CODE_RANGE:
2538 case TYPE_CODE_BOOL:
2539 case TYPE_CODE_ENUM:
2540 return INTEGER_CONVERSION_BADNESS;
2542 return INT_FLOAT_CONVERSION_BADNESS;
2544 return INCOMPATIBLE_TYPE_BADNESS;
2547 case TYPE_CODE_BOOL:
2548 switch (TYPE_CODE (arg))
2551 case TYPE_CODE_CHAR:
2552 case TYPE_CODE_RANGE:
2553 case TYPE_CODE_ENUM:
2556 return BOOLEAN_CONVERSION_BADNESS;
2557 case TYPE_CODE_BOOL:
2560 return INCOMPATIBLE_TYPE_BADNESS;
2564 switch (TYPE_CODE (arg))
2567 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2568 return FLOAT_PROMOTION_BADNESS;
2569 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2572 return FLOAT_CONVERSION_BADNESS;
2574 case TYPE_CODE_BOOL:
2575 case TYPE_CODE_ENUM:
2576 case TYPE_CODE_RANGE:
2577 case TYPE_CODE_CHAR:
2578 return INT_FLOAT_CONVERSION_BADNESS;
2580 return INCOMPATIBLE_TYPE_BADNESS;
2583 case TYPE_CODE_COMPLEX:
2584 switch (TYPE_CODE (arg))
2585 { /* Strictly not needed for C++, but... */
2587 return FLOAT_PROMOTION_BADNESS;
2588 case TYPE_CODE_COMPLEX:
2591 return INCOMPATIBLE_TYPE_BADNESS;
2594 case TYPE_CODE_STRUCT:
2595 /* currently same as TYPE_CODE_CLASS */
2596 switch (TYPE_CODE (arg))
2598 case TYPE_CODE_STRUCT:
2599 /* Check for derivation */
2600 if (is_ancestor (parm, arg))
2601 return BASE_CONVERSION_BADNESS;
2602 /* else fall through */
2604 return INCOMPATIBLE_TYPE_BADNESS;
2607 case TYPE_CODE_UNION:
2608 switch (TYPE_CODE (arg))
2610 case TYPE_CODE_UNION:
2612 return INCOMPATIBLE_TYPE_BADNESS;
2615 case TYPE_CODE_MEMBERPTR:
2616 switch (TYPE_CODE (arg))
2619 return INCOMPATIBLE_TYPE_BADNESS;
2622 case TYPE_CODE_METHOD:
2623 switch (TYPE_CODE (arg))
2627 return INCOMPATIBLE_TYPE_BADNESS;
2631 switch (TYPE_CODE (arg))
2635 return INCOMPATIBLE_TYPE_BADNESS;
2640 switch (TYPE_CODE (arg))
2644 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2646 return INCOMPATIBLE_TYPE_BADNESS;
2649 case TYPE_CODE_VOID:
2651 return INCOMPATIBLE_TYPE_BADNESS;
2652 } /* switch (TYPE_CODE (arg)) */
2656 /* End of functions for overload resolution */
2659 print_bit_vector (B_TYPE *bits, int nbits)
2663 for (bitno = 0; bitno < nbits; bitno++)
2665 if ((bitno % 8) == 0)
2667 puts_filtered (" ");
2669 if (B_TST (bits, bitno))
2670 printf_filtered (("1"));
2672 printf_filtered (("0"));
2676 /* Note the first arg should be the "this" pointer, we may not want to
2677 include it since we may get into a infinitely recursive situation. */
2680 print_arg_types (struct field *args, int nargs, int spaces)
2686 for (i = 0; i < nargs; i++)
2687 recursive_dump_type (args[i].type, spaces + 2);
2692 dump_fn_fieldlists (struct type *type, int spaces)
2698 printfi_filtered (spaces, "fn_fieldlists ");
2699 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2700 printf_filtered ("\n");
2701 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2703 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2704 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2706 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2707 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2709 printf_filtered (_(") length %d\n"),
2710 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2711 for (overload_idx = 0;
2712 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2715 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2717 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2718 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2720 printf_filtered (")\n");
2721 printfi_filtered (spaces + 8, "type ");
2722 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2723 printf_filtered ("\n");
2725 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2728 printfi_filtered (spaces + 8, "args ");
2729 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2730 printf_filtered ("\n");
2732 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2733 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2735 printfi_filtered (spaces + 8, "fcontext ");
2736 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2738 printf_filtered ("\n");
2740 printfi_filtered (spaces + 8, "is_const %d\n",
2741 TYPE_FN_FIELD_CONST (f, overload_idx));
2742 printfi_filtered (spaces + 8, "is_volatile %d\n",
2743 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2744 printfi_filtered (spaces + 8, "is_private %d\n",
2745 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2746 printfi_filtered (spaces + 8, "is_protected %d\n",
2747 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2748 printfi_filtered (spaces + 8, "is_stub %d\n",
2749 TYPE_FN_FIELD_STUB (f, overload_idx));
2750 printfi_filtered (spaces + 8, "voffset %u\n",
2751 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2757 print_cplus_stuff (struct type *type, int spaces)
2759 printfi_filtered (spaces, "n_baseclasses %d\n",
2760 TYPE_N_BASECLASSES (type));
2761 printfi_filtered (spaces, "nfn_fields %d\n",
2762 TYPE_NFN_FIELDS (type));
2763 printfi_filtered (spaces, "nfn_fields_total %d\n",
2764 TYPE_NFN_FIELDS_TOTAL (type));
2765 if (TYPE_N_BASECLASSES (type) > 0)
2767 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2768 TYPE_N_BASECLASSES (type));
2769 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2770 printf_filtered (")");
2772 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2773 TYPE_N_BASECLASSES (type));
2774 puts_filtered ("\n");
2776 if (TYPE_NFIELDS (type) > 0)
2778 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2780 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2781 TYPE_NFIELDS (type));
2782 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2783 printf_filtered (")");
2784 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2785 TYPE_NFIELDS (type));
2786 puts_filtered ("\n");
2788 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2790 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2791 TYPE_NFIELDS (type));
2792 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2793 printf_filtered (")");
2794 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2795 TYPE_NFIELDS (type));
2796 puts_filtered ("\n");
2799 if (TYPE_NFN_FIELDS (type) > 0)
2801 dump_fn_fieldlists (type, spaces);
2806 print_bound_type (int bt)
2810 case BOUND_CANNOT_BE_DETERMINED:
2811 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2813 case BOUND_BY_REF_ON_STACK:
2814 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2816 case BOUND_BY_VALUE_ON_STACK:
2817 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2819 case BOUND_BY_REF_IN_REG:
2820 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2822 case BOUND_BY_VALUE_IN_REG:
2823 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2826 printf_filtered ("(BOUND_SIMPLE)");
2829 printf_filtered (_("(unknown bound type)"));
2834 static struct obstack dont_print_type_obstack;
2837 recursive_dump_type (struct type *type, int spaces)
2842 obstack_begin (&dont_print_type_obstack, 0);
2844 if (TYPE_NFIELDS (type) > 0
2845 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2847 struct type **first_dont_print
2848 = (struct type **) obstack_base (&dont_print_type_obstack);
2850 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2855 if (type == first_dont_print[i])
2857 printfi_filtered (spaces, "type node ");
2858 gdb_print_host_address (type, gdb_stdout);
2859 printf_filtered (_(" <same as already seen type>\n"));
2864 obstack_ptr_grow (&dont_print_type_obstack, type);
2867 printfi_filtered (spaces, "type node ");
2868 gdb_print_host_address (type, gdb_stdout);
2869 printf_filtered ("\n");
2870 printfi_filtered (spaces, "name '%s' (",
2871 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2872 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2873 printf_filtered (")\n");
2874 printfi_filtered (spaces, "tagname '%s' (",
2875 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2876 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2877 printf_filtered (")\n");
2878 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2879 switch (TYPE_CODE (type))
2881 case TYPE_CODE_UNDEF:
2882 printf_filtered ("(TYPE_CODE_UNDEF)");
2885 printf_filtered ("(TYPE_CODE_PTR)");
2887 case TYPE_CODE_ARRAY:
2888 printf_filtered ("(TYPE_CODE_ARRAY)");
2890 case TYPE_CODE_STRUCT:
2891 printf_filtered ("(TYPE_CODE_STRUCT)");
2893 case TYPE_CODE_UNION:
2894 printf_filtered ("(TYPE_CODE_UNION)");
2896 case TYPE_CODE_ENUM:
2897 printf_filtered ("(TYPE_CODE_ENUM)");
2899 case TYPE_CODE_FLAGS:
2900 printf_filtered ("(TYPE_CODE_FLAGS)");
2902 case TYPE_CODE_FUNC:
2903 printf_filtered ("(TYPE_CODE_FUNC)");
2906 printf_filtered ("(TYPE_CODE_INT)");
2909 printf_filtered ("(TYPE_CODE_FLT)");
2911 case TYPE_CODE_VOID:
2912 printf_filtered ("(TYPE_CODE_VOID)");
2915 printf_filtered ("(TYPE_CODE_SET)");
2917 case TYPE_CODE_RANGE:
2918 printf_filtered ("(TYPE_CODE_RANGE)");
2920 case TYPE_CODE_STRING:
2921 printf_filtered ("(TYPE_CODE_STRING)");
2923 case TYPE_CODE_BITSTRING:
2924 printf_filtered ("(TYPE_CODE_BITSTRING)");
2926 case TYPE_CODE_ERROR:
2927 printf_filtered ("(TYPE_CODE_ERROR)");
2929 case TYPE_CODE_MEMBERPTR:
2930 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2932 case TYPE_CODE_METHODPTR:
2933 printf_filtered ("(TYPE_CODE_METHODPTR)");
2935 case TYPE_CODE_METHOD:
2936 printf_filtered ("(TYPE_CODE_METHOD)");
2939 printf_filtered ("(TYPE_CODE_REF)");
2941 case TYPE_CODE_CHAR:
2942 printf_filtered ("(TYPE_CODE_CHAR)");
2944 case TYPE_CODE_BOOL:
2945 printf_filtered ("(TYPE_CODE_BOOL)");
2947 case TYPE_CODE_COMPLEX:
2948 printf_filtered ("(TYPE_CODE_COMPLEX)");
2950 case TYPE_CODE_TYPEDEF:
2951 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2953 case TYPE_CODE_TEMPLATE:
2954 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2956 case TYPE_CODE_TEMPLATE_ARG:
2957 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2959 case TYPE_CODE_NAMESPACE:
2960 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2963 printf_filtered ("(UNKNOWN TYPE CODE)");
2966 puts_filtered ("\n");
2967 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2968 printfi_filtered (spaces, "upper_bound_type 0x%x ",
2969 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2970 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2971 puts_filtered ("\n");
2972 printfi_filtered (spaces, "lower_bound_type 0x%x ",
2973 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2974 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2975 puts_filtered ("\n");
2976 printfi_filtered (spaces, "objfile ");
2977 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2978 printf_filtered ("\n");
2979 printfi_filtered (spaces, "target_type ");
2980 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2981 printf_filtered ("\n");
2982 if (TYPE_TARGET_TYPE (type) != NULL)
2984 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2986 printfi_filtered (spaces, "pointer_type ");
2987 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2988 printf_filtered ("\n");
2989 printfi_filtered (spaces, "reference_type ");
2990 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2991 printf_filtered ("\n");
2992 printfi_filtered (spaces, "type_chain ");
2993 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
2994 printf_filtered ("\n");
2995 printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
2996 if (TYPE_CONST (type))
2998 puts_filtered (" TYPE_FLAG_CONST");
3000 if (TYPE_VOLATILE (type))
3002 puts_filtered (" TYPE_FLAG_VOLATILE");
3004 if (TYPE_CODE_SPACE (type))
3006 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3008 if (TYPE_DATA_SPACE (type))
3010 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3012 if (TYPE_ADDRESS_CLASS_1 (type))
3014 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3016 if (TYPE_ADDRESS_CLASS_2 (type))
3018 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3020 puts_filtered ("\n");
3021 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
3022 if (TYPE_UNSIGNED (type))
3024 puts_filtered (" TYPE_FLAG_UNSIGNED");
3026 if (TYPE_NOSIGN (type))
3028 puts_filtered (" TYPE_FLAG_NOSIGN");
3030 if (TYPE_STUB (type))
3032 puts_filtered (" TYPE_FLAG_STUB");
3034 if (TYPE_TARGET_STUB (type))
3036 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3038 if (TYPE_STATIC (type))
3040 puts_filtered (" TYPE_FLAG_STATIC");
3042 if (TYPE_PROTOTYPED (type))
3044 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3046 if (TYPE_INCOMPLETE (type))
3048 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3050 if (TYPE_VARARGS (type))
3052 puts_filtered (" TYPE_FLAG_VARARGS");
3054 /* This is used for things like AltiVec registers on ppc. Gcc emits
3055 an attribute for the array type, which tells whether or not we
3056 have a vector, instead of a regular array. */
3057 if (TYPE_VECTOR (type))
3059 puts_filtered (" TYPE_FLAG_VECTOR");
3061 puts_filtered ("\n");
3062 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3063 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3064 puts_filtered ("\n");
3065 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3067 printfi_filtered (spaces + 2,
3068 "[%d] bitpos %d bitsize %d type ",
3069 idx, TYPE_FIELD_BITPOS (type, idx),
3070 TYPE_FIELD_BITSIZE (type, idx));
3071 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3072 printf_filtered (" name '%s' (",
3073 TYPE_FIELD_NAME (type, idx) != NULL
3074 ? TYPE_FIELD_NAME (type, idx)
3076 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3077 printf_filtered (")\n");
3078 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3080 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3083 printfi_filtered (spaces, "vptr_basetype ");
3084 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3085 puts_filtered ("\n");
3086 if (TYPE_VPTR_BASETYPE (type) != NULL)
3088 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3090 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3091 switch (TYPE_CODE (type))
3093 case TYPE_CODE_STRUCT:
3094 printfi_filtered (spaces, "cplus_stuff ");
3095 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3096 puts_filtered ("\n");
3097 print_cplus_stuff (type, spaces);
3101 printfi_filtered (spaces, "floatformat ");
3102 if (TYPE_FLOATFORMAT (type) == NULL)
3103 puts_filtered ("(null)");
3106 puts_filtered ("{ ");
3107 if (TYPE_FLOATFORMAT (type)[0] == NULL
3108 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
3109 puts_filtered ("(null)");
3111 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
3113 puts_filtered (", ");
3114 if (TYPE_FLOATFORMAT (type)[1] == NULL
3115 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
3116 puts_filtered ("(null)");
3118 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
3120 puts_filtered (" }");
3122 puts_filtered ("\n");
3126 /* We have to pick one of the union types to be able print and test
3127 the value. Pick cplus_struct_type, even though we know it isn't
3128 any particular one. */
3129 printfi_filtered (spaces, "type_specific ");
3130 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3131 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3133 printf_filtered (_(" (unknown data form)"));
3135 printf_filtered ("\n");
3140 obstack_free (&dont_print_type_obstack, NULL);
3143 /* Trivial helpers for the libiberty hash table, for mapping one
3148 struct type *old, *new;
3152 type_pair_hash (const void *item)
3154 const struct type_pair *pair = item;
3155 return htab_hash_pointer (pair->old);
3159 type_pair_eq (const void *item_lhs, const void *item_rhs)
3161 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
3162 return lhs->old == rhs->old;
3165 /* Allocate the hash table used by copy_type_recursive to walk
3166 types without duplicates. We use OBJFILE's obstack, because
3167 OBJFILE is about to be deleted. */
3170 create_copied_types_hash (struct objfile *objfile)
3172 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
3173 NULL, &objfile->objfile_obstack,
3174 hashtab_obstack_allocate,
3175 dummy_obstack_deallocate);
3178 /* Recursively copy (deep copy) TYPE, if it is associated with OBJFILE.
3179 Return a new type allocated using malloc, a saved type if we have already
3180 visited TYPE (using COPIED_TYPES), or TYPE if it is not associated with
3184 copy_type_recursive (struct objfile *objfile, struct type *type,
3185 htab_t copied_types)
3187 struct type_pair *stored, pair;
3189 struct type *new_type;
3191 if (TYPE_OBJFILE (type) == NULL)
3194 /* This type shouldn't be pointing to any types in other objfiles; if
3195 it did, the type might disappear unexpectedly. */
3196 gdb_assert (TYPE_OBJFILE (type) == objfile);
3199 slot = htab_find_slot (copied_types, &pair, INSERT);
3201 return ((struct type_pair *) *slot)->new;
3203 new_type = alloc_type (NULL);
3205 /* We must add the new type to the hash table immediately, in case
3206 we encounter this type again during a recursive call below. */
3207 stored = xmalloc (sizeof (struct type_pair));
3209 stored->new = new_type;
3212 /* Copy the common fields of types. */
3213 TYPE_CODE (new_type) = TYPE_CODE (type);
3214 TYPE_ARRAY_UPPER_BOUND_TYPE (new_type) = TYPE_ARRAY_UPPER_BOUND_TYPE (type);
3215 TYPE_ARRAY_LOWER_BOUND_TYPE (new_type) = TYPE_ARRAY_LOWER_BOUND_TYPE (type);
3216 if (TYPE_NAME (type))
3217 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
3218 if (TYPE_TAG_NAME (type))
3219 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
3220 TYPE_FLAGS (new_type) = TYPE_FLAGS (type);
3221 TYPE_VPTR_FIELDNO (new_type) = TYPE_VPTR_FIELDNO (type);
3223 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
3224 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
3226 /* Copy the fields. */
3227 TYPE_NFIELDS (new_type) = TYPE_NFIELDS (type);
3228 if (TYPE_NFIELDS (type))
3232 nfields = TYPE_NFIELDS (type);
3233 TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
3234 for (i = 0; i < nfields; i++)
3236 TYPE_FIELD_ARTIFICIAL (new_type, i) = TYPE_FIELD_ARTIFICIAL (type, i);
3237 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
3238 if (TYPE_FIELD_TYPE (type, i))
3239 TYPE_FIELD_TYPE (new_type, i)
3240 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
3242 if (TYPE_FIELD_NAME (type, i))
3243 TYPE_FIELD_NAME (new_type, i) = xstrdup (TYPE_FIELD_NAME (type, i));
3244 if (TYPE_FIELD_STATIC_HAS_ADDR (type, i))
3245 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
3246 TYPE_FIELD_STATIC_PHYSADDR (type, i));
3247 else if (TYPE_FIELD_STATIC (type, i))
3248 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
3249 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type, i)));
3252 TYPE_FIELD_BITPOS (new_type, i) = TYPE_FIELD_BITPOS (type, i);
3253 TYPE_FIELD_STATIC_KIND (new_type, i) = 0;
3258 /* Copy pointers to other types. */
3259 if (TYPE_TARGET_TYPE (type))
3260 TYPE_TARGET_TYPE (new_type) = copy_type_recursive (objfile,
3261 TYPE_TARGET_TYPE (type),
3263 if (TYPE_VPTR_BASETYPE (type))
3264 TYPE_VPTR_BASETYPE (new_type) = copy_type_recursive (objfile,
3265 TYPE_VPTR_BASETYPE (type),
3267 /* Maybe copy the type_specific bits.
3269 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3270 base classes and methods. There's no fundamental reason why we
3271 can't, but at the moment it is not needed. */
3273 if (TYPE_CODE (type) == TYPE_CODE_FLT)
3274 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
3275 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3276 || TYPE_CODE (type) == TYPE_CODE_UNION
3277 || TYPE_CODE (type) == TYPE_CODE_TEMPLATE
3278 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
3279 INIT_CPLUS_SPECIFIC (new_type);
3284 static struct type *
3285 build_flt (int bit, char *name, const struct floatformat **floatformats)
3291 gdb_assert (floatformats != NULL);
3292 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
3293 bit = floatformats[0]->totalsize;
3295 gdb_assert (bit >= 0);
3297 t = init_type (TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, 0, name, NULL);
3298 TYPE_FLOATFORMAT (t) = floatformats;
3303 build_gdbtypes (void)
3306 init_type (TYPE_CODE_VOID, 1,
3308 "void", (struct objfile *) NULL);
3310 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3312 | (gdbarch_char_signed (current_gdbarch) ?
3313 0 : TYPE_FLAG_UNSIGNED)),
3314 "char", (struct objfile *) NULL);
3315 builtin_type_true_char =
3316 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3318 "true character", (struct objfile *) NULL);
3319 builtin_type_signed_char =
3320 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3322 "signed char", (struct objfile *) NULL);
3323 builtin_type_unsigned_char =
3324 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3326 "unsigned char", (struct objfile *) NULL);
3327 builtin_type_short =
3328 init_type (TYPE_CODE_INT,
3329 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
3330 0, "short", (struct objfile *) NULL);
3331 builtin_type_unsigned_short =
3332 init_type (TYPE_CODE_INT,
3333 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
3334 TYPE_FLAG_UNSIGNED, "unsigned short", (struct objfile *) NULL);
3336 init_type (TYPE_CODE_INT,
3337 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
3338 0, "int", (struct objfile *) NULL);
3339 builtin_type_unsigned_int =
3340 init_type (TYPE_CODE_INT,
3341 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
3342 TYPE_FLAG_UNSIGNED, "unsigned int", (struct objfile *) NULL);
3344 init_type (TYPE_CODE_INT,
3345 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3346 0, "long", (struct objfile *) NULL);
3347 builtin_type_unsigned_long =
3348 init_type (TYPE_CODE_INT,
3349 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3350 TYPE_FLAG_UNSIGNED, "unsigned long", (struct objfile *) NULL);
3351 builtin_type_long_long =
3352 init_type (TYPE_CODE_INT,
3353 gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3354 0, "long long", (struct objfile *) NULL);
3355 builtin_type_unsigned_long_long =
3356 init_type (TYPE_CODE_INT,
3357 gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3359 "unsigned long long", (struct objfile *) NULL);
3362 = build_flt (gdbarch_float_bit (current_gdbarch), "float",
3363 gdbarch_float_format (current_gdbarch));
3365 = build_flt (gdbarch_double_bit (current_gdbarch), "double",
3366 gdbarch_double_format (current_gdbarch));
3367 builtin_type_long_double
3368 = build_flt (gdbarch_long_double_bit (current_gdbarch), "long double",
3369 gdbarch_long_double_format
3372 builtin_type_complex =
3373 init_type (TYPE_CODE_COMPLEX,
3374 2 * gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
3376 "complex", (struct objfile *) NULL);
3377 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3378 builtin_type_double_complex =
3379 init_type (TYPE_CODE_COMPLEX,
3380 2 * gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
3382 "double complex", (struct objfile *) NULL);
3383 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3384 builtin_type_string =
3385 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3387 "string", (struct objfile *) NULL);
3389 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3391 "bool", (struct objfile *) NULL);
3393 /* Add user knob for controlling resolution of opaque types */
3394 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
3395 &opaque_type_resolution, _("\
3396 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3397 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL,
3399 show_opaque_type_resolution,
3400 &setlist, &showlist);
3401 opaque_type_resolution = 1;
3403 /* Pointer/Address types. */
3405 /* NOTE: on some targets, addresses and pointers are not necessarily
3406 the same --- for example, on the D10V, pointers are 16 bits long,
3407 but addresses are 32 bits long. See doc/gdbint.texinfo,
3408 ``Pointers Are Not Always Addresses''.
3411 - gdb's `struct type' always describes the target's
3413 - gdb's `struct value' objects should always hold values in
3415 - gdb's CORE_ADDR values are addresses in the unified virtual
3416 address space that the assembler and linker work with. Thus,
3417 since target_read_memory takes a CORE_ADDR as an argument, it
3418 can access any memory on the target, even if the processor has
3419 separate code and data address spaces.
3422 - If v is a value holding a D10V code pointer, its contents are
3423 in target form: a big-endian address left-shifted two bits.
3424 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3425 sizeof (void *) == 2 on the target.
3427 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3428 target type for a value the target will never see. It's only
3429 used to hold the values of (typeless) linker symbols, which are
3430 indeed in the unified virtual address space. */
3431 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
3432 builtin_type_void_func_ptr
3433 = lookup_pointer_type (lookup_function_type (builtin_type_void));
3434 builtin_type_CORE_ADDR =
3435 init_type (TYPE_CODE_INT, gdbarch_addr_bit (current_gdbarch) / 8,
3437 "__CORE_ADDR", (struct objfile *) NULL);
3438 builtin_type_bfd_vma =
3439 init_type (TYPE_CODE_INT, gdbarch_addr_bit (current_gdbarch) / 8,
3441 "__bfd_vma", (struct objfile *) NULL);
3444 static struct gdbarch_data *gdbtypes_data;
3446 const struct builtin_type *
3447 builtin_type (struct gdbarch *gdbarch)
3449 return gdbarch_data (gdbarch, gdbtypes_data);
3453 static struct type *
3454 build_complex (int bit, char *name, struct type *target_type)
3457 if (bit <= 0 || target_type == builtin_type_error)
3459 gdb_assert (builtin_type_error != NULL);
3460 return builtin_type_error;
3462 t = init_type (TYPE_CODE_COMPLEX, 2 * bit / TARGET_CHAR_BIT,
3463 0, name, (struct objfile *) NULL);
3464 TYPE_TARGET_TYPE (t) = target_type;
3469 gdbtypes_post_init (struct gdbarch *gdbarch)
3471 struct builtin_type *builtin_type
3472 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
3474 builtin_type->builtin_void =
3475 init_type (TYPE_CODE_VOID, 1,
3477 "void", (struct objfile *) NULL);
3478 builtin_type->builtin_char =
3479 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3481 | (gdbarch_char_signed (current_gdbarch) ?
3482 0 : TYPE_FLAG_UNSIGNED)),
3483 "char", (struct objfile *) NULL);
3484 builtin_type->builtin_true_char =
3485 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3487 "true character", (struct objfile *) NULL);
3488 builtin_type->builtin_signed_char =
3489 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3491 "signed char", (struct objfile *) NULL);
3492 builtin_type->builtin_unsigned_char =
3493 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3495 "unsigned char", (struct objfile *) NULL);
3496 builtin_type->builtin_short =
3498 (TYPE_CODE_INT, gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
3499 0, "short", (struct objfile *) NULL);
3500 builtin_type->builtin_unsigned_short =
3502 (TYPE_CODE_INT, gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
3503 TYPE_FLAG_UNSIGNED, "unsigned short", (struct objfile *) NULL);
3504 builtin_type->builtin_int =
3506 (TYPE_CODE_INT, gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
3507 0, "int", (struct objfile *) NULL);
3508 builtin_type->builtin_unsigned_int =
3510 (TYPE_CODE_INT, gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
3511 TYPE_FLAG_UNSIGNED, "unsigned int", (struct objfile *) NULL);
3512 builtin_type->builtin_long =
3514 (TYPE_CODE_INT, gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3515 0, "long", (struct objfile *) NULL);
3516 builtin_type->builtin_unsigned_long =
3518 (TYPE_CODE_INT, gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3519 TYPE_FLAG_UNSIGNED, "unsigned long", (struct objfile *) NULL);
3520 builtin_type->builtin_long_long =
3521 init_type (TYPE_CODE_INT,
3522 gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3523 0, "long long", (struct objfile *) NULL);
3524 builtin_type->builtin_unsigned_long_long =
3525 init_type (TYPE_CODE_INT,
3526 gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3527 TYPE_FLAG_UNSIGNED, "unsigned long long",
3528 (struct objfile *) NULL);
3529 builtin_type->builtin_float
3530 = build_flt (gdbarch_float_bit (gdbarch), "float",
3531 gdbarch_float_format (gdbarch));
3532 builtin_type->builtin_double
3533 = build_flt (gdbarch_double_bit (gdbarch), "double",
3534 gdbarch_double_format (gdbarch));
3535 builtin_type->builtin_long_double
3536 = build_flt (gdbarch_long_double_bit (gdbarch), "long double",
3537 gdbarch_long_double_format (gdbarch));
3538 builtin_type->builtin_complex
3539 = build_complex (gdbarch_float_bit (gdbarch), "complex",
3540 builtin_type->builtin_float);
3541 builtin_type->builtin_double_complex
3542 = build_complex (gdbarch_double_bit (gdbarch), "double complex",
3543 builtin_type->builtin_double);
3544 builtin_type->builtin_string =
3545 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3547 "string", (struct objfile *) NULL);
3548 builtin_type->builtin_bool =
3549 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3551 "bool", (struct objfile *) NULL);
3553 /* Pointer/Address types. */
3555 /* NOTE: on some targets, addresses and pointers are not necessarily
3556 the same --- for example, on the D10V, pointers are 16 bits long,
3557 but addresses are 32 bits long. See doc/gdbint.texinfo,
3558 ``Pointers Are Not Always Addresses''.
3561 - gdb's `struct type' always describes the target's
3563 - gdb's `struct value' objects should always hold values in
3565 - gdb's CORE_ADDR values are addresses in the unified virtual
3566 address space that the assembler and linker work with. Thus,
3567 since target_read_memory takes a CORE_ADDR as an argument, it
3568 can access any memory on the target, even if the processor has
3569 separate code and data address spaces.
3572 - If v is a value holding a D10V code pointer, its contents are
3573 in target form: a big-endian address left-shifted two bits.
3574 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3575 sizeof (void *) == 2 on the target.
3577 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3578 target type for a value the target will never see. It's only
3579 used to hold the values of (typeless) linker symbols, which are
3580 indeed in the unified virtual address space. */
3581 builtin_type->builtin_data_ptr
3582 = make_pointer_type (builtin_type->builtin_void, NULL);
3583 builtin_type->builtin_func_ptr
3584 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
3585 builtin_type->builtin_core_addr =
3586 init_type (TYPE_CODE_INT, gdbarch_addr_bit (current_gdbarch) / 8,
3588 "__CORE_ADDR", (struct objfile *) NULL);
3590 return builtin_type;
3593 extern void _initialize_gdbtypes (void);
3595 _initialize_gdbtypes (void)
3597 struct cmd_list_element *c;
3599 /* FIXME: Why don't the following types need to be arch-swapped?
3600 See the comment at the top of the calls to
3601 DEPRECATED_REGISTER_GDBARCH_SWAP below. */
3603 init_type (TYPE_CODE_INT, 0 / 8,
3605 "int0_t", (struct objfile *) NULL);
3607 init_type (TYPE_CODE_INT, 8 / 8,
3609 "int8_t", (struct objfile *) NULL);
3610 builtin_type_uint8 =
3611 init_type (TYPE_CODE_INT, 8 / 8,
3613 "uint8_t", (struct objfile *) NULL);
3614 builtin_type_int16 =
3615 init_type (TYPE_CODE_INT, 16 / 8,
3617 "int16_t", (struct objfile *) NULL);
3618 builtin_type_uint16 =
3619 init_type (TYPE_CODE_INT, 16 / 8,
3621 "uint16_t", (struct objfile *) NULL);
3622 builtin_type_int32 =
3623 init_type (TYPE_CODE_INT, 32 / 8,
3625 "int32_t", (struct objfile *) NULL);
3626 builtin_type_uint32 =
3627 init_type (TYPE_CODE_INT, 32 / 8,
3629 "uint32_t", (struct objfile *) NULL);
3630 builtin_type_int64 =
3631 init_type (TYPE_CODE_INT, 64 / 8,
3633 "int64_t", (struct objfile *) NULL);
3634 builtin_type_uint64 =
3635 init_type (TYPE_CODE_INT, 64 / 8,
3637 "uint64_t", (struct objfile *) NULL);
3638 builtin_type_int128 =
3639 init_type (TYPE_CODE_INT, 128 / 8,
3641 "int128_t", (struct objfile *) NULL);
3642 builtin_type_uint128 =
3643 init_type (TYPE_CODE_INT, 128 / 8,
3645 "uint128_t", (struct objfile *) NULL);
3649 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
3651 /* FIXME - For the moment, handle types by swapping them in and out.
3652 Should be using the per-architecture data-pointer and a large
3655 Note that any type T that we might create a 'T *' type for must
3656 be arch-swapped: we cache a type's 'T *' type in the pointer_type
3657 field, so if we change architectures but don't swap T, then
3658 lookup_pointer_type will start handing out pointer types made for
3659 a different architecture. */
3660 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void);
3661 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char);
3662 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short);
3663 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int);
3664 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long);
3665 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long);
3666 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char);
3667 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char);
3668 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short);
3669 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int);
3670 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long);
3671 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long);
3672 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float);
3673 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double);
3674 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double);
3675 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex);
3676 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex);
3677 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string);
3678 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3679 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3680 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3681 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3682 deprecated_register_gdbarch_swap (NULL, 0, build_gdbtypes);
3684 /* Note: These types do not need to be swapped - they are target
3685 neutral. FIXME: Are you sure? See the comment above the calls
3686 to DEPRECATED_REGISTER_GDBARCH_SWAP above. */
3687 builtin_type_ieee_single
3688 = build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single);
3689 builtin_type_ieee_double
3690 = build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double);
3691 builtin_type_i387_ext
3692 = build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext);
3693 builtin_type_m68881_ext
3694 = build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext);
3695 builtin_type_arm_ext
3696 = build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext);
3697 builtin_type_ia64_spill
3698 = build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill);
3699 builtin_type_ia64_quad
3700 = build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad);
3702 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
3703 Set debugging of C++ overloading."), _("\
3704 Show debugging of C++ overloading."), _("\
3705 When enabled, ranking of the functions is displayed."),
3707 show_overload_debug,
3708 &setdebuglist, &showdebuglist);