gdb/python: new Progspace.executable_filename attribute

Add a new Progspace.executable_filename attribute that contains the
path to the executable for this program space, or None if no
executable is set.

The path within this attribute will be set by the "exec-file" and/or
"file" commands.

Accessing this attribute for an invalid program space will raise an
exception.

This new attribute is similar too, but not the same as the existing
gdb.Progspace.filename attribute.  If I could change the past, I'd
change the 'filename' attribute to 'symbol_filename', which is what it
actually represents.  The old attribute will be set by the
'symbol-file' command, while the new attribute is set by the
'exec-file' command.  Obviously the 'file' command sets both of these
attributes.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Andrew Burgess
2023-09-07 15:47:07 +01:00
parent 5ce85461a1
commit 4e02aca0c5
5 changed files with 165 additions and 0 deletions

View File

@ -131,6 +131,25 @@ pspy_get_symbol_file (PyObject *self, void *closure)
Py_RETURN_NONE;
}
/* Implement the gdb.Progspace.executable_filename attribute. Retun a
string containing the name of the current executable, or None if no
executable is currently set. If the Progspace is invalid then raise an
exception. */
static PyObject *
pspy_get_exec_file (PyObject *self, void *closure)
{
pspace_object *obj = (pspace_object *) self;
PSPY_REQUIRE_VALID (obj);
const char *filename = obj->pspace->exec_filename.get ();
if (filename != nullptr)
return host_string_to_python_string (filename).release ();
Py_RETURN_NONE;
}
static void
pspy_dealloc (PyObject *self)
{
@ -596,6 +615,8 @@ static gdb_PyGetSetDef pspace_getset[] =
{ "symbol_file", pspy_get_symbol_file, nullptr,
"The gdb.Objfile for the progspace's main symbol file, or None.",
nullptr},
{ "executable_filename", pspy_get_exec_file, nullptr,
"The filename for the progspace's executable, or None.", nullptr},
{ "pretty_printers", pspy_get_printers, pspy_set_printers,
"Pretty printers.", NULL },
{ "frame_filters", pspy_get_frame_filters, pspy_set_frame_filters,