public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/mips: rewrite show_mask_address
@ 2022-07-21 18:20 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2022-07-21 18:20 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=52abb4de08e2ccbfd4dfafd13c200ec7b4db97cc

commit 52abb4de08e2ccbfd4dfafd13c200ec7b4db97cc
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Thu May 19 16:13:43 2022 +0100

    gdb/mips: rewrite show_mask_address
    
    This commit is similar to the previous commit, but in this case GDB is
    actually relying on undefined behaviour.
    
    Consider building GDB for all targets on x86-64/GNU-Linux, then doing
    this:
    
      (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)
    
    The 'show mips mask-address' command ends up in show_mask_address in
    mips-tdep.c, and this function does this:
    
      mips_gdbarch_tdep *tdep
        = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
    
    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.
    
    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.
    
    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.
    
    Finally, none of the text in this function is passed through the
    internationalisation mechanism.
    
    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.
    
    After this commit the output of the above example command, still on my
    x86-64 native target is:
    
        (gdb) show mips mask-address
        Zeroing of upper 32 bits of 64-bit addresses is "auto" (current architecture is not MIPS).
    
    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:
    
      (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 "off").
      (gdb)
    
    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
-    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
-  deprecated_show_value_hack (file, from_tty, c, value);
-  switch (mask_address_var)
+  const char *additional_text = "";
+  if (mask_address_var == 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 != bfd_arch_mips)
+	additional_text = _(" (current architecture is not MIPS)");
+      else
+	{
+	  mips_gdbarch_tdep *tdep
+	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+	  if (mips_mask_address_p (tdep))
+	    additional_text = _(" (currently \"on\")");
+	  else
+	    additional_text = _(" (currently \"off\")");
+	}
     }
+
+  gdb_printf (file, _("Zeroing of upper 32 bits of 64-bit addresses is \"%s\"%s.\n"),
+	      value, additional_text);
 }
 
 /* Tell if the program counter value in MEMADDR is in a standard ISA


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-21 18:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21 18:20 [binutils-gdb] gdb/mips: rewrite show_mask_address Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).