From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id B4EB23833012 for ; Tue, 27 Apr 2021 09:10:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B4EB23833012 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x42c.google.com with SMTP id a4so58681203wrr.2 for ; Tue, 27 Apr 2021 02:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=UlzDflyRyt1HYBy1xkhAI9OfjVaR+jw69NxVKZrv+wY=; b=KvNF1/K17VJUz/pDXFdNDwVlrEDy7bAQFYJug8qxi9V2C2h6VtRJGRjyetRK5LuG4i /sdefFKiwnrMtK3fpaEStse0DOQbVVtdouJjSd4E0pHJAw1F1P5n++OFEAVabOYx3ohA KjNFScP2sIce1x5HSyuh/JzyNYavhV/3QDLsr7SLfz0txdhY+iwSL7mD8WnInPgXO4hj LrAt8E8HJVmXVRYNUVa6bcpMPQhICIfSjWtGee3pjGP5EuFXENenlMossvWWZgGNcNoB 4U2GJdaO5KmP87GU8pY6hUGvmdlXqY0ph6tdc722LgiKYPQhKlV7eN/Rk0Uqd7Tpv0qe 2uBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UlzDflyRyt1HYBy1xkhAI9OfjVaR+jw69NxVKZrv+wY=; b=EBdhyyFJICegBWeokagIzQXhxDSWTrp6uXR0uLuH1fk59qAavLO0s+WUOAKPmiQA2Z 9GiLSYSl0rENInCny036FFJvUI7Jz1nKAA46zHj9hc9EovbSMhhIZ5yvdqGoUvsLgPnG dCkeb2bHg9GhOExbSf0kzWXtwFOQ72cNjhsIn1egzCblQQJbBZQCRbY302Uocg7aN7D/ 5Xi521wIipw0a5S8WngvYpS32Sfwu0OqYE9xqTzZ5BTdByA1x3yZRYA8Lrxgss0gXRiq u0vk2mUKdU7JOgzwO9TnkXenPMaF/M7f5tNvuY1Gw+USVmwhM5uKE/UuGSR7N5Z0w0jX Y2cg== X-Gm-Message-State: AOAM531sjqBO4M5BiokjfQvskbZ9DgOQ+6i4FdySkZmwS3rVz3iJzEWW sTgo1lzpkpuyyvLSfqol1bfa1mpebjG0yA== X-Google-Smtp-Source: ABdhPJxvngLRnUVF7tmcW9Qsp17vd+W4WSBWb6d2P4ljbQKEx+DzJXUb3MffmconjyOuD1DslnQBrw== X-Received: by 2002:a5d:564b:: with SMTP id j11mr28723119wrw.307.1619514611818; Tue, 27 Apr 2021 02:10:11 -0700 (PDT) Received: from localhost (host109-151-46-70.range109-151.btcentralplus.com. [109.151.46.70]) by smtp.gmail.com with ESMTPSA id f8sm19945362wmc.8.2021.04.27.02.10.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 02:10:11 -0700 (PDT) Date: Tue, 27 Apr 2021 10:10:10 +0100 From: Andrew Burgess To: Tankut Baris Aktemur Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2] gdb/python: add a 'connection_num' attribute to Inferior objects Message-ID: <20210427091010.GZ2610@embecosm.com> References: <1618239868-11211-1-git-send-email-tankut.baris.aktemur@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1618239868-11211-1-git-send-email-tankut.baris.aktemur@intel.com> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 10:02:47 up 16 days, 19:49, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Apr 2021 09:10:15 -0000 * Tankut Baris Aktemur via Gdb-patches [2021-04-12 17:04:28 +0200]: > Define a 'connection_num' attribute for Inferior objects. The > read-only attribute is the ID of the process stratum target of an > inferior, as printed by "info inferiors". > > gdb/ChangeLog: > 2021-04-12 Tankut Baris Aktemur > > * python/py-inferior.c (infpy_get_connection_num): New function. > (inferior_object_getset): Add a new element for 'connection_num'. > * NEWS: Mention the 'connection_num' attribute of Inferior objects. > > gdb/doc/ChangeLog: > 2021-04-12 Tankut Baris Aktemur > > * python.texi (Inferiors In Python): Mention the 'connection_num' > attribute. > > gdb/testsuite/ChangeLog: > 2021-04-12 Tankut Baris Aktemur > > * gdb.python/py-inferior.exp: Add test cases for > * 'connection_num'. Thanks for looking at this, I had a couple of minor comments. > --- > gdb/NEWS | 5 +++++ > gdb/doc/python.texi | 5 +++++ > gdb/python/py-inferior.c | 16 +++++++++++++++ > gdb/testsuite/gdb.python/py-inferior.exp | 25 +++++++++++++++++++++++- > 4 files changed, 50 insertions(+), 1 deletion(-) > > diff --git a/gdb/NEWS b/gdb/NEWS > index 6cf76a14317..bdc0e2c6593 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -138,6 +138,11 @@ QMemTags > Request the remote to store the specified allocation tags to the requested > memory range. > > +* Python API > + > + ** Inferior objects now contain a read-only 'connection_num' attribute that > + gives the ID of the Inferior's process stratum target. I don't think you should mention "process stratum" here. The NEWS file is for users to read, and "stratum" is not mentioned anywhere in the GDB manual (or in this NEWS file). How about: ** Inferior objects now contain a read-only 'connection_num' attribute that gives the connection number as seen in 'info connections' and 'info inferiors'. > + > *** Changes in GDB 10 > > * There are new feature names for ARC targets: "org.gnu.gdb.arc.core" > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 9135d415dd1..b459ff245d4 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -2989,6 +2989,11 @@ A @code{gdb.Inferior} object has the following attributes: > ID of inferior, as assigned by GDB. > @end defvar > > +@defvar Inferior.connection_num > +ID of inferior's connection (i.e.@: process target), as assigned by > +@value{GDBN}. > +@end defvar > + > @defvar Inferior.pid > Process ID of the inferior, as assigned by the underlying operating > system. > diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c > index a3d5952a10b..a7fac34f3d6 100644 > --- a/gdb/python/py-inferior.c > +++ b/gdb/python/py-inferior.c > @@ -426,6 +426,20 @@ infpy_get_num (PyObject *self, void *closure) > return gdb_py_object_from_longest (inf->inferior->num).release (); > } > > +static PyObject * > +infpy_get_connection_num (PyObject *self, void *closure) This function should have a header comment. Otherwise, this looks good. Thanks, Andrew > +{ > + inferior_object *inf = (inferior_object *) self; > + > + INFPY_REQUIRE_VALID (inf); > + > + process_stratum_target *target = inf->inferior->process_target (); > + if (target == nullptr) > + Py_RETURN_NONE; > + > + return PyLong_FromLong (target->connection_number); > +} > + > static PyObject * > infpy_get_pid (PyObject *self, void *closure) > { > @@ -928,6 +942,8 @@ gdbpy_initialize_inferior (void) > static gdb_PyGetSetDef inferior_object_getset[] = > { > { "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL }, > + { "connection_num", infpy_get_connection_num, NULL, > + "ID of inferior's connection, as assigned by GDB.", NULL }, > { "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.", > NULL }, > { "was_attached", infpy_get_was_attached, NULL, > diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp > index 9df74e05182..2252215b721 100644 > --- a/gdb/testsuite/gdb.python/py-inferior.exp > +++ b/gdb/testsuite/gdb.python/py-inferior.exp > @@ -51,6 +51,7 @@ gdb_py_test_silent_cmd "python i0 = inferiors\[0\]" "get first inferior" 0 > > gdb_test "python print ('result = %s' % (i0 == inferiors\[0\]))" " = True" "test equality comparison (true)" > gdb_test "python print ('result = %s' % i0.num)" " = \[0-9\]+" "test Inferior.num" > +gdb_test "python print ('result = %s' % i0.connection_num)" " = \[0-9\]+" "test Inferior.connection_num" > gdb_test "python print ('result = %s' % i0.pid)" " = \[0-9\]+" "test Inferior.pid" > gdb_test "python print ('result = %s' % i0.was_attached)" " = False" "test Inferior.was_attached" > gdb_test "python print (i0.threads ())" "\\(,\\)" "test Inferior.threads" > @@ -262,6 +263,8 @@ with_test_prefix "is_valid" { > # correctly. > gdb_test "python print (inf_list\[1\].num)" \ > "RuntimeError: Inferior no longer exists.*" > + gdb_test "python print (inf_list\[1\].connection_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)" \ > @@ -278,10 +281,30 @@ with_test_prefix "is_valid" { > with_test_prefix "selected_inferior" { > gdb_test "inferior 1" ".*" "switch to first inferior" > gdb_test "py print (gdb.selected_inferior().num)" "1" "first inferior selected" > + gdb_test "py print (gdb.selected_inferior().connection_num)" "1" \ > + "first inferior's connection" > + # Figure out if inf 1 has a native target. > + set inf_1_is_native [gdb_is_target_native] > > - gdb_test "add-inferior" "Added inferior 3 on connection .*" "create new inferior" > + gdb_test "add-inferior -no-connection" "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 "py print (gdb.selected_inferior().connection_num)" "None" \ > + "third inferior's None connection" > + gdb_test "target native" "Done. Use the \"run\" command to start a process." \ > + "target for the third inferior" > + > + # If inf 1 has a native target, inf 3's target is shared with 1's. > + # Otherwise, it must have created a new target with a new number. > + if {$inf_1_is_native} { > + set expected_connection_num 1 > + } else { > + set expected_connection_num 2 > + } > + gdb_test "py print (gdb.selected_inferior().connection_num)" \ > + "$expected_connection_num" \ > + "third inferior's native connection" > + > gdb_test "inferior 1" ".*" "switch back to first inferior" > gdb_test_no_output "remove-inferiors 3" "remove second inferior" > } > -- > 2.17.1 >