GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ada

Ada: DWARF debug info fix for variant part of derived types

Correctly generates DWARF debug information for Ada derived types with variant parts, ensuring discriminant information is properly included.

This commit addresses an issue with generating DWARF debug information for Ada derived types that have variant parts. It works around a DWARF limitation where the discriminant attribute must reference a member DIE of the same record type. The fix ensures that even when a discriminant is a sub-component of a parent type, its information is correctly captured in the DWARF output.

In Details

In gcc/dwarf2out.cc, the gen_field_die function is modified to handle discriminants within derived Ada types that are sub-components of parent types. By adjusting return types and adding an ANONYMOUS parameter, it can now correctly generate DW_AT_discr attributes for DW_TAG_variant_part DIEs, even when the discriminant is not a direct member but a nested component. This resolves a limitation in DWARF representation for complex Ada type hierarchies.

For Context
DWARF
A debugging data file format used by many compilers to store information about variables, types, and code locations. This information is used by debuggers to provide a meaningful debugging experience.
DIE
Stands for Debugging Information Entry. It's a fundamental unit within DWARF, representing a specific entity like a function, variable, type, or scope.
DW_TAG_variant_part
A DWARF tag used to describe a variant part of a record type. This is analogous to discriminated unions or variant records in programming languages.
DW_TAG_member
A DWARF tag used to describe a component (field) within a structure or record type.
DW_AT_discr
A DWARF attribute that specifies the discriminant for a variant part (DW_TAG_variant_part).
Filed Under: adadwarfdebugging