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, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
28 #include "expression.h"
33 #include "complaints.h"
36 /* These variables point to the objects
37 representing the predefined C data types. */
39 struct type *builtin_type_void;
40 struct type *builtin_type_char;
41 struct type *builtin_type_short;
42 struct type *builtin_type_int;
43 struct type *builtin_type_long;
44 struct type *builtin_type_long_long;
45 struct type *builtin_type_signed_char;
46 struct type *builtin_type_unsigned_char;
47 struct type *builtin_type_unsigned_short;
48 struct type *builtin_type_unsigned_int;
49 struct type *builtin_type_unsigned_long;
50 struct type *builtin_type_unsigned_long_long;
51 struct type *builtin_type_float;
52 struct type *builtin_type_double;
53 struct type *builtin_type_long_double;
54 struct type *builtin_type_complex;
55 struct type *builtin_type_double_complex;
56 struct type *builtin_type_string;
57 struct type *builtin_type_int8;
58 struct type *builtin_type_uint8;
59 struct type *builtin_type_int16;
60 struct type *builtin_type_uint16;
61 struct type *builtin_type_int32;
62 struct type *builtin_type_uint32;
63 struct type *builtin_type_int64;
64 struct type *builtin_type_uint64;
65 struct type *builtin_type_bool;
67 int opaque_type_resolution = 1;
70 struct extra { char str[128]; int len; }; /* maximum extention is 128! FIXME */
72 static void add_name PARAMS ((struct extra *, char *));
73 static void add_mangled_type PARAMS ((struct extra *, struct type *));
75 static void cfront_mangle_name PARAMS ((struct type *, int, int));
77 static void print_bit_vector PARAMS ((B_TYPE *, int));
78 static void print_arg_types PARAMS ((struct type **, int));
79 static void dump_fn_fieldlists PARAMS ((struct type *, int));
80 static void print_cplus_stuff PARAMS ((struct type *, int));
82 /* Alloc a new type structure and fill it with some defaults. If
83 OBJFILE is non-NULL, then allocate the space for the type structure
84 in that objfile's type_obstack. */
88 struct objfile *objfile;
90 register struct type *type;
92 /* Alloc the structure and start off with all fields zeroed. */
96 type = (struct type *) xmalloc (sizeof (struct type));
100 type = (struct type *) obstack_alloc (&objfile -> type_obstack,
101 sizeof (struct type));
102 OBJSTAT (objfile, n_types++);
104 memset ((char *) type, 0, sizeof (struct type));
106 /* Initialize the fields that might not be zero. */
108 TYPE_CODE (type) = TYPE_CODE_UNDEF;
109 TYPE_OBJFILE (type) = objfile;
110 TYPE_VPTR_FIELDNO (type) = -1;
111 TYPE_CV_TYPE (type) = type; /* chain back to itself */
116 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
117 to a pointer to memory where the pointer type should be stored.
118 If *TYPEPTR is zero, update it to point to the pointer type we return.
119 We allocate new memory if needed. */
122 make_pointer_type (type, typeptr)
124 struct type **typeptr;
126 register struct type *ntype; /* New type */
127 struct objfile *objfile;
129 ntype = TYPE_POINTER_TYPE (type);
134 return ntype; /* Don't care about alloc, and have new type. */
135 else if (*typeptr == 0)
137 *typeptr = ntype; /* Tracking alloc, and we have new type. */
142 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
144 ntype = alloc_type (TYPE_OBJFILE (type));
148 else /* We have storage, but need to reset it. */
151 objfile = TYPE_OBJFILE (ntype);
152 memset ((char *) ntype, 0, sizeof (struct type));
153 TYPE_OBJFILE (ntype) = objfile;
156 TYPE_TARGET_TYPE (ntype) = type;
157 TYPE_POINTER_TYPE (type) = ntype;
159 /* FIXME! Assume the machine has only one representation for pointers! */
161 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
162 TYPE_CODE (ntype) = TYPE_CODE_PTR;
164 /* pointers are unsigned */
165 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
167 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
168 TYPE_POINTER_TYPE (type) = ntype;
173 /* Given a type TYPE, return a type of pointers to that type.
174 May need to construct such a type if this is the first use. */
177 lookup_pointer_type (type)
180 return make_pointer_type (type, (struct type **)0);
183 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
184 to a pointer to memory where the reference type should be stored.
185 If *TYPEPTR is zero, update it to point to the reference type we return.
186 We allocate new memory if needed. */
189 make_reference_type (type, typeptr)
191 struct type **typeptr;
193 register struct type *ntype; /* New type */
194 struct objfile *objfile;
196 ntype = TYPE_REFERENCE_TYPE (type);
201 return ntype; /* Don't care about alloc, and have new type. */
202 else if (*typeptr == 0)
204 *typeptr = ntype; /* Tracking alloc, and we have new type. */
209 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
211 ntype = alloc_type (TYPE_OBJFILE (type));
215 else /* We have storage, but need to reset it. */
218 objfile = TYPE_OBJFILE (ntype);
219 memset ((char *) ntype, 0, sizeof (struct type));
220 TYPE_OBJFILE (ntype) = objfile;
223 TYPE_TARGET_TYPE (ntype) = type;
224 TYPE_REFERENCE_TYPE (type) = ntype;
226 /* FIXME! Assume the machine has only one representation for references,
227 and that it matches the (only) representation for pointers! */
229 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
230 TYPE_CODE (ntype) = TYPE_CODE_REF;
232 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
233 TYPE_REFERENCE_TYPE (type) = ntype;
238 /* Same as above, but caller doesn't care about memory allocation details. */
241 lookup_reference_type (type)
244 return make_reference_type (type, (struct type **)0);
247 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
248 to a pointer to memory where the function type should be stored.
249 If *TYPEPTR is zero, update it to point to the function type we return.
250 We allocate new memory if needed. */
253 make_function_type (type, typeptr)
255 struct type **typeptr;
257 register struct type *ntype; /* New type */
258 struct objfile *objfile;
260 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
262 ntype = alloc_type (TYPE_OBJFILE (type));
266 else /* We have storage, but need to reset it. */
269 objfile = TYPE_OBJFILE (ntype);
270 memset ((char *) ntype, 0, sizeof (struct type));
271 TYPE_OBJFILE (ntype) = objfile;
274 TYPE_TARGET_TYPE (ntype) = type;
276 TYPE_LENGTH (ntype) = 1;
277 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
283 /* Given a type TYPE, return a type of functions that return that type.
284 May need to construct such a type if this is the first use. */
287 lookup_function_type (type)
290 return make_function_type (type, (struct type **)0);
294 /* Make a "c-v" variant of a type -- a type that is identical to the
295 one supplied except that it may have const or volatile attributes
296 CNST is a flag for setting the const attribute
297 VOLTL is a flag for setting the volatile attribute
298 TYPE is the base type whose variant we are creating.
299 TYPEPTR, if nonzero, points
300 to a pointer to memory where the reference type should be stored.
301 If *TYPEPTR is zero, update it to point to the reference type we return.
302 We allocate new memory if needed. */
305 make_cv_type (cnst, voltl, type, typeptr)
309 struct type **typeptr;
311 register struct type *ntype; /* New type */
312 register struct type *tmp_type = type; /* tmp type */
313 struct objfile *objfile;
315 ntype = TYPE_CV_TYPE (type);
317 while (ntype != type)
319 if ((TYPE_CONST (ntype) == cnst) &&
320 (TYPE_VOLATILE (ntype) == voltl))
324 else if (*typeptr == 0)
326 *typeptr = ntype; /* Tracking alloc, and we have new type. */
331 ntype = TYPE_CV_TYPE (ntype);
334 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
336 ntype = alloc_type (TYPE_OBJFILE (type));
340 else /* We have storage, but need to reset it. */
343 objfile = TYPE_OBJFILE (ntype);
344 /* memset ((char *) ntype, 0, sizeof (struct type)); */
345 TYPE_OBJFILE (ntype) = objfile;
348 /* Copy original type */
349 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
350 /* But zero out fields that shouldn't be copied */
351 TYPE_POINTER_TYPE (ntype) = (struct type *) 0; /* Need new pointer kind */
352 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; /* Need new referene kind */
353 /* Note: TYPE_TARGET_TYPE can be left as is */
355 /* Set flags appropriately */
357 TYPE_FLAGS (ntype) |= TYPE_FLAG_CONST;
359 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_CONST;
362 TYPE_FLAGS (ntype) |= TYPE_FLAG_VOLATILE;
364 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_VOLATILE;
366 /* Fix the chain of cv variants */
367 TYPE_CV_TYPE (ntype) = type;
368 TYPE_CV_TYPE (tmp_type) = ntype;
376 /* Implement direct support for MEMBER_TYPE in GNU C++.
377 May need to construct such a type if this is the first use.
378 The TYPE is the type of the member. The DOMAIN is the type
379 of the aggregate that the member belongs to. */
382 lookup_member_type (type, domain)
386 register struct type *mtype;
388 mtype = alloc_type (TYPE_OBJFILE (type));
389 smash_to_member_type (mtype, domain, type);
393 /* Allocate a stub method whose return type is TYPE.
394 This apparently happens for speed of symbol reading, since parsing
395 out the arguments to the method is cpu-intensive, the way we are doing
396 it. So, we will fill in arguments later.
397 This always returns a fresh type. */
400 allocate_stub_method (type)
405 mtype = alloc_type (TYPE_OBJFILE (type));
406 TYPE_TARGET_TYPE (mtype) = type;
407 /* _DOMAIN_TYPE (mtype) = unknown yet */
408 /* _ARG_TYPES (mtype) = unknown yet */
409 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
410 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
411 TYPE_LENGTH (mtype) = 1;
415 /* Create a range type using either a blank type supplied in RESULT_TYPE,
416 or creating a new type, inheriting the objfile from INDEX_TYPE.
418 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
419 HIGH_BOUND, inclusive.
421 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
422 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
425 create_range_type (result_type, index_type, low_bound, high_bound)
426 struct type *result_type;
427 struct type *index_type;
431 if (result_type == NULL)
433 result_type = alloc_type (TYPE_OBJFILE (index_type));
435 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
436 TYPE_TARGET_TYPE (result_type) = index_type;
437 if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB)
438 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
440 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
441 TYPE_NFIELDS (result_type) = 2;
442 TYPE_FIELDS (result_type) = (struct field *)
443 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
444 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
445 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
446 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
447 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
448 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
451 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
453 return (result_type);
456 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
457 Return 1 of type is a range type, 0 if it is discrete (and bounds
458 will fit in LONGEST), or -1 otherwise. */
461 get_discrete_bounds (type, lowp, highp)
463 LONGEST *lowp, *highp;
465 CHECK_TYPEDEF (type);
466 switch (TYPE_CODE (type))
468 case TYPE_CODE_RANGE:
469 *lowp = TYPE_LOW_BOUND (type);
470 *highp = TYPE_HIGH_BOUND (type);
473 if (TYPE_NFIELDS (type) > 0)
475 /* The enums may not be sorted by value, so search all
479 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
480 for (i = 0; i < TYPE_NFIELDS (type); i++)
482 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
483 *lowp = TYPE_FIELD_BITPOS (type, i);
484 if (TYPE_FIELD_BITPOS (type, i) > *highp)
485 *highp = TYPE_FIELD_BITPOS (type, i);
488 /* Set unsigned indicator if warranted. */
491 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
505 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
507 if (!TYPE_UNSIGNED (type))
509 *lowp = - (1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
513 /* ... fall through for unsigned ints ... */
516 /* This round-about calculation is to avoid shifting by
517 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
518 if TYPE_LENGTH (type) == sizeof (LONGEST). */
519 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
520 *highp = (*highp - 1) | *highp;
527 /* Create an array type using either a blank type supplied in RESULT_TYPE,
528 or creating a new type, inheriting the objfile from RANGE_TYPE.
530 Elements will be of type ELEMENT_TYPE, the indices will be of type
533 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
534 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
537 create_array_type (result_type, element_type, range_type)
538 struct type *result_type;
539 struct type *element_type;
540 struct type *range_type;
542 LONGEST low_bound, high_bound;
544 if (result_type == NULL)
546 result_type = alloc_type (TYPE_OBJFILE (range_type));
548 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
549 TYPE_TARGET_TYPE (result_type) = element_type;
550 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
551 low_bound = high_bound = 0;
552 CHECK_TYPEDEF (element_type);
553 TYPE_LENGTH (result_type) =
554 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
555 TYPE_NFIELDS (result_type) = 1;
556 TYPE_FIELDS (result_type) =
557 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
558 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
559 TYPE_FIELD_TYPE (result_type, 0) = range_type;
560 TYPE_VPTR_FIELDNO (result_type) = -1;
562 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
563 if (TYPE_LENGTH (result_type) == 0)
564 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
566 return (result_type);
569 /* Create a string type using either a blank type supplied in RESULT_TYPE,
570 or creating a new type. String types are similar enough to array of
571 char types that we can use create_array_type to build the basic type
572 and then bash it into a string type.
574 For fixed length strings, the range type contains 0 as the lower
575 bound and the length of the string minus one as the upper bound.
577 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
578 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
581 create_string_type (result_type, range_type)
582 struct type *result_type;
583 struct type *range_type;
585 result_type = create_array_type (result_type,
586 *current_language->string_char_type,
588 TYPE_CODE (result_type) = TYPE_CODE_STRING;
589 return (result_type);
593 create_set_type (result_type, domain_type)
594 struct type *result_type;
595 struct type *domain_type;
597 LONGEST low_bound, high_bound, bit_length;
598 if (result_type == NULL)
600 result_type = alloc_type (TYPE_OBJFILE (domain_type));
602 TYPE_CODE (result_type) = TYPE_CODE_SET;
603 TYPE_NFIELDS (result_type) = 1;
604 TYPE_FIELDS (result_type) = (struct field *)
605 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
606 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
608 if (! (TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB))
610 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
611 low_bound = high_bound = 0;
612 bit_length = high_bound - low_bound + 1;
613 TYPE_LENGTH (result_type)
614 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
616 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
619 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
621 return (result_type);
624 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
625 A MEMBER is a wierd thing -- it amounts to a typed offset into
626 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
627 include the offset (that's the value of the MEMBER itself), but does
628 include the structure type into which it points (for some reason).
630 When "smashing" the type, we preserve the objfile that the
631 old type pointed to, since we aren't changing where the type is actually
635 smash_to_member_type (type, domain, to_type)
638 struct type *to_type;
640 struct objfile *objfile;
642 objfile = TYPE_OBJFILE (type);
644 memset ((char *) type, 0, sizeof (struct type));
645 TYPE_OBJFILE (type) = objfile;
646 TYPE_TARGET_TYPE (type) = to_type;
647 TYPE_DOMAIN_TYPE (type) = domain;
648 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
649 TYPE_CODE (type) = TYPE_CODE_MEMBER;
652 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
653 METHOD just means `function that gets an extra "this" argument'.
655 When "smashing" the type, we preserve the objfile that the
656 old type pointed to, since we aren't changing where the type is actually
660 smash_to_method_type (type, domain, to_type, args)
663 struct type *to_type;
666 struct objfile *objfile;
668 objfile = TYPE_OBJFILE (type);
670 memset ((char *) type, 0, sizeof (struct type));
671 TYPE_OBJFILE (type) = objfile;
672 TYPE_TARGET_TYPE (type) = to_type;
673 TYPE_DOMAIN_TYPE (type) = domain;
674 TYPE_ARG_TYPES (type) = args;
675 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
676 TYPE_CODE (type) = TYPE_CODE_METHOD;
679 /* Return a typename for a struct/union/enum type without "struct ",
680 "union ", or "enum ". If the type has a NULL name, return NULL. */
683 type_name_no_tag (type)
684 register const struct type *type;
686 if (TYPE_TAG_NAME (type) != NULL)
687 return TYPE_TAG_NAME (type);
689 /* Is there code which expects this to return the name if there is no
690 tag name? My guess is that this is mainly used for C++ in cases where
691 the two will always be the same. */
692 return TYPE_NAME (type);
695 /* Lookup a primitive type named NAME.
696 Return zero if NAME is not a primitive type.*/
699 lookup_primitive_typename (name)
702 struct type ** const *p;
704 for (p = current_language -> la_builtin_type_vector; *p != NULL; p++)
706 if (STREQ ((**p) -> name, name))
714 /* Lookup a typedef or primitive type named NAME,
715 visible in lexical block BLOCK.
716 If NOERR is nonzero, return zero if NAME is not suitably defined. */
719 lookup_typename (name, block, noerr)
724 register struct symbol *sym;
725 register struct type *tmp;
727 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
728 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
730 tmp = lookup_primitive_typename (name);
735 else if (!tmp && noerr)
741 error ("No type named %s.", name);
744 return (SYMBOL_TYPE (sym));
748 lookup_unsigned_typename (name)
751 char *uns = alloca (strlen (name) + 10);
753 strcpy (uns, "unsigned ");
754 strcpy (uns + 9, name);
755 return (lookup_typename (uns, (struct block *) NULL, 0));
759 lookup_signed_typename (name)
763 char *uns = alloca (strlen (name) + 8);
765 strcpy (uns, "signed ");
766 strcpy (uns + 7, name);
767 t = lookup_typename (uns, (struct block *) NULL, 1);
768 /* If we don't find "signed FOO" just try again with plain "FOO". */
771 return lookup_typename (name, (struct block *) NULL, 0);
774 /* Lookup a structure type named "struct NAME",
775 visible in lexical block BLOCK. */
778 lookup_struct (name, block)
782 register struct symbol *sym;
784 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
785 (struct symtab **) NULL);
789 error ("No struct type named %s.", name);
791 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
793 error ("This context has class, union or enum %s, not a struct.", name);
795 return (SYMBOL_TYPE (sym));
798 /* Lookup a union type named "union NAME",
799 visible in lexical block BLOCK. */
802 lookup_union (name, block)
806 register struct symbol *sym;
809 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
810 (struct symtab **) NULL);
813 error ("No union type named %s.", name);
815 t = SYMBOL_TYPE(sym);
817 if (TYPE_CODE (t) == TYPE_CODE_UNION)
820 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
821 * a further "declared_type" field to discover it is really a union.
823 if (HAVE_CPLUS_STRUCT (t))
824 if (TYPE_DECLARED_TYPE(t) == DECLARED_TYPE_UNION)
827 /* If we get here, it's not a union */
828 error ("This context has class, struct or enum %s, not a union.", name);
832 /* Lookup an enum type named "enum NAME",
833 visible in lexical block BLOCK. */
836 lookup_enum (name, block)
840 register struct symbol *sym;
842 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
843 (struct symtab **) NULL);
846 error ("No enum type named %s.", name);
848 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
850 error ("This context has class, struct or union %s, not an enum.", name);
852 return (SYMBOL_TYPE (sym));
855 /* Lookup a template type named "template NAME<TYPE>",
856 visible in lexical block BLOCK. */
859 lookup_template_type (name, type, block)
865 char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4);
868 strcat (nam, type->name);
869 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
871 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
875 error ("No template type named %s.", name);
877 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
879 error ("This context has class, union or enum %s, not a struct.", name);
881 return (SYMBOL_TYPE (sym));
884 /* Given a type TYPE, lookup the type of the component of type named NAME.
886 TYPE can be either a struct or union, or a pointer or reference to a struct or
887 union. If it is a pointer or reference, its target type is automatically used.
888 Thus '.' and '->' are interchangable, as specified for the definitions of the
889 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
891 If NOERR is nonzero, return zero if NAME is not suitably defined.
892 If NAME is the name of a baseclass type, return that type. */
895 lookup_struct_elt_type (type, name, noerr)
904 CHECK_TYPEDEF (type);
905 if (TYPE_CODE (type) != TYPE_CODE_PTR
906 && TYPE_CODE (type) != TYPE_CODE_REF)
908 type = TYPE_TARGET_TYPE (type);
911 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
912 TYPE_CODE (type) != TYPE_CODE_UNION)
914 target_terminal_ours ();
915 gdb_flush (gdb_stdout);
916 fprintf_unfiltered (gdb_stderr, "Type ");
917 type_print (type, "", gdb_stderr, -1);
918 error (" is not a structure or union type.");
922 /* FIXME: This change put in by Michael seems incorrect for the case where
923 the structure tag name is the same as the member name. I.E. when doing
924 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
929 typename = type_name_no_tag (type);
930 if (typename != NULL && STREQ (typename, name))
935 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
937 char *t_field_name = TYPE_FIELD_NAME (type, i);
939 if (t_field_name && STREQ (t_field_name, name))
941 return TYPE_FIELD_TYPE (type, i);
945 /* OK, it's not in this class. Recursively check the baseclasses. */
946 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
950 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
962 target_terminal_ours ();
963 gdb_flush (gdb_stdout);
964 fprintf_unfiltered (gdb_stderr, "Type ");
965 type_print (type, "", gdb_stderr, -1);
966 fprintf_unfiltered (gdb_stderr, " has no component named ");
967 fputs_filtered (name, gdb_stderr);
969 return (struct type *)-1; /* For lint */
972 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
973 valid. Callers should be aware that in some cases (for example,
974 the type or one of its baseclasses is a stub type and we are
975 debugging a .o file), this function will not be able to find the virtual
976 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
980 fill_in_vptr_fieldno (type)
983 CHECK_TYPEDEF (type);
985 if (TYPE_VPTR_FIELDNO (type) < 0)
989 /* We must start at zero in case the first (and only) baseclass is
990 virtual (and hence we cannot share the table pointer). */
991 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
993 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
994 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
996 TYPE_VPTR_FIELDNO (type)
997 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
998 TYPE_VPTR_BASETYPE (type)
999 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
1006 /* Find the method and field indices for the destructor in class type T.
1007 Return 1 if the destructor was found, otherwise, return 0. */
1010 get_destructor_fn_field (t, method_indexp, field_indexp)
1017 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1020 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1022 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1024 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j)))
1035 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1037 If this is a stubbed struct (i.e. declared as struct foo *), see if
1038 we can find a full definition in some other file. If so, copy this
1039 definition, so we can use it in future. There used to be a comment (but
1040 not any code) that if we don't find a full definition, we'd set a flag
1041 so we don't spend time in the future checking the same type. That would
1042 be a mistake, though--we might load in more symbols which contain a
1043 full definition for the type.
1045 This used to be coded as a macro, but I don't think it is called
1046 often enough to merit such treatment. */
1048 struct complaint stub_noname_complaint =
1049 {"stub type has NULL name", 0, 0};
1052 check_typedef (type)
1053 register struct type *type;
1055 struct type *orig_type = type;
1056 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1058 if (!TYPE_TARGET_TYPE (type))
1063 /* It is dangerous to call lookup_symbol if we are currently
1064 reading a symtab. Infinite recursion is one danger. */
1065 if (currently_reading_symtab)
1068 name = type_name_no_tag (type);
1069 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1070 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1071 as appropriate? (this code was written before TYPE_NAME and
1072 TYPE_TAG_NAME were separate). */
1075 complain (&stub_noname_complaint);
1078 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
1079 (struct symtab **) NULL);
1081 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1083 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1085 type = TYPE_TARGET_TYPE (type);
1088 /* If this is a struct/class/union with no fields, then check whether a
1089 full definition exists somewhere else. This is for systems where a
1090 type definition with no fields is issued for such types, instead of
1091 identifying them as stub types in the first place */
1093 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1095 char * name = type_name_no_tag (type);
1096 struct type * newtype;
1099 complain (&stub_noname_complaint);
1102 newtype = lookup_transparent_type (name);
1105 memcpy ((char *) type, (char *) newtype, sizeof (struct type));
1108 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1109 else if ((TYPE_FLAGS(type) & TYPE_FLAG_STUB) && ! currently_reading_symtab)
1111 char* name = type_name_no_tag (type);
1112 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1113 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1114 as appropriate? (this code was written before TYPE_NAME and
1115 TYPE_TAG_NAME were separate). */
1119 complain (&stub_noname_complaint);
1122 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL);
1125 memcpy ((char *)type, (char *)SYMBOL_TYPE(sym), sizeof (struct type));
1129 if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB)
1131 struct type *range_type;
1132 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1134 if (TYPE_FLAGS (target_type) & (TYPE_FLAG_STUB | TYPE_FLAG_TARGET_STUB))
1136 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1137 && TYPE_NFIELDS (type) == 1
1138 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1139 == TYPE_CODE_RANGE))
1141 /* Now recompute the length of the array type, based on its
1142 number of elements and the target type's length. */
1143 TYPE_LENGTH (type) =
1144 ((TYPE_FIELD_BITPOS (range_type, 1)
1145 - TYPE_FIELD_BITPOS (range_type, 0)
1147 * TYPE_LENGTH (target_type));
1148 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1150 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1152 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1153 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1156 /* Cache TYPE_LENGTH for future use. */
1157 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1161 /* New code added to support parsing of Cfront stabs strings */
1163 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1164 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1168 struct extra * pextras;
1173 if ((nlen = (n ? strlen(n) : 0))==0)
1175 sprintf(pextras->str+pextras->len,"%d%s",nlen,n);
1176 pextras->len=strlen(pextras->str);
1180 add_mangled_type(pextras,t)
1181 struct extra * pextras;
1184 enum type_code tcode;
1188 tcode = TYPE_CODE(t);
1189 tlen = TYPE_LENGTH(t);
1190 tflags = TYPE_FLAGS(t);
1191 tname = TYPE_NAME(t);
1192 /* args of "..." seem to get mangled as "e" */
1210 if ((pname=strrchr(tname,'l'),pname) && !strcmp(pname,"long"))
1219 static struct complaint msg = {"Bad int type code length x%x\n",0,0};
1221 complain (&msg, tlen);
1240 static struct complaint msg = {"Bad float type code length x%x\n",0,0};
1241 complain (&msg, tlen);
1247 /* followed by what it's a ref to */
1251 /* followed by what it's a ptr to */
1253 case TYPE_CODE_TYPEDEF:
1255 static struct complaint msg = {"Typedefs in overloaded functions not yet supported\n",0,0};
1258 /* followed by type bytes & name */
1260 case TYPE_CODE_FUNC:
1262 /* followed by func's arg '_' & ret types */
1264 case TYPE_CODE_VOID:
1267 case TYPE_CODE_METHOD:
1269 /* followed by name of class and func's arg '_' & ret types */
1270 add_name(pextras,tname);
1271 ADD_EXTRA('F'); /* then mangle function */
1273 case TYPE_CODE_STRUCT: /* C struct */
1274 case TYPE_CODE_UNION: /* C union */
1275 case TYPE_CODE_ENUM: /* Enumeration type */
1276 /* followed by name of type */
1277 add_name(pextras,tname);
1280 /* errors possible types/not supported */
1281 case TYPE_CODE_CHAR:
1282 case TYPE_CODE_ARRAY: /* Array type */
1283 case TYPE_CODE_MEMBER: /* Member type */
1284 case TYPE_CODE_BOOL:
1285 case TYPE_CODE_COMPLEX: /* Complex float */
1286 case TYPE_CODE_UNDEF:
1287 case TYPE_CODE_SET: /* Pascal sets */
1288 case TYPE_CODE_RANGE:
1289 case TYPE_CODE_STRING:
1290 case TYPE_CODE_BITSTRING:
1291 case TYPE_CODE_ERROR:
1294 static struct complaint msg = {"Unknown type code x%x\n",0,0};
1295 complain (&msg, tcode);
1299 add_mangled_type(pextras,t->target_type);
1304 cfront_mangle_name(type, i, j)
1310 char *mangled_name = gdb_mangle_name (type, i, j);
1312 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1314 /* kludge to support cfront methods - gdb expects to find "F" for
1315 ARM_mangled names, so when we mangle, we have to add it here */
1319 char * arm_mangled_name;
1320 struct fn_field *method = &f[j];
1321 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1322 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1323 char *newname = type_name_no_tag (type);
1325 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1326 int nargs = TYPE_NFIELDS(ftype); /* number of args */
1327 struct extra extras, * pextras = &extras;
1330 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1333 /* add args here! */
1334 if (nargs <= 1) /* no args besides this */
1337 for (k=1; k<nargs; k++)
1340 t = TYPE_FIELD_TYPE(ftype,k);
1341 add_mangled_type(pextras,t);
1345 printf("add_mangled_type: %s\n",extras.str); /* FIXME */
1346 arm_mangled_name = malloc(strlen(mangled_name)+extras.len);
1347 sprintf(arm_mangled_name,"%s%s",mangled_name,extras.str);
1349 mangled_name = arm_mangled_name;
1355 /* End of new code added to support parsing of Cfront stabs strings */
1357 /* Ugly hack to convert method stubs into method types.
1359 He ain't kiddin'. This demangles the name of the method into a string
1360 including argument types, parses out each argument type, generates
1361 a string casting a zero to that type, evaluates the string, and stuffs
1362 the resulting type into an argtype vector!!! Then it knows the type
1363 of the whole function (including argument types for overloading),
1364 which info used to be in the stab's but was removed to hack back
1365 the space required for them. */
1368 check_stub_method (type, method_id, signature_id)
1374 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1375 char *demangled_name = cplus_demangle (mangled_name,
1376 DMGL_PARAMS | DMGL_ANSI);
1377 char *argtypetext, *p;
1378 int depth = 0, argcount = 1;
1379 struct type **argtypes;
1382 /* Make sure we got back a function string that we can use. */
1384 p = strchr (demangled_name, '(');
1386 if (demangled_name == NULL || p == NULL)
1387 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1389 /* Now, read in the parameters that define this type. */
1402 else if (*p == ',' && depth == 0)
1410 /* We need two more slots: one for the THIS pointer, and one for the
1411 NULL [...] or void [end of arglist]. */
1413 argtypes = (struct type **)
1414 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
1416 /* FIXME: This is wrong for static member functions. */
1417 argtypes[0] = lookup_pointer_type (type);
1420 if (*p != ')') /* () means no args, skip while */
1425 if (depth <= 0 && (*p == ',' || *p == ')'))
1427 /* Avoid parsing of ellipsis, they will be handled below. */
1428 if (strncmp (argtypetext, "...", p - argtypetext) != 0)
1430 argtypes[argcount] =
1431 parse_and_eval_type (argtypetext, p - argtypetext);
1434 argtypetext = p + 1;
1450 if (p[-2] != '.') /* Not '...' */
1452 argtypes[argcount] = builtin_type_void; /* List terminator */
1456 argtypes[argcount] = NULL; /* Ellist terminator */
1459 free (demangled_name);
1461 f = TYPE_FN_FIELDLIST1 (type, method_id);
1463 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1465 /* Now update the old "stub" type into a real type. */
1466 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1467 TYPE_DOMAIN_TYPE (mtype) = type;
1468 TYPE_ARG_TYPES (mtype) = argtypes;
1469 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1470 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1473 const struct cplus_struct_type cplus_struct_default;
1476 allocate_cplus_struct_type (type)
1479 if (!HAVE_CPLUS_STRUCT (type))
1481 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1482 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1483 *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default;
1487 /* Helper function to initialize the standard scalar types.
1489 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1490 of the string pointed to by name in the type_obstack for that objfile,
1491 and initialize the type name to that copy. There are places (mipsread.c
1492 in particular, where init_type is called with a NULL value for NAME). */
1495 init_type (code, length, flags, name, objfile)
1496 enum type_code code;
1500 struct objfile *objfile;
1502 register struct type *type;
1504 type = alloc_type (objfile);
1505 TYPE_CODE (type) = code;
1506 TYPE_LENGTH (type) = length;
1507 TYPE_FLAGS (type) |= flags;
1508 if ((name != NULL) && (objfile != NULL))
1511 obsavestring (name, strlen (name), &objfile -> type_obstack);
1515 TYPE_NAME (type) = name;
1520 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1522 INIT_CPLUS_SPECIFIC (type);
1527 /* Look up a fundamental type for the specified objfile.
1528 May need to construct such a type if this is the first use.
1530 Some object file formats (ELF, COFF, etc) do not define fundamental
1531 types such as "int" or "double". Others (stabs for example), do
1532 define fundamental types.
1534 For the formats which don't provide fundamental types, gdb can create
1535 such types, using defaults reasonable for the current language and
1536 the current target machine.
1538 NOTE: This routine is obsolescent. Each debugging format reader
1539 should manage it's own fundamental types, either creating them from
1540 suitable defaults or reading them from the debugging information,
1541 whichever is appropriate. The DWARF reader has already been
1542 fixed to do this. Once the other readers are fixed, this routine
1543 will go away. Also note that fundamental types should be managed
1544 on a compilation unit basis in a multi-language environment, not
1545 on a linkage unit basis as is done here. */
1549 lookup_fundamental_type (objfile, typeid)
1550 struct objfile *objfile;
1553 register struct type **typep;
1554 register int nbytes;
1556 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1558 error ("internal error - invalid fundamental type id %d", typeid);
1561 /* If this is the first time we need a fundamental type for this objfile
1562 then we need to initialize the vector of type pointers. */
1564 if (objfile -> fundamental_types == NULL)
1566 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1567 objfile -> fundamental_types = (struct type **)
1568 obstack_alloc (&objfile -> type_obstack, nbytes);
1569 memset ((char *) objfile -> fundamental_types, 0, nbytes);
1570 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1573 /* Look for this particular type in the fundamental type vector. If one is
1574 not found, create and install one appropriate for the current language. */
1576 typep = objfile -> fundamental_types + typeid;
1579 *typep = create_fundamental_type (objfile, typeid);
1589 /* FIXME: Should we return true for references as well as pointers? */
1593 && TYPE_CODE (t) == TYPE_CODE_PTR
1594 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1597 /* Chill varying string and arrays are represented as follows:
1599 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1601 Return true if TYPE is such a Chill varying type. */
1604 chill_varying_type (type)
1607 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1608 || TYPE_NFIELDS (type) != 2
1609 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1614 /* Check whether BASE is an ancestor or base class or DCLASS
1615 Return 1 if so, and 0 if not.
1616 Note: callers may want to check for identity of the types before
1617 calling this function -- identical types are considered to satisfy
1618 the ancestor relationship even if they're identical */
1621 is_ancestor (base, dclass)
1623 struct type * dclass;
1627 CHECK_TYPEDEF (base);
1628 CHECK_TYPEDEF (dclass);
1633 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1634 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1642 /* See whether DCLASS has a virtual table. This routine is aimed at
1643 the HP/Taligent ANSI C++ runtime model, and may not work with other
1644 runtime models. Return 1 => Yes, 0 => No. */
1648 struct type * dclass;
1650 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1651 has virtual functions or virtual bases. */
1655 if (TYPE_CODE(dclass) != TYPE_CODE_CLASS)
1658 /* First check for the presence of virtual bases */
1659 if (TYPE_FIELD_VIRTUAL_BITS(dclass))
1660 for (i=0; i < TYPE_N_BASECLASSES(dclass); i++)
1661 if (B_TST(TYPE_FIELD_VIRTUAL_BITS(dclass), i))
1664 /* Next check for virtual functions */
1665 if (TYPE_FN_FIELDLISTS(dclass))
1666 for (i=0; i < TYPE_NFN_FIELDS(dclass); i++)
1667 if (TYPE_FN_FIELD_VIRTUAL_P(TYPE_FN_FIELDLIST1(dclass, i), 0))
1670 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1671 if (TYPE_FIELD_VIRTUAL_BITS(dclass))
1672 for (i=0; i < TYPE_N_BASECLASSES(dclass); i++)
1673 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS(dclass), i)) &&
1674 (has_vtable (TYPE_FIELD_TYPE(dclass, i))))
1677 /* Well, maybe we don't need a virtual table */
1681 /* Return a pointer to the "primary base class" of DCLASS.
1683 A NULL return indicates that DCLASS has no primary base, or that it
1684 couldn't be found (insufficient information).
1686 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1687 and may not work with other runtime models. */
1690 primary_base_class (dclass)
1691 struct type * dclass;
1693 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1694 is the first directly inherited, non-virtual base class that
1695 requires a virtual table */
1699 if (TYPE_CODE(dclass) != TYPE_CODE_CLASS)
1702 for (i=0; i < TYPE_N_BASECLASSES(dclass); i++)
1703 if (!TYPE_FIELD_VIRTUAL(dclass, i) &&
1704 has_vtable(TYPE_FIELD_TYPE(dclass, i)))
1705 return TYPE_FIELD_TYPE(dclass, i);
1710 /* Global manipulated by virtual_base_list[_aux]() */
1712 static struct vbase * current_vbase_list = NULL;
1714 /* Return a pointer to a null-terminated list of struct vbase
1715 items. The vbasetype pointer of each item in the list points to the
1716 type information for a virtual base of the argument DCLASS.
1718 Helper function for virtual_base_list().
1719 Note: the list goes backward, right-to-left. virtual_base_list()
1720 copies the items out in reverse order. */
1723 virtual_base_list_aux (dclass)
1724 struct type * dclass;
1726 struct vbase * tmp_vbase;
1729 if (TYPE_CODE(dclass) != TYPE_CODE_CLASS)
1732 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1734 /* Recurse on this ancestor, first */
1735 virtual_base_list_aux(TYPE_FIELD_TYPE(dclass, i));
1737 /* If this current base is itself virtual, add it to the list */
1738 if (BASETYPE_VIA_VIRTUAL(dclass, i))
1740 struct type * basetype = TYPE_FIELD_TYPE (dclass, i);
1742 /* Check if base already recorded */
1743 tmp_vbase = current_vbase_list;
1746 if (tmp_vbase->vbasetype == basetype)
1747 break; /* found it */
1748 tmp_vbase = tmp_vbase->next;
1751 if (!tmp_vbase) /* normal exit from loop */
1753 /* Allocate new item for this virtual base */
1754 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
1756 /* Stick it on at the end of the list */
1757 tmp_vbase->vbasetype = basetype;
1758 tmp_vbase->next = current_vbase_list;
1759 current_vbase_list = tmp_vbase;
1762 } /* for loop over bases */
1766 /* Compute the list of virtual bases in the right order. Virtual
1767 bases are laid out in the object's memory area in order of their
1768 occurrence in a depth-first, left-to-right search through the
1771 Argument DCLASS is the type whose virtual bases are required.
1772 Return value is the address of a null-terminated array of pointers
1773 to struct type items.
1775 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1776 and may not work with other runtime models.
1778 This routine merely hands off the argument to virtual_base_list_aux()
1779 and then copies the result into an array to save space. */
1782 virtual_base_list (dclass)
1783 struct type * dclass;
1785 register struct vbase * tmp_vbase;
1786 register struct vbase * tmp_vbase_2;
1789 struct type ** vbase_array;
1791 current_vbase_list = NULL;
1792 virtual_base_list_aux(dclass);
1794 for (i=0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1799 vbase_array = (struct type **) xmalloc((count + 1) * sizeof (struct type *));
1801 for (i=count -1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
1802 vbase_array[i] = tmp_vbase->vbasetype;
1804 /* Get rid of constructed chain */
1805 tmp_vbase_2 = tmp_vbase = current_vbase_list;
1808 tmp_vbase = tmp_vbase->next;
1810 tmp_vbase_2 = tmp_vbase;
1813 vbase_array[count] = NULL;
1817 /* Return the length of the virtual base list of the type DCLASS. */
1820 virtual_base_list_length (dclass)
1821 struct type * dclass;
1824 register struct vbase * tmp_vbase;
1826 current_vbase_list = NULL;
1827 virtual_base_list_aux(dclass);
1829 for (i=0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1834 /* Return the number of elements of the virtual base list of the type
1835 DCLASS, ignoring those appearing in the primary base (and its
1836 primary base, recursively). */
1839 virtual_base_list_length_skip_primaries (dclass)
1840 struct type * dclass;
1843 register struct vbase * tmp_vbase;
1844 struct type * primary;
1846 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
1849 return virtual_base_list_length (dclass);
1851 current_vbase_list = NULL;
1852 virtual_base_list_aux(dclass);
1854 for (i=0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
1856 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
1864 /* Return the index (position) of type BASE, which is a virtual base
1865 class of DCLASS, in the latter's virtual base list. A return of -1
1866 indicates "not found" or a problem. */
1869 virtual_base_index(base, dclass)
1871 struct type * dclass;
1873 register struct type * vbase;
1876 if ((TYPE_CODE(dclass) != TYPE_CODE_CLASS) ||
1877 (TYPE_CODE(base) != TYPE_CODE_CLASS))
1881 vbase = TYPE_VIRTUAL_BASE_LIST(dclass)[0];
1886 vbase = TYPE_VIRTUAL_BASE_LIST(dclass)[++i];
1889 return vbase ? i : -1;
1894 /* Return the index (position) of type BASE, which is a virtual base
1895 class of DCLASS, in the latter's virtual base list. Skip over all
1896 bases that may appear in the virtual base list of the primary base
1897 class of DCLASS (recursively). A return of -1 indicates "not
1898 found" or a problem. */
1901 virtual_base_index_skip_primaries(base, dclass)
1903 struct type * dclass;
1905 register struct type * vbase;
1907 struct type * primary;
1909 if ((TYPE_CODE(dclass) != TYPE_CODE_CLASS) ||
1910 (TYPE_CODE(base) != TYPE_CODE_CLASS))
1913 primary = TYPE_RUNTIME_PTR(dclass) ? TYPE_PRIMARY_BASE(dclass) : NULL;
1917 vbase = TYPE_VIRTUAL_BASE_LIST(dclass)[0];
1920 if (!primary || (virtual_base_index_skip_primaries(vbase, primary) < 0))
1924 vbase = TYPE_VIRTUAL_BASE_LIST(dclass)[++i];
1927 return vbase ? j : -1;
1930 /* Return position of a derived class DCLASS in the list of
1931 * primary bases starting with the remotest ancestor.
1932 * Position returned is 0-based. */
1935 class_index_in_primary_list (dclass)
1936 struct type * dclass;
1938 struct type * pbc; /* primary base class */
1940 /* Simply recurse on primary base */
1941 pbc = TYPE_PRIMARY_BASE (dclass);
1943 return 1 + class_index_in_primary_list (pbc);
1948 /* Return a count of the number of virtual functions a type has.
1949 * This includes all the virtual functions it inherits from its
1953 /* pai: FIXME This doesn't do the right thing: count redefined virtual
1954 * functions only once (latest redefinition)
1958 count_virtual_fns (dclass)
1959 struct type * dclass;
1961 int base; /* index for base classes */
1962 int fn, oi; /* function and overloaded instance indices */
1964 int vfuncs; /* count to return */
1966 /* recurse on bases that can share virtual table */
1967 struct type * pbc = primary_base_class (dclass);
1969 vfuncs = count_virtual_fns (pbc);
1971 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
1972 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
1973 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
1981 /* Functions for overload resolution begin here */
1983 /* Compare two badness vectors A and B and return the result.
1984 * 0 => A and B are identical
1985 * 1 => A and B are incomparable
1986 * 2 => A is better than B
1987 * 3 => A is worse than B */
1990 compare_badness (a, b)
1991 struct badness_vector * a;
1992 struct badness_vector * b;
1996 short found_pos = 0; /* any positives in c? */
1997 short found_neg = 0; /* any negatives in c? */
1999 /* differing lengths => incomparable */
2000 if (a->length != b->length)
2003 /* Subtract b from a */
2004 for (i=0; i < a->length; i++)
2006 tmp = a->rank[i] - b->rank[i];
2016 return 1; /* incomparable */
2018 return 3; /* A > B */
2020 else /* no positives */
2023 return 2; /* A < B */
2025 return 0; /* A == B */
2029 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2030 * to the types of an argument list (ARGS, length NARGS).
2031 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2033 struct badness_vector *
2034 rank_function (parms, nparms, args, nargs)
2035 struct type ** parms;
2037 struct type ** args;
2041 struct badness_vector * bv;
2042 int min_len = nparms < nargs ? nparms : nargs;
2044 bv = xmalloc (sizeof (struct badness_vector));
2045 bv->length = nargs + 1; /* add 1 for the length-match rank */
2046 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2048 /* First compare the lengths of the supplied lists.
2049 * If there is a mismatch, set it to a high value. */
2051 /* pai/1997-06-03 FIXME: when we have debug info about default
2052 * arguments and ellipsis parameter lists, we should consider those
2053 * and rank the length-match more finely. */
2055 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2057 /* Now rank all the parameters of the candidate function */
2058 for (i=1; i <= min_len; i++)
2059 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2061 /* If more arguments than parameters, add dummy entries */
2062 for (i = min_len +1; i <= nargs; i++)
2063 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2068 /* Compare one type (PARM) for compatibility with another (ARG).
2069 * PARM is intended to be the parameter type of a function; and
2070 * ARG is the supplied argument's type. This function tests if
2071 * the latter can be converted to the former.
2073 * Return 0 if they are identical types;
2074 * Otherwise, return an integer which corresponds to how compatible
2075 * PARM is to ARG. The higher the return value, the worse the match.
2076 * Generally the "bad" conversions are all uniformly assigned a 100 */
2079 rank_one_type (parm, arg)
2083 /* Identical type pointers */
2084 /* However, this still doesn't catch all cases of same type for arg
2085 * and param. The reason is that builtin types are different from
2086 * the same ones constructed from the object. */
2090 /* Resolve typedefs */
2091 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2092 parm = check_typedef (parm);
2093 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2094 arg = check_typedef (arg);
2096 /* Check if identical after resolving typedefs */
2101 /* Debugging only */
2102 printf("------ Arg is %s [%d], parm is %s [%d]\n",
2103 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2106 /* x -> y means arg of type x being supplied for parameter of type y */
2108 switch (TYPE_CODE (parm))
2111 switch (TYPE_CODE (arg))
2114 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2115 return VOID_PTR_CONVERSION_BADNESS;
2117 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2118 case TYPE_CODE_ARRAY:
2119 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2120 case TYPE_CODE_FUNC:
2121 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2123 case TYPE_CODE_ENUM:
2124 case TYPE_CODE_CHAR:
2125 case TYPE_CODE_RANGE:
2126 case TYPE_CODE_BOOL:
2127 return POINTER_CONVERSION_BADNESS;
2129 return INCOMPATIBLE_TYPE_BADNESS;
2131 case TYPE_CODE_ARRAY:
2132 switch (TYPE_CODE (arg))
2135 case TYPE_CODE_ARRAY:
2136 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2138 return INCOMPATIBLE_TYPE_BADNESS;
2140 case TYPE_CODE_FUNC:
2141 switch (TYPE_CODE (arg))
2143 case TYPE_CODE_PTR: /* funcptr -> func */
2144 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2146 return INCOMPATIBLE_TYPE_BADNESS;
2149 switch (TYPE_CODE (arg))
2152 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2154 /* Deal with signed, unsigned, and plain chars and
2155 signed and unsigned ints */
2156 if (TYPE_NOSIGN (parm))
2158 /* This case only for character types */
2159 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2162 return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */
2164 else if (TYPE_UNSIGNED (parm))
2166 if (TYPE_UNSIGNED (arg))
2168 if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2169 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2170 else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long"))
2171 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2173 return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
2177 if (!strcmp (TYPE_NAME (arg), "long") && !strcmp (TYPE_NAME (parm), "int"))
2178 return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
2180 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2183 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2185 if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2187 else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long"))
2188 return INTEGER_PROMOTION_BADNESS;
2190 return INTEGER_COERCION_BADNESS;
2193 return INTEGER_COERCION_BADNESS;
2195 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2196 return INTEGER_PROMOTION_BADNESS;
2198 return INTEGER_COERCION_BADNESS;
2199 case TYPE_CODE_ENUM:
2200 case TYPE_CODE_CHAR:
2201 case TYPE_CODE_RANGE:
2202 case TYPE_CODE_BOOL:
2203 return INTEGER_PROMOTION_BADNESS;
2205 return INT_FLOAT_CONVERSION_BADNESS;
2207 return NS_POINTER_CONVERSION_BADNESS;
2209 return INCOMPATIBLE_TYPE_BADNESS;
2212 case TYPE_CODE_ENUM:
2213 switch (TYPE_CODE (arg))
2216 case TYPE_CODE_CHAR:
2217 case TYPE_CODE_RANGE:
2218 case TYPE_CODE_BOOL:
2219 case TYPE_CODE_ENUM:
2220 return INTEGER_COERCION_BADNESS;
2222 return INT_FLOAT_CONVERSION_BADNESS;
2224 return INCOMPATIBLE_TYPE_BADNESS;
2227 case TYPE_CODE_CHAR:
2228 switch (TYPE_CODE (arg))
2230 case TYPE_CODE_RANGE:
2231 case TYPE_CODE_BOOL:
2232 case TYPE_CODE_ENUM:
2233 return INTEGER_COERCION_BADNESS;
2235 return INT_FLOAT_CONVERSION_BADNESS;
2237 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2238 return INTEGER_COERCION_BADNESS;
2239 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2240 return INTEGER_PROMOTION_BADNESS;
2241 /* >>> !! else fall through !! <<< */
2242 case TYPE_CODE_CHAR:
2243 /* Deal with signed, unsigned, and plain chars for C++
2244 and with int cases falling through from previous case */
2245 if (TYPE_NOSIGN (parm))
2247 if (TYPE_NOSIGN (arg))
2250 return INTEGER_COERCION_BADNESS;
2252 else if (TYPE_UNSIGNED (parm))
2254 if (TYPE_UNSIGNED (arg))
2257 return INTEGER_PROMOTION_BADNESS;
2259 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2262 return INTEGER_COERCION_BADNESS;
2264 return INCOMPATIBLE_TYPE_BADNESS;
2267 case TYPE_CODE_RANGE:
2268 switch (TYPE_CODE (arg))
2271 case TYPE_CODE_CHAR:
2272 case TYPE_CODE_RANGE:
2273 case TYPE_CODE_BOOL:
2274 case TYPE_CODE_ENUM:
2275 return INTEGER_COERCION_BADNESS;
2277 return INT_FLOAT_CONVERSION_BADNESS;
2279 return INCOMPATIBLE_TYPE_BADNESS;
2282 case TYPE_CODE_BOOL:
2283 switch (TYPE_CODE (arg))
2286 case TYPE_CODE_CHAR:
2287 case TYPE_CODE_RANGE:
2288 case TYPE_CODE_ENUM:
2291 return BOOLEAN_CONVERSION_BADNESS;
2292 case TYPE_CODE_BOOL:
2295 return INCOMPATIBLE_TYPE_BADNESS;
2299 switch (TYPE_CODE (arg))
2302 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2303 return FLOAT_PROMOTION_BADNESS;
2304 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2307 return FLOAT_CONVERSION_BADNESS;
2309 case TYPE_CODE_BOOL:
2310 case TYPE_CODE_ENUM:
2311 case TYPE_CODE_RANGE:
2312 case TYPE_CODE_CHAR:
2313 return INT_FLOAT_CONVERSION_BADNESS;
2315 return INCOMPATIBLE_TYPE_BADNESS;
2318 case TYPE_CODE_COMPLEX:
2319 switch (TYPE_CODE (arg))
2320 { /* Strictly not needed for C++, but... */
2322 return FLOAT_PROMOTION_BADNESS;
2323 case TYPE_CODE_COMPLEX:
2326 return INCOMPATIBLE_TYPE_BADNESS;
2329 case TYPE_CODE_STRUCT:
2330 /* currently same as TYPE_CODE_CLASS */
2331 switch (TYPE_CODE (arg))
2333 case TYPE_CODE_STRUCT:
2334 /* Check for derivation */
2335 if (is_ancestor (parm, arg))
2336 return BASE_CONVERSION_BADNESS;
2337 /* else fall through */
2339 return INCOMPATIBLE_TYPE_BADNESS;
2342 case TYPE_CODE_UNION:
2343 switch (TYPE_CODE (arg))
2345 case TYPE_CODE_UNION:
2347 return INCOMPATIBLE_TYPE_BADNESS;
2350 case TYPE_CODE_MEMBER:
2351 switch (TYPE_CODE (arg))
2354 return INCOMPATIBLE_TYPE_BADNESS;
2357 case TYPE_CODE_METHOD:
2358 switch (TYPE_CODE (arg))
2362 return INCOMPATIBLE_TYPE_BADNESS;
2366 switch (TYPE_CODE (arg))
2370 return INCOMPATIBLE_TYPE_BADNESS;
2375 switch (TYPE_CODE (arg))
2379 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2381 return INCOMPATIBLE_TYPE_BADNESS;
2384 case TYPE_CODE_VOID:
2386 return INCOMPATIBLE_TYPE_BADNESS;
2387 } /* switch (TYPE_CODE (arg)) */
2391 /* End of functions for overload resolution */
2395 #if MAINTENANCE_CMDS
2398 print_bit_vector (bits, nbits)
2404 for (bitno = 0; bitno < nbits; bitno++)
2406 if ((bitno % 8) == 0)
2408 puts_filtered (" ");
2410 if (B_TST (bits, bitno))
2412 printf_filtered ("1");
2416 printf_filtered ("0");
2421 /* The args list is a strange beast. It is either terminated by a NULL
2422 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2423 type for normal fixed argcount functions. (FIXME someday)
2424 Also note the first arg should be the "this" pointer, we may not want to
2425 include it since we may get into a infinitely recursive situation. */
2428 print_arg_types (args, spaces)
2434 while (*args != NULL)
2436 recursive_dump_type (*args, spaces + 2);
2437 if ((*args++) -> code == TYPE_CODE_VOID)
2446 dump_fn_fieldlists (type, spaces)
2454 printfi_filtered (spaces, "fn_fieldlists ");
2455 gdb_print_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2456 printf_filtered ("\n");
2457 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2459 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2460 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2462 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2463 gdb_print_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2465 printf_filtered (") length %d\n",
2466 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2467 for (overload_idx = 0;
2468 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2471 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2473 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2474 gdb_print_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2476 printf_filtered (")\n");
2477 printfi_filtered (spaces + 8, "type ");
2478 gdb_print_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2479 printf_filtered ("\n");
2481 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2484 printfi_filtered (spaces + 8, "args ");
2485 gdb_print_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2486 printf_filtered ("\n");
2488 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
2489 printfi_filtered (spaces + 8, "fcontext ");
2490 gdb_print_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2492 printf_filtered ("\n");
2494 printfi_filtered (spaces + 8, "is_const %d\n",
2495 TYPE_FN_FIELD_CONST (f, overload_idx));
2496 printfi_filtered (spaces + 8, "is_volatile %d\n",
2497 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2498 printfi_filtered (spaces + 8, "is_private %d\n",
2499 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2500 printfi_filtered (spaces + 8, "is_protected %d\n",
2501 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2502 printfi_filtered (spaces + 8, "is_stub %d\n",
2503 TYPE_FN_FIELD_STUB (f, overload_idx));
2504 printfi_filtered (spaces + 8, "voffset %u\n",
2505 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2511 print_cplus_stuff (type, spaces)
2515 printfi_filtered (spaces, "n_baseclasses %d\n",
2516 TYPE_N_BASECLASSES (type));
2517 printfi_filtered (spaces, "nfn_fields %d\n",
2518 TYPE_NFN_FIELDS (type));
2519 printfi_filtered (spaces, "nfn_fields_total %d\n",
2520 TYPE_NFN_FIELDS_TOTAL (type));
2521 if (TYPE_N_BASECLASSES (type) > 0)
2523 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2524 TYPE_N_BASECLASSES (type));
2525 gdb_print_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2526 printf_filtered (")");
2528 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2529 TYPE_N_BASECLASSES (type));
2530 puts_filtered ("\n");
2532 if (TYPE_NFIELDS (type) > 0)
2534 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2536 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2537 TYPE_NFIELDS (type));
2538 gdb_print_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2539 printf_filtered (")");
2540 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2541 TYPE_NFIELDS (type));
2542 puts_filtered ("\n");
2544 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2546 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2547 TYPE_NFIELDS (type));
2548 gdb_print_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2549 printf_filtered (")");
2550 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2551 TYPE_NFIELDS (type));
2552 puts_filtered ("\n");
2555 if (TYPE_NFN_FIELDS (type) > 0)
2557 dump_fn_fieldlists (type, spaces);
2561 static struct obstack dont_print_type_obstack;
2564 recursive_dump_type (type, spaces)
2571 obstack_begin (&dont_print_type_obstack, 0);
2573 if (TYPE_NFIELDS (type) > 0
2574 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2576 struct type **first_dont_print
2577 = (struct type **)obstack_base (&dont_print_type_obstack);
2579 int i = (struct type **)obstack_next_free (&dont_print_type_obstack)
2584 if (type == first_dont_print[i])
2586 printfi_filtered (spaces, "type node ");
2587 gdb_print_address (type, gdb_stdout);
2588 printf_filtered (" <same as already seen type>\n");
2593 obstack_ptr_grow (&dont_print_type_obstack, type);
2596 printfi_filtered (spaces, "type node ");
2597 gdb_print_address (type, gdb_stdout);
2598 printf_filtered ("\n");
2599 printfi_filtered (spaces, "name '%s' (",
2600 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2601 gdb_print_address (TYPE_NAME (type), gdb_stdout);
2602 printf_filtered (")\n");
2603 if (TYPE_TAG_NAME (type) != NULL)
2605 printfi_filtered (spaces, "tagname '%s' (",
2606 TYPE_TAG_NAME (type));
2607 gdb_print_address (TYPE_TAG_NAME (type), gdb_stdout);
2608 printf_filtered (")\n");
2610 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2611 switch (TYPE_CODE (type))
2613 case TYPE_CODE_UNDEF:
2614 printf_filtered ("(TYPE_CODE_UNDEF)");
2617 printf_filtered ("(TYPE_CODE_PTR)");
2619 case TYPE_CODE_ARRAY:
2620 printf_filtered ("(TYPE_CODE_ARRAY)");
2622 case TYPE_CODE_STRUCT:
2623 printf_filtered ("(TYPE_CODE_STRUCT)");
2625 case TYPE_CODE_UNION:
2626 printf_filtered ("(TYPE_CODE_UNION)");
2628 case TYPE_CODE_ENUM:
2629 printf_filtered ("(TYPE_CODE_ENUM)");
2631 case TYPE_CODE_FUNC:
2632 printf_filtered ("(TYPE_CODE_FUNC)");
2635 printf_filtered ("(TYPE_CODE_INT)");
2638 printf_filtered ("(TYPE_CODE_FLT)");
2640 case TYPE_CODE_VOID:
2641 printf_filtered ("(TYPE_CODE_VOID)");
2644 printf_filtered ("(TYPE_CODE_SET)");
2646 case TYPE_CODE_RANGE:
2647 printf_filtered ("(TYPE_CODE_RANGE)");
2649 case TYPE_CODE_STRING:
2650 printf_filtered ("(TYPE_CODE_STRING)");
2652 case TYPE_CODE_ERROR:
2653 printf_filtered ("(TYPE_CODE_ERROR)");
2655 case TYPE_CODE_MEMBER:
2656 printf_filtered ("(TYPE_CODE_MEMBER)");
2658 case TYPE_CODE_METHOD:
2659 printf_filtered ("(TYPE_CODE_METHOD)");
2662 printf_filtered ("(TYPE_CODE_REF)");
2664 case TYPE_CODE_CHAR:
2665 printf_filtered ("(TYPE_CODE_CHAR)");
2667 case TYPE_CODE_BOOL:
2668 printf_filtered ("(TYPE_CODE_BOOL)");
2670 case TYPE_CODE_TYPEDEF:
2671 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2674 printf_filtered ("(UNKNOWN TYPE CODE)");
2677 puts_filtered ("\n");
2678 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2679 printfi_filtered (spaces, "objfile ");
2680 gdb_print_address (TYPE_OBJFILE (type), gdb_stdout);
2681 printf_filtered ("\n");
2682 printfi_filtered (spaces, "target_type ");
2683 gdb_print_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2684 printf_filtered ("\n");
2685 if (TYPE_TARGET_TYPE (type) != NULL)
2687 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2689 printfi_filtered (spaces, "pointer_type ");
2690 gdb_print_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2691 printf_filtered ("\n");
2692 printfi_filtered (spaces, "reference_type ");
2693 gdb_print_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2694 printf_filtered ("\n");
2695 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
2696 if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED)
2698 puts_filtered (" TYPE_FLAG_UNSIGNED");
2700 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
2702 puts_filtered (" TYPE_FLAG_STUB");
2704 puts_filtered ("\n");
2705 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
2706 gdb_print_address (TYPE_FIELDS (type), gdb_stdout);
2707 puts_filtered ("\n");
2708 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
2710 printfi_filtered (spaces + 2,
2711 "[%d] bitpos %d bitsize %d type ",
2712 idx, TYPE_FIELD_BITPOS (type, idx),
2713 TYPE_FIELD_BITSIZE (type, idx));
2714 gdb_print_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
2715 printf_filtered (" name '%s' (",
2716 TYPE_FIELD_NAME (type, idx) != NULL
2717 ? TYPE_FIELD_NAME (type, idx)
2719 gdb_print_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
2720 printf_filtered (")\n");
2721 if (TYPE_FIELD_TYPE (type, idx) != NULL)
2723 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
2726 printfi_filtered (spaces, "vptr_basetype ");
2727 gdb_print_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
2728 puts_filtered ("\n");
2729 if (TYPE_VPTR_BASETYPE (type) != NULL)
2731 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
2733 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
2734 switch (TYPE_CODE (type))
2736 case TYPE_CODE_METHOD:
2737 case TYPE_CODE_FUNC:
2738 printfi_filtered (spaces, "arg_types ");
2739 gdb_print_address (TYPE_ARG_TYPES (type), gdb_stdout);
2740 puts_filtered ("\n");
2741 print_arg_types (TYPE_ARG_TYPES (type), spaces);
2744 case TYPE_CODE_STRUCT:
2745 printfi_filtered (spaces, "cplus_stuff ");
2746 gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2747 puts_filtered ("\n");
2748 print_cplus_stuff (type, spaces);
2752 /* We have to pick one of the union types to be able print and test
2753 the value. Pick cplus_struct_type, even though we know it isn't
2754 any particular one. */
2755 printfi_filtered (spaces, "type_specific ");
2756 gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2757 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
2759 printf_filtered (" (unknown data form)");
2761 printf_filtered ("\n");
2766 obstack_free (&dont_print_type_obstack, NULL);
2769 #endif /* MAINTENANCE_CMDS */
2772 static void build_gdbtypes PARAMS ((void));
2777 init_type (TYPE_CODE_VOID, 1,
2779 "void", (struct objfile *) NULL);
2781 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2783 "char", (struct objfile *) NULL);
2784 TYPE_FLAGS (builtin_type_char) |= TYPE_FLAG_NOSIGN;
2786 builtin_type_signed_char =
2787 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2789 "signed char", (struct objfile *) NULL);
2790 builtin_type_unsigned_char =
2791 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2793 "unsigned char", (struct objfile *) NULL);
2794 builtin_type_short =
2795 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
2797 "short", (struct objfile *) NULL);
2798 builtin_type_unsigned_short =
2799 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
2801 "unsigned short", (struct objfile *) NULL);
2803 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
2805 "int", (struct objfile *) NULL);
2806 builtin_type_unsigned_int =
2807 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
2809 "unsigned int", (struct objfile *) NULL);
2811 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
2813 "long", (struct objfile *) NULL);
2814 builtin_type_unsigned_long =
2815 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
2817 "unsigned long", (struct objfile *) NULL);
2818 builtin_type_long_long =
2819 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2821 "long long", (struct objfile *) NULL);
2822 builtin_type_unsigned_long_long =
2823 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
2825 "unsigned long long", (struct objfile *) NULL);
2826 builtin_type_float =
2827 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
2829 "float", (struct objfile *) NULL);
2830 builtin_type_double =
2831 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
2833 "double", (struct objfile *) NULL);
2834 builtin_type_long_double =
2835 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
2837 "long double", (struct objfile *) NULL);
2838 builtin_type_complex =
2839 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
2841 "complex", (struct objfile *) NULL);
2842 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
2843 builtin_type_double_complex =
2844 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
2846 "double complex", (struct objfile *) NULL);
2847 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
2848 builtin_type_string =
2849 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2851 "string", (struct objfile *) NULL);
2853 init_type (TYPE_CODE_INT, 8 / 8,
2855 "int8_t", (struct objfile *) NULL);
2856 builtin_type_uint8 =
2857 init_type (TYPE_CODE_INT, 8 / 8,
2859 "uint8_t", (struct objfile *) NULL);
2860 builtin_type_int16 =
2861 init_type (TYPE_CODE_INT, 16 / 8,
2863 "int16_t", (struct objfile *) NULL);
2864 builtin_type_uint16 =
2865 init_type (TYPE_CODE_INT, 16 / 8,
2867 "uint16_t", (struct objfile *) NULL);
2868 builtin_type_int32 =
2869 init_type (TYPE_CODE_INT, 32 / 8,
2871 "int32_t", (struct objfile *) NULL);
2872 builtin_type_uint32 =
2873 init_type (TYPE_CODE_INT, 32 / 8,
2875 "uint32_t", (struct objfile *) NULL);
2876 builtin_type_int64 =
2877 init_type (TYPE_CODE_INT, 64 / 8,
2879 "int64_t", (struct objfile *) NULL);
2880 builtin_type_uint64 =
2881 init_type (TYPE_CODE_INT, 64 / 8,
2883 "uint64_t", (struct objfile *) NULL);
2885 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
2887 "bool", (struct objfile *) NULL);
2889 /* Add user knob for controlling resolution of opaque types */
2891 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *)&opaque_type_resolution,
2892 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
2895 opaque_type_resolution = 1;
2900 extern void _initialize_gdbtypes PARAMS ((void));
2902 _initialize_gdbtypes ()