Skip to content

Implement IXCLRDataExceptionState state comparison#131011

Merged
rcj1 merged 4 commits into
mainfrom
copilot/exception-dac
Jul 20, 2026
Merged

Implement IXCLRDataExceptionState state comparison#131011
rcj1 merged 4 commits into
mainfrom
copilot/exception-dac

Conversation

@rcj1

@rcj1 rcj1 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Implement a couple APIs that were found to be used internally

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 18, 2026 04:05
@rcj1
rcj1 temporarily deployed to copilot-pat-pool July 18, 2026 04:05 — with GitHub Actions Inactive
@rcj1
rcj1 temporarily deployed to copilot-pat-pool July 18, 2026 04:05 — with GitHub Actions Inactive
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@rcj1
rcj1 had a problem deploying to copilot-pat-pool July 18, 2026 04:06 — with GitHub Actions Failure
@rcj1
rcj1 temporarily deployed to copilot-pat-pool July 18, 2026 04:07 — with GitHub Actions Inactive
@rcj1
rcj1 temporarily deployed to copilot-pat-pool July 18, 2026 04:08 — with GitHub Actions Inactive
@rcj1
rcj1 temporarily deployed to copilot-pat-pool July 18, 2026 04:08 — with GitHub Actions Inactive

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

Implements IXCLRDataExceptionState.IsSameState / IsSameState2 in the cDAC legacy shim and adds unit tests to validate the HRESULT behavior when comparing exception state based on exception address and “first-chance” semantics.

Changes:

  • Implement IXCLRDataExceptionState.IsSameState and IsSameState2 in ClrDataExceptionState (including DEBUG-only validation against the legacy DAC implementation).
  • Add unit tests for state comparison (IsSameState / IsSameState2) and flag validation behavior.
Show a summary per file
File Description
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataExceptionState.cs Adds cDAC implementation of exception state comparison logic for IsSameState/IsSameState2.
src/native/managed/cdac/tests/UnitTests/ClrDataExceptionStateTests.cs Adds unit tests covering matching/different exception addresses and IsSameState2 flag handling.

Copilot's findings

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

@rcj1 rcj1 changed the title Implement IXCLRDataExceptionState state comparison [WIP] Implement IXCLRDataExceptionState state comparison Jul 18, 2026
@rcj1

rcj1 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot 1. please put both flags under CLRDATA_EXCEPTION_PARTIAL in an enum in IXCLRData.cs.
2. resolve #131011 (comment) by modifying the CLRDataExceptionState managed constructor to take the previous exception info as a parameter.

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 18, 2026 05:13
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>

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: 5/5 changed files
  • Comments generated: 1

Copilot AI review requested due to automatic review settings July 18, 2026 05:17

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

@copilot 1. please put both flags under CLRDATA_EXCEPTION_PARTIAL in an enum in IXCLRData.cs.
2. resolve #131011 (comment) by modifying ...

Implemented in a554b966 with naming clarification in 48f1797d. The comparison flags now use CLRDataExceptionSameFlag, nested states retain their exception-info address through GetPrevious, and invalid flags throw ArgumentException within the HRESULT boundary.

Copilot finished work on behalf of rcj1 July 18, 2026 05:20

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

Comments suppressed due to low confidence (1)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/IXCLRData.cs:969

  • This adds a new public enum type to the Legacy assembly. Unless this is intended to be part of the supported public surface, consider making it internal (tests can still access it via InternalsVisibleTo) to avoid expanding public API and triggering API-approval requirements.
[Flags]
public enum CLRDataExceptionSameFlag : uint
{
    CLRDATA_EXSAME_SECOND_CHANCE = 0,
    CLRDATA_EXSAME_FIRST_CHANCE = 0x1,
}
  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 18, 2026 05:39
Copilot finished work on behalf of rcj1 July 18, 2026 05:40

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

Comments suppressed due to low confidence (1)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/IXCLRData.cs:969

  • This change introduces new public API surface (CLRDataExceptionSameFlag). The provided PR metadata doesn’t include any linked api-approved issue/proposal, which is required for new public APIs in dotnet/runtime. Either (1) link the approved API proposal/issue, or (2) make this enum internal if it’s only intended for internal/test use (the Legacy csproj already has InternalsVisibleTo for the tests).
[Flags]
public enum CLRDataExceptionSameFlag : uint
{
    CLRDATA_EXSAME_SECOND_CHANCE = 0,
    CLRDATA_EXSAME_FIRST_CHANCE = 0x1,
}
  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Copilot finished work on behalf of rcj1 July 18, 2026 06:27
Copilot finished work on behalf of rcj1 July 18, 2026 06:32
@rcj1
rcj1 marked this pull request as ready for review July 19, 2026 02:14
@rcj1 rcj1 changed the title [WIP] Implement IXCLRDataExceptionState state comparison Implement IXCLRDataExceptionState state comparison Jul 19, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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 temporarily deployed to copilot-pat-pool July 19, 2026 02:15 Inactive
Copilot AI temporarily deployed to copilot-pat-pool July 19, 2026 02:15 Inactive
@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "999caed0da5317795648effd23c91cb03eb7f7a7",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "3522269feadf7e6d9a5ed422ccd269335ebe62a9",
  "last_reviewed_commit": "999caed0da5317795648effd23c91cb03eb7f7a7",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "3522269feadf7e6d9a5ed422ccd269335ebe62a9",
  "last_recorded_worker_run_id": "29689456510",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "999caed0da5317795648effd23c91cb03eb7f7a7",
      "review_id": 4730877931
    }
  ]
}

@github-actions github-actions Bot 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.

Holistic Review

Motivation: The cdac legacy IXCLRDataExceptionState implementation previously stubbed out IsSameState and IsSameState2 with E_NOTIMPL (falling back to the legacy DAC when available). This PR implements those two APIs natively in managed cdac code because they were found to be used internally, moving another slice of the legacy DAC surface onto the data-contract reader.

Approach: A new IsSameState2(uint flags, EXCEPTION_RECORD64*) private helper faithfully ports the logic from ClrDataExceptionState::IsSameState2 in src/coreclr/debug/daccess/task.cpp: it validates the flag mask (only SECOND_CHANCE/FIRST_CHANCE allowed, otherwise E_INVALIDARG), returns S_OK for a partial (last-exception) state only on a first-chance query, and otherwise compares the stored exception record's ExceptionAddress against the requested record. To reach the exception record the class now carries a new _exceptionInfoAddress field: when non-null it reads ExceptionInfo.ExceptionRecord via the data descriptor (used by the nested/previous state produced by GetPrevious), and when null it falls back to ThreadData.OSExceptionRecord. The constructor gains this parameter, and all four call sites are updated (Null for the current/last/notification cases, _previousExInfoAddress for the nested case). Both public methods delegate to the helper and, under DEBUG, cross-validate the HRESULT against the legacy implementation via Debug.ValidateHResult. A new CLRDataExceptionSameFlag enum mirrors the native constants. Tests exercise matching/non-matching addresses, the nested (previous) path, partial-state first/second chance, and invalid flags across the standard architectures.

Summary: This is a clean, well-scoped port that matches the native reference implementation closely, including the pointer-size-dependent exception-record offset (sizeof(uint)*2 + PointerSize for the ExceptionAddress field) and the 32-bit truncation of the requested address. The constructor signature change is threaded correctly through all call sites and the test file, and test coverage is thorough with good use of [Theory]/[ClassData]. I found no correctness or behavioral issues in the changed code. One minor, non-blocking style nit is noted inline (prefer nameof over a "ExceptionRecord" string literal for the field lookup). Verdict: LGTM.

Detailed Findings

No blocking issues. See the single inline comment for an optional nameof style suggestion consistent with the repository's C# conventions.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 187.9 AIC · ⌖ 10.5 AIC · ⊞ 10K

@rcj1
rcj1 merged commit 7c4b0f2 into main Jul 20, 2026
92 checks passed
@rcj1
rcj1 deleted the copilot/exception-dac branch July 20, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants