Fix big-endian aggregate assignment in Ada
authorTom Tromey <tromey@adacore.com>
Fri, 26 Apr 2019 16:57:52 +0000 (10:57 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 1 May 2019 14:09:22 +0000 (08:09 -0600)
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.

gdb/ChangeLog
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/packed_array_assign.exp

index fdbcb67fe78c9a7cbc4d61544c07192465598e4f..1588143646a9e5d16e734b5048023a47fc93e3bf 100644 (file)
@@ -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.
index 676cd6d02ae3b839aab74e080aa20a5beb82024f..da70a514784ec278b28913a94d18122f4f96e2b6 100644 (file)
@@ -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);
index 6331e520eaeeff2a96cd2e6e4ced821d57b116e7..573aa16806c9ef29e5b7d8592832d6cac33a80aa 100644 (file)
@@ -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).
index 93910ac6cb42b4efb71143a92eb4c3471845eedb..8ed2d63ecf362b219e131c168904ccb6fe73ac9e 100644 (file)
@@ -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\\)"
This page took 0.037635 seconds and 4 git commands to generate.