From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2430 invoked by alias); 15 May 2011 14:17:19 -0000 Received: (qmail 2422 invoked by uid 22791); 15 May 2011 14:17:19 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,TW_QD,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mailout-de.gmx.net (HELO mailout-de.gmx.net) (213.165.64.22) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Sun, 15 May 2011 14:17:07 +0000 Received: (qmail invoked by alias); 15 May 2011 14:17:05 -0000 Received: from kref-5d833bf0.pool.mediaWays.net (EHLO [93.131.59.240]) [93.131.59.240] by mail.gmx.net (mp018) with SMTP; 15 May 2011 16:17:05 +0200 Message-ID: <4DCFE110.4000703@gmx.de> Date: Sun, 15 May 2011 14:17:00 -0000 From: Klaus Rudolph User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: gdb@sourceware.org Subject: Re: automated cast to different data type possible? References: <20110511090850.28500@gmx.net> <20110512061641.103010@gmx.net> <201105121913.12475.andre.poenitz@nokia.com> In-Reply-To: <201105121913.12475.andre.poenitz@nokia.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit 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/msg00069.txt.bz2 André Pönitz wrote: > > 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] Sorry, please give me an idea who is calling qdump_KRBase and what is parameter d? I actually have no idea how to add that to the printer script... or maybe any other python script to gdb. Thanks Klaus