python: Add Inferior.progspace property
authorSimon Marchi <simon.marchi@ericsson.com>
Thu, 13 Sep 2018 19:39:26 +0000 (15:39 -0400)
committerSimon Marchi <simon.marchi@ericsson.com>
Thu, 13 Sep 2018 19:42:12 +0000 (15:42 -0400)
This patch adds a progspace property to the gdb.Inferior type, which
allows getting the gdb.Progspace object associated to that inferior.
In conjunction with the following patch, this will allow scripts iterate
on objfiles associated with a particular inferior.

gdb/ChangeLog:

* python/py-inferior.c (infpy_get_progspace): New function.
(inferior_object_getset): Add progspace property.
* NEWS: Mention the new property.

gdb/doc/ChangeLog:

* python.texi (Inferiors In Python): Document
Inferior.progspace.
(Program Spaces In Python): Document that
gdb.current_progspace() is the same as
gdb.selected_inferior().progspace.

gdb/testsuite/ChangeLog:

* gdb.python/py-inferior.exp: Add tests for Inferior.progspace
and a few other Inferior properties when the Inferior is no
longer valid.

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/python.texi
gdb/python/py-inferior.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-inferior.exp

index 5783e7cb0a346c3e0d108d7551945adac9e10259..8ec110cef3d92ab98672b71a090e16239fdf12a5 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-13  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * python/py-inferior.c (infpy_get_progspace): New function.
+       (inferior_object_getset): Add progspace property.
+       * NEWS: Mention the new property.
+
 2018-09-13  Tom Tromey  <tom@tromey.com>
 
        PR rust/23650:
index 4e4f12d8d13671b5fc7cf8c1bd302023d7e402f3..4e26f4bb977b66135c1cf723fa15da51b64d5d27 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -84,6 +84,11 @@ GNU/Linux/RISC-V             riscv*-*-linux*
 CSKY ELF                       csky*-*-elf
 CSKY GNU/LINUX                 csky*-*-linux
 
+* Python API
+
+  ** The gdb.Inferior type has a new 'progspace' property, which is the program
+     space associated to that inferior.
+
 *** Changes in GDB 8.2
 
 * The 'set disassembler-options' command now supports specifying options
index 1c965087af65d8dec04067625fb6b9c173ef9ad5..4750c340b5c9ca3be288ce35a28de627d22a41fb 100644 (file)
@@ -1,3 +1,12 @@
+2018-09-13  Simon Marchi  <simon.marchi@ericsson.com>
+2018-09-13  Tom Tromey  <tom@tromey.com>
+
+       * python.texi (Inferiors In Python): Document
+       Inferior.progspace.
+       (Program Spaces In Python): Document that
+       gdb.current_progspace() is the same as
+       gdb.selected_inferior().progspace.
+
 2018-09-13  Simon Marchi  <simon.marchi@ericsson.com>
 
        * python.texi (Basic Python): Mention the string representation
index 6e2bf5c9effaa6735748a3c752d8c6fee8d7fb7d..75d8ae1e39994e99922097a5b167c4dce0849332 100644 (file)
@@ -2836,6 +2836,10 @@ Boolean signaling whether the inferior was created using `attach', or
 started by @value{GDBN} itself.
 @end defvar
 
+@defvar Inferior.progspace
+The inferior's program space.  @xref{Progspaces In Python}.
+@end defvar
+
 A @code{gdb.Inferior} object has the following methods:
 
 @defun Inferior.is_valid ()
@@ -3995,7 +3999,9 @@ The following progspace-related functions are available in the
 @findex gdb.current_progspace
 @defun gdb.current_progspace ()
 This function returns the program space of the currently selected inferior.
-@xref{Inferiors and Programs}.
+@xref{Inferiors and Programs}.  This is identical to
+@code{gdb.selected_inferior().progspace} (@pxref{Inferiors In Python}) and is
+included for historical compatibility.
 @end defun
 
 @findex gdb.progspaces
index 56019bf9e05902768662c72027ed2937145e8025..727a8d2f3063298dfc938919f3ee4f55fd72713c 100644 (file)
@@ -459,6 +459,23 @@ infpy_get_was_attached (PyObject *self, void *closure)
   Py_RETURN_FALSE;
 }
 
+/* Getter of gdb.Inferior.progspace.  */
+
+static PyObject *
+infpy_get_progspace (PyObject *self, void *closure)
+{
+  inferior_object *inf = (inferior_object *) self;
+
+  INFPY_REQUIRE_VALID (inf);
+
+  program_space *pspace = inf->inferior->pspace;
+  gdb_assert (pspace != nullptr);
+
+  PyObject *py_pspace = pspace_to_pspace_object (pspace);
+  Py_XINCREF (py_pspace);
+  return py_pspace;
+}
+
 static int
 build_inferior_list (struct inferior *inf, void *arg)
 {
@@ -966,6 +983,7 @@ static gdb_PyGetSetDef inferior_object_getset[] =
     NULL },
   { "was_attached", infpy_get_was_attached, NULL,
     "True if the inferior was created using 'attach'.", NULL },
+  { "progspace", infpy_get_progspace, NULL, "Program space of this inferior" },
   { NULL }
 };
 
index 7d6a2ecbf07d13d4d3d3a78e9070260fee2d584d..553eaab15ba245d333dbf6b29a1e691ed86ae3a1 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-13  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * gdb.python/py-inferior.exp: Add tests for Inferior.progspace
+       and a few other Inferior properties when the Inferior is no
+       longer valid.
+
 2018-09-13  Tom Tromey  <tom@tromey.com>
 
        PR rust/23650:
index 7ec81930ff0cdb40fca637565163300f80c0973b..38f52573b190fb4bdddb99fa525c8760c5565b2a 100644 (file)
@@ -55,6 +55,9 @@ gdb_test "python print ('result = %s' % i0.pid)" " = \[0-9\]+" "test Inferior.pi
 gdb_test "python print ('result = %s' % i0.was_attached)" " = False" "test Inferior.was_attached"
 gdb_test "python print (i0.threads ())" "\\(<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
 
+gdb_test "python print (i0.progspace)" "<gdb.Progspace object at $hex>"
+gdb_test "python print (i0.progspace == gdb.progspaces()\[0\])" "True"
+
 # Test the number of inferior threads.
 
 gdb_breakpoint check_threads
@@ -263,6 +266,8 @@ with_test_prefix "is_valid" {
        "RuntimeError: Inferior no longer exists.*"
     gdb_test "python print (inf_list\[1\].was_attached)" \
        "RuntimeError: Inferior no longer exists.*"
+    gdb_test "python print (inf_list\[1\].progspace)" \
+       "RuntimeError: Inferior no longer exists.*"
     gdb_test "python print (inf_list\[1\].threads ())" \
        "RuntimeError: Inferior no longer exists.*"
     gdb_test "python print (inf_list\[1\].thread_from_thread_handle (1))" \
This page took 0.043922 seconds and 4 git commands to generate.