From patchwork Fri Mar 10 18:43:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 66252 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 096D1385B50B for ; Fri, 10 Mar 2023 18:45:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 096D1385B50B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678473948; bh=0PjJR1ftXRF28FvoK573n91jiTjZouDxz3ggrNLSDd0=; 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=nVL9yH3T6kQzytt/Kx7tGxuwApHqLR7k5G1tMZIVTKf12F1gICeJGY5t0VkbwaZqY kllWJd3qmfKpMnJfOmPSZ7oNo4RfM8WIqzefpb2g8S8XGvQGrZIiMNZyH3eeUGXBV5 vKHO8TpdLqKXd789HLdGQu69SRihLLR/0wGntwG4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id AC39D3858023 for ; Fri, 10 Mar 2023 18:43:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC39D3858023 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-427-T1n-rr4sOuOg9Y_S5Sd2Jw-1; Fri, 10 Mar 2023 13:43:33 -0500 X-MC-Unique: T1n-rr4sOuOg9Y_S5Sd2Jw-1 Received: by mail-wr1-f71.google.com with SMTP id 15-20020a056000156f00b002ca79db6d42so1196762wrz.18 for ; Fri, 10 Mar 2023 10:43:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678473812; 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=0PjJR1ftXRF28FvoK573n91jiTjZouDxz3ggrNLSDd0=; b=NGbsx6YB9ruSEeNxq4w4TpKEo/nVS+YgrF2kBwXC9jIMlXMNezu3Uo07w+vKgaoCsP AEPENTaWQ/JnAID3U0uJ3VwHklGmIZPiP4o450TSqnM/CA2L0AT0FqTqMePrSDYxI6Rs feBitRhPga1KjDchHlir6+ULFBifTgrr2Irv04eQXmMzkr/iHRIxF8xKWRLndmI4SH6l 0jBwgZDav4r4B6xDkidz5mWjo6VW41+kT4qJ7rdtwh4VctLq2GrFofZkiqXgDfQIrAIG QMJSRIYDb37CwjMCWOJrW3AFwgvQmiNmNNuaywzav4yED1IMn1SD1+Keb6diQMwR7Fh5 2G9A== X-Gm-Message-State: AO0yUKVOc9f1L+gsKEfljJAICVtSvq1h8baxlvuuDBSN17H7J+VPpFFv uDv+mVSVKEjQ4EysQNo+miH5nd0EWzpa8qmtqrKTH9e+RJdZ+FdOch9QAANdFRHI+GriKzme8Xi s28fnKdoiVBu5wEPf3I3AX0vEIph6R44DVsVAIyXUwDHzlGsBwK1TshYseYor1MC0Qu7sm9lSbE MQx6qz9Q== X-Received: by 2002:a05:600c:3ba6:b0:3e2:1e31:36bc with SMTP id n38-20020a05600c3ba600b003e21e3136bcmr3773925wms.12.1678473812424; Fri, 10 Mar 2023 10:43:32 -0800 (PST) X-Google-Smtp-Source: AK7set+WR5G+3PaWMTtfH3DbuQdMWGoHI96tzv8L167/SXgArIjMRFVEu1fixbaNcyArA/ELA++EJQ== X-Received: by 2002:a05:600c:3ba6:b0:3e2:1e31:36bc with SMTP id n38-20020a05600c3ba600b003e21e3136bcmr3773913wms.12.1678473812099; Fri, 10 Mar 2023 10:43:32 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id z5-20020a5d6545000000b002c56046a3b5sm444805wrv.53.2023.03.10.10.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 10:43:31 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 7/9] gdbarch: remove some unneeded predefault="0" from gdbarch_components.py Date: Fri, 10 Mar 2023 18:43:16 +0000 Message-Id: <939ad1f38ff602ae04f1988e19cb5f1ca824af5a.1678473293.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I noticed that there are a bunch of 'predefault="0"' lines in gdbarch_components.py, and that some (just some, not all) of these are not needed. The gdbarch is already zero initialized, but these lines seem to exists so that we can know when to compare against "0" and when to compare against "NULL". At least, this seems to be useful in some places in the generated code. Specifically, if we remove the predefault="0" line from the max_insn_length component then we end up generating a line like: gdb_assert (gdbarch->max_insn_length != NULL); which doesn't compile as we compare a ULONGEST to NULL. In this commit I remove all the predefault="0" lines that I claim are obviously not needed. These are lines for components that are not Values (i.e. the component holds a function pointer anyway), or for Value components that hold a pointer type, in which case using NULL is fine. The only changes after this commit are some fields that have nullptr as their initial value, and gcore_bfd_target now compares to NULL not 0 in gdbarch_gcore_bfd_target_p, which, given the field is of type 'const char *', seems like an improvement. --- gdb/gdbarch.c | 10 +++++----- gdb/gdbarch_components.py | 22 +--------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 6018c632f91..84f6a481885 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -88,7 +88,7 @@ struct gdbarch gdbarch_ecoff_reg_to_regnum_ftype *ecoff_reg_to_regnum = no_op_reg_to_regnum; gdbarch_sdb_reg_to_regnum_ftype *sdb_reg_to_regnum = no_op_reg_to_regnum; gdbarch_dwarf2_reg_to_regnum_ftype *dwarf2_reg_to_regnum = no_op_reg_to_regnum; - gdbarch_register_name_ftype *register_name = 0; + gdbarch_register_name_ftype *register_name = nullptr; gdbarch_register_type_ftype *register_type = nullptr; gdbarch_dummy_id_ftype *dummy_id = default_dummy_id; int deprecated_fp_regnum = -1; @@ -115,12 +115,12 @@ struct gdbarch gdbarch_return_value_as_value_ftype *return_value_as_value = default_gdbarch_return_value; gdbarch_get_return_buf_addr_ftype *get_return_buf_addr = default_get_return_buf_addr; gdbarch_return_in_first_hidden_param_p_ftype *return_in_first_hidden_param_p = default_return_in_first_hidden_param_p; - gdbarch_skip_prologue_ftype *skip_prologue = 0; + gdbarch_skip_prologue_ftype *skip_prologue = nullptr; gdbarch_skip_main_prologue_ftype *skip_main_prologue = nullptr; gdbarch_skip_entrypoint_ftype *skip_entrypoint = nullptr; - gdbarch_inner_than_ftype *inner_than = 0; + gdbarch_inner_than_ftype *inner_than = nullptr; gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc = default_breakpoint_from_pc; - gdbarch_breakpoint_kind_from_pc_ftype *breakpoint_kind_from_pc = 0; + gdbarch_breakpoint_kind_from_pc_ftype *breakpoint_kind_from_pc = nullptr; gdbarch_sw_breakpoint_from_kind_ftype *sw_breakpoint_from_kind = NULL; gdbarch_breakpoint_kind_from_current_state_ftype *breakpoint_kind_from_current_state = default_breakpoint_kind_from_current_state; gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address = nullptr; @@ -3912,7 +3912,7 @@ bool gdbarch_gcore_bfd_target_p (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); - return gdbarch->gcore_bfd_target != 0; + return gdbarch->gcore_bfd_target != NULL; } const char * diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 2cb700309fd..57bbf8eb7b6 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -340,7 +340,6 @@ and if Dwarf versions < 4 need to be supported. """, type="int", name="dwarf2_addr_size", - predefault="0", postdefault="gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT", ) @@ -567,7 +566,6 @@ should never return nullptr. params=[("int", "regnr")], param_checks=["regnr >= 0", "regnr < gdbarch_num_cooked_regs (gdbarch)"], result_checks=["result != nullptr"], - predefault="0", invalid=True, ) @@ -915,7 +913,6 @@ Method( type="CORE_ADDR", name="skip_prologue", params=[("CORE_ADDR", "ip")], - predefault="0", invalid=True, ) @@ -950,7 +947,6 @@ Function( type="int", name="inner_than", params=[("CORE_ADDR", "lhs"), ("CORE_ADDR", "rhs")], - predefault="0", invalid=True, ) @@ -969,7 +965,6 @@ Return the breakpoint kind for this target based on *PCPTR. type="int", name="breakpoint_kind_from_pc", params=[("CORE_ADDR *", "pcptr")], - predefault="0", invalid=True, ) @@ -1673,7 +1668,6 @@ BFD target to use when generating a core file. type="const char *", name="gcore_bfd_target", predicate=True, - predefault="0", printer="pstring (gdbarch->gcore_bfd_target)", invalid=True, ) @@ -1697,7 +1691,6 @@ significant bit of the pfn for pointers to virtual member functions. """, type="int", name="vbit_in_delta", - predefault="0", invalid=False, ) @@ -1718,8 +1711,8 @@ The maximum length of an instruction on this architecture in bytes. """, type="ULONGEST", name="max_insn_length", - predicate=True, predefault="0", + predicate=True, invalid=True, ) @@ -1991,7 +1984,6 @@ The filename of the XML syscall for this architecture. """, type="const char *", name="xml_syscall_file", - predefault="0", invalid=False, printer="pstring (gdbarch->xml_syscall_file)", ) @@ -2002,7 +1994,6 @@ Information about system calls from this architecture """, type="struct syscalls_info *", name="syscalls_info", - predefault="0", invalid=False, printer="host_address_to_string (gdbarch->syscalls_info)", ) @@ -2020,7 +2011,6 @@ in this case, this prefix would be the character `$'. """, type="const char *const *", name="stap_integer_prefixes", - predefault="0", invalid=False, printer="pstring_list (gdbarch->stap_integer_prefixes)", ) @@ -2032,7 +2022,6 @@ on the architecture's assembly. """, type="const char *const *", name="stap_integer_suffixes", - predefault="0", invalid=False, printer="pstring_list (gdbarch->stap_integer_suffixes)", ) @@ -2049,7 +2038,6 @@ in this case, this prefix would be the character `%'. """, type="const char *const *", name="stap_register_prefixes", - predefault="0", invalid=False, printer="pstring_list (gdbarch->stap_register_prefixes)", ) @@ -2061,7 +2049,6 @@ the architecture's assembly. """, type="const char *const *", name="stap_register_suffixes", - predefault="0", invalid=False, printer="pstring_list (gdbarch->stap_register_suffixes)", ) @@ -2081,7 +2068,6 @@ displacement, e.g., `4(%eax)' on x86. """, type="const char *const *", name="stap_register_indirection_prefixes", - predefault="0", invalid=False, printer="pstring_list (gdbarch->stap_register_indirection_prefixes)", ) @@ -2101,7 +2087,6 @@ displacement, e.g., `4(%eax)' on x86. """, type="const char *const *", name="stap_register_indirection_suffixes", - predefault="0", invalid=False, printer="pstring_list (gdbarch->stap_register_indirection_suffixes)", ) @@ -2117,7 +2102,6 @@ register would be represented as `r10' internally. """, type="const char *", name="stap_gdb_register_prefix", - predefault="0", invalid=False, printer="pstring (gdbarch->stap_gdb_register_prefix)", ) @@ -2128,7 +2112,6 @@ Suffix used to name a register using GDB's nomenclature. """, type="const char *", name="stap_gdb_register_suffix", - predefault="0", invalid=False, printer="pstring (gdbarch->stap_gdb_register_suffix)", ) @@ -2610,7 +2593,6 @@ Functions for allowing a target to modify its disassembler options. """, type="const char *", name="disassembler_options_implicit", - predefault="0", invalid=False, printer="pstring (gdbarch->disassembler_options_implicit)", ) @@ -2618,7 +2600,6 @@ Functions for allowing a target to modify its disassembler options. Value( type="char **", name="disassembler_options", - predefault="0", invalid=False, printer="pstring_ptr (gdbarch->disassembler_options)", ) @@ -2626,7 +2607,6 @@ Value( Value( type="const disasm_options_and_args_t *", name="valid_disassembler_options", - predefault="0", invalid=False, printer="host_address_to_string (gdbarch->valid_disassembler_options)", )