From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x12a.google.com with SMTP id g7so1602217ile.0 for ; Thu, 08 Dec 2022 11:18:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aw8VlCHJXt7xDa0AcGqDhTrK+mg4E5HLC+QqXM2TE6s=; b=Vl3oNAgcq+71dEUIuUlc7p408pMF7MQcao5G7zoiJZHm7Hi89VOEXbarwrPF7lpXoK Y5m34yeXcDRgp2vRHyS2G9EPu+BZLGe4bo1rLlO7hDQ39OlwADTv+3iI0mgdgtGNQFxP N7soqjt105N+m2OE8FoizDxQHPxqGLdyzMVso0hCTBtxZIUmsLTgZu1Ig/W/F3NFJc5V 6E04G3NBEkMFw2n3ImxJz7eXRAuqcwxObq25CgMNuFkYRQR0gw9avfkTUJZ9TFuyI1oR W71bOKkP/tY2EXOu/hZISTjhieqIMbSe0c92Hr+AcxcHYvzrk3RCsp6f/IOMAZ0IYXCh axuA== 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) From: Tom Tromey 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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) { -- 2.34.3