From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7426 invoked by alias); 29 Sep 2009 09:57:11 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 7411 invoked by uid 22791); 29 Sep 2009 09:57:09 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Date: Tue, 29 Sep 2009 09:57:00 -0000 Message-ID: Subject: python: a patch for getting target thread id from a thread object From: Noam Yorav-Raphael To: archer Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2009-q3/txt/msg00261.txt.bz2 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 } };