Skip to content

Fix #20004 - generate DW_TAG_enumerator for enum members in DWARF deb…#22864

Draft
dkorpel wants to merge 1 commit intodlang:masterfrom
dkorpel:fix-20004-dwarf-enum-members
Draft

Fix #20004 - generate DW_TAG_enumerator for enum members in DWARF deb…#22864
dkorpel wants to merge 1 commit intodlang:masterfrom
dkorpel:fix-20004-dwarf-enum-members

Conversation

@dkorpel
Copy link
Copy Markdown
Contributor

@dkorpel dkorpel commented Apr 2, 2026

…ug info

Closes #20004

@dkorpel dkorpel added the Feature:Debug Info DWARF, PDB label Apr 2, 2026
@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#22864"

@dkorpel dkorpel force-pushed the fix-20004-dwarf-enum-members branch 3 times, most recently from 4194317 to cf52fdb Compare April 2, 2026 23:32
@dkorpel
Copy link
Copy Markdown
Contributor Author

dkorpel commented Apr 3, 2026

The backend currently assumes TYenum is a 4-byte integer (like in C), it doesn't support D's arbitrary enums. Adding TYenum8 TYenum16 types etc. looks redundant, maybe the backend type of D enums should always be whatever the base type is (TYuns8 TYuns16 etc.) with a separate flag specifying it has an enum symbol for debug info.

@ibuclaw
Copy link
Copy Markdown
Member

ibuclaw commented Apr 3, 2026

@dkorpel dwarf supports this (enum class)

@ibuclaw
Copy link
Copy Markdown
Member

ibuclaw commented Apr 3, 2026

From the dwarfv5 spec (rewrote example as D)

enum E : byte { E1 , E2 = 100 }
! DWARF description !
11$: DW_TAG_enumeration_type
        DW_AT_name("E")
        DW_AT_type(reference to "byte")
        DW_AT_enum_class(present)
12$:    DW_TAG_enumerator
            DW_AT_name("E1")
            DW_AT_const_value(0)
13$:    DW_TAG_enumerator
            DW_AT_name("E2")
            DW_AT_const_value(100)
14$: 

@ibuclaw
Copy link
Copy Markdown
Member

ibuclaw commented Apr 3, 2026

Named enums in D are all strongly typed, so DW_AT_enum_class should always be emitted in debug code.

@dkorpel
Copy link
Copy Markdown
Contributor Author

dkorpel commented Apr 3, 2026

The dwarf debug info generation works with the current changes, but the change from TYuns8 to TYenum causes problems with code generation

@dkorpel dkorpel force-pushed the fix-20004-dwarf-enum-members branch from cf52fdb to debf6f0 Compare April 4, 2026 14:12
…F debug info

For D enums, the backend's SEenumlist was never populated and SENforward
was never cleared, causing all enum types to appear as forward-referenced
declarations with no children in DWARF output.

Changes:
- In visitEnum, use type_enum for all integral base types (not just int),
  and populate SEenumlist with member names and values when debug info
  is enabled. This allows GDB to show symbolic enum names.
- In type_size, make TYenum delegate to its Tnext (base type) for the
  size. Previously TYenum was hardcoded as LONGSIZE (4 bytes), which
  caused incorrect parameter passing for e.g. ulong or ubyte enums.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dkorpel dkorpel force-pushed the fix-20004-dwarf-enum-members branch from debf6f0 to aac5d88 Compare April 4, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DWARF: DW_TAG_enumerator is not being generated for enum members

3 participants