Skip to content

[cDAC] Implement DacDbi API GetUserState#130208

Open
rcj1 wants to merge 1 commit into
mainfrom
copilot/implement-dacdbi-getuserstate
Open

[cDAC] Implement DacDbi API GetUserState#130208
rcj1 wants to merge 1 commit into
mainfrom
copilot/implement-dacdbi-getuserstate

Conversation

@rcj1

@rcj1 rcj1 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Implement this API with the use of GC-safety APIs on ExecutionManager (as a relatively thin wrapper) and GCInfo contracts.

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 5, 2026 00:00
@rcj1 rcj1 changed the title Implement cDAC dacdbi GetUserState [cDAC] Implement DacDbi API GetUserState Jul 5, 2026
@rcj1 rcj1 self-assigned this Jul 5, 2026
@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.

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

Implements the cDAC DacDbi GetUserState API by composing existing thread/stack-walk contracts with a new GC-safepoint query, and adds cross-validation coverage in dump tests.

Changes:

  • Implement DacDbiImpl.GetUserState by combining existing partial user state with a new “GC-unsafe point” bit derived from the thread IP.
  • Add IsGcSafe support to the ExecutionManager + GCInfo contract layers (including x86 and the general GCInfo decoder), and document the new APIs.
  • Add a dump test that cross-validates GetUserState against the contracts’ computed GC-safepoint status.
Show a summary per file
File Description
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiThreadDumpTests.cs Adds dump-based cross-validation test for GetUserState vs contract-derived GC-safepoint state.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs Adds CorDebugUserState.USER_UNSAFE_POINT flag used by GetUserState.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs Implements GetUserState using contracts + stack context IP GC-safety check.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/X86/GCInfo.cs Adds x86 IsGcSafe implementation and lazy decode of no-GC regions.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/IGCInfoDecoder.cs Extends internal decoder interface with IsGcSafe.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/GCInfoX86_1.cs Wires IsGcSafe through the x86 IGCInfo implementation.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/GCInfoDecoder.cs Implements IsGcSafe for the general GCInfo decoder path.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/GCInfo_1.cs Wires IsGcSafe through the generic IGCInfo implementation.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManagerCore.cs Adds IExecutionManager.IsGcSafe using CodeBlock resolution + GCInfo decode.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManager_1.cs Exposes IsGcSafe via contract version 1 wrapper.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManager_2.cs Exposes IsGcSafe via contract version 2 wrapper.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IGCInfo.cs Adds new public IGCInfo.IsGcSafe API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IExecutionManager.cs Adds new public IExecutionManager.IsGcSafe API.
docs/design/datacontracts/GCInfo.md Documents IGCInfo.IsGcSafe.
docs/design/datacontracts/ExecutionManager.md Documents IExecutionManager.IsGcSafe.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 4

@rcj1 rcj1 marked this pull request as ready for review July 5, 2026 01:21
public int GetUserState(ulong vmThread, int* pRetVal)
=> LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.GetUserState(vmThread, pRetVal) : HResults.E_NOTIMPL;
{
*pRetVal = default;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This write should be in the try catch to handle NRE

IPlatformAgnosticContext context = IPlatformAgnosticContext.GetContextForPlatform(_target);
byte[] contextBytes = _target.Contracts.StackWalk.GetContext(threadData, ThreadContextSource.Debugger, context.FullContextFlags);
context.FillFromBuffer(contextBytes);
if (!_target.Contracts.ExecutionManager.IsGcSafe(context.InstructionPointer))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This misses some logic that the native has. See:

CrawlFrame * pCF = &(iter.m_crawl);
if (pCF->IsFrameless() && pCF->IsActiveFunc())
{
if (pCF->IsGcSafe())
{
fIsGCSafe = TRUE;
}
}

Is this intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What in particular am I missing here?

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