From 78fee2ad3bd4ac98a38b472ba8f6e5648aa8493a Mon Sep 17 00:00:00 2001 From: Kevin Pouget Date: Wed, 31 Aug 2011 16:05:05 +0200 Subject: [PATCH] Python selected_inferior --- gdb/doc/gdb.texinfo | 4 ++++ gdb/python/py-inferior.c | 14 ++++++++++++++ gdb/python/python-internal.h | 1 + gdb/python/python.c | 3 +++ gdb/testsuite/gdb.python/py-inferior.exp | 12 +++++++++++- 5 files changed, 33 insertions(+), 1 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 23b2a98..09eb45c 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -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 diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 6add681..8ed3ea5 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -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) { diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 996b23b..99c3f6b 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -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); diff --git a/gdb/python/python.c b/gdb/python/python.c index 03edce9..52eeb07 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1415,6 +1415,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." }, diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index b853c79..f8e0c4e 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -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 -- 1.7.6