[cDAC] Relax HRESULT validation to allow divergent failure codes#125236
Merged
max-charlamb merged 1 commit intodotnet:mainfrom Mar 6, 2026
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the cDAC Legacy layer’s DEBUG cross-validation to stop asserting on exact HRESULT equality when both the cDAC and legacy/native DAC correctly fail, but return different failure codes. This avoids debugger-process termination and associated test flakiness while still preserving strict validation for success results.
Changes:
- Introduces
Debug.ValidateHResult()(withHResultValidationMode) to centralize HRESULT comparison rules. - Replaces ~113
Debug.Assert(hrLocal == hr, ...)call sites withDebug.ValidateHResult(hr, hrLocal)across the Legacy implementation. - Preserves strict matching for success HRESULTs while allowing divergent failure HRESULTs by default.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs | Replaces legacy-vs-cDAC HRESULT equality asserts with Debug.ValidateHResult. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs | Same replacement for IXCLRDataProcess-related validation asserts. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataStackWalk.cs | Uses Debug.ValidateHResult when cross-validating stack-walk HRESULTs in DEBUG. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodInstance.cs | Replaces per-site “allow any failing HRESULT” logic with the shared validator. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataFrame.cs | Updates frame HRESULT validation to use the shared validator. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/DebugExtensions.cs | Adds centralized HRESULT validation helper and mode enum. |
rcj1
approved these changes
Mar 5, 2026
Contributor
rcj1
left a comment
There was a problem hiding this comment.
As long as none of these callers differentiate between failures, then looks good to me
noahfalk
approved these changes
Mar 6, 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
The cDAC's DEBUG validation asserts compare HRESULTs between the cDAC and legacy DAC using exact equality (
Debug.Assert(hrLocal == hr)). This causes the debugger process to crash when the cDAC and native DAC return different failure HRESULTs for the same invalid input.For example, when
GetMethodTableDatais called with a garbage method table pointer, the cDAC may throwInvalidOperationException(0x80131C49) while the native DAC returnsE_INVALIDARG(0x80070057). Both correctly reject the input, but the exact HRESULT comparison fires a fatalDebug.Assertthat terminates the debugger mid-command — causing flaky CI failures likeSOS.VarargPInvokeInteropMDin thecDAC_windows_x64_releasejob.No consumer (ClrMD, SOS, managed debugger) branches on specific failure codes from these APIs — they only check success vs failure.
Changes
New file:
DebugExtensions.cs— addsDebug.ValidateHResult()as a C# 14 static extension method onSystem.Diagnostics.Debug:With two validation modes via
HResultValidationMode:Exact— HRESULTs must match exactly (available for APIs where the specific code matters)AllowDivergentFailures(default) — success HRESULTs (S_OK,S_FALSE) must match exactly, but any two failing HRESULTs (negative values) are considered equivalentConverted all 113 call sites across 5 files from:
to: