Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor
@ 2026-10-13  7:47 Tomáš Hrnčiar
  2026-10-13 12:55 ` Eli Zaretskii
  2026-10-14 15:58 ` Tom Tromey
  0 siblings, 2 replies; 8+ messages in thread
From: Tomáš Hrnčiar @ 2026-10-13  7:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tomáš Hrnčiar

Add a new allow_pending parameter to the gdb.Breakpoint constructor.
Setting the new parameter to False causes GDB to raise an error instead
of creating a pending breakpoint.  By default this parameter is True,
which allows pending breakpoints to be created, preserving the existing
behaviour.
---
 gdb/NEWS                                   |  6 ++
 gdb/doc/python.texi                        | 17 +++--
 gdb/python/py-breakpoint.c                 | 16 +++--
 gdb/testsuite/gdb.python/py-breakpoint.exp | 82 ++++++++++++++++++++--
 4 files changed, 109 insertions(+), 12 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 5d0c4745653..eb637a21724 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -79,6 +79,12 @@ info locals
   The new "-shadowed on|off" option overrides the "set print shadowed"
   setting for a single invocation of the command.
 
+* Python API
+
+  ** The gdb.Breakpoint constructor now takes an optional
+     'allow_pending' argument.  Setting it to False causes GDB to raise
+     an error instead of creating a pending breakpoint.
+
 *** Changes in GDB 18
 
 * Support for the Common Trace Format (CTF) has been removed.  GDB now
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ddb347361f7..0b24698a77f 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{]})
+@defun Breakpoint.__init__ (spec @r{[}, type @r{][}, wp_class @r{][}, internal @r{][}, temporary @r{][}, qualified @r{][}, allow_pending @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}
@@ -6983,16 +6983,25 @@ the function passed in @code{spec} as a fully-qualified name.  It is equivalent
 to @code{break}'s @code{-qualified} flag (@pxref{Linespec Locations} and
 @ref{Explicit Locations}).
 
+The optional @var{allow_pending} argument is a boolean that controls whether
+the created breakpoint can be pending or not
+(@pxref{Set Breaks,,Pending Breakpoints}).  The @var{allow_pending} argument is
+set to @code{True} by default and is only considered when @var{type} is
+@code{gdb.BP_BREAKPOINT} or @code{gdb.BP_HARDWARE_BREAKPOINT}.  If
+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.
+
 @end defun
 
-@defun Breakpoint.__init__ (@r{[} source @r{][}, function @r{][}, label @r{][}, line @r{]}, @r{][} internal @r{][}, temporary @r{][}, qualified @r{]})
+@defun Breakpoint.__init__ (@r{[} source @r{][}, function @r{][}, label @r{][}, line @r{]}, @r{][} internal @r{][}, temporary @r{][}, qualified @r{][}, allow_pending @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
 @var{function}, @var{label} and @var{line}.
 
-@var{internal}, @var{temporary} and @var{qualified} have the same usage as
-explained previously.
+@var{internal}, @var{temporary}, @var{qualified} and @var{allow_pending} have
+the same usage as explained previously.
 @end defun
 
 The available types are represented by constants defined in the @code{gdb}
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index b1615db1be3..7261bd8e25b 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -914,7 +914,8 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
   static const char *keywords[] = { "spec", "type", "wp_class", "internal",
 				    "temporary","source", "function",
-				    "label", "line", "qualified", NULL };
+				    "label", "line", "qualified",
+				    "allow_pending", nullptr };
   const char *spec = NULL;
   enum bptype type = bp_breakpoint;
   int access_type = hw_write;
@@ -928,13 +929,16 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   char *source = NULL;
   char *function = NULL;
   PyObject *qualified = Py_False;
+  PyObject *allow_pending = Py_True;
 
-  if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO!", keywords,
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO!O!",
+					keywords,
 					&spec, &type, &access_type,
 					&internal,
 					&temporary, &source,
 					&function, &label, &lineobj,
-					&PyBool_Type, &qualified))
+					&PyBool_Type, &qualified,
+					&PyBool_Type, &allow_pending))
     return -1;
 
 
@@ -1022,12 +1026,16 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	    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,
-			       AUTO_BOOLEAN_TRUE,
+			       pending_enabled,
 			       ops,
 			       0, 1, internal_bp, 0);
 	    break;
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 8b19a11b1f6..c78a321d055 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -628,10 +628,82 @@ proc_with_prefix test_bkpt_address {} {
 }
 
 proc_with_prefix test_bkpt_pending {} {
+    global srcfile testfile
+
+    clean_restart ${testfile}
+
     delete_breakpoints
     gdb_breakpoint "nosuchfunction" -allow-pending
     gdb_test "python print (gdb.breakpoints()\[0\].pending)" "True" \
 	"Check pending status of pending breakpoint"
+
+    delete_breakpoints
+    with_test_prefix "allow_pending=True" {
+	gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\",\
+	    line=\"900\", allow_pending=True)" \
+	    [multi_line \
+		 "^No compiled code for line 900 in file \[^\r\n\]+\\." \
+		 "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
+	    "set pending explicit breakpoint by source and missing line"
+	gdb_test_no_output "python assert(bp1.pending)" \
+	    "verify pending explicit breakpoint created for missing line"
+	gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\",\
+	    allow_pending=True)" \
+	    [multi_line \
+		 "Function \"blah\" not defined.*" \
+		 "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
+	    "set pending explicit breakpoint by missing function"
+	gdb_test_no_output "python assert(bp1.pending)" \
+	    "verify pending explicit breakpoint created for missing function"
+	gdb_test "python bp1 = gdb.Breakpoint (\"missing_function\",\
+	    allow_pending=True)" \
+	    [multi_line \
+		 "Function \"missing_function\" not defined.*" \
+		 "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
+	    "set pending breakpoint by missing function"
+	gdb_test_no_output "python assert(bp1.pending)" \
+	    "verify pending breakpoint created for missing function"
+	gdb_test_no_output "python assert(len(gdb.breakpoints()) == 3)" \
+	    "verify expected number of pending breakpoints were created"
+    }
+
+    delete_breakpoints
+    with_test_prefix "allow_pending=False" {
+	gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\",\
+	    line=\"900\", allow_pending=False)" \
+	    [multi_line \
+		 "Python Exception <class 'gdb.error'>: No compiled code for\
+		  line 900 in file \[^\r\n\]+\\." \
+		 "Error occurred in Python: No compiled code for line 900 in\
+		  file \[^\r\n\]+\\."] \
+	    "set invalid explicit breakpoint by source and missing line"
+	gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\",\
+	    allow_pending=False)" \
+	    [multi_line \
+		 "Python Exception <class 'gdb.error'>: Function \"blah\" not\
+		  defined\\." \
+		 "Error occurred in Python: Function \"blah\" not defined\\."] \
+	    "set invalid explicit breakpoint by missing function"
+	gdb_test "python bp1 = gdb.Breakpoint (\"missing_function\",\
+	    allow_pending=False)" \
+	    [multi_line \
+		 "Python Exception <class 'gdb.error'>: Function\
+		  \"missing_function\" not defined\\." \
+		 "Error occurred in Python: Function \"missing_function\" not\
+		  defined\\."] \
+	    "set invalid breakpoint by missing function"
+	gdb_test_no_output "python assert(len(gdb.breakpoints()) == 0)" \
+	    "verify no pending breakpoints were created"
+    }
+
+    # Test allow_pending with a non-bool type.
+    delete_breakpoints
+    gdb_test "python gdb.Breakpoint (\"multiply\", allow_pending=None)" \
+	[multi_line \
+	     "Python Exception <class 'TypeError'>: argument 11 must be bool,\
+	      not None" \
+	     "Error occurred in Python: argument 11 must be bool, not None"] \
+	"allow_pending non_bool_type"
 }
 
 # Helper proc to install an event listener for a given breakpoint
@@ -744,12 +816,14 @@ proc_with_prefix test_bkpt_explicit_loc {} {
 	"set invalid explicit breakpoint by missing source and line"
     gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\", line=\"900\")" \
 	[multi_line \
-	     "^No compiled code for line 900 in file \"$srcfile\"\\." \
+	     "^No compiled code for line 900 in file \[^\r\n\]+\\." \
 	     "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
-	"set invalid explicit breakpoint by source and invalid line"
+	"set pending explicit breakpoint by source and missing line"
     gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\")" \
-	"Function \"blah\" not defined.*" \
-	"set invalid explicit breakpoint by missing function"
+	[multi_line \
+	    "Function \"blah\" not defined.*" \
+	    "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
+	"set pending explicit breakpoint by missing function"
 
     delete_breakpoints
     gdb_test "catch throw" "Catchpoint .* \\(throw\\)"
-- 
2.55.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor
  2026-10-13  7:47 [PATCH] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor Tomáš Hrnčiar
@ 2026-10-13 12:55 ` Eli Zaretskii
  2026-10-14 15:58 ` Tom Tromey
  1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2026-10-13 12:55 UTC (permalink / raw)
  To: Tomáš Hrnčiar; +Cc: gdb-patches

> From: Tomáš Hrnčiar <thrnciar@redhat.com>
> Cc: Tomáš Hrnčiar <thrnciar@redhat.com>
> Date: Tue, 13 Oct 2026 09:47:50 +0200
> 
> Add a new allow_pending parameter to the gdb.Breakpoint constructor.
> Setting the new parameter to False causes GDB to raise an error instead
> of creating a pending breakpoint.  By default this parameter is True,
> which allows pending breakpoints to be created, preserving the existing
> behaviour.
> ---
>  gdb/NEWS                                   |  6 ++
>  gdb/doc/python.texi                        | 17 +++--
>  gdb/python/py-breakpoint.c                 | 16 +++--
>  gdb/testsuite/gdb.python/py-breakpoint.exp | 82 ++++++++++++++++++++--
>  4 files changed, 109 insertions(+), 12 deletions(-)

Thanks, the documentation parts are okay.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor
  2026-10-13  7:47 [PATCH] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor Tomáš Hrnčiar
  2026-10-13 12:55 ` Eli Zaretskii
@ 2026-10-14 15:58 ` Tom Tromey
  2026-10-22 13:54   ` Andrew Burgess
  2026-10-27  8:09   ` [PATCH v2] " Tomáš Hrnčiar
  1 sibling, 2 replies; 8+ messages in thread
From: Tom Tromey @ 2026-10-14 15:58 UTC (permalink / raw)
  To: Tomáš Hrnčiar; +Cc: gdb-patches

>>>>> "Tomáš" == Tomáš Hrnčiar <thrnciar@redhat.com> writes:

Tomáš> Add a new allow_pending parameter to the gdb.Breakpoint constructor.
Tomáš> Setting the new parameter to False causes GDB to raise an error instead
Tomáš> of creating a pending breakpoint.  By default this parameter is True,
Tomáš> which allows pending breakpoints to be created, preserving the existing
Tomáš> behaviour.

Hi.  Thanks for the patch.

This is PR python/12816 so please add this tag to the commit message:

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12816

Tomáš> +  ** The gdb.Breakpoint constructor now takes an optional
Tomáš> +     'allow_pending' argument.  Setting it to False causes GDB to raise
Tomáš> +     an error instead of creating a pending breakpoint.

I wonder about calling the new argument 'pending' instead.  I tend to
think that's a bit nicer since we already match the parameter and
attribute name for 'temporary'.

thanks,
Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor
  2026-10-14 15:58 ` Tom Tromey
@ 2026-10-22 13:54   ` Andrew Burgess
  2026-10-22 17:50     ` Simon Marchi
  2026-10-22 18:35     ` Tom Tromey
  2026-10-27  8:09   ` [PATCH v2] " Tomáš Hrnčiar
  1 sibling, 2 replies; 8+ messages in thread
From: Andrew Burgess @ 2026-10-22 13:54 UTC (permalink / raw)
  To: Tom Tromey, Tomáš Hrnčiar; +Cc: gdb-patches

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Tomáš" == Tomáš Hrnčiar <thrnciar@redhat.com> writes:
>
> Tomáš> Add a new allow_pending parameter to the gdb.Breakpoint constructor.
> Tomáš> Setting the new parameter to False causes GDB to raise an error instead
> Tomáš> of creating a pending breakpoint.  By default this parameter is True,
> Tomáš> which allows pending breakpoints to be created, preserving the existing
> Tomáš> behaviour.
>
> Hi.  Thanks for the patch.
>
> This is PR python/12816 so please add this tag to the commit message:
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12816
>
> Tomáš> +  ** The gdb.Breakpoint constructor now takes an optional
> Tomáš> +     'allow_pending' argument.  Setting it to False causes GDB to raise
> Tomáš> +     an error instead of creating a pending breakpoint.
>
> I wonder about calling the new argument 'pending' instead.  I tend to
> think that's a bit nicer since we already match the parameter and
> attribute name for 'temporary'.

Hi Tom,

Full disclosure: I consulted with Tomáš about this patch before it was
posted.

I suggested that the argument be called allow_pending rather than just
pending as having:

  bp = gdb.Breakpoint("file.c:10", pending=True)

seemed (to me) that this was a request *for* a pending breakpoint, which
clearly isn't what this actually does.  I felt that:

  bp = gdb.Breakpoint("file.c:10", allow_pending=True)

was much clearer about the intent.

Though, having just typed this, I realise that as 'True' is the default,
you'll never actually write that, you'd instead only write:

  bp = gdb.Breakpoint("file.c:10", pending=False)

where reading this as a request *for* a non-pending breakpoint is
actually fine.  So, I guess the case where the name 'pending' is (IMHO)
confusing, is the case that you're less likely to write.

Still, I do prefer the fuller name, but if you'd rather it was changed,
then that's also fine with me, I'm not that tied to it.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor
  2026-10-22 13:54   ` Andrew Burgess
@ 2026-10-22 17:50     ` Simon Marchi
  2026-10-22 18:35     ` Tom Tromey
  1 sibling, 0 replies; 8+ messages in thread
From: Simon Marchi @ 2026-10-22 17:50 UTC (permalink / raw)
  To: Andrew Burgess, Tom Tromey, Tomáš Hrnčiar; +Cc: gdb-patches

On 10/22/26 9:54 AM, Andrew Burgess wrote:
> Tom Tromey <tom@tromey.com> writes:
> 
>>>>>>> "Tomáš" == Tomáš Hrnčiar <thrnciar@redhat.com> writes:
>>
>> Tomáš> Add a new allow_pending parameter to the gdb.Breakpoint constructor.
>> Tomáš> Setting the new parameter to False causes GDB to raise an error instead
>> Tomáš> of creating a pending breakpoint.  By default this parameter is True,
>> Tomáš> which allows pending breakpoints to be created, preserving the existing
>> Tomáš> behaviour.
>>
>> Hi.  Thanks for the patch.
>>
>> This is PR python/12816 so please add this tag to the commit message:
>>
>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12816
>>
>> Tomáš> +  ** The gdb.Breakpoint constructor now takes an optional
>> Tomáš> +     'allow_pending' argument.  Setting it to False causes GDB to raise
>> Tomáš> +     an error instead of creating a pending breakpoint.
>>
>> I wonder about calling the new argument 'pending' instead.  I tend to
>> think that's a bit nicer since we already match the parameter and
>> attribute name for 'temporary'.
> 
> Hi Tom,
> 
> Full disclosure: I consulted with Tomáš about this patch before it was
> posted.
> 
> I suggested that the argument be called allow_pending rather than just
> pending as having:
> 
>   bp = gdb.Breakpoint("file.c:10", pending=True)
> 
> seemed (to me) that this was a request *for* a pending breakpoint, which
> clearly isn't what this actually does.  I felt that:
> 
>   bp = gdb.Breakpoint("file.c:10", allow_pending=True)
> 
> was much clearer about the intent.
> 
> Though, having just typed this, I realise that as 'True' is the default,
> you'll never actually write that, you'd instead only write:
> 
>   bp = gdb.Breakpoint("file.c:10", pending=False)
> 
> where reading this as a request *for* a non-pending breakpoint is
> actually fine.  So, I guess the case where the name 'pending' is (IMHO)
> confusing, is the case that you're less likely to write.
> 
> Still, I do prefer the fuller name, but if you'd rather it was changed,
> then that's also fine with me, I'm not that tied to it.

I like "allow_pending" for the reason you explained.

Simon

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor
  2026-10-22 13:54   ` Andrew Burgess
  2026-10-22 17:50     ` Simon Marchi
@ 2026-10-22 18:35     ` Tom Tromey
  1 sibling, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2026-10-22 18:35 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Tom Tromey, Tomáš Hrnčiar, gdb-patches

>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> I suggested that the argument be called allow_pending rather than just
Andrew> pending as having:
Andrew>   bp = gdb.Breakpoint("file.c:10", pending=True)
Andrew> seemed (to me) that this was a request *for* a pending breakpoint, which
Andrew> clearly isn't what this actually does.  I felt that:

Makes sense, thank you.

Andrew> Still, I do prefer the fuller name, but if you'd rather it was changed,
Andrew> then that's also fine with me, I'm not that tied to it.

It's fine.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor
  2026-10-14 15:58 ` Tom Tromey
  2026-10-22 13:54   ` Andrew Burgess
@ 2026-10-27  8:09   ` Tomáš Hrnčiar
  2026-10-27 14:06     ` Tom Tromey
  1 sibling, 1 reply; 8+ messages in thread
From: Tomáš Hrnčiar @ 2026-10-27  8:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, Tomáš Hrnčiar, Eli Zaretskii

Add a new allow_pending parameter to the gdb.Breakpoint constructor.
Setting the new parameter to False causes GDB to raise an error instead
of creating a pending breakpoint.  By default this parameter is True,
which allows pending breakpoints to be created, preserving the existing
behaviour.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12816
---
 gdb/NEWS                                   |  6 ++
 gdb/doc/python.texi                        | 17 +++--
 gdb/python/py-breakpoint.c                 | 16 +++--
 gdb/testsuite/gdb.python/py-breakpoint.exp | 82 ++++++++++++++++++++--
 4 files changed, 109 insertions(+), 12 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 5d0c4745653..eb637a21724 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -79,6 +79,12 @@ info locals
   The new "-shadowed on|off" option overrides the "set print shadowed"
   setting for a single invocation of the command.
 
+* Python API
+
+  ** The gdb.Breakpoint constructor now takes an optional
+     'allow_pending' argument.  Setting it to False causes GDB to raise
+     an error instead of creating a pending breakpoint.
+
 *** Changes in GDB 18
 
 * Support for the Common Trace Format (CTF) has been removed.  GDB now
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ddb347361f7..0b24698a77f 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{]})
+@defun Breakpoint.__init__ (spec @r{[}, type @r{][}, wp_class @r{][}, internal @r{][}, temporary @r{][}, qualified @r{][}, allow_pending @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}
@@ -6983,16 +6983,25 @@ the function passed in @code{spec} as a fully-qualified name.  It is equivalent
 to @code{break}'s @code{-qualified} flag (@pxref{Linespec Locations} and
 @ref{Explicit Locations}).
 
+The optional @var{allow_pending} argument is a boolean that controls whether
+the created breakpoint can be pending or not
+(@pxref{Set Breaks,,Pending Breakpoints}).  The @var{allow_pending} argument is
+set to @code{True} by default and is only considered when @var{type} is
+@code{gdb.BP_BREAKPOINT} or @code{gdb.BP_HARDWARE_BREAKPOINT}.  If
+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.
+
 @end defun
 
-@defun Breakpoint.__init__ (@r{[} source @r{][}, function @r{][}, label @r{][}, line @r{]}, @r{][} internal @r{][}, temporary @r{][}, qualified @r{]})
+@defun Breakpoint.__init__ (@r{[} source @r{][}, function @r{][}, label @r{][}, line @r{]}, @r{][} internal @r{][}, temporary @r{][}, qualified @r{][}, allow_pending @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
 @var{function}, @var{label} and @var{line}.
 
-@var{internal}, @var{temporary} and @var{qualified} have the same usage as
-explained previously.
+@var{internal}, @var{temporary}, @var{qualified} and @var{allow_pending} have
+the same usage as explained previously.
 @end defun
 
 The available types are represented by constants defined in the @code{gdb}
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index b1615db1be3..7261bd8e25b 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -914,7 +914,8 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
   static const char *keywords[] = { "spec", "type", "wp_class", "internal",
 				    "temporary","source", "function",
-				    "label", "line", "qualified", NULL };
+				    "label", "line", "qualified",
+				    "allow_pending", nullptr };
   const char *spec = NULL;
   enum bptype type = bp_breakpoint;
   int access_type = hw_write;
@@ -928,13 +929,16 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   char *source = NULL;
   char *function = NULL;
   PyObject *qualified = Py_False;
+  PyObject *allow_pending = Py_True;
 
-  if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO!", keywords,
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO!O!",
+					keywords,
 					&spec, &type, &access_type,
 					&internal,
 					&temporary, &source,
 					&function, &label, &lineobj,
-					&PyBool_Type, &qualified))
+					&PyBool_Type, &qualified,
+					&PyBool_Type, &allow_pending))
     return -1;
 
 
@@ -1022,12 +1026,16 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	    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,
-			       AUTO_BOOLEAN_TRUE,
+			       pending_enabled,
 			       ops,
 			       0, 1, internal_bp, 0);
 	    break;
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 8b19a11b1f6..c78a321d055 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -628,10 +628,82 @@ proc_with_prefix test_bkpt_address {} {
 }
 
 proc_with_prefix test_bkpt_pending {} {
+    global srcfile testfile
+
+    clean_restart ${testfile}
+
     delete_breakpoints
     gdb_breakpoint "nosuchfunction" -allow-pending
     gdb_test "python print (gdb.breakpoints()\[0\].pending)" "True" \
 	"Check pending status of pending breakpoint"
+
+    delete_breakpoints
+    with_test_prefix "allow_pending=True" {
+	gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\",\
+	    line=\"900\", allow_pending=True)" \
+	    [multi_line \
+		 "^No compiled code for line 900 in file \[^\r\n\]+\\." \
+		 "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
+	    "set pending explicit breakpoint by source and missing line"
+	gdb_test_no_output "python assert(bp1.pending)" \
+	    "verify pending explicit breakpoint created for missing line"
+	gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\",\
+	    allow_pending=True)" \
+	    [multi_line \
+		 "Function \"blah\" not defined.*" \
+		 "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
+	    "set pending explicit breakpoint by missing function"
+	gdb_test_no_output "python assert(bp1.pending)" \
+	    "verify pending explicit breakpoint created for missing function"
+	gdb_test "python bp1 = gdb.Breakpoint (\"missing_function\",\
+	    allow_pending=True)" \
+	    [multi_line \
+		 "Function \"missing_function\" not defined.*" \
+		 "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
+	    "set pending breakpoint by missing function"
+	gdb_test_no_output "python assert(bp1.pending)" \
+	    "verify pending breakpoint created for missing function"
+	gdb_test_no_output "python assert(len(gdb.breakpoints()) == 3)" \
+	    "verify expected number of pending breakpoints were created"
+    }
+
+    delete_breakpoints
+    with_test_prefix "allow_pending=False" {
+	gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\",\
+	    line=\"900\", allow_pending=False)" \
+	    [multi_line \
+		 "Python Exception <class 'gdb.error'>: No compiled code for\
+		  line 900 in file \[^\r\n\]+\\." \
+		 "Error occurred in Python: No compiled code for line 900 in\
+		  file \[^\r\n\]+\\."] \
+	    "set invalid explicit breakpoint by source and missing line"
+	gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\",\
+	    allow_pending=False)" \
+	    [multi_line \
+		 "Python Exception <class 'gdb.error'>: Function \"blah\" not\
+		  defined\\." \
+		 "Error occurred in Python: Function \"blah\" not defined\\."] \
+	    "set invalid explicit breakpoint by missing function"
+	gdb_test "python bp1 = gdb.Breakpoint (\"missing_function\",\
+	    allow_pending=False)" \
+	    [multi_line \
+		 "Python Exception <class 'gdb.error'>: Function\
+		  \"missing_function\" not defined\\." \
+		 "Error occurred in Python: Function \"missing_function\" not\
+		  defined\\."] \
+	    "set invalid breakpoint by missing function"
+	gdb_test_no_output "python assert(len(gdb.breakpoints()) == 0)" \
+	    "verify no pending breakpoints were created"
+    }
+
+    # Test allow_pending with a non-bool type.
+    delete_breakpoints
+    gdb_test "python gdb.Breakpoint (\"multiply\", allow_pending=None)" \
+	[multi_line \
+	     "Python Exception <class 'TypeError'>: argument 11 must be bool,\
+	      not None" \
+	     "Error occurred in Python: argument 11 must be bool, not None"] \
+	"allow_pending non_bool_type"
 }
 
 # Helper proc to install an event listener for a given breakpoint
@@ -744,12 +816,14 @@ proc_with_prefix test_bkpt_explicit_loc {} {
 	"set invalid explicit breakpoint by missing source and line"
     gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\", line=\"900\")" \
 	[multi_line \
-	     "^No compiled code for line 900 in file \"$srcfile\"\\." \
+	     "^No compiled code for line 900 in file \[^\r\n\]+\\." \
 	     "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
-	"set invalid explicit breakpoint by source and invalid line"
+	"set pending explicit breakpoint by source and missing line"
     gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\")" \
-	"Function \"blah\" not defined.*" \
-	"set invalid explicit breakpoint by missing function"
+	[multi_line \
+	    "Function \"blah\" not defined.*" \
+	    "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \
+	"set pending explicit breakpoint by missing function"
 
     delete_breakpoints
     gdb_test "catch throw" "Catchpoint .* \\(throw\\)"
-- 
2.56.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor
  2026-10-27  8:09   ` [PATCH v2] " Tomáš Hrnčiar
@ 2026-10-27 14:06     ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2026-10-27 14:06 UTC (permalink / raw)
  To: Tomáš Hrnčiar; +Cc: gdb-patches, tom, Eli Zaretskii

>>>>> Tomáš Hrnčiar <thrnciar@redhat.com> writes:

> Add a new allow_pending parameter to the gdb.Breakpoint constructor.
> Setting the new parameter to False causes GDB to raise an error instead
> of creating a pending breakpoint.  By default this parameter is True,
> which allows pending breakpoints to be created, preserving the existing
> behaviour.

> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12816

Ok.  Thank you.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-10-27 14:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-13  7:47 [PATCH] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor Tomáš Hrnčiar
2026-10-13 12:55 ` Eli Zaretskii
2026-10-14 15:58 ` Tom Tromey
2026-10-22 13:54   ` Andrew Burgess
2026-10-22 17:50     ` Simon Marchi
2026-10-22 18:35     ` Tom Tromey
2026-10-27  8:09   ` [PATCH v2] " Tomáš Hrnčiar
2026-10-27 14:06     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox