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 Free Software Foundation, Inc.
6 Contributed by Cygnus Support, using pieces from other GDB modules.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
26 #include "gdb_string.h"
32 #include "expression.h"
37 #include "complaints.h"
41 #include "gdb_assert.h"
44 /* These variables point to the objects
45 representing the predefined C data types. */
47 struct type
*builtin_type_void
;
48 struct type
*builtin_type_char
;
49 struct type
*builtin_type_true_char
;
50 struct type
*builtin_type_short
;
51 struct type
*builtin_type_int
;
52 struct type
*builtin_type_long
;
53 struct type
*builtin_type_long_long
;
54 struct type
*builtin_type_signed_char
;
55 struct type
*builtin_type_unsigned_char
;
56 struct type
*builtin_type_unsigned_short
;
57 struct type
*builtin_type_unsigned_int
;
58 struct type
*builtin_type_unsigned_long
;
59 struct type
*builtin_type_unsigned_long_long
;
60 struct type
*builtin_type_float
;
61 struct type
*builtin_type_double
;
62 struct type
*builtin_type_long_double
;
63 struct type
*builtin_type_complex
;
64 struct type
*builtin_type_double_complex
;
65 struct type
*builtin_type_string
;
66 struct type
*builtin_type_int0
;
67 struct type
*builtin_type_int8
;
68 struct type
*builtin_type_uint8
;
69 struct type
*builtin_type_int16
;
70 struct type
*builtin_type_uint16
;
71 struct type
*builtin_type_int32
;
72 struct type
*builtin_type_uint32
;
73 struct type
*builtin_type_int64
;
74 struct type
*builtin_type_uint64
;
75 struct type
*builtin_type_int128
;
76 struct type
*builtin_type_uint128
;
77 struct type
*builtin_type_bool
;
79 /* 128 bit long vector types */
80 struct type
*builtin_type_v2_double
;
81 struct type
*builtin_type_v4_float
;
82 struct type
*builtin_type_v2_int64
;
83 struct type
*builtin_type_v4_int32
;
84 struct type
*builtin_type_v8_int16
;
85 struct type
*builtin_type_v16_int8
;
86 /* 64 bit long vector types */
87 struct type
*builtin_type_v2_float
;
88 struct type
*builtin_type_v2_int32
;
89 struct type
*builtin_type_v4_int16
;
90 struct type
*builtin_type_v8_int8
;
92 struct type
*builtin_type_v4sf
;
93 struct type
*builtin_type_v4si
;
94 struct type
*builtin_type_v16qi
;
95 struct type
*builtin_type_v8qi
;
96 struct type
*builtin_type_v8hi
;
97 struct type
*builtin_type_v4hi
;
98 struct type
*builtin_type_v2si
;
99 struct type
*builtin_type_vec64
;
100 struct type
*builtin_type_vec128
;
101 struct type
*builtin_type_ieee_single
[BFD_ENDIAN_UNKNOWN
];
102 struct type
*builtin_type_ieee_single_big
;
103 struct type
*builtin_type_ieee_single_little
;
104 struct type
*builtin_type_ieee_double
[BFD_ENDIAN_UNKNOWN
];
105 struct type
*builtin_type_ieee_double_big
;
106 struct type
*builtin_type_ieee_double_little
;
107 struct type
*builtin_type_ieee_double_littlebyte_bigword
;
108 struct type
*builtin_type_i387_ext
;
109 struct type
*builtin_type_m68881_ext
;
110 struct type
*builtin_type_i960_ext
;
111 struct type
*builtin_type_m88110_ext
;
112 struct type
*builtin_type_m88110_harris_ext
;
113 struct type
*builtin_type_arm_ext
[BFD_ENDIAN_UNKNOWN
];
114 struct type
*builtin_type_arm_ext_big
;
115 struct type
*builtin_type_arm_ext_littlebyte_bigword
;
116 struct type
*builtin_type_ia64_spill
[BFD_ENDIAN_UNKNOWN
];
117 struct type
*builtin_type_ia64_spill_big
;
118 struct type
*builtin_type_ia64_spill_little
;
119 struct type
*builtin_type_ia64_quad
[BFD_ENDIAN_UNKNOWN
];
120 struct type
*builtin_type_ia64_quad_big
;
121 struct type
*builtin_type_ia64_quad_little
;
122 struct type
*builtin_type_void_data_ptr
;
123 struct type
*builtin_type_void_func_ptr
;
124 struct type
*builtin_type_CORE_ADDR
;
125 struct type
*builtin_type_bfd_vma
;
127 int opaque_type_resolution
= 1;
129 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
130 struct cmd_list_element
*c
, const char *value
)
132 fprintf_filtered (file
, _("\
133 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
137 int overload_debug
= 0;
139 show_overload_debug (struct ui_file
*file
, int from_tty
,
140 struct cmd_list_element
*c
, const char *value
)
142 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"), value
);
149 }; /* maximum extension is 128! FIXME */
151 static void print_bit_vector (B_TYPE
*, int);
152 static void print_arg_types (struct field
*, int, int);
153 static void dump_fn_fieldlists (struct type
*, int);
154 static void print_cplus_stuff (struct type
*, int);
155 static void virtual_base_list_aux (struct type
*dclass
);
158 /* Alloc a new type structure and fill it with some defaults. If
159 OBJFILE is non-NULL, then allocate the space for the type structure
160 in that objfile's objfile_obstack. Otherwise allocate the new type structure
161 by xmalloc () (for permanent types). */
164 alloc_type (struct objfile
*objfile
)
168 /* Alloc the structure and start off with all fields zeroed. */
172 type
= xmalloc (sizeof (struct type
));
173 memset (type
, 0, sizeof (struct type
));
174 TYPE_MAIN_TYPE (type
) = xmalloc (sizeof (struct main_type
));
178 type
= obstack_alloc (&objfile
->objfile_obstack
,
179 sizeof (struct type
));
180 memset (type
, 0, sizeof (struct type
));
181 TYPE_MAIN_TYPE (type
) = obstack_alloc (&objfile
->objfile_obstack
,
182 sizeof (struct main_type
));
183 OBJSTAT (objfile
, n_types
++);
185 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
187 /* Initialize the fields that might not be zero. */
189 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
190 TYPE_OBJFILE (type
) = objfile
;
191 TYPE_VPTR_FIELDNO (type
) = -1;
192 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
197 /* Alloc a new type instance structure, fill it with some defaults,
198 and point it at OLDTYPE. Allocate the new type instance from the
199 same place as OLDTYPE. */
202 alloc_type_instance (struct type
*oldtype
)
206 /* Allocate the structure. */
208 if (TYPE_OBJFILE (oldtype
) == NULL
)
210 type
= xmalloc (sizeof (struct type
));
211 memset (type
, 0, sizeof (struct type
));
215 type
= obstack_alloc (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
216 sizeof (struct type
));
217 memset (type
, 0, sizeof (struct type
));
219 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
221 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
226 /* Clear all remnants of the previous type at TYPE, in preparation for
227 replacing it with something else. */
229 smash_type (struct type
*type
)
231 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
233 /* For now, delete the rings. */
234 TYPE_CHAIN (type
) = type
;
236 /* For now, leave the pointer/reference types alone. */
239 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
240 to a pointer to memory where the pointer type should be stored.
241 If *TYPEPTR is zero, update it to point to the pointer type we return.
242 We allocate new memory if needed. */
245 make_pointer_type (struct type
*type
, struct type
**typeptr
)
247 struct type
*ntype
; /* New type */
248 struct objfile
*objfile
;
250 ntype
= TYPE_POINTER_TYPE (type
);
255 return ntype
; /* Don't care about alloc, and have new type. */
256 else if (*typeptr
== 0)
258 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
263 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
265 ntype
= alloc_type (TYPE_OBJFILE (type
));
270 /* We have storage, but need to reset it. */
273 objfile
= TYPE_OBJFILE (ntype
);
275 TYPE_OBJFILE (ntype
) = objfile
;
278 TYPE_TARGET_TYPE (ntype
) = type
;
279 TYPE_POINTER_TYPE (type
) = ntype
;
281 /* FIXME! Assume the machine has only one representation for pointers! */
283 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
284 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
286 /* Mark pointers as unsigned. The target converts between pointers
287 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
288 ADDRESS_TO_POINTER(). */
289 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
291 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
292 TYPE_POINTER_TYPE (type
) = ntype
;
297 /* Given a type TYPE, return a type of pointers to that type.
298 May need to construct such a type if this is the first use. */
301 lookup_pointer_type (struct type
*type
)
303 return make_pointer_type (type
, (struct type
**) 0);
306 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
307 to a pointer to memory where the reference type should be stored.
308 If *TYPEPTR is zero, update it to point to the reference type we return.
309 We allocate new memory if needed. */
312 make_reference_type (struct type
*type
, struct type
**typeptr
)
314 struct type
*ntype
; /* New type */
315 struct objfile
*objfile
;
317 ntype
= TYPE_REFERENCE_TYPE (type
);
322 return ntype
; /* Don't care about alloc, and have new type. */
323 else if (*typeptr
== 0)
325 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
330 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
332 ntype
= alloc_type (TYPE_OBJFILE (type
));
337 /* We have storage, but need to reset it. */
340 objfile
= TYPE_OBJFILE (ntype
);
342 TYPE_OBJFILE (ntype
) = objfile
;
345 TYPE_TARGET_TYPE (ntype
) = type
;
346 TYPE_REFERENCE_TYPE (type
) = ntype
;
348 /* FIXME! Assume the machine has only one representation for references,
349 and that it matches the (only) representation for pointers! */
351 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
352 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
354 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
355 TYPE_REFERENCE_TYPE (type
) = ntype
;
360 /* Same as above, but caller doesn't care about memory allocation details. */
363 lookup_reference_type (struct type
*type
)
365 return make_reference_type (type
, (struct type
**) 0);
368 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
369 to a pointer to memory where the function type should be stored.
370 If *TYPEPTR is zero, update it to point to the function type we return.
371 We allocate new memory if needed. */
374 make_function_type (struct type
*type
, struct type
**typeptr
)
376 struct type
*ntype
; /* New type */
377 struct objfile
*objfile
;
379 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
381 ntype
= alloc_type (TYPE_OBJFILE (type
));
386 /* We have storage, but need to reset it. */
389 objfile
= TYPE_OBJFILE (ntype
);
391 TYPE_OBJFILE (ntype
) = objfile
;
394 TYPE_TARGET_TYPE (ntype
) = type
;
396 TYPE_LENGTH (ntype
) = 1;
397 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
403 /* Given a type TYPE, return a type of functions that return that type.
404 May need to construct such a type if this is the first use. */
407 lookup_function_type (struct type
*type
)
409 return make_function_type (type
, (struct type
**) 0);
412 /* Identify address space identifier by name --
413 return the integer flag defined in gdbtypes.h. */
415 address_space_name_to_int (char *space_identifier
)
417 struct gdbarch
*gdbarch
= current_gdbarch
;
419 /* Check for known address space delimiters. */
420 if (!strcmp (space_identifier
, "code"))
421 return TYPE_FLAG_CODE_SPACE
;
422 else if (!strcmp (space_identifier
, "data"))
423 return TYPE_FLAG_DATA_SPACE
;
424 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
425 && gdbarch_address_class_name_to_type_flags (gdbarch
,
430 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
433 /* Identify address space identifier by integer flag as defined in
434 gdbtypes.h -- return the string version of the adress space name. */
437 address_space_int_to_name (int space_flag
)
439 struct gdbarch
*gdbarch
= current_gdbarch
;
440 if (space_flag
& TYPE_FLAG_CODE_SPACE
)
442 else if (space_flag
& TYPE_FLAG_DATA_SPACE
)
444 else if ((space_flag
& TYPE_FLAG_ADDRESS_CLASS_ALL
)
445 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
446 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
451 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
453 If STORAGE is non-NULL, create the new type instance there.
454 STORAGE must be in the same obstack as TYPE. */
457 make_qualified_type (struct type
*type
, int new_flags
,
458 struct type
*storage
)
464 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
466 ntype
= TYPE_CHAIN (ntype
);
467 } while (ntype
!= type
);
469 /* Create a new type instance. */
471 ntype
= alloc_type_instance (type
);
474 /* If STORAGE was provided, it had better be in the same objfile as
475 TYPE. Otherwise, we can't link it into TYPE's cv chain: if one
476 objfile is freed and the other kept, we'd have dangling
478 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
481 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
482 TYPE_CHAIN (ntype
) = ntype
;
485 /* Pointers or references to the original type are not relevant to
487 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
488 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
490 /* Chain the new qualified type to the old type. */
491 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
492 TYPE_CHAIN (type
) = ntype
;
494 /* Now set the instance flags and return the new type. */
495 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
497 /* Set length of new type to that of the original type. */
498 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
503 /* Make an address-space-delimited variant of a type -- a type that
504 is identical to the one supplied except that it has an address
505 space attribute attached to it (such as "code" or "data").
507 The space attributes "code" and "data" are for Harvard architectures.
508 The address space attributes are for architectures which have
509 alternately sized pointers or pointers with alternate representations. */
512 make_type_with_address_space (struct type
*type
, int space_flag
)
515 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
516 & ~(TYPE_FLAG_CODE_SPACE
| TYPE_FLAG_DATA_SPACE
517 | TYPE_FLAG_ADDRESS_CLASS_ALL
))
520 return make_qualified_type (type
, new_flags
, NULL
);
523 /* Make a "c-v" variant of a type -- a type that is identical to the
524 one supplied except that it may have const or volatile attributes
525 CNST is a flag for setting the const attribute
526 VOLTL is a flag for setting the volatile attribute
527 TYPE is the base type whose variant we are creating.
529 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
530 storage to hold the new qualified type; *TYPEPTR and TYPE must be
531 in the same objfile. Otherwise, allocate fresh memory for the new
532 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
533 new type we construct. */
535 make_cv_type (int cnst
, int voltl
, struct type
*type
, struct type
**typeptr
)
537 struct type
*ntype
; /* New type */
538 struct type
*tmp_type
= type
; /* tmp type */
539 struct objfile
*objfile
;
541 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
542 & ~(TYPE_FLAG_CONST
| TYPE_FLAG_VOLATILE
));
545 new_flags
|= TYPE_FLAG_CONST
;
548 new_flags
|= TYPE_FLAG_VOLATILE
;
550 if (typeptr
&& *typeptr
!= NULL
)
552 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
553 a C-V variant chain that threads across objfiles: if one
554 objfile gets freed, then the other has a broken C-V chain.
556 This code used to try to copy over the main type from TYPE to
557 *TYPEPTR if they were in different objfiles, but that's
558 wrong, too: TYPE may have a field list or member function
559 lists, which refer to types of their own, etc. etc. The
560 whole shebang would need to be copied over recursively; you
561 can't have inter-objfile pointers. The only thing to do is
562 to leave stub types as stub types, and look them up afresh by
563 name each time you encounter them. */
564 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
567 ntype
= make_qualified_type (type
, new_flags
, typeptr
? *typeptr
: NULL
);
575 /* Replace the contents of ntype with the type *type. This changes the
576 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
577 the changes are propogated to all types in the TYPE_CHAIN.
579 In order to build recursive types, it's inevitable that we'll need
580 to update types in place --- but this sort of indiscriminate
581 smashing is ugly, and needs to be replaced with something more
582 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
583 clear if more steps are needed. */
585 replace_type (struct type
*ntype
, struct type
*type
)
589 /* These two types had better be in the same objfile. Otherwise,
590 the assignment of one type's main type structure to the other
591 will produce a type with references to objects (names; field
592 lists; etc.) allocated on an objfile other than its own. */
593 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
595 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
597 /* The type length is not a part of the main type. Update it for each
598 type on the variant chain. */
601 /* Assert that this element of the chain has no address-class bits
602 set in its flags. Such type variants might have type lengths
603 which are supposed to be different from the non-address-class
604 variants. This assertion shouldn't ever be triggered because
605 symbol readers which do construct address-class variants don't
606 call replace_type(). */
607 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
609 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
610 chain
= TYPE_CHAIN (chain
);
611 } while (ntype
!= chain
);
613 /* Assert that the two types have equivalent instance qualifiers.
614 This should be true for at least all of our debug readers. */
615 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
618 /* Implement direct support for MEMBER_TYPE in GNU C++.
619 May need to construct such a type if this is the first use.
620 The TYPE is the type of the member. The DOMAIN is the type
621 of the aggregate that the member belongs to. */
624 lookup_member_type (struct type
*type
, struct type
*domain
)
628 mtype
= alloc_type (TYPE_OBJFILE (type
));
629 smash_to_member_type (mtype
, domain
, type
);
633 /* Allocate a stub method whose return type is TYPE.
634 This apparently happens for speed of symbol reading, since parsing
635 out the arguments to the method is cpu-intensive, the way we are doing
636 it. So, we will fill in arguments later.
637 This always returns a fresh type. */
640 allocate_stub_method (struct type
*type
)
644 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
645 TYPE_OBJFILE (type
));
646 TYPE_TARGET_TYPE (mtype
) = type
;
647 /* _DOMAIN_TYPE (mtype) = unknown yet */
651 /* Create a range type using either a blank type supplied in RESULT_TYPE,
652 or creating a new type, inheriting the objfile from INDEX_TYPE.
654 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
655 HIGH_BOUND, inclusive.
657 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
658 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
661 create_range_type (struct type
*result_type
, struct type
*index_type
,
662 int low_bound
, int high_bound
)
664 if (result_type
== NULL
)
666 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
668 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
669 TYPE_TARGET_TYPE (result_type
) = index_type
;
670 if (TYPE_STUB (index_type
))
671 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
673 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
674 TYPE_NFIELDS (result_type
) = 2;
675 TYPE_FIELDS (result_type
) = (struct field
*)
676 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
677 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
678 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
679 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
680 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
681 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
684 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
686 return (result_type
);
689 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
690 Return 1 if type is a range type, 0 if it is discrete (and bounds
691 will fit in LONGEST), or -1 otherwise. */
694 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
696 CHECK_TYPEDEF (type
);
697 switch (TYPE_CODE (type
))
699 case TYPE_CODE_RANGE
:
700 *lowp
= TYPE_LOW_BOUND (type
);
701 *highp
= TYPE_HIGH_BOUND (type
);
704 if (TYPE_NFIELDS (type
) > 0)
706 /* The enums may not be sorted by value, so search all
710 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
711 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
713 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
714 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
715 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
716 *highp
= TYPE_FIELD_BITPOS (type
, i
);
719 /* Set unsigned indicator if warranted. */
722 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
736 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
738 if (!TYPE_UNSIGNED (type
))
740 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
744 /* ... fall through for unsigned ints ... */
747 /* This round-about calculation is to avoid shifting by
748 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
749 if TYPE_LENGTH (type) == sizeof (LONGEST). */
750 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
751 *highp
= (*highp
- 1) | *highp
;
758 /* Create an array type using either a blank type supplied in RESULT_TYPE,
759 or creating a new type, inheriting the objfile from RANGE_TYPE.
761 Elements will be of type ELEMENT_TYPE, the indices will be of type
764 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
765 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
768 create_array_type (struct type
*result_type
, struct type
*element_type
,
769 struct type
*range_type
)
771 LONGEST low_bound
, high_bound
;
773 if (result_type
== NULL
)
775 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
777 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
778 TYPE_TARGET_TYPE (result_type
) = element_type
;
779 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
780 low_bound
= high_bound
= 0;
781 CHECK_TYPEDEF (element_type
);
782 TYPE_LENGTH (result_type
) =
783 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
784 TYPE_NFIELDS (result_type
) = 1;
785 TYPE_FIELDS (result_type
) =
786 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
787 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
788 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
789 TYPE_VPTR_FIELDNO (result_type
) = -1;
791 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
792 if (TYPE_LENGTH (result_type
) == 0)
793 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
795 return (result_type
);
798 /* Create a string type using either a blank type supplied in RESULT_TYPE,
799 or creating a new type. String types are similar enough to array of
800 char types that we can use create_array_type to build the basic type
801 and then bash it into a string type.
803 For fixed length strings, the range type contains 0 as the lower
804 bound and the length of the string minus one as the upper bound.
806 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
807 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
810 create_string_type (struct type
*result_type
, struct type
*range_type
)
812 struct type
*string_char_type
;
814 string_char_type
= language_string_char_type (current_language
,
816 result_type
= create_array_type (result_type
,
819 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
820 return (result_type
);
824 create_set_type (struct type
*result_type
, struct type
*domain_type
)
826 LONGEST low_bound
, high_bound
, bit_length
;
827 if (result_type
== NULL
)
829 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
831 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
832 TYPE_NFIELDS (result_type
) = 1;
833 TYPE_FIELDS (result_type
) = (struct field
*)
834 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
835 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
837 if (!TYPE_STUB (domain_type
))
839 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
840 low_bound
= high_bound
= 0;
841 bit_length
= high_bound
- low_bound
+ 1;
842 TYPE_LENGTH (result_type
)
843 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
845 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
848 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
850 return (result_type
);
854 append_flags_type_flag (struct type
*type
, int bitpos
, char *name
)
856 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLAGS
);
857 gdb_assert (bitpos
< TYPE_NFIELDS (type
));
858 gdb_assert (bitpos
>= 0);
862 TYPE_FIELD_NAME (type
, bitpos
) = xstrdup (name
);
863 TYPE_FIELD_BITPOS (type
, bitpos
) = bitpos
;
867 /* Don't show this field to the user. */
868 TYPE_FIELD_BITPOS (type
, bitpos
) = -1;
873 init_flags_type (char *name
, int length
)
875 int nfields
= length
* TARGET_CHAR_BIT
;
878 type
= init_type (TYPE_CODE_FLAGS
, length
, TYPE_FLAG_UNSIGNED
, name
, NULL
);
879 TYPE_NFIELDS (type
) = nfields
;
880 TYPE_FIELDS (type
) = TYPE_ALLOC (type
, nfields
* sizeof (struct field
));
881 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
));
886 /* Construct and return a type of the form:
887 struct NAME { ELT_TYPE ELT_NAME[N]; }
888 We use these types for SIMD registers. For example, the type of
889 the SSE registers on the late x86-family processors is:
890 struct __builtin_v4sf { float f[4]; }
891 built by the function call:
892 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
893 The type returned is a permanent type, allocated using malloc; it
894 doesn't live in any objfile's obstack. */
896 init_simd_type (char *name
,
897 struct type
*elt_type
,
901 struct type
*simd_type
;
902 struct type
*array_type
;
904 simd_type
= init_composite_type (name
, TYPE_CODE_STRUCT
);
905 array_type
= create_array_type (0, elt_type
,
906 create_range_type (0, builtin_type_int
,
908 append_composite_type_field (simd_type
, elt_name
, array_type
);
913 init_vector_type (struct type
*elt_type
, int n
)
915 struct type
*array_type
;
917 array_type
= create_array_type (0, elt_type
,
918 create_range_type (0, builtin_type_int
,
920 TYPE_FLAGS (array_type
) |= TYPE_FLAG_VECTOR
;
925 build_builtin_type_vec64 (void)
927 /* Construct a type for the 64 bit registers. The type we're
930 union __gdb_builtin_type_vec64
942 t
= init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION
);
943 append_composite_type_field (t
, "uint64", builtin_type_int64
);
944 append_composite_type_field (t
, "v2_float", builtin_type_v2_float
);
945 append_composite_type_field (t
, "v2_int32", builtin_type_v2_int32
);
946 append_composite_type_field (t
, "v4_int16", builtin_type_v4_int16
);
947 append_composite_type_field (t
, "v8_int8", builtin_type_v8_int8
);
949 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
950 TYPE_NAME (t
) = "builtin_type_vec64";
955 build_builtin_type_vec128 (void)
957 /* Construct a type for the 128 bit registers. The type we're
960 union __gdb_builtin_type_vec128
972 t
= init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION
);
973 append_composite_type_field (t
, "uint128", builtin_type_int128
);
974 append_composite_type_field (t
, "v4_float", builtin_type_v4_float
);
975 append_composite_type_field (t
, "v4_int32", builtin_type_v4_int32
);
976 append_composite_type_field (t
, "v8_int16", builtin_type_v8_int16
);
977 append_composite_type_field (t
, "v16_int8", builtin_type_v16_int8
);
979 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
980 TYPE_NAME (t
) = "builtin_type_vec128";
984 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
985 A MEMBER is a wierd thing -- it amounts to a typed offset into
986 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
987 include the offset (that's the value of the MEMBER itself), but does
988 include the structure type into which it points (for some reason).
990 When "smashing" the type, we preserve the objfile that the
991 old type pointed to, since we aren't changing where the type is actually
995 smash_to_member_type (struct type
*type
, struct type
*domain
,
996 struct type
*to_type
)
998 struct objfile
*objfile
;
1000 objfile
= TYPE_OBJFILE (type
);
1003 TYPE_OBJFILE (type
) = objfile
;
1004 TYPE_TARGET_TYPE (type
) = to_type
;
1005 TYPE_DOMAIN_TYPE (type
) = domain
;
1006 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1007 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
1010 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1011 METHOD just means `function that gets an extra "this" argument'.
1013 When "smashing" the type, we preserve the objfile that the
1014 old type pointed to, since we aren't changing where the type is actually
1018 smash_to_method_type (struct type
*type
, struct type
*domain
,
1019 struct type
*to_type
, struct field
*args
,
1020 int nargs
, int varargs
)
1022 struct objfile
*objfile
;
1024 objfile
= TYPE_OBJFILE (type
);
1027 TYPE_OBJFILE (type
) = objfile
;
1028 TYPE_TARGET_TYPE (type
) = to_type
;
1029 TYPE_DOMAIN_TYPE (type
) = domain
;
1030 TYPE_FIELDS (type
) = args
;
1031 TYPE_NFIELDS (type
) = nargs
;
1033 TYPE_FLAGS (type
) |= TYPE_FLAG_VARARGS
;
1034 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1035 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1038 /* Return a typename for a struct/union/enum type without "struct ",
1039 "union ", or "enum ". If the type has a NULL name, return NULL. */
1042 type_name_no_tag (const struct type
*type
)
1044 if (TYPE_TAG_NAME (type
) != NULL
)
1045 return TYPE_TAG_NAME (type
);
1047 /* Is there code which expects this to return the name if there is no
1048 tag name? My guess is that this is mainly used for C++ in cases where
1049 the two will always be the same. */
1050 return TYPE_NAME (type
);
1053 /* Lookup a typedef or primitive type named NAME,
1054 visible in lexical block BLOCK.
1055 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1058 lookup_typename (char *name
, struct block
*block
, int noerr
)
1063 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1064 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1066 tmp
= language_lookup_primitive_type_by_name (current_language
,
1073 else if (!tmp
&& noerr
)
1079 error (_("No type named %s."), name
);
1082 return (SYMBOL_TYPE (sym
));
1086 lookup_unsigned_typename (char *name
)
1088 char *uns
= alloca (strlen (name
) + 10);
1090 strcpy (uns
, "unsigned ");
1091 strcpy (uns
+ 9, name
);
1092 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
1096 lookup_signed_typename (char *name
)
1099 char *uns
= alloca (strlen (name
) + 8);
1101 strcpy (uns
, "signed ");
1102 strcpy (uns
+ 7, name
);
1103 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
1104 /* If we don't find "signed FOO" just try again with plain "FOO". */
1107 return lookup_typename (name
, (struct block
*) NULL
, 0);
1110 /* Lookup a structure type named "struct NAME",
1111 visible in lexical block BLOCK. */
1114 lookup_struct (char *name
, struct block
*block
)
1118 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1119 (struct symtab
**) NULL
);
1123 error (_("No struct type named %s."), name
);
1125 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1127 error (_("This context has class, union or enum %s, not a struct."), name
);
1129 return (SYMBOL_TYPE (sym
));
1132 /* Lookup a union type named "union NAME",
1133 visible in lexical block BLOCK. */
1136 lookup_union (char *name
, struct block
*block
)
1141 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1142 (struct symtab
**) NULL
);
1145 error (_("No union type named %s."), name
);
1147 t
= SYMBOL_TYPE (sym
);
1149 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1152 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1153 * a further "declared_type" field to discover it is really a union.
1155 if (HAVE_CPLUS_STRUCT (t
))
1156 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1159 /* If we get here, it's not a union */
1160 error (_("This context has class, struct or enum %s, not a union."), name
);
1164 /* Lookup an enum type named "enum NAME",
1165 visible in lexical block BLOCK. */
1168 lookup_enum (char *name
, struct block
*block
)
1172 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1173 (struct symtab
**) NULL
);
1176 error (_("No enum type named %s."), name
);
1178 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1180 error (_("This context has class, struct or union %s, not an enum."), name
);
1182 return (SYMBOL_TYPE (sym
));
1185 /* Lookup a template type named "template NAME<TYPE>",
1186 visible in lexical block BLOCK. */
1189 lookup_template_type (char *name
, struct type
*type
, struct block
*block
)
1192 char *nam
= (char *) alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1195 strcat (nam
, TYPE_NAME (type
));
1196 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1198 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1202 error (_("No template type named %s."), name
);
1204 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1206 error (_("This context has class, union or enum %s, not a struct."), name
);
1208 return (SYMBOL_TYPE (sym
));
1211 /* Given a type TYPE, lookup the type of the component of type named NAME.
1213 TYPE can be either a struct or union, or a pointer or reference to a struct or
1214 union. If it is a pointer or reference, its target type is automatically used.
1215 Thus '.' and '->' are interchangable, as specified for the definitions of the
1216 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1218 If NOERR is nonzero, return zero if NAME is not suitably defined.
1219 If NAME is the name of a baseclass type, return that type. */
1222 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1228 CHECK_TYPEDEF (type
);
1229 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1230 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1232 type
= TYPE_TARGET_TYPE (type
);
1235 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
1236 TYPE_CODE (type
) != TYPE_CODE_UNION
)
1238 target_terminal_ours ();
1239 gdb_flush (gdb_stdout
);
1240 fprintf_unfiltered (gdb_stderr
, "Type ");
1241 type_print (type
, "", gdb_stderr
, -1);
1242 error (_(" is not a structure or union type."));
1246 /* FIXME: This change put in by Michael seems incorrect for the case where
1247 the structure tag name is the same as the member name. I.E. when doing
1248 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1253 typename
= type_name_no_tag (type
);
1254 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1259 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1261 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1263 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1265 return TYPE_FIELD_TYPE (type
, i
);
1269 /* OK, it's not in this class. Recursively check the baseclasses. */
1270 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1274 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, 1);
1286 target_terminal_ours ();
1287 gdb_flush (gdb_stdout
);
1288 fprintf_unfiltered (gdb_stderr
, "Type ");
1289 type_print (type
, "", gdb_stderr
, -1);
1290 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1291 fputs_filtered (name
, gdb_stderr
);
1293 return (struct type
*) -1; /* For lint */
1296 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1297 valid. Callers should be aware that in some cases (for example,
1298 the type or one of its baseclasses is a stub type and we are
1299 debugging a .o file), this function will not be able to find the virtual
1300 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1301 will remain NULL. */
1304 fill_in_vptr_fieldno (struct type
*type
)
1306 CHECK_TYPEDEF (type
);
1308 if (TYPE_VPTR_FIELDNO (type
) < 0)
1312 /* We must start at zero in case the first (and only) baseclass is
1313 virtual (and hence we cannot share the table pointer). */
1314 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1316 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1317 fill_in_vptr_fieldno (baseclass
);
1318 if (TYPE_VPTR_FIELDNO (baseclass
) >= 0)
1320 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (baseclass
);
1321 TYPE_VPTR_BASETYPE (type
) = TYPE_VPTR_BASETYPE (baseclass
);
1328 /* Find the method and field indices for the destructor in class type T.
1329 Return 1 if the destructor was found, otherwise, return 0. */
1332 get_destructor_fn_field (struct type
*t
, int *method_indexp
, int *field_indexp
)
1336 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1339 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1341 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1343 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1355 stub_noname_complaint (void)
1357 complaint (&symfile_complaints
, _("stub type has NULL name"));
1360 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1362 If this is a stubbed struct (i.e. declared as struct foo *), see if
1363 we can find a full definition in some other file. If so, copy this
1364 definition, so we can use it in future. There used to be a comment (but
1365 not any code) that if we don't find a full definition, we'd set a flag
1366 so we don't spend time in the future checking the same type. That would
1367 be a mistake, though--we might load in more symbols which contain a
1368 full definition for the type.
1370 This used to be coded as a macro, but I don't think it is called
1371 often enough to merit such treatment. */
1373 /* Find the real type of TYPE. This function returns the real type, after
1374 removing all layers of typedefs and completing opaque or stub types.
1375 Completion changes the TYPE argument, but stripping of typedefs does
1379 check_typedef (struct type
*type
)
1381 struct type
*orig_type
= type
;
1382 int is_const
, is_volatile
;
1384 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1386 if (!TYPE_TARGET_TYPE (type
))
1391 /* It is dangerous to call lookup_symbol if we are currently
1392 reading a symtab. Infinite recursion is one danger. */
1393 if (currently_reading_symtab
)
1396 name
= type_name_no_tag (type
);
1397 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1398 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1399 as appropriate? (this code was written before TYPE_NAME and
1400 TYPE_TAG_NAME were separate). */
1403 stub_noname_complaint ();
1406 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0,
1407 (struct symtab
**) NULL
);
1409 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1411 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1413 type
= TYPE_TARGET_TYPE (type
);
1416 is_const
= TYPE_CONST (type
);
1417 is_volatile
= TYPE_VOLATILE (type
);
1419 /* If this is a struct/class/union with no fields, then check whether a
1420 full definition exists somewhere else. This is for systems where a
1421 type definition with no fields is issued for such types, instead of
1422 identifying them as stub types in the first place */
1424 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1426 char *name
= type_name_no_tag (type
);
1427 struct type
*newtype
;
1430 stub_noname_complaint ();
1433 newtype
= lookup_transparent_type (name
);
1437 /* If the resolved type and the stub are in the same objfile,
1438 then replace the stub type with the real deal. But if
1439 they're in separate objfiles, leave the stub alone; we'll
1440 just look up the transparent type every time we call
1441 check_typedef. We can't create pointers between types
1442 allocated to different objfiles, since they may have
1443 different lifetimes. Trying to copy NEWTYPE over to TYPE's
1444 objfile is pointless, too, since you'll have to move over any
1445 other types NEWTYPE refers to, which could be an unbounded
1447 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1448 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1453 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1454 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1456 char *name
= type_name_no_tag (type
);
1457 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1458 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1459 as appropriate? (this code was written before TYPE_NAME and
1460 TYPE_TAG_NAME were separate). */
1464 stub_noname_complaint ();
1467 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0, (struct symtab
**) NULL
);
1469 make_cv_type (is_const
, is_volatile
, SYMBOL_TYPE (sym
), &type
);
1472 if (TYPE_TARGET_STUB (type
))
1474 struct type
*range_type
;
1475 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1477 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1480 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1481 && TYPE_NFIELDS (type
) == 1
1482 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1483 == TYPE_CODE_RANGE
))
1485 /* Now recompute the length of the array type, based on its
1486 number of elements and the target type's length. */
1487 TYPE_LENGTH (type
) =
1488 ((TYPE_FIELD_BITPOS (range_type
, 1)
1489 - TYPE_FIELD_BITPOS (range_type
, 0)
1491 * TYPE_LENGTH (target_type
));
1492 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1494 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1496 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1497 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
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 occurs,
1506 silently return builtin_type_void. */
1508 static struct type
*
1509 safe_parse_type (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_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 string
1532 including argument types, parses out each argument type, generates
1533 a string casting a zero to that type, evaluates the string, and stuffs
1534 the resulting type into an argtype vector!!! Then it knows the type
1535 of the whole function (including argument types for overloading),
1536 which info used to be in the stab's but was removed to hack back
1537 the space required for them. */
1540 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1543 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1544 char *demangled_name
= cplus_demangle (mangled_name
,
1545 DMGL_PARAMS
| DMGL_ANSI
);
1546 char *argtypetext
, *p
;
1547 int depth
= 0, argcount
= 1;
1548 struct field
*argtypes
;
1551 /* Make sure we got back a function string that we can use. */
1553 p
= strchr (demangled_name
, '(');
1557 if (demangled_name
== NULL
|| p
== NULL
)
1558 error (_("Internal: Cannot demangle mangled name `%s'."), mangled_name
);
1560 /* Now, read in the parameters that define this type. */
1565 if (*p
== '(' || *p
== '<')
1569 else if (*p
== ')' || *p
== '>')
1573 else if (*p
== ',' && depth
== 0)
1581 /* If we read one argument and it was ``void'', don't count it. */
1582 if (strncmp (argtypetext
, "(void)", 6) == 0)
1585 /* We need one extra slot, for the THIS pointer. */
1587 argtypes
= (struct field
*)
1588 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1591 /* Add THIS pointer for non-static methods. */
1592 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1593 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1597 argtypes
[0].type
= lookup_pointer_type (type
);
1601 if (*p
!= ')') /* () means no args, skip while */
1606 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1608 /* Avoid parsing of ellipsis, they will be handled below.
1609 Also avoid ``void'' as above. */
1610 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1611 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1613 argtypes
[argcount
].type
=
1614 safe_parse_type (argtypetext
, p
- argtypetext
);
1617 argtypetext
= p
+ 1;
1620 if (*p
== '(' || *p
== '<')
1624 else if (*p
== ')' || *p
== '>')
1633 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1635 /* Now update the old "stub" type into a real type. */
1636 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1637 TYPE_DOMAIN_TYPE (mtype
) = type
;
1638 TYPE_FIELDS (mtype
) = argtypes
;
1639 TYPE_NFIELDS (mtype
) = argcount
;
1640 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1641 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1643 TYPE_FLAGS (mtype
) |= TYPE_FLAG_VARARGS
;
1645 xfree (demangled_name
);
1648 /* This is the external interface to check_stub_method, above. This function
1649 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1650 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1651 and TYPE_FN_FIELDLIST_NAME will be correct.
1653 This function unfortunately can not die until stabs do. */
1656 check_stub_method_group (struct type
*type
, int method_id
)
1658 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1659 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1660 int j
, found_stub
= 0;
1662 for (j
= 0; j
< len
; j
++)
1663 if (TYPE_FN_FIELD_STUB (f
, j
))
1666 check_stub_method (type
, method_id
, j
);
1669 /* GNU v3 methods with incorrect names were corrected when we read in
1670 type information, because it was cheaper to do it then. The only GNU v2
1671 methods with incorrect method names are operators and destructors;
1672 destructors were also corrected when we read in type information.
1674 Therefore the only thing we need to handle here are v2 operator
1676 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1679 char dem_opname
[256];
1681 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1682 dem_opname
, DMGL_ANSI
);
1684 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1687 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1691 const struct cplus_struct_type cplus_struct_default
;
1694 allocate_cplus_struct_type (struct type
*type
)
1696 if (!HAVE_CPLUS_STRUCT (type
))
1698 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1699 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1700 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1704 /* Helper function to initialize the standard scalar types.
1706 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1707 of the string pointed to by name in the objfile_obstack for that objfile,
1708 and initialize the type name to that copy. There are places (mipsread.c
1709 in particular, where init_type is called with a NULL value for NAME). */
1712 init_type (enum type_code code
, int length
, int flags
, char *name
,
1713 struct objfile
*objfile
)
1717 type
= alloc_type (objfile
);
1718 TYPE_CODE (type
) = code
;
1719 TYPE_LENGTH (type
) = length
;
1720 TYPE_FLAGS (type
) |= flags
;
1721 if ((name
!= NULL
) && (objfile
!= NULL
))
1724 obsavestring (name
, strlen (name
), &objfile
->objfile_obstack
);
1728 TYPE_NAME (type
) = name
;
1733 if (name
&& strcmp (name
, "char") == 0)
1734 TYPE_FLAGS (type
) |= TYPE_FLAG_NOSIGN
;
1736 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
1737 || code
== TYPE_CODE_NAMESPACE
)
1739 INIT_CPLUS_SPECIFIC (type
);
1744 /* Helper function. Create an empty composite type. */
1747 init_composite_type (char *name
, enum type_code code
)
1750 gdb_assert (code
== TYPE_CODE_STRUCT
1751 || code
== TYPE_CODE_UNION
);
1752 t
= init_type (code
, 0, 0, NULL
, NULL
);
1753 TYPE_TAG_NAME (t
) = name
;
1757 /* Helper function. Append a field to a composite type. */
1760 append_composite_type_field (struct type
*t
, char *name
, struct type
*field
)
1763 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
1764 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
1765 sizeof (struct field
) * TYPE_NFIELDS (t
));
1766 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
1767 memset (f
, 0, sizeof f
[0]);
1768 FIELD_TYPE (f
[0]) = field
;
1769 FIELD_NAME (f
[0]) = name
;
1770 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1772 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
1773 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
1775 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
1777 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
1778 if (TYPE_NFIELDS (t
) > 1)
1780 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
1781 + TYPE_LENGTH (field
) * TARGET_CHAR_BIT
);
1786 /* Look up a fundamental type for the specified objfile.
1787 May need to construct such a type if this is the first use.
1789 Some object file formats (ELF, COFF, etc) do not define fundamental
1790 types such as "int" or "double". Others (stabs for example), do
1791 define fundamental types.
1793 For the formats which don't provide fundamental types, gdb can create
1794 such types, using defaults reasonable for the current language and
1795 the current target machine.
1797 NOTE: This routine is obsolescent. Each debugging format reader
1798 should manage it's own fundamental types, either creating them from
1799 suitable defaults or reading them from the debugging information,
1800 whichever is appropriate. The DWARF reader has already been
1801 fixed to do this. Once the other readers are fixed, this routine
1802 will go away. Also note that fundamental types should be managed
1803 on a compilation unit basis in a multi-language environment, not
1804 on a linkage unit basis as is done here. */
1808 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1810 struct type
**typep
;
1813 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1815 error (_("internal error - invalid fundamental type id %d"), typeid);
1818 /* If this is the first time we need a fundamental type for this objfile
1819 then we need to initialize the vector of type pointers. */
1821 if (objfile
->fundamental_types
== NULL
)
1823 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1824 objfile
->fundamental_types
= (struct type
**)
1825 obstack_alloc (&objfile
->objfile_obstack
, nbytes
);
1826 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1827 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1830 /* Look for this particular type in the fundamental type vector. If one is
1831 not found, create and install one appropriate for the current language. */
1833 typep
= objfile
->fundamental_types
+ typeid;
1836 *typep
= create_fundamental_type (objfile
, typeid);
1843 can_dereference (struct type
*t
)
1845 /* FIXME: Should we return true for references as well as pointers? */
1849 && TYPE_CODE (t
) == TYPE_CODE_PTR
1850 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1854 is_integral_type (struct type
*t
)
1859 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1860 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1861 || (TYPE_CODE (t
) == TYPE_CODE_FLAGS
)
1862 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1863 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1864 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1867 /* Check whether BASE is an ancestor or base class or DCLASS
1868 Return 1 if so, and 0 if not.
1869 Note: callers may want to check for identity of the types before
1870 calling this function -- identical types are considered to satisfy
1871 the ancestor relationship even if they're identical */
1874 is_ancestor (struct type
*base
, struct type
*dclass
)
1878 CHECK_TYPEDEF (base
);
1879 CHECK_TYPEDEF (dclass
);
1883 if (TYPE_NAME (base
) && TYPE_NAME (dclass
) &&
1884 !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1887 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1888 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1896 /* See whether DCLASS has a virtual table. This routine is aimed at
1897 the HP/Taligent ANSI C++ runtime model, and may not work with other
1898 runtime models. Return 1 => Yes, 0 => No. */
1901 has_vtable (struct type
*dclass
)
1903 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1904 has virtual functions or virtual bases. */
1908 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1911 /* First check for the presence of virtual bases */
1912 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1913 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1914 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
1917 /* Next check for virtual functions */
1918 if (TYPE_FN_FIELDLISTS (dclass
))
1919 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
1920 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
1923 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1924 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1925 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1926 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
1927 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
1930 /* Well, maybe we don't need a virtual table */
1934 /* Return a pointer to the "primary base class" of DCLASS.
1936 A NULL return indicates that DCLASS has no primary base, or that it
1937 couldn't be found (insufficient information).
1939 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1940 and may not work with other runtime models. */
1943 primary_base_class (struct type
*dclass
)
1945 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1946 is the first directly inherited, non-virtual base class that
1947 requires a virtual table */
1951 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1954 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1955 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
1956 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
1957 return TYPE_FIELD_TYPE (dclass
, i
);
1962 /* Global manipulated by virtual_base_list[_aux]() */
1964 static struct vbase
*current_vbase_list
= NULL
;
1966 /* Return a pointer to a null-terminated list of struct vbase
1967 items. The vbasetype pointer of each item in the list points to the
1968 type information for a virtual base of the argument DCLASS.
1970 Helper function for virtual_base_list().
1971 Note: the list goes backward, right-to-left. virtual_base_list()
1972 copies the items out in reverse order. */
1975 virtual_base_list_aux (struct type
*dclass
)
1977 struct vbase
*tmp_vbase
;
1980 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1983 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1985 /* Recurse on this ancestor, first */
1986 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
1988 /* If this current base is itself virtual, add it to the list */
1989 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
1991 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
1993 /* Check if base already recorded */
1994 tmp_vbase
= current_vbase_list
;
1997 if (tmp_vbase
->vbasetype
== basetype
)
1998 break; /* found it */
1999 tmp_vbase
= tmp_vbase
->next
;
2002 if (!tmp_vbase
) /* normal exit from loop */
2004 /* Allocate new item for this virtual base */
2005 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
2007 /* Stick it on at the end of the list */
2008 tmp_vbase
->vbasetype
= basetype
;
2009 tmp_vbase
->next
= current_vbase_list
;
2010 current_vbase_list
= tmp_vbase
;
2013 } /* for loop over bases */
2017 /* Compute the list of virtual bases in the right order. Virtual
2018 bases are laid out in the object's memory area in order of their
2019 occurrence in a depth-first, left-to-right search through the
2022 Argument DCLASS is the type whose virtual bases are required.
2023 Return value is the address of a null-terminated array of pointers
2024 to struct type items.
2026 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2027 and may not work with other runtime models.
2029 This routine merely hands off the argument to virtual_base_list_aux()
2030 and then copies the result into an array to save space. */
2033 virtual_base_list (struct type
*dclass
)
2035 struct vbase
*tmp_vbase
;
2036 struct vbase
*tmp_vbase_2
;
2039 struct type
**vbase_array
;
2041 current_vbase_list
= NULL
;
2042 virtual_base_list_aux (dclass
);
2044 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2049 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
2051 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
2052 vbase_array
[i
] = tmp_vbase
->vbasetype
;
2054 /* Get rid of constructed chain */
2055 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
2058 tmp_vbase
= tmp_vbase
->next
;
2059 xfree (tmp_vbase_2
);
2060 tmp_vbase_2
= tmp_vbase
;
2063 vbase_array
[count
] = NULL
;
2067 /* Return the length of the virtual base list of the type DCLASS. */
2070 virtual_base_list_length (struct type
*dclass
)
2073 struct vbase
*tmp_vbase
;
2075 current_vbase_list
= NULL
;
2076 virtual_base_list_aux (dclass
);
2078 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2083 /* Return the number of elements of the virtual base list of the type
2084 DCLASS, ignoring those appearing in the primary base (and its
2085 primary base, recursively). */
2088 virtual_base_list_length_skip_primaries (struct type
*dclass
)
2091 struct vbase
*tmp_vbase
;
2092 struct type
*primary
;
2094 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2097 return virtual_base_list_length (dclass
);
2099 current_vbase_list
= NULL
;
2100 virtual_base_list_aux (dclass
);
2102 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
2104 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
2112 /* Return the index (position) of type BASE, which is a virtual base
2113 class of DCLASS, in the latter's virtual base list. A return of -1
2114 indicates "not found" or a problem. */
2117 virtual_base_index (struct type
*base
, struct type
*dclass
)
2122 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2123 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2127 vbase
= virtual_base_list (dclass
)[0];
2132 vbase
= virtual_base_list (dclass
)[++i
];
2135 return vbase
? i
: -1;
2140 /* Return the index (position) of type BASE, which is a virtual base
2141 class of DCLASS, in the latter's virtual base list. Skip over all
2142 bases that may appear in the virtual base list of the primary base
2143 class of DCLASS (recursively). A return of -1 indicates "not
2144 found" or a problem. */
2147 virtual_base_index_skip_primaries (struct type
*base
, struct type
*dclass
)
2151 struct type
*primary
;
2153 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2154 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2157 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2161 vbase
= virtual_base_list (dclass
)[0];
2164 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
2168 vbase
= virtual_base_list (dclass
)[++i
];
2171 return vbase
? j
: -1;
2174 /* Return position of a derived class DCLASS in the list of
2175 * primary bases starting with the remotest ancestor.
2176 * Position returned is 0-based. */
2179 class_index_in_primary_list (struct type
*dclass
)
2181 struct type
*pbc
; /* primary base class */
2183 /* Simply recurse on primary base */
2184 pbc
= TYPE_PRIMARY_BASE (dclass
);
2186 return 1 + class_index_in_primary_list (pbc
);
2191 /* Return a count of the number of virtual functions a type has.
2192 * This includes all the virtual functions it inherits from its
2196 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2197 * functions only once (latest redefinition)
2201 count_virtual_fns (struct type
*dclass
)
2203 int fn
, oi
; /* function and overloaded instance indices */
2204 int vfuncs
; /* count to return */
2206 /* recurse on bases that can share virtual table */
2207 struct type
*pbc
= primary_base_class (dclass
);
2209 vfuncs
= count_virtual_fns (pbc
);
2213 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2214 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2215 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2223 /* Functions for overload resolution begin here */
2225 /* Compare two badness vectors A and B and return the result.
2226 * 0 => A and B are identical
2227 * 1 => A and B are incomparable
2228 * 2 => A is better than B
2229 * 3 => A is worse than B */
2232 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2236 short found_pos
= 0; /* any positives in c? */
2237 short found_neg
= 0; /* any negatives in c? */
2239 /* differing lengths => incomparable */
2240 if (a
->length
!= b
->length
)
2243 /* Subtract b from a */
2244 for (i
= 0; i
< a
->length
; i
++)
2246 tmp
= a
->rank
[i
] - b
->rank
[i
];
2256 return 1; /* incomparable */
2258 return 3; /* A > B */
2264 return 2; /* A < B */
2266 return 0; /* A == B */
2270 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2271 * to the types of an argument list (ARGS, length NARGS).
2272 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2274 struct badness_vector
*
2275 rank_function (struct type
**parms
, int nparms
, struct type
**args
, int nargs
)
2278 struct badness_vector
*bv
;
2279 int min_len
= nparms
< nargs
? nparms
: nargs
;
2281 bv
= xmalloc (sizeof (struct badness_vector
));
2282 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2283 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2285 /* First compare the lengths of the supplied lists.
2286 * If there is a mismatch, set it to a high value. */
2288 /* pai/1997-06-03 FIXME: when we have debug info about default
2289 * arguments and ellipsis parameter lists, we should consider those
2290 * and rank the length-match more finely. */
2292 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2294 /* Now rank all the parameters of the candidate function */
2295 for (i
= 1; i
<= min_len
; i
++)
2296 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2298 /* If more arguments than parameters, add dummy entries */
2299 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2300 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2305 /* Compare the names of two integer types, assuming that any sign
2306 qualifiers have been checked already. We do it this way because
2307 there may be an "int" in the name of one of the types. */
2310 integer_types_same_name_p (const char *first
, const char *second
)
2312 int first_p
, second_p
;
2314 /* If both are shorts, return 1; if neither is a short, keep checking. */
2315 first_p
= (strstr (first
, "short") != NULL
);
2316 second_p
= (strstr (second
, "short") != NULL
);
2317 if (first_p
&& second_p
)
2319 if (first_p
|| second_p
)
2322 /* Likewise for long. */
2323 first_p
= (strstr (first
, "long") != NULL
);
2324 second_p
= (strstr (second
, "long") != NULL
);
2325 if (first_p
&& second_p
)
2327 if (first_p
|| second_p
)
2330 /* Likewise for char. */
2331 first_p
= (strstr (first
, "char") != NULL
);
2332 second_p
= (strstr (second
, "char") != NULL
);
2333 if (first_p
&& second_p
)
2335 if (first_p
|| second_p
)
2338 /* They must both be ints. */
2342 /* Compare one type (PARM) for compatibility with another (ARG).
2343 * PARM is intended to be the parameter type of a function; and
2344 * ARG is the supplied argument's type. This function tests if
2345 * the latter can be converted to the former.
2347 * Return 0 if they are identical types;
2348 * Otherwise, return an integer which corresponds to how compatible
2349 * PARM is to ARG. The higher the return value, the worse the match.
2350 * Generally the "bad" conversions are all uniformly assigned a 100 */
2353 rank_one_type (struct type
*parm
, struct type
*arg
)
2355 /* Identical type pointers */
2356 /* However, this still doesn't catch all cases of same type for arg
2357 * and param. The reason is that builtin types are different from
2358 * the same ones constructed from the object. */
2362 /* Resolve typedefs */
2363 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2364 parm
= check_typedef (parm
);
2365 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2366 arg
= check_typedef (arg
);
2369 Well, damnit, if the names are exactly the same,
2370 i'll say they are exactly the same. This happens when we generate
2371 method stubs. The types won't point to the same address, but they
2372 really are the same.
2375 if (TYPE_NAME (parm
) && TYPE_NAME (arg
) &&
2376 !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2379 /* Check if identical after resolving typedefs */
2383 /* See through references, since we can almost make non-references
2385 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2386 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2387 + REFERENCE_CONVERSION_BADNESS
);
2388 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2389 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2390 + REFERENCE_CONVERSION_BADNESS
);
2392 /* Debugging only. */
2393 fprintf_filtered (gdb_stderr
,"------ Arg is %s [%d], parm is %s [%d]\n",
2394 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2396 /* x -> y means arg of type x being supplied for parameter of type y */
2398 switch (TYPE_CODE (parm
))
2401 switch (TYPE_CODE (arg
))
2404 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2405 return VOID_PTR_CONVERSION_BADNESS
;
2407 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2408 case TYPE_CODE_ARRAY
:
2409 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2410 case TYPE_CODE_FUNC
:
2411 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2413 case TYPE_CODE_ENUM
:
2414 case TYPE_CODE_FLAGS
:
2415 case TYPE_CODE_CHAR
:
2416 case TYPE_CODE_RANGE
:
2417 case TYPE_CODE_BOOL
:
2418 return POINTER_CONVERSION_BADNESS
;
2420 return INCOMPATIBLE_TYPE_BADNESS
;
2422 case TYPE_CODE_ARRAY
:
2423 switch (TYPE_CODE (arg
))
2426 case TYPE_CODE_ARRAY
:
2427 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2429 return INCOMPATIBLE_TYPE_BADNESS
;
2431 case TYPE_CODE_FUNC
:
2432 switch (TYPE_CODE (arg
))
2434 case TYPE_CODE_PTR
: /* funcptr -> func */
2435 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2437 return INCOMPATIBLE_TYPE_BADNESS
;
2440 switch (TYPE_CODE (arg
))
2443 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2445 /* Deal with signed, unsigned, and plain chars and
2446 signed and unsigned ints */
2447 if (TYPE_NOSIGN (parm
))
2449 /* This case only for character types */
2450 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2453 return INTEGER_CONVERSION_BADNESS
; /* signed/unsigned char -> plain char */
2455 else if (TYPE_UNSIGNED (parm
))
2457 if (TYPE_UNSIGNED (arg
))
2459 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2460 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2462 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2463 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2464 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2466 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2470 if (integer_types_same_name_p (TYPE_NAME (arg
), "long")
2471 && integer_types_same_name_p (TYPE_NAME (parm
), "int"))
2472 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2474 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2477 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2479 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2481 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2482 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2483 return INTEGER_PROMOTION_BADNESS
;
2485 return INTEGER_CONVERSION_BADNESS
;
2488 return INTEGER_CONVERSION_BADNESS
;
2490 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2491 return INTEGER_PROMOTION_BADNESS
;
2493 return INTEGER_CONVERSION_BADNESS
;
2494 case TYPE_CODE_ENUM
:
2495 case TYPE_CODE_FLAGS
:
2496 case TYPE_CODE_CHAR
:
2497 case TYPE_CODE_RANGE
:
2498 case TYPE_CODE_BOOL
:
2499 return INTEGER_PROMOTION_BADNESS
;
2501 return INT_FLOAT_CONVERSION_BADNESS
;
2503 return NS_POINTER_CONVERSION_BADNESS
;
2505 return INCOMPATIBLE_TYPE_BADNESS
;
2508 case TYPE_CODE_ENUM
:
2509 switch (TYPE_CODE (arg
))
2512 case TYPE_CODE_CHAR
:
2513 case TYPE_CODE_RANGE
:
2514 case TYPE_CODE_BOOL
:
2515 case TYPE_CODE_ENUM
:
2516 return INTEGER_CONVERSION_BADNESS
;
2518 return INT_FLOAT_CONVERSION_BADNESS
;
2520 return INCOMPATIBLE_TYPE_BADNESS
;
2523 case TYPE_CODE_CHAR
:
2524 switch (TYPE_CODE (arg
))
2526 case TYPE_CODE_RANGE
:
2527 case TYPE_CODE_BOOL
:
2528 case TYPE_CODE_ENUM
:
2529 return INTEGER_CONVERSION_BADNESS
;
2531 return INT_FLOAT_CONVERSION_BADNESS
;
2533 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2534 return INTEGER_CONVERSION_BADNESS
;
2535 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2536 return INTEGER_PROMOTION_BADNESS
;
2537 /* >>> !! else fall through !! <<< */
2538 case TYPE_CODE_CHAR
:
2539 /* Deal with signed, unsigned, and plain chars for C++
2540 and with int cases falling through from previous case */
2541 if (TYPE_NOSIGN (parm
))
2543 if (TYPE_NOSIGN (arg
))
2546 return INTEGER_CONVERSION_BADNESS
;
2548 else if (TYPE_UNSIGNED (parm
))
2550 if (TYPE_UNSIGNED (arg
))
2553 return INTEGER_PROMOTION_BADNESS
;
2555 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2558 return INTEGER_CONVERSION_BADNESS
;
2560 return INCOMPATIBLE_TYPE_BADNESS
;
2563 case TYPE_CODE_RANGE
:
2564 switch (TYPE_CODE (arg
))
2567 case TYPE_CODE_CHAR
:
2568 case TYPE_CODE_RANGE
:
2569 case TYPE_CODE_BOOL
:
2570 case TYPE_CODE_ENUM
:
2571 return INTEGER_CONVERSION_BADNESS
;
2573 return INT_FLOAT_CONVERSION_BADNESS
;
2575 return INCOMPATIBLE_TYPE_BADNESS
;
2578 case TYPE_CODE_BOOL
:
2579 switch (TYPE_CODE (arg
))
2582 case TYPE_CODE_CHAR
:
2583 case TYPE_CODE_RANGE
:
2584 case TYPE_CODE_ENUM
:
2587 return BOOLEAN_CONVERSION_BADNESS
;
2588 case TYPE_CODE_BOOL
:
2591 return INCOMPATIBLE_TYPE_BADNESS
;
2595 switch (TYPE_CODE (arg
))
2598 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2599 return FLOAT_PROMOTION_BADNESS
;
2600 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2603 return FLOAT_CONVERSION_BADNESS
;
2605 case TYPE_CODE_BOOL
:
2606 case TYPE_CODE_ENUM
:
2607 case TYPE_CODE_RANGE
:
2608 case TYPE_CODE_CHAR
:
2609 return INT_FLOAT_CONVERSION_BADNESS
;
2611 return INCOMPATIBLE_TYPE_BADNESS
;
2614 case TYPE_CODE_COMPLEX
:
2615 switch (TYPE_CODE (arg
))
2616 { /* Strictly not needed for C++, but... */
2618 return FLOAT_PROMOTION_BADNESS
;
2619 case TYPE_CODE_COMPLEX
:
2622 return INCOMPATIBLE_TYPE_BADNESS
;
2625 case TYPE_CODE_STRUCT
:
2626 /* currently same as TYPE_CODE_CLASS */
2627 switch (TYPE_CODE (arg
))
2629 case TYPE_CODE_STRUCT
:
2630 /* Check for derivation */
2631 if (is_ancestor (parm
, arg
))
2632 return BASE_CONVERSION_BADNESS
;
2633 /* else fall through */
2635 return INCOMPATIBLE_TYPE_BADNESS
;
2638 case TYPE_CODE_UNION
:
2639 switch (TYPE_CODE (arg
))
2641 case TYPE_CODE_UNION
:
2643 return INCOMPATIBLE_TYPE_BADNESS
;
2646 case TYPE_CODE_MEMBER
:
2647 switch (TYPE_CODE (arg
))
2650 return INCOMPATIBLE_TYPE_BADNESS
;
2653 case TYPE_CODE_METHOD
:
2654 switch (TYPE_CODE (arg
))
2658 return INCOMPATIBLE_TYPE_BADNESS
;
2662 switch (TYPE_CODE (arg
))
2666 return INCOMPATIBLE_TYPE_BADNESS
;
2671 switch (TYPE_CODE (arg
))
2675 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2677 return INCOMPATIBLE_TYPE_BADNESS
;
2680 case TYPE_CODE_VOID
:
2682 return INCOMPATIBLE_TYPE_BADNESS
;
2683 } /* switch (TYPE_CODE (arg)) */
2687 /* End of functions for overload resolution */
2690 print_bit_vector (B_TYPE
*bits
, int nbits
)
2694 for (bitno
= 0; bitno
< nbits
; bitno
++)
2696 if ((bitno
% 8) == 0)
2698 puts_filtered (" ");
2700 if (B_TST (bits
, bitno
))
2701 printf_filtered (("1"));
2703 printf_filtered (("0"));
2707 /* Note the first arg should be the "this" pointer, we may not want to
2708 include it since we may get into a infinitely recursive situation. */
2711 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2717 for (i
= 0; i
< nargs
; i
++)
2718 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2723 dump_fn_fieldlists (struct type
*type
, int spaces
)
2729 printfi_filtered (spaces
, "fn_fieldlists ");
2730 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2731 printf_filtered ("\n");
2732 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2734 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2735 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2737 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2738 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2740 printf_filtered (_(") length %d\n"),
2741 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2742 for (overload_idx
= 0;
2743 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2746 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2748 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2749 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2751 printf_filtered (")\n");
2752 printfi_filtered (spaces
+ 8, "type ");
2753 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2754 printf_filtered ("\n");
2756 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2759 printfi_filtered (spaces
+ 8, "args ");
2760 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2761 printf_filtered ("\n");
2763 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2764 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
, overload_idx
)),
2766 printfi_filtered (spaces
+ 8, "fcontext ");
2767 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2769 printf_filtered ("\n");
2771 printfi_filtered (spaces
+ 8, "is_const %d\n",
2772 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2773 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2774 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2775 printfi_filtered (spaces
+ 8, "is_private %d\n",
2776 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2777 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2778 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2779 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2780 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2781 printfi_filtered (spaces
+ 8, "voffset %u\n",
2782 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2788 print_cplus_stuff (struct type
*type
, int spaces
)
2790 printfi_filtered (spaces
, "n_baseclasses %d\n",
2791 TYPE_N_BASECLASSES (type
));
2792 printfi_filtered (spaces
, "nfn_fields %d\n",
2793 TYPE_NFN_FIELDS (type
));
2794 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2795 TYPE_NFN_FIELDS_TOTAL (type
));
2796 if (TYPE_N_BASECLASSES (type
) > 0)
2798 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2799 TYPE_N_BASECLASSES (type
));
2800 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2801 printf_filtered (")");
2803 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2804 TYPE_N_BASECLASSES (type
));
2805 puts_filtered ("\n");
2807 if (TYPE_NFIELDS (type
) > 0)
2809 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2811 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2812 TYPE_NFIELDS (type
));
2813 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2814 printf_filtered (")");
2815 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2816 TYPE_NFIELDS (type
));
2817 puts_filtered ("\n");
2819 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2821 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2822 TYPE_NFIELDS (type
));
2823 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2824 printf_filtered (")");
2825 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2826 TYPE_NFIELDS (type
));
2827 puts_filtered ("\n");
2830 if (TYPE_NFN_FIELDS (type
) > 0)
2832 dump_fn_fieldlists (type
, spaces
);
2837 print_bound_type (int bt
)
2841 case BOUND_CANNOT_BE_DETERMINED
:
2842 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2844 case BOUND_BY_REF_ON_STACK
:
2845 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2847 case BOUND_BY_VALUE_ON_STACK
:
2848 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2850 case BOUND_BY_REF_IN_REG
:
2851 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2853 case BOUND_BY_VALUE_IN_REG
:
2854 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2857 printf_filtered ("(BOUND_SIMPLE)");
2860 printf_filtered (_("(unknown bound type)"));
2865 static struct obstack dont_print_type_obstack
;
2868 recursive_dump_type (struct type
*type
, int spaces
)
2873 obstack_begin (&dont_print_type_obstack
, 0);
2875 if (TYPE_NFIELDS (type
) > 0
2876 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2878 struct type
**first_dont_print
2879 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2881 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
2886 if (type
== first_dont_print
[i
])
2888 printfi_filtered (spaces
, "type node ");
2889 gdb_print_host_address (type
, gdb_stdout
);
2890 printf_filtered (_(" <same as already seen type>\n"));
2895 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2898 printfi_filtered (spaces
, "type node ");
2899 gdb_print_host_address (type
, gdb_stdout
);
2900 printf_filtered ("\n");
2901 printfi_filtered (spaces
, "name '%s' (",
2902 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2903 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2904 printf_filtered (")\n");
2905 printfi_filtered (spaces
, "tagname '%s' (",
2906 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2907 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2908 printf_filtered (")\n");
2909 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2910 switch (TYPE_CODE (type
))
2912 case TYPE_CODE_UNDEF
:
2913 printf_filtered ("(TYPE_CODE_UNDEF)");
2916 printf_filtered ("(TYPE_CODE_PTR)");
2918 case TYPE_CODE_ARRAY
:
2919 printf_filtered ("(TYPE_CODE_ARRAY)");
2921 case TYPE_CODE_STRUCT
:
2922 printf_filtered ("(TYPE_CODE_STRUCT)");
2924 case TYPE_CODE_UNION
:
2925 printf_filtered ("(TYPE_CODE_UNION)");
2927 case TYPE_CODE_ENUM
:
2928 printf_filtered ("(TYPE_CODE_ENUM)");
2930 case TYPE_CODE_FLAGS
:
2931 printf_filtered ("(TYPE_CODE_FLAGS)");
2933 case TYPE_CODE_FUNC
:
2934 printf_filtered ("(TYPE_CODE_FUNC)");
2937 printf_filtered ("(TYPE_CODE_INT)");
2940 printf_filtered ("(TYPE_CODE_FLT)");
2942 case TYPE_CODE_VOID
:
2943 printf_filtered ("(TYPE_CODE_VOID)");
2946 printf_filtered ("(TYPE_CODE_SET)");
2948 case TYPE_CODE_RANGE
:
2949 printf_filtered ("(TYPE_CODE_RANGE)");
2951 case TYPE_CODE_STRING
:
2952 printf_filtered ("(TYPE_CODE_STRING)");
2954 case TYPE_CODE_BITSTRING
:
2955 printf_filtered ("(TYPE_CODE_BITSTRING)");
2957 case TYPE_CODE_ERROR
:
2958 printf_filtered ("(TYPE_CODE_ERROR)");
2960 case TYPE_CODE_MEMBER
:
2961 printf_filtered ("(TYPE_CODE_MEMBER)");
2963 case TYPE_CODE_METHOD
:
2964 printf_filtered ("(TYPE_CODE_METHOD)");
2967 printf_filtered ("(TYPE_CODE_REF)");
2969 case TYPE_CODE_CHAR
:
2970 printf_filtered ("(TYPE_CODE_CHAR)");
2972 case TYPE_CODE_BOOL
:
2973 printf_filtered ("(TYPE_CODE_BOOL)");
2975 case TYPE_CODE_COMPLEX
:
2976 printf_filtered ("(TYPE_CODE_COMPLEX)");
2978 case TYPE_CODE_TYPEDEF
:
2979 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2981 case TYPE_CODE_TEMPLATE
:
2982 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2984 case TYPE_CODE_TEMPLATE_ARG
:
2985 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2987 case TYPE_CODE_NAMESPACE
:
2988 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2991 printf_filtered ("(UNKNOWN TYPE CODE)");
2994 puts_filtered ("\n");
2995 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2996 printfi_filtered (spaces
, "upper_bound_type 0x%x ",
2997 TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
2998 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
2999 puts_filtered ("\n");
3000 printfi_filtered (spaces
, "lower_bound_type 0x%x ",
3001 TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3002 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3003 puts_filtered ("\n");
3004 printfi_filtered (spaces
, "objfile ");
3005 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
3006 printf_filtered ("\n");
3007 printfi_filtered (spaces
, "target_type ");
3008 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
3009 printf_filtered ("\n");
3010 if (TYPE_TARGET_TYPE (type
) != NULL
)
3012 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
3014 printfi_filtered (spaces
, "pointer_type ");
3015 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
3016 printf_filtered ("\n");
3017 printfi_filtered (spaces
, "reference_type ");
3018 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
3019 printf_filtered ("\n");
3020 printfi_filtered (spaces
, "type_chain ");
3021 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
3022 printf_filtered ("\n");
3023 printfi_filtered (spaces
, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type
));
3024 if (TYPE_CONST (type
))
3026 puts_filtered (" TYPE_FLAG_CONST");
3028 if (TYPE_VOLATILE (type
))
3030 puts_filtered (" TYPE_FLAG_VOLATILE");
3032 if (TYPE_CODE_SPACE (type
))
3034 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3036 if (TYPE_DATA_SPACE (type
))
3038 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3040 if (TYPE_ADDRESS_CLASS_1 (type
))
3042 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3044 if (TYPE_ADDRESS_CLASS_2 (type
))
3046 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3048 puts_filtered ("\n");
3049 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
3050 if (TYPE_UNSIGNED (type
))
3052 puts_filtered (" TYPE_FLAG_UNSIGNED");
3054 if (TYPE_NOSIGN (type
))
3056 puts_filtered (" TYPE_FLAG_NOSIGN");
3058 if (TYPE_STUB (type
))
3060 puts_filtered (" TYPE_FLAG_STUB");
3062 if (TYPE_TARGET_STUB (type
))
3064 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3066 if (TYPE_STATIC (type
))
3068 puts_filtered (" TYPE_FLAG_STATIC");
3070 if (TYPE_PROTOTYPED (type
))
3072 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3074 if (TYPE_INCOMPLETE (type
))
3076 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3078 if (TYPE_VARARGS (type
))
3080 puts_filtered (" TYPE_FLAG_VARARGS");
3082 /* This is used for things like AltiVec registers on ppc. Gcc emits
3083 an attribute for the array type, which tells whether or not we
3084 have a vector, instead of a regular array. */
3085 if (TYPE_VECTOR (type
))
3087 puts_filtered (" TYPE_FLAG_VECTOR");
3089 puts_filtered ("\n");
3090 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
3091 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
3092 puts_filtered ("\n");
3093 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
3095 printfi_filtered (spaces
+ 2,
3096 "[%d] bitpos %d bitsize %d type ",
3097 idx
, TYPE_FIELD_BITPOS (type
, idx
),
3098 TYPE_FIELD_BITSIZE (type
, idx
));
3099 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
3100 printf_filtered (" name '%s' (",
3101 TYPE_FIELD_NAME (type
, idx
) != NULL
3102 ? TYPE_FIELD_NAME (type
, idx
)
3104 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
3105 printf_filtered (")\n");
3106 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
3108 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
3111 printfi_filtered (spaces
, "vptr_basetype ");
3112 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
3113 puts_filtered ("\n");
3114 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
3116 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
3118 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
3119 switch (TYPE_CODE (type
))
3121 case TYPE_CODE_STRUCT
:
3122 printfi_filtered (spaces
, "cplus_stuff ");
3123 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3124 puts_filtered ("\n");
3125 print_cplus_stuff (type
, spaces
);
3129 printfi_filtered (spaces
, "floatformat ");
3130 if (TYPE_FLOATFORMAT (type
) == NULL
3131 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
3132 puts_filtered ("(null)");
3134 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
3135 puts_filtered ("\n");
3139 /* We have to pick one of the union types to be able print and test
3140 the value. Pick cplus_struct_type, even though we know it isn't
3141 any particular one. */
3142 printfi_filtered (spaces
, "type_specific ");
3143 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3144 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
3146 printf_filtered (_(" (unknown data form)"));
3148 printf_filtered ("\n");
3153 obstack_free (&dont_print_type_obstack
, NULL
);
3156 /* Trivial helpers for the libiberty hash table, for mapping one
3161 struct type
*old
, *new;
3165 type_pair_hash (const void *item
)
3167 const struct type_pair
*pair
= item
;
3168 return htab_hash_pointer (pair
->old
);
3172 type_pair_eq (const void *item_lhs
, const void *item_rhs
)
3174 const struct type_pair
*lhs
= item_lhs
, *rhs
= item_rhs
;
3175 return lhs
->old
== rhs
->old
;
3178 /* Allocate the hash table used by copy_type_recursive to walk
3179 types without duplicates. We use OBJFILE's obstack, because
3180 OBJFILE is about to be deleted. */
3183 create_copied_types_hash (struct objfile
*objfile
)
3185 return htab_create_alloc_ex (1, type_pair_hash
, type_pair_eq
,
3186 NULL
, &objfile
->objfile_obstack
,
3187 hashtab_obstack_allocate
,
3188 dummy_obstack_deallocate
);
3191 /* Recursively copy (deep copy) TYPE, if it is associated with OBJFILE.
3192 Return a new type allocated using malloc, a saved type if we have already
3193 visited TYPE (using COPIED_TYPES), or TYPE if it is not associated with
3197 copy_type_recursive (struct objfile
*objfile
, struct type
*type
,
3198 htab_t copied_types
)
3200 struct type_pair
*stored
, pair
;
3202 struct type
*new_type
;
3204 if (TYPE_OBJFILE (type
) == NULL
)
3207 /* This type shouldn't be pointing to any types in other objfiles; if
3208 it did, the type might disappear unexpectedly. */
3209 gdb_assert (TYPE_OBJFILE (type
) == objfile
);
3212 slot
= htab_find_slot (copied_types
, &pair
, INSERT
);
3214 return ((struct type_pair
*) *slot
)->new;
3216 new_type
= alloc_type (NULL
);
3218 /* We must add the new type to the hash table immediately, in case
3219 we encounter this type again during a recursive call below. */
3220 stored
= xmalloc (sizeof (struct type_pair
));
3222 stored
->new = new_type
;
3225 /* Copy the common fields of types. */
3226 TYPE_CODE (new_type
) = TYPE_CODE (type
);
3227 TYPE_ARRAY_UPPER_BOUND_TYPE (new_type
) = TYPE_ARRAY_UPPER_BOUND_TYPE (type
);
3228 TYPE_ARRAY_LOWER_BOUND_TYPE (new_type
) = TYPE_ARRAY_LOWER_BOUND_TYPE (type
);
3229 if (TYPE_NAME (type
))
3230 TYPE_NAME (new_type
) = xstrdup (TYPE_NAME (type
));
3231 if (TYPE_TAG_NAME (type
))
3232 TYPE_TAG_NAME (new_type
) = xstrdup (TYPE_TAG_NAME (type
));
3233 TYPE_FLAGS (new_type
) = TYPE_FLAGS (type
);
3234 TYPE_VPTR_FIELDNO (new_type
) = TYPE_VPTR_FIELDNO (type
);
3236 TYPE_INSTANCE_FLAGS (new_type
) = TYPE_INSTANCE_FLAGS (type
);
3237 TYPE_LENGTH (new_type
) = TYPE_LENGTH (type
);
3239 /* Copy the fields. */
3240 TYPE_NFIELDS (new_type
) = TYPE_NFIELDS (type
);
3241 if (TYPE_NFIELDS (type
))
3245 nfields
= TYPE_NFIELDS (type
);
3246 TYPE_FIELDS (new_type
) = xmalloc (sizeof (struct field
) * nfields
);
3247 for (i
= 0; i
< nfields
; i
++)
3249 TYPE_FIELD_ARTIFICIAL (new_type
, i
) = TYPE_FIELD_ARTIFICIAL (type
, i
);
3250 TYPE_FIELD_BITSIZE (new_type
, i
) = TYPE_FIELD_BITSIZE (type
, i
);
3251 if (TYPE_FIELD_TYPE (type
, i
))
3252 TYPE_FIELD_TYPE (new_type
, i
)
3253 = copy_type_recursive (objfile
, TYPE_FIELD_TYPE (type
, i
),
3255 if (TYPE_FIELD_NAME (type
, i
))
3256 TYPE_FIELD_NAME (new_type
, i
) = xstrdup (TYPE_FIELD_NAME (type
, i
));
3257 if (TYPE_FIELD_STATIC_HAS_ADDR (type
, i
))
3258 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type
, i
),
3259 TYPE_FIELD_STATIC_PHYSADDR (type
, i
));
3260 else if (TYPE_FIELD_STATIC (type
, i
))
3261 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type
, i
),
3262 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type
, i
)));
3265 TYPE_FIELD_BITPOS (new_type
, i
) = TYPE_FIELD_BITPOS (type
, i
);
3266 TYPE_FIELD_STATIC_KIND (new_type
, i
) = 0;
3271 /* Copy pointers to other types. */
3272 if (TYPE_TARGET_TYPE (type
))
3273 TYPE_TARGET_TYPE (new_type
) = copy_type_recursive (objfile
,
3274 TYPE_TARGET_TYPE (type
),
3276 if (TYPE_VPTR_BASETYPE (type
))
3277 TYPE_VPTR_BASETYPE (new_type
) = copy_type_recursive (objfile
,
3278 TYPE_VPTR_BASETYPE (type
),
3280 /* Maybe copy the type_specific bits.
3282 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3283 base classes and methods. There's no fundamental reason why we
3284 can't, but at the moment it is not needed. */
3286 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
3287 TYPE_FLOATFORMAT (new_type
) == TYPE_FLOATFORMAT (type
);
3288 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
3289 || TYPE_CODE (type
) == TYPE_CODE_UNION
3290 || TYPE_CODE (type
) == TYPE_CODE_TEMPLATE
3291 || TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
3292 INIT_CPLUS_SPECIFIC (new_type
);
3298 build_gdbtypes (void)
3301 init_type (TYPE_CODE_VOID
, 1,
3303 "void", (struct objfile
*) NULL
);
3305 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3307 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3308 "char", (struct objfile
*) NULL
);
3309 builtin_type_true_char
=
3310 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3312 "true character", (struct objfile
*) NULL
);
3313 builtin_type_signed_char
=
3314 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3316 "signed char", (struct objfile
*) NULL
);
3317 builtin_type_unsigned_char
=
3318 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3320 "unsigned char", (struct objfile
*) NULL
);
3321 builtin_type_short
=
3322 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3324 "short", (struct objfile
*) NULL
);
3325 builtin_type_unsigned_short
=
3326 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3328 "unsigned short", (struct objfile
*) NULL
);
3330 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3332 "int", (struct objfile
*) NULL
);
3333 builtin_type_unsigned_int
=
3334 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3336 "unsigned int", (struct objfile
*) NULL
);
3338 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3340 "long", (struct objfile
*) NULL
);
3341 builtin_type_unsigned_long
=
3342 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3344 "unsigned long", (struct objfile
*) NULL
);
3345 builtin_type_long_long
=
3346 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3348 "long long", (struct objfile
*) NULL
);
3349 builtin_type_unsigned_long_long
=
3350 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3352 "unsigned long long", (struct objfile
*) NULL
);
3353 builtin_type_float
=
3354 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3356 "float", (struct objfile
*) NULL
);
3357 /* vinschen@redhat.com 2002-02-08:
3358 The below lines are disabled since they are doing the wrong
3359 thing for non-multiarch targets. They are setting the correct
3360 type of floats for the target but while on multiarch targets
3361 this is done everytime the architecture changes, it's done on
3362 non-multiarch targets only on startup, leaving the wrong values
3363 in even if the architecture changes (eg. from big-endian to
3366 TYPE_FLOATFORMAT (builtin_type_float
) = TARGET_FLOAT_FORMAT
;
3368 builtin_type_double
=
3369 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3371 "double", (struct objfile
*) NULL
);
3373 TYPE_FLOATFORMAT (builtin_type_double
) = TARGET_DOUBLE_FORMAT
;
3375 builtin_type_long_double
=
3376 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3378 "long double", (struct objfile
*) NULL
);
3380 TYPE_FLOATFORMAT (builtin_type_long_double
) = TARGET_LONG_DOUBLE_FORMAT
;
3382 builtin_type_complex
=
3383 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3385 "complex", (struct objfile
*) NULL
);
3386 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
3387 builtin_type_double_complex
=
3388 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3390 "double complex", (struct objfile
*) NULL
);
3391 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
3392 builtin_type_string
=
3393 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3395 "string", (struct objfile
*) NULL
);
3397 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3399 "bool", (struct objfile
*) NULL
);
3401 /* Add user knob for controlling resolution of opaque types */
3402 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
3403 &opaque_type_resolution
, _("\
3404 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3405 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL
,
3407 show_opaque_type_resolution
,
3408 &setlist
, &showlist
);
3409 opaque_type_resolution
= 1;
3411 /* Build SIMD types. */
3413 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
3415 = init_simd_type ("__builtin_v4si", builtin_type_int32
, "f", 4);
3417 = init_simd_type ("__builtin_v16qi", builtin_type_int8
, "f", 16);
3419 = init_simd_type ("__builtin_v8qi", builtin_type_int8
, "f", 8);
3421 = init_simd_type ("__builtin_v8hi", builtin_type_int16
, "f", 8);
3423 = init_simd_type ("__builtin_v4hi", builtin_type_int16
, "f", 4);
3425 = init_simd_type ("__builtin_v2si", builtin_type_int32
, "f", 2);
3427 /* 128 bit vectors. */
3428 builtin_type_v2_double
= init_vector_type (builtin_type_double
, 2);
3429 builtin_type_v4_float
= init_vector_type (builtin_type_float
, 4);
3430 builtin_type_v2_int64
= init_vector_type (builtin_type_int64
, 2);
3431 builtin_type_v4_int32
= init_vector_type (builtin_type_int32
, 4);
3432 builtin_type_v8_int16
= init_vector_type (builtin_type_int16
, 8);
3433 builtin_type_v16_int8
= init_vector_type (builtin_type_int8
, 16);
3434 /* 64 bit vectors. */
3435 builtin_type_v2_float
= init_vector_type (builtin_type_float
, 2);
3436 builtin_type_v2_int32
= init_vector_type (builtin_type_int32
, 2);
3437 builtin_type_v4_int16
= init_vector_type (builtin_type_int16
, 4);
3438 builtin_type_v8_int8
= init_vector_type (builtin_type_int8
, 8);
3441 builtin_type_vec64
= build_builtin_type_vec64 ();
3442 builtin_type_vec128
= build_builtin_type_vec128 ();
3444 /* Pointer/Address types. */
3446 /* NOTE: on some targets, addresses and pointers are not necessarily
3447 the same --- for example, on the D10V, pointers are 16 bits long,
3448 but addresses are 32 bits long. See doc/gdbint.texinfo,
3449 ``Pointers Are Not Always Addresses''.
3452 - gdb's `struct type' always describes the target's
3454 - gdb's `struct value' objects should always hold values in
3456 - gdb's CORE_ADDR values are addresses in the unified virtual
3457 address space that the assembler and linker work with. Thus,
3458 since target_read_memory takes a CORE_ADDR as an argument, it
3459 can access any memory on the target, even if the processor has
3460 separate code and data address spaces.
3463 - If v is a value holding a D10V code pointer, its contents are
3464 in target form: a big-endian address left-shifted two bits.
3465 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3466 sizeof (void *) == 2 on the target.
3468 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3469 target type for a value the target will never see. It's only
3470 used to hold the values of (typeless) linker symbols, which are
3471 indeed in the unified virtual address space. */
3472 builtin_type_void_data_ptr
= make_pointer_type (builtin_type_void
, NULL
);
3473 builtin_type_void_func_ptr
3474 = lookup_pointer_type (lookup_function_type (builtin_type_void
));
3475 builtin_type_CORE_ADDR
=
3476 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3478 "__CORE_ADDR", (struct objfile
*) NULL
);
3479 builtin_type_bfd_vma
=
3480 init_type (TYPE_CODE_INT
, TARGET_BFD_VMA_BIT
/ 8,
3482 "__bfd_vma", (struct objfile
*) NULL
);
3485 static struct gdbarch_data
*gdbtypes_data
;
3487 const struct builtin_type
*
3488 builtin_type (struct gdbarch
*gdbarch
)
3490 return gdbarch_data (gdbarch
, gdbtypes_data
);
3494 static struct type
*
3495 build_flt (int bit
, char *name
, const struct floatformat
*floatformat
)
3498 if (bit
<= 0 || floatformat
== NULL
)
3500 gdb_assert (builtin_type_error
!= NULL
);
3501 return builtin_type_error
;
3503 t
= init_type (TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
,
3504 0, name
, (struct objfile
*) NULL
);
3505 TYPE_FLOATFORMAT (t
) = floatformat
;
3509 static struct type
*
3510 build_complex (int bit
, char *name
, struct type
*target_type
)
3513 if (bit
<= 0 || target_type
== builtin_type_error
)
3515 gdb_assert (builtin_type_error
!= NULL
);
3516 return builtin_type_error
;
3518 t
= init_type (TYPE_CODE_COMPLEX
, 2 * bit
/ TARGET_CHAR_BIT
,
3519 0, name
, (struct objfile
*) NULL
);
3520 TYPE_TARGET_TYPE (t
) = target_type
;
3525 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3527 struct builtin_type
*builtin_type
3528 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3530 builtin_type
->builtin_void
=
3531 init_type (TYPE_CODE_VOID
, 1,
3533 "void", (struct objfile
*) NULL
);
3534 builtin_type
->builtin_char
=
3535 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3537 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3538 "char", (struct objfile
*) NULL
);
3539 builtin_type
->builtin_true_char
=
3540 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3542 "true character", (struct objfile
*) NULL
);
3543 builtin_type
->builtin_signed_char
=
3544 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3546 "signed char", (struct objfile
*) NULL
);
3547 builtin_type
->builtin_unsigned_char
=
3548 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3550 "unsigned char", (struct objfile
*) NULL
);
3551 builtin_type
->builtin_short
=
3552 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3554 "short", (struct objfile
*) NULL
);
3555 builtin_type
->builtin_unsigned_short
=
3556 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3558 "unsigned short", (struct objfile
*) NULL
);
3559 builtin_type
->builtin_int
=
3560 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3562 "int", (struct objfile
*) NULL
);
3563 builtin_type
->builtin_unsigned_int
=
3564 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3566 "unsigned int", (struct objfile
*) NULL
);
3567 builtin_type
->builtin_long
=
3568 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3570 "long", (struct objfile
*) NULL
);
3571 builtin_type
->builtin_unsigned_long
=
3572 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3574 "unsigned long", (struct objfile
*) NULL
);
3575 builtin_type
->builtin_long_long
=
3576 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3578 "long long", (struct objfile
*) NULL
);
3579 builtin_type
->builtin_unsigned_long_long
=
3580 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3582 "unsigned long long", (struct objfile
*) NULL
);
3583 builtin_type
->builtin_float
3584 = build_flt (gdbarch_float_bit (gdbarch
), "float",
3585 gdbarch_float_format (gdbarch
));
3586 builtin_type
->builtin_double
3587 = build_flt (gdbarch_double_bit (gdbarch
), "double",
3588 gdbarch_double_format (gdbarch
));
3589 builtin_type
->builtin_long_double
3590 = build_flt (gdbarch_long_double_bit (gdbarch
), "long double",
3591 gdbarch_long_double_format (gdbarch
));
3592 builtin_type
->builtin_complex
3593 = build_complex (gdbarch_float_bit (gdbarch
), "complex",
3594 builtin_type
->builtin_float
);
3595 builtin_type
->builtin_double_complex
3596 = build_complex (gdbarch_double_bit (gdbarch
), "double complex",
3597 builtin_type
->builtin_double
);
3598 builtin_type
->builtin_string
=
3599 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3601 "string", (struct objfile
*) NULL
);
3602 builtin_type
->builtin_bool
=
3603 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3605 "bool", (struct objfile
*) NULL
);
3607 /* Pointer/Address types. */
3609 /* NOTE: on some targets, addresses and pointers are not necessarily
3610 the same --- for example, on the D10V, pointers are 16 bits long,
3611 but addresses are 32 bits long. See doc/gdbint.texinfo,
3612 ``Pointers Are Not Always Addresses''.
3615 - gdb's `struct type' always describes the target's
3617 - gdb's `struct value' objects should always hold values in
3619 - gdb's CORE_ADDR values are addresses in the unified virtual
3620 address space that the assembler and linker work with. Thus,
3621 since target_read_memory takes a CORE_ADDR as an argument, it
3622 can access any memory on the target, even if the processor has
3623 separate code and data address spaces.
3626 - If v is a value holding a D10V code pointer, its contents are
3627 in target form: a big-endian address left-shifted two bits.
3628 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3629 sizeof (void *) == 2 on the target.
3631 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3632 target type for a value the target will never see. It's only
3633 used to hold the values of (typeless) linker symbols, which are
3634 indeed in the unified virtual address space. */
3635 builtin_type
->builtin_data_ptr
3636 = make_pointer_type (builtin_type
->builtin_void
, NULL
);
3637 builtin_type
->builtin_func_ptr
3638 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3639 builtin_type
->builtin_core_addr
=
3640 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3642 "__CORE_ADDR", (struct objfile
*) NULL
);
3644 return builtin_type
;
3647 extern void _initialize_gdbtypes (void);
3649 _initialize_gdbtypes (void)
3651 struct cmd_list_element
*c
;
3654 init_type (TYPE_CODE_INT
, 0 / 8,
3656 "int0_t", (struct objfile
*) NULL
);
3658 init_type (TYPE_CODE_INT
, 8 / 8,
3660 "int8_t", (struct objfile
*) NULL
);
3661 builtin_type_uint8
=
3662 init_type (TYPE_CODE_INT
, 8 / 8,
3664 "uint8_t", (struct objfile
*) NULL
);
3665 builtin_type_int16
=
3666 init_type (TYPE_CODE_INT
, 16 / 8,
3668 "int16_t", (struct objfile
*) NULL
);
3669 builtin_type_uint16
=
3670 init_type (TYPE_CODE_INT
, 16 / 8,
3672 "uint16_t", (struct objfile
*) NULL
);
3673 builtin_type_int32
=
3674 init_type (TYPE_CODE_INT
, 32 / 8,
3676 "int32_t", (struct objfile
*) NULL
);
3677 builtin_type_uint32
=
3678 init_type (TYPE_CODE_INT
, 32 / 8,
3680 "uint32_t", (struct objfile
*) NULL
);
3681 builtin_type_int64
=
3682 init_type (TYPE_CODE_INT
, 64 / 8,
3684 "int64_t", (struct objfile
*) NULL
);
3685 builtin_type_uint64
=
3686 init_type (TYPE_CODE_INT
, 64 / 8,
3688 "uint64_t", (struct objfile
*) NULL
);
3689 builtin_type_int128
=
3690 init_type (TYPE_CODE_INT
, 128 / 8,
3692 "int128_t", (struct objfile
*) NULL
);
3693 builtin_type_uint128
=
3694 init_type (TYPE_CODE_INT
, 128 / 8,
3696 "uint128_t", (struct objfile
*) NULL
);
3700 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
3702 /* FIXME - For the moment, handle types by swapping them in and out.
3703 Should be using the per-architecture data-pointer and a large
3705 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void
);
3706 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char
);
3707 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short
);
3708 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int
);
3709 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long
);
3710 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long
);
3711 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char
);
3712 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char
);
3713 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short
);
3714 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int
);
3715 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long
);
3716 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long
);
3717 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float
);
3718 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double
);
3719 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double
);
3720 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex
);
3721 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex
);
3722 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string
);
3723 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf
);
3724 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si
);
3725 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi
);
3726 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi
);
3727 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi
);
3728 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi
);
3729 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si
);
3730 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double
);
3731 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float
);
3732 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64
);
3733 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32
);
3734 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16
);
3735 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8
);
3736 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float
);
3737 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32
);
3738 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8
);
3739 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16
);
3740 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128
);
3741 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr
);
3742 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr
);
3743 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR
);
3744 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma
);
3745 deprecated_register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
3747 /* Note: These types do not need to be swapped - they are target
3749 builtin_type_ieee_single_big
=
3750 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_big
.totalsize
/ 8,
3751 0, "builtin_type_ieee_single_big", NULL
);
3752 TYPE_FLOATFORMAT (builtin_type_ieee_single_big
) = &floatformat_ieee_single_big
;
3753 builtin_type_ieee_single_little
=
3754 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_little
.totalsize
/ 8,
3755 0, "builtin_type_ieee_single_little", NULL
);
3756 TYPE_FLOATFORMAT (builtin_type_ieee_single_little
) = &floatformat_ieee_single_little
;
3757 builtin_type_ieee_single
[BFD_ENDIAN_BIG
]
3758 = build_flt (floatformat_ieee_single_big
.totalsize
,
3759 "builtin_type_ieee_single_big",
3760 &floatformat_ieee_single_big
);
3761 builtin_type_ieee_single
[BFD_ENDIAN_LITTLE
]
3762 = build_flt (floatformat_ieee_single_little
.totalsize
,
3763 "builtin_type_ieee_single_little",
3764 &floatformat_ieee_single_little
);
3765 builtin_type_ieee_double_big
=
3766 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_big
.totalsize
/ 8,
3767 0, "builtin_type_ieee_double_big", NULL
);
3768 TYPE_FLOATFORMAT (builtin_type_ieee_double_big
) = &floatformat_ieee_double_big
;
3769 builtin_type_ieee_double_little
=
3770 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_little
.totalsize
/ 8,
3771 0, "builtin_type_ieee_double_little", NULL
);
3772 TYPE_FLOATFORMAT (builtin_type_ieee_double_little
) = &floatformat_ieee_double_little
;
3773 builtin_type_ieee_double
[BFD_ENDIAN_BIG
]
3774 = build_flt (floatformat_ieee_double_big
.totalsize
,
3775 "builtin_type_ieee_double_big",
3776 &floatformat_ieee_double_big
);
3777 builtin_type_ieee_double
[BFD_ENDIAN_LITTLE
]
3778 = build_flt (floatformat_ieee_double_little
.totalsize
,
3779 "builtin_type_ieee_double_little",
3780 &floatformat_ieee_double_little
);
3781 builtin_type_ieee_double_littlebyte_bigword
=
3782 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_littlebyte_bigword
.totalsize
/ 8,
3783 0, "builtin_type_ieee_double_littlebyte_bigword", NULL
);
3784 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword
) = &floatformat_ieee_double_littlebyte_bigword
;
3785 builtin_type_i387_ext
=
3786 init_type (TYPE_CODE_FLT
, floatformat_i387_ext
.totalsize
/ 8,
3787 0, "builtin_type_i387_ext", NULL
);
3788 TYPE_FLOATFORMAT (builtin_type_i387_ext
) = &floatformat_i387_ext
;
3789 builtin_type_m68881_ext
=
3790 init_type (TYPE_CODE_FLT
, floatformat_m68881_ext
.totalsize
/ 8,
3791 0, "builtin_type_m68881_ext", NULL
);
3792 TYPE_FLOATFORMAT (builtin_type_m68881_ext
) = &floatformat_m68881_ext
;
3793 builtin_type_i960_ext
=
3794 init_type (TYPE_CODE_FLT
, floatformat_i960_ext
.totalsize
/ 8,
3795 0, "builtin_type_i960_ext", NULL
);
3796 TYPE_FLOATFORMAT (builtin_type_i960_ext
) = &floatformat_i960_ext
;
3797 builtin_type_m88110_ext
=
3798 init_type (TYPE_CODE_FLT
, floatformat_m88110_ext
.totalsize
/ 8,
3799 0, "builtin_type_m88110_ext", NULL
);
3800 TYPE_FLOATFORMAT (builtin_type_m88110_ext
) = &floatformat_m88110_ext
;
3801 builtin_type_m88110_harris_ext
=
3802 init_type (TYPE_CODE_FLT
, floatformat_m88110_harris_ext
.totalsize
/ 8,
3803 0, "builtin_type_m88110_harris_ext", NULL
);
3804 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext
) = &floatformat_m88110_harris_ext
;
3805 builtin_type_arm_ext_big
=
3806 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_big
.totalsize
/ 8,
3807 0, "builtin_type_arm_ext_big", NULL
);
3808 TYPE_FLOATFORMAT (builtin_type_arm_ext_big
) = &floatformat_arm_ext_big
;
3809 builtin_type_arm_ext_littlebyte_bigword
=
3810 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_littlebyte_bigword
.totalsize
/ 8,
3811 0, "builtin_type_arm_ext_littlebyte_bigword", NULL
);
3812 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword
) = &floatformat_arm_ext_littlebyte_bigword
;
3813 builtin_type_arm_ext
[BFD_ENDIAN_BIG
]
3814 = build_flt (floatformat_arm_ext_big
.totalsize
,
3815 "builtin_type_arm_ext_big",
3816 &floatformat_arm_ext_big
);
3817 builtin_type_arm_ext
[BFD_ENDIAN_LITTLE
]
3818 = build_flt (floatformat_arm_ext_littlebyte_bigword
.totalsize
,
3819 "builtin_type_arm_ext_littlebyte_bigword",
3820 &floatformat_arm_ext_littlebyte_bigword
);
3821 builtin_type_ia64_spill_big
=
3822 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_big
.totalsize
/ 8,
3823 0, "builtin_type_ia64_spill_big", NULL
);
3824 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big
) = &floatformat_ia64_spill_big
;
3825 builtin_type_ia64_spill_little
=
3826 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_little
.totalsize
/ 8,
3827 0, "builtin_type_ia64_spill_little", NULL
);
3828 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little
) = &floatformat_ia64_spill_little
;
3829 builtin_type_ia64_spill
[BFD_ENDIAN_BIG
]
3830 = build_flt (floatformat_ia64_spill_big
.totalsize
,
3831 "builtin_type_ia64_spill_big",
3832 &floatformat_ia64_spill_big
);
3833 builtin_type_ia64_spill
[BFD_ENDIAN_LITTLE
]
3834 = build_flt (floatformat_ia64_spill_little
.totalsize
,
3835 "builtin_type_ia64_spill_little",
3836 &floatformat_ia64_spill_little
);
3837 builtin_type_ia64_quad_big
=
3838 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_big
.totalsize
/ 8,
3839 0, "builtin_type_ia64_quad_big", NULL
);
3840 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big
) = &floatformat_ia64_quad_big
;
3841 builtin_type_ia64_quad_little
=
3842 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_little
.totalsize
/ 8,
3843 0, "builtin_type_ia64_quad_little", NULL
);
3844 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little
) = &floatformat_ia64_quad_little
;
3845 builtin_type_ia64_quad
[BFD_ENDIAN_BIG
]
3846 = build_flt (floatformat_ia64_quad_big
.totalsize
,
3847 "builtin_type_ia64_quad_big",
3848 &floatformat_ia64_quad_big
);
3849 builtin_type_ia64_quad
[BFD_ENDIAN_LITTLE
]
3850 = build_flt (floatformat_ia64_quad_little
.totalsize
,
3851 "builtin_type_ia64_quad_little",
3852 &floatformat_ia64_quad_little
);
3854 add_setshow_zinteger_cmd ("overload", no_class
, &overload_debug
, _("\
3855 Set debugging of C++ overloading."), _("\
3856 Show debugging of C++ overloading."), _("\
3857 When enabled, ranking of the functions is displayed."),
3859 show_overload_debug
,
3860 &setdebuglist
, &showdebuglist
);