Skip to content

[cDAC] Implement delegate inspection DacDbi APIs#128784

Open
Copilot wants to merge 5 commits into
mainfrom
copilot/delegate-inspection-apis
Open

[cDAC] Implement delegate inspection DacDbi APIs#128784
Copilot wants to merge 5 commits into
mainfrom
copilot/delegate-inspection-apis

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

Implements GetDelegateFunctionData and GetDelegateTargetObject in the managed cDAC DacDbi layer, on top of cherry-picked native commit 86d4004 which removes GetDelegateType and simplifies the two delegate APIs' signatures.

cDAC contract

  • New IObject.GetDelegateInfo(addr, out methodPtr, out methodPtrAux, out invocationCount) implemented in Object_1 via a new Data.Delegate type. No version bump; no compat shims for older dumps.

Data descriptors

  • cdac_data<DelegateObject> template + friend in src/coreclr/vm/object.h.
  • New Delegate type in datadescriptor.inc with Target, MethodPtr, MethodPtrAux, InvocationList, InvocationCount.
  • DataType.Delegate enum value.

DacDbi cDAC implementations

  • DacDbiImpl.GetDelegateFunctionData / GetDelegateTargetObject implemented using the new contract + ExecutionManager, RuntimeTypeSystem, and Loader contracts. Delegate-kind branching (closed / open / multicast / wrapper) mirrors the native logic.
  • Both follow the standard cDAC pattern: try/catch translating exceptions to HRs, plus #if DEBUG validation against the legacy implementation (Debug.ValidateHResult + Debug.Assert on outputs).
  • Added CORDBG_E_UNSUPPORTED_DELEGATE HR constant.
  • Vtable slot for the removed GetDelegateType is dropped in IDacDbiInterface.cs to match the native interface.

Unit tests

  • MockDelegateObjectData + AddDelegateObject helpers in MockDescriptors.Object.cs.
  • Four ObjectTests cases for GetDelegateInfo: closed delegate, open delegate, multicast delegate, and null-address argument validation.

Passes internal delegate inspection tests, matching the current limitations of support (these limitations do surface at the ICD boundary).

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 30, 2026 16:46
@rcj1 rcj1 added area-Diagnostics-cdac and removed NO-REVIEW Experimental/testing PR, do NOT review it area-Diagnostics-coreclr labels May 30, 2026
@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

Implements GetDelegateFunctionData and GetDelegateTargetObject in the managed cDAC DacDbi layer, on top of a cherry-picked native simplification that removes GetDelegateType and drops the delegateType/ppTargetAppDomain parameters from the two surviving delegate APIs. Adds the supporting Delegate data descriptor, an IObject.GetDelegateInfo contract member, and unit tests for the new managed code path.

Changes:

  • Native: removes GetDelegateType and slims GetDelegateFunctionData/GetDelegateTargetObject signatures across dacdbi.idl, dacdbiinterface.h, dacdbiimpl.{h,cpp}, and the divalue.cpp consumer.
  • cDAC contract: new Delegate data type, cdac_data<DelegateObject> in object.h, IObject.GetDelegateInfo/DelegateInfo, Object_1 implementation, and CORDBG_E_UNSUPPORTED_DELEGATE.
  • Managed DacDbi: implements both delegate APIs in DacDbiImpl with try/catch + #if DEBUG legacy validation, plus a shared IsDelegateHelper; adds mock delegate object layout and four xUnit theories in ObjectTests.
Show a summary per file
File Description
src/coreclr/inc/dacdbi.idl Drop DelegateType typedef + GetDelegateType; trim parameters on the two delegate APIs.
src/coreclr/debug/inc/dacdbiinterface.h Mirror IDL: remove DelegateType enum and GetDelegateType vtable slot.
src/coreclr/debug/daccess/dacdbiimpl.{h,cpp} Remove GetDelegateType; rewrite the two APIs to check IsDelegate/InvocationCount and dispatch on _methodPtrAux.
src/coreclr/debug/di/divalue.cpp Update consumers to call simplified DAC APIs directly.
src/coreclr/vm/object.h Add cdac_data<DelegateObject> with Target/MethodPtr/MethodPtrAux/InvocationCount offsets.
src/coreclr/vm/datadescriptor/datadescriptor.inc Emit new Delegate cDAC type descriptor.
src/coreclr/vm/comdelegate.cpp Comment-only fix-up to reflect the removed GetDelegateType API.
src/native/managed/cdac/.../Data/Delegate.cs, DataType.cs New managed data type + enum entry.
src/native/managed/cdac/.../Abstractions/Contracts/IObject.cs, CorDbHResults.cs Add DelegateInfo record + GetDelegateInfo default; add CORDBG_E_UNSUPPORTED_DELEGATE.
src/native/managed/cdac/.../Contracts/Object_1.cs Implement GetDelegateInfo over the new descriptor.
src/native/managed/cdac/.../Legacy/Dbi/IDacDbiInterface.cs Update vtable to match native (drop GetDelegateType, slim signatures).
src/native/managed/cdac/.../Legacy/Dbi/DacDbiImpl.cs Implement both delegate APIs with debug validation; extract IsDelegateHelper.
src/native/managed/cdac/tests/MockDescriptors/MockDescriptors.Object.cs Add MockDelegateObjectData + AddDelegateObject helper.
src/native/managed/cdac/tests/ObjectTests.cs New closed/open/multicast GetDelegateInfo theories.
docs/design/datacontracts/Object.md Document the new DelegateInfo API and Delegate data descriptor fields.

Copilot's findings

  • Files reviewed: 18/18 changed files
  • Comments generated: 3

Comment thread src/native/managed/cdac/tests/MockDescriptors/MockDescriptors.Object.cs Outdated
@rcj1 rcj1 changed the title [WIP] Implement delegate inspection DacDbi APIs on cDAC [cDAC] Implement delegate inspection DacDbi APIs May 30, 2026
Copilot AI review requested due to automatic review settings May 30, 2026 17:31
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.

Copilot's findings

  • Files reviewed: 18/18 changed files
  • Comments generated: 0 new

@rcj1 rcj1 marked this pull request as ready for review May 30, 2026 18:14
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.

3 participants