]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Reject slicing a packed array
authorTom Tromey <tromey@adacore.com>
Wed, 4 Nov 2020 15:49:16 +0000 (08:49 -0700)
committerTom Tromey <tromey@adacore.com>
Wed, 4 Nov 2020 15:49:17 +0000 (08:49 -0700)
In Ada mode, gdb rejects slicing a packed array.  However, with
-fgnat-encodings=minimal, gdb will instead print incorrect results.
This patch changes gdb to also reject slicing a packed array in this
mode.

FWIW I believe that this rejection is a gdb limitation.  Removing it
looked complicated, though, and meanwhile my main goal for the time
being is to bring the DWARF encodings up to par with Gnat encodings.

gdb/ChangeLog
2020-11-04  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (ada_is_any_packed_array_type): New function.
(ada_evaluate_subexp) <case TERNOP_SLICE>: Use it.

gdb/testsuite/ChangeLog
2020-11-04  Tom Tromey  <tromey@adacore.com>

* gdb.ada/mod_from_name.exp: Test printing slice.

gdb/ChangeLog
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/mod_from_name.exp

index 031792d50b5dfdd81b6fe248626d765d161564f1..1b473d55867a0353d7fe09c66269d2bbbb563d36 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-04  Tom Tromey  <tromey@adacore.com>
+
+       * ada-lang.c (ada_is_any_packed_array_type): New function.
+       (ada_evaluate_subexp) <case TERNOP_SLICE>: Use it.
+
 2020-11-04  Tom Tromey  <tromey@adacore.com>
 
        * dwarf2/read.c (recognize_bound_expression)
index f6043b50aff88897fddcabdc9119008f36de22b8..bfb46a538b96987187797eb5aee7175e9b06167c 100644 (file)
@@ -2012,6 +2012,17 @@ ada_is_unconstrained_packed_array_type (struct type *type)
   return 0;
 }
 
+/* Return true if TYPE is a (Gnat-encoded) constrained packed array
+   type, or if it is an ordinary (non-Gnat-encoded) packed array.  */
+
+static bool
+ada_is_any_packed_array_type (struct type *type)
+{
+  return (ada_is_constrained_packed_array_type (type)
+         || (type->code () == TYPE_CODE_ARRAY
+             && TYPE_FIELD_BITSIZE (type, 0) % 8 != 0));
+}
+
 /* Given that TYPE encodes a packed array type (constrained or unconstrained),
    return the size of its elements in bits.  */
 
@@ -10609,7 +10620,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
          TYPE_TARGET_TYPE (value_type (array)) =
            ada_aligned_type (TYPE_TARGET_TYPE (value_type (array)));
 
-       if (ada_is_constrained_packed_array_type (value_type (array)))
+       if (ada_is_any_packed_array_type (value_type (array)))
          error (_("cannot slice a packed array"));
 
        /* If this is a reference to an array or an array lvalue,
index 5190920812f0804ef6a13277a69ee6663af7d45d..386b58e802061f57a18dbbdceb015b4d0197f076 100644 (file)
@@ -1,3 +1,7 @@
+2020-11-04  Tom Tromey  <tromey@adacore.com>
+
+       * gdb.ada/mod_from_name.exp: Test printing slice.
+
 2020-11-04  Tom Tromey  <tromey@adacore.com>
 
        * gdb.ada/O2_float_param.exp: Test different -fgnat-encodings
index fec383bb4906070c9bc3668ee7a1f536e26eda72..43d81e0026f9df630a4dd1570ff64cda9bd1f42d 100644 (file)
@@ -40,4 +40,5 @@ foreach_with_prefix scenario {all minimal} {
     }
     gdb_test "print xp" \
        "= \\(y => \\(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10\\)\\)"
+    gdb_test "print slice" "cannot slice a packed array"
 }