From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19232 invoked by alias); 6 Dec 2001 23:12:03 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 19058 invoked from network); 6 Dec 2001 23:11:53 -0000 Received: from unknown (HELO nevyn.them.org) (128.2.145.6) by sources.redhat.com with SMTP; 6 Dec 2001 23:11:53 -0000 Received: from drow by nevyn.them.org with local (Exim 3.33 #1 (Debian)) id 16C7gt-0006s1-00 for ; Thu, 06 Dec 2001 18:12:31 -0500 Date: Thu, 06 Dec 2001 15:12:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sources.redhat.com Subject: [rfa] Build cv-qualified types correctly Message-ID: <20011206181231.A26281@nevyn.them.org> Mail-Followup-To: gdb-patches@sources.redhat.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.23i X-SW-Source: 2001-12/txt/msg00181.txt.bz2 We call make_cv_type mostly on unfinished types. We then later decide they are opaque (nfields == 0), and go to look them up. That's a bug. We then look up just the name and discard cv-qualifiers. That's a bug too. This patch fixes both. Needed for my 3.0/dwarf2 work, no regressions on 2.95.3/stabs/x86-linux. Fixes the missing "const" I referenced in a previous message today. OK to commit? -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer 2001-12-06 Daniel Jacobowitz * 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. Index: dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.36 diff -u -p -r1.36 dwarf2read.c --- dwarf2read.c 2001/11/29 13:19:05 1.36 +++ dwarf2read.c 2001/12/06 22:33:17 @@ -2364,7 +2364,7 @@ read_structure_scope (struct die_info *d 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 Index: gdbtypes.c =================================================================== RCS file: /cvs/src/src/gdb/gdbtypes.c,v retrieving revision 1.28 diff -u -p -r1.28 gdbtypes.c --- gdbtypes.c 2001/11/15 01:55:59 1.28 +++ gdbtypes.c 2001/12/06 22:33:17 @@ -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,9 +470,52 @@ make_cv_type (int cnst, int voltl, struc 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. The TYPE is the type of the member. The DOMAIN is the type @@ -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 *typ 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 *typ } 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 *typ } 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) Index: gdbtypes.h =================================================================== RCS file: /cvs/src/src/gdb/gdbtypes.h,v retrieving revision 1.18 diff -u -p -r1.18 gdbtypes.h --- gdbtypes.h 2001/11/15 01:55:59 1.18 +++ gdbtypes.h 2001/12/06 22:33:18 @@ -1037,6 +1037,8 @@ extern struct type *make_reference_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); Index: hp-symtab-read.c =================================================================== RCS file: /cvs/src/src/gdb/hp-symtab-read.c,v retrieving revision 1.7 diff -u -p -r1.7 hp-symtab-read.c --- hp-symtab-read.c 2001/05/12 03:18:33 1.7 +++ hp-symtab-read.c 2001/12/06 22:33:18 @@ -2018,6 +2018,9 @@ hpread_read_struct_type (dnttpointer hp_ /* 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; } Index: stabsread.c =================================================================== RCS file: /cvs/src/src/gdb/stabsread.c,v retrieving revision 1.16 diff -u -p -r1.16 stabsread.c --- stabsread.c 2001/09/24 17:16:53 1.16 +++ stabsread.c 2001/12/06 22:33:19 @@ -4090,6 +4129,8 @@ read_struct_type (char **pp, struct type type = error_type (pp, objfile); } + /* Fix up any cv-qualified versions of this type. */ + finish_cv_type (type); do_cleanups (back_to); return (type); }