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 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
;
101 struct type
*builtin_type_ieee_single
[BFD_ENDIAN_UNKNOWN
];
102 struct type
*builtin_type_ieee_single_big
;
103 struct type
*builtin_type_ieee_single_little
;
104 struct type
*builtin_type_ieee_double
[BFD_ENDIAN_UNKNOWN
];
105 struct type
*builtin_type_ieee_double_big
;
106 struct type
*builtin_type_ieee_double_little
;
107 struct type
*builtin_type_ieee_double_littlebyte_bigword
;
108 struct type
*builtin_type_i387_ext
;
109 struct type
*builtin_type_m68881_ext
;
110 struct type
*builtin_type_i960_ext
;
111 struct type
*builtin_type_m88110_ext
;
112 struct type
*builtin_type_m88110_harris_ext
;
113 struct type
*builtin_type_arm_ext
[BFD_ENDIAN_UNKNOWN
];
114 struct type
*builtin_type_arm_ext_big
;
115 struct type
*builtin_type_arm_ext_littlebyte_bigword
;
116 struct type
*builtin_type_ia64_spill
[BFD_ENDIAN_UNKNOWN
];
117 struct type
*builtin_type_ia64_spill_big
;
118 struct type
*builtin_type_ia64_spill_little
;
119 struct type
*builtin_type_ia64_quad
[BFD_ENDIAN_UNKNOWN
];
120 struct type
*builtin_type_ia64_quad_big
;
121 struct type
*builtin_type_ia64_quad_little
;
122 struct type
*builtin_type_void_data_ptr
;
123 struct type
*builtin_type_void_func_ptr
;
124 struct type
*builtin_type_CORE_ADDR
;
125 struct type
*builtin_type_bfd_vma
;
127 int opaque_type_resolution
= 1;
129 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
130 struct cmd_list_element
*c
, const char *value
)
132 fprintf_filtered (file
, _("\
133 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
137 int overload_debug
= 0;
139 show_overload_debug (struct ui_file
*file
, int from_tty
,
140 struct cmd_list_element
*c
, const char *value
)
142 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"), value
);
149 }; /* maximum extension is 128! FIXME */
151 static void print_bit_vector (B_TYPE
*, int);
152 static void print_arg_types (struct field
*, int, int);
153 static void dump_fn_fieldlists (struct type
*, int);
154 static void print_cplus_stuff (struct type
*, int);
155 static void virtual_base_list_aux (struct type
*dclass
);
158 /* Alloc a new type structure and fill it with some defaults. If
159 OBJFILE is non-NULL, then allocate the space for the type structure
160 in that objfile's objfile_obstack. Otherwise allocate the new type structure
161 by xmalloc () (for permanent types). */
164 alloc_type (struct objfile
*objfile
)
168 /* Alloc the structure and start off with all fields zeroed. */
172 type
= xmalloc (sizeof (struct type
));
173 memset (type
, 0, sizeof (struct type
));
174 TYPE_MAIN_TYPE (type
) = xmalloc (sizeof (struct main_type
));
178 type
= obstack_alloc (&objfile
->objfile_obstack
,
179 sizeof (struct type
));
180 memset (type
, 0, sizeof (struct type
));
181 TYPE_MAIN_TYPE (type
) = obstack_alloc (&objfile
->objfile_obstack
,
182 sizeof (struct main_type
));
183 OBJSTAT (objfile
, n_types
++);
185 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
187 /* Initialize the fields that might not be zero. */
189 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
190 TYPE_OBJFILE (type
) = objfile
;
191 TYPE_VPTR_FIELDNO (type
) = -1;
192 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
197 /* Alloc a new type instance structure, fill it with some defaults,
198 and point it at OLDTYPE. Allocate the new type instance from the
199 same place as OLDTYPE. */
202 alloc_type_instance (struct type
*oldtype
)
206 /* Allocate the structure. */
208 if (TYPE_OBJFILE (oldtype
) == NULL
)
210 type
= xmalloc (sizeof (struct type
));
211 memset (type
, 0, sizeof (struct type
));
215 type
= obstack_alloc (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
216 sizeof (struct type
));
217 memset (type
, 0, sizeof (struct type
));
219 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
221 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
226 /* Clear all remnants of the previous type at TYPE, in preparation for
227 replacing it with something else. */
229 smash_type (struct type
*type
)
231 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
233 /* For now, delete the rings. */
234 TYPE_CHAIN (type
) = type
;
236 /* For now, leave the pointer/reference types alone. */
239 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
240 to a pointer to memory where the pointer type should be stored.
241 If *TYPEPTR is zero, update it to point to the pointer type we return.
242 We allocate new memory if needed. */
245 make_pointer_type (struct type
*type
, struct type
**typeptr
)
247 struct type
*ntype
; /* New type */
248 struct objfile
*objfile
;
250 ntype
= TYPE_POINTER_TYPE (type
);
255 return ntype
; /* Don't care about alloc, and have new type. */
256 else if (*typeptr
== 0)
258 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
263 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
265 ntype
= alloc_type (TYPE_OBJFILE (type
));
270 /* We have storage, but need to reset it. */
273 objfile
= TYPE_OBJFILE (ntype
);
275 TYPE_OBJFILE (ntype
) = objfile
;
278 TYPE_TARGET_TYPE (ntype
) = type
;
279 TYPE_POINTER_TYPE (type
) = ntype
;
281 /* FIXME! Assume the machine has only one representation for pointers! */
283 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
284 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
286 /* Mark pointers as unsigned. The target converts between pointers
287 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
288 ADDRESS_TO_POINTER(). */
289 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
291 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
292 TYPE_POINTER_TYPE (type
) = ntype
;
297 /* Given a type TYPE, return a type of pointers to that type.
298 May need to construct such a type if this is the first use. */
301 lookup_pointer_type (struct type
*type
)
303 return make_pointer_type (type
, (struct type
**) 0);
306 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
307 to a pointer to memory where the reference type should be stored.
308 If *TYPEPTR is zero, update it to point to the reference type we return.
309 We allocate new memory if needed. */
312 make_reference_type (struct type
*type
, struct type
**typeptr
)
314 struct type
*ntype
; /* New type */
315 struct objfile
*objfile
;
317 ntype
= TYPE_REFERENCE_TYPE (type
);
322 return ntype
; /* Don't care about alloc, and have new type. */
323 else if (*typeptr
== 0)
325 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
330 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
332 ntype
= alloc_type (TYPE_OBJFILE (type
));
337 /* We have storage, but need to reset it. */
340 objfile
= TYPE_OBJFILE (ntype
);
342 TYPE_OBJFILE (ntype
) = objfile
;
345 TYPE_TARGET_TYPE (ntype
) = type
;
346 TYPE_REFERENCE_TYPE (type
) = ntype
;
348 /* FIXME! Assume the machine has only one representation for references,
349 and that it matches the (only) representation for pointers! */
351 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
352 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
354 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
355 TYPE_REFERENCE_TYPE (type
) = ntype
;
360 /* Same as above, but caller doesn't care about memory allocation details. */
363 lookup_reference_type (struct type
*type
)
365 return make_reference_type (type
, (struct type
**) 0);
368 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
369 to a pointer to memory where the function type should be stored.
370 If *TYPEPTR is zero, update it to point to the function type we return.
371 We allocate new memory if needed. */
374 make_function_type (struct type
*type
, struct type
**typeptr
)
376 struct type
*ntype
; /* New type */
377 struct objfile
*objfile
;
379 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
381 ntype
= alloc_type (TYPE_OBJFILE (type
));
386 /* We have storage, but need to reset it. */
389 objfile
= TYPE_OBJFILE (ntype
);
391 TYPE_OBJFILE (ntype
) = objfile
;
394 TYPE_TARGET_TYPE (ntype
) = type
;
396 TYPE_LENGTH (ntype
) = 1;
397 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
403 /* Given a type TYPE, return a type of functions that return that type.
404 May need to construct such a type if this is the first use. */
407 lookup_function_type (struct type
*type
)
409 return make_function_type (type
, (struct type
**) 0);
412 /* Identify address space identifier by name --
413 return the integer flag defined in gdbtypes.h. */
415 address_space_name_to_int (char *space_identifier
)
417 struct gdbarch
*gdbarch
= current_gdbarch
;
419 /* Check for known address space delimiters. */
420 if (!strcmp (space_identifier
, "code"))
421 return TYPE_FLAG_CODE_SPACE
;
422 else if (!strcmp (space_identifier
, "data"))
423 return TYPE_FLAG_DATA_SPACE
;
424 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
425 && gdbarch_address_class_name_to_type_flags (gdbarch
,
430 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
433 /* Identify address space identifier by integer flag as defined in
434 gdbtypes.h -- return the string version of the adress space name. */
437 address_space_int_to_name (int space_flag
)
439 struct gdbarch
*gdbarch
= current_gdbarch
;
440 if (space_flag
& TYPE_FLAG_CODE_SPACE
)
442 else if (space_flag
& TYPE_FLAG_DATA_SPACE
)
444 else if ((space_flag
& TYPE_FLAG_ADDRESS_CLASS_ALL
)
445 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
446 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
451 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
453 If STORAGE is non-NULL, create the new type instance there.
454 STORAGE must be in the same obstack as TYPE. */
457 make_qualified_type (struct type
*type
, int new_flags
,
458 struct type
*storage
)
464 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
466 ntype
= TYPE_CHAIN (ntype
);
467 } while (ntype
!= type
);
469 /* Create a new type instance. */
471 ntype
= alloc_type_instance (type
);
474 /* If STORAGE was provided, it had better be in the same objfile as
475 TYPE. Otherwise, we can't link it into TYPE's cv chain: if one
476 objfile is freed and the other kept, we'd have dangling
478 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
481 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
482 TYPE_CHAIN (ntype
) = ntype
;
485 /* Pointers or references to the original type are not relevant to
487 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
488 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
490 /* Chain the new qualified type to the old type. */
491 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
492 TYPE_CHAIN (type
) = ntype
;
494 /* Now set the instance flags and return the new type. */
495 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
497 /* Set length of new type to that of the original type. */
498 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
503 /* Make an address-space-delimited variant of a type -- a type that
504 is identical to the one supplied except that it has an address
505 space attribute attached to it (such as "code" or "data").
507 The space attributes "code" and "data" are for Harvard architectures.
508 The address space attributes are for architectures which have
509 alternately sized pointers or pointers with alternate representations. */
512 make_type_with_address_space (struct type
*type
, int space_flag
)
515 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
516 & ~(TYPE_FLAG_CODE_SPACE
| TYPE_FLAG_DATA_SPACE
517 | TYPE_FLAG_ADDRESS_CLASS_ALL
))
520 return make_qualified_type (type
, new_flags
, NULL
);
523 /* Make a "c-v" variant of a type -- a type that is identical to the
524 one supplied except that it may have const or volatile attributes
525 CNST is a flag for setting the const attribute
526 VOLTL is a flag for setting the volatile attribute
527 TYPE is the base type whose variant we are creating.
529 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
530 storage to hold the new qualified type; *TYPEPTR and TYPE must be
531 in the same objfile. Otherwise, allocate fresh memory for the new
532 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
533 new type we construct. */
535 make_cv_type (int cnst
, int voltl
, struct type
*type
, struct type
**typeptr
)
537 struct type
*ntype
; /* New type */
538 struct type
*tmp_type
= type
; /* tmp type */
539 struct objfile
*objfile
;
541 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
542 & ~(TYPE_FLAG_CONST
| TYPE_FLAG_VOLATILE
));
545 new_flags
|= TYPE_FLAG_CONST
;
548 new_flags
|= TYPE_FLAG_VOLATILE
;
550 if (typeptr
&& *typeptr
!= NULL
)
552 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
553 a C-V variant chain that threads across objfiles: if one
554 objfile gets freed, then the other has a broken C-V chain.
556 This code used to try to copy over the main type from TYPE to
557 *TYPEPTR if they were in different objfiles, but that's
558 wrong, too: TYPE may have a field list or member function
559 lists, which refer to types of their own, etc. etc. The
560 whole shebang would need to be copied over recursively; you
561 can't have inter-objfile pointers. The only thing to do is
562 to leave stub types as stub types, and look them up afresh by
563 name each time you encounter them. */
564 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
567 ntype
= make_qualified_type (type
, new_flags
, typeptr
? *typeptr
: NULL
);
575 /* Replace the contents of ntype with the type *type. This changes the
576 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
577 the changes are propogated to all types in the TYPE_CHAIN.
579 In order to build recursive types, it's inevitable that we'll need
580 to update types in place --- but this sort of indiscriminate
581 smashing is ugly, and needs to be replaced with something more
582 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
583 clear if more steps are needed. */
585 replace_type (struct type
*ntype
, struct type
*type
)
589 /* These two types had better be in the same objfile. Otherwise,
590 the assignment of one type's main type structure to the other
591 will produce a type with references to objects (names; field
592 lists; etc.) allocated on an objfile other than its own. */
593 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
595 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
597 /* The type length is not a part of the main type. Update it for each
598 type on the variant chain. */
601 /* Assert that this element of the chain has no address-class bits
602 set in its flags. Such type variants might have type lengths
603 which are supposed to be different from the non-address-class
604 variants. This assertion shouldn't ever be triggered because
605 symbol readers which do construct address-class variants don't
606 call replace_type(). */
607 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
609 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
610 chain
= TYPE_CHAIN (chain
);
611 } while (ntype
!= chain
);
613 /* Assert that the two types have equivalent instance qualifiers.
614 This should be true for at least all of our debug readers. */
615 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
618 /* Implement direct support for MEMBER_TYPE in GNU C++.
619 May need to construct such a type if this is the first use.
620 The TYPE is the type of the member. The DOMAIN is the type
621 of the aggregate that the member belongs to. */
624 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
628 mtype
= alloc_type (TYPE_OBJFILE (type
));
629 smash_to_memberptr_type (mtype
, domain
, type
);
633 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
636 lookup_methodptr_type (struct type
*to_type
)
640 mtype
= alloc_type (TYPE_OBJFILE (to_type
));
641 TYPE_TARGET_TYPE (mtype
) = to_type
;
642 TYPE_DOMAIN_TYPE (mtype
) = TYPE_DOMAIN_TYPE (to_type
);
643 TYPE_LENGTH (mtype
) = cplus_method_ptr_size ();
644 TYPE_CODE (mtype
) = TYPE_CODE_METHODPTR
;
648 /* Allocate a stub method whose return type is TYPE.
649 This apparently happens for speed of symbol reading, since parsing
650 out the arguments to the method is cpu-intensive, the way we are doing
651 it. So, we will fill in arguments later.
652 This always returns a fresh type. */
655 allocate_stub_method (struct type
*type
)
659 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
660 TYPE_OBJFILE (type
));
661 TYPE_TARGET_TYPE (mtype
) = type
;
662 /* _DOMAIN_TYPE (mtype) = unknown yet */
666 /* Create a range type using either a blank type supplied in RESULT_TYPE,
667 or creating a new type, inheriting the objfile from INDEX_TYPE.
669 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
670 HIGH_BOUND, inclusive.
672 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
673 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
676 create_range_type (struct type
*result_type
, struct type
*index_type
,
677 int low_bound
, int high_bound
)
679 if (result_type
== NULL
)
681 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
683 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
684 TYPE_TARGET_TYPE (result_type
) = index_type
;
685 if (TYPE_STUB (index_type
))
686 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
688 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
689 TYPE_NFIELDS (result_type
) = 2;
690 TYPE_FIELDS (result_type
) = (struct field
*)
691 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
692 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
693 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
694 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
695 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
696 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
699 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
701 return (result_type
);
704 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
705 Return 1 if type is a range type, 0 if it is discrete (and bounds
706 will fit in LONGEST), or -1 otherwise. */
709 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
711 CHECK_TYPEDEF (type
);
712 switch (TYPE_CODE (type
))
714 case TYPE_CODE_RANGE
:
715 *lowp
= TYPE_LOW_BOUND (type
);
716 *highp
= TYPE_HIGH_BOUND (type
);
719 if (TYPE_NFIELDS (type
) > 0)
721 /* The enums may not be sorted by value, so search all
725 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
726 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
728 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
729 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
730 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
731 *highp
= TYPE_FIELD_BITPOS (type
, i
);
734 /* Set unsigned indicator if warranted. */
737 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
751 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
753 if (!TYPE_UNSIGNED (type
))
755 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
759 /* ... fall through for unsigned ints ... */
762 /* This round-about calculation is to avoid shifting by
763 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
764 if TYPE_LENGTH (type) == sizeof (LONGEST). */
765 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
766 *highp
= (*highp
- 1) | *highp
;
773 /* Create an array type using either a blank type supplied in RESULT_TYPE,
774 or creating a new type, inheriting the objfile from RANGE_TYPE.
776 Elements will be of type ELEMENT_TYPE, the indices will be of type
779 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
780 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
783 create_array_type (struct type
*result_type
, struct type
*element_type
,
784 struct type
*range_type
)
786 LONGEST low_bound
, high_bound
;
788 if (result_type
== NULL
)
790 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
792 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
793 TYPE_TARGET_TYPE (result_type
) = element_type
;
794 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
795 low_bound
= high_bound
= 0;
796 CHECK_TYPEDEF (element_type
);
797 TYPE_LENGTH (result_type
) =
798 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
799 TYPE_NFIELDS (result_type
) = 1;
800 TYPE_FIELDS (result_type
) =
801 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
802 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
803 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
804 TYPE_VPTR_FIELDNO (result_type
) = -1;
806 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
807 if (TYPE_LENGTH (result_type
) == 0)
808 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
810 return (result_type
);
813 /* Create a string type using either a blank type supplied in RESULT_TYPE,
814 or creating a new type. String types are similar enough to array of
815 char types that we can use create_array_type to build the basic type
816 and then bash it into a string type.
818 For fixed length strings, the range type contains 0 as the lower
819 bound and the length of the string minus one as the upper bound.
821 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
822 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
825 create_string_type (struct type
*result_type
, struct type
*range_type
)
827 struct type
*string_char_type
;
829 string_char_type
= language_string_char_type (current_language
,
831 result_type
= create_array_type (result_type
,
834 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
835 return (result_type
);
839 create_set_type (struct type
*result_type
, struct type
*domain_type
)
841 LONGEST low_bound
, high_bound
, bit_length
;
842 if (result_type
== NULL
)
844 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
846 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
847 TYPE_NFIELDS (result_type
) = 1;
848 TYPE_FIELDS (result_type
) = (struct field
*)
849 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
850 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
852 if (!TYPE_STUB (domain_type
))
854 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
855 low_bound
= high_bound
= 0;
856 bit_length
= high_bound
- low_bound
+ 1;
857 TYPE_LENGTH (result_type
)
858 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
860 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
863 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
865 return (result_type
);
869 append_flags_type_flag (struct type
*type
, int bitpos
, char *name
)
871 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
872 gdb_assert (bitpos
< TYPE_NFIELDS (type
));
873 gdb_assert (bitpos
>= 0);
877 TYPE_FIELD_NAME (type
, bitpos
) = xstrdup (name
);
878 TYPE_FIELD_BITPOS (type
, bitpos
) = bitpos
;
882 /* Don't show this field to the user. */
883 TYPE_FIELD_BITPOS (type
, bitpos
) = -1;
888 init_flags_type (char *name
, int length
)
890 int nfields
= length
* TARGET_CHAR_BIT
;
893 type
= init_type (TYPE_CODE_FLAGS
, length
, TYPE_FLAG_UNSIGNED
, name
, NULL
);
894 TYPE_NFIELDS (type
) = nfields
;
895 TYPE_FIELDS (type
) = TYPE_ALLOC (type
, nfields
* sizeof (struct field
));
896 memset (TYPE_FIELDS (type
), 0, nfields
* sizeof (struct field
));
901 /* Construct and return a type of the form:
902 struct NAME { ELT_TYPE ELT_NAME[N]; }
903 We use these types for SIMD registers. For example, the type of
904 the SSE registers on the late x86-family processors is:
905 struct __builtin_v4sf { float f[4]; }
906 built by the function call:
907 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
908 The type returned is a permanent type, allocated using malloc; it
909 doesn't live in any objfile's obstack. */
911 init_simd_type (char *name
,
912 struct type
*elt_type
,
916 struct type
*simd_type
;
917 struct type
*array_type
;
919 simd_type
= init_composite_type (name
, TYPE_CODE_STRUCT
);
920 array_type
= create_array_type (0, elt_type
,
921 create_range_type (0, builtin_type_int
,
923 append_composite_type_field (simd_type
, elt_name
, array_type
);
928 init_vector_type (struct type
*elt_type
, int n
)
930 struct type
*array_type
;
932 array_type
= create_array_type (0, elt_type
,
933 create_range_type (0, builtin_type_int
,
935 TYPE_FLAGS (array_type
) |= TYPE_FLAG_VECTOR
;
940 build_builtin_type_vec64 (void)
942 /* Construct a type for the 64 bit registers. The type we're
945 union __gdb_builtin_type_vec64
957 t
= init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION
);
958 append_composite_type_field (t
, "uint64", builtin_type_int64
);
959 append_composite_type_field (t
, "v2_float", builtin_type_v2_float
);
960 append_composite_type_field (t
, "v2_int32", builtin_type_v2_int32
);
961 append_composite_type_field (t
, "v4_int16", builtin_type_v4_int16
);
962 append_composite_type_field (t
, "v8_int8", builtin_type_v8_int8
);
964 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
965 TYPE_NAME (t
) = "builtin_type_vec64";
970 build_builtin_type_vec128 (void)
972 /* Construct a type for the 128 bit registers. The type we're
975 union __gdb_builtin_type_vec128
987 t
= init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION
);
988 append_composite_type_field (t
, "uint128", builtin_type_int128
);
989 append_composite_type_field (t
, "v4_float", builtin_type_v4_float
);
990 append_composite_type_field (t
, "v4_int32", builtin_type_v4_int32
);
991 append_composite_type_field (t
, "v8_int16", builtin_type_v8_int16
);
992 append_composite_type_field (t
, "v16_int8", builtin_type_v16_int8
);
994 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
995 TYPE_NAME (t
) = "builtin_type_vec128";
999 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
1000 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
1001 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
1002 TYPE doesn't include the offset (that's the value of the MEMBER
1003 itself), but does include the structure type into which it points
1006 When "smashing" the type, we preserve the objfile that the
1007 old type pointed to, since we aren't changing where the type is actually
1011 smash_to_memberptr_type (struct type
*type
, struct type
*domain
,
1012 struct type
*to_type
)
1014 struct objfile
*objfile
;
1016 objfile
= TYPE_OBJFILE (type
);
1019 TYPE_OBJFILE (type
) = objfile
;
1020 TYPE_TARGET_TYPE (type
) = to_type
;
1021 TYPE_DOMAIN_TYPE (type
) = domain
;
1022 /* Assume that a data member pointer is the same size as a normal
1024 TYPE_LENGTH (type
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
1025 TYPE_CODE (type
) = TYPE_CODE_MEMBERPTR
;
1028 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1029 METHOD just means `function that gets an extra "this" argument'.
1031 When "smashing" the type, we preserve the objfile that the
1032 old type pointed to, since we aren't changing where the type is actually
1036 smash_to_method_type (struct type
*type
, struct type
*domain
,
1037 struct type
*to_type
, struct field
*args
,
1038 int nargs
, int varargs
)
1040 struct objfile
*objfile
;
1042 objfile
= TYPE_OBJFILE (type
);
1045 TYPE_OBJFILE (type
) = objfile
;
1046 TYPE_TARGET_TYPE (type
) = to_type
;
1047 TYPE_DOMAIN_TYPE (type
) = domain
;
1048 TYPE_FIELDS (type
) = args
;
1049 TYPE_NFIELDS (type
) = nargs
;
1051 TYPE_FLAGS (type
) |= TYPE_FLAG_VARARGS
;
1052 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1053 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1056 /* Return a typename for a struct/union/enum type without "struct ",
1057 "union ", or "enum ". If the type has a NULL name, return NULL. */
1060 type_name_no_tag (const struct type
*type
)
1062 if (TYPE_TAG_NAME (type
) != NULL
)
1063 return TYPE_TAG_NAME (type
);
1065 /* Is there code which expects this to return the name if there is no
1066 tag name? My guess is that this is mainly used for C++ in cases where
1067 the two will always be the same. */
1068 return TYPE_NAME (type
);
1071 /* Lookup a typedef or primitive type named NAME,
1072 visible in lexical block BLOCK.
1073 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1076 lookup_typename (char *name
, struct block
*block
, int noerr
)
1081 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1082 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1084 tmp
= language_lookup_primitive_type_by_name (current_language
,
1091 else if (!tmp
&& noerr
)
1097 error (_("No type named %s."), name
);
1100 return (SYMBOL_TYPE (sym
));
1104 lookup_unsigned_typename (char *name
)
1106 char *uns
= alloca (strlen (name
) + 10);
1108 strcpy (uns
, "unsigned ");
1109 strcpy (uns
+ 9, name
);
1110 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
1114 lookup_signed_typename (char *name
)
1117 char *uns
= alloca (strlen (name
) + 8);
1119 strcpy (uns
, "signed ");
1120 strcpy (uns
+ 7, name
);
1121 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
1122 /* If we don't find "signed FOO" just try again with plain "FOO". */
1125 return lookup_typename (name
, (struct block
*) NULL
, 0);
1128 /* Lookup a structure type named "struct NAME",
1129 visible in lexical block BLOCK. */
1132 lookup_struct (char *name
, struct block
*block
)
1136 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1137 (struct symtab
**) NULL
);
1141 error (_("No struct type named %s."), name
);
1143 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1145 error (_("This context has class, union or enum %s, not a struct."), name
);
1147 return (SYMBOL_TYPE (sym
));
1150 /* Lookup a union type named "union NAME",
1151 visible in lexical block BLOCK. */
1154 lookup_union (char *name
, struct block
*block
)
1159 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1160 (struct symtab
**) NULL
);
1163 error (_("No union type named %s."), name
);
1165 t
= SYMBOL_TYPE (sym
);
1167 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1170 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1171 * a further "declared_type" field to discover it is really a union.
1173 if (HAVE_CPLUS_STRUCT (t
))
1174 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1177 /* If we get here, it's not a union */
1178 error (_("This context has class, struct or enum %s, not a union."), name
);
1182 /* Lookup an enum type named "enum NAME",
1183 visible in lexical block BLOCK. */
1186 lookup_enum (char *name
, struct block
*block
)
1190 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1191 (struct symtab
**) NULL
);
1194 error (_("No enum type named %s."), name
);
1196 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1198 error (_("This context has class, struct or union %s, not an enum."), name
);
1200 return (SYMBOL_TYPE (sym
));
1203 /* Lookup a template type named "template NAME<TYPE>",
1204 visible in lexical block BLOCK. */
1207 lookup_template_type (char *name
, struct type
*type
, struct block
*block
)
1210 char *nam
= (char *) alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1213 strcat (nam
, TYPE_NAME (type
));
1214 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1216 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1220 error (_("No template type named %s."), name
);
1222 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1224 error (_("This context has class, union or enum %s, not a struct."), name
);
1226 return (SYMBOL_TYPE (sym
));
1229 /* Given a type TYPE, lookup the type of the component of type named NAME.
1231 TYPE can be either a struct or union, or a pointer or reference to a struct or
1232 union. If it is a pointer or reference, its target type is automatically used.
1233 Thus '.' and '->' are interchangable, as specified for the definitions of the
1234 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1236 If NOERR is nonzero, return zero if NAME is not suitably defined.
1237 If NAME is the name of a baseclass type, return that type. */
1240 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1246 CHECK_TYPEDEF (type
);
1247 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1248 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1250 type
= TYPE_TARGET_TYPE (type
);
1253 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
1254 TYPE_CODE (type
) != TYPE_CODE_UNION
)
1256 target_terminal_ours ();
1257 gdb_flush (gdb_stdout
);
1258 fprintf_unfiltered (gdb_stderr
, "Type ");
1259 type_print (type
, "", gdb_stderr
, -1);
1260 error (_(" is not a structure or union type."));
1264 /* FIXME: This change put in by Michael seems incorrect for the case where
1265 the structure tag name is the same as the member name. I.E. when doing
1266 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1271 typename
= type_name_no_tag (type
);
1272 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1277 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1279 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1281 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1283 return TYPE_FIELD_TYPE (type
, i
);
1287 /* OK, it's not in this class. Recursively check the baseclasses. */
1288 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1292 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1304 target_terminal_ours ();
1305 gdb_flush (gdb_stdout
);
1306 fprintf_unfiltered (gdb_stderr
, "Type ");
1307 type_print (type
, "", gdb_stderr
, -1);
1308 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1309 fputs_filtered (name
, gdb_stderr
);
1311 return (struct type
*) -1; /* For lint */
1314 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1315 valid. Callers should be aware that in some cases (for example,
1316 the type or one of its baseclasses is a stub type and we are
1317 debugging a .o file), this function will not be able to find the virtual
1318 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1319 will remain NULL. */
1322 fill_in_vptr_fieldno (struct type
*type
)
1324 CHECK_TYPEDEF (type
);
1326 if (TYPE_VPTR_FIELDNO (type
) < 0)
1330 /* We must start at zero in case the first (and only) baseclass is
1331 virtual (and hence we cannot share the table pointer). */
1332 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1334 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1335 fill_in_vptr_fieldno (baseclass
);
1336 if (TYPE_VPTR_FIELDNO (baseclass
) >= 0)
1338 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (baseclass
);
1339 TYPE_VPTR_BASETYPE (type
) = TYPE_VPTR_BASETYPE (baseclass
);
1346 /* Find the method and field indices for the destructor in class type T.
1347 Return 1 if the destructor was found, otherwise, return 0. */
1350 get_destructor_fn_field (struct type
*t
, int *method_indexp
, int *field_indexp
)
1354 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1357 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1359 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1361 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1373 stub_noname_complaint (void)
1375 complaint (&symfile_complaints
, _("stub type has NULL name"));
1378 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1380 If this is a stubbed struct (i.e. declared as struct foo *), see if
1381 we can find a full definition in some other file. If so, copy this
1382 definition, so we can use it in future. There used to be a comment (but
1383 not any code) that if we don't find a full definition, we'd set a flag
1384 so we don't spend time in the future checking the same type. That would
1385 be a mistake, though--we might load in more symbols which contain a
1386 full definition for the type.
1388 This used to be coded as a macro, but I don't think it is called
1389 often enough to merit such treatment. */
1391 /* Find the real type of TYPE. This function returns the real type, after
1392 removing all layers of typedefs and completing opaque or stub types.
1393 Completion changes the TYPE argument, but stripping of typedefs does
1397 check_typedef (struct type
*type
)
1399 struct type
*orig_type
= type
;
1400 int is_const
, is_volatile
;
1402 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1404 if (!TYPE_TARGET_TYPE (type
))
1409 /* It is dangerous to call lookup_symbol if we are currently
1410 reading a symtab. Infinite recursion is one danger. */
1411 if (currently_reading_symtab
)
1414 name
= type_name_no_tag (type
);
1415 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1416 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1417 as appropriate? (this code was written before TYPE_NAME and
1418 TYPE_TAG_NAME were separate). */
1421 stub_noname_complaint ();
1424 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0,
1425 (struct symtab
**) NULL
);
1427 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1429 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1431 type
= TYPE_TARGET_TYPE (type
);
1434 is_const
= TYPE_CONST (type
);
1435 is_volatile
= TYPE_VOLATILE (type
);
1437 /* If this is a struct/class/union with no fields, then check whether a
1438 full definition exists somewhere else. This is for systems where a
1439 type definition with no fields is issued for such types, instead of
1440 identifying them as stub types in the first place */
1442 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1444 char *name
= type_name_no_tag (type
);
1445 struct type
*newtype
;
1448 stub_noname_complaint ();
1451 newtype
= lookup_transparent_type (name
);
1455 /* If the resolved type and the stub are in the same objfile,
1456 then replace the stub type with the real deal. But if
1457 they're in separate objfiles, leave the stub alone; we'll
1458 just look up the transparent type every time we call
1459 check_typedef. We can't create pointers between types
1460 allocated to different objfiles, since they may have
1461 different lifetimes. Trying to copy NEWTYPE over to TYPE's
1462 objfile is pointless, too, since you'll have to move over any
1463 other types NEWTYPE refers to, which could be an unbounded
1465 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1466 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1471 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1472 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1474 char *name
= type_name_no_tag (type
);
1475 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1476 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1477 as appropriate? (this code was written before TYPE_NAME and
1478 TYPE_TAG_NAME were separate). */
1482 stub_noname_complaint ();
1485 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0, (struct symtab
**) NULL
);
1487 make_cv_type (is_const
, is_volatile
, SYMBOL_TYPE (sym
), &type
);
1490 if (TYPE_TARGET_STUB (type
))
1492 struct type
*range_type
;
1493 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1495 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1498 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1499 && TYPE_NFIELDS (type
) == 1
1500 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1501 == TYPE_CODE_RANGE
))
1503 /* Now recompute the length of the array type, based on its
1504 number of elements and the target type's length. */
1505 TYPE_LENGTH (type
) =
1506 ((TYPE_FIELD_BITPOS (range_type
, 1)
1507 - TYPE_FIELD_BITPOS (range_type
, 0)
1509 * TYPE_LENGTH (target_type
));
1510 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1512 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1514 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1515 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1518 /* Cache TYPE_LENGTH for future use. */
1519 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1523 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1524 silently return builtin_type_void. */
1526 static struct type
*
1527 safe_parse_type (char *p
, int length
)
1529 struct ui_file
*saved_gdb_stderr
;
1532 /* Suppress error messages. */
1533 saved_gdb_stderr
= gdb_stderr
;
1534 gdb_stderr
= ui_file_new ();
1536 /* Call parse_and_eval_type() without fear of longjmp()s. */
1537 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1538 type
= builtin_type_void
;
1540 /* Stop suppressing error messages. */
1541 ui_file_delete (gdb_stderr
);
1542 gdb_stderr
= saved_gdb_stderr
;
1547 /* Ugly hack to convert method stubs into method types.
1549 He ain't kiddin'. This demangles the name of the method into a string
1550 including argument types, parses out each argument type, generates
1551 a string casting a zero to that type, evaluates the string, and stuffs
1552 the resulting type into an argtype vector!!! Then it knows the type
1553 of the whole function (including argument types for overloading),
1554 which info used to be in the stab's but was removed to hack back
1555 the space required for them. */
1558 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1561 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1562 char *demangled_name
= cplus_demangle (mangled_name
,
1563 DMGL_PARAMS
| DMGL_ANSI
);
1564 char *argtypetext
, *p
;
1565 int depth
= 0, argcount
= 1;
1566 struct field
*argtypes
;
1569 /* Make sure we got back a function string that we can use. */
1571 p
= strchr (demangled_name
, '(');
1575 if (demangled_name
== NULL
|| p
== NULL
)
1576 error (_("Internal: Cannot demangle mangled name `%s'."), mangled_name
);
1578 /* Now, read in the parameters that define this type. */
1583 if (*p
== '(' || *p
== '<')
1587 else if (*p
== ')' || *p
== '>')
1591 else if (*p
== ',' && depth
== 0)
1599 /* If we read one argument and it was ``void'', don't count it. */
1600 if (strncmp (argtypetext
, "(void)", 6) == 0)
1603 /* We need one extra slot, for the THIS pointer. */
1605 argtypes
= (struct field
*)
1606 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1609 /* Add THIS pointer for non-static methods. */
1610 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1611 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1615 argtypes
[0].type
= lookup_pointer_type (type
);
1619 if (*p
!= ')') /* () means no args, skip while */
1624 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1626 /* Avoid parsing of ellipsis, they will be handled below.
1627 Also avoid ``void'' as above. */
1628 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1629 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1631 argtypes
[argcount
].type
=
1632 safe_parse_type (argtypetext
, p
- argtypetext
);
1635 argtypetext
= p
+ 1;
1638 if (*p
== '(' || *p
== '<')
1642 else if (*p
== ')' || *p
== '>')
1651 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1653 /* Now update the old "stub" type into a real type. */
1654 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1655 TYPE_DOMAIN_TYPE (mtype
) = type
;
1656 TYPE_FIELDS (mtype
) = argtypes
;
1657 TYPE_NFIELDS (mtype
) = argcount
;
1658 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1659 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1661 TYPE_FLAGS (mtype
) |= TYPE_FLAG_VARARGS
;
1663 xfree (demangled_name
);
1666 /* This is the external interface to check_stub_method, above. This function
1667 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1668 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1669 and TYPE_FN_FIELDLIST_NAME will be correct.
1671 This function unfortunately can not die until stabs do. */
1674 check_stub_method_group (struct type
*type
, int method_id
)
1676 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1677 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1678 int j
, found_stub
= 0;
1680 for (j
= 0; j
< len
; j
++)
1681 if (TYPE_FN_FIELD_STUB (f
, j
))
1684 check_stub_method (type
, method_id
, j
);
1687 /* GNU v3 methods with incorrect names were corrected when we read in
1688 type information, because it was cheaper to do it then. The only GNU v2
1689 methods with incorrect method names are operators and destructors;
1690 destructors were also corrected when we read in type information.
1692 Therefore the only thing we need to handle here are v2 operator
1694 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1697 char dem_opname
[256];
1699 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1700 dem_opname
, DMGL_ANSI
);
1702 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1705 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1709 const struct cplus_struct_type cplus_struct_default
;
1712 allocate_cplus_struct_type (struct type
*type
)
1714 if (!HAVE_CPLUS_STRUCT (type
))
1716 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1717 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1718 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1722 /* Helper function to initialize the standard scalar types.
1724 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1725 of the string pointed to by name in the objfile_obstack for that objfile,
1726 and initialize the type name to that copy. There are places (mipsread.c
1727 in particular, where init_type is called with a NULL value for NAME). */
1730 init_type (enum type_code code
, int length
, int flags
, char *name
,
1731 struct objfile
*objfile
)
1735 type
= alloc_type (objfile
);
1736 TYPE_CODE (type
) = code
;
1737 TYPE_LENGTH (type
) = length
;
1738 TYPE_FLAGS (type
) |= flags
;
1739 if ((name
!= NULL
) && (objfile
!= NULL
))
1742 obsavestring (name
, strlen (name
), &objfile
->objfile_obstack
);
1746 TYPE_NAME (type
) = name
;
1751 if (name
&& strcmp (name
, "char") == 0)
1752 TYPE_FLAGS (type
) |= TYPE_FLAG_NOSIGN
;
1754 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
1755 || code
== TYPE_CODE_NAMESPACE
)
1757 INIT_CPLUS_SPECIFIC (type
);
1762 /* Helper function. Create an empty composite type. */
1765 init_composite_type (char *name
, enum type_code code
)
1768 gdb_assert (code
== TYPE_CODE_STRUCT
1769 || code
== TYPE_CODE_UNION
);
1770 t
= init_type (code
, 0, 0, NULL
, NULL
);
1771 TYPE_TAG_NAME (t
) = name
;
1775 /* Helper function. Append a field to a composite type. */
1778 append_composite_type_field (struct type
*t
, char *name
, struct type
*field
)
1781 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
1782 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
1783 sizeof (struct field
) * TYPE_NFIELDS (t
));
1784 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
1785 memset (f
, 0, sizeof f
[0]);
1786 FIELD_TYPE (f
[0]) = field
;
1787 FIELD_NAME (f
[0]) = name
;
1788 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1790 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
1791 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
1793 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
1795 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
1796 if (TYPE_NFIELDS (t
) > 1)
1798 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
1799 + TYPE_LENGTH (field
) * TARGET_CHAR_BIT
);
1804 /* Look up a fundamental type for the specified objfile.
1805 May need to construct such a type if this is the first use.
1807 Some object file formats (ELF, COFF, etc) do not define fundamental
1808 types such as "int" or "double". Others (stabs for example), do
1809 define fundamental types.
1811 For the formats which don't provide fundamental types, gdb can create
1812 such types, using defaults reasonable for the current language and
1813 the current target machine.
1815 NOTE: This routine is obsolescent. Each debugging format reader
1816 should manage it's own fundamental types, either creating them from
1817 suitable defaults or reading them from the debugging information,
1818 whichever is appropriate. The DWARF reader has already been
1819 fixed to do this. Once the other readers are fixed, this routine
1820 will go away. Also note that fundamental types should be managed
1821 on a compilation unit basis in a multi-language environment, not
1822 on a linkage unit basis as is done here. */
1826 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1828 struct type
**typep
;
1831 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1833 error (_("internal error - invalid fundamental type id %d"), typeid);
1836 /* If this is the first time we need a fundamental type for this objfile
1837 then we need to initialize the vector of type pointers. */
1839 if (objfile
->fundamental_types
== NULL
)
1841 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1842 objfile
->fundamental_types
= (struct type
**)
1843 obstack_alloc (&objfile
->objfile_obstack
, nbytes
);
1844 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1845 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1848 /* Look for this particular type in the fundamental type vector. If one is
1849 not found, create and install one appropriate for the current language. */
1851 typep
= objfile
->fundamental_types
+ typeid;
1854 *typep
= create_fundamental_type (objfile
, typeid);
1861 can_dereference (struct type
*t
)
1863 /* FIXME: Should we return true for references as well as pointers? */
1867 && TYPE_CODE (t
) == TYPE_CODE_PTR
1868 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1872 is_integral_type (struct type
*t
)
1877 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1878 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1879 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
1880 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1881 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1882 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1885 /* Check whether BASE is an ancestor or base class or DCLASS
1886 Return 1 if so, and 0 if not.
1887 Note: callers may want to check for identity of the types before
1888 calling this function -- identical types are considered to satisfy
1889 the ancestor relationship even if they're identical */
1892 is_ancestor (struct type
*base
, struct type
*dclass
)
1896 CHECK_TYPEDEF (base
);
1897 CHECK_TYPEDEF (dclass
);
1901 if (TYPE_NAME (base
) && TYPE_NAME (dclass
) &&
1902 !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1905 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1906 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1914 /* See whether DCLASS has a virtual table. This routine is aimed at
1915 the HP/Taligent ANSI C++ runtime model, and may not work with other
1916 runtime models. Return 1 => Yes, 0 => No. */
1919 has_vtable (struct type
*dclass
)
1921 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1922 has virtual functions or virtual bases. */
1926 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1929 /* First check for the presence of virtual bases */
1930 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1931 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1932 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
1935 /* Next check for virtual functions */
1936 if (TYPE_FN_FIELDLISTS (dclass
))
1937 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
1938 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
1941 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1942 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1943 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1944 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
1945 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
1948 /* Well, maybe we don't need a virtual table */
1952 /* Return a pointer to the "primary base class" of DCLASS.
1954 A NULL return indicates that DCLASS has no primary base, or that it
1955 couldn't be found (insufficient information).
1957 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1958 and may not work with other runtime models. */
1961 primary_base_class (struct type
*dclass
)
1963 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1964 is the first directly inherited, non-virtual base class that
1965 requires a virtual table */
1969 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1972 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1973 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
1974 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
1975 return TYPE_FIELD_TYPE (dclass
, i
);
1980 /* Global manipulated by virtual_base_list[_aux]() */
1982 static struct vbase
*current_vbase_list
= NULL
;
1984 /* Return a pointer to a null-terminated list of struct vbase
1985 items. The vbasetype pointer of each item in the list points to the
1986 type information for a virtual base of the argument DCLASS.
1988 Helper function for virtual_base_list().
1989 Note: the list goes backward, right-to-left. virtual_base_list()
1990 copies the items out in reverse order. */
1993 virtual_base_list_aux (struct type
*dclass
)
1995 struct vbase
*tmp_vbase
;
1998 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
2001 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
2003 /* Recurse on this ancestor, first */
2004 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
2006 /* If this current base is itself virtual, add it to the list */
2007 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
2009 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
2011 /* Check if base already recorded */
2012 tmp_vbase
= current_vbase_list
;
2015 if (tmp_vbase
->vbasetype
== basetype
)
2016 break; /* found it */
2017 tmp_vbase
= tmp_vbase
->next
;
2020 if (!tmp_vbase
) /* normal exit from loop */
2022 /* Allocate new item for this virtual base */
2023 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
2025 /* Stick it on at the end of the list */
2026 tmp_vbase
->vbasetype
= basetype
;
2027 tmp_vbase
->next
= current_vbase_list
;
2028 current_vbase_list
= tmp_vbase
;
2031 } /* for loop over bases */
2035 /* Compute the list of virtual bases in the right order. Virtual
2036 bases are laid out in the object's memory area in order of their
2037 occurrence in a depth-first, left-to-right search through the
2040 Argument DCLASS is the type whose virtual bases are required.
2041 Return value is the address of a null-terminated array of pointers
2042 to struct type items.
2044 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2045 and may not work with other runtime models.
2047 This routine merely hands off the argument to virtual_base_list_aux()
2048 and then copies the result into an array to save space. */
2051 virtual_base_list (struct type
*dclass
)
2053 struct vbase
*tmp_vbase
;
2054 struct vbase
*tmp_vbase_2
;
2057 struct type
**vbase_array
;
2059 current_vbase_list
= NULL
;
2060 virtual_base_list_aux (dclass
);
2062 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2067 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
2069 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
2070 vbase_array
[i
] = tmp_vbase
->vbasetype
;
2072 /* Get rid of constructed chain */
2073 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
2076 tmp_vbase
= tmp_vbase
->next
;
2077 xfree (tmp_vbase_2
);
2078 tmp_vbase_2
= tmp_vbase
;
2081 vbase_array
[count
] = NULL
;
2085 /* Return the length of the virtual base list of the type DCLASS. */
2088 virtual_base_list_length (struct type
*dclass
)
2091 struct vbase
*tmp_vbase
;
2093 current_vbase_list
= NULL
;
2094 virtual_base_list_aux (dclass
);
2096 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2101 /* Return the number of elements of the virtual base list of the type
2102 DCLASS, ignoring those appearing in the primary base (and its
2103 primary base, recursively). */
2106 virtual_base_list_length_skip_primaries (struct type
*dclass
)
2109 struct vbase
*tmp_vbase
;
2110 struct type
*primary
;
2112 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2115 return virtual_base_list_length (dclass
);
2117 current_vbase_list
= NULL
;
2118 virtual_base_list_aux (dclass
);
2120 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
2122 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
2130 /* Return the index (position) of type BASE, which is a virtual base
2131 class of DCLASS, in the latter's virtual base list. A return of -1
2132 indicates "not found" or a problem. */
2135 virtual_base_index (struct type
*base
, struct type
*dclass
)
2140 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2141 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2145 vbase
= virtual_base_list (dclass
)[0];
2150 vbase
= virtual_base_list (dclass
)[++i
];
2153 return vbase
? i
: -1;
2158 /* Return the index (position) of type BASE, which is a virtual base
2159 class of DCLASS, in the latter's virtual base list. Skip over all
2160 bases that may appear in the virtual base list of the primary base
2161 class of DCLASS (recursively). A return of -1 indicates "not
2162 found" or a problem. */
2165 virtual_base_index_skip_primaries (struct type
*base
, struct type
*dclass
)
2169 struct type
*primary
;
2171 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2172 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2175 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2179 vbase
= virtual_base_list (dclass
)[0];
2182 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
2186 vbase
= virtual_base_list (dclass
)[++i
];
2189 return vbase
? j
: -1;
2192 /* Return position of a derived class DCLASS in the list of
2193 * primary bases starting with the remotest ancestor.
2194 * Position returned is 0-based. */
2197 class_index_in_primary_list (struct type
*dclass
)
2199 struct type
*pbc
; /* primary base class */
2201 /* Simply recurse on primary base */
2202 pbc
= TYPE_PRIMARY_BASE (dclass
);
2204 return 1 + class_index_in_primary_list (pbc
);
2209 /* Return a count of the number of virtual functions a type has.
2210 * This includes all the virtual functions it inherits from its
2214 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2215 * functions only once (latest redefinition)
2219 count_virtual_fns (struct type
*dclass
)
2221 int fn
, oi
; /* function and overloaded instance indices */
2222 int vfuncs
; /* count to return */
2224 /* recurse on bases that can share virtual table */
2225 struct type
*pbc
= primary_base_class (dclass
);
2227 vfuncs
= count_virtual_fns (pbc
);
2231 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2232 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2233 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2241 /* Functions for overload resolution begin here */
2243 /* Compare two badness vectors A and B and return the result.
2244 * 0 => A and B are identical
2245 * 1 => A and B are incomparable
2246 * 2 => A is better than B
2247 * 3 => A is worse than B */
2250 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2254 short found_pos
= 0; /* any positives in c? */
2255 short found_neg
= 0; /* any negatives in c? */
2257 /* differing lengths => incomparable */
2258 if (a
->length
!= b
->length
)
2261 /* Subtract b from a */
2262 for (i
= 0; i
< a
->length
; i
++)
2264 tmp
= a
->rank
[i
] - b
->rank
[i
];
2274 return 1; /* incomparable */
2276 return 3; /* A > B */
2282 return 2; /* A < B */
2284 return 0; /* A == B */
2288 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2289 * to the types of an argument list (ARGS, length NARGS).
2290 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2292 struct badness_vector
*
2293 rank_function (struct type
**parms
, int nparms
, struct type
**args
, int nargs
)
2296 struct badness_vector
*bv
;
2297 int min_len
= nparms
< nargs
? nparms
: nargs
;
2299 bv
= xmalloc (sizeof (struct badness_vector
));
2300 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2301 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2303 /* First compare the lengths of the supplied lists.
2304 * If there is a mismatch, set it to a high value. */
2306 /* pai/1997-06-03 FIXME: when we have debug info about default
2307 * arguments and ellipsis parameter lists, we should consider those
2308 * and rank the length-match more finely. */
2310 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2312 /* Now rank all the parameters of the candidate function */
2313 for (i
= 1; i
<= min_len
; i
++)
2314 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2316 /* If more arguments than parameters, add dummy entries */
2317 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2318 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2323 /* Compare the names of two integer types, assuming that any sign
2324 qualifiers have been checked already. We do it this way because
2325 there may be an "int" in the name of one of the types. */
2328 integer_types_same_name_p (const char *first
, const char *second
)
2330 int first_p
, second_p
;
2332 /* If both are shorts, return 1; if neither is a short, keep checking. */
2333 first_p
= (strstr (first
, "short") != NULL
);
2334 second_p
= (strstr (second
, "short") != NULL
);
2335 if (first_p
&& second_p
)
2337 if (first_p
|| second_p
)
2340 /* Likewise for long. */
2341 first_p
= (strstr (first
, "long") != NULL
);
2342 second_p
= (strstr (second
, "long") != NULL
);
2343 if (first_p
&& second_p
)
2345 if (first_p
|| second_p
)
2348 /* Likewise for char. */
2349 first_p
= (strstr (first
, "char") != NULL
);
2350 second_p
= (strstr (second
, "char") != NULL
);
2351 if (first_p
&& second_p
)
2353 if (first_p
|| second_p
)
2356 /* They must both be ints. */
2360 /* Compare one type (PARM) for compatibility with another (ARG).
2361 * PARM is intended to be the parameter type of a function; and
2362 * ARG is the supplied argument's type. This function tests if
2363 * the latter can be converted to the former.
2365 * Return 0 if they are identical types;
2366 * Otherwise, return an integer which corresponds to how compatible
2367 * PARM is to ARG. The higher the return value, the worse the match.
2368 * Generally the "bad" conversions are all uniformly assigned a 100 */
2371 rank_one_type (struct type
*parm
, struct type
*arg
)
2373 /* Identical type pointers */
2374 /* However, this still doesn't catch all cases of same type for arg
2375 * and param. The reason is that builtin types are different from
2376 * the same ones constructed from the object. */
2380 /* Resolve typedefs */
2381 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2382 parm
= check_typedef (parm
);
2383 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2384 arg
= check_typedef (arg
);
2387 Well, damnit, if the names are exactly the same,
2388 i'll say they are exactly the same. This happens when we generate
2389 method stubs. The types won't point to the same address, but they
2390 really are the same.
2393 if (TYPE_NAME (parm
) && TYPE_NAME (arg
) &&
2394 !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2397 /* Check if identical after resolving typedefs */
2401 /* See through references, since we can almost make non-references
2403 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2404 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2405 + REFERENCE_CONVERSION_BADNESS
);
2406 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2407 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2408 + REFERENCE_CONVERSION_BADNESS
);
2410 /* Debugging only. */
2411 fprintf_filtered (gdb_stderr
,"------ Arg is %s [%d], parm is %s [%d]\n",
2412 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2414 /* x -> y means arg of type x being supplied for parameter of type y */
2416 switch (TYPE_CODE (parm
))
2419 switch (TYPE_CODE (arg
))
2422 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2423 return VOID_PTR_CONVERSION_BADNESS
;
2425 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2426 case TYPE_CODE_ARRAY
:
2427 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2428 case TYPE_CODE_FUNC
:
2429 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2431 case TYPE_CODE_ENUM
:
2432 case TYPE_CODE_FLAGS
:
2433 case TYPE_CODE_CHAR
:
2434 case TYPE_CODE_RANGE
:
2435 case TYPE_CODE_BOOL
:
2436 return POINTER_CONVERSION_BADNESS
;
2438 return INCOMPATIBLE_TYPE_BADNESS
;
2440 case TYPE_CODE_ARRAY
:
2441 switch (TYPE_CODE (arg
))
2444 case TYPE_CODE_ARRAY
:
2445 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2447 return INCOMPATIBLE_TYPE_BADNESS
;
2449 case TYPE_CODE_FUNC
:
2450 switch (TYPE_CODE (arg
))
2452 case TYPE_CODE_PTR
: /* funcptr -> func */
2453 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2455 return INCOMPATIBLE_TYPE_BADNESS
;
2458 switch (TYPE_CODE (arg
))
2461 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2463 /* Deal with signed, unsigned, and plain chars and
2464 signed and unsigned ints */
2465 if (TYPE_NOSIGN (parm
))
2467 /* This case only for character types */
2468 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2471 return INTEGER_CONVERSION_BADNESS
; /* signed/unsigned char -> plain char */
2473 else if (TYPE_UNSIGNED (parm
))
2475 if (TYPE_UNSIGNED (arg
))
2477 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2478 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2480 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2481 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2482 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2484 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2488 if (integer_types_same_name_p (TYPE_NAME (arg
), "long")
2489 && integer_types_same_name_p (TYPE_NAME (parm
), "int"))
2490 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2492 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2495 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2497 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2499 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2500 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2501 return INTEGER_PROMOTION_BADNESS
;
2503 return INTEGER_CONVERSION_BADNESS
;
2506 return INTEGER_CONVERSION_BADNESS
;
2508 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2509 return INTEGER_PROMOTION_BADNESS
;
2511 return INTEGER_CONVERSION_BADNESS
;
2512 case TYPE_CODE_ENUM
:
2513 case TYPE_CODE_FLAGS
:
2514 case TYPE_CODE_CHAR
:
2515 case TYPE_CODE_RANGE
:
2516 case TYPE_CODE_BOOL
:
2517 return INTEGER_PROMOTION_BADNESS
;
2519 return INT_FLOAT_CONVERSION_BADNESS
;
2521 return NS_POINTER_CONVERSION_BADNESS
;
2523 return INCOMPATIBLE_TYPE_BADNESS
;
2526 case TYPE_CODE_ENUM
:
2527 switch (TYPE_CODE (arg
))
2530 case TYPE_CODE_CHAR
:
2531 case TYPE_CODE_RANGE
:
2532 case TYPE_CODE_BOOL
:
2533 case TYPE_CODE_ENUM
:
2534 return INTEGER_CONVERSION_BADNESS
;
2536 return INT_FLOAT_CONVERSION_BADNESS
;
2538 return INCOMPATIBLE_TYPE_BADNESS
;
2541 case TYPE_CODE_CHAR
:
2542 switch (TYPE_CODE (arg
))
2544 case TYPE_CODE_RANGE
:
2545 case TYPE_CODE_BOOL
:
2546 case TYPE_CODE_ENUM
:
2547 return INTEGER_CONVERSION_BADNESS
;
2549 return INT_FLOAT_CONVERSION_BADNESS
;
2551 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2552 return INTEGER_CONVERSION_BADNESS
;
2553 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2554 return INTEGER_PROMOTION_BADNESS
;
2555 /* >>> !! else fall through !! <<< */
2556 case TYPE_CODE_CHAR
:
2557 /* Deal with signed, unsigned, and plain chars for C++
2558 and with int cases falling through from previous case */
2559 if (TYPE_NOSIGN (parm
))
2561 if (TYPE_NOSIGN (arg
))
2564 return INTEGER_CONVERSION_BADNESS
;
2566 else if (TYPE_UNSIGNED (parm
))
2568 if (TYPE_UNSIGNED (arg
))
2571 return INTEGER_PROMOTION_BADNESS
;
2573 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2576 return INTEGER_CONVERSION_BADNESS
;
2578 return INCOMPATIBLE_TYPE_BADNESS
;
2581 case TYPE_CODE_RANGE
:
2582 switch (TYPE_CODE (arg
))
2585 case TYPE_CODE_CHAR
:
2586 case TYPE_CODE_RANGE
:
2587 case TYPE_CODE_BOOL
:
2588 case TYPE_CODE_ENUM
:
2589 return INTEGER_CONVERSION_BADNESS
;
2591 return INT_FLOAT_CONVERSION_BADNESS
;
2593 return INCOMPATIBLE_TYPE_BADNESS
;
2596 case TYPE_CODE_BOOL
:
2597 switch (TYPE_CODE (arg
))
2600 case TYPE_CODE_CHAR
:
2601 case TYPE_CODE_RANGE
:
2602 case TYPE_CODE_ENUM
:
2605 return BOOLEAN_CONVERSION_BADNESS
;
2606 case TYPE_CODE_BOOL
:
2609 return INCOMPATIBLE_TYPE_BADNESS
;
2613 switch (TYPE_CODE (arg
))
2616 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2617 return FLOAT_PROMOTION_BADNESS
;
2618 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2621 return FLOAT_CONVERSION_BADNESS
;
2623 case TYPE_CODE_BOOL
:
2624 case TYPE_CODE_ENUM
:
2625 case TYPE_CODE_RANGE
:
2626 case TYPE_CODE_CHAR
:
2627 return INT_FLOAT_CONVERSION_BADNESS
;
2629 return INCOMPATIBLE_TYPE_BADNESS
;
2632 case TYPE_CODE_COMPLEX
:
2633 switch (TYPE_CODE (arg
))
2634 { /* Strictly not needed for C++, but... */
2636 return FLOAT_PROMOTION_BADNESS
;
2637 case TYPE_CODE_COMPLEX
:
2640 return INCOMPATIBLE_TYPE_BADNESS
;
2643 case TYPE_CODE_STRUCT
:
2644 /* currently same as TYPE_CODE_CLASS */
2645 switch (TYPE_CODE (arg
))
2647 case TYPE_CODE_STRUCT
:
2648 /* Check for derivation */
2649 if (is_ancestor (parm
, arg
))
2650 return BASE_CONVERSION_BADNESS
;
2651 /* else fall through */
2653 return INCOMPATIBLE_TYPE_BADNESS
;
2656 case TYPE_CODE_UNION
:
2657 switch (TYPE_CODE (arg
))
2659 case TYPE_CODE_UNION
:
2661 return INCOMPATIBLE_TYPE_BADNESS
;
2664 case TYPE_CODE_MEMBERPTR
:
2665 switch (TYPE_CODE (arg
))
2668 return INCOMPATIBLE_TYPE_BADNESS
;
2671 case TYPE_CODE_METHOD
:
2672 switch (TYPE_CODE (arg
))
2676 return INCOMPATIBLE_TYPE_BADNESS
;
2680 switch (TYPE_CODE (arg
))
2684 return INCOMPATIBLE_TYPE_BADNESS
;
2689 switch (TYPE_CODE (arg
))
2693 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2695 return INCOMPATIBLE_TYPE_BADNESS
;
2698 case TYPE_CODE_VOID
:
2700 return INCOMPATIBLE_TYPE_BADNESS
;
2701 } /* switch (TYPE_CODE (arg)) */
2705 /* End of functions for overload resolution */
2708 print_bit_vector (B_TYPE
*bits
, int nbits
)
2712 for (bitno
= 0; bitno
< nbits
; bitno
++)
2714 if ((bitno
% 8) == 0)
2716 puts_filtered (" ");
2718 if (B_TST (bits
, bitno
))
2719 printf_filtered (("1"));
2721 printf_filtered (("0"));
2725 /* Note the first arg should be the "this" pointer, we may not want to
2726 include it since we may get into a infinitely recursive situation. */
2729 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2735 for (i
= 0; i
< nargs
; i
++)
2736 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2741 dump_fn_fieldlists (struct type
*type
, int spaces
)
2747 printfi_filtered (spaces
, "fn_fieldlists ");
2748 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2749 printf_filtered ("\n");
2750 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2752 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2753 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2755 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2756 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2758 printf_filtered (_(") length %d\n"),
2759 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2760 for (overload_idx
= 0;
2761 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2764 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2766 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2767 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2769 printf_filtered (")\n");
2770 printfi_filtered (spaces
+ 8, "type ");
2771 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2772 printf_filtered ("\n");
2774 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2777 printfi_filtered (spaces
+ 8, "args ");
2778 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2779 printf_filtered ("\n");
2781 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2782 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
, overload_idx
)),
2784 printfi_filtered (spaces
+ 8, "fcontext ");
2785 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2787 printf_filtered ("\n");
2789 printfi_filtered (spaces
+ 8, "is_const %d\n",
2790 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2791 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2792 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2793 printfi_filtered (spaces
+ 8, "is_private %d\n",
2794 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2795 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2796 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2797 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2798 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2799 printfi_filtered (spaces
+ 8, "voffset %u\n",
2800 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2806 print_cplus_stuff (struct type
*type
, int spaces
)
2808 printfi_filtered (spaces
, "n_baseclasses %d\n",
2809 TYPE_N_BASECLASSES (type
));
2810 printfi_filtered (spaces
, "nfn_fields %d\n",
2811 TYPE_NFN_FIELDS (type
));
2812 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2813 TYPE_NFN_FIELDS_TOTAL (type
));
2814 if (TYPE_N_BASECLASSES (type
) > 0)
2816 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2817 TYPE_N_BASECLASSES (type
));
2818 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2819 printf_filtered (")");
2821 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2822 TYPE_N_BASECLASSES (type
));
2823 puts_filtered ("\n");
2825 if (TYPE_NFIELDS (type
) > 0)
2827 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2829 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2830 TYPE_NFIELDS (type
));
2831 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2832 printf_filtered (")");
2833 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2834 TYPE_NFIELDS (type
));
2835 puts_filtered ("\n");
2837 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2839 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2840 TYPE_NFIELDS (type
));
2841 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2842 printf_filtered (")");
2843 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2844 TYPE_NFIELDS (type
));
2845 puts_filtered ("\n");
2848 if (TYPE_NFN_FIELDS (type
) > 0)
2850 dump_fn_fieldlists (type
, spaces
);
2855 print_bound_type (int bt
)
2859 case BOUND_CANNOT_BE_DETERMINED
:
2860 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2862 case BOUND_BY_REF_ON_STACK
:
2863 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2865 case BOUND_BY_VALUE_ON_STACK
:
2866 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2868 case BOUND_BY_REF_IN_REG
:
2869 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2871 case BOUND_BY_VALUE_IN_REG
:
2872 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2875 printf_filtered ("(BOUND_SIMPLE)");
2878 printf_filtered (_("(unknown bound type)"));
2883 static struct obstack dont_print_type_obstack
;
2886 recursive_dump_type (struct type
*type
, int spaces
)
2891 obstack_begin (&dont_print_type_obstack
, 0);
2893 if (TYPE_NFIELDS (type
) > 0
2894 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2896 struct type
**first_dont_print
2897 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2899 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
2904 if (type
== first_dont_print
[i
])
2906 printfi_filtered (spaces
, "type node ");
2907 gdb_print_host_address (type
, gdb_stdout
);
2908 printf_filtered (_(" <same as already seen type>\n"));
2913 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2916 printfi_filtered (spaces
, "type node ");
2917 gdb_print_host_address (type
, gdb_stdout
);
2918 printf_filtered ("\n");
2919 printfi_filtered (spaces
, "name '%s' (",
2920 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2921 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2922 printf_filtered (")\n");
2923 printfi_filtered (spaces
, "tagname '%s' (",
2924 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2925 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2926 printf_filtered (")\n");
2927 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2928 switch (TYPE_CODE (type
))
2930 case TYPE_CODE_UNDEF
:
2931 printf_filtered ("(TYPE_CODE_UNDEF)");
2934 printf_filtered ("(TYPE_CODE_PTR)");
2936 case TYPE_CODE_ARRAY
:
2937 printf_filtered ("(TYPE_CODE_ARRAY)");
2939 case TYPE_CODE_STRUCT
:
2940 printf_filtered ("(TYPE_CODE_STRUCT)");
2942 case TYPE_CODE_UNION
:
2943 printf_filtered ("(TYPE_CODE_UNION)");
2945 case TYPE_CODE_ENUM
:
2946 printf_filtered ("(TYPE_CODE_ENUM)");
2948 case TYPE_CODE_FLAGS
:
2949 printf_filtered ("(TYPE_CODE_FLAGS)");
2951 case TYPE_CODE_FUNC
:
2952 printf_filtered ("(TYPE_CODE_FUNC)");
2955 printf_filtered ("(TYPE_CODE_INT)");
2958 printf_filtered ("(TYPE_CODE_FLT)");
2960 case TYPE_CODE_VOID
:
2961 printf_filtered ("(TYPE_CODE_VOID)");
2964 printf_filtered ("(TYPE_CODE_SET)");
2966 case TYPE_CODE_RANGE
:
2967 printf_filtered ("(TYPE_CODE_RANGE)");
2969 case TYPE_CODE_STRING
:
2970 printf_filtered ("(TYPE_CODE_STRING)");
2972 case TYPE_CODE_BITSTRING
:
2973 printf_filtered ("(TYPE_CODE_BITSTRING)");
2975 case TYPE_CODE_ERROR
:
2976 printf_filtered ("(TYPE_CODE_ERROR)");
2978 case TYPE_CODE_MEMBERPTR
:
2979 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2981 case TYPE_CODE_METHODPTR
:
2982 printf_filtered ("(TYPE_CODE_METHODPTR)");
2984 case TYPE_CODE_METHOD
:
2985 printf_filtered ("(TYPE_CODE_METHOD)");
2988 printf_filtered ("(TYPE_CODE_REF)");
2990 case TYPE_CODE_CHAR
:
2991 printf_filtered ("(TYPE_CODE_CHAR)");
2993 case TYPE_CODE_BOOL
:
2994 printf_filtered ("(TYPE_CODE_BOOL)");
2996 case TYPE_CODE_COMPLEX
:
2997 printf_filtered ("(TYPE_CODE_COMPLEX)");
2999 case TYPE_CODE_TYPEDEF
:
3000 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3002 case TYPE_CODE_TEMPLATE
:
3003 printf_filtered ("(TYPE_CODE_TEMPLATE)");
3005 case TYPE_CODE_TEMPLATE_ARG
:
3006 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
3008 case TYPE_CODE_NAMESPACE
:
3009 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3012 printf_filtered ("(UNKNOWN TYPE CODE)");
3015 puts_filtered ("\n");
3016 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
3017 printfi_filtered (spaces
, "upper_bound_type 0x%x ",
3018 TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3019 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3020 puts_filtered ("\n");
3021 printfi_filtered (spaces
, "lower_bound_type 0x%x ",
3022 TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3023 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3024 puts_filtered ("\n");
3025 printfi_filtered (spaces
, "objfile ");
3026 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
3027 printf_filtered ("\n");
3028 printfi_filtered (spaces
, "target_type ");
3029 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
3030 printf_filtered ("\n");
3031 if (TYPE_TARGET_TYPE (type
) != NULL
)
3033 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
3035 printfi_filtered (spaces
, "pointer_type ");
3036 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
3037 printf_filtered ("\n");
3038 printfi_filtered (spaces
, "reference_type ");
3039 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
3040 printf_filtered ("\n");
3041 printfi_filtered (spaces
, "type_chain ");
3042 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
3043 printf_filtered ("\n");
3044 printfi_filtered (spaces
, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type
));
3045 if (TYPE_CONST (type
))
3047 puts_filtered (" TYPE_FLAG_CONST");
3049 if (TYPE_VOLATILE (type
))
3051 puts_filtered (" TYPE_FLAG_VOLATILE");
3053 if (TYPE_CODE_SPACE (type
))
3055 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3057 if (TYPE_DATA_SPACE (type
))
3059 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3061 if (TYPE_ADDRESS_CLASS_1 (type
))
3063 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3065 if (TYPE_ADDRESS_CLASS_2 (type
))
3067 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3069 puts_filtered ("\n");
3070 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
3071 if (TYPE_UNSIGNED (type
))
3073 puts_filtered (" TYPE_FLAG_UNSIGNED");
3075 if (TYPE_NOSIGN (type
))
3077 puts_filtered (" TYPE_FLAG_NOSIGN");
3079 if (TYPE_STUB (type
))
3081 puts_filtered (" TYPE_FLAG_STUB");
3083 if (TYPE_TARGET_STUB (type
))
3085 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3087 if (TYPE_STATIC (type
))
3089 puts_filtered (" TYPE_FLAG_STATIC");
3091 if (TYPE_PROTOTYPED (type
))
3093 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3095 if (TYPE_INCOMPLETE (type
))
3097 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3099 if (TYPE_VARARGS (type
))
3101 puts_filtered (" TYPE_FLAG_VARARGS");
3103 /* This is used for things like AltiVec registers on ppc. Gcc emits
3104 an attribute for the array type, which tells whether or not we
3105 have a vector, instead of a regular array. */
3106 if (TYPE_VECTOR (type
))
3108 puts_filtered (" TYPE_FLAG_VECTOR");
3110 puts_filtered ("\n");
3111 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
3112 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
3113 puts_filtered ("\n");
3114 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
3116 printfi_filtered (spaces
+ 2,
3117 "[%d] bitpos %d bitsize %d type ",
3118 idx
, TYPE_FIELD_BITPOS (type
, idx
),
3119 TYPE_FIELD_BITSIZE (type
, idx
));
3120 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
3121 printf_filtered (" name '%s' (",
3122 TYPE_FIELD_NAME (type
, idx
) != NULL
3123 ? TYPE_FIELD_NAME (type
, idx
)
3125 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
3126 printf_filtered (")\n");
3127 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
3129 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
3132 printfi_filtered (spaces
, "vptr_basetype ");
3133 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
3134 puts_filtered ("\n");
3135 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
3137 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
3139 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
3140 switch (TYPE_CODE (type
))
3142 case TYPE_CODE_STRUCT
:
3143 printfi_filtered (spaces
, "cplus_stuff ");
3144 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3145 puts_filtered ("\n");
3146 print_cplus_stuff (type
, spaces
);
3150 printfi_filtered (spaces
, "floatformat ");
3151 if (TYPE_FLOATFORMAT (type
) == NULL
3152 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
3153 puts_filtered ("(null)");
3155 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
3156 puts_filtered ("\n");
3160 /* We have to pick one of the union types to be able print and test
3161 the value. Pick cplus_struct_type, even though we know it isn't
3162 any particular one. */
3163 printfi_filtered (spaces
, "type_specific ");
3164 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3165 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
3167 printf_filtered (_(" (unknown data form)"));
3169 printf_filtered ("\n");
3174 obstack_free (&dont_print_type_obstack
, NULL
);
3177 /* Trivial helpers for the libiberty hash table, for mapping one
3182 struct type
*old
, *new;
3186 type_pair_hash (const void *item
)
3188 const struct type_pair
*pair
= item
;
3189 return htab_hash_pointer (pair
->old
);
3193 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
3195 const struct type_pair
*lhs
= item_lhs
, *rhs
= item_rhs
;
3196 return lhs
->old
== rhs
->old
;
3199 /* Allocate the hash table used by copy_type_recursive to walk
3200 types without duplicates. We use OBJFILE's obstack, because
3201 OBJFILE is about to be deleted. */
3204 create_copied_types_hash (struct objfile
*objfile
)
3206 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
3207 NULL
, &objfile
->objfile_obstack
,
3208 hashtab_obstack_allocate
,
3209 dummy_obstack_deallocate
);
3212 /* Recursively copy (deep copy) TYPE, if it is associated with OBJFILE.
3213 Return a new type allocated using malloc, a saved type if we have already
3214 visited TYPE (using COPIED_TYPES), or TYPE if it is not associated with
3218 copy_type_recursive (struct objfile
*objfile
, struct type
*type
,
3219 htab_t copied_types
)
3221 struct type_pair
*stored
, pair
;
3223 struct type
*new_type
;
3225 if (TYPE_OBJFILE (type
) == NULL
)
3228 /* This type shouldn't be pointing to any types in other objfiles; if
3229 it did, the type might disappear unexpectedly. */
3230 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
3233 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
3235 return ((struct type_pair
*) *slot
)->new;
3237 new_type
= alloc_type (NULL
);
3239 /* We must add the new type to the hash table immediately, in case
3240 we encounter this type again during a recursive call below. */
3241 stored
= xmalloc (sizeof (struct type_pair
));
3243 stored
->new = new_type
;
3246 /* Copy the common fields of types. */
3247 TYPE_CODE (new_type
) = TYPE_CODE (type
);
3248 TYPE_ARRAY_UPPER_BOUND_TYPE (new_type
) = TYPE_ARRAY_UPPER_BOUND_TYPE (type
);
3249 TYPE_ARRAY_LOWER_BOUND_TYPE (new_type
) = TYPE_ARRAY_LOWER_BOUND_TYPE (type
);
3250 if (TYPE_NAME (type
))
3251 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
3252 if (TYPE_TAG_NAME (type
))
3253 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
3254 TYPE_FLAGS (new_type
) = TYPE_FLAGS (type
);
3255 TYPE_VPTR_FIELDNO (new_type
) = TYPE_VPTR_FIELDNO (type
);
3257 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
3258 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
3260 /* Copy the fields. */
3261 TYPE_NFIELDS (new_type
) = TYPE_NFIELDS (type
);
3262 if (TYPE_NFIELDS (type
))
3266 nfields
= TYPE_NFIELDS (type
);
3267 TYPE_FIELDS (new_type
) = xmalloc (sizeof (struct field
) * nfields
);
3268 for (i
= 0; i
< nfields
; i
++)
3270 TYPE_FIELD_ARTIFICIAL (new_type
, i
) = TYPE_FIELD_ARTIFICIAL (type
, i
);
3271 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
3272 if (TYPE_FIELD_TYPE (type
, i
))
3273 TYPE_FIELD_TYPE (new_type
, i
)
3274 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
3276 if (TYPE_FIELD_NAME (type
, i
))
3277 TYPE_FIELD_NAME (new_type
, i
) = xstrdup (TYPE_FIELD_NAME (type
, i
));
3278 if (TYPE_FIELD_STATIC_HAS_ADDR (type
, i
))
3279 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
3280 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
3281 else if (TYPE_FIELD_STATIC (type
, i
))
3282 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
3283 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
, i
)));
3286 TYPE_FIELD_BITPOS (new_type
, i
) = TYPE_FIELD_BITPOS (type
, i
);
3287 TYPE_FIELD_STATIC_KIND (new_type
, i
) = 0;
3292 /* Copy pointers to other types. */
3293 if (TYPE_TARGET_TYPE (type
))
3294 TYPE_TARGET_TYPE (new_type
) = copy_type_recursive (objfile
,
3295 TYPE_TARGET_TYPE (type
),
3297 if (TYPE_VPTR_BASETYPE (type
))
3298 TYPE_VPTR_BASETYPE (new_type
) = copy_type_recursive (objfile
,
3299 TYPE_VPTR_BASETYPE (type
),
3301 /* Maybe copy the type_specific bits.
3303 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3304 base classes and methods. There's no fundamental reason why we
3305 can't, but at the moment it is not needed. */
3307 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
3308 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
3309 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3310 || TYPE_CODE (type
) == TYPE_CODE_UNION
3311 || TYPE_CODE (type
) == TYPE_CODE_TEMPLATE
3312 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
3313 INIT_CPLUS_SPECIFIC (new_type
);
3319 build_gdbtypes (void)
3322 init_type (TYPE_CODE_VOID
, 1,
3324 "void", (struct objfile
*) NULL
);
3326 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3328 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3329 "char", (struct objfile
*) NULL
);
3330 builtin_type_true_char
=
3331 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3333 "true character", (struct objfile
*) NULL
);
3334 builtin_type_signed_char
=
3335 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3337 "signed char", (struct objfile
*) NULL
);
3338 builtin_type_unsigned_char
=
3339 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3341 "unsigned char", (struct objfile
*) NULL
);
3342 builtin_type_short
=
3343 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3345 "short", (struct objfile
*) NULL
);
3346 builtin_type_unsigned_short
=
3347 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3349 "unsigned short", (struct objfile
*) NULL
);
3351 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3353 "int", (struct objfile
*) NULL
);
3354 builtin_type_unsigned_int
=
3355 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3357 "unsigned int", (struct objfile
*) NULL
);
3359 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3361 "long", (struct objfile
*) NULL
);
3362 builtin_type_unsigned_long
=
3363 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3365 "unsigned long", (struct objfile
*) NULL
);
3366 builtin_type_long_long
=
3367 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3369 "long long", (struct objfile
*) NULL
);
3370 builtin_type_unsigned_long_long
=
3371 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3373 "unsigned long long", (struct objfile
*) NULL
);
3374 builtin_type_float
=
3375 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3377 "float", (struct objfile
*) NULL
);
3378 /* vinschen@redhat.com 2002-02-08:
3379 The below lines are disabled since they are doing the wrong
3380 thing for non-multiarch targets. They are setting the correct
3381 type of floats for the target but while on multiarch targets
3382 this is done everytime the architecture changes, it's done on
3383 non-multiarch targets only on startup, leaving the wrong values
3384 in even if the architecture changes (eg. from big-endian to
3387 TYPE_FLOATFORMAT (builtin_type_float
) = TARGET_FLOAT_FORMAT
;
3389 builtin_type_double
=
3390 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3392 "double", (struct objfile
*) NULL
);
3394 TYPE_FLOATFORMAT (builtin_type_double
) = TARGET_DOUBLE_FORMAT
;
3396 builtin_type_long_double
=
3397 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3399 "long double", (struct objfile
*) NULL
);
3401 TYPE_FLOATFORMAT (builtin_type_long_double
) = TARGET_LONG_DOUBLE_FORMAT
;
3403 builtin_type_complex
=
3404 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3406 "complex", (struct objfile
*) NULL
);
3407 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
3408 builtin_type_double_complex
=
3409 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3411 "double complex", (struct objfile
*) NULL
);
3412 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
3413 builtin_type_string
=
3414 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3416 "string", (struct objfile
*) NULL
);
3418 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3420 "bool", (struct objfile
*) NULL
);
3422 /* Add user knob for controlling resolution of opaque types */
3423 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
3424 &opaque_type_resolution
, _("\
3425 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3426 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL
,
3428 show_opaque_type_resolution
,
3429 &setlist
, &showlist
);
3430 opaque_type_resolution
= 1;
3432 /* Build SIMD types. */
3434 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
3436 = init_simd_type ("__builtin_v4si", builtin_type_int32
, "f", 4);
3438 = init_simd_type ("__builtin_v16qi", builtin_type_int8
, "f", 16);
3440 = init_simd_type ("__builtin_v8qi", builtin_type_int8
, "f", 8);
3442 = init_simd_type ("__builtin_v8hi", builtin_type_int16
, "f", 8);
3444 = init_simd_type ("__builtin_v4hi", builtin_type_int16
, "f", 4);
3446 = init_simd_type ("__builtin_v2si", builtin_type_int32
, "f", 2);
3448 /* 128 bit vectors. */
3449 builtin_type_v2_double
= init_vector_type (builtin_type_double
, 2);
3450 builtin_type_v4_float
= init_vector_type (builtin_type_float
, 4);
3451 builtin_type_v2_int64
= init_vector_type (builtin_type_int64
, 2);
3452 builtin_type_v4_int32
= init_vector_type (builtin_type_int32
, 4);
3453 builtin_type_v8_int16
= init_vector_type (builtin_type_int16
, 8);
3454 builtin_type_v16_int8
= init_vector_type (builtin_type_int8
, 16);
3455 /* 64 bit vectors. */
3456 builtin_type_v2_float
= init_vector_type (builtin_type_float
, 2);
3457 builtin_type_v2_int32
= init_vector_type (builtin_type_int32
, 2);
3458 builtin_type_v4_int16
= init_vector_type (builtin_type_int16
, 4);
3459 builtin_type_v8_int8
= init_vector_type (builtin_type_int8
, 8);
3462 builtin_type_vec64
= build_builtin_type_vec64 ();
3463 builtin_type_vec128
= build_builtin_type_vec128 ();
3465 /* Pointer/Address types. */
3467 /* NOTE: on some targets, addresses and pointers are not necessarily
3468 the same --- for example, on the D10V, pointers are 16 bits long,
3469 but addresses are 32 bits long. See doc/gdbint.texinfo,
3470 ``Pointers Are Not Always Addresses''.
3473 - gdb's `struct type' always describes the target's
3475 - gdb's `struct value' objects should always hold values in
3477 - gdb's CORE_ADDR values are addresses in the unified virtual
3478 address space that the assembler and linker work with. Thus,
3479 since target_read_memory takes a CORE_ADDR as an argument, it
3480 can access any memory on the target, even if the processor has
3481 separate code and data address spaces.
3484 - If v is a value holding a D10V code pointer, its contents are
3485 in target form: a big-endian address left-shifted two bits.
3486 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3487 sizeof (void *) == 2 on the target.
3489 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3490 target type for a value the target will never see. It's only
3491 used to hold the values of (typeless) linker symbols, which are
3492 indeed in the unified virtual address space. */
3493 builtin_type_void_data_ptr
= make_pointer_type (builtin_type_void
, NULL
);
3494 builtin_type_void_func_ptr
3495 = lookup_pointer_type (lookup_function_type (builtin_type_void
));
3496 builtin_type_CORE_ADDR
=
3497 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3499 "__CORE_ADDR", (struct objfile
*) NULL
);
3500 builtin_type_bfd_vma
=
3501 init_type (TYPE_CODE_INT
, TARGET_BFD_VMA_BIT
/ 8,
3503 "__bfd_vma", (struct objfile
*) NULL
);
3506 static struct gdbarch_data
*gdbtypes_data
;
3508 const struct builtin_type
*
3509 builtin_type (struct gdbarch
*gdbarch
)
3511 return gdbarch_data (gdbarch
, gdbtypes_data
);
3515 static struct type
*
3516 build_flt (int bit
, char *name
, const struct floatformat
*floatformat
)
3519 if (bit
<= 0 || floatformat
== NULL
)
3521 gdb_assert (builtin_type_error
!= NULL
);
3522 return builtin_type_error
;
3524 t
= init_type (TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
,
3525 0, name
, (struct objfile
*) NULL
);
3526 TYPE_FLOATFORMAT (t
) = floatformat
;
3530 static struct type
*
3531 build_complex (int bit
, char *name
, struct type
*target_type
)
3534 if (bit
<= 0 || target_type
== builtin_type_error
)
3536 gdb_assert (builtin_type_error
!= NULL
);
3537 return builtin_type_error
;
3539 t
= init_type (TYPE_CODE_COMPLEX
, 2 * bit
/ TARGET_CHAR_BIT
,
3540 0, name
, (struct objfile
*) NULL
);
3541 TYPE_TARGET_TYPE (t
) = target_type
;
3546 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3548 struct builtin_type
*builtin_type
3549 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3551 builtin_type
->builtin_void
=
3552 init_type (TYPE_CODE_VOID
, 1,
3554 "void", (struct objfile
*) NULL
);
3555 builtin_type
->builtin_char
=
3556 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3558 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3559 "char", (struct objfile
*) NULL
);
3560 builtin_type
->builtin_true_char
=
3561 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3563 "true character", (struct objfile
*) NULL
);
3564 builtin_type
->builtin_signed_char
=
3565 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3567 "signed char", (struct objfile
*) NULL
);
3568 builtin_type
->builtin_unsigned_char
=
3569 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3571 "unsigned char", (struct objfile
*) NULL
);
3572 builtin_type
->builtin_short
=
3573 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3575 "short", (struct objfile
*) NULL
);
3576 builtin_type
->builtin_unsigned_short
=
3577 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3579 "unsigned short", (struct objfile
*) NULL
);
3580 builtin_type
->builtin_int
=
3581 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3583 "int", (struct objfile
*) NULL
);
3584 builtin_type
->builtin_unsigned_int
=
3585 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3587 "unsigned int", (struct objfile
*) NULL
);
3588 builtin_type
->builtin_long
=
3589 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3591 "long", (struct objfile
*) NULL
);
3592 builtin_type
->builtin_unsigned_long
=
3593 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3595 "unsigned long", (struct objfile
*) NULL
);
3596 builtin_type
->builtin_long_long
=
3597 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3599 "long long", (struct objfile
*) NULL
);
3600 builtin_type
->builtin_unsigned_long_long
=
3601 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3603 "unsigned long long", (struct objfile
*) NULL
);
3604 builtin_type
->builtin_float
3605 = build_flt (gdbarch_float_bit (gdbarch
), "float",
3606 gdbarch_float_format (gdbarch
));
3607 builtin_type
->builtin_double
3608 = build_flt (gdbarch_double_bit (gdbarch
), "double",
3609 gdbarch_double_format (gdbarch
));
3610 builtin_type
->builtin_long_double
3611 = build_flt (gdbarch_long_double_bit (gdbarch
), "long double",
3612 gdbarch_long_double_format (gdbarch
));
3613 builtin_type
->builtin_complex
3614 = build_complex (gdbarch_float_bit (gdbarch
), "complex",
3615 builtin_type
->builtin_float
);
3616 builtin_type
->builtin_double_complex
3617 = build_complex (gdbarch_double_bit (gdbarch
), "double complex",
3618 builtin_type
->builtin_double
);
3619 builtin_type
->builtin_string
=
3620 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3622 "string", (struct objfile
*) NULL
);
3623 builtin_type
->builtin_bool
=
3624 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3626 "bool", (struct objfile
*) NULL
);
3628 /* Pointer/Address types. */
3630 /* NOTE: on some targets, addresses and pointers are not necessarily
3631 the same --- for example, on the D10V, pointers are 16 bits long,
3632 but addresses are 32 bits long. See doc/gdbint.texinfo,
3633 ``Pointers Are Not Always Addresses''.
3636 - gdb's `struct type' always describes the target's
3638 - gdb's `struct value' objects should always hold values in
3640 - gdb's CORE_ADDR values are addresses in the unified virtual
3641 address space that the assembler and linker work with. Thus,
3642 since target_read_memory takes a CORE_ADDR as an argument, it
3643 can access any memory on the target, even if the processor has
3644 separate code and data address spaces.
3647 - If v is a value holding a D10V code pointer, its contents are
3648 in target form: a big-endian address left-shifted two bits.
3649 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3650 sizeof (void *) == 2 on the target.
3652 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3653 target type for a value the target will never see. It's only
3654 used to hold the values of (typeless) linker symbols, which are
3655 indeed in the unified virtual address space. */
3656 builtin_type
->builtin_data_ptr
3657 = make_pointer_type (builtin_type
->builtin_void
, NULL
);
3658 builtin_type
->builtin_func_ptr
3659 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3660 builtin_type
->builtin_core_addr
=
3661 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3663 "__CORE_ADDR", (struct objfile
*) NULL
);
3665 return builtin_type
;
3668 extern void _initialize_gdbtypes (void);
3670 _initialize_gdbtypes (void)
3672 struct cmd_list_element
*c
;
3674 /* FIXME: Why don't the following types need to be arch-swapped?
3675 See the comment at the top of the calls to
3676 DEPRECATED_REGISTER_GDBARCH_SWAP below. */
3678 init_type (TYPE_CODE_INT
, 0 / 8,
3680 "int0_t", (struct objfile
*) NULL
);
3682 init_type (TYPE_CODE_INT
, 8 / 8,
3684 "int8_t", (struct objfile
*) NULL
);
3685 builtin_type_uint8
=
3686 init_type (TYPE_CODE_INT
, 8 / 8,
3688 "uint8_t", (struct objfile
*) NULL
);
3689 builtin_type_int16
=
3690 init_type (TYPE_CODE_INT
, 16 / 8,
3692 "int16_t", (struct objfile
*) NULL
);
3693 builtin_type_uint16
=
3694 init_type (TYPE_CODE_INT
, 16 / 8,
3696 "uint16_t", (struct objfile
*) NULL
);
3697 builtin_type_int32
=
3698 init_type (TYPE_CODE_INT
, 32 / 8,
3700 "int32_t", (struct objfile
*) NULL
);
3701 builtin_type_uint32
=
3702 init_type (TYPE_CODE_INT
, 32 / 8,
3704 "uint32_t", (struct objfile
*) NULL
);
3705 builtin_type_int64
=
3706 init_type (TYPE_CODE_INT
, 64 / 8,
3708 "int64_t", (struct objfile
*) NULL
);
3709 builtin_type_uint64
=
3710 init_type (TYPE_CODE_INT
, 64 / 8,
3712 "uint64_t", (struct objfile
*) NULL
);
3713 builtin_type_int128
=
3714 init_type (TYPE_CODE_INT
, 128 / 8,
3716 "int128_t", (struct objfile
*) NULL
);
3717 builtin_type_uint128
=
3718 init_type (TYPE_CODE_INT
, 128 / 8,
3720 "uint128_t", (struct objfile
*) NULL
);
3724 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
3726 /* FIXME - For the moment, handle types by swapping them in and out.
3727 Should be using the per-architecture data-pointer and a large
3730 Note that any type T that we might create a 'T *' type for must
3731 be arch-swapped: we cache a type's 'T *' type in the pointer_type
3732 field, so if we change architectures but don't swap T, then
3733 lookup_pointer_type will start handing out pointer types made for
3734 a different architecture. */
3735 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void
);
3736 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char
);
3737 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short
);
3738 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int
);
3739 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long
);
3740 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long
);
3741 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char
);
3742 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char
);
3743 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short
);
3744 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int
);
3745 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long
);
3746 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long
);
3747 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float
);
3748 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double
);
3749 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double
);
3750 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex
);
3751 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex
);
3752 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string
);
3753 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf
);
3754 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si
);
3755 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi
);
3756 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi
);
3757 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi
);
3758 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi
);
3759 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si
);
3760 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double
);
3761 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float
);
3762 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64
);
3763 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32
);
3764 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16
);
3765 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8
);
3766 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float
);
3767 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32
);
3768 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8
);
3769 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16
);
3770 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128
);
3771 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr
);
3772 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr
);
3773 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR
);
3774 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma
);
3775 deprecated_register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
3777 /* Note: These types do not need to be swapped - they are target
3778 neutral. FIXME: Are you sure? See the comment above the calls
3779 to DEPRECATED_REGISTER_GDBARCH_SWAP above. */
3780 builtin_type_ieee_single_big
=
3781 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_big
.totalsize
/ 8,
3782 0, "builtin_type_ieee_single_big", NULL
);
3783 TYPE_FLOATFORMAT (builtin_type_ieee_single_big
) = &floatformat_ieee_single_big
;
3784 builtin_type_ieee_single_little
=
3785 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_little
.totalsize
/ 8,
3786 0, "builtin_type_ieee_single_little", NULL
);
3787 TYPE_FLOATFORMAT (builtin_type_ieee_single_little
) = &floatformat_ieee_single_little
;
3788 builtin_type_ieee_single
[BFD_ENDIAN_BIG
]
3789 = build_flt (floatformat_ieee_single_big
.totalsize
,
3790 "builtin_type_ieee_single_big",
3791 &floatformat_ieee_single_big
);
3792 builtin_type_ieee_single
[BFD_ENDIAN_LITTLE
]
3793 = build_flt (floatformat_ieee_single_little
.totalsize
,
3794 "builtin_type_ieee_single_little",
3795 &floatformat_ieee_single_little
);
3796 builtin_type_ieee_double_big
=
3797 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_big
.totalsize
/ 8,
3798 0, "builtin_type_ieee_double_big", NULL
);
3799 TYPE_FLOATFORMAT (builtin_type_ieee_double_big
) = &floatformat_ieee_double_big
;
3800 builtin_type_ieee_double_little
=
3801 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_little
.totalsize
/ 8,
3802 0, "builtin_type_ieee_double_little", NULL
);
3803 TYPE_FLOATFORMAT (builtin_type_ieee_double_little
) = &floatformat_ieee_double_little
;
3804 builtin_type_ieee_double
[BFD_ENDIAN_BIG
]
3805 = build_flt (floatformat_ieee_double_big
.totalsize
,
3806 "builtin_type_ieee_double_big",
3807 &floatformat_ieee_double_big
);
3808 builtin_type_ieee_double
[BFD_ENDIAN_LITTLE
]
3809 = build_flt (floatformat_ieee_double_little
.totalsize
,
3810 "builtin_type_ieee_double_little",
3811 &floatformat_ieee_double_little
);
3812 builtin_type_ieee_double_littlebyte_bigword
=
3813 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_littlebyte_bigword
.totalsize
/ 8,
3814 0, "builtin_type_ieee_double_littlebyte_bigword", NULL
);
3815 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword
) = &floatformat_ieee_double_littlebyte_bigword
;
3816 builtin_type_i387_ext
=
3817 init_type (TYPE_CODE_FLT
, floatformat_i387_ext
.totalsize
/ 8,
3818 0, "builtin_type_i387_ext", NULL
);
3819 TYPE_FLOATFORMAT (builtin_type_i387_ext
) = &floatformat_i387_ext
;
3820 builtin_type_m68881_ext
=
3821 init_type (TYPE_CODE_FLT
, floatformat_m68881_ext
.totalsize
/ 8,
3822 0, "builtin_type_m68881_ext", NULL
);
3823 TYPE_FLOATFORMAT (builtin_type_m68881_ext
) = &floatformat_m68881_ext
;
3824 builtin_type_i960_ext
=
3825 init_type (TYPE_CODE_FLT
, floatformat_i960_ext
.totalsize
/ 8,
3826 0, "builtin_type_i960_ext", NULL
);
3827 TYPE_FLOATFORMAT (builtin_type_i960_ext
) = &floatformat_i960_ext
;
3828 builtin_type_m88110_ext
=
3829 init_type (TYPE_CODE_FLT
, floatformat_m88110_ext
.totalsize
/ 8,
3830 0, "builtin_type_m88110_ext", NULL
);
3831 TYPE_FLOATFORMAT (builtin_type_m88110_ext
) = &floatformat_m88110_ext
;
3832 builtin_type_m88110_harris_ext
=
3833 init_type (TYPE_CODE_FLT
, floatformat_m88110_harris_ext
.totalsize
/ 8,
3834 0, "builtin_type_m88110_harris_ext", NULL
);
3835 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext
) = &floatformat_m88110_harris_ext
;
3836 builtin_type_arm_ext_big
=
3837 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_big
.totalsize
/ 8,
3838 0, "builtin_type_arm_ext_big", NULL
);
3839 TYPE_FLOATFORMAT (builtin_type_arm_ext_big
) = &floatformat_arm_ext_big
;
3840 builtin_type_arm_ext_littlebyte_bigword
=
3841 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_littlebyte_bigword
.totalsize
/ 8,
3842 0, "builtin_type_arm_ext_littlebyte_bigword", NULL
);
3843 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword
) = &floatformat_arm_ext_littlebyte_bigword
;
3844 builtin_type_arm_ext
[BFD_ENDIAN_BIG
]
3845 = build_flt (floatformat_arm_ext_big
.totalsize
,
3846 "builtin_type_arm_ext_big",
3847 &floatformat_arm_ext_big
);
3848 builtin_type_arm_ext
[BFD_ENDIAN_LITTLE
]
3849 = build_flt (floatformat_arm_ext_littlebyte_bigword
.totalsize
,
3850 "builtin_type_arm_ext_littlebyte_bigword",
3851 &floatformat_arm_ext_littlebyte_bigword
);
3852 builtin_type_ia64_spill_big
=
3853 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_big
.totalsize
/ 8,
3854 0, "builtin_type_ia64_spill_big", NULL
);
3855 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big
) = &floatformat_ia64_spill_big
;
3856 builtin_type_ia64_spill_little
=
3857 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_little
.totalsize
/ 8,
3858 0, "builtin_type_ia64_spill_little", NULL
);
3859 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little
) = &floatformat_ia64_spill_little
;
3860 builtin_type_ia64_spill
[BFD_ENDIAN_BIG
]
3861 = build_flt (floatformat_ia64_spill_big
.totalsize
,
3862 "builtin_type_ia64_spill_big",
3863 &floatformat_ia64_spill_big
);
3864 builtin_type_ia64_spill
[BFD_ENDIAN_LITTLE
]
3865 = build_flt (floatformat_ia64_spill_little
.totalsize
,
3866 "builtin_type_ia64_spill_little",
3867 &floatformat_ia64_spill_little
);
3868 builtin_type_ia64_quad_big
=
3869 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_big
.totalsize
/ 8,
3870 0, "builtin_type_ia64_quad_big", NULL
);
3871 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big
) = &floatformat_ia64_quad_big
;
3872 builtin_type_ia64_quad_little
=
3873 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_little
.totalsize
/ 8,
3874 0, "builtin_type_ia64_quad_little", NULL
);
3875 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little
) = &floatformat_ia64_quad_little
;
3876 builtin_type_ia64_quad
[BFD_ENDIAN_BIG
]
3877 = build_flt (floatformat_ia64_quad_big
.totalsize
,
3878 "builtin_type_ia64_quad_big",
3879 &floatformat_ia64_quad_big
);
3880 builtin_type_ia64_quad
[BFD_ENDIAN_LITTLE
]
3881 = build_flt (floatformat_ia64_quad_little
.totalsize
,
3882 "builtin_type_ia64_quad_little",
3883 &floatformat_ia64_quad_little
);
3885 add_setshow_zinteger_cmd ("overload", no_class
, &overload_debug
, _("\
3886 Set debugging of C++ overloading."), _("\
3887 Show debugging of C++ overloading."), _("\
3888 When enabled, ranking of the functions is displayed."),
3890 show_overload_debug
,
3891 &setdebuglist
, &showdebuglist
);