* python/lib/gdb/printing.py (register_pretty_printer): New argument
`replace'. testsuite/ * gdb.python/py-pp-maint.py: Add tests for `replace' arg.
This commit is contained in:
parent
690a49373c
commit
1fa57852d6
@ -1,5 +1,8 @@
|
||||
2011-10-07 Doug Evans <dje@google.com>
|
||||
|
||||
* python/lib/gdb/printing.py (register_pretty_printer): New argument
|
||||
`replace'.
|
||||
|
||||
* python/lib/gdb/printing.py: Whitespace cleanup.
|
||||
|
||||
* python/py-value.c (valpy_call): Initialize ftype to avoid compiler
|
||||
|
@ -68,7 +68,7 @@ class SubPrettyPrinter(object):
|
||||
self.enabled = True
|
||||
|
||||
|
||||
def register_pretty_printer(obj, printer):
|
||||
def register_pretty_printer(obj, printer, replace=False):
|
||||
"""Register pretty-printer PRINTER with OBJ.
|
||||
|
||||
The printer is added to the front of the search list, thus one can override
|
||||
@ -81,6 +81,8 @@ def register_pretty_printer(obj, printer):
|
||||
is registered globally).
|
||||
printer: Either a function of one argument (old way) or any object
|
||||
which has attributes: name, enabled, __call__.
|
||||
replace: If True replace any existing copy of the printer.
|
||||
Otherwise if the printer already exists raise an exception.
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
@ -128,10 +130,16 @@ def register_pretty_printer(obj, printer):
|
||||
# Alas, we can't do the same for functions and __name__, they could
|
||||
# all have a canonical name like "lookup_function".
|
||||
# PERF: gdb records printers in a list, making this inefficient.
|
||||
if (printer.name in
|
||||
[p.name for p in obj.pretty_printers if hasattr(p, "name")]):
|
||||
raise RuntimeError("pretty-printer already registered: %s" %
|
||||
printer.name)
|
||||
i = 0
|
||||
for p in obj.pretty_printers:
|
||||
if hasattr(p, "name") and p.name == printer.name:
|
||||
if replace:
|
||||
del obj.pretty_printers[i]
|
||||
break
|
||||
else:
|
||||
raise RuntimeError("pretty-printer already registered: %s" %
|
||||
printer.name)
|
||||
i = i + 1
|
||||
|
||||
obj.pretty_printers.insert(0, printer)
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
2011-10-07 Doug Evans <dje@google.com>
|
||||
|
||||
* gdb.python/py-pp-maint.py: Add tests for `replace' arg.
|
||||
|
||||
2011-10-07 Kevin Pouget <kevin.pouget@st.com>
|
||||
|
||||
Allow Python notification of new object-file loadings.
|
||||
|
@ -71,4 +71,16 @@ def build_pretty_printer():
|
||||
|
||||
|
||||
gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)
|
||||
gdb.printing.register_pretty_printer(gdb, build_pretty_printer())
|
||||
my_pretty_printer = build_pretty_printer()
|
||||
gdb.printing.register_pretty_printer(gdb, my_pretty_printer)
|
||||
|
||||
# Exercise the "replace" argument to register pretty_printer.
|
||||
saw_runtime_error = False
|
||||
try:
|
||||
gdb.printing.register_pretty_printer(gdb, my_pretty_printer, replace=False)
|
||||
except RuntimeError:
|
||||
saw_runtime_error = True
|
||||
pass
|
||||
if not saw_runtime_error:
|
||||
raise RuntimeError("Missing RuntimeError from register_pretty_printer")
|
||||
gdb.printing.register_pretty_printer(gdb, my_pretty_printer, replace=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user