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"
33 #include "complaints.h"
35 /* Alloc a new type structure and fill it with some defaults. If
36 OBJFILE is non-NULL, then allocate the space for the type structure
37 in that objfile's type_obstack. */
41 struct objfile *objfile;
43 register struct type *type;
45 /* Alloc the structure and start off with all fields zeroed. */
49 type = (struct type *) xmalloc (sizeof (struct type));
53 type = (struct type *) obstack_alloc (&objfile -> type_obstack,
54 sizeof (struct type));
56 memset ((char *) type, 0, sizeof (struct type));
58 /* Initialize the fields that might not be zero. */
60 TYPE_CODE (type) = TYPE_CODE_UNDEF;
61 TYPE_OBJFILE (type) = objfile;
62 TYPE_VPTR_FIELDNO (type) = -1;
67 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
68 to a pointer to memory where the pointer type should be stored.
69 If *TYPEPTR is zero, update it to point to the pointer type we return.
70 We allocate new memory if needed. */
73 make_pointer_type (type, typeptr)
75 struct type **typeptr;
77 register struct type *ntype; /* New type */
78 struct objfile *objfile;
80 ntype = TYPE_POINTER_TYPE (type);
84 return ntype; /* Don't care about alloc, and have new type. */
85 else if (*typeptr == 0)
87 *typeptr = ntype; /* Tracking alloc, and we have new type. */
91 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
93 ntype = alloc_type (TYPE_OBJFILE (type));
97 else /* We have storage, but need to reset it. */
100 objfile = TYPE_OBJFILE (ntype);
101 memset ((char *) ntype, 0, sizeof (struct type));
102 TYPE_OBJFILE (ntype) = objfile;
105 TYPE_TARGET_TYPE (ntype) = type;
106 TYPE_POINTER_TYPE (type) = ntype;
108 /* FIXME! Assume the machine has only one representation for pointers! */
110 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
111 TYPE_CODE (ntype) = TYPE_CODE_PTR;
113 /* pointers are unsigned */
114 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
116 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
117 TYPE_POINTER_TYPE (type) = ntype;
122 /* Given a type TYPE, return a type of pointers to that type.
123 May need to construct such a type if this is the first use. */
126 lookup_pointer_type (type)
129 return make_pointer_type (type, (struct type **)0);
132 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
133 to a pointer to memory where the reference type should be stored.
134 If *TYPEPTR is zero, update it to point to the reference type we return.
135 We allocate new memory if needed. */
138 make_reference_type (type, typeptr)
140 struct type **typeptr;
142 register struct type *ntype; /* New type */
143 struct objfile *objfile;
145 ntype = TYPE_REFERENCE_TYPE (type);
149 return ntype; /* Don't care about alloc, and have new type. */
150 else if (*typeptr == 0)
152 *typeptr = ntype; /* Tracking alloc, and we have new type. */
156 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
158 ntype = alloc_type (TYPE_OBJFILE (type));
162 else /* We have storage, but need to reset it. */
165 objfile = TYPE_OBJFILE (ntype);
166 memset ((char *) ntype, 0, sizeof (struct type));
167 TYPE_OBJFILE (ntype) = objfile;
170 TYPE_TARGET_TYPE (ntype) = type;
171 TYPE_REFERENCE_TYPE (type) = ntype;
173 /* FIXME! Assume the machine has only one representation for references,
174 and that it matches the (only) representation for pointers! */
176 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
177 TYPE_CODE (ntype) = TYPE_CODE_REF;
179 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
180 TYPE_REFERENCE_TYPE (type) = ntype;
185 /* Same as above, but caller doesn't care about memory allocation details. */
188 lookup_reference_type (type)
191 return make_reference_type (type, (struct type **)0);
194 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
195 to a pointer to memory where the function type should be stored.
196 If *TYPEPTR is zero, update it to point to the function type we return.
197 We allocate new memory if needed. */
200 make_function_type (type, typeptr)
202 struct type **typeptr;
204 register struct type *ntype; /* New type */
205 struct objfile *objfile;
207 ntype = TYPE_FUNCTION_TYPE (type);
211 return ntype; /* Don't care about alloc, and have new type. */
212 else if (*typeptr == 0)
214 *typeptr = ntype; /* Tracking alloc, and we have new type. */
218 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
220 ntype = alloc_type (TYPE_OBJFILE (type));
224 else /* We have storage, but need to reset it. */
227 objfile = TYPE_OBJFILE (ntype);
228 memset ((char *) ntype, 0, sizeof (struct type));
229 TYPE_OBJFILE (ntype) = objfile;
232 TYPE_TARGET_TYPE (ntype) = type;
233 TYPE_FUNCTION_TYPE (type) = ntype;
235 TYPE_LENGTH (ntype) = 1;
236 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
238 if (!TYPE_FUNCTION_TYPE (type)) /* Remember it, if don't have one. */
239 TYPE_FUNCTION_TYPE (type) = ntype;
245 /* Given a type TYPE, return a type of functions that return that type.
246 May need to construct such a type if this is the first use. */
249 lookup_function_type (type)
252 return make_function_type (type, (struct type **)0);
255 /* Implement direct support for MEMBER_TYPE in GNU C++.
256 May need to construct such a type if this is the first use.
257 The TYPE is the type of the member. The DOMAIN is the type
258 of the aggregate that the member belongs to. */
261 lookup_member_type (type, domain)
265 register struct type *mtype;
267 mtype = alloc_type (TYPE_OBJFILE (type));
268 smash_to_member_type (mtype, domain, type);
272 /* Allocate a stub method whose return type is TYPE.
273 This apparently happens for speed of symbol reading, since parsing
274 out the arguments to the method is cpu-intensive, the way we are doing
275 it. So, we will fill in arguments later.
276 This always returns a fresh type. */
279 allocate_stub_method (type)
284 mtype = alloc_type (TYPE_OBJFILE (type));
285 TYPE_TARGET_TYPE (mtype) = type;
286 /* _DOMAIN_TYPE (mtype) = unknown yet */
287 /* _ARG_TYPES (mtype) = unknown yet */
288 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
289 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
290 TYPE_LENGTH (mtype) = 1;
294 /* Create a range type using either a blank type supplied in RESULT_TYPE,
295 or creating a new type. Indices will be of type INDEX_TYPE, and will
296 range from LOW_BOUND to HIGH_BOUND, inclusive.
298 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
299 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
302 create_range_type (result_type, index_type, low_bound, high_bound)
303 struct type *result_type;
304 struct type *index_type;
308 if (result_type == NULL)
310 result_type = alloc_type (TYPE_OBJFILE (index_type));
312 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
313 TYPE_TARGET_TYPE (result_type) = index_type;
314 TYPE_LENGTH (result_type) = TYPE_LENGTH (index_type);
315 TYPE_NFIELDS (result_type) = 2;
316 TYPE_FIELDS (result_type) = (struct field *)
317 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
318 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
319 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
320 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
321 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
322 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
324 return (result_type);
328 /* Create an array type using either a blank type supplied in RESULT_TYPE,
329 or creating a new type. Elements will be of type ELEMENT_TYPE, the
330 indices will be of type RANGE_TYPE.
332 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
333 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
336 create_array_type (result_type, element_type, range_type)
337 struct type *result_type;
338 struct type *element_type;
339 struct type *range_type;
344 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
346 /* FIXME: We only handle range types at the moment. Complain and
347 create a dummy range type to use. */
348 warning ("internal error: array index type must be a range type");
349 range_type = lookup_fundamental_type (TYPE_OBJFILE (range_type),
351 range_type = create_range_type ((struct type *) NULL, range_type, 0, 0);
353 if (result_type == NULL)
355 result_type = alloc_type (TYPE_OBJFILE (element_type));
357 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
358 TYPE_TARGET_TYPE (result_type) = element_type;
359 low_bound = TYPE_FIELD_BITPOS (range_type, 0);
360 high_bound = TYPE_FIELD_BITPOS (range_type, 1);
361 TYPE_LENGTH (result_type) =
362 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
363 TYPE_NFIELDS (result_type) = 1;
364 TYPE_FIELDS (result_type) =
365 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
366 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
367 TYPE_FIELD_TYPE (result_type, 0) = range_type;
368 TYPE_VPTR_FIELDNO (result_type) = -1;
370 return (result_type);
374 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
375 A MEMBER is a wierd thing -- it amounts to a typed offset into
376 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
377 include the offset (that's the value of the MEMBER itself), but does
378 include the structure type into which it points (for some reason).
380 When "smashing" the type, we preserve the objfile that the
381 old type pointed to, since we aren't changing where the type is actually
385 smash_to_member_type (type, domain, to_type)
388 struct type *to_type;
390 struct objfile *objfile;
392 objfile = TYPE_OBJFILE (type);
394 memset ((char *) type, 0, sizeof (struct type));
395 TYPE_OBJFILE (type) = objfile;
396 TYPE_TARGET_TYPE (type) = to_type;
397 TYPE_DOMAIN_TYPE (type) = domain;
398 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
399 TYPE_CODE (type) = TYPE_CODE_MEMBER;
402 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
403 METHOD just means `function that gets an extra "this" argument'.
405 When "smashing" the type, we preserve the objfile that the
406 old type pointed to, since we aren't changing where the type is actually
410 smash_to_method_type (type, domain, to_type, args)
413 struct type *to_type;
416 struct objfile *objfile;
418 objfile = TYPE_OBJFILE (type);
420 memset ((char *) type, 0, sizeof (struct type));
421 TYPE_OBJFILE (type) = objfile;
422 TYPE_TARGET_TYPE (type) = to_type;
423 TYPE_DOMAIN_TYPE (type) = domain;
424 TYPE_ARG_TYPES (type) = args;
425 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
426 TYPE_CODE (type) = TYPE_CODE_METHOD;
429 /* Return a typename for a struct/union/enum type
430 without the tag qualifier. If the type has a NULL name,
434 type_name_no_tag (type)
435 register const struct type *type;
439 if ((name = TYPE_NAME (type)) != NULL)
441 switch (TYPE_CODE (type))
443 case TYPE_CODE_STRUCT:
444 if(!strncmp (name, "struct ", 7))
449 case TYPE_CODE_UNION:
450 if(!strncmp (name, "union ", 6))
456 if(!strncmp (name, "enum ", 5))
461 default: /* To avoid -Wall warnings */
468 /* Lookup a primitive type named NAME.
469 Return zero if NAME is not a primitive type.*/
472 lookup_primitive_typename (name)
475 struct type ** const *p;
477 for (p = current_language -> la_builtin_type_vector; *p != NULL; p++)
479 if (STREQ ((**p) -> name, name))
487 /* Lookup a typedef or primitive type named NAME,
488 visible in lexical block BLOCK.
489 If NOERR is nonzero, return zero if NAME is not suitably defined. */
492 lookup_typename (name, block, noerr)
497 register struct symbol *sym;
498 register struct type *tmp;
500 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
501 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
503 tmp = lookup_primitive_typename (name);
508 else if (!tmp && noerr)
514 error ("No type named %s.", name);
517 return (SYMBOL_TYPE (sym));
521 lookup_unsigned_typename (name)
524 char *uns = alloca (strlen (name) + 10);
526 strcpy (uns, "unsigned ");
527 strcpy (uns + 9, name);
528 return (lookup_typename (uns, (struct block *) NULL, 0));
532 lookup_signed_typename (name)
536 char *uns = alloca (strlen (name) + 8);
538 strcpy (uns, "signed ");
539 strcpy (uns + 7, name);
540 t = lookup_typename (uns, (struct block *) NULL, 1);
541 /* If we don't find "signed FOO" just try again with plain "FOO". */
544 return lookup_typename (name, (struct block *) NULL, 0);
547 /* Lookup a structure type named "struct NAME",
548 visible in lexical block BLOCK. */
551 lookup_struct (name, block)
555 register struct symbol *sym;
557 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
558 (struct symtab **) NULL);
562 error ("No struct type named %s.", name);
564 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
566 error ("This context has class, union or enum %s, not a struct.", name);
568 return (SYMBOL_TYPE (sym));
571 /* Lookup a union type named "union NAME",
572 visible in lexical block BLOCK. */
575 lookup_union (name, block)
579 register struct symbol *sym;
581 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
582 (struct symtab **) NULL);
586 error ("No union type named %s.", name);
588 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
590 error ("This context has class, struct or enum %s, not a union.", name);
592 return (SYMBOL_TYPE (sym));
595 /* Lookup an enum type named "enum NAME",
596 visible in lexical block BLOCK. */
599 lookup_enum (name, block)
603 register struct symbol *sym;
605 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
606 (struct symtab **) NULL);
609 error ("No enum type named %s.", name);
611 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
613 error ("This context has class, struct or union %s, not an enum.", name);
615 return (SYMBOL_TYPE (sym));
618 /* Lookup a template type named "template NAME<TYPE>",
619 visible in lexical block BLOCK. */
622 lookup_template_type (name, type, block)
628 char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4);
631 strcat (nam, type->name);
632 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
634 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
638 error ("No template type named %s.", name);
640 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
642 error ("This context has class, union or enum %s, not a struct.", name);
644 return (SYMBOL_TYPE (sym));
647 /* Given a type TYPE, lookup the type of the component of type named
649 If NOERR is nonzero, return zero if NAME is not suitably defined. */
652 lookup_struct_elt_type (type, name, noerr)
659 if (TYPE_CODE (type) == TYPE_CODE_PTR ||
660 TYPE_CODE (type) == TYPE_CODE_REF)
661 type = TYPE_TARGET_TYPE (type);
663 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
664 TYPE_CODE (type) != TYPE_CODE_UNION)
666 target_terminal_ours ();
668 fprintf (stderr, "Type ");
669 type_print (type, "", stderr, -1);
670 error (" is not a structure or union type.");
673 check_stub_type (type);
675 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
677 char *t_field_name = TYPE_FIELD_NAME (type, i);
679 if (t_field_name && STREQ (t_field_name, name))
681 return TYPE_FIELD_TYPE (type, i);
685 /* OK, it's not in this class. Recursively check the baseclasses. */
686 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
690 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 0);
702 target_terminal_ours ();
704 fprintf (stderr, "Type ");
705 type_print (type, "", stderr, -1);
706 fprintf (stderr, " has no component named ");
707 fputs_filtered (name, stderr);
709 return (struct type *)-1; /* For lint */
712 /* This function is really horrible, but to avoid it, there would need
713 to be more filling in of forward references. */
716 fill_in_vptr_fieldno (type)
719 if (TYPE_VPTR_FIELDNO (type) < 0)
722 for (i = 1; i < TYPE_N_BASECLASSES (type); i++)
724 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
725 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
727 TYPE_VPTR_FIELDNO (type)
728 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
729 TYPE_VPTR_BASETYPE (type)
730 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
737 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
739 If this is a stubbed struct (i.e. declared as struct foo *), see if
740 we can find a full definition in some other file. If so, copy this
741 definition, so we can use it in future. If not, set a flag so we
742 don't waste too much time in future. (FIXME, this doesn't seem
745 This used to be coded as a macro, but I don't think it is called
746 often enough to merit such treatment.
749 struct complaint stub_noname_complaint =
750 {"stub type has NULL name", 0, 0};
753 check_stub_type (type)
756 if (TYPE_FLAGS(type) & TYPE_FLAG_STUB)
758 char* name = type_name_no_tag (type);
762 complain (&stub_noname_complaint);
765 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
766 (struct symtab **) NULL);
769 memcpy ((char *)type, (char *)SYMBOL_TYPE(sym), sizeof (struct type));
774 /* Ugly hack to convert method stubs into method types.
776 He ain't kiddin'. This demangles the name of the method into a string
777 including argument types, parses out each argument type, generates
778 a string casting a zero to that type, evaluates the string, and stuffs
779 the resulting type into an argtype vector!!! Then it knows the type
780 of the whole function (including argument types for overloading),
781 which info used to be in the stab's but was removed to hack back
782 the space required for them. */
785 check_stub_method (type, i, j)
791 char *mangled_name = gdb_mangle_name (type, i, j);
792 char *demangled_name = cplus_demangle (mangled_name,
793 DMGL_PARAMS | DMGL_ANSI);
794 char *argtypetext, *p;
795 int depth = 0, argcount = 1;
796 struct type **argtypes;
799 if (demangled_name == NULL)
801 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
804 /* Now, read in the parameters that define this type. */
805 argtypetext = strchr (demangled_name, '(') + 1;
817 else if (*p == ',' && depth == 0)
825 /* We need two more slots: one for the THIS pointer, and one for the
826 NULL [...] or void [end of arglist]. */
828 argtypes = (struct type **)
829 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
831 argtypes[0] = lookup_pointer_type (type);
834 if (*p != ')') /* () means no args, skip while */
839 if (depth <= 0 && (*p == ',' || *p == ')'))
842 parse_and_eval_type (argtypetext, p - argtypetext);
860 if (p[-2] != '.') /* Not '...' */
862 argtypes[argcount] = builtin_type_void; /* List terminator */
866 argtypes[argcount] = NULL; /* Ellist terminator */
869 free (demangled_name);
871 f = TYPE_FN_FIELDLIST1 (type, i);
872 TYPE_FN_FIELD_PHYSNAME (f, j) = mangled_name;
874 /* Now update the old "stub" type into a real type. */
875 mtype = TYPE_FN_FIELD_TYPE (f, j);
876 TYPE_DOMAIN_TYPE (mtype) = type;
877 TYPE_ARG_TYPES (mtype) = argtypes;
878 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
879 TYPE_FN_FIELD_STUB (f, j) = 0;
882 struct cplus_struct_type cplus_struct_default;
885 allocate_cplus_struct_type (type)
888 if (!HAVE_CPLUS_STRUCT (type))
890 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
891 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
892 *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default;
896 /* Helper function to initialize the standard scalar types.
898 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
899 of the string pointed to by name in the type_obstack for that objfile,
900 and initialize the type name to that copy. There are places (mipsread.c
901 in particular, where init_type is called with a NULL value for NAME). */
904 init_type (code, length, flags, name, objfile)
909 struct objfile *objfile;
911 register struct type *type;
913 type = alloc_type (objfile);
914 TYPE_CODE (type) = code;
915 TYPE_LENGTH (type) = length;
916 TYPE_FLAGS (type) |= flags;
917 if ((name != NULL) && (objfile != NULL))
920 obsavestring (name, strlen (name), &objfile -> type_obstack);
924 TYPE_NAME (type) = name;
929 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
931 INIT_CPLUS_SPECIFIC (type);
936 /* Look up a fundamental type for the specified objfile.
937 May need to construct such a type if this is the first use.
939 Some object file formats (ELF, COFF, etc) do not define fundamental
940 types such as "int" or "double". Others (stabs for example), do
941 define fundamental types.
943 For the formats which don't provide fundamental types, gdb can create
944 such types, using defaults reasonable for the current language and
945 the current target machine.
947 NOTE: This routine is obsolescent. Each debugging format reader
948 should manage it's own fundamental types, either creating them from
949 suitable defaults or reading them from the debugging information,
950 whichever is appropriate. The DWARF reader has already been
951 fixed to do this. Once the other readers are fixed, this routine
952 will go away. Also note that fundamental types should be managed
953 on a compilation unit basis in a multi-language environment, not
954 on a linkage unit basis as is done here. */
958 lookup_fundamental_type (objfile, typeid)
959 struct objfile *objfile;
962 register struct type **typep;
965 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
967 error ("internal error - invalid fundamental type id %d", typeid);
970 /* If this is the first time we need a fundamental type for this objfile
971 then we need to initialize the vector of type pointers. */
973 if (objfile -> fundamental_types == NULL)
975 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
976 objfile -> fundamental_types = (struct type **)
977 obstack_alloc (&objfile -> type_obstack, nbytes);
978 memset ((char *) objfile -> fundamental_types, 0, nbytes);
981 /* Look for this particular type in the fundamental type vector. If one is
982 not found, create and install one appropriate for the current language. */
984 typep = objfile -> fundamental_types + typeid;
987 *typep = create_fundamental_type (objfile, typeid);
996 print_bit_vector (bits, nbits)
1002 for (bitno = 0; bitno < nbits; bitno++)
1004 if ((bitno % 8) == 0)
1006 puts_filtered (" ");
1008 if (B_TST (bits, bitno))
1010 printf_filtered ("1");
1014 printf_filtered ("0");
1019 /* The args list is a strange beast. It is either terminated by a NULL
1020 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
1021 type for normal fixed argcount functions. (FIXME someday)
1022 Also note the first arg should be the "this" pointer, we may not want to
1023 include it since we may get into a infinitely recursive situation. */
1026 print_arg_types (args, spaces)
1032 while (*args != NULL)
1034 recursive_dump_type (*args, spaces + 2);
1035 if ((*args++) -> code == TYPE_CODE_VOID)
1044 dump_fn_fieldlists (type, spaces)
1052 printfi_filtered (spaces, "fn_fieldlists 0x%x\n",
1053 TYPE_FN_FIELDLISTS (type));
1054 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
1056 f = TYPE_FN_FIELDLIST1 (type, method_idx);
1057 printfi_filtered (spaces + 2, "[%d] name '%s' (0x%x) length %d\n",
1059 TYPE_FN_FIELDLIST_NAME (type, method_idx),
1060 TYPE_FN_FIELDLIST_NAME (type, method_idx),
1061 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
1062 for (overload_idx = 0;
1063 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
1066 printfi_filtered (spaces + 4, "[%d] physname '%s' (0x%x)\n",
1068 TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
1069 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
1070 printfi_filtered (spaces + 8, "type 0x%x\n",
1071 TYPE_FN_FIELD_TYPE (f, overload_idx));
1072 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
1074 printfi_filtered (spaces + 8, "args 0x%x\n",
1075 TYPE_FN_FIELD_ARGS (f, overload_idx));
1076 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
1077 printfi_filtered (spaces + 8, "fcontext 0x%x\n",
1078 TYPE_FN_FIELD_FCONTEXT (f, overload_idx));
1079 printfi_filtered (spaces + 8, "is_const %d\n",
1080 TYPE_FN_FIELD_CONST (f, overload_idx));
1081 printfi_filtered (spaces + 8, "is_volatile %d\n",
1082 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
1083 printfi_filtered (spaces + 8, "is_private %d\n",
1084 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
1085 printfi_filtered (spaces + 8, "is_protected %d\n",
1086 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
1087 printfi_filtered (spaces + 8, "is_stub %d\n",
1088 TYPE_FN_FIELD_STUB (f, overload_idx));
1089 printfi_filtered (spaces + 8, "voffset %u\n",
1090 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
1096 print_cplus_stuff (type, spaces)
1100 printfi_filtered (spaces, "n_baseclasses %d\n",
1101 TYPE_N_BASECLASSES (type));
1102 printfi_filtered (spaces, "nfn_fields %d\n",
1103 TYPE_NFN_FIELDS (type));
1104 printfi_filtered (spaces, "nfn_fields_total %d\n",
1105 TYPE_NFN_FIELDS_TOTAL (type));
1106 if (TYPE_N_BASECLASSES (type) > 0)
1108 printfi_filtered (spaces, "virtual_field_bits (%d bits at *0x%x)",
1109 TYPE_N_BASECLASSES (type),
1110 TYPE_FIELD_VIRTUAL_BITS (type));
1111 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
1112 TYPE_N_BASECLASSES (type));
1113 puts_filtered ("\n");
1115 if (TYPE_NFIELDS (type) > 0)
1117 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
1119 printfi_filtered (spaces, "private_field_bits (%d bits at *0x%x)",
1120 TYPE_NFIELDS (type),
1121 TYPE_FIELD_PRIVATE_BITS (type));
1122 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
1123 TYPE_NFIELDS (type));
1124 puts_filtered ("\n");
1126 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
1128 printfi_filtered (spaces, "protected_field_bits (%d bits at *0x%x)",
1129 TYPE_NFIELDS (type),
1130 TYPE_FIELD_PROTECTED_BITS (type));
1131 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
1132 TYPE_NFIELDS (type));
1133 puts_filtered ("\n");
1136 if (TYPE_NFN_FIELDS (type) > 0)
1138 dump_fn_fieldlists (type, spaces);
1143 recursive_dump_type (type, spaces)
1149 printfi_filtered (spaces, "type node 0x%x\n", type);
1150 printfi_filtered (spaces, "name '%s' (0x%x)\n", TYPE_NAME (type),
1151 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
1152 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
1153 switch (TYPE_CODE (type))
1155 case TYPE_CODE_UNDEF:
1156 printf_filtered ("(TYPE_CODE_UNDEF)");
1159 printf_filtered ("(TYPE_CODE_PTR)");
1161 case TYPE_CODE_ARRAY:
1162 printf_filtered ("(TYPE_CODE_ARRAY)");
1164 case TYPE_CODE_STRUCT:
1165 printf_filtered ("(TYPE_CODE_STRUCT)");
1167 case TYPE_CODE_UNION:
1168 printf_filtered ("(TYPE_CODE_UNION)");
1170 case TYPE_CODE_ENUM:
1171 printf_filtered ("(TYPE_CODE_ENUM)");
1173 case TYPE_CODE_FUNC:
1174 printf_filtered ("(TYPE_CODE_FUNC)");
1177 printf_filtered ("(TYPE_CODE_INT)");
1180 printf_filtered ("(TYPE_CODE_FLT)");
1182 case TYPE_CODE_VOID:
1183 printf_filtered ("(TYPE_CODE_VOID)");
1186 printf_filtered ("(TYPE_CODE_SET)");
1188 case TYPE_CODE_RANGE:
1189 printf_filtered ("(TYPE_CODE_RANGE)");
1191 case TYPE_CODE_PASCAL_ARRAY:
1192 printf_filtered ("(TYPE_CODE_PASCAL_ARRAY)");
1194 case TYPE_CODE_ERROR:
1195 printf_filtered ("(TYPE_CODE_ERROR)");
1197 case TYPE_CODE_MEMBER:
1198 printf_filtered ("(TYPE_CODE_MEMBER)");
1200 case TYPE_CODE_METHOD:
1201 printf_filtered ("(TYPE_CODE_METHOD)");
1204 printf_filtered ("(TYPE_CODE_REF)");
1206 case TYPE_CODE_CHAR:
1207 printf_filtered ("(TYPE_CODE_CHAR)");
1209 case TYPE_CODE_BOOL:
1210 printf_filtered ("(TYPE_CODE_BOOL)");
1213 printf_filtered ("(UNKNOWN TYPE CODE)");
1216 puts_filtered ("\n");
1217 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
1218 printfi_filtered (spaces, "objfile 0x%x\n", TYPE_OBJFILE (type));
1219 printfi_filtered (spaces, "target_type 0x%x\n", TYPE_TARGET_TYPE (type));
1220 if (TYPE_TARGET_TYPE (type) != NULL)
1222 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
1224 printfi_filtered (spaces, "pointer_type 0x%x\n",
1225 TYPE_POINTER_TYPE (type));
1226 printfi_filtered (spaces, "reference_type 0x%x\n",
1227 TYPE_REFERENCE_TYPE (type));
1228 printfi_filtered (spaces, "function_type 0x%x\n",
1229 TYPE_FUNCTION_TYPE (type));
1230 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
1231 if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED)
1233 puts_filtered (" TYPE_FLAG_UNSIGNED");
1235 if (TYPE_FLAGS (type) & TYPE_FLAG_SIGNED)
1237 puts_filtered (" TYPE_FLAG_SIGNED");
1239 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1241 puts_filtered (" TYPE_FLAG_STUB");
1243 puts_filtered ("\n");
1244 printfi_filtered (spaces, "nfields %d 0x%x\n", TYPE_NFIELDS (type),
1245 TYPE_FIELDS (type));
1246 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
1248 printfi_filtered (spaces + 2,
1249 "[%d] bitpos %d bitsize %d type 0x%x name '%s' (0x%x)\n",
1250 idx, TYPE_FIELD_BITPOS (type, idx),
1251 TYPE_FIELD_BITSIZE (type, idx),
1252 TYPE_FIELD_TYPE (type, idx),
1253 TYPE_FIELD_NAME (type, idx),
1254 TYPE_FIELD_NAME (type, idx) != NULL
1255 ? TYPE_FIELD_NAME (type, idx)
1257 if (TYPE_FIELD_TYPE (type, idx) != NULL)
1259 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
1262 printfi_filtered (spaces, "vptr_basetype 0x%x\n",
1263 TYPE_VPTR_BASETYPE (type));
1264 if (TYPE_VPTR_BASETYPE (type) != NULL)
1266 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
1268 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
1269 switch (TYPE_CODE (type))
1271 case TYPE_CODE_METHOD:
1272 case TYPE_CODE_FUNC:
1273 printfi_filtered (spaces, "arg_types 0x%x\n", TYPE_ARG_TYPES (type));
1274 print_arg_types (TYPE_ARG_TYPES (type), spaces);
1277 case TYPE_CODE_STRUCT:
1278 printfi_filtered (spaces, "cplus_stuff 0x%x\n",
1279 TYPE_CPLUS_SPECIFIC (type));
1280 print_cplus_stuff (type, spaces);
1284 /* We have to pick one of the union types to be able print and test
1285 the value. Pick cplus_struct_type, even though we know it isn't
1286 any particular one. */
1287 printfi_filtered (spaces, "type_specific 0x%x",
1288 TYPE_CPLUS_SPECIFIC (type));
1289 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
1291 printf_filtered (" (unknown data form)");
1293 printf_filtered ("\n");
1299 #endif /* MAINTENANCE_CMDS */