From patchwork Thu Dec 8 19:18:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 61709 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 D74D73817F8E for ; Thu, 8 Dec 2022 19:19:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D74D73817F8E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670527146; bh=aw8VlCHJXt7xDa0AcGqDhTrK+mg4E5HLC+QqXM2TE6s=; 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=VEEazYvV/Lfc1KgSWJ11fY1R4BpHJa3b3pb5ZVWVjccsUV8ueV2FqlMlAuzt4L2nG Unb4oTess26JvluaORZcA0v7SnLVRAr2Rp99TQ5P/9xKyjAMyNOoRBHcXTAJM22s9V PKie7O3rPfvzymYW5ffovUnxwyh7HcGq1TnUxYs0= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 85BE5387386C for ; Thu, 8 Dec 2022 19:18:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 85BE5387386C Received: by mail-il1-x12a.google.com with SMTP id g7so1602217ile.0 for ; Thu, 08 Dec 2022 11:18:15 -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=aw8VlCHJXt7xDa0AcGqDhTrK+mg4E5HLC+QqXM2TE6s=; b=34meRxoNjqjjWeExAz8+POwOsPgteqbPozzMsOjGs34ntYmaxApfDm8om3IAD2WZE6 0FpuE/ZzmSj/Du7yN65sT7Ou6Kb3816U2LZ8tXj18DoGwpdkmATnGydTtkK+3fTpAgZl pDUD8L/rkZW73veVKp+lUkTL5NJxeXcCxxt/UnQfumYgrQ0/NX9SeWNVzJ6bNWld6bV6 sd0AjJUF4zGwoNkVNwPczqRx/QH8Bm4P6mIUZAl4GoDVmQUG2WLc1VEJYqGCBofWqDkb 0afl9dh52EgrKexDcD+HzwJmxleatTV/n2B7oHfmChB+L7P3gpERihnRUChFPEPTXzk0 lJfA== X-Gm-Message-State: ANoB5pmINyrts4NHaL6amrIlfOb8uucToF0MeLpsupLC+vZvdc6C3TVQ lG9O4Lzv6KKqjLxew6zzVOBY+83gBgFOduoE X-Google-Smtp-Source: AA0mqf4gsnpwVs914JBAe3dptiVgDtB0eZt01oOh2vMbowS5iVNMSHwUYr478E27PvCrVlWDN4ulmw== X-Received: by 2002:a92:ad03:0:b0:303:99b:9df7 with SMTP id w3-20020a92ad03000000b00303099b9df7mr25244405ilh.94.1670527094742; Thu, 08 Dec 2022 11:18:14 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 11:18:14 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] Refactor body of bppy_init Date: Thu, 8 Dec 2022 12:18:02 -0700 Message-Id: <20221208191804.3819129-2-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.1 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" This patch pulls the body of bppy_init out into a separate function. This will simplify a subsequent patch. --- gdb/python/py-breakpoint.c | 161 ++++++++++++++++++++----------------- 1 file changed, 87 insertions(+), 74 deletions(-) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 63b18bd0f92..917fd367d06 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -813,6 +813,90 @@ 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, int temporary_bp, + int internal_bp, const char *spec, + PyObject *qualified, 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 != NULL && PyObject_IsTrue (qualified) + ? symbol_name_match_type::FULL + : symbol_name_match_type::WILD); + + if (spec != NULL) + { + gdb::unique_xmalloc_ptr + 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_loc + (new explicit_location_spec ()); + + explicit_loc->source_filename + = source != nullptr ? xstrdup (source) : nullptr; + explicit_loc->function_name + = function != nullptr ? xstrdup (function) : nullptr; + explicit_loc->label_name + = label != nullptr ? xstrdup (label) : nullptr; + + 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); + + create_breakpoint (gdbpy_enter::get_gdbarch (), + locspec.get (), NULL, -1, NULL, false, + 0, + temporary_bp, type, + 0, + AUTO_BOOLEAN_TRUE, + 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) @@ -881,80 +965,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) try { - switch (type) - { - case bp_breakpoint: - case bp_hardware_breakpoint: - { - location_spec_up locspec; - symbol_name_match_type func_name_match_type - = (qualified != NULL && PyObject_IsTrue (qualified) - ? symbol_name_match_type::FULL - : symbol_name_match_type::WILD); - - if (spec != NULL) - { - gdb::unique_xmalloc_ptr - 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_loc - (new explicit_location_spec ()); - - explicit_loc->source_filename - = source != nullptr ? xstrdup (source) : nullptr; - explicit_loc->function_name - = function != nullptr ? xstrdup (function) : nullptr; - explicit_loc->label_name - = label != nullptr ? xstrdup (label) : nullptr; - - 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); - - create_breakpoint (gdbpy_enter::get_gdbarch (), - locspec.get (), NULL, -1, NULL, false, - 0, - temporary_bp, type, - 0, - AUTO_BOOLEAN_TRUE, - 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, source, function, label, + line.get ()); } catch (const gdb_exception &except) { From patchwork Thu Dec 8 19:18:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 61710 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 4087C3815CA0 for ; Thu, 8 Dec 2022 19:19:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4087C3815CA0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670527152; bh=30g8RtRxs3tl4FW3/ioANBihsSAP+VJJjuioEo9P0fY=; 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=bwcNtYBLtOsry/S2V8O954RqlGSuS7z+kuf6BUkQAXLLIFyugrjB1CQocRcIcI6zX 6PEGg7eK0PNQ5h244gpBY8EC91oImGkJ1zvzXguOTFzw5Z1ZAI2w5QP2970wi1XgUT gbu6BV9AKpJMCBIKnVnVsaa/CFARZ8YiDvL2F99U= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by sourceware.org (Postfix) with ESMTPS id 287583889051 for ; Thu, 8 Dec 2022 19:18:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 287583889051 Received: by mail-io1-xd2f.google.com with SMTP id r72so833257iod.5 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=30g8RtRxs3tl4FW3/ioANBihsSAP+VJJjuioEo9P0fY=; b=sCZI5fMZM2qprQ3ABqcY1PtkYQHcIND+mGSRrtk940cdqjL3NiFKdIJhQV0BsIuw8w SZUEh9ZH/SHM/vsdv65zhraAjghF1d/cwDvX0wxo9dNenJ/IHVPqXr1uWl0P64tepYDW i+Cijbcezqod47LmnmtWDwkpfAk1UuHurKGMCbhICTzTtS/lFzno55+5Ahi9Y9z/uMko Fh0BsX+nMcteyOAY52LC4dOGmo3mOzz6FwrvxRurz9XU5FSkRa/mJihAl2LJcFKkI2vZ rr5TFMNoftdXxUgtQo06ScYTh0TMbDD7pvD+vTK4EBkX/DsYkgb0pmzOVedyG4Y/rALu gCQg== X-Gm-Message-State: ANoB5pkT74BqLignL+gbP3DFEaMxD4em6S3ouuJq1VNzYkMU3+jf/Lrw ywkGPkWn8a8JlTr0iNqAXVnraCKK/U46ClxF X-Google-Smtp-Source: AA0mqf5GYtH5Iwut4VfdWyt2hdUcsYZHrvY4GNyUeCS/QSjZSDHOz0DQgpqSKdQ2e7Q+/qGJx6o2Cw== X-Received: by 2002:a02:b691:0:b0:389:af9:4860 with SMTP id i17-20020a02b691000000b003890af94860mr30181877jam.164.1670527095450; Thu, 08 Dec 2022 11:18:15 -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.14 (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 2/3] Fix latent bug in Python breakpoint creation Date: Thu, 8 Dec 2022 12:18:03 -0700 Message-Id: <20221208191804.3819129-3-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" While working on the previous patch, I noticed that Python breakpoint creation does: - = (qualified != NULL && PyObject_IsTrue (qualified) PyObject_IsTrue can fail, so this is missing an error check. This patch adds the missing check. Note that this could probably be improved by using the "p" format in the call to gdb_PyArg_ParseTupleAndKeywords, but that was added in Python 3.3, and I think gdb still supports 3.2. --- gdb/python/py-breakpoint.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 917fd367d06..39d9bd5dff6 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -818,7 +818,7 @@ bppy_init_validate_args (const char *spec, char *source, static void bppy_create_breakpoint (enum bptype type, int access_type, int temporary_bp, int internal_bp, const char *spec, - PyObject *qualified, const char *source, + int qualified, const char *source, const char *function, const char *label, const char *line) { @@ -829,7 +829,7 @@ bppy_create_breakpoint (enum bptype type, int access_type, int temporary_bp, { location_spec_up locspec; symbol_name_match_type func_name_match_type - = (qualified != NULL && PyObject_IsTrue (qualified) + = (qualified ? symbol_name_match_type::FULL : symbol_name_match_type::WILD); @@ -916,14 +916,15 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) char *label = NULL; char *source = NULL; char *function = NULL; - PyObject * qualified = NULL; + PyObject *qualified_obj = nullptr; + int qualified = 0; if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO", keywords, &spec, &type, &access_type, &internal, &temporary, &source, &function, &label, &lineobj, - &qualified)) + &qualified_obj)) return -1; @@ -955,6 +956,13 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) return -1; } + if (qualified_obj != nullptr) + { + qualified = PyObject_IsTrue (qualified_obj); + if (qualified == -1) + return -1; + } + if (bppy_init_validate_args (spec, source, function, label, line.get (), type) == -1) return -1; 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" }