Skip to content

[cDAC] Hide module lookup map layout details - #130730

Merged
max-charlamb merged 1 commit into
dotnet:mainfrom
max-charlamb:max-charlamb/cdac-module-lookup-map-api
Aug 3, 2026
Merged

[cDAC] Hide module lookup map layout details#130730
max-charlamb merged 1 commit into
dotnet:mainfrom
max-charlamb:max-charlamb/cdac-module-lookup-map-api

Conversation

@max-charlamb

Copy link
Copy Markdown
Member

Summary

  • Replace the layout-shaped ModuleLookupTables record with module-and-kind lookup operations.
  • Keep lookup-map selection, table traversal, flag masking, and metadata-token construction inside the Loader contract.
  • Expose the map data base directly where SOS must populate its frozen module-data shape, removing consumer-side TableDataOffset arithmetic.
  • Migrate contract, DacDbi, SOS, signature, code-version, metadata, and test consumers; update Loader-related contract documentation.

This gives consumers semantic operations for module lookup maps without exposing the native lookup-map object layout.

Validation

  • dotnet build src\native\managed\cdac\cdac.slnx -c Debug -p:UseSharedCompilation=false /nr:false
  • dotnet test src\native\managed\cdac\tests\UnitTests\Microsoft.Diagnostics.DataContractReader.Tests.csproj -c Debug --no-build (2697 passed, 16 skipped)
  • Targeted DacDbiImplTests, CodeVersionsTests, and LoaderTests run (579 passed)

Note

This PR was generated with the assistance of GitHub Copilot.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors cDAC’s module lookup-map access to avoid leaking native lookup-map layout details to consumers by replacing the layout-shaped ModuleLookupTables with module+kind-based lookup operations implemented inside the Loader contract.

Changes:

  • Replaces ModuleLookupTables with ModuleLookupMapKind plus new ILoader APIs for lookup-map base access, element lookup, and enumeration.
  • Implements map selection, traversal, flag masking, and metadata-token construction inside Loader_1.
  • Migrates legacy/SOS and contract/test consumers and updates Loader/related contract documentation.

Reviewed changes

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

Show a summary per file
File Description
src/native/managed/cdac/tests/UnitTests/DacDbiImplTests.cs Updates mocks/helpers to use module+kind lookup APIs.
src/native/managed/cdac/tests/UnitTests/CodeVersionsTests.cs Updates mock loader lookups for IL code versioning map.
src/native/managed/cdac/tests/DumpTests/IXCLRDataMethodDefinitionDumpTests.cs Switches MethodDef→Desc lookup to module+kind API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs Updates SOS DAC shims to new lookup APIs and enumeration shape.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/TypeDataWalk.cs Migrates typedef/typeref map access to new API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs Migrates multiple token→desc/MT lookups to new API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodDefinition.cs Updates MethodDef→Desc lookup to new API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/EcmaMetadataUtils.cs Adds mdtMemberRef token type for token construction/mapping.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/GC/GcSignatureTypeProvider.cs Updates type resolution lookups to kind-based API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/SignatureTypeProvider.cs Updates type resolution lookups to kind-based API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs Updates FieldDef→Desc lookup to kind-based API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ManagedTypeSource_1.cs Updates TypeDef→MT lookup to kind-based API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Loader_1.cs Centralizes lookup-map selection, traversal, masking, and token construction.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManagerCore.cs Updates TypeDef/TypeRef resolution to new lookup API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs Updates MethodDef→ILCodeVersioningState lookup to new API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ILoader.cs Replaces ModuleLookupTables with ModuleLookupMapKind and new public ILoader methods.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/Extensions/ILoaderExtensions.cs Updates assembly-ref resolution helper to use new lookup API.
docs/design/datacontracts/ManagedTypeSource.md Updates spec pseudocode to new lookup API.
docs/design/datacontracts/Loader.md Updates Loader contract spec to new lookup API and enumeration/token behavior.
docs/design/datacontracts/CodeVersions.md Updates spec pseudocode to new lookup API.

Comment thread src/native/managed/cdac/tests/UnitTests/CodeVersionsTests.cs Outdated
Copilot AI review requested due to automatic review settings July 15, 2026 01:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 20 out of 20 changed files in this pull request and generated 3 comments.

Comment thread src/native/managed/cdac/tests/UnitTests/CodeVersionsTests.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f2aa5dc4-0c99-43f0-af14-734143849c4a
Copilot AI review requested due to automatic review settings August 3, 2026 19:42
@max-charlamb
max-charlamb force-pushed the max-charlamb/cdac-module-lookup-map-api branch from 655e74c to 037212e Compare August 3, 2026 19:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 20 out of 20 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Loader_1.cs:648

  • EnumerateModuleLookupMap currently builds metadata tokens from the per-segment index returned by EnumerateModuleLookupMap(GetModuleLookupMap(...)). When the lookup map spans multiple linked segments (Next != Null), that index is no longer the original metadata RID, so CreateModuleLookupMapToken(kind, rid) can produce incorrect / invalid tokens (e.g., RID 0) and callers like SOSDacImpl.TraverseModuleMap will report wrong indices.
    IEnumerable<(TargetPointer Value, uint Token)> ILoader.EnumerateModuleLookupMap(ModuleHandle module, ModuleLookupMapKind kind)
    {
        foreach ((TargetPointer value, uint rid) in EnumerateModuleLookupMap(GetModuleLookupMap(module, kind)))
            yield return (value, CreateModuleLookupMapToken(kind, rid));
    }

docs/design/datacontracts/Loader.md:726

  • Loader.md removed the note/guard for builds that don't have code versioning (FEATURE_CODE_VERSIONING). The implementation treats MethodDefToILCodeVersioningState as an optional map (null/empty when absent), so the spec should reflect that rather than always reading the field unconditionally.
        TypeDefToMethodTable => target.ReadPointer(module.Address + /* Module::TypeDefToMethodTableMap offset */),
        TypeRefToMethodTable => target.ReadPointer(module.Address + /* Module::TypeRefToMethodTableMap offset */),
        MethodDefToILCodeVersioningState => target.ReadPointer(module.Address + /* Module::MethodDefToILCodeVersioningStateMap offset */),
    };

docs/design/datacontracts/Loader.md:798

  • EnumerateModuleLookupMap pseudocode constructs the returned token from the segment-local "index". When the lookup map spans multiple linked segments (Next != Null), "index" is adjusted via index -= count and no longer corresponds to the original metadata RID, so the returned token can be wrong. Track a base RID offset per segment when creating the token.
            TargetPointer rawValue = target.ReadPointer(entryAddress);
            ulong maskedValue = rawValue & ~(supportedFlagsMask.Value);
            if (maskedValue != 0)
                yield return (new TargetPointer(maskedValue), CreateModuleLookupMapToken(kind, index));
            index++;

@max-charlamb
max-charlamb marked this pull request as ready for review August 3, 2026 20:22
@max-charlamb
max-charlamb requested a review from rcj1 August 3, 2026 20:22
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@max-charlamb

Copy link
Copy Markdown
Member Author

/ba-g osx timeout

@max-charlamb
max-charlamb merged commit 6b16041 into dotnet:main Aug 3, 2026
70 of 73 checks passed
@max-charlamb
max-charlamb deleted the max-charlamb/cdac-module-lookup-map-api branch August 3, 2026 22:47
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 4, 2026
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