This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Add Python InferiorThread.inferior attribute


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8465445732dc04c3fb6cf954274e12d06b274f08

commit 8465445732dc04c3fb6cf954274e12d06b274f08
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Jan 13 10:56:06 2016 +0000

    Add Python InferiorThread.inferior attribute
    
    So a script can easily get at a thread's inferior and its number.
    
    gdb/ChangeLog:
    2016-01-13  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-13  Pedro Alves  <palves@redhat.com>
    
    	* gdb.python/py-infthread.exp: Test InferiorThread.inferior.
    
    gdb/doc/ChangeLog:
    2016-01-13  Pedro Alves  <palves@redhat.com>
    
    	* python.texi (Threads In Python): Document
    	InferiorThread.inferior.

Diff:
---
 gdb/ChangeLog                             |  6 ++++++
 gdb/NEWS                                  |  5 +++++
 gdb/doc/ChangeLog                         |  5 +++++
 gdb/doc/python.texi                       |  5 +++++
 gdb/python/py-infthread.c                 | 14 ++++++++++++++
 gdb/testsuite/ChangeLog                   |  4 ++++
 gdb/testsuite/gdb.python/py-infthread.exp |  3 +++
 7 files changed, 42 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1e6f922..47b5ffb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2016-01-13  Pedro Alves  <palves@redhat.com>
 
+	* NEWS: Mention InferiorThread.inferior.
+	* python/py-infthread.c (thpy_get_inferior): New.
+	(thread_object_getset): Register "inferior".
+
+2016-01-13  Pedro Alves  <palves@redhat.com>
+
 	* NEWS: Mention $_inferior.
 	* inferior.c (inferior_id_make_value): New.
 	(inferior_funcs): New.
diff --git a/gdb/NEWS b/gdb/NEWS
index c22ac54..ed38754 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -175,6 +175,11 @@ show remote catch-syscall-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/ChangeLog b/gdb/doc/ChangeLog
index b51e8df..be16225 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,10 @@
 2016-01-13  Pedro Alves  <palves@redhat.com>
 
+	* python.texi (Threads In Python): Document
+	InferiorThread.inferior.
+
+2016-01-13  Pedro Alves  <palves@redhat.com>
+
 	* gdb.texinfo (Inferiors and Programs): Document the $_inferior
 	convenience variable.
 	(Convenience Vars): Likewise.
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/ChangeLog b/gdb/testsuite/ChangeLog
index 5d773ca..ec2a067 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,9 @@
 2016-01-13  Pedro Alves  <palves@redhat.com>
 
+	* gdb.python/py-infthread.exp: Test InferiorThread.inferior.
+
+2016-01-13  Pedro Alves  <palves@redhat.com>
+
 	* gdb.base/default.exp: Expect $_inferior as well.
 	* gdb.multi/base.exp: Test $_inferior.
 
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'" \


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]