public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Pedro Alves <palves@redhat.com>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH v3 2/7] Add Python InferiorThread.inferior attribute
Date: Wed, 06 Jan 2016 18:57:00 -0000	[thread overview]
Message-ID: <568D6382.6090507@ericsson.com> (raw)
In-Reply-To: <1452085418-18300-3-git-send-email-palves@redhat.com>

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  <palves@redhat.com>
> 
> 	* 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  <palves@redhat.com>
> 
> 	* gdb.python/py-infthread.exp: Test InferiorThread.inferior.
> 
> gdb/doc/ChangeLog:
> 2016-01-06  Pedro Alves  <palves@redhat.com>
> 
> 	* 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.InferiorThread object at 0x\[\[:xdigit:\]\]
>  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.

  reply	other threads:[~2016-01-06 18:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-06 13:03 [PATCH v3 0/7] Per-inferior/Inferior-qualified thread IDs Pedro Alves
2016-01-06 13:03 ` [PATCH v3 1/7] Add a new $_inferior convenience variable Pedro Alves
2016-01-06 18:56   ` Simon Marchi
2016-01-06 13:03 ` [PATCH v3 3/7] Centralize thread ID printing Pedro Alves
2016-01-06 18:57   ` Simon Marchi
2016-01-06 13:03 ` [PATCH v3 2/7] Add Python InferiorThread.inferior attribute Pedro Alves
2016-01-06 18:57   ` Simon Marchi [this message]
2016-01-06 13:03 ` [PATCH v3 5/7] InferiorThread.global_num Pedro Alves
2016-01-06 19:03   ` Simon Marchi
2016-01-06 13:04 ` [PATCH v3 4/7] Per-inferior/Inferior-qualified thread IDs Pedro Alves
2016-01-06 18:51   ` Simon Marchi
2016-01-07 19:45     ` Pedro Alves
2016-01-07 22:28       ` Simon Marchi
2016-01-07 23:37         ` Pedro Alves
2016-12-07 21:10           ` Thomas Schwinge
2016-12-07 21:29             ` Simon Marchi
2016-12-08  8:53               ` Thomas Schwinge
2016-01-07 22:02   ` Simon Marchi
2016-01-07 22:24     ` Pedro Alves
2016-01-06 13:11 ` [PATCH v3 6/7] Implement "info threads -gid" Pedro Alves
2016-01-06 19:12   ` Simon Marchi
2016-01-06 13:11 ` [PATCH v3 7/7] Add $_gthread convenience variable Pedro Alves
2016-01-06 19:14   ` Simon Marchi
2016-01-08 13:54 ` [PATCH v3 0/7] Per-inferior/Inferior-qualified thread IDs Yao Qi
2016-01-13 11:25   ` Pedro Alves

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=568D6382.6090507@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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).