[Ada] Array bound incorrectly printed for array indexed by enum subrange
authorJoel Brobecker <brobecker@adacore.com>
Thu, 9 Jan 2014 13:30:39 +0000 (17:30 +0400)
committerJoel Brobecker <brobecker@adacore.com>
Mon, 27 Jan 2014 04:13:49 +0000 (08:13 +0400)
Consider the following declarations:

   type Range_Type is (One, Two, Three);
   type Array_Type is array (Range_Type range One .. Two) of Integer;
   A : Array_Type := (1, 2);

Trying to print A can yield:

   (gdb) print a
   $1 = (one => 1, 2)

The bound of the first element should not have been printed, since
"one" is the first enumerate of type Range_Type. Similarly, with
the following declarations:

   type Array2_Type is array (Range_Type range Two .. Three) of Integer;
   A2 : Array2_Type := (2, 3);

GDB is failing to print the bound of the first element of "A2":

   (gdb) print a2
   $2 = (2, 3)

This is because the index type for both types Array_Type and Array2_Type
are subranges (by DWARF definition for arrays), of an anonymous subrange
type. When deciding whether to print the bound of the first element,
we handle subranges, but only up to one level. This patch enhanced
the code to handle any number of subrange levels.

gdb/ChangeLog:

        * ada-valprint.c (print_optional_low_bound): Get index_type's
        target type for as long as it is a TYPE_CODE_RANGE.

No testcase with this patch, but this will be tested via the testcase
of another patch, which uses the DWARF assembler to generate debugging
info for an array indexed by an enum.

gdb/ChangeLog
gdb/ada-valprint.c

index 3f47aff0d8cc7e6b4661541da13cb5c9ed7999c4..a96b3423ab11faff4a1ff6b50edd1f989c27b959 100644 (file)
@@ -1,3 +1,8 @@
+2014-01-27  Joel Brobecker  <brobecker@adacore.com>
+
+       * ada-valprint.c (print_optional_low_bound): Get index_type's
+       target type for as long as it is a TYPE_CODE_RANGE.
+
 2014-01-27  Joel Brobecker  <brobecker@adacore.com>
 
        * procfs.c (procfs_make_note_section): Remove assertion and
index 8f2219fb24e7e79bd5d4a61f042fce5bdad3caca..b7b3a9ccfb65c3efa5d845422c66550201978d15 100644 (file)
@@ -79,7 +79,7 @@ print_optional_low_bound (struct ui_file *stream, struct type *type,
 
   index_type = TYPE_INDEX_TYPE (type);
 
-  if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
+  while (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
     {
       /* We need to know what the base type is, in order to do the
          appropriate check below.  Otherwise, if this is a subrange
This page took 0.027194 seconds and 4 git commands to generate.