Skip to content

DWARF for enums could be improved #32920

Closed
@tromey

Description

@tromey

Suppose you have a "non-trivial" enum like:

enum MoreComplicated {
    One,
    Two(i32),
}

The DWARF looks like:

 <2><a7>: Abbrev Number: 6 (DW_TAG_union_type)
    <a8>   DW_AT_name        : (indirect string, offset: 0x16e): MoreComplicated
    <ac>   DW_AT_byte_size   : 24
 <3><ad>: Abbrev Number: 7 (DW_TAG_member)
    <ae>   DW_AT_type        : <0xc0>
    <b2>   DW_AT_data_member_location: 0
 <3><b3>: Abbrev Number: 7 (DW_TAG_member)
    <b4>   DW_AT_type        : <0xd1>
    <b8>   DW_AT_data_member_location: 0

Then looking at the type of One, aka DIE 0xc0:

 <2><c0>: Abbrev Number: 8 (DW_TAG_structure_type)
    <c1>   DW_AT_name        : (indirect string, offset: 0x160): One
    <c5>   DW_AT_byte_size   : 1
 <3><c6>: Abbrev Number: 9 (DW_TAG_member)
    <c7>   DW_AT_name        : (indirect string, offset: 0x1b7): RUST$ENUM$DISR
    <cb>   DW_AT_type        : <0x6d>
    <cf>   DW_AT_data_member_location: 0

This is peculiar DWARF in a few ways.

First, this emits a separate structure type for each branch. DWARF has a notion of a discriminated union that might be a closer fit semantically. See DW_TAG_variant_part, DW_AT_discr, etc. (gdb's DWARF reader doesn't handle these at all, but it certainly could be made to.)

Second, I think at the very least the discriminant should be marked DW_AT_artificial.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions