From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29648 invoked by alias); 27 Nov 2001 05:36:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.cygnus.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 29568 invoked from network); 27 Nov 2001 05:36:43 -0000 Received: from unknown (HELO nevyn.them.org) (128.2.145.6) by hostedprojects.ges.redhat.com with SMTP; 27 Nov 2001 05:36:43 -0000 Received: from drow by nevyn.them.org with local (Exim 3.32 #1 (Debian)) id 168avT-0001X4-00; Tue, 27 Nov 2001 00:36:59 -0500 Date: Wed, 14 Nov 2001 00:12:00 -0000 From: Daniel Jacobowitz To: Jim Blandy Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA/c++] Fix printing classes with virtual base classes Message-ID: <20011127003659.A3965@nevyn.them.org> Mail-Followup-To: Jim Blandy , gdb-patches@sources.redhat.com References: <20011126201945.A27754@nevyn.them.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.23i X-SW-Source: 2001-11/txt/msg00267.txt.bz2 Message-ID: <20011114001200.-1UPC1s5sp0-aF1X76oH9TOy2WmAkabKicPrNcNqw-Y@z> On Mon, Nov 26, 2001 at 11:39:34PM -0500, Jim Blandy wrote: > > I'm with you on VALUE_OFFSET and VALUE_EMBEDDED_OFFSET. I'm pretty > sure VALUE_OFFSET can be eliminated from GDB entirely, with some minor > changes to the representation of subvalues of registers and > convenience variables. I am exceedingly tempted to do this. > Can you explain exactly what TYPE_VPTR_FIELDNO means, and how it works > in heavily derived classes? What I think you're basically doing there > is taking the address of the field indicated by TYPE_VPTR_FIELDNO, > casting that to a void *, and then casting that to the `struct > gdb_gnu_v3_abi_vtable' type. I have this vague memory that maybe > using TYPE_VPTR_FIELDNO correctly would fix that. I certainly can't explain it :) This code mostly mystifies me. It seems that the vptr for a given class is always a field of the class, and may actually overlap where the vptr for its first virtual base class. TYPE_VPTR_FIELDNO tells us where it is. For example, in GCC 2.x, this code: class Foo { int bar; public: virtual int thug() { return 1; } }; class Foo2 { int bar2; }; class Baz : public Foo2, public Foo { int baz; public: virtual int thugs() { return 1; } }; will cause vptr_fieldno for Baz to be 1, indicating its vptr is stored in memory at the beginning of field 1. Gnu v2 code handles this by casting the Baz to a Foo, at which point magic happens, and somehow the vptr is visible. This suggests that my fix is not the best way of doing it, and I should be using TYPE_VPTR_BASETYPE somehow instead. I may need to think some more. Upon further reflection, TYPE_VPTR_FIELDNO is supposed to be a field index in TYPE_VPTR_BASETYPE. Interesting. I think there's something wrong here; more comments tomorrow. > I wonder if that dereferencing code could be simplified with a > judicious use of `lookup_pointer_type (vtable_type)' and > `value_deref'... I suppose it would read simpler if I took a value_addr () and cast a bit. But magic happens in value casting that I don't want to happen. -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer