[PATCH] gdb/python: Add gdb.InferiorThread.details attribute
Andrew Burgess
aburgess@redhat.com
Tue Feb 15 11:52:33 GMT 2022
This adds a new read-only attribute gdb.InferiorThread.details, this
attribute contains a string, the results of target_extra_thread_info
for the thread, or None, if target_extra_thread_info returns nullptr.
As the string returned by target_extra_thread_info is unstructured,
this attribute is only really useful for echoing straight through to
the user, but, if a user wants to write a command that displays the
same, or a similar 'Thread Id' to the one seen in 'info threads', then
they need access to this string.
Given that the string produced by target_extra_thread_info varies by
target, there's only minimal testing of this attribute, I check that
the attribute can be accessed, and that the return value is either
None, or a string.
---
gdb/NEWS | 5 +++++
gdb/doc/python.texi | 7 +++++++
gdb/python/py-infthread.c | 21 +++++++++++++++++++++
gdb/testsuite/gdb.python/py-infthread.exp | 5 +++++
4 files changed, 38 insertions(+)
diff --git a/gdb/NEWS b/gdb/NEWS
index 9da74e71796..10b5489622c 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -185,6 +185,11 @@ GNU/Linux/LoongArch loongarch*-*-linux*
set styling'). When false, which is the default if the argument
is not given, then no styling is applied to the returned string.
+ ** New read-only attribute gdb.InferiorThread.details, which is
+ either a string, containing additional, target specific thread
+ state information, or None, if there is no such additional
+ information.
+
* New features in the GDB remote stub, GDBserver
** GDBserver is now supported on OpenRISC GNU/Linux.
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index c1a3f5f2a7e..ac4ebbeaeae 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3574,6 +3574,13 @@
a @code{gdb.Inferior} object. This attribute is not writable.
@end defvar
+@defvar InferiorThread.details
+A string containing target specific, thread state information. The
+format of this string varies by target. If there is no additional
+state information for this thread, then this attribute contains
+@code{None}.
+@end defvar
+
A @code{gdb.InferiorThread} object has the following methods:
@defun InferiorThread.is_valid ()
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index e568d8d916e..efd536688c1 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -76,6 +76,24 @@ thpy_get_name (PyObject *self, void *ignore)
return PyString_FromString (name);
}
+/* Return a string containing target specific additional information about
+ the state of the thread, or None, if there is no such additional
+ information. */
+
+static PyObject *
+thpy_get_details (PyObject *self, void *ignore)
+{
+ thread_object *thread_obj = (thread_object *) self;
+
+ THPY_REQUIRE_VALID (thread_obj);
+
+ const char *extra_info = target_extra_thread_info (thread_obj->thread);
+ if (extra_info == nullptr)
+ Py_RETURN_NONE;
+
+ return PyString_FromString (extra_info);
+}
+
static int
thpy_set_name (PyObject *self, PyObject *newvalue, void *ignore)
{
@@ -347,6 +365,9 @@ static gdb_PyGetSetDef thread_object_getset[] =
{
{ "name", thpy_get_name, thpy_set_name,
"The name of the thread, as set by the user or the OS.", NULL },
+ { "details", thpy_get_details, NULL,
+ "A target specific string containing extra thread state details.",
+ NULL },
{ "num", thpy_get_num, NULL,
"Per-inferior number of the thread, as assigned by GDB.", NULL },
{ "global_num", thpy_get_global_num, NULL,
diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
index 5cbbe43c44c..a7754198e60 100644
--- a/gdb/testsuite/gdb.python/py-infthread.exp
+++ b/gdb/testsuite/gdb.python/py-infthread.exp
@@ -77,6 +77,11 @@ gdb_py_test_silent_cmd "python gdb.selected_thread().name = None" \
gdb_test "python print (gdb.selected_thread().name == name)" "True" \
"check name of current thread again"
+gdb_test_no_output "python details = gdb.selected_thread().details" \
+ "record the thread details string"
+gdb_test "python print(details is None or isinstance(details, str))" "True" \
+ "check that the details has an acceptable type"
+
gdb_test "python print ('result = %s' % t0.is_stopped ())" " = True" "test InferiorThread.is_stopped"
gdb_test "python print ('result = %s' % t0.is_running ())" " = False" "test InferiorThread.is_running"
gdb_test "python print ('result = %s' % t0.is_exited ())" " = False" "test InferiorThread.is_exited"
--
2.25.4
More information about the Gdb-patches
mailing list