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_true_char
;
42 struct type
*builtin_type_short
;
43 struct type
*builtin_type_int
;
44 struct type
*builtin_type_long
;
45 struct type
*builtin_type_long_long
;
46 struct type
*builtin_type_signed_char
;
47 struct type
*builtin_type_unsigned_char
;
48 struct type
*builtin_type_unsigned_short
;
49 struct type
*builtin_type_unsigned_int
;
50 struct type
*builtin_type_unsigned_long
;
51 struct type
*builtin_type_unsigned_long_long
;
52 struct type
*builtin_type_float
;
53 struct type
*builtin_type_double
;
54 struct type
*builtin_type_long_double
;
55 struct type
*builtin_type_complex
;
56 struct type
*builtin_type_double_complex
;
57 struct type
*builtin_type_string
;
58 struct type
*builtin_type_int8
;
59 struct type
*builtin_type_uint8
;
60 struct type
*builtin_type_int16
;
61 struct type
*builtin_type_uint16
;
62 struct type
*builtin_type_int32
;
63 struct type
*builtin_type_uint32
;
64 struct type
*builtin_type_int64
;
65 struct type
*builtin_type_uint64
;
66 struct type
*builtin_type_bool
;
68 int opaque_type_resolution
= 1;
71 struct extra
{ char str
[128]; int len
; }; /* maximum extention is 128! FIXME */
73 static void add_name
PARAMS ((struct extra
*, char *));
74 static void add_mangled_type
PARAMS ((struct extra
*, struct type
*));
76 static void cfront_mangle_name
PARAMS ((struct type
*, int, int));
78 static void print_bit_vector
PARAMS ((B_TYPE
*, int));
79 static void print_arg_types
PARAMS ((struct type
**, int));
80 static void dump_fn_fieldlists
PARAMS ((struct type
*, int));
81 static void print_cplus_stuff
PARAMS ((struct type
*, int));
82 static void virtual_base_list_aux
PARAMS ((struct type
*dclass
));
85 /* Alloc a new type structure and fill it with some defaults. If
86 OBJFILE is non-NULL, then allocate the space for the type structure
87 in that objfile's type_obstack. */
91 struct objfile
*objfile
;
93 register struct type
*type
;
95 /* Alloc the structure and start off with all fields zeroed. */
99 type
= (struct type
*) xmalloc (sizeof (struct type
));
103 type
= (struct type
*) obstack_alloc (&objfile
-> type_obstack
,
104 sizeof (struct type
));
105 OBJSTAT (objfile
, n_types
++);
107 memset ((char *) type
, 0, sizeof (struct type
));
109 /* Initialize the fields that might not be zero. */
111 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
112 TYPE_OBJFILE (type
) = objfile
;
113 TYPE_VPTR_FIELDNO (type
) = -1;
114 TYPE_CV_TYPE (type
) = type
; /* chain back to itself */
119 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
120 to a pointer to memory where the pointer type should be stored.
121 If *TYPEPTR is zero, update it to point to the pointer type we return.
122 We allocate new memory if needed. */
125 make_pointer_type (type
, typeptr
)
127 struct type
**typeptr
;
129 register struct type
*ntype
; /* New type */
130 struct objfile
*objfile
;
132 ntype
= TYPE_POINTER_TYPE (type
);
137 return ntype
; /* Don't care about alloc, and have new type. */
138 else if (*typeptr
== 0)
140 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
145 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
147 ntype
= alloc_type (TYPE_OBJFILE (type
));
151 else /* We have storage, but need to reset it. */
154 objfile
= TYPE_OBJFILE (ntype
);
155 memset ((char *) ntype
, 0, sizeof (struct type
));
156 TYPE_OBJFILE (ntype
) = objfile
;
159 TYPE_TARGET_TYPE (ntype
) = type
;
160 TYPE_POINTER_TYPE (type
) = ntype
;
162 /* FIXME! Assume the machine has only one representation for pointers! */
164 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
165 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
167 /* pointers are unsigned */
168 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
170 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
171 TYPE_POINTER_TYPE (type
) = ntype
;
176 /* Given a type TYPE, return a type of pointers to that type.
177 May need to construct such a type if this is the first use. */
180 lookup_pointer_type (type
)
183 return make_pointer_type (type
, (struct type
**)0);
186 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
187 to a pointer to memory where the reference type should be stored.
188 If *TYPEPTR is zero, update it to point to the reference type we return.
189 We allocate new memory if needed. */
192 make_reference_type (type
, typeptr
)
194 struct type
**typeptr
;
196 register struct type
*ntype
; /* New type */
197 struct objfile
*objfile
;
199 ntype
= TYPE_REFERENCE_TYPE (type
);
204 return ntype
; /* Don't care about alloc, and have new type. */
205 else if (*typeptr
== 0)
207 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
212 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
214 ntype
= alloc_type (TYPE_OBJFILE (type
));
218 else /* We have storage, but need to reset it. */
221 objfile
= TYPE_OBJFILE (ntype
);
222 memset ((char *) ntype
, 0, sizeof (struct type
));
223 TYPE_OBJFILE (ntype
) = objfile
;
226 TYPE_TARGET_TYPE (ntype
) = type
;
227 TYPE_REFERENCE_TYPE (type
) = ntype
;
229 /* FIXME! Assume the machine has only one representation for references,
230 and that it matches the (only) representation for pointers! */
232 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
233 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
235 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
236 TYPE_REFERENCE_TYPE (type
) = ntype
;
241 /* Same as above, but caller doesn't care about memory allocation details. */
244 lookup_reference_type (type
)
247 return make_reference_type (type
, (struct type
**)0);
250 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
251 to a pointer to memory where the function type should be stored.
252 If *TYPEPTR is zero, update it to point to the function type we return.
253 We allocate new memory if needed. */
256 make_function_type (type
, typeptr
)
258 struct type
**typeptr
;
260 register struct type
*ntype
; /* New type */
261 struct objfile
*objfile
;
263 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
265 ntype
= alloc_type (TYPE_OBJFILE (type
));
269 else /* We have storage, but need to reset it. */
272 objfile
= TYPE_OBJFILE (ntype
);
273 memset ((char *) ntype
, 0, sizeof (struct type
));
274 TYPE_OBJFILE (ntype
) = objfile
;
277 TYPE_TARGET_TYPE (ntype
) = type
;
279 TYPE_LENGTH (ntype
) = 1;
280 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
286 /* Given a type TYPE, return a type of functions that return that type.
287 May need to construct such a type if this is the first use. */
290 lookup_function_type (type
)
293 return make_function_type (type
, (struct type
**)0);
297 /* Make a "c-v" variant of a type -- a type that is identical to the
298 one supplied except that it may have const or volatile attributes
299 CNST is a flag for setting the const attribute
300 VOLTL is a flag for setting the volatile attribute
301 TYPE is the base type whose variant we are creating.
302 TYPEPTR, if nonzero, points
303 to a pointer to memory where the reference type should be stored.
304 If *TYPEPTR is zero, update it to point to the reference type we return.
305 We allocate new memory if needed. */
308 make_cv_type (cnst
, voltl
, type
, typeptr
)
312 struct type
**typeptr
;
314 register struct type
*ntype
; /* New type */
315 register struct type
*tmp_type
= type
; /* tmp type */
316 struct objfile
*objfile
;
318 ntype
= TYPE_CV_TYPE (type
);
320 while (ntype
!= type
)
322 if ((TYPE_CONST (ntype
) == cnst
) &&
323 (TYPE_VOLATILE (ntype
) == voltl
))
327 else if (*typeptr
== 0)
329 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
334 ntype
= TYPE_CV_TYPE (ntype
);
337 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
339 ntype
= alloc_type (TYPE_OBJFILE (type
));
343 else /* We have storage, but need to reset it. */
346 objfile
= TYPE_OBJFILE (ntype
);
347 /* memset ((char *) ntype, 0, sizeof (struct type)); */
348 TYPE_OBJFILE (ntype
) = objfile
;
351 /* Copy original type */
352 memcpy ((char *) ntype
, (char *) type
, sizeof (struct type
));
353 /* But zero out fields that shouldn't be copied */
354 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0; /* Need new pointer kind */
355 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0; /* Need new referene kind */
356 /* Note: TYPE_TARGET_TYPE can be left as is */
358 /* Set flags appropriately */
360 TYPE_FLAGS (ntype
) |= TYPE_FLAG_CONST
;
362 TYPE_FLAGS (ntype
) &= ~TYPE_FLAG_CONST
;
365 TYPE_FLAGS (ntype
) |= TYPE_FLAG_VOLATILE
;
367 TYPE_FLAGS (ntype
) &= ~TYPE_FLAG_VOLATILE
;
369 /* Fix the chain of cv variants */
370 TYPE_CV_TYPE (ntype
) = type
;
371 TYPE_CV_TYPE (tmp_type
) = ntype
;
379 /* Implement direct support for MEMBER_TYPE in GNU C++.
380 May need to construct such a type if this is the first use.
381 The TYPE is the type of the member. The DOMAIN is the type
382 of the aggregate that the member belongs to. */
385 lookup_member_type (type
, domain
)
389 register struct type
*mtype
;
391 mtype
= alloc_type (TYPE_OBJFILE (type
));
392 smash_to_member_type (mtype
, domain
, type
);
396 /* Allocate a stub method whose return type is TYPE.
397 This apparently happens for speed of symbol reading, since parsing
398 out the arguments to the method is cpu-intensive, the way we are doing
399 it. So, we will fill in arguments later.
400 This always returns a fresh type. */
403 allocate_stub_method (type
)
408 mtype
= alloc_type (TYPE_OBJFILE (type
));
409 TYPE_TARGET_TYPE (mtype
) = type
;
410 /* _DOMAIN_TYPE (mtype) = unknown yet */
411 /* _ARG_TYPES (mtype) = unknown yet */
412 TYPE_FLAGS (mtype
) = TYPE_FLAG_STUB
;
413 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
414 TYPE_LENGTH (mtype
) = 1;
418 /* Create a range type using either a blank type supplied in RESULT_TYPE,
419 or creating a new type, inheriting the objfile from INDEX_TYPE.
421 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
422 HIGH_BOUND, inclusive.
424 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
425 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
428 create_range_type (result_type
, index_type
, low_bound
, high_bound
)
429 struct type
*result_type
;
430 struct type
*index_type
;
434 if (result_type
== NULL
)
436 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
438 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
439 TYPE_TARGET_TYPE (result_type
) = index_type
;
440 if (TYPE_FLAGS (index_type
) & TYPE_FLAG_STUB
)
441 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
443 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
444 TYPE_NFIELDS (result_type
) = 2;
445 TYPE_FIELDS (result_type
) = (struct field
*)
446 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
447 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
448 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
449 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
450 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
451 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
454 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
456 return (result_type
);
459 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
460 Return 1 of type is a range type, 0 if it is discrete (and bounds
461 will fit in LONGEST), or -1 otherwise. */
464 get_discrete_bounds (type
, lowp
, highp
)
466 LONGEST
*lowp
, *highp
;
468 CHECK_TYPEDEF (type
);
469 switch (TYPE_CODE (type
))
471 case TYPE_CODE_RANGE
:
472 *lowp
= TYPE_LOW_BOUND (type
);
473 *highp
= TYPE_HIGH_BOUND (type
);
476 if (TYPE_NFIELDS (type
) > 0)
478 /* The enums may not be sorted by value, so search all
482 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
483 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
485 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
486 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
487 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
488 *highp
= TYPE_FIELD_BITPOS (type
, i
);
491 /* Set unsigned indicator if warranted. */
494 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
508 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
510 if (!TYPE_UNSIGNED (type
))
512 *lowp
= - (1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
516 /* ... fall through for unsigned ints ... */
519 /* This round-about calculation is to avoid shifting by
520 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
521 if TYPE_LENGTH (type) == sizeof (LONGEST). */
522 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
523 *highp
= (*highp
- 1) | *highp
;
530 /* Create an array type using either a blank type supplied in RESULT_TYPE,
531 or creating a new type, inheriting the objfile from RANGE_TYPE.
533 Elements will be of type ELEMENT_TYPE, the indices will be of type
536 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
537 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
540 create_array_type (result_type
, element_type
, range_type
)
541 struct type
*result_type
;
542 struct type
*element_type
;
543 struct type
*range_type
;
545 LONGEST low_bound
, high_bound
;
547 if (result_type
== NULL
)
549 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
551 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
552 TYPE_TARGET_TYPE (result_type
) = element_type
;
553 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
554 low_bound
= high_bound
= 0;
555 CHECK_TYPEDEF (element_type
);
556 TYPE_LENGTH (result_type
) =
557 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
558 TYPE_NFIELDS (result_type
) = 1;
559 TYPE_FIELDS (result_type
) =
560 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
561 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
562 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
563 TYPE_VPTR_FIELDNO (result_type
) = -1;
565 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
566 if (TYPE_LENGTH (result_type
) == 0)
567 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
569 return (result_type
);
572 /* Create a string type using either a blank type supplied in RESULT_TYPE,
573 or creating a new type. String types are similar enough to array of
574 char types that we can use create_array_type to build the basic type
575 and then bash it into a string type.
577 For fixed length strings, the range type contains 0 as the lower
578 bound and the length of the string minus one as the upper bound.
580 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
581 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
584 create_string_type (result_type
, range_type
)
585 struct type
*result_type
;
586 struct type
*range_type
;
588 result_type
= create_array_type (result_type
,
589 *current_language
->string_char_type
,
591 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
592 return (result_type
);
596 create_set_type (result_type
, domain_type
)
597 struct type
*result_type
;
598 struct type
*domain_type
;
600 LONGEST low_bound
, high_bound
, bit_length
;
601 if (result_type
== NULL
)
603 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
605 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
606 TYPE_NFIELDS (result_type
) = 1;
607 TYPE_FIELDS (result_type
) = (struct field
*)
608 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
609 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
611 if (! (TYPE_FLAGS (domain_type
) & TYPE_FLAG_STUB
))
613 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
614 low_bound
= high_bound
= 0;
615 bit_length
= high_bound
- low_bound
+ 1;
616 TYPE_LENGTH (result_type
)
617 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
619 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
622 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
624 return (result_type
);
627 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
628 A MEMBER is a wierd thing -- it amounts to a typed offset into
629 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
630 include the offset (that's the value of the MEMBER itself), but does
631 include the structure type into which it points (for some reason).
633 When "smashing" the type, we preserve the objfile that the
634 old type pointed to, since we aren't changing where the type is actually
638 smash_to_member_type (type
, domain
, to_type
)
641 struct type
*to_type
;
643 struct objfile
*objfile
;
645 objfile
= TYPE_OBJFILE (type
);
647 memset ((char *) type
, 0, sizeof (struct type
));
648 TYPE_OBJFILE (type
) = objfile
;
649 TYPE_TARGET_TYPE (type
) = to_type
;
650 TYPE_DOMAIN_TYPE (type
) = domain
;
651 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
652 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
655 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
656 METHOD just means `function that gets an extra "this" argument'.
658 When "smashing" the type, we preserve the objfile that the
659 old type pointed to, since we aren't changing where the type is actually
663 smash_to_method_type (type
, domain
, to_type
, args
)
666 struct type
*to_type
;
669 struct objfile
*objfile
;
671 objfile
= TYPE_OBJFILE (type
);
673 memset ((char *) type
, 0, sizeof (struct type
));
674 TYPE_OBJFILE (type
) = objfile
;
675 TYPE_TARGET_TYPE (type
) = to_type
;
676 TYPE_DOMAIN_TYPE (type
) = domain
;
677 TYPE_ARG_TYPES (type
) = args
;
678 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
679 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
682 /* Return a typename for a struct/union/enum type without "struct ",
683 "union ", or "enum ". If the type has a NULL name, return NULL. */
686 type_name_no_tag (type
)
687 register const struct type
*type
;
689 if (TYPE_TAG_NAME (type
) != NULL
)
690 return TYPE_TAG_NAME (type
);
692 /* Is there code which expects this to return the name if there is no
693 tag name? My guess is that this is mainly used for C++ in cases where
694 the two will always be the same. */
695 return TYPE_NAME (type
);
698 /* Lookup a primitive type named NAME.
699 Return zero if NAME is not a primitive type.*/
702 lookup_primitive_typename (name
)
705 struct type
** const *p
;
707 for (p
= current_language
-> la_builtin_type_vector
; *p
!= NULL
; p
++)
709 if (STREQ ((**p
) -> name
, name
))
717 /* Lookup a typedef or primitive type named NAME,
718 visible in lexical block BLOCK.
719 If NOERR is nonzero, return zero if NAME is not suitably defined. */
722 lookup_typename (name
, block
, noerr
)
727 register struct symbol
*sym
;
728 register struct type
*tmp
;
730 sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
731 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
733 tmp
= lookup_primitive_typename (name
);
738 else if (!tmp
&& noerr
)
744 error ("No type named %s.", name
);
747 return (SYMBOL_TYPE (sym
));
751 lookup_unsigned_typename (name
)
754 char *uns
= alloca (strlen (name
) + 10);
756 strcpy (uns
, "unsigned ");
757 strcpy (uns
+ 9, name
);
758 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
762 lookup_signed_typename (name
)
766 char *uns
= alloca (strlen (name
) + 8);
768 strcpy (uns
, "signed ");
769 strcpy (uns
+ 7, name
);
770 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
771 /* If we don't find "signed FOO" just try again with plain "FOO". */
774 return lookup_typename (name
, (struct block
*) NULL
, 0);
777 /* Lookup a structure type named "struct NAME",
778 visible in lexical block BLOCK. */
781 lookup_struct (name
, block
)
785 register struct symbol
*sym
;
787 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
788 (struct symtab
**) NULL
);
792 error ("No struct type named %s.", name
);
794 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
796 error ("This context has class, union or enum %s, not a struct.", name
);
798 return (SYMBOL_TYPE (sym
));
801 /* Lookup a union type named "union NAME",
802 visible in lexical block BLOCK. */
805 lookup_union (name
, block
)
809 register struct symbol
*sym
;
812 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
813 (struct symtab
**) NULL
);
816 error ("No union type named %s.", name
);
818 t
= SYMBOL_TYPE(sym
);
820 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
823 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
824 * a further "declared_type" field to discover it is really a union.
826 if (HAVE_CPLUS_STRUCT (t
))
827 if (TYPE_DECLARED_TYPE(t
) == DECLARED_TYPE_UNION
)
830 /* If we get here, it's not a union */
831 error ("This context has class, struct or enum %s, not a union.", name
);
835 /* Lookup an enum type named "enum NAME",
836 visible in lexical block BLOCK. */
839 lookup_enum (name
, block
)
843 register struct symbol
*sym
;
845 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
846 (struct symtab
**) NULL
);
849 error ("No enum type named %s.", name
);
851 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
853 error ("This context has class, struct or union %s, not an enum.", name
);
855 return (SYMBOL_TYPE (sym
));
858 /* Lookup a template type named "template NAME<TYPE>",
859 visible in lexical block BLOCK. */
862 lookup_template_type (name
, type
, block
)
868 char *nam
= (char*) alloca(strlen(name
) + strlen(type
->name
) + 4);
871 strcat (nam
, type
->name
);
872 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
874 sym
= lookup_symbol (nam
, block
, VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
878 error ("No template type named %s.", name
);
880 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
882 error ("This context has class, union or enum %s, not a struct.", name
);
884 return (SYMBOL_TYPE (sym
));
887 /* Given a type TYPE, lookup the type of the component of type named NAME.
889 TYPE can be either a struct or union, or a pointer or reference to a struct or
890 union. If it is a pointer or reference, its target type is automatically used.
891 Thus '.' and '->' are interchangable, as specified for the definitions of the
892 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
894 If NOERR is nonzero, return zero if NAME is not suitably defined.
895 If NAME is the name of a baseclass type, return that type. */
898 lookup_struct_elt_type (type
, name
, noerr
)
907 CHECK_TYPEDEF (type
);
908 if (TYPE_CODE (type
) != TYPE_CODE_PTR
909 && TYPE_CODE (type
) != TYPE_CODE_REF
)
911 type
= TYPE_TARGET_TYPE (type
);
914 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
915 TYPE_CODE (type
) != TYPE_CODE_UNION
)
917 target_terminal_ours ();
918 gdb_flush (gdb_stdout
);
919 fprintf_unfiltered (gdb_stderr
, "Type ");
920 type_print (type
, "", gdb_stderr
, -1);
921 error (" is not a structure or union type.");
925 /* FIXME: This change put in by Michael seems incorrect for the case where
926 the structure tag name is the same as the member name. I.E. when doing
927 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
932 typename
= type_name_no_tag (type
);
933 if (typename
!= NULL
&& STREQ (typename
, name
))
938 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
940 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
942 if (t_field_name
&& STREQ (t_field_name
, name
))
944 return TYPE_FIELD_TYPE (type
, i
);
948 /* OK, it's not in this class. Recursively check the baseclasses. */
949 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
953 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
965 target_terminal_ours ();
966 gdb_flush (gdb_stdout
);
967 fprintf_unfiltered (gdb_stderr
, "Type ");
968 type_print (type
, "", gdb_stderr
, -1);
969 fprintf_unfiltered (gdb_stderr
, " has no component named ");
970 fputs_filtered (name
, gdb_stderr
);
972 return (struct type
*)-1; /* For lint */
975 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
976 valid. Callers should be aware that in some cases (for example,
977 the type or one of its baseclasses is a stub type and we are
978 debugging a .o file), this function will not be able to find the virtual
979 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
983 fill_in_vptr_fieldno (type
)
986 CHECK_TYPEDEF (type
);
988 if (TYPE_VPTR_FIELDNO (type
) < 0)
992 /* We must start at zero in case the first (and only) baseclass is
993 virtual (and hence we cannot share the table pointer). */
994 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
996 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
997 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
999 TYPE_VPTR_FIELDNO (type
)
1000 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
1001 TYPE_VPTR_BASETYPE (type
)
1002 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
1009 /* Find the method and field indices for the destructor in class type T.
1010 Return 1 if the destructor was found, otherwise, return 0. */
1013 get_destructor_fn_field (t
, method_indexp
, field_indexp
)
1020 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1023 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1025 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1027 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f
, j
)))
1038 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1040 If this is a stubbed struct (i.e. declared as struct foo *), see if
1041 we can find a full definition in some other file. If so, copy this
1042 definition, so we can use it in future. There used to be a comment (but
1043 not any code) that if we don't find a full definition, we'd set a flag
1044 so we don't spend time in the future checking the same type. That would
1045 be a mistake, though--we might load in more symbols which contain a
1046 full definition for the type.
1048 This used to be coded as a macro, but I don't think it is called
1049 often enough to merit such treatment. */
1051 struct complaint stub_noname_complaint
=
1052 {"stub type has NULL name", 0, 0};
1055 check_typedef (type
)
1056 register struct type
*type
;
1058 struct type
*orig_type
= type
;
1059 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1061 if (!TYPE_TARGET_TYPE (type
))
1066 /* It is dangerous to call lookup_symbol if we are currently
1067 reading a symtab. Infinite recursion is one danger. */
1068 if (currently_reading_symtab
)
1071 name
= type_name_no_tag (type
);
1072 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1073 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1074 as appropriate? (this code was written before TYPE_NAME and
1075 TYPE_TAG_NAME were separate). */
1078 complain (&stub_noname_complaint
);
1081 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
1082 (struct symtab
**) NULL
);
1084 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1086 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1088 type
= TYPE_TARGET_TYPE (type
);
1091 /* If this is a struct/class/union with no fields, then check whether a
1092 full definition exists somewhere else. This is for systems where a
1093 type definition with no fields is issued for such types, instead of
1094 identifying them as stub types in the first place */
1096 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1098 char * name
= type_name_no_tag (type
);
1099 struct type
* newtype
;
1102 complain (&stub_noname_complaint
);
1105 newtype
= lookup_transparent_type (name
);
1108 memcpy ((char *) type
, (char *) newtype
, sizeof (struct type
));
1111 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1112 else if ((TYPE_FLAGS(type
) & TYPE_FLAG_STUB
) && ! currently_reading_symtab
)
1114 char* name
= type_name_no_tag (type
);
1115 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1116 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1117 as appropriate? (this code was written before TYPE_NAME and
1118 TYPE_TAG_NAME were separate). */
1122 complain (&stub_noname_complaint
);
1125 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0, (struct symtab
**) NULL
);
1128 memcpy ((char *)type
, (char *)SYMBOL_TYPE(sym
), sizeof (struct type
));
1132 if (TYPE_FLAGS (type
) & TYPE_FLAG_TARGET_STUB
)
1134 struct type
*range_type
;
1135 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1137 if (TYPE_FLAGS (target_type
) & (TYPE_FLAG_STUB
| TYPE_FLAG_TARGET_STUB
))
1139 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1140 && TYPE_NFIELDS (type
) == 1
1141 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1142 == TYPE_CODE_RANGE
))
1144 /* Now recompute the length of the array type, based on its
1145 number of elements and the target type's length. */
1146 TYPE_LENGTH (type
) =
1147 ((TYPE_FIELD_BITPOS (range_type
, 1)
1148 - TYPE_FIELD_BITPOS (range_type
, 0)
1150 * TYPE_LENGTH (target_type
));
1151 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1153 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1155 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1156 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1159 /* Cache TYPE_LENGTH for future use. */
1160 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1164 /* New code added to support parsing of Cfront stabs strings */
1166 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1167 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1171 struct extra
* pextras
;
1176 if ((nlen
= (n
? strlen(n
) : 0))==0)
1178 sprintf(pextras
->str
+pextras
->len
,"%d%s",nlen
,n
);
1179 pextras
->len
=strlen(pextras
->str
);
1183 add_mangled_type(pextras
,t
)
1184 struct extra
* pextras
;
1187 enum type_code tcode
;
1191 tcode
= TYPE_CODE(t
);
1192 tlen
= TYPE_LENGTH(t
);
1193 tflags
= TYPE_FLAGS(t
);
1194 tname
= TYPE_NAME(t
);
1195 /* args of "..." seem to get mangled as "e" */
1213 if ((pname
=strrchr(tname
,'l'),pname
) && !strcmp(pname
,"long"))
1222 static struct complaint msg
= {"Bad int type code length x%x\n",0,0};
1224 complain (&msg
, tlen
);
1243 static struct complaint msg
= {"Bad float type code length x%x\n",0,0};
1244 complain (&msg
, tlen
);
1250 /* followed by what it's a ref to */
1254 /* followed by what it's a ptr to */
1256 case TYPE_CODE_TYPEDEF
:
1258 static struct complaint msg
= {"Typedefs in overloaded functions not yet supported\n",0,0};
1261 /* followed by type bytes & name */
1263 case TYPE_CODE_FUNC
:
1265 /* followed by func's arg '_' & ret types */
1267 case TYPE_CODE_VOID
:
1270 case TYPE_CODE_METHOD
:
1272 /* followed by name of class and func's arg '_' & ret types */
1273 add_name(pextras
,tname
);
1274 ADD_EXTRA('F'); /* then mangle function */
1276 case TYPE_CODE_STRUCT
: /* C struct */
1277 case TYPE_CODE_UNION
: /* C union */
1278 case TYPE_CODE_ENUM
: /* Enumeration type */
1279 /* followed by name of type */
1280 add_name(pextras
,tname
);
1283 /* errors possible types/not supported */
1284 case TYPE_CODE_CHAR
:
1285 case TYPE_CODE_ARRAY
: /* Array type */
1286 case TYPE_CODE_MEMBER
: /* Member type */
1287 case TYPE_CODE_BOOL
:
1288 case TYPE_CODE_COMPLEX
: /* Complex float */
1289 case TYPE_CODE_UNDEF
:
1290 case TYPE_CODE_SET
: /* Pascal sets */
1291 case TYPE_CODE_RANGE
:
1292 case TYPE_CODE_STRING
:
1293 case TYPE_CODE_BITSTRING
:
1294 case TYPE_CODE_ERROR
:
1297 static struct complaint msg
= {"Unknown type code x%x\n",0,0};
1298 complain (&msg
, tcode
);
1302 add_mangled_type(pextras
,t
->target_type
);
1307 cfront_mangle_name(type
, i
, j
)
1313 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1315 f
= TYPE_FN_FIELDLIST1 (type
, i
); /* moved from below */
1317 /* kludge to support cfront methods - gdb expects to find "F" for
1318 ARM_mangled names, so when we mangle, we have to add it here */
1322 char * arm_mangled_name
;
1323 struct fn_field
*method
= &f
[j
];
1324 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1325 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1326 char *newname
= type_name_no_tag (type
);
1328 struct type
*ftype
= TYPE_FN_FIELD_TYPE (f
, j
);
1329 int nargs
= TYPE_NFIELDS(ftype
); /* number of args */
1330 struct extra extras
, * pextras
= &extras
;
1333 if (TYPE_FN_FIELD_STATIC_P (f
, j
)) /* j for sublist within this list */
1336 /* add args here! */
1337 if (nargs
<= 1) /* no args besides this */
1340 for (k
=1; k
<nargs
; k
++)
1343 t
= TYPE_FIELD_TYPE(ftype
,k
);
1344 add_mangled_type(pextras
,t
);
1348 printf("add_mangled_type: %s\n",extras
.str
); /* FIXME */
1349 arm_mangled_name
= malloc(strlen(mangled_name
)+extras
.len
);
1350 sprintf(arm_mangled_name
,"%s%s",mangled_name
,extras
.str
);
1352 mangled_name
= arm_mangled_name
;
1358 /* End of new code added to support parsing of Cfront stabs strings */
1360 /* Ugly hack to convert method stubs into method types.
1362 He ain't kiddin'. This demangles the name of the method into a string
1363 including argument types, parses out each argument type, generates
1364 a string casting a zero to that type, evaluates the string, and stuffs
1365 the resulting type into an argtype vector!!! Then it knows the type
1366 of the whole function (including argument types for overloading),
1367 which info used to be in the stab's but was removed to hack back
1368 the space required for them. */
1371 check_stub_method (type
, method_id
, signature_id
)
1377 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1378 char *demangled_name
= cplus_demangle (mangled_name
,
1379 DMGL_PARAMS
| DMGL_ANSI
);
1380 char *argtypetext
, *p
;
1381 int depth
= 0, argcount
= 1;
1382 struct type
**argtypes
;
1385 /* Make sure we got back a function string that we can use. */
1387 p
= strchr (demangled_name
, '(');
1389 if (demangled_name
== NULL
|| p
== NULL
)
1390 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
1392 /* Now, read in the parameters that define this type. */
1405 else if (*p
== ',' && depth
== 0)
1413 /* We need two more slots: one for the THIS pointer, and one for the
1414 NULL [...] or void [end of arglist]. */
1416 argtypes
= (struct type
**)
1417 TYPE_ALLOC (type
, (argcount
+ 2) * sizeof (struct type
*));
1419 /* FIXME: This is wrong for static member functions. */
1420 argtypes
[0] = lookup_pointer_type (type
);
1423 if (*p
!= ')') /* () means no args, skip while */
1428 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1430 /* Avoid parsing of ellipsis, they will be handled below. */
1431 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0)
1433 argtypes
[argcount
] =
1434 parse_and_eval_type (argtypetext
, p
- argtypetext
);
1437 argtypetext
= p
+ 1;
1453 if (p
[-2] != '.') /* Not '...' */
1455 argtypes
[argcount
] = builtin_type_void
; /* List terminator */
1459 argtypes
[argcount
] = NULL
; /* Ellist terminator */
1462 free (demangled_name
);
1464 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1466 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1468 /* Now update the old "stub" type into a real type. */
1469 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1470 TYPE_DOMAIN_TYPE (mtype
) = type
;
1471 TYPE_ARG_TYPES (mtype
) = argtypes
;
1472 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1473 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1476 const struct cplus_struct_type cplus_struct_default
;
1479 allocate_cplus_struct_type (type
)
1482 if (!HAVE_CPLUS_STRUCT (type
))
1484 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1485 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1486 *(TYPE_CPLUS_SPECIFIC(type
)) = cplus_struct_default
;
1490 /* Helper function to initialize the standard scalar types.
1492 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1493 of the string pointed to by name in the type_obstack for that objfile,
1494 and initialize the type name to that copy. There are places (mipsread.c
1495 in particular, where init_type is called with a NULL value for NAME). */
1498 init_type (code
, length
, flags
, name
, objfile
)
1499 enum type_code code
;
1503 struct objfile
*objfile
;
1505 register struct type
*type
;
1507 type
= alloc_type (objfile
);
1508 TYPE_CODE (type
) = code
;
1509 TYPE_LENGTH (type
) = length
;
1510 TYPE_FLAGS (type
) |= flags
;
1511 if ((name
!= NULL
) && (objfile
!= NULL
))
1514 obsavestring (name
, strlen (name
), &objfile
-> type_obstack
);
1518 TYPE_NAME (type
) = name
;
1523 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1525 INIT_CPLUS_SPECIFIC (type
);
1530 /* Look up a fundamental type for the specified objfile.
1531 May need to construct such a type if this is the first use.
1533 Some object file formats (ELF, COFF, etc) do not define fundamental
1534 types such as "int" or "double". Others (stabs for example), do
1535 define fundamental types.
1537 For the formats which don't provide fundamental types, gdb can create
1538 such types, using defaults reasonable for the current language and
1539 the current target machine.
1541 NOTE: This routine is obsolescent. Each debugging format reader
1542 should manage it's own fundamental types, either creating them from
1543 suitable defaults or reading them from the debugging information,
1544 whichever is appropriate. The DWARF reader has already been
1545 fixed to do this. Once the other readers are fixed, this routine
1546 will go away. Also note that fundamental types should be managed
1547 on a compilation unit basis in a multi-language environment, not
1548 on a linkage unit basis as is done here. */
1552 lookup_fundamental_type (objfile
, typeid)
1553 struct objfile
*objfile
;
1556 register struct type
**typep
;
1557 register int nbytes
;
1559 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1561 error ("internal error - invalid fundamental type id %d", typeid);
1564 /* If this is the first time we need a fundamental type for this objfile
1565 then we need to initialize the vector of type pointers. */
1567 if (objfile
-> fundamental_types
== NULL
)
1569 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1570 objfile
-> fundamental_types
= (struct type
**)
1571 obstack_alloc (&objfile
-> type_obstack
, nbytes
);
1572 memset ((char *) objfile
-> fundamental_types
, 0, nbytes
);
1573 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1576 /* Look for this particular type in the fundamental type vector. If one is
1577 not found, create and install one appropriate for the current language. */
1579 typep
= objfile
-> fundamental_types
+ typeid;
1582 *typep
= create_fundamental_type (objfile
, typeid);
1592 /* FIXME: Should we return true for references as well as pointers? */
1596 && TYPE_CODE (t
) == TYPE_CODE_PTR
1597 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1600 /* Chill varying string and arrays are represented as follows:
1602 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1604 Return true if TYPE is such a Chill varying type. */
1607 chill_varying_type (type
)
1610 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1611 || TYPE_NFIELDS (type
) != 2
1612 || strcmp (TYPE_FIELD_NAME (type
, 0), "__var_length") != 0)
1617 /* Check whether BASE is an ancestor or base class or DCLASS
1618 Return 1 if so, and 0 if not.
1619 Note: callers may want to check for identity of the types before
1620 calling this function -- identical types are considered to satisfy
1621 the ancestor relationship even if they're identical */
1624 is_ancestor (base
, dclass
)
1626 struct type
* dclass
;
1630 CHECK_TYPEDEF (base
);
1631 CHECK_TYPEDEF (dclass
);
1636 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1637 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1645 /* See whether DCLASS has a virtual table. This routine is aimed at
1646 the HP/Taligent ANSI C++ runtime model, and may not work with other
1647 runtime models. Return 1 => Yes, 0 => No. */
1651 struct type
* dclass
;
1653 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1654 has virtual functions or virtual bases. */
1658 if (TYPE_CODE(dclass
) != TYPE_CODE_CLASS
)
1661 /* First check for the presence of virtual bases */
1662 if (TYPE_FIELD_VIRTUAL_BITS(dclass
))
1663 for (i
=0; i
< TYPE_N_BASECLASSES(dclass
); i
++)
1664 if (B_TST(TYPE_FIELD_VIRTUAL_BITS(dclass
), i
))
1667 /* Next check for virtual functions */
1668 if (TYPE_FN_FIELDLISTS(dclass
))
1669 for (i
=0; i
< TYPE_NFN_FIELDS(dclass
); i
++)
1670 if (TYPE_FN_FIELD_VIRTUAL_P(TYPE_FN_FIELDLIST1(dclass
, i
), 0))
1673 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1674 if (TYPE_FIELD_VIRTUAL_BITS(dclass
))
1675 for (i
=0; i
< TYPE_N_BASECLASSES(dclass
); i
++)
1676 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS(dclass
), i
)) &&
1677 (has_vtable (TYPE_FIELD_TYPE(dclass
, i
))))
1680 /* Well, maybe we don't need a virtual table */
1684 /* Return a pointer to the "primary base class" of DCLASS.
1686 A NULL return indicates that DCLASS has no primary base, or that it
1687 couldn't be found (insufficient information).
1689 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1690 and may not work with other runtime models. */
1693 primary_base_class (dclass
)
1694 struct type
* dclass
;
1696 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1697 is the first directly inherited, non-virtual base class that
1698 requires a virtual table */
1702 if (TYPE_CODE(dclass
) != TYPE_CODE_CLASS
)
1705 for (i
=0; i
< TYPE_N_BASECLASSES(dclass
); i
++)
1706 if (!TYPE_FIELD_VIRTUAL(dclass
, i
) &&
1707 has_vtable(TYPE_FIELD_TYPE(dclass
, i
)))
1708 return TYPE_FIELD_TYPE(dclass
, i
);
1713 /* Global manipulated by virtual_base_list[_aux]() */
1715 static struct vbase
* current_vbase_list
= NULL
;
1717 /* Return a pointer to a null-terminated list of struct vbase
1718 items. The vbasetype pointer of each item in the list points to the
1719 type information for a virtual base of the argument DCLASS.
1721 Helper function for virtual_base_list().
1722 Note: the list goes backward, right-to-left. virtual_base_list()
1723 copies the items out in reverse order. */
1726 virtual_base_list_aux (dclass
)
1727 struct type
* dclass
;
1729 struct vbase
* tmp_vbase
;
1732 if (TYPE_CODE(dclass
) != TYPE_CODE_CLASS
)
1735 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1737 /* Recurse on this ancestor, first */
1738 virtual_base_list_aux(TYPE_FIELD_TYPE(dclass
, i
));
1740 /* If this current base is itself virtual, add it to the list */
1741 if (BASETYPE_VIA_VIRTUAL(dclass
, i
))
1743 struct type
* basetype
= TYPE_FIELD_TYPE (dclass
, i
);
1745 /* Check if base already recorded */
1746 tmp_vbase
= current_vbase_list
;
1749 if (tmp_vbase
->vbasetype
== basetype
)
1750 break; /* found it */
1751 tmp_vbase
= tmp_vbase
->next
;
1754 if (!tmp_vbase
) /* normal exit from loop */
1756 /* Allocate new item for this virtual base */
1757 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
1759 /* Stick it on at the end of the list */
1760 tmp_vbase
->vbasetype
= basetype
;
1761 tmp_vbase
->next
= current_vbase_list
;
1762 current_vbase_list
= tmp_vbase
;
1765 } /* for loop over bases */
1769 /* Compute the list of virtual bases in the right order. Virtual
1770 bases are laid out in the object's memory area in order of their
1771 occurrence in a depth-first, left-to-right search through the
1774 Argument DCLASS is the type whose virtual bases are required.
1775 Return value is the address of a null-terminated array of pointers
1776 to struct type items.
1778 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1779 and may not work with other runtime models.
1781 This routine merely hands off the argument to virtual_base_list_aux()
1782 and then copies the result into an array to save space. */
1785 virtual_base_list (dclass
)
1786 struct type
* dclass
;
1788 register struct vbase
* tmp_vbase
;
1789 register struct vbase
* tmp_vbase_2
;
1792 struct type
** vbase_array
;
1794 current_vbase_list
= NULL
;
1795 virtual_base_list_aux(dclass
);
1797 for (i
=0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1802 vbase_array
= (struct type
**) xmalloc((count
+ 1) * sizeof (struct type
*));
1804 for (i
=count
-1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
1805 vbase_array
[i
] = tmp_vbase
->vbasetype
;
1807 /* Get rid of constructed chain */
1808 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
1811 tmp_vbase
= tmp_vbase
->next
;
1813 tmp_vbase_2
= tmp_vbase
;
1816 vbase_array
[count
] = NULL
;
1820 /* Return the length of the virtual base list of the type DCLASS. */
1823 virtual_base_list_length (dclass
)
1824 struct type
* dclass
;
1827 register struct vbase
* tmp_vbase
;
1829 current_vbase_list
= NULL
;
1830 virtual_base_list_aux(dclass
);
1832 for (i
=0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1837 /* Return the number of elements of the virtual base list of the type
1838 DCLASS, ignoring those appearing in the primary base (and its
1839 primary base, recursively). */
1842 virtual_base_list_length_skip_primaries (dclass
)
1843 struct type
* dclass
;
1846 register struct vbase
* tmp_vbase
;
1847 struct type
* primary
;
1849 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
1852 return virtual_base_list_length (dclass
);
1854 current_vbase_list
= NULL
;
1855 virtual_base_list_aux(dclass
);
1857 for (i
=0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
1859 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
1867 /* Return the index (position) of type BASE, which is a virtual base
1868 class of DCLASS, in the latter's virtual base list. A return of -1
1869 indicates "not found" or a problem. */
1872 virtual_base_index(base
, dclass
)
1874 struct type
* dclass
;
1876 register struct type
* vbase
;
1879 if ((TYPE_CODE(dclass
) != TYPE_CODE_CLASS
) ||
1880 (TYPE_CODE(base
) != TYPE_CODE_CLASS
))
1884 vbase
= TYPE_VIRTUAL_BASE_LIST(dclass
)[0];
1889 vbase
= TYPE_VIRTUAL_BASE_LIST(dclass
)[++i
];
1892 return vbase
? i
: -1;
1897 /* Return the index (position) of type BASE, which is a virtual base
1898 class of DCLASS, in the latter's virtual base list. Skip over all
1899 bases that may appear in the virtual base list of the primary base
1900 class of DCLASS (recursively). A return of -1 indicates "not
1901 found" or a problem. */
1904 virtual_base_index_skip_primaries(base
, dclass
)
1906 struct type
* dclass
;
1908 register struct type
* vbase
;
1910 struct type
* primary
;
1912 if ((TYPE_CODE(dclass
) != TYPE_CODE_CLASS
) ||
1913 (TYPE_CODE(base
) != TYPE_CODE_CLASS
))
1916 primary
= TYPE_RUNTIME_PTR(dclass
) ? TYPE_PRIMARY_BASE(dclass
) : NULL
;
1920 vbase
= TYPE_VIRTUAL_BASE_LIST(dclass
)[0];
1923 if (!primary
|| (virtual_base_index_skip_primaries(vbase
, primary
) < 0))
1927 vbase
= TYPE_VIRTUAL_BASE_LIST(dclass
)[++i
];
1930 return vbase
? j
: -1;
1933 /* Return position of a derived class DCLASS in the list of
1934 * primary bases starting with the remotest ancestor.
1935 * Position returned is 0-based. */
1938 class_index_in_primary_list (dclass
)
1939 struct type
* dclass
;
1941 struct type
* pbc
; /* primary base class */
1943 /* Simply recurse on primary base */
1944 pbc
= TYPE_PRIMARY_BASE (dclass
);
1946 return 1 + class_index_in_primary_list (pbc
);
1951 /* Return a count of the number of virtual functions a type has.
1952 * This includes all the virtual functions it inherits from its
1956 /* pai: FIXME This doesn't do the right thing: count redefined virtual
1957 * functions only once (latest redefinition)
1961 count_virtual_fns (dclass
)
1962 struct type
* dclass
;
1964 int base
; /* index for base classes */
1965 int fn
, oi
; /* function and overloaded instance indices */
1967 int vfuncs
; /* count to return */
1969 /* recurse on bases that can share virtual table */
1970 struct type
* pbc
= primary_base_class (dclass
);
1972 vfuncs
= count_virtual_fns (pbc
);
1974 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
1975 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
1976 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
1984 /* Functions for overload resolution begin here */
1986 /* Compare two badness vectors A and B and return the result.
1987 * 0 => A and B are identical
1988 * 1 => A and B are incomparable
1989 * 2 => A is better than B
1990 * 3 => A is worse than B */
1993 compare_badness (a
, b
)
1994 struct badness_vector
* a
;
1995 struct badness_vector
* b
;
1999 short found_pos
= 0; /* any positives in c? */
2000 short found_neg
= 0; /* any negatives in c? */
2002 /* differing lengths => incomparable */
2003 if (a
->length
!= b
->length
)
2006 /* Subtract b from a */
2007 for (i
=0; i
< a
->length
; i
++)
2009 tmp
= a
->rank
[i
] - b
->rank
[i
];
2019 return 1; /* incomparable */
2021 return 3; /* A > B */
2023 else /* no positives */
2026 return 2; /* A < B */
2028 return 0; /* A == B */
2032 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2033 * to the types of an argument list (ARGS, length NARGS).
2034 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2036 struct badness_vector
*
2037 rank_function (parms
, nparms
, args
, nargs
)
2038 struct type
** parms
;
2040 struct type
** args
;
2044 struct badness_vector
* bv
;
2045 int min_len
= nparms
< nargs
? nparms
: nargs
;
2047 bv
= xmalloc (sizeof (struct badness_vector
));
2048 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2049 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2051 /* First compare the lengths of the supplied lists.
2052 * If there is a mismatch, set it to a high value. */
2054 /* pai/1997-06-03 FIXME: when we have debug info about default
2055 * arguments and ellipsis parameter lists, we should consider those
2056 * and rank the length-match more finely. */
2058 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2060 /* Now rank all the parameters of the candidate function */
2061 for (i
=1; i
<= min_len
; i
++)
2062 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2064 /* If more arguments than parameters, add dummy entries */
2065 for (i
= min_len
+1; i
<= nargs
; i
++)
2066 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2071 /* Compare one type (PARM) for compatibility with another (ARG).
2072 * PARM is intended to be the parameter type of a function; and
2073 * ARG is the supplied argument's type. This function tests if
2074 * the latter can be converted to the former.
2076 * Return 0 if they are identical types;
2077 * Otherwise, return an integer which corresponds to how compatible
2078 * PARM is to ARG. The higher the return value, the worse the match.
2079 * Generally the "bad" conversions are all uniformly assigned a 100 */
2082 rank_one_type (parm
, arg
)
2086 /* Identical type pointers */
2087 /* However, this still doesn't catch all cases of same type for arg
2088 * and param. The reason is that builtin types are different from
2089 * the same ones constructed from the object. */
2093 /* Resolve typedefs */
2094 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2095 parm
= check_typedef (parm
);
2096 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2097 arg
= check_typedef (arg
);
2099 /* Check if identical after resolving typedefs */
2104 /* Debugging only */
2105 printf("------ Arg is %s [%d], parm is %s [%d]\n",
2106 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2109 /* x -> y means arg of type x being supplied for parameter of type y */
2111 switch (TYPE_CODE (parm
))
2114 switch (TYPE_CODE (arg
))
2117 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2118 return VOID_PTR_CONVERSION_BADNESS
;
2120 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2121 case TYPE_CODE_ARRAY
:
2122 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2123 case TYPE_CODE_FUNC
:
2124 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2126 case TYPE_CODE_ENUM
:
2127 case TYPE_CODE_CHAR
:
2128 case TYPE_CODE_RANGE
:
2129 case TYPE_CODE_BOOL
:
2130 return POINTER_CONVERSION_BADNESS
;
2132 return INCOMPATIBLE_TYPE_BADNESS
;
2134 case TYPE_CODE_ARRAY
:
2135 switch (TYPE_CODE (arg
))
2138 case TYPE_CODE_ARRAY
:
2139 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2141 return INCOMPATIBLE_TYPE_BADNESS
;
2143 case TYPE_CODE_FUNC
:
2144 switch (TYPE_CODE (arg
))
2146 case TYPE_CODE_PTR
: /* funcptr -> func */
2147 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2149 return INCOMPATIBLE_TYPE_BADNESS
;
2152 switch (TYPE_CODE (arg
))
2155 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2157 /* Deal with signed, unsigned, and plain chars and
2158 signed and unsigned ints */
2159 if (TYPE_NOSIGN (parm
))
2161 /* This case only for character types */
2162 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2165 return INTEGER_COERCION_BADNESS
; /* signed/unsigned char -> plain char */
2167 else if (TYPE_UNSIGNED (parm
))
2169 if (TYPE_UNSIGNED (arg
))
2171 if (!strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2172 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2173 else if (!strcmp (TYPE_NAME (arg
), "int") && !strcmp (TYPE_NAME (parm
), "long"))
2174 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2176 return INTEGER_COERCION_BADNESS
; /* unsigned long -> unsigned int */
2180 if (!strcmp (TYPE_NAME (arg
), "long") && !strcmp (TYPE_NAME (parm
), "int"))
2181 return INTEGER_COERCION_BADNESS
; /* signed long -> unsigned int */
2183 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2186 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2188 if (!strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2190 else if (!strcmp (TYPE_NAME (arg
), "int") && !strcmp (TYPE_NAME (parm
), "long"))
2191 return INTEGER_PROMOTION_BADNESS
;
2193 return INTEGER_COERCION_BADNESS
;
2196 return INTEGER_COERCION_BADNESS
;
2198 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2199 return INTEGER_PROMOTION_BADNESS
;
2201 return INTEGER_COERCION_BADNESS
;
2202 case TYPE_CODE_ENUM
:
2203 case TYPE_CODE_CHAR
:
2204 case TYPE_CODE_RANGE
:
2205 case TYPE_CODE_BOOL
:
2206 return INTEGER_PROMOTION_BADNESS
;
2208 return INT_FLOAT_CONVERSION_BADNESS
;
2210 return NS_POINTER_CONVERSION_BADNESS
;
2212 return INCOMPATIBLE_TYPE_BADNESS
;
2215 case TYPE_CODE_ENUM
:
2216 switch (TYPE_CODE (arg
))
2219 case TYPE_CODE_CHAR
:
2220 case TYPE_CODE_RANGE
:
2221 case TYPE_CODE_BOOL
:
2222 case TYPE_CODE_ENUM
:
2223 return INTEGER_COERCION_BADNESS
;
2225 return INT_FLOAT_CONVERSION_BADNESS
;
2227 return INCOMPATIBLE_TYPE_BADNESS
;
2230 case TYPE_CODE_CHAR
:
2231 switch (TYPE_CODE (arg
))
2233 case TYPE_CODE_RANGE
:
2234 case TYPE_CODE_BOOL
:
2235 case TYPE_CODE_ENUM
:
2236 return INTEGER_COERCION_BADNESS
;
2238 return INT_FLOAT_CONVERSION_BADNESS
;
2240 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2241 return INTEGER_COERCION_BADNESS
;
2242 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2243 return INTEGER_PROMOTION_BADNESS
;
2244 /* >>> !! else fall through !! <<< */
2245 case TYPE_CODE_CHAR
:
2246 /* Deal with signed, unsigned, and plain chars for C++
2247 and with int cases falling through from previous case */
2248 if (TYPE_NOSIGN (parm
))
2250 if (TYPE_NOSIGN (arg
))
2253 return INTEGER_COERCION_BADNESS
;
2255 else if (TYPE_UNSIGNED (parm
))
2257 if (TYPE_UNSIGNED (arg
))
2260 return INTEGER_PROMOTION_BADNESS
;
2262 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2265 return INTEGER_COERCION_BADNESS
;
2267 return INCOMPATIBLE_TYPE_BADNESS
;
2270 case TYPE_CODE_RANGE
:
2271 switch (TYPE_CODE (arg
))
2274 case TYPE_CODE_CHAR
:
2275 case TYPE_CODE_RANGE
:
2276 case TYPE_CODE_BOOL
:
2277 case TYPE_CODE_ENUM
:
2278 return INTEGER_COERCION_BADNESS
;
2280 return INT_FLOAT_CONVERSION_BADNESS
;
2282 return INCOMPATIBLE_TYPE_BADNESS
;
2285 case TYPE_CODE_BOOL
:
2286 switch (TYPE_CODE (arg
))
2289 case TYPE_CODE_CHAR
:
2290 case TYPE_CODE_RANGE
:
2291 case TYPE_CODE_ENUM
:
2294 return BOOLEAN_CONVERSION_BADNESS
;
2295 case TYPE_CODE_BOOL
:
2298 return INCOMPATIBLE_TYPE_BADNESS
;
2302 switch (TYPE_CODE (arg
))
2305 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2306 return FLOAT_PROMOTION_BADNESS
;
2307 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2310 return FLOAT_CONVERSION_BADNESS
;
2312 case TYPE_CODE_BOOL
:
2313 case TYPE_CODE_ENUM
:
2314 case TYPE_CODE_RANGE
:
2315 case TYPE_CODE_CHAR
:
2316 return INT_FLOAT_CONVERSION_BADNESS
;
2318 return INCOMPATIBLE_TYPE_BADNESS
;
2321 case TYPE_CODE_COMPLEX
:
2322 switch (TYPE_CODE (arg
))
2323 { /* Strictly not needed for C++, but... */
2325 return FLOAT_PROMOTION_BADNESS
;
2326 case TYPE_CODE_COMPLEX
:
2329 return INCOMPATIBLE_TYPE_BADNESS
;
2332 case TYPE_CODE_STRUCT
:
2333 /* currently same as TYPE_CODE_CLASS */
2334 switch (TYPE_CODE (arg
))
2336 case TYPE_CODE_STRUCT
:
2337 /* Check for derivation */
2338 if (is_ancestor (parm
, arg
))
2339 return BASE_CONVERSION_BADNESS
;
2340 /* else fall through */
2342 return INCOMPATIBLE_TYPE_BADNESS
;
2345 case TYPE_CODE_UNION
:
2346 switch (TYPE_CODE (arg
))
2348 case TYPE_CODE_UNION
:
2350 return INCOMPATIBLE_TYPE_BADNESS
;
2353 case TYPE_CODE_MEMBER
:
2354 switch (TYPE_CODE (arg
))
2357 return INCOMPATIBLE_TYPE_BADNESS
;
2360 case TYPE_CODE_METHOD
:
2361 switch (TYPE_CODE (arg
))
2365 return INCOMPATIBLE_TYPE_BADNESS
;
2369 switch (TYPE_CODE (arg
))
2373 return INCOMPATIBLE_TYPE_BADNESS
;
2378 switch (TYPE_CODE (arg
))
2382 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2384 return INCOMPATIBLE_TYPE_BADNESS
;
2387 case TYPE_CODE_VOID
:
2389 return INCOMPATIBLE_TYPE_BADNESS
;
2390 } /* switch (TYPE_CODE (arg)) */
2394 /* End of functions for overload resolution */
2397 print_bit_vector (bits
, nbits
)
2403 for (bitno
= 0; bitno
< nbits
; bitno
++)
2405 if ((bitno
% 8) == 0)
2407 puts_filtered (" ");
2409 if (B_TST (bits
, bitno
))
2411 printf_filtered ("1");
2415 printf_filtered ("0");
2420 /* The args list is a strange beast. It is either terminated by a NULL
2421 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2422 type for normal fixed argcount functions. (FIXME someday)
2423 Also note the first arg should be the "this" pointer, we may not want to
2424 include it since we may get into a infinitely recursive situation. */
2427 print_arg_types (args
, spaces
)
2433 while (*args
!= NULL
)
2435 recursive_dump_type (*args
, spaces
+ 2);
2436 if ((*args
++) -> code
== TYPE_CODE_VOID
)
2445 dump_fn_fieldlists (type
, spaces
)
2453 printfi_filtered (spaces
, "fn_fieldlists ");
2454 gdb_print_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2455 printf_filtered ("\n");
2456 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2458 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2459 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2461 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2462 gdb_print_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2464 printf_filtered (") length %d\n",
2465 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2466 for (overload_idx
= 0;
2467 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2470 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2472 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2473 gdb_print_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2475 printf_filtered (")\n");
2476 printfi_filtered (spaces
+ 8, "type ");
2477 gdb_print_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2478 printf_filtered ("\n");
2480 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2483 printfi_filtered (spaces
+ 8, "args ");
2484 gdb_print_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2485 printf_filtered ("\n");
2487 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
), spaces
);
2488 printfi_filtered (spaces
+ 8, "fcontext ");
2489 gdb_print_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2491 printf_filtered ("\n");
2493 printfi_filtered (spaces
+ 8, "is_const %d\n",
2494 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2495 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2496 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2497 printfi_filtered (spaces
+ 8, "is_private %d\n",
2498 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2499 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2500 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2501 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2502 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2503 printfi_filtered (spaces
+ 8, "voffset %u\n",
2504 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2510 print_cplus_stuff (type
, spaces
)
2514 printfi_filtered (spaces
, "n_baseclasses %d\n",
2515 TYPE_N_BASECLASSES (type
));
2516 printfi_filtered (spaces
, "nfn_fields %d\n",
2517 TYPE_NFN_FIELDS (type
));
2518 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2519 TYPE_NFN_FIELDS_TOTAL (type
));
2520 if (TYPE_N_BASECLASSES (type
) > 0)
2522 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2523 TYPE_N_BASECLASSES (type
));
2524 gdb_print_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2525 printf_filtered (")");
2527 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2528 TYPE_N_BASECLASSES (type
));
2529 puts_filtered ("\n");
2531 if (TYPE_NFIELDS (type
) > 0)
2533 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2535 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2536 TYPE_NFIELDS (type
));
2537 gdb_print_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2538 printf_filtered (")");
2539 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2540 TYPE_NFIELDS (type
));
2541 puts_filtered ("\n");
2543 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2545 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2546 TYPE_NFIELDS (type
));
2547 gdb_print_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2548 printf_filtered (")");
2549 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2550 TYPE_NFIELDS (type
));
2551 puts_filtered ("\n");
2554 if (TYPE_NFN_FIELDS (type
) > 0)
2556 dump_fn_fieldlists (type
, spaces
);
2560 static struct obstack dont_print_type_obstack
;
2563 recursive_dump_type (type
, spaces
)
2570 obstack_begin (&dont_print_type_obstack
, 0);
2572 if (TYPE_NFIELDS (type
) > 0
2573 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2575 struct type
**first_dont_print
2576 = (struct type
**)obstack_base (&dont_print_type_obstack
);
2578 int i
= (struct type
**)obstack_next_free (&dont_print_type_obstack
)
2583 if (type
== first_dont_print
[i
])
2585 printfi_filtered (spaces
, "type node ");
2586 gdb_print_address (type
, gdb_stdout
);
2587 printf_filtered (" <same as already seen type>\n");
2592 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2595 printfi_filtered (spaces
, "type node ");
2596 gdb_print_address (type
, gdb_stdout
);
2597 printf_filtered ("\n");
2598 printfi_filtered (spaces
, "name '%s' (",
2599 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2600 gdb_print_address (TYPE_NAME (type
), gdb_stdout
);
2601 printf_filtered (")\n");
2602 if (TYPE_TAG_NAME (type
) != NULL
)
2604 printfi_filtered (spaces
, "tagname '%s' (",
2605 TYPE_TAG_NAME (type
));
2606 gdb_print_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2607 printf_filtered (")\n");
2609 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2610 switch (TYPE_CODE (type
))
2612 case TYPE_CODE_UNDEF
:
2613 printf_filtered ("(TYPE_CODE_UNDEF)");
2616 printf_filtered ("(TYPE_CODE_PTR)");
2618 case TYPE_CODE_ARRAY
:
2619 printf_filtered ("(TYPE_CODE_ARRAY)");
2621 case TYPE_CODE_STRUCT
:
2622 printf_filtered ("(TYPE_CODE_STRUCT)");
2624 case TYPE_CODE_UNION
:
2625 printf_filtered ("(TYPE_CODE_UNION)");
2627 case TYPE_CODE_ENUM
:
2628 printf_filtered ("(TYPE_CODE_ENUM)");
2630 case TYPE_CODE_FUNC
:
2631 printf_filtered ("(TYPE_CODE_FUNC)");
2634 printf_filtered ("(TYPE_CODE_INT)");
2637 printf_filtered ("(TYPE_CODE_FLT)");
2639 case TYPE_CODE_VOID
:
2640 printf_filtered ("(TYPE_CODE_VOID)");
2643 printf_filtered ("(TYPE_CODE_SET)");
2645 case TYPE_CODE_RANGE
:
2646 printf_filtered ("(TYPE_CODE_RANGE)");
2648 case TYPE_CODE_STRING
:
2649 printf_filtered ("(TYPE_CODE_STRING)");
2651 case TYPE_CODE_ERROR
:
2652 printf_filtered ("(TYPE_CODE_ERROR)");
2654 case TYPE_CODE_MEMBER
:
2655 printf_filtered ("(TYPE_CODE_MEMBER)");
2657 case TYPE_CODE_METHOD
:
2658 printf_filtered ("(TYPE_CODE_METHOD)");
2661 printf_filtered ("(TYPE_CODE_REF)");
2663 case TYPE_CODE_CHAR
:
2664 printf_filtered ("(TYPE_CODE_CHAR)");
2666 case TYPE_CODE_BOOL
:
2667 printf_filtered ("(TYPE_CODE_BOOL)");
2669 case TYPE_CODE_TYPEDEF
:
2670 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2673 printf_filtered ("(UNKNOWN TYPE CODE)");
2676 puts_filtered ("\n");
2677 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2678 printfi_filtered (spaces
, "objfile ");
2679 gdb_print_address (TYPE_OBJFILE (type
), gdb_stdout
);
2680 printf_filtered ("\n");
2681 printfi_filtered (spaces
, "target_type ");
2682 gdb_print_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2683 printf_filtered ("\n");
2684 if (TYPE_TARGET_TYPE (type
) != NULL
)
2686 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2688 printfi_filtered (spaces
, "pointer_type ");
2689 gdb_print_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2690 printf_filtered ("\n");
2691 printfi_filtered (spaces
, "reference_type ");
2692 gdb_print_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2693 printf_filtered ("\n");
2694 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
2695 if (TYPE_FLAGS (type
) & TYPE_FLAG_UNSIGNED
)
2697 puts_filtered (" TYPE_FLAG_UNSIGNED");
2699 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
2701 puts_filtered (" TYPE_FLAG_STUB");
2703 puts_filtered ("\n");
2704 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2705 gdb_print_address (TYPE_FIELDS (type
), gdb_stdout
);
2706 puts_filtered ("\n");
2707 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2709 printfi_filtered (spaces
+ 2,
2710 "[%d] bitpos %d bitsize %d type ",
2711 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2712 TYPE_FIELD_BITSIZE (type
, idx
));
2713 gdb_print_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2714 printf_filtered (" name '%s' (",
2715 TYPE_FIELD_NAME (type
, idx
) != NULL
2716 ? TYPE_FIELD_NAME (type
, idx
)
2718 gdb_print_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2719 printf_filtered (")\n");
2720 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2722 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2725 printfi_filtered (spaces
, "vptr_basetype ");
2726 gdb_print_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2727 puts_filtered ("\n");
2728 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2730 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2732 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
2733 switch (TYPE_CODE (type
))
2735 case TYPE_CODE_METHOD
:
2736 case TYPE_CODE_FUNC
:
2737 printfi_filtered (spaces
, "arg_types ");
2738 gdb_print_address (TYPE_ARG_TYPES (type
), gdb_stdout
);
2739 puts_filtered ("\n");
2740 print_arg_types (TYPE_ARG_TYPES (type
), spaces
);
2743 case TYPE_CODE_STRUCT
:
2744 printfi_filtered (spaces
, "cplus_stuff ");
2745 gdb_print_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2746 puts_filtered ("\n");
2747 print_cplus_stuff (type
, spaces
);
2751 /* We have to pick one of the union types to be able print and test
2752 the value. Pick cplus_struct_type, even though we know it isn't
2753 any particular one. */
2754 printfi_filtered (spaces
, "type_specific ");
2755 gdb_print_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2756 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
2758 printf_filtered (" (unknown data form)");
2760 printf_filtered ("\n");
2765 obstack_free (&dont_print_type_obstack
, NULL
);
2768 static void build_gdbtypes
PARAMS ((void));
2773 init_type (TYPE_CODE_VOID
, 1,
2775 "void", (struct objfile
*) NULL
);
2777 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2779 "char", (struct objfile
*) NULL
);
2780 TYPE_FLAGS (builtin_type_char
) |= TYPE_FLAG_NOSIGN
;
2781 builtin_type_true_char
=
2782 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2784 "true character", (struct objfile
*) NULL
);
2785 builtin_type_signed_char
=
2786 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2788 "signed char", (struct objfile
*) NULL
);
2789 builtin_type_unsigned_char
=
2790 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2792 "unsigned char", (struct objfile
*) NULL
);
2793 builtin_type_short
=
2794 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
2796 "short", (struct objfile
*) NULL
);
2797 builtin_type_unsigned_short
=
2798 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
2800 "unsigned short", (struct objfile
*) NULL
);
2802 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
2804 "int", (struct objfile
*) NULL
);
2805 builtin_type_unsigned_int
=
2806 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
2808 "unsigned int", (struct objfile
*) NULL
);
2810 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
2812 "long", (struct objfile
*) NULL
);
2813 builtin_type_unsigned_long
=
2814 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
2816 "unsigned long", (struct objfile
*) NULL
);
2817 builtin_type_long_long
=
2818 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2820 "long long", (struct objfile
*) NULL
);
2821 builtin_type_unsigned_long_long
=
2822 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2824 "unsigned long long", (struct objfile
*) NULL
);
2825 builtin_type_float
=
2826 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
2828 "float", (struct objfile
*) NULL
);
2829 builtin_type_double
=
2830 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2832 "double", (struct objfile
*) NULL
);
2833 builtin_type_long_double
=
2834 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2836 "long double", (struct objfile
*) NULL
);
2837 builtin_type_complex
=
2838 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
2840 "complex", (struct objfile
*) NULL
);
2841 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
2842 builtin_type_double_complex
=
2843 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2845 "double complex", (struct objfile
*) NULL
);
2846 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
2847 builtin_type_string
=
2848 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2850 "string", (struct objfile
*) NULL
);
2852 init_type (TYPE_CODE_INT
, 8 / 8,
2854 "int8_t", (struct objfile
*) NULL
);
2855 builtin_type_uint8
=
2856 init_type (TYPE_CODE_INT
, 8 / 8,
2858 "uint8_t", (struct objfile
*) NULL
);
2859 builtin_type_int16
=
2860 init_type (TYPE_CODE_INT
, 16 / 8,
2862 "int16_t", (struct objfile
*) NULL
);
2863 builtin_type_uint16
=
2864 init_type (TYPE_CODE_INT
, 16 / 8,
2866 "uint16_t", (struct objfile
*) NULL
);
2867 builtin_type_int32
=
2868 init_type (TYPE_CODE_INT
, 32 / 8,
2870 "int32_t", (struct objfile
*) NULL
);
2871 builtin_type_uint32
=
2872 init_type (TYPE_CODE_INT
, 32 / 8,
2874 "uint32_t", (struct objfile
*) NULL
);
2875 builtin_type_int64
=
2876 init_type (TYPE_CODE_INT
, 64 / 8,
2878 "int64_t", (struct objfile
*) NULL
);
2879 builtin_type_uint64
=
2880 init_type (TYPE_CODE_INT
, 64 / 8,
2882 "uint64_t", (struct objfile
*) NULL
);
2884 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2886 "bool", (struct objfile
*) NULL
);
2888 /* Add user knob for controlling resolution of opaque types */
2890 (add_set_cmd ("opaque-type-resolution", class_support
, var_boolean
, (char *)&opaque_type_resolution
,
2891 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
2894 opaque_type_resolution
= 1;
2899 extern void _initialize_gdbtypes
PARAMS ((void));
2901 _initialize_gdbtypes ()
2905 /* FIXME - For the moment, handle types by swapping them in and out.
2906 Should be using the per-architecture data-pointer and a large
2908 register_gdbarch_swap (&builtin_type_void
, sizeof (struct type
*), NULL
);
2909 register_gdbarch_swap (&builtin_type_char
, sizeof (struct type
*), NULL
);
2910 register_gdbarch_swap (&builtin_type_short
, sizeof (struct type
*), NULL
);
2911 register_gdbarch_swap (&builtin_type_int
, sizeof (struct type
*), NULL
);
2912 register_gdbarch_swap (&builtin_type_long
, sizeof (struct type
*), NULL
);
2913 register_gdbarch_swap (&builtin_type_long_long
, sizeof (struct type
*), NULL
);
2914 register_gdbarch_swap (&builtin_type_signed_char
, sizeof (struct type
*), NULL
);
2915 register_gdbarch_swap (&builtin_type_unsigned_char
, sizeof (struct type
*), NULL
);
2916 register_gdbarch_swap (&builtin_type_unsigned_short
, sizeof (struct type
*), NULL
);
2917 register_gdbarch_swap (&builtin_type_unsigned_int
, sizeof (struct type
*), NULL
);
2918 register_gdbarch_swap (&builtin_type_unsigned_long
, sizeof (struct type
*), NULL
);
2919 register_gdbarch_swap (&builtin_type_unsigned_long_long
, sizeof (struct type
*), NULL
);
2920 register_gdbarch_swap (&builtin_type_float
, sizeof (struct type
*), NULL
);
2921 register_gdbarch_swap (&builtin_type_double
, sizeof (struct type
*), NULL
);
2922 register_gdbarch_swap (&builtin_type_long_double
, sizeof (struct type
*), NULL
);
2923 register_gdbarch_swap (&builtin_type_complex
, sizeof (struct type
*), NULL
);
2924 register_gdbarch_swap (&builtin_type_double_complex
, sizeof (struct type
*), NULL
);
2925 register_gdbarch_swap (&builtin_type_string
, sizeof (struct type
*), NULL
);
2926 register_gdbarch_swap (&builtin_type_int8
, sizeof (struct type
*), NULL
);
2927 register_gdbarch_swap (&builtin_type_uint8
, sizeof (struct type
*), NULL
);
2928 register_gdbarch_swap (&builtin_type_int16
, sizeof (struct type
*), NULL
);
2929 register_gdbarch_swap (&builtin_type_uint16
, sizeof (struct type
*), NULL
);
2930 register_gdbarch_swap (&builtin_type_int32
, sizeof (struct type
*), NULL
);
2931 register_gdbarch_swap (&builtin_type_uint32
, sizeof (struct type
*), NULL
);
2932 register_gdbarch_swap (&builtin_type_int64
, sizeof (struct type
*), NULL
);
2933 register_gdbarch_swap (&builtin_type_uint64
, sizeof (struct type
*), NULL
);
2934 register_gdbarch_swap (NULL
, 0, build_gdbtypes
);