public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [commit/Ada] Ignore __XA types when redundant.
@ 2014-11-14 16:44 Joel Brobecker
  2014-11-19  8:48 ` pushed: " Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2014-11-14 16:44 UTC (permalink / raw)
  To: gdb-patches

Hello,

Consider the following code which declares a variable A2 which
is an array of arrays of integers.

   type Array2_First is array (24 .. 26) of Integer;
   type Array2_Second is array (1 .. 2) of Array2_First;
   A1 : Array1_Second := ((10, 11, 12), (13, 14, 15));

Trying to print the type of that variable currently yields:

    (gdb) ptype A2
    type = array (1 .. 2, 24 .. 26) of integer

This is not correct, as this is the description of a two-dimension
array, which is different from an array of arrays. The expected
output is:

    (gdb) ptype a2
    type = array (1 .. 2) of foo_n926_029.array2_first

GDB's struct type currently handles multi-dimension arrays the same
way arrays of arrays, where each dimension is stored as a sub-array.
The ada-valprint module considers that consecutive array layers
are in fact multi-dimension arrays. For array of arrays, a typedef
layer is introduced between the two arrays, creating a break between
each array type.

In our situation, A2 is a described as a typedef of an array type...

        .uleb128 0x8    # (DIE (0x125) DW_TAG_variable)
        .ascii "a2\0"   # DW_AT_name
        .long   0xfc    # DW_AT_type

        .uleb128 0x4    # (DIE (0xfc) DW_TAG_typedef)
        .long   .LASF5  # DW_AT_name: "foo__array2_second"
        .long   0x107   # DW_AT_type

        .uleb128 0x5    # (DIE (0x107) DW_TAG_array_type)
        .long   .LASF5  # DW_AT_name: "foo__array2_second"
        .long   0xb4    # DW_AT_type
        .uleb128 0x6    # (DIE (0x114) DW_TAG_subrange_type)
        .long   0x11b   # DW_AT_type
        .byte   0x2     # DW_AT_upper_bound
        .byte   0       # end of children of DIE 0x107

... whose element type is, as expected, a typedef to the sub-array
type:

        .uleb128 0x4    # (DIE (0xb4) DW_TAG_typedef)
        .long   .LASF4  # DW_AT_name: "foo__array2_first"
        .long   0xbf    # DW_AT_type

        .uleb128 0x9    # (DIE (0xbf) DW_TAG_array_type)
        .long   .LASF4  # DW_AT_name: "foo__array2_first"
        .long   0xd8    # DW_AT_GNAT_descriptive_type
        .long   0x1c5   # DW_AT_type
        .uleb128 0xa    # (DIE (0xd0) DW_TAG_subrange_type)
        .long   0xf0    # DW_AT_type
        .byte   0x18    # DW_AT_lower_bound
        .byte   0x1a    # DW_AT_upper_bound
        .byte   0       # end of children of DIE 0xbf

The reason why things fails is that, during expression evaluation,
GDB tries to "fix" A1's type. Because the sub-array has a parallel
(descriptive) type (DIE 0xd8), GDB thinks that our array's index
type must be dynamic and therefore needs to be fixed. This in turn
causes the sub-array to be "fixed", which itself results in the
typedef layer to be stripped.

However, looking closer at the parallel type, we see...

        .uleb128 0xb    # (DIE (0xd8) DW_TAG_structure_type)
        .long   .LASF8  # DW_AT_name: "foo__array2_first___XA"
        [...]
        .uleb128 0xc    # (DIE (0xe4) DW_TAG_member)
        .long   .LASF10 # DW_AT_name: "foo__Tarray2_firstD1___XDLU_24__26"

... that all it tells us is that the array bounds are 24 and 26,
which is already correctly provided by the array's DW_TAG_subrange_type
bounds, meaning that this parallel type is just redundant.

Parallel types in general are slowly being removed in favor of
standard DWARF constructs. But in the meantime, this patch kills
two birds with one stone:

  1. It recognizes this situation where the XA type is useless,
     and saves an unnecessary range-type fixing;

  2. It fixes the issue at hand because ignoring the XA type results
     in no type fixing being required, which allows the typedef layer
     to be preserved.

gdb/ChangeLog:

        * ada-lang.c (ada_is_redundant_range_encoding): New function.
        (ada_is_redundant_index_type_desc): New function.
        (to_fixed_array_type): Ignore parallel XA type if redundant.

gdb/testsuite/ChangeLog:

        * gdb.ada/arr_arr: New testcase.

Tested on x86_64-linux. I will push the patch sometime next week...

Thanks,
-- 
Joel

---
 gdb/ada-lang.c                        | 73 +++++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.ada/arr_arr.exp     | 33 ++++++++++++++++
 gdb/testsuite/gdb.ada/arr_arr/foo.adb | 25 ++++++++++++
 gdb/testsuite/gdb.ada/arr_arr/pck.adb | 21 ++++++++++
 gdb/testsuite/gdb.ada/arr_arr/pck.ads | 19 +++++++++
 5 files changed, 171 insertions(+)
 create mode 100644 gdb/testsuite/gdb.ada/arr_arr.exp
 create mode 100644 gdb/testsuite/gdb.ada/arr_arr/foo.adb
 create mode 100644 gdb/testsuite/gdb.ada/arr_arr/pck.adb
 create mode 100644 gdb/testsuite/gdb.ada/arr_arr/pck.ads

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 5b5c22f..b576839 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -8309,6 +8309,68 @@ to_fixed_variant_branch_type (struct type *var_type0, const gdb_byte *valaddr,
     return TYPE_FIELD_TYPE (var_type, which);
 }
 
+/* Assuming RANGE_TYPE is a TYPE_CODE_RANGE, return nonzero if
+   ENCODING_TYPE, a type following the GNAT conventions for discrete
+   type encodings, only carries redundant information.  */
+
+static int
+ada_is_redundant_range_encoding (struct type *range_type,
+				 struct type *encoding_type)
+{
+  struct type *fixed_range_type;
+  char *bounds_str;
+  int n;
+  LONGEST lo, hi;
+
+  gdb_assert (TYPE_CODE (range_type) == TYPE_CODE_RANGE);
+
+  if (is_dynamic_type (range_type))
+    return 0;
+
+  if (TYPE_NAME (encoding_type) == NULL)
+    return 0;
+
+  bounds_str = strstr (TYPE_NAME (encoding_type), "___XDLU_");
+  if (bounds_str == NULL)
+    return 0;
+
+  n = 8; /* Skip "___XDLU_".  */
+  if (!ada_scan_number (bounds_str, n, &lo, &n))
+    return 0;
+  if (TYPE_LOW_BOUND (range_type) != lo)
+    return 0;
+
+  n += 2; /* Skip the "__" separator between the two bounds.  */
+  if (!ada_scan_number (bounds_str, n, &hi, &n))
+    return 0;
+  if (TYPE_HIGH_BOUND (range_type) != hi)
+    return 0;
+
+  return 1;
+}
+
+/* Given the array type ARRAY_TYPE, return nonzero if DESC_TYPE,
+   a type following the GNAT encoding for describing array type
+   indices, only carries redundant information.  */
+
+static int
+ada_is_redundant_index_type_desc (struct type *array_type,
+				  struct type *desc_type)
+{
+  struct type *this_layer = check_typedef (array_type);
+  int i;
+
+  for (i = 0; i < TYPE_NFIELDS (desc_type); i++)
+    {
+      if (!ada_is_redundant_range_encoding (TYPE_INDEX_TYPE (this_layer),
+					    TYPE_FIELD_TYPE (desc_type, i)))
+	return 0;
+      this_layer = check_typedef (TYPE_TARGET_TYPE (this_layer));
+    }
+
+  return 1;
+}
+
 /* Assuming that TYPE0 is an array type describing the type of a value
    at ADDR, and that DVAL describes a record containing any
    discriminants used in TYPE0, returns a type for the value that
@@ -8335,6 +8397,17 @@ to_fixed_array_type (struct type *type0, struct value *dval,
 
   index_type_desc = ada_find_parallel_type (type0, "___XA");
   ada_fixup_array_indexes_type (index_type_desc);
+  if (index_type_desc != NULL
+      && ada_is_redundant_index_type_desc (type0, index_type_desc))
+    {
+      /* Ignore this ___XA parallel type, as it does not bring any
+	 useful information.  This allows us to avoid creating fixed
+	 versions of the array's index types, which would be identical
+	 to the original ones.  This, in turn, can also help avoid
+	 the creation of fixed versions of the array itself.  */
+      index_type_desc = NULL;
+    }
+
   if (index_type_desc == NULL)
     {
       struct type *elt_type0 = ada_check_typedef (TYPE_TARGET_TYPE (type0));
diff --git a/gdb/testsuite/gdb.ada/arr_arr.exp b/gdb/testsuite/gdb.ada/arr_arr.exp
new file mode 100644
index 0000000..2be18e0
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/arr_arr.exp
@@ -0,0 +1,33 @@
+# Copyright 2014 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 foo
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
+  return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
+if ![runto "foo.adb:$bp_location" ] then {
+  perror "Couldn't run ${testfile}"
+  return
+}
+
+gdb_test "ptype a2" \
+         " = array \\(1 \\.\\. 2\\) of foo.array2_first"
diff --git a/gdb/testsuite/gdb.ada/arr_arr/foo.adb b/gdb/testsuite/gdb.ada/arr_arr/foo.adb
new file mode 100644
index 0000000..b4af104
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/arr_arr/foo.adb
@@ -0,0 +1,25 @@
+--  Copyright 2014 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/>.
+
+with System;
+with Pck; use Pck;
+
+procedure Foo is
+   type Array2_First is array (24 .. 26) of Integer;
+   type Array2_Second is array (1 .. 2) of Array2_First;
+   A2 : Array2_Second := ((10, 11, 12), (13, 14, 15));
+begin
+   Do_Nothing (A2'Address);  --  START
+end Foo;
diff --git a/gdb/testsuite/gdb.ada/arr_arr/pck.adb b/gdb/testsuite/gdb.ada/arr_arr/pck.adb
new file mode 100644
index 0000000..2b31332
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/arr_arr/pck.adb
@@ -0,0 +1,21 @@
+--  Copyright 2014 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/>.
+
+package body Pck is
+   procedure Do_Nothing (A : System.Address) is
+   begin
+      null;
+   end Do_Nothing;
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/arr_arr/pck.ads b/gdb/testsuite/gdb.ada/arr_arr/pck.ads
new file mode 100644
index 0000000..100d7d5
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/arr_arr/pck.ads
@@ -0,0 +1,19 @@
+--  Copyright 2014 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/>.
+
+with System;
+package Pck is
+   procedure Do_Nothing (A : System.Address);
+end Pck;
-- 
1.9.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* pushed: [commit/Ada] Ignore __XA types when redundant.
  2014-11-14 16:44 [commit/Ada] Ignore __XA types when redundant Joel Brobecker
@ 2014-11-19  8:48 ` Joel Brobecker
  2014-11-19 18:19   ` Regression for gdb.ada/arrayidx.exp [Re: pushed: [commit/Ada] Ignore __XA types when redundant.] Jan Kratochvil
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2014-11-19  8:48 UTC (permalink / raw)
  To: gdb-patches

> gdb/ChangeLog:
> 
>         * ada-lang.c (ada_is_redundant_range_encoding): New function.
>         (ada_is_redundant_index_type_desc): New function.
>         (to_fixed_array_type): Ignore parallel XA type if redundant.
> 
> gdb/testsuite/ChangeLog:
> 
>         * gdb.ada/arr_arr: New testcase.

Pushed!

Thank you,
-- 
Joel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Regression for gdb.ada/arrayidx.exp  [Re: pushed: [commit/Ada] Ignore __XA types when redundant.]
  2014-11-19  8:48 ` pushed: " Joel Brobecker
@ 2014-11-19 18:19   ` Jan Kratochvil
  2014-11-20  4:10     ` Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2014-11-19 18:19 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Wed, 19 Nov 2014 09:48:42 +0100, Joel Brobecker wrote:
> > gdb/ChangeLog:
> > 
> >         * ada-lang.c (ada_is_redundant_range_encoding): New function.
> >         (ada_is_redundant_index_type_desc): New function.
> >         (to_fixed_array_type): Ignore parallel XA type if redundant.
> > 
> > gdb/testsuite/ChangeLog:
> > 
> >         * gdb.ada/arr_arr: New testcase.
> 
> Pushed!

With gcc-gnat-4.9.2-1.fc21.x86_64 I see
-PASS: gdb.ada/arrayidx.exp: print r_two_three, indexes off
+FAIL: gdb.ada/arrayidx.exp: print r_two_three, indexes off
-PASS: gdb.ada/arrayidx.exp: print r_two_three
+FAIL: gdb.ada/arrayidx.exp: print r_two_three

8908fca5772fcff9f7766158ba2aa59f5a2b1f68 is the first bad commit
commit 8908fca5772fcff9f7766158ba2aa59f5a2b1f68
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Sat Sep 27 09:09:34 2014 -0700

    [Ada] Ignore __XA types when redundant.


Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Regression for gdb.ada/arrayidx.exp  [Re: pushed: [commit/Ada] Ignore __XA types when redundant.]
  2014-11-19 18:19   ` Regression for gdb.ada/arrayidx.exp [Re: pushed: [commit/Ada] Ignore __XA types when redundant.] Jan Kratochvil
@ 2014-11-20  4:10     ` Joel Brobecker
  2014-11-20  6:45       ` Jan Kratochvil
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2014-11-20  4:10 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

> With gcc-gnat-4.9.2-1.fc21.x86_64 I see
> -PASS: gdb.ada/arrayidx.exp: print r_two_three, indexes off
> +FAIL: gdb.ada/arrayidx.exp: print r_two_three, indexes off
> -PASS: gdb.ada/arrayidx.exp: print r_two_three
> +FAIL: gdb.ada/arrayidx.exp: print r_two_three
> 
> 8908fca5772fcff9f7766158ba2aa59f5a2b1f68 is the first bad commit
> commit 8908fca5772fcff9f7766158ba2aa59f5a2b1f68
> Author: Joel Brobecker <brobecker@adacore.com>
> Date:   Sat Sep 27 09:09:34 2014 -0700
> 
>     [Ada] Ignore __XA types when redundant.

Thanks for letting me know, but I would need a little more info
about it, since it passes for me (I wouldn't have pushed the patch
otherwise).

Can you send me gdb.ada/arrayidx/ directory (from the build area)?

-- 
Joel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Regression for gdb.ada/arrayidx.exp  [Re: pushed: [commit/Ada] Ignore __XA types when redundant.]
  2014-11-20  4:10     ` Joel Brobecker
@ 2014-11-20  6:45       ` Jan Kratochvil
  2014-11-20  9:47         ` should be fixed: " Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2014-11-20  6:45 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Thu, 20 Nov 2014 05:10:10 +0100, Joel Brobecker wrote:
> > With gcc-gnat-4.9.2-1.fc21.x86_64 I see
> > -PASS: gdb.ada/arrayidx.exp: print r_two_three, indexes off
> > +FAIL: gdb.ada/arrayidx.exp: print r_two_three, indexes off
> > -PASS: gdb.ada/arrayidx.exp: print r_two_three
> > +FAIL: gdb.ada/arrayidx.exp: print r_two_three
> > 
> > 8908fca5772fcff9f7766158ba2aa59f5a2b1f68 is the first bad commit
> > commit 8908fca5772fcff9f7766158ba2aa59f5a2b1f68
> > Author: Joel Brobecker <brobecker@adacore.com>
> > Date:   Sat Sep 27 09:09:34 2014 -0700
> > 
> >     [Ada] Ignore __XA types when redundant.
> 
> Thanks for letting me know, but I would need a little more info
> about it, since it passes for me (I wouldn't have pushed the patch
> otherwise).
> 
> Can you send me gdb.ada/arrayidx/ directory (from the build area)?

http://people.redhat.com/jkratoch/arrayidx.tar.xz


Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* should be fixed: Regression for gdb.ada/arrayidx.exp  [Re: pushed: [commit/Ada] Ignore __XA types when redundant.]
  2014-11-20  6:45       ` Jan Kratochvil
@ 2014-11-20  9:47         ` Joel Brobecker
  2014-11-20  9:57           ` Jan Kratochvil
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2014-11-20  9:47 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 673 bytes --]

> > > With gcc-gnat-4.9.2-1.fc21.x86_64 I see
> > > -PASS: gdb.ada/arrayidx.exp: print r_two_three, indexes off
> > > +FAIL: gdb.ada/arrayidx.exp: print r_two_three, indexes off
> > > -PASS: gdb.ada/arrayidx.exp: print r_two_three
> > > +FAIL: gdb.ada/arrayidx.exp: print r_two_three
[...]
> http://people.redhat.com/jkratoch/arrayidx.tar.xz

Thanks. This allowed me to understand the source of the problem,
and to push a fix (attached).

gdb/ChangeLog:

        * ada-lang.c (ada_is_redundant_range_encoding): Return 0
        if the TYPE_CODE of range_type's base type does not match
        the TYPE_CODE of encoding_type's base type.

Tested on x86_64-linux.

-- 
Joel

[-- Attachment #2: 0001-Ada-XA-type-is-not-redundant-if-the-ranges-subtypes-.patch --]
[-- Type: text/x-diff, Size: 4538 bytes --]

From 005e2509a167c05719df3a3edd966865110a5052 Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Thu, 20 Nov 2014 12:10:41 +0400
Subject: [PATCH] [Ada] XA type is not redundant if the ranges' subtypes do not
 match

Jan noticed that gdb.ada/arrayidx.exp regressed after I applied
the following patch:

    commit 8908fca5772fcff9f7766158ba2aa59f5a2b1f68
    Author: Joel Brobecker <brobecker@adacore.com>
    Date:   Sat Sep 27 09:09:34 2014 -0700
    Subject: [Ada] Ignore __XA types when redundant.

What happens is that we're trying to print the value of
r_two_three, which is defined as follow:

   type Index is (One, Two, Three);
   type RTable is array (Index range Two .. Three) of Integer;
   R_Two_Three : RTable := (2, 3);

The expected output is:

    (gdb) p r_two_three
    $1 = (two => 2, 3)

But after the patch above was applied, with the program program
compiled using gcc-gnat-4.9.2-1.fc21.x86_64 (x86_64-linux),
the output becomes:

    (gdb) p r_two_three
    $1 = (2, 3)

(the name of the first bound is missing). The problem comes from
the fact that the compiler described the array's index type as
a plain base type, instead of as a subrange of the enumerated type.
More particularly, this is what gcc-gnat-4.9.2-1.fc21.x86_64
generated:

 <3><7ce>: Abbrev Number: 9 (DW_TAG_array_type)
    <7cf>   DW_AT_name        : (indirect string, offset: 0xc13): p__rtable
    [...]
    <7d7>   DW_AT_GNAT_descriptive_type: <0x98a>
    [...]
 <4><7df>: Abbrev Number: 8 (DW_TAG_subrange_type)
    <7e0>   DW_AT_type        : <0xa79>

where DIE 0xa79 is:

 <1><a79>: Abbrev Number: 2 (DW_TAG_base_type)
    <a7a>   DW_AT_byte_size   : 8
    <a7b>   DW_AT_encoding    : 7       (unsigned)
    <a7c>   DW_AT_name        : (indirect string, offset: 0xfc): sizetype

The actual array subrange type can be found in the array's
parallel XA type (the DW_AT_GNAT_descriptive_type).

The recent commit correctly found that that bounds taken from
the descriptive type are the same as bounds of our array's index
type. But it failed to notice that ignoring this descriptive
type would make us lose the actual array index type, making us
think that we're printing an array indexed by integers.

I hadn't seen that problem, because the compiler I used produced
debugging info where the array's index type is correctly described:

 <3><79f>: Abbrev Number: 10 (DW_TAG_array_type)
    <7a0>   DW_AT_name        : (indirect string, offset: 0xb3d): p__rtable
    [...]
 <4><7b0>: Abbrev Number: 8 (DW_TAG_subrange_type)
    <7b1>   DW_AT_type        : <0x9b2>
    <7b5>   DW_AT_upper_bound : 2

... where DIE 0x9b2 leads us to ...

 <3><9b2>: Abbrev Number: 9 (DW_TAG_subrange_type)
    [...]
    <9b8>   DW_AT_type        : <0x962>

 <2><962>: Abbrev Number: 22 (DW_TAG_enumeration_type)
    <963>   DW_AT_name        : (indirect string, offset: 0xb34): p__index
    [...]

This patch fixes the issue by also making sure that the subtype
of the original range type does match the subtype found in the
descriptive type.

gdb/ChangeLog:

        * ada-lang.c (ada_is_redundant_range_encoding): Return 0
        if the TYPE_CODE of range_type's base type does not match
        the TYPE_CODE of encoding_type's base type.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/ada-lang.c | 11 +++++++++++
 2 files changed, 17 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5f58e6c..75b739e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-20  Joel Brobecker  <brobecker@adacore.com>
+
+	* ada-lang.c (ada_is_redundant_range_encoding): Return 0
+	if the TYPE_CODE of range_type's base type does not match
+	the TYPE_CODE of encoding_type's base type.
+
 2014-11-19  Joel Brobecker  <brobecker@adacore.com>
 
 	* ada-lang.c (ada_unqualified_name): Return DECODED_NAME if
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e46ad8e..122aaf4 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -8334,6 +8334,17 @@ ada_is_redundant_range_encoding (struct type *range_type,
 
   gdb_assert (TYPE_CODE (range_type) == TYPE_CODE_RANGE);
 
+  if (TYPE_CODE (get_base_type (range_type))
+      != TYPE_CODE (get_base_type (encoding_type)))
+    {
+      /* The compiler probably used a simple base type to describe
+	 the range type instead of the range's actual base type,
+	 expecting us to get the real base type from the encoding
+	 anyway.  In this situation, the encoding cannot be ignored
+	 as redundant.  */
+      return 0;
+    }
+
   if (is_dynamic_type (range_type))
     return 0;
 
-- 
1.9.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: should be fixed: Regression for gdb.ada/arrayidx.exp  [Re: pushed: [commit/Ada] Ignore __XA types when redundant.]
  2014-11-20  9:47         ` should be fixed: " Joel Brobecker
@ 2014-11-20  9:57           ` Jan Kratochvil
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Kratochvil @ 2014-11-20  9:57 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Thu, 20 Nov 2014 10:46:56 +0100, Joel Brobecker wrote:
> Thanks. This allowed me to understand the source of the problem,
> and to push a fix (attached).
> 
> gdb/ChangeLog:
> 
>         * ada-lang.c (ada_is_redundant_range_encoding): Return 0
>         if the TYPE_CODE of range_type's base type does not match
>         the TYPE_CODE of encoding_type's base type.

Confirming 005e2509a167c05719df3a3edd966865110a5052 PASSes now on F-21.x86_64.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-11-20  9:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-14 16:44 [commit/Ada] Ignore __XA types when redundant Joel Brobecker
2014-11-19  8:48 ` pushed: " Joel Brobecker
2014-11-19 18:19   ` Regression for gdb.ada/arrayidx.exp [Re: pushed: [commit/Ada] Ignore __XA types when redundant.] Jan Kratochvil
2014-11-20  4:10     ` Joel Brobecker
2014-11-20  6:45       ` Jan Kratochvil
2014-11-20  9:47         ` should be fixed: " Joel Brobecker
2014-11-20  9:57           ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).