From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id 585B23886C47 for ; Wed, 30 Mar 2022 10:04:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 585B23886C47 Received: by mail-lj1-x231.google.com with SMTP id 17so26994194lji.1 for ; Wed, 30 Mar 2022 03:04:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Lsv/xnXJa3g9PTzbVIfZ8lW/E9UP5NZipjpftAxUz8E=; b=oYn05ciab8YNKKRaE+xEhu+vW1Y/w5ytGM1LfYMdSM+laKZiaO8AGXF3FerGDAl+VL /HAOXGMvthjvrTMTNNXtI8WOJwcZvAmPy64Nhd3yS4wu6zYndfMPcUf5GBM/4eV9m8ku vXb1icpi8OQM+6QgeSkbBEf9LWH4pv320/pFNkRWJ/qpN2fy3KXF7dajtKIzx0wXmYm5 A0w/aWDrt3EsWnjyxWM+KqAVkKaUtPq0B0DI2xZB8tuRoqJXeVj7VMEyn08xiAekKSR+ Wn+l4mM2PXx4GtdM7HSfpEss8DFepymZ5ZAsb8eM2u19M6UZHZN0Jb2lgGwSw1kNR4Lk vhcw== X-Gm-Message-State: AOAM531bBBIfhWa8IyNUu2XQV+9WGGVPfqiga5kPVumyXMkN9xYFFaxM cVAW6BNoro4LMl/RnuZD6Qg1u7O68+LRPXkBc1Y= X-Google-Smtp-Source: ABdhPJyIMkCXjpzckNXcky4LerWREtpl35sQMJFWSPQ+jRM2mafxMqO1XlALiQytrk4S6cBZKOa4uzL4fYKMQJyEWEk= X-Received: by 2002:a05:651c:1248:b0:247:ebd8:95b with SMTP id h8-20020a05651c124800b00247ebd8095bmr6034550ljh.43.1648634665832; Wed, 30 Mar 2022 03:04:25 -0700 (PDT) MIME-Version: 1.0 References: <20220329212717.1184271-1-simon.farre.cx@gmail.com> <20220329212717.1184271-2-simon.farre.cx@gmail.com> <87k0cbakdu.fsf@redhat.com> In-Reply-To: <87k0cbakdu.fsf@redhat.com> From: Simon Farre Date: Wed, 30 Mar 2022 12:04:14 +0200 Message-ID: Subject: Re: [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property To: Andrew Burgess Cc: Simon Farre via Gdb-patches X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Wed, 30 Mar 2022 10:04:29 -0000 Seems perfectly reasonable to me and I will look into it right away. I suppose it could be worth also adding an attribute to the BreakpointLocation that signals it's "minor" version number (like it's displayed when running "info break") although, I'm going to try and tackle what you've listed here, first. Den ons 30 mars 2022 kl 10:56 skrev Andrew Burgess : > Simon Farre via Gdb-patches writes: > > > Currently it's not possible from the Python API to know > > where a breakpoint has been installed in memory. > > > > This attribute returns a list of the addresses where > > this breakpoint has been installed. This reflects > > the same information shown by the command `info b`. > > > > If the breakpoint is pending it will return None, > > but also if the breakpoint is not of type "breakpoint" > > or "watchpoint" it will also return none. > > > > The rationale for this patch is for IDE or debug adapters > > as they are called, for instance for VSCode, to be able > > to fetch breakpoint related data directly from Python, > > but also useful for plugins that need to query information > > about breakpoints. > > I agree that this is a problem that needs to be solved. Unfortunately, > I don't think this is the right approach to take here. > > I think that we should introduce a BreakpointLocation object, which > should encapsulate the information here. > > The reason is that GDB has the ability to enable and disable breakpoints > at the individual location level, so we would at a minimum support: > > BreakpointLocation.address : read-only, a single address, which > corresponds to what you're adding here, > > BreakpointLocation.enabled : read/write, can enable/disable a single > location, > > BreapointLocation.breakpoint : read-only, the parent breakpoint > object, > > I'm sure we would probably end up adding more functionality over time, > but I think once the we've got the object in place then we have the > framework for future work in place. > > Then we'd obviously want to add: > > Breakpoint.locations : read-only, a list of BreakpointLocation > objects. > > I know this is initially much more work, but I think it will give a > better solution in the end. > > Thanks, > Andrew > > > > > > --- > > gdb/NEWS | 5 +++++ > > gdb/doc/python.texi | 6 ++++++ > > gdb/python/py-breakpoint.c | 26 ++++++++++++++++++++++++++ > > 3 files changed, 37 insertions(+) > > > > diff --git a/gdb/NEWS b/gdb/NEWS > > index 9e7e41d3bd6..1410c7027e8 100644 > > --- a/gdb/NEWS > > +++ b/gdb/NEWS > > @@ -21,6 +21,11 @@ > > Breakpoint was installed. This is the information displayed > > by the 'info breakpoints' command. > > > > + ** Added attribute Breakpoint.addresses > > + This returns a list of addresses (as longs) where the > > + breakpoint was installed. This is the same address information > > + displayed by the 'info breakpoint' command > > + > > *** Changes in GDB 12 > > > > * DBX mode is deprecated, and will be removed in GDB 13 > > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > > index 0d842af6229..3511b8b00a4 100644 > > --- a/gdb/doc/python.texi > > +++ b/gdb/doc/python.texi > > @@ -6074,6 +6074,12 @@ breakpoint or is of a type that doesn't have a > source location related to it > > it returns @code{None}. This attribute is not writable. > > @end defvar > > > > +@defvar Breakpoint.addresses > > +This attribute holds the address(es) where the breakpoint was installed. > > +If the breakpoint is a pending breakpoint, it returns @code{None}. > > +This attribute is not writable. > > +@end defvar > > + > > @node Finish Breakpoints in Python > > @subsubsection Finish Breakpoints > > > > diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c > > index 1b9ac6957a5..19c7cec815c 100644 > > --- a/gdb/python/py-breakpoint.c > > +++ b/gdb/python/py-breakpoint.c > > @@ -721,6 +721,30 @@ static PyObject* bppy_get_source_locations(PyObject > *self, void* closure) > > return list.release(); > > } > > > > +/* Python function to get all addresses where this breakpoint is set */ > > + > > +static PyObject* bppy_get_addresses(PyObject *self, void* closure) > > +{ > > + gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self; > > + struct breakpoint* bp = self_bp->bp; > > + > > + BPPY_REQUIRE_VALID (self_bp); > > + > > + if (pending_breakpoint_p(bp)) > > + Py_RETURN_NONE; > > + > > + if (!is_breakpoint(bp) && !is_watchpoint(bp)) > > + Py_RETURN_NONE; > > + > > + gdbpy_ref<> list (PyList_New (0)); > > + > > + for (const bp_location* it = bp->loc; it != nullptr; it = it->next) > > + if(PyList_Append(list.get(), PyLong_FromLong(it->address)) != 0) > > + return nullptr; > > + > > + return list.release(); > > +} > > + > > /* Internal function to validate the Python parameters/keywords > > provided to bppy_init. */ > > > > @@ -1295,6 +1319,8 @@ or None if no condition set."}, > > "Whether this breakpoint is a pending breakpoint."}, > > { "source_locations", bppy_get_source_locations, NULL, > > "Source file locations where this breakpoint is installed"}, > > + { "addresses", bppy_get_addresses, NULL, > > + "Get addresses of where this breakpoint is set" }, > > { NULL } /* Sentinel. */ > > }; > > > > -- > > 2.32.0 > >