Fix premature returns for argument/pointer checks in SOSDacImpl.cs#124814
Merged
Fix premature returns for argument/pointer checks in SOSDacImpl.cs#124814
Conversation
Contributor
|
Tagging subscribers to this area: @agocke |
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
…x GetPEFileName E_NOTIMPL Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix argument and pointer checks in SOSDacImpl.cs
Fix premature returns for argument/pointer checks in SOSDacImpl.cs
Feb 24, 2026
max-charlamb
approved these changes
Feb 24, 2026
Member
max-charlamb
left a comment
There was a problem hiding this comment.
lgtm, nice cleanup.
Especially good find on the bug in GetThreadFromThinlockID
rcj1
reviewed
Feb 24, 2026
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors error handling in SOSDacImpl.cs by moving argument and pointer validation checks from before try blocks to inside try blocks, converting early returns to thrown exceptions. The goal is to ensure that the catch block can handle HResult conversion and that DEBUG comparison blocks work correctly.
Changes:
- Moved null pointer and invalid argument checks from before try blocks to inside try blocks across approximately 30 methods
- Changed early
return HResults.E_INVALIDARGstatements tothrow new ArgumentException()inside try blocks - Changed early
return HResults.E_POINTERstatements tothrow new NullReferenceException()inside try blocks - Restructured methods like
GetILForModule,GetMethodDescFromToken, andTraverseModuleMapfrom if/else structures to unified try/catch blocks - Added try/catch wrapper to
SOSMethodEnum.GetCount
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
noahfalk
added a commit
to noahfalk/runtime
that referenced
this pull request
Feb 26, 2026
…atch, use heapData.GenerationTable.Count, and use local buffers for debug cross-validation - Change void* to DacpGenerationData* in ISOSDacInterface8 methods - Move null/validation checks inside try/catch blocks per PR dotnet#124814 pattern - Replace ReadGlobal<uint>(TotalGenerationCount) with heapData.GenerationTable.Count - Use local buffers for legacy DAC cross-validation to avoid overwriting cDAC data - Use 'is null'/'is not null' instead of '== null'/'!= null' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
noahfalk
added a commit
to noahfalk/runtime
that referenced
this pull request
Feb 26, 2026
…atch, use heapData.GenerationTable.Count, and use local buffers for debug cross-validation - Change void* to DacpGenerationData* in ISOSDacInterface8 methods - Move null/validation checks inside try/catch blocks per PR dotnet#124814 pattern - Replace ReadGlobal<uint>(TotalGenerationCount) with heapData.GenerationTable.Count - Use local buffers for legacy DAC cross-validation to avoid overwriting cDAC data - Use 'is null'/'is not null' instead of '== null'/'!= null' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
noahfalk
added a commit
to noahfalk/runtime
that referenced
this pull request
Mar 1, 2026
…atch, use heapData.GenerationTable.Count, and use local buffers for debug cross-validation - Change void* to DacpGenerationData* in ISOSDacInterface8 methods - Move null/validation checks inside try/catch blocks per PR dotnet#124814 pattern - Replace ReadGlobal<uint>(TotalGenerationCount) with heapData.GenerationTable.Count - Use local buffers for legacy DAC cross-validation to avoid overwriting cDAC data - Use 'is null'/'is not null' instead of '== null'/'!= null' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
iremyux
pushed a commit
to iremyux/dotnet-runtime
that referenced
this pull request
Mar 2, 2026
…otnet#124814) ## Description Argument and pointer validation checks at the start of `SOSDacImpl` methods were returning early (before the `try/catch`), bypassing the catch block's HResult conversion and the `#if DEBUG` legacy comparison block. ### Changes - **E_INVALIDARG checks** → moved inside `try`, replaced `return HResults.E_INVALIDARG` with `throw new ArgumentException()` - **E_POINTER checks** → moved inside `try`, replaced `return HResults.E_POINTER` with `throw new NullReferenceException()` - **`if/else` guard patterns** (ISOSDacInterface14 methods, `GetILForModule`, `GetMethodDescFromToken`, `TraverseModuleMap`) → flattened into unified `try/catch` with throws - **Switch `default:` cases** (`GetMethodDescFromToken`, `TraverseModuleMap`) → replaced `hr = HResults.E_INVALIDARG` with `throw new ArgumentException()` so execution halts rather than falling through - **`GetPEFileName`** → inner `return HResults.E_NOTIMPL` inside `try` replaced with `throw new NotImplementedException()` to prevent `CopyStringToBuffer` from running on empty paths - **`SOSMethodEnum.GetCount`** → added `try/catch` wrapper; `return HResults.E_POINTER` → `throw new NullReferenceException()` - **`GetThreadFromThinlockID`** → fixed latent bug: null check was setting `hr` but not preventing the `try` block from running, causing `*pThread` dereference on a null pointer **Before / After pattern:** ```csharp // Before — bypasses catch and #if DEBUG block int ISOSDacInterface.GetThreadData(ClrDataAddress thread, DacpThreadData* data) { if (thread == 0 || data == null) return HResults.E_INVALIDARG; // skips try/catch and DEBUG comparison int hr = HResults.S_OK; try { ... } catch (Exception ex) { hr = ex.HResult; } ... } // After — check participates in unified error handling int ISOSDacInterface.GetThreadData(ClrDataAddress thread, DacpThreadData* data) { int hr = HResults.S_OK; try { if (thread == 0 || data == null) throw new ArgumentException(); ... } catch (Exception ex) { hr = ex.HResult; } ... } ``` ## Testing - All 832 existing cDAC unit tests pass. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/runtime/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rcj1 <77995559+rcj1@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.
Description
Argument and pointer validation checks at the start of
SOSDacImplmethods were returning early (before thetry/catch), bypassing the catch block's HResult conversion and the#if DEBUGlegacy comparison block.Changes
try, replacedreturn HResults.E_INVALIDARGwiththrow new ArgumentException()try, replacedreturn HResults.E_POINTERwiththrow new NullReferenceException()if/elseguard patterns (ISOSDacInterface14 methods,GetILForModule,GetMethodDescFromToken,TraverseModuleMap) → flattened into unifiedtry/catchwith throwsdefault:cases (GetMethodDescFromToken,TraverseModuleMap) → replacedhr = HResults.E_INVALIDARGwiththrow new ArgumentException()so execution halts rather than falling throughGetPEFileName→ innerreturn HResults.E_NOTIMPLinsidetryreplaced withthrow new NotImplementedException()to preventCopyStringToBufferfrom running on empty pathsSOSMethodEnum.GetCount→ addedtry/catchwrapper;return HResults.E_POINTER→throw new NullReferenceException()GetThreadFromThinlockID→ fixed latent bug: null check was settinghrbut not preventing thetryblock from running, causing*pThreaddereference on a null pointerBefore / After pattern:
Testing
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.