From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id B9ED2384D170; Thu, 21 Jul 2022 18:20:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9ED2384D170 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/mips: rewrite show_mask_address X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 6dff2a6ffed01ec1db55d06cfdd747bb2d83aeea X-Git-Newrev: 52abb4de08e2ccbfd4dfafd13c200ec7b4db97cc Message-Id: <20220721182011.B9ED2384D170@sourceware.org> Date: Thu, 21 Jul 2022 18:20:11 +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:11 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D52abb4de08e2= ccbfd4dfafd13c200ec7b4db97cc commit 52abb4de08e2ccbfd4dfafd13c200ec7b4db97cc Author: Andrew Burgess Date: Thu May 19 16:13:43 2022 +0100 gdb/mips: rewrite show_mask_address =20 This commit is similar to the previous commit, but in this case GDB is actually relying on undefined behaviour. =20 Consider building GDB for all targets on x86-64/GNU-Linux, then doing this: =20 (gdb) show mips mask-address Zeroing of upper 32 bits of 64-bit addresses is auto. The 32 bit address mask is set automatically. Currently disabled (gdb) =20 The 'show mips mask-address' command ends up in show_mask_address in mips-tdep.c, and this function does this: =20 mips_gdbarch_tdep *tdep =3D (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); =20 Later we might pass TDEP to mips_mask_address_p. However, in my example above, on an x86-64 native target, the current target architecture will be an x86-64 gdbarch, and the tdep field within the gdbarch will be of type i386_gdbarch_tdep, not of type mips_gdbarch_tdep, as a result the cast above was incorrect, and TDEP is not pointing at what it thinks it is. =20 I also think the current output is a little confusing, we appear to have two lines that show the same information, but using different words. =20 The first line comes from calling deprecated_show_value_hack, while the second line is printed directly from show_mask_address. However, both of these lines are printing the same mask_address_var value. I don't think the two lines actually adds any value here. =20 Finally, none of the text in this function is passed through the internationalisation mechanism. =20 It would be nice to remove another use of deprecated_show_value_hack if possible, so this commit does a complete rewrite of show_mask_address. =20 After this commit the output of the above example command, still on my x86-64 native target is: =20 (gdb) show mips mask-address Zeroing of upper 32 bits of 64-bit addresses is "auto" (current arc= hitecture is not MIPS). =20 The 'current architecture is not MIPS' text is only displayed when the current architecture is not MIPS. If the architecture is mips then we get the more commonly seen 'currently "on"' or 'currently "off"', like this: =20 (gdb) set architecture mips The target architecture is set to "mips". (gdb) show mips mask-address Zeroing of upper 32 bits of 64-bit addresses is "auto" (currently "of= f"). (gdb) =20 All the text is passed through the internationalisation mechanism, and we only call gdbarch_tdep when we know the gdbarch architecture is bfd_arch_mips. Diff: --- gdb/mips-tdep.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c index 65aa86dd98d..071319ccc73 100644 --- a/gdb/mips-tdep.c +++ b/gdb/mips-tdep.c @@ -1183,28 +1183,25 @@ static void show_mask_address (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { - mips_gdbarch_tdep *tdep - =3D (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); - - deprecated_show_value_hack (file, from_tty, c, value); - switch (mask_address_var) + const char *additional_text =3D ""; + if (mask_address_var =3D=3D AUTO_BOOLEAN_AUTO) { - case AUTO_BOOLEAN_TRUE: - gdb_printf (file, "The 32 bit mips address mask is enabled\n"); - break; - case AUTO_BOOLEAN_FALSE: - gdb_printf (file, "The 32 bit mips address mask is disabled\n"); - break; - case AUTO_BOOLEAN_AUTO: - gdb_printf - (file, - "The 32 bit address mask is set automatically. Currently %s\n", - mips_mask_address_p (tdep) ? "enabled" : "disabled"); - break; - default: - internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch= ")); - break; + if (gdbarch_bfd_arch_info (target_gdbarch ())->arch !=3D bfd_arch_mi= ps) + additional_text =3D _(" (current architecture is not MIPS)"); + else + { + mips_gdbarch_tdep *tdep + =3D (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ()); + + if (mips_mask_address_p (tdep)) + additional_text =3D _(" (currently \"on\")"); + else + additional_text =3D _(" (currently \"off\")"); + } } + + gdb_printf (file, _("Zeroing of upper 32 bits of 64-bit addresses is \"%= s\"%s.\n"), + value, additional_text); } =20 /* Tell if the program counter value in MEMADDR is in a standard ISA