[cDAC] Implement ClrDataMethodDefinition APIs#127104
Conversation
Implement GetName, HasClassOrMethodInstantiation, StartEnumInstances, EnumInstance, and EndEnumInstances on ClrDataMethodDefinition. - GetName: TypeNameBuilder path for loaded methods, metadata fallback for unloaded methods - HasClassOrMethodInstantiation: mirrors native E_UNEXPECTED for null MethodDesc, boolean result for found MethodDesc - Start/Enum/EndEnumInstances: reuses SOSDacImpl.EnumMethodInstances with legacy delegation and fallback - SetCodeNotification: deferred (needs new contract APIs) - All methods include #if DEBUG cross-validation against legacy DAC Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
GetName, StartEnumInstances, HasClassOrMethodInstantiation are now implemented in the cDAC and no longer need legacy fallback. SetCodeNotification remains allowlisted (needs INotifications contract). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR implements most of the IXCLRDataMethodDefinition surface in the managed cDAC legacy-layer wrapper (ClrDataMethodDefinition), and updates the legacy fallback allowlist accordingly so these APIs no longer delegate by default.
Changes:
- Implemented
IXCLRDataMethodDefinitionAPIs for name retrieval, generic instantiation detection, and instance enumeration using cDAC contracts plus legacy cross-validation/fallback behavior. - Added a metadata-based fallback path for method names when a
MethodDesccannot be resolved. - Updated
LegacyFallbackHelperallowlist to remove the newly-implemented APIs (leavingSetCodeNotificationas the remaining fallback).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/LegacyFallbackHelper.cs | Removes IXCLRDataMethodDefinition members from the fallback allowlist now that they’re implemented (keeps SetCodeNotification). |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodDefinition.cs | Adds implementations for GetName, HasClassOrMethodInstantiation, and Start/Enum/End instance enumeration using cDAC contracts with legacy sync/validation. |
|
Who uses GetName? |
StartEnumInstances now properly cleans up the legacy enumeration handle when the cDAC side fails or returns S_FALSE, preventing resource leaks. The GCHandle is only allocated after emi.Start() succeeds. EndEnumInstances now calls IEnum.Dispose() to release the enumerator before freeing the GCHandle, matching ClrDataModule cleanup pattern. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply the same fix as ClrDataMethodDefinition: only allocate the GCHandle after emi.Start() returns S_OK, and clean up the legacy handle in a finally block when ownership is not transferred. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Implements most of the IXCLRDataMethodDefinition surface in the managed cDAC legacy layer, aligning behavior with the native/legacy DAC and reducing reliance on the legacy fallback allowlist.
Changes:
- Implemented
IXCLRDataMethodDefinitionAPIs for name retrieval, generic instantiation detection, and instance enumeration (start/next/end) inClrDataMethodDefinition. - Tightened
StartEnumMethodInstancesByAddresshandle/cleanup behavior to avoid orphaning legacy enumeration handles on failure paths. - Updated
LegacyFallbackHelperallowlist to remove methods that are now implemented, leavingSetCodeNotificationas deferred.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs | Ensures enum handle is only published on S_OK and reliably cleans up legacy handles when cDAC enum creation fails. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/LegacyFallbackHelper.cs | Removes now-implemented IXCLRDataMethodDefinition methods from the fallback allowlist; keeps SetCodeNotification. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodDefinition.cs | Adds managed implementations for method definition APIs, including metadata-based naming fallback and instance enumeration with legacy sync. |
This comment has been minimized.
This comment has been minimized.
- Add null bGeneric check in HasClassOrMethodInstantiation (throws E_POINTER) - Replace if/else pattern with throw for E_UNEXPECTED when methodDesc is null - Use Interop.BOOL.TRUE/FALSE instead of raw 1/0 - Add instance.IsNullRef guard in EnumInstance Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🤖 Copilot Code Review — PR #127104Note This review was generated by Copilot using multi-model analysis (Claude Opus 4.6 primary, Claude Sonnet 4.5 + GPT-5.3-Codex secondary). Holistic AssessmentMotivation: Justified — implements cDAC-side Approach: Sound — reuses the existing Summary: Detailed Findings
|
Add IXCLRDataMethodDefinitionDumpTests with 8 test methods covering: - GetName: query length, full retrieval, truncation (S_FALSE), null termination - HasClassOrMethodInstantiation: non-generic (FALSE) and generic type (TRUE) - Start/Enum/EndEnumInstances: non-generic method returns exactly one instance - EndEnumInstances: zero handle returns error Tests use the StackWalk debuggee's full dump. The generic type test walks the crash thread stack to find a module with loaded generic type MethodDescs, avoiding ILoader.GetRootAssembly() which requires the AssemblyList data descriptor that is not always present in locally-generated dumps. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Implements most IXCLRDataMethodDefinition APIs in the managed cDAC legacy layer wrapper, aiming to match native DAC behavior while reusing existing cDAC enumeration infrastructure and keeping optional DEBUG-time parity validation.
Changes:
- Implemented
GetName,HasClassOrMethodInstantiation, andStart/Enum/EndEnumInstancesonClrDataMethodDefinition. - Added legacy-handle cleanup to prevent orphaned legacy enumerations when cDAC enum creation fails.
- Updated the legacy fallback allowlist to remove newly-implemented
IXCLRDataMethodDefinitionmembers (leavingSetCodeNotificationdeferred).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs | Prevents orphaned legacy method-instance enumerations by deferring handle publication and cleaning up in finally. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/LegacyFallbackHelper.cs | Removes implemented IXCLRDataMethodDefinition APIs from the fallback allowlist; keeps SetCodeNotification allowlisted. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodDefinition.cs | Implements several IXCLRDataMethodDefinition APIs (name formatting, generic instantiation detection, and instance enumeration) using cDAC contracts with legacy sync/parity hooks. |
Native ClrDataMethodDefinition::EnumInstance does not null-check the output pointer — it dereferences *instance directly, and if NULL the AV is caught by EX_CATCH. The managed equivalent naturally throws NullReferenceException from DacComNullableByRef.Interface setter, which maps to E_POINTER at the COM interop boundary — matching native behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
There was a problem hiding this comment.
Pull request overview
This PR implements most of the IXCLRDataMethodDefinition surface in the cDAC managed wrapper, adds dump-based integration coverage for the new behavior, and tightens legacy fallback allowlisting to reflect the newly implemented APIs.
Changes:
- Implement
IXCLRDataMethodDefinition.GetName,HasClassOrMethodInstantiation, and method instance enumeration (StartEnumInstances/EnumInstance/EndEnumInstances) inClrDataMethodDefinition. - Add dump-based tests validating name retrieval, generic-instantiation detection, and enumeration lifecycle.
- Fix legacy-enumeration handle cleanup semantics for
StartEnumMethodInstancesByAddressand updateLegacyFallbackHelperallowlist accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/native/managed/cdac/tests/DumpTests/IXCLRDataMethodDefinitionDumpTests.cs | Adds dump-based integration tests for the newly implemented IXCLRDataMethodDefinition APIs. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs | Adjusts handle publication timing and ensures legacy handle cleanup when cDAC enumeration setup fails. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/LegacyFallbackHelper.cs | Removes now-implemented IXCLRDataMethodDefinition members from the fallback allowlist (leaving SetCodeNotification). |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodDefinition.cs | Implements method name retrieval, generic-instantiation detection, and method-instance enumeration with debug cross-validation. |
Note
This PR was generated with the assistance of GitHub Copilot.
Summary
Implements 5 of 6 IXCLRDataMethodDefinition APIs in the cDAC's managed ClrDataMethodDefinition wrapper:
GetNameHasClassOrMethodInstantiationStartEnumInstancesSOSDacImpl.EnumMethodInstancesEnumInstanceEndEnumInstancesSetCodeNotificationINotificationscontract lacks JIT notification table write APIsDetails
TypeNameBuilderwithFormatSignature|FormatNamespace|FormatFullInstflags (matching nativedaccess.cpp:5268). Falls back toGetFullMethodNameFromMetadatawhen no MethodDesc is available.IRuntimeTypeSystemcontract methods, matching nativetask.cpp:3486-3516.SOSDacImpl.EnumMethodInstancesinfrastructure (sameIEnum<MethodDescHandle>+ GCHandle pattern).#if DEBUGcross-validation blocks against the legacy DAC.LegacyFallbackHelperallowlist.Testing