1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 Contributed by Cygnus Support, using pieces from other GDB modules.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
30 #include "expression.h"
35 #include "complaints.h"
39 #include "gdb_assert.h"
43 /* Floatformat pairs. */
44 const struct floatformat
*floatformats_ieee_single
[BFD_ENDIAN_UNKNOWN
] = {
45 &floatformat_ieee_single_big
,
46 &floatformat_ieee_single_little
48 const struct floatformat
*floatformats_ieee_double
[BFD_ENDIAN_UNKNOWN
] = {
49 &floatformat_ieee_double_big
,
50 &floatformat_ieee_double_little
52 const struct floatformat
*floatformats_ieee_double_littlebyte_bigword
[BFD_ENDIAN_UNKNOWN
] = {
53 &floatformat_ieee_double_big
,
54 &floatformat_ieee_double_littlebyte_bigword
56 const struct floatformat
*floatformats_i387_ext
[BFD_ENDIAN_UNKNOWN
] = {
57 &floatformat_i387_ext
,
60 const struct floatformat
*floatformats_m68881_ext
[BFD_ENDIAN_UNKNOWN
] = {
61 &floatformat_m68881_ext
,
62 &floatformat_m68881_ext
64 const struct floatformat
*floatformats_arm_ext
[BFD_ENDIAN_UNKNOWN
] = {
65 &floatformat_arm_ext_big
,
66 &floatformat_arm_ext_littlebyte_bigword
68 const struct floatformat
*floatformats_ia64_spill
[BFD_ENDIAN_UNKNOWN
] = {
69 &floatformat_ia64_spill_big
,
70 &floatformat_ia64_spill_little
72 const struct floatformat
*floatformats_ia64_quad
[BFD_ENDIAN_UNKNOWN
] = {
73 &floatformat_ia64_quad_big
,
74 &floatformat_ia64_quad_little
76 const struct floatformat
*floatformats_vax_f
[BFD_ENDIAN_UNKNOWN
] = {
80 const struct floatformat
*floatformats_vax_d
[BFD_ENDIAN_UNKNOWN
] = {
84 const struct floatformat
*floatformats_ibm_long_double
[BFD_ENDIAN_UNKNOWN
] = {
85 &floatformat_ibm_long_double
,
86 &floatformat_ibm_long_double
90 int opaque_type_resolution
= 1;
92 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
93 struct cmd_list_element
*c
,
96 fprintf_filtered (file
, _("\
97 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
101 int overload_debug
= 0;
103 show_overload_debug (struct ui_file
*file
, int from_tty
,
104 struct cmd_list_element
*c
, const char *value
)
106 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"),
114 }; /* Maximum extension is 128! FIXME */
116 static void print_bit_vector (B_TYPE
*, int);
117 static void print_arg_types (struct field
*, int, int);
118 static void dump_fn_fieldlists (struct type
*, int);
119 static void print_cplus_stuff (struct type
*, int);
122 /* Alloc a new type structure and fill it with some defaults. If
123 OBJFILE is non-NULL, then allocate the space for the type structure
124 in that objfile's objfile_obstack. Otherwise allocate the new type
125 structure by xmalloc () (for permanent types). */
128 alloc_type (struct objfile
*objfile
)
132 /* Alloc the structure and start off with all fields zeroed. */
136 type
= XZALLOC (struct type
);
137 TYPE_MAIN_TYPE (type
) = XZALLOC (struct main_type
);
141 type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct type
);
142 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
144 OBJSTAT (objfile
, n_types
++);
147 /* Initialize the fields that might not be zero. */
149 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
150 TYPE_OBJFILE (type
) = objfile
;
151 TYPE_VPTR_FIELDNO (type
) = -1;
152 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
157 /* Alloc a new type instance structure, fill it with some defaults,
158 and point it at OLDTYPE. Allocate the new type instance from the
159 same place as OLDTYPE. */
162 alloc_type_instance (struct type
*oldtype
)
166 /* Allocate the structure. */
168 if (TYPE_OBJFILE (oldtype
) == NULL
)
169 type
= XZALLOC (struct type
);
171 type
= OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
174 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
176 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
181 /* Clear all remnants of the previous type at TYPE, in preparation for
182 replacing it with something else. */
184 smash_type (struct type
*type
)
186 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
188 /* For now, delete the rings. */
189 TYPE_CHAIN (type
) = type
;
191 /* For now, leave the pointer/reference types alone. */
194 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
195 to a pointer to memory where the pointer type should be stored.
196 If *TYPEPTR is zero, update it to point to the pointer type we return.
197 We allocate new memory if needed. */
200 make_pointer_type (struct type
*type
, struct type
**typeptr
)
202 struct type
*ntype
; /* New type */
203 struct objfile
*objfile
;
206 ntype
= TYPE_POINTER_TYPE (type
);
211 return ntype
; /* Don't care about alloc,
212 and have new type. */
213 else if (*typeptr
== 0)
215 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
220 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
222 ntype
= alloc_type (TYPE_OBJFILE (type
));
226 else /* We have storage, but need to reset it. */
229 objfile
= TYPE_OBJFILE (ntype
);
230 chain
= TYPE_CHAIN (ntype
);
232 TYPE_CHAIN (ntype
) = chain
;
233 TYPE_OBJFILE (ntype
) = objfile
;
236 TYPE_TARGET_TYPE (ntype
) = type
;
237 TYPE_POINTER_TYPE (type
) = ntype
;
239 /* FIXME! Assume the machine has only one representation for
242 TYPE_LENGTH (ntype
) =
243 gdbarch_ptr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
244 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
246 /* Mark pointers as unsigned. The target converts between pointers
247 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
248 gdbarch_address_to_pointer. */
249 TYPE_UNSIGNED (ntype
) = 1;
251 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
252 TYPE_POINTER_TYPE (type
) = ntype
;
254 /* Update the length of all the other variants of this type. */
255 chain
= TYPE_CHAIN (ntype
);
256 while (chain
!= ntype
)
258 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
259 chain
= TYPE_CHAIN (chain
);
265 /* Given a type TYPE, return a type of pointers to that type.
266 May need to construct such a type if this is the first use. */
269 lookup_pointer_type (struct type
*type
)
271 return make_pointer_type (type
, (struct type
**) 0);
274 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
275 points to a pointer to memory where the reference type should be
276 stored. If *TYPEPTR is zero, update it to point to the reference
277 type we return. We allocate new memory if needed. */
280 make_reference_type (struct type
*type
, struct type
**typeptr
)
282 struct type
*ntype
; /* New type */
283 struct objfile
*objfile
;
286 ntype
= TYPE_REFERENCE_TYPE (type
);
291 return ntype
; /* Don't care about alloc,
292 and have new type. */
293 else if (*typeptr
== 0)
295 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
300 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
302 ntype
= alloc_type (TYPE_OBJFILE (type
));
306 else /* We have storage, but need to reset it. */
309 objfile
= TYPE_OBJFILE (ntype
);
310 chain
= TYPE_CHAIN (ntype
);
312 TYPE_CHAIN (ntype
) = chain
;
313 TYPE_OBJFILE (ntype
) = objfile
;
316 TYPE_TARGET_TYPE (ntype
) = type
;
317 TYPE_REFERENCE_TYPE (type
) = ntype
;
319 /* FIXME! Assume the machine has only one representation for
320 references, and that it matches the (only) representation for
323 TYPE_LENGTH (ntype
) = gdbarch_ptr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
324 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
326 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
327 TYPE_REFERENCE_TYPE (type
) = ntype
;
329 /* Update the length of all the other variants of this type. */
330 chain
= TYPE_CHAIN (ntype
);
331 while (chain
!= ntype
)
333 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
334 chain
= TYPE_CHAIN (chain
);
340 /* Same as above, but caller doesn't care about memory allocation
344 lookup_reference_type (struct type
*type
)
346 return make_reference_type (type
, (struct type
**) 0);
349 /* Lookup a function type that returns type TYPE. TYPEPTR, if
350 nonzero, points to a pointer to memory where the function type
351 should be stored. If *TYPEPTR is zero, update it to point to the
352 function type we return. We allocate new memory if needed. */
355 make_function_type (struct type
*type
, struct type
**typeptr
)
357 struct type
*ntype
; /* New type */
358 struct objfile
*objfile
;
360 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
362 ntype
= alloc_type (TYPE_OBJFILE (type
));
366 else /* We have storage, but need to reset it. */
369 objfile
= TYPE_OBJFILE (ntype
);
371 TYPE_OBJFILE (ntype
) = objfile
;
374 TYPE_TARGET_TYPE (ntype
) = type
;
376 TYPE_LENGTH (ntype
) = 1;
377 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
383 /* Given a type TYPE, return a type of functions that return that type.
384 May need to construct such a type if this is the first use. */
387 lookup_function_type (struct type
*type
)
389 return make_function_type (type
, (struct type
**) 0);
392 /* Identify address space identifier by name --
393 return the integer flag defined in gdbtypes.h. */
395 address_space_name_to_int (char *space_identifier
)
397 struct gdbarch
*gdbarch
= current_gdbarch
;
399 /* Check for known address space delimiters. */
400 if (!strcmp (space_identifier
, "code"))
401 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
402 else if (!strcmp (space_identifier
, "data"))
403 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
404 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
405 && gdbarch_address_class_name_to_type_flags (gdbarch
,
410 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
413 /* Identify address space identifier by integer flag as defined in
414 gdbtypes.h -- return the string version of the adress space name. */
417 address_space_int_to_name (int space_flag
)
419 struct gdbarch
*gdbarch
= current_gdbarch
;
420 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
422 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
424 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
425 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
426 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
431 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
433 If STORAGE is non-NULL, create the new type instance there.
434 STORAGE must be in the same obstack as TYPE. */
437 make_qualified_type (struct type
*type
, int new_flags
,
438 struct type
*storage
)
445 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
447 ntype
= TYPE_CHAIN (ntype
);
449 while (ntype
!= type
);
451 /* Create a new type instance. */
453 ntype
= alloc_type_instance (type
);
456 /* If STORAGE was provided, it had better be in the same objfile
457 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
458 if one objfile is freed and the other kept, we'd have
459 dangling pointers. */
460 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
463 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
464 TYPE_CHAIN (ntype
) = ntype
;
467 /* Pointers or references to the original type are not relevant to
469 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
470 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
472 /* Chain the new qualified type to the old type. */
473 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
474 TYPE_CHAIN (type
) = ntype
;
476 /* Now set the instance flags and return the new type. */
477 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
479 /* Set length of new type to that of the original type. */
480 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
485 /* Make an address-space-delimited variant of a type -- a type that
486 is identical to the one supplied except that it has an address
487 space attribute attached to it (such as "code" or "data").
489 The space attributes "code" and "data" are for Harvard
490 architectures. The address space attributes are for architectures
491 which have alternately sized pointers or pointers with alternate
495 make_type_with_address_space (struct type
*type
, int space_flag
)
498 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
499 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
500 | TYPE_INSTANCE_FLAG_DATA_SPACE
501 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
504 return make_qualified_type (type
, new_flags
, NULL
);
507 /* Make a "c-v" variant of a type -- a type that is identical to the
508 one supplied except that it may have const or volatile attributes
509 CNST is a flag for setting the const attribute
510 VOLTL is a flag for setting the volatile attribute
511 TYPE is the base type whose variant we are creating.
513 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
514 storage to hold the new qualified type; *TYPEPTR and TYPE must be
515 in the same objfile. Otherwise, allocate fresh memory for the new
516 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
517 new type we construct. */
519 make_cv_type (int cnst
, int voltl
,
521 struct type
**typeptr
)
523 struct type
*ntype
; /* New type */
524 struct type
*tmp_type
= type
; /* tmp type */
525 struct objfile
*objfile
;
527 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
528 & ~(TYPE_INSTANCE_FLAG_CONST
| TYPE_INSTANCE_FLAG_VOLATILE
));
531 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
534 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
536 if (typeptr
&& *typeptr
!= NULL
)
538 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
539 a C-V variant chain that threads across objfiles: if one
540 objfile gets freed, then the other has a broken C-V chain.
542 This code used to try to copy over the main type from TYPE to
543 *TYPEPTR if they were in different objfiles, but that's
544 wrong, too: TYPE may have a field list or member function
545 lists, which refer to types of their own, etc. etc. The
546 whole shebang would need to be copied over recursively; you
547 can't have inter-objfile pointers. The only thing to do is
548 to leave stub types as stub types, and look them up afresh by
549 name each time you encounter them. */
550 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
553 ntype
= make_qualified_type (type
, new_flags
,
554 typeptr
? *typeptr
: NULL
);
562 /* Replace the contents of ntype with the type *type. This changes the
563 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
564 the changes are propogated to all types in the TYPE_CHAIN.
566 In order to build recursive types, it's inevitable that we'll need
567 to update types in place --- but this sort of indiscriminate
568 smashing is ugly, and needs to be replaced with something more
569 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
570 clear if more steps are needed. */
572 replace_type (struct type
*ntype
, struct type
*type
)
576 /* These two types had better be in the same objfile. Otherwise,
577 the assignment of one type's main type structure to the other
578 will produce a type with references to objects (names; field
579 lists; etc.) allocated on an objfile other than its own. */
580 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
582 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
584 /* The type length is not a part of the main type. Update it for
585 each type on the variant chain. */
589 /* Assert that this element of the chain has no address-class bits
590 set in its flags. Such type variants might have type lengths
591 which are supposed to be different from the non-address-class
592 variants. This assertion shouldn't ever be triggered because
593 symbol readers which do construct address-class variants don't
594 call replace_type(). */
595 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
597 TYPE_LENGTH (chain
) = TYPE_LENGTH (type
);
598 chain
= TYPE_CHAIN (chain
);
600 while (ntype
!= chain
);
602 /* Assert that the two types have equivalent instance qualifiers.
603 This should be true for at least all of our debug readers. */
604 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
607 /* Implement direct support for MEMBER_TYPE in GNU C++.
608 May need to construct such a type if this is the first use.
609 The TYPE is the type of the member. The DOMAIN is the type
610 of the aggregate that the member belongs to. */
613 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
617 mtype
= alloc_type (TYPE_OBJFILE (type
));
618 smash_to_memberptr_type (mtype
, domain
, type
);
622 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
625 lookup_methodptr_type (struct type
*to_type
)
629 mtype
= alloc_type (TYPE_OBJFILE (to_type
));
630 TYPE_TARGET_TYPE (mtype
) = to_type
;
631 TYPE_DOMAIN_TYPE (mtype
) = TYPE_DOMAIN_TYPE (to_type
);
632 TYPE_LENGTH (mtype
) = cplus_method_ptr_size (to_type
);
633 TYPE_CODE (mtype
) = TYPE_CODE_METHODPTR
;
637 /* Allocate a stub method whose return type is TYPE. This apparently
638 happens for speed of symbol reading, since parsing out the
639 arguments to the method is cpu-intensive, the way we are doing it.
640 So, we will fill in arguments later. This always returns a fresh
644 allocate_stub_method (struct type
*type
)
648 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
649 TYPE_OBJFILE (type
));
650 TYPE_TARGET_TYPE (mtype
) = type
;
651 /* _DOMAIN_TYPE (mtype) = unknown yet */
655 /* Create a range type using either a blank type supplied in
656 RESULT_TYPE, or creating a new type, inheriting the objfile from
659 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
660 to HIGH_BOUND, inclusive.
662 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
663 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
666 create_range_type (struct type
*result_type
, struct type
*index_type
,
667 int low_bound
, int high_bound
)
669 if (result_type
== NULL
)
670 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
671 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
672 TYPE_TARGET_TYPE (result_type
) = index_type
;
673 if (TYPE_STUB (index_type
))
674 TYPE_TARGET_STUB (result_type
) = 1;
676 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
677 TYPE_NFIELDS (result_type
) = 2;
678 TYPE_FIELDS (result_type
) = TYPE_ZALLOC (result_type
,
679 TYPE_NFIELDS (result_type
)
680 * sizeof (struct field
));
681 TYPE_LOW_BOUND (result_type
) = low_bound
;
682 TYPE_HIGH_BOUND (result_type
) = high_bound
;
685 TYPE_UNSIGNED (result_type
) = 1;
690 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
691 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
692 bounds will fit in LONGEST), or -1 otherwise. */
695 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
697 CHECK_TYPEDEF (type
);
698 switch (TYPE_CODE (type
))
700 case TYPE_CODE_RANGE
:
701 *lowp
= TYPE_LOW_BOUND (type
);
702 *highp
= TYPE_HIGH_BOUND (type
);
705 if (TYPE_NFIELDS (type
) > 0)
707 /* The enums may not be sorted by value, so search all
711 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
712 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
714 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
715 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
716 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
717 *highp
= TYPE_FIELD_BITPOS (type
, i
);
720 /* Set unsigned indicator if warranted. */
723 TYPE_UNSIGNED (type
) = 1;
737 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
739 if (!TYPE_UNSIGNED (type
))
741 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
745 /* ... fall through for unsigned ints ... */
748 /* This round-about calculation is to avoid shifting by
749 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
750 if TYPE_LENGTH (type) == sizeof (LONGEST). */
751 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
752 *highp
= (*highp
- 1) | *highp
;
759 /* Create an array type using either a blank type supplied in
760 RESULT_TYPE, or creating a new type, inheriting the objfile from
763 Elements will be of type ELEMENT_TYPE, the indices will be of type
766 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
767 sure it is TYPE_CODE_UNDEF before we bash it into an array
771 create_array_type (struct type
*result_type
,
772 struct type
*element_type
,
773 struct type
*range_type
)
775 LONGEST low_bound
, high_bound
;
777 if (result_type
== NULL
)
779 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
781 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
782 TYPE_TARGET_TYPE (result_type
) = element_type
;
783 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
784 low_bound
= high_bound
= 0;
785 CHECK_TYPEDEF (element_type
);
786 /* Be careful when setting the array length. Ada arrays can be
787 empty arrays with the high_bound being smaller than the low_bound.
788 In such cases, the array length should be zero. */
789 if (high_bound
< low_bound
)
790 TYPE_LENGTH (result_type
) = 0;
792 TYPE_LENGTH (result_type
) =
793 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
794 TYPE_NFIELDS (result_type
) = 1;
795 TYPE_FIELDS (result_type
) =
796 (struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
));
797 TYPE_INDEX_TYPE (result_type
) = range_type
;
798 TYPE_VPTR_FIELDNO (result_type
) = -1;
800 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
801 if (TYPE_LENGTH (result_type
) == 0)
802 TYPE_TARGET_STUB (result_type
) = 1;
808 lookup_array_range_type (struct type
*element_type
,
809 int low_bound
, int high_bound
)
811 struct gdbarch
*gdbarch
= current_gdbarch
;
812 struct type
*index_type
= builtin_type (gdbarch
)->builtin_int
;
813 struct type
*range_type
814 = create_range_type (NULL
, index_type
, low_bound
, high_bound
);
815 return create_array_type (NULL
, element_type
, range_type
);
818 /* Create a string type using either a blank type supplied in
819 RESULT_TYPE, or creating a new type. String types are similar
820 enough to array of char types that we can use create_array_type to
821 build the basic type and then bash it into a string type.
823 For fixed length strings, the range type contains 0 as the lower
824 bound and the length of the string minus one as the upper bound.
826 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
827 sure it is TYPE_CODE_UNDEF before we bash it into a string
831 create_string_type (struct type
*result_type
,
832 struct type
*string_char_type
,
833 struct type
*range_type
)
835 result_type
= create_array_type (result_type
,
838 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
843 lookup_string_range_type (struct type
*string_char_type
,
844 int low_bound
, int high_bound
)
846 struct type
*result_type
;
847 result_type
= lookup_array_range_type (string_char_type
,
848 low_bound
, high_bound
);
849 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
854 create_set_type (struct type
*result_type
, struct type
*domain_type
)
856 if (result_type
== NULL
)
858 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
860 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
861 TYPE_NFIELDS (result_type
) = 1;
862 TYPE_FIELDS (result_type
) = TYPE_ZALLOC (result_type
, sizeof (struct field
));
864 if (!TYPE_STUB (domain_type
))
866 LONGEST low_bound
, high_bound
, bit_length
;
867 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
868 low_bound
= high_bound
= 0;
869 bit_length
= high_bound
- low_bound
+ 1;
870 TYPE_LENGTH (result_type
)
871 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
873 TYPE_UNSIGNED (result_type
) = 1;
875 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
881 append_flags_type_flag (struct type
*type
, int bitpos
, char *name
)
883 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
884 gdb_assert (bitpos
< TYPE_NFIELDS (type
));
885 gdb_assert (bitpos
>= 0);
889 TYPE_FIELD_NAME (type
, bitpos
) = xstrdup (name
);
890 TYPE_FIELD_BITPOS (type
, bitpos
) = bitpos
;
894 /* Don't show this field to the user. */
895 TYPE_FIELD_BITPOS (type
, bitpos
) = -1;
900 init_flags_type (char *name
, int length
)
902 int nfields
= length
* TARGET_CHAR_BIT
;
905 type
= init_type (TYPE_CODE_FLAGS
, length
,
906 TYPE_FLAG_UNSIGNED
, name
, NULL
);
907 TYPE_NFIELDS (type
) = nfields
;
908 TYPE_FIELDS (type
) = TYPE_ZALLOC (type
, nfields
* sizeof (struct field
));
913 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
914 and any array types nested inside it. */
917 make_vector_type (struct type
*array_type
)
919 struct type
*inner_array
, *elt_type
;
922 /* Find the innermost array type, in case the array is
923 multi-dimensional. */
924 inner_array
= array_type
;
925 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
926 inner_array
= TYPE_TARGET_TYPE (inner_array
);
928 elt_type
= TYPE_TARGET_TYPE (inner_array
);
929 if (TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
931 flags
= TYPE_INSTANCE_FLAGS (elt_type
) | TYPE_FLAG_NOTTEXT
;
932 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
933 TYPE_TARGET_TYPE (inner_array
) = elt_type
;
936 TYPE_VECTOR (array_type
) = 1;
940 init_vector_type (struct type
*elt_type
, int n
)
942 struct type
*array_type
;
943 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
944 make_vector_type (array_type
);
948 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
949 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
950 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
951 TYPE doesn't include the offset (that's the value of the MEMBER
952 itself), but does include the structure type into which it points
955 When "smashing" the type, we preserve the objfile that the old type
956 pointed to, since we aren't changing where the type is actually
960 smash_to_memberptr_type (struct type
*type
, struct type
*domain
,
961 struct type
*to_type
)
963 struct objfile
*objfile
;
965 objfile
= TYPE_OBJFILE (type
);
968 TYPE_OBJFILE (type
) = objfile
;
969 TYPE_TARGET_TYPE (type
) = to_type
;
970 TYPE_DOMAIN_TYPE (type
) = domain
;
971 /* Assume that a data member pointer is the same size as a normal
973 TYPE_LENGTH (type
) = gdbarch_ptr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
974 TYPE_CODE (type
) = TYPE_CODE_MEMBERPTR
;
977 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
978 METHOD just means `function that gets an extra "this" argument'.
980 When "smashing" the type, we preserve the objfile that the old type
981 pointed to, since we aren't changing where the type is actually
985 smash_to_method_type (struct type
*type
, struct type
*domain
,
986 struct type
*to_type
, struct field
*args
,
987 int nargs
, int varargs
)
989 struct objfile
*objfile
;
991 objfile
= TYPE_OBJFILE (type
);
994 TYPE_OBJFILE (type
) = objfile
;
995 TYPE_TARGET_TYPE (type
) = to_type
;
996 TYPE_DOMAIN_TYPE (type
) = domain
;
997 TYPE_FIELDS (type
) = args
;
998 TYPE_NFIELDS (type
) = nargs
;
1000 TYPE_VARARGS (type
) = 1;
1001 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1002 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1005 /* Return a typename for a struct/union/enum type without "struct ",
1006 "union ", or "enum ". If the type has a NULL name, return NULL. */
1009 type_name_no_tag (const struct type
*type
)
1011 if (TYPE_TAG_NAME (type
) != NULL
)
1012 return TYPE_TAG_NAME (type
);
1014 /* Is there code which expects this to return the name if there is
1015 no tag name? My guess is that this is mainly used for C++ in
1016 cases where the two will always be the same. */
1017 return TYPE_NAME (type
);
1020 /* Lookup a typedef or primitive type named NAME, visible in lexical
1021 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1022 suitably defined. */
1025 lookup_typename (const struct language_defn
*language
,
1026 struct gdbarch
*gdbarch
, char *name
,
1027 struct block
*block
, int noerr
)
1032 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0);
1033 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1035 tmp
= language_lookup_primitive_type_by_name (language
, gdbarch
, name
);
1040 else if (!tmp
&& noerr
)
1046 error (_("No type named %s."), name
);
1049 return (SYMBOL_TYPE (sym
));
1053 lookup_unsigned_typename (const struct language_defn
*language
,
1054 struct gdbarch
*gdbarch
, char *name
)
1056 char *uns
= alloca (strlen (name
) + 10);
1058 strcpy (uns
, "unsigned ");
1059 strcpy (uns
+ 9, name
);
1060 return lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 0);
1064 lookup_signed_typename (const struct language_defn
*language
,
1065 struct gdbarch
*gdbarch
, char *name
)
1068 char *uns
= alloca (strlen (name
) + 8);
1070 strcpy (uns
, "signed ");
1071 strcpy (uns
+ 7, name
);
1072 t
= lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 1);
1073 /* If we don't find "signed FOO" just try again with plain "FOO". */
1076 return lookup_typename (language
, gdbarch
, name
, (struct block
*) NULL
, 0);
1079 /* Lookup a structure type named "struct NAME",
1080 visible in lexical block BLOCK. */
1083 lookup_struct (char *name
, struct block
*block
)
1087 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1091 error (_("No struct type named %s."), name
);
1093 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1095 error (_("This context has class, union or enum %s, not a struct."),
1098 return (SYMBOL_TYPE (sym
));
1101 /* Lookup a union type named "union NAME",
1102 visible in lexical block BLOCK. */
1105 lookup_union (char *name
, struct block
*block
)
1110 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1113 error (_("No union type named %s."), name
);
1115 t
= SYMBOL_TYPE (sym
);
1117 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1120 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1121 * a further "declared_type" field to discover it is really a union.
1123 if (HAVE_CPLUS_STRUCT (t
))
1124 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1127 /* If we get here, it's not a union. */
1128 error (_("This context has class, struct or enum %s, not a union."),
1133 /* Lookup an enum type named "enum NAME",
1134 visible in lexical block BLOCK. */
1137 lookup_enum (char *name
, struct block
*block
)
1141 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1144 error (_("No enum type named %s."), name
);
1146 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1148 error (_("This context has class, struct or union %s, not an enum."),
1151 return (SYMBOL_TYPE (sym
));
1154 /* Lookup a template type named "template NAME<TYPE>",
1155 visible in lexical block BLOCK. */
1158 lookup_template_type (char *name
, struct type
*type
,
1159 struct block
*block
)
1162 char *nam
= (char *)
1163 alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1166 strcat (nam
, TYPE_NAME (type
));
1167 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1169 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0);
1173 error (_("No template type named %s."), name
);
1175 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1177 error (_("This context has class, union or enum %s, not a struct."),
1180 return (SYMBOL_TYPE (sym
));
1183 /* Given a type TYPE, lookup the type of the component of type named
1186 TYPE can be either a struct or union, or a pointer or reference to
1187 a struct or union. If it is a pointer or reference, its target
1188 type is automatically used. Thus '.' and '->' are interchangable,
1189 as specified for the definitions of the expression element types
1190 STRUCTOP_STRUCT and STRUCTOP_PTR.
1192 If NOERR is nonzero, return zero if NAME is not suitably defined.
1193 If NAME is the name of a baseclass type, return that type. */
1196 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1202 CHECK_TYPEDEF (type
);
1203 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1204 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1206 type
= TYPE_TARGET_TYPE (type
);
1209 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1210 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1212 target_terminal_ours ();
1213 gdb_flush (gdb_stdout
);
1214 fprintf_unfiltered (gdb_stderr
, "Type ");
1215 type_print (type
, "", gdb_stderr
, -1);
1216 error (_(" is not a structure or union type."));
1220 /* FIXME: This change put in by Michael seems incorrect for the case
1221 where the structure tag name is the same as the member name.
1222 I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
1223 foo; } bell;" Disabled by fnf. */
1227 typename
= type_name_no_tag (type
);
1228 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1233 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1235 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1237 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1239 return TYPE_FIELD_TYPE (type
, i
);
1243 /* OK, it's not in this class. Recursively check the baseclasses. */
1244 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1248 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1260 target_terminal_ours ();
1261 gdb_flush (gdb_stdout
);
1262 fprintf_unfiltered (gdb_stderr
, "Type ");
1263 type_print (type
, "", gdb_stderr
, -1);
1264 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1265 fputs_filtered (name
, gdb_stderr
);
1267 return (struct type
*) -1; /* For lint */
1270 /* Lookup the vptr basetype/fieldno values for TYPE.
1271 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1272 vptr_fieldno. Also, if found and basetype is from the same objfile,
1274 If not found, return -1 and ignore BASETYPEP.
1275 Callers should be aware that in some cases (for example,
1276 the type or one of its baseclasses is a stub type and we are
1277 debugging a .o file), this function will not be able to find the
1278 virtual function table pointer, and vptr_fieldno will remain -1 and
1279 vptr_basetype will remain NULL or incomplete. */
1282 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1284 CHECK_TYPEDEF (type
);
1286 if (TYPE_VPTR_FIELDNO (type
) < 0)
1290 /* We must start at zero in case the first (and only) baseclass
1291 is virtual (and hence we cannot share the table pointer). */
1292 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1294 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1296 struct type
*basetype
;
1298 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1301 /* If the type comes from a different objfile we can't cache
1302 it, it may have a different lifetime. PR 2384 */
1303 if (TYPE_OBJFILE (type
) == TYPE_OBJFILE (basetype
))
1305 TYPE_VPTR_FIELDNO (type
) = fieldno
;
1306 TYPE_VPTR_BASETYPE (type
) = basetype
;
1309 *basetypep
= basetype
;
1320 *basetypep
= TYPE_VPTR_BASETYPE (type
);
1321 return TYPE_VPTR_FIELDNO (type
);
1326 stub_noname_complaint (void)
1328 complaint (&symfile_complaints
, _("stub type has NULL name"));
1331 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1333 If this is a stubbed struct (i.e. declared as struct foo *), see if
1334 we can find a full definition in some other file. If so, copy this
1335 definition, so we can use it in future. There used to be a comment
1336 (but not any code) that if we don't find a full definition, we'd
1337 set a flag so we don't spend time in the future checking the same
1338 type. That would be a mistake, though--we might load in more
1339 symbols which contain a full definition for the type.
1341 This used to be coded as a macro, but I don't think it is called
1342 often enough to merit such treatment. */
1344 /* Find the real type of TYPE. This function returns the real type,
1345 after removing all layers of typedefs and completing opaque or stub
1346 types. Completion changes the TYPE argument, but stripping of
1347 typedefs does not. */
1350 check_typedef (struct type
*type
)
1352 struct type
*orig_type
= type
;
1353 int is_const
, is_volatile
;
1357 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1359 if (!TYPE_TARGET_TYPE (type
))
1364 /* It is dangerous to call lookup_symbol if we are currently
1365 reading a symtab. Infinite recursion is one danger. */
1366 if (currently_reading_symtab
)
1369 name
= type_name_no_tag (type
);
1370 /* FIXME: shouldn't we separately check the TYPE_NAME and
1371 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1372 VAR_DOMAIN as appropriate? (this code was written before
1373 TYPE_NAME and TYPE_TAG_NAME were separate). */
1376 stub_noname_complaint ();
1379 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1381 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1382 else /* TYPE_CODE_UNDEF */
1383 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
);
1385 type
= TYPE_TARGET_TYPE (type
);
1388 is_const
= TYPE_CONST (type
);
1389 is_volatile
= TYPE_VOLATILE (type
);
1391 /* If this is a struct/class/union with no fields, then check
1392 whether a full definition exists somewhere else. This is for
1393 systems where a type definition with no fields is issued for such
1394 types, instead of identifying them as stub types in the first
1397 if (TYPE_IS_OPAQUE (type
)
1398 && opaque_type_resolution
1399 && !currently_reading_symtab
)
1401 char *name
= type_name_no_tag (type
);
1402 struct type
*newtype
;
1405 stub_noname_complaint ();
1408 newtype
= lookup_transparent_type (name
);
1412 /* If the resolved type and the stub are in the same
1413 objfile, then replace the stub type with the real deal.
1414 But if they're in separate objfiles, leave the stub
1415 alone; we'll just look up the transparent type every time
1416 we call check_typedef. We can't create pointers between
1417 types allocated to different objfiles, since they may
1418 have different lifetimes. Trying to copy NEWTYPE over to
1419 TYPE's objfile is pointless, too, since you'll have to
1420 move over any other types NEWTYPE refers to, which could
1421 be an unbounded amount of stuff. */
1422 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1423 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1428 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1430 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1432 char *name
= type_name_no_tag (type
);
1433 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1434 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1435 as appropriate? (this code was written before TYPE_NAME and
1436 TYPE_TAG_NAME were separate). */
1440 stub_noname_complaint ();
1443 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1446 /* Same as above for opaque types, we can replace the stub
1447 with the complete type only if they are int the same
1449 if (TYPE_OBJFILE (SYMBOL_TYPE(sym
)) == TYPE_OBJFILE (type
))
1450 make_cv_type (is_const
, is_volatile
,
1451 SYMBOL_TYPE (sym
), &type
);
1453 type
= SYMBOL_TYPE (sym
);
1457 if (TYPE_TARGET_STUB (type
))
1459 struct type
*range_type
;
1460 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1462 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1466 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1467 && TYPE_NFIELDS (type
) == 1
1468 && (TYPE_CODE (range_type
= TYPE_INDEX_TYPE (type
))
1469 == TYPE_CODE_RANGE
))
1471 /* Now recompute the length of the array type, based on its
1472 number of elements and the target type's length.
1473 Watch out for Ada null Ada arrays where the high bound
1474 is smaller than the low bound. */
1475 const int low_bound
= TYPE_LOW_BOUND (range_type
);
1476 const int high_bound
= TYPE_HIGH_BOUND (range_type
);
1479 if (high_bound
< low_bound
)
1482 nb_elements
= high_bound
- low_bound
+ 1;
1484 TYPE_LENGTH (type
) = nb_elements
* TYPE_LENGTH (target_type
);
1485 TYPE_TARGET_STUB (type
) = 0;
1487 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1489 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1490 TYPE_TARGET_STUB (type
) = 0;
1493 /* Cache TYPE_LENGTH for future use. */
1494 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1498 /* Parse a type expression in the string [P..P+LENGTH). If an error
1499 occurs, silently return a void type. */
1501 static struct type
*
1502 safe_parse_type (struct gdbarch
*gdbarch
, char *p
, int length
)
1504 struct ui_file
*saved_gdb_stderr
;
1507 /* Suppress error messages. */
1508 saved_gdb_stderr
= gdb_stderr
;
1509 gdb_stderr
= ui_file_new ();
1511 /* Call parse_and_eval_type() without fear of longjmp()s. */
1512 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1513 type
= builtin_type (gdbarch
)->builtin_void
;
1515 /* Stop suppressing error messages. */
1516 ui_file_delete (gdb_stderr
);
1517 gdb_stderr
= saved_gdb_stderr
;
1522 /* Ugly hack to convert method stubs into method types.
1524 He ain't kiddin'. This demangles the name of the method into a
1525 string including argument types, parses out each argument type,
1526 generates a string casting a zero to that type, evaluates the
1527 string, and stuffs the resulting type into an argtype vector!!!
1528 Then it knows the type of the whole function (including argument
1529 types for overloading), which info used to be in the stab's but was
1530 removed to hack back the space required for them. */
1533 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1535 struct gdbarch
*gdbarch
= current_gdbarch
;
1537 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1538 char *demangled_name
= cplus_demangle (mangled_name
,
1539 DMGL_PARAMS
| DMGL_ANSI
);
1540 char *argtypetext
, *p
;
1541 int depth
= 0, argcount
= 1;
1542 struct field
*argtypes
;
1545 /* Make sure we got back a function string that we can use. */
1547 p
= strchr (demangled_name
, '(');
1551 if (demangled_name
== NULL
|| p
== NULL
)
1552 error (_("Internal: Cannot demangle mangled name `%s'."),
1555 /* Now, read in the parameters that define this type. */
1560 if (*p
== '(' || *p
== '<')
1564 else if (*p
== ')' || *p
== '>')
1568 else if (*p
== ',' && depth
== 0)
1576 /* If we read one argument and it was ``void'', don't count it. */
1577 if (strncmp (argtypetext
, "(void)", 6) == 0)
1580 /* We need one extra slot, for the THIS pointer. */
1582 argtypes
= (struct field
*)
1583 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1586 /* Add THIS pointer for non-static methods. */
1587 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1588 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1592 argtypes
[0].type
= lookup_pointer_type (type
);
1596 if (*p
!= ')') /* () means no args, skip while */
1601 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1603 /* Avoid parsing of ellipsis, they will be handled below.
1604 Also avoid ``void'' as above. */
1605 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1606 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1608 argtypes
[argcount
].type
=
1609 safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
);
1612 argtypetext
= p
+ 1;
1615 if (*p
== '(' || *p
== '<')
1619 else if (*p
== ')' || *p
== '>')
1628 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1630 /* Now update the old "stub" type into a real type. */
1631 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1632 TYPE_DOMAIN_TYPE (mtype
) = type
;
1633 TYPE_FIELDS (mtype
) = argtypes
;
1634 TYPE_NFIELDS (mtype
) = argcount
;
1635 TYPE_STUB (mtype
) = 0;
1636 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1638 TYPE_VARARGS (mtype
) = 1;
1640 xfree (demangled_name
);
1643 /* This is the external interface to check_stub_method, above. This
1644 function unstubs all of the signatures for TYPE's METHOD_ID method
1645 name. After calling this function TYPE_FN_FIELD_STUB will be
1646 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1649 This function unfortunately can not die until stabs do. */
1652 check_stub_method_group (struct type
*type
, int method_id
)
1654 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1655 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1656 int j
, found_stub
= 0;
1658 for (j
= 0; j
< len
; j
++)
1659 if (TYPE_FN_FIELD_STUB (f
, j
))
1662 check_stub_method (type
, method_id
, j
);
1665 /* GNU v3 methods with incorrect names were corrected when we read
1666 in type information, because it was cheaper to do it then. The
1667 only GNU v2 methods with incorrect method names are operators and
1668 destructors; destructors were also corrected when we read in type
1671 Therefore the only thing we need to handle here are v2 operator
1673 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1676 char dem_opname
[256];
1678 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1680 dem_opname
, DMGL_ANSI
);
1682 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1686 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1690 const struct cplus_struct_type cplus_struct_default
;
1693 allocate_cplus_struct_type (struct type
*type
)
1695 if (!HAVE_CPLUS_STRUCT (type
))
1697 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1698 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1699 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1703 /* Helper function to initialize the standard scalar types.
1705 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy of
1706 the string pointed to by name in the objfile_obstack for that
1707 objfile, and initialize the type name to that copy. There are
1708 places (mipsread.c in particular, where init_type is called with a
1709 NULL value for NAME). */
1712 init_type (enum type_code code
, int length
, int flags
,
1713 char *name
, struct objfile
*objfile
)
1717 type
= alloc_type (objfile
);
1718 TYPE_CODE (type
) = code
;
1719 TYPE_LENGTH (type
) = length
;
1721 gdb_assert (!(flags
& (TYPE_FLAG_MIN
- 1)));
1722 if (flags
& TYPE_FLAG_UNSIGNED
)
1723 TYPE_UNSIGNED (type
) = 1;
1724 if (flags
& TYPE_FLAG_NOSIGN
)
1725 TYPE_NOSIGN (type
) = 1;
1726 if (flags
& TYPE_FLAG_STUB
)
1727 TYPE_STUB (type
) = 1;
1728 if (flags
& TYPE_FLAG_TARGET_STUB
)
1729 TYPE_TARGET_STUB (type
) = 1;
1730 if (flags
& TYPE_FLAG_STATIC
)
1731 TYPE_STATIC (type
) = 1;
1732 if (flags
& TYPE_FLAG_PROTOTYPED
)
1733 TYPE_PROTOTYPED (type
) = 1;
1734 if (flags
& TYPE_FLAG_INCOMPLETE
)
1735 TYPE_INCOMPLETE (type
) = 1;
1736 if (flags
& TYPE_FLAG_VARARGS
)
1737 TYPE_VARARGS (type
) = 1;
1738 if (flags
& TYPE_FLAG_VECTOR
)
1739 TYPE_VECTOR (type
) = 1;
1740 if (flags
& TYPE_FLAG_STUB_SUPPORTED
)
1741 TYPE_STUB_SUPPORTED (type
) = 1;
1742 if (flags
& TYPE_FLAG_NOTTEXT
)
1743 TYPE_NOTTEXT (type
) = 1;
1744 if (flags
& TYPE_FLAG_FIXED_INSTANCE
)
1745 TYPE_FIXED_INSTANCE (type
) = 1;
1747 if ((name
!= NULL
) && (objfile
!= NULL
))
1749 TYPE_NAME (type
) = obsavestring (name
, strlen (name
),
1750 &objfile
->objfile_obstack
);
1754 TYPE_NAME (type
) = name
;
1759 if (name
&& strcmp (name
, "char") == 0)
1760 TYPE_NOSIGN (type
) = 1;
1762 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
1763 || code
== TYPE_CODE_NAMESPACE
)
1765 INIT_CPLUS_SPECIFIC (type
);
1770 /* Helper function. Create an empty composite type. */
1773 init_composite_type (char *name
, enum type_code code
)
1776 gdb_assert (code
== TYPE_CODE_STRUCT
1777 || code
== TYPE_CODE_UNION
);
1778 t
= init_type (code
, 0, 0, NULL
, NULL
);
1779 TYPE_TAG_NAME (t
) = name
;
1783 /* Helper function. Append a field to a composite type. */
1786 append_composite_type_field_aligned (struct type
*t
, char *name
,
1787 struct type
*field
, int alignment
)
1790 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
1791 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
1792 sizeof (struct field
) * TYPE_NFIELDS (t
));
1793 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
1794 memset (f
, 0, sizeof f
[0]);
1795 FIELD_TYPE (f
[0]) = field
;
1796 FIELD_NAME (f
[0]) = name
;
1797 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1799 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
1800 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
1802 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
1804 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
1805 if (TYPE_NFIELDS (t
) > 1)
1807 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
1808 + (TYPE_LENGTH (FIELD_TYPE (f
[-1]))
1809 * TARGET_CHAR_BIT
));
1813 int left
= FIELD_BITPOS (f
[0]) % (alignment
* TARGET_CHAR_BIT
);
1816 FIELD_BITPOS (f
[0]) += left
;
1817 TYPE_LENGTH (t
) += left
/ TARGET_CHAR_BIT
;
1825 append_composite_type_field (struct type
*t
, char *name
,
1828 append_composite_type_field_aligned (t
, name
, field
, 0);
1832 can_dereference (struct type
*t
)
1834 /* FIXME: Should we return true for references as well as
1839 && TYPE_CODE (t
) == TYPE_CODE_PTR
1840 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1844 is_integral_type (struct type
*t
)
1849 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1850 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1851 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
1852 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1853 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1854 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1857 /* Check whether BASE is an ancestor or base class or DCLASS
1858 Return 1 if so, and 0 if not.
1859 Note: callers may want to check for identity of the types before
1860 calling this function -- identical types are considered to satisfy
1861 the ancestor relationship even if they're identical. */
1864 is_ancestor (struct type
*base
, struct type
*dclass
)
1868 CHECK_TYPEDEF (base
);
1869 CHECK_TYPEDEF (dclass
);
1873 if (TYPE_NAME (base
) && TYPE_NAME (dclass
)
1874 && !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1877 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1878 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1886 /* Functions for overload resolution begin here */
1888 /* Compare two badness vectors A and B and return the result.
1889 0 => A and B are identical
1890 1 => A and B are incomparable
1891 2 => A is better than B
1892 3 => A is worse than B */
1895 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
1899 short found_pos
= 0; /* any positives in c? */
1900 short found_neg
= 0; /* any negatives in c? */
1902 /* differing lengths => incomparable */
1903 if (a
->length
!= b
->length
)
1906 /* Subtract b from a */
1907 for (i
= 0; i
< a
->length
; i
++)
1909 tmp
= a
->rank
[i
] - b
->rank
[i
];
1919 return 1; /* incomparable */
1921 return 3; /* A > B */
1927 return 2; /* A < B */
1929 return 0; /* A == B */
1933 /* Rank a function by comparing its parameter types (PARMS, length
1934 NPARMS), to the types of an argument list (ARGS, length NARGS).
1935 Return a pointer to a badness vector. This has NARGS + 1
1938 struct badness_vector
*
1939 rank_function (struct type
**parms
, int nparms
,
1940 struct type
**args
, int nargs
)
1943 struct badness_vector
*bv
;
1944 int min_len
= nparms
< nargs
? nparms
: nargs
;
1946 bv
= xmalloc (sizeof (struct badness_vector
));
1947 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
1948 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
1950 /* First compare the lengths of the supplied lists.
1951 If there is a mismatch, set it to a high value. */
1953 /* pai/1997-06-03 FIXME: when we have debug info about default
1954 arguments and ellipsis parameter lists, we should consider those
1955 and rank the length-match more finely. */
1957 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
1959 /* Now rank all the parameters of the candidate function */
1960 for (i
= 1; i
<= min_len
; i
++)
1961 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
1963 /* If more arguments than parameters, add dummy entries */
1964 for (i
= min_len
+ 1; i
<= nargs
; i
++)
1965 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
1970 /* Compare the names of two integer types, assuming that any sign
1971 qualifiers have been checked already. We do it this way because
1972 there may be an "int" in the name of one of the types. */
1975 integer_types_same_name_p (const char *first
, const char *second
)
1977 int first_p
, second_p
;
1979 /* If both are shorts, return 1; if neither is a short, keep
1981 first_p
= (strstr (first
, "short") != NULL
);
1982 second_p
= (strstr (second
, "short") != NULL
);
1983 if (first_p
&& second_p
)
1985 if (first_p
|| second_p
)
1988 /* Likewise for long. */
1989 first_p
= (strstr (first
, "long") != NULL
);
1990 second_p
= (strstr (second
, "long") != NULL
);
1991 if (first_p
&& second_p
)
1993 if (first_p
|| second_p
)
1996 /* Likewise for char. */
1997 first_p
= (strstr (first
, "char") != NULL
);
1998 second_p
= (strstr (second
, "char") != NULL
);
1999 if (first_p
&& second_p
)
2001 if (first_p
|| second_p
)
2004 /* They must both be ints. */
2008 /* Compare one type (PARM) for compatibility with another (ARG).
2009 * PARM is intended to be the parameter type of a function; and
2010 * ARG is the supplied argument's type. This function tests if
2011 * the latter can be converted to the former.
2013 * Return 0 if they are identical types;
2014 * Otherwise, return an integer which corresponds to how compatible
2015 * PARM is to ARG. The higher the return value, the worse the match.
2016 * Generally the "bad" conversions are all uniformly assigned a 100. */
2019 rank_one_type (struct type
*parm
, struct type
*arg
)
2021 /* Identical type pointers. */
2022 /* However, this still doesn't catch all cases of same type for arg
2023 and param. The reason is that builtin types are different from
2024 the same ones constructed from the object. */
2028 /* Resolve typedefs */
2029 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2030 parm
= check_typedef (parm
);
2031 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2032 arg
= check_typedef (arg
);
2035 Well, damnit, if the names are exactly the same, I'll say they
2036 are exactly the same. This happens when we generate method
2037 stubs. The types won't point to the same address, but they
2038 really are the same.
2041 if (TYPE_NAME (parm
) && TYPE_NAME (arg
)
2042 && !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2045 /* Check if identical after resolving typedefs. */
2049 /* See through references, since we can almost make non-references
2051 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2052 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2053 + REFERENCE_CONVERSION_BADNESS
);
2054 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2055 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2056 + REFERENCE_CONVERSION_BADNESS
);
2058 /* Debugging only. */
2059 fprintf_filtered (gdb_stderr
,
2060 "------ Arg is %s [%d], parm is %s [%d]\n",
2061 TYPE_NAME (arg
), TYPE_CODE (arg
),
2062 TYPE_NAME (parm
), TYPE_CODE (parm
));
2064 /* x -> y means arg of type x being supplied for parameter of type y */
2066 switch (TYPE_CODE (parm
))
2069 switch (TYPE_CODE (arg
))
2072 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2073 return VOID_PTR_CONVERSION_BADNESS
;
2075 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2076 TYPE_TARGET_TYPE (arg
));
2077 case TYPE_CODE_ARRAY
:
2078 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2079 TYPE_TARGET_TYPE (arg
));
2080 case TYPE_CODE_FUNC
:
2081 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2083 case TYPE_CODE_ENUM
:
2084 case TYPE_CODE_FLAGS
:
2085 case TYPE_CODE_CHAR
:
2086 case TYPE_CODE_RANGE
:
2087 case TYPE_CODE_BOOL
:
2088 return POINTER_CONVERSION_BADNESS
;
2090 return INCOMPATIBLE_TYPE_BADNESS
;
2092 case TYPE_CODE_ARRAY
:
2093 switch (TYPE_CODE (arg
))
2096 case TYPE_CODE_ARRAY
:
2097 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2098 TYPE_TARGET_TYPE (arg
));
2100 return INCOMPATIBLE_TYPE_BADNESS
;
2102 case TYPE_CODE_FUNC
:
2103 switch (TYPE_CODE (arg
))
2105 case TYPE_CODE_PTR
: /* funcptr -> func */
2106 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2108 return INCOMPATIBLE_TYPE_BADNESS
;
2111 switch (TYPE_CODE (arg
))
2114 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2116 /* Deal with signed, unsigned, and plain chars and
2117 signed and unsigned ints. */
2118 if (TYPE_NOSIGN (parm
))
2120 /* This case only for character types */
2121 if (TYPE_NOSIGN (arg
))
2122 return 0; /* plain char -> plain char */
2123 else /* signed/unsigned char -> plain char */
2124 return INTEGER_CONVERSION_BADNESS
;
2126 else if (TYPE_UNSIGNED (parm
))
2128 if (TYPE_UNSIGNED (arg
))
2130 /* unsigned int -> unsigned int, or
2131 unsigned long -> unsigned long */
2132 if (integer_types_same_name_p (TYPE_NAME (parm
),
2135 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2137 && integer_types_same_name_p (TYPE_NAME (parm
),
2139 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2141 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2145 if (integer_types_same_name_p (TYPE_NAME (arg
),
2147 && integer_types_same_name_p (TYPE_NAME (parm
),
2149 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2151 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2154 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2156 if (integer_types_same_name_p (TYPE_NAME (parm
),
2159 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2161 && integer_types_same_name_p (TYPE_NAME (parm
),
2163 return INTEGER_PROMOTION_BADNESS
;
2165 return INTEGER_CONVERSION_BADNESS
;
2168 return INTEGER_CONVERSION_BADNESS
;
2170 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2171 return INTEGER_PROMOTION_BADNESS
;
2173 return INTEGER_CONVERSION_BADNESS
;
2174 case TYPE_CODE_ENUM
:
2175 case TYPE_CODE_FLAGS
:
2176 case TYPE_CODE_CHAR
:
2177 case TYPE_CODE_RANGE
:
2178 case TYPE_CODE_BOOL
:
2179 return INTEGER_PROMOTION_BADNESS
;
2181 return INT_FLOAT_CONVERSION_BADNESS
;
2183 return NS_POINTER_CONVERSION_BADNESS
;
2185 return INCOMPATIBLE_TYPE_BADNESS
;
2188 case TYPE_CODE_ENUM
:
2189 switch (TYPE_CODE (arg
))
2192 case TYPE_CODE_CHAR
:
2193 case TYPE_CODE_RANGE
:
2194 case TYPE_CODE_BOOL
:
2195 case TYPE_CODE_ENUM
:
2196 return INTEGER_CONVERSION_BADNESS
;
2198 return INT_FLOAT_CONVERSION_BADNESS
;
2200 return INCOMPATIBLE_TYPE_BADNESS
;
2203 case TYPE_CODE_CHAR
:
2204 switch (TYPE_CODE (arg
))
2206 case TYPE_CODE_RANGE
:
2207 case TYPE_CODE_BOOL
:
2208 case TYPE_CODE_ENUM
:
2209 return INTEGER_CONVERSION_BADNESS
;
2211 return INT_FLOAT_CONVERSION_BADNESS
;
2213 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2214 return INTEGER_CONVERSION_BADNESS
;
2215 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2216 return INTEGER_PROMOTION_BADNESS
;
2217 /* >>> !! else fall through !! <<< */
2218 case TYPE_CODE_CHAR
:
2219 /* Deal with signed, unsigned, and plain chars for C++ and
2220 with int cases falling through from previous case. */
2221 if (TYPE_NOSIGN (parm
))
2223 if (TYPE_NOSIGN (arg
))
2226 return INTEGER_CONVERSION_BADNESS
;
2228 else if (TYPE_UNSIGNED (parm
))
2230 if (TYPE_UNSIGNED (arg
))
2233 return INTEGER_PROMOTION_BADNESS
;
2235 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2238 return INTEGER_CONVERSION_BADNESS
;
2240 return INCOMPATIBLE_TYPE_BADNESS
;
2243 case TYPE_CODE_RANGE
:
2244 switch (TYPE_CODE (arg
))
2247 case TYPE_CODE_CHAR
:
2248 case TYPE_CODE_RANGE
:
2249 case TYPE_CODE_BOOL
:
2250 case TYPE_CODE_ENUM
:
2251 return INTEGER_CONVERSION_BADNESS
;
2253 return INT_FLOAT_CONVERSION_BADNESS
;
2255 return INCOMPATIBLE_TYPE_BADNESS
;
2258 case TYPE_CODE_BOOL
:
2259 switch (TYPE_CODE (arg
))
2262 case TYPE_CODE_CHAR
:
2263 case TYPE_CODE_RANGE
:
2264 case TYPE_CODE_ENUM
:
2267 return BOOLEAN_CONVERSION_BADNESS
;
2268 case TYPE_CODE_BOOL
:
2271 return INCOMPATIBLE_TYPE_BADNESS
;
2275 switch (TYPE_CODE (arg
))
2278 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2279 return FLOAT_PROMOTION_BADNESS
;
2280 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2283 return FLOAT_CONVERSION_BADNESS
;
2285 case TYPE_CODE_BOOL
:
2286 case TYPE_CODE_ENUM
:
2287 case TYPE_CODE_RANGE
:
2288 case TYPE_CODE_CHAR
:
2289 return INT_FLOAT_CONVERSION_BADNESS
;
2291 return INCOMPATIBLE_TYPE_BADNESS
;
2294 case TYPE_CODE_COMPLEX
:
2295 switch (TYPE_CODE (arg
))
2296 { /* Strictly not needed for C++, but... */
2298 return FLOAT_PROMOTION_BADNESS
;
2299 case TYPE_CODE_COMPLEX
:
2302 return INCOMPATIBLE_TYPE_BADNESS
;
2305 case TYPE_CODE_STRUCT
:
2306 /* currently same as TYPE_CODE_CLASS */
2307 switch (TYPE_CODE (arg
))
2309 case TYPE_CODE_STRUCT
:
2310 /* Check for derivation */
2311 if (is_ancestor (parm
, arg
))
2312 return BASE_CONVERSION_BADNESS
;
2313 /* else fall through */
2315 return INCOMPATIBLE_TYPE_BADNESS
;
2318 case TYPE_CODE_UNION
:
2319 switch (TYPE_CODE (arg
))
2321 case TYPE_CODE_UNION
:
2323 return INCOMPATIBLE_TYPE_BADNESS
;
2326 case TYPE_CODE_MEMBERPTR
:
2327 switch (TYPE_CODE (arg
))
2330 return INCOMPATIBLE_TYPE_BADNESS
;
2333 case TYPE_CODE_METHOD
:
2334 switch (TYPE_CODE (arg
))
2338 return INCOMPATIBLE_TYPE_BADNESS
;
2342 switch (TYPE_CODE (arg
))
2346 return INCOMPATIBLE_TYPE_BADNESS
;
2351 switch (TYPE_CODE (arg
))
2355 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0),
2356 TYPE_FIELD_TYPE (arg
, 0));
2358 return INCOMPATIBLE_TYPE_BADNESS
;
2361 case TYPE_CODE_VOID
:
2363 return INCOMPATIBLE_TYPE_BADNESS
;
2364 } /* switch (TYPE_CODE (arg)) */
2368 /* End of functions for overload resolution */
2371 print_bit_vector (B_TYPE
*bits
, int nbits
)
2375 for (bitno
= 0; bitno
< nbits
; bitno
++)
2377 if ((bitno
% 8) == 0)
2379 puts_filtered (" ");
2381 if (B_TST (bits
, bitno
))
2382 printf_filtered (("1"));
2384 printf_filtered (("0"));
2388 /* Note the first arg should be the "this" pointer, we may not want to
2389 include it since we may get into a infinitely recursive
2393 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2399 for (i
= 0; i
< nargs
; i
++)
2400 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2405 field_is_static (struct field
*f
)
2407 /* "static" fields are the fields whose location is not relative
2408 to the address of the enclosing struct. It would be nice to
2409 have a dedicated flag that would be set for static fields when
2410 the type is being created. But in practice, checking the field
2411 loc_kind should give us an accurate answer (at least as long as
2412 we assume that DWARF block locations are not going to be used
2413 for static fields). FIXME? */
2414 return (FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSNAME
2415 || FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSADDR
);
2419 dump_fn_fieldlists (struct type
*type
, int spaces
)
2425 printfi_filtered (spaces
, "fn_fieldlists ");
2426 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2427 printf_filtered ("\n");
2428 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2430 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2431 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2433 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2434 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2436 printf_filtered (_(") length %d\n"),
2437 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2438 for (overload_idx
= 0;
2439 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2442 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2444 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2445 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2447 printf_filtered (")\n");
2448 printfi_filtered (spaces
+ 8, "type ");
2449 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2451 printf_filtered ("\n");
2453 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2456 printfi_filtered (spaces
+ 8, "args ");
2457 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2459 printf_filtered ("\n");
2461 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2462 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
,
2465 printfi_filtered (spaces
+ 8, "fcontext ");
2466 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2468 printf_filtered ("\n");
2470 printfi_filtered (spaces
+ 8, "is_const %d\n",
2471 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2472 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2473 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2474 printfi_filtered (spaces
+ 8, "is_private %d\n",
2475 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2476 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2477 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2478 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2479 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2480 printfi_filtered (spaces
+ 8, "voffset %u\n",
2481 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2487 print_cplus_stuff (struct type
*type
, int spaces
)
2489 printfi_filtered (spaces
, "n_baseclasses %d\n",
2490 TYPE_N_BASECLASSES (type
));
2491 printfi_filtered (spaces
, "nfn_fields %d\n",
2492 TYPE_NFN_FIELDS (type
));
2493 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2494 TYPE_NFN_FIELDS_TOTAL (type
));
2495 if (TYPE_N_BASECLASSES (type
) > 0)
2497 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2498 TYPE_N_BASECLASSES (type
));
2499 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
),
2501 printf_filtered (")");
2503 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2504 TYPE_N_BASECLASSES (type
));
2505 puts_filtered ("\n");
2507 if (TYPE_NFIELDS (type
) > 0)
2509 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2511 printfi_filtered (spaces
,
2512 "private_field_bits (%d bits at *",
2513 TYPE_NFIELDS (type
));
2514 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
),
2516 printf_filtered (")");
2517 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2518 TYPE_NFIELDS (type
));
2519 puts_filtered ("\n");
2521 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2523 printfi_filtered (spaces
,
2524 "protected_field_bits (%d bits at *",
2525 TYPE_NFIELDS (type
));
2526 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
),
2528 printf_filtered (")");
2529 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2530 TYPE_NFIELDS (type
));
2531 puts_filtered ("\n");
2534 if (TYPE_NFN_FIELDS (type
) > 0)
2536 dump_fn_fieldlists (type
, spaces
);
2540 static struct obstack dont_print_type_obstack
;
2543 recursive_dump_type (struct type
*type
, int spaces
)
2548 obstack_begin (&dont_print_type_obstack
, 0);
2550 if (TYPE_NFIELDS (type
) > 0
2551 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2553 struct type
**first_dont_print
2554 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2556 int i
= (struct type
**)
2557 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
2561 if (type
== first_dont_print
[i
])
2563 printfi_filtered (spaces
, "type node ");
2564 gdb_print_host_address (type
, gdb_stdout
);
2565 printf_filtered (_(" <same as already seen type>\n"));
2570 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2573 printfi_filtered (spaces
, "type node ");
2574 gdb_print_host_address (type
, gdb_stdout
);
2575 printf_filtered ("\n");
2576 printfi_filtered (spaces
, "name '%s' (",
2577 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2578 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2579 printf_filtered (")\n");
2580 printfi_filtered (spaces
, "tagname '%s' (",
2581 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2582 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2583 printf_filtered (")\n");
2584 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2585 switch (TYPE_CODE (type
))
2587 case TYPE_CODE_UNDEF
:
2588 printf_filtered ("(TYPE_CODE_UNDEF)");
2591 printf_filtered ("(TYPE_CODE_PTR)");
2593 case TYPE_CODE_ARRAY
:
2594 printf_filtered ("(TYPE_CODE_ARRAY)");
2596 case TYPE_CODE_STRUCT
:
2597 printf_filtered ("(TYPE_CODE_STRUCT)");
2599 case TYPE_CODE_UNION
:
2600 printf_filtered ("(TYPE_CODE_UNION)");
2602 case TYPE_CODE_ENUM
:
2603 printf_filtered ("(TYPE_CODE_ENUM)");
2605 case TYPE_CODE_FLAGS
:
2606 printf_filtered ("(TYPE_CODE_FLAGS)");
2608 case TYPE_CODE_FUNC
:
2609 printf_filtered ("(TYPE_CODE_FUNC)");
2612 printf_filtered ("(TYPE_CODE_INT)");
2615 printf_filtered ("(TYPE_CODE_FLT)");
2617 case TYPE_CODE_VOID
:
2618 printf_filtered ("(TYPE_CODE_VOID)");
2621 printf_filtered ("(TYPE_CODE_SET)");
2623 case TYPE_CODE_RANGE
:
2624 printf_filtered ("(TYPE_CODE_RANGE)");
2626 case TYPE_CODE_STRING
:
2627 printf_filtered ("(TYPE_CODE_STRING)");
2629 case TYPE_CODE_BITSTRING
:
2630 printf_filtered ("(TYPE_CODE_BITSTRING)");
2632 case TYPE_CODE_ERROR
:
2633 printf_filtered ("(TYPE_CODE_ERROR)");
2635 case TYPE_CODE_MEMBERPTR
:
2636 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2638 case TYPE_CODE_METHODPTR
:
2639 printf_filtered ("(TYPE_CODE_METHODPTR)");
2641 case TYPE_CODE_METHOD
:
2642 printf_filtered ("(TYPE_CODE_METHOD)");
2645 printf_filtered ("(TYPE_CODE_REF)");
2647 case TYPE_CODE_CHAR
:
2648 printf_filtered ("(TYPE_CODE_CHAR)");
2650 case TYPE_CODE_BOOL
:
2651 printf_filtered ("(TYPE_CODE_BOOL)");
2653 case TYPE_CODE_COMPLEX
:
2654 printf_filtered ("(TYPE_CODE_COMPLEX)");
2656 case TYPE_CODE_TYPEDEF
:
2657 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2659 case TYPE_CODE_TEMPLATE
:
2660 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2662 case TYPE_CODE_TEMPLATE_ARG
:
2663 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2665 case TYPE_CODE_NAMESPACE
:
2666 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2669 printf_filtered ("(UNKNOWN TYPE CODE)");
2672 puts_filtered ("\n");
2673 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2674 printfi_filtered (spaces
, "objfile ");
2675 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
2676 printf_filtered ("\n");
2677 printfi_filtered (spaces
, "target_type ");
2678 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2679 printf_filtered ("\n");
2680 if (TYPE_TARGET_TYPE (type
) != NULL
)
2682 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2684 printfi_filtered (spaces
, "pointer_type ");
2685 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2686 printf_filtered ("\n");
2687 printfi_filtered (spaces
, "reference_type ");
2688 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2689 printf_filtered ("\n");
2690 printfi_filtered (spaces
, "type_chain ");
2691 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
2692 printf_filtered ("\n");
2693 printfi_filtered (spaces
, "instance_flags 0x%x",
2694 TYPE_INSTANCE_FLAGS (type
));
2695 if (TYPE_CONST (type
))
2697 puts_filtered (" TYPE_FLAG_CONST");
2699 if (TYPE_VOLATILE (type
))
2701 puts_filtered (" TYPE_FLAG_VOLATILE");
2703 if (TYPE_CODE_SPACE (type
))
2705 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2707 if (TYPE_DATA_SPACE (type
))
2709 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2711 if (TYPE_ADDRESS_CLASS_1 (type
))
2713 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
2715 if (TYPE_ADDRESS_CLASS_2 (type
))
2717 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
2719 puts_filtered ("\n");
2721 printfi_filtered (spaces
, "flags");
2722 if (TYPE_UNSIGNED (type
))
2724 puts_filtered (" TYPE_FLAG_UNSIGNED");
2726 if (TYPE_NOSIGN (type
))
2728 puts_filtered (" TYPE_FLAG_NOSIGN");
2730 if (TYPE_STUB (type
))
2732 puts_filtered (" TYPE_FLAG_STUB");
2734 if (TYPE_TARGET_STUB (type
))
2736 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2738 if (TYPE_STATIC (type
))
2740 puts_filtered (" TYPE_FLAG_STATIC");
2742 if (TYPE_PROTOTYPED (type
))
2744 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2746 if (TYPE_INCOMPLETE (type
))
2748 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2750 if (TYPE_VARARGS (type
))
2752 puts_filtered (" TYPE_FLAG_VARARGS");
2754 /* This is used for things like AltiVec registers on ppc. Gcc emits
2755 an attribute for the array type, which tells whether or not we
2756 have a vector, instead of a regular array. */
2757 if (TYPE_VECTOR (type
))
2759 puts_filtered (" TYPE_FLAG_VECTOR");
2761 if (TYPE_FIXED_INSTANCE (type
))
2763 puts_filtered (" TYPE_FIXED_INSTANCE");
2765 if (TYPE_STUB_SUPPORTED (type
))
2767 puts_filtered (" TYPE_STUB_SUPPORTED");
2769 if (TYPE_NOTTEXT (type
))
2771 puts_filtered (" TYPE_NOTTEXT");
2773 puts_filtered ("\n");
2774 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2775 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
2776 puts_filtered ("\n");
2777 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2779 printfi_filtered (spaces
+ 2,
2780 "[%d] bitpos %d bitsize %d type ",
2781 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2782 TYPE_FIELD_BITSIZE (type
, idx
));
2783 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2784 printf_filtered (" name '%s' (",
2785 TYPE_FIELD_NAME (type
, idx
) != NULL
2786 ? TYPE_FIELD_NAME (type
, idx
)
2788 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2789 printf_filtered (")\n");
2790 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2792 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2795 printfi_filtered (spaces
, "vptr_basetype ");
2796 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2797 puts_filtered ("\n");
2798 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2800 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2802 printfi_filtered (spaces
, "vptr_fieldno %d\n",
2803 TYPE_VPTR_FIELDNO (type
));
2804 switch (TYPE_CODE (type
))
2806 case TYPE_CODE_STRUCT
:
2807 printfi_filtered (spaces
, "cplus_stuff ");
2808 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
),
2810 puts_filtered ("\n");
2811 print_cplus_stuff (type
, spaces
);
2815 printfi_filtered (spaces
, "floatformat ");
2816 if (TYPE_FLOATFORMAT (type
) == NULL
)
2817 puts_filtered ("(null)");
2820 puts_filtered ("{ ");
2821 if (TYPE_FLOATFORMAT (type
)[0] == NULL
2822 || TYPE_FLOATFORMAT (type
)[0]->name
== NULL
)
2823 puts_filtered ("(null)");
2825 puts_filtered (TYPE_FLOATFORMAT (type
)[0]->name
);
2827 puts_filtered (", ");
2828 if (TYPE_FLOATFORMAT (type
)[1] == NULL
2829 || TYPE_FLOATFORMAT (type
)[1]->name
== NULL
)
2830 puts_filtered ("(null)");
2832 puts_filtered (TYPE_FLOATFORMAT (type
)[1]->name
);
2834 puts_filtered (" }");
2836 puts_filtered ("\n");
2840 /* We have to pick one of the union types to be able print and
2841 test the value. Pick cplus_struct_type, even though we know
2842 it isn't any particular one. */
2843 printfi_filtered (spaces
, "type_specific ");
2844 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2845 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
2847 printf_filtered (_(" (unknown data form)"));
2849 printf_filtered ("\n");
2854 obstack_free (&dont_print_type_obstack
, NULL
);
2857 /* Trivial helpers for the libiberty hash table, for mapping one
2862 struct type
*old
, *new;
2866 type_pair_hash (const void *item
)
2868 const struct type_pair
*pair
= item
;
2869 return htab_hash_pointer (pair
->old
);
2873 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
2875 const struct type_pair
*lhs
= item_lhs
, *rhs
= item_rhs
;
2876 return lhs
->old
== rhs
->old
;
2879 /* Allocate the hash table used by copy_type_recursive to walk
2880 types without duplicates. We use OBJFILE's obstack, because
2881 OBJFILE is about to be deleted. */
2884 create_copied_types_hash (struct objfile
*objfile
)
2886 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
2887 NULL
, &objfile
->objfile_obstack
,
2888 hashtab_obstack_allocate
,
2889 dummy_obstack_deallocate
);
2892 /* Recursively copy (deep copy) TYPE, if it is associated with
2893 OBJFILE. Return a new type allocated using malloc, a saved type if
2894 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
2895 not associated with OBJFILE. */
2898 copy_type_recursive (struct objfile
*objfile
,
2900 htab_t copied_types
)
2902 struct type_pair
*stored
, pair
;
2904 struct type
*new_type
;
2906 if (TYPE_OBJFILE (type
) == NULL
)
2909 /* This type shouldn't be pointing to any types in other objfiles;
2910 if it did, the type might disappear unexpectedly. */
2911 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
2914 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
2916 return ((struct type_pair
*) *slot
)->new;
2918 new_type
= alloc_type (NULL
);
2920 /* We must add the new type to the hash table immediately, in case
2921 we encounter this type again during a recursive call below. */
2922 stored
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct type_pair
));
2924 stored
->new = new_type
;
2927 /* Copy the common fields of types. For the main type, we simply
2928 copy the entire thing and then update specific fields as needed. */
2929 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
2930 TYPE_OBJFILE (new_type
) = NULL
;
2932 if (TYPE_NAME (type
))
2933 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
2934 if (TYPE_TAG_NAME (type
))
2935 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
2937 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
2938 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
2940 /* Copy the fields. */
2941 if (TYPE_NFIELDS (type
))
2945 nfields
= TYPE_NFIELDS (type
);
2946 TYPE_FIELDS (new_type
) = XCALLOC (nfields
, struct field
);
2947 for (i
= 0; i
< nfields
; i
++)
2949 TYPE_FIELD_ARTIFICIAL (new_type
, i
) =
2950 TYPE_FIELD_ARTIFICIAL (type
, i
);
2951 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
2952 if (TYPE_FIELD_TYPE (type
, i
))
2953 TYPE_FIELD_TYPE (new_type
, i
)
2954 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
2956 if (TYPE_FIELD_NAME (type
, i
))
2957 TYPE_FIELD_NAME (new_type
, i
) =
2958 xstrdup (TYPE_FIELD_NAME (type
, i
));
2959 switch (TYPE_FIELD_LOC_KIND (type
, i
))
2961 case FIELD_LOC_KIND_BITPOS
:
2962 SET_FIELD_BITPOS (TYPE_FIELD (new_type
, i
),
2963 TYPE_FIELD_BITPOS (type
, i
));
2965 case FIELD_LOC_KIND_PHYSADDR
:
2966 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
2967 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
2969 case FIELD_LOC_KIND_PHYSNAME
:
2970 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
2971 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
,
2975 internal_error (__FILE__
, __LINE__
,
2976 _("Unexpected type field location kind: %d"),
2977 TYPE_FIELD_LOC_KIND (type
, i
));
2982 /* Copy pointers to other types. */
2983 if (TYPE_TARGET_TYPE (type
))
2984 TYPE_TARGET_TYPE (new_type
) =
2985 copy_type_recursive (objfile
,
2986 TYPE_TARGET_TYPE (type
),
2988 if (TYPE_VPTR_BASETYPE (type
))
2989 TYPE_VPTR_BASETYPE (new_type
) =
2990 copy_type_recursive (objfile
,
2991 TYPE_VPTR_BASETYPE (type
),
2993 /* Maybe copy the type_specific bits.
2995 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
2996 base classes and methods. There's no fundamental reason why we
2997 can't, but at the moment it is not needed. */
2999 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
3000 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
3001 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3002 || TYPE_CODE (type
) == TYPE_CODE_UNION
3003 || TYPE_CODE (type
) == TYPE_CODE_TEMPLATE
3004 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
3005 INIT_CPLUS_SPECIFIC (new_type
);
3010 /* Make a copy of the given TYPE, except that the pointer & reference
3011 types are not preserved.
3013 This function assumes that the given type has an associated objfile.
3014 This objfile is used to allocate the new type. */
3017 copy_type (const struct type
*type
)
3019 struct type
*new_type
;
3021 gdb_assert (TYPE_OBJFILE (type
) != NULL
);
3023 new_type
= alloc_type (TYPE_OBJFILE (type
));
3024 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
3025 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
3026 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
3027 sizeof (struct main_type
));
3033 init_float_type (int bit
, char *name
, const struct floatformat
**floatformats
)
3039 gdb_assert (floatformats
!= NULL
);
3040 gdb_assert (floatformats
[0] != NULL
&& floatformats
[1] != NULL
);
3041 bit
= floatformats
[0]->totalsize
;
3043 gdb_assert (bit
>= 0);
3045 t
= init_type (TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
, 0, name
, NULL
);
3046 TYPE_FLOATFORMAT (t
) = floatformats
;
3051 init_complex_type (char *name
, struct type
*target_type
)
3054 t
= init_type (TYPE_CODE_COMPLEX
, 2 * TYPE_LENGTH (target_type
),
3055 0, name
, (struct objfile
*) NULL
);
3056 TYPE_TARGET_TYPE (t
) = target_type
;
3060 static struct gdbarch_data
*gdbtypes_data
;
3062 const struct builtin_type
*
3063 builtin_type (struct gdbarch
*gdbarch
)
3065 return gdbarch_data (gdbarch
, gdbtypes_data
);
3069 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3071 struct builtin_type
*builtin_type
3072 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3075 builtin_type
->builtin_void
=
3076 init_type (TYPE_CODE_VOID
, 1,
3078 "void", (struct objfile
*) NULL
);
3079 builtin_type
->builtin_char
=
3080 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3082 | (gdbarch_char_signed (gdbarch
) ? 0 : TYPE_FLAG_UNSIGNED
)),
3083 "char", (struct objfile
*) NULL
);
3084 builtin_type
->builtin_signed_char
=
3085 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3087 "signed char", (struct objfile
*) NULL
);
3088 builtin_type
->builtin_unsigned_char
=
3089 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3091 "unsigned char", (struct objfile
*) NULL
);
3092 builtin_type
->builtin_short
=
3093 init_type (TYPE_CODE_INT
,
3094 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3095 0, "short", (struct objfile
*) NULL
);
3096 builtin_type
->builtin_unsigned_short
=
3097 init_type (TYPE_CODE_INT
,
3098 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3099 TYPE_FLAG_UNSIGNED
, "unsigned short",
3100 (struct objfile
*) NULL
);
3101 builtin_type
->builtin_int
=
3102 init_type (TYPE_CODE_INT
,
3103 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3104 0, "int", (struct objfile
*) NULL
);
3105 builtin_type
->builtin_unsigned_int
=
3106 init_type (TYPE_CODE_INT
,
3107 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3108 TYPE_FLAG_UNSIGNED
, "unsigned int",
3109 (struct objfile
*) NULL
);
3110 builtin_type
->builtin_long
=
3111 init_type (TYPE_CODE_INT
,
3112 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3113 0, "long", (struct objfile
*) NULL
);
3114 builtin_type
->builtin_unsigned_long
=
3115 init_type (TYPE_CODE_INT
,
3116 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3117 TYPE_FLAG_UNSIGNED
, "unsigned long",
3118 (struct objfile
*) NULL
);
3119 builtin_type
->builtin_long_long
=
3120 init_type (TYPE_CODE_INT
,
3121 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3122 0, "long long", (struct objfile
*) NULL
);
3123 builtin_type
->builtin_unsigned_long_long
=
3124 init_type (TYPE_CODE_INT
,
3125 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3126 TYPE_FLAG_UNSIGNED
, "unsigned long long",
3127 (struct objfile
*) NULL
);
3128 builtin_type
->builtin_float
3129 = init_float_type (gdbarch_float_bit (gdbarch
),
3130 "float", gdbarch_float_format (gdbarch
));
3131 builtin_type
->builtin_double
3132 = init_float_type (gdbarch_double_bit (gdbarch
),
3133 "double", gdbarch_double_format (gdbarch
));
3134 builtin_type
->builtin_long_double
3135 = init_float_type (gdbarch_long_double_bit (gdbarch
),
3136 "long double", gdbarch_long_double_format (gdbarch
));
3137 builtin_type
->builtin_complex
3138 = init_complex_type ("complex", builtin_type
->builtin_float
);
3139 builtin_type
->builtin_double_complex
3140 = init_complex_type ("double complex", builtin_type
->builtin_double
);
3141 builtin_type
->builtin_string
=
3142 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3144 "string", (struct objfile
*) NULL
);
3145 builtin_type
->builtin_bool
=
3146 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3148 "bool", (struct objfile
*) NULL
);
3150 /* The following three are about decimal floating point types, which
3151 are 32-bits, 64-bits and 128-bits respectively. */
3152 builtin_type
->builtin_decfloat
3153 = init_type (TYPE_CODE_DECFLOAT
, 32 / 8,
3155 "_Decimal32", (struct objfile
*) NULL
);
3156 builtin_type
->builtin_decdouble
3157 = init_type (TYPE_CODE_DECFLOAT
, 64 / 8,
3159 "_Decimal64", (struct objfile
*) NULL
);
3160 builtin_type
->builtin_declong
3161 = init_type (TYPE_CODE_DECFLOAT
, 128 / 8,
3163 "_Decimal128", (struct objfile
*) NULL
);
3165 /* "True" character types. */
3166 builtin_type
->builtin_true_char
=
3167 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3169 "true character", (struct objfile
*) NULL
);
3170 builtin_type
->builtin_true_unsigned_char
=
3171 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3173 "true character", (struct objfile
*) NULL
);
3175 /* Fixed-size integer types. */
3176 builtin_type
->builtin_int0
=
3177 init_type (TYPE_CODE_INT
, 0 / 8,
3179 "int0_t", (struct objfile
*) NULL
);
3180 builtin_type
->builtin_int8
=
3181 init_type (TYPE_CODE_INT
, 8 / 8,
3183 "int8_t", (struct objfile
*) NULL
);
3184 builtin_type
->builtin_uint8
=
3185 init_type (TYPE_CODE_INT
, 8 / 8,
3186 TYPE_FLAG_UNSIGNED
| TYPE_FLAG_NOTTEXT
,
3187 "uint8_t", (struct objfile
*) NULL
);
3188 builtin_type
->builtin_int16
=
3189 init_type (TYPE_CODE_INT
, 16 / 8,
3191 "int16_t", (struct objfile
*) NULL
);
3192 builtin_type
->builtin_uint16
=
3193 init_type (TYPE_CODE_INT
, 16 / 8,
3195 "uint16_t", (struct objfile
*) NULL
);
3196 builtin_type
->builtin_int32
=
3197 init_type (TYPE_CODE_INT
, 32 / 8,
3199 "int32_t", (struct objfile
*) NULL
);
3200 builtin_type
->builtin_uint32
=
3201 init_type (TYPE_CODE_INT
, 32 / 8,
3203 "uint32_t", (struct objfile
*) NULL
);
3204 builtin_type
->builtin_int64
=
3205 init_type (TYPE_CODE_INT
, 64 / 8,
3207 "int64_t", (struct objfile
*) NULL
);
3208 builtin_type
->builtin_uint64
=
3209 init_type (TYPE_CODE_INT
, 64 / 8,
3211 "uint64_t", (struct objfile
*) NULL
);
3212 builtin_type
->builtin_int128
=
3213 init_type (TYPE_CODE_INT
, 128 / 8,
3215 "int128_t", (struct objfile
*) NULL
);
3216 builtin_type
->builtin_uint128
=
3217 init_type (TYPE_CODE_INT
, 128 / 8,
3219 "uint128_t", (struct objfile
*) NULL
);
3221 /* Default data/code pointer types. */
3222 builtin_type
->builtin_data_ptr
=
3223 make_pointer_type (builtin_type
->builtin_void
, NULL
);
3224 builtin_type
->builtin_func_ptr
=
3225 lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3227 /* This type represents a GDB internal function. */
3228 builtin_type
->internal_fn
=
3229 init_type (TYPE_CODE_INTERNAL_FUNCTION
, 0, 0,
3230 "<internal function>", NULL
);
3232 return builtin_type
;
3236 /* This set of objfile-based types is intended to be used by symbol
3237 readers as basic types. */
3239 static const struct objfile_data
*objfile_type_data
;
3241 const struct objfile_type
*
3242 objfile_type (struct objfile
*objfile
)
3244 struct gdbarch
*gdbarch
;
3245 struct objfile_type
*objfile_type
3246 = objfile_data (objfile
, objfile_type_data
);
3249 return objfile_type
;
3251 objfile_type
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3252 1, struct objfile_type
);
3254 /* Use the objfile architecture to determine basic type properties. */
3255 gdbarch
= get_objfile_arch (objfile
);
3258 objfile_type
->builtin_void
3259 = init_type (TYPE_CODE_VOID
, 1,
3263 objfile_type
->builtin_char
3264 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3266 | (gdbarch_char_signed (gdbarch
) ? 0 : TYPE_FLAG_UNSIGNED
)),
3268 objfile_type
->builtin_signed_char
3269 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3271 "signed char", objfile
);
3272 objfile_type
->builtin_unsigned_char
3273 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3275 "unsigned char", objfile
);
3276 objfile_type
->builtin_short
3277 = init_type (TYPE_CODE_INT
,
3278 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3279 0, "short", objfile
);
3280 objfile_type
->builtin_unsigned_short
3281 = init_type (TYPE_CODE_INT
,
3282 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3283 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
3284 objfile_type
->builtin_int
3285 = init_type (TYPE_CODE_INT
,
3286 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3288 objfile_type
->builtin_unsigned_int
3289 = init_type (TYPE_CODE_INT
,
3290 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3291 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
3292 objfile_type
->builtin_long
3293 = init_type (TYPE_CODE_INT
,
3294 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3295 0, "long", objfile
);
3296 objfile_type
->builtin_unsigned_long
3297 = init_type (TYPE_CODE_INT
,
3298 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3299 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
3300 objfile_type
->builtin_long_long
3301 = init_type (TYPE_CODE_INT
,
3302 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3303 0, "long long", objfile
);
3304 objfile_type
->builtin_unsigned_long_long
3305 = init_type (TYPE_CODE_INT
,
3306 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3307 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
3309 objfile_type
->builtin_float
3310 = init_type (TYPE_CODE_FLT
,
3311 gdbarch_float_bit (gdbarch
) / TARGET_CHAR_BIT
,
3312 0, "float", objfile
);
3313 TYPE_FLOATFORMAT (objfile_type
->builtin_float
)
3314 = gdbarch_float_format (gdbarch
);
3315 objfile_type
->builtin_double
3316 = init_type (TYPE_CODE_FLT
,
3317 gdbarch_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
3318 0, "double", objfile
);
3319 TYPE_FLOATFORMAT (objfile_type
->builtin_double
)
3320 = gdbarch_double_format (gdbarch
);
3321 objfile_type
->builtin_long_double
3322 = init_type (TYPE_CODE_FLT
,
3323 gdbarch_long_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
3324 0, "long double", objfile
);
3325 TYPE_FLOATFORMAT (objfile_type
->builtin_long_double
)
3326 = gdbarch_long_double_format (gdbarch
);
3328 /* This type represents a type that was unrecognized in symbol read-in. */
3329 objfile_type
->builtin_error
3330 = init_type (TYPE_CODE_ERROR
, 0, 0, "<unknown type>", objfile
);
3332 /* The following set of types is used for symbols with no
3333 debug information. */
3334 objfile_type
->nodebug_text_symbol
3335 = init_type (TYPE_CODE_FUNC
, 1, 0,
3336 "<text variable, no debug info>", objfile
);
3337 TYPE_TARGET_TYPE (objfile_type
->nodebug_text_symbol
)
3338 = objfile_type
->builtin_int
;
3339 objfile_type
->nodebug_data_symbol
3340 = init_type (TYPE_CODE_INT
,
3341 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3342 "<data variable, no debug info>", objfile
);
3343 objfile_type
->nodebug_unknown_symbol
3344 = init_type (TYPE_CODE_INT
, 1, 0,
3345 "<variable (not text or data), no debug info>", objfile
);
3346 objfile_type
->nodebug_tls_symbol
3347 = init_type (TYPE_CODE_INT
,
3348 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3349 "<thread local variable, no debug info>", objfile
);
3351 /* NOTE: on some targets, addresses and pointers are not necessarily
3352 the same --- for example, on the D10V, pointers are 16 bits long,
3353 but addresses are 32 bits long. See doc/gdbint.texinfo,
3354 ``Pointers Are Not Always Addresses''.
3357 - gdb's `struct type' always describes the target's
3359 - gdb's `struct value' objects should always hold values in
3361 - gdb's CORE_ADDR values are addresses in the unified virtual
3362 address space that the assembler and linker work with. Thus,
3363 since target_read_memory takes a CORE_ADDR as an argument, it
3364 can access any memory on the target, even if the processor has
3365 separate code and data address spaces.
3368 - If v is a value holding a D10V code pointer, its contents are
3369 in target form: a big-endian address left-shifted two bits.
3370 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3371 sizeof (void *) == 2 on the target.
3373 In this context, objfile_type->builtin_core_addr is a bit odd:
3374 it's a target type for a value the target will never see. It's
3375 only used to hold the values of (typeless) linker symbols, which
3376 are indeed in the unified virtual address space. */
3378 objfile_type
->builtin_core_addr
3379 = init_type (TYPE_CODE_INT
,
3380 gdbarch_addr_bit (gdbarch
) / 8,
3381 TYPE_FLAG_UNSIGNED
, "__CORE_ADDR", objfile
);
3383 set_objfile_data (objfile
, objfile_type_data
, objfile_type
);
3384 return objfile_type
;
3388 extern void _initialize_gdbtypes (void);
3390 _initialize_gdbtypes (void)
3392 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
3393 objfile_type_data
= register_objfile_data ();
3395 add_setshow_zinteger_cmd ("overload", no_class
, &overload_debug
, _("\
3396 Set debugging of C++ overloading."), _("\
3397 Show debugging of C++ overloading."), _("\
3398 When enabled, ranking of the functions is displayed."),
3400 show_overload_debug
,
3401 &setdebuglist
, &showdebuglist
);
3403 /* Add user knob for controlling resolution of opaque types. */
3404 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
3405 &opaque_type_resolution
, _("\
3406 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3407 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL
,
3409 show_opaque_type_resolution
,
3410 &setlist
, &showlist
);