Skip to content

[cDAC] Implement GetMethodDefinitionByToken in ClrDataModule#127091

Merged
max-charlamb merged 3 commits intodotnet:mainfrom
max-charlamb:dev/max-charlamb/cdac-getmethoddefbytoken
Apr 18, 2026
Merged

[cDAC] Implement GetMethodDefinitionByToken in ClrDataModule#127091
max-charlamb merged 3 commits intodotnet:mainfrom
max-charlamb:dev/max-charlamb/cdac-getmethoddefbytoken

Conversation

@max-charlamb
Copy link
Copy Markdown
Member

@max-charlamb max-charlamb commented Apr 17, 2026

Note

This PR was generated with the assistance of GitHub Copilot.

Summary

Implement IXCLRDataModule.GetMethodDefinitionByToken in the cDAC ClrDataModule wrapper instead of delegating entirely to the legacy DAC. Remove it from the no-fallback allowlist and add newly-exposed downstream methods.

Changes

ClrDataModule.cs — Replaced the one-line legacy delegation stub with a full cDAC implementation that:

  1. Calls the legacy implementation first (if available) for DEBUG parity validation
  2. Validates the token is an mdtMethodDef (throws ArgumentExceptionE_INVALIDARG)
  3. Creates a ClrDataMethodDefinition with the token, module address, and legacy method definition
  4. Includes #if DEBUG ValidateHResult check against the legacy result

LegacyFallbackHelper.cs — Removed GetMethodDefinitionByToken from the no-fallback allowlist. Added four IXCLRDataMethodDefinition methods that are now exposed as blocked fallbacks because GetMethodDefinitionByToken returns a cDAC-managed wrapper instead of a legacy object:

  • StartEnumInstances
  • GetName
  • SetCodeNotification
  • HasClassOrMethodInstantiation

These methods are not yet implemented in the cDAC and must remain on the allowlist until they are.

Pattern

Follows the same pattern used by EnumMethodDefinitionByName (line 302) which already creates ClrDataMethodDefinition objects in the same way.

The C++ legacy implementation (task.cpp:2215-2251) validates the token type, then calls ClrDataMethodDefinition::NewFromModule which simply creates a ClrDataMethodDefinition — the cDAC version mirrors this behavior.

Motivation

This enables removing GetMethodDefinitionByToken from the cDAC no-fallback allowlist (#126752).

@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 IXCLRDataModule.GetMethodDefinitionByToken in the managed cDAC ClrDataModule wrapper so it no longer relies solely on legacy DAC delegation, enabling progress toward stricter “no legacy fallback” coverage.

Changes:

  • Replace the legacy-only delegation stub with a cDAC implementation that validates the token type and constructs a ClrDataMethodDefinition.
  • When a legacy module is available, also invokes the legacy method to capture its result for DEBUG HRESULT parity validation.

Max Charlamb and others added 2 commits April 17, 2026 17:31
Implement IXCLRDataModule.GetMethodDefinitionByToken in the cDAC
ClrDataModule wrapper instead of delegating entirely to the legacy DAC.

The implementation validates the token is an mdtMethodDef, retrieves
the legacy method definition for DEBUG parity validation, and creates
a ClrDataMethodDefinition with the token and module address.

This follows the same pattern used by EnumMethodDefinitionByName and
enables removing GetMethodDefinitionByToken from the cDAC no-fallback
allowlist.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Now that GetMethodDefinitionByToken is implemented in the cDAC, it no
longer needs to be in the LegacyFallbackHelper allowlist.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@max-charlamb max-charlamb force-pushed the dev/max-charlamb/cdac-getmethoddefbytoken branch from fb386ce to e67c1fb Compare April 17, 2026 21:34
GetMethodDefinitionByToken now returns a cDAC-managed
ClrDataMethodDefinition wrapper. When SOS calls methods on it, those
delegate to legacy but are blocked by the no-fallback check. Add the
four downstream methods that are not yet implemented in the cDAC:

- StartEnumInstances
- GetName
- SetCodeNotification
- HasClassOrMethodInstantiation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 18, 2026 00:46
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 2 out of 2 changed files in this pull request and generated 2 comments.

@max-charlamb
Copy link
Copy Markdown
Member Author

/ba-g cDAC only change and cDAC legs pass

@max-charlamb max-charlamb merged commit b4e3e05 into dotnet:main Apr 18, 2026
58 of 66 checks passed
@max-charlamb max-charlamb deleted the dev/max-charlamb/cdac-getmethoddefbytoken branch April 18, 2026 02:23
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