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_v4_float;
77 struct type *builtin_type_v4_int32;
78 struct type *builtin_type_v8_int16;
79 struct type *builtin_type_v16_int8;
80 /* 64 bit long vector types */
81 struct type *builtin_type_v2_float;
82 struct type *builtin_type_v2_int32;
83 struct type *builtin_type_v4_int16;
84 struct type *builtin_type_v8_int8;
86 struct type *builtin_type_v4sf;
87 struct type *builtin_type_v4si;
88 struct type *builtin_type_v16qi;
89 struct type *builtin_type_v8qi;
90 struct type *builtin_type_v8hi;
91 struct type *builtin_type_v4hi;
92 struct type *builtin_type_v2si;
93 struct type *builtin_type_vec128;
94 struct type *builtin_type_ieee_single_big;
95 struct type *builtin_type_ieee_single_little;
96 struct type *builtin_type_ieee_double_big;
97 struct type *builtin_type_ieee_double_little;
98 struct type *builtin_type_ieee_double_littlebyte_bigword;
99 struct type *builtin_type_i387_ext;
100 struct type *builtin_type_m68881_ext;
101 struct type *builtin_type_i960_ext;
102 struct type *builtin_type_m88110_ext;
103 struct type *builtin_type_m88110_harris_ext;
104 struct type *builtin_type_arm_ext_big;
105 struct type *builtin_type_arm_ext_littlebyte_bigword;
106 struct type *builtin_type_ia64_spill_big;
107 struct type *builtin_type_ia64_spill_little;
108 struct type *builtin_type_ia64_quad_big;
109 struct type *builtin_type_ia64_quad_little;
110 struct type *builtin_type_void_data_ptr;
111 struct type *builtin_type_void_func_ptr;
112 struct type *builtin_type_CORE_ADDR;
113 struct type *builtin_type_bfd_vma;
115 int opaque_type_resolution = 1;
116 int overload_debug = 0;
122 }; /* maximum extension is 128! FIXME */
124 static void add_name (struct extra *, char *);
125 static void add_mangled_type (struct extra *, struct type *);
127 static void cfront_mangle_name (struct type *, int, int);
129 static void print_bit_vector (B_TYPE *, int);
130 static void print_arg_types (struct type **, int);
131 static void dump_fn_fieldlists (struct type *, int);
132 static void print_cplus_stuff (struct type *, int);
133 static void virtual_base_list_aux (struct type *dclass);
136 /* Alloc a new type structure and fill it with some defaults. If
137 OBJFILE is non-NULL, then allocate the space for the type structure
138 in that objfile's type_obstack. */
141 alloc_type (struct objfile *objfile)
143 register struct type *type;
145 /* Alloc the structure and start off with all fields zeroed. */
149 type = (struct type *) xmalloc (sizeof (struct type));
153 type = (struct type *) obstack_alloc (&objfile->type_obstack,
154 sizeof (struct type));
155 OBJSTAT (objfile, n_types++);
157 memset ((char *) type, 0, sizeof (struct type));
159 /* Initialize the fields that might not be zero. */
161 TYPE_CODE (type) = TYPE_CODE_UNDEF;
162 TYPE_OBJFILE (type) = objfile;
163 TYPE_VPTR_FIELDNO (type) = -1;
164 TYPE_CV_TYPE (type) = type; /* chain back to itself */
165 TYPE_AS_TYPE (type) = type; /* ditto */
170 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
171 to a pointer to memory where the pointer type should be stored.
172 If *TYPEPTR is zero, update it to point to the pointer type we return.
173 We allocate new memory if needed. */
176 make_pointer_type (struct type *type, struct type **typeptr)
178 register struct type *ntype; /* New type */
179 struct objfile *objfile;
181 ntype = TYPE_POINTER_TYPE (type);
186 return ntype; /* Don't care about alloc, and have new type. */
187 else if (*typeptr == 0)
189 *typeptr = ntype; /* Tracking alloc, and we have new type. */
194 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
196 ntype = alloc_type (TYPE_OBJFILE (type));
201 /* We have storage, but need to reset it. */
204 objfile = TYPE_OBJFILE (ntype);
205 memset ((char *) ntype, 0, sizeof (struct type));
206 TYPE_OBJFILE (ntype) = objfile;
209 TYPE_TARGET_TYPE (ntype) = type;
210 TYPE_POINTER_TYPE (type) = ntype;
212 /* FIXME! Assume the machine has only one representation for pointers! */
214 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
215 TYPE_CODE (ntype) = TYPE_CODE_PTR;
217 /* Mark pointers as unsigned. The target converts between pointers
218 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
219 ADDRESS_TO_POINTER(). */
220 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
222 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
223 TYPE_POINTER_TYPE (type) = ntype;
228 /* Given a type TYPE, return a type of pointers to that type.
229 May need to construct such a type if this is the first use. */
232 lookup_pointer_type (struct type *type)
234 return make_pointer_type (type, (struct type **) 0);
237 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
238 to a pointer to memory where the reference type should be stored.
239 If *TYPEPTR is zero, update it to point to the reference type we return.
240 We allocate new memory if needed. */
243 make_reference_type (struct type *type, struct type **typeptr)
245 register struct type *ntype; /* New type */
246 struct objfile *objfile;
248 ntype = TYPE_REFERENCE_TYPE (type);
253 return ntype; /* Don't care about alloc, and have new type. */
254 else if (*typeptr == 0)
256 *typeptr = ntype; /* Tracking alloc, and we have new type. */
261 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
263 ntype = alloc_type (TYPE_OBJFILE (type));
268 /* We have storage, but need to reset it. */
271 objfile = TYPE_OBJFILE (ntype);
272 memset ((char *) ntype, 0, sizeof (struct type));
273 TYPE_OBJFILE (ntype) = objfile;
276 TYPE_TARGET_TYPE (ntype) = type;
277 TYPE_REFERENCE_TYPE (type) = ntype;
279 /* FIXME! Assume the machine has only one representation for references,
280 and that it matches the (only) representation for pointers! */
282 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
283 TYPE_CODE (ntype) = TYPE_CODE_REF;
285 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
286 TYPE_REFERENCE_TYPE (type) = ntype;
291 /* Same as above, but caller doesn't care about memory allocation details. */
294 lookup_reference_type (struct type *type)
296 return make_reference_type (type, (struct type **) 0);
299 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
300 to a pointer to memory where the function type should be stored.
301 If *TYPEPTR is zero, update it to point to the function type we return.
302 We allocate new memory if needed. */
305 make_function_type (struct type *type, struct type **typeptr)
307 register struct type *ntype; /* New type */
308 struct objfile *objfile;
310 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
312 ntype = alloc_type (TYPE_OBJFILE (type));
317 /* We have storage, but need to reset it. */
320 objfile = TYPE_OBJFILE (ntype);
321 memset ((char *) ntype, 0, sizeof (struct type));
322 TYPE_OBJFILE (ntype) = objfile;
325 TYPE_TARGET_TYPE (ntype) = type;
327 TYPE_LENGTH (ntype) = 1;
328 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
334 /* Given a type TYPE, return a type of functions that return that type.
335 May need to construct such a type if this is the first use. */
338 lookup_function_type (struct type *type)
340 return make_function_type (type, (struct type **) 0);
343 /* Identify address space identifier by name --
344 return the integer flag defined in gdbtypes.h. */
346 address_space_name_to_int (char *space_identifier)
348 /* Check for known address space delimiters. */
349 if (!strcmp (space_identifier, "code"))
350 return TYPE_FLAG_CODE_SPACE;
351 else if (!strcmp (space_identifier, "data"))
352 return TYPE_FLAG_DATA_SPACE;
354 error ("Unknown address space specifier: \"%s\"", space_identifier);
357 /* Identify address space identifier by integer flag as defined in
358 gdbtypes.h -- return the string version of the adress space name. */
361 address_space_int_to_name (int space_flag)
363 if (space_flag & TYPE_FLAG_CODE_SPACE)
365 else if (space_flag & TYPE_FLAG_DATA_SPACE)
371 /* Make an address-space-delimited variant of a type -- a type that
372 is identical to the one supplied except that it has an address
373 space attribute attached to it (such as "code" or "data").
375 This is for Harvard architectures. */
378 make_type_with_address_space (struct type *type, int space_flag)
384 if ((ntype->flags & space_flag) != 0)
386 ntype = TYPE_AS_TYPE (ntype);
387 } while (ntype != type);
389 /* Create a new, duplicate type. */
390 ntype = alloc_type (TYPE_OBJFILE (type));
391 /* Copy original type. */
392 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
394 /* Pointers or references to the original type are not relevant to
395 the new type; but if the original type is a pointer, the new type
396 points to the same thing (so TYPE_TARGET_TYPE remains unchanged). */
397 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
398 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
399 TYPE_CV_TYPE (ntype) = ntype;
401 /* Chain the new address-space-specific type to the old type. */
402 ntype->as_type = type->as_type;
403 type->as_type = ntype;
405 /* Now set the address-space flag, and return the new type. */
406 ntype->flags |= space_flag;
411 /* Make a "c-v" variant of a type -- a type that is identical to the
412 one supplied except that it may have const or volatile attributes
413 CNST is a flag for setting the const attribute
414 VOLTL is a flag for setting the volatile attribute
415 TYPE is the base type whose variant we are creating.
416 TYPEPTR, if nonzero, points
417 to a pointer to memory where the reference type should be stored.
418 If *TYPEPTR is zero, update it to point to the reference type we return.
419 We allocate new memory if needed. */
422 make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
424 register struct type *ntype; /* New type */
425 register struct type *tmp_type = type; /* tmp type */
426 struct objfile *objfile;
428 ntype = TYPE_CV_TYPE (type);
430 while (ntype != type)
432 if ((TYPE_CONST (ntype) == cnst) &&
433 (TYPE_VOLATILE (ntype) == voltl))
437 else if (*typeptr == 0)
439 *typeptr = ntype; /* Tracking alloc, and we have new type. */
444 ntype = TYPE_CV_TYPE (ntype);
447 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
449 ntype = alloc_type (TYPE_OBJFILE (type));
454 /* We have storage, but need to reset it. */
457 objfile = TYPE_OBJFILE (ntype);
458 /* memset ((char *) ntype, 0, sizeof (struct type)); */
459 TYPE_OBJFILE (ntype) = objfile;
462 /* Copy original type */
463 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
464 /* But zero out fields that shouldn't be copied */
465 TYPE_POINTER_TYPE (ntype) = (struct type *) 0; /* Need new pointer kind */
466 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; /* Need new referene kind */
467 TYPE_AS_TYPE (ntype) = ntype; /* Need new address-space kind. */
468 /* Note: TYPE_TARGET_TYPE can be left as is */
470 /* Set flags appropriately */
472 TYPE_FLAGS (ntype) |= TYPE_FLAG_CONST;
474 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_CONST;
477 TYPE_FLAGS (ntype) |= TYPE_FLAG_VOLATILE;
479 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_VOLATILE;
481 /* Fix the chain of cv variants */
482 TYPE_CV_TYPE (ntype) = type;
483 TYPE_CV_TYPE (tmp_type) = ntype;
488 /* When reading in a class type, we may have created references to
489 cv-qualified versions of the type (in method arguments, for
490 instance). Update everything on the cv ring from the primary
493 The only reason we do not need to do the same thing for address
494 spaces is that type readers do not create address space qualified
497 finish_cv_type (struct type *type)
499 struct type *ntype, *cv_type, *ptr_type, *ref_type;
502 gdb_assert (!TYPE_CONST (type) && !TYPE_VOLATILE (type));
505 while ((ntype = TYPE_CV_TYPE (ntype)) != type)
508 cv_flags = TYPE_FLAGS (ntype) & (TYPE_FLAG_VOLATILE | TYPE_FLAG_CONST);
510 /* If any reference or pointer types were created, save them too. */
511 ptr_type = TYPE_POINTER_TYPE (ntype);
512 ref_type = TYPE_REFERENCE_TYPE (ntype);
514 /* Don't disturb the CV chain. */
515 cv_type = TYPE_CV_TYPE (ntype);
517 /* Verify that we haven't added any address-space qualified types,
519 gdb_assert (ntype == TYPE_AS_TYPE (ntype));
521 /* Copy original type */
522 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
524 /* Restore everything. */
525 TYPE_POINTER_TYPE (ntype) = ptr_type;
526 TYPE_REFERENCE_TYPE (ntype) = ref_type;
527 TYPE_CV_TYPE (ntype) = cv_type;
528 TYPE_FLAGS (ntype) = TYPE_FLAGS (ntype) | cv_flags;
530 TYPE_AS_TYPE (ntype) = ntype;
534 /* Replace the contents of ntype with the type *type.
536 In order to build recursive types, it's inevitable that we'll need
537 to update types in place --- but this sort of indiscriminate
538 smashing is ugly, and needs to be replaced with something more
539 controlled. For example, Daniel Jacobowitz has suggested moving
540 the fields common to a set of c/v variants into their own object,
541 which the variants would share.
543 This function does not handle the replacement type being
544 cv-qualified; it could be easily fixed to, but it would be better
545 to just change the whole approach. */
547 replace_type (struct type *ntype, struct type *type)
549 struct type *cv_chain, *as_chain, *ptr, *ref;
551 cv_chain = TYPE_CV_TYPE (ntype);
552 as_chain = TYPE_AS_TYPE (ntype);
553 ptr = TYPE_POINTER_TYPE (ntype);
554 ref = TYPE_REFERENCE_TYPE (ntype);
558 TYPE_POINTER_TYPE (ntype) = ptr;
559 TYPE_REFERENCE_TYPE (ntype) = ref;
560 TYPE_CV_TYPE (ntype) = cv_chain;
561 TYPE_AS_TYPE (ntype) = as_chain;
563 finish_cv_type (ntype);
566 /* Implement direct support for MEMBER_TYPE in GNU C++.
567 May need to construct such a type if this is the first use.
568 The TYPE is the type of the member. The DOMAIN is the type
569 of the aggregate that the member belongs to. */
572 lookup_member_type (struct type *type, struct type *domain)
574 register struct type *mtype;
576 mtype = alloc_type (TYPE_OBJFILE (type));
577 smash_to_member_type (mtype, domain, type);
581 /* Allocate a stub method whose return type is TYPE.
582 This apparently happens for speed of symbol reading, since parsing
583 out the arguments to the method is cpu-intensive, the way we are doing
584 it. So, we will fill in arguments later.
585 This always returns a fresh type. */
588 allocate_stub_method (struct type *type)
592 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
593 TYPE_OBJFILE (type));
594 TYPE_TARGET_TYPE (mtype) = type;
595 /* _DOMAIN_TYPE (mtype) = unknown yet */
596 /* _ARG_TYPES (mtype) = unknown yet */
600 /* Create a range type using either a blank type supplied in RESULT_TYPE,
601 or creating a new type, inheriting the objfile from INDEX_TYPE.
603 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
604 HIGH_BOUND, inclusive.
606 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
607 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
610 create_range_type (struct type *result_type, struct type *index_type,
611 int low_bound, int high_bound)
613 if (result_type == NULL)
615 result_type = alloc_type (TYPE_OBJFILE (index_type));
617 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
618 TYPE_TARGET_TYPE (result_type) = index_type;
619 if (TYPE_STUB (index_type))
620 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
622 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
623 TYPE_NFIELDS (result_type) = 2;
624 TYPE_FIELDS (result_type) = (struct field *)
625 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
626 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
627 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
628 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
629 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
630 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
633 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
635 return (result_type);
638 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
639 Return 1 of type is a range type, 0 if it is discrete (and bounds
640 will fit in LONGEST), or -1 otherwise. */
643 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
645 CHECK_TYPEDEF (type);
646 switch (TYPE_CODE (type))
648 case TYPE_CODE_RANGE:
649 *lowp = TYPE_LOW_BOUND (type);
650 *highp = TYPE_HIGH_BOUND (type);
653 if (TYPE_NFIELDS (type) > 0)
655 /* The enums may not be sorted by value, so search all
659 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
660 for (i = 0; i < TYPE_NFIELDS (type); i++)
662 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
663 *lowp = TYPE_FIELD_BITPOS (type, i);
664 if (TYPE_FIELD_BITPOS (type, i) > *highp)
665 *highp = TYPE_FIELD_BITPOS (type, i);
668 /* Set unsigned indicator if warranted. */
671 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
685 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
687 if (!TYPE_UNSIGNED (type))
689 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
693 /* ... fall through for unsigned ints ... */
696 /* This round-about calculation is to avoid shifting by
697 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
698 if TYPE_LENGTH (type) == sizeof (LONGEST). */
699 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
700 *highp = (*highp - 1) | *highp;
707 /* Create an array type using either a blank type supplied in RESULT_TYPE,
708 or creating a new type, inheriting the objfile from RANGE_TYPE.
710 Elements will be of type ELEMENT_TYPE, the indices will be of type
713 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
714 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
717 create_array_type (struct type *result_type, struct type *element_type,
718 struct type *range_type)
720 LONGEST low_bound, high_bound;
722 if (result_type == NULL)
724 result_type = alloc_type (TYPE_OBJFILE (range_type));
726 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
727 TYPE_TARGET_TYPE (result_type) = element_type;
728 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
729 low_bound = high_bound = 0;
730 CHECK_TYPEDEF (element_type);
731 TYPE_LENGTH (result_type) =
732 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
733 TYPE_NFIELDS (result_type) = 1;
734 TYPE_FIELDS (result_type) =
735 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
736 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
737 TYPE_FIELD_TYPE (result_type, 0) = range_type;
738 TYPE_VPTR_FIELDNO (result_type) = -1;
740 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
741 if (TYPE_LENGTH (result_type) == 0)
742 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
744 return (result_type);
747 /* Create a string type using either a blank type supplied in RESULT_TYPE,
748 or creating a new type. String types are similar enough to array of
749 char types that we can use create_array_type to build the basic type
750 and then bash it into a string type.
752 For fixed length strings, the range type contains 0 as the lower
753 bound and the length of the string minus one as the upper bound.
755 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
756 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
759 create_string_type (struct type *result_type, struct type *range_type)
761 result_type = create_array_type (result_type,
762 *current_language->string_char_type,
764 TYPE_CODE (result_type) = TYPE_CODE_STRING;
765 return (result_type);
769 create_set_type (struct type *result_type, struct type *domain_type)
771 LONGEST low_bound, high_bound, bit_length;
772 if (result_type == NULL)
774 result_type = alloc_type (TYPE_OBJFILE (domain_type));
776 TYPE_CODE (result_type) = TYPE_CODE_SET;
777 TYPE_NFIELDS (result_type) = 1;
778 TYPE_FIELDS (result_type) = (struct field *)
779 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
780 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
782 if (!TYPE_STUB (domain_type))
784 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
785 low_bound = high_bound = 0;
786 bit_length = high_bound - low_bound + 1;
787 TYPE_LENGTH (result_type)
788 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
790 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
793 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
795 return (result_type);
798 /* Construct and return a type of the form:
799 struct NAME { ELT_TYPE ELT_NAME[N]; }
800 We use these types for SIMD registers. For example, the type of
801 the SSE registers on the late x86-family processors is:
802 struct __builtin_v4sf { float f[4]; }
803 built by the function call:
804 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
805 The type returned is a permanent type, allocated using malloc; it
806 doesn't live in any objfile's obstack. */
808 init_simd_type (char *name,
809 struct type *elt_type,
813 struct type *simd_type;
814 struct type *array_type;
816 simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
817 array_type = create_array_type (0, elt_type,
818 create_range_type (0, builtin_type_int,
820 append_composite_type_field (simd_type, elt_name, array_type);
825 init_vector_type (struct type *elt_type, int n)
827 struct type *array_type;
829 array_type = create_array_type (0, elt_type,
830 create_range_type (0, builtin_type_int,
832 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
837 build_builtin_type_vec128 (void)
839 /* Construct a type for the 128 bit registers. The type we're
842 union __gdb_builtin_type_vec128
854 t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
855 append_composite_type_field (t, "uint128", builtin_type_int128);
856 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
857 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
858 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
859 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
864 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
865 A MEMBER is a wierd thing -- it amounts to a typed offset into
866 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
867 include the offset (that's the value of the MEMBER itself), but does
868 include the structure type into which it points (for some reason).
870 When "smashing" the type, we preserve the objfile that the
871 old type pointed to, since we aren't changing where the type is actually
875 smash_to_member_type (struct type *type, struct type *domain,
876 struct type *to_type)
878 struct objfile *objfile;
880 objfile = TYPE_OBJFILE (type);
882 memset ((char *) type, 0, sizeof (struct type));
883 TYPE_OBJFILE (type) = objfile;
884 TYPE_TARGET_TYPE (type) = to_type;
885 TYPE_DOMAIN_TYPE (type) = domain;
886 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
887 TYPE_CODE (type) = TYPE_CODE_MEMBER;
890 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
891 METHOD just means `function that gets an extra "this" argument'.
893 When "smashing" the type, we preserve the objfile that the
894 old type pointed to, since we aren't changing where the type is actually
898 smash_to_method_type (struct type *type, struct type *domain,
899 struct type *to_type, struct type **args)
901 struct objfile *objfile;
903 objfile = TYPE_OBJFILE (type);
905 memset ((char *) type, 0, sizeof (struct type));
906 TYPE_OBJFILE (type) = objfile;
907 TYPE_TARGET_TYPE (type) = to_type;
908 TYPE_DOMAIN_TYPE (type) = domain;
909 TYPE_ARG_TYPES (type) = args;
910 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
911 TYPE_CODE (type) = TYPE_CODE_METHOD;
914 /* Return a typename for a struct/union/enum type without "struct ",
915 "union ", or "enum ". If the type has a NULL name, return NULL. */
918 type_name_no_tag (register const struct type *type)
920 if (TYPE_TAG_NAME (type) != NULL)
921 return TYPE_TAG_NAME (type);
923 /* Is there code which expects this to return the name if there is no
924 tag name? My guess is that this is mainly used for C++ in cases where
925 the two will always be the same. */
926 return TYPE_NAME (type);
929 /* Lookup a primitive type named NAME.
930 Return zero if NAME is not a primitive type. */
933 lookup_primitive_typename (char *name)
935 struct type **const *p;
937 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
939 if (STREQ ((**p)->name, name))
947 /* Lookup a typedef or primitive type named NAME,
948 visible in lexical block BLOCK.
949 If NOERR is nonzero, return zero if NAME is not suitably defined. */
952 lookup_typename (char *name, struct block *block, int noerr)
954 register struct symbol *sym;
955 register struct type *tmp;
957 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
958 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
960 tmp = lookup_primitive_typename (name);
965 else if (!tmp && noerr)
971 error ("No type named %s.", name);
974 return (SYMBOL_TYPE (sym));
978 lookup_unsigned_typename (char *name)
980 char *uns = alloca (strlen (name) + 10);
982 strcpy (uns, "unsigned ");
983 strcpy (uns + 9, name);
984 return (lookup_typename (uns, (struct block *) NULL, 0));
988 lookup_signed_typename (char *name)
991 char *uns = alloca (strlen (name) + 8);
993 strcpy (uns, "signed ");
994 strcpy (uns + 7, name);
995 t = lookup_typename (uns, (struct block *) NULL, 1);
996 /* If we don't find "signed FOO" just try again with plain "FOO". */
999 return lookup_typename (name, (struct block *) NULL, 0);
1002 /* Lookup a structure type named "struct NAME",
1003 visible in lexical block BLOCK. */
1006 lookup_struct (char *name, struct block *block)
1008 register struct symbol *sym;
1010 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
1011 (struct symtab **) NULL);
1015 error ("No struct type named %s.", name);
1017 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1019 error ("This context has class, union or enum %s, not a struct.", name);
1021 return (SYMBOL_TYPE (sym));
1024 /* Lookup a union type named "union NAME",
1025 visible in lexical block BLOCK. */
1028 lookup_union (char *name, struct block *block)
1030 register struct symbol *sym;
1033 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
1034 (struct symtab **) NULL);
1037 error ("No union type named %s.", name);
1039 t = SYMBOL_TYPE (sym);
1041 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1044 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1045 * a further "declared_type" field to discover it is really a union.
1047 if (HAVE_CPLUS_STRUCT (t))
1048 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1051 /* If we get here, it's not a union */
1052 error ("This context has class, struct or enum %s, not a union.", name);
1056 /* Lookup an enum type named "enum NAME",
1057 visible in lexical block BLOCK. */
1060 lookup_enum (char *name, struct block *block)
1062 register struct symbol *sym;
1064 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
1065 (struct symtab **) NULL);
1068 error ("No enum type named %s.", name);
1070 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1072 error ("This context has class, struct or union %s, not an enum.", name);
1074 return (SYMBOL_TYPE (sym));
1077 /* Lookup a template type named "template NAME<TYPE>",
1078 visible in lexical block BLOCK. */
1081 lookup_template_type (char *name, struct type *type, struct block *block)
1084 char *nam = (char *) alloca (strlen (name) + strlen (type->name) + 4);
1087 strcat (nam, type->name);
1088 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1090 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
1094 error ("No template type named %s.", name);
1096 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1098 error ("This context has class, union or enum %s, not a struct.", name);
1100 return (SYMBOL_TYPE (sym));
1103 /* Given a type TYPE, lookup the type of the component of type named NAME.
1105 TYPE can be either a struct or union, or a pointer or reference to a struct or
1106 union. If it is a pointer or reference, its target type is automatically used.
1107 Thus '.' and '->' are interchangable, as specified for the definitions of the
1108 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1110 If NOERR is nonzero, return zero if NAME is not suitably defined.
1111 If NAME is the name of a baseclass type, return that type. */
1114 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1120 CHECK_TYPEDEF (type);
1121 if (TYPE_CODE (type) != TYPE_CODE_PTR
1122 && TYPE_CODE (type) != TYPE_CODE_REF)
1124 type = TYPE_TARGET_TYPE (type);
1127 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1128 TYPE_CODE (type) != TYPE_CODE_UNION)
1130 target_terminal_ours ();
1131 gdb_flush (gdb_stdout);
1132 fprintf_unfiltered (gdb_stderr, "Type ");
1133 type_print (type, "", gdb_stderr, -1);
1134 error (" is not a structure or union type.");
1138 /* FIXME: This change put in by Michael seems incorrect for the case where
1139 the structure tag name is the same as the member name. I.E. when doing
1140 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1145 typename = type_name_no_tag (type);
1146 if (typename != NULL && STREQ (typename, name))
1151 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1153 char *t_field_name = TYPE_FIELD_NAME (type, i);
1155 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1157 return TYPE_FIELD_TYPE (type, i);
1161 /* OK, it's not in this class. Recursively check the baseclasses. */
1162 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1166 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1178 target_terminal_ours ();
1179 gdb_flush (gdb_stdout);
1180 fprintf_unfiltered (gdb_stderr, "Type ");
1181 type_print (type, "", gdb_stderr, -1);
1182 fprintf_unfiltered (gdb_stderr, " has no component named ");
1183 fputs_filtered (name, gdb_stderr);
1185 return (struct type *) -1; /* For lint */
1188 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1189 valid. Callers should be aware that in some cases (for example,
1190 the type or one of its baseclasses is a stub type and we are
1191 debugging a .o file), this function will not be able to find the virtual
1192 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1193 will remain NULL. */
1196 fill_in_vptr_fieldno (struct type *type)
1198 CHECK_TYPEDEF (type);
1200 if (TYPE_VPTR_FIELDNO (type) < 0)
1204 /* We must start at zero in case the first (and only) baseclass is
1205 virtual (and hence we cannot share the table pointer). */
1206 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1208 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
1209 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
1211 TYPE_VPTR_FIELDNO (type)
1212 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
1213 TYPE_VPTR_BASETYPE (type)
1214 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
1221 /* Find the method and field indices for the destructor in class type T.
1222 Return 1 if the destructor was found, otherwise, return 0. */
1225 get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
1229 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1232 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1234 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1236 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1247 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1249 If this is a stubbed struct (i.e. declared as struct foo *), see if
1250 we can find a full definition in some other file. If so, copy this
1251 definition, so we can use it in future. There used to be a comment (but
1252 not any code) that if we don't find a full definition, we'd set a flag
1253 so we don't spend time in the future checking the same type. That would
1254 be a mistake, though--we might load in more symbols which contain a
1255 full definition for the type.
1257 This used to be coded as a macro, but I don't think it is called
1258 often enough to merit such treatment. */
1260 struct complaint stub_noname_complaint =
1261 {"stub type has NULL name", 0, 0};
1264 check_typedef (struct type *type)
1266 struct type *orig_type = type;
1267 int is_const, is_volatile;
1269 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1271 if (!TYPE_TARGET_TYPE (type))
1276 /* It is dangerous to call lookup_symbol if we are currently
1277 reading a symtab. Infinite recursion is one danger. */
1278 if (currently_reading_symtab)
1281 name = type_name_no_tag (type);
1282 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1283 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1284 as appropriate? (this code was written before TYPE_NAME and
1285 TYPE_TAG_NAME were separate). */
1288 complain (&stub_noname_complaint);
1291 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
1292 (struct symtab **) NULL);
1294 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1296 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1298 type = TYPE_TARGET_TYPE (type);
1301 is_const = TYPE_CONST (type);
1302 is_volatile = TYPE_VOLATILE (type);
1304 /* If this is a struct/class/union with no fields, then check whether a
1305 full definition exists somewhere else. This is for systems where a
1306 type definition with no fields is issued for such types, instead of
1307 identifying them as stub types in the first place */
1309 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1311 char *name = type_name_no_tag (type);
1312 struct type *newtype;
1315 complain (&stub_noname_complaint);
1318 newtype = lookup_transparent_type (name);
1320 make_cv_type (is_const, is_volatile, newtype, &type);
1322 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1323 else if (TYPE_STUB (type) && !currently_reading_symtab)
1325 char *name = type_name_no_tag (type);
1326 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1327 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1328 as appropriate? (this code was written before TYPE_NAME and
1329 TYPE_TAG_NAME were separate). */
1333 complain (&stub_noname_complaint);
1336 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL);
1338 make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type);
1341 if (TYPE_TARGET_STUB (type))
1343 struct type *range_type;
1344 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1346 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1349 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1350 && TYPE_NFIELDS (type) == 1
1351 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1352 == TYPE_CODE_RANGE))
1354 /* Now recompute the length of the array type, based on its
1355 number of elements and the target type's length. */
1356 TYPE_LENGTH (type) =
1357 ((TYPE_FIELD_BITPOS (range_type, 1)
1358 - TYPE_FIELD_BITPOS (range_type, 0)
1360 * TYPE_LENGTH (target_type));
1361 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1363 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1365 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1366 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1369 /* Cache TYPE_LENGTH for future use. */
1370 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1374 /* New code added to support parsing of Cfront stabs strings */
1375 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1376 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1379 add_name (struct extra *pextras, char *n)
1383 if ((nlen = (n ? strlen (n) : 0)) == 0)
1385 sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1386 pextras->len = strlen (pextras->str);
1390 add_mangled_type (struct extra *pextras, struct type *t)
1392 enum type_code tcode;
1396 tcode = TYPE_CODE (t);
1397 tlen = TYPE_LENGTH (t);
1398 tflags = TYPE_FLAGS (t);
1399 tname = TYPE_NAME (t);
1400 /* args of "..." seem to get mangled as "e" */
1418 if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1431 static struct complaint msg =
1432 {"Bad int type code length x%x\n", 0, 0};
1434 complain (&msg, tlen);
1453 static struct complaint msg =
1454 {"Bad float type code length x%x\n", 0, 0};
1455 complain (&msg, tlen);
1461 /* followed by what it's a ref to */
1465 /* followed by what it's a ptr to */
1467 case TYPE_CODE_TYPEDEF:
1469 static struct complaint msg =
1470 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1473 /* followed by type bytes & name */
1475 case TYPE_CODE_FUNC:
1477 /* followed by func's arg '_' & ret types */
1479 case TYPE_CODE_VOID:
1482 case TYPE_CODE_METHOD:
1484 /* followed by name of class and func's arg '_' & ret types */
1485 add_name (pextras, tname);
1486 ADD_EXTRA ('F'); /* then mangle function */
1488 case TYPE_CODE_STRUCT: /* C struct */
1489 case TYPE_CODE_UNION: /* C union */
1490 case TYPE_CODE_ENUM: /* Enumeration type */
1491 /* followed by name of type */
1492 add_name (pextras, tname);
1495 /* errors possible types/not supported */
1496 case TYPE_CODE_CHAR:
1497 case TYPE_CODE_ARRAY: /* Array type */
1498 case TYPE_CODE_MEMBER: /* Member type */
1499 case TYPE_CODE_BOOL:
1500 case TYPE_CODE_COMPLEX: /* Complex float */
1501 case TYPE_CODE_UNDEF:
1502 case TYPE_CODE_SET: /* Pascal sets */
1503 case TYPE_CODE_RANGE:
1504 case TYPE_CODE_STRING:
1505 case TYPE_CODE_BITSTRING:
1506 case TYPE_CODE_ERROR:
1509 static struct complaint msg =
1510 {"Unknown type code x%x\n", 0, 0};
1511 complain (&msg, tcode);
1515 add_mangled_type (pextras, t->target_type);
1520 cfront_mangle_name (struct type *type, int i, int j)
1523 char *mangled_name = gdb_mangle_name (type, i, j);
1525 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1527 /* kludge to support cfront methods - gdb expects to find "F" for
1528 ARM_mangled names, so when we mangle, we have to add it here */
1532 char *arm_mangled_name;
1533 struct fn_field *method = &f[j];
1534 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1535 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1536 char *newname = type_name_no_tag (type);
1538 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1539 int nargs = TYPE_NFIELDS (ftype); /* number of args */
1540 struct extra extras, *pextras = &extras;
1543 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1546 /* add args here! */
1547 if (nargs <= 1) /* no args besides this */
1551 for (k = 1; k < nargs; k++)
1554 t = TYPE_FIELD_TYPE (ftype, k);
1555 add_mangled_type (pextras, t);
1559 printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1560 xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str);
1561 xfree (mangled_name);
1562 mangled_name = arm_mangled_name;
1568 /* End of new code added to support parsing of Cfront stabs strings */
1570 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1571 silently return builtin_type_void. */
1574 safe_parse_type (char *p, int length)
1576 struct ui_file *saved_gdb_stderr;
1579 /* Suppress error messages. */
1580 saved_gdb_stderr = gdb_stderr;
1581 gdb_stderr = ui_file_new ();
1583 /* Call parse_and_eval_type() without fear of longjmp()s. */
1584 if (!gdb_parse_and_eval_type (p, length, &type))
1585 type = builtin_type_void;
1587 /* Stop suppressing error messages. */
1588 ui_file_delete (gdb_stderr);
1589 gdb_stderr = saved_gdb_stderr;
1594 /* Ugly hack to convert method stubs into method types.
1596 He ain't kiddin'. This demangles the name of the method into a string
1597 including argument types, parses out each argument type, generates
1598 a string casting a zero to that type, evaluates the string, and stuffs
1599 the resulting type into an argtype vector!!! Then it knows the type
1600 of the whole function (including argument types for overloading),
1601 which info used to be in the stab's but was removed to hack back
1602 the space required for them. */
1605 check_stub_method (struct type *type, int method_id, int signature_id)
1608 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1609 char *demangled_name = cplus_demangle (mangled_name,
1610 DMGL_PARAMS | DMGL_ANSI);
1611 char *argtypetext, *p;
1612 int depth = 0, argcount = 1;
1613 struct type **argtypes;
1616 /* Make sure we got back a function string that we can use. */
1618 p = strchr (demangled_name, '(');
1622 if (demangled_name == NULL || p == NULL)
1623 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1625 /* Now, read in the parameters that define this type. */
1630 if (*p == '(' || *p == '<')
1634 else if (*p == ')' || *p == '>')
1638 else if (*p == ',' && depth == 0)
1646 /* We need two more slots: one for the THIS pointer, and one for the
1647 NULL [...] or void [end of arglist]. */
1649 argtypes = (struct type **)
1650 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
1652 /* FIXME: This is wrong for static member functions. */
1653 argtypes[0] = lookup_pointer_type (type);
1656 if (*p != ')') /* () means no args, skip while */
1661 if (depth <= 0 && (*p == ',' || *p == ')'))
1663 /* Avoid parsing of ellipsis, they will be handled below. */
1664 if (strncmp (argtypetext, "...", p - argtypetext) != 0)
1666 argtypes[argcount] =
1667 safe_parse_type (argtypetext, p - argtypetext);
1670 argtypetext = p + 1;
1673 if (*p == '(' || *p == '<')
1677 else if (*p == ')' || *p == '>')
1686 if (p[-2] != '.') /* Not '...' */
1688 argtypes[argcount] = builtin_type_void; /* List terminator */
1692 argtypes[argcount] = NULL; /* Ellist terminator */
1695 xfree (demangled_name);
1697 f = TYPE_FN_FIELDLIST1 (type, method_id);
1699 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1701 /* Now update the old "stub" type into a real type. */
1702 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1703 TYPE_DOMAIN_TYPE (mtype) = type;
1704 TYPE_ARG_TYPES (mtype) = argtypes;
1705 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1706 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1709 const struct cplus_struct_type cplus_struct_default;
1712 allocate_cplus_struct_type (struct type *type)
1714 if (!HAVE_CPLUS_STRUCT (type))
1716 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1717 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1718 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1722 /* Helper function to initialize the standard scalar types.
1724 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1725 of the string pointed to by name in the type_obstack for that objfile,
1726 and initialize the type name to that copy. There are places (mipsread.c
1727 in particular, where init_type is called with a NULL value for NAME). */
1730 init_type (enum type_code code, int length, int flags, char *name,
1731 struct objfile *objfile)
1733 register struct type *type;
1735 type = alloc_type (objfile);
1736 TYPE_CODE (type) = code;
1737 TYPE_LENGTH (type) = length;
1738 TYPE_FLAGS (type) |= flags;
1739 if ((name != NULL) && (objfile != NULL))
1742 obsavestring (name, strlen (name), &objfile->type_obstack);
1746 TYPE_NAME (type) = name;
1751 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1753 INIT_CPLUS_SPECIFIC (type);
1758 /* Helper function. Create an empty composite type. */
1761 init_composite_type (char *name, enum type_code code)
1764 gdb_assert (code == TYPE_CODE_STRUCT
1765 || code == TYPE_CODE_UNION);
1766 t = init_type (code, 0, 0, NULL, NULL);
1767 TYPE_TAG_NAME (t) = name;
1771 /* Helper function. Append a field to a composite type. */
1774 append_composite_type_field (struct type *t, char *name, struct type *field)
1777 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1778 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1779 sizeof (struct field) * TYPE_NFIELDS (t));
1780 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1781 memset (f, 0, sizeof f[0]);
1782 FIELD_TYPE (f[0]) = field;
1783 FIELD_NAME (f[0]) = name;
1784 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1786 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1787 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1789 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1791 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1792 if (TYPE_NFIELDS (t) > 1)
1794 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1795 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1800 /* Look up a fundamental type for the specified objfile.
1801 May need to construct such a type if this is the first use.
1803 Some object file formats (ELF, COFF, etc) do not define fundamental
1804 types such as "int" or "double". Others (stabs for example), do
1805 define fundamental types.
1807 For the formats which don't provide fundamental types, gdb can create
1808 such types, using defaults reasonable for the current language and
1809 the current target machine.
1811 NOTE: This routine is obsolescent. Each debugging format reader
1812 should manage it's own fundamental types, either creating them from
1813 suitable defaults or reading them from the debugging information,
1814 whichever is appropriate. The DWARF reader has already been
1815 fixed to do this. Once the other readers are fixed, this routine
1816 will go away. Also note that fundamental types should be managed
1817 on a compilation unit basis in a multi-language environment, not
1818 on a linkage unit basis as is done here. */
1822 lookup_fundamental_type (struct objfile *objfile, int typeid)
1824 register struct type **typep;
1825 register int nbytes;
1827 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1829 error ("internal error - invalid fundamental type id %d", typeid);
1832 /* If this is the first time we need a fundamental type for this objfile
1833 then we need to initialize the vector of type pointers. */
1835 if (objfile->fundamental_types == NULL)
1837 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1838 objfile->fundamental_types = (struct type **)
1839 obstack_alloc (&objfile->type_obstack, nbytes);
1840 memset ((char *) objfile->fundamental_types, 0, nbytes);
1841 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1844 /* Look for this particular type in the fundamental type vector. If one is
1845 not found, create and install one appropriate for the current language. */
1847 typep = objfile->fundamental_types + typeid;
1850 *typep = create_fundamental_type (objfile, typeid);
1857 can_dereference (struct type *t)
1859 /* FIXME: Should we return true for references as well as pointers? */
1863 && TYPE_CODE (t) == TYPE_CODE_PTR
1864 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1868 is_integral_type (struct type *t)
1873 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1874 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1875 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1876 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1877 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1880 /* Chill varying string and arrays are represented as follows:
1882 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1884 Return true if TYPE is such a Chill varying type. */
1887 chill_varying_type (struct type *type)
1889 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1890 || TYPE_NFIELDS (type) != 2
1891 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1896 /* Check whether BASE is an ancestor or base class or DCLASS
1897 Return 1 if so, and 0 if not.
1898 Note: callers may want to check for identity of the types before
1899 calling this function -- identical types are considered to satisfy
1900 the ancestor relationship even if they're identical */
1903 is_ancestor (struct type *base, struct type *dclass)
1907 CHECK_TYPEDEF (base);
1908 CHECK_TYPEDEF (dclass);
1912 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
1913 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1916 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1917 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1925 /* See whether DCLASS has a virtual table. This routine is aimed at
1926 the HP/Taligent ANSI C++ runtime model, and may not work with other
1927 runtime models. Return 1 => Yes, 0 => No. */
1930 has_vtable (struct type *dclass)
1932 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1933 has virtual functions or virtual bases. */
1937 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1940 /* First check for the presence of virtual bases */
1941 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1942 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1943 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1946 /* Next check for virtual functions */
1947 if (TYPE_FN_FIELDLISTS (dclass))
1948 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1949 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1952 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1953 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1954 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1955 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1956 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1959 /* Well, maybe we don't need a virtual table */
1963 /* Return a pointer to the "primary base class" of DCLASS.
1965 A NULL return indicates that DCLASS has no primary base, or that it
1966 couldn't be found (insufficient information).
1968 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1969 and may not work with other runtime models. */
1972 primary_base_class (struct type *dclass)
1974 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1975 is the first directly inherited, non-virtual base class that
1976 requires a virtual table */
1980 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1983 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1984 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1985 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1986 return TYPE_FIELD_TYPE (dclass, i);
1991 /* Global manipulated by virtual_base_list[_aux]() */
1993 static struct vbase *current_vbase_list = NULL;
1995 /* Return a pointer to a null-terminated list of struct vbase
1996 items. The vbasetype pointer of each item in the list points to the
1997 type information for a virtual base of the argument DCLASS.
1999 Helper function for virtual_base_list().
2000 Note: the list goes backward, right-to-left. virtual_base_list()
2001 copies the items out in reverse order. */
2004 virtual_base_list_aux (struct type *dclass)
2006 struct vbase *tmp_vbase;
2009 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
2012 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
2014 /* Recurse on this ancestor, first */
2015 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
2017 /* If this current base is itself virtual, add it to the list */
2018 if (BASETYPE_VIA_VIRTUAL (dclass, i))
2020 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
2022 /* Check if base already recorded */
2023 tmp_vbase = current_vbase_list;
2026 if (tmp_vbase->vbasetype == basetype)
2027 break; /* found it */
2028 tmp_vbase = tmp_vbase->next;
2031 if (!tmp_vbase) /* normal exit from loop */
2033 /* Allocate new item for this virtual base */
2034 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
2036 /* Stick it on at the end of the list */
2037 tmp_vbase->vbasetype = basetype;
2038 tmp_vbase->next = current_vbase_list;
2039 current_vbase_list = tmp_vbase;
2042 } /* for loop over bases */
2046 /* Compute the list of virtual bases in the right order. Virtual
2047 bases are laid out in the object's memory area in order of their
2048 occurrence in a depth-first, left-to-right search through the
2051 Argument DCLASS is the type whose virtual bases are required.
2052 Return value is the address of a null-terminated array of pointers
2053 to struct type items.
2055 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2056 and may not work with other runtime models.
2058 This routine merely hands off the argument to virtual_base_list_aux()
2059 and then copies the result into an array to save space. */
2062 virtual_base_list (struct type *dclass)
2064 register struct vbase *tmp_vbase;
2065 register struct vbase *tmp_vbase_2;
2068 struct type **vbase_array;
2070 current_vbase_list = NULL;
2071 virtual_base_list_aux (dclass);
2073 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2078 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
2080 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
2081 vbase_array[i] = tmp_vbase->vbasetype;
2083 /* Get rid of constructed chain */
2084 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2087 tmp_vbase = tmp_vbase->next;
2088 xfree (tmp_vbase_2);
2089 tmp_vbase_2 = tmp_vbase;
2092 vbase_array[count] = NULL;
2096 /* Return the length of the virtual base list of the type DCLASS. */
2099 virtual_base_list_length (struct type *dclass)
2102 register struct vbase *tmp_vbase;
2104 current_vbase_list = NULL;
2105 virtual_base_list_aux (dclass);
2107 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2112 /* Return the number of elements of the virtual base list of the type
2113 DCLASS, ignoring those appearing in the primary base (and its
2114 primary base, recursively). */
2117 virtual_base_list_length_skip_primaries (struct type *dclass)
2120 register struct vbase *tmp_vbase;
2121 struct type *primary;
2123 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2126 return virtual_base_list_length (dclass);
2128 current_vbase_list = NULL;
2129 virtual_base_list_aux (dclass);
2131 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
2133 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
2141 /* Return the index (position) of type BASE, which is a virtual base
2142 class of DCLASS, in the latter's virtual base list. A return of -1
2143 indicates "not found" or a problem. */
2146 virtual_base_index (struct type *base, struct type *dclass)
2148 register struct type *vbase;
2151 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2152 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2156 vbase = virtual_base_list (dclass)[0];
2161 vbase = virtual_base_list (dclass)[++i];
2164 return vbase ? i : -1;
2169 /* Return the index (position) of type BASE, which is a virtual base
2170 class of DCLASS, in the latter's virtual base list. Skip over all
2171 bases that may appear in the virtual base list of the primary base
2172 class of DCLASS (recursively). A return of -1 indicates "not
2173 found" or a problem. */
2176 virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
2178 register struct type *vbase;
2180 struct type *primary;
2182 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2183 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2186 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2190 vbase = virtual_base_list (dclass)[0];
2193 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2197 vbase = virtual_base_list (dclass)[++i];
2200 return vbase ? j : -1;
2203 /* Return position of a derived class DCLASS in the list of
2204 * primary bases starting with the remotest ancestor.
2205 * Position returned is 0-based. */
2208 class_index_in_primary_list (struct type *dclass)
2210 struct type *pbc; /* primary base class */
2212 /* Simply recurse on primary base */
2213 pbc = TYPE_PRIMARY_BASE (dclass);
2215 return 1 + class_index_in_primary_list (pbc);
2220 /* Return a count of the number of virtual functions a type has.
2221 * This includes all the virtual functions it inherits from its
2225 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2226 * functions only once (latest redefinition)
2230 count_virtual_fns (struct type *dclass)
2232 int fn, oi; /* function and overloaded instance indices */
2233 int vfuncs; /* count to return */
2235 /* recurse on bases that can share virtual table */
2236 struct type *pbc = primary_base_class (dclass);
2238 vfuncs = count_virtual_fns (pbc);
2242 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2243 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2244 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2252 /* Functions for overload resolution begin here */
2254 /* Compare two badness vectors A and B and return the result.
2255 * 0 => A and B are identical
2256 * 1 => A and B are incomparable
2257 * 2 => A is better than B
2258 * 3 => A is worse than B */
2261 compare_badness (struct badness_vector *a, struct badness_vector *b)
2265 short found_pos = 0; /* any positives in c? */
2266 short found_neg = 0; /* any negatives in c? */
2268 /* differing lengths => incomparable */
2269 if (a->length != b->length)
2272 /* Subtract b from a */
2273 for (i = 0; i < a->length; i++)
2275 tmp = a->rank[i] - b->rank[i];
2285 return 1; /* incomparable */
2287 return 3; /* A > B */
2293 return 2; /* A < B */
2295 return 0; /* A == B */
2299 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2300 * to the types of an argument list (ARGS, length NARGS).
2301 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2303 struct badness_vector *
2304 rank_function (struct type **parms, int nparms, struct type **args, int nargs)
2307 struct badness_vector *bv;
2308 int min_len = nparms < nargs ? nparms : nargs;
2310 bv = xmalloc (sizeof (struct badness_vector));
2311 bv->length = nargs + 1; /* add 1 for the length-match rank */
2312 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2314 /* First compare the lengths of the supplied lists.
2315 * If there is a mismatch, set it to a high value. */
2317 /* pai/1997-06-03 FIXME: when we have debug info about default
2318 * arguments and ellipsis parameter lists, we should consider those
2319 * and rank the length-match more finely. */
2321 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2323 /* Now rank all the parameters of the candidate function */
2324 for (i = 1; i <= min_len; i++)
2325 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2327 /* If more arguments than parameters, add dummy entries */
2328 for (i = min_len + 1; i <= nargs; i++)
2329 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2334 /* Compare one type (PARM) for compatibility with another (ARG).
2335 * PARM is intended to be the parameter type of a function; and
2336 * ARG is the supplied argument's type. This function tests if
2337 * the latter can be converted to the former.
2339 * Return 0 if they are identical types;
2340 * Otherwise, return an integer which corresponds to how compatible
2341 * PARM is to ARG. The higher the return value, the worse the match.
2342 * Generally the "bad" conversions are all uniformly assigned a 100 */
2345 rank_one_type (struct type *parm, struct type *arg)
2347 /* Identical type pointers */
2348 /* However, this still doesn't catch all cases of same type for arg
2349 * and param. The reason is that builtin types are different from
2350 * the same ones constructed from the object. */
2354 /* Resolve typedefs */
2355 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2356 parm = check_typedef (parm);
2357 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2358 arg = check_typedef (arg);
2361 Well, damnit, if the names are exactly the same,
2362 i'll say they are exactly the same. This happens when we generate
2363 method stubs. The types won't point to the same address, but they
2364 really are the same.
2367 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2368 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2371 /* Check if identical after resolving typedefs */
2375 /* See through references, since we can almost make non-references
2377 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2378 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2379 + REFERENCE_CONVERSION_BADNESS);
2380 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2381 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2382 + REFERENCE_CONVERSION_BADNESS);
2384 /* Debugging only. */
2385 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2386 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2388 /* x -> y means arg of type x being supplied for parameter of type y */
2390 switch (TYPE_CODE (parm))
2393 switch (TYPE_CODE (arg))
2396 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2397 return VOID_PTR_CONVERSION_BADNESS;
2399 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2400 case TYPE_CODE_ARRAY:
2401 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2402 case TYPE_CODE_FUNC:
2403 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2405 case TYPE_CODE_ENUM:
2406 case TYPE_CODE_CHAR:
2407 case TYPE_CODE_RANGE:
2408 case TYPE_CODE_BOOL:
2409 return POINTER_CONVERSION_BADNESS;
2411 return INCOMPATIBLE_TYPE_BADNESS;
2413 case TYPE_CODE_ARRAY:
2414 switch (TYPE_CODE (arg))
2417 case TYPE_CODE_ARRAY:
2418 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2420 return INCOMPATIBLE_TYPE_BADNESS;
2422 case TYPE_CODE_FUNC:
2423 switch (TYPE_CODE (arg))
2425 case TYPE_CODE_PTR: /* funcptr -> func */
2426 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2428 return INCOMPATIBLE_TYPE_BADNESS;
2431 switch (TYPE_CODE (arg))
2434 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2436 /* Deal with signed, unsigned, and plain chars and
2437 signed and unsigned ints */
2438 if (TYPE_NOSIGN (parm))
2440 /* This case only for character types */
2441 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2444 return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */
2446 else if (TYPE_UNSIGNED (parm))
2448 if (TYPE_UNSIGNED (arg))
2450 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2451 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2452 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2453 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2455 return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
2459 if (!strcmp_iw (TYPE_NAME (arg), "long") && !strcmp_iw (TYPE_NAME (parm), "int"))
2460 return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
2462 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2465 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2467 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2469 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2470 return INTEGER_PROMOTION_BADNESS;
2472 return INTEGER_COERCION_BADNESS;
2475 return INTEGER_COERCION_BADNESS;
2477 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2478 return INTEGER_PROMOTION_BADNESS;
2480 return INTEGER_COERCION_BADNESS;
2481 case TYPE_CODE_ENUM:
2482 case TYPE_CODE_CHAR:
2483 case TYPE_CODE_RANGE:
2484 case TYPE_CODE_BOOL:
2485 return INTEGER_PROMOTION_BADNESS;
2487 return INT_FLOAT_CONVERSION_BADNESS;
2489 return NS_POINTER_CONVERSION_BADNESS;
2491 return INCOMPATIBLE_TYPE_BADNESS;
2494 case TYPE_CODE_ENUM:
2495 switch (TYPE_CODE (arg))
2498 case TYPE_CODE_CHAR:
2499 case TYPE_CODE_RANGE:
2500 case TYPE_CODE_BOOL:
2501 case TYPE_CODE_ENUM:
2502 return INTEGER_COERCION_BADNESS;
2504 return INT_FLOAT_CONVERSION_BADNESS;
2506 return INCOMPATIBLE_TYPE_BADNESS;
2509 case TYPE_CODE_CHAR:
2510 switch (TYPE_CODE (arg))
2512 case TYPE_CODE_RANGE:
2513 case TYPE_CODE_BOOL:
2514 case TYPE_CODE_ENUM:
2515 return INTEGER_COERCION_BADNESS;
2517 return INT_FLOAT_CONVERSION_BADNESS;
2519 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2520 return INTEGER_COERCION_BADNESS;
2521 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2522 return INTEGER_PROMOTION_BADNESS;
2523 /* >>> !! else fall through !! <<< */
2524 case TYPE_CODE_CHAR:
2525 /* Deal with signed, unsigned, and plain chars for C++
2526 and with int cases falling through from previous case */
2527 if (TYPE_NOSIGN (parm))
2529 if (TYPE_NOSIGN (arg))
2532 return INTEGER_COERCION_BADNESS;
2534 else if (TYPE_UNSIGNED (parm))
2536 if (TYPE_UNSIGNED (arg))
2539 return INTEGER_PROMOTION_BADNESS;
2541 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2544 return INTEGER_COERCION_BADNESS;
2546 return INCOMPATIBLE_TYPE_BADNESS;
2549 case TYPE_CODE_RANGE:
2550 switch (TYPE_CODE (arg))
2553 case TYPE_CODE_CHAR:
2554 case TYPE_CODE_RANGE:
2555 case TYPE_CODE_BOOL:
2556 case TYPE_CODE_ENUM:
2557 return INTEGER_COERCION_BADNESS;
2559 return INT_FLOAT_CONVERSION_BADNESS;
2561 return INCOMPATIBLE_TYPE_BADNESS;
2564 case TYPE_CODE_BOOL:
2565 switch (TYPE_CODE (arg))
2568 case TYPE_CODE_CHAR:
2569 case TYPE_CODE_RANGE:
2570 case TYPE_CODE_ENUM:
2573 return BOOLEAN_CONVERSION_BADNESS;
2574 case TYPE_CODE_BOOL:
2577 return INCOMPATIBLE_TYPE_BADNESS;
2581 switch (TYPE_CODE (arg))
2584 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2585 return FLOAT_PROMOTION_BADNESS;
2586 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2589 return FLOAT_CONVERSION_BADNESS;
2591 case TYPE_CODE_BOOL:
2592 case TYPE_CODE_ENUM:
2593 case TYPE_CODE_RANGE:
2594 case TYPE_CODE_CHAR:
2595 return INT_FLOAT_CONVERSION_BADNESS;
2597 return INCOMPATIBLE_TYPE_BADNESS;
2600 case TYPE_CODE_COMPLEX:
2601 switch (TYPE_CODE (arg))
2602 { /* Strictly not needed for C++, but... */
2604 return FLOAT_PROMOTION_BADNESS;
2605 case TYPE_CODE_COMPLEX:
2608 return INCOMPATIBLE_TYPE_BADNESS;
2611 case TYPE_CODE_STRUCT:
2612 /* currently same as TYPE_CODE_CLASS */
2613 switch (TYPE_CODE (arg))
2615 case TYPE_CODE_STRUCT:
2616 /* Check for derivation */
2617 if (is_ancestor (parm, arg))
2618 return BASE_CONVERSION_BADNESS;
2619 /* else fall through */
2621 return INCOMPATIBLE_TYPE_BADNESS;
2624 case TYPE_CODE_UNION:
2625 switch (TYPE_CODE (arg))
2627 case TYPE_CODE_UNION:
2629 return INCOMPATIBLE_TYPE_BADNESS;
2632 case TYPE_CODE_MEMBER:
2633 switch (TYPE_CODE (arg))
2636 return INCOMPATIBLE_TYPE_BADNESS;
2639 case TYPE_CODE_METHOD:
2640 switch (TYPE_CODE (arg))
2644 return INCOMPATIBLE_TYPE_BADNESS;
2648 switch (TYPE_CODE (arg))
2652 return INCOMPATIBLE_TYPE_BADNESS;
2657 switch (TYPE_CODE (arg))
2661 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2663 return INCOMPATIBLE_TYPE_BADNESS;
2666 case TYPE_CODE_VOID:
2668 return INCOMPATIBLE_TYPE_BADNESS;
2669 } /* switch (TYPE_CODE (arg)) */
2673 /* End of functions for overload resolution */
2676 print_bit_vector (B_TYPE *bits, int nbits)
2680 for (bitno = 0; bitno < nbits; bitno++)
2682 if ((bitno % 8) == 0)
2684 puts_filtered (" ");
2686 if (B_TST (bits, bitno))
2688 printf_filtered ("1");
2692 printf_filtered ("0");
2697 /* The args list is a strange beast. It is either terminated by a NULL
2698 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2699 type for normal fixed argcount functions. (FIXME someday)
2700 Also note the first arg should be the "this" pointer, we may not want to
2701 include it since we may get into a infinitely recursive situation. */
2704 print_arg_types (struct type **args, int spaces)
2708 while (*args != NULL)
2710 recursive_dump_type (*args, spaces + 2);
2711 if ((*args++)->code == TYPE_CODE_VOID)
2720 dump_fn_fieldlists (struct type *type, int spaces)
2726 printfi_filtered (spaces, "fn_fieldlists ");
2727 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2728 printf_filtered ("\n");
2729 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2731 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2732 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2734 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2735 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2737 printf_filtered (") length %d\n",
2738 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2739 for (overload_idx = 0;
2740 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2743 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2745 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2746 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2748 printf_filtered (")\n");
2749 printfi_filtered (spaces + 8, "type ");
2750 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2751 printf_filtered ("\n");
2753 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2756 printfi_filtered (spaces + 8, "args ");
2757 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2758 printf_filtered ("\n");
2760 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
2761 printfi_filtered (spaces + 8, "fcontext ");
2762 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2764 printf_filtered ("\n");
2766 printfi_filtered (spaces + 8, "is_const %d\n",
2767 TYPE_FN_FIELD_CONST (f, overload_idx));
2768 printfi_filtered (spaces + 8, "is_volatile %d\n",
2769 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2770 printfi_filtered (spaces + 8, "is_private %d\n",
2771 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2772 printfi_filtered (spaces + 8, "is_protected %d\n",
2773 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2774 printfi_filtered (spaces + 8, "is_stub %d\n",
2775 TYPE_FN_FIELD_STUB (f, overload_idx));
2776 printfi_filtered (spaces + 8, "voffset %u\n",
2777 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2783 print_cplus_stuff (struct type *type, int spaces)
2785 printfi_filtered (spaces, "n_baseclasses %d\n",
2786 TYPE_N_BASECLASSES (type));
2787 printfi_filtered (spaces, "nfn_fields %d\n",
2788 TYPE_NFN_FIELDS (type));
2789 printfi_filtered (spaces, "nfn_fields_total %d\n",
2790 TYPE_NFN_FIELDS_TOTAL (type));
2791 if (TYPE_N_BASECLASSES (type) > 0)
2793 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2794 TYPE_N_BASECLASSES (type));
2795 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2796 printf_filtered (")");
2798 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2799 TYPE_N_BASECLASSES (type));
2800 puts_filtered ("\n");
2802 if (TYPE_NFIELDS (type) > 0)
2804 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2806 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2807 TYPE_NFIELDS (type));
2808 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2809 printf_filtered (")");
2810 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2811 TYPE_NFIELDS (type));
2812 puts_filtered ("\n");
2814 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2816 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2817 TYPE_NFIELDS (type));
2818 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2819 printf_filtered (")");
2820 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2821 TYPE_NFIELDS (type));
2822 puts_filtered ("\n");
2825 if (TYPE_NFN_FIELDS (type) > 0)
2827 dump_fn_fieldlists (type, spaces);
2832 print_bound_type (int bt)
2836 case BOUND_CANNOT_BE_DETERMINED:
2837 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2839 case BOUND_BY_REF_ON_STACK:
2840 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2842 case BOUND_BY_VALUE_ON_STACK:
2843 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2845 case BOUND_BY_REF_IN_REG:
2846 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2848 case BOUND_BY_VALUE_IN_REG:
2849 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2852 printf_filtered ("(BOUND_SIMPLE)");
2855 printf_filtered ("(unknown bound type)");
2860 static struct obstack dont_print_type_obstack;
2863 recursive_dump_type (struct type *type, int spaces)
2868 obstack_begin (&dont_print_type_obstack, 0);
2870 if (TYPE_NFIELDS (type) > 0
2871 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2873 struct type **first_dont_print
2874 = (struct type **) obstack_base (&dont_print_type_obstack);
2876 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2881 if (type == first_dont_print[i])
2883 printfi_filtered (spaces, "type node ");
2884 gdb_print_host_address (type, gdb_stdout);
2885 printf_filtered (" <same as already seen type>\n");
2890 obstack_ptr_grow (&dont_print_type_obstack, type);
2893 printfi_filtered (spaces, "type node ");
2894 gdb_print_host_address (type, gdb_stdout);
2895 printf_filtered ("\n");
2896 printfi_filtered (spaces, "name '%s' (",
2897 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2898 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2899 printf_filtered (")\n");
2900 printfi_filtered (spaces, "tagname '%s' (",
2901 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2902 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2903 printf_filtered (")\n");
2904 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2905 switch (TYPE_CODE (type))
2907 case TYPE_CODE_UNDEF:
2908 printf_filtered ("(TYPE_CODE_UNDEF)");
2911 printf_filtered ("(TYPE_CODE_PTR)");
2913 case TYPE_CODE_ARRAY:
2914 printf_filtered ("(TYPE_CODE_ARRAY)");
2916 case TYPE_CODE_STRUCT:
2917 printf_filtered ("(TYPE_CODE_STRUCT)");
2919 case TYPE_CODE_UNION:
2920 printf_filtered ("(TYPE_CODE_UNION)");
2922 case TYPE_CODE_ENUM:
2923 printf_filtered ("(TYPE_CODE_ENUM)");
2925 case TYPE_CODE_FUNC:
2926 printf_filtered ("(TYPE_CODE_FUNC)");
2929 printf_filtered ("(TYPE_CODE_INT)");
2932 printf_filtered ("(TYPE_CODE_FLT)");
2934 case TYPE_CODE_VOID:
2935 printf_filtered ("(TYPE_CODE_VOID)");
2938 printf_filtered ("(TYPE_CODE_SET)");
2940 case TYPE_CODE_RANGE:
2941 printf_filtered ("(TYPE_CODE_RANGE)");
2943 case TYPE_CODE_STRING:
2944 printf_filtered ("(TYPE_CODE_STRING)");
2946 case TYPE_CODE_BITSTRING:
2947 printf_filtered ("(TYPE_CODE_BITSTRING)");
2949 case TYPE_CODE_ERROR:
2950 printf_filtered ("(TYPE_CODE_ERROR)");
2952 case TYPE_CODE_MEMBER:
2953 printf_filtered ("(TYPE_CODE_MEMBER)");
2955 case TYPE_CODE_METHOD:
2956 printf_filtered ("(TYPE_CODE_METHOD)");
2959 printf_filtered ("(TYPE_CODE_REF)");
2961 case TYPE_CODE_CHAR:
2962 printf_filtered ("(TYPE_CODE_CHAR)");
2964 case TYPE_CODE_BOOL:
2965 printf_filtered ("(TYPE_CODE_BOOL)");
2967 case TYPE_CODE_COMPLEX:
2968 printf_filtered ("(TYPE_CODE_COMPLEX)");
2970 case TYPE_CODE_TYPEDEF:
2971 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2973 case TYPE_CODE_TEMPLATE:
2974 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2976 case TYPE_CODE_TEMPLATE_ARG:
2977 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2980 printf_filtered ("(UNKNOWN TYPE CODE)");
2983 puts_filtered ("\n");
2984 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2985 printfi_filtered (spaces, "upper_bound_type 0x%x ",
2986 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2987 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2988 puts_filtered ("\n");
2989 printfi_filtered (spaces, "lower_bound_type 0x%x ",
2990 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2991 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2992 puts_filtered ("\n");
2993 printfi_filtered (spaces, "objfile ");
2994 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2995 printf_filtered ("\n");
2996 printfi_filtered (spaces, "target_type ");
2997 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2998 printf_filtered ("\n");
2999 if (TYPE_TARGET_TYPE (type) != NULL)
3001 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3003 printfi_filtered (spaces, "pointer_type ");
3004 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
3005 printf_filtered ("\n");
3006 printfi_filtered (spaces, "reference_type ");
3007 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
3008 printf_filtered ("\n");
3009 printfi_filtered (spaces, "cv_type ");
3010 gdb_print_host_address (TYPE_CV_TYPE (type), gdb_stdout);
3011 printf_filtered ("\n");
3012 printfi_filtered (spaces, "as_type ");
3013 gdb_print_host_address (TYPE_AS_TYPE (type), gdb_stdout);
3014 printf_filtered ("\n");
3015 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
3016 if (TYPE_UNSIGNED (type))
3018 puts_filtered (" TYPE_FLAG_UNSIGNED");
3020 if (TYPE_NOSIGN (type))
3022 puts_filtered (" TYPE_FLAG_NOSIGN");
3024 if (TYPE_STUB (type))
3026 puts_filtered (" TYPE_FLAG_STUB");
3028 if (TYPE_TARGET_STUB (type))
3030 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3032 if (TYPE_STATIC (type))
3034 puts_filtered (" TYPE_FLAG_STATIC");
3036 if (TYPE_CONST (type))
3038 puts_filtered (" TYPE_FLAG_CONST");
3040 if (TYPE_VOLATILE (type))
3042 puts_filtered (" TYPE_FLAG_VOLATILE");
3044 if (TYPE_PROTOTYPED (type))
3046 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3048 if (TYPE_INCOMPLETE (type))
3050 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3052 if (TYPE_CODE_SPACE (type))
3054 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3056 if (TYPE_DATA_SPACE (type))
3058 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3060 if (TYPE_VARARGS (type))
3062 puts_filtered (" TYPE_FLAG_VARARGS");
3064 /* This is used for things like AltiVec registers on ppc. Gcc emits
3065 an attribute for the array type, which tells whether or not we
3066 have a vector, instead of a regular array. */
3067 if (TYPE_VECTOR (type))
3069 puts_filtered (" TYPE_FLAG_VECTOR");
3071 puts_filtered ("\n");
3072 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3073 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3074 puts_filtered ("\n");
3075 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3077 printfi_filtered (spaces + 2,
3078 "[%d] bitpos %d bitsize %d type ",
3079 idx, TYPE_FIELD_BITPOS (type, idx),
3080 TYPE_FIELD_BITSIZE (type, idx));
3081 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3082 printf_filtered (" name '%s' (",
3083 TYPE_FIELD_NAME (type, idx) != NULL
3084 ? TYPE_FIELD_NAME (type, idx)
3086 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3087 printf_filtered (")\n");
3088 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3090 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3093 printfi_filtered (spaces, "vptr_basetype ");
3094 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3095 puts_filtered ("\n");
3096 if (TYPE_VPTR_BASETYPE (type) != NULL)
3098 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3100 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3101 switch (TYPE_CODE (type))
3103 case TYPE_CODE_METHOD:
3104 case TYPE_CODE_FUNC:
3105 printfi_filtered (spaces, "arg_types ");
3106 gdb_print_host_address (TYPE_ARG_TYPES (type), gdb_stdout);
3107 puts_filtered ("\n");
3108 print_arg_types (TYPE_ARG_TYPES (type), spaces);
3111 case TYPE_CODE_STRUCT:
3112 printfi_filtered (spaces, "cplus_stuff ");
3113 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3114 puts_filtered ("\n");
3115 print_cplus_stuff (type, spaces);
3119 printfi_filtered (spaces, "floatformat ");
3120 if (TYPE_FLOATFORMAT (type) == NULL
3121 || TYPE_FLOATFORMAT (type)->name == NULL)
3122 puts_filtered ("(null)");
3124 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3125 puts_filtered ("\n");
3129 /* We have to pick one of the union types to be able print and test
3130 the value. Pick cplus_struct_type, even though we know it isn't
3131 any particular one. */
3132 printfi_filtered (spaces, "type_specific ");
3133 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3134 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3136 printf_filtered (" (unknown data form)");
3138 printf_filtered ("\n");
3143 obstack_free (&dont_print_type_obstack, NULL);
3146 static void build_gdbtypes (void);
3148 build_gdbtypes (void)
3151 init_type (TYPE_CODE_VOID, 1,
3153 "void", (struct objfile *) NULL);
3155 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3157 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
3158 "char", (struct objfile *) NULL);
3159 builtin_type_true_char =
3160 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3162 "true character", (struct objfile *) NULL);
3163 builtin_type_signed_char =
3164 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3166 "signed char", (struct objfile *) NULL);
3167 builtin_type_unsigned_char =
3168 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3170 "unsigned char", (struct objfile *) NULL);
3171 builtin_type_short =
3172 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3174 "short", (struct objfile *) NULL);
3175 builtin_type_unsigned_short =
3176 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3178 "unsigned short", (struct objfile *) NULL);
3180 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3182 "int", (struct objfile *) NULL);
3183 builtin_type_unsigned_int =
3184 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3186 "unsigned int", (struct objfile *) NULL);
3188 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3190 "long", (struct objfile *) NULL);
3191 builtin_type_unsigned_long =
3192 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3194 "unsigned long", (struct objfile *) NULL);
3195 builtin_type_long_long =
3196 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3198 "long long", (struct objfile *) NULL);
3199 builtin_type_unsigned_long_long =
3200 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3202 "unsigned long long", (struct objfile *) NULL);
3203 builtin_type_float =
3204 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3206 "float", (struct objfile *) NULL);
3207 /* vinschen@redhat.com 2002-02-08:
3208 The below lines are disabled since they are doing the wrong
3209 thing for non-multiarch targets. They are setting the correct
3210 type of floats for the target but while on multiarch targets
3211 this is done everytime the architecture changes, it's done on
3212 non-multiarch targets only on startup, leaving the wrong values
3213 in even if the architecture changes (eg. from big-endian to
3216 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
3218 builtin_type_double =
3219 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3221 "double", (struct objfile *) NULL);
3223 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
3225 builtin_type_long_double =
3226 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3228 "long double", (struct objfile *) NULL);
3230 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
3232 builtin_type_complex =
3233 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3235 "complex", (struct objfile *) NULL);
3236 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3237 builtin_type_double_complex =
3238 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3240 "double complex", (struct objfile *) NULL);
3241 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3242 builtin_type_string =
3243 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3245 "string", (struct objfile *) NULL);
3247 init_type (TYPE_CODE_INT, 8 / 8,
3249 "int8_t", (struct objfile *) NULL);
3250 builtin_type_uint8 =
3251 init_type (TYPE_CODE_INT, 8 / 8,
3253 "uint8_t", (struct objfile *) NULL);
3254 builtin_type_int16 =
3255 init_type (TYPE_CODE_INT, 16 / 8,
3257 "int16_t", (struct objfile *) NULL);
3258 builtin_type_uint16 =
3259 init_type (TYPE_CODE_INT, 16 / 8,
3261 "uint16_t", (struct objfile *) NULL);
3262 builtin_type_int32 =
3263 init_type (TYPE_CODE_INT, 32 / 8,
3265 "int32_t", (struct objfile *) NULL);
3266 builtin_type_uint32 =
3267 init_type (TYPE_CODE_INT, 32 / 8,
3269 "uint32_t", (struct objfile *) NULL);
3270 builtin_type_int64 =
3271 init_type (TYPE_CODE_INT, 64 / 8,
3273 "int64_t", (struct objfile *) NULL);
3274 builtin_type_uint64 =
3275 init_type (TYPE_CODE_INT, 64 / 8,
3277 "uint64_t", (struct objfile *) NULL);
3278 builtin_type_int128 =
3279 init_type (TYPE_CODE_INT, 128 / 8,
3281 "int128_t", (struct objfile *) NULL);
3282 builtin_type_uint128 =
3283 init_type (TYPE_CODE_INT, 128 / 8,
3285 "uint128_t", (struct objfile *) NULL);
3287 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3289 "bool", (struct objfile *) NULL);
3291 /* Add user knob for controlling resolution of opaque types */
3293 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
3294 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3297 opaque_type_resolution = 1;
3299 /* Build SIMD types. */
3301 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
3303 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
3305 = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
3307 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
3309 = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
3311 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3313 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
3315 /* 128 bit vectors. */
3316 builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3317 builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3318 builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3319 builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3320 /* 64 bit vectors. */
3321 builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
3322 builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3323 builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3324 builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
3327 builtin_type_vec128 = build_builtin_type_vec128 ();
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_v4_float, sizeof (struct type *), NULL);
3417 register_gdbarch_swap (&builtin_type_v4_int32, sizeof (struct type *), NULL);
3418 register_gdbarch_swap (&builtin_type_v8_int16, sizeof (struct type *), NULL);
3419 register_gdbarch_swap (&builtin_type_v16_int8, sizeof (struct type *), NULL);
3420 register_gdbarch_swap (&builtin_type_v2_float, sizeof (struct type *), NULL);
3421 register_gdbarch_swap (&builtin_type_v2_int32, sizeof (struct type *), NULL);
3422 register_gdbarch_swap (&builtin_type_v8_int8, sizeof (struct type *), NULL);
3423 register_gdbarch_swap (&builtin_type_v4_int16, sizeof (struct type *), NULL);
3424 register_gdbarch_swap (&builtin_type_vec128, sizeof (struct type *), NULL);
3425 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3426 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3427 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3428 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3429 register_gdbarch_swap (NULL, 0, build_gdbtypes);
3431 /* Note: These types do not need to be swapped - they are target
3433 builtin_type_ieee_single_big =
3434 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3435 0, "builtin_type_ieee_single_big", NULL);
3436 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3437 builtin_type_ieee_single_little =
3438 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3439 0, "builtin_type_ieee_single_little", NULL);
3440 TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
3441 builtin_type_ieee_double_big =
3442 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3443 0, "builtin_type_ieee_double_big", NULL);
3444 TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
3445 builtin_type_ieee_double_little =
3446 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3447 0, "builtin_type_ieee_double_little", NULL);
3448 TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
3449 builtin_type_ieee_double_littlebyte_bigword =
3450 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3451 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
3452 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
3453 builtin_type_i387_ext =
3454 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3455 0, "builtin_type_i387_ext", NULL);
3456 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
3457 builtin_type_m68881_ext =
3458 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3459 0, "builtin_type_m68881_ext", NULL);
3460 TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
3461 builtin_type_i960_ext =
3462 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3463 0, "builtin_type_i960_ext", NULL);
3464 TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
3465 builtin_type_m88110_ext =
3466 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3467 0, "builtin_type_m88110_ext", NULL);
3468 TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
3469 builtin_type_m88110_harris_ext =
3470 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3471 0, "builtin_type_m88110_harris_ext", NULL);
3472 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
3473 builtin_type_arm_ext_big =
3474 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3475 0, "builtin_type_arm_ext_big", NULL);
3476 TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
3477 builtin_type_arm_ext_littlebyte_bigword =
3478 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3479 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
3480 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
3481 builtin_type_ia64_spill_big =
3482 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3483 0, "builtin_type_ia64_spill_big", NULL);
3484 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
3485 builtin_type_ia64_spill_little =
3486 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3487 0, "builtin_type_ia64_spill_little", NULL);
3488 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
3489 builtin_type_ia64_quad_big =
3490 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3491 0, "builtin_type_ia64_quad_big", NULL);
3492 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
3493 builtin_type_ia64_quad_little =
3494 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3495 0, "builtin_type_ia64_quad_little", NULL);
3496 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
3499 add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
3500 "Set debugging of C++ overloading.\n\
3501 When enabled, ranking of the functions\n\
3502 is displayed.", &setdebuglist),