Uh oh!
There was an error while loading. Please reload this page.
[cDAC] Relax HRESULT validation to allow divergent failure codes - #125236
Conversation
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
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
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
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: