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
89 struct type
*builtin_type_ieee_single
;
90 struct type
*builtin_type_ieee_double
;
91 struct type
*builtin_type_i387_ext
;
92 struct type
*builtin_type_m68881_ext
;
93 struct type
*builtin_type_arm_ext
;
94 struct type
*builtin_type_ia64_spill
;
95 struct type
*builtin_type_ia64_quad
;
97 int opaque_type_resolution
= 1;
99 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
100 struct cmd_list_element
*c
,
103 fprintf_filtered (file
, _("\
104 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
108 int overload_debug
= 0;
110 show_overload_debug (struct ui_file
*file
, int from_tty
,
111 struct cmd_list_element
*c
, const char *value
)
113 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"),
121 }; /* Maximum extension is 128! FIXME */
123 static void print_bit_vector (B_TYPE
*, int);
124 static void print_arg_types (struct field
*, int, int);
125 static void dump_fn_fieldlists (struct type
*, int);
126 static void print_cplus_stuff (struct type
*, int);
129 /* Alloc a new type structure and fill it with some defaults. If
130 OBJFILE is non-NULL, then allocate the space for the type structure
131 in that objfile's objfile_obstack. Otherwise allocate the new type
132 structure by xmalloc () (for permanent types). */
135 alloc_type (struct objfile
*objfile
)
139 /* Alloc the structure and start off with all fields zeroed. */
143 type
= XZALLOC (struct type
);
144 TYPE_MAIN_TYPE (type
) = XZALLOC (struct main_type
);
148 type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct type
);
149 TYPE_MAIN_TYPE (type
) = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
151 OBJSTAT (objfile
, n_types
++);
154 /* Initialize the fields that might not be zero. */
156 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
157 TYPE_OBJFILE (type
) = objfile
;
158 TYPE_VPTR_FIELDNO (type
) = -1;
159 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
164 /* Alloc a new type instance structure, fill it with some defaults,
165 and point it at OLDTYPE. Allocate the new type instance from the
166 same place as OLDTYPE. */
169 alloc_type_instance (struct type
*oldtype
)
173 /* Allocate the structure. */
175 if (TYPE_OBJFILE (oldtype
) == NULL
)
176 type
= XZALLOC (struct type
);
178 type
= OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
181 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
183 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
188 /* Clear all remnants of the previous type at TYPE, in preparation for
189 replacing it with something else. */
191 smash_type (struct type
*type
)
193 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
195 /* For now, delete the rings. */
196 TYPE_CHAIN (type
) = type
;
198 /* For now, leave the pointer/reference types alone. */
201 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
202 to a pointer to memory where the pointer type should be stored.
203 If *TYPEPTR is zero, update it to point to the pointer type we return.
204 We allocate new memory if needed. */
207 make_pointer_type (struct type
*type
, struct type
**typeptr
)
209 struct type
*ntype
; /* New type */
210 struct objfile
*objfile
;
213 ntype
= TYPE_POINTER_TYPE (type
);
218 return ntype
; /* Don't care about alloc,
219 and have new type. */
220 else if (*typeptr
== 0)
222 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
227 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
229 ntype
= alloc_type (TYPE_OBJFILE (type
));
233 else /* We have storage, but need to reset it. */
236 objfile
= TYPE_OBJFILE (ntype
);
237 chain
= TYPE_CHAIN (ntype
);
239 TYPE_CHAIN (ntype
) = chain
;
240 TYPE_OBJFILE (ntype
) = objfile
;
243 TYPE_TARGET_TYPE (ntype
) = type
;
244 TYPE_POINTER_TYPE (type
) = ntype
;
246 /* FIXME! Assume the machine has only one representation for
249 TYPE_LENGTH (ntype
) =
250 gdbarch_ptr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
251 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
253 /* Mark pointers as unsigned. The target converts between pointers
254 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
255 gdbarch_address_to_pointer. */
256 TYPE_UNSIGNED (ntype
) = 1;
258 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
259 TYPE_POINTER_TYPE (type
) = ntype
;
261 /* Update the length of all the other variants of this type. */
262 chain
= TYPE_CHAIN (ntype
);
263 while (chain
!= ntype
)
265 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
266 chain
= TYPE_CHAIN (chain
);
272 /* Given a type TYPE, return a type of pointers to that type.
273 May need to construct such a type if this is the first use. */
276 lookup_pointer_type (struct type
*type
)
278 return make_pointer_type (type
, (struct type
**) 0);
281 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
282 points to a pointer to memory where the reference type should be
283 stored. If *TYPEPTR is zero, update it to point to the reference
284 type we return. We allocate new memory if needed. */
287 make_reference_type (struct type
*type
, struct type
**typeptr
)
289 struct type
*ntype
; /* New type */
290 struct objfile
*objfile
;
293 ntype
= TYPE_REFERENCE_TYPE (type
);
298 return ntype
; /* Don't care about alloc,
299 and have new type. */
300 else if (*typeptr
== 0)
302 *typeptr
= ntype
; /* Tracking alloc, and have new type. */
307 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
309 ntype
= alloc_type (TYPE_OBJFILE (type
));
313 else /* We have storage, but need to reset it. */
316 objfile
= TYPE_OBJFILE (ntype
);
317 chain
= TYPE_CHAIN (ntype
);
319 TYPE_CHAIN (ntype
) = chain
;
320 TYPE_OBJFILE (ntype
) = objfile
;
323 TYPE_TARGET_TYPE (ntype
) = type
;
324 TYPE_REFERENCE_TYPE (type
) = ntype
;
326 /* FIXME! Assume the machine has only one representation for
327 references, and that it matches the (only) representation for
330 TYPE_LENGTH (ntype
) = gdbarch_ptr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
331 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
333 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
334 TYPE_REFERENCE_TYPE (type
) = ntype
;
336 /* Update the length of all the other variants of this type. */
337 chain
= TYPE_CHAIN (ntype
);
338 while (chain
!= ntype
)
340 TYPE_LENGTH (chain
) = TYPE_LENGTH (ntype
);
341 chain
= TYPE_CHAIN (chain
);
347 /* Same as above, but caller doesn't care about memory allocation
351 lookup_reference_type (struct type
*type
)
353 return make_reference_type (type
, (struct type
**) 0);
356 /* Lookup a function type that returns type TYPE. TYPEPTR, if
357 nonzero, points to a pointer to memory where the function type
358 should be stored. If *TYPEPTR is zero, update it to point to the
359 function type we return. We allocate new memory if needed. */
362 make_function_type (struct type
*type
, struct type
**typeptr
)
364 struct type
*ntype
; /* New type */
365 struct objfile
*objfile
;
367 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
369 ntype
= alloc_type (TYPE_OBJFILE (type
));
373 else /* We have storage, but need to reset it. */
376 objfile
= TYPE_OBJFILE (ntype
);
378 TYPE_OBJFILE (ntype
) = objfile
;
381 TYPE_TARGET_TYPE (ntype
) = type
;
383 TYPE_LENGTH (ntype
) = 1;
384 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
390 /* Given a type TYPE, return a type of functions that return that type.
391 May need to construct such a type if this is the first use. */
394 lookup_function_type (struct type
*type
)
396 return make_function_type (type
, (struct type
**) 0);
399 /* Identify address space identifier by name --
400 return the integer flag defined in gdbtypes.h. */
402 address_space_name_to_int (char *space_identifier
)
404 struct gdbarch
*gdbarch
= current_gdbarch
;
406 /* Check for known address space delimiters. */
407 if (!strcmp (space_identifier
, "code"))
408 return TYPE_INSTANCE_FLAG_CODE_SPACE
;
409 else if (!strcmp (space_identifier
, "data"))
410 return TYPE_INSTANCE_FLAG_DATA_SPACE
;
411 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
412 && gdbarch_address_class_name_to_type_flags (gdbarch
,
417 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
420 /* Identify address space identifier by integer flag as defined in
421 gdbtypes.h -- return the string version of the adress space name. */
424 address_space_int_to_name (int space_flag
)
426 struct gdbarch
*gdbarch
= current_gdbarch
;
427 if (space_flag
& TYPE_INSTANCE_FLAG_CODE_SPACE
)
429 else if (space_flag
& TYPE_INSTANCE_FLAG_DATA_SPACE
)
431 else if ((space_flag
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
432 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
433 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
438 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
440 If STORAGE is non-NULL, create the new type instance there.
441 STORAGE must be in the same obstack as TYPE. */
444 make_qualified_type (struct type
*type
, int new_flags
,
445 struct type
*storage
)
452 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
454 ntype
= TYPE_CHAIN (ntype
);
456 while (ntype
!= type
);
458 /* Create a new type instance. */
460 ntype
= alloc_type_instance (type
);
463 /* If STORAGE was provided, it had better be in the same objfile
464 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
465 if one objfile is freed and the other kept, we'd have
466 dangling pointers. */
467 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
470 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
471 TYPE_CHAIN (ntype
) = ntype
;
474 /* Pointers or references to the original type are not relevant to
476 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
477 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
479 /* Chain the new qualified type to the old type. */
480 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
481 TYPE_CHAIN (type
) = ntype
;
483 /* Now set the instance flags and return the new type. */
484 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
486 /* Set length of new type to that of the original type. */
487 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
492 /* Make an address-space-delimited variant of a type -- a type that
493 is identical to the one supplied except that it has an address
494 space attribute attached to it (such as "code" or "data").
496 The space attributes "code" and "data" are for Harvard
497 architectures. The address space attributes are for architectures
498 which have alternately sized pointers or pointers with alternate
502 make_type_with_address_space (struct type
*type
, int space_flag
)
505 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
506 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
507 | TYPE_INSTANCE_FLAG_DATA_SPACE
508 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
))
511 return make_qualified_type (type
, new_flags
, NULL
);
514 /* Make a "c-v" variant of a type -- a type that is identical to the
515 one supplied except that it may have const or volatile attributes
516 CNST is a flag for setting the const attribute
517 VOLTL is a flag for setting the volatile attribute
518 TYPE is the base type whose variant we are creating.
520 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
521 storage to hold the new qualified type; *TYPEPTR and TYPE must be
522 in the same objfile. Otherwise, allocate fresh memory for the new
523 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
524 new type we construct. */
526 make_cv_type (int cnst
, int voltl
,
528 struct type
**typeptr
)
530 struct type
*ntype
; /* New type */
531 struct type
*tmp_type
= type
; /* tmp type */
532 struct objfile
*objfile
;
534 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
535 & ~(TYPE_INSTANCE_FLAG_CONST
| TYPE_INSTANCE_FLAG_VOLATILE
));
538 new_flags
|= TYPE_INSTANCE_FLAG_CONST
;
541 new_flags
|= TYPE_INSTANCE_FLAG_VOLATILE
;
543 if (typeptr
&& *typeptr
!= NULL
)
545 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
546 a C-V variant chain that threads across objfiles: if one
547 objfile gets freed, then the other has a broken C-V chain.
549 This code used to try to copy over the main type from TYPE to
550 *TYPEPTR if they were in different objfiles, but that's
551 wrong, too: TYPE may have a field list or member function
552 lists, which refer to types of their own, etc. etc. The
553 whole shebang would need to be copied over recursively; you
554 can't have inter-objfile pointers. The only thing to do is
555 to leave stub types as stub types, and look them up afresh by
556 name each time you encounter them. */
557 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
560 ntype
= make_qualified_type (type
, new_flags
,
561 typeptr
? *typeptr
: NULL
);
569 /* Replace the contents of ntype with the type *type. This changes the
570 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
571 the changes are propogated to all types in the TYPE_CHAIN.
573 In order to build recursive types, it's inevitable that we'll need
574 to update types in place --- but this sort of indiscriminate
575 smashing is ugly, and needs to be replaced with something more
576 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
577 clear if more steps are needed. */
579 replace_type (struct type
*ntype
, struct type
*type
)
583 /* These two types had better be in the same objfile. Otherwise,
584 the assignment of one type's main type structure to the other
585 will produce a type with references to objects (names; field
586 lists; etc.) allocated on an objfile other than its own. */
587 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
589 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
591 /* The type length is not a part of the main type. Update it for
592 each type on the variant chain. */
596 /* Assert that this element of the chain has no address-class bits
597 set in its flags. Such type variants might have type lengths
598 which are supposed to be different from the non-address-class
599 variants. This assertion shouldn't ever be triggered because
600 symbol readers which do construct address-class variants don't
601 call replace_type(). */
602 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
604 TYPE_LENGTH (chain
) = TYPE_LENGTH (type
);
605 chain
= TYPE_CHAIN (chain
);
607 while (ntype
!= chain
);
609 /* Assert that the two types have equivalent instance qualifiers.
610 This should be true for at least all of our debug readers. */
611 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
614 /* Implement direct support for MEMBER_TYPE in GNU C++.
615 May need to construct such a type if this is the first use.
616 The TYPE is the type of the member. The DOMAIN is the type
617 of the aggregate that the member belongs to. */
620 lookup_memberptr_type (struct type
*type
, struct type
*domain
)
624 mtype
= alloc_type (TYPE_OBJFILE (type
));
625 smash_to_memberptr_type (mtype
, domain
, type
);
629 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
632 lookup_methodptr_type (struct type
*to_type
)
636 mtype
= alloc_type (TYPE_OBJFILE (to_type
));
637 TYPE_TARGET_TYPE (mtype
) = to_type
;
638 TYPE_DOMAIN_TYPE (mtype
) = TYPE_DOMAIN_TYPE (to_type
);
639 TYPE_LENGTH (mtype
) = cplus_method_ptr_size (to_type
);
640 TYPE_CODE (mtype
) = TYPE_CODE_METHODPTR
;
644 /* Allocate a stub method whose return type is TYPE. This apparently
645 happens for speed of symbol reading, since parsing out the
646 arguments to the method is cpu-intensive, the way we are doing it.
647 So, we will fill in arguments later. This always returns a fresh
651 allocate_stub_method (struct type
*type
)
655 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
656 TYPE_OBJFILE (type
));
657 TYPE_TARGET_TYPE (mtype
) = type
;
658 /* _DOMAIN_TYPE (mtype) = unknown yet */
662 /* Create a range type using either a blank type supplied in
663 RESULT_TYPE, or creating a new type, inheriting the objfile from
666 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
667 to HIGH_BOUND, inclusive.
669 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
670 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
673 create_range_type (struct type
*result_type
, struct type
*index_type
,
674 int low_bound
, int high_bound
)
676 if (result_type
== NULL
)
677 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
678 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
679 TYPE_TARGET_TYPE (result_type
) = index_type
;
680 if (TYPE_STUB (index_type
))
681 TYPE_TARGET_STUB (result_type
) = 1;
683 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
684 TYPE_NFIELDS (result_type
) = 2;
685 TYPE_FIELDS (result_type
) = TYPE_ZALLOC (result_type
,
686 TYPE_NFIELDS (result_type
)
687 * sizeof (struct field
));
688 TYPE_LOW_BOUND (result_type
) = low_bound
;
689 TYPE_HIGH_BOUND (result_type
) = high_bound
;
692 TYPE_UNSIGNED (result_type
) = 1;
697 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
698 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
699 bounds will fit in LONGEST), or -1 otherwise. */
702 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
704 CHECK_TYPEDEF (type
);
705 switch (TYPE_CODE (type
))
707 case TYPE_CODE_RANGE
:
708 *lowp
= TYPE_LOW_BOUND (type
);
709 *highp
= TYPE_HIGH_BOUND (type
);
712 if (TYPE_NFIELDS (type
) > 0)
714 /* The enums may not be sorted by value, so search all
718 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
719 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
721 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
722 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
723 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
724 *highp
= TYPE_FIELD_BITPOS (type
, i
);
727 /* Set unsigned indicator if warranted. */
730 TYPE_UNSIGNED (type
) = 1;
744 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
746 if (!TYPE_UNSIGNED (type
))
748 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
752 /* ... fall through for unsigned ints ... */
755 /* This round-about calculation is to avoid shifting by
756 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
757 if TYPE_LENGTH (type) == sizeof (LONGEST). */
758 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
759 *highp
= (*highp
- 1) | *highp
;
766 /* Create an array type using either a blank type supplied in
767 RESULT_TYPE, or creating a new type, inheriting the objfile from
770 Elements will be of type ELEMENT_TYPE, the indices will be of type
773 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
774 sure it is TYPE_CODE_UNDEF before we bash it into an array
778 create_array_type (struct type
*result_type
,
779 struct type
*element_type
,
780 struct type
*range_type
)
782 LONGEST low_bound
, high_bound
;
784 if (result_type
== NULL
)
786 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
788 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
789 TYPE_TARGET_TYPE (result_type
) = element_type
;
790 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
791 low_bound
= high_bound
= 0;
792 CHECK_TYPEDEF (element_type
);
793 /* Be careful when setting the array length. Ada arrays can be
794 empty arrays with the high_bound being smaller than the low_bound.
795 In such cases, the array length should be zero. */
796 if (high_bound
< low_bound
)
797 TYPE_LENGTH (result_type
) = 0;
799 TYPE_LENGTH (result_type
) =
800 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
801 TYPE_NFIELDS (result_type
) = 1;
802 TYPE_FIELDS (result_type
) =
803 (struct field
*) TYPE_ZALLOC (result_type
, sizeof (struct field
));
804 TYPE_INDEX_TYPE (result_type
) = range_type
;
805 TYPE_VPTR_FIELDNO (result_type
) = -1;
807 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
808 if (TYPE_LENGTH (result_type
) == 0)
809 TYPE_TARGET_STUB (result_type
) = 1;
815 lookup_array_range_type (struct type
*element_type
,
816 int low_bound
, int high_bound
)
818 struct gdbarch
*gdbarch
= current_gdbarch
;
819 struct type
*index_type
= builtin_type (gdbarch
)->builtin_int
;
820 struct type
*range_type
821 = create_range_type (NULL
, index_type
, low_bound
, high_bound
);
822 return create_array_type (NULL
, element_type
, range_type
);
825 /* Create a string type using either a blank type supplied in
826 RESULT_TYPE, or creating a new type. String types are similar
827 enough to array of char types that we can use create_array_type to
828 build the basic type and then bash it into a string type.
830 For fixed length strings, the range type contains 0 as the lower
831 bound and the length of the string minus one as the upper bound.
833 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
834 sure it is TYPE_CODE_UNDEF before we bash it into a string
838 create_string_type (struct type
*result_type
,
839 struct type
*string_char_type
,
840 struct type
*range_type
)
842 result_type
= create_array_type (result_type
,
845 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
850 lookup_string_range_type (struct type
*string_char_type
,
851 int low_bound
, int high_bound
)
853 struct type
*result_type
;
854 result_type
= lookup_array_range_type (string_char_type
,
855 low_bound
, high_bound
);
856 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
861 create_set_type (struct type
*result_type
, struct type
*domain_type
)
863 if (result_type
== NULL
)
865 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
867 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
868 TYPE_NFIELDS (result_type
) = 1;
869 TYPE_FIELDS (result_type
) = TYPE_ZALLOC (result_type
, sizeof (struct field
));
871 if (!TYPE_STUB (domain_type
))
873 LONGEST low_bound
, high_bound
, bit_length
;
874 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
875 low_bound
= high_bound
= 0;
876 bit_length
= high_bound
- low_bound
+ 1;
877 TYPE_LENGTH (result_type
)
878 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
880 TYPE_UNSIGNED (result_type
) = 1;
882 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
888 append_flags_type_flag (struct type
*type
, int bitpos
, char *name
)
890 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
891 gdb_assert (bitpos
< TYPE_NFIELDS (type
));
892 gdb_assert (bitpos
>= 0);
896 TYPE_FIELD_NAME (type
, bitpos
) = xstrdup (name
);
897 TYPE_FIELD_BITPOS (type
, bitpos
) = bitpos
;
901 /* Don't show this field to the user. */
902 TYPE_FIELD_BITPOS (type
, bitpos
) = -1;
907 init_flags_type (char *name
, int length
)
909 int nfields
= length
* TARGET_CHAR_BIT
;
912 type
= init_type (TYPE_CODE_FLAGS
, length
,
913 TYPE_FLAG_UNSIGNED
, name
, NULL
);
914 TYPE_NFIELDS (type
) = nfields
;
915 TYPE_FIELDS (type
) = TYPE_ZALLOC (type
, nfields
* sizeof (struct field
));
920 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
921 and any array types nested inside it. */
924 make_vector_type (struct type
*array_type
)
926 struct type
*inner_array
, *elt_type
;
929 /* Find the innermost array type, in case the array is
930 multi-dimensional. */
931 inner_array
= array_type
;
932 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
933 inner_array
= TYPE_TARGET_TYPE (inner_array
);
935 elt_type
= TYPE_TARGET_TYPE (inner_array
);
936 if (TYPE_CODE (elt_type
) == TYPE_CODE_INT
)
938 flags
= TYPE_INSTANCE_FLAGS (elt_type
) | TYPE_FLAG_NOTTEXT
;
939 elt_type
= make_qualified_type (elt_type
, flags
, NULL
);
940 TYPE_TARGET_TYPE (inner_array
) = elt_type
;
943 TYPE_VECTOR (array_type
) = 1;
947 init_vector_type (struct type
*elt_type
, int n
)
949 struct type
*array_type
;
950 array_type
= lookup_array_range_type (elt_type
, 0, n
- 1);
951 make_vector_type (array_type
);
955 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
956 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
957 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
958 TYPE doesn't include the offset (that's the value of the MEMBER
959 itself), but does include the structure type into which it points
962 When "smashing" the type, we preserve the objfile that the old type
963 pointed to, since we aren't changing where the type is actually
967 smash_to_memberptr_type (struct type
*type
, struct type
*domain
,
968 struct type
*to_type
)
970 struct objfile
*objfile
;
972 objfile
= TYPE_OBJFILE (type
);
975 TYPE_OBJFILE (type
) = objfile
;
976 TYPE_TARGET_TYPE (type
) = to_type
;
977 TYPE_DOMAIN_TYPE (type
) = domain
;
978 /* Assume that a data member pointer is the same size as a normal
980 TYPE_LENGTH (type
) = gdbarch_ptr_bit (current_gdbarch
) / TARGET_CHAR_BIT
;
981 TYPE_CODE (type
) = TYPE_CODE_MEMBERPTR
;
984 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
985 METHOD just means `function that gets an extra "this" argument'.
987 When "smashing" the type, we preserve the objfile that the old type
988 pointed to, since we aren't changing where the type is actually
992 smash_to_method_type (struct type
*type
, struct type
*domain
,
993 struct type
*to_type
, struct field
*args
,
994 int nargs
, int varargs
)
996 struct objfile
*objfile
;
998 objfile
= TYPE_OBJFILE (type
);
1001 TYPE_OBJFILE (type
) = objfile
;
1002 TYPE_TARGET_TYPE (type
) = to_type
;
1003 TYPE_DOMAIN_TYPE (type
) = domain
;
1004 TYPE_FIELDS (type
) = args
;
1005 TYPE_NFIELDS (type
) = nargs
;
1007 TYPE_VARARGS (type
) = 1;
1008 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1009 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1012 /* Return a typename for a struct/union/enum type without "struct ",
1013 "union ", or "enum ". If the type has a NULL name, return NULL. */
1016 type_name_no_tag (const struct type
*type
)
1018 if (TYPE_TAG_NAME (type
) != NULL
)
1019 return TYPE_TAG_NAME (type
);
1021 /* Is there code which expects this to return the name if there is
1022 no tag name? My guess is that this is mainly used for C++ in
1023 cases where the two will always be the same. */
1024 return TYPE_NAME (type
);
1027 /* Lookup a typedef or primitive type named NAME, visible in lexical
1028 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1029 suitably defined. */
1032 lookup_typename (const struct language_defn
*language
,
1033 struct gdbarch
*gdbarch
, char *name
,
1034 struct block
*block
, int noerr
)
1039 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0);
1040 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1042 tmp
= language_lookup_primitive_type_by_name (language
, gdbarch
, name
);
1047 else if (!tmp
&& noerr
)
1053 error (_("No type named %s."), name
);
1056 return (SYMBOL_TYPE (sym
));
1060 lookup_unsigned_typename (const struct language_defn
*language
,
1061 struct gdbarch
*gdbarch
, char *name
)
1063 char *uns
= alloca (strlen (name
) + 10);
1065 strcpy (uns
, "unsigned ");
1066 strcpy (uns
+ 9, name
);
1067 return lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 0);
1071 lookup_signed_typename (const struct language_defn
*language
,
1072 struct gdbarch
*gdbarch
, char *name
)
1075 char *uns
= alloca (strlen (name
) + 8);
1077 strcpy (uns
, "signed ");
1078 strcpy (uns
+ 7, name
);
1079 t
= lookup_typename (language
, gdbarch
, uns
, (struct block
*) NULL
, 1);
1080 /* If we don't find "signed FOO" just try again with plain "FOO". */
1083 return lookup_typename (language
, gdbarch
, name
, (struct block
*) NULL
, 0);
1086 /* Lookup a structure type named "struct NAME",
1087 visible in lexical block BLOCK. */
1090 lookup_struct (char *name
, struct block
*block
)
1094 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1098 error (_("No struct type named %s."), name
);
1100 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1102 error (_("This context has class, union or enum %s, not a struct."),
1105 return (SYMBOL_TYPE (sym
));
1108 /* Lookup a union type named "union NAME",
1109 visible in lexical block BLOCK. */
1112 lookup_union (char *name
, struct block
*block
)
1117 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1120 error (_("No union type named %s."), name
);
1122 t
= SYMBOL_TYPE (sym
);
1124 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1127 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1128 * a further "declared_type" field to discover it is really a union.
1130 if (HAVE_CPLUS_STRUCT (t
))
1131 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1134 /* If we get here, it's not a union. */
1135 error (_("This context has class, struct or enum %s, not a union."),
1140 /* Lookup an enum type named "enum NAME",
1141 visible in lexical block BLOCK. */
1144 lookup_enum (char *name
, struct block
*block
)
1148 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0);
1151 error (_("No enum type named %s."), name
);
1153 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1155 error (_("This context has class, struct or union %s, not an enum."),
1158 return (SYMBOL_TYPE (sym
));
1161 /* Lookup a template type named "template NAME<TYPE>",
1162 visible in lexical block BLOCK. */
1165 lookup_template_type (char *name
, struct type
*type
,
1166 struct block
*block
)
1169 char *nam
= (char *)
1170 alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1173 strcat (nam
, TYPE_NAME (type
));
1174 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1176 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0);
1180 error (_("No template type named %s."), name
);
1182 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1184 error (_("This context has class, union or enum %s, not a struct."),
1187 return (SYMBOL_TYPE (sym
));
1190 /* Given a type TYPE, lookup the type of the component of type named
1193 TYPE can be either a struct or union, or a pointer or reference to
1194 a struct or union. If it is a pointer or reference, its target
1195 type is automatically used. Thus '.' and '->' are interchangable,
1196 as specified for the definitions of the expression element types
1197 STRUCTOP_STRUCT and STRUCTOP_PTR.
1199 If NOERR is nonzero, return zero if NAME is not suitably defined.
1200 If NAME is the name of a baseclass type, return that type. */
1203 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1209 CHECK_TYPEDEF (type
);
1210 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1211 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1213 type
= TYPE_TARGET_TYPE (type
);
1216 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1217 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1219 target_terminal_ours ();
1220 gdb_flush (gdb_stdout
);
1221 fprintf_unfiltered (gdb_stderr
, "Type ");
1222 type_print (type
, "", gdb_stderr
, -1);
1223 error (_(" is not a structure or union type."));
1227 /* FIXME: This change put in by Michael seems incorrect for the case
1228 where the structure tag name is the same as the member name.
1229 I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
1230 foo; } bell;" Disabled by fnf. */
1234 typename
= type_name_no_tag (type
);
1235 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1240 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1242 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1244 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1246 return TYPE_FIELD_TYPE (type
, i
);
1250 /* OK, it's not in this class. Recursively check the baseclasses. */
1251 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1255 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1267 target_terminal_ours ();
1268 gdb_flush (gdb_stdout
);
1269 fprintf_unfiltered (gdb_stderr
, "Type ");
1270 type_print (type
, "", gdb_stderr
, -1);
1271 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1272 fputs_filtered (name
, gdb_stderr
);
1274 return (struct type
*) -1; /* For lint */
1277 /* Lookup the vptr basetype/fieldno values for TYPE.
1278 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1279 vptr_fieldno. Also, if found and basetype is from the same objfile,
1281 If not found, return -1 and ignore BASETYPEP.
1282 Callers should be aware that in some cases (for example,
1283 the type or one of its baseclasses is a stub type and we are
1284 debugging a .o file), this function will not be able to find the
1285 virtual function table pointer, and vptr_fieldno will remain -1 and
1286 vptr_basetype will remain NULL or incomplete. */
1289 get_vptr_fieldno (struct type
*type
, struct type
**basetypep
)
1291 CHECK_TYPEDEF (type
);
1293 if (TYPE_VPTR_FIELDNO (type
) < 0)
1297 /* We must start at zero in case the first (and only) baseclass
1298 is virtual (and hence we cannot share the table pointer). */
1299 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1301 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1303 struct type
*basetype
;
1305 fieldno
= get_vptr_fieldno (baseclass
, &basetype
);
1308 /* If the type comes from a different objfile we can't cache
1309 it, it may have a different lifetime. PR 2384 */
1310 if (TYPE_OBJFILE (type
) == TYPE_OBJFILE (basetype
))
1312 TYPE_VPTR_FIELDNO (type
) = fieldno
;
1313 TYPE_VPTR_BASETYPE (type
) = basetype
;
1316 *basetypep
= basetype
;
1327 *basetypep
= TYPE_VPTR_BASETYPE (type
);
1328 return TYPE_VPTR_FIELDNO (type
);
1333 stub_noname_complaint (void)
1335 complaint (&symfile_complaints
, _("stub type has NULL name"));
1338 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1340 If this is a stubbed struct (i.e. declared as struct foo *), see if
1341 we can find a full definition in some other file. If so, copy this
1342 definition, so we can use it in future. There used to be a comment
1343 (but not any code) that if we don't find a full definition, we'd
1344 set a flag so we don't spend time in the future checking the same
1345 type. That would be a mistake, though--we might load in more
1346 symbols which contain a full definition for the type.
1348 This used to be coded as a macro, but I don't think it is called
1349 often enough to merit such treatment. */
1351 /* Find the real type of TYPE. This function returns the real type,
1352 after removing all layers of typedefs and completing opaque or stub
1353 types. Completion changes the TYPE argument, but stripping of
1354 typedefs does not. */
1357 check_typedef (struct type
*type
)
1359 struct type
*orig_type
= type
;
1360 int is_const
, is_volatile
;
1364 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1366 if (!TYPE_TARGET_TYPE (type
))
1371 /* It is dangerous to call lookup_symbol if we are currently
1372 reading a symtab. Infinite recursion is one danger. */
1373 if (currently_reading_symtab
)
1376 name
= type_name_no_tag (type
);
1377 /* FIXME: shouldn't we separately check the TYPE_NAME and
1378 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1379 VAR_DOMAIN as appropriate? (this code was written before
1380 TYPE_NAME and TYPE_TAG_NAME were separate). */
1383 stub_noname_complaint ();
1386 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1388 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1389 else /* TYPE_CODE_UNDEF */
1390 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
);
1392 type
= TYPE_TARGET_TYPE (type
);
1395 is_const
= TYPE_CONST (type
);
1396 is_volatile
= TYPE_VOLATILE (type
);
1398 /* If this is a struct/class/union with no fields, then check
1399 whether a full definition exists somewhere else. This is for
1400 systems where a type definition with no fields is issued for such
1401 types, instead of identifying them as stub types in the first
1404 if (TYPE_IS_OPAQUE (type
)
1405 && opaque_type_resolution
1406 && !currently_reading_symtab
)
1408 char *name
= type_name_no_tag (type
);
1409 struct type
*newtype
;
1412 stub_noname_complaint ();
1415 newtype
= lookup_transparent_type (name
);
1419 /* If the resolved type and the stub are in the same
1420 objfile, then replace the stub type with the real deal.
1421 But if they're in separate objfiles, leave the stub
1422 alone; we'll just look up the transparent type every time
1423 we call check_typedef. We can't create pointers between
1424 types allocated to different objfiles, since they may
1425 have different lifetimes. Trying to copy NEWTYPE over to
1426 TYPE's objfile is pointless, too, since you'll have to
1427 move over any other types NEWTYPE refers to, which could
1428 be an unbounded amount of stuff. */
1429 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1430 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1435 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1437 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1439 char *name
= type_name_no_tag (type
);
1440 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1441 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1442 as appropriate? (this code was written before TYPE_NAME and
1443 TYPE_TAG_NAME were separate). */
1447 stub_noname_complaint ();
1450 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0);
1453 /* Same as above for opaque types, we can replace the stub
1454 with the complete type only if they are int the same
1456 if (TYPE_OBJFILE (SYMBOL_TYPE(sym
)) == TYPE_OBJFILE (type
))
1457 make_cv_type (is_const
, is_volatile
,
1458 SYMBOL_TYPE (sym
), &type
);
1460 type
= SYMBOL_TYPE (sym
);
1464 if (TYPE_TARGET_STUB (type
))
1466 struct type
*range_type
;
1467 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1469 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1473 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1474 && TYPE_NFIELDS (type
) == 1
1475 && (TYPE_CODE (range_type
= TYPE_INDEX_TYPE (type
))
1476 == TYPE_CODE_RANGE
))
1478 /* Now recompute the length of the array type, based on its
1479 number of elements and the target type's length.
1480 Watch out for Ada null Ada arrays where the high bound
1481 is smaller than the low bound. */
1482 const int low_bound
= TYPE_LOW_BOUND (range_type
);
1483 const int high_bound
= TYPE_HIGH_BOUND (range_type
);
1486 if (high_bound
< low_bound
)
1489 nb_elements
= high_bound
- low_bound
+ 1;
1491 TYPE_LENGTH (type
) = nb_elements
* TYPE_LENGTH (target_type
);
1492 TYPE_TARGET_STUB (type
) = 0;
1494 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1496 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1497 TYPE_TARGET_STUB (type
) = 0;
1500 /* Cache TYPE_LENGTH for future use. */
1501 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1505 /* Parse a type expression in the string [P..P+LENGTH). If an error
1506 occurs, silently return a void type. */
1508 static struct type
*
1509 safe_parse_type (struct gdbarch
*gdbarch
, char *p
, int length
)
1511 struct ui_file
*saved_gdb_stderr
;
1514 /* Suppress error messages. */
1515 saved_gdb_stderr
= gdb_stderr
;
1516 gdb_stderr
= ui_file_new ();
1518 /* Call parse_and_eval_type() without fear of longjmp()s. */
1519 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1520 type
= builtin_type (gdbarch
)->builtin_void
;
1522 /* Stop suppressing error messages. */
1523 ui_file_delete (gdb_stderr
);
1524 gdb_stderr
= saved_gdb_stderr
;
1529 /* Ugly hack to convert method stubs into method types.
1531 He ain't kiddin'. This demangles the name of the method into a
1532 string including argument types, parses out each argument type,
1533 generates a string casting a zero to that type, evaluates the
1534 string, and stuffs the resulting type into an argtype vector!!!
1535 Then it knows the type of the whole function (including argument
1536 types for overloading), which info used to be in the stab's but was
1537 removed to hack back the space required for them. */
1540 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1542 struct gdbarch
*gdbarch
= current_gdbarch
;
1544 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1545 char *demangled_name
= cplus_demangle (mangled_name
,
1546 DMGL_PARAMS
| DMGL_ANSI
);
1547 char *argtypetext
, *p
;
1548 int depth
= 0, argcount
= 1;
1549 struct field
*argtypes
;
1552 /* Make sure we got back a function string that we can use. */
1554 p
= strchr (demangled_name
, '(');
1558 if (demangled_name
== NULL
|| p
== NULL
)
1559 error (_("Internal: Cannot demangle mangled name `%s'."),
1562 /* Now, read in the parameters that define this type. */
1567 if (*p
== '(' || *p
== '<')
1571 else if (*p
== ')' || *p
== '>')
1575 else if (*p
== ',' && depth
== 0)
1583 /* If we read one argument and it was ``void'', don't count it. */
1584 if (strncmp (argtypetext
, "(void)", 6) == 0)
1587 /* We need one extra slot, for the THIS pointer. */
1589 argtypes
= (struct field
*)
1590 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1593 /* Add THIS pointer for non-static methods. */
1594 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1595 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1599 argtypes
[0].type
= lookup_pointer_type (type
);
1603 if (*p
!= ')') /* () means no args, skip while */
1608 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1610 /* Avoid parsing of ellipsis, they will be handled below.
1611 Also avoid ``void'' as above. */
1612 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1613 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1615 argtypes
[argcount
].type
=
1616 safe_parse_type (gdbarch
, argtypetext
, p
- argtypetext
);
1619 argtypetext
= p
+ 1;
1622 if (*p
== '(' || *p
== '<')
1626 else if (*p
== ')' || *p
== '>')
1635 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1637 /* Now update the old "stub" type into a real type. */
1638 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1639 TYPE_DOMAIN_TYPE (mtype
) = type
;
1640 TYPE_FIELDS (mtype
) = argtypes
;
1641 TYPE_NFIELDS (mtype
) = argcount
;
1642 TYPE_STUB (mtype
) = 0;
1643 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1645 TYPE_VARARGS (mtype
) = 1;
1647 xfree (demangled_name
);
1650 /* This is the external interface to check_stub_method, above. This
1651 function unstubs all of the signatures for TYPE's METHOD_ID method
1652 name. After calling this function TYPE_FN_FIELD_STUB will be
1653 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1656 This function unfortunately can not die until stabs do. */
1659 check_stub_method_group (struct type
*type
, int method_id
)
1661 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1662 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1663 int j
, found_stub
= 0;
1665 for (j
= 0; j
< len
; j
++)
1666 if (TYPE_FN_FIELD_STUB (f
, j
))
1669 check_stub_method (type
, method_id
, j
);
1672 /* GNU v3 methods with incorrect names were corrected when we read
1673 in type information, because it was cheaper to do it then. The
1674 only GNU v2 methods with incorrect method names are operators and
1675 destructors; destructors were also corrected when we read in type
1678 Therefore the only thing we need to handle here are v2 operator
1680 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1683 char dem_opname
[256];
1685 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1687 dem_opname
, DMGL_ANSI
);
1689 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
,
1693 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1697 const struct cplus_struct_type cplus_struct_default
;
1700 allocate_cplus_struct_type (struct type
*type
)
1702 if (!HAVE_CPLUS_STRUCT (type
))
1704 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1705 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1706 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1710 /* Helper function to initialize the standard scalar types.
1712 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy of
1713 the string pointed to by name in the objfile_obstack for that
1714 objfile, and initialize the type name to that copy. There are
1715 places (mipsread.c in particular, where init_type is called with a
1716 NULL value for NAME). */
1719 init_type (enum type_code code
, int length
, int flags
,
1720 char *name
, struct objfile
*objfile
)
1724 type
= alloc_type (objfile
);
1725 TYPE_CODE (type
) = code
;
1726 TYPE_LENGTH (type
) = length
;
1728 gdb_assert (!(flags
& (TYPE_FLAG_MIN
- 1)));
1729 if (flags
& TYPE_FLAG_UNSIGNED
)
1730 TYPE_UNSIGNED (type
) = 1;
1731 if (flags
& TYPE_FLAG_NOSIGN
)
1732 TYPE_NOSIGN (type
) = 1;
1733 if (flags
& TYPE_FLAG_STUB
)
1734 TYPE_STUB (type
) = 1;
1735 if (flags
& TYPE_FLAG_TARGET_STUB
)
1736 TYPE_TARGET_STUB (type
) = 1;
1737 if (flags
& TYPE_FLAG_STATIC
)
1738 TYPE_STATIC (type
) = 1;
1739 if (flags
& TYPE_FLAG_PROTOTYPED
)
1740 TYPE_PROTOTYPED (type
) = 1;
1741 if (flags
& TYPE_FLAG_INCOMPLETE
)
1742 TYPE_INCOMPLETE (type
) = 1;
1743 if (flags
& TYPE_FLAG_VARARGS
)
1744 TYPE_VARARGS (type
) = 1;
1745 if (flags
& TYPE_FLAG_VECTOR
)
1746 TYPE_VECTOR (type
) = 1;
1747 if (flags
& TYPE_FLAG_STUB_SUPPORTED
)
1748 TYPE_STUB_SUPPORTED (type
) = 1;
1749 if (flags
& TYPE_FLAG_NOTTEXT
)
1750 TYPE_NOTTEXT (type
) = 1;
1751 if (flags
& TYPE_FLAG_FIXED_INSTANCE
)
1752 TYPE_FIXED_INSTANCE (type
) = 1;
1754 if ((name
!= NULL
) && (objfile
!= NULL
))
1756 TYPE_NAME (type
) = obsavestring (name
, strlen (name
),
1757 &objfile
->objfile_obstack
);
1761 TYPE_NAME (type
) = name
;
1766 if (name
&& strcmp (name
, "char") == 0)
1767 TYPE_NOSIGN (type
) = 1;
1769 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
1770 || code
== TYPE_CODE_NAMESPACE
)
1772 INIT_CPLUS_SPECIFIC (type
);
1777 /* Helper function. Create an empty composite type. */
1780 init_composite_type (char *name
, enum type_code code
)
1783 gdb_assert (code
== TYPE_CODE_STRUCT
1784 || code
== TYPE_CODE_UNION
);
1785 t
= init_type (code
, 0, 0, NULL
, NULL
);
1786 TYPE_TAG_NAME (t
) = name
;
1790 /* Helper function. Append a field to a composite type. */
1793 append_composite_type_field_aligned (struct type
*t
, char *name
,
1794 struct type
*field
, int alignment
)
1797 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
1798 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
1799 sizeof (struct field
) * TYPE_NFIELDS (t
));
1800 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
1801 memset (f
, 0, sizeof f
[0]);
1802 FIELD_TYPE (f
[0]) = field
;
1803 FIELD_NAME (f
[0]) = name
;
1804 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1806 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
1807 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
1809 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
1811 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
1812 if (TYPE_NFIELDS (t
) > 1)
1814 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
1815 + (TYPE_LENGTH (FIELD_TYPE (f
[-1]))
1816 * TARGET_CHAR_BIT
));
1820 int left
= FIELD_BITPOS (f
[0]) % (alignment
* TARGET_CHAR_BIT
);
1823 FIELD_BITPOS (f
[0]) += left
;
1824 TYPE_LENGTH (t
) += left
/ TARGET_CHAR_BIT
;
1832 append_composite_type_field (struct type
*t
, char *name
,
1835 append_composite_type_field_aligned (t
, name
, field
, 0);
1839 can_dereference (struct type
*t
)
1841 /* FIXME: Should we return true for references as well as
1846 && TYPE_CODE (t
) == TYPE_CODE_PTR
1847 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1851 is_integral_type (struct type
*t
)
1856 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1857 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1858 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
1859 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1860 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1861 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1864 /* Check whether BASE is an ancestor or base class or DCLASS
1865 Return 1 if so, and 0 if not.
1866 Note: callers may want to check for identity of the types before
1867 calling this function -- identical types are considered to satisfy
1868 the ancestor relationship even if they're identical. */
1871 is_ancestor (struct type
*base
, struct type
*dclass
)
1875 CHECK_TYPEDEF (base
);
1876 CHECK_TYPEDEF (dclass
);
1880 if (TYPE_NAME (base
) && TYPE_NAME (dclass
)
1881 && !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1884 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1885 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1893 /* Functions for overload resolution begin here */
1895 /* Compare two badness vectors A and B and return the result.
1896 0 => A and B are identical
1897 1 => A and B are incomparable
1898 2 => A is better than B
1899 3 => A is worse than B */
1902 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
1906 short found_pos
= 0; /* any positives in c? */
1907 short found_neg
= 0; /* any negatives in c? */
1909 /* differing lengths => incomparable */
1910 if (a
->length
!= b
->length
)
1913 /* Subtract b from a */
1914 for (i
= 0; i
< a
->length
; i
++)
1916 tmp
= a
->rank
[i
] - b
->rank
[i
];
1926 return 1; /* incomparable */
1928 return 3; /* A > B */
1934 return 2; /* A < B */
1936 return 0; /* A == B */
1940 /* Rank a function by comparing its parameter types (PARMS, length
1941 NPARMS), to the types of an argument list (ARGS, length NARGS).
1942 Return a pointer to a badness vector. This has NARGS + 1
1945 struct badness_vector
*
1946 rank_function (struct type
**parms
, int nparms
,
1947 struct type
**args
, int nargs
)
1950 struct badness_vector
*bv
;
1951 int min_len
= nparms
< nargs
? nparms
: nargs
;
1953 bv
= xmalloc (sizeof (struct badness_vector
));
1954 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
1955 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
1957 /* First compare the lengths of the supplied lists.
1958 If there is a mismatch, set it to a high value. */
1960 /* pai/1997-06-03 FIXME: when we have debug info about default
1961 arguments and ellipsis parameter lists, we should consider those
1962 and rank the length-match more finely. */
1964 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
1966 /* Now rank all the parameters of the candidate function */
1967 for (i
= 1; i
<= min_len
; i
++)
1968 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
1970 /* If more arguments than parameters, add dummy entries */
1971 for (i
= min_len
+ 1; i
<= nargs
; i
++)
1972 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
1977 /* Compare the names of two integer types, assuming that any sign
1978 qualifiers have been checked already. We do it this way because
1979 there may be an "int" in the name of one of the types. */
1982 integer_types_same_name_p (const char *first
, const char *second
)
1984 int first_p
, second_p
;
1986 /* If both are shorts, return 1; if neither is a short, keep
1988 first_p
= (strstr (first
, "short") != NULL
);
1989 second_p
= (strstr (second
, "short") != NULL
);
1990 if (first_p
&& second_p
)
1992 if (first_p
|| second_p
)
1995 /* Likewise for long. */
1996 first_p
= (strstr (first
, "long") != NULL
);
1997 second_p
= (strstr (second
, "long") != NULL
);
1998 if (first_p
&& second_p
)
2000 if (first_p
|| second_p
)
2003 /* Likewise for char. */
2004 first_p
= (strstr (first
, "char") != NULL
);
2005 second_p
= (strstr (second
, "char") != NULL
);
2006 if (first_p
&& second_p
)
2008 if (first_p
|| second_p
)
2011 /* They must both be ints. */
2015 /* Compare one type (PARM) for compatibility with another (ARG).
2016 * PARM is intended to be the parameter type of a function; and
2017 * ARG is the supplied argument's type. This function tests if
2018 * the latter can be converted to the former.
2020 * Return 0 if they are identical types;
2021 * Otherwise, return an integer which corresponds to how compatible
2022 * PARM is to ARG. The higher the return value, the worse the match.
2023 * Generally the "bad" conversions are all uniformly assigned a 100. */
2026 rank_one_type (struct type
*parm
, struct type
*arg
)
2028 /* Identical type pointers. */
2029 /* However, this still doesn't catch all cases of same type for arg
2030 and param. The reason is that builtin types are different from
2031 the same ones constructed from the object. */
2035 /* Resolve typedefs */
2036 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2037 parm
= check_typedef (parm
);
2038 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2039 arg
= check_typedef (arg
);
2042 Well, damnit, if the names are exactly the same, I'll say they
2043 are exactly the same. This happens when we generate method
2044 stubs. The types won't point to the same address, but they
2045 really are the same.
2048 if (TYPE_NAME (parm
) && TYPE_NAME (arg
)
2049 && !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2052 /* Check if identical after resolving typedefs. */
2056 /* See through references, since we can almost make non-references
2058 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2059 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2060 + REFERENCE_CONVERSION_BADNESS
);
2061 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2062 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2063 + REFERENCE_CONVERSION_BADNESS
);
2065 /* Debugging only. */
2066 fprintf_filtered (gdb_stderr
,
2067 "------ Arg is %s [%d], parm is %s [%d]\n",
2068 TYPE_NAME (arg
), TYPE_CODE (arg
),
2069 TYPE_NAME (parm
), TYPE_CODE (parm
));
2071 /* x -> y means arg of type x being supplied for parameter of type y */
2073 switch (TYPE_CODE (parm
))
2076 switch (TYPE_CODE (arg
))
2079 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2080 return VOID_PTR_CONVERSION_BADNESS
;
2082 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2083 TYPE_TARGET_TYPE (arg
));
2084 case TYPE_CODE_ARRAY
:
2085 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2086 TYPE_TARGET_TYPE (arg
));
2087 case TYPE_CODE_FUNC
:
2088 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2090 case TYPE_CODE_ENUM
:
2091 case TYPE_CODE_FLAGS
:
2092 case TYPE_CODE_CHAR
:
2093 case TYPE_CODE_RANGE
:
2094 case TYPE_CODE_BOOL
:
2095 return POINTER_CONVERSION_BADNESS
;
2097 return INCOMPATIBLE_TYPE_BADNESS
;
2099 case TYPE_CODE_ARRAY
:
2100 switch (TYPE_CODE (arg
))
2103 case TYPE_CODE_ARRAY
:
2104 return rank_one_type (TYPE_TARGET_TYPE (parm
),
2105 TYPE_TARGET_TYPE (arg
));
2107 return INCOMPATIBLE_TYPE_BADNESS
;
2109 case TYPE_CODE_FUNC
:
2110 switch (TYPE_CODE (arg
))
2112 case TYPE_CODE_PTR
: /* funcptr -> func */
2113 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2115 return INCOMPATIBLE_TYPE_BADNESS
;
2118 switch (TYPE_CODE (arg
))
2121 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2123 /* Deal with signed, unsigned, and plain chars and
2124 signed and unsigned ints. */
2125 if (TYPE_NOSIGN (parm
))
2127 /* This case only for character types */
2128 if (TYPE_NOSIGN (arg
))
2129 return 0; /* plain char -> plain char */
2130 else /* signed/unsigned char -> plain char */
2131 return INTEGER_CONVERSION_BADNESS
;
2133 else if (TYPE_UNSIGNED (parm
))
2135 if (TYPE_UNSIGNED (arg
))
2137 /* unsigned int -> unsigned int, or
2138 unsigned long -> unsigned long */
2139 if (integer_types_same_name_p (TYPE_NAME (parm
),
2142 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2144 && integer_types_same_name_p (TYPE_NAME (parm
),
2146 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2148 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2152 if (integer_types_same_name_p (TYPE_NAME (arg
),
2154 && integer_types_same_name_p (TYPE_NAME (parm
),
2156 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2158 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2161 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2163 if (integer_types_same_name_p (TYPE_NAME (parm
),
2166 else if (integer_types_same_name_p (TYPE_NAME (arg
),
2168 && integer_types_same_name_p (TYPE_NAME (parm
),
2170 return INTEGER_PROMOTION_BADNESS
;
2172 return INTEGER_CONVERSION_BADNESS
;
2175 return INTEGER_CONVERSION_BADNESS
;
2177 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2178 return INTEGER_PROMOTION_BADNESS
;
2180 return INTEGER_CONVERSION_BADNESS
;
2181 case TYPE_CODE_ENUM
:
2182 case TYPE_CODE_FLAGS
:
2183 case TYPE_CODE_CHAR
:
2184 case TYPE_CODE_RANGE
:
2185 case TYPE_CODE_BOOL
:
2186 return INTEGER_PROMOTION_BADNESS
;
2188 return INT_FLOAT_CONVERSION_BADNESS
;
2190 return NS_POINTER_CONVERSION_BADNESS
;
2192 return INCOMPATIBLE_TYPE_BADNESS
;
2195 case TYPE_CODE_ENUM
:
2196 switch (TYPE_CODE (arg
))
2199 case TYPE_CODE_CHAR
:
2200 case TYPE_CODE_RANGE
:
2201 case TYPE_CODE_BOOL
:
2202 case TYPE_CODE_ENUM
:
2203 return INTEGER_CONVERSION_BADNESS
;
2205 return INT_FLOAT_CONVERSION_BADNESS
;
2207 return INCOMPATIBLE_TYPE_BADNESS
;
2210 case TYPE_CODE_CHAR
:
2211 switch (TYPE_CODE (arg
))
2213 case TYPE_CODE_RANGE
:
2214 case TYPE_CODE_BOOL
:
2215 case TYPE_CODE_ENUM
:
2216 return INTEGER_CONVERSION_BADNESS
;
2218 return INT_FLOAT_CONVERSION_BADNESS
;
2220 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2221 return INTEGER_CONVERSION_BADNESS
;
2222 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2223 return INTEGER_PROMOTION_BADNESS
;
2224 /* >>> !! else fall through !! <<< */
2225 case TYPE_CODE_CHAR
:
2226 /* Deal with signed, unsigned, and plain chars for C++ and
2227 with int cases falling through from previous case. */
2228 if (TYPE_NOSIGN (parm
))
2230 if (TYPE_NOSIGN (arg
))
2233 return INTEGER_CONVERSION_BADNESS
;
2235 else if (TYPE_UNSIGNED (parm
))
2237 if (TYPE_UNSIGNED (arg
))
2240 return INTEGER_PROMOTION_BADNESS
;
2242 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2245 return INTEGER_CONVERSION_BADNESS
;
2247 return INCOMPATIBLE_TYPE_BADNESS
;
2250 case TYPE_CODE_RANGE
:
2251 switch (TYPE_CODE (arg
))
2254 case TYPE_CODE_CHAR
:
2255 case TYPE_CODE_RANGE
:
2256 case TYPE_CODE_BOOL
:
2257 case TYPE_CODE_ENUM
:
2258 return INTEGER_CONVERSION_BADNESS
;
2260 return INT_FLOAT_CONVERSION_BADNESS
;
2262 return INCOMPATIBLE_TYPE_BADNESS
;
2265 case TYPE_CODE_BOOL
:
2266 switch (TYPE_CODE (arg
))
2269 case TYPE_CODE_CHAR
:
2270 case TYPE_CODE_RANGE
:
2271 case TYPE_CODE_ENUM
:
2274 return BOOLEAN_CONVERSION_BADNESS
;
2275 case TYPE_CODE_BOOL
:
2278 return INCOMPATIBLE_TYPE_BADNESS
;
2282 switch (TYPE_CODE (arg
))
2285 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2286 return FLOAT_PROMOTION_BADNESS
;
2287 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2290 return FLOAT_CONVERSION_BADNESS
;
2292 case TYPE_CODE_BOOL
:
2293 case TYPE_CODE_ENUM
:
2294 case TYPE_CODE_RANGE
:
2295 case TYPE_CODE_CHAR
:
2296 return INT_FLOAT_CONVERSION_BADNESS
;
2298 return INCOMPATIBLE_TYPE_BADNESS
;
2301 case TYPE_CODE_COMPLEX
:
2302 switch (TYPE_CODE (arg
))
2303 { /* Strictly not needed for C++, but... */
2305 return FLOAT_PROMOTION_BADNESS
;
2306 case TYPE_CODE_COMPLEX
:
2309 return INCOMPATIBLE_TYPE_BADNESS
;
2312 case TYPE_CODE_STRUCT
:
2313 /* currently same as TYPE_CODE_CLASS */
2314 switch (TYPE_CODE (arg
))
2316 case TYPE_CODE_STRUCT
:
2317 /* Check for derivation */
2318 if (is_ancestor (parm
, arg
))
2319 return BASE_CONVERSION_BADNESS
;
2320 /* else fall through */
2322 return INCOMPATIBLE_TYPE_BADNESS
;
2325 case TYPE_CODE_UNION
:
2326 switch (TYPE_CODE (arg
))
2328 case TYPE_CODE_UNION
:
2330 return INCOMPATIBLE_TYPE_BADNESS
;
2333 case TYPE_CODE_MEMBERPTR
:
2334 switch (TYPE_CODE (arg
))
2337 return INCOMPATIBLE_TYPE_BADNESS
;
2340 case TYPE_CODE_METHOD
:
2341 switch (TYPE_CODE (arg
))
2345 return INCOMPATIBLE_TYPE_BADNESS
;
2349 switch (TYPE_CODE (arg
))
2353 return INCOMPATIBLE_TYPE_BADNESS
;
2358 switch (TYPE_CODE (arg
))
2362 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0),
2363 TYPE_FIELD_TYPE (arg
, 0));
2365 return INCOMPATIBLE_TYPE_BADNESS
;
2368 case TYPE_CODE_VOID
:
2370 return INCOMPATIBLE_TYPE_BADNESS
;
2371 } /* switch (TYPE_CODE (arg)) */
2375 /* End of functions for overload resolution */
2378 print_bit_vector (B_TYPE
*bits
, int nbits
)
2382 for (bitno
= 0; bitno
< nbits
; bitno
++)
2384 if ((bitno
% 8) == 0)
2386 puts_filtered (" ");
2388 if (B_TST (bits
, bitno
))
2389 printf_filtered (("1"));
2391 printf_filtered (("0"));
2395 /* Note the first arg should be the "this" pointer, we may not want to
2396 include it since we may get into a infinitely recursive
2400 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2406 for (i
= 0; i
< nargs
; i
++)
2407 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2412 field_is_static (struct field
*f
)
2414 /* "static" fields are the fields whose location is not relative
2415 to the address of the enclosing struct. It would be nice to
2416 have a dedicated flag that would be set for static fields when
2417 the type is being created. But in practice, checking the field
2418 loc_kind should give us an accurate answer (at least as long as
2419 we assume that DWARF block locations are not going to be used
2420 for static fields). FIXME? */
2421 return (FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSNAME
2422 || FIELD_LOC_KIND (*f
) == FIELD_LOC_KIND_PHYSADDR
);
2426 dump_fn_fieldlists (struct type
*type
, int spaces
)
2432 printfi_filtered (spaces
, "fn_fieldlists ");
2433 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2434 printf_filtered ("\n");
2435 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2437 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2438 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2440 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2441 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2443 printf_filtered (_(") length %d\n"),
2444 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2445 for (overload_idx
= 0;
2446 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2449 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2451 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2452 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2454 printf_filtered (")\n");
2455 printfi_filtered (spaces
+ 8, "type ");
2456 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2458 printf_filtered ("\n");
2460 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2463 printfi_filtered (spaces
+ 8, "args ");
2464 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2466 printf_filtered ("\n");
2468 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2469 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
,
2472 printfi_filtered (spaces
+ 8, "fcontext ");
2473 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2475 printf_filtered ("\n");
2477 printfi_filtered (spaces
+ 8, "is_const %d\n",
2478 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2479 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2480 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2481 printfi_filtered (spaces
+ 8, "is_private %d\n",
2482 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2483 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2484 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2485 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2486 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2487 printfi_filtered (spaces
+ 8, "voffset %u\n",
2488 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2494 print_cplus_stuff (struct type
*type
, int spaces
)
2496 printfi_filtered (spaces
, "n_baseclasses %d\n",
2497 TYPE_N_BASECLASSES (type
));
2498 printfi_filtered (spaces
, "nfn_fields %d\n",
2499 TYPE_NFN_FIELDS (type
));
2500 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2501 TYPE_NFN_FIELDS_TOTAL (type
));
2502 if (TYPE_N_BASECLASSES (type
) > 0)
2504 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2505 TYPE_N_BASECLASSES (type
));
2506 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
),
2508 printf_filtered (")");
2510 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2511 TYPE_N_BASECLASSES (type
));
2512 puts_filtered ("\n");
2514 if (TYPE_NFIELDS (type
) > 0)
2516 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2518 printfi_filtered (spaces
,
2519 "private_field_bits (%d bits at *",
2520 TYPE_NFIELDS (type
));
2521 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
),
2523 printf_filtered (")");
2524 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2525 TYPE_NFIELDS (type
));
2526 puts_filtered ("\n");
2528 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2530 printfi_filtered (spaces
,
2531 "protected_field_bits (%d bits at *",
2532 TYPE_NFIELDS (type
));
2533 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
),
2535 printf_filtered (")");
2536 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2537 TYPE_NFIELDS (type
));
2538 puts_filtered ("\n");
2541 if (TYPE_NFN_FIELDS (type
) > 0)
2543 dump_fn_fieldlists (type
, spaces
);
2547 static struct obstack dont_print_type_obstack
;
2550 recursive_dump_type (struct type
*type
, int spaces
)
2555 obstack_begin (&dont_print_type_obstack
, 0);
2557 if (TYPE_NFIELDS (type
) > 0
2558 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2560 struct type
**first_dont_print
2561 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2563 int i
= (struct type
**)
2564 obstack_next_free (&dont_print_type_obstack
) - first_dont_print
;
2568 if (type
== first_dont_print
[i
])
2570 printfi_filtered (spaces
, "type node ");
2571 gdb_print_host_address (type
, gdb_stdout
);
2572 printf_filtered (_(" <same as already seen type>\n"));
2577 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2580 printfi_filtered (spaces
, "type node ");
2581 gdb_print_host_address (type
, gdb_stdout
);
2582 printf_filtered ("\n");
2583 printfi_filtered (spaces
, "name '%s' (",
2584 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2585 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2586 printf_filtered (")\n");
2587 printfi_filtered (spaces
, "tagname '%s' (",
2588 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2589 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2590 printf_filtered (")\n");
2591 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2592 switch (TYPE_CODE (type
))
2594 case TYPE_CODE_UNDEF
:
2595 printf_filtered ("(TYPE_CODE_UNDEF)");
2598 printf_filtered ("(TYPE_CODE_PTR)");
2600 case TYPE_CODE_ARRAY
:
2601 printf_filtered ("(TYPE_CODE_ARRAY)");
2603 case TYPE_CODE_STRUCT
:
2604 printf_filtered ("(TYPE_CODE_STRUCT)");
2606 case TYPE_CODE_UNION
:
2607 printf_filtered ("(TYPE_CODE_UNION)");
2609 case TYPE_CODE_ENUM
:
2610 printf_filtered ("(TYPE_CODE_ENUM)");
2612 case TYPE_CODE_FLAGS
:
2613 printf_filtered ("(TYPE_CODE_FLAGS)");
2615 case TYPE_CODE_FUNC
:
2616 printf_filtered ("(TYPE_CODE_FUNC)");
2619 printf_filtered ("(TYPE_CODE_INT)");
2622 printf_filtered ("(TYPE_CODE_FLT)");
2624 case TYPE_CODE_VOID
:
2625 printf_filtered ("(TYPE_CODE_VOID)");
2628 printf_filtered ("(TYPE_CODE_SET)");
2630 case TYPE_CODE_RANGE
:
2631 printf_filtered ("(TYPE_CODE_RANGE)");
2633 case TYPE_CODE_STRING
:
2634 printf_filtered ("(TYPE_CODE_STRING)");
2636 case TYPE_CODE_BITSTRING
:
2637 printf_filtered ("(TYPE_CODE_BITSTRING)");
2639 case TYPE_CODE_ERROR
:
2640 printf_filtered ("(TYPE_CODE_ERROR)");
2642 case TYPE_CODE_MEMBERPTR
:
2643 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2645 case TYPE_CODE_METHODPTR
:
2646 printf_filtered ("(TYPE_CODE_METHODPTR)");
2648 case TYPE_CODE_METHOD
:
2649 printf_filtered ("(TYPE_CODE_METHOD)");
2652 printf_filtered ("(TYPE_CODE_REF)");
2654 case TYPE_CODE_CHAR
:
2655 printf_filtered ("(TYPE_CODE_CHAR)");
2657 case TYPE_CODE_BOOL
:
2658 printf_filtered ("(TYPE_CODE_BOOL)");
2660 case TYPE_CODE_COMPLEX
:
2661 printf_filtered ("(TYPE_CODE_COMPLEX)");
2663 case TYPE_CODE_TYPEDEF
:
2664 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2666 case TYPE_CODE_TEMPLATE
:
2667 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2669 case TYPE_CODE_TEMPLATE_ARG
:
2670 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2672 case TYPE_CODE_NAMESPACE
:
2673 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2676 printf_filtered ("(UNKNOWN TYPE CODE)");
2679 puts_filtered ("\n");
2680 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2681 printfi_filtered (spaces
, "objfile ");
2682 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
2683 printf_filtered ("\n");
2684 printfi_filtered (spaces
, "target_type ");
2685 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2686 printf_filtered ("\n");
2687 if (TYPE_TARGET_TYPE (type
) != NULL
)
2689 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2691 printfi_filtered (spaces
, "pointer_type ");
2692 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2693 printf_filtered ("\n");
2694 printfi_filtered (spaces
, "reference_type ");
2695 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2696 printf_filtered ("\n");
2697 printfi_filtered (spaces
, "type_chain ");
2698 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
2699 printf_filtered ("\n");
2700 printfi_filtered (spaces
, "instance_flags 0x%x",
2701 TYPE_INSTANCE_FLAGS (type
));
2702 if (TYPE_CONST (type
))
2704 puts_filtered (" TYPE_FLAG_CONST");
2706 if (TYPE_VOLATILE (type
))
2708 puts_filtered (" TYPE_FLAG_VOLATILE");
2710 if (TYPE_CODE_SPACE (type
))
2712 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2714 if (TYPE_DATA_SPACE (type
))
2716 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2718 if (TYPE_ADDRESS_CLASS_1 (type
))
2720 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
2722 if (TYPE_ADDRESS_CLASS_2 (type
))
2724 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
2726 puts_filtered ("\n");
2728 printfi_filtered (spaces
, "flags");
2729 if (TYPE_UNSIGNED (type
))
2731 puts_filtered (" TYPE_FLAG_UNSIGNED");
2733 if (TYPE_NOSIGN (type
))
2735 puts_filtered (" TYPE_FLAG_NOSIGN");
2737 if (TYPE_STUB (type
))
2739 puts_filtered (" TYPE_FLAG_STUB");
2741 if (TYPE_TARGET_STUB (type
))
2743 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2745 if (TYPE_STATIC (type
))
2747 puts_filtered (" TYPE_FLAG_STATIC");
2749 if (TYPE_PROTOTYPED (type
))
2751 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2753 if (TYPE_INCOMPLETE (type
))
2755 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2757 if (TYPE_VARARGS (type
))
2759 puts_filtered (" TYPE_FLAG_VARARGS");
2761 /* This is used for things like AltiVec registers on ppc. Gcc emits
2762 an attribute for the array type, which tells whether or not we
2763 have a vector, instead of a regular array. */
2764 if (TYPE_VECTOR (type
))
2766 puts_filtered (" TYPE_FLAG_VECTOR");
2768 if (TYPE_FIXED_INSTANCE (type
))
2770 puts_filtered (" TYPE_FIXED_INSTANCE");
2772 if (TYPE_STUB_SUPPORTED (type
))
2774 puts_filtered (" TYPE_STUB_SUPPORTED");
2776 if (TYPE_NOTTEXT (type
))
2778 puts_filtered (" TYPE_NOTTEXT");
2780 puts_filtered ("\n");
2781 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2782 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
2783 puts_filtered ("\n");
2784 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2786 printfi_filtered (spaces
+ 2,
2787 "[%d] bitpos %d bitsize %d type ",
2788 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2789 TYPE_FIELD_BITSIZE (type
, idx
));
2790 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2791 printf_filtered (" name '%s' (",
2792 TYPE_FIELD_NAME (type
, idx
) != NULL
2793 ? TYPE_FIELD_NAME (type
, idx
)
2795 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2796 printf_filtered (")\n");
2797 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2799 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2802 printfi_filtered (spaces
, "vptr_basetype ");
2803 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2804 puts_filtered ("\n");
2805 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2807 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2809 printfi_filtered (spaces
, "vptr_fieldno %d\n",
2810 TYPE_VPTR_FIELDNO (type
));
2811 switch (TYPE_CODE (type
))
2813 case TYPE_CODE_STRUCT
:
2814 printfi_filtered (spaces
, "cplus_stuff ");
2815 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
),
2817 puts_filtered ("\n");
2818 print_cplus_stuff (type
, spaces
);
2822 printfi_filtered (spaces
, "floatformat ");
2823 if (TYPE_FLOATFORMAT (type
) == NULL
)
2824 puts_filtered ("(null)");
2827 puts_filtered ("{ ");
2828 if (TYPE_FLOATFORMAT (type
)[0] == NULL
2829 || TYPE_FLOATFORMAT (type
)[0]->name
== NULL
)
2830 puts_filtered ("(null)");
2832 puts_filtered (TYPE_FLOATFORMAT (type
)[0]->name
);
2834 puts_filtered (", ");
2835 if (TYPE_FLOATFORMAT (type
)[1] == NULL
2836 || TYPE_FLOATFORMAT (type
)[1]->name
== NULL
)
2837 puts_filtered ("(null)");
2839 puts_filtered (TYPE_FLOATFORMAT (type
)[1]->name
);
2841 puts_filtered (" }");
2843 puts_filtered ("\n");
2847 /* We have to pick one of the union types to be able print and
2848 test the value. Pick cplus_struct_type, even though we know
2849 it isn't any particular one. */
2850 printfi_filtered (spaces
, "type_specific ");
2851 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2852 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
2854 printf_filtered (_(" (unknown data form)"));
2856 printf_filtered ("\n");
2861 obstack_free (&dont_print_type_obstack
, NULL
);
2864 /* Trivial helpers for the libiberty hash table, for mapping one
2869 struct type
*old
, *new;
2873 type_pair_hash (const void *item
)
2875 const struct type_pair
*pair
= item
;
2876 return htab_hash_pointer (pair
->old
);
2880 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
2882 const struct type_pair
*lhs
= item_lhs
, *rhs
= item_rhs
;
2883 return lhs
->old
== rhs
->old
;
2886 /* Allocate the hash table used by copy_type_recursive to walk
2887 types without duplicates. We use OBJFILE's obstack, because
2888 OBJFILE is about to be deleted. */
2891 create_copied_types_hash (struct objfile
*objfile
)
2893 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
2894 NULL
, &objfile
->objfile_obstack
,
2895 hashtab_obstack_allocate
,
2896 dummy_obstack_deallocate
);
2899 /* Recursively copy (deep copy) TYPE, if it is associated with
2900 OBJFILE. Return a new type allocated using malloc, a saved type if
2901 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
2902 not associated with OBJFILE. */
2905 copy_type_recursive (struct objfile
*objfile
,
2907 htab_t copied_types
)
2909 struct type_pair
*stored
, pair
;
2911 struct type
*new_type
;
2913 if (TYPE_OBJFILE (type
) == NULL
)
2916 /* This type shouldn't be pointing to any types in other objfiles;
2917 if it did, the type might disappear unexpectedly. */
2918 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
2921 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
2923 return ((struct type_pair
*) *slot
)->new;
2925 new_type
= alloc_type (NULL
);
2927 /* We must add the new type to the hash table immediately, in case
2928 we encounter this type again during a recursive call below. */
2929 stored
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct type_pair
));
2931 stored
->new = new_type
;
2934 /* Copy the common fields of types. For the main type, we simply
2935 copy the entire thing and then update specific fields as needed. */
2936 *TYPE_MAIN_TYPE (new_type
) = *TYPE_MAIN_TYPE (type
);
2937 TYPE_OBJFILE (new_type
) = NULL
;
2939 if (TYPE_NAME (type
))
2940 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
2941 if (TYPE_TAG_NAME (type
))
2942 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
2944 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
2945 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
2947 /* Copy the fields. */
2948 if (TYPE_NFIELDS (type
))
2952 nfields
= TYPE_NFIELDS (type
);
2953 TYPE_FIELDS (new_type
) = XCALLOC (nfields
, struct field
);
2954 for (i
= 0; i
< nfields
; i
++)
2956 TYPE_FIELD_ARTIFICIAL (new_type
, i
) =
2957 TYPE_FIELD_ARTIFICIAL (type
, i
);
2958 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
2959 if (TYPE_FIELD_TYPE (type
, i
))
2960 TYPE_FIELD_TYPE (new_type
, i
)
2961 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
2963 if (TYPE_FIELD_NAME (type
, i
))
2964 TYPE_FIELD_NAME (new_type
, i
) =
2965 xstrdup (TYPE_FIELD_NAME (type
, i
));
2966 switch (TYPE_FIELD_LOC_KIND (type
, i
))
2968 case FIELD_LOC_KIND_BITPOS
:
2969 SET_FIELD_BITPOS (TYPE_FIELD (new_type
, i
),
2970 TYPE_FIELD_BITPOS (type
, i
));
2972 case FIELD_LOC_KIND_PHYSADDR
:
2973 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
2974 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
2976 case FIELD_LOC_KIND_PHYSNAME
:
2977 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
2978 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
,
2982 internal_error (__FILE__
, __LINE__
,
2983 _("Unexpected type field location kind: %d"),
2984 TYPE_FIELD_LOC_KIND (type
, i
));
2989 /* Copy pointers to other types. */
2990 if (TYPE_TARGET_TYPE (type
))
2991 TYPE_TARGET_TYPE (new_type
) =
2992 copy_type_recursive (objfile
,
2993 TYPE_TARGET_TYPE (type
),
2995 if (TYPE_VPTR_BASETYPE (type
))
2996 TYPE_VPTR_BASETYPE (new_type
) =
2997 copy_type_recursive (objfile
,
2998 TYPE_VPTR_BASETYPE (type
),
3000 /* Maybe copy the type_specific bits.
3002 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3003 base classes and methods. There's no fundamental reason why we
3004 can't, but at the moment it is not needed. */
3006 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
3007 TYPE_FLOATFORMAT (new_type
) = TYPE_FLOATFORMAT (type
);
3008 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3009 || TYPE_CODE (type
) == TYPE_CODE_UNION
3010 || TYPE_CODE (type
) == TYPE_CODE_TEMPLATE
3011 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
3012 INIT_CPLUS_SPECIFIC (new_type
);
3017 /* Make a copy of the given TYPE, except that the pointer & reference
3018 types are not preserved.
3020 This function assumes that the given type has an associated objfile.
3021 This objfile is used to allocate the new type. */
3024 copy_type (const struct type
*type
)
3026 struct type
*new_type
;
3028 gdb_assert (TYPE_OBJFILE (type
) != NULL
);
3030 new_type
= alloc_type (TYPE_OBJFILE (type
));
3031 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
3032 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
3033 memcpy (TYPE_MAIN_TYPE (new_type
), TYPE_MAIN_TYPE (type
),
3034 sizeof (struct main_type
));
3039 static struct type
*
3040 build_flt (int bit
, char *name
, const struct floatformat
**floatformats
)
3046 gdb_assert (floatformats
!= NULL
);
3047 gdb_assert (floatformats
[0] != NULL
&& floatformats
[1] != NULL
);
3048 bit
= floatformats
[0]->totalsize
;
3050 gdb_assert (bit
>= 0);
3052 t
= init_type (TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
, 0, name
, NULL
);
3053 TYPE_FLOATFORMAT (t
) = floatformats
;
3057 static struct gdbarch_data
*gdbtypes_data
;
3059 const struct builtin_type
*
3060 builtin_type (struct gdbarch
*gdbarch
)
3062 return gdbarch_data (gdbarch
, gdbtypes_data
);
3066 static struct type
*
3067 build_complex (int bit
, char *name
, struct type
*target_type
)
3070 t
= init_type (TYPE_CODE_COMPLEX
, 2 * bit
/ TARGET_CHAR_BIT
,
3071 0, name
, (struct objfile
*) NULL
);
3072 TYPE_TARGET_TYPE (t
) = target_type
;
3077 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3079 struct builtin_type
*builtin_type
3080 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3083 builtin_type
->builtin_void
=
3084 init_type (TYPE_CODE_VOID
, 1,
3086 "void", (struct objfile
*) NULL
);
3087 builtin_type
->builtin_char
=
3088 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3090 | (gdbarch_char_signed (gdbarch
) ? 0 : TYPE_FLAG_UNSIGNED
)),
3091 "char", (struct objfile
*) NULL
);
3092 builtin_type
->builtin_signed_char
=
3093 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3095 "signed char", (struct objfile
*) NULL
);
3096 builtin_type
->builtin_unsigned_char
=
3097 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3099 "unsigned char", (struct objfile
*) NULL
);
3100 builtin_type
->builtin_short
=
3101 init_type (TYPE_CODE_INT
,
3102 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3103 0, "short", (struct objfile
*) NULL
);
3104 builtin_type
->builtin_unsigned_short
=
3105 init_type (TYPE_CODE_INT
,
3106 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3107 TYPE_FLAG_UNSIGNED
, "unsigned short",
3108 (struct objfile
*) NULL
);
3109 builtin_type
->builtin_int
=
3110 init_type (TYPE_CODE_INT
,
3111 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3112 0, "int", (struct objfile
*) NULL
);
3113 builtin_type
->builtin_unsigned_int
=
3114 init_type (TYPE_CODE_INT
,
3115 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3116 TYPE_FLAG_UNSIGNED
, "unsigned int",
3117 (struct objfile
*) NULL
);
3118 builtin_type
->builtin_long
=
3119 init_type (TYPE_CODE_INT
,
3120 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3121 0, "long", (struct objfile
*) NULL
);
3122 builtin_type
->builtin_unsigned_long
=
3123 init_type (TYPE_CODE_INT
,
3124 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3125 TYPE_FLAG_UNSIGNED
, "unsigned long",
3126 (struct objfile
*) NULL
);
3127 builtin_type
->builtin_long_long
=
3128 init_type (TYPE_CODE_INT
,
3129 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3130 0, "long long", (struct objfile
*) NULL
);
3131 builtin_type
->builtin_unsigned_long_long
=
3132 init_type (TYPE_CODE_INT
,
3133 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3134 TYPE_FLAG_UNSIGNED
, "unsigned long long",
3135 (struct objfile
*) NULL
);
3136 builtin_type
->builtin_float
3137 = build_flt (gdbarch_float_bit (gdbarch
), "float",
3138 gdbarch_float_format (gdbarch
));
3139 builtin_type
->builtin_double
3140 = build_flt (gdbarch_double_bit (gdbarch
), "double",
3141 gdbarch_double_format (gdbarch
));
3142 builtin_type
->builtin_long_double
3143 = build_flt (gdbarch_long_double_bit (gdbarch
), "long double",
3144 gdbarch_long_double_format (gdbarch
));
3145 builtin_type
->builtin_complex
3146 = build_complex (gdbarch_float_bit (gdbarch
), "complex",
3147 builtin_type
->builtin_float
);
3148 builtin_type
->builtin_double_complex
3149 = build_complex (gdbarch_double_bit (gdbarch
), "double complex",
3150 builtin_type
->builtin_double
);
3151 builtin_type
->builtin_string
=
3152 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3154 "string", (struct objfile
*) NULL
);
3155 builtin_type
->builtin_bool
=
3156 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3158 "bool", (struct objfile
*) NULL
);
3160 /* The following three are about decimal floating point types, which
3161 are 32-bits, 64-bits and 128-bits respectively. */
3162 builtin_type
->builtin_decfloat
3163 = init_type (TYPE_CODE_DECFLOAT
, 32 / 8,
3165 "_Decimal32", (struct objfile
*) NULL
);
3166 builtin_type
->builtin_decdouble
3167 = init_type (TYPE_CODE_DECFLOAT
, 64 / 8,
3169 "_Decimal64", (struct objfile
*) NULL
);
3170 builtin_type
->builtin_declong
3171 = init_type (TYPE_CODE_DECFLOAT
, 128 / 8,
3173 "_Decimal128", (struct objfile
*) NULL
);
3175 /* "True" character types. */
3176 builtin_type
->builtin_true_char
=
3177 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3179 "true character", (struct objfile
*) NULL
);
3180 builtin_type
->builtin_true_unsigned_char
=
3181 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3183 "true character", (struct objfile
*) NULL
);
3185 /* Fixed-size integer types. */
3186 builtin_type
->builtin_int0
=
3187 init_type (TYPE_CODE_INT
, 0 / 8,
3189 "int0_t", (struct objfile
*) NULL
);
3190 builtin_type
->builtin_int8
=
3191 init_type (TYPE_CODE_INT
, 8 / 8,
3193 "int8_t", (struct objfile
*) NULL
);
3194 builtin_type
->builtin_uint8
=
3195 init_type (TYPE_CODE_INT
, 8 / 8,
3196 TYPE_FLAG_UNSIGNED
| TYPE_FLAG_NOTTEXT
,
3197 "uint8_t", (struct objfile
*) NULL
);
3198 builtin_type
->builtin_int16
=
3199 init_type (TYPE_CODE_INT
, 16 / 8,
3201 "int16_t", (struct objfile
*) NULL
);
3202 builtin_type
->builtin_uint16
=
3203 init_type (TYPE_CODE_INT
, 16 / 8,
3205 "uint16_t", (struct objfile
*) NULL
);
3206 builtin_type
->builtin_int32
=
3207 init_type (TYPE_CODE_INT
, 32 / 8,
3209 "int32_t", (struct objfile
*) NULL
);
3210 builtin_type
->builtin_uint32
=
3211 init_type (TYPE_CODE_INT
, 32 / 8,
3213 "uint32_t", (struct objfile
*) NULL
);
3214 builtin_type
->builtin_int64
=
3215 init_type (TYPE_CODE_INT
, 64 / 8,
3217 "int64_t", (struct objfile
*) NULL
);
3218 builtin_type
->builtin_uint64
=
3219 init_type (TYPE_CODE_INT
, 64 / 8,
3221 "uint64_t", (struct objfile
*) NULL
);
3222 builtin_type
->builtin_int128
=
3223 init_type (TYPE_CODE_INT
, 128 / 8,
3225 "int128_t", (struct objfile
*) NULL
);
3226 builtin_type
->builtin_uint128
=
3227 init_type (TYPE_CODE_INT
, 128 / 8,
3229 "uint128_t", (struct objfile
*) NULL
);
3231 /* Default data/code pointer types. */
3232 builtin_type
->builtin_data_ptr
=
3233 make_pointer_type (builtin_type
->builtin_void
, NULL
);
3234 builtin_type
->builtin_func_ptr
=
3235 lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3237 /* This type represents a GDB internal function. */
3238 builtin_type
->internal_fn
=
3239 init_type (TYPE_CODE_INTERNAL_FUNCTION
, 0, 0,
3240 "<internal function>", NULL
);
3242 return builtin_type
;
3246 /* This set of objfile-based types is intended to be used by symbol
3247 readers as basic types. */
3249 static const struct objfile_data
*objfile_type_data
;
3251 const struct objfile_type
*
3252 objfile_type (struct objfile
*objfile
)
3254 struct gdbarch
*gdbarch
;
3255 struct objfile_type
*objfile_type
3256 = objfile_data (objfile
, objfile_type_data
);
3259 return objfile_type
;
3261 objfile_type
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3262 1, struct objfile_type
);
3264 /* Use the objfile architecture to determine basic type properties. */
3265 gdbarch
= get_objfile_arch (objfile
);
3268 objfile_type
->builtin_void
3269 = init_type (TYPE_CODE_VOID
, 1,
3273 objfile_type
->builtin_char
3274 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3276 | (gdbarch_char_signed (gdbarch
) ? 0 : TYPE_FLAG_UNSIGNED
)),
3278 objfile_type
->builtin_signed_char
3279 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3281 "signed char", objfile
);
3282 objfile_type
->builtin_unsigned_char
3283 = init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3285 "unsigned char", objfile
);
3286 objfile_type
->builtin_short
3287 = init_type (TYPE_CODE_INT
,
3288 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3289 0, "short", objfile
);
3290 objfile_type
->builtin_unsigned_short
3291 = init_type (TYPE_CODE_INT
,
3292 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
3293 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
3294 objfile_type
->builtin_int
3295 = init_type (TYPE_CODE_INT
,
3296 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3298 objfile_type
->builtin_unsigned_int
3299 = init_type (TYPE_CODE_INT
,
3300 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
3301 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
3302 objfile_type
->builtin_long
3303 = init_type (TYPE_CODE_INT
,
3304 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3305 0, "long", objfile
);
3306 objfile_type
->builtin_unsigned_long
3307 = init_type (TYPE_CODE_INT
,
3308 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3309 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
3310 objfile_type
->builtin_long_long
3311 = init_type (TYPE_CODE_INT
,
3312 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3313 0, "long long", objfile
);
3314 objfile_type
->builtin_unsigned_long_long
3315 = init_type (TYPE_CODE_INT
,
3316 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
3317 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
3319 objfile_type
->builtin_float
3320 = init_type (TYPE_CODE_FLT
,
3321 gdbarch_float_bit (gdbarch
) / TARGET_CHAR_BIT
,
3322 0, "float", objfile
);
3323 TYPE_FLOATFORMAT (objfile_type
->builtin_float
)
3324 = gdbarch_float_format (gdbarch
);
3325 objfile_type
->builtin_double
3326 = init_type (TYPE_CODE_FLT
,
3327 gdbarch_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
3328 0, "double", objfile
);
3329 TYPE_FLOATFORMAT (objfile_type
->builtin_double
)
3330 = gdbarch_double_format (gdbarch
);
3331 objfile_type
->builtin_long_double
3332 = init_type (TYPE_CODE_FLT
,
3333 gdbarch_long_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
3334 0, "long double", objfile
);
3335 TYPE_FLOATFORMAT (objfile_type
->builtin_long_double
)
3336 = gdbarch_long_double_format (gdbarch
);
3338 /* This type represents a type that was unrecognized in symbol read-in. */
3339 objfile_type
->builtin_error
3340 = init_type (TYPE_CODE_ERROR
, 0, 0, "<unknown type>", objfile
);
3342 /* The following set of types is used for symbols with no
3343 debug information. */
3344 objfile_type
->nodebug_text_symbol
3345 = init_type (TYPE_CODE_FUNC
, 1, 0,
3346 "<text variable, no debug info>", objfile
);
3347 TYPE_TARGET_TYPE (objfile_type
->nodebug_text_symbol
)
3348 = objfile_type
->builtin_int
;
3349 objfile_type
->nodebug_data_symbol
3350 = init_type (TYPE_CODE_INT
,
3351 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3352 "<data variable, no debug info>", objfile
);
3353 objfile_type
->nodebug_unknown_symbol
3354 = init_type (TYPE_CODE_INT
, 1, 0,
3355 "<variable (not text or data), no debug info>", objfile
);
3356 objfile_type
->nodebug_tls_symbol
3357 = init_type (TYPE_CODE_INT
,
3358 gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
, 0,
3359 "<thread local variable, no debug info>", objfile
);
3361 /* NOTE: on some targets, addresses and pointers are not necessarily
3362 the same --- for example, on the D10V, pointers are 16 bits long,
3363 but addresses are 32 bits long. See doc/gdbint.texinfo,
3364 ``Pointers Are Not Always Addresses''.
3367 - gdb's `struct type' always describes the target's
3369 - gdb's `struct value' objects should always hold values in
3371 - gdb's CORE_ADDR values are addresses in the unified virtual
3372 address space that the assembler and linker work with. Thus,
3373 since target_read_memory takes a CORE_ADDR as an argument, it
3374 can access any memory on the target, even if the processor has
3375 separate code and data address spaces.
3378 - If v is a value holding a D10V code pointer, its contents are
3379 in target form: a big-endian address left-shifted two bits.
3380 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3381 sizeof (void *) == 2 on the target.
3383 In this context, objfile_type->builtin_core_addr is a bit odd:
3384 it's a target type for a value the target will never see. It's
3385 only used to hold the values of (typeless) linker symbols, which
3386 are indeed in the unified virtual address space. */
3388 objfile_type
->builtin_core_addr
3389 = init_type (TYPE_CODE_INT
,
3390 gdbarch_addr_bit (gdbarch
) / 8,
3391 TYPE_FLAG_UNSIGNED
, "__CORE_ADDR", objfile
);
3393 set_objfile_data (objfile
, objfile_type_data
, objfile_type
);
3394 return objfile_type
;
3398 extern void _initialize_gdbtypes (void);
3400 _initialize_gdbtypes (void)
3402 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
3403 objfile_type_data
= register_objfile_data ();
3405 /* FIXME: The following types are architecture-neutral. However,
3406 they contain pointer_type and reference_type fields potentially
3407 caching pointer or reference types that *are* architecture
3410 builtin_type_ieee_single
=
3411 build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single
);
3412 builtin_type_ieee_double
=
3413 build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double
);
3414 builtin_type_i387_ext
=
3415 build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext
);
3416 builtin_type_m68881_ext
=
3417 build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext
);
3418 builtin_type_arm_ext
=
3419 build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext
);
3420 builtin_type_ia64_spill
=
3421 build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill
);
3422 builtin_type_ia64_quad
=
3423 build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad
);
3425 add_setshow_zinteger_cmd ("overload", no_class
, &overload_debug
, _("\
3426 Set debugging of C++ overloading."), _("\
3427 Show debugging of C++ overloading."), _("\
3428 When enabled, ranking of the functions is displayed."),
3430 show_overload_debug
,
3431 &setdebuglist
, &showdebuglist
);
3433 /* Add user knob for controlling resolution of opaque types. */
3434 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
3435 &opaque_type_resolution
, _("\
3436 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3437 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL
,
3439 show_opaque_type_resolution
,
3440 &setlist
, &showlist
);