[gdb] Improve printing of float formats
authorTom de Vries <tdevries@suse.de>
Wed, 30 Nov 2022 10:37:11 +0000 (11:37 +0100)
committerTom de Vries <tdevries@suse.de>
Wed, 30 Nov 2022 10:37:11 +0000 (11:37 +0100)
Currently, on x86_64, a little endian target, I get:
...
$ gdb -q -batch -ex "maint print architecture" | grep " = floatformat"
gdbarch_dump: bfloat16_format = floatformat_bfloat16_big
gdbarch_dump: double_format = floatformat_ieee_double_big
gdbarch_dump: float_format = floatformat_ieee_single_big
gdbarch_dump: half_format = floatformat_ieee_half_big
gdbarch_dump: long_double_format = floatformat_i387_ext
...
which suggests big endian.

This is due to this bit of code in pformat:
...
    /* Just print out one of them - this is only for diagnostics.  */
    return format[0]->name;
...

Fix this by using gdbarch_byte_order to pick the appropriate index, such that
we have the more accurate:
...
gdbarch_dump: bfloat16_format = floatformat_bfloat16_little
gdbarch_dump: half_format = floatformat_ieee_half_little
gdbarch_dump: float_format = floatformat_ieee_single_little
gdbarch_dump: double_format = floatformat_ieee_double_little
gdbarch_dump: long_double_format = floatformat_i387_ext
...

Tested on x86_64-linux.

gdb/arch-utils.c
gdb/gdbarch-components.py
gdb/gdbarch.c

index 7b84daf046e25bb4ded0da9aeb65e36e7ece0991..60ffdc5e16abe30252880d14ebc569ae30e3d2f1 100644 (file)
@@ -1104,13 +1104,13 @@ show_gdbarch_debug (struct ui_file *file, int from_tty,
 }
 
 static const char *
-pformat (const struct floatformat **format)
+pformat (struct gdbarch *gdbarch, const struct floatformat **format)
 {
   if (format == NULL)
     return "(null)";
-  else
-    /* Just print out one of them - this is only for diagnostics.  */
-    return format[0]->name;
+
+  int format_index = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE ? 1 : 0;
+  return format[format_index]->name;
 }
 
 static const char *
index 9b688998a7bd44b9405f37f7d32d5a1ad23ce0e7..e7230949aad574c8b2e062783b5943c0ce5cc44e 100644 (file)
@@ -201,7 +201,7 @@ Value(
     name="bfloat16_format",
     postdefault="floatformats_bfloat16",
     invalid=True,
-    printer="pformat (gdbarch->bfloat16_format)",
+    printer="pformat (gdbarch, gdbarch->bfloat16_format)",
 )
 
 Value(
@@ -216,7 +216,7 @@ Value(
     name="half_format",
     postdefault="floatformats_ieee_half",
     invalid=True,
-    printer="pformat (gdbarch->half_format)",
+    printer="pformat (gdbarch, gdbarch->half_format)",
 )
 
 Value(
@@ -231,7 +231,7 @@ Value(
     name="float_format",
     postdefault="floatformats_ieee_single",
     invalid=True,
-    printer="pformat (gdbarch->float_format)",
+    printer="pformat (gdbarch, gdbarch->float_format)",
 )
 
 Value(
@@ -246,7 +246,7 @@ Value(
     name="double_format",
     postdefault="floatformats_ieee_double",
     invalid=True,
-    printer="pformat (gdbarch->double_format)",
+    printer="pformat (gdbarch, gdbarch->double_format)",
 )
 
 Value(
@@ -261,7 +261,7 @@ Value(
     name="long_double_format",
     postdefault="floatformats_ieee_double",
     invalid=True,
-    printer="pformat (gdbarch->long_double_format)",
+    printer="pformat (gdbarch, gdbarch->long_double_format)",
 )
 
 Value(
index 3227e945880165bc3784da0deeee3764efc21bc9..ddb8dec1c72d24b68cca5996c8182c5babe05cd9 100644 (file)
@@ -565,31 +565,31 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
                       plongest (gdbarch->bfloat16_bit));
   gdb_printf (file,
                       "gdbarch_dump: bfloat16_format = %s\n",
-                      pformat (gdbarch->bfloat16_format));
+                      pformat (gdbarch, gdbarch->bfloat16_format));
   gdb_printf (file,
                       "gdbarch_dump: half_bit = %s\n",
                       plongest (gdbarch->half_bit));
   gdb_printf (file,
                       "gdbarch_dump: half_format = %s\n",
-                      pformat (gdbarch->half_format));
+                      pformat (gdbarch, gdbarch->half_format));
   gdb_printf (file,
                       "gdbarch_dump: float_bit = %s\n",
                       plongest (gdbarch->float_bit));
   gdb_printf (file,
                       "gdbarch_dump: float_format = %s\n",
-                      pformat (gdbarch->float_format));
+                      pformat (gdbarch, gdbarch->float_format));
   gdb_printf (file,
                       "gdbarch_dump: double_bit = %s\n",
                       plongest (gdbarch->double_bit));
   gdb_printf (file,
                       "gdbarch_dump: double_format = %s\n",
-                      pformat (gdbarch->double_format));
+                      pformat (gdbarch, gdbarch->double_format));
   gdb_printf (file,
                       "gdbarch_dump: long_double_bit = %s\n",
                       plongest (gdbarch->long_double_bit));
   gdb_printf (file,
                       "gdbarch_dump: long_double_format = %s\n",
-                      pformat (gdbarch->long_double_format));
+                      pformat (gdbarch, gdbarch->long_double_format));
   gdb_printf (file,
                       "gdbarch_dump: wchar_bit = %s\n",
                       plongest (gdbarch->wchar_bit));