From patchwork Thu Dec 8 19:18:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 61708 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B28A391B46C for ; Thu, 8 Dec 2022 19:18:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B28A391B46C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670527139; bh=BBahPGvw6eDAcnTax4v5e1NosFK3yH8xvnXYeDI23/Y=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=YUd/QqHyr/Y1GaP8gTTPkQfK8eOEALsZQVrPubMVBQ6JoD98TAkBtMWe1USL9Wi1i g1TRTsIOVYWzCTK0E3tAUP2wbAwiWXOmm7bxgrK80QLdGoYx+6Pl30ALFYXuBQySep XMMPl4tu3Xz+qMrzL1GOpZz+2tVxZTaU1Cn9mcAs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id E9BAB38937F5 for ; Thu, 8 Dec 2022 19:18:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E9BAB38937F5 Received: by mail-io1-xd2d.google.com with SMTP id o189so854083iof.0 for ; Thu, 08 Dec 2022 11:18:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BBahPGvw6eDAcnTax4v5e1NosFK3yH8xvnXYeDI23/Y=; b=M6VdPhadQzM2RVhmbQxqIY4vwYErimBpa+YFFfLkMLIvo3NY+EJdk14N8MJmU5u8F+ 0W501s2j5Xsl4+uIoHteDqXI5dsxFLaSITo97KZUe+OpaLN1MmAmrWD/6pCPqkBlpaTD VVs+UkWQ5QOGTtdu712rtXpPfLpb6pVxCBdKt9Vl8ehSIezaOiN//D12hu8PoIMfAYBp FKkAtUswB5AO6qwQy8rIDgj2do/Nz12uLPfkV6upXkk3Yb+BAXUtIKJ+VP9LLJ99J17v nMfEBI15vesMPQMeDeg4rfaZeojg1Jvp3djmrbsM5mXLa8iiPKT3+GeE1SMzbmPLMkWG 7X3A== X-Gm-Message-State: ANoB5pki2fou8bEdxwb4jeX37BNlPU3PI36uLrqvFvoXeiViRMiYv+Yb EYdeo33Lb4O4UhAEn+Un3CJTRnn2/wJqCQ+z X-Google-Smtp-Source: AA0mqf5lsfBp2dQSh1nInTL+KDn6BUs3cikC1zvHRZa8jMxQ1z5/Pz7cwPQeBTpbUYCxSRZ0Ql0jyQ== X-Received: by 2002:a6b:dc02:0:b0:6a3:2119:e929 with SMTP id s2-20020a6bdc02000000b006a32119e929mr38067346ioc.39.1670527096112; Thu, 08 Dec 2022 11:18:16 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id a16-20020a027350000000b0038a08d5ac32sm8422462jae.31.2022.12.08.11.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 11:18:15 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/3] Let Python breakpoints be created silently Date: Thu, 8 Dec 2022 12:18:04 -0700 Message-Id: <20221208191804.3819129-4-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20221208191804.3819129-1-tromey@adacore.com> References: <20221208191804.3819129-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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 | 30 +++++++++++++++++----- gdb/testsuite/gdb.python/py-breakpoint.exp | 3 ++- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 9cbb2f9f57d..bcbd3b271e8 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -5910,7 +5910,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{][}, 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} @@ -5940,9 +5940,15 @@ 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{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{]}) +@defun Breakpoint.__init__ (@r{[} source @r{][}, function @r{][}, label @r{][}, line @r{]}, @r{][} internal @r{][}, temporary @r{][}, qualified @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 39d9bd5dff6..f942a1c631e 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -903,7 +903,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", + "announce", nullptr }; const char *spec = NULL; enum bptype type = bp_breakpoint; int access_type = hw_write; @@ -918,13 +919,15 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) char *function = NULL; PyObject *qualified_obj = nullptr; int qualified = 0; + PyObject *announce_obj = nullptr; + int announce = 1; - if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO", keywords, + if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOOO", keywords, &spec, &type, &access_type, &internal, &temporary, &source, &function, &label, &lineobj, - &qualified_obj)) + &qualified_obj, &announce_obj)) return -1; @@ -963,6 +966,13 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) return -1; } + if (announce_obj != nullptr) + { + announce = PyObject_IsTrue (announce_obj); + if (announce == -1) + return -1; + } + if (bppy_init_validate_args (spec, source, function, label, line.get (), type) == -1) return -1; @@ -973,9 +983,17 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) try { - bppy_create_breakpoint (type, access_type, temporary_bp, internal_bp, - spec, qualified, source, function, label, - line.get ()); + if (announce) + bppy_create_breakpoint (type, access_type, temporary_bp, internal_bp, + spec, qualified, source, function, + label, line.get ()); + else + execute_fn_to_ui_file (&null_stream, [&] () + { + bppy_create_breakpoint (type, access_type, temporary_bp, + internal_bp, spec, qualified, + source, function, label, line.get ()); + }); } catch (const gdb_exception &except) { diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index e36e87dc291..27f0619443e 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -544,7 +544,8 @@ proc_with_prefix test_bkpt_address {} { proc_with_prefix test_bkpt_pending {} { 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" }