1 /* Support routines for manipulating internal types for GDB.
2 Copyright (C) 1992, 93, 94, 95, 96, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support, using pieces from other GDB modules.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
29 #include "expression.h"
34 #include "complaints.h"
37 /* These variables point to the objects
38 representing the predefined C data types. */
40 struct type *builtin_type_void;
41 struct type *builtin_type_char;
42 struct type *builtin_type_true_char;
43 struct type *builtin_type_short;
44 struct type *builtin_type_int;
45 struct type *builtin_type_long;
46 struct type *builtin_type_long_long;
47 struct type *builtin_type_signed_char;
48 struct type *builtin_type_unsigned_char;
49 struct type *builtin_type_unsigned_short;
50 struct type *builtin_type_unsigned_int;
51 struct type *builtin_type_unsigned_long;
52 struct type *builtin_type_unsigned_long_long;
53 struct type *builtin_type_float;
54 struct type *builtin_type_double;
55 struct type *builtin_type_long_double;
56 struct type *builtin_type_complex;
57 struct type *builtin_type_double_complex;
58 struct type *builtin_type_string;
59 struct type *builtin_type_int8;
60 struct type *builtin_type_uint8;
61 struct type *builtin_type_int16;
62 struct type *builtin_type_uint16;
63 struct type *builtin_type_int32;
64 struct type *builtin_type_uint32;
65 struct type *builtin_type_int64;
66 struct type *builtin_type_uint64;
67 struct type *builtin_type_bool;
68 struct type *builtin_type_v4sf;
69 struct type *builtin_type_v4si;
70 struct type *builtin_type_v8qi;
71 struct type *builtin_type_v4hi;
72 struct type *builtin_type_v2si;
74 int opaque_type_resolution = 1;
81 }; /* maximum extention is 128! FIXME */
83 static void add_name PARAMS ((struct extra *, char *));
84 static void add_mangled_type PARAMS ((struct extra *, struct type *));
86 static void cfront_mangle_name PARAMS ((struct type *, int, int));
88 static void print_bit_vector PARAMS ((B_TYPE *, int));
89 static void print_arg_types PARAMS ((struct type **, int));
90 static void dump_fn_fieldlists PARAMS ((struct type *, int));
91 static void print_cplus_stuff PARAMS ((struct type *, int));
92 static void virtual_base_list_aux PARAMS ((struct type * dclass));
95 /* Alloc a new type structure and fill it with some defaults. If
96 OBJFILE is non-NULL, then allocate the space for the type structure
97 in that objfile's type_obstack. */
101 struct objfile *objfile;
103 register struct type *type;
105 /* Alloc the structure and start off with all fields zeroed. */
109 type = (struct type *) xmalloc (sizeof (struct type));
113 type = (struct type *) obstack_alloc (&objfile->type_obstack,
114 sizeof (struct type));
115 OBJSTAT (objfile, n_types++);
117 memset ((char *) type, 0, sizeof (struct type));
119 /* Initialize the fields that might not be zero. */
121 TYPE_CODE (type) = TYPE_CODE_UNDEF;
122 TYPE_OBJFILE (type) = objfile;
123 TYPE_VPTR_FIELDNO (type) = -1;
124 TYPE_CV_TYPE (type) = type; /* chain back to itself */
129 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
130 to a pointer to memory where the pointer type should be stored.
131 If *TYPEPTR is zero, update it to point to the pointer type we return.
132 We allocate new memory if needed. */
135 make_pointer_type (type, typeptr)
137 struct type **typeptr;
139 register struct type *ntype; /* New type */
140 struct objfile *objfile;
142 ntype = TYPE_POINTER_TYPE (type);
147 return ntype; /* Don't care about alloc, and have new type. */
148 else if (*typeptr == 0)
150 *typeptr = ntype; /* Tracking alloc, and we have new type. */
155 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
157 ntype = alloc_type (TYPE_OBJFILE (type));
162 /* We have storage, but need to reset it. */
165 objfile = TYPE_OBJFILE (ntype);
166 memset ((char *) ntype, 0, sizeof (struct type));
167 TYPE_OBJFILE (ntype) = objfile;
170 TYPE_TARGET_TYPE (ntype) = type;
171 TYPE_POINTER_TYPE (type) = ntype;
173 /* FIXME! Assume the machine has only one representation for pointers! */
175 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
176 TYPE_CODE (ntype) = TYPE_CODE_PTR;
178 /* pointers are unsigned */
179 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
181 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
182 TYPE_POINTER_TYPE (type) = ntype;
187 /* Given a type TYPE, return a type of pointers to that type.
188 May need to construct such a type if this is the first use. */
191 lookup_pointer_type (type)
194 return make_pointer_type (type, (struct type **) 0);
197 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
198 to a pointer to memory where the reference type should be stored.
199 If *TYPEPTR is zero, update it to point to the reference type we return.
200 We allocate new memory if needed. */
203 make_reference_type (type, typeptr)
205 struct type **typeptr;
207 register struct type *ntype; /* New type */
208 struct objfile *objfile;
210 ntype = TYPE_REFERENCE_TYPE (type);
215 return ntype; /* Don't care about alloc, and have new type. */
216 else if (*typeptr == 0)
218 *typeptr = ntype; /* Tracking alloc, and we have new type. */
223 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
225 ntype = alloc_type (TYPE_OBJFILE (type));
230 /* We have storage, but need to reset it. */
233 objfile = TYPE_OBJFILE (ntype);
234 memset ((char *) ntype, 0, sizeof (struct type));
235 TYPE_OBJFILE (ntype) = objfile;
238 TYPE_TARGET_TYPE (ntype) = type;
239 TYPE_REFERENCE_TYPE (type) = ntype;
241 /* FIXME! Assume the machine has only one representation for references,
242 and that it matches the (only) representation for pointers! */
244 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
245 TYPE_CODE (ntype) = TYPE_CODE_REF;
247 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
248 TYPE_REFERENCE_TYPE (type) = ntype;
253 /* Same as above, but caller doesn't care about memory allocation details. */
256 lookup_reference_type (type)
259 return make_reference_type (type, (struct type **) 0);
262 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
263 to a pointer to memory where the function type should be stored.
264 If *TYPEPTR is zero, update it to point to the function type we return.
265 We allocate new memory if needed. */
268 make_function_type (type, typeptr)
270 struct type **typeptr;
272 register struct type *ntype; /* New type */
273 struct objfile *objfile;
275 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
277 ntype = alloc_type (TYPE_OBJFILE (type));
282 /* We have storage, but need to reset it. */
285 objfile = TYPE_OBJFILE (ntype);
286 memset ((char *) ntype, 0, sizeof (struct type));
287 TYPE_OBJFILE (ntype) = objfile;
290 TYPE_TARGET_TYPE (ntype) = type;
292 TYPE_LENGTH (ntype) = 1;
293 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
299 /* Given a type TYPE, return a type of functions that return that type.
300 May need to construct such a type if this is the first use. */
303 lookup_function_type (type)
306 return make_function_type (type, (struct type **) 0);
310 /* Make a "c-v" variant of a type -- a type that is identical to the
311 one supplied except that it may have const or volatile attributes
312 CNST is a flag for setting the const attribute
313 VOLTL is a flag for setting the volatile attribute
314 TYPE is the base type whose variant we are creating.
315 TYPEPTR, if nonzero, points
316 to a pointer to memory where the reference type should be stored.
317 If *TYPEPTR is zero, update it to point to the reference type we return.
318 We allocate new memory if needed. */
321 make_cv_type (cnst, voltl, type, typeptr)
325 struct type **typeptr;
327 register struct type *ntype; /* New type */
328 register struct type *tmp_type = type; /* tmp type */
329 struct objfile *objfile;
331 ntype = TYPE_CV_TYPE (type);
333 while (ntype != type)
335 if ((TYPE_CONST (ntype) == cnst) &&
336 (TYPE_VOLATILE (ntype) == voltl))
340 else if (*typeptr == 0)
342 *typeptr = ntype; /* Tracking alloc, and we have new type. */
347 ntype = TYPE_CV_TYPE (ntype);
350 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
352 ntype = alloc_type (TYPE_OBJFILE (type));
357 /* We have storage, but need to reset it. */
360 objfile = TYPE_OBJFILE (ntype);
361 /* memset ((char *) ntype, 0, sizeof (struct type)); */
362 TYPE_OBJFILE (ntype) = objfile;
365 /* Copy original type */
366 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
367 /* But zero out fields that shouldn't be copied */
368 TYPE_POINTER_TYPE (ntype) = (struct type *) 0; /* Need new pointer kind */
369 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; /* Need new referene kind */
370 /* Note: TYPE_TARGET_TYPE can be left as is */
372 /* Set flags appropriately */
374 TYPE_FLAGS (ntype) |= TYPE_FLAG_CONST;
376 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_CONST;
379 TYPE_FLAGS (ntype) |= TYPE_FLAG_VOLATILE;
381 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_VOLATILE;
383 /* Fix the chain of cv variants */
384 TYPE_CV_TYPE (ntype) = type;
385 TYPE_CV_TYPE (tmp_type) = ntype;
393 /* Implement direct support for MEMBER_TYPE in GNU C++.
394 May need to construct such a type if this is the first use.
395 The TYPE is the type of the member. The DOMAIN is the type
396 of the aggregate that the member belongs to. */
399 lookup_member_type (type, domain)
403 register struct type *mtype;
405 mtype = alloc_type (TYPE_OBJFILE (type));
406 smash_to_member_type (mtype, domain, type);
410 /* Allocate a stub method whose return type is TYPE.
411 This apparently happens for speed of symbol reading, since parsing
412 out the arguments to the method is cpu-intensive, the way we are doing
413 it. So, we will fill in arguments later.
414 This always returns a fresh type. */
417 allocate_stub_method (type)
422 mtype = alloc_type (TYPE_OBJFILE (type));
423 TYPE_TARGET_TYPE (mtype) = type;
424 /* _DOMAIN_TYPE (mtype) = unknown yet */
425 /* _ARG_TYPES (mtype) = unknown yet */
426 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
427 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
428 TYPE_LENGTH (mtype) = 1;
432 /* Create a range type using either a blank type supplied in RESULT_TYPE,
433 or creating a new type, inheriting the objfile from INDEX_TYPE.
435 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
436 HIGH_BOUND, inclusive.
438 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
439 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
442 create_range_type (result_type, index_type, low_bound, high_bound)
443 struct type *result_type;
444 struct type *index_type;
448 if (result_type == NULL)
450 result_type = alloc_type (TYPE_OBJFILE (index_type));
452 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
453 TYPE_TARGET_TYPE (result_type) = index_type;
454 if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB)
455 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
457 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
458 TYPE_NFIELDS (result_type) = 2;
459 TYPE_FIELDS (result_type) = (struct field *)
460 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
461 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
462 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
463 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
464 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
465 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
468 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
470 return (result_type);
473 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
474 Return 1 of type is a range type, 0 if it is discrete (and bounds
475 will fit in LONGEST), or -1 otherwise. */
478 get_discrete_bounds (type, lowp, highp)
480 LONGEST *lowp, *highp;
482 CHECK_TYPEDEF (type);
483 switch (TYPE_CODE (type))
485 case TYPE_CODE_RANGE:
486 *lowp = TYPE_LOW_BOUND (type);
487 *highp = TYPE_HIGH_BOUND (type);
490 if (TYPE_NFIELDS (type) > 0)
492 /* The enums may not be sorted by value, so search all
496 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
497 for (i = 0; i < TYPE_NFIELDS (type); i++)
499 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
500 *lowp = TYPE_FIELD_BITPOS (type, i);
501 if (TYPE_FIELD_BITPOS (type, i) > *highp)
502 *highp = TYPE_FIELD_BITPOS (type, i);
505 /* Set unsigned indicator if warranted. */
508 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
522 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
524 if (!TYPE_UNSIGNED (type))
526 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
530 /* ... fall through for unsigned ints ... */
533 /* This round-about calculation is to avoid shifting by
534 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
535 if TYPE_LENGTH (type) == sizeof (LONGEST). */
536 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
537 *highp = (*highp - 1) | *highp;
544 /* Create an array type using either a blank type supplied in RESULT_TYPE,
545 or creating a new type, inheriting the objfile from RANGE_TYPE.
547 Elements will be of type ELEMENT_TYPE, the indices will be of type
550 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
551 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
554 create_array_type (result_type, element_type, range_type)
555 struct type *result_type;
556 struct type *element_type;
557 struct type *range_type;
559 LONGEST low_bound, high_bound;
561 if (result_type == NULL)
563 result_type = alloc_type (TYPE_OBJFILE (range_type));
565 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
566 TYPE_TARGET_TYPE (result_type) = element_type;
567 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
568 low_bound = high_bound = 0;
569 CHECK_TYPEDEF (element_type);
570 TYPE_LENGTH (result_type) =
571 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
572 TYPE_NFIELDS (result_type) = 1;
573 TYPE_FIELDS (result_type) =
574 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
575 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
576 TYPE_FIELD_TYPE (result_type, 0) = range_type;
577 TYPE_VPTR_FIELDNO (result_type) = -1;
579 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
580 if (TYPE_LENGTH (result_type) == 0)
581 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
583 return (result_type);
586 /* Create a string type using either a blank type supplied in RESULT_TYPE,
587 or creating a new type. String types are similar enough to array of
588 char types that we can use create_array_type to build the basic type
589 and then bash it into a string type.
591 For fixed length strings, the range type contains 0 as the lower
592 bound and the length of the string minus one as the upper bound.
594 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
595 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
598 create_string_type (result_type, range_type)
599 struct type *result_type;
600 struct type *range_type;
602 result_type = create_array_type (result_type,
603 *current_language->string_char_type,
605 TYPE_CODE (result_type) = TYPE_CODE_STRING;
606 return (result_type);
610 create_set_type (result_type, domain_type)
611 struct type *result_type;
612 struct type *domain_type;
614 LONGEST low_bound, high_bound, bit_length;
615 if (result_type == NULL)
617 result_type = alloc_type (TYPE_OBJFILE (domain_type));
619 TYPE_CODE (result_type) = TYPE_CODE_SET;
620 TYPE_NFIELDS (result_type) = 1;
621 TYPE_FIELDS (result_type) = (struct field *)
622 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
623 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
625 if (!(TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB))
627 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
628 low_bound = high_bound = 0;
629 bit_length = high_bound - low_bound + 1;
630 TYPE_LENGTH (result_type)
631 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
633 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
636 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
638 return (result_type);
642 /* Construct and return a type of the form:
643 struct NAME { ELT_TYPE ELT_NAME[N]; }
644 We use these types for SIMD registers. For example, the type of
645 the SSE registers on the late x86-family processors is:
646 struct __builtin_v4sf { float f[4]; }
647 built by the function call:
648 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
649 The type returned is a permanent type, allocated using malloc; it
650 doesn't live in any objfile's obstack. */
652 init_simd_type (char *name,
653 struct type *elt_type,
660 /* Build the field structure. */
661 f = xmalloc (sizeof (*f));
662 memset (f, 0, sizeof (*f));
664 f->type = create_array_type (0, elt_type,
665 create_range_type (0, builtin_type_int,
669 /* Build a struct type with that field. */
670 t = init_type (TYPE_CODE_STRUCT, n * TYPE_LENGTH (elt_type), 0, 0, 0);
679 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
680 A MEMBER is a wierd thing -- it amounts to a typed offset into
681 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
682 include the offset (that's the value of the MEMBER itself), but does
683 include the structure type into which it points (for some reason).
685 When "smashing" the type, we preserve the objfile that the
686 old type pointed to, since we aren't changing where the type is actually
690 smash_to_member_type (type, domain, to_type)
693 struct type *to_type;
695 struct objfile *objfile;
697 objfile = TYPE_OBJFILE (type);
699 memset ((char *) type, 0, sizeof (struct type));
700 TYPE_OBJFILE (type) = objfile;
701 TYPE_TARGET_TYPE (type) = to_type;
702 TYPE_DOMAIN_TYPE (type) = domain;
703 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
704 TYPE_CODE (type) = TYPE_CODE_MEMBER;
707 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
708 METHOD just means `function that gets an extra "this" argument'.
710 When "smashing" the type, we preserve the objfile that the
711 old type pointed to, since we aren't changing where the type is actually
715 smash_to_method_type (type, domain, to_type, args)
718 struct type *to_type;
721 struct objfile *objfile;
723 objfile = TYPE_OBJFILE (type);
725 memset ((char *) type, 0, sizeof (struct type));
726 TYPE_OBJFILE (type) = objfile;
727 TYPE_TARGET_TYPE (type) = to_type;
728 TYPE_DOMAIN_TYPE (type) = domain;
729 TYPE_ARG_TYPES (type) = args;
730 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
731 TYPE_CODE (type) = TYPE_CODE_METHOD;
734 /* Return a typename for a struct/union/enum type without "struct ",
735 "union ", or "enum ". If the type has a NULL name, return NULL. */
738 type_name_no_tag (type)
739 register const struct type *type;
741 if (TYPE_TAG_NAME (type) != NULL)
742 return TYPE_TAG_NAME (type);
744 /* Is there code which expects this to return the name if there is no
745 tag name? My guess is that this is mainly used for C++ in cases where
746 the two will always be the same. */
747 return TYPE_NAME (type);
750 /* Lookup a primitive type named NAME.
751 Return zero if NAME is not a primitive type. */
754 lookup_primitive_typename (name)
757 struct type **const *p;
759 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
761 if (STREQ ((**p)->name, name))
769 /* Lookup a typedef or primitive type named NAME,
770 visible in lexical block BLOCK.
771 If NOERR is nonzero, return zero if NAME is not suitably defined. */
774 lookup_typename (name, block, noerr)
779 register struct symbol *sym;
780 register struct type *tmp;
782 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
783 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
785 tmp = lookup_primitive_typename (name);
790 else if (!tmp && noerr)
796 error ("No type named %s.", name);
799 return (SYMBOL_TYPE (sym));
803 lookup_unsigned_typename (name)
806 char *uns = alloca (strlen (name) + 10);
808 strcpy (uns, "unsigned ");
809 strcpy (uns + 9, name);
810 return (lookup_typename (uns, (struct block *) NULL, 0));
814 lookup_signed_typename (name)
818 char *uns = alloca (strlen (name) + 8);
820 strcpy (uns, "signed ");
821 strcpy (uns + 7, name);
822 t = lookup_typename (uns, (struct block *) NULL, 1);
823 /* If we don't find "signed FOO" just try again with plain "FOO". */
826 return lookup_typename (name, (struct block *) NULL, 0);
829 /* Lookup a structure type named "struct NAME",
830 visible in lexical block BLOCK. */
833 lookup_struct (name, block)
837 register struct symbol *sym;
839 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
840 (struct symtab **) NULL);
844 error ("No struct type named %s.", name);
846 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
848 error ("This context has class, union or enum %s, not a struct.", name);
850 return (SYMBOL_TYPE (sym));
853 /* Lookup a union type named "union NAME",
854 visible in lexical block BLOCK. */
857 lookup_union (name, block)
861 register struct symbol *sym;
864 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
865 (struct symtab **) NULL);
868 error ("No union type named %s.", name);
870 t = SYMBOL_TYPE (sym);
872 if (TYPE_CODE (t) == TYPE_CODE_UNION)
875 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
876 * a further "declared_type" field to discover it is really a union.
878 if (HAVE_CPLUS_STRUCT (t))
879 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
882 /* If we get here, it's not a union */
883 error ("This context has class, struct or enum %s, not a union.", name);
887 /* Lookup an enum type named "enum NAME",
888 visible in lexical block BLOCK. */
891 lookup_enum (name, block)
895 register struct symbol *sym;
897 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
898 (struct symtab **) NULL);
901 error ("No enum type named %s.", name);
903 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
905 error ("This context has class, struct or union %s, not an enum.", name);
907 return (SYMBOL_TYPE (sym));
910 /* Lookup a template type named "template NAME<TYPE>",
911 visible in lexical block BLOCK. */
914 lookup_template_type (name, type, block)
920 char *nam = (char *) alloca (strlen (name) + strlen (type->name) + 4);
923 strcat (nam, type->name);
924 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
926 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
930 error ("No template type named %s.", name);
932 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
934 error ("This context has class, union or enum %s, not a struct.", name);
936 return (SYMBOL_TYPE (sym));
939 /* Given a type TYPE, lookup the type of the component of type named NAME.
941 TYPE can be either a struct or union, or a pointer or reference to a struct or
942 union. If it is a pointer or reference, its target type is automatically used.
943 Thus '.' and '->' are interchangable, as specified for the definitions of the
944 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
946 If NOERR is nonzero, return zero if NAME is not suitably defined.
947 If NAME is the name of a baseclass type, return that type. */
950 lookup_struct_elt_type (type, name, noerr)
959 CHECK_TYPEDEF (type);
960 if (TYPE_CODE (type) != TYPE_CODE_PTR
961 && TYPE_CODE (type) != TYPE_CODE_REF)
963 type = TYPE_TARGET_TYPE (type);
966 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
967 TYPE_CODE (type) != TYPE_CODE_UNION)
969 target_terminal_ours ();
970 gdb_flush (gdb_stdout);
971 fprintf_unfiltered (gdb_stderr, "Type ");
972 type_print (type, "", gdb_stderr, -1);
973 error (" is not a structure or union type.");
977 /* FIXME: This change put in by Michael seems incorrect for the case where
978 the structure tag name is the same as the member name. I.E. when doing
979 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
984 typename = type_name_no_tag (type);
985 if (typename != NULL && STREQ (typename, name))
990 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
992 char *t_field_name = TYPE_FIELD_NAME (type, i);
994 if (t_field_name && STREQ (t_field_name, name))
996 return TYPE_FIELD_TYPE (type, i);
1000 /* OK, it's not in this class. Recursively check the baseclasses. */
1001 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1005 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1017 target_terminal_ours ();
1018 gdb_flush (gdb_stdout);
1019 fprintf_unfiltered (gdb_stderr, "Type ");
1020 type_print (type, "", gdb_stderr, -1);
1021 fprintf_unfiltered (gdb_stderr, " has no component named ");
1022 fputs_filtered (name, gdb_stderr);
1024 return (struct type *) -1; /* For lint */
1027 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1028 valid. Callers should be aware that in some cases (for example,
1029 the type or one of its baseclasses is a stub type and we are
1030 debugging a .o file), this function will not be able to find the virtual
1031 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1032 will remain NULL. */
1035 fill_in_vptr_fieldno (type)
1038 CHECK_TYPEDEF (type);
1040 if (TYPE_VPTR_FIELDNO (type) < 0)
1044 /* We must start at zero in case the first (and only) baseclass is
1045 virtual (and hence we cannot share the table pointer). */
1046 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1048 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
1049 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
1051 TYPE_VPTR_FIELDNO (type)
1052 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
1053 TYPE_VPTR_BASETYPE (type)
1054 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
1061 /* Find the method and field indices for the destructor in class type T.
1062 Return 1 if the destructor was found, otherwise, return 0. */
1065 get_destructor_fn_field (t, method_indexp, field_indexp)
1072 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1075 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1077 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1079 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j)))
1090 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1092 If this is a stubbed struct (i.e. declared as struct foo *), see if
1093 we can find a full definition in some other file. If so, copy this
1094 definition, so we can use it in future. There used to be a comment (but
1095 not any code) that if we don't find a full definition, we'd set a flag
1096 so we don't spend time in the future checking the same type. That would
1097 be a mistake, though--we might load in more symbols which contain a
1098 full definition for the type.
1100 This used to be coded as a macro, but I don't think it is called
1101 often enough to merit such treatment. */
1103 struct complaint stub_noname_complaint =
1104 {"stub type has NULL name", 0, 0};
1107 check_typedef (type)
1108 register struct type *type;
1110 struct type *orig_type = type;
1111 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1113 if (!TYPE_TARGET_TYPE (type))
1118 /* It is dangerous to call lookup_symbol if we are currently
1119 reading a symtab. Infinite recursion is one danger. */
1120 if (currently_reading_symtab)
1123 name = type_name_no_tag (type);
1124 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1125 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1126 as appropriate? (this code was written before TYPE_NAME and
1127 TYPE_TAG_NAME were separate). */
1130 complain (&stub_noname_complaint);
1133 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
1134 (struct symtab **) NULL);
1136 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1138 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1140 type = TYPE_TARGET_TYPE (type);
1143 /* If this is a struct/class/union with no fields, then check whether a
1144 full definition exists somewhere else. This is for systems where a
1145 type definition with no fields is issued for such types, instead of
1146 identifying them as stub types in the first place */
1148 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1150 char *name = type_name_no_tag (type);
1151 struct type *newtype;
1154 complain (&stub_noname_complaint);
1157 newtype = lookup_transparent_type (name);
1160 memcpy ((char *) type, (char *) newtype, sizeof (struct type));
1163 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1164 else if ((TYPE_FLAGS (type) & TYPE_FLAG_STUB) && !currently_reading_symtab)
1166 char *name = type_name_no_tag (type);
1167 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1168 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1169 as appropriate? (this code was written before TYPE_NAME and
1170 TYPE_TAG_NAME were separate). */
1174 complain (&stub_noname_complaint);
1177 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL);
1180 memcpy ((char *) type, (char *) SYMBOL_TYPE (sym), sizeof (struct type));
1184 if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB)
1186 struct type *range_type;
1187 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1189 if (TYPE_FLAGS (target_type) & (TYPE_FLAG_STUB | TYPE_FLAG_TARGET_STUB))
1192 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1193 && TYPE_NFIELDS (type) == 1
1194 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1195 == TYPE_CODE_RANGE))
1197 /* Now recompute the length of the array type, based on its
1198 number of elements and the target type's length. */
1199 TYPE_LENGTH (type) =
1200 ((TYPE_FIELD_BITPOS (range_type, 1)
1201 - TYPE_FIELD_BITPOS (range_type, 0)
1203 * TYPE_LENGTH (target_type));
1204 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1206 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1208 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1209 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1212 /* Cache TYPE_LENGTH for future use. */
1213 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1217 /* New code added to support parsing of Cfront stabs strings */
1219 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1220 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1223 add_name (pextras, n)
1224 struct extra *pextras;
1229 if ((nlen = (n ? strlen (n) : 0)) == 0)
1231 sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1232 pextras->len = strlen (pextras->str);
1236 add_mangled_type (pextras, t)
1237 struct extra *pextras;
1240 enum type_code tcode;
1244 tcode = TYPE_CODE (t);
1245 tlen = TYPE_LENGTH (t);
1246 tflags = TYPE_FLAGS (t);
1247 tname = TYPE_NAME (t);
1248 /* args of "..." seem to get mangled as "e" */
1266 if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1279 static struct complaint msg =
1280 {"Bad int type code length x%x\n", 0, 0};
1282 complain (&msg, tlen);
1301 static struct complaint msg =
1302 {"Bad float type code length x%x\n", 0, 0};
1303 complain (&msg, tlen);
1309 /* followed by what it's a ref to */
1313 /* followed by what it's a ptr to */
1315 case TYPE_CODE_TYPEDEF:
1317 static struct complaint msg =
1318 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1321 /* followed by type bytes & name */
1323 case TYPE_CODE_FUNC:
1325 /* followed by func's arg '_' & ret types */
1327 case TYPE_CODE_VOID:
1330 case TYPE_CODE_METHOD:
1332 /* followed by name of class and func's arg '_' & ret types */
1333 add_name (pextras, tname);
1334 ADD_EXTRA ('F'); /* then mangle function */
1336 case TYPE_CODE_STRUCT: /* C struct */
1337 case TYPE_CODE_UNION: /* C union */
1338 case TYPE_CODE_ENUM: /* Enumeration type */
1339 /* followed by name of type */
1340 add_name (pextras, tname);
1343 /* errors possible types/not supported */
1344 case TYPE_CODE_CHAR:
1345 case TYPE_CODE_ARRAY: /* Array type */
1346 case TYPE_CODE_MEMBER: /* Member type */
1347 case TYPE_CODE_BOOL:
1348 case TYPE_CODE_COMPLEX: /* Complex float */
1349 case TYPE_CODE_UNDEF:
1350 case TYPE_CODE_SET: /* Pascal sets */
1351 case TYPE_CODE_RANGE:
1352 case TYPE_CODE_STRING:
1353 case TYPE_CODE_BITSTRING:
1354 case TYPE_CODE_ERROR:
1357 static struct complaint msg =
1358 {"Unknown type code x%x\n", 0, 0};
1359 complain (&msg, tcode);
1363 add_mangled_type (pextras, t->target_type);
1368 cfront_mangle_name (type, i, j)
1374 char *mangled_name = gdb_mangle_name (type, i, j);
1376 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1378 /* kludge to support cfront methods - gdb expects to find "F" for
1379 ARM_mangled names, so when we mangle, we have to add it here */
1383 char *arm_mangled_name;
1384 struct fn_field *method = &f[j];
1385 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1386 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1387 char *newname = type_name_no_tag (type);
1389 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1390 int nargs = TYPE_NFIELDS (ftype); /* number of args */
1391 struct extra extras, *pextras = &extras;
1394 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1397 /* add args here! */
1398 if (nargs <= 1) /* no args besides this */
1402 for (k = 1; k < nargs; k++)
1405 t = TYPE_FIELD_TYPE (ftype, k);
1406 add_mangled_type (pextras, t);
1410 printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1411 arm_mangled_name = malloc (strlen (mangled_name) + extras.len);
1412 sprintf (arm_mangled_name, "%s%s", mangled_name, extras.str);
1413 free (mangled_name);
1414 mangled_name = arm_mangled_name;
1420 /* End of new code added to support parsing of Cfront stabs strings */
1422 /* Ugly hack to convert method stubs into method types.
1424 He ain't kiddin'. This demangles the name of the method into a string
1425 including argument types, parses out each argument type, generates
1426 a string casting a zero to that type, evaluates the string, and stuffs
1427 the resulting type into an argtype vector!!! Then it knows the type
1428 of the whole function (including argument types for overloading),
1429 which info used to be in the stab's but was removed to hack back
1430 the space required for them. */
1433 check_stub_method (type, method_id, signature_id)
1439 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1440 char *demangled_name = cplus_demangle (mangled_name,
1441 DMGL_PARAMS | DMGL_ANSI);
1442 char *argtypetext, *p;
1443 int depth = 0, argcount = 1;
1444 struct type **argtypes;
1447 /* Make sure we got back a function string that we can use. */
1449 p = strchr (demangled_name, '(');
1451 if (demangled_name == NULL || p == NULL)
1452 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1454 /* Now, read in the parameters that define this type. */
1467 else if (*p == ',' && depth == 0)
1475 /* We need two more slots: one for the THIS pointer, and one for the
1476 NULL [...] or void [end of arglist]. */
1478 argtypes = (struct type **)
1479 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
1481 /* FIXME: This is wrong for static member functions. */
1482 argtypes[0] = lookup_pointer_type (type);
1485 if (*p != ')') /* () means no args, skip while */
1490 if (depth <= 0 && (*p == ',' || *p == ')'))
1492 /* Avoid parsing of ellipsis, they will be handled below. */
1493 if (strncmp (argtypetext, "...", p - argtypetext) != 0)
1495 argtypes[argcount] =
1496 parse_and_eval_type (argtypetext, p - argtypetext);
1499 argtypetext = p + 1;
1515 if (p[-2] != '.') /* Not '...' */
1517 argtypes[argcount] = builtin_type_void; /* List terminator */
1521 argtypes[argcount] = NULL; /* Ellist terminator */
1524 free (demangled_name);
1526 f = TYPE_FN_FIELDLIST1 (type, method_id);
1528 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1530 /* Now update the old "stub" type into a real type. */
1531 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1532 TYPE_DOMAIN_TYPE (mtype) = type;
1533 TYPE_ARG_TYPES (mtype) = argtypes;
1534 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1535 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1538 const struct cplus_struct_type cplus_struct_default;
1541 allocate_cplus_struct_type (type)
1544 if (!HAVE_CPLUS_STRUCT (type))
1546 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1547 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1548 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1552 /* Helper function to initialize the standard scalar types.
1554 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1555 of the string pointed to by name in the type_obstack for that objfile,
1556 and initialize the type name to that copy. There are places (mipsread.c
1557 in particular, where init_type is called with a NULL value for NAME). */
1560 init_type (code, length, flags, name, objfile)
1561 enum type_code code;
1565 struct objfile *objfile;
1567 register struct type *type;
1569 type = alloc_type (objfile);
1570 TYPE_CODE (type) = code;
1571 TYPE_LENGTH (type) = length;
1572 TYPE_FLAGS (type) |= flags;
1573 if ((name != NULL) && (objfile != NULL))
1576 obsavestring (name, strlen (name), &objfile->type_obstack);
1580 TYPE_NAME (type) = name;
1585 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1587 INIT_CPLUS_SPECIFIC (type);
1592 /* Look up a fundamental type for the specified objfile.
1593 May need to construct such a type if this is the first use.
1595 Some object file formats (ELF, COFF, etc) do not define fundamental
1596 types such as "int" or "double". Others (stabs for example), do
1597 define fundamental types.
1599 For the formats which don't provide fundamental types, gdb can create
1600 such types, using defaults reasonable for the current language and
1601 the current target machine.
1603 NOTE: This routine is obsolescent. Each debugging format reader
1604 should manage it's own fundamental types, either creating them from
1605 suitable defaults or reading them from the debugging information,
1606 whichever is appropriate. The DWARF reader has already been
1607 fixed to do this. Once the other readers are fixed, this routine
1608 will go away. Also note that fundamental types should be managed
1609 on a compilation unit basis in a multi-language environment, not
1610 on a linkage unit basis as is done here. */
1614 lookup_fundamental_type (objfile, typeid)
1615 struct objfile *objfile;
1618 register struct type **typep;
1619 register int nbytes;
1621 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1623 error ("internal error - invalid fundamental type id %d", typeid);
1626 /* If this is the first time we need a fundamental type for this objfile
1627 then we need to initialize the vector of type pointers. */
1629 if (objfile->fundamental_types == NULL)
1631 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1632 objfile->fundamental_types = (struct type **)
1633 obstack_alloc (&objfile->type_obstack, nbytes);
1634 memset ((char *) objfile->fundamental_types, 0, nbytes);
1635 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1638 /* Look for this particular type in the fundamental type vector. If one is
1639 not found, create and install one appropriate for the current language. */
1641 typep = objfile->fundamental_types + typeid;
1644 *typep = create_fundamental_type (objfile, typeid);
1654 /* FIXME: Should we return true for references as well as pointers? */
1658 && TYPE_CODE (t) == TYPE_CODE_PTR
1659 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1663 is_integral_type (t)
1669 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1670 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1671 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1672 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1673 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1676 /* Chill varying string and arrays are represented as follows:
1678 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1680 Return true if TYPE is such a Chill varying type. */
1683 chill_varying_type (type)
1686 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1687 || TYPE_NFIELDS (type) != 2
1688 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1693 /* Check whether BASE is an ancestor or base class or DCLASS
1694 Return 1 if so, and 0 if not.
1695 Note: callers may want to check for identity of the types before
1696 calling this function -- identical types are considered to satisfy
1697 the ancestor relationship even if they're identical */
1700 is_ancestor (base, dclass)
1702 struct type *dclass;
1706 CHECK_TYPEDEF (base);
1707 CHECK_TYPEDEF (dclass);
1712 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1713 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1721 /* See whether DCLASS has a virtual table. This routine is aimed at
1722 the HP/Taligent ANSI C++ runtime model, and may not work with other
1723 runtime models. Return 1 => Yes, 0 => No. */
1727 struct type *dclass;
1729 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1730 has virtual functions or virtual bases. */
1734 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1737 /* First check for the presence of virtual bases */
1738 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1739 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1740 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1743 /* Next check for virtual functions */
1744 if (TYPE_FN_FIELDLISTS (dclass))
1745 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1746 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1749 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1750 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1751 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1752 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1753 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1756 /* Well, maybe we don't need a virtual table */
1760 /* Return a pointer to the "primary base class" of DCLASS.
1762 A NULL return indicates that DCLASS has no primary base, or that it
1763 couldn't be found (insufficient information).
1765 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1766 and may not work with other runtime models. */
1769 primary_base_class (dclass)
1770 struct type *dclass;
1772 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1773 is the first directly inherited, non-virtual base class that
1774 requires a virtual table */
1778 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1781 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1782 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1783 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1784 return TYPE_FIELD_TYPE (dclass, i);
1789 /* Global manipulated by virtual_base_list[_aux]() */
1791 static struct vbase *current_vbase_list = NULL;
1793 /* Return a pointer to a null-terminated list of struct vbase
1794 items. The vbasetype pointer of each item in the list points to the
1795 type information for a virtual base of the argument DCLASS.
1797 Helper function for virtual_base_list().
1798 Note: the list goes backward, right-to-left. virtual_base_list()
1799 copies the items out in reverse order. */
1802 virtual_base_list_aux (dclass)
1803 struct type *dclass;
1805 struct vbase *tmp_vbase;
1808 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1811 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1813 /* Recurse on this ancestor, first */
1814 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
1816 /* If this current base is itself virtual, add it to the list */
1817 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1819 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1821 /* Check if base already recorded */
1822 tmp_vbase = current_vbase_list;
1825 if (tmp_vbase->vbasetype == basetype)
1826 break; /* found it */
1827 tmp_vbase = tmp_vbase->next;
1830 if (!tmp_vbase) /* normal exit from loop */
1832 /* Allocate new item for this virtual base */
1833 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
1835 /* Stick it on at the end of the list */
1836 tmp_vbase->vbasetype = basetype;
1837 tmp_vbase->next = current_vbase_list;
1838 current_vbase_list = tmp_vbase;
1841 } /* for loop over bases */
1845 /* Compute the list of virtual bases in the right order. Virtual
1846 bases are laid out in the object's memory area in order of their
1847 occurrence in a depth-first, left-to-right search through the
1850 Argument DCLASS is the type whose virtual bases are required.
1851 Return value is the address of a null-terminated array of pointers
1852 to struct type items.
1854 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1855 and may not work with other runtime models.
1857 This routine merely hands off the argument to virtual_base_list_aux()
1858 and then copies the result into an array to save space. */
1861 virtual_base_list (dclass)
1862 struct type *dclass;
1864 register struct vbase *tmp_vbase;
1865 register struct vbase *tmp_vbase_2;
1868 struct type **vbase_array;
1870 current_vbase_list = NULL;
1871 virtual_base_list_aux (dclass);
1873 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1878 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
1880 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
1881 vbase_array[i] = tmp_vbase->vbasetype;
1883 /* Get rid of constructed chain */
1884 tmp_vbase_2 = tmp_vbase = current_vbase_list;
1887 tmp_vbase = tmp_vbase->next;
1889 tmp_vbase_2 = tmp_vbase;
1892 vbase_array[count] = NULL;
1896 /* Return the length of the virtual base list of the type DCLASS. */
1899 virtual_base_list_length (dclass)
1900 struct type *dclass;
1903 register struct vbase *tmp_vbase;
1905 current_vbase_list = NULL;
1906 virtual_base_list_aux (dclass);
1908 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1913 /* Return the number of elements of the virtual base list of the type
1914 DCLASS, ignoring those appearing in the primary base (and its
1915 primary base, recursively). */
1918 virtual_base_list_length_skip_primaries (dclass)
1919 struct type *dclass;
1922 register struct vbase *tmp_vbase;
1923 struct type *primary;
1925 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
1928 return virtual_base_list_length (dclass);
1930 current_vbase_list = NULL;
1931 virtual_base_list_aux (dclass);
1933 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
1935 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
1943 /* Return the index (position) of type BASE, which is a virtual base
1944 class of DCLASS, in the latter's virtual base list. A return of -1
1945 indicates "not found" or a problem. */
1948 virtual_base_index (base, dclass)
1950 struct type *dclass;
1952 register struct type *vbase;
1955 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
1956 (TYPE_CODE (base) != TYPE_CODE_CLASS))
1960 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0];
1965 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i];
1968 return vbase ? i : -1;
1973 /* Return the index (position) of type BASE, which is a virtual base
1974 class of DCLASS, in the latter's virtual base list. Skip over all
1975 bases that may appear in the virtual base list of the primary base
1976 class of DCLASS (recursively). A return of -1 indicates "not
1977 found" or a problem. */
1980 virtual_base_index_skip_primaries (base, dclass)
1982 struct type *dclass;
1984 register struct type *vbase;
1986 struct type *primary;
1988 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
1989 (TYPE_CODE (base) != TYPE_CODE_CLASS))
1992 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
1996 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0];
1999 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2003 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i];
2006 return vbase ? j : -1;
2009 /* Return position of a derived class DCLASS in the list of
2010 * primary bases starting with the remotest ancestor.
2011 * Position returned is 0-based. */
2014 class_index_in_primary_list (dclass)
2015 struct type *dclass;
2017 struct type *pbc; /* primary base class */
2019 /* Simply recurse on primary base */
2020 pbc = TYPE_PRIMARY_BASE (dclass);
2022 return 1 + class_index_in_primary_list (pbc);
2027 /* Return a count of the number of virtual functions a type has.
2028 * This includes all the virtual functions it inherits from its
2032 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2033 * functions only once (latest redefinition)
2037 count_virtual_fns (dclass)
2038 struct type *dclass;
2040 int fn, oi; /* function and overloaded instance indices */
2041 int vfuncs; /* count to return */
2043 /* recurse on bases that can share virtual table */
2044 struct type *pbc = primary_base_class (dclass);
2046 vfuncs = count_virtual_fns (pbc);
2048 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2049 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2050 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2058 /* Functions for overload resolution begin here */
2060 /* Compare two badness vectors A and B and return the result.
2061 * 0 => A and B are identical
2062 * 1 => A and B are incomparable
2063 * 2 => A is better than B
2064 * 3 => A is worse than B */
2067 compare_badness (a, b)
2068 struct badness_vector *a;
2069 struct badness_vector *b;
2073 short found_pos = 0; /* any positives in c? */
2074 short found_neg = 0; /* any negatives in c? */
2076 /* differing lengths => incomparable */
2077 if (a->length != b->length)
2080 /* Subtract b from a */
2081 for (i = 0; i < a->length; i++)
2083 tmp = a->rank[i] - b->rank[i];
2093 return 1; /* incomparable */
2095 return 3; /* A > B */
2101 return 2; /* A < B */
2103 return 0; /* A == B */
2107 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2108 * to the types of an argument list (ARGS, length NARGS).
2109 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2111 struct badness_vector *
2112 rank_function (parms, nparms, args, nargs)
2113 struct type **parms;
2119 struct badness_vector *bv;
2120 int min_len = nparms < nargs ? nparms : nargs;
2122 bv = xmalloc (sizeof (struct badness_vector));
2123 bv->length = nargs + 1; /* add 1 for the length-match rank */
2124 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2126 /* First compare the lengths of the supplied lists.
2127 * If there is a mismatch, set it to a high value. */
2129 /* pai/1997-06-03 FIXME: when we have debug info about default
2130 * arguments and ellipsis parameter lists, we should consider those
2131 * and rank the length-match more finely. */
2133 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2135 /* Now rank all the parameters of the candidate function */
2136 for (i = 1; i <= min_len; i++)
2137 bv->rank[i] = rank_one_type (parms[i - 1], args[i - 1]);
2139 /* If more arguments than parameters, add dummy entries */
2140 for (i = min_len + 1; i <= nargs; i++)
2141 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2146 /* Compare one type (PARM) for compatibility with another (ARG).
2147 * PARM is intended to be the parameter type of a function; and
2148 * ARG is the supplied argument's type. This function tests if
2149 * the latter can be converted to the former.
2151 * Return 0 if they are identical types;
2152 * Otherwise, return an integer which corresponds to how compatible
2153 * PARM is to ARG. The higher the return value, the worse the match.
2154 * Generally the "bad" conversions are all uniformly assigned a 100 */
2157 rank_one_type (parm, arg)
2161 /* Identical type pointers */
2162 /* However, this still doesn't catch all cases of same type for arg
2163 * and param. The reason is that builtin types are different from
2164 * the same ones constructed from the object. */
2168 /* Resolve typedefs */
2169 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2170 parm = check_typedef (parm);
2171 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2172 arg = check_typedef (arg);
2174 /* Check if identical after resolving typedefs */
2179 /* Debugging only */
2180 printf ("------ Arg is %s [%d], parm is %s [%d]\n",
2181 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2184 /* x -> y means arg of type x being supplied for parameter of type y */
2186 switch (TYPE_CODE (parm))
2189 switch (TYPE_CODE (arg))
2192 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2193 return VOID_PTR_CONVERSION_BADNESS;
2195 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2196 case TYPE_CODE_ARRAY:
2197 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2198 case TYPE_CODE_FUNC:
2199 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2201 case TYPE_CODE_ENUM:
2202 case TYPE_CODE_CHAR:
2203 case TYPE_CODE_RANGE:
2204 case TYPE_CODE_BOOL:
2205 return POINTER_CONVERSION_BADNESS;
2207 return INCOMPATIBLE_TYPE_BADNESS;
2209 case TYPE_CODE_ARRAY:
2210 switch (TYPE_CODE (arg))
2213 case TYPE_CODE_ARRAY:
2214 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2216 return INCOMPATIBLE_TYPE_BADNESS;
2218 case TYPE_CODE_FUNC:
2219 switch (TYPE_CODE (arg))
2221 case TYPE_CODE_PTR: /* funcptr -> func */
2222 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2224 return INCOMPATIBLE_TYPE_BADNESS;
2227 switch (TYPE_CODE (arg))
2230 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2232 /* Deal with signed, unsigned, and plain chars and
2233 signed and unsigned ints */
2234 if (TYPE_NOSIGN (parm))
2236 /* This case only for character types */
2237 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2240 return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */
2242 else if (TYPE_UNSIGNED (parm))
2244 if (TYPE_UNSIGNED (arg))
2246 if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2247 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2248 else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long"))
2249 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2251 return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
2255 if (!strcmp (TYPE_NAME (arg), "long") && !strcmp (TYPE_NAME (parm), "int"))
2256 return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
2258 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2261 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2263 if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2265 else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long"))
2266 return INTEGER_PROMOTION_BADNESS;
2268 return INTEGER_COERCION_BADNESS;
2271 return INTEGER_COERCION_BADNESS;
2273 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2274 return INTEGER_PROMOTION_BADNESS;
2276 return INTEGER_COERCION_BADNESS;
2277 case TYPE_CODE_ENUM:
2278 case TYPE_CODE_CHAR:
2279 case TYPE_CODE_RANGE:
2280 case TYPE_CODE_BOOL:
2281 return INTEGER_PROMOTION_BADNESS;
2283 return INT_FLOAT_CONVERSION_BADNESS;
2285 return NS_POINTER_CONVERSION_BADNESS;
2287 return INCOMPATIBLE_TYPE_BADNESS;
2290 case TYPE_CODE_ENUM:
2291 switch (TYPE_CODE (arg))
2294 case TYPE_CODE_CHAR:
2295 case TYPE_CODE_RANGE:
2296 case TYPE_CODE_BOOL:
2297 case TYPE_CODE_ENUM:
2298 return INTEGER_COERCION_BADNESS;
2300 return INT_FLOAT_CONVERSION_BADNESS;
2302 return INCOMPATIBLE_TYPE_BADNESS;
2305 case TYPE_CODE_CHAR:
2306 switch (TYPE_CODE (arg))
2308 case TYPE_CODE_RANGE:
2309 case TYPE_CODE_BOOL:
2310 case TYPE_CODE_ENUM:
2311 return INTEGER_COERCION_BADNESS;
2313 return INT_FLOAT_CONVERSION_BADNESS;
2315 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2316 return INTEGER_COERCION_BADNESS;
2317 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2318 return INTEGER_PROMOTION_BADNESS;
2319 /* >>> !! else fall through !! <<< */
2320 case TYPE_CODE_CHAR:
2321 /* Deal with signed, unsigned, and plain chars for C++
2322 and with int cases falling through from previous case */
2323 if (TYPE_NOSIGN (parm))
2325 if (TYPE_NOSIGN (arg))
2328 return INTEGER_COERCION_BADNESS;
2330 else if (TYPE_UNSIGNED (parm))
2332 if (TYPE_UNSIGNED (arg))
2335 return INTEGER_PROMOTION_BADNESS;
2337 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2340 return INTEGER_COERCION_BADNESS;
2342 return INCOMPATIBLE_TYPE_BADNESS;
2345 case TYPE_CODE_RANGE:
2346 switch (TYPE_CODE (arg))
2349 case TYPE_CODE_CHAR:
2350 case TYPE_CODE_RANGE:
2351 case TYPE_CODE_BOOL:
2352 case TYPE_CODE_ENUM:
2353 return INTEGER_COERCION_BADNESS;
2355 return INT_FLOAT_CONVERSION_BADNESS;
2357 return INCOMPATIBLE_TYPE_BADNESS;
2360 case TYPE_CODE_BOOL:
2361 switch (TYPE_CODE (arg))
2364 case TYPE_CODE_CHAR:
2365 case TYPE_CODE_RANGE:
2366 case TYPE_CODE_ENUM:
2369 return BOOLEAN_CONVERSION_BADNESS;
2370 case TYPE_CODE_BOOL:
2373 return INCOMPATIBLE_TYPE_BADNESS;
2377 switch (TYPE_CODE (arg))
2380 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2381 return FLOAT_PROMOTION_BADNESS;
2382 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2385 return FLOAT_CONVERSION_BADNESS;
2387 case TYPE_CODE_BOOL:
2388 case TYPE_CODE_ENUM:
2389 case TYPE_CODE_RANGE:
2390 case TYPE_CODE_CHAR:
2391 return INT_FLOAT_CONVERSION_BADNESS;
2393 return INCOMPATIBLE_TYPE_BADNESS;
2396 case TYPE_CODE_COMPLEX:
2397 switch (TYPE_CODE (arg))
2398 { /* Strictly not needed for C++, but... */
2400 return FLOAT_PROMOTION_BADNESS;
2401 case TYPE_CODE_COMPLEX:
2404 return INCOMPATIBLE_TYPE_BADNESS;
2407 case TYPE_CODE_STRUCT:
2408 /* currently same as TYPE_CODE_CLASS */
2409 switch (TYPE_CODE (arg))
2411 case TYPE_CODE_STRUCT:
2412 /* Check for derivation */
2413 if (is_ancestor (parm, arg))
2414 return BASE_CONVERSION_BADNESS;
2415 /* else fall through */
2417 return INCOMPATIBLE_TYPE_BADNESS;
2420 case TYPE_CODE_UNION:
2421 switch (TYPE_CODE (arg))
2423 case TYPE_CODE_UNION:
2425 return INCOMPATIBLE_TYPE_BADNESS;
2428 case TYPE_CODE_MEMBER:
2429 switch (TYPE_CODE (arg))
2432 return INCOMPATIBLE_TYPE_BADNESS;
2435 case TYPE_CODE_METHOD:
2436 switch (TYPE_CODE (arg))
2440 return INCOMPATIBLE_TYPE_BADNESS;
2444 switch (TYPE_CODE (arg))
2448 return INCOMPATIBLE_TYPE_BADNESS;
2453 switch (TYPE_CODE (arg))
2457 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2459 return INCOMPATIBLE_TYPE_BADNESS;
2462 case TYPE_CODE_VOID:
2464 return INCOMPATIBLE_TYPE_BADNESS;
2465 } /* switch (TYPE_CODE (arg)) */
2469 /* End of functions for overload resolution */
2472 print_bit_vector (bits, nbits)
2478 for (bitno = 0; bitno < nbits; bitno++)
2480 if ((bitno % 8) == 0)
2482 puts_filtered (" ");
2484 if (B_TST (bits, bitno))
2486 printf_filtered ("1");
2490 printf_filtered ("0");
2495 /* The args list is a strange beast. It is either terminated by a NULL
2496 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2497 type for normal fixed argcount functions. (FIXME someday)
2498 Also note the first arg should be the "this" pointer, we may not want to
2499 include it since we may get into a infinitely recursive situation. */
2502 print_arg_types (args, spaces)
2508 while (*args != NULL)
2510 recursive_dump_type (*args, spaces + 2);
2511 if ((*args++)->code == TYPE_CODE_VOID)
2520 dump_fn_fieldlists (type, spaces)
2528 printfi_filtered (spaces, "fn_fieldlists ");
2529 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2530 printf_filtered ("\n");
2531 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2533 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2534 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2536 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2537 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2539 printf_filtered (") length %d\n",
2540 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2541 for (overload_idx = 0;
2542 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2545 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2547 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2548 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2550 printf_filtered (")\n");
2551 printfi_filtered (spaces + 8, "type ");
2552 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2553 printf_filtered ("\n");
2555 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2558 printfi_filtered (spaces + 8, "args ");
2559 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2560 printf_filtered ("\n");
2562 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
2563 printfi_filtered (spaces + 8, "fcontext ");
2564 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2566 printf_filtered ("\n");
2568 printfi_filtered (spaces + 8, "is_const %d\n",
2569 TYPE_FN_FIELD_CONST (f, overload_idx));
2570 printfi_filtered (spaces + 8, "is_volatile %d\n",
2571 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2572 printfi_filtered (spaces + 8, "is_private %d\n",
2573 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2574 printfi_filtered (spaces + 8, "is_protected %d\n",
2575 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2576 printfi_filtered (spaces + 8, "is_stub %d\n",
2577 TYPE_FN_FIELD_STUB (f, overload_idx));
2578 printfi_filtered (spaces + 8, "voffset %u\n",
2579 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2585 print_cplus_stuff (type, spaces)
2589 printfi_filtered (spaces, "n_baseclasses %d\n",
2590 TYPE_N_BASECLASSES (type));
2591 printfi_filtered (spaces, "nfn_fields %d\n",
2592 TYPE_NFN_FIELDS (type));
2593 printfi_filtered (spaces, "nfn_fields_total %d\n",
2594 TYPE_NFN_FIELDS_TOTAL (type));
2595 if (TYPE_N_BASECLASSES (type) > 0)
2597 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2598 TYPE_N_BASECLASSES (type));
2599 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2600 printf_filtered (")");
2602 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2603 TYPE_N_BASECLASSES (type));
2604 puts_filtered ("\n");
2606 if (TYPE_NFIELDS (type) > 0)
2608 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2610 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2611 TYPE_NFIELDS (type));
2612 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2613 printf_filtered (")");
2614 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2615 TYPE_NFIELDS (type));
2616 puts_filtered ("\n");
2618 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2620 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2621 TYPE_NFIELDS (type));
2622 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2623 printf_filtered (")");
2624 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2625 TYPE_NFIELDS (type));
2626 puts_filtered ("\n");
2629 if (TYPE_NFN_FIELDS (type) > 0)
2631 dump_fn_fieldlists (type, spaces);
2635 static struct obstack dont_print_type_obstack;
2638 recursive_dump_type (type, spaces)
2645 obstack_begin (&dont_print_type_obstack, 0);
2647 if (TYPE_NFIELDS (type) > 0
2648 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2650 struct type **first_dont_print
2651 = (struct type **) obstack_base (&dont_print_type_obstack);
2653 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2658 if (type == first_dont_print[i])
2660 printfi_filtered (spaces, "type node ");
2661 gdb_print_host_address (type, gdb_stdout);
2662 printf_filtered (" <same as already seen type>\n");
2667 obstack_ptr_grow (&dont_print_type_obstack, type);
2670 printfi_filtered (spaces, "type node ");
2671 gdb_print_host_address (type, gdb_stdout);
2672 printf_filtered ("\n");
2673 printfi_filtered (spaces, "name '%s' (",
2674 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2675 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2676 printf_filtered (")\n");
2677 if (TYPE_TAG_NAME (type) != NULL)
2679 printfi_filtered (spaces, "tagname '%s' (",
2680 TYPE_TAG_NAME (type));
2681 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2682 printf_filtered (")\n");
2684 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2685 switch (TYPE_CODE (type))
2687 case TYPE_CODE_UNDEF:
2688 printf_filtered ("(TYPE_CODE_UNDEF)");
2691 printf_filtered ("(TYPE_CODE_PTR)");
2693 case TYPE_CODE_ARRAY:
2694 printf_filtered ("(TYPE_CODE_ARRAY)");
2696 case TYPE_CODE_STRUCT:
2697 printf_filtered ("(TYPE_CODE_STRUCT)");
2699 case TYPE_CODE_UNION:
2700 printf_filtered ("(TYPE_CODE_UNION)");
2702 case TYPE_CODE_ENUM:
2703 printf_filtered ("(TYPE_CODE_ENUM)");
2705 case TYPE_CODE_FUNC:
2706 printf_filtered ("(TYPE_CODE_FUNC)");
2709 printf_filtered ("(TYPE_CODE_INT)");
2712 printf_filtered ("(TYPE_CODE_FLT)");
2714 case TYPE_CODE_VOID:
2715 printf_filtered ("(TYPE_CODE_VOID)");
2718 printf_filtered ("(TYPE_CODE_SET)");
2720 case TYPE_CODE_RANGE:
2721 printf_filtered ("(TYPE_CODE_RANGE)");
2723 case TYPE_CODE_STRING:
2724 printf_filtered ("(TYPE_CODE_STRING)");
2726 case TYPE_CODE_ERROR:
2727 printf_filtered ("(TYPE_CODE_ERROR)");
2729 case TYPE_CODE_MEMBER:
2730 printf_filtered ("(TYPE_CODE_MEMBER)");
2732 case TYPE_CODE_METHOD:
2733 printf_filtered ("(TYPE_CODE_METHOD)");
2736 printf_filtered ("(TYPE_CODE_REF)");
2738 case TYPE_CODE_CHAR:
2739 printf_filtered ("(TYPE_CODE_CHAR)");
2741 case TYPE_CODE_BOOL:
2742 printf_filtered ("(TYPE_CODE_BOOL)");
2744 case TYPE_CODE_TYPEDEF:
2745 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2748 printf_filtered ("(UNKNOWN TYPE CODE)");
2751 puts_filtered ("\n");
2752 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2753 printfi_filtered (spaces, "objfile ");
2754 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2755 printf_filtered ("\n");
2756 printfi_filtered (spaces, "target_type ");
2757 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2758 printf_filtered ("\n");
2759 if (TYPE_TARGET_TYPE (type) != NULL)
2761 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2763 printfi_filtered (spaces, "pointer_type ");
2764 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2765 printf_filtered ("\n");
2766 printfi_filtered (spaces, "reference_type ");
2767 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2768 printf_filtered ("\n");
2769 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
2770 if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED)
2772 puts_filtered (" TYPE_FLAG_UNSIGNED");
2774 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
2776 puts_filtered (" TYPE_FLAG_STUB");
2778 puts_filtered ("\n");
2779 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
2780 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
2781 puts_filtered ("\n");
2782 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
2784 printfi_filtered (spaces + 2,
2785 "[%d] bitpos %d bitsize %d type ",
2786 idx, TYPE_FIELD_BITPOS (type, idx),
2787 TYPE_FIELD_BITSIZE (type, idx));
2788 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
2789 printf_filtered (" name '%s' (",
2790 TYPE_FIELD_NAME (type, idx) != NULL
2791 ? TYPE_FIELD_NAME (type, idx)
2793 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
2794 printf_filtered (")\n");
2795 if (TYPE_FIELD_TYPE (type, idx) != NULL)
2797 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
2800 printfi_filtered (spaces, "vptr_basetype ");
2801 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
2802 puts_filtered ("\n");
2803 if (TYPE_VPTR_BASETYPE (type) != NULL)
2805 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
2807 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
2808 switch (TYPE_CODE (type))
2810 case TYPE_CODE_METHOD:
2811 case TYPE_CODE_FUNC:
2812 printfi_filtered (spaces, "arg_types ");
2813 gdb_print_host_address (TYPE_ARG_TYPES (type), gdb_stdout);
2814 puts_filtered ("\n");
2815 print_arg_types (TYPE_ARG_TYPES (type), spaces);
2818 case TYPE_CODE_STRUCT:
2819 printfi_filtered (spaces, "cplus_stuff ");
2820 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2821 puts_filtered ("\n");
2822 print_cplus_stuff (type, spaces);
2826 /* We have to pick one of the union types to be able print and test
2827 the value. Pick cplus_struct_type, even though we know it isn't
2828 any particular one. */
2829 printfi_filtered (spaces, "type_specific ");
2830 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2831 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
2833 printf_filtered (" (unknown data form)");
2835 printf_filtered ("\n");
2840 obstack_free (&dont_print_type_obstack, NULL);
2843 static void build_gdbtypes PARAMS ((void));
2848 init_type (TYPE_CODE_VOID, 1,
2850 "void", (struct objfile *) NULL);
2852 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2854 "char", (struct objfile *) NULL);
2855 TYPE_FLAGS (builtin_type_char) |= TYPE_FLAG_NOSIGN;
2856 builtin_type_true_char =
2857 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2859 "true character", (struct objfile *) NULL);
2860 builtin_type_signed_char =
2861 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2863 "signed char", (struct objfile *) NULL);
2864 builtin_type_unsigned_char =
2865 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2867 "unsigned char", (struct objfile *) NULL);
2868 builtin_type_short =
2869 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
2871 "short", (struct objfile *) NULL);
2872 builtin_type_unsigned_short =
2873 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
2875 "unsigned short", (struct objfile *) NULL);
2877 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
2879 "int", (struct objfile *) NULL);
2880 builtin_type_unsigned_int =
2881 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
2883 "unsigned int", (struct objfile *) NULL);
2885 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
2887 "long", (struct objfile *) NULL);
2888 builtin_type_unsigned_long =
2889 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
2891 "unsigned long", (struct objfile *) NULL);
2892 builtin_type_long_long =
2893 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2895 "long long", (struct objfile *) NULL);
2896 builtin_type_unsigned_long_long =
2897 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2899 "unsigned long long", (struct objfile *) NULL);
2900 builtin_type_float =
2901 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
2903 "float", (struct objfile *) NULL);
2904 builtin_type_double =
2905 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
2907 "double", (struct objfile *) NULL);
2908 builtin_type_long_double =
2909 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
2911 "long double", (struct objfile *) NULL);
2912 builtin_type_complex =
2913 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
2915 "complex", (struct objfile *) NULL);
2916 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
2917 builtin_type_double_complex =
2918 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
2920 "double complex", (struct objfile *) NULL);
2921 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
2922 builtin_type_string =
2923 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2925 "string", (struct objfile *) NULL);
2927 init_type (TYPE_CODE_INT, 8 / 8,
2929 "int8_t", (struct objfile *) NULL);
2930 builtin_type_uint8 =
2931 init_type (TYPE_CODE_INT, 8 / 8,
2933 "uint8_t", (struct objfile *) NULL);
2934 builtin_type_int16 =
2935 init_type (TYPE_CODE_INT, 16 / 8,
2937 "int16_t", (struct objfile *) NULL);
2938 builtin_type_uint16 =
2939 init_type (TYPE_CODE_INT, 16 / 8,
2941 "uint16_t", (struct objfile *) NULL);
2942 builtin_type_int32 =
2943 init_type (TYPE_CODE_INT, 32 / 8,
2945 "int32_t", (struct objfile *) NULL);
2946 builtin_type_uint32 =
2947 init_type (TYPE_CODE_INT, 32 / 8,
2949 "uint32_t", (struct objfile *) NULL);
2950 builtin_type_int64 =
2951 init_type (TYPE_CODE_INT, 64 / 8,
2953 "int64_t", (struct objfile *) NULL);
2954 builtin_type_uint64 =
2955 init_type (TYPE_CODE_INT, 64 / 8,
2957 "uint64_t", (struct objfile *) NULL);
2959 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2961 "bool", (struct objfile *) NULL);
2963 /* Add user knob for controlling resolution of opaque types */
2965 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
2966 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
2969 opaque_type_resolution = 1;
2972 /* Build SIMD types. */
2974 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
2976 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
2978 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
2980 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
2982 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
2986 extern void _initialize_gdbtypes PARAMS ((void));
2988 _initialize_gdbtypes ()
2992 /* FIXME - For the moment, handle types by swapping them in and out.
2993 Should be using the per-architecture data-pointer and a large
2995 register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL);
2996 register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL);
2997 register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL);
2998 register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL);
2999 register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL);
3000 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL);
3001 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL);
3002 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL);
3003 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL);
3004 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL);
3005 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL);
3006 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL);
3007 register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL);
3008 register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL);
3009 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL);
3010 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL);
3011 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL);
3012 register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL);
3013 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL);
3014 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL);
3015 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL);
3016 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL);
3017 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL);
3018 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
3019 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
3020 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
3021 register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
3022 register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL);
3023 register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL);
3024 register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
3025 register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
3026 register_gdbarch_swap (NULL, 0, build_gdbtypes);