MFC: An off-by-one malloc size was corrupting the installer's memory,
[dragonfly.git] / contrib / gdb-6.2.1 / gdb / gdbtypes.c
blob1349ffbbe19aceb8eaa4e616bb1805981d040cb7
1 /* Support routines for manipulating internal types for GDB.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004 Free Software Foundation, Inc.
4 Contributed by Cygnus Support, using pieces from other GDB modules.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 #include "defs.h"
24 #include "gdb_string.h"
25 #include "bfd.h"
26 #include "symtab.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "gdbtypes.h"
30 #include "expression.h"
31 #include "language.h"
32 #include "target.h"
33 #include "value.h"
34 #include "demangle.h"
35 #include "complaints.h"
36 #include "gdbcmd.h"
37 #include "wrapper.h"
38 #include "cp-abi.h"
39 #include "gdb_assert.h"
41 /* These variables point to the objects
42 representing the predefined C data types. */
44 struct type *builtin_type_void;
45 struct type *builtin_type_char;
46 struct type *builtin_type_true_char;
47 struct type *builtin_type_short;
48 struct type *builtin_type_int;
49 struct type *builtin_type_long;
50 struct type *builtin_type_long_long;
51 struct type *builtin_type_signed_char;
52 struct type *builtin_type_unsigned_char;
53 struct type *builtin_type_unsigned_short;
54 struct type *builtin_type_unsigned_int;
55 struct type *builtin_type_unsigned_long;
56 struct type *builtin_type_unsigned_long_long;
57 struct type *builtin_type_float;
58 struct type *builtin_type_double;
59 struct type *builtin_type_long_double;
60 struct type *builtin_type_complex;
61 struct type *builtin_type_double_complex;
62 struct type *builtin_type_string;
63 struct type *builtin_type_int0;
64 struct type *builtin_type_int8;
65 struct type *builtin_type_uint8;
66 struct type *builtin_type_int16;
67 struct type *builtin_type_uint16;
68 struct type *builtin_type_int32;
69 struct type *builtin_type_uint32;
70 struct type *builtin_type_int64;
71 struct type *builtin_type_uint64;
72 struct type *builtin_type_int128;
73 struct type *builtin_type_uint128;
74 struct type *builtin_type_bool;
76 /* 128 bit long vector types */
77 struct type *builtin_type_v2_double;
78 struct type *builtin_type_v4_float;
79 struct type *builtin_type_v2_int64;
80 struct type *builtin_type_v4_int32;
81 struct type *builtin_type_v8_int16;
82 struct type *builtin_type_v16_int8;
83 /* 64 bit long vector types */
84 struct type *builtin_type_v2_float;
85 struct type *builtin_type_v2_int32;
86 struct type *builtin_type_v4_int16;
87 struct type *builtin_type_v8_int8;
89 struct type *builtin_type_v4sf;
90 struct type *builtin_type_v4si;
91 struct type *builtin_type_v16qi;
92 struct type *builtin_type_v8qi;
93 struct type *builtin_type_v8hi;
94 struct type *builtin_type_v4hi;
95 struct type *builtin_type_v2si;
96 struct type *builtin_type_vec64;
97 struct type *builtin_type_vec64i;
98 struct type *builtin_type_vec128;
99 struct type *builtin_type_vec128i;
100 struct type *builtin_type_ieee_single_big;
101 struct type *builtin_type_ieee_single_little;
102 struct type *builtin_type_ieee_double_big;
103 struct type *builtin_type_ieee_double_little;
104 struct type *builtin_type_ieee_double_littlebyte_bigword;
105 struct type *builtin_type_i387_ext;
106 struct type *builtin_type_m68881_ext;
107 struct type *builtin_type_i960_ext;
108 struct type *builtin_type_m88110_ext;
109 struct type *builtin_type_m88110_harris_ext;
110 struct type *builtin_type_arm_ext_big;
111 struct type *builtin_type_arm_ext_littlebyte_bigword;
112 struct type *builtin_type_ia64_spill_big;
113 struct type *builtin_type_ia64_spill_little;
114 struct type *builtin_type_ia64_quad_big;
115 struct type *builtin_type_ia64_quad_little;
116 struct type *builtin_type_void_data_ptr;
117 struct type *builtin_type_void_func_ptr;
118 struct type *builtin_type_CORE_ADDR;
119 struct type *builtin_type_bfd_vma;
121 int opaque_type_resolution = 1;
122 int overload_debug = 0;
124 struct extra
126 char str[128];
127 int len;
128 }; /* maximum extension is 128! FIXME */
130 static void print_bit_vector (B_TYPE *, int);
131 static void print_arg_types (struct field *, int, int);
132 static void dump_fn_fieldlists (struct type *, int);
133 static void print_cplus_stuff (struct type *, int);
134 static void virtual_base_list_aux (struct type *dclass);
137 /* Alloc a new type structure and fill it with some defaults. If
138 OBJFILE is non-NULL, then allocate the space for the type structure
139 in that objfile's objfile_obstack. Otherwise allocate the new type structure
140 by xmalloc () (for permanent types). */
142 struct type *
143 alloc_type (struct objfile *objfile)
145 struct type *type;
147 /* Alloc the structure and start off with all fields zeroed. */
149 if (objfile == NULL)
151 type = xmalloc (sizeof (struct type));
152 memset (type, 0, sizeof (struct type));
153 TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
155 else
157 type = obstack_alloc (&objfile->objfile_obstack,
158 sizeof (struct type));
159 memset (type, 0, sizeof (struct type));
160 TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
161 sizeof (struct main_type));
162 OBJSTAT (objfile, n_types++);
164 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
166 /* Initialize the fields that might not be zero. */
168 TYPE_CODE (type) = TYPE_CODE_UNDEF;
169 TYPE_OBJFILE (type) = objfile;
170 TYPE_VPTR_FIELDNO (type) = -1;
171 TYPE_CHAIN (type) = type; /* Chain back to itself. */
173 return (type);
176 /* Alloc a new type instance structure, fill it with some defaults,
177 and point it at OLDTYPE. Allocate the new type instance from the
178 same place as OLDTYPE. */
180 static struct type *
181 alloc_type_instance (struct type *oldtype)
183 struct type *type;
185 /* Allocate the structure. */
187 if (TYPE_OBJFILE (oldtype) == NULL)
189 type = xmalloc (sizeof (struct type));
190 memset (type, 0, sizeof (struct type));
192 else
194 type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
195 sizeof (struct type));
196 memset (type, 0, sizeof (struct type));
198 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
200 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
202 return (type);
205 /* Clear all remnants of the previous type at TYPE, in preparation for
206 replacing it with something else. */
207 static void
208 smash_type (struct type *type)
210 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
212 /* For now, delete the rings. */
213 TYPE_CHAIN (type) = type;
215 /* For now, leave the pointer/reference types alone. */
218 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
219 to a pointer to memory where the pointer type should be stored.
220 If *TYPEPTR is zero, update it to point to the pointer type we return.
221 We allocate new memory if needed. */
223 struct type *
224 make_pointer_type (struct type *type, struct type **typeptr)
226 struct type *ntype; /* New type */
227 struct objfile *objfile;
229 ntype = TYPE_POINTER_TYPE (type);
231 if (ntype)
233 if (typeptr == 0)
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. */
238 return ntype;
242 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
244 ntype = alloc_type (TYPE_OBJFILE (type));
245 if (typeptr)
246 *typeptr = ntype;
248 else
249 /* We have storage, but need to reset it. */
251 ntype = *typeptr;
252 objfile = TYPE_OBJFILE (ntype);
253 smash_type (ntype);
254 TYPE_OBJFILE (ntype) = objfile;
257 TYPE_TARGET_TYPE (ntype) = type;
258 TYPE_POINTER_TYPE (type) = ntype;
260 /* FIXME! Assume the machine has only one representation for pointers! */
262 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
263 TYPE_CODE (ntype) = TYPE_CODE_PTR;
265 /* Mark pointers as unsigned. The target converts between pointers
266 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
267 ADDRESS_TO_POINTER(). */
268 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
270 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
271 TYPE_POINTER_TYPE (type) = ntype;
273 return ntype;
276 /* Given a type TYPE, return a type of pointers to that type.
277 May need to construct such a type if this is the first use. */
279 struct type *
280 lookup_pointer_type (struct type *type)
282 return make_pointer_type (type, (struct type **) 0);
285 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
286 to a pointer to memory where the reference type should be stored.
287 If *TYPEPTR is zero, update it to point to the reference type we return.
288 We allocate new memory if needed. */
290 struct type *
291 make_reference_type (struct type *type, struct type **typeptr)
293 struct type *ntype; /* New type */
294 struct objfile *objfile;
296 ntype = TYPE_REFERENCE_TYPE (type);
298 if (ntype)
300 if (typeptr == 0)
301 return ntype; /* Don't care about alloc, and have new type. */
302 else if (*typeptr == 0)
304 *typeptr = ntype; /* Tracking alloc, and we have new type. */
305 return ntype;
309 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
311 ntype = alloc_type (TYPE_OBJFILE (type));
312 if (typeptr)
313 *typeptr = ntype;
315 else
316 /* We have storage, but need to reset it. */
318 ntype = *typeptr;
319 objfile = TYPE_OBJFILE (ntype);
320 smash_type (ntype);
321 TYPE_OBJFILE (ntype) = objfile;
324 TYPE_TARGET_TYPE (ntype) = type;
325 TYPE_REFERENCE_TYPE (type) = ntype;
327 /* FIXME! Assume the machine has only one representation for references,
328 and that it matches the (only) representation for pointers! */
330 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
331 TYPE_CODE (ntype) = TYPE_CODE_REF;
333 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
334 TYPE_REFERENCE_TYPE (type) = ntype;
336 return ntype;
339 /* Same as above, but caller doesn't care about memory allocation details. */
341 struct type *
342 lookup_reference_type (struct type *type)
344 return make_reference_type (type, (struct type **) 0);
347 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
348 to a pointer to memory where the function type should be stored.
349 If *TYPEPTR is zero, update it to point to the function type we return.
350 We allocate new memory if needed. */
352 struct type *
353 make_function_type (struct type *type, struct type **typeptr)
355 struct type *ntype; /* New type */
356 struct objfile *objfile;
358 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
360 ntype = alloc_type (TYPE_OBJFILE (type));
361 if (typeptr)
362 *typeptr = ntype;
364 else
365 /* We have storage, but need to reset it. */
367 ntype = *typeptr;
368 objfile = TYPE_OBJFILE (ntype);
369 smash_type (ntype);
370 TYPE_OBJFILE (ntype) = objfile;
373 TYPE_TARGET_TYPE (ntype) = type;
375 TYPE_LENGTH (ntype) = 1;
376 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
378 return ntype;
382 /* Given a type TYPE, return a type of functions that return that type.
383 May need to construct such a type if this is the first use. */
385 struct type *
386 lookup_function_type (struct type *type)
388 return make_function_type (type, (struct type **) 0);
391 /* Identify address space identifier by name --
392 return the integer flag defined in gdbtypes.h. */
393 extern int
394 address_space_name_to_int (char *space_identifier)
396 struct gdbarch *gdbarch = current_gdbarch;
397 int type_flags;
398 /* Check for known address space delimiters. */
399 if (!strcmp (space_identifier, "code"))
400 return TYPE_FLAG_CODE_SPACE;
401 else if (!strcmp (space_identifier, "data"))
402 return TYPE_FLAG_DATA_SPACE;
403 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
404 && gdbarch_address_class_name_to_type_flags (gdbarch,
405 space_identifier,
406 &type_flags))
407 return type_flags;
408 else
409 error ("Unknown address space specifier: \"%s\"", space_identifier);
412 /* Identify address space identifier by integer flag as defined in
413 gdbtypes.h -- return the string version of the adress space name. */
415 const char *
416 address_space_int_to_name (int space_flag)
418 struct gdbarch *gdbarch = current_gdbarch;
419 if (space_flag & TYPE_FLAG_CODE_SPACE)
420 return "code";
421 else if (space_flag & TYPE_FLAG_DATA_SPACE)
422 return "data";
423 else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL)
424 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
425 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
426 else
427 return NULL;
430 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
431 If STORAGE is non-NULL, create the new type instance there. */
433 static struct type *
434 make_qualified_type (struct type *type, int new_flags,
435 struct type *storage)
437 struct type *ntype;
439 ntype = type;
440 do {
441 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
442 return ntype;
443 ntype = TYPE_CHAIN (ntype);
444 } while (ntype != type);
446 /* Create a new type instance. */
447 if (storage == NULL)
448 ntype = alloc_type_instance (type);
449 else
451 ntype = storage;
452 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
453 TYPE_CHAIN (ntype) = ntype;
456 /* Pointers or references to the original type are not relevant to
457 the new type. */
458 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
459 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
461 /* Chain the new qualified type to the old type. */
462 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
463 TYPE_CHAIN (type) = ntype;
465 /* Now set the instance flags and return the new type. */
466 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
468 /* Set length of new type to that of the original type. */
469 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
471 return ntype;
474 /* Make an address-space-delimited variant of a type -- a type that
475 is identical to the one supplied except that it has an address
476 space attribute attached to it (such as "code" or "data").
478 The space attributes "code" and "data" are for Harvard architectures.
479 The address space attributes are for architectures which have
480 alternately sized pointers or pointers with alternate representations. */
482 struct type *
483 make_type_with_address_space (struct type *type, int space_flag)
485 struct type *ntype;
486 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
487 & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE
488 | TYPE_FLAG_ADDRESS_CLASS_ALL))
489 | space_flag);
491 return make_qualified_type (type, new_flags, NULL);
494 /* Make a "c-v" variant of a type -- a type that is identical to the
495 one supplied except that it may have const or volatile attributes
496 CNST is a flag for setting the const attribute
497 VOLTL is a flag for setting the volatile attribute
498 TYPE is the base type whose variant we are creating.
499 TYPEPTR, if nonzero, points
500 to a pointer to memory where the reference type should be stored.
501 If *TYPEPTR is zero, update it to point to the reference type we return.
502 We allocate new memory if needed. */
504 struct type *
505 make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
507 struct type *ntype; /* New type */
508 struct type *tmp_type = type; /* tmp type */
509 struct objfile *objfile;
511 int new_flags = (TYPE_INSTANCE_FLAGS (type)
512 & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
514 if (cnst)
515 new_flags |= TYPE_FLAG_CONST;
517 if (voltl)
518 new_flags |= TYPE_FLAG_VOLATILE;
520 if (typeptr && *typeptr != NULL)
522 /* Objfile is per-core-type. This const-qualified type had best
523 belong to the same objfile as the type it is qualifying, unless
524 we are overwriting a stub type, in which case the safest thing
525 to do is to copy the core type into the new objfile. */
527 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)
528 || TYPE_STUB (*typeptr));
529 if (TYPE_OBJFILE (*typeptr) != TYPE_OBJFILE (type))
531 TYPE_MAIN_TYPE (*typeptr)
532 = TYPE_ALLOC (*typeptr, sizeof (struct main_type));
533 *TYPE_MAIN_TYPE (*typeptr)
534 = *TYPE_MAIN_TYPE (type);
538 ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
540 if (typeptr != NULL)
541 *typeptr = ntype;
543 return ntype;
546 /* Replace the contents of ntype with the type *type. This changes the
547 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
548 the changes are propogated to all types in the TYPE_CHAIN.
550 In order to build recursive types, it's inevitable that we'll need
551 to update types in place --- but this sort of indiscriminate
552 smashing is ugly, and needs to be replaced with something more
553 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
554 clear if more steps are needed. */
555 void
556 replace_type (struct type *ntype, struct type *type)
558 struct type *chain;
560 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
562 /* The type length is not a part of the main type. Update it for each
563 type on the variant chain. */
564 chain = ntype;
565 do {
566 /* Assert that this element of the chain has no address-class bits
567 set in its flags. Such type variants might have type lengths
568 which are supposed to be different from the non-address-class
569 variants. This assertion shouldn't ever be triggered because
570 symbol readers which do construct address-class variants don't
571 call replace_type(). */
572 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
574 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
575 chain = TYPE_CHAIN (chain);
576 } while (ntype != chain);
578 /* Assert that the two types have equivalent instance qualifiers.
579 This should be true for at least all of our debug readers. */
580 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
583 /* Implement direct support for MEMBER_TYPE in GNU C++.
584 May need to construct such a type if this is the first use.
585 The TYPE is the type of the member. The DOMAIN is the type
586 of the aggregate that the member belongs to. */
588 struct type *
589 lookup_member_type (struct type *type, struct type *domain)
591 struct type *mtype;
593 mtype = alloc_type (TYPE_OBJFILE (type));
594 smash_to_member_type (mtype, domain, type);
595 return (mtype);
598 /* Allocate a stub method whose return type is TYPE.
599 This apparently happens for speed of symbol reading, since parsing
600 out the arguments to the method is cpu-intensive, the way we are doing
601 it. So, we will fill in arguments later.
602 This always returns a fresh type. */
604 struct type *
605 allocate_stub_method (struct type *type)
607 struct type *mtype;
609 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
610 TYPE_OBJFILE (type));
611 TYPE_TARGET_TYPE (mtype) = type;
612 /* _DOMAIN_TYPE (mtype) = unknown yet */
613 return (mtype);
616 /* Create a range type using either a blank type supplied in RESULT_TYPE,
617 or creating a new type, inheriting the objfile from INDEX_TYPE.
619 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
620 HIGH_BOUND, inclusive.
622 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
623 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
625 struct type *
626 create_range_type (struct type *result_type, struct type *index_type,
627 int low_bound, int high_bound)
629 if (result_type == NULL)
631 result_type = alloc_type (TYPE_OBJFILE (index_type));
633 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
634 TYPE_TARGET_TYPE (result_type) = index_type;
635 if (TYPE_STUB (index_type))
636 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
637 else
638 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
639 TYPE_NFIELDS (result_type) = 2;
640 TYPE_FIELDS (result_type) = (struct field *)
641 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
642 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
643 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
644 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
645 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
646 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
648 if (low_bound >= 0)
649 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
651 return (result_type);
654 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
655 Return 1 of type is a range type, 0 if it is discrete (and bounds
656 will fit in LONGEST), or -1 otherwise. */
659 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
661 CHECK_TYPEDEF (type);
662 switch (TYPE_CODE (type))
664 case TYPE_CODE_RANGE:
665 *lowp = TYPE_LOW_BOUND (type);
666 *highp = TYPE_HIGH_BOUND (type);
667 return 1;
668 case TYPE_CODE_ENUM:
669 if (TYPE_NFIELDS (type) > 0)
671 /* The enums may not be sorted by value, so search all
672 entries */
673 int i;
675 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
676 for (i = 0; i < TYPE_NFIELDS (type); i++)
678 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
679 *lowp = TYPE_FIELD_BITPOS (type, i);
680 if (TYPE_FIELD_BITPOS (type, i) > *highp)
681 *highp = TYPE_FIELD_BITPOS (type, i);
684 /* Set unsigned indicator if warranted. */
685 if (*lowp >= 0)
687 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
690 else
692 *lowp = 0;
693 *highp = -1;
695 return 0;
696 case TYPE_CODE_BOOL:
697 *lowp = 0;
698 *highp = 1;
699 return 0;
700 case TYPE_CODE_INT:
701 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
702 return -1;
703 if (!TYPE_UNSIGNED (type))
705 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
706 *highp = -*lowp - 1;
707 return 0;
709 /* ... fall through for unsigned ints ... */
710 case TYPE_CODE_CHAR:
711 *lowp = 0;
712 /* This round-about calculation is to avoid shifting by
713 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
714 if TYPE_LENGTH (type) == sizeof (LONGEST). */
715 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
716 *highp = (*highp - 1) | *highp;
717 return 0;
718 default:
719 return -1;
723 /* Create an array type using either a blank type supplied in RESULT_TYPE,
724 or creating a new type, inheriting the objfile from RANGE_TYPE.
726 Elements will be of type ELEMENT_TYPE, the indices will be of type
727 RANGE_TYPE.
729 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
730 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
732 struct type *
733 create_array_type (struct type *result_type, struct type *element_type,
734 struct type *range_type)
736 LONGEST low_bound, high_bound;
738 if (result_type == NULL)
740 result_type = alloc_type (TYPE_OBJFILE (range_type));
742 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
743 TYPE_TARGET_TYPE (result_type) = element_type;
744 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
745 low_bound = high_bound = 0;
746 CHECK_TYPEDEF (element_type);
747 TYPE_LENGTH (result_type) =
748 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
749 TYPE_NFIELDS (result_type) = 1;
750 TYPE_FIELDS (result_type) =
751 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
752 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
753 TYPE_FIELD_TYPE (result_type, 0) = range_type;
754 TYPE_VPTR_FIELDNO (result_type) = -1;
756 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
757 if (TYPE_LENGTH (result_type) == 0)
758 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
760 return (result_type);
763 /* Create a string type using either a blank type supplied in RESULT_TYPE,
764 or creating a new type. String types are similar enough to array of
765 char types that we can use create_array_type to build the basic type
766 and then bash it into a string type.
768 For fixed length strings, the range type contains 0 as the lower
769 bound and the length of the string minus one as the upper bound.
771 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
772 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
774 struct type *
775 create_string_type (struct type *result_type, struct type *range_type)
777 result_type = create_array_type (result_type,
778 *current_language->string_char_type,
779 range_type);
780 TYPE_CODE (result_type) = TYPE_CODE_STRING;
781 return (result_type);
784 struct type *
785 create_set_type (struct type *result_type, struct type *domain_type)
787 LONGEST low_bound, high_bound, bit_length;
788 if (result_type == NULL)
790 result_type = alloc_type (TYPE_OBJFILE (domain_type));
792 TYPE_CODE (result_type) = TYPE_CODE_SET;
793 TYPE_NFIELDS (result_type) = 1;
794 TYPE_FIELDS (result_type) = (struct field *)
795 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
796 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
798 if (!TYPE_STUB (domain_type))
800 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
801 low_bound = high_bound = 0;
802 bit_length = high_bound - low_bound + 1;
803 TYPE_LENGTH (result_type)
804 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
806 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
808 if (low_bound >= 0)
809 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
811 return (result_type);
814 /* Construct and return a type of the form:
815 struct NAME { ELT_TYPE ELT_NAME[N]; }
816 We use these types for SIMD registers. For example, the type of
817 the SSE registers on the late x86-family processors is:
818 struct __builtin_v4sf { float f[4]; }
819 built by the function call:
820 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
821 The type returned is a permanent type, allocated using malloc; it
822 doesn't live in any objfile's obstack. */
823 static struct type *
824 init_simd_type (char *name,
825 struct type *elt_type,
826 char *elt_name,
827 int n)
829 struct type *simd_type;
830 struct type *array_type;
832 simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
833 array_type = create_array_type (0, elt_type,
834 create_range_type (0, builtin_type_int,
835 0, n-1));
836 append_composite_type_field (simd_type, elt_name, array_type);
837 return simd_type;
840 static struct type *
841 init_vector_type (struct type *elt_type, int n)
843 struct type *array_type;
845 array_type = create_array_type (0, elt_type,
846 create_range_type (0, builtin_type_int,
847 0, n-1));
848 TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
849 return array_type;
852 static struct type *
853 build_builtin_type_vec64 (void)
855 /* Construct a type for the 64 bit registers. The type we're
856 building is this: */
857 #if 0
858 union __gdb_builtin_type_vec64
860 int64_t uint64;
861 float v2_float[2];
862 int32_t v2_int32[2];
863 int16_t v4_int16[4];
864 int8_t v8_int8[8];
866 #endif
868 struct type *t;
870 t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION);
871 append_composite_type_field (t, "uint64", builtin_type_int64);
872 append_composite_type_field (t, "v2_float", builtin_type_v2_float);
873 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
874 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
875 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
877 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
878 TYPE_NAME (t) = "builtin_type_vec64";
879 return t;
882 static struct type *
883 build_builtin_type_vec64i (void)
885 /* Construct a type for the 64 bit registers. The type we're
886 building is this: */
887 #if 0
888 union __gdb_builtin_type_vec64i
890 int64_t uint64;
891 int32_t v2_int32[2];
892 int16_t v4_int16[4];
893 int8_t v8_int8[8];
895 #endif
897 struct type *t;
899 t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
900 append_composite_type_field (t, "uint64", builtin_type_int64);
901 append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
902 append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
903 append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
905 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
906 TYPE_NAME (t) = "builtin_type_vec64i";
907 return t;
910 static struct type *
911 build_builtin_type_vec128 (void)
913 /* Construct a type for the 128 bit registers. The type we're
914 building is this: */
915 #if 0
916 union __gdb_builtin_type_vec128
918 int128_t uint128;
919 float v4_float[4];
920 int32_t v4_int32[4];
921 int16_t v8_int16[8];
922 int8_t v16_int8[16];
924 #endif
926 struct type *t;
928 t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
929 append_composite_type_field (t, "uint128", builtin_type_int128);
930 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
931 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
932 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
933 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
935 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
936 TYPE_NAME (t) = "builtin_type_vec128";
937 return t;
940 static struct type *
941 build_builtin_type_vec128i (void)
943 /* 128-bit Intel SIMD registers */
944 struct type *t;
946 t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
947 append_composite_type_field (t, "v4_float", builtin_type_v4_float);
948 append_composite_type_field (t, "v2_double", builtin_type_v2_double);
949 append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
950 append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
951 append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
952 append_composite_type_field (t, "v2_int64", builtin_type_v2_int64);
953 append_composite_type_field (t, "uint128", builtin_type_int128);
955 TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
956 TYPE_NAME (t) = "builtin_type_vec128i";
957 return t;
960 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
961 A MEMBER is a wierd thing -- it amounts to a typed offset into
962 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
963 include the offset (that's the value of the MEMBER itself), but does
964 include the structure type into which it points (for some reason).
966 When "smashing" the type, we preserve the objfile that the
967 old type pointed to, since we aren't changing where the type is actually
968 allocated. */
970 void
971 smash_to_member_type (struct type *type, struct type *domain,
972 struct type *to_type)
974 struct objfile *objfile;
976 objfile = TYPE_OBJFILE (type);
978 smash_type (type);
979 TYPE_OBJFILE (type) = objfile;
980 TYPE_TARGET_TYPE (type) = to_type;
981 TYPE_DOMAIN_TYPE (type) = domain;
982 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
983 TYPE_CODE (type) = TYPE_CODE_MEMBER;
986 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
987 METHOD just means `function that gets an extra "this" argument'.
989 When "smashing" the type, we preserve the objfile that the
990 old type pointed to, since we aren't changing where the type is actually
991 allocated. */
993 void
994 smash_to_method_type (struct type *type, struct type *domain,
995 struct type *to_type, struct field *args,
996 int nargs, int varargs)
998 struct objfile *objfile;
1000 objfile = TYPE_OBJFILE (type);
1002 smash_type (type);
1003 TYPE_OBJFILE (type) = objfile;
1004 TYPE_TARGET_TYPE (type) = to_type;
1005 TYPE_DOMAIN_TYPE (type) = domain;
1006 TYPE_FIELDS (type) = args;
1007 TYPE_NFIELDS (type) = nargs;
1008 if (varargs)
1009 TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
1010 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1011 TYPE_CODE (type) = TYPE_CODE_METHOD;
1014 /* Return a typename for a struct/union/enum type without "struct ",
1015 "union ", or "enum ". If the type has a NULL name, return NULL. */
1017 char *
1018 type_name_no_tag (const struct type *type)
1020 if (TYPE_TAG_NAME (type) != NULL)
1021 return TYPE_TAG_NAME (type);
1023 /* Is there code which expects this to return the name if there is no
1024 tag name? My guess is that this is mainly used for C++ in cases where
1025 the two will always be the same. */
1026 return TYPE_NAME (type);
1029 /* Lookup a primitive type named NAME.
1030 Return zero if NAME is not a primitive type. */
1032 struct type *
1033 lookup_primitive_typename (char *name)
1035 struct type **const *p;
1037 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
1039 if (strcmp (TYPE_NAME (**p), name) == 0)
1041 return (**p);
1044 return (NULL);
1047 /* Lookup a typedef or primitive type named NAME,
1048 visible in lexical block BLOCK.
1049 If NOERR is nonzero, return zero if NAME is not suitably defined. */
1051 struct type *
1052 lookup_typename (char *name, struct block *block, int noerr)
1054 struct symbol *sym;
1055 struct type *tmp;
1057 sym = lookup_symbol (name, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
1058 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1060 tmp = lookup_primitive_typename (name);
1061 if (tmp)
1063 return (tmp);
1065 else if (!tmp && noerr)
1067 return (NULL);
1069 else
1071 error ("No type named %s.", name);
1074 return (SYMBOL_TYPE (sym));
1077 struct type *
1078 lookup_unsigned_typename (char *name)
1080 char *uns = alloca (strlen (name) + 10);
1082 strcpy (uns, "unsigned ");
1083 strcpy (uns + 9, name);
1084 return (lookup_typename (uns, (struct block *) NULL, 0));
1087 struct type *
1088 lookup_signed_typename (char *name)
1090 struct type *t;
1091 char *uns = alloca (strlen (name) + 8);
1093 strcpy (uns, "signed ");
1094 strcpy (uns + 7, name);
1095 t = lookup_typename (uns, (struct block *) NULL, 1);
1096 /* If we don't find "signed FOO" just try again with plain "FOO". */
1097 if (t != NULL)
1098 return t;
1099 return lookup_typename (name, (struct block *) NULL, 0);
1102 /* Lookup a structure type named "struct NAME",
1103 visible in lexical block BLOCK. */
1105 struct type *
1106 lookup_struct (char *name, struct block *block)
1108 struct symbol *sym;
1110 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1111 (struct symtab **) NULL);
1113 if (sym == NULL)
1115 error ("No struct type named %s.", name);
1117 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1119 error ("This context has class, union or enum %s, not a struct.", name);
1121 return (SYMBOL_TYPE (sym));
1124 /* Lookup a union type named "union NAME",
1125 visible in lexical block BLOCK. */
1127 struct type *
1128 lookup_union (char *name, struct block *block)
1130 struct symbol *sym;
1131 struct type *t;
1133 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1134 (struct symtab **) NULL);
1136 if (sym == NULL)
1137 error ("No union type named %s.", name);
1139 t = SYMBOL_TYPE (sym);
1141 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1142 return (t);
1144 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1145 * a further "declared_type" field to discover it is really a union.
1147 if (HAVE_CPLUS_STRUCT (t))
1148 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1149 return (t);
1151 /* If we get here, it's not a union */
1152 error ("This context has class, struct or enum %s, not a union.", name);
1156 /* Lookup an enum type named "enum NAME",
1157 visible in lexical block BLOCK. */
1159 struct type *
1160 lookup_enum (char *name, struct block *block)
1162 struct symbol *sym;
1164 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
1165 (struct symtab **) NULL);
1166 if (sym == NULL)
1168 error ("No enum type named %s.", name);
1170 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1172 error ("This context has class, struct or union %s, not an enum.", name);
1174 return (SYMBOL_TYPE (sym));
1177 /* Lookup a template type named "template NAME<TYPE>",
1178 visible in lexical block BLOCK. */
1180 struct type *
1181 lookup_template_type (char *name, struct type *type, struct block *block)
1183 struct symbol *sym;
1184 char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1185 strcpy (nam, name);
1186 strcat (nam, "<");
1187 strcat (nam, TYPE_NAME (type));
1188 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1190 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
1192 if (sym == NULL)
1194 error ("No template type named %s.", name);
1196 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1198 error ("This context has class, union or enum %s, not a struct.", name);
1200 return (SYMBOL_TYPE (sym));
1203 /* Given a type TYPE, lookup the type of the component of type named NAME.
1205 TYPE can be either a struct or union, or a pointer or reference to a struct or
1206 union. If it is a pointer or reference, its target type is automatically used.
1207 Thus '.' and '->' are interchangable, as specified for the definitions of the
1208 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1210 If NOERR is nonzero, return zero if NAME is not suitably defined.
1211 If NAME is the name of a baseclass type, return that type. */
1213 struct type *
1214 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1216 int i;
1218 for (;;)
1220 CHECK_TYPEDEF (type);
1221 if (TYPE_CODE (type) != TYPE_CODE_PTR
1222 && TYPE_CODE (type) != TYPE_CODE_REF)
1223 break;
1224 type = TYPE_TARGET_TYPE (type);
1227 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1228 TYPE_CODE (type) != TYPE_CODE_UNION)
1230 target_terminal_ours ();
1231 gdb_flush (gdb_stdout);
1232 fprintf_unfiltered (gdb_stderr, "Type ");
1233 type_print (type, "", gdb_stderr, -1);
1234 error (" is not a structure or union type.");
1237 #if 0
1238 /* FIXME: This change put in by Michael seems incorrect for the case where
1239 the structure tag name is the same as the member name. I.E. when doing
1240 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1241 Disabled by fnf. */
1243 char *typename;
1245 typename = type_name_no_tag (type);
1246 if (typename != NULL && strcmp (typename, name) == 0)
1247 return type;
1249 #endif
1251 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1253 char *t_field_name = TYPE_FIELD_NAME (type, i);
1255 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1257 return TYPE_FIELD_TYPE (type, i);
1261 /* OK, it's not in this class. Recursively check the baseclasses. */
1262 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1264 struct type *t;
1266 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1267 if (t != NULL)
1269 return t;
1273 if (noerr)
1275 return NULL;
1278 target_terminal_ours ();
1279 gdb_flush (gdb_stdout);
1280 fprintf_unfiltered (gdb_stderr, "Type ");
1281 type_print (type, "", gdb_stderr, -1);
1282 fprintf_unfiltered (gdb_stderr, " has no component named ");
1283 fputs_filtered (name, gdb_stderr);
1284 error (".");
1285 return (struct type *) -1; /* For lint */
1288 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1289 valid. Callers should be aware that in some cases (for example,
1290 the type or one of its baseclasses is a stub type and we are
1291 debugging a .o file), this function will not be able to find the virtual
1292 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1293 will remain NULL. */
1295 void
1296 fill_in_vptr_fieldno (struct type *type)
1298 CHECK_TYPEDEF (type);
1300 if (TYPE_VPTR_FIELDNO (type) < 0)
1302 int i;
1304 /* We must start at zero in case the first (and only) baseclass is
1305 virtual (and hence we cannot share the table pointer). */
1306 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1308 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1309 fill_in_vptr_fieldno (baseclass);
1310 if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
1312 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
1313 TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
1314 break;
1320 /* Find the method and field indices for the destructor in class type T.
1321 Return 1 if the destructor was found, otherwise, return 0. */
1324 get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
1326 int i;
1328 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1330 int j;
1331 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1333 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1335 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1337 *method_indexp = i;
1338 *field_indexp = j;
1339 return 1;
1343 return 0;
1346 static void
1347 stub_noname_complaint (void)
1349 complaint (&symfile_complaints, "stub type has NULL name");
1352 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1354 If this is a stubbed struct (i.e. declared as struct foo *), see if
1355 we can find a full definition in some other file. If so, copy this
1356 definition, so we can use it in future. There used to be a comment (but
1357 not any code) that if we don't find a full definition, we'd set a flag
1358 so we don't spend time in the future checking the same type. That would
1359 be a mistake, though--we might load in more symbols which contain a
1360 full definition for the type.
1362 This used to be coded as a macro, but I don't think it is called
1363 often enough to merit such treatment. */
1365 /* Find the real type of TYPE. This function returns the real type, after
1366 removing all layers of typedefs and completing opaque or stub types.
1367 Completion changes the TYPE argument, but stripping of typedefs does
1368 not. */
1370 struct type *
1371 check_typedef (struct type *type)
1373 struct type *orig_type = type;
1374 int is_const, is_volatile;
1376 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1378 if (!TYPE_TARGET_TYPE (type))
1380 char *name;
1381 struct symbol *sym;
1383 /* It is dangerous to call lookup_symbol if we are currently
1384 reading a symtab. Infinite recursion is one danger. */
1385 if (currently_reading_symtab)
1386 return type;
1388 name = type_name_no_tag (type);
1389 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1390 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1391 as appropriate? (this code was written before TYPE_NAME and
1392 TYPE_TAG_NAME were separate). */
1393 if (name == NULL)
1395 stub_noname_complaint ();
1396 return type;
1398 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
1399 (struct symtab **) NULL);
1400 if (sym)
1401 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1402 else
1403 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1405 type = TYPE_TARGET_TYPE (type);
1408 is_const = TYPE_CONST (type);
1409 is_volatile = TYPE_VOLATILE (type);
1411 /* If this is a struct/class/union with no fields, then check whether a
1412 full definition exists somewhere else. This is for systems where a
1413 type definition with no fields is issued for such types, instead of
1414 identifying them as stub types in the first place */
1416 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1418 char *name = type_name_no_tag (type);
1419 struct type *newtype;
1420 if (name == NULL)
1422 stub_noname_complaint ();
1423 return type;
1425 newtype = lookup_transparent_type (name);
1426 if (newtype)
1427 make_cv_type (is_const, is_volatile, newtype, &type);
1429 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1430 else if (TYPE_STUB (type) && !currently_reading_symtab)
1432 char *name = type_name_no_tag (type);
1433 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1434 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1435 as appropriate? (this code was written before TYPE_NAME and
1436 TYPE_TAG_NAME were separate). */
1437 struct symbol *sym;
1438 if (name == NULL)
1440 stub_noname_complaint ();
1441 return type;
1443 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL);
1444 if (sym)
1445 make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type);
1448 if (TYPE_TARGET_STUB (type))
1450 struct type *range_type;
1451 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1453 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1456 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1457 && TYPE_NFIELDS (type) == 1
1458 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1459 == TYPE_CODE_RANGE))
1461 /* Now recompute the length of the array type, based on its
1462 number of elements and the target type's length. */
1463 TYPE_LENGTH (type) =
1464 ((TYPE_FIELD_BITPOS (range_type, 1)
1465 - TYPE_FIELD_BITPOS (range_type, 0)
1466 + 1)
1467 * TYPE_LENGTH (target_type));
1468 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1470 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1472 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1473 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1476 /* Cache TYPE_LENGTH for future use. */
1477 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1478 return type;
1481 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1482 silently return builtin_type_void. */
1484 static struct type *
1485 safe_parse_type (char *p, int length)
1487 struct ui_file *saved_gdb_stderr;
1488 struct type *type;
1490 /* Suppress error messages. */
1491 saved_gdb_stderr = gdb_stderr;
1492 gdb_stderr = ui_file_new ();
1494 /* Call parse_and_eval_type() without fear of longjmp()s. */
1495 if (!gdb_parse_and_eval_type (p, length, &type))
1496 type = builtin_type_void;
1498 /* Stop suppressing error messages. */
1499 ui_file_delete (gdb_stderr);
1500 gdb_stderr = saved_gdb_stderr;
1502 return type;
1505 /* Ugly hack to convert method stubs into method types.
1507 He ain't kiddin'. This demangles the name of the method into a string
1508 including argument types, parses out each argument type, generates
1509 a string casting a zero to that type, evaluates the string, and stuffs
1510 the resulting type into an argtype vector!!! Then it knows the type
1511 of the whole function (including argument types for overloading),
1512 which info used to be in the stab's but was removed to hack back
1513 the space required for them. */
1515 static void
1516 check_stub_method (struct type *type, int method_id, int signature_id)
1518 struct fn_field *f;
1519 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1520 char *demangled_name = cplus_demangle (mangled_name,
1521 DMGL_PARAMS | DMGL_ANSI);
1522 char *argtypetext, *p;
1523 int depth = 0, argcount = 1;
1524 struct field *argtypes;
1525 struct type *mtype;
1527 /* Make sure we got back a function string that we can use. */
1528 if (demangled_name)
1529 p = strchr (demangled_name, '(');
1530 else
1531 p = NULL;
1533 if (demangled_name == NULL || p == NULL)
1534 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1536 /* Now, read in the parameters that define this type. */
1537 p += 1;
1538 argtypetext = p;
1539 while (*p)
1541 if (*p == '(' || *p == '<')
1543 depth += 1;
1545 else if (*p == ')' || *p == '>')
1547 depth -= 1;
1549 else if (*p == ',' && depth == 0)
1551 argcount += 1;
1554 p += 1;
1557 /* If we read one argument and it was ``void'', don't count it. */
1558 if (strncmp (argtypetext, "(void)", 6) == 0)
1559 argcount -= 1;
1561 /* We need one extra slot, for the THIS pointer. */
1563 argtypes = (struct field *)
1564 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1565 p = argtypetext;
1567 /* Add THIS pointer for non-static methods. */
1568 f = TYPE_FN_FIELDLIST1 (type, method_id);
1569 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1570 argcount = 0;
1571 else
1573 argtypes[0].type = lookup_pointer_type (type);
1574 argcount = 1;
1577 if (*p != ')') /* () means no args, skip while */
1579 depth = 0;
1580 while (*p)
1582 if (depth <= 0 && (*p == ',' || *p == ')'))
1584 /* Avoid parsing of ellipsis, they will be handled below.
1585 Also avoid ``void'' as above. */
1586 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1587 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1589 argtypes[argcount].type =
1590 safe_parse_type (argtypetext, p - argtypetext);
1591 argcount += 1;
1593 argtypetext = p + 1;
1596 if (*p == '(' || *p == '<')
1598 depth += 1;
1600 else if (*p == ')' || *p == '>')
1602 depth -= 1;
1605 p += 1;
1609 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1611 /* Now update the old "stub" type into a real type. */
1612 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1613 TYPE_DOMAIN_TYPE (mtype) = type;
1614 TYPE_FIELDS (mtype) = argtypes;
1615 TYPE_NFIELDS (mtype) = argcount;
1616 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1617 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1618 if (p[-2] == '.')
1619 TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1621 xfree (demangled_name);
1624 /* This is the external interface to check_stub_method, above. This function
1625 unstubs all of the signatures for TYPE's METHOD_ID method name. After
1626 calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1627 and TYPE_FN_FIELDLIST_NAME will be correct.
1629 This function unfortunately can not die until stabs do. */
1631 void
1632 check_stub_method_group (struct type *type, int method_id)
1634 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1635 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1636 int j, found_stub = 0;
1638 for (j = 0; j < len; j++)
1639 if (TYPE_FN_FIELD_STUB (f, j))
1641 found_stub = 1;
1642 check_stub_method (type, method_id, j);
1645 /* GNU v3 methods with incorrect names were corrected when we read in
1646 type information, because it was cheaper to do it then. The only GNU v2
1647 methods with incorrect method names are operators and destructors;
1648 destructors were also corrected when we read in type information.
1650 Therefore the only thing we need to handle here are v2 operator
1651 names. */
1652 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1654 int ret;
1655 char dem_opname[256];
1657 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1658 dem_opname, DMGL_ANSI);
1659 if (!ret)
1660 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1661 dem_opname, 0);
1662 if (ret)
1663 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1667 const struct cplus_struct_type cplus_struct_default;
1669 void
1670 allocate_cplus_struct_type (struct type *type)
1672 if (!HAVE_CPLUS_STRUCT (type))
1674 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1675 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1676 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1680 /* Helper function to initialize the standard scalar types.
1682 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1683 of the string pointed to by name in the objfile_obstack for that objfile,
1684 and initialize the type name to that copy. There are places (mipsread.c
1685 in particular, where init_type is called with a NULL value for NAME). */
1687 struct type *
1688 init_type (enum type_code code, int length, int flags, char *name,
1689 struct objfile *objfile)
1691 struct type *type;
1693 type = alloc_type (objfile);
1694 TYPE_CODE (type) = code;
1695 TYPE_LENGTH (type) = length;
1696 TYPE_FLAGS (type) |= flags;
1697 if ((name != NULL) && (objfile != NULL))
1699 TYPE_NAME (type) =
1700 obsavestring (name, strlen (name), &objfile->objfile_obstack);
1702 else
1704 TYPE_NAME (type) = name;
1707 /* C++ fancies. */
1709 if (name && strcmp (name, "char") == 0)
1710 TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
1712 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1713 || code == TYPE_CODE_NAMESPACE)
1715 INIT_CPLUS_SPECIFIC (type);
1717 return (type);
1720 /* Helper function. Create an empty composite type. */
1722 struct type *
1723 init_composite_type (char *name, enum type_code code)
1725 struct type *t;
1726 gdb_assert (code == TYPE_CODE_STRUCT
1727 || code == TYPE_CODE_UNION);
1728 t = init_type (code, 0, 0, NULL, NULL);
1729 TYPE_TAG_NAME (t) = name;
1730 return t;
1733 /* Helper function. Append a field to a composite type. */
1735 void
1736 append_composite_type_field (struct type *t, char *name, struct type *field)
1738 struct field *f;
1739 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1740 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1741 sizeof (struct field) * TYPE_NFIELDS (t));
1742 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1743 memset (f, 0, sizeof f[0]);
1744 FIELD_TYPE (f[0]) = field;
1745 FIELD_NAME (f[0]) = name;
1746 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1748 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1749 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1751 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1753 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1754 if (TYPE_NFIELDS (t) > 1)
1756 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1757 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1762 /* Look up a fundamental type for the specified objfile.
1763 May need to construct such a type if this is the first use.
1765 Some object file formats (ELF, COFF, etc) do not define fundamental
1766 types such as "int" or "double". Others (stabs for example), do
1767 define fundamental types.
1769 For the formats which don't provide fundamental types, gdb can create
1770 such types, using defaults reasonable for the current language and
1771 the current target machine.
1773 NOTE: This routine is obsolescent. Each debugging format reader
1774 should manage it's own fundamental types, either creating them from
1775 suitable defaults or reading them from the debugging information,
1776 whichever is appropriate. The DWARF reader has already been
1777 fixed to do this. Once the other readers are fixed, this routine
1778 will go away. Also note that fundamental types should be managed
1779 on a compilation unit basis in a multi-language environment, not
1780 on a linkage unit basis as is done here. */
1783 struct type *
1784 lookup_fundamental_type (struct objfile *objfile, int typeid)
1786 struct type **typep;
1787 int nbytes;
1789 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1791 error ("internal error - invalid fundamental type id %d", typeid);
1794 /* If this is the first time we need a fundamental type for this objfile
1795 then we need to initialize the vector of type pointers. */
1797 if (objfile->fundamental_types == NULL)
1799 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1800 objfile->fundamental_types = (struct type **)
1801 obstack_alloc (&objfile->objfile_obstack, nbytes);
1802 memset ((char *) objfile->fundamental_types, 0, nbytes);
1803 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1806 /* Look for this particular type in the fundamental type vector. If one is
1807 not found, create and install one appropriate for the current language. */
1809 typep = objfile->fundamental_types + typeid;
1810 if (*typep == NULL)
1812 *typep = create_fundamental_type (objfile, typeid);
1815 return (*typep);
1819 can_dereference (struct type *t)
1821 /* FIXME: Should we return true for references as well as pointers? */
1822 CHECK_TYPEDEF (t);
1823 return
1824 (t != NULL
1825 && TYPE_CODE (t) == TYPE_CODE_PTR
1826 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1830 is_integral_type (struct type *t)
1832 CHECK_TYPEDEF (t);
1833 return
1834 ((t != NULL)
1835 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1836 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1837 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1838 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1839 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1842 /* Check whether BASE is an ancestor or base class or DCLASS
1843 Return 1 if so, and 0 if not.
1844 Note: callers may want to check for identity of the types before
1845 calling this function -- identical types are considered to satisfy
1846 the ancestor relationship even if they're identical */
1849 is_ancestor (struct type *base, struct type *dclass)
1851 int i;
1853 CHECK_TYPEDEF (base);
1854 CHECK_TYPEDEF (dclass);
1856 if (base == dclass)
1857 return 1;
1858 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
1859 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1860 return 1;
1862 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1863 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1864 return 1;
1866 return 0;
1871 /* See whether DCLASS has a virtual table. This routine is aimed at
1872 the HP/Taligent ANSI C++ runtime model, and may not work with other
1873 runtime models. Return 1 => Yes, 0 => No. */
1876 has_vtable (struct type *dclass)
1878 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1879 has virtual functions or virtual bases. */
1881 int i;
1883 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1884 return 0;
1886 /* First check for the presence of virtual bases */
1887 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1888 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1889 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1890 return 1;
1892 /* Next check for virtual functions */
1893 if (TYPE_FN_FIELDLISTS (dclass))
1894 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1895 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1896 return 1;
1898 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1899 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1900 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1901 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1902 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1903 return 1;
1905 /* Well, maybe we don't need a virtual table */
1906 return 0;
1909 /* Return a pointer to the "primary base class" of DCLASS.
1911 A NULL return indicates that DCLASS has no primary base, or that it
1912 couldn't be found (insufficient information).
1914 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1915 and may not work with other runtime models. */
1917 struct type *
1918 primary_base_class (struct type *dclass)
1920 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1921 is the first directly inherited, non-virtual base class that
1922 requires a virtual table */
1924 int i;
1926 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1927 return NULL;
1929 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1930 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1931 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1932 return TYPE_FIELD_TYPE (dclass, i);
1934 return NULL;
1937 /* Global manipulated by virtual_base_list[_aux]() */
1939 static struct vbase *current_vbase_list = NULL;
1941 /* Return a pointer to a null-terminated list of struct vbase
1942 items. The vbasetype pointer of each item in the list points to the
1943 type information for a virtual base of the argument DCLASS.
1945 Helper function for virtual_base_list().
1946 Note: the list goes backward, right-to-left. virtual_base_list()
1947 copies the items out in reverse order. */
1949 static void
1950 virtual_base_list_aux (struct type *dclass)
1952 struct vbase *tmp_vbase;
1953 int i;
1955 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1956 return;
1958 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1960 /* Recurse on this ancestor, first */
1961 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
1963 /* If this current base is itself virtual, add it to the list */
1964 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1966 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1968 /* Check if base already recorded */
1969 tmp_vbase = current_vbase_list;
1970 while (tmp_vbase)
1972 if (tmp_vbase->vbasetype == basetype)
1973 break; /* found it */
1974 tmp_vbase = tmp_vbase->next;
1977 if (!tmp_vbase) /* normal exit from loop */
1979 /* Allocate new item for this virtual base */
1980 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
1982 /* Stick it on at the end of the list */
1983 tmp_vbase->vbasetype = basetype;
1984 tmp_vbase->next = current_vbase_list;
1985 current_vbase_list = tmp_vbase;
1987 } /* if virtual */
1988 } /* for loop over bases */
1992 /* Compute the list of virtual bases in the right order. Virtual
1993 bases are laid out in the object's memory area in order of their
1994 occurrence in a depth-first, left-to-right search through the
1995 ancestors.
1997 Argument DCLASS is the type whose virtual bases are required.
1998 Return value is the address of a null-terminated array of pointers
1999 to struct type items.
2001 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
2002 and may not work with other runtime models.
2004 This routine merely hands off the argument to virtual_base_list_aux()
2005 and then copies the result into an array to save space. */
2007 struct type **
2008 virtual_base_list (struct type *dclass)
2010 struct vbase *tmp_vbase;
2011 struct vbase *tmp_vbase_2;
2012 int i;
2013 int count;
2014 struct type **vbase_array;
2016 current_vbase_list = NULL;
2017 virtual_base_list_aux (dclass);
2019 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2020 /* no body */ ;
2022 count = i;
2024 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
2026 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
2027 vbase_array[i] = tmp_vbase->vbasetype;
2029 /* Get rid of constructed chain */
2030 tmp_vbase_2 = tmp_vbase = current_vbase_list;
2031 while (tmp_vbase)
2033 tmp_vbase = tmp_vbase->next;
2034 xfree (tmp_vbase_2);
2035 tmp_vbase_2 = tmp_vbase;
2038 vbase_array[count] = NULL;
2039 return vbase_array;
2042 /* Return the length of the virtual base list of the type DCLASS. */
2045 virtual_base_list_length (struct type *dclass)
2047 int i;
2048 struct vbase *tmp_vbase;
2050 current_vbase_list = NULL;
2051 virtual_base_list_aux (dclass);
2053 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
2054 /* no body */ ;
2055 return i;
2058 /* Return the number of elements of the virtual base list of the type
2059 DCLASS, ignoring those appearing in the primary base (and its
2060 primary base, recursively). */
2063 virtual_base_list_length_skip_primaries (struct type *dclass)
2065 int i;
2066 struct vbase *tmp_vbase;
2067 struct type *primary;
2069 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2071 if (!primary)
2072 return virtual_base_list_length (dclass);
2074 current_vbase_list = NULL;
2075 virtual_base_list_aux (dclass);
2077 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
2079 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
2080 continue;
2081 i++;
2083 return i;
2087 /* Return the index (position) of type BASE, which is a virtual base
2088 class of DCLASS, in the latter's virtual base list. A return of -1
2089 indicates "not found" or a problem. */
2092 virtual_base_index (struct type *base, struct type *dclass)
2094 struct type *vbase;
2095 int i;
2097 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2098 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2099 return -1;
2101 i = 0;
2102 vbase = virtual_base_list (dclass)[0];
2103 while (vbase)
2105 if (vbase == base)
2106 break;
2107 vbase = virtual_base_list (dclass)[++i];
2110 return vbase ? i : -1;
2115 /* Return the index (position) of type BASE, which is a virtual base
2116 class of DCLASS, in the latter's virtual base list. Skip over all
2117 bases that may appear in the virtual base list of the primary base
2118 class of DCLASS (recursively). A return of -1 indicates "not
2119 found" or a problem. */
2122 virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
2124 struct type *vbase;
2125 int i, j;
2126 struct type *primary;
2128 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2129 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2130 return -1;
2132 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2134 j = -1;
2135 i = 0;
2136 vbase = virtual_base_list (dclass)[0];
2137 while (vbase)
2139 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2140 j++;
2141 if (vbase == base)
2142 break;
2143 vbase = virtual_base_list (dclass)[++i];
2146 return vbase ? j : -1;
2149 /* Return position of a derived class DCLASS in the list of
2150 * primary bases starting with the remotest ancestor.
2151 * Position returned is 0-based. */
2154 class_index_in_primary_list (struct type *dclass)
2156 struct type *pbc; /* primary base class */
2158 /* Simply recurse on primary base */
2159 pbc = TYPE_PRIMARY_BASE (dclass);
2160 if (pbc)
2161 return 1 + class_index_in_primary_list (pbc);
2162 else
2163 return 0;
2166 /* Return a count of the number of virtual functions a type has.
2167 * This includes all the virtual functions it inherits from its
2168 * base classes too.
2171 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2172 * functions only once (latest redefinition)
2176 count_virtual_fns (struct type *dclass)
2178 int fn, oi; /* function and overloaded instance indices */
2179 int vfuncs; /* count to return */
2181 /* recurse on bases that can share virtual table */
2182 struct type *pbc = primary_base_class (dclass);
2183 if (pbc)
2184 vfuncs = count_virtual_fns (pbc);
2185 else
2186 vfuncs = 0;
2188 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2189 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2190 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2191 vfuncs++;
2193 return vfuncs;
2198 /* Functions for overload resolution begin here */
2200 /* Compare two badness vectors A and B and return the result.
2201 * 0 => A and B are identical
2202 * 1 => A and B are incomparable
2203 * 2 => A is better than B
2204 * 3 => A is worse than B */
2207 compare_badness (struct badness_vector *a, struct badness_vector *b)
2209 int i;
2210 int tmp;
2211 short found_pos = 0; /* any positives in c? */
2212 short found_neg = 0; /* any negatives in c? */
2214 /* differing lengths => incomparable */
2215 if (a->length != b->length)
2216 return 1;
2218 /* Subtract b from a */
2219 for (i = 0; i < a->length; i++)
2221 tmp = a->rank[i] - b->rank[i];
2222 if (tmp > 0)
2223 found_pos = 1;
2224 else if (tmp < 0)
2225 found_neg = 1;
2228 if (found_pos)
2230 if (found_neg)
2231 return 1; /* incomparable */
2232 else
2233 return 3; /* A > B */
2235 else
2236 /* no positives */
2238 if (found_neg)
2239 return 2; /* A < B */
2240 else
2241 return 0; /* A == B */
2245 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2246 * to the types of an argument list (ARGS, length NARGS).
2247 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2249 struct badness_vector *
2250 rank_function (struct type **parms, int nparms, struct type **args, int nargs)
2252 int i;
2253 struct badness_vector *bv;
2254 int min_len = nparms < nargs ? nparms : nargs;
2256 bv = xmalloc (sizeof (struct badness_vector));
2257 bv->length = nargs + 1; /* add 1 for the length-match rank */
2258 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2260 /* First compare the lengths of the supplied lists.
2261 * If there is a mismatch, set it to a high value. */
2263 /* pai/1997-06-03 FIXME: when we have debug info about default
2264 * arguments and ellipsis parameter lists, we should consider those
2265 * and rank the length-match more finely. */
2267 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2269 /* Now rank all the parameters of the candidate function */
2270 for (i = 1; i <= min_len; i++)
2271 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2273 /* If more arguments than parameters, add dummy entries */
2274 for (i = min_len + 1; i <= nargs; i++)
2275 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2277 return bv;
2280 /* Compare the names of two integer types, assuming that any sign
2281 qualifiers have been checked already. We do it this way because
2282 there may be an "int" in the name of one of the types. */
2284 static int
2285 integer_types_same_name_p (const char *first, const char *second)
2287 int first_p, second_p;
2289 /* If both are shorts, return 1; if neither is a short, keep checking. */
2290 first_p = (strstr (first, "short") != NULL);
2291 second_p = (strstr (second, "short") != NULL);
2292 if (first_p && second_p)
2293 return 1;
2294 if (first_p || second_p)
2295 return 0;
2297 /* Likewise for long. */
2298 first_p = (strstr (first, "long") != NULL);
2299 second_p = (strstr (second, "long") != NULL);
2300 if (first_p && second_p)
2301 return 1;
2302 if (first_p || second_p)
2303 return 0;
2305 /* Likewise for char. */
2306 first_p = (strstr (first, "char") != NULL);
2307 second_p = (strstr (second, "char") != NULL);
2308 if (first_p && second_p)
2309 return 1;
2310 if (first_p || second_p)
2311 return 0;
2313 /* They must both be ints. */
2314 return 1;
2317 /* Compare one type (PARM) for compatibility with another (ARG).
2318 * PARM is intended to be the parameter type of a function; and
2319 * ARG is the supplied argument's type. This function tests if
2320 * the latter can be converted to the former.
2322 * Return 0 if they are identical types;
2323 * Otherwise, return an integer which corresponds to how compatible
2324 * PARM is to ARG. The higher the return value, the worse the match.
2325 * Generally the "bad" conversions are all uniformly assigned a 100 */
2328 rank_one_type (struct type *parm, struct type *arg)
2330 /* Identical type pointers */
2331 /* However, this still doesn't catch all cases of same type for arg
2332 * and param. The reason is that builtin types are different from
2333 * the same ones constructed from the object. */
2334 if (parm == arg)
2335 return 0;
2337 /* Resolve typedefs */
2338 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2339 parm = check_typedef (parm);
2340 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2341 arg = check_typedef (arg);
2344 Well, damnit, if the names are exactly the same,
2345 i'll say they are exactly the same. This happens when we generate
2346 method stubs. The types won't point to the same address, but they
2347 really are the same.
2350 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2351 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2352 return 0;
2354 /* Check if identical after resolving typedefs */
2355 if (parm == arg)
2356 return 0;
2358 /* See through references, since we can almost make non-references
2359 references. */
2360 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2361 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2362 + REFERENCE_CONVERSION_BADNESS);
2363 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2364 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2365 + REFERENCE_CONVERSION_BADNESS);
2366 if (overload_debug)
2367 /* Debugging only. */
2368 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2369 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2371 /* x -> y means arg of type x being supplied for parameter of type y */
2373 switch (TYPE_CODE (parm))
2375 case TYPE_CODE_PTR:
2376 switch (TYPE_CODE (arg))
2378 case TYPE_CODE_PTR:
2379 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2380 return VOID_PTR_CONVERSION_BADNESS;
2381 else
2382 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2383 case TYPE_CODE_ARRAY:
2384 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2385 case TYPE_CODE_FUNC:
2386 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2387 case TYPE_CODE_INT:
2388 case TYPE_CODE_ENUM:
2389 case TYPE_CODE_CHAR:
2390 case TYPE_CODE_RANGE:
2391 case TYPE_CODE_BOOL:
2392 return POINTER_CONVERSION_BADNESS;
2393 default:
2394 return INCOMPATIBLE_TYPE_BADNESS;
2396 case TYPE_CODE_ARRAY:
2397 switch (TYPE_CODE (arg))
2399 case TYPE_CODE_PTR:
2400 case TYPE_CODE_ARRAY:
2401 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2402 default:
2403 return INCOMPATIBLE_TYPE_BADNESS;
2405 case TYPE_CODE_FUNC:
2406 switch (TYPE_CODE (arg))
2408 case TYPE_CODE_PTR: /* funcptr -> func */
2409 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2410 default:
2411 return INCOMPATIBLE_TYPE_BADNESS;
2413 case TYPE_CODE_INT:
2414 switch (TYPE_CODE (arg))
2416 case TYPE_CODE_INT:
2417 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2419 /* Deal with signed, unsigned, and plain chars and
2420 signed and unsigned ints */
2421 if (TYPE_NOSIGN (parm))
2423 /* This case only for character types */
2424 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2425 return 0;
2426 else
2427 return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */
2429 else if (TYPE_UNSIGNED (parm))
2431 if (TYPE_UNSIGNED (arg))
2433 /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2434 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2435 return 0;
2436 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2437 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
2438 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2439 else
2440 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
2442 else
2444 if (integer_types_same_name_p (TYPE_NAME (arg), "long")
2445 && integer_types_same_name_p (TYPE_NAME (parm), "int"))
2446 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
2447 else
2448 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2451 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2453 if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2454 return 0;
2455 else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2456 && integer_types_same_name_p (TYPE_NAME (parm), "long"))
2457 return INTEGER_PROMOTION_BADNESS;
2458 else
2459 return INTEGER_CONVERSION_BADNESS;
2461 else
2462 return INTEGER_CONVERSION_BADNESS;
2464 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2465 return INTEGER_PROMOTION_BADNESS;
2466 else
2467 return INTEGER_CONVERSION_BADNESS;
2468 case TYPE_CODE_ENUM:
2469 case TYPE_CODE_CHAR:
2470 case TYPE_CODE_RANGE:
2471 case TYPE_CODE_BOOL:
2472 return INTEGER_PROMOTION_BADNESS;
2473 case TYPE_CODE_FLT:
2474 return INT_FLOAT_CONVERSION_BADNESS;
2475 case TYPE_CODE_PTR:
2476 return NS_POINTER_CONVERSION_BADNESS;
2477 default:
2478 return INCOMPATIBLE_TYPE_BADNESS;
2480 break;
2481 case TYPE_CODE_ENUM:
2482 switch (TYPE_CODE (arg))
2484 case TYPE_CODE_INT:
2485 case TYPE_CODE_CHAR:
2486 case TYPE_CODE_RANGE:
2487 case TYPE_CODE_BOOL:
2488 case TYPE_CODE_ENUM:
2489 return INTEGER_CONVERSION_BADNESS;
2490 case TYPE_CODE_FLT:
2491 return INT_FLOAT_CONVERSION_BADNESS;
2492 default:
2493 return INCOMPATIBLE_TYPE_BADNESS;
2495 break;
2496 case TYPE_CODE_CHAR:
2497 switch (TYPE_CODE (arg))
2499 case TYPE_CODE_RANGE:
2500 case TYPE_CODE_BOOL:
2501 case TYPE_CODE_ENUM:
2502 return INTEGER_CONVERSION_BADNESS;
2503 case TYPE_CODE_FLT:
2504 return INT_FLOAT_CONVERSION_BADNESS;
2505 case TYPE_CODE_INT:
2506 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2507 return INTEGER_CONVERSION_BADNESS;
2508 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2509 return INTEGER_PROMOTION_BADNESS;
2510 /* >>> !! else fall through !! <<< */
2511 case TYPE_CODE_CHAR:
2512 /* Deal with signed, unsigned, and plain chars for C++
2513 and with int cases falling through from previous case */
2514 if (TYPE_NOSIGN (parm))
2516 if (TYPE_NOSIGN (arg))
2517 return 0;
2518 else
2519 return INTEGER_CONVERSION_BADNESS;
2521 else if (TYPE_UNSIGNED (parm))
2523 if (TYPE_UNSIGNED (arg))
2524 return 0;
2525 else
2526 return INTEGER_PROMOTION_BADNESS;
2528 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2529 return 0;
2530 else
2531 return INTEGER_CONVERSION_BADNESS;
2532 default:
2533 return INCOMPATIBLE_TYPE_BADNESS;
2535 break;
2536 case TYPE_CODE_RANGE:
2537 switch (TYPE_CODE (arg))
2539 case TYPE_CODE_INT:
2540 case TYPE_CODE_CHAR:
2541 case TYPE_CODE_RANGE:
2542 case TYPE_CODE_BOOL:
2543 case TYPE_CODE_ENUM:
2544 return INTEGER_CONVERSION_BADNESS;
2545 case TYPE_CODE_FLT:
2546 return INT_FLOAT_CONVERSION_BADNESS;
2547 default:
2548 return INCOMPATIBLE_TYPE_BADNESS;
2550 break;
2551 case TYPE_CODE_BOOL:
2552 switch (TYPE_CODE (arg))
2554 case TYPE_CODE_INT:
2555 case TYPE_CODE_CHAR:
2556 case TYPE_CODE_RANGE:
2557 case TYPE_CODE_ENUM:
2558 case TYPE_CODE_FLT:
2559 case TYPE_CODE_PTR:
2560 return BOOLEAN_CONVERSION_BADNESS;
2561 case TYPE_CODE_BOOL:
2562 return 0;
2563 default:
2564 return INCOMPATIBLE_TYPE_BADNESS;
2566 break;
2567 case TYPE_CODE_FLT:
2568 switch (TYPE_CODE (arg))
2570 case TYPE_CODE_FLT:
2571 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2572 return FLOAT_PROMOTION_BADNESS;
2573 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2574 return 0;
2575 else
2576 return FLOAT_CONVERSION_BADNESS;
2577 case TYPE_CODE_INT:
2578 case TYPE_CODE_BOOL:
2579 case TYPE_CODE_ENUM:
2580 case TYPE_CODE_RANGE:
2581 case TYPE_CODE_CHAR:
2582 return INT_FLOAT_CONVERSION_BADNESS;
2583 default:
2584 return INCOMPATIBLE_TYPE_BADNESS;
2586 break;
2587 case TYPE_CODE_COMPLEX:
2588 switch (TYPE_CODE (arg))
2589 { /* Strictly not needed for C++, but... */
2590 case TYPE_CODE_FLT:
2591 return FLOAT_PROMOTION_BADNESS;
2592 case TYPE_CODE_COMPLEX:
2593 return 0;
2594 default:
2595 return INCOMPATIBLE_TYPE_BADNESS;
2597 break;
2598 case TYPE_CODE_STRUCT:
2599 /* currently same as TYPE_CODE_CLASS */
2600 switch (TYPE_CODE (arg))
2602 case TYPE_CODE_STRUCT:
2603 /* Check for derivation */
2604 if (is_ancestor (parm, arg))
2605 return BASE_CONVERSION_BADNESS;
2606 /* else fall through */
2607 default:
2608 return INCOMPATIBLE_TYPE_BADNESS;
2610 break;
2611 case TYPE_CODE_UNION:
2612 switch (TYPE_CODE (arg))
2614 case TYPE_CODE_UNION:
2615 default:
2616 return INCOMPATIBLE_TYPE_BADNESS;
2618 break;
2619 case TYPE_CODE_MEMBER:
2620 switch (TYPE_CODE (arg))
2622 default:
2623 return INCOMPATIBLE_TYPE_BADNESS;
2625 break;
2626 case TYPE_CODE_METHOD:
2627 switch (TYPE_CODE (arg))
2630 default:
2631 return INCOMPATIBLE_TYPE_BADNESS;
2633 break;
2634 case TYPE_CODE_REF:
2635 switch (TYPE_CODE (arg))
2638 default:
2639 return INCOMPATIBLE_TYPE_BADNESS;
2642 break;
2643 case TYPE_CODE_SET:
2644 switch (TYPE_CODE (arg))
2646 /* Not in C++ */
2647 case TYPE_CODE_SET:
2648 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2649 default:
2650 return INCOMPATIBLE_TYPE_BADNESS;
2652 break;
2653 case TYPE_CODE_VOID:
2654 default:
2655 return INCOMPATIBLE_TYPE_BADNESS;
2656 } /* switch (TYPE_CODE (arg)) */
2660 /* End of functions for overload resolution */
2662 static void
2663 print_bit_vector (B_TYPE *bits, int nbits)
2665 int bitno;
2667 for (bitno = 0; bitno < nbits; bitno++)
2669 if ((bitno % 8) == 0)
2671 puts_filtered (" ");
2673 if (B_TST (bits, bitno))
2675 printf_filtered ("1");
2677 else
2679 printf_filtered ("0");
2684 /* Note the first arg should be the "this" pointer, we may not want to
2685 include it since we may get into a infinitely recursive situation. */
2687 static void
2688 print_arg_types (struct field *args, int nargs, int spaces)
2690 if (args != NULL)
2692 int i;
2694 for (i = 0; i < nargs; i++)
2695 recursive_dump_type (args[i].type, spaces + 2);
2699 static void
2700 dump_fn_fieldlists (struct type *type, int spaces)
2702 int method_idx;
2703 int overload_idx;
2704 struct fn_field *f;
2706 printfi_filtered (spaces, "fn_fieldlists ");
2707 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2708 printf_filtered ("\n");
2709 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2711 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2712 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2713 method_idx,
2714 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2715 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2716 gdb_stdout);
2717 printf_filtered (") length %d\n",
2718 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2719 for (overload_idx = 0;
2720 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2721 overload_idx++)
2723 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2724 overload_idx,
2725 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2726 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2727 gdb_stdout);
2728 printf_filtered (")\n");
2729 printfi_filtered (spaces + 8, "type ");
2730 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2731 printf_filtered ("\n");
2733 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2734 spaces + 8 + 2);
2736 printfi_filtered (spaces + 8, "args ");
2737 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2738 printf_filtered ("\n");
2740 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2741 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2742 spaces);
2743 printfi_filtered (spaces + 8, "fcontext ");
2744 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2745 gdb_stdout);
2746 printf_filtered ("\n");
2748 printfi_filtered (spaces + 8, "is_const %d\n",
2749 TYPE_FN_FIELD_CONST (f, overload_idx));
2750 printfi_filtered (spaces + 8, "is_volatile %d\n",
2751 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2752 printfi_filtered (spaces + 8, "is_private %d\n",
2753 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2754 printfi_filtered (spaces + 8, "is_protected %d\n",
2755 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2756 printfi_filtered (spaces + 8, "is_stub %d\n",
2757 TYPE_FN_FIELD_STUB (f, overload_idx));
2758 printfi_filtered (spaces + 8, "voffset %u\n",
2759 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2764 static void
2765 print_cplus_stuff (struct type *type, int spaces)
2767 printfi_filtered (spaces, "n_baseclasses %d\n",
2768 TYPE_N_BASECLASSES (type));
2769 printfi_filtered (spaces, "nfn_fields %d\n",
2770 TYPE_NFN_FIELDS (type));
2771 printfi_filtered (spaces, "nfn_fields_total %d\n",
2772 TYPE_NFN_FIELDS_TOTAL (type));
2773 if (TYPE_N_BASECLASSES (type) > 0)
2775 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2776 TYPE_N_BASECLASSES (type));
2777 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2778 printf_filtered (")");
2780 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2781 TYPE_N_BASECLASSES (type));
2782 puts_filtered ("\n");
2784 if (TYPE_NFIELDS (type) > 0)
2786 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2788 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2789 TYPE_NFIELDS (type));
2790 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2791 printf_filtered (")");
2792 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2793 TYPE_NFIELDS (type));
2794 puts_filtered ("\n");
2796 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2798 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2799 TYPE_NFIELDS (type));
2800 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2801 printf_filtered (")");
2802 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2803 TYPE_NFIELDS (type));
2804 puts_filtered ("\n");
2807 if (TYPE_NFN_FIELDS (type) > 0)
2809 dump_fn_fieldlists (type, spaces);
2813 static void
2814 print_bound_type (int bt)
2816 switch (bt)
2818 case BOUND_CANNOT_BE_DETERMINED:
2819 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2820 break;
2821 case BOUND_BY_REF_ON_STACK:
2822 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2823 break;
2824 case BOUND_BY_VALUE_ON_STACK:
2825 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2826 break;
2827 case BOUND_BY_REF_IN_REG:
2828 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2829 break;
2830 case BOUND_BY_VALUE_IN_REG:
2831 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2832 break;
2833 case BOUND_SIMPLE:
2834 printf_filtered ("(BOUND_SIMPLE)");
2835 break;
2836 default:
2837 printf_filtered ("(unknown bound type)");
2838 break;
2842 static struct obstack dont_print_type_obstack;
2844 void
2845 recursive_dump_type (struct type *type, int spaces)
2847 int idx;
2849 if (spaces == 0)
2850 obstack_begin (&dont_print_type_obstack, 0);
2852 if (TYPE_NFIELDS (type) > 0
2853 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2855 struct type **first_dont_print
2856 = (struct type **) obstack_base (&dont_print_type_obstack);
2858 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2859 - first_dont_print;
2861 while (--i >= 0)
2863 if (type == first_dont_print[i])
2865 printfi_filtered (spaces, "type node ");
2866 gdb_print_host_address (type, gdb_stdout);
2867 printf_filtered (" <same as already seen type>\n");
2868 return;
2872 obstack_ptr_grow (&dont_print_type_obstack, type);
2875 printfi_filtered (spaces, "type node ");
2876 gdb_print_host_address (type, gdb_stdout);
2877 printf_filtered ("\n");
2878 printfi_filtered (spaces, "name '%s' (",
2879 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2880 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2881 printf_filtered (")\n");
2882 printfi_filtered (spaces, "tagname '%s' (",
2883 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2884 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2885 printf_filtered (")\n");
2886 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2887 switch (TYPE_CODE (type))
2889 case TYPE_CODE_UNDEF:
2890 printf_filtered ("(TYPE_CODE_UNDEF)");
2891 break;
2892 case TYPE_CODE_PTR:
2893 printf_filtered ("(TYPE_CODE_PTR)");
2894 break;
2895 case TYPE_CODE_ARRAY:
2896 printf_filtered ("(TYPE_CODE_ARRAY)");
2897 break;
2898 case TYPE_CODE_STRUCT:
2899 printf_filtered ("(TYPE_CODE_STRUCT)");
2900 break;
2901 case TYPE_CODE_UNION:
2902 printf_filtered ("(TYPE_CODE_UNION)");
2903 break;
2904 case TYPE_CODE_ENUM:
2905 printf_filtered ("(TYPE_CODE_ENUM)");
2906 break;
2907 case TYPE_CODE_FUNC:
2908 printf_filtered ("(TYPE_CODE_FUNC)");
2909 break;
2910 case TYPE_CODE_INT:
2911 printf_filtered ("(TYPE_CODE_INT)");
2912 break;
2913 case TYPE_CODE_FLT:
2914 printf_filtered ("(TYPE_CODE_FLT)");
2915 break;
2916 case TYPE_CODE_VOID:
2917 printf_filtered ("(TYPE_CODE_VOID)");
2918 break;
2919 case TYPE_CODE_SET:
2920 printf_filtered ("(TYPE_CODE_SET)");
2921 break;
2922 case TYPE_CODE_RANGE:
2923 printf_filtered ("(TYPE_CODE_RANGE)");
2924 break;
2925 case TYPE_CODE_STRING:
2926 printf_filtered ("(TYPE_CODE_STRING)");
2927 break;
2928 case TYPE_CODE_BITSTRING:
2929 printf_filtered ("(TYPE_CODE_BITSTRING)");
2930 break;
2931 case TYPE_CODE_ERROR:
2932 printf_filtered ("(TYPE_CODE_ERROR)");
2933 break;
2934 case TYPE_CODE_MEMBER:
2935 printf_filtered ("(TYPE_CODE_MEMBER)");
2936 break;
2937 case TYPE_CODE_METHOD:
2938 printf_filtered ("(TYPE_CODE_METHOD)");
2939 break;
2940 case TYPE_CODE_REF:
2941 printf_filtered ("(TYPE_CODE_REF)");
2942 break;
2943 case TYPE_CODE_CHAR:
2944 printf_filtered ("(TYPE_CODE_CHAR)");
2945 break;
2946 case TYPE_CODE_BOOL:
2947 printf_filtered ("(TYPE_CODE_BOOL)");
2948 break;
2949 case TYPE_CODE_COMPLEX:
2950 printf_filtered ("(TYPE_CODE_COMPLEX)");
2951 break;
2952 case TYPE_CODE_TYPEDEF:
2953 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2954 break;
2955 case TYPE_CODE_TEMPLATE:
2956 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2957 break;
2958 case TYPE_CODE_TEMPLATE_ARG:
2959 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2960 break;
2961 case TYPE_CODE_NAMESPACE:
2962 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2963 break;
2964 default:
2965 printf_filtered ("(UNKNOWN TYPE CODE)");
2966 break;
2968 puts_filtered ("\n");
2969 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2970 printfi_filtered (spaces, "upper_bound_type 0x%x ",
2971 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2972 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2973 puts_filtered ("\n");
2974 printfi_filtered (spaces, "lower_bound_type 0x%x ",
2975 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2976 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2977 puts_filtered ("\n");
2978 printfi_filtered (spaces, "objfile ");
2979 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2980 printf_filtered ("\n");
2981 printfi_filtered (spaces, "target_type ");
2982 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2983 printf_filtered ("\n");
2984 if (TYPE_TARGET_TYPE (type) != NULL)
2986 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2988 printfi_filtered (spaces, "pointer_type ");
2989 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2990 printf_filtered ("\n");
2991 printfi_filtered (spaces, "reference_type ");
2992 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2993 printf_filtered ("\n");
2994 printfi_filtered (spaces, "type_chain ");
2995 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
2996 printf_filtered ("\n");
2997 printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
2998 if (TYPE_CONST (type))
3000 puts_filtered (" TYPE_FLAG_CONST");
3002 if (TYPE_VOLATILE (type))
3004 puts_filtered (" TYPE_FLAG_VOLATILE");
3006 if (TYPE_CODE_SPACE (type))
3008 puts_filtered (" TYPE_FLAG_CODE_SPACE");
3010 if (TYPE_DATA_SPACE (type))
3012 puts_filtered (" TYPE_FLAG_DATA_SPACE");
3014 if (TYPE_ADDRESS_CLASS_1 (type))
3016 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3018 if (TYPE_ADDRESS_CLASS_2 (type))
3020 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3022 puts_filtered ("\n");
3023 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
3024 if (TYPE_UNSIGNED (type))
3026 puts_filtered (" TYPE_FLAG_UNSIGNED");
3028 if (TYPE_NOSIGN (type))
3030 puts_filtered (" TYPE_FLAG_NOSIGN");
3032 if (TYPE_STUB (type))
3034 puts_filtered (" TYPE_FLAG_STUB");
3036 if (TYPE_TARGET_STUB (type))
3038 puts_filtered (" TYPE_FLAG_TARGET_STUB");
3040 if (TYPE_STATIC (type))
3042 puts_filtered (" TYPE_FLAG_STATIC");
3044 if (TYPE_PROTOTYPED (type))
3046 puts_filtered (" TYPE_FLAG_PROTOTYPED");
3048 if (TYPE_INCOMPLETE (type))
3050 puts_filtered (" TYPE_FLAG_INCOMPLETE");
3052 if (TYPE_VARARGS (type))
3054 puts_filtered (" TYPE_FLAG_VARARGS");
3056 /* This is used for things like AltiVec registers on ppc. Gcc emits
3057 an attribute for the array type, which tells whether or not we
3058 have a vector, instead of a regular array. */
3059 if (TYPE_VECTOR (type))
3061 puts_filtered (" TYPE_FLAG_VECTOR");
3063 puts_filtered ("\n");
3064 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
3065 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
3066 puts_filtered ("\n");
3067 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
3069 printfi_filtered (spaces + 2,
3070 "[%d] bitpos %d bitsize %d type ",
3071 idx, TYPE_FIELD_BITPOS (type, idx),
3072 TYPE_FIELD_BITSIZE (type, idx));
3073 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
3074 printf_filtered (" name '%s' (",
3075 TYPE_FIELD_NAME (type, idx) != NULL
3076 ? TYPE_FIELD_NAME (type, idx)
3077 : "<NULL>");
3078 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
3079 printf_filtered (")\n");
3080 if (TYPE_FIELD_TYPE (type, idx) != NULL)
3082 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
3085 printfi_filtered (spaces, "vptr_basetype ");
3086 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
3087 puts_filtered ("\n");
3088 if (TYPE_VPTR_BASETYPE (type) != NULL)
3090 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
3092 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
3093 switch (TYPE_CODE (type))
3095 case TYPE_CODE_STRUCT:
3096 printfi_filtered (spaces, "cplus_stuff ");
3097 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3098 puts_filtered ("\n");
3099 print_cplus_stuff (type, spaces);
3100 break;
3102 case TYPE_CODE_FLT:
3103 printfi_filtered (spaces, "floatformat ");
3104 if (TYPE_FLOATFORMAT (type) == NULL
3105 || TYPE_FLOATFORMAT (type)->name == NULL)
3106 puts_filtered ("(null)");
3107 else
3108 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3109 puts_filtered ("\n");
3110 break;
3112 default:
3113 /* We have to pick one of the union types to be able print and test
3114 the value. Pick cplus_struct_type, even though we know it isn't
3115 any particular one. */
3116 printfi_filtered (spaces, "type_specific ");
3117 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3118 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3120 printf_filtered (" (unknown data form)");
3122 printf_filtered ("\n");
3123 break;
3126 if (spaces == 0)
3127 obstack_free (&dont_print_type_obstack, NULL);
3130 static void build_gdbtypes (void);
3131 static void
3132 build_gdbtypes (void)
3134 builtin_type_void =
3135 init_type (TYPE_CODE_VOID, 1,
3137 "void", (struct objfile *) NULL);
3138 builtin_type_char =
3139 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3140 (TYPE_FLAG_NOSIGN
3141 | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
3142 "char", (struct objfile *) NULL);
3143 builtin_type_true_char =
3144 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3146 "true character", (struct objfile *) NULL);
3147 builtin_type_signed_char =
3148 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3150 "signed char", (struct objfile *) NULL);
3151 builtin_type_unsigned_char =
3152 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3153 TYPE_FLAG_UNSIGNED,
3154 "unsigned char", (struct objfile *) NULL);
3155 builtin_type_short =
3156 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3158 "short", (struct objfile *) NULL);
3159 builtin_type_unsigned_short =
3160 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3161 TYPE_FLAG_UNSIGNED,
3162 "unsigned short", (struct objfile *) NULL);
3163 builtin_type_int =
3164 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3166 "int", (struct objfile *) NULL);
3167 builtin_type_unsigned_int =
3168 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3169 TYPE_FLAG_UNSIGNED,
3170 "unsigned int", (struct objfile *) NULL);
3171 builtin_type_long =
3172 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3174 "long", (struct objfile *) NULL);
3175 builtin_type_unsigned_long =
3176 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3177 TYPE_FLAG_UNSIGNED,
3178 "unsigned long", (struct objfile *) NULL);
3179 builtin_type_long_long =
3180 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3182 "long long", (struct objfile *) NULL);
3183 builtin_type_unsigned_long_long =
3184 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3185 TYPE_FLAG_UNSIGNED,
3186 "unsigned long long", (struct objfile *) NULL);
3187 builtin_type_float =
3188 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3190 "float", (struct objfile *) NULL);
3191 /* vinschen@redhat.com 2002-02-08:
3192 The below lines are disabled since they are doing the wrong
3193 thing for non-multiarch targets. They are setting the correct
3194 type of floats for the target but while on multiarch targets
3195 this is done everytime the architecture changes, it's done on
3196 non-multiarch targets only on startup, leaving the wrong values
3197 in even if the architecture changes (eg. from big-endian to
3198 little-endian). */
3199 #if 0
3200 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
3201 #endif
3202 builtin_type_double =
3203 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3205 "double", (struct objfile *) NULL);
3206 #if 0
3207 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
3208 #endif
3209 builtin_type_long_double =
3210 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3212 "long double", (struct objfile *) NULL);
3213 #if 0
3214 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
3215 #endif
3216 builtin_type_complex =
3217 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3219 "complex", (struct objfile *) NULL);
3220 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3221 builtin_type_double_complex =
3222 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3224 "double complex", (struct objfile *) NULL);
3225 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3226 builtin_type_string =
3227 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3229 "string", (struct objfile *) NULL);
3230 builtin_type_int0 =
3231 init_type (TYPE_CODE_INT, 0 / 8,
3233 "int0_t", (struct objfile *) NULL);
3234 builtin_type_int8 =
3235 init_type (TYPE_CODE_INT, 8 / 8,
3237 "int8_t", (struct objfile *) NULL);
3238 builtin_type_uint8 =
3239 init_type (TYPE_CODE_INT, 8 / 8,
3240 TYPE_FLAG_UNSIGNED,
3241 "uint8_t", (struct objfile *) NULL);
3242 builtin_type_int16 =
3243 init_type (TYPE_CODE_INT, 16 / 8,
3245 "int16_t", (struct objfile *) NULL);
3246 builtin_type_uint16 =
3247 init_type (TYPE_CODE_INT, 16 / 8,
3248 TYPE_FLAG_UNSIGNED,
3249 "uint16_t", (struct objfile *) NULL);
3250 builtin_type_int32 =
3251 init_type (TYPE_CODE_INT, 32 / 8,
3253 "int32_t", (struct objfile *) NULL);
3254 builtin_type_uint32 =
3255 init_type (TYPE_CODE_INT, 32 / 8,
3256 TYPE_FLAG_UNSIGNED,
3257 "uint32_t", (struct objfile *) NULL);
3258 builtin_type_int64 =
3259 init_type (TYPE_CODE_INT, 64 / 8,
3261 "int64_t", (struct objfile *) NULL);
3262 builtin_type_uint64 =
3263 init_type (TYPE_CODE_INT, 64 / 8,
3264 TYPE_FLAG_UNSIGNED,
3265 "uint64_t", (struct objfile *) NULL);
3266 builtin_type_int128 =
3267 init_type (TYPE_CODE_INT, 128 / 8,
3269 "int128_t", (struct objfile *) NULL);
3270 builtin_type_uint128 =
3271 init_type (TYPE_CODE_INT, 128 / 8,
3272 TYPE_FLAG_UNSIGNED,
3273 "uint128_t", (struct objfile *) NULL);
3274 builtin_type_bool =
3275 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3277 "bool", (struct objfile *) NULL);
3279 /* Add user knob for controlling resolution of opaque types */
3280 add_show_from_set
3281 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
3282 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3283 &setlist),
3284 &showlist);
3285 opaque_type_resolution = 1;
3287 /* Build SIMD types. */
3288 builtin_type_v4sf
3289 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
3290 builtin_type_v4si
3291 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
3292 builtin_type_v16qi
3293 = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
3294 builtin_type_v8qi
3295 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
3296 builtin_type_v8hi
3297 = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
3298 builtin_type_v4hi
3299 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3300 builtin_type_v2si
3301 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
3303 /* 128 bit vectors. */
3304 builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
3305 builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3306 builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
3307 builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3308 builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3309 builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3310 /* 64 bit vectors. */
3311 builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
3312 builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3313 builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3314 builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
3316 /* Vector types. */
3317 builtin_type_vec64 = build_builtin_type_vec64 ();
3318 builtin_type_vec64i = build_builtin_type_vec64i ();
3319 builtin_type_vec128 = build_builtin_type_vec128 ();
3320 builtin_type_vec128i = build_builtin_type_vec128i ();
3322 /* Pointer/Address types. */
3324 /* NOTE: on some targets, addresses and pointers are not necessarily
3325 the same --- for example, on the D10V, pointers are 16 bits long,
3326 but addresses are 32 bits long. See doc/gdbint.texinfo,
3327 ``Pointers Are Not Always Addresses''.
3329 The upshot is:
3330 - gdb's `struct type' always describes the target's
3331 representation.
3332 - gdb's `struct value' objects should always hold values in
3333 target form.
3334 - gdb's CORE_ADDR values are addresses in the unified virtual
3335 address space that the assembler and linker work with. Thus,
3336 since target_read_memory takes a CORE_ADDR as an argument, it
3337 can access any memory on the target, even if the processor has
3338 separate code and data address spaces.
3340 So, for example:
3341 - If v is a value holding a D10V code pointer, its contents are
3342 in target form: a big-endian address left-shifted two bits.
3343 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3344 sizeof (void *) == 2 on the target.
3346 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3347 target type for a value the target will never see. It's only
3348 used to hold the values of (typeless) linker symbols, which are
3349 indeed in the unified virtual address space. */
3350 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
3351 builtin_type_void_func_ptr
3352 = lookup_pointer_type (lookup_function_type (builtin_type_void));
3353 builtin_type_CORE_ADDR =
3354 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
3355 TYPE_FLAG_UNSIGNED,
3356 "__CORE_ADDR", (struct objfile *) NULL);
3357 builtin_type_bfd_vma =
3358 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3359 TYPE_FLAG_UNSIGNED,
3360 "__bfd_vma", (struct objfile *) NULL);
3363 extern void _initialize_gdbtypes (void);
3364 void
3365 _initialize_gdbtypes (void)
3367 struct cmd_list_element *c;
3368 build_gdbtypes ();
3370 /* FIXME - For the moment, handle types by swapping them in and out.
3371 Should be using the per-architecture data-pointer and a large
3372 struct. */
3373 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void);
3374 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char);
3375 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short);
3376 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int);
3377 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long);
3378 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long);
3379 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char);
3380 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char);
3381 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short);
3382 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int);
3383 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long);
3384 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long);
3385 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float);
3386 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double);
3387 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double);
3388 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex);
3389 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex);
3390 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string);
3391 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int8);
3392 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint8);
3393 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int16);
3394 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint16);
3395 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int32);
3396 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint32);
3397 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int64);
3398 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint64);
3399 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int128);
3400 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint128);
3401 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf);
3402 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si);
3403 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi);
3404 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi);
3405 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi);
3406 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi);
3407 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si);
3408 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double);
3409 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float);
3410 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64);
3411 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32);
3412 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16);
3413 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8);
3414 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float);
3415 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32);
3416 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8);
3417 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16);
3418 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128);
3419 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128i);
3420 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3421 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3422 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3423 DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3424 deprecated_register_gdbarch_swap (NULL, 0, build_gdbtypes);
3426 /* Note: These types do not need to be swapped - they are target
3427 neutral. */
3428 builtin_type_ieee_single_big =
3429 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3430 0, "builtin_type_ieee_single_big", NULL);
3431 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3432 builtin_type_ieee_single_little =
3433 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3434 0, "builtin_type_ieee_single_little", NULL);
3435 TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
3436 builtin_type_ieee_double_big =
3437 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3438 0, "builtin_type_ieee_double_big", NULL);
3439 TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
3440 builtin_type_ieee_double_little =
3441 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3442 0, "builtin_type_ieee_double_little", NULL);
3443 TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
3444 builtin_type_ieee_double_littlebyte_bigword =
3445 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3446 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
3447 TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
3448 builtin_type_i387_ext =
3449 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3450 0, "builtin_type_i387_ext", NULL);
3451 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
3452 builtin_type_m68881_ext =
3453 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3454 0, "builtin_type_m68881_ext", NULL);
3455 TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
3456 builtin_type_i960_ext =
3457 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3458 0, "builtin_type_i960_ext", NULL);
3459 TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
3460 builtin_type_m88110_ext =
3461 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3462 0, "builtin_type_m88110_ext", NULL);
3463 TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
3464 builtin_type_m88110_harris_ext =
3465 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3466 0, "builtin_type_m88110_harris_ext", NULL);
3467 TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
3468 builtin_type_arm_ext_big =
3469 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3470 0, "builtin_type_arm_ext_big", NULL);
3471 TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
3472 builtin_type_arm_ext_littlebyte_bigword =
3473 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3474 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
3475 TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
3476 builtin_type_ia64_spill_big =
3477 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3478 0, "builtin_type_ia64_spill_big", NULL);
3479 TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
3480 builtin_type_ia64_spill_little =
3481 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3482 0, "builtin_type_ia64_spill_little", NULL);
3483 TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
3484 builtin_type_ia64_quad_big =
3485 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3486 0, "builtin_type_ia64_quad_big", NULL);
3487 TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
3488 builtin_type_ia64_quad_little =
3489 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3490 0, "builtin_type_ia64_quad_little", NULL);
3491 TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
3493 add_show_from_set (
3494 add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
3495 "Set debugging of C++ overloading.\n\
3496 When enabled, ranking of the functions\n\
3497 is displayed.", &setdebuglist),
3498 &showdebuglist);