Add `thread_from_thread_handle' method to (Python) gdb.Inferior
authorKevin Buettner <kevinb@redhat.com>
Wed, 4 May 2016 23:23:08 +0000 (16:23 -0700)
committerKevin Buettner <kevinb@redhat.com>
Thu, 21 Sep 2017 18:20:51 +0000 (11:20 -0700)
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.

gdb/ChangeLog
gdb/python/py-inferior.c
gdb/python/python-internal.h

index be466cb64ef4ab74ad37cb20b41d6693b3ffcdc7..bf9d0871e9017e0976577fa489d8aea96fa637c4 100644 (file)
@@ -1,3 +1,10 @@
+2017-09-21  Kevin Buettner  <kevinb@redhat.com>
+
+       * 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.
+
 2017-09-21  Kevin Buettner  <kevinb@redhat.com>
 
        * target.h (struct target_ops): Add to_thread_handle_to_thread_info.
index 5cad042f820ff20680438189980b2a63bb65a92f..381586d82dc05f3a6e9e3e1e3465828253f689e7 100644 (file)
@@ -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 }
 };
 
index a8270b26adcf5abf4a4405f9843cd78b6ebb8867..8fc8cc5a5d2b0b78e9cfa2bbcabe2723febca18b 100644 (file)
@@ -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
 {
This page took 0.032108 seconds and 4 git commands to generate.