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_int0
;
64 struct type
*builtin_type_int8
;
65 struct type
*builtin_type_uint8
;
66 struct type
*builtin_type_int16
;
67 struct type
*builtin_type_uint16
;
68 struct type
*builtin_type_int32
;
69 struct type
*builtin_type_uint32
;
70 struct type
*builtin_type_int64
;
71 struct type
*builtin_type_uint64
;
72 struct type
*builtin_type_int128
;
73 struct type
*builtin_type_uint128
;
74 struct type
*builtin_type_bool
;
76 /* 128 bit long vector types */
77 struct type
*builtin_type_v2_double
;
78 struct type
*builtin_type_v4_float
;
79 struct type
*builtin_type_v2_int64
;
80 struct type
*builtin_type_v4_int32
;
81 struct type
*builtin_type_v8_int16
;
82 struct type
*builtin_type_v16_int8
;
83 /* 64 bit long vector types */
84 struct type
*builtin_type_v2_float
;
85 struct type
*builtin_type_v2_int32
;
86 struct type
*builtin_type_v4_int16
;
87 struct type
*builtin_type_v8_int8
;
89 struct type
*builtin_type_v4sf
;
90 struct type
*builtin_type_v4si
;
91 struct type
*builtin_type_v16qi
;
92 struct type
*builtin_type_v8qi
;
93 struct type
*builtin_type_v8hi
;
94 struct type
*builtin_type_v4hi
;
95 struct type
*builtin_type_v2si
;
96 struct type
*builtin_type_vec64
;
97 struct type
*builtin_type_vec64i
;
98 struct type
*builtin_type_vec128
;
99 struct type
*builtin_type_vec128i
;
100 struct type
*builtin_type_ieee_single_big
;
101 struct type
*builtin_type_ieee_single_little
;
102 struct type
*builtin_type_ieee_double_big
;
103 struct type
*builtin_type_ieee_double_little
;
104 struct type
*builtin_type_ieee_double_littlebyte_bigword
;
105 struct type
*builtin_type_i387_ext
;
106 struct type
*builtin_type_m68881_ext
;
107 struct type
*builtin_type_i960_ext
;
108 struct type
*builtin_type_m88110_ext
;
109 struct type
*builtin_type_m88110_harris_ext
;
110 struct type
*builtin_type_arm_ext_big
;
111 struct type
*builtin_type_arm_ext_littlebyte_bigword
;
112 struct type
*builtin_type_ia64_spill_big
;
113 struct type
*builtin_type_ia64_spill_little
;
114 struct type
*builtin_type_ia64_quad_big
;
115 struct type
*builtin_type_ia64_quad_little
;
116 struct type
*builtin_type_void_data_ptr
;
117 struct type
*builtin_type_void_func_ptr
;
118 struct type
*builtin_type_CORE_ADDR
;
119 struct type
*builtin_type_bfd_vma
;
121 int opaque_type_resolution
= 1;
122 int overload_debug
= 0;
128 }; /* maximum extension is 128! FIXME */
130 static void add_name (struct extra
*, char *);
131 static void add_mangled_type (struct extra
*, struct type
*);
132 #if 0 /* OBSOLETE CFront */
133 // OBSOLETE static void cfront_mangle_name (struct type *, int, int);
134 #endif /* OBSOLETE CFront */
135 static void print_bit_vector (B_TYPE
*, int);
136 static void print_arg_types (struct field
*, int, int);
137 static void dump_fn_fieldlists (struct type
*, int);
138 static void print_cplus_stuff (struct type
*, int);
139 static void virtual_base_list_aux (struct type
*dclass
);
142 /* Alloc a new type structure and fill it with some defaults. If
143 OBJFILE is non-NULL, then allocate the space for the type structure
144 in that objfile's type_obstack. Otherwise allocate the new type structure
145 by xmalloc () (for permanent types). */
148 alloc_type (struct objfile
*objfile
)
152 /* Alloc the structure and start off with all fields zeroed. */
156 type
= xmalloc (sizeof (struct type
));
157 memset (type
, 0, sizeof (struct type
));
158 TYPE_MAIN_TYPE (type
) = xmalloc (sizeof (struct main_type
));
162 type
= obstack_alloc (&objfile
->type_obstack
,
163 sizeof (struct type
));
164 memset (type
, 0, sizeof (struct type
));
165 TYPE_MAIN_TYPE (type
) = obstack_alloc (&objfile
->type_obstack
,
166 sizeof (struct main_type
));
167 OBJSTAT (objfile
, n_types
++);
169 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
171 /* Initialize the fields that might not be zero. */
173 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
174 TYPE_OBJFILE (type
) = objfile
;
175 TYPE_VPTR_FIELDNO (type
) = -1;
176 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
181 /* Alloc a new type instance structure, fill it with some defaults,
182 and point it at OLDTYPE. Allocate the new type instance from the
183 same place as OLDTYPE. */
186 alloc_type_instance (struct type
*oldtype
)
190 /* Allocate the structure. */
192 if (TYPE_OBJFILE (oldtype
) == NULL
)
194 type
= xmalloc (sizeof (struct type
));
195 memset (type
, 0, sizeof (struct type
));
199 type
= obstack_alloc (&TYPE_OBJFILE (oldtype
)->type_obstack
,
200 sizeof (struct type
));
201 memset (type
, 0, sizeof (struct type
));
203 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
205 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
210 /* Clear all remnants of the previous type at TYPE, in preparation for
211 replacing it with something else. */
213 smash_type (struct type
*type
)
215 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
217 /* For now, delete the rings. */
218 TYPE_CHAIN (type
) = type
;
220 /* For now, leave the pointer/reference types alone. */
223 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
224 to a pointer to memory where the pointer type should be stored.
225 If *TYPEPTR is zero, update it to point to the pointer type we return.
226 We allocate new memory if needed. */
229 make_pointer_type (struct type
*type
, struct type
**typeptr
)
231 struct type
*ntype
; /* New type */
232 struct objfile
*objfile
;
234 ntype
= TYPE_POINTER_TYPE (type
);
239 return ntype
; /* Don't care about alloc, and have new type. */
240 else if (*typeptr
== 0)
242 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
247 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
249 ntype
= alloc_type (TYPE_OBJFILE (type
));
254 /* We have storage, but need to reset it. */
257 objfile
= TYPE_OBJFILE (ntype
);
259 TYPE_OBJFILE (ntype
) = objfile
;
262 TYPE_TARGET_TYPE (ntype
) = type
;
263 TYPE_POINTER_TYPE (type
) = ntype
;
265 /* FIXME! Assume the machine has only one representation for pointers! */
267 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
268 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
270 /* Mark pointers as unsigned. The target converts between pointers
271 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
272 ADDRESS_TO_POINTER(). */
273 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
275 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
276 TYPE_POINTER_TYPE (type
) = ntype
;
281 /* Given a type TYPE, return a type of pointers to that type.
282 May need to construct such a type if this is the first use. */
285 lookup_pointer_type (struct type
*type
)
287 return make_pointer_type (type
, (struct type
**) 0);
290 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
291 to a pointer to memory where the reference type should be stored.
292 If *TYPEPTR is zero, update it to point to the reference type we return.
293 We allocate new memory if needed. */
296 make_reference_type (struct type
*type
, struct type
**typeptr
)
298 struct type
*ntype
; /* New type */
299 struct objfile
*objfile
;
301 ntype
= TYPE_REFERENCE_TYPE (type
);
306 return ntype
; /* Don't care about alloc, and have new type. */
307 else if (*typeptr
== 0)
309 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
314 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
316 ntype
= alloc_type (TYPE_OBJFILE (type
));
321 /* We have storage, but need to reset it. */
324 objfile
= TYPE_OBJFILE (ntype
);
326 TYPE_OBJFILE (ntype
) = objfile
;
329 TYPE_TARGET_TYPE (ntype
) = type
;
330 TYPE_REFERENCE_TYPE (type
) = ntype
;
332 /* FIXME! Assume the machine has only one representation for references,
333 and that it matches the (only) representation for pointers! */
335 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
336 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
338 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
339 TYPE_REFERENCE_TYPE (type
) = ntype
;
344 /* Same as above, but caller doesn't care about memory allocation details. */
347 lookup_reference_type (struct type
*type
)
349 return make_reference_type (type
, (struct type
**) 0);
352 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
353 to a pointer to memory where the function type should be stored.
354 If *TYPEPTR is zero, update it to point to the function type we return.
355 We allocate new memory if needed. */
358 make_function_type (struct type
*type
, struct type
**typeptr
)
360 struct type
*ntype
; /* New type */
361 struct objfile
*objfile
;
363 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
365 ntype
= alloc_type (TYPE_OBJFILE (type
));
370 /* We have storage, but need to reset it. */
373 objfile
= TYPE_OBJFILE (ntype
);
375 TYPE_OBJFILE (ntype
) = objfile
;
378 TYPE_TARGET_TYPE (ntype
) = type
;
380 TYPE_LENGTH (ntype
) = 1;
381 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
387 /* Given a type TYPE, return a type of functions that return that type.
388 May need to construct such a type if this is the first use. */
391 lookup_function_type (struct type
*type
)
393 return make_function_type (type
, (struct type
**) 0);
396 /* Identify address space identifier by name --
397 return the integer flag defined in gdbtypes.h. */
399 address_space_name_to_int (char *space_identifier
)
401 struct gdbarch
*gdbarch
= current_gdbarch
;
403 /* Check for known address space delimiters. */
404 if (!strcmp (space_identifier
, "code"))
405 return TYPE_FLAG_CODE_SPACE
;
406 else if (!strcmp (space_identifier
, "data"))
407 return TYPE_FLAG_DATA_SPACE
;
408 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
409 && gdbarch_address_class_name_to_type_flags (gdbarch
,
414 error ("Unknown address space specifier: \"%s\"", space_identifier
);
417 /* Identify address space identifier by integer flag as defined in
418 gdbtypes.h -- return the string version of the adress space name. */
421 address_space_int_to_name (int space_flag
)
423 struct gdbarch
*gdbarch
= current_gdbarch
;
424 if (space_flag
& TYPE_FLAG_CODE_SPACE
)
426 else if (space_flag
& TYPE_FLAG_DATA_SPACE
)
428 else if ((space_flag
& TYPE_FLAG_ADDRESS_CLASS_ALL
)
429 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
430 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
435 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
436 If STORAGE is non-NULL, create the new type instance there. */
439 make_qualified_type (struct type
*type
, int new_flags
,
440 struct type
*storage
)
446 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
448 ntype
= TYPE_CHAIN (ntype
);
449 } while (ntype
!= type
);
451 /* Create a new type instance. */
453 ntype
= alloc_type_instance (type
);
457 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
458 TYPE_CHAIN (ntype
) = ntype
;
461 /* Pointers or references to the original type are not relevant to
463 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
464 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
466 /* Chain the new qualified type to the old type. */
467 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
468 TYPE_CHAIN (type
) = ntype
;
470 /* Now set the instance flags and return the new type. */
471 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
473 /* Set length of new type to that of the original type. */
474 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
479 /* Make an address-space-delimited variant of a type -- a type that
480 is identical to the one supplied except that it has an address
481 space attribute attached to it (such as "code" or "data").
483 The space attributes "code" and "data" are for Harvard architectures.
484 The address space attributes are for architectures which have
485 alternately sized pointers or pointers with alternate representations. */
488 make_type_with_address_space (struct type
*type
, int space_flag
)
491 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
492 & ~(TYPE_FLAG_CODE_SPACE
| TYPE_FLAG_DATA_SPACE
493 | TYPE_FLAG_ADDRESS_CLASS_ALL
))
496 return make_qualified_type (type
, new_flags
, NULL
);
499 /* Make a "c-v" variant of a type -- a type that is identical to the
500 one supplied except that it may have const or volatile attributes
501 CNST is a flag for setting the const attribute
502 VOLTL is a flag for setting the volatile attribute
503 TYPE is the base type whose variant we are creating.
504 TYPEPTR, if nonzero, points
505 to a pointer to memory where the reference type should be stored.
506 If *TYPEPTR is zero, update it to point to the reference type we return.
507 We allocate new memory if needed. */
510 make_cv_type (int cnst
, int voltl
, struct type
*type
, struct type
**typeptr
)
512 struct type
*ntype
; /* New type */
513 struct type
*tmp_type
= type
; /* tmp type */
514 struct objfile
*objfile
;
516 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
517 & ~(TYPE_FLAG_CONST
| TYPE_FLAG_VOLATILE
));
520 new_flags
|= TYPE_FLAG_CONST
;
523 new_flags
|= TYPE_FLAG_VOLATILE
;
525 if (typeptr
&& *typeptr
!= NULL
)
527 /* Objfile is per-core-type. This const-qualified type had best
528 belong to the same objfile as the type it is qualifying, unless
529 we are overwriting a stub type, in which case the safest thing
530 to do is to copy the core type into the new objfile. */
532 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
)
533 || TYPE_STUB (*typeptr
));
534 if (TYPE_OBJFILE (*typeptr
) != TYPE_OBJFILE (type
))
536 TYPE_MAIN_TYPE (*typeptr
)
537 = TYPE_ALLOC (*typeptr
, sizeof (struct main_type
));
538 *TYPE_MAIN_TYPE (*typeptr
)
539 = *TYPE_MAIN_TYPE (type
);
543 ntype
= make_qualified_type (type
, new_flags
, typeptr
? *typeptr
: NULL
);
551 /* Replace the contents of ntype with the type *type. This changes the
552 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
553 the changes are propogated to all types in the TYPE_CHAIN.
555 In order to build recursive types, it's inevitable that we'll need
556 to update types in place --- but this sort of indiscriminate
557 smashing is ugly, and needs to be replaced with something more
558 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
559 clear if more steps are needed. */
561 replace_type (struct type
*ntype
, struct type
*type
)
565 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
567 /* The type length is not a part of the main type. Update it for each
568 type on the variant chain. */
571 /* Assert that this element of the chain has no address-class bits
572 set in its flags. Such type variants might have type lengths
573 which are supposed to be different from the non-address-class
574 variants. This assertion shouldn't ever be triggered because
575 symbol readers which do construct address-class variants don't
576 call replace_type(). */
577 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
579 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
580 chain
= TYPE_CHAIN (chain
);
581 } while (ntype
!= chain
);
583 /* Assert that the two types have equivalent instance qualifiers.
584 This should be true for at least all of our debug readers. */
585 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
588 /* Implement direct support for MEMBER_TYPE in GNU C++.
589 May need to construct such a type if this is the first use.
590 The TYPE is the type of the member. The DOMAIN is the type
591 of the aggregate that the member belongs to. */
594 lookup_member_type (struct type
*type
, struct type
*domain
)
598 mtype
= alloc_type (TYPE_OBJFILE (type
));
599 smash_to_member_type (mtype
, domain
, type
);
603 /* Allocate a stub method whose return type is TYPE.
604 This apparently happens for speed of symbol reading, since parsing
605 out the arguments to the method is cpu-intensive, the way we are doing
606 it. So, we will fill in arguments later.
607 This always returns a fresh type. */
610 allocate_stub_method (struct type
*type
)
614 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
615 TYPE_OBJFILE (type
));
616 TYPE_TARGET_TYPE (mtype
) = type
;
617 /* _DOMAIN_TYPE (mtype) = unknown yet */
621 /* Create a range type using either a blank type supplied in RESULT_TYPE,
622 or creating a new type, inheriting the objfile from INDEX_TYPE.
624 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
625 HIGH_BOUND, inclusive.
627 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
628 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
631 create_range_type (struct type
*result_type
, struct type
*index_type
,
632 int low_bound
, int high_bound
)
634 if (result_type
== NULL
)
636 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
638 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
639 TYPE_TARGET_TYPE (result_type
) = index_type
;
640 if (TYPE_STUB (index_type
))
641 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
643 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
644 TYPE_NFIELDS (result_type
) = 2;
645 TYPE_FIELDS (result_type
) = (struct field
*)
646 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
647 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
648 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
649 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
650 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
651 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
654 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
656 return (result_type
);
659 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
660 Return 1 of type is a range type, 0 if it is discrete (and bounds
661 will fit in LONGEST), or -1 otherwise. */
664 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
666 CHECK_TYPEDEF (type
);
667 switch (TYPE_CODE (type
))
669 case TYPE_CODE_RANGE
:
670 *lowp
= TYPE_LOW_BOUND (type
);
671 *highp
= TYPE_HIGH_BOUND (type
);
674 if (TYPE_NFIELDS (type
) > 0)
676 /* The enums may not be sorted by value, so search all
680 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
681 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
683 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
684 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
685 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
686 *highp
= TYPE_FIELD_BITPOS (type
, i
);
689 /* Set unsigned indicator if warranted. */
692 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
706 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
708 if (!TYPE_UNSIGNED (type
))
710 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
714 /* ... fall through for unsigned ints ... */
717 /* This round-about calculation is to avoid shifting by
718 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
719 if TYPE_LENGTH (type) == sizeof (LONGEST). */
720 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
721 *highp
= (*highp
- 1) | *highp
;
728 /* Create an array type using either a blank type supplied in RESULT_TYPE,
729 or creating a new type, inheriting the objfile from RANGE_TYPE.
731 Elements will be of type ELEMENT_TYPE, the indices will be of type
734 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
735 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
738 create_array_type (struct type
*result_type
, struct type
*element_type
,
739 struct type
*range_type
)
741 LONGEST low_bound
, high_bound
;
743 if (result_type
== NULL
)
745 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
747 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
748 TYPE_TARGET_TYPE (result_type
) = element_type
;
749 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
750 low_bound
= high_bound
= 0;
751 CHECK_TYPEDEF (element_type
);
752 TYPE_LENGTH (result_type
) =
753 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
754 TYPE_NFIELDS (result_type
) = 1;
755 TYPE_FIELDS (result_type
) =
756 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
757 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
758 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
759 TYPE_VPTR_FIELDNO (result_type
) = -1;
761 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
762 if (TYPE_LENGTH (result_type
) == 0)
763 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
765 return (result_type
);
768 /* Create a string type using either a blank type supplied in RESULT_TYPE,
769 or creating a new type. String types are similar enough to array of
770 char types that we can use create_array_type to build the basic type
771 and then bash it into a string type.
773 For fixed length strings, the range type contains 0 as the lower
774 bound and the length of the string minus one as the upper bound.
776 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
777 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
780 create_string_type (struct type
*result_type
, struct type
*range_type
)
782 result_type
= create_array_type (result_type
,
783 *current_language
->string_char_type
,
785 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
786 return (result_type
);
790 create_set_type (struct type
*result_type
, struct type
*domain_type
)
792 LONGEST low_bound
, high_bound
, bit_length
;
793 if (result_type
== NULL
)
795 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
797 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
798 TYPE_NFIELDS (result_type
) = 1;
799 TYPE_FIELDS (result_type
) = (struct field
*)
800 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
801 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
803 if (!TYPE_STUB (domain_type
))
805 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
806 low_bound
= high_bound
= 0;
807 bit_length
= high_bound
- low_bound
+ 1;
808 TYPE_LENGTH (result_type
)
809 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
811 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
814 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
816 return (result_type
);
819 /* Construct and return a type of the form:
820 struct NAME { ELT_TYPE ELT_NAME[N]; }
821 We use these types for SIMD registers. For example, the type of
822 the SSE registers on the late x86-family processors is:
823 struct __builtin_v4sf { float f[4]; }
824 built by the function call:
825 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
826 The type returned is a permanent type, allocated using malloc; it
827 doesn't live in any objfile's obstack. */
829 init_simd_type (char *name
,
830 struct type
*elt_type
,
834 struct type
*simd_type
;
835 struct type
*array_type
;
837 simd_type
= init_composite_type (name
, TYPE_CODE_STRUCT
);
838 array_type
= create_array_type (0, elt_type
,
839 create_range_type (0, builtin_type_int
,
841 append_composite_type_field (simd_type
, elt_name
, array_type
);
846 init_vector_type (struct type
*elt_type
, int n
)
848 struct type
*array_type
;
850 array_type
= create_array_type (0, elt_type
,
851 create_range_type (0, builtin_type_int
,
853 TYPE_FLAGS (array_type
) |= TYPE_FLAG_VECTOR
;
858 build_builtin_type_vec64 (void)
860 /* Construct a type for the 64 bit registers. The type we're
863 union __gdb_builtin_type_vec64
875 t
= init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION
);
876 append_composite_type_field (t
, "uint64", builtin_type_int64
);
877 append_composite_type_field (t
, "v2_float", builtin_type_v2_float
);
878 append_composite_type_field (t
, "v2_int32", builtin_type_v2_int32
);
879 append_composite_type_field (t
, "v4_int16", builtin_type_v4_int16
);
880 append_composite_type_field (t
, "v8_int8", builtin_type_v8_int8
);
882 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
883 TYPE_NAME (t
) = "builtin_type_vec64";
888 build_builtin_type_vec64i (void)
890 /* Construct a type for the 64 bit registers. The type we're
893 union __gdb_builtin_type_vec64i
904 t
= init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION
);
905 append_composite_type_field (t
, "uint64", builtin_type_int64
);
906 append_composite_type_field (t
, "v2_int32", builtin_type_v2_int32
);
907 append_composite_type_field (t
, "v4_int16", builtin_type_v4_int16
);
908 append_composite_type_field (t
, "v8_int8", builtin_type_v8_int8
);
910 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
911 TYPE_NAME (t
) = "builtin_type_vec64i";
916 build_builtin_type_vec128 (void)
918 /* Construct a type for the 128 bit registers. The type we're
921 union __gdb_builtin_type_vec128
933 t
= init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION
);
934 append_composite_type_field (t
, "uint128", builtin_type_int128
);
935 append_composite_type_field (t
, "v4_float", builtin_type_v4_float
);
936 append_composite_type_field (t
, "v4_int32", builtin_type_v4_int32
);
937 append_composite_type_field (t
, "v8_int16", builtin_type_v8_int16
);
938 append_composite_type_field (t
, "v16_int8", builtin_type_v16_int8
);
940 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
941 TYPE_NAME (t
) = "builtin_type_vec128";
946 build_builtin_type_vec128i (void)
948 /* 128-bit Intel SIMD registers */
951 t
= init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION
);
952 append_composite_type_field (t
, "v4_float", builtin_type_v4_float
);
953 append_composite_type_field (t
, "v2_double", builtin_type_v2_double
);
954 append_composite_type_field (t
, "v16_int8", builtin_type_v16_int8
);
955 append_composite_type_field (t
, "v8_int16", builtin_type_v8_int16
);
956 append_composite_type_field (t
, "v4_int32", builtin_type_v4_int32
);
957 append_composite_type_field (t
, "v2_int64", builtin_type_v2_int64
);
958 append_composite_type_field (t
, "uint128", builtin_type_int128
);
960 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
961 TYPE_NAME (t
) = "builtin_type_vec128i";
965 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
966 A MEMBER is a wierd thing -- it amounts to a typed offset into
967 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
968 include the offset (that's the value of the MEMBER itself), but does
969 include the structure type into which it points (for some reason).
971 When "smashing" the type, we preserve the objfile that the
972 old type pointed to, since we aren't changing where the type is actually
976 smash_to_member_type (struct type
*type
, struct type
*domain
,
977 struct type
*to_type
)
979 struct objfile
*objfile
;
981 objfile
= TYPE_OBJFILE (type
);
984 TYPE_OBJFILE (type
) = objfile
;
985 TYPE_TARGET_TYPE (type
) = to_type
;
986 TYPE_DOMAIN_TYPE (type
) = domain
;
987 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
988 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
991 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
992 METHOD just means `function that gets an extra "this" argument'.
994 When "smashing" the type, we preserve the objfile that the
995 old type pointed to, since we aren't changing where the type is actually
999 smash_to_method_type (struct type
*type
, struct type
*domain
,
1000 struct type
*to_type
, struct field
*args
,
1001 int nargs
, int varargs
)
1003 struct objfile
*objfile
;
1005 objfile
= TYPE_OBJFILE (type
);
1008 TYPE_OBJFILE (type
) = objfile
;
1009 TYPE_TARGET_TYPE (type
) = to_type
;
1010 TYPE_DOMAIN_TYPE (type
) = domain
;
1011 TYPE_FIELDS (type
) = args
;
1012 TYPE_NFIELDS (type
) = nargs
;
1014 TYPE_FLAGS (type
) |= TYPE_FLAG_VARARGS
;
1015 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1016 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1019 /* Return a typename for a struct/union/enum type without "struct ",
1020 "union ", or "enum ". If the type has a NULL name, return NULL. */
1023 type_name_no_tag (register const struct type
*type
)
1025 if (TYPE_TAG_NAME (type
) != NULL
)
1026 return TYPE_TAG_NAME (type
);
1028 /* Is there code which expects this to return the name if there is no
1029 tag name? My guess is that this is mainly used for C++ in cases where
1030 the two will always be the same. */
1031 return TYPE_NAME (type
);
1034 /* Lookup a primitive type named NAME.
1035 Return zero if NAME is not a primitive type. */
1038 lookup_primitive_typename (char *name
)
1040 struct type
**const *p
;
1042 for (p
= current_language
->la_builtin_type_vector
; *p
!= NULL
; p
++)
1044 if (strcmp (TYPE_NAME (**p
), name
) == 0)
1052 /* Lookup a typedef or primitive type named NAME,
1053 visible in lexical block BLOCK.
1054 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1057 lookup_typename (char *name
, struct block
*block
, int noerr
)
1062 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1063 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1065 tmp
= lookup_primitive_typename (name
);
1070 else if (!tmp
&& noerr
)
1076 error ("No type named %s.", name
);
1079 return (SYMBOL_TYPE (sym
));
1083 lookup_unsigned_typename (char *name
)
1085 char *uns
= alloca (strlen (name
) + 10);
1087 strcpy (uns
, "unsigned ");
1088 strcpy (uns
+ 9, name
);
1089 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
1093 lookup_signed_typename (char *name
)
1096 char *uns
= alloca (strlen (name
) + 8);
1098 strcpy (uns
, "signed ");
1099 strcpy (uns
+ 7, name
);
1100 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
1101 /* If we don't find "signed FOO" just try again with plain "FOO". */
1104 return lookup_typename (name
, (struct block
*) NULL
, 0);
1107 /* Lookup a structure type named "struct NAME",
1108 visible in lexical block BLOCK. */
1111 lookup_struct (char *name
, struct block
*block
)
1115 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1116 (struct symtab
**) NULL
);
1120 error ("No struct type named %s.", name
);
1122 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1124 error ("This context has class, union or enum %s, not a struct.", name
);
1126 return (SYMBOL_TYPE (sym
));
1129 /* Lookup a union type named "union NAME",
1130 visible in lexical block BLOCK. */
1133 lookup_union (char *name
, struct block
*block
)
1138 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1139 (struct symtab
**) NULL
);
1142 error ("No union type named %s.", name
);
1144 t
= SYMBOL_TYPE (sym
);
1146 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1149 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1150 * a further "declared_type" field to discover it is really a union.
1152 if (HAVE_CPLUS_STRUCT (t
))
1153 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1156 /* If we get here, it's not a union */
1157 error ("This context has class, struct or enum %s, not a union.", name
);
1161 /* Lookup an enum type named "enum NAME",
1162 visible in lexical block BLOCK. */
1165 lookup_enum (char *name
, struct block
*block
)
1169 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1170 (struct symtab
**) NULL
);
1173 error ("No enum type named %s.", name
);
1175 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1177 error ("This context has class, struct or union %s, not an enum.", name
);
1179 return (SYMBOL_TYPE (sym
));
1182 /* Lookup a template type named "template NAME<TYPE>",
1183 visible in lexical block BLOCK. */
1186 lookup_template_type (char *name
, struct type
*type
, struct block
*block
)
1189 char *nam
= (char *) alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1192 strcat (nam
, TYPE_NAME (type
));
1193 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1195 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1199 error ("No template type named %s.", name
);
1201 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1203 error ("This context has class, union or enum %s, not a struct.", name
);
1205 return (SYMBOL_TYPE (sym
));
1208 /* Given a type TYPE, lookup the type of the component of type named NAME.
1210 TYPE can be either a struct or union, or a pointer or reference to a struct or
1211 union. If it is a pointer or reference, its target type is automatically used.
1212 Thus '.' and '->' are interchangable, as specified for the definitions of the
1213 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1215 If NOERR is nonzero, return zero if NAME is not suitably defined.
1216 If NAME is the name of a baseclass type, return that type. */
1219 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1225 CHECK_TYPEDEF (type
);
1226 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1227 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1229 type
= TYPE_TARGET_TYPE (type
);
1232 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
1233 TYPE_CODE (type
) != TYPE_CODE_UNION
)
1235 target_terminal_ours ();
1236 gdb_flush (gdb_stdout
);
1237 fprintf_unfiltered (gdb_stderr
, "Type ");
1238 type_print (type
, "", gdb_stderr
, -1);
1239 error (" is not a structure or union type.");
1243 /* FIXME: This change put in by Michael seems incorrect for the case where
1244 the structure tag name is the same as the member name. I.E. when doing
1245 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1250 typename
= type_name_no_tag (type
);
1251 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1256 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1258 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1260 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1262 return TYPE_FIELD_TYPE (type
, i
);
1266 /* OK, it's not in this class. Recursively check the baseclasses. */
1267 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1271 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
1283 target_terminal_ours ();
1284 gdb_flush (gdb_stdout
);
1285 fprintf_unfiltered (gdb_stderr
, "Type ");
1286 type_print (type
, "", gdb_stderr
, -1);
1287 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1288 fputs_filtered (name
, gdb_stderr
);
1290 return (struct type
*) -1; /* For lint */
1293 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1294 valid. Callers should be aware that in some cases (for example,
1295 the type or one of its baseclasses is a stub type and we are
1296 debugging a .o file), this function will not be able to find the virtual
1297 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1298 will remain NULL. */
1301 fill_in_vptr_fieldno (struct type
*type
)
1303 CHECK_TYPEDEF (type
);
1305 if (TYPE_VPTR_FIELDNO (type
) < 0)
1309 /* We must start at zero in case the first (and only) baseclass is
1310 virtual (and hence we cannot share the table pointer). */
1311 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1313 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1314 fill_in_vptr_fieldno (baseclass
);
1315 if (TYPE_VPTR_FIELDNO (baseclass
) >= 0)
1317 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (baseclass
);
1318 TYPE_VPTR_BASETYPE (type
) = TYPE_VPTR_BASETYPE (baseclass
);
1325 /* Find the method and field indices for the destructor in class type T.
1326 Return 1 if the destructor was found, otherwise, return 0. */
1329 get_destructor_fn_field (struct type
*t
, int *method_indexp
, int *field_indexp
)
1333 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1336 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1338 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1340 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1351 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1353 If this is a stubbed struct (i.e. declared as struct foo *), see if
1354 we can find a full definition in some other file. If so, copy this
1355 definition, so we can use it in future. There used to be a comment (but
1356 not any code) that if we don't find a full definition, we'd set a flag
1357 so we don't spend time in the future checking the same type. That would
1358 be a mistake, though--we might load in more symbols which contain a
1359 full definition for the type.
1361 This used to be coded as a macro, but I don't think it is called
1362 often enough to merit such treatment. */
1365 stub_noname_complaint (void)
1367 complaint (&symfile_complaints
, "stub type has NULL name");
1371 check_typedef (struct type
*type
)
1373 struct type
*orig_type
= type
;
1374 int is_const
, is_volatile
;
1376 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1378 if (!TYPE_TARGET_TYPE (type
))
1383 /* It is dangerous to call lookup_symbol if we are currently
1384 reading a symtab. Infinite recursion is one danger. */
1385 if (currently_reading_symtab
)
1388 name
= type_name_no_tag (type
);
1389 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1390 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1391 as appropriate? (this code was written before TYPE_NAME and
1392 TYPE_TAG_NAME were separate). */
1395 stub_noname_complaint ();
1398 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0,
1399 (struct symtab
**) NULL
);
1401 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1403 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1405 type
= TYPE_TARGET_TYPE (type
);
1408 is_const
= TYPE_CONST (type
);
1409 is_volatile
= TYPE_VOLATILE (type
);
1411 /* If this is a struct/class/union with no fields, then check whether a
1412 full definition exists somewhere else. This is for systems where a
1413 type definition with no fields is issued for such types, instead of
1414 identifying them as stub types in the first place */
1416 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1418 char *name
= type_name_no_tag (type
);
1419 struct type
*newtype
;
1422 stub_noname_complaint ();
1425 newtype
= lookup_transparent_type (name
);
1427 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1429 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1430 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1432 char *name
= type_name_no_tag (type
);
1433 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1434 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1435 as appropriate? (this code was written before TYPE_NAME and
1436 TYPE_TAG_NAME were separate). */
1440 stub_noname_complaint ();
1443 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0, (struct symtab
**) NULL
);
1445 make_cv_type (is_const
, is_volatile
, SYMBOL_TYPE (sym
), &type
);
1448 if (TYPE_TARGET_STUB (type
))
1450 struct type
*range_type
;
1451 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1453 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1456 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1457 && TYPE_NFIELDS (type
) == 1
1458 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1459 == TYPE_CODE_RANGE
))
1461 /* Now recompute the length of the array type, based on its
1462 number of elements and the target type's length. */
1463 TYPE_LENGTH (type
) =
1464 ((TYPE_FIELD_BITPOS (range_type
, 1)
1465 - TYPE_FIELD_BITPOS (range_type
, 0)
1467 * TYPE_LENGTH (target_type
));
1468 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1470 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1472 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1473 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1476 /* Cache TYPE_LENGTH for future use. */
1477 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1481 #if 0 /* OBSOLETE CFront */
1482 // OBSOLETE /* New code added to support parsing of Cfront stabs strings */
1483 // OBSOLETE #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1484 // OBSOLETE #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1486 // OBSOLETE static void
1487 // OBSOLETE add_name (struct extra *pextras, char *n)
1489 // OBSOLETE int nlen;
1491 // OBSOLETE if ((nlen = (n ? strlen (n) : 0)) == 0)
1493 // OBSOLETE sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1494 // OBSOLETE pextras->len = strlen (pextras->str);
1497 // OBSOLETE static void
1498 // OBSOLETE add_mangled_type (struct extra *pextras, struct type *t)
1500 // OBSOLETE enum type_code tcode;
1501 // OBSOLETE int tlen, tflags;
1502 // OBSOLETE char *tname;
1504 // OBSOLETE tcode = TYPE_CODE (t);
1505 // OBSOLETE tlen = TYPE_LENGTH (t);
1506 // OBSOLETE tflags = TYPE_FLAGS (t);
1507 // OBSOLETE tname = TYPE_NAME (t);
1508 // OBSOLETE /* args of "..." seem to get mangled as "e" */
1510 // OBSOLETE switch (tcode)
1512 // OBSOLETE case TYPE_CODE_INT:
1513 // OBSOLETE if (tflags == 1)
1514 // OBSOLETE ADD_EXTRA ('U');
1515 // OBSOLETE switch (tlen)
1518 // OBSOLETE ADD_EXTRA ('c');
1521 // OBSOLETE ADD_EXTRA ('s');
1525 // OBSOLETE char *pname;
1526 // OBSOLETE if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1528 // OBSOLETE ADD_EXTRA ('l');
1532 // OBSOLETE ADD_EXTRA ('i');
1536 // OBSOLETE default:
1538 // OBSOLETE complaint (&symfile_complaints, "Bad int type code length x%x",
1543 // OBSOLETE case TYPE_CODE_FLT:
1544 // OBSOLETE switch (tlen)
1547 // OBSOLETE ADD_EXTRA ('f');
1550 // OBSOLETE ADD_EXTRA ('d');
1552 // OBSOLETE case 16:
1553 // OBSOLETE ADD_EXTRA ('r');
1555 // OBSOLETE default:
1557 // OBSOLETE complaint (&symfile_complaints, "Bad float type code length x%x",
1562 // OBSOLETE case TYPE_CODE_REF:
1563 // OBSOLETE ADD_EXTRA ('R');
1564 // OBSOLETE /* followed by what it's a ref to */
1566 // OBSOLETE case TYPE_CODE_PTR:
1567 // OBSOLETE ADD_EXTRA ('P');
1568 // OBSOLETE /* followed by what it's a ptr to */
1570 // OBSOLETE case TYPE_CODE_TYPEDEF:
1572 // OBSOLETE complaint (&symfile_complaints,
1573 // OBSOLETE "Typedefs in overloaded functions not yet supported");
1575 // OBSOLETE /* followed by type bytes & name */
1577 // OBSOLETE case TYPE_CODE_FUNC:
1578 // OBSOLETE ADD_EXTRA ('F');
1579 // OBSOLETE /* followed by func's arg '_' & ret types */
1581 // OBSOLETE case TYPE_CODE_VOID:
1582 // OBSOLETE ADD_EXTRA ('v');
1584 // OBSOLETE case TYPE_CODE_METHOD:
1585 // OBSOLETE ADD_EXTRA ('M');
1586 // OBSOLETE /* followed by name of class and func's arg '_' & ret types */
1587 // OBSOLETE add_name (pextras, tname);
1588 // OBSOLETE ADD_EXTRA ('F'); /* then mangle function */
1590 // OBSOLETE case TYPE_CODE_STRUCT: /* C struct */
1591 // OBSOLETE case TYPE_CODE_UNION: /* C union */
1592 // OBSOLETE case TYPE_CODE_ENUM: /* Enumeration type */
1593 // OBSOLETE /* followed by name of type */
1594 // OBSOLETE add_name (pextras, tname);
1597 // OBSOLETE /* errors possible types/not supported */
1598 // OBSOLETE case TYPE_CODE_CHAR:
1599 // OBSOLETE case TYPE_CODE_ARRAY: /* Array type */
1600 // OBSOLETE case TYPE_CODE_MEMBER: /* Member type */
1601 // OBSOLETE case TYPE_CODE_BOOL:
1602 // OBSOLETE case TYPE_CODE_COMPLEX: /* Complex float */
1603 // OBSOLETE case TYPE_CODE_UNDEF:
1604 // OBSOLETE case TYPE_CODE_SET: /* Pascal sets */
1605 // OBSOLETE case TYPE_CODE_RANGE:
1606 // OBSOLETE case TYPE_CODE_STRING:
1607 // OBSOLETE case TYPE_CODE_BITSTRING:
1608 // OBSOLETE case TYPE_CODE_ERROR:
1609 // OBSOLETE default:
1611 // OBSOLETE complaint (&symfile_complaints, "Unknown type code x%x", tcode);
1614 // OBSOLETE if (TYPE_TARGET_TYPE (t))
1615 // OBSOLETE add_mangled_type (pextras, TYPE_TARGET_TYPE (t));
1619 // OBSOLETE cfront_mangle_name (struct type *type, int i, int j)
1621 // OBSOLETE struct fn_field *f;
1622 // OBSOLETE char *mangled_name = gdb_mangle_name (type, i, j);
1624 // OBSOLETE f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1626 // OBSOLETE /* kludge to support cfront methods - gdb expects to find "F" for
1627 // OBSOLETE ARM_mangled names, so when we mangle, we have to add it here */
1628 // OBSOLETE if (ARM_DEMANGLING)
1631 // OBSOLETE char *arm_mangled_name;
1632 // OBSOLETE struct fn_field *method = &f[j];
1633 // OBSOLETE char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1634 // OBSOLETE char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1635 // OBSOLETE char *newname = type_name_no_tag (type);
1637 // OBSOLETE struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1638 // OBSOLETE int nargs = TYPE_NFIELDS (ftype); /* number of args */
1639 // OBSOLETE struct extra extras, *pextras = &extras;
1640 // OBSOLETE INIT_EXTRA
1642 // OBSOLETE if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1643 // OBSOLETE ADD_EXTRA ('S')
1644 // OBSOLETE ADD_EXTRA ('F')
1645 // OBSOLETE /* add args here! */
1646 // OBSOLETE if (nargs <= 1) /* no args besides this */
1647 // OBSOLETE ADD_EXTRA ('v')
1650 // OBSOLETE for (k = 1; k < nargs; k++)
1652 // OBSOLETE struct type *t;
1653 // OBSOLETE t = TYPE_FIELD_TYPE (ftype, k);
1654 // OBSOLETE add_mangled_type (pextras, t);
1657 // OBSOLETE ADD_EXTRA ('\0')
1658 // OBSOLETE printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1659 // OBSOLETE xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str);
1660 // OBSOLETE xfree (mangled_name);
1661 // OBSOLETE mangled_name = arm_mangled_name;
1665 // OBSOLETE #undef ADD_EXTRA
1666 // OBSOLETE /* End of new code added to support parsing of Cfront stabs strings */
1667 #endif /* OBSOLETE CFront */
1669 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1670 silently return builtin_type_void. */
1672 static struct type
*
1673 safe_parse_type (char *p
, int length
)
1675 struct ui_file
*saved_gdb_stderr
;
1678 /* Suppress error messages. */
1679 saved_gdb_stderr
= gdb_stderr
;
1680 gdb_stderr
= ui_file_new ();
1682 /* Call parse_and_eval_type() without fear of longjmp()s. */
1683 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1684 type
= builtin_type_void
;
1686 /* Stop suppressing error messages. */
1687 ui_file_delete (gdb_stderr
);
1688 gdb_stderr
= saved_gdb_stderr
;
1693 /* Ugly hack to convert method stubs into method types.
1695 He ain't kiddin'. This demangles the name of the method into a string
1696 including argument types, parses out each argument type, generates
1697 a string casting a zero to that type, evaluates the string, and stuffs
1698 the resulting type into an argtype vector!!! Then it knows the type
1699 of the whole function (including argument types for overloading),
1700 which info used to be in the stab's but was removed to hack back
1701 the space required for them. */
1704 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1707 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1708 char *demangled_name
= cplus_demangle (mangled_name
,
1709 DMGL_PARAMS
| DMGL_ANSI
);
1710 char *argtypetext
, *p
;
1711 int depth
= 0, argcount
= 1;
1712 struct field
*argtypes
;
1715 /* Make sure we got back a function string that we can use. */
1717 p
= strchr (demangled_name
, '(');
1721 if (demangled_name
== NULL
|| p
== NULL
)
1722 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
1724 /* Now, read in the parameters that define this type. */
1729 if (*p
== '(' || *p
== '<')
1733 else if (*p
== ')' || *p
== '>')
1737 else if (*p
== ',' && depth
== 0)
1745 /* If we read one argument and it was ``void'', don't count it. */
1746 if (strncmp (argtypetext
, "(void)", 6) == 0)
1749 /* We need one extra slot, for the THIS pointer. */
1751 argtypes
= (struct field
*)
1752 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1755 /* Add THIS pointer for non-static methods. */
1756 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1757 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1761 argtypes
[0].type
= lookup_pointer_type (type
);
1765 if (*p
!= ')') /* () means no args, skip while */
1770 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1772 /* Avoid parsing of ellipsis, they will be handled below.
1773 Also avoid ``void'' as above. */
1774 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1775 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1777 argtypes
[argcount
].type
=
1778 safe_parse_type (argtypetext
, p
- argtypetext
);
1781 argtypetext
= p
+ 1;
1784 if (*p
== '(' || *p
== '<')
1788 else if (*p
== ')' || *p
== '>')
1797 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1799 /* Now update the old "stub" type into a real type. */
1800 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1801 TYPE_DOMAIN_TYPE (mtype
) = type
;
1802 TYPE_FIELDS (mtype
) = argtypes
;
1803 TYPE_NFIELDS (mtype
) = argcount
;
1804 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1805 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1807 TYPE_FLAGS (mtype
) |= TYPE_FLAG_VARARGS
;
1809 xfree (demangled_name
);
1812 /* This is the external interface to check_stub_method, above. This function
1813 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1814 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1815 and TYPE_FN_FIELDLIST_NAME will be correct.
1817 This function unfortunately can not die until stabs do. */
1820 check_stub_method_group (struct type
*type
, int method_id
)
1822 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1823 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1824 int j
, found_stub
= 0;
1826 for (j
= 0; j
< len
; j
++)
1827 if (TYPE_FN_FIELD_STUB (f
, j
))
1830 check_stub_method (type
, method_id
, j
);
1833 /* GNU v3 methods with incorrect names were corrected when we read in
1834 type information, because it was cheaper to do it then. The only GNU v2
1835 methods with incorrect method names are operators and destructors;
1836 destructors were also corrected when we read in type information.
1838 Therefore the only thing we need to handle here are v2 operator
1840 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1843 char dem_opname
[256];
1845 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1846 dem_opname
, DMGL_ANSI
);
1848 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1851 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1855 const struct cplus_struct_type cplus_struct_default
;
1858 allocate_cplus_struct_type (struct type
*type
)
1860 if (!HAVE_CPLUS_STRUCT (type
))
1862 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1863 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1864 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1868 /* Helper function to initialize the standard scalar types.
1870 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1871 of the string pointed to by name in the type_obstack for that objfile,
1872 and initialize the type name to that copy. There are places (mipsread.c
1873 in particular, where init_type is called with a NULL value for NAME). */
1876 init_type (enum type_code code
, int length
, int flags
, char *name
,
1877 struct objfile
*objfile
)
1881 type
= alloc_type (objfile
);
1882 TYPE_CODE (type
) = code
;
1883 TYPE_LENGTH (type
) = length
;
1884 TYPE_FLAGS (type
) |= flags
;
1885 if ((name
!= NULL
) && (objfile
!= NULL
))
1888 obsavestring (name
, strlen (name
), &objfile
->type_obstack
);
1892 TYPE_NAME (type
) = name
;
1897 if (name
&& strcmp (name
, "char") == 0)
1898 TYPE_FLAGS (type
) |= TYPE_FLAG_NOSIGN
;
1900 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
1901 || code
== TYPE_CODE_NAMESPACE
)
1903 INIT_CPLUS_SPECIFIC (type
);
1908 /* Helper function. Create an empty composite type. */
1911 init_composite_type (char *name
, enum type_code code
)
1914 gdb_assert (code
== TYPE_CODE_STRUCT
1915 || code
== TYPE_CODE_UNION
);
1916 t
= init_type (code
, 0, 0, NULL
, NULL
);
1917 TYPE_TAG_NAME (t
) = name
;
1921 /* Helper function. Append a field to a composite type. */
1924 append_composite_type_field (struct type
*t
, char *name
, struct type
*field
)
1927 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
1928 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
1929 sizeof (struct field
) * TYPE_NFIELDS (t
));
1930 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
1931 memset (f
, 0, sizeof f
[0]);
1932 FIELD_TYPE (f
[0]) = field
;
1933 FIELD_NAME (f
[0]) = name
;
1934 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1936 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
1937 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
1939 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
1941 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
1942 if (TYPE_NFIELDS (t
) > 1)
1944 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
1945 + TYPE_LENGTH (field
) * TARGET_CHAR_BIT
);
1950 /* Look up a fundamental type for the specified objfile.
1951 May need to construct such a type if this is the first use.
1953 Some object file formats (ELF, COFF, etc) do not define fundamental
1954 types such as "int" or "double". Others (stabs for example), do
1955 define fundamental types.
1957 For the formats which don't provide fundamental types, gdb can create
1958 such types, using defaults reasonable for the current language and
1959 the current target machine.
1961 NOTE: This routine is obsolescent. Each debugging format reader
1962 should manage it's own fundamental types, either creating them from
1963 suitable defaults or reading them from the debugging information,
1964 whichever is appropriate. The DWARF reader has already been
1965 fixed to do this. Once the other readers are fixed, this routine
1966 will go away. Also note that fundamental types should be managed
1967 on a compilation unit basis in a multi-language environment, not
1968 on a linkage unit basis as is done here. */
1972 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1974 struct type
**typep
;
1977 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1979 error ("internal error - invalid fundamental type id %d", typeid);
1982 /* If this is the first time we need a fundamental type for this objfile
1983 then we need to initialize the vector of type pointers. */
1985 if (objfile
->fundamental_types
== NULL
)
1987 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1988 objfile
->fundamental_types
= (struct type
**)
1989 obstack_alloc (&objfile
->type_obstack
, nbytes
);
1990 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1991 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1994 /* Look for this particular type in the fundamental type vector. If one is
1995 not found, create and install one appropriate for the current language. */
1997 typep
= objfile
->fundamental_types
+ typeid;
2000 *typep
= create_fundamental_type (objfile
, typeid);
2007 can_dereference (struct type
*t
)
2009 /* FIXME: Should we return true for references as well as pointers? */
2013 && TYPE_CODE (t
) == TYPE_CODE_PTR
2014 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
2018 is_integral_type (struct type
*t
)
2023 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
2024 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
2025 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
2026 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
2027 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
2030 /* Check whether BASE is an ancestor or base class or DCLASS
2031 Return 1 if so, and 0 if not.
2032 Note: callers may want to check for identity of the types before
2033 calling this function -- identical types are considered to satisfy
2034 the ancestor relationship even if they're identical */
2037 is_ancestor (struct type
*base
, struct type
*dclass
)
2041 CHECK_TYPEDEF (base
);
2042 CHECK_TYPEDEF (dclass
);
2046 if (TYPE_NAME (base
) && TYPE_NAME (dclass
) &&
2047 !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
2050 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2051 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
2059 /* See whether DCLASS has a virtual table. This routine is aimed at
2060 the HP/Taligent ANSI C++ runtime model, and may not work with other
2061 runtime models. Return 1 => Yes, 0 => No. */
2064 has_vtable (struct type
*dclass
)
2066 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
2067 has virtual functions or virtual bases. */
2071 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
2074 /* First check for the presence of virtual bases */
2075 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
2076 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2077 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
2080 /* Next check for virtual functions */
2081 if (TYPE_FN_FIELDLISTS (dclass
))
2082 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
2083 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
2086 /* Recurse on non-virtual bases to see if any of them needs a vtable */
2087 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
2088 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2089 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
2090 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
2093 /* Well, maybe we don't need a virtual table */
2097 /* Return a pointer to the "primary base class" of DCLASS.
2099 A NULL return indicates that DCLASS has no primary base, or that it
2100 couldn't be found (insufficient information).
2102 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2103 and may not work with other runtime models. */
2106 primary_base_class (struct type
*dclass
)
2108 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
2109 is the first directly inherited, non-virtual base class that
2110 requires a virtual table */
2114 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
2117 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2118 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
2119 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
2120 return TYPE_FIELD_TYPE (dclass
, i
);
2125 /* Global manipulated by virtual_base_list[_aux]() */
2127 static struct vbase
*current_vbase_list
= NULL
;
2129 /* Return a pointer to a null-terminated list of struct vbase
2130 items. The vbasetype pointer of each item in the list points to the
2131 type information for a virtual base of the argument DCLASS.
2133 Helper function for virtual_base_list().
2134 Note: the list goes backward, right-to-left. virtual_base_list()
2135 copies the items out in reverse order. */
2138 virtual_base_list_aux (struct type
*dclass
)
2140 struct vbase
*tmp_vbase
;
2143 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
2146 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2148 /* Recurse on this ancestor, first */
2149 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
2151 /* If this current base is itself virtual, add it to the list */
2152 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
2154 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
2156 /* Check if base already recorded */
2157 tmp_vbase
= current_vbase_list
;
2160 if (tmp_vbase
->vbasetype
== basetype
)
2161 break; /* found it */
2162 tmp_vbase
= tmp_vbase
->next
;
2165 if (!tmp_vbase
) /* normal exit from loop */
2167 /* Allocate new item for this virtual base */
2168 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
2170 /* Stick it on at the end of the list */
2171 tmp_vbase
->vbasetype
= basetype
;
2172 tmp_vbase
->next
= current_vbase_list
;
2173 current_vbase_list
= tmp_vbase
;
2176 } /* for loop over bases */
2180 /* Compute the list of virtual bases in the right order. Virtual
2181 bases are laid out in the object's memory area in order of their
2182 occurrence in a depth-first, left-to-right search through the
2185 Argument DCLASS is the type whose virtual bases are required.
2186 Return value is the address of a null-terminated array of pointers
2187 to struct type items.
2189 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2190 and may not work with other runtime models.
2192 This routine merely hands off the argument to virtual_base_list_aux()
2193 and then copies the result into an array to save space. */
2196 virtual_base_list (struct type
*dclass
)
2198 struct vbase
*tmp_vbase
;
2199 struct vbase
*tmp_vbase_2
;
2202 struct type
**vbase_array
;
2204 current_vbase_list
= NULL
;
2205 virtual_base_list_aux (dclass
);
2207 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2212 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
2214 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
2215 vbase_array
[i
] = tmp_vbase
->vbasetype
;
2217 /* Get rid of constructed chain */
2218 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
2221 tmp_vbase
= tmp_vbase
->next
;
2222 xfree (tmp_vbase_2
);
2223 tmp_vbase_2
= tmp_vbase
;
2226 vbase_array
[count
] = NULL
;
2230 /* Return the length of the virtual base list of the type DCLASS. */
2233 virtual_base_list_length (struct type
*dclass
)
2236 struct vbase
*tmp_vbase
;
2238 current_vbase_list
= NULL
;
2239 virtual_base_list_aux (dclass
);
2241 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2246 /* Return the number of elements of the virtual base list of the type
2247 DCLASS, ignoring those appearing in the primary base (and its
2248 primary base, recursively). */
2251 virtual_base_list_length_skip_primaries (struct type
*dclass
)
2254 struct vbase
*tmp_vbase
;
2255 struct type
*primary
;
2257 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2260 return virtual_base_list_length (dclass
);
2262 current_vbase_list
= NULL
;
2263 virtual_base_list_aux (dclass
);
2265 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
2267 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
2275 /* Return the index (position) of type BASE, which is a virtual base
2276 class of DCLASS, in the latter's virtual base list. A return of -1
2277 indicates "not found" or a problem. */
2280 virtual_base_index (struct type
*base
, struct type
*dclass
)
2285 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2286 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2290 vbase
= virtual_base_list (dclass
)[0];
2295 vbase
= virtual_base_list (dclass
)[++i
];
2298 return vbase
? i
: -1;
2303 /* Return the index (position) of type BASE, which is a virtual base
2304 class of DCLASS, in the latter's virtual base list. Skip over all
2305 bases that may appear in the virtual base list of the primary base
2306 class of DCLASS (recursively). A return of -1 indicates "not
2307 found" or a problem. */
2310 virtual_base_index_skip_primaries (struct type
*base
, struct type
*dclass
)
2314 struct type
*primary
;
2316 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2317 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2320 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2324 vbase
= virtual_base_list (dclass
)[0];
2327 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
2331 vbase
= virtual_base_list (dclass
)[++i
];
2334 return vbase
? j
: -1;
2337 /* Return position of a derived class DCLASS in the list of
2338 * primary bases starting with the remotest ancestor.
2339 * Position returned is 0-based. */
2342 class_index_in_primary_list (struct type
*dclass
)
2344 struct type
*pbc
; /* primary base class */
2346 /* Simply recurse on primary base */
2347 pbc
= TYPE_PRIMARY_BASE (dclass
);
2349 return 1 + class_index_in_primary_list (pbc
);
2354 /* Return a count of the number of virtual functions a type has.
2355 * This includes all the virtual functions it inherits from its
2359 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2360 * functions only once (latest redefinition)
2364 count_virtual_fns (struct type
*dclass
)
2366 int fn
, oi
; /* function and overloaded instance indices */
2367 int vfuncs
; /* count to return */
2369 /* recurse on bases that can share virtual table */
2370 struct type
*pbc
= primary_base_class (dclass
);
2372 vfuncs
= count_virtual_fns (pbc
);
2376 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2377 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2378 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2386 /* Functions for overload resolution begin here */
2388 /* Compare two badness vectors A and B and return the result.
2389 * 0 => A and B are identical
2390 * 1 => A and B are incomparable
2391 * 2 => A is better than B
2392 * 3 => A is worse than B */
2395 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2399 short found_pos
= 0; /* any positives in c? */
2400 short found_neg
= 0; /* any negatives in c? */
2402 /* differing lengths => incomparable */
2403 if (a
->length
!= b
->length
)
2406 /* Subtract b from a */
2407 for (i
= 0; i
< a
->length
; i
++)
2409 tmp
= a
->rank
[i
] - b
->rank
[i
];
2419 return 1; /* incomparable */
2421 return 3; /* A > B */
2427 return 2; /* A < B */
2429 return 0; /* A == B */
2433 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2434 * to the types of an argument list (ARGS, length NARGS).
2435 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2437 struct badness_vector
*
2438 rank_function (struct type
**parms
, int nparms
, struct type
**args
, int nargs
)
2441 struct badness_vector
*bv
;
2442 int min_len
= nparms
< nargs
? nparms
: nargs
;
2444 bv
= xmalloc (sizeof (struct badness_vector
));
2445 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2446 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2448 /* First compare the lengths of the supplied lists.
2449 * If there is a mismatch, set it to a high value. */
2451 /* pai/1997-06-03 FIXME: when we have debug info about default
2452 * arguments and ellipsis parameter lists, we should consider those
2453 * and rank the length-match more finely. */
2455 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2457 /* Now rank all the parameters of the candidate function */
2458 for (i
= 1; i
<= min_len
; i
++)
2459 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2461 /* If more arguments than parameters, add dummy entries */
2462 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2463 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2468 /* Compare the names of two integer types, assuming that any sign
2469 qualifiers have been checked already. We do it this way because
2470 there may be an "int" in the name of one of the types. */
2473 integer_types_same_name_p (const char *first
, const char *second
)
2475 int first_p
, second_p
;
2477 /* If both are shorts, return 1; if neither is a short, keep checking. */
2478 first_p
= (strstr (first
, "short") != NULL
);
2479 second_p
= (strstr (second
, "short") != NULL
);
2480 if (first_p
&& second_p
)
2482 if (first_p
|| second_p
)
2485 /* Likewise for long. */
2486 first_p
= (strstr (first
, "long") != NULL
);
2487 second_p
= (strstr (second
, "long") != NULL
);
2488 if (first_p
&& second_p
)
2490 if (first_p
|| second_p
)
2493 /* Likewise for char. */
2494 first_p
= (strstr (first
, "char") != NULL
);
2495 second_p
= (strstr (second
, "char") != NULL
);
2496 if (first_p
&& second_p
)
2498 if (first_p
|| second_p
)
2501 /* They must both be ints. */
2505 /* Compare one type (PARM) for compatibility with another (ARG).
2506 * PARM is intended to be the parameter type of a function; and
2507 * ARG is the supplied argument's type. This function tests if
2508 * the latter can be converted to the former.
2510 * Return 0 if they are identical types;
2511 * Otherwise, return an integer which corresponds to how compatible
2512 * PARM is to ARG. The higher the return value, the worse the match.
2513 * Generally the "bad" conversions are all uniformly assigned a 100 */
2516 rank_one_type (struct type
*parm
, struct type
*arg
)
2518 /* Identical type pointers */
2519 /* However, this still doesn't catch all cases of same type for arg
2520 * and param. The reason is that builtin types are different from
2521 * the same ones constructed from the object. */
2525 /* Resolve typedefs */
2526 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2527 parm
= check_typedef (parm
);
2528 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2529 arg
= check_typedef (arg
);
2532 Well, damnit, if the names are exactly the same,
2533 i'll say they are exactly the same. This happens when we generate
2534 method stubs. The types won't point to the same address, but they
2535 really are the same.
2538 if (TYPE_NAME (parm
) && TYPE_NAME (arg
) &&
2539 !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2542 /* Check if identical after resolving typedefs */
2546 /* See through references, since we can almost make non-references
2548 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2549 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2550 + REFERENCE_CONVERSION_BADNESS
);
2551 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2552 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2553 + REFERENCE_CONVERSION_BADNESS
);
2555 /* Debugging only. */
2556 fprintf_filtered (gdb_stderr
,"------ Arg is %s [%d], parm is %s [%d]\n",
2557 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2559 /* x -> y means arg of type x being supplied for parameter of type y */
2561 switch (TYPE_CODE (parm
))
2564 switch (TYPE_CODE (arg
))
2567 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2568 return VOID_PTR_CONVERSION_BADNESS
;
2570 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2571 case TYPE_CODE_ARRAY
:
2572 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2573 case TYPE_CODE_FUNC
:
2574 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2576 case TYPE_CODE_ENUM
:
2577 case TYPE_CODE_CHAR
:
2578 case TYPE_CODE_RANGE
:
2579 case TYPE_CODE_BOOL
:
2580 return POINTER_CONVERSION_BADNESS
;
2582 return INCOMPATIBLE_TYPE_BADNESS
;
2584 case TYPE_CODE_ARRAY
:
2585 switch (TYPE_CODE (arg
))
2588 case TYPE_CODE_ARRAY
:
2589 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2591 return INCOMPATIBLE_TYPE_BADNESS
;
2593 case TYPE_CODE_FUNC
:
2594 switch (TYPE_CODE (arg
))
2596 case TYPE_CODE_PTR
: /* funcptr -> func */
2597 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2599 return INCOMPATIBLE_TYPE_BADNESS
;
2602 switch (TYPE_CODE (arg
))
2605 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2607 /* Deal with signed, unsigned, and plain chars and
2608 signed and unsigned ints */
2609 if (TYPE_NOSIGN (parm
))
2611 /* This case only for character types */
2612 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2615 return INTEGER_CONVERSION_BADNESS
; /* signed/unsigned char -> plain char */
2617 else if (TYPE_UNSIGNED (parm
))
2619 if (TYPE_UNSIGNED (arg
))
2621 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2622 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2624 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2625 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2626 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2628 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2632 if (integer_types_same_name_p (TYPE_NAME (arg
), "long")
2633 && integer_types_same_name_p (TYPE_NAME (parm
), "int"))
2634 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2636 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2639 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2641 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2643 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2644 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2645 return INTEGER_PROMOTION_BADNESS
;
2647 return INTEGER_CONVERSION_BADNESS
;
2650 return INTEGER_CONVERSION_BADNESS
;
2652 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2653 return INTEGER_PROMOTION_BADNESS
;
2655 return INTEGER_CONVERSION_BADNESS
;
2656 case TYPE_CODE_ENUM
:
2657 case TYPE_CODE_CHAR
:
2658 case TYPE_CODE_RANGE
:
2659 case TYPE_CODE_BOOL
:
2660 return INTEGER_PROMOTION_BADNESS
;
2662 return INT_FLOAT_CONVERSION_BADNESS
;
2664 return NS_POINTER_CONVERSION_BADNESS
;
2666 return INCOMPATIBLE_TYPE_BADNESS
;
2669 case TYPE_CODE_ENUM
:
2670 switch (TYPE_CODE (arg
))
2673 case TYPE_CODE_CHAR
:
2674 case TYPE_CODE_RANGE
:
2675 case TYPE_CODE_BOOL
:
2676 case TYPE_CODE_ENUM
:
2677 return INTEGER_CONVERSION_BADNESS
;
2679 return INT_FLOAT_CONVERSION_BADNESS
;
2681 return INCOMPATIBLE_TYPE_BADNESS
;
2684 case TYPE_CODE_CHAR
:
2685 switch (TYPE_CODE (arg
))
2687 case TYPE_CODE_RANGE
:
2688 case TYPE_CODE_BOOL
:
2689 case TYPE_CODE_ENUM
:
2690 return INTEGER_CONVERSION_BADNESS
;
2692 return INT_FLOAT_CONVERSION_BADNESS
;
2694 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2695 return INTEGER_CONVERSION_BADNESS
;
2696 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2697 return INTEGER_PROMOTION_BADNESS
;
2698 /* >>> !! else fall through !! <<< */
2699 case TYPE_CODE_CHAR
:
2700 /* Deal with signed, unsigned, and plain chars for C++
2701 and with int cases falling through from previous case */
2702 if (TYPE_NOSIGN (parm
))
2704 if (TYPE_NOSIGN (arg
))
2707 return INTEGER_CONVERSION_BADNESS
;
2709 else if (TYPE_UNSIGNED (parm
))
2711 if (TYPE_UNSIGNED (arg
))
2714 return INTEGER_PROMOTION_BADNESS
;
2716 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2719 return INTEGER_CONVERSION_BADNESS
;
2721 return INCOMPATIBLE_TYPE_BADNESS
;
2724 case TYPE_CODE_RANGE
:
2725 switch (TYPE_CODE (arg
))
2728 case TYPE_CODE_CHAR
:
2729 case TYPE_CODE_RANGE
:
2730 case TYPE_CODE_BOOL
:
2731 case TYPE_CODE_ENUM
:
2732 return INTEGER_CONVERSION_BADNESS
;
2734 return INT_FLOAT_CONVERSION_BADNESS
;
2736 return INCOMPATIBLE_TYPE_BADNESS
;
2739 case TYPE_CODE_BOOL
:
2740 switch (TYPE_CODE (arg
))
2743 case TYPE_CODE_CHAR
:
2744 case TYPE_CODE_RANGE
:
2745 case TYPE_CODE_ENUM
:
2748 return BOOLEAN_CONVERSION_BADNESS
;
2749 case TYPE_CODE_BOOL
:
2752 return INCOMPATIBLE_TYPE_BADNESS
;
2756 switch (TYPE_CODE (arg
))
2759 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2760 return FLOAT_PROMOTION_BADNESS
;
2761 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2764 return FLOAT_CONVERSION_BADNESS
;
2766 case TYPE_CODE_BOOL
:
2767 case TYPE_CODE_ENUM
:
2768 case TYPE_CODE_RANGE
:
2769 case TYPE_CODE_CHAR
:
2770 return INT_FLOAT_CONVERSION_BADNESS
;
2772 return INCOMPATIBLE_TYPE_BADNESS
;
2775 case TYPE_CODE_COMPLEX
:
2776 switch (TYPE_CODE (arg
))
2777 { /* Strictly not needed for C++, but... */
2779 return FLOAT_PROMOTION_BADNESS
;
2780 case TYPE_CODE_COMPLEX
:
2783 return INCOMPATIBLE_TYPE_BADNESS
;
2786 case TYPE_CODE_STRUCT
:
2787 /* currently same as TYPE_CODE_CLASS */
2788 switch (TYPE_CODE (arg
))
2790 case TYPE_CODE_STRUCT
:
2791 /* Check for derivation */
2792 if (is_ancestor (parm
, arg
))
2793 return BASE_CONVERSION_BADNESS
;
2794 /* else fall through */
2796 return INCOMPATIBLE_TYPE_BADNESS
;
2799 case TYPE_CODE_UNION
:
2800 switch (TYPE_CODE (arg
))
2802 case TYPE_CODE_UNION
:
2804 return INCOMPATIBLE_TYPE_BADNESS
;
2807 case TYPE_CODE_MEMBER
:
2808 switch (TYPE_CODE (arg
))
2811 return INCOMPATIBLE_TYPE_BADNESS
;
2814 case TYPE_CODE_METHOD
:
2815 switch (TYPE_CODE (arg
))
2819 return INCOMPATIBLE_TYPE_BADNESS
;
2823 switch (TYPE_CODE (arg
))
2827 return INCOMPATIBLE_TYPE_BADNESS
;
2832 switch (TYPE_CODE (arg
))
2836 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2838 return INCOMPATIBLE_TYPE_BADNESS
;
2841 case TYPE_CODE_VOID
:
2843 return INCOMPATIBLE_TYPE_BADNESS
;
2844 } /* switch (TYPE_CODE (arg)) */
2848 /* End of functions for overload resolution */
2851 print_bit_vector (B_TYPE
*bits
, int nbits
)
2855 for (bitno
= 0; bitno
< nbits
; bitno
++)
2857 if ((bitno
% 8) == 0)
2859 puts_filtered (" ");
2861 if (B_TST (bits
, bitno
))
2863 printf_filtered ("1");
2867 printf_filtered ("0");
2872 /* Note the first arg should be the "this" pointer, we may not want to
2873 include it since we may get into a infinitely recursive situation. */
2876 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2882 for (i
= 0; i
< nargs
; i
++)
2883 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2888 dump_fn_fieldlists (struct type
*type
, int spaces
)
2894 printfi_filtered (spaces
, "fn_fieldlists ");
2895 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2896 printf_filtered ("\n");
2897 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2899 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2900 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2902 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2903 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2905 printf_filtered (") length %d\n",
2906 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2907 for (overload_idx
= 0;
2908 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2911 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2913 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2914 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2916 printf_filtered (")\n");
2917 printfi_filtered (spaces
+ 8, "type ");
2918 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2919 printf_filtered ("\n");
2921 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2924 printfi_filtered (spaces
+ 8, "args ");
2925 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2926 printf_filtered ("\n");
2928 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2929 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
, overload_idx
)),
2931 printfi_filtered (spaces
+ 8, "fcontext ");
2932 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2934 printf_filtered ("\n");
2936 printfi_filtered (spaces
+ 8, "is_const %d\n",
2937 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2938 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2939 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2940 printfi_filtered (spaces
+ 8, "is_private %d\n",
2941 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2942 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2943 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2944 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2945 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2946 printfi_filtered (spaces
+ 8, "voffset %u\n",
2947 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2953 print_cplus_stuff (struct type
*type
, int spaces
)
2955 printfi_filtered (spaces
, "n_baseclasses %d\n",
2956 TYPE_N_BASECLASSES (type
));
2957 printfi_filtered (spaces
, "nfn_fields %d\n",
2958 TYPE_NFN_FIELDS (type
));
2959 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2960 TYPE_NFN_FIELDS_TOTAL (type
));
2961 if (TYPE_N_BASECLASSES (type
) > 0)
2963 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2964 TYPE_N_BASECLASSES (type
));
2965 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2966 printf_filtered (")");
2968 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2969 TYPE_N_BASECLASSES (type
));
2970 puts_filtered ("\n");
2972 if (TYPE_NFIELDS (type
) > 0)
2974 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2976 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2977 TYPE_NFIELDS (type
));
2978 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2979 printf_filtered (")");
2980 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2981 TYPE_NFIELDS (type
));
2982 puts_filtered ("\n");
2984 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2986 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2987 TYPE_NFIELDS (type
));
2988 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2989 printf_filtered (")");
2990 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2991 TYPE_NFIELDS (type
));
2992 puts_filtered ("\n");
2995 if (TYPE_NFN_FIELDS (type
) > 0)
2997 dump_fn_fieldlists (type
, spaces
);
3002 print_bound_type (int bt
)
3006 case BOUND_CANNOT_BE_DETERMINED
:
3007 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
3009 case BOUND_BY_REF_ON_STACK
:
3010 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
3012 case BOUND_BY_VALUE_ON_STACK
:
3013 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
3015 case BOUND_BY_REF_IN_REG
:
3016 printf_filtered ("(BOUND_BY_REF_IN_REG)");
3018 case BOUND_BY_VALUE_IN_REG
:
3019 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
3022 printf_filtered ("(BOUND_SIMPLE)");
3025 printf_filtered ("(unknown bound type)");
3030 static struct obstack dont_print_type_obstack
;
3033 recursive_dump_type (struct type
*type
, int spaces
)
3038 obstack_begin (&dont_print_type_obstack
, 0);
3040 if (TYPE_NFIELDS (type
) > 0
3041 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
3043 struct type
**first_dont_print
3044 = (struct type
**) obstack_base (&dont_print_type_obstack
);
3046 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
3051 if (type
== first_dont_print
[i
])
3053 printfi_filtered (spaces
, "type node ");
3054 gdb_print_host_address (type
, gdb_stdout
);
3055 printf_filtered (" <same as already seen type>\n");
3060 obstack_ptr_grow (&dont_print_type_obstack
, type
);
3063 printfi_filtered (spaces
, "type node ");
3064 gdb_print_host_address (type
, gdb_stdout
);
3065 printf_filtered ("\n");
3066 printfi_filtered (spaces
, "name '%s' (",
3067 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
3068 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
3069 printf_filtered (")\n");
3070 printfi_filtered (spaces
, "tagname '%s' (",
3071 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
3072 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
3073 printf_filtered (")\n");
3074 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
3075 switch (TYPE_CODE (type
))
3077 case TYPE_CODE_UNDEF
:
3078 printf_filtered ("(TYPE_CODE_UNDEF)");
3081 printf_filtered ("(TYPE_CODE_PTR)");
3083 case TYPE_CODE_ARRAY
:
3084 printf_filtered ("(TYPE_CODE_ARRAY)");
3086 case TYPE_CODE_STRUCT
:
3087 printf_filtered ("(TYPE_CODE_STRUCT)");
3089 case TYPE_CODE_UNION
:
3090 printf_filtered ("(TYPE_CODE_UNION)");
3092 case TYPE_CODE_ENUM
:
3093 printf_filtered ("(TYPE_CODE_ENUM)");
3095 case TYPE_CODE_FUNC
:
3096 printf_filtered ("(TYPE_CODE_FUNC)");
3099 printf_filtered ("(TYPE_CODE_INT)");
3102 printf_filtered ("(TYPE_CODE_FLT)");
3104 case TYPE_CODE_VOID
:
3105 printf_filtered ("(TYPE_CODE_VOID)");
3108 printf_filtered ("(TYPE_CODE_SET)");
3110 case TYPE_CODE_RANGE
:
3111 printf_filtered ("(TYPE_CODE_RANGE)");
3113 case TYPE_CODE_STRING
:
3114 printf_filtered ("(TYPE_CODE_STRING)");
3116 case TYPE_CODE_BITSTRING
:
3117 printf_filtered ("(TYPE_CODE_BITSTRING)");
3119 case TYPE_CODE_ERROR
:
3120 printf_filtered ("(TYPE_CODE_ERROR)");
3122 case TYPE_CODE_MEMBER
:
3123 printf_filtered ("(TYPE_CODE_MEMBER)");
3125 case TYPE_CODE_METHOD
:
3126 printf_filtered ("(TYPE_CODE_METHOD)");
3129 printf_filtered ("(TYPE_CODE_REF)");
3131 case TYPE_CODE_CHAR
:
3132 printf_filtered ("(TYPE_CODE_CHAR)");
3134 case TYPE_CODE_BOOL
:
3135 printf_filtered ("(TYPE_CODE_BOOL)");
3137 case TYPE_CODE_COMPLEX
:
3138 printf_filtered ("(TYPE_CODE_COMPLEX)");
3140 case TYPE_CODE_TYPEDEF
:
3141 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3143 case TYPE_CODE_TEMPLATE
:
3144 printf_filtered ("(TYPE_CODE_TEMPLATE)");
3146 case TYPE_CODE_TEMPLATE_ARG
:
3147 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
3149 case TYPE_CODE_NAMESPACE
:
3150 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3153 printf_filtered ("(UNKNOWN TYPE CODE)");
3156 puts_filtered ("\n");
3157 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
3158 printfi_filtered (spaces
, "upper_bound_type 0x%x ",
3159 TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3160 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3161 puts_filtered ("\n");
3162 printfi_filtered (spaces
, "lower_bound_type 0x%x ",
3163 TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3164 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3165 puts_filtered ("\n");
3166 printfi_filtered (spaces
, "objfile ");
3167 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
3168 printf_filtered ("\n");
3169 printfi_filtered (spaces
, "target_type ");
3170 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
3171 printf_filtered ("\n");
3172 if (TYPE_TARGET_TYPE (type
) != NULL
)
3174 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
3176 printfi_filtered (spaces
, "pointer_type ");
3177 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
3178 printf_filtered ("\n");
3179 printfi_filtered (spaces
, "reference_type ");
3180 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
3181 printf_filtered ("\n");
3182 printfi_filtered (spaces
, "type_chain ");
3183 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
3184 printf_filtered ("\n");
3185 printfi_filtered (spaces
, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type
));
3186 if (TYPE_CONST (type
))
3188 puts_filtered (" TYPE_FLAG_CONST");
3190 if (TYPE_VOLATILE (type
))
3192 puts_filtered (" TYPE_FLAG_VOLATILE");
3194 if (TYPE_CODE_SPACE (type
))
3196 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3198 if (TYPE_DATA_SPACE (type
))
3200 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3202 if (TYPE_ADDRESS_CLASS_1 (type
))
3204 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3206 if (TYPE_ADDRESS_CLASS_2 (type
))
3208 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3210 puts_filtered ("\n");
3211 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
3212 if (TYPE_UNSIGNED (type
))
3214 puts_filtered (" TYPE_FLAG_UNSIGNED");
3216 if (TYPE_NOSIGN (type
))
3218 puts_filtered (" TYPE_FLAG_NOSIGN");
3220 if (TYPE_STUB (type
))
3222 puts_filtered (" TYPE_FLAG_STUB");
3224 if (TYPE_TARGET_STUB (type
))
3226 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3228 if (TYPE_STATIC (type
))
3230 puts_filtered (" TYPE_FLAG_STATIC");
3232 if (TYPE_PROTOTYPED (type
))
3234 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3236 if (TYPE_INCOMPLETE (type
))
3238 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3240 if (TYPE_VARARGS (type
))
3242 puts_filtered (" TYPE_FLAG_VARARGS");
3244 /* This is used for things like AltiVec registers on ppc. Gcc emits
3245 an attribute for the array type, which tells whether or not we
3246 have a vector, instead of a regular array. */
3247 if (TYPE_VECTOR (type
))
3249 puts_filtered (" TYPE_FLAG_VECTOR");
3251 puts_filtered ("\n");
3252 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
3253 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
3254 puts_filtered ("\n");
3255 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
3257 printfi_filtered (spaces
+ 2,
3258 "[%d] bitpos %d bitsize %d type ",
3259 idx
, TYPE_FIELD_BITPOS (type
, idx
),
3260 TYPE_FIELD_BITSIZE (type
, idx
));
3261 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
3262 printf_filtered (" name '%s' (",
3263 TYPE_FIELD_NAME (type
, idx
) != NULL
3264 ? TYPE_FIELD_NAME (type
, idx
)
3266 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
3267 printf_filtered (")\n");
3268 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
3270 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
3273 printfi_filtered (spaces
, "vptr_basetype ");
3274 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
3275 puts_filtered ("\n");
3276 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
3278 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
3280 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
3281 switch (TYPE_CODE (type
))
3283 case TYPE_CODE_STRUCT
:
3284 printfi_filtered (spaces
, "cplus_stuff ");
3285 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3286 puts_filtered ("\n");
3287 print_cplus_stuff (type
, spaces
);
3291 printfi_filtered (spaces
, "floatformat ");
3292 if (TYPE_FLOATFORMAT (type
) == NULL
3293 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
3294 puts_filtered ("(null)");
3296 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
3297 puts_filtered ("\n");
3301 /* We have to pick one of the union types to be able print and test
3302 the value. Pick cplus_struct_type, even though we know it isn't
3303 any particular one. */
3304 printfi_filtered (spaces
, "type_specific ");
3305 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3306 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
3308 printf_filtered (" (unknown data form)");
3310 printf_filtered ("\n");
3315 obstack_free (&dont_print_type_obstack
, NULL
);
3318 static void build_gdbtypes (void);
3320 build_gdbtypes (void)
3323 init_type (TYPE_CODE_VOID
, 1,
3325 "void", (struct objfile
*) NULL
);
3327 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3329 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3330 "char", (struct objfile
*) NULL
);
3331 builtin_type_true_char
=
3332 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3334 "true character", (struct objfile
*) NULL
);
3335 builtin_type_signed_char
=
3336 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3338 "signed char", (struct objfile
*) NULL
);
3339 builtin_type_unsigned_char
=
3340 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3342 "unsigned char", (struct objfile
*) NULL
);
3343 builtin_type_short
=
3344 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3346 "short", (struct objfile
*) NULL
);
3347 builtin_type_unsigned_short
=
3348 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3350 "unsigned short", (struct objfile
*) NULL
);
3352 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3354 "int", (struct objfile
*) NULL
);
3355 builtin_type_unsigned_int
=
3356 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3358 "unsigned int", (struct objfile
*) NULL
);
3360 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3362 "long", (struct objfile
*) NULL
);
3363 builtin_type_unsigned_long
=
3364 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3366 "unsigned long", (struct objfile
*) NULL
);
3367 builtin_type_long_long
=
3368 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3370 "long long", (struct objfile
*) NULL
);
3371 builtin_type_unsigned_long_long
=
3372 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3374 "unsigned long long", (struct objfile
*) NULL
);
3375 builtin_type_float
=
3376 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3378 "float", (struct objfile
*) NULL
);
3379 /* vinschen@redhat.com 2002-02-08:
3380 The below lines are disabled since they are doing the wrong
3381 thing for non-multiarch targets. They are setting the correct
3382 type of floats for the target but while on multiarch targets
3383 this is done everytime the architecture changes, it's done on
3384 non-multiarch targets only on startup, leaving the wrong values
3385 in even if the architecture changes (eg. from big-endian to
3388 TYPE_FLOATFORMAT (builtin_type_float
) = TARGET_FLOAT_FORMAT
;
3390 builtin_type_double
=
3391 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3393 "double", (struct objfile
*) NULL
);
3395 TYPE_FLOATFORMAT (builtin_type_double
) = TARGET_DOUBLE_FORMAT
;
3397 builtin_type_long_double
=
3398 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3400 "long double", (struct objfile
*) NULL
);
3402 TYPE_FLOATFORMAT (builtin_type_long_double
) = TARGET_LONG_DOUBLE_FORMAT
;
3404 builtin_type_complex
=
3405 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3407 "complex", (struct objfile
*) NULL
);
3408 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
3409 builtin_type_double_complex
=
3410 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3412 "double complex", (struct objfile
*) NULL
);
3413 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
3414 builtin_type_string
=
3415 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3417 "string", (struct objfile
*) NULL
);
3419 init_type (TYPE_CODE_INT
, 0 / 8,
3421 "int0_t", (struct objfile
*) NULL
);
3423 init_type (TYPE_CODE_INT
, 8 / 8,
3425 "int8_t", (struct objfile
*) NULL
);
3426 builtin_type_uint8
=
3427 init_type (TYPE_CODE_INT
, 8 / 8,
3429 "uint8_t", (struct objfile
*) NULL
);
3430 builtin_type_int16
=
3431 init_type (TYPE_CODE_INT
, 16 / 8,
3433 "int16_t", (struct objfile
*) NULL
);
3434 builtin_type_uint16
=
3435 init_type (TYPE_CODE_INT
, 16 / 8,
3437 "uint16_t", (struct objfile
*) NULL
);
3438 builtin_type_int32
=
3439 init_type (TYPE_CODE_INT
, 32 / 8,
3441 "int32_t", (struct objfile
*) NULL
);
3442 builtin_type_uint32
=
3443 init_type (TYPE_CODE_INT
, 32 / 8,
3445 "uint32_t", (struct objfile
*) NULL
);
3446 builtin_type_int64
=
3447 init_type (TYPE_CODE_INT
, 64 / 8,
3449 "int64_t", (struct objfile
*) NULL
);
3450 builtin_type_uint64
=
3451 init_type (TYPE_CODE_INT
, 64 / 8,
3453 "uint64_t", (struct objfile
*) NULL
);
3454 builtin_type_int128
=
3455 init_type (TYPE_CODE_INT
, 128 / 8,
3457 "int128_t", (struct objfile
*) NULL
);
3458 builtin_type_uint128
=
3459 init_type (TYPE_CODE_INT
, 128 / 8,
3461 "uint128_t", (struct objfile
*) NULL
);
3463 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3465 "bool", (struct objfile
*) NULL
);
3467 /* Add user knob for controlling resolution of opaque types */
3469 (add_set_cmd ("opaque-type-resolution", class_support
, var_boolean
, (char *) &opaque_type_resolution
,
3470 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3473 opaque_type_resolution
= 1;
3475 /* Build SIMD types. */
3477 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
3479 = init_simd_type ("__builtin_v4si", builtin_type_int32
, "f", 4);
3481 = init_simd_type ("__builtin_v16qi", builtin_type_int8
, "f", 16);
3483 = init_simd_type ("__builtin_v8qi", builtin_type_int8
, "f", 8);
3485 = init_simd_type ("__builtin_v8hi", builtin_type_int16
, "f", 8);
3487 = init_simd_type ("__builtin_v4hi", builtin_type_int16
, "f", 4);
3489 = init_simd_type ("__builtin_v2si", builtin_type_int32
, "f", 2);
3491 /* 128 bit vectors. */
3492 builtin_type_v2_double
= init_vector_type (builtin_type_double
, 2);
3493 builtin_type_v4_float
= init_vector_type (builtin_type_float
, 4);
3494 builtin_type_v2_int64
= init_vector_type (builtin_type_int64
, 2);
3495 builtin_type_v4_int32
= init_vector_type (builtin_type_int32
, 4);
3496 builtin_type_v8_int16
= init_vector_type (builtin_type_int16
, 8);
3497 builtin_type_v16_int8
= init_vector_type (builtin_type_int8
, 16);
3498 /* 64 bit vectors. */
3499 builtin_type_v2_float
= init_vector_type (builtin_type_float
, 2);
3500 builtin_type_v2_int32
= init_vector_type (builtin_type_int32
, 2);
3501 builtin_type_v4_int16
= init_vector_type (builtin_type_int16
, 4);
3502 builtin_type_v8_int8
= init_vector_type (builtin_type_int8
, 8);
3505 builtin_type_vec64
= build_builtin_type_vec64 ();
3506 builtin_type_vec64i
= build_builtin_type_vec64i ();
3507 builtin_type_vec128
= build_builtin_type_vec128 ();
3508 builtin_type_vec128i
= build_builtin_type_vec128i ();
3510 /* Pointer/Address types. */
3512 /* NOTE: on some targets, addresses and pointers are not necessarily
3513 the same --- for example, on the D10V, pointers are 16 bits long,
3514 but addresses are 32 bits long. See doc/gdbint.texinfo,
3515 ``Pointers Are Not Always Addresses''.
3518 - gdb's `struct type' always describes the target's
3520 - gdb's `struct value' objects should always hold values in
3522 - gdb's CORE_ADDR values are addresses in the unified virtual
3523 address space that the assembler and linker work with. Thus,
3524 since target_read_memory takes a CORE_ADDR as an argument, it
3525 can access any memory on the target, even if the processor has
3526 separate code and data address spaces.
3529 - If v is a value holding a D10V code pointer, its contents are
3530 in target form: a big-endian address left-shifted two bits.
3531 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3532 sizeof (void *) == 2 on the target.
3534 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3535 target type for a value the target will never see. It's only
3536 used to hold the values of (typeless) linker symbols, which are
3537 indeed in the unified virtual address space. */
3538 builtin_type_void_data_ptr
= make_pointer_type (builtin_type_void
, NULL
);
3539 builtin_type_void_func_ptr
3540 = lookup_pointer_type (lookup_function_type (builtin_type_void
));
3541 builtin_type_CORE_ADDR
=
3542 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3544 "__CORE_ADDR", (struct objfile
*) NULL
);
3545 builtin_type_bfd_vma
=
3546 init_type (TYPE_CODE_INT
, TARGET_BFD_VMA_BIT
/ 8,
3548 "__bfd_vma", (struct objfile
*) NULL
);
3551 extern void _initialize_gdbtypes (void);
3553 _initialize_gdbtypes (void)
3555 struct cmd_list_element
*c
;
3558 /* FIXME - For the moment, handle types by swapping them in and out.
3559 Should be using the per-architecture data-pointer and a large
3561 register_gdbarch_swap (&builtin_type_void
, sizeof (struct type
*), NULL
);
3562 register_gdbarch_swap (&builtin_type_char
, sizeof (struct type
*), NULL
);
3563 register_gdbarch_swap (&builtin_type_short
, sizeof (struct type
*), NULL
);
3564 register_gdbarch_swap (&builtin_type_int
, sizeof (struct type
*), NULL
);
3565 register_gdbarch_swap (&builtin_type_long
, sizeof (struct type
*), NULL
);
3566 register_gdbarch_swap (&builtin_type_long_long
, sizeof (struct type
*), NULL
);
3567 register_gdbarch_swap (&builtin_type_signed_char
, sizeof (struct type
*), NULL
);
3568 register_gdbarch_swap (&builtin_type_unsigned_char
, sizeof (struct type
*), NULL
);
3569 register_gdbarch_swap (&builtin_type_unsigned_short
, sizeof (struct type
*), NULL
);
3570 register_gdbarch_swap (&builtin_type_unsigned_int
, sizeof (struct type
*), NULL
);
3571 register_gdbarch_swap (&builtin_type_unsigned_long
, sizeof (struct type
*), NULL
);
3572 register_gdbarch_swap (&builtin_type_unsigned_long_long
, sizeof (struct type
*), NULL
);
3573 register_gdbarch_swap (&builtin_type_float
, sizeof (struct type
*), NULL
);
3574 register_gdbarch_swap (&builtin_type_double
, sizeof (struct type
*), NULL
);
3575 register_gdbarch_swap (&builtin_type_long_double
, sizeof (struct type
*), NULL
);
3576 register_gdbarch_swap (&builtin_type_complex
, sizeof (struct type
*), NULL
);
3577 register_gdbarch_swap (&builtin_type_double_complex
, sizeof (struct type
*), NULL
);
3578 register_gdbarch_swap (&builtin_type_string
, sizeof (struct type
*), NULL
);
3579 register_gdbarch_swap (&builtin_type_int8
, sizeof (struct type
*), NULL
);
3580 register_gdbarch_swap (&builtin_type_uint8
, sizeof (struct type
*), NULL
);
3581 register_gdbarch_swap (&builtin_type_int16
, sizeof (struct type
*), NULL
);
3582 register_gdbarch_swap (&builtin_type_uint16
, sizeof (struct type
*), NULL
);
3583 register_gdbarch_swap (&builtin_type_int32
, sizeof (struct type
*), NULL
);
3584 register_gdbarch_swap (&builtin_type_uint32
, sizeof (struct type
*), NULL
);
3585 register_gdbarch_swap (&builtin_type_int64
, sizeof (struct type
*), NULL
);
3586 register_gdbarch_swap (&builtin_type_uint64
, sizeof (struct type
*), NULL
);
3587 register_gdbarch_swap (&builtin_type_int128
, sizeof (struct type
*), NULL
);
3588 register_gdbarch_swap (&builtin_type_uint128
, sizeof (struct type
*), NULL
);
3589 register_gdbarch_swap (&builtin_type_v4sf
, sizeof (struct type
*), NULL
);
3590 register_gdbarch_swap (&builtin_type_v4si
, sizeof (struct type
*), NULL
);
3591 register_gdbarch_swap (&builtin_type_v16qi
, sizeof (struct type
*), NULL
);
3592 register_gdbarch_swap (&builtin_type_v8qi
, sizeof (struct type
*), NULL
);
3593 register_gdbarch_swap (&builtin_type_v8hi
, sizeof (struct type
*), NULL
);
3594 register_gdbarch_swap (&builtin_type_v4hi
, sizeof (struct type
*), NULL
);
3595 register_gdbarch_swap (&builtin_type_v2si
, sizeof (struct type
*), NULL
);
3596 register_gdbarch_swap (&builtin_type_v2_double
, sizeof (struct type
*), NULL
);
3597 register_gdbarch_swap (&builtin_type_v4_float
, sizeof (struct type
*), NULL
);
3598 register_gdbarch_swap (&builtin_type_v2_int64
, sizeof (struct type
*), NULL
);
3599 register_gdbarch_swap (&builtin_type_v4_int32
, sizeof (struct type
*), NULL
);
3600 register_gdbarch_swap (&builtin_type_v8_int16
, sizeof (struct type
*), NULL
);
3601 register_gdbarch_swap (&builtin_type_v16_int8
, sizeof (struct type
*), NULL
);
3602 register_gdbarch_swap (&builtin_type_v2_float
, sizeof (struct type
*), NULL
);
3603 register_gdbarch_swap (&builtin_type_v2_int32
, sizeof (struct type
*), NULL
);
3604 register_gdbarch_swap (&builtin_type_v8_int8
, sizeof (struct type
*), NULL
);
3605 register_gdbarch_swap (&builtin_type_v4_int16
, sizeof (struct type
*), NULL
);
3606 register_gdbarch_swap (&builtin_type_vec128
, sizeof (struct type
*), NULL
);
3607 register_gdbarch_swap (&builtin_type_vec128i
, sizeof (struct type
*), NULL
);
3608 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr
);
3609 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr
);
3610 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR
);
3611 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma
);
3612 register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
3614 /* Note: These types do not need to be swapped - they are target
3616 builtin_type_ieee_single_big
=
3617 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_big
.totalsize
/ 8,
3618 0, "builtin_type_ieee_single_big", NULL
);
3619 TYPE_FLOATFORMAT (builtin_type_ieee_single_big
) = &floatformat_ieee_single_big
;
3620 builtin_type_ieee_single_little
=
3621 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_little
.totalsize
/ 8,
3622 0, "builtin_type_ieee_single_little", NULL
);
3623 TYPE_FLOATFORMAT (builtin_type_ieee_single_little
) = &floatformat_ieee_single_little
;
3624 builtin_type_ieee_double_big
=
3625 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_big
.totalsize
/ 8,
3626 0, "builtin_type_ieee_double_big", NULL
);
3627 TYPE_FLOATFORMAT (builtin_type_ieee_double_big
) = &floatformat_ieee_double_big
;
3628 builtin_type_ieee_double_little
=
3629 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_little
.totalsize
/ 8,
3630 0, "builtin_type_ieee_double_little", NULL
);
3631 TYPE_FLOATFORMAT (builtin_type_ieee_double_little
) = &floatformat_ieee_double_little
;
3632 builtin_type_ieee_double_littlebyte_bigword
=
3633 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_littlebyte_bigword
.totalsize
/ 8,
3634 0, "builtin_type_ieee_double_littlebyte_bigword", NULL
);
3635 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword
) = &floatformat_ieee_double_littlebyte_bigword
;
3636 builtin_type_i387_ext
=
3637 init_type (TYPE_CODE_FLT
, floatformat_i387_ext
.totalsize
/ 8,
3638 0, "builtin_type_i387_ext", NULL
);
3639 TYPE_FLOATFORMAT (builtin_type_i387_ext
) = &floatformat_i387_ext
;
3640 builtin_type_m68881_ext
=
3641 init_type (TYPE_CODE_FLT
, floatformat_m68881_ext
.totalsize
/ 8,
3642 0, "builtin_type_m68881_ext", NULL
);
3643 TYPE_FLOATFORMAT (builtin_type_m68881_ext
) = &floatformat_m68881_ext
;
3644 builtin_type_i960_ext
=
3645 init_type (TYPE_CODE_FLT
, floatformat_i960_ext
.totalsize
/ 8,
3646 0, "builtin_type_i960_ext", NULL
);
3647 TYPE_FLOATFORMAT (builtin_type_i960_ext
) = &floatformat_i960_ext
;
3648 builtin_type_m88110_ext
=
3649 init_type (TYPE_CODE_FLT
, floatformat_m88110_ext
.totalsize
/ 8,
3650 0, "builtin_type_m88110_ext", NULL
);
3651 TYPE_FLOATFORMAT (builtin_type_m88110_ext
) = &floatformat_m88110_ext
;
3652 builtin_type_m88110_harris_ext
=
3653 init_type (TYPE_CODE_FLT
, floatformat_m88110_harris_ext
.totalsize
/ 8,
3654 0, "builtin_type_m88110_harris_ext", NULL
);
3655 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext
) = &floatformat_m88110_harris_ext
;
3656 builtin_type_arm_ext_big
=
3657 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_big
.totalsize
/ 8,
3658 0, "builtin_type_arm_ext_big", NULL
);
3659 TYPE_FLOATFORMAT (builtin_type_arm_ext_big
) = &floatformat_arm_ext_big
;
3660 builtin_type_arm_ext_littlebyte_bigword
=
3661 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_littlebyte_bigword
.totalsize
/ 8,
3662 0, "builtin_type_arm_ext_littlebyte_bigword", NULL
);
3663 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword
) = &floatformat_arm_ext_littlebyte_bigword
;
3664 builtin_type_ia64_spill_big
=
3665 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_big
.totalsize
/ 8,
3666 0, "builtin_type_ia64_spill_big", NULL
);
3667 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big
) = &floatformat_ia64_spill_big
;
3668 builtin_type_ia64_spill_little
=
3669 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_little
.totalsize
/ 8,
3670 0, "builtin_type_ia64_spill_little", NULL
);
3671 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little
) = &floatformat_ia64_spill_little
;
3672 builtin_type_ia64_quad_big
=
3673 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_big
.totalsize
/ 8,
3674 0, "builtin_type_ia64_quad_big", NULL
);
3675 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big
) = &floatformat_ia64_quad_big
;
3676 builtin_type_ia64_quad_little
=
3677 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_little
.totalsize
/ 8,
3678 0, "builtin_type_ia64_quad_little", NULL
);
3679 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little
) = &floatformat_ia64_quad_little
;
3682 add_set_cmd ("overload", no_class
, var_zinteger
, (char *) &overload_debug
,
3683 "Set debugging of C++ overloading.\n\
3684 When enabled, ranking of the functions\n\
3685 is displayed.", &setdebuglist
),