[cDAC] Implement simple DacDbi methods and IDebugger contract#126032
Draft
max-charlamb wants to merge 2 commits intodotnet:mainfrom
Draft
[cDAC] Implement simple DacDbi methods and IDebugger contract#126032max-charlamb wants to merge 2 commits intodotnet:mainfrom
max-charlamb wants to merge 2 commits intodotnet:mainfrom
Conversation
Implement 37 IDacDbiInterface methods using cDAC contracts, replacing legacy delegation stubs with actual implementations: IDebugger contract (new): - Add IDebugger interface with 5 APIs for debugger state - Debugger_1 implementation reading from Debugger data descriptor and CLRJitAttachState/MetadataUpdatesApplied globals - Data descriptors in datadescriptor.inc and cdac_data<Debugger> - Contract documentation in docs/design/datacontracts/Debugger.md Implemented DacDbi methods by contract group: - Debugger: IsLeftSideInitialized, GetDefinesBitField, GetMDStructuresVersion, GetAttachStateFlags, MetadataUpdatesApplied - Thread: EnumerateThreads, IsThreadMarkedDead, TryGetVolatileOSThreadID, GetUniqueThreadID, GetCurrentException, IsThreadSuspendedOrHijacked, HasUnhandledException - Loader: GetAssemblyFromDomainAssembly, GetAppDomainFullName, GetModuleSimpleName, GetAssemblyPath, GetModulePath, GetModuleForDomainAssembly, GetDomainAssemblyFromModule, EnumerateAssembliesInAppDomain, EnumerateModulesInAssembly, IsModuleMapped - Hardcoded: GetAppDomainId, GetAppDomainFromId, GetCurrentAppDomain, EnumerateAppDomains, IsAssemblyFullyTrusted, GetConnectionID, GetTaskID, IsWinRTModule, GetAppDomainIdFromVmObjectHandle, EnableNGENPolicy - Type: GetTypeDef, IsValueType, HasTypeParams - Object: GetObjectFromRefPtr, GetObject, GetVmObjectHandle, IsVmObjectHandleValid, GetHandleAddressFromVmHandle - Code/GC: GetMethodDescPtrFromIP, AreGCStructuresValid, GetGCHeapInformation, GetTypeID, GetTypeIDForType All methods include #if DEBUG validation against legacy DAC. Tests: - 48 unit tests for IDebugger contract (DebuggerTests.cs) - 29 dump tests across 6 test classes (DacDbi*DumpTests.cs) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new Debugger cDAC contract and begins implementing IDacDbiInterface in managed C# using cDAC contracts, with accompanying unit tests and dump-based integration tests. It also wires up CoreCLR data descriptors/globals so the contract can read debugger state from targets.
Changes:
- Introduce IDebugger contract (data descriptor + managed contract implementation) and register it in the contract registry.
- Add a managed DacDbiImpl implementation (COM-visible) intended to replace legacy native delegation stubs for a set of IDacDbiInterface methods.
- Add unit tests for the Debugger contract plus multiple dump-based DacDbi integration test classes.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiThreadDumpTests.cs | Adds dump-based tests for DacDbi thread APIs (enumeration, thread state, OS thread id, exception). |
| src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiObjectDumpTests.cs | Adds dump-based tests for DacDbi object-handle identity and AppDomain-id-from-handle behavior. |
| src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiLoaderDumpTests.cs | Adds dump-based tests for loader/module/assembly DacDbi APIs, including string-returning methods and enumeration callbacks. |
| src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiGCDumpTests.cs | Adds dump-based tests for DacDbi GC APIs and cross-validation with GC contract. |
| src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiDebuggerDumpTests.cs | Adds dump-based tests for DacDbi Debugger-related APIs and cross-validation with Debugger contract. |
| src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiAppDomainDumpTests.cs | Adds dump-based tests for AppDomain/misc policy/flags-related DacDbi APIs. |
| src/native/managed/cdac/tests/DebuggerTests.cs | Adds unit tests for the new IDebugger contract using mock targets/memory. |
| src/native/managed/cdac/mscordaccore_universal/Entrypoints.cs | Adds unmanaged entrypoint for creating the managed COM DacDbi interface implementation. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/CachingContractRegistry.cs | Registers the Debugger contract factory so it’s available via Target.Contracts. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs | Introduces the managed COM class implementing IDacDbiInterface methods via cDAC contracts (with DEBUG cross-validation against legacy DAC). |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Debugger.cs | Adds processed-data reader for the Debugger data descriptor. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Debugger_1.cs | Implements IDebugger v1 using globals + processed data. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/DebuggerFactory.cs | Creates the correct Debugger contract implementation for a given version. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Constants.cs | Adds global names used by the Debugger contract implementation. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/DataType.cs | Adds DataType.Debugger for the new data descriptor. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/CorDbHResults.cs | Adds CORDBG_E_NOTREADY constant used by Debugger contract error behavior. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IDebugger.cs | Defines the IDebugger contract surface and default stub implementation. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/ContractRegistry.cs | Exposes Target.Contracts.Debugger accessor on the base registry. |
| src/coreclr/vm/datadescriptor/datadescriptor.inc | Adds Debugger data descriptor fields and global pointers (Debugger, CLRJitAttachState, MetadataUpdatesApplied) and registers the Debugger contract. |
| src/coreclr/debug/ee/debugger.h | Exposes Debugger field offsets to cDAC via cdac_data specialization. |
| docs/design/datacontracts/Debugger.md | Documents the Debugger contract’s APIs, globals, data descriptors, and algorithms. |
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiAppDomainDumpTests.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiDebuggerDumpTests.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiDebuggerDumpTests.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiAppDomainDumpTests.cs
Outdated
Show resolved
Hide resolved
max-charlamb
commented
Mar 24, 2026
...tive/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Debugger_1.cs
Outdated
Show resolved
Hide resolved
...tive/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Debugger_1.cs
Outdated
Show resolved
Hide resolved
...tive/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Debugger_1.cs
Outdated
Show resolved
Hide resolved
…mplement 3 new methods - Redesign IDebugger: TryGetDebuggerData replaces separate APIs - Use Marshal.GetExceptionForHR, ReadGlobalPointer for CLRJitAttachState - Implement GetModuleSimpleName, GetCurrentException, EnumerateModulesInAssembly - Fix GetAppDomainIdFromVmObjectHandle null handle, allow null legacy in entrypoint - Fix test BOOL types, add checkedCount assertions, filter Dead/Unstarted threads - Replace TestStringHolder with NativeStringHolder (native vtable layout) - Update Debugger.md doc format, include cdacdata.h, remove unnecessary friend decl Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
noahfalk
approved these changes
Mar 24, 2026
| namespace Microsoft.Diagnostics.DataContractReader.DumpTests; | ||
|
|
||
| /// <summary> | ||
| /// Creates a native-memory object that mimics the C++ IStringHolder vtable layout. |
Member
There was a problem hiding this comment.
Should we just make IStringHolder a COM interface so that our standard COM marshalling techniques work? Seems like it might be a little simpler.
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.
Summary
Implements 37 IDacDbiInterface methods in managed C# using cDAC contracts, replacing legacy native delegation stubs with actual implementations. Also introduces a new IDebugger contract for debugger state queries.
This builds on top of #125074 (COM conversion of IDacDbiInterface).
New IDebugger Contract
Adds the IDebugger contract with 5 APIs for reading debugger state:
datadescriptor.incandcdac_data<Debugger>Debugger_1implementation reading from Debugger data descriptor andCLRJitAttachState/MetadataUpdatesAppliedglobalsdocs/design/datacontracts/Debugger.mdImplemented DacDbi Methods by Contract Group
Debugger:
IsLeftSideInitialized,GetDefinesBitField,GetMDStructuresVersion,GetAttachStateFlags,MetadataUpdatesAppliedThread:
EnumerateThreads,IsThreadMarkedDead,TryGetVolatileOSThreadID,GetUniqueThreadID,GetCurrentException,IsThreadSuspendedOrHijacked,HasUnhandledExceptionLoader:
GetAssemblyFromDomainAssembly,GetAppDomainFullName,GetModuleSimpleName,GetAssemblyPath,GetModulePath,GetModuleForDomainAssembly,GetDomainAssemblyFromModule,EnumerateAssembliesInAppDomain,EnumerateModulesInAssembly,IsModuleMappedHardcoded:
GetAppDomainId,GetAppDomainFromId,GetCurrentAppDomain,EnumerateAppDomains,IsAssemblyFullyTrusted,GetConnectionID,GetTaskID,IsWinRTModule,GetAppDomainIdFromVmObjectHandle,EnableNGENPolicyType:
GetTypeDef,IsValueType,HasTypeParamsObject:
GetObjectFromRefPtr,GetObject,GetVmObjectHandle,IsVmObjectHandleValid,GetHandleAddressFromVmHandleCode/GC:
GetMethodDescPtrFromIP,AreGCStructuresValid,GetGCHeapInformation,GetTypeID,GetTypeIDForTypeAll methods include
#if DEBUGvalidation against the legacy DAC to verify consistency.IStringHolder Vtable Calling
Since
IStringHolderis not a COM interface (it's a plain C++ abstract class with a single virtual method), the managed implementation calls through its vtable directly usingdelegate* unmanagedfunction pointers.Testing
DebuggerTests.cs)DacDbi*DumpTests.cs) validating against real crash dumps