From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6551 invoked by alias); 13 Apr 2011 17:29:54 -0000 Received: (qmail 6541 invoked by uid 22791); 13 Apr 2011 17:29:52 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp.nokia.com (HELO mgw-da02.nokia.com) (147.243.128.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Apr 2011 17:29:47 +0000 Received: from gar.localnet (bettdhcp167187.europe.nokia.com [172.25.167.187]) by mgw-da02.nokia.com (Switch-3.4.3/Switch-3.4.3) with ESMTP id p3DHTkhI003084 for ; Wed, 13 Apr 2011 20:29:46 +0300 From: =?utf-8?q?Andr=C3=A9_P=C3=B6nitz?= To: gdb@sourceware.org Subject: Re: cast in gdb python results in virtual baseclass botch Date: Wed, 13 Apr 2011 17:29:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.32-21-generic; KDE/4.4.5; i686; ; ) References: <201104131726.55718.andre.poenitz@nokia.com> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201104131929.46854.andre.poenitz@nokia.com> X-Nokia-AV: Clean X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2011-04/txt/msg00051.txt.bz2 On Wednesday 13 April 2011 19:08:17 ext Christoph Mathys wrote: > On Wed, Apr 13, 2011 at 5:26 PM, Andr=C3=A9 P=C3=B6nitz wrote: > > I don't think you have to cast. > > > > inner =3D item.value["px"].dereference() has already the correct type. >=20 > I expressed myself badly: >=20 > class XmlNodeInterface > { }; > class XmlNode : public XmlNodeInterface > { > xmlNode* m_pNode; > }; >=20 > I've got a reference to a "shared_ptr", and I want m_pNode. > So after I extracted px, I think I have to downcast from IXmlNode to XmlN= ode 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 =3D {} def lookupType(typestring): type =3D typeCache.get(typestring) if type is None: ts =3D typestring while True: if ts.startswith("class "): ts =3D ts[6:] elif ts.startswith("struct "): ts =3D ts[7:] elif ts.startswith("const "): ts =3D ts[6:] elif ts.startswith("volatile "): ts =3D ts[9:] elif ts.startswith("enum "): ts =3D ts[5:] elif ts.endswith("const"): ts =3D ts[-5:] elif ts.endswith("volatile"): ts =3D ts[-8:] else: break try: type =3D gdb.lookup_type(ts) except RuntimeError, error: # See http://sourceware.org/bugzilla/show_bug.cgi?id=3D11912 exp =3D "(class '%s'*)0" % ts try: type =3D parseAndEvaluate(exp).type.target() except: # Can throw "RuntimeError: No type named class Foo." pass except: pass typeCache[typestring] =3D type if type is None and typestring.endswith('*'): type =3D lookupType(typestring[0:-1]) if not type is None: type =3D type.pointer() typeCache[typestring] =3D type if type is None: # could be gdb.lookup_type("char[3]") generating # "RuntimeError: No type named char[3]" pass return type