-
-
Notifications
You must be signed in to change notification settings - Fork 668
Fix Issue 22251: Omit DW_AT_type for noreturn variables in DWARF #22302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request and interest in making D better, @Adityazzzzz! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
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 referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
| if (tidx == 0) // FIX: If noreturn use NOTYPE array | ||
| { | ||
| dwarfabbrev.append(DW_TAG_formal_parameter, DW_CHILDREN_no); | ||
| formalcode = dwarfabbrev.awrite!formal_var_abbrev_suffix_notype; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want to set this in another variable other than formalcode, otherwise you'll get corrupt dwarf for the opposite reason - abbreviation has no TYPE, but data contains one.
| if (tidx == 0) // FIX: If noreturn use NOTYPE array | ||
| { | ||
| dwarfabbrev.append(DW_TAG_variable, DW_CHILDREN_no); | ||
| variablecode = dwarfabbrev.awrite!formal_var_abbrev_suffix_notype; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise here for variablecode.
|
I can see handling void/noreturn symbols being done for globals, locals, and parameters. But not for field members. |
| cast(void)dwarf_typidx(sa.Stype); | ||
| if (!formalcode) | ||
| uint tidx = cast(uint)dwarf_typidx(sa.Stype); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing whitespace
| cast(void)dwarf_typidx(sa.Stype); | ||
| if (!variablecode) | ||
| uint tidx = cast(uint)dwarf_typidx(sa.Stype); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
| debug_info.buf.write32(tidx); // DW_AT_type | ||
| debug_info.buf.writeByte(sa.Sflags & SFLartifical ? 1 : 0); // DW_FORM_tag | ||
| debug_info.buf.writeStringz(getSymName(sa)); // DW_AT_name | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Variables with noreturn type (type index 0) were causing corrupt DWARF output because the compiler was writing a type index of 0 into abbreviations that expected a valid type reference. This patch adds a check to generate specific abbreviations without DW_AT_type for variables, parameters, and globals when the type index is 0.
97d7201 to
1afb8fa
Compare
|
@ibuclaw @thewilsonator Please Review |
|
Maybe it would be better to simply omit emitting debug info for noreturn-typed symbols. I don't know if debuggers can even handle a "bottom type". |
|
Or disallow creating variables of type noreturn. |
What this PR does / why we need it: This PR fixes a DWARF debug info corruption issue when compiling variables or parameters of type noreturn.
Previously, the compiler treated noreturn types (which have a type index of 0) like normal types. It generated a DWARF abbreviation containing DW_AT_type and wrote a 0 value for it. However, tools like objdump interpret a type index of 0 as invalid or missing context in this specific scenario, causing them to lose synchronization with the DWARF stream and report corruption errors like: objdump: Warning: Unable to find entry for abbreviation [number]
The Fix: I modified dwarf_outsym in backend/dwarfdbginf.d to handle noreturn types specially:
Verification: Using the reproduction case from the issue:
Before: objdump --dwarf=info reported: Warning: Unable to find entry for abbreviation... and displayed corrupted tags.
After: objdump output is clean. noreturn variables appear correctly without a DW_AT_type field:
Ref: #22251