Add gdb.Objfile.is_file attribute

Sometimes an objfile comes from memory and not from a file.  It can be
useful to be able to check this from Python, so this patch adds a new
"is_file" attribute.
This commit is contained in:
Tom Tromey
2022-06-20 12:32:52 -06:00
parent 3acd9a692d
commit 99298c958c
4 changed files with 36 additions and 0 deletions

View File

@ -101,6 +101,18 @@ objfpy_get_username (PyObject *self, void *closure)
Py_RETURN_NONE;
}
/* Get the 'is_file' attribute. */
static PyObject *
objfpy_get_is_file (PyObject *o, void *ignore)
{
objfile_object *self = (objfile_object *) o;
if (self->objfile != nullptr)
return PyBool_FromLong ((self->objfile->flags & OBJF_NOT_FILENAME) == 0);
Py_RETURN_NONE;
}
/* If SELF is a separate debug-info file, return the "backlink" field.
Otherwise return None. */
@ -762,6 +774,8 @@ static gdb_PyGetSetDef objfile_getset[] =
"Type printers.", NULL },
{ "xmethods", objfpy_get_xmethods, NULL,
"Debug methods.", NULL },
{ "is_file", objfpy_get_is_file, nullptr,
"Whether this objfile came from a file.", nullptr },
{ NULL }
};