[PATCH v2 2/5] Add python method InferiorThread.thread_handle
Kevin Buettner
kevinb@redhat.com
Thu Feb 28 02:31:00 GMT 2019
gdb/ChangeLog:
* python/py-infthread.c (thpy_thread_handle): New function.
(thread_object_methods): Register thpy_thread_handle.
---
gdb/python/py-infthread.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index bf90d08ae6..13e11b16e1 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -257,6 +257,24 @@ thpy_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
+/* Implementation of gdb.InferiorThread.thread_handle (self) -> handle. */
+
+static PyObject *
+thpy_thread_handle (PyObject *self, PyObject *args)
+{
+ thread_object *thread_obj = (thread_object *) self;
+ THPY_REQUIRE_VALID (thread_obj);
+
+ gdb::byte_vector hv = target_thread_info_to_thread_handle (thread_obj->thread);
+
+ if (hv.size () == 0)
+ return NULL;
+
+ PyObject *object = PyBytes_FromStringAndSize ((const char *) hv.data (),
+ hv.size());
+ return object;
+}
+
/* Return a reference to a new Python object representing a ptid_t.
The object is a tuple containing (pid, lwp, tid). */
PyObject *
@@ -336,6 +354,9 @@ Return whether the thread is running." },
{ "is_exited", thpy_is_exited, METH_NOARGS,
"is_exited () -> Boolean\n\
Return whether the thread is exited." },
+ { "thread_handle", thpy_thread_handle, METH_NOARGS,
+ "thread_handle () -> handle\n\
+Return thread handle for thread." },
{ NULL }
};
More information about the Gdb-patches
mailing list