Skip to content

[cDAC] Fix bug in GetThreadData#126592

Merged
rcj1 merged 8 commits intodotnet:mainfrom
rcj1:fix-thread-state-bug
Apr 11, 2026
Merged

[cDAC] Fix bug in GetThreadData#126592
rcj1 merged 8 commits intodotnet:mainfrom
rcj1:fix-thread-state-bug

Conversation

@rcj1
Copy link
Copy Markdown
Contributor

@rcj1 rcj1 commented Apr 6, 2026

We have to ensure that the thread is reported as dead when either Dead or ReportDead are set. There are, however, certain cases where it is useful to distinguish between the two, for example GetThreadOwningMonitorLock.

Copilot AI review requested due to automatic review settings April 6, 2026 23:14
@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.

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

This PR fixes cDAC thread “dead” semantics by treating ThreadState.ReportDead as dead for enumeration and IsThreadMarkedDead, while still allowing callers to distinguish Dead vs ReportDead when needed (e.g., monitor-lock ownership queries).

Changes:

  • Update thread enumeration and IsThreadMarkedDead to consider ReportDead as dead.
  • Extend the managed thread contract to surface ReportDead and convert runtime state bits into contract flags.
  • Adjust Thread contract documentation to reflect that raw runtime state requires conversion to the contract enum.

Reviewed changes

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

File Description
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs Treat ReportDead threads as dead for enumeration and IsThreadMarkedDead.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.cs Add mapping from runtime Thread::State bits (incl. TS_ReportDead) into contract ThreadState.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IThread.cs Add ThreadState.ReportDead to the public contract enum.
docs/design/datacontracts/Thread.md Note that Thread::State should be converted to the contract enum rather than used as a raw integer.

Copy link
Copy Markdown
Member

@max-charlamb max-charlamb left a comment

Choose a reason for hiding this comment

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

lgtm

Copilot AI review requested due to automatic review settings April 10, 2026 17:43
@rcj1 rcj1 force-pushed the fix-thread-state-bug branch from 87ae76b to 6561442 Compare April 10, 2026 17:46
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 16 out of 16 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

src/coreclr/vm/comsynchronizable.cpp:408

  • ThreadNative_GetThreadState now reads the raw m_State via GetState(), but still only treats TS_Dead as "stopped". Previously GetSnapshotState() ORed TS_Dead when the reporting bit was set (now TS_Stopped), so this will fail to report shutting-down threads as stopped. Update the condition to treat TS_Stopped (and likely TS_Dead as well) as ThreadStopped to preserve behavior.
    // grab a snapshot
    Thread::ThreadState state = thread->GetState();

    if (state & Thread::TS_Dead)
        res |= ThreadNative::ThreadStopped;

Copilot AI review requested due to automatic review settings April 10, 2026 21:22
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 17 out of 17 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks!

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copilot AI review requested due to automatic review settings April 11, 2026 18:27
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 17 out of 17 changed files in this pull request and generated 1 comment.

@rcj1 rcj1 merged commit 9bb0c1e into dotnet:main Apr 11, 2026
112 of 126 checks passed
@rcj1 rcj1 deleted the fix-thread-state-bug branch April 11, 2026 21:00
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