Skip to content

Implement GetIlCodeAndSig DacDbi API in cDAC#128354

Merged
rcj1 merged 6 commits into
mainfrom
copilot/implement-getilcodeandsig-api
Jun 3, 2026
Merged

Implement GetIlCodeAndSig DacDbi API in cDAC#128354
rcj1 merged 6 commits into
mainfrom
copilot/implement-getilcodeandsig-api

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

Port the GetILCodeAndSig DacDbi entry point from the native DAC to the managed cDAC, returning the target-address/size of a method's IL and its local-variable signature token.

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot AI self-assigned this May 19, 2026
Copilot AI review requested due to automatic review settings May 19, 2026 02:11
Copilot AI review requested due to automatic review settings May 19, 2026 02:11
@rcj1 rcj1 requested a review from Copilot May 19, 2026 02:12
@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 the managed cDAC path for GetILCodeAndSig, replacing an E_NOTIMPL fallback with metadata/loader-based IL lookup and signature-token extraction.

Changes:

  • Adds IL header size/code-size helpers.
  • Implements DacDbiImpl.GetILCodeAndSig.
  • Adds metadata token and HRESULT constants needed by the implementation.
Show a summary per file
File Description
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/HeaderReaderHelpers.cs Adds helpers for IL header size and code size decoding.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs Implements cDAC GetILCodeAndSig behavior.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/EcmaMetadataUtils.cs Adds mdtSignature token type.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/CorDbHResults.cs Adds CORDBG_E_FUNCTION_NOT_IL.

Copilot's findings

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

@rcj1 rcj1 marked this pull request as ready for review May 19, 2026 04:33
@rcj1 rcj1 marked this pull request as ready for review May 19, 2026 04:33
@rcj1 rcj1 requested review from Copilot May 19, 2026 04:33
@rcj1 rcj1 requested review from max-charlamb and noahfalk May 19, 2026 04:34
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

Comments suppressed due to low confidence (3)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs:1361

  • pLocalSigToken is pre-initialized to TokenType.mdtSignature (0x11000000). Native DAC initializes this out param to mdSignatureNil (0) and only sets a non-zero token when a LocalVarSigTok exists. Initializing to the token type mask yields an invalid token on success for methods without locals (and will mismatch the legacy DAC behavior).
            if (dwExactGenericArgsTokenIndex == 0)
            {
                // In a rare case of VS4Mac debugging VS4Mac ARM64 optimized code we get a null

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs:1371

  • GetILCodeAndSig doesn’t validate that functionToken is actually a MethodDef token before using it with MetadataReader and the MethodDefToDesc lookup. Other methods in this type explicitly validate token type (e.g., GetActiveRejitILCodeVersionNode throws ArgumentException when the token type isn’t mdtMethodDef). Adding the same check here should help keep HRESULT behavior aligned with the native DAC (E_INVALIDARG for invalid tokens) and avoid BadImageFormat/other accidental failures.
                {
                    *pRetVal = rawToken;
                }
                else
                {
                    // The real generics type token is the MethodTable of the "this" object.

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs:1365

  • GetILCodeAndSig now has a non-trivial managed implementation (metadata validation, MethodDesc mapping, IL header parsing) but there are no unit/integration tests exercising the new behavior (success path, non-IL methods -> CORDBG_E_FUNCTION_NOT_IL, methods without locals -> mdSignatureNil, etc.). This file already has targeted tests for other DacDbiImpl entry points, so adding coverage here would help prevent regressions and ensure behavior matches the native DAC.
        try
        {
            if (dwExactGenericArgsTokenIndex == 0)
            {
                // In a rare case of VS4Mac debugging VS4Mac ARM64 optimized code we get a null
                // generics argument token. We aren't sure why the token is null, it may be a bug
                // or it may be by design in the runtime. In the interest of time we are working
                // around the issue rather than investigating the root cause.
                if (rawToken == 0)
  • Files reviewed: 4/4 changed files
  • Comments generated: 3

@rcj1 rcj1 merged commit 2790c60 into main Jun 3, 2026
62 checks passed
@rcj1 rcj1 deleted the copilot/implement-getilcodeandsig-api branch June 3, 2026 04:50
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.

5 participants