From 34f5f757b389e8fb3eab64f816e484c2cc434292 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Tue, 28 Apr 2015 22:14:23 -0700 Subject: 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. --- gdb/python/lib/gdb/printing.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'gdb/python/lib') 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") -- cgit v1.1