]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/testsuite/ChangeLog
[Ada] Enhance type printing for arrays with variable-sized elements
authorPierre-Marie de Rodat <derodat@adacore.com>
Tue, 15 Sep 2015 09:56:03 +0000 (11:56 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 15 Sep 2015 21:16:22 +0000 (23:16 +0200)
commitbfca584fae65570fa8ed052f662948763f3ccfa8
treec76b15b2ed62c3e871553d3ba4c0f14a4cafb3ec
parentb326e5870e54f52d52c32388f7f6e07454e2f2c2
[Ada] Enhance type printing for arrays with variable-sized elements

This change is relevant only for standard DWARF (as opposed to the GNAT
encodings extensions): at the time of writing it only makes a difference
with GCC patches that are to be integrated: see the patch series
submission at
<https://gcc.gnu.org/ml/gcc-patches/2015-07/msg01353.html>.

Given the following Ada declarations:

   subtype Small_Int is Natural range 0 .. 100;
   type R_Type (L : Small_Int := 0) is record
      S : String (1 .. L);
   end record;
   type A_Type is array (Natural range <>) of R_Type;

   A : A_Type := (1 => (L => 0, S => ""),
                  2 => (L => 2, S => "ab"));

Before this change, we would get the following GDB session:

    (gdb) ptype a
    type = array (1 .. 2) of foo.r_type <packed: 838-bit elements>

This is wrong: "a" is not a packed array.  This output comes from the
fact that, because R_Type has a dynamic size (with a maximum), the
compiler has to describe in the debugging information the size allocated
for each array element (i.e. the stride, in DWARF parlance: see
DW_AT_byte_stride).  Ada type printing currently assumes that arrays
with a stride are packed, hence the above output.

In practice, GNAT never performs bit-packing for arrays that contain
variable-sized elements.  Leveraging this fact, this patch enhances type
printing so that ptype does not pretend that arrays are packed when they
have a stride and they contain dynamic elements.  After this change, we
get the following expected output:

    (gdb) ptype a
    type = array (1 .. 2) of foo.r_type

gdb/ChangeLog:

* ada-typeprint.c (print_array_type): Do not describe arrays as
packed when they embed dynamic elements.

gdb/testsuite/ChangeLog:

* gdb.ada/array_of_variable_length.exp: New testcase.
* gdb.ada/array_of_variable_length/foo.adb: New file.
* gdb.ada/array_of_variable_length/pck.adb: New file.
* gdb.ada/array_of_variable_length/pck.ads: New file.

Tested on x86_64-linux, no regression.
gdb/ChangeLog
gdb/ada-typeprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/array_of_variable_length.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/array_of_variable_length/foo.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/array_of_variable_length/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/array_of_variable_length/pck.ads [new file with mode: 0644]