Repository navigation
Resolve NativeAOT DWARF class declarations to their complete types - #138224
Conversation
Every class is described with a forward declaration and a complete type, and references from variables, parameters and fields point to the declaration. Debuggers find the complete type by name, but dsymutil only keeps the DIEs that are referenced from code or data. Complete types that nothing references directly, like interfaces, or classes whose methods are all inlined in optimized builds, are dropped from the dSYM, and lldb shows the variables of those types as incomplete types. The DWARF writer now resolves references to a forward declaration to its complete type, and doesn't emit the declaration, like clang does for types defined in the same unit. CodeView still uses forward references. Co-authored-by: Copilot <[email protected]> Copilot-Session: ce36e465-0dbf-430e-9290-67490662095a
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
|
I think we should be able to apply this diff on top that should achieve the same effect: diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfBuilder.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfBuilder.cs
index ad527c92f0c..251a7a4c11e 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfBuilder.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfBuilder.cs
@@ -109,21 +109,7 @@ public DwarfBuilder(
public bool UseDwarf5 => _useDwarf5;
public int FrameRegister => _frameRegister;
- // References to a forward declaration that has a complete type are resolved to the complete type.
- public uint ResolveOffset(uint typeIndex)
- {
- if (typeIndex == 0)
- {
- return 0;
- }
-
- if (_dwarfTypes[(int)typeIndex - 1] is DwarfClassTypeInfo { CompleteTypeIndex: not 0 } forwardDeclaration)
- {
- typeIndex = forwardDeclaration.CompleteTypeIndex;
- }
-
- return _dwarfTypeOffsets[typeIndex - 1];
- }
+ public uint ResolveOffset(uint typeIndex) => typeIndex == 0 ? 0u : _dwarfTypeOffsets[typeIndex - 1];
public void Write(
SectionWriter infoSectionWriter,
@@ -218,15 +204,8 @@ public void WriteInfoTable(
int typeIndex = 0;
foreach (DwarfInfo type in _dwarfTypes)
{
- // Debuggers find the complete type of a declaration by its name, but tools like dsymutil
- // only keep the types that are referenced. The declaration isn't emitted, and its references
- // are resolved to the complete type, so that the complete type is kept when it is used.
- if (type is not DwarfClassTypeInfo { CompleteTypeIndex: not 0 })
- {
- _dwarfTypeOffsets[typeIndex] = (uint)dwarfInfoWriter.Position;
- type.Dump(dwarfInfoWriter);
- }
-
+ _dwarfTypeOffsets[typeIndex] = (uint)dwarfInfoWriter.Position;
+ type.Dump(dwarfInfoWriter);
typeIndex++;
}
@@ -466,16 +445,20 @@ public uint GetCompleteClassTypeIndex(
uint forwardDeclarationTypeIndex = 0)
{
var classInfo = new DwarfClassTypeInfo(classTypeDescriptor, classFieldsTypeDescriptor, fields, statics);
- _dwarfTypes.Add(classInfo);
_staticFields.AddRange(classInfo.StaticVariables);
- uint typeIndex = (uint)_dwarfTypes.Count;
+ // Debuggers find the complete type of a declaration by its name, but tools like dsymutil
+ // only keep the types that are referenced. The complete type replaces the forward declaration,
+ // so that references to the declaration keep the complete type alive.
if (forwardDeclarationTypeIndex != 0)
{
- ((DwarfClassTypeInfo)_dwarfTypes[(int)forwardDeclarationTypeIndex - 1]).CompleteTypeIndex = typeIndex;
+ Debug.Assert(_dwarfTypes[(int)forwardDeclarationTypeIndex - 1] is DwarfClassTypeInfo);
+ _dwarfTypes[(int)forwardDeclarationTypeIndex - 1] = classInfo;
+ return forwardDeclarationTypeIndex;
}
- return typeIndex;
+ _dwarfTypes.Add(classInfo);
+ return (uint)_dwarfTypes.Count;
}
public uint GetMemberFunctionTypeIndex(MemberFunctionTypeDescriptor memberDescriptor, uint[] argumentTypes)
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfInfo.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfInfo.cs
index 54afdc96518..fa0d68c6d65 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfInfo.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfInfo.cs
@@ -226,9 +226,6 @@ internal sealed class DwarfClassTypeInfo : DwarfInfo
private readonly List<DwarfStaticVariableInfo> _statics;
private List<DwarfMemberFunction> _methods;
- // The type index of the complete type of a forward declaration, if any.
- public uint CompleteTypeIndex { get; set; }
-
public DwarfClassTypeInfo(ClassTypeDescriptor typeDescriptor)
{
_isForwardDecl = true; |
Applying Michal's suggestion: the complete type takes the place of its forward declaration in the type list, so references to the declaration resolve to the complete type without redirecting them when resolving offsets. Co-authored-by: Copilot <[email protected]> Copilot-Session: ce36e465-0dbf-430e-9290-67490662095a
|
@MichalStrehovsky thank you, applied! We should also probably enable the DwarfDump smoke test on macOS, no? |
If it works, sure. I don't have a mac to test with. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the NativeAOT DWARF type-definition update.
No open issues 🎉
What changed in this PR
This PR updates NativeAOT’s DWARF writer so class references point directly to complete types, preventing dsymutil from dropping definitions needed by debuggers.
Changes:
- Replaces DWARF forward declarations with complete types at the same type index.
- Passes declaration indices through the shared writer interface while preserving CodeView’s separate records.
- Adds a smoke-test check that
Programhas a class definition without a forward declaration.
| File | Description |
|---|---|
| src/tests/nativeaot/SmokeTests/DwarfDump/Program.cs | Checks class debug information for the absence of a forward declaration. |
| src/coreclr/tools/Common/TypeSystem/TypesDebugInfoWriter/TypesDebugInfoWriter.cs | Adds an optional forward-declaration index parameter. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs | Supplies the declaration index when creating a complete type. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfBuilder.cs | Replaces the declaration record with the complete class record. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/CodeView/CodeViewTypesBuilder.cs | Matches the updated interface without changing CodeView behavior. |
Review effort: Balanced
Every class is described with a forward declaration and a complete type, and references from variables, parameters and fields point to the declaration. Debuggers find the complete type by name, but dsymutil only keeps the DIEs that are referenced from code or data. Complete types that nothing references directly, like interfaces, or classes whose methods are all inlined in optimized builds, are dropped from the dSYM, and lldb shows the variables of those types as incomplete types.
The DWARF writer now resolves references to a forward declaration to its complete type, and doesn't emit the declaration, like clang does for types defined in the same unit. CodeView still uses forward references.
Validated on lldb/gdb on Linux with Dwarf 4 and 5, and on macOS with lldb.