aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-progspace.c32
-rw-r--r--gdb/python/python-internal.h4
-rw-r--r--gdb/python/python.c28
3 files changed, 51 insertions, 13 deletions
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index 3eaa466..e01338f 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -58,7 +58,16 @@ extern PyTypeObject pspace_object_type
static const struct program_space_data *pspy_pspace_data_key;
-
+/* Require that PSPACE_OBJ be a valid program space ID. */
+#define PSPY_REQUIRE_VALID(pspace_obj) \
+ do { \
+ if (pspace_obj->pspace == nullptr) \
+ { \
+ PyErr_SetString (PyExc_RuntimeError, \
+ _("Program space no longer exists.")); \
+ return NULL; \
+ } \
+ } while (0)
/* An Objfile method which returns the objfile's file name, or None. */
@@ -314,7 +323,17 @@ pspy_set_type_printers (PyObject *o, PyObject *value, void *ignore)
return 0;
}
-
+/* Implement the objfiles method. */
+
+static PyObject *
+pspy_get_objfiles (PyObject *self_, PyObject *args)
+{
+ pspace_object *self = (pspace_object *) self_;
+
+ PSPY_REQUIRE_VALID (self);
+
+ return build_objfiles_list (self->pspace).release ();
+}
/* Clear the PSPACE pointer in a Pspace object and remove the reference. */
@@ -397,6 +416,13 @@ static gdb_PyGetSetDef pspace_getset[] =
{ NULL }
};
+static PyMethodDef progspace_object_methods[] =
+{
+ { "objfiles", pspy_get_objfiles, METH_NOARGS,
+ "Return a sequence of objfiles associated to this program space." },
+ { NULL }
+};
+
PyTypeObject pspace_object_type =
{
PyVarObject_HEAD_INIT (NULL, 0)
@@ -426,7 +452,7 @@ PyTypeObject pspace_object_type =
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
- 0, /* tp_methods */
+ progspace_object_methods, /* tp_methods */
0, /* tp_members */
pspace_getset, /* tp_getset */
0, /* tp_base */
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 3874fdc..785ad17 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -549,6 +549,10 @@ struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
struct frame_info *frame_object_to_frame_info (PyObject *frame_obj);
struct gdbarch *arch_object_to_gdbarch (PyObject *obj);
+/* Return a Python list containing an Objfile object for each objfile in
+ PSPACE. */
+gdbpy_ref<> build_objfiles_list (program_space *pspace);
+
void gdbpy_initialize_gdb_readline (void);
int gdbpy_initialize_auto_load (void)
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 6f798a0..371f4a5 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1437,10 +1437,10 @@ gdbpy_get_current_objfile (PyObject *unused1, PyObject *unused2)
return result;
}
-/* Return a sequence holding all the Objfiles. */
+/* See python-internal.h. */
-static PyObject *
-gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
+gdbpy_ref<>
+build_objfiles_list (program_space *pspace)
{
struct objfile *objf;
@@ -1448,15 +1448,23 @@ gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
if (list == NULL)
return NULL;
- ALL_OBJFILES (objf)
- {
- PyObject *item = objfile_to_objfile_object (objf);
+ ALL_PSPACE_OBJFILES (pspace, objf)
+ {
+ PyObject *item = objfile_to_objfile_object (objf);
- if (!item || PyList_Append (list.get (), item) == -1)
- return NULL;
- }
+ if (item == nullptr || PyList_Append (list.get (), item) == -1)
+ return NULL;
+ }
- return list.release ();
+ return list;
+}
+
+/* Return a sequence holding all the Objfiles. */
+
+static PyObject *
+gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
+{
+ return build_objfiles_list (current_program_space).release ();
}
/* Compute the list of active python type printers and store them in