cast in gdb python results in virtual baseclass botch
André Pönitz
andre.poenitz@nokia.com
Wed Apr 13 17:29:00 GMT 2011
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
More information about the Gdb
mailing list