* [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
@ 2011-04-21 12:26 Kevin Pouget
2011-04-25 19:16 ` Tom Tromey
0 siblings, 1 reply; 8+ messages in thread
From: Kevin Pouget @ 2011-04-21 12:26 UTC (permalink / raw)
To: gdb-patches
Hello,
I would like to introduce a new Python function,
`gdb.selected_inferior()', which returns the Python obj corresponding
to current_inferior; let me know what you think about it.
I named the function `selected_inferior' according to the existing
`selected_thread'.
Cordially,
Kevin
--
2011-04-21 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-04-21 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-04-21 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().
---
gdb/doc/gdb.texinfo | 4 ++++
gdb/python/py-inferior.c | 13 +++++++++++++
gdb/python/python-internal.h | 1 +
gdb/python/python.c | 3 +++
gdb/testsuite/gdb.python/py-inferior.exp | 12 ++++++++++--
5 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c71d664..c2cd093 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -21916,6 +21916,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 b9df394..46858c6 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -620,6 +620,19 @@ infpy_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
+/* 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;
+}
/* Clear the INFERIOR pointer in an Inferior object and clear the
thread list. */
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index d3cb788..025add9 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -147,6 +147,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 8a7bc66..20a2d03 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1276,6 +1276,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 42ca920..518f2c1 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -66,6 +66,14 @@ gdb_test "python print 'result =', i0.pid" " =
\[0-9\]+" "test Inferior.pid"
gdb_test "python print 'result =', i0.was_attached" " = False" "test
Inferior.was_attached"
gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object
at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
+# Test gdb.selected_inferior()
+gdb_test "add-inferior" "Added inferior 2" "Create new inferior"
+gdb_test "py print gdb.selected_inferior().num" "1" "First inferior selected"
+gdb_test "inferior 2" ".*" "Switch to second inferior"
+gdb_test "py print gdb.selected_inferior().num" "2" "Second inferior selected"
+gdb_test "inferior 1" ".*" "Switch to first inferior"
+gdb_test_no_output "remove-inferiors 2" "Remove second inferior"
+
# Test memory read and write operations.
gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
@@ -199,14 +207,14 @@ gdb_py_test_silent_cmd "python inf_list =
gdb.inferiors()" "get initial list" 1
gdb_test "python print len(inf_list)" "1" "Get inferior list length"
gdb_test "python print inf_list\[0\].is_valid()" "True" \
"Check inferior validity"
-gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
+gdb_test "add-inferior" "Added inferior 3.*" "add empty inferior 3"
gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
gdb_test "python print len(inf_list)" "2" "Get inferior list length"
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 3" "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" \
--
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
2011-04-21 12:26 [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface Kevin Pouget
@ 2011-04-25 19:16 ` Tom Tromey
[not found] ` <BANLkTikmK+Khg7yJ0MLDpOxAt2xuwcZYDQ@mail.gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2011-04-25 19:16 UTC (permalink / raw)
To: Kevin Pouget; +Cc: gdb-patches
>>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:
Kevin> I would like to introduce a new Python function,
Kevin> `gdb.selected_inferior()', which returns the Python obj corresponding
Kevin> to current_inferior; let me know what you think about it.
Kevin> I named the function `selected_inferior' according to the existing
Kevin> `selected_thread'.
The code bits are generally ok; one nit.
Kevin> + inf_obj = inferior_to_inferior_object (current_inferior());
Space before open paren.
This is ok with this changed, pending doc review.
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
[not found] ` <BANLkTikmK+Khg7yJ0MLDpOxAt2xuwcZYDQ@mail.gmail.com>
@ 2011-04-26 7:36 ` Kevin Pouget
2011-05-30 7:45 ` Kevin Pouget
0 siblings, 1 reply; 8+ messages in thread
From: Kevin Pouget @ 2011-04-26 7:36 UTC (permalink / raw)
To: gdb-patches
thanks for your approval,
here is the updated patch:
2011-04-21 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-04-21 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-04-21 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().
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c71d664..c2cd093 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -21916,6 +21916,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 b9df394..09cee50 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -620,6 +620,19 @@ infpy_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
+/* 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;
+}
/* Clear the INFERIOR pointer in an Inferior object and clear the
thread list. */
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index d3cb788..025add9 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -147,6 +147,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 8a7bc66..20a2d03 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1276,6 +1276,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 42ca920..518f2c1 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -66,6 +66,14 @@ gdb_test "python print 'result =', i0.pid" " =
\[0-9\]+" "test Inferior.pid"
gdb_test "python print 'result =', i0.was_attached" " = False" "test
Inferior.was_attached"
gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object
at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
+# Test gdb.selected_inferior()
+gdb_test "add-inferior" "Added inferior 2" "Create new inferior"
+gdb_test "py print gdb.selected_inferior().num" "1" "First inferior selected"
+gdb_test "inferior 2" ".*" "Switch to second inferior"
+gdb_test "py print gdb.selected_inferior().num" "2" "Second inferior selected"
+gdb_test "inferior 1" ".*" "Switch to first inferior"
+gdb_test_no_output "remove-inferiors 2" "Remove second inferior"
+
# Test memory read and write operations.
gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
@@ -199,14 +207,14 @@ gdb_py_test_silent_cmd "python inf_list =
gdb.inferiors()" "get initial list" 1
gdb_test "python print len(inf_list)" "1" "Get inferior list length"
gdb_test "python print inf_list\[0\].is_valid()" "True" \
"Check inferior validity"
-gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
+gdb_test "add-inferior" "Added inferior 3.*" "add empty inferior 3"
gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
gdb_test "python print len(inf_list)" "2" "Get inferior list length"
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 3" "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" \
--
On Mon, Apr 25, 2011 at 3:15 PM, Tom Tromey <tromey@redhat.com> wrote:
>
> >>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:
>
> Kevin> I would like to introduce a new Python function,
> Kevin> `gdb.selected_inferior()', which returns the Python obj corresponding
> Kevin> to current_inferior; let me know what you think about it.
> Kevin> I named the function `selected_inferior' according to the existing
> Kevin> `selected_thread'.
>
> The code bits are generally ok; one nit.
>
> Kevin> + inf_obj = inferior_to_inferior_object (current_inferior());
>
> Space before open paren.
>
> This is ok with this changed, pending doc review.
>
> Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
2011-04-26 7:36 ` Kevin Pouget
@ 2011-05-30 7:45 ` Kevin Pouget
2011-05-30 7:50 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Kevin Pouget @ 2011-05-30 7:45 UTC (permalink / raw)
To: gdb-patches
Hello,
I just wanted to ping this patch, which has been approved by Tom but
has a pending doc review
cordially,
Kevin
--
2011-05-30 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-05-30 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-05-30 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().
--
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c71d664..c2cd093 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -21916,6 +21916,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 b9df394..09cee50 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -620,6 +620,19 @@ infpy_is_valid (PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
+/* 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;
+}
/* Clear the INFERIOR pointer in an Inferior object and clear the
thread list. */
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index d3cb788..025add9 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -147,6 +147,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 8a7bc66..20a2d03 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1276,6 +1276,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 42ca920..518f2c1 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -66,6 +66,14 @@ gdb_test "python print 'result =', i0.pid" " =
\[0-9\]+" "test Inferior.pid"
gdb_test "python print 'result =', i0.was_attached" " = False" "test
Inferior.was_attached"
gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object
at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
+# Test gdb.selected_inferior()
+gdb_test "add-inferior" "Added inferior 2" "Create new inferior"
+gdb_test "py print gdb.selected_inferior().num" "1" "First inferior selected"
+gdb_test "inferior 2" ".*" "Switch to second inferior"
+gdb_test "py print gdb.selected_inferior().num" "2" "Second inferior selected"
+gdb_test "inferior 1" ".*" "Switch to first inferior"
+gdb_test_no_output "remove-inferiors 2" "Remove second inferior"
+
# Test memory read and write operations.
gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
@@ -199,14 +207,14 @@ gdb_py_test_silent_cmd "python inf_list =
gdb.inferiors()" "get initial list" 1
gdb_test "python print len(inf_list)" "1" "Get inferior list length"
gdb_test "python print inf_list\[0\].is_valid()" "True" \
"Check inferior validity"
-gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
+gdb_test "add-inferior" "Added inferior 3.*" "add empty inferior 3"
gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
gdb_test "python print len(inf_list)" "2" "Get inferior list length"
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 3" "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" \
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
2011-05-30 7:45 ` Kevin Pouget
@ 2011-05-30 7:50 ` Eli Zaretskii
2011-08-31 14:14 ` Kevin Pouget
0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2011-05-30 7:50 UTC (permalink / raw)
To: Kevin Pouget; +Cc: gdb-patches
> From: Kevin Pouget <kevin.pouget@gmail.com>
> Date: Mon, 30 May 2011 03:44:28 -0400
>
> has a pending doc review
Sorry. The patch for the manual is okay.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
2011-05-30 7:50 ` Eli Zaretskii
@ 2011-08-31 14:14 ` Kevin Pouget
2011-08-31 15:34 ` Tom Tromey
2011-09-19 10:16 ` Kevin Pouget
0 siblings, 2 replies; 8+ messages in thread
From: Kevin Pouget @ 2011-08-31 14:14 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1460 bytes --]
> ---------- Forwarded message ----------
> From: Tom Tromey <tromey@redhat.com>
> Date: Mon, Apr 25, 2011 at 9:15 PM
> Subject: Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
>
> This is ok with this changed, pending doc review.
>
> Tom
>
> ---------- Forwarded message ----------
> From: Eli Zaretskii <eliz@gnu.org>
> Date: Mon, May 30, 2011 at 9:50 AM
> Subject: Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
> To: Kevin Pouget <kevin.pouget@gmail.com>
> Cc: gdb-patches@sourceware.org
>
>
> > From: Kevin Pouget <kevin.pouget@gmail.com>
> > Date: Mon, 30 May 2011 03:44:28 -0400
> >
> > has a pending doc review
>
> Sorry. The patch for the manual is okay.
Hello,
I regenerated this patch against the up-to-date tree, which was
previously accepted
Cordially,
Kevin
2011-08-31 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-08-31 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-08-31 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().
[-- Attachment #2: 0001-Python-selected_inferior.patch --]
[-- Type: text/x-patch, Size: 4186 bytes --]
From 78fee2ad3bd4ac98a38b472ba8f6e5648aa8493a Mon Sep 17 00:00:00 2001
From: Kevin Pouget <kevin.pouget@st.com>
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
2011-08-31 14:14 ` Kevin Pouget
@ 2011-08-31 15:34 ` Tom Tromey
2011-09-19 10:16 ` Kevin Pouget
1 sibling, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2011-08-31 15:34 UTC (permalink / raw)
To: Kevin Pouget; +Cc: Eli Zaretskii, gdb-patches
>>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:
Kevin> I regenerated this patch against the up-to-date tree, which was
Kevin> previously accepted
It is still ok.
I will contact you off-list about setting up a write-after-approval
account.
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
2011-08-31 14:14 ` Kevin Pouget
2011-08-31 15:34 ` Tom Tromey
@ 2011-09-19 10:16 ` Kevin Pouget
1 sibling, 0 replies; 8+ messages in thread
From: Kevin Pouget @ 2011-09-19 10:16 UTC (permalink / raw)
To: gdb-patches
On Wed, Aug 31, 2011 at 4:13 PM, Kevin Pouget <kevin.pouget@gmail.com> wrote:
>
> > ---------- Forwarded message ----------
> > From: Tom Tromey <tromey@redhat.com>
> > Date: Mon, Apr 25, 2011 at 9:15 PM
> > Subject: Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
> >
> > This is ok with this changed, pending doc review.
> >
> > Tom
> >
> > ---------- Forwarded message ----------
> > From: Eli Zaretskii <eliz@gnu.org>
> > Date: Mon, May 30, 2011 at 9:50 AM
> > Subject: Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface.
> > To: Kevin Pouget <kevin.pouget@gmail.com>
> > Cc: gdb-patches@sourceware.org
> >
> >
> > > From: Kevin Pouget <kevin.pouget@gmail.com>
> > > Date: Mon, 30 May 2011 03:44:28 -0400
> > >
> > > has a pending doc review
> >
> > Sorry. The patch for the manual is okay.
>
> Hello,
>
> I regenerated this patch against the up-to-date tree, which was
> previously accepted
>
>
> Cordially,
>
> Kevin
>
> 2011-08-31 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-08-31 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-08-31 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().
Commited on 15 Sep 2011:
http://sourceware.org/ml/gdb-cvs/2011-09/msg00086.html
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-09-19 8:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-21 12:26 [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface Kevin Pouget
2011-04-25 19:16 ` Tom Tromey
[not found] ` <BANLkTikmK+Khg7yJ0MLDpOxAt2xuwcZYDQ@mail.gmail.com>
2011-04-26 7:36 ` Kevin Pouget
2011-05-30 7:45 ` Kevin Pouget
2011-05-30 7:50 ` Eli Zaretskii
2011-08-31 14:14 ` Kevin Pouget
2011-08-31 15:34 ` Tom Tromey
2011-09-19 10:16 ` Kevin Pouget
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox