aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorKevin Buettner <kevinb@redhat.com>2016-05-04 16:23:08 -0700
committerKevin Buettner <kevinb@redhat.com>2017-09-21 11:20:51 -0700
commitfbbe5337a6d839309c0415765803a19f3e38f6e4 (patch)
treeab14464ea4db78a911d04011b0ad4936f1f40873 /gdb/python
parente04ee09e24563f013c35cdebd7e9de3092b99b83 (diff)
downloadgdb-fbbe5337a6d839309c0415765803a19f3e38f6e4.zip
gdb-fbbe5337a6d839309c0415765803a19f3e38f6e4.tar.gz
gdb-fbbe5337a6d839309c0415765803a19f3e38f6e4.tar.bz2
Add `thread_from_thread_handle' method to (Python) gdb.Inferior
gdb/ChangeLog: * python/py-inferior.c (gdbpy_thread_from_thread_handle): New function. (inferior_object_methods): Add gdbpy_thread_from_thread_handle. * python/python-internal.h (thread_object_type): Declare.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-inferior.c54
-rw-r--r--gdb/python/python-internal.h2
2 files changed, 56 insertions, 0 deletions
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 5cad042..381586d 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -814,6 +814,56 @@ infpy_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
+/* Implementation of gdb.Inferior.thread_from_thread_handle (self, handle)
+ -> gdb.InferiorThread. */
+
+PyObject *
+infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
+{
+ PyObject *handle_obj, *result;
+ inferior_object *inf_obj = (inferior_object *) self;
+ static const char *keywords[] = { "thread_handle", NULL };
+
+ INFPY_REQUIRE_VALID (inf_obj);
+
+ if (! gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, &handle_obj))
+ return NULL;
+
+ result = Py_None;
+
+ if (!gdbpy_is_value_object (handle_obj))
+ {
+ PyErr_SetString (PyExc_TypeError,
+ _("Argument 'handle_obj' must be a thread handle object."));
+
+ return NULL;
+ }
+ else
+ {
+ TRY
+ {
+ struct thread_info *thread_info;
+ struct value *val = value_object_to_value (handle_obj);
+
+ thread_info = find_thread_by_handle (val, inf_obj->inferior);
+ if (thread_info != NULL)
+ {
+ result = (PyObject *) find_thread_object (thread_info->ptid);
+ if (result != NULL)
+ Py_INCREF (result);
+ }
+ }
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDB_PY_HANDLE_EXCEPTION (except);
+ }
+ END_CATCH
+ }
+
+ return result;
+}
+
+
static void
infpy_dealloc (PyObject *obj)
{
@@ -926,6 +976,10 @@ Write the given buffer object to the inferior's memory." },
METH_VARARGS | METH_KEYWORDS,
"search_memory (address, length, pattern) -> long\n\
Return a long with the address of a match, or None." },
+ { "thread_from_thread_handle", (PyCFunction) infpy_thread_from_thread_handle,
+ METH_VARARGS | METH_KEYWORDS,
+ "thread_from_thread_handle (handle) -> gdb.InferiorThread.\n\
+Return thread object corresponding to thread handle." },
{ NULL }
};
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index a8270b2..8fc8cc5 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -377,6 +377,8 @@ extern PyTypeObject breakpoint_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("breakpoint_object");
extern PyTypeObject frame_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("frame_object");
+extern PyTypeObject thread_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("thread_object");
typedef struct gdbpy_breakpoint_object
{