From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 919 invoked by alias); 2 Jun 2012 10:29:15 -0000 Received: (qmail 910 invoked by uid 22791); 2 Jun 2012 10:29:14 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_THREADED,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_WEB X-Spam-Check-By: sourceware.org Received: from forward9.mail.yandex.net (HELO forward9.mail.yandex.net) (77.88.61.48) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 02 Jun 2012 10:28:59 +0000 Received: from smtp9.mail.yandex.net (smtp9.mail.yandex.net [77.88.61.35]) by forward9.mail.yandex.net (Yandex) with ESMTP id C7F40CE1B6E; Sat, 2 Jun 2012 14:28:57 +0400 (MSK) Received: from smtp9.mail.yandex.net (localhost [127.0.0.1]) by smtp9.mail.yandex.net (Yandex) with ESMTP id A6EB515204B8; Sat, 2 Jun 2012 14:28:57 +0400 (MSK) Received: from kts.bestnet.kharkov.ua (kts.bestnet.kharkov.ua [80.92.226.138]) by smtp9.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Sune6tlU-Svn4fAG7; Sat, 2 Jun 2012 14:28:57 +0400 X-Yandex-Rcpt-Suid: graham.labdon@avalonsciences.com X-Yandex-Rcpt-Suid: gdb@sourceware.org Message-ID: <4FC9EAEA.7050404@yandex.ru> Date: Sat, 02 Jun 2012 10:29:00 -0000 From: xgsa User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120411 Thunderbird/11.0.1 MIME-Version: 1.0 To: somersetgraham CC: gdb@sourceware.org Subject: Re: help with pretty printing References: <33943560.post@talk.nabble.com> In-Reply-To: <33943560.post@talk.nabble.com> Content-Type: text/plain; charset=UTF-8; format=flowed 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: 2012-06/txt/msg00008.txt.bz2 You could try the Qt pretty from here: https://projects.kde.org/projects/extragear/kdevelop/kdevelop/repository/revisions/4.1/show/debuggers/gdb/printers If they work properly you could compare their implementation with yours or just use them. Anton. -------- Original message -------- > 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 – > > class QFilePrinter: > def __init__(self, val): > self.val = val > data = self.val['d_ptr']['d'].dereference() > > def children(self): > names = [1,2] > data = self.val['d_ptr']['d'] > for i in names: > if i==1: > ptype = gdb.lookup_type("QFilePrivate").pointer() > yield "fileName",data.cast(ptype).dereference()["fileName"] > if i == 2: > exp = "((class QFile*)%s)->exists()" % (self.val.address) > r = callClassMethod(self.val, "exists","") > yield "exists",r > > def to_string (self): > data = self.val['d_ptr']['d'] > ptype = 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 – > > def lookup_function (val): > #print "Look-up and return a pretty-printer that can print val." > > # Get the type. > type = val.type; > print type > # If it points to a reference, get the reference. > if type.code == gdb.TYPE_CODE_REF: > print "deref" > type = type.target () > > print type > # Get the unqualified type, stripped of typedefs. > type = type.unqualified ().strip_typedefs () > print type > > # Get the type name. > typename = type.tag > print typename > #print typename > if typename == 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) > > # Cannot find a pretty printer. Return None. > print "not found" > return None > # > def build_dictionary (): > pretty_printers_dict[re.compile ('^QFile$')] = lambda > val:QFilePrinter(val) > pretty_printers_dict[re.compile ('^QFile *$')] = lambda > val:QFilePrinter(val) > > pretty_printers_dict = {} > > build_dictionary () > > When I debug my code containing a pointer to a QFile object my pretty > printer is not invoked, but if I type ‘print *f’ (f is a pointer to a QFile > object) the pretty printer is invoked. Also I add ‘*f’ in the Expressions > window in Eclipse the printer is invoked. > > Is it possible to get my pretty printer to work with pointers in all cases? > >