public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 4/9] Reject slicing a packed array
Date: Wed, 30 Sep 2020 14:05:55 -0600	[thread overview]
Message-ID: <20200930200600.1207702-5-tromey@adacore.com> (raw)
In-Reply-To: <20200930200600.1207702-1-tromey@adacore.com>

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.

2020-09-30  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-09-30  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/mod_from_name.exp: Test printing slice.
---
 gdb/ChangeLog                           |  5 +++++
 gdb/ada-lang.c                          | 13 ++++++++++++-
 gdb/testsuite/ChangeLog                 |  4 ++++
 gdb/testsuite/gdb.ada/mod_from_name.exp |  1 +
 4 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index c7eabbef2ae..d851f57414b 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2030,6 +2030,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.  */
 
@@ -10626,7 +10637,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/gdb.ada/mod_from_name.exp b/gdb/testsuite/gdb.ada/mod_from_name.exp
index fec383bb490..43d81e0026f 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"
 }
-- 
2.26.2


  parent reply	other threads:[~2020-09-30 20:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-30 20:05 [PATCH 0/9] Fix most -fgnat-encodings=minimal failures Tom Tromey
2020-09-30 20:05 ` [PATCH 1/9] Avoid crash in ada-lang.c:to_fixed_array_type Tom Tromey
2020-09-30 20:05 ` [PATCH 2/9] Fix decoding of multi-dimensional constrained packed arrays Tom Tromey
2020-09-30 20:05 ` [PATCH 3/9] Synthesize array descriptors with -fgnat-encodings=minimal Tom Tromey
2020-11-06 12:08   ` Luis Machado
2020-11-06 17:55     ` Tom Tromey
2020-09-30 20:05 ` Tom Tromey [this message]
2020-09-30 20:05 ` [PATCH 5/9] Resolve dynamic type in ada_value_struct_elt Tom Tromey
2020-09-30 20:05 ` [PATCH 6/9] Fix bit strides for -fgnat-encodings=minimal Tom Tromey
2020-09-30 20:05 ` [PATCH 7/9] Only use stride for final element type Tom Tromey
2020-09-30 20:05 ` [PATCH 8/9] Use bit stride when taking slice of array Tom Tromey
2020-09-30 20:06 ` [PATCH 9/9] Recognize names of array types Tom Tromey
2020-11-04 15:49 ` [PATCH 0/9] Fix most -fgnat-encodings=minimal failures Tom Tromey
2020-11-04 16:33   ` Tom de Vries
2020-11-04 17:20     ` Tom de Vries
2020-11-04 18:52     ` Tom Tromey
2020-11-04 19:54       ` Tom de Vries
2020-11-16 14:32         ` Tom de Vries
2020-11-16 14:01     ` [PATCH][gdb/testsuite] Fix minimal encodings KPASSes Tom de Vries
2020-11-23 19:10       ` [committed][gdb/testsuite] " Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200930200600.1207702-5-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).