From: Andrew Burgess <aburgess@redhat.com>
To: Simon Farre via Gdb-patches <gdb-patches@sourceware.org>,
gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property
Date: Wed, 30 Mar 2022 09:56:45 +0100 [thread overview]
Message-ID: <87k0cbakdu.fsf@redhat.com> (raw)
In-Reply-To: <20220329212717.1184271-2-simon.farre.cx@gmail.com>
Simon Farre via Gdb-patches <gdb-patches@sourceware.org> 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
next prev parent reply other threads:[~2022-03-30 8:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-29 21:27 [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property Simon Farre
2022-03-29 21:27 ` [PATCH 2/2] gdb/python: add gdb.Breakpoint.addresses property Simon Farre
2022-03-30 8:56 ` Andrew Burgess [this message]
2022-03-30 10:04 ` Simon Farre
2022-03-30 8:58 ` [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k0cbakdu.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).