Skip to content

Implement cDAC stub tracing support - #131546

Closed
rcj1 wants to merge 1 commit into
mainfrom
copilot/75023b33-c2ac-44d8-aeb6-b4acfe3ef451
Closed

Implement cDAC stub tracing support#131546
rcj1 wants to merge 1 commit into
mainfrom
copilot/75023b33-c2ac-44d8-aeb6-b4acfe3ef451

Conversation

@rcj1

@rcj1 rcj1 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 18:30
@rcj1 rcj1 closed this Jul 29, 2026
@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.

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 adds cDAC “stub tracing” support end-to-end: it introduces a new StubTracing contract to classify/step through runtime stubs, wires it into the CoreCLR data descriptors / globals, and exposes it through the legacy IXCLRDataProcess.FollowStub2 surface with new and updated unit tests.

Changes:

  • Add new IStubTracing contract (v1) + implementation (StubTracing_1) and register it for CoreCLR targets.
  • Extend CoreCLR data descriptors / globals to expose prestub-related breakpoints and call-counting stub data needed by stub tracing.
  • Implement IXCLRDataProcess.FollowStub2 in the legacy layer using the new contract, with added/updated unit tests.
Show a summary per file
File Description
src/native/managed/cdac/tests/UnitTests/StubTracingTests.cs New unit tests covering StubTracing contract behavior (managed code, precodes, continuations, call-counting stubs, etc.).
src/native/managed/cdac/tests/UnitTests/PrecodeStubsTests.cs Adds assertions for GetPrecodeType behavior (contract v3).
src/native/managed/cdac/tests/UnitTests/MethodDescTests.cs Adds coverage for new IRuntimeTypeSystem.IsPInvoke.
src/native/managed/cdac/tests/UnitTests/IXCLRDataProcessTests.cs Adds tests for IXCLRDataProcess.FollowStub2 success/failure, continuation flow, and 32-bit sign-extension truncation.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs Implements FollowStub2 using StubTracing; changes FollowStub to E_NOTIMPL; adds continuation encode/decode helpers.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/IXCLRData.cs Adds typed FollowStub2 buffer/flag declarations and updates the FollowStub2 signature accordingly.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataTask.cs Exposes internal accessors needed to retrieve task address / legacy implementation during stub tracing.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/DataType.cs Adds CallCountingStubData data type identifier.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/PrecodeMachineDescriptor.cs Refactors optional-field handling and lazily reads byte-pattern blobs for precodes.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/CallCountingStubData.cs New data descriptor for reading a call-counting stub’s target address.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/CoreCLRContracts.cs Registers the StubTracing contract (c1).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StubTracing_1.cs New StubTracing contract implementation (v1) with logic for jump stubs, call-counting stubs, precodes, prestub continuations, etc.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs Implements IsPInvoke based on method classification.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/PrecodeStubs_Common.cs Switches from internal KnownPrecodeType to public PrecodeType for shared precode logic.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/PrecodeStubs_3.cs Adds GetPrecodeType API implementation for v3; updates precode-type plumbing.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/PrecodeStubs_2.cs Updates signature to return PrecodeType?.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/PrecodeStubs_1.cs Updates signature to return PrecodeType?.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Constants.cs Adds globals for prestub patch label and compilation-finished notification address.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IStubTracing.cs New public contract surface for stub tracing (enums + records + interface).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeTypeSystem.cs Adds IsPInvoke to the contract API surface.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IPrecodeStubs.cs Adds public PrecodeType + GetPrecodeType API (v3-only per docs).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/ContractRegistry.cs Exposes StubTracing via the contract registry.
src/coreclr/vm/util.hpp Declares the exported cDAC global for DACNotifyCompilationFinished.
src/coreclr/vm/stubmgr.cpp Exports g_cdacThePreStubPatchLabel when applicable.
src/coreclr/vm/prestub.cpp Exports g_cdacDACNotifyCompilationFinished.
src/coreclr/vm/datadescriptor/datadescriptor.inc Adds CallCountingStubData, new globals, and registers the StubTracing global contract.
src/coreclr/vm/class.h Declares g_cdacThePreStubPatchLabel.
docs/design/datacontracts/StubTracing.md New contract spec for StubTracing including generated usage blocks.
docs/design/datacontracts/RuntimeTypeSystem.md Updates spec to include IsPInvoke API and algorithm sketch.
docs/design/datacontracts/PrecodeStubs.md Documents PrecodeType + GetPrecodeType API (v3-only).
docs/design/datacontracts/data-descriptor-meanings.json Adds meanings for new data/global descriptors used by stub tracing.

Copilot's findings

  • Files reviewed: 31/31 changed files
  • Comments generated: 5

/*struct CLRDATA_FOLLOW_STUB_BUFFER*/ void* outBuffer,
uint* outFlags)
=> LegacyFallbackHelper.CanFallback() && _legacyProcess is not null ? _legacyProcess.FollowStub(inFlags, inAddr, inBuffer, outAddr, outBuffer, outFlags) : HResults.E_NOTIMPL;
=> HResults.E_NOTIMPL;
Comment on lines +1719 to +1724
if (inFlags != CLRDataFollowStubInFlag.CLRDATA_FOLLOW_STUB_DEFAULT)
throw new ArgumentException();
if (outAddr is null || outBuffer is null || outFlags is null)
throw new NullReferenceException();

*outBuffer = default;
Comment on lines +1792 to +1804
StubContinuationKind kind = (StubContinuationKind)buffer->Data[0];
return kind switch
{
StubContinuationKind.MethodJitted => new StubContinuation(
kind,
new TargetPointer(buffer->Data[1]),
TargetCodePointer.Null),
StubContinuationKind.FramePush => new StubContinuation(
kind,
TargetPointer.Null,
new TargetCodePointer(buffer->Data[1])),
_ => throw new ArgumentException(),
};
case CodeKind.VSD_ResolveStub:
case CodeKind.VSD_LookupStub:
case CodeKind.VSD_VTableStub:
return s_failed; // we don't suppport these yet
Comment on lines +8 to +16
public enum StubTraceKind
{
Unknown,
Failed,
Managed,
Unmanaged,
UnjittedMethod,
FramePush,
}
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