Skip to content

[cDAC] Implement GetMetadata for cDAC#131169

Open
barosiak wants to merge 2 commits into
dotnet:mainfrom
barosiak:barosiak/GetMetadata
Open

[cDAC] Implement GetMetadata for cDAC#131169
barosiak wants to merge 2 commits into
dotnet:mainfrom
barosiak:barosiak/GetMetadata

Conversation

@barosiak

Copy link
Copy Markdown
Member

Summary

Implements DacDbiImpl.GetMetadata for the cDAC.

Changes

  • DacDbiImpl.cs - Implement GetMetadata.
  • CorDbHResults.cs - Add the CORDBG_E_MISSING_METADATA constant.
  • EcmaMetadata_1.cs, IEcmaMetadata.cs - Expose GetReadWriteSavedMetadataAddress on the contract.
  • EcmaMetadata.md - Document GetReadWriteSavedMetadataAddress.
  • DacDbiImplTests.cs - Add tests for the non-dynamic, dynamic, empty-metadata, and null-buffer cases.

@barosiak barosiak self-assigned this Jul 21, 2026
Copilot AI review requested due to automatic review settings July 21, 2026 21:23
@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.

@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

Implements DacDbiImpl.GetMetadata in the cDAC legacy Dbi layer by retrieving a target metadata span via the IEcmaMetadata contract (read-only metadata for normal modules; saved read-write metadata for reflection-emit/dynamic modules). The PR also extends the EcmaMetadata contract surface to expose the saved dynamic-metadata address, updates the contract design doc accordingly, and adds unit tests covering key GetMetadata scenarios.

Changes:

  • Implement DacDbiImpl.GetMetadata using Loader + EcmaMetadata contracts, including a new HRESULT for missing metadata.
  • Expose IEcmaMetadata.GetReadWriteSavedMetadataAddress (implementation + abstractions) and document it.
  • Add unit tests for non-dynamic, dynamic, empty-metadata, and null-buffer paths.
Show a summary per file
File Description
src/native/managed/cdac/tests/UnitTests/DacDbiImplTests.cs Adds unit tests for DacDbiImpl.GetMetadata covering dynamic/non-dynamic, missing metadata, and null buffer.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs Implements GetMetadata by selecting the correct metadata span based on module flags and mapping failures to HRESULTs.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/EcmaMetadata_1.cs Exposes the saved read-write metadata span accessor needed for reflection-emit modules.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/CorDbHResults.cs Adds CORDBG_E_MISSING_METADATA HRESULT constant used by GetMetadata.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IEcmaMetadata.cs Extends the EcmaMetadata contract interface with GetReadWriteSavedMetadataAddress.
docs/design/datacontracts/EcmaMetadata.md Documents the new EcmaMetadata contract API surface.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 2

Comment thread src/native/managed/cdac/tests/UnitTests/DacDbiImplTests.cs Outdated
Copilot AI review requested due to automatic review settings July 21, 2026 22:45

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.

Copilot's findings

Comments suppressed due to low confidence (1)

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

  • GetMetadata dereferences pTargetBuffer before validating it (and also accepts vmModule==0), unlike neighboring methods such as GetSymbolsBuffer/GetModuleData which validate pointer arguments up front. Relying on a null dereference to produce an HRESULT is brittle and can become an uncatchable AccessViolation depending on codegen / runtime settings; it also makes the contract less clear for callers. Add explicit argument validation and only write through pTargetBuffer after the null check.
            *pTargetBuffer = default;
            Contracts.ILoader loader = _target.Contracts.Loader;
            Contracts.ModuleHandle handle = loader.GetModuleHandleFromModulePtr(new TargetPointer(vmModule));
            Contracts.ModuleFlags flags = loader.GetFlags(handle);
            Contracts.IEcmaMetadata ecmaMetadata = _target.Contracts.EcmaMetadata;
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new

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