1 /* Support routines for manipulating internal types for GDB.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support, using pieces from other GDB modules.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
30 #include "expression.h"
35 #include "complaints.h"
39 #include "gdb_assert.h"
41 /* These variables point to the objects
42 representing the predefined C data types. */
44 struct type
*builtin_type_void
;
45 struct type
*builtin_type_char
;
46 struct type
*builtin_type_true_char
;
47 struct type
*builtin_type_short
;
48 struct type
*builtin_type_int
;
49 struct type
*builtin_type_long
;
50 struct type
*builtin_type_long_long
;
51 struct type
*builtin_type_signed_char
;
52 struct type
*builtin_type_unsigned_char
;
53 struct type
*builtin_type_unsigned_short
;
54 struct type
*builtin_type_unsigned_int
;
55 struct type
*builtin_type_unsigned_long
;
56 struct type
*builtin_type_unsigned_long_long
;
57 struct type
*builtin_type_float
;
58 struct type
*builtin_type_double
;
59 struct type
*builtin_type_long_double
;
60 struct type
*builtin_type_complex
;
61 struct type
*builtin_type_double_complex
;
62 struct type
*builtin_type_string
;
63 struct type
*builtin_type_int8
;
64 struct type
*builtin_type_uint8
;
65 struct type
*builtin_type_int16
;
66 struct type
*builtin_type_uint16
;
67 struct type
*builtin_type_int32
;
68 struct type
*builtin_type_uint32
;
69 struct type
*builtin_type_int64
;
70 struct type
*builtin_type_uint64
;
71 struct type
*builtin_type_int128
;
72 struct type
*builtin_type_uint128
;
73 struct type
*builtin_type_bool
;
75 /* 128 bit long vector types */
76 struct type
*builtin_type_v2_double
;
77 struct type
*builtin_type_v4_float
;
78 struct type
*builtin_type_v2_int64
;
79 struct type
*builtin_type_v4_int32
;
80 struct type
*builtin_type_v8_int16
;
81 struct type
*builtin_type_v16_int8
;
82 /* 64 bit long vector types */
83 struct type
*builtin_type_v2_float
;
84 struct type
*builtin_type_v2_int32
;
85 struct type
*builtin_type_v4_int16
;
86 struct type
*builtin_type_v8_int8
;
88 struct type
*builtin_type_v4sf
;
89 struct type
*builtin_type_v4si
;
90 struct type
*builtin_type_v16qi
;
91 struct type
*builtin_type_v8qi
;
92 struct type
*builtin_type_v8hi
;
93 struct type
*builtin_type_v4hi
;
94 struct type
*builtin_type_v2si
;
95 struct type
*builtin_type_vec64
;
96 struct type
*builtin_type_vec64i
;
97 struct type
*builtin_type_vec128
;
98 struct type
*builtin_type_vec128i
;
99 struct type
*builtin_type_ieee_single_big
;
100 struct type
*builtin_type_ieee_single_little
;
101 struct type
*builtin_type_ieee_double_big
;
102 struct type
*builtin_type_ieee_double_little
;
103 struct type
*builtin_type_ieee_double_littlebyte_bigword
;
104 struct type
*builtin_type_i387_ext
;
105 struct type
*builtin_type_m68881_ext
;
106 struct type
*builtin_type_i960_ext
;
107 struct type
*builtin_type_m88110_ext
;
108 struct type
*builtin_type_m88110_harris_ext
;
109 struct type
*builtin_type_arm_ext_big
;
110 struct type
*builtin_type_arm_ext_littlebyte_bigword
;
111 struct type
*builtin_type_ia64_spill_big
;
112 struct type
*builtin_type_ia64_spill_little
;
113 struct type
*builtin_type_ia64_quad_big
;
114 struct type
*builtin_type_ia64_quad_little
;
115 struct type
*builtin_type_void_data_ptr
;
116 struct type
*builtin_type_void_func_ptr
;
117 struct type
*builtin_type_CORE_ADDR
;
118 struct type
*builtin_type_bfd_vma
;
120 int opaque_type_resolution
= 1;
121 int overload_debug
= 0;
127 }; /* maximum extension is 128! FIXME */
129 static void add_name (struct extra
*, char *);
130 static void add_mangled_type (struct extra
*, struct type
*);
131 #if 0 /* OBSOLETE CFront */
132 // OBSOLETE static void cfront_mangle_name (struct type *, int, int);
133 #endif /* OBSOLETE CFront */
134 static void print_bit_vector (B_TYPE
*, int);
135 static void print_arg_types (struct field
*, int, int);
136 static void dump_fn_fieldlists (struct type
*, int);
137 static void print_cplus_stuff (struct type
*, int);
138 static void virtual_base_list_aux (struct type
*dclass
);
141 /* Alloc a new type structure and fill it with some defaults. If
142 OBJFILE is non-NULL, then allocate the space for the type structure
143 in that objfile's type_obstack. Otherwise allocate the new type structure
144 by xmalloc () (for permanent types). */
147 alloc_type (struct objfile
*objfile
)
149 register struct type
*type
;
151 /* Alloc the structure and start off with all fields zeroed. */
155 type
= xmalloc (sizeof (struct type
));
156 memset (type
, 0, sizeof (struct type
));
157 TYPE_MAIN_TYPE (type
) = xmalloc (sizeof (struct main_type
));
161 type
= obstack_alloc (&objfile
->type_obstack
,
162 sizeof (struct type
));
163 memset (type
, 0, sizeof (struct type
));
164 TYPE_MAIN_TYPE (type
) = obstack_alloc (&objfile
->type_obstack
,
165 sizeof (struct main_type
));
166 OBJSTAT (objfile
, n_types
++);
168 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
170 /* Initialize the fields that might not be zero. */
172 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
173 TYPE_OBJFILE (type
) = objfile
;
174 TYPE_VPTR_FIELDNO (type
) = -1;
175 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
180 /* Alloc a new type instance structure, fill it with some defaults,
181 and point it at OLDTYPE. Allocate the new type instance from the
182 same place as OLDTYPE. */
185 alloc_type_instance (struct type
*oldtype
)
189 /* Allocate the structure. */
191 if (TYPE_OBJFILE (oldtype
) == NULL
)
193 type
= xmalloc (sizeof (struct type
));
194 memset (type
, 0, sizeof (struct type
));
198 type
= obstack_alloc (&TYPE_OBJFILE (oldtype
)->type_obstack
,
199 sizeof (struct type
));
200 memset (type
, 0, sizeof (struct type
));
202 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
204 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
209 /* Clear all remnants of the previous type at TYPE, in preparation for
210 replacing it with something else. */
212 smash_type (struct type
*type
)
214 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
216 /* For now, delete the rings. */
217 TYPE_CHAIN (type
) = type
;
219 /* For now, leave the pointer/reference types alone. */
222 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
223 to a pointer to memory where the pointer type should be stored.
224 If *TYPEPTR is zero, update it to point to the pointer type we return.
225 We allocate new memory if needed. */
228 make_pointer_type (struct type
*type
, struct type
**typeptr
)
230 register struct type
*ntype
; /* New type */
231 struct objfile
*objfile
;
233 ntype
= TYPE_POINTER_TYPE (type
);
238 return ntype
; /* Don't care about alloc, and have new type. */
239 else if (*typeptr
== 0)
241 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
246 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
248 ntype
= alloc_type (TYPE_OBJFILE (type
));
253 /* We have storage, but need to reset it. */
256 objfile
= TYPE_OBJFILE (ntype
);
258 TYPE_OBJFILE (ntype
) = objfile
;
261 TYPE_TARGET_TYPE (ntype
) = type
;
262 TYPE_POINTER_TYPE (type
) = ntype
;
264 /* FIXME! Assume the machine has only one representation for pointers! */
266 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
267 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
269 /* Mark pointers as unsigned. The target converts between pointers
270 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
271 ADDRESS_TO_POINTER(). */
272 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
274 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
275 TYPE_POINTER_TYPE (type
) = ntype
;
280 /* Given a type TYPE, return a type of pointers to that type.
281 May need to construct such a type if this is the first use. */
284 lookup_pointer_type (struct type
*type
)
286 return make_pointer_type (type
, (struct type
**) 0);
289 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
290 to a pointer to memory where the reference type should be stored.
291 If *TYPEPTR is zero, update it to point to the reference type we return.
292 We allocate new memory if needed. */
295 make_reference_type (struct type
*type
, struct type
**typeptr
)
297 register struct type
*ntype
; /* New type */
298 struct objfile
*objfile
;
300 ntype
= TYPE_REFERENCE_TYPE (type
);
305 return ntype
; /* Don't care about alloc, and have new type. */
306 else if (*typeptr
== 0)
308 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
313 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
315 ntype
= alloc_type (TYPE_OBJFILE (type
));
320 /* We have storage, but need to reset it. */
323 objfile
= TYPE_OBJFILE (ntype
);
325 TYPE_OBJFILE (ntype
) = objfile
;
328 TYPE_TARGET_TYPE (ntype
) = type
;
329 TYPE_REFERENCE_TYPE (type
) = ntype
;
331 /* FIXME! Assume the machine has only one representation for references,
332 and that it matches the (only) representation for pointers! */
334 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
335 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
337 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
338 TYPE_REFERENCE_TYPE (type
) = ntype
;
343 /* Same as above, but caller doesn't care about memory allocation details. */
346 lookup_reference_type (struct type
*type
)
348 return make_reference_type (type
, (struct type
**) 0);
351 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
352 to a pointer to memory where the function type should be stored.
353 If *TYPEPTR is zero, update it to point to the function type we return.
354 We allocate new memory if needed. */
357 make_function_type (struct type
*type
, struct type
**typeptr
)
359 register struct type
*ntype
; /* New type */
360 struct objfile
*objfile
;
362 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
364 ntype
= alloc_type (TYPE_OBJFILE (type
));
369 /* We have storage, but need to reset it. */
372 objfile
= TYPE_OBJFILE (ntype
);
374 TYPE_OBJFILE (ntype
) = objfile
;
377 TYPE_TARGET_TYPE (ntype
) = type
;
379 TYPE_LENGTH (ntype
) = 1;
380 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
386 /* Given a type TYPE, return a type of functions that return that type.
387 May need to construct such a type if this is the first use. */
390 lookup_function_type (struct type
*type
)
392 return make_function_type (type
, (struct type
**) 0);
395 /* Identify address space identifier by name --
396 return the integer flag defined in gdbtypes.h. */
398 address_space_name_to_int (char *space_identifier
)
400 struct gdbarch
*gdbarch
= current_gdbarch
;
402 /* Check for known address space delimiters. */
403 if (!strcmp (space_identifier
, "code"))
404 return TYPE_FLAG_CODE_SPACE
;
405 else if (!strcmp (space_identifier
, "data"))
406 return TYPE_FLAG_DATA_SPACE
;
407 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
408 && gdbarch_address_class_name_to_type_flags (gdbarch
,
413 error ("Unknown address space specifier: \"%s\"", space_identifier
);
416 /* Identify address space identifier by integer flag as defined in
417 gdbtypes.h -- return the string version of the adress space name. */
420 address_space_int_to_name (int space_flag
)
422 struct gdbarch
*gdbarch
= current_gdbarch
;
423 if (space_flag
& TYPE_FLAG_CODE_SPACE
)
425 else if (space_flag
& TYPE_FLAG_DATA_SPACE
)
427 else if ((space_flag
& TYPE_FLAG_ADDRESS_CLASS_ALL
)
428 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
429 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
434 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
435 If STORAGE is non-NULL, create the new type instance there. */
438 make_qualified_type (struct type
*type
, int new_flags
,
439 struct type
*storage
)
445 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
447 ntype
= TYPE_CHAIN (ntype
);
448 } while (ntype
!= type
);
450 /* Create a new type instance. */
452 ntype
= alloc_type_instance (type
);
456 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
457 TYPE_CHAIN (ntype
) = ntype
;
460 /* Pointers or references to the original type are not relevant to
462 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
463 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
465 /* Chain the new qualified type to the old type. */
466 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
467 TYPE_CHAIN (type
) = ntype
;
469 /* Now set the instance flags and return the new type. */
470 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
472 /* Set length of new type to that of the original type. */
473 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
478 /* Make an address-space-delimited variant of a type -- a type that
479 is identical to the one supplied except that it has an address
480 space attribute attached to it (such as "code" or "data").
482 The space attributes "code" and "data" are for Harvard architectures.
483 The address space attributes are for architectures which have
484 alternately sized pointers or pointers with alternate representations. */
487 make_type_with_address_space (struct type
*type
, int space_flag
)
490 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
491 & ~(TYPE_FLAG_CODE_SPACE
| TYPE_FLAG_DATA_SPACE
492 | TYPE_FLAG_ADDRESS_CLASS_ALL
))
495 return make_qualified_type (type
, new_flags
, NULL
);
498 /* Make a "c-v" variant of a type -- a type that is identical to the
499 one supplied except that it may have const or volatile attributes
500 CNST is a flag for setting the const attribute
501 VOLTL is a flag for setting the volatile attribute
502 TYPE is the base type whose variant we are creating.
503 TYPEPTR, if nonzero, points
504 to a pointer to memory where the reference type should be stored.
505 If *TYPEPTR is zero, update it to point to the reference type we return.
506 We allocate new memory if needed. */
509 make_cv_type (int cnst
, int voltl
, struct type
*type
, struct type
**typeptr
)
511 register struct type
*ntype
; /* New type */
512 register struct type
*tmp_type
= type
; /* tmp type */
513 struct objfile
*objfile
;
515 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
516 & ~(TYPE_FLAG_CONST
| TYPE_FLAG_VOLATILE
));
519 new_flags
|= TYPE_FLAG_CONST
;
522 new_flags
|= TYPE_FLAG_VOLATILE
;
524 if (typeptr
&& *typeptr
!= NULL
)
526 /* Objfile is per-core-type. This const-qualified type had best
527 belong to the same objfile as the type it is qualifying, unless
528 we are overwriting a stub type, in which case the safest thing
529 to do is to copy the core type into the new objfile. */
531 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
)
532 || TYPE_STUB (*typeptr
));
533 if (TYPE_OBJFILE (*typeptr
) != TYPE_OBJFILE (type
))
535 TYPE_MAIN_TYPE (*typeptr
)
536 = TYPE_ALLOC (*typeptr
, sizeof (struct main_type
));
537 *TYPE_MAIN_TYPE (*typeptr
)
538 = *TYPE_MAIN_TYPE (type
);
542 ntype
= make_qualified_type (type
, new_flags
, typeptr
? *typeptr
: NULL
);
550 /* Replace the contents of ntype with the type *type. This changes the
551 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
552 the changes are propogated to all types in the TYPE_CHAIN.
554 In order to build recursive types, it's inevitable that we'll need
555 to update types in place --- but this sort of indiscriminate
556 smashing is ugly, and needs to be replaced with something more
557 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
558 clear if more steps are needed. */
560 replace_type (struct type
*ntype
, struct type
*type
)
564 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
566 /* The type length is not a part of the main type. Update it for each
567 type on the variant chain. */
570 /* Assert that this element of the chain has no address-class bits
571 set in its flags. Such type variants might have type lengths
572 which are supposed to be different from the non-address-class
573 variants. This assertion shouldn't ever be triggered because
574 symbol readers which do construct address-class variants don't
575 call replace_type(). */
576 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
578 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
579 chain
= TYPE_CHAIN (chain
);
580 } while (ntype
!= chain
);
582 /* Assert that the two types have equivalent instance qualifiers.
583 This should be true for at least all of our debug readers. */
584 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
587 /* Implement direct support for MEMBER_TYPE in GNU C++.
588 May need to construct such a type if this is the first use.
589 The TYPE is the type of the member. The DOMAIN is the type
590 of the aggregate that the member belongs to. */
593 lookup_member_type (struct type
*type
, struct type
*domain
)
595 register struct type
*mtype
;
597 mtype
= alloc_type (TYPE_OBJFILE (type
));
598 smash_to_member_type (mtype
, domain
, type
);
602 /* Allocate a stub method whose return type is TYPE.
603 This apparently happens for speed of symbol reading, since parsing
604 out the arguments to the method is cpu-intensive, the way we are doing
605 it. So, we will fill in arguments later.
606 This always returns a fresh type. */
609 allocate_stub_method (struct type
*type
)
613 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
614 TYPE_OBJFILE (type
));
615 TYPE_TARGET_TYPE (mtype
) = type
;
616 /* _DOMAIN_TYPE (mtype) = unknown yet */
620 /* Create a range type using either a blank type supplied in RESULT_TYPE,
621 or creating a new type, inheriting the objfile from INDEX_TYPE.
623 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
624 HIGH_BOUND, inclusive.
626 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
627 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
630 create_range_type (struct type
*result_type
, struct type
*index_type
,
631 int low_bound
, int high_bound
)
633 if (result_type
== NULL
)
635 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
637 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
638 TYPE_TARGET_TYPE (result_type
) = index_type
;
639 if (TYPE_STUB (index_type
))
640 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
642 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
643 TYPE_NFIELDS (result_type
) = 2;
644 TYPE_FIELDS (result_type
) = (struct field
*)
645 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
646 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
647 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
648 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
649 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
650 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
653 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
655 return (result_type
);
658 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
659 Return 1 of type is a range type, 0 if it is discrete (and bounds
660 will fit in LONGEST), or -1 otherwise. */
663 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
665 CHECK_TYPEDEF (type
);
666 switch (TYPE_CODE (type
))
668 case TYPE_CODE_RANGE
:
669 *lowp
= TYPE_LOW_BOUND (type
);
670 *highp
= TYPE_HIGH_BOUND (type
);
673 if (TYPE_NFIELDS (type
) > 0)
675 /* The enums may not be sorted by value, so search all
679 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
680 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
682 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
683 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
684 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
685 *highp
= TYPE_FIELD_BITPOS (type
, i
);
688 /* Set unsigned indicator if warranted. */
691 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
705 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
707 if (!TYPE_UNSIGNED (type
))
709 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
713 /* ... fall through for unsigned ints ... */
716 /* This round-about calculation is to avoid shifting by
717 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
718 if TYPE_LENGTH (type) == sizeof (LONGEST). */
719 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
720 *highp
= (*highp
- 1) | *highp
;
727 /* Create an array type using either a blank type supplied in RESULT_TYPE,
728 or creating a new type, inheriting the objfile from RANGE_TYPE.
730 Elements will be of type ELEMENT_TYPE, the indices will be of type
733 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
734 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
737 create_array_type (struct type
*result_type
, struct type
*element_type
,
738 struct type
*range_type
)
740 LONGEST low_bound
, high_bound
;
742 if (result_type
== NULL
)
744 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
746 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
747 TYPE_TARGET_TYPE (result_type
) = element_type
;
748 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
749 low_bound
= high_bound
= 0;
750 CHECK_TYPEDEF (element_type
);
751 TYPE_LENGTH (result_type
) =
752 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
753 TYPE_NFIELDS (result_type
) = 1;
754 TYPE_FIELDS (result_type
) =
755 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
756 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
757 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
758 TYPE_VPTR_FIELDNO (result_type
) = -1;
760 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
761 if (TYPE_LENGTH (result_type
) == 0)
762 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
764 return (result_type
);
767 /* Create a string type using either a blank type supplied in RESULT_TYPE,
768 or creating a new type. String types are similar enough to array of
769 char types that we can use create_array_type to build the basic type
770 and then bash it into a string type.
772 For fixed length strings, the range type contains 0 as the lower
773 bound and the length of the string minus one as the upper bound.
775 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
776 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
779 create_string_type (struct type
*result_type
, struct type
*range_type
)
781 result_type
= create_array_type (result_type
,
782 *current_language
->string_char_type
,
784 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
785 return (result_type
);
789 create_set_type (struct type
*result_type
, struct type
*domain_type
)
791 LONGEST low_bound
, high_bound
, bit_length
;
792 if (result_type
== NULL
)
794 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
796 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
797 TYPE_NFIELDS (result_type
) = 1;
798 TYPE_FIELDS (result_type
) = (struct field
*)
799 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
800 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
802 if (!TYPE_STUB (domain_type
))
804 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
805 low_bound
= high_bound
= 0;
806 bit_length
= high_bound
- low_bound
+ 1;
807 TYPE_LENGTH (result_type
)
808 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
810 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
813 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
815 return (result_type
);
818 /* Construct and return a type of the form:
819 struct NAME { ELT_TYPE ELT_NAME[N]; }
820 We use these types for SIMD registers. For example, the type of
821 the SSE registers on the late x86-family processors is:
822 struct __builtin_v4sf { float f[4]; }
823 built by the function call:
824 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
825 The type returned is a permanent type, allocated using malloc; it
826 doesn't live in any objfile's obstack. */
828 init_simd_type (char *name
,
829 struct type
*elt_type
,
833 struct type
*simd_type
;
834 struct type
*array_type
;
836 simd_type
= init_composite_type (name
, TYPE_CODE_STRUCT
);
837 array_type
= create_array_type (0, elt_type
,
838 create_range_type (0, builtin_type_int
,
840 append_composite_type_field (simd_type
, elt_name
, array_type
);
845 init_vector_type (struct type
*elt_type
, int n
)
847 struct type
*array_type
;
849 array_type
= create_array_type (0, elt_type
,
850 create_range_type (0, builtin_type_int
,
852 TYPE_FLAGS (array_type
) |= TYPE_FLAG_VECTOR
;
857 build_builtin_type_vec64 (void)
859 /* Construct a type for the 64 bit registers. The type we're
862 union __gdb_builtin_type_vec64
874 t
= init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION
);
875 append_composite_type_field (t
, "uint64", builtin_type_int64
);
876 append_composite_type_field (t
, "v2_float", builtin_type_v2_float
);
877 append_composite_type_field (t
, "v2_int32", builtin_type_v2_int32
);
878 append_composite_type_field (t
, "v4_int16", builtin_type_v4_int16
);
879 append_composite_type_field (t
, "v8_int8", builtin_type_v8_int8
);
881 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
882 TYPE_NAME (t
) = "builtin_type_vec64";
887 build_builtin_type_vec64i (void)
889 /* Construct a type for the 64 bit registers. The type we're
892 union __gdb_builtin_type_vec64i
903 t
= init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION
);
904 append_composite_type_field (t
, "uint64", builtin_type_int64
);
905 append_composite_type_field (t
, "v2_int32", builtin_type_v2_int32
);
906 append_composite_type_field (t
, "v4_int16", builtin_type_v4_int16
);
907 append_composite_type_field (t
, "v8_int8", builtin_type_v8_int8
);
909 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
910 TYPE_NAME (t
) = "builtin_type_vec64i";
915 build_builtin_type_vec128 (void)
917 /* Construct a type for the 128 bit registers. The type we're
920 union __gdb_builtin_type_vec128
932 t
= init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION
);
933 append_composite_type_field (t
, "uint128", builtin_type_int128
);
934 append_composite_type_field (t
, "v4_float", builtin_type_v4_float
);
935 append_composite_type_field (t
, "v4_int32", builtin_type_v4_int32
);
936 append_composite_type_field (t
, "v8_int16", builtin_type_v8_int16
);
937 append_composite_type_field (t
, "v16_int8", builtin_type_v16_int8
);
939 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
940 TYPE_NAME (t
) = "builtin_type_vec128";
945 build_builtin_type_vec128i (void)
947 /* 128-bit Intel SIMD registers */
950 t
= init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION
);
951 append_composite_type_field (t
, "v4_float", builtin_type_v4_float
);
952 append_composite_type_field (t
, "v2_double", builtin_type_v2_double
);
953 append_composite_type_field (t
, "v16_int8", builtin_type_v16_int8
);
954 append_composite_type_field (t
, "v8_int16", builtin_type_v8_int16
);
955 append_composite_type_field (t
, "v4_int32", builtin_type_v4_int32
);
956 append_composite_type_field (t
, "v2_int64", builtin_type_v2_int64
);
957 append_composite_type_field (t
, "uint128", builtin_type_int128
);
959 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
960 TYPE_NAME (t
) = "builtin_type_vec128i";
964 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
965 A MEMBER is a wierd thing -- it amounts to a typed offset into
966 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
967 include the offset (that's the value of the MEMBER itself), but does
968 include the structure type into which it points (for some reason).
970 When "smashing" the type, we preserve the objfile that the
971 old type pointed to, since we aren't changing where the type is actually
975 smash_to_member_type (struct type
*type
, struct type
*domain
,
976 struct type
*to_type
)
978 struct objfile
*objfile
;
980 objfile
= TYPE_OBJFILE (type
);
983 TYPE_OBJFILE (type
) = objfile
;
984 TYPE_TARGET_TYPE (type
) = to_type
;
985 TYPE_DOMAIN_TYPE (type
) = domain
;
986 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
987 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
990 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
991 METHOD just means `function that gets an extra "this" argument'.
993 When "smashing" the type, we preserve the objfile that the
994 old type pointed to, since we aren't changing where the type is actually
998 smash_to_method_type (struct type
*type
, struct type
*domain
,
999 struct type
*to_type
, struct field
*args
,
1000 int nargs
, int varargs
)
1002 struct objfile
*objfile
;
1004 objfile
= TYPE_OBJFILE (type
);
1007 TYPE_OBJFILE (type
) = objfile
;
1008 TYPE_TARGET_TYPE (type
) = to_type
;
1009 TYPE_DOMAIN_TYPE (type
) = domain
;
1010 TYPE_FIELDS (type
) = args
;
1011 TYPE_NFIELDS (type
) = nargs
;
1013 TYPE_FLAGS (type
) |= TYPE_FLAG_VARARGS
;
1014 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1015 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1018 /* Return a typename for a struct/union/enum type without "struct ",
1019 "union ", or "enum ". If the type has a NULL name, return NULL. */
1022 type_name_no_tag (register const struct type
*type
)
1024 if (TYPE_TAG_NAME (type
) != NULL
)
1025 return TYPE_TAG_NAME (type
);
1027 /* Is there code which expects this to return the name if there is no
1028 tag name? My guess is that this is mainly used for C++ in cases where
1029 the two will always be the same. */
1030 return TYPE_NAME (type
);
1033 /* Lookup a primitive type named NAME.
1034 Return zero if NAME is not a primitive type. */
1037 lookup_primitive_typename (char *name
)
1039 struct type
**const *p
;
1041 for (p
= current_language
->la_builtin_type_vector
; *p
!= NULL
; p
++)
1043 if (strcmp (TYPE_NAME (**p
), name
) == 0)
1051 /* Lookup a typedef or primitive type named NAME,
1052 visible in lexical block BLOCK.
1053 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1056 lookup_typename (char *name
, struct block
*block
, int noerr
)
1058 register struct symbol
*sym
;
1059 register struct type
*tmp
;
1061 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1062 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1064 tmp
= lookup_primitive_typename (name
);
1069 else if (!tmp
&& noerr
)
1075 error ("No type named %s.", name
);
1078 return (SYMBOL_TYPE (sym
));
1082 lookup_unsigned_typename (char *name
)
1084 char *uns
= alloca (strlen (name
) + 10);
1086 strcpy (uns
, "unsigned ");
1087 strcpy (uns
+ 9, name
);
1088 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
1092 lookup_signed_typename (char *name
)
1095 char *uns
= alloca (strlen (name
) + 8);
1097 strcpy (uns
, "signed ");
1098 strcpy (uns
+ 7, name
);
1099 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
1100 /* If we don't find "signed FOO" just try again with plain "FOO". */
1103 return lookup_typename (name
, (struct block
*) NULL
, 0);
1106 /* Lookup a structure type named "struct NAME",
1107 visible in lexical block BLOCK. */
1110 lookup_struct (char *name
, struct block
*block
)
1112 register struct symbol
*sym
;
1114 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1115 (struct symtab
**) NULL
);
1119 error ("No struct type named %s.", name
);
1121 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1123 error ("This context has class, union or enum %s, not a struct.", name
);
1125 return (SYMBOL_TYPE (sym
));
1128 /* Lookup a union type named "union NAME",
1129 visible in lexical block BLOCK. */
1132 lookup_union (char *name
, struct block
*block
)
1134 register struct symbol
*sym
;
1137 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1138 (struct symtab
**) NULL
);
1141 error ("No union type named %s.", name
);
1143 t
= SYMBOL_TYPE (sym
);
1145 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1148 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1149 * a further "declared_type" field to discover it is really a union.
1151 if (HAVE_CPLUS_STRUCT (t
))
1152 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1155 /* If we get here, it's not a union */
1156 error ("This context has class, struct or enum %s, not a union.", name
);
1160 /* Lookup an enum type named "enum NAME",
1161 visible in lexical block BLOCK. */
1164 lookup_enum (char *name
, struct block
*block
)
1166 register struct symbol
*sym
;
1168 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1169 (struct symtab
**) NULL
);
1172 error ("No enum type named %s.", name
);
1174 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1176 error ("This context has class, struct or union %s, not an enum.", name
);
1178 return (SYMBOL_TYPE (sym
));
1181 /* Lookup a template type named "template NAME<TYPE>",
1182 visible in lexical block BLOCK. */
1185 lookup_template_type (char *name
, struct type
*type
, struct block
*block
)
1188 char *nam
= (char *) alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1191 strcat (nam
, TYPE_NAME (type
));
1192 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1194 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1198 error ("No template type named %s.", name
);
1200 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1202 error ("This context has class, union or enum %s, not a struct.", name
);
1204 return (SYMBOL_TYPE (sym
));
1207 /* Given a type TYPE, lookup the type of the component of type named NAME.
1209 TYPE can be either a struct or union, or a pointer or reference to a struct or
1210 union. If it is a pointer or reference, its target type is automatically used.
1211 Thus '.' and '->' are interchangable, as specified for the definitions of the
1212 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1214 If NOERR is nonzero, return zero if NAME is not suitably defined.
1215 If NAME is the name of a baseclass type, return that type. */
1218 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1224 CHECK_TYPEDEF (type
);
1225 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1226 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1228 type
= TYPE_TARGET_TYPE (type
);
1231 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
1232 TYPE_CODE (type
) != TYPE_CODE_UNION
)
1234 target_terminal_ours ();
1235 gdb_flush (gdb_stdout
);
1236 fprintf_unfiltered (gdb_stderr
, "Type ");
1237 type_print (type
, "", gdb_stderr
, -1);
1238 error (" is not a structure or union type.");
1242 /* FIXME: This change put in by Michael seems incorrect for the case where
1243 the structure tag name is the same as the member name. I.E. when doing
1244 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1249 typename
= type_name_no_tag (type
);
1250 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1255 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1257 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1259 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1261 return TYPE_FIELD_TYPE (type
, i
);
1265 /* OK, it's not in this class. Recursively check the baseclasses. */
1266 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1270 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
1282 target_terminal_ours ();
1283 gdb_flush (gdb_stdout
);
1284 fprintf_unfiltered (gdb_stderr
, "Type ");
1285 type_print (type
, "", gdb_stderr
, -1);
1286 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1287 fputs_filtered (name
, gdb_stderr
);
1289 return (struct type
*) -1; /* For lint */
1292 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1293 valid. Callers should be aware that in some cases (for example,
1294 the type or one of its baseclasses is a stub type and we are
1295 debugging a .o file), this function will not be able to find the virtual
1296 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1297 will remain NULL. */
1300 fill_in_vptr_fieldno (struct type
*type
)
1302 CHECK_TYPEDEF (type
);
1304 if (TYPE_VPTR_FIELDNO (type
) < 0)
1308 /* We must start at zero in case the first (and only) baseclass is
1309 virtual (and hence we cannot share the table pointer). */
1310 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1312 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1313 fill_in_vptr_fieldno (baseclass
);
1314 if (TYPE_VPTR_FIELDNO (baseclass
) >= 0)
1316 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (baseclass
);
1317 TYPE_VPTR_BASETYPE (type
) = TYPE_VPTR_BASETYPE (baseclass
);
1324 /* Find the method and field indices for the destructor in class type T.
1325 Return 1 if the destructor was found, otherwise, return 0. */
1328 get_destructor_fn_field (struct type
*t
, int *method_indexp
, int *field_indexp
)
1332 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1335 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1337 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1339 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1350 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1352 If this is a stubbed struct (i.e. declared as struct foo *), see if
1353 we can find a full definition in some other file. If so, copy this
1354 definition, so we can use it in future. There used to be a comment (but
1355 not any code) that if we don't find a full definition, we'd set a flag
1356 so we don't spend time in the future checking the same type. That would
1357 be a mistake, though--we might load in more symbols which contain a
1358 full definition for the type.
1360 This used to be coded as a macro, but I don't think it is called
1361 often enough to merit such treatment. */
1364 stub_noname_complaint (void)
1366 complaint (&symfile_complaints
, "stub type has NULL name");
1370 check_typedef (struct type
*type
)
1372 struct type
*orig_type
= type
;
1373 int is_const
, is_volatile
;
1375 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1377 if (!TYPE_TARGET_TYPE (type
))
1382 /* It is dangerous to call lookup_symbol if we are currently
1383 reading a symtab. Infinite recursion is one danger. */
1384 if (currently_reading_symtab
)
1387 name
= type_name_no_tag (type
);
1388 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1389 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1390 as appropriate? (this code was written before TYPE_NAME and
1391 TYPE_TAG_NAME were separate). */
1394 stub_noname_complaint ();
1397 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0,
1398 (struct symtab
**) NULL
);
1400 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1402 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1404 type
= TYPE_TARGET_TYPE (type
);
1407 is_const
= TYPE_CONST (type
);
1408 is_volatile
= TYPE_VOLATILE (type
);
1410 /* If this is a struct/class/union with no fields, then check whether a
1411 full definition exists somewhere else. This is for systems where a
1412 type definition with no fields is issued for such types, instead of
1413 identifying them as stub types in the first place */
1415 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1417 char *name
= type_name_no_tag (type
);
1418 struct type
*newtype
;
1421 stub_noname_complaint ();
1424 newtype
= lookup_transparent_type (name
);
1426 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1428 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1429 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1431 char *name
= type_name_no_tag (type
);
1432 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1433 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1434 as appropriate? (this code was written before TYPE_NAME and
1435 TYPE_TAG_NAME were separate). */
1439 stub_noname_complaint ();
1442 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0, (struct symtab
**) NULL
);
1444 make_cv_type (is_const
, is_volatile
, SYMBOL_TYPE (sym
), &type
);
1447 if (TYPE_TARGET_STUB (type
))
1449 struct type
*range_type
;
1450 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1452 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1455 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1456 && TYPE_NFIELDS (type
) == 1
1457 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1458 == TYPE_CODE_RANGE
))
1460 /* Now recompute the length of the array type, based on its
1461 number of elements and the target type's length. */
1462 TYPE_LENGTH (type
) =
1463 ((TYPE_FIELD_BITPOS (range_type
, 1)
1464 - TYPE_FIELD_BITPOS (range_type
, 0)
1466 * TYPE_LENGTH (target_type
));
1467 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1469 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1471 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1472 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1475 /* Cache TYPE_LENGTH for future use. */
1476 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1480 #if 0 /* OBSOLETE CFront */
1481 // OBSOLETE /* New code added to support parsing of Cfront stabs strings */
1482 // OBSOLETE #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1483 // OBSOLETE #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1485 // OBSOLETE static void
1486 // OBSOLETE add_name (struct extra *pextras, char *n)
1488 // OBSOLETE int nlen;
1490 // OBSOLETE if ((nlen = (n ? strlen (n) : 0)) == 0)
1492 // OBSOLETE sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1493 // OBSOLETE pextras->len = strlen (pextras->str);
1496 // OBSOLETE static void
1497 // OBSOLETE add_mangled_type (struct extra *pextras, struct type *t)
1499 // OBSOLETE enum type_code tcode;
1500 // OBSOLETE int tlen, tflags;
1501 // OBSOLETE char *tname;
1503 // OBSOLETE tcode = TYPE_CODE (t);
1504 // OBSOLETE tlen = TYPE_LENGTH (t);
1505 // OBSOLETE tflags = TYPE_FLAGS (t);
1506 // OBSOLETE tname = TYPE_NAME (t);
1507 // OBSOLETE /* args of "..." seem to get mangled as "e" */
1509 // OBSOLETE switch (tcode)
1511 // OBSOLETE case TYPE_CODE_INT:
1512 // OBSOLETE if (tflags == 1)
1513 // OBSOLETE ADD_EXTRA ('U');
1514 // OBSOLETE switch (tlen)
1517 // OBSOLETE ADD_EXTRA ('c');
1520 // OBSOLETE ADD_EXTRA ('s');
1524 // OBSOLETE char *pname;
1525 // OBSOLETE if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1527 // OBSOLETE ADD_EXTRA ('l');
1531 // OBSOLETE ADD_EXTRA ('i');
1535 // OBSOLETE default:
1537 // OBSOLETE complaint (&symfile_complaints, "Bad int type code length x%x",
1542 // OBSOLETE case TYPE_CODE_FLT:
1543 // OBSOLETE switch (tlen)
1546 // OBSOLETE ADD_EXTRA ('f');
1549 // OBSOLETE ADD_EXTRA ('d');
1551 // OBSOLETE case 16:
1552 // OBSOLETE ADD_EXTRA ('r');
1554 // OBSOLETE default:
1556 // OBSOLETE complaint (&symfile_complaints, "Bad float type code length x%x",
1561 // OBSOLETE case TYPE_CODE_REF:
1562 // OBSOLETE ADD_EXTRA ('R');
1563 // OBSOLETE /* followed by what it's a ref to */
1565 // OBSOLETE case TYPE_CODE_PTR:
1566 // OBSOLETE ADD_EXTRA ('P');
1567 // OBSOLETE /* followed by what it's a ptr to */
1569 // OBSOLETE case TYPE_CODE_TYPEDEF:
1571 // OBSOLETE complaint (&symfile_complaints,
1572 // OBSOLETE "Typedefs in overloaded functions not yet supported");
1574 // OBSOLETE /* followed by type bytes & name */
1576 // OBSOLETE case TYPE_CODE_FUNC:
1577 // OBSOLETE ADD_EXTRA ('F');
1578 // OBSOLETE /* followed by func's arg '_' & ret types */
1580 // OBSOLETE case TYPE_CODE_VOID:
1581 // OBSOLETE ADD_EXTRA ('v');
1583 // OBSOLETE case TYPE_CODE_METHOD:
1584 // OBSOLETE ADD_EXTRA ('M');
1585 // OBSOLETE /* followed by name of class and func's arg '_' & ret types */
1586 // OBSOLETE add_name (pextras, tname);
1587 // OBSOLETE ADD_EXTRA ('F'); /* then mangle function */
1589 // OBSOLETE case TYPE_CODE_STRUCT: /* C struct */
1590 // OBSOLETE case TYPE_CODE_UNION: /* C union */
1591 // OBSOLETE case TYPE_CODE_ENUM: /* Enumeration type */
1592 // OBSOLETE /* followed by name of type */
1593 // OBSOLETE add_name (pextras, tname);
1596 // OBSOLETE /* errors possible types/not supported */
1597 // OBSOLETE case TYPE_CODE_CHAR:
1598 // OBSOLETE case TYPE_CODE_ARRAY: /* Array type */
1599 // OBSOLETE case TYPE_CODE_MEMBER: /* Member type */
1600 // OBSOLETE case TYPE_CODE_BOOL:
1601 // OBSOLETE case TYPE_CODE_COMPLEX: /* Complex float */
1602 // OBSOLETE case TYPE_CODE_UNDEF:
1603 // OBSOLETE case TYPE_CODE_SET: /* Pascal sets */
1604 // OBSOLETE case TYPE_CODE_RANGE:
1605 // OBSOLETE case TYPE_CODE_STRING:
1606 // OBSOLETE case TYPE_CODE_BITSTRING:
1607 // OBSOLETE case TYPE_CODE_ERROR:
1608 // OBSOLETE default:
1610 // OBSOLETE complaint (&symfile_complaints, "Unknown type code x%x", tcode);
1613 // OBSOLETE if (TYPE_TARGET_TYPE (t))
1614 // OBSOLETE add_mangled_type (pextras, TYPE_TARGET_TYPE (t));
1618 // OBSOLETE cfront_mangle_name (struct type *type, int i, int j)
1620 // OBSOLETE struct fn_field *f;
1621 // OBSOLETE char *mangled_name = gdb_mangle_name (type, i, j);
1623 // OBSOLETE f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1625 // OBSOLETE /* kludge to support cfront methods - gdb expects to find "F" for
1626 // OBSOLETE ARM_mangled names, so when we mangle, we have to add it here */
1627 // OBSOLETE if (ARM_DEMANGLING)
1630 // OBSOLETE char *arm_mangled_name;
1631 // OBSOLETE struct fn_field *method = &f[j];
1632 // OBSOLETE char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1633 // OBSOLETE char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1634 // OBSOLETE char *newname = type_name_no_tag (type);
1636 // OBSOLETE struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1637 // OBSOLETE int nargs = TYPE_NFIELDS (ftype); /* number of args */
1638 // OBSOLETE struct extra extras, *pextras = &extras;
1639 // OBSOLETE INIT_EXTRA
1641 // OBSOLETE if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1642 // OBSOLETE ADD_EXTRA ('S')
1643 // OBSOLETE ADD_EXTRA ('F')
1644 // OBSOLETE /* add args here! */
1645 // OBSOLETE if (nargs <= 1) /* no args besides this */
1646 // OBSOLETE ADD_EXTRA ('v')
1649 // OBSOLETE for (k = 1; k < nargs; k++)
1651 // OBSOLETE struct type *t;
1652 // OBSOLETE t = TYPE_FIELD_TYPE (ftype, k);
1653 // OBSOLETE add_mangled_type (pextras, t);
1656 // OBSOLETE ADD_EXTRA ('\0')
1657 // OBSOLETE printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1658 // OBSOLETE xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str);
1659 // OBSOLETE xfree (mangled_name);
1660 // OBSOLETE mangled_name = arm_mangled_name;
1664 // OBSOLETE #undef ADD_EXTRA
1665 // OBSOLETE /* End of new code added to support parsing of Cfront stabs strings */
1666 #endif /* OBSOLETE CFront */
1668 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1669 silently return builtin_type_void. */
1672 safe_parse_type (char *p
, int length
)
1674 struct ui_file
*saved_gdb_stderr
;
1677 /* Suppress error messages. */
1678 saved_gdb_stderr
= gdb_stderr
;
1679 gdb_stderr
= ui_file_new ();
1681 /* Call parse_and_eval_type() without fear of longjmp()s. */
1682 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1683 type
= builtin_type_void
;
1685 /* Stop suppressing error messages. */
1686 ui_file_delete (gdb_stderr
);
1687 gdb_stderr
= saved_gdb_stderr
;
1692 /* Ugly hack to convert method stubs into method types.
1694 He ain't kiddin'. This demangles the name of the method into a string
1695 including argument types, parses out each argument type, generates
1696 a string casting a zero to that type, evaluates the string, and stuffs
1697 the resulting type into an argtype vector!!! Then it knows the type
1698 of the whole function (including argument types for overloading),
1699 which info used to be in the stab's but was removed to hack back
1700 the space required for them. */
1703 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1706 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1707 char *demangled_name
= cplus_demangle (mangled_name
,
1708 DMGL_PARAMS
| DMGL_ANSI
);
1709 char *argtypetext
, *p
;
1710 int depth
= 0, argcount
= 1;
1711 struct field
*argtypes
;
1714 /* Make sure we got back a function string that we can use. */
1716 p
= strchr (demangled_name
, '(');
1720 if (demangled_name
== NULL
|| p
== NULL
)
1721 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
1723 /* Now, read in the parameters that define this type. */
1728 if (*p
== '(' || *p
== '<')
1732 else if (*p
== ')' || *p
== '>')
1736 else if (*p
== ',' && depth
== 0)
1744 /* If we read one argument and it was ``void'', don't count it. */
1745 if (strncmp (argtypetext
, "(void)", 6) == 0)
1748 /* We need one extra slot, for the THIS pointer. */
1750 argtypes
= (struct field
*)
1751 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1754 /* Add THIS pointer for non-static methods. */
1755 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1756 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1760 argtypes
[0].type
= lookup_pointer_type (type
);
1764 if (*p
!= ')') /* () means no args, skip while */
1769 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1771 /* Avoid parsing of ellipsis, they will be handled below.
1772 Also avoid ``void'' as above. */
1773 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1774 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1776 argtypes
[argcount
].type
=
1777 safe_parse_type (argtypetext
, p
- argtypetext
);
1780 argtypetext
= p
+ 1;
1783 if (*p
== '(' || *p
== '<')
1787 else if (*p
== ')' || *p
== '>')
1796 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1798 /* Now update the old "stub" type into a real type. */
1799 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1800 TYPE_DOMAIN_TYPE (mtype
) = type
;
1801 TYPE_FIELDS (mtype
) = argtypes
;
1802 TYPE_NFIELDS (mtype
) = argcount
;
1803 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1804 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1806 TYPE_FLAGS (mtype
) |= TYPE_FLAG_VARARGS
;
1808 xfree (demangled_name
);
1811 /* This is the external interface to check_stub_method, above. This function
1812 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1813 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1814 and TYPE_FN_FIELDLIST_NAME will be correct.
1816 This function unfortunately can not die until stabs do. */
1819 check_stub_method_group (struct type
*type
, int method_id
)
1821 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1822 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1823 int j
, found_stub
= 0;
1825 for (j
= 0; j
< len
; j
++)
1826 if (TYPE_FN_FIELD_STUB (f
, j
))
1829 check_stub_method (type
, method_id
, j
);
1832 /* GNU v3 methods with incorrect names were corrected when we read in
1833 type information, because it was cheaper to do it then. The only GNU v2
1834 methods with incorrect method names are operators and destructors;
1835 destructors were also corrected when we read in type information.
1837 Therefore the only thing we need to handle here are v2 operator
1839 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1842 char dem_opname
[256];
1844 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1845 dem_opname
, DMGL_ANSI
);
1847 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1850 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1854 const struct cplus_struct_type cplus_struct_default
;
1857 allocate_cplus_struct_type (struct type
*type
)
1859 if (!HAVE_CPLUS_STRUCT (type
))
1861 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1862 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1863 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1867 /* Helper function to initialize the standard scalar types.
1869 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1870 of the string pointed to by name in the type_obstack for that objfile,
1871 and initialize the type name to that copy. There are places (mipsread.c
1872 in particular, where init_type is called with a NULL value for NAME). */
1875 init_type (enum type_code code
, int length
, int flags
, char *name
,
1876 struct objfile
*objfile
)
1878 register struct type
*type
;
1880 type
= alloc_type (objfile
);
1881 TYPE_CODE (type
) = code
;
1882 TYPE_LENGTH (type
) = length
;
1883 TYPE_FLAGS (type
) |= flags
;
1884 if ((name
!= NULL
) && (objfile
!= NULL
))
1887 obsavestring (name
, strlen (name
), &objfile
->type_obstack
);
1891 TYPE_NAME (type
) = name
;
1896 if (name
&& strcmp (name
, "char") == 0)
1897 TYPE_FLAGS (type
) |= TYPE_FLAG_NOSIGN
;
1899 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1901 INIT_CPLUS_SPECIFIC (type
);
1906 /* Helper function. Create an empty composite type. */
1909 init_composite_type (char *name
, enum type_code code
)
1912 gdb_assert (code
== TYPE_CODE_STRUCT
1913 || code
== TYPE_CODE_UNION
);
1914 t
= init_type (code
, 0, 0, NULL
, NULL
);
1915 TYPE_TAG_NAME (t
) = name
;
1919 /* Helper function. Append a field to a composite type. */
1922 append_composite_type_field (struct type
*t
, char *name
, struct type
*field
)
1925 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
1926 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
1927 sizeof (struct field
) * TYPE_NFIELDS (t
));
1928 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
1929 memset (f
, 0, sizeof f
[0]);
1930 FIELD_TYPE (f
[0]) = field
;
1931 FIELD_NAME (f
[0]) = name
;
1932 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1934 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
1935 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
1937 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
1939 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
1940 if (TYPE_NFIELDS (t
) > 1)
1942 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
1943 + TYPE_LENGTH (field
) * TARGET_CHAR_BIT
);
1948 /* Look up a fundamental type for the specified objfile.
1949 May need to construct such a type if this is the first use.
1951 Some object file formats (ELF, COFF, etc) do not define fundamental
1952 types such as "int" or "double". Others (stabs for example), do
1953 define fundamental types.
1955 For the formats which don't provide fundamental types, gdb can create
1956 such types, using defaults reasonable for the current language and
1957 the current target machine.
1959 NOTE: This routine is obsolescent. Each debugging format reader
1960 should manage it's own fundamental types, either creating them from
1961 suitable defaults or reading them from the debugging information,
1962 whichever is appropriate. The DWARF reader has already been
1963 fixed to do this. Once the other readers are fixed, this routine
1964 will go away. Also note that fundamental types should be managed
1965 on a compilation unit basis in a multi-language environment, not
1966 on a linkage unit basis as is done here. */
1970 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1972 register struct type
**typep
;
1973 register int nbytes
;
1975 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1977 error ("internal error - invalid fundamental type id %d", typeid);
1980 /* If this is the first time we need a fundamental type for this objfile
1981 then we need to initialize the vector of type pointers. */
1983 if (objfile
->fundamental_types
== NULL
)
1985 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1986 objfile
->fundamental_types
= (struct type
**)
1987 obstack_alloc (&objfile
->type_obstack
, nbytes
);
1988 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1989 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1992 /* Look for this particular type in the fundamental type vector. If one is
1993 not found, create and install one appropriate for the current language. */
1995 typep
= objfile
->fundamental_types
+ typeid;
1998 *typep
= create_fundamental_type (objfile
, typeid);
2005 can_dereference (struct type
*t
)
2007 /* FIXME: Should we return true for references as well as pointers? */
2011 && TYPE_CODE (t
) == TYPE_CODE_PTR
2012 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
2016 is_integral_type (struct type
*t
)
2021 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
2022 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
2023 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
2024 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
2025 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
2028 /* Check whether BASE is an ancestor or base class or DCLASS
2029 Return 1 if so, and 0 if not.
2030 Note: callers may want to check for identity of the types before
2031 calling this function -- identical types are considered to satisfy
2032 the ancestor relationship even if they're identical */
2035 is_ancestor (struct type
*base
, struct type
*dclass
)
2039 CHECK_TYPEDEF (base
);
2040 CHECK_TYPEDEF (dclass
);
2044 if (TYPE_NAME (base
) && TYPE_NAME (dclass
) &&
2045 !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
2048 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2049 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
2057 /* See whether DCLASS has a virtual table. This routine is aimed at
2058 the HP/Taligent ANSI C++ runtime model, and may not work with other
2059 runtime models. Return 1 => Yes, 0 => No. */
2062 has_vtable (struct type
*dclass
)
2064 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
2065 has virtual functions or virtual bases. */
2069 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
2072 /* First check for the presence of virtual bases */
2073 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
2074 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2075 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
2078 /* Next check for virtual functions */
2079 if (TYPE_FN_FIELDLISTS (dclass
))
2080 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
2081 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
2084 /* Recurse on non-virtual bases to see if any of them needs a vtable */
2085 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
2086 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2087 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
2088 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
2091 /* Well, maybe we don't need a virtual table */
2095 /* Return a pointer to the "primary base class" of DCLASS.
2097 A NULL return indicates that DCLASS has no primary base, or that it
2098 couldn't be found (insufficient information).
2100 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2101 and may not work with other runtime models. */
2104 primary_base_class (struct type
*dclass
)
2106 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
2107 is the first directly inherited, non-virtual base class that
2108 requires a virtual table */
2112 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
2115 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2116 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
2117 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
2118 return TYPE_FIELD_TYPE (dclass
, i
);
2123 /* Global manipulated by virtual_base_list[_aux]() */
2125 static struct vbase
*current_vbase_list
= NULL
;
2127 /* Return a pointer to a null-terminated list of struct vbase
2128 items. The vbasetype pointer of each item in the list points to the
2129 type information for a virtual base of the argument DCLASS.
2131 Helper function for virtual_base_list().
2132 Note: the list goes backward, right-to-left. virtual_base_list()
2133 copies the items out in reverse order. */
2136 virtual_base_list_aux (struct type
*dclass
)
2138 struct vbase
*tmp_vbase
;
2141 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
2144 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2146 /* Recurse on this ancestor, first */
2147 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
2149 /* If this current base is itself virtual, add it to the list */
2150 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
2152 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
2154 /* Check if base already recorded */
2155 tmp_vbase
= current_vbase_list
;
2158 if (tmp_vbase
->vbasetype
== basetype
)
2159 break; /* found it */
2160 tmp_vbase
= tmp_vbase
->next
;
2163 if (!tmp_vbase
) /* normal exit from loop */
2165 /* Allocate new item for this virtual base */
2166 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
2168 /* Stick it on at the end of the list */
2169 tmp_vbase
->vbasetype
= basetype
;
2170 tmp_vbase
->next
= current_vbase_list
;
2171 current_vbase_list
= tmp_vbase
;
2174 } /* for loop over bases */
2178 /* Compute the list of virtual bases in the right order. Virtual
2179 bases are laid out in the object's memory area in order of their
2180 occurrence in a depth-first, left-to-right search through the
2183 Argument DCLASS is the type whose virtual bases are required.
2184 Return value is the address of a null-terminated array of pointers
2185 to struct type items.
2187 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2188 and may not work with other runtime models.
2190 This routine merely hands off the argument to virtual_base_list_aux()
2191 and then copies the result into an array to save space. */
2194 virtual_base_list (struct type
*dclass
)
2196 register struct vbase
*tmp_vbase
;
2197 register struct vbase
*tmp_vbase_2
;
2200 struct type
**vbase_array
;
2202 current_vbase_list
= NULL
;
2203 virtual_base_list_aux (dclass
);
2205 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2210 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
2212 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
2213 vbase_array
[i
] = tmp_vbase
->vbasetype
;
2215 /* Get rid of constructed chain */
2216 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
2219 tmp_vbase
= tmp_vbase
->next
;
2220 xfree (tmp_vbase_2
);
2221 tmp_vbase_2
= tmp_vbase
;
2224 vbase_array
[count
] = NULL
;
2228 /* Return the length of the virtual base list of the type DCLASS. */
2231 virtual_base_list_length (struct type
*dclass
)
2234 register struct vbase
*tmp_vbase
;
2236 current_vbase_list
= NULL
;
2237 virtual_base_list_aux (dclass
);
2239 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2244 /* Return the number of elements of the virtual base list of the type
2245 DCLASS, ignoring those appearing in the primary base (and its
2246 primary base, recursively). */
2249 virtual_base_list_length_skip_primaries (struct type
*dclass
)
2252 register struct vbase
*tmp_vbase
;
2253 struct type
*primary
;
2255 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2258 return virtual_base_list_length (dclass
);
2260 current_vbase_list
= NULL
;
2261 virtual_base_list_aux (dclass
);
2263 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
2265 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
2273 /* Return the index (position) of type BASE, which is a virtual base
2274 class of DCLASS, in the latter's virtual base list. A return of -1
2275 indicates "not found" or a problem. */
2278 virtual_base_index (struct type
*base
, struct type
*dclass
)
2280 register struct type
*vbase
;
2283 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2284 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2288 vbase
= virtual_base_list (dclass
)[0];
2293 vbase
= virtual_base_list (dclass
)[++i
];
2296 return vbase
? i
: -1;
2301 /* Return the index (position) of type BASE, which is a virtual base
2302 class of DCLASS, in the latter's virtual base list. Skip over all
2303 bases that may appear in the virtual base list of the primary base
2304 class of DCLASS (recursively). A return of -1 indicates "not
2305 found" or a problem. */
2308 virtual_base_index_skip_primaries (struct type
*base
, struct type
*dclass
)
2310 register struct type
*vbase
;
2312 struct type
*primary
;
2314 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2315 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2318 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2322 vbase
= virtual_base_list (dclass
)[0];
2325 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
2329 vbase
= virtual_base_list (dclass
)[++i
];
2332 return vbase
? j
: -1;
2335 /* Return position of a derived class DCLASS in the list of
2336 * primary bases starting with the remotest ancestor.
2337 * Position returned is 0-based. */
2340 class_index_in_primary_list (struct type
*dclass
)
2342 struct type
*pbc
; /* primary base class */
2344 /* Simply recurse on primary base */
2345 pbc
= TYPE_PRIMARY_BASE (dclass
);
2347 return 1 + class_index_in_primary_list (pbc
);
2352 /* Return a count of the number of virtual functions a type has.
2353 * This includes all the virtual functions it inherits from its
2357 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2358 * functions only once (latest redefinition)
2362 count_virtual_fns (struct type
*dclass
)
2364 int fn
, oi
; /* function and overloaded instance indices */
2365 int vfuncs
; /* count to return */
2367 /* recurse on bases that can share virtual table */
2368 struct type
*pbc
= primary_base_class (dclass
);
2370 vfuncs
= count_virtual_fns (pbc
);
2374 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2375 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2376 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2384 /* Functions for overload resolution begin here */
2386 /* Compare two badness vectors A and B and return the result.
2387 * 0 => A and B are identical
2388 * 1 => A and B are incomparable
2389 * 2 => A is better than B
2390 * 3 => A is worse than B */
2393 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2397 short found_pos
= 0; /* any positives in c? */
2398 short found_neg
= 0; /* any negatives in c? */
2400 /* differing lengths => incomparable */
2401 if (a
->length
!= b
->length
)
2404 /* Subtract b from a */
2405 for (i
= 0; i
< a
->length
; i
++)
2407 tmp
= a
->rank
[i
] - b
->rank
[i
];
2417 return 1; /* incomparable */
2419 return 3; /* A > B */
2425 return 2; /* A < B */
2427 return 0; /* A == B */
2431 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2432 * to the types of an argument list (ARGS, length NARGS).
2433 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2435 struct badness_vector
*
2436 rank_function (struct type
**parms
, int nparms
, struct type
**args
, int nargs
)
2439 struct badness_vector
*bv
;
2440 int min_len
= nparms
< nargs
? nparms
: nargs
;
2442 bv
= xmalloc (sizeof (struct badness_vector
));
2443 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2444 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2446 /* First compare the lengths of the supplied lists.
2447 * If there is a mismatch, set it to a high value. */
2449 /* pai/1997-06-03 FIXME: when we have debug info about default
2450 * arguments and ellipsis parameter lists, we should consider those
2451 * and rank the length-match more finely. */
2453 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2455 /* Now rank all the parameters of the candidate function */
2456 for (i
= 1; i
<= min_len
; i
++)
2457 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2459 /* If more arguments than parameters, add dummy entries */
2460 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2461 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2466 /* Compare the names of two integer types, assuming that any sign
2467 qualifiers have been checked already. We do it this way because
2468 there may be an "int" in the name of one of the types. */
2471 integer_types_same_name_p (const char *first
, const char *second
)
2473 int first_p
, second_p
;
2475 /* If both are shorts, return 1; if neither is a short, keep checking. */
2476 first_p
= (strstr (first
, "short") != NULL
);
2477 second_p
= (strstr (second
, "short") != NULL
);
2478 if (first_p
&& second_p
)
2480 if (first_p
|| second_p
)
2483 /* Likewise for long. */
2484 first_p
= (strstr (first
, "long") != NULL
);
2485 second_p
= (strstr (second
, "long") != NULL
);
2486 if (first_p
&& second_p
)
2488 if (first_p
|| second_p
)
2491 /* Likewise for char. */
2492 first_p
= (strstr (first
, "char") != NULL
);
2493 second_p
= (strstr (second
, "char") != NULL
);
2494 if (first_p
&& second_p
)
2496 if (first_p
|| second_p
)
2499 /* They must both be ints. */
2503 /* Compare one type (PARM) for compatibility with another (ARG).
2504 * PARM is intended to be the parameter type of a function; and
2505 * ARG is the supplied argument's type. This function tests if
2506 * the latter can be converted to the former.
2508 * Return 0 if they are identical types;
2509 * Otherwise, return an integer which corresponds to how compatible
2510 * PARM is to ARG. The higher the return value, the worse the match.
2511 * Generally the "bad" conversions are all uniformly assigned a 100 */
2514 rank_one_type (struct type
*parm
, struct type
*arg
)
2516 /* Identical type pointers */
2517 /* However, this still doesn't catch all cases of same type for arg
2518 * and param. The reason is that builtin types are different from
2519 * the same ones constructed from the object. */
2523 /* Resolve typedefs */
2524 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2525 parm
= check_typedef (parm
);
2526 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2527 arg
= check_typedef (arg
);
2530 Well, damnit, if the names are exactly the same,
2531 i'll say they are exactly the same. This happens when we generate
2532 method stubs. The types won't point to the same address, but they
2533 really are the same.
2536 if (TYPE_NAME (parm
) && TYPE_NAME (arg
) &&
2537 !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2540 /* Check if identical after resolving typedefs */
2544 /* See through references, since we can almost make non-references
2546 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2547 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2548 + REFERENCE_CONVERSION_BADNESS
);
2549 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2550 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2551 + REFERENCE_CONVERSION_BADNESS
);
2553 /* Debugging only. */
2554 fprintf_filtered (gdb_stderr
,"------ Arg is %s [%d], parm is %s [%d]\n",
2555 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2557 /* x -> y means arg of type x being supplied for parameter of type y */
2559 switch (TYPE_CODE (parm
))
2562 switch (TYPE_CODE (arg
))
2565 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2566 return VOID_PTR_CONVERSION_BADNESS
;
2568 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2569 case TYPE_CODE_ARRAY
:
2570 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2571 case TYPE_CODE_FUNC
:
2572 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2574 case TYPE_CODE_ENUM
:
2575 case TYPE_CODE_CHAR
:
2576 case TYPE_CODE_RANGE
:
2577 case TYPE_CODE_BOOL
:
2578 return POINTER_CONVERSION_BADNESS
;
2580 return INCOMPATIBLE_TYPE_BADNESS
;
2582 case TYPE_CODE_ARRAY
:
2583 switch (TYPE_CODE (arg
))
2586 case TYPE_CODE_ARRAY
:
2587 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2589 return INCOMPATIBLE_TYPE_BADNESS
;
2591 case TYPE_CODE_FUNC
:
2592 switch (TYPE_CODE (arg
))
2594 case TYPE_CODE_PTR
: /* funcptr -> func */
2595 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2597 return INCOMPATIBLE_TYPE_BADNESS
;
2600 switch (TYPE_CODE (arg
))
2603 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2605 /* Deal with signed, unsigned, and plain chars and
2606 signed and unsigned ints */
2607 if (TYPE_NOSIGN (parm
))
2609 /* This case only for character types */
2610 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2613 return INTEGER_CONVERSION_BADNESS
; /* signed/unsigned char -> plain char */
2615 else if (TYPE_UNSIGNED (parm
))
2617 if (TYPE_UNSIGNED (arg
))
2619 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2620 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2622 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2623 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2624 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2626 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2630 if (integer_types_same_name_p (TYPE_NAME (arg
), "long")
2631 && integer_types_same_name_p (TYPE_NAME (parm
), "int"))
2632 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2634 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2637 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2639 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2641 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2642 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2643 return INTEGER_PROMOTION_BADNESS
;
2645 return INTEGER_CONVERSION_BADNESS
;
2648 return INTEGER_CONVERSION_BADNESS
;
2650 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2651 return INTEGER_PROMOTION_BADNESS
;
2653 return INTEGER_CONVERSION_BADNESS
;
2654 case TYPE_CODE_ENUM
:
2655 case TYPE_CODE_CHAR
:
2656 case TYPE_CODE_RANGE
:
2657 case TYPE_CODE_BOOL
:
2658 return INTEGER_PROMOTION_BADNESS
;
2660 return INT_FLOAT_CONVERSION_BADNESS
;
2662 return NS_POINTER_CONVERSION_BADNESS
;
2664 return INCOMPATIBLE_TYPE_BADNESS
;
2667 case TYPE_CODE_ENUM
:
2668 switch (TYPE_CODE (arg
))
2671 case TYPE_CODE_CHAR
:
2672 case TYPE_CODE_RANGE
:
2673 case TYPE_CODE_BOOL
:
2674 case TYPE_CODE_ENUM
:
2675 return INTEGER_CONVERSION_BADNESS
;
2677 return INT_FLOAT_CONVERSION_BADNESS
;
2679 return INCOMPATIBLE_TYPE_BADNESS
;
2682 case TYPE_CODE_CHAR
:
2683 switch (TYPE_CODE (arg
))
2685 case TYPE_CODE_RANGE
:
2686 case TYPE_CODE_BOOL
:
2687 case TYPE_CODE_ENUM
:
2688 return INTEGER_CONVERSION_BADNESS
;
2690 return INT_FLOAT_CONVERSION_BADNESS
;
2692 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2693 return INTEGER_CONVERSION_BADNESS
;
2694 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2695 return INTEGER_PROMOTION_BADNESS
;
2696 /* >>> !! else fall through !! <<< */
2697 case TYPE_CODE_CHAR
:
2698 /* Deal with signed, unsigned, and plain chars for C++
2699 and with int cases falling through from previous case */
2700 if (TYPE_NOSIGN (parm
))
2702 if (TYPE_NOSIGN (arg
))
2705 return INTEGER_CONVERSION_BADNESS
;
2707 else if (TYPE_UNSIGNED (parm
))
2709 if (TYPE_UNSIGNED (arg
))
2712 return INTEGER_PROMOTION_BADNESS
;
2714 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2717 return INTEGER_CONVERSION_BADNESS
;
2719 return INCOMPATIBLE_TYPE_BADNESS
;
2722 case TYPE_CODE_RANGE
:
2723 switch (TYPE_CODE (arg
))
2726 case TYPE_CODE_CHAR
:
2727 case TYPE_CODE_RANGE
:
2728 case TYPE_CODE_BOOL
:
2729 case TYPE_CODE_ENUM
:
2730 return INTEGER_CONVERSION_BADNESS
;
2732 return INT_FLOAT_CONVERSION_BADNESS
;
2734 return INCOMPATIBLE_TYPE_BADNESS
;
2737 case TYPE_CODE_BOOL
:
2738 switch (TYPE_CODE (arg
))
2741 case TYPE_CODE_CHAR
:
2742 case TYPE_CODE_RANGE
:
2743 case TYPE_CODE_ENUM
:
2746 return BOOLEAN_CONVERSION_BADNESS
;
2747 case TYPE_CODE_BOOL
:
2750 return INCOMPATIBLE_TYPE_BADNESS
;
2754 switch (TYPE_CODE (arg
))
2757 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2758 return FLOAT_PROMOTION_BADNESS
;
2759 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2762 return FLOAT_CONVERSION_BADNESS
;
2764 case TYPE_CODE_BOOL
:
2765 case TYPE_CODE_ENUM
:
2766 case TYPE_CODE_RANGE
:
2767 case TYPE_CODE_CHAR
:
2768 return INT_FLOAT_CONVERSION_BADNESS
;
2770 return INCOMPATIBLE_TYPE_BADNESS
;
2773 case TYPE_CODE_COMPLEX
:
2774 switch (TYPE_CODE (arg
))
2775 { /* Strictly not needed for C++, but... */
2777 return FLOAT_PROMOTION_BADNESS
;
2778 case TYPE_CODE_COMPLEX
:
2781 return INCOMPATIBLE_TYPE_BADNESS
;
2784 case TYPE_CODE_STRUCT
:
2785 /* currently same as TYPE_CODE_CLASS */
2786 switch (TYPE_CODE (arg
))
2788 case TYPE_CODE_STRUCT
:
2789 /* Check for derivation */
2790 if (is_ancestor (parm
, arg
))
2791 return BASE_CONVERSION_BADNESS
;
2792 /* else fall through */
2794 return INCOMPATIBLE_TYPE_BADNESS
;
2797 case TYPE_CODE_UNION
:
2798 switch (TYPE_CODE (arg
))
2800 case TYPE_CODE_UNION
:
2802 return INCOMPATIBLE_TYPE_BADNESS
;
2805 case TYPE_CODE_MEMBER
:
2806 switch (TYPE_CODE (arg
))
2809 return INCOMPATIBLE_TYPE_BADNESS
;
2812 case TYPE_CODE_METHOD
:
2813 switch (TYPE_CODE (arg
))
2817 return INCOMPATIBLE_TYPE_BADNESS
;
2821 switch (TYPE_CODE (arg
))
2825 return INCOMPATIBLE_TYPE_BADNESS
;
2830 switch (TYPE_CODE (arg
))
2834 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2836 return INCOMPATIBLE_TYPE_BADNESS
;
2839 case TYPE_CODE_VOID
:
2841 return INCOMPATIBLE_TYPE_BADNESS
;
2842 } /* switch (TYPE_CODE (arg)) */
2846 /* End of functions for overload resolution */
2849 print_bit_vector (B_TYPE
*bits
, int nbits
)
2853 for (bitno
= 0; bitno
< nbits
; bitno
++)
2855 if ((bitno
% 8) == 0)
2857 puts_filtered (" ");
2859 if (B_TST (bits
, bitno
))
2861 printf_filtered ("1");
2865 printf_filtered ("0");
2870 /* Note the first arg should be the "this" pointer, we may not want to
2871 include it since we may get into a infinitely recursive situation. */
2874 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2880 for (i
= 0; i
< nargs
; i
++)
2881 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2886 dump_fn_fieldlists (struct type
*type
, int spaces
)
2892 printfi_filtered (spaces
, "fn_fieldlists ");
2893 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2894 printf_filtered ("\n");
2895 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2897 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2898 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2900 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2901 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2903 printf_filtered (") length %d\n",
2904 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2905 for (overload_idx
= 0;
2906 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2909 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2911 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2912 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2914 printf_filtered (")\n");
2915 printfi_filtered (spaces
+ 8, "type ");
2916 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2917 printf_filtered ("\n");
2919 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2922 printfi_filtered (spaces
+ 8, "args ");
2923 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2924 printf_filtered ("\n");
2926 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2927 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
, overload_idx
)),
2929 printfi_filtered (spaces
+ 8, "fcontext ");
2930 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2932 printf_filtered ("\n");
2934 printfi_filtered (spaces
+ 8, "is_const %d\n",
2935 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2936 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2937 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2938 printfi_filtered (spaces
+ 8, "is_private %d\n",
2939 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2940 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2941 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2942 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2943 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2944 printfi_filtered (spaces
+ 8, "voffset %u\n",
2945 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2951 print_cplus_stuff (struct type
*type
, int spaces
)
2953 printfi_filtered (spaces
, "n_baseclasses %d\n",
2954 TYPE_N_BASECLASSES (type
));
2955 printfi_filtered (spaces
, "nfn_fields %d\n",
2956 TYPE_NFN_FIELDS (type
));
2957 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2958 TYPE_NFN_FIELDS_TOTAL (type
));
2959 if (TYPE_N_BASECLASSES (type
) > 0)
2961 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2962 TYPE_N_BASECLASSES (type
));
2963 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2964 printf_filtered (")");
2966 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2967 TYPE_N_BASECLASSES (type
));
2968 puts_filtered ("\n");
2970 if (TYPE_NFIELDS (type
) > 0)
2972 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2974 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2975 TYPE_NFIELDS (type
));
2976 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2977 printf_filtered (")");
2978 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2979 TYPE_NFIELDS (type
));
2980 puts_filtered ("\n");
2982 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2984 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2985 TYPE_NFIELDS (type
));
2986 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2987 printf_filtered (")");
2988 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2989 TYPE_NFIELDS (type
));
2990 puts_filtered ("\n");
2993 if (TYPE_NFN_FIELDS (type
) > 0)
2995 dump_fn_fieldlists (type
, spaces
);
3000 print_bound_type (int bt
)
3004 case BOUND_CANNOT_BE_DETERMINED
:
3005 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
3007 case BOUND_BY_REF_ON_STACK
:
3008 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
3010 case BOUND_BY_VALUE_ON_STACK
:
3011 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
3013 case BOUND_BY_REF_IN_REG
:
3014 printf_filtered ("(BOUND_BY_REF_IN_REG)");
3016 case BOUND_BY_VALUE_IN_REG
:
3017 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
3020 printf_filtered ("(BOUND_SIMPLE)");
3023 printf_filtered ("(unknown bound type)");
3028 static struct obstack dont_print_type_obstack
;
3031 recursive_dump_type (struct type
*type
, int spaces
)
3036 obstack_begin (&dont_print_type_obstack
, 0);
3038 if (TYPE_NFIELDS (type
) > 0
3039 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
3041 struct type
**first_dont_print
3042 = (struct type
**) obstack_base (&dont_print_type_obstack
);
3044 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
3049 if (type
== first_dont_print
[i
])
3051 printfi_filtered (spaces
, "type node ");
3052 gdb_print_host_address (type
, gdb_stdout
);
3053 printf_filtered (" <same as already seen type>\n");
3058 obstack_ptr_grow (&dont_print_type_obstack
, type
);
3061 printfi_filtered (spaces
, "type node ");
3062 gdb_print_host_address (type
, gdb_stdout
);
3063 printf_filtered ("\n");
3064 printfi_filtered (spaces
, "name '%s' (",
3065 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
3066 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
3067 printf_filtered (")\n");
3068 printfi_filtered (spaces
, "tagname '%s' (",
3069 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
3070 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
3071 printf_filtered (")\n");
3072 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
3073 switch (TYPE_CODE (type
))
3075 case TYPE_CODE_UNDEF
:
3076 printf_filtered ("(TYPE_CODE_UNDEF)");
3079 printf_filtered ("(TYPE_CODE_PTR)");
3081 case TYPE_CODE_ARRAY
:
3082 printf_filtered ("(TYPE_CODE_ARRAY)");
3084 case TYPE_CODE_STRUCT
:
3085 printf_filtered ("(TYPE_CODE_STRUCT)");
3087 case TYPE_CODE_UNION
:
3088 printf_filtered ("(TYPE_CODE_UNION)");
3090 case TYPE_CODE_ENUM
:
3091 printf_filtered ("(TYPE_CODE_ENUM)");
3093 case TYPE_CODE_FUNC
:
3094 printf_filtered ("(TYPE_CODE_FUNC)");
3097 printf_filtered ("(TYPE_CODE_INT)");
3100 printf_filtered ("(TYPE_CODE_FLT)");
3102 case TYPE_CODE_VOID
:
3103 printf_filtered ("(TYPE_CODE_VOID)");
3106 printf_filtered ("(TYPE_CODE_SET)");
3108 case TYPE_CODE_RANGE
:
3109 printf_filtered ("(TYPE_CODE_RANGE)");
3111 case TYPE_CODE_STRING
:
3112 printf_filtered ("(TYPE_CODE_STRING)");
3114 case TYPE_CODE_BITSTRING
:
3115 printf_filtered ("(TYPE_CODE_BITSTRING)");
3117 case TYPE_CODE_ERROR
:
3118 printf_filtered ("(TYPE_CODE_ERROR)");
3120 case TYPE_CODE_MEMBER
:
3121 printf_filtered ("(TYPE_CODE_MEMBER)");
3123 case TYPE_CODE_METHOD
:
3124 printf_filtered ("(TYPE_CODE_METHOD)");
3127 printf_filtered ("(TYPE_CODE_REF)");
3129 case TYPE_CODE_CHAR
:
3130 printf_filtered ("(TYPE_CODE_CHAR)");
3132 case TYPE_CODE_BOOL
:
3133 printf_filtered ("(TYPE_CODE_BOOL)");
3135 case TYPE_CODE_COMPLEX
:
3136 printf_filtered ("(TYPE_CODE_COMPLEX)");
3138 case TYPE_CODE_TYPEDEF
:
3139 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3141 case TYPE_CODE_TEMPLATE
:
3142 printf_filtered ("(TYPE_CODE_TEMPLATE)");
3144 case TYPE_CODE_TEMPLATE_ARG
:
3145 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
3148 printf_filtered ("(UNKNOWN TYPE CODE)");
3151 puts_filtered ("\n");
3152 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
3153 printfi_filtered (spaces
, "upper_bound_type 0x%x ",
3154 TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3155 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3156 puts_filtered ("\n");
3157 printfi_filtered (spaces
, "lower_bound_type 0x%x ",
3158 TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3159 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3160 puts_filtered ("\n");
3161 printfi_filtered (spaces
, "objfile ");
3162 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
3163 printf_filtered ("\n");
3164 printfi_filtered (spaces
, "target_type ");
3165 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
3166 printf_filtered ("\n");
3167 if (TYPE_TARGET_TYPE (type
) != NULL
)
3169 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
3171 printfi_filtered (spaces
, "pointer_type ");
3172 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
3173 printf_filtered ("\n");
3174 printfi_filtered (spaces
, "reference_type ");
3175 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
3176 printf_filtered ("\n");
3177 printfi_filtered (spaces
, "type_chain ");
3178 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
3179 printf_filtered ("\n");
3180 printfi_filtered (spaces
, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type
));
3181 if (TYPE_CONST (type
))
3183 puts_filtered (" TYPE_FLAG_CONST");
3185 if (TYPE_VOLATILE (type
))
3187 puts_filtered (" TYPE_FLAG_VOLATILE");
3189 if (TYPE_CODE_SPACE (type
))
3191 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3193 if (TYPE_DATA_SPACE (type
))
3195 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3197 if (TYPE_ADDRESS_CLASS_1 (type
))
3199 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3201 if (TYPE_ADDRESS_CLASS_2 (type
))
3203 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3205 puts_filtered ("\n");
3206 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
3207 if (TYPE_UNSIGNED (type
))
3209 puts_filtered (" TYPE_FLAG_UNSIGNED");
3211 if (TYPE_NOSIGN (type
))
3213 puts_filtered (" TYPE_FLAG_NOSIGN");
3215 if (TYPE_STUB (type
))
3217 puts_filtered (" TYPE_FLAG_STUB");
3219 if (TYPE_TARGET_STUB (type
))
3221 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3223 if (TYPE_STATIC (type
))
3225 puts_filtered (" TYPE_FLAG_STATIC");
3227 if (TYPE_PROTOTYPED (type
))
3229 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3231 if (TYPE_INCOMPLETE (type
))
3233 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3235 if (TYPE_VARARGS (type
))
3237 puts_filtered (" TYPE_FLAG_VARARGS");
3239 /* This is used for things like AltiVec registers on ppc. Gcc emits
3240 an attribute for the array type, which tells whether or not we
3241 have a vector, instead of a regular array. */
3242 if (TYPE_VECTOR (type
))
3244 puts_filtered (" TYPE_FLAG_VECTOR");
3246 puts_filtered ("\n");
3247 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
3248 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
3249 puts_filtered ("\n");
3250 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
3252 printfi_filtered (spaces
+ 2,
3253 "[%d] bitpos %d bitsize %d type ",
3254 idx
, TYPE_FIELD_BITPOS (type
, idx
),
3255 TYPE_FIELD_BITSIZE (type
, idx
));
3256 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
3257 printf_filtered (" name '%s' (",
3258 TYPE_FIELD_NAME (type
, idx
) != NULL
3259 ? TYPE_FIELD_NAME (type
, idx
)
3261 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
3262 printf_filtered (")\n");
3263 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
3265 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
3268 printfi_filtered (spaces
, "vptr_basetype ");
3269 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
3270 puts_filtered ("\n");
3271 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
3273 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
3275 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
3276 switch (TYPE_CODE (type
))
3278 case TYPE_CODE_STRUCT
:
3279 printfi_filtered (spaces
, "cplus_stuff ");
3280 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3281 puts_filtered ("\n");
3282 print_cplus_stuff (type
, spaces
);
3286 printfi_filtered (spaces
, "floatformat ");
3287 if (TYPE_FLOATFORMAT (type
) == NULL
3288 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
3289 puts_filtered ("(null)");
3291 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
3292 puts_filtered ("\n");
3296 /* We have to pick one of the union types to be able print and test
3297 the value. Pick cplus_struct_type, even though we know it isn't
3298 any particular one. */
3299 printfi_filtered (spaces
, "type_specific ");
3300 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3301 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
3303 printf_filtered (" (unknown data form)");
3305 printf_filtered ("\n");
3310 obstack_free (&dont_print_type_obstack
, NULL
);
3313 static void build_gdbtypes (void);
3315 build_gdbtypes (void)
3318 init_type (TYPE_CODE_VOID
, 1,
3320 "void", (struct objfile
*) NULL
);
3322 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3324 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3325 "char", (struct objfile
*) NULL
);
3326 builtin_type_true_char
=
3327 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3329 "true character", (struct objfile
*) NULL
);
3330 builtin_type_signed_char
=
3331 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3333 "signed char", (struct objfile
*) NULL
);
3334 builtin_type_unsigned_char
=
3335 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3337 "unsigned char", (struct objfile
*) NULL
);
3338 builtin_type_short
=
3339 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3341 "short", (struct objfile
*) NULL
);
3342 builtin_type_unsigned_short
=
3343 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3345 "unsigned short", (struct objfile
*) NULL
);
3347 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3349 "int", (struct objfile
*) NULL
);
3350 builtin_type_unsigned_int
=
3351 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3353 "unsigned int", (struct objfile
*) NULL
);
3355 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3357 "long", (struct objfile
*) NULL
);
3358 builtin_type_unsigned_long
=
3359 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3361 "unsigned long", (struct objfile
*) NULL
);
3362 builtin_type_long_long
=
3363 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3365 "long long", (struct objfile
*) NULL
);
3366 builtin_type_unsigned_long_long
=
3367 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3369 "unsigned long long", (struct objfile
*) NULL
);
3370 builtin_type_float
=
3371 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3373 "float", (struct objfile
*) NULL
);
3374 /* vinschen@redhat.com 2002-02-08:
3375 The below lines are disabled since they are doing the wrong
3376 thing for non-multiarch targets. They are setting the correct
3377 type of floats for the target but while on multiarch targets
3378 this is done everytime the architecture changes, it's done on
3379 non-multiarch targets only on startup, leaving the wrong values
3380 in even if the architecture changes (eg. from big-endian to
3383 TYPE_FLOATFORMAT (builtin_type_float
) = TARGET_FLOAT_FORMAT
;
3385 builtin_type_double
=
3386 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3388 "double", (struct objfile
*) NULL
);
3390 TYPE_FLOATFORMAT (builtin_type_double
) = TARGET_DOUBLE_FORMAT
;
3392 builtin_type_long_double
=
3393 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3395 "long double", (struct objfile
*) NULL
);
3397 TYPE_FLOATFORMAT (builtin_type_long_double
) = TARGET_LONG_DOUBLE_FORMAT
;
3399 builtin_type_complex
=
3400 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3402 "complex", (struct objfile
*) NULL
);
3403 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
3404 builtin_type_double_complex
=
3405 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3407 "double complex", (struct objfile
*) NULL
);
3408 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
3409 builtin_type_string
=
3410 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3412 "string", (struct objfile
*) NULL
);
3414 init_type (TYPE_CODE_INT
, 8 / 8,
3416 "int8_t", (struct objfile
*) NULL
);
3417 builtin_type_uint8
=
3418 init_type (TYPE_CODE_INT
, 8 / 8,
3420 "uint8_t", (struct objfile
*) NULL
);
3421 builtin_type_int16
=
3422 init_type (TYPE_CODE_INT
, 16 / 8,
3424 "int16_t", (struct objfile
*) NULL
);
3425 builtin_type_uint16
=
3426 init_type (TYPE_CODE_INT
, 16 / 8,
3428 "uint16_t", (struct objfile
*) NULL
);
3429 builtin_type_int32
=
3430 init_type (TYPE_CODE_INT
, 32 / 8,
3432 "int32_t", (struct objfile
*) NULL
);
3433 builtin_type_uint32
=
3434 init_type (TYPE_CODE_INT
, 32 / 8,
3436 "uint32_t", (struct objfile
*) NULL
);
3437 builtin_type_int64
=
3438 init_type (TYPE_CODE_INT
, 64 / 8,
3440 "int64_t", (struct objfile
*) NULL
);
3441 builtin_type_uint64
=
3442 init_type (TYPE_CODE_INT
, 64 / 8,
3444 "uint64_t", (struct objfile
*) NULL
);
3445 builtin_type_int128
=
3446 init_type (TYPE_CODE_INT
, 128 / 8,
3448 "int128_t", (struct objfile
*) NULL
);
3449 builtin_type_uint128
=
3450 init_type (TYPE_CODE_INT
, 128 / 8,
3452 "uint128_t", (struct objfile
*) NULL
);
3454 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3456 "bool", (struct objfile
*) NULL
);
3458 /* Add user knob for controlling resolution of opaque types */
3460 (add_set_cmd ("opaque-type-resolution", class_support
, var_boolean
, (char *) &opaque_type_resolution
,
3461 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3464 opaque_type_resolution
= 1;
3466 /* Build SIMD types. */
3468 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
3470 = init_simd_type ("__builtin_v4si", builtin_type_int32
, "f", 4);
3472 = init_simd_type ("__builtin_v16qi", builtin_type_int8
, "f", 16);
3474 = init_simd_type ("__builtin_v8qi", builtin_type_int8
, "f", 8);
3476 = init_simd_type ("__builtin_v8hi", builtin_type_int16
, "f", 8);
3478 = init_simd_type ("__builtin_v4hi", builtin_type_int16
, "f", 4);
3480 = init_simd_type ("__builtin_v2si", builtin_type_int32
, "f", 2);
3482 /* 128 bit vectors. */
3483 builtin_type_v2_double
= init_vector_type (builtin_type_double
, 2);
3484 builtin_type_v4_float
= init_vector_type (builtin_type_float
, 4);
3485 builtin_type_v2_int64
= init_vector_type (builtin_type_int64
, 2);
3486 builtin_type_v4_int32
= init_vector_type (builtin_type_int32
, 4);
3487 builtin_type_v8_int16
= init_vector_type (builtin_type_int16
, 8);
3488 builtin_type_v16_int8
= init_vector_type (builtin_type_int8
, 16);
3489 /* 64 bit vectors. */
3490 builtin_type_v2_float
= init_vector_type (builtin_type_float
, 2);
3491 builtin_type_v2_int32
= init_vector_type (builtin_type_int32
, 2);
3492 builtin_type_v4_int16
= init_vector_type (builtin_type_int16
, 4);
3493 builtin_type_v8_int8
= init_vector_type (builtin_type_int8
, 8);
3496 builtin_type_vec64
= build_builtin_type_vec64 ();
3497 builtin_type_vec64i
= build_builtin_type_vec64i ();
3498 builtin_type_vec128
= build_builtin_type_vec128 ();
3499 builtin_type_vec128i
= build_builtin_type_vec128i ();
3501 /* Pointer/Address types. */
3503 /* NOTE: on some targets, addresses and pointers are not necessarily
3504 the same --- for example, on the D10V, pointers are 16 bits long,
3505 but addresses are 32 bits long. See doc/gdbint.texinfo,
3506 ``Pointers Are Not Always Addresses''.
3509 - gdb's `struct type' always describes the target's
3511 - gdb's `struct value' objects should always hold values in
3513 - gdb's CORE_ADDR values are addresses in the unified virtual
3514 address space that the assembler and linker work with. Thus,
3515 since target_read_memory takes a CORE_ADDR as an argument, it
3516 can access any memory on the target, even if the processor has
3517 separate code and data address spaces.
3520 - If v is a value holding a D10V code pointer, its contents are
3521 in target form: a big-endian address left-shifted two bits.
3522 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3523 sizeof (void *) == 2 on the target.
3525 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3526 target type for a value the target will never see. It's only
3527 used to hold the values of (typeless) linker symbols, which are
3528 indeed in the unified virtual address space. */
3529 builtin_type_void_data_ptr
= make_pointer_type (builtin_type_void
, NULL
);
3530 builtin_type_void_func_ptr
3531 = lookup_pointer_type (lookup_function_type (builtin_type_void
));
3532 builtin_type_CORE_ADDR
=
3533 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3535 "__CORE_ADDR", (struct objfile
*) NULL
);
3536 builtin_type_bfd_vma
=
3537 init_type (TYPE_CODE_INT
, TARGET_BFD_VMA_BIT
/ 8,
3539 "__bfd_vma", (struct objfile
*) NULL
);
3542 extern void _initialize_gdbtypes (void);
3544 _initialize_gdbtypes (void)
3546 struct cmd_list_element
*c
;
3549 /* FIXME - For the moment, handle types by swapping them in and out.
3550 Should be using the per-architecture data-pointer and a large
3552 register_gdbarch_swap (&builtin_type_void
, sizeof (struct type
*), NULL
);
3553 register_gdbarch_swap (&builtin_type_char
, sizeof (struct type
*), NULL
);
3554 register_gdbarch_swap (&builtin_type_short
, sizeof (struct type
*), NULL
);
3555 register_gdbarch_swap (&builtin_type_int
, sizeof (struct type
*), NULL
);
3556 register_gdbarch_swap (&builtin_type_long
, sizeof (struct type
*), NULL
);
3557 register_gdbarch_swap (&builtin_type_long_long
, sizeof (struct type
*), NULL
);
3558 register_gdbarch_swap (&builtin_type_signed_char
, sizeof (struct type
*), NULL
);
3559 register_gdbarch_swap (&builtin_type_unsigned_char
, sizeof (struct type
*), NULL
);
3560 register_gdbarch_swap (&builtin_type_unsigned_short
, sizeof (struct type
*), NULL
);
3561 register_gdbarch_swap (&builtin_type_unsigned_int
, sizeof (struct type
*), NULL
);
3562 register_gdbarch_swap (&builtin_type_unsigned_long
, sizeof (struct type
*), NULL
);
3563 register_gdbarch_swap (&builtin_type_unsigned_long_long
, sizeof (struct type
*), NULL
);
3564 register_gdbarch_swap (&builtin_type_float
, sizeof (struct type
*), NULL
);
3565 register_gdbarch_swap (&builtin_type_double
, sizeof (struct type
*), NULL
);
3566 register_gdbarch_swap (&builtin_type_long_double
, sizeof (struct type
*), NULL
);
3567 register_gdbarch_swap (&builtin_type_complex
, sizeof (struct type
*), NULL
);
3568 register_gdbarch_swap (&builtin_type_double_complex
, sizeof (struct type
*), NULL
);
3569 register_gdbarch_swap (&builtin_type_string
, sizeof (struct type
*), NULL
);
3570 register_gdbarch_swap (&builtin_type_int8
, sizeof (struct type
*), NULL
);
3571 register_gdbarch_swap (&builtin_type_uint8
, sizeof (struct type
*), NULL
);
3572 register_gdbarch_swap (&builtin_type_int16
, sizeof (struct type
*), NULL
);
3573 register_gdbarch_swap (&builtin_type_uint16
, sizeof (struct type
*), NULL
);
3574 register_gdbarch_swap (&builtin_type_int32
, sizeof (struct type
*), NULL
);
3575 register_gdbarch_swap (&builtin_type_uint32
, sizeof (struct type
*), NULL
);
3576 register_gdbarch_swap (&builtin_type_int64
, sizeof (struct type
*), NULL
);
3577 register_gdbarch_swap (&builtin_type_uint64
, sizeof (struct type
*), NULL
);
3578 register_gdbarch_swap (&builtin_type_int128
, sizeof (struct type
*), NULL
);
3579 register_gdbarch_swap (&builtin_type_uint128
, sizeof (struct type
*), NULL
);
3580 register_gdbarch_swap (&builtin_type_v4sf
, sizeof (struct type
*), NULL
);
3581 register_gdbarch_swap (&builtin_type_v4si
, sizeof (struct type
*), NULL
);
3582 register_gdbarch_swap (&builtin_type_v16qi
, sizeof (struct type
*), NULL
);
3583 register_gdbarch_swap (&builtin_type_v8qi
, sizeof (struct type
*), NULL
);
3584 register_gdbarch_swap (&builtin_type_v8hi
, sizeof (struct type
*), NULL
);
3585 register_gdbarch_swap (&builtin_type_v4hi
, sizeof (struct type
*), NULL
);
3586 register_gdbarch_swap (&builtin_type_v2si
, sizeof (struct type
*), NULL
);
3587 register_gdbarch_swap (&builtin_type_v2_double
, sizeof (struct type
*), NULL
);
3588 register_gdbarch_swap (&builtin_type_v4_float
, sizeof (struct type
*), NULL
);
3589 register_gdbarch_swap (&builtin_type_v2_int64
, sizeof (struct type
*), NULL
);
3590 register_gdbarch_swap (&builtin_type_v4_int32
, sizeof (struct type
*), NULL
);
3591 register_gdbarch_swap (&builtin_type_v8_int16
, sizeof (struct type
*), NULL
);
3592 register_gdbarch_swap (&builtin_type_v16_int8
, sizeof (struct type
*), NULL
);
3593 register_gdbarch_swap (&builtin_type_v2_float
, sizeof (struct type
*), NULL
);
3594 register_gdbarch_swap (&builtin_type_v2_int32
, sizeof (struct type
*), NULL
);
3595 register_gdbarch_swap (&builtin_type_v8_int8
, sizeof (struct type
*), NULL
);
3596 register_gdbarch_swap (&builtin_type_v4_int16
, sizeof (struct type
*), NULL
);
3597 register_gdbarch_swap (&builtin_type_vec128
, sizeof (struct type
*), NULL
);
3598 register_gdbarch_swap (&builtin_type_vec128i
, sizeof (struct type
*), NULL
);
3599 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr
);
3600 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr
);
3601 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR
);
3602 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma
);
3603 register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
3605 /* Note: These types do not need to be swapped - they are target
3607 builtin_type_ieee_single_big
=
3608 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_big
.totalsize
/ 8,
3609 0, "builtin_type_ieee_single_big", NULL
);
3610 TYPE_FLOATFORMAT (builtin_type_ieee_single_big
) = &floatformat_ieee_single_big
;
3611 builtin_type_ieee_single_little
=
3612 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_little
.totalsize
/ 8,
3613 0, "builtin_type_ieee_single_little", NULL
);
3614 TYPE_FLOATFORMAT (builtin_type_ieee_single_little
) = &floatformat_ieee_single_little
;
3615 builtin_type_ieee_double_big
=
3616 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_big
.totalsize
/ 8,
3617 0, "builtin_type_ieee_double_big", NULL
);
3618 TYPE_FLOATFORMAT (builtin_type_ieee_double_big
) = &floatformat_ieee_double_big
;
3619 builtin_type_ieee_double_little
=
3620 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_little
.totalsize
/ 8,
3621 0, "builtin_type_ieee_double_little", NULL
);
3622 TYPE_FLOATFORMAT (builtin_type_ieee_double_little
) = &floatformat_ieee_double_little
;
3623 builtin_type_ieee_double_littlebyte_bigword
=
3624 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_littlebyte_bigword
.totalsize
/ 8,
3625 0, "builtin_type_ieee_double_littlebyte_bigword", NULL
);
3626 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword
) = &floatformat_ieee_double_littlebyte_bigword
;
3627 builtin_type_i387_ext
=
3628 init_type (TYPE_CODE_FLT
, floatformat_i387_ext
.totalsize
/ 8,
3629 0, "builtin_type_i387_ext", NULL
);
3630 TYPE_FLOATFORMAT (builtin_type_i387_ext
) = &floatformat_i387_ext
;
3631 builtin_type_m68881_ext
=
3632 init_type (TYPE_CODE_FLT
, floatformat_m68881_ext
.totalsize
/ 8,
3633 0, "builtin_type_m68881_ext", NULL
);
3634 TYPE_FLOATFORMAT (builtin_type_m68881_ext
) = &floatformat_m68881_ext
;
3635 builtin_type_i960_ext
=
3636 init_type (TYPE_CODE_FLT
, floatformat_i960_ext
.totalsize
/ 8,
3637 0, "builtin_type_i960_ext", NULL
);
3638 TYPE_FLOATFORMAT (builtin_type_i960_ext
) = &floatformat_i960_ext
;
3639 builtin_type_m88110_ext
=
3640 init_type (TYPE_CODE_FLT
, floatformat_m88110_ext
.totalsize
/ 8,
3641 0, "builtin_type_m88110_ext", NULL
);
3642 TYPE_FLOATFORMAT (builtin_type_m88110_ext
) = &floatformat_m88110_ext
;
3643 builtin_type_m88110_harris_ext
=
3644 init_type (TYPE_CODE_FLT
, floatformat_m88110_harris_ext
.totalsize
/ 8,
3645 0, "builtin_type_m88110_harris_ext", NULL
);
3646 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext
) = &floatformat_m88110_harris_ext
;
3647 builtin_type_arm_ext_big
=
3648 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_big
.totalsize
/ 8,
3649 0, "builtin_type_arm_ext_big", NULL
);
3650 TYPE_FLOATFORMAT (builtin_type_arm_ext_big
) = &floatformat_arm_ext_big
;
3651 builtin_type_arm_ext_littlebyte_bigword
=
3652 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_littlebyte_bigword
.totalsize
/ 8,
3653 0, "builtin_type_arm_ext_littlebyte_bigword", NULL
);
3654 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword
) = &floatformat_arm_ext_littlebyte_bigword
;
3655 builtin_type_ia64_spill_big
=
3656 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_big
.totalsize
/ 8,
3657 0, "builtin_type_ia64_spill_big", NULL
);
3658 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big
) = &floatformat_ia64_spill_big
;
3659 builtin_type_ia64_spill_little
=
3660 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_little
.totalsize
/ 8,
3661 0, "builtin_type_ia64_spill_little", NULL
);
3662 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little
) = &floatformat_ia64_spill_little
;
3663 builtin_type_ia64_quad_big
=
3664 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_big
.totalsize
/ 8,
3665 0, "builtin_type_ia64_quad_big", NULL
);
3666 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big
) = &floatformat_ia64_quad_big
;
3667 builtin_type_ia64_quad_little
=
3668 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_little
.totalsize
/ 8,
3669 0, "builtin_type_ia64_quad_little", NULL
);
3670 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little
) = &floatformat_ia64_quad_little
;
3673 add_set_cmd ("overload", no_class
, var_zinteger
, (char *) &overload_debug
,
3674 "Set debugging of C++ overloading.\n\
3675 When enabled, ranking of the functions\n\
3676 is displayed.", &setdebuglist
),