]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
fix printing of DWARF fixed-point type objects with format modifier
authorJoel Brobecker <brobecker@adacore.com>
Sun, 15 Nov 2020 08:14:24 +0000 (03:14 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Sun, 15 Nov 2020 08:14:24 +0000 (03:14 -0500)
Consider a fixed-point type such the scaling factor is 1/16,
as the following Ada code snippet would create:

      type FP1_Type is delta 0.1 range -1.0 .. +1.0;
      FP1_Var : FP1_Type := 0.25;

Printing the value of this variable with a format modifier yields
the wrong value. E.g.:

    (gdb) p /x fp1_var
    $6 = 0x4

Since the real value is 0.25, we therefore expected...

    (gdb) p /x fp1_var
    $6 = 0x0

What happens, in this case, is that the value being printed is
actually the "raw" value of our object, before the scaling factor
gets applied.

This commit fixes the issue by using approach as for float values,
where we convert the value into an integer value, prior to printing,
knowing that the conversion takes the scaling factor into account.

gdb/ChangeLog:

        * printcmd.c (print_scalar_formatted): Add fixed-point type
        handling when options->format is set.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/dw2-fixed-point.exp: Add "print /x" tests.

gdb/ChangeLog
gdb/printcmd.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp

index 16905ac636d0c36bd34c96244fa719bbe5ce7d80..0d322da69c505e7733de3f83e588543612d705a9 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-15  Joel Brobecker  <brobecker@adacore.com>
+
+       * printcmd.c (print_scalar_formatted): Add fixed-point type
+       handling when options->format is set.
+
 2020-11-15  Joel Brobecker  <brobecker@adacore.com>
 
        * ada-valprint.c (ada_value_print_1): Add fixed-point type handling.
index f7186c296afc1a1087f0e8c3cf3826537416f5bc..665142446f4bd2be7eb19f063fbedf29733f80ac 100644 (file)
@@ -421,7 +421,8 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type,
      range case, we want to avoid this, so we store the unpacked value
      here for possible use later.  */
   gdb::optional<LONGEST> val_long;
-  if ((type->code () == TYPE_CODE_FLT
+  if (((type->code () == TYPE_CODE_FLT
+       || is_fixed_point_type (type))
        && (options->format == 'o'
           || options->format == 'x'
           || options->format == 't'
index 0f629bd76b9cebfb9f910ea67c003664b6a08df7..9b9ffe51133bb575a7e80d42ae41beecaa5b00a6 100644 (file)
@@ -1,3 +1,7 @@
+2020-11-15  Joel Brobecker  <brobecker@adacore.com>
+
+       * gdb.dwarf2/dw2-fixed-point.exp: Add "print /x" tests.
+
 2020-11-15  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.ada/fixed_cmp.exp: Force compilation to use -fgnat-encodings=all.
index bf88ffe4f73ef2f47d81d298eeaac5185fa8012b..27c549c602f481b073c5f8eb9cd1f4e2ae4d98c7 100644 (file)
@@ -122,11 +122,23 @@ gdb_test_no_output "set lang ada"
 gdb_test "print pck.fp1_var" \
          " = 0.25"
 
+gdb_test "print /x pck.fp1_var" \
+         " = 0x0"
+
 gdb_test "print pck.fp2_var" \
          " = -0.01"
 
+gdb_test "print /x pck.fp2_var" \
+         " = 0x0"
+
 gdb_test "print pck.fp3_var" \
          " = 0.1"
 
+gdb_test "print /x pck.fp3_var" \
+         " = 0x0"
+
 gdb_test "print pck.fp1_range_var" \
          " = 1"
+
+gdb_test "print /x pck.fp1_range_var" \
+         " = 0x1"