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"
35 /* These variables point to the objects
36 representing the predefined C data types. */
38 struct type
*builtin_type_void
;
39 struct type
*builtin_type_char
;
40 struct type
*builtin_type_short
;
41 struct type
*builtin_type_int
;
42 struct type
*builtin_type_long
;
43 struct type
*builtin_type_long_long
;
44 struct type
*builtin_type_signed_char
;
45 struct type
*builtin_type_unsigned_char
;
46 struct type
*builtin_type_unsigned_short
;
47 struct type
*builtin_type_unsigned_int
;
48 struct type
*builtin_type_unsigned_long
;
49 struct type
*builtin_type_unsigned_long_long
;
50 struct type
*builtin_type_float
;
51 struct type
*builtin_type_double
;
52 struct type
*builtin_type_long_double
;
53 struct type
*builtin_type_complex
;
54 struct type
*builtin_type_double_complex
;
55 struct type
*builtin_type_string
;
56 struct type
*builtin_type_int8
;
57 struct type
*builtin_type_uint8
;
58 struct type
*builtin_type_int16
;
59 struct type
*builtin_type_uint16
;
60 struct type
*builtin_type_int32
;
61 struct type
*builtin_type_uint32
;
62 struct type
*builtin_type_int64
;
63 struct type
*builtin_type_uint64
;
64 /* start-sanitize-r5900 */
65 struct type
*builtin_type_int128
;
66 struct type
*builtin_type_uint128
;
67 /* end-sanitize-r5900 */
69 struct extra
{ char str
[128]; int len
; }; /* maximum extention is 128! FIXME */
71 static void add_name
PARAMS ((struct extra
*, char *));
72 static void add_mangled_type
PARAMS ((struct extra
*, struct type
*));
74 static void cfront_mangle_name
PARAMS ((struct type
*, int, int));
76 static void print_bit_vector
PARAMS ((B_TYPE
*, int));
77 static void print_arg_types
PARAMS ((struct type
**, int));
78 static void dump_fn_fieldlists
PARAMS ((struct type
*, int));
79 static void print_cplus_stuff
PARAMS ((struct type
*, int));
81 void _initialize_gdbtypes
PARAMS ((void));
83 /* Alloc a new type structure and fill it with some defaults. If
84 OBJFILE is non-NULL, then allocate the space for the type structure
85 in that objfile's type_obstack. */
89 struct objfile
*objfile
;
91 register struct type
*type
;
93 /* Alloc the structure and start off with all fields zeroed. */
97 type
= (struct type
*) xmalloc (sizeof (struct type
));
101 type
= (struct type
*) obstack_alloc (&objfile
-> type_obstack
,
102 sizeof (struct type
));
103 OBJSTAT (objfile
, n_types
++);
105 memset ((char *) type
, 0, sizeof (struct type
));
107 /* Initialize the fields that might not be zero. */
109 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
110 TYPE_OBJFILE (type
) = objfile
;
111 TYPE_VPTR_FIELDNO (type
) = -1;
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);
293 /* Implement direct support for MEMBER_TYPE in GNU C++.
294 May need to construct such a type if this is the first use.
295 The TYPE is the type of the member. The DOMAIN is the type
296 of the aggregate that the member belongs to. */
299 lookup_member_type (type
, domain
)
303 register struct type
*mtype
;
305 mtype
= alloc_type (TYPE_OBJFILE (type
));
306 smash_to_member_type (mtype
, domain
, type
);
310 /* Allocate a stub method whose return type is TYPE.
311 This apparently happens for speed of symbol reading, since parsing
312 out the arguments to the method is cpu-intensive, the way we are doing
313 it. So, we will fill in arguments later.
314 This always returns a fresh type. */
317 allocate_stub_method (type
)
322 mtype
= alloc_type (TYPE_OBJFILE (type
));
323 TYPE_TARGET_TYPE (mtype
) = type
;
324 /* _DOMAIN_TYPE (mtype) = unknown yet */
325 /* _ARG_TYPES (mtype) = unknown yet */
326 TYPE_FLAGS (mtype
) = TYPE_FLAG_STUB
;
327 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
328 TYPE_LENGTH (mtype
) = 1;
332 /* Create a range type using either a blank type supplied in RESULT_TYPE,
333 or creating a new type, inheriting the objfile from INDEX_TYPE.
335 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
336 HIGH_BOUND, inclusive.
338 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
339 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
342 create_range_type (result_type
, index_type
, low_bound
, high_bound
)
343 struct type
*result_type
;
344 struct type
*index_type
;
348 if (result_type
== NULL
)
350 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
352 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
353 TYPE_TARGET_TYPE (result_type
) = index_type
;
354 if (TYPE_FLAGS (index_type
) & TYPE_FLAG_STUB
)
355 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
357 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
358 TYPE_NFIELDS (result_type
) = 2;
359 TYPE_FIELDS (result_type
) = (struct field
*)
360 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
361 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
362 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
363 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
364 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
365 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
368 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
370 return (result_type
);
373 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
374 Return 1 of type is a range type, 0 if it is discrete (and bounds
375 will fit in LONGEST), or -1 otherwise. */
378 get_discrete_bounds (type
, lowp
, highp
)
380 LONGEST
*lowp
, *highp
;
382 CHECK_TYPEDEF (type
);
383 switch (TYPE_CODE (type
))
385 case TYPE_CODE_RANGE
:
386 *lowp
= TYPE_LOW_BOUND (type
);
387 *highp
= TYPE_HIGH_BOUND (type
);
390 if (TYPE_NFIELDS (type
) > 0)
392 /* The enums may not be sorted by value, so search all
396 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
397 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
399 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
400 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
401 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
402 *highp
= TYPE_FIELD_BITPOS (type
, i
);
405 /* Set unsigned indicator if warranted. */
408 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
422 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
424 if (!TYPE_UNSIGNED (type
))
426 *lowp
= - (1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
430 /* ... fall through for unsigned ints ... */
433 /* This round-about calculation is to avoid shifting by
434 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
435 if TYPE_LENGTH (type) == sizeof (LONGEST). */
436 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
437 *highp
= (*highp
- 1) | *highp
;
444 /* Create an array type using either a blank type supplied in RESULT_TYPE,
445 or creating a new type, inheriting the objfile from RANGE_TYPE.
447 Elements will be of type ELEMENT_TYPE, the indices will be of type
450 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
451 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
454 create_array_type (result_type
, element_type
, range_type
)
455 struct type
*result_type
;
456 struct type
*element_type
;
457 struct type
*range_type
;
459 LONGEST low_bound
, high_bound
;
461 if (result_type
== NULL
)
463 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
465 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
466 TYPE_TARGET_TYPE (result_type
) = element_type
;
467 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
468 low_bound
= high_bound
= 0;
469 CHECK_TYPEDEF (element_type
);
470 TYPE_LENGTH (result_type
) =
471 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
472 TYPE_NFIELDS (result_type
) = 1;
473 TYPE_FIELDS (result_type
) =
474 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
475 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
476 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
477 TYPE_VPTR_FIELDNO (result_type
) = -1;
479 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
480 if (TYPE_LENGTH (result_type
) == 0)
481 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
483 return (result_type
);
486 /* Create a string type using either a blank type supplied in RESULT_TYPE,
487 or creating a new type. String types are similar enough to array of
488 char types that we can use create_array_type to build the basic type
489 and then bash it into a string type.
491 For fixed length strings, the range type contains 0 as the lower
492 bound and the length of the string minus one as the upper bound.
494 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
495 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
498 create_string_type (result_type
, range_type
)
499 struct type
*result_type
;
500 struct type
*range_type
;
502 result_type
= create_array_type (result_type
,
503 *current_language
->string_char_type
,
505 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
506 return (result_type
);
510 create_set_type (result_type
, domain_type
)
511 struct type
*result_type
;
512 struct type
*domain_type
;
514 LONGEST low_bound
, high_bound
, bit_length
;
515 if (result_type
== NULL
)
517 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
519 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
520 TYPE_NFIELDS (result_type
) = 1;
521 TYPE_FIELDS (result_type
) = (struct field
*)
522 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
523 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
525 if (! (TYPE_FLAGS (domain_type
) & TYPE_FLAG_STUB
))
527 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
528 low_bound
= high_bound
= 0;
529 bit_length
= high_bound
- low_bound
+ 1;
530 TYPE_LENGTH (result_type
)
531 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
533 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
536 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
538 return (result_type
);
541 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
542 A MEMBER is a wierd thing -- it amounts to a typed offset into
543 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
544 include the offset (that's the value of the MEMBER itself), but does
545 include the structure type into which it points (for some reason).
547 When "smashing" the type, we preserve the objfile that the
548 old type pointed to, since we aren't changing where the type is actually
552 smash_to_member_type (type
, domain
, to_type
)
555 struct type
*to_type
;
557 struct objfile
*objfile
;
559 objfile
= TYPE_OBJFILE (type
);
561 memset ((char *) type
, 0, sizeof (struct type
));
562 TYPE_OBJFILE (type
) = objfile
;
563 TYPE_TARGET_TYPE (type
) = to_type
;
564 TYPE_DOMAIN_TYPE (type
) = domain
;
565 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
566 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
569 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
570 METHOD just means `function that gets an extra "this" argument'.
572 When "smashing" the type, we preserve the objfile that the
573 old type pointed to, since we aren't changing where the type is actually
577 smash_to_method_type (type
, domain
, to_type
, args
)
580 struct type
*to_type
;
583 struct objfile
*objfile
;
585 objfile
= TYPE_OBJFILE (type
);
587 memset ((char *) type
, 0, sizeof (struct type
));
588 TYPE_OBJFILE (type
) = objfile
;
589 TYPE_TARGET_TYPE (type
) = to_type
;
590 TYPE_DOMAIN_TYPE (type
) = domain
;
591 TYPE_ARG_TYPES (type
) = args
;
592 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
593 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
596 /* Return a typename for a struct/union/enum type without "struct ",
597 "union ", or "enum ". If the type has a NULL name, return NULL. */
600 type_name_no_tag (type
)
601 register const struct type
*type
;
603 if (TYPE_TAG_NAME (type
) != NULL
)
604 return TYPE_TAG_NAME (type
);
606 /* Is there code which expects this to return the name if there is no
607 tag name? My guess is that this is mainly used for C++ in cases where
608 the two will always be the same. */
609 return TYPE_NAME (type
);
612 /* Lookup a primitive type named NAME.
613 Return zero if NAME is not a primitive type.*/
616 lookup_primitive_typename (name
)
619 struct type
** const *p
;
621 for (p
= current_language
-> la_builtin_type_vector
; *p
!= NULL
; p
++)
623 if (STREQ ((**p
) -> name
, name
))
631 /* Lookup a typedef or primitive type named NAME,
632 visible in lexical block BLOCK.
633 If NOERR is nonzero, return zero if NAME is not suitably defined. */
636 lookup_typename (name
, block
, noerr
)
641 register struct symbol
*sym
;
642 register struct type
*tmp
;
644 sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
645 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
647 tmp
= lookup_primitive_typename (name
);
652 else if (!tmp
&& noerr
)
658 error ("No type named %s.", name
);
661 return (SYMBOL_TYPE (sym
));
665 lookup_unsigned_typename (name
)
668 char *uns
= alloca (strlen (name
) + 10);
670 strcpy (uns
, "unsigned ");
671 strcpy (uns
+ 9, name
);
672 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
676 lookup_signed_typename (name
)
680 char *uns
= alloca (strlen (name
) + 8);
682 strcpy (uns
, "signed ");
683 strcpy (uns
+ 7, name
);
684 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
685 /* If we don't find "signed FOO" just try again with plain "FOO". */
688 return lookup_typename (name
, (struct block
*) NULL
, 0);
691 /* Lookup a structure type named "struct NAME",
692 visible in lexical block BLOCK. */
695 lookup_struct (name
, block
)
699 register struct symbol
*sym
;
701 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
702 (struct symtab
**) NULL
);
706 error ("No struct type named %s.", name
);
708 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
710 error ("This context has class, union or enum %s, not a struct.", name
);
712 return (SYMBOL_TYPE (sym
));
715 /* Lookup a union type named "union NAME",
716 visible in lexical block BLOCK. */
719 lookup_union (name
, block
)
723 register struct symbol
*sym
;
725 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
726 (struct symtab
**) NULL
);
730 error ("No union type named %s.", name
);
732 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_UNION
)
734 error ("This context has class, struct or enum %s, not a union.", name
);
736 return (SYMBOL_TYPE (sym
));
739 /* Lookup an enum type named "enum NAME",
740 visible in lexical block BLOCK. */
743 lookup_enum (name
, block
)
747 register struct symbol
*sym
;
749 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
750 (struct symtab
**) NULL
);
753 error ("No enum type named %s.", name
);
755 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
757 error ("This context has class, struct or union %s, not an enum.", name
);
759 return (SYMBOL_TYPE (sym
));
762 /* Lookup a template type named "template NAME<TYPE>",
763 visible in lexical block BLOCK. */
766 lookup_template_type (name
, type
, block
)
772 char *nam
= (char*) alloca(strlen(name
) + strlen(type
->name
) + 4);
775 strcat (nam
, type
->name
);
776 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
778 sym
= lookup_symbol (nam
, block
, VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
782 error ("No template type named %s.", name
);
784 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
786 error ("This context has class, union or enum %s, not a struct.", name
);
788 return (SYMBOL_TYPE (sym
));
791 /* Given a type TYPE, lookup the type of the component of type named NAME.
793 TYPE can be either a struct or union, or a pointer or reference to a struct or
794 union. If it is a pointer or reference, its target type is automatically used.
795 Thus '.' and '->' are interchangable, as specified for the definitions of the
796 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
798 If NOERR is nonzero, return zero if NAME is not suitably defined.
799 If NAME is the name of a baseclass type, return that type. */
802 lookup_struct_elt_type (type
, name
, noerr
)
811 CHECK_TYPEDEF (type
);
812 if (TYPE_CODE (type
) != TYPE_CODE_PTR
813 && TYPE_CODE (type
) != TYPE_CODE_REF
)
815 type
= TYPE_TARGET_TYPE (type
);
818 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
819 TYPE_CODE (type
) != TYPE_CODE_UNION
)
821 target_terminal_ours ();
822 gdb_flush (gdb_stdout
);
823 fprintf_unfiltered (gdb_stderr
, "Type ");
824 type_print (type
, "", gdb_stderr
, -1);
825 error (" is not a structure or union type.");
829 /* FIXME: This change put in by Michael seems incorrect for the case where
830 the structure tag name is the same as the member name. I.E. when doing
831 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
836 typename
= type_name_no_tag (type
);
837 if (typename
!= NULL
&& STREQ (typename
, name
))
842 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
844 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
846 if (t_field_name
&& STREQ (t_field_name
, name
))
848 return TYPE_FIELD_TYPE (type
, i
);
852 /* OK, it's not in this class. Recursively check the baseclasses. */
853 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
857 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
869 target_terminal_ours ();
870 gdb_flush (gdb_stdout
);
871 fprintf_unfiltered (gdb_stderr
, "Type ");
872 type_print (type
, "", gdb_stderr
, -1);
873 fprintf_unfiltered (gdb_stderr
, " has no component named ");
874 fputs_filtered (name
, gdb_stderr
);
876 return (struct type
*)-1; /* For lint */
879 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
880 valid. Callers should be aware that in some cases (for example,
881 the type or one of its baseclasses is a stub type and we are
882 debugging a .o file), this function will not be able to find the virtual
883 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
887 fill_in_vptr_fieldno (type
)
890 CHECK_TYPEDEF (type
);
892 if (TYPE_VPTR_FIELDNO (type
) < 0)
896 /* We must start at zero in case the first (and only) baseclass is
897 virtual (and hence we cannot share the table pointer). */
898 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
900 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
901 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
903 TYPE_VPTR_FIELDNO (type
)
904 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
905 TYPE_VPTR_BASETYPE (type
)
906 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
913 /* Find the method and field indices for the destructor in class type T.
914 Return 1 if the destructor was found, otherwise, return 0. */
917 get_destructor_fn_field (t
, method_indexp
, field_indexp
)
924 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
927 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
929 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
931 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f
, j
)))
942 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
944 If this is a stubbed struct (i.e. declared as struct foo *), see if
945 we can find a full definition in some other file. If so, copy this
946 definition, so we can use it in future. There used to be a comment (but
947 not any code) that if we don't find a full definition, we'd set a flag
948 so we don't spend time in the future checking the same type. That would
949 be a mistake, though--we might load in more symbols which contain a
950 full definition for the type.
952 This used to be coded as a macro, but I don't think it is called
953 often enough to merit such treatment. */
955 struct complaint stub_noname_complaint
=
956 {"stub type has NULL name", 0, 0};
960 register struct type
*type
;
962 struct type
*orig_type
= type
;
963 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
965 if (!TYPE_TARGET_TYPE (type
))
970 /* It is dangerous to call lookup_symbol if we are currently
971 reading a symtab. Infinite recursion is one danger. */
972 if (currently_reading_symtab
)
975 name
= type_name_no_tag (type
);
976 /* FIXME: shouldn't we separately check the TYPE_NAME and the
977 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
978 as appropriate? (this code was written before TYPE_NAME and
979 TYPE_TAG_NAME were separate). */
982 complain (&stub_noname_complaint
);
985 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
986 (struct symtab
**) NULL
);
988 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
990 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
992 type
= TYPE_TARGET_TYPE (type
);
995 if ((TYPE_FLAGS(type
) & TYPE_FLAG_STUB
) && ! currently_reading_symtab
)
997 char* name
= type_name_no_tag (type
);
998 /* FIXME: shouldn't we separately check the TYPE_NAME and the
999 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1000 as appropriate? (this code was written before TYPE_NAME and
1001 TYPE_TAG_NAME were separate). */
1005 complain (&stub_noname_complaint
);
1008 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
1009 (struct symtab
**) NULL
);
1012 memcpy ((char *)type
,
1013 (char *)SYMBOL_TYPE(sym
),
1014 sizeof (struct type
));
1018 if (TYPE_FLAGS (type
) & TYPE_FLAG_TARGET_STUB
)
1020 struct type
*range_type
;
1021 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1023 if (TYPE_FLAGS (target_type
) & (TYPE_FLAG_STUB
| TYPE_FLAG_TARGET_STUB
))
1025 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1026 && TYPE_NFIELDS (type
) == 1
1027 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1028 == TYPE_CODE_RANGE
))
1030 /* Now recompute the length of the array type, based on its
1031 number of elements and the target type's length. */
1032 TYPE_LENGTH (type
) =
1033 ((TYPE_FIELD_BITPOS (range_type
, 1)
1034 - TYPE_FIELD_BITPOS (range_type
, 0)
1036 * TYPE_LENGTH (target_type
));
1037 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1039 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1041 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1042 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1045 /* Cache TYPE_LENGTH for future use. */
1046 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1050 /* New code added to support parsing of Cfront stabs strings */
1052 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1053 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1057 struct extra
* pextras
;
1062 if ((nlen
= (n
? strlen(n
) : 0))==0)
1064 sprintf(pextras
->str
+pextras
->len
,"%d%s",nlen
,n
);
1065 pextras
->len
=strlen(pextras
->str
);
1069 add_mangled_type(pextras
,t
)
1070 struct extra
* pextras
;
1073 enum type_code tcode
;
1077 tcode
= TYPE_CODE(t
);
1078 tlen
= TYPE_LENGTH(t
);
1079 tflags
= TYPE_FLAGS(t
);
1080 tname
= TYPE_NAME(t
);
1081 /* args of "..." seem to get mangled as "e" */
1099 if ((pname
=strrchr(tname
,'l'),pname
) && !strcmp(pname
,"long"))
1108 static struct complaint msg
= {"Bad int type code length x%x\n",0,0};
1110 complain (&msg
, tlen
);
1129 static struct complaint msg
= {"Bad float type code length x%x\n",0,0};
1130 complain (&msg
, tlen
);
1136 /* followed by what it's a ref to */
1140 /* followed by what it's a ptr to */
1142 case TYPE_CODE_TYPEDEF
:
1144 static struct complaint msg
= {"Typedefs in overloaded functions not yet supported\n",0,0};
1147 /* followed by type bytes & name */
1149 case TYPE_CODE_FUNC
:
1151 /* followed by func's arg '_' & ret types */
1153 case TYPE_CODE_VOID
:
1156 case TYPE_CODE_METHOD
:
1158 /* followed by name of class and func's arg '_' & ret types */
1159 add_name(pextras
,tname
);
1160 ADD_EXTRA('F'); /* then mangle function */
1162 case TYPE_CODE_STRUCT
: /* C struct */
1163 case TYPE_CODE_UNION
: /* C union */
1164 case TYPE_CODE_ENUM
: /* Enumeration type */
1165 /* followed by name of type */
1166 add_name(pextras
,tname
);
1169 /* errors possible types/not supported */
1170 case TYPE_CODE_CHAR
:
1171 case TYPE_CODE_ARRAY
: /* Array type */
1172 case TYPE_CODE_MEMBER
: /* Member type */
1173 case TYPE_CODE_BOOL
:
1174 case TYPE_CODE_COMPLEX
: /* Complex float */
1175 case TYPE_CODE_UNDEF
:
1176 case TYPE_CODE_SET
: /* Pascal sets */
1177 case TYPE_CODE_RANGE
:
1178 case TYPE_CODE_STRING
:
1179 case TYPE_CODE_BITSTRING
:
1180 case TYPE_CODE_ERROR
:
1183 static struct complaint msg
= {"Unknown type code x%x\n",0,0};
1184 complain (&msg
, tcode
);
1188 add_mangled_type(pextras
,t
->target_type
);
1193 cfront_mangle_name(type
, i
, j
)
1199 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1201 f
= TYPE_FN_FIELDLIST1 (type
, i
); /* moved from below */
1203 /* kludge to support cfront methods - gdb expects to find "F" for
1204 ARM_mangled names, so when we mangle, we have to add it here */
1208 char * arm_mangled_name
;
1209 struct fn_field
*method
= &f
[j
];
1210 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1211 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1212 char *newname
= type_name_no_tag (type
);
1214 struct type
*ftype
= TYPE_FN_FIELD_TYPE (f
, j
);
1215 int nargs
= TYPE_NFIELDS(ftype
); /* number of args */
1216 struct extra extras
, * pextras
= &extras
;
1219 if (TYPE_FN_FIELD_STATIC_P (f
, j
)) /* j for sublist within this list */
1222 /* add args here! */
1223 if (nargs
<= 1) /* no args besides this */
1226 for (k
=1; k
<nargs
; k
++)
1229 t
= TYPE_FIELD_TYPE(ftype
,k
);
1230 add_mangled_type(pextras
,t
);
1234 printf("add_mangled_type: %s\n",extras
.str
); /* FIXME */
1235 arm_mangled_name
= malloc(strlen(mangled_name
)+extras
.len
);
1236 sprintf(arm_mangled_name
,"%s%s",mangled_name
,extras
.str
);
1238 mangled_name
= arm_mangled_name
;
1244 /* End of new code added to support parsing of Cfront stabs strings */
1246 /* Ugly hack to convert method stubs into method types.
1248 He ain't kiddin'. This demangles the name of the method into a string
1249 including argument types, parses out each argument type, generates
1250 a string casting a zero to that type, evaluates the string, and stuffs
1251 the resulting type into an argtype vector!!! Then it knows the type
1252 of the whole function (including argument types for overloading),
1253 which info used to be in the stab's but was removed to hack back
1254 the space required for them. */
1257 check_stub_method (type
, method_id
, signature_id
)
1263 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1264 char *demangled_name
= cplus_demangle (mangled_name
,
1265 DMGL_PARAMS
| DMGL_ANSI
);
1266 char *argtypetext
, *p
;
1267 int depth
= 0, argcount
= 1;
1268 struct type
**argtypes
;
1271 /* Make sure we got back a function string that we can use. */
1273 p
= strchr (demangled_name
, '(');
1275 if (demangled_name
== NULL
|| p
== NULL
)
1276 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
1278 /* Now, read in the parameters that define this type. */
1291 else if (*p
== ',' && depth
== 0)
1299 /* We need two more slots: one for the THIS pointer, and one for the
1300 NULL [...] or void [end of arglist]. */
1302 argtypes
= (struct type
**)
1303 TYPE_ALLOC (type
, (argcount
+ 2) * sizeof (struct type
*));
1305 /* FIXME: This is wrong for static member functions. */
1306 argtypes
[0] = lookup_pointer_type (type
);
1309 if (*p
!= ')') /* () means no args, skip while */
1314 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1316 /* Avoid parsing of ellipsis, they will be handled below. */
1317 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0)
1319 argtypes
[argcount
] =
1320 parse_and_eval_type (argtypetext
, p
- argtypetext
);
1323 argtypetext
= p
+ 1;
1339 if (p
[-2] != '.') /* Not '...' */
1341 argtypes
[argcount
] = builtin_type_void
; /* List terminator */
1345 argtypes
[argcount
] = NULL
; /* Ellist terminator */
1348 free (demangled_name
);
1350 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1352 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1354 /* Now update the old "stub" type into a real type. */
1355 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1356 TYPE_DOMAIN_TYPE (mtype
) = type
;
1357 TYPE_ARG_TYPES (mtype
) = argtypes
;
1358 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1359 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1362 const struct cplus_struct_type cplus_struct_default
;
1365 allocate_cplus_struct_type (type
)
1368 if (!HAVE_CPLUS_STRUCT (type
))
1370 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1371 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1372 *(TYPE_CPLUS_SPECIFIC(type
)) = cplus_struct_default
;
1376 /* Helper function to initialize the standard scalar types.
1378 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1379 of the string pointed to by name in the type_obstack for that objfile,
1380 and initialize the type name to that copy. There are places (mipsread.c
1381 in particular, where init_type is called with a NULL value for NAME). */
1384 init_type (code
, length
, flags
, name
, objfile
)
1385 enum type_code code
;
1389 struct objfile
*objfile
;
1391 register struct type
*type
;
1393 type
= alloc_type (objfile
);
1394 TYPE_CODE (type
) = code
;
1395 TYPE_LENGTH (type
) = length
;
1396 TYPE_FLAGS (type
) |= flags
;
1397 if ((name
!= NULL
) && (objfile
!= NULL
))
1400 obsavestring (name
, strlen (name
), &objfile
-> type_obstack
);
1404 TYPE_NAME (type
) = name
;
1409 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1411 INIT_CPLUS_SPECIFIC (type
);
1416 /* Look up a fundamental type for the specified objfile.
1417 May need to construct such a type if this is the first use.
1419 Some object file formats (ELF, COFF, etc) do not define fundamental
1420 types such as "int" or "double". Others (stabs for example), do
1421 define fundamental types.
1423 For the formats which don't provide fundamental types, gdb can create
1424 such types, using defaults reasonable for the current language and
1425 the current target machine.
1427 NOTE: This routine is obsolescent. Each debugging format reader
1428 should manage it's own fundamental types, either creating them from
1429 suitable defaults or reading them from the debugging information,
1430 whichever is appropriate. The DWARF reader has already been
1431 fixed to do this. Once the other readers are fixed, this routine
1432 will go away. Also note that fundamental types should be managed
1433 on a compilation unit basis in a multi-language environment, not
1434 on a linkage unit basis as is done here. */
1438 lookup_fundamental_type (objfile
, typeid)
1439 struct objfile
*objfile
;
1442 register struct type
**typep
;
1443 register int nbytes
;
1445 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1447 error ("internal error - invalid fundamental type id %d", typeid);
1450 /* If this is the first time we need a fundamental type for this objfile
1451 then we need to initialize the vector of type pointers. */
1453 if (objfile
-> fundamental_types
== NULL
)
1455 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1456 objfile
-> fundamental_types
= (struct type
**)
1457 obstack_alloc (&objfile
-> type_obstack
, nbytes
);
1458 memset ((char *) objfile
-> fundamental_types
, 0, nbytes
);
1459 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1462 /* Look for this particular type in the fundamental type vector. If one is
1463 not found, create and install one appropriate for the current language. */
1465 typep
= objfile
-> fundamental_types
+ typeid;
1468 *typep
= create_fundamental_type (objfile
, typeid);
1478 /* FIXME: Should we return true for references as well as pointers? */
1482 && TYPE_CODE (t
) == TYPE_CODE_PTR
1483 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1486 /* Chill varying string and arrays are represented as follows:
1488 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1490 Return true if TYPE is such a Chill varying type. */
1493 chill_varying_type (type
)
1496 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1497 || TYPE_NFIELDS (type
) != 2
1498 || strcmp (TYPE_FIELD_NAME (type
, 0), "__var_length") != 0)
1503 #if MAINTENANCE_CMDS
1506 print_bit_vector (bits
, nbits
)
1512 for (bitno
= 0; bitno
< nbits
; bitno
++)
1514 if ((bitno
% 8) == 0)
1516 puts_filtered (" ");
1518 if (B_TST (bits
, bitno
))
1520 printf_filtered ("1");
1524 printf_filtered ("0");
1529 /* The args list is a strange beast. It is either terminated by a NULL
1530 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
1531 type for normal fixed argcount functions. (FIXME someday)
1532 Also note the first arg should be the "this" pointer, we may not want to
1533 include it since we may get into a infinitely recursive situation. */
1536 print_arg_types (args
, spaces
)
1542 while (*args
!= NULL
)
1544 recursive_dump_type (*args
, spaces
+ 2);
1545 if ((*args
++) -> code
== TYPE_CODE_VOID
)
1554 dump_fn_fieldlists (type
, spaces
)
1562 printfi_filtered (spaces
, "fn_fieldlists ");
1563 gdb_print_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
1564 printf_filtered ("\n");
1565 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
1567 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
1568 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
1570 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
1571 gdb_print_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
1573 printf_filtered (") length %d\n",
1574 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
1575 for (overload_idx
= 0;
1576 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
1579 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
1581 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
1582 gdb_print_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
1584 printf_filtered (")\n");
1585 printfi_filtered (spaces
+ 8, "type ");
1586 gdb_print_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
1587 printf_filtered ("\n");
1589 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
1592 printfi_filtered (spaces
+ 8, "args ");
1593 gdb_print_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
1594 printf_filtered ("\n");
1596 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
), spaces
);
1597 printfi_filtered (spaces
+ 8, "fcontext ");
1598 gdb_print_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
1600 printf_filtered ("\n");
1602 printfi_filtered (spaces
+ 8, "is_const %d\n",
1603 TYPE_FN_FIELD_CONST (f
, overload_idx
));
1604 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
1605 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
1606 printfi_filtered (spaces
+ 8, "is_private %d\n",
1607 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
1608 printfi_filtered (spaces
+ 8, "is_protected %d\n",
1609 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
1610 printfi_filtered (spaces
+ 8, "is_stub %d\n",
1611 TYPE_FN_FIELD_STUB (f
, overload_idx
));
1612 printfi_filtered (spaces
+ 8, "voffset %u\n",
1613 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
1619 print_cplus_stuff (type
, spaces
)
1623 printfi_filtered (spaces
, "n_baseclasses %d\n",
1624 TYPE_N_BASECLASSES (type
));
1625 printfi_filtered (spaces
, "nfn_fields %d\n",
1626 TYPE_NFN_FIELDS (type
));
1627 printfi_filtered (spaces
, "nfn_fields_total %d\n",
1628 TYPE_NFN_FIELDS_TOTAL (type
));
1629 if (TYPE_N_BASECLASSES (type
) > 0)
1631 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
1632 TYPE_N_BASECLASSES (type
));
1633 gdb_print_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
1634 printf_filtered (")");
1636 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
1637 TYPE_N_BASECLASSES (type
));
1638 puts_filtered ("\n");
1640 if (TYPE_NFIELDS (type
) > 0)
1642 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
1644 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
1645 TYPE_NFIELDS (type
));
1646 gdb_print_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
1647 printf_filtered (")");
1648 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
1649 TYPE_NFIELDS (type
));
1650 puts_filtered ("\n");
1652 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
1654 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
1655 TYPE_NFIELDS (type
));
1656 gdb_print_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
1657 printf_filtered (")");
1658 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
1659 TYPE_NFIELDS (type
));
1660 puts_filtered ("\n");
1663 if (TYPE_NFN_FIELDS (type
) > 0)
1665 dump_fn_fieldlists (type
, spaces
);
1669 static struct obstack dont_print_type_obstack
;
1672 recursive_dump_type (type
, spaces
)
1679 obstack_begin (&dont_print_type_obstack
, 0);
1681 if (TYPE_NFIELDS (type
) > 0
1682 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
1684 struct type
**first_dont_print
1685 = (struct type
**)obstack_base (&dont_print_type_obstack
);
1687 int i
= (struct type
**)obstack_next_free (&dont_print_type_obstack
)
1692 if (type
== first_dont_print
[i
])
1694 printfi_filtered (spaces
, "type node ");
1695 gdb_print_address (type
, gdb_stdout
);
1696 printf_filtered (" <same as already seen type>\n");
1701 obstack_ptr_grow (&dont_print_type_obstack
, type
);
1704 printfi_filtered (spaces
, "type node ");
1705 gdb_print_address (type
, gdb_stdout
);
1706 printf_filtered ("\n");
1707 printfi_filtered (spaces
, "name '%s' (",
1708 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
1709 gdb_print_address (TYPE_NAME (type
), gdb_stdout
);
1710 printf_filtered (")\n");
1711 if (TYPE_TAG_NAME (type
) != NULL
)
1713 printfi_filtered (spaces
, "tagname '%s' (",
1714 TYPE_TAG_NAME (type
));
1715 gdb_print_address (TYPE_TAG_NAME (type
), gdb_stdout
);
1716 printf_filtered (")\n");
1718 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
1719 switch (TYPE_CODE (type
))
1721 case TYPE_CODE_UNDEF
:
1722 printf_filtered ("(TYPE_CODE_UNDEF)");
1725 printf_filtered ("(TYPE_CODE_PTR)");
1727 case TYPE_CODE_ARRAY
:
1728 printf_filtered ("(TYPE_CODE_ARRAY)");
1730 case TYPE_CODE_STRUCT
:
1731 printf_filtered ("(TYPE_CODE_STRUCT)");
1733 case TYPE_CODE_UNION
:
1734 printf_filtered ("(TYPE_CODE_UNION)");
1736 case TYPE_CODE_ENUM
:
1737 printf_filtered ("(TYPE_CODE_ENUM)");
1739 case TYPE_CODE_FUNC
:
1740 printf_filtered ("(TYPE_CODE_FUNC)");
1743 printf_filtered ("(TYPE_CODE_INT)");
1746 printf_filtered ("(TYPE_CODE_FLT)");
1748 case TYPE_CODE_VOID
:
1749 printf_filtered ("(TYPE_CODE_VOID)");
1752 printf_filtered ("(TYPE_CODE_SET)");
1754 case TYPE_CODE_RANGE
:
1755 printf_filtered ("(TYPE_CODE_RANGE)");
1757 case TYPE_CODE_STRING
:
1758 printf_filtered ("(TYPE_CODE_STRING)");
1760 case TYPE_CODE_ERROR
:
1761 printf_filtered ("(TYPE_CODE_ERROR)");
1763 case TYPE_CODE_MEMBER
:
1764 printf_filtered ("(TYPE_CODE_MEMBER)");
1766 case TYPE_CODE_METHOD
:
1767 printf_filtered ("(TYPE_CODE_METHOD)");
1770 printf_filtered ("(TYPE_CODE_REF)");
1772 case TYPE_CODE_CHAR
:
1773 printf_filtered ("(TYPE_CODE_CHAR)");
1775 case TYPE_CODE_BOOL
:
1776 printf_filtered ("(TYPE_CODE_BOOL)");
1778 case TYPE_CODE_TYPEDEF
:
1779 printf_filtered ("(TYPE_CODE_TYPEDEF)");
1782 printf_filtered ("(UNKNOWN TYPE CODE)");
1785 puts_filtered ("\n");
1786 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
1787 printfi_filtered (spaces
, "objfile ");
1788 gdb_print_address (TYPE_OBJFILE (type
), gdb_stdout
);
1789 printf_filtered ("\n");
1790 printfi_filtered (spaces
, "target_type ");
1791 gdb_print_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
1792 printf_filtered ("\n");
1793 if (TYPE_TARGET_TYPE (type
) != NULL
)
1795 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
1797 printfi_filtered (spaces
, "pointer_type ");
1798 gdb_print_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
1799 printf_filtered ("\n");
1800 printfi_filtered (spaces
, "reference_type ");
1801 gdb_print_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
1802 printf_filtered ("\n");
1803 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
1804 if (TYPE_FLAGS (type
) & TYPE_FLAG_UNSIGNED
)
1806 puts_filtered (" TYPE_FLAG_UNSIGNED");
1808 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1810 puts_filtered (" TYPE_FLAG_STUB");
1812 puts_filtered ("\n");
1813 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
1814 gdb_print_address (TYPE_FIELDS (type
), gdb_stdout
);
1815 puts_filtered ("\n");
1816 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
1818 printfi_filtered (spaces
+ 2,
1819 "[%d] bitpos %d bitsize %d type ",
1820 idx
, TYPE_FIELD_BITPOS (type
, idx
),
1821 TYPE_FIELD_BITSIZE (type
, idx
));
1822 gdb_print_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
1823 printf_filtered (" name '%s' (",
1824 TYPE_FIELD_NAME (type
, idx
) != NULL
1825 ? TYPE_FIELD_NAME (type
, idx
)
1827 gdb_print_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
1828 printf_filtered (")\n");
1829 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
1831 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
1834 printfi_filtered (spaces
, "vptr_basetype ");
1835 gdb_print_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
1836 puts_filtered ("\n");
1837 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
1839 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
1841 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
1842 switch (TYPE_CODE (type
))
1844 case TYPE_CODE_METHOD
:
1845 case TYPE_CODE_FUNC
:
1846 printfi_filtered (spaces
, "arg_types ");
1847 gdb_print_address (TYPE_ARG_TYPES (type
), gdb_stdout
);
1848 puts_filtered ("\n");
1849 print_arg_types (TYPE_ARG_TYPES (type
), spaces
);
1852 case TYPE_CODE_STRUCT
:
1853 printfi_filtered (spaces
, "cplus_stuff ");
1854 gdb_print_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
1855 puts_filtered ("\n");
1856 print_cplus_stuff (type
, spaces
);
1860 /* We have to pick one of the union types to be able print and test
1861 the value. Pick cplus_struct_type, even though we know it isn't
1862 any particular one. */
1863 printfi_filtered (spaces
, "type_specific ");
1864 gdb_print_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
1865 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
1867 printf_filtered (" (unknown data form)");
1869 printf_filtered ("\n");
1874 obstack_free (&dont_print_type_obstack
, NULL
);
1877 #endif /* MAINTENANCE_CMDS */
1880 _initialize_gdbtypes ()
1883 init_type (TYPE_CODE_VOID
, 1,
1885 "void", (struct objfile
*) NULL
);
1887 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
1889 "char", (struct objfile
*) NULL
);
1890 builtin_type_signed_char
=
1891 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
1893 "signed char", (struct objfile
*) NULL
);
1894 builtin_type_unsigned_char
=
1895 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
1897 "unsigned char", (struct objfile
*) NULL
);
1898 builtin_type_short
=
1899 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
1901 "short", (struct objfile
*) NULL
);
1902 builtin_type_unsigned_short
=
1903 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
1905 "unsigned short", (struct objfile
*) NULL
);
1907 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1909 "int", (struct objfile
*) NULL
);
1910 builtin_type_unsigned_int
=
1911 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1913 "unsigned int", (struct objfile
*) NULL
);
1915 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
1917 "long", (struct objfile
*) NULL
);
1918 builtin_type_unsigned_long
=
1919 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
1921 "unsigned long", (struct objfile
*) NULL
);
1922 builtin_type_long_long
=
1923 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
1925 "long long", (struct objfile
*) NULL
);
1926 builtin_type_unsigned_long_long
=
1927 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
1929 "unsigned long long", (struct objfile
*) NULL
);
1930 builtin_type_float
=
1931 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
1933 "float", (struct objfile
*) NULL
);
1934 builtin_type_double
=
1935 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
1937 "double", (struct objfile
*) NULL
);
1938 builtin_type_long_double
=
1939 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
1941 "long double", (struct objfile
*) NULL
);
1942 builtin_type_complex
=
1943 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
1945 "complex", (struct objfile
*) NULL
);
1946 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
1947 builtin_type_double_complex
=
1948 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
1950 "double complex", (struct objfile
*) NULL
);
1951 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
1952 builtin_type_string
=
1953 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
1955 "string", (struct objfile
*) NULL
);
1957 init_type (TYPE_CODE_INT
, 8 / 8,
1959 "int8_t", (struct objfile
*) NULL
);
1960 builtin_type_uint8
=
1961 init_type (TYPE_CODE_INT
, 8 / 8,
1963 "uint8_t", (struct objfile
*) NULL
);
1964 builtin_type_int16
=
1965 init_type (TYPE_CODE_INT
, 16 / 8,
1967 "int16_t", (struct objfile
*) NULL
);
1968 builtin_type_uint16
=
1969 init_type (TYPE_CODE_INT
, 16 / 8,
1971 "uint16_t", (struct objfile
*) NULL
);
1972 builtin_type_int32
=
1973 init_type (TYPE_CODE_INT
, 32 / 8,
1975 "int32_t", (struct objfile
*) NULL
);
1976 builtin_type_uint32
=
1977 init_type (TYPE_CODE_INT
, 32 / 8,
1979 "uint32_t", (struct objfile
*) NULL
);
1980 builtin_type_int64
=
1981 init_type (TYPE_CODE_INT
, 64 / 8,
1983 "int64_t", (struct objfile
*) NULL
);
1984 builtin_type_uint64
=
1985 init_type (TYPE_CODE_INT
, 64 / 8,
1987 "uint64_t", (struct objfile
*) NULL
);
1988 /* start-sanitize-r5900 */
1989 builtin_type_int128
=
1990 init_type (TYPE_CODE_INT
, 128 / 8,
1992 "int128_t", (struct objfile
*) NULL
);
1993 builtin_type_uint128
=
1994 init_type (TYPE_CODE_INT
, 128 / 8,
1996 "uint128_t", (struct objfile
*) NULL
);
1997 /* end-sanitize-r5900 */