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.129.124]) by sourceware.org (Postfix) with ESMTPS id C01433959C56 for ; Tue, 31 May 2022 14:30:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C01433959C56 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-497-aBgJD9anMxer2q5yTz0f8Q-1; Tue, 31 May 2022 10:30:57 -0400 X-MC-Unique: aBgJD9anMxer2q5yTz0f8Q-1 Received: by mail-wm1-f72.google.com with SMTP id m31-20020a05600c3b1f00b003973a563605so6107682wms.9 for ; Tue, 31 May 2022 07:30:56 -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=da+xUX/DwA2td5ThjnJphYFR3/QODRkpIctJD/+bQIM=; b=NY3Qxlb9zmP2ZJ9mZULb1Lf1xc7n/JeLhRZBLLavgnuqHRoJF6x2Tvl23DbooD7N5U I5dF5nIKtCimkisumlo+aUhlAe2jEEKjXBChtEMcOsBAk+aeIsPl2OY18r4lShk6+EFG 6mBnDU86oyPYATNG+kpJ70Tf+vWo4C2mlZVbXZLttY4reRkQk4SLPX1KMjgBVOG5haEo H/U3L3v+iNtLGnLUYIhyFettfJARzcju8F8L459bEeGWeoVOLD60Dn85d3Gkl7Iitc+5 YzfvpywO7rr09qI2E72bA1LcYoox8Q0iTRQmkTd0rf2fuqnhU4TtpNcbqIjsP7ceEJvo ViLg== X-Gm-Message-State: AOAM531cQgXNWGiGeA9g2vbIa2fyC2X2uMCbUYuqXP8I2tiYPJX8nMJL Kcpo79BMol7YBJFGy3/in7vfkl/61ooiV6KSZAKtoW/N9THC4oSoTyzBv5qB15kAnCDhDr9BrTd baqGx3yqo4EwHMuTLDKJ4exzbYi7TfaxJYj0v2yAi0Y53G0IAG4iO2uIX5I+1rmWLyNIt2/cVFw == X-Received: by 2002:a5d:6146:0:b0:20d:d42:e954 with SMTP id y6-20020a5d6146000000b0020d0d42e954mr50500049wrt.372.1654007455525; Tue, 31 May 2022 07:30:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh1IuVmFOgUJwQDKsetjs/jK0Vud4yQCGyvSCsUpE6/tgTM7O9sTtLtnp2faFzGIHpyhKQ0w== X-Received: by 2002:a5d:6146:0:b0:20d:d42:e954 with SMTP id y6-20020a5d6146000000b0020d0d42e954mr50500035wrt.372.1654007455320; Tue, 31 May 2022 07:30:55 -0700 (PDT) Received: from localhost (host109-152-215-36.range109-152.btcentralplus.com. [109.152.215.36]) by smtp.gmail.com with ESMTPSA id i12-20020a0560001acc00b002102d4ed579sm7629397wry.39.2022.05.31.07.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 07:30:54 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/5] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Date: Tue, 31 May 2022 15:30:46 +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.6 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: Tue, 31 May 2022 14:31:00 -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 49664093f00..d39342e19c6 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -9015,14 +9015,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"), @@ -9053,14 +9055,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