1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 Contributed by Cygnus Support, using pieces from other GDB modules.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
26 #include "gdb_string.h"
32 #include "expression.h"
37 #include "complaints.h"
41 #include "gdb_assert.h"
44 /* These variables point to the objects
45 representing the predefined C data types. */
47 struct type *builtin_type_int0;
48 struct type *builtin_type_int8;
49 struct type *builtin_type_uint8;
50 struct type *builtin_type_int16;
51 struct type *builtin_type_uint16;
52 struct type *builtin_type_int32;
53 struct type *builtin_type_uint32;
54 struct type *builtin_type_int64;
55 struct type *builtin_type_uint64;
56 struct type *builtin_type_int128;
57 struct type *builtin_type_uint128;
59 /* Floatformat pairs. */
60 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
61 &floatformat_ieee_single_big,
62 &floatformat_ieee_single_little
64 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
65 &floatformat_ieee_double_big,
66 &floatformat_ieee_double_little
68 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
69 &floatformat_ieee_double_big,
70 &floatformat_ieee_double_littlebyte_bigword
72 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
73 &floatformat_i387_ext,
76 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
77 &floatformat_m68881_ext,
78 &floatformat_m68881_ext
80 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
81 &floatformat_arm_ext_big,
82 &floatformat_arm_ext_littlebyte_bigword
84 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
85 &floatformat_ia64_spill_big,
86 &floatformat_ia64_spill_little
88 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
89 &floatformat_ia64_quad_big,
90 &floatformat_ia64_quad_little
92 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
96 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
101 struct type *builtin_type_ieee_single;
102 struct type *builtin_type_ieee_double;
103 struct type *builtin_type_i387_ext;
104 struct type *builtin_type_m68881_ext;
105 struct type *builtin_type_arm_ext;
106 struct type *builtin_type_ia64_spill;
107 struct type *builtin_type_ia64_quad;
110 int opaque_type_resolution = 1;
112 show_opaque_type_resolution (struct ui_file *file, int from_tty,
113 struct cmd_list_element *c,
116 fprintf_filtered (file, _("\
117 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
121 int overload_debug = 0;
123 show_overload_debug (struct ui_file *file, int from_tty,
124 struct cmd_list_element *c, const char *value)
126 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
134 }; /* Maximum extension is 128! FIXME */
136 static void print_bit_vector (B_TYPE *, int);
137 static void print_arg_types (struct field *, int, int);
138 static void dump_fn_fieldlists (struct type *, int);
139 static void print_cplus_stuff (struct type *, int);
140 static void virtual_base_list_aux (struct type *dclass);
143 /* Alloc a new type structure and fill it with some defaults. If
144 OBJFILE is non-NULL, then allocate the space for the type structure
145 in that objfile's objfile_obstack. Otherwise allocate the new type
146 structure by xmalloc () (for permanent types). */
149 alloc_type (struct objfile *objfile)
153 /* Alloc the structure and start off with all fields zeroed. */
157 type = xmalloc (sizeof (struct type));
158 memset (type, 0, sizeof (struct type));
159 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
163 type = obstack_alloc (&objfile->objfile_obstack,
164 sizeof (struct type));
165 memset (type, 0, sizeof (struct type));
166 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
167 sizeof (struct main_type));
168 OBJSTAT (objfile, n_types++);
170 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
172 /* Initialize the fields that might not be zero. */
174 TYPE_CODE (type) = TYPE_CODE_UNDEF;
175 TYPE_OBJFILE (type) = objfile;
176 TYPE_VPTR_FIELDNO (type) = -1;
177 TYPE_CHAIN (type) = type; /* Chain back to itself. */
182 /* Alloc a new type instance structure, fill it with some defaults,
183 and point it at OLDTYPE. Allocate the new type instance from the
184 same place as OLDTYPE. */
187 alloc_type_instance (struct type *oldtype)
191 /* Allocate the structure. */
193 if (TYPE_OBJFILE (oldtype) == NULL)
195 type = xmalloc (sizeof (struct type));
196 memset (type, 0, sizeof (struct type));
200 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
201 sizeof (struct type));
202 memset (type, 0, sizeof (struct type));
204 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
206 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
211 /* Clear all remnants of the previous type at TYPE, in preparation for
212 replacing it with something else. */
214 smash_type (struct type *type)
216 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
218 /* For now, delete the rings. */
219 TYPE_CHAIN (type) = type;
221 /* For now, leave the pointer/reference types alone. */
224 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
225 to a pointer to memory where the pointer type should be stored.
226 If *TYPEPTR is zero, update it to point to the pointer type we return.
227 We allocate new memory if needed. */
230 make_pointer_type (struct type *type, struct type **typeptr)
232 struct type *ntype; /* New type */
233 struct objfile *objfile;
236 ntype = TYPE_POINTER_TYPE (type);
241 return ntype; /* Don't care about alloc,
242 and have new type. */
243 else if (*typeptr == 0)
245 *typeptr = ntype; /* Tracking alloc, and have new type. */
250 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
252 ntype = alloc_type (TYPE_OBJFILE (type));
256 else /* We have storage, but need to reset it. */
259 objfile = TYPE_OBJFILE (ntype);
260 chain = TYPE_CHAIN (ntype);
262 TYPE_CHAIN (ntype) = chain;
263 TYPE_OBJFILE (ntype) = objfile;
266 TYPE_TARGET_TYPE (ntype) = type;
267 TYPE_POINTER_TYPE (type) = ntype;
269 /* FIXME! Assume the machine has only one representation for
272 TYPE_LENGTH (ntype) =
273 gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
274 TYPE_CODE (ntype) = TYPE_CODE_PTR;
276 /* Mark pointers as unsigned. The target converts between pointers
277 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
278 gdbarch_address_to_pointer. */
279 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
281 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
282 TYPE_POINTER_TYPE (type) = ntype;
284 /* Update the length of all the other variants of this type. */
285 chain = TYPE_CHAIN (ntype);
286 while (chain != ntype)
288 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
289 chain = TYPE_CHAIN (chain);
295 /* Given a type TYPE, return a type of pointers to that type.
296 May need to construct such a type if this is the first use. */
299 lookup_pointer_type (struct type *type)
301 return make_pointer_type (type, (struct type **) 0);
304 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
305 points to a pointer to memory where the reference type should be
306 stored. If *TYPEPTR is zero, update it to point to the reference
307 type we return. We allocate new memory if needed. */
310 make_reference_type (struct type *type, struct type **typeptr)
312 struct type *ntype; /* New type */
313 struct objfile *objfile;
316 ntype = TYPE_REFERENCE_TYPE (type);
321 return ntype; /* Don't care about alloc,
322 and have new type. */
323 else if (*typeptr == 0)
325 *typeptr = ntype; /* Tracking alloc, and have new type. */
330 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
332 ntype = alloc_type (TYPE_OBJFILE (type));
336 else /* We have storage, but need to reset it. */
339 objfile = TYPE_OBJFILE (ntype);
340 chain = TYPE_CHAIN (ntype);
342 TYPE_CHAIN (ntype) = chain;
343 TYPE_OBJFILE (ntype) = objfile;
346 TYPE_TARGET_TYPE (ntype) = type;
347 TYPE_REFERENCE_TYPE (type) = ntype;
349 /* FIXME! Assume the machine has only one representation for
350 references, and that it matches the (only) representation for
353 TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
354 TYPE_CODE (ntype) = TYPE_CODE_REF;
356 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
357 TYPE_REFERENCE_TYPE (type) = ntype;
359 /* Update the length of all the other variants of this type. */
360 chain = TYPE_CHAIN (ntype);
361 while (chain != ntype)
363 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
364 chain = TYPE_CHAIN (chain);
370 /* Same as above, but caller doesn't care about memory allocation
374 lookup_reference_type (struct type *type)
376 return make_reference_type (type, (struct type **) 0);
379 /* Lookup a function type that returns type TYPE. TYPEPTR, if
380 nonzero, points to a pointer to memory where the function type
381 should be stored. If *TYPEPTR is zero, update it to point to the
382 function type we return. We allocate new memory if needed. */
385 make_function_type (struct type *type, struct type **typeptr)
387 struct type *ntype; /* New type */
388 struct objfile *objfile;
390 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
392 ntype = alloc_type (TYPE_OBJFILE (type));
396 else /* We have storage, but need to reset it. */
399 objfile = TYPE_OBJFILE (ntype);
401 TYPE_OBJFILE (ntype) = objfile;
404 TYPE_TARGET_TYPE (ntype) = type;
406 TYPE_LENGTH (ntype) = 1;
407 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
413 /* Given a type TYPE, return a type of functions that return that type.
414 May need to construct such a type if this is the first use. */
417 lookup_function_type (struct type *type)
419 return make_function_type (type, (struct type **) 0);
422 /* Identify address space identifier by name --
423 return the integer flag defined in gdbtypes.h. */
425 address_space_name_to_int (char *space_identifier)
427 struct gdbarch *gdbarch = current_gdbarch;
429 /* Check for known address space delimiters. */
430 if (!strcmp (space_identifier, "code"))
431 return TYPE_FLAG_CODE_SPACE;
432 else if (!strcmp (space_identifier, "data"))
433 return TYPE_FLAG_DATA_SPACE;
434 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
435 && gdbarch_address_class_name_to_type_flags (gdbarch,
440 error (_("Unknown address space specifier: \"%s\""), space_identifier);
443 /* Identify address space identifier by integer flag as defined in
444 gdbtypes.h -- return the string version of the adress space name. */
447 address_space_int_to_name (int space_flag)
449 struct gdbarch *gdbarch = current_gdbarch;
450 if (space_flag & TYPE_FLAG_CODE_SPACE)
452 else if (space_flag & TYPE_FLAG_DATA_SPACE)
454 else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL)
455 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
456 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
461 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
463 If STORAGE is non-NULL, create the new type instance there.
464 STORAGE must be in the same obstack as TYPE. */
467 make_qualified_type (struct type *type, int new_flags,
468 struct type *storage)
474 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
476 ntype = TYPE_CHAIN (ntype);
477 } while (ntype != type);
479 /* Create a new type instance. */
481 ntype = alloc_type_instance (type);
484 /* If STORAGE was provided, it had better be in the same objfile
485 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
486 if one objfile is freed and the other kept, we'd have
487 dangling pointers. */
488 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
491 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
492 TYPE_CHAIN (ntype) = ntype;
495 /* Pointers or references to the original type are not relevant to
497 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
498 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
500 /* Chain the new qualified type to the old type. */
501 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
502 TYPE_CHAIN (type) = ntype;
504 /* Now set the instance flags and return the new type. */
505 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
507 /* Set length of new type to that of the original type. */
508 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
513 /* Make an address-space-delimited variant of a type -- a type that
514 is identical to the one supplied except that it has an address
515 space attribute attached to it (such as "code" or "data").
517 The space attributes "code" and "data" are for Harvard
518 architectures. The address space attributes are for architectures
519 which have alternately sized pointers or pointers with alternate
523 make_type_with_address_space (struct type *type, int space_flag)
526 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
527 & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE
528 | TYPE_FLAG_ADDRESS_CLASS_ALL))
531 return make_qualified_type (type, new_flags, NULL);
534 /* Make a "c-v" variant of a type -- a type that is identical to the
535 one supplied except that it may have const or volatile attributes
536 CNST is a flag for setting the const attribute
537 VOLTL is a flag for setting the volatile attribute
538 TYPE is the base type whose variant we are creating.
540 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
541 storage to hold the new qualified type; *TYPEPTR and TYPE must be
542 in the same objfile. Otherwise, allocate fresh memory for the new
543 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
544 new type we construct. */
546 make_cv_type (int cnst, int voltl,
548 struct type **typeptr)
550 struct type *ntype; /* New type */
551 struct type *tmp_type = type; /* tmp type */
552 struct objfile *objfile;
554 int new_flags = (TYPE_INSTANCE_FLAGS (type)
555 & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
558 new_flags |= TYPE_FLAG_CONST;
561 new_flags |= TYPE_FLAG_VOLATILE;
563 if (typeptr && *typeptr != NULL)
565 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
566 a C-V variant chain that threads across objfiles: if one
567 objfile gets freed, then the other has a broken C-V chain.
569 This code used to try to copy over the main type from TYPE to
570 *TYPEPTR if they were in different objfiles, but that's
571 wrong, too: TYPE may have a field list or member function
572 lists, which refer to types of their own, etc. etc. The
573 whole shebang would need to be copied over recursively; you
574 can't have inter-objfile pointers. The only thing to do is
575 to leave stub types as stub types, and look them up afresh by
576 name each time you encounter them. */
577 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
580 ntype = make_qualified_type (type, new_flags,
581 typeptr ? *typeptr : NULL);
589 /* Replace the contents of ntype with the type *type. This changes the
590 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
591 the changes are propogated to all types in the TYPE_CHAIN.
593 In order to build recursive types, it's inevitable that we'll need
594 to update types in place --- but this sort of indiscriminate
595 smashing is ugly, and needs to be replaced with something more
596 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
597 clear if more steps are needed. */
599 replace_type (struct type *ntype, struct type *type)
603 /* These two types had better be in the same objfile. Otherwise,
604 the assignment of one type's main type structure to the other
605 will produce a type with references to objects (names; field
606 lists; etc.) allocated on an objfile other than its own. */
607 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
609 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
611 /* The type length is not a part of the main type. Update it for
612 each type on the variant chain. */
615 /* Assert that this element of the chain has no address-class bits
616 set in its flags. Such type variants might have type lengths
617 which are supposed to be different from the non-address-class
618 variants. This assertion shouldn't ever be triggered because
619 symbol readers which do construct address-class variants don't
620 call replace_type(). */
621 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
623 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
624 chain = TYPE_CHAIN (chain);
625 } while (ntype != chain);
627 /* Assert that the two types have equivalent instance qualifiers.
628 This should be true for at least all of our debug readers. */
629 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
632 /* Implement direct support for MEMBER_TYPE in GNU C++.
633 May need to construct such a type if this is the first use.
634 The TYPE is the type of the member. The DOMAIN is the type
635 of the aggregate that the member belongs to. */
638 lookup_memberptr_type (struct type *type, struct type *domain)
642 mtype = alloc_type (TYPE_OBJFILE (type));
643 smash_to_memberptr_type (mtype, domain, type);
647 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
650 lookup_methodptr_type (struct type *to_type)
654 mtype = alloc_type (TYPE_OBJFILE (to_type));
655 TYPE_TARGET_TYPE (mtype) = to_type;
656 TYPE_DOMAIN_TYPE (mtype) = TYPE_DOMAIN_TYPE (to_type);
657 TYPE_LENGTH (mtype) = cplus_method_ptr_size ();
658 TYPE_CODE (mtype) = TYPE_CODE_METHODPTR;
662 /* Allocate a stub method whose return type is TYPE. This apparently
663 happens for speed of symbol reading, since parsing out the
664 arguments to the method is cpu-intensive, the way we are doing it.
665 So, we will fill in arguments later. This always returns a fresh
669 allocate_stub_method (struct type *type)
673 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
674 TYPE_OBJFILE (type));
675 TYPE_TARGET_TYPE (mtype) = type;
676 /* _DOMAIN_TYPE (mtype) = unknown yet */
680 /* Create a range type using either a blank type supplied in
681 RESULT_TYPE, or creating a new type, inheriting the objfile from
684 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
685 to HIGH_BOUND, inclusive.
687 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
688 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
691 create_range_type (struct type *result_type, struct type *index_type,
692 int low_bound, int high_bound)
694 if (result_type == NULL)
696 result_type = alloc_type (TYPE_OBJFILE (index_type));
698 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
699 TYPE_TARGET_TYPE (result_type) = index_type;
700 if (TYPE_STUB (index_type))
701 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
703 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
704 TYPE_NFIELDS (result_type) = 2;
705 TYPE_FIELDS (result_type) = (struct field *)
706 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
707 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
708 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
709 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
710 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
711 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
714 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
716 return (result_type);
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_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
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 TYPE_LENGTH (result_type) =
816 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
817 TYPE_NFIELDS (result_type) = 1;
818 TYPE_FIELDS (result_type) =
819 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
820 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
821 TYPE_FIELD_TYPE (result_type, 0) = range_type;
822 TYPE_VPTR_FIELDNO (result_type) = -1;
824 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
825 if (TYPE_LENGTH (result_type) == 0)
826 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
828 return (result_type);
831 /* Create a string type using either a blank type supplied in
832 RESULT_TYPE, or creating a new type. String types are similar
833 enough to array of char types that we can use create_array_type to
834 build the basic type and then bash it into a string type.
836 For fixed length strings, the range type contains 0 as the lower
837 bound and the length of the string minus one as the upper bound.
839 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
840 sure it is TYPE_CODE_UNDEF before we bash it into a string
844 create_string_type (struct type *result_type,
845 struct type *range_type)
847 struct type *string_char_type;
849 string_char_type = language_string_char_type (current_language,
851 result_type = create_array_type (result_type,
854 TYPE_CODE (result_type) = TYPE_CODE_STRING;
855 return (result_type);
859 create_set_type (struct type *result_type, struct type *domain_type)
861 if (result_type == NULL)
863 result_type = alloc_type (TYPE_OBJFILE (domain_type));
865 TYPE_CODE (result_type) = TYPE_CODE_SET;
866 TYPE_NFIELDS (result_type) = 1;
867 TYPE_FIELDS (result_type) = (struct field *)
868 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
869 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
871 if (!TYPE_STUB (domain_type))
873 LONGEST low_bound, high_bound, bit_length;
874 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
875 low_bound = high_bound = 0;
876 bit_length = high_bound - low_bound + 1;
877 TYPE_LENGTH (result_type)
878 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
880 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
882 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
884 return (result_type);
888 append_flags_type_flag (struct type *type, int bitpos, char *name)
890 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
891 gdb_assert (bitpos < TYPE_NFIELDS (type));
892 gdb_assert (bitpos >= 0);
896 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
897 TYPE_FIELD_BITPOS (type, bitpos) = bitpos;
901 /* Don't show this field to the user. */
902 TYPE_FIELD_BITPOS (type, bitpos) = -1;
907 init_flags_type (char *name, int length)
909 int nfields = length * TARGET_CHAR_BIT;
912 type = init_type (TYPE_CODE_FLAGS, length,
913 TYPE_FLAG_UNSIGNED, name, NULL);
914 TYPE_NFIELDS (type) = nfields;
915 TYPE_FIELDS (type) = TYPE_ALLOC (type,
916 nfields * sizeof (struct field));
917 memset (TYPE_FIELDS (type), 0, nfields * sizeof (struct field));
923 init_vector_type (struct type *elt_type, int n)
925 struct type *array_type;
927 array_type = create_array_type (0, elt_type,
928 create_range_type (0,
931 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
935 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
936 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
937 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
938 TYPE doesn't include the offset (that's the value of the MEMBER
939 itself), but does include the structure type into which it points
942 When "smashing" the type, we preserve the objfile that the old type
943 pointed to, since we aren't changing where the type is actually
947 smash_to_memberptr_type (struct type *type, struct type *domain,
948 struct type *to_type)
950 struct objfile *objfile;
952 objfile = TYPE_OBJFILE (type);
955 TYPE_OBJFILE (type) = objfile;
956 TYPE_TARGET_TYPE (type) = to_type;
957 TYPE_DOMAIN_TYPE (type) = domain;
958 /* Assume that a data member pointer is the same size as a normal
960 TYPE_LENGTH (type) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
961 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
964 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
965 METHOD just means `function that gets an extra "this" argument'.
967 When "smashing" the type, we preserve the objfile that the old type
968 pointed to, since we aren't changing where the type is actually
972 smash_to_method_type (struct type *type, struct type *domain,
973 struct type *to_type, struct field *args,
974 int nargs, int varargs)
976 struct objfile *objfile;
978 objfile = TYPE_OBJFILE (type);
981 TYPE_OBJFILE (type) = objfile;
982 TYPE_TARGET_TYPE (type) = to_type;
983 TYPE_DOMAIN_TYPE (type) = domain;
984 TYPE_FIELDS (type) = args;
985 TYPE_NFIELDS (type) = nargs;
987 TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
988 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
989 TYPE_CODE (type) = TYPE_CODE_METHOD;
992 /* Return a typename for a struct/union/enum type without "struct ",
993 "union ", or "enum ". If the type has a NULL name, return NULL. */
996 type_name_no_tag (const struct type *type)
998 if (TYPE_TAG_NAME (type) != NULL)
999 return TYPE_TAG_NAME (type);
1001 /* Is there code which expects this to return the name if there is
1002 no tag name? My guess is that this is mainly used for C++ in
1003 cases where the two will always be the same. */
1004 return TYPE_NAME (type);
1007 /* Lookup a typedef or primitive type named NAME, visible in lexical
1008 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1009 suitably defined. */
1012 lookup_typename (char *name, struct block *block, int noerr)
1017 sym = lookup_symbol (name, block, VAR_DOMAIN, 0,
1018 (struct symtab **) NULL);
1019 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1021 tmp = language_lookup_primitive_type_by_name (current_language,
1028 else if (!tmp && noerr)
1034 error (_("No type named %s."), name);
1037 return (SYMBOL_TYPE (sym));
1041 lookup_unsigned_typename (char *name)
1043 char *uns = alloca (strlen (name) + 10);
1045 strcpy (uns, "unsigned ");
1046 strcpy (uns + 9, name);
1047 return (lookup_typename (uns, (struct block *) NULL, 0));
1051 lookup_signed_typename (char *name)
1054 char *uns = alloca (strlen (name) + 8);
1056 strcpy (uns, "signed ");
1057 strcpy (uns + 7, name);
1058 t = lookup_typename (uns, (struct block *) NULL, 1);
1059 /* If we don't find "signed FOO" just try again with plain "FOO". */
1062 return lookup_typename (name, (struct block *) NULL, 0);
1065 /* Lookup a structure type named "struct NAME",
1066 visible in lexical block BLOCK. */
1069 lookup_struct (char *name, struct block *block)
1073 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1074 (struct symtab **) NULL);
1078 error (_("No struct type named %s."), name);
1080 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1082 error (_("This context has class, union or enum %s, not a struct."),
1085 return (SYMBOL_TYPE (sym));
1088 /* Lookup a union type named "union NAME",
1089 visible in lexical block BLOCK. */
1092 lookup_union (char *name, struct block *block)
1097 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1098 (struct symtab **) NULL);
1101 error (_("No union type named %s."), name);
1103 t = SYMBOL_TYPE (sym);
1105 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1108 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1109 * a further "declared_type" field to discover it is really a union.
1111 if (HAVE_CPLUS_STRUCT (t))
1112 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1115 /* If we get here, it's not a union. */
1116 error (_("This context has class, struct or enum %s, not a union."),
1121 /* Lookup an enum type named "enum NAME",
1122 visible in lexical block BLOCK. */
1125 lookup_enum (char *name, struct block *block)
1129 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1130 (struct symtab **) NULL);
1133 error (_("No enum type named %s."), name);
1135 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1137 error (_("This context has class, struct or union %s, not an enum."),
1140 return (SYMBOL_TYPE (sym));
1143 /* Lookup a template type named "template NAME<TYPE>",
1144 visible in lexical block BLOCK. */
1147 lookup_template_type (char *name, struct type *type,
1148 struct block *block)
1151 char *nam = (char *)
1152 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1155 strcat (nam, TYPE_NAME (type));
1156 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1158 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0,
1159 (struct symtab **) NULL);
1163 error (_("No template type named %s."), name);
1165 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1167 error (_("This context has class, union or enum %s, not a struct."),
1170 return (SYMBOL_TYPE (sym));
1173 /* Given a type TYPE, lookup the type of the component of type named
1176 TYPE can be either a struct or union, or a pointer or reference to
1177 a struct or union. If it is a pointer or reference, its target
1178 type is automatically used. Thus '.' and '->' are interchangable,
1179 as specified for the definitions of the expression element types
1180 STRUCTOP_STRUCT and STRUCTOP_PTR.
1182 If NOERR is nonzero, return zero if NAME is not suitably defined.
1183 If NAME is the name of a baseclass type, return that type. */
1186 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1192 CHECK_TYPEDEF (type);
1193 if (TYPE_CODE (type) != TYPE_CODE_PTR
1194 && TYPE_CODE (type) != TYPE_CODE_REF)
1196 type = TYPE_TARGET_TYPE (type);
1199 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1200 && TYPE_CODE (type) != TYPE_CODE_UNION)
1202 target_terminal_ours ();
1203 gdb_flush (gdb_stdout);
1204 fprintf_unfiltered (gdb_stderr, "Type ");
1205 type_print (type, "", gdb_stderr, -1);
1206 error (_(" is not a structure or union type."));
1210 /* FIXME: This change put in by Michael seems incorrect for the case
1211 where the structure tag name is the same as the member name.
1212 I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
1213 foo; } bell;" Disabled by fnf. */
1217 typename = type_name_no_tag (type);
1218 if (typename != NULL && strcmp (typename, name) == 0)
1223 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1225 char *t_field_name = TYPE_FIELD_NAME (type, i);
1227 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1229 return TYPE_FIELD_TYPE (type, i);
1233 /* OK, it's not in this class. Recursively check the baseclasses. */
1234 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1238 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1250 target_terminal_ours ();
1251 gdb_flush (gdb_stdout);
1252 fprintf_unfiltered (gdb_stderr, "Type ");
1253 type_print (type, "", gdb_stderr, -1);
1254 fprintf_unfiltered (gdb_stderr, " has no component named ");
1255 fputs_filtered (name, gdb_stderr);
1257 return (struct type *) -1; /* For lint */
1260 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1261 valid. Callers should be aware that in some cases (for example,
1262 the type or one of its baseclasses is a stub type and we are
1263 debugging a .o file), this function will not be able to find the
1264 virtual function table pointer, and vptr_fieldno will remain -1 and
1265 vptr_basetype will remain NULL. */
1268 fill_in_vptr_fieldno (struct type *type)
1270 CHECK_TYPEDEF (type);
1272 if (TYPE_VPTR_FIELDNO (type) < 0)
1276 /* We must start at zero in case the first (and only) baseclass
1277 is virtual (and hence we cannot share the table pointer). */
1278 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1280 struct type *baseclass = check_typedef (TYPE_BASECLASS (type,
1282 fill_in_vptr_fieldno (baseclass);
1283 if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
1285 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
1286 TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
1293 /* Find the method and field indices for the destructor in class type T.
1294 Return 1 if the destructor was found, otherwise, return 0. */
1297 get_destructor_fn_field (struct type *t,
1303 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1306 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1308 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1310 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1322 stub_noname_complaint (void)
1324 complaint (&symfile_complaints, _("stub type has NULL name"));
1327 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1329 If this is a stubbed struct (i.e. declared as struct foo *), see if
1330 we can find a full definition in some other file. If so, copy this
1331 definition, so we can use it in future. There used to be a comment
1332 (but not any code) that if we don't find a full definition, we'd
1333 set a flag so we don't spend time in the future checking the same
1334 type. That would be a mistake, though--we might load in more
1335 symbols which contain a full definition for the type.
1337 This used to be coded as a macro, but I don't think it is called
1338 often enough to merit such treatment. */
1340 /* Find the real type of TYPE. This function returns the real type,
1341 after removing all layers of typedefs and completing opaque or stub
1342 types. Completion changes the TYPE argument, but stripping of
1343 typedefs does not. */
1346 check_typedef (struct type *type)
1348 struct type *orig_type = type;
1349 int is_const, is_volatile;
1353 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1355 if (!TYPE_TARGET_TYPE (type))
1360 /* It is dangerous to call lookup_symbol if we are currently
1361 reading a symtab. Infinite recursion is one danger. */
1362 if (currently_reading_symtab)
1365 name = type_name_no_tag (type);
1366 /* FIXME: shouldn't we separately check the TYPE_NAME and
1367 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1368 VAR_DOMAIN as appropriate? (this code was written before
1369 TYPE_NAME and TYPE_TAG_NAME were separate). */
1372 stub_noname_complaint ();
1375 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
1376 (struct symtab **) NULL);
1378 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1379 else /* TYPE_CODE_UNDEF */
1380 TYPE_TARGET_TYPE (type) = alloc_type (NULL);
1382 type = TYPE_TARGET_TYPE (type);
1385 is_const = TYPE_CONST (type);
1386 is_volatile = TYPE_VOLATILE (type);
1388 /* If this is a struct/class/union with no fields, then check
1389 whether a full definition exists somewhere else. This is for
1390 systems where a type definition with no fields is issued for such
1391 types, instead of identifying them as stub types in the first
1394 if (TYPE_IS_OPAQUE (type)
1395 && opaque_type_resolution
1396 && !currently_reading_symtab)
1398 char *name = type_name_no_tag (type);
1399 struct type *newtype;
1402 stub_noname_complaint ();
1405 newtype = lookup_transparent_type (name);
1409 /* If the resolved type and the stub are in the same
1410 objfile, then replace the stub type with the real deal.
1411 But if they're in separate objfiles, leave the stub
1412 alone; we'll just look up the transparent type every time
1413 we call check_typedef. We can't create pointers between
1414 types allocated to different objfiles, since they may
1415 have different lifetimes. Trying to copy NEWTYPE over to
1416 TYPE's objfile is pointless, too, since you'll have to
1417 move over any other types NEWTYPE refers to, which could
1418 be an unbounded amount of stuff. */
1419 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
1420 make_cv_type (is_const, is_volatile, newtype, &type);
1425 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1427 else if (TYPE_STUB (type) && !currently_reading_symtab)
1429 char *name = type_name_no_tag (type);
1430 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1431 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1432 as appropriate? (this code was written before TYPE_NAME and
1433 TYPE_TAG_NAME were separate). */
1437 stub_noname_complaint ();
1440 sym = lookup_symbol (name, 0, STRUCT_DOMAIN,
1441 0, (struct symtab **) NULL);
1444 /* Same as above for opaque types, we can replace the stub
1445 with the complete type only if they are int the same
1447 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
1448 make_cv_type (is_const, is_volatile,
1449 SYMBOL_TYPE (sym), &type);
1451 type = SYMBOL_TYPE (sym);
1455 if (TYPE_TARGET_STUB (type))
1457 struct type *range_type;
1458 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1460 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1464 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1465 && TYPE_NFIELDS (type) == 1
1466 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1467 == TYPE_CODE_RANGE))
1469 /* Now recompute the length of the array type, based on its
1470 number of elements and the target type's length. */
1471 TYPE_LENGTH (type) =
1472 ((TYPE_FIELD_BITPOS (range_type, 1)
1473 - TYPE_FIELD_BITPOS (range_type, 0) + 1)
1474 * TYPE_LENGTH (target_type));
1475 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1477 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1479 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1480 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1483 /* Cache TYPE_LENGTH for future use. */
1484 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1488 /* Parse a type expression in the string [P..P+LENGTH). If an error
1489 occurs, silently return builtin_type_void. */
1491 static struct type *
1492 safe_parse_type (char *p, int length)
1494 struct ui_file *saved_gdb_stderr;
1497 /* Suppress error messages. */
1498 saved_gdb_stderr = gdb_stderr;
1499 gdb_stderr = ui_file_new ();
1501 /* Call parse_and_eval_type() without fear of longjmp()s. */
1502 if (!gdb_parse_and_eval_type (p, length, &type))
1503 type = builtin_type_void;
1505 /* Stop suppressing error messages. */
1506 ui_file_delete (gdb_stderr);
1507 gdb_stderr = saved_gdb_stderr;
1512 /* Ugly hack to convert method stubs into method types.
1514 He ain't kiddin'. This demangles the name of the method into a
1515 string including argument types, parses out each argument type,
1516 generates a string casting a zero to that type, evaluates the
1517 string, and stuffs the resulting type into an argtype vector!!!
1518 Then it knows the type of the whole function (including argument
1519 types for overloading), which info used to be in the stab's but was
1520 removed to hack back the space required for them. */
1523 check_stub_method (struct type *type, int method_id, int signature_id)
1526 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1527 char *demangled_name = cplus_demangle (mangled_name,
1528 DMGL_PARAMS | DMGL_ANSI);
1529 char *argtypetext, *p;
1530 int depth = 0, argcount = 1;
1531 struct field *argtypes;
1534 /* Make sure we got back a function string that we can use. */
1536 p = strchr (demangled_name, '(');
1540 if (demangled_name == NULL || p == NULL)
1541 error (_("Internal: Cannot demangle mangled name `%s'."),
1544 /* Now, read in the parameters that define this type. */
1549 if (*p == '(' || *p == '<')
1553 else if (*p == ')' || *p == '>')
1557 else if (*p == ',' && depth == 0)
1565 /* If we read one argument and it was ``void'', don't count it. */
1566 if (strncmp (argtypetext, "(void)", 6) == 0)
1569 /* We need one extra slot, for the THIS pointer. */
1571 argtypes = (struct field *)
1572 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1575 /* Add THIS pointer for non-static methods. */
1576 f = TYPE_FN_FIELDLIST1 (type, method_id);
1577 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1581 argtypes[0].type = lookup_pointer_type (type);
1585 if (*p != ')') /* () means no args, skip while */
1590 if (depth <= 0 && (*p == ',' || *p == ')'))
1592 /* Avoid parsing of ellipsis, they will be handled below.
1593 Also avoid ``void'' as above. */
1594 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1595 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1597 argtypes[argcount].type =
1598 safe_parse_type (argtypetext, p - argtypetext);
1601 argtypetext = p + 1;
1604 if (*p == '(' || *p == '<')
1608 else if (*p == ')' || *p == '>')
1617 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1619 /* Now update the old "stub" type into a real type. */
1620 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1621 TYPE_DOMAIN_TYPE (mtype) = type;
1622 TYPE_FIELDS (mtype) = argtypes;
1623 TYPE_NFIELDS (mtype) = argcount;
1624 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1625 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1627 TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1629 xfree (demangled_name);
1632 /* This is the external interface to check_stub_method, above. This
1633 function unstubs all of the signatures for TYPE's METHOD_ID method
1634 name. After calling this function TYPE_FN_FIELD_STUB will be
1635 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1638 This function unfortunately can not die until stabs do. */
1641 check_stub_method_group (struct type *type, int method_id)
1643 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1644 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1645 int j, found_stub = 0;
1647 for (j = 0; j < len; j++)
1648 if (TYPE_FN_FIELD_STUB (f, j))
1651 check_stub_method (type, method_id, j);
1654 /* GNU v3 methods with incorrect names were corrected when we read
1655 in type information, because it was cheaper to do it then. The
1656 only GNU v2 methods with incorrect method names are operators and
1657 destructors; destructors were also corrected when we read in type
1660 Therefore the only thing we need to handle here are v2 operator
1662 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1665 char dem_opname[256];
1667 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1669 dem_opname, DMGL_ANSI);
1671 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1675 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1679 const struct cplus_struct_type cplus_struct_default;
1682 allocate_cplus_struct_type (struct type *type)
1684 if (!HAVE_CPLUS_STRUCT (type))
1686 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1687 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1688 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1692 /* Helper function to initialize the standard scalar types.
1694 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy of
1695 the string pointed to by name in the objfile_obstack for that
1696 objfile, and initialize the type name to that copy. There are
1697 places (mipsread.c in particular, where init_type is called with a
1698 NULL value for NAME). */
1701 init_type (enum type_code code, int length, int flags,
1702 char *name, struct objfile *objfile)
1706 type = alloc_type (objfile);
1707 TYPE_CODE (type) = code;
1708 TYPE_LENGTH (type) = length;
1709 TYPE_FLAGS (type) |= flags;
1710 if ((name != NULL) && (objfile != NULL))
1712 TYPE_NAME (type) = obsavestring (name, strlen (name),
1713 &objfile->objfile_obstack);
1717 TYPE_NAME (type) = name;
1722 if (name && strcmp (name, "char") == 0)
1723 TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
1725 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1726 || code == TYPE_CODE_NAMESPACE)
1728 INIT_CPLUS_SPECIFIC (type);
1733 /* Helper function. Create an empty composite type. */
1736 init_composite_type (char *name, enum type_code code)
1739 gdb_assert (code == TYPE_CODE_STRUCT
1740 || code == TYPE_CODE_UNION);
1741 t = init_type (code, 0, 0, NULL, NULL);
1742 TYPE_TAG_NAME (t) = name;
1746 /* Helper function. Append a field to a composite type. */
1749 append_composite_type_field (struct type *t, char *name,
1753 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1754 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1755 sizeof (struct field) * TYPE_NFIELDS (t));
1756 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1757 memset (f, 0, sizeof f[0]);
1758 FIELD_TYPE (f[0]) = field;
1759 FIELD_NAME (f[0]) = name;
1760 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1762 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1763 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1765 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1767 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1768 if (TYPE_NFIELDS (t) > 1)
1770 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1771 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1776 /* Look up a fundamental type for the specified objfile.
1777 May need to construct such a type if this is the first use.
1779 Some object file formats (ELF, COFF, etc) do not define fundamental
1780 types such as "int" or "double". Others (stabs for example), do
1781 define fundamental types.
1783 For the formats which don't provide fundamental types, gdb can
1784 create such types, using defaults reasonable for the current
1785 language and the current target machine.
1787 NOTE: This routine is obsolescent. Each debugging format reader
1788 should manage it's own fundamental types, either creating them from
1789 suitable defaults or reading them from the debugging information,
1790 whichever is appropriate. The DWARF reader has already been fixed
1791 to do this. Once the other readers are fixed, this routine will go
1792 away. Also note that fundamental types should be managed on a
1793 compilation unit basis in a multi-language environment, not on a
1794 linkage unit basis as is done here. */
1798 lookup_fundamental_type (struct objfile *objfile, int typeid)
1800 struct type **typep;
1803 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1805 error (_("internal error - invalid fundamental type id %d"),
1809 /* If this is the first time we need a fundamental type for this
1810 objfile then we need to initialize the vector of type
1813 if (objfile->fundamental_types == NULL)
1815 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1816 objfile->fundamental_types = (struct type **)
1817 obstack_alloc (&objfile->objfile_obstack, nbytes);
1818 memset ((char *) objfile->fundamental_types, 0, nbytes);
1819 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1822 /* Look for this particular type in the fundamental type vector. If
1823 one is not found, create and install one appropriate for the
1824 current language. */
1826 typep = objfile->fundamental_types + typeid;
1829 *typep = create_fundamental_type (objfile, typeid);
1836 can_dereference (struct type *t)
1838 /* FIXME: Should we return true for references as well as
1843 && TYPE_CODE (t) == TYPE_CODE_PTR
1844 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1848 is_integral_type (struct type *t)
1853 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1854 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1855 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
1856 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1857 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1858 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1861 /* Check whether BASE is an ancestor or base class or DCLASS
1862 Return 1 if so, and 0 if not.
1863 Note: callers may want to check for identity of the types before
1864 calling this function -- identical types are considered to satisfy
1865 the ancestor relationship even if they're identical. */
1868 is_ancestor (struct type *base, struct type *dclass)
1872 CHECK_TYPEDEF (base);
1873 CHECK_TYPEDEF (dclass);
1877 if (TYPE_NAME (base) && TYPE_NAME (dclass)
1878 && !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1881 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1882 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1890 /* See whether DCLASS has a virtual table. This routine is aimed at
1891 the HP/Taligent ANSI C++ runtime model, and may not work with other
1892 runtime models. Return 1 => Yes, 0 => No. */
1895 has_vtable (struct type *dclass)
1897 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1898 has virtual functions or virtual bases. */
1902 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1905 /* First check for the presence of virtual bases. */
1906 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1907 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1908 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1911 /* Next check for virtual functions. */
1912 if (TYPE_FN_FIELDLISTS (dclass))
1913 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1914 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1917 /* Recurse on non-virtual bases to see if any of them needs a
1919 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1920 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1921 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1922 && (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1925 /* Well, maybe we don't need a virtual table. */
1929 /* Return a pointer to the "primary base class" of DCLASS.
1931 A NULL return indicates that DCLASS has no primary base, or that it
1932 couldn't be found (insufficient information).
1934 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1935 and may not work with other runtime models. */
1938 primary_base_class (struct type *dclass)
1940 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1941 is the first directly inherited, non-virtual base class that
1942 requires a virtual table. */
1946 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1949 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1950 if (!TYPE_FIELD_VIRTUAL (dclass, i)
1951 && has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1952 return TYPE_FIELD_TYPE (dclass, i);
1957 /* Global manipulated by virtual_base_list[_aux](). */
1959 static struct vbase *current_vbase_list = NULL;
1961 /* Return a pointer to a null-terminated list of struct vbase items.
1962 The vbasetype pointer of each item in the list points to the type
1963 information for a virtual base of the argument DCLASS.
1965 Helper function for virtual_base_list().
1966 Note: the list goes backward, right-to-left.
1967 virtual_base_list() copies the items out in reverse order. */
1970 virtual_base_list_aux (struct type *dclass)
1972 struct vbase *tmp_vbase;
1975 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1978 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1980 /* Recurse on this ancestor, first */
1981 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
1983 /* If this current base is itself virtual, add it to the list */
1984 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1986 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1988 /* Check if base already recorded */
1989 tmp_vbase = current_vbase_list;
1992 if (tmp_vbase->vbasetype == basetype)
1993 break; /* found it */
1994 tmp_vbase = tmp_vbase->next;
1997 if (!tmp_vbase) /* normal exit from loop */
1999 /* Allocate new item for this virtual base */
2000 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
2002 /* Stick it on at the end of the list */
2003 tmp_vbase->vbasetype = basetype;
2004 tmp_vbase->next = current_vbase_list;
2005 current_vbase_list = tmp_vbase;
2008 } /* for loop over bases */
2012 /* Compute the list of virtual bases in the right order. Virtual
2013 bases are laid out in the object's memory area in order of their
2014 occurrence in a depth-first, left-to-right search through the
2017 Argument DCLASS is the type whose virtual bases are required.
2018 Return value is the address of a null-terminated array of pointers
2019 to struct type items.
2021 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2022 and may not work with other runtime models.
2024 This routine merely hands off the argument to virtual_base_list_aux()
2025 and then copies the result into an array to save space. */
2028 virtual_base_list (struct type *dclass)
2030 struct vbase *tmp_vbase;
2031 struct vbase *tmp_vbase_2;
2034 struct type **vbase_array;
2036 current_vbase_list = NULL;
2037 virtual_base_list_aux (dclass);
2039 for (i = 0, tmp_vbase = current_vbase_list;
2041 i++, tmp_vbase = tmp_vbase->next)
2046 vbase_array = (struct type **)
2047 xmalloc ((count + 1) * sizeof (struct type *));
2049 for (i = count - 1, tmp_vbase = current_vbase_list;
2051 tmp_vbase = tmp_vbase->next)
2052 vbase_array[i] = tmp_vbase->vbasetype;
2054 /* Get rid of constructed chain. */
2055 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2058 tmp_vbase = tmp_vbase->next;
2059 xfree (tmp_vbase_2);
2060 tmp_vbase_2 = tmp_vbase;
2063 vbase_array[count] = NULL;
2067 /* Return the length of the virtual base list of the type DCLASS. */
2070 virtual_base_list_length (struct type *dclass)
2073 struct vbase *tmp_vbase;
2075 current_vbase_list = NULL;
2076 virtual_base_list_aux (dclass);
2078 for (i = 0, tmp_vbase = current_vbase_list;
2080 i++, tmp_vbase = tmp_vbase->next)
2085 /* Return the number of elements of the virtual base list of the type
2086 DCLASS, ignoring those appearing in the primary base (and its
2087 primary base, recursively). */
2090 virtual_base_list_length_skip_primaries (struct type *dclass)
2093 struct vbase *tmp_vbase;
2094 struct type *primary;
2096 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2099 return virtual_base_list_length (dclass);
2101 current_vbase_list = NULL;
2102 virtual_base_list_aux (dclass);
2104 for (i = 0, tmp_vbase = current_vbase_list;
2106 tmp_vbase = tmp_vbase->next)
2108 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
2116 /* Return the index (position) of type BASE, which is a virtual base
2117 class of DCLASS, in the latter's virtual base list. A return of -1
2118 indicates "not found" or a problem. */
2121 virtual_base_index (struct type *base, struct type *dclass)
2126 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS)
2127 || (TYPE_CODE (base) != TYPE_CODE_CLASS))
2131 vbase = virtual_base_list (dclass)[0];
2136 vbase = virtual_base_list (dclass)[++i];
2139 return vbase ? i : -1;
2144 /* Return the index (position) of type BASE, which is a virtual base
2145 class of DCLASS, in the latter's virtual base list. Skip over all
2146 bases that may appear in the virtual base list of the primary base
2147 class of DCLASS (recursively). A return of -1 indicates "not
2148 found" or a problem. */
2151 virtual_base_index_skip_primaries (struct type *base,
2152 struct type *dclass)
2156 struct type *primary;
2158 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS)
2159 || (TYPE_CODE (base) != TYPE_CODE_CLASS))
2162 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2166 vbase = virtual_base_list (dclass)[0];
2170 || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2174 vbase = virtual_base_list (dclass)[++i];
2177 return vbase ? j : -1;
2180 /* Return position of a derived class DCLASS in the list of primary
2181 bases starting with the remotest ancestor. Position returned is
2185 class_index_in_primary_list (struct type *dclass)
2187 struct type *pbc; /* primary base class */
2189 /* Simply recurse on primary base */
2190 pbc = TYPE_PRIMARY_BASE (dclass);
2192 return 1 + class_index_in_primary_list (pbc);
2197 /* Return a count of the number of virtual functions a type has. This
2198 includes all the virtual functions it inherits from its base
2201 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2202 functions only once (latest redefinition). */
2205 count_virtual_fns (struct type *dclass)
2207 int fn, oi; /* function and overloaded instance indices */
2208 int vfuncs; /* count to return */
2210 /* recurse on bases that can share virtual table */
2211 struct type *pbc = primary_base_class (dclass);
2213 vfuncs = count_virtual_fns (pbc);
2217 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2218 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2219 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2227 /* Functions for overload resolution begin here */
2229 /* Compare two badness vectors A and B and return the result.
2230 0 => A and B are identical
2231 1 => A and B are incomparable
2232 2 => A is better than B
2233 3 => A is worse than B */
2236 compare_badness (struct badness_vector *a, struct badness_vector *b)
2240 short found_pos = 0; /* any positives in c? */
2241 short found_neg = 0; /* any negatives in c? */
2243 /* differing lengths => incomparable */
2244 if (a->length != b->length)
2247 /* Subtract b from a */
2248 for (i = 0; i < a->length; i++)
2250 tmp = a->rank[i] - b->rank[i];
2260 return 1; /* incomparable */
2262 return 3; /* A > B */
2268 return 2; /* A < B */
2270 return 0; /* A == B */
2274 /* Rank a function by comparing its parameter types (PARMS, length
2275 NPARMS), to the types of an argument list (ARGS, length NARGS).
2276 Return a pointer to a badness vector. This has NARGS + 1
2279 struct badness_vector *
2280 rank_function (struct type **parms, int nparms,
2281 struct type **args, int nargs)
2284 struct badness_vector *bv;
2285 int min_len = nparms < nargs ? nparms : nargs;
2287 bv = xmalloc (sizeof (struct badness_vector));
2288 bv->length = nargs + 1; /* add 1 for the length-match rank */
2289 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2291 /* First compare the lengths of the supplied lists.
2292 If there is a mismatch, set it to a high value. */
2294 /* pai/1997-06-03 FIXME: when we have debug info about default
2295 arguments and ellipsis parameter lists, we should consider those
2296 and rank the length-match more finely. */
2298 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2300 /* Now rank all the parameters of the candidate function */
2301 for (i = 1; i <= min_len; i++)
2302 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2304 /* If more arguments than parameters, add dummy entries */
2305 for (i = min_len + 1; i <= nargs; i++)
2306 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2311 /* Compare the names of two integer types, assuming that any sign
2312 qualifiers have been checked already. We do it this way because
2313 there may be an "int" in the name of one of the types. */
2316 integer_types_same_name_p (const char *first, const char *second)
2318 int first_p, second_p;
2320 /* If both are shorts, return 1; if neither is a short, keep
2322 first_p = (strstr (first, "short") != NULL);
2323 second_p = (strstr (second, "short") != NULL);
2324 if (first_p && second_p)
2326 if (first_p || second_p)
2329 /* Likewise for long. */
2330 first_p = (strstr (first, "long") != NULL);
2331 second_p = (strstr (second, "long") != NULL);
2332 if (first_p && second_p)
2334 if (first_p || second_p)
2337 /* Likewise for char. */
2338 first_p = (strstr (first, "char") != NULL);
2339 second_p = (strstr (second, "char") != NULL);
2340 if (first_p && second_p)
2342 if (first_p || second_p)
2345 /* They must both be ints. */
2349 /* Compare one type (PARM) for compatibility with another (ARG).
2350 * PARM is intended to be the parameter type of a function; and
2351 * ARG is the supplied argument's type. This function tests if
2352 * the latter can be converted to the former.
2354 * Return 0 if they are identical types;
2355 * Otherwise, return an integer which corresponds to how compatible
2356 * PARM is to ARG. The higher the return value, the worse the match.
2357 * Generally the "bad" conversions are all uniformly assigned a 100. */
2360 rank_one_type (struct type *parm, struct type *arg)
2362 /* Identical type pointers. */
2363 /* However, this still doesn't catch all cases of same type for arg
2364 and param. The reason is that builtin types are different from
2365 the same ones constructed from the object. */
2369 /* Resolve typedefs */
2370 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2371 parm = check_typedef (parm);
2372 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2373 arg = check_typedef (arg);
2376 Well, damnit, if the names are exactly the same, I'll say they
2377 are exactly the same. This happens when we generate method
2378 stubs. The types won't point to the same address, but they
2379 really are the same.
2382 if (TYPE_NAME (parm) && TYPE_NAME (arg)
2383 && !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2386 /* Check if identical after resolving typedefs. */
2390 /* See through references, since we can almost make non-references
2392 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2393 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2394 + REFERENCE_CONVERSION_BADNESS);
2395 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2396 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2397 + REFERENCE_CONVERSION_BADNESS);
2399 /* Debugging only. */
2400 fprintf_filtered (gdb_stderr,
2401 "------ Arg is %s [%d], parm is %s [%d]\n",
2402 TYPE_NAME (arg), TYPE_CODE (arg),
2403 TYPE_NAME (parm), TYPE_CODE (parm));
2405 /* x -> y means arg of type x being supplied for parameter of type y */
2407 switch (TYPE_CODE (parm))
2410 switch (TYPE_CODE (arg))
2413 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2414 return VOID_PTR_CONVERSION_BADNESS;
2416 return rank_one_type (TYPE_TARGET_TYPE (parm),
2417 TYPE_TARGET_TYPE (arg));
2418 case TYPE_CODE_ARRAY:
2419 return rank_one_type (TYPE_TARGET_TYPE (parm),
2420 TYPE_TARGET_TYPE (arg));
2421 case TYPE_CODE_FUNC:
2422 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2424 case TYPE_CODE_ENUM:
2425 case TYPE_CODE_FLAGS:
2426 case TYPE_CODE_CHAR:
2427 case TYPE_CODE_RANGE:
2428 case TYPE_CODE_BOOL:
2429 return POINTER_CONVERSION_BADNESS;
2431 return INCOMPATIBLE_TYPE_BADNESS;
2433 case TYPE_CODE_ARRAY:
2434 switch (TYPE_CODE (arg))
2437 case TYPE_CODE_ARRAY:
2438 return rank_one_type (TYPE_TARGET_TYPE (parm),
2439 TYPE_TARGET_TYPE (arg));
2441 return INCOMPATIBLE_TYPE_BADNESS;
2443 case TYPE_CODE_FUNC:
2444 switch (TYPE_CODE (arg))
2446 case TYPE_CODE_PTR: /* funcptr -> func */
2447 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2449 return INCOMPATIBLE_TYPE_BADNESS;
2452 switch (TYPE_CODE (arg))
2455 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2457 /* Deal with signed, unsigned, and plain chars and
2458 signed and unsigned ints. */
2459 if (TYPE_NOSIGN (parm))
2461 /* This case only for character types */
2462 if (TYPE_NOSIGN (arg))
2463 return 0; /* plain char -> plain char */
2464 else /* signed/unsigned char -> plain char */
2465 return INTEGER_CONVERSION_BADNESS;
2467 else if (TYPE_UNSIGNED (parm))
2469 if (TYPE_UNSIGNED (arg))
2471 /* unsigned int -> unsigned int, or
2472 unsigned long -> unsigned long */
2473 if (integer_types_same_name_p (TYPE_NAME (parm),
2476 else if (integer_types_same_name_p (TYPE_NAME (arg),
2478 && integer_types_same_name_p (TYPE_NAME (parm),
2480 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2482 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
2486 if (integer_types_same_name_p (TYPE_NAME (arg),
2488 && integer_types_same_name_p (TYPE_NAME (parm),
2490 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
2492 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2495 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2497 if (integer_types_same_name_p (TYPE_NAME (parm),
2500 else if (integer_types_same_name_p (TYPE_NAME (arg),
2502 && integer_types_same_name_p (TYPE_NAME (parm),
2504 return INTEGER_PROMOTION_BADNESS;
2506 return INTEGER_CONVERSION_BADNESS;
2509 return INTEGER_CONVERSION_BADNESS;
2511 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2512 return INTEGER_PROMOTION_BADNESS;
2514 return INTEGER_CONVERSION_BADNESS;
2515 case TYPE_CODE_ENUM:
2516 case TYPE_CODE_FLAGS:
2517 case TYPE_CODE_CHAR:
2518 case TYPE_CODE_RANGE:
2519 case TYPE_CODE_BOOL:
2520 return INTEGER_PROMOTION_BADNESS;
2522 return INT_FLOAT_CONVERSION_BADNESS;
2524 return NS_POINTER_CONVERSION_BADNESS;
2526 return INCOMPATIBLE_TYPE_BADNESS;
2529 case TYPE_CODE_ENUM:
2530 switch (TYPE_CODE (arg))
2533 case TYPE_CODE_CHAR:
2534 case TYPE_CODE_RANGE:
2535 case TYPE_CODE_BOOL:
2536 case TYPE_CODE_ENUM:
2537 return INTEGER_CONVERSION_BADNESS;
2539 return INT_FLOAT_CONVERSION_BADNESS;
2541 return INCOMPATIBLE_TYPE_BADNESS;
2544 case TYPE_CODE_CHAR:
2545 switch (TYPE_CODE (arg))
2547 case TYPE_CODE_RANGE:
2548 case TYPE_CODE_BOOL:
2549 case TYPE_CODE_ENUM:
2550 return INTEGER_CONVERSION_BADNESS;
2552 return INT_FLOAT_CONVERSION_BADNESS;
2554 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2555 return INTEGER_CONVERSION_BADNESS;
2556 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2557 return INTEGER_PROMOTION_BADNESS;
2558 /* >>> !! else fall through !! <<< */
2559 case TYPE_CODE_CHAR:
2560 /* Deal with signed, unsigned, and plain chars for C++ and
2561 with int cases falling through from previous case. */
2562 if (TYPE_NOSIGN (parm))
2564 if (TYPE_NOSIGN (arg))
2567 return INTEGER_CONVERSION_BADNESS;
2569 else if (TYPE_UNSIGNED (parm))
2571 if (TYPE_UNSIGNED (arg))
2574 return INTEGER_PROMOTION_BADNESS;
2576 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2579 return INTEGER_CONVERSION_BADNESS;
2581 return INCOMPATIBLE_TYPE_BADNESS;
2584 case TYPE_CODE_RANGE:
2585 switch (TYPE_CODE (arg))
2588 case TYPE_CODE_CHAR:
2589 case TYPE_CODE_RANGE:
2590 case TYPE_CODE_BOOL:
2591 case TYPE_CODE_ENUM:
2592 return INTEGER_CONVERSION_BADNESS;
2594 return INT_FLOAT_CONVERSION_BADNESS;
2596 return INCOMPATIBLE_TYPE_BADNESS;
2599 case TYPE_CODE_BOOL:
2600 switch (TYPE_CODE (arg))
2603 case TYPE_CODE_CHAR:
2604 case TYPE_CODE_RANGE:
2605 case TYPE_CODE_ENUM:
2608 return BOOLEAN_CONVERSION_BADNESS;
2609 case TYPE_CODE_BOOL:
2612 return INCOMPATIBLE_TYPE_BADNESS;
2616 switch (TYPE_CODE (arg))
2619 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2620 return FLOAT_PROMOTION_BADNESS;
2621 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2624 return FLOAT_CONVERSION_BADNESS;
2626 case TYPE_CODE_BOOL:
2627 case TYPE_CODE_ENUM:
2628 case TYPE_CODE_RANGE:
2629 case TYPE_CODE_CHAR:
2630 return INT_FLOAT_CONVERSION_BADNESS;
2632 return INCOMPATIBLE_TYPE_BADNESS;
2635 case TYPE_CODE_COMPLEX:
2636 switch (TYPE_CODE (arg))
2637 { /* Strictly not needed for C++, but... */
2639 return FLOAT_PROMOTION_BADNESS;
2640 case TYPE_CODE_COMPLEX:
2643 return INCOMPATIBLE_TYPE_BADNESS;
2646 case TYPE_CODE_STRUCT:
2647 /* currently same as TYPE_CODE_CLASS */
2648 switch (TYPE_CODE (arg))
2650 case TYPE_CODE_STRUCT:
2651 /* Check for derivation */
2652 if (is_ancestor (parm, arg))
2653 return BASE_CONVERSION_BADNESS;
2654 /* else fall through */
2656 return INCOMPATIBLE_TYPE_BADNESS;
2659 case TYPE_CODE_UNION:
2660 switch (TYPE_CODE (arg))
2662 case TYPE_CODE_UNION:
2664 return INCOMPATIBLE_TYPE_BADNESS;
2667 case TYPE_CODE_MEMBERPTR:
2668 switch (TYPE_CODE (arg))
2671 return INCOMPATIBLE_TYPE_BADNESS;
2674 case TYPE_CODE_METHOD:
2675 switch (TYPE_CODE (arg))
2679 return INCOMPATIBLE_TYPE_BADNESS;
2683 switch (TYPE_CODE (arg))
2687 return INCOMPATIBLE_TYPE_BADNESS;
2692 switch (TYPE_CODE (arg))
2696 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
2697 TYPE_FIELD_TYPE (arg, 0));
2699 return INCOMPATIBLE_TYPE_BADNESS;
2702 case TYPE_CODE_VOID:
2704 return INCOMPATIBLE_TYPE_BADNESS;
2705 } /* switch (TYPE_CODE (arg)) */
2709 /* End of functions for overload resolution */
2712 print_bit_vector (B_TYPE *bits, int nbits)
2716 for (bitno = 0; bitno < nbits; bitno++)
2718 if ((bitno % 8) == 0)
2720 puts_filtered (" ");
2722 if (B_TST (bits, bitno))
2723 printf_filtered (("1"));
2725 printf_filtered (("0"));
2729 /* Note the first arg should be the "this" pointer, we may not want to
2730 include it since we may get into a infinitely recursive
2734 print_arg_types (struct field *args, int nargs, int spaces)
2740 for (i = 0; i < nargs; i++)
2741 recursive_dump_type (args[i].type, spaces + 2);
2746 dump_fn_fieldlists (struct type *type, int spaces)
2752 printfi_filtered (spaces, "fn_fieldlists ");
2753 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2754 printf_filtered ("\n");
2755 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2757 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2758 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2760 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2761 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2763 printf_filtered (_(") length %d\n"),
2764 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2765 for (overload_idx = 0;
2766 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2769 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2771 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2772 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2774 printf_filtered (")\n");
2775 printfi_filtered (spaces + 8, "type ");
2776 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
2778 printf_filtered ("\n");
2780 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2783 printfi_filtered (spaces + 8, "args ");
2784 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
2786 printf_filtered ("\n");
2788 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2789 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f,
2792 printfi_filtered (spaces + 8, "fcontext ");
2793 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2795 printf_filtered ("\n");
2797 printfi_filtered (spaces + 8, "is_const %d\n",
2798 TYPE_FN_FIELD_CONST (f, overload_idx));
2799 printfi_filtered (spaces + 8, "is_volatile %d\n",
2800 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2801 printfi_filtered (spaces + 8, "is_private %d\n",
2802 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2803 printfi_filtered (spaces + 8, "is_protected %d\n",
2804 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2805 printfi_filtered (spaces + 8, "is_stub %d\n",
2806 TYPE_FN_FIELD_STUB (f, overload_idx));
2807 printfi_filtered (spaces + 8, "voffset %u\n",
2808 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2814 print_cplus_stuff (struct type *type, int spaces)
2816 printfi_filtered (spaces, "n_baseclasses %d\n",
2817 TYPE_N_BASECLASSES (type));
2818 printfi_filtered (spaces, "nfn_fields %d\n",
2819 TYPE_NFN_FIELDS (type));
2820 printfi_filtered (spaces, "nfn_fields_total %d\n",
2821 TYPE_NFN_FIELDS_TOTAL (type));
2822 if (TYPE_N_BASECLASSES (type) > 0)
2824 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2825 TYPE_N_BASECLASSES (type));
2826 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
2828 printf_filtered (")");
2830 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2831 TYPE_N_BASECLASSES (type));
2832 puts_filtered ("\n");
2834 if (TYPE_NFIELDS (type) > 0)
2836 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2838 printfi_filtered (spaces,
2839 "private_field_bits (%d bits at *",
2840 TYPE_NFIELDS (type));
2841 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
2843 printf_filtered (")");
2844 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2845 TYPE_NFIELDS (type));
2846 puts_filtered ("\n");
2848 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2850 printfi_filtered (spaces,
2851 "protected_field_bits (%d bits at *",
2852 TYPE_NFIELDS (type));
2853 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
2855 printf_filtered (")");
2856 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2857 TYPE_NFIELDS (type));
2858 puts_filtered ("\n");
2861 if (TYPE_NFN_FIELDS (type) > 0)
2863 dump_fn_fieldlists (type, spaces);
2868 print_bound_type (int bt)
2872 case BOUND_CANNOT_BE_DETERMINED:
2873 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2875 case BOUND_BY_REF_ON_STACK:
2876 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2878 case BOUND_BY_VALUE_ON_STACK:
2879 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2881 case BOUND_BY_REF_IN_REG:
2882 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2884 case BOUND_BY_VALUE_IN_REG:
2885 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2888 printf_filtered ("(BOUND_SIMPLE)");
2891 printf_filtered (_("(unknown bound type)"));
2896 static struct obstack dont_print_type_obstack;
2899 recursive_dump_type (struct type *type, int spaces)
2904 obstack_begin (&dont_print_type_obstack, 0);
2906 if (TYPE_NFIELDS (type) > 0
2907 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2909 struct type **first_dont_print
2910 = (struct type **) obstack_base (&dont_print_type_obstack);
2912 int i = (struct type **)
2913 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
2917 if (type == first_dont_print[i])
2919 printfi_filtered (spaces, "type node ");
2920 gdb_print_host_address (type, gdb_stdout);
2921 printf_filtered (_(" <same as already seen type>\n"));
2926 obstack_ptr_grow (&dont_print_type_obstack, type);
2929 printfi_filtered (spaces, "type node ");
2930 gdb_print_host_address (type, gdb_stdout);
2931 printf_filtered ("\n");
2932 printfi_filtered (spaces, "name '%s' (",
2933 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2934 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2935 printf_filtered (")\n");
2936 printfi_filtered (spaces, "tagname '%s' (",
2937 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2938 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2939 printf_filtered (")\n");
2940 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2941 switch (TYPE_CODE (type))
2943 case TYPE_CODE_UNDEF:
2944 printf_filtered ("(TYPE_CODE_UNDEF)");
2947 printf_filtered ("(TYPE_CODE_PTR)");
2949 case TYPE_CODE_ARRAY:
2950 printf_filtered ("(TYPE_CODE_ARRAY)");
2952 case TYPE_CODE_STRUCT:
2953 printf_filtered ("(TYPE_CODE_STRUCT)");
2955 case TYPE_CODE_UNION:
2956 printf_filtered ("(TYPE_CODE_UNION)");
2958 case TYPE_CODE_ENUM:
2959 printf_filtered ("(TYPE_CODE_ENUM)");
2961 case TYPE_CODE_FLAGS:
2962 printf_filtered ("(TYPE_CODE_FLAGS)");
2964 case TYPE_CODE_FUNC:
2965 printf_filtered ("(TYPE_CODE_FUNC)");
2968 printf_filtered ("(TYPE_CODE_INT)");
2971 printf_filtered ("(TYPE_CODE_FLT)");
2973 case TYPE_CODE_VOID:
2974 printf_filtered ("(TYPE_CODE_VOID)");
2977 printf_filtered ("(TYPE_CODE_SET)");
2979 case TYPE_CODE_RANGE:
2980 printf_filtered ("(TYPE_CODE_RANGE)");
2982 case TYPE_CODE_STRING:
2983 printf_filtered ("(TYPE_CODE_STRING)");
2985 case TYPE_CODE_BITSTRING:
2986 printf_filtered ("(TYPE_CODE_BITSTRING)");
2988 case TYPE_CODE_ERROR:
2989 printf_filtered ("(TYPE_CODE_ERROR)");
2991 case TYPE_CODE_MEMBERPTR:
2992 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2994 case TYPE_CODE_METHODPTR:
2995 printf_filtered ("(TYPE_CODE_METHODPTR)");
2997 case TYPE_CODE_METHOD:
2998 printf_filtered ("(TYPE_CODE_METHOD)");
3001 printf_filtered ("(TYPE_CODE_REF)");
3003 case TYPE_CODE_CHAR:
3004 printf_filtered ("(TYPE_CODE_CHAR)");
3006 case TYPE_CODE_BOOL:
3007 printf_filtered ("(TYPE_CODE_BOOL)");
3009 case TYPE_CODE_COMPLEX:
3010 printf_filtered ("(TYPE_CODE_COMPLEX)");
3012 case TYPE_CODE_TYPEDEF:
3013 printf_filtered ("(TYPE_CODE_TYPEDEF)");
3015 case TYPE_CODE_TEMPLATE:
3016 printf_filtered ("(TYPE_CODE_TEMPLATE)");
3018 case TYPE_CODE_TEMPLATE_ARG:
3019 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
3021 case TYPE_CODE_NAMESPACE:
3022 printf_filtered ("(TYPE_CODE_NAMESPACE)");
3025 printf_filtered ("(UNKNOWN TYPE CODE)");
3028 puts_filtered ("\n");
3029 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
3030 printfi_filtered (spaces, "upper_bound_type 0x%x ",
3031 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
3032 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
3033 puts_filtered ("\n");
3034 printfi_filtered (spaces, "lower_bound_type 0x%x ",
3035 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
3036 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
3037 puts_filtered ("\n");
3038 printfi_filtered (spaces, "objfile ");
3039 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
3040 printf_filtered ("\n");
3041 printfi_filtered (spaces, "target_type ");
3042 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
3043 printf_filtered ("\n");
3044 if (TYPE_TARGET_TYPE (type) != NULL)
3046 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
3048 printfi_filtered (spaces, "pointer_type ");
3049 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
3050 printf_filtered ("\n");
3051 printfi_filtered (spaces, "reference_type ");
3052 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
3053 printf_filtered ("\n");
3054 printfi_filtered (spaces, "type_chain ");
3055 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
3056 printf_filtered ("\n");
3057 printfi_filtered (spaces, "instance_flags 0x%x",
3058 TYPE_INSTANCE_FLAGS (type));
3059 if (TYPE_CONST (type))
3061 puts_filtered (" TYPE_FLAG_CONST");
3063 if (TYPE_VOLATILE (type))
3065 puts_filtered (" TYPE_FLAG_VOLATILE");
3067 if (TYPE_CODE_SPACE (type))
3069 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3071 if (TYPE_DATA_SPACE (type))
3073 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3075 if (TYPE_ADDRESS_CLASS_1 (type))
3077 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3079 if (TYPE_ADDRESS_CLASS_2 (type))
3081 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3083 puts_filtered ("\n");
3084 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
3085 if (TYPE_UNSIGNED (type))
3087 puts_filtered (" TYPE_FLAG_UNSIGNED");
3089 if (TYPE_NOSIGN (type))
3091 puts_filtered (" TYPE_FLAG_NOSIGN");
3093 if (TYPE_STUB (type))
3095 puts_filtered (" TYPE_FLAG_STUB");
3097 if (TYPE_TARGET_STUB (type))
3099 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3101 if (TYPE_STATIC (type))
3103 puts_filtered (" TYPE_FLAG_STATIC");
3105 if (TYPE_PROTOTYPED (type))
3107 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3109 if (TYPE_INCOMPLETE (type))
3111 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3113 if (TYPE_VARARGS (type))
3115 puts_filtered (" TYPE_FLAG_VARARGS");
3117 /* This is used for things like AltiVec registers on ppc. Gcc emits
3118 an attribute for the array type, which tells whether or not we
3119 have a vector, instead of a regular array. */
3120 if (TYPE_VECTOR (type))
3122 puts_filtered (" TYPE_FLAG_VECTOR");
3124 puts_filtered ("\n");
3125 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3126 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3127 puts_filtered ("\n");
3128 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3130 printfi_filtered (spaces + 2,
3131 "[%d] bitpos %d bitsize %d type ",
3132 idx, TYPE_FIELD_BITPOS (type, idx),
3133 TYPE_FIELD_BITSIZE (type, idx));
3134 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3135 printf_filtered (" name '%s' (",
3136 TYPE_FIELD_NAME (type, idx) != NULL
3137 ? TYPE_FIELD_NAME (type, idx)
3139 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3140 printf_filtered (")\n");
3141 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3143 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3146 printfi_filtered (spaces, "vptr_basetype ");
3147 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3148 puts_filtered ("\n");
3149 if (TYPE_VPTR_BASETYPE (type) != NULL)
3151 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3153 printfi_filtered (spaces, "vptr_fieldno %d\n",
3154 TYPE_VPTR_FIELDNO (type));
3155 switch (TYPE_CODE (type))
3157 case TYPE_CODE_STRUCT:
3158 printfi_filtered (spaces, "cplus_stuff ");
3159 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
3161 puts_filtered ("\n");
3162 print_cplus_stuff (type, spaces);
3166 printfi_filtered (spaces, "floatformat ");
3167 if (TYPE_FLOATFORMAT (type) == NULL)
3168 puts_filtered ("(null)");
3171 puts_filtered ("{ ");
3172 if (TYPE_FLOATFORMAT (type)[0] == NULL
3173 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
3174 puts_filtered ("(null)");
3176 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
3178 puts_filtered (", ");
3179 if (TYPE_FLOATFORMAT (type)[1] == NULL
3180 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
3181 puts_filtered ("(null)");
3183 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
3185 puts_filtered (" }");
3187 puts_filtered ("\n");
3191 /* We have to pick one of the union types to be able print and
3192 test the value. Pick cplus_struct_type, even though we know
3193 it isn't any particular one. */
3194 printfi_filtered (spaces, "type_specific ");
3195 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3196 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3198 printf_filtered (_(" (unknown data form)"));
3200 printf_filtered ("\n");
3205 obstack_free (&dont_print_type_obstack, NULL);
3208 /* Trivial helpers for the libiberty hash table, for mapping one
3213 struct type *old, *new;
3217 type_pair_hash (const void *item)
3219 const struct type_pair *pair = item;
3220 return htab_hash_pointer (pair->old);
3224 type_pair_eq (const void *item_lhs, const void *item_rhs)
3226 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
3227 return lhs->old == rhs->old;
3230 /* Allocate the hash table used by copy_type_recursive to walk
3231 types without duplicates. We use OBJFILE's obstack, because
3232 OBJFILE is about to be deleted. */
3235 create_copied_types_hash (struct objfile *objfile)
3237 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
3238 NULL, &objfile->objfile_obstack,
3239 hashtab_obstack_allocate,
3240 dummy_obstack_deallocate);
3243 /* Recursively copy (deep copy) TYPE, if it is associated with
3244 OBJFILE. Return a new type allocated using malloc, a saved type if
3245 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
3246 not associated with OBJFILE. */
3249 copy_type_recursive (struct objfile *objfile,
3251 htab_t copied_types)
3253 struct type_pair *stored, pair;
3255 struct type *new_type;
3257 if (TYPE_OBJFILE (type) == NULL)
3260 /* This type shouldn't be pointing to any types in other objfiles;
3261 if it did, the type might disappear unexpectedly. */
3262 gdb_assert (TYPE_OBJFILE (type) == objfile);
3265 slot = htab_find_slot (copied_types, &pair, INSERT);
3267 return ((struct type_pair *) *slot)->new;
3269 new_type = alloc_type (NULL);
3271 /* We must add the new type to the hash table immediately, in case
3272 we encounter this type again during a recursive call below. */
3273 stored = xmalloc (sizeof (struct type_pair));
3275 stored->new = new_type;
3278 /* Copy the common fields of types. */
3279 TYPE_CODE (new_type) = TYPE_CODE (type);
3280 TYPE_ARRAY_UPPER_BOUND_TYPE (new_type) =
3281 TYPE_ARRAY_UPPER_BOUND_TYPE (type);
3282 TYPE_ARRAY_LOWER_BOUND_TYPE (new_type) =
3283 TYPE_ARRAY_LOWER_BOUND_TYPE (type);
3284 if (TYPE_NAME (type))
3285 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
3286 if (TYPE_TAG_NAME (type))
3287 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
3288 TYPE_FLAGS (new_type) = TYPE_FLAGS (type);
3289 TYPE_VPTR_FIELDNO (new_type) = TYPE_VPTR_FIELDNO (type);
3291 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
3292 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
3294 /* Copy the fields. */
3295 TYPE_NFIELDS (new_type) = TYPE_NFIELDS (type);
3296 if (TYPE_NFIELDS (type))
3300 nfields = TYPE_NFIELDS (type);
3301 TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
3302 for (i = 0; i < nfields; i++)
3304 TYPE_FIELD_ARTIFICIAL (new_type, i) =
3305 TYPE_FIELD_ARTIFICIAL (type, i);
3306 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
3307 if (TYPE_FIELD_TYPE (type, i))
3308 TYPE_FIELD_TYPE (new_type, i)
3309 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
3311 if (TYPE_FIELD_NAME (type, i))
3312 TYPE_FIELD_NAME (new_type, i) =
3313 xstrdup (TYPE_FIELD_NAME (type, i));
3314 if (TYPE_FIELD_STATIC_HAS_ADDR (type, i))
3315 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
3316 TYPE_FIELD_STATIC_PHYSADDR (type, i));
3317 else if (TYPE_FIELD_STATIC (type, i))
3318 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
3319 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
3323 TYPE_FIELD_BITPOS (new_type, i) =
3324 TYPE_FIELD_BITPOS (type, i);
3325 TYPE_FIELD_STATIC_KIND (new_type, i) = 0;
3330 /* Copy pointers to other types. */
3331 if (TYPE_TARGET_TYPE (type))
3332 TYPE_TARGET_TYPE (new_type) =
3333 copy_type_recursive (objfile,
3334 TYPE_TARGET_TYPE (type),
3336 if (TYPE_VPTR_BASETYPE (type))
3337 TYPE_VPTR_BASETYPE (new_type) =
3338 copy_type_recursive (objfile,
3339 TYPE_VPTR_BASETYPE (type),
3341 /* Maybe copy the type_specific bits.
3343 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3344 base classes and methods. There's no fundamental reason why we
3345 can't, but at the moment it is not needed. */
3347 if (TYPE_CODE (type) == TYPE_CODE_FLT)
3348 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
3349 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3350 || TYPE_CODE (type) == TYPE_CODE_UNION
3351 || TYPE_CODE (type) == TYPE_CODE_TEMPLATE
3352 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
3353 INIT_CPLUS_SPECIFIC (new_type);
3358 static struct type *
3359 build_flt (int bit, char *name, const struct floatformat **floatformats)
3365 gdb_assert (floatformats != NULL);
3366 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
3367 bit = floatformats[0]->totalsize;
3369 gdb_assert (bit >= 0);
3371 t = init_type (TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, 0, name, NULL);
3372 TYPE_FLOATFORMAT (t) = floatformats;
3376 static struct gdbarch_data *gdbtypes_data;
3378 const struct builtin_type *
3379 builtin_type (struct gdbarch *gdbarch)
3381 return gdbarch_data (gdbarch, gdbtypes_data);
3385 static struct type *
3386 build_complex (int bit, char *name, struct type *target_type)
3389 if (bit <= 0 || target_type == builtin_type_error)
3391 gdb_assert (builtin_type_error != NULL);
3392 return builtin_type_error;
3394 t = init_type (TYPE_CODE_COMPLEX, 2 * bit / TARGET_CHAR_BIT,
3395 0, name, (struct objfile *) NULL);
3396 TYPE_TARGET_TYPE (t) = target_type;
3401 gdbtypes_post_init (struct gdbarch *gdbarch)
3403 struct builtin_type *builtin_type
3404 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
3406 builtin_type->builtin_void =
3407 init_type (TYPE_CODE_VOID, 1,
3409 "void", (struct objfile *) NULL);
3410 builtin_type->builtin_char =
3411 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3413 | (gdbarch_char_signed (current_gdbarch) ?
3414 0 : TYPE_FLAG_UNSIGNED)),
3415 "char", (struct objfile *) NULL);
3416 builtin_type->builtin_true_char =
3417 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3419 "true character", (struct objfile *) NULL);
3420 builtin_type->builtin_signed_char =
3421 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3423 "signed char", (struct objfile *) NULL);
3424 builtin_type->builtin_unsigned_char =
3425 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3427 "unsigned char", (struct objfile *) NULL);
3428 builtin_type->builtin_short =
3429 init_type (TYPE_CODE_INT,
3430 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
3431 0, "short", (struct objfile *) NULL);
3432 builtin_type->builtin_unsigned_short =
3433 init_type (TYPE_CODE_INT,
3434 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
3435 TYPE_FLAG_UNSIGNED, "unsigned short",
3436 (struct objfile *) NULL);
3437 builtin_type->builtin_int =
3438 init_type (TYPE_CODE_INT,
3439 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
3440 0, "int", (struct objfile *) NULL);
3441 builtin_type->builtin_unsigned_int =
3442 init_type (TYPE_CODE_INT,
3443 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
3444 TYPE_FLAG_UNSIGNED, "unsigned int",
3445 (struct objfile *) NULL);
3446 builtin_type->builtin_long =
3447 init_type (TYPE_CODE_INT,
3448 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3449 0, "long", (struct objfile *) NULL);
3450 builtin_type->builtin_unsigned_long =
3451 init_type (TYPE_CODE_INT,
3452 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3453 TYPE_FLAG_UNSIGNED, "unsigned long",
3454 (struct objfile *) NULL);
3455 builtin_type->builtin_long_long =
3456 init_type (TYPE_CODE_INT,
3457 gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3458 0, "long long", (struct objfile *) NULL);
3459 builtin_type->builtin_unsigned_long_long =
3460 init_type (TYPE_CODE_INT,
3461 gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
3462 TYPE_FLAG_UNSIGNED, "unsigned long long",
3463 (struct objfile *) NULL);
3464 builtin_type->builtin_float
3465 = build_flt (gdbarch_float_bit (gdbarch), "float",
3466 gdbarch_float_format (gdbarch));
3467 builtin_type->builtin_double
3468 = build_flt (gdbarch_double_bit (gdbarch), "double",
3469 gdbarch_double_format (gdbarch));
3470 builtin_type->builtin_long_double
3471 = build_flt (gdbarch_long_double_bit (gdbarch), "long double",
3472 gdbarch_long_double_format (gdbarch));
3473 builtin_type->builtin_complex
3474 = build_complex (gdbarch_float_bit (gdbarch), "complex",
3475 builtin_type->builtin_float);
3476 builtin_type->builtin_double_complex
3477 = build_complex (gdbarch_double_bit (gdbarch), "double complex",
3478 builtin_type->builtin_double);
3479 builtin_type->builtin_string =
3480 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3482 "string", (struct objfile *) NULL);
3483 builtin_type->builtin_bool =
3484 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3486 "bool", (struct objfile *) NULL);
3488 /* Pointer/Address types. */
3490 /* NOTE: on some targets, addresses and pointers are not necessarily
3491 the same --- for example, on the D10V, pointers are 16 bits long,
3492 but addresses are 32 bits long. See doc/gdbint.texinfo,
3493 ``Pointers Are Not Always Addresses''.
3496 - gdb's `struct type' always describes the target's
3498 - gdb's `struct value' objects should always hold values in
3500 - gdb's CORE_ADDR values are addresses in the unified virtual
3501 address space that the assembler and linker work with. Thus,
3502 since target_read_memory takes a CORE_ADDR as an argument, it
3503 can access any memory on the target, even if the processor has
3504 separate code and data address spaces.
3507 - If v is a value holding a D10V code pointer, its contents are
3508 in target form: a big-endian address left-shifted two bits.
3509 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3510 sizeof (void *) == 2 on the target.
3512 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3513 target type for a value the target will never see. It's only
3514 used to hold the values of (typeless) linker symbols, which are
3515 indeed in the unified virtual address space. */
3517 builtin_type->builtin_data_ptr =
3518 make_pointer_type (builtin_type->builtin_void, NULL);
3519 builtin_type->builtin_func_ptr =
3520 lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
3521 builtin_type->builtin_core_addr =
3522 init_type (TYPE_CODE_INT,
3523 gdbarch_addr_bit (current_gdbarch) / 8,
3525 "__CORE_ADDR", (struct objfile *) NULL);
3528 /* The following set of types is used for symbols with no
3529 debug information. */
3530 builtin_type->nodebug_text_symbol =
3531 init_type (TYPE_CODE_FUNC, 1, 0,
3532 "<text variable, no debug info>", NULL);
3533 TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol) =
3534 builtin_type->builtin_int;
3535 builtin_type->nodebug_data_symbol =
3536 init_type (TYPE_CODE_INT,
3537 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
3538 "<data variable, no debug info>", NULL);
3539 builtin_type->nodebug_unknown_symbol =
3540 init_type (TYPE_CODE_INT, 1, 0,
3541 "<variable (not text or data), no debug info>", NULL);
3542 builtin_type->nodebug_tls_symbol =
3543 init_type (TYPE_CODE_INT,
3544 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
3545 "<thread local variable, no debug info>", NULL);
3547 return builtin_type;
3550 extern void _initialize_gdbtypes (void);
3552 _initialize_gdbtypes (void)
3554 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
3556 /* FIXME: The following types are architecture-neutral. However,
3557 they contain pointer_type and reference_type fields potentially
3558 caching pointer or reference types that *are* architecture
3562 init_type (TYPE_CODE_INT, 0 / 8,
3564 "int0_t", (struct objfile *) NULL);
3566 init_type (TYPE_CODE_INT, 8 / 8,
3568 "int8_t", (struct objfile *) NULL);
3569 builtin_type_uint8 =
3570 init_type (TYPE_CODE_INT, 8 / 8,
3572 "uint8_t", (struct objfile *) NULL);
3573 builtin_type_int16 =
3574 init_type (TYPE_CODE_INT, 16 / 8,
3576 "int16_t", (struct objfile *) NULL);
3577 builtin_type_uint16 =
3578 init_type (TYPE_CODE_INT, 16 / 8,
3580 "uint16_t", (struct objfile *) NULL);
3581 builtin_type_int32 =
3582 init_type (TYPE_CODE_INT, 32 / 8,
3584 "int32_t", (struct objfile *) NULL);
3585 builtin_type_uint32 =
3586 init_type (TYPE_CODE_INT, 32 / 8,
3588 "uint32_t", (struct objfile *) NULL);
3589 builtin_type_int64 =
3590 init_type (TYPE_CODE_INT, 64 / 8,
3592 "int64_t", (struct objfile *) NULL);
3593 builtin_type_uint64 =
3594 init_type (TYPE_CODE_INT, 64 / 8,
3596 "uint64_t", (struct objfile *) NULL);
3597 builtin_type_int128 =
3598 init_type (TYPE_CODE_INT, 128 / 8,
3600 "int128_t", (struct objfile *) NULL);
3601 builtin_type_uint128 =
3602 init_type (TYPE_CODE_INT, 128 / 8,
3604 "uint128_t", (struct objfile *) NULL);
3606 builtin_type_ieee_single =
3607 build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single);
3608 builtin_type_ieee_double =
3609 build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double);
3610 builtin_type_i387_ext =
3611 build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext);
3612 builtin_type_m68881_ext =
3613 build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext);
3614 builtin_type_arm_ext =
3615 build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext);
3616 builtin_type_ia64_spill =
3617 build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill);
3618 builtin_type_ia64_quad =
3619 build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad);
3621 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
3622 Set debugging of C++ overloading."), _("\
3623 Show debugging of C++ overloading."), _("\
3624 When enabled, ranking of the functions is displayed."),
3626 show_overload_debug,
3627 &setdebuglist, &showdebuglist);
3629 /* Add user knob for controlling resolution of opaque types. */
3630 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
3631 &opaque_type_resolution, _("\
3632 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3633 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL,
3635 show_opaque_type_resolution,
3636 &setlist, &showlist);