public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* gdb python pretty printer question
@ 2011-09-28 22:43 S Boucher
  2011-10-05 19:09 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: S Boucher @ 2011-09-28 22:43 UTC (permalink / raw)
  To: gdb

I'm trying to use the python pretty printer functionality to to print what are basically sub classes implemented in C.


given the following:

struct base {
 int type; /* 1 for S1, 2 for S2, 0 otherwise */

int x,y,z;
}

stuct S1 {
 struct base b;
 int w;
}

struct S2 {
struct base b;
int q;

}

If the pretty printer lookup notices a type 'struct base' with it's type == 1, then use a custom S1Printer class.

class S1Printer(object):
  ....

    def to_string(self):
         v = self.val.cast(gdb.lookup_type("S1"))
        return v.__str__()


Problem with that is that when v.__str__() is called to print 'b' from S1, it notices that b is a S1, and we have a recursion...

Any way to prevent the recursion?

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

* Re: gdb python pretty printer question
  2011-09-28 22:43 gdb python pretty printer question S Boucher
@ 2011-10-05 19:09 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2011-10-05 19:09 UTC (permalink / raw)
  To: S Boucher; +Cc: gdb

>>>>> ">" == S Boucher <stbya@yahoo.com> writes:

>> I'm trying to use the python pretty printer functionality to to print
>> what are basically sub classes implemented in C.
[...]

>>         return v.__str__()

>> Problem with that is that when v.__str__() is called to print 'b' from
>> S1, it notices that b is a S1, and we have a recursion...

>> Any way to prevent the recursion?

Nothing built-in.
I suggest just having S1Printer.to_string delegate to some other function.

Tom

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

end of thread, other threads:[~2011-10-05 19:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-28 22:43 gdb python pretty printer question S Boucher
2011-10-05 19:09 ` Tom Tromey

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).