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 525103858403 for ; Wed, 30 Mar 2022 08:56:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 525103858403 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-508-WhCwm9_IPNG2VyRzr2oI8g-1; Wed, 30 Mar 2022 04:56:49 -0400 X-MC-Unique: WhCwm9_IPNG2VyRzr2oI8g-1 Received: by mail-wm1-f71.google.com with SMTP id v2-20020a05600c214200b0038c7c02deceso2333035wml.8 for ; Wed, 30 Mar 2022 01:56:49 -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=2xoICnow1UnGfNz/qQVNMTAXrlGFdkajQbTOBGd4PqI=; b=L9zUdYe2sIY0rfGcxY9INP76tcz4J5LztmTkV3LVRwFjXtghBinHm58F/ip3DokjRu EC7tdJD7SH2UyOcKQBexNmmQUOsbWagkdoqxwbFj5b7juwk2w+XjLk9hwm/lLoICsg/g Z2CiEe8zf0LhNZsmZ5+i0VmygVV22ElMVW+jybSLy4cRlYqAZzbwak0yEy9iACrpZzI8 3Oh7RlXotWjUabKUN6HPgRp18GK+tEhHVCaRCDOOJYgnhxiLQoDu9ZNek1JMDzwFtLaN t7CLqjb1uK4dsL+F/4Kq0NfPfIA0a0Y4rUeFsFsnkWaw5o8TOXcVG5U0DxQ7tBCbj0kI LgLQ== X-Gm-Message-State: AOAM532AqoMZ4vEP2aWWNurt+BkNpM3bUGoT/Y6uadhYNNGZPAJPxb3N QDqLkdAbIbzn90L7bekfwpFYx2AYYTrpzyNy441yiOD/y+TQohWkB/TX7C/2zTYCLd/TBtZKzM2 Rd0NWqK1jfk+hDfpwvdYEY3KHf/wS0o2As4e7TSjgXwJMy51EhAgGeIJxdQBj7mimP+TkQaNmZg == X-Received: by 2002:a05:600c:4110:b0:38c:ba41:9fb with SMTP id j16-20020a05600c411000b0038cba4109fbmr3378130wmi.47.1648630608091; Wed, 30 Mar 2022 01:56:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+uX+QDnW5fEya2x9kRG+EZ7lan9NUQnNShN1N4tbNkFLJgKFBXPoUD6C9Bqls69HEMvQk5A== X-Received: by 2002:a05:600c:4110:b0:38c:ba41:9fb with SMTP id j16-20020a05600c411000b0038cba4109fbmr3378113wmi.47.1648630607807; Wed, 30 Mar 2022 01:56:47 -0700 (PDT) Received: from localhost (host86-169-131-113.range86-169.btcentralplus.com. [86.169.131.113]) by smtp.gmail.com with ESMTPSA id p11-20020a5d638b000000b002048a77636dsm16311367wru.97.2022.03.30.01.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 01:56:47 -0700 (PDT) From: Andrew Burgess To: Simon Farre via Gdb-patches , gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property In-Reply-To: <20220329212717.1184271-2-simon.farre.cx@gmail.com> References: <20220329212717.1184271-1-simon.farre.cx@gmail.com> <20220329212717.1184271-2-simon.farre.cx@gmail.com> Date: Wed, 30 Mar 2022 09:56:45 +0100 Message-ID: <87k0cbakdu.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.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 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 08:56:53 -0000 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