[2/4] Add python method gdb.InferiorThread.thread_handle
Commit Message
gdb/ChangeLog:
* py-infthread.c (thpy_thread_handle): New function.
(thread_object_methods): Add thpy_thread_handle.
---
gdb/python/py-infthread.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
@@ -253,6 +253,32 @@ thpy_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
+/* Implementation of gdb.InferiorThread.thread_handle (self, gdbtype) -> handle. */
+
+static PyObject *
+thpy_thread_handle (PyObject *self, PyObject *args)
+{
+ PyObject *type_obj;
+ struct type *type;
+ thread_object *thread_obj = (thread_object *) self;
+
+ THPY_REQUIRE_VALID (thread_obj);
+
+ if (! PyArg_ParseTuple (args, "O", &type_obj))
+ return NULL;
+
+ type = type_object_to_type (type_obj);
+ if (type == nullptr)
+ {
+ PyErr_SetString (PyExc_RuntimeError,
+ _("Argument must be a type."));
+ return NULL;
+ }
+
+ return value_to_value_object
+ (thread_to_thread_handle (thread_obj->thread, type));
+}
+
/* Return a reference to a new Python object representing a ptid_t.
The object is a tuple containing (pid, lwp, tid). */
PyObject *
@@ -340,6 +366,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_VARARGS,
+ "thread_handle (gdbtype) -> handle\n\
+Return thread handle for thread." },
{ NULL }
};