Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "André Pönitz" <andre.poenitz@nokia.com>
To: gdb@sourceware.org
Subject: Re: cast in gdb python results in virtual baseclass botch
Date: Wed, 13 Apr 2011 17:29:00 -0000	[thread overview]
Message-ID: <201104131929.46854.andre.poenitz@nokia.com> (raw)
In-Reply-To: <BANLkTikQGvoL600knsPZgA6aig1XyKM9pA@mail.gmail.com>

On Wednesday 13 April 2011 19:08:17 ext Christoph Mathys wrote:
> On Wed, Apr 13, 2011 at 5:26 PM, André Pönitz <andre.poenitz@nokia.com> wrote:
> > I don't think you have to cast.
> >
> > inner = item.value["px"].dereference()   has already the correct type.
> 
> I expressed myself badly:
> 
> class XmlNodeInterface
> { };
> class XmlNode : public XmlNodeInterface
> {
>  xmlNode* m_pNode;
> };
> 
> I've got a reference to a "shared_ptr<IXmlNode>", and I want m_pNode.
> So after I extracted px, I think I have to downcast from IXmlNode to XmlNode

Then

 item.value["px"].dereference().cast(gdb.lookup_type("IXmlNode").pointer())["m_pNode"]

or something similar might do the trick.

Regards,
Andre'


PS: In similar cases I use a 'lookupType' function defined as follows:

typeInfoCache = {}

def lookupType(typestring):
    type = typeCache.get(typestring)
    if type is None:
        ts = typestring
        while True:
            if ts.startswith("class "):
                ts = ts[6:]
            elif ts.startswith("struct "):
                ts = ts[7:]
            elif ts.startswith("const "):
                ts = ts[6:]
            elif ts.startswith("volatile "):
                ts = ts[9:]
            elif ts.startswith("enum "):
                ts = ts[5:]
            elif ts.endswith("const"):
                ts = ts[-5:]
            elif ts.endswith("volatile"):
                ts = ts[-8:]
            else:
                break
        try:
            type = gdb.lookup_type(ts)
        except RuntimeError, error:
            # See http://sourceware.org/bugzilla/show_bug.cgi?id=11912
            exp = "(class '%s'*)0" % ts
            try:
                type = parseAndEvaluate(exp).type.target()
            except:
                # Can throw "RuntimeError: No type named class Foo."
                pass
        except:
            pass
        typeCache[typestring] = type
    if type is None and typestring.endswith('*'):
        type = lookupType(typestring[0:-1])
        if not type is None:
            type = type.pointer()
            typeCache[typestring] = type
    if type is None:
        # could be gdb.lookup_type("char[3]") generating
        # "RuntimeError: No type named char[3]"
        pass
    return type


  parent reply	other threads:[~2011-04-13 17:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-13 14:59 Christoph Mathys
2011-04-13 15:27 ` André Pönitz
2011-04-13 17:08   ` Christoph Mathys
2011-04-13 17:09     ` Christoph Mathys
2011-04-13 17:29     ` André Pönitz [this message]
2011-04-14 13:45       ` Christoph Mathys
2011-04-14 16:03 ` Tom Tromey

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=201104131929.46854.andre.poenitz@nokia.com \
    --to=andre.poenitz@nokia.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