Repository navigation
Conversation
|
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 |
There was a problem hiding this comment.
🔵 Needs a closer look
The shared boxed-enum change affects CodeView and DWARF, but Linux dump tests do not establish Windows/macOS debugger name resolution or boxed-value inspection, leaving those contracts to human validation.
No open issues 🎉
What changed in this PR
This PR corrects NativeAOT debug metadata so debuggers can locate static fields and interpret arrays, interfaces, boxed enums, and this consistently. Most changes affect DWARF; the boxed-enum correction also affects CodeView.
Changes:
- Align static-field locations with storage order, remove an extra GC-static dereference, and omit unsupported thread-static locations.
- Correct array and interface layouts, boxed-enum descriptions, and DWARF
thisparameter types. - Extend the DWARF smoke tests with regression checks for these cases.
| File | Description |
|---|---|
src/tests/nativeaot/SmokeTests/DwarfDump/Program.cs |
Adds test types and DWARF assertions for the corrected metadata. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs |
Fixes interface size and static-location descriptor ordering; removes thread-static locations. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/UnixObjectWriter.Aot.cs |
Emits ordinary instance-method this parameters as pointers, preserving state-machine handling. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ObjectWriter.Aot.cs |
Shares declaration-compatible this typing and uses enumeration types for boxed-enum MethodTables. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfInfo.cs |
Uses a single dereference for GC-static locations. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/Dwarf/DwarfBuilder.cs |
Skips unavailable static locations and removes the duplicate array element-count field. |
Review effort: Balanced
This has been validated on macOS as well. I've found issues related to how |
Windows (CodeView) validation of the boxed enum changeThe commit that describes boxed enums with their enumeration type also changes the Windows debug info, so I checked it on Windows x64. I built the same NativeAOT probe with the ILC from before and after that commit. The probe uses PDB type records, from
cdb/WinDbg, stopped in a method with a Visual Studio 2026: |
a3ecd55 to
45ba752
Compare
On non-Windows targets, the debug info of a class emits its static fields grouped by storage region (non-GC, GC, then thread statics), but the descriptors with their locations were collected in field declaration order. The DWARF writer pairs both lists by index, so any class declaring a GC static before a non-GC one got the locations of its static fields swapped. Collect the location descriptors per region and concatenate them in the same order as the fields. Co-authored-by: Copilot <[email protected]> Copilot-Session: bf34413c-9243-495c-acf3-59e4b5f38a9f
The static base symbol of a type with GC statics holds a reference to the object storing those statics, and the offset of each GC static field already includes the MethodTable pointer at the start of that object. The location expression dereferenced the symbol twice, which made debuggers read the fields relative to the MethodTable of the statics object instead of the object itself. Dereference the static base once. Co-authored-by: Copilot <[email protected]> Copilot-Session: bf34413c-9243-495c-acf3-59e4b5f38a9f
The location of thread static fields was described like the location of GC statics, relative to the __THREADSTATICS symbol of the type. That symbol is not the storage of the thread statics: the storage is looked up at runtime for the current thread from the index of the type, which a DWARF location expression can't describe. Debuggers read thread static fields from an unrelated address. Keep declaring thread static fields, but don't describe their location. Co-authored-by: Copilot <[email protected]> Copilot-Session: bf34413c-9243-495c-acf3-59e4b5f38a9f
The DWARF description of array types derives from System.Array, which already describes the number of elements with its _numComponents field, and then declared its own m_NumComponents member at the same offset. Debuggers building a C++ record from this see two overlapping fields: clang asserts on the layout, and lldb can evaluate m_NumComponents to a wrong value in expressions. Only describe the bounds and the elements in the array types. Co-authored-by: Copilot <[email protected]> Copilot-Session: bf34413c-9243-495c-acf3-59e4b5f38a9f
Interfaces are described as classes deriving from Object, so debuggers can cast them to the actual type of the instance, but their size was their own instance byte count, which is 0. A class smaller than its base class is invalid; gdb fails to print variables of interface types with "access outside bounds of object". Use the size of Object for interfaces. Co-authored-by: Copilot <[email protected]> Copilot-Session: bf34413c-9243-495c-acf3-59e4b5f38a9f
The debug info of every allocated MethodTable was created through GetTypeIndex, which describes a boxed enum as a class named like the enum with its value__ field. The same name was also used by the enumeration type describing variables and fields of the enum, which makes the name ambiguous for debuggers: lldb fails to evaluate Color::Green with "reference to 'Color' is ambiguous", and gdb looks up the enumerators in the class. Use the enumeration type for boxed enums. Co-authored-by: Copilot <[email protected]> Copilot-Session: bf34413c-9243-495c-acf3-59e4b5f38a9f
Member function declarations describe their object pointer as a pointer to the class, but the this parameter of the method definitions had the type of a variable of the class: a reference for reference types and value type byrefs. Debuggers use the this parameter to resolve the members of the class in expressions; gdb fails to evaluate a call like Method() inside an instance method with "Attempt to take contents of a non-pointer value". Give the this parameter of the method definitions the type of the object pointer of their declaration. Co-authored-by: Copilot <[email protected]> Copilot-Session: bf34413c-9243-495c-acf3-59e4b5f38a9f
45ba752 to
deb59f4
Compare
Fix NativeAOT debug info for statics, arrays, interfaces, enums and
thisWhile evaluating how lldb and gdb handle the DWARF that NativeAOT emits through their C++ support, I found several places where the debug info is inconsistent or wrong. Debuggers then show wrong values, fail to evaluate expressions, or trip assertions. This PR fixes them.
Changes
Fix NativeAOT DWARF locations of static fields. On non-Windows targets, the static fields of a class are emitted grouped by storage region (non-GC, GC, then thread statics), but the descriptors with their locations were collected in declaration order, and the DWARF writer pairs both lists by index. Any class declaring a GC static before a non-GC static got the locations of its fields swapped. The location descriptors are now grouped the same way as the fields.
Fix NativeAOT DWARF location of GC static fields. The GC static base symbol holds a reference to the object storing the statics, and the field offsets already include the MethodTable pointer, but the location expression dereferenced the symbol twice. Debuggers read GC statics relative to the MethodTable of the statics object. It now dereferences once, which matches the code the compiler generates.
Don't describe a location for thread statics in NativeAOT DWARF. Thread statics that aren't inlined in the module TLS block were described relative to the
__THREADSTATICSsymbol of the type, which isn't their storage. The storage is looked up at runtime for the current thread (GetThreadStaticBaseForType), which a location expression can't describe. The fields are still declared, without a location, so debuggers report them as unavailable instead of reading an unrelated address.Remove duplicate element count from NativeAOT DWARF array types. Array types derive from
System.Array, which describes the element count with_numComponents, and also declared their ownm_NumComponentsat the same offset. Clang-based debuggers reject the overlapping fields: an assertions-enabled lldb aborts in clang's record layout, and lldbmainevaluatesarray.m_NumComponentsto 0. The array types now only describe the bounds and the elements; the count is_numComponentsof the base class, whichNativeAOT.natvisalready uses on Windows.Fix size of interfaces in NativeAOT debug info. Interfaces are described as classes deriving from
Object, so debuggers can cast them to the actual type of the instance, but their size was their own instance byte count of 0. gdb fails to print variables of interface types with "access outside bounds of object". Interfaces now have the size ofObject. This only changesDW_AT_byte_size; CodeView takes the size of classes from elsewhere.Describe boxed enums with their enumeration type in NativeAOT debug info. Every allocated MethodTable gets debug info, and a boxed enum was described as a class or struct named like the enum, with its
value__field, next to the enumeration type with the same name. This also affects CodeView. Debuggers then resolve the name to the wrong type:Color::Greenis "ambiguous".dt Colorshows the struct, anddx color == Color::Bluefails with "Unable to bind name 'Blue'".Boxed enums are now described by the enumeration type.
Describe the this parameter as a pointer in NativeAOT DWARF. Member function declarations describe their object pointer as a pointer to the class, but the
thisparameter of the method definitions was a reference (or a byref for value types). gdb fails to evaluate member calls likeMethod()in an instance method with "Attempt to take contents of a non-pointer value". The definitions now use the type of the declaration's object pointer, which is also how the Visual Studio debugger showsthison Windows. CodeView is unchanged.Visible behavior changes
_numComponents(fromSystem.Array);m_NumComponentsno longer exists in DWARF.thisis a pointer in lldb and gdb, like the Visual Studio debugger already shows it on Windows: members are accessed withthis->, and lldb'sframe variable thisprints the pointer (frame variable *thisexpands the object). Other object variables are still references, accessed with., as in Visual Studio.Not tested: other architectures and macOS.