From 99298c958c5393402cd2bc2885c195838a9dd363 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 20 Jun 2022 12:32:52 -0600 Subject: 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. --- gdb/python/py-objfile.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gdb/python/py-objfile.c') diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 3e3270e..298f3f2 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -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 } }; -- cgit v1.1