aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2020-11-04 08:49:16 -0700
committerTom Tromey <tromey@adacore.com>2020-11-04 08:49:17 -0700
commitc9a28cbed612a32efca1167d3b4641278a85059e (patch)
tree11f0a148742b08aaea32656df77f8e985171e1ec /gdb
parent575673752cade1772f4a6ba2e38306e5ac9a91f6 (diff)
downloadgdb-c9a28cbed612a32efca1167d3b4641278a85059e.zip
gdb-c9a28cbed612a32efca1167d3b4641278a85059e.tar.gz
gdb-c9a28cbed612a32efca1167d3b4641278a85059e.tar.bz2
Reject slicing a packed array
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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/ada-lang.c13
-rw-r--r--gdb/testsuite/ChangeLog4
-rw-r--r--gdb/testsuite/gdb.ada/mod_from_name.exp1
4 files changed, 22 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 031792d..1b473d5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
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)
(quirk_ada_thick_pointer): New functions.
(read_array_type): Call quirk_ada_thick_pointer.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index f6043b5..bfb46a5 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -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,
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 5190920..386b58e 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,9 @@
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
values.
* gdb.ada/access_to_unbounded_array.exp: Test different
diff --git a/gdb/testsuite/gdb.ada/mod_from_name.exp b/gdb/testsuite/gdb.ada/mod_from_name.exp
index fec383b..43d81e0 100644
--- a/gdb/testsuite/gdb.ada/mod_from_name.exp
+++ b/gdb/testsuite/gdb.ada/mod_from_name.exp
@@ -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"
}