-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[cDAC] Implement simple DacDbi methods and IDebugger contract #126032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
max-charlamb
merged 17 commits into
dotnet:main
from
max-charlamb:droid-debug-dacdbi-impl
Apr 1, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4e4e0a0
Implement cDAC DacDbi methods and IDebugger contract
9cc1018
Address PR review feedback: redesign IDebugger contract, fix tests, i…
12deea8
Fix bugs found during live MDbg cross-validation testing
df8aaf9
Fix GetDomainAssemblyFromModule: fall back to legacy
d4180c3
Fix CI failures: FEATURE_METADATA_UPDATER guard, DomainAssembly ident…
095f7d9
Update Debugger.md pseudocode for double-indirection pattern
151ffe5
Revert DomainAssembly cDAC implementations to legacy fallback
61085ed
Address PR review feedback: calling conventions, cdac_data cleanup
da076b2
Guard Debugger data descriptors with DEBUGGING_SUPPORTED
1857d11
Merge remote-tracking branch 'origin/main' into droid-debug-dacdbi-impl
b5c52d3
Remove stale blank line in debugger.h to eliminate diff
c5c689b
Use GCIdentifiers constants instead of magic strings in GetGCHeapInfo…
f9999ce
Use ICorDebugDataTarget for CDAC initialization instead of ICorDebugM…
37a383c
Use DefaultADID global instead of hardcoded AppDomain ID
2d96110
Use TryGetSimpleName for GetModuleSimpleName to match native DAC
39eca3c
Use TryGetSimpleName for GetModuleSimpleName to match native DAC
ce7dffa
Guard Debugger data descriptors with !TARGET_WASM
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Contract Debugger | ||
|
|
||
| This contract is for reading debugger state from the target process, including initialization status, configuration flags, metadata update state, and JIT attach state. | ||
|
|
||
| ## APIs of contract | ||
|
|
||
| ```csharp | ||
| record struct DebuggerData(uint DefinesBitField, uint MDStructuresVersion); | ||
| ``` | ||
|
|
||
| ```csharp | ||
| bool TryGetDebuggerData(out DebuggerData data); | ||
| int GetAttachStateFlags(); | ||
| bool MetadataUpdatesApplied(); | ||
| ``` | ||
|
|
||
| ## Version 1 | ||
|
|
||
| The contract depends on the following globals | ||
|
|
||
| | Global Name | Type | Description | | ||
| | --- | --- | --- | | ||
| | `Debugger` | TargetPointer | Address of the pointer to the Debugger instance (`&g_pDebugger`) | | ||
| | `CLRJitAttachState` | TargetPointer | Pointer to the CLR JIT attach state flags | | ||
| | `MetadataUpdatesApplied` | TargetPointer | Pointer to the g_metadataUpdatesApplied flag | | ||
|
|
||
| The contract additionally depends on these data descriptors | ||
|
|
||
| | Data Descriptor Name | Field | Meaning | | ||
| | --- | --- | --- | | ||
| | `Debugger` | `LeftSideInitialized` | Whether the left-side debugger infrastructure is initialized | | ||
| | `Debugger` | `Defines` | Bitfield of compile-time debugger feature defines | | ||
| | `Debugger` | `MDStructuresVersion` | Version of metadata data structures | | ||
|
|
||
| ```csharp | ||
| bool TryGetDebuggerData(out DebuggerData data) | ||
| { | ||
| data = default; | ||
| // The Debugger global points to g_pDebugger (a pointer-to-pointer). | ||
| // First read gets the address of g_pDebugger, second dereferences it. | ||
| TargetPointer debuggerPtrPtr = target.ReadGlobalPointer("Debugger"); | ||
| if (debuggerPtrPtr == TargetPointer.Null) | ||
| return false; | ||
| TargetPointer debuggerPtr = target.ReadPointer(debuggerPtrPtr); | ||
| if (debuggerPtr == TargetPointer.Null) | ||
| return false; | ||
| int leftSideInitialized = target.Read<int>(debuggerPtr + /* Debugger::LeftSideInitialized offset */); | ||
| if (leftSideInitialized == 0) | ||
| return false; | ||
| data = new DebuggerData( | ||
| DefinesBitField: target.Read<uint>(debuggerPtr + /* Debugger::Defines offset */), | ||
| MDStructuresVersion: target.Read<uint>(debuggerPtr + /* Debugger::MDStructuresVersion offset */)); | ||
| return true; | ||
| } | ||
|
|
||
| int GetAttachStateFlags() | ||
| { | ||
| TargetPointer addr = target.ReadGlobalPointer("CLRJitAttachState"); | ||
| return (int)target.Read<uint>(addr); | ||
| } | ||
|
|
||
| bool MetadataUpdatesApplied() | ||
| { | ||
| if (target.TryReadGlobalPointer("MetadataUpdatesApplied", out TargetPointer addr)) | ||
| return target.Read<byte>(addr) != 0; | ||
| return false; | ||
| } | ||
| ``` | ||
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
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
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
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
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
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
22 changes: 22 additions & 0 deletions
22
...managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IDebugger.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
|
||
| public record struct DebuggerData(uint DefinesBitField, uint MDStructuresVersion); | ||
|
|
||
| public interface IDebugger : IContract | ||
| { | ||
| static string IContract.Name { get; } = nameof(Debugger); | ||
|
|
||
| bool TryGetDebuggerData(out DebuggerData data) => throw new NotImplementedException(); | ||
| int GetAttachStateFlags() => throw new NotImplementedException(); | ||
| bool MetadataUpdatesApplied() => throw new NotImplementedException(); | ||
| } | ||
|
|
||
| public readonly struct Debugger : IDebugger | ||
| { | ||
| // Everything throws NotImplementedException | ||
| } |
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
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
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
18 changes: 18 additions & 0 deletions
18
...aged/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/DebuggerFactory.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
|
||
| public sealed class DebuggerFactory : IContractFactory<IDebugger> | ||
| { | ||
| IDebugger IContractFactory<IDebugger>.CreateContract(Target target, int version) | ||
| { | ||
| return version switch | ||
| { | ||
| 1 => new Debugger_1(target), | ||
| _ => default(Debugger), | ||
| }; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...e/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Debugger_1.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
|
||
| internal readonly struct Debugger_1 : IDebugger | ||
| { | ||
| private readonly Target _target; | ||
|
|
||
| internal Debugger_1(Target target) | ||
| { | ||
| _target = target; | ||
| } | ||
|
|
||
| bool IDebugger.TryGetDebuggerData(out DebuggerData data) | ||
| { | ||
| data = default; | ||
| TargetPointer debuggerPtrPtr = _target.ReadGlobalPointer(Constants.Globals.Debugger); | ||
| if (debuggerPtrPtr == TargetPointer.Null) | ||
| return false; | ||
|
|
||
| TargetPointer debuggerPtr = _target.ReadPointer(debuggerPtrPtr); | ||
| if (debuggerPtr == TargetPointer.Null) | ||
| return false; | ||
|
|
||
| Data.Debugger debugger = _target.ProcessedData.GetOrAdd<Data.Debugger>(debuggerPtr); | ||
| if (debugger.LeftSideInitialized == 0) | ||
| return false; | ||
|
|
||
| data = new DebuggerData(debugger.Defines, debugger.MDStructuresVersion); | ||
| return true; | ||
| } | ||
|
|
||
| int IDebugger.GetAttachStateFlags() | ||
| { | ||
| TargetPointer addr = _target.ReadGlobalPointer(Constants.Globals.CLRJitAttachState); | ||
| return (int)_target.Read<uint>(addr.Value); | ||
| } | ||
|
|
||
| bool IDebugger.MetadataUpdatesApplied() | ||
| { | ||
| if (_target.TryReadGlobalPointer(Constants.Globals.MetadataUpdatesApplied, out TargetPointer? addr)) | ||
| { | ||
| return _target.Read<byte>(addr.Value.Value) != 0; | ||
| } | ||
| return false; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.