Skip to content

Use DAC GCInfo interfaces for X86 SOS reporting, and address bugs in DAC GCInfo interface handling for other platforms - #6198

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

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

Conversation

@davidwrighton

@davidwrighton davidwrighton commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

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.

davidwrighton and others added 3 commits November 6, 2026 15:10
Display X86 headers and decoded push/pop transitions, correct common slot formatting and preserve compatibility with legacy GCInfo output in SOS tests.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
Delegate register naming and optional X86 details to IMachine without changing machine-selection guards. Only missing Interface18 permits automatic legacy decoding; report errors from available interfaces. Preserve the explicit -legacy comparison switch.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
Respect the pointer flag for EBP push reporting and label pops as argument counts rather than pointer counts. Regress against legacy output from the existing dictionary scenario under X86 Cdb and dotnet-dump cDAC configurations.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
davidwrighton and others added 2 commits November 6, 2026 16:47
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
Follow existing machine-class virtual declaration style to avoid Clang's inconsistent-missing-override errors. Gate supplemental X86 assertions on actual reporting capability rather than DAC selection.

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

Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
@davidwrighton davidwrighton changed the title [Prototype] Use DAC GCInfo interfaces for X86 SOS reporting Use DAC GCInfo interfaces for X86 SOS reporting, and address bugs in DAC GCInfo interface handling for other platforms Nov 10, 2026
@davidwrighton
davidwrighton marked this pull request as ready for review November 10, 2026 19:51
@davidwrighton
davidwrighton requested a review from a team as a code owner November 10, 2026 19:51
@davidwrighton
davidwrighton requested a balanced review from Copilot November 10, 2026 20:09

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.

🟢 Approval recommended

No active review issues were identified for the DAC-based X86 GCInfo reporting and formatting changes.

No open issues 🎉

What changed in this PR

Adds prototype DAC-interface-based X86 GCInfo reporting to SOS, paired with the companion runtime changes. It also improves shared GCInfo formatting while preserving legacy decoding for runtimes without Interface18 and explicit -legacy comparisons.

Changes:

  • Uses Interface18 for common GCInfo and optional Interface19 for X86 details, with architecture-specific formatting through IMachine.
  • Corrects root and argument formatting and reports interface failures instead of silently falling back.
  • Updates parsers and tests for legacy/interface output, including X86 non-pointer push/pop regression coverage.
File Description
src/​tests/​SOS.Tests/​CodeInfoTests.cs Adds legacy comparisons and X86 push/pop regression checks.
src/​tests/​SOS.Tests/​CodeCommandParsingTests.cs Tests hexadecimal sizes and qualified interface roots.
src/​tests/​SOS.Tests/​CodeCommandParsing.cs Supports -legacy and expanded GCInfo output formats.
src/​tests/​SOS.Tests/​ClrUTests.cs Checks standalone and interleaved GCInfo consistency.
src/​SOS/​Strike/​strike.cpp Restricts automatic fallback to absent Interface18 and reports failures.
src/​SOS/​Strike/​gcinfoprovider.h Adds X86 supplemental data storage and clarifies creation results.
src/​SOS/​Strike/​gcinfoprovider.cpp Validates interface results and improves root and transition formatting.
src/​SOS/​Strike/​exts.h Adds machine-specific GCInfo retrieval and formatting hooks.
src/​SOS/​Strike/​disasmRISCV64.cpp Provides RISC-V register-name mapping for interface output.
src/​SOS/​Strike/​disasmLOONGARCH64.cpp Provides LoongArch register-name mapping for interface output.
src/​SOS/​Strike/​disasm.h Declares architecture-specific GCInfo overrides.
src/​SOS/​Strike/​disasm.cpp Implements X86 supplemental reporting and register-name mappings.
src/​shared/​pal/​prebuilt/​inc/​sospriv.h Adds prebuilt Interface19 declarations and X86 data structures.
src/​shared/​pal/​prebuilt/​idl/​sospriv_i.cpp Adds the Interface19 identifier.
src/​shared/​inc/​sospriv.idl Defines the optional X86 GCInfo interface contract.

Review effort: Balanced

@davidwrighton
davidwrighton merged commit f2b03ce into dotnet:main Nov 10, 2026
25 checks passed
davidwrighton added a commit to dotnet/runtime that referenced this pull request Nov 17, 2026
## 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](https://gist.github.com/davidwrighton/1f07d7c37e663beebb32b07f384fdc32).

## 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.

---------

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 352b31fe-6b43-42a3-89cf-1944f4642820
Copilot-Session: 35abd219-305c-4a6c-b33d-3a4d7a665c88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants