1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 Contributed by Cygnus Support, using pieces from other GDB modules.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
26 #include "gdb_string.h"
32 #include "expression.h"
37 #include "complaints.h"
41 #include "gdb_assert.h"
44 /* These variables point to the objects
45 representing the predefined C data types. */
47 struct type
*builtin_type_void
;
48 struct type
*builtin_type_char
;
49 struct type
*builtin_type_true_char
;
50 struct type
*builtin_type_short
;
51 struct type
*builtin_type_int
;
52 struct type
*builtin_type_long
;
53 struct type
*builtin_type_long_long
;
54 struct type
*builtin_type_signed_char
;
55 struct type
*builtin_type_unsigned_char
;
56 struct type
*builtin_type_unsigned_short
;
57 struct type
*builtin_type_unsigned_int
;
58 struct type
*builtin_type_unsigned_long
;
59 struct type
*builtin_type_unsigned_long_long
;
60 struct type
*builtin_type_float
;
61 struct type
*builtin_type_double
;
62 struct type
*builtin_type_long_double
;
63 struct type
*builtin_type_complex
;
64 struct type
*builtin_type_double_complex
;
65 struct type
*builtin_type_string
;
66 struct type
*builtin_type_int0
;
67 struct type
*builtin_type_int8
;
68 struct type
*builtin_type_uint8
;
69 struct type
*builtin_type_int16
;
70 struct type
*builtin_type_uint16
;
71 struct type
*builtin_type_int32
;
72 struct type
*builtin_type_uint32
;
73 struct type
*builtin_type_int64
;
74 struct type
*builtin_type_uint64
;
75 struct type
*builtin_type_int128
;
76 struct type
*builtin_type_uint128
;
77 struct type
*builtin_type_bool
;
79 /* 128 bit long vector types */
80 struct type
*builtin_type_v2_double
;
81 struct type
*builtin_type_v4_float
;
82 struct type
*builtin_type_v2_int64
;
83 struct type
*builtin_type_v4_int32
;
84 struct type
*builtin_type_v8_int16
;
85 struct type
*builtin_type_v16_int8
;
86 /* 64 bit long vector types */
87 struct type
*builtin_type_v2_float
;
88 struct type
*builtin_type_v2_int32
;
89 struct type
*builtin_type_v4_int16
;
90 struct type
*builtin_type_v8_int8
;
92 struct type
*builtin_type_v4sf
;
93 struct type
*builtin_type_v4si
;
94 struct type
*builtin_type_v16qi
;
95 struct type
*builtin_type_v8qi
;
96 struct type
*builtin_type_v8hi
;
97 struct type
*builtin_type_v4hi
;
98 struct type
*builtin_type_v2si
;
99 struct type
*builtin_type_vec64
;
100 struct type
*builtin_type_vec128
;
102 /* Floatformat pairs. */
103 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
104 &floatformat_ieee_single_big
,
105 &floatformat_ieee_single_little
107 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
108 &floatformat_ieee_double_big
,
109 &floatformat_ieee_double_little
111 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
112 &floatformat_ieee_double_big
,
113 &floatformat_ieee_double_littlebyte_bigword
115 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
116 &floatformat_i387_ext
,
117 &floatformat_i387_ext
119 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
120 &floatformat_m68881_ext
,
121 &floatformat_m68881_ext
123 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
124 &floatformat_arm_ext_big
,
125 &floatformat_arm_ext_littlebyte_bigword
127 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
128 &floatformat_ia64_spill_big
,
129 &floatformat_ia64_spill_little
131 const struct floatformat
*floatformats_ia64_quad
[BFD_ENDIAN_UNKNOWN
] = {
132 &floatformat_ia64_quad_big
,
133 &floatformat_ia64_quad_little
135 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
139 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
144 struct type
*builtin_type_ieee_single
;
145 struct type
*builtin_type_ieee_double
;
146 struct type
*builtin_type_i387_ext
;
147 struct type
*builtin_type_m68881_ext
;
148 struct type
*builtin_type_arm_ext
;
149 struct type
*builtin_type_ia64_spill
;
150 struct type
*builtin_type_ia64_quad
;
152 struct type
*builtin_type_void_data_ptr
;
153 struct type
*builtin_type_void_func_ptr
;
154 struct type
*builtin_type_CORE_ADDR
;
155 struct type
*builtin_type_bfd_vma
;
157 int opaque_type_resolution
= 1;
159 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
160 struct cmd_list_element
*c
, const char *value
)
162 fprintf_filtered (file
, _("\
163 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
167 int overload_debug
= 0;
169 show_overload_debug (struct ui_file
*file
, int from_tty
,
170 struct cmd_list_element
*c
, const char *value
)
172 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"), value
);
179 }; /* maximum extension is 128! FIXME */
181 static void print_bit_vector (B_TYPE
*, int);
182 static void print_arg_types (struct field
*, int, int);
183 static void dump_fn_fieldlists (struct type
*, int);
184 static void print_cplus_stuff (struct type
*, int);
185 static void virtual_base_list_aux (struct type
*dclass
);
188 /* Alloc a new type structure and fill it with some defaults. If
189 OBJFILE is non-NULL, then allocate the space for the type structure
190 in that objfile's objfile_obstack. Otherwise allocate the new type structure
191 by xmalloc () (for permanent types). */
194 alloc_type (struct objfile
*objfile
)
198 /* Alloc the structure and start off with all fields zeroed. */
202 type
= xmalloc (sizeof (struct type
));
203 memset (type
, 0, sizeof (struct type
));
204 TYPE_MAIN_TYPE (type
) = xmalloc (sizeof (struct main_type
));
208 type
= obstack_alloc (&objfile
->objfile_obstack
,
209 sizeof (struct type
));
210 memset (type
, 0, sizeof (struct type
));
211 TYPE_MAIN_TYPE (type
) = obstack_alloc (&objfile
->objfile_obstack
,
212 sizeof (struct main_type
));
213 OBJSTAT (objfile
, n_types
++);
215 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
217 /* Initialize the fields that might not be zero. */
219 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
220 TYPE_OBJFILE (type
) = objfile
;
221 TYPE_VPTR_FIELDNO (type
) = -1;
222 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
227 /* Alloc a new type instance structure, fill it with some defaults,
228 and point it at OLDTYPE. Allocate the new type instance from the
229 same place as OLDTYPE. */
232 alloc_type_instance (struct type
*oldtype
)
236 /* Allocate the structure. */
238 if (TYPE_OBJFILE (oldtype
) == NULL
)
240 type
= xmalloc (sizeof (struct type
));
241 memset (type
, 0, sizeof (struct type
));
245 type
= obstack_alloc (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
246 sizeof (struct type
));
247 memset (type
, 0, sizeof (struct type
));
249 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
251 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
256 /* Clear all remnants of the previous type at TYPE, in preparation for
257 replacing it with something else. */
259 smash_type (struct type
*type
)
261 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
263 /* For now, delete the rings. */
264 TYPE_CHAIN (type
) = type
;
266 /* For now, leave the pointer/reference types alone. */
269 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
270 to a pointer to memory where the pointer type should be stored.
271 If *TYPEPTR is zero, update it to point to the pointer type we return.
272 We allocate new memory if needed. */
275 make_pointer_type (struct type
*type
, struct type
**typeptr
)
277 struct type
*ntype
; /* New type */
278 struct objfile
*objfile
;
280 ntype
= TYPE_POINTER_TYPE (type
);
285 return ntype
; /* Don't care about alloc, and have new type. */
286 else if (*typeptr
== 0)
288 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
293 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
295 ntype
= alloc_type (TYPE_OBJFILE (type
));
300 /* We have storage, but need to reset it. */
303 objfile
= TYPE_OBJFILE (ntype
);
305 TYPE_OBJFILE (ntype
) = objfile
;
308 TYPE_TARGET_TYPE (ntype
) = type
;
309 TYPE_POINTER_TYPE (type
) = ntype
;
311 /* FIXME! Assume the machine has only one representation for pointers! */
313 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
314 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
316 /* Mark pointers as unsigned. The target converts between pointers
317 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
318 ADDRESS_TO_POINTER(). */
319 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
321 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
322 TYPE_POINTER_TYPE (type
) = ntype
;
327 /* Given a type TYPE, return a type of pointers to that type.
328 May need to construct such a type if this is the first use. */
331 lookup_pointer_type (struct type
*type
)
333 return make_pointer_type (type
, (struct type
**) 0);
336 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
337 to a pointer to memory where the reference type should be stored.
338 If *TYPEPTR is zero, update it to point to the reference type we return.
339 We allocate new memory if needed. */
342 make_reference_type (struct type
*type
, struct type
**typeptr
)
344 struct type
*ntype
; /* New type */
345 struct objfile
*objfile
;
347 ntype
= TYPE_REFERENCE_TYPE (type
);
352 return ntype
; /* Don't care about alloc, and have new type. */
353 else if (*typeptr
== 0)
355 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
360 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
362 ntype
= alloc_type (TYPE_OBJFILE (type
));
367 /* We have storage, but need to reset it. */
370 objfile
= TYPE_OBJFILE (ntype
);
372 TYPE_OBJFILE (ntype
) = objfile
;
375 TYPE_TARGET_TYPE (ntype
) = type
;
376 TYPE_REFERENCE_TYPE (type
) = ntype
;
378 /* FIXME! Assume the machine has only one representation for references,
379 and that it matches the (only) representation for pointers! */
381 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
382 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
384 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
385 TYPE_REFERENCE_TYPE (type
) = ntype
;
390 /* Same as above, but caller doesn't care about memory allocation details. */
393 lookup_reference_type (struct type
*type
)
395 return make_reference_type (type
, (struct type
**) 0);
398 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
399 to a pointer to memory where the function type should be stored.
400 If *TYPEPTR is zero, update it to point to the function type we return.
401 We allocate new memory if needed. */
404 make_function_type (struct type
*type
, struct type
**typeptr
)
406 struct type
*ntype
; /* New type */
407 struct objfile
*objfile
;
409 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
411 ntype
= alloc_type (TYPE_OBJFILE (type
));
416 /* We have storage, but need to reset it. */
419 objfile
= TYPE_OBJFILE (ntype
);
421 TYPE_OBJFILE (ntype
) = objfile
;
424 TYPE_TARGET_TYPE (ntype
) = type
;
426 TYPE_LENGTH (ntype
) = 1;
427 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
433 /* Given a type TYPE, return a type of functions that return that type.
434 May need to construct such a type if this is the first use. */
437 lookup_function_type (struct type
*type
)
439 return make_function_type (type
, (struct type
**) 0);
442 /* Identify address space identifier by name --
443 return the integer flag defined in gdbtypes.h. */
445 address_space_name_to_int (char *space_identifier
)
447 struct gdbarch
*gdbarch
= current_gdbarch
;
449 /* Check for known address space delimiters. */
450 if (!strcmp (space_identifier
, "code"))
451 return TYPE_FLAG_CODE_SPACE
;
452 else if (!strcmp (space_identifier
, "data"))
453 return TYPE_FLAG_DATA_SPACE
;
454 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
455 && gdbarch_address_class_name_to_type_flags (gdbarch
,
460 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
463 /* Identify address space identifier by integer flag as defined in
464 gdbtypes.h -- return the string version of the adress space name. */
467 address_space_int_to_name (int space_flag
)
469 struct gdbarch
*gdbarch
= current_gdbarch
;
470 if (space_flag
& TYPE_FLAG_CODE_SPACE
)
472 else if (space_flag
& TYPE_FLAG_DATA_SPACE
)
474 else if ((space_flag
& TYPE_FLAG_ADDRESS_CLASS_ALL
)
475 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
476 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
481 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
483 If STORAGE is non-NULL, create the new type instance there.
484 STORAGE must be in the same obstack as TYPE. */
487 make_qualified_type (struct type
*type
, int new_flags
,
488 struct type
*storage
)
494 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
496 ntype
= TYPE_CHAIN (ntype
);
497 } while (ntype
!= type
);
499 /* Create a new type instance. */
501 ntype
= alloc_type_instance (type
);
504 /* If STORAGE was provided, it had better be in the same objfile as
505 TYPE. Otherwise, we can't link it into TYPE's cv chain: if one
506 objfile is freed and the other kept, we'd have dangling
508 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
511 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
512 TYPE_CHAIN (ntype
) = ntype
;
515 /* Pointers or references to the original type are not relevant to
517 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
518 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
520 /* Chain the new qualified type to the old type. */
521 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
522 TYPE_CHAIN (type
) = ntype
;
524 /* Now set the instance flags and return the new type. */
525 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
527 /* Set length of new type to that of the original type. */
528 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
533 /* Make an address-space-delimited variant of a type -- a type that
534 is identical to the one supplied except that it has an address
535 space attribute attached to it (such as "code" or "data").
537 The space attributes "code" and "data" are for Harvard architectures.
538 The address space attributes are for architectures which have
539 alternately sized pointers or pointers with alternate representations. */
542 make_type_with_address_space (struct type
*type
, int space_flag
)
545 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
546 & ~(TYPE_FLAG_CODE_SPACE
| TYPE_FLAG_DATA_SPACE
547 | TYPE_FLAG_ADDRESS_CLASS_ALL
))
550 return make_qualified_type (type
, new_flags
, NULL
);
553 /* Make a "c-v" variant of a type -- a type that is identical to the
554 one supplied except that it may have const or volatile attributes
555 CNST is a flag for setting the const attribute
556 VOLTL is a flag for setting the volatile attribute
557 TYPE is the base type whose variant we are creating.
559 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
560 storage to hold the new qualified type; *TYPEPTR and TYPE must be
561 in the same objfile. Otherwise, allocate fresh memory for the new
562 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
563 new type we construct. */
565 make_cv_type (int cnst
, int voltl
, struct type
*type
, struct type
**typeptr
)
567 struct type
*ntype
; /* New type */
568 struct type
*tmp_type
= type
; /* tmp type */
569 struct objfile
*objfile
;
571 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
572 & ~(TYPE_FLAG_CONST
| TYPE_FLAG_VOLATILE
));
575 new_flags
|= TYPE_FLAG_CONST
;
578 new_flags
|= TYPE_FLAG_VOLATILE
;
580 if (typeptr
&& *typeptr
!= NULL
)
582 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
583 a C-V variant chain that threads across objfiles: if one
584 objfile gets freed, then the other has a broken C-V chain.
586 This code used to try to copy over the main type from TYPE to
587 *TYPEPTR if they were in different objfiles, but that's
588 wrong, too: TYPE may have a field list or member function
589 lists, which refer to types of their own, etc. etc. The
590 whole shebang would need to be copied over recursively; you
591 can't have inter-objfile pointers. The only thing to do is
592 to leave stub types as stub types, and look them up afresh by
593 name each time you encounter them. */
594 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
597 ntype
= make_qualified_type (type
, new_flags
, typeptr
? *typeptr
: NULL
);
605 /* Replace the contents of ntype with the type *type. This changes the
606 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
607 the changes are propogated to all types in the TYPE_CHAIN.
609 In order to build recursive types, it's inevitable that we'll need
610 to update types in place --- but this sort of indiscriminate
611 smashing is ugly, and needs to be replaced with something more
612 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
613 clear if more steps are needed. */
615 replace_type (struct type
*ntype
, struct type
*type
)
619 /* These two types had better be in the same objfile. Otherwise,
620 the assignment of one type's main type structure to the other
621 will produce a type with references to objects (names; field
622 lists; etc.) allocated on an objfile other than its own. */
623 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
625 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
627 /* The type length is not a part of the main type. Update it for each
628 type on the variant chain. */
631 /* Assert that this element of the chain has no address-class bits
632 set in its flags. Such type variants might have type lengths
633 which are supposed to be different from the non-address-class
634 variants. This assertion shouldn't ever be triggered because
635 symbol readers which do construct address-class variants don't
636 call replace_type(). */
637 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
639 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
640 chain
= TYPE_CHAIN (chain
);
641 } while (ntype
!= chain
);
643 /* Assert that the two types have equivalent instance qualifiers.
644 This should be true for at least all of our debug readers. */
645 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
648 /* Implement direct support for MEMBER_TYPE in GNU C++.
649 May need to construct such a type if this is the first use.
650 The TYPE is the type of the member. The DOMAIN is the type
651 of the aggregate that the member belongs to. */
654 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
658 mtype
= alloc_type (TYPE_OBJFILE (type
));
659 smash_to_memberptr_type (mtype
, domain
, type
);
663 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
666 lookup_methodptr_type (struct type
*to_type
)
670 mtype
= alloc_type (TYPE_OBJFILE (to_type
));
671 TYPE_TARGET_TYPE (mtype
) = to_type
;
672 TYPE_DOMAIN_TYPE (mtype
) = TYPE_DOMAIN_TYPE (to_type
);
673 TYPE_LENGTH (mtype
) = cplus_method_ptr_size ();
674 TYPE_CODE (mtype
) = TYPE_CODE_METHODPTR
;
678 /* Allocate a stub method whose return type is TYPE.
679 This apparently happens for speed of symbol reading, since parsing
680 out the arguments to the method is cpu-intensive, the way we are doing
681 it. So, we will fill in arguments later.
682 This always returns a fresh type. */
685 allocate_stub_method (struct type
*type
)
689 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
690 TYPE_OBJFILE (type
));
691 TYPE_TARGET_TYPE (mtype
) = type
;
692 /* _DOMAIN_TYPE (mtype) = unknown yet */
696 /* Create a range type using either a blank type supplied in RESULT_TYPE,
697 or creating a new type, inheriting the objfile from INDEX_TYPE.
699 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
700 HIGH_BOUND, inclusive.
702 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
703 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
706 create_range_type (struct type
*result_type
, struct type
*index_type
,
707 int low_bound
, int high_bound
)
709 if (result_type
== NULL
)
711 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
713 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
714 TYPE_TARGET_TYPE (result_type
) = index_type
;
715 if (TYPE_STUB (index_type
))
716 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
718 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
719 TYPE_NFIELDS (result_type
) = 2;
720 TYPE_FIELDS (result_type
) = (struct field
*)
721 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
722 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
723 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
724 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
725 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
726 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
729 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
731 return (result_type
);
734 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
735 Return 1 if type is a range type, 0 if it is discrete (and bounds
736 will fit in LONGEST), or -1 otherwise. */
739 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
741 CHECK_TYPEDEF (type
);
742 switch (TYPE_CODE (type
))
744 case TYPE_CODE_RANGE
:
745 *lowp
= TYPE_LOW_BOUND (type
);
746 *highp
= TYPE_HIGH_BOUND (type
);
749 if (TYPE_NFIELDS (type
) > 0)
751 /* The enums may not be sorted by value, so search all
755 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
756 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
758 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
759 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
760 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
761 *highp
= TYPE_FIELD_BITPOS (type
, i
);
764 /* Set unsigned indicator if warranted. */
767 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
781 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
783 if (!TYPE_UNSIGNED (type
))
785 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
789 /* ... fall through for unsigned ints ... */
792 /* This round-about calculation is to avoid shifting by
793 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
794 if TYPE_LENGTH (type) == sizeof (LONGEST). */
795 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
796 *highp
= (*highp
- 1) | *highp
;
803 /* Create an array type using either a blank type supplied in RESULT_TYPE,
804 or creating a new type, inheriting the objfile from RANGE_TYPE.
806 Elements will be of type ELEMENT_TYPE, the indices will be of type
809 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
810 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
813 create_array_type (struct type
*result_type
, struct type
*element_type
,
814 struct type
*range_type
)
816 LONGEST low_bound
, high_bound
;
818 if (result_type
== NULL
)
820 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
822 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
823 TYPE_TARGET_TYPE (result_type
) = element_type
;
824 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
825 low_bound
= high_bound
= 0;
826 CHECK_TYPEDEF (element_type
);
827 TYPE_LENGTH (result_type
) =
828 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
829 TYPE_NFIELDS (result_type
) = 1;
830 TYPE_FIELDS (result_type
) =
831 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
832 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
833 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
834 TYPE_VPTR_FIELDNO (result_type
) = -1;
836 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
837 if (TYPE_LENGTH (result_type
) == 0)
838 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
840 return (result_type
);
843 /* Create a string type using either a blank type supplied in RESULT_TYPE,
844 or creating a new type. String types are similar enough to array of
845 char types that we can use create_array_type to build the basic type
846 and then bash it into a string type.
848 For fixed length strings, the range type contains 0 as the lower
849 bound and the length of the string minus one as the upper bound.
851 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
852 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
855 create_string_type (struct type
*result_type
, struct type
*range_type
)
857 struct type
*string_char_type
;
859 string_char_type
= language_string_char_type (current_language
,
861 result_type
= create_array_type (result_type
,
864 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
865 return (result_type
);
869 create_set_type (struct type
*result_type
, struct type
*domain_type
)
871 LONGEST low_bound
, high_bound
, bit_length
;
872 if (result_type
== NULL
)
874 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
876 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
877 TYPE_NFIELDS (result_type
) = 1;
878 TYPE_FIELDS (result_type
) = (struct field
*)
879 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
880 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
882 if (!TYPE_STUB (domain_type
))
884 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
885 low_bound
= high_bound
= 0;
886 bit_length
= high_bound
- low_bound
+ 1;
887 TYPE_LENGTH (result_type
)
888 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
890 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
893 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
895 return (result_type
);
899 append_flags_type_flag (struct type
*type
, int bitpos
, char *name
)
901 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
902 gdb_assert (bitpos
< TYPE_NFIELDS (type
));
903 gdb_assert (bitpos
>= 0);
907 TYPE_FIELD_NAME (type
, bitpos
) = xstrdup (name
);
908 TYPE_FIELD_BITPOS (type
, bitpos
) = bitpos
;
912 /* Don't show this field to the user. */
913 TYPE_FIELD_BITPOS (type
, bitpos
) = -1;
918 init_flags_type (char *name
, int length
)
920 int nfields
= length
* TARGET_CHAR_BIT
;
923 type
= init_type (TYPE_CODE_FLAGS
, length
, TYPE_FLAG_UNSIGNED
, name
, NULL
);
924 TYPE_NFIELDS (type
) = nfields
;
925 TYPE_FIELDS (type
) = TYPE_ALLOC (type
, nfields
* sizeof (struct field
));
926 memset (TYPE_FIELDS (type
), 0, nfields
* sizeof (struct field
));
931 /* Construct and return a type of the form:
932 struct NAME { ELT_TYPE ELT_NAME[N]; }
933 We use these types for SIMD registers. For example, the type of
934 the SSE registers on the late x86-family processors is:
935 struct __builtin_v4sf { float f[4]; }
936 built by the function call:
937 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
938 The type returned is a permanent type, allocated using malloc; it
939 doesn't live in any objfile's obstack. */
941 init_simd_type (char *name
,
942 struct type
*elt_type
,
946 struct type
*simd_type
;
947 struct type
*array_type
;
949 simd_type
= init_composite_type (name
, TYPE_CODE_STRUCT
);
950 array_type
= create_array_type (0, elt_type
,
951 create_range_type (0, builtin_type_int
,
953 append_composite_type_field (simd_type
, elt_name
, array_type
);
958 init_vector_type (struct type
*elt_type
, int n
)
960 struct type
*array_type
;
962 array_type
= create_array_type (0, elt_type
,
963 create_range_type (0, builtin_type_int
,
965 TYPE_FLAGS (array_type
) |= TYPE_FLAG_VECTOR
;
970 build_builtin_type_vec64 (void)
972 /* Construct a type for the 64 bit registers. The type we're
975 union __gdb_builtin_type_vec64
987 t
= init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION
);
988 append_composite_type_field (t
, "uint64", builtin_type_int64
);
989 append_composite_type_field (t
, "v2_float", builtin_type_v2_float
);
990 append_composite_type_field (t
, "v2_int32", builtin_type_v2_int32
);
991 append_composite_type_field (t
, "v4_int16", builtin_type_v4_int16
);
992 append_composite_type_field (t
, "v8_int8", builtin_type_v8_int8
);
994 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
995 TYPE_NAME (t
) = "builtin_type_vec64";
1000 build_builtin_type_vec128 (void)
1002 /* Construct a type for the 128 bit registers. The type we're
1003 building is this: */
1005 union __gdb_builtin_type_vec128
1009 int32_t v4_int32
[4];
1010 int16_t v8_int16
[8];
1011 int8_t v16_int8
[16];
1017 t
= init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION
);
1018 append_composite_type_field (t
, "uint128", builtin_type_int128
);
1019 append_composite_type_field (t
, "v4_float", builtin_type_v4_float
);
1020 append_composite_type_field (t
, "v4_int32", builtin_type_v4_int32
);
1021 append_composite_type_field (t
, "v8_int16", builtin_type_v8_int16
);
1022 append_composite_type_field (t
, "v16_int8", builtin_type_v16_int8
);
1024 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
1025 TYPE_NAME (t
) = "builtin_type_vec128";
1029 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
1030 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1031 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1032 TYPE doesn't include the offset (that's the value of the MEMBER
1033 itself), but does include the structure type into which it points
1036 When "smashing" the type, we preserve the objfile that the
1037 old type pointed to, since we aren't changing where the type is actually
1041 smash_to_memberptr_type (struct type
*type
, struct type
*domain
,
1042 struct type
*to_type
)
1044 struct objfile
*objfile
;
1046 objfile
= TYPE_OBJFILE (type
);
1049 TYPE_OBJFILE (type
) = objfile
;
1050 TYPE_TARGET_TYPE (type
) = to_type
;
1051 TYPE_DOMAIN_TYPE (type
) = domain
;
1052 /* Assume that a data member pointer is the same size as a normal
1054 TYPE_LENGTH (type
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
1055 TYPE_CODE (type
) = TYPE_CODE_MEMBERPTR
;
1058 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1059 METHOD just means `function that gets an extra "this" argument'.
1061 When "smashing" the type, we preserve the objfile that the
1062 old type pointed to, since we aren't changing where the type is actually
1066 smash_to_method_type (struct type
*type
, struct type
*domain
,
1067 struct type
*to_type
, struct field
*args
,
1068 int nargs
, int varargs
)
1070 struct objfile
*objfile
;
1072 objfile
= TYPE_OBJFILE (type
);
1075 TYPE_OBJFILE (type
) = objfile
;
1076 TYPE_TARGET_TYPE (type
) = to_type
;
1077 TYPE_DOMAIN_TYPE (type
) = domain
;
1078 TYPE_FIELDS (type
) = args
;
1079 TYPE_NFIELDS (type
) = nargs
;
1081 TYPE_FLAGS (type
) |= TYPE_FLAG_VARARGS
;
1082 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1083 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1086 /* Return a typename for a struct/union/enum type without "struct ",
1087 "union ", or "enum ". If the type has a NULL name, return NULL. */
1090 type_name_no_tag (const struct type
*type
)
1092 if (TYPE_TAG_NAME (type
) != NULL
)
1093 return TYPE_TAG_NAME (type
);
1095 /* Is there code which expects this to return the name if there is no
1096 tag name? My guess is that this is mainly used for C++ in cases where
1097 the two will always be the same. */
1098 return TYPE_NAME (type
);
1101 /* Lookup a typedef or primitive type named NAME,
1102 visible in lexical block BLOCK.
1103 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1106 lookup_typename (char *name
, struct block
*block
, int noerr
)
1111 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1112 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1114 tmp
= language_lookup_primitive_type_by_name (current_language
,
1121 else if (!tmp
&& noerr
)
1127 error (_("No type named %s."), name
);
1130 return (SYMBOL_TYPE (sym
));
1134 lookup_unsigned_typename (char *name
)
1136 char *uns
= alloca (strlen (name
) + 10);
1138 strcpy (uns
, "unsigned ");
1139 strcpy (uns
+ 9, name
);
1140 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
1144 lookup_signed_typename (char *name
)
1147 char *uns
= alloca (strlen (name
) + 8);
1149 strcpy (uns
, "signed ");
1150 strcpy (uns
+ 7, name
);
1151 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
1152 /* If we don't find "signed FOO" just try again with plain "FOO". */
1155 return lookup_typename (name
, (struct block
*) NULL
, 0);
1158 /* Lookup a structure type named "struct NAME",
1159 visible in lexical block BLOCK. */
1162 lookup_struct (char *name
, struct block
*block
)
1166 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1167 (struct symtab
**) NULL
);
1171 error (_("No struct type named %s."), name
);
1173 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1175 error (_("This context has class, union or enum %s, not a struct."), name
);
1177 return (SYMBOL_TYPE (sym
));
1180 /* Lookup a union type named "union NAME",
1181 visible in lexical block BLOCK. */
1184 lookup_union (char *name
, struct block
*block
)
1189 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1190 (struct symtab
**) NULL
);
1193 error (_("No union type named %s."), name
);
1195 t
= SYMBOL_TYPE (sym
);
1197 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1200 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1201 * a further "declared_type" field to discover it is really a union.
1203 if (HAVE_CPLUS_STRUCT (t
))
1204 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1207 /* If we get here, it's not a union */
1208 error (_("This context has class, struct or enum %s, not a union."), name
);
1212 /* Lookup an enum type named "enum NAME",
1213 visible in lexical block BLOCK. */
1216 lookup_enum (char *name
, struct block
*block
)
1220 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1221 (struct symtab
**) NULL
);
1224 error (_("No enum type named %s."), name
);
1226 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1228 error (_("This context has class, struct or union %s, not an enum."), name
);
1230 return (SYMBOL_TYPE (sym
));
1233 /* Lookup a template type named "template NAME<TYPE>",
1234 visible in lexical block BLOCK. */
1237 lookup_template_type (char *name
, struct type
*type
, struct block
*block
)
1240 char *nam
= (char *) alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1243 strcat (nam
, TYPE_NAME (type
));
1244 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1246 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1250 error (_("No template type named %s."), name
);
1252 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1254 error (_("This context has class, union or enum %s, not a struct."), name
);
1256 return (SYMBOL_TYPE (sym
));
1259 /* Given a type TYPE, lookup the type of the component of type named NAME.
1261 TYPE can be either a struct or union, or a pointer or reference to a struct or
1262 union. If it is a pointer or reference, its target type is automatically used.
1263 Thus '.' and '->' are interchangable, as specified for the definitions of the
1264 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1266 If NOERR is nonzero, return zero if NAME is not suitably defined.
1267 If NAME is the name of a baseclass type, return that type. */
1270 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1276 CHECK_TYPEDEF (type
);
1277 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1278 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1280 type
= TYPE_TARGET_TYPE (type
);
1283 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
1284 TYPE_CODE (type
) != TYPE_CODE_UNION
)
1286 target_terminal_ours ();
1287 gdb_flush (gdb_stdout
);
1288 fprintf_unfiltered (gdb_stderr
, "Type ");
1289 type_print (type
, "", gdb_stderr
, -1);
1290 error (_(" is not a structure or union type."));
1294 /* FIXME: This change put in by Michael seems incorrect for the case where
1295 the structure tag name is the same as the member name. I.E. when doing
1296 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1301 typename
= type_name_no_tag (type
);
1302 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1307 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1309 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1311 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1313 return TYPE_FIELD_TYPE (type
, i
);
1317 /* OK, it's not in this class. Recursively check the baseclasses. */
1318 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1322 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1334 target_terminal_ours ();
1335 gdb_flush (gdb_stdout
);
1336 fprintf_unfiltered (gdb_stderr
, "Type ");
1337 type_print (type
, "", gdb_stderr
, -1);
1338 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1339 fputs_filtered (name
, gdb_stderr
);
1341 return (struct type
*) -1; /* For lint */
1344 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1345 valid. Callers should be aware that in some cases (for example,
1346 the type or one of its baseclasses is a stub type and we are
1347 debugging a .o file), this function will not be able to find the virtual
1348 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1349 will remain NULL. */
1352 fill_in_vptr_fieldno (struct type
*type
)
1354 CHECK_TYPEDEF (type
);
1356 if (TYPE_VPTR_FIELDNO (type
) < 0)
1360 /* We must start at zero in case the first (and only) baseclass is
1361 virtual (and hence we cannot share the table pointer). */
1362 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1364 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1365 fill_in_vptr_fieldno (baseclass
);
1366 if (TYPE_VPTR_FIELDNO (baseclass
) >= 0)
1368 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (baseclass
);
1369 TYPE_VPTR_BASETYPE (type
) = TYPE_VPTR_BASETYPE (baseclass
);
1376 /* Find the method and field indices for the destructor in class type T.
1377 Return 1 if the destructor was found, otherwise, return 0. */
1380 get_destructor_fn_field (struct type
*t
, int *method_indexp
, int *field_indexp
)
1384 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1387 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1389 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1391 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1403 stub_noname_complaint (void)
1405 complaint (&symfile_complaints
, _("stub type has NULL name"));
1408 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1410 If this is a stubbed struct (i.e. declared as struct foo *), see if
1411 we can find a full definition in some other file. If so, copy this
1412 definition, so we can use it in future. There used to be a comment (but
1413 not any code) that if we don't find a full definition, we'd set a flag
1414 so we don't spend time in the future checking the same type. That would
1415 be a mistake, though--we might load in more symbols which contain a
1416 full definition for the type.
1418 This used to be coded as a macro, but I don't think it is called
1419 often enough to merit such treatment. */
1421 /* Find the real type of TYPE. This function returns the real type, after
1422 removing all layers of typedefs and completing opaque or stub types.
1423 Completion changes the TYPE argument, but stripping of typedefs does
1427 check_typedef (struct type
*type
)
1429 struct type
*orig_type
= type
;
1430 int is_const
, is_volatile
;
1432 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1434 if (!TYPE_TARGET_TYPE (type
))
1439 /* It is dangerous to call lookup_symbol if we are currently
1440 reading a symtab. Infinite recursion is one danger. */
1441 if (currently_reading_symtab
)
1444 name
= type_name_no_tag (type
);
1445 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1446 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1447 as appropriate? (this code was written before TYPE_NAME and
1448 TYPE_TAG_NAME were separate). */
1451 stub_noname_complaint ();
1454 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0,
1455 (struct symtab
**) NULL
);
1457 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1459 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1461 type
= TYPE_TARGET_TYPE (type
);
1464 is_const
= TYPE_CONST (type
);
1465 is_volatile
= TYPE_VOLATILE (type
);
1467 /* If this is a struct/class/union with no fields, then check whether a
1468 full definition exists somewhere else. This is for systems where a
1469 type definition with no fields is issued for such types, instead of
1470 identifying them as stub types in the first place */
1472 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1474 char *name
= type_name_no_tag (type
);
1475 struct type
*newtype
;
1478 stub_noname_complaint ();
1481 newtype
= lookup_transparent_type (name
);
1485 /* If the resolved type and the stub are in the same objfile,
1486 then replace the stub type with the real deal. But if
1487 they're in separate objfiles, leave the stub alone; we'll
1488 just look up the transparent type every time we call
1489 check_typedef. We can't create pointers between types
1490 allocated to different objfiles, since they may have
1491 different lifetimes. Trying to copy NEWTYPE over to TYPE's
1492 objfile is pointless, too, since you'll have to move over any
1493 other types NEWTYPE refers to, which could be an unbounded
1495 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1496 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1501 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1502 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1504 char *name
= type_name_no_tag (type
);
1505 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1506 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1507 as appropriate? (this code was written before TYPE_NAME and
1508 TYPE_TAG_NAME were separate). */
1512 stub_noname_complaint ();
1515 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0, (struct symtab
**) NULL
);
1517 make_cv_type (is_const
, is_volatile
, SYMBOL_TYPE (sym
), &type
);
1520 if (TYPE_TARGET_STUB (type
))
1522 struct type
*range_type
;
1523 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1525 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1528 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1529 && TYPE_NFIELDS (type
) == 1
1530 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1531 == TYPE_CODE_RANGE
))
1533 /* Now recompute the length of the array type, based on its
1534 number of elements and the target type's length. */
1535 TYPE_LENGTH (type
) =
1536 ((TYPE_FIELD_BITPOS (range_type
, 1)
1537 - TYPE_FIELD_BITPOS (range_type
, 0)
1539 * TYPE_LENGTH (target_type
));
1540 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1542 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1544 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1545 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1548 /* Cache TYPE_LENGTH for future use. */
1549 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1553 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1554 silently return builtin_type_void. */
1556 static struct type
*
1557 safe_parse_type (char *p
, int length
)
1559 struct ui_file
*saved_gdb_stderr
;
1562 /* Suppress error messages. */
1563 saved_gdb_stderr
= gdb_stderr
;
1564 gdb_stderr
= ui_file_new ();
1566 /* Call parse_and_eval_type() without fear of longjmp()s. */
1567 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1568 type
= builtin_type_void
;
1570 /* Stop suppressing error messages. */
1571 ui_file_delete (gdb_stderr
);
1572 gdb_stderr
= saved_gdb_stderr
;
1577 /* Ugly hack to convert method stubs into method types.
1579 He ain't kiddin'. This demangles the name of the method into a string
1580 including argument types, parses out each argument type, generates
1581 a string casting a zero to that type, evaluates the string, and stuffs
1582 the resulting type into an argtype vector!!! Then it knows the type
1583 of the whole function (including argument types for overloading),
1584 which info used to be in the stab's but was removed to hack back
1585 the space required for them. */
1588 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1591 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1592 char *demangled_name
= cplus_demangle (mangled_name
,
1593 DMGL_PARAMS
| DMGL_ANSI
);
1594 char *argtypetext
, *p
;
1595 int depth
= 0, argcount
= 1;
1596 struct field
*argtypes
;
1599 /* Make sure we got back a function string that we can use. */
1601 p
= strchr (demangled_name
, '(');
1605 if (demangled_name
== NULL
|| p
== NULL
)
1606 error (_("Internal: Cannot demangle mangled name `%s'."), mangled_name
);
1608 /* Now, read in the parameters that define this type. */
1613 if (*p
== '(' || *p
== '<')
1617 else if (*p
== ')' || *p
== '>')
1621 else if (*p
== ',' && depth
== 0)
1629 /* If we read one argument and it was ``void'', don't count it. */
1630 if (strncmp (argtypetext
, "(void)", 6) == 0)
1633 /* We need one extra slot, for the THIS pointer. */
1635 argtypes
= (struct field
*)
1636 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1639 /* Add THIS pointer for non-static methods. */
1640 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1641 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1645 argtypes
[0].type
= lookup_pointer_type (type
);
1649 if (*p
!= ')') /* () means no args, skip while */
1654 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1656 /* Avoid parsing of ellipsis, they will be handled below.
1657 Also avoid ``void'' as above. */
1658 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1659 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1661 argtypes
[argcount
].type
=
1662 safe_parse_type (argtypetext
, p
- argtypetext
);
1665 argtypetext
= p
+ 1;
1668 if (*p
== '(' || *p
== '<')
1672 else if (*p
== ')' || *p
== '>')
1681 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1683 /* Now update the old "stub" type into a real type. */
1684 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1685 TYPE_DOMAIN_TYPE (mtype
) = type
;
1686 TYPE_FIELDS (mtype
) = argtypes
;
1687 TYPE_NFIELDS (mtype
) = argcount
;
1688 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1689 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1691 TYPE_FLAGS (mtype
) |= TYPE_FLAG_VARARGS
;
1693 xfree (demangled_name
);
1696 /* This is the external interface to check_stub_method, above. This function
1697 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1698 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1699 and TYPE_FN_FIELDLIST_NAME will be correct.
1701 This function unfortunately can not die until stabs do. */
1704 check_stub_method_group (struct type
*type
, int method_id
)
1706 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1707 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1708 int j
, found_stub
= 0;
1710 for (j
= 0; j
< len
; j
++)
1711 if (TYPE_FN_FIELD_STUB (f
, j
))
1714 check_stub_method (type
, method_id
, j
);
1717 /* GNU v3 methods with incorrect names were corrected when we read in
1718 type information, because it was cheaper to do it then. The only GNU v2
1719 methods with incorrect method names are operators and destructors;
1720 destructors were also corrected when we read in type information.
1722 Therefore the only thing we need to handle here are v2 operator
1724 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1727 char dem_opname
[256];
1729 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1730 dem_opname
, DMGL_ANSI
);
1732 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1735 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1739 const struct cplus_struct_type cplus_struct_default
;
1742 allocate_cplus_struct_type (struct type
*type
)
1744 if (!HAVE_CPLUS_STRUCT (type
))
1746 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1747 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1748 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1752 /* Helper function to initialize the standard scalar types.
1754 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1755 of the string pointed to by name in the objfile_obstack for that objfile,
1756 and initialize the type name to that copy. There are places (mipsread.c
1757 in particular, where init_type is called with a NULL value for NAME). */
1760 init_type (enum type_code code
, int length
, int flags
, char *name
,
1761 struct objfile
*objfile
)
1765 type
= alloc_type (objfile
);
1766 TYPE_CODE (type
) = code
;
1767 TYPE_LENGTH (type
) = length
;
1768 TYPE_FLAGS (type
) |= flags
;
1769 if ((name
!= NULL
) && (objfile
!= NULL
))
1772 obsavestring (name
, strlen (name
), &objfile
->objfile_obstack
);
1776 TYPE_NAME (type
) = name
;
1781 if (name
&& strcmp (name
, "char") == 0)
1782 TYPE_FLAGS (type
) |= TYPE_FLAG_NOSIGN
;
1784 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
1785 || code
== TYPE_CODE_NAMESPACE
)
1787 INIT_CPLUS_SPECIFIC (type
);
1792 /* Helper function. Create an empty composite type. */
1795 init_composite_type (char *name
, enum type_code code
)
1798 gdb_assert (code
== TYPE_CODE_STRUCT
1799 || code
== TYPE_CODE_UNION
);
1800 t
= init_type (code
, 0, 0, NULL
, NULL
);
1801 TYPE_TAG_NAME (t
) = name
;
1805 /* Helper function. Append a field to a composite type. */
1808 append_composite_type_field (struct type
*t
, char *name
, struct type
*field
)
1811 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
1812 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
1813 sizeof (struct field
) * TYPE_NFIELDS (t
));
1814 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
1815 memset (f
, 0, sizeof f
[0]);
1816 FIELD_TYPE (f
[0]) = field
;
1817 FIELD_NAME (f
[0]) = name
;
1818 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1820 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
1821 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
1823 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
1825 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
1826 if (TYPE_NFIELDS (t
) > 1)
1828 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
1829 + TYPE_LENGTH (field
) * TARGET_CHAR_BIT
);
1834 /* Look up a fundamental type for the specified objfile.
1835 May need to construct such a type if this is the first use.
1837 Some object file formats (ELF, COFF, etc) do not define fundamental
1838 types such as "int" or "double". Others (stabs for example), do
1839 define fundamental types.
1841 For the formats which don't provide fundamental types, gdb can create
1842 such types, using defaults reasonable for the current language and
1843 the current target machine.
1845 NOTE: This routine is obsolescent. Each debugging format reader
1846 should manage it's own fundamental types, either creating them from
1847 suitable defaults or reading them from the debugging information,
1848 whichever is appropriate. The DWARF reader has already been
1849 fixed to do this. Once the other readers are fixed, this routine
1850 will go away. Also note that fundamental types should be managed
1851 on a compilation unit basis in a multi-language environment, not
1852 on a linkage unit basis as is done here. */
1856 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1858 struct type
**typep
;
1861 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1863 error (_("internal error - invalid fundamental type id %d"), typeid);
1866 /* If this is the first time we need a fundamental type for this objfile
1867 then we need to initialize the vector of type pointers. */
1869 if (objfile
->fundamental_types
== NULL
)
1871 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1872 objfile
->fundamental_types
= (struct type
**)
1873 obstack_alloc (&objfile
->objfile_obstack
, nbytes
);
1874 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1875 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1878 /* Look for this particular type in the fundamental type vector. If one is
1879 not found, create and install one appropriate for the current language. */
1881 typep
= objfile
->fundamental_types
+ typeid;
1884 *typep
= create_fundamental_type (objfile
, typeid);
1891 can_dereference (struct type
*t
)
1893 /* FIXME: Should we return true for references as well as pointers? */
1897 && TYPE_CODE (t
) == TYPE_CODE_PTR
1898 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1902 is_integral_type (struct type
*t
)
1907 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1908 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1909 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
1910 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1911 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1912 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1915 /* Check whether BASE is an ancestor or base class or DCLASS
1916 Return 1 if so, and 0 if not.
1917 Note: callers may want to check for identity of the types before
1918 calling this function -- identical types are considered to satisfy
1919 the ancestor relationship even if they're identical */
1922 is_ancestor (struct type
*base
, struct type
*dclass
)
1926 CHECK_TYPEDEF (base
);
1927 CHECK_TYPEDEF (dclass
);
1931 if (TYPE_NAME (base
) && TYPE_NAME (dclass
) &&
1932 !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1935 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1936 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1944 /* See whether DCLASS has a virtual table. This routine is aimed at
1945 the HP/Taligent ANSI C++ runtime model, and may not work with other
1946 runtime models. Return 1 => Yes, 0 => No. */
1949 has_vtable (struct type
*dclass
)
1951 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1952 has virtual functions or virtual bases. */
1956 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1959 /* First check for the presence of virtual bases */
1960 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1961 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1962 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
1965 /* Next check for virtual functions */
1966 if (TYPE_FN_FIELDLISTS (dclass
))
1967 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
1968 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
1971 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1972 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1973 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1974 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
1975 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
1978 /* Well, maybe we don't need a virtual table */
1982 /* Return a pointer to the "primary base class" of DCLASS.
1984 A NULL return indicates that DCLASS has no primary base, or that it
1985 couldn't be found (insufficient information).
1987 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1988 and may not work with other runtime models. */
1991 primary_base_class (struct type
*dclass
)
1993 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1994 is the first directly inherited, non-virtual base class that
1995 requires a virtual table */
1999 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
2002 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2003 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
2004 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
2005 return TYPE_FIELD_TYPE (dclass
, i
);
2010 /* Global manipulated by virtual_base_list[_aux]() */
2012 static struct vbase
*current_vbase_list
= NULL
;
2014 /* Return a pointer to a null-terminated list of struct vbase
2015 items. The vbasetype pointer of each item in the list points to the
2016 type information for a virtual base of the argument DCLASS.
2018 Helper function for virtual_base_list().
2019 Note: the list goes backward, right-to-left. virtual_base_list()
2020 copies the items out in reverse order. */
2023 virtual_base_list_aux (struct type
*dclass
)
2025 struct vbase
*tmp_vbase
;
2028 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
2031 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2033 /* Recurse on this ancestor, first */
2034 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
2036 /* If this current base is itself virtual, add it to the list */
2037 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
2039 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
2041 /* Check if base already recorded */
2042 tmp_vbase
= current_vbase_list
;
2045 if (tmp_vbase
->vbasetype
== basetype
)
2046 break; /* found it */
2047 tmp_vbase
= tmp_vbase
->next
;
2050 if (!tmp_vbase
) /* normal exit from loop */
2052 /* Allocate new item for this virtual base */
2053 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
2055 /* Stick it on at the end of the list */
2056 tmp_vbase
->vbasetype
= basetype
;
2057 tmp_vbase
->next
= current_vbase_list
;
2058 current_vbase_list
= tmp_vbase
;
2061 } /* for loop over bases */
2065 /* Compute the list of virtual bases in the right order. Virtual
2066 bases are laid out in the object's memory area in order of their
2067 occurrence in a depth-first, left-to-right search through the
2070 Argument DCLASS is the type whose virtual bases are required.
2071 Return value is the address of a null-terminated array of pointers
2072 to struct type items.
2074 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2075 and may not work with other runtime models.
2077 This routine merely hands off the argument to virtual_base_list_aux()
2078 and then copies the result into an array to save space. */
2081 virtual_base_list (struct type
*dclass
)
2083 struct vbase
*tmp_vbase
;
2084 struct vbase
*tmp_vbase_2
;
2087 struct type
**vbase_array
;
2089 current_vbase_list
= NULL
;
2090 virtual_base_list_aux (dclass
);
2092 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2097 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
2099 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
2100 vbase_array
[i
] = tmp_vbase
->vbasetype
;
2102 /* Get rid of constructed chain */
2103 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
2106 tmp_vbase
= tmp_vbase
->next
;
2107 xfree (tmp_vbase_2
);
2108 tmp_vbase_2
= tmp_vbase
;
2111 vbase_array
[count
] = NULL
;
2115 /* Return the length of the virtual base list of the type DCLASS. */
2118 virtual_base_list_length (struct type
*dclass
)
2121 struct vbase
*tmp_vbase
;
2123 current_vbase_list
= NULL
;
2124 virtual_base_list_aux (dclass
);
2126 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2131 /* Return the number of elements of the virtual base list of the type
2132 DCLASS, ignoring those appearing in the primary base (and its
2133 primary base, recursively). */
2136 virtual_base_list_length_skip_primaries (struct type
*dclass
)
2139 struct vbase
*tmp_vbase
;
2140 struct type
*primary
;
2142 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2145 return virtual_base_list_length (dclass
);
2147 current_vbase_list
= NULL
;
2148 virtual_base_list_aux (dclass
);
2150 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
2152 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
2160 /* Return the index (position) of type BASE, which is a virtual base
2161 class of DCLASS, in the latter's virtual base list. A return of -1
2162 indicates "not found" or a problem. */
2165 virtual_base_index (struct type
*base
, struct type
*dclass
)
2170 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2171 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2175 vbase
= virtual_base_list (dclass
)[0];
2180 vbase
= virtual_base_list (dclass
)[++i
];
2183 return vbase
? i
: -1;
2188 /* Return the index (position) of type BASE, which is a virtual base
2189 class of DCLASS, in the latter's virtual base list. Skip over all
2190 bases that may appear in the virtual base list of the primary base
2191 class of DCLASS (recursively). A return of -1 indicates "not
2192 found" or a problem. */
2195 virtual_base_index_skip_primaries (struct type
*base
, struct type
*dclass
)
2199 struct type
*primary
;
2201 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2202 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2205 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2209 vbase
= virtual_base_list (dclass
)[0];
2212 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
2216 vbase
= virtual_base_list (dclass
)[++i
];
2219 return vbase
? j
: -1;
2222 /* Return position of a derived class DCLASS in the list of
2223 * primary bases starting with the remotest ancestor.
2224 * Position returned is 0-based. */
2227 class_index_in_primary_list (struct type
*dclass
)
2229 struct type
*pbc
; /* primary base class */
2231 /* Simply recurse on primary base */
2232 pbc
= TYPE_PRIMARY_BASE (dclass
);
2234 return 1 + class_index_in_primary_list (pbc
);
2239 /* Return a count of the number of virtual functions a type has.
2240 * This includes all the virtual functions it inherits from its
2244 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2245 * functions only once (latest redefinition)
2249 count_virtual_fns (struct type
*dclass
)
2251 int fn
, oi
; /* function and overloaded instance indices */
2252 int vfuncs
; /* count to return */
2254 /* recurse on bases that can share virtual table */
2255 struct type
*pbc
= primary_base_class (dclass
);
2257 vfuncs
= count_virtual_fns (pbc
);
2261 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2262 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2263 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2271 /* Functions for overload resolution begin here */
2273 /* Compare two badness vectors A and B and return the result.
2274 * 0 => A and B are identical
2275 * 1 => A and B are incomparable
2276 * 2 => A is better than B
2277 * 3 => A is worse than B */
2280 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2284 short found_pos
= 0; /* any positives in c? */
2285 short found_neg
= 0; /* any negatives in c? */
2287 /* differing lengths => incomparable */
2288 if (a
->length
!= b
->length
)
2291 /* Subtract b from a */
2292 for (i
= 0; i
< a
->length
; i
++)
2294 tmp
= a
->rank
[i
] - b
->rank
[i
];
2304 return 1; /* incomparable */
2306 return 3; /* A > B */
2312 return 2; /* A < B */
2314 return 0; /* A == B */
2318 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2319 * to the types of an argument list (ARGS, length NARGS).
2320 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2322 struct badness_vector
*
2323 rank_function (struct type
**parms
, int nparms
, struct type
**args
, int nargs
)
2326 struct badness_vector
*bv
;
2327 int min_len
= nparms
< nargs
? nparms
: nargs
;
2329 bv
= xmalloc (sizeof (struct badness_vector
));
2330 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2331 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2333 /* First compare the lengths of the supplied lists.
2334 * If there is a mismatch, set it to a high value. */
2336 /* pai/1997-06-03 FIXME: when we have debug info about default
2337 * arguments and ellipsis parameter lists, we should consider those
2338 * and rank the length-match more finely. */
2340 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2342 /* Now rank all the parameters of the candidate function */
2343 for (i
= 1; i
<= min_len
; i
++)
2344 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2346 /* If more arguments than parameters, add dummy entries */
2347 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2348 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2353 /* Compare the names of two integer types, assuming that any sign
2354 qualifiers have been checked already. We do it this way because
2355 there may be an "int" in the name of one of the types. */
2358 integer_types_same_name_p (const char *first
, const char *second
)
2360 int first_p
, second_p
;
2362 /* If both are shorts, return 1; if neither is a short, keep checking. */
2363 first_p
= (strstr (first
, "short") != NULL
);
2364 second_p
= (strstr (second
, "short") != NULL
);
2365 if (first_p
&& second_p
)
2367 if (first_p
|| second_p
)
2370 /* Likewise for long. */
2371 first_p
= (strstr (first
, "long") != NULL
);
2372 second_p
= (strstr (second
, "long") != NULL
);
2373 if (first_p
&& second_p
)
2375 if (first_p
|| second_p
)
2378 /* Likewise for char. */
2379 first_p
= (strstr (first
, "char") != NULL
);
2380 second_p
= (strstr (second
, "char") != NULL
);
2381 if (first_p
&& second_p
)
2383 if (first_p
|| second_p
)
2386 /* They must both be ints. */
2390 /* Compare one type (PARM) for compatibility with another (ARG).
2391 * PARM is intended to be the parameter type of a function; and
2392 * ARG is the supplied argument's type. This function tests if
2393 * the latter can be converted to the former.
2395 * Return 0 if they are identical types;
2396 * Otherwise, return an integer which corresponds to how compatible
2397 * PARM is to ARG. The higher the return value, the worse the match.
2398 * Generally the "bad" conversions are all uniformly assigned a 100 */
2401 rank_one_type (struct type
*parm
, struct type
*arg
)
2403 /* Identical type pointers */
2404 /* However, this still doesn't catch all cases of same type for arg
2405 * and param. The reason is that builtin types are different from
2406 * the same ones constructed from the object. */
2410 /* Resolve typedefs */
2411 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2412 parm
= check_typedef (parm
);
2413 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2414 arg
= check_typedef (arg
);
2417 Well, damnit, if the names are exactly the same,
2418 i'll say they are exactly the same. This happens when we generate
2419 method stubs. The types won't point to the same address, but they
2420 really are the same.
2423 if (TYPE_NAME (parm
) && TYPE_NAME (arg
) &&
2424 !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2427 /* Check if identical after resolving typedefs */
2431 /* See through references, since we can almost make non-references
2433 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2434 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2435 + REFERENCE_CONVERSION_BADNESS
);
2436 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2437 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2438 + REFERENCE_CONVERSION_BADNESS
);
2440 /* Debugging only. */
2441 fprintf_filtered (gdb_stderr
,"------ Arg is %s [%d], parm is %s [%d]\n",
2442 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2444 /* x -> y means arg of type x being supplied for parameter of type y */
2446 switch (TYPE_CODE (parm
))
2449 switch (TYPE_CODE (arg
))
2452 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2453 return VOID_PTR_CONVERSION_BADNESS
;
2455 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2456 case TYPE_CODE_ARRAY
:
2457 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2458 case TYPE_CODE_FUNC
:
2459 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2461 case TYPE_CODE_ENUM
:
2462 case TYPE_CODE_FLAGS
:
2463 case TYPE_CODE_CHAR
:
2464 case TYPE_CODE_RANGE
:
2465 case TYPE_CODE_BOOL
:
2466 return POINTER_CONVERSION_BADNESS
;
2468 return INCOMPATIBLE_TYPE_BADNESS
;
2470 case TYPE_CODE_ARRAY
:
2471 switch (TYPE_CODE (arg
))
2474 case TYPE_CODE_ARRAY
:
2475 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2477 return INCOMPATIBLE_TYPE_BADNESS
;
2479 case TYPE_CODE_FUNC
:
2480 switch (TYPE_CODE (arg
))
2482 case TYPE_CODE_PTR
: /* funcptr -> func */
2483 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2485 return INCOMPATIBLE_TYPE_BADNESS
;
2488 switch (TYPE_CODE (arg
))
2491 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2493 /* Deal with signed, unsigned, and plain chars and
2494 signed and unsigned ints */
2495 if (TYPE_NOSIGN (parm
))
2497 /* This case only for character types */
2498 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2501 return INTEGER_CONVERSION_BADNESS
; /* signed/unsigned char -> plain char */
2503 else if (TYPE_UNSIGNED (parm
))
2505 if (TYPE_UNSIGNED (arg
))
2507 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2508 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2510 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2511 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2512 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2514 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2518 if (integer_types_same_name_p (TYPE_NAME (arg
), "long")
2519 && integer_types_same_name_p (TYPE_NAME (parm
), "int"))
2520 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2522 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2525 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2527 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2529 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2530 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2531 return INTEGER_PROMOTION_BADNESS
;
2533 return INTEGER_CONVERSION_BADNESS
;
2536 return INTEGER_CONVERSION_BADNESS
;
2538 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2539 return INTEGER_PROMOTION_BADNESS
;
2541 return INTEGER_CONVERSION_BADNESS
;
2542 case TYPE_CODE_ENUM
:
2543 case TYPE_CODE_FLAGS
:
2544 case TYPE_CODE_CHAR
:
2545 case TYPE_CODE_RANGE
:
2546 case TYPE_CODE_BOOL
:
2547 return INTEGER_PROMOTION_BADNESS
;
2549 return INT_FLOAT_CONVERSION_BADNESS
;
2551 return NS_POINTER_CONVERSION_BADNESS
;
2553 return INCOMPATIBLE_TYPE_BADNESS
;
2556 case TYPE_CODE_ENUM
:
2557 switch (TYPE_CODE (arg
))
2560 case TYPE_CODE_CHAR
:
2561 case TYPE_CODE_RANGE
:
2562 case TYPE_CODE_BOOL
:
2563 case TYPE_CODE_ENUM
:
2564 return INTEGER_CONVERSION_BADNESS
;
2566 return INT_FLOAT_CONVERSION_BADNESS
;
2568 return INCOMPATIBLE_TYPE_BADNESS
;
2571 case TYPE_CODE_CHAR
:
2572 switch (TYPE_CODE (arg
))
2574 case TYPE_CODE_RANGE
:
2575 case TYPE_CODE_BOOL
:
2576 case TYPE_CODE_ENUM
:
2577 return INTEGER_CONVERSION_BADNESS
;
2579 return INT_FLOAT_CONVERSION_BADNESS
;
2581 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2582 return INTEGER_CONVERSION_BADNESS
;
2583 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2584 return INTEGER_PROMOTION_BADNESS
;
2585 /* >>> !! else fall through !! <<< */
2586 case TYPE_CODE_CHAR
:
2587 /* Deal with signed, unsigned, and plain chars for C++
2588 and with int cases falling through from previous case */
2589 if (TYPE_NOSIGN (parm
))
2591 if (TYPE_NOSIGN (arg
))
2594 return INTEGER_CONVERSION_BADNESS
;
2596 else if (TYPE_UNSIGNED (parm
))
2598 if (TYPE_UNSIGNED (arg
))
2601 return INTEGER_PROMOTION_BADNESS
;
2603 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2606 return INTEGER_CONVERSION_BADNESS
;
2608 return INCOMPATIBLE_TYPE_BADNESS
;
2611 case TYPE_CODE_RANGE
:
2612 switch (TYPE_CODE (arg
))
2615 case TYPE_CODE_CHAR
:
2616 case TYPE_CODE_RANGE
:
2617 case TYPE_CODE_BOOL
:
2618 case TYPE_CODE_ENUM
:
2619 return INTEGER_CONVERSION_BADNESS
;
2621 return INT_FLOAT_CONVERSION_BADNESS
;
2623 return INCOMPATIBLE_TYPE_BADNESS
;
2626 case TYPE_CODE_BOOL
:
2627 switch (TYPE_CODE (arg
))
2630 case TYPE_CODE_CHAR
:
2631 case TYPE_CODE_RANGE
:
2632 case TYPE_CODE_ENUM
:
2635 return BOOLEAN_CONVERSION_BADNESS
;
2636 case TYPE_CODE_BOOL
:
2639 return INCOMPATIBLE_TYPE_BADNESS
;
2643 switch (TYPE_CODE (arg
))
2646 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2647 return FLOAT_PROMOTION_BADNESS
;
2648 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2651 return FLOAT_CONVERSION_BADNESS
;
2653 case TYPE_CODE_BOOL
:
2654 case TYPE_CODE_ENUM
:
2655 case TYPE_CODE_RANGE
:
2656 case TYPE_CODE_CHAR
:
2657 return INT_FLOAT_CONVERSION_BADNESS
;
2659 return INCOMPATIBLE_TYPE_BADNESS
;
2662 case TYPE_CODE_COMPLEX
:
2663 switch (TYPE_CODE (arg
))
2664 { /* Strictly not needed for C++, but... */
2666 return FLOAT_PROMOTION_BADNESS
;
2667 case TYPE_CODE_COMPLEX
:
2670 return INCOMPATIBLE_TYPE_BADNESS
;
2673 case TYPE_CODE_STRUCT
:
2674 /* currently same as TYPE_CODE_CLASS */
2675 switch (TYPE_CODE (arg
))
2677 case TYPE_CODE_STRUCT
:
2678 /* Check for derivation */
2679 if (is_ancestor (parm
, arg
))
2680 return BASE_CONVERSION_BADNESS
;
2681 /* else fall through */
2683 return INCOMPATIBLE_TYPE_BADNESS
;
2686 case TYPE_CODE_UNION
:
2687 switch (TYPE_CODE (arg
))
2689 case TYPE_CODE_UNION
:
2691 return INCOMPATIBLE_TYPE_BADNESS
;
2694 case TYPE_CODE_MEMBERPTR
:
2695 switch (TYPE_CODE (arg
))
2698 return INCOMPATIBLE_TYPE_BADNESS
;
2701 case TYPE_CODE_METHOD
:
2702 switch (TYPE_CODE (arg
))
2706 return INCOMPATIBLE_TYPE_BADNESS
;
2710 switch (TYPE_CODE (arg
))
2714 return INCOMPATIBLE_TYPE_BADNESS
;
2719 switch (TYPE_CODE (arg
))
2723 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2725 return INCOMPATIBLE_TYPE_BADNESS
;
2728 case TYPE_CODE_VOID
:
2730 return INCOMPATIBLE_TYPE_BADNESS
;
2731 } /* switch (TYPE_CODE (arg)) */
2735 /* End of functions for overload resolution */
2738 print_bit_vector (B_TYPE
*bits
, int nbits
)
2742 for (bitno
= 0; bitno
< nbits
; bitno
++)
2744 if ((bitno
% 8) == 0)
2746 puts_filtered (" ");
2748 if (B_TST (bits
, bitno
))
2749 printf_filtered (("1"));
2751 printf_filtered (("0"));
2755 /* Note the first arg should be the "this" pointer, we may not want to
2756 include it since we may get into a infinitely recursive situation. */
2759 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2765 for (i
= 0; i
< nargs
; i
++)
2766 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2771 dump_fn_fieldlists (struct type
*type
, int spaces
)
2777 printfi_filtered (spaces
, "fn_fieldlists ");
2778 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2779 printf_filtered ("\n");
2780 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2782 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2783 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2785 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2786 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2788 printf_filtered (_(") length %d\n"),
2789 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2790 for (overload_idx
= 0;
2791 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2794 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2796 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2797 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2799 printf_filtered (")\n");
2800 printfi_filtered (spaces
+ 8, "type ");
2801 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2802 printf_filtered ("\n");
2804 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2807 printfi_filtered (spaces
+ 8, "args ");
2808 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2809 printf_filtered ("\n");
2811 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2812 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
, overload_idx
)),
2814 printfi_filtered (spaces
+ 8, "fcontext ");
2815 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2817 printf_filtered ("\n");
2819 printfi_filtered (spaces
+ 8, "is_const %d\n",
2820 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2821 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2822 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2823 printfi_filtered (spaces
+ 8, "is_private %d\n",
2824 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2825 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2826 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2827 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2828 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2829 printfi_filtered (spaces
+ 8, "voffset %u\n",
2830 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2836 print_cplus_stuff (struct type
*type
, int spaces
)
2838 printfi_filtered (spaces
, "n_baseclasses %d\n",
2839 TYPE_N_BASECLASSES (type
));
2840 printfi_filtered (spaces
, "nfn_fields %d\n",
2841 TYPE_NFN_FIELDS (type
));
2842 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2843 TYPE_NFN_FIELDS_TOTAL (type
));
2844 if (TYPE_N_BASECLASSES (type
) > 0)
2846 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2847 TYPE_N_BASECLASSES (type
));
2848 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2849 printf_filtered (")");
2851 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2852 TYPE_N_BASECLASSES (type
));
2853 puts_filtered ("\n");
2855 if (TYPE_NFIELDS (type
) > 0)
2857 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2859 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2860 TYPE_NFIELDS (type
));
2861 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2862 printf_filtered (")");
2863 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2864 TYPE_NFIELDS (type
));
2865 puts_filtered ("\n");
2867 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2869 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2870 TYPE_NFIELDS (type
));
2871 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2872 printf_filtered (")");
2873 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2874 TYPE_NFIELDS (type
));
2875 puts_filtered ("\n");
2878 if (TYPE_NFN_FIELDS (type
) > 0)
2880 dump_fn_fieldlists (type
, spaces
);
2885 print_bound_type (int bt
)
2889 case BOUND_CANNOT_BE_DETERMINED
:
2890 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2892 case BOUND_BY_REF_ON_STACK
:
2893 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2895 case BOUND_BY_VALUE_ON_STACK
:
2896 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2898 case BOUND_BY_REF_IN_REG
:
2899 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2901 case BOUND_BY_VALUE_IN_REG
:
2902 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2905 printf_filtered ("(BOUND_SIMPLE)");
2908 printf_filtered (_("(unknown bound type)"));
2913 static struct obstack dont_print_type_obstack
;
2916 recursive_dump_type (struct type
*type
, int spaces
)
2921 obstack_begin (&dont_print_type_obstack
, 0);
2923 if (TYPE_NFIELDS (type
) > 0
2924 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2926 struct type
**first_dont_print
2927 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2929 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
2934 if (type
== first_dont_print
[i
])
2936 printfi_filtered (spaces
, "type node ");
2937 gdb_print_host_address (type
, gdb_stdout
);
2938 printf_filtered (_(" <same as already seen type>\n"));
2943 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2946 printfi_filtered (spaces
, "type node ");
2947 gdb_print_host_address (type
, gdb_stdout
);
2948 printf_filtered ("\n");
2949 printfi_filtered (spaces
, "name '%s' (",
2950 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2951 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2952 printf_filtered (")\n");
2953 printfi_filtered (spaces
, "tagname '%s' (",
2954 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2955 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2956 printf_filtered (")\n");
2957 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2958 switch (TYPE_CODE (type
))
2960 case TYPE_CODE_UNDEF
:
2961 printf_filtered ("(TYPE_CODE_UNDEF)");
2964 printf_filtered ("(TYPE_CODE_PTR)");
2966 case TYPE_CODE_ARRAY
:
2967 printf_filtered ("(TYPE_CODE_ARRAY)");
2969 case TYPE_CODE_STRUCT
:
2970 printf_filtered ("(TYPE_CODE_STRUCT)");
2972 case TYPE_CODE_UNION
:
2973 printf_filtered ("(TYPE_CODE_UNION)");
2975 case TYPE_CODE_ENUM
:
2976 printf_filtered ("(TYPE_CODE_ENUM)");
2978 case TYPE_CODE_FLAGS
:
2979 printf_filtered ("(TYPE_CODE_FLAGS)");
2981 case TYPE_CODE_FUNC
:
2982 printf_filtered ("(TYPE_CODE_FUNC)");
2985 printf_filtered ("(TYPE_CODE_INT)");
2988 printf_filtered ("(TYPE_CODE_FLT)");
2990 case TYPE_CODE_VOID
:
2991 printf_filtered ("(TYPE_CODE_VOID)");
2994 printf_filtered ("(TYPE_CODE_SET)");
2996 case TYPE_CODE_RANGE
:
2997 printf_filtered ("(TYPE_CODE_RANGE)");
2999 case TYPE_CODE_STRING
:
3000 printf_filtered ("(TYPE_CODE_STRING)");
3002 case TYPE_CODE_BITSTRING
:
3003 printf_filtered ("(TYPE_CODE_BITSTRING)");
3005 case TYPE_CODE_ERROR
:
3006 printf_filtered ("(TYPE_CODE_ERROR)");
3008 case TYPE_CODE_MEMBERPTR
:
3009 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
3011 case TYPE_CODE_METHODPTR
:
3012 printf_filtered ("(TYPE_CODE_METHODPTR)");
3014 case TYPE_CODE_METHOD
:
3015 printf_filtered ("(TYPE_CODE_METHOD)");
3018 printf_filtered ("(TYPE_CODE_REF)");
3020 case TYPE_CODE_CHAR
:
3021 printf_filtered ("(TYPE_CODE_CHAR)");
3023 case TYPE_CODE_BOOL
:
3024 printf_filtered ("(TYPE_CODE_BOOL)");
3026 case TYPE_CODE_COMPLEX
:
3027 printf_filtered ("(TYPE_CODE_COMPLEX)");
3029 case TYPE_CODE_TYPEDEF
:
3030 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3032 case TYPE_CODE_TEMPLATE
:
3033 printf_filtered ("(TYPE_CODE_TEMPLATE)");
3035 case TYPE_CODE_TEMPLATE_ARG
:
3036 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
3038 case TYPE_CODE_NAMESPACE
:
3039 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3042 printf_filtered ("(UNKNOWN TYPE CODE)");
3045 puts_filtered ("\n");
3046 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
3047 printfi_filtered (spaces
, "upper_bound_type 0x%x ",
3048 TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3049 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3050 puts_filtered ("\n");
3051 printfi_filtered (spaces
, "lower_bound_type 0x%x ",
3052 TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3053 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3054 puts_filtered ("\n");
3055 printfi_filtered (spaces
, "objfile ");
3056 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
3057 printf_filtered ("\n");
3058 printfi_filtered (spaces
, "target_type ");
3059 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
3060 printf_filtered ("\n");
3061 if (TYPE_TARGET_TYPE (type
) != NULL
)
3063 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
3065 printfi_filtered (spaces
, "pointer_type ");
3066 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
3067 printf_filtered ("\n");
3068 printfi_filtered (spaces
, "reference_type ");
3069 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
3070 printf_filtered ("\n");
3071 printfi_filtered (spaces
, "type_chain ");
3072 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
3073 printf_filtered ("\n");
3074 printfi_filtered (spaces
, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type
));
3075 if (TYPE_CONST (type
))
3077 puts_filtered (" TYPE_FLAG_CONST");
3079 if (TYPE_VOLATILE (type
))
3081 puts_filtered (" TYPE_FLAG_VOLATILE");
3083 if (TYPE_CODE_SPACE (type
))
3085 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3087 if (TYPE_DATA_SPACE (type
))
3089 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3091 if (TYPE_ADDRESS_CLASS_1 (type
))
3093 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3095 if (TYPE_ADDRESS_CLASS_2 (type
))
3097 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3099 puts_filtered ("\n");
3100 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
3101 if (TYPE_UNSIGNED (type
))
3103 puts_filtered (" TYPE_FLAG_UNSIGNED");
3105 if (TYPE_NOSIGN (type
))
3107 puts_filtered (" TYPE_FLAG_NOSIGN");
3109 if (TYPE_STUB (type
))
3111 puts_filtered (" TYPE_FLAG_STUB");
3113 if (TYPE_TARGET_STUB (type
))
3115 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3117 if (TYPE_STATIC (type
))
3119 puts_filtered (" TYPE_FLAG_STATIC");
3121 if (TYPE_PROTOTYPED (type
))
3123 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3125 if (TYPE_INCOMPLETE (type
))
3127 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3129 if (TYPE_VARARGS (type
))
3131 puts_filtered (" TYPE_FLAG_VARARGS");
3133 /* This is used for things like AltiVec registers on ppc. Gcc emits
3134 an attribute for the array type, which tells whether or not we
3135 have a vector, instead of a regular array. */
3136 if (TYPE_VECTOR (type
))
3138 puts_filtered (" TYPE_FLAG_VECTOR");
3140 puts_filtered ("\n");
3141 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
3142 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
3143 puts_filtered ("\n");
3144 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
3146 printfi_filtered (spaces
+ 2,
3147 "[%d] bitpos %d bitsize %d type ",
3148 idx
, TYPE_FIELD_BITPOS (type
, idx
),
3149 TYPE_FIELD_BITSIZE (type
, idx
));
3150 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
3151 printf_filtered (" name '%s' (",
3152 TYPE_FIELD_NAME (type
, idx
) != NULL
3153 ? TYPE_FIELD_NAME (type
, idx
)
3155 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
3156 printf_filtered (")\n");
3157 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
3159 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
3162 printfi_filtered (spaces
, "vptr_basetype ");
3163 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
3164 puts_filtered ("\n");
3165 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
3167 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
3169 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
3170 switch (TYPE_CODE (type
))
3172 case TYPE_CODE_STRUCT
:
3173 printfi_filtered (spaces
, "cplus_stuff ");
3174 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3175 puts_filtered ("\n");
3176 print_cplus_stuff (type
, spaces
);
3180 printfi_filtered (spaces
, "floatformat ");
3181 if (TYPE_FLOATFORMAT (type
) == NULL
)
3182 puts_filtered ("(null)");
3185 puts_filtered ("{ ");
3186 if (TYPE_FLOATFORMAT (type
)[0] == NULL
3187 || TYPE_FLOATFORMAT (type
)[0]->name
== NULL
)
3188 puts_filtered ("(null)");
3190 puts_filtered (TYPE_FLOATFORMAT (type
)[0]->name
);
3192 puts_filtered (", ");
3193 if (TYPE_FLOATFORMAT (type
)[1] == NULL
3194 || TYPE_FLOATFORMAT (type
)[1]->name
== NULL
)
3195 puts_filtered ("(null)");
3197 puts_filtered (TYPE_FLOATFORMAT (type
)[1]->name
);
3199 puts_filtered (" }");
3201 puts_filtered ("\n");
3205 /* We have to pick one of the union types to be able print and test
3206 the value. Pick cplus_struct_type, even though we know it isn't
3207 any particular one. */
3208 printfi_filtered (spaces
, "type_specific ");
3209 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3210 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
3212 printf_filtered (_(" (unknown data form)"));
3214 printf_filtered ("\n");
3219 obstack_free (&dont_print_type_obstack
, NULL
);
3222 /* Trivial helpers for the libiberty hash table, for mapping one
3227 struct type
*old
, *new;
3231 type_pair_hash (const void *item
)
3233 const struct type_pair
*pair
= item
;
3234 return htab_hash_pointer (pair
->old
);
3238 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
3240 const struct type_pair
*lhs
= item_lhs
, *rhs
= item_rhs
;
3241 return lhs
->old
== rhs
->old
;
3244 /* Allocate the hash table used by copy_type_recursive to walk
3245 types without duplicates. We use OBJFILE's obstack, because
3246 OBJFILE is about to be deleted. */
3249 create_copied_types_hash (struct objfile
*objfile
)
3251 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
3252 NULL
, &objfile
->objfile_obstack
,
3253 hashtab_obstack_allocate
,
3254 dummy_obstack_deallocate
);
3257 /* Recursively copy (deep copy) TYPE, if it is associated with OBJFILE.
3258 Return a new type allocated using malloc, a saved type if we have already
3259 visited TYPE (using COPIED_TYPES), or TYPE if it is not associated with
3263 copy_type_recursive (struct objfile
*objfile
, struct type
*type
,
3264 htab_t copied_types
)
3266 struct type_pair
*stored
, pair
;
3268 struct type
*new_type
;
3270 if (TYPE_OBJFILE (type
) == NULL
)
3273 /* This type shouldn't be pointing to any types in other objfiles; if
3274 it did, the type might disappear unexpectedly. */
3275 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
3278 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
3280 return ((struct type_pair
*) *slot
)->new;
3282 new_type
= alloc_type (NULL
);
3284 /* We must add the new type to the hash table immediately, in case
3285 we encounter this type again during a recursive call below. */
3286 stored
= xmalloc (sizeof (struct type_pair
));
3288 stored
->new = new_type
;
3291 /* Copy the common fields of types. */
3292 TYPE_CODE (new_type
) = TYPE_CODE (type
);
3293 TYPE_ARRAY_UPPER_BOUND_TYPE (new_type
) = TYPE_ARRAY_UPPER_BOUND_TYPE (type
);
3294 TYPE_ARRAY_LOWER_BOUND_TYPE (new_type
) = TYPE_ARRAY_LOWER_BOUND_TYPE (type
);
3295 if (TYPE_NAME (type
))
3296 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
3297 if (TYPE_TAG_NAME (type
))
3298 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
3299 TYPE_FLAGS (new_type
) = TYPE_FLAGS (type
);
3300 TYPE_VPTR_FIELDNO (new_type
) = TYPE_VPTR_FIELDNO (type
);
3302 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
3303 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
3305 /* Copy the fields. */
3306 TYPE_NFIELDS (new_type
) = TYPE_NFIELDS (type
);
3307 if (TYPE_NFIELDS (type
))
3311 nfields
= TYPE_NFIELDS (type
);
3312 TYPE_FIELDS (new_type
) = xmalloc (sizeof (struct field
) * nfields
);
3313 for (i
= 0; i
< nfields
; i
++)
3315 TYPE_FIELD_ARTIFICIAL (new_type
, i
) = TYPE_FIELD_ARTIFICIAL (type
, i
);
3316 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
3317 if (TYPE_FIELD_TYPE (type
, i
))
3318 TYPE_FIELD_TYPE (new_type
, i
)
3319 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
3321 if (TYPE_FIELD_NAME (type
, i
))
3322 TYPE_FIELD_NAME (new_type
, i
) = xstrdup (TYPE_FIELD_NAME (type
, i
));
3323 if (TYPE_FIELD_STATIC_HAS_ADDR (type
, i
))
3324 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
3325 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
3326 else if (TYPE_FIELD_STATIC (type
, i
))
3327 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
3328 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
, i
)));
3331 TYPE_FIELD_BITPOS (new_type
, i
) = TYPE_FIELD_BITPOS (type
, i
);
3332 TYPE_FIELD_STATIC_KIND (new_type
, i
) = 0;
3337 /* Copy pointers to other types. */
3338 if (TYPE_TARGET_TYPE (type
))
3339 TYPE_TARGET_TYPE (new_type
) = copy_type_recursive (objfile
,
3340 TYPE_TARGET_TYPE (type
),
3342 if (TYPE_VPTR_BASETYPE (type
))
3343 TYPE_VPTR_BASETYPE (new_type
) = copy_type_recursive (objfile
,
3344 TYPE_VPTR_BASETYPE (type
),
3346 /* Maybe copy the type_specific bits.
3348 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3349 base classes and methods. There's no fundamental reason why we
3350 can't, but at the moment it is not needed. */
3352 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
3353 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
3354 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3355 || TYPE_CODE (type
) == TYPE_CODE_UNION
3356 || TYPE_CODE (type
) == TYPE_CODE_TEMPLATE
3357 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
3358 INIT_CPLUS_SPECIFIC (new_type
);
3363 static struct type
*
3364 build_flt (int bit
, char *name
, const struct floatformat
**floatformats
)
3370 gdb_assert (floatformats
!= NULL
);
3371 gdb_assert (floatformats
[0] != NULL
&& floatformats
[1] != NULL
);
3372 bit
= floatformats
[0]->totalsize
;
3374 gdb_assert (bit
>= 0);
3376 t
= init_type (TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
, 0, name
, NULL
);
3377 TYPE_FLOATFORMAT (t
) = floatformats
;
3382 build_gdbtypes (void)
3385 init_type (TYPE_CODE_VOID
, 1,
3387 "void", (struct objfile
*) NULL
);
3389 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3391 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3392 "char", (struct objfile
*) NULL
);
3393 builtin_type_true_char
=
3394 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3396 "true character", (struct objfile
*) NULL
);
3397 builtin_type_signed_char
=
3398 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3400 "signed char", (struct objfile
*) NULL
);
3401 builtin_type_unsigned_char
=
3402 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3404 "unsigned char", (struct objfile
*) NULL
);
3405 builtin_type_short
=
3406 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3408 "short", (struct objfile
*) NULL
);
3409 builtin_type_unsigned_short
=
3410 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3412 "unsigned short", (struct objfile
*) NULL
);
3414 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3416 "int", (struct objfile
*) NULL
);
3417 builtin_type_unsigned_int
=
3418 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3420 "unsigned int", (struct objfile
*) NULL
);
3422 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3424 "long", (struct objfile
*) NULL
);
3425 builtin_type_unsigned_long
=
3426 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3428 "unsigned long", (struct objfile
*) NULL
);
3429 builtin_type_long_long
=
3430 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3432 "long long", (struct objfile
*) NULL
);
3433 builtin_type_unsigned_long_long
=
3434 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3436 "unsigned long long", (struct objfile
*) NULL
);
3438 builtin_type_float
= build_flt (TARGET_FLOAT_BIT
, "float",
3439 TARGET_FLOAT_FORMAT
);
3440 builtin_type_double
= build_flt (TARGET_DOUBLE_BIT
, "double",
3441 TARGET_DOUBLE_FORMAT
);
3442 builtin_type_long_double
= build_flt (TARGET_LONG_DOUBLE_BIT
, "long double",
3443 TARGET_LONG_DOUBLE_FORMAT
);
3445 builtin_type_complex
=
3446 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3448 "complex", (struct objfile
*) NULL
);
3449 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
3450 builtin_type_double_complex
=
3451 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3453 "double complex", (struct objfile
*) NULL
);
3454 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
3455 builtin_type_string
=
3456 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3458 "string", (struct objfile
*) NULL
);
3460 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3462 "bool", (struct objfile
*) NULL
);
3464 /* Add user knob for controlling resolution of opaque types */
3465 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
3466 &opaque_type_resolution
, _("\
3467 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3468 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL
,
3470 show_opaque_type_resolution
,
3471 &setlist
, &showlist
);
3472 opaque_type_resolution
= 1;
3474 /* Build SIMD types. */
3476 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
3478 = init_simd_type ("__builtin_v4si", builtin_type_int32
, "f", 4);
3480 = init_simd_type ("__builtin_v16qi", builtin_type_int8
, "f", 16);
3482 = init_simd_type ("__builtin_v8qi", builtin_type_int8
, "f", 8);
3484 = init_simd_type ("__builtin_v8hi", builtin_type_int16
, "f", 8);
3486 = init_simd_type ("__builtin_v4hi", builtin_type_int16
, "f", 4);
3488 = init_simd_type ("__builtin_v2si", builtin_type_int32
, "f", 2);
3490 /* 128 bit vectors. */
3491 builtin_type_v2_double
= init_vector_type (builtin_type_double
, 2);
3492 builtin_type_v4_float
= init_vector_type (builtin_type_float
, 4);
3493 builtin_type_v2_int64
= init_vector_type (builtin_type_int64
, 2);
3494 builtin_type_v4_int32
= init_vector_type (builtin_type_int32
, 4);
3495 builtin_type_v8_int16
= init_vector_type (builtin_type_int16
, 8);
3496 builtin_type_v16_int8
= init_vector_type (builtin_type_int8
, 16);
3497 /* 64 bit vectors. */
3498 builtin_type_v2_float
= init_vector_type (builtin_type_float
, 2);
3499 builtin_type_v2_int32
= init_vector_type (builtin_type_int32
, 2);
3500 builtin_type_v4_int16
= init_vector_type (builtin_type_int16
, 4);
3501 builtin_type_v8_int8
= init_vector_type (builtin_type_int8
, 8);
3504 builtin_type_vec64
= build_builtin_type_vec64 ();
3505 builtin_type_vec128
= build_builtin_type_vec128 ();
3507 /* Pointer/Address types. */
3509 /* NOTE: on some targets, addresses and pointers are not necessarily
3510 the same --- for example, on the D10V, pointers are 16 bits long,
3511 but addresses are 32 bits long. See doc/gdbint.texinfo,
3512 ``Pointers Are Not Always Addresses''.
3515 - gdb's `struct type' always describes the target's
3517 - gdb's `struct value' objects should always hold values in
3519 - gdb's CORE_ADDR values are addresses in the unified virtual
3520 address space that the assembler and linker work with. Thus,
3521 since target_read_memory takes a CORE_ADDR as an argument, it
3522 can access any memory on the target, even if the processor has
3523 separate code and data address spaces.
3526 - If v is a value holding a D10V code pointer, its contents are
3527 in target form: a big-endian address left-shifted two bits.
3528 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3529 sizeof (void *) == 2 on the target.
3531 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3532 target type for a value the target will never see. It's only
3533 used to hold the values of (typeless) linker symbols, which are
3534 indeed in the unified virtual address space. */
3535 builtin_type_void_data_ptr
= make_pointer_type (builtin_type_void
, NULL
);
3536 builtin_type_void_func_ptr
3537 = lookup_pointer_type (lookup_function_type (builtin_type_void
));
3538 builtin_type_CORE_ADDR
=
3539 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3541 "__CORE_ADDR", (struct objfile
*) NULL
);
3542 builtin_type_bfd_vma
=
3543 init_type (TYPE_CODE_INT
, TARGET_BFD_VMA_BIT
/ 8,
3545 "__bfd_vma", (struct objfile
*) NULL
);
3548 static struct gdbarch_data
*gdbtypes_data
;
3550 const struct builtin_type
*
3551 builtin_type (struct gdbarch
*gdbarch
)
3553 return gdbarch_data (gdbarch
, gdbtypes_data
);
3557 static struct type
*
3558 build_complex (int bit
, char *name
, struct type
*target_type
)
3561 if (bit
<= 0 || target_type
== builtin_type_error
)
3563 gdb_assert (builtin_type_error
!= NULL
);
3564 return builtin_type_error
;
3566 t
= init_type (TYPE_CODE_COMPLEX
, 2 * bit
/ TARGET_CHAR_BIT
,
3567 0, name
, (struct objfile
*) NULL
);
3568 TYPE_TARGET_TYPE (t
) = target_type
;
3573 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3575 struct builtin_type
*builtin_type
3576 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3578 builtin_type
->builtin_void
=
3579 init_type (TYPE_CODE_VOID
, 1,
3581 "void", (struct objfile
*) NULL
);
3582 builtin_type
->builtin_char
=
3583 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3585 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3586 "char", (struct objfile
*) NULL
);
3587 builtin_type
->builtin_true_char
=
3588 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3590 "true character", (struct objfile
*) NULL
);
3591 builtin_type
->builtin_signed_char
=
3592 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3594 "signed char", (struct objfile
*) NULL
);
3595 builtin_type
->builtin_unsigned_char
=
3596 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3598 "unsigned char", (struct objfile
*) NULL
);
3599 builtin_type
->builtin_short
=
3600 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3602 "short", (struct objfile
*) NULL
);
3603 builtin_type
->builtin_unsigned_short
=
3604 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3606 "unsigned short", (struct objfile
*) NULL
);
3607 builtin_type
->builtin_int
=
3608 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3610 "int", (struct objfile
*) NULL
);
3611 builtin_type
->builtin_unsigned_int
=
3612 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3614 "unsigned int", (struct objfile
*) NULL
);
3615 builtin_type
->builtin_long
=
3616 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3618 "long", (struct objfile
*) NULL
);
3619 builtin_type
->builtin_unsigned_long
=
3620 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3622 "unsigned long", (struct objfile
*) NULL
);
3623 builtin_type
->builtin_long_long
=
3624 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3626 "long long", (struct objfile
*) NULL
);
3627 builtin_type
->builtin_unsigned_long_long
=
3628 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3630 "unsigned long long", (struct objfile
*) NULL
);
3631 builtin_type
->builtin_float
3632 = build_flt (gdbarch_float_bit (gdbarch
), "float",
3633 gdbarch_float_format (gdbarch
));
3634 builtin_type
->builtin_double
3635 = build_flt (gdbarch_double_bit (gdbarch
), "double",
3636 gdbarch_double_format (gdbarch
));
3637 builtin_type
->builtin_long_double
3638 = build_flt (gdbarch_long_double_bit (gdbarch
), "long double",
3639 gdbarch_long_double_format (gdbarch
));
3640 builtin_type
->builtin_complex
3641 = build_complex (gdbarch_float_bit (gdbarch
), "complex",
3642 builtin_type
->builtin_float
);
3643 builtin_type
->builtin_double_complex
3644 = build_complex (gdbarch_double_bit (gdbarch
), "double complex",
3645 builtin_type
->builtin_double
);
3646 builtin_type
->builtin_string
=
3647 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3649 "string", (struct objfile
*) NULL
);
3650 builtin_type
->builtin_bool
=
3651 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3653 "bool", (struct objfile
*) NULL
);
3655 /* Pointer/Address types. */
3657 /* NOTE: on some targets, addresses and pointers are not necessarily
3658 the same --- for example, on the D10V, pointers are 16 bits long,
3659 but addresses are 32 bits long. See doc/gdbint.texinfo,
3660 ``Pointers Are Not Always Addresses''.
3663 - gdb's `struct type' always describes the target's
3665 - gdb's `struct value' objects should always hold values in
3667 - gdb's CORE_ADDR values are addresses in the unified virtual
3668 address space that the assembler and linker work with. Thus,
3669 since target_read_memory takes a CORE_ADDR as an argument, it
3670 can access any memory on the target, even if the processor has
3671 separate code and data address spaces.
3674 - If v is a value holding a D10V code pointer, its contents are
3675 in target form: a big-endian address left-shifted two bits.
3676 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3677 sizeof (void *) == 2 on the target.
3679 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3680 target type for a value the target will never see. It's only
3681 used to hold the values of (typeless) linker symbols, which are
3682 indeed in the unified virtual address space. */
3683 builtin_type
->builtin_data_ptr
3684 = make_pointer_type (builtin_type
->builtin_void
, NULL
);
3685 builtin_type
->builtin_func_ptr
3686 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3687 builtin_type
->builtin_core_addr
=
3688 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3690 "__CORE_ADDR", (struct objfile
*) NULL
);
3692 return builtin_type
;
3695 extern void _initialize_gdbtypes (void);
3697 _initialize_gdbtypes (void)
3699 struct cmd_list_element
*c
;
3701 /* FIXME: Why don't the following types need to be arch-swapped?
3702 See the comment at the top of the calls to
3703 DEPRECATED_REGISTER_GDBARCH_SWAP below. */
3705 init_type (TYPE_CODE_INT
, 0 / 8,
3707 "int0_t", (struct objfile
*) NULL
);
3709 init_type (TYPE_CODE_INT
, 8 / 8,
3711 "int8_t", (struct objfile
*) NULL
);
3712 builtin_type_uint8
=
3713 init_type (TYPE_CODE_INT
, 8 / 8,
3715 "uint8_t", (struct objfile
*) NULL
);
3716 builtin_type_int16
=
3717 init_type (TYPE_CODE_INT
, 16 / 8,
3719 "int16_t", (struct objfile
*) NULL
);
3720 builtin_type_uint16
=
3721 init_type (TYPE_CODE_INT
, 16 / 8,
3723 "uint16_t", (struct objfile
*) NULL
);
3724 builtin_type_int32
=
3725 init_type (TYPE_CODE_INT
, 32 / 8,
3727 "int32_t", (struct objfile
*) NULL
);
3728 builtin_type_uint32
=
3729 init_type (TYPE_CODE_INT
, 32 / 8,
3731 "uint32_t", (struct objfile
*) NULL
);
3732 builtin_type_int64
=
3733 init_type (TYPE_CODE_INT
, 64 / 8,
3735 "int64_t", (struct objfile
*) NULL
);
3736 builtin_type_uint64
=
3737 init_type (TYPE_CODE_INT
, 64 / 8,
3739 "uint64_t", (struct objfile
*) NULL
);
3740 builtin_type_int128
=
3741 init_type (TYPE_CODE_INT
, 128 / 8,
3743 "int128_t", (struct objfile
*) NULL
);
3744 builtin_type_uint128
=
3745 init_type (TYPE_CODE_INT
, 128 / 8,
3747 "uint128_t", (struct objfile
*) NULL
);
3751 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
3753 /* FIXME - For the moment, handle types by swapping them in and out.
3754 Should be using the per-architecture data-pointer and a large
3757 Note that any type T that we might create a 'T *' type for must
3758 be arch-swapped: we cache a type's 'T *' type in the pointer_type
3759 field, so if we change architectures but don't swap T, then
3760 lookup_pointer_type will start handing out pointer types made for
3761 a different architecture. */
3762 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void
);
3763 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char
);
3764 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short
);
3765 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int
);
3766 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long
);
3767 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long
);
3768 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char
);
3769 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char
);
3770 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short
);
3771 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int
);
3772 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long
);
3773 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long
);
3774 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float
);
3775 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double
);
3776 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double
);
3777 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex
);
3778 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex
);
3779 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string
);
3780 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf
);
3781 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si
);
3782 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi
);
3783 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi
);
3784 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi
);
3785 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi
);
3786 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si
);
3787 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double
);
3788 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float
);
3789 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64
);
3790 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32
);
3791 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16
);
3792 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8
);
3793 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float
);
3794 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32
);
3795 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8
);
3796 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16
);
3797 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128
);
3798 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr
);
3799 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr
);
3800 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR
);
3801 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma
);
3802 deprecated_register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
3804 /* Note: These types do not need to be swapped - they are target
3805 neutral. FIXME: Are you sure? See the comment above the calls
3806 to DEPRECATED_REGISTER_GDBARCH_SWAP above. */
3807 builtin_type_ieee_single
3808 = build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single
);
3809 builtin_type_ieee_double
3810 = build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double
);
3811 builtin_type_i387_ext
3812 = build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext
);
3813 builtin_type_m68881_ext
3814 = build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext
);
3815 builtin_type_arm_ext
3816 = build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext
);
3817 builtin_type_ia64_spill
3818 = build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill
);
3819 builtin_type_ia64_quad
3820 = build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad
);
3822 add_setshow_zinteger_cmd ("overload", no_class
, &overload_debug
, _("\
3823 Set debugging of C++ overloading."), _("\
3824 Show debugging of C++ overloading."), _("\
3825 When enabled, ranking of the functions is displayed."),
3827 show_overload_debug
,
3828 &setdebuglist
, &showdebuglist
);