aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2024-01-09 17:29:24 +0000
committerAndrew Burgess <aburgess@redhat.com>2024-01-12 09:22:25 +0000
commit76118e1675f5eaf3fc44524ec435981705572629 (patch)
tree4f4351eece10850ac947757b538a795a72e43491 /gdb/python
parent322ffd247e4e95a0d5a1b11ad1ef91f3378e6174 (diff)
downloadbinutils-76118e1675f5eaf3fc44524ec435981705572629.zip
binutils-76118e1675f5eaf3fc44524ec435981705572629.tar.gz
binutils-76118e1675f5eaf3fc44524ec435981705572629.tar.bz2
gdb/python: New InferiorThread.ptid_string attribute
This commit adds a new InferiorThread.ptid_string attribute. This read-only attribute contains the string returned by target_pid_to_str, which actually converts a ptid (not pid) to a string. This is the string that appears (at least in part) in the output of 'info threads' in the 'Target Id' column, but also in the thread exited message that GDB prints. Having access to this string from Python is useful for allowing extensions identify threads in a similar way to how GDB core would identify the thread. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-infthread.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 00d7171..632984d 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -185,6 +185,30 @@ thpy_get_ptid (PyObject *self, void *closure)
return gdbpy_create_ptid_object (thread_obj->thread->ptid);
}
+/* Implement gdb.InferiorThread.ptid_string attribute. */
+
+static PyObject *
+thpy_get_ptid_string (PyObject *self, void *closure)
+{
+ thread_object *thread_obj = (thread_object *) self;
+ THPY_REQUIRE_VALID (thread_obj);
+ ptid_t ptid = thread_obj->thread->ptid;
+
+ try
+ {
+ /* Select the correct inferior before calling a target_* function. */
+ scoped_restore_current_thread restore_thread;
+ switch_to_inferior_no_thread (thread_obj->thread->inf);
+ std::string ptid_str = target_pid_to_str (ptid);
+ return PyUnicode_FromString (ptid_str.c_str ());
+ }
+ catch (const gdb_exception &except)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ return nullptr;
+ }
+}
+
/* Getter for InferiorThread.inferior -> Inferior. */
static PyObject *
@@ -388,6 +412,9 @@ static gdb_PyGetSetDef thread_object_getset[] =
"Global number of the thread, as assigned by GDB.", NULL },
{ "ptid", thpy_get_ptid, NULL, "ID of the thread, as assigned by the OS.",
NULL },
+ { "ptid_string", thpy_get_ptid_string, nullptr,
+ "A string representing ptid, as used by, for example, 'info threads'.",
+ nullptr },
{ "inferior", thpy_get_inferior, NULL,
"The Inferior object this thread belongs to.", NULL },