Skip to content

[cDac] Implement thread state - #130029

Merged
leculver merged 13 commits into
dotnet:mainfrom
leculver:restore-thread-state
Jul 7, 2026
Merged

leculver merged 13 commits into
dotnet:mainfrom
leculver:restore-thread-state

Conversation

@leculver

@leculver leculver commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

PR #126592 ("[cDAC] Fix bug in GetThreadData") removed threadData->state = thread->m_State; from ClrDataAccess::GetThreadData while reworking dead-thread reporting in a different path. We still use a LOT of the enums in threadstate to debug the runtime. In addition to the few that were previously wrapped:

  1. The GC/debug suspension flags are critical to diagnosing hangs.
  2. The COM apartment flags aren't used often, but do help us track down com issues (especially hangs due to apartment cross-calls).
  3. The thread abort ones are not critical in most cases, but if they were to be present it would be a HUGE clue as to what's wrong wiht the process (someone is using an obsolete feature they shouldn't).

Once I wrapped those, I didn't have a good reason to not just finish the enum.

@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

Restores DacpThreadData::state population in the legacy DAC implementation of ClrDataAccess::GetThreadData, ensuring consumers (e.g., SOS) can once again observe per-thread ThreadState flags instead of the zero-initialized default.

Changes:

  • Re-add assignment of threadData->state from Thread::m_State in ClrDataAccess::GetThreadData.
Show a summary per file
File Description
src/coreclr/debug/daccess/request.cpp Restores DacpThreadData::state reporting by copying the thread’s m_State into the returned struct.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@max-charlamb

Copy link
Copy Markdown
Member

It looks like this method is implemented in SOSDacImpl.cs (cDAC) and should be updated as well.

@leculver

Copy link
Copy Markdown
Contributor Author

Good catch. This says: data->state = 0; // Set to 0, nobody uses this which is incorrect. Having the threadstate is critical to debugging runtime hangs.

@leculver leculver changed the title Restore DacpThreadData::state in GetThreadData [cDac] Implement thread state Jun 30, 2026
@leculver
leculver requested a review from jkotas June 30, 2026 13:36
@leculver

Copy link
Copy Markdown
Contributor Author

@jkotas Any objections here? We already half-wrapped the enum. After adding the suspension related values (which we need for investigations like #128401), and COM related ones (which are also needed, though rarely) I went ahead and finished the enum to not make it swiss cheese. Happy to just wrap the exact ones we need if that's the preference.

@jkotas

jkotas commented Jun 30, 2026

Copy link
Copy Markdown
Member

We should be only exposing the values that are actually needed by the diagnostic stack.

@jkotas

jkotas commented Jun 30, 2026

Copy link
Copy Markdown
Member

After adding the suspension related values (which we need for investigations like #128401)

Just because of you need the value for some investigation does not mean that it should be exposed by the diagnostic contract.

You can always dump the full content of the Thread using dt and let AI reason about it.

Copilot AI review requested due to automatic review settings June 30, 2026 13:54
@leculver

Copy link
Copy Markdown
Contributor Author

I've scaled back to just the exact enum flags we use.

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's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 3

Comment thread docs/design/datacontracts/Thread.md Resolved
@leculver

leculver commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Just because of you need the value for some investigation does not mean that it should be exposed by the diagnostic contract.

You can always dump the full content of the Thread using dt and let AI reason about it.

If it's not exposed by the contract, it won't be produced by SOS or tools like ClrMD. When a dump can contain hundreds or thousands of threads, it's not a fun prospect to spend 20 minutes digging through every Thread instance. SOS's !clrthreads output immediately pops out as a "one of these things is not like the other" when these state bits are set, and we rely on these specific ones the PR now has wrapped for some automated analysis as well.

I'm fine with not wrapping the whole enum, but we really do need these to not be something that has to be dug out by hand in the debugger, or (for our automated analysis) require a pdb where we don't need one today.

Comment thread docs/design/datacontracts/Thread.md Resolved
Copilot AI review requested due to automatic review settings June 30, 2026 16:09

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's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 3

Comment thread src/coreclr/vm/threads.h Resolved
Comment thread docs/design/datacontracts/Thread.md Resolved
Comment thread src/coreclr/vm/threads.h Resolved
Copilot AI review requested due to automatic review settings June 30, 2026 18:36
Copilot AI review requested due to automatic review settings July 7, 2026 14:57
@leculver
leculver force-pushed the restore-thread-state branch from 0cfe1b5 to 0772208 Compare July 7, 2026 14:57
@leculver
leculver requested a review from jkotas July 7, 2026 15:01

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's findings

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

Comment thread src/coreclr/vm/threads.h Resolved
Comment thread docs/design/datacontracts/Thread.md Resolved
Copilot AI review requested due to automatic review settings July 7, 2026 15:06
Co-authored-by: Copilot Autofix powered by AI <[email protected]>

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's findings

  • Files reviewed: 11/11 changed files
  • Comments generated: 2

Comment thread docs/design/datacontracts/Thread.md Resolved
Comment thread src/coreclr/vm/threadsuspend.cpp Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings July 7, 2026 15:22

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's findings

  • Files reviewed: 11/11 changed files
  • Comments generated: 1

Comment thread docs/design/datacontracts/Thread.md Resolved
@leculver
leculver enabled auto-merge (squash) July 7, 2026 15:56
@leculver
leculver merged commit 03ba8a2 into dotnet:main Jul 7, 2026
141 checks passed
@leculver
leculver deleted the restore-thread-state branch July 7, 2026 19:44
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 8, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
PR #126592 ("[cDAC] Fix bug in GetThreadData") removed
`threadData->state = thread->m_State;` from ClrDataAccess::GetThreadData
while reworking dead-thread reporting in a different path. We still use
a LOT of the enums in threadstate to debug the runtime. In addition to
the few that were previously wrapped:

1. The GC/debug suspension flags are critical to diagnosing hangs.
2. The COM apartment flags aren't used often, but do help us track down
com issues (especially hangs due to apartment cross-calls).
3. The thread abort ones are not critical in most cases, but if they
were to be present it would be a HUGE clue as to what's wrong wiht the
process (someone is using an obsolete feature they shouldn't).

Once I wrapped those, I didn't have a good reason to not just finish the
enum.

---------

Co-authored-by: Jan Kotas <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants