Remove TEB field from Thread, DAC, and cDAC#126902
Merged
max-charlamb merged 2 commits intodotnet:mainfrom Apr 15, 2026
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
aa402c9 to
d0e418d
Compare
The TEB (Thread Environment Block) pointer was stored in Thread::m_pTEB and exposed through the DAC via DacpThreadData.teb and through the cDAC via the Thread data contract. Consumers (SOS, ClrMD) can instead look up the TEB from the OS thread ID via the debugger's native API, which does not depend on the runtime carrying this value. Changes: - request.cpp: Always set threadData->teb to NULL (field retained for binary layout compatibility of DacpThreadData) - datadescriptor.inc: Remove TEB field from Thread type descriptor - threads.h: Remove TEB from cdac_data<Thread> - Data/Thread.cs: Remove TEB property and reading logic - Thread_1.cs: Remove TEB from ThreadData construction - IThread.cs: Remove TEB from ThreadData record - SOSDacImpl.cs: Set data->teb = 0, remove debug assertion - Thread.md: Remove TEB from data contract documentation - Test mocks: Remove TEB from mock thread descriptors Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The m_pTEB field cached a pointer to the thread's TEB (_NT_TIB) that was only used in three places: - GetTEB() accessor - no longer called by any consumer - GetExceptionListPtr() - dead code, never called - Debug-only stack bounds check in RedirectThreadAtHandledJITCase The debug check now uses GetCachedStackBase/Limit which are already cached on the Thread object. The cached stack limit (from VirtualQuery) is slightly more permissive than the TEB's committed stack limit, which is acceptable for a diagnostic assert. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d0e418d to
7a7bfc2
Compare
Member
|
|
hoyosjs
approved these changes
Apr 15, 2026
This was referenced Apr 15, 2026
max-charlamb
added a commit
to dotnet/diagnostics
that referenced
this pull request
Apr 16, 2026
> [!NOTE] > This PR was generated with the assistance of GitHub Copilot. ## Summary Stop reading the TEB from `DacpThreadData.teb` in the `!Threads` command and instead look it up via `IDebuggerServices::GetThreadTeb(osThreadId)`. This decouples SOS from a runtime-internal field that is being removed from the DAC/cDAC Thread data contract. ## Changes ### strike.cpp The `!Threads` command reads the COM apartment state (STA/MTA/NTA) by dereferencing `TEB.ReservedForOle`. Previously it used `Thread.teb` from `DacpThreadData`; now it calls `GetDebuggerServices()->GetThreadTeb(Thread.osThreadId)` to get the TEB address. ### New test: ThreadApartment Added a new SOS integration test that validates `clrthreads` properly displays COM apartment state: - **Debuggee**: Creates one STA thread (`SetApartmentState(STA)`) and one MTA thread before breaking - **Script**: Verifies the Apt column contains both STA and MTA values - **Windows-only**: Guarded in both the test method (`OS.Kind != OSKind.Windows`) and the script (`IFDEF:WINDOWS`) ## Verification Manually verified with cdb against a dump containing STA/MTA threads: - Original SOS: STA 1, MTA 4 - New SOS: STA 1, MTA 4 (identical output) ## Related PRs - dotnet/runtime#126902 — Removes TEB from the Thread data contract and DAC (always returns 0) --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Note
This PR was generated with the assistance of GitHub Copilot.
Summary
Remove the TEB (Thread Environment Block) pointer from the DAC/cDAC Thread data contract. Consumers should look up the TEB from the OS thread ID via the debugger's native API instead.
Background
The
Thread::m_pTEBfield was exposed throughDacpThreadData.teband through the cDACThreadData.TEBcontract field. Analysis of all consumers shows:DacpThreadData.tebin one place (strike.cpp:4460) to display COM apartment state in!Threads. A companion PR in dotnet/diagnostics switches this to useIDebuggerServices::GetThreadTeb(osThreadId)instead.DacpThreadData.Tebto deriveStackBase/StackLimit. A companion PR in microsoft/clrmd switches this to useIThreadReader.GetThreadTeb(osThreadId)instead.TargetPointer.Nullfor TEB.Changes
request.cpp: Always setthreadData->teb = NULL(field retained for binary layout compatibility)datadescriptor.inc: Remove TEB field from Thread type descriptorthreads.h: Remove TEB fromcdac_data<Thread>Data/Thread.cs: Remove TEB property and reading logicThread_1.cs: Remove TEB from ThreadData constructionIThread.cs: Remove TEB from ThreadData recordSOSDacImpl.cs: Setdata->teb = 0, remove debug assertionThread.md: Remove TEB from data contract documentationCompanion PRs
GetThreadTeb(osThreadId)for apartment state display + new ThreadApartment regression testDacRuntimeswitches toIThreadReader.GetThreadTeb(osThreadId)for stack boundsValidation
!Threadsoutput identical between legacy DAC and cDAC (Release)