summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Vrany <jan.vrany@labware.com>2022-03-18 15:33:13 +0000
committerJan Vrany <jan.vrany@labware.com>2023-04-21 16:05:56 +0100
commitcddc37e79994008d968aad80fe0b7e23bb6f363f (patch)
tree3a13ec0a4448a66393ef8e4734e8adef76ee7ae5
parentd687163fd902541a0f99563a3821f9503de1d440 (diff)
downloadbinutils-gdb-cddc37e79994008d968aad80fe0b7e23bb6f363f.tar.gz
gdb/python: add is_dynamic attribute to Objfile Python object
-rw-r--r--gdb/doc/python.texi4
-rw-r--r--gdb/objfiles.h7
-rw-r--r--gdb/python/py-objfile.c25
-rw-r--r--gdb/python/python-internal.h1
-rw-r--r--gdb/testsuite/gdb.python/py-objfile.exp5
5 files changed, 42 insertions, 0 deletions
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 1315ddcacbc..92d7f80aaa8 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -5138,6 +5138,10 @@ The @code{frame_filters} attribute is a dictionary of frame filter
objects. @xref{Frame Filter API}, for more information.
@end defvar
+@defvar Objfile.is_dynamic
+The @code{is_dynamic} attribute indicates whether the objfile is dynamic or not.
+@end defvar
+
One may add arbitrary attributes to @code{gdb.Objfile} objects
in the usual Python way.
This is useful if, for example, one needs to do some extra record keeping
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 342aa09ac6a..ac4c43b2930 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -784,6 +784,13 @@ public:
next time. If an objfile does not have the symbols, it will
never have them. */
bool skip_jit_symbol_lookup = false;
+
+ /* Return true if this objfile is dynamic (created by JIT reader API or
+ by from Python by instantiating gdb.Objfile object). */
+ bool is_dynamic() const
+ {
+ return this->obfd == nullptr;
+ }
};
/* A deleter for objfile. */
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 3676763e29b..f7bc440cf31 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -188,6 +188,21 @@ objfpy_get_progspace (PyObject *self, void *closure)
Py_RETURN_NONE;
}
+/* An Objfile method which returns whether this Objfile is dynamic or not. */
+
+static PyObject *
+objfpy_get_is_dynamic (PyObject *self, void *closure)
+{
+ objfile_object *obj = (objfile_object *) self;
+
+ OBJFPY_REQUIRE_VALID (obj);
+
+ if (obj->objfile->is_dynamic ())
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
+
static void
objfpy_dealloc (PyObject *o)
{
@@ -733,6 +748,14 @@ objfile_to_objfile_object (struct objfile *objfile)
return gdbpy_ref<>::new_reference (result);
}
+struct objfile *
+objfile_object_to_objfile (PyObject *obj)
+{
+ if (! PyObject_TypeCheck (obj, &objfile_object_type))
+ return nullptr;
+ return ((objfile_object *) obj)->objfile;
+}
+
int
gdbpy_initialize_objfile (void)
{
@@ -796,6 +819,8 @@ static gdb_PyGetSetDef objfile_getset[] =
"Debug methods.", NULL },
{ "is_file", objfpy_get_is_file, nullptr,
"Whether this objfile came from a file.", nullptr },
+ { "is_dynamic", objfpy_get_is_dynamic, NULL,
+ "True if this Objfile is dynamic, else False.", NULL },
{ NULL }
};
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 258f5c42537..acb7ca8f6cc 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -480,6 +480,7 @@ struct symtab *symtab_object_to_symtab (PyObject *obj);
struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
frame_info_ptr frame_object_to_frame_info (PyObject *frame_obj);
struct gdbarch *arch_object_to_gdbarch (PyObject *obj);
+struct objfile *objfile_object_to_objfile (PyObject *obj);
/* Convert Python object OBJ to a program_space pointer. OBJ must be a
gdb.Progspace reference. Return nullptr if the gdb.Progspace is not
diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp
index db9733b1f0e..ff6d1272883 100644
--- a/gdb/testsuite/gdb.python/py-objfile.exp
+++ b/gdb/testsuite/gdb.python/py-objfile.exp
@@ -91,6 +91,8 @@ gdb_test "python print (objfile.progspace)" "<gdb\.Progspace object at .*>" \
"Get objfile program space"
gdb_test "python print (objfile.is_valid())" "True" \
"Get objfile validity"
+gdb_test "python print (objfile.is_dynamic)" "False" \
+ "Check is_dynamic() returns False"
gdb_unload "unload 1"
@@ -181,3 +183,6 @@ gdb_py_test_silent_cmd "python objfile = gdb.Objfile(\"Test objfile\")" \
gdb_test "python print(objfile)" \
"<gdb.Objfile filename=Test objfile>" \
"print dynamic objfile"
+
+gdb_test "python print (objfile.is_dynamic)" "True" \
+ "Check is_dynamic() returns True for Python-created objfile"