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 obstack_alloc (&TYPE_OBJFILE (result_type
) -> type_obstack
,
318 sizeof (struct field
));
321 /* Create range type. */
322 range_type
= alloc_type (TYPE_OBJFILE (result_type
));
323 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
324 TYPE_TARGET_TYPE (range_type
) = builtin_type_int
; /* FIXME */
326 /* This should never be needed. */
327 TYPE_LENGTH (range_type
) = sizeof (int);
329 TYPE_NFIELDS (range_type
) = 2;
330 TYPE_FIELDS (range_type
) = (struct field
*)
331 obstack_alloc (&TYPE_OBJFILE (range_type
) -> type_obstack
,
332 2 * sizeof (struct field
));
333 TYPE_FIELD_BITPOS (range_type
, 0) = 0; /* FIXME */
334 TYPE_FIELD_BITPOS (range_type
, 1) = number
-1; /* FIXME */
335 TYPE_FIELD_TYPE (range_type
, 0) = builtin_type_int
; /* FIXME */
336 TYPE_FIELD_TYPE (range_type
, 1) = builtin_type_int
; /* FIXME */
338 TYPE_FIELD_TYPE(result_type
,0)=range_type
;
339 TYPE_VPTR_FIELDNO (result_type
) = -1;
341 return (result_type
);
345 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
346 A MEMBER is a wierd thing -- it amounts to a typed offset into
347 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
348 include the offset (that's the value of the MEMBER itself), but does
349 include the structure type into which it points (for some reason).
351 When "smashing" the type, we preserve the objfile that the
352 old type pointed to, since we aren't changing where the type is actually
356 smash_to_member_type (type
, domain
, to_type
)
359 struct type
*to_type
;
361 struct objfile
*objfile
;
363 objfile
= TYPE_OBJFILE (type
);
365 memset ((char *)type
, 0, sizeof (struct type
));
366 TYPE_OBJFILE (type
) = objfile
;
367 TYPE_TARGET_TYPE (type
) = to_type
;
368 TYPE_DOMAIN_TYPE (type
) = domain
;
369 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
370 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
373 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
374 METHOD just means `function that gets an extra "this" argument'.
376 When "smashing" the type, we preserve the objfile that the
377 old type pointed to, since we aren't changing where the type is actually
381 smash_to_method_type (type
, domain
, to_type
, args
)
384 struct type
*to_type
;
387 struct objfile
*objfile
;
389 objfile
= TYPE_OBJFILE (type
);
391 memset ((char *)type
, 0, sizeof (struct type
));
392 TYPE_OBJFILE (type
) = objfile
;
393 TYPE_TARGET_TYPE (type
) = to_type
;
394 TYPE_DOMAIN_TYPE (type
) = domain
;
395 TYPE_ARG_TYPES (type
) = args
;
396 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
397 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
400 /* Return a typename for a struct/union/enum type
401 without the tag qualifier. If the type has a NULL name,
405 type_name_no_tag (type
)
406 register const struct type
*type
;
410 if ((name
= TYPE_NAME (type
)) != NULL
)
412 switch (TYPE_CODE (type
))
414 case TYPE_CODE_STRUCT
:
415 if(!strncmp (name
, "struct ", 7))
420 case TYPE_CODE_UNION
:
421 if(!strncmp (name
, "union ", 6))
427 if(!strncmp (name
, "enum ", 5))
432 default: /* To avoid -Wall warnings */
439 /* Lookup a primitive type named NAME.
440 Return zero if NAME is not a primitive type.*/
443 lookup_primitive_typename (name
)
446 struct type
** const *p
;
448 for (p
= current_language
-> la_builtin_type_vector
; *p
!= NULL
; p
++)
450 if (!strcmp ((**p
) -> name
, name
))
458 /* Lookup a typedef or primitive type named NAME,
459 visible in lexical block BLOCK.
460 If NOERR is nonzero, return zero if NAME is not suitably defined. */
463 lookup_typename (name
, block
, noerr
)
468 register struct symbol
*sym
;
469 register struct type
*tmp
;
471 sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
472 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
474 tmp
= lookup_primitive_typename (name
);
479 else if (!tmp
&& noerr
)
485 error ("No type named %s.", name
);
488 return (SYMBOL_TYPE (sym
));
492 lookup_unsigned_typename (name
)
495 char *uns
= alloca (strlen (name
) + 10);
497 strcpy (uns
, "unsigned ");
498 strcpy (uns
+ 9, name
);
499 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
502 /* Lookup a structure type named "struct NAME",
503 visible in lexical block BLOCK. */
506 lookup_struct (name
, block
)
510 register struct symbol
*sym
;
512 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
513 (struct symtab
**) NULL
);
517 error ("No struct type named %s.", name
);
519 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
521 error ("This context has class, union or enum %s, not a struct.", name
);
523 return (SYMBOL_TYPE (sym
));
526 /* Lookup a union type named "union NAME",
527 visible in lexical block BLOCK. */
530 lookup_union (name
, block
)
534 register struct symbol
*sym
;
536 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
537 (struct symtab
**) NULL
);
541 error ("No union type named %s.", name
);
543 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_UNION
)
545 error ("This context has class, struct or enum %s, not a union.", name
);
547 return (SYMBOL_TYPE (sym
));
550 /* Lookup an enum type named "enum NAME",
551 visible in lexical block BLOCK. */
554 lookup_enum (name
, block
)
558 register struct symbol
*sym
;
560 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
561 (struct symtab
**) NULL
);
564 error ("No enum type named %s.", name
);
566 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
568 error ("This context has class, struct or union %s, not an enum.", name
);
570 return (SYMBOL_TYPE (sym
));
573 /* Lookup a template type named "template NAME<TYPE>",
574 visible in lexical block BLOCK. */
577 lookup_template_type (name
, type
, block
)
583 char *nam
= (char*) alloca(strlen(name
) + strlen(type
->name
) + 4);
586 strcat (nam
, type
->name
);
587 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
589 sym
= lookup_symbol (nam
, block
, VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
593 error ("No template type named %s.", name
);
595 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
597 error ("This context has class, union or enum %s, not a struct.", name
);
599 return (SYMBOL_TYPE (sym
));
602 /* Given a type TYPE, lookup the type of the component of type named
604 If NOERR is nonzero, return zero if NAME is not suitably defined. */
607 lookup_struct_elt_type (type
, name
, noerr
)
614 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
615 TYPE_CODE (type
) != TYPE_CODE_UNION
)
617 target_terminal_ours ();
619 fprintf (stderr
, "Type ");
620 type_print (type
, "", stderr
, -1);
621 error (" is not a structure or union type.");
624 check_stub_type (type
);
626 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
628 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
630 if (t_field_name
&& !strcmp (t_field_name
, name
))
632 return TYPE_FIELD_TYPE (type
, i
);
636 /* OK, it's not in this class. Recursively check the baseclasses. */
637 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
641 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 0);
653 target_terminal_ours ();
655 fprintf (stderr
, "Type ");
656 type_print (type
, "", stderr
, -1);
657 fprintf (stderr
, " has no component named ");
658 fputs_filtered (name
, stderr
);
660 return (struct type
*)-1; /* For lint */
663 /* This function is really horrible, but to avoid it, there would need
664 to be more filling in of forward references. */
667 fill_in_vptr_fieldno (type
)
670 if (TYPE_VPTR_FIELDNO (type
) < 0)
673 for (i
= 1; i
< TYPE_N_BASECLASSES (type
); i
++)
675 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
676 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
678 TYPE_VPTR_FIELDNO (type
)
679 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
680 TYPE_VPTR_BASETYPE (type
)
681 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
688 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
690 If this is a stubbed struct (i.e. declared as struct foo *), see if
691 we can find a full definition in some other file. If so, copy this
692 definition, so we can use it in future. If not, set a flag so we
693 don't waste too much time in future. (FIXME, this doesn't seem
696 This used to be coded as a macro, but I don't think it is called
697 often enough to merit such treatment.
700 struct complaint stub_noname_complaint
=
701 {"stub type has NULL name", 0, 0};
704 check_stub_type (type
)
707 if (TYPE_FLAGS(type
) & TYPE_FLAG_STUB
)
709 char* name
= type_name_no_tag (type
);
713 complain (&stub_noname_complaint
, 0);
716 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
717 (struct symtab
**) NULL
);
720 memcpy ((char *)type
, (char *)SYMBOL_TYPE(sym
), sizeof (struct type
));
725 /* Ugly hack to convert method stubs into method types.
727 He ain't kiddin'. This demangles the name of the method into a string
728 including argument types, parses out each argument type, generates
729 a string casting a zero to that type, evaluates the string, and stuffs
730 the resulting type into an argtype vector!!! Then it knows the type
731 of the whole function (including argument types for overloading),
732 which info used to be in the stab's but was removed to hack back
733 the space required for them. */
736 check_stub_method (type
, i
, j
)
742 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
743 char *demangled_name
= cplus_demangle (mangled_name
, DMGL_PARAMS
);
744 char *argtypetext
, *p
;
745 int depth
= 0, argcount
= 1;
746 struct type
**argtypes
;
749 if (demangled_name
== NULL
)
751 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
754 /* Now, read in the parameters that define this type. */
755 argtypetext
= strchr (demangled_name
, '(') + 1;
767 else if (*p
== ',' && depth
== 0)
775 /* We need two more slots: one for the THIS pointer, and one for the
776 NULL [...] or void [end of arglist]. */
778 argtypes
= (struct type
**)
779 obstack_alloc (&TYPE_OBJFILE (type
) -> type_obstack
,
780 (argcount
+2) * sizeof (struct type
*));
782 argtypes
[0] = lookup_pointer_type (type
);
785 if (*p
!= ')') /* () means no args, skip while */
790 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
793 parse_and_eval_type (argtypetext
, p
- argtypetext
);
811 if (p
[-2] != '.') /* ... */
813 argtypes
[argcount
] = builtin_type_void
; /* Ellist terminator */
817 argtypes
[argcount
] = NULL
; /* List terminator */
820 free (demangled_name
);
822 f
= TYPE_FN_FIELDLIST1 (type
, i
);
823 TYPE_FN_FIELD_PHYSNAME (f
, j
) = mangled_name
;
825 /* Now update the old "stub" type into a real type. */
826 mtype
= TYPE_FN_FIELD_TYPE (f
, j
);
827 TYPE_DOMAIN_TYPE (mtype
) = type
;
828 TYPE_ARG_TYPES (mtype
) = argtypes
;
829 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
830 TYPE_FN_FIELD_STUB (f
, j
) = 0;
833 const struct cplus_struct_type cplus_struct_default
;
836 allocate_cplus_struct_type (type
)
839 if (!HAVE_CPLUS_STRUCT (type
))
841 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
842 obstack_alloc (¤t_objfile
-> type_obstack
,
843 sizeof (struct cplus_struct_type
));
844 *(TYPE_CPLUS_SPECIFIC(type
)) = cplus_struct_default
;
848 /* Helper function to initialize the standard scalar types.
850 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
851 of the string pointed to by name in the type_obstack for that objfile,
852 and initialize the type name to that copy. There are places (mipsread.c
853 in particular, where init_type is called with a NULL value for NAME). */
856 init_type (code
, length
, flags
, name
, objfile
)
861 struct objfile
*objfile
;
863 register struct type
*type
;
865 type
= alloc_type (objfile
);
866 TYPE_CODE (type
) = code
;
867 TYPE_LENGTH (type
) = length
;
868 TYPE_FLAGS (type
) |= flags
;
869 if ((name
!= NULL
) && (objfile
!= NULL
))
872 obsavestring (name
, strlen (name
), &objfile
-> type_obstack
);
876 TYPE_NAME (type
) = name
;
881 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
883 INIT_CPLUS_SPECIFIC (type
);
888 /* Look up a fundamental type for the specified objfile.
889 May need to construct such a type if this is the first use.
891 Some object file formats (ELF, COFF, etc) do not define fundamental
892 types such as "int" or "double". Others (stabs for example), do
893 define fundamental types.
895 For the formats which don't provide fundamental types, gdb can create
896 such types, using defaults reasonable for the current target machine.
898 FIXME: Some compilers distinguish explicitly signed integral types
899 (signed short, signed int, signed long) from "regular" integral types
900 (short, int, long) in the debugging information. There is some dis-
901 agreement as to how useful this feature is. In particular, gcc does
902 not support this. Also, only some debugging formats allow the
903 distinction to be passed on to a debugger. For now, we always just
904 use "short", "int", or "long" as the type name, for both the implicit
905 and explicitly signed types. This also makes life easier for the
906 gdb test suite since we don't have to account for the differences
907 in output depending upon what the compiler and debugging format
908 support. We will probably have to re-examine the issue when gdb
909 starts taking it's fundamental type information directly from the
910 debugging information supplied by the compiler. fnf@cygnus.com */
913 lookup_fundamental_type (objfile
, typeid)
914 struct objfile
*objfile
;
917 register struct type
*type
= NULL
;
918 register struct type
**typep
;
921 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
923 error ("internal error - invalid fundamental type id %d", typeid);
927 /* If this is the first time we */
928 if (objfile
-> fundamental_types
== NULL
)
930 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
931 objfile
-> fundamental_types
= (struct type
**)
932 obstack_alloc (&objfile
-> type_obstack
, nbytes
);
933 memset ((char *)objfile
-> fundamental_types
, 0, nbytes
);
935 typep
= objfile
-> fundamental_types
+ typeid;
936 if ((type
= *typep
) == NULL
)
941 error ("internal error: unhandled type id %d", typeid);
944 type
= init_type (TYPE_CODE_VOID
,
945 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
950 type
= init_type (TYPE_CODE_INT
,
951 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
956 type
= init_type (TYPE_CODE_PASCAL_ARRAY
,
957 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
962 type
= init_type (TYPE_CODE_INT
,
963 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
968 type
= init_type (TYPE_CODE_INT
,
969 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
971 "signed char", objfile
);
973 case FT_UNSIGNED_CHAR
:
974 type
= init_type (TYPE_CODE_INT
,
975 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
977 "unsigned char", objfile
);
980 type
= init_type (TYPE_CODE_INT
,
981 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
985 case FT_SIGNED_SHORT
:
986 type
= init_type (TYPE_CODE_INT
,
987 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
989 "short", objfile
); /* FIXME -fnf */
991 case FT_UNSIGNED_SHORT
:
992 type
= init_type (TYPE_CODE_INT
,
993 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
995 "unsigned short", objfile
);
998 type
= init_type (TYPE_CODE_INT
,
999 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1003 case FT_SIGNED_INTEGER
:
1004 type
= init_type (TYPE_CODE_INT
,
1005 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1007 "int", objfile
); /* FIXME -fnf */
1009 case FT_UNSIGNED_INTEGER
:
1010 type
= init_type (TYPE_CODE_INT
,
1011 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1013 "unsigned int", objfile
);
1015 case FT_FIXED_DECIMAL
:
1016 type
= init_type (TYPE_CODE_INT
,
1017 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1019 "fixed decimal", objfile
);
1022 type
= init_type (TYPE_CODE_INT
,
1023 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
1027 case FT_SIGNED_LONG
:
1028 type
= init_type (TYPE_CODE_INT
,
1029 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
1031 "long", objfile
); /* FIXME -fnf */
1033 case FT_UNSIGNED_LONG
:
1034 type
= init_type (TYPE_CODE_INT
,
1035 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
1037 "unsigned long", objfile
);
1040 type
= init_type (TYPE_CODE_INT
,
1041 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
1043 "long long", objfile
);
1045 case FT_SIGNED_LONG_LONG
:
1046 type
= init_type (TYPE_CODE_INT
,
1047 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
1049 "signed long long", objfile
);
1051 case FT_UNSIGNED_LONG_LONG
:
1052 type
= init_type (TYPE_CODE_INT
,
1053 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
1055 "unsigned long long", objfile
);
1058 type
= init_type (TYPE_CODE_FLT
,
1059 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
1063 case FT_DBL_PREC_FLOAT
:
1064 type
= init_type (TYPE_CODE_FLT
,
1065 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
1069 case FT_FLOAT_DECIMAL
:
1070 type
= init_type (TYPE_CODE_FLT
,
1071 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
1073 "floating decimal", objfile
);
1075 case FT_EXT_PREC_FLOAT
:
1076 type
= init_type (TYPE_CODE_FLT
,
1077 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
1079 "long double", objfile
);
1082 type
= init_type (TYPE_CODE_FLT
,
1083 TARGET_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
1085 "complex", objfile
);
1087 case FT_DBL_PREC_COMPLEX
:
1088 type
= init_type (TYPE_CODE_FLT
,
1089 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
1091 "double complex", objfile
);
1093 case FT_EXT_PREC_COMPLEX
:
1094 type
= init_type (TYPE_CODE_FLT
,
1095 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
1097 "long double complex", objfile
);
1100 /* Install the newly created type in the objfile's fundamental_types
1108 #if MAINTENANCE_CMDS
1110 void recursive_dump_type (type
, spaces
)
1117 print_spaces_filtered (spaces
, stdout
);
1118 printf_filtered ("type node @ 0x%x\n", type
);
1119 print_spaces_filtered (spaces
, stdout
);
1120 printf_filtered ("name: 0x%x '%s'\n", type
-> name
,
1121 type
-> name
? type
-> name
: "<NULL>");
1122 print_spaces_filtered (spaces
, stdout
);
1123 printf_filtered ("code: 0x%x ", type
-> code
);
1124 switch (type
-> code
)
1126 case TYPE_CODE_UNDEF
: printf_filtered ("TYPE_CODE_UNDEF"); break;
1127 case TYPE_CODE_PTR
: printf_filtered ("TYPE_CODE_PTR"); break;
1128 case TYPE_CODE_ARRAY
: printf_filtered ("TYPE_CODE_ARRAY"); break;
1129 case TYPE_CODE_STRUCT
: printf_filtered ("TYPE_CODE_STRUCT"); break;
1130 case TYPE_CODE_UNION
: printf_filtered ("TYPE_CODE_UNION"); break;
1131 case TYPE_CODE_ENUM
: printf_filtered ("TYPE_CODE_ENUM"); break;
1132 case TYPE_CODE_FUNC
: printf_filtered ("TYPE_CODE_FUNC"); break;
1133 case TYPE_CODE_INT
: printf_filtered ("TYPE_CODE_INT"); break;
1134 case TYPE_CODE_FLT
: printf_filtered ("TYPE_CODE_FLT"); break;
1135 case TYPE_CODE_VOID
: printf_filtered ("TYPE_CODE_VOID"); break;
1136 case TYPE_CODE_SET
: printf_filtered ("TYPE_CODE_SET"); break;
1137 case TYPE_CODE_RANGE
: printf_filtered ("TYPE_CODE_RANGE"); break;
1138 case TYPE_CODE_PASCAL_ARRAY
: printf_filtered ("TYPE_CODE_PASCAL_ARRAY"); break;
1139 case TYPE_CODE_ERROR
: printf_filtered ("TYPE_CODE_ERROR"); break;
1140 case TYPE_CODE_MEMBER
: printf_filtered ("TYPE_CODE_MEMBER"); break;
1141 case TYPE_CODE_METHOD
: printf_filtered ("TYPE_CODE_METHOD"); break;
1142 case TYPE_CODE_REF
: printf_filtered ("TYPE_CODE_REF"); break;
1143 case TYPE_CODE_CHAR
: printf_filtered ("TYPE_CODE_CHAR"); break;
1144 case TYPE_CODE_BOOL
: printf_filtered ("TYPE_CODE_BOOL"); break;
1145 default: printf_filtered ("<UNKNOWN TYPE CODE>"); break;
1147 printf_filtered ("\n");
1148 print_spaces_filtered (spaces
, stdout
);
1149 printf_filtered ("length: %d\n", type
-> length
);
1150 print_spaces_filtered (spaces
, stdout
);
1151 printf_filtered ("objfile: 0x%x\n", type
-> objfile
);
1152 print_spaces_filtered (spaces
, stdout
);
1153 printf_filtered ("target_type: 0x%x\n", type
-> target_type
);
1154 if (type
-> target_type
!= NULL
)
1156 recursive_dump_type (type
-> target_type
, spaces
+ 2);
1158 print_spaces_filtered (spaces
, stdout
);
1159 printf_filtered ("pointer_type: 0x%x\n", type
-> pointer_type
);
1160 print_spaces_filtered (spaces
, stdout
);
1161 printf_filtered ("reference_type: 0x%x\n", type
-> reference_type
);
1162 print_spaces_filtered (spaces
, stdout
);
1163 printf_filtered ("function_type: 0x%x\n", type
-> function_type
);
1165 print_spaces_filtered (spaces
, stdout
);
1166 printf_filtered ("flags: 0x%x", type
-> flags
);
1167 if (type
-> flags
& TYPE_FLAG_UNSIGNED
)
1168 printf_filtered (" TYPE_FLAG_UNSIGNED");
1169 if (type
-> flags
& TYPE_FLAG_SIGNED
)
1170 printf_filtered (" TYPE_FLAG_SIGNED");
1171 if (type
-> flags
& TYPE_FLAG_STUB
)
1172 printf_filtered (" TYPE_FLAG_STUB");
1173 printf_filtered ("\n");
1175 print_spaces_filtered (spaces
, stdout
);
1176 printf_filtered ("nfields: %d at 0x%x\n", type
-> nfields
, type
-> fields
);
1177 for (idx
= 0; idx
< type
-> nfields
; idx
++)
1179 fldp
= &(type
-> fields
[idx
]);
1180 print_spaces_filtered (spaces
+ 2, stdout
);
1181 printf_filtered ("[%d] bitpos %d bitsize %d type 0x%x name 0x%x '%s'\n",
1182 idx
, fldp
-> bitpos
, fldp
-> bitsize
, fldp
-> type
,
1183 fldp
-> name
, fldp
-> name
? fldp
-> name
: "<NULL>");
1184 if (fldp
-> type
!= NULL
)
1186 recursive_dump_type (fldp
-> type
, spaces
+ 4);
1190 print_spaces_filtered (spaces
, stdout
);
1191 printf_filtered ("vptr_basetype: 0x%x\n", type
-> vptr_basetype
);
1192 if (type
-> vptr_basetype
!= NULL
)
1194 recursive_dump_type (type
-> vptr_basetype
, spaces
+ 2);
1197 print_spaces_filtered (spaces
, stdout
);
1198 printf_filtered ("vptr_fieldno: %d\n", type
-> vptr_fieldno
);
1200 switch (type
-> code
)
1202 case TYPE_CODE_METHOD
:
1203 case TYPE_CODE_FUNC
:
1204 print_spaces_filtered (spaces
, stdout
);
1205 printf_filtered ("arg_types: 0x%x\n",
1206 type
-> type_specific
.arg_types
);
1209 case TYPE_CODE_STRUCT
:
1210 print_spaces_filtered (spaces
, stdout
);
1211 printf_filtered ("cplus_stuff: 0x%x\n",
1212 type
-> type_specific
.cplus_stuff
);
1217 #endif /* MAINTENANCE_CMDS */