1 /* Support routines for manipulating internal types for GDB.
2 Copyright (C) 1992, 1993, 1994, 1995 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 /* Alloc a new type structure and fill it with some defaults. If
58 OBJFILE is non-NULL, then allocate the space for the type structure
59 in that objfile's type_obstack. */
63 struct objfile *objfile;
65 register struct type *type;
67 /* Alloc the structure and start off with all fields zeroed. */
71 type = (struct type *) xmalloc (sizeof (struct type));
75 type = (struct type *) obstack_alloc (&objfile -> type_obstack,
76 sizeof (struct type));
77 OBJSTAT (objfile, n_types++);
79 memset ((char *) type, 0, sizeof (struct type));
81 /* Initialize the fields that might not be zero. */
83 TYPE_CODE (type) = TYPE_CODE_UNDEF;
84 TYPE_OBJFILE (type) = objfile;
85 TYPE_VPTR_FIELDNO (type) = -1;
90 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
91 to a pointer to memory where the pointer type should be stored.
92 If *TYPEPTR is zero, update it to point to the pointer type we return.
93 We allocate new memory if needed. */
96 make_pointer_type (type, typeptr)
98 struct type **typeptr;
100 register struct type *ntype; /* New type */
101 struct objfile *objfile;
103 ntype = TYPE_POINTER_TYPE (type);
107 return ntype; /* Don't care about alloc, and have new type. */
108 else if (*typeptr == 0)
110 *typeptr = ntype; /* Tracking alloc, and we have new type. */
114 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
116 ntype = alloc_type (TYPE_OBJFILE (type));
120 else /* We have storage, but need to reset it. */
123 objfile = TYPE_OBJFILE (ntype);
124 memset ((char *) ntype, 0, sizeof (struct type));
125 TYPE_OBJFILE (ntype) = objfile;
128 TYPE_TARGET_TYPE (ntype) = type;
129 TYPE_POINTER_TYPE (type) = ntype;
131 /* FIXME! Assume the machine has only one representation for pointers! */
133 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
134 TYPE_CODE (ntype) = TYPE_CODE_PTR;
136 /* pointers are unsigned */
137 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
139 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
140 TYPE_POINTER_TYPE (type) = ntype;
145 /* Given a type TYPE, return a type of pointers to that type.
146 May need to construct such a type if this is the first use. */
149 lookup_pointer_type (type)
152 return make_pointer_type (type, (struct type **)0);
155 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
156 to a pointer to memory where the reference type should be stored.
157 If *TYPEPTR is zero, update it to point to the reference type we return.
158 We allocate new memory if needed. */
161 make_reference_type (type, typeptr)
163 struct type **typeptr;
165 register struct type *ntype; /* New type */
166 struct objfile *objfile;
168 ntype = TYPE_REFERENCE_TYPE (type);
172 return ntype; /* Don't care about alloc, and have new type. */
173 else if (*typeptr == 0)
175 *typeptr = ntype; /* Tracking alloc, and we have new type. */
179 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
181 ntype = alloc_type (TYPE_OBJFILE (type));
185 else /* We have storage, but need to reset it. */
188 objfile = TYPE_OBJFILE (ntype);
189 memset ((char *) ntype, 0, sizeof (struct type));
190 TYPE_OBJFILE (ntype) = objfile;
193 TYPE_TARGET_TYPE (ntype) = type;
194 TYPE_REFERENCE_TYPE (type) = ntype;
196 /* FIXME! Assume the machine has only one representation for references,
197 and that it matches the (only) representation for pointers! */
199 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
200 TYPE_CODE (ntype) = TYPE_CODE_REF;
202 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
203 TYPE_REFERENCE_TYPE (type) = ntype;
208 /* Same as above, but caller doesn't care about memory allocation details. */
211 lookup_reference_type (type)
214 return make_reference_type (type, (struct type **)0);
217 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
218 to a pointer to memory where the function type should be stored.
219 If *TYPEPTR is zero, update it to point to the function type we return.
220 We allocate new memory if needed. */
223 make_function_type (type, typeptr)
225 struct type **typeptr;
227 register struct type *ntype; /* New type */
228 struct objfile *objfile;
230 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
232 ntype = alloc_type (TYPE_OBJFILE (type));
236 else /* We have storage, but need to reset it. */
239 objfile = TYPE_OBJFILE (ntype);
240 memset ((char *) ntype, 0, sizeof (struct type));
241 TYPE_OBJFILE (ntype) = objfile;
244 TYPE_TARGET_TYPE (ntype) = type;
246 TYPE_LENGTH (ntype) = 1;
247 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
253 /* Given a type TYPE, return a type of functions that return that type.
254 May need to construct such a type if this is the first use. */
257 lookup_function_type (type)
260 return make_function_type (type, (struct type **)0);
263 /* Implement direct support for MEMBER_TYPE in GNU C++.
264 May need to construct such a type if this is the first use.
265 The TYPE is the type of the member. The DOMAIN is the type
266 of the aggregate that the member belongs to. */
269 lookup_member_type (type, domain)
273 register struct type *mtype;
275 mtype = alloc_type (TYPE_OBJFILE (type));
276 smash_to_member_type (mtype, domain, type);
280 /* Allocate a stub method whose return type is TYPE.
281 This apparently happens for speed of symbol reading, since parsing
282 out the arguments to the method is cpu-intensive, the way we are doing
283 it. So, we will fill in arguments later.
284 This always returns a fresh type. */
287 allocate_stub_method (type)
292 mtype = alloc_type (TYPE_OBJFILE (type));
293 TYPE_TARGET_TYPE (mtype) = type;
294 /* _DOMAIN_TYPE (mtype) = unknown yet */
295 /* _ARG_TYPES (mtype) = unknown yet */
296 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
297 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
298 TYPE_LENGTH (mtype) = 1;
302 /* Create a range type using either a blank type supplied in RESULT_TYPE,
303 or creating a new type, inheriting the objfile from INDEX_TYPE.
305 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
306 HIGH_BOUND, inclusive.
308 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
309 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
312 create_range_type (result_type, index_type, low_bound, high_bound)
313 struct type *result_type;
314 struct type *index_type;
318 if (result_type == NULL)
320 result_type = alloc_type (TYPE_OBJFILE (index_type));
322 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
323 TYPE_TARGET_TYPE (result_type) = index_type;
324 if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB)
325 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
327 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
328 TYPE_NFIELDS (result_type) = 2;
329 TYPE_FIELDS (result_type) = (struct field *)
330 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
331 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
332 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
333 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
334 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
335 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
337 return (result_type);
340 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
341 Return 1 of type is a range type, 0 if it is discrete (and bounds
342 will fit in LONGEST), or -1 otherwise. */
345 get_discrete_bounds (type, lowp, highp)
347 LONGEST *lowp, *highp;
349 CHECK_TYPEDEF (type);
350 switch (TYPE_CODE (type))
352 case TYPE_CODE_RANGE:
353 *lowp = TYPE_LOW_BOUND (type);
354 *highp = TYPE_HIGH_BOUND (type);
357 if (TYPE_NFIELDS (type) > 0)
359 /* The enums may not be sorted by value, so search all
363 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
364 for (i = 0; i < TYPE_NFIELDS (type); i++)
366 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
367 *lowp = TYPE_FIELD_BITPOS (type, i);
368 if (TYPE_FIELD_BITPOS (type, i) > *highp)
369 *highp = TYPE_FIELD_BITPOS (type, i);
383 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
385 if (!TYPE_UNSIGNED (type))
387 *lowp = - (1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
391 /* ... fall through for unsigned ints ... */
394 /* This round-about calculation is to avoid shifting by
395 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
396 if TYPE_LENGTH (type) == sizeof (LONGEST). */
397 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
398 *highp = (*highp - 1) | *highp;
405 /* Create an array type using either a blank type supplied in RESULT_TYPE,
406 or creating a new type, inheriting the objfile from RANGE_TYPE.
408 Elements will be of type ELEMENT_TYPE, the indices will be of type
411 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
412 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
415 create_array_type (result_type, element_type, range_type)
416 struct type *result_type;
417 struct type *element_type;
418 struct type *range_type;
420 LONGEST low_bound, high_bound;
422 if (result_type == NULL)
424 result_type = alloc_type (TYPE_OBJFILE (range_type));
426 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
427 TYPE_TARGET_TYPE (result_type) = element_type;
428 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
429 low_bound = high_bound = 0;
430 CHECK_TYPEDEF (element_type);
431 TYPE_LENGTH (result_type) =
432 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
433 TYPE_NFIELDS (result_type) = 1;
434 TYPE_FIELDS (result_type) =
435 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
436 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
437 TYPE_FIELD_TYPE (result_type, 0) = range_type;
438 TYPE_VPTR_FIELDNO (result_type) = -1;
440 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
441 if (TYPE_LENGTH (result_type) == 0)
442 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
444 return (result_type);
447 /* Create a string type using either a blank type supplied in RESULT_TYPE,
448 or creating a new type. String types are similar enough to array of
449 char types that we can use create_array_type to build the basic type
450 and then bash it into a string type.
452 For fixed length strings, the range type contains 0 as the lower
453 bound and the length of the string minus one as the upper bound.
455 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
456 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
459 create_string_type (result_type, range_type)
460 struct type *result_type;
461 struct type *range_type;
463 result_type = create_array_type (result_type,
464 *current_language->string_char_type,
466 TYPE_CODE (result_type) = TYPE_CODE_STRING;
467 return (result_type);
471 create_set_type (result_type, domain_type)
472 struct type *result_type;
473 struct type *domain_type;
475 LONGEST low_bound, high_bound, bit_length;
476 if (result_type == NULL)
478 result_type = alloc_type (TYPE_OBJFILE (domain_type));
480 TYPE_CODE (result_type) = TYPE_CODE_SET;
481 TYPE_NFIELDS (result_type) = 1;
482 TYPE_FIELDS (result_type) = (struct field *)
483 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
484 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
486 if (! (TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB))
488 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
489 low_bound = high_bound = 0;
490 bit_length = high_bound - low_bound + 1;
491 TYPE_LENGTH (result_type)
492 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
494 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
495 return (result_type);
498 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
499 A MEMBER is a wierd thing -- it amounts to a typed offset into
500 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
501 include the offset (that's the value of the MEMBER itself), but does
502 include the structure type into which it points (for some reason).
504 When "smashing" the type, we preserve the objfile that the
505 old type pointed to, since we aren't changing where the type is actually
509 smash_to_member_type (type, domain, to_type)
512 struct type *to_type;
514 struct objfile *objfile;
516 objfile = TYPE_OBJFILE (type);
518 memset ((char *) type, 0, sizeof (struct type));
519 TYPE_OBJFILE (type) = objfile;
520 TYPE_TARGET_TYPE (type) = to_type;
521 TYPE_DOMAIN_TYPE (type) = domain;
522 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
523 TYPE_CODE (type) = TYPE_CODE_MEMBER;
526 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
527 METHOD just means `function that gets an extra "this" argument'.
529 When "smashing" the type, we preserve the objfile that the
530 old type pointed to, since we aren't changing where the type is actually
534 smash_to_method_type (type, domain, to_type, args)
537 struct type *to_type;
540 struct objfile *objfile;
542 objfile = TYPE_OBJFILE (type);
544 memset ((char *) type, 0, sizeof (struct type));
545 TYPE_OBJFILE (type) = objfile;
546 TYPE_TARGET_TYPE (type) = to_type;
547 TYPE_DOMAIN_TYPE (type) = domain;
548 TYPE_ARG_TYPES (type) = args;
549 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
550 TYPE_CODE (type) = TYPE_CODE_METHOD;
553 /* Return a typename for a struct/union/enum type without "struct ",
554 "union ", or "enum ". If the type has a NULL name, return NULL. */
557 type_name_no_tag (type)
558 register const struct type *type;
560 if (TYPE_TAG_NAME (type) != NULL)
561 return TYPE_TAG_NAME (type);
563 /* Is there code which expects this to return the name if there is no
564 tag name? My guess is that this is mainly used for C++ in cases where
565 the two will always be the same. */
566 return TYPE_NAME (type);
569 /* Lookup a primitive type named NAME.
570 Return zero if NAME is not a primitive type.*/
573 lookup_primitive_typename (name)
576 struct type ** const *p;
578 for (p = current_language -> la_builtin_type_vector; *p != NULL; p++)
580 if (STREQ ((**p) -> name, name))
588 /* Lookup a typedef or primitive type named NAME,
589 visible in lexical block BLOCK.
590 If NOERR is nonzero, return zero if NAME is not suitably defined. */
593 lookup_typename (name, block, noerr)
598 register struct symbol *sym;
599 register struct type *tmp;
601 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
602 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
604 tmp = lookup_primitive_typename (name);
609 else if (!tmp && noerr)
615 error ("No type named %s.", name);
618 return (SYMBOL_TYPE (sym));
622 lookup_unsigned_typename (name)
625 char *uns = alloca (strlen (name) + 10);
627 strcpy (uns, "unsigned ");
628 strcpy (uns + 9, name);
629 return (lookup_typename (uns, (struct block *) NULL, 0));
633 lookup_signed_typename (name)
637 char *uns = alloca (strlen (name) + 8);
639 strcpy (uns, "signed ");
640 strcpy (uns + 7, name);
641 t = lookup_typename (uns, (struct block *) NULL, 1);
642 /* If we don't find "signed FOO" just try again with plain "FOO". */
645 return lookup_typename (name, (struct block *) NULL, 0);
648 /* Lookup a structure type named "struct NAME",
649 visible in lexical block BLOCK. */
652 lookup_struct (name, block)
656 register struct symbol *sym;
658 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
659 (struct symtab **) NULL);
663 error ("No struct type named %s.", name);
665 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
667 error ("This context has class, union or enum %s, not a struct.", name);
669 return (SYMBOL_TYPE (sym));
672 /* Lookup a union type named "union NAME",
673 visible in lexical block BLOCK. */
676 lookup_union (name, block)
680 register struct symbol *sym;
682 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
683 (struct symtab **) NULL);
687 error ("No union type named %s.", name);
689 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
691 error ("This context has class, struct or enum %s, not a union.", name);
693 return (SYMBOL_TYPE (sym));
696 /* Lookup an enum type named "enum NAME",
697 visible in lexical block BLOCK. */
700 lookup_enum (name, block)
704 register struct symbol *sym;
706 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
707 (struct symtab **) NULL);
710 error ("No enum type named %s.", name);
712 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
714 error ("This context has class, struct or union %s, not an enum.", name);
716 return (SYMBOL_TYPE (sym));
719 /* Lookup a template type named "template NAME<TYPE>",
720 visible in lexical block BLOCK. */
723 lookup_template_type (name, type, block)
729 char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4);
732 strcat (nam, type->name);
733 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
735 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
739 error ("No template type named %s.", name);
741 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
743 error ("This context has class, union or enum %s, not a struct.", name);
745 return (SYMBOL_TYPE (sym));
748 /* Given a type TYPE, lookup the type of the component of type named NAME.
750 TYPE can be either a struct or union, or a pointer or reference to a struct or
751 union. If it is a pointer or reference, its target type is automatically used.
752 Thus '.' and '->' are interchangable, as specified for the definitions of the
753 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
755 If NOERR is nonzero, return zero if NAME is not suitably defined.
756 If NAME is the name of a baseclass type, return that type. */
759 lookup_struct_elt_type (type, name, noerr)
768 CHECK_TYPEDEF (type);
769 if (TYPE_CODE (type) != TYPE_CODE_PTR
770 && TYPE_CODE (type) != TYPE_CODE_REF)
772 type = TYPE_TARGET_TYPE (type);
775 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
776 TYPE_CODE (type) != TYPE_CODE_UNION)
778 target_terminal_ours ();
779 gdb_flush (gdb_stdout);
780 fprintf_unfiltered (gdb_stderr, "Type ");
781 type_print (type, "", gdb_stderr, -1);
782 error (" is not a structure or union type.");
786 /* FIXME: This change put in by Michael seems incorrect for the case where
787 the structure tag name is the same as the member name. I.E. when doing
788 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
793 typename = type_name_no_tag (type);
794 if (typename != NULL && STREQ (typename, name))
799 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
801 char *t_field_name = TYPE_FIELD_NAME (type, i);
803 if (t_field_name && STREQ (t_field_name, name))
805 return TYPE_FIELD_TYPE (type, i);
809 /* OK, it's not in this class. Recursively check the baseclasses. */
810 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
814 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
826 target_terminal_ours ();
827 gdb_flush (gdb_stdout);
828 fprintf_unfiltered (gdb_stderr, "Type ");
829 type_print (type, "", gdb_stderr, -1);
830 fprintf_unfiltered (gdb_stderr, " has no component named ");
831 fputs_filtered (name, gdb_stderr);
833 return (struct type *)-1; /* For lint */
836 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
837 valid. Callers should be aware that in some cases (for example,
838 the type or one of its baseclasses is a stub type and we are
839 debugging a .o file), this function will not be able to find the virtual
840 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
844 fill_in_vptr_fieldno (type)
847 CHECK_TYPEDEF (type);
849 if (TYPE_VPTR_FIELDNO (type) < 0)
853 /* We must start at zero in case the first (and only) baseclass is
854 virtual (and hence we cannot share the table pointer). */
855 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
857 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
858 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
860 TYPE_VPTR_FIELDNO (type)
861 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
862 TYPE_VPTR_BASETYPE (type)
863 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
870 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
872 If this is a stubbed struct (i.e. declared as struct foo *), see if
873 we can find a full definition in some other file. If so, copy this
874 definition, so we can use it in future. There used to be a comment (but
875 not any code) that if we don't find a full definition, we'd set a flag
876 so we don't spend time in the future checking the same type. That would
877 be a mistake, though--we might load in more symbols which contain a
878 full definition for the type.
880 This used to be coded as a macro, but I don't think it is called
881 often enough to merit such treatment. */
883 struct complaint stub_noname_complaint =
884 {"stub type has NULL name", 0, 0};
888 register struct type *type;
890 struct type *orig_type = type;
891 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
893 if (!TYPE_TARGET_TYPE (type))
898 /* It is dangerous to call lookup_symbol if we are currently
899 reading a symtab. Infinite recursion is one danger. */
900 if (currently_reading_symtab)
903 name = type_name_no_tag (type);
904 /* FIXME: shouldn't we separately check the TYPE_NAME and the
905 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
906 as appropriate? (this code was written before TYPE_NAME and
907 TYPE_TAG_NAME were separate). */
910 complain (&stub_noname_complaint);
913 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
914 (struct symtab **) NULL);
916 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
918 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
920 type = TYPE_TARGET_TYPE (type);
923 if ((TYPE_FLAGS(type) & TYPE_FLAG_STUB) && ! currently_reading_symtab)
925 char* name = type_name_no_tag (type);
926 /* FIXME: shouldn't we separately check the TYPE_NAME and the
927 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
928 as appropriate? (this code was written before TYPE_NAME and
929 TYPE_TAG_NAME were separate). */
933 complain (&stub_noname_complaint);
936 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
937 (struct symtab **) NULL);
940 memcpy ((char *)type,
941 (char *)SYMBOL_TYPE(sym),
942 sizeof (struct type));
946 if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB)
948 struct type *range_type;
949 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
951 if (TYPE_FLAGS (target_type) & TYPE_FLAG_STUB)
953 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
954 && TYPE_NFIELDS (type) == 1
955 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
958 /* Now recompute the length of the array type, based on its
959 number of elements and the target type's length. */
961 ((TYPE_FIELD_BITPOS (range_type, 1)
962 - TYPE_FIELD_BITPOS (range_type, 0)
964 * TYPE_LENGTH (target_type));
965 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
967 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
969 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
970 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
973 /* Cache TYPE_LENGTH for future use. */
974 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
978 /* New code added to support parsing of Cfront stabs strings */
980 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
981 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
982 struct extra { char str[128]; int len; }; /* maximum extention is 128! FIXME */
985 struct extra * pextras;
988 char lenstr[512]; /* FIXME! hardcoded :-( */
990 if ((nlen = (n ? strlen(n) : 0))==0)
992 sprintf(pextras->str+pextras->len,"%d%s",nlen,n);
993 pextras->len=strlen(pextras->str);
997 add_mangled_type(pextras,t)
998 struct extra * pextras;
1001 enum type_code tcode;
1005 tcode = TYPE_CODE(t);
1006 tlen = TYPE_LENGTH(t);
1007 tflags = TYPE_FLAGS(t);
1008 tname = TYPE_NAME(t);
1009 /* args of "..." seem to get mangled as "e" */
1027 if ((pname=strrchr(tname,'l'),pname) && !strcmp(pname,"long"))
1036 static struct complaint msg = {"Bad int type code length x%x\n",0,0};
1038 complain (&msg, tlen);
1057 static struct complaint msg = {"Bad float type code length x%x\n",0,0};
1058 complain (&msg, tlen);
1064 /* followed by what it's a ref to */
1068 /* followed by what it's a ptr to */
1070 case TYPE_CODE_TYPEDEF:
1072 static struct complaint msg = {"Typedefs in overloaded functions not yet supported\n",0,0};
1075 /* followed by type bytes & name */
1077 case TYPE_CODE_FUNC:
1079 /* followed by func's arg '_' & ret types */
1081 case TYPE_CODE_VOID:
1084 case TYPE_CODE_METHOD:
1086 /* followed by name of class and func's arg '_' & ret types */
1087 add_name(pextras,tname);
1088 ADD_EXTRA('F'); /* then mangle function */
1090 case TYPE_CODE_STRUCT: /* C struct */
1091 case TYPE_CODE_UNION: /* C union */
1092 case TYPE_CODE_ENUM: /* Enumeration type */
1093 /* followed by name of type */
1094 add_name(pextras,tname);
1097 /* errors possible types/not supported */
1098 case TYPE_CODE_CHAR:
1099 case TYPE_CODE_ARRAY: /* Array type */
1100 case TYPE_CODE_MEMBER: /* Member type */
1101 case TYPE_CODE_BOOL:
1102 case TYPE_CODE_COMPLEX: /* Complex float */
1103 case TYPE_CODE_UNDEF:
1104 case TYPE_CODE_SET: /* Pascal sets */
1105 case TYPE_CODE_RANGE:
1106 case TYPE_CODE_STRING:
1107 case TYPE_CODE_BITSTRING:
1108 case TYPE_CODE_ERROR:
1111 static struct complaint msg = {"Unknown type code x%x\n",0,0};
1112 complain (&msg, tcode);
1116 add_mangled_type(pextras,t->target_type);
1120 cfront_mangle_name(type, i, j)
1126 char *mangled_name = gdb_mangle_name (type, i, j);
1128 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1130 /* kludge to support cfront methods - gdb expects to find "F" for
1131 ARM_mangled names, so when we mangle, we have to add it here */
1135 char * arm_mangled_name;
1136 struct fn_field *method = &f[j];
1137 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1138 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1139 char *newname = type_name_no_tag (type);
1141 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1142 int nargs = TYPE_NFIELDS(ftype); /* number of args */
1143 struct extra extras, * pextras = &extras;
1146 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1149 /* add args here! */
1150 if (nargs <= 1) /* no args besides this */
1153 for (k=1; k<nargs; k++)
1156 t = TYPE_FIELD_TYPE(ftype,k);
1157 add_mangled_type(pextras,t);
1161 printf("add_mangled_type: %s\n",extras.str); /* FIXME */
1162 arm_mangled_name = malloc(strlen(mangled_name)+extras.len);
1163 sprintf(arm_mangled_name,"%s%s",mangled_name,extras.str);
1165 mangled_name = arm_mangled_name;
1169 /* End of new code added to support parsing of Cfront stabs strings */
1171 /* Ugly hack to convert method stubs into method types.
1173 He ain't kiddin'. This demangles the name of the method into a string
1174 including argument types, parses out each argument type, generates
1175 a string casting a zero to that type, evaluates the string, and stuffs
1176 the resulting type into an argtype vector!!! Then it knows the type
1177 of the whole function (including argument types for overloading),
1178 which info used to be in the stab's but was removed to hack back
1179 the space required for them. */
1182 check_stub_method (type, i, j)
1188 char *mangled_name = gdb_mangle_name (type, i, j);
1189 char *demangled_name = cplus_demangle (mangled_name,
1190 DMGL_PARAMS | DMGL_ANSI);
1191 char *argtypetext, *p;
1192 int depth = 0, argcount = 1;
1193 struct type **argtypes;
1196 /* Make sure we got back a function string that we can use. */
1198 p = strchr (demangled_name, '(');
1200 if (demangled_name == NULL || p == NULL)
1201 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1203 /* Now, read in the parameters that define this type. */
1216 else if (*p == ',' && depth == 0)
1224 /* We need two more slots: one for the THIS pointer, and one for the
1225 NULL [...] or void [end of arglist]. */
1227 argtypes = (struct type **)
1228 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
1230 /* FIXME: This is wrong for static member functions. */
1231 argtypes[0] = lookup_pointer_type (type);
1234 if (*p != ')') /* () means no args, skip while */
1239 if (depth <= 0 && (*p == ',' || *p == ')'))
1241 /* Avoid parsing of ellipsis, they will be handled below. */
1242 if (strncmp (argtypetext, "...", p - argtypetext) != 0)
1244 argtypes[argcount] =
1245 parse_and_eval_type (argtypetext, p - argtypetext);
1248 argtypetext = p + 1;
1264 if (p[-2] != '.') /* Not '...' */
1266 argtypes[argcount] = builtin_type_void; /* List terminator */
1270 argtypes[argcount] = NULL; /* Ellist terminator */
1273 free (demangled_name);
1275 f = TYPE_FN_FIELDLIST1 (type, i);
1277 TYPE_FN_FIELD_PHYSNAME (f, j) = mangled_name;
1279 /* Now update the old "stub" type into a real type. */
1280 mtype = TYPE_FN_FIELD_TYPE (f, j);
1281 TYPE_DOMAIN_TYPE (mtype) = type;
1282 TYPE_ARG_TYPES (mtype) = argtypes;
1283 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1284 TYPE_FN_FIELD_STUB (f, j) = 0;
1287 const struct cplus_struct_type cplus_struct_default;
1290 allocate_cplus_struct_type (type)
1293 if (!HAVE_CPLUS_STRUCT (type))
1295 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1296 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1297 *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default;
1301 /* Helper function to initialize the standard scalar types.
1303 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1304 of the string pointed to by name in the type_obstack for that objfile,
1305 and initialize the type name to that copy. There are places (mipsread.c
1306 in particular, where init_type is called with a NULL value for NAME). */
1309 init_type (code, length, flags, name, objfile)
1310 enum type_code code;
1314 struct objfile *objfile;
1316 register struct type *type;
1318 type = alloc_type (objfile);
1319 TYPE_CODE (type) = code;
1320 TYPE_LENGTH (type) = length;
1321 TYPE_FLAGS (type) |= flags;
1322 if ((name != NULL) && (objfile != NULL))
1325 obsavestring (name, strlen (name), &objfile -> type_obstack);
1329 TYPE_NAME (type) = name;
1334 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1336 INIT_CPLUS_SPECIFIC (type);
1341 /* Look up a fundamental type for the specified objfile.
1342 May need to construct such a type if this is the first use.
1344 Some object file formats (ELF, COFF, etc) do not define fundamental
1345 types such as "int" or "double". Others (stabs for example), do
1346 define fundamental types.
1348 For the formats which don't provide fundamental types, gdb can create
1349 such types, using defaults reasonable for the current language and
1350 the current target machine.
1352 NOTE: This routine is obsolescent. Each debugging format reader
1353 should manage it's own fundamental types, either creating them from
1354 suitable defaults or reading them from the debugging information,
1355 whichever is appropriate. The DWARF reader has already been
1356 fixed to do this. Once the other readers are fixed, this routine
1357 will go away. Also note that fundamental types should be managed
1358 on a compilation unit basis in a multi-language environment, not
1359 on a linkage unit basis as is done here. */
1363 lookup_fundamental_type (objfile, typeid)
1364 struct objfile *objfile;
1367 register struct type **typep;
1368 register int nbytes;
1370 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1372 error ("internal error - invalid fundamental type id %d", typeid);
1375 /* If this is the first time we need a fundamental type for this objfile
1376 then we need to initialize the vector of type pointers. */
1378 if (objfile -> fundamental_types == NULL)
1380 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1381 objfile -> fundamental_types = (struct type **)
1382 obstack_alloc (&objfile -> type_obstack, nbytes);
1383 memset ((char *) objfile -> fundamental_types, 0, nbytes);
1384 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1387 /* Look for this particular type in the fundamental type vector. If one is
1388 not found, create and install one appropriate for the current language. */
1390 typep = objfile -> fundamental_types + typeid;
1393 *typep = create_fundamental_type (objfile, typeid);
1403 /* FIXME: Should we return true for references as well as pointers? */
1407 && TYPE_CODE (t) == TYPE_CODE_PTR
1408 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1411 /* Chill varying string and arrays are represented as follows:
1413 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1415 Return true if TYPE is such a Chill varying type. */
1418 chill_varying_type (type)
1421 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1422 || TYPE_NFIELDS (type) != 2
1423 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1428 #if MAINTENANCE_CMDS
1431 print_bit_vector (bits, nbits)
1437 for (bitno = 0; bitno < nbits; bitno++)
1439 if ((bitno % 8) == 0)
1441 puts_filtered (" ");
1443 if (B_TST (bits, bitno))
1445 printf_filtered ("1");
1449 printf_filtered ("0");
1454 /* The args list is a strange beast. It is either terminated by a NULL
1455 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
1456 type for normal fixed argcount functions. (FIXME someday)
1457 Also note the first arg should be the "this" pointer, we may not want to
1458 include it since we may get into a infinitely recursive situation. */
1461 print_arg_types (args, spaces)
1467 while (*args != NULL)
1469 recursive_dump_type (*args, spaces + 2);
1470 if ((*args++) -> code == TYPE_CODE_VOID)
1479 dump_fn_fieldlists (type, spaces)
1487 printfi_filtered (spaces, "fn_fieldlists ");
1488 gdb_print_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
1489 printf_filtered ("\n");
1490 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
1492 f = TYPE_FN_FIELDLIST1 (type, method_idx);
1493 printfi_filtered (spaces + 2, "[%d] name '%s' (",
1495 TYPE_FN_FIELDLIST_NAME (type, method_idx));
1496 gdb_print_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
1498 printf_filtered (") length %d\n",
1499 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
1500 for (overload_idx = 0;
1501 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
1504 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
1506 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
1507 gdb_print_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
1509 printf_filtered (")\n");
1510 printfi_filtered (spaces + 8, "type ");
1511 gdb_print_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
1512 printf_filtered ("\n");
1514 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
1517 printfi_filtered (spaces + 8, "args ");
1518 gdb_print_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
1519 printf_filtered ("\n");
1521 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
1522 printfi_filtered (spaces + 8, "fcontext ");
1523 gdb_print_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
1525 printf_filtered ("\n");
1527 printfi_filtered (spaces + 8, "is_const %d\n",
1528 TYPE_FN_FIELD_CONST (f, overload_idx));
1529 printfi_filtered (spaces + 8, "is_volatile %d\n",
1530 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
1531 printfi_filtered (spaces + 8, "is_private %d\n",
1532 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
1533 printfi_filtered (spaces + 8, "is_protected %d\n",
1534 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
1535 printfi_filtered (spaces + 8, "is_stub %d\n",
1536 TYPE_FN_FIELD_STUB (f, overload_idx));
1537 printfi_filtered (spaces + 8, "voffset %u\n",
1538 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
1544 print_cplus_stuff (type, spaces)
1548 printfi_filtered (spaces, "n_baseclasses %d\n",
1549 TYPE_N_BASECLASSES (type));
1550 printfi_filtered (spaces, "nfn_fields %d\n",
1551 TYPE_NFN_FIELDS (type));
1552 printfi_filtered (spaces, "nfn_fields_total %d\n",
1553 TYPE_NFN_FIELDS_TOTAL (type));
1554 if (TYPE_N_BASECLASSES (type) > 0)
1556 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
1557 TYPE_N_BASECLASSES (type));
1558 gdb_print_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
1559 printf_filtered (")");
1561 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
1562 TYPE_N_BASECLASSES (type));
1563 puts_filtered ("\n");
1565 if (TYPE_NFIELDS (type) > 0)
1567 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
1569 printfi_filtered (spaces, "private_field_bits (%d bits at *",
1570 TYPE_NFIELDS (type));
1571 gdb_print_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
1572 printf_filtered (")");
1573 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
1574 TYPE_NFIELDS (type));
1575 puts_filtered ("\n");
1577 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
1579 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
1580 TYPE_NFIELDS (type));
1581 gdb_print_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
1582 printf_filtered (")");
1583 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
1584 TYPE_NFIELDS (type));
1585 puts_filtered ("\n");
1588 if (TYPE_NFN_FIELDS (type) > 0)
1590 dump_fn_fieldlists (type, spaces);
1594 static struct obstack dont_print_type_obstack;
1597 recursive_dump_type (type, spaces)
1604 obstack_begin (&dont_print_type_obstack, 0);
1606 if (TYPE_NFIELDS (type) > 0
1607 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
1609 struct type **first_dont_print
1610 = (struct type **)obstack_base (&dont_print_type_obstack);
1612 int i = (struct type **)obstack_next_free (&dont_print_type_obstack)
1617 if (type == first_dont_print[i])
1619 printfi_filtered (spaces, "type node ");
1620 gdb_print_address (type, gdb_stdout);
1621 printf_filtered (" <same as already seen type>\n");
1626 obstack_ptr_grow (&dont_print_type_obstack, type);
1629 printfi_filtered (spaces, "type node ");
1630 gdb_print_address (type, gdb_stdout);
1631 printf_filtered ("\n");
1632 printfi_filtered (spaces, "name '%s' (",
1633 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
1634 gdb_print_address (TYPE_NAME (type), gdb_stdout);
1635 printf_filtered (")\n");
1636 if (TYPE_TAG_NAME (type) != NULL)
1638 printfi_filtered (spaces, "tagname '%s' (",
1639 TYPE_TAG_NAME (type));
1640 gdb_print_address (TYPE_TAG_NAME (type), gdb_stdout);
1641 printf_filtered (")\n");
1643 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
1644 switch (TYPE_CODE (type))
1646 case TYPE_CODE_UNDEF:
1647 printf_filtered ("(TYPE_CODE_UNDEF)");
1650 printf_filtered ("(TYPE_CODE_PTR)");
1652 case TYPE_CODE_ARRAY:
1653 printf_filtered ("(TYPE_CODE_ARRAY)");
1655 case TYPE_CODE_STRUCT:
1656 printf_filtered ("(TYPE_CODE_STRUCT)");
1658 case TYPE_CODE_UNION:
1659 printf_filtered ("(TYPE_CODE_UNION)");
1661 case TYPE_CODE_ENUM:
1662 printf_filtered ("(TYPE_CODE_ENUM)");
1664 case TYPE_CODE_FUNC:
1665 printf_filtered ("(TYPE_CODE_FUNC)");
1668 printf_filtered ("(TYPE_CODE_INT)");
1671 printf_filtered ("(TYPE_CODE_FLT)");
1673 case TYPE_CODE_VOID:
1674 printf_filtered ("(TYPE_CODE_VOID)");
1677 printf_filtered ("(TYPE_CODE_SET)");
1679 case TYPE_CODE_RANGE:
1680 printf_filtered ("(TYPE_CODE_RANGE)");
1682 case TYPE_CODE_STRING:
1683 printf_filtered ("(TYPE_CODE_STRING)");
1685 case TYPE_CODE_ERROR:
1686 printf_filtered ("(TYPE_CODE_ERROR)");
1688 case TYPE_CODE_MEMBER:
1689 printf_filtered ("(TYPE_CODE_MEMBER)");
1691 case TYPE_CODE_METHOD:
1692 printf_filtered ("(TYPE_CODE_METHOD)");
1695 printf_filtered ("(TYPE_CODE_REF)");
1697 case TYPE_CODE_CHAR:
1698 printf_filtered ("(TYPE_CODE_CHAR)");
1700 case TYPE_CODE_BOOL:
1701 printf_filtered ("(TYPE_CODE_BOOL)");
1703 case TYPE_CODE_TYPEDEF:
1704 printf_filtered ("(TYPE_CODE_TYPEDEF)");
1707 printf_filtered ("(UNKNOWN TYPE CODE)");
1710 puts_filtered ("\n");
1711 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
1712 printfi_filtered (spaces, "objfile ");
1713 gdb_print_address (TYPE_OBJFILE (type), gdb_stdout);
1714 printf_filtered ("\n");
1715 printfi_filtered (spaces, "target_type ");
1716 gdb_print_address (TYPE_TARGET_TYPE (type), gdb_stdout);
1717 printf_filtered ("\n");
1718 if (TYPE_TARGET_TYPE (type) != NULL)
1720 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
1722 printfi_filtered (spaces, "pointer_type ");
1723 gdb_print_address (TYPE_POINTER_TYPE (type), gdb_stdout);
1724 printf_filtered ("\n");
1725 printfi_filtered (spaces, "reference_type ");
1726 gdb_print_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
1727 printf_filtered ("\n");
1728 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
1729 if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED)
1731 puts_filtered (" TYPE_FLAG_UNSIGNED");
1733 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1735 puts_filtered (" TYPE_FLAG_STUB");
1737 puts_filtered ("\n");
1738 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
1739 gdb_print_address (TYPE_FIELDS (type), gdb_stdout);
1740 puts_filtered ("\n");
1741 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
1743 printfi_filtered (spaces + 2,
1744 "[%d] bitpos %d bitsize %d type ",
1745 idx, TYPE_FIELD_BITPOS (type, idx),
1746 TYPE_FIELD_BITSIZE (type, idx));
1747 gdb_print_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
1748 printf_filtered (" name '%s' (",
1749 TYPE_FIELD_NAME (type, idx) != NULL
1750 ? TYPE_FIELD_NAME (type, idx)
1752 gdb_print_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
1753 printf_filtered (")\n");
1754 if (TYPE_FIELD_TYPE (type, idx) != NULL)
1756 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
1759 printfi_filtered (spaces, "vptr_basetype ");
1760 gdb_print_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
1761 puts_filtered ("\n");
1762 if (TYPE_VPTR_BASETYPE (type) != NULL)
1764 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
1766 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
1767 switch (TYPE_CODE (type))
1769 case TYPE_CODE_METHOD:
1770 case TYPE_CODE_FUNC:
1771 printfi_filtered (spaces, "arg_types ");
1772 gdb_print_address (TYPE_ARG_TYPES (type), gdb_stdout);
1773 puts_filtered ("\n");
1774 print_arg_types (TYPE_ARG_TYPES (type), spaces);
1777 case TYPE_CODE_STRUCT:
1778 printfi_filtered (spaces, "cplus_stuff ");
1779 gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
1780 puts_filtered ("\n");
1781 print_cplus_stuff (type, spaces);
1785 /* We have to pick one of the union types to be able print and test
1786 the value. Pick cplus_struct_type, even though we know it isn't
1787 any particular one. */
1788 printfi_filtered (spaces, "type_specific ");
1789 gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
1790 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
1792 printf_filtered (" (unknown data form)");
1794 printf_filtered ("\n");
1799 obstack_free (&dont_print_type_obstack, NULL);
1802 #endif /* MAINTENANCE_CMDS */
1805 _initialize_gdbtypes ()
1808 init_type (TYPE_CODE_VOID, 1,
1810 "void", (struct objfile *) NULL);
1812 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1814 "char", (struct objfile *) NULL);
1815 builtin_type_signed_char =
1816 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1818 "signed char", (struct objfile *) NULL);
1819 builtin_type_unsigned_char =
1820 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1822 "unsigned char", (struct objfile *) NULL);
1823 builtin_type_short =
1824 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1826 "short", (struct objfile *) NULL);
1827 builtin_type_unsigned_short =
1828 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1830 "unsigned short", (struct objfile *) NULL);
1832 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1834 "int", (struct objfile *) NULL);
1835 builtin_type_unsigned_int =
1836 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1838 "unsigned int", (struct objfile *) NULL);
1840 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1842 "long", (struct objfile *) NULL);
1843 builtin_type_unsigned_long =
1844 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1846 "unsigned long", (struct objfile *) NULL);
1847 builtin_type_long_long =
1848 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1850 "long long", (struct objfile *) NULL);
1851 builtin_type_unsigned_long_long =
1852 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1854 "unsigned long long", (struct objfile *) NULL);
1855 builtin_type_float =
1856 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1858 "float", (struct objfile *) NULL);
1859 builtin_type_double =
1860 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
1862 "double", (struct objfile *) NULL);
1863 builtin_type_long_double =
1864 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
1866 "long double", (struct objfile *) NULL);
1867 builtin_type_complex =
1868 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1870 "complex", (struct objfile *) NULL);
1871 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
1872 builtin_type_double_complex =
1873 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
1875 "double complex", (struct objfile *) NULL);
1876 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
1877 builtin_type_string =
1878 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1880 "string", (struct objfile *) NULL);