From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/5] Rewrite gdb.BreakpointLocation repr method
Date: Wed, 14 Oct 2026 08:08:49 -0600 [thread overview]
Message-ID: <20261014-python-safety-breakpoint-v1-1-c8e72d58f3cd@tromey.com> (raw)
In-Reply-To: <20261014-python-safety-breakpoint-v1-0-c8e72d58f3cd@tromey.com>
This rewrites the gdb.BreakpointLocation repr method to use the Python
safety API.
---
gdb/python/py-breakpoint.c | 45 +++++++++++++++++++++++++--------------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index b1615db1be3..cb18fec11f9 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -44,6 +44,9 @@ struct gdbpy_breakpoint_location_object : public PyObject
/* An owning reference to the location's breakpoint owner. */
gdbpy_breakpoint_object *owner;
+
+ /* Implementation of 'repr'. */
+ gdbpy_ref<> repr ();
};
static_assert (gdb::is_python_allocatable_v<gdbpy_breakpoint_location_object>);
@@ -1716,40 +1719,41 @@ bplocpy_dealloc (PyObject *py_self)
/* __repr__ implementation for gdb.BreakpointLocation. */
-static PyObject *
-bplocpy_repr (PyObject *py_self)
+gdbpy_ref<>
+gdbpy_breakpoint_location_object::repr ()
{
- const auto self = (gdbpy_breakpoint_location_object *) py_self;
- if (self->owner == nullptr || self->owner->bp == nullptr
- || self->owner->bp != self->bp_loc->owner)
- return gdb_py_invalid_object_repr (py_self);
+ if (owner == nullptr || owner->bp == nullptr || owner->bp != bp_loc->owner)
+ /* FIXME: Python safety. gdb_py_invalid_object_repr ought to
+ throw on error, and return gdbpy_ref<>, but currently does
+ not. */
+ return gdbpy_ref<> (gdb_py_invalid_object_repr (this));
- const auto enabled = self->bp_loc->enabled ? "enabled" : "disabled";
+ const auto enabled = bp_loc->enabled ? "enabled" : "disabled";
std::string str (enabled);
str += string_printf (" address=%s",
- paddress (self->bp_loc->owner->gdbarch,
- self->bp_loc->address));
+ paddress (bp_loc->owner->gdbarch,
+ bp_loc->address));
- if (self->bp_loc->requested_address != self->bp_loc->address)
+ if (bp_loc->requested_address != bp_loc->address)
str += string_printf (" requested_address=%s",
- paddress (self->bp_loc->owner->gdbarch,
- self->bp_loc->requested_address));
- if (self->bp_loc->symtab != nullptr)
- str += string_printf (" source=%s:%d", self->bp_loc->symtab->filename (),
- self->bp_loc->line_number);
+ paddress (bp_loc->owner->gdbarch,
+ bp_loc->requested_address));
+ if (bp_loc->symtab != nullptr)
+ str += string_printf (" source=%s:%d", bp_loc->symtab->filename (),
+ bp_loc->line_number);
- const auto fn_name = self->bp_loc->function_name.get ();
+ const auto fn_name = bp_loc->function_name.get ();
if (fn_name != nullptr)
{
str += " in ";
str += fn_name;
}
- return PyUnicode_FromFormat ("<%s %s>",
- gdbpy_py_obj_tp_name (py_self).c_str (),
- str.c_str ());
+ return gdbpy_unicode_from_format ("<%s %s>",
+ gdbpy_py_obj_tp_name (this).c_str (),
+ str.c_str ());
}
/* Attribute get/set Python definitions. */
@@ -1783,7 +1787,8 @@ PyTypeObject breakpoint_location_object_type =
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
- bplocpy_repr, /*tp_repr*/
+ wrap_tp_callback<gdbpy_breakpoint_location_object,
+ &gdbpy_breakpoint_location_object::repr>, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
--
2.49.0
next prev parent reply other threads:[~2026-10-14 14:09 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 ` Tom Tromey [this message]
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 ` [PATCH 3/5] Add require_valid to Python breakpoint and breakpoint location Tom Tromey
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-1-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