public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* pretty printer for pointers
@ 2012-06-19  9:15 graham
  2012-06-21 13:57 ` Joachim Protze
  0 siblings, 1 reply; 2+ messages in thread
From: graham @ 2012-06-19  9:15 UTC (permalink / raw)
  To: gdb

Hi
I am trying to write some pretty printers for Qt types. I have had some success
but want to pretty print pointers to classes.
I have a printer for the type QTextDocument and want an equivalent for a pointer
to this type.

In the non printer version of the printer I have lines such as this

    def children(self):
        yield "isEmpty",callClassMethod(self.val,"isEmpty","")

Which works as expected

Now I want to do the same in the pointer equivalent printer but cannot see how
to do this
I have tried many things including this
    def children(self):
        data2 = self.val.dereference()
        ptype2 = gdb.lookup_type("QTextDocument").pointer()
        yield
"isEmpty",callClassMethod(data2.cast(ptype2).dereference(),"isEmpty","")

but this results in an infinite loop

My implementation of the callClassMethod function is

def callClassMethod (value,func,args):

    type = value.type
    #type = type.unqualified ().strip_typedefs ()
    #print "type %s" % type
    exp = "((class %s*)%s)->%s()" % (type, value.address, func)
    print "exp = %s" % exp
    #print("CALL: %s" % exp)
    result = None
    try:
        result = gdb.parse_and_eval(exp)
        
    except:
        print "pass"
        pass
    #print("  -> %s" % result)
    return result

I would be grateful if someone could help me solve this issue

Thanks in advance

Graham


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: pretty printer for pointers
  2012-06-19  9:15 pretty printer for pointers graham
@ 2012-06-21 13:57 ` Joachim Protze
  0 siblings, 0 replies; 2+ messages in thread
From: Joachim Protze @ 2012-06-21 13:57 UTC (permalink / raw)
  To: graham; +Cc: gdb

[-- Attachment #1: Type: text/plain, Size: 831 bytes --]

On 19.06.2012 10:27, graham wrote:
> I have tried many things including this
>     def children(self):
>         data2 = self.val.dereference()
>         ptype2 = gdb.lookup_type("QTextDocument").pointer()
>         yield
> "isEmpty",callClassMethod(data2.cast(ptype2).dereference(),"isEmpty","")
>
> but this results in an infinite loop
>
> My implementation of the callClassMethod function is
>
> def callClassMethod (value,func,args):
>
>     type = value.type
>     #type = type.unqualified ().strip_typedefs ()
>     #print "type %s" % type
>     exp = "((class %s*)%s)->%s()" % (type, value.address, func)
"%s" % value.address
is the source of your infinite loop as it triggers the pretty printer
for the pointer to value. Try
"%i" % long(value.address)
or
"0x%x" % long(value.address)

- Joachim


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5306 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-21 13:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-19  9:15 pretty printer for pointers graham
2012-06-21 13:57 ` Joachim Protze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).