public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix big-endian aggregate assignment in Ada
@ 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=d48e62f4a263a871b7a62793e8000625735bc2f6

commit d48e62f4a263a871b7a62793e8000625735bc2f6
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri Apr 26 10:57:52 2019 -0600

    Fix big-endian aggregate assignment in Ada
    
    A bug internal to AdaCore notes that assigning a non-scalar value to
    an element of a packed array will sometimes fail.
    
    The bug turns out to be that ada_value_assign incorrectly computes the
    starting point for the assignment.  This patch fixes the problem.
    
    gdb/ChangeLog
    2019-05-01  Tom Tromey  <tromey@adacore.com>
    
    	* ada-lang.c (ada_value_assign): Correctly compute starting offset
    	for big-endian copies.
    
    gdb/testsuite/ChangeLog
    2019-05-01  Tom Tromey  <tromey@adacore.com>
    
    	* gdb.ada/packed_array_assign.exp: Add packed assignment
    	regression test.

Diff:
---
 gdb/ChangeLog                                 |  5 +++++
 gdb/ada-lang.c                                | 14 ++++++++------
 gdb/testsuite/ChangeLog                       |  5 +++++
 gdb/testsuite/gdb.ada/packed_array_assign.exp |  5 +++++
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index fdbcb67..1588143 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-01  Tom Tromey  <tromey@adacore.com>
+
+	* ada-lang.c (ada_value_assign): Correctly compute starting offset
+	for big-endian copies.
+
 2019-04-30  Ali Tamur  <tamur@google.com>
 	* gdb/dwarf2read.c (read_3_bytes): New declaration.
 	(read_attribute_value): Added DW_FORM_strx1-4 cases.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 676cd6d..da70a51 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2710,12 +2710,14 @@ ada_value_assign (struct value *toval, struct value *fromval)
       from_size = value_bitsize (fromval);
       if (from_size == 0)
 	from_size = TYPE_LENGTH (value_type (fromval)) * TARGET_CHAR_BIT;
-      if (gdbarch_bits_big_endian (get_type_arch (type)))
-        copy_bitwise (buffer, value_bitpos (toval),
-		      value_contents (fromval), from_size - bits, bits, 1);
-      else
-        copy_bitwise (buffer, value_bitpos (toval),
-		      value_contents (fromval), 0, bits, 0);
+
+      const int is_big_endian = gdbarch_bits_big_endian (get_type_arch (type));
+      ULONGEST from_offset = 0;
+      if (is_big_endian && is_scalar_type (value_type (fromval)))
+	from_offset = from_size - bits;
+      copy_bitwise (buffer, value_bitpos (toval),
+		    value_contents (fromval), from_offset,
+		    bits, is_big_endian);
       write_memory_with_notification (to_addr, buffer, len);
 
       val = value_copy (toval);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 6331e52..573aa16 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-01  Tom Tromey  <tromey@adacore.com>
+
+	* gdb.ada/packed_array_assign.exp: Add packed assignment
+	regression test.
+
 2019-05-01  Tom de Vries  <tdevries@suse.de>
 
 	* boards/cc-with-tweaks.exp: Generate gdb.sh, and pass it in env(GDB).
diff --git a/gdb/testsuite/gdb.ada/packed_array_assign.exp b/gdb/testsuite/gdb.ada/packed_array_assign.exp
index 93910ac..8ed2d63 100644
--- a/gdb/testsuite/gdb.ada/packed_array_assign.exp
+++ b/gdb/testsuite/gdb.ada/packed_array_assign.exp
@@ -28,3 +28,8 @@ runto "aggregates.run_test"
 gdb_test \
     "print pra := ((packed_array_assign_x => 2, packed_array_assign_y => 0, packed_array_assign_w => 17), pr, (packed_array_assign_x => 7, packed_array_assign_y => 1, packed_array_assign_w => 23))" \
     " = \\(\\(packed_array_assign_w => 17, packed_array_assign_x => 2, packed_array_assign_y => 0\\), \\(packed_array_assign_w => 104, packed_array_assign_x => 2, packed_array_assign_y => 3\\), \\(packed_array_assign_w => 23, packed_array_assign_x => 7, packed_array_assign_y => 1\\)\\)"
+
+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\\)"


^ 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 big-endian aggregate assignment in Ada 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).