1 /* Support routines for manipulating internal types for GDB.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000
3 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_int8
;
64 struct type
*builtin_type_uint8
;
65 struct type
*builtin_type_int16
;
66 struct type
*builtin_type_uint16
;
67 struct type
*builtin_type_int32
;
68 struct type
*builtin_type_uint32
;
69 struct type
*builtin_type_int64
;
70 struct type
*builtin_type_uint64
;
71 struct type
*builtin_type_int128
;
72 struct type
*builtin_type_uint128
;
73 struct type
*builtin_type_bool
;
74 struct type
*builtin_type_v4sf
;
75 struct type
*builtin_type_v4si
;
76 struct type
*builtin_type_v8qi
;
77 struct type
*builtin_type_v4hi
;
78 struct type
*builtin_type_v2si
;
79 struct type
*builtin_type_ieee_single_big
;
80 struct type
*builtin_type_ieee_single_little
;
81 struct type
*builtin_type_ieee_double_big
;
82 struct type
*builtin_type_ieee_double_little
;
83 struct type
*builtin_type_ieee_double_littlebyte_bigword
;
84 struct type
*builtin_type_i387_ext
;
85 struct type
*builtin_type_m68881_ext
;
86 struct type
*builtin_type_i960_ext
;
87 struct type
*builtin_type_m88110_ext
;
88 struct type
*builtin_type_m88110_harris_ext
;
89 struct type
*builtin_type_arm_ext_big
;
90 struct type
*builtin_type_arm_ext_littlebyte_bigword
;
91 struct type
*builtin_type_ia64_spill_big
;
92 struct type
*builtin_type_ia64_spill_little
;
93 struct type
*builtin_type_ia64_quad_big
;
94 struct type
*builtin_type_ia64_quad_little
;
95 struct type
*builtin_type_void_data_ptr
;
96 struct type
*builtin_type_void_func_ptr
;
97 struct type
*builtin_type_CORE_ADDR
;
98 struct type
*builtin_type_bfd_vma
;
100 int opaque_type_resolution
= 1;
101 int overload_debug
= 0;
107 }; /* maximum extension is 128! FIXME */
109 static void add_name (struct extra
*, char *);
110 static void add_mangled_type (struct extra
*, struct type
*);
112 static void cfront_mangle_name (struct type
*, int, int);
114 static void print_bit_vector (B_TYPE
*, int);
115 static void print_arg_types (struct type
**, int);
116 static void dump_fn_fieldlists (struct type
*, int);
117 static void print_cplus_stuff (struct type
*, int);
118 static void virtual_base_list_aux (struct type
*dclass
);
121 /* Alloc a new type structure and fill it with some defaults. If
122 OBJFILE is non-NULL, then allocate the space for the type structure
123 in that objfile's type_obstack. */
126 alloc_type (struct objfile
*objfile
)
128 register struct type
*type
;
130 /* Alloc the structure and start off with all fields zeroed. */
134 type
= (struct type
*) xmalloc (sizeof (struct type
));
138 type
= (struct type
*) obstack_alloc (&objfile
->type_obstack
,
139 sizeof (struct type
));
140 OBJSTAT (objfile
, n_types
++);
142 memset ((char *) type
, 0, sizeof (struct type
));
144 /* Initialize the fields that might not be zero. */
146 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
147 TYPE_OBJFILE (type
) = objfile
;
148 TYPE_VPTR_FIELDNO (type
) = -1;
149 TYPE_CV_TYPE (type
) = type
; /* chain back to itself */
150 TYPE_AS_TYPE (type
) = type
; /* ditto */
155 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
156 to a pointer to memory where the pointer type should be stored.
157 If *TYPEPTR is zero, update it to point to the pointer type we return.
158 We allocate new memory if needed. */
161 make_pointer_type (struct type
*type
, struct type
**typeptr
)
163 register struct type
*ntype
; /* New type */
164 struct objfile
*objfile
;
166 ntype
= TYPE_POINTER_TYPE (type
);
171 return ntype
; /* Don't care about alloc, and have new type. */
172 else if (*typeptr
== 0)
174 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
179 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
181 ntype
= alloc_type (TYPE_OBJFILE (type
));
186 /* We have storage, but need to reset it. */
189 objfile
= TYPE_OBJFILE (ntype
);
190 memset ((char *) ntype
, 0, sizeof (struct type
));
191 TYPE_OBJFILE (ntype
) = objfile
;
194 TYPE_TARGET_TYPE (ntype
) = type
;
195 TYPE_POINTER_TYPE (type
) = ntype
;
197 /* FIXME! Assume the machine has only one representation for pointers! */
199 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
200 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
202 /* Mark pointers as unsigned. The target converts between pointers
203 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
204 ADDRESS_TO_POINTER(). */
205 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
207 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
208 TYPE_POINTER_TYPE (type
) = ntype
;
213 /* Given a type TYPE, return a type of pointers to that type.
214 May need to construct such a type if this is the first use. */
217 lookup_pointer_type (struct type
*type
)
219 return make_pointer_type (type
, (struct type
**) 0);
222 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
223 to a pointer to memory where the reference type should be stored.
224 If *TYPEPTR is zero, update it to point to the reference type we return.
225 We allocate new memory if needed. */
228 make_reference_type (struct type
*type
, struct type
**typeptr
)
230 register struct type
*ntype
; /* New type */
231 struct objfile
*objfile
;
233 ntype
= TYPE_REFERENCE_TYPE (type
);
238 return ntype
; /* Don't care about alloc, and have new type. */
239 else if (*typeptr
== 0)
241 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
246 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
248 ntype
= alloc_type (TYPE_OBJFILE (type
));
253 /* We have storage, but need to reset it. */
256 objfile
= TYPE_OBJFILE (ntype
);
257 memset ((char *) ntype
, 0, sizeof (struct type
));
258 TYPE_OBJFILE (ntype
) = objfile
;
261 TYPE_TARGET_TYPE (ntype
) = type
;
262 TYPE_REFERENCE_TYPE (type
) = ntype
;
264 /* FIXME! Assume the machine has only one representation for references,
265 and that it matches the (only) representation for pointers! */
267 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
268 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
270 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
271 TYPE_REFERENCE_TYPE (type
) = ntype
;
276 /* Same as above, but caller doesn't care about memory allocation details. */
279 lookup_reference_type (struct type
*type
)
281 return make_reference_type (type
, (struct type
**) 0);
284 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
285 to a pointer to memory where the function type should be stored.
286 If *TYPEPTR is zero, update it to point to the function type we return.
287 We allocate new memory if needed. */
290 make_function_type (struct type
*type
, struct type
**typeptr
)
292 register struct type
*ntype
; /* New type */
293 struct objfile
*objfile
;
295 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
297 ntype
= alloc_type (TYPE_OBJFILE (type
));
302 /* We have storage, but need to reset it. */
305 objfile
= TYPE_OBJFILE (ntype
);
306 memset ((char *) ntype
, 0, sizeof (struct type
));
307 TYPE_OBJFILE (ntype
) = objfile
;
310 TYPE_TARGET_TYPE (ntype
) = type
;
312 TYPE_LENGTH (ntype
) = 1;
313 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
319 /* Given a type TYPE, return a type of functions that return that type.
320 May need to construct such a type if this is the first use. */
323 lookup_function_type (struct type
*type
)
325 return make_function_type (type
, (struct type
**) 0);
328 /* Identify address space identifier by name --
329 return the integer flag defined in gdbtypes.h. */
331 address_space_name_to_int (char *space_identifier
)
333 /* Check for known address space delimiters. */
334 if (!strcmp (space_identifier
, "code"))
335 return TYPE_FLAG_CODE_SPACE
;
336 else if (!strcmp (space_identifier
, "data"))
337 return TYPE_FLAG_DATA_SPACE
;
339 error ("Unknown address space specifier: \"%s\"", space_identifier
);
342 /* Identify address space identifier by integer flag as defined in
343 gdbtypes.h -- return the string version of the adress space name. */
346 address_space_int_to_name (int space_flag
)
348 if (space_flag
& TYPE_FLAG_CODE_SPACE
)
350 else if (space_flag
& TYPE_FLAG_DATA_SPACE
)
356 /* Make an address-space-delimited variant of a type -- a type that
357 is identical to the one supplied except that it has an address
358 space attribute attached to it (such as "code" or "data").
360 This is for Harvard architectures. */
363 make_type_with_address_space (struct type
*type
, int space_flag
)
369 if ((ntype
->flags
& space_flag
) != 0)
371 ntype
= TYPE_AS_TYPE (ntype
);
372 } while (ntype
!= type
);
374 /* Create a new, duplicate type. */
375 ntype
= alloc_type (TYPE_OBJFILE (type
));
376 /* Copy original type. */
377 memcpy ((char *) ntype
, (char *) type
, sizeof (struct type
));
379 /* Pointers or references to the original type are not relevant to
380 the new type; but if the original type is a pointer, the new type
381 points to the same thing (so TYPE_TARGET_TYPE remains unchanged). */
382 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0;
383 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0;
384 TYPE_CV_TYPE (ntype
) = ntype
;
386 /* Chain the new address-space-specific type to the old type. */
387 ntype
->as_type
= type
->as_type
;
388 type
->as_type
= ntype
;
390 /* Now set the address-space flag, and return the new type. */
391 ntype
->flags
|= space_flag
;
396 /* Make a "c-v" variant of a type -- a type that is identical to the
397 one supplied except that it may have const or volatile attributes
398 CNST is a flag for setting the const attribute
399 VOLTL is a flag for setting the volatile attribute
400 TYPE is the base type whose variant we are creating.
401 TYPEPTR, if nonzero, points
402 to a pointer to memory where the reference type should be stored.
403 If *TYPEPTR is zero, update it to point to the reference type we return.
404 We allocate new memory if needed. */
407 make_cv_type (int cnst
, int voltl
, struct type
*type
, struct type
**typeptr
)
409 register struct type
*ntype
; /* New type */
410 register struct type
*tmp_type
= type
; /* tmp type */
411 struct objfile
*objfile
;
413 ntype
= TYPE_CV_TYPE (type
);
415 while (ntype
!= type
)
417 if ((TYPE_CONST (ntype
) == cnst
) &&
418 (TYPE_VOLATILE (ntype
) == voltl
))
422 else if (*typeptr
== 0)
424 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
429 ntype
= TYPE_CV_TYPE (ntype
);
432 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
434 ntype
= alloc_type (TYPE_OBJFILE (type
));
439 /* We have storage, but need to reset it. */
442 objfile
= TYPE_OBJFILE (ntype
);
443 /* memset ((char *) ntype, 0, sizeof (struct type)); */
444 TYPE_OBJFILE (ntype
) = objfile
;
447 /* Copy original type */
448 memcpy ((char *) ntype
, (char *) type
, sizeof (struct type
));
449 /* But zero out fields that shouldn't be copied */
450 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0; /* Need new pointer kind */
451 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0; /* Need new referene kind */
452 TYPE_AS_TYPE (ntype
) = ntype
; /* Need new address-space kind. */
453 /* Note: TYPE_TARGET_TYPE can be left as is */
455 /* Set flags appropriately */
457 TYPE_FLAGS (ntype
) |= TYPE_FLAG_CONST
;
459 TYPE_FLAGS (ntype
) &= ~TYPE_FLAG_CONST
;
462 TYPE_FLAGS (ntype
) |= TYPE_FLAG_VOLATILE
;
464 TYPE_FLAGS (ntype
) &= ~TYPE_FLAG_VOLATILE
;
466 /* Fix the chain of cv variants */
467 TYPE_CV_TYPE (ntype
) = type
;
468 TYPE_CV_TYPE (tmp_type
) = ntype
;
473 /* When reading in a class type, we may have created references to
474 cv-qualified versions of the type (in method arguments, for
475 instance). Update everything on the cv ring from the primary
478 The only reason we do not need to do the same thing for address
479 spaces is that type readers do not create address space qualified
482 finish_cv_type (struct type
*type
)
484 struct type
*ntype
, *cv_type
, *ptr_type
, *ref_type
;
487 gdb_assert (!TYPE_CONST (type
) && !TYPE_VOLATILE (type
));
490 while ((ntype
= TYPE_CV_TYPE (ntype
)) != type
)
493 cv_flags
= TYPE_FLAGS (ntype
) & (TYPE_FLAG_VOLATILE
| TYPE_FLAG_CONST
);
495 /* If any reference or pointer types were created, save them too. */
496 ptr_type
= TYPE_POINTER_TYPE (ntype
);
497 ref_type
= TYPE_REFERENCE_TYPE (ntype
);
499 /* Don't disturb the CV chain. */
500 cv_type
= TYPE_CV_TYPE (ntype
);
502 /* Verify that we haven't added any address-space qualified types,
504 gdb_assert (ntype
== TYPE_AS_TYPE (ntype
));
506 /* Copy original type */
507 memcpy ((char *) ntype
, (char *) type
, sizeof (struct type
));
509 /* Restore everything. */
510 TYPE_POINTER_TYPE (ntype
) = ptr_type
;
511 TYPE_REFERENCE_TYPE (ntype
) = ref_type
;
512 TYPE_CV_TYPE (ntype
) = cv_type
;
513 TYPE_FLAGS (ntype
) = TYPE_FLAGS (ntype
) | cv_flags
;
515 TYPE_AS_TYPE (ntype
) = ntype
;
519 /* Implement direct support for MEMBER_TYPE in GNU C++.
520 May need to construct such a type if this is the first use.
521 The TYPE is the type of the member. The DOMAIN is the type
522 of the aggregate that the member belongs to. */
525 lookup_member_type (struct type
*type
, struct type
*domain
)
527 register struct type
*mtype
;
529 mtype
= alloc_type (TYPE_OBJFILE (type
));
530 smash_to_member_type (mtype
, domain
, type
);
534 /* Allocate a stub method whose return type is TYPE.
535 This apparently happens for speed of symbol reading, since parsing
536 out the arguments to the method is cpu-intensive, the way we are doing
537 it. So, we will fill in arguments later.
538 This always returns a fresh type. */
541 allocate_stub_method (struct type
*type
)
545 mtype
= init_type (TYPE_CODE_METHOD
, 1, TYPE_FLAG_STUB
, NULL
,
546 TYPE_OBJFILE (type
));
547 TYPE_TARGET_TYPE (mtype
) = type
;
548 /* _DOMAIN_TYPE (mtype) = unknown yet */
549 /* _ARG_TYPES (mtype) = unknown yet */
553 /* Create a range type using either a blank type supplied in RESULT_TYPE,
554 or creating a new type, inheriting the objfile from INDEX_TYPE.
556 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
557 HIGH_BOUND, inclusive.
559 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
560 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
563 create_range_type (struct type
*result_type
, struct type
*index_type
,
564 int low_bound
, int high_bound
)
566 if (result_type
== NULL
)
568 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
570 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
571 TYPE_TARGET_TYPE (result_type
) = index_type
;
572 if (TYPE_STUB (index_type
))
573 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
575 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
576 TYPE_NFIELDS (result_type
) = 2;
577 TYPE_FIELDS (result_type
) = (struct field
*)
578 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
579 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
580 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
581 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
582 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
583 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
586 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
588 return (result_type
);
591 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
592 Return 1 of type is a range type, 0 if it is discrete (and bounds
593 will fit in LONGEST), or -1 otherwise. */
596 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
598 CHECK_TYPEDEF (type
);
599 switch (TYPE_CODE (type
))
601 case TYPE_CODE_RANGE
:
602 *lowp
= TYPE_LOW_BOUND (type
);
603 *highp
= TYPE_HIGH_BOUND (type
);
606 if (TYPE_NFIELDS (type
) > 0)
608 /* The enums may not be sorted by value, so search all
612 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
613 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
615 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
616 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
617 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
618 *highp
= TYPE_FIELD_BITPOS (type
, i
);
621 /* Set unsigned indicator if warranted. */
624 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
638 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
640 if (!TYPE_UNSIGNED (type
))
642 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
646 /* ... fall through for unsigned ints ... */
649 /* This round-about calculation is to avoid shifting by
650 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
651 if TYPE_LENGTH (type) == sizeof (LONGEST). */
652 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
653 *highp
= (*highp
- 1) | *highp
;
660 /* Create an array type using either a blank type supplied in RESULT_TYPE,
661 or creating a new type, inheriting the objfile from RANGE_TYPE.
663 Elements will be of type ELEMENT_TYPE, the indices will be of type
666 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
667 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
670 create_array_type (struct type
*result_type
, struct type
*element_type
,
671 struct type
*range_type
)
673 LONGEST low_bound
, high_bound
;
675 if (result_type
== NULL
)
677 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
679 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
680 TYPE_TARGET_TYPE (result_type
) = element_type
;
681 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
682 low_bound
= high_bound
= 0;
683 CHECK_TYPEDEF (element_type
);
684 TYPE_LENGTH (result_type
) =
685 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
686 TYPE_NFIELDS (result_type
) = 1;
687 TYPE_FIELDS (result_type
) =
688 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
689 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
690 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
691 TYPE_VPTR_FIELDNO (result_type
) = -1;
693 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
694 if (TYPE_LENGTH (result_type
) == 0)
695 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
697 return (result_type
);
700 /* Create a string type using either a blank type supplied in RESULT_TYPE,
701 or creating a new type. String types are similar enough to array of
702 char types that we can use create_array_type to build the basic type
703 and then bash it into a string type.
705 For fixed length strings, the range type contains 0 as the lower
706 bound and the length of the string minus one as the upper bound.
708 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
709 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
712 create_string_type (struct type
*result_type
, struct type
*range_type
)
714 result_type
= create_array_type (result_type
,
715 *current_language
->string_char_type
,
717 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
718 return (result_type
);
722 create_set_type (struct type
*result_type
, struct type
*domain_type
)
724 LONGEST low_bound
, high_bound
, bit_length
;
725 if (result_type
== NULL
)
727 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
729 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
730 TYPE_NFIELDS (result_type
) = 1;
731 TYPE_FIELDS (result_type
) = (struct field
*)
732 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
733 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
735 if (!TYPE_STUB (domain_type
))
737 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
738 low_bound
= high_bound
= 0;
739 bit_length
= high_bound
- low_bound
+ 1;
740 TYPE_LENGTH (result_type
)
741 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
743 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
746 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
748 return (result_type
);
752 /* Construct and return a type of the form:
753 struct NAME { ELT_TYPE ELT_NAME[N]; }
754 We use these types for SIMD registers. For example, the type of
755 the SSE registers on the late x86-family processors is:
756 struct __builtin_v4sf { float f[4]; }
757 built by the function call:
758 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
759 The type returned is a permanent type, allocated using malloc; it
760 doesn't live in any objfile's obstack. */
762 init_simd_type (char *name
,
763 struct type
*elt_type
,
770 /* Build the field structure. */
771 f
= xmalloc (sizeof (*f
));
772 memset (f
, 0, sizeof (*f
));
774 f
->type
= create_array_type (0, elt_type
,
775 create_range_type (0, builtin_type_int
,
779 /* Build a struct type with that field. */
780 t
= init_type (TYPE_CODE_STRUCT
, n
* TYPE_LENGTH (elt_type
), 0, 0, 0);
789 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
790 A MEMBER is a wierd thing -- it amounts to a typed offset into
791 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
792 include the offset (that's the value of the MEMBER itself), but does
793 include the structure type into which it points (for some reason).
795 When "smashing" the type, we preserve the objfile that the
796 old type pointed to, since we aren't changing where the type is actually
800 smash_to_member_type (struct type
*type
, struct type
*domain
,
801 struct type
*to_type
)
803 struct objfile
*objfile
;
805 objfile
= TYPE_OBJFILE (type
);
807 memset ((char *) type
, 0, sizeof (struct type
));
808 TYPE_OBJFILE (type
) = objfile
;
809 TYPE_TARGET_TYPE (type
) = to_type
;
810 TYPE_DOMAIN_TYPE (type
) = domain
;
811 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
812 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
815 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
816 METHOD just means `function that gets an extra "this" argument'.
818 When "smashing" the type, we preserve the objfile that the
819 old type pointed to, since we aren't changing where the type is actually
823 smash_to_method_type (struct type
*type
, struct type
*domain
,
824 struct type
*to_type
, struct type
**args
)
826 struct objfile
*objfile
;
828 objfile
= TYPE_OBJFILE (type
);
830 memset ((char *) type
, 0, sizeof (struct type
));
831 TYPE_OBJFILE (type
) = objfile
;
832 TYPE_TARGET_TYPE (type
) = to_type
;
833 TYPE_DOMAIN_TYPE (type
) = domain
;
834 TYPE_ARG_TYPES (type
) = args
;
835 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
836 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
839 /* Return a typename for a struct/union/enum type without "struct ",
840 "union ", or "enum ". If the type has a NULL name, return NULL. */
843 type_name_no_tag (register const struct type
*type
)
845 if (TYPE_TAG_NAME (type
) != NULL
)
846 return TYPE_TAG_NAME (type
);
848 /* Is there code which expects this to return the name if there is no
849 tag name? My guess is that this is mainly used for C++ in cases where
850 the two will always be the same. */
851 return TYPE_NAME (type
);
854 /* Lookup a primitive type named NAME.
855 Return zero if NAME is not a primitive type. */
858 lookup_primitive_typename (char *name
)
860 struct type
**const *p
;
862 for (p
= current_language
->la_builtin_type_vector
; *p
!= NULL
; p
++)
864 if (STREQ ((**p
)->name
, name
))
872 /* Lookup a typedef or primitive type named NAME,
873 visible in lexical block BLOCK.
874 If NOERR is nonzero, return zero if NAME is not suitably defined. */
877 lookup_typename (char *name
, struct block
*block
, int noerr
)
879 register struct symbol
*sym
;
880 register struct type
*tmp
;
882 sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
883 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
885 tmp
= lookup_primitive_typename (name
);
890 else if (!tmp
&& noerr
)
896 error ("No type named %s.", name
);
899 return (SYMBOL_TYPE (sym
));
903 lookup_unsigned_typename (char *name
)
905 char *uns
= alloca (strlen (name
) + 10);
907 strcpy (uns
, "unsigned ");
908 strcpy (uns
+ 9, name
);
909 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
913 lookup_signed_typename (char *name
)
916 char *uns
= alloca (strlen (name
) + 8);
918 strcpy (uns
, "signed ");
919 strcpy (uns
+ 7, name
);
920 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
921 /* If we don't find "signed FOO" just try again with plain "FOO". */
924 return lookup_typename (name
, (struct block
*) NULL
, 0);
927 /* Lookup a structure type named "struct NAME",
928 visible in lexical block BLOCK. */
931 lookup_struct (char *name
, struct block
*block
)
933 register struct symbol
*sym
;
935 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
936 (struct symtab
**) NULL
);
940 error ("No struct type named %s.", name
);
942 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
944 error ("This context has class, union or enum %s, not a struct.", name
);
946 return (SYMBOL_TYPE (sym
));
949 /* Lookup a union type named "union NAME",
950 visible in lexical block BLOCK. */
953 lookup_union (char *name
, struct block
*block
)
955 register struct symbol
*sym
;
958 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
959 (struct symtab
**) NULL
);
962 error ("No union type named %s.", name
);
964 t
= SYMBOL_TYPE (sym
);
966 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
969 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
970 * a further "declared_type" field to discover it is really a union.
972 if (HAVE_CPLUS_STRUCT (t
))
973 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
976 /* If we get here, it's not a union */
977 error ("This context has class, struct or enum %s, not a union.", name
);
981 /* Lookup an enum type named "enum NAME",
982 visible in lexical block BLOCK. */
985 lookup_enum (char *name
, struct block
*block
)
987 register struct symbol
*sym
;
989 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
990 (struct symtab
**) NULL
);
993 error ("No enum type named %s.", name
);
995 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
997 error ("This context has class, struct or union %s, not an enum.", name
);
999 return (SYMBOL_TYPE (sym
));
1002 /* Lookup a template type named "template NAME<TYPE>",
1003 visible in lexical block BLOCK. */
1006 lookup_template_type (char *name
, struct type
*type
, struct block
*block
)
1009 char *nam
= (char *) alloca (strlen (name
) + strlen (type
->name
) + 4);
1012 strcat (nam
, type
->name
);
1013 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1015 sym
= lookup_symbol (nam
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
1019 error ("No template type named %s.", name
);
1021 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1023 error ("This context has class, union or enum %s, not a struct.", name
);
1025 return (SYMBOL_TYPE (sym
));
1028 /* Given a type TYPE, lookup the type of the component of type named NAME.
1030 TYPE can be either a struct or union, or a pointer or reference to a struct or
1031 union. If it is a pointer or reference, its target type is automatically used.
1032 Thus '.' and '->' are interchangable, as specified for the definitions of the
1033 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1035 If NOERR is nonzero, return zero if NAME is not suitably defined.
1036 If NAME is the name of a baseclass type, return that type. */
1039 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1045 CHECK_TYPEDEF (type
);
1046 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1047 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1049 type
= TYPE_TARGET_TYPE (type
);
1052 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
1053 TYPE_CODE (type
) != TYPE_CODE_UNION
)
1055 target_terminal_ours ();
1056 gdb_flush (gdb_stdout
);
1057 fprintf_unfiltered (gdb_stderr
, "Type ");
1058 type_print (type
, "", gdb_stderr
, -1);
1059 error (" is not a structure or union type.");
1063 /* FIXME: This change put in by Michael seems incorrect for the case where
1064 the structure tag name is the same as the member name. I.E. when doing
1065 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1070 typename
= type_name_no_tag (type
);
1071 if (typename
!= NULL
&& STREQ (typename
, name
))
1076 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1078 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1080 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1082 return TYPE_FIELD_TYPE (type
, i
);
1086 /* OK, it's not in this class. Recursively check the baseclasses. */
1087 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1091 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
1103 target_terminal_ours ();
1104 gdb_flush (gdb_stdout
);
1105 fprintf_unfiltered (gdb_stderr
, "Type ");
1106 type_print (type
, "", gdb_stderr
, -1);
1107 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1108 fputs_filtered (name
, gdb_stderr
);
1110 return (struct type
*) -1; /* For lint */
1113 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1114 valid. Callers should be aware that in some cases (for example,
1115 the type or one of its baseclasses is a stub type and we are
1116 debugging a .o file), this function will not be able to find the virtual
1117 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1118 will remain NULL. */
1121 fill_in_vptr_fieldno (struct type
*type
)
1123 CHECK_TYPEDEF (type
);
1125 if (TYPE_VPTR_FIELDNO (type
) < 0)
1129 /* We must start at zero in case the first (and only) baseclass is
1130 virtual (and hence we cannot share the table pointer). */
1131 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1133 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
1134 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
1136 TYPE_VPTR_FIELDNO (type
)
1137 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
1138 TYPE_VPTR_BASETYPE (type
)
1139 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
1146 /* Find the method and field indices for the destructor in class type T.
1147 Return 1 if the destructor was found, otherwise, return 0. */
1150 get_destructor_fn_field (struct type
*t
, int *method_indexp
, int *field_indexp
)
1154 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1157 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1159 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1161 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1172 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1174 If this is a stubbed struct (i.e. declared as struct foo *), see if
1175 we can find a full definition in some other file. If so, copy this
1176 definition, so we can use it in future. There used to be a comment (but
1177 not any code) that if we don't find a full definition, we'd set a flag
1178 so we don't spend time in the future checking the same type. That would
1179 be a mistake, though--we might load in more symbols which contain a
1180 full definition for the type.
1182 This used to be coded as a macro, but I don't think it is called
1183 often enough to merit such treatment. */
1185 struct complaint stub_noname_complaint
=
1186 {"stub type has NULL name", 0, 0};
1189 check_typedef (struct type
*type
)
1191 struct type
*orig_type
= type
;
1192 int is_const
, is_volatile
;
1194 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1196 if (!TYPE_TARGET_TYPE (type
))
1201 /* It is dangerous to call lookup_symbol if we are currently
1202 reading a symtab. Infinite recursion is one danger. */
1203 if (currently_reading_symtab
)
1206 name
= type_name_no_tag (type
);
1207 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1208 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1209 as appropriate? (this code was written before TYPE_NAME and
1210 TYPE_TAG_NAME were separate). */
1213 complain (&stub_noname_complaint
);
1216 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
1217 (struct symtab
**) NULL
);
1219 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1221 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1223 type
= TYPE_TARGET_TYPE (type
);
1226 is_const
= TYPE_CONST (type
);
1227 is_volatile
= TYPE_VOLATILE (type
);
1229 /* If this is a struct/class/union with no fields, then check whether a
1230 full definition exists somewhere else. This is for systems where a
1231 type definition with no fields is issued for such types, instead of
1232 identifying them as stub types in the first place */
1234 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1236 char *name
= type_name_no_tag (type
);
1237 struct type
*newtype
;
1240 complain (&stub_noname_complaint
);
1243 newtype
= lookup_transparent_type (name
);
1245 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1247 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1248 else if (TYPE_STUB (type
) && !currently_reading_symtab
)
1250 char *name
= type_name_no_tag (type
);
1251 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1252 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1253 as appropriate? (this code was written before TYPE_NAME and
1254 TYPE_TAG_NAME were separate). */
1258 complain (&stub_noname_complaint
);
1261 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0, (struct symtab
**) NULL
);
1263 make_cv_type (is_const
, is_volatile
, SYMBOL_TYPE (sym
), &type
);
1266 if (TYPE_TARGET_STUB (type
))
1268 struct type
*range_type
;
1269 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1271 if (TYPE_STUB (target_type
) || TYPE_TARGET_STUB (target_type
))
1274 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1275 && TYPE_NFIELDS (type
) == 1
1276 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1277 == TYPE_CODE_RANGE
))
1279 /* Now recompute the length of the array type, based on its
1280 number of elements and the target type's length. */
1281 TYPE_LENGTH (type
) =
1282 ((TYPE_FIELD_BITPOS (range_type
, 1)
1283 - TYPE_FIELD_BITPOS (range_type
, 0)
1285 * TYPE_LENGTH (target_type
));
1286 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1288 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1290 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1291 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1294 /* Cache TYPE_LENGTH for future use. */
1295 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1299 /* New code added to support parsing of Cfront stabs strings */
1300 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1301 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1304 add_name (struct extra
*pextras
, char *n
)
1308 if ((nlen
= (n
? strlen (n
) : 0)) == 0)
1310 sprintf (pextras
->str
+ pextras
->len
, "%d%s", nlen
, n
);
1311 pextras
->len
= strlen (pextras
->str
);
1315 add_mangled_type (struct extra
*pextras
, struct type
*t
)
1317 enum type_code tcode
;
1321 tcode
= TYPE_CODE (t
);
1322 tlen
= TYPE_LENGTH (t
);
1323 tflags
= TYPE_FLAGS (t
);
1324 tname
= TYPE_NAME (t
);
1325 /* args of "..." seem to get mangled as "e" */
1343 if ((pname
= strrchr (tname
, 'l'), pname
) && !strcmp (pname
, "long"))
1356 static struct complaint msg
=
1357 {"Bad int type code length x%x\n", 0, 0};
1359 complain (&msg
, tlen
);
1378 static struct complaint msg
=
1379 {"Bad float type code length x%x\n", 0, 0};
1380 complain (&msg
, tlen
);
1386 /* followed by what it's a ref to */
1390 /* followed by what it's a ptr to */
1392 case TYPE_CODE_TYPEDEF
:
1394 static struct complaint msg
=
1395 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1398 /* followed by type bytes & name */
1400 case TYPE_CODE_FUNC
:
1402 /* followed by func's arg '_' & ret types */
1404 case TYPE_CODE_VOID
:
1407 case TYPE_CODE_METHOD
:
1409 /* followed by name of class and func's arg '_' & ret types */
1410 add_name (pextras
, tname
);
1411 ADD_EXTRA ('F'); /* then mangle function */
1413 case TYPE_CODE_STRUCT
: /* C struct */
1414 case TYPE_CODE_UNION
: /* C union */
1415 case TYPE_CODE_ENUM
: /* Enumeration type */
1416 /* followed by name of type */
1417 add_name (pextras
, tname
);
1420 /* errors possible types/not supported */
1421 case TYPE_CODE_CHAR
:
1422 case TYPE_CODE_ARRAY
: /* Array type */
1423 case TYPE_CODE_MEMBER
: /* Member type */
1424 case TYPE_CODE_BOOL
:
1425 case TYPE_CODE_COMPLEX
: /* Complex float */
1426 case TYPE_CODE_UNDEF
:
1427 case TYPE_CODE_SET
: /* Pascal sets */
1428 case TYPE_CODE_RANGE
:
1429 case TYPE_CODE_STRING
:
1430 case TYPE_CODE_BITSTRING
:
1431 case TYPE_CODE_ERROR
:
1434 static struct complaint msg
=
1435 {"Unknown type code x%x\n", 0, 0};
1436 complain (&msg
, tcode
);
1440 add_mangled_type (pextras
, t
->target_type
);
1445 cfront_mangle_name (struct type
*type
, int i
, int j
)
1448 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1450 f
= TYPE_FN_FIELDLIST1 (type
, i
); /* moved from below */
1452 /* kludge to support cfront methods - gdb expects to find "F" for
1453 ARM_mangled names, so when we mangle, we have to add it here */
1457 char *arm_mangled_name
;
1458 struct fn_field
*method
= &f
[j
];
1459 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1460 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1461 char *newname
= type_name_no_tag (type
);
1463 struct type
*ftype
= TYPE_FN_FIELD_TYPE (f
, j
);
1464 int nargs
= TYPE_NFIELDS (ftype
); /* number of args */
1465 struct extra extras
, *pextras
= &extras
;
1468 if (TYPE_FN_FIELD_STATIC_P (f
, j
)) /* j for sublist within this list */
1471 /* add args here! */
1472 if (nargs
<= 1) /* no args besides this */
1476 for (k
= 1; k
< nargs
; k
++)
1479 t
= TYPE_FIELD_TYPE (ftype
, k
);
1480 add_mangled_type (pextras
, t
);
1484 printf ("add_mangled_type: %s\n", extras
.str
); /* FIXME */
1485 xasprintf (&arm_mangled_name
, "%s%s", mangled_name
, extras
.str
);
1486 xfree (mangled_name
);
1487 mangled_name
= arm_mangled_name
;
1493 /* End of new code added to support parsing of Cfront stabs strings */
1495 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1496 silently return builtin_type_void. */
1499 safe_parse_type (char *p
, int length
)
1501 struct ui_file
*saved_gdb_stderr
;
1504 /* Suppress error messages. */
1505 saved_gdb_stderr
= gdb_stderr
;
1506 gdb_stderr
= ui_file_new ();
1508 /* Call parse_and_eval_type() without fear of longjmp()s. */
1509 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1510 type
= builtin_type_void
;
1512 /* Stop suppressing error messages. */
1513 ui_file_delete (gdb_stderr
);
1514 gdb_stderr
= saved_gdb_stderr
;
1519 /* Ugly hack to convert method stubs into method types.
1521 He ain't kiddin'. This demangles the name of the method into a string
1522 including argument types, parses out each argument type, generates
1523 a string casting a zero to that type, evaluates the string, and stuffs
1524 the resulting type into an argtype vector!!! Then it knows the type
1525 of the whole function (including argument types for overloading),
1526 which info used to be in the stab's but was removed to hack back
1527 the space required for them. */
1530 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1533 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1534 char *demangled_name
= cplus_demangle (mangled_name
,
1535 DMGL_PARAMS
| DMGL_ANSI
);
1536 char *argtypetext
, *p
;
1537 int depth
= 0, argcount
= 1;
1538 struct type
**argtypes
;
1541 /* Make sure we got back a function string that we can use. */
1543 p
= strchr (demangled_name
, '(');
1547 if (demangled_name
== NULL
|| p
== NULL
)
1548 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
1550 /* Now, read in the parameters that define this type. */
1555 if (*p
== '(' || *p
== '<')
1559 else if (*p
== ')' || *p
== '>')
1563 else if (*p
== ',' && depth
== 0)
1571 /* We need two more slots: one for the THIS pointer, and one for the
1572 NULL [...] or void [end of arglist]. */
1574 argtypes
= (struct type
**)
1575 TYPE_ALLOC (type
, (argcount
+ 2) * sizeof (struct type
*));
1577 /* FIXME: This is wrong for static member functions. */
1578 argtypes
[0] = lookup_pointer_type (type
);
1581 if (*p
!= ')') /* () means no args, skip while */
1586 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1588 /* Avoid parsing of ellipsis, they will be handled below. */
1589 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0)
1591 argtypes
[argcount
] =
1592 safe_parse_type (argtypetext
, p
- argtypetext
);
1595 argtypetext
= p
+ 1;
1598 if (*p
== '(' || *p
== '<')
1602 else if (*p
== ')' || *p
== '>')
1611 if (p
[-2] != '.') /* Not '...' */
1613 argtypes
[argcount
] = builtin_type_void
; /* List terminator */
1617 argtypes
[argcount
] = NULL
; /* Ellist terminator */
1620 xfree (demangled_name
);
1622 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1624 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1626 /* Now update the old "stub" type into a real type. */
1627 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1628 TYPE_DOMAIN_TYPE (mtype
) = type
;
1629 TYPE_ARG_TYPES (mtype
) = argtypes
;
1630 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1631 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1634 const struct cplus_struct_type cplus_struct_default
;
1637 allocate_cplus_struct_type (struct type
*type
)
1639 if (!HAVE_CPLUS_STRUCT (type
))
1641 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1642 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1643 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1647 /* Helper function to initialize the standard scalar types.
1649 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1650 of the string pointed to by name in the type_obstack for that objfile,
1651 and initialize the type name to that copy. There are places (mipsread.c
1652 in particular, where init_type is called with a NULL value for NAME). */
1655 init_type (enum type_code code
, int length
, int flags
, char *name
,
1656 struct objfile
*objfile
)
1658 register struct type
*type
;
1660 type
= alloc_type (objfile
);
1661 TYPE_CODE (type
) = code
;
1662 TYPE_LENGTH (type
) = length
;
1663 TYPE_FLAGS (type
) |= flags
;
1664 if ((name
!= NULL
) && (objfile
!= NULL
))
1667 obsavestring (name
, strlen (name
), &objfile
->type_obstack
);
1671 TYPE_NAME (type
) = name
;
1676 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1678 INIT_CPLUS_SPECIFIC (type
);
1683 /* Look up a fundamental type for the specified objfile.
1684 May need to construct such a type if this is the first use.
1686 Some object file formats (ELF, COFF, etc) do not define fundamental
1687 types such as "int" or "double". Others (stabs for example), do
1688 define fundamental types.
1690 For the formats which don't provide fundamental types, gdb can create
1691 such types, using defaults reasonable for the current language and
1692 the current target machine.
1694 NOTE: This routine is obsolescent. Each debugging format reader
1695 should manage it's own fundamental types, either creating them from
1696 suitable defaults or reading them from the debugging information,
1697 whichever is appropriate. The DWARF reader has already been
1698 fixed to do this. Once the other readers are fixed, this routine
1699 will go away. Also note that fundamental types should be managed
1700 on a compilation unit basis in a multi-language environment, not
1701 on a linkage unit basis as is done here. */
1705 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1707 register struct type
**typep
;
1708 register int nbytes
;
1710 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1712 error ("internal error - invalid fundamental type id %d", typeid);
1715 /* If this is the first time we need a fundamental type for this objfile
1716 then we need to initialize the vector of type pointers. */
1718 if (objfile
->fundamental_types
== NULL
)
1720 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1721 objfile
->fundamental_types
= (struct type
**)
1722 obstack_alloc (&objfile
->type_obstack
, nbytes
);
1723 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1724 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1727 /* Look for this particular type in the fundamental type vector. If one is
1728 not found, create and install one appropriate for the current language. */
1730 typep
= objfile
->fundamental_types
+ typeid;
1733 *typep
= create_fundamental_type (objfile
, typeid);
1740 can_dereference (struct type
*t
)
1742 /* FIXME: Should we return true for references as well as pointers? */
1746 && TYPE_CODE (t
) == TYPE_CODE_PTR
1747 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1751 is_integral_type (struct type
*t
)
1756 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1757 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1758 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1759 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1760 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1763 /* Chill varying string and arrays are represented as follows:
1765 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1767 Return true if TYPE is such a Chill varying type. */
1770 chill_varying_type (struct type
*type
)
1772 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1773 || TYPE_NFIELDS (type
) != 2
1774 || strcmp (TYPE_FIELD_NAME (type
, 0), "__var_length") != 0)
1779 /* Check whether BASE is an ancestor or base class or DCLASS
1780 Return 1 if so, and 0 if not.
1781 Note: callers may want to check for identity of the types before
1782 calling this function -- identical types are considered to satisfy
1783 the ancestor relationship even if they're identical */
1786 is_ancestor (struct type
*base
, struct type
*dclass
)
1790 CHECK_TYPEDEF (base
);
1791 CHECK_TYPEDEF (dclass
);
1795 if (TYPE_NAME (base
) && TYPE_NAME (dclass
) &&
1796 !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1799 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1800 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1808 /* See whether DCLASS has a virtual table. This routine is aimed at
1809 the HP/Taligent ANSI C++ runtime model, and may not work with other
1810 runtime models. Return 1 => Yes, 0 => No. */
1813 has_vtable (struct type
*dclass
)
1815 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1816 has virtual functions or virtual bases. */
1820 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1823 /* First check for the presence of virtual bases */
1824 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1825 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1826 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
1829 /* Next check for virtual functions */
1830 if (TYPE_FN_FIELDLISTS (dclass
))
1831 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
1832 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
1835 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1836 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1837 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1838 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
1839 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
1842 /* Well, maybe we don't need a virtual table */
1846 /* Return a pointer to the "primary base class" of DCLASS.
1848 A NULL return indicates that DCLASS has no primary base, or that it
1849 couldn't be found (insufficient information).
1851 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1852 and may not work with other runtime models. */
1855 primary_base_class (struct type
*dclass
)
1857 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1858 is the first directly inherited, non-virtual base class that
1859 requires a virtual table */
1863 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1866 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1867 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
1868 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
1869 return TYPE_FIELD_TYPE (dclass
, i
);
1874 /* Global manipulated by virtual_base_list[_aux]() */
1876 static struct vbase
*current_vbase_list
= NULL
;
1878 /* Return a pointer to a null-terminated list of struct vbase
1879 items. The vbasetype pointer of each item in the list points to the
1880 type information for a virtual base of the argument DCLASS.
1882 Helper function for virtual_base_list().
1883 Note: the list goes backward, right-to-left. virtual_base_list()
1884 copies the items out in reverse order. */
1887 virtual_base_list_aux (struct type
*dclass
)
1889 struct vbase
*tmp_vbase
;
1892 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1895 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1897 /* Recurse on this ancestor, first */
1898 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
1900 /* If this current base is itself virtual, add it to the list */
1901 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
1903 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
1905 /* Check if base already recorded */
1906 tmp_vbase
= current_vbase_list
;
1909 if (tmp_vbase
->vbasetype
== basetype
)
1910 break; /* found it */
1911 tmp_vbase
= tmp_vbase
->next
;
1914 if (!tmp_vbase
) /* normal exit from loop */
1916 /* Allocate new item for this virtual base */
1917 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
1919 /* Stick it on at the end of the list */
1920 tmp_vbase
->vbasetype
= basetype
;
1921 tmp_vbase
->next
= current_vbase_list
;
1922 current_vbase_list
= tmp_vbase
;
1925 } /* for loop over bases */
1929 /* Compute the list of virtual bases in the right order. Virtual
1930 bases are laid out in the object's memory area in order of their
1931 occurrence in a depth-first, left-to-right search through the
1934 Argument DCLASS is the type whose virtual bases are required.
1935 Return value is the address of a null-terminated array of pointers
1936 to struct type items.
1938 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1939 and may not work with other runtime models.
1941 This routine merely hands off the argument to virtual_base_list_aux()
1942 and then copies the result into an array to save space. */
1945 virtual_base_list (struct type
*dclass
)
1947 register struct vbase
*tmp_vbase
;
1948 register struct vbase
*tmp_vbase_2
;
1951 struct type
**vbase_array
;
1953 current_vbase_list
= NULL
;
1954 virtual_base_list_aux (dclass
);
1956 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1961 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
1963 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
1964 vbase_array
[i
] = tmp_vbase
->vbasetype
;
1966 /* Get rid of constructed chain */
1967 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
1970 tmp_vbase
= tmp_vbase
->next
;
1971 xfree (tmp_vbase_2
);
1972 tmp_vbase_2
= tmp_vbase
;
1975 vbase_array
[count
] = NULL
;
1979 /* Return the length of the virtual base list of the type DCLASS. */
1982 virtual_base_list_length (struct type
*dclass
)
1985 register struct vbase
*tmp_vbase
;
1987 current_vbase_list
= NULL
;
1988 virtual_base_list_aux (dclass
);
1990 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1995 /* Return the number of elements of the virtual base list of the type
1996 DCLASS, ignoring those appearing in the primary base (and its
1997 primary base, recursively). */
2000 virtual_base_list_length_skip_primaries (struct type
*dclass
)
2003 register struct vbase
*tmp_vbase
;
2004 struct type
*primary
;
2006 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2009 return virtual_base_list_length (dclass
);
2011 current_vbase_list
= NULL
;
2012 virtual_base_list_aux (dclass
);
2014 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
2016 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
2024 /* Return the index (position) of type BASE, which is a virtual base
2025 class of DCLASS, in the latter's virtual base list. A return of -1
2026 indicates "not found" or a problem. */
2029 virtual_base_index (struct type
*base
, struct type
*dclass
)
2031 register struct type
*vbase
;
2034 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2035 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2039 vbase
= virtual_base_list (dclass
)[0];
2044 vbase
= virtual_base_list (dclass
)[++i
];
2047 return vbase
? i
: -1;
2052 /* Return the index (position) of type BASE, which is a virtual base
2053 class of DCLASS, in the latter's virtual base list. Skip over all
2054 bases that may appear in the virtual base list of the primary base
2055 class of DCLASS (recursively). A return of -1 indicates "not
2056 found" or a problem. */
2059 virtual_base_index_skip_primaries (struct type
*base
, struct type
*dclass
)
2061 register struct type
*vbase
;
2063 struct type
*primary
;
2065 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2066 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2069 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2073 vbase
= virtual_base_list (dclass
)[0];
2076 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
2080 vbase
= virtual_base_list (dclass
)[++i
];
2083 return vbase
? j
: -1;
2086 /* Return position of a derived class DCLASS in the list of
2087 * primary bases starting with the remotest ancestor.
2088 * Position returned is 0-based. */
2091 class_index_in_primary_list (struct type
*dclass
)
2093 struct type
*pbc
; /* primary base class */
2095 /* Simply recurse on primary base */
2096 pbc
= TYPE_PRIMARY_BASE (dclass
);
2098 return 1 + class_index_in_primary_list (pbc
);
2103 /* Return a count of the number of virtual functions a type has.
2104 * This includes all the virtual functions it inherits from its
2108 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2109 * functions only once (latest redefinition)
2113 count_virtual_fns (struct type
*dclass
)
2115 int fn
, oi
; /* function and overloaded instance indices */
2116 int vfuncs
; /* count to return */
2118 /* recurse on bases that can share virtual table */
2119 struct type
*pbc
= primary_base_class (dclass
);
2121 vfuncs
= count_virtual_fns (pbc
);
2125 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2126 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2127 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2135 /* Functions for overload resolution begin here */
2137 /* Compare two badness vectors A and B and return the result.
2138 * 0 => A and B are identical
2139 * 1 => A and B are incomparable
2140 * 2 => A is better than B
2141 * 3 => A is worse than B */
2144 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2148 short found_pos
= 0; /* any positives in c? */
2149 short found_neg
= 0; /* any negatives in c? */
2151 /* differing lengths => incomparable */
2152 if (a
->length
!= b
->length
)
2155 /* Subtract b from a */
2156 for (i
= 0; i
< a
->length
; i
++)
2158 tmp
= a
->rank
[i
] - b
->rank
[i
];
2168 return 1; /* incomparable */
2170 return 3; /* A > B */
2176 return 2; /* A < B */
2178 return 0; /* A == B */
2182 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2183 * to the types of an argument list (ARGS, length NARGS).
2184 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2186 struct badness_vector
*
2187 rank_function (struct type
**parms
, int nparms
, struct type
**args
, int nargs
)
2190 struct badness_vector
*bv
;
2191 int min_len
= nparms
< nargs
? nparms
: nargs
;
2193 bv
= xmalloc (sizeof (struct badness_vector
));
2194 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2195 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2197 /* First compare the lengths of the supplied lists.
2198 * If there is a mismatch, set it to a high value. */
2200 /* pai/1997-06-03 FIXME: when we have debug info about default
2201 * arguments and ellipsis parameter lists, we should consider those
2202 * and rank the length-match more finely. */
2204 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2206 /* Now rank all the parameters of the candidate function */
2207 for (i
= 1; i
<= min_len
; i
++)
2208 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2210 /* If more arguments than parameters, add dummy entries */
2211 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2212 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2217 /* Compare one type (PARM) for compatibility with another (ARG).
2218 * PARM is intended to be the parameter type of a function; and
2219 * ARG is the supplied argument's type. This function tests if
2220 * the latter can be converted to the former.
2222 * Return 0 if they are identical types;
2223 * Otherwise, return an integer which corresponds to how compatible
2224 * PARM is to ARG. The higher the return value, the worse the match.
2225 * Generally the "bad" conversions are all uniformly assigned a 100 */
2228 rank_one_type (struct type
*parm
, struct type
*arg
)
2230 /* Identical type pointers */
2231 /* However, this still doesn't catch all cases of same type for arg
2232 * and param. The reason is that builtin types are different from
2233 * the same ones constructed from the object. */
2237 /* Resolve typedefs */
2238 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2239 parm
= check_typedef (parm
);
2240 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2241 arg
= check_typedef (arg
);
2244 Well, damnit, if the names are exactly the same,
2245 i'll say they are exactly the same. This happens when we generate
2246 method stubs. The types won't point to the same address, but they
2247 really are the same.
2250 if (TYPE_NAME (parm
) && TYPE_NAME (arg
) &&
2251 !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2254 /* Check if identical after resolving typedefs */
2258 /* See through references, since we can almost make non-references
2260 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2261 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2262 + REFERENCE_CONVERSION_BADNESS
);
2263 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2264 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2265 + REFERENCE_CONVERSION_BADNESS
);
2267 /* Debugging only. */
2268 fprintf_filtered (gdb_stderr
,"------ Arg is %s [%d], parm is %s [%d]\n",
2269 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2271 /* x -> y means arg of type x being supplied for parameter of type y */
2273 switch (TYPE_CODE (parm
))
2276 switch (TYPE_CODE (arg
))
2279 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2280 return VOID_PTR_CONVERSION_BADNESS
;
2282 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2283 case TYPE_CODE_ARRAY
:
2284 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2285 case TYPE_CODE_FUNC
:
2286 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2288 case TYPE_CODE_ENUM
:
2289 case TYPE_CODE_CHAR
:
2290 case TYPE_CODE_RANGE
:
2291 case TYPE_CODE_BOOL
:
2292 return POINTER_CONVERSION_BADNESS
;
2294 return INCOMPATIBLE_TYPE_BADNESS
;
2296 case TYPE_CODE_ARRAY
:
2297 switch (TYPE_CODE (arg
))
2300 case TYPE_CODE_ARRAY
:
2301 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2303 return INCOMPATIBLE_TYPE_BADNESS
;
2305 case TYPE_CODE_FUNC
:
2306 switch (TYPE_CODE (arg
))
2308 case TYPE_CODE_PTR
: /* funcptr -> func */
2309 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2311 return INCOMPATIBLE_TYPE_BADNESS
;
2314 switch (TYPE_CODE (arg
))
2317 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2319 /* Deal with signed, unsigned, and plain chars and
2320 signed and unsigned ints */
2321 if (TYPE_NOSIGN (parm
))
2323 /* This case only for character types */
2324 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2327 return INTEGER_COERCION_BADNESS
; /* signed/unsigned char -> plain char */
2329 else if (TYPE_UNSIGNED (parm
))
2331 if (TYPE_UNSIGNED (arg
))
2333 if (!strcmp_iw (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2334 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2335 else if (!strcmp_iw (TYPE_NAME (arg
), "int") && !strcmp_iw (TYPE_NAME (parm
), "long"))
2336 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2338 return INTEGER_COERCION_BADNESS
; /* unsigned long -> unsigned int */
2342 if (!strcmp_iw (TYPE_NAME (arg
), "long") && !strcmp_iw (TYPE_NAME (parm
), "int"))
2343 return INTEGER_COERCION_BADNESS
; /* signed long -> unsigned int */
2345 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2348 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2350 if (!strcmp_iw (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2352 else if (!strcmp_iw (TYPE_NAME (arg
), "int") && !strcmp_iw (TYPE_NAME (parm
), "long"))
2353 return INTEGER_PROMOTION_BADNESS
;
2355 return INTEGER_COERCION_BADNESS
;
2358 return INTEGER_COERCION_BADNESS
;
2360 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2361 return INTEGER_PROMOTION_BADNESS
;
2363 return INTEGER_COERCION_BADNESS
;
2364 case TYPE_CODE_ENUM
:
2365 case TYPE_CODE_CHAR
:
2366 case TYPE_CODE_RANGE
:
2367 case TYPE_CODE_BOOL
:
2368 return INTEGER_PROMOTION_BADNESS
;
2370 return INT_FLOAT_CONVERSION_BADNESS
;
2372 return NS_POINTER_CONVERSION_BADNESS
;
2374 return INCOMPATIBLE_TYPE_BADNESS
;
2377 case TYPE_CODE_ENUM
:
2378 switch (TYPE_CODE (arg
))
2381 case TYPE_CODE_CHAR
:
2382 case TYPE_CODE_RANGE
:
2383 case TYPE_CODE_BOOL
:
2384 case TYPE_CODE_ENUM
:
2385 return INTEGER_COERCION_BADNESS
;
2387 return INT_FLOAT_CONVERSION_BADNESS
;
2389 return INCOMPATIBLE_TYPE_BADNESS
;
2392 case TYPE_CODE_CHAR
:
2393 switch (TYPE_CODE (arg
))
2395 case TYPE_CODE_RANGE
:
2396 case TYPE_CODE_BOOL
:
2397 case TYPE_CODE_ENUM
:
2398 return INTEGER_COERCION_BADNESS
;
2400 return INT_FLOAT_CONVERSION_BADNESS
;
2402 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2403 return INTEGER_COERCION_BADNESS
;
2404 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2405 return INTEGER_PROMOTION_BADNESS
;
2406 /* >>> !! else fall through !! <<< */
2407 case TYPE_CODE_CHAR
:
2408 /* Deal with signed, unsigned, and plain chars for C++
2409 and with int cases falling through from previous case */
2410 if (TYPE_NOSIGN (parm
))
2412 if (TYPE_NOSIGN (arg
))
2415 return INTEGER_COERCION_BADNESS
;
2417 else if (TYPE_UNSIGNED (parm
))
2419 if (TYPE_UNSIGNED (arg
))
2422 return INTEGER_PROMOTION_BADNESS
;
2424 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2427 return INTEGER_COERCION_BADNESS
;
2429 return INCOMPATIBLE_TYPE_BADNESS
;
2432 case TYPE_CODE_RANGE
:
2433 switch (TYPE_CODE (arg
))
2436 case TYPE_CODE_CHAR
:
2437 case TYPE_CODE_RANGE
:
2438 case TYPE_CODE_BOOL
:
2439 case TYPE_CODE_ENUM
:
2440 return INTEGER_COERCION_BADNESS
;
2442 return INT_FLOAT_CONVERSION_BADNESS
;
2444 return INCOMPATIBLE_TYPE_BADNESS
;
2447 case TYPE_CODE_BOOL
:
2448 switch (TYPE_CODE (arg
))
2451 case TYPE_CODE_CHAR
:
2452 case TYPE_CODE_RANGE
:
2453 case TYPE_CODE_ENUM
:
2456 return BOOLEAN_CONVERSION_BADNESS
;
2457 case TYPE_CODE_BOOL
:
2460 return INCOMPATIBLE_TYPE_BADNESS
;
2464 switch (TYPE_CODE (arg
))
2467 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2468 return FLOAT_PROMOTION_BADNESS
;
2469 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2472 return FLOAT_CONVERSION_BADNESS
;
2474 case TYPE_CODE_BOOL
:
2475 case TYPE_CODE_ENUM
:
2476 case TYPE_CODE_RANGE
:
2477 case TYPE_CODE_CHAR
:
2478 return INT_FLOAT_CONVERSION_BADNESS
;
2480 return INCOMPATIBLE_TYPE_BADNESS
;
2483 case TYPE_CODE_COMPLEX
:
2484 switch (TYPE_CODE (arg
))
2485 { /* Strictly not needed for C++, but... */
2487 return FLOAT_PROMOTION_BADNESS
;
2488 case TYPE_CODE_COMPLEX
:
2491 return INCOMPATIBLE_TYPE_BADNESS
;
2494 case TYPE_CODE_STRUCT
:
2495 /* currently same as TYPE_CODE_CLASS */
2496 switch (TYPE_CODE (arg
))
2498 case TYPE_CODE_STRUCT
:
2499 /* Check for derivation */
2500 if (is_ancestor (parm
, arg
))
2501 return BASE_CONVERSION_BADNESS
;
2502 /* else fall through */
2504 return INCOMPATIBLE_TYPE_BADNESS
;
2507 case TYPE_CODE_UNION
:
2508 switch (TYPE_CODE (arg
))
2510 case TYPE_CODE_UNION
:
2512 return INCOMPATIBLE_TYPE_BADNESS
;
2515 case TYPE_CODE_MEMBER
:
2516 switch (TYPE_CODE (arg
))
2519 return INCOMPATIBLE_TYPE_BADNESS
;
2522 case TYPE_CODE_METHOD
:
2523 switch (TYPE_CODE (arg
))
2527 return INCOMPATIBLE_TYPE_BADNESS
;
2531 switch (TYPE_CODE (arg
))
2535 return INCOMPATIBLE_TYPE_BADNESS
;
2540 switch (TYPE_CODE (arg
))
2544 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2546 return INCOMPATIBLE_TYPE_BADNESS
;
2549 case TYPE_CODE_VOID
:
2551 return INCOMPATIBLE_TYPE_BADNESS
;
2552 } /* switch (TYPE_CODE (arg)) */
2556 /* End of functions for overload resolution */
2559 print_bit_vector (B_TYPE
*bits
, int nbits
)
2563 for (bitno
= 0; bitno
< nbits
; bitno
++)
2565 if ((bitno
% 8) == 0)
2567 puts_filtered (" ");
2569 if (B_TST (bits
, bitno
))
2571 printf_filtered ("1");
2575 printf_filtered ("0");
2580 /* The args list is a strange beast. It is either terminated by a NULL
2581 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2582 type for normal fixed argcount functions. (FIXME someday)
2583 Also note the first arg should be the "this" pointer, we may not want to
2584 include it since we may get into a infinitely recursive situation. */
2587 print_arg_types (struct type
**args
, int spaces
)
2591 while (*args
!= NULL
)
2593 recursive_dump_type (*args
, spaces
+ 2);
2594 if ((*args
++)->code
== TYPE_CODE_VOID
)
2603 dump_fn_fieldlists (struct type
*type
, int spaces
)
2609 printfi_filtered (spaces
, "fn_fieldlists ");
2610 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2611 printf_filtered ("\n");
2612 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2614 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2615 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2617 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2618 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2620 printf_filtered (") length %d\n",
2621 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2622 for (overload_idx
= 0;
2623 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2626 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2628 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2629 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2631 printf_filtered (")\n");
2632 printfi_filtered (spaces
+ 8, "type ");
2633 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2634 printf_filtered ("\n");
2636 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2639 printfi_filtered (spaces
+ 8, "args ");
2640 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2641 printf_filtered ("\n");
2643 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
), spaces
);
2644 printfi_filtered (spaces
+ 8, "fcontext ");
2645 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2647 printf_filtered ("\n");
2649 printfi_filtered (spaces
+ 8, "is_const %d\n",
2650 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2651 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2652 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2653 printfi_filtered (spaces
+ 8, "is_private %d\n",
2654 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2655 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2656 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2657 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2658 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2659 printfi_filtered (spaces
+ 8, "voffset %u\n",
2660 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2666 print_cplus_stuff (struct type
*type
, int spaces
)
2668 printfi_filtered (spaces
, "n_baseclasses %d\n",
2669 TYPE_N_BASECLASSES (type
));
2670 printfi_filtered (spaces
, "nfn_fields %d\n",
2671 TYPE_NFN_FIELDS (type
));
2672 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2673 TYPE_NFN_FIELDS_TOTAL (type
));
2674 if (TYPE_N_BASECLASSES (type
) > 0)
2676 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2677 TYPE_N_BASECLASSES (type
));
2678 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2679 printf_filtered (")");
2681 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2682 TYPE_N_BASECLASSES (type
));
2683 puts_filtered ("\n");
2685 if (TYPE_NFIELDS (type
) > 0)
2687 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2689 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2690 TYPE_NFIELDS (type
));
2691 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2692 printf_filtered (")");
2693 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2694 TYPE_NFIELDS (type
));
2695 puts_filtered ("\n");
2697 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2699 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2700 TYPE_NFIELDS (type
));
2701 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2702 printf_filtered (")");
2703 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2704 TYPE_NFIELDS (type
));
2705 puts_filtered ("\n");
2708 if (TYPE_NFN_FIELDS (type
) > 0)
2710 dump_fn_fieldlists (type
, spaces
);
2715 print_bound_type (int bt
)
2719 case BOUND_CANNOT_BE_DETERMINED
:
2720 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2722 case BOUND_BY_REF_ON_STACK
:
2723 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2725 case BOUND_BY_VALUE_ON_STACK
:
2726 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2728 case BOUND_BY_REF_IN_REG
:
2729 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2731 case BOUND_BY_VALUE_IN_REG
:
2732 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2735 printf_filtered ("(BOUND_SIMPLE)");
2738 printf_filtered ("(unknown bound type)");
2743 static struct obstack dont_print_type_obstack
;
2746 recursive_dump_type (struct type
*type
, int spaces
)
2751 obstack_begin (&dont_print_type_obstack
, 0);
2753 if (TYPE_NFIELDS (type
) > 0
2754 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2756 struct type
**first_dont_print
2757 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2759 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
2764 if (type
== first_dont_print
[i
])
2766 printfi_filtered (spaces
, "type node ");
2767 gdb_print_host_address (type
, gdb_stdout
);
2768 printf_filtered (" <same as already seen type>\n");
2773 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2776 printfi_filtered (spaces
, "type node ");
2777 gdb_print_host_address (type
, gdb_stdout
);
2778 printf_filtered ("\n");
2779 printfi_filtered (spaces
, "name '%s' (",
2780 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2781 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2782 printf_filtered (")\n");
2783 printfi_filtered (spaces
, "tagname '%s' (",
2784 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "<NULL>");
2785 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2786 printf_filtered (")\n");
2787 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2788 switch (TYPE_CODE (type
))
2790 case TYPE_CODE_UNDEF
:
2791 printf_filtered ("(TYPE_CODE_UNDEF)");
2794 printf_filtered ("(TYPE_CODE_PTR)");
2796 case TYPE_CODE_ARRAY
:
2797 printf_filtered ("(TYPE_CODE_ARRAY)");
2799 case TYPE_CODE_STRUCT
:
2800 printf_filtered ("(TYPE_CODE_STRUCT)");
2802 case TYPE_CODE_UNION
:
2803 printf_filtered ("(TYPE_CODE_UNION)");
2805 case TYPE_CODE_ENUM
:
2806 printf_filtered ("(TYPE_CODE_ENUM)");
2808 case TYPE_CODE_FUNC
:
2809 printf_filtered ("(TYPE_CODE_FUNC)");
2812 printf_filtered ("(TYPE_CODE_INT)");
2815 printf_filtered ("(TYPE_CODE_FLT)");
2817 case TYPE_CODE_VOID
:
2818 printf_filtered ("(TYPE_CODE_VOID)");
2821 printf_filtered ("(TYPE_CODE_SET)");
2823 case TYPE_CODE_RANGE
:
2824 printf_filtered ("(TYPE_CODE_RANGE)");
2826 case TYPE_CODE_STRING
:
2827 printf_filtered ("(TYPE_CODE_STRING)");
2829 case TYPE_CODE_BITSTRING
:
2830 printf_filtered ("(TYPE_CODE_BITSTRING)");
2832 case TYPE_CODE_ERROR
:
2833 printf_filtered ("(TYPE_CODE_ERROR)");
2835 case TYPE_CODE_MEMBER
:
2836 printf_filtered ("(TYPE_CODE_MEMBER)");
2838 case TYPE_CODE_METHOD
:
2839 printf_filtered ("(TYPE_CODE_METHOD)");
2842 printf_filtered ("(TYPE_CODE_REF)");
2844 case TYPE_CODE_CHAR
:
2845 printf_filtered ("(TYPE_CODE_CHAR)");
2847 case TYPE_CODE_BOOL
:
2848 printf_filtered ("(TYPE_CODE_BOOL)");
2850 case TYPE_CODE_COMPLEX
:
2851 printf_filtered ("(TYPE_CODE_COMPLEX)");
2853 case TYPE_CODE_TYPEDEF
:
2854 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2856 case TYPE_CODE_TEMPLATE
:
2857 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2859 case TYPE_CODE_TEMPLATE_ARG
:
2860 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2863 printf_filtered ("(UNKNOWN TYPE CODE)");
2866 puts_filtered ("\n");
2867 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2868 printfi_filtered (spaces
, "upper_bound_type 0x%x ",
2869 TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
2870 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type
));
2871 puts_filtered ("\n");
2872 printfi_filtered (spaces
, "lower_bound_type 0x%x ",
2873 TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
2874 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type
));
2875 puts_filtered ("\n");
2876 printfi_filtered (spaces
, "objfile ");
2877 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
2878 printf_filtered ("\n");
2879 printfi_filtered (spaces
, "target_type ");
2880 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2881 printf_filtered ("\n");
2882 if (TYPE_TARGET_TYPE (type
) != NULL
)
2884 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2886 printfi_filtered (spaces
, "pointer_type ");
2887 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2888 printf_filtered ("\n");
2889 printfi_filtered (spaces
, "reference_type ");
2890 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2891 printf_filtered ("\n");
2892 printfi_filtered (spaces
, "cv_type ");
2893 gdb_print_host_address (TYPE_CV_TYPE (type
), gdb_stdout
);
2894 printf_filtered ("\n");
2895 printfi_filtered (spaces
, "as_type ");
2896 gdb_print_host_address (TYPE_AS_TYPE (type
), gdb_stdout
);
2897 printf_filtered ("\n");
2898 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
2899 if (TYPE_UNSIGNED (type
))
2901 puts_filtered (" TYPE_FLAG_UNSIGNED");
2903 if (TYPE_NOSIGN (type
))
2905 puts_filtered (" TYPE_FLAG_NOSIGN");
2907 if (TYPE_STUB (type
))
2909 puts_filtered (" TYPE_FLAG_STUB");
2911 if (TYPE_TARGET_STUB (type
))
2913 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2915 if (TYPE_STATIC (type
))
2917 puts_filtered (" TYPE_FLAG_STATIC");
2919 if (TYPE_CONST (type
))
2921 puts_filtered (" TYPE_FLAG_CONST");
2923 if (TYPE_VOLATILE (type
))
2925 puts_filtered (" TYPE_FLAG_VOLATILE");
2927 if (TYPE_PROTOTYPED (type
))
2929 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2931 if (TYPE_INCOMPLETE (type
))
2933 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2935 if (TYPE_CODE_SPACE (type
))
2937 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2939 if (TYPE_DATA_SPACE (type
))
2941 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2943 if (TYPE_VARARGS (type
))
2945 puts_filtered (" TYPE_FLAG_VARARGS");
2947 puts_filtered ("\n");
2948 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2949 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
2950 puts_filtered ("\n");
2951 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2953 printfi_filtered (spaces
+ 2,
2954 "[%d] bitpos %d bitsize %d type ",
2955 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2956 TYPE_FIELD_BITSIZE (type
, idx
));
2957 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2958 printf_filtered (" name '%s' (",
2959 TYPE_FIELD_NAME (type
, idx
) != NULL
2960 ? TYPE_FIELD_NAME (type
, idx
)
2962 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2963 printf_filtered (")\n");
2964 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2966 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2969 printfi_filtered (spaces
, "vptr_basetype ");
2970 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2971 puts_filtered ("\n");
2972 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2974 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2976 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
2977 switch (TYPE_CODE (type
))
2979 case TYPE_CODE_METHOD
:
2980 case TYPE_CODE_FUNC
:
2981 printfi_filtered (spaces
, "arg_types ");
2982 gdb_print_host_address (TYPE_ARG_TYPES (type
), gdb_stdout
);
2983 puts_filtered ("\n");
2984 print_arg_types (TYPE_ARG_TYPES (type
), spaces
);
2987 case TYPE_CODE_STRUCT
:
2988 printfi_filtered (spaces
, "cplus_stuff ");
2989 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2990 puts_filtered ("\n");
2991 print_cplus_stuff (type
, spaces
);
2995 printfi_filtered (spaces
, "floatformat ");
2996 if (TYPE_FLOATFORMAT (type
) == NULL
2997 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
2998 puts_filtered ("(null)");
3000 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
3001 puts_filtered ("\n");
3005 /* We have to pick one of the union types to be able print and test
3006 the value. Pick cplus_struct_type, even though we know it isn't
3007 any particular one. */
3008 printfi_filtered (spaces
, "type_specific ");
3009 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
3010 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
3012 printf_filtered (" (unknown data form)");
3014 printf_filtered ("\n");
3019 obstack_free (&dont_print_type_obstack
, NULL
);
3022 static void build_gdbtypes (void);
3024 build_gdbtypes (void)
3027 init_type (TYPE_CODE_VOID
, 1,
3029 "void", (struct objfile
*) NULL
);
3031 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3033 "char", (struct objfile
*) NULL
);
3034 builtin_type_true_char
=
3035 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3037 "true character", (struct objfile
*) NULL
);
3038 builtin_type_signed_char
=
3039 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3041 "signed char", (struct objfile
*) NULL
);
3042 builtin_type_unsigned_char
=
3043 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3045 "unsigned char", (struct objfile
*) NULL
);
3046 builtin_type_short
=
3047 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3049 "short", (struct objfile
*) NULL
);
3050 builtin_type_unsigned_short
=
3051 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
3053 "unsigned short", (struct objfile
*) NULL
);
3055 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3057 "int", (struct objfile
*) NULL
);
3058 builtin_type_unsigned_int
=
3059 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3061 "unsigned int", (struct objfile
*) NULL
);
3063 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3065 "long", (struct objfile
*) NULL
);
3066 builtin_type_unsigned_long
=
3067 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
3069 "unsigned long", (struct objfile
*) NULL
);
3070 builtin_type_long_long
=
3071 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3073 "long long", (struct objfile
*) NULL
);
3074 builtin_type_unsigned_long_long
=
3075 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
3077 "unsigned long long", (struct objfile
*) NULL
);
3078 builtin_type_float
=
3079 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3081 "float", (struct objfile
*) NULL
);
3082 TYPE_FLOATFORMAT (builtin_type_float
) = TARGET_FLOAT_FORMAT
;
3083 builtin_type_double
=
3084 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3086 "double", (struct objfile
*) NULL
);
3087 TYPE_FLOATFORMAT (builtin_type_double
) = TARGET_DOUBLE_FORMAT
;
3088 builtin_type_long_double
=
3089 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3091 "long double", (struct objfile
*) NULL
);
3092 TYPE_FLOATFORMAT (builtin_type_long_double
) = TARGET_LONG_DOUBLE_FORMAT
;
3093 builtin_type_complex
=
3094 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3096 "complex", (struct objfile
*) NULL
);
3097 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
3098 builtin_type_double_complex
=
3099 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3101 "double complex", (struct objfile
*) NULL
);
3102 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
3103 builtin_type_string
=
3104 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3106 "string", (struct objfile
*) NULL
);
3108 init_type (TYPE_CODE_INT
, 8 / 8,
3110 "int8_t", (struct objfile
*) NULL
);
3111 builtin_type_uint8
=
3112 init_type (TYPE_CODE_INT
, 8 / 8,
3114 "uint8_t", (struct objfile
*) NULL
);
3115 builtin_type_int16
=
3116 init_type (TYPE_CODE_INT
, 16 / 8,
3118 "int16_t", (struct objfile
*) NULL
);
3119 builtin_type_uint16
=
3120 init_type (TYPE_CODE_INT
, 16 / 8,
3122 "uint16_t", (struct objfile
*) NULL
);
3123 builtin_type_int32
=
3124 init_type (TYPE_CODE_INT
, 32 / 8,
3126 "int32_t", (struct objfile
*) NULL
);
3127 builtin_type_uint32
=
3128 init_type (TYPE_CODE_INT
, 32 / 8,
3130 "uint32_t", (struct objfile
*) NULL
);
3131 builtin_type_int64
=
3132 init_type (TYPE_CODE_INT
, 64 / 8,
3134 "int64_t", (struct objfile
*) NULL
);
3135 builtin_type_uint64
=
3136 init_type (TYPE_CODE_INT
, 64 / 8,
3138 "uint64_t", (struct objfile
*) NULL
);
3139 builtin_type_int128
=
3140 init_type (TYPE_CODE_INT
, 128 / 8,
3142 "int128_t", (struct objfile
*) NULL
);
3143 builtin_type_uint128
=
3144 init_type (TYPE_CODE_INT
, 128 / 8,
3146 "uint128_t", (struct objfile
*) NULL
);
3148 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3150 "bool", (struct objfile
*) NULL
);
3152 /* Add user knob for controlling resolution of opaque types */
3154 (add_set_cmd ("opaque-type-resolution", class_support
, var_boolean
, (char *) &opaque_type_resolution
,
3155 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3158 opaque_type_resolution
= 1;
3160 /* Build SIMD types. */
3162 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
3164 = init_simd_type ("__builtin_v4si", builtin_type_int32
, "f", 4);
3166 = init_simd_type ("__builtin_v8qi", builtin_type_int8
, "f", 8);
3168 = init_simd_type ("__builtin_v4hi", builtin_type_int16
, "f", 4);
3170 = init_simd_type ("__builtin_v2si", builtin_type_int32
, "f", 2);
3172 /* Pointer/Address types. */
3174 /* NOTE: on some targets, addresses and pointers are not necessarily
3175 the same --- for example, on the D10V, pointers are 16 bits long,
3176 but addresses are 32 bits long. See doc/gdbint.texinfo,
3177 ``Pointers Are Not Always Addresses''.
3180 - gdb's `struct type' always describes the target's
3182 - gdb's `struct value' objects should always hold values in
3184 - gdb's CORE_ADDR values are addresses in the unified virtual
3185 address space that the assembler and linker work with. Thus,
3186 since target_read_memory takes a CORE_ADDR as an argument, it
3187 can access any memory on the target, even if the processor has
3188 separate code and data address spaces.
3191 - If v is a value holding a D10V code pointer, its contents are
3192 in target form: a big-endian address left-shifted two bits.
3193 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3194 sizeof (void *) == 2 on the target.
3196 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3197 target type for a value the target will never see. It's only
3198 used to hold the values of (typeless) linker symbols, which are
3199 indeed in the unified virtual address space. */
3200 builtin_type_void_data_ptr
= make_pointer_type (builtin_type_void
, NULL
);
3201 builtin_type_void_func_ptr
3202 = lookup_pointer_type (lookup_function_type (builtin_type_void
));
3203 builtin_type_CORE_ADDR
=
3204 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3206 "__CORE_ADDR", (struct objfile
*) NULL
);
3207 builtin_type_bfd_vma
=
3208 init_type (TYPE_CODE_INT
, TARGET_BFD_VMA_BIT
/ 8,
3210 "__bfd_vma", (struct objfile
*) NULL
);
3214 extern void _initialize_gdbtypes (void);
3216 _initialize_gdbtypes (void)
3218 struct cmd_list_element
*c
;
3221 /* FIXME - For the moment, handle types by swapping them in and out.
3222 Should be using the per-architecture data-pointer and a large
3224 register_gdbarch_swap (&builtin_type_void
, sizeof (struct type
*), NULL
);
3225 register_gdbarch_swap (&builtin_type_char
, sizeof (struct type
*), NULL
);
3226 register_gdbarch_swap (&builtin_type_short
, sizeof (struct type
*), NULL
);
3227 register_gdbarch_swap (&builtin_type_int
, sizeof (struct type
*), NULL
);
3228 register_gdbarch_swap (&builtin_type_long
, sizeof (struct type
*), NULL
);
3229 register_gdbarch_swap (&builtin_type_long_long
, sizeof (struct type
*), NULL
);
3230 register_gdbarch_swap (&builtin_type_signed_char
, sizeof (struct type
*), NULL
);
3231 register_gdbarch_swap (&builtin_type_unsigned_char
, sizeof (struct type
*), NULL
);
3232 register_gdbarch_swap (&builtin_type_unsigned_short
, sizeof (struct type
*), NULL
);
3233 register_gdbarch_swap (&builtin_type_unsigned_int
, sizeof (struct type
*), NULL
);
3234 register_gdbarch_swap (&builtin_type_unsigned_long
, sizeof (struct type
*), NULL
);
3235 register_gdbarch_swap (&builtin_type_unsigned_long_long
, sizeof (struct type
*), NULL
);
3236 register_gdbarch_swap (&builtin_type_float
, sizeof (struct type
*), NULL
);
3237 register_gdbarch_swap (&builtin_type_double
, sizeof (struct type
*), NULL
);
3238 register_gdbarch_swap (&builtin_type_long_double
, sizeof (struct type
*), NULL
);
3239 register_gdbarch_swap (&builtin_type_complex
, sizeof (struct type
*), NULL
);
3240 register_gdbarch_swap (&builtin_type_double_complex
, sizeof (struct type
*), NULL
);
3241 register_gdbarch_swap (&builtin_type_string
, sizeof (struct type
*), NULL
);
3242 register_gdbarch_swap (&builtin_type_int8
, sizeof (struct type
*), NULL
);
3243 register_gdbarch_swap (&builtin_type_uint8
, sizeof (struct type
*), NULL
);
3244 register_gdbarch_swap (&builtin_type_int16
, sizeof (struct type
*), NULL
);
3245 register_gdbarch_swap (&builtin_type_uint16
, sizeof (struct type
*), NULL
);
3246 register_gdbarch_swap (&builtin_type_int32
, sizeof (struct type
*), NULL
);
3247 register_gdbarch_swap (&builtin_type_uint32
, sizeof (struct type
*), NULL
);
3248 register_gdbarch_swap (&builtin_type_int64
, sizeof (struct type
*), NULL
);
3249 register_gdbarch_swap (&builtin_type_uint64
, sizeof (struct type
*), NULL
);
3250 register_gdbarch_swap (&builtin_type_int128
, sizeof (struct type
*), NULL
);
3251 register_gdbarch_swap (&builtin_type_uint128
, sizeof (struct type
*), NULL
);
3252 register_gdbarch_swap (&builtin_type_v4sf
, sizeof (struct type
*), NULL
);
3253 register_gdbarch_swap (&builtin_type_v4si
, sizeof (struct type
*), NULL
);
3254 register_gdbarch_swap (&builtin_type_v8qi
, sizeof (struct type
*), NULL
);
3255 register_gdbarch_swap (&builtin_type_v4hi
, sizeof (struct type
*), NULL
);
3256 register_gdbarch_swap (&builtin_type_v2si
, sizeof (struct type
*), NULL
);
3257 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr
);
3258 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr
);
3259 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR
);
3260 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma
);
3261 register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
3263 /* Note: These types do not need to be swapped - they are target
3265 builtin_type_ieee_single_big
=
3266 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_big
.totalsize
/ 8,
3267 0, "builtin_type_ieee_single_big", NULL
);
3268 TYPE_FLOATFORMAT (builtin_type_ieee_single_big
) = &floatformat_ieee_single_big
;
3269 builtin_type_ieee_single_little
=
3270 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_little
.totalsize
/ 8,
3271 0, "builtin_type_ieee_single_little", NULL
);
3272 builtin_type_ieee_double_big
=
3273 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_big
.totalsize
/ 8,
3274 0, "builtin_type_ieee_double_big", NULL
);
3275 builtin_type_ieee_double_little
=
3276 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_little
.totalsize
/ 8,
3277 0, "builtin_type_ieee_double_little", NULL
);
3278 builtin_type_ieee_double_littlebyte_bigword
=
3279 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_littlebyte_bigword
.totalsize
/ 8,
3280 0, "builtin_type_ieee_double_littlebyte_bigword", NULL
);
3281 builtin_type_i387_ext
=
3282 init_type (TYPE_CODE_FLT
, floatformat_i387_ext
.totalsize
/ 8,
3283 0, "builtin_type_i387_ext", NULL
);
3284 TYPE_FLOATFORMAT (builtin_type_i387_ext
) = &floatformat_i387_ext
;
3285 builtin_type_m68881_ext
=
3286 init_type (TYPE_CODE_FLT
, floatformat_m68881_ext
.totalsize
/ 8,
3287 0, "builtin_type_m68881_ext", NULL
);
3288 builtin_type_i960_ext
=
3289 init_type (TYPE_CODE_FLT
, floatformat_i960_ext
.totalsize
/ 8,
3290 0, "builtin_type_i960_ext", NULL
);
3291 builtin_type_m88110_ext
=
3292 init_type (TYPE_CODE_FLT
, floatformat_m88110_ext
.totalsize
/ 8,
3293 0, "builtin_type_m88110_ext", NULL
);
3294 builtin_type_m88110_harris_ext
=
3295 init_type (TYPE_CODE_FLT
, floatformat_m88110_harris_ext
.totalsize
/ 8,
3296 0, "builtin_type_m88110_harris_ext", NULL
);
3297 builtin_type_arm_ext_big
=
3298 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_big
.totalsize
/ 8,
3299 0, "builtin_type_arm_ext_big", NULL
);
3300 builtin_type_arm_ext_littlebyte_bigword
=
3301 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_littlebyte_bigword
.totalsize
/ 8,
3302 0, "builtin_type_arm_ext_littlebyte_bigword", NULL
);
3303 builtin_type_ia64_spill_big
=
3304 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_big
.totalsize
/ 8,
3305 0, "builtin_type_ia64_spill_big", NULL
);
3306 builtin_type_ia64_spill_little
=
3307 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_little
.totalsize
/ 8,
3308 0, "builtin_type_ia64_spill_little", NULL
);
3309 builtin_type_ia64_quad_big
=
3310 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_big
.totalsize
/ 8,
3311 0, "builtin_type_ia64_quad_big", NULL
);
3312 builtin_type_ia64_quad_little
=
3313 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_little
.totalsize
/ 8,
3314 0, "builtin_type_ia64_quad_little", NULL
);
3317 add_set_cmd ("overload", no_class
, var_zinteger
, (char *) &overload_debug
,
3318 "Set debugging of C++ overloading.\n\
3319 When enabled, ranking of the functions\n\
3320 is displayed.", &setdebuglist
),