mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-31 01:45:52 +08:00
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.
This commit is contained in:
@ -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")
|
||||
|
Reference in New Issue
Block a user