Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Paul Marquess <Paul.Marquess@owmobility.com>
To: "gdb@sourceware.org" <gdb@sourceware.org>
Subject: RE: getting subclass type from base class pointer
Date: Thu, 29 Oct 2015 23:38:00 -0000	[thread overview]
Message-ID: <CY1PR0501MB11786B043D21E72D27B73A8D95200@CY1PR0501MB1178.namprd05.prod.outlook.com> (raw)
In-Reply-To: <CY1PR0501MB1178C26EDF7B171D6BDAE33E95200@CY1PR0501MB1178.namprd05.prod.outlook.com>

> From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On Behalf Of Paul Marquess
> 
> I must be missing something obvious, so apologies upfront.
> 
> Consider this simple snippet of C++
> 
> 
> class SuperClass
> {
> };
> 
> class SubClass : public SuperClass
> {
> };
> 
> int main()
> {
>     SuperClass* pTest = new SubClass;
> 
>     delete pTest; // << Break here in GDB }
> 
> Using the python API I'm trying to determine the type of object that pTest points to. 
> 
> 
> gdb) python x = gdb.parse_and_eval("pTest")
> (gdb) python print x.type
> SuperClass *
> (gdb) python print x.dereference().type
> SuperClass
> 
> How do I get at the SubClass object using the Python API?


Quick follow-up to my own post, the actual code I'm working with is more like shown below, so I there should be a vtable in play. 
Same question - how get at the SubClass object if I have a pointer to a SuperClass object using the Python API?


class SuperClass 
{
    public:
    virtual int fred() { return 1; }
    SuperClass() {}
    virtual ~SuperClass() {}
};

class SubClass : public SuperClass 
{
    public:
    virtual int fred() { return 2 ;}
    SubClass() {}
    virtual ~SubClass() {}
};

int main()
{
    SuperClass* pTest = new SubClass;

    delete pTest;
}


  reply	other threads:[~2015-10-29 23:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-29 19:41 Paul Marquess
2015-10-29 23:38 ` Paul Marquess [this message]
2015-10-30  7:20   ` André Pönitz
2015-10-30 11:26     ` Paul Marquess

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=CY1PR0501MB11786B043D21E72D27B73A8D95200@CY1PR0501MB1178.namprd05.prod.outlook.com \
    --to=paul.marquess@owmobility.com \
    --cc=gdb@sourceware.org \
    /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