public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* python: a patch for getting target thread id from a thread object
@ 2009-09-29  9:57 Noam Yorav-Raphael
  2009-09-29 18:05 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Noam Yorav-Raphael @ 2009-09-29  9:57 UTC (permalink / raw)
  To: archer

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 }
 };

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: python: a patch for getting target thread id from a thread object
  2009-09-29  9:57 python: a patch for getting target thread id from a thread object Noam Yorav-Raphael
@ 2009-09-29 18:05 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2009-09-29 18:05 UTC (permalink / raw)
  To: Noam Yorav-Raphael; +Cc: archer

>>>>> "Noam" == Noam Yorav-Raphael <noamraph@gmail.com> writes:

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

I think the idea is fine.

BTW do you have copyright papers on file?  I don't remember, and I can't
easily look... if not we have to do that before we can accept
non-trivial patches.

Noam> +  { "get_target_id", thpy_get_target_id, METH_NOARGS,
Noam> +    "get_target_id () -> str\n\
Noam> +Return the target ID of the thread." },

We went through and remove the "get_" prefixes everywhere a while back.
Also, I think this should be an attribute (see thread_object_getset), as
that is more consistent with our current API decisions.

Finally, this patch needs an update to doc/gdb.texinfo.

thanks,
Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-09-29 18:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-29  9:57 python: a patch for getting target thread id from a thread object Noam Yorav-Raphael
2009-09-29 18:05 ` Tom Tromey

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).