From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 84391 invoked by alias); 29 Oct 2015 23:38:34 -0000 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 Received: (qmail 84380 invoked by uid 89); 29 Oct 2015 23:38:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: na01-bl2-obe.outbound.protection.outlook.com Received: from mail-bl2on0053.outbound.protection.outlook.com (HELO na01-bl2-obe.outbound.protection.outlook.com) (65.55.169.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA256 encrypted) ESMTPS; Thu, 29 Oct 2015 23:38:32 +0000 Received: from CY1PR0501MB1178.namprd05.prod.outlook.com (10.160.145.14) by CY1PR0501MB1179.namprd05.prod.outlook.com (10.160.145.140) with Microsoft SMTP Server (TLS) id 15.1.306.13; Thu, 29 Oct 2015 23:38:27 +0000 Received: from CY1PR0501MB1178.namprd05.prod.outlook.com ([10.160.145.14]) by CY1PR0501MB1178.namprd05.prod.outlook.com ([10.160.145.14]) with mapi id 15.01.0306.003; Thu, 29 Oct 2015 23:38:27 +0000 From: Paul Marquess To: "gdb@sourceware.org" Subject: RE: getting subclass type from base class pointer Date: Thu, 29 Oct 2015 23:38:00 -0000 Message-ID: References: In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Paul.Marquess@owmobility.com; x-microsoft-exchange-diagnostics: 1;CY1PR0501MB1179;5:iCTMgtp79ImrS/i8Z26N1ainDs5RiGEhsfcqRq4YFcnHwUtVmheWIDINQGfEvSSwWiW7mBhXWIIl0Hs3tVbNKidaXwO7KTCUJrp0+6MmXZr7+eJumLqX6/NCNMJSuYAmM/f2B+AOVNgJFEJYAX5vqA==;24:dtS0qye7q/LPeY5DcrkjdAH5jH0BiaG6Hc0WxYYYwOc4htnIgqnTgON0ANE0kt1sY63t9YGat9WB9zFQ0JCnPull/TTi6joMxuwwS8e8Nos=;20:9jCqi1NLhwSmbUhl3YqK41ICDjm4hPX5xU7x/RC23q3PjHJK53HOhytUtUWUERUtCoUpEYadTb9MPXNaGDDvHQ== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0501MB1179; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001)(10201501046)(102215026);SRVR:CY1PR0501MB1179;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0501MB1179; x-forefront-prvs: 0744CFB5E8 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(199003)(189002)(99286002)(40100003)(86362001)(106356001)(2351001)(19580395003)(5003600100002)(74316001)(33656002)(5002640100001)(107886002)(76176999)(77096005)(105586002)(5001960100002)(19580405001)(189998001)(2950100001)(92566002)(2501003)(5004730100002)(101416001)(102836002)(50986999)(11100500001)(110136002)(81156007)(54356999)(10400500002)(76576001)(97736004)(122556002)(5008740100001)(5007970100001)(450100001)(87936001)(2900100001)(66066001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0501MB1179;H:CY1PR0501MB1178.namprd05.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: owmobility.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: owmobility.com X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2015 23:38:27.3671 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 042bf9d6-5c89-4240-a963-35f806e16660 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0501MB1179 X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg00112.txt.bz2 > From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On Behal= f Of Paul Marquess >=20 > I must be missing something obvious, so apologies upfront. >=20 > Consider this simple snippet of C++ >=20 >=20 > class SuperClass > { > }; >=20 > class SubClass : public SuperClass > { > }; >=20 > int main() > { > SuperClass* pTest =3D new SubClass; >=20 > delete pTest; // << Break here in GDB } >=20 > Using the python API I'm trying to determine the type of object that pTes= t points to.=20 >=20 >=20 > gdb) python x =3D gdb.parse_and_eval("pTest") > (gdb) python print x.type > SuperClass * > (gdb) python print x.dereference().type > SuperClass >=20 > 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 li= ke shown below, so I there should be a vtable in play.=20 Same question - how get at the SubClass object if I have a pointer to a Sup= erClass object using the Python API? class SuperClass=20 { public: virtual int fred() { return 1; } SuperClass() {} virtual ~SuperClass() {} }; class SubClass : public SuperClass=20 { public: virtual int fred() { return 2 ;} SubClass() {} virtual ~SubClass() {} }; int main() { SuperClass* pTest =3D new SubClass; delete pTest; }