This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: Access to "default GDB printer" from Python pretty printers?
- From: Tom Tromey <tromey at redhat dot com>
- To: ppluzhnikov at google dot com (Paul Pluzhnikov)
- Cc: archer at sourceware dot org
- Date: Wed, 05 Nov 2008 11:44:57 -0700
- Subject: Re: Access to "default GDB printer" from Python pretty printers?
- References: <20081105175721.C2DB73A6B0C@localhost>
- Reply-to: Tom Tromey <tromey at redhat dot com>
Paul> def Print_sockaddr(val):
Paul> AF_UNIX = 1
Paul> AF_INET = 2
Paul> AF_INET6 = 10
Paul> af = val['sa_family']
Paul> if af == AF_UNIX:
Paul> return Print_sockaddr_un(val)
Paul> elif af == AF_INET:
Paul> return Print_sockaddr_in(val)
Paul> elif af == AF_INET6:
Paul> return Print_sockaddr_in6(val)
Paul> else:
Paul> # Don't know how to print this kind of sockaddr.
Paul> # Just do whatever GDB would have done without Python.
Paul> return gdb.print_value(val)
Paul> Reasonable?
It occurs to me that we will be able to handle this case ok in the new
unified style using delegation plus a special return result.
Something like:
class Print_sockaddr_un ...
class Print_sockaddr_in ...
class Print_sockaddr_in6 ...
def Print_sockaddr(val):
if same as above
...
else:
return None
That is, rather than register a class constructor, we register a
delegating "constructor" which decides what to do based on the value.
If the constructor returns None, we'll just revert to the default.
What do you think of this?
Tom