Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* cast in gdb python results in virtual baseclass botch
@ 2011-04-13 14:59 Christoph Mathys
  2011-04-13 15:27 ` André Pönitz
  2011-04-14 16:03 ` Tom Tromey
  0 siblings, 2 replies; 7+ messages in thread
From: Christoph Mathys @ 2011-04-13 14:59 UTC (permalink / raw)
  To: gdb

I try to cast a gdb.Value to another type. There are cases where it
works, and others where it doesn't, and I don't really know why. If it
doesn't work, I get the following exception when I call cast():
RuntimeError: virtual baseclass botch

I use gdb 7.2, which apparently does not yet support dynamic_cast().

Both variables are stored inside a boost::shared_ptr, and I try to
cast to contained interface pointer to a specific implementation
pointer.

Christoph


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: cast in gdb python results in virtual baseclass botch
  2011-04-13 14:59 cast in gdb python results in virtual baseclass botch Christoph Mathys
@ 2011-04-13 15:27 ` André Pönitz
  2011-04-13 17:08   ` Christoph Mathys
  2011-04-14 16:03 ` Tom Tromey
  1 sibling, 1 reply; 7+ messages in thread
From: André Pönitz @ 2011-04-13 15:27 UTC (permalink / raw)
  To: gdb

On Wednesday 13 April 2011 16:59:49 ext Christoph Mathys wrote:
> I try to cast a gdb.Value to another type. There are cases where it
> works, and others where it doesn't, and I don't really know why. If it
> doesn't work, I get the following exception when I call cast():
> RuntimeError: virtual baseclass botch
> 
> I use gdb 7.2, which apparently does not yet support dynamic_cast().
> 
> Both variables are stored inside a boost::shared_ptr, and I try to
> cast to contained interface pointer to a specific implementation
> pointer.

I don't think you have to cast. 

inner = item.value["px"].dereference()   has already the correct type.

Andre'


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: cast in gdb python results in virtual baseclass botch
  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
  0 siblings, 2 replies; 7+ messages in thread
From: Christoph Mathys @ 2011-04-13 17:08 UTC (permalink / raw)
  To: gdb

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.

Christoph


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: cast in gdb python results in virtual baseclass botch
  2011-04-13 17:08   ` Christoph Mathys
@ 2011-04-13 17:09     ` Christoph Mathys
  2011-04-13 17:29     ` André Pönitz
  1 sibling, 0 replies; 7+ messages in thread
From: Christoph Mathys @ 2011-04-13 17:09 UTC (permalink / raw)
  To: gdb

> 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.

And this should of course have been a "shared_ptr<XmlNodeInterface>".


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: cast in gdb python results in virtual baseclass botch
  2011-04-13 17:08   ` Christoph Mathys
  2011-04-13 17:09     ` Christoph Mathys
@ 2011-04-13 17:29     ` André Pönitz
  2011-04-14 13:45       ` Christoph Mathys
  1 sibling, 1 reply; 7+ messages in thread
From: André Pönitz @ 2011-04-13 17:29 UTC (permalink / raw)
  To: gdb

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: cast in gdb python results in virtual baseclass botch
  2011-04-13 17:29     ` André Pönitz
@ 2011-04-14 13:45       ` Christoph Mathys
  0 siblings, 0 replies; 7+ messages in thread
From: Christoph Mathys @ 2011-04-14 13:45 UTC (permalink / raw)
  To: gdb

On Wed, Apr 13, 2011 at 7:29 PM, André Pönitz <andre.poenitz@nokia.com> wrote:
> 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:
>>
> Then
>
>  item.value["px"].dereference().cast(gdb.lookup_type("IXmlNode").pointer())["m_pNode"]
>
> or something similar might do the trick.

Thanks for the input. That's what I do really, except that I cast to
XmlNode pointer and not the interface. The cast works for most of the
instance variables, except for some, and I don't know why. But well,
it is good enough for now...

Christoph


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: cast in gdb python results in virtual baseclass botch
  2011-04-13 14:59 cast in gdb python results in virtual baseclass botch Christoph Mathys
  2011-04-13 15:27 ` André Pönitz
@ 2011-04-14 16:03 ` Tom Tromey
  1 sibling, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2011-04-14 16:03 UTC (permalink / raw)
  To: Christoph Mathys; +Cc: gdb

>>>>> "Christoph" == Christoph Mathys <eraserix@gmail.com> writes:

Christoph> RuntimeError: virtual baseclass botch

Christoph> I use gdb 7.2, which apparently does not yet support dynamic_cast().

Christoph> Both variables are stored inside a boost::shared_ptr, and I try to
Christoph> cast to contained interface pointer to a specific implementation
Christoph> pointer.

Can you make a small, self-contained example program showing the bug?
That would be very helpful.

I am not sure under what circumstances "virtual baseclass botch" can
show up.  The code is obscure.

Tom


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-04-14 16:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-13 14:59 cast in gdb python results in virtual baseclass botch 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
2011-04-14 13:45       ` Christoph Mathys
2011-04-14 16:03 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox