Skip to content

[cDAC] Implement GetPartialUserState for cDAC#127848

Merged
barosiak merged 7 commits intodotnet:mainfrom
barosiak:barosiak/GetPartialUserState
May 8, 2026
Merged

[cDAC] Implement GetPartialUserState for cDAC#127848
barosiak merged 7 commits intodotnet:mainfrom
barosiak:barosiak/GetPartialUserState

Conversation

@barosiak
Copy link
Copy Markdown
Member

@barosiak barosiak commented May 6, 2026

Summary

Replaces the legacy-delegation stub in DacDbiImpl.GetPartialUserState with a managed implementation using the IThread contract, mirroring the native C++ logic in dacdbiimpl.cpp that maps thread state flags to CorDebugUserState.

Changes

  • Rename TS_Interruptible to TS_WaitSleepJoin and remove TSNC_DebuggerSleepWaitJoin from ThreadStateNC across all VM consumers
  • Add WaitSleepJoin to ThreadState enum (from m_State)
  • Implement GetPartialUserState in DacDbiImpl with DEBUG cross-validation
  • Add CorDebugUserState typed enum to IDacDbiInterface
  • Update data descriptor, contract docs, and VM annotations
  • Add unit and dump tests

@barosiak barosiak requested review from max-charlamb, noahfalk and rcj1 May 6, 2026 01:56
@barosiak barosiak self-assigned this May 6, 2026
Copilot AI review requested due to automatic review settings May 6, 2026 01:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements DacDbiImpl.GetPartialUserState in the managed cDAC reader by mapping thread state flags from the IThread contract (including new Interruptible and StateNC/ThreadStateNC) to a typed CorDebugUserState, and adds unit + dump-based tests to validate the mapping.

Changes:

  • Extend the Thread contract surface to expose Interruptible plus a new StateNC field (ThreadStateNC) and plumb it through descriptors, data model, and contract implementation.
  • Replace the legacy-delegation stub for GetPartialUserState with a managed implementation (plus DEBUG cross-validation against legacy DAC).
  • Add unit and dump tests validating state-flag mapping and GetPartialUserState results.

Reviewed changes

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

Show a summary per file
File Description
src/native/managed/cdac/tests/ThreadTests.cs Adds a unit test ensuring raw state fields map to ThreadState / ThreadStateNC.
src/native/managed/cdac/tests/MockDescriptors/MockDescriptors.Thread.cs Extends mock Thread layout to include StateNC and exposes setters.
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiThreadDumpTests.cs Adds dump test cross-validating GetPartialUserState against IThread contract data.
src/native/managed/cdac/tests/ClrDataExceptionStateTests.cs Updates mocks constructing ThreadData to include the new StateNC field.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs Introduces typed CorDebugUserState and updates GetPartialUserState signature.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs Implements GetPartialUserState using thread contract data and DEBUG cross-validation.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Thread.cs Reads new StateNC field from the Thread data descriptor.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.cs Maps StateNC into ThreadData and adds Interruptible mapping.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IThread.cs Extends ThreadState, adds ThreadStateNC, and adds StateNC to ThreadData.
src/coreclr/vm/threads.h Annotates thread state bits and adds m_StateNC to the cDAC data offsets.
src/coreclr/vm/datadescriptor/datadescriptor.inc Adds Thread.StateNC field to the cDAC data descriptor.
docs/design/datacontracts/Thread.md Documents new ThreadState.Interruptible, ThreadStateNC, and ThreadData.StateNC.

Comment thread src/coreclr/vm/threads.h Outdated
Comment thread src/coreclr/vm/threads.h Outdated
Copilot AI review requested due to automatic review settings May 6, 2026 23:05
@barosiak barosiak requested a review from jkotas May 6, 2026 23:09
Comment thread src/coreclr/debug/daccess/dacdbiimpl.cpp Outdated
Comment thread src/coreclr/vm/threads.h Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 14 out of 14 changed files in this pull request and generated 1 comment.

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

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copilot AI review requested due to automatic review settings May 7, 2026 19:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 14 out of 14 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs:163

  • This adds new public API surface (public enum CorDebugUserState and a public COM interface method signature change using it), but the PR description doesn't link an api-approved issue/proposal. If this surface is intended to be consumable outside this assembly, it should go through API review; otherwise consider making the enum (and/or the updated signature surface) internal to avoid committing to a public contract prematurely.
[Flags]
public enum CorDebugUserState
{
    USER_BACKGROUND = 0x04,
    USER_UNSTARTED = 0x08,
    USER_STOPPED = 0x10,
    USER_WAIT_SLEEP_JOIN = 0x20,
    USER_THREADPOOL = 0x100,
}

// Name-surface projection of IDacDbiInterface in native method order for COM binding validation.
// Parameter shapes are intentionally coarse placeholders and will be refined with method implementation work.
[GeneratedComInterface]
[Guid("DB505C1B-A327-4A46-8C32-AF55A56F8E09")]
public unsafe partial interface IDacDbiInterface

src/coreclr/debug/daccess/dacdbiimpl.cpp:5698

  • GetPartialUserState no longer uses the historical workaround for Wait/Sleep/Join detection (previously checking TS_Interruptible OR the non-concurrency TSNC_DebuggerSleepWaitJoin bit, with an in-code note that TS_Interruptible was unreliable). This change makes debugger/DAC user state depend solely on TS_WaitSleepJoin being accurate in all cases. If the underlying reliability concern is still relevant, this could be a behavior regression; if it has been fixed, please add an updated comment (or test coverage) documenting why the NC bit is no longer needed. Related changes are in threads.h (removing the TSNC flag) and comsynchronizable.cpp (no longer setting it).
        // Don't report a StopRequested if the thread has actually stopped.
        if (ts & Thread::TS_Stopped)
        {
            result |= USER_STOPPED;
        }

        if (ts & Thread::TS_WaitSleepJoin)
        {
            result |= USER_WAIT_SLEEP_JOIN;
        }

Comment thread src/native/managed/cdac/tests/ThreadTests.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 7, 2026 21:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 14 out of 14 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/debug/daccess/dacdbiimpl.cpp
@barosiak barosiak enabled auto-merge (squash) May 7, 2026 21:46
@barosiak barosiak merged commit fd9ddfa into dotnet:main May 8, 2026
121 of 123 checks passed
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.

5 participants