Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH v2 2/2] Let Python breakpoints be created silently
Date: Mon, 09 Nov 2026 13:53:25 -0700	[thread overview]
Message-ID: <20261109-submit-py-bp-announce-v2-2-aac3f3d98da6@adacore.com> (raw)
In-Reply-To: <20261109-submit-py-bp-announce-v2-0-aac3f3d98da6@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(-)

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


  parent reply	other threads:[~2026-11-09 20:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-10 12:26   ` [PATCH v2 2/2] Let Python breakpoints be created silently Eli Zaretskii

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=20261109-submit-py-bp-announce-v2-2-aac3f3d98da6@adacore.com \
    --to=tromey@adacore.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