Implement cDAC stub tracing support - #131546
Closed
rcj1 wants to merge 1 commit into
Closed
Conversation
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
|
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. |
Contributor
There was a problem hiding this comment.
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
IStubTracingcontract (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.FollowStub2in 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, | ||
| } |
This was referenced Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.