* solib-svr4.c (IGNORE_FIRST_LINK_MAP_ENTRY): Avoid dereferencing
[binutils-gdb.git] / gdb / gdbtypes.c
blob005a29d1dad332c2bcd3c7c6ed71fea580354f8a
1 /* Support routines for manipulating internal types for GDB.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 Contributed by Cygnus Support, using pieces from other GDB modules.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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"
40 #include "hashtab.h"
42 /* These variables point to the objects
43 representing the predefined C data types. */
45 struct type *builtin_type_int0;
46 struct type *builtin_type_int8;
47 struct type *builtin_type_uint8;
48 struct type *builtin_type_int16;
49 struct type *builtin_type_uint16;
50 struct type *builtin_type_int32;
51 struct type *builtin_type_uint32;
52 struct type *builtin_type_int64;
53 struct type *builtin_type_uint64;
54 struct type *builtin_type_int128;
55 struct type *builtin_type_uint128;
57 /* Floatformat pairs. */
58 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
59 &floatformat_ieee_single_big,
60 &floatformat_ieee_single_little
62 const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
63 &floatformat_ieee_double_big,
64 &floatformat_ieee_double_little
66 const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
67 &floatformat_ieee_double_big,
68 &floatformat_ieee_double_littlebyte_bigword
70 const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
71 &floatformat_i387_ext,
72 &floatformat_i387_ext
74 const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
75 &floatformat_m68881_ext,
76 &floatformat_m68881_ext
78 const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
79 &floatformat_arm_ext_big,
80 &floatformat_arm_ext_littlebyte_bigword
82 const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
83 &floatformat_ia64_spill_big,
84 &floatformat_ia64_spill_little
86 const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
87 &floatformat_ia64_quad_big,
88 &floatformat_ia64_quad_little
90 const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
91 &floatformat_vax_f,
92 &floatformat_vax_f
94 const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
95 &floatformat_vax_d,
96 &floatformat_vax_d
98 const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
99 &floatformat_ibm_long_double,
100 &floatformat_ibm_long_double
103 struct type *builtin_type_ieee_single;
104 struct type *builtin_type_ieee_double;
105 struct type *builtin_type_i387_ext;
106 struct type *builtin_type_m68881_ext;
107 struct type *builtin_type_arm_ext;
108 struct type *builtin_type_ia64_spill;
109 struct type *builtin_type_ia64_quad;
111 /* Platform-neutral void type. */
112 struct type *builtin_type_void;
114 /* Platform-neutral character types. */
115 struct type *builtin_type_true_char;
116 struct type *builtin_type_true_unsigned_char;
119 int opaque_type_resolution = 1;
120 static void
121 show_opaque_type_resolution (struct ui_file *file, int from_tty,
122 struct cmd_list_element *c,
123 const char *value)
125 fprintf_filtered (file, _("\
126 Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
127 value);
130 int overload_debug = 0;
131 static void
132 show_overload_debug (struct ui_file *file, int from_tty,
133 struct cmd_list_element *c, const char *value)
135 fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
136 value);
139 struct extra
141 char str[128];
142 int len;
143 }; /* Maximum extension is 128! FIXME */
145 static void print_bit_vector (B_TYPE *, int);
146 static void print_arg_types (struct field *, int, int);
147 static void dump_fn_fieldlists (struct type *, int);
148 static void print_cplus_stuff (struct type *, int);
151 /* Alloc a new type structure and fill it with some defaults. If
152 OBJFILE is non-NULL, then allocate the space for the type structure
153 in that objfile's objfile_obstack. Otherwise allocate the new type
154 structure by xmalloc () (for permanent types). */
156 struct type *
157 alloc_type (struct objfile *objfile)
159 struct type *type;
161 /* Alloc the structure and start off with all fields zeroed. */
163 if (objfile == NULL)
165 type = XZALLOC (struct type);
166 TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
168 else
170 type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
171 TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
172 struct main_type);
173 OBJSTAT (objfile, n_types++);
176 /* Initialize the fields that might not be zero. */
178 TYPE_CODE (type) = TYPE_CODE_UNDEF;
179 TYPE_OBJFILE (type) = objfile;
180 TYPE_VPTR_FIELDNO (type) = -1;
181 TYPE_CHAIN (type) = type; /* Chain back to itself. */
183 return type;
186 /* Alloc a new type instance structure, fill it with some defaults,
187 and point it at OLDTYPE. Allocate the new type instance from the
188 same place as OLDTYPE. */
190 static struct type *
191 alloc_type_instance (struct type *oldtype)
193 struct type *type;
195 /* Allocate the structure. */
197 if (TYPE_OBJFILE (oldtype) == NULL)
198 type = XZALLOC (struct type);
199 else
200 type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
201 struct type);
203 TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
205 TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
207 return type;
210 /* Clear all remnants of the previous type at TYPE, in preparation for
211 replacing it with something else. */
212 static void
213 smash_type (struct type *type)
215 memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
217 /* For now, delete the rings. */
218 TYPE_CHAIN (type) = type;
220 /* For now, leave the pointer/reference types alone. */
223 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
224 to a pointer to memory where the pointer type should be stored.
225 If *TYPEPTR is zero, update it to point to the pointer type we return.
226 We allocate new memory if needed. */
228 struct type *
229 make_pointer_type (struct type *type, struct type **typeptr)
231 struct type *ntype; /* New type */
232 struct objfile *objfile;
233 struct type *chain;
235 ntype = TYPE_POINTER_TYPE (type);
237 if (ntype)
239 if (typeptr == 0)
240 return ntype; /* Don't care about alloc,
241 and have new type. */
242 else if (*typeptr == 0)
244 *typeptr = ntype; /* Tracking alloc, and have new type. */
245 return ntype;
249 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
251 ntype = alloc_type (TYPE_OBJFILE (type));
252 if (typeptr)
253 *typeptr = ntype;
255 else /* We have storage, but need to reset it. */
257 ntype = *typeptr;
258 objfile = TYPE_OBJFILE (ntype);
259 chain = TYPE_CHAIN (ntype);
260 smash_type (ntype);
261 TYPE_CHAIN (ntype) = chain;
262 TYPE_OBJFILE (ntype) = objfile;
265 TYPE_TARGET_TYPE (ntype) = type;
266 TYPE_POINTER_TYPE (type) = ntype;
268 /* FIXME! Assume the machine has only one representation for
269 pointers! */
271 TYPE_LENGTH (ntype) =
272 gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
273 TYPE_CODE (ntype) = TYPE_CODE_PTR;
275 /* Mark pointers as unsigned. The target converts between pointers
276 and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
277 gdbarch_address_to_pointer. */
278 TYPE_UNSIGNED (ntype) = 1;
280 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
281 TYPE_POINTER_TYPE (type) = ntype;
283 /* Update the length of all the other variants of this type. */
284 chain = TYPE_CHAIN (ntype);
285 while (chain != ntype)
287 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
288 chain = TYPE_CHAIN (chain);
291 return ntype;
294 /* Given a type TYPE, return a type of pointers to that type.
295 May need to construct such a type if this is the first use. */
297 struct type *
298 lookup_pointer_type (struct type *type)
300 return make_pointer_type (type, (struct type **) 0);
303 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
304 points to a pointer to memory where the reference type should be
305 stored. If *TYPEPTR is zero, update it to point to the reference
306 type we return. We allocate new memory if needed. */
308 struct type *
309 make_reference_type (struct type *type, struct type **typeptr)
311 struct type *ntype; /* New type */
312 struct objfile *objfile;
313 struct type *chain;
315 ntype = TYPE_REFERENCE_TYPE (type);
317 if (ntype)
319 if (typeptr == 0)
320 return ntype; /* Don't care about alloc,
321 and have new type. */
322 else if (*typeptr == 0)
324 *typeptr = ntype; /* Tracking alloc, and have new type. */
325 return ntype;
329 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
331 ntype = alloc_type (TYPE_OBJFILE (type));
332 if (typeptr)
333 *typeptr = ntype;
335 else /* We have storage, but need to reset it. */
337 ntype = *typeptr;
338 objfile = TYPE_OBJFILE (ntype);
339 chain = TYPE_CHAIN (ntype);
340 smash_type (ntype);
341 TYPE_CHAIN (ntype) = chain;
342 TYPE_OBJFILE (ntype) = objfile;
345 TYPE_TARGET_TYPE (ntype) = type;
346 TYPE_REFERENCE_TYPE (type) = ntype;
348 /* FIXME! Assume the machine has only one representation for
349 references, and that it matches the (only) representation for
350 pointers! */
352 TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
353 TYPE_CODE (ntype) = TYPE_CODE_REF;
355 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
356 TYPE_REFERENCE_TYPE (type) = ntype;
358 /* Update the length of all the other variants of this type. */
359 chain = TYPE_CHAIN (ntype);
360 while (chain != ntype)
362 TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
363 chain = TYPE_CHAIN (chain);
366 return ntype;
369 /* Same as above, but caller doesn't care about memory allocation
370 details. */
372 struct type *
373 lookup_reference_type (struct type *type)
375 return make_reference_type (type, (struct type **) 0);
378 /* Lookup a function type that returns type TYPE. TYPEPTR, if
379 nonzero, points to a pointer to memory where the function type
380 should be stored. If *TYPEPTR is zero, update it to point to the
381 function type we return. We allocate new memory from OBJFILE if needed; use
382 NULL for permanent types. */
384 struct type *
385 make_function_type (struct type *type, struct type **typeptr,
386 struct objfile *objfile)
388 struct type *ntype; /* New type */
390 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
392 ntype = alloc_type (objfile);
393 if (typeptr)
394 *typeptr = ntype;
396 else /* We have storage, but need to reset it. */
398 ntype = *typeptr;
399 smash_type (ntype);
400 TYPE_OBJFILE (ntype) = objfile;
403 TYPE_TARGET_TYPE (ntype) = type;
405 TYPE_LENGTH (ntype) = 1;
406 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
408 return ntype;
412 /* Given a type TYPE, return a type of functions that return that type.
413 May need to construct such a type if this is the first use. */
415 struct type *
416 lookup_function_type (struct type *type)
418 return make_function_type (type, (struct type **) 0, TYPE_OBJFILE (type));
421 /* Identify address space identifier by name --
422 return the integer flag defined in gdbtypes.h. */
423 extern int
424 address_space_name_to_int (char *space_identifier)
426 struct gdbarch *gdbarch = current_gdbarch;
427 int type_flags;
428 /* Check for known address space delimiters. */
429 if (!strcmp (space_identifier, "code"))
430 return TYPE_INSTANCE_FLAG_CODE_SPACE;
431 else if (!strcmp (space_identifier, "data"))
432 return TYPE_INSTANCE_FLAG_DATA_SPACE;
433 else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
434 && gdbarch_address_class_name_to_type_flags (gdbarch,
435 space_identifier,
436 &type_flags))
437 return type_flags;
438 else
439 error (_("Unknown address space specifier: \"%s\""), space_identifier);
442 /* Identify address space identifier by integer flag as defined in
443 gdbtypes.h -- return the string version of the adress space name. */
445 const char *
446 address_space_int_to_name (int space_flag)
448 struct gdbarch *gdbarch = current_gdbarch;
449 if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE)
450 return "code";
451 else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE)
452 return "data";
453 else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
454 && gdbarch_address_class_type_flags_to_name_p (gdbarch))
455 return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
456 else
457 return NULL;
460 /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
462 If STORAGE is non-NULL, create the new type instance there.
463 STORAGE must be in the same obstack as TYPE. */
465 static struct type *
466 make_qualified_type (struct type *type, int new_flags,
467 struct type *storage)
469 struct type *ntype;
471 ntype = type;
474 if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
475 return ntype;
476 ntype = TYPE_CHAIN (ntype);
478 while (ntype != type);
480 /* Create a new type instance. */
481 if (storage == NULL)
482 ntype = alloc_type_instance (type);
483 else
485 /* If STORAGE was provided, it had better be in the same objfile
486 as TYPE. Otherwise, we can't link it into TYPE's cv chain:
487 if one objfile is freed and the other kept, we'd have
488 dangling pointers. */
489 gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
491 ntype = storage;
492 TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
493 TYPE_CHAIN (ntype) = ntype;
496 /* Pointers or references to the original type are not relevant to
497 the new type. */
498 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
499 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
501 /* Chain the new qualified type to the old type. */
502 TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
503 TYPE_CHAIN (type) = ntype;
505 /* Now set the instance flags and return the new type. */
506 TYPE_INSTANCE_FLAGS (ntype) = new_flags;
508 /* Set length of new type to that of the original type. */
509 TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
511 return ntype;
514 /* Make an address-space-delimited variant of a type -- a type that
515 is identical to the one supplied except that it has an address
516 space attribute attached to it (such as "code" or "data").
518 The space attributes "code" and "data" are for Harvard
519 architectures. The address space attributes are for architectures
520 which have alternately sized pointers or pointers with alternate
521 representations. */
523 struct type *
524 make_type_with_address_space (struct type *type, int space_flag)
526 struct type *ntype;
527 int new_flags = ((TYPE_INSTANCE_FLAGS (type)
528 & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
529 | TYPE_INSTANCE_FLAG_DATA_SPACE
530 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL))
531 | space_flag);
533 return make_qualified_type (type, new_flags, NULL);
536 /* Make a "c-v" variant of a type -- a type that is identical to the
537 one supplied except that it may have const or volatile attributes
538 CNST is a flag for setting the const attribute
539 VOLTL is a flag for setting the volatile attribute
540 TYPE is the base type whose variant we are creating.
542 If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
543 storage to hold the new qualified type; *TYPEPTR and TYPE must be
544 in the same objfile. Otherwise, allocate fresh memory for the new
545 type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
546 new type we construct. */
547 struct type *
548 make_cv_type (int cnst, int voltl,
549 struct type *type,
550 struct type **typeptr)
552 struct type *ntype; /* New type */
553 struct type *tmp_type = type; /* tmp type */
554 struct objfile *objfile;
556 int new_flags = (TYPE_INSTANCE_FLAGS (type)
557 & ~(TYPE_INSTANCE_FLAG_CONST | TYPE_INSTANCE_FLAG_VOLATILE));
559 if (cnst)
560 new_flags |= TYPE_INSTANCE_FLAG_CONST;
562 if (voltl)
563 new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
565 if (typeptr && *typeptr != NULL)
567 /* TYPE and *TYPEPTR must be in the same objfile. We can't have
568 a C-V variant chain that threads across objfiles: if one
569 objfile gets freed, then the other has a broken C-V chain.
571 This code used to try to copy over the main type from TYPE to
572 *TYPEPTR if they were in different objfiles, but that's
573 wrong, too: TYPE may have a field list or member function
574 lists, which refer to types of their own, etc. etc. The
575 whole shebang would need to be copied over recursively; you
576 can't have inter-objfile pointers. The only thing to do is
577 to leave stub types as stub types, and look them up afresh by
578 name each time you encounter them. */
579 gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
582 ntype = make_qualified_type (type, new_flags,
583 typeptr ? *typeptr : NULL);
585 if (typeptr != NULL)
586 *typeptr = ntype;
588 return ntype;
591 /* Replace the contents of ntype with the type *type. This changes the
592 contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
593 the changes are propogated to all types in the TYPE_CHAIN.
595 In order to build recursive types, it's inevitable that we'll need
596 to update types in place --- but this sort of indiscriminate
597 smashing is ugly, and needs to be replaced with something more
598 controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
599 clear if more steps are needed. */
600 void
601 replace_type (struct type *ntype, struct type *type)
603 struct type *chain;
605 /* These two types had better be in the same objfile. Otherwise,
606 the assignment of one type's main type structure to the other
607 will produce a type with references to objects (names; field
608 lists; etc.) allocated on an objfile other than its own. */
609 gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
611 *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
613 /* The type length is not a part of the main type. Update it for
614 each type on the variant chain. */
615 chain = ntype;
618 /* Assert that this element of the chain has no address-class bits
619 set in its flags. Such type variants might have type lengths
620 which are supposed to be different from the non-address-class
621 variants. This assertion shouldn't ever be triggered because
622 symbol readers which do construct address-class variants don't
623 call replace_type(). */
624 gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
626 TYPE_LENGTH (chain) = TYPE_LENGTH (type);
627 chain = TYPE_CHAIN (chain);
629 while (ntype != chain);
631 /* Assert that the two types have equivalent instance qualifiers.
632 This should be true for at least all of our debug readers. */
633 gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
636 /* Implement direct support for MEMBER_TYPE in GNU C++.
637 May need to construct such a type if this is the first use.
638 The TYPE is the type of the member. The DOMAIN is the type
639 of the aggregate that the member belongs to. */
641 struct type *
642 lookup_memberptr_type (struct type *type, struct type *domain)
644 struct type *mtype;
646 mtype = alloc_type (TYPE_OBJFILE (type));
647 smash_to_memberptr_type (mtype, domain, type);
648 return mtype;
651 /* Return a pointer-to-method type, for a method of type TO_TYPE. */
653 struct type *
654 lookup_methodptr_type (struct type *to_type)
656 struct type *mtype;
658 mtype = alloc_type (TYPE_OBJFILE (to_type));
659 TYPE_TARGET_TYPE (mtype) = to_type;
660 TYPE_DOMAIN_TYPE (mtype) = TYPE_DOMAIN_TYPE (to_type);
661 TYPE_LENGTH (mtype) = cplus_method_ptr_size (to_type);
662 TYPE_CODE (mtype) = TYPE_CODE_METHODPTR;
663 return mtype;
666 /* Allocate a stub method whose return type is TYPE. This apparently
667 happens for speed of symbol reading, since parsing out the
668 arguments to the method is cpu-intensive, the way we are doing it.
669 So, we will fill in arguments later. This always returns a fresh
670 type. */
672 struct type *
673 allocate_stub_method (struct type *type)
675 struct type *mtype;
677 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
678 TYPE_OBJFILE (type));
679 TYPE_TARGET_TYPE (mtype) = type;
680 /* _DOMAIN_TYPE (mtype) = unknown yet */
681 return mtype;
684 /* Create a range type using either a blank type supplied in
685 RESULT_TYPE, or creating a new type, inheriting the objfile from
686 INDEX_TYPE.
688 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
689 to HIGH_BOUND, inclusive.
691 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
692 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
694 struct type *
695 create_range_type (struct type *result_type, struct type *index_type,
696 int low_bound, int high_bound)
698 if (result_type == NULL)
699 result_type = alloc_type (TYPE_OBJFILE (index_type));
700 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
701 TYPE_TARGET_TYPE (result_type) = index_type;
702 if (TYPE_STUB (index_type))
703 TYPE_TARGET_STUB (result_type) = 1;
704 else
705 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
706 TYPE_NFIELDS (result_type) = 2;
707 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
708 TYPE_NFIELDS (result_type)
709 * sizeof (struct field));
710 TYPE_LOW_BOUND (result_type) = low_bound;
711 TYPE_HIGH_BOUND (result_type) = high_bound;
713 if (low_bound >= 0)
714 TYPE_UNSIGNED (result_type) = 1;
716 return result_type;
719 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
720 TYPE. Return 1 if type is a range type, 0 if it is discrete (and
721 bounds will fit in LONGEST), or -1 otherwise. */
724 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
726 CHECK_TYPEDEF (type);
727 switch (TYPE_CODE (type))
729 case TYPE_CODE_RANGE:
730 *lowp = TYPE_LOW_BOUND (type);
731 *highp = TYPE_HIGH_BOUND (type);
732 return 1;
733 case TYPE_CODE_ENUM:
734 if (TYPE_NFIELDS (type) > 0)
736 /* The enums may not be sorted by value, so search all
737 entries */
738 int i;
740 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
741 for (i = 0; i < TYPE_NFIELDS (type); i++)
743 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
744 *lowp = TYPE_FIELD_BITPOS (type, i);
745 if (TYPE_FIELD_BITPOS (type, i) > *highp)
746 *highp = TYPE_FIELD_BITPOS (type, i);
749 /* Set unsigned indicator if warranted. */
750 if (*lowp >= 0)
752 TYPE_UNSIGNED (type) = 1;
755 else
757 *lowp = 0;
758 *highp = -1;
760 return 0;
761 case TYPE_CODE_BOOL:
762 *lowp = 0;
763 *highp = 1;
764 return 0;
765 case TYPE_CODE_INT:
766 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
767 return -1;
768 if (!TYPE_UNSIGNED (type))
770 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
771 *highp = -*lowp - 1;
772 return 0;
774 /* ... fall through for unsigned ints ... */
775 case TYPE_CODE_CHAR:
776 *lowp = 0;
777 /* This round-about calculation is to avoid shifting by
778 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
779 if TYPE_LENGTH (type) == sizeof (LONGEST). */
780 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
781 *highp = (*highp - 1) | *highp;
782 return 0;
783 default:
784 return -1;
788 /* Create an array type using either a blank type supplied in
789 RESULT_TYPE, or creating a new type, inheriting the objfile from
790 RANGE_TYPE.
792 Elements will be of type ELEMENT_TYPE, the indices will be of type
793 RANGE_TYPE.
795 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
796 sure it is TYPE_CODE_UNDEF before we bash it into an array
797 type? */
799 struct type *
800 create_array_type (struct type *result_type,
801 struct type *element_type,
802 struct type *range_type)
804 LONGEST low_bound, high_bound;
806 if (result_type == NULL)
808 result_type = alloc_type (TYPE_OBJFILE (range_type));
810 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
811 TYPE_TARGET_TYPE (result_type) = element_type;
812 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
813 low_bound = high_bound = 0;
814 CHECK_TYPEDEF (element_type);
815 /* Be careful when setting the array length. Ada arrays can be
816 empty arrays with the high_bound being smaller than the low_bound.
817 In such cases, the array length should be zero. */
818 if (high_bound < low_bound)
819 TYPE_LENGTH (result_type) = 0;
820 else
821 TYPE_LENGTH (result_type) =
822 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
823 TYPE_NFIELDS (result_type) = 1;
824 TYPE_FIELDS (result_type) =
825 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
826 TYPE_INDEX_TYPE (result_type) = range_type;
827 TYPE_VPTR_FIELDNO (result_type) = -1;
829 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
830 if (TYPE_LENGTH (result_type) == 0)
831 TYPE_TARGET_STUB (result_type) = 1;
833 return result_type;
836 /* Create a string type using either a blank type supplied in
837 RESULT_TYPE, or creating a new type. String types are similar
838 enough to array of char types that we can use create_array_type to
839 build the basic type and then bash it into a string type.
841 For fixed length strings, the range type contains 0 as the lower
842 bound and the length of the string minus one as the upper bound.
844 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
845 sure it is TYPE_CODE_UNDEF before we bash it into a string
846 type? */
848 struct type *
849 create_string_type (struct type *result_type,
850 struct type *string_char_type,
851 struct type *range_type)
853 result_type = create_array_type (result_type,
854 string_char_type,
855 range_type);
856 TYPE_CODE (result_type) = TYPE_CODE_STRING;
857 return result_type;
860 struct type *
861 create_set_type (struct type *result_type, struct type *domain_type)
863 if (result_type == NULL)
865 result_type = alloc_type (TYPE_OBJFILE (domain_type));
867 TYPE_CODE (result_type) = TYPE_CODE_SET;
868 TYPE_NFIELDS (result_type) = 1;
869 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
871 if (!TYPE_STUB (domain_type))
873 LONGEST low_bound, high_bound, bit_length;
874 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
875 low_bound = high_bound = 0;
876 bit_length = high_bound - low_bound + 1;
877 TYPE_LENGTH (result_type)
878 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
879 if (low_bound >= 0)
880 TYPE_UNSIGNED (result_type) = 1;
882 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
884 return result_type;
887 void
888 append_flags_type_flag (struct type *type, int bitpos, char *name)
890 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
891 gdb_assert (bitpos < TYPE_NFIELDS (type));
892 gdb_assert (bitpos >= 0);
894 if (name)
896 TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
897 TYPE_FIELD_BITPOS (type, bitpos) = bitpos;
899 else
901 /* Don't show this field to the user. */
902 TYPE_FIELD_BITPOS (type, bitpos) = -1;
906 struct type *
907 init_flags_type (char *name, int length)
909 int nfields = length * TARGET_CHAR_BIT;
910 struct type *type;
912 type = init_type (TYPE_CODE_FLAGS, length,
913 TYPE_FLAG_UNSIGNED, name, NULL);
914 TYPE_NFIELDS (type) = nfields;
915 TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
917 return type;
920 /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
921 and any array types nested inside it. */
923 void
924 make_vector_type (struct type *array_type)
926 struct type *inner_array, *elt_type;
927 int flags;
929 /* Find the innermost array type, in case the array is
930 multi-dimensional. */
931 inner_array = array_type;
932 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
933 inner_array = TYPE_TARGET_TYPE (inner_array);
935 elt_type = TYPE_TARGET_TYPE (inner_array);
936 if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
938 flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_FLAG_NOTTEXT;
939 elt_type = make_qualified_type (elt_type, flags, NULL);
940 TYPE_TARGET_TYPE (inner_array) = elt_type;
943 TYPE_VECTOR (array_type) = 1;
946 struct type *
947 init_vector_type (struct type *elt_type, int n)
949 struct type *array_type;
951 array_type = create_array_type (0, elt_type,
952 create_range_type (0,
953 builtin_type_int32,
954 0, n-1));
955 make_vector_type (array_type);
956 return array_type;
959 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
960 TO_TYPE. A member pointer is a wierd thing -- it amounts to a
961 typed offset into a struct, e.g. "an int at offset 8". A MEMBER
962 TYPE doesn't include the offset (that's the value of the MEMBER
963 itself), but does include the structure type into which it points
964 (for some reason).
966 When "smashing" the type, we preserve the objfile that the old type
967 pointed to, since we aren't changing where the type is actually
968 allocated. */
970 void
971 smash_to_memberptr_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 /* Assume that a data member pointer is the same size as a normal
983 pointer. */
984 TYPE_LENGTH (type) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
985 TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
988 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
989 METHOD just means `function that gets an extra "this" argument'.
991 When "smashing" the type, we preserve the objfile that the old type
992 pointed to, since we aren't changing where the type is actually
993 allocated. */
995 void
996 smash_to_method_type (struct type *type, struct type *domain,
997 struct type *to_type, struct field *args,
998 int nargs, int varargs)
1000 struct objfile *objfile;
1002 objfile = TYPE_OBJFILE (type);
1004 smash_type (type);
1005 TYPE_OBJFILE (type) = objfile;
1006 TYPE_TARGET_TYPE (type) = to_type;
1007 TYPE_DOMAIN_TYPE (type) = domain;
1008 TYPE_FIELDS (type) = args;
1009 TYPE_NFIELDS (type) = nargs;
1010 if (varargs)
1011 TYPE_VARARGS (type) = 1;
1012 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
1013 TYPE_CODE (type) = TYPE_CODE_METHOD;
1016 /* Return a typename for a struct/union/enum type without "struct ",
1017 "union ", or "enum ". If the type has a NULL name, return NULL. */
1019 char *
1020 type_name_no_tag (const struct type *type)
1022 if (TYPE_TAG_NAME (type) != NULL)
1023 return TYPE_TAG_NAME (type);
1025 /* Is there code which expects this to return the name if there is
1026 no tag name? My guess is that this is mainly used for C++ in
1027 cases where the two will always be the same. */
1028 return TYPE_NAME (type);
1031 /* Lookup a typedef or primitive type named NAME, visible in lexical
1032 block BLOCK. If NOERR is nonzero, return zero if NAME is not
1033 suitably defined. */
1035 struct type *
1036 lookup_typename (const struct language_defn *language,
1037 struct gdbarch *gdbarch, char *name,
1038 struct block *block, int noerr)
1040 struct symbol *sym;
1041 struct type *tmp;
1043 sym = lookup_symbol (name, block, VAR_DOMAIN, 0);
1044 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1046 tmp = language_lookup_primitive_type_by_name (language, gdbarch, name);
1047 if (tmp)
1049 return tmp;
1051 else if (!tmp && noerr)
1053 return NULL;
1055 else
1057 error (_("No type named %s."), name);
1060 return (SYMBOL_TYPE (sym));
1063 struct type *
1064 lookup_unsigned_typename (const struct language_defn *language,
1065 struct gdbarch *gdbarch, char *name)
1067 char *uns = alloca (strlen (name) + 10);
1069 strcpy (uns, "unsigned ");
1070 strcpy (uns + 9, name);
1071 return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0);
1074 struct type *
1075 lookup_signed_typename (const struct language_defn *language,
1076 struct gdbarch *gdbarch, char *name)
1078 struct type *t;
1079 char *uns = alloca (strlen (name) + 8);
1081 strcpy (uns, "signed ");
1082 strcpy (uns + 7, name);
1083 t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1);
1084 /* If we don't find "signed FOO" just try again with plain "FOO". */
1085 if (t != NULL)
1086 return t;
1087 return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0);
1090 /* Lookup a structure type named "struct NAME",
1091 visible in lexical block BLOCK. */
1093 struct type *
1094 lookup_struct (char *name, struct block *block)
1096 struct symbol *sym;
1098 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1100 if (sym == NULL)
1102 error (_("No struct type named %s."), name);
1104 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1106 error (_("This context has class, union or enum %s, not a struct."),
1107 name);
1109 return (SYMBOL_TYPE (sym));
1112 /* Lookup a union type named "union NAME",
1113 visible in lexical block BLOCK. */
1115 struct type *
1116 lookup_union (char *name, struct block *block)
1118 struct symbol *sym;
1119 struct type *t;
1121 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1123 if (sym == NULL)
1124 error (_("No union type named %s."), name);
1126 t = SYMBOL_TYPE (sym);
1128 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1129 return t;
1131 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
1132 * a further "declared_type" field to discover it is really a union.
1134 if (HAVE_CPLUS_STRUCT (t))
1135 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
1136 return t;
1138 /* If we get here, it's not a union. */
1139 error (_("This context has class, struct or enum %s, not a union."),
1140 name);
1144 /* Lookup an enum type named "enum NAME",
1145 visible in lexical block BLOCK. */
1147 struct type *
1148 lookup_enum (char *name, struct block *block)
1150 struct symbol *sym;
1152 sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0);
1153 if (sym == NULL)
1155 error (_("No enum type named %s."), name);
1157 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
1159 error (_("This context has class, struct or union %s, not an enum."),
1160 name);
1162 return (SYMBOL_TYPE (sym));
1165 /* Lookup a template type named "template NAME<TYPE>",
1166 visible in lexical block BLOCK. */
1168 struct type *
1169 lookup_template_type (char *name, struct type *type,
1170 struct block *block)
1172 struct symbol *sym;
1173 char *nam = (char *)
1174 alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
1175 strcpy (nam, name);
1176 strcat (nam, "<");
1177 strcat (nam, TYPE_NAME (type));
1178 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1180 sym = lookup_symbol (nam, block, VAR_DOMAIN, 0);
1182 if (sym == NULL)
1184 error (_("No template type named %s."), name);
1186 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1188 error (_("This context has class, union or enum %s, not a struct."),
1189 name);
1191 return (SYMBOL_TYPE (sym));
1194 /* Given a type TYPE, lookup the type of the component of type named
1195 NAME.
1197 TYPE can be either a struct or union, or a pointer or reference to
1198 a struct or union. If it is a pointer or reference, its target
1199 type is automatically used. Thus '.' and '->' are interchangable,
1200 as specified for the definitions of the expression element types
1201 STRUCTOP_STRUCT and STRUCTOP_PTR.
1203 If NOERR is nonzero, return zero if NAME is not suitably defined.
1204 If NAME is the name of a baseclass type, return that type. */
1206 struct type *
1207 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1209 int i;
1211 for (;;)
1213 CHECK_TYPEDEF (type);
1214 if (TYPE_CODE (type) != TYPE_CODE_PTR
1215 && TYPE_CODE (type) != TYPE_CODE_REF)
1216 break;
1217 type = TYPE_TARGET_TYPE (type);
1220 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1221 && TYPE_CODE (type) != TYPE_CODE_UNION)
1223 target_terminal_ours ();
1224 gdb_flush (gdb_stdout);
1225 fprintf_unfiltered (gdb_stderr, "Type ");
1226 type_print (type, "", gdb_stderr, -1);
1227 error (_(" is not a structure or union type."));
1230 #if 0
1231 /* FIXME: This change put in by Michael seems incorrect for the case
1232 where the structure tag name is the same as the member name.
1233 I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
1234 foo; } bell;" Disabled by fnf. */
1236 char *typename;
1238 typename = type_name_no_tag (type);
1239 if (typename != NULL && strcmp (typename, name) == 0)
1240 return type;
1242 #endif
1244 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1246 char *t_field_name = TYPE_FIELD_NAME (type, i);
1248 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1250 return TYPE_FIELD_TYPE (type, i);
1254 /* OK, it's not in this class. Recursively check the baseclasses. */
1255 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1257 struct type *t;
1259 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
1260 if (t != NULL)
1262 return t;
1266 if (noerr)
1268 return NULL;
1271 target_terminal_ours ();
1272 gdb_flush (gdb_stdout);
1273 fprintf_unfiltered (gdb_stderr, "Type ");
1274 type_print (type, "", gdb_stderr, -1);
1275 fprintf_unfiltered (gdb_stderr, " has no component named ");
1276 fputs_filtered (name, gdb_stderr);
1277 error (("."));
1278 return (struct type *) -1; /* For lint */
1281 /* Lookup the vptr basetype/fieldno values for TYPE.
1282 If found store vptr_basetype in *BASETYPEP if non-NULL, and return
1283 vptr_fieldno. Also, if found and basetype is from the same objfile,
1284 cache the results.
1285 If not found, return -1 and ignore BASETYPEP.
1286 Callers should be aware that in some cases (for example,
1287 the type or one of its baseclasses is a stub type and we are
1288 debugging a .o file), this function will not be able to find the
1289 virtual function table pointer, and vptr_fieldno will remain -1 and
1290 vptr_basetype will remain NULL or incomplete. */
1293 get_vptr_fieldno (struct type *type, struct type **basetypep)
1295 CHECK_TYPEDEF (type);
1297 if (TYPE_VPTR_FIELDNO (type) < 0)
1299 int i;
1301 /* We must start at zero in case the first (and only) baseclass
1302 is virtual (and hence we cannot share the table pointer). */
1303 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1305 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1306 int fieldno;
1307 struct type *basetype;
1309 fieldno = get_vptr_fieldno (baseclass, &basetype);
1310 if (fieldno >= 0)
1312 /* If the type comes from a different objfile we can't cache
1313 it, it may have a different lifetime. PR 2384 */
1314 if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
1316 TYPE_VPTR_FIELDNO (type) = fieldno;
1317 TYPE_VPTR_BASETYPE (type) = basetype;
1319 if (basetypep)
1320 *basetypep = basetype;
1321 return fieldno;
1325 /* Not found. */
1326 return -1;
1328 else
1330 if (basetypep)
1331 *basetypep = TYPE_VPTR_BASETYPE (type);
1332 return TYPE_VPTR_FIELDNO (type);
1336 static void
1337 stub_noname_complaint (void)
1339 complaint (&symfile_complaints, _("stub type has NULL name"));
1342 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1344 If this is a stubbed struct (i.e. declared as struct foo *), see if
1345 we can find a full definition in some other file. If so, copy this
1346 definition, so we can use it in future. There used to be a comment
1347 (but not any code) that if we don't find a full definition, we'd
1348 set a flag so we don't spend time in the future checking the same
1349 type. That would be a mistake, though--we might load in more
1350 symbols which contain a full definition for the type.
1352 This used to be coded as a macro, but I don't think it is called
1353 often enough to merit such treatment. */
1355 /* Find the real type of TYPE. This function returns the real type,
1356 after removing all layers of typedefs and completing opaque or stub
1357 types. Completion changes the TYPE argument, but stripping of
1358 typedefs does not. */
1360 struct type *
1361 check_typedef (struct type *type)
1363 struct type *orig_type = type;
1364 int is_const, is_volatile;
1366 gdb_assert (type);
1368 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1370 if (!TYPE_TARGET_TYPE (type))
1372 char *name;
1373 struct symbol *sym;
1375 /* It is dangerous to call lookup_symbol if we are currently
1376 reading a symtab. Infinite recursion is one danger. */
1377 if (currently_reading_symtab)
1378 return type;
1380 name = type_name_no_tag (type);
1381 /* FIXME: shouldn't we separately check the TYPE_NAME and
1382 the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
1383 VAR_DOMAIN as appropriate? (this code was written before
1384 TYPE_NAME and TYPE_TAG_NAME were separate). */
1385 if (name == NULL)
1387 stub_noname_complaint ();
1388 return type;
1390 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1391 if (sym)
1392 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1393 else /* TYPE_CODE_UNDEF */
1394 TYPE_TARGET_TYPE (type) = alloc_type (NULL);
1396 type = TYPE_TARGET_TYPE (type);
1399 is_const = TYPE_CONST (type);
1400 is_volatile = TYPE_VOLATILE (type);
1402 /* If this is a struct/class/union with no fields, then check
1403 whether a full definition exists somewhere else. This is for
1404 systems where a type definition with no fields is issued for such
1405 types, instead of identifying them as stub types in the first
1406 place. */
1408 if (TYPE_IS_OPAQUE (type)
1409 && opaque_type_resolution
1410 && !currently_reading_symtab)
1412 char *name = type_name_no_tag (type);
1413 struct type *newtype;
1414 if (name == NULL)
1416 stub_noname_complaint ();
1417 return type;
1419 newtype = lookup_transparent_type (name);
1421 if (newtype)
1423 /* If the resolved type and the stub are in the same
1424 objfile, then replace the stub type with the real deal.
1425 But if they're in separate objfiles, leave the stub
1426 alone; we'll just look up the transparent type every time
1427 we call check_typedef. We can't create pointers between
1428 types allocated to different objfiles, since they may
1429 have different lifetimes. Trying to copy NEWTYPE over to
1430 TYPE's objfile is pointless, too, since you'll have to
1431 move over any other types NEWTYPE refers to, which could
1432 be an unbounded amount of stuff. */
1433 if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
1434 make_cv_type (is_const, is_volatile, newtype, &type);
1435 else
1436 type = newtype;
1439 /* Otherwise, rely on the stub flag being set for opaque/stubbed
1440 types. */
1441 else if (TYPE_STUB (type) && !currently_reading_symtab)
1443 char *name = type_name_no_tag (type);
1444 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1445 TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
1446 as appropriate? (this code was written before TYPE_NAME and
1447 TYPE_TAG_NAME were separate). */
1448 struct symbol *sym;
1449 if (name == NULL)
1451 stub_noname_complaint ();
1452 return type;
1454 sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0);
1455 if (sym)
1457 /* Same as above for opaque types, we can replace the stub
1458 with the complete type only if they are int the same
1459 objfile. */
1460 if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
1461 make_cv_type (is_const, is_volatile,
1462 SYMBOL_TYPE (sym), &type);
1463 else
1464 type = SYMBOL_TYPE (sym);
1468 if (TYPE_TARGET_STUB (type))
1470 struct type *range_type;
1471 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1473 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1475 /* Empty. */
1477 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1478 && TYPE_NFIELDS (type) == 1
1479 && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
1480 == TYPE_CODE_RANGE))
1482 /* Now recompute the length of the array type, based on its
1483 number of elements and the target type's length.
1484 Watch out for Ada null Ada arrays where the high bound
1485 is smaller than the low bound. */
1486 const int low_bound = TYPE_LOW_BOUND (range_type);
1487 const int high_bound = TYPE_HIGH_BOUND (range_type);
1488 int nb_elements;
1490 if (high_bound < low_bound)
1491 nb_elements = 0;
1492 else
1493 nb_elements = high_bound - low_bound + 1;
1495 TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
1496 TYPE_TARGET_STUB (type) = 0;
1498 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1500 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1501 TYPE_TARGET_STUB (type) = 0;
1504 /* Cache TYPE_LENGTH for future use. */
1505 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1506 return type;
1509 /* Parse a type expression in the string [P..P+LENGTH). If an error
1510 occurs, silently return builtin_type_void. */
1512 static struct type *
1513 safe_parse_type (char *p, int length)
1515 struct ui_file *saved_gdb_stderr;
1516 struct type *type;
1518 /* Suppress error messages. */
1519 saved_gdb_stderr = gdb_stderr;
1520 gdb_stderr = ui_file_new ();
1522 /* Call parse_and_eval_type() without fear of longjmp()s. */
1523 if (!gdb_parse_and_eval_type (p, length, &type))
1524 type = builtin_type_void;
1526 /* Stop suppressing error messages. */
1527 ui_file_delete (gdb_stderr);
1528 gdb_stderr = saved_gdb_stderr;
1530 return type;
1533 /* Ugly hack to convert method stubs into method types.
1535 He ain't kiddin'. This demangles the name of the method into a
1536 string including argument types, parses out each argument type,
1537 generates a string casting a zero to that type, evaluates the
1538 string, and stuffs the resulting type into an argtype vector!!!
1539 Then it knows the type of the whole function (including argument
1540 types for overloading), which info used to be in the stab's but was
1541 removed to hack back the space required for them. */
1543 static void
1544 check_stub_method (struct type *type, int method_id, int signature_id)
1546 struct fn_field *f;
1547 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1548 char *demangled_name = cplus_demangle (mangled_name,
1549 DMGL_PARAMS | DMGL_ANSI);
1550 char *argtypetext, *p;
1551 int depth = 0, argcount = 1;
1552 struct field *argtypes;
1553 struct type *mtype;
1555 /* Make sure we got back a function string that we can use. */
1556 if (demangled_name)
1557 p = strchr (demangled_name, '(');
1558 else
1559 p = NULL;
1561 if (demangled_name == NULL || p == NULL)
1562 error (_("Internal: Cannot demangle mangled name `%s'."),
1563 mangled_name);
1565 /* Now, read in the parameters that define this type. */
1566 p += 1;
1567 argtypetext = p;
1568 while (*p)
1570 if (*p == '(' || *p == '<')
1572 depth += 1;
1574 else if (*p == ')' || *p == '>')
1576 depth -= 1;
1578 else if (*p == ',' && depth == 0)
1580 argcount += 1;
1583 p += 1;
1586 /* If we read one argument and it was ``void'', don't count it. */
1587 if (strncmp (argtypetext, "(void)", 6) == 0)
1588 argcount -= 1;
1590 /* We need one extra slot, for the THIS pointer. */
1592 argtypes = (struct field *)
1593 TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
1594 p = argtypetext;
1596 /* Add THIS pointer for non-static methods. */
1597 f = TYPE_FN_FIELDLIST1 (type, method_id);
1598 if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1599 argcount = 0;
1600 else
1602 argtypes[0].type = lookup_pointer_type (type);
1603 argcount = 1;
1606 if (*p != ')') /* () means no args, skip while */
1608 depth = 0;
1609 while (*p)
1611 if (depth <= 0 && (*p == ',' || *p == ')'))
1613 /* Avoid parsing of ellipsis, they will be handled below.
1614 Also avoid ``void'' as above. */
1615 if (strncmp (argtypetext, "...", p - argtypetext) != 0
1616 && strncmp (argtypetext, "void", p - argtypetext) != 0)
1618 argtypes[argcount].type =
1619 safe_parse_type (argtypetext, p - argtypetext);
1620 argcount += 1;
1622 argtypetext = p + 1;
1625 if (*p == '(' || *p == '<')
1627 depth += 1;
1629 else if (*p == ')' || *p == '>')
1631 depth -= 1;
1634 p += 1;
1638 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1640 /* Now update the old "stub" type into a real type. */
1641 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1642 TYPE_DOMAIN_TYPE (mtype) = type;
1643 TYPE_FIELDS (mtype) = argtypes;
1644 TYPE_NFIELDS (mtype) = argcount;
1645 TYPE_STUB (mtype) = 0;
1646 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1647 if (p[-2] == '.')
1648 TYPE_VARARGS (mtype) = 1;
1650 xfree (demangled_name);
1653 /* This is the external interface to check_stub_method, above. This
1654 function unstubs all of the signatures for TYPE's METHOD_ID method
1655 name. After calling this function TYPE_FN_FIELD_STUB will be
1656 cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
1657 correct.
1659 This function unfortunately can not die until stabs do. */
1661 void
1662 check_stub_method_group (struct type *type, int method_id)
1664 int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1665 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1666 int j, found_stub = 0;
1668 for (j = 0; j < len; j++)
1669 if (TYPE_FN_FIELD_STUB (f, j))
1671 found_stub = 1;
1672 check_stub_method (type, method_id, j);
1675 /* GNU v3 methods with incorrect names were corrected when we read
1676 in type information, because it was cheaper to do it then. The
1677 only GNU v2 methods with incorrect method names are operators and
1678 destructors; destructors were also corrected when we read in type
1679 information.
1681 Therefore the only thing we need to handle here are v2 operator
1682 names. */
1683 if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1685 int ret;
1686 char dem_opname[256];
1688 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1689 method_id),
1690 dem_opname, DMGL_ANSI);
1691 if (!ret)
1692 ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
1693 method_id),
1694 dem_opname, 0);
1695 if (ret)
1696 TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1700 const struct cplus_struct_type cplus_struct_default;
1702 void
1703 allocate_cplus_struct_type (struct type *type)
1705 if (!HAVE_CPLUS_STRUCT (type))
1707 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1708 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1709 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1713 /* Helper function to initialize the standard scalar types.
1715 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy of
1716 the string pointed to by name in the objfile_obstack for that
1717 objfile, and initialize the type name to that copy. There are
1718 places (mipsread.c in particular, where init_type is called with a
1719 NULL value for NAME). */
1721 struct type *
1722 init_type (enum type_code code, int length, int flags,
1723 char *name, struct objfile *objfile)
1725 struct type *type;
1727 type = alloc_type (objfile);
1728 TYPE_CODE (type) = code;
1729 TYPE_LENGTH (type) = length;
1731 gdb_assert (!(flags & (TYPE_FLAG_MIN - 1)));
1732 if (flags & TYPE_FLAG_UNSIGNED)
1733 TYPE_UNSIGNED (type) = 1;
1734 if (flags & TYPE_FLAG_NOSIGN)
1735 TYPE_NOSIGN (type) = 1;
1736 if (flags & TYPE_FLAG_STUB)
1737 TYPE_STUB (type) = 1;
1738 if (flags & TYPE_FLAG_TARGET_STUB)
1739 TYPE_TARGET_STUB (type) = 1;
1740 if (flags & TYPE_FLAG_STATIC)
1741 TYPE_STATIC (type) = 1;
1742 if (flags & TYPE_FLAG_PROTOTYPED)
1743 TYPE_PROTOTYPED (type) = 1;
1744 if (flags & TYPE_FLAG_INCOMPLETE)
1745 TYPE_INCOMPLETE (type) = 1;
1746 if (flags & TYPE_FLAG_VARARGS)
1747 TYPE_VARARGS (type) = 1;
1748 if (flags & TYPE_FLAG_VECTOR)
1749 TYPE_VECTOR (type) = 1;
1750 if (flags & TYPE_FLAG_STUB_SUPPORTED)
1751 TYPE_STUB_SUPPORTED (type) = 1;
1752 if (flags & TYPE_FLAG_NOTTEXT)
1753 TYPE_NOTTEXT (type) = 1;
1754 if (flags & TYPE_FLAG_FIXED_INSTANCE)
1755 TYPE_FIXED_INSTANCE (type) = 1;
1757 if ((name != NULL) && (objfile != NULL))
1759 TYPE_NAME (type) = obsavestring (name, strlen (name),
1760 &objfile->objfile_obstack);
1762 else
1764 TYPE_NAME (type) = name;
1767 /* C++ fancies. */
1769 if (name && strcmp (name, "char") == 0)
1770 TYPE_NOSIGN (type) = 1;
1772 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1773 || code == TYPE_CODE_NAMESPACE)
1775 INIT_CPLUS_SPECIFIC (type);
1777 return type;
1780 /* Helper function. Create an empty composite type. */
1782 struct type *
1783 init_composite_type (char *name, enum type_code code)
1785 struct type *t;
1786 gdb_assert (code == TYPE_CODE_STRUCT
1787 || code == TYPE_CODE_UNION);
1788 t = init_type (code, 0, 0, NULL, NULL);
1789 TYPE_TAG_NAME (t) = name;
1790 return t;
1793 /* Helper function. Append a field to a composite type. */
1795 void
1796 append_composite_type_field_aligned (struct type *t, char *name,
1797 struct type *field, int alignment)
1799 struct field *f;
1800 TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1801 TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1802 sizeof (struct field) * TYPE_NFIELDS (t));
1803 f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1804 memset (f, 0, sizeof f[0]);
1805 FIELD_TYPE (f[0]) = field;
1806 FIELD_NAME (f[0]) = name;
1807 if (TYPE_CODE (t) == TYPE_CODE_UNION)
1809 if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1810 TYPE_LENGTH (t) = TYPE_LENGTH (field);
1812 else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1814 TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1815 if (TYPE_NFIELDS (t) > 1)
1817 FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1818 + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
1819 * TARGET_CHAR_BIT));
1821 if (alignment)
1823 int left = FIELD_BITPOS (f[0]) % (alignment * TARGET_CHAR_BIT);
1824 if (left)
1826 FIELD_BITPOS (f[0]) += left;
1827 TYPE_LENGTH (t) += left / TARGET_CHAR_BIT;
1834 void
1835 append_composite_type_field (struct type *t, char *name,
1836 struct type *field)
1838 append_composite_type_field_aligned (t, name, field, 0);
1842 can_dereference (struct type *t)
1844 /* FIXME: Should we return true for references as well as
1845 pointers? */
1846 CHECK_TYPEDEF (t);
1847 return
1848 (t != NULL
1849 && TYPE_CODE (t) == TYPE_CODE_PTR
1850 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1854 is_integral_type (struct type *t)
1856 CHECK_TYPEDEF (t);
1857 return
1858 ((t != NULL)
1859 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1860 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1861 || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
1862 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1863 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1864 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1867 /* Check whether BASE is an ancestor or base class or DCLASS
1868 Return 1 if so, and 0 if not.
1869 Note: callers may want to check for identity of the types before
1870 calling this function -- identical types are considered to satisfy
1871 the ancestor relationship even if they're identical. */
1874 is_ancestor (struct type *base, struct type *dclass)
1876 int i;
1878 CHECK_TYPEDEF (base);
1879 CHECK_TYPEDEF (dclass);
1881 if (base == dclass)
1882 return 1;
1883 if (TYPE_NAME (base) && TYPE_NAME (dclass)
1884 && !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1885 return 1;
1887 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1888 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1889 return 1;
1891 return 0;
1896 /* Functions for overload resolution begin here */
1898 /* Compare two badness vectors A and B and return the result.
1899 0 => A and B are identical
1900 1 => A and B are incomparable
1901 2 => A is better than B
1902 3 => A is worse than B */
1905 compare_badness (struct badness_vector *a, struct badness_vector *b)
1907 int i;
1908 int tmp;
1909 short found_pos = 0; /* any positives in c? */
1910 short found_neg = 0; /* any negatives in c? */
1912 /* differing lengths => incomparable */
1913 if (a->length != b->length)
1914 return 1;
1916 /* Subtract b from a */
1917 for (i = 0; i < a->length; i++)
1919 tmp = a->rank[i] - b->rank[i];
1920 if (tmp > 0)
1921 found_pos = 1;
1922 else if (tmp < 0)
1923 found_neg = 1;
1926 if (found_pos)
1928 if (found_neg)
1929 return 1; /* incomparable */
1930 else
1931 return 3; /* A > B */
1933 else
1934 /* no positives */
1936 if (found_neg)
1937 return 2; /* A < B */
1938 else
1939 return 0; /* A == B */
1943 /* Rank a function by comparing its parameter types (PARMS, length
1944 NPARMS), to the types of an argument list (ARGS, length NARGS).
1945 Return a pointer to a badness vector. This has NARGS + 1
1946 entries. */
1948 struct badness_vector *
1949 rank_function (struct type **parms, int nparms,
1950 struct type **args, int nargs)
1952 int i;
1953 struct badness_vector *bv;
1954 int min_len = nparms < nargs ? nparms : nargs;
1956 bv = xmalloc (sizeof (struct badness_vector));
1957 bv->length = nargs + 1; /* add 1 for the length-match rank */
1958 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
1960 /* First compare the lengths of the supplied lists.
1961 If there is a mismatch, set it to a high value. */
1963 /* pai/1997-06-03 FIXME: when we have debug info about default
1964 arguments and ellipsis parameter lists, we should consider those
1965 and rank the length-match more finely. */
1967 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
1969 /* Now rank all the parameters of the candidate function */
1970 for (i = 1; i <= min_len; i++)
1971 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
1973 /* If more arguments than parameters, add dummy entries */
1974 for (i = min_len + 1; i <= nargs; i++)
1975 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
1977 return bv;
1980 /* Compare the names of two integer types, assuming that any sign
1981 qualifiers have been checked already. We do it this way because
1982 there may be an "int" in the name of one of the types. */
1984 static int
1985 integer_types_same_name_p (const char *first, const char *second)
1987 int first_p, second_p;
1989 /* If both are shorts, return 1; if neither is a short, keep
1990 checking. */
1991 first_p = (strstr (first, "short") != NULL);
1992 second_p = (strstr (second, "short") != NULL);
1993 if (first_p && second_p)
1994 return 1;
1995 if (first_p || second_p)
1996 return 0;
1998 /* Likewise for long. */
1999 first_p = (strstr (first, "long") != NULL);
2000 second_p = (strstr (second, "long") != NULL);
2001 if (first_p && second_p)
2002 return 1;
2003 if (first_p || second_p)
2004 return 0;
2006 /* Likewise for char. */
2007 first_p = (strstr (first, "char") != NULL);
2008 second_p = (strstr (second, "char") != NULL);
2009 if (first_p && second_p)
2010 return 1;
2011 if (first_p || second_p)
2012 return 0;
2014 /* They must both be ints. */
2015 return 1;
2018 /* Compare one type (PARM) for compatibility with another (ARG).
2019 * PARM is intended to be the parameter type of a function; and
2020 * ARG is the supplied argument's type. This function tests if
2021 * the latter can be converted to the former.
2023 * Return 0 if they are identical types;
2024 * Otherwise, return an integer which corresponds to how compatible
2025 * PARM is to ARG. The higher the return value, the worse the match.
2026 * Generally the "bad" conversions are all uniformly assigned a 100. */
2029 rank_one_type (struct type *parm, struct type *arg)
2031 /* Identical type pointers. */
2032 /* However, this still doesn't catch all cases of same type for arg
2033 and param. The reason is that builtin types are different from
2034 the same ones constructed from the object. */
2035 if (parm == arg)
2036 return 0;
2038 /* Resolve typedefs */
2039 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2040 parm = check_typedef (parm);
2041 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2042 arg = check_typedef (arg);
2045 Well, damnit, if the names are exactly the same, I'll say they
2046 are exactly the same. This happens when we generate method
2047 stubs. The types won't point to the same address, but they
2048 really are the same.
2051 if (TYPE_NAME (parm) && TYPE_NAME (arg)
2052 && !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2053 return 0;
2055 /* Check if identical after resolving typedefs. */
2056 if (parm == arg)
2057 return 0;
2059 /* See through references, since we can almost make non-references
2060 references. */
2061 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2062 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2063 + REFERENCE_CONVERSION_BADNESS);
2064 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2065 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2066 + REFERENCE_CONVERSION_BADNESS);
2067 if (overload_debug)
2068 /* Debugging only. */
2069 fprintf_filtered (gdb_stderr,
2070 "------ Arg is %s [%d], parm is %s [%d]\n",
2071 TYPE_NAME (arg), TYPE_CODE (arg),
2072 TYPE_NAME (parm), TYPE_CODE (parm));
2074 /* x -> y means arg of type x being supplied for parameter of type y */
2076 switch (TYPE_CODE (parm))
2078 case TYPE_CODE_PTR:
2079 switch (TYPE_CODE (arg))
2081 case TYPE_CODE_PTR:
2082 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2083 return VOID_PTR_CONVERSION_BADNESS;
2084 else
2085 return rank_one_type (TYPE_TARGET_TYPE (parm),
2086 TYPE_TARGET_TYPE (arg));
2087 case TYPE_CODE_ARRAY:
2088 return rank_one_type (TYPE_TARGET_TYPE (parm),
2089 TYPE_TARGET_TYPE (arg));
2090 case TYPE_CODE_FUNC:
2091 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2092 case TYPE_CODE_INT:
2093 case TYPE_CODE_ENUM:
2094 case TYPE_CODE_FLAGS:
2095 case TYPE_CODE_CHAR:
2096 case TYPE_CODE_RANGE:
2097 case TYPE_CODE_BOOL:
2098 return POINTER_CONVERSION_BADNESS;
2099 default:
2100 return INCOMPATIBLE_TYPE_BADNESS;
2102 case TYPE_CODE_ARRAY:
2103 switch (TYPE_CODE (arg))
2105 case TYPE_CODE_PTR:
2106 case TYPE_CODE_ARRAY:
2107 return rank_one_type (TYPE_TARGET_TYPE (parm),
2108 TYPE_TARGET_TYPE (arg));
2109 default:
2110 return INCOMPATIBLE_TYPE_BADNESS;
2112 case TYPE_CODE_FUNC:
2113 switch (TYPE_CODE (arg))
2115 case TYPE_CODE_PTR: /* funcptr -> func */
2116 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2117 default:
2118 return INCOMPATIBLE_TYPE_BADNESS;
2120 case TYPE_CODE_INT:
2121 switch (TYPE_CODE (arg))
2123 case TYPE_CODE_INT:
2124 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2126 /* Deal with signed, unsigned, and plain chars and
2127 signed and unsigned ints. */
2128 if (TYPE_NOSIGN (parm))
2130 /* This case only for character types */
2131 if (TYPE_NOSIGN (arg))
2132 return 0; /* plain char -> plain char */
2133 else /* signed/unsigned char -> plain char */
2134 return INTEGER_CONVERSION_BADNESS;
2136 else if (TYPE_UNSIGNED (parm))
2138 if (TYPE_UNSIGNED (arg))
2140 /* unsigned int -> unsigned int, or
2141 unsigned long -> unsigned long */
2142 if (integer_types_same_name_p (TYPE_NAME (parm),
2143 TYPE_NAME (arg)))
2144 return 0;
2145 else if (integer_types_same_name_p (TYPE_NAME (arg),
2146 "int")
2147 && integer_types_same_name_p (TYPE_NAME (parm),
2148 "long"))
2149 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2150 else
2151 return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
2153 else
2155 if (integer_types_same_name_p (TYPE_NAME (arg),
2156 "long")
2157 && integer_types_same_name_p (TYPE_NAME (parm),
2158 "int"))
2159 return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
2160 else
2161 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2164 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2166 if (integer_types_same_name_p (TYPE_NAME (parm),
2167 TYPE_NAME (arg)))
2168 return 0;
2169 else if (integer_types_same_name_p (TYPE_NAME (arg),
2170 "int")
2171 && integer_types_same_name_p (TYPE_NAME (parm),
2172 "long"))
2173 return INTEGER_PROMOTION_BADNESS;
2174 else
2175 return INTEGER_CONVERSION_BADNESS;
2177 else
2178 return INTEGER_CONVERSION_BADNESS;
2180 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2181 return INTEGER_PROMOTION_BADNESS;
2182 else
2183 return INTEGER_CONVERSION_BADNESS;
2184 case TYPE_CODE_ENUM:
2185 case TYPE_CODE_FLAGS:
2186 case TYPE_CODE_CHAR:
2187 case TYPE_CODE_RANGE:
2188 case TYPE_CODE_BOOL:
2189 return INTEGER_PROMOTION_BADNESS;
2190 case TYPE_CODE_FLT:
2191 return INT_FLOAT_CONVERSION_BADNESS;
2192 case TYPE_CODE_PTR:
2193 return NS_POINTER_CONVERSION_BADNESS;
2194 default:
2195 return INCOMPATIBLE_TYPE_BADNESS;
2197 break;
2198 case TYPE_CODE_ENUM:
2199 switch (TYPE_CODE (arg))
2201 case TYPE_CODE_INT:
2202 case TYPE_CODE_CHAR:
2203 case TYPE_CODE_RANGE:
2204 case TYPE_CODE_BOOL:
2205 case TYPE_CODE_ENUM:
2206 return INTEGER_CONVERSION_BADNESS;
2207 case TYPE_CODE_FLT:
2208 return INT_FLOAT_CONVERSION_BADNESS;
2209 default:
2210 return INCOMPATIBLE_TYPE_BADNESS;
2212 break;
2213 case TYPE_CODE_CHAR:
2214 switch (TYPE_CODE (arg))
2216 case TYPE_CODE_RANGE:
2217 case TYPE_CODE_BOOL:
2218 case TYPE_CODE_ENUM:
2219 return INTEGER_CONVERSION_BADNESS;
2220 case TYPE_CODE_FLT:
2221 return INT_FLOAT_CONVERSION_BADNESS;
2222 case TYPE_CODE_INT:
2223 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2224 return INTEGER_CONVERSION_BADNESS;
2225 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2226 return INTEGER_PROMOTION_BADNESS;
2227 /* >>> !! else fall through !! <<< */
2228 case TYPE_CODE_CHAR:
2229 /* Deal with signed, unsigned, and plain chars for C++ and
2230 with int cases falling through from previous case. */
2231 if (TYPE_NOSIGN (parm))
2233 if (TYPE_NOSIGN (arg))
2234 return 0;
2235 else
2236 return INTEGER_CONVERSION_BADNESS;
2238 else if (TYPE_UNSIGNED (parm))
2240 if (TYPE_UNSIGNED (arg))
2241 return 0;
2242 else
2243 return INTEGER_PROMOTION_BADNESS;
2245 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2246 return 0;
2247 else
2248 return INTEGER_CONVERSION_BADNESS;
2249 default:
2250 return INCOMPATIBLE_TYPE_BADNESS;
2252 break;
2253 case TYPE_CODE_RANGE:
2254 switch (TYPE_CODE (arg))
2256 case TYPE_CODE_INT:
2257 case TYPE_CODE_CHAR:
2258 case TYPE_CODE_RANGE:
2259 case TYPE_CODE_BOOL:
2260 case TYPE_CODE_ENUM:
2261 return INTEGER_CONVERSION_BADNESS;
2262 case TYPE_CODE_FLT:
2263 return INT_FLOAT_CONVERSION_BADNESS;
2264 default:
2265 return INCOMPATIBLE_TYPE_BADNESS;
2267 break;
2268 case TYPE_CODE_BOOL:
2269 switch (TYPE_CODE (arg))
2271 case TYPE_CODE_INT:
2272 case TYPE_CODE_CHAR:
2273 case TYPE_CODE_RANGE:
2274 case TYPE_CODE_ENUM:
2275 case TYPE_CODE_FLT:
2276 case TYPE_CODE_PTR:
2277 return BOOLEAN_CONVERSION_BADNESS;
2278 case TYPE_CODE_BOOL:
2279 return 0;
2280 default:
2281 return INCOMPATIBLE_TYPE_BADNESS;
2283 break;
2284 case TYPE_CODE_FLT:
2285 switch (TYPE_CODE (arg))
2287 case TYPE_CODE_FLT:
2288 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2289 return FLOAT_PROMOTION_BADNESS;
2290 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2291 return 0;
2292 else
2293 return FLOAT_CONVERSION_BADNESS;
2294 case TYPE_CODE_INT:
2295 case TYPE_CODE_BOOL:
2296 case TYPE_CODE_ENUM:
2297 case TYPE_CODE_RANGE:
2298 case TYPE_CODE_CHAR:
2299 return INT_FLOAT_CONVERSION_BADNESS;
2300 default:
2301 return INCOMPATIBLE_TYPE_BADNESS;
2303 break;
2304 case TYPE_CODE_COMPLEX:
2305 switch (TYPE_CODE (arg))
2306 { /* Strictly not needed for C++, but... */
2307 case TYPE_CODE_FLT:
2308 return FLOAT_PROMOTION_BADNESS;
2309 case TYPE_CODE_COMPLEX:
2310 return 0;
2311 default:
2312 return INCOMPATIBLE_TYPE_BADNESS;
2314 break;
2315 case TYPE_CODE_STRUCT:
2316 /* currently same as TYPE_CODE_CLASS */
2317 switch (TYPE_CODE (arg))
2319 case TYPE_CODE_STRUCT:
2320 /* Check for derivation */
2321 if (is_ancestor (parm, arg))
2322 return BASE_CONVERSION_BADNESS;
2323 /* else fall through */
2324 default:
2325 return INCOMPATIBLE_TYPE_BADNESS;
2327 break;
2328 case TYPE_CODE_UNION:
2329 switch (TYPE_CODE (arg))
2331 case TYPE_CODE_UNION:
2332 default:
2333 return INCOMPATIBLE_TYPE_BADNESS;
2335 break;
2336 case TYPE_CODE_MEMBERPTR:
2337 switch (TYPE_CODE (arg))
2339 default:
2340 return INCOMPATIBLE_TYPE_BADNESS;
2342 break;
2343 case TYPE_CODE_METHOD:
2344 switch (TYPE_CODE (arg))
2347 default:
2348 return INCOMPATIBLE_TYPE_BADNESS;
2350 break;
2351 case TYPE_CODE_REF:
2352 switch (TYPE_CODE (arg))
2355 default:
2356 return INCOMPATIBLE_TYPE_BADNESS;
2359 break;
2360 case TYPE_CODE_SET:
2361 switch (TYPE_CODE (arg))
2363 /* Not in C++ */
2364 case TYPE_CODE_SET:
2365 return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
2366 TYPE_FIELD_TYPE (arg, 0));
2367 default:
2368 return INCOMPATIBLE_TYPE_BADNESS;
2370 break;
2371 case TYPE_CODE_VOID:
2372 default:
2373 return INCOMPATIBLE_TYPE_BADNESS;
2374 } /* switch (TYPE_CODE (arg)) */
2378 /* End of functions for overload resolution */
2380 static void
2381 print_bit_vector (B_TYPE *bits, int nbits)
2383 int bitno;
2385 for (bitno = 0; bitno < nbits; bitno++)
2387 if ((bitno % 8) == 0)
2389 puts_filtered (" ");
2391 if (B_TST (bits, bitno))
2392 printf_filtered (("1"));
2393 else
2394 printf_filtered (("0"));
2398 /* Note the first arg should be the "this" pointer, we may not want to
2399 include it since we may get into a infinitely recursive
2400 situation. */
2402 static void
2403 print_arg_types (struct field *args, int nargs, int spaces)
2405 if (args != NULL)
2407 int i;
2409 for (i = 0; i < nargs; i++)
2410 recursive_dump_type (args[i].type, spaces + 2);
2415 field_is_static (struct field *f)
2417 /* "static" fields are the fields whose location is not relative
2418 to the address of the enclosing struct. It would be nice to
2419 have a dedicated flag that would be set for static fields when
2420 the type is being created. But in practice, checking the field
2421 loc_kind should give us an accurate answer (at least as long as
2422 we assume that DWARF block locations are not going to be used
2423 for static fields). FIXME? */
2424 return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME
2425 || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR);
2428 static void
2429 dump_fn_fieldlists (struct type *type, int spaces)
2431 int method_idx;
2432 int overload_idx;
2433 struct fn_field *f;
2435 printfi_filtered (spaces, "fn_fieldlists ");
2436 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2437 printf_filtered ("\n");
2438 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2440 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2441 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2442 method_idx,
2443 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2444 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2445 gdb_stdout);
2446 printf_filtered (_(") length %d\n"),
2447 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2448 for (overload_idx = 0;
2449 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2450 overload_idx++)
2452 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2453 overload_idx,
2454 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2455 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2456 gdb_stdout);
2457 printf_filtered (")\n");
2458 printfi_filtered (spaces + 8, "type ");
2459 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
2460 gdb_stdout);
2461 printf_filtered ("\n");
2463 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2464 spaces + 8 + 2);
2466 printfi_filtered (spaces + 8, "args ");
2467 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
2468 gdb_stdout);
2469 printf_filtered ("\n");
2471 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2472 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f,
2473 overload_idx)),
2474 spaces);
2475 printfi_filtered (spaces + 8, "fcontext ");
2476 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2477 gdb_stdout);
2478 printf_filtered ("\n");
2480 printfi_filtered (spaces + 8, "is_const %d\n",
2481 TYPE_FN_FIELD_CONST (f, overload_idx));
2482 printfi_filtered (spaces + 8, "is_volatile %d\n",
2483 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2484 printfi_filtered (spaces + 8, "is_private %d\n",
2485 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2486 printfi_filtered (spaces + 8, "is_protected %d\n",
2487 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2488 printfi_filtered (spaces + 8, "is_stub %d\n",
2489 TYPE_FN_FIELD_STUB (f, overload_idx));
2490 printfi_filtered (spaces + 8, "voffset %u\n",
2491 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2496 static void
2497 print_cplus_stuff (struct type *type, int spaces)
2499 printfi_filtered (spaces, "n_baseclasses %d\n",
2500 TYPE_N_BASECLASSES (type));
2501 printfi_filtered (spaces, "nfn_fields %d\n",
2502 TYPE_NFN_FIELDS (type));
2503 printfi_filtered (spaces, "nfn_fields_total %d\n",
2504 TYPE_NFN_FIELDS_TOTAL (type));
2505 if (TYPE_N_BASECLASSES (type) > 0)
2507 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2508 TYPE_N_BASECLASSES (type));
2509 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
2510 gdb_stdout);
2511 printf_filtered (")");
2513 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2514 TYPE_N_BASECLASSES (type));
2515 puts_filtered ("\n");
2517 if (TYPE_NFIELDS (type) > 0)
2519 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2521 printfi_filtered (spaces,
2522 "private_field_bits (%d bits at *",
2523 TYPE_NFIELDS (type));
2524 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
2525 gdb_stdout);
2526 printf_filtered (")");
2527 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2528 TYPE_NFIELDS (type));
2529 puts_filtered ("\n");
2531 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2533 printfi_filtered (spaces,
2534 "protected_field_bits (%d bits at *",
2535 TYPE_NFIELDS (type));
2536 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
2537 gdb_stdout);
2538 printf_filtered (")");
2539 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2540 TYPE_NFIELDS (type));
2541 puts_filtered ("\n");
2544 if (TYPE_NFN_FIELDS (type) > 0)
2546 dump_fn_fieldlists (type, spaces);
2550 static struct obstack dont_print_type_obstack;
2552 void
2553 recursive_dump_type (struct type *type, int spaces)
2555 int idx;
2557 if (spaces == 0)
2558 obstack_begin (&dont_print_type_obstack, 0);
2560 if (TYPE_NFIELDS (type) > 0
2561 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2563 struct type **first_dont_print
2564 = (struct type **) obstack_base (&dont_print_type_obstack);
2566 int i = (struct type **)
2567 obstack_next_free (&dont_print_type_obstack) - first_dont_print;
2569 while (--i >= 0)
2571 if (type == first_dont_print[i])
2573 printfi_filtered (spaces, "type node ");
2574 gdb_print_host_address (type, gdb_stdout);
2575 printf_filtered (_(" <same as already seen type>\n"));
2576 return;
2580 obstack_ptr_grow (&dont_print_type_obstack, type);
2583 printfi_filtered (spaces, "type node ");
2584 gdb_print_host_address (type, gdb_stdout);
2585 printf_filtered ("\n");
2586 printfi_filtered (spaces, "name '%s' (",
2587 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2588 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2589 printf_filtered (")\n");
2590 printfi_filtered (spaces, "tagname '%s' (",
2591 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2592 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2593 printf_filtered (")\n");
2594 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2595 switch (TYPE_CODE (type))
2597 case TYPE_CODE_UNDEF:
2598 printf_filtered ("(TYPE_CODE_UNDEF)");
2599 break;
2600 case TYPE_CODE_PTR:
2601 printf_filtered ("(TYPE_CODE_PTR)");
2602 break;
2603 case TYPE_CODE_ARRAY:
2604 printf_filtered ("(TYPE_CODE_ARRAY)");
2605 break;
2606 case TYPE_CODE_STRUCT:
2607 printf_filtered ("(TYPE_CODE_STRUCT)");
2608 break;
2609 case TYPE_CODE_UNION:
2610 printf_filtered ("(TYPE_CODE_UNION)");
2611 break;
2612 case TYPE_CODE_ENUM:
2613 printf_filtered ("(TYPE_CODE_ENUM)");
2614 break;
2615 case TYPE_CODE_FLAGS:
2616 printf_filtered ("(TYPE_CODE_FLAGS)");
2617 break;
2618 case TYPE_CODE_FUNC:
2619 printf_filtered ("(TYPE_CODE_FUNC)");
2620 break;
2621 case TYPE_CODE_INT:
2622 printf_filtered ("(TYPE_CODE_INT)");
2623 break;
2624 case TYPE_CODE_FLT:
2625 printf_filtered ("(TYPE_CODE_FLT)");
2626 break;
2627 case TYPE_CODE_VOID:
2628 printf_filtered ("(TYPE_CODE_VOID)");
2629 break;
2630 case TYPE_CODE_SET:
2631 printf_filtered ("(TYPE_CODE_SET)");
2632 break;
2633 case TYPE_CODE_RANGE:
2634 printf_filtered ("(TYPE_CODE_RANGE)");
2635 break;
2636 case TYPE_CODE_STRING:
2637 printf_filtered ("(TYPE_CODE_STRING)");
2638 break;
2639 case TYPE_CODE_BITSTRING:
2640 printf_filtered ("(TYPE_CODE_BITSTRING)");
2641 break;
2642 case TYPE_CODE_ERROR:
2643 printf_filtered ("(TYPE_CODE_ERROR)");
2644 break;
2645 case TYPE_CODE_MEMBERPTR:
2646 printf_filtered ("(TYPE_CODE_MEMBERPTR)");
2647 break;
2648 case TYPE_CODE_METHODPTR:
2649 printf_filtered ("(TYPE_CODE_METHODPTR)");
2650 break;
2651 case TYPE_CODE_METHOD:
2652 printf_filtered ("(TYPE_CODE_METHOD)");
2653 break;
2654 case TYPE_CODE_REF:
2655 printf_filtered ("(TYPE_CODE_REF)");
2656 break;
2657 case TYPE_CODE_CHAR:
2658 printf_filtered ("(TYPE_CODE_CHAR)");
2659 break;
2660 case TYPE_CODE_BOOL:
2661 printf_filtered ("(TYPE_CODE_BOOL)");
2662 break;
2663 case TYPE_CODE_COMPLEX:
2664 printf_filtered ("(TYPE_CODE_COMPLEX)");
2665 break;
2666 case TYPE_CODE_TYPEDEF:
2667 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2668 break;
2669 case TYPE_CODE_TEMPLATE:
2670 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2671 break;
2672 case TYPE_CODE_TEMPLATE_ARG:
2673 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2674 break;
2675 case TYPE_CODE_NAMESPACE:
2676 printf_filtered ("(TYPE_CODE_NAMESPACE)");
2677 break;
2678 default:
2679 printf_filtered ("(UNKNOWN TYPE CODE)");
2680 break;
2682 puts_filtered ("\n");
2683 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2684 printfi_filtered (spaces, "objfile ");
2685 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2686 printf_filtered ("\n");
2687 printfi_filtered (spaces, "target_type ");
2688 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2689 printf_filtered ("\n");
2690 if (TYPE_TARGET_TYPE (type) != NULL)
2692 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2694 printfi_filtered (spaces, "pointer_type ");
2695 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2696 printf_filtered ("\n");
2697 printfi_filtered (spaces, "reference_type ");
2698 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2699 printf_filtered ("\n");
2700 printfi_filtered (spaces, "type_chain ");
2701 gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
2702 printf_filtered ("\n");
2703 printfi_filtered (spaces, "instance_flags 0x%x",
2704 TYPE_INSTANCE_FLAGS (type));
2705 if (TYPE_CONST (type))
2707 puts_filtered (" TYPE_FLAG_CONST");
2709 if (TYPE_VOLATILE (type))
2711 puts_filtered (" TYPE_FLAG_VOLATILE");
2713 if (TYPE_CODE_SPACE (type))
2715 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2717 if (TYPE_DATA_SPACE (type))
2719 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2721 if (TYPE_ADDRESS_CLASS_1 (type))
2723 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
2725 if (TYPE_ADDRESS_CLASS_2 (type))
2727 puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
2729 puts_filtered ("\n");
2731 printfi_filtered (spaces, "flags");
2732 if (TYPE_UNSIGNED (type))
2734 puts_filtered (" TYPE_FLAG_UNSIGNED");
2736 if (TYPE_NOSIGN (type))
2738 puts_filtered (" TYPE_FLAG_NOSIGN");
2740 if (TYPE_STUB (type))
2742 puts_filtered (" TYPE_FLAG_STUB");
2744 if (TYPE_TARGET_STUB (type))
2746 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2748 if (TYPE_STATIC (type))
2750 puts_filtered (" TYPE_FLAG_STATIC");
2752 if (TYPE_PROTOTYPED (type))
2754 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2756 if (TYPE_INCOMPLETE (type))
2758 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2760 if (TYPE_VARARGS (type))
2762 puts_filtered (" TYPE_FLAG_VARARGS");
2764 /* This is used for things like AltiVec registers on ppc. Gcc emits
2765 an attribute for the array type, which tells whether or not we
2766 have a vector, instead of a regular array. */
2767 if (TYPE_VECTOR (type))
2769 puts_filtered (" TYPE_FLAG_VECTOR");
2771 if (TYPE_FIXED_INSTANCE (type))
2773 puts_filtered (" TYPE_FIXED_INSTANCE");
2775 if (TYPE_STUB_SUPPORTED (type))
2777 puts_filtered (" TYPE_STUB_SUPPORTED");
2779 if (TYPE_NOTTEXT (type))
2781 puts_filtered (" TYPE_NOTTEXT");
2783 puts_filtered ("\n");
2784 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
2785 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
2786 puts_filtered ("\n");
2787 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
2789 printfi_filtered (spaces + 2,
2790 "[%d] bitpos %d bitsize %d type ",
2791 idx, TYPE_FIELD_BITPOS (type, idx),
2792 TYPE_FIELD_BITSIZE (type, idx));
2793 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
2794 printf_filtered (" name '%s' (",
2795 TYPE_FIELD_NAME (type, idx) != NULL
2796 ? TYPE_FIELD_NAME (type, idx)
2797 : "<NULL>");
2798 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
2799 printf_filtered (")\n");
2800 if (TYPE_FIELD_TYPE (type, idx) != NULL)
2802 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
2805 printfi_filtered (spaces, "vptr_basetype ");
2806 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
2807 puts_filtered ("\n");
2808 if (TYPE_VPTR_BASETYPE (type) != NULL)
2810 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
2812 printfi_filtered (spaces, "vptr_fieldno %d\n",
2813 TYPE_VPTR_FIELDNO (type));
2814 switch (TYPE_CODE (type))
2816 case TYPE_CODE_STRUCT:
2817 printfi_filtered (spaces, "cplus_stuff ");
2818 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
2819 gdb_stdout);
2820 puts_filtered ("\n");
2821 print_cplus_stuff (type, spaces);
2822 break;
2824 case TYPE_CODE_FLT:
2825 printfi_filtered (spaces, "floatformat ");
2826 if (TYPE_FLOATFORMAT (type) == NULL)
2827 puts_filtered ("(null)");
2828 else
2830 puts_filtered ("{ ");
2831 if (TYPE_FLOATFORMAT (type)[0] == NULL
2832 || TYPE_FLOATFORMAT (type)[0]->name == NULL)
2833 puts_filtered ("(null)");
2834 else
2835 puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
2837 puts_filtered (", ");
2838 if (TYPE_FLOATFORMAT (type)[1] == NULL
2839 || TYPE_FLOATFORMAT (type)[1]->name == NULL)
2840 puts_filtered ("(null)");
2841 else
2842 puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
2844 puts_filtered (" }");
2846 puts_filtered ("\n");
2847 break;
2849 default:
2850 /* We have to pick one of the union types to be able print and
2851 test the value. Pick cplus_struct_type, even though we know
2852 it isn't any particular one. */
2853 printfi_filtered (spaces, "type_specific ");
2854 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2855 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
2857 printf_filtered (_(" (unknown data form)"));
2859 printf_filtered ("\n");
2860 break;
2863 if (spaces == 0)
2864 obstack_free (&dont_print_type_obstack, NULL);
2867 /* Trivial helpers for the libiberty hash table, for mapping one
2868 type to another. */
2870 struct type_pair
2872 struct type *old, *new;
2875 static hashval_t
2876 type_pair_hash (const void *item)
2878 const struct type_pair *pair = item;
2879 return htab_hash_pointer (pair->old);
2882 static int
2883 type_pair_eq (const void *item_lhs, const void *item_rhs)
2885 const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
2886 return lhs->old == rhs->old;
2889 /* Allocate the hash table used by copy_type_recursive to walk
2890 types without duplicates. We use OBJFILE's obstack, because
2891 OBJFILE is about to be deleted. */
2893 htab_t
2894 create_copied_types_hash (struct objfile *objfile)
2896 return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
2897 NULL, &objfile->objfile_obstack,
2898 hashtab_obstack_allocate,
2899 dummy_obstack_deallocate);
2902 /* Recursively copy (deep copy) TYPE, if it is associated with
2903 OBJFILE. Return a new type allocated using malloc, a saved type if
2904 we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
2905 not associated with OBJFILE. */
2907 struct type *
2908 copy_type_recursive (struct objfile *objfile,
2909 struct type *type,
2910 htab_t copied_types)
2912 struct type_pair *stored, pair;
2913 void **slot;
2914 struct type *new_type;
2916 if (TYPE_OBJFILE (type) == NULL)
2917 return type;
2919 /* This type shouldn't be pointing to any types in other objfiles;
2920 if it did, the type might disappear unexpectedly. */
2921 gdb_assert (TYPE_OBJFILE (type) == objfile);
2923 pair.old = type;
2924 slot = htab_find_slot (copied_types, &pair, INSERT);
2925 if (*slot != NULL)
2926 return ((struct type_pair *) *slot)->new;
2928 new_type = alloc_type (NULL);
2930 /* We must add the new type to the hash table immediately, in case
2931 we encounter this type again during a recursive call below. */
2932 stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
2933 stored->old = type;
2934 stored->new = new_type;
2935 *slot = stored;
2937 /* Copy the common fields of types. For the main type, we simply
2938 copy the entire thing and then update specific fields as needed. */
2939 *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
2940 TYPE_OBJFILE (new_type) = NULL;
2942 if (TYPE_NAME (type))
2943 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
2944 if (TYPE_TAG_NAME (type))
2945 TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
2947 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
2948 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
2950 /* Copy the fields. */
2951 if (TYPE_NFIELDS (type))
2953 int i, nfields;
2955 nfields = TYPE_NFIELDS (type);
2956 TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
2957 for (i = 0; i < nfields; i++)
2959 TYPE_FIELD_ARTIFICIAL (new_type, i) =
2960 TYPE_FIELD_ARTIFICIAL (type, i);
2961 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
2962 if (TYPE_FIELD_TYPE (type, i))
2963 TYPE_FIELD_TYPE (new_type, i)
2964 = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
2965 copied_types);
2966 if (TYPE_FIELD_NAME (type, i))
2967 TYPE_FIELD_NAME (new_type, i) =
2968 xstrdup (TYPE_FIELD_NAME (type, i));
2969 switch (TYPE_FIELD_LOC_KIND (type, i))
2971 case FIELD_LOC_KIND_BITPOS:
2972 SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
2973 TYPE_FIELD_BITPOS (type, i));
2974 break;
2975 case FIELD_LOC_KIND_PHYSADDR:
2976 SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
2977 TYPE_FIELD_STATIC_PHYSADDR (type, i));
2978 break;
2979 case FIELD_LOC_KIND_PHYSNAME:
2980 SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
2981 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
2982 i)));
2983 break;
2984 default:
2985 internal_error (__FILE__, __LINE__,
2986 _("Unexpected type field location kind: %d"),
2987 TYPE_FIELD_LOC_KIND (type, i));
2992 /* Copy pointers to other types. */
2993 if (TYPE_TARGET_TYPE (type))
2994 TYPE_TARGET_TYPE (new_type) =
2995 copy_type_recursive (objfile,
2996 TYPE_TARGET_TYPE (type),
2997 copied_types);
2998 if (TYPE_VPTR_BASETYPE (type))
2999 TYPE_VPTR_BASETYPE (new_type) =
3000 copy_type_recursive (objfile,
3001 TYPE_VPTR_BASETYPE (type),
3002 copied_types);
3003 /* Maybe copy the type_specific bits.
3005 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
3006 base classes and methods. There's no fundamental reason why we
3007 can't, but at the moment it is not needed. */
3009 if (TYPE_CODE (type) == TYPE_CODE_FLT)
3010 TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
3011 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3012 || TYPE_CODE (type) == TYPE_CODE_UNION
3013 || TYPE_CODE (type) == TYPE_CODE_TEMPLATE
3014 || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
3015 INIT_CPLUS_SPECIFIC (new_type);
3017 return new_type;
3020 /* Make a copy of the given TYPE, except that the pointer & reference
3021 types are not preserved.
3023 This function assumes that the given type has an associated objfile.
3024 This objfile is used to allocate the new type. */
3026 struct type *
3027 copy_type (const struct type *type)
3029 struct type *new_type;
3031 gdb_assert (TYPE_OBJFILE (type) != NULL);
3033 new_type = alloc_type (TYPE_OBJFILE (type));
3034 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
3035 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
3036 memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
3037 sizeof (struct main_type));
3039 return new_type;
3042 static struct type *
3043 build_flt (int bit, char *name, const struct floatformat **floatformats)
3045 struct type *t;
3047 if (bit == -1)
3049 gdb_assert (floatformats != NULL);
3050 gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
3051 bit = floatformats[0]->totalsize;
3053 gdb_assert (bit >= 0);
3055 t = init_type (TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, 0, name, NULL);
3056 TYPE_FLOATFORMAT (t) = floatformats;
3057 return t;
3060 static struct gdbarch_data *gdbtypes_data;
3062 const struct builtin_type *
3063 builtin_type (struct gdbarch *gdbarch)
3065 return gdbarch_data (gdbarch, gdbtypes_data);
3069 static struct type *
3070 build_complex (int bit, char *name, struct type *target_type)
3072 struct type *t;
3073 if (bit <= 0 || target_type == builtin_type_error)
3075 gdb_assert (builtin_type_error != NULL);
3076 return builtin_type_error;
3078 t = init_type (TYPE_CODE_COMPLEX, 2 * bit / TARGET_CHAR_BIT,
3079 0, name, (struct objfile *) NULL);
3080 TYPE_TARGET_TYPE (t) = target_type;
3081 return t;
3084 static void *
3085 gdbtypes_post_init (struct gdbarch *gdbarch)
3087 struct builtin_type *builtin_type
3088 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
3090 builtin_type->builtin_void =
3091 init_type (TYPE_CODE_VOID, 1,
3093 "void", (struct objfile *) NULL);
3094 builtin_type->builtin_char =
3095 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3096 (TYPE_FLAG_NOSIGN
3097 | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
3098 "char", (struct objfile *) NULL);
3099 builtin_type->builtin_signed_char =
3100 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3102 "signed char", (struct objfile *) NULL);
3103 builtin_type->builtin_unsigned_char =
3104 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3105 TYPE_FLAG_UNSIGNED,
3106 "unsigned char", (struct objfile *) NULL);
3107 builtin_type->builtin_short =
3108 init_type (TYPE_CODE_INT,
3109 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
3110 0, "short", (struct objfile *) NULL);
3111 builtin_type->builtin_unsigned_short =
3112 init_type (TYPE_CODE_INT,
3113 gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
3114 TYPE_FLAG_UNSIGNED, "unsigned short",
3115 (struct objfile *) NULL);
3116 builtin_type->builtin_int =
3117 init_type (TYPE_CODE_INT,
3118 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
3119 0, "int", (struct objfile *) NULL);
3120 builtin_type->builtin_unsigned_int =
3121 init_type (TYPE_CODE_INT,
3122 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
3123 TYPE_FLAG_UNSIGNED, "unsigned int",
3124 (struct objfile *) NULL);
3125 builtin_type->builtin_long =
3126 init_type (TYPE_CODE_INT,
3127 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
3128 0, "long", (struct objfile *) NULL);
3129 builtin_type->builtin_unsigned_long =
3130 init_type (TYPE_CODE_INT,
3131 gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
3132 TYPE_FLAG_UNSIGNED, "unsigned long",
3133 (struct objfile *) NULL);
3134 builtin_type->builtin_long_long =
3135 init_type (TYPE_CODE_INT,
3136 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
3137 0, "long long", (struct objfile *) NULL);
3138 builtin_type->builtin_unsigned_long_long =
3139 init_type (TYPE_CODE_INT,
3140 gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
3141 TYPE_FLAG_UNSIGNED, "unsigned long long",
3142 (struct objfile *) NULL);
3143 builtin_type->builtin_float
3144 = build_flt (gdbarch_float_bit (gdbarch), "float",
3145 gdbarch_float_format (gdbarch));
3146 builtin_type->builtin_double
3147 = build_flt (gdbarch_double_bit (gdbarch), "double",
3148 gdbarch_double_format (gdbarch));
3149 builtin_type->builtin_long_double
3150 = build_flt (gdbarch_long_double_bit (gdbarch), "long double",
3151 gdbarch_long_double_format (gdbarch));
3152 builtin_type->builtin_complex
3153 = build_complex (gdbarch_float_bit (gdbarch), "complex",
3154 builtin_type->builtin_float);
3155 builtin_type->builtin_double_complex
3156 = build_complex (gdbarch_double_bit (gdbarch), "double complex",
3157 builtin_type->builtin_double);
3158 builtin_type->builtin_string =
3159 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3161 "string", (struct objfile *) NULL);
3162 builtin_type->builtin_bool =
3163 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3165 "bool", (struct objfile *) NULL);
3167 /* The following three are about decimal floating point types, which
3168 are 32-bits, 64-bits and 128-bits respectively. */
3169 builtin_type->builtin_decfloat
3170 = init_type (TYPE_CODE_DECFLOAT, 32 / 8,
3172 "_Decimal32", (struct objfile *) NULL);
3173 builtin_type->builtin_decdouble
3174 = init_type (TYPE_CODE_DECFLOAT, 64 / 8,
3176 "_Decimal64", (struct objfile *) NULL);
3177 builtin_type->builtin_declong
3178 = init_type (TYPE_CODE_DECFLOAT, 128 / 8,
3180 "_Decimal128", (struct objfile *) NULL);
3182 /* Pointer/Address types. */
3184 /* NOTE: on some targets, addresses and pointers are not necessarily
3185 the same --- for example, on the D10V, pointers are 16 bits long,
3186 but addresses are 32 bits long. See doc/gdbint.texinfo,
3187 ``Pointers Are Not Always Addresses''.
3189 The upshot is:
3190 - gdb's `struct type' always describes the target's
3191 representation.
3192 - gdb's `struct value' objects should always hold values in
3193 target form.
3194 - gdb's CORE_ADDR values are addresses in the unified virtual
3195 address space that the assembler and linker work with. Thus,
3196 since target_read_memory takes a CORE_ADDR as an argument, it
3197 can access any memory on the target, even if the processor has
3198 separate code and data address spaces.
3200 So, for example:
3201 - If v is a value holding a D10V code pointer, its contents are
3202 in target form: a big-endian address left-shifted two bits.
3203 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3204 sizeof (void *) == 2 on the target.
3206 In this context, builtin_type->CORE_ADDR is a bit odd: it's a
3207 target type for a value the target will never see. It's only
3208 used to hold the values of (typeless) linker symbols, which are
3209 indeed in the unified virtual address space. */
3211 builtin_type->builtin_data_ptr =
3212 make_pointer_type (builtin_type->builtin_void, NULL);
3213 builtin_type->builtin_func_ptr =
3214 lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
3215 builtin_type->builtin_core_addr =
3216 init_type (TYPE_CODE_INT,
3217 gdbarch_addr_bit (gdbarch) / 8,
3218 TYPE_FLAG_UNSIGNED,
3219 "__CORE_ADDR", (struct objfile *) NULL);
3222 /* The following set of types is used for symbols with no
3223 debug information. */
3224 builtin_type->nodebug_text_symbol =
3225 init_type (TYPE_CODE_FUNC, 1, 0,
3226 "<text variable, no debug info>", NULL);
3227 TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol) =
3228 builtin_type->builtin_int;
3229 builtin_type->nodebug_data_symbol =
3230 init_type (TYPE_CODE_INT,
3231 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
3232 "<data variable, no debug info>", NULL);
3233 builtin_type->nodebug_unknown_symbol =
3234 init_type (TYPE_CODE_INT, 1, 0,
3235 "<variable (not text or data), no debug info>", NULL);
3236 builtin_type->nodebug_tls_symbol =
3237 init_type (TYPE_CODE_INT,
3238 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
3239 "<thread local variable, no debug info>", NULL);
3241 return builtin_type;
3244 extern void _initialize_gdbtypes (void);
3245 void
3246 _initialize_gdbtypes (void)
3248 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
3250 /* FIXME: The following types are architecture-neutral. However,
3251 they contain pointer_type and reference_type fields potentially
3252 caching pointer or reference types that *are* architecture
3253 dependent. */
3255 builtin_type_int0 =
3256 init_type (TYPE_CODE_INT, 0 / 8,
3258 "int0_t", (struct objfile *) NULL);
3259 builtin_type_int8 =
3260 init_type (TYPE_CODE_INT, 8 / 8,
3261 TYPE_FLAG_NOTTEXT,
3262 "int8_t", (struct objfile *) NULL);
3263 builtin_type_uint8 =
3264 init_type (TYPE_CODE_INT, 8 / 8,
3265 TYPE_FLAG_UNSIGNED | TYPE_FLAG_NOTTEXT,
3266 "uint8_t", (struct objfile *) NULL);
3267 builtin_type_int16 =
3268 init_type (TYPE_CODE_INT, 16 / 8,
3270 "int16_t", (struct objfile *) NULL);
3271 builtin_type_uint16 =
3272 init_type (TYPE_CODE_INT, 16 / 8,
3273 TYPE_FLAG_UNSIGNED,
3274 "uint16_t", (struct objfile *) NULL);
3275 builtin_type_int32 =
3276 init_type (TYPE_CODE_INT, 32 / 8,
3278 "int32_t", (struct objfile *) NULL);
3279 builtin_type_uint32 =
3280 init_type (TYPE_CODE_INT, 32 / 8,
3281 TYPE_FLAG_UNSIGNED,
3282 "uint32_t", (struct objfile *) NULL);
3283 builtin_type_int64 =
3284 init_type (TYPE_CODE_INT, 64 / 8,
3286 "int64_t", (struct objfile *) NULL);
3287 builtin_type_uint64 =
3288 init_type (TYPE_CODE_INT, 64 / 8,
3289 TYPE_FLAG_UNSIGNED,
3290 "uint64_t", (struct objfile *) NULL);
3291 builtin_type_int128 =
3292 init_type (TYPE_CODE_INT, 128 / 8,
3294 "int128_t", (struct objfile *) NULL);
3295 builtin_type_uint128 =
3296 init_type (TYPE_CODE_INT, 128 / 8,
3297 TYPE_FLAG_UNSIGNED,
3298 "uint128_t", (struct objfile *) NULL);
3300 builtin_type_ieee_single =
3301 build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single);
3302 builtin_type_ieee_double =
3303 build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double);
3304 builtin_type_i387_ext =
3305 build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext);
3306 builtin_type_m68881_ext =
3307 build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext);
3308 builtin_type_arm_ext =
3309 build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext);
3310 builtin_type_ia64_spill =
3311 build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill);
3312 builtin_type_ia64_quad =
3313 build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad);
3315 builtin_type_void =
3316 init_type (TYPE_CODE_VOID, 1,
3318 "void", (struct objfile *) NULL);
3319 builtin_type_true_char =
3320 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3322 "true character", (struct objfile *) NULL);
3323 builtin_type_true_unsigned_char =
3324 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3325 TYPE_FLAG_UNSIGNED,
3326 "true character", (struct objfile *) NULL);
3328 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
3329 Set debugging of C++ overloading."), _("\
3330 Show debugging of C++ overloading."), _("\
3331 When enabled, ranking of the functions is displayed."),
3332 NULL,
3333 show_overload_debug,
3334 &setdebuglist, &showdebuglist);
3336 /* Add user knob for controlling resolution of opaque types. */
3337 add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
3338 &opaque_type_resolution, _("\
3339 Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
3340 Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL,
3341 NULL,
3342 show_opaque_type_resolution,
3343 &setlist, &showlist);