From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 89F223829BE0 for ; Fri, 10 Jun 2022 13:08:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 89F223829BE0 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-416-y3LIh8PtPiiaaTyKXszPXw-1; Fri, 10 Jun 2022 09:08:23 -0400 X-MC-Unique: y3LIh8PtPiiaaTyKXszPXw-1 Received: by mail-wm1-f70.google.com with SMTP id j31-20020a05600c1c1f00b0039c481c4664so5539937wms.7 for ; Fri, 10 Jun 2022 06:08:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5xmcz8HbErXhFtqoHFM/oeMuUJkCDS+jz+wtjqR5w/A=; b=b0Mm50fvwHABHz9nvf190FOmEJ+HhpzMgmUZd3706YZ3v12oEqyqICp3fW3Zc2ulR3 w+8Eijb9K1EeY5tyKc7UlEiVPrx2kDBlZmjmiHasxH2Xh3i2uINhwcZARnNc92pbqU/k gO1RN9/hDRgWzVL6D1DSWB1dPSoKTFw7WiyGnBcMmMJAPli8G8ViU12q4Zj8qHFjCxEn kt/4ZxnGHT57gmS9mKrpokYvfqnNv5SfV88iqeUMtuleEv7+UvsPxSEAfurMkB8UNZQb BmP4apD6ULtABYelHyLZkRzTOw/dbFIB7FxQWFeIjYTuDCYM0Ah+wHxf9i0zzzvfye5Z hhbw== X-Gm-Message-State: AOAM533m4t+6C+H2cffudiSFymIdIzVyVDzwZSShXQufQj/VtFLBX67l ECpJhP2KuDqAGUhmVaJvDOykpoaJyk/MzdOTcGS/xBX5GaLA3rHCRvrfJJKqOzmneoUx8R1Xipd 1aonODCehh75hJNOD4hop/QNWWBpH35OuKMQ5ZBy72kVhvEbms/ZdQfDLqyac+1XhhZMS+pTOAg == X-Received: by 2002:a5d:5704:0:b0:218:3fe6:412c with SMTP id a4-20020a5d5704000000b002183fe6412cmr24702373wrv.445.1654866501528; Fri, 10 Jun 2022 06:08:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2vtW7VKp2/JJjK2plBU8IIFmo5oruUbMEusaZo470P+hpzASx/JG8w3rbgeRdpDOA/wtywA== X-Received: by 2002:a5d:5704:0:b0:218:3fe6:412c with SMTP id a4-20020a5d5704000000b002183fe6412cmr24702348wrv.445.1654866501204; Fri, 10 Jun 2022 06:08:21 -0700 (PDT) Received: from localhost (host109-152-215-36.range109-152.btcentralplus.com. [109.152.215.36]) by smtp.gmail.com with ESMTPSA id r124-20020a1c2b82000000b0039466988f6csm3066863wmr.31.2022.06.10.06.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 06:08:20 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Date: Fri, 10 Jun 2022 14:08:09 +0100 Message-Id: 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.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_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Fri, 10 Jun 2022 13:08:25 -0000 This is a small refactor to resolve an issue before it becomes a problem in a later commit. Move the fetching of an arm_gdbarch_tdep into a more inner scope within two functions in arm-tdep.c. The problem with the current code is that the functions in question are used as the callbacks for two set/show parameters. These set/show parameters are available no matter the current architecture, but are really about controlling an ARM architecture specific setting. And so, if I build GDB for all targets on an x86-64/GNU-Linux system, I can still do this: (gdb) show arm fpu (gdb) show arm abi After these calls we end up in show_fp_model and arm_show_abi respectively, where we unconditionally do this: arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); However, the gdbarch_tdep() result will only be a arm_gdbarch_tdep if the current architecture is ARM, otherwise the result will actually be of some other type. This isn't actually a problem, as in both cases the use of tdep is guarded by a later check that the gdbarch architecture is bfd_arch_arm. This commit just moves the call to gdbarch_tdep() after the architecture check. In a later commit gdbarch_tdep() will be able to spot when we are casting the result to the wrong type, and this function will trigger assertion failures if things are not fixed. There should be not user visible changes after this commit. --- gdb/arm-tdep.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 456649afdaa..7f27d4bd6e8 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -9077,14 +9077,16 @@ static void show_fp_model (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { - arm_gdbarch_tdep *tdep - = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); - if (arm_fp_model == ARM_FLOAT_AUTO && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm) - gdb_printf (file, _("\ + { + arm_gdbarch_tdep *tdep + = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); + + gdb_printf (file, _("\ The current ARM floating point model is \"auto\" (currently \"%s\").\n"), - fp_model_strings[tdep->fp_model]); + fp_model_strings[tdep->fp_model]); + } else gdb_printf (file, _("\ The current ARM floating point model is \"%s\".\n"), @@ -9115,14 +9117,16 @@ static void arm_show_abi (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { - arm_gdbarch_tdep *tdep - = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); - if (arm_abi_global == ARM_ABI_AUTO && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm) - gdb_printf (file, _("\ + { + arm_gdbarch_tdep *tdep + = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); + + gdb_printf (file, _("\ The current ARM ABI is \"auto\" (currently \"%s\").\n"), - arm_abi_strings[tdep->arm_abi]); + arm_abi_strings[tdep->arm_abi]); + } else gdb_printf (file, _("The current ARM ABI is \"%s\".\n"), arm_abi_string); -- 2.25.4