public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix bug in assignment to nested packed structure
@ 2019-05-01 14:17 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2019-05-01 14:17 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4504bbdec57c77b6468838276e62b2137eedfdd5

commit 4504bbdec57c77b6468838276e62b2137eedfdd5
Author: Tom Tromey <tromey@adacore.com>
Date:   Mon Apr 29 09:55:39 2019 -0600

    Fix bug in assignment to nested packed structure
    
    A user at AdaCore found a case where assignment to a nested packed
    structure would fail.  The bug is that ada_value_primitive_field
    doesn't account for the situation where a field is not packed relative
    to its containing structure, but where the structure itself is packed
    in its parent.
    
    gdb/ChangeLog
    2019-05-01  Tom Tromey  <tromey@adacore.com>
    
    	* ada-lang.c (ada_value_primitive_field): Treat more fields as
    	bitfields.
    
    gdb/testsuite/ChangeLog
    2019-05-01  Tom Tromey  <tromey@adacore.com>
    
    	* gdb.ada/packed_array_assign/aggregates.ads (Nested_Packed): New
    	record.
    	(NPR): New variable.
    	* gdb.ada/packed_array_assign.exp: Add nested packed assignment
    	test.

Diff:
---
 gdb/ChangeLog                                            | 5 +++++
 gdb/ada-lang.c                                           | 7 ++++---
 gdb/testsuite/ChangeLog                                  | 8 ++++++++
 gdb/testsuite/gdb.ada/packed_array_assign.exp            | 3 +++
 gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads | 7 +++++++
 5 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1588143..eba0426 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2019-05-01  Tom Tromey  <tromey@adacore.com>
 
+	* ada-lang.c (ada_value_primitive_field): Treat more fields as
+	bitfields.
+
+2019-05-01  Tom Tromey  <tromey@adacore.com>
+
 	* ada-lang.c (ada_value_assign): Correctly compute starting offset
 	for big-endian copies.
 
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index da70a51..1a56663 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -7189,9 +7189,10 @@ ada_value_primitive_field (struct value *arg1, int offset, int fieldno,
   arg_type = ada_check_typedef (arg_type);
   type = TYPE_FIELD_TYPE (arg_type, fieldno);
 
-  /* Handle packed fields.  */
-
-  if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0)
+  /* Handle packed fields.  It might be that the field is not packed
+     relative to its containing structure, but the structure itself is
+     packed; in this case we must take the bit-field path.  */
+  if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0 || value_bitpos (arg1) != 0)
     {
       int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno);
       int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 573aa16..0f96ea2 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,13 @@
 2019-05-01  Tom Tromey  <tromey@adacore.com>
 
+	* gdb.ada/packed_array_assign/aggregates.ads (Nested_Packed): New
+	record.
+	(NPR): New variable.
+	* gdb.ada/packed_array_assign.exp: Add nested packed assignment
+	test.
+
+2019-05-01  Tom Tromey  <tromey@adacore.com>
+
 	* gdb.ada/packed_array_assign.exp: Add packed assignment
 	regression test.
 
diff --git a/gdb/testsuite/gdb.ada/packed_array_assign.exp b/gdb/testsuite/gdb.ada/packed_array_assign.exp
index 8ed2d63..407ea9c 100644
--- a/gdb/testsuite/gdb.ada/packed_array_assign.exp
+++ b/gdb/testsuite/gdb.ada/packed_array_assign.exp
@@ -33,3 +33,6 @@ gdb_test "print pra(1) := pr" \
     " = \\(packed_array_assign_w => 104, packed_array_assign_x => 2, packed_array_assign_y => 3\\)"
 gdb_test "print pra(1)" \
     " = \\(packed_array_assign_w => 104, packed_array_assign_x => 2, packed_array_assign_y => 3\\)"
+
+gdb_test "print npr := (q000 => 3, r000 => (packed_array_assign_x => 6, packed_array_assign_y => 1, packed_array_assign_w => 117))" \
+    " = \\(q000 => 3, r000 => \\(packed_array_assign_w => 117, packed_array_assign_x => 6, packed_array_assign_y => 1\\)\\)"
diff --git a/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads b/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads
index f0d0525..d1b0552 100644
--- a/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads
+++ b/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads
@@ -25,6 +25,12 @@ package Aggregates is
    type Packed_RecArr is array (Integer range <>) of Packed_Rec;
    pragma Pack (Packed_RecArr);
 
+   type Nested_Packed is record
+      Q000 : Int;
+      R000 : Packed_Rec;
+   end record;
+   pragma Pack (Nested_Packed);
+
    procedure Run_Test;
 
 private
@@ -32,4 +38,5 @@ private
                        Packed_Array_Assign_W => 104,
                        Packed_Array_Assign_X  => 2);
    PRA : Packed_RecArr (1 .. 3);
+   NPR : Nested_Packed := (q000 => 3, r000 => (packed_array_assign_x => 6, packed_array_assign_y => 1, packed_array_assign_w => 117));
 end Aggregates;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-01 14:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-01 14:17 [binutils-gdb] Fix bug in assignment to nested packed structure Tom Tromey

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).