* python/py-prettyprint.c (search_pp_list): Skip disabled printers.
* python/python-internal.h (gdbpy_enabled_cst): Declare.
* python/python.c (gdbpy_enabled_cst): Define.
(_initialize_python): Initialize gdbpy_enabled_cst.
* NEWS: Add entry.
doc/
* gdb.texinfo (Python API): New node `Disabling Pretty-Printers'.
testsuite/
* gdb.python/py-prettyprint.exp: Add new test for enabled and
disabled printers.
* gdb.python/py-prettyprint.py (disable_lookup_function): New function.
(enable_lookup_function): New function.
+2010-06-04 Doug Evans <dje@google.com>
+
+ Add support for enabling/disabling individual pretty-printers.
+ * python/py-prettyprint.c (search_pp_list): Skip disabled printers.
+ * python/python-internal.h (gdbpy_enabled_cst): Declare.
+ * python/python.c (gdbpy_enabled_cst): Define.
+ (_initialize_python): Initialize gdbpy_enabled_cst.
+ * NEWS: Add entry.
+
2010-06-04 Jan Kratochvil <jan.kratochvil@redhat.com>
* breakpoint.c (update_global_location_list): Fix comment typo.
** Pretty-printers are now also looked up in the current program space.
+** Pretty-printers can now be individually enabled and disabled.
+
** GDB now looks for names of Python scripts to auto-load in a
special section named `.debug_gdb_scripts', in addition to looking
for a OBJFILE-gdb.py script when OBJFILE is read by the debugger.
+2010-06-04 Doug Evans <dje@google.com>
+
+ * gdb.texinfo (Python API): New node `Disabling Pretty-Printers'.
+
2010-06-03 Doug Evans <dje@google.com>
* gdbint.texinfo (Coding): Add subsection on command names.
* Types In Python:: Python representation of types.
* Pretty Printing API:: Pretty-printing values.
* Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
+* Disabling Pretty-Printers:: Disabling broken printers.
* Commands In Python:: Implementing new commands in Python.
* Parameters In Python:: Adding new @value{GDBN} parameters.
* Functions In Python:: Writing new convenience functions.
@subsubsection Selecting Pretty-Printers
The Python list @code{gdb.pretty_printers} contains an array of
-functions that have been registered via addition as a pretty-printer.
+functions or callable objects that have been registered via addition
+as a pretty-printer.
Each @code{gdb.Progspace} contains a @code{pretty_printers} attribute.
Each @code{gdb.Objfile} also contains a @code{pretty_printers}
attribute.
@value{GDBN} first checks the @code{pretty_printers} attribute of each
@code{gdb.Objfile} in the current program space and iteratively calls
-each function in the list for that @code{gdb.Objfile} until it receives
+each enabled function (@pxref{Disabling Pretty-Printers})
+in the list for that @code{gdb.Objfile} until it receives
a pretty-printer object.
If no pretty-printer is found in the objfile lists, @value{GDBN} then
searches the pretty-printer list of the current program space,
-calling each function until an object is returned.
+calling each enabled function until an object is returned.
After these lists have been exhausted, it tries the global
-@code{gdb.pretty-printers} list, again calling each function until an
+@code{gdb.pretty_printers} list, again calling each enabled function until an
object is returned.
The order in which the objfiles are searched is not specified. For a
gdb.libstdcxx.v6.register_printers (gdb.current_objfile ())
@end smallexample
+@node Disabling Pretty-Printers
+@subsubsection Disabling Pretty-Printers
+@cindex disabling pretty-printers
+
+For various reasons a pretty-printer may not work.
+For example, the underlying data structure may have changed and
+the pretty-printer is out of date.
+
+The consequences of a broken pretty-printer are severe enough that
+@value{GDBN} provides support for enabling and disabling individual
+printers. For example, if @code{print frame-arguments} is on,
+a backtrace can become highly illegible if any argument is printed
+with a broken printer.
+
+Pretty-printers are enabled and disabled by attaching an @code{enabled}
+attribute to the registered function or callable object. If this attribute
+is present and its value is @code{False}, the printer is disabled, otherwise
+the printer is enabled.
+
@node Commands In Python
@subsubsection Commands In Python
if (! function)
return NULL;
+ /* Skip if disabled. */
+ if (PyObject_HasAttr (function, gdbpy_enabled_cst)
+ && ! PyObject_IsTrue (PyObject_GetAttr (function, gdbpy_enabled_cst)))
+ continue;
+
printer = PyObject_CallFunctionObjArgs (function, value, NULL);
if (! printer)
return NULL;
extern PyObject *gdbpy_children_cst;
extern PyObject *gdbpy_to_string_cst;
extern PyObject *gdbpy_display_hint_cst;
+extern PyObject *gdbpy_enabled_cst;
extern PyObject *gdbpy_gdberror_exc;
PyObject *gdbpy_children_cst;
PyObject *gdbpy_display_hint_cst;
PyObject *gdbpy_doc_cst;
+PyObject *gdbpy_enabled_cst;
/* The GdbError exception. */
PyObject *gdbpy_gdberror_exc;
gdbpy_children_cst = PyString_FromString ("children");
gdbpy_display_hint_cst = PyString_FromString ("display_hint");
gdbpy_doc_cst = PyString_FromString ("__doc__");
+ gdbpy_enabled_cst = PyString_FromString ("enabled");
/* Create a couple objects which are used for Python's stdout and
stderr. */
+2010-06-04 Doug Evans <dje@google.com>
+
+ * gdb.python/py-prettyprint.exp: Add new test for enabled and
+ disabled printers.
+ * gdb.python/py-prettyprint.py (disable_lookup_function): New function.
+ (enable_lookup_function): New function.
+
2010-06-04 Tom Tromey <tromey@redhat.com>
* gdb.python/py-value.exp (test_value_hash): Don't test equality
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
-
if ![runto_main ] then {
perror "couldn't run to breakpoint"
return
run_lang_tests "c"
run_lang_tests "c++"
+
+# Run various other tests.
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug"] != "" } {
+ untested "Couldn't compile ${srcfile}"
+ return -1
+}
+
+# Start with a fresh gdb.
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+if ![runto_main ] then {
+ perror "couldn't run to breakpoint"
+ return
+}
+
+gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \
+ ".*Breakpoint.*"
+gdb_test "continue" ".*Breakpoint.*"
+
+set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
+
+gdb_test "python execfile ('${remote_python_file}')" ""
+
+gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \
+ "print ss enabled #1"
+
+gdb_test "python disable_lookup_function ()" ""
+
+gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \
+ "print ss disabled"
+
+gdb_test "python enable_lookup_function ()" ""
+
+gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \
+ "print ss enabled #2"
+
+remote_file host delete ${remote_python_file}
return None
+def disable_lookup_function ():
+ lookup_function.enabled = False
+
+def enable_lookup_function ():
+ lookup_function.enabled = True
def register_pretty_printers ():
pretty_printers_dict[re.compile ('^struct s$')] = pp_s