From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id HfS9MW5c4GoGtS4AWB0awg (envelope-from ) for ; Tue, 27 Oct 2026 04:10:22 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OLqW1LfG; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B35E1378003; Tue, 27 Oct 2026 04:10:22 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_SBL_CSS autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 41A36378002 for ; Tue, 27 Oct 2026 04:10:21 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 42D464BA23E4 for ; Tue, 27 Oct 2026 08:10:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42D464BA23E4 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OLqW1LfG Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id CB4854BA23CA for ; Tue, 27 Oct 2026 08:09:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB4854BA23CA Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB4854BA23CA Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793088590; cv=none; b=PLTDEB/wFq1K/sGs3KfHnxjUjECK/KueoDxiHuWDcXtFYali8oT0XNgJXBjsuxyCJDT2+qAt2hNVKe1Wxw0pPQFZ8eYXI4mb/gyxO/Oy9oTUGSL5eSCFslE/dMkFQLg9mwSjj1489CTuvn+o7Rq5SeGgpNsHM2sfktFFujvvrJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793088590; c=relaxed/simple; bh=agxteYq80hZkooeM2tFr6CVK8QZRBWbVMraK8v1OCS8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XdClV75qcLduO+EyxqyyTpjse9QsMymZGYul6YMbMf/64/U1fraFhxhz7Iv6OSGp2TSuiZV7r/ji/kItnP8AEClcLsoE9MzbRonRZ/0aaV4cTSo+31CkYlrQg05osHDxZAepnCUxVFDJ0+Y2vIsz6jfiyKxgbCeB9I60i3LTOts= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OLqW1LfG DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB4854BA23CA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793088588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Yc/V3EIlwToXpCQzxLqjxqXcperxj+T3x0VToz1F7M=; b=OLqW1LfGN3eclQ1mg0AUoFNEhznrPQj+mP0tKF5m/Vba6vXh0cUU4o7HXQEeD0Dcw3sG6Q aqgWKHwHXknLPYUaUBp3H3ZwH5AXNoC6iwfQ/UbHk0nUBnrrsrZHzqGQNlIc41z0OW5hEr QNJiYSsAQOL0zubHnZSWqHiSVS4BXlQ= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-b_t8LVxqNcOJ0d__P9GLLw-1; Tue, 27 Oct 2026 04:09:47 -0400 X-MC-Unique: b_t8LVxqNcOJ0d__P9GLLw-1 X-Mimecast-MFC-AGG-ID: b_t8LVxqNcOJ0d__P9GLLw_1793088586 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4a4654add56so24431725e9.2 for ; Tue, 27 Oct 2026 01:09:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793088586; x=1793693386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+Yc/V3EIlwToXpCQzxLqjxqXcperxj+T3x0VToz1F7M=; b=pVx0dAegLze/Rn1guBPkWZOslB3X3Q5dokpC6wrf7EyBModXzCYudkMsmOeVLTLVJg eC1nHIgDqp1PbaWXlIXlfFg+Zm+j0eUUmaDMru5NjQm6he3gK3S04AGnRv9zpsQE77/5 LIrCBQqF3qpzX3nmjz07h192bx5YGb96otmRJDxdjxo/rnwybysB0yz1hEZC8deacFmN dD/rlRE4W1YVKjD3os6ElxGuxIR6eGZDWGnuhjTB5ERSB5n5SYi2SF6xEBMeVqZolcrq HWJKS6kiixQnTPNtC5gD6pftWTIQnmIs+kjHD5YycEv/KNhEIndOB7TO2tvQS+wSVFEi TQWg== X-Gm-Message-State: AFq9FYLbuY/diyX42DGC8grLDetYtqXD8rSiuVHiqrJwh7F6nQB6TVJA nkqk6fN0BjuebUxsO8Jq3pJ1WfmekMHcvCS5kt7N7emkqGOgsL9zScUa/AjrlzJjSvR4j0TArer G7JSY2DYSm37CxXMnGOSegq3cUaYwYMVMBnzzWdaz0rkIAjJoOlDeSln99mHqPzTL6gnBFXlylo Q6k1HdBwTF/kIa3A+C8s9b9jHyZzmrNLq7LxP+Vvnrox2nKNYJQA== X-Gm-Gg: AYBFou3flO1WTxd1yTyBeh4sCM0478/Lsz23dXK1WO8fJGePQIb/mPBvucjS5xEt+pt 6tVPsOMOmykobOgYl80MHNvQ6/uliwwd7exOaCQlgFgdNF8rQ8GCQn17ocZnY0imiXegL85ny5A fH8pKSWRzfWf0sbIEFdqkqLy5eiDojugiziwRApYgMxI17easj7uyCWzhNMFvFlFE5sdeVthel8 yxTuv0v5S9ncTouGAPZc6sZnVE7DZzUWCu8DiPMKoLvwoP371sdK05mTV3mfY+ScLWB52a+dKbU /+obujs/jqu+TEwKxJOyoUA1hSBVRvtdZZ4VZf2nice4srcZ1T22GGCFZmmyGq5HiUaI0y9GPKt wdHvTZ+ArYK3usLhGQQEL2OZ9cMo= X-Received: by 2002:a05:600c:83c7:b0:4a1:fae2:a8ab with SMTP id 5b1f17b1804b1-4a35ac39cedmr166613455e9.3.1793088585499; Tue, 27 Oct 2026 01:09:45 -0700 (PDT) X-Received: by 2002:a05:600c:83c7:b0:4a1:fae2:a8ab with SMTP id 5b1f17b1804b1-4a35ac39cedmr166612725e9.3.1793088584836; Tue, 27 Oct 2026 01:09:44 -0700 (PDT) Received: from redhat.com ([31.192.89.71]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e3ecd354asm20469644f8f.43.2026.10.27.01.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 01:09:43 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hrn=C4=8Diar?= To: gdb-patches@sourceware.org Cc: tom@tromey.com, =?UTF-8?q?Tom=C3=A1=C5=A1=20Hrn=C4=8Diar?= , Eli Zaretskii Subject: [PATCH v2] gdb/python: add allow_pending parameter to gdb.Breakpoint constructor Date: Tue, 27 Oct 2026 09:09:21 +0100 Message-ID: <20261027080921.2944156-1-thrnciar@redhat.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <877bjk46l1.fsf@tromey.com> References: <877bjk46l1.fsf@tromey.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: UqFiTHJOf_BhXlM3jhgnxl1ehK_DF0zdfVEdd9LjMgA_1793088586 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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 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 : 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 : 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 : 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 : 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