]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/testsuite/ChangeLog
(Ada) assigning packed array aggregate with variable as component
authorJoel Brobecker <brobecker@adacore.com>
Sat, 8 Sep 2018 21:44:36 +0000 (16:44 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Sat, 8 Sep 2018 21:44:36 +0000 (17:44 -0400)
commit2a62dfa93f1980fd8d5b0651753c550942fa30b6
tree228c39cd8b3c1c5440c2ca23b03dd54cfca55078
parentd1908f2d6b9f161b6a31449e83e1b671acb99620
(Ada) assigning packed array aggregate with variable as component

Consider a variable "PRA" defined as a packed array of packed
records as follow:

   subtype Int is Integer range 0 .. 7;
   type Packed_Rec is record
      X, Y : Int;
      W    : Integer;
   end record;
   pragma Pack (Packed_Rec);
   type Packed_RecArr is array (Integer range <>) of Packed_Rec;
   pragma Pack (Packed_RecArr);

   PRA : Packed_RecArr (1 .. 3);

Consider also a variable "PR", which is a Packed_Rec record,
declared as follow:

   PR : Packed_Rec := (2, 2, 2);

Trying to assign a new value to PRA using an aggregate expression
where one of the components is our variable PR yields the wrong
result on big-endian machines (e.g. on ppc-linux):

    (gdb) p pra := (pr, (2,2,2), (2,2,2))
    $6 = ((x => 1, y => 0, w => 8), [...]

On the other hand, replacing "pr" by "(2,2,2)" does work.

I tracked the issue down to the bit offset we use to extract
the value of "PR" and copy it inside PRA. in value_assign_to_component,
we have:

  if (gdbarch_bits_big_endian (get_type_arch (value_type (container))))
    move_bits ([target buffer], [bit offset in target buffer],
               [source buffer where PR is stored],
               TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits,
               bits, 1);

The issue is with the third-to-last argument, which provides the bit
offset where the value of PR is stored relative to its start address,
and therefore the bit offset relative to the start of the source
buffer passed as the previous argument.

In our case, component is a 38bit packed record whose TYPE_LENGTH
is 5 bytes, so the bit-offset that gets calculated is 2 (bits).
However, that formula only really applies to scalars, whereas
in our case, we have a record (struct). The offset in the non-scalar
case should be zero.

gdb/ChangeLog:

        * ada-lang.c (value_assign_to_component): In the case of
        big-endian targets, extract the bits of the given VAL
        using an src_offset of zero if container is not a scalar.

gdb/testsuite/ChangeLog:

        * gdb.ada/packed_array_assign: New testcase.
gdb/ChangeLog
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/packed_array_assign.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/packed_array_assign/aggregates.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads [new file with mode: 0644]
gdb/testsuite/gdb.ada/packed_array_assign/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/packed_array_assign/pck.ads [new file with mode: 0644]
gdb/testsuite/gdb.ada/packed_array_assign/tester.adb [new file with mode: 0644]