From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 3/5] Add require_valid to Python breakpoint and breakpoint location
Date: Wed, 14 Oct 2026 08:08:51 -0600 [thread overview]
Message-ID: <20261014-python-safety-breakpoint-v1-3-c8e72d58f3cd@tromey.com> (raw)
In-Reply-To: <20261014-python-safety-breakpoint-v1-0-c8e72d58f3cd@tromey.com>
This adds a require_valid method to the Python breakpoint and
breakpoint location objects. These will be used in subsequent
patches.
Note that the breakpoint location implementation checks that the
breakpoint is valid. This was done by all users of the macro, so it
seemed more convenient to do this here.
---
gdb/python/py-breakpoint.c | 17 +++++++++++++++++
gdb/python/python-internal.h | 3 +++
2 files changed, 20 insertions(+)
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 8781c17838b..40d1244abcf 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -69,6 +69,15 @@ struct gdbpy_breakpoint_location_object : public PyObject
/* Implementation of 'repr'. */
gdbpy_ref<> repr ();
+
+ /* If this breakpoint location is not valid, throw an exception. */
+ void require_valid () const
+ {
+ owner->require_valid ();
+ if (owner->bp != bp_loc->owner)
+ return gdbpy_err_format (PyExc_RuntimeError,
+ _("Breakpoint location is invalid."));
+ }
};
static_assert (gdb::is_python_allocatable_v<gdbpy_breakpoint_location_object>);
@@ -159,6 +168,14 @@ static struct pybp_code pybp_watch_types[] =
{NULL} /* Sentinel. */
};
+void
+gdbpy_breakpoint_object::require_valid () const
+{
+ if (bp == nullptr)
+ gdbpy_err_format (PyExc_RuntimeError, _("Breakpoint %d is invalid."),
+ number);
+}
+
/* Python function which checks the validity of a breakpoint object. */
static PyObject *
bppy_is_valid (PyObject *self, PyObject *args)
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 55e5e8eaabe..2d990ee6ac1 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -427,6 +427,9 @@ struct gdbpy_breakpoint_object : public PyObject
/* 1 is this is a FinishBreakpoint object, 0 otherwise. */
int is_finish_bp;
+
+ /* If this breakpoint is not valid, throw an exception. */
+ void require_valid () const;
};
static_assert (gdb::is_python_allocatable_v<gdbpy_breakpoint_object>);
--
2.49.0
next prev parent reply other threads:[~2026-10-14 14:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 14:08 [PATCH 0/5] Use Python safety API for breakpoint locations Tom Tromey
2026-10-14 14:08 ` [PATCH 1/5] Rewrite gdb.BreakpointLocation repr method Tom Tromey
2026-10-14 14:08 ` [PATCH 2/5] Move two macros from python-internal.h to py-breakpoint.c Tom Tromey
2026-10-14 14:08 ` Tom Tromey [this message]
2026-10-14 14:08 ` [PATCH 4/5] Rewrite breakpoint location getter methods Tom Tromey
2026-10-14 14:08 ` [PATCH 5/5] Rewrite gdb.BreakpointLocation setter Tom Tromey
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=20261014-python-safety-breakpoint-v1-3-c8e72d58f3cd@tromey.com \
--to=tom@tromey.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