gdb/python: Add gdb.InferiorThread.details attribute

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.
This commit is contained in:
Andrew Burgess 2022-02-14 17:02:03 +00:00
parent ea764154c2
commit 659971cb0f
5 changed files with 58 additions and 0 deletions

View file

@ -76,6 +76,32 @@ 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;
try
{
extra_info = target_extra_thread_info (thread_obj->thread);
}
catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
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 +373,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,