Skip to content

Add ISOSDacInterface18 for GCInfo inspection APIs#129761

Open
max-charlamb wants to merge 4 commits into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/isosdacinterface18-gcinfo
Open

Add ISOSDacInterface18 for GCInfo inspection APIs#129761
max-charlamb wants to merge 4 commits into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/isosdacinterface18-gcinfo

Conversation

@max-charlamb

@max-charlamb max-charlamb commented Jun 23, 2026

Copy link
Copy Markdown
Member

Note

This content was generated with AI assistance.

ISOSDacInterface18 for GCInfo inspection APIs

Add ISOSDacInterface18 with 4 COM methods exposing GC info data through the cDAC for the SOS !GCInfo command:

  • GetGCInfoHeader -- header fields (version, code size, prolog, stack base register, GS cookie, PSP sym, generics context)
  • GetGCInfoInterruptibleRanges -- code regions where GC can interrupt execution
  • GetGCInfoSafePoints -- specific offsets with point-in-time GC slot liveness
  • GetGCInfoSlotLifetimes -- unified slot lifetime ranges (register + stack combined via SOSGCSlotLifetime with IsRegister discriminator)

IGCInfo contract changes

  • Add GetHeader, GetSafePoints, GetSlotLifetimes to IGCInfo/IGCInfoDecoder
  • Consolidate GetStackBaseRegister and GetSizeOfStackParameterArea into GCInfoHeader (accessed via GetHeader()). These fields require the same decode depth (DecodePoints.ReversePInvoke) as the rest of the header, so there's no performance benefit to keeping them separate.
  • Keep GetCodeLength as a standalone method -- it only decodes to DecodePoints.CodeLength, which is significantly cheaper than the full header decode. Used on the hot path by EEJitManager/InterpreterJitManager/ReadyToRunJitManager for method size lookups.
  • Keep GetCalleePoppedArgumentsSize as a standalone method -- it returns 0 via a default interface method on non-x86 platforms without any decoding. Only x86 reads the ArgCount header field.
  • Eagerly decode safe points in DecodeSafePoints, stored denormalized
  • Single-pass chunk decoder for interruptible slot lifetimes (O(transitions), not O(codeLength))
  • Safe-point-only methods emit [safePointOffset, safePointOffset+1) per live slot per safe point
  • Implement x86 GCInfo support (GetHeader/GetSafePoints/GetSlotLifetimes)
  • Add GenericsContextKind.None as default enum value
  • Fix GSCookieValidRange -- only set when GSCookie is present
  • Native DAC returns E_NOINTERFACE for ISOSDacInterface18 (cDAC-only interface)

Bug fix: ARM thumb bit in relative offset computation

EEJitManager.GetMethodInfo and InterpreterJitManager.GetMethodInfo computed relativeOffset as jittedCodeAddress.Value - codeStart.Value. On ARM (Thumb-2), TargetCodePointer.Value includes the thumb bit (bit 0 = 1), but codeStart (a TargetPointer from the nibble map) does not. This produced a relative offset that was off by 1, causing FindSafePoint and EnumerateLiveSlots to look up the wrong offset.

Fixed by stripping the thumb bit via CodePointerUtils.AddressFromCodePointer before computing the difference. ReadyToRunJitManager was already doing this correctly.

Companion PR

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.

Pull request overview

This PR introduces a new SOS-DAC COM interface (ISOSDacInterface18) intended to expose GCInfo inspection APIs (header, safe points, interruptible ranges, and slot lifetimes), alongside expanding the managed cDAC IGCInfo contract and decoder surface to project the same data.

Changes:

  • Add ISOSDacInterface18 (IDL + prebuilt headers + C# GeneratedComInterface) and wire it up through DAC QueryInterface.
  • Implement GCInfo inspection entrypoints in the native DAC (ClrDataAccess) using GcInfoDecoder / GcInfoDumper, and extend the managed GCInfo decoder/contracts with header/safe point/lifetime APIs.
  • Extend GCInfo platform traits to include PSP symbol encoding base across architectures; add placeholder (E_NOTIMPL) stubs in the managed legacy SOS DAC implementation.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs Adds ISOSDacInterface18 exposure but currently returns E_NOTIMPL for all new methods.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ISOSDacInterface.cs Defines GCInfo structs and ISOSDacInterface18 managed COM declarations.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/X86/GCInfo.cs Implements newly added IGCInfoDecoder members on x86 by throwing NotSupportedException.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/PlatformTraits/RISCV64GCInfoTraits.cs Adds PSP symbol stack-slot encoding base.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/PlatformTraits/LoongArch64GCInfoTraits.cs Adds PSP symbol stack-slot encoding base.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/PlatformTraits/InterpreterGCInfoTraits.cs Adds PSP symbol stack-slot encoding base.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/PlatformTraits/IGCInfoTraits.cs Extends traits interface with PSP_SYM_STACK_SLOT_ENCBASE.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/PlatformTraits/ARMGCInfoTraits.cs Adds PSP symbol stack-slot encoding base.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/PlatformTraits/ARM64GCInfoTraits.cs Adds PSP symbol stack-slot encoding base.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/PlatformTraits/AMD64GCInfoTraits.cs Adds PSP symbol stack-slot encoding base.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/IGCInfoDecoder.cs Expands decoder interface to include header/safe points/lifetimes.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/GCInfoDecoder.cs Adds decoding/projection for header/safe points/lifetimes (includes a correctness issue in safe-point lookup and a potentially expensive lifetime algorithm).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/GCInfo_1.cs Plumbs new IGCInfo contract methods to the decoder implementation.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IGCInfo.cs Adds public contract types (header/lifetime records) and new IGCInfo methods.
src/coreclr/pal/prebuilt/inc/sospriv.h Updates prebuilt SOS-DAC header with new interface and structs.
src/coreclr/pal/prebuilt/idl/sospriv_i.cpp Adds GUID definitions for new SOS-DAC interfaces/enums.
src/coreclr/inc/sospriv.idl Adds IDL definitions for GCInfo structs and ISOSDacInterface18.
src/coreclr/debug/daccess/request.cpp Implements ClrDataAccess::GetGCInfo* methods and supporting helpers.
src/coreclr/debug/daccess/dacimpl.h Extends ClrDataAccess inheritance and declares ISOSDacInterface17/18 methods.
src/coreclr/debug/daccess/daccess.cpp Extends QueryInterface to support ISOSDacInterface17/18.

@max-charlamb max-charlamb force-pushed the dev/max-charlamb/isosdacinterface18-gcinfo branch from 646c0fb to 5310bc9 Compare June 23, 2026 18:28
Copilot AI review requested due to automatic review settings June 23, 2026 18:48
@max-charlamb max-charlamb force-pushed the dev/max-charlamb/isosdacinterface18-gcinfo branch from 5310bc9 to 2f24300 Compare June 23, 2026 18:48

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.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 7 comments.

@max-charlamb max-charlamb force-pushed the dev/max-charlamb/isosdacinterface18-gcinfo branch from 2f24300 to 36cbff5 Compare June 23, 2026 21:06
Copilot AI review requested due to automatic review settings June 24, 2026 14:44
@max-charlamb max-charlamb force-pushed the dev/max-charlamb/isosdacinterface18-gcinfo branch from 36cbff5 to 487271d Compare June 24, 2026 14:44

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.

@max-charlamb max-charlamb force-pushed the dev/max-charlamb/isosdacinterface18-gcinfo branch from 7d34213 to 6be5694 Compare June 30, 2026 20:23
@max-charlamb max-charlamb force-pushed the dev/max-charlamb/isosdacinterface18-gcinfo branch from c5743a4 to 930ed91 Compare July 6, 2026 20:32
@max-charlamb max-charlamb marked this pull request as ready for review July 6, 2026 20:35
Copilot AI review requested due to automatic review settings July 6, 2026 20:35
@max-charlamb max-charlamb changed the title WIP: Add ISOSDacInterface18 for GCInfo inspection APIs Add ISOSDacInterface18 for GCInfo inspection APIs Jul 6, 2026

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/GCInfoX86_1.cs:41

  • GCInfoX86_1 doesn’t implement the new IGCInfo members (GetHeader/GetSafePoints/GetSlotLifetimes). Since these are default interface methods, calls will fall back to the interface default (throwing NotImplementedException) on x86, which will break GcScanner now that it calls GetHeader().
    uint IGCInfo.GetCodeLength(IGCInfoHandle gcInfoHandle)
        => AssertCorrectHandle(gcInfoHandle).GetCodeLength();

    uint IGCInfo.GetCalleePoppedArgumentsSize(IGCInfoHandle gcInfoHandle)
        => AssertCorrectHandle(gcInfoHandle).GetCalleePoppedArgumentsSize();

    IReadOnlyList<InterruptibleRange> IGCInfo.GetInterruptibleRanges(IGCInfoHandle gcInfoHandle)
        => AssertCorrectHandle(gcInfoHandle).GetInterruptibleRanges();

    IReadOnlyList<LiveSlot> IGCInfo.EnumerateLiveSlots(IGCInfoHandle gcInfoHandle, uint instructionOffset, GcSlotEnumerationOptions options)
        => AssertCorrectHandle(gcInfoHandle).EnumerateLiveSlots(instructionOffset, options);

Copilot AI review requested due to automatic review settings July 6, 2026 20:53
@max-charlamb max-charlamb force-pushed the dev/max-charlamb/isosdacinterface18-gcinfo branch from 4719686 to 2643859 Compare July 6, 2026 20:53
@max-charlamb max-charlamb force-pushed the dev/max-charlamb/isosdacinterface18-gcinfo branch from 2643859 to ca43450 Compare July 6, 2026 20:57

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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 6, 2026 20:59
Add tracking for GcTransitionPointer PUSH/POP/KILL actions and
StackDepthTransition in x86 GetSlotLifetimes. Pushed GC pointer
arguments now emit SP-relative stack slot lifetimes from their
push offset to their pop/kill offset.

Also handle register PUSH/POP actions for stack depth tracking
(non-pointer register pushes affect the depth but don't create
GC slot lifetimes).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@max-charlamb max-charlamb force-pushed the dev/max-charlamb/isosdacinterface18-gcinfo branch from ca43450 to b399f34 Compare July 6, 2026 21:03

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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 6, 2026 21:04

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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Copilot AI review requested due to automatic review settings July 6, 2026 21:14

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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

- Fix BaseRegister XML doc: describe as stack base kind (0/1/2), not
  a CPU register number
- Use RegMaskToRegisterNumber helper in x86 GetHeader instead of
  hard-coded register numbers
- Remove unused GetStackBaseRegister/GetSizeOfStackParameterArea
  public methods from GcInfoDecoder (callers use GetHeader)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants