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"
40 /* These variables point to the objects
41 representing the predefined C data types. */
43 struct type
*builtin_type_void
;
44 struct type
*builtin_type_char
;
45 struct type
*builtin_type_true_char
;
46 struct type
*builtin_type_short
;
47 struct type
*builtin_type_int
;
48 struct type
*builtin_type_long
;
49 struct type
*builtin_type_long_long
;
50 struct type
*builtin_type_signed_char
;
51 struct type
*builtin_type_unsigned_char
;
52 struct type
*builtin_type_unsigned_short
;
53 struct type
*builtin_type_unsigned_int
;
54 struct type
*builtin_type_unsigned_long
;
55 struct type
*builtin_type_unsigned_long_long
;
56 struct type
*builtin_type_float
;
57 struct type
*builtin_type_double
;
58 struct type
*builtin_type_long_double
;
59 struct type
*builtin_type_complex
;
60 struct type
*builtin_type_double_complex
;
61 struct type
*builtin_type_string
;
62 struct type
*builtin_type_int8
;
63 struct type
*builtin_type_uint8
;
64 struct type
*builtin_type_int16
;
65 struct type
*builtin_type_uint16
;
66 struct type
*builtin_type_int32
;
67 struct type
*builtin_type_uint32
;
68 struct type
*builtin_type_int64
;
69 struct type
*builtin_type_uint64
;
70 struct type
*builtin_type_bool
;
71 struct type
*builtin_type_v4sf
;
72 struct type
*builtin_type_v4si
;
73 struct type
*builtin_type_v8qi
;
74 struct type
*builtin_type_v4hi
;
75 struct type
*builtin_type_v2si
;
76 struct type
*builtin_type_ieee_single_big
;
77 struct type
*builtin_type_ieee_single_little
;
78 struct type
*builtin_type_ieee_double_big
;
79 struct type
*builtin_type_ieee_double_little
;
80 struct type
*builtin_type_ieee_double_littlebyte_bigword
;
81 struct type
*builtin_type_i387_ext
;
82 struct type
*builtin_type_m68881_ext
;
83 struct type
*builtin_type_i960_ext
;
84 struct type
*builtin_type_m88110_ext
;
85 struct type
*builtin_type_m88110_harris_ext
;
86 struct type
*builtin_type_arm_ext_big
;
87 struct type
*builtin_type_arm_ext_littlebyte_bigword
;
88 struct type
*builtin_type_ia64_spill_big
;
89 struct type
*builtin_type_ia64_spill_little
;
90 struct type
*builtin_type_ia64_quad_big
;
91 struct type
*builtin_type_ia64_quad_little
;
92 struct type
*builtin_type_void_data_ptr
;
93 struct type
*builtin_type_void_func_ptr
;
94 struct type
*builtin_type_CORE_ADDR
;
95 struct type
*builtin_type_bfd_vma
;
97 int opaque_type_resolution
= 1;
98 int overload_debug
= 0;
104 }; /* maximum extension is 128! FIXME */
106 static void add_name (struct extra
*, char *);
107 static void add_mangled_type (struct extra
*, struct type
*);
109 static void cfront_mangle_name (struct type
*, int, int);
111 static void print_bit_vector (B_TYPE
*, int);
112 static void print_arg_types (struct type
**, int);
113 static void dump_fn_fieldlists (struct type
*, int);
114 static void print_cplus_stuff (struct type
*, int);
115 static void virtual_base_list_aux (struct type
*dclass
);
118 /* Alloc a new type structure and fill it with some defaults. If
119 OBJFILE is non-NULL, then allocate the space for the type structure
120 in that objfile's type_obstack. */
123 alloc_type (struct objfile
*objfile
)
125 register struct type
*type
;
127 /* Alloc the structure and start off with all fields zeroed. */
131 type
= (struct type
*) xmalloc (sizeof (struct type
));
135 type
= (struct type
*) obstack_alloc (&objfile
->type_obstack
,
136 sizeof (struct type
));
137 OBJSTAT (objfile
, n_types
++);
139 memset ((char *) type
, 0, sizeof (struct type
));
141 /* Initialize the fields that might not be zero. */
143 TYPE_CODE (type
) = TYPE_CODE_UNDEF
;
144 TYPE_OBJFILE (type
) = objfile
;
145 TYPE_VPTR_FIELDNO (type
) = -1;
146 TYPE_CV_TYPE (type
) = type
; /* chain back to itself */
151 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
152 to a pointer to memory where the pointer type should be stored.
153 If *TYPEPTR is zero, update it to point to the pointer type we return.
154 We allocate new memory if needed. */
157 make_pointer_type (struct type
*type
, struct type
**typeptr
)
159 register struct type
*ntype
; /* New type */
160 struct objfile
*objfile
;
162 ntype
= TYPE_POINTER_TYPE (type
);
167 return ntype
; /* Don't care about alloc, and have new type. */
168 else if (*typeptr
== 0)
170 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
175 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
177 ntype
= alloc_type (TYPE_OBJFILE (type
));
182 /* We have storage, but need to reset it. */
185 objfile
= TYPE_OBJFILE (ntype
);
186 memset ((char *) ntype
, 0, sizeof (struct type
));
187 TYPE_OBJFILE (ntype
) = objfile
;
190 TYPE_TARGET_TYPE (ntype
) = type
;
191 TYPE_POINTER_TYPE (type
) = ntype
;
193 /* FIXME! Assume the machine has only one representation for pointers! */
195 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
196 TYPE_CODE (ntype
) = TYPE_CODE_PTR
;
198 /* Mark pointers as unsigned. The target converts between pointers
199 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
200 ADDRESS_TO_POINTER(). */
201 TYPE_FLAGS (ntype
) |= TYPE_FLAG_UNSIGNED
;
203 if (!TYPE_POINTER_TYPE (type
)) /* Remember it, if don't have one. */
204 TYPE_POINTER_TYPE (type
) = ntype
;
209 /* Given a type TYPE, return a type of pointers to that type.
210 May need to construct such a type if this is the first use. */
213 lookup_pointer_type (struct type
*type
)
215 return make_pointer_type (type
, (struct type
**) 0);
218 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
219 to a pointer to memory where the reference type should be stored.
220 If *TYPEPTR is zero, update it to point to the reference type we return.
221 We allocate new memory if needed. */
224 make_reference_type (struct type
*type
, struct type
**typeptr
)
226 register struct type
*ntype
; /* New type */
227 struct objfile
*objfile
;
229 ntype
= TYPE_REFERENCE_TYPE (type
);
234 return ntype
; /* Don't care about alloc, and have new type. */
235 else if (*typeptr
== 0)
237 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
242 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
244 ntype
= alloc_type (TYPE_OBJFILE (type
));
249 /* We have storage, but need to reset it. */
252 objfile
= TYPE_OBJFILE (ntype
);
253 memset ((char *) ntype
, 0, sizeof (struct type
));
254 TYPE_OBJFILE (ntype
) = objfile
;
257 TYPE_TARGET_TYPE (ntype
) = type
;
258 TYPE_REFERENCE_TYPE (type
) = ntype
;
260 /* FIXME! Assume the machine has only one representation for references,
261 and that it matches the (only) representation for pointers! */
263 TYPE_LENGTH (ntype
) = TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
264 TYPE_CODE (ntype
) = TYPE_CODE_REF
;
266 if (!TYPE_REFERENCE_TYPE (type
)) /* Remember it, if don't have one. */
267 TYPE_REFERENCE_TYPE (type
) = ntype
;
272 /* Same as above, but caller doesn't care about memory allocation details. */
275 lookup_reference_type (struct type
*type
)
277 return make_reference_type (type
, (struct type
**) 0);
280 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
281 to a pointer to memory where the function type should be stored.
282 If *TYPEPTR is zero, update it to point to the function type we return.
283 We allocate new memory if needed. */
286 make_function_type (struct type
*type
, struct type
**typeptr
)
288 register struct type
*ntype
; /* New type */
289 struct objfile
*objfile
;
291 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
293 ntype
= alloc_type (TYPE_OBJFILE (type
));
298 /* We have storage, but need to reset it. */
301 objfile
= TYPE_OBJFILE (ntype
);
302 memset ((char *) ntype
, 0, sizeof (struct type
));
303 TYPE_OBJFILE (ntype
) = objfile
;
306 TYPE_TARGET_TYPE (ntype
) = type
;
308 TYPE_LENGTH (ntype
) = 1;
309 TYPE_CODE (ntype
) = TYPE_CODE_FUNC
;
315 /* Given a type TYPE, return a type of functions that return that type.
316 May need to construct such a type if this is the first use. */
319 lookup_function_type (struct type
*type
)
321 return make_function_type (type
, (struct type
**) 0);
325 /* Make a "c-v" variant of a type -- a type that is identical to the
326 one supplied except that it may have const or volatile attributes
327 CNST is a flag for setting the const attribute
328 VOLTL is a flag for setting the volatile attribute
329 TYPE is the base type whose variant we are creating.
330 TYPEPTR, if nonzero, points
331 to a pointer to memory where the reference type should be stored.
332 If *TYPEPTR is zero, update it to point to the reference type we return.
333 We allocate new memory if needed. */
336 make_cv_type (int cnst
, int voltl
, struct type
*type
, struct type
**typeptr
)
338 register struct type
*ntype
; /* New type */
339 register struct type
*tmp_type
= type
; /* tmp type */
340 struct objfile
*objfile
;
342 ntype
= TYPE_CV_TYPE (type
);
344 while (ntype
!= type
)
346 if ((TYPE_CONST (ntype
) == cnst
) &&
347 (TYPE_VOLATILE (ntype
) == voltl
))
351 else if (*typeptr
== 0)
353 *typeptr
= ntype
; /* Tracking alloc, and we have new type. */
358 ntype
= TYPE_CV_TYPE (ntype
);
361 if (typeptr
== 0 || *typeptr
== 0) /* We'll need to allocate one. */
363 ntype
= alloc_type (TYPE_OBJFILE (type
));
368 /* We have storage, but need to reset it. */
371 objfile
= TYPE_OBJFILE (ntype
);
372 /* memset ((char *) ntype, 0, sizeof (struct type)); */
373 TYPE_OBJFILE (ntype
) = objfile
;
376 /* Copy original type */
377 memcpy ((char *) ntype
, (char *) type
, sizeof (struct type
));
378 /* But zero out fields that shouldn't be copied */
379 TYPE_POINTER_TYPE (ntype
) = (struct type
*) 0; /* Need new pointer kind */
380 TYPE_REFERENCE_TYPE (ntype
) = (struct type
*) 0; /* Need new referene kind */
381 /* Note: TYPE_TARGET_TYPE can be left as is */
383 /* Set flags appropriately */
385 TYPE_FLAGS (ntype
) |= TYPE_FLAG_CONST
;
387 TYPE_FLAGS (ntype
) &= ~TYPE_FLAG_CONST
;
390 TYPE_FLAGS (ntype
) |= TYPE_FLAG_VOLATILE
;
392 TYPE_FLAGS (ntype
) &= ~TYPE_FLAG_VOLATILE
;
394 /* Fix the chain of cv variants */
395 TYPE_CV_TYPE (ntype
) = type
;
396 TYPE_CV_TYPE (tmp_type
) = ntype
;
404 /* Implement direct support for MEMBER_TYPE in GNU C++.
405 May need to construct such a type if this is the first use.
406 The TYPE is the type of the member. The DOMAIN is the type
407 of the aggregate that the member belongs to. */
410 lookup_member_type (struct type
*type
, struct type
*domain
)
412 register struct type
*mtype
;
414 mtype
= alloc_type (TYPE_OBJFILE (type
));
415 smash_to_member_type (mtype
, domain
, type
);
419 /* Allocate a stub method whose return type is TYPE.
420 This apparently happens for speed of symbol reading, since parsing
421 out the arguments to the method is cpu-intensive, the way we are doing
422 it. So, we will fill in arguments later.
423 This always returns a fresh type. */
426 allocate_stub_method (struct type
*type
)
430 mtype
= alloc_type (TYPE_OBJFILE (type
));
431 TYPE_TARGET_TYPE (mtype
) = type
;
432 /* _DOMAIN_TYPE (mtype) = unknown yet */
433 /* _ARG_TYPES (mtype) = unknown yet */
434 TYPE_FLAGS (mtype
) = TYPE_FLAG_STUB
;
435 TYPE_CODE (mtype
) = TYPE_CODE_METHOD
;
436 TYPE_LENGTH (mtype
) = 1;
440 /* Create a range type using either a blank type supplied in RESULT_TYPE,
441 or creating a new type, inheriting the objfile from INDEX_TYPE.
443 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
444 HIGH_BOUND, inclusive.
446 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
447 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
450 create_range_type (struct type
*result_type
, struct type
*index_type
,
451 int low_bound
, int high_bound
)
453 if (result_type
== NULL
)
455 result_type
= alloc_type (TYPE_OBJFILE (index_type
));
457 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
458 TYPE_TARGET_TYPE (result_type
) = index_type
;
459 if (TYPE_FLAGS (index_type
) & TYPE_FLAG_STUB
)
460 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
462 TYPE_LENGTH (result_type
) = TYPE_LENGTH (check_typedef (index_type
));
463 TYPE_NFIELDS (result_type
) = 2;
464 TYPE_FIELDS (result_type
) = (struct field
*)
465 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
466 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
467 TYPE_FIELD_BITPOS (result_type
, 0) = low_bound
;
468 TYPE_FIELD_BITPOS (result_type
, 1) = high_bound
;
469 TYPE_FIELD_TYPE (result_type
, 0) = builtin_type_int
; /* FIXME */
470 TYPE_FIELD_TYPE (result_type
, 1) = builtin_type_int
; /* FIXME */
473 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
475 return (result_type
);
478 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
479 Return 1 of type is a range type, 0 if it is discrete (and bounds
480 will fit in LONGEST), or -1 otherwise. */
483 get_discrete_bounds (struct type
*type
, LONGEST
*lowp
, LONGEST
*highp
)
485 CHECK_TYPEDEF (type
);
486 switch (TYPE_CODE (type
))
488 case TYPE_CODE_RANGE
:
489 *lowp
= TYPE_LOW_BOUND (type
);
490 *highp
= TYPE_HIGH_BOUND (type
);
493 if (TYPE_NFIELDS (type
) > 0)
495 /* The enums may not be sorted by value, so search all
499 *lowp
= *highp
= TYPE_FIELD_BITPOS (type
, 0);
500 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
502 if (TYPE_FIELD_BITPOS (type
, i
) < *lowp
)
503 *lowp
= TYPE_FIELD_BITPOS (type
, i
);
504 if (TYPE_FIELD_BITPOS (type
, i
) > *highp
)
505 *highp
= TYPE_FIELD_BITPOS (type
, i
);
508 /* Set unsigned indicator if warranted. */
511 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
525 if (TYPE_LENGTH (type
) > sizeof (LONGEST
)) /* Too big */
527 if (!TYPE_UNSIGNED (type
))
529 *lowp
= -(1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1));
533 /* ... fall through for unsigned ints ... */
536 /* This round-about calculation is to avoid shifting by
537 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
538 if TYPE_LENGTH (type) == sizeof (LONGEST). */
539 *highp
= 1 << (TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1);
540 *highp
= (*highp
- 1) | *highp
;
547 /* Create an array type using either a blank type supplied in RESULT_TYPE,
548 or creating a new type, inheriting the objfile from RANGE_TYPE.
550 Elements will be of type ELEMENT_TYPE, the indices will be of type
553 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
554 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
557 create_array_type (struct type
*result_type
, struct type
*element_type
,
558 struct type
*range_type
)
560 LONGEST low_bound
, high_bound
;
562 if (result_type
== NULL
)
564 result_type
= alloc_type (TYPE_OBJFILE (range_type
));
566 TYPE_CODE (result_type
) = TYPE_CODE_ARRAY
;
567 TYPE_TARGET_TYPE (result_type
) = element_type
;
568 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
569 low_bound
= high_bound
= 0;
570 CHECK_TYPEDEF (element_type
);
571 TYPE_LENGTH (result_type
) =
572 TYPE_LENGTH (element_type
) * (high_bound
- low_bound
+ 1);
573 TYPE_NFIELDS (result_type
) = 1;
574 TYPE_FIELDS (result_type
) =
575 (struct field
*) TYPE_ALLOC (result_type
, sizeof (struct field
));
576 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
577 TYPE_FIELD_TYPE (result_type
, 0) = range_type
;
578 TYPE_VPTR_FIELDNO (result_type
) = -1;
580 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
581 if (TYPE_LENGTH (result_type
) == 0)
582 TYPE_FLAGS (result_type
) |= TYPE_FLAG_TARGET_STUB
;
584 return (result_type
);
587 /* Create a string type using either a blank type supplied in RESULT_TYPE,
588 or creating a new type. String types are similar enough to array of
589 char types that we can use create_array_type to build the basic type
590 and then bash it into a string type.
592 For fixed length strings, the range type contains 0 as the lower
593 bound and the length of the string minus one as the upper bound.
595 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
596 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
599 create_string_type (struct type
*result_type
, struct type
*range_type
)
601 result_type
= create_array_type (result_type
,
602 *current_language
->string_char_type
,
604 TYPE_CODE (result_type
) = TYPE_CODE_STRING
;
605 return (result_type
);
609 create_set_type (struct type
*result_type
, struct type
*domain_type
)
611 LONGEST low_bound
, high_bound
, bit_length
;
612 if (result_type
== NULL
)
614 result_type
= alloc_type (TYPE_OBJFILE (domain_type
));
616 TYPE_CODE (result_type
) = TYPE_CODE_SET
;
617 TYPE_NFIELDS (result_type
) = 1;
618 TYPE_FIELDS (result_type
) = (struct field
*)
619 TYPE_ALLOC (result_type
, 1 * sizeof (struct field
));
620 memset (TYPE_FIELDS (result_type
), 0, sizeof (struct field
));
622 if (!(TYPE_FLAGS (domain_type
) & TYPE_FLAG_STUB
))
624 if (get_discrete_bounds (domain_type
, &low_bound
, &high_bound
) < 0)
625 low_bound
= high_bound
= 0;
626 bit_length
= high_bound
- low_bound
+ 1;
627 TYPE_LENGTH (result_type
)
628 = (bit_length
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
630 TYPE_FIELD_TYPE (result_type
, 0) = domain_type
;
633 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
635 return (result_type
);
639 /* Construct and return a type of the form:
640 struct NAME { ELT_TYPE ELT_NAME[N]; }
641 We use these types for SIMD registers. For example, the type of
642 the SSE registers on the late x86-family processors is:
643 struct __builtin_v4sf { float f[4]; }
644 built by the function call:
645 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
646 The type returned is a permanent type, allocated using malloc; it
647 doesn't live in any objfile's obstack. */
649 init_simd_type (char *name
,
650 struct type
*elt_type
,
657 /* Build the field structure. */
658 f
= xmalloc (sizeof (*f
));
659 memset (f
, 0, sizeof (*f
));
661 f
->type
= create_array_type (0, elt_type
,
662 create_range_type (0, builtin_type_int
,
666 /* Build a struct type with that field. */
667 t
= init_type (TYPE_CODE_STRUCT
, n
* TYPE_LENGTH (elt_type
), 0, 0, 0);
676 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
677 A MEMBER is a wierd thing -- it amounts to a typed offset into
678 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
679 include the offset (that's the value of the MEMBER itself), but does
680 include the structure type into which it points (for some reason).
682 When "smashing" the type, we preserve the objfile that the
683 old type pointed to, since we aren't changing where the type is actually
687 smash_to_member_type (struct type
*type
, struct type
*domain
,
688 struct type
*to_type
)
690 struct objfile
*objfile
;
692 objfile
= TYPE_OBJFILE (type
);
694 memset ((char *) type
, 0, sizeof (struct type
));
695 TYPE_OBJFILE (type
) = objfile
;
696 TYPE_TARGET_TYPE (type
) = to_type
;
697 TYPE_DOMAIN_TYPE (type
) = domain
;
698 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
699 TYPE_CODE (type
) = TYPE_CODE_MEMBER
;
702 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
703 METHOD just means `function that gets an extra "this" argument'.
705 When "smashing" the type, we preserve the objfile that the
706 old type pointed to, since we aren't changing where the type is actually
710 smash_to_method_type (struct type
*type
, struct type
*domain
,
711 struct type
*to_type
, struct type
**args
)
713 struct objfile
*objfile
;
715 objfile
= TYPE_OBJFILE (type
);
717 memset ((char *) type
, 0, sizeof (struct type
));
718 TYPE_OBJFILE (type
) = objfile
;
719 TYPE_TARGET_TYPE (type
) = to_type
;
720 TYPE_DOMAIN_TYPE (type
) = domain
;
721 TYPE_ARG_TYPES (type
) = args
;
722 TYPE_LENGTH (type
) = 1; /* In practice, this is never needed. */
723 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
726 /* Return a typename for a struct/union/enum type without "struct ",
727 "union ", or "enum ". If the type has a NULL name, return NULL. */
730 type_name_no_tag (register const struct type
*type
)
732 if (TYPE_TAG_NAME (type
) != NULL
)
733 return TYPE_TAG_NAME (type
);
735 /* Is there code which expects this to return the name if there is no
736 tag name? My guess is that this is mainly used for C++ in cases where
737 the two will always be the same. */
738 return TYPE_NAME (type
);
741 /* Lookup a primitive type named NAME.
742 Return zero if NAME is not a primitive type. */
745 lookup_primitive_typename (char *name
)
747 struct type
**const *p
;
749 for (p
= current_language
->la_builtin_type_vector
; *p
!= NULL
; p
++)
751 if (STREQ ((**p
)->name
, name
))
759 /* Lookup a typedef or primitive type named NAME,
760 visible in lexical block BLOCK.
761 If NOERR is nonzero, return zero if NAME is not suitably defined. */
764 lookup_typename (char *name
, struct block
*block
, int noerr
)
766 register struct symbol
*sym
;
767 register struct type
*tmp
;
769 sym
= lookup_symbol (name
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
770 if (sym
== NULL
|| SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
772 tmp
= lookup_primitive_typename (name
);
777 else if (!tmp
&& noerr
)
783 error ("No type named %s.", name
);
786 return (SYMBOL_TYPE (sym
));
790 lookup_unsigned_typename (char *name
)
792 char *uns
= alloca (strlen (name
) + 10);
794 strcpy (uns
, "unsigned ");
795 strcpy (uns
+ 9, name
);
796 return (lookup_typename (uns
, (struct block
*) NULL
, 0));
800 lookup_signed_typename (char *name
)
803 char *uns
= alloca (strlen (name
) + 8);
805 strcpy (uns
, "signed ");
806 strcpy (uns
+ 7, name
);
807 t
= lookup_typename (uns
, (struct block
*) NULL
, 1);
808 /* If we don't find "signed FOO" just try again with plain "FOO". */
811 return lookup_typename (name
, (struct block
*) NULL
, 0);
814 /* Lookup a structure type named "struct NAME",
815 visible in lexical block BLOCK. */
818 lookup_struct (char *name
, struct block
*block
)
820 register struct symbol
*sym
;
822 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
823 (struct symtab
**) NULL
);
827 error ("No struct type named %s.", name
);
829 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
831 error ("This context has class, union or enum %s, not a struct.", name
);
833 return (SYMBOL_TYPE (sym
));
836 /* Lookup a union type named "union NAME",
837 visible in lexical block BLOCK. */
840 lookup_union (char *name
, struct block
*block
)
842 register struct symbol
*sym
;
845 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
846 (struct symtab
**) NULL
);
849 error ("No union type named %s.", name
);
851 t
= SYMBOL_TYPE (sym
);
853 if (TYPE_CODE (t
) == TYPE_CODE_UNION
)
856 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
857 * a further "declared_type" field to discover it is really a union.
859 if (HAVE_CPLUS_STRUCT (t
))
860 if (TYPE_DECLARED_TYPE (t
) == DECLARED_TYPE_UNION
)
863 /* If we get here, it's not a union */
864 error ("This context has class, struct or enum %s, not a union.", name
);
868 /* Lookup an enum type named "enum NAME",
869 visible in lexical block BLOCK. */
872 lookup_enum (char *name
, struct block
*block
)
874 register struct symbol
*sym
;
876 sym
= lookup_symbol (name
, block
, STRUCT_NAMESPACE
, 0,
877 (struct symtab
**) NULL
);
880 error ("No enum type named %s.", name
);
882 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_ENUM
)
884 error ("This context has class, struct or union %s, not an enum.", name
);
886 return (SYMBOL_TYPE (sym
));
889 /* Lookup a template type named "template NAME<TYPE>",
890 visible in lexical block BLOCK. */
893 lookup_template_type (char *name
, struct type
*type
, struct block
*block
)
896 char *nam
= (char *) alloca (strlen (name
) + strlen (type
->name
) + 4);
899 strcat (nam
, type
->name
);
900 strcat (nam
, " >"); /* FIXME, extra space still introduced in gcc? */
902 sym
= lookup_symbol (nam
, block
, VAR_NAMESPACE
, 0, (struct symtab
**) NULL
);
906 error ("No template type named %s.", name
);
908 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_STRUCT
)
910 error ("This context has class, union or enum %s, not a struct.", name
);
912 return (SYMBOL_TYPE (sym
));
915 /* Given a type TYPE, lookup the type of the component of type named NAME.
917 TYPE can be either a struct or union, or a pointer or reference to a struct or
918 union. If it is a pointer or reference, its target type is automatically used.
919 Thus '.' and '->' are interchangable, as specified for the definitions of the
920 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
922 If NOERR is nonzero, return zero if NAME is not suitably defined.
923 If NAME is the name of a baseclass type, return that type. */
926 lookup_struct_elt_type (struct type
*type
, char *name
, int noerr
)
932 CHECK_TYPEDEF (type
);
933 if (TYPE_CODE (type
) != TYPE_CODE_PTR
934 && TYPE_CODE (type
) != TYPE_CODE_REF
)
936 type
= TYPE_TARGET_TYPE (type
);
939 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
940 TYPE_CODE (type
) != TYPE_CODE_UNION
)
942 target_terminal_ours ();
943 gdb_flush (gdb_stdout
);
944 fprintf_unfiltered (gdb_stderr
, "Type ");
945 type_print (type
, "", gdb_stderr
, -1);
946 error (" is not a structure or union type.");
950 /* FIXME: This change put in by Michael seems incorrect for the case where
951 the structure tag name is the same as the member name. I.E. when doing
952 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
957 typename
= type_name_no_tag (type
);
958 if (typename
!= NULL
&& STREQ (typename
, name
))
963 for (i
= TYPE_NFIELDS (type
) - 1; i
>= TYPE_N_BASECLASSES (type
); i
--)
965 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
967 if (t_field_name
&& (strcmp_iw (t_field_name
, name
) == 0))
969 return TYPE_FIELD_TYPE (type
, i
);
973 /* OK, it's not in this class. Recursively check the baseclasses. */
974 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
978 t
= lookup_struct_elt_type (TYPE_BASECLASS (type
, i
), name
, noerr
);
990 target_terminal_ours ();
991 gdb_flush (gdb_stdout
);
992 fprintf_unfiltered (gdb_stderr
, "Type ");
993 type_print (type
, "", gdb_stderr
, -1);
994 fprintf_unfiltered (gdb_stderr
, " has no component named ");
995 fputs_filtered (name
, gdb_stderr
);
997 return (struct type
*) -1; /* For lint */
1000 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1001 valid. Callers should be aware that in some cases (for example,
1002 the type or one of its baseclasses is a stub type and we are
1003 debugging a .o file), this function will not be able to find the virtual
1004 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1005 will remain NULL. */
1008 fill_in_vptr_fieldno (struct type
*type
)
1010 CHECK_TYPEDEF (type
);
1012 if (TYPE_VPTR_FIELDNO (type
) < 0)
1016 /* We must start at zero in case the first (and only) baseclass is
1017 virtual (and hence we cannot share the table pointer). */
1018 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1020 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, i
));
1021 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
)) >= 0)
1023 TYPE_VPTR_FIELDNO (type
)
1024 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, i
));
1025 TYPE_VPTR_BASETYPE (type
)
1026 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type
, i
));
1033 /* Find the method and field indices for the destructor in class type T.
1034 Return 1 if the destructor was found, otherwise, return 0. */
1037 get_destructor_fn_field (struct type
*t
, int *method_indexp
, int *field_indexp
)
1041 for (i
= 0; i
< TYPE_NFN_FIELDS (t
); i
++)
1044 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, i
);
1046 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (t
, i
); j
++)
1048 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f
, j
)) != 0)
1059 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1061 If this is a stubbed struct (i.e. declared as struct foo *), see if
1062 we can find a full definition in some other file. If so, copy this
1063 definition, so we can use it in future. There used to be a comment (but
1064 not any code) that if we don't find a full definition, we'd set a flag
1065 so we don't spend time in the future checking the same type. That would
1066 be a mistake, though--we might load in more symbols which contain a
1067 full definition for the type.
1069 This used to be coded as a macro, but I don't think it is called
1070 often enough to merit such treatment. */
1072 struct complaint stub_noname_complaint
=
1073 {"stub type has NULL name", 0, 0};
1076 check_typedef (register struct type
*type
)
1078 struct type
*orig_type
= type
;
1079 while (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
1081 if (!TYPE_TARGET_TYPE (type
))
1086 /* It is dangerous to call lookup_symbol if we are currently
1087 reading a symtab. Infinite recursion is one danger. */
1088 if (currently_reading_symtab
)
1091 name
= type_name_no_tag (type
);
1092 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1093 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1094 as appropriate? (this code was written before TYPE_NAME and
1095 TYPE_TAG_NAME were separate). */
1098 complain (&stub_noname_complaint
);
1101 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0,
1102 (struct symtab
**) NULL
);
1104 TYPE_TARGET_TYPE (type
) = SYMBOL_TYPE (sym
);
1106 TYPE_TARGET_TYPE (type
) = alloc_type (NULL
); /* TYPE_CODE_UNDEF */
1108 type
= TYPE_TARGET_TYPE (type
);
1111 /* If this is a struct/class/union with no fields, then check whether a
1112 full definition exists somewhere else. This is for systems where a
1113 type definition with no fields is issued for such types, instead of
1114 identifying them as stub types in the first place */
1116 if (TYPE_IS_OPAQUE (type
) && opaque_type_resolution
&& !currently_reading_symtab
)
1118 char *name
= type_name_no_tag (type
);
1119 struct type
*newtype
;
1122 complain (&stub_noname_complaint
);
1125 newtype
= lookup_transparent_type (name
);
1128 memcpy ((char *) type
, (char *) newtype
, sizeof (struct type
));
1131 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1132 else if ((TYPE_FLAGS (type
) & TYPE_FLAG_STUB
) && !currently_reading_symtab
)
1134 char *name
= type_name_no_tag (type
);
1135 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1136 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1137 as appropriate? (this code was written before TYPE_NAME and
1138 TYPE_TAG_NAME were separate). */
1142 complain (&stub_noname_complaint
);
1145 sym
= lookup_symbol (name
, 0, STRUCT_NAMESPACE
, 0, (struct symtab
**) NULL
);
1148 memcpy ((char *) type
, (char *) SYMBOL_TYPE (sym
), sizeof (struct type
));
1152 if (TYPE_FLAGS (type
) & TYPE_FLAG_TARGET_STUB
)
1154 struct type
*range_type
;
1155 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1157 if (TYPE_FLAGS (target_type
) & (TYPE_FLAG_STUB
| TYPE_FLAG_TARGET_STUB
))
1160 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1161 && TYPE_NFIELDS (type
) == 1
1162 && (TYPE_CODE (range_type
= TYPE_FIELD_TYPE (type
, 0))
1163 == TYPE_CODE_RANGE
))
1165 /* Now recompute the length of the array type, based on its
1166 number of elements and the target type's length. */
1167 TYPE_LENGTH (type
) =
1168 ((TYPE_FIELD_BITPOS (range_type
, 1)
1169 - TYPE_FIELD_BITPOS (range_type
, 0)
1171 * TYPE_LENGTH (target_type
));
1172 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1174 else if (TYPE_CODE (type
) == TYPE_CODE_RANGE
)
1176 TYPE_LENGTH (type
) = TYPE_LENGTH (target_type
);
1177 TYPE_FLAGS (type
) &= ~TYPE_FLAG_TARGET_STUB
;
1180 /* Cache TYPE_LENGTH for future use. */
1181 TYPE_LENGTH (orig_type
) = TYPE_LENGTH (type
);
1185 /* New code added to support parsing of Cfront stabs strings */
1186 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1187 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1190 add_name (struct extra
*pextras
, char *n
)
1194 if ((nlen
= (n
? strlen (n
) : 0)) == 0)
1196 sprintf (pextras
->str
+ pextras
->len
, "%d%s", nlen
, n
);
1197 pextras
->len
= strlen (pextras
->str
);
1201 add_mangled_type (struct extra
*pextras
, struct type
*t
)
1203 enum type_code tcode
;
1207 tcode
= TYPE_CODE (t
);
1208 tlen
= TYPE_LENGTH (t
);
1209 tflags
= TYPE_FLAGS (t
);
1210 tname
= TYPE_NAME (t
);
1211 /* args of "..." seem to get mangled as "e" */
1229 if ((pname
= strrchr (tname
, 'l'), pname
) && !strcmp (pname
, "long"))
1242 static struct complaint msg
=
1243 {"Bad int type code length x%x\n", 0, 0};
1245 complain (&msg
, tlen
);
1264 static struct complaint msg
=
1265 {"Bad float type code length x%x\n", 0, 0};
1266 complain (&msg
, tlen
);
1272 /* followed by what it's a ref to */
1276 /* followed by what it's a ptr to */
1278 case TYPE_CODE_TYPEDEF
:
1280 static struct complaint msg
=
1281 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1284 /* followed by type bytes & name */
1286 case TYPE_CODE_FUNC
:
1288 /* followed by func's arg '_' & ret types */
1290 case TYPE_CODE_VOID
:
1293 case TYPE_CODE_METHOD
:
1295 /* followed by name of class and func's arg '_' & ret types */
1296 add_name (pextras
, tname
);
1297 ADD_EXTRA ('F'); /* then mangle function */
1299 case TYPE_CODE_STRUCT
: /* C struct */
1300 case TYPE_CODE_UNION
: /* C union */
1301 case TYPE_CODE_ENUM
: /* Enumeration type */
1302 /* followed by name of type */
1303 add_name (pextras
, tname
);
1306 /* errors possible types/not supported */
1307 case TYPE_CODE_CHAR
:
1308 case TYPE_CODE_ARRAY
: /* Array type */
1309 case TYPE_CODE_MEMBER
: /* Member type */
1310 case TYPE_CODE_BOOL
:
1311 case TYPE_CODE_COMPLEX
: /* Complex float */
1312 case TYPE_CODE_UNDEF
:
1313 case TYPE_CODE_SET
: /* Pascal sets */
1314 case TYPE_CODE_RANGE
:
1315 case TYPE_CODE_STRING
:
1316 case TYPE_CODE_BITSTRING
:
1317 case TYPE_CODE_ERROR
:
1320 static struct complaint msg
=
1321 {"Unknown type code x%x\n", 0, 0};
1322 complain (&msg
, tcode
);
1326 add_mangled_type (pextras
, t
->target_type
);
1331 cfront_mangle_name (struct type
*type
, int i
, int j
)
1334 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1336 f
= TYPE_FN_FIELDLIST1 (type
, i
); /* moved from below */
1338 /* kludge to support cfront methods - gdb expects to find "F" for
1339 ARM_mangled names, so when we mangle, we have to add it here */
1343 char *arm_mangled_name
;
1344 struct fn_field
*method
= &f
[j
];
1345 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1346 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
1347 char *newname
= type_name_no_tag (type
);
1349 struct type
*ftype
= TYPE_FN_FIELD_TYPE (f
, j
);
1350 int nargs
= TYPE_NFIELDS (ftype
); /* number of args */
1351 struct extra extras
, *pextras
= &extras
;
1354 if (TYPE_FN_FIELD_STATIC_P (f
, j
)) /* j for sublist within this list */
1357 /* add args here! */
1358 if (nargs
<= 1) /* no args besides this */
1362 for (k
= 1; k
< nargs
; k
++)
1365 t
= TYPE_FIELD_TYPE (ftype
, k
);
1366 add_mangled_type (pextras
, t
);
1370 printf ("add_mangled_type: %s\n", extras
.str
); /* FIXME */
1371 xasprintf (&arm_mangled_name
, "%s%s", mangled_name
, extras
.str
);
1372 xfree (mangled_name
);
1373 mangled_name
= arm_mangled_name
;
1379 /* End of new code added to support parsing of Cfront stabs strings */
1381 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1382 silently return builtin_type_void. */
1385 safe_parse_type (char *p
, int length
)
1387 struct ui_file
*saved_gdb_stderr
;
1390 /* Suppress error messages. */
1391 saved_gdb_stderr
= gdb_stderr
;
1392 gdb_stderr
= ui_file_new ();
1394 /* Call parse_and_eval_type() without fear of longjmp()s. */
1395 if (!gdb_parse_and_eval_type (p
, length
, &type
))
1396 type
= builtin_type_void
;
1398 /* Stop suppressing error messages. */
1399 ui_file_delete (gdb_stderr
);
1400 gdb_stderr
= saved_gdb_stderr
;
1405 /* Ugly hack to convert method stubs into method types.
1407 He ain't kiddin'. This demangles the name of the method into a string
1408 including argument types, parses out each argument type, generates
1409 a string casting a zero to that type, evaluates the string, and stuffs
1410 the resulting type into an argtype vector!!! Then it knows the type
1411 of the whole function (including argument types for overloading),
1412 which info used to be in the stab's but was removed to hack back
1413 the space required for them. */
1416 check_stub_method (struct type
*type
, int method_id
, int signature_id
)
1419 char *mangled_name
= gdb_mangle_name (type
, method_id
, signature_id
);
1420 char *demangled_name
= cplus_demangle (mangled_name
,
1421 DMGL_PARAMS
| DMGL_ANSI
);
1422 char *argtypetext
, *p
;
1423 int depth
= 0, argcount
= 1;
1424 struct type
**argtypes
;
1427 /* Make sure we got back a function string that we can use. */
1429 p
= strchr (demangled_name
, '(');
1433 if (demangled_name
== NULL
|| p
== NULL
)
1434 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name
);
1436 /* Now, read in the parameters that define this type. */
1441 if (*p
== '(' || *p
== '<')
1445 else if (*p
== ')' || *p
== '>')
1449 else if (*p
== ',' && depth
== 0)
1457 /* We need two more slots: one for the THIS pointer, and one for the
1458 NULL [...] or void [end of arglist]. */
1460 argtypes
= (struct type
**)
1461 TYPE_ALLOC (type
, (argcount
+ 2) * sizeof (struct type
*));
1463 /* FIXME: This is wrong for static member functions. */
1464 argtypes
[0] = lookup_pointer_type (type
);
1467 if (*p
!= ')') /* () means no args, skip while */
1472 if (depth
<= 0 && (*p
== ',' || *p
== ')'))
1474 /* Avoid parsing of ellipsis, they will be handled below. */
1475 if (strncmp (argtypetext
, "...", p
- argtypetext
) != 0)
1477 argtypes
[argcount
] =
1478 safe_parse_type (argtypetext
, p
- argtypetext
);
1481 argtypetext
= p
+ 1;
1484 if (*p
== '(' || *p
== '<')
1488 else if (*p
== ')' || *p
== '>')
1497 if (p
[-2] != '.') /* Not '...' */
1499 argtypes
[argcount
] = builtin_type_void
; /* List terminator */
1503 argtypes
[argcount
] = NULL
; /* Ellist terminator */
1506 xfree (demangled_name
);
1508 f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
1510 TYPE_FN_FIELD_PHYSNAME (f
, signature_id
) = mangled_name
;
1512 /* Now update the old "stub" type into a real type. */
1513 mtype
= TYPE_FN_FIELD_TYPE (f
, signature_id
);
1514 TYPE_DOMAIN_TYPE (mtype
) = type
;
1515 TYPE_ARG_TYPES (mtype
) = argtypes
;
1516 TYPE_FLAGS (mtype
) &= ~TYPE_FLAG_STUB
;
1517 TYPE_FN_FIELD_STUB (f
, signature_id
) = 0;
1520 const struct cplus_struct_type cplus_struct_default
;
1523 allocate_cplus_struct_type (struct type
*type
)
1525 if (!HAVE_CPLUS_STRUCT (type
))
1527 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1528 TYPE_ALLOC (type
, sizeof (struct cplus_struct_type
));
1529 *(TYPE_CPLUS_SPECIFIC (type
)) = cplus_struct_default
;
1533 /* Helper function to initialize the standard scalar types.
1535 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1536 of the string pointed to by name in the type_obstack for that objfile,
1537 and initialize the type name to that copy. There are places (mipsread.c
1538 in particular, where init_type is called with a NULL value for NAME). */
1541 init_type (enum type_code code
, int length
, int flags
, char *name
,
1542 struct objfile
*objfile
)
1544 register struct type
*type
;
1546 type
= alloc_type (objfile
);
1547 TYPE_CODE (type
) = code
;
1548 TYPE_LENGTH (type
) = length
;
1549 TYPE_FLAGS (type
) |= flags
;
1550 if ((name
!= NULL
) && (objfile
!= NULL
))
1553 obsavestring (name
, strlen (name
), &objfile
->type_obstack
);
1557 TYPE_NAME (type
) = name
;
1562 if (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
1564 INIT_CPLUS_SPECIFIC (type
);
1569 /* Look up a fundamental type for the specified objfile.
1570 May need to construct such a type if this is the first use.
1572 Some object file formats (ELF, COFF, etc) do not define fundamental
1573 types such as "int" or "double". Others (stabs for example), do
1574 define fundamental types.
1576 For the formats which don't provide fundamental types, gdb can create
1577 such types, using defaults reasonable for the current language and
1578 the current target machine.
1580 NOTE: This routine is obsolescent. Each debugging format reader
1581 should manage it's own fundamental types, either creating them from
1582 suitable defaults or reading them from the debugging information,
1583 whichever is appropriate. The DWARF reader has already been
1584 fixed to do this. Once the other readers are fixed, this routine
1585 will go away. Also note that fundamental types should be managed
1586 on a compilation unit basis in a multi-language environment, not
1587 on a linkage unit basis as is done here. */
1591 lookup_fundamental_type (struct objfile
*objfile
, int typeid)
1593 register struct type
**typep
;
1594 register int nbytes
;
1596 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
1598 error ("internal error - invalid fundamental type id %d", typeid);
1601 /* If this is the first time we need a fundamental type for this objfile
1602 then we need to initialize the vector of type pointers. */
1604 if (objfile
->fundamental_types
== NULL
)
1606 nbytes
= FT_NUM_MEMBERS
* sizeof (struct type
*);
1607 objfile
->fundamental_types
= (struct type
**)
1608 obstack_alloc (&objfile
->type_obstack
, nbytes
);
1609 memset ((char *) objfile
->fundamental_types
, 0, nbytes
);
1610 OBJSTAT (objfile
, n_types
+= FT_NUM_MEMBERS
);
1613 /* Look for this particular type in the fundamental type vector. If one is
1614 not found, create and install one appropriate for the current language. */
1616 typep
= objfile
->fundamental_types
+ typeid;
1619 *typep
= create_fundamental_type (objfile
, typeid);
1626 can_dereference (struct type
*t
)
1628 /* FIXME: Should we return true for references as well as pointers? */
1632 && TYPE_CODE (t
) == TYPE_CODE_PTR
1633 && TYPE_CODE (TYPE_TARGET_TYPE (t
)) != TYPE_CODE_VOID
);
1637 is_integral_type (struct type
*t
)
1642 && ((TYPE_CODE (t
) == TYPE_CODE_INT
)
1643 || (TYPE_CODE (t
) == TYPE_CODE_ENUM
)
1644 || (TYPE_CODE (t
) == TYPE_CODE_CHAR
)
1645 || (TYPE_CODE (t
) == TYPE_CODE_RANGE
)
1646 || (TYPE_CODE (t
) == TYPE_CODE_BOOL
)));
1649 /* Chill varying string and arrays are represented as follows:
1651 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1653 Return true if TYPE is such a Chill varying type. */
1656 chill_varying_type (struct type
*type
)
1658 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1659 || TYPE_NFIELDS (type
) != 2
1660 || strcmp (TYPE_FIELD_NAME (type
, 0), "__var_length") != 0)
1665 /* Check whether BASE is an ancestor or base class or DCLASS
1666 Return 1 if so, and 0 if not.
1667 Note: callers may want to check for identity of the types before
1668 calling this function -- identical types are considered to satisfy
1669 the ancestor relationship even if they're identical */
1672 is_ancestor (struct type
*base
, struct type
*dclass
)
1676 CHECK_TYPEDEF (base
);
1677 CHECK_TYPEDEF (dclass
);
1681 if (TYPE_NAME (base
) && TYPE_NAME (dclass
) &&
1682 !strcmp (TYPE_NAME (base
), TYPE_NAME (dclass
)))
1685 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1686 if (is_ancestor (base
, TYPE_BASECLASS (dclass
, i
)))
1694 /* See whether DCLASS has a virtual table. This routine is aimed at
1695 the HP/Taligent ANSI C++ runtime model, and may not work with other
1696 runtime models. Return 1 => Yes, 0 => No. */
1699 has_vtable (struct type
*dclass
)
1701 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1702 has virtual functions or virtual bases. */
1706 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1709 /* First check for the presence of virtual bases */
1710 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1711 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1712 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
))
1715 /* Next check for virtual functions */
1716 if (TYPE_FN_FIELDLISTS (dclass
))
1717 for (i
= 0; i
< TYPE_NFN_FIELDS (dclass
); i
++)
1718 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, i
), 0))
1721 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1722 if (TYPE_FIELD_VIRTUAL_BITS (dclass
))
1723 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1724 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass
), i
)) &&
1725 (has_vtable (TYPE_FIELD_TYPE (dclass
, i
))))
1728 /* Well, maybe we don't need a virtual table */
1732 /* Return a pointer to the "primary base class" of DCLASS.
1734 A NULL return indicates that DCLASS has no primary base, or that it
1735 couldn't be found (insufficient information).
1737 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1738 and may not work with other runtime models. */
1741 primary_base_class (struct type
*dclass
)
1743 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1744 is the first directly inherited, non-virtual base class that
1745 requires a virtual table */
1749 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1752 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1753 if (!TYPE_FIELD_VIRTUAL (dclass
, i
) &&
1754 has_vtable (TYPE_FIELD_TYPE (dclass
, i
)))
1755 return TYPE_FIELD_TYPE (dclass
, i
);
1760 /* Global manipulated by virtual_base_list[_aux]() */
1762 static struct vbase
*current_vbase_list
= NULL
;
1764 /* Return a pointer to a null-terminated list of struct vbase
1765 items. The vbasetype pointer of each item in the list points to the
1766 type information for a virtual base of the argument DCLASS.
1768 Helper function for virtual_base_list().
1769 Note: the list goes backward, right-to-left. virtual_base_list()
1770 copies the items out in reverse order. */
1773 virtual_base_list_aux (struct type
*dclass
)
1775 struct vbase
*tmp_vbase
;
1778 if (TYPE_CODE (dclass
) != TYPE_CODE_CLASS
)
1781 for (i
= 0; i
< TYPE_N_BASECLASSES (dclass
); i
++)
1783 /* Recurse on this ancestor, first */
1784 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass
, i
));
1786 /* If this current base is itself virtual, add it to the list */
1787 if (BASETYPE_VIA_VIRTUAL (dclass
, i
))
1789 struct type
*basetype
= TYPE_FIELD_TYPE (dclass
, i
);
1791 /* Check if base already recorded */
1792 tmp_vbase
= current_vbase_list
;
1795 if (tmp_vbase
->vbasetype
== basetype
)
1796 break; /* found it */
1797 tmp_vbase
= tmp_vbase
->next
;
1800 if (!tmp_vbase
) /* normal exit from loop */
1802 /* Allocate new item for this virtual base */
1803 tmp_vbase
= (struct vbase
*) xmalloc (sizeof (struct vbase
));
1805 /* Stick it on at the end of the list */
1806 tmp_vbase
->vbasetype
= basetype
;
1807 tmp_vbase
->next
= current_vbase_list
;
1808 current_vbase_list
= tmp_vbase
;
1811 } /* for loop over bases */
1815 /* Compute the list of virtual bases in the right order. Virtual
1816 bases are laid out in the object's memory area in order of their
1817 occurrence in a depth-first, left-to-right search through the
1820 Argument DCLASS is the type whose virtual bases are required.
1821 Return value is the address of a null-terminated array of pointers
1822 to struct type items.
1824 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1825 and may not work with other runtime models.
1827 This routine merely hands off the argument to virtual_base_list_aux()
1828 and then copies the result into an array to save space. */
1831 virtual_base_list (struct type
*dclass
)
1833 register struct vbase
*tmp_vbase
;
1834 register struct vbase
*tmp_vbase_2
;
1837 struct type
**vbase_array
;
1839 current_vbase_list
= NULL
;
1840 virtual_base_list_aux (dclass
);
1842 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1847 vbase_array
= (struct type
**) xmalloc ((count
+ 1) * sizeof (struct type
*));
1849 for (i
= count
- 1, tmp_vbase
= current_vbase_list
; i
>= 0; i
--, tmp_vbase
= tmp_vbase
->next
)
1850 vbase_array
[i
] = tmp_vbase
->vbasetype
;
1852 /* Get rid of constructed chain */
1853 tmp_vbase_2
= tmp_vbase
= current_vbase_list
;
1856 tmp_vbase
= tmp_vbase
->next
;
1857 xfree (tmp_vbase_2
);
1858 tmp_vbase_2
= tmp_vbase
;
1861 vbase_array
[count
] = NULL
;
1865 /* Return the length of the virtual base list of the type DCLASS. */
1868 virtual_base_list_length (struct type
*dclass
)
1871 register struct vbase
*tmp_vbase
;
1873 current_vbase_list
= NULL
;
1874 virtual_base_list_aux (dclass
);
1876 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; i
++, tmp_vbase
= tmp_vbase
->next
)
1881 /* Return the number of elements of the virtual base list of the type
1882 DCLASS, ignoring those appearing in the primary base (and its
1883 primary base, recursively). */
1886 virtual_base_list_length_skip_primaries (struct type
*dclass
)
1889 register struct vbase
*tmp_vbase
;
1890 struct type
*primary
;
1892 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
1895 return virtual_base_list_length (dclass
);
1897 current_vbase_list
= NULL
;
1898 virtual_base_list_aux (dclass
);
1900 for (i
= 0, tmp_vbase
= current_vbase_list
; tmp_vbase
!= NULL
; tmp_vbase
= tmp_vbase
->next
)
1902 if (virtual_base_index (tmp_vbase
->vbasetype
, primary
) >= 0)
1910 /* Return the index (position) of type BASE, which is a virtual base
1911 class of DCLASS, in the latter's virtual base list. A return of -1
1912 indicates "not found" or a problem. */
1915 virtual_base_index (struct type
*base
, struct type
*dclass
)
1917 register struct type
*vbase
;
1920 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
1921 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
1925 vbase
= virtual_base_list (dclass
)[0];
1930 vbase
= virtual_base_list (dclass
)[++i
];
1933 return vbase
? i
: -1;
1938 /* Return the index (position) of type BASE, which is a virtual base
1939 class of DCLASS, in the latter's virtual base list. Skip over all
1940 bases that may appear in the virtual base list of the primary base
1941 class of DCLASS (recursively). A return of -1 indicates "not
1942 found" or a problem. */
1945 virtual_base_index_skip_primaries (struct type
*base
, struct type
*dclass
)
1947 register struct type
*vbase
;
1949 struct type
*primary
;
1951 if ((TYPE_CODE (dclass
) != TYPE_CODE_CLASS
) ||
1952 (TYPE_CODE (base
) != TYPE_CODE_CLASS
))
1955 primary
= TYPE_RUNTIME_PTR (dclass
) ? TYPE_PRIMARY_BASE (dclass
) : NULL
;
1959 vbase
= virtual_base_list (dclass
)[0];
1962 if (!primary
|| (virtual_base_index_skip_primaries (vbase
, primary
) < 0))
1966 vbase
= virtual_base_list (dclass
)[++i
];
1969 return vbase
? j
: -1;
1972 /* Return position of a derived class DCLASS in the list of
1973 * primary bases starting with the remotest ancestor.
1974 * Position returned is 0-based. */
1977 class_index_in_primary_list (struct type
*dclass
)
1979 struct type
*pbc
; /* primary base class */
1981 /* Simply recurse on primary base */
1982 pbc
= TYPE_PRIMARY_BASE (dclass
);
1984 return 1 + class_index_in_primary_list (pbc
);
1989 /* Return a count of the number of virtual functions a type has.
1990 * This includes all the virtual functions it inherits from its
1994 /* pai: FIXME This doesn't do the right thing: count redefined virtual
1995 * functions only once (latest redefinition)
1999 count_virtual_fns (struct type
*dclass
)
2001 int fn
, oi
; /* function and overloaded instance indices */
2002 int vfuncs
; /* count to return */
2004 /* recurse on bases that can share virtual table */
2005 struct type
*pbc
= primary_base_class (dclass
);
2007 vfuncs
= count_virtual_fns (pbc
);
2011 for (fn
= 0; fn
< TYPE_NFN_FIELDS (dclass
); fn
++)
2012 for (oi
= 0; oi
< TYPE_FN_FIELDLIST_LENGTH (dclass
, fn
); oi
++)
2013 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass
, fn
), oi
))
2021 /* Functions for overload resolution begin here */
2023 /* Compare two badness vectors A and B and return the result.
2024 * 0 => A and B are identical
2025 * 1 => A and B are incomparable
2026 * 2 => A is better than B
2027 * 3 => A is worse than B */
2030 compare_badness (struct badness_vector
*a
, struct badness_vector
*b
)
2034 short found_pos
= 0; /* any positives in c? */
2035 short found_neg
= 0; /* any negatives in c? */
2037 /* differing lengths => incomparable */
2038 if (a
->length
!= b
->length
)
2041 /* Subtract b from a */
2042 for (i
= 0; i
< a
->length
; i
++)
2044 tmp
= a
->rank
[i
] - b
->rank
[i
];
2054 return 1; /* incomparable */
2056 return 3; /* A > B */
2062 return 2; /* A < B */
2064 return 0; /* A == B */
2068 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2069 * to the types of an argument list (ARGS, length NARGS).
2070 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2072 struct badness_vector
*
2073 rank_function (struct type
**parms
, int nparms
, struct type
**args
, int nargs
)
2076 struct badness_vector
*bv
;
2077 int min_len
= nparms
< nargs
? nparms
: nargs
;
2079 bv
= xmalloc (sizeof (struct badness_vector
));
2080 bv
->length
= nargs
+ 1; /* add 1 for the length-match rank */
2081 bv
->rank
= xmalloc ((nargs
+ 1) * sizeof (int));
2083 /* First compare the lengths of the supplied lists.
2084 * If there is a mismatch, set it to a high value. */
2086 /* pai/1997-06-03 FIXME: when we have debug info about default
2087 * arguments and ellipsis parameter lists, we should consider those
2088 * and rank the length-match more finely. */
2090 LENGTH_MATCH (bv
) = (nargs
!= nparms
) ? LENGTH_MISMATCH_BADNESS
: 0;
2092 /* Now rank all the parameters of the candidate function */
2093 for (i
= 1; i
<= min_len
; i
++)
2094 bv
->rank
[i
] = rank_one_type (parms
[i
-1], args
[i
-1]);
2096 /* If more arguments than parameters, add dummy entries */
2097 for (i
= min_len
+ 1; i
<= nargs
; i
++)
2098 bv
->rank
[i
] = TOO_FEW_PARAMS_BADNESS
;
2103 /* Compare one type (PARM) for compatibility with another (ARG).
2104 * PARM is intended to be the parameter type of a function; and
2105 * ARG is the supplied argument's type. This function tests if
2106 * the latter can be converted to the former.
2108 * Return 0 if they are identical types;
2109 * Otherwise, return an integer which corresponds to how compatible
2110 * PARM is to ARG. The higher the return value, the worse the match.
2111 * Generally the "bad" conversions are all uniformly assigned a 100 */
2114 rank_one_type (struct type
*parm
, struct type
*arg
)
2116 /* Identical type pointers */
2117 /* However, this still doesn't catch all cases of same type for arg
2118 * and param. The reason is that builtin types are different from
2119 * the same ones constructed from the object. */
2123 /* Resolve typedefs */
2124 if (TYPE_CODE (parm
) == TYPE_CODE_TYPEDEF
)
2125 parm
= check_typedef (parm
);
2126 if (TYPE_CODE (arg
) == TYPE_CODE_TYPEDEF
)
2127 arg
= check_typedef (arg
);
2130 Well, damnit, if the names are exactly the same,
2131 i'll say they are exactly the same. This happens when we generate
2132 method stubs. The types won't point to the same address, but they
2133 really are the same.
2136 if (TYPE_NAME (parm
) && TYPE_NAME (arg
) &&
2137 !strcmp (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2140 /* Check if identical after resolving typedefs */
2144 /* See through references, since we can almost make non-references
2146 if (TYPE_CODE (arg
) == TYPE_CODE_REF
)
2147 return (rank_one_type (parm
, TYPE_TARGET_TYPE (arg
))
2148 + REFERENCE_CONVERSION_BADNESS
);
2149 if (TYPE_CODE (parm
) == TYPE_CODE_REF
)
2150 return (rank_one_type (TYPE_TARGET_TYPE (parm
), arg
)
2151 + REFERENCE_CONVERSION_BADNESS
);
2153 /* Debugging only. */
2154 fprintf_filtered (gdb_stderr
,"------ Arg is %s [%d], parm is %s [%d]\n",
2155 TYPE_NAME (arg
), TYPE_CODE (arg
), TYPE_NAME (parm
), TYPE_CODE (parm
));
2157 /* x -> y means arg of type x being supplied for parameter of type y */
2159 switch (TYPE_CODE (parm
))
2162 switch (TYPE_CODE (arg
))
2165 if (TYPE_CODE (TYPE_TARGET_TYPE (parm
)) == TYPE_CODE_VOID
)
2166 return VOID_PTR_CONVERSION_BADNESS
;
2168 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2169 case TYPE_CODE_ARRAY
:
2170 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2171 case TYPE_CODE_FUNC
:
2172 return rank_one_type (TYPE_TARGET_TYPE (parm
), arg
);
2174 case TYPE_CODE_ENUM
:
2175 case TYPE_CODE_CHAR
:
2176 case TYPE_CODE_RANGE
:
2177 case TYPE_CODE_BOOL
:
2178 return POINTER_CONVERSION_BADNESS
;
2180 return INCOMPATIBLE_TYPE_BADNESS
;
2182 case TYPE_CODE_ARRAY
:
2183 switch (TYPE_CODE (arg
))
2186 case TYPE_CODE_ARRAY
:
2187 return rank_one_type (TYPE_TARGET_TYPE (parm
), TYPE_TARGET_TYPE (arg
));
2189 return INCOMPATIBLE_TYPE_BADNESS
;
2191 case TYPE_CODE_FUNC
:
2192 switch (TYPE_CODE (arg
))
2194 case TYPE_CODE_PTR
: /* funcptr -> func */
2195 return rank_one_type (parm
, TYPE_TARGET_TYPE (arg
));
2197 return INCOMPATIBLE_TYPE_BADNESS
;
2200 switch (TYPE_CODE (arg
))
2203 if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2205 /* Deal with signed, unsigned, and plain chars and
2206 signed and unsigned ints */
2207 if (TYPE_NOSIGN (parm
))
2209 /* This case only for character types */
2210 if (TYPE_NOSIGN (arg
)) /* plain char -> plain char */
2213 return INTEGER_COERCION_BADNESS
; /* signed/unsigned char -> plain char */
2215 else if (TYPE_UNSIGNED (parm
))
2217 if (TYPE_UNSIGNED (arg
))
2219 if (!strcmp_iw (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2220 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2221 else if (!strcmp_iw (TYPE_NAME (arg
), "int") && !strcmp_iw (TYPE_NAME (parm
), "long"))
2222 return INTEGER_PROMOTION_BADNESS
; /* unsigned int -> unsigned long */
2224 return INTEGER_COERCION_BADNESS
; /* unsigned long -> unsigned int */
2228 if (!strcmp_iw (TYPE_NAME (arg
), "long") && !strcmp_iw (TYPE_NAME (parm
), "int"))
2229 return INTEGER_COERCION_BADNESS
; /* signed long -> unsigned int */
2231 return INTEGER_CONVERSION_BADNESS
; /* signed int/long -> unsigned int/long */
2234 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2236 if (!strcmp_iw (TYPE_NAME (parm
), TYPE_NAME (arg
)))
2238 else if (!strcmp_iw (TYPE_NAME (arg
), "int") && !strcmp_iw (TYPE_NAME (parm
), "long"))
2239 return INTEGER_PROMOTION_BADNESS
;
2241 return INTEGER_COERCION_BADNESS
;
2244 return INTEGER_COERCION_BADNESS
;
2246 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2247 return INTEGER_PROMOTION_BADNESS
;
2249 return INTEGER_COERCION_BADNESS
;
2250 case TYPE_CODE_ENUM
:
2251 case TYPE_CODE_CHAR
:
2252 case TYPE_CODE_RANGE
:
2253 case TYPE_CODE_BOOL
:
2254 return INTEGER_PROMOTION_BADNESS
;
2256 return INT_FLOAT_CONVERSION_BADNESS
;
2258 return NS_POINTER_CONVERSION_BADNESS
;
2260 return INCOMPATIBLE_TYPE_BADNESS
;
2263 case TYPE_CODE_ENUM
:
2264 switch (TYPE_CODE (arg
))
2267 case TYPE_CODE_CHAR
:
2268 case TYPE_CODE_RANGE
:
2269 case TYPE_CODE_BOOL
:
2270 case TYPE_CODE_ENUM
:
2271 return INTEGER_COERCION_BADNESS
;
2273 return INT_FLOAT_CONVERSION_BADNESS
;
2275 return INCOMPATIBLE_TYPE_BADNESS
;
2278 case TYPE_CODE_CHAR
:
2279 switch (TYPE_CODE (arg
))
2281 case TYPE_CODE_RANGE
:
2282 case TYPE_CODE_BOOL
:
2283 case TYPE_CODE_ENUM
:
2284 return INTEGER_COERCION_BADNESS
;
2286 return INT_FLOAT_CONVERSION_BADNESS
;
2288 if (TYPE_LENGTH (arg
) > TYPE_LENGTH (parm
))
2289 return INTEGER_COERCION_BADNESS
;
2290 else if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2291 return INTEGER_PROMOTION_BADNESS
;
2292 /* >>> !! else fall through !! <<< */
2293 case TYPE_CODE_CHAR
:
2294 /* Deal with signed, unsigned, and plain chars for C++
2295 and with int cases falling through from previous case */
2296 if (TYPE_NOSIGN (parm
))
2298 if (TYPE_NOSIGN (arg
))
2301 return INTEGER_COERCION_BADNESS
;
2303 else if (TYPE_UNSIGNED (parm
))
2305 if (TYPE_UNSIGNED (arg
))
2308 return INTEGER_PROMOTION_BADNESS
;
2310 else if (!TYPE_NOSIGN (arg
) && !TYPE_UNSIGNED (arg
))
2313 return INTEGER_COERCION_BADNESS
;
2315 return INCOMPATIBLE_TYPE_BADNESS
;
2318 case TYPE_CODE_RANGE
:
2319 switch (TYPE_CODE (arg
))
2322 case TYPE_CODE_CHAR
:
2323 case TYPE_CODE_RANGE
:
2324 case TYPE_CODE_BOOL
:
2325 case TYPE_CODE_ENUM
:
2326 return INTEGER_COERCION_BADNESS
;
2328 return INT_FLOAT_CONVERSION_BADNESS
;
2330 return INCOMPATIBLE_TYPE_BADNESS
;
2333 case TYPE_CODE_BOOL
:
2334 switch (TYPE_CODE (arg
))
2337 case TYPE_CODE_CHAR
:
2338 case TYPE_CODE_RANGE
:
2339 case TYPE_CODE_ENUM
:
2342 return BOOLEAN_CONVERSION_BADNESS
;
2343 case TYPE_CODE_BOOL
:
2346 return INCOMPATIBLE_TYPE_BADNESS
;
2350 switch (TYPE_CODE (arg
))
2353 if (TYPE_LENGTH (arg
) < TYPE_LENGTH (parm
))
2354 return FLOAT_PROMOTION_BADNESS
;
2355 else if (TYPE_LENGTH (arg
) == TYPE_LENGTH (parm
))
2358 return FLOAT_CONVERSION_BADNESS
;
2360 case TYPE_CODE_BOOL
:
2361 case TYPE_CODE_ENUM
:
2362 case TYPE_CODE_RANGE
:
2363 case TYPE_CODE_CHAR
:
2364 return INT_FLOAT_CONVERSION_BADNESS
;
2366 return INCOMPATIBLE_TYPE_BADNESS
;
2369 case TYPE_CODE_COMPLEX
:
2370 switch (TYPE_CODE (arg
))
2371 { /* Strictly not needed for C++, but... */
2373 return FLOAT_PROMOTION_BADNESS
;
2374 case TYPE_CODE_COMPLEX
:
2377 return INCOMPATIBLE_TYPE_BADNESS
;
2380 case TYPE_CODE_STRUCT
:
2381 /* currently same as TYPE_CODE_CLASS */
2382 switch (TYPE_CODE (arg
))
2384 case TYPE_CODE_STRUCT
:
2385 /* Check for derivation */
2386 if (is_ancestor (parm
, arg
))
2387 return BASE_CONVERSION_BADNESS
;
2388 /* else fall through */
2390 return INCOMPATIBLE_TYPE_BADNESS
;
2393 case TYPE_CODE_UNION
:
2394 switch (TYPE_CODE (arg
))
2396 case TYPE_CODE_UNION
:
2398 return INCOMPATIBLE_TYPE_BADNESS
;
2401 case TYPE_CODE_MEMBER
:
2402 switch (TYPE_CODE (arg
))
2405 return INCOMPATIBLE_TYPE_BADNESS
;
2408 case TYPE_CODE_METHOD
:
2409 switch (TYPE_CODE (arg
))
2413 return INCOMPATIBLE_TYPE_BADNESS
;
2417 switch (TYPE_CODE (arg
))
2421 return INCOMPATIBLE_TYPE_BADNESS
;
2426 switch (TYPE_CODE (arg
))
2430 return rank_one_type (TYPE_FIELD_TYPE (parm
, 0), TYPE_FIELD_TYPE (arg
, 0));
2432 return INCOMPATIBLE_TYPE_BADNESS
;
2435 case TYPE_CODE_VOID
:
2437 return INCOMPATIBLE_TYPE_BADNESS
;
2438 } /* switch (TYPE_CODE (arg)) */
2442 /* End of functions for overload resolution */
2445 print_bit_vector (B_TYPE
*bits
, int nbits
)
2449 for (bitno
= 0; bitno
< nbits
; bitno
++)
2451 if ((bitno
% 8) == 0)
2453 puts_filtered (" ");
2455 if (B_TST (bits
, bitno
))
2457 printf_filtered ("1");
2461 printf_filtered ("0");
2466 /* The args list is a strange beast. It is either terminated by a NULL
2467 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2468 type for normal fixed argcount functions. (FIXME someday)
2469 Also note the first arg should be the "this" pointer, we may not want to
2470 include it since we may get into a infinitely recursive situation. */
2473 print_arg_types (struct type
**args
, int spaces
)
2477 while (*args
!= NULL
)
2479 recursive_dump_type (*args
, spaces
+ 2);
2480 if ((*args
++)->code
== TYPE_CODE_VOID
)
2489 dump_fn_fieldlists (struct type
*type
, int spaces
)
2495 printfi_filtered (spaces
, "fn_fieldlists ");
2496 gdb_print_host_address (TYPE_FN_FIELDLISTS (type
), gdb_stdout
);
2497 printf_filtered ("\n");
2498 for (method_idx
= 0; method_idx
< TYPE_NFN_FIELDS (type
); method_idx
++)
2500 f
= TYPE_FN_FIELDLIST1 (type
, method_idx
);
2501 printfi_filtered (spaces
+ 2, "[%d] name '%s' (",
2503 TYPE_FN_FIELDLIST_NAME (type
, method_idx
));
2504 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type
, method_idx
),
2506 printf_filtered (") length %d\n",
2507 TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
));
2508 for (overload_idx
= 0;
2509 overload_idx
< TYPE_FN_FIELDLIST_LENGTH (type
, method_idx
);
2512 printfi_filtered (spaces
+ 4, "[%d] physname '%s' (",
2514 TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
));
2515 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f
, overload_idx
),
2517 printf_filtered (")\n");
2518 printfi_filtered (spaces
+ 8, "type ");
2519 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f
, overload_idx
), gdb_stdout
);
2520 printf_filtered ("\n");
2522 recursive_dump_type (TYPE_FN_FIELD_TYPE (f
, overload_idx
),
2525 printfi_filtered (spaces
+ 8, "args ");
2526 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f
, overload_idx
), gdb_stdout
);
2527 printf_filtered ("\n");
2529 print_arg_types (TYPE_FN_FIELD_ARGS (f
, overload_idx
), spaces
);
2530 printfi_filtered (spaces
+ 8, "fcontext ");
2531 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f
, overload_idx
),
2533 printf_filtered ("\n");
2535 printfi_filtered (spaces
+ 8, "is_const %d\n",
2536 TYPE_FN_FIELD_CONST (f
, overload_idx
));
2537 printfi_filtered (spaces
+ 8, "is_volatile %d\n",
2538 TYPE_FN_FIELD_VOLATILE (f
, overload_idx
));
2539 printfi_filtered (spaces
+ 8, "is_private %d\n",
2540 TYPE_FN_FIELD_PRIVATE (f
, overload_idx
));
2541 printfi_filtered (spaces
+ 8, "is_protected %d\n",
2542 TYPE_FN_FIELD_PROTECTED (f
, overload_idx
));
2543 printfi_filtered (spaces
+ 8, "is_stub %d\n",
2544 TYPE_FN_FIELD_STUB (f
, overload_idx
));
2545 printfi_filtered (spaces
+ 8, "voffset %u\n",
2546 TYPE_FN_FIELD_VOFFSET (f
, overload_idx
));
2552 print_cplus_stuff (struct type
*type
, int spaces
)
2554 printfi_filtered (spaces
, "n_baseclasses %d\n",
2555 TYPE_N_BASECLASSES (type
));
2556 printfi_filtered (spaces
, "nfn_fields %d\n",
2557 TYPE_NFN_FIELDS (type
));
2558 printfi_filtered (spaces
, "nfn_fields_total %d\n",
2559 TYPE_NFN_FIELDS_TOTAL (type
));
2560 if (TYPE_N_BASECLASSES (type
) > 0)
2562 printfi_filtered (spaces
, "virtual_field_bits (%d bits at *",
2563 TYPE_N_BASECLASSES (type
));
2564 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type
), gdb_stdout
);
2565 printf_filtered (")");
2567 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type
),
2568 TYPE_N_BASECLASSES (type
));
2569 puts_filtered ("\n");
2571 if (TYPE_NFIELDS (type
) > 0)
2573 if (TYPE_FIELD_PRIVATE_BITS (type
) != NULL
)
2575 printfi_filtered (spaces
, "private_field_bits (%d bits at *",
2576 TYPE_NFIELDS (type
));
2577 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type
), gdb_stdout
);
2578 printf_filtered (")");
2579 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type
),
2580 TYPE_NFIELDS (type
));
2581 puts_filtered ("\n");
2583 if (TYPE_FIELD_PROTECTED_BITS (type
) != NULL
)
2585 printfi_filtered (spaces
, "protected_field_bits (%d bits at *",
2586 TYPE_NFIELDS (type
));
2587 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type
), gdb_stdout
);
2588 printf_filtered (")");
2589 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type
),
2590 TYPE_NFIELDS (type
));
2591 puts_filtered ("\n");
2594 if (TYPE_NFN_FIELDS (type
) > 0)
2596 dump_fn_fieldlists (type
, spaces
);
2600 static struct obstack dont_print_type_obstack
;
2603 recursive_dump_type (struct type
*type
, int spaces
)
2608 obstack_begin (&dont_print_type_obstack
, 0);
2610 if (TYPE_NFIELDS (type
) > 0
2611 || (TYPE_CPLUS_SPECIFIC (type
) && TYPE_NFN_FIELDS (type
) > 0))
2613 struct type
**first_dont_print
2614 = (struct type
**) obstack_base (&dont_print_type_obstack
);
2616 int i
= (struct type
**) obstack_next_free (&dont_print_type_obstack
)
2621 if (type
== first_dont_print
[i
])
2623 printfi_filtered (spaces
, "type node ");
2624 gdb_print_host_address (type
, gdb_stdout
);
2625 printf_filtered (" <same as already seen type>\n");
2630 obstack_ptr_grow (&dont_print_type_obstack
, type
);
2633 printfi_filtered (spaces
, "type node ");
2634 gdb_print_host_address (type
, gdb_stdout
);
2635 printf_filtered ("\n");
2636 printfi_filtered (spaces
, "name '%s' (",
2637 TYPE_NAME (type
) ? TYPE_NAME (type
) : "<NULL>");
2638 gdb_print_host_address (TYPE_NAME (type
), gdb_stdout
);
2639 printf_filtered (")\n");
2640 if (TYPE_TAG_NAME (type
) != NULL
)
2642 printfi_filtered (spaces
, "tagname '%s' (",
2643 TYPE_TAG_NAME (type
));
2644 gdb_print_host_address (TYPE_TAG_NAME (type
), gdb_stdout
);
2645 printf_filtered (")\n");
2647 printfi_filtered (spaces
, "code 0x%x ", TYPE_CODE (type
));
2648 switch (TYPE_CODE (type
))
2650 case TYPE_CODE_UNDEF
:
2651 printf_filtered ("(TYPE_CODE_UNDEF)");
2654 printf_filtered ("(TYPE_CODE_PTR)");
2656 case TYPE_CODE_ARRAY
:
2657 printf_filtered ("(TYPE_CODE_ARRAY)");
2659 case TYPE_CODE_STRUCT
:
2660 printf_filtered ("(TYPE_CODE_STRUCT)");
2662 case TYPE_CODE_UNION
:
2663 printf_filtered ("(TYPE_CODE_UNION)");
2665 case TYPE_CODE_ENUM
:
2666 printf_filtered ("(TYPE_CODE_ENUM)");
2668 case TYPE_CODE_FUNC
:
2669 printf_filtered ("(TYPE_CODE_FUNC)");
2672 printf_filtered ("(TYPE_CODE_INT)");
2675 printf_filtered ("(TYPE_CODE_FLT)");
2677 case TYPE_CODE_VOID
:
2678 printf_filtered ("(TYPE_CODE_VOID)");
2681 printf_filtered ("(TYPE_CODE_SET)");
2683 case TYPE_CODE_RANGE
:
2684 printf_filtered ("(TYPE_CODE_RANGE)");
2686 case TYPE_CODE_STRING
:
2687 printf_filtered ("(TYPE_CODE_STRING)");
2689 case TYPE_CODE_ERROR
:
2690 printf_filtered ("(TYPE_CODE_ERROR)");
2692 case TYPE_CODE_MEMBER
:
2693 printf_filtered ("(TYPE_CODE_MEMBER)");
2695 case TYPE_CODE_METHOD
:
2696 printf_filtered ("(TYPE_CODE_METHOD)");
2699 printf_filtered ("(TYPE_CODE_REF)");
2701 case TYPE_CODE_CHAR
:
2702 printf_filtered ("(TYPE_CODE_CHAR)");
2704 case TYPE_CODE_BOOL
:
2705 printf_filtered ("(TYPE_CODE_BOOL)");
2707 case TYPE_CODE_TYPEDEF
:
2708 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2711 printf_filtered ("(UNKNOWN TYPE CODE)");
2714 puts_filtered ("\n");
2715 printfi_filtered (spaces
, "length %d\n", TYPE_LENGTH (type
));
2716 printfi_filtered (spaces
, "objfile ");
2717 gdb_print_host_address (TYPE_OBJFILE (type
), gdb_stdout
);
2718 printf_filtered ("\n");
2719 printfi_filtered (spaces
, "target_type ");
2720 gdb_print_host_address (TYPE_TARGET_TYPE (type
), gdb_stdout
);
2721 printf_filtered ("\n");
2722 if (TYPE_TARGET_TYPE (type
) != NULL
)
2724 recursive_dump_type (TYPE_TARGET_TYPE (type
), spaces
+ 2);
2726 printfi_filtered (spaces
, "pointer_type ");
2727 gdb_print_host_address (TYPE_POINTER_TYPE (type
), gdb_stdout
);
2728 printf_filtered ("\n");
2729 printfi_filtered (spaces
, "reference_type ");
2730 gdb_print_host_address (TYPE_REFERENCE_TYPE (type
), gdb_stdout
);
2731 printf_filtered ("\n");
2732 printfi_filtered (spaces
, "flags 0x%x", TYPE_FLAGS (type
));
2733 if (TYPE_FLAGS (type
) & TYPE_FLAG_UNSIGNED
)
2735 puts_filtered (" TYPE_FLAG_UNSIGNED");
2737 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
2739 puts_filtered (" TYPE_FLAG_STUB");
2741 puts_filtered ("\n");
2742 printfi_filtered (spaces
, "nfields %d ", TYPE_NFIELDS (type
));
2743 gdb_print_host_address (TYPE_FIELDS (type
), gdb_stdout
);
2744 puts_filtered ("\n");
2745 for (idx
= 0; idx
< TYPE_NFIELDS (type
); idx
++)
2747 printfi_filtered (spaces
+ 2,
2748 "[%d] bitpos %d bitsize %d type ",
2749 idx
, TYPE_FIELD_BITPOS (type
, idx
),
2750 TYPE_FIELD_BITSIZE (type
, idx
));
2751 gdb_print_host_address (TYPE_FIELD_TYPE (type
, idx
), gdb_stdout
);
2752 printf_filtered (" name '%s' (",
2753 TYPE_FIELD_NAME (type
, idx
) != NULL
2754 ? TYPE_FIELD_NAME (type
, idx
)
2756 gdb_print_host_address (TYPE_FIELD_NAME (type
, idx
), gdb_stdout
);
2757 printf_filtered (")\n");
2758 if (TYPE_FIELD_TYPE (type
, idx
) != NULL
)
2760 recursive_dump_type (TYPE_FIELD_TYPE (type
, idx
), spaces
+ 4);
2763 printfi_filtered (spaces
, "vptr_basetype ");
2764 gdb_print_host_address (TYPE_VPTR_BASETYPE (type
), gdb_stdout
);
2765 puts_filtered ("\n");
2766 if (TYPE_VPTR_BASETYPE (type
) != NULL
)
2768 recursive_dump_type (TYPE_VPTR_BASETYPE (type
), spaces
+ 2);
2770 printfi_filtered (spaces
, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type
));
2771 switch (TYPE_CODE (type
))
2773 case TYPE_CODE_METHOD
:
2774 case TYPE_CODE_FUNC
:
2775 printfi_filtered (spaces
, "arg_types ");
2776 gdb_print_host_address (TYPE_ARG_TYPES (type
), gdb_stdout
);
2777 puts_filtered ("\n");
2778 print_arg_types (TYPE_ARG_TYPES (type
), spaces
);
2781 case TYPE_CODE_STRUCT
:
2782 printfi_filtered (spaces
, "cplus_stuff ");
2783 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2784 puts_filtered ("\n");
2785 print_cplus_stuff (type
, spaces
);
2789 printfi_filtered (spaces
, "floatformat ");
2790 if (TYPE_FLOATFORMAT (type
) == NULL
2791 || TYPE_FLOATFORMAT (type
)->name
== NULL
)
2792 puts_filtered ("(null)");
2794 puts_filtered (TYPE_FLOATFORMAT (type
)->name
);
2795 puts_filtered ("\n");
2799 /* We have to pick one of the union types to be able print and test
2800 the value. Pick cplus_struct_type, even though we know it isn't
2801 any particular one. */
2802 printfi_filtered (spaces
, "type_specific ");
2803 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type
), gdb_stdout
);
2804 if (TYPE_CPLUS_SPECIFIC (type
) != NULL
)
2806 printf_filtered (" (unknown data form)");
2808 printf_filtered ("\n");
2813 obstack_free (&dont_print_type_obstack
, NULL
);
2816 static void build_gdbtypes (void);
2818 build_gdbtypes (void)
2821 init_type (TYPE_CODE_VOID
, 1,
2823 "void", (struct objfile
*) NULL
);
2825 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2827 "char", (struct objfile
*) NULL
);
2828 TYPE_FLAGS (builtin_type_char
) |= TYPE_FLAG_NOSIGN
;
2829 builtin_type_true_char
=
2830 init_type (TYPE_CODE_CHAR
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2832 "true character", (struct objfile
*) NULL
);
2833 builtin_type_signed_char
=
2834 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2836 "signed char", (struct objfile
*) NULL
);
2837 builtin_type_unsigned_char
=
2838 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2840 "unsigned char", (struct objfile
*) NULL
);
2841 builtin_type_short
=
2842 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
2844 "short", (struct objfile
*) NULL
);
2845 builtin_type_unsigned_short
=
2846 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
2848 "unsigned short", (struct objfile
*) NULL
);
2850 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
2852 "int", (struct objfile
*) NULL
);
2853 builtin_type_unsigned_int
=
2854 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
2856 "unsigned int", (struct objfile
*) NULL
);
2858 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
2860 "long", (struct objfile
*) NULL
);
2861 builtin_type_unsigned_long
=
2862 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
2864 "unsigned long", (struct objfile
*) NULL
);
2865 builtin_type_long_long
=
2866 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2868 "long long", (struct objfile
*) NULL
);
2869 builtin_type_unsigned_long_long
=
2870 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
2872 "unsigned long long", (struct objfile
*) NULL
);
2873 builtin_type_float
=
2874 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
2876 "float", (struct objfile
*) NULL
);
2877 TYPE_FLOATFORMAT (builtin_type_float
) = TARGET_FLOAT_FORMAT
;
2878 builtin_type_double
=
2879 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2881 "double", (struct objfile
*) NULL
);
2882 TYPE_FLOATFORMAT (builtin_type_double
) = TARGET_DOUBLE_FORMAT
;
2883 builtin_type_long_double
=
2884 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2886 "long double", (struct objfile
*) NULL
);
2887 TYPE_FLOATFORMAT (builtin_type_long_double
) = TARGET_LONG_DOUBLE_FORMAT
;
2888 builtin_type_complex
=
2889 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
2891 "complex", (struct objfile
*) NULL
);
2892 TYPE_TARGET_TYPE (builtin_type_complex
) = builtin_type_float
;
2893 builtin_type_double_complex
=
2894 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
2896 "double complex", (struct objfile
*) NULL
);
2897 TYPE_TARGET_TYPE (builtin_type_double_complex
) = builtin_type_double
;
2898 builtin_type_string
=
2899 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2901 "string", (struct objfile
*) NULL
);
2903 init_type (TYPE_CODE_INT
, 8 / 8,
2905 "int8_t", (struct objfile
*) NULL
);
2906 builtin_type_uint8
=
2907 init_type (TYPE_CODE_INT
, 8 / 8,
2909 "uint8_t", (struct objfile
*) NULL
);
2910 builtin_type_int16
=
2911 init_type (TYPE_CODE_INT
, 16 / 8,
2913 "int16_t", (struct objfile
*) NULL
);
2914 builtin_type_uint16
=
2915 init_type (TYPE_CODE_INT
, 16 / 8,
2917 "uint16_t", (struct objfile
*) NULL
);
2918 builtin_type_int32
=
2919 init_type (TYPE_CODE_INT
, 32 / 8,
2921 "int32_t", (struct objfile
*) NULL
);
2922 builtin_type_uint32
=
2923 init_type (TYPE_CODE_INT
, 32 / 8,
2925 "uint32_t", (struct objfile
*) NULL
);
2926 builtin_type_int64
=
2927 init_type (TYPE_CODE_INT
, 64 / 8,
2929 "int64_t", (struct objfile
*) NULL
);
2930 builtin_type_uint64
=
2931 init_type (TYPE_CODE_INT
, 64 / 8,
2933 "uint64_t", (struct objfile
*) NULL
);
2935 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
2937 "bool", (struct objfile
*) NULL
);
2939 /* Add user knob for controlling resolution of opaque types */
2941 (add_set_cmd ("opaque-type-resolution", class_support
, var_boolean
, (char *) &opaque_type_resolution
,
2942 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
2945 opaque_type_resolution
= 1;
2948 /* Build SIMD types. */
2950 = init_simd_type ("__builtin_v4sf", builtin_type_float
, "f", 4);
2952 = init_simd_type ("__builtin_v4si", builtin_type_int32
, "f", 4);
2954 = init_simd_type ("__builtin_v8qi", builtin_type_int8
, "f", 8);
2956 = init_simd_type ("__builtin_v4hi", builtin_type_int16
, "f", 4);
2958 = init_simd_type ("__builtin_v2si", builtin_type_int32
, "f", 2);
2960 /* Pointer/Address types. */
2962 /* NOTE: on some targets, addresses and pointers are not necessarily
2963 the same --- for example, on the D10V, pointers are 16 bits long,
2964 but addresses are 32 bits long. See doc/gdbint.texinfo,
2965 ``Pointers Are Not Always Addresses''.
2968 - gdb's `struct type' always describes the target's
2970 - gdb's `struct value' objects should always hold values in
2972 - gdb's CORE_ADDR values are addresses in the unified virtual
2973 address space that the assembler and linker work with. Thus,
2974 since target_read_memory takes a CORE_ADDR as an argument, it
2975 can access any memory on the target, even if the processor has
2976 separate code and data address spaces.
2979 - If v is a value holding a D10V code pointer, its contents are
2980 in target form: a big-endian address left-shifted two bits.
2981 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
2982 sizeof (void *) == 2 on the target.
2984 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
2985 target type for a value the target will never see. It's only
2986 used to hold the values of (typeless) linker symbols, which are
2987 indeed in the unified virtual address space. */
2988 builtin_type_void_data_ptr
= make_pointer_type (builtin_type_void
, NULL
);
2989 builtin_type_void_func_ptr
2990 = lookup_pointer_type (lookup_function_type (builtin_type_void
));
2991 builtin_type_CORE_ADDR
=
2992 init_type (TYPE_CODE_INT
, TARGET_ADDR_BIT
/ 8,
2994 "__CORE_ADDR", (struct objfile
*) NULL
);
2995 builtin_type_bfd_vma
=
2996 init_type (TYPE_CODE_INT
, TARGET_BFD_VMA_BIT
/ 8,
2998 "__bfd_vma", (struct objfile
*) NULL
);
3002 extern void _initialize_gdbtypes (void);
3004 _initialize_gdbtypes (void)
3006 struct cmd_list_element
*c
;
3009 /* FIXME - For the moment, handle types by swapping them in and out.
3010 Should be using the per-architecture data-pointer and a large
3012 register_gdbarch_swap (&builtin_type_void
, sizeof (struct type
*), NULL
);
3013 register_gdbarch_swap (&builtin_type_char
, sizeof (struct type
*), NULL
);
3014 register_gdbarch_swap (&builtin_type_short
, sizeof (struct type
*), NULL
);
3015 register_gdbarch_swap (&builtin_type_int
, sizeof (struct type
*), NULL
);
3016 register_gdbarch_swap (&builtin_type_long
, sizeof (struct type
*), NULL
);
3017 register_gdbarch_swap (&builtin_type_long_long
, sizeof (struct type
*), NULL
);
3018 register_gdbarch_swap (&builtin_type_signed_char
, sizeof (struct type
*), NULL
);
3019 register_gdbarch_swap (&builtin_type_unsigned_char
, sizeof (struct type
*), NULL
);
3020 register_gdbarch_swap (&builtin_type_unsigned_short
, sizeof (struct type
*), NULL
);
3021 register_gdbarch_swap (&builtin_type_unsigned_int
, sizeof (struct type
*), NULL
);
3022 register_gdbarch_swap (&builtin_type_unsigned_long
, sizeof (struct type
*), NULL
);
3023 register_gdbarch_swap (&builtin_type_unsigned_long_long
, sizeof (struct type
*), NULL
);
3024 register_gdbarch_swap (&builtin_type_float
, sizeof (struct type
*), NULL
);
3025 register_gdbarch_swap (&builtin_type_double
, sizeof (struct type
*), NULL
);
3026 register_gdbarch_swap (&builtin_type_long_double
, sizeof (struct type
*), NULL
);
3027 register_gdbarch_swap (&builtin_type_complex
, sizeof (struct type
*), NULL
);
3028 register_gdbarch_swap (&builtin_type_double_complex
, sizeof (struct type
*), NULL
);
3029 register_gdbarch_swap (&builtin_type_string
, sizeof (struct type
*), NULL
);
3030 register_gdbarch_swap (&builtin_type_int8
, sizeof (struct type
*), NULL
);
3031 register_gdbarch_swap (&builtin_type_uint8
, sizeof (struct type
*), NULL
);
3032 register_gdbarch_swap (&builtin_type_int16
, sizeof (struct type
*), NULL
);
3033 register_gdbarch_swap (&builtin_type_uint16
, sizeof (struct type
*), NULL
);
3034 register_gdbarch_swap (&builtin_type_int32
, sizeof (struct type
*), NULL
);
3035 register_gdbarch_swap (&builtin_type_uint32
, sizeof (struct type
*), NULL
);
3036 register_gdbarch_swap (&builtin_type_int64
, sizeof (struct type
*), NULL
);
3037 register_gdbarch_swap (&builtin_type_uint64
, sizeof (struct type
*), NULL
);
3038 register_gdbarch_swap (&builtin_type_v4sf
, sizeof (struct type
*), NULL
);
3039 register_gdbarch_swap (&builtin_type_v4si
, sizeof (struct type
*), NULL
);
3040 register_gdbarch_swap (&builtin_type_v8qi
, sizeof (struct type
*), NULL
);
3041 register_gdbarch_swap (&builtin_type_v4hi
, sizeof (struct type
*), NULL
);
3042 register_gdbarch_swap (&builtin_type_v2si
, sizeof (struct type
*), NULL
);
3043 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr
);
3044 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr
);
3045 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR
);
3046 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma
);
3047 register_gdbarch_swap (NULL
, 0, build_gdbtypes
);
3049 /* Note: These types do not need to be swapped - they are target
3051 builtin_type_ieee_single_big
=
3052 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_big
.totalsize
/ 8,
3053 0, "builtin_type_ieee_single_big", NULL
);
3054 TYPE_FLOATFORMAT (builtin_type_ieee_single_big
) = &floatformat_ieee_single_big
;
3055 builtin_type_ieee_single_little
=
3056 init_type (TYPE_CODE_FLT
, floatformat_ieee_single_little
.totalsize
/ 8,
3057 0, "builtin_type_ieee_single_little", NULL
);
3058 builtin_type_ieee_double_big
=
3059 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_big
.totalsize
/ 8,
3060 0, "builtin_type_ieee_double_big", NULL
);
3061 builtin_type_ieee_double_little
=
3062 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_little
.totalsize
/ 8,
3063 0, "builtin_type_ieee_double_little", NULL
);
3064 builtin_type_ieee_double_littlebyte_bigword
=
3065 init_type (TYPE_CODE_FLT
, floatformat_ieee_double_littlebyte_bigword
.totalsize
/ 8,
3066 0, "builtin_type_ieee_double_littlebyte_bigword", NULL
);
3067 builtin_type_i387_ext
=
3068 init_type (TYPE_CODE_FLT
, floatformat_i387_ext
.totalsize
/ 8,
3069 0, "builtin_type_i387_ext", NULL
);
3070 TYPE_FLOATFORMAT (builtin_type_i387_ext
) = &floatformat_i387_ext
;
3071 builtin_type_m68881_ext
=
3072 init_type (TYPE_CODE_FLT
, floatformat_m68881_ext
.totalsize
/ 8,
3073 0, "builtin_type_m68881_ext", NULL
);
3074 builtin_type_i960_ext
=
3075 init_type (TYPE_CODE_FLT
, floatformat_i960_ext
.totalsize
/ 8,
3076 0, "builtin_type_i960_ext", NULL
);
3077 builtin_type_m88110_ext
=
3078 init_type (TYPE_CODE_FLT
, floatformat_m88110_ext
.totalsize
/ 8,
3079 0, "builtin_type_m88110_ext", NULL
);
3080 builtin_type_m88110_harris_ext
=
3081 init_type (TYPE_CODE_FLT
, floatformat_m88110_harris_ext
.totalsize
/ 8,
3082 0, "builtin_type_m88110_harris_ext", NULL
);
3083 builtin_type_arm_ext_big
=
3084 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_big
.totalsize
/ 8,
3085 0, "builtin_type_arm_ext_big", NULL
);
3086 builtin_type_arm_ext_littlebyte_bigword
=
3087 init_type (TYPE_CODE_FLT
, floatformat_arm_ext_littlebyte_bigword
.totalsize
/ 8,
3088 0, "builtin_type_arm_ext_littlebyte_bigword", NULL
);
3089 builtin_type_ia64_spill_big
=
3090 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_big
.totalsize
/ 8,
3091 0, "builtin_type_ia64_spill_big", NULL
);
3092 builtin_type_ia64_spill_little
=
3093 init_type (TYPE_CODE_FLT
, floatformat_ia64_spill_little
.totalsize
/ 8,
3094 0, "builtin_type_ia64_spill_little", NULL
);
3095 builtin_type_ia64_quad_big
=
3096 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_big
.totalsize
/ 8,
3097 0, "builtin_type_ia64_quad_big", NULL
);
3098 builtin_type_ia64_quad_little
=
3099 init_type (TYPE_CODE_FLT
, floatformat_ia64_quad_little
.totalsize
/ 8,
3100 0, "builtin_type_ia64_quad_little", NULL
);
3103 add_set_cmd ("overload", no_class
, var_zinteger
, (char *) &overload_debug
,
3104 "Set debugging of C++ overloading.\n\
3105 When enabled, ranking of the functions\n\
3106 is displayed.", &setdebuglist
),