From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 75DA63857430 for ; Tue, 21 Jun 2022 11:25:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 75DA63857430 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-332-HTDTyUVAP9GZ4RaNYJOppw-1; Tue, 21 Jun 2022 07:25:39 -0400 X-MC-Unique: HTDTyUVAP9GZ4RaNYJOppw-1 Received: by mail-wm1-f70.google.com with SMTP id l3-20020a05600c1d0300b0039c7efa2526so6263079wms.3 for ; Tue, 21 Jun 2022 04:25:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=9uUIUtakIyPruxkNJCzQBaAYHQQUBm1uRW6OhfawgGY=; b=02wItYt9rtxM0kSGHrIiQQ7CjpCjHYneiX7Qqk0AvVrEneutGVLslbVPTChJ67dBOe BqSf4vXcyX12lZZ+Qwd22tdNUweB5F1TcBh2ka/eoG2Je5qcbh+qsMxEaj+DALQK9v4y iDk3Yg0RPvqvJ0A56gsfCUeLPbCxFVOG6YiPITUoAsjkHV7A2g7QRzR9rBK06GncqsJc bcLhRs/ZMNtpglRMSy3ToBnyGIiMZqmknJ5bXX3q54r9Agmqz2sTjClYFBEi5SabTsZq LCRKjTUt5DINOj69l0ua7pSmycpC3QuzEdzkz/XCi1hG1muNIG1awf4mXL29WNzupCyI w3Pw== X-Gm-Message-State: AJIora9cqNHceXg60N5y05iVTR0KKbIPAuCCuCm9F7MJF+Dsr66tXZKv UNnqW96F5TqymnhNrPn3AEQDdGVllL2D41O0X8z9bAP6DwV9Zjs+RlGrewBqV2RbG/uCOwGd1Sr c36wSJrNh0TIhG1Y2v+rLXYr9CIetKijazJ5prsMKI1VtOQLJlwR/HU1JKm8JxbdmrBWM+sVg8g == X-Received: by 2002:a5d:6d46:0:b0:21b:933d:7950 with SMTP id k6-20020a5d6d46000000b0021b933d7950mr6862157wri.679.1655810737615; Tue, 21 Jun 2022 04:25:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v5j7MnprIJJ7Qk3leu1JVlRZ39ZsRJA6GHuuYSzxhlZf86RqzMS6MoWPpVmrqOcRy15JlqPg== X-Received: by 2002:a5d:6d46:0:b0:21b:933d:7950 with SMTP id k6-20020a5d6d46000000b0021b933d7950mr6862117wri.679.1655810737164; Tue, 21 Jun 2022 04:25:37 -0700 (PDT) Received: from localhost ([213.31.44.107]) by smtp.gmail.com with ESMTPSA id k190-20020a1ca1c7000000b0039c587342d8sm21696277wme.3.2022.06.21.04.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 04:25:36 -0700 (PDT) From: Andrew Burgess To: Tom Tromey via Gdb-patches , gdb-patches@sourceware.org Cc: Tom Tromey Subject: Re: [PATCH] Add gdb.Objfile.is_file attribute In-Reply-To: <20220620183940.2718428-1-tromey@adacore.com> References: <20220620183940.2718428-1-tromey@adacore.com> Date: Tue, 21 Jun 2022 12:25:35 +0100 Message-ID: <87letqcl74.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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, 21 Jun 2022 11:25:42 -0000 Tom Tromey via Gdb-patches writes: > Sometimes an objfile comes from memory and not from a file. It can be > useful to be able to check this from Python, so this patch adds a new > "is_file" attribute. LGTM. Thanks, Andrew > --- > gdb/NEWS | 3 +++ > gdb/doc/python.texi | 7 +++++++ > gdb/python/py-objfile.c | 14 ++++++++++++++ > gdb/testsuite/gdb.base/jit-reader.exp | 12 ++++++++++++ > 4 files changed, 36 insertions(+) > > diff --git a/gdb/NEWS b/gdb/NEWS > index 5576c355b7a..e1bb468e76c 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -106,6 +106,9 @@ GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux* > to wrap the result of a call to a Disassembler. It has > read-only attributes 'length' and 'string'. > > + ** gdb.Objfile now has an attribute named "is_file". This is True > + if the objfile comes from a file, and False otherwise. > + > * New features in the GDB remote stub, GDBserver > > ** GDBserver is now supported on LoongArch GNU/Linux. > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 9e2e97b1e74..19ae33012c3 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -4891,6 +4891,13 @@ The value is @code{None} if the objfile is no longer valid. > See the @code{gdb.Objfile.is_valid} method, described below. > @end defvar > > +@defvar Objfile.is_file > +An objfile often comes from an ordinary file, but in some cases it may > +be constructed from the contents of memory. This attribute is > +@code{True} for file-backed objfiles, and @code{False} for other > +kinds. > +@end defvar > + > @defvar Objfile.owner > For separate debug info objfiles this is the corresponding @code{gdb.Objfile} > object that debug info is being provided for. > diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c > index 3e3270e7cd3..298f3f23632 100644 > --- a/gdb/python/py-objfile.c > +++ b/gdb/python/py-objfile.c > @@ -101,6 +101,18 @@ objfpy_get_username (PyObject *self, void *closure) > Py_RETURN_NONE; > } > > +/* Get the 'is_file' attribute. */ > + > +static PyObject * > +objfpy_get_is_file (PyObject *o, void *ignore) > +{ > + objfile_object *self = (objfile_object *) o; > + > + if (self->objfile != nullptr) > + return PyBool_FromLong ((self->objfile->flags & OBJF_NOT_FILENAME) == 0); > + Py_RETURN_NONE; > +} > + > /* If SELF is a separate debug-info file, return the "backlink" field. > Otherwise return None. */ > > @@ -762,6 +774,8 @@ static gdb_PyGetSetDef objfile_getset[] = > "Type printers.", NULL }, > { "xmethods", objfpy_get_xmethods, NULL, > "Debug methods.", NULL }, > + { "is_file", objfpy_get_is_file, nullptr, > + "Whether this objfile came from a file.", nullptr }, > { NULL } > }; > > diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp > index d94360cd7d9..117e9fe0e34 100644 > --- a/gdb/testsuite/gdb.base/jit-reader.exp > +++ b/gdb/testsuite/gdb.base/jit-reader.exp > @@ -13,6 +13,9 @@ > # You should have received a copy of the GNU General Public License > # along with this program. If not, see . > > +# Optionally test a Python API here as well. > +load_lib gdb-python.exp > + > standard_testfile jit-reader-host.c > > if { (![istarget x86_64-*-*] && ![istarget i?86-*-*]) || ![is_lp64_target] } { > @@ -271,6 +274,15 @@ proc jit_reader_test {} { > "#1 ${any} in main ${any}" \ > ] > } > + > + if {![skip_python_tests]} { > + gdb_test "python print(any(\[not x.is_file for x in gdb.objfiles()\]))" \ > + "True" \ > + "at least one non-file objfile" > + gdb_test "python print(any(\[x.is_file for x in gdb.objfiles()\]))" \ > + "True" \ > + "at least one file-based objfile" > + } > } > > jit_reader_test > -- > 2.34.1