From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32324 invoked by alias); 12 May 2011 17:13:19 -0000 Received: (qmail 32315 invoked by uid 22791); 12 May 2011 17:13:18 -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; Thu, 12 May 2011 17:13:03 +0000 Received: from gar.localnet (berwst16747.europe.nokia.com [172.25.167.47]) by mgw-da02.nokia.com (Switch-3.4.4/Switch-3.4.3) with ESMTP id p4CHCvrb003901; Thu, 12 May 2011 20:12:57 +0300 From: =?iso-8859-1?q?Andr=E9_P=F6nitz?= To: gdb@sourceware.org Subject: Re: automated cast to different data type possible? Date: Thu, 12 May 2011 17:13:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.32-21-generic; KDE/4.4.5; i686; ; ) Cc: ext Tom Tromey , Klaus Rudolph References: <20110511090850.28500@gmx.net> <20110512061641.103010@gmx.net> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201105121913.12475.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-05/txt/msg00053.txt.bz2 On Thursday 12 May 2011 18:05:13 ext Tom Tromey wrote: > >>>>> "Klaus" == Klaus Rudolph writes: > > Tom> You want "set print object on". > > Klaus> This only works with classes which includes a vtable, but there > Klaus> is no virtual function inside that hierarchy. > > Sorry about that; you even noted this in your original message and I > missed it. > > Pretty-printers just change how a value is displayed. They don't change > the type. [...] Assuming that I understood the task correctly it can be done with gdb python scripting nevertheless. Given struct KRBase { enum Type { TYPE_A, TYPE_B } type; KRBase(Type _type) : type(_type) {} }; struct KRA : KRBase { int x, y; KRA() : KRBase(TYPE_A), x(1), y(32) {} }; struct KRB : KRBase { KRB() : KRBase(TYPE_B) {} }; void testKR() { KRBase *ptr1 = new KRA; KRBase *ptr2 = new KRB; break_here(); } creating a display of ptr1 @0x809a9d0 KRA KRBase KRA x 1 int y 32 int ptr2 @0x809a9e0 KRB KRBase KRB takes three lines of python code: def qdump__KRBase(d, item): base = ["KRA", "KRB"][int(item.value["type"])] d.putItem(Item(item.value.cast(lookupType(base)), item.iname)) [using, admittedly, the *cough* "other" approach to pretty printing] Andre' PS: I put a real screenshot at http://imageshack.us/photo/my-images/135/kr2e.png as I am not sure how acceptable attaching a 15k .png is on this list.