Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Subject: Re: [PATCH v4 2/7] Add `thread_from_thread_handle' method to (Python) gdb.Inferior
Date: Wed, 16 Aug 2017 17:37:00 -0000	[thread overview]
Message-ID: <20170816103657.283cd869@pinnacle.lan> (raw)
In-Reply-To: <20170816092542.6d2deb00@pinnacle.lan>

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/python/py-inferior.c     | 54 ++++++++++++++++++++++++++++++++++++++++++++
 gdb/python/python-internal.h |  2 ++
 2 files changed, 56 insertions(+)

diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index f6a24a0..67a7e6e 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -751,6 +751,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)
 {
@@ -861,6 +911,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 ebb83f0..40e64f0 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -379,6 +379,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
 {


  parent reply	other threads:[~2017-08-16 17:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-16 16:25 [PATCH v4 0/7] Thread handle to thread info mapping Kevin Buettner
2017-08-16 17:35 ` [PATCH v4 1/7] Add target method for converting thread handle to thread_info struct pointer Kevin Buettner
2017-08-16 17:37 ` Kevin Buettner [this message]
2017-08-16 17:38 ` [PATCH v4 3/7] Documentation for Inferior.thread_from_thread_handle Kevin Buettner
2017-08-16 17:40 ` [PATCH v4 4/7] Test case " Kevin Buettner
2017-08-16 17:41 ` [PATCH v4 5/7] Add thread_db_notice_clone to gdbserver Kevin Buettner
2017-09-29 12:24   ` Pedro Alves
2017-08-16 17:43 ` [PATCH v4 6/7] Add thread_handle_to_thread_info support for remote targets Kevin Buettner
2017-08-16 17:44 ` [PATCH v4 7/7] Documentation for qXfer:threads:read handle attribute Kevin Buettner
2017-09-13  0:00 ` [PATCH v4 0/7] Thread handle to thread info mapping Kevin Buettner
2017-09-18 20:17 ` Simon Marchi
2017-09-21 18:56   ` Kevin Buettner
2017-09-21 18:57 ` Kevin Buettner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170816103657.283cd869@pinnacle.lan \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox