1 /* Support routines for manipulating internal types for GDB.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support, using pieces from other GDB modules.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
30 #include "expression.h"
35 #include "complaints.h"
39 #include "gdb_assert.h"
41 /* These variables point to the objects
42 representing the predefined C data types. */
44 struct type *builtin_type_void;
45 struct type *builtin_type_char;
46 struct type *builtin_type_true_char;
47 struct type *builtin_type_short;
48 struct type *builtin_type_int;
49 struct type *builtin_type_long;
50 struct type *builtin_type_long_long;
51 struct type *builtin_type_signed_char;
52 struct type *builtin_type_unsigned_char;
53 struct type *builtin_type_unsigned_short;
54 struct type *builtin_type_unsigned_int;
55 struct type *builtin_type_unsigned_long;
56 struct type *builtin_type_unsigned_long_long;
57 struct type *builtin_type_float;
58 struct type *builtin_type_double;
59 struct type *builtin_type_long_double;
60 struct type *builtin_type_complex;
61 struct type *builtin_type_double_complex;
62 struct type *builtin_type_string;
63 struct type *builtin_type_int8;
64 struct type *builtin_type_uint8;
65 struct type *builtin_type_int16;
66 struct type *builtin_type_uint16;
67 struct type *builtin_type_int32;
68 struct type *builtin_type_uint32;
69 struct type *builtin_type_int64;
70 struct type *builtin_type_uint64;
71 struct type *builtin_type_int128;
72 struct type *builtin_type_uint128;
73 struct type *builtin_type_bool;
75 /* 128 bit long vector types */
76 struct type *builtin_type_v2_double;
77 struct type *builtin_type_v4_float;
78 struct type *builtin_type_v2_int64;
79 struct type *builtin_type_v4_int32;
80 struct type *builtin_type_v8_int16;
81 struct type *builtin_type_v16_int8;
82 /* 64 bit long vector types */
83 struct type *builtin_type_v2_float;
84 struct type *builtin_type_v2_int32;
85 struct type *builtin_type_v4_int16;
86 struct type *builtin_type_v8_int8;
88 struct type *builtin_type_v4sf;
89 struct type *builtin_type_v4si;
90 struct type *builtin_type_v16qi;
91 struct type *builtin_type_v8qi;
92 struct type *builtin_type_v8hi;
93 struct type *builtin_type_v4hi;
94 struct type *builtin_type_v2si;
95 struct type *builtin_type_vec128;
96 struct type *builtin_type_vec128i;
97 struct type *builtin_type_ieee_single_big;
98 struct type *builtin_type_ieee_single_little;
99 struct type *builtin_type_ieee_double_big;
100 struct type *builtin_type_ieee_double_little;
101 struct type *builtin_type_ieee_double_littlebyte_bigword;
102 struct type *builtin_type_i387_ext;
103 struct type *builtin_type_m68881_ext;
104 struct type *builtin_type_i960_ext;
105 struct type *builtin_type_m88110_ext;
106 struct type *builtin_type_m88110_harris_ext;
107 struct type *builtin_type_arm_ext_big;
108 struct type *builtin_type_arm_ext_littlebyte_bigword;
109 struct type *builtin_type_ia64_spill_big;
110 struct type *builtin_type_ia64_spill_little;
111 struct type *builtin_type_ia64_quad_big;
112 struct type *builtin_type_ia64_quad_little;
113 struct type *builtin_type_void_data_ptr;
114 struct type *builtin_type_void_func_ptr;
115 struct type *builtin_type_CORE_ADDR;
116 struct type *builtin_type_bfd_vma;
118 int opaque_type_resolution = 1;
119 int overload_debug = 0;
125 }; /* maximum extension is 128! FIXME */
127 static void add_name (struct extra *, char *);
128 static void add_mangled_type (struct extra *, struct type *);
130 static void cfront_mangle_name (struct type *, int, int);
132 static void print_bit_vector (B_TYPE *, int);
133 static void print_arg_types (struct field *, int, int);
134 static void dump_fn_fieldlists (struct type *, int);
135 static void print_cplus_stuff (struct type *, int);
136 static void virtual_base_list_aux (struct type *dclass);
139 /* Alloc a new type structure and fill it with some defaults. If
140 OBJFILE is non-NULL, then allocate the space for the type structure
141 in that objfile's type_obstack. Otherwise allocate the new type structure
142 by xmalloc () (for permanent types). */
145 alloc_type (struct objfile *objfile)
147 register struct type *type;
149 /* Alloc the structure and start off with all fields zeroed. */
153 type = xmalloc (sizeof (struct type));
154 memset (type, 0, sizeof (struct type));
155 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
159 type = obstack_alloc (&objfile->type_obstack,
160 sizeof (struct type));
161 memset (type, 0, sizeof (struct type));
162 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->type_obstack,
163 sizeof (struct main_type));
164 OBJSTAT (objfile, n_types++);
166 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
168 /* Initialize the fields that might not be zero. */
170 TYPE_CODE (type) = TYPE_CODE_UNDEF;
171 TYPE_OBJFILE (type) = objfile;
172 TYPE_VPTR_FIELDNO (type) = -1;
173 TYPE_CHAIN (type) = type; /* Chain back to itself. */
178 /* Alloc a new type instance structure, fill it with some defaults,
179 and point it at OLDTYPE. Allocate the new type instance from the
180 same place as OLDTYPE. */
183 alloc_type_instance (struct type *oldtype)
187 /* Allocate the structure. */
189 if (TYPE_OBJFILE (oldtype) == NULL)
191 type = xmalloc (sizeof (struct type));
192 memset (type, 0, sizeof (struct type));
196 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->type_obstack,
197 sizeof (struct type));
198 memset (type, 0, sizeof (struct type));
200 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
202 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
207 /* Clear all remnants of the previous type at TYPE, in preparation for
208 replacing it with something else. */
210 smash_type (struct type *type)
212 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
214 /* For now, delete the rings. */
215 TYPE_CHAIN (type) = type;
217 /* For now, leave the pointer/reference types alone. */
220 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
221 to a pointer to memory where the pointer type should be stored.
222 If *TYPEPTR is zero, update it to point to the pointer type we return.
223 We allocate new memory if needed. */
226 make_pointer_type (struct type *type, struct type **typeptr)
228 register struct type *ntype; /* New type */
229 struct objfile *objfile;
231 ntype = TYPE_POINTER_TYPE (type);
236 return ntype; /* Don't care about alloc, and have new type. */
237 else if (*typeptr == 0)
239 *typeptr = ntype; /* Tracking alloc, and we have new type. */
244 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
246 ntype = alloc_type (TYPE_OBJFILE (type));
251 /* We have storage, but need to reset it. */
254 objfile = TYPE_OBJFILE (ntype);
256 TYPE_OBJFILE (ntype) = objfile;
259 TYPE_TARGET_TYPE (ntype) = type;
260 TYPE_POINTER_TYPE (type) = ntype;
262 /* FIXME! Assume the machine has only one representation for pointers! */
264 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
265 TYPE_CODE (ntype) = TYPE_CODE_PTR;
267 /* Mark pointers as unsigned. The target converts between pointers
268 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
269 ADDRESS_TO_POINTER(). */
270 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
272 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
273 TYPE_POINTER_TYPE (type) = ntype;
278 /* Given a type TYPE, return a type of pointers to that type.
279 May need to construct such a type if this is the first use. */
282 lookup_pointer_type (struct type *type)
284 return make_pointer_type (type, (struct type **) 0);
287 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
288 to a pointer to memory where the reference type should be stored.
289 If *TYPEPTR is zero, update it to point to the reference type we return.
290 We allocate new memory if needed. */
293 make_reference_type (struct type *type, struct type **typeptr)
295 register struct type *ntype; /* New type */
296 struct objfile *objfile;
298 ntype = TYPE_REFERENCE_TYPE (type);
303 return ntype; /* Don't care about alloc, and have new type. */
304 else if (*typeptr == 0)
306 *typeptr = ntype; /* Tracking alloc, and we have new type. */
311 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
313 ntype = alloc_type (TYPE_OBJFILE (type));
318 /* We have storage, but need to reset it. */
321 objfile = TYPE_OBJFILE (ntype);
323 TYPE_OBJFILE (ntype) = objfile;
326 TYPE_TARGET_TYPE (ntype) = type;
327 TYPE_REFERENCE_TYPE (type) = ntype;
329 /* FIXME! Assume the machine has only one representation for references,
330 and that it matches the (only) representation for pointers! */
332 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
333 TYPE_CODE (ntype) = TYPE_CODE_REF;
335 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
336 TYPE_REFERENCE_TYPE (type) = ntype;
341 /* Same as above, but caller doesn't care about memory allocation details. */
344 lookup_reference_type (struct type *type)
346 return make_reference_type (type, (struct type **) 0);
349 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
350 to a pointer to memory where the function type should be stored.
351 If *TYPEPTR is zero, update it to point to the function type we return.
352 We allocate new memory if needed. */
355 make_function_type (struct type *type, struct type **typeptr)
357 register struct type *ntype; /* New type */
358 struct objfile *objfile;
360 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
362 ntype = alloc_type (TYPE_OBJFILE (type));
367 /* We have storage, but need to reset it. */
370 objfile = TYPE_OBJFILE (ntype);
372 TYPE_OBJFILE (ntype) = objfile;
375 TYPE_TARGET_TYPE (ntype) = type;
377 TYPE_LENGTH (ntype) = 1;
378 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
384 /* Given a type TYPE, return a type of functions that return that type.
385 May need to construct such a type if this is the first use. */
388 lookup_function_type (struct type *type)
390 return make_function_type (type, (struct type **) 0);
393 /* Identify address space identifier by name --
394 return the integer flag defined in gdbtypes.h. */
396 address_space_name_to_int (char *space_identifier)
398 /* Check for known address space delimiters. */
399 if (!strcmp (space_identifier, "code"))
400 return TYPE_FLAG_CODE_SPACE;
401 else if (!strcmp (space_identifier, "data"))
402 return TYPE_FLAG_DATA_SPACE;
404 error ("Unknown address space specifier: \"%s\"", space_identifier);
407 /* Identify address space identifier by integer flag as defined in
408 gdbtypes.h -- return the string version of the adress space name. */
411 address_space_int_to_name (int space_flag)
413 if (space_flag & TYPE_FLAG_CODE_SPACE)
415 else if (space_flag & TYPE_FLAG_DATA_SPACE)
421 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
422 If STORAGE is non-NULL, create the new type instance there. */
425 make_qualified_type (struct type *type, int new_flags,
426 struct type *storage)
432 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
434 ntype = TYPE_CHAIN (ntype);
435 } while (ntype != type);
437 /* Create a new type instance. */
439 ntype = alloc_type_instance (type);
443 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
444 TYPE_CHAIN (ntype) = ntype;
447 /* Pointers or references to the original type are not relevant to
449 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
450 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
452 /* Chain the new qualified type to the old type. */
453 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
454 TYPE_CHAIN (type) = ntype;
456 /* Now set the instance flags and return the new type. */
457 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
462 /* Make an address-space-delimited variant of a type -- a type that
463 is identical to the one supplied except that it has an address
464 space attribute attached to it (such as "code" or "data").
466 This is for Harvard architectures. */
469 make_type_with_address_space (struct type *type, int space_flag)
472 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
473 & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE))
476 return make_qualified_type (type, new_flags, NULL);
479 /* Make a "c-v" variant of a type -- a type that is identical to the
480 one supplied except that it may have const or volatile attributes
481 CNST is a flag for setting the const attribute
482 VOLTL is a flag for setting the volatile attribute
483 TYPE is the base type whose variant we are creating.
484 TYPEPTR, if nonzero, points
485 to a pointer to memory where the reference type should be stored.
486 If *TYPEPTR is zero, update it to point to the reference type we return.
487 We allocate new memory if needed. */
490 make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
492 register struct type *ntype; /* New type */
493 register struct type *tmp_type = type; /* tmp type */
494 struct objfile *objfile;
496 int new_flags = (TYPE_INSTANCE_FLAGS (type)
497 & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
500 new_flags |= TYPE_FLAG_CONST;
503 new_flags |= TYPE_FLAG_VOLATILE;
505 if (typeptr && *typeptr != NULL)
507 /* Objfile is per-core-type. This const-qualified type had best
508 belong to the same objfile as the type it is qualifying, unless
509 we are overwriting a stub type, in which case the safest thing
510 to do is to copy the core type into the new objfile. */
512 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)
513 || TYPE_STUB (*typeptr));
514 if (TYPE_OBJFILE (*typeptr) != TYPE_OBJFILE (type))
516 TYPE_MAIN_TYPE (*typeptr)
517 = TYPE_ALLOC (*typeptr, sizeof (struct main_type));
518 *TYPE_MAIN_TYPE (*typeptr)
519 = *TYPE_MAIN_TYPE (type);
523 ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
531 /* Replace the contents of ntype with the type *type. This changes the
532 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
533 the changes are propogated to all types in the TYPE_CHAIN.
535 In order to build recursive types, it's inevitable that we'll need
536 to update types in place --- but this sort of indiscriminate
537 smashing is ugly, and needs to be replaced with something more
538 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
539 clear if more steps are needed. */
541 replace_type (struct type *ntype, struct type *type)
543 struct type *cv_chain, *as_chain, *ptr, *ref;
545 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
547 /* Assert that the two types have equivalent instance qualifiers.
548 This should be true for at least all of our debug readers. */
549 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
552 /* Implement direct support for MEMBER_TYPE in GNU C++.
553 May need to construct such a type if this is the first use.
554 The TYPE is the type of the member. The DOMAIN is the type
555 of the aggregate that the member belongs to. */
558 lookup_member_type (struct type *type, struct type *domain)
560 register struct type *mtype;
562 mtype = alloc_type (TYPE_OBJFILE (type));
563 smash_to_member_type (mtype, domain, type);
567 /* Allocate a stub method whose return type is TYPE.
568 This apparently happens for speed of symbol reading, since parsing
569 out the arguments to the method is cpu-intensive, the way we are doing
570 it. So, we will fill in arguments later.
571 This always returns a fresh type. */
574 allocate_stub_method (struct type *type)
578 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
579 TYPE_OBJFILE (type));
580 TYPE_TARGET_TYPE (mtype) = type;
581 /* _DOMAIN_TYPE (mtype) = unknown yet */
585 /* Create a range type using either a blank type supplied in RESULT_TYPE,
586 or creating a new type, inheriting the objfile from INDEX_TYPE.
588 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
589 HIGH_BOUND, inclusive.
591 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
592 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
595 create_range_type (struct type *result_type, struct type *index_type,
596 int low_bound, int high_bound)
598 if (result_type == NULL)
600 result_type = alloc_type (TYPE_OBJFILE (index_type));
602 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
603 TYPE_TARGET_TYPE (result_type) = index_type;
604 if (TYPE_STUB (index_type))
605 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
607 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
608 TYPE_NFIELDS (result_type) = 2;
609 TYPE_FIELDS (result_type) = (struct field *)
610 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
611 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
612 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
613 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
614 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
615 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
618 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
620 return (result_type);
623 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
624 Return 1 of type is a range type, 0 if it is discrete (and bounds
625 will fit in LONGEST), or -1 otherwise. */
628 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
630 CHECK_TYPEDEF (type);
631 switch (TYPE_CODE (type))
633 case TYPE_CODE_RANGE:
634 *lowp = TYPE_LOW_BOUND (type);
635 *highp = TYPE_HIGH_BOUND (type);
638 if (TYPE_NFIELDS (type) > 0)
640 /* The enums may not be sorted by value, so search all
644 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
645 for (i = 0; i < TYPE_NFIELDS (type); i++)
647 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
648 *lowp = TYPE_FIELD_BITPOS (type, i);
649 if (TYPE_FIELD_BITPOS (type, i) > *highp)
650 *highp = TYPE_FIELD_BITPOS (type, i);
653 /* Set unsigned indicator if warranted. */
656 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
670 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
672 if (!TYPE_UNSIGNED (type))
674 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
678 /* ... fall through for unsigned ints ... */
681 /* This round-about calculation is to avoid shifting by
682 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
683 if TYPE_LENGTH (type) == sizeof (LONGEST). */
684 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
685 *highp = (*highp - 1) | *highp;
692 /* Create an array type using either a blank type supplied in RESULT_TYPE,
693 or creating a new type, inheriting the objfile from RANGE_TYPE.
695 Elements will be of type ELEMENT_TYPE, the indices will be of type
698 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
699 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
702 create_array_type (struct type *result_type, struct type *element_type,
703 struct type *range_type)
705 LONGEST low_bound, high_bound;
707 if (result_type == NULL)
709 result_type = alloc_type (TYPE_OBJFILE (range_type));
711 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
712 TYPE_TARGET_TYPE (result_type) = element_type;
713 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
714 low_bound = high_bound = 0;
715 CHECK_TYPEDEF (element_type);
716 TYPE_LENGTH (result_type) =
717 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
718 TYPE_NFIELDS (result_type) = 1;
719 TYPE_FIELDS (result_type) =
720 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
721 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
722 TYPE_FIELD_TYPE (result_type, 0) = range_type;
723 TYPE_VPTR_FIELDNO (result_type) = -1;
725 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
726 if (TYPE_LENGTH (result_type) == 0)
727 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
729 return (result_type);
732 /* Create a string type using either a blank type supplied in RESULT_TYPE,
733 or creating a new type. String types are similar enough to array of
734 char types that we can use create_array_type to build the basic type
735 and then bash it into a string type.
737 For fixed length strings, the range type contains 0 as the lower
738 bound and the length of the string minus one as the upper bound.
740 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
741 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
744 create_string_type (struct type *result_type, struct type *range_type)
746 result_type = create_array_type (result_type,
747 *current_language->string_char_type,
749 TYPE_CODE (result_type) = TYPE_CODE_STRING;
750 return (result_type);
754 create_set_type (struct type *result_type, struct type *domain_type)
756 LONGEST low_bound, high_bound, bit_length;
757 if (result_type == NULL)
759 result_type = alloc_type (TYPE_OBJFILE (domain_type));
761 TYPE_CODE (result_type) = TYPE_CODE_SET;
762 TYPE_NFIELDS (result_type) = 1;
763 TYPE_FIELDS (result_type) = (struct field *)
764 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
765 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
767 if (!TYPE_STUB (domain_type))
769 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
770 low_bound = high_bound = 0;
771 bit_length = high_bound - low_bound + 1;
772 TYPE_LENGTH (result_type)
773 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
775 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
778 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
780 return (result_type);
783 /* Construct and return a type of the form:
784 struct NAME { ELT_TYPE ELT_NAME[N]; }
785 We use these types for SIMD registers. For example, the type of
786 the SSE registers on the late x86-family processors is:
787 struct __builtin_v4sf { float f[4]; }
788 built by the function call:
789 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
790 The type returned is a permanent type, allocated using malloc; it
791 doesn't live in any objfile's obstack. */
793 init_simd_type (char *name,
794 struct type *elt_type,
798 struct type *simd_type;
799 struct type *array_type;
801 simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
802 array_type = create_array_type (0, elt_type,
803 create_range_type (0, builtin_type_int,
805 append_composite_type_field (simd_type, elt_name, array_type);
810 init_vector_type (struct type *elt_type, int n)
812 struct type *array_type;
814 array_type = create_array_type (0, elt_type,
815 create_range_type (0, builtin_type_int,
817 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
822 build_builtin_type_vec128 (void)
824 /* Construct a type for the 128 bit registers. The type we're
827 union __gdb_builtin_type_vec128
839 t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
840 append_composite_type_field (t, "uint128", builtin_type_int128);
841 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
842 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
843 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
844 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
850 build_builtin_type_vec128i (void)
852 /* 128-bit Intel SIMD registers */
855 t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
856 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
857 append_composite_type_field (t, "v2_double", builtin_type_v2_double);
858 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
859 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
860 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
861 append_composite_type_field (t, "v2_int64", builtin_type_v2_int64);
862 append_composite_type_field (t, "uint128", builtin_type_int128);
867 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
868 A MEMBER is a wierd thing -- it amounts to a typed offset into
869 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
870 include the offset (that's the value of the MEMBER itself), but does
871 include the structure type into which it points (for some reason).
873 When "smashing" the type, we preserve the objfile that the
874 old type pointed to, since we aren't changing where the type is actually
878 smash_to_member_type (struct type *type, struct type *domain,
879 struct type *to_type)
881 struct objfile *objfile;
883 objfile = TYPE_OBJFILE (type);
886 TYPE_OBJFILE (type) = objfile;
887 TYPE_TARGET_TYPE (type) = to_type;
888 TYPE_DOMAIN_TYPE (type) = domain;
889 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
890 TYPE_CODE (type) = TYPE_CODE_MEMBER;
893 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
894 METHOD just means `function that gets an extra "this" argument'.
896 When "smashing" the type, we preserve the objfile that the
897 old type pointed to, since we aren't changing where the type is actually
901 smash_to_method_type (struct type *type, struct type *domain,
902 struct type *to_type, struct field *args,
903 int nargs, int varargs)
905 struct objfile *objfile;
907 objfile = TYPE_OBJFILE (type);
910 TYPE_OBJFILE (type) = objfile;
911 TYPE_TARGET_TYPE (type) = to_type;
912 TYPE_DOMAIN_TYPE (type) = domain;
913 TYPE_FIELDS (type) = args;
914 TYPE_NFIELDS (type) = nargs;
916 TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
917 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
918 TYPE_CODE (type) = TYPE_CODE_METHOD;
921 /* Return a typename for a struct/union/enum type without "struct ",
922 "union ", or "enum ". If the type has a NULL name, return NULL. */
925 type_name_no_tag (register const struct type *type)
927 if (TYPE_TAG_NAME (type) != NULL)
928 return TYPE_TAG_NAME (type);
930 /* Is there code which expects this to return the name if there is no
931 tag name? My guess is that this is mainly used for C++ in cases where
932 the two will always be the same. */
933 return TYPE_NAME (type);
936 /* Lookup a primitive type named NAME.
937 Return zero if NAME is not a primitive type. */
940 lookup_primitive_typename (char *name)
942 struct type **const *p;
944 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
946 if (STREQ (TYPE_NAME (**p), name))
954 /* Lookup a typedef or primitive type named NAME,
955 visible in lexical block BLOCK.
956 If NOERR is nonzero, return zero if NAME is not suitably defined. */
959 lookup_typename (char *name, struct block *block, int noerr)
961 register struct symbol *sym;
962 register struct type *tmp;
964 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
965 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
967 tmp = lookup_primitive_typename (name);
972 else if (!tmp && noerr)
978 error ("No type named %s.", name);
981 return (SYMBOL_TYPE (sym));
985 lookup_unsigned_typename (char *name)
987 char *uns = alloca (strlen (name) + 10);
989 strcpy (uns, "unsigned ");
990 strcpy (uns + 9, name);
991 return (lookup_typename (uns, (struct block *) NULL, 0));
995 lookup_signed_typename (char *name)
998 char *uns = alloca (strlen (name) + 8);
1000 strcpy (uns, "signed ");
1001 strcpy (uns + 7, name);
1002 t = lookup_typename (uns, (struct block *) NULL, 1);
1003 /* If we don't find "signed FOO" just try again with plain "FOO". */
1006 return lookup_typename (name, (struct block *) NULL, 0);
1009 /* Lookup a structure type named "struct NAME",
1010 visible in lexical block BLOCK. */
1013 lookup_struct (char *name, struct block *block)
1015 register struct symbol *sym;
1017 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
1018 (struct symtab **) NULL);
1022 error ("No struct type named %s.", name);
1024 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1026 error ("This context has class, union or enum %s, not a struct.", name);
1028 return (SYMBOL_TYPE (sym));
1031 /* Lookup a union type named "union NAME",
1032 visible in lexical block BLOCK. */
1035 lookup_union (char *name, struct block *block)
1037 register struct symbol *sym;
1040 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
1041 (struct symtab **) NULL);
1044 error ("No union type named %s.", name);
1046 t = SYMBOL_TYPE (sym);
1048 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1051 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1052 * a further "declared_type" field to discover it is really a union.
1054 if (HAVE_CPLUS_STRUCT (t))
1055 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1058 /* If we get here, it's not a union */
1059 error ("This context has class, struct or enum %s, not a union.", name);
1063 /* Lookup an enum type named "enum NAME",
1064 visible in lexical block BLOCK. */
1067 lookup_enum (char *name, struct block *block)
1069 register struct symbol *sym;
1071 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
1072 (struct symtab **) NULL);
1075 error ("No enum type named %s.", name);
1077 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1079 error ("This context has class, struct or union %s, not an enum.", name);
1081 return (SYMBOL_TYPE (sym));
1084 /* Lookup a template type named "template NAME<TYPE>",
1085 visible in lexical block BLOCK. */
1088 lookup_template_type (char *name, struct type *type, struct block *block)
1091 char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1094 strcat (nam, TYPE_NAME (type));
1095 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1097 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
1101 error ("No template type named %s.", name);
1103 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1105 error ("This context has class, union or enum %s, not a struct.", name);
1107 return (SYMBOL_TYPE (sym));
1110 /* Given a type TYPE, lookup the type of the component of type named NAME.
1112 TYPE can be either a struct or union, or a pointer or reference to a struct or
1113 union. If it is a pointer or reference, its target type is automatically used.
1114 Thus '.' and '->' are interchangable, as specified for the definitions of the
1115 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1117 If NOERR is nonzero, return zero if NAME is not suitably defined.
1118 If NAME is the name of a baseclass type, return that type. */
1121 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1127 CHECK_TYPEDEF (type);
1128 if (TYPE_CODE (type) != TYPE_CODE_PTR
1129 && TYPE_CODE (type) != TYPE_CODE_REF)
1131 type = TYPE_TARGET_TYPE (type);
1134 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1135 TYPE_CODE (type) != TYPE_CODE_UNION)
1137 target_terminal_ours ();
1138 gdb_flush (gdb_stdout);
1139 fprintf_unfiltered (gdb_stderr, "Type ");
1140 type_print (type, "", gdb_stderr, -1);
1141 error (" is not a structure or union type.");
1145 /* FIXME: This change put in by Michael seems incorrect for the case where
1146 the structure tag name is the same as the member name. I.E. when doing
1147 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1152 typename = type_name_no_tag (type);
1153 if (typename != NULL && STREQ (typename, name))
1158 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1160 char *t_field_name = TYPE_FIELD_NAME (type, i);
1162 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1164 return TYPE_FIELD_TYPE (type, i);
1168 /* OK, it's not in this class. Recursively check the baseclasses. */
1169 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1173 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1185 target_terminal_ours ();
1186 gdb_flush (gdb_stdout);
1187 fprintf_unfiltered (gdb_stderr, "Type ");
1188 type_print (type, "", gdb_stderr, -1);
1189 fprintf_unfiltered (gdb_stderr, " has no component named ");
1190 fputs_filtered (name, gdb_stderr);
1192 return (struct type *) -1; /* For lint */
1195 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1196 valid. Callers should be aware that in some cases (for example,
1197 the type or one of its baseclasses is a stub type and we are
1198 debugging a .o file), this function will not be able to find the virtual
1199 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1200 will remain NULL. */
1203 fill_in_vptr_fieldno (struct type *type)
1205 CHECK_TYPEDEF (type);
1207 if (TYPE_VPTR_FIELDNO (type) < 0)
1211 /* We must start at zero in case the first (and only) baseclass is
1212 virtual (and hence we cannot share the table pointer). */
1213 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1215 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
1216 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
1218 TYPE_VPTR_FIELDNO (type)
1219 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
1220 TYPE_VPTR_BASETYPE (type)
1221 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
1228 /* Find the method and field indices for the destructor in class type T.
1229 Return 1 if the destructor was found, otherwise, return 0. */
1232 get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
1236 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1239 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1241 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1243 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1254 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1256 If this is a stubbed struct (i.e. declared as struct foo *), see if
1257 we can find a full definition in some other file. If so, copy this
1258 definition, so we can use it in future. There used to be a comment (but
1259 not any code) that if we don't find a full definition, we'd set a flag
1260 so we don't spend time in the future checking the same type. That would
1261 be a mistake, though--we might load in more symbols which contain a
1262 full definition for the type.
1264 This used to be coded as a macro, but I don't think it is called
1265 often enough to merit such treatment. */
1267 struct complaint stub_noname_complaint =
1268 {"stub type has NULL name", 0, 0};
1271 check_typedef (struct type *type)
1273 struct type *orig_type = type;
1274 int is_const, is_volatile;
1276 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1278 if (!TYPE_TARGET_TYPE (type))
1283 /* It is dangerous to call lookup_symbol if we are currently
1284 reading a symtab. Infinite recursion is one danger. */
1285 if (currently_reading_symtab)
1288 name = type_name_no_tag (type);
1289 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1290 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1291 as appropriate? (this code was written before TYPE_NAME and
1292 TYPE_TAG_NAME were separate). */
1295 complain (&stub_noname_complaint);
1298 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
1299 (struct symtab **) NULL);
1301 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1303 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1305 type = TYPE_TARGET_TYPE (type);
1308 is_const = TYPE_CONST (type);
1309 is_volatile = TYPE_VOLATILE (type);
1311 /* If this is a struct/class/union with no fields, then check whether a
1312 full definition exists somewhere else. This is for systems where a
1313 type definition with no fields is issued for such types, instead of
1314 identifying them as stub types in the first place */
1316 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1318 char *name = type_name_no_tag (type);
1319 struct type *newtype;
1322 complain (&stub_noname_complaint);
1325 newtype = lookup_transparent_type (name);
1327 make_cv_type (is_const, is_volatile, newtype, &type);
1329 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1330 else if (TYPE_STUB (type) && !currently_reading_symtab)
1332 char *name = type_name_no_tag (type);
1333 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1334 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1335 as appropriate? (this code was written before TYPE_NAME and
1336 TYPE_TAG_NAME were separate). */
1340 complain (&stub_noname_complaint);
1343 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL);
1345 make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type);
1348 if (TYPE_TARGET_STUB (type))
1350 struct type *range_type;
1351 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1353 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1356 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1357 && TYPE_NFIELDS (type) == 1
1358 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1359 == TYPE_CODE_RANGE))
1361 /* Now recompute the length of the array type, based on its
1362 number of elements and the target type's length. */
1363 TYPE_LENGTH (type) =
1364 ((TYPE_FIELD_BITPOS (range_type, 1)
1365 - TYPE_FIELD_BITPOS (range_type, 0)
1367 * TYPE_LENGTH (target_type));
1368 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1370 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1372 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1373 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1376 /* Cache TYPE_LENGTH for future use. */
1377 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1381 /* New code added to support parsing of Cfront stabs strings */
1382 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1383 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1386 add_name (struct extra *pextras, char *n)
1390 if ((nlen = (n ? strlen (n) : 0)) == 0)
1392 sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1393 pextras->len = strlen (pextras->str);
1397 add_mangled_type (struct extra *pextras, struct type *t)
1399 enum type_code tcode;
1403 tcode = TYPE_CODE (t);
1404 tlen = TYPE_LENGTH (t);
1405 tflags = TYPE_FLAGS (t);
1406 tname = TYPE_NAME (t);
1407 /* args of "..." seem to get mangled as "e" */
1425 if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1438 static struct complaint msg =
1439 {"Bad int type code length x%x\n", 0, 0};
1441 complain (&msg, tlen);
1460 static struct complaint msg =
1461 {"Bad float type code length x%x\n", 0, 0};
1462 complain (&msg, tlen);
1468 /* followed by what it's a ref to */
1472 /* followed by what it's a ptr to */
1474 case TYPE_CODE_TYPEDEF:
1476 static struct complaint msg =
1477 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1480 /* followed by type bytes & name */
1482 case TYPE_CODE_FUNC:
1484 /* followed by func's arg '_' & ret types */
1486 case TYPE_CODE_VOID:
1489 case TYPE_CODE_METHOD:
1491 /* followed by name of class and func's arg '_' & ret types */
1492 add_name (pextras, tname);
1493 ADD_EXTRA ('F'); /* then mangle function */
1495 case TYPE_CODE_STRUCT: /* C struct */
1496 case TYPE_CODE_UNION: /* C union */
1497 case TYPE_CODE_ENUM: /* Enumeration type */
1498 /* followed by name of type */
1499 add_name (pextras, tname);
1502 /* errors possible types/not supported */
1503 case TYPE_CODE_CHAR:
1504 case TYPE_CODE_ARRAY: /* Array type */
1505 case TYPE_CODE_MEMBER: /* Member type */
1506 case TYPE_CODE_BOOL:
1507 case TYPE_CODE_COMPLEX: /* Complex float */
1508 case TYPE_CODE_UNDEF:
1509 case TYPE_CODE_SET: /* Pascal sets */
1510 case TYPE_CODE_RANGE:
1511 case TYPE_CODE_STRING:
1512 case TYPE_CODE_BITSTRING:
1513 case TYPE_CODE_ERROR:
1516 static struct complaint msg =
1517 {"Unknown type code x%x\n", 0, 0};
1518 complain (&msg, tcode);
1521 if (TYPE_TARGET_TYPE (t))
1522 add_mangled_type (pextras, TYPE_TARGET_TYPE (t));
1527 cfront_mangle_name (struct type *type, int i, int j)
1530 char *mangled_name = gdb_mangle_name (type, i, j);
1532 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1534 /* kludge to support cfront methods - gdb expects to find "F" for
1535 ARM_mangled names, so when we mangle, we have to add it here */
1539 char *arm_mangled_name;
1540 struct fn_field *method = &f[j];
1541 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1542 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1543 char *newname = type_name_no_tag (type);
1545 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1546 int nargs = TYPE_NFIELDS (ftype); /* number of args */
1547 struct extra extras, *pextras = &extras;
1550 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1553 /* add args here! */
1554 if (nargs <= 1) /* no args besides this */
1558 for (k = 1; k < nargs; k++)
1561 t = TYPE_FIELD_TYPE (ftype, k);
1562 add_mangled_type (pextras, t);
1566 printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1567 xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str);
1568 xfree (mangled_name);
1569 mangled_name = arm_mangled_name;
1575 /* End of new code added to support parsing of Cfront stabs strings */
1577 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1578 silently return builtin_type_void. */
1581 safe_parse_type (char *p, int length)
1583 struct ui_file *saved_gdb_stderr;
1586 /* Suppress error messages. */
1587 saved_gdb_stderr = gdb_stderr;
1588 gdb_stderr = ui_file_new ();
1590 /* Call parse_and_eval_type() without fear of longjmp()s. */
1591 if (!gdb_parse_and_eval_type (p, length, &type))
1592 type = builtin_type_void;
1594 /* Stop suppressing error messages. */
1595 ui_file_delete (gdb_stderr);
1596 gdb_stderr = saved_gdb_stderr;
1601 /* Ugly hack to convert method stubs into method types.
1603 He ain't kiddin'. This demangles the name of the method into a string
1604 including argument types, parses out each argument type, generates
1605 a string casting a zero to that type, evaluates the string, and stuffs
1606 the resulting type into an argtype vector!!! Then it knows the type
1607 of the whole function (including argument types for overloading),
1608 which info used to be in the stab's but was removed to hack back
1609 the space required for them. */
1612 check_stub_method (struct type *type, int method_id, int signature_id)
1615 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1616 char *demangled_name = cplus_demangle (mangled_name,
1617 DMGL_PARAMS | DMGL_ANSI);
1618 char *argtypetext, *p;
1619 int depth = 0, argcount = 1;
1620 struct field *argtypes;
1623 /* Make sure we got back a function string that we can use. */
1625 p = strchr (demangled_name, '(');
1629 if (demangled_name == NULL || p == NULL)
1630 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1632 /* Now, read in the parameters that define this type. */
1637 if (*p == '(' || *p == '<')
1641 else if (*p == ')' || *p == '>')
1645 else if (*p == ',' && depth == 0)
1653 /* If we read one argument and it was ``void'', don't count it. */
1654 if (strncmp (argtypetext, "(void)", 6) == 0)
1657 /* We need one extra slot, for the THIS pointer. */
1659 argtypes = (struct field *)
1660 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1663 /* Add THIS pointer for non-static methods. */
1664 f = TYPE_FN_FIELDLIST1 (type, method_id);
1665 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1669 argtypes[0].type = lookup_pointer_type (type);
1673 if (*p != ')') /* () means no args, skip while */
1678 if (depth <= 0 && (*p == ',' || *p == ')'))
1680 /* Avoid parsing of ellipsis, they will be handled below.
1681 Also avoid ``void'' as above. */
1682 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1683 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1685 argtypes[argcount].type =
1686 safe_parse_type (argtypetext, p - argtypetext);
1689 argtypetext = p + 1;
1692 if (*p == '(' || *p == '<')
1696 else if (*p == ')' || *p == '>')
1705 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1707 /* Now update the old "stub" type into a real type. */
1708 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1709 TYPE_DOMAIN_TYPE (mtype) = type;
1710 TYPE_FIELDS (mtype) = argtypes;
1711 TYPE_NFIELDS (mtype) = argcount;
1712 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1713 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1715 TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1717 xfree (demangled_name);
1720 const struct cplus_struct_type cplus_struct_default;
1723 allocate_cplus_struct_type (struct type *type)
1725 if (!HAVE_CPLUS_STRUCT (type))
1727 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1728 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1729 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1733 /* Helper function to initialize the standard scalar types.
1735 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1736 of the string pointed to by name in the type_obstack for that objfile,
1737 and initialize the type name to that copy. There are places (mipsread.c
1738 in particular, where init_type is called with a NULL value for NAME). */
1741 init_type (enum type_code code, int length, int flags, char *name,
1742 struct objfile *objfile)
1744 register struct type *type;
1746 type = alloc_type (objfile);
1747 TYPE_CODE (type) = code;
1748 TYPE_LENGTH (type) = length;
1749 TYPE_FLAGS (type) |= flags;
1750 if ((name != NULL) && (objfile != NULL))
1753 obsavestring (name, strlen (name), &objfile->type_obstack);
1757 TYPE_NAME (type) = name;
1762 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1764 INIT_CPLUS_SPECIFIC (type);
1769 /* Helper function. Create an empty composite type. */
1772 init_composite_type (char *name, enum type_code code)
1775 gdb_assert (code == TYPE_CODE_STRUCT
1776 || code == TYPE_CODE_UNION);
1777 t = init_type (code, 0, 0, NULL, NULL);
1778 TYPE_TAG_NAME (t) = name;
1782 /* Helper function. Append a field to a composite type. */
1785 append_composite_type_field (struct type *t, char *name, struct type *field)
1788 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1789 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1790 sizeof (struct field) * TYPE_NFIELDS (t));
1791 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1792 memset (f, 0, sizeof f[0]);
1793 FIELD_TYPE (f[0]) = field;
1794 FIELD_NAME (f[0]) = name;
1795 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1797 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1798 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1800 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1802 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1803 if (TYPE_NFIELDS (t) > 1)
1805 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1806 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1811 /* Look up a fundamental type for the specified objfile.
1812 May need to construct such a type if this is the first use.
1814 Some object file formats (ELF, COFF, etc) do not define fundamental
1815 types such as "int" or "double". Others (stabs for example), do
1816 define fundamental types.
1818 For the formats which don't provide fundamental types, gdb can create
1819 such types, using defaults reasonable for the current language and
1820 the current target machine.
1822 NOTE: This routine is obsolescent. Each debugging format reader
1823 should manage it's own fundamental types, either creating them from
1824 suitable defaults or reading them from the debugging information,
1825 whichever is appropriate. The DWARF reader has already been
1826 fixed to do this. Once the other readers are fixed, this routine
1827 will go away. Also note that fundamental types should be managed
1828 on a compilation unit basis in a multi-language environment, not
1829 on a linkage unit basis as is done here. */
1833 lookup_fundamental_type (struct objfile *objfile, int typeid)
1835 register struct type **typep;
1836 register int nbytes;
1838 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1840 error ("internal error - invalid fundamental type id %d", typeid);
1843 /* If this is the first time we need a fundamental type for this objfile
1844 then we need to initialize the vector of type pointers. */
1846 if (objfile->fundamental_types == NULL)
1848 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1849 objfile->fundamental_types = (struct type **)
1850 obstack_alloc (&objfile->type_obstack, nbytes);
1851 memset ((char *) objfile->fundamental_types, 0, nbytes);
1852 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1855 /* Look for this particular type in the fundamental type vector. If one is
1856 not found, create and install one appropriate for the current language. */
1858 typep = objfile->fundamental_types + typeid;
1861 *typep = create_fundamental_type (objfile, typeid);
1868 can_dereference (struct type *t)
1870 /* FIXME: Should we return true for references as well as pointers? */
1874 && TYPE_CODE (t) == TYPE_CODE_PTR
1875 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1879 is_integral_type (struct type *t)
1884 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1885 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1886 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1887 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1888 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1891 /* Chill varying string and arrays are represented as follows:
1893 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1895 Return true if TYPE is such a Chill varying type. */
1898 chill_varying_type (struct type *type)
1900 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1901 || TYPE_NFIELDS (type) != 2
1902 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1907 /* Check whether BASE is an ancestor or base class or DCLASS
1908 Return 1 if so, and 0 if not.
1909 Note: callers may want to check for identity of the types before
1910 calling this function -- identical types are considered to satisfy
1911 the ancestor relationship even if they're identical */
1914 is_ancestor (struct type *base, struct type *dclass)
1918 CHECK_TYPEDEF (base);
1919 CHECK_TYPEDEF (dclass);
1923 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
1924 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1927 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1928 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1936 /* See whether DCLASS has a virtual table. This routine is aimed at
1937 the HP/Taligent ANSI C++ runtime model, and may not work with other
1938 runtime models. Return 1 => Yes, 0 => No. */
1941 has_vtable (struct type *dclass)
1943 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1944 has virtual functions or virtual bases. */
1948 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1951 /* First check for the presence of virtual bases */
1952 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1953 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1954 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1957 /* Next check for virtual functions */
1958 if (TYPE_FN_FIELDLISTS (dclass))
1959 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1960 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1963 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1964 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1965 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1966 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1967 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1970 /* Well, maybe we don't need a virtual table */
1974 /* Return a pointer to the "primary base class" of DCLASS.
1976 A NULL return indicates that DCLASS has no primary base, or that it
1977 couldn't be found (insufficient information).
1979 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1980 and may not work with other runtime models. */
1983 primary_base_class (struct type *dclass)
1985 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1986 is the first directly inherited, non-virtual base class that
1987 requires a virtual table */
1991 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1994 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1995 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1996 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1997 return TYPE_FIELD_TYPE (dclass, i);
2002 /* Global manipulated by virtual_base_list[_aux]() */
2004 static struct vbase *current_vbase_list = NULL;
2006 /* Return a pointer to a null-terminated list of struct vbase
2007 items. The vbasetype pointer of each item in the list points to the
2008 type information for a virtual base of the argument DCLASS.
2010 Helper function for virtual_base_list().
2011 Note: the list goes backward, right-to-left. virtual_base_list()
2012 copies the items out in reverse order. */
2015 virtual_base_list_aux (struct type *dclass)
2017 struct vbase *tmp_vbase;
2020 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
2023 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2025 /* Recurse on this ancestor, first */
2026 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
2028 /* If this current base is itself virtual, add it to the list */
2029 if (BASETYPE_VIA_VIRTUAL (dclass, i))
2031 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
2033 /* Check if base already recorded */
2034 tmp_vbase = current_vbase_list;
2037 if (tmp_vbase->vbasetype == basetype)
2038 break; /* found it */
2039 tmp_vbase = tmp_vbase->next;
2042 if (!tmp_vbase) /* normal exit from loop */
2044 /* Allocate new item for this virtual base */
2045 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
2047 /* Stick it on at the end of the list */
2048 tmp_vbase->vbasetype = basetype;
2049 tmp_vbase->next = current_vbase_list;
2050 current_vbase_list = tmp_vbase;
2053 } /* for loop over bases */
2057 /* Compute the list of virtual bases in the right order. Virtual
2058 bases are laid out in the object's memory area in order of their
2059 occurrence in a depth-first, left-to-right search through the
2062 Argument DCLASS is the type whose virtual bases are required.
2063 Return value is the address of a null-terminated array of pointers
2064 to struct type items.
2066 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2067 and may not work with other runtime models.
2069 This routine merely hands off the argument to virtual_base_list_aux()
2070 and then copies the result into an array to save space. */
2073 virtual_base_list (struct type *dclass)
2075 register struct vbase *tmp_vbase;
2076 register struct vbase *tmp_vbase_2;
2079 struct type **vbase_array;
2081 current_vbase_list = NULL;
2082 virtual_base_list_aux (dclass);
2084 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2089 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
2091 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
2092 vbase_array[i] = tmp_vbase->vbasetype;
2094 /* Get rid of constructed chain */
2095 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2098 tmp_vbase = tmp_vbase->next;
2099 xfree (tmp_vbase_2);
2100 tmp_vbase_2 = tmp_vbase;
2103 vbase_array[count] = NULL;
2107 /* Return the length of the virtual base list of the type DCLASS. */
2110 virtual_base_list_length (struct type *dclass)
2113 register struct vbase *tmp_vbase;
2115 current_vbase_list = NULL;
2116 virtual_base_list_aux (dclass);
2118 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2123 /* Return the number of elements of the virtual base list of the type
2124 DCLASS, ignoring those appearing in the primary base (and its
2125 primary base, recursively). */
2128 virtual_base_list_length_skip_primaries (struct type *dclass)
2131 register struct vbase *tmp_vbase;
2132 struct type *primary;
2134 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2137 return virtual_base_list_length (dclass);
2139 current_vbase_list = NULL;
2140 virtual_base_list_aux (dclass);
2142 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
2144 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
2152 /* Return the index (position) of type BASE, which is a virtual base
2153 class of DCLASS, in the latter's virtual base list. A return of -1
2154 indicates "not found" or a problem. */
2157 virtual_base_index (struct type *base, struct type *dclass)
2159 register struct type *vbase;
2162 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2163 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2167 vbase = virtual_base_list (dclass)[0];
2172 vbase = virtual_base_list (dclass)[++i];
2175 return vbase ? i : -1;
2180 /* Return the index (position) of type BASE, which is a virtual base
2181 class of DCLASS, in the latter's virtual base list. Skip over all
2182 bases that may appear in the virtual base list of the primary base
2183 class of DCLASS (recursively). A return of -1 indicates "not
2184 found" or a problem. */
2187 virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
2189 register struct type *vbase;
2191 struct type *primary;
2193 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2194 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2197 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2201 vbase = virtual_base_list (dclass)[0];
2204 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2208 vbase = virtual_base_list (dclass)[++i];
2211 return vbase ? j : -1;
2214 /* Return position of a derived class DCLASS in the list of
2215 * primary bases starting with the remotest ancestor.
2216 * Position returned is 0-based. */
2219 class_index_in_primary_list (struct type *dclass)
2221 struct type *pbc; /* primary base class */
2223 /* Simply recurse on primary base */
2224 pbc = TYPE_PRIMARY_BASE (dclass);
2226 return 1 + class_index_in_primary_list (pbc);
2231 /* Return a count of the number of virtual functions a type has.
2232 * This includes all the virtual functions it inherits from its
2236 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2237 * functions only once (latest redefinition)
2241 count_virtual_fns (struct type *dclass)
2243 int fn, oi; /* function and overloaded instance indices */
2244 int vfuncs; /* count to return */
2246 /* recurse on bases that can share virtual table */
2247 struct type *pbc = primary_base_class (dclass);
2249 vfuncs = count_virtual_fns (pbc);
2253 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2254 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2255 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2263 /* Functions for overload resolution begin here */
2265 /* Compare two badness vectors A and B and return the result.
2266 * 0 => A and B are identical
2267 * 1 => A and B are incomparable
2268 * 2 => A is better than B
2269 * 3 => A is worse than B */
2272 compare_badness (struct badness_vector *a, struct badness_vector *b)
2276 short found_pos = 0; /* any positives in c? */
2277 short found_neg = 0; /* any negatives in c? */
2279 /* differing lengths => incomparable */
2280 if (a->length != b->length)
2283 /* Subtract b from a */
2284 for (i = 0; i < a->length; i++)
2286 tmp = a->rank[i] - b->rank[i];
2296 return 1; /* incomparable */
2298 return 3; /* A > B */
2304 return 2; /* A < B */
2306 return 0; /* A == B */
2310 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2311 * to the types of an argument list (ARGS, length NARGS).
2312 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2314 struct badness_vector *
2315 rank_function (struct type **parms, int nparms, struct type **args, int nargs)
2318 struct badness_vector *bv;
2319 int min_len = nparms < nargs ? nparms : nargs;
2321 bv = xmalloc (sizeof (struct badness_vector));
2322 bv->length = nargs + 1; /* add 1 for the length-match rank */
2323 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2325 /* First compare the lengths of the supplied lists.
2326 * If there is a mismatch, set it to a high value. */
2328 /* pai/1997-06-03 FIXME: when we have debug info about default
2329 * arguments and ellipsis parameter lists, we should consider those
2330 * and rank the length-match more finely. */
2332 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2334 /* Now rank all the parameters of the candidate function */
2335 for (i = 1; i <= min_len; i++)
2336 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2338 /* If more arguments than parameters, add dummy entries */
2339 for (i = min_len + 1; i <= nargs; i++)
2340 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2345 /* Compare one type (PARM) for compatibility with another (ARG).
2346 * PARM is intended to be the parameter type of a function; and
2347 * ARG is the supplied argument's type. This function tests if
2348 * the latter can be converted to the former.
2350 * Return 0 if they are identical types;
2351 * Otherwise, return an integer which corresponds to how compatible
2352 * PARM is to ARG. The higher the return value, the worse the match.
2353 * Generally the "bad" conversions are all uniformly assigned a 100 */
2356 rank_one_type (struct type *parm, struct type *arg)
2358 /* Identical type pointers */
2359 /* However, this still doesn't catch all cases of same type for arg
2360 * and param. The reason is that builtin types are different from
2361 * the same ones constructed from the object. */
2365 /* Resolve typedefs */
2366 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2367 parm = check_typedef (parm);
2368 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2369 arg = check_typedef (arg);
2372 Well, damnit, if the names are exactly the same,
2373 i'll say they are exactly the same. This happens when we generate
2374 method stubs. The types won't point to the same address, but they
2375 really are the same.
2378 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2379 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2382 /* Check if identical after resolving typedefs */
2386 /* See through references, since we can almost make non-references
2388 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2389 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2390 + REFERENCE_CONVERSION_BADNESS);
2391 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2392 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2393 + REFERENCE_CONVERSION_BADNESS);
2395 /* Debugging only. */
2396 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2397 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2399 /* x -> y means arg of type x being supplied for parameter of type y */
2401 switch (TYPE_CODE (parm))
2404 switch (TYPE_CODE (arg))
2407 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2408 return VOID_PTR_CONVERSION_BADNESS;
2410 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2411 case TYPE_CODE_ARRAY:
2412 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2413 case TYPE_CODE_FUNC:
2414 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2416 case TYPE_CODE_ENUM:
2417 case TYPE_CODE_CHAR:
2418 case TYPE_CODE_RANGE:
2419 case TYPE_CODE_BOOL:
2420 return POINTER_CONVERSION_BADNESS;
2422 return INCOMPATIBLE_TYPE_BADNESS;
2424 case TYPE_CODE_ARRAY:
2425 switch (TYPE_CODE (arg))
2428 case TYPE_CODE_ARRAY:
2429 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2431 return INCOMPATIBLE_TYPE_BADNESS;
2433 case TYPE_CODE_FUNC:
2434 switch (TYPE_CODE (arg))
2436 case TYPE_CODE_PTR: /* funcptr -> func */
2437 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2439 return INCOMPATIBLE_TYPE_BADNESS;
2442 switch (TYPE_CODE (arg))
2445 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2447 /* Deal with signed, unsigned, and plain chars and
2448 signed and unsigned ints */
2449 if (TYPE_NOSIGN (parm))
2451 /* This case only for character types */
2452 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2455 return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */
2457 else if (TYPE_UNSIGNED (parm))
2459 if (TYPE_UNSIGNED (arg))
2461 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2462 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2463 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2464 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2466 return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
2470 if (!strcmp_iw (TYPE_NAME (arg), "long") && !strcmp_iw (TYPE_NAME (parm), "int"))
2471 return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
2473 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2476 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2478 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2480 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2481 return INTEGER_PROMOTION_BADNESS;
2483 return INTEGER_COERCION_BADNESS;
2486 return INTEGER_COERCION_BADNESS;
2488 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2489 return INTEGER_PROMOTION_BADNESS;
2491 return INTEGER_COERCION_BADNESS;
2492 case TYPE_CODE_ENUM:
2493 case TYPE_CODE_CHAR:
2494 case TYPE_CODE_RANGE:
2495 case TYPE_CODE_BOOL:
2496 return INTEGER_PROMOTION_BADNESS;
2498 return INT_FLOAT_CONVERSION_BADNESS;
2500 return NS_POINTER_CONVERSION_BADNESS;
2502 return INCOMPATIBLE_TYPE_BADNESS;
2505 case TYPE_CODE_ENUM:
2506 switch (TYPE_CODE (arg))
2509 case TYPE_CODE_CHAR:
2510 case TYPE_CODE_RANGE:
2511 case TYPE_CODE_BOOL:
2512 case TYPE_CODE_ENUM:
2513 return INTEGER_COERCION_BADNESS;
2515 return INT_FLOAT_CONVERSION_BADNESS;
2517 return INCOMPATIBLE_TYPE_BADNESS;
2520 case TYPE_CODE_CHAR:
2521 switch (TYPE_CODE (arg))
2523 case TYPE_CODE_RANGE:
2524 case TYPE_CODE_BOOL:
2525 case TYPE_CODE_ENUM:
2526 return INTEGER_COERCION_BADNESS;
2528 return INT_FLOAT_CONVERSION_BADNESS;
2530 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2531 return INTEGER_COERCION_BADNESS;
2532 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2533 return INTEGER_PROMOTION_BADNESS;
2534 /* >>> !! else fall through !! <<< */
2535 case TYPE_CODE_CHAR:
2536 /* Deal with signed, unsigned, and plain chars for C++
2537 and with int cases falling through from previous case */
2538 if (TYPE_NOSIGN (parm))
2540 if (TYPE_NOSIGN (arg))
2543 return INTEGER_COERCION_BADNESS;
2545 else if (TYPE_UNSIGNED (parm))
2547 if (TYPE_UNSIGNED (arg))
2550 return INTEGER_PROMOTION_BADNESS;
2552 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2555 return INTEGER_COERCION_BADNESS;
2557 return INCOMPATIBLE_TYPE_BADNESS;
2560 case TYPE_CODE_RANGE:
2561 switch (TYPE_CODE (arg))
2564 case TYPE_CODE_CHAR:
2565 case TYPE_CODE_RANGE:
2566 case TYPE_CODE_BOOL:
2567 case TYPE_CODE_ENUM:
2568 return INTEGER_COERCION_BADNESS;
2570 return INT_FLOAT_CONVERSION_BADNESS;
2572 return INCOMPATIBLE_TYPE_BADNESS;
2575 case TYPE_CODE_BOOL:
2576 switch (TYPE_CODE (arg))
2579 case TYPE_CODE_CHAR:
2580 case TYPE_CODE_RANGE:
2581 case TYPE_CODE_ENUM:
2584 return BOOLEAN_CONVERSION_BADNESS;
2585 case TYPE_CODE_BOOL:
2588 return INCOMPATIBLE_TYPE_BADNESS;
2592 switch (TYPE_CODE (arg))
2595 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2596 return FLOAT_PROMOTION_BADNESS;
2597 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2600 return FLOAT_CONVERSION_BADNESS;
2602 case TYPE_CODE_BOOL:
2603 case TYPE_CODE_ENUM:
2604 case TYPE_CODE_RANGE:
2605 case TYPE_CODE_CHAR:
2606 return INT_FLOAT_CONVERSION_BADNESS;
2608 return INCOMPATIBLE_TYPE_BADNESS;
2611 case TYPE_CODE_COMPLEX:
2612 switch (TYPE_CODE (arg))
2613 { /* Strictly not needed for C++, but... */
2615 return FLOAT_PROMOTION_BADNESS;
2616 case TYPE_CODE_COMPLEX:
2619 return INCOMPATIBLE_TYPE_BADNESS;
2622 case TYPE_CODE_STRUCT:
2623 /* currently same as TYPE_CODE_CLASS */
2624 switch (TYPE_CODE (arg))
2626 case TYPE_CODE_STRUCT:
2627 /* Check for derivation */
2628 if (is_ancestor (parm, arg))
2629 return BASE_CONVERSION_BADNESS;
2630 /* else fall through */
2632 return INCOMPATIBLE_TYPE_BADNESS;
2635 case TYPE_CODE_UNION:
2636 switch (TYPE_CODE (arg))
2638 case TYPE_CODE_UNION:
2640 return INCOMPATIBLE_TYPE_BADNESS;
2643 case TYPE_CODE_MEMBER:
2644 switch (TYPE_CODE (arg))
2647 return INCOMPATIBLE_TYPE_BADNESS;
2650 case TYPE_CODE_METHOD:
2651 switch (TYPE_CODE (arg))
2655 return INCOMPATIBLE_TYPE_BADNESS;
2659 switch (TYPE_CODE (arg))
2663 return INCOMPATIBLE_TYPE_BADNESS;
2668 switch (TYPE_CODE (arg))
2672 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2674 return INCOMPATIBLE_TYPE_BADNESS;
2677 case TYPE_CODE_VOID:
2679 return INCOMPATIBLE_TYPE_BADNESS;
2680 } /* switch (TYPE_CODE (arg)) */
2684 /* End of functions for overload resolution */
2687 print_bit_vector (B_TYPE *bits, int nbits)
2691 for (bitno = 0; bitno < nbits; bitno++)
2693 if ((bitno % 8) == 0)
2695 puts_filtered (" ");
2697 if (B_TST (bits, bitno))
2699 printf_filtered ("1");
2703 printf_filtered ("0");
2708 /* Note the first arg should be the "this" pointer, we may not want to
2709 include it since we may get into a infinitely recursive situation. */
2712 print_arg_types (struct field *args, int nargs, int spaces)
2718 for (i = 0; i < nargs; i++)
2719 recursive_dump_type (args[i].type, spaces + 2);
2724 dump_fn_fieldlists (struct type *type, int spaces)
2730 printfi_filtered (spaces, "fn_fieldlists ");
2731 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2732 printf_filtered ("\n");
2733 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2735 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2736 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2738 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2739 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2741 printf_filtered (") length %d\n",
2742 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2743 for (overload_idx = 0;
2744 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2747 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2749 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2750 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2752 printf_filtered (")\n");
2753 printfi_filtered (spaces + 8, "type ");
2754 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2755 printf_filtered ("\n");
2757 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2760 printfi_filtered (spaces + 8, "args ");
2761 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2762 printf_filtered ("\n");
2764 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2765 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2767 printfi_filtered (spaces + 8, "fcontext ");
2768 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2770 printf_filtered ("\n");
2772 printfi_filtered (spaces + 8, "is_const %d\n",
2773 TYPE_FN_FIELD_CONST (f, overload_idx));
2774 printfi_filtered (spaces + 8, "is_volatile %d\n",
2775 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2776 printfi_filtered (spaces + 8, "is_private %d\n",
2777 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2778 printfi_filtered (spaces + 8, "is_protected %d\n",
2779 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2780 printfi_filtered (spaces + 8, "is_stub %d\n",
2781 TYPE_FN_FIELD_STUB (f, overload_idx));
2782 printfi_filtered (spaces + 8, "voffset %u\n",
2783 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2789 print_cplus_stuff (struct type *type, int spaces)
2791 printfi_filtered (spaces, "n_baseclasses %d\n",
2792 TYPE_N_BASECLASSES (type));
2793 printfi_filtered (spaces, "nfn_fields %d\n",
2794 TYPE_NFN_FIELDS (type));
2795 printfi_filtered (spaces, "nfn_fields_total %d\n",
2796 TYPE_NFN_FIELDS_TOTAL (type));
2797 if (TYPE_N_BASECLASSES (type) > 0)
2799 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2800 TYPE_N_BASECLASSES (type));
2801 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2802 printf_filtered (")");
2804 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2805 TYPE_N_BASECLASSES (type));
2806 puts_filtered ("\n");
2808 if (TYPE_NFIELDS (type) > 0)
2810 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2812 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2813 TYPE_NFIELDS (type));
2814 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2815 printf_filtered (")");
2816 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2817 TYPE_NFIELDS (type));
2818 puts_filtered ("\n");
2820 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2822 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2823 TYPE_NFIELDS (type));
2824 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2825 printf_filtered (")");
2826 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2827 TYPE_NFIELDS (type));
2828 puts_filtered ("\n");
2831 if (TYPE_NFN_FIELDS (type) > 0)
2833 dump_fn_fieldlists (type, spaces);
2838 print_bound_type (int bt)
2842 case BOUND_CANNOT_BE_DETERMINED:
2843 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2845 case BOUND_BY_REF_ON_STACK:
2846 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2848 case BOUND_BY_VALUE_ON_STACK:
2849 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2851 case BOUND_BY_REF_IN_REG:
2852 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2854 case BOUND_BY_VALUE_IN_REG:
2855 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2858 printf_filtered ("(BOUND_SIMPLE)");
2861 printf_filtered ("(unknown bound type)");
2866 static struct obstack dont_print_type_obstack;
2869 recursive_dump_type (struct type *type, int spaces)
2874 obstack_begin (&dont_print_type_obstack, 0);
2876 if (TYPE_NFIELDS (type) > 0
2877 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2879 struct type **first_dont_print
2880 = (struct type **) obstack_base (&dont_print_type_obstack);
2882 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2887 if (type == first_dont_print[i])
2889 printfi_filtered (spaces, "type node ");
2890 gdb_print_host_address (type, gdb_stdout);
2891 printf_filtered (" <same as already seen type>\n");
2896 obstack_ptr_grow (&dont_print_type_obstack, type);
2899 printfi_filtered (spaces, "type node ");
2900 gdb_print_host_address (type, gdb_stdout);
2901 printf_filtered ("\n");
2902 printfi_filtered (spaces, "name '%s' (",
2903 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2904 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2905 printf_filtered (")\n");
2906 printfi_filtered (spaces, "tagname '%s' (",
2907 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2908 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2909 printf_filtered (")\n");
2910 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2911 switch (TYPE_CODE (type))
2913 case TYPE_CODE_UNDEF:
2914 printf_filtered ("(TYPE_CODE_UNDEF)");
2917 printf_filtered ("(TYPE_CODE_PTR)");
2919 case TYPE_CODE_ARRAY:
2920 printf_filtered ("(TYPE_CODE_ARRAY)");
2922 case TYPE_CODE_STRUCT:
2923 printf_filtered ("(TYPE_CODE_STRUCT)");
2925 case TYPE_CODE_UNION:
2926 printf_filtered ("(TYPE_CODE_UNION)");
2928 case TYPE_CODE_ENUM:
2929 printf_filtered ("(TYPE_CODE_ENUM)");
2931 case TYPE_CODE_FUNC:
2932 printf_filtered ("(TYPE_CODE_FUNC)");
2935 printf_filtered ("(TYPE_CODE_INT)");
2938 printf_filtered ("(TYPE_CODE_FLT)");
2940 case TYPE_CODE_VOID:
2941 printf_filtered ("(TYPE_CODE_VOID)");
2944 printf_filtered ("(TYPE_CODE_SET)");
2946 case TYPE_CODE_RANGE:
2947 printf_filtered ("(TYPE_CODE_RANGE)");
2949 case TYPE_CODE_STRING:
2950 printf_filtered ("(TYPE_CODE_STRING)");
2952 case TYPE_CODE_BITSTRING:
2953 printf_filtered ("(TYPE_CODE_BITSTRING)");
2955 case TYPE_CODE_ERROR:
2956 printf_filtered ("(TYPE_CODE_ERROR)");
2958 case TYPE_CODE_MEMBER:
2959 printf_filtered ("(TYPE_CODE_MEMBER)");
2961 case TYPE_CODE_METHOD:
2962 printf_filtered ("(TYPE_CODE_METHOD)");
2965 printf_filtered ("(TYPE_CODE_REF)");
2967 case TYPE_CODE_CHAR:
2968 printf_filtered ("(TYPE_CODE_CHAR)");
2970 case TYPE_CODE_BOOL:
2971 printf_filtered ("(TYPE_CODE_BOOL)");
2973 case TYPE_CODE_COMPLEX:
2974 printf_filtered ("(TYPE_CODE_COMPLEX)");
2976 case TYPE_CODE_TYPEDEF:
2977 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2979 case TYPE_CODE_TEMPLATE:
2980 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2982 case TYPE_CODE_TEMPLATE_ARG:
2983 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2986 printf_filtered ("(UNKNOWN TYPE CODE)");
2989 puts_filtered ("\n");
2990 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2991 printfi_filtered (spaces, "upper_bound_type 0x%x ",
2992 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2993 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2994 puts_filtered ("\n");
2995 printfi_filtered (spaces, "lower_bound_type 0x%x ",
2996 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2997 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2998 puts_filtered ("\n");
2999 printfi_filtered (spaces, "objfile ");
3000 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
3001 printf_filtered ("\n");
3002 printfi_filtered (spaces, "target_type ");
3003 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
3004 printf_filtered ("\n");
3005 if (TYPE_TARGET_TYPE (type) != NULL)
3007 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3009 printfi_filtered (spaces, "pointer_type ");
3010 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
3011 printf_filtered ("\n");
3012 printfi_filtered (spaces, "reference_type ");
3013 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
3014 printf_filtered ("\n");
3015 printfi_filtered (spaces, "type_chain ");
3016 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
3017 printf_filtered ("\n");
3018 printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
3019 if (TYPE_CONST (type))
3021 puts_filtered (" TYPE_FLAG_CONST");
3023 if (TYPE_VOLATILE (type))
3025 puts_filtered (" TYPE_FLAG_VOLATILE");
3027 if (TYPE_CODE_SPACE (type))
3029 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3031 if (TYPE_DATA_SPACE (type))
3033 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3035 puts_filtered ("\n");
3036 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
3037 if (TYPE_UNSIGNED (type))
3039 puts_filtered (" TYPE_FLAG_UNSIGNED");
3041 if (TYPE_NOSIGN (type))
3043 puts_filtered (" TYPE_FLAG_NOSIGN");
3045 if (TYPE_STUB (type))
3047 puts_filtered (" TYPE_FLAG_STUB");
3049 if (TYPE_TARGET_STUB (type))
3051 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3053 if (TYPE_STATIC (type))
3055 puts_filtered (" TYPE_FLAG_STATIC");
3057 if (TYPE_PROTOTYPED (type))
3059 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3061 if (TYPE_INCOMPLETE (type))
3063 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3065 if (TYPE_VARARGS (type))
3067 puts_filtered (" TYPE_FLAG_VARARGS");
3069 /* This is used for things like AltiVec registers on ppc. Gcc emits
3070 an attribute for the array type, which tells whether or not we
3071 have a vector, instead of a regular array. */
3072 if (TYPE_VECTOR (type))
3074 puts_filtered (" TYPE_FLAG_VECTOR");
3076 puts_filtered ("\n");
3077 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3078 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3079 puts_filtered ("\n");
3080 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3082 printfi_filtered (spaces + 2,
3083 "[%d] bitpos %d bitsize %d type ",
3084 idx, TYPE_FIELD_BITPOS (type, idx),
3085 TYPE_FIELD_BITSIZE (type, idx));
3086 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3087 printf_filtered (" name '%s' (",
3088 TYPE_FIELD_NAME (type, idx) != NULL
3089 ? TYPE_FIELD_NAME (type, idx)
3091 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3092 printf_filtered (")\n");
3093 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3095 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3098 printfi_filtered (spaces, "vptr_basetype ");
3099 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3100 puts_filtered ("\n");
3101 if (TYPE_VPTR_BASETYPE (type) != NULL)
3103 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3105 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3106 switch (TYPE_CODE (type))
3108 case TYPE_CODE_STRUCT:
3109 printfi_filtered (spaces, "cplus_stuff ");
3110 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3111 puts_filtered ("\n");
3112 print_cplus_stuff (type, spaces);
3116 printfi_filtered (spaces, "floatformat ");
3117 if (TYPE_FLOATFORMAT (type) == NULL
3118 || TYPE_FLOATFORMAT (type)->name == NULL)
3119 puts_filtered ("(null)");
3121 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3122 puts_filtered ("\n");
3126 /* We have to pick one of the union types to be able print and test
3127 the value. Pick cplus_struct_type, even though we know it isn't
3128 any particular one. */
3129 printfi_filtered (spaces, "type_specific ");
3130 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3131 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3133 printf_filtered (" (unknown data form)");
3135 printf_filtered ("\n");
3140 obstack_free (&dont_print_type_obstack, NULL);
3143 static void build_gdbtypes (void);
3145 build_gdbtypes (void)
3148 init_type (TYPE_CODE_VOID, 1,
3150 "void", (struct objfile *) NULL);
3152 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3154 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
3155 "char", (struct objfile *) NULL);
3156 builtin_type_true_char =
3157 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3159 "true character", (struct objfile *) NULL);
3160 builtin_type_signed_char =
3161 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3163 "signed char", (struct objfile *) NULL);
3164 builtin_type_unsigned_char =
3165 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3167 "unsigned char", (struct objfile *) NULL);
3168 builtin_type_short =
3169 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3171 "short", (struct objfile *) NULL);
3172 builtin_type_unsigned_short =
3173 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3175 "unsigned short", (struct objfile *) NULL);
3177 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3179 "int", (struct objfile *) NULL);
3180 builtin_type_unsigned_int =
3181 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3183 "unsigned int", (struct objfile *) NULL);
3185 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3187 "long", (struct objfile *) NULL);
3188 builtin_type_unsigned_long =
3189 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3191 "unsigned long", (struct objfile *) NULL);
3192 builtin_type_long_long =
3193 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3195 "long long", (struct objfile *) NULL);
3196 builtin_type_unsigned_long_long =
3197 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3199 "unsigned long long", (struct objfile *) NULL);
3200 builtin_type_float =
3201 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3203 "float", (struct objfile *) NULL);
3205 The below lines are disabled since they are doing the wrong
3206 thing for non-multiarch targets. They are setting the correct
3207 type of floats for the target but while on multiarch targets
3208 this is done everytime the architecture changes, it's done on
3209 non-multiarch targets only on startup, leaving the wrong values
3210 in even if the architecture changes (eg. from big-endian to
3213 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
3215 builtin_type_double =
3216 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3218 "double", (struct objfile *) NULL);
3220 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
3222 builtin_type_long_double =
3223 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3225 "long double", (struct objfile *) NULL);
3227 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
3229 builtin_type_complex =
3230 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3232 "complex", (struct objfile *) NULL);
3233 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3234 builtin_type_double_complex =
3235 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3237 "double complex", (struct objfile *) NULL);
3238 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3239 builtin_type_string =
3240 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3242 "string", (struct objfile *) NULL);
3244 init_type (TYPE_CODE_INT, 8 / 8,
3246 "int8_t", (struct objfile *) NULL);
3247 builtin_type_uint8 =
3248 init_type (TYPE_CODE_INT, 8 / 8,
3250 "uint8_t", (struct objfile *) NULL);
3251 builtin_type_int16 =
3252 init_type (TYPE_CODE_INT, 16 / 8,
3254 "int16_t", (struct objfile *) NULL);
3255 builtin_type_uint16 =
3256 init_type (TYPE_CODE_INT, 16 / 8,
3258 "uint16_t", (struct objfile *) NULL);
3259 builtin_type_int32 =
3260 init_type (TYPE_CODE_INT, 32 / 8,
3262 "int32_t", (struct objfile *) NULL);
3263 builtin_type_uint32 =
3264 init_type (TYPE_CODE_INT, 32 / 8,
3266 "uint32_t", (struct objfile *) NULL);
3267 builtin_type_int64 =
3268 init_type (TYPE_CODE_INT, 64 / 8,
3270 "int64_t", (struct objfile *) NULL);
3271 builtin_type_uint64 =
3272 init_type (TYPE_CODE_INT, 64 / 8,
3274 "uint64_t", (struct objfile *) NULL);
3275 builtin_type_int128 =
3276 init_type (TYPE_CODE_INT, 128 / 8,
3278 "int128_t", (struct objfile *) NULL);
3279 builtin_type_uint128 =
3280 init_type (TYPE_CODE_INT, 128 / 8,
3282 "uint128_t", (struct objfile *) NULL);
3284 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3286 "bool", (struct objfile *) NULL);
3288 /* Add user knob for controlling resolution of opaque types */
3290 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
3291 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3294 opaque_type_resolution = 1;
3296 /* Build SIMD types. */
3298 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
3300 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
3302 = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
3304 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
3306 = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
3308 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3310 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
3312 /* 128 bit vectors. */
3313 builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
3314 builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3315 builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
3316 builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3317 builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3318 builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3319 /* 64 bit vectors. */
3320 builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
3321 builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3322 builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3323 builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
3326 builtin_type_vec128 = build_builtin_type_vec128 ();
3327 builtin_type_vec128i = build_builtin_type_vec128i ();
3329 /* Pointer/Address types. */
3331 /* NOTE: on some targets, addresses and pointers are not necessarily
3332 the same --- for example, on the D10V, pointers are 16 bits long,
3333 but addresses are 32 bits long. See doc/gdbint.texinfo,
3334 ``Pointers Are Not Always Addresses''.
3337 - gdb's `struct type' always describes the target's
3339 - gdb's `struct value' objects should always hold values in
3341 - gdb's CORE_ADDR values are addresses in the unified virtual
3342 address space that the assembler and linker work with. Thus,
3343 since target_read_memory takes a CORE_ADDR as an argument, it
3344 can access any memory on the target, even if the processor has
3345 separate code and data address spaces.
3348 - If v is a value holding a D10V code pointer, its contents are
3349 in target form: a big-endian address left-shifted two bits.
3350 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3351 sizeof (void *) == 2 on the target.
3353 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3354 target type for a value the target will never see. It's only
3355 used to hold the values of (typeless) linker symbols, which are
3356 indeed in the unified virtual address space. */
3357 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
3358 builtin_type_void_func_ptr
3359 = lookup_pointer_type (lookup_function_type (builtin_type_void));
3360 builtin_type_CORE_ADDR =
3361 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
3363 "__CORE_ADDR", (struct objfile *) NULL);
3364 builtin_type_bfd_vma =
3365 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3367 "__bfd_vma", (struct objfile *) NULL);
3371 extern void _initialize_gdbtypes (void);
3373 _initialize_gdbtypes (void)
3375 struct cmd_list_element *c;
3378 /* FIXME - For the moment, handle types by swapping them in and out.
3379 Should be using the per-architecture data-pointer and a large
3381 register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL);
3382 register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL);
3383 register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL);
3384 register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL);
3385 register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL);
3386 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL);
3387 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL);
3388 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL);
3389 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL);
3390 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL);
3391 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL);
3392 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL);
3393 register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL);
3394 register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL);
3395 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL);
3396 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL);
3397 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL);
3398 register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL);
3399 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL);
3400 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL);
3401 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL);
3402 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL);
3403 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL);
3404 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
3405 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
3406 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
3407 register_gdbarch_swap (&builtin_type_int128, sizeof (struct type *), NULL);
3408 register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type *), NULL);
3409 register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
3410 register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL);
3411 register_gdbarch_swap (&builtin_type_v16qi, sizeof (struct type *), NULL);
3412 register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL);
3413 register_gdbarch_swap (&builtin_type_v8hi, sizeof (struct type *), NULL);
3414 register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
3415 register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
3416 register_gdbarch_swap (&builtin_type_v2_double, sizeof (struct type *), NULL);
3417 register_gdbarch_swap (&builtin_type_v4_float, sizeof (struct type *), NULL);
3418 register_gdbarch_swap (&builtin_type_v2_int64, sizeof (struct type *), NULL);
3419 register_gdbarch_swap (&builtin_type_v4_int32, sizeof (struct type *), NULL);
3420 register_gdbarch_swap (&builtin_type_v8_int16, sizeof (struct type *), NULL);
3421 register_gdbarch_swap (&builtin_type_v16_int8, sizeof (struct type *), NULL);
3422 register_gdbarch_swap (&builtin_type_v2_float, sizeof (struct type *), NULL);
3423 register_gdbarch_swap (&builtin_type_v2_int32, sizeof (struct type *), NULL);
3424 register_gdbarch_swap (&builtin_type_v8_int8, sizeof (struct type *), NULL);
3425 register_gdbarch_swap (&builtin_type_v4_int16, sizeof (struct type *), NULL);
3426 register_gdbarch_swap (&builtin_type_vec128, sizeof (struct type *), NULL);
3427 register_gdbarch_swap (&builtin_type_vec128i, sizeof (struct type *), NULL);
3428 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3429 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3430 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3431 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3432 register_gdbarch_swap (NULL, 0, build_gdbtypes);
3434 /* Note: These types do not need to be swapped - they are target
3436 builtin_type_ieee_single_big =
3437 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3438 0, "builtin_type_ieee_single_big", NULL);
3439 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3440 builtin_type_ieee_single_little =
3441 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3442 0, "builtin_type_ieee_single_little", NULL);
3443 TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
3444 builtin_type_ieee_double_big =
3445 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3446 0, "builtin_type_ieee_double_big", NULL);
3447 TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
3448 builtin_type_ieee_double_little =
3449 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3450 0, "builtin_type_ieee_double_little", NULL);
3451 TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
3452 builtin_type_ieee_double_littlebyte_bigword =
3453 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3454 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
3455 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
3456 builtin_type_i387_ext =
3457 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3458 0, "builtin_type_i387_ext", NULL);
3459 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
3460 builtin_type_m68881_ext =
3461 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3462 0, "builtin_type_m68881_ext", NULL);
3463 TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
3464 builtin_type_i960_ext =
3465 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3466 0, "builtin_type_i960_ext", NULL);
3467 TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
3468 builtin_type_m88110_ext =
3469 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3470 0, "builtin_type_m88110_ext", NULL);
3471 TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
3472 builtin_type_m88110_harris_ext =
3473 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3474 0, "builtin_type_m88110_harris_ext", NULL);
3475 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
3476 builtin_type_arm_ext_big =
3477 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3478 0, "builtin_type_arm_ext_big", NULL);
3479 TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
3480 builtin_type_arm_ext_littlebyte_bigword =
3481 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3482 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
3483 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
3484 builtin_type_ia64_spill_big =
3485 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3486 0, "builtin_type_ia64_spill_big", NULL);
3487 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
3488 builtin_type_ia64_spill_little =
3489 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3490 0, "builtin_type_ia64_spill_little", NULL);
3491 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
3492 builtin_type_ia64_quad_big =
3493 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3494 0, "builtin_type_ia64_quad_big", NULL);
3495 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
3496 builtin_type_ia64_quad_little =
3497 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3498 0, "builtin_type_ia64_quad_little", NULL);
3499 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
3502 add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
3503 "Set debugging of C++ overloading.\n\
3504 When enabled, ranking of the functions\n\
3505 is displayed.", &setdebuglist),