From patchwork Thu Sep 13 02:36:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 29354 Received: (qmail 33218 invoked by alias); 13 Sep 2018 02:36:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 33205 invoked by uid 89); 13 Sep 2018 02:36:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.2 spammy=stolen X-HELO: sessmg23.ericsson.net Received: from sessmg23.ericsson.net (HELO sessmg23.ericsson.net) (193.180.251.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Sep 2018 02:36:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1536806211; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=uzdMpuIuLb913WhN+pc2Nh62QCK6WcRKYv27hQe3AF0=; b=L4aOsUzQR+HVXC7SWCj8pbDVhDGPB7cnCKbbYf858lMIG11R9n/+jHx1VvQMSh9s hMOPC7F52/YPw9pjqtRmjpDoL4wQKWZnfx1xmWh3FTfF6dN19Nb+3UWCy3+FWOXq pttEvN/rLYq5Ywbpxg5BxKXRjZ/yox6X6d+tCtEMApE=; Received: from ESESBMB504.ericsson.se (Unknown_Domain [153.88.183.117]) by sessmg23.ericsson.net (Symantec Mail Security) with SMTP id 7F.2E.22015.34DC99B5; Thu, 13 Sep 2018 04:36:51 +0200 (CEST) Received: from ESESSMB502.ericsson.se (153.88.183.163) by ESESBMB504.ericsson.se (153.88.183.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Thu, 13 Sep 2018 04:36:50 +0200 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (153.88.183.157) by ESESSMB502.ericsson.se (153.88.183.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Thu, 13 Sep 2018 04:36:50 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fpmQ1H+08vIpY5DeaDQ+Zgomb+CWL8oe/79HBt8RNeQ=; b=lRvDWnIU+17GEt88yqJVfKO84ymx72Vkfyn74SaoOBWOIedjyrLOOVkR6okPWbozaNt5VI9qxzaDUpR7v7ghH8bf13tmzzRykMMtOMH2S1tGMkRYHzwErDa1QriqBQAPrBvbLw7O62DQwIkNgOBCZxCtq+U8OTROLPcwRL7p/bM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from elxacz23q12.ericsson.se (192.176.1.81) by BN7PR15MB2385.namprd15.prod.outlook.com (2603:10b6:406:8c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.17; Thu, 13 Sep 2018 02:36:46 +0000 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH v2 1/3] python: Add Inferior.progspace property Date: Wed, 12 Sep 2018 22:36:25 -0400 Message-Id: <20180913023627.18855-1-simon.marchi@ericsson.com> MIME-Version: 1.0 Return-Path: simon.marchi@ericsson.com Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-IsSubscribed: yes New in v2: the bit in the gdb.current_progspace doc, stolen from Tom Tromey's 2014 patch. 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. While modifying py-inferior.exp, I added some checks for the other Inferior properties, when the Inferior is no longer valid. This doesn't seem tested at the moment. 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/NEWS | 5 +++++ gdb/doc/python.texi | 8 +++++++- gdb/python/py-inferior.c | 18 ++++++++++++++++++ gdb/testsuite/gdb.python/py-inferior.exp | 5 +++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/gdb/NEWS b/gdb/NEWS index 4e4f12d8d13..73d95f2a559 100644 --- 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 diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 1c70088acea..ca3e651098f 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -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 diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 56019bf9e05..727a8d2f306 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -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 } }; diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 077279f2f54..04d98cea06b 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -54,6 +54,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 ())" "\\(,\\)" "test Inferior.threads" +gdb_test "python print (i0.progspace)" "" +gdb_test "python print (i0.progspace == gdb.progspaces()\[0\])" "True" + # Test the number of inferior threads. gdb_breakpoint check_threads @@ -262,6 +265,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))" \