aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2015-04-28 22:14:23 -0700
committerDoug Evans <dje@google.com>2015-04-28 22:14:23 -0700
commit34f5f757b389e8fb3eab64f816e484c2cc434292 (patch)
treed03a9187ae43e7827e184dff9afd6d4de63c3b88 /gdb/python
parent69b4374a87e5029ac4831c7a4471815514df662f (diff)
downloadgdb-34f5f757b389e8fb3eab64f816e484c2cc434292.zip
gdb-34f5f757b389e8fb3eab64f816e484c2cc434292.tar.gz
gdb-34f5f757b389e8fb3eab64f816e484c2cc434292.tar.bz2
PR python/18299
gdb/ChangeLog: PR python/18299 * python/lib/gdb/printing.py (register_pretty_printer): Handle name or __name__ attributes. Handle gdb module as first argument. gdb/testsuite/ChangeLog: * gdb.python/py-pp-maint.py: Move "replace" testing to ... * gdb.python/py-pp-registration.exp: ... here. New file. * gdb.python/py-pp-registration.c: New file. * gdb.python/py-pp-registration.py: New file.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/lib/gdb/printing.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py
index e384e41..ff20f71 100644
--- a/gdb/python/lib/gdb/printing.py
+++ b/gdb/python/lib/gdb/printing.py
@@ -114,15 +114,21 @@ def register_pretty_printer(obj, printer, replace=False):
if not hasattr(printer, "__call__"):
raise TypeError("printer missing attribute: __call__")
- if obj is None:
+ if hasattr(printer, "name"):
+ name = printer.name
+ else:
+ name = printer.__name__
+ if obj is None or obj is gdb:
if gdb.parameter("verbose"):
gdb.write("Registering global %s pretty-printer ...\n" % name)
obj = gdb
else:
if gdb.parameter("verbose"):
- gdb.write("Registering %s pretty-printer for %s ...\n" %
- (printer.name, obj.filename))
+ gdb.write("Registering %s pretty-printer for %s ...\n" % (
+ name, obj.filename))
+ # Printers implemented as functions are old-style. In order to not risk
+ # breaking anything we do not check __name__ here.
if hasattr(printer, "name"):
if not isinstance(printer.name, basestring):
raise TypeError("printer name is not a string")