diff options
-rw-r--r-- | gdb/ChangeLog | 13 | ||||
-rw-r--r-- | gdb/dwarf2read.c | 2 | ||||
-rw-r--r-- | gdb/gdbtypes.c | 59 | ||||
-rw-r--r-- | gdb/gdbtypes.h | 2 | ||||
-rw-r--r-- | gdb/hp-symtab-read.c | 3 | ||||
-rw-r--r-- | gdb/stabsread.c | 2 |
6 files changed, 73 insertions, 8 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b29b15d..6b54dfa 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2001-12-07 Daniel Jacobowitz <drow@mvista.com> + + * gdbtypes.c (finish_cv_type): New function. + (check_typedef): Remove ``register'' keyword from argument. + Preserve const and volatile attributes across filling in + opaque types. + * gdbtypes.h (finish_cv_type): Add prototype. + + * hp-symtab-read.c (hpread_read_struct_type): Call finish_cv_type. + * stabsread.c (read_struct_type): Likewise. + * dwarf2read.c (read_structure_scope): Likewise. Remove redundant + assignment to die->type. + 2001-12-07 Jim Blandy <jimb@redhat.com> * printcmd.c (print_scalar_formatted): Compare the length of the diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index a788efb..7e1e2ce 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -2381,7 +2381,7 @@ read_structure_scope (struct die_info *die, struct objfile *objfile, TYPE_FLAGS (type) |= TYPE_FLAG_STUB; } - die->type = type; + finish_cv_type (die->type); } /* Given a pointer to a die which begins an enumeration, process all diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 8a941de..6a8fe1f 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -36,6 +36,7 @@ #include "gdbcmd.h" #include "wrapper.h" #include "cp-abi.h" +#include "gdb_assert.h" /* These variables point to the objects representing the predefined C data types. */ @@ -469,8 +470,51 @@ make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr) return ntype; } +/* When reading in a class type, we may have created references to + cv-qualified versions of the type (in method arguments, for + instance). Update everything on the cv ring from the primary + type TYPE. + The only reason we do not need to do the same thing for address + spaces is that type readers do not create address space qualified + types. */ +void +finish_cv_type (struct type *type) +{ + struct type *ntype, *cv_type, *ptr_type, *ref_type; + int cv_flags; + + gdb_assert (!TYPE_CONST (type) && !TYPE_VOLATILE (type)); + + ntype = type; + while ((ntype = TYPE_CV_TYPE (ntype)) != type) + { + /* Save cv_flags. */ + cv_flags = TYPE_FLAGS (ntype) & (TYPE_FLAG_VOLATILE | TYPE_FLAG_CONST); + + /* If any reference or pointer types were created, save them too. */ + ptr_type = TYPE_POINTER_TYPE (ntype); + ref_type = TYPE_REFERENCE_TYPE (ntype); + + /* Don't disturb the CV chain. */ + cv_type = TYPE_CV_TYPE (ntype); + + /* Verify that we haven't added any address-space qualified types, + for the future. */ + gdb_assert (ntype == TYPE_AS_TYPE (ntype)); + + /* Copy original type */ + memcpy ((char *) ntype, (char *) type, sizeof (struct type)); + /* Restore everything. */ + TYPE_POINTER_TYPE (ntype) = ptr_type; + TYPE_REFERENCE_TYPE (ntype) = ref_type; + TYPE_CV_TYPE (ntype) = cv_type; + TYPE_FLAGS (ntype) = TYPE_FLAGS (ntype) | cv_flags; + + TYPE_AS_TYPE (ntype) = ntype; + } +} /* Implement direct support for MEMBER_TYPE in GNU C++. May need to construct such a type if this is the first use. @@ -1144,9 +1188,11 @@ struct complaint stub_noname_complaint = {"stub type has NULL name", 0, 0}; struct type * -check_typedef (register struct type *type) +check_typedef (struct type *type) { struct type *orig_type = type; + int is_const, is_volatile; + while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) { if (!TYPE_TARGET_TYPE (type)) @@ -1179,6 +1225,9 @@ check_typedef (register struct type *type) type = TYPE_TARGET_TYPE (type); } + is_const = TYPE_CONST (type); + is_volatile = TYPE_VOLATILE (type); + /* If this is a struct/class/union with no fields, then check whether a full definition exists somewhere else. This is for systems where a type definition with no fields is issued for such types, instead of @@ -1195,9 +1244,7 @@ check_typedef (register struct type *type) } newtype = lookup_transparent_type (name); if (newtype) - { - memcpy ((char *) type, (char *) newtype, sizeof (struct type)); - } + make_cv_type (is_const, is_volatile, newtype, &type); } /* Otherwise, rely on the stub flag being set for opaque/stubbed types */ else if ((TYPE_FLAGS (type) & TYPE_FLAG_STUB) && !currently_reading_symtab) @@ -1215,9 +1262,7 @@ check_typedef (register struct type *type) } sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL); if (sym) - { - memcpy ((char *) type, (char *) SYMBOL_TYPE (sym), sizeof (struct type)); - } + make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type); } if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB) diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 3bc8131..de27f8e 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1037,6 +1037,8 @@ extern struct type *make_reference_type (struct type *, struct type **); extern struct type *make_cv_type (int, int, struct type *, struct type **); +extern void finish_cv_type (struct type *); + extern int address_space_name_to_int (char *); extern char *address_space_int_to_name (int); diff --git a/gdb/hp-symtab-read.c b/gdb/hp-symtab-read.c index 9898cfc..57665ff 100644 --- a/gdb/hp-symtab-read.c +++ b/gdb/hp-symtab-read.c @@ -2018,6 +2018,9 @@ hpread_read_struct_type (dnttpointer hp_type, union dnttentry *dn_bufp, /* Clear the global saying what template we are in the middle of processing */ current_template = NULL; + /* Fix up any cv-qualified versions of this type. */ + finish_cv_type (type); + return type; } diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 2063923..8a46acf 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -4090,6 +4090,8 @@ read_struct_type (char **pp, struct type *type, struct objfile *objfile) type = error_type (pp, objfile); } + /* Fix up any cv-qualified versions of this type. */ + finish_cv_type (type); do_cleanups (back_to); return (type); } |