This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v4 2/6] Add python method InferiorThread.handle
- From: Kevin Buettner <kevinb at redhat dot com>
- To: gdb-patches at sourceware dot org
- Cc: Kevin Buettner <kevinb at redhat dot com>
- Date: Thu, 4 Apr 2019 09:58:50 -0700
- Subject: [PATCH v4 2/6] Add python method InferiorThread.handle
- References: <20190404165854.17343-1-kevinb@redhat.com>
gdb/ChangeLog:
* python/py-infthread.c (thpy_thread_handle): New function.
(thread_object_methods): Register thpy_thread_handle.
---
gdb/python/py-infthread.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index bf90d08ae6..1d201b9b35 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -257,6 +257,37 @@ thpy_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
+/* Implementation of gdb.InferiorThread.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;
+
+ TRY
+ {
+ hv = target_thread_info_to_thread_handle (thread_obj->thread);
+ }
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ GDB_PY_HANDLE_EXCEPTION (ex);
+ }
+ END_CATCH
+
+ if (hv.size () == 0)
+ {
+ PyErr_SetString (PyExc_RuntimeError, _("Thread handle not found."));
+ 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 +367,9 @@ Return whether the thread is running." },
{ "is_exited", thpy_is_exited, METH_NOARGS,
"is_exited () -> Boolean\n\
Return whether the thread is exited." },
+ { "handle", thpy_thread_handle, METH_NOARGS,
+ "handle () -> handle\n\
+Return thread library specific handle for thread." },
{ NULL }
};
--
2.20.1