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
= alloc_type (TYPE_OBJFILE (type
));
546 TYPE_TARGET_TYPE (mtype
) = type
;
547 /* _DOMAIN_TYPE (mtype) = unknown yet */
548 /* _ARG_TYPES (mtype) = unknown yet */
549 TYPE_FLAGS (mtype
) = TYPE_FLAG_STUB
;
550 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
551 TYPE_LENGTH (mtype
) = 1;
555 /* Create a range type using either a blank type supplied in RESULT_TYPE,
556 or creating a new type, inheriting the objfile from INDEX_TYPE.
558 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
559 HIGH_BOUND, inclusive.
561 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
562 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
565 create_range_type (struct type
*result_type
, struct type
*index_type
,
566 int low_bound
, int high_bound
)
568 if (result_type
== NULL
)
570 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
572 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
573 TYPE_TARGET_TYPE (result_type
) = index_type
;
574 if (TYPE_FLAGS (index_type
) & TYPE_FLAG_STUB
)
575 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
577 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
578 TYPE_NFIELDS (result_type
) = 2;
579 TYPE_FIELDS (result_type
) = (struct field
*)
580 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
581 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
582 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
583 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
584 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
585 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
588 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
590 return (result_type
);
593 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
594 Return 1 of type is a range type, 0 if it is discrete (and bounds
595 will fit in LONGEST), or -1 otherwise. */
598 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
600 CHECK_TYPEDEF (type
);
601 switch (TYPE_CODE (type
))
603 case TYPE_CODE_RANGE
:
604 *lowp
= TYPE_LOW_BOUND (type
);
605 *highp
= TYPE_HIGH_BOUND (type
);
608 if (TYPE_NFIELDS (type
) > 0)
610 /* The enums may not be sorted by value, so search all
614 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
615 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
617 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
618 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
619 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
620 *highp
= TYPE_FIELD_BITPOS (type
, i
);
623 /* Set unsigned indicator if warranted. */
626 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
640 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
642 if (!TYPE_UNSIGNED (type
))
644 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
648 /* ... fall through for unsigned ints ... */
651 /* This round-about calculation is to avoid shifting by
652 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
653 if TYPE_LENGTH (type) == sizeof (LONGEST). */
654 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
655 *highp
= (*highp
- 1) | *highp
;
662 /* Create an array type using either a blank type supplied in RESULT_TYPE,
663 or creating a new type, inheriting the objfile from RANGE_TYPE.
665 Elements will be of type ELEMENT_TYPE, the indices will be of type
668 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
669 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
672 create_array_type (struct type
*result_type
, struct type
*element_type
,
673 struct type
*range_type
)
675 LONGEST low_bound
, high_bound
;
677 if (result_type
== NULL
)
679 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
681 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
682 TYPE_TARGET_TYPE (result_type
) = element_type
;
683 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
684 low_bound
= high_bound
= 0;
685 CHECK_TYPEDEF (element_type
);
686 TYPE_LENGTH (result_type
) =
687 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
688 TYPE_NFIELDS (result_type
) = 1;
689 TYPE_FIELDS (result_type
) =
690 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
691 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
692 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
693 TYPE_VPTR_FIELDNO (result_type
) = -1;
695 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
696 if (TYPE_LENGTH (result_type
) == 0)
697 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
699 return (result_type
);
702 /* Create a string type using either a blank type supplied in RESULT_TYPE,
703 or creating a new type. String types are similar enough to array of
704 char types that we can use create_array_type to build the basic type
705 and then bash it into a string type.
707 For fixed length strings, the range type contains 0 as the lower
708 bound and the length of the string minus one as the upper bound.
710 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
711 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
714 create_string_type (struct type
*result_type
, struct type
*range_type
)
716 result_type
= create_array_type (result_type
,
717 *current_language
->string_char_type
,
719 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
720 return (result_type
);
724 create_set_type (struct type
*result_type
, struct type
*domain_type
)
726 LONGEST low_bound
, high_bound
, bit_length
;
727 if (result_type
== NULL
)
729 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
731 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
732 TYPE_NFIELDS (result_type
) = 1;
733 TYPE_FIELDS (result_type
) = (struct field
*)
734 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
735 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
737 if (!(TYPE_FLAGS (domain_type
) & TYPE_FLAG_STUB
))
739 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
740 low_bound
= high_bound
= 0;
741 bit_length
= high_bound
- low_bound
+ 1;
742 TYPE_LENGTH (result_type
)
743 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
745 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
748 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
750 return (result_type
);
754 /* Construct and return a type of the form:
755 struct NAME { ELT_TYPE ELT_NAME[N]; }
756 We use these types for SIMD registers. For example, the type of
757 the SSE registers on the late x86-family processors is:
758 struct __builtin_v4sf { float f[4]; }
759 built by the function call:
760 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
761 The type returned is a permanent type, allocated using malloc; it
762 doesn't live in any objfile's obstack. */
764 init_simd_type (char *name
,
765 struct type
*elt_type
,
772 /* Build the field structure. */
773 f
= xmalloc (sizeof (*f
));
774 memset (f
, 0, sizeof (*f
));
776 f
->type
= create_array_type (0, elt_type
,
777 create_range_type (0, builtin_type_int
,
781 /* Build a struct type with that field. */
782 t
= init_type (TYPE_CODE_STRUCT
, n
* TYPE_LENGTH (elt_type
), 0, 0, 0);
791 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
792 A MEMBER is a wierd thing -- it amounts to a typed offset into
793 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
794 include the offset (that's the value of the MEMBER itself), but does
795 include the structure type into which it points (for some reason).
797 When "smashing" the type, we preserve the objfile that the
798 old type pointed to, since we aren't changing where the type is actually
802 smash_to_member_type (struct type
*type
, struct type
*domain
,
803 struct type
*to_type
)
805 struct objfile
*objfile
;
807 objfile
= TYPE_OBJFILE (type
);
809 memset ((char *) type
, 0, sizeof (struct type
));
810 TYPE_OBJFILE (type
) = objfile
;
811 TYPE_TARGET_TYPE (type
) = to_type
;
812 TYPE_DOMAIN_TYPE (type
) = domain
;
813 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
814 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
817 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
818 METHOD just means `function that gets an extra "this" argument'.
820 When "smashing" the type, we preserve the objfile that the
821 old type pointed to, since we aren't changing where the type is actually
825 smash_to_method_type (struct type
*type
, struct type
*domain
,
826 struct type
*to_type
, struct type
**args
)
828 struct objfile
*objfile
;
830 objfile
= TYPE_OBJFILE (type
);
832 memset ((char *) type
, 0, sizeof (struct type
));
833 TYPE_OBJFILE (type
) = objfile
;
834 TYPE_TARGET_TYPE (type
) = to_type
;
835 TYPE_DOMAIN_TYPE (type
) = domain
;
836 TYPE_ARG_TYPES (type
) = args
;
837 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
838 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
841 /* Return a typename for a struct/union/enum type without "struct ",
842 "union ", or "enum ". If the type has a NULL name, return NULL. */
845 type_name_no_tag (register const struct type
*type
)
847 if (TYPE_TAG_NAME (type
) != NULL
)
848 return TYPE_TAG_NAME (type
);
850 /* Is there code which expects this to return the name if there is no
851 tag name? My guess is that this is mainly used for C++ in cases where
852 the two will always be the same. */
853 return TYPE_NAME (type
);
856 /* Lookup a primitive type named NAME.
857 Return zero if NAME is not a primitive type. */
860 lookup_primitive_typename (char *name
)
862 struct type
**const *p
;
864 for (p
= current_language
->la_builtin_type_vector
; *p
!= NULL
; p
++)
866 if (STREQ ((**p
)->name
, name
))
874 /* Lookup a typedef or primitive type named NAME,
875 visible in lexical block BLOCK.
876 If NOERR is nonzero, return zero if NAME is not suitably defined. */
879 lookup_typename (char *name
, struct block
*block
, int noerr
)
881 register struct symbol
*sym
;
882 register struct type
*tmp
;
884 sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
885 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
887 tmp
= lookup_primitive_typename (name
);
892 else if (!tmp
&& noerr
)
898 error ("No type named %s.", name
);
901 return (SYMBOL_TYPE (sym
));
905 lookup_unsigned_typename (char *name
)
907 char *uns
= alloca (strlen (name
) + 10);
909 strcpy (uns
, "unsigned ");
910 strcpy (uns
+ 9, name
);
911 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
915 lookup_signed_typename (char *name
)
918 char *uns
= alloca (strlen (name
) + 8);
920 strcpy (uns
, "signed ");
921 strcpy (uns
+ 7, name
);
922 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
923 /* If we don't find "signed FOO" just try again with plain "FOO". */
926 return lookup_typename (name
, (struct block
*) NULL
, 0);
929 /* Lookup a structure type named "struct NAME",
930 visible in lexical block BLOCK. */
933 lookup_struct (char *name
, struct block
*block
)
935 register struct symbol
*sym
;
937 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
938 (struct symtab
**) NULL
);
942 error ("No struct type named %s.", name
);
944 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
946 error ("This context has class, union or enum %s, not a struct.", name
);
948 return (SYMBOL_TYPE (sym
));
951 /* Lookup a union type named "union NAME",
952 visible in lexical block BLOCK. */
955 lookup_union (char *name
, struct block
*block
)
957 register struct symbol
*sym
;
960 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
961 (struct symtab
**) NULL
);
964 error ("No union type named %s.", name
);
966 t
= SYMBOL_TYPE (sym
);
968 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
971 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
972 * a further "declared_type" field to discover it is really a union.
974 if (HAVE_CPLUS_STRUCT (t
))
975 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
978 /* If we get here, it's not a union */
979 error ("This context has class, struct or enum %s, not a union.", name
);
983 /* Lookup an enum type named "enum NAME",
984 visible in lexical block BLOCK. */
987 lookup_enum (char *name
, struct block
*block
)
989 register struct symbol
*sym
;
991 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
992 (struct symtab
**) NULL
);
995 error ("No enum type named %s.", name
);
997 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
999 error ("This context has class, struct or union %s, not an enum.", name
);
1001 return (SYMBOL_TYPE (sym
));
1004 /* Lookup a template type named "template NAME<TYPE>",
1005 visible in lexical block BLOCK. */
1008 lookup_template_type (char *name
, struct type
*type
, struct block
*block
)
1011 char *nam
= (char *) alloca (strlen (name
) + strlen (type
->name
) + 4);
1014 strcat (nam
, type
->name
);
1015 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
1017 sym
= lookup_symbol (nam
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
1021 error ("No template type named %s.", name
);
1023 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
1025 error ("This context has class, union or enum %s, not a struct.", name
);
1027 return (SYMBOL_TYPE (sym
));
1030 /* Given a type TYPE, lookup the type of the component of type named NAME.
1032 TYPE can be either a struct or union, or a pointer or reference to a struct or
1033 union. If it is a pointer or reference, its target type is automatically used.
1034 Thus '.' and '->' are interchangable, as specified for the definitions of the
1035 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1037 If NOERR is nonzero, return zero if NAME is not suitably defined.
1038 If NAME is the name of a baseclass type, return that type. */
1041 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
1047 CHECK_TYPEDEF (type
);
1048 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1049 && TYPE_CODE (type
) != TYPE_CODE_REF
)
1051 type
= TYPE_TARGET_TYPE (type
);
1054 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
1055 TYPE_CODE (type
) != TYPE_CODE_UNION
)
1057 target_terminal_ours ();
1058 gdb_flush (gdb_stdout
);
1059 fprintf_unfiltered (gdb_stderr
, "Type ");
1060 type_print (type
, "", gdb_stderr
, -1);
1061 error (" is not a structure or union type.");
1065 /* FIXME: This change put in by Michael seems incorrect for the case where
1066 the structure tag name is the same as the member name. I.E. when doing
1067 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1072 typename
= type_name_no_tag (type
);
1073 if (typename
!= NULL
&& STREQ (typename
, name
))
1078 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
1080 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
1082 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
1084 return TYPE_FIELD_TYPE (type
, i
);
1088 /* OK, it's not in this class. Recursively check the baseclasses. */
1089 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
1093 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
1105 target_terminal_ours ();
1106 gdb_flush (gdb_stdout
);
1107 fprintf_unfiltered (gdb_stderr
, "Type ");
1108 type_print (type
, "", gdb_stderr
, -1);
1109 fprintf_unfiltered (gdb_stderr
, " has no component named ");
1110 fputs_filtered (name
, gdb_stderr
);
1112 return (struct type
*) -1; /* For lint */
1115 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1116 valid. Callers should be aware that in some cases (for example,
1117 the type or one of its baseclasses is a stub type and we are
1118 debugging a .o file), this function will not be able to find the virtual
1119 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1120 will remain NULL. */
1123 fill_in_vptr_fieldno (struct type
*type
)
1125 CHECK_TYPEDEF (type
);
1127 if (TYPE_VPTR_FIELDNO (type
) < 0)
1131 /* We must start at zero in case the first (and only) baseclass is
1132 virtual (and hence we cannot share the table pointer). */
1133 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1135 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
1136 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
1138 TYPE_VPTR_FIELDNO (type
)
1139 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
1140 TYPE_VPTR_BASETYPE (type
)
1141 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
1148 /* Find the method and field indices for the destructor in class type T.
1149 Return 1 if the destructor was found, otherwise, return 0. */
1152 get_destructor_fn_field (struct type
*t
, int *method_indexp
, int *field_indexp
)
1156 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1159 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1161 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1163 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1174 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1176 If this is a stubbed struct (i.e. declared as struct foo *), see if
1177 we can find a full definition in some other file. If so, copy this
1178 definition, so we can use it in future. There used to be a comment (but
1179 not any code) that if we don't find a full definition, we'd set a flag
1180 so we don't spend time in the future checking the same type. That would
1181 be a mistake, though--we might load in more symbols which contain a
1182 full definition for the type.
1184 This used to be coded as a macro, but I don't think it is called
1185 often enough to merit such treatment. */
1187 struct complaint stub_noname_complaint
=
1188 {"stub type has NULL name", 0, 0};
1191 check_typedef (struct type
*type
)
1193 struct type
*orig_type
= type
;
1194 int is_const
, is_volatile
;
1196 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1198 if (!TYPE_TARGET_TYPE (type
))
1203 /* It is dangerous to call lookup_symbol if we are currently
1204 reading a symtab. Infinite recursion is one danger. */
1205 if (currently_reading_symtab
)
1208 name
= type_name_no_tag (type
);
1209 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1210 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1211 as appropriate? (this code was written before TYPE_NAME and
1212 TYPE_TAG_NAME were separate). */
1215 complain (&stub_noname_complaint
);
1218 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
1219 (struct symtab
**) NULL
);
1221 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1223 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1225 type
= TYPE_TARGET_TYPE (type
);
1228 is_const
= TYPE_CONST (type
);
1229 is_volatile
= TYPE_VOLATILE (type
);
1231 /* If this is a struct/class/union with no fields, then check whether a
1232 full definition exists somewhere else. This is for systems where a
1233 type definition with no fields is issued for such types, instead of
1234 identifying them as stub types in the first place */
1236 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1238 char *name
= type_name_no_tag (type
);
1239 struct type
*newtype
;
1242 complain (&stub_noname_complaint
);
1245 newtype
= lookup_transparent_type (name
);
1247 make_cv_type (is_const
, is_volatile
, newtype
, &type
);
1249 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1250 else if ((TYPE_FLAGS (type
) & TYPE_FLAG_STUB
) && !currently_reading_symtab
)
1252 char *name
= type_name_no_tag (type
);
1253 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1254 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1255 as appropriate? (this code was written before TYPE_NAME and
1256 TYPE_TAG_NAME were separate). */
1260 complain (&stub_noname_complaint
);
1263 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0, (struct symtab
**) NULL
);
1265 make_cv_type (is_const
, is_volatile
, SYMBOL_TYPE (sym
), &type
);
1268 if (TYPE_FLAGS (type
) & TYPE_FLAG_TARGET_STUB
)
1270 struct type
*range_type
;
1271 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1273 if (TYPE_FLAGS (target_type
) & (TYPE_FLAG_STUB
| TYPE_FLAG_TARGET_STUB
))
1276 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1277 && TYPE_NFIELDS (type
) == 1
1278 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1279 == TYPE_CODE_RANGE
))
1281 /* Now recompute the length of the array type, based on its
1282 number of elements and the target type's length. */
1283 TYPE_LENGTH (type
) =
1284 ((TYPE_FIELD_BITPOS (range_type
, 1)
1285 - TYPE_FIELD_BITPOS (range_type
, 0)
1287 * TYPE_LENGTH (target_type
));
1288 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1290 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1292 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1293 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1296 /* Cache TYPE_LENGTH for future use. */
1297 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1301 /* New code added to support parsing of Cfront stabs strings */
1302 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1303 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1306 add_name (struct extra
*pextras
, char *n
)
1310 if ((nlen
= (n
? strlen (n
) : 0)) == 0)
1312 sprintf (pextras
->str
+ pextras
->len
, "%d%s", nlen
, n
);
1313 pextras
->len
= strlen (pextras
->str
);
1317 add_mangled_type (struct extra
*pextras
, struct type
*t
)
1319 enum type_code tcode
;
1323 tcode
= TYPE_CODE (t
);
1324 tlen
= TYPE_LENGTH (t
);
1325 tflags
= TYPE_FLAGS (t
);
1326 tname
= TYPE_NAME (t
);
1327 /* args of "..." seem to get mangled as "e" */
1345 if ((pname
= strrchr (tname
, 'l'), pname
) && !strcmp (pname
, "long"))
1358 static struct complaint msg
=
1359 {"Bad int type code length x%x\n", 0, 0};
1361 complain (&msg
, tlen
);
1380 static struct complaint msg
=
1381 {"Bad float type code length x%x\n", 0, 0};
1382 complain (&msg
, tlen
);
1388 /* followed by what it's a ref to */
1392 /* followed by what it's a ptr to */
1394 case TYPE_CODE_TYPEDEF
:
1396 static struct complaint msg
=
1397 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1400 /* followed by type bytes & name */
1402 case TYPE_CODE_FUNC
:
1404 /* followed by func's arg '_' & ret types */
1406 case TYPE_CODE_VOID
:
1409 case TYPE_CODE_METHOD
:
1411 /* followed by name of class and func's arg '_' & ret types */
1412 add_name (pextras
, tname
);
1413 ADD_EXTRA ('F'); /* then mangle function */
1415 case TYPE_CODE_STRUCT
: /* C struct */
1416 case TYPE_CODE_UNION
: /* C union */
1417 case TYPE_CODE_ENUM
: /* Enumeration type */
1418 /* followed by name of type */
1419 add_name (pextras
, tname
);
1422 /* errors possible types/not supported */
1423 case TYPE_CODE_CHAR
:
1424 case TYPE_CODE_ARRAY
: /* Array type */
1425 case TYPE_CODE_MEMBER
: /* Member type */
1426 case TYPE_CODE_BOOL
:
1427 case TYPE_CODE_COMPLEX
: /* Complex float */
1428 case TYPE_CODE_UNDEF
:
1429 case TYPE_CODE_SET
: /* Pascal sets */
1430 case TYPE_CODE_RANGE
:
1431 case TYPE_CODE_STRING
:
1432 case TYPE_CODE_BITSTRING
:
1433 case TYPE_CODE_ERROR
:
1436 static struct complaint msg
=
1437 {"Unknown type code x%x\n", 0, 0};
1438 complain (&msg
, tcode
);
1442 add_mangled_type (pextras
, t
->target_type
);
1447 cfront_mangle_name (struct type
*type
, int i
, int j
)
1450 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1452 f
= TYPE_FN_FIELDLIST1 (type
, i
); /* moved from below */
1454 /* kludge to support cfront methods - gdb expects to find "F" for
1455 ARM_mangled names, so when we mangle, we have to add it here */
1459 char *arm_mangled_name
;
1460 struct fn_field
*method
= &f
[j
];
1461 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1462 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1463 char *newname
= type_name_no_tag (type
);
1465 struct type
*ftype
= TYPE_FN_FIELD_TYPE (f
, j
);
1466 int nargs
= TYPE_NFIELDS (ftype
); /* number of args */
1467 struct extra extras
, *pextras
= &extras
;
1470 if (TYPE_FN_FIELD_STATIC_P (f
, j
)) /* j for sublist within this list */
1473 /* add args here! */
1474 if (nargs
<= 1) /* no args besides this */
1478 for (k
= 1; k
< nargs
; k
++)
1481 t
= TYPE_FIELD_TYPE (ftype
, k
);
1482 add_mangled_type (pextras
, t
);
1486 printf ("add_mangled_type: %s\n", extras
.str
); /* FIXME */
1487 xasprintf (&arm_mangled_name
, "%s%s", mangled_name
, extras
.str
);
1488 xfree (mangled_name
);
1489 mangled_name
= arm_mangled_name
;
1495 /* End of new code added to support parsing of Cfront stabs strings */
1497 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1498 silently return builtin_type_void. */
1501 safe_parse_type (char *p
, int length
)
1503 struct ui_file
*saved_gdb_stderr
;
1506 /* Suppress error messages. */
1507 saved_gdb_stderr
= gdb_stderr
;
1508 gdb_stderr
= ui_file_new ();
1510 /* Call parse_and_eval_type() without fear of longjmp()s. */
1511 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1512 type
= builtin_type_void
;
1514 /* Stop suppressing error messages. */
1515 ui_file_delete (gdb_stderr
);
1516 gdb_stderr
= saved_gdb_stderr
;
1521 /* Ugly hack to convert method stubs into method types.
1523 He ain't kiddin'. This demangles the name of the method into a string
1524 including argument types, parses out each argument type, generates
1525 a string casting a zero to that type, evaluates the string, and stuffs
1526 the resulting type into an argtype vector!!! Then it knows the type
1527 of the whole function (including argument types for overloading),
1528 which info used to be in the stab's but was removed to hack back
1529 the space required for them. */
1532 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1535 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1536 char *demangled_name
= cplus_demangle (mangled_name
,
1537 DMGL_PARAMS
| DMGL_ANSI
);
1538 char *argtypetext
, *p
;
1539 int depth
= 0, argcount
= 1;
1540 struct type
**argtypes
;
1543 /* Make sure we got back a function string that we can use. */
1545 p
= strchr (demangled_name
, '(');
1549 if (demangled_name
== NULL
|| p
== NULL
)
1550 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
1552 /* Now, read in the parameters that define this type. */
1557 if (*p
== '(' || *p
== '<')
1561 else if (*p
== ')' || *p
== '>')
1565 else if (*p
== ',' && depth
== 0)
1573 /* We need two more slots: one for the THIS pointer, and one for the
1574 NULL [...] or void [end of arglist]. */
1576 argtypes
= (struct type
**)
1577 TYPE_ALLOC (type
, (argcount
+ 2) * sizeof (struct type
*));
1579 /* FIXME: This is wrong for static member functions. */
1580 argtypes
[0] = lookup_pointer_type (type
);
1583 if (*p
!= ')') /* () means no args, skip while */
1588 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1590 /* Avoid parsing of ellipsis, they will be handled below. */
1591 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0)
1593 argtypes
[argcount
] =
1594 safe_parse_type (argtypetext
, p
- argtypetext
);
1597 argtypetext
= p
+ 1;
1600 if (*p
== '(' || *p
== '<')
1604 else if (*p
== ')' || *p
== '>')
1613 if (p
[-2] != '.') /* Not '...' */
1615 argtypes
[argcount
] = builtin_type_void
; /* List terminator */
1619 argtypes
[argcount
] = NULL
; /* Ellist terminator */
1622 xfree (demangled_name
);
1624 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1626 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1628 /* Now update the old "stub" type into a real type. */
1629 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1630 TYPE_DOMAIN_TYPE (mtype
) = type
;
1631 TYPE_ARG_TYPES (mtype
) = argtypes
;
1632 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1633 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1636 const struct cplus_struct_type cplus_struct_default
;
1639 allocate_cplus_struct_type (struct type
*type
)
1641 if (!HAVE_CPLUS_STRUCT (type
))
1643 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1644 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1645 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1649 /* Helper function to initialize the standard scalar types.
1651 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1652 of the string pointed to by name in the type_obstack for that objfile,
1653 and initialize the type name to that copy. There are places (mipsread.c
1654 in particular, where init_type is called with a NULL value for NAME). */
1657 init_type (enum type_code code
, int length
, int flags
, char *name
,
1658 struct objfile
*objfile
)
1660 register struct type
*type
;
1662 type
= alloc_type (objfile
);
1663 TYPE_CODE (type
) = code
;
1664 TYPE_LENGTH (type
) = length
;
1665 TYPE_FLAGS (type
) |= flags
;
1666 if ((name
!= NULL
) && (objfile
!= NULL
))
1669 obsavestring (name
, strlen (name
), &objfile
->type_obstack
);
1673 TYPE_NAME (type
) = name
;
1678 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1680 INIT_CPLUS_SPECIFIC (type
);
1685 /* Look up a fundamental type for the specified objfile.
1686 May need to construct such a type if this is the first use.
1688 Some object file formats (ELF, COFF, etc) do not define fundamental
1689 types such as "int" or "double". Others (stabs for example), do
1690 define fundamental types.
1692 For the formats which don't provide fundamental types, gdb can create
1693 such types, using defaults reasonable for the current language and
1694 the current target machine.
1696 NOTE: This routine is obsolescent. Each debugging format reader
1697 should manage it's own fundamental types, either creating them from
1698 suitable defaults or reading them from the debugging information,
1699 whichever is appropriate. The DWARF reader has already been
1700 fixed to do this. Once the other readers are fixed, this routine
1701 will go away. Also note that fundamental types should be managed
1702 on a compilation unit basis in a multi-language environment, not
1703 on a linkage unit basis as is done here. */
1707 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1709 register struct type
**typep
;
1710 register int nbytes
;
1712 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1714 error ("internal error - invalid fundamental type id %d", typeid);
1717 /* If this is the first time we need a fundamental type for this objfile
1718 then we need to initialize the vector of type pointers. */
1720 if (objfile
->fundamental_types
== NULL
)
1722 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1723 objfile
->fundamental_types
= (struct type
**)
1724 obstack_alloc (&objfile
->type_obstack
, nbytes
);
1725 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1726 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1729 /* Look for this particular type in the fundamental type vector. If one is
1730 not found, create and install one appropriate for the current language. */
1732 typep
= objfile
->fundamental_types
+ typeid;
1735 *typep
= create_fundamental_type (objfile
, typeid);
1742 can_dereference (struct type
*t
)
1744 /* FIXME: Should we return true for references as well as pointers? */
1748 && TYPE_CODE (t
) == TYPE_CODE_PTR
1749 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1753 is_integral_type (struct type
*t
)
1758 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1759 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1760 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1761 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1762 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1765 /* Chill varying string and arrays are represented as follows:
1767 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1769 Return true if TYPE is such a Chill varying type. */
1772 chill_varying_type (struct type
*type
)
1774 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1775 || TYPE_NFIELDS (type
) != 2
1776 || strcmp (TYPE_FIELD_NAME (type
, 0), "__var_length") != 0)
1781 /* Check whether BASE is an ancestor or base class or DCLASS
1782 Return 1 if so, and 0 if not.
1783 Note: callers may want to check for identity of the types before
1784 calling this function -- identical types are considered to satisfy
1785 the ancestor relationship even if they're identical */
1788 is_ancestor (struct type
*base
, struct type
*dclass
)
1792 CHECK_TYPEDEF (base
);
1793 CHECK_TYPEDEF (dclass
);
1797 if (TYPE_NAME (base
) && TYPE_NAME (dclass
) &&
1798 !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1801 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1802 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1810 /* See whether DCLASS has a virtual table. This routine is aimed at
1811 the HP/Taligent ANSI C++ runtime model, and may not work with other
1812 runtime models. Return 1 => Yes, 0 => No. */
1815 has_vtable (struct type
*dclass
)
1817 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1818 has virtual functions or virtual bases. */
1822 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1825 /* First check for the presence of virtual bases */
1826 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1827 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1828 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
1831 /* Next check for virtual functions */
1832 if (TYPE_FN_FIELDLISTS (dclass
))
1833 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
1834 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
1837 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1838 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1839 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1840 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
1841 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
1844 /* Well, maybe we don't need a virtual table */
1848 /* Return a pointer to the "primary base class" of DCLASS.
1850 A NULL return indicates that DCLASS has no primary base, or that it
1851 couldn't be found (insufficient information).
1853 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1854 and may not work with other runtime models. */
1857 primary_base_class (struct type
*dclass
)
1859 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1860 is the first directly inherited, non-virtual base class that
1861 requires a virtual table */
1865 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1868 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1869 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
1870 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
1871 return TYPE_FIELD_TYPE (dclass
, i
);
1876 /* Global manipulated by virtual_base_list[_aux]() */
1878 static struct vbase
*current_vbase_list
= NULL
;
1880 /* Return a pointer to a null-terminated list of struct vbase
1881 items. The vbasetype pointer of each item in the list points to the
1882 type information for a virtual base of the argument DCLASS.
1884 Helper function for virtual_base_list().
1885 Note: the list goes backward, right-to-left. virtual_base_list()
1886 copies the items out in reverse order. */
1889 virtual_base_list_aux (struct type
*dclass
)
1891 struct vbase
*tmp_vbase
;
1894 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1897 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1899 /* Recurse on this ancestor, first */
1900 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
1902 /* If this current base is itself virtual, add it to the list */
1903 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
1905 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
1907 /* Check if base already recorded */
1908 tmp_vbase
= current_vbase_list
;
1911 if (tmp_vbase
->vbasetype
== basetype
)
1912 break; /* found it */
1913 tmp_vbase
= tmp_vbase
->next
;
1916 if (!tmp_vbase
) /* normal exit from loop */
1918 /* Allocate new item for this virtual base */
1919 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
1921 /* Stick it on at the end of the list */
1922 tmp_vbase
->vbasetype
= basetype
;
1923 tmp_vbase
->next
= current_vbase_list
;
1924 current_vbase_list
= tmp_vbase
;
1927 } /* for loop over bases */
1931 /* Compute the list of virtual bases in the right order. Virtual
1932 bases are laid out in the object's memory area in order of their
1933 occurrence in a depth-first, left-to-right search through the
1936 Argument DCLASS is the type whose virtual bases are required.
1937 Return value is the address of a null-terminated array of pointers
1938 to struct type items.
1940 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1941 and may not work with other runtime models.
1943 This routine merely hands off the argument to virtual_base_list_aux()
1944 and then copies the result into an array to save space. */
1947 virtual_base_list (struct type
*dclass
)
1949 register struct vbase
*tmp_vbase
;
1950 register struct vbase
*tmp_vbase_2
;
1953 struct type
**vbase_array
;
1955 current_vbase_list
= NULL
;
1956 virtual_base_list_aux (dclass
);
1958 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1963 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
1965 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
1966 vbase_array
[i
] = tmp_vbase
->vbasetype
;
1968 /* Get rid of constructed chain */
1969 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
1972 tmp_vbase
= tmp_vbase
->next
;
1973 xfree (tmp_vbase_2
);
1974 tmp_vbase_2
= tmp_vbase
;
1977 vbase_array
[count
] = NULL
;
1981 /* Return the length of the virtual base list of the type DCLASS. */
1984 virtual_base_list_length (struct type
*dclass
)
1987 register struct vbase
*tmp_vbase
;
1989 current_vbase_list
= NULL
;
1990 virtual_base_list_aux (dclass
);
1992 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1997 /* Return the number of elements of the virtual base list of the type
1998 DCLASS, ignoring those appearing in the primary base (and its
1999 primary base, recursively). */
2002 virtual_base_list_length_skip_primaries (struct type
*dclass
)
2005 register struct vbase
*tmp_vbase
;
2006 struct type
*primary
;
2008 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2011 return virtual_base_list_length (dclass
);
2013 current_vbase_list
= NULL
;
2014 virtual_base_list_aux (dclass
);
2016 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
2018 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
2026 /* Return the index (position) of type BASE, which is a virtual base
2027 class of DCLASS, in the latter's virtual base list. A return of -1
2028 indicates "not found" or a problem. */
2031 virtual_base_index (struct type
*base
, struct type
*dclass
)
2033 register struct type
*vbase
;
2036 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2037 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2041 vbase
= virtual_base_list (dclass
)[0];
2046 vbase
= virtual_base_list (dclass
)[++i
];
2049 return vbase
? i
: -1;
2054 /* Return the index (position) of type BASE, which is a virtual base
2055 class of DCLASS, in the latter's virtual base list. Skip over all
2056 bases that may appear in the virtual base list of the primary base
2057 class of DCLASS (recursively). A return of -1 indicates "not
2058 found" or a problem. */
2061 virtual_base_index_skip_primaries (struct type
*base
, struct type
*dclass
)
2063 register struct type
*vbase
;
2065 struct type
*primary
;
2067 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
2068 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
2071 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
2075 vbase
= virtual_base_list (dclass
)[0];
2078 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
2082 vbase
= virtual_base_list (dclass
)[++i
];
2085 return vbase
? j
: -1;
2088 /* Return position of a derived class DCLASS in the list of
2089 * primary bases starting with the remotest ancestor.
2090 * Position returned is 0-based. */
2093 class_index_in_primary_list (struct type
*dclass
)
2095 struct type
*pbc
; /* primary base class */
2097 /* Simply recurse on primary base */
2098 pbc
= TYPE_PRIMARY_BASE (dclass
);
2100 return 1 + class_index_in_primary_list (pbc
);
2105 /* Return a count of the number of virtual functions a type has.
2106 * This includes all the virtual functions it inherits from its
2110 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2111 * functions only once (latest redefinition)
2115 count_virtual_fns (struct type
*dclass
)
2117 int fn
, oi
; /* function and overloaded instance indices */
2118 int vfuncs
; /* count to return */
2120 /* recurse on bases that can share virtual table */
2121 struct type
*pbc
= primary_base_class (dclass
);
2123 vfuncs
= count_virtual_fns (pbc
);
2127 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2128 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2129 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2137 /* Functions for overload resolution begin here */
2139 /* Compare two badness vectors A and B and return the result.
2140 * 0 => A and B are identical
2141 * 1 => A and B are incomparable
2142 * 2 => A is better than B
2143 * 3 => A is worse than B */
2146 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2150 short found_pos
= 0; /* any positives in c? */
2151 short found_neg
= 0; /* any negatives in c? */
2153 /* differing lengths => incomparable */
2154 if (a
->length
!= b
->length
)
2157 /* Subtract b from a */
2158 for (i
= 0; i
< a
->length
; i
++)
2160 tmp
= a
->rank
[i
] - b
->rank
[i
];
2170 return 1; /* incomparable */
2172 return 3; /* A > B */
2178 return 2; /* A < B */
2180 return 0; /* A == B */
2184 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2185 * to the types of an argument list (ARGS, length NARGS).
2186 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2188 struct badness_vector
*
2189 rank_function (struct type
**parms
, int nparms
, struct type
**args
, int nargs
)
2192 struct badness_vector
*bv
;
2193 int min_len
= nparms
< nargs
? nparms
: nargs
;
2195 bv
= xmalloc (sizeof (struct badness_vector
));
2196 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2197 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2199 /* First compare the lengths of the supplied lists.
2200 * If there is a mismatch, set it to a high value. */
2202 /* pai/1997-06-03 FIXME: when we have debug info about default
2203 * arguments and ellipsis parameter lists, we should consider those
2204 * and rank the length-match more finely. */
2206 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2208 /* Now rank all the parameters of the candidate function */
2209 for (i
= 1; i
<= min_len
; i
++)
2210 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2212 /* If more arguments than parameters, add dummy entries */
2213 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2214 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2219 /* Compare one type (PARM) for compatibility with another (ARG).
2220 * PARM is intended to be the parameter type of a function; and
2221 * ARG is the supplied argument's type. This function tests if
2222 * the latter can be converted to the former.
2224 * Return 0 if they are identical types;
2225 * Otherwise, return an integer which corresponds to how compatible
2226 * PARM is to ARG. The higher the return value, the worse the match.
2227 * Generally the "bad" conversions are all uniformly assigned a 100 */
2230 rank_one_type (struct type
*parm
, struct type
*arg
)
2232 /* Identical type pointers */
2233 /* However, this still doesn't catch all cases of same type for arg
2234 * and param. The reason is that builtin types are different from
2235 * the same ones constructed from the object. */
2239 /* Resolve typedefs */
2240 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2241 parm
= check_typedef (parm
);
2242 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2243 arg
= check_typedef (arg
);
2246 Well, damnit, if the names are exactly the same,
2247 i'll say they are exactly the same. This happens when we generate
2248 method stubs. The types won't point to the same address, but they
2249 really are the same.
2252 if (TYPE_NAME (parm
) && TYPE_NAME (arg
) &&
2253 !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2256 /* Check if identical after resolving typedefs */
2260 /* See through references, since we can almost make non-references
2262 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2263 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2264 + REFERENCE_CONVERSION_BADNESS
);
2265 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2266 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2267 + REFERENCE_CONVERSION_BADNESS
);
2269 /* Debugging only. */
2270 fprintf_filtered (gdb_stderr
,"------ Arg is %s [%d], parm is %s [%d]\n",
2271 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2273 /* x -> y means arg of type x being supplied for parameter of type y */
2275 switch (TYPE_CODE (parm
))
2278 switch (TYPE_CODE (arg
))
2281 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2282 return VOID_PTR_CONVERSION_BADNESS
;
2284 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2285 case TYPE_CODE_ARRAY
:
2286 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2287 case TYPE_CODE_FUNC
:
2288 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2290 case TYPE_CODE_ENUM
:
2291 case TYPE_CODE_CHAR
:
2292 case TYPE_CODE_RANGE
:
2293 case TYPE_CODE_BOOL
:
2294 return POINTER_CONVERSION_BADNESS
;
2296 return INCOMPATIBLE_TYPE_BADNESS
;
2298 case TYPE_CODE_ARRAY
:
2299 switch (TYPE_CODE (arg
))
2302 case TYPE_CODE_ARRAY
:
2303 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2305 return INCOMPATIBLE_TYPE_BADNESS
;
2307 case TYPE_CODE_FUNC
:
2308 switch (TYPE_CODE (arg
))
2310 case TYPE_CODE_PTR
: /* funcptr -> func */
2311 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2313 return INCOMPATIBLE_TYPE_BADNESS
;
2316 switch (TYPE_CODE (arg
))
2319 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2321 /* Deal with signed, unsigned, and plain chars and
2322 signed and unsigned ints */
2323 if (TYPE_NOSIGN (parm
))
2325 /* This case only for character types */
2326 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2329 return INTEGER_COERCION_BADNESS
; /* signed/unsigned char -> plain char */
2331 else if (TYPE_UNSIGNED (parm
))
2333 if (TYPE_UNSIGNED (arg
))
2335 if (!strcmp_iw (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2336 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2337 else if (!strcmp_iw (TYPE_NAME (arg
), "int") && !strcmp_iw (TYPE_NAME (parm
), "long"))
2338 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2340 return INTEGER_COERCION_BADNESS
; /* unsigned long -> unsigned int */
2344 if (!strcmp_iw (TYPE_NAME (arg
), "long") && !strcmp_iw (TYPE_NAME (parm
), "int"))
2345 return INTEGER_COERCION_BADNESS
; /* signed long -> unsigned int */
2347 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2350 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2352 if (!strcmp_iw (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2354 else if (!strcmp_iw (TYPE_NAME (arg
), "int") && !strcmp_iw (TYPE_NAME (parm
), "long"))
2355 return INTEGER_PROMOTION_BADNESS
;
2357 return INTEGER_COERCION_BADNESS
;
2360 return INTEGER_COERCION_BADNESS
;
2362 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2363 return INTEGER_PROMOTION_BADNESS
;
2365 return INTEGER_COERCION_BADNESS
;
2366 case TYPE_CODE_ENUM
:
2367 case TYPE_CODE_CHAR
:
2368 case TYPE_CODE_RANGE
:
2369 case TYPE_CODE_BOOL
:
2370 return INTEGER_PROMOTION_BADNESS
;
2372 return INT_FLOAT_CONVERSION_BADNESS
;
2374 return NS_POINTER_CONVERSION_BADNESS
;
2376 return INCOMPATIBLE_TYPE_BADNESS
;
2379 case TYPE_CODE_ENUM
:
2380 switch (TYPE_CODE (arg
))
2383 case TYPE_CODE_CHAR
:
2384 case TYPE_CODE_RANGE
:
2385 case TYPE_CODE_BOOL
:
2386 case TYPE_CODE_ENUM
:
2387 return INTEGER_COERCION_BADNESS
;
2389 return INT_FLOAT_CONVERSION_BADNESS
;
2391 return INCOMPATIBLE_TYPE_BADNESS
;
2394 case TYPE_CODE_CHAR
:
2395 switch (TYPE_CODE (arg
))
2397 case TYPE_CODE_RANGE
:
2398 case TYPE_CODE_BOOL
:
2399 case TYPE_CODE_ENUM
:
2400 return INTEGER_COERCION_BADNESS
;
2402 return INT_FLOAT_CONVERSION_BADNESS
;
2404 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2405 return INTEGER_COERCION_BADNESS
;
2406 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2407 return INTEGER_PROMOTION_BADNESS
;
2408 /* >>> !! else fall through !! <<< */
2409 case TYPE_CODE_CHAR
:
2410 /* Deal with signed, unsigned, and plain chars for C++
2411 and with int cases falling through from previous case */
2412 if (TYPE_NOSIGN (parm
))
2414 if (TYPE_NOSIGN (arg
))
2417 return INTEGER_COERCION_BADNESS
;
2419 else if (TYPE_UNSIGNED (parm
))
2421 if (TYPE_UNSIGNED (arg
))
2424 return INTEGER_PROMOTION_BADNESS
;
2426 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2429 return INTEGER_COERCION_BADNESS
;
2431 return INCOMPATIBLE_TYPE_BADNESS
;
2434 case TYPE_CODE_RANGE
:
2435 switch (TYPE_CODE (arg
))
2438 case TYPE_CODE_CHAR
:
2439 case TYPE_CODE_RANGE
:
2440 case TYPE_CODE_BOOL
:
2441 case TYPE_CODE_ENUM
:
2442 return INTEGER_COERCION_BADNESS
;
2444 return INT_FLOAT_CONVERSION_BADNESS
;
2446 return INCOMPATIBLE_TYPE_BADNESS
;
2449 case TYPE_CODE_BOOL
:
2450 switch (TYPE_CODE (arg
))
2453 case TYPE_CODE_CHAR
:
2454 case TYPE_CODE_RANGE
:
2455 case TYPE_CODE_ENUM
:
2458 return BOOLEAN_CONVERSION_BADNESS
;
2459 case TYPE_CODE_BOOL
:
2462 return INCOMPATIBLE_TYPE_BADNESS
;
2466 switch (TYPE_CODE (arg
))
2469 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2470 return FLOAT_PROMOTION_BADNESS
;
2471 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2474 return FLOAT_CONVERSION_BADNESS
;
2476 case TYPE_CODE_BOOL
:
2477 case TYPE_CODE_ENUM
:
2478 case TYPE_CODE_RANGE
:
2479 case TYPE_CODE_CHAR
:
2480 return INT_FLOAT_CONVERSION_BADNESS
;
2482 return INCOMPATIBLE_TYPE_BADNESS
;
2485 case TYPE_CODE_COMPLEX
:
2486 switch (TYPE_CODE (arg
))
2487 { /* Strictly not needed for C++, but... */
2489 return FLOAT_PROMOTION_BADNESS
;
2490 case TYPE_CODE_COMPLEX
:
2493 return INCOMPATIBLE_TYPE_BADNESS
;
2496 case TYPE_CODE_STRUCT
:
2497 /* currently same as TYPE_CODE_CLASS */
2498 switch (TYPE_CODE (arg
))
2500 case TYPE_CODE_STRUCT
:
2501 /* Check for derivation */
2502 if (is_ancestor (parm
, arg
))
2503 return BASE_CONVERSION_BADNESS
;
2504 /* else fall through */
2506 return INCOMPATIBLE_TYPE_BADNESS
;
2509 case TYPE_CODE_UNION
:
2510 switch (TYPE_CODE (arg
))
2512 case TYPE_CODE_UNION
:
2514 return INCOMPATIBLE_TYPE_BADNESS
;
2517 case TYPE_CODE_MEMBER
:
2518 switch (TYPE_CODE (arg
))
2521 return INCOMPATIBLE_TYPE_BADNESS
;
2524 case TYPE_CODE_METHOD
:
2525 switch (TYPE_CODE (arg
))
2529 return INCOMPATIBLE_TYPE_BADNESS
;
2533 switch (TYPE_CODE (arg
))
2537 return INCOMPATIBLE_TYPE_BADNESS
;
2542 switch (TYPE_CODE (arg
))
2546 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2548 return INCOMPATIBLE_TYPE_BADNESS
;
2551 case TYPE_CODE_VOID
:
2553 return INCOMPATIBLE_TYPE_BADNESS
;
2554 } /* switch (TYPE_CODE (arg)) */
2558 /* End of functions for overload resolution */
2561 print_bit_vector (B_TYPE
*bits
, int nbits
)
2565 for (bitno
= 0; bitno
< nbits
; bitno
++)
2567 if ((bitno
% 8) == 0)
2569 puts_filtered (" ");
2571 if (B_TST (bits
, bitno
))
2573 printf_filtered ("1");
2577 printf_filtered ("0");
2582 /* The args list is a strange beast. It is either terminated by a NULL
2583 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2584 type for normal fixed argcount functions. (FIXME someday)
2585 Also note the first arg should be the "this" pointer, we may not want to
2586 include it since we may get into a infinitely recursive situation. */
2589 print_arg_types (struct type
**args
, int spaces
)
2593 while (*args
!= NULL
)
2595 recursive_dump_type (*args
, spaces
+ 2);
2596 if ((*args
++)->code
== TYPE_CODE_VOID
)
2605 dump_fn_fieldlists (struct type
*type
, int spaces
)
2611 printfi_filtered (spaces
, "fn_fieldlists ");
2612 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2613 printf_filtered ("\n");
2614 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2616 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2617 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2619 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2620 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2622 printf_filtered (") length %d\n",
2623 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2624 for (overload_idx
= 0;
2625 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2628 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2630 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2631 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2633 printf_filtered (")\n");
2634 printfi_filtered (spaces
+ 8, "type ");
2635 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2636 printf_filtered ("\n");
2638 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2641 printfi_filtered (spaces
+ 8, "args ");
2642 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2643 printf_filtered ("\n");
2645 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
), spaces
);
2646 printfi_filtered (spaces
+ 8, "fcontext ");
2647 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2649 printf_filtered ("\n");
2651 printfi_filtered (spaces
+ 8, "is_const %d\n",
2652 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2653 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2654 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2655 printfi_filtered (spaces
+ 8, "is_private %d\n",
2656 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2657 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2658 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2659 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2660 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2661 printfi_filtered (spaces
+ 8, "voffset %u\n",
2662 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2668 print_cplus_stuff (struct type
*type
, int spaces
)
2670 printfi_filtered (spaces
, "n_baseclasses %d\n",
2671 TYPE_N_BASECLASSES (type
));
2672 printfi_filtered (spaces
, "nfn_fields %d\n",
2673 TYPE_NFN_FIELDS (type
));
2674 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2675 TYPE_NFN_FIELDS_TOTAL (type
));
2676 if (TYPE_N_BASECLASSES (type
) > 0)
2678 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2679 TYPE_N_BASECLASSES (type
));
2680 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2681 printf_filtered (")");
2683 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2684 TYPE_N_BASECLASSES (type
));
2685 puts_filtered ("\n");
2687 if (TYPE_NFIELDS (type
) > 0)
2689 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2691 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2692 TYPE_NFIELDS (type
));
2693 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2694 printf_filtered (")");
2695 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2696 TYPE_NFIELDS (type
));
2697 puts_filtered ("\n");
2699 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2701 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2702 TYPE_NFIELDS (type
));
2703 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2704 printf_filtered (")");
2705 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2706 TYPE_NFIELDS (type
));
2707 puts_filtered ("\n");
2710 if (TYPE_NFN_FIELDS (type
) > 0)
2712 dump_fn_fieldlists (type
, spaces
);
2716 static struct obstack dont_print_type_obstack
;
2719 recursive_dump_type (struct type
*type
, int spaces
)
2724 obstack_begin (&dont_print_type_obstack
, 0);
2726 if (TYPE_NFIELDS (type
) > 0
2727 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2729 struct type
**first_dont_print
2730 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2732 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
2737 if (type
== first_dont_print
[i
])
2739 printfi_filtered (spaces
, "type node ");
2740 gdb_print_host_address (type
, gdb_stdout
);
2741 printf_filtered (" <same as already seen type>\n");
2746 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2749 printfi_filtered (spaces
, "type node ");
2750 gdb_print_host_address (type
, gdb_stdout
);
2751 printf_filtered ("\n");
2752 printfi_filtered (spaces
, "name '%s' (",
2753 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2754 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2755 printf_filtered (")\n");
2756 if (TYPE_TAG_NAME (type
) != NULL
)
2758 printfi_filtered (spaces
, "tagname '%s' (",
2759 TYPE_TAG_NAME (type
));
2760 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2761 printf_filtered (")\n");
2763 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2764 switch (TYPE_CODE (type
))
2766 case TYPE_CODE_UNDEF
:
2767 printf_filtered ("(TYPE_CODE_UNDEF)");
2770 printf_filtered ("(TYPE_CODE_PTR)");
2772 case TYPE_CODE_ARRAY
:
2773 printf_filtered ("(TYPE_CODE_ARRAY)");
2775 case TYPE_CODE_STRUCT
:
2776 printf_filtered ("(TYPE_CODE_STRUCT)");
2778 case TYPE_CODE_UNION
:
2779 printf_filtered ("(TYPE_CODE_UNION)");
2781 case TYPE_CODE_ENUM
:
2782 printf_filtered ("(TYPE_CODE_ENUM)");
2784 case TYPE_CODE_FUNC
:
2785 printf_filtered ("(TYPE_CODE_FUNC)");
2788 printf_filtered ("(TYPE_CODE_INT)");
2791 printf_filtered ("(TYPE_CODE_FLT)");
2793 case TYPE_CODE_VOID
:
2794 printf_filtered ("(TYPE_CODE_VOID)");
2797 printf_filtered ("(TYPE_CODE_SET)");
2799 case TYPE_CODE_RANGE
:
2800 printf_filtered ("(TYPE_CODE_RANGE)");
2802 case TYPE_CODE_STRING
:
2803 printf_filtered ("(TYPE_CODE_STRING)");
2805 case TYPE_CODE_ERROR
:
2806 printf_filtered ("(TYPE_CODE_ERROR)");
2808 case TYPE_CODE_MEMBER
:
2809 printf_filtered ("(TYPE_CODE_MEMBER)");
2811 case TYPE_CODE_METHOD
:
2812 printf_filtered ("(TYPE_CODE_METHOD)");
2815 printf_filtered ("(TYPE_CODE_REF)");
2817 case TYPE_CODE_CHAR
:
2818 printf_filtered ("(TYPE_CODE_CHAR)");
2820 case TYPE_CODE_BOOL
:
2821 printf_filtered ("(TYPE_CODE_BOOL)");
2823 case TYPE_CODE_TYPEDEF
:
2824 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2827 printf_filtered ("(UNKNOWN TYPE CODE)");
2830 puts_filtered ("\n");
2831 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2832 printfi_filtered (spaces
, "objfile ");
2833 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
2834 printf_filtered ("\n");
2835 printfi_filtered (spaces
, "target_type ");
2836 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2837 printf_filtered ("\n");
2838 if (TYPE_TARGET_TYPE (type
) != NULL
)
2840 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2842 printfi_filtered (spaces
, "pointer_type ");
2843 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2844 printf_filtered ("\n");
2845 printfi_filtered (spaces
, "reference_type ");
2846 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2847 printf_filtered ("\n");
2848 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
2849 if (TYPE_FLAGS (type
) & TYPE_FLAG_UNSIGNED
)
2851 puts_filtered (" TYPE_FLAG_UNSIGNED");
2853 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
2855 puts_filtered (" TYPE_FLAG_STUB");
2857 puts_filtered ("\n");
2858 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2859 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
2860 puts_filtered ("\n");
2861 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2863 printfi_filtered (spaces
+ 2,
2864 "[%d] bitpos %d bitsize %d type ",
2865 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2866 TYPE_FIELD_BITSIZE (type
, idx
));
2867 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2868 printf_filtered (" name '%s' (",
2869 TYPE_FIELD_NAME (type
, idx
) != NULL
2870 ? TYPE_FIELD_NAME (type
, idx
)
2872 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2873 printf_filtered (")\n");
2874 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2876 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2879 printfi_filtered (spaces
, "vptr_basetype ");
2880 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2881 puts_filtered ("\n");
2882 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2884 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2886 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
2887 switch (TYPE_CODE (type
))
2889 case TYPE_CODE_METHOD
:
2890 case TYPE_CODE_FUNC
:
2891 printfi_filtered (spaces
, "arg_types ");
2892 gdb_print_host_address (TYPE_ARG_TYPES (type
), gdb_stdout
);
2893 puts_filtered ("\n");
2894 print_arg_types (TYPE_ARG_TYPES (type
), spaces
);
2897 case TYPE_CODE_STRUCT
:
2898 printfi_filtered (spaces
, "cplus_stuff ");
2899 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2900 puts_filtered ("\n");
2901 print_cplus_stuff (type
, spaces
);
2905 printfi_filtered (spaces
, "floatformat ");
2906 if (TYPE_FLOATFORMAT (type
) == NULL
2907 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
2908 puts_filtered ("(null)");
2910 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
2911 puts_filtered ("\n");
2915 /* We have to pick one of the union types to be able print and test
2916 the value. Pick cplus_struct_type, even though we know it isn't
2917 any particular one. */
2918 printfi_filtered (spaces
, "type_specific ");
2919 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2920 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
2922 printf_filtered (" (unknown data form)");
2924 printf_filtered ("\n");
2929 obstack_free (&dont_print_type_obstack
, NULL
);
2932 static void build_gdbtypes (void);
2934 build_gdbtypes (void)
2937 init_type (TYPE_CODE_VOID
, 1,
2939 "void", (struct objfile
*) NULL
);
2941 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2943 "char", (struct objfile
*) NULL
);
2944 TYPE_FLAGS (builtin_type_char
) |= TYPE_FLAG_NOSIGN
;
2945 builtin_type_true_char
=
2946 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2948 "true character", (struct objfile
*) NULL
);
2949 builtin_type_signed_char
=
2950 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2952 "signed char", (struct objfile
*) NULL
);
2953 builtin_type_unsigned_char
=
2954 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2956 "unsigned char", (struct objfile
*) NULL
);
2957 builtin_type_short
=
2958 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
2960 "short", (struct objfile
*) NULL
);
2961 builtin_type_unsigned_short
=
2962 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
2964 "unsigned short", (struct objfile
*) NULL
);
2966 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
2968 "int", (struct objfile
*) NULL
);
2969 builtin_type_unsigned_int
=
2970 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
2972 "unsigned int", (struct objfile
*) NULL
);
2974 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
2976 "long", (struct objfile
*) NULL
);
2977 builtin_type_unsigned_long
=
2978 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
2980 "unsigned long", (struct objfile
*) NULL
);
2981 builtin_type_long_long
=
2982 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2984 "long long", (struct objfile
*) NULL
);
2985 builtin_type_unsigned_long_long
=
2986 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2988 "unsigned long long", (struct objfile
*) NULL
);
2989 builtin_type_float
=
2990 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
2992 "float", (struct objfile
*) NULL
);
2993 TYPE_FLOATFORMAT (builtin_type_float
) = TARGET_FLOAT_FORMAT
;
2994 builtin_type_double
=
2995 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2997 "double", (struct objfile
*) NULL
);
2998 TYPE_FLOATFORMAT (builtin_type_double
) = TARGET_DOUBLE_FORMAT
;
2999 builtin_type_long_double
=
3000 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3002 "long double", (struct objfile
*) NULL
);
3003 TYPE_FLOATFORMAT (builtin_type_long_double
) = TARGET_LONG_DOUBLE_FORMAT
;
3004 builtin_type_complex
=
3005 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
3007 "complex", (struct objfile
*) NULL
);
3008 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
3009 builtin_type_double_complex
=
3010 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3012 "double complex", (struct objfile
*) NULL
);
3013 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
3014 builtin_type_string
=
3015 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3017 "string", (struct objfile
*) NULL
);
3019 init_type (TYPE_CODE_INT
, 8 / 8,
3021 "int8_t", (struct objfile
*) NULL
);
3022 builtin_type_uint8
=
3023 init_type (TYPE_CODE_INT
, 8 / 8,
3025 "uint8_t", (struct objfile
*) NULL
);
3026 builtin_type_int16
=
3027 init_type (TYPE_CODE_INT
, 16 / 8,
3029 "int16_t", (struct objfile
*) NULL
);
3030 builtin_type_uint16
=
3031 init_type (TYPE_CODE_INT
, 16 / 8,
3033 "uint16_t", (struct objfile
*) NULL
);
3034 builtin_type_int32
=
3035 init_type (TYPE_CODE_INT
, 32 / 8,
3037 "int32_t", (struct objfile
*) NULL
);
3038 builtin_type_uint32
=
3039 init_type (TYPE_CODE_INT
, 32 / 8,
3041 "uint32_t", (struct objfile
*) NULL
);
3042 builtin_type_int64
=
3043 init_type (TYPE_CODE_INT
, 64 / 8,
3045 "int64_t", (struct objfile
*) NULL
);
3046 builtin_type_uint64
=
3047 init_type (TYPE_CODE_INT
, 64 / 8,
3049 "uint64_t", (struct objfile
*) NULL
);
3050 builtin_type_int128
=
3051 init_type (TYPE_CODE_INT
, 128 / 8,
3053 "int128_t", (struct objfile
*) NULL
);
3054 builtin_type_uint128
=
3055 init_type (TYPE_CODE_INT
, 128 / 8,
3057 "uint128_t", (struct objfile
*) NULL
);
3059 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3061 "bool", (struct objfile
*) NULL
);
3063 /* Add user knob for controlling resolution of opaque types */
3065 (add_set_cmd ("opaque-type-resolution", class_support
, var_boolean
, (char *) &opaque_type_resolution
,
3066 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3069 opaque_type_resolution
= 1;
3071 /* Build SIMD types. */
3073 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
3075 = init_simd_type ("__builtin_v4si", builtin_type_int32
, "f", 4);
3077 = init_simd_type ("__builtin_v8qi", builtin_type_int8
, "f", 8);
3079 = init_simd_type ("__builtin_v4hi", builtin_type_int16
, "f", 4);
3081 = init_simd_type ("__builtin_v2si", builtin_type_int32
, "f", 2);
3083 /* Pointer/Address types. */
3085 /* NOTE: on some targets, addresses and pointers are not necessarily
3086 the same --- for example, on the D10V, pointers are 16 bits long,
3087 but addresses are 32 bits long. See doc/gdbint.texinfo,
3088 ``Pointers Are Not Always Addresses''.
3091 - gdb's `struct type' always describes the target's
3093 - gdb's `struct value' objects should always hold values in
3095 - gdb's CORE_ADDR values are addresses in the unified virtual
3096 address space that the assembler and linker work with. Thus,
3097 since target_read_memory takes a CORE_ADDR as an argument, it
3098 can access any memory on the target, even if the processor has
3099 separate code and data address spaces.
3102 - If v is a value holding a D10V code pointer, its contents are
3103 in target form: a big-endian address left-shifted two bits.
3104 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3105 sizeof (void *) == 2 on the target.
3107 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3108 target type for a value the target will never see. It's only
3109 used to hold the values of (typeless) linker symbols, which are
3110 indeed in the unified virtual address space. */
3111 builtin_type_void_data_ptr
= make_pointer_type (builtin_type_void
, NULL
);
3112 builtin_type_void_func_ptr
3113 = lookup_pointer_type (lookup_function_type (builtin_type_void
));
3114 builtin_type_CORE_ADDR
=
3115 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
3117 "__CORE_ADDR", (struct objfile
*) NULL
);
3118 builtin_type_bfd_vma
=
3119 init_type (TYPE_CODE_INT
, TARGET_BFD_VMA_BIT
/ 8,
3121 "__bfd_vma", (struct objfile
*) NULL
);
3125 extern void _initialize_gdbtypes (void);
3127 _initialize_gdbtypes (void)
3129 struct cmd_list_element
*c
;
3132 /* FIXME - For the moment, handle types by swapping them in and out.
3133 Should be using the per-architecture data-pointer and a large
3135 register_gdbarch_swap (&builtin_type_void
, sizeof (struct type
*), NULL
);
3136 register_gdbarch_swap (&builtin_type_char
, sizeof (struct type
*), NULL
);
3137 register_gdbarch_swap (&builtin_type_short
, sizeof (struct type
*), NULL
);
3138 register_gdbarch_swap (&builtin_type_int
, sizeof (struct type
*), NULL
);
3139 register_gdbarch_swap (&builtin_type_long
, sizeof (struct type
*), NULL
);
3140 register_gdbarch_swap (&builtin_type_long_long
, sizeof (struct type
*), NULL
);
3141 register_gdbarch_swap (&builtin_type_signed_char
, sizeof (struct type
*), NULL
);
3142 register_gdbarch_swap (&builtin_type_unsigned_char
, sizeof (struct type
*), NULL
);
3143 register_gdbarch_swap (&builtin_type_unsigned_short
, sizeof (struct type
*), NULL
);
3144 register_gdbarch_swap (&builtin_type_unsigned_int
, sizeof (struct type
*), NULL
);
3145 register_gdbarch_swap (&builtin_type_unsigned_long
, sizeof (struct type
*), NULL
);
3146 register_gdbarch_swap (&builtin_type_unsigned_long_long
, sizeof (struct type
*), NULL
);
3147 register_gdbarch_swap (&builtin_type_float
, sizeof (struct type
*), NULL
);
3148 register_gdbarch_swap (&builtin_type_double
, sizeof (struct type
*), NULL
);
3149 register_gdbarch_swap (&builtin_type_long_double
, sizeof (struct type
*), NULL
);
3150 register_gdbarch_swap (&builtin_type_complex
, sizeof (struct type
*), NULL
);
3151 register_gdbarch_swap (&builtin_type_double_complex
, sizeof (struct type
*), NULL
);
3152 register_gdbarch_swap (&builtin_type_string
, sizeof (struct type
*), NULL
);
3153 register_gdbarch_swap (&builtin_type_int8
, sizeof (struct type
*), NULL
);
3154 register_gdbarch_swap (&builtin_type_uint8
, sizeof (struct type
*), NULL
);
3155 register_gdbarch_swap (&builtin_type_int16
, sizeof (struct type
*), NULL
);
3156 register_gdbarch_swap (&builtin_type_uint16
, sizeof (struct type
*), NULL
);
3157 register_gdbarch_swap (&builtin_type_int32
, sizeof (struct type
*), NULL
);
3158 register_gdbarch_swap (&builtin_type_uint32
, sizeof (struct type
*), NULL
);
3159 register_gdbarch_swap (&builtin_type_int64
, sizeof (struct type
*), NULL
);
3160 register_gdbarch_swap (&builtin_type_uint64
, sizeof (struct type
*), NULL
);
3161 register_gdbarch_swap (&builtin_type_int128
, sizeof (struct type
*), NULL
);
3162 register_gdbarch_swap (&builtin_type_uint128
, sizeof (struct type
*), NULL
);
3163 register_gdbarch_swap (&builtin_type_v4sf
, sizeof (struct type
*), NULL
);
3164 register_gdbarch_swap (&builtin_type_v4si
, sizeof (struct type
*), NULL
);
3165 register_gdbarch_swap (&builtin_type_v8qi
, sizeof (struct type
*), NULL
);
3166 register_gdbarch_swap (&builtin_type_v4hi
, sizeof (struct type
*), NULL
);
3167 register_gdbarch_swap (&builtin_type_v2si
, sizeof (struct type
*), NULL
);
3168 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr
);
3169 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr
);
3170 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR
);
3171 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma
);
3172 register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
3174 /* Note: These types do not need to be swapped - they are target
3176 builtin_type_ieee_single_big
=
3177 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_big
.totalsize
/ 8,
3178 0, "builtin_type_ieee_single_big", NULL
);
3179 TYPE_FLOATFORMAT (builtin_type_ieee_single_big
) = &floatformat_ieee_single_big
;
3180 builtin_type_ieee_single_little
=
3181 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_little
.totalsize
/ 8,
3182 0, "builtin_type_ieee_single_little", NULL
);
3183 builtin_type_ieee_double_big
=
3184 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_big
.totalsize
/ 8,
3185 0, "builtin_type_ieee_double_big", NULL
);
3186 builtin_type_ieee_double_little
=
3187 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_little
.totalsize
/ 8,
3188 0, "builtin_type_ieee_double_little", NULL
);
3189 builtin_type_ieee_double_littlebyte_bigword
=
3190 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_littlebyte_bigword
.totalsize
/ 8,
3191 0, "builtin_type_ieee_double_littlebyte_bigword", NULL
);
3192 builtin_type_i387_ext
=
3193 init_type (TYPE_CODE_FLT
, floatformat_i387_ext
.totalsize
/ 8,
3194 0, "builtin_type_i387_ext", NULL
);
3195 TYPE_FLOATFORMAT (builtin_type_i387_ext
) = &floatformat_i387_ext
;
3196 builtin_type_m68881_ext
=
3197 init_type (TYPE_CODE_FLT
, floatformat_m68881_ext
.totalsize
/ 8,
3198 0, "builtin_type_m68881_ext", NULL
);
3199 builtin_type_i960_ext
=
3200 init_type (TYPE_CODE_FLT
, floatformat_i960_ext
.totalsize
/ 8,
3201 0, "builtin_type_i960_ext", NULL
);
3202 builtin_type_m88110_ext
=
3203 init_type (TYPE_CODE_FLT
, floatformat_m88110_ext
.totalsize
/ 8,
3204 0, "builtin_type_m88110_ext", NULL
);
3205 builtin_type_m88110_harris_ext
=
3206 init_type (TYPE_CODE_FLT
, floatformat_m88110_harris_ext
.totalsize
/ 8,
3207 0, "builtin_type_m88110_harris_ext", NULL
);
3208 builtin_type_arm_ext_big
=
3209 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_big
.totalsize
/ 8,
3210 0, "builtin_type_arm_ext_big", NULL
);
3211 builtin_type_arm_ext_littlebyte_bigword
=
3212 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_littlebyte_bigword
.totalsize
/ 8,
3213 0, "builtin_type_arm_ext_littlebyte_bigword", NULL
);
3214 builtin_type_ia64_spill_big
=
3215 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_big
.totalsize
/ 8,
3216 0, "builtin_type_ia64_spill_big", NULL
);
3217 builtin_type_ia64_spill_little
=
3218 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_little
.totalsize
/ 8,
3219 0, "builtin_type_ia64_spill_little", NULL
);
3220 builtin_type_ia64_quad_big
=
3221 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_big
.totalsize
/ 8,
3222 0, "builtin_type_ia64_quad_big", NULL
);
3223 builtin_type_ia64_quad_little
=
3224 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_little
.totalsize
/ 8,
3225 0, "builtin_type_ia64_quad_little", NULL
);
3228 add_set_cmd ("overload", no_class
, var_zinteger
, (char *) &overload_debug
,
3229 "Set debugging of C++ overloading.\n\
3230 When enabled, ranking of the functions\n\
3231 is displayed.", &setdebuglist
),