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) {