Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

Fixes Issue

main PR

Description

DWARF debug info was not generated for types referenced but never instantiated (e.g., var nullObj = (MyClass)null). The GetClassTypeIndex method skipped instance fields when hasInstanceFields was false, which occurred for reference types without a constructed EEType.

Changes:

  • Removed the hasInstanceFields guard that prevented instance field processing
  • Removed the now-unused hasInstanceFields variable
  • Added comments explaining the rationale

Instance fields are now emitted for all types regardless of instantiation status, enabling debuggers to display type information for null references and in signal/exception scenarios.

Customer Impact

Debugging scenarios involving null references or types never explicitly instantiated cannot inspect field information. This primarily affects low-level debugging, signal handlers, and crash analysis where type metadata is critical.

Regression

No. This addresses a long-standing limitation in debug info generation, not a recent regression.

Testing

Built ILCompiler.Compiler successfully. The change is isolated to debug info emission and does not affect runtime behavior or code generation.

Risk

Low. The change only affects debug metadata generation for the AOT compiler. It removes a constraint that was overly restrictive, allowing more complete debug information. No changes to runtime logic or code generation paths.

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Original prompt

This section details on the original issue you should resolve

<issue_title>No DWARF debug info generated when accessing fields on a null object unless explicitly instantiated</issue_title>
<issue_description>### Description

When testing .NET and OS-level signal/exception handling, I found an issue where certain code patterns fail to generate DWARF debug info. Specifically, the following code does not generate DWARF debug information:

public class NullObjectTest
{
    public int aaaaa1;
    public int aaaaa2;
    public int aaaaa3;
    public int aaaaa4;
    public string aaaaa5;
    public string aaaaa6 => aaaaa5;
    public object aaaaa7;
}
var nullObj = (NullObjectTest)null;
nullObj.aaaaa4 = 1;

The issue occurs unless the user explicitly instantiates (e.g., new) the class. This was discovered during low-level signal handling tests, where I encountered unexpected behavior in the ILC output.

Reproduction Steps

  1. Create the class NullObjectTest as shown above.
  2. Assign var nullObj = (NullObjectTest)null;
  3. Try accessing or assigning a field, e.g., nullObj.aaaaa4 = 1;
  4. Build and inspect the generated DWARF debug info.
  5. Observe that no DWARF debug information is created for this code pattern unless NullObjectTest is instantiated via new.

Expected behavior

DWARF debug info should be generated even when fields are accessed or assigned on a variable that is statically typed but not explicitly instantiated (i.e., is null).

Actual behavior

No DWARF debug info is produced for the code above when not explicitly instantiating the object. This limits debugging and inspection during signal exception or crash analysis. The issue seems specific to certain IL patterns generated by the compiler.

Regression?

I am not sure if this is a regression. It was noticed during custom OS signal exception testing. Unsure if previous builds had the same behavior.

Known Workarounds

Explicitly instantiate the class:

var obj = new NullObjectTest();
obj.aaaaa4 = 1;

This allows DWARF debug info to be generated as expected.

Configuration

Observed with latest .NET. Please clarify if specific OS/platform details are needed.

Other information

Discovered when testing OS signal/exception mechanisms and analyzing ILC output. Might be related to compiler optimization for null values.

Proposed fix (reported by reporter):

  • File: src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs
  • Method: GetClassTypeIndex
  • Change: remove or comment out the guard that skips types without instance fields:

Current code to change:

if (!hasInstanceFields)
    continue;

Rationale: That guard causes types that are referenced as a null variable (no explicit new) to be skipped when emitting type/field metadata used for DWARF generation. Removing/commenting out it ensures the type is considered and DWARF debug info (field/location info) will be generated even when the variable is null at compile-time.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix DWARF debug info generation for null objects Fix DWARF debug info generation for uninstantiated types Dec 16, 2025
Copilot AI requested a review from agocke December 16, 2025 22:34
{
if (!hasInstanceFields)
continue;
// Allow instance fields to be emitted even for types that are never instantiated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this is problematic because we're going to be looking at layout of types that we didn't look at before (no constructed type means we never had to calculate type size or look at instance fields). If there's a problem with the type (e.g. has an instance field of a type that doesn't resolve because e.g. NuGet was a mismatched version), we're likely to crash here a couple lines down. We had crashes like that before, this is what the code around line 636 is dealing with.

I'm going to ask about the motivation in the original issue. Right now I'm leaning toward By Design/Won't fix on this.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No DWARF debug info generated when accessing fields on a null object unless explicitly instantiated

4 participants