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;
70 int opaque_type_resolution = 1;
77 }; /* maximum extention is 128! FIXME */
79 static void add_name PARAMS ((struct extra *, char *));
80 static void add_mangled_type PARAMS ((struct extra *, struct type *));
82 static void cfront_mangle_name PARAMS ((struct type *, int, int));
84 static void print_bit_vector PARAMS ((B_TYPE *, int));
85 static void print_arg_types PARAMS ((struct type **, int));
86 static void dump_fn_fieldlists PARAMS ((struct type *, int));
87 static void print_cplus_stuff PARAMS ((struct type *, int));
88 static void virtual_base_list_aux PARAMS ((struct type * dclass));
91 /* Alloc a new type structure and fill it with some defaults. If
92 OBJFILE is non-NULL, then allocate the space for the type structure
93 in that objfile's type_obstack. */
97 struct objfile *objfile;
99 register struct type *type;
101 /* Alloc the structure and start off with all fields zeroed. */
105 type = (struct type *) xmalloc (sizeof (struct type));
109 type = (struct type *) obstack_alloc (&objfile->type_obstack,
110 sizeof (struct type));
111 OBJSTAT (objfile, n_types++);
113 memset ((char *) type, 0, sizeof (struct type));
115 /* Initialize the fields that might not be zero. */
117 TYPE_CODE (type) = TYPE_CODE_UNDEF;
118 TYPE_OBJFILE (type) = objfile;
119 TYPE_VPTR_FIELDNO (type) = -1;
120 TYPE_CV_TYPE (type) = type; /* chain back to itself */
125 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
126 to a pointer to memory where the pointer type should be stored.
127 If *TYPEPTR is zero, update it to point to the pointer type we return.
128 We allocate new memory if needed. */
131 make_pointer_type (type, typeptr)
133 struct type **typeptr;
135 register struct type *ntype; /* New type */
136 struct objfile *objfile;
138 ntype = TYPE_POINTER_TYPE (type);
143 return ntype; /* Don't care about alloc, and have new type. */
144 else if (*typeptr == 0)
146 *typeptr = ntype; /* Tracking alloc, and we have new type. */
151 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
153 ntype = alloc_type (TYPE_OBJFILE (type));
158 /* We have storage, but need to reset it. */
161 objfile = TYPE_OBJFILE (ntype);
162 memset ((char *) ntype, 0, sizeof (struct type));
163 TYPE_OBJFILE (ntype) = objfile;
166 TYPE_TARGET_TYPE (ntype) = type;
167 TYPE_POINTER_TYPE (type) = ntype;
169 /* FIXME! Assume the machine has only one representation for pointers! */
171 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
172 TYPE_CODE (ntype) = TYPE_CODE_PTR;
174 /* pointers are unsigned */
175 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
177 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
178 TYPE_POINTER_TYPE (type) = ntype;
183 /* Given a type TYPE, return a type of pointers to that type.
184 May need to construct such a type if this is the first use. */
187 lookup_pointer_type (type)
190 return make_pointer_type (type, (struct type **) 0);
193 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
194 to a pointer to memory where the reference type should be stored.
195 If *TYPEPTR is zero, update it to point to the reference type we return.
196 We allocate new memory if needed. */
199 make_reference_type (type, typeptr)
201 struct type **typeptr;
203 register struct type *ntype; /* New type */
204 struct objfile *objfile;
206 ntype = TYPE_REFERENCE_TYPE (type);
211 return ntype; /* Don't care about alloc, and have new type. */
212 else if (*typeptr == 0)
214 *typeptr = ntype; /* Tracking alloc, and we have new type. */
219 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
221 ntype = alloc_type (TYPE_OBJFILE (type));
226 /* We have storage, but need to reset it. */
229 objfile = TYPE_OBJFILE (ntype);
230 memset ((char *) ntype, 0, sizeof (struct type));
231 TYPE_OBJFILE (ntype) = objfile;
234 TYPE_TARGET_TYPE (ntype) = type;
235 TYPE_REFERENCE_TYPE (type) = ntype;
237 /* FIXME! Assume the machine has only one representation for references,
238 and that it matches the (only) representation for pointers! */
240 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
241 TYPE_CODE (ntype) = TYPE_CODE_REF;
243 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
244 TYPE_REFERENCE_TYPE (type) = ntype;
249 /* Same as above, but caller doesn't care about memory allocation details. */
252 lookup_reference_type (type)
255 return make_reference_type (type, (struct type **) 0);
258 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
259 to a pointer to memory where the function type should be stored.
260 If *TYPEPTR is zero, update it to point to the function type we return.
261 We allocate new memory if needed. */
264 make_function_type (type, typeptr)
266 struct type **typeptr;
268 register struct type *ntype; /* New type */
269 struct objfile *objfile;
271 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
273 ntype = alloc_type (TYPE_OBJFILE (type));
278 /* We have storage, but need to reset it. */
281 objfile = TYPE_OBJFILE (ntype);
282 memset ((char *) ntype, 0, sizeof (struct type));
283 TYPE_OBJFILE (ntype) = objfile;
286 TYPE_TARGET_TYPE (ntype) = type;
288 TYPE_LENGTH (ntype) = 1;
289 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
295 /* Given a type TYPE, return a type of functions that return that type.
296 May need to construct such a type if this is the first use. */
299 lookup_function_type (type)
302 return make_function_type (type, (struct type **) 0);
306 /* Make a "c-v" variant of a type -- a type that is identical to the
307 one supplied except that it may have const or volatile attributes
308 CNST is a flag for setting the const attribute
309 VOLTL is a flag for setting the volatile attribute
310 TYPE is the base type whose variant we are creating.
311 TYPEPTR, if nonzero, points
312 to a pointer to memory where the reference type should be stored.
313 If *TYPEPTR is zero, update it to point to the reference type we return.
314 We allocate new memory if needed. */
317 make_cv_type (cnst, voltl, type, typeptr)
321 struct type **typeptr;
323 register struct type *ntype; /* New type */
324 register struct type *tmp_type = type; /* tmp type */
325 struct objfile *objfile;
327 ntype = TYPE_CV_TYPE (type);
329 while (ntype != type)
331 if ((TYPE_CONST (ntype) == cnst) &&
332 (TYPE_VOLATILE (ntype) == voltl))
336 else if (*typeptr == 0)
338 *typeptr = ntype; /* Tracking alloc, and we have new type. */
343 ntype = TYPE_CV_TYPE (ntype);
346 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
348 ntype = alloc_type (TYPE_OBJFILE (type));
353 /* We have storage, but need to reset it. */
356 objfile = TYPE_OBJFILE (ntype);
357 /* memset ((char *) ntype, 0, sizeof (struct type)); */
358 TYPE_OBJFILE (ntype) = objfile;
361 /* Copy original type */
362 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
363 /* But zero out fields that shouldn't be copied */
364 TYPE_POINTER_TYPE (ntype) = (struct type *) 0; /* Need new pointer kind */
365 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; /* Need new referene kind */
366 /* Note: TYPE_TARGET_TYPE can be left as is */
368 /* Set flags appropriately */
370 TYPE_FLAGS (ntype) |= TYPE_FLAG_CONST;
372 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_CONST;
375 TYPE_FLAGS (ntype) |= TYPE_FLAG_VOLATILE;
377 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_VOLATILE;
379 /* Fix the chain of cv variants */
380 TYPE_CV_TYPE (ntype) = type;
381 TYPE_CV_TYPE (tmp_type) = ntype;
389 /* Implement direct support for MEMBER_TYPE in GNU C++.
390 May need to construct such a type if this is the first use.
391 The TYPE is the type of the member. The DOMAIN is the type
392 of the aggregate that the member belongs to. */
395 lookup_member_type (type, domain)
399 register struct type *mtype;
401 mtype = alloc_type (TYPE_OBJFILE (type));
402 smash_to_member_type (mtype, domain, type);
406 /* Allocate a stub method whose return type is TYPE.
407 This apparently happens for speed of symbol reading, since parsing
408 out the arguments to the method is cpu-intensive, the way we are doing
409 it. So, we will fill in arguments later.
410 This always returns a fresh type. */
413 allocate_stub_method (type)
418 mtype = alloc_type (TYPE_OBJFILE (type));
419 TYPE_TARGET_TYPE (mtype) = type;
420 /* _DOMAIN_TYPE (mtype) = unknown yet */
421 /* _ARG_TYPES (mtype) = unknown yet */
422 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
423 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
424 TYPE_LENGTH (mtype) = 1;
428 /* Create a range type using either a blank type supplied in RESULT_TYPE,
429 or creating a new type, inheriting the objfile from INDEX_TYPE.
431 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
432 HIGH_BOUND, inclusive.
434 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
435 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
438 create_range_type (result_type, index_type, low_bound, high_bound)
439 struct type *result_type;
440 struct type *index_type;
444 if (result_type == NULL)
446 result_type = alloc_type (TYPE_OBJFILE (index_type));
448 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
449 TYPE_TARGET_TYPE (result_type) = index_type;
450 if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB)
451 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
453 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
454 TYPE_NFIELDS (result_type) = 2;
455 TYPE_FIELDS (result_type) = (struct field *)
456 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
457 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
458 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
459 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
460 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
461 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
464 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
466 return (result_type);
469 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
470 Return 1 of type is a range type, 0 if it is discrete (and bounds
471 will fit in LONGEST), or -1 otherwise. */
474 get_discrete_bounds (type, lowp, highp)
476 LONGEST *lowp, *highp;
478 CHECK_TYPEDEF (type);
479 switch (TYPE_CODE (type))
481 case TYPE_CODE_RANGE:
482 *lowp = TYPE_LOW_BOUND (type);
483 *highp = TYPE_HIGH_BOUND (type);
486 if (TYPE_NFIELDS (type) > 0)
488 /* The enums may not be sorted by value, so search all
492 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
493 for (i = 0; i < TYPE_NFIELDS (type); i++)
495 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
496 *lowp = TYPE_FIELD_BITPOS (type, i);
497 if (TYPE_FIELD_BITPOS (type, i) > *highp)
498 *highp = TYPE_FIELD_BITPOS (type, i);
501 /* Set unsigned indicator if warranted. */
504 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
518 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
520 if (!TYPE_UNSIGNED (type))
522 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
526 /* ... fall through for unsigned ints ... */
529 /* This round-about calculation is to avoid shifting by
530 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
531 if TYPE_LENGTH (type) == sizeof (LONGEST). */
532 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
533 *highp = (*highp - 1) | *highp;
540 /* Create an array type using either a blank type supplied in RESULT_TYPE,
541 or creating a new type, inheriting the objfile from RANGE_TYPE.
543 Elements will be of type ELEMENT_TYPE, the indices will be of type
546 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
547 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
550 create_array_type (result_type, element_type, range_type)
551 struct type *result_type;
552 struct type *element_type;
553 struct type *range_type;
555 LONGEST low_bound, high_bound;
557 if (result_type == NULL)
559 result_type = alloc_type (TYPE_OBJFILE (range_type));
561 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
562 TYPE_TARGET_TYPE (result_type) = element_type;
563 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
564 low_bound = high_bound = 0;
565 CHECK_TYPEDEF (element_type);
566 TYPE_LENGTH (result_type) =
567 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
568 TYPE_NFIELDS (result_type) = 1;
569 TYPE_FIELDS (result_type) =
570 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
571 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
572 TYPE_FIELD_TYPE (result_type, 0) = range_type;
573 TYPE_VPTR_FIELDNO (result_type) = -1;
575 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
576 if (TYPE_LENGTH (result_type) == 0)
577 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
579 return (result_type);
582 /* Create a string type using either a blank type supplied in RESULT_TYPE,
583 or creating a new type. String types are similar enough to array of
584 char types that we can use create_array_type to build the basic type
585 and then bash it into a string type.
587 For fixed length strings, the range type contains 0 as the lower
588 bound and the length of the string minus one as the upper bound.
590 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
591 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
594 create_string_type (result_type, range_type)
595 struct type *result_type;
596 struct type *range_type;
598 result_type = create_array_type (result_type,
599 *current_language->string_char_type,
601 TYPE_CODE (result_type) = TYPE_CODE_STRING;
602 return (result_type);
606 create_set_type (result_type, domain_type)
607 struct type *result_type;
608 struct type *domain_type;
610 LONGEST low_bound, high_bound, bit_length;
611 if (result_type == NULL)
613 result_type = alloc_type (TYPE_OBJFILE (domain_type));
615 TYPE_CODE (result_type) = TYPE_CODE_SET;
616 TYPE_NFIELDS (result_type) = 1;
617 TYPE_FIELDS (result_type) = (struct field *)
618 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
619 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
621 if (!(TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB))
623 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
624 low_bound = high_bound = 0;
625 bit_length = high_bound - low_bound + 1;
626 TYPE_LENGTH (result_type)
627 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
629 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
632 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
634 return (result_type);
638 /* Construct and return a type of the form:
639 struct NAME { ELT_TYPE ELT_NAME[N]; }
640 We use these types for SIMD registers. For example, the type of
641 the SSE registers on the late x86-family processors is:
642 struct __builtin_v4sf { float f[4]; }
643 built by the function call:
644 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
645 The type returned is a permanent type, allocated using malloc; it
646 doesn't live in any objfile's obstack. */
648 init_simd_type (char *name,
649 struct type *elt_type,
656 /* Build the field structure. */
657 f = xmalloc (sizeof (*f));
658 memset (f, 0, sizeof (*f));
660 f->type = create_array_type (0, elt_type,
661 create_range_type (0, builtin_type_int, 0, n));
664 /* Build a struct type with that field. */
665 t = init_type (TYPE_CODE_STRUCT, n * TYPE_LENGTH (elt_type), 0, 0, 0);
674 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
675 A MEMBER is a wierd thing -- it amounts to a typed offset into
676 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
677 include the offset (that's the value of the MEMBER itself), but does
678 include the structure type into which it points (for some reason).
680 When "smashing" the type, we preserve the objfile that the
681 old type pointed to, since we aren't changing where the type is actually
685 smash_to_member_type (type, domain, to_type)
688 struct type *to_type;
690 struct objfile *objfile;
692 objfile = TYPE_OBJFILE (type);
694 memset ((char *) type, 0, sizeof (struct type));
695 TYPE_OBJFILE (type) = objfile;
696 TYPE_TARGET_TYPE (type) = to_type;
697 TYPE_DOMAIN_TYPE (type) = domain;
698 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
699 TYPE_CODE (type) = TYPE_CODE_MEMBER;
702 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
703 METHOD just means `function that gets an extra "this" argument'.
705 When "smashing" the type, we preserve the objfile that the
706 old type pointed to, since we aren't changing where the type is actually
710 smash_to_method_type (type, domain, to_type, args)
713 struct type *to_type;
716 struct objfile *objfile;
718 objfile = TYPE_OBJFILE (type);
720 memset ((char *) type, 0, sizeof (struct type));
721 TYPE_OBJFILE (type) = objfile;
722 TYPE_TARGET_TYPE (type) = to_type;
723 TYPE_DOMAIN_TYPE (type) = domain;
724 TYPE_ARG_TYPES (type) = args;
725 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
726 TYPE_CODE (type) = TYPE_CODE_METHOD;
729 /* Return a typename for a struct/union/enum type without "struct ",
730 "union ", or "enum ". If the type has a NULL name, return NULL. */
733 type_name_no_tag (type)
734 register const struct type *type;
736 if (TYPE_TAG_NAME (type) != NULL)
737 return TYPE_TAG_NAME (type);
739 /* Is there code which expects this to return the name if there is no
740 tag name? My guess is that this is mainly used for C++ in cases where
741 the two will always be the same. */
742 return TYPE_NAME (type);
745 /* Lookup a primitive type named NAME.
746 Return zero if NAME is not a primitive type. */
749 lookup_primitive_typename (name)
752 struct type **const *p;
754 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
756 if (STREQ ((**p)->name, name))
764 /* Lookup a typedef or primitive type named NAME,
765 visible in lexical block BLOCK.
766 If NOERR is nonzero, return zero if NAME is not suitably defined. */
769 lookup_typename (name, block, noerr)
774 register struct symbol *sym;
775 register struct type *tmp;
777 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
778 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
780 tmp = lookup_primitive_typename (name);
785 else if (!tmp && noerr)
791 error ("No type named %s.", name);
794 return (SYMBOL_TYPE (sym));
798 lookup_unsigned_typename (name)
801 char *uns = alloca (strlen (name) + 10);
803 strcpy (uns, "unsigned ");
804 strcpy (uns + 9, name);
805 return (lookup_typename (uns, (struct block *) NULL, 0));
809 lookup_signed_typename (name)
813 char *uns = alloca (strlen (name) + 8);
815 strcpy (uns, "signed ");
816 strcpy (uns + 7, name);
817 t = lookup_typename (uns, (struct block *) NULL, 1);
818 /* If we don't find "signed FOO" just try again with plain "FOO". */
821 return lookup_typename (name, (struct block *) NULL, 0);
824 /* Lookup a structure type named "struct NAME",
825 visible in lexical block BLOCK. */
828 lookup_struct (name, block)
832 register struct symbol *sym;
834 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
835 (struct symtab **) NULL);
839 error ("No struct type named %s.", name);
841 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
843 error ("This context has class, union or enum %s, not a struct.", name);
845 return (SYMBOL_TYPE (sym));
848 /* Lookup a union type named "union NAME",
849 visible in lexical block BLOCK. */
852 lookup_union (name, block)
856 register struct symbol *sym;
859 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
860 (struct symtab **) NULL);
863 error ("No union type named %s.", name);
865 t = SYMBOL_TYPE (sym);
867 if (TYPE_CODE (t) == TYPE_CODE_UNION)
870 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
871 * a further "declared_type" field to discover it is really a union.
873 if (HAVE_CPLUS_STRUCT (t))
874 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
877 /* If we get here, it's not a union */
878 error ("This context has class, struct or enum %s, not a union.", name);
882 /* Lookup an enum type named "enum NAME",
883 visible in lexical block BLOCK. */
886 lookup_enum (name, block)
890 register struct symbol *sym;
892 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
893 (struct symtab **) NULL);
896 error ("No enum type named %s.", name);
898 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
900 error ("This context has class, struct or union %s, not an enum.", name);
902 return (SYMBOL_TYPE (sym));
905 /* Lookup a template type named "template NAME<TYPE>",
906 visible in lexical block BLOCK. */
909 lookup_template_type (name, type, block)
915 char *nam = (char *) alloca (strlen (name) + strlen (type->name) + 4);
918 strcat (nam, type->name);
919 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
921 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
925 error ("No template type named %s.", name);
927 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
929 error ("This context has class, union or enum %s, not a struct.", name);
931 return (SYMBOL_TYPE (sym));
934 /* Given a type TYPE, lookup the type of the component of type named NAME.
936 TYPE can be either a struct or union, or a pointer or reference to a struct or
937 union. If it is a pointer or reference, its target type is automatically used.
938 Thus '.' and '->' are interchangable, as specified for the definitions of the
939 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
941 If NOERR is nonzero, return zero if NAME is not suitably defined.
942 If NAME is the name of a baseclass type, return that type. */
945 lookup_struct_elt_type (type, name, noerr)
954 CHECK_TYPEDEF (type);
955 if (TYPE_CODE (type) != TYPE_CODE_PTR
956 && TYPE_CODE (type) != TYPE_CODE_REF)
958 type = TYPE_TARGET_TYPE (type);
961 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
962 TYPE_CODE (type) != TYPE_CODE_UNION)
964 target_terminal_ours ();
965 gdb_flush (gdb_stdout);
966 fprintf_unfiltered (gdb_stderr, "Type ");
967 type_print (type, "", gdb_stderr, -1);
968 error (" is not a structure or union type.");
972 /* FIXME: This change put in by Michael seems incorrect for the case where
973 the structure tag name is the same as the member name. I.E. when doing
974 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
979 typename = type_name_no_tag (type);
980 if (typename != NULL && STREQ (typename, name))
985 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
987 char *t_field_name = TYPE_FIELD_NAME (type, i);
989 if (t_field_name && STREQ (t_field_name, name))
991 return TYPE_FIELD_TYPE (type, i);
995 /* OK, it's not in this class. Recursively check the baseclasses. */
996 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1000 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1012 target_terminal_ours ();
1013 gdb_flush (gdb_stdout);
1014 fprintf_unfiltered (gdb_stderr, "Type ");
1015 type_print (type, "", gdb_stderr, -1);
1016 fprintf_unfiltered (gdb_stderr, " has no component named ");
1017 fputs_filtered (name, gdb_stderr);
1019 return (struct type *) -1; /* For lint */
1022 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1023 valid. Callers should be aware that in some cases (for example,
1024 the type or one of its baseclasses is a stub type and we are
1025 debugging a .o file), this function will not be able to find the virtual
1026 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1027 will remain NULL. */
1030 fill_in_vptr_fieldno (type)
1033 CHECK_TYPEDEF (type);
1035 if (TYPE_VPTR_FIELDNO (type) < 0)
1039 /* We must start at zero in case the first (and only) baseclass is
1040 virtual (and hence we cannot share the table pointer). */
1041 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1043 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
1044 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
1046 TYPE_VPTR_FIELDNO (type)
1047 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
1048 TYPE_VPTR_BASETYPE (type)
1049 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
1056 /* Find the method and field indices for the destructor in class type T.
1057 Return 1 if the destructor was found, otherwise, return 0. */
1060 get_destructor_fn_field (t, method_indexp, field_indexp)
1067 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1070 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1072 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1074 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j)))
1085 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1087 If this is a stubbed struct (i.e. declared as struct foo *), see if
1088 we can find a full definition in some other file. If so, copy this
1089 definition, so we can use it in future. There used to be a comment (but
1090 not any code) that if we don't find a full definition, we'd set a flag
1091 so we don't spend time in the future checking the same type. That would
1092 be a mistake, though--we might load in more symbols which contain a
1093 full definition for the type.
1095 This used to be coded as a macro, but I don't think it is called
1096 often enough to merit such treatment. */
1098 struct complaint stub_noname_complaint =
1099 {"stub type has NULL name", 0, 0};
1102 check_typedef (type)
1103 register struct type *type;
1105 struct type *orig_type = type;
1106 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1108 if (!TYPE_TARGET_TYPE (type))
1113 /* It is dangerous to call lookup_symbol if we are currently
1114 reading a symtab. Infinite recursion is one danger. */
1115 if (currently_reading_symtab)
1118 name = type_name_no_tag (type);
1119 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1120 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1121 as appropriate? (this code was written before TYPE_NAME and
1122 TYPE_TAG_NAME were separate). */
1125 complain (&stub_noname_complaint);
1128 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
1129 (struct symtab **) NULL);
1131 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1133 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1135 type = TYPE_TARGET_TYPE (type);
1138 /* If this is a struct/class/union with no fields, then check whether a
1139 full definition exists somewhere else. This is for systems where a
1140 type definition with no fields is issued for such types, instead of
1141 identifying them as stub types in the first place */
1143 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1145 char *name = type_name_no_tag (type);
1146 struct type *newtype;
1149 complain (&stub_noname_complaint);
1152 newtype = lookup_transparent_type (name);
1155 memcpy ((char *) type, (char *) newtype, sizeof (struct type));
1158 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1159 else if ((TYPE_FLAGS (type) & TYPE_FLAG_STUB) && !currently_reading_symtab)
1161 char *name = type_name_no_tag (type);
1162 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1163 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1164 as appropriate? (this code was written before TYPE_NAME and
1165 TYPE_TAG_NAME were separate). */
1169 complain (&stub_noname_complaint);
1172 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL);
1175 memcpy ((char *) type, (char *) SYMBOL_TYPE (sym), sizeof (struct type));
1179 if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB)
1181 struct type *range_type;
1182 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1184 if (TYPE_FLAGS (target_type) & (TYPE_FLAG_STUB | TYPE_FLAG_TARGET_STUB))
1187 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1188 && TYPE_NFIELDS (type) == 1
1189 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1190 == TYPE_CODE_RANGE))
1192 /* Now recompute the length of the array type, based on its
1193 number of elements and the target type's length. */
1194 TYPE_LENGTH (type) =
1195 ((TYPE_FIELD_BITPOS (range_type, 1)
1196 - TYPE_FIELD_BITPOS (range_type, 0)
1198 * TYPE_LENGTH (target_type));
1199 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1201 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1203 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1204 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1207 /* Cache TYPE_LENGTH for future use. */
1208 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1212 /* New code added to support parsing of Cfront stabs strings */
1214 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1215 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1218 add_name (pextras, n)
1219 struct extra *pextras;
1224 if ((nlen = (n ? strlen (n) : 0)) == 0)
1226 sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1227 pextras->len = strlen (pextras->str);
1231 add_mangled_type (pextras, t)
1232 struct extra *pextras;
1235 enum type_code tcode;
1239 tcode = TYPE_CODE (t);
1240 tlen = TYPE_LENGTH (t);
1241 tflags = TYPE_FLAGS (t);
1242 tname = TYPE_NAME (t);
1243 /* args of "..." seem to get mangled as "e" */
1261 if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1274 static struct complaint msg =
1275 {"Bad int type code length x%x\n", 0, 0};
1277 complain (&msg, tlen);
1296 static struct complaint msg =
1297 {"Bad float type code length x%x\n", 0, 0};
1298 complain (&msg, tlen);
1304 /* followed by what it's a ref to */
1308 /* followed by what it's a ptr to */
1310 case TYPE_CODE_TYPEDEF:
1312 static struct complaint msg =
1313 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1316 /* followed by type bytes & name */
1318 case TYPE_CODE_FUNC:
1320 /* followed by func's arg '_' & ret types */
1322 case TYPE_CODE_VOID:
1325 case TYPE_CODE_METHOD:
1327 /* followed by name of class and func's arg '_' & ret types */
1328 add_name (pextras, tname);
1329 ADD_EXTRA ('F'); /* then mangle function */
1331 case TYPE_CODE_STRUCT: /* C struct */
1332 case TYPE_CODE_UNION: /* C union */
1333 case TYPE_CODE_ENUM: /* Enumeration type */
1334 /* followed by name of type */
1335 add_name (pextras, tname);
1338 /* errors possible types/not supported */
1339 case TYPE_CODE_CHAR:
1340 case TYPE_CODE_ARRAY: /* Array type */
1341 case TYPE_CODE_MEMBER: /* Member type */
1342 case TYPE_CODE_BOOL:
1343 case TYPE_CODE_COMPLEX: /* Complex float */
1344 case TYPE_CODE_UNDEF:
1345 case TYPE_CODE_SET: /* Pascal sets */
1346 case TYPE_CODE_RANGE:
1347 case TYPE_CODE_STRING:
1348 case TYPE_CODE_BITSTRING:
1349 case TYPE_CODE_ERROR:
1352 static struct complaint msg =
1353 {"Unknown type code x%x\n", 0, 0};
1354 complain (&msg, tcode);
1358 add_mangled_type (pextras, t->target_type);
1363 cfront_mangle_name (type, i, j)
1369 char *mangled_name = gdb_mangle_name (type, i, j);
1371 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1373 /* kludge to support cfront methods - gdb expects to find "F" for
1374 ARM_mangled names, so when we mangle, we have to add it here */
1378 char *arm_mangled_name;
1379 struct fn_field *method = &f[j];
1380 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1381 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1382 char *newname = type_name_no_tag (type);
1384 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1385 int nargs = TYPE_NFIELDS (ftype); /* number of args */
1386 struct extra extras, *pextras = &extras;
1389 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1392 /* add args here! */
1393 if (nargs <= 1) /* no args besides this */
1397 for (k = 1; k < nargs; k++)
1400 t = TYPE_FIELD_TYPE (ftype, k);
1401 add_mangled_type (pextras, t);
1405 printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1406 arm_mangled_name = malloc (strlen (mangled_name) + extras.len);
1407 sprintf (arm_mangled_name, "%s%s", mangled_name, extras.str);
1408 free (mangled_name);
1409 mangled_name = arm_mangled_name;
1415 /* End of new code added to support parsing of Cfront stabs strings */
1417 /* Ugly hack to convert method stubs into method types.
1419 He ain't kiddin'. This demangles the name of the method into a string
1420 including argument types, parses out each argument type, generates
1421 a string casting a zero to that type, evaluates the string, and stuffs
1422 the resulting type into an argtype vector!!! Then it knows the type
1423 of the whole function (including argument types for overloading),
1424 which info used to be in the stab's but was removed to hack back
1425 the space required for them. */
1428 check_stub_method (type, method_id, signature_id)
1434 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1435 char *demangled_name = cplus_demangle (mangled_name,
1436 DMGL_PARAMS | DMGL_ANSI);
1437 char *argtypetext, *p;
1438 int depth = 0, argcount = 1;
1439 struct type **argtypes;
1442 /* Make sure we got back a function string that we can use. */
1444 p = strchr (demangled_name, '(');
1446 if (demangled_name == NULL || p == NULL)
1447 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1449 /* Now, read in the parameters that define this type. */
1462 else if (*p == ',' && depth == 0)
1470 /* We need two more slots: one for the THIS pointer, and one for the
1471 NULL [...] or void [end of arglist]. */
1473 argtypes = (struct type **)
1474 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
1476 /* FIXME: This is wrong for static member functions. */
1477 argtypes[0] = lookup_pointer_type (type);
1480 if (*p != ')') /* () means no args, skip while */
1485 if (depth <= 0 && (*p == ',' || *p == ')'))
1487 /* Avoid parsing of ellipsis, they will be handled below. */
1488 if (strncmp (argtypetext, "...", p - argtypetext) != 0)
1490 argtypes[argcount] =
1491 parse_and_eval_type (argtypetext, p - argtypetext);
1494 argtypetext = p + 1;
1510 if (p[-2] != '.') /* Not '...' */
1512 argtypes[argcount] = builtin_type_void; /* List terminator */
1516 argtypes[argcount] = NULL; /* Ellist terminator */
1519 free (demangled_name);
1521 f = TYPE_FN_FIELDLIST1 (type, method_id);
1523 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1525 /* Now update the old "stub" type into a real type. */
1526 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1527 TYPE_DOMAIN_TYPE (mtype) = type;
1528 TYPE_ARG_TYPES (mtype) = argtypes;
1529 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1530 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1533 const struct cplus_struct_type cplus_struct_default;
1536 allocate_cplus_struct_type (type)
1539 if (!HAVE_CPLUS_STRUCT (type))
1541 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1542 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1543 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1547 /* Helper function to initialize the standard scalar types.
1549 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1550 of the string pointed to by name in the type_obstack for that objfile,
1551 and initialize the type name to that copy. There are places (mipsread.c
1552 in particular, where init_type is called with a NULL value for NAME). */
1555 init_type (code, length, flags, name, objfile)
1556 enum type_code code;
1560 struct objfile *objfile;
1562 register struct type *type;
1564 type = alloc_type (objfile);
1565 TYPE_CODE (type) = code;
1566 TYPE_LENGTH (type) = length;
1567 TYPE_FLAGS (type) |= flags;
1568 if ((name != NULL) && (objfile != NULL))
1571 obsavestring (name, strlen (name), &objfile->type_obstack);
1575 TYPE_NAME (type) = name;
1580 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1582 INIT_CPLUS_SPECIFIC (type);
1587 /* Look up a fundamental type for the specified objfile.
1588 May need to construct such a type if this is the first use.
1590 Some object file formats (ELF, COFF, etc) do not define fundamental
1591 types such as "int" or "double". Others (stabs for example), do
1592 define fundamental types.
1594 For the formats which don't provide fundamental types, gdb can create
1595 such types, using defaults reasonable for the current language and
1596 the current target machine.
1598 NOTE: This routine is obsolescent. Each debugging format reader
1599 should manage it's own fundamental types, either creating them from
1600 suitable defaults or reading them from the debugging information,
1601 whichever is appropriate. The DWARF reader has already been
1602 fixed to do this. Once the other readers are fixed, this routine
1603 will go away. Also note that fundamental types should be managed
1604 on a compilation unit basis in a multi-language environment, not
1605 on a linkage unit basis as is done here. */
1609 lookup_fundamental_type (objfile, typeid)
1610 struct objfile *objfile;
1613 register struct type **typep;
1614 register int nbytes;
1616 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1618 error ("internal error - invalid fundamental type id %d", typeid);
1621 /* If this is the first time we need a fundamental type for this objfile
1622 then we need to initialize the vector of type pointers. */
1624 if (objfile->fundamental_types == NULL)
1626 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1627 objfile->fundamental_types = (struct type **)
1628 obstack_alloc (&objfile->type_obstack, nbytes);
1629 memset ((char *) objfile->fundamental_types, 0, nbytes);
1630 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1633 /* Look for this particular type in the fundamental type vector. If one is
1634 not found, create and install one appropriate for the current language. */
1636 typep = objfile->fundamental_types + typeid;
1639 *typep = create_fundamental_type (objfile, typeid);
1649 /* FIXME: Should we return true for references as well as pointers? */
1653 && TYPE_CODE (t) == TYPE_CODE_PTR
1654 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1658 is_integral_type (t)
1664 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1665 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1666 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1667 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1668 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1671 /* Chill varying string and arrays are represented as follows:
1673 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1675 Return true if TYPE is such a Chill varying type. */
1678 chill_varying_type (type)
1681 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1682 || TYPE_NFIELDS (type) != 2
1683 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1688 /* Check whether BASE is an ancestor or base class or DCLASS
1689 Return 1 if so, and 0 if not.
1690 Note: callers may want to check for identity of the types before
1691 calling this function -- identical types are considered to satisfy
1692 the ancestor relationship even if they're identical */
1695 is_ancestor (base, dclass)
1697 struct type *dclass;
1701 CHECK_TYPEDEF (base);
1702 CHECK_TYPEDEF (dclass);
1707 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1708 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1716 /* See whether DCLASS has a virtual table. This routine is aimed at
1717 the HP/Taligent ANSI C++ runtime model, and may not work with other
1718 runtime models. Return 1 => Yes, 0 => No. */
1722 struct type *dclass;
1724 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1725 has virtual functions or virtual bases. */
1729 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1732 /* First check for the presence of virtual bases */
1733 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1734 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1735 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1738 /* Next check for virtual functions */
1739 if (TYPE_FN_FIELDLISTS (dclass))
1740 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1741 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1744 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1745 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1746 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1747 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1748 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1751 /* Well, maybe we don't need a virtual table */
1755 /* Return a pointer to the "primary base class" of DCLASS.
1757 A NULL return indicates that DCLASS has no primary base, or that it
1758 couldn't be found (insufficient information).
1760 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1761 and may not work with other runtime models. */
1764 primary_base_class (dclass)
1765 struct type *dclass;
1767 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1768 is the first directly inherited, non-virtual base class that
1769 requires a virtual table */
1773 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1776 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1777 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1778 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1779 return TYPE_FIELD_TYPE (dclass, i);
1784 /* Global manipulated by virtual_base_list[_aux]() */
1786 static struct vbase *current_vbase_list = NULL;
1788 /* Return a pointer to a null-terminated list of struct vbase
1789 items. The vbasetype pointer of each item in the list points to the
1790 type information for a virtual base of the argument DCLASS.
1792 Helper function for virtual_base_list().
1793 Note: the list goes backward, right-to-left. virtual_base_list()
1794 copies the items out in reverse order. */
1797 virtual_base_list_aux (dclass)
1798 struct type *dclass;
1800 struct vbase *tmp_vbase;
1803 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1806 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1808 /* Recurse on this ancestor, first */
1809 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
1811 /* If this current base is itself virtual, add it to the list */
1812 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1814 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1816 /* Check if base already recorded */
1817 tmp_vbase = current_vbase_list;
1820 if (tmp_vbase->vbasetype == basetype)
1821 break; /* found it */
1822 tmp_vbase = tmp_vbase->next;
1825 if (!tmp_vbase) /* normal exit from loop */
1827 /* Allocate new item for this virtual base */
1828 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
1830 /* Stick it on at the end of the list */
1831 tmp_vbase->vbasetype = basetype;
1832 tmp_vbase->next = current_vbase_list;
1833 current_vbase_list = tmp_vbase;
1836 } /* for loop over bases */
1840 /* Compute the list of virtual bases in the right order. Virtual
1841 bases are laid out in the object's memory area in order of their
1842 occurrence in a depth-first, left-to-right search through the
1845 Argument DCLASS is the type whose virtual bases are required.
1846 Return value is the address of a null-terminated array of pointers
1847 to struct type items.
1849 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1850 and may not work with other runtime models.
1852 This routine merely hands off the argument to virtual_base_list_aux()
1853 and then copies the result into an array to save space. */
1856 virtual_base_list (dclass)
1857 struct type *dclass;
1859 register struct vbase *tmp_vbase;
1860 register struct vbase *tmp_vbase_2;
1863 struct type **vbase_array;
1865 current_vbase_list = NULL;
1866 virtual_base_list_aux (dclass);
1868 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1873 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
1875 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
1876 vbase_array[i] = tmp_vbase->vbasetype;
1878 /* Get rid of constructed chain */
1879 tmp_vbase_2 = tmp_vbase = current_vbase_list;
1882 tmp_vbase = tmp_vbase->next;
1884 tmp_vbase_2 = tmp_vbase;
1887 vbase_array[count] = NULL;
1891 /* Return the length of the virtual base list of the type DCLASS. */
1894 virtual_base_list_length (dclass)
1895 struct type *dclass;
1898 register struct vbase *tmp_vbase;
1900 current_vbase_list = NULL;
1901 virtual_base_list_aux (dclass);
1903 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1908 /* Return the number of elements of the virtual base list of the type
1909 DCLASS, ignoring those appearing in the primary base (and its
1910 primary base, recursively). */
1913 virtual_base_list_length_skip_primaries (dclass)
1914 struct type *dclass;
1917 register struct vbase *tmp_vbase;
1918 struct type *primary;
1920 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
1923 return virtual_base_list_length (dclass);
1925 current_vbase_list = NULL;
1926 virtual_base_list_aux (dclass);
1928 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
1930 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
1938 /* Return the index (position) of type BASE, which is a virtual base
1939 class of DCLASS, in the latter's virtual base list. A return of -1
1940 indicates "not found" or a problem. */
1943 virtual_base_index (base, dclass)
1945 struct type *dclass;
1947 register struct type *vbase;
1950 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
1951 (TYPE_CODE (base) != TYPE_CODE_CLASS))
1955 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0];
1960 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i];
1963 return vbase ? i : -1;
1968 /* Return the index (position) of type BASE, which is a virtual base
1969 class of DCLASS, in the latter's virtual base list. Skip over all
1970 bases that may appear in the virtual base list of the primary base
1971 class of DCLASS (recursively). A return of -1 indicates "not
1972 found" or a problem. */
1975 virtual_base_index_skip_primaries (base, dclass)
1977 struct type *dclass;
1979 register struct type *vbase;
1981 struct type *primary;
1983 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
1984 (TYPE_CODE (base) != TYPE_CODE_CLASS))
1987 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
1991 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0];
1994 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
1998 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i];
2001 return vbase ? j : -1;
2004 /* Return position of a derived class DCLASS in the list of
2005 * primary bases starting with the remotest ancestor.
2006 * Position returned is 0-based. */
2009 class_index_in_primary_list (dclass)
2010 struct type *dclass;
2012 struct type *pbc; /* primary base class */
2014 /* Simply recurse on primary base */
2015 pbc = TYPE_PRIMARY_BASE (dclass);
2017 return 1 + class_index_in_primary_list (pbc);
2022 /* Return a count of the number of virtual functions a type has.
2023 * This includes all the virtual functions it inherits from its
2027 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2028 * functions only once (latest redefinition)
2032 count_virtual_fns (dclass)
2033 struct type *dclass;
2035 int fn, oi; /* function and overloaded instance indices */
2036 int vfuncs; /* count to return */
2038 /* recurse on bases that can share virtual table */
2039 struct type *pbc = primary_base_class (dclass);
2041 vfuncs = count_virtual_fns (pbc);
2043 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2044 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2045 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2053 /* Functions for overload resolution begin here */
2055 /* Compare two badness vectors A and B and return the result.
2056 * 0 => A and B are identical
2057 * 1 => A and B are incomparable
2058 * 2 => A is better than B
2059 * 3 => A is worse than B */
2062 compare_badness (a, b)
2063 struct badness_vector *a;
2064 struct badness_vector *b;
2068 short found_pos = 0; /* any positives in c? */
2069 short found_neg = 0; /* any negatives in c? */
2071 /* differing lengths => incomparable */
2072 if (a->length != b->length)
2075 /* Subtract b from a */
2076 for (i = 0; i < a->length; i++)
2078 tmp = a->rank[i] - b->rank[i];
2088 return 1; /* incomparable */
2090 return 3; /* A > B */
2096 return 2; /* A < B */
2098 return 0; /* A == B */
2102 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2103 * to the types of an argument list (ARGS, length NARGS).
2104 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2106 struct badness_vector *
2107 rank_function (parms, nparms, args, nargs)
2108 struct type **parms;
2114 struct badness_vector *bv;
2115 int min_len = nparms < nargs ? nparms : nargs;
2117 bv = xmalloc (sizeof (struct badness_vector));
2118 bv->length = nargs + 1; /* add 1 for the length-match rank */
2119 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2121 /* First compare the lengths of the supplied lists.
2122 * If there is a mismatch, set it to a high value. */
2124 /* pai/1997-06-03 FIXME: when we have debug info about default
2125 * arguments and ellipsis parameter lists, we should consider those
2126 * and rank the length-match more finely. */
2128 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2130 /* Now rank all the parameters of the candidate function */
2131 for (i = 1; i <= min_len; i++)
2132 bv->rank[i] = rank_one_type (parms[i - 1], args[i - 1]);
2134 /* If more arguments than parameters, add dummy entries */
2135 for (i = min_len + 1; i <= nargs; i++)
2136 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2141 /* Compare one type (PARM) for compatibility with another (ARG).
2142 * PARM is intended to be the parameter type of a function; and
2143 * ARG is the supplied argument's type. This function tests if
2144 * the latter can be converted to the former.
2146 * Return 0 if they are identical types;
2147 * Otherwise, return an integer which corresponds to how compatible
2148 * PARM is to ARG. The higher the return value, the worse the match.
2149 * Generally the "bad" conversions are all uniformly assigned a 100 */
2152 rank_one_type (parm, arg)
2156 /* Identical type pointers */
2157 /* However, this still doesn't catch all cases of same type for arg
2158 * and param. The reason is that builtin types are different from
2159 * the same ones constructed from the object. */
2163 /* Resolve typedefs */
2164 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2165 parm = check_typedef (parm);
2166 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2167 arg = check_typedef (arg);
2169 /* Check if identical after resolving typedefs */
2174 /* Debugging only */
2175 printf ("------ Arg is %s [%d], parm is %s [%d]\n",
2176 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2179 /* x -> y means arg of type x being supplied for parameter of type y */
2181 switch (TYPE_CODE (parm))
2184 switch (TYPE_CODE (arg))
2187 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2188 return VOID_PTR_CONVERSION_BADNESS;
2190 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2191 case TYPE_CODE_ARRAY:
2192 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2193 case TYPE_CODE_FUNC:
2194 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2196 case TYPE_CODE_ENUM:
2197 case TYPE_CODE_CHAR:
2198 case TYPE_CODE_RANGE:
2199 case TYPE_CODE_BOOL:
2200 return POINTER_CONVERSION_BADNESS;
2202 return INCOMPATIBLE_TYPE_BADNESS;
2204 case TYPE_CODE_ARRAY:
2205 switch (TYPE_CODE (arg))
2208 case TYPE_CODE_ARRAY:
2209 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2211 return INCOMPATIBLE_TYPE_BADNESS;
2213 case TYPE_CODE_FUNC:
2214 switch (TYPE_CODE (arg))
2216 case TYPE_CODE_PTR: /* funcptr -> func */
2217 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2219 return INCOMPATIBLE_TYPE_BADNESS;
2222 switch (TYPE_CODE (arg))
2225 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2227 /* Deal with signed, unsigned, and plain chars and
2228 signed and unsigned ints */
2229 if (TYPE_NOSIGN (parm))
2231 /* This case only for character types */
2232 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2235 return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */
2237 else if (TYPE_UNSIGNED (parm))
2239 if (TYPE_UNSIGNED (arg))
2241 if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2242 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2243 else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long"))
2244 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2246 return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
2250 if (!strcmp (TYPE_NAME (arg), "long") && !strcmp (TYPE_NAME (parm), "int"))
2251 return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
2253 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2256 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2258 if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2260 else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long"))
2261 return INTEGER_PROMOTION_BADNESS;
2263 return INTEGER_COERCION_BADNESS;
2266 return INTEGER_COERCION_BADNESS;
2268 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2269 return INTEGER_PROMOTION_BADNESS;
2271 return INTEGER_COERCION_BADNESS;
2272 case TYPE_CODE_ENUM:
2273 case TYPE_CODE_CHAR:
2274 case TYPE_CODE_RANGE:
2275 case TYPE_CODE_BOOL:
2276 return INTEGER_PROMOTION_BADNESS;
2278 return INT_FLOAT_CONVERSION_BADNESS;
2280 return NS_POINTER_CONVERSION_BADNESS;
2282 return INCOMPATIBLE_TYPE_BADNESS;
2285 case TYPE_CODE_ENUM:
2286 switch (TYPE_CODE (arg))
2289 case TYPE_CODE_CHAR:
2290 case TYPE_CODE_RANGE:
2291 case TYPE_CODE_BOOL:
2292 case TYPE_CODE_ENUM:
2293 return INTEGER_COERCION_BADNESS;
2295 return INT_FLOAT_CONVERSION_BADNESS;
2297 return INCOMPATIBLE_TYPE_BADNESS;
2300 case TYPE_CODE_CHAR:
2301 switch (TYPE_CODE (arg))
2303 case TYPE_CODE_RANGE:
2304 case TYPE_CODE_BOOL:
2305 case TYPE_CODE_ENUM:
2306 return INTEGER_COERCION_BADNESS;
2308 return INT_FLOAT_CONVERSION_BADNESS;
2310 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2311 return INTEGER_COERCION_BADNESS;
2312 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2313 return INTEGER_PROMOTION_BADNESS;
2314 /* >>> !! else fall through !! <<< */
2315 case TYPE_CODE_CHAR:
2316 /* Deal with signed, unsigned, and plain chars for C++
2317 and with int cases falling through from previous case */
2318 if (TYPE_NOSIGN (parm))
2320 if (TYPE_NOSIGN (arg))
2323 return INTEGER_COERCION_BADNESS;
2325 else if (TYPE_UNSIGNED (parm))
2327 if (TYPE_UNSIGNED (arg))
2330 return INTEGER_PROMOTION_BADNESS;
2332 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2335 return INTEGER_COERCION_BADNESS;
2337 return INCOMPATIBLE_TYPE_BADNESS;
2340 case TYPE_CODE_RANGE:
2341 switch (TYPE_CODE (arg))
2344 case TYPE_CODE_CHAR:
2345 case TYPE_CODE_RANGE:
2346 case TYPE_CODE_BOOL:
2347 case TYPE_CODE_ENUM:
2348 return INTEGER_COERCION_BADNESS;
2350 return INT_FLOAT_CONVERSION_BADNESS;
2352 return INCOMPATIBLE_TYPE_BADNESS;
2355 case TYPE_CODE_BOOL:
2356 switch (TYPE_CODE (arg))
2359 case TYPE_CODE_CHAR:
2360 case TYPE_CODE_RANGE:
2361 case TYPE_CODE_ENUM:
2364 return BOOLEAN_CONVERSION_BADNESS;
2365 case TYPE_CODE_BOOL:
2368 return INCOMPATIBLE_TYPE_BADNESS;
2372 switch (TYPE_CODE (arg))
2375 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2376 return FLOAT_PROMOTION_BADNESS;
2377 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2380 return FLOAT_CONVERSION_BADNESS;
2382 case TYPE_CODE_BOOL:
2383 case TYPE_CODE_ENUM:
2384 case TYPE_CODE_RANGE:
2385 case TYPE_CODE_CHAR:
2386 return INT_FLOAT_CONVERSION_BADNESS;
2388 return INCOMPATIBLE_TYPE_BADNESS;
2391 case TYPE_CODE_COMPLEX:
2392 switch (TYPE_CODE (arg))
2393 { /* Strictly not needed for C++, but... */
2395 return FLOAT_PROMOTION_BADNESS;
2396 case TYPE_CODE_COMPLEX:
2399 return INCOMPATIBLE_TYPE_BADNESS;
2402 case TYPE_CODE_STRUCT:
2403 /* currently same as TYPE_CODE_CLASS */
2404 switch (TYPE_CODE (arg))
2406 case TYPE_CODE_STRUCT:
2407 /* Check for derivation */
2408 if (is_ancestor (parm, arg))
2409 return BASE_CONVERSION_BADNESS;
2410 /* else fall through */
2412 return INCOMPATIBLE_TYPE_BADNESS;
2415 case TYPE_CODE_UNION:
2416 switch (TYPE_CODE (arg))
2418 case TYPE_CODE_UNION:
2420 return INCOMPATIBLE_TYPE_BADNESS;
2423 case TYPE_CODE_MEMBER:
2424 switch (TYPE_CODE (arg))
2427 return INCOMPATIBLE_TYPE_BADNESS;
2430 case TYPE_CODE_METHOD:
2431 switch (TYPE_CODE (arg))
2435 return INCOMPATIBLE_TYPE_BADNESS;
2439 switch (TYPE_CODE (arg))
2443 return INCOMPATIBLE_TYPE_BADNESS;
2448 switch (TYPE_CODE (arg))
2452 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2454 return INCOMPATIBLE_TYPE_BADNESS;
2457 case TYPE_CODE_VOID:
2459 return INCOMPATIBLE_TYPE_BADNESS;
2460 } /* switch (TYPE_CODE (arg)) */
2464 /* End of functions for overload resolution */
2467 print_bit_vector (bits, nbits)
2473 for (bitno = 0; bitno < nbits; bitno++)
2475 if ((bitno % 8) == 0)
2477 puts_filtered (" ");
2479 if (B_TST (bits, bitno))
2481 printf_filtered ("1");
2485 printf_filtered ("0");
2490 /* The args list is a strange beast. It is either terminated by a NULL
2491 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2492 type for normal fixed argcount functions. (FIXME someday)
2493 Also note the first arg should be the "this" pointer, we may not want to
2494 include it since we may get into a infinitely recursive situation. */
2497 print_arg_types (args, spaces)
2503 while (*args != NULL)
2505 recursive_dump_type (*args, spaces + 2);
2506 if ((*args++)->code == TYPE_CODE_VOID)
2515 dump_fn_fieldlists (type, spaces)
2523 printfi_filtered (spaces, "fn_fieldlists ");
2524 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2525 printf_filtered ("\n");
2526 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2528 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2529 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2531 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2532 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2534 printf_filtered (") length %d\n",
2535 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2536 for (overload_idx = 0;
2537 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2540 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2542 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2543 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2545 printf_filtered (")\n");
2546 printfi_filtered (spaces + 8, "type ");
2547 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2548 printf_filtered ("\n");
2550 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2553 printfi_filtered (spaces + 8, "args ");
2554 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2555 printf_filtered ("\n");
2557 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
2558 printfi_filtered (spaces + 8, "fcontext ");
2559 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2561 printf_filtered ("\n");
2563 printfi_filtered (spaces + 8, "is_const %d\n",
2564 TYPE_FN_FIELD_CONST (f, overload_idx));
2565 printfi_filtered (spaces + 8, "is_volatile %d\n",
2566 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2567 printfi_filtered (spaces + 8, "is_private %d\n",
2568 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2569 printfi_filtered (spaces + 8, "is_protected %d\n",
2570 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2571 printfi_filtered (spaces + 8, "is_stub %d\n",
2572 TYPE_FN_FIELD_STUB (f, overload_idx));
2573 printfi_filtered (spaces + 8, "voffset %u\n",
2574 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2580 print_cplus_stuff (type, spaces)
2584 printfi_filtered (spaces, "n_baseclasses %d\n",
2585 TYPE_N_BASECLASSES (type));
2586 printfi_filtered (spaces, "nfn_fields %d\n",
2587 TYPE_NFN_FIELDS (type));
2588 printfi_filtered (spaces, "nfn_fields_total %d\n",
2589 TYPE_NFN_FIELDS_TOTAL (type));
2590 if (TYPE_N_BASECLASSES (type) > 0)
2592 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2593 TYPE_N_BASECLASSES (type));
2594 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2595 printf_filtered (")");
2597 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2598 TYPE_N_BASECLASSES (type));
2599 puts_filtered ("\n");
2601 if (TYPE_NFIELDS (type) > 0)
2603 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2605 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2606 TYPE_NFIELDS (type));
2607 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2608 printf_filtered (")");
2609 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2610 TYPE_NFIELDS (type));
2611 puts_filtered ("\n");
2613 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2615 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2616 TYPE_NFIELDS (type));
2617 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2618 printf_filtered (")");
2619 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2620 TYPE_NFIELDS (type));
2621 puts_filtered ("\n");
2624 if (TYPE_NFN_FIELDS (type) > 0)
2626 dump_fn_fieldlists (type, spaces);
2630 static struct obstack dont_print_type_obstack;
2633 recursive_dump_type (type, spaces)
2640 obstack_begin (&dont_print_type_obstack, 0);
2642 if (TYPE_NFIELDS (type) > 0
2643 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2645 struct type **first_dont_print
2646 = (struct type **) obstack_base (&dont_print_type_obstack);
2648 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2653 if (type == first_dont_print[i])
2655 printfi_filtered (spaces, "type node ");
2656 gdb_print_host_address (type, gdb_stdout);
2657 printf_filtered (" <same as already seen type>\n");
2662 obstack_ptr_grow (&dont_print_type_obstack, type);
2665 printfi_filtered (spaces, "type node ");
2666 gdb_print_host_address (type, gdb_stdout);
2667 printf_filtered ("\n");
2668 printfi_filtered (spaces, "name '%s' (",
2669 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2670 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2671 printf_filtered (")\n");
2672 if (TYPE_TAG_NAME (type) != NULL)
2674 printfi_filtered (spaces, "tagname '%s' (",
2675 TYPE_TAG_NAME (type));
2676 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2677 printf_filtered (")\n");
2679 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2680 switch (TYPE_CODE (type))
2682 case TYPE_CODE_UNDEF:
2683 printf_filtered ("(TYPE_CODE_UNDEF)");
2686 printf_filtered ("(TYPE_CODE_PTR)");
2688 case TYPE_CODE_ARRAY:
2689 printf_filtered ("(TYPE_CODE_ARRAY)");
2691 case TYPE_CODE_STRUCT:
2692 printf_filtered ("(TYPE_CODE_STRUCT)");
2694 case TYPE_CODE_UNION:
2695 printf_filtered ("(TYPE_CODE_UNION)");
2697 case TYPE_CODE_ENUM:
2698 printf_filtered ("(TYPE_CODE_ENUM)");
2700 case TYPE_CODE_FUNC:
2701 printf_filtered ("(TYPE_CODE_FUNC)");
2704 printf_filtered ("(TYPE_CODE_INT)");
2707 printf_filtered ("(TYPE_CODE_FLT)");
2709 case TYPE_CODE_VOID:
2710 printf_filtered ("(TYPE_CODE_VOID)");
2713 printf_filtered ("(TYPE_CODE_SET)");
2715 case TYPE_CODE_RANGE:
2716 printf_filtered ("(TYPE_CODE_RANGE)");
2718 case TYPE_CODE_STRING:
2719 printf_filtered ("(TYPE_CODE_STRING)");
2721 case TYPE_CODE_ERROR:
2722 printf_filtered ("(TYPE_CODE_ERROR)");
2724 case TYPE_CODE_MEMBER:
2725 printf_filtered ("(TYPE_CODE_MEMBER)");
2727 case TYPE_CODE_METHOD:
2728 printf_filtered ("(TYPE_CODE_METHOD)");
2731 printf_filtered ("(TYPE_CODE_REF)");
2733 case TYPE_CODE_CHAR:
2734 printf_filtered ("(TYPE_CODE_CHAR)");
2736 case TYPE_CODE_BOOL:
2737 printf_filtered ("(TYPE_CODE_BOOL)");
2739 case TYPE_CODE_TYPEDEF:
2740 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2743 printf_filtered ("(UNKNOWN TYPE CODE)");
2746 puts_filtered ("\n");
2747 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2748 printfi_filtered (spaces, "objfile ");
2749 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2750 printf_filtered ("\n");
2751 printfi_filtered (spaces, "target_type ");
2752 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2753 printf_filtered ("\n");
2754 if (TYPE_TARGET_TYPE (type) != NULL)
2756 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2758 printfi_filtered (spaces, "pointer_type ");
2759 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2760 printf_filtered ("\n");
2761 printfi_filtered (spaces, "reference_type ");
2762 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2763 printf_filtered ("\n");
2764 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
2765 if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED)
2767 puts_filtered (" TYPE_FLAG_UNSIGNED");
2769 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
2771 puts_filtered (" TYPE_FLAG_STUB");
2773 puts_filtered ("\n");
2774 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
2775 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
2776 puts_filtered ("\n");
2777 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
2779 printfi_filtered (spaces + 2,
2780 "[%d] bitpos %d bitsize %d type ",
2781 idx, TYPE_FIELD_BITPOS (type, idx),
2782 TYPE_FIELD_BITSIZE (type, idx));
2783 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
2784 printf_filtered (" name '%s' (",
2785 TYPE_FIELD_NAME (type, idx) != NULL
2786 ? TYPE_FIELD_NAME (type, idx)
2788 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
2789 printf_filtered (")\n");
2790 if (TYPE_FIELD_TYPE (type, idx) != NULL)
2792 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
2795 printfi_filtered (spaces, "vptr_basetype ");
2796 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
2797 puts_filtered ("\n");
2798 if (TYPE_VPTR_BASETYPE (type) != NULL)
2800 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
2802 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
2803 switch (TYPE_CODE (type))
2805 case TYPE_CODE_METHOD:
2806 case TYPE_CODE_FUNC:
2807 printfi_filtered (spaces, "arg_types ");
2808 gdb_print_host_address (TYPE_ARG_TYPES (type), gdb_stdout);
2809 puts_filtered ("\n");
2810 print_arg_types (TYPE_ARG_TYPES (type), spaces);
2813 case TYPE_CODE_STRUCT:
2814 printfi_filtered (spaces, "cplus_stuff ");
2815 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2816 puts_filtered ("\n");
2817 print_cplus_stuff (type, spaces);
2821 /* We have to pick one of the union types to be able print and test
2822 the value. Pick cplus_struct_type, even though we know it isn't
2823 any particular one. */
2824 printfi_filtered (spaces, "type_specific ");
2825 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2826 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
2828 printf_filtered (" (unknown data form)");
2830 printf_filtered ("\n");
2835 obstack_free (&dont_print_type_obstack, NULL);
2838 static void build_gdbtypes PARAMS ((void));
2843 init_type (TYPE_CODE_VOID, 1,
2845 "void", (struct objfile *) NULL);
2847 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2849 "char", (struct objfile *) NULL);
2850 TYPE_FLAGS (builtin_type_char) |= TYPE_FLAG_NOSIGN;
2851 builtin_type_true_char =
2852 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2854 "true character", (struct objfile *) NULL);
2855 builtin_type_signed_char =
2856 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2858 "signed char", (struct objfile *) NULL);
2859 builtin_type_unsigned_char =
2860 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2862 "unsigned char", (struct objfile *) NULL);
2863 builtin_type_short =
2864 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
2866 "short", (struct objfile *) NULL);
2867 builtin_type_unsigned_short =
2868 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
2870 "unsigned short", (struct objfile *) NULL);
2872 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
2874 "int", (struct objfile *) NULL);
2875 builtin_type_unsigned_int =
2876 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
2878 "unsigned int", (struct objfile *) NULL);
2880 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
2882 "long", (struct objfile *) NULL);
2883 builtin_type_unsigned_long =
2884 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
2886 "unsigned long", (struct objfile *) NULL);
2887 builtin_type_long_long =
2888 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2890 "long long", (struct objfile *) NULL);
2891 builtin_type_unsigned_long_long =
2892 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2894 "unsigned long long", (struct objfile *) NULL);
2895 builtin_type_float =
2896 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
2898 "float", (struct objfile *) NULL);
2899 builtin_type_double =
2900 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
2902 "double", (struct objfile *) NULL);
2903 builtin_type_long_double =
2904 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
2906 "long double", (struct objfile *) NULL);
2907 builtin_type_complex =
2908 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
2910 "complex", (struct objfile *) NULL);
2911 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
2912 builtin_type_double_complex =
2913 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
2915 "double complex", (struct objfile *) NULL);
2916 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
2917 builtin_type_string =
2918 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2920 "string", (struct objfile *) NULL);
2922 init_type (TYPE_CODE_INT, 8 / 8,
2924 "int8_t", (struct objfile *) NULL);
2925 builtin_type_uint8 =
2926 init_type (TYPE_CODE_INT, 8 / 8,
2928 "uint8_t", (struct objfile *) NULL);
2929 builtin_type_int16 =
2930 init_type (TYPE_CODE_INT, 16 / 8,
2932 "int16_t", (struct objfile *) NULL);
2933 builtin_type_uint16 =
2934 init_type (TYPE_CODE_INT, 16 / 8,
2936 "uint16_t", (struct objfile *) NULL);
2937 builtin_type_int32 =
2938 init_type (TYPE_CODE_INT, 32 / 8,
2940 "int32_t", (struct objfile *) NULL);
2941 builtin_type_uint32 =
2942 init_type (TYPE_CODE_INT, 32 / 8,
2944 "uint32_t", (struct objfile *) NULL);
2945 builtin_type_int64 =
2946 init_type (TYPE_CODE_INT, 64 / 8,
2948 "int64_t", (struct objfile *) NULL);
2949 builtin_type_uint64 =
2950 init_type (TYPE_CODE_INT, 64 / 8,
2952 "uint64_t", (struct objfile *) NULL);
2954 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2956 "bool", (struct objfile *) NULL);
2958 /* Add user knob for controlling resolution of opaque types */
2960 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
2961 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
2964 opaque_type_resolution = 1;
2967 /* Build SIMD types. */
2969 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
2973 extern void _initialize_gdbtypes PARAMS ((void));
2975 _initialize_gdbtypes ()
2979 /* FIXME - For the moment, handle types by swapping them in and out.
2980 Should be using the per-architecture data-pointer and a large
2982 register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL);
2983 register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL);
2984 register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL);
2985 register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL);
2986 register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL);
2987 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL);
2988 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL);
2989 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL);
2990 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL);
2991 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL);
2992 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL);
2993 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL);
2994 register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL);
2995 register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL);
2996 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL);
2997 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL);
2998 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL);
2999 register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL);
3000 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL);
3001 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL);
3002 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL);
3003 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL);
3004 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL);
3005 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
3006 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
3007 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
3008 register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
3009 register_gdbarch_swap (NULL, 0, build_gdbtypes);