From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14432 invoked by alias); 26 Apr 2011 07:36:47 -0000 Received: (qmail 14006 invoked by uid 22791); 26 Apr 2011 07:36:44 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RFC_ABUSE_POST,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-vx0-f169.google.com (HELO mail-vx0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Apr 2011 07:36:29 +0000 Received: by vxk20 with SMTP id 20so388542vxk.0 for ; Tue, 26 Apr 2011 00:36:28 -0700 (PDT) Received: by 10.52.74.99 with SMTP id s3mr675510vdv.108.1303803388474; Tue, 26 Apr 2011 00:36:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.61.6 with HTTP; Tue, 26 Apr 2011 00:36:08 -0700 (PDT) In-Reply-To: References: From: Kevin Pouget Date: Tue, 26 Apr 2011 07:36:00 -0000 Message-ID: Subject: Re: [Patch] PR Python/12692 Add gdb.selected_inferior() to Python interface. To: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-04/txt/msg00467.txt.bz2 thanks for your approval, here is the updated patch: 2011-04-21 =A0Kevin Pouget =A0 =A0 =A0 =A0 =A0PR Python/12692 Add gdb.selected_inferior() to Python interf= ace. =A0 =A0 =A0 =A0* gdb.texinfo (Inferiors In Python): Describe new =A0 =A0 =A0 =A0gdb.selected_inferior() function. 2011-04-21 =A0Kevin Pouget =A0 =A0 =A0 =A0PR Python/12692 Add gdb.selected_inferior() to Python interf= ace. =A0 =A0 =A0 =A0* python/py-inferior.c (GdbMethods): New Python method defin= ition. 2011-04-21 =A0Kevin Pouget =A0 =A0 =A0 =A0 =A0PR Python/12692 Add gdb.selected_inferior() to Python interf= ace. =A0 =A0 =A0 =A0* 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: =A0Return a tuple containing all inferior objects. =A0@end defun +@defun selected_inferior +Return an object representing the current inferior. +@end defun + =A0A @code{gdb.Inferior} object has the following attributes: =A0@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) =A0=A0 Py_RETURN_TRUE; =A0} +/* Implementation of gdb.selected_inferior() -> gdb.Inferior. +=A0=A0 Returns the current inferior object.=A0 */ + +PyObject * +gdbpy_selected_inferior (PyObject *self, PyObject *args) +{ +=A0 PyObject *inf_obj; + +=A0 inf_obj =3D inferior_to_inferior_object (current_inferior ()); +=A0 Py_INCREF (inf_obj); + +=A0 return inf_obj; +} =A0/* Clear the INFERIOR pointer in an Inferior object and clear the =A0=A0=A0 thread list.=A0 */ 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, =A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0 struct type *ty= pe); =A0PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2); =A0PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args); +PyObject *gdbpy_selected_inferior (PyObject *self, PyObject *args); =A0PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args); =A0PyObject *gdbpy_parameter (PyObject *self, PyObject *args); =A0PyObject *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." =A0=A0 { "selected_thread", gdbpy_selected_thread, METH_NOARGS, =A0=A0=A0=A0 "selected_thread () -> gdb.InferiorThread.\n\ =A0Return the selected thread object." }, +=A0 { "selected_inferior", gdbpy_selected_inferior, METH_NOARGS, +=A0=A0=A0 "selected_inferior () -> gdb.Inferior.\n\ +Return the selected inferior object." }, =A0=A0 { "inferiors", gdbpy_inferiors, METH_NOARGS, =A0=A0=A0=A0 "inferiors () -> (gdb.Inferior, ...).\n\ =A0Return 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 =3D', i0.pid" " =3D \[0-9\]+" "test Inferior.pid" =A0gdb_test "python print 'result =3D', i0.was_attached" " =3D False" "test Inferior.was_attached" =A0gdb_test "python print i0.threads ()" "\\(,\\)" "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 select= ed" +gdb_test "inferior 2" ".*" "Switch to second inferior" +gdb_test "py print gdb.selected_inferior().num" "2" "Second inferior selec= ted" +gdb_test "inferior 1" ".*" "Switch to first inferior" +gdb_test_no_output "remove-inferiors 2" "Remove second inferior" + =A0# Test memory read and write operations. =A0gdb_py_test_silent_cmd "python addr =3D gdb.selected_frame ().read_var (= 'str')" \ @@ -199,14 +207,14 @@ gdb_py_test_silent_cmd "python inf_list =3D gdb.inferiors()" "get initial list" 1 =A0gdb_test "python print len(inf_list)" "1" "Get inferior list length" =A0gdb_test "python print inf_list\[0\].is_valid()" "True" \ =A0=A0=A0=A0=A0=A0=A0=A0=A0 "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" =A0gdb_py_test_silent_cmd "python inf_list =3D gdb.inferiors()" "get new li= st" 1 =A0gdb_test "python print len(inf_list)" "2" "Get inferior list length" =A0gdb_test "python print inf_list\[0\].is_valid()" "True" \ =A0=A0=A0=A0=A0=A0=A0=A0=A0 "Check inferior validity" =A0gdb_test "python print inf_list\[1\].is_valid()" "True" \ =A0=A0=A0=A0=A0=A0=A0=A0=A0 "Check inferior validity" -gdb_test_no_output "remove-inferiors 2" "remove-inferiors 2" +gdb_test_no_output "remove-inferiors 3" "remove-inferiors 3" =A0gdb_test "python print inf_list\[0\].is_valid()" "False" \ =A0=A0=A0=A0=A0=A0=A0=A0=A0 "Check inferior validity" =A0gdb_test "python print inf_list\[1\].is_valid()" "True" \ -- On Mon, Apr 25, 2011 at 3:15 PM, Tom Tromey wrote: > > >>>>> "Kevin" =3D=3D Kevin Pouget writes: > > Kevin> I would like to introduce a new Python function, > Kevin> `gdb.selected_inferior()', which returns the Python obj correspond= ing > 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> + =A0inf_obj =3D inferior_to_inferior_object (current_inferior()); > > Space before open paren. > > This is ok with this changed, pending doc review. > > Tom