2011-09-15 Kevin Pouget <kevin.pouget@st.com>
authorKevin Pouget <kpouget@sourceware.org>
Thu, 15 Sep 2011 12:42:30 +0000 (12:42 +0000)
committerKevin Pouget <kpouget@sourceware.org>
Thu, 15 Sep 2011 12:42:30 +0000 (12:42 +0000)
PR Python/12692 Add gdb.selected_inferior() to Python interface.
* python/py-inferior.c (GdbMethods): New Python method definition.

doc:
PR Python/12692 Add gdb.selected_inferior() to Python interface.
* gdb.texinfo (Inferiors In Python): Describe new
gdb.selected_inferior() function.

testsuite:
PR Python/12692 Add gdb.selected_inferior() to Python interface.
* gdb.python/py-inferior.exp: Add testcase for gdb.selected_inferior().

gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/python/py-inferior.c
gdb/python/python-internal.h
gdb/python/python.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-inferior.exp

index 380f75f..c9db20e 100644 (file)
@@ -1,3 +1,8 @@
+2011-09-15  Kevin Pouget <kevin.pouget@st.com>
+
+       PR Python/12692 Add gdb.selected_inferior() to Python interface.
+       * python/py-inferior.c (GdbMethods): New Python method definition.
+
 2011-09-15  Kevin Pouget  <kevin.pouget@st.com>
 
        Handle multiple breakpoint hits in Python interface:
index 54dd4e8..488ba75 100644 (file)
@@ -1,5 +1,11 @@
 2011-09-15  Kevin Pouget  <kevin.pouget@st.com>
 
+       PR Python/12692 Add gdb.selected_inferior() to Python interface.
+       * gdb.texinfo (Inferiors In Python): Describe new
+       gdb.selected_inferior() function.
+
+2011-09-15  Kevin Pouget  <kevin.pouget@st.com>
+
        Handle multiple breakpoint hits in Python interface:
        * gdb.texinfo (Events In Python): New function documentation:
        gdb.BreakpointEvent.breakpoints. Indicate that
index 76c804b..2fecb6a 100644 (file)
@@ -22146,6 +22146,10 @@ module:
 Return a tuple containing all inferior objects.
 @end defun
 
+@defun selected_inferior
+Return an object representing the current inferior.
+@end defun
+
 A @code{gdb.Inferior} object has the following attributes:
 
 @table @code
index 6add681..8ed3ea5 100644 (file)
@@ -683,6 +683,20 @@ py_free_inferior (struct inferior *inf, void *datum)
   do_cleanups (cleanup);
 }
 
+/* Implementation of gdb.selected_inferior() -> gdb.Inferior.
+   Returns the current inferior object.  */
+
+PyObject *
+gdbpy_selected_inferior (PyObject *self, PyObject *args)
+{
+  PyObject *inf_obj;
+
+  inf_obj = inferior_to_inferior_object (current_inferior ());
+  Py_INCREF (inf_obj);
+
+  return inf_obj;
+}
+
 void
 gdbpy_initialize_inferior (void)
 {
index 4209c28..11f1efd 100644 (file)
@@ -151,6 +151,7 @@ PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
                                           struct type *type);
 PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
 PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
+PyObject *gdbpy_selected_inferior (PyObject *self, PyObject *args);
 PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args);
 PyObject *gdbpy_parameter (PyObject *self, PyObject *args);
 PyObject *gdbpy_parameter_value (enum var_types type, void *var);
index 0f702a2..67649c3 100644 (file)
@@ -1423,6 +1423,9 @@ Arguments are separate by spaces and may be quoted."
   { "selected_thread", gdbpy_selected_thread, METH_NOARGS,
     "selected_thread () -> gdb.InferiorThread.\n\
 Return the selected thread object." },
+  { "selected_inferior", gdbpy_selected_inferior, METH_NOARGS,
+    "selected_inferior () -> gdb.Inferior.\n\
+Return the selected inferior object." },
   { "inferiors", gdbpy_inferiors, METH_NOARGS,
     "inferiors () -> (gdb.Inferior, ...).\n\
 Return a tuple containing all inferiors." },
index c33f55b..1ff1358 100644 (file)
@@ -1,3 +1,8 @@
+2011-09-15  Kevin Pouget  <kevin.pouget@st.com>
+
+       PR Python/12692 Add gdb.selected_inferior() to Python interface.
+       * gdb.python/py-inferior.exp: Add testcase for gdb.selected_inferior().
+
 2011-04-30  Kevin Pouget  <kevin.pouget@st.com>
 
        Handle multiple breakpoint hits in Python interface:
index b853c79..f8e0c4e 100644 (file)
@@ -206,8 +206,18 @@ gdb_test "python print inf_list\[0\].is_valid()" "True" \
          "Check inferior validity"
 gdb_test "python print inf_list\[1\].is_valid()" "True" \
          "Check inferior validity"
-gdb_test_no_output "remove-inferiors 2" "remove-inferiors 2"
+gdb_test_no_output "remove-inferiors 2" "remove-inferiors 3"
 gdb_test "python print inf_list\[0\].is_valid()" "False" \
          "Check inferior validity"
 gdb_test "python print inf_list\[1\].is_valid()" "True" \
          "Check inferior validity"
+
+# Test gdb.selected_inferior()
+gdb_test "inferior 1" ".*" "Switch to first inferior"
+gdb_test "py print gdb.selected_inferior().num" "1" "First inferior selected"
+
+gdb_test "add-inferior" "Added inferior 3" "Create new inferior"
+gdb_test "inferior 3" ".*" "Switch to third inferior"
+gdb_test "py print gdb.selected_inferior().num" "3" "Third inferior selected"
+gdb_test "inferior 1" ".*" "Switch to first inferior"
+gdb_test_no_output "remove-inferiors 3" "Remove second inferior"
\ No newline at end of file