(Ada) Fix Length attribute on array access
authorJerome Guitton <guitton@adacore.com>
Fri, 5 Jan 2018 08:03:59 +0000 (03:03 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Fri, 5 Jan 2018 08:14:19 +0000 (03:14 -0500)
commit7150d33cda60fd543e9d9d68eb58d4e6155fb878
tree7c477193d908664414cd91e9fa3136d9a4f2da50
parentcc0e770c0d00acececc43826f4673896d09b3dff
(Ada) Fix Length attribute on array access

Consider the following variable "Indexed_By_Enum", declared as
an access to an array whose index type is an enumerated type
whose underlying values have "gaps":

   type Enum_With_Gaps is (LIT0, LIT1, LIT2, LIT3, LIT4);
   for Enum_With_Gaps use (LIT0 => 3,
                           LIT1 => 5,
                           LIT2 => 8,
                           LIT3 => 13,
                           LIT4 => 21);
   for Enum_With_Gaps'size use 16;

   type MyWord is range 0 .. 16#FFFF# ;
   for MyWord'Size use 16;

   type AR is array (Enum_With_Gaps range <>) of MyWord;
   type AR_Access is access AR;

   Indexed_By_Enum : AR_Access :=
     new AR'(LIT1 => 1,  LIT2 => 43, LIT3 => 42, LIT4 => 41);

Trying to print the length (number of elements) of this array using
the 'Length attribute does not work:

    (gdb) print indexed_by_enum'length
    'POS only defined on discrete types

The problem occurs while trying to get the array's index type.
It was using TYPE_INDEX_TYPE for that. It does not work for Ada arrays
in general; use ada_index_type instead.

gdb/ChangeLog:

* ada-lang.c (ada_array_length): Use ada_index_type instead of
TYPE_INDEX_TYPE.

gdb/testsuite/ChangeLog:

        * gdb.ada/arr_acc_idx_w_gap: New testcase.

Tested on x86_64-linux.
gdb/ChangeLog
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap.ads [new file with mode: 0644]
gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap_main.adb [new file with mode: 0644]
This page took 0.031309 seconds and 4 git commands to generate.