1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 3 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, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
30 #include "expression.h"
35 #include "complaints.h"
39 #include "gdb_assert.h"
42 /* These variables point to the objects
43 representing the predefined C data types. */
45 struct type *builtin_type_int0;
46 struct type *builtin_type_int8;
47 struct type *builtin_type_uint8;
48 struct type *builtin_type_int16;
49 struct type *builtin_type_uint16;
50 struct type *builtin_type_int32;
51 struct type *builtin_type_uint32;
52 struct type *builtin_type_int64;
53 struct type *builtin_type_uint64;
54 struct type *builtin_type_int128;
55 struct type *builtin_type_uint128;
57 /* Floatformat pairs. */
58 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
59 &floatformat_ieee_single_big,
60 &floatformat_ieee_single_little
62 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
63 &floatformat_ieee_double_big,
64 &floatformat_ieee_double_little
66 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
67 &floatformat_ieee_double_big,
68 &floatformat_ieee_double_littlebyte_bigword
70 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
71 &floatformat_i387_ext,
74 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
75 &floatformat_m68881_ext,
76 &floatformat_m68881_ext
78 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
79 &floatformat_arm_ext_big,
80 &floatformat_arm_ext_littlebyte_bigword
82 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
83 &floatformat_ia64_spill_big,
84 &floatformat_ia64_spill_little
86 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
87 &floatformat_ia64_quad_big,
88 &floatformat_ia64_quad_little
90 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
94 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
98 const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
99 &floatformat_ibm_long_double,
100 &floatformat_ibm_long_double
103 struct type *builtin_type_ieee_single;
104 struct type *builtin_type_ieee_double;
105 struct type *builtin_type_i387_ext;
106 struct type *builtin_type_m68881_ext;
107 struct type *builtin_type_arm_ext;
108 struct type *builtin_type_ia64_spill;
109 struct type *builtin_type_ia64_quad;
111 /* Platform-neutral void type. */
112 struct type *builtin_type_void;
114 /* Platform-neutral character types. */
115 struct type *builtin_type_true_char;
116 struct type *builtin_type_true_unsigned_char;
119 int opaque_type_resolution = 1;
121 show_opaque_type_resolution (struct ui_file *file, int from_tty,
122 struct cmd_list_element *c,
125 fprintf_filtered (file, _("\
126 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
130 int overload_debug = 0;
132 show_overload_debug (struct ui_file *file, int from_tty,
133 struct cmd_list_element *c, const char *value)
135 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
143 }; /* Maximum extension is 128! FIXME */
145 static void print_bit_vector (B_TYPE *, int);
146 static void print_arg_types (struct field *, int, int);
147 static void dump_fn_fieldlists (struct type *, int);
148 static void print_cplus_stuff (struct type *, int);
151 /* Alloc a new type structure and fill it with some defaults. If
152 OBJFILE is non-NULL, then allocate the space for the type structure
153 in that objfile's objfile_obstack. Otherwise allocate the new type
154 structure by xmalloc () (for permanent types). */
157 alloc_type (struct objfile *objfile)
161 /* Alloc the structure and start off with all fields zeroed. */
165 type = xmalloc (sizeof (struct type));
166 memset (type, 0, sizeof (struct type));
167 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
171 type = obstack_alloc (&objfile->objfile_obstack,
172 sizeof (struct type));
173 memset (type, 0, sizeof (struct type));
174 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
175 sizeof (struct main_type));
176 OBJSTAT (objfile, n_types++);
178 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
180 /* Initialize the fields that might not be zero. */
182 TYPE_CODE (type) = TYPE_CODE_UNDEF;
183 TYPE_OBJFILE (type) = objfile;
184 TYPE_VPTR_FIELDNO (type) = -1;
185 TYPE_CHAIN (type) = type; /* Chain back to itself. */
190 /* Alloc a new type instance structure, fill it with some defaults,
191 and point it at OLDTYPE. Allocate the new type instance from the
192 same place as OLDTYPE. */
195 alloc_type_instance (struct type *oldtype)
199 /* Allocate the structure. */
201 if (TYPE_OBJFILE (oldtype) == NULL)
203 type = xmalloc (sizeof (struct type));
204 memset (type, 0, sizeof (struct type));
208 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
209 sizeof (struct type));
210 memset (type, 0, sizeof (struct type));
212 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
214 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
219 /* Clear all remnants of the previous type at TYPE, in preparation for
220 replacing it with something else. */
222 smash_type (struct type *type)
224 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
226 /* For now, delete the rings. */
227 TYPE_CHAIN (type) = type;
229 /* For now, leave the pointer/reference types alone. */
232 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
233 to a pointer to memory where the pointer type should be stored.
234 If *TYPEPTR is zero, update it to point to the pointer type we return.
235 We allocate new memory if needed. */
238 make_pointer_type (struct type *type, struct type **typeptr)
240 struct type *ntype; /* New type */
241 struct objfile *objfile;
244 ntype = TYPE_POINTER_TYPE (type);
249 return ntype; /* Don't care about alloc,
250 and have new type. */
251 else if (*typeptr == 0)
253 *typeptr = ntype; /* Tracking alloc, and have new type. */
258 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
260 ntype = alloc_type (TYPE_OBJFILE (type));
264 else /* We have storage, but need to reset it. */
267 objfile = TYPE_OBJFILE (ntype);
268 chain = TYPE_CHAIN (ntype);
270 TYPE_CHAIN (ntype) = chain;
271 TYPE_OBJFILE (ntype) = objfile;
274 TYPE_TARGET_TYPE (ntype) = type;
275 TYPE_POINTER_TYPE (type) = ntype;
277 /* FIXME! Assume the machine has only one representation for
280 TYPE_LENGTH (ntype) =
281 gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
282 TYPE_CODE (ntype) = TYPE_CODE_PTR;
284 /* Mark pointers as unsigned. The target converts between pointers
285 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
286 gdbarch_address_to_pointer. */
287 TYPE_UNSIGNED (ntype) = 1;
289 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
290 TYPE_POINTER_TYPE (type) = ntype;
292 /* Update the length of all the other variants of this type. */
293 chain = TYPE_CHAIN (ntype);
294 while (chain != ntype)
296 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
297 chain = TYPE_CHAIN (chain);
303 /* Given a type TYPE, return a type of pointers to that type.
304 May need to construct such a type if this is the first use. */
307 lookup_pointer_type (struct type *type)
309 return make_pointer_type (type, (struct type **) 0);
312 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
313 points to a pointer to memory where the reference type should be
314 stored. If *TYPEPTR is zero, update it to point to the reference
315 type we return. We allocate new memory if needed. */
318 make_reference_type (struct type *type, struct type **typeptr)
320 struct type *ntype; /* New type */
321 struct objfile *objfile;
324 ntype = TYPE_REFERENCE_TYPE (type);
329 return ntype; /* Don't care about alloc,
330 and have new type. */
331 else if (*typeptr == 0)
333 *typeptr = ntype; /* Tracking alloc, and have new type. */
338 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
340 ntype = alloc_type (TYPE_OBJFILE (type));
344 else /* We have storage, but need to reset it. */
347 objfile = TYPE_OBJFILE (ntype);
348 chain = TYPE_CHAIN (ntype);
350 TYPE_CHAIN (ntype) = chain;
351 TYPE_OBJFILE (ntype) = objfile;
354 TYPE_TARGET_TYPE (ntype) = type;
355 TYPE_REFERENCE_TYPE (type) = ntype;
357 /* FIXME! Assume the machine has only one representation for
358 references, and that it matches the (only) representation for
361 TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
362 TYPE_CODE (ntype) = TYPE_CODE_REF;
364 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
365 TYPE_REFERENCE_TYPE (type) = ntype;
367 /* Update the length of all the other variants of this type. */
368 chain = TYPE_CHAIN (ntype);
369 while (chain != ntype)
371 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
372 chain = TYPE_CHAIN (chain);
378 /* Same as above, but caller doesn't care about memory allocation
382 lookup_reference_type (struct type *type)
384 return make_reference_type (type, (struct type **) 0);
387 /* Lookup a function type that returns type TYPE. TYPEPTR, if
388 nonzero, points to a pointer to memory where the function type
389 should be stored. If *TYPEPTR is zero, update it to point to the
390 function type we return. We allocate new memory if needed. */
393 make_function_type (struct type *type, struct type **typeptr)
395 struct type *ntype; /* New type */
396 struct objfile *objfile;
398 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
400 ntype = alloc_type (TYPE_OBJFILE (type));
404 else /* We have storage, but need to reset it. */
407 objfile = TYPE_OBJFILE (ntype);
409 TYPE_OBJFILE (ntype) = objfile;
412 TYPE_TARGET_TYPE (ntype) = type;
414 TYPE_LENGTH (ntype) = 1;
415 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
421 /* Given a type TYPE, return a type of functions that return that type.
422 May need to construct such a type if this is the first use. */
425 lookup_function_type (struct type *type)
427 return make_function_type (type, (struct type **) 0);
430 /* Identify address space identifier by name --
431 return the integer flag defined in gdbtypes.h. */
433 address_space_name_to_int (char *space_identifier)
435 struct gdbarch *gdbarch = current_gdbarch;
437 /* Check for known address space delimiters. */
438 if (!strcmp (space_identifier, "code"))
439 return TYPE_INSTANCE_FLAG_CODE_SPACE;
440 else if (!strcmp (space_identifier, "data"))
441 return TYPE_INSTANCE_FLAG_DATA_SPACE;
442 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
443 && gdbarch_address_class_name_to_type_flags (gdbarch,
448 error (_("Unknown address space specifier: \"%s\""), space_identifier);
451 /* Identify address space identifier by integer flag as defined in
452 gdbtypes.h -- return the string version of the adress space name. */
455 address_space_int_to_name (int space_flag)
457 struct gdbarch *gdbarch = current_gdbarch;
458 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
460 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
462 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
463 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
464 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
469 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
471 If STORAGE is non-NULL, create the new type instance there.
472 STORAGE must be in the same obstack as TYPE. */
475 make_qualified_type (struct type *type, int new_flags,
476 struct type *storage)
482 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
484 ntype = TYPE_CHAIN (ntype);
485 } while (ntype != type);
487 /* Create a new type instance. */
489 ntype = alloc_type_instance (type);
492 /* If STORAGE was provided, it had better be in the same objfile
493 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
494 if one objfile is freed and the other kept, we'd have
495 dangling pointers. */
496 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
499 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
500 TYPE_CHAIN (ntype) = ntype;
503 /* Pointers or references to the original type are not relevant to
505 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
506 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
508 /* Chain the new qualified type to the old type. */
509 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
510 TYPE_CHAIN (type) = ntype;
512 /* Now set the instance flags and return the new type. */
513 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
515 /* Set length of new type to that of the original type. */
516 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
521 /* Make an address-space-delimited variant of a type -- a type that
522 is identical to the one supplied except that it has an address
523 space attribute attached to it (such as "code" or "data").
525 The space attributes "code" and "data" are for Harvard
526 architectures. The address space attributes are for architectures
527 which have alternately sized pointers or pointers with alternate
531 make_type_with_address_space (struct type *type, int space_flag)
534 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
535 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
536 | TYPE_INSTANCE_FLAG_DATA_SPACE
537 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
540 return make_qualified_type (type, new_flags, NULL);
543 /* Make a "c-v" variant of a type -- a type that is identical to the
544 one supplied except that it may have const or volatile attributes
545 CNST is a flag for setting the const attribute
546 VOLTL is a flag for setting the volatile attribute
547 TYPE is the base type whose variant we are creating.
549 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
550 storage to hold the new qualified type; *TYPEPTR and TYPE must be
551 in the same objfile. Otherwise, allocate fresh memory for the new
552 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
553 new type we construct. */
555 make_cv_type (int cnst, int voltl,
557 struct type **typeptr)
559 struct type *ntype; /* New type */
560 struct type *tmp_type = type; /* tmp type */
561 struct objfile *objfile;
563 int new_flags = (TYPE_INSTANCE_FLAGS (type)
564 & ~(TYPE_INSTANCE_FLAG_CONST | TYPE_INSTANCE_FLAG_VOLATILE));
567 new_flags |= TYPE_INSTANCE_FLAG_CONST;
570 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
572 if (typeptr && *typeptr != NULL)
574 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
575 a C-V variant chain that threads across objfiles: if one
576 objfile gets freed, then the other has a broken C-V chain.
578 This code used to try to copy over the main type from TYPE to
579 *TYPEPTR if they were in different objfiles, but that's
580 wrong, too: TYPE may have a field list or member function
581 lists, which refer to types of their own, etc. etc. The
582 whole shebang would need to be copied over recursively; you
583 can't have inter-objfile pointers. The only thing to do is
584 to leave stub types as stub types, and look them up afresh by
585 name each time you encounter them. */
586 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
589 ntype = make_qualified_type (type, new_flags,
590 typeptr ? *typeptr : NULL);
598 /* Replace the contents of ntype with the type *type. This changes the
599 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
600 the changes are propogated to all types in the TYPE_CHAIN.
602 In order to build recursive types, it's inevitable that we'll need
603 to update types in place --- but this sort of indiscriminate
604 smashing is ugly, and needs to be replaced with something more
605 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
606 clear if more steps are needed. */
608 replace_type (struct type *ntype, struct type *type)
612 /* These two types had better be in the same objfile. Otherwise,
613 the assignment of one type's main type structure to the other
614 will produce a type with references to objects (names; field
615 lists; etc.) allocated on an objfile other than its own. */
616 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
618 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
620 /* The type length is not a part of the main type. Update it for
621 each type on the variant chain. */
624 /* Assert that this element of the chain has no address-class bits
625 set in its flags. Such type variants might have type lengths
626 which are supposed to be different from the non-address-class
627 variants. This assertion shouldn't ever be triggered because
628 symbol readers which do construct address-class variants don't
629 call replace_type(). */
630 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
632 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
633 chain = TYPE_CHAIN (chain);
634 } while (ntype != chain);
636 /* Assert that the two types have equivalent instance qualifiers.
637 This should be true for at least all of our debug readers. */
638 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
641 /* Implement direct support for MEMBER_TYPE in GNU C++.
642 May need to construct such a type if this is the first use.
643 The TYPE is the type of the member. The DOMAIN is the type
644 of the aggregate that the member belongs to. */
647 lookup_memberptr_type (struct type *type, struct type *domain)
651 mtype = alloc_type (TYPE_OBJFILE (type));
652 smash_to_memberptr_type (mtype, domain, type);
656 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
659 lookup_methodptr_type (struct type *to_type)
663 mtype = alloc_type (TYPE_OBJFILE (to_type));
664 TYPE_TARGET_TYPE (mtype) = to_type;
665 TYPE_DOMAIN_TYPE (mtype) = TYPE_DOMAIN_TYPE (to_type);
666 TYPE_LENGTH (mtype) = cplus_method_ptr_size (to_type);
667 TYPE_CODE (mtype) = TYPE_CODE_METHODPTR;
671 /* Allocate a stub method whose return type is TYPE. This apparently
672 happens for speed of symbol reading, since parsing out the
673 arguments to the method is cpu-intensive, the way we are doing it.
674 So, we will fill in arguments later. This always returns a fresh
678 allocate_stub_method (struct type *type)
682 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
683 TYPE_OBJFILE (type));
684 TYPE_TARGET_TYPE (mtype) = type;
685 /* _DOMAIN_TYPE (mtype) = unknown yet */
689 /* Create a range type using either a blank type supplied in
690 RESULT_TYPE, or creating a new type, inheriting the objfile from
693 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
694 to HIGH_BOUND, inclusive.
696 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
697 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
700 create_range_type (struct type *result_type, struct type *index_type,
701 int low_bound, int high_bound)
703 if (result_type == NULL)
705 result_type = alloc_type (TYPE_OBJFILE (index_type));
707 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
708 TYPE_TARGET_TYPE (result_type) = index_type;
709 if (TYPE_STUB (index_type))
710 TYPE_TARGET_STUB (result_type) = 1;
712 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
713 TYPE_NFIELDS (result_type) = 2;
714 TYPE_FIELDS (result_type) = TYPE_ALLOC (result_type,
715 TYPE_NFIELDS (result_type)
716 * sizeof (struct field));
717 memset (TYPE_FIELDS (result_type), 0,
718 TYPE_NFIELDS (result_type) * sizeof (struct field));
719 TYPE_LOW_BOUND (result_type) = low_bound;
720 TYPE_HIGH_BOUND (result_type) = high_bound;
723 TYPE_UNSIGNED (result_type) = 1;
728 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
729 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
730 bounds will fit in LONGEST), or -1 otherwise. */
733 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
735 CHECK_TYPEDEF (type);
736 switch (TYPE_CODE (type))
738 case TYPE_CODE_RANGE:
739 *lowp = TYPE_LOW_BOUND (type);
740 *highp = TYPE_HIGH_BOUND (type);
743 if (TYPE_NFIELDS (type) > 0)
745 /* The enums may not be sorted by value, so search all
749 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
750 for (i = 0; i < TYPE_NFIELDS (type); i++)
752 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
753 *lowp = TYPE_FIELD_BITPOS (type, i);
754 if (TYPE_FIELD_BITPOS (type, i) > *highp)
755 *highp = TYPE_FIELD_BITPOS (type, i);
758 /* Set unsigned indicator if warranted. */
761 TYPE_UNSIGNED (type) = 1;
775 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
777 if (!TYPE_UNSIGNED (type))
779 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
783 /* ... fall through for unsigned ints ... */
786 /* This round-about calculation is to avoid shifting by
787 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
788 if TYPE_LENGTH (type) == sizeof (LONGEST). */
789 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
790 *highp = (*highp - 1) | *highp;
797 /* Create an array type using either a blank type supplied in
798 RESULT_TYPE, or creating a new type, inheriting the objfile from
801 Elements will be of type ELEMENT_TYPE, the indices will be of type
804 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
805 sure it is TYPE_CODE_UNDEF before we bash it into an array
809 create_array_type (struct type *result_type,
810 struct type *element_type,
811 struct type *range_type)
813 LONGEST low_bound, high_bound;
815 if (result_type == NULL)
817 result_type = alloc_type (TYPE_OBJFILE (range_type));
819 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
820 TYPE_TARGET_TYPE (result_type) = element_type;
821 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
822 low_bound = high_bound = 0;
823 CHECK_TYPEDEF (element_type);
824 /* Be careful when setting the array length. Ada arrays can be
825 empty arrays with the high_bound being smaller than the low_bound.
826 In such cases, the array length should be zero. */
827 if (high_bound < low_bound)
828 TYPE_LENGTH (result_type) = 0;
830 TYPE_LENGTH (result_type) =
831 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
832 TYPE_NFIELDS (result_type) = 1;
833 TYPE_FIELDS (result_type) =
834 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
835 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
836 TYPE_INDEX_TYPE (result_type) = range_type;
837 TYPE_VPTR_FIELDNO (result_type) = -1;
839 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
840 if (TYPE_LENGTH (result_type) == 0)
841 TYPE_TARGET_STUB (result_type) = 1;
843 return (result_type);
846 /* Create a string type using either a blank type supplied in
847 RESULT_TYPE, or creating a new type. String types are similar
848 enough to array of char types that we can use create_array_type to
849 build the basic type and then bash it into a string type.
851 For fixed length strings, the range type contains 0 as the lower
852 bound and the length of the string minus one as the upper bound.
854 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
855 sure it is TYPE_CODE_UNDEF before we bash it into a string
859 create_string_type (struct type *result_type,
860 struct type *range_type)
862 struct type *string_char_type;
864 string_char_type = language_string_char_type (current_language,
866 result_type = create_array_type (result_type,
869 TYPE_CODE (result_type) = TYPE_CODE_STRING;
870 return (result_type);
874 create_set_type (struct type *result_type, struct type *domain_type)
876 if (result_type == NULL)
878 result_type = alloc_type (TYPE_OBJFILE (domain_type));
880 TYPE_CODE (result_type) = TYPE_CODE_SET;
881 TYPE_NFIELDS (result_type) = 1;
882 TYPE_FIELDS (result_type) = (struct field *)
883 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
884 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
886 if (!TYPE_STUB (domain_type))
888 LONGEST low_bound, high_bound, bit_length;
889 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
890 low_bound = high_bound = 0;
891 bit_length = high_bound - low_bound + 1;
892 TYPE_LENGTH (result_type)
893 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
895 TYPE_UNSIGNED (result_type) = 1;
897 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
899 return (result_type);
903 append_flags_type_flag (struct type *type, int bitpos, char *name)
905 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
906 gdb_assert (bitpos < TYPE_NFIELDS (type));
907 gdb_assert (bitpos >= 0);
911 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
912 TYPE_FIELD_BITPOS (type, bitpos) = bitpos;
916 /* Don't show this field to the user. */
917 TYPE_FIELD_BITPOS (type, bitpos) = -1;
922 init_flags_type (char *name, int length)
924 int nfields = length * TARGET_CHAR_BIT;
927 type = init_type (TYPE_CODE_FLAGS, length,
928 TYPE_FLAG_UNSIGNED, name, NULL);
929 TYPE_NFIELDS (type) = nfields;
930 TYPE_FIELDS (type) = TYPE_ALLOC (type,
931 nfields * sizeof (struct field));
932 memset (TYPE_FIELDS (type), 0, nfields * sizeof (struct field));
937 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
938 and any array types nested inside it. */
941 make_vector_type (struct type *array_type)
943 struct type *inner_array, *elt_type;
946 /* Find the innermost array type, in case the array is
947 multi-dimensional. */
948 inner_array = array_type;
949 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
950 inner_array = TYPE_TARGET_TYPE (inner_array);
952 elt_type = TYPE_TARGET_TYPE (inner_array);
953 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
955 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_FLAG_NOTTEXT;
956 elt_type = make_qualified_type (elt_type, flags, NULL);
957 TYPE_TARGET_TYPE (inner_array) = elt_type;
960 TYPE_VECTOR (array_type) = 1;
964 init_vector_type (struct type *elt_type, int n)
966 struct type *array_type;
968 array_type = create_array_type (0, elt_type,
969 create_range_type (0,
972 make_vector_type (array_type);
976 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
977 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
978 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
979 TYPE doesn't include the offset (that's the value of the MEMBER
980 itself), but does include the structure type into which it points
983 When "smashing" the type, we preserve the objfile that the old type
984 pointed to, since we aren't changing where the type is actually
988 smash_to_memberptr_type (struct type *type, struct type *domain,
989 struct type *to_type)
991 struct objfile *objfile;
993 objfile = TYPE_OBJFILE (type);
996 TYPE_OBJFILE (type) = objfile;
997 TYPE_TARGET_TYPE (type) = to_type;
998 TYPE_DOMAIN_TYPE (type) = domain;
999 /* Assume that a data member pointer is the same size as a normal
1001 TYPE_LENGTH (type) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
1002 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
1005 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1006 METHOD just means `function that gets an extra "this" argument'.
1008 When "smashing" the type, we preserve the objfile that the old type
1009 pointed to, since we aren't changing where the type is actually
1013 smash_to_method_type (struct type *type, struct type *domain,
1014 struct type *to_type, struct field *args,
1015 int nargs, int varargs)
1017 struct objfile *objfile;
1019 objfile = TYPE_OBJFILE (type);
1022 TYPE_OBJFILE (type) = objfile;
1023 TYPE_TARGET_TYPE (type) = to_type;
1024 TYPE_DOMAIN_TYPE (type) = domain;
1025 TYPE_FIELDS (type) = args;
1026 TYPE_NFIELDS (type) = nargs;
1028 TYPE_VARARGS (type) = 1;
1029 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1030 TYPE_CODE (type) = TYPE_CODE_METHOD;
1033 /* Return a typename for a struct/union/enum type without "struct ",
1034 "union ", or "enum ". If the type has a NULL name, return NULL. */
1037 type_name_no_tag (const struct type *type)
1039 if (TYPE_TAG_NAME (type) != NULL)
1040 return TYPE_TAG_NAME (type);
1042 /* Is there code which expects this to return the name if there is
1043 no tag name? My guess is that this is mainly used for C++ in
1044 cases where the two will always be the same. */
1045 return TYPE_NAME (type);
1048 /* Lookup a typedef or primitive type named NAME, visible in lexical
1049 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1050 suitably defined. */
1053 lookup_typename (char *name, struct block *block, int noerr)
1058 sym = lookup_symbol (name, block, VAR_DOMAIN, 0);
1059 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1061 tmp = language_lookup_primitive_type_by_name (current_language,
1068 else if (!tmp && noerr)
1074 error (_("No type named %s."), name);
1077 return (SYMBOL_TYPE (sym));
1081 lookup_unsigned_typename (char *name)
1083 char *uns = alloca (strlen (name) + 10);
1085 strcpy (uns, "unsigned ");
1086 strcpy (uns + 9, name);
1087 return (lookup_typename (uns, (struct block *) NULL, 0));
1091 lookup_signed_typename (char *name)
1094 char *uns = alloca (strlen (name) + 8);
1096 strcpy (uns, "signed ");
1097 strcpy (uns + 7, name);
1098 t = lookup_typename (uns, (struct block *) NULL, 1);
1099 /* If we don't find "signed FOO" just try again with plain "FOO". */
1102 return lookup_typename (name, (struct block *) NULL, 0);
1105 /* Lookup a structure type named "struct NAME",
1106 visible in lexical block BLOCK. */
1109 lookup_struct (char *name, struct block *block)
1113 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1117 error (_("No struct type named %s."), name);
1119 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1121 error (_("This context has class, union or enum %s, not a struct."),
1124 return (SYMBOL_TYPE (sym));
1127 /* Lookup a union type named "union NAME",
1128 visible in lexical block BLOCK. */
1131 lookup_union (char *name, struct block *block)
1136 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1139 error (_("No union type named %s."), name);
1141 t = SYMBOL_TYPE (sym);
1143 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1146 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1147 * a further "declared_type" field to discover it is really a union.
1149 if (HAVE_CPLUS_STRUCT (t))
1150 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1153 /* If we get here, it's not a union. */
1154 error (_("This context has class, struct or enum %s, not a union."),
1159 /* Lookup an enum type named "enum NAME",
1160 visible in lexical block BLOCK. */
1163 lookup_enum (char *name, struct block *block)
1167 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1170 error (_("No enum type named %s."), name);
1172 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1174 error (_("This context has class, struct or union %s, not an enum."),
1177 return (SYMBOL_TYPE (sym));
1180 /* Lookup a template type named "template NAME<TYPE>",
1181 visible in lexical block BLOCK. */
1184 lookup_template_type (char *name, struct type *type,
1185 struct block *block)
1188 char *nam = (char *)
1189 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1192 strcat (nam, TYPE_NAME (type));
1193 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1195 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0);
1199 error (_("No template type named %s."), name);
1201 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1203 error (_("This context has class, union or enum %s, not a struct."),
1206 return (SYMBOL_TYPE (sym));
1209 /* Given a type TYPE, lookup the type of the component of type named
1212 TYPE can be either a struct or union, or a pointer or reference to
1213 a struct or union. If it is a pointer or reference, its target
1214 type is automatically used. Thus '.' and '->' are interchangable,
1215 as specified for the definitions of the expression element types
1216 STRUCTOP_STRUCT and STRUCTOP_PTR.
1218 If NOERR is nonzero, return zero if NAME is not suitably defined.
1219 If NAME is the name of a baseclass type, return that type. */
1222 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1228 CHECK_TYPEDEF (type);
1229 if (TYPE_CODE (type) != TYPE_CODE_PTR
1230 && TYPE_CODE (type) != TYPE_CODE_REF)
1232 type = TYPE_TARGET_TYPE (type);
1235 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1236 && TYPE_CODE (type) != TYPE_CODE_UNION)
1238 target_terminal_ours ();
1239 gdb_flush (gdb_stdout);
1240 fprintf_unfiltered (gdb_stderr, "Type ");
1241 type_print (type, "", gdb_stderr, -1);
1242 error (_(" is not a structure or union type."));
1246 /* FIXME: This change put in by Michael seems incorrect for the case
1247 where the structure tag name is the same as the member name.
1248 I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
1249 foo; } bell;" Disabled by fnf. */
1253 typename = type_name_no_tag (type);
1254 if (typename != NULL && strcmp (typename, name) == 0)
1259 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1261 char *t_field_name = TYPE_FIELD_NAME (type, i);
1263 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1265 return TYPE_FIELD_TYPE (type, i);
1269 /* OK, it's not in this class. Recursively check the baseclasses. */
1270 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1274 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1286 target_terminal_ours ();
1287 gdb_flush (gdb_stdout);
1288 fprintf_unfiltered (gdb_stderr, "Type ");
1289 type_print (type, "", gdb_stderr, -1);
1290 fprintf_unfiltered (gdb_stderr, " has no component named ");
1291 fputs_filtered (name, gdb_stderr);
1293 return (struct type *) -1; /* For lint */
1296 /* Lookup the vptr basetype/fieldno values for TYPE.
1297 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1298 vptr_fieldno. Also, if found and basetype is from the same objfile,
1300 If not found, return -1 and ignore BASETYPEP.
1301 Callers should be aware that in some cases (for example,
1302 the type or one of its baseclasses is a stub type and we are
1303 debugging a .o file), this function will not be able to find the
1304 virtual function table pointer, and vptr_fieldno will remain -1 and
1305 vptr_basetype will remain NULL or incomplete. */
1308 get_vptr_fieldno (struct type *type, struct type **basetypep)
1310 CHECK_TYPEDEF (type);
1312 if (TYPE_VPTR_FIELDNO (type) < 0)
1316 /* We must start at zero in case the first (and only) baseclass
1317 is virtual (and hence we cannot share the table pointer). */
1318 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1320 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1322 struct type *basetype;
1324 fieldno = get_vptr_fieldno (baseclass, &basetype);
1327 /* If the type comes from a different objfile we can't cache
1328 it, it may have a different lifetime. PR 2384 */
1329 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
1331 TYPE_VPTR_FIELDNO (type) = fieldno;
1332 TYPE_VPTR_BASETYPE (type) = basetype;
1335 *basetypep = basetype;
1346 *basetypep = TYPE_VPTR_BASETYPE (type);
1347 return TYPE_VPTR_FIELDNO (type);
1351 /* Find the method and field indices for the destructor in class type T.
1352 Return 1 if the destructor was found, otherwise, return 0. */
1355 get_destructor_fn_field (struct type *t,
1361 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1364 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1366 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1368 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1380 stub_noname_complaint (void)
1382 complaint (&symfile_complaints, _("stub type has NULL name"));
1385 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1387 If this is a stubbed struct (i.e. declared as struct foo *), see if
1388 we can find a full definition in some other file. If so, copy this
1389 definition, so we can use it in future. There used to be a comment
1390 (but not any code) that if we don't find a full definition, we'd
1391 set a flag so we don't spend time in the future checking the same
1392 type. That would be a mistake, though--we might load in more
1393 symbols which contain a full definition for the type.
1395 This used to be coded as a macro, but I don't think it is called
1396 often enough to merit such treatment. */
1398 /* Find the real type of TYPE. This function returns the real type,
1399 after removing all layers of typedefs and completing opaque or stub
1400 types. Completion changes the TYPE argument, but stripping of
1401 typedefs does not. */
1404 check_typedef (struct type *type)
1406 struct type *orig_type = type;
1407 int is_const, is_volatile;
1411 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1413 if (!TYPE_TARGET_TYPE (type))
1418 /* It is dangerous to call lookup_symbol if we are currently
1419 reading a symtab. Infinite recursion is one danger. */
1420 if (currently_reading_symtab)
1423 name = type_name_no_tag (type);
1424 /* FIXME: shouldn't we separately check the TYPE_NAME and
1425 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1426 VAR_DOMAIN as appropriate? (this code was written before
1427 TYPE_NAME and TYPE_TAG_NAME were separate). */
1430 stub_noname_complaint ();
1433 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1435 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1436 else /* TYPE_CODE_UNDEF */
1437 TYPE_TARGET_TYPE (type) = alloc_type (NULL);
1439 type = TYPE_TARGET_TYPE (type);
1442 is_const = TYPE_CONST (type);
1443 is_volatile = TYPE_VOLATILE (type);
1445 /* If this is a struct/class/union with no fields, then check
1446 whether a full definition exists somewhere else. This is for
1447 systems where a type definition with no fields is issued for such
1448 types, instead of identifying them as stub types in the first
1451 if (TYPE_IS_OPAQUE (type)
1452 && opaque_type_resolution
1453 && !currently_reading_symtab)
1455 char *name = type_name_no_tag (type);
1456 struct type *newtype;
1459 stub_noname_complaint ();
1462 newtype = lookup_transparent_type (name);
1466 /* If the resolved type and the stub are in the same
1467 objfile, then replace the stub type with the real deal.
1468 But if they're in separate objfiles, leave the stub
1469 alone; we'll just look up the transparent type every time
1470 we call check_typedef. We can't create pointers between
1471 types allocated to different objfiles, since they may
1472 have different lifetimes. Trying to copy NEWTYPE over to
1473 TYPE's objfile is pointless, too, since you'll have to
1474 move over any other types NEWTYPE refers to, which could
1475 be an unbounded amount of stuff. */
1476 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
1477 make_cv_type (is_const, is_volatile, newtype, &type);
1482 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1484 else if (TYPE_STUB (type) && !currently_reading_symtab)
1486 char *name = type_name_no_tag (type);
1487 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1488 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1489 as appropriate? (this code was written before TYPE_NAME and
1490 TYPE_TAG_NAME were separate). */
1494 stub_noname_complaint ();
1497 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1500 /* Same as above for opaque types, we can replace the stub
1501 with the complete type only if they are int the same
1503 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
1504 make_cv_type (is_const, is_volatile,
1505 SYMBOL_TYPE (sym), &type);
1507 type = SYMBOL_TYPE (sym);
1511 if (TYPE_TARGET_STUB (type))
1513 struct type *range_type;
1514 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1516 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1520 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1521 && TYPE_NFIELDS (type) == 1
1522 && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
1523 == TYPE_CODE_RANGE))
1525 /* Now recompute the length of the array type, based on its
1526 number of elements and the target type's length.
1527 Watch out for Ada null Ada arrays where the high bound
1528 is smaller than the low bound. */
1529 const int low_bound = TYPE_LOW_BOUND (range_type);
1530 const int high_bound = TYPE_HIGH_BOUND (range_type);
1533 if (high_bound < low_bound)
1536 nb_elements = high_bound - low_bound + 1;
1538 TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
1539 TYPE_TARGET_STUB (type) = 0;
1541 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1543 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1544 TYPE_TARGET_STUB (type) = 0;
1547 /* Cache TYPE_LENGTH for future use. */
1548 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1552 /* Parse a type expression in the string [P..P+LENGTH). If an error
1553 occurs, silently return builtin_type_void. */
1555 static struct type *
1556 safe_parse_type (char *p, int length)
1558 struct ui_file *saved_gdb_stderr;
1561 /* Suppress error messages. */
1562 saved_gdb_stderr = gdb_stderr;
1563 gdb_stderr = ui_file_new ();
1565 /* Call parse_and_eval_type() without fear of longjmp()s. */
1566 if (!gdb_parse_and_eval_type (p, length, &type))
1567 type = builtin_type_void;
1569 /* Stop suppressing error messages. */
1570 ui_file_delete (gdb_stderr);
1571 gdb_stderr = saved_gdb_stderr;
1576 /* Ugly hack to convert method stubs into method types.
1578 He ain't kiddin'. This demangles the name of the method into a
1579 string including argument types, parses out each argument type,
1580 generates a string casting a zero to that type, evaluates the
1581 string, and stuffs the resulting type into an argtype vector!!!
1582 Then it knows the type of the whole function (including argument
1583 types for overloading), which info used to be in the stab's but was
1584 removed to hack back the space required for them. */
1587 check_stub_method (struct type *type, int method_id, int signature_id)
1590 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1591 char *demangled_name = cplus_demangle (mangled_name,
1592 DMGL_PARAMS | DMGL_ANSI);
1593 char *argtypetext, *p;
1594 int depth = 0, argcount = 1;
1595 struct field *argtypes;
1598 /* Make sure we got back a function string that we can use. */
1600 p = strchr (demangled_name, '(');
1604 if (demangled_name == NULL || p == NULL)
1605 error (_("Internal: Cannot demangle mangled name `%s'."),
1608 /* Now, read in the parameters that define this type. */
1613 if (*p == '(' || *p == '<')
1617 else if (*p == ')' || *p == '>')
1621 else if (*p == ',' && depth == 0)
1629 /* If we read one argument and it was ``void'', don't count it. */
1630 if (strncmp (argtypetext, "(void)", 6) == 0)
1633 /* We need one extra slot, for the THIS pointer. */
1635 argtypes = (struct field *)
1636 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1639 /* Add THIS pointer for non-static methods. */
1640 f = TYPE_FN_FIELDLIST1 (type, method_id);
1641 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1645 argtypes[0].type = lookup_pointer_type (type);
1649 if (*p != ')') /* () means no args, skip while */
1654 if (depth <= 0 && (*p == ',' || *p == ')'))
1656 /* Avoid parsing of ellipsis, they will be handled below.
1657 Also avoid ``void'' as above. */
1658 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1659 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1661 argtypes[argcount].type =
1662 safe_parse_type (argtypetext, p - argtypetext);
1665 argtypetext = p + 1;
1668 if (*p == '(' || *p == '<')
1672 else if (*p == ')' || *p == '>')
1681 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1683 /* Now update the old "stub" type into a real type. */
1684 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1685 TYPE_DOMAIN_TYPE (mtype) = type;
1686 TYPE_FIELDS (mtype) = argtypes;
1687 TYPE_NFIELDS (mtype) = argcount;
1688 TYPE_STUB (mtype) = 0;
1689 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1691 TYPE_VARARGS (mtype) = 1;
1693 xfree (demangled_name);
1696 /* This is the external interface to check_stub_method, above. This
1697 function unstubs all of the signatures for TYPE's METHOD_ID method
1698 name. After calling this function TYPE_FN_FIELD_STUB will be
1699 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1702 This function unfortunately can not die until stabs do. */
1705 check_stub_method_group (struct type *type, int method_id)
1707 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1708 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1709 int j, found_stub = 0;
1711 for (j = 0; j < len; j++)
1712 if (TYPE_FN_FIELD_STUB (f, j))
1715 check_stub_method (type, method_id, j);
1718 /* GNU v3 methods with incorrect names were corrected when we read
1719 in type information, because it was cheaper to do it then. The
1720 only GNU v2 methods with incorrect method names are operators and
1721 destructors; destructors were also corrected when we read in type
1724 Therefore the only thing we need to handle here are v2 operator
1726 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1729 char dem_opname[256];
1731 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1733 dem_opname, DMGL_ANSI);
1735 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1739 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1743 const struct cplus_struct_type cplus_struct_default;
1746 allocate_cplus_struct_type (struct type *type)
1748 if (!HAVE_CPLUS_STRUCT (type))
1750 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1751 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1752 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1756 /* Helper function to initialize the standard scalar types.
1758 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy of
1759 the string pointed to by name in the objfile_obstack for that
1760 objfile, and initialize the type name to that copy. There are
1761 places (mipsread.c in particular, where init_type is called with a
1762 NULL value for NAME). */
1765 init_type (enum type_code code, int length, int flags,
1766 char *name, struct objfile *objfile)
1770 type = alloc_type (objfile);
1771 TYPE_CODE (type) = code;
1772 TYPE_LENGTH (type) = length;
1774 gdb_assert (!(flags & (TYPE_FLAG_MIN - 1)));
1775 if (flags & TYPE_FLAG_UNSIGNED)
1776 TYPE_UNSIGNED (type) = 1;
1777 if (flags & TYPE_FLAG_NOSIGN)
1778 TYPE_NOSIGN (type) = 1;
1779 if (flags & TYPE_FLAG_STUB)
1780 TYPE_STUB (type) = 1;
1781 if (flags & TYPE_FLAG_TARGET_STUB)
1782 TYPE_TARGET_STUB (type) = 1;
1783 if (flags & TYPE_FLAG_STATIC)
1784 TYPE_STATIC (type) = 1;
1785 if (flags & TYPE_FLAG_PROTOTYPED)
1786 TYPE_PROTOTYPED (type) = 1;
1787 if (flags & TYPE_FLAG_INCOMPLETE)
1788 TYPE_INCOMPLETE (type) = 1;
1789 if (flags & TYPE_FLAG_VARARGS)
1790 TYPE_VARARGS (type) = 1;
1791 if (flags & TYPE_FLAG_VECTOR)
1792 TYPE_VECTOR (type) = 1;
1793 if (flags & TYPE_FLAG_STUB_SUPPORTED)
1794 TYPE_STUB_SUPPORTED (type) = 1;
1795 if (flags & TYPE_FLAG_NOTTEXT)
1796 TYPE_NOTTEXT (type) = 1;
1797 if (flags & TYPE_FLAG_FIXED_INSTANCE)
1798 TYPE_FIXED_INSTANCE (type) = 1;
1800 if ((name != NULL) && (objfile != NULL))
1802 TYPE_NAME (type) = obsavestring (name, strlen (name),
1803 &objfile->objfile_obstack);
1807 TYPE_NAME (type) = name;
1812 if (name && strcmp (name, "char") == 0)
1813 TYPE_NOSIGN (type) = 1;
1815 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1816 || code == TYPE_CODE_NAMESPACE)
1818 INIT_CPLUS_SPECIFIC (type);
1823 /* Helper function. Create an empty composite type. */
1826 init_composite_type (char *name, enum type_code code)
1829 gdb_assert (code == TYPE_CODE_STRUCT
1830 || code == TYPE_CODE_UNION);
1831 t = init_type (code, 0, 0, NULL, NULL);
1832 TYPE_TAG_NAME (t) = name;
1836 /* Helper function. Append a field to a composite type. */
1839 append_composite_type_field (struct type *t, char *name,
1843 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1844 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1845 sizeof (struct field) * TYPE_NFIELDS (t));
1846 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1847 memset (f, 0, sizeof f[0]);
1848 FIELD_TYPE (f[0]) = field;
1849 FIELD_NAME (f[0]) = name;
1850 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1852 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1853 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1855 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1857 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1858 if (TYPE_NFIELDS (t) > 1)
1860 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1861 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1867 can_dereference (struct type *t)
1869 /* FIXME: Should we return true for references as well as
1874 && TYPE_CODE (t) == TYPE_CODE_PTR
1875 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1879 is_integral_type (struct type *t)
1884 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1885 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1886 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
1887 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1888 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1889 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1892 /* Check whether BASE is an ancestor or base class or DCLASS
1893 Return 1 if so, and 0 if not.
1894 Note: callers may want to check for identity of the types before
1895 calling this function -- identical types are considered to satisfy
1896 the ancestor relationship even if they're identical. */
1899 is_ancestor (struct type *base, struct type *dclass)
1903 CHECK_TYPEDEF (base);
1904 CHECK_TYPEDEF (dclass);
1908 if (TYPE_NAME (base) && TYPE_NAME (dclass)
1909 && !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1912 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1913 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1921 /* Functions for overload resolution begin here */
1923 /* Compare two badness vectors A and B and return the result.
1924 0 => A and B are identical
1925 1 => A and B are incomparable
1926 2 => A is better than B
1927 3 => A is worse than B */
1930 compare_badness (struct badness_vector *a, struct badness_vector *b)
1934 short found_pos = 0; /* any positives in c? */
1935 short found_neg = 0; /* any negatives in c? */
1937 /* differing lengths => incomparable */
1938 if (a->length != b->length)
1941 /* Subtract b from a */
1942 for (i = 0; i < a->length; i++)
1944 tmp = a->rank[i] - b->rank[i];
1954 return 1; /* incomparable */
1956 return 3; /* A > B */
1962 return 2; /* A < B */
1964 return 0; /* A == B */
1968 /* Rank a function by comparing its parameter types (PARMS, length
1969 NPARMS), to the types of an argument list (ARGS, length NARGS).
1970 Return a pointer to a badness vector. This has NARGS + 1
1973 struct badness_vector *
1974 rank_function (struct type **parms, int nparms,
1975 struct type **args, int nargs)
1978 struct badness_vector *bv;
1979 int min_len = nparms < nargs ? nparms : nargs;
1981 bv = xmalloc (sizeof (struct badness_vector));
1982 bv->length = nargs + 1; /* add 1 for the length-match rank */
1983 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
1985 /* First compare the lengths of the supplied lists.
1986 If there is a mismatch, set it to a high value. */
1988 /* pai/1997-06-03 FIXME: when we have debug info about default
1989 arguments and ellipsis parameter lists, we should consider those
1990 and rank the length-match more finely. */
1992 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
1994 /* Now rank all the parameters of the candidate function */
1995 for (i = 1; i <= min_len; i++)
1996 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
1998 /* If more arguments than parameters, add dummy entries */
1999 for (i = min_len + 1; i <= nargs; i++)
2000 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2005 /* Compare the names of two integer types, assuming that any sign
2006 qualifiers have been checked already. We do it this way because
2007 there may be an "int" in the name of one of the types. */
2010 integer_types_same_name_p (const char *first, const char *second)
2012 int first_p, second_p;
2014 /* If both are shorts, return 1; if neither is a short, keep
2016 first_p = (strstr (first, "short") != NULL);
2017 second_p = (strstr (second, "short") != NULL);
2018 if (first_p && second_p)
2020 if (first_p || second_p)
2023 /* Likewise for long. */
2024 first_p = (strstr (first, "long") != NULL);
2025 second_p = (strstr (second, "long") != NULL);
2026 if (first_p && second_p)
2028 if (first_p || second_p)
2031 /* Likewise for char. */
2032 first_p = (strstr (first, "char") != NULL);
2033 second_p = (strstr (second, "char") != NULL);
2034 if (first_p && second_p)
2036 if (first_p || second_p)
2039 /* They must both be ints. */
2043 /* Compare one type (PARM) for compatibility with another (ARG).
2044 * PARM is intended to be the parameter type of a function; and
2045 * ARG is the supplied argument's type. This function tests if
2046 * the latter can be converted to the former.
2048 * Return 0 if they are identical types;
2049 * Otherwise, return an integer which corresponds to how compatible
2050 * PARM is to ARG. The higher the return value, the worse the match.
2051 * Generally the "bad" conversions are all uniformly assigned a 100. */
2054 rank_one_type (struct type *parm, struct type *arg)
2056 /* Identical type pointers. */
2057 /* However, this still doesn't catch all cases of same type for arg
2058 and param. The reason is that builtin types are different from
2059 the same ones constructed from the object. */
2063 /* Resolve typedefs */
2064 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2065 parm = check_typedef (parm);
2066 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2067 arg = check_typedef (arg);
2070 Well, damnit, if the names are exactly the same, I'll say they
2071 are exactly the same. This happens when we generate method
2072 stubs. The types won't point to the same address, but they
2073 really are the same.
2076 if (TYPE_NAME (parm) && TYPE_NAME (arg)
2077 && !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2080 /* Check if identical after resolving typedefs. */
2084 /* See through references, since we can almost make non-references
2086 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2087 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2088 + REFERENCE_CONVERSION_BADNESS);
2089 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2090 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2091 + REFERENCE_CONVERSION_BADNESS);
2093 /* Debugging only. */
2094 fprintf_filtered (gdb_stderr,
2095 "------ Arg is %s [%d], parm is %s [%d]\n",
2096 TYPE_NAME (arg), TYPE_CODE (arg),
2097 TYPE_NAME (parm), TYPE_CODE (parm));
2099 /* x -> y means arg of type x being supplied for parameter of type y */
2101 switch (TYPE_CODE (parm))
2104 switch (TYPE_CODE (arg))
2107 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2108 return VOID_PTR_CONVERSION_BADNESS;
2110 return rank_one_type (TYPE_TARGET_TYPE (parm),
2111 TYPE_TARGET_TYPE (arg));
2112 case TYPE_CODE_ARRAY:
2113 return rank_one_type (TYPE_TARGET_TYPE (parm),
2114 TYPE_TARGET_TYPE (arg));
2115 case TYPE_CODE_FUNC:
2116 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2118 case TYPE_CODE_ENUM:
2119 case TYPE_CODE_FLAGS:
2120 case TYPE_CODE_CHAR:
2121 case TYPE_CODE_RANGE:
2122 case TYPE_CODE_BOOL:
2123 return POINTER_CONVERSION_BADNESS;
2125 return INCOMPATIBLE_TYPE_BADNESS;
2127 case TYPE_CODE_ARRAY:
2128 switch (TYPE_CODE (arg))
2131 case TYPE_CODE_ARRAY:
2132 return rank_one_type (TYPE_TARGET_TYPE (parm),
2133 TYPE_TARGET_TYPE (arg));
2135 return INCOMPATIBLE_TYPE_BADNESS;
2137 case TYPE_CODE_FUNC:
2138 switch (TYPE_CODE (arg))
2140 case TYPE_CODE_PTR: /* funcptr -> func */
2141 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2143 return INCOMPATIBLE_TYPE_BADNESS;
2146 switch (TYPE_CODE (arg))
2149 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2151 /* Deal with signed, unsigned, and plain chars and
2152 signed and unsigned ints. */
2153 if (TYPE_NOSIGN (parm))
2155 /* This case only for character types */
2156 if (TYPE_NOSIGN (arg))
2157 return 0; /* plain char -> plain char */
2158 else /* signed/unsigned char -> plain char */
2159 return INTEGER_CONVERSION_BADNESS;
2161 else if (TYPE_UNSIGNED (parm))
2163 if (TYPE_UNSIGNED (arg))
2165 /* unsigned int -> unsigned int, or
2166 unsigned long -> unsigned long */
2167 if (integer_types_same_name_p (TYPE_NAME (parm),
2170 else if (integer_types_same_name_p (TYPE_NAME (arg),
2172 && integer_types_same_name_p (TYPE_NAME (parm),
2174 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2176 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
2180 if (integer_types_same_name_p (TYPE_NAME (arg),
2182 && integer_types_same_name_p (TYPE_NAME (parm),
2184 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
2186 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2189 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2191 if (integer_types_same_name_p (TYPE_NAME (parm),
2194 else if (integer_types_same_name_p (TYPE_NAME (arg),
2196 && integer_types_same_name_p (TYPE_NAME (parm),
2198 return INTEGER_PROMOTION_BADNESS;
2200 return INTEGER_CONVERSION_BADNESS;
2203 return INTEGER_CONVERSION_BADNESS;
2205 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2206 return INTEGER_PROMOTION_BADNESS;
2208 return INTEGER_CONVERSION_BADNESS;
2209 case TYPE_CODE_ENUM:
2210 case TYPE_CODE_FLAGS:
2211 case TYPE_CODE_CHAR:
2212 case TYPE_CODE_RANGE:
2213 case TYPE_CODE_BOOL:
2214 return INTEGER_PROMOTION_BADNESS;
2216 return INT_FLOAT_CONVERSION_BADNESS;
2218 return NS_POINTER_CONVERSION_BADNESS;
2220 return INCOMPATIBLE_TYPE_BADNESS;
2223 case TYPE_CODE_ENUM:
2224 switch (TYPE_CODE (arg))
2227 case TYPE_CODE_CHAR:
2228 case TYPE_CODE_RANGE:
2229 case TYPE_CODE_BOOL:
2230 case TYPE_CODE_ENUM:
2231 return INTEGER_CONVERSION_BADNESS;
2233 return INT_FLOAT_CONVERSION_BADNESS;
2235 return INCOMPATIBLE_TYPE_BADNESS;
2238 case TYPE_CODE_CHAR:
2239 switch (TYPE_CODE (arg))
2241 case TYPE_CODE_RANGE:
2242 case TYPE_CODE_BOOL:
2243 case TYPE_CODE_ENUM:
2244 return INTEGER_CONVERSION_BADNESS;
2246 return INT_FLOAT_CONVERSION_BADNESS;
2248 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2249 return INTEGER_CONVERSION_BADNESS;
2250 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2251 return INTEGER_PROMOTION_BADNESS;
2252 /* >>> !! else fall through !! <<< */
2253 case TYPE_CODE_CHAR:
2254 /* Deal with signed, unsigned, and plain chars for C++ and
2255 with int cases falling through from previous case. */
2256 if (TYPE_NOSIGN (parm))
2258 if (TYPE_NOSIGN (arg))
2261 return INTEGER_CONVERSION_BADNESS;
2263 else if (TYPE_UNSIGNED (parm))
2265 if (TYPE_UNSIGNED (arg))
2268 return INTEGER_PROMOTION_BADNESS;
2270 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2273 return INTEGER_CONVERSION_BADNESS;
2275 return INCOMPATIBLE_TYPE_BADNESS;
2278 case TYPE_CODE_RANGE:
2279 switch (TYPE_CODE (arg))
2282 case TYPE_CODE_CHAR:
2283 case TYPE_CODE_RANGE:
2284 case TYPE_CODE_BOOL:
2285 case TYPE_CODE_ENUM:
2286 return INTEGER_CONVERSION_BADNESS;
2288 return INT_FLOAT_CONVERSION_BADNESS;
2290 return INCOMPATIBLE_TYPE_BADNESS;
2293 case TYPE_CODE_BOOL:
2294 switch (TYPE_CODE (arg))
2297 case TYPE_CODE_CHAR:
2298 case TYPE_CODE_RANGE:
2299 case TYPE_CODE_ENUM:
2302 return BOOLEAN_CONVERSION_BADNESS;
2303 case TYPE_CODE_BOOL:
2306 return INCOMPATIBLE_TYPE_BADNESS;
2310 switch (TYPE_CODE (arg))
2313 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2314 return FLOAT_PROMOTION_BADNESS;
2315 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2318 return FLOAT_CONVERSION_BADNESS;
2320 case TYPE_CODE_BOOL:
2321 case TYPE_CODE_ENUM:
2322 case TYPE_CODE_RANGE:
2323 case TYPE_CODE_CHAR:
2324 return INT_FLOAT_CONVERSION_BADNESS;
2326 return INCOMPATIBLE_TYPE_BADNESS;
2329 case TYPE_CODE_COMPLEX:
2330 switch (TYPE_CODE (arg))
2331 { /* Strictly not needed for C++, but... */
2333 return FLOAT_PROMOTION_BADNESS;
2334 case TYPE_CODE_COMPLEX:
2337 return INCOMPATIBLE_TYPE_BADNESS;
2340 case TYPE_CODE_STRUCT:
2341 /* currently same as TYPE_CODE_CLASS */
2342 switch (TYPE_CODE (arg))
2344 case TYPE_CODE_STRUCT:
2345 /* Check for derivation */
2346 if (is_ancestor (parm, arg))
2347 return BASE_CONVERSION_BADNESS;
2348 /* else fall through */
2350 return INCOMPATIBLE_TYPE_BADNESS;
2353 case TYPE_CODE_UNION:
2354 switch (TYPE_CODE (arg))
2356 case TYPE_CODE_UNION:
2358 return INCOMPATIBLE_TYPE_BADNESS;
2361 case TYPE_CODE_MEMBERPTR:
2362 switch (TYPE_CODE (arg))
2365 return INCOMPATIBLE_TYPE_BADNESS;
2368 case TYPE_CODE_METHOD:
2369 switch (TYPE_CODE (arg))
2373 return INCOMPATIBLE_TYPE_BADNESS;
2377 switch (TYPE_CODE (arg))
2381 return INCOMPATIBLE_TYPE_BADNESS;
2386 switch (TYPE_CODE (arg))
2390 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
2391 TYPE_FIELD_TYPE (arg, 0));
2393 return INCOMPATIBLE_TYPE_BADNESS;
2396 case TYPE_CODE_VOID:
2398 return INCOMPATIBLE_TYPE_BADNESS;
2399 } /* switch (TYPE_CODE (arg)) */
2403 /* End of functions for overload resolution */
2406 print_bit_vector (B_TYPE *bits, int nbits)
2410 for (bitno = 0; bitno < nbits; bitno++)
2412 if ((bitno % 8) == 0)
2414 puts_filtered (" ");
2416 if (B_TST (bits, bitno))
2417 printf_filtered (("1"));
2419 printf_filtered (("0"));
2423 /* Note the first arg should be the "this" pointer, we may not want to
2424 include it since we may get into a infinitely recursive
2428 print_arg_types (struct field *args, int nargs, int spaces)
2434 for (i = 0; i < nargs; i++)
2435 recursive_dump_type (args[i].type, spaces + 2);
2440 field_is_static (struct field *f)
2442 /* "static" fields are the fields whose location is not relative
2443 to the address of the enclosing struct. It would be nice to
2444 have a dedicated flag that would be set for static fields when
2445 the type is being created. But in practice, checking the field
2446 loc_kind should give us an accurate answer (at least as long as
2447 we assume that DWARF block locations are not going to be used
2448 for static fields). FIXME? */
2449 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
2450 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
2454 dump_fn_fieldlists (struct type *type, int spaces)
2460 printfi_filtered (spaces, "fn_fieldlists ");
2461 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2462 printf_filtered ("\n");
2463 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2465 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2466 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2468 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2469 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2471 printf_filtered (_(") length %d\n"),
2472 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2473 for (overload_idx = 0;
2474 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2477 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2479 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2480 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2482 printf_filtered (")\n");
2483 printfi_filtered (spaces + 8, "type ");
2484 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
2486 printf_filtered ("\n");
2488 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2491 printfi_filtered (spaces + 8, "args ");
2492 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
2494 printf_filtered ("\n");
2496 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2497 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f,
2500 printfi_filtered (spaces + 8, "fcontext ");
2501 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2503 printf_filtered ("\n");
2505 printfi_filtered (spaces + 8, "is_const %d\n",
2506 TYPE_FN_FIELD_CONST (f, overload_idx));
2507 printfi_filtered (spaces + 8, "is_volatile %d\n",
2508 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2509 printfi_filtered (spaces + 8, "is_private %d\n",
2510 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2511 printfi_filtered (spaces + 8, "is_protected %d\n",
2512 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2513 printfi_filtered (spaces + 8, "is_stub %d\n",
2514 TYPE_FN_FIELD_STUB (f, overload_idx));
2515 printfi_filtered (spaces + 8, "voffset %u\n",
2516 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2522 print_cplus_stuff (struct type *type, int spaces)
2524 printfi_filtered (spaces, "n_baseclasses %d\n",
2525 TYPE_N_BASECLASSES (type));
2526 printfi_filtered (spaces, "nfn_fields %d\n",
2527 TYPE_NFN_FIELDS (type));
2528 printfi_filtered (spaces, "nfn_fields_total %d\n",
2529 TYPE_NFN_FIELDS_TOTAL (type));
2530 if (TYPE_N_BASECLASSES (type) > 0)
2532 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2533 TYPE_N_BASECLASSES (type));
2534 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
2536 printf_filtered (")");
2538 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2539 TYPE_N_BASECLASSES (type));
2540 puts_filtered ("\n");
2542 if (TYPE_NFIELDS (type) > 0)
2544 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2546 printfi_filtered (spaces,
2547 "private_field_bits (%d bits at *",
2548 TYPE_NFIELDS (type));
2549 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
2551 printf_filtered (")");
2552 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2553 TYPE_NFIELDS (type));
2554 puts_filtered ("\n");
2556 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2558 printfi_filtered (spaces,
2559 "protected_field_bits (%d bits at *",
2560 TYPE_NFIELDS (type));
2561 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
2563 printf_filtered (")");
2564 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2565 TYPE_NFIELDS (type));
2566 puts_filtered ("\n");
2569 if (TYPE_NFN_FIELDS (type) > 0)
2571 dump_fn_fieldlists (type, spaces);
2575 static struct obstack dont_print_type_obstack;
2578 recursive_dump_type (struct type *type, int spaces)
2583 obstack_begin (&dont_print_type_obstack, 0);
2585 if (TYPE_NFIELDS (type) > 0
2586 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2588 struct type **first_dont_print
2589 = (struct type **) obstack_base (&dont_print_type_obstack);
2591 int i = (struct type **)
2592 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
2596 if (type == first_dont_print[i])
2598 printfi_filtered (spaces, "type node ");
2599 gdb_print_host_address (type, gdb_stdout);
2600 printf_filtered (_(" <same as already seen type>\n"));
2605 obstack_ptr_grow (&dont_print_type_obstack, type);
2608 printfi_filtered (spaces, "type node ");
2609 gdb_print_host_address (type, gdb_stdout);
2610 printf_filtered ("\n");
2611 printfi_filtered (spaces, "name '%s' (",
2612 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2613 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2614 printf_filtered (")\n");
2615 printfi_filtered (spaces, "tagname '%s' (",
2616 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2617 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2618 printf_filtered (")\n");
2619 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2620 switch (TYPE_CODE (type))
2622 case TYPE_CODE_UNDEF:
2623 printf_filtered ("(TYPE_CODE_UNDEF)");
2626 printf_filtered ("(TYPE_CODE_PTR)");
2628 case TYPE_CODE_ARRAY:
2629 printf_filtered ("(TYPE_CODE_ARRAY)");
2631 case TYPE_CODE_STRUCT:
2632 printf_filtered ("(TYPE_CODE_STRUCT)");
2634 case TYPE_CODE_UNION:
2635 printf_filtered ("(TYPE_CODE_UNION)");
2637 case TYPE_CODE_ENUM:
2638 printf_filtered ("(TYPE_CODE_ENUM)");
2640 case TYPE_CODE_FLAGS:
2641 printf_filtered ("(TYPE_CODE_FLAGS)");
2643 case TYPE_CODE_FUNC:
2644 printf_filtered ("(TYPE_CODE_FUNC)");
2647 printf_filtered ("(TYPE_CODE_INT)");
2650 printf_filtered ("(TYPE_CODE_FLT)");
2652 case TYPE_CODE_VOID:
2653 printf_filtered ("(TYPE_CODE_VOID)");
2656 printf_filtered ("(TYPE_CODE_SET)");
2658 case TYPE_CODE_RANGE:
2659 printf_filtered ("(TYPE_CODE_RANGE)");
2661 case TYPE_CODE_STRING:
2662 printf_filtered ("(TYPE_CODE_STRING)");
2664 case TYPE_CODE_BITSTRING:
2665 printf_filtered ("(TYPE_CODE_BITSTRING)");
2667 case TYPE_CODE_ERROR:
2668 printf_filtered ("(TYPE_CODE_ERROR)");
2670 case TYPE_CODE_MEMBERPTR:
2671 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2673 case TYPE_CODE_METHODPTR:
2674 printf_filtered ("(TYPE_CODE_METHODPTR)");
2676 case TYPE_CODE_METHOD:
2677 printf_filtered ("(TYPE_CODE_METHOD)");
2680 printf_filtered ("(TYPE_CODE_REF)");
2682 case TYPE_CODE_CHAR:
2683 printf_filtered ("(TYPE_CODE_CHAR)");
2685 case TYPE_CODE_BOOL:
2686 printf_filtered ("(TYPE_CODE_BOOL)");
2688 case TYPE_CODE_COMPLEX:
2689 printf_filtered ("(TYPE_CODE_COMPLEX)");
2691 case TYPE_CODE_TYPEDEF:
2692 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2694 case TYPE_CODE_TEMPLATE:
2695 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2697 case TYPE_CODE_TEMPLATE_ARG:
2698 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2700 case TYPE_CODE_NAMESPACE:
2701 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2704 printf_filtered ("(UNKNOWN TYPE CODE)");
2707 puts_filtered ("\n");
2708 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2709 printfi_filtered (spaces, "objfile ");
2710 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2711 printf_filtered ("\n");
2712 printfi_filtered (spaces, "target_type ");
2713 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2714 printf_filtered ("\n");
2715 if (TYPE_TARGET_TYPE (type) != NULL)
2717 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2719 printfi_filtered (spaces, "pointer_type ");
2720 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2721 printf_filtered ("\n");
2722 printfi_filtered (spaces, "reference_type ");
2723 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2724 printf_filtered ("\n");
2725 printfi_filtered (spaces, "type_chain ");
2726 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
2727 printf_filtered ("\n");
2728 printfi_filtered (spaces, "instance_flags 0x%x",
2729 TYPE_INSTANCE_FLAGS (type));
2730 if (TYPE_CONST (type))
2732 puts_filtered (" TYPE_FLAG_CONST");
2734 if (TYPE_VOLATILE (type))
2736 puts_filtered (" TYPE_FLAG_VOLATILE");
2738 if (TYPE_CODE_SPACE (type))
2740 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2742 if (TYPE_DATA_SPACE (type))
2744 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2746 if (TYPE_ADDRESS_CLASS_1 (type))
2748 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
2750 if (TYPE_ADDRESS_CLASS_2 (type))
2752 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
2754 puts_filtered ("\n");
2756 printfi_filtered (spaces, "flags");
2757 if (TYPE_UNSIGNED (type))
2759 puts_filtered (" TYPE_FLAG_UNSIGNED");
2761 if (TYPE_NOSIGN (type))
2763 puts_filtered (" TYPE_FLAG_NOSIGN");
2765 if (TYPE_STUB (type))
2767 puts_filtered (" TYPE_FLAG_STUB");
2769 if (TYPE_TARGET_STUB (type))
2771 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2773 if (TYPE_STATIC (type))
2775 puts_filtered (" TYPE_FLAG_STATIC");
2777 if (TYPE_PROTOTYPED (type))
2779 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2781 if (TYPE_INCOMPLETE (type))
2783 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2785 if (TYPE_VARARGS (type))
2787 puts_filtered (" TYPE_FLAG_VARARGS");
2789 /* This is used for things like AltiVec registers on ppc. Gcc emits
2790 an attribute for the array type, which tells whether or not we
2791 have a vector, instead of a regular array. */
2792 if (TYPE_VECTOR (type))
2794 puts_filtered (" TYPE_FLAG_VECTOR");
2796 if (TYPE_FIXED_INSTANCE (type))
2798 puts_filtered (" TYPE_FIXED_INSTANCE");
2800 if (TYPE_STUB_SUPPORTED (type))
2802 puts_filtered (" TYPE_STUB_SUPPORTED");
2804 if (TYPE_NOTTEXT (type))
2806 puts_filtered (" TYPE_NOTTEXT");
2808 puts_filtered ("\n");
2809 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
2810 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
2811 puts_filtered ("\n");
2812 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
2814 printfi_filtered (spaces + 2,
2815 "[%d] bitpos %d bitsize %d type ",
2816 idx, TYPE_FIELD_BITPOS (type, idx),
2817 TYPE_FIELD_BITSIZE (type, idx));
2818 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
2819 printf_filtered (" name '%s' (",
2820 TYPE_FIELD_NAME (type, idx) != NULL
2821 ? TYPE_FIELD_NAME (type, idx)
2823 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
2824 printf_filtered (")\n");
2825 if (TYPE_FIELD_TYPE (type, idx) != NULL)
2827 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
2830 printfi_filtered (spaces, "vptr_basetype ");
2831 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
2832 puts_filtered ("\n");
2833 if (TYPE_VPTR_BASETYPE (type) != NULL)
2835 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
2837 printfi_filtered (spaces, "vptr_fieldno %d\n",
2838 TYPE_VPTR_FIELDNO (type));
2839 switch (TYPE_CODE (type))
2841 case TYPE_CODE_STRUCT:
2842 printfi_filtered (spaces, "cplus_stuff ");
2843 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
2845 puts_filtered ("\n");
2846 print_cplus_stuff (type, spaces);
2850 printfi_filtered (spaces, "floatformat ");
2851 if (TYPE_FLOATFORMAT (type) == NULL)
2852 puts_filtered ("(null)");
2855 puts_filtered ("{ ");
2856 if (TYPE_FLOATFORMAT (type)[0] == NULL
2857 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
2858 puts_filtered ("(null)");
2860 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
2862 puts_filtered (", ");
2863 if (TYPE_FLOATFORMAT (type)[1] == NULL
2864 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
2865 puts_filtered ("(null)");
2867 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
2869 puts_filtered (" }");
2871 puts_filtered ("\n");
2875 /* We have to pick one of the union types to be able print and
2876 test the value. Pick cplus_struct_type, even though we know
2877 it isn't any particular one. */
2878 printfi_filtered (spaces, "type_specific ");
2879 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2880 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
2882 printf_filtered (_(" (unknown data form)"));
2884 printf_filtered ("\n");
2889 obstack_free (&dont_print_type_obstack, NULL);
2892 /* Trivial helpers for the libiberty hash table, for mapping one
2897 struct type *old, *new;
2901 type_pair_hash (const void *item)
2903 const struct type_pair *pair = item;
2904 return htab_hash_pointer (pair->old);
2908 type_pair_eq (const void *item_lhs, const void *item_rhs)
2910 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
2911 return lhs->old == rhs->old;
2914 /* Allocate the hash table used by copy_type_recursive to walk
2915 types without duplicates. We use OBJFILE's obstack, because
2916 OBJFILE is about to be deleted. */
2919 create_copied_types_hash (struct objfile *objfile)
2921 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
2922 NULL, &objfile->objfile_obstack,
2923 hashtab_obstack_allocate,
2924 dummy_obstack_deallocate);
2927 /* Recursively copy (deep copy) TYPE, if it is associated with
2928 OBJFILE. Return a new type allocated using malloc, a saved type if
2929 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
2930 not associated with OBJFILE. */
2933 copy_type_recursive (struct objfile *objfile,
2935 htab_t copied_types)
2937 struct type_pair *stored, pair;
2939 struct type *new_type;
2941 if (TYPE_OBJFILE (type) == NULL)
2944 /* This type shouldn't be pointing to any types in other objfiles;
2945 if it did, the type might disappear unexpectedly. */
2946 gdb_assert (TYPE_OBJFILE (type) == objfile);
2949 slot = htab_find_slot (copied_types, &pair, INSERT);
2951 return ((struct type_pair *) *slot)->new;
2953 new_type = alloc_type (NULL);
2955 /* We must add the new type to the hash table immediately, in case
2956 we encounter this type again during a recursive call below. */
2957 stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
2959 stored->new = new_type;
2962 /* Copy the common fields of types. For the main type, we simply
2963 copy the entire thing and then update specific fields as needed. */
2964 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
2965 TYPE_OBJFILE (new_type) = NULL;
2967 if (TYPE_NAME (type))
2968 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
2969 if (TYPE_TAG_NAME (type))
2970 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
2972 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
2973 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
2975 /* Copy the fields. */
2976 if (TYPE_NFIELDS (type))
2980 nfields = TYPE_NFIELDS (type);
2981 TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
2982 memset (TYPE_FIELDS (new_type), 0, sizeof (struct field) * nfields);
2983 for (i = 0; i < nfields; i++)
2985 TYPE_FIELD_ARTIFICIAL (new_type, i) =
2986 TYPE_FIELD_ARTIFICIAL (type, i);
2987 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
2988 if (TYPE_FIELD_TYPE (type, i))
2989 TYPE_FIELD_TYPE (new_type, i)
2990 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
2992 if (TYPE_FIELD_NAME (type, i))
2993 TYPE_FIELD_NAME (new_type, i) =
2994 xstrdup (TYPE_FIELD_NAME (type, i));
2995 switch (TYPE_FIELD_LOC_KIND (type, i))
2997 case FIELD_LOC_KIND_BITPOS:
2998 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
2999 TYPE_FIELD_BITPOS (type, i));
3001 case FIELD_LOC_KIND_PHYSADDR:
3002 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
3003 TYPE_FIELD_STATIC_PHYSADDR (type, i));
3005 case FIELD_LOC_KIND_PHYSNAME:
3006 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
3007 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
3011 internal_error (__FILE__, __LINE__,
3012 _("Unexpected type field location kind: %d"),
3013 TYPE_FIELD_LOC_KIND (type, i));
3018 /* Copy pointers to other types. */
3019 if (TYPE_TARGET_TYPE (type))
3020 TYPE_TARGET_TYPE (new_type) =
3021 copy_type_recursive (objfile,
3022 TYPE_TARGET_TYPE (type),
3024 if (TYPE_VPTR_BASETYPE (type))
3025 TYPE_VPTR_BASETYPE (new_type) =
3026 copy_type_recursive (objfile,
3027 TYPE_VPTR_BASETYPE (type),
3029 /* Maybe copy the type_specific bits.
3031 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3032 base classes and methods. There's no fundamental reason why we
3033 can't, but at the moment it is not needed. */
3035 if (TYPE_CODE (type) == TYPE_CODE_FLT)
3036 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
3037 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3038 || TYPE_CODE (type) == TYPE_CODE_UNION
3039 || TYPE_CODE (type) == TYPE_CODE_TEMPLATE
3040 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
3041 INIT_CPLUS_SPECIFIC (new_type);
3046 /* Make a copy of the given TYPE, except that the pointer & reference
3047 types are not preserved.
3049 This function assumes that the given type has an associated objfile.
3050 This objfile is used to allocate the new type. */
3053 copy_type (const struct type *type)
3055 struct type *new_type;
3057 gdb_assert (TYPE_OBJFILE (type) != NULL);
3059 new_type = alloc_type (TYPE_OBJFILE (type));
3060 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
3061 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
3062 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
3063 sizeof (struct main_type));
3068 static struct type *
3069 build_flt (int bit, char *name, const struct floatformat **floatformats)
3075 gdb_assert (floatformats != NULL);
3076 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
3077 bit = floatformats[0]->totalsize;
3079 gdb_assert (bit >= 0);
3081 t = init_type (TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, 0, name, NULL);
3082 TYPE_FLOATFORMAT (t) = floatformats;
3086 static struct gdbarch_data *gdbtypes_data;
3088 const struct builtin_type *
3089 builtin_type (struct gdbarch *gdbarch)
3091 return gdbarch_data (gdbarch, gdbtypes_data);
3095 static struct type *
3096 build_complex (int bit, char *name, struct type *target_type)
3099 if (bit <= 0 || target_type == builtin_type_error)
3101 gdb_assert (builtin_type_error != NULL);
3102 return builtin_type_error;
3104 t = init_type (TYPE_CODE_COMPLEX, 2 * bit / TARGET_CHAR_BIT,
3105 0, name, (struct objfile *) NULL);
3106 TYPE_TARGET_TYPE (t) = target_type;
3111 gdbtypes_post_init (struct gdbarch *gdbarch)
3113 struct builtin_type *builtin_type
3114 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
3116 builtin_type->builtin_void =
3117 init_type (TYPE_CODE_VOID, 1,
3119 "void", (struct objfile *) NULL);
3120 builtin_type->builtin_char =
3121 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3123 | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
3124 "char", (struct objfile *) NULL);
3125 builtin_type->builtin_signed_char =
3126 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3128 "signed char", (struct objfile *) NULL);
3129 builtin_type->builtin_unsigned_char =
3130 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3132 "unsigned char", (struct objfile *) NULL);
3133 builtin_type->builtin_short =
3134 init_type (TYPE_CODE_INT,
3135 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
3136 0, "short", (struct objfile *) NULL);
3137 builtin_type->builtin_unsigned_short =
3138 init_type (TYPE_CODE_INT,
3139 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
3140 TYPE_FLAG_UNSIGNED, "unsigned short",
3141 (struct objfile *) NULL);
3142 builtin_type->builtin_int =
3143 init_type (TYPE_CODE_INT,
3144 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
3145 0, "int", (struct objfile *) NULL);
3146 builtin_type->builtin_unsigned_int =
3147 init_type (TYPE_CODE_INT,
3148 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
3149 TYPE_FLAG_UNSIGNED, "unsigned int",
3150 (struct objfile *) NULL);
3151 builtin_type->builtin_long =
3152 init_type (TYPE_CODE_INT,
3153 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
3154 0, "long", (struct objfile *) NULL);
3155 builtin_type->builtin_unsigned_long =
3156 init_type (TYPE_CODE_INT,
3157 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
3158 TYPE_FLAG_UNSIGNED, "unsigned long",
3159 (struct objfile *) NULL);
3160 builtin_type->builtin_long_long =
3161 init_type (TYPE_CODE_INT,
3162 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
3163 0, "long long", (struct objfile *) NULL);
3164 builtin_type->builtin_unsigned_long_long =
3165 init_type (TYPE_CODE_INT,
3166 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
3167 TYPE_FLAG_UNSIGNED, "unsigned long long",
3168 (struct objfile *) NULL);
3169 builtin_type->builtin_float
3170 = build_flt (gdbarch_float_bit (gdbarch), "float",
3171 gdbarch_float_format (gdbarch));
3172 builtin_type->builtin_double
3173 = build_flt (gdbarch_double_bit (gdbarch), "double",
3174 gdbarch_double_format (gdbarch));
3175 builtin_type->builtin_long_double
3176 = build_flt (gdbarch_long_double_bit (gdbarch), "long double",
3177 gdbarch_long_double_format (gdbarch));
3178 builtin_type->builtin_complex
3179 = build_complex (gdbarch_float_bit (gdbarch), "complex",
3180 builtin_type->builtin_float);
3181 builtin_type->builtin_double_complex
3182 = build_complex (gdbarch_double_bit (gdbarch), "double complex",
3183 builtin_type->builtin_double);
3184 builtin_type->builtin_string =
3185 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3187 "string", (struct objfile *) NULL);
3188 builtin_type->builtin_bool =
3189 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3191 "bool", (struct objfile *) NULL);
3193 /* The following three are about decimal floating point types, which
3194 are 32-bits, 64-bits and 128-bits respectively. */
3195 builtin_type->builtin_decfloat
3196 = init_type (TYPE_CODE_DECFLOAT, 32 / 8,
3198 "_Decimal32", (struct objfile *) NULL);
3199 builtin_type->builtin_decdouble
3200 = init_type (TYPE_CODE_DECFLOAT, 64 / 8,
3202 "_Decimal64", (struct objfile *) NULL);
3203 builtin_type->builtin_declong
3204 = init_type (TYPE_CODE_DECFLOAT, 128 / 8,
3206 "_Decimal128", (struct objfile *) NULL);
3208 /* Pointer/Address types. */
3210 /* NOTE: on some targets, addresses and pointers are not necessarily
3211 the same --- for example, on the D10V, pointers are 16 bits long,
3212 but addresses are 32 bits long. See doc/gdbint.texinfo,
3213 ``Pointers Are Not Always Addresses''.
3216 - gdb's `struct type' always describes the target's
3218 - gdb's `struct value' objects should always hold values in
3220 - gdb's CORE_ADDR values are addresses in the unified virtual
3221 address space that the assembler and linker work with. Thus,
3222 since target_read_memory takes a CORE_ADDR as an argument, it
3223 can access any memory on the target, even if the processor has
3224 separate code and data address spaces.
3227 - If v is a value holding a D10V code pointer, its contents are
3228 in target form: a big-endian address left-shifted two bits.
3229 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3230 sizeof (void *) == 2 on the target.
3232 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3233 target type for a value the target will never see. It's only
3234 used to hold the values of (typeless) linker symbols, which are
3235 indeed in the unified virtual address space. */
3237 builtin_type->builtin_data_ptr =
3238 make_pointer_type (builtin_type->builtin_void, NULL);
3239 builtin_type->builtin_func_ptr =
3240 lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
3241 builtin_type->builtin_core_addr =
3242 init_type (TYPE_CODE_INT,
3243 gdbarch_addr_bit (gdbarch) / 8,
3245 "__CORE_ADDR", (struct objfile *) NULL);
3248 /* The following set of types is used for symbols with no
3249 debug information. */
3250 builtin_type->nodebug_text_symbol =
3251 init_type (TYPE_CODE_FUNC, 1, 0,
3252 "<text variable, no debug info>", NULL);
3253 TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol) =
3254 builtin_type->builtin_int;
3255 builtin_type->nodebug_data_symbol =
3256 init_type (TYPE_CODE_INT,
3257 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
3258 "<data variable, no debug info>", NULL);
3259 builtin_type->nodebug_unknown_symbol =
3260 init_type (TYPE_CODE_INT, 1, 0,
3261 "<variable (not text or data), no debug info>", NULL);
3262 builtin_type->nodebug_tls_symbol =
3263 init_type (TYPE_CODE_INT,
3264 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
3265 "<thread local variable, no debug info>", NULL);
3267 return builtin_type;
3270 extern void _initialize_gdbtypes (void);
3272 _initialize_gdbtypes (void)
3274 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
3276 /* FIXME: The following types are architecture-neutral. However,
3277 they contain pointer_type and reference_type fields potentially
3278 caching pointer or reference types that *are* architecture
3282 init_type (TYPE_CODE_INT, 0 / 8,
3284 "int0_t", (struct objfile *) NULL);
3286 init_type (TYPE_CODE_INT, 8 / 8,
3288 "int8_t", (struct objfile *) NULL);
3289 builtin_type_uint8 =
3290 init_type (TYPE_CODE_INT, 8 / 8,
3291 TYPE_FLAG_UNSIGNED | TYPE_FLAG_NOTTEXT,
3292 "uint8_t", (struct objfile *) NULL);
3293 builtin_type_int16 =
3294 init_type (TYPE_CODE_INT, 16 / 8,
3296 "int16_t", (struct objfile *) NULL);
3297 builtin_type_uint16 =
3298 init_type (TYPE_CODE_INT, 16 / 8,
3300 "uint16_t", (struct objfile *) NULL);
3301 builtin_type_int32 =
3302 init_type (TYPE_CODE_INT, 32 / 8,
3304 "int32_t", (struct objfile *) NULL);
3305 builtin_type_uint32 =
3306 init_type (TYPE_CODE_INT, 32 / 8,
3308 "uint32_t", (struct objfile *) NULL);
3309 builtin_type_int64 =
3310 init_type (TYPE_CODE_INT, 64 / 8,
3312 "int64_t", (struct objfile *) NULL);
3313 builtin_type_uint64 =
3314 init_type (TYPE_CODE_INT, 64 / 8,
3316 "uint64_t", (struct objfile *) NULL);
3317 builtin_type_int128 =
3318 init_type (TYPE_CODE_INT, 128 / 8,
3320 "int128_t", (struct objfile *) NULL);
3321 builtin_type_uint128 =
3322 init_type (TYPE_CODE_INT, 128 / 8,
3324 "uint128_t", (struct objfile *) NULL);
3326 builtin_type_ieee_single =
3327 build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single);
3328 builtin_type_ieee_double =
3329 build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double);
3330 builtin_type_i387_ext =
3331 build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext);
3332 builtin_type_m68881_ext =
3333 build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext);
3334 builtin_type_arm_ext =
3335 build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext);
3336 builtin_type_ia64_spill =
3337 build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill);
3338 builtin_type_ia64_quad =
3339 build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad);
3342 init_type (TYPE_CODE_VOID, 1,
3344 "void", (struct objfile *) NULL);
3345 builtin_type_true_char =
3346 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3348 "true character", (struct objfile *) NULL);
3349 builtin_type_true_unsigned_char =
3350 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3352 "true character", (struct objfile *) NULL);
3354 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
3355 Set debugging of C++ overloading."), _("\
3356 Show debugging of C++ overloading."), _("\
3357 When enabled, ranking of the functions is displayed."),
3359 show_overload_debug,
3360 &setdebuglist, &showdebuglist);
3362 /* Add user knob for controlling resolution of opaque types. */
3363 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
3364 &opaque_type_resolution, _("\
3365 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3366 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL,
3368 show_opaque_type_resolution,
3369 &setlist, &showlist);