From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28183 invoked by alias); 1 Jun 2012 09:07:40 -0000 Received: (qmail 28162 invoked by uid 22791); 1 Jun 2012 09:07:38 -0000 X-SWARE-Spam-Status: No, hits=1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from sam.nabble.com (HELO sam.nabble.com) (216.139.236.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jun 2012 09:07:26 +0000 Received: from telerig.nabble.com ([192.168.236.162]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1SaNpN-00063B-Jk for gdb@sourceware.org; Fri, 01 Jun 2012 02:07:25 -0700 Message-ID: <33943560.post@talk.nabble.com> Date: Fri, 01 Jun 2012 09:07:00 -0000 From: somersetgraham To: gdb@sourceware.org Subject: help with pretty printing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 2012-06/txt/msg00000.txt.bz2 I am writing some gdb pretty printers for Qt classes to be used in the Eclipse IDE, but cannot seem to handle pointers to data structures very well (I am very new to Python) For example I want to pretty print the QFile structure which I have achieved with following code =E2=80=93 class QFilePrinter: def __init__(self, val): self.val =3D val data =3D self.val['d_ptr']['d'].dereference() def children(self): names =3D [1,2] data =3D self.val['d_ptr']['d'] for i in names: if i=3D=3D1: ptype =3D gdb.lookup_type("QFilePrivate").pointer() yield "fileName",data.cast(ptype).dereference()["fileName"] if i =3D=3D 2: exp =3D "((class QFile*)%s)->exists()" % (self.val.address) r =3D callClassMethod(self.val, "exists","") yield "exists",r =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 def to_string (self): data =3D self.val['d_ptr']['d'] ptype =3D gdb.lookup_type("QFilePrivate").pointer() return "%s %s" % ("fileName",data.cast(ptype).dereference()["fileName"]) def display_hint (self): return 'string' I have followed some examples that I found online for building a lookup table functions to be called =E2=80=93=20 def lookup_function (val): #print "Look-up and return a pretty-printer that can print val." # Get the type. type =3D val.type; print type # If it points to a reference, get the reference. if type.code =3D=3D gdb.TYPE_CODE_REF: print "deref" type =3D type.target () print type # Get the unqualified type, stripped of typedefs. type =3D type.unqualified ().strip_typedefs () print type =20=20=20=20=20=20=20 # Get the type name. typename =3D type.tag print typename #print typename if typename =3D=3D None: print "None" return None # Iterate over local dictionary of types to determine # if a printer is registered for that type. Return an # instantiation of the printer if found. for function in pretty_printers_dict: if function.search (typename): print "found" return pretty_printers_dict[function] (val) =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 # Cannot find a pretty printer. Return None. print "not found" return None # def build_dictionary (): pretty_printers_dict[re.compile ('^QFile$')] =3D lambda val:QFilePrinter(val) pretty_printers_dict[re.compile ('^QFile *$')] =3D lambda val:QFilePrinter(val) pretty_printers_dict =3D {} build_dictionary () When I debug my code containing a pointer to a QFile object my pretty printer is not invoked, but if I type =E2=80=98print *f=E2=80=99 (f is a po= inter to a QFile object) the pretty printer is invoked. Also I add =E2=80=98*f=E2=80=99 in t= he Expressions window in Eclipse the printer is invoked. Is it possible to get my pretty printer to work with pointers in all cases? --=20 View this message in context: http://old.nabble.com/help-with-pretty-printi= ng-tp33943560p33943560.html Sent from the Sourceware - gdb list mailing list archive at Nabble.com.