]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Ignore artificial fields in Ada
authorTom Tromey <tromey@adacore.com>
Fri, 3 Oct 2025 16:59:29 +0000 (10:59 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 7 Oct 2025 14:25:06 +0000 (08:25 -0600)
commit48b5669c2e26debe49491ecf6e20e82ccf28c15b
treee81883e3483675c101c31e59e23be951cc089a61
parent6d3af8c9f6805e935677757d84dd6cfdb5cda261
Ignore artificial fields in Ada

A user found an unusual Ada situation that DWARF does not readily
support.  Consider this type:

   type Discrete_Typ is tagged null record;
   type Int_Typ (Is_Static : Boolean) is new Discrete_Typ with null record;

   type Signed_Int_Typ (Is_Static : Boolean) is
      new Int_Typ (Is_Static => Is_Static)
                    with record
      case Is_Static is
         when True =>
            Field : Integer;
         when others =>
            null;
      end case;
   end record;

Here, Signed_Int_Typ has a variant part where the discriminant is
stored in a superclass.

Anyway, this code caused gnat-llvm to crash.  While fixing the crash,
I decided to fix this by emitting an anonymous field in Signed_Int_Typ
that represents the discriminant.  This would allow member DIEs to
refer to it -- which I suppose is possibly why DWARF specified that
the discriminant should be a member of the variant (though I don't
really know; this decision always seemed very strange to me).

Making the field anonymous lead to the strange error:

    Type ... is not a structure or union type.

... which comes from lookup_struct_elt, which fails when an anonymous
member of a structure has a non-composite type.  This patch includes a
fix for this issue.

After fixing that, though I decided it would be better if the
artificial discriminant were still given a name.  So, this patch
includes a change to ada_is_ignored_field to ignore artificial fields.

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/ada-lang.c
gdb/gdbtypes.c
gdb/testsuite/gdb.dwarf2/ada-artificial-field.c [new file with mode: 0644]
gdb/testsuite/gdb.dwarf2/ada-artificial-field.exp [new file with mode: 0644]