binutils-gdb/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp
Jerome Guitton 7150d33cda (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.
2018-01-05 03:14:19 -05:00

56 lines
1.6 KiB
Plaintext

# Copyright 2018 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
load_lib "ada.exp"
standard_ada_testfile enum_with_gap_main
if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
return -1
}
clean_restart ${testfile}
set bp_location [gdb_get_line_number "BREAK" ${testdir}/enum_with_gap_main.adb]
if ![runto "enum_with_gap_main.adb:$bp_location" ] then {
perror "Couldn't run ${testfile}"
return
}
gdb_test "print indexed_by_enum.all" \
" = \\(lit1 => 1, 43, 42, 41\\)"
gdb_test "print s.all" \
" = \"Hello!\""
gdb_test "print indexed_by_enum'length" \
" = 4"
gdb_test "print s'length" \
" = 6"
gdb_test "print indexed_by_enum'first" \
" = lit1"
gdb_test "print s'first" \
" = 1"
gdb_test "print indexed_by_enum'last" \
" = lit4"
gdb_test "print s'last" \
" = 6"
gdb_test "print indexed_by_enum(lit2..lit4)" \
" = \\(lit2 => 43, 42, 41\\)"
gdb_test "print s(2..4)" \
" = \"ell\""