This is the mail archive of the mailing list for the Archer project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Access to "default GDB printer" from Python pretty printers?

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]