Skip to content

Implement cDAC GCInfo inspection with ISOSDacInterface18/19 - #137119

Merged
davidwrighton merged 15 commits into
dotnet:mainfrom
davidwrighton:prototype/x86-cdac-gcinfo
Nov 17, 2026
Merged

davidwrighton merged 15 commits into
dotnet:mainfrom
davidwrighton:prototype/x86-cdac-gcinfo

Conversation

@davidwrighton

@davidwrighton davidwrighton commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Implement cDAC GCInfo inspection through ISOSDacInterface18 and ISOSDacInterface19, and correct the X86 decoding and lifetime projection needed to make that information useful to diagnostic tools.

Together, the interfaces let consumers such as SOS obtain decoded GC headers, interruptibility, safe points, root lifetimes, and X86-specific stack transitions from the DAC instead of maintaining their own interpretation of the runtime's encoded GCInfo.

ISOSDacInterface18: normalized GCInfo inspection

Provide the cDAC implementation of all four existing Interface18 methods:

API Information returned
GetGCInfoHeader Encoding version, method/prolog sizes, frame register, parameter area, and available GS-cookie, PSP, and generics-context information.
GetGCInfoInterruptibleRanges Ranges in which execution is fully interruptible.
GetGCInfoSafePoints Discrete safe-point offsets.
GetGCInfoSlotLifetimes Register and stack-root locations, lifetime intervals, and interior/pinned/untracked qualifiers.
  • Resolve the supplied managed-code address through the execution manager, obtain its GCInfo address/version, and select the native or interpreter decoder as appropriate.
  • Normalize contract stack-base identifiers to the existing Interface18 representation: SP-relative or relative to the header's frame register.
  • Keep partially interruptible X86 call-site ranges available to stack walking, but expose those call sites through the safe-point API rather than misreporting them as fully interruptible regions.
  • Support count-then-fetch enumeration, report required capacity with S_FALSE, validate caller buffers/header sizes, and translate failures to HRESULTs.

The existing Interface18 ABI is unchanged; this PR supplies its cDAC implementation.

ISOSDacInterface19: supplemental X86 details

Add a separately queryable interface for information that cannot be represented by Interface18's normalized root model:

API Information returned
GetGCInfoX86Header Epilog information, saved-register mask, argument/frame sizes, frame and method flags, untracked/VarPtr counts, synchronization/no-GC metadata, argument-table metadata, return kind, and reverse P/Invoke offset.
GetGCInfoX86Epilogs Epilog start offsets.
GetGCInfoX86Transitions Decoded register live/dead, push/pop, kill, stack-depth, receiver-register, interior-mask, and call records.

Transition records preserve code offsets, register identifiers, argument counts/indices or masks, pointer/interior/receiver flags, and stack-depth deltas where represented. Ordinary EBP pointer push/pop records currently report zero stack delta; bulk stack-depth records report their byte delta.

Add the corresponding IGCInfo contract methods and data types, managed COM declarations, native IDL, and checked-in native interface definitions. Supplemental data requires a native X86 decoder; other decoders report E_NOTIMPL through the COM interface. Interface18 consumers do not need to use Interface19.

X86 decoder and lifetime correctness

  • Retain interior qualifiers from register LIVE records instead of trying to recover them from later DEAD records.
  • Project root state by code offset, coalescing adjacent intervals only when both the location and qualifiers match.
  • Track outgoing argument depth, pointer indices, and pointer-index gaps. Recompute ESP-relative root/local locations as the stack moves, while using the stable frame-relative argument base for ordinary EBP frames.
  • Count all stack entries when processing fully interruptible pops, including non-pointer arguments. Popping a non-pointer entry must not remove a pointer root below it.
  • Handle both single non-pointer pushes and bulk stack-depth adjustments, including the GCInfo operations corresponding to constant method-body sub esp, N / add esp, N.
  • Treat KILL as invalidating the indicated highest pointer arguments without popping the argument stack.
  • Report partially interruptible call roots only at their call-site offsets rather than inventing tracked liveness between calls.
  • Separate huge-call argument offsets from their encoded interior flags and preserve explicit argument roots and receiver metadata.
  • Exclude explicit no-GC regions from fully interruptible ranges.
  • Accept valid register-death transitions at the method end while rejecting out-of-range transitions and invalid local-lifetime bounds.
  • Preserve untracked and pinned/interior qualifiers when stack movement splits a location's lifetime.

These changes address the X86 problems illustrated in this GCInfo investigation.

Tests and documentation

Add focused coverage for COM interface discovery and calls, header/decoder selection, stack-base normalization, count/fetch buffer semantics, invalid arguments, initialized failure outputs, and unsupported supplemental decoders.

X86 regressions cover GCInfo versions 4 and 5, interior-register lifetimes, pushed pointers, non-pointer single/bulk stack changes in EBP and ESP frames, KILL, pointer-index gaps, huge calls, receiver metadata, explicit no-GC regions, and method-end transitions. An encoded GCInfo fixture from an actual pinned/interior-root method exercises the combined projection.

Document the X86 diagnostic contract, units, flags, lifetime semantics, and limitations in docs/design/datacontracts/GCInfo.md. The specification describes contract APIs independently of the SOS COM adapter.

SOS integration

The companion SOS consumer changes are in dotnet/diagnostics#6198. They format the interface data for !gcinfo and !u -gcinfo, use Interface19 for supplemental X86 reporting, and retain legacy decoding for older runtimes without Interface18.

The diagnostics changes are intended to merge first so runtime SOS integration tests use the updated formatter and output expectations.

Local validation

  • Windows X64 and genuine Windows X86: 347 focused runtime tests passed per architecture, covering GCInfoTests, GCInfoHeaderTests, and StackWalkTests.
  • With the companion diagnostics changes: 20 SOS/parser tests passed per architecture, exercising Legacy/CDac through Cdb and dotnet-dump.
  • New EBP non-pointer pop regressions failed before the decoder fix; the real-output SOS regression also failed against the old formatter.
  • Native cDAC binaries were checked for the correct PE architecture.
  • Analyzer-enabled Abstractions/Contracts rebuilds and focused C# whitespace checks passed.

Known limitations

Dynamic localloc and funclet argument bases require per-frame execution state and are not fully reconstructed by the static lifetime projection. The diagnostic transition interface exposes decoded records, not raw GCInfo encoding bytes, and those records do not distinguish arithmetic stack adjustments from equivalent push/pop operations.

Note

This PR and its description were prepared with GitHub Copilot.

davidwrighton and others added 6 commits November 6, 2026 13:48
Expose the existing GCInfo inspection interface through the cDAC COM object. Forward header, interruptible-range, safe-point, and slot-lifetime queries to the appropriate platform or interpreter decoder, with sized-buffer and HRESULT handling.

Add regression coverage for interface discovery, unmanaged vtable calls, field mappings, buffer sizing, and failure outputs. Validate the NativeAOT cDAC build and 626 focused tests.

Co-authored-by: Copilot <[email protected]>
Keep ISOSDacInterface18 stack-base semantics independent of decoder enums and GCInfo versions. Document the existing API values and cover v5/v6 decoding, native COM output, and unsupported bases.

Co-authored-by: Copilot <[email protected]>
Correct X86 root lifetimes, stack movement, call qualifiers and no-GC ranges. Expose optional X86 headers and decoded transitions for SOS, with contract documentation and decoder/COM regressions.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
Accept terminal transitions for fully interruptible methods while rejecting offsets beyond the code size. Cover the boundary and a real pinned/interior-root method, including Interface18 projection.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
Use total argument stack depth for fully interruptible EBP pops, preserving pointer roots below non-pointer arguments. Cover single and bulk adjustments for both frame styles and encoding versions, and correct the prototype documentation.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
Describe X86 transitions, safepoints, and slot lifetimes using contract APIs. Remove SOS interface and HRESULT bridge details from the contract specification.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Move the prebuilt Interface19 GUID definition before MIDL_DEFINE_GUID is undefined. Directly compile the checked-in file in both GUID macro configurations.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
@jkotas

jkotas commented Nov 7, 2026

Copy link
Copy Markdown
Member

How far are we from being able to call cDAC managed APIs directly in SOS commands? Encapsulating intricate implementation details like this in COM interfaces is unfortunate.

Place each enum member on its own line to satisfy StyleCop SA1136. Leave the expected diagnostics-version mismatch failures unchanged.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
@max-charlamb

Copy link
Copy Markdown
Member

How far are we from being able to call cDAC managed APIs directly in SOS commands? Encapsulating intricate implementation details like this in COM interfaces is unfortunate.

We are working on this. Once we release diagnostics tooling for net11, I have a bunch of changes for SOS to support NativeAOT builds. Then we can compile it together with the cDAC and call the APIs directly for new features. We will still need to call through the ISOSDacInterfaces to support versions of the runtime before the DAC (including framework).

Make ApplyPointerTransition static now that it no longer reads decoder instance state, satisfying CA1822 in the analyzer-enabled CI build.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
@davidwrighton

Copy link
Copy Markdown
Member Author

@max-charlamb ... do you think I should drop the X86 changes, and just add some tweak like.. X86 platform ignores the GCInfo dac interfaces and just does its own thing until this is all ready? Also, do you think you would want to keep the cDAC changes here regardless?

@max-charlamb

Copy link
Copy Markdown
Member

I don't love having a separate set of APIs specifically for x86, however it will be a good amount of time before we are ready to call the cDAC contracts directly from SOS.

If this provides debugging value now, it looks reasonable to me and should be good to add.

@davidwrighton davidwrighton changed the title [Prototype] X86 cDAC GCInfo inspection with ISOSDacInterface18/19 cDAC GCInfo inspection with ISOSDacInterface18/19 Nov 10, 2026
@davidwrighton davidwrighton changed the title cDAC GCInfo inspection with ISOSDacInterface18/19 Implement cDAC GCInfo inspection with ISOSDacInterface18/19 Nov 10, 2026
Correct transition field semantics and stale frame/timing comments. Explain packed argument flags, stack-base translation, call-root intervals, and encoded test fixtures. Remove remaining prototype wording from the contract specification. Comments and documentation only; no behavior or ABI changes.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
davidwrighton added a commit to dotnet/diagnostics that referenced this pull request Nov 10, 2026
…DAC GCInfo interface handling for other platforms (#6198)

## Summary

Prototype SOS support for interface-based X86 GCInfo reporting, paired
with the runtime cDAC changes.

- Use ISOSDacInterface18 for common GCInfo data and optional
ISOSDacInterface19 for X86 supplemental headers, epilogs, argument
push/pop, KILL, and stack-depth details.
- Delegate architecture-specific register names and supplemental
formatting through IMachine. Existing macro-guarded machine
implementation selection is deliberately unchanged.
- Fix formatting of pinned/interior roots and EBP non-pointer pushes.
Pop counts describe all arguments, not only pointers.
- Automatically use the built-in parser only when Interface18 is absent.
Errors from available interfaces are reported explicitly rather than
silently falling back. Preserve explicit `!gcinfo -legacy` for
comparison.
- Update tests/parsing to accept both legacy and interface output, and
add a real-output X86 regression comparing non-pointer pushes and pops
against the legacy encoding.

Companion runtime draft PR:
dotnet/runtime#137119

## Compatibility and scope

.NET 8/9/10 retain the legacy route when the interfaces are unavailable;
tests do not require cDAC on those runtimes. Local integration
validation used the private runtime with both Legacy and CDac, not
separate .NET 8/9/10 installations.

This is a reporting prototype, not a change to machine selection or a
complete cross-target disassembler implementation. Dynamic localloc and
funclet argument-base limitations remain in the companion runtime's
static projection.

## Local validation

- Native SOS builds passed on Windows X86 and X64.
- 20 SOS/parser tests passed per architecture with Legacy/CDac through
Cdb and dotnet-dump; no skips.
- The X86 non-pointer reporting regression failed under both hosts
against the old formatter and passed after the fix.
- The companion runtime passed 347 focused tests per architecture.
- Captured legacy/interface output for RootsScenario, including
pinned/interior locals, register lifetimes, and pointer argument
push/pop.
- C# whitespace checks passed.

> [!NOTE]
> This PR and its description were prepared with GitHub Copilot.

---------

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
@davidwrighton
davidwrighton marked this pull request as ready for review November 11, 2026 02:58
@davidwrighton
davidwrighton requested review from a team and a balanced review from Copilot November 11, 2026 02:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The EBP mapping can make live GC enumeration resolve fully interruptible funclet argument roots to parent-frame addresses instead of their correct ESP-relative locations.

4 open issues
What changed in this PR

This PR enables cDAC-based GCInfo inspection for diagnostic tools through ISOSDacInterface18 and adds supplemental X86 details through ISOSDacInterface19.

Changes:

  • Implements normalized GCInfo queries and adds X86 header, epilog, and transition interfaces.
  • Corrects X86 root lifetime projection, stack movement handling, interior flags, and interruptibility.
  • Adds COM and decoder regression tests and documents the contract’s semantics and limitations.
File Description
src/​native/​managed/​cdac/​tests/​UnitTests/​GCInfoTests.cs Adds COM interface and X86 decoding regression coverage.
src/​native/​managed/​cdac/​Microsoft.Diagnostics.DataContractReader.Legacy/​SOSDacImpl.cs Implements Interface18/19 queries, validation, and result mapping.
src/​native/​managed/​cdac/​Microsoft.Diagnostics.DataContractReader.Legacy/​ISOSDacInterface.cs Declares Interface19 and its managed data structures.
src/​native/​managed/​cdac/​Microsoft.Diagnostics.DataContractReader.Contracts/​Contracts/​GCInfo/​X86/​GCInfo.cs Updates root projection and exposes X86 diagnostic details.
src/​native/​managed/​cdac/​Microsoft.Diagnostics.DataContractReader.Contracts/​Contracts/​GCInfo/​X86/​GCArgTable.cs Corrects argument-depth tracking and huge-call offset decoding.
src/​native/​managed/​cdac/​Microsoft.Diagnostics.DataContractReader.Contracts/​Contracts/​GCInfo/​GCInfoX86_1.cs Connects supplemental contract methods to the X86 decoder.
src/​native/​managed/​cdac/​Microsoft.Diagnostics.DataContractReader.Abstractions/​Contracts/​IGCInfo.cs Adds X86 diagnostic methods and data types.
src/​coreclr/​pal/​prebuilt/​inc/​sospriv.h Adds checked-in native Interface19 declarations.
src/​coreclr/​pal/​prebuilt/​idl/​sospriv_i.cpp Defines the Interface19 identifier.
src/​coreclr/​inc/​sospriv.idl Defines the supplemental X86 COM interface and structures.
docs/​design/​datacontracts/​GCInfo.md Documents X86 projection rules, units, flags, and limitations.

Review effort: Balanced

davidwrighton and others added 3 commits November 11, 2026 11:26
- Fix funclet pushed-root base, EBP interior-pointer flag, and non-pointer
  push indices in the x86 GCInfo decoder.
- Normalize GS cookie offsets to caller SP (including callee-popped bytes)
  and add SpecialSlotBase.InitialStackPointer for double-aligned frames.
- Interface18: document caller-SP-relative special slots and lifetime base
  value 2 (caller SP); report unrepresentable GS cookies as absent.
- Interface19: add GSCookieBase/Offset/ValidRange fields to
  SOSGCInfoX86Header so double-aligned cookies can be reported.
- Add regression tests and update the GCInfo data contract docs.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 35abd219-305c-4a6c-b33d-3a4d7a665c88
ContextHolder.GetBytes now returns a span (dotnet#137102).

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 35abd219-305c-4a6c-b33d-3a4d7a665c88

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The X86 decoder changes affect shared GC-root stack walking and need specialist review because native-decoder parity and Windows X86 SOS/cDAC behavior could not be independently validated.

No open issues 🎉

4 resolved since last review

Review effort: Balanced

@davidwrighton

Copy link
Copy Markdown
Member Author

/ba-g known issues...

@davidwrighton
davidwrighton merged commit fea4079 into dotnet:main Nov 17, 2026
144 of 149 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
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.

4 participants