1 /* Support routines for manipulating internal types for GDB.
2 Copyright (C) 1992 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #include "expression.h"
34 /* Alloc a new type structure and fill it with some defaults. If
35 OBJFILE is non-NULL, then allocate the space for the type structure
36 in that objfile's type_obstack. */
40 struct objfile
*objfile
;
42 register struct type
*type
;
44 /* Alloc the structure and start off with all fields zeroed. */
48 type
= (struct type
*) xmalloc (sizeof (struct type
));
52 type
= (struct type
*) obstack_alloc (&objfile
-> type_obstack
,
53 sizeof (struct type
));
55 memset ((char *) type
, 0, sizeof (struct type
));
57 /* Initialize the fields that might not be zero. */
59 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
60 TYPE_OBJFILE (type
) = objfile
;
61 TYPE_VPTR_FIELDNO (type
) = -1;
66 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
67 to a pointer to memory where the pointer type should be stored.
68 If *TYPEPTR is zero, update it to point to the pointer type we return.
69 We allocate new memory if needed. */
72 make_pointer_type (type
, typeptr
)
74 struct type
**typeptr
;
76 register struct type
*ntype
; /* New type */
77 struct objfile
*objfile
;
79 ntype
= TYPE_POINTER_TYPE (type
);
83 return ntype
; /* Don't care about alloc, and have new type. */
84 else if (*typeptr
== 0)
86 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
90 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
92 ntype
= alloc_type (TYPE_OBJFILE (type
));
96 else /* We have storage, but need to reset it. */
99 objfile
= TYPE_OBJFILE (ntype
);
100 memset ((char *) ntype
, 0, sizeof (struct type
));
101 TYPE_OBJFILE (ntype
) = objfile
;
104 TYPE_TARGET_TYPE (ntype
) = type
;
105 TYPE_POINTER_TYPE (type
) = ntype
;
107 /* FIXME! Assume the machine has only one representation for pointers! */
109 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
110 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
112 /* pointers are unsigned */
113 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
115 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
116 TYPE_POINTER_TYPE (type
) = ntype
;
121 /* Given a type TYPE, return a type of pointers to that type.
122 May need to construct such a type if this is the first use. */
125 lookup_pointer_type (type
)
128 return make_pointer_type (type
, (struct type
**)0);
131 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
132 to a pointer to memory where the reference type should be stored.
133 If *TYPEPTR is zero, update it to point to the reference type we return.
134 We allocate new memory if needed. */
137 make_reference_type (type
, typeptr
)
139 struct type
**typeptr
;
141 register struct type
*ntype
; /* New type */
142 struct objfile
*objfile
;
144 ntype
= TYPE_REFERENCE_TYPE (type
);
148 return ntype
; /* Don't care about alloc, and have new type. */
149 else if (*typeptr
== 0)
151 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
155 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
157 ntype
= alloc_type (TYPE_OBJFILE (type
));
161 else /* We have storage, but need to reset it. */
164 objfile
= TYPE_OBJFILE (ntype
);
165 memset ((char *) ntype
, 0, sizeof (struct type
));
166 TYPE_OBJFILE (ntype
) = objfile
;
169 TYPE_TARGET_TYPE (ntype
) = type
;
170 TYPE_REFERENCE_TYPE (type
) = ntype
;
172 /* FIXME! Assume the machine has only one representation for references,
173 and that it matches the (only) representation for pointers! */
175 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
176 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
178 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
179 TYPE_REFERENCE_TYPE (type
) = ntype
;
184 /* Same as above, but caller doesn't care about memory allocation details. */
187 lookup_reference_type (type
)
190 return make_reference_type (type
, (struct type
**)0);
193 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
194 to a pointer to memory where the function type should be stored.
195 If *TYPEPTR is zero, update it to point to the function type we return.
196 We allocate new memory if needed. */
199 make_function_type (type
, typeptr
)
201 struct type
**typeptr
;
203 register struct type
*ntype
; /* New type */
204 struct objfile
*objfile
;
206 ntype
= TYPE_FUNCTION_TYPE (type
);
210 return ntype
; /* Don't care about alloc, and have new type. */
211 else if (*typeptr
== 0)
213 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
217 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
219 ntype
= alloc_type (TYPE_OBJFILE (type
));
223 else /* We have storage, but need to reset it. */
226 objfile
= TYPE_OBJFILE (ntype
);
227 memset ((char *) ntype
, 0, sizeof (struct type
));
228 TYPE_OBJFILE (ntype
) = objfile
;
231 TYPE_TARGET_TYPE (ntype
) = type
;
232 TYPE_FUNCTION_TYPE (type
) = ntype
;
234 TYPE_LENGTH (ntype
) = 1;
235 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
237 if (!TYPE_FUNCTION_TYPE (type
)) /* Remember it, if don't have one. */
238 TYPE_FUNCTION_TYPE (type
) = ntype
;
244 /* Given a type TYPE, return a type of functions that return that type.
245 May need to construct such a type if this is the first use. */
248 lookup_function_type (type
)
251 return make_function_type (type
, (struct type
**)0);
254 /* Implement direct support for MEMBER_TYPE in GNU C++.
255 May need to construct such a type if this is the first use.
256 The TYPE is the type of the member. The DOMAIN is the type
257 of the aggregate that the member belongs to. */
260 lookup_member_type (type
, domain
)
264 register struct type
*mtype
;
266 mtype
= alloc_type (TYPE_OBJFILE (type
));
267 smash_to_member_type (mtype
, domain
, type
);
271 /* Allocate a stub method whose return type is TYPE.
272 This apparently happens for speed of symbol reading, since parsing
273 out the arguments to the method is cpu-intensive, the way we are doing
274 it. So, we will fill in arguments later.
275 This always returns a fresh type. */
278 allocate_stub_method (type
)
283 mtype
= alloc_type (TYPE_OBJFILE (type
));
284 TYPE_TARGET_TYPE (mtype
) = type
;
285 /* _DOMAIN_TYPE (mtype) = unknown yet */
286 /* _ARG_TYPES (mtype) = unknown yet */
287 TYPE_FLAGS (mtype
) = TYPE_FLAG_STUB
;
288 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
289 TYPE_LENGTH (mtype
) = 1;
293 /* Create an array type. Elements will be of type TYPE, and there will
296 Eventually this should be extended to take two more arguments which
297 specify the bounds of the array and the type of the index.
298 It should also be changed to be a "lookup" function, with the
299 appropriate data structures added to the type field.
300 Then read array type should call here. */
303 create_array_type (element_type
, number
)
304 struct type
*element_type
;
307 struct type
*result_type
;
308 struct type
*range_type
;
310 result_type
= alloc_type (TYPE_OBJFILE (element_type
));
312 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
313 TYPE_TARGET_TYPE (result_type
) = element_type
;
314 TYPE_LENGTH (result_type
) = number
* TYPE_LENGTH (element_type
);
315 TYPE_NFIELDS (result_type
) = 1;
316 TYPE_FIELDS (result_type
) = (struct field
*)
317 TYPE_ALLOC (result_type
, sizeof (struct field
));
320 /* Create range type. */
321 range_type
= alloc_type (TYPE_OBJFILE (result_type
));
322 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
323 TYPE_TARGET_TYPE (range_type
) = builtin_type_int
; /* FIXME */
325 /* This should never be needed. */
326 TYPE_LENGTH (range_type
) = sizeof (int);
328 TYPE_NFIELDS (range_type
) = 2;
329 TYPE_FIELDS (range_type
) = (struct field
*)
330 TYPE_ALLOC (range_type
, 2 * sizeof (struct field
));
331 TYPE_FIELD_BITPOS (range_type
, 0) = 0; /* FIXME */
332 TYPE_FIELD_BITPOS (range_type
, 1) = number
-1; /* FIXME */
333 TYPE_FIELD_TYPE (range_type
, 0) = builtin_type_int
; /* FIXME */
334 TYPE_FIELD_TYPE (range_type
, 1) = builtin_type_int
; /* FIXME */
336 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
337 TYPE_VPTR_FIELDNO (result_type
) = -1;
339 return (result_type
);
343 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
344 A MEMBER is a wierd thing -- it amounts to a typed offset into
345 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
346 include the offset (that's the value of the MEMBER itself), but does
347 include the structure type into which it points (for some reason).
349 When "smashing" the type, we preserve the objfile that the
350 old type pointed to, since we aren't changing where the type is actually
354 smash_to_member_type (type
, domain
, to_type
)
357 struct type
*to_type
;
359 struct objfile
*objfile
;
361 objfile
= TYPE_OBJFILE (type
);
363 memset ((char *) type
, 0, sizeof (struct type
));
364 TYPE_OBJFILE (type
) = objfile
;
365 TYPE_TARGET_TYPE (type
) = to_type
;
366 TYPE_DOMAIN_TYPE (type
) = domain
;
367 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
368 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
371 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
372 METHOD just means `function that gets an extra "this" argument'.
374 When "smashing" the type, we preserve the objfile that the
375 old type pointed to, since we aren't changing where the type is actually
379 smash_to_method_type (type
, domain
, to_type
, args
)
382 struct type
*to_type
;
385 struct objfile
*objfile
;
387 objfile
= TYPE_OBJFILE (type
);
389 memset ((char *) type
, 0, sizeof (struct type
));
390 TYPE_OBJFILE (type
) = objfile
;
391 TYPE_TARGET_TYPE (type
) = to_type
;
392 TYPE_DOMAIN_TYPE (type
) = domain
;
393 TYPE_ARG_TYPES (type
) = args
;
394 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
395 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
398 /* Return a typename for a struct/union/enum type
399 without the tag qualifier. If the type has a NULL name,
403 type_name_no_tag (type
)
404 register const struct type
*type
;
408 if ((name
= TYPE_NAME (type
)) != NULL
)
410 switch (TYPE_CODE (type
))
412 case TYPE_CODE_STRUCT
:
413 if(!strncmp (name
, "struct ", 7))
418 case TYPE_CODE_UNION
:
419 if(!strncmp (name
, "union ", 6))
425 if(!strncmp (name
, "enum ", 5))
430 default: /* To avoid -Wall warnings */
437 /* Lookup a primitive type named NAME.
438 Return zero if NAME is not a primitive type.*/
441 lookup_primitive_typename (name
)
444 struct type
** const *p
;
446 for (p
= current_language
-> la_builtin_type_vector
; *p
!= NULL
; p
++)
448 if (!strcmp ((**p
) -> name
, name
))
456 /* Lookup a typedef or primitive type named NAME,
457 visible in lexical block BLOCK.
458 If NOERR is nonzero, return zero if NAME is not suitably defined. */
461 lookup_typename (name
, block
, noerr
)
466 register struct symbol
*sym
;
467 register struct type
*tmp
;
469 sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
470 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
472 tmp
= lookup_primitive_typename (name
);
477 else if (!tmp
&& noerr
)
483 error ("No type named %s.", name
);
486 return (SYMBOL_TYPE (sym
));
490 lookup_unsigned_typename (name
)
493 char *uns
= alloca (strlen (name
) + 10);
495 strcpy (uns
, "unsigned ");
496 strcpy (uns
+ 9, name
);
497 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
501 lookup_signed_typename (name
)
505 char *uns
= alloca (strlen (name
) + 8);
507 strcpy (uns
, "signed ");
508 strcpy (uns
+ 7, name
);
509 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
510 /* If we don't find "signed FOO" just try again with plain "FOO". */
513 return lookup_typename (name
, (struct block
*) NULL
, 0);
520 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
)
521 error ("This context has %s, not a struct or class.", TYPE_NAME (type
));
525 /* Lookup a structure type named "struct NAME",
526 visible in lexical block BLOCK. */
529 lookup_struct (name
, block
)
533 register struct symbol
*sym
;
535 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
536 (struct symtab
**) NULL
);
540 error ("No struct type named %s.", name
);
542 return check_struct (SYMBOL_TYPE (sym
));
549 if (TYPE_CODE (type
) != TYPE_CODE_UNION
)
550 error ("This context has %s, not a union.", TYPE_NAME (type
));
554 /* Lookup a union type named "union NAME",
555 visible in lexical block BLOCK. */
558 lookup_union (name
, block
)
562 register struct symbol
*sym
;
564 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
565 (struct symtab
**) NULL
);
569 error ("No union type named %s.", name
);
571 return check_union (SYMBOL_TYPE (sym
));
578 if (TYPE_CODE (type
) != TYPE_CODE_ENUM
)
579 error ("This context has %s, not an enum.", TYPE_NAME (type
));
583 /* Lookup an enum type named "enum NAME",
584 visible in lexical block BLOCK. */
587 lookup_enum (name
, block
)
591 register struct symbol
*sym
;
593 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
594 (struct symtab
**) NULL
);
597 error ("No enum type named %s.", name
);
599 return check_enum (SYMBOL_TYPE (sym
));
602 /* Lookup a template type named "template NAME<TYPE>",
603 visible in lexical block BLOCK. */
606 lookup_template_type (name
, type
, block
)
612 char *nam
= (char*) alloca(strlen(name
) + strlen(type
->name
) + 4);
615 strcat (nam
, type
->name
);
616 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
618 sym
= lookup_symbol (nam
, block
, VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
622 error ("No template type named %s.", name
);
624 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
626 error ("This context has class, union or enum %s, not a struct.", name
);
628 return (SYMBOL_TYPE (sym
));
631 /* Given a type TYPE, lookup the type of the component of type named
633 If NOERR is nonzero, return zero if NAME is not suitably defined. */
636 lookup_struct_elt_type (type
, name
, noerr
)
643 if (TYPE_CODE (type
) == TYPE_CODE_PTR
||
644 TYPE_CODE (type
) == TYPE_CODE_REF
)
645 type
= TYPE_TARGET_TYPE (type
);
647 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
648 TYPE_CODE (type
) != TYPE_CODE_UNION
)
650 target_terminal_ours ();
652 fprintf (stderr
, "Type ");
653 type_print (type
, "", stderr
, -1);
654 error (" is not a structure or union type.");
657 check_stub_type (type
);
659 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
661 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
663 if (t_field_name
&& !strcmp (t_field_name
, name
))
665 return TYPE_FIELD_TYPE (type
, i
);
669 /* OK, it's not in this class. Recursively check the baseclasses. */
670 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
674 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 0);
686 target_terminal_ours ();
688 fprintf (stderr
, "Type ");
689 type_print (type
, "", stderr
, -1);
690 fprintf (stderr
, " has no component named ");
691 fputs_filtered (name
, stderr
);
693 return (struct type
*)-1; /* For lint */
696 /* This function is really horrible, but to avoid it, there would need
697 to be more filling in of forward references. */
700 fill_in_vptr_fieldno (type
)
703 if (TYPE_VPTR_FIELDNO (type
) < 0)
706 for (i
= 1; i
< TYPE_N_BASECLASSES (type
); i
++)
708 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
709 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
711 TYPE_VPTR_FIELDNO (type
)
712 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
713 TYPE_VPTR_BASETYPE (type
)
714 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
721 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
723 If this is a stubbed struct (i.e. declared as struct foo *), see if
724 we can find a full definition in some other file. If so, copy this
725 definition, so we can use it in future. If not, set a flag so we
726 don't waste too much time in future. (FIXME, this doesn't seem
729 This used to be coded as a macro, but I don't think it is called
730 often enough to merit such treatment.
733 struct complaint stub_noname_complaint
=
734 {"stub type has NULL name", 0, 0};
737 check_stub_type (type
)
740 if (TYPE_FLAGS(type
) & TYPE_FLAG_STUB
)
742 char* name
= type_name_no_tag (type
);
746 complain (&stub_noname_complaint
, 0);
749 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
750 (struct symtab
**) NULL
);
753 memcpy ((char *)type
, (char *)SYMBOL_TYPE(sym
), sizeof (struct type
));
758 /* Ugly hack to convert method stubs into method types.
760 He ain't kiddin'. This demangles the name of the method into a string
761 including argument types, parses out each argument type, generates
762 a string casting a zero to that type, evaluates the string, and stuffs
763 the resulting type into an argtype vector!!! Then it knows the type
764 of the whole function (including argument types for overloading),
765 which info used to be in the stab's but was removed to hack back
766 the space required for them. */
769 check_stub_method (type
, i
, j
)
775 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
776 char *demangled_name
= cplus_demangle (mangled_name
,
777 DMGL_PARAMS
| DMGL_ANSI
);
778 char *argtypetext
, *p
;
779 int depth
= 0, argcount
= 1;
780 struct type
**argtypes
;
783 if (demangled_name
== NULL
)
785 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
788 /* Now, read in the parameters that define this type. */
789 argtypetext
= strchr (demangled_name
, '(') + 1;
801 else if (*p
== ',' && depth
== 0)
809 /* We need two more slots: one for the THIS pointer, and one for the
810 NULL [...] or void [end of arglist]. */
812 argtypes
= (struct type
**)
813 TYPE_ALLOC (type
, (argcount
+ 2) * sizeof (struct type
*));
815 argtypes
[0] = lookup_pointer_type (type
);
818 if (*p
!= ')') /* () means no args, skip while */
823 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
826 parse_and_eval_type (argtypetext
, p
- argtypetext
);
844 if (p
[-2] != '.') /* Not '...' */
846 argtypes
[argcount
] = builtin_type_void
; /* List terminator */
850 argtypes
[argcount
] = NULL
; /* Ellist terminator */
853 free (demangled_name
);
855 f
= TYPE_FN_FIELDLIST1 (type
, i
);
856 TYPE_FN_FIELD_PHYSNAME (f
, j
) = mangled_name
;
858 /* Now update the old "stub" type into a real type. */
859 mtype
= TYPE_FN_FIELD_TYPE (f
, j
);
860 TYPE_DOMAIN_TYPE (mtype
) = type
;
861 TYPE_ARG_TYPES (mtype
) = argtypes
;
862 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
863 TYPE_FN_FIELD_STUB (f
, j
) = 0;
866 const struct cplus_struct_type cplus_struct_default
;
869 allocate_cplus_struct_type (type
)
872 if (!HAVE_CPLUS_STRUCT (type
))
874 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
875 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
876 *(TYPE_CPLUS_SPECIFIC(type
)) = cplus_struct_default
;
880 /* Helper function to initialize the standard scalar types.
882 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
883 of the string pointed to by name in the type_obstack for that objfile,
884 and initialize the type name to that copy. There are places (mipsread.c
885 in particular, where init_type is called with a NULL value for NAME). */
888 init_type (code
, length
, flags
, name
, objfile
)
893 struct objfile
*objfile
;
895 register struct type
*type
;
897 type
= alloc_type (objfile
);
898 TYPE_CODE (type
) = code
;
899 TYPE_LENGTH (type
) = length
;
900 TYPE_FLAGS (type
) |= flags
;
901 if ((name
!= NULL
) && (objfile
!= NULL
))
904 obsavestring (name
, strlen (name
), &objfile
-> type_obstack
);
908 TYPE_NAME (type
) = name
;
913 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
915 INIT_CPLUS_SPECIFIC (type
);
920 /* Look up a fundamental type for the specified objfile.
921 May need to construct such a type if this is the first use.
923 Some object file formats (ELF, COFF, etc) do not define fundamental
924 types such as "int" or "double". Others (stabs for example), do
925 define fundamental types.
927 For the formats which don't provide fundamental types, gdb can create
928 such types, using defaults reasonable for the current target machine.
930 FIXME: Some compilers distinguish explicitly signed integral types
931 (signed short, signed int, signed long) from "regular" integral types
932 (short, int, long) in the debugging information. There is some dis-
933 agreement as to how useful this feature is. In particular, gcc does
934 not support this. Also, only some debugging formats allow the
935 distinction to be passed on to a debugger. For now, we always just
936 use "short", "int", or "long" as the type name, for both the implicit
937 and explicitly signed types. This also makes life easier for the
938 gdb test suite since we don't have to account for the differences
939 in output depending upon what the compiler and debugging format
940 support. We will probably have to re-examine the issue when gdb
941 starts taking it's fundamental type information directly from the
942 debugging information supplied by the compiler. fnf@cygnus.com */
945 lookup_fundamental_type (objfile
, typeid)
946 struct objfile
*objfile
;
949 register struct type
*type
= NULL
;
950 register struct type
**typep
;
953 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
955 error ("internal error - invalid fundamental type id %d", typeid);
959 /* If this is the first time we */
960 if (objfile
-> fundamental_types
== NULL
)
962 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
963 objfile
-> fundamental_types
= (struct type
**)
964 obstack_alloc (&objfile
-> type_obstack
, nbytes
);
965 memset ((char *) objfile
-> fundamental_types
, 0, nbytes
);
967 typep
= objfile
-> fundamental_types
+ typeid;
968 if ((type
= *typep
) == NULL
)
973 error ("internal error: unhandled type id %d", typeid);
976 type
= init_type (TYPE_CODE_VOID
,
977 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
982 type
= init_type (TYPE_CODE_INT
,
983 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
988 type
= init_type (TYPE_CODE_PASCAL_ARRAY
,
989 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
994 type
= init_type (TYPE_CODE_INT
,
995 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
1000 type
= init_type (TYPE_CODE_INT
,
1001 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
1003 "signed char", objfile
);
1005 case FT_UNSIGNED_CHAR
:
1006 type
= init_type (TYPE_CODE_INT
,
1007 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
1009 "unsigned char", objfile
);
1012 type
= init_type (TYPE_CODE_INT
,
1013 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
1017 case FT_SIGNED_SHORT
:
1018 type
= init_type (TYPE_CODE_INT
,
1019 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
1021 "short", objfile
); /* FIXME -fnf */
1023 case FT_UNSIGNED_SHORT
:
1024 type
= init_type (TYPE_CODE_INT
,
1025 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
1027 "unsigned short", objfile
);
1030 type
= init_type (TYPE_CODE_INT
,
1031 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1035 case FT_SIGNED_INTEGER
:
1036 type
= init_type (TYPE_CODE_INT
,
1037 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1039 "int", objfile
); /* FIXME -fnf */
1041 case FT_UNSIGNED_INTEGER
:
1042 type
= init_type (TYPE_CODE_INT
,
1043 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1045 "unsigned int", objfile
);
1047 case FT_FIXED_DECIMAL
:
1048 type
= init_type (TYPE_CODE_INT
,
1049 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1051 "fixed decimal", objfile
);
1054 type
= init_type (TYPE_CODE_INT
,
1055 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
1059 case FT_SIGNED_LONG
:
1060 type
= init_type (TYPE_CODE_INT
,
1061 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
1063 "long", objfile
); /* FIXME -fnf */
1065 case FT_UNSIGNED_LONG
:
1066 type
= init_type (TYPE_CODE_INT
,
1067 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
1069 "unsigned long", objfile
);
1072 type
= init_type (TYPE_CODE_INT
,
1073 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
1075 "long long", objfile
);
1077 case FT_SIGNED_LONG_LONG
:
1078 type
= init_type (TYPE_CODE_INT
,
1079 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
1081 "signed long long", objfile
);
1083 case FT_UNSIGNED_LONG_LONG
:
1084 type
= init_type (TYPE_CODE_INT
,
1085 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
1087 "unsigned long long", objfile
);
1090 type
= init_type (TYPE_CODE_FLT
,
1091 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
1095 case FT_DBL_PREC_FLOAT
:
1096 type
= init_type (TYPE_CODE_FLT
,
1097 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
1101 case FT_FLOAT_DECIMAL
:
1102 type
= init_type (TYPE_CODE_FLT
,
1103 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
1105 "floating decimal", objfile
);
1107 case FT_EXT_PREC_FLOAT
:
1108 type
= init_type (TYPE_CODE_FLT
,
1109 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
1111 "long double", objfile
);
1114 type
= init_type (TYPE_CODE_FLT
,
1115 TARGET_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
1117 "complex", objfile
);
1119 case FT_DBL_PREC_COMPLEX
:
1120 type
= init_type (TYPE_CODE_FLT
,
1121 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
1123 "double complex", objfile
);
1125 case FT_EXT_PREC_COMPLEX
:
1126 type
= init_type (TYPE_CODE_FLT
,
1127 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
1129 "long double complex", objfile
);
1132 /* Install the newly created type in the objfile's fundamental_types
1140 #if MAINTENANCE_CMDS
1143 print_bit_vector (bits
, nbits
)
1149 for (bitno
= 0; bitno
< nbits
; bitno
++)
1151 if ((bitno
% 8) == 0)
1153 puts_filtered (" ");
1155 if (B_TST (bits
, bitno
))
1157 printf_filtered ("1");
1161 printf_filtered ("0");
1166 /* The args list is a strange beast. It is either terminated by a NULL
1167 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
1168 type for normal fixed argcount functions. (FIXME someday)
1169 Also note the first arg should be the "this" pointer, we may not want to
1170 include it since we may get into a infinitely recursive situation. */
1173 print_arg_types (args
, spaces
)
1179 while (*args
!= NULL
)
1181 recursive_dump_type (*args
, spaces
+ 2);
1182 if ((*args
++) -> code
== TYPE_CODE_VOID
)
1191 dump_fn_fieldlists (type
, spaces
)
1199 printfi_filtered (spaces
, "fn_fieldlists 0x%x\n",
1200 TYPE_FN_FIELDLISTS (type
));
1201 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
1203 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
1204 printfi_filtered (spaces
+ 2, "[%d] name '%s' (0x%x) length %d\n",
1206 TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
1207 TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
1208 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
1209 for (overload_idx
= 0;
1210 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
1213 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (0x%x)\n",
1215 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
1216 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
1217 printfi_filtered (spaces
+ 8, "type 0x%x\n",
1218 TYPE_FN_FIELD_TYPE (f
, overload_idx
));
1219 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
1221 printfi_filtered (spaces
+ 8, "args 0x%x\n",
1222 TYPE_FN_FIELD_ARGS (f
, overload_idx
));
1223 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
), spaces
);
1224 printfi_filtered (spaces
+ 8, "fcontext 0x%x\n",
1225 TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
));
1226 printfi_filtered (spaces
+ 8, "is_const %d\n",
1227 TYPE_FN_FIELD_CONST (f
, overload_idx
));
1228 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
1229 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
1230 printfi_filtered (spaces
+ 8, "is_private %d\n",
1231 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
1232 printfi_filtered (spaces
+ 8, "is_protected %d\n",
1233 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
1234 printfi_filtered (spaces
+ 8, "is_stub %d\n",
1235 TYPE_FN_FIELD_STUB (f
, overload_idx
));
1236 printfi_filtered (spaces
+ 8, "voffset %u\n",
1237 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
1243 print_cplus_stuff (type
, spaces
)
1249 printfi_filtered (spaces
, "n_baseclasses %d\n",
1250 TYPE_N_BASECLASSES (type
));
1251 printfi_filtered (spaces
, "nfn_fields %d\n",
1252 TYPE_NFN_FIELDS (type
));
1253 printfi_filtered (spaces
, "nfn_fields_total %d\n",
1254 TYPE_NFN_FIELDS_TOTAL (type
));
1255 if (TYPE_N_BASECLASSES (type
) > 0)
1257 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *0x%x)",
1258 TYPE_N_BASECLASSES (type
),
1259 TYPE_FIELD_VIRTUAL_BITS (type
));
1260 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
1261 TYPE_N_BASECLASSES (type
));
1262 puts_filtered ("\n");
1264 if (TYPE_NFIELDS (type
) > 0)
1266 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
1268 printfi_filtered (spaces
, "private_field_bits (%d bits at *0x%x)",
1269 TYPE_NFIELDS (type
),
1270 TYPE_FIELD_PRIVATE_BITS (type
));
1271 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
1272 TYPE_NFIELDS (type
));
1273 puts_filtered ("\n");
1275 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
1277 printfi_filtered (spaces
, "protected_field_bits (%d bits at *0x%x)",
1278 TYPE_NFIELDS (type
),
1279 TYPE_FIELD_PROTECTED_BITS (type
));
1280 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
1281 TYPE_NFIELDS (type
));
1282 puts_filtered ("\n");
1285 if (TYPE_NFN_FIELDS (type
) > 0)
1287 dump_fn_fieldlists (type
, spaces
);
1292 recursive_dump_type (type
, spaces
)
1298 printfi_filtered (spaces
, "type node 0x%x\n", type
);
1299 printfi_filtered (spaces
, "name '%s' (0x%x)\n", TYPE_NAME (type
),
1300 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
1301 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
1302 switch (TYPE_CODE (type
))
1304 case TYPE_CODE_UNDEF
:
1305 printf_filtered ("(TYPE_CODE_UNDEF)");
1308 printf_filtered ("(TYPE_CODE_PTR)");
1310 case TYPE_CODE_ARRAY
:
1311 printf_filtered ("(TYPE_CODE_ARRAY)");
1313 case TYPE_CODE_STRUCT
:
1314 printf_filtered ("(TYPE_CODE_STRUCT)");
1316 case TYPE_CODE_UNION
:
1317 printf_filtered ("(TYPE_CODE_UNION)");
1319 case TYPE_CODE_ENUM
:
1320 printf_filtered ("(TYPE_CODE_ENUM)");
1322 case TYPE_CODE_FUNC
:
1323 printf_filtered ("(TYPE_CODE_FUNC)");
1326 printf_filtered ("(TYPE_CODE_INT)");
1329 printf_filtered ("(TYPE_CODE_FLT)");
1331 case TYPE_CODE_VOID
:
1332 printf_filtered ("(TYPE_CODE_VOID)");
1335 printf_filtered ("(TYPE_CODE_SET)");
1337 case TYPE_CODE_RANGE
:
1338 printf_filtered ("(TYPE_CODE_RANGE)");
1340 case TYPE_CODE_PASCAL_ARRAY
:
1341 printf_filtered ("(TYPE_CODE_PASCAL_ARRAY)");
1343 case TYPE_CODE_ERROR
:
1344 printf_filtered ("(TYPE_CODE_ERROR)");
1346 case TYPE_CODE_MEMBER
:
1347 printf_filtered ("(TYPE_CODE_MEMBER)");
1349 case TYPE_CODE_METHOD
:
1350 printf_filtered ("(TYPE_CODE_METHOD)");
1353 printf_filtered ("(TYPE_CODE_REF)");
1355 case TYPE_CODE_CHAR
:
1356 printf_filtered ("(TYPE_CODE_CHAR)");
1358 case TYPE_CODE_BOOL
:
1359 printf_filtered ("(TYPE_CODE_BOOL)");
1362 printf_filtered ("(UNKNOWN TYPE CODE)");
1365 puts_filtered ("\n");
1366 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
1367 printfi_filtered (spaces
, "objfile 0x%x\n", TYPE_OBJFILE (type
));
1368 printfi_filtered (spaces
, "target_type 0x%x\n", TYPE_TARGET_TYPE (type
));
1369 if (TYPE_TARGET_TYPE (type
) != NULL
)
1371 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
1373 printfi_filtered (spaces
, "pointer_type 0x%x\n",
1374 TYPE_POINTER_TYPE (type
));
1375 printfi_filtered (spaces
, "reference_type 0x%x\n",
1376 TYPE_REFERENCE_TYPE (type
));
1377 printfi_filtered (spaces
, "function_type 0x%x\n",
1378 TYPE_FUNCTION_TYPE (type
));
1379 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
1380 if (TYPE_FLAGS (type
) & TYPE_FLAG_UNSIGNED
)
1382 puts_filtered (" TYPE_FLAG_UNSIGNED");
1384 if (TYPE_FLAGS (type
) & TYPE_FLAG_SIGNED
)
1386 puts_filtered (" TYPE_FLAG_SIGNED");
1388 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1390 puts_filtered (" TYPE_FLAG_STUB");
1392 puts_filtered ("\n");
1393 printfi_filtered (spaces
, "nfields %d 0x%x\n", TYPE_NFIELDS (type
),
1394 TYPE_FIELDS (type
));
1395 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
1397 printfi_filtered (spaces
+ 2,
1398 "[%d] bitpos %d bitsize %d type 0x%x name '%s' (0x%x)\n",
1399 idx
, TYPE_FIELD_BITPOS (type
, idx
),
1400 TYPE_FIELD_BITSIZE (type
, idx
),
1401 TYPE_FIELD_TYPE (type
, idx
),
1402 TYPE_FIELD_NAME (type
, idx
),
1403 TYPE_FIELD_NAME (type
, idx
) != NULL
1404 ? TYPE_FIELD_NAME (type
, idx
)
1406 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
1408 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
1411 printfi_filtered (spaces
, "vptr_basetype 0x%x\n",
1412 TYPE_VPTR_BASETYPE (type
));
1413 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
1415 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
1417 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
1418 switch (TYPE_CODE (type
))
1420 case TYPE_CODE_METHOD
:
1421 case TYPE_CODE_FUNC
:
1422 printfi_filtered (spaces
, "arg_types 0x%x\n", TYPE_ARG_TYPES (type
));
1423 print_arg_types (TYPE_ARG_TYPES (type
), spaces
);
1426 case TYPE_CODE_STRUCT
:
1427 printfi_filtered (spaces
, "cplus_stuff 0x%x\n",
1428 TYPE_CPLUS_SPECIFIC (type
));
1429 print_cplus_stuff (type
, spaces
);
1433 /* We have to pick one of the union types to be able print and test
1434 the value. Pick cplus_struct_type, even though we know it isn't
1435 any particular one. */
1436 printfi_filtered (spaces
, "type_specific 0x%x",
1437 TYPE_CPLUS_SPECIFIC (type
));
1438 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
1440 printf_filtered (" (unknown data form)");
1442 printf_filtered ("\n");
1448 #endif /* MAINTENANCE_CMDS */