1 /* Support routines for manipulating internal types for GDB.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004 Free Software Foundation, Inc.
4 Contributed by Cygnus Support, using pieces from other GDB modules.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
30 #include "expression.h"
35 #include "complaints.h"
39 #include "gdb_assert.h"
41 /* These variables point to the objects
42 representing the predefined C data types. */
44 struct type *builtin_type_void;
45 struct type *builtin_type_char;
46 struct type *builtin_type_true_char;
47 struct type *builtin_type_short;
48 struct type *builtin_type_int;
49 struct type *builtin_type_long;
50 struct type *builtin_type_long_long;
51 struct type *builtin_type_signed_char;
52 struct type *builtin_type_unsigned_char;
53 struct type *builtin_type_unsigned_short;
54 struct type *builtin_type_unsigned_int;
55 struct type *builtin_type_unsigned_long;
56 struct type *builtin_type_unsigned_long_long;
57 struct type *builtin_type_float;
58 struct type *builtin_type_double;
59 struct type *builtin_type_long_double;
60 struct type *builtin_type_complex;
61 struct type *builtin_type_double_complex;
62 struct type *builtin_type_string;
63 struct type *builtin_type_int0;
64 struct type *builtin_type_int8;
65 struct type *builtin_type_uint8;
66 struct type *builtin_type_int16;
67 struct type *builtin_type_uint16;
68 struct type *builtin_type_int32;
69 struct type *builtin_type_uint32;
70 struct type *builtin_type_int64;
71 struct type *builtin_type_uint64;
72 struct type *builtin_type_int128;
73 struct type *builtin_type_uint128;
74 struct type *builtin_type_bool;
76 /* 128 bit long vector types */
77 struct type *builtin_type_v2_double;
78 struct type *builtin_type_v4_float;
79 struct type *builtin_type_v2_int64;
80 struct type *builtin_type_v4_int32;
81 struct type *builtin_type_v8_int16;
82 struct type *builtin_type_v16_int8;
83 /* 64 bit long vector types */
84 struct type *builtin_type_v2_float;
85 struct type *builtin_type_v2_int32;
86 struct type *builtin_type_v4_int16;
87 struct type *builtin_type_v8_int8;
89 struct type *builtin_type_v4sf;
90 struct type *builtin_type_v4si;
91 struct type *builtin_type_v16qi;
92 struct type *builtin_type_v8qi;
93 struct type *builtin_type_v8hi;
94 struct type *builtin_type_v4hi;
95 struct type *builtin_type_v2si;
96 struct type *builtin_type_vec64;
97 struct type *builtin_type_vec64i;
98 struct type *builtin_type_vec128;
99 struct type *builtin_type_vec128i;
100 struct type *builtin_type_ieee_single_big;
101 struct type *builtin_type_ieee_single_little;
102 struct type *builtin_type_ieee_double_big;
103 struct type *builtin_type_ieee_double_little;
104 struct type *builtin_type_ieee_double_littlebyte_bigword;
105 struct type *builtin_type_i387_ext;
106 struct type *builtin_type_m68881_ext;
107 struct type *builtin_type_i960_ext;
108 struct type *builtin_type_m88110_ext;
109 struct type *builtin_type_m88110_harris_ext;
110 struct type *builtin_type_arm_ext_big;
111 struct type *builtin_type_arm_ext_littlebyte_bigword;
112 struct type *builtin_type_ia64_spill_big;
113 struct type *builtin_type_ia64_spill_little;
114 struct type *builtin_type_ia64_quad_big;
115 struct type *builtin_type_ia64_quad_little;
116 struct type *builtin_type_void_data_ptr;
117 struct type *builtin_type_void_func_ptr;
118 struct type *builtin_type_CORE_ADDR;
119 struct type *builtin_type_bfd_vma;
121 int opaque_type_resolution = 1;
122 int overload_debug = 0;
128 }; /* maximum extension is 128! FIXME */
130 static void print_bit_vector (B_TYPE *, int);
131 static void print_arg_types (struct field *, int, int);
132 static void dump_fn_fieldlists (struct type *, int);
133 static void print_cplus_stuff (struct type *, int);
134 static void virtual_base_list_aux (struct type *dclass);
137 /* Alloc a new type structure and fill it with some defaults. If
138 OBJFILE is non-NULL, then allocate the space for the type structure
139 in that objfile's objfile_obstack. Otherwise allocate the new type structure
140 by xmalloc () (for permanent types). */
143 alloc_type (struct objfile *objfile)
147 /* Alloc the structure and start off with all fields zeroed. */
151 type = xmalloc (sizeof (struct type));
152 memset (type, 0, sizeof (struct type));
153 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
157 type = obstack_alloc (&objfile->objfile_obstack,
158 sizeof (struct type));
159 memset (type, 0, sizeof (struct type));
160 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
161 sizeof (struct main_type));
162 OBJSTAT (objfile, n_types++);
164 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
166 /* Initialize the fields that might not be zero. */
168 TYPE_CODE (type) = TYPE_CODE_UNDEF;
169 TYPE_OBJFILE (type) = objfile;
170 TYPE_VPTR_FIELDNO (type) = -1;
171 TYPE_CHAIN (type) = type; /* Chain back to itself. */
176 /* Alloc a new type instance structure, fill it with some defaults,
177 and point it at OLDTYPE. Allocate the new type instance from the
178 same place as OLDTYPE. */
181 alloc_type_instance (struct type *oldtype)
185 /* Allocate the structure. */
187 if (TYPE_OBJFILE (oldtype) == NULL)
189 type = xmalloc (sizeof (struct type));
190 memset (type, 0, sizeof (struct type));
194 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
195 sizeof (struct type));
196 memset (type, 0, sizeof (struct type));
198 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
200 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
205 /* Clear all remnants of the previous type at TYPE, in preparation for
206 replacing it with something else. */
208 smash_type (struct type *type)
210 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
212 /* For now, delete the rings. */
213 TYPE_CHAIN (type) = type;
215 /* For now, leave the pointer/reference types alone. */
218 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
219 to a pointer to memory where the pointer type should be stored.
220 If *TYPEPTR is zero, update it to point to the pointer type we return.
221 We allocate new memory if needed. */
224 make_pointer_type (struct type *type, struct type **typeptr)
226 struct type *ntype; /* New type */
227 struct objfile *objfile;
229 ntype = TYPE_POINTER_TYPE (type);
234 return ntype; /* Don't care about alloc, and have new type. */
235 else if (*typeptr == 0)
237 *typeptr = ntype; /* Tracking alloc, and we have new type. */
242 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
244 ntype = alloc_type (TYPE_OBJFILE (type));
249 /* We have storage, but need to reset it. */
252 objfile = TYPE_OBJFILE (ntype);
254 TYPE_OBJFILE (ntype) = objfile;
257 TYPE_TARGET_TYPE (ntype) = type;
258 TYPE_POINTER_TYPE (type) = ntype;
260 /* FIXME! Assume the machine has only one representation for pointers! */
262 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
263 TYPE_CODE (ntype) = TYPE_CODE_PTR;
265 /* Mark pointers as unsigned. The target converts between pointers
266 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
267 ADDRESS_TO_POINTER(). */
268 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
270 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
271 TYPE_POINTER_TYPE (type) = ntype;
276 /* Given a type TYPE, return a type of pointers to that type.
277 May need to construct such a type if this is the first use. */
280 lookup_pointer_type (struct type *type)
282 return make_pointer_type (type, (struct type **) 0);
285 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
286 to a pointer to memory where the reference type should be stored.
287 If *TYPEPTR is zero, update it to point to the reference type we return.
288 We allocate new memory if needed. */
291 make_reference_type (struct type *type, struct type **typeptr)
293 struct type *ntype; /* New type */
294 struct objfile *objfile;
296 ntype = TYPE_REFERENCE_TYPE (type);
301 return ntype; /* Don't care about alloc, and have new type. */
302 else if (*typeptr == 0)
304 *typeptr = ntype; /* Tracking alloc, and we have new type. */
309 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
311 ntype = alloc_type (TYPE_OBJFILE (type));
316 /* We have storage, but need to reset it. */
319 objfile = TYPE_OBJFILE (ntype);
321 TYPE_OBJFILE (ntype) = objfile;
324 TYPE_TARGET_TYPE (ntype) = type;
325 TYPE_REFERENCE_TYPE (type) = ntype;
327 /* FIXME! Assume the machine has only one representation for references,
328 and that it matches the (only) representation for pointers! */
330 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
331 TYPE_CODE (ntype) = TYPE_CODE_REF;
333 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
334 TYPE_REFERENCE_TYPE (type) = ntype;
339 /* Same as above, but caller doesn't care about memory allocation details. */
342 lookup_reference_type (struct type *type)
344 return make_reference_type (type, (struct type **) 0);
347 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
348 to a pointer to memory where the function type should be stored.
349 If *TYPEPTR is zero, update it to point to the function type we return.
350 We allocate new memory if needed. */
353 make_function_type (struct type *type, struct type **typeptr)
355 struct type *ntype; /* New type */
356 struct objfile *objfile;
358 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
360 ntype = alloc_type (TYPE_OBJFILE (type));
365 /* We have storage, but need to reset it. */
368 objfile = TYPE_OBJFILE (ntype);
370 TYPE_OBJFILE (ntype) = objfile;
373 TYPE_TARGET_TYPE (ntype) = type;
375 TYPE_LENGTH (ntype) = 1;
376 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
382 /* Given a type TYPE, return a type of functions that return that type.
383 May need to construct such a type if this is the first use. */
386 lookup_function_type (struct type *type)
388 return make_function_type (type, (struct type **) 0);
391 /* Identify address space identifier by name --
392 return the integer flag defined in gdbtypes.h. */
394 address_space_name_to_int (char *space_identifier)
396 struct gdbarch *gdbarch = current_gdbarch;
398 /* Check for known address space delimiters. */
399 if (!strcmp (space_identifier, "code"))
400 return TYPE_FLAG_CODE_SPACE;
401 else if (!strcmp (space_identifier, "data"))
402 return TYPE_FLAG_DATA_SPACE;
403 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
404 && gdbarch_address_class_name_to_type_flags (gdbarch,
409 error ("Unknown address space specifier: \"%s\"", space_identifier);
412 /* Identify address space identifier by integer flag as defined in
413 gdbtypes.h -- return the string version of the adress space name. */
416 address_space_int_to_name (int space_flag)
418 struct gdbarch *gdbarch = current_gdbarch;
419 if (space_flag & TYPE_FLAG_CODE_SPACE)
421 else if (space_flag & TYPE_FLAG_DATA_SPACE)
423 else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL)
424 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
425 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
430 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
431 If STORAGE is non-NULL, create the new type instance there. */
434 make_qualified_type (struct type *type, int new_flags,
435 struct type *storage)
441 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
443 ntype = TYPE_CHAIN (ntype);
444 } while (ntype != type);
446 /* Create a new type instance. */
448 ntype = alloc_type_instance (type);
452 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
453 TYPE_CHAIN (ntype) = ntype;
456 /* Pointers or references to the original type are not relevant to
458 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
459 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
461 /* Chain the new qualified type to the old type. */
462 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
463 TYPE_CHAIN (type) = ntype;
465 /* Now set the instance flags and return the new type. */
466 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
468 /* Set length of new type to that of the original type. */
469 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
474 /* Make an address-space-delimited variant of a type -- a type that
475 is identical to the one supplied except that it has an address
476 space attribute attached to it (such as "code" or "data").
478 The space attributes "code" and "data" are for Harvard architectures.
479 The address space attributes are for architectures which have
480 alternately sized pointers or pointers with alternate representations. */
483 make_type_with_address_space (struct type *type, int space_flag)
486 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
487 & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE
488 | TYPE_FLAG_ADDRESS_CLASS_ALL))
491 return make_qualified_type (type, new_flags, NULL);
494 /* Make a "c-v" variant of a type -- a type that is identical to the
495 one supplied except that it may have const or volatile attributes
496 CNST is a flag for setting the const attribute
497 VOLTL is a flag for setting the volatile attribute
498 TYPE is the base type whose variant we are creating.
499 TYPEPTR, if nonzero, points
500 to a pointer to memory where the reference type should be stored.
501 If *TYPEPTR is zero, update it to point to the reference type we return.
502 We allocate new memory if needed. */
505 make_cvr_type (int cnst, int voltl, int restrct, struct type *type,
506 struct type **typeptr)
508 struct type *ntype; /* New type */
509 struct type *tmp_type = type; /* tmp type */
510 struct objfile *objfile;
512 int new_flags = (TYPE_INSTANCE_FLAGS (type)
513 & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
516 new_flags |= TYPE_FLAG_CONST;
519 new_flags |= TYPE_FLAG_VOLATILE;
522 new_flags |= TYPE_FLAG_RESTRICT;
524 if (typeptr && *typeptr != NULL)
526 /* Objfile is per-core-type. This const-qualified type had best
527 belong to the same objfile as the type it is qualifying, unless
528 we are overwriting a stub type, in which case the safest thing
529 to do is to copy the core type into the new objfile. */
531 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)
532 || TYPE_STUB (*typeptr));
533 if (TYPE_OBJFILE (*typeptr) != TYPE_OBJFILE (type))
535 TYPE_MAIN_TYPE (*typeptr)
536 = TYPE_ALLOC (*typeptr, sizeof (struct main_type));
537 *TYPE_MAIN_TYPE (*typeptr)
538 = *TYPE_MAIN_TYPE (type);
542 ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
550 /* Replace the contents of ntype with the type *type. This changes the
551 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
552 the changes are propogated to all types in the TYPE_CHAIN.
554 In order to build recursive types, it's inevitable that we'll need
555 to update types in place --- but this sort of indiscriminate
556 smashing is ugly, and needs to be replaced with something more
557 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
558 clear if more steps are needed. */
560 replace_type (struct type *ntype, struct type *type)
564 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
566 /* The type length is not a part of the main type. Update it for each
567 type on the variant chain. */
570 /* Assert that this element of the chain has no address-class bits
571 set in its flags. Such type variants might have type lengths
572 which are supposed to be different from the non-address-class
573 variants. This assertion shouldn't ever be triggered because
574 symbol readers which do construct address-class variants don't
575 call replace_type(). */
576 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
578 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
579 chain = TYPE_CHAIN (chain);
580 } while (ntype != chain);
582 /* Assert that the two types have equivalent instance qualifiers.
583 This should be true for at least all of our debug readers. */
584 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
587 /* Implement direct support for MEMBER_TYPE in GNU C++.
588 May need to construct such a type if this is the first use.
589 The TYPE is the type of the member. The DOMAIN is the type
590 of the aggregate that the member belongs to. */
593 lookup_member_type (struct type *type, struct type *domain)
597 mtype = alloc_type (TYPE_OBJFILE (type));
598 smash_to_member_type (mtype, domain, type);
602 /* Allocate a stub method whose return type is TYPE.
603 This apparently happens for speed of symbol reading, since parsing
604 out the arguments to the method is cpu-intensive, the way we are doing
605 it. So, we will fill in arguments later.
606 This always returns a fresh type. */
609 allocate_stub_method (struct type *type)
613 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
614 TYPE_OBJFILE (type));
615 TYPE_TARGET_TYPE (mtype) = type;
616 /* _DOMAIN_TYPE (mtype) = unknown yet */
620 /* Create a range type using either a blank type supplied in RESULT_TYPE,
621 or creating a new type, inheriting the objfile from INDEX_TYPE.
623 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
624 HIGH_BOUND, inclusive.
626 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
627 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
630 create_range_type (struct type *result_type, struct type *index_type,
631 int low_bound, int high_bound)
633 if (result_type == NULL)
635 result_type = alloc_type (TYPE_OBJFILE (index_type));
637 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
638 TYPE_TARGET_TYPE (result_type) = index_type;
639 if (TYPE_STUB (index_type))
640 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
642 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
643 TYPE_NFIELDS (result_type) = 2;
644 TYPE_FIELDS (result_type) = (struct field *)
645 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
646 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
647 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
648 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
649 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
650 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
653 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
655 return (result_type);
658 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
659 Return 1 of type is a range type, 0 if it is discrete (and bounds
660 will fit in LONGEST), or -1 otherwise. */
663 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
665 CHECK_TYPEDEF (type);
666 switch (TYPE_CODE (type))
668 case TYPE_CODE_RANGE:
669 *lowp = TYPE_LOW_BOUND (type);
670 *highp = TYPE_HIGH_BOUND (type);
673 if (TYPE_NFIELDS (type) > 0)
675 /* The enums may not be sorted by value, so search all
679 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
680 for (i = 0; i < TYPE_NFIELDS (type); i++)
682 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
683 *lowp = TYPE_FIELD_BITPOS (type, i);
684 if (TYPE_FIELD_BITPOS (type, i) > *highp)
685 *highp = TYPE_FIELD_BITPOS (type, i);
688 /* Set unsigned indicator if warranted. */
691 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
705 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
707 if (!TYPE_UNSIGNED (type))
709 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
713 /* ... fall through for unsigned ints ... */
716 /* This round-about calculation is to avoid shifting by
717 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
718 if TYPE_LENGTH (type) == sizeof (LONGEST). */
719 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
720 *highp = (*highp - 1) | *highp;
727 /* Create an array type using either a blank type supplied in RESULT_TYPE,
728 or creating a new type, inheriting the objfile from RANGE_TYPE.
730 Elements will be of type ELEMENT_TYPE, the indices will be of type
733 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
734 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
737 create_array_type (struct type *result_type, struct type *element_type,
738 struct type *range_type)
740 LONGEST low_bound, high_bound;
742 if (result_type == NULL)
744 result_type = alloc_type (TYPE_OBJFILE (range_type));
746 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
747 TYPE_TARGET_TYPE (result_type) = element_type;
748 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
749 low_bound = high_bound = 0;
750 CHECK_TYPEDEF (element_type);
751 TYPE_LENGTH (result_type) =
752 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
753 TYPE_NFIELDS (result_type) = 1;
754 TYPE_FIELDS (result_type) =
755 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
756 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
757 TYPE_FIELD_TYPE (result_type, 0) = range_type;
758 TYPE_VPTR_FIELDNO (result_type) = -1;
760 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
761 if (TYPE_LENGTH (result_type) == 0)
762 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
764 return (result_type);
767 /* Create a string type using either a blank type supplied in RESULT_TYPE,
768 or creating a new type. String types are similar enough to array of
769 char types that we can use create_array_type to build the basic type
770 and then bash it into a string type.
772 For fixed length strings, the range type contains 0 as the lower
773 bound and the length of the string minus one as the upper bound.
775 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
776 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
779 create_string_type (struct type *result_type, struct type *range_type)
781 result_type = create_array_type (result_type,
782 *current_language->string_char_type,
784 TYPE_CODE (result_type) = TYPE_CODE_STRING;
785 return (result_type);
789 create_set_type (struct type *result_type, struct type *domain_type)
791 LONGEST low_bound, high_bound, bit_length;
792 if (result_type == NULL)
794 result_type = alloc_type (TYPE_OBJFILE (domain_type));
796 TYPE_CODE (result_type) = TYPE_CODE_SET;
797 TYPE_NFIELDS (result_type) = 1;
798 TYPE_FIELDS (result_type) = (struct field *)
799 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
800 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
802 if (!TYPE_STUB (domain_type))
804 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
805 low_bound = high_bound = 0;
806 bit_length = high_bound - low_bound + 1;
807 TYPE_LENGTH (result_type)
808 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
810 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
813 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
815 return (result_type);
818 /* Construct and return a type of the form:
819 struct NAME { ELT_TYPE ELT_NAME[N]; }
820 We use these types for SIMD registers. For example, the type of
821 the SSE registers on the late x86-family processors is:
822 struct __builtin_v4sf { float f[4]; }
823 built by the function call:
824 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
825 The type returned is a permanent type, allocated using malloc; it
826 doesn't live in any objfile's obstack. */
828 init_simd_type (char *name,
829 struct type *elt_type,
833 struct type *simd_type;
834 struct type *array_type;
836 simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
837 array_type = create_array_type (0, elt_type,
838 create_range_type (0, builtin_type_int,
840 append_composite_type_field (simd_type, elt_name, array_type);
845 init_vector_type (struct type *elt_type, int n)
847 struct type *array_type;
849 array_type = create_array_type (0, elt_type,
850 create_range_type (0, builtin_type_int,
852 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
857 build_builtin_type_vec64 (void)
859 /* Construct a type for the 64 bit registers. The type we're
862 union __gdb_builtin_type_vec64
874 t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION);
875 append_composite_type_field (t, "uint64", builtin_type_int64);
876 append_composite_type_field (t, "v2_float", builtin_type_v2_float);
877 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
878 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
879 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
881 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
882 TYPE_NAME (t) = "builtin_type_vec64";
887 build_builtin_type_vec64i (void)
889 /* Construct a type for the 64 bit registers. The type we're
892 union __gdb_builtin_type_vec64i
903 t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
904 append_composite_type_field (t, "uint64", builtin_type_int64);
905 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
906 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
907 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
909 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
910 TYPE_NAME (t) = "builtin_type_vec64i";
915 build_builtin_type_vec128 (void)
917 /* Construct a type for the 128 bit registers. The type we're
920 union __gdb_builtin_type_vec128
932 t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
933 append_composite_type_field (t, "uint128", builtin_type_int128);
934 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
935 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
936 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
937 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
939 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
940 TYPE_NAME (t) = "builtin_type_vec128";
945 build_builtin_type_vec128i (void)
947 /* 128-bit Intel SIMD registers */
950 t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
951 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
952 append_composite_type_field (t, "v2_double", builtin_type_v2_double);
953 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
954 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
955 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
956 append_composite_type_field (t, "v2_int64", builtin_type_v2_int64);
957 append_composite_type_field (t, "uint128", builtin_type_int128);
959 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
960 TYPE_NAME (t) = "builtin_type_vec128i";
964 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
965 A MEMBER is a wierd thing -- it amounts to a typed offset into
966 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
967 include the offset (that's the value of the MEMBER itself), but does
968 include the structure type into which it points (for some reason).
970 When "smashing" the type, we preserve the objfile that the
971 old type pointed to, since we aren't changing where the type is actually
975 smash_to_member_type (struct type *type, struct type *domain,
976 struct type *to_type)
978 struct objfile *objfile;
980 objfile = TYPE_OBJFILE (type);
983 TYPE_OBJFILE (type) = objfile;
984 TYPE_TARGET_TYPE (type) = to_type;
985 TYPE_DOMAIN_TYPE (type) = domain;
986 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
987 TYPE_CODE (type) = TYPE_CODE_MEMBER;
990 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
991 METHOD just means `function that gets an extra "this" argument'.
993 When "smashing" the type, we preserve the objfile that the
994 old type pointed to, since we aren't changing where the type is actually
998 smash_to_method_type (struct type *type, struct type *domain,
999 struct type *to_type, struct field *args,
1000 int nargs, int varargs)
1002 struct objfile *objfile;
1004 objfile = TYPE_OBJFILE (type);
1007 TYPE_OBJFILE (type) = objfile;
1008 TYPE_TARGET_TYPE (type) = to_type;
1009 TYPE_DOMAIN_TYPE (type) = domain;
1010 TYPE_FIELDS (type) = args;
1011 TYPE_NFIELDS (type) = nargs;
1013 TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
1014 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1015 TYPE_CODE (type) = TYPE_CODE_METHOD;
1018 /* Return a typename for a struct/union/enum type without "struct ",
1019 "union ", or "enum ". If the type has a NULL name, return NULL. */
1022 type_name_no_tag (const struct type *type)
1024 if (TYPE_TAG_NAME (type) != NULL)
1025 return TYPE_TAG_NAME (type);
1027 /* Is there code which expects this to return the name if there is no
1028 tag name? My guess is that this is mainly used for C++ in cases where
1029 the two will always be the same. */
1030 return TYPE_NAME (type);
1033 /* Lookup a primitive type named NAME.
1034 Return zero if NAME is not a primitive type. */
1037 lookup_primitive_typename (char *name)
1039 struct type **const *p;
1041 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
1043 if (strcmp (TYPE_NAME (**p), name) == 0)
1051 /* Lookup a typedef or primitive type named NAME,
1052 visible in lexical block BLOCK.
1053 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1056 lookup_typename (char *name, struct block *block, int noerr)
1061 sym = lookup_symbol (name, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
1062 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1064 tmp = lookup_primitive_typename (name);
1069 else if (!tmp && noerr)
1075 error ("No type named %s.", name);
1078 return (SYMBOL_TYPE (sym));
1082 lookup_unsigned_typename (char *name)
1084 char *uns = alloca (strlen (name) + 10);
1086 strcpy (uns, "unsigned ");
1087 strcpy (uns + 9, name);
1088 return (lookup_typename (uns, (struct block *) NULL, 0));
1092 lookup_signed_typename (char *name)
1095 char *uns = alloca (strlen (name) + 8);
1097 strcpy (uns, "signed ");
1098 strcpy (uns + 7, name);
1099 t = lookup_typename (uns, (struct block *) NULL, 1);
1100 /* If we don't find "signed FOO" just try again with plain "FOO". */
1103 return lookup_typename (name, (struct block *) NULL, 0);
1106 /* Lookup a structure type named "struct NAME",
1107 visible in lexical block BLOCK. */
1110 lookup_struct (char *name, struct block *block)
1114 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1115 (struct symtab **) NULL);
1119 error ("No struct type named %s.", name);
1121 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1123 error ("This context has class, union or enum %s, not a struct.", name);
1125 return (SYMBOL_TYPE (sym));
1128 /* Lookup a union type named "union NAME",
1129 visible in lexical block BLOCK. */
1132 lookup_union (char *name, struct block *block)
1137 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1138 (struct symtab **) NULL);
1141 error ("No union type named %s.", name);
1143 t = SYMBOL_TYPE (sym);
1145 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1148 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1149 * a further "declared_type" field to discover it is really a union.
1151 if (HAVE_CPLUS_STRUCT (t))
1152 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1155 /* If we get here, it's not a union */
1156 error ("This context has class, struct or enum %s, not a union.", name);
1160 /* Lookup an enum type named "enum NAME",
1161 visible in lexical block BLOCK. */
1164 lookup_enum (char *name, struct block *block)
1168 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1169 (struct symtab **) NULL);
1172 error ("No enum type named %s.", name);
1174 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1176 error ("This context has class, struct or union %s, not an enum.", name);
1178 return (SYMBOL_TYPE (sym));
1181 /* Lookup a template type named "template NAME<TYPE>",
1182 visible in lexical block BLOCK. */
1185 lookup_template_type (char *name, struct type *type, struct block *block)
1188 char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1191 strcat (nam, TYPE_NAME (type));
1192 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1194 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
1198 error ("No template type named %s.", name);
1200 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1202 error ("This context has class, union or enum %s, not a struct.", name);
1204 return (SYMBOL_TYPE (sym));
1207 /* Given a type TYPE, lookup the type of the component of type named NAME.
1209 TYPE can be either a struct or union, or a pointer or reference to a struct or
1210 union. If it is a pointer or reference, its target type is automatically used.
1211 Thus '.' and '->' are interchangable, as specified for the definitions of the
1212 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1214 If NOERR is nonzero, return zero if NAME is not suitably defined.
1215 If NAME is the name of a baseclass type, return that type. */
1218 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1224 CHECK_TYPEDEF (type);
1225 if (TYPE_CODE (type) != TYPE_CODE_PTR
1226 && TYPE_CODE (type) != TYPE_CODE_REF)
1228 type = TYPE_TARGET_TYPE (type);
1231 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1232 TYPE_CODE (type) != TYPE_CODE_UNION)
1234 target_terminal_ours ();
1235 gdb_flush (gdb_stdout);
1236 fprintf_unfiltered (gdb_stderr, "Type ");
1237 type_print (type, "", gdb_stderr, -1);
1238 error (" is not a structure or union type.");
1242 /* FIXME: This change put in by Michael seems incorrect for the case where
1243 the structure tag name is the same as the member name. I.E. when doing
1244 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1249 typename = type_name_no_tag (type);
1250 if (typename != NULL && strcmp (typename, name) == 0)
1255 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1257 char *t_field_name = TYPE_FIELD_NAME (type, i);
1259 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1261 return TYPE_FIELD_TYPE (type, i);
1265 /* OK, it's not in this class. Recursively check the baseclasses. */
1266 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1270 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1282 target_terminal_ours ();
1283 gdb_flush (gdb_stdout);
1284 fprintf_unfiltered (gdb_stderr, "Type ");
1285 type_print (type, "", gdb_stderr, -1);
1286 fprintf_unfiltered (gdb_stderr, " has no component named ");
1287 fputs_filtered (name, gdb_stderr);
1289 return (struct type *) -1; /* For lint */
1292 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1293 valid. Callers should be aware that in some cases (for example,
1294 the type or one of its baseclasses is a stub type and we are
1295 debugging a .o file), this function will not be able to find the virtual
1296 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1297 will remain NULL. */
1300 fill_in_vptr_fieldno (struct type *type)
1302 CHECK_TYPEDEF (type);
1304 if (TYPE_VPTR_FIELDNO (type) < 0)
1308 /* We must start at zero in case the first (and only) baseclass is
1309 virtual (and hence we cannot share the table pointer). */
1310 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1312 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1313 fill_in_vptr_fieldno (baseclass);
1314 if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
1316 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
1317 TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
1324 /* Find the method and field indices for the destructor in class type T.
1325 Return 1 if the destructor was found, otherwise, return 0. */
1328 get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
1332 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1335 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1337 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1339 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1351 stub_noname_complaint (void)
1353 complaint (&symfile_complaints, "stub type has NULL name");
1356 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1358 If this is a stubbed struct (i.e. declared as struct foo *), see if
1359 we can find a full definition in some other file. If so, copy this
1360 definition, so we can use it in future. There used to be a comment (but
1361 not any code) that if we don't find a full definition, we'd set a flag
1362 so we don't spend time in the future checking the same type. That would
1363 be a mistake, though--we might load in more symbols which contain a
1364 full definition for the type.
1366 This used to be coded as a macro, but I don't think it is called
1367 often enough to merit such treatment. */
1369 /* Find the real type of TYPE. This function returns the real type, after
1370 removing all layers of typedefs and completing opaque or stub types.
1371 Completion changes the TYPE argument, but stripping of typedefs does
1375 check_typedef (struct type *type)
1377 struct type *orig_type = type;
1378 int is_const, is_volatile, is_restrict;
1380 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1382 if (!TYPE_TARGET_TYPE (type))
1387 /* It is dangerous to call lookup_symbol if we are currently
1388 reading a symtab. Infinite recursion is one danger. */
1389 if (currently_reading_symtab)
1392 name = type_name_no_tag (type);
1393 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1394 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1395 as appropriate? (this code was written before TYPE_NAME and
1396 TYPE_TAG_NAME were separate). */
1399 stub_noname_complaint ();
1402 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
1403 (struct symtab **) NULL);
1405 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1407 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1409 type = TYPE_TARGET_TYPE (type);
1412 is_const = TYPE_CONST (type);
1413 is_volatile = TYPE_VOLATILE (type);
1414 is_restrict = TYPE_RESTRICT (type);
1416 /* If this is a struct/class/union with no fields, then check whether a
1417 full definition exists somewhere else. This is for systems where a
1418 type definition with no fields is issued for such types, instead of
1419 identifying them as stub types in the first place */
1421 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1423 char *name = type_name_no_tag (type);
1424 struct type *newtype;
1427 stub_noname_complaint ();
1430 newtype = lookup_transparent_type (name);
1432 make_cvr_type (is_const, is_volatile, is_restrict, newtype, &type);
1434 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1435 else if (TYPE_STUB (type) && !currently_reading_symtab)
1437 char *name = type_name_no_tag (type);
1438 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1439 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1440 as appropriate? (this code was written before TYPE_NAME and
1441 TYPE_TAG_NAME were separate). */
1445 stub_noname_complaint ();
1448 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL);
1450 make_cvr_type (is_const, is_volatile, is_restrict, SYMBOL_TYPE (sym),
1454 if (TYPE_TARGET_STUB (type))
1456 struct type *range_type;
1457 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1459 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1462 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1463 && TYPE_NFIELDS (type) == 1
1464 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1465 == TYPE_CODE_RANGE))
1467 /* Now recompute the length of the array type, based on its
1468 number of elements and the target type's length. */
1469 TYPE_LENGTH (type) =
1470 ((TYPE_FIELD_BITPOS (range_type, 1)
1471 - TYPE_FIELD_BITPOS (range_type, 0)
1473 * TYPE_LENGTH (target_type));
1474 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1476 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1478 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1479 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1482 /* Cache TYPE_LENGTH for future use. */
1483 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1487 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1488 silently return builtin_type_void. */
1490 static struct type *
1491 safe_parse_type (char *p, int length)
1493 struct ui_file *saved_gdb_stderr;
1496 /* Suppress error messages. */
1497 saved_gdb_stderr = gdb_stderr;
1498 gdb_stderr = ui_file_new ();
1500 /* Call parse_and_eval_type() without fear of longjmp()s. */
1501 if (!gdb_parse_and_eval_type (p, length, &type))
1502 type = builtin_type_void;
1504 /* Stop suppressing error messages. */
1505 ui_file_delete (gdb_stderr);
1506 gdb_stderr = saved_gdb_stderr;
1511 /* Ugly hack to convert method stubs into method types.
1513 He ain't kiddin'. This demangles the name of the method into a string
1514 including argument types, parses out each argument type, generates
1515 a string casting a zero to that type, evaluates the string, and stuffs
1516 the resulting type into an argtype vector!!! Then it knows the type
1517 of the whole function (including argument types for overloading),
1518 which info used to be in the stab's but was removed to hack back
1519 the space required for them. */
1522 check_stub_method (struct type *type, int method_id, int signature_id)
1525 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1526 char *demangled_name = cplus_demangle (mangled_name,
1527 DMGL_PARAMS | DMGL_ANSI);
1528 char *argtypetext, *p;
1529 int depth = 0, argcount = 1;
1530 struct field *argtypes;
1533 /* Make sure we got back a function string that we can use. */
1535 p = strchr (demangled_name, '(');
1539 if (demangled_name == NULL || p == NULL)
1540 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1542 /* Now, read in the parameters that define this type. */
1547 if (*p == '(' || *p == '<')
1551 else if (*p == ')' || *p == '>')
1555 else if (*p == ',' && depth == 0)
1563 /* If we read one argument and it was ``void'', don't count it. */
1564 if (strncmp (argtypetext, "(void)", 6) == 0)
1567 /* We need one extra slot, for the THIS pointer. */
1569 argtypes = (struct field *)
1570 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1573 /* Add THIS pointer for non-static methods. */
1574 f = TYPE_FN_FIELDLIST1 (type, method_id);
1575 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1579 argtypes[0].type = lookup_pointer_type (type);
1583 if (*p != ')') /* () means no args, skip while */
1588 if (depth <= 0 && (*p == ',' || *p == ')'))
1590 /* Avoid parsing of ellipsis, they will be handled below.
1591 Also avoid ``void'' as above. */
1592 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1593 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1595 argtypes[argcount].type =
1596 safe_parse_type (argtypetext, p - argtypetext);
1599 argtypetext = p + 1;
1602 if (*p == '(' || *p == '<')
1606 else if (*p == ')' || *p == '>')
1615 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1617 /* Now update the old "stub" type into a real type. */
1618 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1619 TYPE_DOMAIN_TYPE (mtype) = type;
1620 TYPE_FIELDS (mtype) = argtypes;
1621 TYPE_NFIELDS (mtype) = argcount;
1622 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1623 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1625 TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1627 xfree (demangled_name);
1630 /* This is the external interface to check_stub_method, above. This function
1631 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1632 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1633 and TYPE_FN_FIELDLIST_NAME will be correct.
1635 This function unfortunately can not die until stabs do. */
1638 check_stub_method_group (struct type *type, int method_id)
1640 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1641 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1642 int j, found_stub = 0;
1644 for (j = 0; j < len; j++)
1645 if (TYPE_FN_FIELD_STUB (f, j))
1648 check_stub_method (type, method_id, j);
1651 /* GNU v3 methods with incorrect names were corrected when we read in
1652 type information, because it was cheaper to do it then. The only GNU v2
1653 methods with incorrect method names are operators and destructors;
1654 destructors were also corrected when we read in type information.
1656 Therefore the only thing we need to handle here are v2 operator
1658 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1661 char dem_opname[256];
1663 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1664 dem_opname, DMGL_ANSI);
1666 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1669 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1673 const struct cplus_struct_type cplus_struct_default;
1676 allocate_cplus_struct_type (struct type *type)
1678 if (!HAVE_CPLUS_STRUCT (type))
1680 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1681 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1682 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1686 /* Helper function to initialize the standard scalar types.
1688 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1689 of the string pointed to by name in the objfile_obstack for that objfile,
1690 and initialize the type name to that copy. There are places (mipsread.c
1691 in particular, where init_type is called with a NULL value for NAME). */
1694 init_type (enum type_code code, int length, int flags, char *name,
1695 struct objfile *objfile)
1699 type = alloc_type (objfile);
1700 TYPE_CODE (type) = code;
1701 TYPE_LENGTH (type) = length;
1702 TYPE_FLAGS (type) |= flags;
1703 if ((name != NULL) && (objfile != NULL))
1706 obsavestring (name, strlen (name), &objfile->objfile_obstack);
1710 TYPE_NAME (type) = name;
1715 if (name && strcmp (name, "char") == 0)
1716 TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
1718 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1719 || code == TYPE_CODE_NAMESPACE)
1721 INIT_CPLUS_SPECIFIC (type);
1726 /* Helper function. Create an empty composite type. */
1729 init_composite_type (char *name, enum type_code code)
1732 gdb_assert (code == TYPE_CODE_STRUCT
1733 || code == TYPE_CODE_UNION);
1734 t = init_type (code, 0, 0, NULL, NULL);
1735 TYPE_TAG_NAME (t) = name;
1739 /* Helper function. Append a field to a composite type. */
1742 append_composite_type_field (struct type *t, char *name, struct type *field)
1745 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1746 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1747 sizeof (struct field) * TYPE_NFIELDS (t));
1748 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1749 memset (f, 0, sizeof f[0]);
1750 FIELD_TYPE (f[0]) = field;
1751 FIELD_NAME (f[0]) = name;
1752 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1754 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1755 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1757 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1759 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1760 if (TYPE_NFIELDS (t) > 1)
1762 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1763 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1768 /* Look up a fundamental type for the specified objfile.
1769 May need to construct such a type if this is the first use.
1771 Some object file formats (ELF, COFF, etc) do not define fundamental
1772 types such as "int" or "double". Others (stabs for example), do
1773 define fundamental types.
1775 For the formats which don't provide fundamental types, gdb can create
1776 such types, using defaults reasonable for the current language and
1777 the current target machine.
1779 NOTE: This routine is obsolescent. Each debugging format reader
1780 should manage it's own fundamental types, either creating them from
1781 suitable defaults or reading them from the debugging information,
1782 whichever is appropriate. The DWARF reader has already been
1783 fixed to do this. Once the other readers are fixed, this routine
1784 will go away. Also note that fundamental types should be managed
1785 on a compilation unit basis in a multi-language environment, not
1786 on a linkage unit basis as is done here. */
1790 lookup_fundamental_type (struct objfile *objfile, int typeid)
1792 struct type **typep;
1795 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1797 error ("internal error - invalid fundamental type id %d", typeid);
1800 /* If this is the first time we need a fundamental type for this objfile
1801 then we need to initialize the vector of type pointers. */
1803 if (objfile->fundamental_types == NULL)
1805 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1806 objfile->fundamental_types = (struct type **)
1807 obstack_alloc (&objfile->objfile_obstack, nbytes);
1808 memset ((char *) objfile->fundamental_types, 0, nbytes);
1809 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1812 /* Look for this particular type in the fundamental type vector. If one is
1813 not found, create and install one appropriate for the current language. */
1815 typep = objfile->fundamental_types + typeid;
1818 *typep = create_fundamental_type (objfile, typeid);
1825 can_dereference (struct type *t)
1827 /* FIXME: Should we return true for references as well as pointers? */
1831 && TYPE_CODE (t) == TYPE_CODE_PTR
1832 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1836 is_integral_type (struct type *t)
1841 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1842 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1843 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1844 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1845 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1848 /* Check whether BASE is an ancestor or base class or DCLASS
1849 Return 1 if so, and 0 if not.
1850 Note: callers may want to check for identity of the types before
1851 calling this function -- identical types are considered to satisfy
1852 the ancestor relationship even if they're identical */
1855 is_ancestor (struct type *base, struct type *dclass)
1859 CHECK_TYPEDEF (base);
1860 CHECK_TYPEDEF (dclass);
1864 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
1865 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1868 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1869 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1877 /* See whether DCLASS has a virtual table. This routine is aimed at
1878 the HP/Taligent ANSI C++ runtime model, and may not work with other
1879 runtime models. Return 1 => Yes, 0 => No. */
1882 has_vtable (struct type *dclass)
1884 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1885 has virtual functions or virtual bases. */
1889 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1892 /* First check for the presence of virtual bases */
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))
1898 /* Next check for virtual functions */
1899 if (TYPE_FN_FIELDLISTS (dclass))
1900 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1901 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1904 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1905 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1906 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1907 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1908 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1911 /* Well, maybe we don't need a virtual table */
1915 /* Return a pointer to the "primary base class" of DCLASS.
1917 A NULL return indicates that DCLASS has no primary base, or that it
1918 couldn't be found (insufficient information).
1920 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1921 and may not work with other runtime models. */
1924 primary_base_class (struct type *dclass)
1926 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1927 is the first directly inherited, non-virtual base class that
1928 requires a virtual table */
1932 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1935 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1936 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1937 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1938 return TYPE_FIELD_TYPE (dclass, i);
1943 /* Global manipulated by virtual_base_list[_aux]() */
1945 static struct vbase *current_vbase_list = NULL;
1947 /* Return a pointer to a null-terminated list of struct vbase
1948 items. The vbasetype pointer of each item in the list points to the
1949 type information for a virtual base of the argument DCLASS.
1951 Helper function for virtual_base_list().
1952 Note: the list goes backward, right-to-left. virtual_base_list()
1953 copies the items out in reverse order. */
1956 virtual_base_list_aux (struct type *dclass)
1958 struct vbase *tmp_vbase;
1961 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1964 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1966 /* Recurse on this ancestor, first */
1967 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
1969 /* If this current base is itself virtual, add it to the list */
1970 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1972 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1974 /* Check if base already recorded */
1975 tmp_vbase = current_vbase_list;
1978 if (tmp_vbase->vbasetype == basetype)
1979 break; /* found it */
1980 tmp_vbase = tmp_vbase->next;
1983 if (!tmp_vbase) /* normal exit from loop */
1985 /* Allocate new item for this virtual base */
1986 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
1988 /* Stick it on at the end of the list */
1989 tmp_vbase->vbasetype = basetype;
1990 tmp_vbase->next = current_vbase_list;
1991 current_vbase_list = tmp_vbase;
1994 } /* for loop over bases */
1998 /* Compute the list of virtual bases in the right order. Virtual
1999 bases are laid out in the object's memory area in order of their
2000 occurrence in a depth-first, left-to-right search through the
2003 Argument DCLASS is the type whose virtual bases are required.
2004 Return value is the address of a null-terminated array of pointers
2005 to struct type items.
2007 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2008 and may not work with other runtime models.
2010 This routine merely hands off the argument to virtual_base_list_aux()
2011 and then copies the result into an array to save space. */
2014 virtual_base_list (struct type *dclass)
2016 struct vbase *tmp_vbase;
2017 struct vbase *tmp_vbase_2;
2020 struct type **vbase_array;
2022 current_vbase_list = NULL;
2023 virtual_base_list_aux (dclass);
2025 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2030 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
2032 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
2033 vbase_array[i] = tmp_vbase->vbasetype;
2035 /* Get rid of constructed chain */
2036 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2039 tmp_vbase = tmp_vbase->next;
2040 xfree (tmp_vbase_2);
2041 tmp_vbase_2 = tmp_vbase;
2044 vbase_array[count] = NULL;
2048 /* Return the length of the virtual base list of the type DCLASS. */
2051 virtual_base_list_length (struct type *dclass)
2054 struct vbase *tmp_vbase;
2056 current_vbase_list = NULL;
2057 virtual_base_list_aux (dclass);
2059 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2064 /* Return the number of elements of the virtual base list of the type
2065 DCLASS, ignoring those appearing in the primary base (and its
2066 primary base, recursively). */
2069 virtual_base_list_length_skip_primaries (struct type *dclass)
2072 struct vbase *tmp_vbase;
2073 struct type *primary;
2075 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2078 return virtual_base_list_length (dclass);
2080 current_vbase_list = NULL;
2081 virtual_base_list_aux (dclass);
2083 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
2085 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
2093 /* Return the index (position) of type BASE, which is a virtual base
2094 class of DCLASS, in the latter's virtual base list. A return of -1
2095 indicates "not found" or a problem. */
2098 virtual_base_index (struct type *base, struct type *dclass)
2103 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2104 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2108 vbase = virtual_base_list (dclass)[0];
2113 vbase = virtual_base_list (dclass)[++i];
2116 return vbase ? i : -1;
2121 /* Return the index (position) of type BASE, which is a virtual base
2122 class of DCLASS, in the latter's virtual base list. Skip over all
2123 bases that may appear in the virtual base list of the primary base
2124 class of DCLASS (recursively). A return of -1 indicates "not
2125 found" or a problem. */
2128 virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
2132 struct type *primary;
2134 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2135 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2138 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2142 vbase = virtual_base_list (dclass)[0];
2145 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2149 vbase = virtual_base_list (dclass)[++i];
2152 return vbase ? j : -1;
2155 /* Return position of a derived class DCLASS in the list of
2156 * primary bases starting with the remotest ancestor.
2157 * Position returned is 0-based. */
2160 class_index_in_primary_list (struct type *dclass)
2162 struct type *pbc; /* primary base class */
2164 /* Simply recurse on primary base */
2165 pbc = TYPE_PRIMARY_BASE (dclass);
2167 return 1 + class_index_in_primary_list (pbc);
2172 /* Return a count of the number of virtual functions a type has.
2173 * This includes all the virtual functions it inherits from its
2177 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2178 * functions only once (latest redefinition)
2182 count_virtual_fns (struct type *dclass)
2184 int fn, oi; /* function and overloaded instance indices */
2185 int vfuncs; /* count to return */
2187 /* recurse on bases that can share virtual table */
2188 struct type *pbc = primary_base_class (dclass);
2190 vfuncs = count_virtual_fns (pbc);
2194 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2195 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2196 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2204 /* Functions for overload resolution begin here */
2206 /* Compare two badness vectors A and B and return the result.
2207 * 0 => A and B are identical
2208 * 1 => A and B are incomparable
2209 * 2 => A is better than B
2210 * 3 => A is worse than B */
2213 compare_badness (struct badness_vector *a, struct badness_vector *b)
2217 short found_pos = 0; /* any positives in c? */
2218 short found_neg = 0; /* any negatives in c? */
2220 /* differing lengths => incomparable */
2221 if (a->length != b->length)
2224 /* Subtract b from a */
2225 for (i = 0; i < a->length; i++)
2227 tmp = a->rank[i] - b->rank[i];
2237 return 1; /* incomparable */
2239 return 3; /* A > B */
2245 return 2; /* A < B */
2247 return 0; /* A == B */
2251 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2252 * to the types of an argument list (ARGS, length NARGS).
2253 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2255 struct badness_vector *
2256 rank_function (struct type **parms, int nparms, struct type **args, int nargs)
2259 struct badness_vector *bv;
2260 int min_len = nparms < nargs ? nparms : nargs;
2262 bv = xmalloc (sizeof (struct badness_vector));
2263 bv->length = nargs + 1; /* add 1 for the length-match rank */
2264 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2266 /* First compare the lengths of the supplied lists.
2267 * If there is a mismatch, set it to a high value. */
2269 /* pai/1997-06-03 FIXME: when we have debug info about default
2270 * arguments and ellipsis parameter lists, we should consider those
2271 * and rank the length-match more finely. */
2273 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2275 /* Now rank all the parameters of the candidate function */
2276 for (i = 1; i <= min_len; i++)
2277 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2279 /* If more arguments than parameters, add dummy entries */
2280 for (i = min_len + 1; i <= nargs; i++)
2281 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2286 /* Compare the names of two integer types, assuming that any sign
2287 qualifiers have been checked already. We do it this way because
2288 there may be an "int" in the name of one of the types. */
2291 integer_types_same_name_p (const char *first, const char *second)
2293 int first_p, second_p;
2295 /* If both are shorts, return 1; if neither is a short, keep checking. */
2296 first_p = (strstr (first, "short") != NULL);
2297 second_p = (strstr (second, "short") != NULL);
2298 if (first_p && second_p)
2300 if (first_p || second_p)
2303 /* Likewise for long. */
2304 first_p = (strstr (first, "long") != NULL);
2305 second_p = (strstr (second, "long") != NULL);
2306 if (first_p && second_p)
2308 if (first_p || second_p)
2311 /* Likewise for char. */
2312 first_p = (strstr (first, "char") != NULL);
2313 second_p = (strstr (second, "char") != NULL);
2314 if (first_p && second_p)
2316 if (first_p || second_p)
2319 /* They must both be ints. */
2323 /* Compare one type (PARM) for compatibility with another (ARG).
2324 * PARM is intended to be the parameter type of a function; and
2325 * ARG is the supplied argument's type. This function tests if
2326 * the latter can be converted to the former.
2328 * Return 0 if they are identical types;
2329 * Otherwise, return an integer which corresponds to how compatible
2330 * PARM is to ARG. The higher the return value, the worse the match.
2331 * Generally the "bad" conversions are all uniformly assigned a 100 */
2334 rank_one_type (struct type *parm, struct type *arg)
2336 /* Identical type pointers */
2337 /* However, this still doesn't catch all cases of same type for arg
2338 * and param. The reason is that builtin types are different from
2339 * the same ones constructed from the object. */
2343 /* Resolve typedefs */
2344 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2345 parm = check_typedef (parm);
2346 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2347 arg = check_typedef (arg);
2350 Well, damnit, if the names are exactly the same,
2351 i'll say they are exactly the same. This happens when we generate
2352 method stubs. The types won't point to the same address, but they
2353 really are the same.
2356 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2357 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2360 /* Check if identical after resolving typedefs */
2364 /* See through references, since we can almost make non-references
2366 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2367 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2368 + REFERENCE_CONVERSION_BADNESS);
2369 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2370 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2371 + REFERENCE_CONVERSION_BADNESS);
2373 /* Debugging only. */
2374 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2375 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2377 /* x -> y means arg of type x being supplied for parameter of type y */
2379 switch (TYPE_CODE (parm))
2382 switch (TYPE_CODE (arg))
2385 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2386 return VOID_PTR_CONVERSION_BADNESS;
2388 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2389 case TYPE_CODE_ARRAY:
2390 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2391 case TYPE_CODE_FUNC:
2392 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2394 case TYPE_CODE_ENUM:
2395 case TYPE_CODE_CHAR:
2396 case TYPE_CODE_RANGE:
2397 case TYPE_CODE_BOOL:
2398 return POINTER_CONVERSION_BADNESS;
2400 return INCOMPATIBLE_TYPE_BADNESS;
2402 case TYPE_CODE_ARRAY:
2403 switch (TYPE_CODE (arg))
2406 case TYPE_CODE_ARRAY:
2407 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2409 return INCOMPATIBLE_TYPE_BADNESS;
2411 case TYPE_CODE_FUNC:
2412 switch (TYPE_CODE (arg))
2414 case TYPE_CODE_PTR: /* funcptr -> func */
2415 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2417 return INCOMPATIBLE_TYPE_BADNESS;
2420 switch (TYPE_CODE (arg))
2423 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2425 /* Deal with signed, unsigned, and plain chars and
2426 signed and unsigned ints */
2427 if (TYPE_NOSIGN (parm))
2429 /* This case only for character types */
2430 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2433 return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */
2435 else if (TYPE_UNSIGNED (parm))
2437 if (TYPE_UNSIGNED (arg))
2439 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2440 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2442 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2443 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
2444 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2446 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
2450 if (integer_types_same_name_p (TYPE_NAME (arg), "long")
2451 && integer_types_same_name_p (TYPE_NAME (parm), "int"))
2452 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
2454 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2457 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2459 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2461 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2462 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
2463 return INTEGER_PROMOTION_BADNESS;
2465 return INTEGER_CONVERSION_BADNESS;
2468 return INTEGER_CONVERSION_BADNESS;
2470 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2471 return INTEGER_PROMOTION_BADNESS;
2473 return INTEGER_CONVERSION_BADNESS;
2474 case TYPE_CODE_ENUM:
2475 case TYPE_CODE_CHAR:
2476 case TYPE_CODE_RANGE:
2477 case TYPE_CODE_BOOL:
2478 return INTEGER_PROMOTION_BADNESS;
2480 return INT_FLOAT_CONVERSION_BADNESS;
2482 return NS_POINTER_CONVERSION_BADNESS;
2484 return INCOMPATIBLE_TYPE_BADNESS;
2487 case TYPE_CODE_ENUM:
2488 switch (TYPE_CODE (arg))
2491 case TYPE_CODE_CHAR:
2492 case TYPE_CODE_RANGE:
2493 case TYPE_CODE_BOOL:
2494 case TYPE_CODE_ENUM:
2495 return INTEGER_CONVERSION_BADNESS;
2497 return INT_FLOAT_CONVERSION_BADNESS;
2499 return INCOMPATIBLE_TYPE_BADNESS;
2502 case TYPE_CODE_CHAR:
2503 switch (TYPE_CODE (arg))
2505 case TYPE_CODE_RANGE:
2506 case TYPE_CODE_BOOL:
2507 case TYPE_CODE_ENUM:
2508 return INTEGER_CONVERSION_BADNESS;
2510 return INT_FLOAT_CONVERSION_BADNESS;
2512 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2513 return INTEGER_CONVERSION_BADNESS;
2514 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2515 return INTEGER_PROMOTION_BADNESS;
2516 /* >>> !! else fall through !! <<< */
2517 case TYPE_CODE_CHAR:
2518 /* Deal with signed, unsigned, and plain chars for C++
2519 and with int cases falling through from previous case */
2520 if (TYPE_NOSIGN (parm))
2522 if (TYPE_NOSIGN (arg))
2525 return INTEGER_CONVERSION_BADNESS;
2527 else if (TYPE_UNSIGNED (parm))
2529 if (TYPE_UNSIGNED (arg))
2532 return INTEGER_PROMOTION_BADNESS;
2534 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2537 return INTEGER_CONVERSION_BADNESS;
2539 return INCOMPATIBLE_TYPE_BADNESS;
2542 case TYPE_CODE_RANGE:
2543 switch (TYPE_CODE (arg))
2546 case TYPE_CODE_CHAR:
2547 case TYPE_CODE_RANGE:
2548 case TYPE_CODE_BOOL:
2549 case TYPE_CODE_ENUM:
2550 return INTEGER_CONVERSION_BADNESS;
2552 return INT_FLOAT_CONVERSION_BADNESS;
2554 return INCOMPATIBLE_TYPE_BADNESS;
2557 case TYPE_CODE_BOOL:
2558 switch (TYPE_CODE (arg))
2561 case TYPE_CODE_CHAR:
2562 case TYPE_CODE_RANGE:
2563 case TYPE_CODE_ENUM:
2566 return BOOLEAN_CONVERSION_BADNESS;
2567 case TYPE_CODE_BOOL:
2570 return INCOMPATIBLE_TYPE_BADNESS;
2574 switch (TYPE_CODE (arg))
2577 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2578 return FLOAT_PROMOTION_BADNESS;
2579 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2582 return FLOAT_CONVERSION_BADNESS;
2584 case TYPE_CODE_BOOL:
2585 case TYPE_CODE_ENUM:
2586 case TYPE_CODE_RANGE:
2587 case TYPE_CODE_CHAR:
2588 return INT_FLOAT_CONVERSION_BADNESS;
2590 return INCOMPATIBLE_TYPE_BADNESS;
2593 case TYPE_CODE_COMPLEX:
2594 switch (TYPE_CODE (arg))
2595 { /* Strictly not needed for C++, but... */
2597 return FLOAT_PROMOTION_BADNESS;
2598 case TYPE_CODE_COMPLEX:
2601 return INCOMPATIBLE_TYPE_BADNESS;
2604 case TYPE_CODE_STRUCT:
2605 /* currently same as TYPE_CODE_CLASS */
2606 switch (TYPE_CODE (arg))
2608 case TYPE_CODE_STRUCT:
2609 /* Check for derivation */
2610 if (is_ancestor (parm, arg))
2611 return BASE_CONVERSION_BADNESS;
2612 /* else fall through */
2614 return INCOMPATIBLE_TYPE_BADNESS;
2617 case TYPE_CODE_UNION:
2618 switch (TYPE_CODE (arg))
2620 case TYPE_CODE_UNION:
2622 return INCOMPATIBLE_TYPE_BADNESS;
2625 case TYPE_CODE_MEMBER:
2626 switch (TYPE_CODE (arg))
2629 return INCOMPATIBLE_TYPE_BADNESS;
2632 case TYPE_CODE_METHOD:
2633 switch (TYPE_CODE (arg))
2637 return INCOMPATIBLE_TYPE_BADNESS;
2641 switch (TYPE_CODE (arg))
2645 return INCOMPATIBLE_TYPE_BADNESS;
2650 switch (TYPE_CODE (arg))
2654 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2656 return INCOMPATIBLE_TYPE_BADNESS;
2659 case TYPE_CODE_VOID:
2661 return INCOMPATIBLE_TYPE_BADNESS;
2662 } /* switch (TYPE_CODE (arg)) */
2666 /* End of functions for overload resolution */
2669 print_bit_vector (B_TYPE *bits, int nbits)
2673 for (bitno = 0; bitno < nbits; bitno++)
2675 if ((bitno % 8) == 0)
2677 puts_filtered (" ");
2679 if (B_TST (bits, bitno))
2681 printf_filtered ("1");
2685 printf_filtered ("0");
2690 /* Note the first arg should be the "this" pointer, we may not want to
2691 include it since we may get into a infinitely recursive situation. */
2694 print_arg_types (struct field *args, int nargs, int spaces)
2700 for (i = 0; i < nargs; i++)
2701 recursive_dump_type (args[i].type, spaces + 2);
2706 dump_fn_fieldlists (struct type *type, int spaces)
2712 printfi_filtered (spaces, "fn_fieldlists ");
2713 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2714 printf_filtered ("\n");
2715 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2717 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2718 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2720 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2721 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2723 printf_filtered (") length %d\n",
2724 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2725 for (overload_idx = 0;
2726 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2729 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2731 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2732 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2734 printf_filtered (")\n");
2735 printfi_filtered (spaces + 8, "type ");
2736 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2737 printf_filtered ("\n");
2739 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2742 printfi_filtered (spaces + 8, "args ");
2743 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2744 printf_filtered ("\n");
2746 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2747 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2749 printfi_filtered (spaces + 8, "fcontext ");
2750 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2752 printf_filtered ("\n");
2754 printfi_filtered (spaces + 8, "is_const %d\n",
2755 TYPE_FN_FIELD_CONST (f, overload_idx));
2756 printfi_filtered (spaces + 8, "is_volatile %d\n",
2757 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2758 printfi_filtered (spaces + 8, "is_private %d\n",
2759 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2760 printfi_filtered (spaces + 8, "is_protected %d\n",
2761 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2762 printfi_filtered (spaces + 8, "is_stub %d\n",
2763 TYPE_FN_FIELD_STUB (f, overload_idx));
2764 printfi_filtered (spaces + 8, "voffset %u\n",
2765 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2771 print_cplus_stuff (struct type *type, int spaces)
2773 printfi_filtered (spaces, "n_baseclasses %d\n",
2774 TYPE_N_BASECLASSES (type));
2775 printfi_filtered (spaces, "nfn_fields %d\n",
2776 TYPE_NFN_FIELDS (type));
2777 printfi_filtered (spaces, "nfn_fields_total %d\n",
2778 TYPE_NFN_FIELDS_TOTAL (type));
2779 if (TYPE_N_BASECLASSES (type) > 0)
2781 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2782 TYPE_N_BASECLASSES (type));
2783 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2784 printf_filtered (")");
2786 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2787 TYPE_N_BASECLASSES (type));
2788 puts_filtered ("\n");
2790 if (TYPE_NFIELDS (type) > 0)
2792 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2794 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2795 TYPE_NFIELDS (type));
2796 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2797 printf_filtered (")");
2798 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2799 TYPE_NFIELDS (type));
2800 puts_filtered ("\n");
2802 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2804 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2805 TYPE_NFIELDS (type));
2806 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2807 printf_filtered (")");
2808 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2809 TYPE_NFIELDS (type));
2810 puts_filtered ("\n");
2813 if (TYPE_NFN_FIELDS (type) > 0)
2815 dump_fn_fieldlists (type, spaces);
2820 print_bound_type (int bt)
2824 case BOUND_CANNOT_BE_DETERMINED:
2825 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2827 case BOUND_BY_REF_ON_STACK:
2828 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2830 case BOUND_BY_VALUE_ON_STACK:
2831 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2833 case BOUND_BY_REF_IN_REG:
2834 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2836 case BOUND_BY_VALUE_IN_REG:
2837 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2840 printf_filtered ("(BOUND_SIMPLE)");
2843 printf_filtered ("(unknown bound type)");
2848 static struct obstack dont_print_type_obstack;
2851 recursive_dump_type (struct type *type, int spaces)
2856 obstack_begin (&dont_print_type_obstack, 0);
2858 if (TYPE_NFIELDS (type) > 0
2859 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2861 struct type **first_dont_print
2862 = (struct type **) obstack_base (&dont_print_type_obstack);
2864 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2869 if (type == first_dont_print[i])
2871 printfi_filtered (spaces, "type node ");
2872 gdb_print_host_address (type, gdb_stdout);
2873 printf_filtered (" <same as already seen type>\n");
2878 obstack_ptr_grow (&dont_print_type_obstack, type);
2881 printfi_filtered (spaces, "type node ");
2882 gdb_print_host_address (type, gdb_stdout);
2883 printf_filtered ("\n");
2884 printfi_filtered (spaces, "name '%s' (",
2885 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2886 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2887 printf_filtered (")\n");
2888 printfi_filtered (spaces, "tagname '%s' (",
2889 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2890 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2891 printf_filtered (")\n");
2892 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2893 switch (TYPE_CODE (type))
2895 case TYPE_CODE_UNDEF:
2896 printf_filtered ("(TYPE_CODE_UNDEF)");
2899 printf_filtered ("(TYPE_CODE_PTR)");
2901 case TYPE_CODE_ARRAY:
2902 printf_filtered ("(TYPE_CODE_ARRAY)");
2904 case TYPE_CODE_STRUCT:
2905 printf_filtered ("(TYPE_CODE_STRUCT)");
2907 case TYPE_CODE_UNION:
2908 printf_filtered ("(TYPE_CODE_UNION)");
2910 case TYPE_CODE_ENUM:
2911 printf_filtered ("(TYPE_CODE_ENUM)");
2913 case TYPE_CODE_FUNC:
2914 printf_filtered ("(TYPE_CODE_FUNC)");
2917 printf_filtered ("(TYPE_CODE_INT)");
2920 printf_filtered ("(TYPE_CODE_FLT)");
2922 case TYPE_CODE_VOID:
2923 printf_filtered ("(TYPE_CODE_VOID)");
2926 printf_filtered ("(TYPE_CODE_SET)");
2928 case TYPE_CODE_RANGE:
2929 printf_filtered ("(TYPE_CODE_RANGE)");
2931 case TYPE_CODE_STRING:
2932 printf_filtered ("(TYPE_CODE_STRING)");
2934 case TYPE_CODE_BITSTRING:
2935 printf_filtered ("(TYPE_CODE_BITSTRING)");
2937 case TYPE_CODE_ERROR:
2938 printf_filtered ("(TYPE_CODE_ERROR)");
2940 case TYPE_CODE_MEMBER:
2941 printf_filtered ("(TYPE_CODE_MEMBER)");
2943 case TYPE_CODE_METHOD:
2944 printf_filtered ("(TYPE_CODE_METHOD)");
2947 printf_filtered ("(TYPE_CODE_REF)");
2949 case TYPE_CODE_CHAR:
2950 printf_filtered ("(TYPE_CODE_CHAR)");
2952 case TYPE_CODE_BOOL:
2953 printf_filtered ("(TYPE_CODE_BOOL)");
2955 case TYPE_CODE_COMPLEX:
2956 printf_filtered ("(TYPE_CODE_COMPLEX)");
2958 case TYPE_CODE_TYPEDEF:
2959 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2961 case TYPE_CODE_TEMPLATE:
2962 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2964 case TYPE_CODE_TEMPLATE_ARG:
2965 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2967 case TYPE_CODE_NAMESPACE:
2968 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2971 printf_filtered ("(UNKNOWN TYPE CODE)");
2974 puts_filtered ("\n");
2975 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2976 printfi_filtered (spaces, "upper_bound_type 0x%x ",
2977 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2978 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2979 puts_filtered ("\n");
2980 printfi_filtered (spaces, "lower_bound_type 0x%x ",
2981 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2982 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2983 puts_filtered ("\n");
2984 printfi_filtered (spaces, "objfile ");
2985 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2986 printf_filtered ("\n");
2987 printfi_filtered (spaces, "target_type ");
2988 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2989 printf_filtered ("\n");
2990 if (TYPE_TARGET_TYPE (type) != NULL)
2992 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2994 printfi_filtered (spaces, "pointer_type ");
2995 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2996 printf_filtered ("\n");
2997 printfi_filtered (spaces, "reference_type ");
2998 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2999 printf_filtered ("\n");
3000 printfi_filtered (spaces, "type_chain ");
3001 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
3002 printf_filtered ("\n");
3003 printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
3004 if (TYPE_CONST (type))
3006 puts_filtered (" TYPE_FLAG_CONST");
3008 if (TYPE_VOLATILE (type))
3010 puts_filtered (" TYPE_FLAG_VOLATILE");
3012 if (TYPE_CODE_SPACE (type))
3014 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3016 if (TYPE_DATA_SPACE (type))
3018 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3020 if (TYPE_ADDRESS_CLASS_1 (type))
3022 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3024 if (TYPE_ADDRESS_CLASS_2 (type))
3026 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3028 puts_filtered ("\n");
3029 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
3030 if (TYPE_UNSIGNED (type))
3032 puts_filtered (" TYPE_FLAG_UNSIGNED");
3034 if (TYPE_NOSIGN (type))
3036 puts_filtered (" TYPE_FLAG_NOSIGN");
3038 if (TYPE_STUB (type))
3040 puts_filtered (" TYPE_FLAG_STUB");
3042 if (TYPE_TARGET_STUB (type))
3044 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3046 if (TYPE_STATIC (type))
3048 puts_filtered (" TYPE_FLAG_STATIC");
3050 if (TYPE_PROTOTYPED (type))
3052 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3054 if (TYPE_INCOMPLETE (type))
3056 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3058 if (TYPE_VARARGS (type))
3060 puts_filtered (" TYPE_FLAG_VARARGS");
3062 /* This is used for things like AltiVec registers on ppc. Gcc emits
3063 an attribute for the array type, which tells whether or not we
3064 have a vector, instead of a regular array. */
3065 if (TYPE_VECTOR (type))
3067 puts_filtered (" TYPE_FLAG_VECTOR");
3069 puts_filtered ("\n");
3070 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3071 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3072 puts_filtered ("\n");
3073 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3075 printfi_filtered (spaces + 2,
3076 "[%d] bitpos %d bitsize %d type ",
3077 idx, TYPE_FIELD_BITPOS (type, idx),
3078 TYPE_FIELD_BITSIZE (type, idx));
3079 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3080 printf_filtered (" name '%s' (",
3081 TYPE_FIELD_NAME (type, idx) != NULL
3082 ? TYPE_FIELD_NAME (type, idx)
3084 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3085 printf_filtered (")\n");
3086 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3088 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3091 printfi_filtered (spaces, "vptr_basetype ");
3092 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3093 puts_filtered ("\n");
3094 if (TYPE_VPTR_BASETYPE (type) != NULL)
3096 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3098 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3099 switch (TYPE_CODE (type))
3101 case TYPE_CODE_STRUCT:
3102 printfi_filtered (spaces, "cplus_stuff ");
3103 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3104 puts_filtered ("\n");
3105 print_cplus_stuff (type, spaces);
3109 printfi_filtered (spaces, "floatformat ");
3110 if (TYPE_FLOATFORMAT (type) == NULL
3111 || TYPE_FLOATFORMAT (type)->name == NULL)
3112 puts_filtered ("(null)");
3114 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3115 puts_filtered ("\n");
3119 /* We have to pick one of the union types to be able print and test
3120 the value. Pick cplus_struct_type, even though we know it isn't
3121 any particular one. */
3122 printfi_filtered (spaces, "type_specific ");
3123 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3124 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3126 printf_filtered (" (unknown data form)");
3128 printf_filtered ("\n");
3133 obstack_free (&dont_print_type_obstack, NULL);
3136 static void build_gdbtypes (void);
3138 build_gdbtypes (void)
3141 init_type (TYPE_CODE_VOID, 1,
3143 "void", (struct objfile *) NULL);
3145 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3147 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
3148 "char", (struct objfile *) NULL);
3149 builtin_type_true_char =
3150 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3152 "true character", (struct objfile *) NULL);
3153 builtin_type_signed_char =
3154 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3156 "signed char", (struct objfile *) NULL);
3157 builtin_type_unsigned_char =
3158 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3160 "unsigned char", (struct objfile *) NULL);
3161 builtin_type_short =
3162 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3164 "short", (struct objfile *) NULL);
3165 builtin_type_unsigned_short =
3166 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3168 "unsigned short", (struct objfile *) NULL);
3170 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3172 "int", (struct objfile *) NULL);
3173 builtin_type_unsigned_int =
3174 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3176 "unsigned int", (struct objfile *) NULL);
3178 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3180 "long", (struct objfile *) NULL);
3181 builtin_type_unsigned_long =
3182 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3184 "unsigned long", (struct objfile *) NULL);
3185 builtin_type_long_long =
3186 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3188 "long long", (struct objfile *) NULL);
3189 builtin_type_unsigned_long_long =
3190 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3192 "unsigned long long", (struct objfile *) NULL);
3193 builtin_type_float =
3194 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3196 "float", (struct objfile *) NULL);
3197 /* vinschen@redhat.com 2002-02-08:
3198 The below lines are disabled since they are doing the wrong
3199 thing for non-multiarch targets. They are setting the correct
3200 type of floats for the target but while on multiarch targets
3201 this is done everytime the architecture changes, it's done on
3202 non-multiarch targets only on startup, leaving the wrong values
3203 in even if the architecture changes (eg. from big-endian to
3206 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
3208 builtin_type_double =
3209 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3211 "double", (struct objfile *) NULL);
3213 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
3215 builtin_type_long_double =
3216 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3218 "long double", (struct objfile *) NULL);
3220 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
3222 builtin_type_complex =
3223 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3225 "complex", (struct objfile *) NULL);
3226 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3227 builtin_type_double_complex =
3228 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3230 "double complex", (struct objfile *) NULL);
3231 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3232 builtin_type_string =
3233 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3235 "string", (struct objfile *) NULL);
3237 init_type (TYPE_CODE_INT, 0 / 8,
3239 "int0_t", (struct objfile *) NULL);
3241 init_type (TYPE_CODE_INT, 8 / 8,
3243 "int8_t", (struct objfile *) NULL);
3244 builtin_type_uint8 =
3245 init_type (TYPE_CODE_INT, 8 / 8,
3247 "uint8_t", (struct objfile *) NULL);
3248 builtin_type_int16 =
3249 init_type (TYPE_CODE_INT, 16 / 8,
3251 "int16_t", (struct objfile *) NULL);
3252 builtin_type_uint16 =
3253 init_type (TYPE_CODE_INT, 16 / 8,
3255 "uint16_t", (struct objfile *) NULL);
3256 builtin_type_int32 =
3257 init_type (TYPE_CODE_INT, 32 / 8,
3259 "int32_t", (struct objfile *) NULL);
3260 builtin_type_uint32 =
3261 init_type (TYPE_CODE_INT, 32 / 8,
3263 "uint32_t", (struct objfile *) NULL);
3264 builtin_type_int64 =
3265 init_type (TYPE_CODE_INT, 64 / 8,
3267 "int64_t", (struct objfile *) NULL);
3268 builtin_type_uint64 =
3269 init_type (TYPE_CODE_INT, 64 / 8,
3271 "uint64_t", (struct objfile *) NULL);
3272 builtin_type_int128 =
3273 init_type (TYPE_CODE_INT, 128 / 8,
3275 "int128_t", (struct objfile *) NULL);
3276 builtin_type_uint128 =
3277 init_type (TYPE_CODE_INT, 128 / 8,
3279 "uint128_t", (struct objfile *) NULL);
3281 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3283 "bool", (struct objfile *) NULL);
3285 /* Add user knob for controlling resolution of opaque types */
3287 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
3288 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3291 opaque_type_resolution = 1;
3293 /* Build SIMD types. */
3295 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
3297 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
3299 = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
3301 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
3303 = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
3305 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3307 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
3309 /* 128 bit vectors. */
3310 builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
3311 builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3312 builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
3313 builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3314 builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3315 builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3316 /* 64 bit vectors. */
3317 builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
3318 builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3319 builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3320 builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
3323 builtin_type_vec64 = build_builtin_type_vec64 ();
3324 builtin_type_vec64i = build_builtin_type_vec64i ();
3325 builtin_type_vec128 = build_builtin_type_vec128 ();
3326 builtin_type_vec128i = build_builtin_type_vec128i ();
3328 /* Pointer/Address types. */
3330 /* NOTE: on some targets, addresses and pointers are not necessarily
3331 the same --- for example, on the D10V, pointers are 16 bits long,
3332 but addresses are 32 bits long. See doc/gdbint.texinfo,
3333 ``Pointers Are Not Always Addresses''.
3336 - gdb's `struct type' always describes the target's
3338 - gdb's `struct value' objects should always hold values in
3340 - gdb's CORE_ADDR values are addresses in the unified virtual
3341 address space that the assembler and linker work with. Thus,
3342 since target_read_memory takes a CORE_ADDR as an argument, it
3343 can access any memory on the target, even if the processor has
3344 separate code and data address spaces.
3347 - If v is a value holding a D10V code pointer, its contents are
3348 in target form: a big-endian address left-shifted two bits.
3349 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3350 sizeof (void *) == 2 on the target.
3352 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3353 target type for a value the target will never see. It's only
3354 used to hold the values of (typeless) linker symbols, which are
3355 indeed in the unified virtual address space. */
3356 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
3357 builtin_type_void_func_ptr
3358 = lookup_pointer_type (lookup_function_type (builtin_type_void));
3359 builtin_type_CORE_ADDR =
3360 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
3362 "__CORE_ADDR", (struct objfile *) NULL);
3363 builtin_type_bfd_vma =
3364 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3366 "__bfd_vma", (struct objfile *) NULL);
3369 extern void _initialize_gdbtypes (void);
3371 _initialize_gdbtypes (void)
3373 struct cmd_list_element *c;
3376 /* FIXME - For the moment, handle types by swapping them in and out.
3377 Should be using the per-architecture data-pointer and a large
3379 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void);
3380 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char);
3381 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short);
3382 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int);
3383 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long);
3384 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long);
3385 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char);
3386 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char);
3387 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short);
3388 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int);
3389 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long);
3390 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long);
3391 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float);
3392 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double);
3393 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double);
3394 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex);
3395 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex);
3396 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string);
3397 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int8);
3398 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint8);
3399 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int16);
3400 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint16);
3401 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int32);
3402 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint32);
3403 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int64);
3404 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint64);
3405 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int128);
3406 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint128);
3407 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf);
3408 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si);
3409 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi);
3410 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi);
3411 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi);
3412 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi);
3413 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si);
3414 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double);
3415 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float);
3416 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64);
3417 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32);
3418 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16);
3419 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8);
3420 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float);
3421 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32);
3422 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8);
3423 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16);
3424 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128);
3425 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128i);
3426 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3427 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3428 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3429 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3430 deprecated_register_gdbarch_swap (NULL, 0, build_gdbtypes);
3432 /* Note: These types do not need to be swapped - they are target
3434 builtin_type_ieee_single_big =
3435 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3436 0, "builtin_type_ieee_single_big", NULL);
3437 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3438 builtin_type_ieee_single_little =
3439 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3440 0, "builtin_type_ieee_single_little", NULL);
3441 TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
3442 builtin_type_ieee_double_big =
3443 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3444 0, "builtin_type_ieee_double_big", NULL);
3445 TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
3446 builtin_type_ieee_double_little =
3447 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3448 0, "builtin_type_ieee_double_little", NULL);
3449 TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
3450 builtin_type_ieee_double_littlebyte_bigword =
3451 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3452 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
3453 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
3454 builtin_type_i387_ext =
3455 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3456 0, "builtin_type_i387_ext", NULL);
3457 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
3458 builtin_type_m68881_ext =
3459 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3460 0, "builtin_type_m68881_ext", NULL);
3461 TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
3462 builtin_type_i960_ext =
3463 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3464 0, "builtin_type_i960_ext", NULL);
3465 TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
3466 builtin_type_m88110_ext =
3467 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3468 0, "builtin_type_m88110_ext", NULL);
3469 TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
3470 builtin_type_m88110_harris_ext =
3471 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3472 0, "builtin_type_m88110_harris_ext", NULL);
3473 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
3474 builtin_type_arm_ext_big =
3475 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3476 0, "builtin_type_arm_ext_big", NULL);
3477 TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
3478 builtin_type_arm_ext_littlebyte_bigword =
3479 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3480 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
3481 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
3482 builtin_type_ia64_spill_big =
3483 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3484 0, "builtin_type_ia64_spill_big", NULL);
3485 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
3486 builtin_type_ia64_spill_little =
3487 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3488 0, "builtin_type_ia64_spill_little", NULL);
3489 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
3490 builtin_type_ia64_quad_big =
3491 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3492 0, "builtin_type_ia64_quad_big", NULL);
3493 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
3494 builtin_type_ia64_quad_little =
3495 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3496 0, "builtin_type_ia64_quad_little", NULL);
3497 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
3500 add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
3501 "Set debugging of C++ overloading.\n\
3502 When enabled, ranking of the functions\n\
3503 is displayed.", &setdebuglist),