From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id A71E2384D16F; Thu, 21 Jul 2022 18:20:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A71E2384D16F Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: d65edaa0bc3f24537ecde3735b1fa041f36f4ab8 X-Git-Newrev: 6dff2a6ffed01ec1db55d06cfdd747bb2d83aeea Message-Id: <20220721182006.A71E2384D16F@sourceware.org> Date: Thu, 21 Jul 2022 18:20:06 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jul 2022 18:20:06 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6dff2a6ffed0= 1ec1db55d06cfdd747bb2d83aeea commit 6dff2a6ffed01ec1db55d06cfdd747bb2d83aeea Author: Andrew Burgess Date: Thu May 19 16:04:26 2022 +0100 gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope =20 This is a small refactor to resolve an issue before it becomes a problem in a later commit. =20 Move the fetching of an arm_gdbarch_tdep into a more inner scope within two functions in arm-tdep.c. =20 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: =20 (gdb) show arm fpu (gdb) show arm abi =20 After these calls we end up in show_fp_model and arm_show_abi respectively, where we unconditionally do this: =20 arm_gdbarch_tdep *tdep =3D (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); =20 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. =20 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. =20 This commit just moves the call to gdbarch_tdep() after the architecture check. =20 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. =20 There should be not user visible changes after this commit. Diff: --- 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 89c2779bbb5..ac49054c074 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -9162,14 +9162,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 - =3D (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); - if (arm_fp_model =3D=3D ARM_FLOAT_AUTO && gdbarch_bfd_arch_info (target_gdbarch ())->arch =3D=3D bfd_arch_a= rm) - gdb_printf (file, _("\ + { + arm_gdbarch_tdep *tdep + =3D (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"), @@ -9200,14 +9202,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 - =3D (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); - if (arm_abi_global =3D=3D ARM_ABI_AUTO && gdbarch_bfd_arch_info (target_gdbarch ())->arch =3D=3D bfd_arch_a= rm) - gdb_printf (file, _("\ + { + arm_gdbarch_tdep *tdep + =3D (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);