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 = XZALLOC (struct type);
166 TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
170 type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
171 TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
173 OBJSTAT (objfile, n_types++);
176 /* Initialize the fields that might not be zero. */
178 TYPE_CODE (type) = TYPE_CODE_UNDEF;
179 TYPE_OBJFILE (type) = objfile;
180 TYPE_VPTR_FIELDNO (type) = -1;
181 TYPE_CHAIN (type) = type; /* Chain back to itself. */
186 /* Alloc a new type instance structure, fill it with some defaults,
187 and point it at OLDTYPE. Allocate the new type instance from the
188 same place as OLDTYPE. */
191 alloc_type_instance (struct type *oldtype)
195 /* Allocate the structure. */
197 if (TYPE_OBJFILE (oldtype) == NULL)
198 type = XZALLOC (struct type);
200 type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
203 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
205 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
210 /* Clear all remnants of the previous type at TYPE, in preparation for
211 replacing it with something else. */
213 smash_type (struct type *type)
215 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
217 /* For now, delete the rings. */
218 TYPE_CHAIN (type) = type;
220 /* For now, leave the pointer/reference types alone. */
223 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
224 to a pointer to memory where the pointer type should be stored.
225 If *TYPEPTR is zero, update it to point to the pointer type we return.
226 We allocate new memory if needed. */
229 make_pointer_type (struct type *type, struct type **typeptr)
231 struct type *ntype; /* New type */
232 struct objfile *objfile;
235 ntype = TYPE_POINTER_TYPE (type);
240 return ntype; /* Don't care about alloc,
241 and have new type. */
242 else if (*typeptr == 0)
244 *typeptr = ntype; /* Tracking alloc, and have new type. */
249 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
251 ntype = alloc_type (TYPE_OBJFILE (type));
255 else /* We have storage, but need to reset it. */
258 objfile = TYPE_OBJFILE (ntype);
259 chain = TYPE_CHAIN (ntype);
261 TYPE_CHAIN (ntype) = chain;
262 TYPE_OBJFILE (ntype) = objfile;
265 TYPE_TARGET_TYPE (ntype) = type;
266 TYPE_POINTER_TYPE (type) = ntype;
268 /* FIXME! Assume the machine has only one representation for
271 TYPE_LENGTH (ntype) =
272 gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
273 TYPE_CODE (ntype) = TYPE_CODE_PTR;
275 /* Mark pointers as unsigned. The target converts between pointers
276 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
277 gdbarch_address_to_pointer. */
278 TYPE_UNSIGNED (ntype) = 1;
280 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
281 TYPE_POINTER_TYPE (type) = ntype;
283 /* Update the length of all the other variants of this type. */
284 chain = TYPE_CHAIN (ntype);
285 while (chain != ntype)
287 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
288 chain = TYPE_CHAIN (chain);
294 /* Given a type TYPE, return a type of pointers to that type.
295 May need to construct such a type if this is the first use. */
298 lookup_pointer_type (struct type *type)
300 return make_pointer_type (type, (struct type **) 0);
303 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
304 points to a pointer to memory where the reference type should be
305 stored. If *TYPEPTR is zero, update it to point to the reference
306 type we return. We allocate new memory if needed. */
309 make_reference_type (struct type *type, struct type **typeptr)
311 struct type *ntype; /* New type */
312 struct objfile *objfile;
315 ntype = TYPE_REFERENCE_TYPE (type);
320 return ntype; /* Don't care about alloc,
321 and have new type. */
322 else if (*typeptr == 0)
324 *typeptr = ntype; /* Tracking alloc, and have new type. */
329 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
331 ntype = alloc_type (TYPE_OBJFILE (type));
335 else /* We have storage, but need to reset it. */
338 objfile = TYPE_OBJFILE (ntype);
339 chain = TYPE_CHAIN (ntype);
341 TYPE_CHAIN (ntype) = chain;
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
349 references, and that it matches the (only) representation for
352 TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
353 TYPE_CODE (ntype) = TYPE_CODE_REF;
355 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
356 TYPE_REFERENCE_TYPE (type) = ntype;
358 /* Update the length of all the other variants of this type. */
359 chain = TYPE_CHAIN (ntype);
360 while (chain != ntype)
362 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
363 chain = TYPE_CHAIN (chain);
369 /* Same as above, but caller doesn't care about memory allocation
373 lookup_reference_type (struct type *type)
375 return make_reference_type (type, (struct type **) 0);
378 /* Lookup a function type that returns type TYPE. TYPEPTR, if
379 nonzero, points to a pointer to memory where the function type
380 should be stored. If *TYPEPTR is zero, update it to point to the
381 function type we return. We allocate new memory from OBJFILE if needed; use
382 NULL for permanent types. */
385 make_function_type (struct type *type, struct type **typeptr,
386 struct objfile *objfile)
388 struct type *ntype; /* New type */
390 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
392 ntype = alloc_type (objfile);
396 else /* We have storage, but need to reset it. */
400 TYPE_OBJFILE (ntype) = objfile;
403 TYPE_TARGET_TYPE (ntype) = type;
405 TYPE_LENGTH (ntype) = 1;
406 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
412 /* Given a type TYPE, return a type of functions that return that type.
413 May need to construct such a type if this is the first use. */
416 lookup_function_type (struct type *type)
418 return make_function_type (type, (struct type **) 0, TYPE_OBJFILE (type));
421 /* Identify address space identifier by name --
422 return the integer flag defined in gdbtypes.h. */
424 address_space_name_to_int (char *space_identifier)
426 struct gdbarch *gdbarch = current_gdbarch;
428 /* Check for known address space delimiters. */
429 if (!strcmp (space_identifier, "code"))
430 return TYPE_INSTANCE_FLAG_CODE_SPACE;
431 else if (!strcmp (space_identifier, "data"))
432 return TYPE_INSTANCE_FLAG_DATA_SPACE;
433 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
434 && gdbarch_address_class_name_to_type_flags (gdbarch,
439 error (_("Unknown address space specifier: \"%s\""), space_identifier);
442 /* Identify address space identifier by integer flag as defined in
443 gdbtypes.h -- return the string version of the adress space name. */
446 address_space_int_to_name (int space_flag)
448 struct gdbarch *gdbarch = current_gdbarch;
449 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
451 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
453 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
454 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
455 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
460 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
462 If STORAGE is non-NULL, create the new type instance there.
463 STORAGE must be in the same obstack as TYPE. */
466 make_qualified_type (struct type *type, int new_flags,
467 struct type *storage)
474 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
476 ntype = TYPE_CHAIN (ntype);
478 while (ntype != type);
480 /* Create a new type instance. */
482 ntype = alloc_type_instance (type);
485 /* If STORAGE was provided, it had better be in the same objfile
486 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
487 if one objfile is freed and the other kept, we'd have
488 dangling pointers. */
489 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
492 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
493 TYPE_CHAIN (ntype) = ntype;
496 /* Pointers or references to the original type are not relevant to
498 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
499 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
501 /* Chain the new qualified type to the old type. */
502 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
503 TYPE_CHAIN (type) = ntype;
505 /* Now set the instance flags and return the new type. */
506 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
508 /* Set length of new type to that of the original type. */
509 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
514 /* Make an address-space-delimited variant of a type -- a type that
515 is identical to the one supplied except that it has an address
516 space attribute attached to it (such as "code" or "data").
518 The space attributes "code" and "data" are for Harvard
519 architectures. The address space attributes are for architectures
520 which have alternately sized pointers or pointers with alternate
524 make_type_with_address_space (struct type *type, int space_flag)
527 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
528 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
529 | TYPE_INSTANCE_FLAG_DATA_SPACE
530 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
533 return make_qualified_type (type, new_flags, NULL);
536 /* Make a "c-v" variant of a type -- a type that is identical to the
537 one supplied except that it may have const or volatile attributes
538 CNST is a flag for setting the const attribute
539 VOLTL is a flag for setting the volatile attribute
540 TYPE is the base type whose variant we are creating.
542 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
543 storage to hold the new qualified type; *TYPEPTR and TYPE must be
544 in the same objfile. Otherwise, allocate fresh memory for the new
545 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
546 new type we construct. */
548 make_cv_type (int cnst, int voltl,
550 struct type **typeptr)
552 struct type *ntype; /* New type */
553 struct type *tmp_type = type; /* tmp type */
554 struct objfile *objfile;
556 int new_flags = (TYPE_INSTANCE_FLAGS (type)
557 & ~(TYPE_INSTANCE_FLAG_CONST | TYPE_INSTANCE_FLAG_VOLATILE));
560 new_flags |= TYPE_INSTANCE_FLAG_CONST;
563 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
565 if (typeptr && *typeptr != NULL)
567 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
568 a C-V variant chain that threads across objfiles: if one
569 objfile gets freed, then the other has a broken C-V chain.
571 This code used to try to copy over the main type from TYPE to
572 *TYPEPTR if they were in different objfiles, but that's
573 wrong, too: TYPE may have a field list or member function
574 lists, which refer to types of their own, etc. etc. The
575 whole shebang would need to be copied over recursively; you
576 can't have inter-objfile pointers. The only thing to do is
577 to leave stub types as stub types, and look them up afresh by
578 name each time you encounter them. */
579 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
582 ntype = make_qualified_type (type, new_flags,
583 typeptr ? *typeptr : NULL);
591 /* Replace the contents of ntype with the type *type. This changes the
592 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
593 the changes are propogated to all types in the TYPE_CHAIN.
595 In order to build recursive types, it's inevitable that we'll need
596 to update types in place --- but this sort of indiscriminate
597 smashing is ugly, and needs to be replaced with something more
598 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
599 clear if more steps are needed. */
601 replace_type (struct type *ntype, struct type *type)
605 /* These two types had better be in the same objfile. Otherwise,
606 the assignment of one type's main type structure to the other
607 will produce a type with references to objects (names; field
608 lists; etc.) allocated on an objfile other than its own. */
609 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
611 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
613 /* The type length is not a part of the main type. Update it for
614 each type on the variant chain. */
618 /* Assert that this element of the chain has no address-class bits
619 set in its flags. Such type variants might have type lengths
620 which are supposed to be different from the non-address-class
621 variants. This assertion shouldn't ever be triggered because
622 symbol readers which do construct address-class variants don't
623 call replace_type(). */
624 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
626 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
627 chain = TYPE_CHAIN (chain);
629 while (ntype != chain);
631 /* Assert that the two types have equivalent instance qualifiers.
632 This should be true for at least all of our debug readers. */
633 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
636 /* Implement direct support for MEMBER_TYPE in GNU C++.
637 May need to construct such a type if this is the first use.
638 The TYPE is the type of the member. The DOMAIN is the type
639 of the aggregate that the member belongs to. */
642 lookup_memberptr_type (struct type *type, struct type *domain)
646 mtype = alloc_type (TYPE_OBJFILE (type));
647 smash_to_memberptr_type (mtype, domain, type);
651 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
654 lookup_methodptr_type (struct type *to_type)
658 mtype = alloc_type (TYPE_OBJFILE (to_type));
659 TYPE_TARGET_TYPE (mtype) = to_type;
660 TYPE_DOMAIN_TYPE (mtype) = TYPE_DOMAIN_TYPE (to_type);
661 TYPE_LENGTH (mtype) = cplus_method_ptr_size (to_type);
662 TYPE_CODE (mtype) = TYPE_CODE_METHODPTR;
666 /* Allocate a stub method whose return type is TYPE. This apparently
667 happens for speed of symbol reading, since parsing out the
668 arguments to the method is cpu-intensive, the way we are doing it.
669 So, we will fill in arguments later. This always returns a fresh
673 allocate_stub_method (struct type *type)
677 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
678 TYPE_OBJFILE (type));
679 TYPE_TARGET_TYPE (mtype) = type;
680 /* _DOMAIN_TYPE (mtype) = unknown yet */
684 /* Create a range type using either a blank type supplied in
685 RESULT_TYPE, or creating a new type, inheriting the objfile from
688 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
689 to HIGH_BOUND, inclusive.
691 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
692 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
695 create_range_type (struct type *result_type, struct type *index_type,
696 int low_bound, int high_bound)
698 if (result_type == NULL)
699 result_type = alloc_type (TYPE_OBJFILE (index_type));
700 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
701 TYPE_TARGET_TYPE (result_type) = index_type;
702 if (TYPE_STUB (index_type))
703 TYPE_TARGET_STUB (result_type) = 1;
705 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
706 TYPE_NFIELDS (result_type) = 2;
707 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
708 TYPE_NFIELDS (result_type)
709 * sizeof (struct field));
710 TYPE_LOW_BOUND (result_type) = low_bound;
711 TYPE_HIGH_BOUND (result_type) = high_bound;
714 TYPE_UNSIGNED (result_type) = 1;
719 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
720 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
721 bounds will fit in LONGEST), or -1 otherwise. */
724 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
726 CHECK_TYPEDEF (type);
727 switch (TYPE_CODE (type))
729 case TYPE_CODE_RANGE:
730 *lowp = TYPE_LOW_BOUND (type);
731 *highp = TYPE_HIGH_BOUND (type);
734 if (TYPE_NFIELDS (type) > 0)
736 /* The enums may not be sorted by value, so search all
740 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
741 for (i = 0; i < TYPE_NFIELDS (type); i++)
743 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
744 *lowp = TYPE_FIELD_BITPOS (type, i);
745 if (TYPE_FIELD_BITPOS (type, i) > *highp)
746 *highp = TYPE_FIELD_BITPOS (type, i);
749 /* Set unsigned indicator if warranted. */
752 TYPE_UNSIGNED (type) = 1;
766 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
768 if (!TYPE_UNSIGNED (type))
770 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
774 /* ... fall through for unsigned ints ... */
777 /* This round-about calculation is to avoid shifting by
778 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
779 if TYPE_LENGTH (type) == sizeof (LONGEST). */
780 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
781 *highp = (*highp - 1) | *highp;
788 /* Create an array type using either a blank type supplied in
789 RESULT_TYPE, or creating a new type, inheriting the objfile from
792 Elements will be of type ELEMENT_TYPE, the indices will be of type
795 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
796 sure it is TYPE_CODE_UNDEF before we bash it into an array
800 create_array_type (struct type *result_type,
801 struct type *element_type,
802 struct type *range_type)
804 LONGEST low_bound, high_bound;
806 if (result_type == NULL)
808 result_type = alloc_type (TYPE_OBJFILE (range_type));
810 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
811 TYPE_TARGET_TYPE (result_type) = element_type;
812 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
813 low_bound = high_bound = 0;
814 CHECK_TYPEDEF (element_type);
815 /* Be careful when setting the array length. Ada arrays can be
816 empty arrays with the high_bound being smaller than the low_bound.
817 In such cases, the array length should be zero. */
818 if (high_bound < low_bound)
819 TYPE_LENGTH (result_type) = 0;
821 TYPE_LENGTH (result_type) =
822 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
823 TYPE_NFIELDS (result_type) = 1;
824 TYPE_FIELDS (result_type) =
825 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
826 TYPE_INDEX_TYPE (result_type) = range_type;
827 TYPE_VPTR_FIELDNO (result_type) = -1;
829 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
830 if (TYPE_LENGTH (result_type) == 0)
831 TYPE_TARGET_STUB (result_type) = 1;
836 /* Create a string type using either a blank type supplied in
837 RESULT_TYPE, or creating a new type. String types are similar
838 enough to array of char types that we can use create_array_type to
839 build the basic type and then bash it into a string type.
841 For fixed length strings, the range type contains 0 as the lower
842 bound and the length of the string minus one as the upper bound.
844 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
845 sure it is TYPE_CODE_UNDEF before we bash it into a string
849 create_string_type (struct type *result_type,
850 struct type *range_type)
852 struct type *string_char_type;
854 string_char_type = language_string_char_type (current_language,
856 result_type = create_array_type (result_type,
859 TYPE_CODE (result_type) = TYPE_CODE_STRING;
864 create_set_type (struct type *result_type, struct type *domain_type)
866 if (result_type == NULL)
868 result_type = alloc_type (TYPE_OBJFILE (domain_type));
870 TYPE_CODE (result_type) = TYPE_CODE_SET;
871 TYPE_NFIELDS (result_type) = 1;
872 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
874 if (!TYPE_STUB (domain_type))
876 LONGEST low_bound, high_bound, bit_length;
877 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
878 low_bound = high_bound = 0;
879 bit_length = high_bound - low_bound + 1;
880 TYPE_LENGTH (result_type)
881 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
883 TYPE_UNSIGNED (result_type) = 1;
885 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
891 append_flags_type_flag (struct type *type, int bitpos, char *name)
893 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
894 gdb_assert (bitpos < TYPE_NFIELDS (type));
895 gdb_assert (bitpos >= 0);
899 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
900 TYPE_FIELD_BITPOS (type, bitpos) = bitpos;
904 /* Don't show this field to the user. */
905 TYPE_FIELD_BITPOS (type, bitpos) = -1;
910 init_flags_type (char *name, int length)
912 int nfields = length * TARGET_CHAR_BIT;
915 type = init_type (TYPE_CODE_FLAGS, length,
916 TYPE_FLAG_UNSIGNED, name, NULL);
917 TYPE_NFIELDS (type) = nfields;
918 TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
923 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
924 and any array types nested inside it. */
927 make_vector_type (struct type *array_type)
929 struct type *inner_array, *elt_type;
932 /* Find the innermost array type, in case the array is
933 multi-dimensional. */
934 inner_array = array_type;
935 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
936 inner_array = TYPE_TARGET_TYPE (inner_array);
938 elt_type = TYPE_TARGET_TYPE (inner_array);
939 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
941 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_FLAG_NOTTEXT;
942 elt_type = make_qualified_type (elt_type, flags, NULL);
943 TYPE_TARGET_TYPE (inner_array) = elt_type;
946 TYPE_VECTOR (array_type) = 1;
950 init_vector_type (struct type *elt_type, int n)
952 struct type *array_type;
954 array_type = create_array_type (0, elt_type,
955 create_range_type (0,
958 make_vector_type (array_type);
962 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
963 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
964 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
965 TYPE doesn't include the offset (that's the value of the MEMBER
966 itself), but does include the structure type into which it points
969 When "smashing" the type, we preserve the objfile that the old type
970 pointed to, since we aren't changing where the type is actually
974 smash_to_memberptr_type (struct type *type, struct type *domain,
975 struct type *to_type)
977 struct objfile *objfile;
979 objfile = TYPE_OBJFILE (type);
982 TYPE_OBJFILE (type) = objfile;
983 TYPE_TARGET_TYPE (type) = to_type;
984 TYPE_DOMAIN_TYPE (type) = domain;
985 /* Assume that a data member pointer is the same size as a normal
987 TYPE_LENGTH (type) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
988 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
991 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
992 METHOD just means `function that gets an extra "this" argument'.
994 When "smashing" the type, we preserve the objfile that the old type
995 pointed to, since we aren't changing where the type is actually
999 smash_to_method_type (struct type *type, struct type *domain,
1000 struct type *to_type, struct field *args,
1001 int nargs, int varargs)
1003 struct objfile *objfile;
1005 objfile = TYPE_OBJFILE (type);
1008 TYPE_OBJFILE (type) = objfile;
1009 TYPE_TARGET_TYPE (type) = to_type;
1010 TYPE_DOMAIN_TYPE (type) = domain;
1011 TYPE_FIELDS (type) = args;
1012 TYPE_NFIELDS (type) = nargs;
1014 TYPE_VARARGS (type) = 1;
1015 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1016 TYPE_CODE (type) = TYPE_CODE_METHOD;
1019 /* Return a typename for a struct/union/enum type without "struct ",
1020 "union ", or "enum ". If the type has a NULL name, return NULL. */
1023 type_name_no_tag (const struct type *type)
1025 if (TYPE_TAG_NAME (type) != NULL)
1026 return TYPE_TAG_NAME (type);
1028 /* Is there code which expects this to return the name if there is
1029 no tag name? My guess is that this is mainly used for C++ in
1030 cases where the two will always be the same. */
1031 return TYPE_NAME (type);
1034 /* Lookup a typedef or primitive type named NAME, visible in lexical
1035 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1036 suitably defined. */
1039 lookup_typename (char *name, struct block *block, int noerr)
1044 sym = lookup_symbol (name, block, VAR_DOMAIN, 0);
1045 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1047 tmp = language_lookup_primitive_type_by_name (current_language,
1054 else if (!tmp && noerr)
1060 error (_("No type named %s."), name);
1063 return (SYMBOL_TYPE (sym));
1067 lookup_unsigned_typename (char *name)
1069 char *uns = alloca (strlen (name) + 10);
1071 strcpy (uns, "unsigned ");
1072 strcpy (uns + 9, name);
1073 return (lookup_typename (uns, (struct block *) NULL, 0));
1077 lookup_signed_typename (char *name)
1080 char *uns = alloca (strlen (name) + 8);
1082 strcpy (uns, "signed ");
1083 strcpy (uns + 7, name);
1084 t = lookup_typename (uns, (struct block *) NULL, 1);
1085 /* If we don't find "signed FOO" just try again with plain "FOO". */
1088 return lookup_typename (name, (struct block *) NULL, 0);
1091 /* Lookup a structure type named "struct NAME",
1092 visible in lexical block BLOCK. */
1095 lookup_struct (char *name, struct block *block)
1099 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1103 error (_("No struct type named %s."), name);
1105 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1107 error (_("This context has class, union or enum %s, not a struct."),
1110 return (SYMBOL_TYPE (sym));
1113 /* Lookup a union type named "union NAME",
1114 visible in lexical block BLOCK. */
1117 lookup_union (char *name, struct block *block)
1122 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1125 error (_("No union type named %s."), name);
1127 t = SYMBOL_TYPE (sym);
1129 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1132 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1133 * a further "declared_type" field to discover it is really a union.
1135 if (HAVE_CPLUS_STRUCT (t))
1136 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1139 /* If we get here, it's not a union. */
1140 error (_("This context has class, struct or enum %s, not a union."),
1145 /* Lookup an enum type named "enum NAME",
1146 visible in lexical block BLOCK. */
1149 lookup_enum (char *name, struct block *block)
1153 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1156 error (_("No enum type named %s."), name);
1158 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1160 error (_("This context has class, struct or union %s, not an enum."),
1163 return (SYMBOL_TYPE (sym));
1166 /* Lookup a template type named "template NAME<TYPE>",
1167 visible in lexical block BLOCK. */
1170 lookup_template_type (char *name, struct type *type,
1171 struct block *block)
1174 char *nam = (char *)
1175 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1178 strcat (nam, TYPE_NAME (type));
1179 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1181 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0);
1185 error (_("No template type named %s."), name);
1187 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1189 error (_("This context has class, union or enum %s, not a struct."),
1192 return (SYMBOL_TYPE (sym));
1195 /* Given a type TYPE, lookup the type of the component of type named
1198 TYPE can be either a struct or union, or a pointer or reference to
1199 a struct or union. If it is a pointer or reference, its target
1200 type is automatically used. Thus '.' and '->' are interchangable,
1201 as specified for the definitions of the expression element types
1202 STRUCTOP_STRUCT and STRUCTOP_PTR.
1204 If NOERR is nonzero, return zero if NAME is not suitably defined.
1205 If NAME is the name of a baseclass type, return that type. */
1208 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1214 CHECK_TYPEDEF (type);
1215 if (TYPE_CODE (type) != TYPE_CODE_PTR
1216 && TYPE_CODE (type) != TYPE_CODE_REF)
1218 type = TYPE_TARGET_TYPE (type);
1221 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1222 && TYPE_CODE (type) != TYPE_CODE_UNION)
1224 target_terminal_ours ();
1225 gdb_flush (gdb_stdout);
1226 fprintf_unfiltered (gdb_stderr, "Type ");
1227 type_print (type, "", gdb_stderr, -1);
1228 error (_(" is not a structure or union type."));
1232 /* FIXME: This change put in by Michael seems incorrect for the case
1233 where the structure tag name is the same as the member name.
1234 I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
1235 foo; } bell;" Disabled by fnf. */
1239 typename = type_name_no_tag (type);
1240 if (typename != NULL && strcmp (typename, name) == 0)
1245 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1247 char *t_field_name = TYPE_FIELD_NAME (type, i);
1249 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1251 return TYPE_FIELD_TYPE (type, i);
1255 /* OK, it's not in this class. Recursively check the baseclasses. */
1256 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1260 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1272 target_terminal_ours ();
1273 gdb_flush (gdb_stdout);
1274 fprintf_unfiltered (gdb_stderr, "Type ");
1275 type_print (type, "", gdb_stderr, -1);
1276 fprintf_unfiltered (gdb_stderr, " has no component named ");
1277 fputs_filtered (name, gdb_stderr);
1279 return (struct type *) -1; /* For lint */
1282 /* Lookup the vptr basetype/fieldno values for TYPE.
1283 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1284 vptr_fieldno. Also, if found and basetype is from the same objfile,
1286 If not found, return -1 and ignore BASETYPEP.
1287 Callers should be aware that in some cases (for example,
1288 the type or one of its baseclasses is a stub type and we are
1289 debugging a .o file), this function will not be able to find the
1290 virtual function table pointer, and vptr_fieldno will remain -1 and
1291 vptr_basetype will remain NULL or incomplete. */
1294 get_vptr_fieldno (struct type *type, struct type **basetypep)
1296 CHECK_TYPEDEF (type);
1298 if (TYPE_VPTR_FIELDNO (type) < 0)
1302 /* We must start at zero in case the first (and only) baseclass
1303 is virtual (and hence we cannot share the table pointer). */
1304 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1306 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1308 struct type *basetype;
1310 fieldno = get_vptr_fieldno (baseclass, &basetype);
1313 /* If the type comes from a different objfile we can't cache
1314 it, it may have a different lifetime. PR 2384 */
1315 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
1317 TYPE_VPTR_FIELDNO (type) = fieldno;
1318 TYPE_VPTR_BASETYPE (type) = basetype;
1321 *basetypep = basetype;
1332 *basetypep = TYPE_VPTR_BASETYPE (type);
1333 return TYPE_VPTR_FIELDNO (type);
1338 stub_noname_complaint (void)
1340 complaint (&symfile_complaints, _("stub type has NULL name"));
1343 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1345 If this is a stubbed struct (i.e. declared as struct foo *), see if
1346 we can find a full definition in some other file. If so, copy this
1347 definition, so we can use it in future. There used to be a comment
1348 (but not any code) that if we don't find a full definition, we'd
1349 set a flag so we don't spend time in the future checking the same
1350 type. That would be a mistake, though--we might load in more
1351 symbols which contain a full definition for the type.
1353 This used to be coded as a macro, but I don't think it is called
1354 often enough to merit such treatment. */
1356 /* Find the real type of TYPE. This function returns the real type,
1357 after removing all layers of typedefs and completing opaque or stub
1358 types. Completion changes the TYPE argument, but stripping of
1359 typedefs does not. */
1362 check_typedef (struct type *type)
1364 struct type *orig_type = type;
1365 int is_const, is_volatile;
1369 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1371 if (!TYPE_TARGET_TYPE (type))
1376 /* It is dangerous to call lookup_symbol if we are currently
1377 reading a symtab. Infinite recursion is one danger. */
1378 if (currently_reading_symtab)
1381 name = type_name_no_tag (type);
1382 /* FIXME: shouldn't we separately check the TYPE_NAME and
1383 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1384 VAR_DOMAIN as appropriate? (this code was written before
1385 TYPE_NAME and TYPE_TAG_NAME were separate). */
1388 stub_noname_complaint ();
1391 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1393 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1394 else /* TYPE_CODE_UNDEF */
1395 TYPE_TARGET_TYPE (type) = alloc_type (NULL);
1397 type = TYPE_TARGET_TYPE (type);
1400 is_const = TYPE_CONST (type);
1401 is_volatile = TYPE_VOLATILE (type);
1403 /* If this is a struct/class/union with no fields, then check
1404 whether a full definition exists somewhere else. This is for
1405 systems where a type definition with no fields is issued for such
1406 types, instead of identifying them as stub types in the first
1409 if (TYPE_IS_OPAQUE (type)
1410 && opaque_type_resolution
1411 && !currently_reading_symtab)
1413 char *name = type_name_no_tag (type);
1414 struct type *newtype;
1417 stub_noname_complaint ();
1420 newtype = lookup_transparent_type (name);
1424 /* If the resolved type and the stub are in the same
1425 objfile, then replace the stub type with the real deal.
1426 But if they're in separate objfiles, leave the stub
1427 alone; we'll just look up the transparent type every time
1428 we call check_typedef. We can't create pointers between
1429 types allocated to different objfiles, since they may
1430 have different lifetimes. Trying to copy NEWTYPE over to
1431 TYPE's objfile is pointless, too, since you'll have to
1432 move over any other types NEWTYPE refers to, which could
1433 be an unbounded amount of stuff. */
1434 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
1435 make_cv_type (is_const, is_volatile, newtype, &type);
1440 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1442 else if (TYPE_STUB (type) && !currently_reading_symtab)
1444 char *name = type_name_no_tag (type);
1445 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1446 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1447 as appropriate? (this code was written before TYPE_NAME and
1448 TYPE_TAG_NAME were separate). */
1452 stub_noname_complaint ();
1455 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1458 /* Same as above for opaque types, we can replace the stub
1459 with the complete type only if they are int the same
1461 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
1462 make_cv_type (is_const, is_volatile,
1463 SYMBOL_TYPE (sym), &type);
1465 type = SYMBOL_TYPE (sym);
1469 if (TYPE_TARGET_STUB (type))
1471 struct type *range_type;
1472 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1474 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1478 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1479 && TYPE_NFIELDS (type) == 1
1480 && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
1481 == TYPE_CODE_RANGE))
1483 /* Now recompute the length of the array type, based on its
1484 number of elements and the target type's length.
1485 Watch out for Ada null Ada arrays where the high bound
1486 is smaller than the low bound. */
1487 const int low_bound = TYPE_LOW_BOUND (range_type);
1488 const int high_bound = TYPE_HIGH_BOUND (range_type);
1491 if (high_bound < low_bound)
1494 nb_elements = high_bound - low_bound + 1;
1496 TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
1497 TYPE_TARGET_STUB (type) = 0;
1499 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1501 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1502 TYPE_TARGET_STUB (type) = 0;
1505 /* Cache TYPE_LENGTH for future use. */
1506 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1510 /* Parse a type expression in the string [P..P+LENGTH). If an error
1511 occurs, silently return builtin_type_void. */
1513 static struct type *
1514 safe_parse_type (char *p, int length)
1516 struct ui_file *saved_gdb_stderr;
1519 /* Suppress error messages. */
1520 saved_gdb_stderr = gdb_stderr;
1521 gdb_stderr = ui_file_new ();
1523 /* Call parse_and_eval_type() without fear of longjmp()s. */
1524 if (!gdb_parse_and_eval_type (p, length, &type))
1525 type = builtin_type_void;
1527 /* Stop suppressing error messages. */
1528 ui_file_delete (gdb_stderr);
1529 gdb_stderr = saved_gdb_stderr;
1534 /* Ugly hack to convert method stubs into method types.
1536 He ain't kiddin'. This demangles the name of the method into a
1537 string including argument types, parses out each argument type,
1538 generates a string casting a zero to that type, evaluates the
1539 string, and stuffs the resulting type into an argtype vector!!!
1540 Then it knows the type of the whole function (including argument
1541 types for overloading), which info used to be in the stab's but was
1542 removed to hack back the space required for them. */
1545 check_stub_method (struct type *type, int method_id, int signature_id)
1548 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1549 char *demangled_name = cplus_demangle (mangled_name,
1550 DMGL_PARAMS | DMGL_ANSI);
1551 char *argtypetext, *p;
1552 int depth = 0, argcount = 1;
1553 struct field *argtypes;
1556 /* Make sure we got back a function string that we can use. */
1558 p = strchr (demangled_name, '(');
1562 if (demangled_name == NULL || p == NULL)
1563 error (_("Internal: Cannot demangle mangled name `%s'."),
1566 /* Now, read in the parameters that define this type. */
1571 if (*p == '(' || *p == '<')
1575 else if (*p == ')' || *p == '>')
1579 else if (*p == ',' && depth == 0)
1587 /* If we read one argument and it was ``void'', don't count it. */
1588 if (strncmp (argtypetext, "(void)", 6) == 0)
1591 /* We need one extra slot, for the THIS pointer. */
1593 argtypes = (struct field *)
1594 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1597 /* Add THIS pointer for non-static methods. */
1598 f = TYPE_FN_FIELDLIST1 (type, method_id);
1599 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1603 argtypes[0].type = lookup_pointer_type (type);
1607 if (*p != ')') /* () means no args, skip while */
1612 if (depth <= 0 && (*p == ',' || *p == ')'))
1614 /* Avoid parsing of ellipsis, they will be handled below.
1615 Also avoid ``void'' as above. */
1616 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1617 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1619 argtypes[argcount].type =
1620 safe_parse_type (argtypetext, p - argtypetext);
1623 argtypetext = p + 1;
1626 if (*p == '(' || *p == '<')
1630 else if (*p == ')' || *p == '>')
1639 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1641 /* Now update the old "stub" type into a real type. */
1642 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1643 TYPE_DOMAIN_TYPE (mtype) = type;
1644 TYPE_FIELDS (mtype) = argtypes;
1645 TYPE_NFIELDS (mtype) = argcount;
1646 TYPE_STUB (mtype) = 0;
1647 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1649 TYPE_VARARGS (mtype) = 1;
1651 xfree (demangled_name);
1654 /* This is the external interface to check_stub_method, above. This
1655 function unstubs all of the signatures for TYPE's METHOD_ID method
1656 name. After calling this function TYPE_FN_FIELD_STUB will be
1657 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1660 This function unfortunately can not die until stabs do. */
1663 check_stub_method_group (struct type *type, int method_id)
1665 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1666 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1667 int j, found_stub = 0;
1669 for (j = 0; j < len; j++)
1670 if (TYPE_FN_FIELD_STUB (f, j))
1673 check_stub_method (type, method_id, j);
1676 /* GNU v3 methods with incorrect names were corrected when we read
1677 in type information, because it was cheaper to do it then. The
1678 only GNU v2 methods with incorrect method names are operators and
1679 destructors; destructors were also corrected when we read in type
1682 Therefore the only thing we need to handle here are v2 operator
1684 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1687 char dem_opname[256];
1689 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1691 dem_opname, DMGL_ANSI);
1693 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1697 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1701 const struct cplus_struct_type cplus_struct_default;
1704 allocate_cplus_struct_type (struct type *type)
1706 if (!HAVE_CPLUS_STRUCT (type))
1708 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1709 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1710 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1714 /* Helper function to initialize the standard scalar types.
1716 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy of
1717 the string pointed to by name in the objfile_obstack for that
1718 objfile, and initialize the type name to that copy. There are
1719 places (mipsread.c in particular, where init_type is called with a
1720 NULL value for NAME). */
1723 init_type (enum type_code code, int length, int flags,
1724 char *name, struct objfile *objfile)
1728 type = alloc_type (objfile);
1729 TYPE_CODE (type) = code;
1730 TYPE_LENGTH (type) = length;
1732 gdb_assert (!(flags & (TYPE_FLAG_MIN - 1)));
1733 if (flags & TYPE_FLAG_UNSIGNED)
1734 TYPE_UNSIGNED (type) = 1;
1735 if (flags & TYPE_FLAG_NOSIGN)
1736 TYPE_NOSIGN (type) = 1;
1737 if (flags & TYPE_FLAG_STUB)
1738 TYPE_STUB (type) = 1;
1739 if (flags & TYPE_FLAG_TARGET_STUB)
1740 TYPE_TARGET_STUB (type) = 1;
1741 if (flags & TYPE_FLAG_STATIC)
1742 TYPE_STATIC (type) = 1;
1743 if (flags & TYPE_FLAG_PROTOTYPED)
1744 TYPE_PROTOTYPED (type) = 1;
1745 if (flags & TYPE_FLAG_INCOMPLETE)
1746 TYPE_INCOMPLETE (type) = 1;
1747 if (flags & TYPE_FLAG_VARARGS)
1748 TYPE_VARARGS (type) = 1;
1749 if (flags & TYPE_FLAG_VECTOR)
1750 TYPE_VECTOR (type) = 1;
1751 if (flags & TYPE_FLAG_STUB_SUPPORTED)
1752 TYPE_STUB_SUPPORTED (type) = 1;
1753 if (flags & TYPE_FLAG_NOTTEXT)
1754 TYPE_NOTTEXT (type) = 1;
1755 if (flags & TYPE_FLAG_FIXED_INSTANCE)
1756 TYPE_FIXED_INSTANCE (type) = 1;
1758 if ((name != NULL) && (objfile != NULL))
1760 TYPE_NAME (type) = obsavestring (name, strlen (name),
1761 &objfile->objfile_obstack);
1765 TYPE_NAME (type) = name;
1770 if (name && strcmp (name, "char") == 0)
1771 TYPE_NOSIGN (type) = 1;
1773 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1774 || code == TYPE_CODE_NAMESPACE)
1776 INIT_CPLUS_SPECIFIC (type);
1781 /* Helper function. Create an empty composite type. */
1784 init_composite_type (char *name, enum type_code code)
1787 gdb_assert (code == TYPE_CODE_STRUCT
1788 || code == TYPE_CODE_UNION);
1789 t = init_type (code, 0, 0, NULL, NULL);
1790 TYPE_TAG_NAME (t) = name;
1794 /* Helper function. Append a field to a composite type. */
1797 append_composite_type_field_aligned (struct type *t, char *name,
1798 struct type *field, int alignment)
1801 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1802 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1803 sizeof (struct field) * TYPE_NFIELDS (t));
1804 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1805 memset (f, 0, sizeof f[0]);
1806 FIELD_TYPE (f[0]) = field;
1807 FIELD_NAME (f[0]) = name;
1808 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1810 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1811 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1813 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1815 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1816 if (TYPE_NFIELDS (t) > 1)
1818 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1819 + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
1820 * TARGET_CHAR_BIT));
1824 int left = FIELD_BITPOS (f[0]) % (alignment * TARGET_CHAR_BIT);
1827 FIELD_BITPOS (f[0]) += left;
1828 TYPE_LENGTH (t) += left / TARGET_CHAR_BIT;
1836 append_composite_type_field (struct type *t, char *name,
1839 append_composite_type_field_aligned (t, name, field, 0);
1843 can_dereference (struct type *t)
1845 /* FIXME: Should we return true for references as well as
1850 && TYPE_CODE (t) == TYPE_CODE_PTR
1851 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1855 is_integral_type (struct type *t)
1860 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1861 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1862 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
1863 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1864 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1865 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1868 /* Check whether BASE is an ancestor or base class or DCLASS
1869 Return 1 if so, and 0 if not.
1870 Note: callers may want to check for identity of the types before
1871 calling this function -- identical types are considered to satisfy
1872 the ancestor relationship even if they're identical. */
1875 is_ancestor (struct type *base, struct type *dclass)
1879 CHECK_TYPEDEF (base);
1880 CHECK_TYPEDEF (dclass);
1884 if (TYPE_NAME (base) && TYPE_NAME (dclass)
1885 && !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1888 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1889 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1897 /* Functions for overload resolution begin here */
1899 /* Compare two badness vectors A and B and return the result.
1900 0 => A and B are identical
1901 1 => A and B are incomparable
1902 2 => A is better than B
1903 3 => A is worse than B */
1906 compare_badness (struct badness_vector *a, struct badness_vector *b)
1910 short found_pos = 0; /* any positives in c? */
1911 short found_neg = 0; /* any negatives in c? */
1913 /* differing lengths => incomparable */
1914 if (a->length != b->length)
1917 /* Subtract b from a */
1918 for (i = 0; i < a->length; i++)
1920 tmp = a->rank[i] - b->rank[i];
1930 return 1; /* incomparable */
1932 return 3; /* A > B */
1938 return 2; /* A < B */
1940 return 0; /* A == B */
1944 /* Rank a function by comparing its parameter types (PARMS, length
1945 NPARMS), to the types of an argument list (ARGS, length NARGS).
1946 Return a pointer to a badness vector. This has NARGS + 1
1949 struct badness_vector *
1950 rank_function (struct type **parms, int nparms,
1951 struct type **args, int nargs)
1954 struct badness_vector *bv;
1955 int min_len = nparms < nargs ? nparms : nargs;
1957 bv = xmalloc (sizeof (struct badness_vector));
1958 bv->length = nargs + 1; /* add 1 for the length-match rank */
1959 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
1961 /* First compare the lengths of the supplied lists.
1962 If there is a mismatch, set it to a high value. */
1964 /* pai/1997-06-03 FIXME: when we have debug info about default
1965 arguments and ellipsis parameter lists, we should consider those
1966 and rank the length-match more finely. */
1968 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
1970 /* Now rank all the parameters of the candidate function */
1971 for (i = 1; i <= min_len; i++)
1972 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
1974 /* If more arguments than parameters, add dummy entries */
1975 for (i = min_len + 1; i <= nargs; i++)
1976 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
1981 /* Compare the names of two integer types, assuming that any sign
1982 qualifiers have been checked already. We do it this way because
1983 there may be an "int" in the name of one of the types. */
1986 integer_types_same_name_p (const char *first, const char *second)
1988 int first_p, second_p;
1990 /* If both are shorts, return 1; if neither is a short, keep
1992 first_p = (strstr (first, "short") != NULL);
1993 second_p = (strstr (second, "short") != NULL);
1994 if (first_p && second_p)
1996 if (first_p || second_p)
1999 /* Likewise for long. */
2000 first_p = (strstr (first, "long") != NULL);
2001 second_p = (strstr (second, "long") != NULL);
2002 if (first_p && second_p)
2004 if (first_p || second_p)
2007 /* Likewise for char. */
2008 first_p = (strstr (first, "char") != NULL);
2009 second_p = (strstr (second, "char") != NULL);
2010 if (first_p && second_p)
2012 if (first_p || second_p)
2015 /* They must both be ints. */
2019 /* Compare one type (PARM) for compatibility with another (ARG).
2020 * PARM is intended to be the parameter type of a function; and
2021 * ARG is the supplied argument's type. This function tests if
2022 * the latter can be converted to the former.
2024 * Return 0 if they are identical types;
2025 * Otherwise, return an integer which corresponds to how compatible
2026 * PARM is to ARG. The higher the return value, the worse the match.
2027 * Generally the "bad" conversions are all uniformly assigned a 100. */
2030 rank_one_type (struct type *parm, struct type *arg)
2032 /* Identical type pointers. */
2033 /* However, this still doesn't catch all cases of same type for arg
2034 and param. The reason is that builtin types are different from
2035 the same ones constructed from the object. */
2039 /* Resolve typedefs */
2040 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2041 parm = check_typedef (parm);
2042 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2043 arg = check_typedef (arg);
2046 Well, damnit, if the names are exactly the same, I'll say they
2047 are exactly the same. This happens when we generate method
2048 stubs. The types won't point to the same address, but they
2049 really are the same.
2052 if (TYPE_NAME (parm) && TYPE_NAME (arg)
2053 && !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2056 /* Check if identical after resolving typedefs. */
2060 /* See through references, since we can almost make non-references
2062 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2063 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2064 + REFERENCE_CONVERSION_BADNESS);
2065 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2066 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2067 + REFERENCE_CONVERSION_BADNESS);
2069 /* Debugging only. */
2070 fprintf_filtered (gdb_stderr,
2071 "------ Arg is %s [%d], parm is %s [%d]\n",
2072 TYPE_NAME (arg), TYPE_CODE (arg),
2073 TYPE_NAME (parm), TYPE_CODE (parm));
2075 /* x -> y means arg of type x being supplied for parameter of type y */
2077 switch (TYPE_CODE (parm))
2080 switch (TYPE_CODE (arg))
2083 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2084 return VOID_PTR_CONVERSION_BADNESS;
2086 return rank_one_type (TYPE_TARGET_TYPE (parm),
2087 TYPE_TARGET_TYPE (arg));
2088 case TYPE_CODE_ARRAY:
2089 return rank_one_type (TYPE_TARGET_TYPE (parm),
2090 TYPE_TARGET_TYPE (arg));
2091 case TYPE_CODE_FUNC:
2092 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2094 case TYPE_CODE_ENUM:
2095 case TYPE_CODE_FLAGS:
2096 case TYPE_CODE_CHAR:
2097 case TYPE_CODE_RANGE:
2098 case TYPE_CODE_BOOL:
2099 return POINTER_CONVERSION_BADNESS;
2101 return INCOMPATIBLE_TYPE_BADNESS;
2103 case TYPE_CODE_ARRAY:
2104 switch (TYPE_CODE (arg))
2107 case TYPE_CODE_ARRAY:
2108 return rank_one_type (TYPE_TARGET_TYPE (parm),
2109 TYPE_TARGET_TYPE (arg));
2111 return INCOMPATIBLE_TYPE_BADNESS;
2113 case TYPE_CODE_FUNC:
2114 switch (TYPE_CODE (arg))
2116 case TYPE_CODE_PTR: /* funcptr -> func */
2117 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2119 return INCOMPATIBLE_TYPE_BADNESS;
2122 switch (TYPE_CODE (arg))
2125 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2127 /* Deal with signed, unsigned, and plain chars and
2128 signed and unsigned ints. */
2129 if (TYPE_NOSIGN (parm))
2131 /* This case only for character types */
2132 if (TYPE_NOSIGN (arg))
2133 return 0; /* plain char -> plain char */
2134 else /* signed/unsigned char -> plain char */
2135 return INTEGER_CONVERSION_BADNESS;
2137 else if (TYPE_UNSIGNED (parm))
2139 if (TYPE_UNSIGNED (arg))
2141 /* unsigned int -> unsigned int, or
2142 unsigned long -> unsigned long */
2143 if (integer_types_same_name_p (TYPE_NAME (parm),
2146 else if (integer_types_same_name_p (TYPE_NAME (arg),
2148 && integer_types_same_name_p (TYPE_NAME (parm),
2150 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2152 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
2156 if (integer_types_same_name_p (TYPE_NAME (arg),
2158 && integer_types_same_name_p (TYPE_NAME (parm),
2160 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
2162 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2165 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
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;
2176 return INTEGER_CONVERSION_BADNESS;
2179 return INTEGER_CONVERSION_BADNESS;
2181 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2182 return INTEGER_PROMOTION_BADNESS;
2184 return INTEGER_CONVERSION_BADNESS;
2185 case TYPE_CODE_ENUM:
2186 case TYPE_CODE_FLAGS:
2187 case TYPE_CODE_CHAR:
2188 case TYPE_CODE_RANGE:
2189 case TYPE_CODE_BOOL:
2190 return INTEGER_PROMOTION_BADNESS;
2192 return INT_FLOAT_CONVERSION_BADNESS;
2194 return NS_POINTER_CONVERSION_BADNESS;
2196 return INCOMPATIBLE_TYPE_BADNESS;
2199 case TYPE_CODE_ENUM:
2200 switch (TYPE_CODE (arg))
2203 case TYPE_CODE_CHAR:
2204 case TYPE_CODE_RANGE:
2205 case TYPE_CODE_BOOL:
2206 case TYPE_CODE_ENUM:
2207 return INTEGER_CONVERSION_BADNESS;
2209 return INT_FLOAT_CONVERSION_BADNESS;
2211 return INCOMPATIBLE_TYPE_BADNESS;
2214 case TYPE_CODE_CHAR:
2215 switch (TYPE_CODE (arg))
2217 case TYPE_CODE_RANGE:
2218 case TYPE_CODE_BOOL:
2219 case TYPE_CODE_ENUM:
2220 return INTEGER_CONVERSION_BADNESS;
2222 return INT_FLOAT_CONVERSION_BADNESS;
2224 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2225 return INTEGER_CONVERSION_BADNESS;
2226 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2227 return INTEGER_PROMOTION_BADNESS;
2228 /* >>> !! else fall through !! <<< */
2229 case TYPE_CODE_CHAR:
2230 /* Deal with signed, unsigned, and plain chars for C++ and
2231 with int cases falling through from previous case. */
2232 if (TYPE_NOSIGN (parm))
2234 if (TYPE_NOSIGN (arg))
2237 return INTEGER_CONVERSION_BADNESS;
2239 else if (TYPE_UNSIGNED (parm))
2241 if (TYPE_UNSIGNED (arg))
2244 return INTEGER_PROMOTION_BADNESS;
2246 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2249 return INTEGER_CONVERSION_BADNESS;
2251 return INCOMPATIBLE_TYPE_BADNESS;
2254 case TYPE_CODE_RANGE:
2255 switch (TYPE_CODE (arg))
2258 case TYPE_CODE_CHAR:
2259 case TYPE_CODE_RANGE:
2260 case TYPE_CODE_BOOL:
2261 case TYPE_CODE_ENUM:
2262 return INTEGER_CONVERSION_BADNESS;
2264 return INT_FLOAT_CONVERSION_BADNESS;
2266 return INCOMPATIBLE_TYPE_BADNESS;
2269 case TYPE_CODE_BOOL:
2270 switch (TYPE_CODE (arg))
2273 case TYPE_CODE_CHAR:
2274 case TYPE_CODE_RANGE:
2275 case TYPE_CODE_ENUM:
2278 return BOOLEAN_CONVERSION_BADNESS;
2279 case TYPE_CODE_BOOL:
2282 return INCOMPATIBLE_TYPE_BADNESS;
2286 switch (TYPE_CODE (arg))
2289 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2290 return FLOAT_PROMOTION_BADNESS;
2291 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2294 return FLOAT_CONVERSION_BADNESS;
2296 case TYPE_CODE_BOOL:
2297 case TYPE_CODE_ENUM:
2298 case TYPE_CODE_RANGE:
2299 case TYPE_CODE_CHAR:
2300 return INT_FLOAT_CONVERSION_BADNESS;
2302 return INCOMPATIBLE_TYPE_BADNESS;
2305 case TYPE_CODE_COMPLEX:
2306 switch (TYPE_CODE (arg))
2307 { /* Strictly not needed for C++, but... */
2309 return FLOAT_PROMOTION_BADNESS;
2310 case TYPE_CODE_COMPLEX:
2313 return INCOMPATIBLE_TYPE_BADNESS;
2316 case TYPE_CODE_STRUCT:
2317 /* currently same as TYPE_CODE_CLASS */
2318 switch (TYPE_CODE (arg))
2320 case TYPE_CODE_STRUCT:
2321 /* Check for derivation */
2322 if (is_ancestor (parm, arg))
2323 return BASE_CONVERSION_BADNESS;
2324 /* else fall through */
2326 return INCOMPATIBLE_TYPE_BADNESS;
2329 case TYPE_CODE_UNION:
2330 switch (TYPE_CODE (arg))
2332 case TYPE_CODE_UNION:
2334 return INCOMPATIBLE_TYPE_BADNESS;
2337 case TYPE_CODE_MEMBERPTR:
2338 switch (TYPE_CODE (arg))
2341 return INCOMPATIBLE_TYPE_BADNESS;
2344 case TYPE_CODE_METHOD:
2345 switch (TYPE_CODE (arg))
2349 return INCOMPATIBLE_TYPE_BADNESS;
2353 switch (TYPE_CODE (arg))
2357 return INCOMPATIBLE_TYPE_BADNESS;
2362 switch (TYPE_CODE (arg))
2366 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
2367 TYPE_FIELD_TYPE (arg, 0));
2369 return INCOMPATIBLE_TYPE_BADNESS;
2372 case TYPE_CODE_VOID:
2374 return INCOMPATIBLE_TYPE_BADNESS;
2375 } /* switch (TYPE_CODE (arg)) */
2379 /* End of functions for overload resolution */
2382 print_bit_vector (B_TYPE *bits, int nbits)
2386 for (bitno = 0; bitno < nbits; bitno++)
2388 if ((bitno % 8) == 0)
2390 puts_filtered (" ");
2392 if (B_TST (bits, bitno))
2393 printf_filtered (("1"));
2395 printf_filtered (("0"));
2399 /* Note the first arg should be the "this" pointer, we may not want to
2400 include it since we may get into a infinitely recursive
2404 print_arg_types (struct field *args, int nargs, int spaces)
2410 for (i = 0; i < nargs; i++)
2411 recursive_dump_type (args[i].type, spaces + 2);
2416 field_is_static (struct field *f)
2418 /* "static" fields are the fields whose location is not relative
2419 to the address of the enclosing struct. It would be nice to
2420 have a dedicated flag that would be set for static fields when
2421 the type is being created. But in practice, checking the field
2422 loc_kind should give us an accurate answer (at least as long as
2423 we assume that DWARF block locations are not going to be used
2424 for static fields). FIXME? */
2425 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
2426 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
2430 dump_fn_fieldlists (struct type *type, int spaces)
2436 printfi_filtered (spaces, "fn_fieldlists ");
2437 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2438 printf_filtered ("\n");
2439 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2441 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2442 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2444 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2445 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2447 printf_filtered (_(") length %d\n"),
2448 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2449 for (overload_idx = 0;
2450 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2453 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2455 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2456 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2458 printf_filtered (")\n");
2459 printfi_filtered (spaces + 8, "type ");
2460 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
2462 printf_filtered ("\n");
2464 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2467 printfi_filtered (spaces + 8, "args ");
2468 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
2470 printf_filtered ("\n");
2472 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2473 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f,
2476 printfi_filtered (spaces + 8, "fcontext ");
2477 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2479 printf_filtered ("\n");
2481 printfi_filtered (spaces + 8, "is_const %d\n",
2482 TYPE_FN_FIELD_CONST (f, overload_idx));
2483 printfi_filtered (spaces + 8, "is_volatile %d\n",
2484 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2485 printfi_filtered (spaces + 8, "is_private %d\n",
2486 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2487 printfi_filtered (spaces + 8, "is_protected %d\n",
2488 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2489 printfi_filtered (spaces + 8, "is_stub %d\n",
2490 TYPE_FN_FIELD_STUB (f, overload_idx));
2491 printfi_filtered (spaces + 8, "voffset %u\n",
2492 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2498 print_cplus_stuff (struct type *type, int spaces)
2500 printfi_filtered (spaces, "n_baseclasses %d\n",
2501 TYPE_N_BASECLASSES (type));
2502 printfi_filtered (spaces, "nfn_fields %d\n",
2503 TYPE_NFN_FIELDS (type));
2504 printfi_filtered (spaces, "nfn_fields_total %d\n",
2505 TYPE_NFN_FIELDS_TOTAL (type));
2506 if (TYPE_N_BASECLASSES (type) > 0)
2508 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2509 TYPE_N_BASECLASSES (type));
2510 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
2512 printf_filtered (")");
2514 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2515 TYPE_N_BASECLASSES (type));
2516 puts_filtered ("\n");
2518 if (TYPE_NFIELDS (type) > 0)
2520 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2522 printfi_filtered (spaces,
2523 "private_field_bits (%d bits at *",
2524 TYPE_NFIELDS (type));
2525 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
2527 printf_filtered (")");
2528 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2529 TYPE_NFIELDS (type));
2530 puts_filtered ("\n");
2532 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2534 printfi_filtered (spaces,
2535 "protected_field_bits (%d bits at *",
2536 TYPE_NFIELDS (type));
2537 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
2539 printf_filtered (")");
2540 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2541 TYPE_NFIELDS (type));
2542 puts_filtered ("\n");
2545 if (TYPE_NFN_FIELDS (type) > 0)
2547 dump_fn_fieldlists (type, spaces);
2551 static struct obstack dont_print_type_obstack;
2554 recursive_dump_type (struct type *type, int spaces)
2559 obstack_begin (&dont_print_type_obstack, 0);
2561 if (TYPE_NFIELDS (type) > 0
2562 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2564 struct type **first_dont_print
2565 = (struct type **) obstack_base (&dont_print_type_obstack);
2567 int i = (struct type **)
2568 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
2572 if (type == first_dont_print[i])
2574 printfi_filtered (spaces, "type node ");
2575 gdb_print_host_address (type, gdb_stdout);
2576 printf_filtered (_(" <same as already seen type>\n"));
2581 obstack_ptr_grow (&dont_print_type_obstack, type);
2584 printfi_filtered (spaces, "type node ");
2585 gdb_print_host_address (type, gdb_stdout);
2586 printf_filtered ("\n");
2587 printfi_filtered (spaces, "name '%s' (",
2588 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2589 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2590 printf_filtered (")\n");
2591 printfi_filtered (spaces, "tagname '%s' (",
2592 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2593 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2594 printf_filtered (")\n");
2595 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2596 switch (TYPE_CODE (type))
2598 case TYPE_CODE_UNDEF:
2599 printf_filtered ("(TYPE_CODE_UNDEF)");
2602 printf_filtered ("(TYPE_CODE_PTR)");
2604 case TYPE_CODE_ARRAY:
2605 printf_filtered ("(TYPE_CODE_ARRAY)");
2607 case TYPE_CODE_STRUCT:
2608 printf_filtered ("(TYPE_CODE_STRUCT)");
2610 case TYPE_CODE_UNION:
2611 printf_filtered ("(TYPE_CODE_UNION)");
2613 case TYPE_CODE_ENUM:
2614 printf_filtered ("(TYPE_CODE_ENUM)");
2616 case TYPE_CODE_FLAGS:
2617 printf_filtered ("(TYPE_CODE_FLAGS)");
2619 case TYPE_CODE_FUNC:
2620 printf_filtered ("(TYPE_CODE_FUNC)");
2623 printf_filtered ("(TYPE_CODE_INT)");
2626 printf_filtered ("(TYPE_CODE_FLT)");
2628 case TYPE_CODE_VOID:
2629 printf_filtered ("(TYPE_CODE_VOID)");
2632 printf_filtered ("(TYPE_CODE_SET)");
2634 case TYPE_CODE_RANGE:
2635 printf_filtered ("(TYPE_CODE_RANGE)");
2637 case TYPE_CODE_STRING:
2638 printf_filtered ("(TYPE_CODE_STRING)");
2640 case TYPE_CODE_BITSTRING:
2641 printf_filtered ("(TYPE_CODE_BITSTRING)");
2643 case TYPE_CODE_ERROR:
2644 printf_filtered ("(TYPE_CODE_ERROR)");
2646 case TYPE_CODE_MEMBERPTR:
2647 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2649 case TYPE_CODE_METHODPTR:
2650 printf_filtered ("(TYPE_CODE_METHODPTR)");
2652 case TYPE_CODE_METHOD:
2653 printf_filtered ("(TYPE_CODE_METHOD)");
2656 printf_filtered ("(TYPE_CODE_REF)");
2658 case TYPE_CODE_CHAR:
2659 printf_filtered ("(TYPE_CODE_CHAR)");
2661 case TYPE_CODE_BOOL:
2662 printf_filtered ("(TYPE_CODE_BOOL)");
2664 case TYPE_CODE_COMPLEX:
2665 printf_filtered ("(TYPE_CODE_COMPLEX)");
2667 case TYPE_CODE_TYPEDEF:
2668 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2670 case TYPE_CODE_TEMPLATE:
2671 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2673 case TYPE_CODE_TEMPLATE_ARG:
2674 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2676 case TYPE_CODE_NAMESPACE:
2677 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2680 printf_filtered ("(UNKNOWN TYPE CODE)");
2683 puts_filtered ("\n");
2684 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2685 printfi_filtered (spaces, "objfile ");
2686 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2687 printf_filtered ("\n");
2688 printfi_filtered (spaces, "target_type ");
2689 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2690 printf_filtered ("\n");
2691 if (TYPE_TARGET_TYPE (type) != NULL)
2693 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2695 printfi_filtered (spaces, "pointer_type ");
2696 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2697 printf_filtered ("\n");
2698 printfi_filtered (spaces, "reference_type ");
2699 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2700 printf_filtered ("\n");
2701 printfi_filtered (spaces, "type_chain ");
2702 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
2703 printf_filtered ("\n");
2704 printfi_filtered (spaces, "instance_flags 0x%x",
2705 TYPE_INSTANCE_FLAGS (type));
2706 if (TYPE_CONST (type))
2708 puts_filtered (" TYPE_FLAG_CONST");
2710 if (TYPE_VOLATILE (type))
2712 puts_filtered (" TYPE_FLAG_VOLATILE");
2714 if (TYPE_CODE_SPACE (type))
2716 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2718 if (TYPE_DATA_SPACE (type))
2720 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2722 if (TYPE_ADDRESS_CLASS_1 (type))
2724 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
2726 if (TYPE_ADDRESS_CLASS_2 (type))
2728 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
2730 puts_filtered ("\n");
2732 printfi_filtered (spaces, "flags");
2733 if (TYPE_UNSIGNED (type))
2735 puts_filtered (" TYPE_FLAG_UNSIGNED");
2737 if (TYPE_NOSIGN (type))
2739 puts_filtered (" TYPE_FLAG_NOSIGN");
2741 if (TYPE_STUB (type))
2743 puts_filtered (" TYPE_FLAG_STUB");
2745 if (TYPE_TARGET_STUB (type))
2747 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2749 if (TYPE_STATIC (type))
2751 puts_filtered (" TYPE_FLAG_STATIC");
2753 if (TYPE_PROTOTYPED (type))
2755 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2757 if (TYPE_INCOMPLETE (type))
2759 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2761 if (TYPE_VARARGS (type))
2763 puts_filtered (" TYPE_FLAG_VARARGS");
2765 /* This is used for things like AltiVec registers on ppc. Gcc emits
2766 an attribute for the array type, which tells whether or not we
2767 have a vector, instead of a regular array. */
2768 if (TYPE_VECTOR (type))
2770 puts_filtered (" TYPE_FLAG_VECTOR");
2772 if (TYPE_FIXED_INSTANCE (type))
2774 puts_filtered (" TYPE_FIXED_INSTANCE");
2776 if (TYPE_STUB_SUPPORTED (type))
2778 puts_filtered (" TYPE_STUB_SUPPORTED");
2780 if (TYPE_NOTTEXT (type))
2782 puts_filtered (" TYPE_NOTTEXT");
2784 puts_filtered ("\n");
2785 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
2786 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
2787 puts_filtered ("\n");
2788 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
2790 printfi_filtered (spaces + 2,
2791 "[%d] bitpos %d bitsize %d type ",
2792 idx, TYPE_FIELD_BITPOS (type, idx),
2793 TYPE_FIELD_BITSIZE (type, idx));
2794 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
2795 printf_filtered (" name '%s' (",
2796 TYPE_FIELD_NAME (type, idx) != NULL
2797 ? TYPE_FIELD_NAME (type, idx)
2799 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
2800 printf_filtered (")\n");
2801 if (TYPE_FIELD_TYPE (type, idx) != NULL)
2803 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
2806 printfi_filtered (spaces, "vptr_basetype ");
2807 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
2808 puts_filtered ("\n");
2809 if (TYPE_VPTR_BASETYPE (type) != NULL)
2811 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
2813 printfi_filtered (spaces, "vptr_fieldno %d\n",
2814 TYPE_VPTR_FIELDNO (type));
2815 switch (TYPE_CODE (type))
2817 case TYPE_CODE_STRUCT:
2818 printfi_filtered (spaces, "cplus_stuff ");
2819 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
2821 puts_filtered ("\n");
2822 print_cplus_stuff (type, spaces);
2826 printfi_filtered (spaces, "floatformat ");
2827 if (TYPE_FLOATFORMAT (type) == NULL)
2828 puts_filtered ("(null)");
2831 puts_filtered ("{ ");
2832 if (TYPE_FLOATFORMAT (type)[0] == NULL
2833 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
2834 puts_filtered ("(null)");
2836 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
2838 puts_filtered (", ");
2839 if (TYPE_FLOATFORMAT (type)[1] == NULL
2840 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
2841 puts_filtered ("(null)");
2843 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
2845 puts_filtered (" }");
2847 puts_filtered ("\n");
2851 /* We have to pick one of the union types to be able print and
2852 test the value. Pick cplus_struct_type, even though we know
2853 it isn't any particular one. */
2854 printfi_filtered (spaces, "type_specific ");
2855 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2856 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
2858 printf_filtered (_(" (unknown data form)"));
2860 printf_filtered ("\n");
2865 obstack_free (&dont_print_type_obstack, NULL);
2868 /* Trivial helpers for the libiberty hash table, for mapping one
2873 struct type *old, *new;
2877 type_pair_hash (const void *item)
2879 const struct type_pair *pair = item;
2880 return htab_hash_pointer (pair->old);
2884 type_pair_eq (const void *item_lhs, const void *item_rhs)
2886 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
2887 return lhs->old == rhs->old;
2890 /* Allocate the hash table used by copy_type_recursive to walk
2891 types without duplicates. We use OBJFILE's obstack, because
2892 OBJFILE is about to be deleted. */
2895 create_copied_types_hash (struct objfile *objfile)
2897 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
2898 NULL, &objfile->objfile_obstack,
2899 hashtab_obstack_allocate,
2900 dummy_obstack_deallocate);
2903 /* Recursively copy (deep copy) TYPE, if it is associated with
2904 OBJFILE. Return a new type allocated using malloc, a saved type if
2905 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
2906 not associated with OBJFILE. */
2909 copy_type_recursive (struct objfile *objfile,
2911 htab_t copied_types)
2913 struct type_pair *stored, pair;
2915 struct type *new_type;
2917 if (TYPE_OBJFILE (type) == NULL)
2920 /* This type shouldn't be pointing to any types in other objfiles;
2921 if it did, the type might disappear unexpectedly. */
2922 gdb_assert (TYPE_OBJFILE (type) == objfile);
2925 slot = htab_find_slot (copied_types, &pair, INSERT);
2927 return ((struct type_pair *) *slot)->new;
2929 new_type = alloc_type (NULL);
2931 /* We must add the new type to the hash table immediately, in case
2932 we encounter this type again during a recursive call below. */
2933 stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
2935 stored->new = new_type;
2938 /* Copy the common fields of types. For the main type, we simply
2939 copy the entire thing and then update specific fields as needed. */
2940 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
2941 TYPE_OBJFILE (new_type) = NULL;
2943 if (TYPE_NAME (type))
2944 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
2945 if (TYPE_TAG_NAME (type))
2946 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
2948 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
2949 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
2951 /* Copy the fields. */
2952 if (TYPE_NFIELDS (type))
2956 nfields = TYPE_NFIELDS (type);
2957 TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
2958 for (i = 0; i < nfields; i++)
2960 TYPE_FIELD_ARTIFICIAL (new_type, i) =
2961 TYPE_FIELD_ARTIFICIAL (type, i);
2962 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
2963 if (TYPE_FIELD_TYPE (type, i))
2964 TYPE_FIELD_TYPE (new_type, i)
2965 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
2967 if (TYPE_FIELD_NAME (type, i))
2968 TYPE_FIELD_NAME (new_type, i) =
2969 xstrdup (TYPE_FIELD_NAME (type, i));
2970 switch (TYPE_FIELD_LOC_KIND (type, i))
2972 case FIELD_LOC_KIND_BITPOS:
2973 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
2974 TYPE_FIELD_BITPOS (type, i));
2976 case FIELD_LOC_KIND_PHYSADDR:
2977 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
2978 TYPE_FIELD_STATIC_PHYSADDR (type, i));
2980 case FIELD_LOC_KIND_PHYSNAME:
2981 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
2982 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
2986 internal_error (__FILE__, __LINE__,
2987 _("Unexpected type field location kind: %d"),
2988 TYPE_FIELD_LOC_KIND (type, i));
2993 /* Copy pointers to other types. */
2994 if (TYPE_TARGET_TYPE (type))
2995 TYPE_TARGET_TYPE (new_type) =
2996 copy_type_recursive (objfile,
2997 TYPE_TARGET_TYPE (type),
2999 if (TYPE_VPTR_BASETYPE (type))
3000 TYPE_VPTR_BASETYPE (new_type) =
3001 copy_type_recursive (objfile,
3002 TYPE_VPTR_BASETYPE (type),
3004 /* Maybe copy the type_specific bits.
3006 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3007 base classes and methods. There's no fundamental reason why we
3008 can't, but at the moment it is not needed. */
3010 if (TYPE_CODE (type) == TYPE_CODE_FLT)
3011 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
3012 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3013 || TYPE_CODE (type) == TYPE_CODE_UNION
3014 || TYPE_CODE (type) == TYPE_CODE_TEMPLATE
3015 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
3016 INIT_CPLUS_SPECIFIC (new_type);
3021 /* Make a copy of the given TYPE, except that the pointer & reference
3022 types are not preserved.
3024 This function assumes that the given type has an associated objfile.
3025 This objfile is used to allocate the new type. */
3028 copy_type (const struct type *type)
3030 struct type *new_type;
3032 gdb_assert (TYPE_OBJFILE (type) != NULL);
3034 new_type = alloc_type (TYPE_OBJFILE (type));
3035 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
3036 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
3037 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
3038 sizeof (struct main_type));
3043 static struct type *
3044 build_flt (int bit, char *name, const struct floatformat **floatformats)
3050 gdb_assert (floatformats != NULL);
3051 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
3052 bit = floatformats[0]->totalsize;
3054 gdb_assert (bit >= 0);
3056 t = init_type (TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, 0, name, NULL);
3057 TYPE_FLOATFORMAT (t) = floatformats;
3061 static struct gdbarch_data *gdbtypes_data;
3063 const struct builtin_type *
3064 builtin_type (struct gdbarch *gdbarch)
3066 return gdbarch_data (gdbarch, gdbtypes_data);
3070 static struct type *
3071 build_complex (int bit, char *name, struct type *target_type)
3074 if (bit <= 0 || target_type == builtin_type_error)
3076 gdb_assert (builtin_type_error != NULL);
3077 return builtin_type_error;
3079 t = init_type (TYPE_CODE_COMPLEX, 2 * bit / TARGET_CHAR_BIT,
3080 0, name, (struct objfile *) NULL);
3081 TYPE_TARGET_TYPE (t) = target_type;
3086 gdbtypes_post_init (struct gdbarch *gdbarch)
3088 struct builtin_type *builtin_type
3089 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
3091 builtin_type->builtin_void =
3092 init_type (TYPE_CODE_VOID, 1,
3094 "void", (struct objfile *) NULL);
3095 builtin_type->builtin_char =
3096 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3098 | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
3099 "char", (struct objfile *) NULL);
3100 builtin_type->builtin_signed_char =
3101 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3103 "signed char", (struct objfile *) NULL);
3104 builtin_type->builtin_unsigned_char =
3105 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3107 "unsigned char", (struct objfile *) NULL);
3108 builtin_type->builtin_short =
3109 init_type (TYPE_CODE_INT,
3110 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
3111 0, "short", (struct objfile *) NULL);
3112 builtin_type->builtin_unsigned_short =
3113 init_type (TYPE_CODE_INT,
3114 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
3115 TYPE_FLAG_UNSIGNED, "unsigned short",
3116 (struct objfile *) NULL);
3117 builtin_type->builtin_int =
3118 init_type (TYPE_CODE_INT,
3119 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
3120 0, "int", (struct objfile *) NULL);
3121 builtin_type->builtin_unsigned_int =
3122 init_type (TYPE_CODE_INT,
3123 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
3124 TYPE_FLAG_UNSIGNED, "unsigned int",
3125 (struct objfile *) NULL);
3126 builtin_type->builtin_long =
3127 init_type (TYPE_CODE_INT,
3128 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
3129 0, "long", (struct objfile *) NULL);
3130 builtin_type->builtin_unsigned_long =
3131 init_type (TYPE_CODE_INT,
3132 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
3133 TYPE_FLAG_UNSIGNED, "unsigned long",
3134 (struct objfile *) NULL);
3135 builtin_type->builtin_long_long =
3136 init_type (TYPE_CODE_INT,
3137 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
3138 0, "long long", (struct objfile *) NULL);
3139 builtin_type->builtin_unsigned_long_long =
3140 init_type (TYPE_CODE_INT,
3141 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
3142 TYPE_FLAG_UNSIGNED, "unsigned long long",
3143 (struct objfile *) NULL);
3144 builtin_type->builtin_float
3145 = build_flt (gdbarch_float_bit (gdbarch), "float",
3146 gdbarch_float_format (gdbarch));
3147 builtin_type->builtin_double
3148 = build_flt (gdbarch_double_bit (gdbarch), "double",
3149 gdbarch_double_format (gdbarch));
3150 builtin_type->builtin_long_double
3151 = build_flt (gdbarch_long_double_bit (gdbarch), "long double",
3152 gdbarch_long_double_format (gdbarch));
3153 builtin_type->builtin_complex
3154 = build_complex (gdbarch_float_bit (gdbarch), "complex",
3155 builtin_type->builtin_float);
3156 builtin_type->builtin_double_complex
3157 = build_complex (gdbarch_double_bit (gdbarch), "double complex",
3158 builtin_type->builtin_double);
3159 builtin_type->builtin_string =
3160 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3162 "string", (struct objfile *) NULL);
3163 builtin_type->builtin_bool =
3164 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3166 "bool", (struct objfile *) NULL);
3168 /* The following three are about decimal floating point types, which
3169 are 32-bits, 64-bits and 128-bits respectively. */
3170 builtin_type->builtin_decfloat
3171 = init_type (TYPE_CODE_DECFLOAT, 32 / 8,
3173 "_Decimal32", (struct objfile *) NULL);
3174 builtin_type->builtin_decdouble
3175 = init_type (TYPE_CODE_DECFLOAT, 64 / 8,
3177 "_Decimal64", (struct objfile *) NULL);
3178 builtin_type->builtin_declong
3179 = init_type (TYPE_CODE_DECFLOAT, 128 / 8,
3181 "_Decimal128", (struct objfile *) NULL);
3183 /* Pointer/Address types. */
3185 /* NOTE: on some targets, addresses and pointers are not necessarily
3186 the same --- for example, on the D10V, pointers are 16 bits long,
3187 but addresses are 32 bits long. See doc/gdbint.texinfo,
3188 ``Pointers Are Not Always Addresses''.
3191 - gdb's `struct type' always describes the target's
3193 - gdb's `struct value' objects should always hold values in
3195 - gdb's CORE_ADDR values are addresses in the unified virtual
3196 address space that the assembler and linker work with. Thus,
3197 since target_read_memory takes a CORE_ADDR as an argument, it
3198 can access any memory on the target, even if the processor has
3199 separate code and data address spaces.
3202 - If v is a value holding a D10V code pointer, its contents are
3203 in target form: a big-endian address left-shifted two bits.
3204 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3205 sizeof (void *) == 2 on the target.
3207 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3208 target type for a value the target will never see. It's only
3209 used to hold the values of (typeless) linker symbols, which are
3210 indeed in the unified virtual address space. */
3212 builtin_type->builtin_data_ptr =
3213 make_pointer_type (builtin_type->builtin_void, NULL);
3214 builtin_type->builtin_func_ptr =
3215 lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
3216 builtin_type->builtin_core_addr =
3217 init_type (TYPE_CODE_INT,
3218 gdbarch_addr_bit (gdbarch) / 8,
3220 "__CORE_ADDR", (struct objfile *) NULL);
3223 /* The following set of types is used for symbols with no
3224 debug information. */
3225 builtin_type->nodebug_text_symbol =
3226 init_type (TYPE_CODE_FUNC, 1, 0,
3227 "<text variable, no debug info>", NULL);
3228 TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol) =
3229 builtin_type->builtin_int;
3230 builtin_type->nodebug_data_symbol =
3231 init_type (TYPE_CODE_INT,
3232 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
3233 "<data variable, no debug info>", NULL);
3234 builtin_type->nodebug_unknown_symbol =
3235 init_type (TYPE_CODE_INT, 1, 0,
3236 "<variable (not text or data), no debug info>", NULL);
3237 builtin_type->nodebug_tls_symbol =
3238 init_type (TYPE_CODE_INT,
3239 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
3240 "<thread local variable, no debug info>", NULL);
3242 return builtin_type;
3245 extern void _initialize_gdbtypes (void);
3247 _initialize_gdbtypes (void)
3249 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
3251 /* FIXME: The following types are architecture-neutral. However,
3252 they contain pointer_type and reference_type fields potentially
3253 caching pointer or reference types that *are* architecture
3257 init_type (TYPE_CODE_INT, 0 / 8,
3259 "int0_t", (struct objfile *) NULL);
3261 init_type (TYPE_CODE_INT, 8 / 8,
3263 "int8_t", (struct objfile *) NULL);
3264 builtin_type_uint8 =
3265 init_type (TYPE_CODE_INT, 8 / 8,
3266 TYPE_FLAG_UNSIGNED | TYPE_FLAG_NOTTEXT,
3267 "uint8_t", (struct objfile *) NULL);
3268 builtin_type_int16 =
3269 init_type (TYPE_CODE_INT, 16 / 8,
3271 "int16_t", (struct objfile *) NULL);
3272 builtin_type_uint16 =
3273 init_type (TYPE_CODE_INT, 16 / 8,
3275 "uint16_t", (struct objfile *) NULL);
3276 builtin_type_int32 =
3277 init_type (TYPE_CODE_INT, 32 / 8,
3279 "int32_t", (struct objfile *) NULL);
3280 builtin_type_uint32 =
3281 init_type (TYPE_CODE_INT, 32 / 8,
3283 "uint32_t", (struct objfile *) NULL);
3284 builtin_type_int64 =
3285 init_type (TYPE_CODE_INT, 64 / 8,
3287 "int64_t", (struct objfile *) NULL);
3288 builtin_type_uint64 =
3289 init_type (TYPE_CODE_INT, 64 / 8,
3291 "uint64_t", (struct objfile *) NULL);
3292 builtin_type_int128 =
3293 init_type (TYPE_CODE_INT, 128 / 8,
3295 "int128_t", (struct objfile *) NULL);
3296 builtin_type_uint128 =
3297 init_type (TYPE_CODE_INT, 128 / 8,
3299 "uint128_t", (struct objfile *) NULL);
3301 builtin_type_ieee_single =
3302 build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single);
3303 builtin_type_ieee_double =
3304 build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double);
3305 builtin_type_i387_ext =
3306 build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext);
3307 builtin_type_m68881_ext =
3308 build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext);
3309 builtin_type_arm_ext =
3310 build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext);
3311 builtin_type_ia64_spill =
3312 build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill);
3313 builtin_type_ia64_quad =
3314 build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad);
3317 init_type (TYPE_CODE_VOID, 1,
3319 "void", (struct objfile *) NULL);
3320 builtin_type_true_char =
3321 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3323 "true character", (struct objfile *) NULL);
3324 builtin_type_true_unsigned_char =
3325 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3327 "true character", (struct objfile *) NULL);
3329 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
3330 Set debugging of C++ overloading."), _("\
3331 Show debugging of C++ overloading."), _("\
3332 When enabled, ranking of the functions is displayed."),
3334 show_overload_debug,
3335 &setdebuglist, &showdebuglist);
3337 /* Add user knob for controlling resolution of opaque types. */
3338 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
3339 &opaque_type_resolution, _("\
3340 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3341 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL,
3343 show_opaque_type_resolution,
3344 &setlist, &showlist);