Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Berlin <dan@cgsoftware.com>
To: Daniel Jacobowitz <drow@mvista.com>
Cc: Jim Blandy <jimb@zwingli.cygnus.com>, <gdb-patches@sources.redhat.com>
Subject: Re: [RFA/c++] Fix printing classes with virtual base classes
Date: Mon, 26 Nov 2001 22:05:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.33.0111270041310.5497-100000@www.cgsoftware.com> (raw)
In-Reply-To: <20011127003659.A3965@nevyn.them.org>

On Tue, 27 Nov 2001, Daniel Jacobowitz wrote:

> 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's taking advantage of g++ magic.
I didn't add it, and have wanted to rid us of it for years.
It's evil.
It's a a field that g++ uses internally to track where the
virtual function table is.
If you want to see how fragile C++ support is in gdb, change the vfield
name in gcc/cp/cp-tree.h and watch what happens.

While you are there, notice that they don't use $ to begin it because it
confuses gdb (bad), and that it actually won't match the string we test
against, depending on what the assembler supports in terms of label names
(It might be __vptr_a instead of _vptr.a).
Cute, no?

> It seems that the vptr for a given class is always a field of the class,
Yes, it has to be, g++ generates them.

However, be aware that they may not always be correct at all times during
execution.
I see comments like this in the g++ code
/* If this class uses a different vtable than its primary base
         then when we will need to initialize our vptr after the base
         class constructor runs.  */
Giving me the impression that it can be very dangerous to rely on them at
all times in gdb.
GCC knows when it's safe to use them, because it's generating the code.
We don't.


> and may actually overlap where the vptr for its first virtual base
> class.

It's going to depend on a number of factors.
>   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.

Yes.
>   Interesting.  I think there's something
> wrong here; more comments tomorrow.
Wouldn't surprise me a bit.
>
> > 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.



WARNING: multiple messages have this Message-ID
From: Daniel Berlin <dan@cgsoftware.com>
To: Daniel Jacobowitz <drow@mvista.com>
Cc: Jim Blandy <jimb@zwingli.cygnus.com>, <gdb-patches@sources.redhat.com>
Subject: Re: [RFA/c++] Fix printing classes with virtual base classes
Date: Wed, 14 Nov 2001 00:15:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.33.0111270041310.5497-100000@www.cgsoftware.com> (raw)
Message-ID: <20011114001500.owSudccVxY0RLdqeXqGaC2p0a7X3xvTmJRDqZ-wIgO0@z> (raw)
In-Reply-To: <20011127003659.A3965@nevyn.them.org>



On Tue, 27 Nov 2001, Daniel Jacobowitz wrote:

> 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's taking advantage of g++ magic.
I didn't add it, and have wanted to rid us of it for years.
It's evil.
It's a a field that g++ uses internally to track where the
virtual function table is.
If you want to see how fragile C++ support is in gdb, change the vfield
name in gcc/cp/cp-tree.h and watch what happens.

While you are there, notice that they don't use $ to begin it because it
confuses gdb (bad), and that it actually won't match the string we test
against, depending on what the assembler supports in terms of label names
(It might be __vptr_a instead of _vptr.a).
Cute, no?

> It seems that the vptr for a given class is always a field of the class,
Yes, it has to be, g++ generates them.

However, be aware that they may not always be correct at all times during
execution.
I see comments like this in the g++ code
/* If this class uses a different vtable than its primary base
         then when we will need to initialize our vptr after the base
         class constructor runs.  */
Giving me the impression that it can be very dangerous to rely on them at
all times in gdb.
GCC knows when it's safe to use them, because it's generating the code.
We don't.


> and may actually overlap where the vptr for its first virtual base
> class.

It's going to depend on a number of factors.
>   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.

Yes.
>   Interesting.  I think there's something
> wrong here; more comments tomorrow.
Wouldn't surprise me a bit.
>
> > 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.



  parent reply	other threads:[~2001-11-26 22:05 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-13  9:24 Daniel Jacobowitz
2001-11-13  9:24 ` Daniel Jacobowitz
2001-11-13  9:34   ` Kevin Buettner
2001-11-26 18:25     ` Kevin Buettner
2001-11-26 21:07     ` Andrew Cagney
2001-11-13 21:56       ` Andrew Cagney
2001-11-14 22:09       ` Jim Blandy
2001-11-27 12:48         ` Jim Blandy
2001-11-26 18:02   ` Daniel Jacobowitz
2001-11-13 18:02 ` Jim Blandy
2001-11-14  9:33   ` Daniel Jacobowitz
2001-11-14 22:39     ` Jim Blandy
2001-11-14 22:41       ` Daniel Jacobowitz
2001-11-27 13:26         ` Daniel Jacobowitz
2001-11-21 13:03       ` Daniel Jacobowitz
2001-11-22 13:53         ` Jim Blandy
2001-11-30 11:42           ` Jim Blandy
2001-11-29 22:41         ` Daniel Jacobowitz
2001-11-30  8:48         ` Andrew Cagney
2001-11-21 17:30           ` Andrew Cagney
2001-11-30  8:57           ` Daniel Jacobowitz
2001-11-21 23:07             ` Daniel Jacobowitz
2001-11-27 13:16       ` Jim Blandy
2001-11-26 23:08     ` Daniel Jacobowitz
2001-11-26 20:38   ` Jim Blandy
2001-11-26 21:36   ` Daniel Jacobowitz
2001-11-14  0:12     ` Daniel Jacobowitz
2001-11-26 22:05     ` Daniel Berlin [this message]
2001-11-14  0:15       ` Daniel Berlin
2001-11-27  7:15     ` Jim Blandy
2001-11-14 13:02       ` Jim Blandy
2001-11-27  7:45       ` Daniel Jacobowitz
2001-11-14 13:55         ` Daniel Jacobowitz
2001-11-26 17:19 ` Daniel Jacobowitz
2001-11-15 14:06 Michael Elizabeth Chastain
2001-11-16 11:52 ` Daniel Berlin
2001-11-27 20:49   ` Daniel Berlin
2001-11-27 20:38 ` Michael Elizabeth Chastain
2001-11-30  9:00 Michael Elizabeth Chastain
2001-11-21 23:07 ` Michael Elizabeth Chastain
2001-11-22  3:17 ` Daniel Jacobowitz
2001-11-30  9:52   ` Daniel Jacobowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.33.0111270041310.5497-100000@www.cgsoftware.com \
    --to=dan@cgsoftware.com \
    --cc=drow@mvista.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=jimb@zwingli.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox