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 /* Alloc a new type structure and fill it with some defaults. If
82 OBJFILE is non-NULL, then allocate the space for the type structure
83 in that objfile's type_obstack. */
87 struct objfile
*objfile
;
89 register struct type
*type
;
91 /* Alloc the structure and start off with all fields zeroed. */
95 type
= (struct type
*) xmalloc (sizeof (struct type
));
99 type
= (struct type
*) obstack_alloc (&objfile
-> type_obstack
,
100 sizeof (struct type
));
101 OBJSTAT (objfile
, n_types
++);
103 memset ((char *) type
, 0, sizeof (struct type
));
105 /* Initialize the fields that might not be zero. */
107 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
108 TYPE_OBJFILE (type
) = objfile
;
109 TYPE_VPTR_FIELDNO (type
) = -1;
114 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
115 to a pointer to memory where the pointer type should be stored.
116 If *TYPEPTR is zero, update it to point to the pointer type we return.
117 We allocate new memory if needed. */
120 make_pointer_type (type
, typeptr
)
122 struct type
**typeptr
;
124 register struct type
*ntype
; /* New type */
125 struct objfile
*objfile
;
127 ntype
= TYPE_POINTER_TYPE (type
);
132 return ntype
; /* Don't care about alloc, and have new type. */
133 else if (*typeptr
== 0)
135 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
140 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
142 ntype
= alloc_type (TYPE_OBJFILE (type
));
146 else /* We have storage, but need to reset it. */
149 objfile
= TYPE_OBJFILE (ntype
);
150 memset ((char *) ntype
, 0, sizeof (struct type
));
151 TYPE_OBJFILE (ntype
) = objfile
;
154 TYPE_TARGET_TYPE (ntype
) = type
;
155 TYPE_POINTER_TYPE (type
) = ntype
;
157 /* FIXME! Assume the machine has only one representation for pointers! */
159 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
160 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
162 /* pointers are unsigned */
163 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
165 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
166 TYPE_POINTER_TYPE (type
) = ntype
;
171 /* Given a type TYPE, return a type of pointers to that type.
172 May need to construct such a type if this is the first use. */
175 lookup_pointer_type (type
)
178 return make_pointer_type (type
, (struct type
**)0);
181 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
182 to a pointer to memory where the reference type should be stored.
183 If *TYPEPTR is zero, update it to point to the reference type we return.
184 We allocate new memory if needed. */
187 make_reference_type (type
, typeptr
)
189 struct type
**typeptr
;
191 register struct type
*ntype
; /* New type */
192 struct objfile
*objfile
;
194 ntype
= TYPE_REFERENCE_TYPE (type
);
199 return ntype
; /* Don't care about alloc, and have new type. */
200 else if (*typeptr
== 0)
202 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
207 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
209 ntype
= alloc_type (TYPE_OBJFILE (type
));
213 else /* We have storage, but need to reset it. */
216 objfile
= TYPE_OBJFILE (ntype
);
217 memset ((char *) ntype
, 0, sizeof (struct type
));
218 TYPE_OBJFILE (ntype
) = objfile
;
221 TYPE_TARGET_TYPE (ntype
) = type
;
222 TYPE_REFERENCE_TYPE (type
) = ntype
;
224 /* FIXME! Assume the machine has only one representation for references,
225 and that it matches the (only) representation for pointers! */
227 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
228 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
230 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
231 TYPE_REFERENCE_TYPE (type
) = ntype
;
236 /* Same as above, but caller doesn't care about memory allocation details. */
239 lookup_reference_type (type
)
242 return make_reference_type (type
, (struct type
**)0);
245 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
246 to a pointer to memory where the function type should be stored.
247 If *TYPEPTR is zero, update it to point to the function type we return.
248 We allocate new memory if needed. */
251 make_function_type (type
, typeptr
)
253 struct type
**typeptr
;
255 register struct type
*ntype
; /* New type */
256 struct objfile
*objfile
;
258 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
260 ntype
= alloc_type (TYPE_OBJFILE (type
));
264 else /* We have storage, but need to reset it. */
267 objfile
= TYPE_OBJFILE (ntype
);
268 memset ((char *) ntype
, 0, sizeof (struct type
));
269 TYPE_OBJFILE (ntype
) = objfile
;
272 TYPE_TARGET_TYPE (ntype
) = type
;
274 TYPE_LENGTH (ntype
) = 1;
275 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
281 /* Given a type TYPE, return a type of functions that return that type.
282 May need to construct such a type if this is the first use. */
285 lookup_function_type (type
)
288 return make_function_type (type
, (struct type
**)0);
291 /* Implement direct support for MEMBER_TYPE in GNU C++.
292 May need to construct such a type if this is the first use.
293 The TYPE is the type of the member. The DOMAIN is the type
294 of the aggregate that the member belongs to. */
297 lookup_member_type (type
, domain
)
301 register struct type
*mtype
;
303 mtype
= alloc_type (TYPE_OBJFILE (type
));
304 smash_to_member_type (mtype
, domain
, type
);
308 /* Allocate a stub method whose return type is TYPE.
309 This apparently happens for speed of symbol reading, since parsing
310 out the arguments to the method is cpu-intensive, the way we are doing
311 it. So, we will fill in arguments later.
312 This always returns a fresh type. */
315 allocate_stub_method (type
)
320 mtype
= alloc_type (TYPE_OBJFILE (type
));
321 TYPE_TARGET_TYPE (mtype
) = type
;
322 /* _DOMAIN_TYPE (mtype) = unknown yet */
323 /* _ARG_TYPES (mtype) = unknown yet */
324 TYPE_FLAGS (mtype
) = TYPE_FLAG_STUB
;
325 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
326 TYPE_LENGTH (mtype
) = 1;
330 /* Create a range type using either a blank type supplied in RESULT_TYPE,
331 or creating a new type, inheriting the objfile from INDEX_TYPE.
333 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
334 HIGH_BOUND, inclusive.
336 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
337 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
340 create_range_type (result_type
, index_type
, low_bound
, high_bound
)
341 struct type
*result_type
;
342 struct type
*index_type
;
346 if (result_type
== NULL
)
348 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
350 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
351 TYPE_TARGET_TYPE (result_type
) = index_type
;
352 if (TYPE_FLAGS (index_type
) & TYPE_FLAG_STUB
)
353 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
355 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
356 TYPE_NFIELDS (result_type
) = 2;
357 TYPE_FIELDS (result_type
) = (struct field
*)
358 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
359 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
360 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
361 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
362 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
363 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
366 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
368 return (result_type
);
371 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
372 Return 1 of type is a range type, 0 if it is discrete (and bounds
373 will fit in LONGEST), or -1 otherwise. */
376 get_discrete_bounds (type
, lowp
, highp
)
378 LONGEST
*lowp
, *highp
;
380 CHECK_TYPEDEF (type
);
381 switch (TYPE_CODE (type
))
383 case TYPE_CODE_RANGE
:
384 *lowp
= TYPE_LOW_BOUND (type
);
385 *highp
= TYPE_HIGH_BOUND (type
);
388 if (TYPE_NFIELDS (type
) > 0)
390 /* The enums may not be sorted by value, so search all
394 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
395 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
397 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
398 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
399 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
400 *highp
= TYPE_FIELD_BITPOS (type
, i
);
403 /* Set unsigned indicator if warranted. */
406 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
420 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
422 if (!TYPE_UNSIGNED (type
))
424 *lowp
= - (1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
428 /* ... fall through for unsigned ints ... */
431 /* This round-about calculation is to avoid shifting by
432 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
433 if TYPE_LENGTH (type) == sizeof (LONGEST). */
434 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
435 *highp
= (*highp
- 1) | *highp
;
442 /* Create an array type using either a blank type supplied in RESULT_TYPE,
443 or creating a new type, inheriting the objfile from RANGE_TYPE.
445 Elements will be of type ELEMENT_TYPE, the indices will be of type
448 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
449 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
452 create_array_type (result_type
, element_type
, range_type
)
453 struct type
*result_type
;
454 struct type
*element_type
;
455 struct type
*range_type
;
457 LONGEST low_bound
, high_bound
;
459 if (result_type
== NULL
)
461 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
463 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
464 TYPE_TARGET_TYPE (result_type
) = element_type
;
465 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
466 low_bound
= high_bound
= 0;
467 CHECK_TYPEDEF (element_type
);
468 TYPE_LENGTH (result_type
) =
469 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
470 TYPE_NFIELDS (result_type
) = 1;
471 TYPE_FIELDS (result_type
) =
472 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
473 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
474 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
475 TYPE_VPTR_FIELDNO (result_type
) = -1;
477 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
478 if (TYPE_LENGTH (result_type
) == 0)
479 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
481 return (result_type
);
484 /* Create a string type using either a blank type supplied in RESULT_TYPE,
485 or creating a new type. String types are similar enough to array of
486 char types that we can use create_array_type to build the basic type
487 and then bash it into a string type.
489 For fixed length strings, the range type contains 0 as the lower
490 bound and the length of the string minus one as the upper bound.
492 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
493 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
496 create_string_type (result_type
, range_type
)
497 struct type
*result_type
;
498 struct type
*range_type
;
500 result_type
= create_array_type (result_type
,
501 *current_language
->string_char_type
,
503 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
504 return (result_type
);
508 create_set_type (result_type
, domain_type
)
509 struct type
*result_type
;
510 struct type
*domain_type
;
512 LONGEST low_bound
, high_bound
, bit_length
;
513 if (result_type
== NULL
)
515 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
517 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
518 TYPE_NFIELDS (result_type
) = 1;
519 TYPE_FIELDS (result_type
) = (struct field
*)
520 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
521 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
523 if (! (TYPE_FLAGS (domain_type
) & TYPE_FLAG_STUB
))
525 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
526 low_bound
= high_bound
= 0;
527 bit_length
= high_bound
- low_bound
+ 1;
528 TYPE_LENGTH (result_type
)
529 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
531 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
534 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
536 return (result_type
);
539 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
540 A MEMBER is a wierd thing -- it amounts to a typed offset into
541 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
542 include the offset (that's the value of the MEMBER itself), but does
543 include the structure type into which it points (for some reason).
545 When "smashing" the type, we preserve the objfile that the
546 old type pointed to, since we aren't changing where the type is actually
550 smash_to_member_type (type
, domain
, to_type
)
553 struct type
*to_type
;
555 struct objfile
*objfile
;
557 objfile
= TYPE_OBJFILE (type
);
559 memset ((char *) type
, 0, sizeof (struct type
));
560 TYPE_OBJFILE (type
) = objfile
;
561 TYPE_TARGET_TYPE (type
) = to_type
;
562 TYPE_DOMAIN_TYPE (type
) = domain
;
563 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
564 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
567 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
568 METHOD just means `function that gets an extra "this" argument'.
570 When "smashing" the type, we preserve the objfile that the
571 old type pointed to, since we aren't changing where the type is actually
575 smash_to_method_type (type
, domain
, to_type
, args
)
578 struct type
*to_type
;
581 struct objfile
*objfile
;
583 objfile
= TYPE_OBJFILE (type
);
585 memset ((char *) type
, 0, sizeof (struct type
));
586 TYPE_OBJFILE (type
) = objfile
;
587 TYPE_TARGET_TYPE (type
) = to_type
;
588 TYPE_DOMAIN_TYPE (type
) = domain
;
589 TYPE_ARG_TYPES (type
) = args
;
590 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
591 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
594 /* Return a typename for a struct/union/enum type without "struct ",
595 "union ", or "enum ". If the type has a NULL name, return NULL. */
598 type_name_no_tag (type
)
599 register const struct type
*type
;
601 if (TYPE_TAG_NAME (type
) != NULL
)
602 return TYPE_TAG_NAME (type
);
604 /* Is there code which expects this to return the name if there is no
605 tag name? My guess is that this is mainly used for C++ in cases where
606 the two will always be the same. */
607 return TYPE_NAME (type
);
610 /* Lookup a primitive type named NAME.
611 Return zero if NAME is not a primitive type.*/
614 lookup_primitive_typename (name
)
617 struct type
** const *p
;
619 for (p
= current_language
-> la_builtin_type_vector
; *p
!= NULL
; p
++)
621 if (STREQ ((**p
) -> name
, name
))
629 /* Lookup a typedef or primitive type named NAME,
630 visible in lexical block BLOCK.
631 If NOERR is nonzero, return zero if NAME is not suitably defined. */
634 lookup_typename (name
, block
, noerr
)
639 register struct symbol
*sym
;
640 register struct type
*tmp
;
642 sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
643 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
645 tmp
= lookup_primitive_typename (name
);
650 else if (!tmp
&& noerr
)
656 error ("No type named %s.", name
);
659 return (SYMBOL_TYPE (sym
));
663 lookup_unsigned_typename (name
)
666 char *uns
= alloca (strlen (name
) + 10);
668 strcpy (uns
, "unsigned ");
669 strcpy (uns
+ 9, name
);
670 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
674 lookup_signed_typename (name
)
678 char *uns
= alloca (strlen (name
) + 8);
680 strcpy (uns
, "signed ");
681 strcpy (uns
+ 7, name
);
682 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
683 /* If we don't find "signed FOO" just try again with plain "FOO". */
686 return lookup_typename (name
, (struct block
*) NULL
, 0);
689 /* Lookup a structure type named "struct NAME",
690 visible in lexical block BLOCK. */
693 lookup_struct (name
, block
)
697 register struct symbol
*sym
;
699 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
700 (struct symtab
**) NULL
);
704 error ("No struct type named %s.", name
);
706 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
708 error ("This context has class, union or enum %s, not a struct.", name
);
710 return (SYMBOL_TYPE (sym
));
713 /* Lookup a union type named "union NAME",
714 visible in lexical block BLOCK. */
717 lookup_union (name
, block
)
721 register struct symbol
*sym
;
723 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
724 (struct symtab
**) NULL
);
728 error ("No union type named %s.", name
);
730 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_UNION
)
732 error ("This context has class, struct or enum %s, not a union.", name
);
734 return (SYMBOL_TYPE (sym
));
737 /* Lookup an enum type named "enum NAME",
738 visible in lexical block BLOCK. */
741 lookup_enum (name
, block
)
745 register struct symbol
*sym
;
747 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
748 (struct symtab
**) NULL
);
751 error ("No enum type named %s.", name
);
753 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
755 error ("This context has class, struct or union %s, not an enum.", name
);
757 return (SYMBOL_TYPE (sym
));
760 /* Lookup a template type named "template NAME<TYPE>",
761 visible in lexical block BLOCK. */
764 lookup_template_type (name
, type
, block
)
770 char *nam
= (char*) alloca(strlen(name
) + strlen(type
->name
) + 4);
773 strcat (nam
, type
->name
);
774 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
776 sym
= lookup_symbol (nam
, block
, VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
780 error ("No template type named %s.", name
);
782 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
784 error ("This context has class, union or enum %s, not a struct.", name
);
786 return (SYMBOL_TYPE (sym
));
789 /* Given a type TYPE, lookup the type of the component of type named NAME.
791 TYPE can be either a struct or union, or a pointer or reference to a struct or
792 union. If it is a pointer or reference, its target type is automatically used.
793 Thus '.' and '->' are interchangable, as specified for the definitions of the
794 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
796 If NOERR is nonzero, return zero if NAME is not suitably defined.
797 If NAME is the name of a baseclass type, return that type. */
800 lookup_struct_elt_type (type
, name
, noerr
)
809 CHECK_TYPEDEF (type
);
810 if (TYPE_CODE (type
) != TYPE_CODE_PTR
811 && TYPE_CODE (type
) != TYPE_CODE_REF
)
813 type
= TYPE_TARGET_TYPE (type
);
816 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
817 TYPE_CODE (type
) != TYPE_CODE_UNION
)
819 target_terminal_ours ();
820 gdb_flush (gdb_stdout
);
821 fprintf_unfiltered (gdb_stderr
, "Type ");
822 type_print (type
, "", gdb_stderr
, -1);
823 error (" is not a structure or union type.");
827 /* FIXME: This change put in by Michael seems incorrect for the case where
828 the structure tag name is the same as the member name. I.E. when doing
829 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
834 typename
= type_name_no_tag (type
);
835 if (typename
!= NULL
&& STREQ (typename
, name
))
840 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
842 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
844 if (t_field_name
&& STREQ (t_field_name
, name
))
846 return TYPE_FIELD_TYPE (type
, i
);
850 /* OK, it's not in this class. Recursively check the baseclasses. */
851 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
855 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
867 target_terminal_ours ();
868 gdb_flush (gdb_stdout
);
869 fprintf_unfiltered (gdb_stderr
, "Type ");
870 type_print (type
, "", gdb_stderr
, -1);
871 fprintf_unfiltered (gdb_stderr
, " has no component named ");
872 fputs_filtered (name
, gdb_stderr
);
874 return (struct type
*)-1; /* For lint */
877 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
878 valid. Callers should be aware that in some cases (for example,
879 the type or one of its baseclasses is a stub type and we are
880 debugging a .o file), this function will not be able to find the virtual
881 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
885 fill_in_vptr_fieldno (type
)
888 CHECK_TYPEDEF (type
);
890 if (TYPE_VPTR_FIELDNO (type
) < 0)
894 /* We must start at zero in case the first (and only) baseclass is
895 virtual (and hence we cannot share the table pointer). */
896 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
898 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
899 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
901 TYPE_VPTR_FIELDNO (type
)
902 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
903 TYPE_VPTR_BASETYPE (type
)
904 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
911 /* Find the method and field indices for the destructor in class type T.
912 Return 1 if the destructor was found, otherwise, return 0. */
915 get_destructor_fn_field (t
, method_indexp
, field_indexp
)
922 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
925 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
927 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
929 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f
, j
)))
940 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
942 If this is a stubbed struct (i.e. declared as struct foo *), see if
943 we can find a full definition in some other file. If so, copy this
944 definition, so we can use it in future. There used to be a comment (but
945 not any code) that if we don't find a full definition, we'd set a flag
946 so we don't spend time in the future checking the same type. That would
947 be a mistake, though--we might load in more symbols which contain a
948 full definition for the type.
950 This used to be coded as a macro, but I don't think it is called
951 often enough to merit such treatment. */
953 struct complaint stub_noname_complaint
=
954 {"stub type has NULL name", 0, 0};
958 register struct type
*type
;
960 struct type
*orig_type
= type
;
961 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
963 if (!TYPE_TARGET_TYPE (type
))
968 /* It is dangerous to call lookup_symbol if we are currently
969 reading a symtab. Infinite recursion is one danger. */
970 if (currently_reading_symtab
)
973 name
= type_name_no_tag (type
);
974 /* FIXME: shouldn't we separately check the TYPE_NAME and the
975 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
976 as appropriate? (this code was written before TYPE_NAME and
977 TYPE_TAG_NAME were separate). */
980 complain (&stub_noname_complaint
);
983 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
984 (struct symtab
**) NULL
);
986 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
988 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
990 type
= TYPE_TARGET_TYPE (type
);
993 if ((TYPE_FLAGS(type
) & TYPE_FLAG_STUB
) && ! currently_reading_symtab
)
995 char* name
= type_name_no_tag (type
);
996 /* FIXME: shouldn't we separately check the TYPE_NAME and the
997 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
998 as appropriate? (this code was written before TYPE_NAME and
999 TYPE_TAG_NAME were separate). */
1003 complain (&stub_noname_complaint
);
1006 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
1007 (struct symtab
**) NULL
);
1010 memcpy ((char *)type
,
1011 (char *)SYMBOL_TYPE(sym
),
1012 sizeof (struct type
));
1016 if (TYPE_FLAGS (type
) & TYPE_FLAG_TARGET_STUB
)
1018 struct type
*range_type
;
1019 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1021 if (TYPE_FLAGS (target_type
) & (TYPE_FLAG_STUB
| TYPE_FLAG_TARGET_STUB
))
1023 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1024 && TYPE_NFIELDS (type
) == 1
1025 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1026 == TYPE_CODE_RANGE
))
1028 /* Now recompute the length of the array type, based on its
1029 number of elements and the target type's length. */
1030 TYPE_LENGTH (type
) =
1031 ((TYPE_FIELD_BITPOS (range_type
, 1)
1032 - TYPE_FIELD_BITPOS (range_type
, 0)
1034 * TYPE_LENGTH (target_type
));
1035 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1037 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1039 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1040 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1043 /* Cache TYPE_LENGTH for future use. */
1044 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1048 /* New code added to support parsing of Cfront stabs strings */
1050 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1051 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1055 struct extra
* pextras
;
1060 if ((nlen
= (n
? strlen(n
) : 0))==0)
1062 sprintf(pextras
->str
+pextras
->len
,"%d%s",nlen
,n
);
1063 pextras
->len
=strlen(pextras
->str
);
1067 add_mangled_type(pextras
,t
)
1068 struct extra
* pextras
;
1071 enum type_code tcode
;
1075 tcode
= TYPE_CODE(t
);
1076 tlen
= TYPE_LENGTH(t
);
1077 tflags
= TYPE_FLAGS(t
);
1078 tname
= TYPE_NAME(t
);
1079 /* args of "..." seem to get mangled as "e" */
1097 if ((pname
=strrchr(tname
,'l'),pname
) && !strcmp(pname
,"long"))
1106 static struct complaint msg
= {"Bad int type code length x%x\n",0,0};
1108 complain (&msg
, tlen
);
1127 static struct complaint msg
= {"Bad float type code length x%x\n",0,0};
1128 complain (&msg
, tlen
);
1134 /* followed by what it's a ref to */
1138 /* followed by what it's a ptr to */
1140 case TYPE_CODE_TYPEDEF
:
1142 static struct complaint msg
= {"Typedefs in overloaded functions not yet supported\n",0,0};
1145 /* followed by type bytes & name */
1147 case TYPE_CODE_FUNC
:
1149 /* followed by func's arg '_' & ret types */
1151 case TYPE_CODE_VOID
:
1154 case TYPE_CODE_METHOD
:
1156 /* followed by name of class and func's arg '_' & ret types */
1157 add_name(pextras
,tname
);
1158 ADD_EXTRA('F'); /* then mangle function */
1160 case TYPE_CODE_STRUCT
: /* C struct */
1161 case TYPE_CODE_UNION
: /* C union */
1162 case TYPE_CODE_ENUM
: /* Enumeration type */
1163 /* followed by name of type */
1164 add_name(pextras
,tname
);
1167 /* errors possible types/not supported */
1168 case TYPE_CODE_CHAR
:
1169 case TYPE_CODE_ARRAY
: /* Array type */
1170 case TYPE_CODE_MEMBER
: /* Member type */
1171 case TYPE_CODE_BOOL
:
1172 case TYPE_CODE_COMPLEX
: /* Complex float */
1173 case TYPE_CODE_UNDEF
:
1174 case TYPE_CODE_SET
: /* Pascal sets */
1175 case TYPE_CODE_RANGE
:
1176 case TYPE_CODE_STRING
:
1177 case TYPE_CODE_BITSTRING
:
1178 case TYPE_CODE_ERROR
:
1181 static struct complaint msg
= {"Unknown type code x%x\n",0,0};
1182 complain (&msg
, tcode
);
1186 add_mangled_type(pextras
,t
->target_type
);
1191 cfront_mangle_name(type
, i
, j
)
1197 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1199 f
= TYPE_FN_FIELDLIST1 (type
, i
); /* moved from below */
1201 /* kludge to support cfront methods - gdb expects to find "F" for
1202 ARM_mangled names, so when we mangle, we have to add it here */
1206 char * arm_mangled_name
;
1207 struct fn_field
*method
= &f
[j
];
1208 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1209 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1210 char *newname
= type_name_no_tag (type
);
1212 struct type
*ftype
= TYPE_FN_FIELD_TYPE (f
, j
);
1213 int nargs
= TYPE_NFIELDS(ftype
); /* number of args */
1214 struct extra extras
, * pextras
= &extras
;
1217 if (TYPE_FN_FIELD_STATIC_P (f
, j
)) /* j for sublist within this list */
1220 /* add args here! */
1221 if (nargs
<= 1) /* no args besides this */
1224 for (k
=1; k
<nargs
; k
++)
1227 t
= TYPE_FIELD_TYPE(ftype
,k
);
1228 add_mangled_type(pextras
,t
);
1232 printf("add_mangled_type: %s\n",extras
.str
); /* FIXME */
1233 arm_mangled_name
= malloc(strlen(mangled_name
)+extras
.len
);
1234 sprintf(arm_mangled_name
,"%s%s",mangled_name
,extras
.str
);
1236 mangled_name
= arm_mangled_name
;
1242 /* End of new code added to support parsing of Cfront stabs strings */
1244 /* Ugly hack to convert method stubs into method types.
1246 He ain't kiddin'. This demangles the name of the method into a string
1247 including argument types, parses out each argument type, generates
1248 a string casting a zero to that type, evaluates the string, and stuffs
1249 the resulting type into an argtype vector!!! Then it knows the type
1250 of the whole function (including argument types for overloading),
1251 which info used to be in the stab's but was removed to hack back
1252 the space required for them. */
1255 check_stub_method (type
, method_id
, signature_id
)
1261 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1262 char *demangled_name
= cplus_demangle (mangled_name
,
1263 DMGL_PARAMS
| DMGL_ANSI
);
1264 char *argtypetext
, *p
;
1265 int depth
= 0, argcount
= 1;
1266 struct type
**argtypes
;
1269 /* Make sure we got back a function string that we can use. */
1271 p
= strchr (demangled_name
, '(');
1273 if (demangled_name
== NULL
|| p
== NULL
)
1274 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
1276 /* Now, read in the parameters that define this type. */
1289 else if (*p
== ',' && depth
== 0)
1297 /* We need two more slots: one for the THIS pointer, and one for the
1298 NULL [...] or void [end of arglist]. */
1300 argtypes
= (struct type
**)
1301 TYPE_ALLOC (type
, (argcount
+ 2) * sizeof (struct type
*));
1303 /* FIXME: This is wrong for static member functions. */
1304 argtypes
[0] = lookup_pointer_type (type
);
1307 if (*p
!= ')') /* () means no args, skip while */
1312 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1314 /* Avoid parsing of ellipsis, they will be handled below. */
1315 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0)
1317 argtypes
[argcount
] =
1318 parse_and_eval_type (argtypetext
, p
- argtypetext
);
1321 argtypetext
= p
+ 1;
1337 if (p
[-2] != '.') /* Not '...' */
1339 argtypes
[argcount
] = builtin_type_void
; /* List terminator */
1343 argtypes
[argcount
] = NULL
; /* Ellist terminator */
1346 free (demangled_name
);
1348 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1350 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1352 /* Now update the old "stub" type into a real type. */
1353 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1354 TYPE_DOMAIN_TYPE (mtype
) = type
;
1355 TYPE_ARG_TYPES (mtype
) = argtypes
;
1356 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1357 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1360 const struct cplus_struct_type cplus_struct_default
;
1363 allocate_cplus_struct_type (type
)
1366 if (!HAVE_CPLUS_STRUCT (type
))
1368 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1369 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1370 *(TYPE_CPLUS_SPECIFIC(type
)) = cplus_struct_default
;
1374 /* Helper function to initialize the standard scalar types.
1376 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1377 of the string pointed to by name in the type_obstack for that objfile,
1378 and initialize the type name to that copy. There are places (mipsread.c
1379 in particular, where init_type is called with a NULL value for NAME). */
1382 init_type (code
, length
, flags
, name
, objfile
)
1383 enum type_code code
;
1387 struct objfile
*objfile
;
1389 register struct type
*type
;
1391 type
= alloc_type (objfile
);
1392 TYPE_CODE (type
) = code
;
1393 TYPE_LENGTH (type
) = length
;
1394 TYPE_FLAGS (type
) |= flags
;
1395 if ((name
!= NULL
) && (objfile
!= NULL
))
1398 obsavestring (name
, strlen (name
), &objfile
-> type_obstack
);
1402 TYPE_NAME (type
) = name
;
1407 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1409 INIT_CPLUS_SPECIFIC (type
);
1414 /* Look up a fundamental type for the specified objfile.
1415 May need to construct such a type if this is the first use.
1417 Some object file formats (ELF, COFF, etc) do not define fundamental
1418 types such as "int" or "double". Others (stabs for example), do
1419 define fundamental types.
1421 For the formats which don't provide fundamental types, gdb can create
1422 such types, using defaults reasonable for the current language and
1423 the current target machine.
1425 NOTE: This routine is obsolescent. Each debugging format reader
1426 should manage it's own fundamental types, either creating them from
1427 suitable defaults or reading them from the debugging information,
1428 whichever is appropriate. The DWARF reader has already been
1429 fixed to do this. Once the other readers are fixed, this routine
1430 will go away. Also note that fundamental types should be managed
1431 on a compilation unit basis in a multi-language environment, not
1432 on a linkage unit basis as is done here. */
1436 lookup_fundamental_type (objfile
, typeid)
1437 struct objfile
*objfile
;
1440 register struct type
**typep
;
1441 register int nbytes
;
1443 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1445 error ("internal error - invalid fundamental type id %d", typeid);
1448 /* If this is the first time we need a fundamental type for this objfile
1449 then we need to initialize the vector of type pointers. */
1451 if (objfile
-> fundamental_types
== NULL
)
1453 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1454 objfile
-> fundamental_types
= (struct type
**)
1455 obstack_alloc (&objfile
-> type_obstack
, nbytes
);
1456 memset ((char *) objfile
-> fundamental_types
, 0, nbytes
);
1457 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1460 /* Look for this particular type in the fundamental type vector. If one is
1461 not found, create and install one appropriate for the current language. */
1463 typep
= objfile
-> fundamental_types
+ typeid;
1466 *typep
= create_fundamental_type (objfile
, typeid);
1476 /* FIXME: Should we return true for references as well as pointers? */
1480 && TYPE_CODE (t
) == TYPE_CODE_PTR
1481 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1484 /* Chill varying string and arrays are represented as follows:
1486 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1488 Return true if TYPE is such a Chill varying type. */
1491 chill_varying_type (type
)
1494 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1495 || TYPE_NFIELDS (type
) != 2
1496 || strcmp (TYPE_FIELD_NAME (type
, 0), "__var_length") != 0)
1501 #if MAINTENANCE_CMDS
1504 print_bit_vector (bits
, nbits
)
1510 for (bitno
= 0; bitno
< nbits
; bitno
++)
1512 if ((bitno
% 8) == 0)
1514 puts_filtered (" ");
1516 if (B_TST (bits
, bitno
))
1518 printf_filtered ("1");
1522 printf_filtered ("0");
1527 /* The args list is a strange beast. It is either terminated by a NULL
1528 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
1529 type for normal fixed argcount functions. (FIXME someday)
1530 Also note the first arg should be the "this" pointer, we may not want to
1531 include it since we may get into a infinitely recursive situation. */
1534 print_arg_types (args
, spaces
)
1540 while (*args
!= NULL
)
1542 recursive_dump_type (*args
, spaces
+ 2);
1543 if ((*args
++) -> code
== TYPE_CODE_VOID
)
1552 dump_fn_fieldlists (type
, spaces
)
1560 printfi_filtered (spaces
, "fn_fieldlists ");
1561 gdb_print_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
1562 printf_filtered ("\n");
1563 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
1565 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
1566 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
1568 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
1569 gdb_print_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
1571 printf_filtered (") length %d\n",
1572 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
1573 for (overload_idx
= 0;
1574 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
1577 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
1579 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
1580 gdb_print_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
1582 printf_filtered (")\n");
1583 printfi_filtered (spaces
+ 8, "type ");
1584 gdb_print_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
1585 printf_filtered ("\n");
1587 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
1590 printfi_filtered (spaces
+ 8, "args ");
1591 gdb_print_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
1592 printf_filtered ("\n");
1594 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
), spaces
);
1595 printfi_filtered (spaces
+ 8, "fcontext ");
1596 gdb_print_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
1598 printf_filtered ("\n");
1600 printfi_filtered (spaces
+ 8, "is_const %d\n",
1601 TYPE_FN_FIELD_CONST (f
, overload_idx
));
1602 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
1603 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
1604 printfi_filtered (spaces
+ 8, "is_private %d\n",
1605 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
1606 printfi_filtered (spaces
+ 8, "is_protected %d\n",
1607 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
1608 printfi_filtered (spaces
+ 8, "is_stub %d\n",
1609 TYPE_FN_FIELD_STUB (f
, overload_idx
));
1610 printfi_filtered (spaces
+ 8, "voffset %u\n",
1611 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
1617 print_cplus_stuff (type
, spaces
)
1621 printfi_filtered (spaces
, "n_baseclasses %d\n",
1622 TYPE_N_BASECLASSES (type
));
1623 printfi_filtered (spaces
, "nfn_fields %d\n",
1624 TYPE_NFN_FIELDS (type
));
1625 printfi_filtered (spaces
, "nfn_fields_total %d\n",
1626 TYPE_NFN_FIELDS_TOTAL (type
));
1627 if (TYPE_N_BASECLASSES (type
) > 0)
1629 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
1630 TYPE_N_BASECLASSES (type
));
1631 gdb_print_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
1632 printf_filtered (")");
1634 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
1635 TYPE_N_BASECLASSES (type
));
1636 puts_filtered ("\n");
1638 if (TYPE_NFIELDS (type
) > 0)
1640 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
1642 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
1643 TYPE_NFIELDS (type
));
1644 gdb_print_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
1645 printf_filtered (")");
1646 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
1647 TYPE_NFIELDS (type
));
1648 puts_filtered ("\n");
1650 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
1652 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
1653 TYPE_NFIELDS (type
));
1654 gdb_print_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
1655 printf_filtered (")");
1656 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
1657 TYPE_NFIELDS (type
));
1658 puts_filtered ("\n");
1661 if (TYPE_NFN_FIELDS (type
) > 0)
1663 dump_fn_fieldlists (type
, spaces
);
1667 static struct obstack dont_print_type_obstack
;
1670 recursive_dump_type (type
, spaces
)
1677 obstack_begin (&dont_print_type_obstack
, 0);
1679 if (TYPE_NFIELDS (type
) > 0
1680 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
1682 struct type
**first_dont_print
1683 = (struct type
**)obstack_base (&dont_print_type_obstack
);
1685 int i
= (struct type
**)obstack_next_free (&dont_print_type_obstack
)
1690 if (type
== first_dont_print
[i
])
1692 printfi_filtered (spaces
, "type node ");
1693 gdb_print_address (type
, gdb_stdout
);
1694 printf_filtered (" <same as already seen type>\n");
1699 obstack_ptr_grow (&dont_print_type_obstack
, type
);
1702 printfi_filtered (spaces
, "type node ");
1703 gdb_print_address (type
, gdb_stdout
);
1704 printf_filtered ("\n");
1705 printfi_filtered (spaces
, "name '%s' (",
1706 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
1707 gdb_print_address (TYPE_NAME (type
), gdb_stdout
);
1708 printf_filtered (")\n");
1709 if (TYPE_TAG_NAME (type
) != NULL
)
1711 printfi_filtered (spaces
, "tagname '%s' (",
1712 TYPE_TAG_NAME (type
));
1713 gdb_print_address (TYPE_TAG_NAME (type
), gdb_stdout
);
1714 printf_filtered (")\n");
1716 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
1717 switch (TYPE_CODE (type
))
1719 case TYPE_CODE_UNDEF
:
1720 printf_filtered ("(TYPE_CODE_UNDEF)");
1723 printf_filtered ("(TYPE_CODE_PTR)");
1725 case TYPE_CODE_ARRAY
:
1726 printf_filtered ("(TYPE_CODE_ARRAY)");
1728 case TYPE_CODE_STRUCT
:
1729 printf_filtered ("(TYPE_CODE_STRUCT)");
1731 case TYPE_CODE_UNION
:
1732 printf_filtered ("(TYPE_CODE_UNION)");
1734 case TYPE_CODE_ENUM
:
1735 printf_filtered ("(TYPE_CODE_ENUM)");
1737 case TYPE_CODE_FUNC
:
1738 printf_filtered ("(TYPE_CODE_FUNC)");
1741 printf_filtered ("(TYPE_CODE_INT)");
1744 printf_filtered ("(TYPE_CODE_FLT)");
1746 case TYPE_CODE_VOID
:
1747 printf_filtered ("(TYPE_CODE_VOID)");
1750 printf_filtered ("(TYPE_CODE_SET)");
1752 case TYPE_CODE_RANGE
:
1753 printf_filtered ("(TYPE_CODE_RANGE)");
1755 case TYPE_CODE_STRING
:
1756 printf_filtered ("(TYPE_CODE_STRING)");
1758 case TYPE_CODE_ERROR
:
1759 printf_filtered ("(TYPE_CODE_ERROR)");
1761 case TYPE_CODE_MEMBER
:
1762 printf_filtered ("(TYPE_CODE_MEMBER)");
1764 case TYPE_CODE_METHOD
:
1765 printf_filtered ("(TYPE_CODE_METHOD)");
1768 printf_filtered ("(TYPE_CODE_REF)");
1770 case TYPE_CODE_CHAR
:
1771 printf_filtered ("(TYPE_CODE_CHAR)");
1773 case TYPE_CODE_BOOL
:
1774 printf_filtered ("(TYPE_CODE_BOOL)");
1776 case TYPE_CODE_TYPEDEF
:
1777 printf_filtered ("(TYPE_CODE_TYPEDEF)");
1780 printf_filtered ("(UNKNOWN TYPE CODE)");
1783 puts_filtered ("\n");
1784 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
1785 printfi_filtered (spaces
, "objfile ");
1786 gdb_print_address (TYPE_OBJFILE (type
), gdb_stdout
);
1787 printf_filtered ("\n");
1788 printfi_filtered (spaces
, "target_type ");
1789 gdb_print_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
1790 printf_filtered ("\n");
1791 if (TYPE_TARGET_TYPE (type
) != NULL
)
1793 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
1795 printfi_filtered (spaces
, "pointer_type ");
1796 gdb_print_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
1797 printf_filtered ("\n");
1798 printfi_filtered (spaces
, "reference_type ");
1799 gdb_print_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
1800 printf_filtered ("\n");
1801 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
1802 if (TYPE_FLAGS (type
) & TYPE_FLAG_UNSIGNED
)
1804 puts_filtered (" TYPE_FLAG_UNSIGNED");
1806 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1808 puts_filtered (" TYPE_FLAG_STUB");
1810 puts_filtered ("\n");
1811 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
1812 gdb_print_address (TYPE_FIELDS (type
), gdb_stdout
);
1813 puts_filtered ("\n");
1814 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
1816 printfi_filtered (spaces
+ 2,
1817 "[%d] bitpos %d bitsize %d type ",
1818 idx
, TYPE_FIELD_BITPOS (type
, idx
),
1819 TYPE_FIELD_BITSIZE (type
, idx
));
1820 gdb_print_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
1821 printf_filtered (" name '%s' (",
1822 TYPE_FIELD_NAME (type
, idx
) != NULL
1823 ? TYPE_FIELD_NAME (type
, idx
)
1825 gdb_print_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
1826 printf_filtered (")\n");
1827 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
1829 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
1832 printfi_filtered (spaces
, "vptr_basetype ");
1833 gdb_print_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
1834 puts_filtered ("\n");
1835 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
1837 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
1839 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
1840 switch (TYPE_CODE (type
))
1842 case TYPE_CODE_METHOD
:
1843 case TYPE_CODE_FUNC
:
1844 printfi_filtered (spaces
, "arg_types ");
1845 gdb_print_address (TYPE_ARG_TYPES (type
), gdb_stdout
);
1846 puts_filtered ("\n");
1847 print_arg_types (TYPE_ARG_TYPES (type
), spaces
);
1850 case TYPE_CODE_STRUCT
:
1851 printfi_filtered (spaces
, "cplus_stuff ");
1852 gdb_print_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
1853 puts_filtered ("\n");
1854 print_cplus_stuff (type
, spaces
);
1858 /* We have to pick one of the union types to be able print and test
1859 the value. Pick cplus_struct_type, even though we know it isn't
1860 any particular one. */
1861 printfi_filtered (spaces
, "type_specific ");
1862 gdb_print_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
1863 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
1865 printf_filtered (" (unknown data form)");
1867 printf_filtered ("\n");
1872 obstack_free (&dont_print_type_obstack
, NULL
);
1875 #endif /* MAINTENANCE_CMDS */
1878 static void build_gdbtypes
PARAMS ((void));
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 */
2001 extern void _initialize_gdbtypes
PARAMS ((void));
2003 _initialize_gdbtypes ()
2006 /* start-sanitize-carp start-sanitize-vr4xxx */
2007 /* FIXME - For the moment, handle types by swapping them in and out.
2008 Should be using the per-architecture data-pointer and a large
2010 register_gdbarch_swap (&builtin_type_void
, sizeof (struct type
*), NULL
);
2011 register_gdbarch_swap (&builtin_type_char
, sizeof (struct type
*), NULL
);
2012 register_gdbarch_swap (&builtin_type_short
, sizeof (struct type
*), NULL
);
2013 register_gdbarch_swap (&builtin_type_int
, sizeof (struct type
*), NULL
);
2014 register_gdbarch_swap (&builtin_type_long
, sizeof (struct type
*), NULL
);
2015 register_gdbarch_swap (&builtin_type_long_long
, sizeof (struct type
*), NULL
);
2016 register_gdbarch_swap (&builtin_type_signed_char
, sizeof (struct type
*), NULL
);
2017 register_gdbarch_swap (&builtin_type_unsigned_char
, sizeof (struct type
*), NULL
);
2018 register_gdbarch_swap (&builtin_type_unsigned_short
, sizeof (struct type
*), NULL
);
2019 register_gdbarch_swap (&builtin_type_unsigned_int
, sizeof (struct type
*), NULL
);
2020 register_gdbarch_swap (&builtin_type_unsigned_long
, sizeof (struct type
*), NULL
);
2021 register_gdbarch_swap (&builtin_type_unsigned_long_long
, sizeof (struct type
*), NULL
);
2022 register_gdbarch_swap (&builtin_type_float
, sizeof (struct type
*), NULL
);
2023 register_gdbarch_swap (&builtin_type_double
, sizeof (struct type
*), NULL
);
2024 register_gdbarch_swap (&builtin_type_long_double
, sizeof (struct type
*), NULL
);
2025 register_gdbarch_swap (&builtin_type_complex
, sizeof (struct type
*), NULL
);
2026 register_gdbarch_swap (&builtin_type_double_complex
, sizeof (struct type
*), NULL
);
2027 register_gdbarch_swap (&builtin_type_string
, sizeof (struct type
*), NULL
);
2028 register_gdbarch_swap (&builtin_type_int8
, sizeof (struct type
*), NULL
);
2029 register_gdbarch_swap (&builtin_type_uint8
, sizeof (struct type
*), NULL
);
2030 register_gdbarch_swap (&builtin_type_int16
, sizeof (struct type
*), NULL
);
2031 register_gdbarch_swap (&builtin_type_uint16
, sizeof (struct type
*), NULL
);
2032 register_gdbarch_swap (&builtin_type_int32
, sizeof (struct type
*), NULL
);
2033 register_gdbarch_swap (&builtin_type_uint32
, sizeof (struct type
*), NULL
);
2034 register_gdbarch_swap (&builtin_type_int64
, sizeof (struct type
*), NULL
);
2035 register_gdbarch_swap (&builtin_type_uint64
, sizeof (struct type
*), NULL
);
2036 /* start-sanitize-r5900 */
2037 register_gdbarch_swap (&builtin_type_int128
, sizeof (struct type
*), NULL
);
2038 register_gdbarch_swap (&builtin_type_uint128
, sizeof (struct type
*), NULL
);
2039 /* end-sanitize-r5900 */
2040 register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
2041 /* end-sanitize-carp end-sanitize-vr4xxx */