1 /* Support routines for manipulating internal types for GDB.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004 Free Software Foundation, Inc.
4 Contributed by Cygnus Support, using pieces from other GDB modules.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
30 #include "expression.h"
35 #include "complaints.h"
39 #include "gdb_assert.h"
41 /* These variables point to the objects
42 representing the predefined C data types. */
44 struct type
*builtin_type_void
;
45 struct type
*builtin_type_char
;
46 struct type
*builtin_type_true_char
;
47 struct type
*builtin_type_short
;
48 struct type
*builtin_type_int
;
49 struct type
*builtin_type_long
;
50 struct type
*builtin_type_long_long
;
51 struct type
*builtin_type_signed_char
;
52 struct type
*builtin_type_unsigned_char
;
53 struct type
*builtin_type_unsigned_short
;
54 struct type
*builtin_type_unsigned_int
;
55 struct type
*builtin_type_unsigned_long
;
56 struct type
*builtin_type_unsigned_long_long
;
57 struct type
*builtin_type_float
;
58 struct type
*builtin_type_double
;
59 struct type
*builtin_type_long_double
;
60 struct type
*builtin_type_complex
;
61 struct type
*builtin_type_double_complex
;
62 struct type
*builtin_type_string
;
63 struct type
*builtin_type_int0
;
64 struct type
*builtin_type_int8
;
65 struct type
*builtin_type_uint8
;
66 struct type
*builtin_type_int16
;
67 struct type
*builtin_type_uint16
;
68 struct type
*builtin_type_int32
;
69 struct type
*builtin_type_uint32
;
70 struct type
*builtin_type_int64
;
71 struct type
*builtin_type_uint64
;
72 struct type
*builtin_type_int128
;
73 struct type
*builtin_type_uint128
;
74 struct type
*builtin_type_bool
;
76 /* 128 bit long vector types */
77 struct type
*builtin_type_v2_double
;
78 struct type
*builtin_type_v4_float
;
79 struct type
*builtin_type_v2_int64
;
80 struct type
*builtin_type_v4_int32
;
81 struct type
*builtin_type_v8_int16
;
82 struct type
*builtin_type_v16_int8
;
83 /* 64 bit long vector types */
84 struct type
*builtin_type_v2_float
;
85 struct type
*builtin_type_v2_int32
;
86 struct type
*builtin_type_v4_int16
;
87 struct type
*builtin_type_v8_int8
;
89 struct type
*builtin_type_v4sf
;
90 struct type
*builtin_type_v4si
;
91 struct type
*builtin_type_v16qi
;
92 struct type
*builtin_type_v8qi
;
93 struct type
*builtin_type_v8hi
;
94 struct type
*builtin_type_v4hi
;
95 struct type
*builtin_type_v2si
;
96 struct type
*builtin_type_vec64
;
97 struct type
*builtin_type_vec64i
;
98 struct type
*builtin_type_vec128
;
99 struct type
*builtin_type_vec128i
;
100 struct type
*builtin_type_ieee_single
[BFD_ENDIAN_UNKNOWN
];
101 struct type
*builtin_type_ieee_single_big
;
102 struct type
*builtin_type_ieee_single_little
;
103 struct type
*builtin_type_ieee_double
[BFD_ENDIAN_UNKNOWN
];
104 struct type
*builtin_type_ieee_double_big
;
105 struct type
*builtin_type_ieee_double_little
;
106 struct type
*builtin_type_ieee_double_littlebyte_bigword
;
107 struct type
*builtin_type_i387_ext
;
108 struct type
*builtin_type_m68881_ext
;
109 struct type
*builtin_type_i960_ext
;
110 struct type
*builtin_type_m88110_ext
;
111 struct type
*builtin_type_m88110_harris_ext
;
112 struct type
*builtin_type_arm_ext
[BFD_ENDIAN_UNKNOWN
];
113 struct type
*builtin_type_arm_ext_big
;
114 struct type
*builtin_type_arm_ext_littlebyte_bigword
;
115 struct type
*builtin_type_ia64_spill
[BFD_ENDIAN_UNKNOWN
];
116 struct type
*builtin_type_ia64_spill_big
;
117 struct type
*builtin_type_ia64_spill_little
;
118 struct type
*builtin_type_ia64_quad
[BFD_ENDIAN_UNKNOWN
];
119 struct type
*builtin_type_ia64_quad_big
;
120 struct type
*builtin_type_ia64_quad_little
;
121 struct type
*builtin_type_void_data_ptr
;
122 struct type
*builtin_type_void_func_ptr
;
123 struct type
*builtin_type_CORE_ADDR
;
124 struct type
*builtin_type_bfd_vma
;
126 int opaque_type_resolution
= 1;
128 show_opaque_type_resolution (struct ui_file
*file
, int from_tty
,
129 struct cmd_list_element
*c
, const char *value
)
131 fprintf_filtered (file
, _("\
132 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
136 int overload_debug
= 0;
138 show_overload_debug (struct ui_file
*file
, int from_tty
,
139 struct cmd_list_element
*c
, const char *value
)
141 fprintf_filtered (file
, _("Debugging of C++ overloading is %s.\n"), value
);
148 }; /* maximum extension is 128! FIXME */
150 static void print_bit_vector (B_TYPE
*, int);
151 static void print_arg_types (struct field
*, int, int);
152 static void dump_fn_fieldlists (struct type
*, int);
153 static void print_cplus_stuff (struct type
*, int);
154 static void virtual_base_list_aux (struct type
*dclass
);
157 /* Alloc a new type structure and fill it with some defaults. If
158 OBJFILE is non-NULL, then allocate the space for the type structure
159 in that objfile's objfile_obstack. Otherwise allocate the new type structure
160 by xmalloc () (for permanent types). */
163 alloc_type (struct objfile
*objfile
)
167 /* Alloc the structure and start off with all fields zeroed. */
171 type
= xmalloc (sizeof (struct type
));
172 memset (type
, 0, sizeof (struct type
));
173 TYPE_MAIN_TYPE (type
) = xmalloc (sizeof (struct main_type
));
177 type
= obstack_alloc (&objfile
->objfile_obstack
,
178 sizeof (struct type
));
179 memset (type
, 0, sizeof (struct type
));
180 TYPE_MAIN_TYPE (type
) = obstack_alloc (&objfile
->objfile_obstack
,
181 sizeof (struct main_type
));
182 OBJSTAT (objfile
, n_types
++);
184 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
186 /* Initialize the fields that might not be zero. */
188 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
189 TYPE_OBJFILE (type
) = objfile
;
190 TYPE_VPTR_FIELDNO (type
) = -1;
191 TYPE_CHAIN (type
) = type
; /* Chain back to itself. */
196 /* Alloc a new type instance structure, fill it with some defaults,
197 and point it at OLDTYPE. Allocate the new type instance from the
198 same place as OLDTYPE. */
201 alloc_type_instance (struct type
*oldtype
)
205 /* Allocate the structure. */
207 if (TYPE_OBJFILE (oldtype
) == NULL
)
209 type
= xmalloc (sizeof (struct type
));
210 memset (type
, 0, sizeof (struct type
));
214 type
= obstack_alloc (&TYPE_OBJFILE (oldtype
)->objfile_obstack
,
215 sizeof (struct type
));
216 memset (type
, 0, sizeof (struct type
));
218 TYPE_MAIN_TYPE (type
) = TYPE_MAIN_TYPE (oldtype
);
220 TYPE_CHAIN (type
) = type
; /* Chain back to itself for now. */
225 /* Clear all remnants of the previous type at TYPE, in preparation for
226 replacing it with something else. */
228 smash_type (struct type
*type
)
230 memset (TYPE_MAIN_TYPE (type
), 0, sizeof (struct main_type
));
232 /* For now, delete the rings. */
233 TYPE_CHAIN (type
) = type
;
235 /* For now, leave the pointer/reference types alone. */
238 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
239 to a pointer to memory where the pointer type should be stored.
240 If *TYPEPTR is zero, update it to point to the pointer type we return.
241 We allocate new memory if needed. */
244 make_pointer_type (struct type
*type
, struct type
**typeptr
)
246 struct type
*ntype
; /* New type */
247 struct objfile
*objfile
;
249 ntype
= TYPE_POINTER_TYPE (type
);
254 return ntype
; /* Don't care about alloc, and have new type. */
255 else if (*typeptr
== 0)
257 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
262 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
264 ntype
= alloc_type (TYPE_OBJFILE (type
));
269 /* We have storage, but need to reset it. */
272 objfile
= TYPE_OBJFILE (ntype
);
274 TYPE_OBJFILE (ntype
) = objfile
;
277 TYPE_TARGET_TYPE (ntype
) = type
;
278 TYPE_POINTER_TYPE (type
) = ntype
;
280 /* FIXME! Assume the machine has only one representation for pointers! */
282 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
283 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
285 /* Mark pointers as unsigned. The target converts between pointers
286 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
287 ADDRESS_TO_POINTER(). */
288 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
290 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
291 TYPE_POINTER_TYPE (type
) = ntype
;
296 /* Given a type TYPE, return a type of pointers to that type.
297 May need to construct such a type if this is the first use. */
300 lookup_pointer_type (struct type
*type
)
302 return make_pointer_type (type
, (struct type
**) 0);
305 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
306 to a pointer to memory where the reference type should be stored.
307 If *TYPEPTR is zero, update it to point to the reference type we return.
308 We allocate new memory if needed. */
311 make_reference_type (struct type
*type
, struct type
**typeptr
)
313 struct type
*ntype
; /* New type */
314 struct objfile
*objfile
;
316 ntype
= TYPE_REFERENCE_TYPE (type
);
321 return ntype
; /* Don't care about alloc, and have new type. */
322 else if (*typeptr
== 0)
324 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
329 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
331 ntype
= alloc_type (TYPE_OBJFILE (type
));
336 /* We have storage, but need to reset it. */
339 objfile
= TYPE_OBJFILE (ntype
);
341 TYPE_OBJFILE (ntype
) = objfile
;
344 TYPE_TARGET_TYPE (ntype
) = type
;
345 TYPE_REFERENCE_TYPE (type
) = ntype
;
347 /* FIXME! Assume the machine has only one representation for references,
348 and that it matches the (only) representation for pointers! */
350 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
351 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
353 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
354 TYPE_REFERENCE_TYPE (type
) = ntype
;
359 /* Same as above, but caller doesn't care about memory allocation details. */
362 lookup_reference_type (struct type
*type
)
364 return make_reference_type (type
, (struct type
**) 0);
367 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
368 to a pointer to memory where the function type should be stored.
369 If *TYPEPTR is zero, update it to point to the function type we return.
370 We allocate new memory if needed. */
373 make_function_type (struct type
*type
, struct type
**typeptr
)
375 struct type
*ntype
; /* New type */
376 struct objfile
*objfile
;
378 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
380 ntype
= alloc_type (TYPE_OBJFILE (type
));
385 /* We have storage, but need to reset it. */
388 objfile
= TYPE_OBJFILE (ntype
);
390 TYPE_OBJFILE (ntype
) = objfile
;
393 TYPE_TARGET_TYPE (ntype
) = type
;
395 TYPE_LENGTH (ntype
) = 1;
396 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
402 /* Given a type TYPE, return a type of functions that return that type.
403 May need to construct such a type if this is the first use. */
406 lookup_function_type (struct type
*type
)
408 return make_function_type (type
, (struct type
**) 0);
411 /* Identify address space identifier by name --
412 return the integer flag defined in gdbtypes.h. */
414 address_space_name_to_int (char *space_identifier
)
416 struct gdbarch
*gdbarch
= current_gdbarch
;
418 /* Check for known address space delimiters. */
419 if (!strcmp (space_identifier
, "code"))
420 return TYPE_FLAG_CODE_SPACE
;
421 else if (!strcmp (space_identifier
, "data"))
422 return TYPE_FLAG_DATA_SPACE
;
423 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch
)
424 && gdbarch_address_class_name_to_type_flags (gdbarch
,
429 error (_("Unknown address space specifier: \"%s\""), space_identifier
);
432 /* Identify address space identifier by integer flag as defined in
433 gdbtypes.h -- return the string version of the adress space name. */
436 address_space_int_to_name (int space_flag
)
438 struct gdbarch
*gdbarch
= current_gdbarch
;
439 if (space_flag
& TYPE_FLAG_CODE_SPACE
)
441 else if (space_flag
& TYPE_FLAG_DATA_SPACE
)
443 else if ((space_flag
& TYPE_FLAG_ADDRESS_CLASS_ALL
)
444 && gdbarch_address_class_type_flags_to_name_p (gdbarch
))
445 return gdbarch_address_class_type_flags_to_name (gdbarch
, space_flag
);
450 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
452 If STORAGE is non-NULL, create the new type instance there.
453 STORAGE must be in the same obstack as TYPE. */
456 make_qualified_type (struct type
*type
, int new_flags
,
457 struct type
*storage
)
463 if (TYPE_INSTANCE_FLAGS (ntype
) == new_flags
)
465 ntype
= TYPE_CHAIN (ntype
);
466 } while (ntype
!= type
);
468 /* Create a new type instance. */
470 ntype
= alloc_type_instance (type
);
473 /* If STORAGE was provided, it had better be in the same objfile as
474 TYPE. Otherwise, we can't link it into TYPE's cv chain: if one
475 objfile is freed and the other kept, we'd have dangling
477 gdb_assert (TYPE_OBJFILE (type
) == TYPE_OBJFILE (storage
));
480 TYPE_MAIN_TYPE (ntype
) = TYPE_MAIN_TYPE (type
);
481 TYPE_CHAIN (ntype
) = ntype
;
484 /* Pointers or references to the original type are not relevant to
486 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
487 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
489 /* Chain the new qualified type to the old type. */
490 TYPE_CHAIN (ntype
) = TYPE_CHAIN (type
);
491 TYPE_CHAIN (type
) = ntype
;
493 /* Now set the instance flags and return the new type. */
494 TYPE_INSTANCE_FLAGS (ntype
) = new_flags
;
496 /* Set length of new type to that of the original type. */
497 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
502 /* Make an address-space-delimited variant of a type -- a type that
503 is identical to the one supplied except that it has an address
504 space attribute attached to it (such as "code" or "data").
506 The space attributes "code" and "data" are for Harvard architectures.
507 The address space attributes are for architectures which have
508 alternately sized pointers or pointers with alternate representations. */
511 make_type_with_address_space (struct type
*type
, int space_flag
)
514 int new_flags
= ((TYPE_INSTANCE_FLAGS (type
)
515 & ~(TYPE_FLAG_CODE_SPACE
| TYPE_FLAG_DATA_SPACE
516 | TYPE_FLAG_ADDRESS_CLASS_ALL
))
519 return make_qualified_type (type
, new_flags
, NULL
);
522 /* Make a "c-v" variant of a type -- a type that is identical to the
523 one supplied except that it may have const or volatile attributes
524 CNST is a flag for setting the const attribute
525 VOLTL is a flag for setting the volatile attribute
526 TYPE is the base type whose variant we are creating.
528 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
529 storage to hold the new qualified type; *TYPEPTR and TYPE must be
530 in the same objfile. Otherwise, allocate fresh memory for the new
531 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
532 new type we construct. */
534 make_cv_type (int cnst
, int voltl
, struct type
*type
, struct type
**typeptr
)
536 struct type
*ntype
; /* New type */
537 struct type
*tmp_type
= type
; /* tmp type */
538 struct objfile
*objfile
;
540 int new_flags
= (TYPE_INSTANCE_FLAGS (type
)
541 & ~(TYPE_FLAG_CONST
| TYPE_FLAG_VOLATILE
));
544 new_flags
|= TYPE_FLAG_CONST
;
547 new_flags
|= TYPE_FLAG_VOLATILE
;
549 if (typeptr
&& *typeptr
!= NULL
)
551 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
552 a C-V variant chain that threads across objfiles: if one
553 objfile gets freed, then the other has a broken C-V chain.
555 This code used to try to copy over the main type from TYPE to
556 *TYPEPTR if they were in different objfiles, but that's
557 wrong, too: TYPE may have a field list or member function
558 lists, which refer to types of their own, etc. etc. The
559 whole shebang would need to be copied over recursively; you
560 can't have inter-objfile pointers. The only thing to do is
561 to leave stub types as stub types, and look them up afresh by
562 name each time you encounter them. */
563 gdb_assert (TYPE_OBJFILE (*typeptr
) == TYPE_OBJFILE (type
));
566 ntype
= make_qualified_type (type
, new_flags
, typeptr
? *typeptr
: NULL
);
574 /* Replace the contents of ntype with the type *type. This changes the
575 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
576 the changes are propogated to all types in the TYPE_CHAIN.
578 In order to build recursive types, it's inevitable that we'll need
579 to update types in place --- but this sort of indiscriminate
580 smashing is ugly, and needs to be replaced with something more
581 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
582 clear if more steps are needed. */
584 replace_type (struct type
*ntype
, struct type
*type
)
588 /* These two types had better be in the same objfile. Otherwise,
589 the assignment of one type's main type structure to the other
590 will produce a type with references to objects (names; field
591 lists; etc.) allocated on an objfile other than its own. */
592 gdb_assert (TYPE_OBJFILE (ntype
) == TYPE_OBJFILE (ntype
));
594 *TYPE_MAIN_TYPE (ntype
) = *TYPE_MAIN_TYPE (type
);
596 /* The type length is not a part of the main type. Update it for each
597 type on the variant chain. */
600 /* Assert that this element of the chain has no address-class bits
601 set in its flags. Such type variants might have type lengths
602 which are supposed to be different from the non-address-class
603 variants. This assertion shouldn't ever be triggered because
604 symbol readers which do construct address-class variants don't
605 call replace_type(). */
606 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain
) == 0);
608 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
609 chain
= TYPE_CHAIN (chain
);
610 } while (ntype
!= chain
);
612 /* Assert that the two types have equivalent instance qualifiers.
613 This should be true for at least all of our debug readers. */
614 gdb_assert (TYPE_INSTANCE_FLAGS (ntype
) == TYPE_INSTANCE_FLAGS (type
));
617 /* Implement direct support for MEMBER_TYPE in GNU C++.
618 May need to construct such a type if this is the first use.
619 The TYPE is the type of the member. The DOMAIN is the type
620 of the aggregate that the member belongs to. */
623 lookup_member_type (struct type
*type
, struct type
*domain
)
627 mtype
= alloc_type (TYPE_OBJFILE (type
));
628 smash_to_member_type (mtype
, domain
, type
);
632 /* Allocate a stub method whose return type is TYPE.
633 This apparently happens for speed of symbol reading, since parsing
634 out the arguments to the method is cpu-intensive, the way we are doing
635 it. So, we will fill in arguments later.
636 This always returns a fresh type. */
639 allocate_stub_method (struct type
*type
)
643 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
644 TYPE_OBJFILE (type
));
645 TYPE_TARGET_TYPE (mtype
) = type
;
646 /* _DOMAIN_TYPE (mtype) = unknown yet */
650 /* Create a range type using either a blank type supplied in RESULT_TYPE,
651 or creating a new type, inheriting the objfile from INDEX_TYPE.
653 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
654 HIGH_BOUND, inclusive.
656 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
657 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
660 create_range_type (struct type
*result_type
, struct type
*index_type
,
661 int low_bound
, int high_bound
)
663 if (result_type
== NULL
)
665 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
667 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
668 TYPE_TARGET_TYPE (result_type
) = index_type
;
669 if (TYPE_STUB (index_type
))
670 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
672 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
673 TYPE_NFIELDS (result_type
) = 2;
674 TYPE_FIELDS (result_type
) = (struct field
*)
675 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
676 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
677 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
678 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
679 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
680 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
683 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
685 return (result_type
);
688 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
689 Return 1 of type is a range type, 0 if it is discrete (and bounds
690 will fit in LONGEST), or -1 otherwise. */
693 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
695 CHECK_TYPEDEF (type
);
696 switch (TYPE_CODE (type
))
698 case TYPE_CODE_RANGE
:
699 *lowp
= TYPE_LOW_BOUND (type
);
700 *highp
= TYPE_HIGH_BOUND (type
);
703 if (TYPE_NFIELDS (type
) > 0)
705 /* The enums may not be sorted by value, so search all
709 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
710 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
712 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
713 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
714 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
715 *highp
= TYPE_FIELD_BITPOS (type
, i
);
718 /* Set unsigned indicator if warranted. */
721 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
735 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
737 if (!TYPE_UNSIGNED (type
))
739 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
743 /* ... fall through for unsigned ints ... */
746 /* This round-about calculation is to avoid shifting by
747 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
748 if TYPE_LENGTH (type) == sizeof (LONGEST). */
749 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
750 *highp
= (*highp
- 1) | *highp
;
757 /* Create an array type using either a blank type supplied in RESULT_TYPE,
758 or creating a new type, inheriting the objfile from RANGE_TYPE.
760 Elements will be of type ELEMENT_TYPE, the indices will be of type
763 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
764 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
767 create_array_type (struct type
*result_type
, struct type
*element_type
,
768 struct type
*range_type
)
770 LONGEST low_bound
, high_bound
;
772 if (result_type
== NULL
)
774 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
776 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
777 TYPE_TARGET_TYPE (result_type
) = element_type
;
778 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
779 low_bound
= high_bound
= 0;
780 CHECK_TYPEDEF (element_type
);
781 TYPE_LENGTH (result_type
) =
782 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
783 TYPE_NFIELDS (result_type
) = 1;
784 TYPE_FIELDS (result_type
) =
785 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
786 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
787 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
788 TYPE_VPTR_FIELDNO (result_type
) = -1;
790 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
791 if (TYPE_LENGTH (result_type
) == 0)
792 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
794 return (result_type
);
797 /* Create a string type using either a blank type supplied in RESULT_TYPE,
798 or creating a new type. String types are similar enough to array of
799 char types that we can use create_array_type to build the basic type
800 and then bash it into a string type.
802 For fixed length strings, the range type contains 0 as the lower
803 bound and the length of the string minus one as the upper bound.
805 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
806 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
809 create_string_type (struct type
*result_type
, struct type
*range_type
)
811 struct type
*string_char_type
;
813 string_char_type
= language_string_char_type (current_language
,
815 result_type
= create_array_type (result_type
,
818 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
819 return (result_type
);
823 create_set_type (struct type
*result_type
, struct type
*domain_type
)
825 LONGEST low_bound
, high_bound
, bit_length
;
826 if (result_type
== NULL
)
828 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
830 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
831 TYPE_NFIELDS (result_type
) = 1;
832 TYPE_FIELDS (result_type
) = (struct field
*)
833 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
834 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
836 if (!TYPE_STUB (domain_type
))
838 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
839 low_bound
= high_bound
= 0;
840 bit_length
= high_bound
- low_bound
+ 1;
841 TYPE_LENGTH (result_type
)
842 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
844 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
847 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
849 return (result_type
);
852 /* Construct and return a type of the form:
853 struct NAME { ELT_TYPE ELT_NAME[N]; }
854 We use these types for SIMD registers. For example, the type of
855 the SSE registers on the late x86-family processors is:
856 struct __builtin_v4sf { float f[4]; }
857 built by the function call:
858 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
859 The type returned is a permanent type, allocated using malloc; it
860 doesn't live in any objfile's obstack. */
862 init_simd_type (char *name
,
863 struct type
*elt_type
,
867 struct type
*simd_type
;
868 struct type
*array_type
;
870 simd_type
= init_composite_type (name
, TYPE_CODE_STRUCT
);
871 array_type
= create_array_type (0, elt_type
,
872 create_range_type (0, builtin_type_int
,
874 append_composite_type_field (simd_type
, elt_name
, array_type
);
879 init_vector_type (struct type
*elt_type
, int n
)
881 struct type
*array_type
;
883 array_type
= create_array_type (0, elt_type
,
884 create_range_type (0, builtin_type_int
,
886 TYPE_FLAGS (array_type
) |= TYPE_FLAG_VECTOR
;
891 build_builtin_type_vec64 (void)
893 /* Construct a type for the 64 bit registers. The type we're
896 union __gdb_builtin_type_vec64
908 t
= init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION
);
909 append_composite_type_field (t
, "uint64", builtin_type_int64
);
910 append_composite_type_field (t
, "v2_float", builtin_type_v2_float
);
911 append_composite_type_field (t
, "v2_int32", builtin_type_v2_int32
);
912 append_composite_type_field (t
, "v4_int16", builtin_type_v4_int16
);
913 append_composite_type_field (t
, "v8_int8", builtin_type_v8_int8
);
915 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
916 TYPE_NAME (t
) = "builtin_type_vec64";
921 build_builtin_type_vec64i (void)
923 /* Construct a type for the 64 bit registers. The type we're
926 union __gdb_builtin_type_vec64i
937 t
= init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION
);
938 append_composite_type_field (t
, "uint64", builtin_type_int64
);
939 append_composite_type_field (t
, "v2_int32", builtin_type_v2_int32
);
940 append_composite_type_field (t
, "v4_int16", builtin_type_v4_int16
);
941 append_composite_type_field (t
, "v8_int8", builtin_type_v8_int8
);
943 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
944 TYPE_NAME (t
) = "builtin_type_vec64i";
949 build_builtin_type_vec128 (void)
951 /* Construct a type for the 128 bit registers. The type we're
954 union __gdb_builtin_type_vec128
966 t
= init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION
);
967 append_composite_type_field (t
, "uint128", builtin_type_int128
);
968 append_composite_type_field (t
, "v4_float", builtin_type_v4_float
);
969 append_composite_type_field (t
, "v4_int32", builtin_type_v4_int32
);
970 append_composite_type_field (t
, "v8_int16", builtin_type_v8_int16
);
971 append_composite_type_field (t
, "v16_int8", builtin_type_v16_int8
);
973 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
974 TYPE_NAME (t
) = "builtin_type_vec128";
979 build_builtin_type_vec128i (void)
981 /* 128-bit Intel SIMD registers */
984 t
= init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION
);
985 append_composite_type_field (t
, "v4_float", builtin_type_v4_float
);
986 append_composite_type_field (t
, "v2_double", builtin_type_v2_double
);
987 append_composite_type_field (t
, "v16_int8", builtin_type_v16_int8
);
988 append_composite_type_field (t
, "v8_int16", builtin_type_v8_int16
);
989 append_composite_type_field (t
, "v4_int32", builtin_type_v4_int32
);
990 append_composite_type_field (t
, "v2_int64", builtin_type_v2_int64
);
991 append_composite_type_field (t
, "uint128", builtin_type_int128
);
993 TYPE_FLAGS (t
) |= TYPE_FLAG_VECTOR
;
994 TYPE_NAME (t
) = "builtin_type_vec128i";
998 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
999 A MEMBER is a wierd thing -- it amounts to a typed offset into
1000 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
1001 include the offset (that's the value of the MEMBER itself), but does
1002 include the structure type into which it points (for some reason).
1004 When "smashing" the type, we preserve the objfile that the
1005 old type pointed to, since we aren't changing where the type is actually
1009 smash_to_member_type (struct type
*type
, struct type
*domain
,
1010 struct type
*to_type
)
1012 struct objfile
*objfile
;
1014 objfile
= TYPE_OBJFILE (type
);
1017 TYPE_OBJFILE (type
) = objfile
;
1018 TYPE_TARGET_TYPE (type
) = to_type
;
1019 TYPE_DOMAIN_TYPE (type
) = domain
;
1020 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1021 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
1024 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
1025 METHOD just means `function that gets an extra "this" argument'.
1027 When "smashing" the type, we preserve the objfile that the
1028 old type pointed to, since we aren't changing where the type is actually
1032 smash_to_method_type (struct type
*type
, struct type
*domain
,
1033 struct type
*to_type
, struct field
*args
,
1034 int nargs
, int varargs
)
1036 struct objfile
*objfile
;
1038 objfile
= TYPE_OBJFILE (type
);
1041 TYPE_OBJFILE (type
) = objfile
;
1042 TYPE_TARGET_TYPE (type
) = to_type
;
1043 TYPE_DOMAIN_TYPE (type
) = domain
;
1044 TYPE_FIELDS (type
) = args
;
1045 TYPE_NFIELDS (type
) = nargs
;
1047 TYPE_FLAGS (type
) |= TYPE_FLAG_VARARGS
;
1048 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
1049 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
1052 /* Return a typename for a struct/union/enum type without "struct ",
1053 "union ", or "enum ". If the type has a NULL name, return NULL. */
1056 type_name_no_tag (const struct type
*type
)
1058 if (TYPE_TAG_NAME (type
) != NULL
)
1059 return TYPE_TAG_NAME (type
);
1061 /* Is there code which expects this to return the name if there is no
1062 tag name? My guess is that this is mainly used for C++ in cases where
1063 the two will always be the same. */
1064 return TYPE_NAME (type
);
1067 /* Lookup a typedef or primitive type named NAME,
1068 visible in lexical block BLOCK.
1069 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1072 lookup_typename (char *name
, struct block
*block
, int noerr
)
1077 sym
= lookup_symbol (name
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1078 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
1080 tmp
= language_lookup_primitive_type_by_name (current_language
,
1087 else if (!tmp
&& noerr
)
1093 error (_("No type named %s."), name
);
1096 return (SYMBOL_TYPE (sym
));
1100 lookup_unsigned_typename (char *name
)
1102 char *uns
= alloca (strlen (name
) + 10);
1104 strcpy (uns
, "unsigned ");
1105 strcpy (uns
+ 9, name
);
1106 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
1110 lookup_signed_typename (char *name
)
1113 char *uns
= alloca (strlen (name
) + 8);
1115 strcpy (uns
, "signed ");
1116 strcpy (uns
+ 7, name
);
1117 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
1118 /* If we don't find "signed FOO" just try again with plain "FOO". */
1121 return lookup_typename (name
, (struct block
*) NULL
, 0);
1124 /* Lookup a structure type named "struct NAME",
1125 visible in lexical block BLOCK. */
1128 lookup_struct (char *name
, struct block
*block
)
1132 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1133 (struct symtab
**) NULL
);
1137 error (_("No struct type named %s."), name
);
1139 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1141 error (_("This context has class, union or enum %s, not a struct."), name
);
1143 return (SYMBOL_TYPE (sym
));
1146 /* Lookup a union type named "union NAME",
1147 visible in lexical block BLOCK. */
1150 lookup_union (char *name
, struct block
*block
)
1155 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1156 (struct symtab
**) NULL
);
1159 error (_("No union type named %s."), name
);
1161 t
= SYMBOL_TYPE (sym
);
1163 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1166 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1167 * a further "declared_type" field to discover it is really a union.
1169 if (HAVE_CPLUS_STRUCT (t
))
1170 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
1173 /* If we get here, it's not a union */
1174 error (_("This context has class, struct or enum %s, not a union."), name
);
1178 /* Lookup an enum type named "enum NAME",
1179 visible in lexical block BLOCK. */
1182 lookup_enum (char *name
, struct block
*block
)
1186 sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, 0,
1187 (struct symtab
**) NULL
);
1190 error (_("No enum type named %s."), name
);
1192 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
1194 error (_("This context has class, struct or union %s, not an enum."), name
);
1196 return (SYMBOL_TYPE (sym
));
1199 /* Lookup a template type named "template NAME<TYPE>",
1200 visible in lexical block BLOCK. */
1203 lookup_template_type (char *name
, struct type
*type
, struct block
*block
)
1206 char *nam
= (char *) alloca (strlen (name
) + strlen (TYPE_NAME (type
)) + 4);
1209 strcat (nam
, TYPE_NAME (type
));
1210 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1212 sym
= lookup_symbol (nam
, block
, VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
1216 error (_("No template type named %s."), name
);
1218 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1220 error (_("This context has class, union or enum %s, not a struct."), name
);
1222 return (SYMBOL_TYPE (sym
));
1225 /* Given a type TYPE, lookup the type of the component of type named NAME.
1227 TYPE can be either a struct or union, or a pointer or reference to a struct or
1228 union. If it is a pointer or reference, its target type is automatically used.
1229 Thus '.' and '->' are interchangable, as specified for the definitions of the
1230 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1232 If NOERR is nonzero, return zero if NAME is not suitably defined.
1233 If NAME is the name of a baseclass type, return that type. */
1236 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1242 CHECK_TYPEDEF (type
);
1243 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1244 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1246 type
= TYPE_TARGET_TYPE (type
);
1249 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
1250 TYPE_CODE (type
) != TYPE_CODE_UNION
)
1252 target_terminal_ours ();
1253 gdb_flush (gdb_stdout
);
1254 fprintf_unfiltered (gdb_stderr
, "Type ");
1255 type_print (type
, "", gdb_stderr
, -1);
1256 error (_(" is not a structure or union type."));
1260 /* FIXME: This change put in by Michael seems incorrect for the case where
1261 the structure tag name is the same as the member name. I.E. when doing
1262 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1267 typename
= type_name_no_tag (type
);
1268 if (typename
!= NULL
&& strcmp (typename
, name
) == 0)
1273 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1275 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1277 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1279 return TYPE_FIELD_TYPE (type
, i
);
1283 /* OK, it's not in this class. Recursively check the baseclasses. */
1284 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1288 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
1300 target_terminal_ours ();
1301 gdb_flush (gdb_stdout
);
1302 fprintf_unfiltered (gdb_stderr
, "Type ");
1303 type_print (type
, "", gdb_stderr
, -1);
1304 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1305 fputs_filtered (name
, gdb_stderr
);
1307 return (struct type
*) -1; /* For lint */
1310 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1311 valid. Callers should be aware that in some cases (for example,
1312 the type or one of its baseclasses is a stub type and we are
1313 debugging a .o file), this function will not be able to find the virtual
1314 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1315 will remain NULL. */
1318 fill_in_vptr_fieldno (struct type
*type
)
1320 CHECK_TYPEDEF (type
);
1322 if (TYPE_VPTR_FIELDNO (type
) < 0)
1326 /* We must start at zero in case the first (and only) baseclass is
1327 virtual (and hence we cannot share the table pointer). */
1328 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1330 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1331 fill_in_vptr_fieldno (baseclass
);
1332 if (TYPE_VPTR_FIELDNO (baseclass
) >= 0)
1334 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (baseclass
);
1335 TYPE_VPTR_BASETYPE (type
) = TYPE_VPTR_BASETYPE (baseclass
);
1342 /* Find the method and field indices for the destructor in class type T.
1343 Return 1 if the destructor was found, otherwise, return 0. */
1346 get_destructor_fn_field (struct type
*t
, int *method_indexp
, int *field_indexp
)
1350 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1353 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1355 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1357 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1369 stub_noname_complaint (void)
1371 complaint (&symfile_complaints
, _("stub type has NULL name"));
1374 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1376 If this is a stubbed struct (i.e. declared as struct foo *), see if
1377 we can find a full definition in some other file. If so, copy this
1378 definition, so we can use it in future. There used to be a comment (but
1379 not any code) that if we don't find a full definition, we'd set a flag
1380 so we don't spend time in the future checking the same type. That would
1381 be a mistake, though--we might load in more symbols which contain a
1382 full definition for the type.
1384 This used to be coded as a macro, but I don't think it is called
1385 often enough to merit such treatment. */
1387 /* Find the real type of TYPE. This function returns the real type, after
1388 removing all layers of typedefs and completing opaque or stub types.
1389 Completion changes the TYPE argument, but stripping of typedefs does
1393 check_typedef (struct type
*type
)
1395 struct type
*orig_type
= type
;
1396 int is_const
, is_volatile
;
1398 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1400 if (!TYPE_TARGET_TYPE (type
))
1405 /* It is dangerous to call lookup_symbol if we are currently
1406 reading a symtab. Infinite recursion is one danger. */
1407 if (currently_reading_symtab
)
1410 name
= type_name_no_tag (type
);
1411 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1412 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1413 as appropriate? (this code was written before TYPE_NAME and
1414 TYPE_TAG_NAME were separate). */
1417 stub_noname_complaint ();
1420 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0,
1421 (struct symtab
**) NULL
);
1423 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1425 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1427 type
= TYPE_TARGET_TYPE (type
);
1430 is_const
= TYPE_CONST (type
);
1431 is_volatile
= TYPE_VOLATILE (type
);
1433 /* If this is a struct/class/union with no fields, then check whether a
1434 full definition exists somewhere else. This is for systems where a
1435 type definition with no fields is issued for such types, instead of
1436 identifying them as stub types in the first place */
1438 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1440 char *name
= type_name_no_tag (type
);
1441 struct type
*newtype
;
1444 stub_noname_complaint ();
1447 newtype
= lookup_transparent_type (name
);
1451 /* If the resolved type and the stub are in the same objfile,
1452 then replace the stub type with the real deal. But if
1453 they're in separate objfiles, leave the stub alone; we'll
1454 just look up the transparent type every time we call
1455 check_typedef. We can't create pointers between types
1456 allocated to different objfiles, since they may have
1457 different lifetimes. Trying to copy NEWTYPE over to TYPE's
1458 objfile is pointless, too, since you'll have to move over any
1459 other types NEWTYPE refers to, which could be an unbounded
1461 if (TYPE_OBJFILE (newtype
) == TYPE_OBJFILE (type
))
1462 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1467 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1468 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1470 char *name
= type_name_no_tag (type
);
1471 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1472 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1473 as appropriate? (this code was written before TYPE_NAME and
1474 TYPE_TAG_NAME were separate). */
1478 stub_noname_complaint ();
1481 sym
= lookup_symbol (name
, 0, STRUCT_DOMAIN
, 0, (struct symtab
**) NULL
);
1483 make_cv_type (is_const
, is_volatile
, SYMBOL_TYPE (sym
), &type
);
1486 if (TYPE_TARGET_STUB (type
))
1488 struct type
*range_type
;
1489 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1491 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1494 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1495 && TYPE_NFIELDS (type
) == 1
1496 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1497 == TYPE_CODE_RANGE
))
1499 /* Now recompute the length of the array type, based on its
1500 number of elements and the target type's length. */
1501 TYPE_LENGTH (type
) =
1502 ((TYPE_FIELD_BITPOS (range_type
, 1)
1503 - TYPE_FIELD_BITPOS (range_type
, 0)
1505 * TYPE_LENGTH (target_type
));
1506 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1508 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1510 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1511 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1514 /* Cache TYPE_LENGTH for future use. */
1515 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1519 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1520 silently return builtin_type_void. */
1522 static struct type
*
1523 safe_parse_type (char *p
, int length
)
1525 struct ui_file
*saved_gdb_stderr
;
1528 /* Suppress error messages. */
1529 saved_gdb_stderr
= gdb_stderr
;
1530 gdb_stderr
= ui_file_new ();
1532 /* Call parse_and_eval_type() without fear of longjmp()s. */
1533 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1534 type
= builtin_type_void
;
1536 /* Stop suppressing error messages. */
1537 ui_file_delete (gdb_stderr
);
1538 gdb_stderr
= saved_gdb_stderr
;
1543 /* Ugly hack to convert method stubs into method types.
1545 He ain't kiddin'. This demangles the name of the method into a string
1546 including argument types, parses out each argument type, generates
1547 a string casting a zero to that type, evaluates the string, and stuffs
1548 the resulting type into an argtype vector!!! Then it knows the type
1549 of the whole function (including argument types for overloading),
1550 which info used to be in the stab's but was removed to hack back
1551 the space required for them. */
1554 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1557 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1558 char *demangled_name
= cplus_demangle (mangled_name
,
1559 DMGL_PARAMS
| DMGL_ANSI
);
1560 char *argtypetext
, *p
;
1561 int depth
= 0, argcount
= 1;
1562 struct field
*argtypes
;
1565 /* Make sure we got back a function string that we can use. */
1567 p
= strchr (demangled_name
, '(');
1571 if (demangled_name
== NULL
|| p
== NULL
)
1572 error (_("Internal: Cannot demangle mangled name `%s'."), mangled_name
);
1574 /* Now, read in the parameters that define this type. */
1579 if (*p
== '(' || *p
== '<')
1583 else if (*p
== ')' || *p
== '>')
1587 else if (*p
== ',' && depth
== 0)
1595 /* If we read one argument and it was ``void'', don't count it. */
1596 if (strncmp (argtypetext
, "(void)", 6) == 0)
1599 /* We need one extra slot, for the THIS pointer. */
1601 argtypes
= (struct field
*)
1602 TYPE_ALLOC (type
, (argcount
+ 1) * sizeof (struct field
));
1605 /* Add THIS pointer for non-static methods. */
1606 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1607 if (TYPE_FN_FIELD_STATIC_P (f
, signature_id
))
1611 argtypes
[0].type
= lookup_pointer_type (type
);
1615 if (*p
!= ')') /* () means no args, skip while */
1620 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1622 /* Avoid parsing of ellipsis, they will be handled below.
1623 Also avoid ``void'' as above. */
1624 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0
1625 && strncmp (argtypetext
, "void", p
- argtypetext
) != 0)
1627 argtypes
[argcount
].type
=
1628 safe_parse_type (argtypetext
, p
- argtypetext
);
1631 argtypetext
= p
+ 1;
1634 if (*p
== '(' || *p
== '<')
1638 else if (*p
== ')' || *p
== '>')
1647 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1649 /* Now update the old "stub" type into a real type. */
1650 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1651 TYPE_DOMAIN_TYPE (mtype
) = type
;
1652 TYPE_FIELDS (mtype
) = argtypes
;
1653 TYPE_NFIELDS (mtype
) = argcount
;
1654 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1655 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1657 TYPE_FLAGS (mtype
) |= TYPE_FLAG_VARARGS
;
1659 xfree (demangled_name
);
1662 /* This is the external interface to check_stub_method, above. This function
1663 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1664 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1665 and TYPE_FN_FIELDLIST_NAME will be correct.
1667 This function unfortunately can not die until stabs do. */
1670 check_stub_method_group (struct type
*type
, int method_id
)
1672 int len
= TYPE_FN_FIELDLIST_LENGTH (type
, method_id
);
1673 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1674 int j
, found_stub
= 0;
1676 for (j
= 0; j
< len
; j
++)
1677 if (TYPE_FN_FIELD_STUB (f
, j
))
1680 check_stub_method (type
, method_id
, j
);
1683 /* GNU v3 methods with incorrect names were corrected when we read in
1684 type information, because it was cheaper to do it then. The only GNU v2
1685 methods with incorrect method names are operators and destructors;
1686 destructors were also corrected when we read in type information.
1688 Therefore the only thing we need to handle here are v2 operator
1690 if (found_stub
&& strncmp (TYPE_FN_FIELD_PHYSNAME (f
, 0), "_Z", 2) != 0)
1693 char dem_opname
[256];
1695 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1696 dem_opname
, DMGL_ANSI
);
1698 ret
= cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type
, method_id
),
1701 TYPE_FN_FIELDLIST_NAME (type
, method_id
) = xstrdup (dem_opname
);
1705 const struct cplus_struct_type cplus_struct_default
;
1708 allocate_cplus_struct_type (struct type
*type
)
1710 if (!HAVE_CPLUS_STRUCT (type
))
1712 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1713 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1714 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1718 /* Helper function to initialize the standard scalar types.
1720 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1721 of the string pointed to by name in the objfile_obstack for that objfile,
1722 and initialize the type name to that copy. There are places (mipsread.c
1723 in particular, where init_type is called with a NULL value for NAME). */
1726 init_type (enum type_code code
, int length
, int flags
, char *name
,
1727 struct objfile
*objfile
)
1731 type
= alloc_type (objfile
);
1732 TYPE_CODE (type
) = code
;
1733 TYPE_LENGTH (type
) = length
;
1734 TYPE_FLAGS (type
) |= flags
;
1735 if ((name
!= NULL
) && (objfile
!= NULL
))
1738 obsavestring (name
, strlen (name
), &objfile
->objfile_obstack
);
1742 TYPE_NAME (type
) = name
;
1747 if (name
&& strcmp (name
, "char") == 0)
1748 TYPE_FLAGS (type
) |= TYPE_FLAG_NOSIGN
;
1750 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
1751 || code
== TYPE_CODE_NAMESPACE
)
1753 INIT_CPLUS_SPECIFIC (type
);
1758 /* Helper function. Create an empty composite type. */
1761 init_composite_type (char *name
, enum type_code code
)
1764 gdb_assert (code
== TYPE_CODE_STRUCT
1765 || code
== TYPE_CODE_UNION
);
1766 t
= init_type (code
, 0, 0, NULL
, NULL
);
1767 TYPE_TAG_NAME (t
) = name
;
1771 /* Helper function. Append a field to a composite type. */
1774 append_composite_type_field (struct type
*t
, char *name
, struct type
*field
)
1777 TYPE_NFIELDS (t
) = TYPE_NFIELDS (t
) + 1;
1778 TYPE_FIELDS (t
) = xrealloc (TYPE_FIELDS (t
),
1779 sizeof (struct field
) * TYPE_NFIELDS (t
));
1780 f
= &(TYPE_FIELDS (t
)[TYPE_NFIELDS (t
) - 1]);
1781 memset (f
, 0, sizeof f
[0]);
1782 FIELD_TYPE (f
[0]) = field
;
1783 FIELD_NAME (f
[0]) = name
;
1784 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
1786 if (TYPE_LENGTH (t
) < TYPE_LENGTH (field
))
1787 TYPE_LENGTH (t
) = TYPE_LENGTH (field
);
1789 else if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
1791 TYPE_LENGTH (t
) = TYPE_LENGTH (t
) + TYPE_LENGTH (field
);
1792 if (TYPE_NFIELDS (t
) > 1)
1794 FIELD_BITPOS (f
[0]) = (FIELD_BITPOS (f
[-1])
1795 + TYPE_LENGTH (field
) * TARGET_CHAR_BIT
);
1800 /* Look up a fundamental type for the specified objfile.
1801 May need to construct such a type if this is the first use.
1803 Some object file formats (ELF, COFF, etc) do not define fundamental
1804 types such as "int" or "double". Others (stabs for example), do
1805 define fundamental types.
1807 For the formats which don't provide fundamental types, gdb can create
1808 such types, using defaults reasonable for the current language and
1809 the current target machine.
1811 NOTE: This routine is obsolescent. Each debugging format reader
1812 should manage it's own fundamental types, either creating them from
1813 suitable defaults or reading them from the debugging information,
1814 whichever is appropriate. The DWARF reader has already been
1815 fixed to do this. Once the other readers are fixed, this routine
1816 will go away. Also note that fundamental types should be managed
1817 on a compilation unit basis in a multi-language environment, not
1818 on a linkage unit basis as is done here. */
1822 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1824 struct type
**typep
;
1827 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1829 error (_("internal error - invalid fundamental type id %d"), typeid);
1832 /* If this is the first time we need a fundamental type for this objfile
1833 then we need to initialize the vector of type pointers. */
1835 if (objfile
->fundamental_types
== NULL
)
1837 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1838 objfile
->fundamental_types
= (struct type
**)
1839 obstack_alloc (&objfile
->objfile_obstack
, nbytes
);
1840 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1841 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1844 /* Look for this particular type in the fundamental type vector. If one is
1845 not found, create and install one appropriate for the current language. */
1847 typep
= objfile
->fundamental_types
+ typeid;
1850 *typep
= create_fundamental_type (objfile
, typeid);
1857 can_dereference (struct type
*t
)
1859 /* FIXME: Should we return true for references as well as pointers? */
1863 && TYPE_CODE (t
) == TYPE_CODE_PTR
1864 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1868 is_integral_type (struct type
*t
)
1873 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1874 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1875 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1876 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1877 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1880 /* Check whether BASE is an ancestor or base class or DCLASS
1881 Return 1 if so, and 0 if not.
1882 Note: callers may want to check for identity of the types before
1883 calling this function -- identical types are considered to satisfy
1884 the ancestor relationship even if they're identical */
1887 is_ancestor (struct type
*base
, struct type
*dclass
)
1891 CHECK_TYPEDEF (base
);
1892 CHECK_TYPEDEF (dclass
);
1896 if (TYPE_NAME (base
) && TYPE_NAME (dclass
) &&
1897 !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1900 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1901 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1909 /* See whether DCLASS has a virtual table. This routine is aimed at
1910 the HP/Taligent ANSI C++ runtime model, and may not work with other
1911 runtime models. Return 1 => Yes, 0 => No. */
1914 has_vtable (struct type
*dclass
)
1916 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1917 has virtual functions or virtual bases. */
1921 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1924 /* First check for the presence of virtual bases */
1925 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1926 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1927 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
1930 /* Next check for virtual functions */
1931 if (TYPE_FN_FIELDLISTS (dclass
))
1932 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
1933 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
1936 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1937 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1938 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1939 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
1940 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
1943 /* Well, maybe we don't need a virtual table */
1947 /* Return a pointer to the "primary base class" of DCLASS.
1949 A NULL return indicates that DCLASS has no primary base, or that it
1950 couldn't be found (insufficient information).
1952 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1953 and may not work with other runtime models. */
1956 primary_base_class (struct type
*dclass
)
1958 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1959 is the first directly inherited, non-virtual base class that
1960 requires a virtual table */
1964 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1967 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1968 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
1969 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
1970 return TYPE_FIELD_TYPE (dclass
, i
);
1975 /* Global manipulated by virtual_base_list[_aux]() */
1977 static struct vbase
*current_vbase_list
= NULL
;
1979 /* Return a pointer to a null-terminated list of struct vbase
1980 items. The vbasetype pointer of each item in the list points to the
1981 type information for a virtual base of the argument DCLASS.
1983 Helper function for virtual_base_list().
1984 Note: the list goes backward, right-to-left. virtual_base_list()
1985 copies the items out in reverse order. */
1988 virtual_base_list_aux (struct type
*dclass
)
1990 struct vbase
*tmp_vbase
;
1993 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1996 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1998 /* Recurse on this ancestor, first */
1999 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
2001 /* If this current base is itself virtual, add it to the list */
2002 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
2004 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
2006 /* Check if base already recorded */
2007 tmp_vbase
= current_vbase_list
;
2010 if (tmp_vbase
->vbasetype
== basetype
)
2011 break; /* found it */
2012 tmp_vbase
= tmp_vbase
->next
;
2015 if (!tmp_vbase
) /* normal exit from loop */
2017 /* Allocate new item for this virtual base */
2018 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
2020 /* Stick it on at the end of the list */
2021 tmp_vbase
->vbasetype
= basetype
;
2022 tmp_vbase
->next
= current_vbase_list
;
2023 current_vbase_list
= tmp_vbase
;
2026 } /* for loop over bases */
2030 /* Compute the list of virtual bases in the right order. Virtual
2031 bases are laid out in the object's memory area in order of their
2032 occurrence in a depth-first, left-to-right search through the
2035 Argument DCLASS is the type whose virtual bases are required.
2036 Return value is the address of a null-terminated array of pointers
2037 to struct type items.
2039 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2040 and may not work with other runtime models.
2042 This routine merely hands off the argument to virtual_base_list_aux()
2043 and then copies the result into an array to save space. */
2046 virtual_base_list (struct type
*dclass
)
2048 struct vbase
*tmp_vbase
;
2049 struct vbase
*tmp_vbase_2
;
2052 struct type
**vbase_array
;
2054 current_vbase_list
= NULL
;
2055 virtual_base_list_aux (dclass
);
2057 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2062 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
2064 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
2065 vbase_array
[i
] = tmp_vbase
->vbasetype
;
2067 /* Get rid of constructed chain */
2068 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
2071 tmp_vbase
= tmp_vbase
->next
;
2072 xfree (tmp_vbase_2
);
2073 tmp_vbase_2
= tmp_vbase
;
2076 vbase_array
[count
] = NULL
;
2080 /* Return the length of the virtual base list of the type DCLASS. */
2083 virtual_base_list_length (struct type
*dclass
)
2086 struct vbase
*tmp_vbase
;
2088 current_vbase_list
= NULL
;
2089 virtual_base_list_aux (dclass
);
2091 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
2096 /* Return the number of elements of the virtual base list of the type
2097 DCLASS, ignoring those appearing in the primary base (and its
2098 primary base, recursively). */
2101 virtual_base_list_length_skip_primaries (struct type
*dclass
)
2104 struct vbase
*tmp_vbase
;
2105 struct type
*primary
;
2107 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2110 return virtual_base_list_length (dclass
);
2112 current_vbase_list
= NULL
;
2113 virtual_base_list_aux (dclass
);
2115 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
2117 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
2125 /* Return the index (position) of type BASE, which is a virtual base
2126 class of DCLASS, in the latter's virtual base list. A return of -1
2127 indicates "not found" or a problem. */
2130 virtual_base_index (struct type
*base
, struct type
*dclass
)
2135 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2136 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2140 vbase
= virtual_base_list (dclass
)[0];
2145 vbase
= virtual_base_list (dclass
)[++i
];
2148 return vbase
? i
: -1;
2153 /* Return the index (position) of type BASE, which is a virtual base
2154 class of DCLASS, in the latter's virtual base list. Skip over all
2155 bases that may appear in the virtual base list of the primary base
2156 class of DCLASS (recursively). A return of -1 indicates "not
2157 found" or a problem. */
2160 virtual_base_index_skip_primaries (struct type
*base
, struct type
*dclass
)
2164 struct type
*primary
;
2166 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2167 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2170 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2174 vbase
= virtual_base_list (dclass
)[0];
2177 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
2181 vbase
= virtual_base_list (dclass
)[++i
];
2184 return vbase
? j
: -1;
2187 /* Return position of a derived class DCLASS in the list of
2188 * primary bases starting with the remotest ancestor.
2189 * Position returned is 0-based. */
2192 class_index_in_primary_list (struct type
*dclass
)
2194 struct type
*pbc
; /* primary base class */
2196 /* Simply recurse on primary base */
2197 pbc
= TYPE_PRIMARY_BASE (dclass
);
2199 return 1 + class_index_in_primary_list (pbc
);
2204 /* Return a count of the number of virtual functions a type has.
2205 * This includes all the virtual functions it inherits from its
2209 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2210 * functions only once (latest redefinition)
2214 count_virtual_fns (struct type
*dclass
)
2216 int fn
, oi
; /* function and overloaded instance indices */
2217 int vfuncs
; /* count to return */
2219 /* recurse on bases that can share virtual table */
2220 struct type
*pbc
= primary_base_class (dclass
);
2222 vfuncs
= count_virtual_fns (pbc
);
2226 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2227 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2228 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2236 /* Functions for overload resolution begin here */
2238 /* Compare two badness vectors A and B and return the result.
2239 * 0 => A and B are identical
2240 * 1 => A and B are incomparable
2241 * 2 => A is better than B
2242 * 3 => A is worse than B */
2245 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2249 short found_pos
= 0; /* any positives in c? */
2250 short found_neg
= 0; /* any negatives in c? */
2252 /* differing lengths => incomparable */
2253 if (a
->length
!= b
->length
)
2256 /* Subtract b from a */
2257 for (i
= 0; i
< a
->length
; i
++)
2259 tmp
= a
->rank
[i
] - b
->rank
[i
];
2269 return 1; /* incomparable */
2271 return 3; /* A > B */
2277 return 2; /* A < B */
2279 return 0; /* A == B */
2283 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2284 * to the types of an argument list (ARGS, length NARGS).
2285 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2287 struct badness_vector
*
2288 rank_function (struct type
**parms
, int nparms
, struct type
**args
, int nargs
)
2291 struct badness_vector
*bv
;
2292 int min_len
= nparms
< nargs
? nparms
: nargs
;
2294 bv
= xmalloc (sizeof (struct badness_vector
));
2295 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2296 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2298 /* First compare the lengths of the supplied lists.
2299 * If there is a mismatch, set it to a high value. */
2301 /* pai/1997-06-03 FIXME: when we have debug info about default
2302 * arguments and ellipsis parameter lists, we should consider those
2303 * and rank the length-match more finely. */
2305 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2307 /* Now rank all the parameters of the candidate function */
2308 for (i
= 1; i
<= min_len
; i
++)
2309 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2311 /* If more arguments than parameters, add dummy entries */
2312 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2313 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2318 /* Compare the names of two integer types, assuming that any sign
2319 qualifiers have been checked already. We do it this way because
2320 there may be an "int" in the name of one of the types. */
2323 integer_types_same_name_p (const char *first
, const char *second
)
2325 int first_p
, second_p
;
2327 /* If both are shorts, return 1; if neither is a short, keep checking. */
2328 first_p
= (strstr (first
, "short") != NULL
);
2329 second_p
= (strstr (second
, "short") != NULL
);
2330 if (first_p
&& second_p
)
2332 if (first_p
|| second_p
)
2335 /* Likewise for long. */
2336 first_p
= (strstr (first
, "long") != NULL
);
2337 second_p
= (strstr (second
, "long") != NULL
);
2338 if (first_p
&& second_p
)
2340 if (first_p
|| second_p
)
2343 /* Likewise for char. */
2344 first_p
= (strstr (first
, "char") != NULL
);
2345 second_p
= (strstr (second
, "char") != NULL
);
2346 if (first_p
&& second_p
)
2348 if (first_p
|| second_p
)
2351 /* They must both be ints. */
2355 /* Compare one type (PARM) for compatibility with another (ARG).
2356 * PARM is intended to be the parameter type of a function; and
2357 * ARG is the supplied argument's type. This function tests if
2358 * the latter can be converted to the former.
2360 * Return 0 if they are identical types;
2361 * Otherwise, return an integer which corresponds to how compatible
2362 * PARM is to ARG. The higher the return value, the worse the match.
2363 * Generally the "bad" conversions are all uniformly assigned a 100 */
2366 rank_one_type (struct type
*parm
, struct type
*arg
)
2368 /* Identical type pointers */
2369 /* However, this still doesn't catch all cases of same type for arg
2370 * and param. The reason is that builtin types are different from
2371 * the same ones constructed from the object. */
2375 /* Resolve typedefs */
2376 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2377 parm
= check_typedef (parm
);
2378 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2379 arg
= check_typedef (arg
);
2382 Well, damnit, if the names are exactly the same,
2383 i'll say they are exactly the same. This happens when we generate
2384 method stubs. The types won't point to the same address, but they
2385 really are the same.
2388 if (TYPE_NAME (parm
) && TYPE_NAME (arg
) &&
2389 !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2392 /* Check if identical after resolving typedefs */
2396 /* See through references, since we can almost make non-references
2398 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2399 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2400 + REFERENCE_CONVERSION_BADNESS
);
2401 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2402 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2403 + REFERENCE_CONVERSION_BADNESS
);
2405 /* Debugging only. */
2406 fprintf_filtered (gdb_stderr
,"------ Arg is %s [%d], parm is %s [%d]\n",
2407 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2409 /* x -> y means arg of type x being supplied for parameter of type y */
2411 switch (TYPE_CODE (parm
))
2414 switch (TYPE_CODE (arg
))
2417 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2418 return VOID_PTR_CONVERSION_BADNESS
;
2420 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2421 case TYPE_CODE_ARRAY
:
2422 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2423 case TYPE_CODE_FUNC
:
2424 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2426 case TYPE_CODE_ENUM
:
2427 case TYPE_CODE_CHAR
:
2428 case TYPE_CODE_RANGE
:
2429 case TYPE_CODE_BOOL
:
2430 return POINTER_CONVERSION_BADNESS
;
2432 return INCOMPATIBLE_TYPE_BADNESS
;
2434 case TYPE_CODE_ARRAY
:
2435 switch (TYPE_CODE (arg
))
2438 case TYPE_CODE_ARRAY
:
2439 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2441 return INCOMPATIBLE_TYPE_BADNESS
;
2443 case TYPE_CODE_FUNC
:
2444 switch (TYPE_CODE (arg
))
2446 case TYPE_CODE_PTR
: /* funcptr -> func */
2447 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2449 return INCOMPATIBLE_TYPE_BADNESS
;
2452 switch (TYPE_CODE (arg
))
2455 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2457 /* Deal with signed, unsigned, and plain chars and
2458 signed and unsigned ints */
2459 if (TYPE_NOSIGN (parm
))
2461 /* This case only for character types */
2462 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2465 return INTEGER_CONVERSION_BADNESS
; /* signed/unsigned char -> plain char */
2467 else if (TYPE_UNSIGNED (parm
))
2469 if (TYPE_UNSIGNED (arg
))
2471 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2472 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2474 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2475 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2476 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2478 return INTEGER_CONVERSION_BADNESS
; /* unsigned long -> unsigned int */
2482 if (integer_types_same_name_p (TYPE_NAME (arg
), "long")
2483 && integer_types_same_name_p (TYPE_NAME (parm
), "int"))
2484 return INTEGER_CONVERSION_BADNESS
; /* signed long -> unsigned int */
2486 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2489 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2491 if (integer_types_same_name_p (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2493 else if (integer_types_same_name_p (TYPE_NAME (arg
), "int")
2494 && integer_types_same_name_p (TYPE_NAME (parm
), "long"))
2495 return INTEGER_PROMOTION_BADNESS
;
2497 return INTEGER_CONVERSION_BADNESS
;
2500 return INTEGER_CONVERSION_BADNESS
;
2502 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2503 return INTEGER_PROMOTION_BADNESS
;
2505 return INTEGER_CONVERSION_BADNESS
;
2506 case TYPE_CODE_ENUM
:
2507 case TYPE_CODE_CHAR
:
2508 case TYPE_CODE_RANGE
:
2509 case TYPE_CODE_BOOL
:
2510 return INTEGER_PROMOTION_BADNESS
;
2512 return INT_FLOAT_CONVERSION_BADNESS
;
2514 return NS_POINTER_CONVERSION_BADNESS
;
2516 return INCOMPATIBLE_TYPE_BADNESS
;
2519 case TYPE_CODE_ENUM
:
2520 switch (TYPE_CODE (arg
))
2523 case TYPE_CODE_CHAR
:
2524 case TYPE_CODE_RANGE
:
2525 case TYPE_CODE_BOOL
:
2526 case TYPE_CODE_ENUM
:
2527 return INTEGER_CONVERSION_BADNESS
;
2529 return INT_FLOAT_CONVERSION_BADNESS
;
2531 return INCOMPATIBLE_TYPE_BADNESS
;
2534 case TYPE_CODE_CHAR
:
2535 switch (TYPE_CODE (arg
))
2537 case TYPE_CODE_RANGE
:
2538 case TYPE_CODE_BOOL
:
2539 case TYPE_CODE_ENUM
:
2540 return INTEGER_CONVERSION_BADNESS
;
2542 return INT_FLOAT_CONVERSION_BADNESS
;
2544 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2545 return INTEGER_CONVERSION_BADNESS
;
2546 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2547 return INTEGER_PROMOTION_BADNESS
;
2548 /* >>> !! else fall through !! <<< */
2549 case TYPE_CODE_CHAR
:
2550 /* Deal with signed, unsigned, and plain chars for C++
2551 and with int cases falling through from previous case */
2552 if (TYPE_NOSIGN (parm
))
2554 if (TYPE_NOSIGN (arg
))
2557 return INTEGER_CONVERSION_BADNESS
;
2559 else if (TYPE_UNSIGNED (parm
))
2561 if (TYPE_UNSIGNED (arg
))
2564 return INTEGER_PROMOTION_BADNESS
;
2566 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2569 return INTEGER_CONVERSION_BADNESS
;
2571 return INCOMPATIBLE_TYPE_BADNESS
;
2574 case TYPE_CODE_RANGE
:
2575 switch (TYPE_CODE (arg
))
2578 case TYPE_CODE_CHAR
:
2579 case TYPE_CODE_RANGE
:
2580 case TYPE_CODE_BOOL
:
2581 case TYPE_CODE_ENUM
:
2582 return INTEGER_CONVERSION_BADNESS
;
2584 return INT_FLOAT_CONVERSION_BADNESS
;
2586 return INCOMPATIBLE_TYPE_BADNESS
;
2589 case TYPE_CODE_BOOL
:
2590 switch (TYPE_CODE (arg
))
2593 case TYPE_CODE_CHAR
:
2594 case TYPE_CODE_RANGE
:
2595 case TYPE_CODE_ENUM
:
2598 return BOOLEAN_CONVERSION_BADNESS
;
2599 case TYPE_CODE_BOOL
:
2602 return INCOMPATIBLE_TYPE_BADNESS
;
2606 switch (TYPE_CODE (arg
))
2609 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2610 return FLOAT_PROMOTION_BADNESS
;
2611 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2614 return FLOAT_CONVERSION_BADNESS
;
2616 case TYPE_CODE_BOOL
:
2617 case TYPE_CODE_ENUM
:
2618 case TYPE_CODE_RANGE
:
2619 case TYPE_CODE_CHAR
:
2620 return INT_FLOAT_CONVERSION_BADNESS
;
2622 return INCOMPATIBLE_TYPE_BADNESS
;
2625 case TYPE_CODE_COMPLEX
:
2626 switch (TYPE_CODE (arg
))
2627 { /* Strictly not needed for C++, but... */
2629 return FLOAT_PROMOTION_BADNESS
;
2630 case TYPE_CODE_COMPLEX
:
2633 return INCOMPATIBLE_TYPE_BADNESS
;
2636 case TYPE_CODE_STRUCT
:
2637 /* currently same as TYPE_CODE_CLASS */
2638 switch (TYPE_CODE (arg
))
2640 case TYPE_CODE_STRUCT
:
2641 /* Check for derivation */
2642 if (is_ancestor (parm
, arg
))
2643 return BASE_CONVERSION_BADNESS
;
2644 /* else fall through */
2646 return INCOMPATIBLE_TYPE_BADNESS
;
2649 case TYPE_CODE_UNION
:
2650 switch (TYPE_CODE (arg
))
2652 case TYPE_CODE_UNION
:
2654 return INCOMPATIBLE_TYPE_BADNESS
;
2657 case TYPE_CODE_MEMBER
:
2658 switch (TYPE_CODE (arg
))
2661 return INCOMPATIBLE_TYPE_BADNESS
;
2664 case TYPE_CODE_METHOD
:
2665 switch (TYPE_CODE (arg
))
2669 return INCOMPATIBLE_TYPE_BADNESS
;
2673 switch (TYPE_CODE (arg
))
2677 return INCOMPATIBLE_TYPE_BADNESS
;
2682 switch (TYPE_CODE (arg
))
2686 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2688 return INCOMPATIBLE_TYPE_BADNESS
;
2691 case TYPE_CODE_VOID
:
2693 return INCOMPATIBLE_TYPE_BADNESS
;
2694 } /* switch (TYPE_CODE (arg)) */
2698 /* End of functions for overload resolution */
2701 print_bit_vector (B_TYPE
*bits
, int nbits
)
2705 for (bitno
= 0; bitno
< nbits
; bitno
++)
2707 if ((bitno
% 8) == 0)
2709 puts_filtered (" ");
2711 if (B_TST (bits
, bitno
))
2712 printf_filtered (("1"));
2714 printf_filtered (("0"));
2718 /* Note the first arg should be the "this" pointer, we may not want to
2719 include it since we may get into a infinitely recursive situation. */
2722 print_arg_types (struct field
*args
, int nargs
, int spaces
)
2728 for (i
= 0; i
< nargs
; i
++)
2729 recursive_dump_type (args
[i
].type
, spaces
+ 2);
2734 dump_fn_fieldlists (struct type
*type
, int spaces
)
2740 printfi_filtered (spaces
, "fn_fieldlists ");
2741 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2742 printf_filtered ("\n");
2743 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2745 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2746 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2748 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2749 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2751 printf_filtered (_(") length %d\n"),
2752 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2753 for (overload_idx
= 0;
2754 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2757 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2759 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2760 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2762 printf_filtered (")\n");
2763 printfi_filtered (spaces
+ 8, "type ");
2764 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2765 printf_filtered ("\n");
2767 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2770 printfi_filtered (spaces
+ 8, "args ");
2771 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2772 printf_filtered ("\n");
2774 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
),
2775 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f
, overload_idx
)),
2777 printfi_filtered (spaces
+ 8, "fcontext ");
2778 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2780 printf_filtered ("\n");
2782 printfi_filtered (spaces
+ 8, "is_const %d\n",
2783 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2784 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2785 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2786 printfi_filtered (spaces
+ 8, "is_private %d\n",
2787 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2788 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2789 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2790 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2791 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2792 printfi_filtered (spaces
+ 8, "voffset %u\n",
2793 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2799 print_cplus_stuff (struct type
*type
, int spaces
)
2801 printfi_filtered (spaces
, "n_baseclasses %d\n",
2802 TYPE_N_BASECLASSES (type
));
2803 printfi_filtered (spaces
, "nfn_fields %d\n",
2804 TYPE_NFN_FIELDS (type
));
2805 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2806 TYPE_NFN_FIELDS_TOTAL (type
));
2807 if (TYPE_N_BASECLASSES (type
) > 0)
2809 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2810 TYPE_N_BASECLASSES (type
));
2811 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2812 printf_filtered (")");
2814 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2815 TYPE_N_BASECLASSES (type
));
2816 puts_filtered ("\n");
2818 if (TYPE_NFIELDS (type
) > 0)
2820 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2822 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2823 TYPE_NFIELDS (type
));
2824 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2825 printf_filtered (")");
2826 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2827 TYPE_NFIELDS (type
));
2828 puts_filtered ("\n");
2830 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2832 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2833 TYPE_NFIELDS (type
));
2834 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2835 printf_filtered (")");
2836 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2837 TYPE_NFIELDS (type
));
2838 puts_filtered ("\n");
2841 if (TYPE_NFN_FIELDS (type
) > 0)
2843 dump_fn_fieldlists (type
, spaces
);
2848 print_bound_type (int bt
)
2852 case BOUND_CANNOT_BE_DETERMINED
:
2853 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2855 case BOUND_BY_REF_ON_STACK
:
2856 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2858 case BOUND_BY_VALUE_ON_STACK
:
2859 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2861 case BOUND_BY_REF_IN_REG
:
2862 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2864 case BOUND_BY_VALUE_IN_REG
:
2865 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2868 printf_filtered ("(BOUND_SIMPLE)");
2871 printf_filtered (_("(unknown bound type)"));
2876 static struct obstack dont_print_type_obstack
;
2879 recursive_dump_type (struct type
*type
, int spaces
)
2884 obstack_begin (&dont_print_type_obstack
, 0);
2886 if (TYPE_NFIELDS (type
) > 0
2887 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2889 struct type
**first_dont_print
2890 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2892 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
2897 if (type
== first_dont_print
[i
])
2899 printfi_filtered (spaces
, "type node ");
2900 gdb_print_host_address (type
, gdb_stdout
);
2901 printf_filtered (_(" <same as already seen type>\n"));
2906 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2909 printfi_filtered (spaces
, "type node ");
2910 gdb_print_host_address (type
, gdb_stdout
);
2911 printf_filtered ("\n");
2912 printfi_filtered (spaces
, "name '%s' (",
2913 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2914 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2915 printf_filtered (")\n");
2916 printfi_filtered (spaces
, "tagname '%s' (",
2917 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2918 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2919 printf_filtered (")\n");
2920 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2921 switch (TYPE_CODE (type
))
2923 case TYPE_CODE_UNDEF
:
2924 printf_filtered ("(TYPE_CODE_UNDEF)");
2927 printf_filtered ("(TYPE_CODE_PTR)");
2929 case TYPE_CODE_ARRAY
:
2930 printf_filtered ("(TYPE_CODE_ARRAY)");
2932 case TYPE_CODE_STRUCT
:
2933 printf_filtered ("(TYPE_CODE_STRUCT)");
2935 case TYPE_CODE_UNION
:
2936 printf_filtered ("(TYPE_CODE_UNION)");
2938 case TYPE_CODE_ENUM
:
2939 printf_filtered ("(TYPE_CODE_ENUM)");
2941 case TYPE_CODE_FUNC
:
2942 printf_filtered ("(TYPE_CODE_FUNC)");
2945 printf_filtered ("(TYPE_CODE_INT)");
2948 printf_filtered ("(TYPE_CODE_FLT)");
2950 case TYPE_CODE_VOID
:
2951 printf_filtered ("(TYPE_CODE_VOID)");
2954 printf_filtered ("(TYPE_CODE_SET)");
2956 case TYPE_CODE_RANGE
:
2957 printf_filtered ("(TYPE_CODE_RANGE)");
2959 case TYPE_CODE_STRING
:
2960 printf_filtered ("(TYPE_CODE_STRING)");
2962 case TYPE_CODE_BITSTRING
:
2963 printf_filtered ("(TYPE_CODE_BITSTRING)");
2965 case TYPE_CODE_ERROR
:
2966 printf_filtered ("(TYPE_CODE_ERROR)");
2968 case TYPE_CODE_MEMBER
:
2969 printf_filtered ("(TYPE_CODE_MEMBER)");
2971 case TYPE_CODE_METHOD
:
2972 printf_filtered ("(TYPE_CODE_METHOD)");
2975 printf_filtered ("(TYPE_CODE_REF)");
2977 case TYPE_CODE_CHAR
:
2978 printf_filtered ("(TYPE_CODE_CHAR)");
2980 case TYPE_CODE_BOOL
:
2981 printf_filtered ("(TYPE_CODE_BOOL)");
2983 case TYPE_CODE_COMPLEX
:
2984 printf_filtered ("(TYPE_CODE_COMPLEX)");
2986 case TYPE_CODE_TYPEDEF
:
2987 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2989 case TYPE_CODE_TEMPLATE
:
2990 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2992 case TYPE_CODE_TEMPLATE_ARG
:
2993 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2995 case TYPE_CODE_NAMESPACE
:
2996 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2999 printf_filtered ("(UNKNOWN TYPE CODE)");
3002 puts_filtered ("\n");
3003 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
3004 printfi_filtered (spaces
, "upper_bound_type 0x%x ",
3005 TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3006 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
3007 puts_filtered ("\n");
3008 printfi_filtered (spaces
, "lower_bound_type 0x%x ",
3009 TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3010 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
3011 puts_filtered ("\n");
3012 printfi_filtered (spaces
, "objfile ");
3013 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
3014 printf_filtered ("\n");
3015 printfi_filtered (spaces
, "target_type ");
3016 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
3017 printf_filtered ("\n");
3018 if (TYPE_TARGET_TYPE (type
) != NULL
)
3020 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
3022 printfi_filtered (spaces
, "pointer_type ");
3023 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
3024 printf_filtered ("\n");
3025 printfi_filtered (spaces
, "reference_type ");
3026 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
3027 printf_filtered ("\n");
3028 printfi_filtered (spaces
, "type_chain ");
3029 gdb_print_host_address (TYPE_CHAIN (type
), gdb_stdout
);
3030 printf_filtered ("\n");
3031 printfi_filtered (spaces
, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type
));
3032 if (TYPE_CONST (type
))
3034 puts_filtered (" TYPE_FLAG_CONST");
3036 if (TYPE_VOLATILE (type
))
3038 puts_filtered (" TYPE_FLAG_VOLATILE");
3040 if (TYPE_CODE_SPACE (type
))
3042 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3044 if (TYPE_DATA_SPACE (type
))
3046 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3048 if (TYPE_ADDRESS_CLASS_1 (type
))
3050 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3052 if (TYPE_ADDRESS_CLASS_2 (type
))
3054 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3056 puts_filtered ("\n");
3057 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
3058 if (TYPE_UNSIGNED (type
))
3060 puts_filtered (" TYPE_FLAG_UNSIGNED");
3062 if (TYPE_NOSIGN (type
))
3064 puts_filtered (" TYPE_FLAG_NOSIGN");
3066 if (TYPE_STUB (type
))
3068 puts_filtered (" TYPE_FLAG_STUB");
3070 if (TYPE_TARGET_STUB (type
))
3072 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3074 if (TYPE_STATIC (type
))
3076 puts_filtered (" TYPE_FLAG_STATIC");
3078 if (TYPE_PROTOTYPED (type
))
3080 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3082 if (TYPE_INCOMPLETE (type
))
3084 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3086 if (TYPE_VARARGS (type
))
3088 puts_filtered (" TYPE_FLAG_VARARGS");
3090 /* This is used for things like AltiVec registers on ppc. Gcc emits
3091 an attribute for the array type, which tells whether or not we
3092 have a vector, instead of a regular array. */
3093 if (TYPE_VECTOR (type
))
3095 puts_filtered (" TYPE_FLAG_VECTOR");
3097 puts_filtered ("\n");
3098 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
3099 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
3100 puts_filtered ("\n");
3101 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
3103 printfi_filtered (spaces
+ 2,
3104 "[%d] bitpos %d bitsize %d type ",
3105 idx
, TYPE_FIELD_BITPOS (type
, idx
),
3106 TYPE_FIELD_BITSIZE (type
, idx
));
3107 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
3108 printf_filtered (" name '%s' (",
3109 TYPE_FIELD_NAME (type
, idx
) != NULL
3110 ? TYPE_FIELD_NAME (type
, idx
)
3112 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
3113 printf_filtered (")\n");
3114 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
3116 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
3119 printfi_filtered (spaces
, "vptr_basetype ");
3120 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
3121 puts_filtered ("\n");
3122 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
3124 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
3126 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
3127 switch (TYPE_CODE (type
))
3129 case TYPE_CODE_STRUCT
:
3130 printfi_filtered (spaces
, "cplus_stuff ");
3131 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3132 puts_filtered ("\n");
3133 print_cplus_stuff (type
, spaces
);
3137 printfi_filtered (spaces
, "floatformat ");
3138 if (TYPE_FLOATFORMAT (type
) == NULL
3139 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
3140 puts_filtered ("(null)");
3142 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
3143 puts_filtered ("\n");
3147 /* We have to pick one of the union types to be able print and test
3148 the value. Pick cplus_struct_type, even though we know it isn't
3149 any particular one. */
3150 printfi_filtered (spaces
, "type_specific ");
3151 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3152 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
3154 printf_filtered (_(" (unknown data form)"));
3156 printf_filtered ("\n");
3161 obstack_free (&dont_print_type_obstack
, NULL
);
3164 static void build_gdbtypes (void);
3166 build_gdbtypes (void)
3169 init_type (TYPE_CODE_VOID
, 1,
3171 "void", (struct objfile
*) NULL
);
3173 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3175 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3176 "char", (struct objfile
*) NULL
);
3177 builtin_type_true_char
=
3178 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3180 "true character", (struct objfile
*) NULL
);
3181 builtin_type_signed_char
=
3182 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3184 "signed char", (struct objfile
*) NULL
);
3185 builtin_type_unsigned_char
=
3186 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3188 "unsigned char", (struct objfile
*) NULL
);
3189 builtin_type_short
=
3190 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3192 "short", (struct objfile
*) NULL
);
3193 builtin_type_unsigned_short
=
3194 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3196 "unsigned short", (struct objfile
*) NULL
);
3198 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3200 "int", (struct objfile
*) NULL
);
3201 builtin_type_unsigned_int
=
3202 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3204 "unsigned int", (struct objfile
*) NULL
);
3206 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3208 "long", (struct objfile
*) NULL
);
3209 builtin_type_unsigned_long
=
3210 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3212 "unsigned long", (struct objfile
*) NULL
);
3213 builtin_type_long_long
=
3214 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3216 "long long", (struct objfile
*) NULL
);
3217 builtin_type_unsigned_long_long
=
3218 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3220 "unsigned long long", (struct objfile
*) NULL
);
3221 builtin_type_float
=
3222 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3224 "float", (struct objfile
*) NULL
);
3225 /* vinschen@redhat.com 2002-02-08:
3226 The below lines are disabled since they are doing the wrong
3227 thing for non-multiarch targets. They are setting the correct
3228 type of floats for the target but while on multiarch targets
3229 this is done everytime the architecture changes, it's done on
3230 non-multiarch targets only on startup, leaving the wrong values
3231 in even if the architecture changes (eg. from big-endian to
3234 TYPE_FLOATFORMAT (builtin_type_float
) = TARGET_FLOAT_FORMAT
;
3236 builtin_type_double
=
3237 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3239 "double", (struct objfile
*) NULL
);
3241 TYPE_FLOATFORMAT (builtin_type_double
) = TARGET_DOUBLE_FORMAT
;
3243 builtin_type_long_double
=
3244 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3246 "long double", (struct objfile
*) NULL
);
3248 TYPE_FLOATFORMAT (builtin_type_long_double
) = TARGET_LONG_DOUBLE_FORMAT
;
3250 builtin_type_complex
=
3251 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3253 "complex", (struct objfile
*) NULL
);
3254 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
3255 builtin_type_double_complex
=
3256 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3258 "double complex", (struct objfile
*) NULL
);
3259 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
3260 builtin_type_string
=
3261 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3263 "string", (struct objfile
*) NULL
);
3265 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3267 "bool", (struct objfile
*) NULL
);
3269 /* Add user knob for controlling resolution of opaque types */
3270 add_setshow_boolean_cmd ("opaque-type-resolution", class_support
,
3271 &opaque_type_resolution
, _("\
3272 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3273 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL
,
3275 show_opaque_type_resolution
,
3276 &setlist
, &showlist
);
3277 opaque_type_resolution
= 1;
3279 /* Build SIMD types. */
3281 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
3283 = init_simd_type ("__builtin_v4si", builtin_type_int32
, "f", 4);
3285 = init_simd_type ("__builtin_v16qi", builtin_type_int8
, "f", 16);
3287 = init_simd_type ("__builtin_v8qi", builtin_type_int8
, "f", 8);
3289 = init_simd_type ("__builtin_v8hi", builtin_type_int16
, "f", 8);
3291 = init_simd_type ("__builtin_v4hi", builtin_type_int16
, "f", 4);
3293 = init_simd_type ("__builtin_v2si", builtin_type_int32
, "f", 2);
3295 /* 128 bit vectors. */
3296 builtin_type_v2_double
= init_vector_type (builtin_type_double
, 2);
3297 builtin_type_v4_float
= init_vector_type (builtin_type_float
, 4);
3298 builtin_type_v2_int64
= init_vector_type (builtin_type_int64
, 2);
3299 builtin_type_v4_int32
= init_vector_type (builtin_type_int32
, 4);
3300 builtin_type_v8_int16
= init_vector_type (builtin_type_int16
, 8);
3301 builtin_type_v16_int8
= init_vector_type (builtin_type_int8
, 16);
3302 /* 64 bit vectors. */
3303 builtin_type_v2_float
= init_vector_type (builtin_type_float
, 2);
3304 builtin_type_v2_int32
= init_vector_type (builtin_type_int32
, 2);
3305 builtin_type_v4_int16
= init_vector_type (builtin_type_int16
, 4);
3306 builtin_type_v8_int8
= init_vector_type (builtin_type_int8
, 8);
3309 builtin_type_vec64
= build_builtin_type_vec64 ();
3310 builtin_type_vec64i
= build_builtin_type_vec64i ();
3311 builtin_type_vec128
= build_builtin_type_vec128 ();
3312 builtin_type_vec128i
= build_builtin_type_vec128i ();
3314 /* Pointer/Address types. */
3316 /* NOTE: on some targets, addresses and pointers are not necessarily
3317 the same --- for example, on the D10V, pointers are 16 bits long,
3318 but addresses are 32 bits long. See doc/gdbint.texinfo,
3319 ``Pointers Are Not Always Addresses''.
3322 - gdb's `struct type' always describes the target's
3324 - gdb's `struct value' objects should always hold values in
3326 - gdb's CORE_ADDR values are addresses in the unified virtual
3327 address space that the assembler and linker work with. Thus,
3328 since target_read_memory takes a CORE_ADDR as an argument, it
3329 can access any memory on the target, even if the processor has
3330 separate code and data address spaces.
3333 - If v is a value holding a D10V code pointer, its contents are
3334 in target form: a big-endian address left-shifted two bits.
3335 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3336 sizeof (void *) == 2 on the target.
3338 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3339 target type for a value the target will never see. It's only
3340 used to hold the values of (typeless) linker symbols, which are
3341 indeed in the unified virtual address space. */
3342 builtin_type_void_data_ptr
= make_pointer_type (builtin_type_void
, NULL
);
3343 builtin_type_void_func_ptr
3344 = lookup_pointer_type (lookup_function_type (builtin_type_void
));
3345 builtin_type_CORE_ADDR
=
3346 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3348 "__CORE_ADDR", (struct objfile
*) NULL
);
3349 builtin_type_bfd_vma
=
3350 init_type (TYPE_CODE_INT
, TARGET_BFD_VMA_BIT
/ 8,
3352 "__bfd_vma", (struct objfile
*) NULL
);
3355 static struct gdbarch_data
*gdbtypes_data
;
3357 const struct builtin_type
*
3358 builtin_type (struct gdbarch
*gdbarch
)
3360 return gdbarch_data (gdbarch
, gdbtypes_data
);
3364 static struct type
*
3365 build_flt (int bit
, char *name
, const struct floatformat
*floatformat
)
3368 if (bit
<= 0 || floatformat
== NULL
)
3370 gdb_assert (builtin_type_error
!= NULL
);
3371 return builtin_type_error
;
3373 t
= init_type (TYPE_CODE_FLT
, bit
/ TARGET_CHAR_BIT
,
3374 0, name
, (struct objfile
*) NULL
);
3375 TYPE_FLOATFORMAT (t
) = floatformat
;
3379 static struct type
*
3380 build_complex (int bit
, char *name
, struct type
*target_type
)
3383 if (bit
<= 0 || target_type
== builtin_type_error
)
3385 gdb_assert (builtin_type_error
!= NULL
);
3386 return builtin_type_error
;
3388 t
= init_type (TYPE_CODE_COMPLEX
, 2 * bit
/ TARGET_CHAR_BIT
,
3389 0, name
, (struct objfile
*) NULL
);
3390 TYPE_TARGET_TYPE (t
) = target_type
;
3395 gdbtypes_post_init (struct gdbarch
*gdbarch
)
3397 struct builtin_type
*builtin_type
3398 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_type
);
3400 builtin_type
->builtin_void
=
3401 init_type (TYPE_CODE_VOID
, 1,
3403 "void", (struct objfile
*) NULL
);
3404 builtin_type
->builtin_char
=
3405 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3407 | (TARGET_CHAR_SIGNED
? 0 : TYPE_FLAG_UNSIGNED
)),
3408 "char", (struct objfile
*) NULL
);
3409 builtin_type
->builtin_true_char
=
3410 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3412 "true character", (struct objfile
*) NULL
);
3413 builtin_type
->builtin_signed_char
=
3414 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3416 "signed char", (struct objfile
*) NULL
);
3417 builtin_type
->builtin_unsigned_char
=
3418 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3420 "unsigned char", (struct objfile
*) NULL
);
3421 builtin_type
->builtin_short
=
3422 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3424 "short", (struct objfile
*) NULL
);
3425 builtin_type
->builtin_unsigned_short
=
3426 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3428 "unsigned short", (struct objfile
*) NULL
);
3429 builtin_type
->builtin_int
=
3430 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3432 "int", (struct objfile
*) NULL
);
3433 builtin_type
->builtin_unsigned_int
=
3434 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3436 "unsigned int", (struct objfile
*) NULL
);
3437 builtin_type
->builtin_long
=
3438 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3440 "long", (struct objfile
*) NULL
);
3441 builtin_type
->builtin_unsigned_long
=
3442 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3444 "unsigned long", (struct objfile
*) NULL
);
3445 builtin_type
->builtin_long_long
=
3446 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3448 "long long", (struct objfile
*) NULL
);
3449 builtin_type
->builtin_unsigned_long_long
=
3450 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3452 "unsigned long long", (struct objfile
*) NULL
);
3453 builtin_type
->builtin_float
3454 = build_flt (gdbarch_float_bit (gdbarch
), "float",
3455 gdbarch_float_format (gdbarch
));
3456 builtin_type
->builtin_double
3457 = build_flt (gdbarch_double_bit (gdbarch
), "double",
3458 gdbarch_double_format (gdbarch
));
3459 builtin_type
->builtin_long_double
3460 = build_flt (gdbarch_long_double_bit (gdbarch
), "long double",
3461 gdbarch_long_double_format (gdbarch
));
3462 builtin_type
->builtin_complex
3463 = build_complex (gdbarch_float_bit (gdbarch
), "complex",
3464 builtin_type
->builtin_float
);
3465 builtin_type
->builtin_double_complex
3466 = build_complex (gdbarch_double_bit (gdbarch
), "double complex",
3467 builtin_type
->builtin_double
);
3468 builtin_type
->builtin_string
=
3469 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3471 "string", (struct objfile
*) NULL
);
3472 builtin_type
->builtin_bool
=
3473 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3475 "bool", (struct objfile
*) NULL
);
3477 /* Pointer/Address types. */
3479 /* NOTE: on some targets, addresses and pointers are not necessarily
3480 the same --- for example, on the D10V, pointers are 16 bits long,
3481 but addresses are 32 bits long. See doc/gdbint.texinfo,
3482 ``Pointers Are Not Always Addresses''.
3485 - gdb's `struct type' always describes the target's
3487 - gdb's `struct value' objects should always hold values in
3489 - gdb's CORE_ADDR values are addresses in the unified virtual
3490 address space that the assembler and linker work with. Thus,
3491 since target_read_memory takes a CORE_ADDR as an argument, it
3492 can access any memory on the target, even if the processor has
3493 separate code and data address spaces.
3496 - If v is a value holding a D10V code pointer, its contents are
3497 in target form: a big-endian address left-shifted two bits.
3498 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3499 sizeof (void *) == 2 on the target.
3501 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3502 target type for a value the target will never see. It's only
3503 used to hold the values of (typeless) linker symbols, which are
3504 indeed in the unified virtual address space. */
3505 builtin_type
->builtin_data_ptr
3506 = make_pointer_type (builtin_type
->builtin_void
, NULL
);
3507 builtin_type
->builtin_func_ptr
3508 = lookup_pointer_type (lookup_function_type (builtin_type
->builtin_void
));
3509 builtin_type
->builtin_core_addr
=
3510 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3512 "__CORE_ADDR", (struct objfile
*) NULL
);
3514 return builtin_type
;
3517 extern void _initialize_gdbtypes (void);
3519 _initialize_gdbtypes (void)
3521 struct cmd_list_element
*c
;
3524 init_type (TYPE_CODE_INT
, 0 / 8,
3526 "int0_t", (struct objfile
*) NULL
);
3528 init_type (TYPE_CODE_INT
, 8 / 8,
3530 "int8_t", (struct objfile
*) NULL
);
3531 builtin_type_uint8
=
3532 init_type (TYPE_CODE_INT
, 8 / 8,
3534 "uint8_t", (struct objfile
*) NULL
);
3535 builtin_type_int16
=
3536 init_type (TYPE_CODE_INT
, 16 / 8,
3538 "int16_t", (struct objfile
*) NULL
);
3539 builtin_type_uint16
=
3540 init_type (TYPE_CODE_INT
, 16 / 8,
3542 "uint16_t", (struct objfile
*) NULL
);
3543 builtin_type_int32
=
3544 init_type (TYPE_CODE_INT
, 32 / 8,
3546 "int32_t", (struct objfile
*) NULL
);
3547 builtin_type_uint32
=
3548 init_type (TYPE_CODE_INT
, 32 / 8,
3550 "uint32_t", (struct objfile
*) NULL
);
3551 builtin_type_int64
=
3552 init_type (TYPE_CODE_INT
, 64 / 8,
3554 "int64_t", (struct objfile
*) NULL
);
3555 builtin_type_uint64
=
3556 init_type (TYPE_CODE_INT
, 64 / 8,
3558 "uint64_t", (struct objfile
*) NULL
);
3559 builtin_type_int128
=
3560 init_type (TYPE_CODE_INT
, 128 / 8,
3562 "int128_t", (struct objfile
*) NULL
);
3563 builtin_type_uint128
=
3564 init_type (TYPE_CODE_INT
, 128 / 8,
3566 "uint128_t", (struct objfile
*) NULL
);
3570 gdbtypes_data
= gdbarch_data_register_post_init (gdbtypes_post_init
);
3572 /* FIXME - For the moment, handle types by swapping them in and out.
3573 Should be using the per-architecture data-pointer and a large
3575 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void
);
3576 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char
);
3577 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short
);
3578 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int
);
3579 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long
);
3580 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long
);
3581 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char
);
3582 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char
);
3583 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short
);
3584 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int
);
3585 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long
);
3586 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long
);
3587 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float
);
3588 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double
);
3589 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double
);
3590 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex
);
3591 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex
);
3592 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string
);
3593 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf
);
3594 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si
);
3595 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi
);
3596 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi
);
3597 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi
);
3598 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi
);
3599 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si
);
3600 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double
);
3601 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float
);
3602 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64
);
3603 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32
);
3604 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16
);
3605 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8
);
3606 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float
);
3607 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32
);
3608 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8
);
3609 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16
);
3610 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128
);
3611 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128i
);
3612 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr
);
3613 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr
);
3614 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR
);
3615 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma
);
3616 deprecated_register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
3618 /* Note: These types do not need to be swapped - they are target
3620 builtin_type_ieee_single_big
=
3621 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_big
.totalsize
/ 8,
3622 0, "builtin_type_ieee_single_big", NULL
);
3623 TYPE_FLOATFORMAT (builtin_type_ieee_single_big
) = &floatformat_ieee_single_big
;
3624 builtin_type_ieee_single_little
=
3625 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_little
.totalsize
/ 8,
3626 0, "builtin_type_ieee_single_little", NULL
);
3627 TYPE_FLOATFORMAT (builtin_type_ieee_single_little
) = &floatformat_ieee_single_little
;
3628 builtin_type_ieee_single
[BFD_ENDIAN_BIG
]
3629 = build_flt (floatformat_ieee_single_big
.totalsize
,
3630 "builtin_type_ieee_single_big",
3631 &floatformat_ieee_single_big
);
3632 builtin_type_ieee_single
[BFD_ENDIAN_LITTLE
]
3633 = build_flt (floatformat_ieee_single_little
.totalsize
,
3634 "builtin_type_ieee_single_little",
3635 &floatformat_ieee_single_little
);
3636 builtin_type_ieee_double_big
=
3637 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_big
.totalsize
/ 8,
3638 0, "builtin_type_ieee_double_big", NULL
);
3639 TYPE_FLOATFORMAT (builtin_type_ieee_double_big
) = &floatformat_ieee_double_big
;
3640 builtin_type_ieee_double_little
=
3641 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_little
.totalsize
/ 8,
3642 0, "builtin_type_ieee_double_little", NULL
);
3643 TYPE_FLOATFORMAT (builtin_type_ieee_double_little
) = &floatformat_ieee_double_little
;
3644 builtin_type_ieee_double
[BFD_ENDIAN_BIG
]
3645 = build_flt (floatformat_ieee_double_big
.totalsize
,
3646 "builtin_type_ieee_double_big",
3647 &floatformat_ieee_double_big
);
3648 builtin_type_ieee_double
[BFD_ENDIAN_LITTLE
]
3649 = build_flt (floatformat_ieee_double_little
.totalsize
,
3650 "builtin_type_ieee_double_little",
3651 &floatformat_ieee_double_little
);
3652 builtin_type_ieee_double_littlebyte_bigword
=
3653 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_littlebyte_bigword
.totalsize
/ 8,
3654 0, "builtin_type_ieee_double_littlebyte_bigword", NULL
);
3655 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword
) = &floatformat_ieee_double_littlebyte_bigword
;
3656 builtin_type_i387_ext
=
3657 init_type (TYPE_CODE_FLT
, floatformat_i387_ext
.totalsize
/ 8,
3658 0, "builtin_type_i387_ext", NULL
);
3659 TYPE_FLOATFORMAT (builtin_type_i387_ext
) = &floatformat_i387_ext
;
3660 builtin_type_m68881_ext
=
3661 init_type (TYPE_CODE_FLT
, floatformat_m68881_ext
.totalsize
/ 8,
3662 0, "builtin_type_m68881_ext", NULL
);
3663 TYPE_FLOATFORMAT (builtin_type_m68881_ext
) = &floatformat_m68881_ext
;
3664 builtin_type_i960_ext
=
3665 init_type (TYPE_CODE_FLT
, floatformat_i960_ext
.totalsize
/ 8,
3666 0, "builtin_type_i960_ext", NULL
);
3667 TYPE_FLOATFORMAT (builtin_type_i960_ext
) = &floatformat_i960_ext
;
3668 builtin_type_m88110_ext
=
3669 init_type (TYPE_CODE_FLT
, floatformat_m88110_ext
.totalsize
/ 8,
3670 0, "builtin_type_m88110_ext", NULL
);
3671 TYPE_FLOATFORMAT (builtin_type_m88110_ext
) = &floatformat_m88110_ext
;
3672 builtin_type_m88110_harris_ext
=
3673 init_type (TYPE_CODE_FLT
, floatformat_m88110_harris_ext
.totalsize
/ 8,
3674 0, "builtin_type_m88110_harris_ext", NULL
);
3675 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext
) = &floatformat_m88110_harris_ext
;
3676 builtin_type_arm_ext_big
=
3677 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_big
.totalsize
/ 8,
3678 0, "builtin_type_arm_ext_big", NULL
);
3679 TYPE_FLOATFORMAT (builtin_type_arm_ext_big
) = &floatformat_arm_ext_big
;
3680 builtin_type_arm_ext_littlebyte_bigword
=
3681 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_littlebyte_bigword
.totalsize
/ 8,
3682 0, "builtin_type_arm_ext_littlebyte_bigword", NULL
);
3683 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword
) = &floatformat_arm_ext_littlebyte_bigword
;
3684 builtin_type_arm_ext
[BFD_ENDIAN_BIG
]
3685 = build_flt (floatformat_arm_ext_big
.totalsize
,
3686 "builtin_type_arm_ext_big",
3687 &floatformat_arm_ext_big
);
3688 builtin_type_arm_ext
[BFD_ENDIAN_LITTLE
]
3689 = build_flt (floatformat_arm_ext_littlebyte_bigword
.totalsize
,
3690 "builtin_type_arm_ext_littlebyte_bigword",
3691 &floatformat_arm_ext_littlebyte_bigword
);
3692 builtin_type_ia64_spill_big
=
3693 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_big
.totalsize
/ 8,
3694 0, "builtin_type_ia64_spill_big", NULL
);
3695 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big
) = &floatformat_ia64_spill_big
;
3696 builtin_type_ia64_spill_little
=
3697 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_little
.totalsize
/ 8,
3698 0, "builtin_type_ia64_spill_little", NULL
);
3699 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little
) = &floatformat_ia64_spill_little
;
3700 builtin_type_ia64_spill
[BFD_ENDIAN_BIG
]
3701 = build_flt (floatformat_ia64_spill_big
.totalsize
,
3702 "builtin_type_ia64_spill_big",
3703 &floatformat_ia64_spill_big
);
3704 builtin_type_ia64_spill
[BFD_ENDIAN_LITTLE
]
3705 = build_flt (floatformat_ia64_spill_little
.totalsize
,
3706 "builtin_type_ia64_spill_little",
3707 &floatformat_ia64_spill_little
);
3708 builtin_type_ia64_quad_big
=
3709 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_big
.totalsize
/ 8,
3710 0, "builtin_type_ia64_quad_big", NULL
);
3711 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big
) = &floatformat_ia64_quad_big
;
3712 builtin_type_ia64_quad_little
=
3713 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_little
.totalsize
/ 8,
3714 0, "builtin_type_ia64_quad_little", NULL
);
3715 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little
) = &floatformat_ia64_quad_little
;
3716 builtin_type_ia64_quad
[BFD_ENDIAN_BIG
]
3717 = build_flt (floatformat_ia64_quad_big
.totalsize
,
3718 "builtin_type_ia64_quad_big",
3719 &floatformat_ia64_quad_big
);
3720 builtin_type_ia64_quad
[BFD_ENDIAN_LITTLE
]
3721 = build_flt (floatformat_ia64_quad_little
.totalsize
,
3722 "builtin_type_ia64_quad_little",
3723 &floatformat_ia64_quad_little
);
3725 add_setshow_zinteger_cmd ("overload", no_class
, &overload_debug
, _("\
3726 Set debugging of C++ overloading."), _("\
3727 Show debugging of C++ overloading."), _("\
3728 When enabled, ranking of the functions is displayed."),
3730 show_overload_debug
,
3731 &setdebuglist
, &showdebuglist
);