Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: xgsa <xgsa@yandex.ru>
To: somersetgraham <graham.labdon@avalonsciences.com>
Cc: gdb@sourceware.org
Subject: Re: help with pretty printing
Date: Sat, 02 Jun 2012 10:29:00 -0000	[thread overview]
Message-ID: <4FC9EAEA.7050404@yandex.ru> (raw)
In-Reply-To: <33943560.post@talk.nabble.com>

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?
>
>



  parent reply	other threads:[~2012-06-02 10:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-01  9:07 somersetgraham
2012-06-02  5:28 ` Niko Sams
2012-06-02 10:29 ` xgsa [this message]
2012-06-02 11:10   ` Niko Sams
2012-06-02 11:24     ` xgsa
2012-06-07  7:42 ` Joachim Protze
2012-06-07 18:27   ` Paul_Koning
2012-06-25 11:05     ` Joachim Protze

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FC9EAEA.7050404@yandex.ru \
    --to=xgsa@yandex.ru \
    --cc=gdb@sourceware.org \
    --cc=graham.labdon@avalonsciences.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox