diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2018-09-13 15:40:41 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2018-09-13 15:42:12 -0400 |
commit | 0ae1a3211adcb8e7518b0b656b2309ebbc45e9ae (patch) | |
tree | 96c5436eeaac8f151adfd96c5fc17117b8f3b4ba /gdb/python/py-progspace.c | |
parent | a40bf0c2e93daac4ae4ce7dd1c43ab6135e76720 (diff) | |
download | binutils-0ae1a3211adcb8e7518b0b656b2309ebbc45e9ae.zip binutils-0ae1a3211adcb8e7518b0b656b2309ebbc45e9ae.tar.gz binutils-0ae1a3211adcb8e7518b0b656b2309ebbc45e9ae.tar.bz2 |
python: Add Progspace.objfiles method
This patch adds an objfiles method to the Progspace object, which
returns a sequence of the objfiles associated to that program space. I
chose a method rather than a property for symmetry with gdb.objfiles().
gdb/ChangeLog:
* python/py-progspace.c (PSPY_REQUIRE_VALID): New macro.
(pspy_get_objfiles): New function.
(progspace_object_methods): New.
(pspace_object_type): Add tp_methods callback.
* python/python-internal.h (build_objfiles_list): New
declaration.
* python/python.c (build_objfiles_list): New function.
(gdbpy_objfiles): Implement using build_objfiles_list.
* NEWS: Mention the Progspace.objfiles method.
gdb/doc/ChangeLog:
* python.texi (Program Spaces In Python): Document the
Progspace.objfiles method.
(Objfiles In Python): Mention that gdb.objfiles() is identical
to gdb.selected_inferior().progspace.objfiles().
gdb/testsuite/ChangeLog:
* gdb.python/py-progspace.exp: Test the Progspace.objfiles
method.
Diffstat (limited to 'gdb/python/py-progspace.c')
-rw-r--r-- | gdb/python/py-progspace.c | 32 |
1 files changed, 29 insertions, 3 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 */ |