From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23215 invoked by alias); 16 May 2011 11:43:25 -0000 Received: (qmail 23207 invoked by uid 22791); 16 May 2011 11:43:25 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,TW_QD,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; Mon, 16 May 2011 11:43:11 +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 p4GBh7j6021896; Mon, 16 May 2011 14:43:07 +0300 From: =?iso-8859-1?q?Andr=E9_P=F6nitz?= To: gdb@sourceware.org Subject: Re: automated cast to different data type possible? Date: Mon, 16 May 2011 11:43:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.32-21-generic; KDE/4.4.5; i686; ; ) Cc: ext Klaus Rudolph References: <20110511090850.28500@gmx.net> <201105121913.12475.andre.poenitz@nokia.com> <4DCFE110.4000703@gmx.de> In-Reply-To: <4DCFE110.4000703@gmx.de> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <201105161343.54594.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/msg00075.txt.bz2 On Sunday 15 May 2011 16:20:00 ext Klaus Rudolph wrote: > Andr=E9 P=F6nitz wrote: > > > Assuming that I understood the task correctly it can be done with=20 > > gdb python scripting nevertheless. [...It] takes three lines of python = code: > >=20 > > def qdump__KRBase(d, item): > > base =3D ["KRA", "KRB"][int(item.value["type"])] > > d.putItem(Item(item.value.cast(lookupType(base)), item.iname)) > >=20 > > [using, admittedly, the *cough* "other" approach to pretty printing] >=20 > Sorry, >=20 > 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. The code would be called from a Python script that creates the full display for an local variable including all expanded children in one go.=20 'd' is an object that accumulates output that's finally 'printed', and takes care of properly closing nested items in case of exceptions. The approach is different from the one taken by the "official" pretty=20 printers, but also uses gdb's python scripting. Since this approach gives access to all levels of the hierarchy at one time, re-arranging items or re-writing parts of the "parent" items (like in your case the=20 name of the type) is straightforward. Andre'