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;
73 struct type *builtin_type_ptr;
74 struct type *builtin_type_CORE_ADDR;
75 struct type *builtin_type_bfd_vma;
77 int opaque_type_resolution = 1;
84 }; /* maximum extention is 128! FIXME */
86 static void add_name PARAMS ((struct extra *, char *));
87 static void add_mangled_type PARAMS ((struct extra *, struct type *));
89 static void cfront_mangle_name PARAMS ((struct type *, int, int));
91 static void print_bit_vector PARAMS ((B_TYPE *, int));
92 static void print_arg_types PARAMS ((struct type **, int));
93 static void dump_fn_fieldlists PARAMS ((struct type *, int));
94 static void print_cplus_stuff PARAMS ((struct type *, int));
95 static void virtual_base_list_aux PARAMS ((struct type * dclass));
98 /* Alloc a new type structure and fill it with some defaults. If
99 OBJFILE is non-NULL, then allocate the space for the type structure
100 in that objfile's type_obstack. */
104 struct objfile *objfile;
106 register struct type *type;
108 /* Alloc the structure and start off with all fields zeroed. */
112 type = (struct type *) xmalloc (sizeof (struct type));
116 type = (struct type *) obstack_alloc (&objfile->type_obstack,
117 sizeof (struct type));
118 OBJSTAT (objfile, n_types++);
120 memset ((char *) type, 0, sizeof (struct type));
122 /* Initialize the fields that might not be zero. */
124 TYPE_CODE (type) = TYPE_CODE_UNDEF;
125 TYPE_OBJFILE (type) = objfile;
126 TYPE_VPTR_FIELDNO (type) = -1;
127 TYPE_CV_TYPE (type) = type; /* chain back to itself */
132 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
133 to a pointer to memory where the pointer type should be stored.
134 If *TYPEPTR is zero, update it to point to the pointer type we return.
135 We allocate new memory if needed. */
138 make_pointer_type (type, typeptr)
140 struct type **typeptr;
142 register struct type *ntype; /* New type */
143 struct objfile *objfile;
145 ntype = TYPE_POINTER_TYPE (type);
150 return ntype; /* Don't care about alloc, and have new type. */
151 else if (*typeptr == 0)
153 *typeptr = ntype; /* Tracking alloc, and we have new type. */
158 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
160 ntype = alloc_type (TYPE_OBJFILE (type));
165 /* We have storage, but need to reset it. */
168 objfile = TYPE_OBJFILE (ntype);
169 memset ((char *) ntype, 0, sizeof (struct type));
170 TYPE_OBJFILE (ntype) = objfile;
173 TYPE_TARGET_TYPE (ntype) = type;
174 TYPE_POINTER_TYPE (type) = ntype;
176 /* FIXME! Assume the machine has only one representation for pointers! */
178 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
179 TYPE_CODE (ntype) = TYPE_CODE_PTR;
181 /* pointers are unsigned */
182 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
184 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
185 TYPE_POINTER_TYPE (type) = ntype;
190 /* Given a type TYPE, return a type of pointers to that type.
191 May need to construct such a type if this is the first use. */
194 lookup_pointer_type (type)
197 return make_pointer_type (type, (struct type **) 0);
200 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
201 to a pointer to memory where the reference type should be stored.
202 If *TYPEPTR is zero, update it to point to the reference type we return.
203 We allocate new memory if needed. */
206 make_reference_type (type, typeptr)
208 struct type **typeptr;
210 register struct type *ntype; /* New type */
211 struct objfile *objfile;
213 ntype = TYPE_REFERENCE_TYPE (type);
218 return ntype; /* Don't care about alloc, and have new type. */
219 else if (*typeptr == 0)
221 *typeptr = ntype; /* Tracking alloc, and we have new type. */
226 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
228 ntype = alloc_type (TYPE_OBJFILE (type));
233 /* We have storage, but need to reset it. */
236 objfile = TYPE_OBJFILE (ntype);
237 memset ((char *) ntype, 0, sizeof (struct type));
238 TYPE_OBJFILE (ntype) = objfile;
241 TYPE_TARGET_TYPE (ntype) = type;
242 TYPE_REFERENCE_TYPE (type) = ntype;
244 /* FIXME! Assume the machine has only one representation for references,
245 and that it matches the (only) representation for pointers! */
247 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
248 TYPE_CODE (ntype) = TYPE_CODE_REF;
250 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
251 TYPE_REFERENCE_TYPE (type) = ntype;
256 /* Same as above, but caller doesn't care about memory allocation details. */
259 lookup_reference_type (type)
262 return make_reference_type (type, (struct type **) 0);
265 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
266 to a pointer to memory where the function type should be stored.
267 If *TYPEPTR is zero, update it to point to the function type we return.
268 We allocate new memory if needed. */
271 make_function_type (type, typeptr)
273 struct type **typeptr;
275 register struct type *ntype; /* New type */
276 struct objfile *objfile;
278 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
280 ntype = alloc_type (TYPE_OBJFILE (type));
285 /* We have storage, but need to reset it. */
288 objfile = TYPE_OBJFILE (ntype);
289 memset ((char *) ntype, 0, sizeof (struct type));
290 TYPE_OBJFILE (ntype) = objfile;
293 TYPE_TARGET_TYPE (ntype) = type;
295 TYPE_LENGTH (ntype) = 1;
296 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
302 /* Given a type TYPE, return a type of functions that return that type.
303 May need to construct such a type if this is the first use. */
306 lookup_function_type (type)
309 return make_function_type (type, (struct type **) 0);
313 /* Make a "c-v" variant of a type -- a type that is identical to the
314 one supplied except that it may have const or volatile attributes
315 CNST is a flag for setting the const attribute
316 VOLTL is a flag for setting the volatile attribute
317 TYPE is the base type whose variant we are creating.
318 TYPEPTR, if nonzero, points
319 to a pointer to memory where the reference type should be stored.
320 If *TYPEPTR is zero, update it to point to the reference type we return.
321 We allocate new memory if needed. */
324 make_cv_type (cnst, voltl, type, typeptr)
328 struct type **typeptr;
330 register struct type *ntype; /* New type */
331 register struct type *tmp_type = type; /* tmp type */
332 struct objfile *objfile;
334 ntype = TYPE_CV_TYPE (type);
336 while (ntype != type)
338 if ((TYPE_CONST (ntype) == cnst) &&
339 (TYPE_VOLATILE (ntype) == voltl))
343 else if (*typeptr == 0)
345 *typeptr = ntype; /* Tracking alloc, and we have new type. */
350 ntype = TYPE_CV_TYPE (ntype);
353 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
355 ntype = alloc_type (TYPE_OBJFILE (type));
360 /* We have storage, but need to reset it. */
363 objfile = TYPE_OBJFILE (ntype);
364 /* memset ((char *) ntype, 0, sizeof (struct type)); */
365 TYPE_OBJFILE (ntype) = objfile;
368 /* Copy original type */
369 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
370 /* But zero out fields that shouldn't be copied */
371 TYPE_POINTER_TYPE (ntype) = (struct type *) 0; /* Need new pointer kind */
372 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; /* Need new referene kind */
373 /* Note: TYPE_TARGET_TYPE can be left as is */
375 /* Set flags appropriately */
377 TYPE_FLAGS (ntype) |= TYPE_FLAG_CONST;
379 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_CONST;
382 TYPE_FLAGS (ntype) |= TYPE_FLAG_VOLATILE;
384 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_VOLATILE;
386 /* Fix the chain of cv variants */
387 TYPE_CV_TYPE (ntype) = type;
388 TYPE_CV_TYPE (tmp_type) = ntype;
396 /* Implement direct support for MEMBER_TYPE in GNU C++.
397 May need to construct such a type if this is the first use.
398 The TYPE is the type of the member. The DOMAIN is the type
399 of the aggregate that the member belongs to. */
402 lookup_member_type (type, domain)
406 register struct type *mtype;
408 mtype = alloc_type (TYPE_OBJFILE (type));
409 smash_to_member_type (mtype, domain, type);
413 /* Allocate a stub method whose return type is TYPE.
414 This apparently happens for speed of symbol reading, since parsing
415 out the arguments to the method is cpu-intensive, the way we are doing
416 it. So, we will fill in arguments later.
417 This always returns a fresh type. */
420 allocate_stub_method (type)
425 mtype = alloc_type (TYPE_OBJFILE (type));
426 TYPE_TARGET_TYPE (mtype) = type;
427 /* _DOMAIN_TYPE (mtype) = unknown yet */
428 /* _ARG_TYPES (mtype) = unknown yet */
429 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
430 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
431 TYPE_LENGTH (mtype) = 1;
435 /* Create a range type using either a blank type supplied in RESULT_TYPE,
436 or creating a new type, inheriting the objfile from INDEX_TYPE.
438 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
439 HIGH_BOUND, inclusive.
441 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
442 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
445 create_range_type (result_type, index_type, low_bound, high_bound)
446 struct type *result_type;
447 struct type *index_type;
451 if (result_type == NULL)
453 result_type = alloc_type (TYPE_OBJFILE (index_type));
455 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
456 TYPE_TARGET_TYPE (result_type) = index_type;
457 if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB)
458 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
460 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
461 TYPE_NFIELDS (result_type) = 2;
462 TYPE_FIELDS (result_type) = (struct field *)
463 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
464 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
465 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
466 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
467 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
468 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
471 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
473 return (result_type);
476 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
477 Return 1 of type is a range type, 0 if it is discrete (and bounds
478 will fit in LONGEST), or -1 otherwise. */
481 get_discrete_bounds (type, lowp, highp)
483 LONGEST *lowp, *highp;
485 CHECK_TYPEDEF (type);
486 switch (TYPE_CODE (type))
488 case TYPE_CODE_RANGE:
489 *lowp = TYPE_LOW_BOUND (type);
490 *highp = TYPE_HIGH_BOUND (type);
493 if (TYPE_NFIELDS (type) > 0)
495 /* The enums may not be sorted by value, so search all
499 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
500 for (i = 0; i < TYPE_NFIELDS (type); i++)
502 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
503 *lowp = TYPE_FIELD_BITPOS (type, i);
504 if (TYPE_FIELD_BITPOS (type, i) > *highp)
505 *highp = TYPE_FIELD_BITPOS (type, i);
508 /* Set unsigned indicator if warranted. */
511 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
525 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
527 if (!TYPE_UNSIGNED (type))
529 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
533 /* ... fall through for unsigned ints ... */
536 /* This round-about calculation is to avoid shifting by
537 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
538 if TYPE_LENGTH (type) == sizeof (LONGEST). */
539 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
540 *highp = (*highp - 1) | *highp;
547 /* Create an array type using either a blank type supplied in RESULT_TYPE,
548 or creating a new type, inheriting the objfile from RANGE_TYPE.
550 Elements will be of type ELEMENT_TYPE, the indices will be of type
553 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
554 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
557 create_array_type (result_type, element_type, range_type)
558 struct type *result_type;
559 struct type *element_type;
560 struct type *range_type;
562 LONGEST low_bound, high_bound;
564 if (result_type == NULL)
566 result_type = alloc_type (TYPE_OBJFILE (range_type));
568 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
569 TYPE_TARGET_TYPE (result_type) = element_type;
570 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
571 low_bound = high_bound = 0;
572 CHECK_TYPEDEF (element_type);
573 TYPE_LENGTH (result_type) =
574 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
575 TYPE_NFIELDS (result_type) = 1;
576 TYPE_FIELDS (result_type) =
577 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
578 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
579 TYPE_FIELD_TYPE (result_type, 0) = range_type;
580 TYPE_VPTR_FIELDNO (result_type) = -1;
582 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
583 if (TYPE_LENGTH (result_type) == 0)
584 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
586 return (result_type);
589 /* Create a string type using either a blank type supplied in RESULT_TYPE,
590 or creating a new type. String types are similar enough to array of
591 char types that we can use create_array_type to build the basic type
592 and then bash it into a string type.
594 For fixed length strings, the range type contains 0 as the lower
595 bound and the length of the string minus one as the upper bound.
597 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
598 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
601 create_string_type (result_type, range_type)
602 struct type *result_type;
603 struct type *range_type;
605 result_type = create_array_type (result_type,
606 *current_language->string_char_type,
608 TYPE_CODE (result_type) = TYPE_CODE_STRING;
609 return (result_type);
613 create_set_type (result_type, domain_type)
614 struct type *result_type;
615 struct type *domain_type;
617 LONGEST low_bound, high_bound, bit_length;
618 if (result_type == NULL)
620 result_type = alloc_type (TYPE_OBJFILE (domain_type));
622 TYPE_CODE (result_type) = TYPE_CODE_SET;
623 TYPE_NFIELDS (result_type) = 1;
624 TYPE_FIELDS (result_type) = (struct field *)
625 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
626 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
628 if (!(TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB))
630 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
631 low_bound = high_bound = 0;
632 bit_length = high_bound - low_bound + 1;
633 TYPE_LENGTH (result_type)
634 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
636 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
639 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
641 return (result_type);
645 /* Construct and return a type of the form:
646 struct NAME { ELT_TYPE ELT_NAME[N]; }
647 We use these types for SIMD registers. For example, the type of
648 the SSE registers on the late x86-family processors is:
649 struct __builtin_v4sf { float f[4]; }
650 built by the function call:
651 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
652 The type returned is a permanent type, allocated using malloc; it
653 doesn't live in any objfile's obstack. */
655 init_simd_type (char *name,
656 struct type *elt_type,
663 /* Build the field structure. */
664 f = xmalloc (sizeof (*f));
665 memset (f, 0, sizeof (*f));
667 f->type = create_array_type (0, elt_type,
668 create_range_type (0, builtin_type_int,
672 /* Build a struct type with that field. */
673 t = init_type (TYPE_CODE_STRUCT, n * TYPE_LENGTH (elt_type), 0, 0, 0);
682 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
683 A MEMBER is a wierd thing -- it amounts to a typed offset into
684 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
685 include the offset (that's the value of the MEMBER itself), but does
686 include the structure type into which it points (for some reason).
688 When "smashing" the type, we preserve the objfile that the
689 old type pointed to, since we aren't changing where the type is actually
693 smash_to_member_type (type, domain, to_type)
696 struct type *to_type;
698 struct objfile *objfile;
700 objfile = TYPE_OBJFILE (type);
702 memset ((char *) type, 0, sizeof (struct type));
703 TYPE_OBJFILE (type) = objfile;
704 TYPE_TARGET_TYPE (type) = to_type;
705 TYPE_DOMAIN_TYPE (type) = domain;
706 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
707 TYPE_CODE (type) = TYPE_CODE_MEMBER;
710 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
711 METHOD just means `function that gets an extra "this" argument'.
713 When "smashing" the type, we preserve the objfile that the
714 old type pointed to, since we aren't changing where the type is actually
718 smash_to_method_type (type, domain, to_type, args)
721 struct type *to_type;
724 struct objfile *objfile;
726 objfile = TYPE_OBJFILE (type);
728 memset ((char *) type, 0, sizeof (struct type));
729 TYPE_OBJFILE (type) = objfile;
730 TYPE_TARGET_TYPE (type) = to_type;
731 TYPE_DOMAIN_TYPE (type) = domain;
732 TYPE_ARG_TYPES (type) = args;
733 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
734 TYPE_CODE (type) = TYPE_CODE_METHOD;
737 /* Return a typename for a struct/union/enum type without "struct ",
738 "union ", or "enum ". If the type has a NULL name, return NULL. */
741 type_name_no_tag (type)
742 register const struct type *type;
744 if (TYPE_TAG_NAME (type) != NULL)
745 return TYPE_TAG_NAME (type);
747 /* Is there code which expects this to return the name if there is no
748 tag name? My guess is that this is mainly used for C++ in cases where
749 the two will always be the same. */
750 return TYPE_NAME (type);
753 /* Lookup a primitive type named NAME.
754 Return zero if NAME is not a primitive type. */
757 lookup_primitive_typename (name)
760 struct type **const *p;
762 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
764 if (STREQ ((**p)->name, name))
772 /* Lookup a typedef or primitive type named NAME,
773 visible in lexical block BLOCK.
774 If NOERR is nonzero, return zero if NAME is not suitably defined. */
777 lookup_typename (name, block, noerr)
782 register struct symbol *sym;
783 register struct type *tmp;
785 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
786 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
788 tmp = lookup_primitive_typename (name);
793 else if (!tmp && noerr)
799 error ("No type named %s.", name);
802 return (SYMBOL_TYPE (sym));
806 lookup_unsigned_typename (name)
809 char *uns = alloca (strlen (name) + 10);
811 strcpy (uns, "unsigned ");
812 strcpy (uns + 9, name);
813 return (lookup_typename (uns, (struct block *) NULL, 0));
817 lookup_signed_typename (name)
821 char *uns = alloca (strlen (name) + 8);
823 strcpy (uns, "signed ");
824 strcpy (uns + 7, name);
825 t = lookup_typename (uns, (struct block *) NULL, 1);
826 /* If we don't find "signed FOO" just try again with plain "FOO". */
829 return lookup_typename (name, (struct block *) NULL, 0);
832 /* Lookup a structure type named "struct NAME",
833 visible in lexical block BLOCK. */
836 lookup_struct (name, block)
840 register struct symbol *sym;
842 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
843 (struct symtab **) NULL);
847 error ("No struct type named %s.", name);
849 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
851 error ("This context has class, union or enum %s, not a struct.", name);
853 return (SYMBOL_TYPE (sym));
856 /* Lookup a union type named "union NAME",
857 visible in lexical block BLOCK. */
860 lookup_union (name, block)
864 register struct symbol *sym;
867 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
868 (struct symtab **) NULL);
871 error ("No union type named %s.", name);
873 t = SYMBOL_TYPE (sym);
875 if (TYPE_CODE (t) == TYPE_CODE_UNION)
878 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
879 * a further "declared_type" field to discover it is really a union.
881 if (HAVE_CPLUS_STRUCT (t))
882 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
885 /* If we get here, it's not a union */
886 error ("This context has class, struct or enum %s, not a union.", name);
890 /* Lookup an enum type named "enum NAME",
891 visible in lexical block BLOCK. */
894 lookup_enum (name, block)
898 register struct symbol *sym;
900 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
901 (struct symtab **) NULL);
904 error ("No enum type named %s.", name);
906 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
908 error ("This context has class, struct or union %s, not an enum.", name);
910 return (SYMBOL_TYPE (sym));
913 /* Lookup a template type named "template NAME<TYPE>",
914 visible in lexical block BLOCK. */
917 lookup_template_type (name, type, block)
923 char *nam = (char *) alloca (strlen (name) + strlen (type->name) + 4);
926 strcat (nam, type->name);
927 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
929 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
933 error ("No template type named %s.", name);
935 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
937 error ("This context has class, union or enum %s, not a struct.", name);
939 return (SYMBOL_TYPE (sym));
942 /* Given a type TYPE, lookup the type of the component of type named NAME.
944 TYPE can be either a struct or union, or a pointer or reference to a struct or
945 union. If it is a pointer or reference, its target type is automatically used.
946 Thus '.' and '->' are interchangable, as specified for the definitions of the
947 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
949 If NOERR is nonzero, return zero if NAME is not suitably defined.
950 If NAME is the name of a baseclass type, return that type. */
953 lookup_struct_elt_type (type, name, noerr)
962 CHECK_TYPEDEF (type);
963 if (TYPE_CODE (type) != TYPE_CODE_PTR
964 && TYPE_CODE (type) != TYPE_CODE_REF)
966 type = TYPE_TARGET_TYPE (type);
969 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
970 TYPE_CODE (type) != TYPE_CODE_UNION)
972 target_terminal_ours ();
973 gdb_flush (gdb_stdout);
974 fprintf_unfiltered (gdb_stderr, "Type ");
975 type_print (type, "", gdb_stderr, -1);
976 error (" is not a structure or union type.");
980 /* FIXME: This change put in by Michael seems incorrect for the case where
981 the structure tag name is the same as the member name. I.E. when doing
982 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
987 typename = type_name_no_tag (type);
988 if (typename != NULL && STREQ (typename, name))
993 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
995 char *t_field_name = TYPE_FIELD_NAME (type, i);
997 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
999 return TYPE_FIELD_TYPE (type, i);
1003 /* OK, it's not in this class. Recursively check the baseclasses. */
1004 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1008 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1020 target_terminal_ours ();
1021 gdb_flush (gdb_stdout);
1022 fprintf_unfiltered (gdb_stderr, "Type ");
1023 type_print (type, "", gdb_stderr, -1);
1024 fprintf_unfiltered (gdb_stderr, " has no component named ");
1025 fputs_filtered (name, gdb_stderr);
1027 return (struct type *) -1; /* For lint */
1030 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1031 valid. Callers should be aware that in some cases (for example,
1032 the type or one of its baseclasses is a stub type and we are
1033 debugging a .o file), this function will not be able to find the virtual
1034 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1035 will remain NULL. */
1038 fill_in_vptr_fieldno (type)
1041 CHECK_TYPEDEF (type);
1043 if (TYPE_VPTR_FIELDNO (type) < 0)
1047 /* We must start at zero in case the first (and only) baseclass is
1048 virtual (and hence we cannot share the table pointer). */
1049 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1051 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
1052 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
1054 TYPE_VPTR_FIELDNO (type)
1055 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
1056 TYPE_VPTR_BASETYPE (type)
1057 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
1064 /* Find the method and field indices for the destructor in class type T.
1065 Return 1 if the destructor was found, otherwise, return 0. */
1068 get_destructor_fn_field (t, method_indexp, field_indexp)
1075 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1078 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1080 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1082 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j)))
1093 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1095 If this is a stubbed struct (i.e. declared as struct foo *), see if
1096 we can find a full definition in some other file. If so, copy this
1097 definition, so we can use it in future. There used to be a comment (but
1098 not any code) that if we don't find a full definition, we'd set a flag
1099 so we don't spend time in the future checking the same type. That would
1100 be a mistake, though--we might load in more symbols which contain a
1101 full definition for the type.
1103 This used to be coded as a macro, but I don't think it is called
1104 often enough to merit such treatment. */
1106 struct complaint stub_noname_complaint =
1107 {"stub type has NULL name", 0, 0};
1110 check_typedef (type)
1111 register struct type *type;
1113 struct type *orig_type = type;
1114 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1116 if (!TYPE_TARGET_TYPE (type))
1121 /* It is dangerous to call lookup_symbol if we are currently
1122 reading a symtab. Infinite recursion is one danger. */
1123 if (currently_reading_symtab)
1126 name = type_name_no_tag (type);
1127 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1128 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1129 as appropriate? (this code was written before TYPE_NAME and
1130 TYPE_TAG_NAME were separate). */
1133 complain (&stub_noname_complaint);
1136 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
1137 (struct symtab **) NULL);
1139 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1141 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1143 type = TYPE_TARGET_TYPE (type);
1146 /* If this is a struct/class/union with no fields, then check whether a
1147 full definition exists somewhere else. This is for systems where a
1148 type definition with no fields is issued for such types, instead of
1149 identifying them as stub types in the first place */
1151 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1153 char *name = type_name_no_tag (type);
1154 struct type *newtype;
1157 complain (&stub_noname_complaint);
1160 newtype = lookup_transparent_type (name);
1163 memcpy ((char *) type, (char *) newtype, sizeof (struct type));
1166 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1167 else if ((TYPE_FLAGS (type) & TYPE_FLAG_STUB) && !currently_reading_symtab)
1169 char *name = type_name_no_tag (type);
1170 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1171 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1172 as appropriate? (this code was written before TYPE_NAME and
1173 TYPE_TAG_NAME were separate). */
1177 complain (&stub_noname_complaint);
1180 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL);
1183 memcpy ((char *) type, (char *) SYMBOL_TYPE (sym), sizeof (struct type));
1187 if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB)
1189 struct type *range_type;
1190 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1192 if (TYPE_FLAGS (target_type) & (TYPE_FLAG_STUB | TYPE_FLAG_TARGET_STUB))
1195 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1196 && TYPE_NFIELDS (type) == 1
1197 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1198 == TYPE_CODE_RANGE))
1200 /* Now recompute the length of the array type, based on its
1201 number of elements and the target type's length. */
1202 TYPE_LENGTH (type) =
1203 ((TYPE_FIELD_BITPOS (range_type, 1)
1204 - TYPE_FIELD_BITPOS (range_type, 0)
1206 * TYPE_LENGTH (target_type));
1207 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1209 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1211 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1212 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1215 /* Cache TYPE_LENGTH for future use. */
1216 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1220 /* New code added to support parsing of Cfront stabs strings */
1222 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1223 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1226 add_name (pextras, n)
1227 struct extra *pextras;
1232 if ((nlen = (n ? strlen (n) : 0)) == 0)
1234 sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1235 pextras->len = strlen (pextras->str);
1239 add_mangled_type (pextras, t)
1240 struct extra *pextras;
1243 enum type_code tcode;
1247 tcode = TYPE_CODE (t);
1248 tlen = TYPE_LENGTH (t);
1249 tflags = TYPE_FLAGS (t);
1250 tname = TYPE_NAME (t);
1251 /* args of "..." seem to get mangled as "e" */
1269 if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1282 static struct complaint msg =
1283 {"Bad int type code length x%x\n", 0, 0};
1285 complain (&msg, tlen);
1304 static struct complaint msg =
1305 {"Bad float type code length x%x\n", 0, 0};
1306 complain (&msg, tlen);
1312 /* followed by what it's a ref to */
1316 /* followed by what it's a ptr to */
1318 case TYPE_CODE_TYPEDEF:
1320 static struct complaint msg =
1321 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1324 /* followed by type bytes & name */
1326 case TYPE_CODE_FUNC:
1328 /* followed by func's arg '_' & ret types */
1330 case TYPE_CODE_VOID:
1333 case TYPE_CODE_METHOD:
1335 /* followed by name of class and func's arg '_' & ret types */
1336 add_name (pextras, tname);
1337 ADD_EXTRA ('F'); /* then mangle function */
1339 case TYPE_CODE_STRUCT: /* C struct */
1340 case TYPE_CODE_UNION: /* C union */
1341 case TYPE_CODE_ENUM: /* Enumeration type */
1342 /* followed by name of type */
1343 add_name (pextras, tname);
1346 /* errors possible types/not supported */
1347 case TYPE_CODE_CHAR:
1348 case TYPE_CODE_ARRAY: /* Array type */
1349 case TYPE_CODE_MEMBER: /* Member type */
1350 case TYPE_CODE_BOOL:
1351 case TYPE_CODE_COMPLEX: /* Complex float */
1352 case TYPE_CODE_UNDEF:
1353 case TYPE_CODE_SET: /* Pascal sets */
1354 case TYPE_CODE_RANGE:
1355 case TYPE_CODE_STRING:
1356 case TYPE_CODE_BITSTRING:
1357 case TYPE_CODE_ERROR:
1360 static struct complaint msg =
1361 {"Unknown type code x%x\n", 0, 0};
1362 complain (&msg, tcode);
1366 add_mangled_type (pextras, t->target_type);
1371 cfront_mangle_name (type, i, j)
1377 char *mangled_name = gdb_mangle_name (type, i, j);
1379 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1381 /* kludge to support cfront methods - gdb expects to find "F" for
1382 ARM_mangled names, so when we mangle, we have to add it here */
1386 char *arm_mangled_name;
1387 struct fn_field *method = &f[j];
1388 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1389 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1390 char *newname = type_name_no_tag (type);
1392 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1393 int nargs = TYPE_NFIELDS (ftype); /* number of args */
1394 struct extra extras, *pextras = &extras;
1397 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1400 /* add args here! */
1401 if (nargs <= 1) /* no args besides this */
1405 for (k = 1; k < nargs; k++)
1408 t = TYPE_FIELD_TYPE (ftype, k);
1409 add_mangled_type (pextras, t);
1413 printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1414 arm_mangled_name = malloc (strlen (mangled_name) + extras.len);
1415 sprintf (arm_mangled_name, "%s%s", mangled_name, extras.str);
1416 free (mangled_name);
1417 mangled_name = arm_mangled_name;
1423 /* End of new code added to support parsing of Cfront stabs strings */
1425 /* Ugly hack to convert method stubs into method types.
1427 He ain't kiddin'. This demangles the name of the method into a string
1428 including argument types, parses out each argument type, generates
1429 a string casting a zero to that type, evaluates the string, and stuffs
1430 the resulting type into an argtype vector!!! Then it knows the type
1431 of the whole function (including argument types for overloading),
1432 which info used to be in the stab's but was removed to hack back
1433 the space required for them. */
1436 check_stub_method (type, method_id, signature_id)
1442 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1443 char *demangled_name = cplus_demangle (mangled_name,
1444 DMGL_PARAMS | DMGL_ANSI);
1445 char *argtypetext, *p;
1446 int depth = 0, argcount = 1;
1447 struct type **argtypes;
1450 /* Make sure we got back a function string that we can use. */
1452 p = strchr (demangled_name, '(');
1454 if (demangled_name == NULL || p == NULL)
1455 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1457 /* Now, read in the parameters that define this type. */
1470 else if (*p == ',' && depth == 0)
1478 /* We need two more slots: one for the THIS pointer, and one for the
1479 NULL [...] or void [end of arglist]. */
1481 argtypes = (struct type **)
1482 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
1484 /* FIXME: This is wrong for static member functions. */
1485 argtypes[0] = lookup_pointer_type (type);
1488 if (*p != ')') /* () means no args, skip while */
1493 if (depth <= 0 && (*p == ',' || *p == ')'))
1495 /* Avoid parsing of ellipsis, they will be handled below. */
1496 if (strncmp (argtypetext, "...", p - argtypetext) != 0)
1498 argtypes[argcount] =
1499 parse_and_eval_type (argtypetext, p - argtypetext);
1502 argtypetext = p + 1;
1518 if (p[-2] != '.') /* Not '...' */
1520 argtypes[argcount] = builtin_type_void; /* List terminator */
1524 argtypes[argcount] = NULL; /* Ellist terminator */
1527 free (demangled_name);
1529 f = TYPE_FN_FIELDLIST1 (type, method_id);
1531 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1533 /* Now update the old "stub" type into a real type. */
1534 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1535 TYPE_DOMAIN_TYPE (mtype) = type;
1536 TYPE_ARG_TYPES (mtype) = argtypes;
1537 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1538 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1541 const struct cplus_struct_type cplus_struct_default;
1544 allocate_cplus_struct_type (type)
1547 if (!HAVE_CPLUS_STRUCT (type))
1549 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1550 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1551 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1555 /* Helper function to initialize the standard scalar types.
1557 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1558 of the string pointed to by name in the type_obstack for that objfile,
1559 and initialize the type name to that copy. There are places (mipsread.c
1560 in particular, where init_type is called with a NULL value for NAME). */
1563 init_type (code, length, flags, name, objfile)
1564 enum type_code code;
1568 struct objfile *objfile;
1570 register struct type *type;
1572 type = alloc_type (objfile);
1573 TYPE_CODE (type) = code;
1574 TYPE_LENGTH (type) = length;
1575 TYPE_FLAGS (type) |= flags;
1576 if ((name != NULL) && (objfile != NULL))
1579 obsavestring (name, strlen (name), &objfile->type_obstack);
1583 TYPE_NAME (type) = name;
1588 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1590 INIT_CPLUS_SPECIFIC (type);
1595 /* Look up a fundamental type for the specified objfile.
1596 May need to construct such a type if this is the first use.
1598 Some object file formats (ELF, COFF, etc) do not define fundamental
1599 types such as "int" or "double". Others (stabs for example), do
1600 define fundamental types.
1602 For the formats which don't provide fundamental types, gdb can create
1603 such types, using defaults reasonable for the current language and
1604 the current target machine.
1606 NOTE: This routine is obsolescent. Each debugging format reader
1607 should manage it's own fundamental types, either creating them from
1608 suitable defaults or reading them from the debugging information,
1609 whichever is appropriate. The DWARF reader has already been
1610 fixed to do this. Once the other readers are fixed, this routine
1611 will go away. Also note that fundamental types should be managed
1612 on a compilation unit basis in a multi-language environment, not
1613 on a linkage unit basis as is done here. */
1617 lookup_fundamental_type (objfile, typeid)
1618 struct objfile *objfile;
1621 register struct type **typep;
1622 register int nbytes;
1624 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1626 error ("internal error - invalid fundamental type id %d", typeid);
1629 /* If this is the first time we need a fundamental type for this objfile
1630 then we need to initialize the vector of type pointers. */
1632 if (objfile->fundamental_types == NULL)
1634 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1635 objfile->fundamental_types = (struct type **)
1636 obstack_alloc (&objfile->type_obstack, nbytes);
1637 memset ((char *) objfile->fundamental_types, 0, nbytes);
1638 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1641 /* Look for this particular type in the fundamental type vector. If one is
1642 not found, create and install one appropriate for the current language. */
1644 typep = objfile->fundamental_types + typeid;
1647 *typep = create_fundamental_type (objfile, typeid);
1657 /* FIXME: Should we return true for references as well as pointers? */
1661 && TYPE_CODE (t) == TYPE_CODE_PTR
1662 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1666 is_integral_type (t)
1672 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1673 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1674 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1675 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1676 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1679 /* Chill varying string and arrays are represented as follows:
1681 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1683 Return true if TYPE is such a Chill varying type. */
1686 chill_varying_type (type)
1689 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1690 || TYPE_NFIELDS (type) != 2
1691 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1696 /* Check whether BASE is an ancestor or base class or DCLASS
1697 Return 1 if so, and 0 if not.
1698 Note: callers may want to check for identity of the types before
1699 calling this function -- identical types are considered to satisfy
1700 the ancestor relationship even if they're identical */
1703 is_ancestor (base, dclass)
1705 struct type *dclass;
1709 CHECK_TYPEDEF (base);
1710 CHECK_TYPEDEF (dclass);
1715 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1716 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1724 /* See whether DCLASS has a virtual table. This routine is aimed at
1725 the HP/Taligent ANSI C++ runtime model, and may not work with other
1726 runtime models. Return 1 => Yes, 0 => No. */
1730 struct type *dclass;
1732 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1733 has virtual functions or virtual bases. */
1737 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1740 /* First check for the presence of virtual bases */
1741 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1742 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1743 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1746 /* Next check for virtual functions */
1747 if (TYPE_FN_FIELDLISTS (dclass))
1748 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1749 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1752 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1753 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1754 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1755 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1756 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1759 /* Well, maybe we don't need a virtual table */
1763 /* Return a pointer to the "primary base class" of DCLASS.
1765 A NULL return indicates that DCLASS has no primary base, or that it
1766 couldn't be found (insufficient information).
1768 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1769 and may not work with other runtime models. */
1772 primary_base_class (dclass)
1773 struct type *dclass;
1775 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1776 is the first directly inherited, non-virtual base class that
1777 requires a virtual table */
1781 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1784 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1785 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1786 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1787 return TYPE_FIELD_TYPE (dclass, i);
1792 /* Global manipulated by virtual_base_list[_aux]() */
1794 static struct vbase *current_vbase_list = NULL;
1796 /* Return a pointer to a null-terminated list of struct vbase
1797 items. The vbasetype pointer of each item in the list points to the
1798 type information for a virtual base of the argument DCLASS.
1800 Helper function for virtual_base_list().
1801 Note: the list goes backward, right-to-left. virtual_base_list()
1802 copies the items out in reverse order. */
1805 virtual_base_list_aux (dclass)
1806 struct type *dclass;
1808 struct vbase *tmp_vbase;
1811 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1814 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1816 /* Recurse on this ancestor, first */
1817 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
1819 /* If this current base is itself virtual, add it to the list */
1820 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1822 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1824 /* Check if base already recorded */
1825 tmp_vbase = current_vbase_list;
1828 if (tmp_vbase->vbasetype == basetype)
1829 break; /* found it */
1830 tmp_vbase = tmp_vbase->next;
1833 if (!tmp_vbase) /* normal exit from loop */
1835 /* Allocate new item for this virtual base */
1836 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
1838 /* Stick it on at the end of the list */
1839 tmp_vbase->vbasetype = basetype;
1840 tmp_vbase->next = current_vbase_list;
1841 current_vbase_list = tmp_vbase;
1844 } /* for loop over bases */
1848 /* Compute the list of virtual bases in the right order. Virtual
1849 bases are laid out in the object's memory area in order of their
1850 occurrence in a depth-first, left-to-right search through the
1853 Argument DCLASS is the type whose virtual bases are required.
1854 Return value is the address of a null-terminated array of pointers
1855 to struct type items.
1857 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1858 and may not work with other runtime models.
1860 This routine merely hands off the argument to virtual_base_list_aux()
1861 and then copies the result into an array to save space. */
1864 virtual_base_list (dclass)
1865 struct type *dclass;
1867 register struct vbase *tmp_vbase;
1868 register struct vbase *tmp_vbase_2;
1871 struct type **vbase_array;
1873 current_vbase_list = NULL;
1874 virtual_base_list_aux (dclass);
1876 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1881 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
1883 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
1884 vbase_array[i] = tmp_vbase->vbasetype;
1886 /* Get rid of constructed chain */
1887 tmp_vbase_2 = tmp_vbase = current_vbase_list;
1890 tmp_vbase = tmp_vbase->next;
1892 tmp_vbase_2 = tmp_vbase;
1895 vbase_array[count] = NULL;
1899 /* Return the length of the virtual base list of the type DCLASS. */
1902 virtual_base_list_length (dclass)
1903 struct type *dclass;
1906 register struct vbase *tmp_vbase;
1908 current_vbase_list = NULL;
1909 virtual_base_list_aux (dclass);
1911 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1916 /* Return the number of elements of the virtual base list of the type
1917 DCLASS, ignoring those appearing in the primary base (and its
1918 primary base, recursively). */
1921 virtual_base_list_length_skip_primaries (dclass)
1922 struct type *dclass;
1925 register struct vbase *tmp_vbase;
1926 struct type *primary;
1928 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
1931 return virtual_base_list_length (dclass);
1933 current_vbase_list = NULL;
1934 virtual_base_list_aux (dclass);
1936 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
1938 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
1946 /* Return the index (position) of type BASE, which is a virtual base
1947 class of DCLASS, in the latter's virtual base list. A return of -1
1948 indicates "not found" or a problem. */
1951 virtual_base_index (base, dclass)
1953 struct type *dclass;
1955 register struct type *vbase;
1958 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
1959 (TYPE_CODE (base) != TYPE_CODE_CLASS))
1963 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0];
1968 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i];
1971 return vbase ? i : -1;
1976 /* Return the index (position) of type BASE, which is a virtual base
1977 class of DCLASS, in the latter's virtual base list. Skip over all
1978 bases that may appear in the virtual base list of the primary base
1979 class of DCLASS (recursively). A return of -1 indicates "not
1980 found" or a problem. */
1983 virtual_base_index_skip_primaries (base, dclass)
1985 struct type *dclass;
1987 register struct type *vbase;
1989 struct type *primary;
1991 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
1992 (TYPE_CODE (base) != TYPE_CODE_CLASS))
1995 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
1999 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0];
2002 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2006 vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i];
2009 return vbase ? j : -1;
2012 /* Return position of a derived class DCLASS in the list of
2013 * primary bases starting with the remotest ancestor.
2014 * Position returned is 0-based. */
2017 class_index_in_primary_list (dclass)
2018 struct type *dclass;
2020 struct type *pbc; /* primary base class */
2022 /* Simply recurse on primary base */
2023 pbc = TYPE_PRIMARY_BASE (dclass);
2025 return 1 + class_index_in_primary_list (pbc);
2030 /* Return a count of the number of virtual functions a type has.
2031 * This includes all the virtual functions it inherits from its
2035 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2036 * functions only once (latest redefinition)
2040 count_virtual_fns (dclass)
2041 struct type *dclass;
2043 int fn, oi; /* function and overloaded instance indices */
2044 int vfuncs; /* count to return */
2046 /* recurse on bases that can share virtual table */
2047 struct type *pbc = primary_base_class (dclass);
2049 vfuncs = count_virtual_fns (pbc);
2051 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2052 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2053 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2061 /* Functions for overload resolution begin here */
2063 /* Compare two badness vectors A and B and return the result.
2064 * 0 => A and B are identical
2065 * 1 => A and B are incomparable
2066 * 2 => A is better than B
2067 * 3 => A is worse than B */
2070 compare_badness (a, b)
2071 struct badness_vector *a;
2072 struct badness_vector *b;
2076 short found_pos = 0; /* any positives in c? */
2077 short found_neg = 0; /* any negatives in c? */
2079 /* differing lengths => incomparable */
2080 if (a->length != b->length)
2083 /* Subtract b from a */
2084 for (i = 0; i < a->length; i++)
2086 tmp = a->rank[i] - b->rank[i];
2096 return 1; /* incomparable */
2098 return 3; /* A > B */
2104 return 2; /* A < B */
2106 return 0; /* A == B */
2110 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2111 * to the types of an argument list (ARGS, length NARGS).
2112 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2114 struct badness_vector *
2115 rank_function (parms, nparms, args, nargs)
2116 struct type **parms;
2122 struct badness_vector *bv;
2123 int min_len = nparms < nargs ? nparms : nargs;
2125 bv = xmalloc (sizeof (struct badness_vector));
2126 bv->length = nargs + 1; /* add 1 for the length-match rank */
2127 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2129 /* First compare the lengths of the supplied lists.
2130 * If there is a mismatch, set it to a high value. */
2132 /* pai/1997-06-03 FIXME: when we have debug info about default
2133 * arguments and ellipsis parameter lists, we should consider those
2134 * and rank the length-match more finely. */
2136 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2138 /* Now rank all the parameters of the candidate function */
2139 for (i = 1; i < min_len; i++)
2140 bv->rank[i] = rank_one_type (parms[i], args[i]);
2142 /* If more arguments than parameters, add dummy entries */
2143 for (i = min_len + 1; i <= nargs; i++)
2144 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2149 /* Compare one type (PARM) for compatibility with another (ARG).
2150 * PARM is intended to be the parameter type of a function; and
2151 * ARG is the supplied argument's type. This function tests if
2152 * the latter can be converted to the former.
2154 * Return 0 if they are identical types;
2155 * Otherwise, return an integer which corresponds to how compatible
2156 * PARM is to ARG. The higher the return value, the worse the match.
2157 * Generally the "bad" conversions are all uniformly assigned a 100 */
2160 rank_one_type (parm, arg)
2164 /* Identical type pointers */
2165 /* However, this still doesn't catch all cases of same type for arg
2166 * and param. The reason is that builtin types are different from
2167 * the same ones constructed from the object. */
2171 /* Resolve typedefs */
2172 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2173 parm = check_typedef (parm);
2174 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2175 arg = check_typedef (arg);
2177 /* Check if identical after resolving typedefs */
2181 /* See through references, since we can almost make non-references
2183 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2184 return (rank_one_type (TYPE_TARGET_TYPE (arg), parm)
2185 + REFERENCE_CONVERSION_BADNESS);
2186 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2187 return (rank_one_type (arg, TYPE_TARGET_TYPE (parm))
2188 + REFERENCE_CONVERSION_BADNESS);
2191 /* Debugging only. */
2192 /* FIXME/FYI: cagney/2000-03-13: No need to #ifdef this sort of
2193 thing. Instead add a command like ``set debug gdbtypes <int>''.
2194 (A predicate to this is the addition of the ``set debug''). Also,
2195 send the output to gdb_stderr and don't use printf. */
2196 printf ("------ Arg is %s [%d], parm is %s [%d]\n",
2197 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2200 /* x -> y means arg of type x being supplied for parameter of type y */
2202 switch (TYPE_CODE (parm))
2205 switch (TYPE_CODE (arg))
2208 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2209 return VOID_PTR_CONVERSION_BADNESS;
2211 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2212 case TYPE_CODE_ARRAY:
2213 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2214 case TYPE_CODE_FUNC:
2215 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2217 case TYPE_CODE_ENUM:
2218 case TYPE_CODE_CHAR:
2219 case TYPE_CODE_RANGE:
2220 case TYPE_CODE_BOOL:
2221 return POINTER_CONVERSION_BADNESS;
2223 return INCOMPATIBLE_TYPE_BADNESS;
2225 case TYPE_CODE_ARRAY:
2226 switch (TYPE_CODE (arg))
2229 case TYPE_CODE_ARRAY:
2230 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2232 return INCOMPATIBLE_TYPE_BADNESS;
2234 case TYPE_CODE_FUNC:
2235 switch (TYPE_CODE (arg))
2237 case TYPE_CODE_PTR: /* funcptr -> func */
2238 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2240 return INCOMPATIBLE_TYPE_BADNESS;
2243 switch (TYPE_CODE (arg))
2246 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2248 /* Deal with signed, unsigned, and plain chars and
2249 signed and unsigned ints */
2250 if (TYPE_NOSIGN (parm))
2252 /* This case only for character types */
2253 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2256 return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */
2258 else if (TYPE_UNSIGNED (parm))
2260 if (TYPE_UNSIGNED (arg))
2262 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2263 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2264 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2265 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2267 return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
2271 if (!strcmp_iw (TYPE_NAME (arg), "long") && !strcmp_iw (TYPE_NAME (parm), "int"))
2272 return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
2274 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2277 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2279 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2281 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2282 return INTEGER_PROMOTION_BADNESS;
2284 return INTEGER_COERCION_BADNESS;
2287 return INTEGER_COERCION_BADNESS;
2289 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2290 return INTEGER_PROMOTION_BADNESS;
2292 return INTEGER_COERCION_BADNESS;
2293 case TYPE_CODE_ENUM:
2294 case TYPE_CODE_CHAR:
2295 case TYPE_CODE_RANGE:
2296 case TYPE_CODE_BOOL:
2297 return INTEGER_PROMOTION_BADNESS;
2299 return INT_FLOAT_CONVERSION_BADNESS;
2301 return NS_POINTER_CONVERSION_BADNESS;
2303 return INCOMPATIBLE_TYPE_BADNESS;
2306 case TYPE_CODE_ENUM:
2307 switch (TYPE_CODE (arg))
2310 case TYPE_CODE_CHAR:
2311 case TYPE_CODE_RANGE:
2312 case TYPE_CODE_BOOL:
2313 case TYPE_CODE_ENUM:
2314 return INTEGER_COERCION_BADNESS;
2316 return INT_FLOAT_CONVERSION_BADNESS;
2318 return INCOMPATIBLE_TYPE_BADNESS;
2321 case TYPE_CODE_CHAR:
2322 switch (TYPE_CODE (arg))
2324 case TYPE_CODE_RANGE:
2325 case TYPE_CODE_BOOL:
2326 case TYPE_CODE_ENUM:
2327 return INTEGER_COERCION_BADNESS;
2329 return INT_FLOAT_CONVERSION_BADNESS;
2331 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2332 return INTEGER_COERCION_BADNESS;
2333 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2334 return INTEGER_PROMOTION_BADNESS;
2335 /* >>> !! else fall through !! <<< */
2336 case TYPE_CODE_CHAR:
2337 /* Deal with signed, unsigned, and plain chars for C++
2338 and with int cases falling through from previous case */
2339 if (TYPE_NOSIGN (parm))
2341 if (TYPE_NOSIGN (arg))
2344 return INTEGER_COERCION_BADNESS;
2346 else if (TYPE_UNSIGNED (parm))
2348 if (TYPE_UNSIGNED (arg))
2351 return INTEGER_PROMOTION_BADNESS;
2353 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2356 return INTEGER_COERCION_BADNESS;
2358 return INCOMPATIBLE_TYPE_BADNESS;
2361 case TYPE_CODE_RANGE:
2362 switch (TYPE_CODE (arg))
2365 case TYPE_CODE_CHAR:
2366 case TYPE_CODE_RANGE:
2367 case TYPE_CODE_BOOL:
2368 case TYPE_CODE_ENUM:
2369 return INTEGER_COERCION_BADNESS;
2371 return INT_FLOAT_CONVERSION_BADNESS;
2373 return INCOMPATIBLE_TYPE_BADNESS;
2376 case TYPE_CODE_BOOL:
2377 switch (TYPE_CODE (arg))
2380 case TYPE_CODE_CHAR:
2381 case TYPE_CODE_RANGE:
2382 case TYPE_CODE_ENUM:
2385 return BOOLEAN_CONVERSION_BADNESS;
2386 case TYPE_CODE_BOOL:
2389 return INCOMPATIBLE_TYPE_BADNESS;
2393 switch (TYPE_CODE (arg))
2396 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2397 return FLOAT_PROMOTION_BADNESS;
2398 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2401 return FLOAT_CONVERSION_BADNESS;
2403 case TYPE_CODE_BOOL:
2404 case TYPE_CODE_ENUM:
2405 case TYPE_CODE_RANGE:
2406 case TYPE_CODE_CHAR:
2407 return INT_FLOAT_CONVERSION_BADNESS;
2409 return INCOMPATIBLE_TYPE_BADNESS;
2412 case TYPE_CODE_COMPLEX:
2413 switch (TYPE_CODE (arg))
2414 { /* Strictly not needed for C++, but... */
2416 return FLOAT_PROMOTION_BADNESS;
2417 case TYPE_CODE_COMPLEX:
2420 return INCOMPATIBLE_TYPE_BADNESS;
2423 case TYPE_CODE_STRUCT:
2424 /* currently same as TYPE_CODE_CLASS */
2425 switch (TYPE_CODE (arg))
2427 case TYPE_CODE_STRUCT:
2428 /* Check for derivation */
2429 if (is_ancestor (parm, arg))
2430 return BASE_CONVERSION_BADNESS;
2431 /* else fall through */
2433 return INCOMPATIBLE_TYPE_BADNESS;
2436 case TYPE_CODE_UNION:
2437 switch (TYPE_CODE (arg))
2439 case TYPE_CODE_UNION:
2441 return INCOMPATIBLE_TYPE_BADNESS;
2444 case TYPE_CODE_MEMBER:
2445 switch (TYPE_CODE (arg))
2448 return INCOMPATIBLE_TYPE_BADNESS;
2451 case TYPE_CODE_METHOD:
2452 switch (TYPE_CODE (arg))
2456 return INCOMPATIBLE_TYPE_BADNESS;
2460 switch (TYPE_CODE (arg))
2464 return INCOMPATIBLE_TYPE_BADNESS;
2469 switch (TYPE_CODE (arg))
2473 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2475 return INCOMPATIBLE_TYPE_BADNESS;
2478 case TYPE_CODE_VOID:
2480 return INCOMPATIBLE_TYPE_BADNESS;
2481 } /* switch (TYPE_CODE (arg)) */
2485 /* End of functions for overload resolution */
2488 print_bit_vector (bits, nbits)
2494 for (bitno = 0; bitno < nbits; bitno++)
2496 if ((bitno % 8) == 0)
2498 puts_filtered (" ");
2500 if (B_TST (bits, bitno))
2502 printf_filtered ("1");
2506 printf_filtered ("0");
2511 /* The args list is a strange beast. It is either terminated by a NULL
2512 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2513 type for normal fixed argcount functions. (FIXME someday)
2514 Also note the first arg should be the "this" pointer, we may not want to
2515 include it since we may get into a infinitely recursive situation. */
2518 print_arg_types (args, spaces)
2524 while (*args != NULL)
2526 recursive_dump_type (*args, spaces + 2);
2527 if ((*args++)->code == TYPE_CODE_VOID)
2536 dump_fn_fieldlists (type, spaces)
2544 printfi_filtered (spaces, "fn_fieldlists ");
2545 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2546 printf_filtered ("\n");
2547 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2549 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2550 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2552 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2553 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2555 printf_filtered (") length %d\n",
2556 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2557 for (overload_idx = 0;
2558 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2561 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2563 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2564 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2566 printf_filtered (")\n");
2567 printfi_filtered (spaces + 8, "type ");
2568 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2569 printf_filtered ("\n");
2571 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2574 printfi_filtered (spaces + 8, "args ");
2575 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2576 printf_filtered ("\n");
2578 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
2579 printfi_filtered (spaces + 8, "fcontext ");
2580 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2582 printf_filtered ("\n");
2584 printfi_filtered (spaces + 8, "is_const %d\n",
2585 TYPE_FN_FIELD_CONST (f, overload_idx));
2586 printfi_filtered (spaces + 8, "is_volatile %d\n",
2587 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2588 printfi_filtered (spaces + 8, "is_private %d\n",
2589 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2590 printfi_filtered (spaces + 8, "is_protected %d\n",
2591 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2592 printfi_filtered (spaces + 8, "is_stub %d\n",
2593 TYPE_FN_FIELD_STUB (f, overload_idx));
2594 printfi_filtered (spaces + 8, "voffset %u\n",
2595 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2601 print_cplus_stuff (type, spaces)
2605 printfi_filtered (spaces, "n_baseclasses %d\n",
2606 TYPE_N_BASECLASSES (type));
2607 printfi_filtered (spaces, "nfn_fields %d\n",
2608 TYPE_NFN_FIELDS (type));
2609 printfi_filtered (spaces, "nfn_fields_total %d\n",
2610 TYPE_NFN_FIELDS_TOTAL (type));
2611 if (TYPE_N_BASECLASSES (type) > 0)
2613 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2614 TYPE_N_BASECLASSES (type));
2615 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2616 printf_filtered (")");
2618 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2619 TYPE_N_BASECLASSES (type));
2620 puts_filtered ("\n");
2622 if (TYPE_NFIELDS (type) > 0)
2624 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2626 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2627 TYPE_NFIELDS (type));
2628 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2629 printf_filtered (")");
2630 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2631 TYPE_NFIELDS (type));
2632 puts_filtered ("\n");
2634 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2636 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2637 TYPE_NFIELDS (type));
2638 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2639 printf_filtered (")");
2640 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2641 TYPE_NFIELDS (type));
2642 puts_filtered ("\n");
2645 if (TYPE_NFN_FIELDS (type) > 0)
2647 dump_fn_fieldlists (type, spaces);
2651 static struct obstack dont_print_type_obstack;
2654 recursive_dump_type (type, spaces)
2661 obstack_begin (&dont_print_type_obstack, 0);
2663 if (TYPE_NFIELDS (type) > 0
2664 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2666 struct type **first_dont_print
2667 = (struct type **) obstack_base (&dont_print_type_obstack);
2669 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2674 if (type == first_dont_print[i])
2676 printfi_filtered (spaces, "type node ");
2677 gdb_print_host_address (type, gdb_stdout);
2678 printf_filtered (" <same as already seen type>\n");
2683 obstack_ptr_grow (&dont_print_type_obstack, type);
2686 printfi_filtered (spaces, "type node ");
2687 gdb_print_host_address (type, gdb_stdout);
2688 printf_filtered ("\n");
2689 printfi_filtered (spaces, "name '%s' (",
2690 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2691 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2692 printf_filtered (")\n");
2693 if (TYPE_TAG_NAME (type) != NULL)
2695 printfi_filtered (spaces, "tagname '%s' (",
2696 TYPE_TAG_NAME (type));
2697 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2698 printf_filtered (")\n");
2700 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2701 switch (TYPE_CODE (type))
2703 case TYPE_CODE_UNDEF:
2704 printf_filtered ("(TYPE_CODE_UNDEF)");
2707 printf_filtered ("(TYPE_CODE_PTR)");
2709 case TYPE_CODE_ARRAY:
2710 printf_filtered ("(TYPE_CODE_ARRAY)");
2712 case TYPE_CODE_STRUCT:
2713 printf_filtered ("(TYPE_CODE_STRUCT)");
2715 case TYPE_CODE_UNION:
2716 printf_filtered ("(TYPE_CODE_UNION)");
2718 case TYPE_CODE_ENUM:
2719 printf_filtered ("(TYPE_CODE_ENUM)");
2721 case TYPE_CODE_FUNC:
2722 printf_filtered ("(TYPE_CODE_FUNC)");
2725 printf_filtered ("(TYPE_CODE_INT)");
2728 printf_filtered ("(TYPE_CODE_FLT)");
2730 case TYPE_CODE_VOID:
2731 printf_filtered ("(TYPE_CODE_VOID)");
2734 printf_filtered ("(TYPE_CODE_SET)");
2736 case TYPE_CODE_RANGE:
2737 printf_filtered ("(TYPE_CODE_RANGE)");
2739 case TYPE_CODE_STRING:
2740 printf_filtered ("(TYPE_CODE_STRING)");
2742 case TYPE_CODE_ERROR:
2743 printf_filtered ("(TYPE_CODE_ERROR)");
2745 case TYPE_CODE_MEMBER:
2746 printf_filtered ("(TYPE_CODE_MEMBER)");
2748 case TYPE_CODE_METHOD:
2749 printf_filtered ("(TYPE_CODE_METHOD)");
2752 printf_filtered ("(TYPE_CODE_REF)");
2754 case TYPE_CODE_CHAR:
2755 printf_filtered ("(TYPE_CODE_CHAR)");
2757 case TYPE_CODE_BOOL:
2758 printf_filtered ("(TYPE_CODE_BOOL)");
2760 case TYPE_CODE_TYPEDEF:
2761 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2764 printf_filtered ("(UNKNOWN TYPE CODE)");
2767 puts_filtered ("\n");
2768 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2769 printfi_filtered (spaces, "objfile ");
2770 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2771 printf_filtered ("\n");
2772 printfi_filtered (spaces, "target_type ");
2773 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2774 printf_filtered ("\n");
2775 if (TYPE_TARGET_TYPE (type) != NULL)
2777 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2779 printfi_filtered (spaces, "pointer_type ");
2780 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2781 printf_filtered ("\n");
2782 printfi_filtered (spaces, "reference_type ");
2783 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2784 printf_filtered ("\n");
2785 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
2786 if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED)
2788 puts_filtered (" TYPE_FLAG_UNSIGNED");
2790 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
2792 puts_filtered (" TYPE_FLAG_STUB");
2794 puts_filtered ("\n");
2795 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
2796 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
2797 puts_filtered ("\n");
2798 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
2800 printfi_filtered (spaces + 2,
2801 "[%d] bitpos %d bitsize %d type ",
2802 idx, TYPE_FIELD_BITPOS (type, idx),
2803 TYPE_FIELD_BITSIZE (type, idx));
2804 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
2805 printf_filtered (" name '%s' (",
2806 TYPE_FIELD_NAME (type, idx) != NULL
2807 ? TYPE_FIELD_NAME (type, idx)
2809 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
2810 printf_filtered (")\n");
2811 if (TYPE_FIELD_TYPE (type, idx) != NULL)
2813 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
2816 printfi_filtered (spaces, "vptr_basetype ");
2817 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
2818 puts_filtered ("\n");
2819 if (TYPE_VPTR_BASETYPE (type) != NULL)
2821 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
2823 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
2824 switch (TYPE_CODE (type))
2826 case TYPE_CODE_METHOD:
2827 case TYPE_CODE_FUNC:
2828 printfi_filtered (spaces, "arg_types ");
2829 gdb_print_host_address (TYPE_ARG_TYPES (type), gdb_stdout);
2830 puts_filtered ("\n");
2831 print_arg_types (TYPE_ARG_TYPES (type), spaces);
2834 case TYPE_CODE_STRUCT:
2835 printfi_filtered (spaces, "cplus_stuff ");
2836 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2837 puts_filtered ("\n");
2838 print_cplus_stuff (type, spaces);
2842 /* We have to pick one of the union types to be able print and test
2843 the value. Pick cplus_struct_type, even though we know it isn't
2844 any particular one. */
2845 printfi_filtered (spaces, "type_specific ");
2846 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2847 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
2849 printf_filtered (" (unknown data form)");
2851 printf_filtered ("\n");
2856 obstack_free (&dont_print_type_obstack, NULL);
2859 static void build_gdbtypes PARAMS ((void));
2864 init_type (TYPE_CODE_VOID, 1,
2866 "void", (struct objfile *) NULL);
2868 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2870 "char", (struct objfile *) NULL);
2871 TYPE_FLAGS (builtin_type_char) |= TYPE_FLAG_NOSIGN;
2872 builtin_type_true_char =
2873 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2875 "true character", (struct objfile *) NULL);
2876 builtin_type_signed_char =
2877 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2879 "signed char", (struct objfile *) NULL);
2880 builtin_type_unsigned_char =
2881 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2883 "unsigned char", (struct objfile *) NULL);
2884 builtin_type_short =
2885 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
2887 "short", (struct objfile *) NULL);
2888 builtin_type_unsigned_short =
2889 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
2891 "unsigned short", (struct objfile *) NULL);
2893 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
2895 "int", (struct objfile *) NULL);
2896 builtin_type_unsigned_int =
2897 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
2899 "unsigned int", (struct objfile *) NULL);
2901 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
2903 "long", (struct objfile *) NULL);
2904 builtin_type_unsigned_long =
2905 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
2907 "unsigned long", (struct objfile *) NULL);
2908 builtin_type_long_long =
2909 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2911 "long long", (struct objfile *) NULL);
2912 builtin_type_unsigned_long_long =
2913 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2915 "unsigned long long", (struct objfile *) NULL);
2916 builtin_type_float =
2917 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
2919 "float", (struct objfile *) NULL);
2920 builtin_type_double =
2921 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
2923 "double", (struct objfile *) NULL);
2924 builtin_type_long_double =
2925 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
2927 "long double", (struct objfile *) NULL);
2928 builtin_type_complex =
2929 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
2931 "complex", (struct objfile *) NULL);
2932 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
2933 builtin_type_double_complex =
2934 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
2936 "double complex", (struct objfile *) NULL);
2937 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
2938 builtin_type_string =
2939 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2941 "string", (struct objfile *) NULL);
2943 init_type (TYPE_CODE_INT, 8 / 8,
2945 "int8_t", (struct objfile *) NULL);
2946 builtin_type_uint8 =
2947 init_type (TYPE_CODE_INT, 8 / 8,
2949 "uint8_t", (struct objfile *) NULL);
2950 builtin_type_int16 =
2951 init_type (TYPE_CODE_INT, 16 / 8,
2953 "int16_t", (struct objfile *) NULL);
2954 builtin_type_uint16 =
2955 init_type (TYPE_CODE_INT, 16 / 8,
2957 "uint16_t", (struct objfile *) NULL);
2958 builtin_type_int32 =
2959 init_type (TYPE_CODE_INT, 32 / 8,
2961 "int32_t", (struct objfile *) NULL);
2962 builtin_type_uint32 =
2963 init_type (TYPE_CODE_INT, 32 / 8,
2965 "uint32_t", (struct objfile *) NULL);
2966 builtin_type_int64 =
2967 init_type (TYPE_CODE_INT, 64 / 8,
2969 "int64_t", (struct objfile *) NULL);
2970 builtin_type_uint64 =
2971 init_type (TYPE_CODE_INT, 64 / 8,
2973 "uint64_t", (struct objfile *) NULL);
2975 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2977 "bool", (struct objfile *) NULL);
2979 /* Add user knob for controlling resolution of opaque types */
2981 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
2982 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
2985 opaque_type_resolution = 1;
2988 /* Build SIMD types. */
2990 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
2992 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
2994 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
2996 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
2998 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
3000 /* Pointer/Address types. */
3001 /* NOTE: At present there is no way of differentiating between at
3002 target address and the target C language pointer type type even
3003 though the two can be different (cf d10v) */
3005 init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8,
3007 "__ptr", (struct objfile *) NULL);
3008 builtin_type_CORE_ADDR =
3009 init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8,
3011 "__CORE_ADDR", (struct objfile *) NULL);
3012 builtin_type_bfd_vma =
3013 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3015 "__bfd_vma", (struct objfile *) NULL);
3019 extern void _initialize_gdbtypes PARAMS ((void));
3021 _initialize_gdbtypes ()
3025 /* FIXME - For the moment, handle types by swapping them in and out.
3026 Should be using the per-architecture data-pointer and a large
3028 register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL);
3029 register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL);
3030 register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL);
3031 register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL);
3032 register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL);
3033 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL);
3034 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL);
3035 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL);
3036 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL);
3037 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL);
3038 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL);
3039 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL);
3040 register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL);
3041 register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL);
3042 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL);
3043 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL);
3044 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL);
3045 register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL);
3046 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL);
3047 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL);
3048 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL);
3049 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL);
3050 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL);
3051 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
3052 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
3053 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
3054 register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
3055 register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL);
3056 register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL);
3057 register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
3058 register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
3059 REGISTER_GDBARCH_SWAP (builtin_type_ptr);
3060 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3061 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3062 register_gdbarch_swap (NULL, 0, build_gdbtypes);