summaryrefslogtreecommitdiff
path: root/gdb/python/py-prettyprint.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2010-04-15 19:54:13 +0000
committerDoug Evans <dje@google.com>2010-04-15 19:54:13 +0000
commitfa33c3cd050c9f8a33ab0826479fd3e0f26a3da6 (patch)
tree8aa1bd5a3237ffff09f051cad7544427a67ed81e /gdb/python/py-prettyprint.c
parent3f7b2faa4bb3f35f6c88687b6943cdbe6003b615 (diff)
* NEWS: Add entry for python program space support.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-progspace.o. (SUBDIR_PYTHON_SRCS): Add py-progspace.c. (py-progspace.o): New rule. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): New function. (find_pretty_printer_from_progspace): New function. (find_pretty_printer_from_gdb): New function. (find_pretty_printer): Rewrite. * python/py-progspace.c: New file. * python/python-internal.h (program_space): Add forward decl. (pspace_to_pspace_object, pspy_get_printers): Declare. (gdbpy_initialize_pspace): Declare. * python/python.c: #include "progspace.h". (gdbpy_get_current_progspace, gdbpy_progspaces): New functions. (_initialize_python): Call gdbpy_initialize_pspace. (GdbMethods): Add current_progspace, progspaces. doc/ * gdb.texinfo (Python API): Add progspaces section. (Selecting Pretty-Printers): Progspace pretty-printers are searched too. (Progspaces In Python): New section. testsuite/ * gdb.python/py-progspace.c: New file. * gdb.python/py-progspace.exp: New file.
Diffstat (limited to 'gdb/python/py-prettyprint.c')
-rw-r--r--gdb/python/py-prettyprint.c110
1 files changed, 81 insertions, 29 deletions
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 9f9fea1527..d26ed581ea 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -29,12 +29,12 @@
#ifdef HAVE_PYTHON
#include "python-internal.h"
-
/* Helper function for find_pretty_printer which iterates over a list,
calls each function and inspects output. This will return a
printer object if one recognizes VALUE. If no printer is found, it
will return None. On error, it will set the Python error and
return NULL. */
+
static PyObject *
search_pp_list (PyObject *list, PyObject *value)
{
@@ -60,18 +60,19 @@ search_pp_list (PyObject *list, PyObject *value)
Py_RETURN_NONE;
}
-/* Find the pretty-printing constructor function for VALUE. If no
- pretty-printer exists, return None. If one exists, return a new
- reference. On error, set the Python error and return NULL. */
+/* Subroutine of find_pretty_printer to simplify it.
+ Look for a pretty-printer to print VALUE in all objfiles.
+ The result is NULL if there's an error and the search should be terminated.
+ The result is Py_None, suitably inc-ref'd, if no pretty-printer was found.
+ Otherwise the result is the pretty-printer function, suitably inc-ref'd. */
+
static PyObject *
-find_pretty_printer (PyObject *value)
+find_pretty_printer_from_objfiles (PyObject *value)
{
- PyObject *pp_list = NULL;
- PyObject *function = NULL;
+ PyObject *pp_list;
+ PyObject *function;
struct objfile *obj;
- volatile struct gdb_exception except;
- /* Look at the pretty-printer dictionary for each objfile. */
ALL_OBJFILES (obj)
{
PyObject *objf = objfile_to_objfile_object (obj);
@@ -84,44 +85,95 @@ find_pretty_printer (PyObject *value)
pp_list = objfpy_get_printers (objf, NULL);
function = search_pp_list (pp_list, value);
+ Py_XDECREF (pp_list);
- /* If there is an error in any objfile list, abort the search and
- exit. */
+ /* If there is an error in any objfile list, abort the search and exit. */
if (! function)
- {
- Py_XDECREF (pp_list);
- return NULL;
- }
+ return NULL;
if (function != Py_None)
- goto done;
+ return function;
Py_DECREF (function);
- Py_XDECREF (pp_list);
}
- pp_list = NULL;
+ Py_RETURN_NONE;
+}
+
+/* Subroutine of find_pretty_printer to simplify it.
+ Look for a pretty-printer to print VALUE in the current program space.
+ The result is NULL if there's an error and the search should be terminated.
+ The result is Py_None, suitably inc-ref'd, if no pretty-printer was found.
+ Otherwise the result is the pretty-printer function, suitably inc-ref'd. */
+
+static PyObject *
+find_pretty_printer_from_progspace (PyObject *value)
+{
+ PyObject *pp_list;
+ PyObject *function;
+ PyObject *obj = pspace_to_pspace_object (current_program_space);
+
+ if (!obj)
+ return NULL;
+ pp_list = pspy_get_printers (obj, NULL);
+ function = search_pp_list (pp_list, value);
+ Py_XDECREF (pp_list);
+ return function;
+}
+
+/* Subroutine of find_pretty_printer to simplify it.
+ Look for a pretty-printer to print VALUE in the gdb module.
+ The result is NULL if there's an error and the search should be terminated.
+ The result is Py_None, suitably inc-ref'd, if no pretty-printer was found.
+ Otherwise the result is the pretty-printer function, suitably inc-ref'd. */
+
+static PyObject *
+find_pretty_printer_from_gdb (PyObject *value)
+{
+ PyObject *pp_list;
+ PyObject *function;
+
/* Fetch the global pretty printer dictionary. */
if (! PyObject_HasAttrString (gdb_module, "pretty_printers"))
+ Py_RETURN_NONE;
+ pp_list = PyObject_GetAttrString (gdb_module, "pretty_printers");
+ if (pp_list == NULL || ! PyList_Check (pp_list))
{
- function = Py_None;
- Py_INCREF (function);
- goto done;
+ Py_XDECREF (pp_list);
+ Py_RETURN_NONE;
}
- pp_list = PyObject_GetAttrString (gdb_module, "pretty_printers");
- if (! pp_list)
- goto done;
- if (! PyList_Check (pp_list))
- goto done;
function = search_pp_list (pp_list, value);
-
- done:
Py_XDECREF (pp_list);
-
return function;
}
+/* Find the pretty-printing constructor function for VALUE. If no
+ pretty-printer exists, return None. If one exists, return a new
+ reference. On error, set the Python error and return NULL. */
+
+static PyObject *
+find_pretty_printer (PyObject *value)
+{
+ PyObject *function;
+
+ /* Look at the pretty-printer dictionary for each objfile
+ in the current program-space. */
+ function = find_pretty_printer_from_objfiles (value);
+ if (function == NULL || function != Py_None)
+ return function;
+ Py_DECREF (function);
+
+ /* Look at the pretty-printer dictionary for the current program-space. */
+ function = find_pretty_printer_from_progspace (value);
+ if (function == NULL || function != Py_None)
+ return function;
+ Py_DECREF (function);
+
+ /* Look at the pretty-printer dictionary in the gdb module. */
+ function = find_pretty_printer_from_gdb (value);
+ return function;
+}
/* Pretty-print a single value, via the printer object PRINTER.
If the function returns a string, a PyObject containing the string