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 52117385355F for ; Mon, 13 Jun 2022 16:16:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 52117385355F Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-209-eOk-JBrUOLO5fM6AudxEeg-1; Mon, 13 Jun 2022 12:16:03 -0400 X-MC-Unique: eOk-JBrUOLO5fM6AudxEeg-1 Received: by mail-qt1-f199.google.com with SMTP id u2-20020ac80502000000b002f94701339eso4696718qtg.13 for ; Mon, 13 Jun 2022 09:16:02 -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=BTgGzSDSHJ6bL06YrjzJrQRU/4Jz3JCXdoidYgHD4JUO9wkzIILWJ97LLdAXnesn7c Vj3SwIgdAZ7eo1BKGD13zH4sz3OZa/4WNq0YLqQoj7tBj/1HoTQfrdxqDoVE10XPqvtI Un6gbpqAahQim3Ba6rcy9yLwOvLggCl5wFdEv5q32JiHGtHh3qHVGRB8iQI+GV6mlveb mQd7bocJ+qyFk9O2Vd0UVH+LzAmHtAP5oLBqxpemP23aK+hH1si1j5xR8Kw1YWf7Fjas GCp/Y5uL4EQDuXmwZX9lvv7PdG/LFINC0Sf3VEFRGcPUga32LW3eGTxQ7WUjG2j3f819 SkGw== X-Gm-Message-State: AOAM5320/OaoQhhMMr9nNTX7ttR/lB/vyyfqZCROPByfMLtoIaozPvrf FZfMpOFpyO+oo2aRAKLSPNtebM2Bn0k/D9sBqvBk/duZ/O9w098OCItSOyXX86qDUuAZVkmRtvR 4KMn8zSjD6nSiRAagJYH8eYEBzXWZLPr+kUdFfO9iZ3uGhpPdTk7LBQaHBNRmw8TikTej040eEw == X-Received: by 2002:a05:620a:4251:b0:6a2:e55f:d2df with SMTP id w17-20020a05620a425100b006a2e55fd2dfmr598127qko.598.1655136962226; Mon, 13 Jun 2022 09:16:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrECePRNq89iUtjWr78JArQxp4NxAcsIQBUBRdibXBoXE+DCc3K4BG2lwReWkw5BQ51n216Q== X-Received: by 2002:a05:620a:4251:b0:6a2:e55f:d2df with SMTP id w17-20020a05620a425100b006a2e55fd2dfmr598081qko.598.1655136961699; Mon, 13 Jun 2022 09:16:01 -0700 (PDT) Received: from localhost (host109-154-20-145.range109-154.btcentralplus.com. [109.154.20.145]) by smtp.gmail.com with ESMTPSA id t5-20020a05622a148500b00304e90f66f7sm5260904qtx.70.2022.06.13.09.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 09:16:01 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Luis Machado , Andrew Burgess Subject: [PATCHv3 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Date: Mon, 13 Jun 2022 17:15:49 +0100 Message-Id: <2b2e3af8804553fc9dd21a76fb6ec8df8fb5111f.1655136816.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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.4 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, 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: Mon, 13 Jun 2022 16:16:07 -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