1 /* Support routines for manipulating internal types for GDB.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
3 Contributed by Cygnus Support, using pieces from other GDB modules.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
28 #include "expression.h"
33 #include "complaints.h"
35 /* These variables point to the objects
36 representing the predefined C data types. */
38 struct type *builtin_type_void;
39 struct type *builtin_type_char;
40 struct type *builtin_type_short;
41 struct type *builtin_type_int;
42 struct type *builtin_type_long;
43 struct type *builtin_type_long_long;
44 struct type *builtin_type_signed_char;
45 struct type *builtin_type_unsigned_char;
46 struct type *builtin_type_unsigned_short;
47 struct type *builtin_type_unsigned_int;
48 struct type *builtin_type_unsigned_long;
49 struct type *builtin_type_unsigned_long_long;
50 struct type *builtin_type_float;
51 struct type *builtin_type_double;
52 struct type *builtin_type_long_double;
53 struct type *builtin_type_complex;
54 struct type *builtin_type_double_complex;
55 struct type *builtin_type_string;
57 struct extra { char str[128]; int len; }; /* maximum extention is 128! FIXME */
59 static void add_name PARAMS ((struct extra *, char *));
60 static void add_mangled_type PARAMS ((struct extra *, struct type *));
62 static void cfront_mangle_name PARAMS ((struct type *, int, int));
64 static void print_bit_vector PARAMS ((B_TYPE *, int));
65 static void print_arg_types PARAMS ((struct type **, int));
66 static void dump_fn_fieldlists PARAMS ((struct type *, int));
67 static void print_cplus_stuff PARAMS ((struct type *, int));
69 /* Alloc a new type structure and fill it with some defaults. If
70 OBJFILE is non-NULL, then allocate the space for the type structure
71 in that objfile's type_obstack. */
75 struct objfile *objfile;
77 register struct type *type;
79 /* Alloc the structure and start off with all fields zeroed. */
83 type = (struct type *) xmalloc (sizeof (struct type));
87 type = (struct type *) obstack_alloc (&objfile -> type_obstack,
88 sizeof (struct type));
89 OBJSTAT (objfile, n_types++);
91 memset ((char *) type, 0, sizeof (struct type));
93 /* Initialize the fields that might not be zero. */
95 TYPE_CODE (type) = TYPE_CODE_UNDEF;
96 TYPE_OBJFILE (type) = objfile;
97 TYPE_VPTR_FIELDNO (type) = -1;
102 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
103 to a pointer to memory where the pointer type should be stored.
104 If *TYPEPTR is zero, update it to point to the pointer type we return.
105 We allocate new memory if needed. */
108 make_pointer_type (type, typeptr)
110 struct type **typeptr;
112 register struct type *ntype; /* New type */
113 struct objfile *objfile;
115 ntype = TYPE_POINTER_TYPE (type);
119 return ntype; /* Don't care about alloc, and have new type. */
120 else if (*typeptr == 0)
122 *typeptr = ntype; /* Tracking alloc, and we have new type. */
126 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
128 ntype = alloc_type (TYPE_OBJFILE (type));
132 else /* We have storage, but need to reset it. */
135 objfile = TYPE_OBJFILE (ntype);
136 memset ((char *) ntype, 0, sizeof (struct type));
137 TYPE_OBJFILE (ntype) = objfile;
140 TYPE_TARGET_TYPE (ntype) = type;
141 TYPE_POINTER_TYPE (type) = ntype;
143 /* FIXME! Assume the machine has only one representation for pointers! */
145 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
146 TYPE_CODE (ntype) = TYPE_CODE_PTR;
148 /* pointers are unsigned */
149 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
151 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
152 TYPE_POINTER_TYPE (type) = ntype;
157 /* Given a type TYPE, return a type of pointers to that type.
158 May need to construct such a type if this is the first use. */
161 lookup_pointer_type (type)
164 return make_pointer_type (type, (struct type **)0);
167 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
168 to a pointer to memory where the reference type should be stored.
169 If *TYPEPTR is zero, update it to point to the reference type we return.
170 We allocate new memory if needed. */
173 make_reference_type (type, typeptr)
175 struct type **typeptr;
177 register struct type *ntype; /* New type */
178 struct objfile *objfile;
180 ntype = TYPE_REFERENCE_TYPE (type);
184 return ntype; /* Don't care about alloc, and have new type. */
185 else if (*typeptr == 0)
187 *typeptr = ntype; /* Tracking alloc, and we have new type. */
191 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
193 ntype = alloc_type (TYPE_OBJFILE (type));
197 else /* We have storage, but need to reset it. */
200 objfile = TYPE_OBJFILE (ntype);
201 memset ((char *) ntype, 0, sizeof (struct type));
202 TYPE_OBJFILE (ntype) = objfile;
205 TYPE_TARGET_TYPE (ntype) = type;
206 TYPE_REFERENCE_TYPE (type) = ntype;
208 /* FIXME! Assume the machine has only one representation for references,
209 and that it matches the (only) representation for pointers! */
211 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
212 TYPE_CODE (ntype) = TYPE_CODE_REF;
214 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
215 TYPE_REFERENCE_TYPE (type) = ntype;
220 /* Same as above, but caller doesn't care about memory allocation details. */
223 lookup_reference_type (type)
226 return make_reference_type (type, (struct type **)0);
229 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
230 to a pointer to memory where the function type should be stored.
231 If *TYPEPTR is zero, update it to point to the function type we return.
232 We allocate new memory if needed. */
235 make_function_type (type, typeptr)
237 struct type **typeptr;
239 register struct type *ntype; /* New type */
240 struct objfile *objfile;
242 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
244 ntype = alloc_type (TYPE_OBJFILE (type));
248 else /* We have storage, but need to reset it. */
251 objfile = TYPE_OBJFILE (ntype);
252 memset ((char *) ntype, 0, sizeof (struct type));
253 TYPE_OBJFILE (ntype) = objfile;
256 TYPE_TARGET_TYPE (ntype) = type;
258 TYPE_LENGTH (ntype) = 1;
259 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
265 /* Given a type TYPE, return a type of functions that return that type.
266 May need to construct such a type if this is the first use. */
269 lookup_function_type (type)
272 return make_function_type (type, (struct type **)0);
275 /* Implement direct support for MEMBER_TYPE in GNU C++.
276 May need to construct such a type if this is the first use.
277 The TYPE is the type of the member. The DOMAIN is the type
278 of the aggregate that the member belongs to. */
281 lookup_member_type (type, domain)
285 register struct type *mtype;
287 mtype = alloc_type (TYPE_OBJFILE (type));
288 smash_to_member_type (mtype, domain, type);
292 /* Allocate a stub method whose return type is TYPE.
293 This apparently happens for speed of symbol reading, since parsing
294 out the arguments to the method is cpu-intensive, the way we are doing
295 it. So, we will fill in arguments later.
296 This always returns a fresh type. */
299 allocate_stub_method (type)
304 mtype = alloc_type (TYPE_OBJFILE (type));
305 TYPE_TARGET_TYPE (mtype) = type;
306 /* _DOMAIN_TYPE (mtype) = unknown yet */
307 /* _ARG_TYPES (mtype) = unknown yet */
308 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
309 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
310 TYPE_LENGTH (mtype) = 1;
314 /* Create a range type using either a blank type supplied in RESULT_TYPE,
315 or creating a new type, inheriting the objfile from INDEX_TYPE.
317 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
318 HIGH_BOUND, inclusive.
320 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
321 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
324 create_range_type (result_type, index_type, low_bound, high_bound)
325 struct type *result_type;
326 struct type *index_type;
330 if (result_type == NULL)
332 result_type = alloc_type (TYPE_OBJFILE (index_type));
334 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
335 TYPE_TARGET_TYPE (result_type) = index_type;
336 if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB)
337 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
339 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
340 TYPE_NFIELDS (result_type) = 2;
341 TYPE_FIELDS (result_type) = (struct field *)
342 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
343 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
344 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
345 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
346 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
347 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
349 return (result_type);
352 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
353 Return 1 of type is a range type, 0 if it is discrete (and bounds
354 will fit in LONGEST), or -1 otherwise. */
357 get_discrete_bounds (type, lowp, highp)
359 LONGEST *lowp, *highp;
361 CHECK_TYPEDEF (type);
362 switch (TYPE_CODE (type))
364 case TYPE_CODE_RANGE:
365 *lowp = TYPE_LOW_BOUND (type);
366 *highp = TYPE_HIGH_BOUND (type);
369 if (TYPE_NFIELDS (type) > 0)
371 /* The enums may not be sorted by value, so search all
375 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
376 for (i = 0; i < TYPE_NFIELDS (type); i++)
378 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
379 *lowp = TYPE_FIELD_BITPOS (type, i);
380 if (TYPE_FIELD_BITPOS (type, i) > *highp)
381 *highp = TYPE_FIELD_BITPOS (type, i);
395 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
397 if (!TYPE_UNSIGNED (type))
399 *lowp = - (1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
403 /* ... fall through for unsigned ints ... */
406 /* This round-about calculation is to avoid shifting by
407 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
408 if TYPE_LENGTH (type) == sizeof (LONGEST). */
409 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
410 *highp = (*highp - 1) | *highp;
417 /* Create an array type using either a blank type supplied in RESULT_TYPE,
418 or creating a new type, inheriting the objfile from RANGE_TYPE.
420 Elements will be of type ELEMENT_TYPE, the indices will be of type
423 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
424 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
427 create_array_type (result_type, element_type, range_type)
428 struct type *result_type;
429 struct type *element_type;
430 struct type *range_type;
432 LONGEST low_bound, high_bound;
434 if (result_type == NULL)
436 result_type = alloc_type (TYPE_OBJFILE (range_type));
438 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
439 TYPE_TARGET_TYPE (result_type) = element_type;
440 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
441 low_bound = high_bound = 0;
442 CHECK_TYPEDEF (element_type);
443 TYPE_LENGTH (result_type) =
444 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
445 TYPE_NFIELDS (result_type) = 1;
446 TYPE_FIELDS (result_type) =
447 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
448 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
449 TYPE_FIELD_TYPE (result_type, 0) = range_type;
450 TYPE_VPTR_FIELDNO (result_type) = -1;
452 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
453 if (TYPE_LENGTH (result_type) == 0)
454 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
456 return (result_type);
459 /* Create a string type using either a blank type supplied in RESULT_TYPE,
460 or creating a new type. String types are similar enough to array of
461 char types that we can use create_array_type to build the basic type
462 and then bash it into a string type.
464 For fixed length strings, the range type contains 0 as the lower
465 bound and the length of the string minus one as the upper bound.
467 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
468 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
471 create_string_type (result_type, range_type)
472 struct type *result_type;
473 struct type *range_type;
475 result_type = create_array_type (result_type,
476 *current_language->string_char_type,
478 TYPE_CODE (result_type) = TYPE_CODE_STRING;
479 return (result_type);
483 create_set_type (result_type, domain_type)
484 struct type *result_type;
485 struct type *domain_type;
487 LONGEST low_bound, high_bound, bit_length;
488 if (result_type == NULL)
490 result_type = alloc_type (TYPE_OBJFILE (domain_type));
492 TYPE_CODE (result_type) = TYPE_CODE_SET;
493 TYPE_NFIELDS (result_type) = 1;
494 TYPE_FIELDS (result_type) = (struct field *)
495 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
496 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
498 if (! (TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB))
500 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
501 low_bound = high_bound = 0;
502 bit_length = high_bound - low_bound + 1;
503 TYPE_LENGTH (result_type)
504 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
506 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
507 return (result_type);
510 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
511 A MEMBER is a wierd thing -- it amounts to a typed offset into
512 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
513 include the offset (that's the value of the MEMBER itself), but does
514 include the structure type into which it points (for some reason).
516 When "smashing" the type, we preserve the objfile that the
517 old type pointed to, since we aren't changing where the type is actually
521 smash_to_member_type (type, domain, to_type)
524 struct type *to_type;
526 struct objfile *objfile;
528 objfile = TYPE_OBJFILE (type);
530 memset ((char *) type, 0, sizeof (struct type));
531 TYPE_OBJFILE (type) = objfile;
532 TYPE_TARGET_TYPE (type) = to_type;
533 TYPE_DOMAIN_TYPE (type) = domain;
534 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
535 TYPE_CODE (type) = TYPE_CODE_MEMBER;
538 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
539 METHOD just means `function that gets an extra "this" argument'.
541 When "smashing" the type, we preserve the objfile that the
542 old type pointed to, since we aren't changing where the type is actually
546 smash_to_method_type (type, domain, to_type, args)
549 struct type *to_type;
552 struct objfile *objfile;
554 objfile = TYPE_OBJFILE (type);
556 memset ((char *) type, 0, sizeof (struct type));
557 TYPE_OBJFILE (type) = objfile;
558 TYPE_TARGET_TYPE (type) = to_type;
559 TYPE_DOMAIN_TYPE (type) = domain;
560 TYPE_ARG_TYPES (type) = args;
561 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
562 TYPE_CODE (type) = TYPE_CODE_METHOD;
565 /* Return a typename for a struct/union/enum type without "struct ",
566 "union ", or "enum ". If the type has a NULL name, return NULL. */
569 type_name_no_tag (type)
570 register const struct type *type;
572 if (TYPE_TAG_NAME (type) != NULL)
573 return TYPE_TAG_NAME (type);
575 /* Is there code which expects this to return the name if there is no
576 tag name? My guess is that this is mainly used for C++ in cases where
577 the two will always be the same. */
578 return TYPE_NAME (type);
581 /* Lookup a primitive type named NAME.
582 Return zero if NAME is not a primitive type.*/
585 lookup_primitive_typename (name)
588 struct type ** const *p;
590 for (p = current_language -> la_builtin_type_vector; *p != NULL; p++)
592 if (STREQ ((**p) -> name, name))
600 /* Lookup a typedef or primitive type named NAME,
601 visible in lexical block BLOCK.
602 If NOERR is nonzero, return zero if NAME is not suitably defined. */
605 lookup_typename (name, block, noerr)
610 register struct symbol *sym;
611 register struct type *tmp;
613 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
614 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
616 tmp = lookup_primitive_typename (name);
621 else if (!tmp && noerr)
627 error ("No type named %s.", name);
630 return (SYMBOL_TYPE (sym));
634 lookup_unsigned_typename (name)
637 char *uns = alloca (strlen (name) + 10);
639 strcpy (uns, "unsigned ");
640 strcpy (uns + 9, name);
641 return (lookup_typename (uns, (struct block *) NULL, 0));
645 lookup_signed_typename (name)
649 char *uns = alloca (strlen (name) + 8);
651 strcpy (uns, "signed ");
652 strcpy (uns + 7, name);
653 t = lookup_typename (uns, (struct block *) NULL, 1);
654 /* If we don't find "signed FOO" just try again with plain "FOO". */
657 return lookup_typename (name, (struct block *) NULL, 0);
660 /* Lookup a structure type named "struct NAME",
661 visible in lexical block BLOCK. */
664 lookup_struct (name, block)
668 register struct symbol *sym;
670 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
671 (struct symtab **) NULL);
675 error ("No struct type named %s.", name);
677 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
679 error ("This context has class, union or enum %s, not a struct.", name);
681 return (SYMBOL_TYPE (sym));
684 /* Lookup a union type named "union NAME",
685 visible in lexical block BLOCK. */
688 lookup_union (name, block)
692 register struct symbol *sym;
694 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
695 (struct symtab **) NULL);
699 error ("No union type named %s.", name);
701 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
703 error ("This context has class, struct or enum %s, not a union.", name);
705 return (SYMBOL_TYPE (sym));
708 /* Lookup an enum type named "enum NAME",
709 visible in lexical block BLOCK. */
712 lookup_enum (name, block)
716 register struct symbol *sym;
718 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
719 (struct symtab **) NULL);
722 error ("No enum type named %s.", name);
724 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
726 error ("This context has class, struct or union %s, not an enum.", name);
728 return (SYMBOL_TYPE (sym));
731 /* Lookup a template type named "template NAME<TYPE>",
732 visible in lexical block BLOCK. */
735 lookup_template_type (name, type, block)
741 char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4);
744 strcat (nam, type->name);
745 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
747 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
751 error ("No template type named %s.", name);
753 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
755 error ("This context has class, union or enum %s, not a struct.", name);
757 return (SYMBOL_TYPE (sym));
760 /* Given a type TYPE, lookup the type of the component of type named NAME.
762 TYPE can be either a struct or union, or a pointer or reference to a struct or
763 union. If it is a pointer or reference, its target type is automatically used.
764 Thus '.' and '->' are interchangable, as specified for the definitions of the
765 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
767 If NOERR is nonzero, return zero if NAME is not suitably defined.
768 If NAME is the name of a baseclass type, return that type. */
771 lookup_struct_elt_type (type, name, noerr)
780 CHECK_TYPEDEF (type);
781 if (TYPE_CODE (type) != TYPE_CODE_PTR
782 && TYPE_CODE (type) != TYPE_CODE_REF)
784 type = TYPE_TARGET_TYPE (type);
787 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
788 TYPE_CODE (type) != TYPE_CODE_UNION)
790 target_terminal_ours ();
791 gdb_flush (gdb_stdout);
792 fprintf_unfiltered (gdb_stderr, "Type ");
793 type_print (type, "", gdb_stderr, -1);
794 error (" is not a structure or union type.");
798 /* FIXME: This change put in by Michael seems incorrect for the case where
799 the structure tag name is the same as the member name. I.E. when doing
800 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
805 typename = type_name_no_tag (type);
806 if (typename != NULL && STREQ (typename, name))
811 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
813 char *t_field_name = TYPE_FIELD_NAME (type, i);
815 if (t_field_name && STREQ (t_field_name, name))
817 return TYPE_FIELD_TYPE (type, i);
821 /* OK, it's not in this class. Recursively check the baseclasses. */
822 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
826 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
838 target_terminal_ours ();
839 gdb_flush (gdb_stdout);
840 fprintf_unfiltered (gdb_stderr, "Type ");
841 type_print (type, "", gdb_stderr, -1);
842 fprintf_unfiltered (gdb_stderr, " has no component named ");
843 fputs_filtered (name, gdb_stderr);
845 return (struct type *)-1; /* For lint */
848 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
849 valid. Callers should be aware that in some cases (for example,
850 the type or one of its baseclasses is a stub type and we are
851 debugging a .o file), this function will not be able to find the virtual
852 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
856 fill_in_vptr_fieldno (type)
859 CHECK_TYPEDEF (type);
861 if (TYPE_VPTR_FIELDNO (type) < 0)
865 /* We must start at zero in case the first (and only) baseclass is
866 virtual (and hence we cannot share the table pointer). */
867 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
869 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
870 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
872 TYPE_VPTR_FIELDNO (type)
873 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
874 TYPE_VPTR_BASETYPE (type)
875 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
882 /* Find the method and field indices for the destructor in class type T.
883 Return 1 if the destructor was found, otherwise, return 0. */
886 get_destructor_fn_field (t, method_indexp, field_indexp)
893 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
896 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
898 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
900 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j)))
911 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
913 If this is a stubbed struct (i.e. declared as struct foo *), see if
914 we can find a full definition in some other file. If so, copy this
915 definition, so we can use it in future. There used to be a comment (but
916 not any code) that if we don't find a full definition, we'd set a flag
917 so we don't spend time in the future checking the same type. That would
918 be a mistake, though--we might load in more symbols which contain a
919 full definition for the type.
921 This used to be coded as a macro, but I don't think it is called
922 often enough to merit such treatment. */
924 struct complaint stub_noname_complaint =
925 {"stub type has NULL name", 0, 0};
929 register struct type *type;
931 struct type *orig_type = type;
932 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
934 if (!TYPE_TARGET_TYPE (type))
939 /* It is dangerous to call lookup_symbol if we are currently
940 reading a symtab. Infinite recursion is one danger. */
941 if (currently_reading_symtab)
944 name = type_name_no_tag (type);
945 /* FIXME: shouldn't we separately check the TYPE_NAME and the
946 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
947 as appropriate? (this code was written before TYPE_NAME and
948 TYPE_TAG_NAME were separate). */
951 complain (&stub_noname_complaint);
954 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
955 (struct symtab **) NULL);
957 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
959 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
961 type = TYPE_TARGET_TYPE (type);
964 if ((TYPE_FLAGS(type) & TYPE_FLAG_STUB) && ! currently_reading_symtab)
966 char* name = type_name_no_tag (type);
967 /* FIXME: shouldn't we separately check the TYPE_NAME and the
968 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
969 as appropriate? (this code was written before TYPE_NAME and
970 TYPE_TAG_NAME were separate). */
974 complain (&stub_noname_complaint);
977 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
978 (struct symtab **) NULL);
981 memcpy ((char *)type,
982 (char *)SYMBOL_TYPE(sym),
983 sizeof (struct type));
987 if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB)
989 struct type *range_type;
990 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
992 if (TYPE_FLAGS (target_type) & TYPE_FLAG_STUB)
994 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
995 && TYPE_NFIELDS (type) == 1
996 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
999 /* Now recompute the length of the array type, based on its
1000 number of elements and the target type's length. */
1001 TYPE_LENGTH (type) =
1002 ((TYPE_FIELD_BITPOS (range_type, 1)
1003 - TYPE_FIELD_BITPOS (range_type, 0)
1005 * TYPE_LENGTH (target_type));
1006 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1008 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1010 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1011 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1014 /* Cache TYPE_LENGTH for future use. */
1015 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1019 /* New code added to support parsing of Cfront stabs strings */
1021 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1022 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1026 struct extra * pextras;
1031 if ((nlen = (n ? strlen(n) : 0))==0)
1033 sprintf(pextras->str+pextras->len,"%d%s",nlen,n);
1034 pextras->len=strlen(pextras->str);
1038 add_mangled_type(pextras,t)
1039 struct extra * pextras;
1042 enum type_code tcode;
1046 tcode = TYPE_CODE(t);
1047 tlen = TYPE_LENGTH(t);
1048 tflags = TYPE_FLAGS(t);
1049 tname = TYPE_NAME(t);
1050 /* args of "..." seem to get mangled as "e" */
1068 if ((pname=strrchr(tname,'l'),pname) && !strcmp(pname,"long"))
1077 static struct complaint msg = {"Bad int type code length x%x\n",0,0};
1079 complain (&msg, tlen);
1098 static struct complaint msg = {"Bad float type code length x%x\n",0,0};
1099 complain (&msg, tlen);
1105 /* followed by what it's a ref to */
1109 /* followed by what it's a ptr to */
1111 case TYPE_CODE_TYPEDEF:
1113 static struct complaint msg = {"Typedefs in overloaded functions not yet supported\n",0,0};
1116 /* followed by type bytes & name */
1118 case TYPE_CODE_FUNC:
1120 /* followed by func's arg '_' & ret types */
1122 case TYPE_CODE_VOID:
1125 case TYPE_CODE_METHOD:
1127 /* followed by name of class and func's arg '_' & ret types */
1128 add_name(pextras,tname);
1129 ADD_EXTRA('F'); /* then mangle function */
1131 case TYPE_CODE_STRUCT: /* C struct */
1132 case TYPE_CODE_UNION: /* C union */
1133 case TYPE_CODE_ENUM: /* Enumeration type */
1134 /* followed by name of type */
1135 add_name(pextras,tname);
1138 /* errors possible types/not supported */
1139 case TYPE_CODE_CHAR:
1140 case TYPE_CODE_ARRAY: /* Array type */
1141 case TYPE_CODE_MEMBER: /* Member type */
1142 case TYPE_CODE_BOOL:
1143 case TYPE_CODE_COMPLEX: /* Complex float */
1144 case TYPE_CODE_UNDEF:
1145 case TYPE_CODE_SET: /* Pascal sets */
1146 case TYPE_CODE_RANGE:
1147 case TYPE_CODE_STRING:
1148 case TYPE_CODE_BITSTRING:
1149 case TYPE_CODE_ERROR:
1152 static struct complaint msg = {"Unknown type code x%x\n",0,0};
1153 complain (&msg, tcode);
1157 add_mangled_type(pextras,t->target_type);
1162 cfront_mangle_name(type, i, j)
1168 char *mangled_name = gdb_mangle_name (type, i, j);
1170 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1172 /* kludge to support cfront methods - gdb expects to find "F" for
1173 ARM_mangled names, so when we mangle, we have to add it here */
1177 char * arm_mangled_name;
1178 struct fn_field *method = &f[j];
1179 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1180 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1181 char *newname = type_name_no_tag (type);
1183 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1184 int nargs = TYPE_NFIELDS(ftype); /* number of args */
1185 struct extra extras, * pextras = &extras;
1188 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1191 /* add args here! */
1192 if (nargs <= 1) /* no args besides this */
1195 for (k=1; k<nargs; k++)
1198 t = TYPE_FIELD_TYPE(ftype,k);
1199 add_mangled_type(pextras,t);
1203 printf("add_mangled_type: %s\n",extras.str); /* FIXME */
1204 arm_mangled_name = malloc(strlen(mangled_name)+extras.len);
1205 sprintf(arm_mangled_name,"%s%s",mangled_name,extras.str);
1207 mangled_name = arm_mangled_name;
1213 /* End of new code added to support parsing of Cfront stabs strings */
1215 /* Ugly hack to convert method stubs into method types.
1217 He ain't kiddin'. This demangles the name of the method into a string
1218 including argument types, parses out each argument type, generates
1219 a string casting a zero to that type, evaluates the string, and stuffs
1220 the resulting type into an argtype vector!!! Then it knows the type
1221 of the whole function (including argument types for overloading),
1222 which info used to be in the stab's but was removed to hack back
1223 the space required for them. */
1226 check_stub_method (type, i, j)
1232 char *mangled_name = gdb_mangle_name (type, i, j);
1233 char *demangled_name = cplus_demangle (mangled_name,
1234 DMGL_PARAMS | DMGL_ANSI);
1235 char *argtypetext, *p;
1236 int depth = 0, argcount = 1;
1237 struct type **argtypes;
1240 /* Make sure we got back a function string that we can use. */
1242 p = strchr (demangled_name, '(');
1244 if (demangled_name == NULL || p == NULL)
1245 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1247 /* Now, read in the parameters that define this type. */
1260 else if (*p == ',' && depth == 0)
1268 /* We need two more slots: one for the THIS pointer, and one for the
1269 NULL [...] or void [end of arglist]. */
1271 argtypes = (struct type **)
1272 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
1274 /* FIXME: This is wrong for static member functions. */
1275 argtypes[0] = lookup_pointer_type (type);
1278 if (*p != ')') /* () means no args, skip while */
1283 if (depth <= 0 && (*p == ',' || *p == ')'))
1285 /* Avoid parsing of ellipsis, they will be handled below. */
1286 if (strncmp (argtypetext, "...", p - argtypetext) != 0)
1288 argtypes[argcount] =
1289 parse_and_eval_type (argtypetext, p - argtypetext);
1292 argtypetext = p + 1;
1308 if (p[-2] != '.') /* Not '...' */
1310 argtypes[argcount] = builtin_type_void; /* List terminator */
1314 argtypes[argcount] = NULL; /* Ellist terminator */
1317 free (demangled_name);
1319 f = TYPE_FN_FIELDLIST1 (type, i);
1321 TYPE_FN_FIELD_PHYSNAME (f, j) = mangled_name;
1323 /* Now update the old "stub" type into a real type. */
1324 mtype = TYPE_FN_FIELD_TYPE (f, j);
1325 TYPE_DOMAIN_TYPE (mtype) = type;
1326 TYPE_ARG_TYPES (mtype) = argtypes;
1327 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1328 TYPE_FN_FIELD_STUB (f, j) = 0;
1331 const struct cplus_struct_type cplus_struct_default;
1334 allocate_cplus_struct_type (type)
1337 if (!HAVE_CPLUS_STRUCT (type))
1339 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1340 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1341 *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default;
1345 /* Helper function to initialize the standard scalar types.
1347 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1348 of the string pointed to by name in the type_obstack for that objfile,
1349 and initialize the type name to that copy. There are places (mipsread.c
1350 in particular, where init_type is called with a NULL value for NAME). */
1353 init_type (code, length, flags, name, objfile)
1354 enum type_code code;
1358 struct objfile *objfile;
1360 register struct type *type;
1362 type = alloc_type (objfile);
1363 TYPE_CODE (type) = code;
1364 TYPE_LENGTH (type) = length;
1365 TYPE_FLAGS (type) |= flags;
1366 if ((name != NULL) && (objfile != NULL))
1369 obsavestring (name, strlen (name), &objfile -> type_obstack);
1373 TYPE_NAME (type) = name;
1378 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1380 INIT_CPLUS_SPECIFIC (type);
1385 /* Look up a fundamental type for the specified objfile.
1386 May need to construct such a type if this is the first use.
1388 Some object file formats (ELF, COFF, etc) do not define fundamental
1389 types such as "int" or "double". Others (stabs for example), do
1390 define fundamental types.
1392 For the formats which don't provide fundamental types, gdb can create
1393 such types, using defaults reasonable for the current language and
1394 the current target machine.
1396 NOTE: This routine is obsolescent. Each debugging format reader
1397 should manage it's own fundamental types, either creating them from
1398 suitable defaults or reading them from the debugging information,
1399 whichever is appropriate. The DWARF reader has already been
1400 fixed to do this. Once the other readers are fixed, this routine
1401 will go away. Also note that fundamental types should be managed
1402 on a compilation unit basis in a multi-language environment, not
1403 on a linkage unit basis as is done here. */
1407 lookup_fundamental_type (objfile, typeid)
1408 struct objfile *objfile;
1411 register struct type **typep;
1412 register int nbytes;
1414 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1416 error ("internal error - invalid fundamental type id %d", typeid);
1419 /* If this is the first time we need a fundamental type for this objfile
1420 then we need to initialize the vector of type pointers. */
1422 if (objfile -> fundamental_types == NULL)
1424 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1425 objfile -> fundamental_types = (struct type **)
1426 obstack_alloc (&objfile -> type_obstack, nbytes);
1427 memset ((char *) objfile -> fundamental_types, 0, nbytes);
1428 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1431 /* Look for this particular type in the fundamental type vector. If one is
1432 not found, create and install one appropriate for the current language. */
1434 typep = objfile -> fundamental_types + typeid;
1437 *typep = create_fundamental_type (objfile, typeid);
1447 /* FIXME: Should we return true for references as well as pointers? */
1451 && TYPE_CODE (t) == TYPE_CODE_PTR
1452 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1455 /* Chill varying string and arrays are represented as follows:
1457 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1459 Return true if TYPE is such a Chill varying type. */
1462 chill_varying_type (type)
1465 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1466 || TYPE_NFIELDS (type) != 2
1467 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1472 #if MAINTENANCE_CMDS
1475 print_bit_vector (bits, nbits)
1481 for (bitno = 0; bitno < nbits; bitno++)
1483 if ((bitno % 8) == 0)
1485 puts_filtered (" ");
1487 if (B_TST (bits, bitno))
1489 printf_filtered ("1");
1493 printf_filtered ("0");
1498 /* The args list is a strange beast. It is either terminated by a NULL
1499 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
1500 type for normal fixed argcount functions. (FIXME someday)
1501 Also note the first arg should be the "this" pointer, we may not want to
1502 include it since we may get into a infinitely recursive situation. */
1505 print_arg_types (args, spaces)
1511 while (*args != NULL)
1513 recursive_dump_type (*args, spaces + 2);
1514 if ((*args++) -> code == TYPE_CODE_VOID)
1523 dump_fn_fieldlists (type, spaces)
1531 printfi_filtered (spaces, "fn_fieldlists ");
1532 gdb_print_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
1533 printf_filtered ("\n");
1534 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
1536 f = TYPE_FN_FIELDLIST1 (type, method_idx);
1537 printfi_filtered (spaces + 2, "[%d] name '%s' (",
1539 TYPE_FN_FIELDLIST_NAME (type, method_idx));
1540 gdb_print_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
1542 printf_filtered (") length %d\n",
1543 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
1544 for (overload_idx = 0;
1545 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
1548 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
1550 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
1551 gdb_print_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
1553 printf_filtered (")\n");
1554 printfi_filtered (spaces + 8, "type ");
1555 gdb_print_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
1556 printf_filtered ("\n");
1558 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
1561 printfi_filtered (spaces + 8, "args ");
1562 gdb_print_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
1563 printf_filtered ("\n");
1565 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
1566 printfi_filtered (spaces + 8, "fcontext ");
1567 gdb_print_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
1569 printf_filtered ("\n");
1571 printfi_filtered (spaces + 8, "is_const %d\n",
1572 TYPE_FN_FIELD_CONST (f, overload_idx));
1573 printfi_filtered (spaces + 8, "is_volatile %d\n",
1574 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
1575 printfi_filtered (spaces + 8, "is_private %d\n",
1576 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
1577 printfi_filtered (spaces + 8, "is_protected %d\n",
1578 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
1579 printfi_filtered (spaces + 8, "is_stub %d\n",
1580 TYPE_FN_FIELD_STUB (f, overload_idx));
1581 printfi_filtered (spaces + 8, "voffset %u\n",
1582 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
1588 print_cplus_stuff (type, spaces)
1592 printfi_filtered (spaces, "n_baseclasses %d\n",
1593 TYPE_N_BASECLASSES (type));
1594 printfi_filtered (spaces, "nfn_fields %d\n",
1595 TYPE_NFN_FIELDS (type));
1596 printfi_filtered (spaces, "nfn_fields_total %d\n",
1597 TYPE_NFN_FIELDS_TOTAL (type));
1598 if (TYPE_N_BASECLASSES (type) > 0)
1600 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
1601 TYPE_N_BASECLASSES (type));
1602 gdb_print_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
1603 printf_filtered (")");
1605 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
1606 TYPE_N_BASECLASSES (type));
1607 puts_filtered ("\n");
1609 if (TYPE_NFIELDS (type) > 0)
1611 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
1613 printfi_filtered (spaces, "private_field_bits (%d bits at *",
1614 TYPE_NFIELDS (type));
1615 gdb_print_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
1616 printf_filtered (")");
1617 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
1618 TYPE_NFIELDS (type));
1619 puts_filtered ("\n");
1621 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
1623 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
1624 TYPE_NFIELDS (type));
1625 gdb_print_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
1626 printf_filtered (")");
1627 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
1628 TYPE_NFIELDS (type));
1629 puts_filtered ("\n");
1632 if (TYPE_NFN_FIELDS (type) > 0)
1634 dump_fn_fieldlists (type, spaces);
1638 static struct obstack dont_print_type_obstack;
1641 recursive_dump_type (type, spaces)
1648 obstack_begin (&dont_print_type_obstack, 0);
1650 if (TYPE_NFIELDS (type) > 0
1651 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
1653 struct type **first_dont_print
1654 = (struct type **)obstack_base (&dont_print_type_obstack);
1656 int i = (struct type **)obstack_next_free (&dont_print_type_obstack)
1661 if (type == first_dont_print[i])
1663 printfi_filtered (spaces, "type node ");
1664 gdb_print_address (type, gdb_stdout);
1665 printf_filtered (" <same as already seen type>\n");
1670 obstack_ptr_grow (&dont_print_type_obstack, type);
1673 printfi_filtered (spaces, "type node ");
1674 gdb_print_address (type, gdb_stdout);
1675 printf_filtered ("\n");
1676 printfi_filtered (spaces, "name '%s' (",
1677 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
1678 gdb_print_address (TYPE_NAME (type), gdb_stdout);
1679 printf_filtered (")\n");
1680 if (TYPE_TAG_NAME (type) != NULL)
1682 printfi_filtered (spaces, "tagname '%s' (",
1683 TYPE_TAG_NAME (type));
1684 gdb_print_address (TYPE_TAG_NAME (type), gdb_stdout);
1685 printf_filtered (")\n");
1687 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
1688 switch (TYPE_CODE (type))
1690 case TYPE_CODE_UNDEF:
1691 printf_filtered ("(TYPE_CODE_UNDEF)");
1694 printf_filtered ("(TYPE_CODE_PTR)");
1696 case TYPE_CODE_ARRAY:
1697 printf_filtered ("(TYPE_CODE_ARRAY)");
1699 case TYPE_CODE_STRUCT:
1700 printf_filtered ("(TYPE_CODE_STRUCT)");
1702 case TYPE_CODE_UNION:
1703 printf_filtered ("(TYPE_CODE_UNION)");
1705 case TYPE_CODE_ENUM:
1706 printf_filtered ("(TYPE_CODE_ENUM)");
1708 case TYPE_CODE_FUNC:
1709 printf_filtered ("(TYPE_CODE_FUNC)");
1712 printf_filtered ("(TYPE_CODE_INT)");
1715 printf_filtered ("(TYPE_CODE_FLT)");
1717 case TYPE_CODE_VOID:
1718 printf_filtered ("(TYPE_CODE_VOID)");
1721 printf_filtered ("(TYPE_CODE_SET)");
1723 case TYPE_CODE_RANGE:
1724 printf_filtered ("(TYPE_CODE_RANGE)");
1726 case TYPE_CODE_STRING:
1727 printf_filtered ("(TYPE_CODE_STRING)");
1729 case TYPE_CODE_ERROR:
1730 printf_filtered ("(TYPE_CODE_ERROR)");
1732 case TYPE_CODE_MEMBER:
1733 printf_filtered ("(TYPE_CODE_MEMBER)");
1735 case TYPE_CODE_METHOD:
1736 printf_filtered ("(TYPE_CODE_METHOD)");
1739 printf_filtered ("(TYPE_CODE_REF)");
1741 case TYPE_CODE_CHAR:
1742 printf_filtered ("(TYPE_CODE_CHAR)");
1744 case TYPE_CODE_BOOL:
1745 printf_filtered ("(TYPE_CODE_BOOL)");
1747 case TYPE_CODE_TYPEDEF:
1748 printf_filtered ("(TYPE_CODE_TYPEDEF)");
1751 printf_filtered ("(UNKNOWN TYPE CODE)");
1754 puts_filtered ("\n");
1755 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
1756 printfi_filtered (spaces, "objfile ");
1757 gdb_print_address (TYPE_OBJFILE (type), gdb_stdout);
1758 printf_filtered ("\n");
1759 printfi_filtered (spaces, "target_type ");
1760 gdb_print_address (TYPE_TARGET_TYPE (type), gdb_stdout);
1761 printf_filtered ("\n");
1762 if (TYPE_TARGET_TYPE (type) != NULL)
1764 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
1766 printfi_filtered (spaces, "pointer_type ");
1767 gdb_print_address (TYPE_POINTER_TYPE (type), gdb_stdout);
1768 printf_filtered ("\n");
1769 printfi_filtered (spaces, "reference_type ");
1770 gdb_print_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
1771 printf_filtered ("\n");
1772 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
1773 if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED)
1775 puts_filtered (" TYPE_FLAG_UNSIGNED");
1777 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1779 puts_filtered (" TYPE_FLAG_STUB");
1781 puts_filtered ("\n");
1782 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
1783 gdb_print_address (TYPE_FIELDS (type), gdb_stdout);
1784 puts_filtered ("\n");
1785 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
1787 printfi_filtered (spaces + 2,
1788 "[%d] bitpos %d bitsize %d type ",
1789 idx, TYPE_FIELD_BITPOS (type, idx),
1790 TYPE_FIELD_BITSIZE (type, idx));
1791 gdb_print_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
1792 printf_filtered (" name '%s' (",
1793 TYPE_FIELD_NAME (type, idx) != NULL
1794 ? TYPE_FIELD_NAME (type, idx)
1796 gdb_print_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
1797 printf_filtered (")\n");
1798 if (TYPE_FIELD_TYPE (type, idx) != NULL)
1800 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
1803 printfi_filtered (spaces, "vptr_basetype ");
1804 gdb_print_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
1805 puts_filtered ("\n");
1806 if (TYPE_VPTR_BASETYPE (type) != NULL)
1808 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
1810 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
1811 switch (TYPE_CODE (type))
1813 case TYPE_CODE_METHOD:
1814 case TYPE_CODE_FUNC:
1815 printfi_filtered (spaces, "arg_types ");
1816 gdb_print_address (TYPE_ARG_TYPES (type), gdb_stdout);
1817 puts_filtered ("\n");
1818 print_arg_types (TYPE_ARG_TYPES (type), spaces);
1821 case TYPE_CODE_STRUCT:
1822 printfi_filtered (spaces, "cplus_stuff ");
1823 gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
1824 puts_filtered ("\n");
1825 print_cplus_stuff (type, spaces);
1829 /* We have to pick one of the union types to be able print and test
1830 the value. Pick cplus_struct_type, even though we know it isn't
1831 any particular one. */
1832 printfi_filtered (spaces, "type_specific ");
1833 gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
1834 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
1836 printf_filtered (" (unknown data form)");
1838 printf_filtered ("\n");
1843 obstack_free (&dont_print_type_obstack, NULL);
1846 #endif /* MAINTENANCE_CMDS */
1849 _initialize_gdbtypes ()
1852 init_type (TYPE_CODE_VOID, 1,
1854 "void", (struct objfile *) NULL);
1856 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1858 "char", (struct objfile *) NULL);
1859 builtin_type_signed_char =
1860 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1862 "signed char", (struct objfile *) NULL);
1863 builtin_type_unsigned_char =
1864 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1866 "unsigned char", (struct objfile *) NULL);
1867 builtin_type_short =
1868 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1870 "short", (struct objfile *) NULL);
1871 builtin_type_unsigned_short =
1872 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1874 "unsigned short", (struct objfile *) NULL);
1876 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1878 "int", (struct objfile *) NULL);
1879 builtin_type_unsigned_int =
1880 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1882 "unsigned int", (struct objfile *) NULL);
1884 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1886 "long", (struct objfile *) NULL);
1887 builtin_type_unsigned_long =
1888 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1890 "unsigned long", (struct objfile *) NULL);
1891 builtin_type_long_long =
1892 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1894 "long long", (struct objfile *) NULL);
1895 builtin_type_unsigned_long_long =
1896 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1898 "unsigned long long", (struct objfile *) NULL);
1899 builtin_type_float =
1900 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1902 "float", (struct objfile *) NULL);
1903 builtin_type_double =
1904 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
1906 "double", (struct objfile *) NULL);
1907 builtin_type_long_double =
1908 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
1910 "long double", (struct objfile *) NULL);
1911 builtin_type_complex =
1912 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1914 "complex", (struct objfile *) NULL);
1915 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
1916 builtin_type_double_complex =
1917 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
1919 "double complex", (struct objfile *) NULL);
1920 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
1921 builtin_type_string =
1922 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1924 "string", (struct objfile *) NULL);