Skip to content

[cDAC] Add API TranslateExceptionRecordToNotification#125931

Merged
rcj1 merged 13 commits intomainfrom
copilot/review-pull-request-state
Apr 2, 2026
Merged

[cDAC] Add API TranslateExceptionRecordToNotification#125931
rcj1 merged 13 commits intomainfrom
copilot/review-pull-request-state

Conversation

@rcj1
Copy link
Copy Markdown
Contributor

@rcj1 rcj1 commented Mar 22, 2026

Tested locally with various notifications.

Copilot AI and others added 2 commits March 22, 2026 12:50
…lateExceptionRecordToNotification

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/3d4683a7-5378-41a6-bb65-fe35cacb62e5

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/163ce877-10b9-4016-bfa8-0c889c4344d3

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/d2c7bddc-dc21-4acf-8d09-e66d8d1852d3

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/af5a239e-4a57-49f1-a673-27583d01977f
Copilot AI review requested due to automatic review settings March 22, 2026 20:10
@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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a managed cDAC surface for decoding debugger notification exception records and wires it into the legacy IXCLRDataProcess.TranslateExceptionRecordToNotification implementation.

Changes:

  • Added INotifications APIs (type detection + parse helpers) plus new public notification-related data types (NotificationType, GcEventType, GcEventData).
  • Implemented these APIs for contract version 1 (Notifications_1) and updated legacy IXCLRData COM interop signatures (including adding EXCEPTION_RECORD64).
  • Added unit tests validating notification type mapping and parse helpers.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/native/managed/cdac/tests/NotificationsTests.cs New unit tests for INotifications decoding/parsing behavior.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs Implements TranslateExceptionRecordToNotification using the cDAC Notifications contract.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/IXCLRData.cs Adds EXCEPTION_RECORD64 and updates COM interface signatures to typed parameters.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataExceptionState.cs Updates exception-state COM method signatures to use EXCEPTION_RECORD64*.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Notifications_1.cs Implements the new INotifications APIs for contract version 1.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/INotifications.cs Defines the new contract APIs and public notification-related types.
docs/design/datacontracts/Notifications.md Documents the new Notifications contract APIs and related types.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 22, 2026 20:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@rcj1 rcj1 marked this pull request as draft March 23, 2026 01:57
Copilot AI review requested due to automatic review settings March 23, 2026 05:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Copilot AI review requested due to automatic review settings March 23, 2026 17:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

@rcj1 rcj1 marked this pull request as ready for review March 23, 2026 18:15
Copilot AI review requested due to automatic review settings March 23, 2026 18:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

…er.Legacy/SOSDacImpl.IXCLRDataProcess.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 23, 2026 21:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings April 1, 2026 15:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

@github-actions

This comment has been minimized.

Copilot AI review requested due to automatic review settings April 2, 2026 02:15
@rcj1 rcj1 force-pushed the copilot/review-pull-request-state branch from b597cb1 to 8d3c983 Compare April 2, 2026 02:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

🤖 Copilot Code Review — PR #125931

Note

This review was generated by GitHub Copilot.

Holistic Assessment

Motivation: This PR adds TryParseNotification to the cDAC Notifications contract, implementing the TranslateExceptionRecordToNotification API in the managed cDAC (SOSDacImpl). The change is well-motivated — it's replacing a void*-based forwarding stub with a proper managed implementation that parses exception records into typed notification objects and dispatches them to the appropriate IXCLRDataExceptionNotification* interface methods. The ClrDataModule.Request() method is also enhanced to handle CLRDATA_REQUEST_REVISION and DACDATAMODULEPRIV_REQUEST_GET_MODULEPTR requests with debug-mode validation against the legacy implementation.

Approach: The approach is clean and well-structured. Using C# records with an abstract base type (NotificationData) for pattern matching is idiomatic and makes the dispatch logic in SOSDacImpl easy to read. The separation between parsing (in the contract) and dispatch (in the legacy bridge) is a sound design. The internal NotificationType_1 enum properly decouples the wire format from the public API enum.

Summary: ⚠️ Needs Human Review. The implementation is generally correct and well-tested, but there are a few concerns around defensive bounds checking in the contract API, inconsistent error handling across notification types, and unchecked HRESULT returns from legacy calls that a human reviewer should evaluate.


Detailed Findings

⚠️ Missing bounds validation in TryParseNotification — could throw IndexOutOfRangeException for short spans

Notifications_1.TryParseNotification() checks exceptionInformation.IsEmpty but then directly accesses exceptionInformation[1] and exceptionInformation[2] without validating the span length. The current caller in SOSDacImpl always passes 15 elements (from EXCEPTION_RECORD64.ExceptionMaximumParameters), so this is safe today. However, the INotifications contract interface accepts an arbitrary ReadOnlySpan<TargetPointer>, meaning future callers passing fewer elements would get an unhandled IndexOutOfRangeException instead of a clean false return.

File: Notifications_1.cs:46-58

Consider adding a minimum-length check:

// Before the switch, validate we have enough elements for the notification type
if (exceptionInformation.Length < 2)
    return false;

Or validate per-branch (e.g., Jit2 and ExceptionCatcherEnter need 3 elements while others need 2).

⚠️ Inconsistent error handling when notify doesn't implement required interface versions

In TranslateExceptionRecordToNotification, the notification cases handle missing interface versions differently:

  • Exception: Returns E_INVALIDARG if notify is not IXCLRDataExceptionNotification2
  • GC: Silently returns S_OK if notify is not IXCLRDataExceptionNotification3
  • ExceptionCatcherEnter: Silently returns S_OK if notify is not IXCLRDataExceptionNotification4
  • JIT (OnCodeGenerated2): Silently skips if notify is not IXCLRDataExceptionNotification5

The JIT case is defensible (it always calls OnCodeGenerated on the base interface, and OnCodeGenerated2 is optional). But the GC and ExceptionCatcherEnter cases silently succeed without dispatching, which could mask issues. A human reviewer should verify this matches the native DAC behavior.

File: SOSDacImpl.IXCLRDataProcess.cs:556-558 vs 577-583 vs 594-596

⚠️ GetModule HRESULT return value is not checked

In the ModuleLoad and ModuleUnload notification cases, _legacyImpl.GetModule(...) is called but its return value (HRESULT) is not checked. If the module lookup fails, legacyModuleOut.Interface will be null, which is passed to ClrDataModule. While ClrDataModule accepts nullable legacy modules, silently ignoring a failed lookup could hide real issues during debugging.

File: SOSDacImpl.IXCLRDataProcess.cs:510-512, 524-526

💡 Consider at least logging the HRESULT in debug builds.

✅ Contract API design — clean use of records for pattern matching

The use of abstract record NotificationData with derived record types is well-designed. It enables clean C# pattern matching in the dispatch logic and follows modern C# idioms. The NotificationType public enum provides a discriminator while the record hierarchy carries type-specific data. XML doc comments are present on all public types.

✅ COM object lifetime management is correct

The UniqueComInterfaceMarshaller<IXCLRDataExceptionNotification> with ComObject.FinalRelease() in the finally block correctly handles the stack-allocated COM object lifetime. The comment explains the rationale well. All return statements are inside the try block, so the finally always executes.

✅ Test coverage is good

NotificationsTests.cs covers all 6 notification types, empty span, unknown types (including legacy JIT_NOTIFICATION = 3), and both supported/unsupported GC events. Tests use [Theory] with [InlineData] for the unknown-type case, and specific [Fact] methods for each notification type with exact value assertions.

✅ ClrDataModule.Request() refactoring

The Request() method is properly refactored to handle CLRDATA_REQUEST_REVISION and DACDATAMODULEPRIV_REQUEST_GET_MODULEPTR requests natively, with debug-mode byte-for-byte validation against the legacy implementation. The validation is correctly moved to the outer Request() scope so it covers all request types uniformly.

💡 Duplicated legacy module retrieval code

The ModuleLoad and ModuleUnload cases contain identical code for retrieving the legacy module. This could be extracted into a small local function to reduce duplication. Minor style concern — not blocking.

File: SOSDacImpl.IXCLRDataProcess.cs:506-514 and 518-528

💡 Documentation matches implementation

Notifications.md accurately documents the new TryParseNotification API, all notification types with correct internal enum values, and the parsing pseudocode. The documentation and implementation are consistent.

Generated by Code Review for issue #125931 ·

@rcj1 rcj1 merged commit 0c92757 into main Apr 2, 2026
64 of 65 checks passed
@rcj1 rcj1 deleted the copilot/review-pull-request-state branch April 2, 2026 17:28
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Apr 9, 2026
Tested locally with various notifications.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

6 participants