From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32408 invoked by alias); 6 Jan 2016 18:57:10 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 32398 invoked by uid 89); 6 Jan 2016 18:57:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy= X-HELO: usplmg20.ericsson.net Received: from usplmg20.ericsson.net (HELO usplmg20.ericsson.net) (198.24.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 06 Jan 2016 18:57:08 +0000 Received: from EUSAAHC007.ericsson.se (Unknown_Domain [147.117.188.93]) by usplmg20.ericsson.net (Symantec Mail Security) with SMTP id 83.DC.06940.3B16D865; Wed, 6 Jan 2016 19:49:23 +0100 (CET) Received: from [142.133.110.144] (147.117.188.8) by smtp-am.internal.ericsson.com (147.117.188.95) with Microsoft SMTP Server id 14.3.248.2; Wed, 6 Jan 2016 13:57:06 -0500 Subject: Re: [PATCH v3 2/7] Add Python InferiorThread.inferior attribute To: Pedro Alves , References: <1452085418-18300-1-git-send-email-palves@redhat.com> <1452085418-18300-3-git-send-email-palves@redhat.com> From: Simon Marchi Message-ID: <568D6382.6090507@ericsson.com> Date: Wed, 06 Jan 2016 18:57:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <1452085418-18300-3-git-send-email-palves@redhat.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg00098.txt.bz2 On 16-01-06 08:03 AM, Pedro Alves wrote: > So a script can easily get at a thread's inferior and its number. > > gdb/ChangeLog: > 2016-01-06 Pedro Alves > > * NEWS: Mention InferiorThread.inferior. > * python/py-infthread.c (thpy_get_inferior): New. > (thread_object_getset): Register "inferior". > > gdb/testsuite/ChangeLog: > 2016-01-06 Pedro Alves > > * gdb.python/py-infthread.exp: Test InferiorThread.inferior. > > gdb/doc/ChangeLog: > 2016-01-06 Pedro Alves > > * python.texi (Threads In Python): Document > InferiorThread.inferior. > --- > gdb/NEWS | 5 +++++ > gdb/doc/python.texi | 5 +++++ > gdb/python/py-infthread.c | 14 ++++++++++++++ > gdb/testsuite/gdb.python/py-infthread.exp | 3 +++ > 4 files changed, 27 insertions(+) > > diff --git a/gdb/NEWS b/gdb/NEWS > index 31c870d..57a6c71 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -151,6 +151,11 @@ show remote exec-event-feature-packet > format. It outputs data in hexadecimal format with zero-padding on the > left. > > +* Python Scripting > + > + ** gdb.InferiorThread objects have a new attribute "inferior", which > + is the Inferior object the thread belongs to. > + > *** Changes in GDB 7.10 > > * Support for process record-replay and reverse debugging on aarch64*-linux* > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index e749810..855da44 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -3006,6 +3006,11 @@ Either the LWPID or TID may be 0, which indicates that the operating system > does not use that identifier. > @end defvar > > +@defvar InferiorThread.inferior > +The inferior this thread belongs to. This attribute is represented as > +a @code{gdb.Inferior} object. This attribute is not writable. > +@end defvar > + > A @code{gdb.InferiorThread} object has the following methods: > > @defun InferiorThread.is_valid () > diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c > index 2637f60..5075071 100644 > --- a/gdb/python/py-infthread.c > +++ b/gdb/python/py-infthread.c > @@ -140,6 +140,18 @@ thpy_get_ptid (PyObject *self, void *closure) > return gdbpy_create_ptid_object (thread_obj->thread->ptid); > } > > +/* Getter for InferiorThread.inferior -> Inferior. */ > + > +static PyObject * > +thpy_get_inferior (PyObject *self, void *ignore) > +{ > + thread_object *thread_obj = (thread_object *) self; > + > + THPY_REQUIRE_VALID (thread_obj); > + > + return thread_obj->inf_obj; > +} > + > /* Implementation of InferiorThread.switch (). > Makes this the GDB selected thread. */ > > @@ -285,6 +297,8 @@ static PyGetSetDef thread_object_getset[] = > { "num", thpy_get_num, NULL, "ID of the thread, as assigned by GDB.", NULL }, > { "ptid", thpy_get_ptid, NULL, "ID of the thread, as assigned by the OS.", > NULL }, > + { "inferior", thpy_get_inferior, NULL, > + "The Inferior object this thread belongs to.", NULL }, > > { NULL } > }; > diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp > index 6e02d02..e07fd82 100644 > --- a/gdb/testsuite/gdb.python/py-infthread.exp > +++ b/gdb/testsuite/gdb.python/py-infthread.exp > @@ -44,6 +44,9 @@ gdb_test "python print (t0)" "\\ gdb_test "python print ('result = %s' % t0.num)" " = 1" "test InferiorThread.num" > gdb_test "python print ('result = %s' % str (t0.ptid))" " = \\(\[0-9\]+, \[0-9\]+, \[0-9\]+\\)" "test InferiorThread.ptid" > > +gdb_py_test_silent_cmd "python i0 = t0.inferior" "test InferiorThread.inferior" 1 > +gdb_test "python print ('result = %s' % i0.num)" " = 1" "test Inferior.num" > + > gdb_py_test_silent_cmd "python name = gdb.selected_thread().name" \ > "get supplied name of current thread" 1 > gdb_py_test_silent_cmd "python gdb.selected_thread().name = 'hibob'" \ > LGTM.