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 7/9] Only use stride for final element type
Date: Wed, 30 Sep 2020 14:05:58 -0600	[thread overview]
Message-ID: <20200930200600.1207702-8-tromey@adacore.com> (raw)
In-Reply-To: <20200930200600.1207702-1-tromey@adacore.com>

A DWARF array type may specify a stride.  Currently, the DWARF reader
applies this stride to every dimension of an array.  However, this
seems incorrect to me -- only the innermost array ought to use the
stride, while outer arrays should compute a stride based on the size
of the inner arrays.  This patch arranges to apply the stride only to
the innermost array type.  This fixes a bug noticed when running some
Ada tests with -fgnat-encodings=minimal.

2020-09-30  Tom Tromey  <tromey@adacore.com>

	* dwarf2/read.c (read_array_type): Only apply stride to innermost
	array.

gdb/testsuite/ChangeLog
2020-09-30  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/enum_idx_packed.exp: Add test.
	* gdb.ada/enum_idx_packed/foo.adb (Multi_Access):
	New variable.
	* gdb.ada/enum_idx_packed/pck.ads (Short)
	(Multi_Dimension, Multi_Dimension_Access): New types.
---
 gdb/ChangeLog                                 |  5 +++++
 gdb/dwarf2/read.c                             | 16 ++++++++++++----
 gdb/testsuite/ChangeLog                       |  8 ++++++++
 gdb/testsuite/gdb.ada/enum_idx_packed.exp     |  3 +++
 gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb |  5 +++++
 gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads |  5 +++++
 6 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e3e68fc1f29..9a94c5b349f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -17089,15 +17089,23 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
       int i = 0;
 
       while (i < range_types.size ())
-	type = create_array_type_with_stride (NULL, type, range_types[i++],
-					      byte_stride_prop, bit_stride);
+	{
+	  type = create_array_type_with_stride (NULL, type, range_types[i++],
+						byte_stride_prop, bit_stride);
+	  bit_stride = 0;
+	  byte_stride_prop = nullptr;
+	}
     }
   else
     {
       size_t ndim = range_types.size ();
       while (ndim-- > 0)
-	type = create_array_type_with_stride (NULL, type, range_types[ndim],
-					      byte_stride_prop, bit_stride);
+	{
+	  type = create_array_type_with_stride (NULL, type, range_types[ndim],
+						byte_stride_prop, bit_stride);
+	  bit_stride = 0;
+	  byte_stride_prop = nullptr;
+	}
     }
 
   /* Understand Dwarf2 support for vector types (like they occur on
diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed.exp b/gdb/testsuite/gdb.ada/enum_idx_packed.exp
index 91859689c4a..2e5a85e76b3 100644
--- a/gdb/testsuite/gdb.ada/enum_idx_packed.exp
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed.exp
@@ -118,4 +118,7 @@ foreach_with_prefix scenario {all minimal} {
 	setup_kfail "minimal encodings" *-*-*
     }
     gdb_test "print multi_multi(2)" " = $matrix"
+
+    gdb_test "print multi_access.all" \
+	" = \\(\\(8, 13, 21, 34, 55\\), \\(1, 1, 2, 3, 5\\)\\)"
 }
diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb b/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb
index e9f30747167..bc82831bb84 100644
--- a/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb
@@ -22,6 +22,10 @@ procedure Foo is
    Small : Small_Table := New_Small_Table (Low => Red, High => Green);
    Multi : Multi_Table := New_Multi_Table (Red, Green, Low, Medium);
    Multi_Multi : Multi_Multi_Table := New_Multi_Multi_Table (1, 2, 1, 7, 1, 10);
+   Multi_Access : Multi_Dimension_Access
+     := new Multi_Dimension'(True => (1, 1, 2, 3, 5),
+                             False => (8, 13, 21, 34, 55));
+
 begin
    Do_Nothing (Full'Address);  -- STOP
    Do_Nothing (Primary'Address);
@@ -29,4 +33,5 @@ begin
    Do_Nothing (Small'Address);
    Do_Nothing (Multi'Address);
    Do_Nothing (Multi_Multi'Address);
+   Do_Nothing (Multi_Access'Address);
 end Foo;
diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads b/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads
index fdfd8bbc4c6..7fe5a9e01d4 100644
--- a/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads
@@ -17,6 +17,7 @@ with System;
 package Pck is
    type Color is (Black, Red, Green, Blue, White);
    type Strength is (None, Low, Medium, High);
+   type Short is new Natural range 0 .. 2 ** 8 - 1;
 
    type Full_Table is array (Color) of Boolean;
    pragma Pack (Full_Table);
@@ -43,5 +44,9 @@ package Pck is
    function New_Multi_Multi_Table (L1, H1, L2, H2, L3, H3: Positive)
       return Multi_Multi_Table;
 
+   type Multi_Dimension is array (Boolean, Color) of Short;
+   pragma Pack (Multi_Dimension);
+   type Multi_Dimension_Access is access all Multi_Dimension;
+
    procedure Do_Nothing (A : System.Address);
 end Pck;
-- 
2.26.2


  parent reply	other threads:[~2020-09-30 20:07 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 ` [PATCH 4/9] Reject slicing a packed array Tom Tromey
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 ` Tom Tromey [this message]
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-8-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).