From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 96464 invoked by alias); 12 Sep 2018 19:37:16 -0000 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 Received: (qmail 96450 invoked by uid 89); 12 Sep 2018 19:37:15 -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=2536, *self, conjunction X-HELO: sesbmg22.ericsson.net Received: from sesbmg22.ericsson.net (HELO sesbmg22.ericsson.net) (193.180.251.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Sep 2018 19:37:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1536781031; 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=1fG9TBm66CI2o2JXO80VKvjDyC3LUz0J9WStOFyx4Mc=; b=R/1SARRxCxZ3ZDyjhgwAC8n7iMcpcgbMk0zqf7oPt+4j2Dy4lk06/Ng/Jy2MbAAt mYuHZH0+rv/C2RJIaDbCxRqhECmrE0W9SlorCWrIj/d2nL/chQG2ICWiMBWFu/3n SN0G2DGA8UTNcQJgo/i4d6Dr5lpRF5h6QyURtlbW/0g=; Received: from ESESSMB501.ericsson.se (Unknown_Domain [153.88.183.119]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id A7.8B.21978.7EA699B5; Wed, 12 Sep 2018 21:37:11 +0200 (CEST) Received: from ESESSMB505.ericsson.se (153.88.183.166) by ESESSMB501.ericsson.se (153.88.183.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Wed, 12 Sep 2018 21:36:42 +0200 Received: from NAM04-CO1-obe.outbound.protection.outlook.com (153.88.183.157) by ESESSMB505.ericsson.se (153.88.183.166) 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; Wed, 12 Sep 2018 21:36:42 +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=dKumntoHeF+HrRM6L2Sg5pACUjHVUZBPHkqSy1WZzXw=; b=bcSN32xdSe1COhfDRoMtP3Db3ONbXkuezZ8hip59qBep8tGK/xDaVOcfbVDkmDkNx6BP+MUe1iRRSvb8LYq1YhQlPHnmYFy4Enicii7I1lgWcJToiEhUfhf4TRShoCiHzXxSsvUa1cg1ZDlSb062hQM3xuzPyHpKsfENn5CuifE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from elxacz23q12.ericsson.se (192.176.1.81) by BYAPR15MB2389.namprd15.prod.outlook.com (2603:10b6:a02:8c::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.15; Wed, 12 Sep 2018 19:36:38 +0000 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 1/3] python: Add Inferior.progspace property Date: Wed, 12 Sep 2018 19:37:00 -0000 Message-Id: <20180912193617.16523-1-simon.marchi@ericsson.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Return-Path: simon.marchi@ericsson.com Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00371.txt.bz2 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. 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 | 4 ++++ gdb/python/py-inferior.c | 18 ++++++++++++++++++ gdb/testsuite/gdb.python/py-inferior.exp | 18 ++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 4e4f12d8d13..21da6ae4ba8 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 program space associated to an inferior is now accessible through a + new "progspace" attribute of gdb.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 5e2ab76d2bc..d4f03439f10 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -2832,6 +2832,10 @@ Boolean signaling whether the inferior was created using `attach', or started by @value{GDBN} itself. @end defvar +@defvar Inferior.progspace +Program space associated to this inferrior, as a @code{gdb.Progspace}. +@end defvar + A @code{gdb.Inferior} object has the following methods: @defun Inferior.is_valid () diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 8e6f148b17a..e770585184b 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) { @@ -963,6 +980,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 6f4a3146684..01307531412 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 @@ -253,6 +256,21 @@ with_test_prefix "is_valid" { gdb_test "python print (my_inferior_count)" "1" \ "test inferior-deleted event handler" + + # Test that other properties and methods handle the removed inferior + # correctly. + gdb_test "python print (inf_list\[1\].num)" \ + "RuntimeError: Inferior no longer exists.*" + gdb_test "python print (inf_list\[1\].pid)" \ + "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))" \ + "RuntimeError: Inferior no longer exists.*" } # Test gdb.selected_inferior() -- 2.19.0