* [PATCH v2 0/2] Add "announce" flag to Python breakpoint creation
@ 2026-11-09 20:53 Tom Tromey
2026-11-09 20:53 ` [PATCH v2 1/2] Refactor body of bppy_init Tom Tromey
2026-11-09 20:53 ` [PATCH v2 2/2] Let Python breakpoints be created silently Tom Tromey
0 siblings, 2 replies; 4+ messages in thread
From: Tom Tromey @ 2026-11-09 20:53 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This is a refresh of a patch from ages ago. v1 was here:
https://inbox.sourceware.org/gdb-patches/20221208191804.3819129-1-tromey@adacore.com/
I'm not sure why I didn't check it in at the time.
Signed-off-by: Tom Tromey <tromey@adacore.com>
---
Tom Tromey (2):
Refactor body of bppy_init
Let Python breakpoints be created silently
gdb/doc/python.texi | 10 +-
gdb/python/py-breakpoint.c | 187 +++++++++++++++++------------
gdb/testsuite/gdb.python/py-breakpoint.exp | 3 +-
3 files changed, 118 insertions(+), 82 deletions(-)
---
base-commit: 96248aa4173886a47a7aa1798861267edde28801
change-id: 20261109-submit-py-bp-announce-db6e5b4e8ec4
Best regards,
--
Tom Tromey <tromey@adacore.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] Refactor body of bppy_init
2026-11-09 20:53 [PATCH v2 0/2] Add "announce" flag to Python breakpoint creation Tom Tromey
@ 2026-11-09 20:53 ` Tom Tromey
2026-11-09 20:53 ` [PATCH v2 2/2] Let Python breakpoints be created silently Tom Tromey
1 sibling, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2026-11-09 20:53 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This patch pulls the body of bppy_init out into a separate function.
This will simplify a subsequent patch.
---
gdb/python/py-breakpoint.c | 172 ++++++++++++++++++++++++---------------------
1 file changed, 93 insertions(+), 79 deletions(-)
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index ee7276f1792..72b55cf7d5f 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -979,6 +979,95 @@ bppy_init_validate_args (const char *spec, char *source,
return 1;
}
+/* Helper function for breakpoint creation. */
+
+static void
+bppy_create_breakpoint (enum bptype type, int access_type, bool temporary_bp,
+ bool internal_bp, const char *spec,
+ bool qualified, bool allow_pending,
+ const char *source, const char *function,
+ const char *label, const char *line)
+{
+ switch (type)
+ {
+ case bp_breakpoint:
+ case bp_hardware_breakpoint:
+ {
+ location_spec_up locspec;
+ symbol_name_match_type func_name_match_type
+ = (qualified
+ ? symbol_name_match_type::FULL
+ : symbol_name_match_type::WILD);
+
+ if (spec != NULL)
+ {
+ gdb::unique_xmalloc_ptr<char>
+ copy_holder (xstrdup (skip_spaces (spec)));
+ const char *copy = copy_holder.get ();
+
+ locspec = string_to_location_spec (©,
+ current_language,
+ func_name_match_type);
+ }
+ else
+ {
+ std::unique_ptr<explicit_location_spec> explicit_loc
+ (new explicit_location_spec ());
+
+ if (source != nullptr)
+ explicit_loc->source_filename = make_unique_xstrdup (source);
+ if (function != nullptr)
+ explicit_loc->function_name = make_unique_xstrdup (function);
+ if (label != nullptr)
+ explicit_loc->label_name = make_unique_xstrdup (label);
+
+ if (line != NULL)
+ explicit_loc->line_offset
+ = linespec_parse_line_offset (line);
+
+ explicit_loc->func_name_match_type = func_name_match_type;
+
+ locspec.reset (explicit_loc.release ());
+ }
+
+ const struct breakpoint_ops *ops
+ = breakpoint_ops_for_location_spec (locspec.get (), false);
+
+ auto_boolean pending_enabled
+ = (allow_pending
+ ? AUTO_BOOLEAN_TRUE
+ : AUTO_BOOLEAN_FALSE);
+ create_breakpoint (gdbpy_enter::get_gdbarch (),
+ locspec.get (), NULL, -1, -1, NULL, false,
+ 0,
+ temporary_bp, type,
+ 0,
+ pending_enabled,
+ ops,
+ 0, 1, internal_bp, 0);
+ break;
+ }
+ case bp_watchpoint:
+ {
+ spec = skip_spaces (spec);
+
+ if (access_type == hw_write)
+ watch_command_wrapper (spec, 0, internal_bp);
+ else if (access_type == hw_access)
+ awatch_command_wrapper (spec, 0, internal_bp);
+ else if (access_type == hw_read)
+ rwatch_command_wrapper (spec, 0, internal_bp);
+ else
+ error(_("Cannot understand watchpoint access type."));
+ break;
+ }
+ case bp_catchpoint:
+ error (_("BP_CATCHPOINT not supported"));
+ default:
+ error(_("Do not understand breakpoint type to set."));
+ }
+}
+
/* Python function to create a new breakpoint. */
static int
bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
@@ -1051,85 +1140,10 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
try
{
- switch (type)
- {
- case bp_breakpoint:
- case bp_hardware_breakpoint:
- {
- location_spec_up locspec;
- gdb_assert (PyBool_Check (qualified));
- symbol_name_match_type func_name_match_type
- = (qualified == Py_True
- ? symbol_name_match_type::FULL
- : symbol_name_match_type::WILD);
-
- if (spec != NULL)
- {
- gdb::unique_xmalloc_ptr<char>
- copy_holder (xstrdup (skip_spaces (spec)));
- const char *copy = copy_holder.get ();
-
- locspec = string_to_location_spec (©,
- current_language,
- func_name_match_type);
- }
- else
- {
- std::unique_ptr<explicit_location_spec> explicit_loc
- (new explicit_location_spec ());
-
- if (source != nullptr)
- explicit_loc->source_filename = make_unique_xstrdup (source);
- if (function != nullptr)
- explicit_loc->function_name = make_unique_xstrdup (function);
- if (label != nullptr)
- explicit_loc->label_name = make_unique_xstrdup (label);
-
- if (line != NULL)
- explicit_loc->line_offset
- = linespec_parse_line_offset (line.get ());
-
- explicit_loc->func_name_match_type = func_name_match_type;
-
- locspec.reset (explicit_loc.release ());
- }
-
- const struct breakpoint_ops *ops
- = breakpoint_ops_for_location_spec (locspec.get (), false);
-
- auto_boolean pending_enabled
- = (allow_pending == Py_True
- ? AUTO_BOOLEAN_TRUE
- : AUTO_BOOLEAN_FALSE);
- create_breakpoint (gdbpy_enter::get_gdbarch (),
- locspec.get (), NULL, -1, -1, NULL, false,
- 0,
- temporary_bp, type,
- 0,
- pending_enabled,
- ops,
- 0, 1, internal_bp, 0);
- break;
- }
- case bp_watchpoint:
- {
- spec = skip_spaces (spec);
-
- if (access_type == hw_write)
- watch_command_wrapper (spec, 0, internal_bp);
- else if (access_type == hw_access)
- awatch_command_wrapper (spec, 0, internal_bp);
- else if (access_type == hw_read)
- rwatch_command_wrapper (spec, 0, internal_bp);
- else
- error(_("Cannot understand watchpoint access type."));
- break;
- }
- case bp_catchpoint:
- error (_("BP_CATCHPOINT not supported"));
- default:
- error(_("Do not understand breakpoint type to set."));
- }
+ bppy_create_breakpoint (type, access_type, temporary_bp, internal_bp,
+ spec, qualified == Py_True,
+ allow_pending == Py_True, source, function,
+ label, line.get ());
}
catch (const gdb_exception &except)
{
--
2.56.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] Let Python breakpoints be created silently
2026-11-09 20:53 [PATCH v2 0/2] Add "announce" flag to Python breakpoint creation Tom Tromey
2026-11-09 20:53 ` [PATCH v2 1/2] Refactor body of bppy_init Tom Tromey
@ 2026-11-09 20:53 ` Tom Tromey
2026-11-10 12:26 ` Eli Zaretskii
1 sibling, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2026-11-09 20:53 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
Currently, a breakpoint created from Python will always announce its
presence; and in some cases (for example a pending breakpoint), other
information will be printed as well.
When scripting gdb, it's useful to be able to control the output in
cases like this. I debated whether to simply disable the output
entirely, but I thought perhaps some existing code acts as a simple
"break"-like command and wants the output.
This patch adds a new "announce" flag to gdb.Breakpoint. Setting this
to False will cause gdb to be silent here.
---
gdb/doc/python.texi | 10 ++++++++--
gdb/python/py-breakpoint.c | 29 ++++++++++++++++++++++-------
gdb/testsuite/gdb.python/py-breakpoint.exp | 3 ++-
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index d8f47098ec8..49eae367f71 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -6953,7 +6953,7 @@ create both breakpoints and watchpoints. The second accepts separate Python
arguments similar to @ref{Explicit Locations}, and can only be used to create
breakpoints.
-@defun Breakpoint.__init__ (spec @r{[}, type @r{][}, wp_class @r{][}, internal @r{][}, temporary @r{][}, qualified @r{][}, allow_pending @r{]})
+@defun Breakpoint.__init__ (spec @r{[}, type @r{][}, wp_class @r{][}, internal @r{][}, temporary @r{][}, qualified @r{][}, allow_pending @r{][}, announce @r{]})
Create a new breakpoint according to @var{spec}, which is a string naming the
location of a breakpoint, or an expression that defines a watchpoint. The
string should describe a location in a format recognized by the @code{break}
@@ -6992,9 +6992,15 @@ the @var{allow_pending} argument is set to @code{False} and the breakpoint
location cannot be resolved, a @code{gdb.error} exception is raised
instead of creating a pending breakpoint.
+The optional @var{announce} argument is a boolean that controls
+whether @var{GDBN} announces the existence of the breakpoint. The
+default is to announce, meaning that a message is printed. Setting
+this argument to false will suppress all output from breakpoint
+creation.
+
@end defun
-@defun Breakpoint.__init__ (@r{[} source @r{][}, function @r{][}, label @r{][}, line @r{]}, @r{][} internal @r{][}, temporary @r{][}, qualified @r{][}, allow_pending @r{]})
+@defun Breakpoint.__init__ (@r{[} source @r{][}, function @r{][}, label @r{][}, line @r{]}, @r{][} internal @r{][}, temporary @r{][}, qualified @r{][}, allow_pending @r{][}, announce @r{]})
This second form of creating a new breakpoint specifies the explicit
location (@pxref{Explicit Locations}) using keywords. The new breakpoint will
be created in the specified source file @var{source}, at the specified
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 72b55cf7d5f..14aa0621283 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "source.h"
+#include "top.h"
#include "value.h"
#include "python-internal.h"
#include "python.h"
@@ -1075,7 +1076,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
static const char *keywords[] = { "spec", "type", "wp_class", "internal",
"temporary","source", "function",
"label", "line", "qualified",
- "allow_pending", nullptr };
+ "allow_pending", "announce", nullptr };
const char *spec = NULL;
enum bptype type = bp_breakpoint;
int access_type = hw_write;
@@ -1090,15 +1091,17 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
char *function = NULL;
PyObject *qualified = Py_False;
PyObject *allow_pending = Py_True;
+ PyObject *announce_obj = Py_True;
- if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO!O!",
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO!O!O!",
keywords,
&spec, &type, &access_type,
&internal,
&temporary, &source,
&function, &label, &lineobj,
&PyBool_Type, &qualified,
- &PyBool_Type, &allow_pending))
+ &PyBool_Type, &allow_pending,
+ &PyBool_Type, &announce_obj))
return -1;
@@ -1140,10 +1143,22 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
try
{
- bppy_create_breakpoint (type, access_type, temporary_bp, internal_bp,
- spec, qualified == Py_True,
- allow_pending == Py_True, source, function,
- label, line.get ());
+ if (announce_obj == Py_True)
+ bppy_create_breakpoint (type, access_type, temporary_bp, internal_bp,
+ spec, qualified == Py_True,
+ allow_pending == Py_True, source, function,
+ label, line.get ());
+ else
+ {
+ std::string ignore;
+ execute_fn_to_string (ignore, [&] ()
+ {
+ bppy_create_breakpoint (type, access_type, temporary_bp, internal_bp,
+ spec, qualified == Py_True,
+ allow_pending == Py_True, source, function,
+ label, line.get ());
+ }, false);
+ }
}
catch (const gdb_exception &except)
{
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 1cfb156eb3c..a2e320c3ae0 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -635,7 +635,8 @@ proc_with_prefix test_bkpt_pending {} {
clean_restart ${testfile}
delete_breakpoints
- gdb_breakpoint "nosuchfunction" -allow-pending
+ gdb_test_no_output "python gdb.Breakpoint(\"nosuchfunction\", announce=False)" \
+ "create pending breakpoint"
gdb_test "python print (gdb.breakpoints()\[0\].pending)" "True" \
"Check pending status of pending breakpoint"
--
2.56.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] Let Python breakpoints be created silently
2026-11-09 20:53 ` [PATCH v2 2/2] Let Python breakpoints be created silently Tom Tromey
@ 2026-11-10 12:26 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2026-11-10 12:26 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
> From: Tom Tromey <tromey@adacore.com>
> Date: Mon, 09 Nov 2026 13:53:25 -0700
> Cc: Tom Tromey <tromey@adacore.com>
>
> Currently, a breakpoint created from Python will always announce its
> presence; and in some cases (for example a pending breakpoint), other
> information will be printed as well.
>
> When scripting gdb, it's useful to be able to control the output in
> cases like this. I debated whether to simply disable the output
> entirely, but I thought perhaps some existing code acts as a simple
> "break"-like command and wants the output.
>
> This patch adds a new "announce" flag to gdb.Breakpoint. Setting this
> to False will cause gdb to be silent here.
> ---
> gdb/doc/python.texi | 10 ++++++++--
> gdb/python/py-breakpoint.c | 29 ++++++++++++++++++++++-------
> gdb/testsuite/gdb.python/py-breakpoint.exp | 3 ++-
> 3 files changed, 32 insertions(+), 10 deletions(-)
Thanks.
> +The optional @var{announce} argument is a boolean that controls
> +whether @var{GDBN} announces the existence of the breakpoint. The
^^^^^^^^^^
"@value{GDBN}"
> +default is to announce, meaning that a message is printed. Setting
> +this argument to false will suppress all output from breakpoint
^^^^^
That "false" should be in @code, no?
The documentation part is okay with those nits fixed.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-10 12:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 20:53 [PATCH v2 0/2] Add "announce" flag to Python breakpoint creation Tom Tromey
2026-11-09 20:53 ` [PATCH v2 1/2] Refactor body of bppy_init Tom Tromey
2026-11-09 20:53 ` [PATCH v2 2/2] Let Python breakpoints be created silently Tom Tromey
2026-11-10 12:26 ` Eli Zaretskii
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox