public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Noam Yorav-Raphael <noamraph@gmail.com>
To: archer <archer@sourceware.org>
Subject: python: a patch for getting target thread id from a thread object
Date: Tue, 29 Sep 2009 09:57:00 -0000	[thread overview]
Message-ID: <b348a0850909290257i6d4ba4aue264a625f656d45f@mail.gmail.com> (raw)

Hello,

Here's a simple patch which adds a method for getting the target
thread id of a Thread object.

My use case is this: I'm writing a gdb script in python which allows
you to attach to running Python processes with a Python debugger
(winpdb).
This is done by switching to the thread which has the Python GIL and
running there some Python commands which start the winpdb debugging
server.
The ID of the thread which has the GIL is available in a global
(_PyThreadState_Current->thread_id). However, currently there's no way
for the python script to know to which thread it should switch, since
it only has access to the internal GDB thread number. The patch fixes
it.

Thanks,
Noam


diff --git a/gdb/python/python-infthread.c b/gdb/python/python-infthread.c
index 21e4eab..7e97f8c 100644
--- a/gdb/python/python-infthread.c
+++ b/gdb/python/python-infthread.c
@@ -73,7 +73,19 @@ thpy_get_num (PyObject *self, void *closure)
   return PyLong_FromLong (thread_obj->thread->num);
 }

+/* Implementation of Thread.get_target_id () -> str.
+   Returns the target ID.  */
+PyObject *
+thpy_get_target_id (PyObject *self, PyObject *args)
+{
+  thread_object *thread_obj = (thread_object *) self;
+
+  THPY_REQUIRE_VALID (thread_obj);
+
+  return PyString_FromString (target_pid_to_str (thread_obj->thread->ptid));
+}
+
+

 /* Implementation of Inferior.frames () -> (gdb.Frame, ...).
    Returns a tuple of all frame objects.  */
@@ -238,6 +251,9 @@ Return the newest frame in the thread." },
   { "switch", thpy_switch, METH_NOARGS,
     "switch ()\n\
 Makes this the GDB selected thread." },
+  { "get_target_id", thpy_get_target_id, METH_NOARGS,
+    "get_target_id () -> str\n\
+Return the target ID of the thread." },

   { NULL }
 };

             reply	other threads:[~2009-09-29  9:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-29  9:57 Noam Yorav-Raphael [this message]
2009-09-29 18:05 ` Tom Tromey

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=b348a0850909290257i6d4ba4aue264a625f656d45f@mail.gmail.com \
    --to=noamraph@gmail.com \
    --cc=archer@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).