[cDAC] Implement SetDebugState for cDAC#127778
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Implements cDAC-side support for debugger thread state updates by exposing Thread::m_StateNC through the Thread contract and wiring DacDbiImpl.SetDebugState to set/reset the debugger-suspend bit, with matching tests and contract docs.
Changes:
- Added
StateNCto the native and managed thread data descriptors and documented the new contract dependency. - Added
ThreadStateNoConcurrencyplusSetThreadState/ResetThreadStateon the cDACIThreadcontract and used them fromDacDbiImpl.SetDebugState. - Added contract-level unit tests for set/reset/idempotent behavior and updated Thread contract documentation.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/native/managed/cdac/tests/ThreadTests.cs |
Adds contract-level tests for setting/resetting StateNC. |
src/native/managed/cdac/tests/MockDescriptors/MockDescriptors.Thread.cs |
Extends mock thread layout with StateNC. |
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs |
Adds managed projection enum for debug thread state values. |
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs |
Implements SetDebugState via the Thread contract. |
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Thread.cs |
Adds StateNC member for descriptor name binding. |
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.cs |
Implements SetThreadState / ResetThreadState and reuses cached thread type info. |
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IThread.cs |
Expands the public Thread contract with the new enum and mutating methods. |
src/coreclr/vm/threads.h |
Annotates native enum values as contract-dependent and exports StateNC offset. |
src/coreclr/vm/datadescriptor/datadescriptor.inc |
Publishes Thread.StateNC in the cDAC data descriptor. |
docs/design/datacontracts/Thread.md |
Documents the new enum, APIs, and descriptor dependency. |
Comments suppressed due to low confidence (1)
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs:706
SetDebugStateadds new DacDbi behavior, but the PR only adds contract-levelThreadTests. This leaves the DacDbi layer untested for the behaviors this method owns (notably HRESULT mapping for invalid states and the end-to-end state change through the legacy-facing API). The cDAC test guidance insrc/native/managed/cdac/tests/README.md:21-32calls for API-implementation-level tests when adding a new wrapper method backed by an existing contract.
Contracts.ThreadData threadData = _target.Contracts.Thread.GetThreadData(new TargetPointer(vmThread));
if ((threadData.State & (Contracts.ThreadState.Stopped | Contracts.ThreadState.Unstarted | Contracts.ThreadState.Detached)) != 0)
throw Marshal.GetExceptionForHR(CorDbgHResults.CORDBG_E_BAD_THREAD_STATE)!;
*pRetVal = threadData.ExposedObjectHandle.Value;
}
catch (System.Exception ex)
{
hr = ex.HResult;
}
#if DEBUG
if (_legacy is not null)
{
ulong retValLocal;
int hrLocal = _legacy.GetThreadObject(vmThread, &retValLocal);
Debug.ValidateHResult(hr, hrLocal);
if (hr == HResults.S_OK)
Debug.Assert(*pRetVal == retValLocal, $"cDAC: {*pRetVal:x}, DAC: {retValLocal:x}");
jkotas
reviewed
May 5, 2026
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
jkotas
reviewed
May 11, 2026
jkotas
approved these changes
May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implement
SetDebugStatein the cDAC. Separates debugger-controlled thread state from ThreadStateNoConcurrency into a new Volatile field to avoid read-modify-write races, and exposes it through the Thread contract.Changes
DacDbiImpl.SetDebugStatewith#if DEBUGlegacy validationThread.mdcontract documentationTest Results
16 new test runs across all architectures. Existing tests pass.