python: Add Inferior.progspace property

This patch adds a progspace property to the gdb.Inferior type, which
allows getting the gdb.Progspace object associated to that inferior.
In conjunction with the following patch, this will allow scripts iterate
on objfiles associated with a particular inferior.

gdb/ChangeLog:

	* python/py-inferior.c (infpy_get_progspace): New function.
	(inferior_object_getset): Add progspace property.
	* NEWS: Mention the new property.

gdb/doc/ChangeLog:

	* python.texi (Inferiors In Python): Document
	Inferior.progspace.
	(Program Spaces In Python): Document that
	gdb.current_progspace() is the same as
	gdb.selected_inferior().progspace.

gdb/testsuite/ChangeLog:

	* gdb.python/py-inferior.exp: Add tests for Inferior.progspace
	and a few other Inferior properties when the Inferior is no
	longer valid.
This commit is contained in:
Simon Marchi 2018-09-13 15:39:26 -04:00
parent 4a3fe98f88
commit a40bf0c2e9
7 changed files with 56 additions and 1 deletions

View file

@ -459,6 +459,23 @@ infpy_get_was_attached (PyObject *self, void *closure)
Py_RETURN_FALSE;
}
/* Getter of gdb.Inferior.progspace. */
static PyObject *
infpy_get_progspace (PyObject *self, void *closure)
{
inferior_object *inf = (inferior_object *) self;
INFPY_REQUIRE_VALID (inf);
program_space *pspace = inf->inferior->pspace;
gdb_assert (pspace != nullptr);
PyObject *py_pspace = pspace_to_pspace_object (pspace);
Py_XINCREF (py_pspace);
return py_pspace;
}
static int
build_inferior_list (struct inferior *inf, void *arg)
{
@ -966,6 +983,7 @@ static gdb_PyGetSetDef inferior_object_getset[] =
NULL },
{ "was_attached", infpy_get_was_attached, NULL,
"True if the inferior was created using 'attach'.", NULL },
{ "progspace", infpy_get_progspace, NULL, "Program space of this inferior" },
{ NULL }
};