-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add cDAC tests and implementation for GetGenerationTable and GetFinalizationFillPointers #124674
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
Open
noahfalk
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
noahfalk:124583_cdac_gc_generation_table
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
104 changes: 104 additions & 0 deletions
104
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/README.md
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,104 @@ | ||
| # Microsoft.Diagnostics.DataContractReader.Legacy | ||
|
|
||
| This project contains `SOSDacImpl`, which implements the `ISOSDacInterface*` and | ||
| `IXCLRDataProcess` COM-style APIs by delegating to the cDAC contract layer. | ||
|
|
||
| ## Implementing a new SOSDacImpl method | ||
|
|
||
| When a method currently delegates to `_legacyImpl` (returning `E_NOTIMPL` when null), | ||
| replace it with a cDAC implementation following this pattern: | ||
|
|
||
| ```csharp | ||
| int ISOSDacInterface8.ExampleMethod(uint* pResult) | ||
| { | ||
| // 1. Validate pointer arguments before the try block | ||
| if (pResult == null) | ||
| return HResults.E_INVALIDARG; | ||
|
|
||
| int hr = HResults.S_OK; | ||
| try | ||
| { | ||
| // 2. Get the relevant contract and call it | ||
| IGC gc = _target.Contracts.GC; | ||
| *pResult = gc.SomeMethod(); | ||
| } | ||
| catch (System.Exception ex) | ||
| { | ||
| hr = ex.HResult; | ||
| } | ||
|
|
||
| // 3. Cross-validate with legacy DAC in debug builds | ||
| #if DEBUG | ||
| if (_legacyImpl8 is not null) | ||
| { | ||
| uint resultLocal; | ||
| int hrLocal = _legacyImpl8.ExampleMethod(&resultLocal); | ||
| Debug.Assert(hrLocal == hr, $"cDAC: {hr:x}, DAC: {hrLocal:x}"); | ||
| if (hr == HResults.S_OK) | ||
| { | ||
| Debug.Assert(*pResult == resultLocal); | ||
| } | ||
| } | ||
| #endif | ||
| return hr; | ||
| } | ||
| ``` | ||
|
|
||
| ### Key conventions | ||
|
|
||
| - **HResult returns**: Methods return `int` HResult codes, not exceptions. | ||
| Use `HResults.S_OK`, `HResults.S_FALSE`, `HResults.E_INVALIDARG`, etc. | ||
| - **Null pointer checks**: Validate output pointer arguments *before* the try block | ||
| and return `E_INVALIDARG`. This matches the native DAC behavior. | ||
| - **Exception handling**: Wrap all contract calls in try/catch. The catch converts | ||
| exceptions to HResult codes via `ex.HResult`. When the native DAC has an explicit | ||
| readability check (e.g., `ptr.IsValid()` or `DACGetMethodTableFromObjectPointer` | ||
| returning NULL), catch `VirtualReadException` specifically and return the same | ||
| HResult the native DAC returns (typically `E_INVALIDARG`). Avoid catching all | ||
| exceptions and mapping to a single HRESULT, as this can mask unrelated bugs. | ||
| - **Debug cross-validation**: In `#if DEBUG`, call the legacy implementation (if | ||
| available) and assert the results match. This catches discrepancies during testing. | ||
|
|
||
| ### Legacy delegation placement | ||
|
|
||
| Some cDAC methods create child objects (e.g., `ClrDataMethodInstance`, | ||
| `ClrDataFrame`) that delegate certain operations to a legacy counterpart. This is | ||
| a temporary implementation workaround to let us create the cDAC incrementally that | ||
| should be removed before cDAC ships to customers. In these cases, the legacy call | ||
| that obtains the counterpart **must be outside `#if DEBUG`**, because the result is | ||
| used functionally, not just for validation. | ||
|
|
||
| For example, `EnumMethodInstanceByAddress` passes `legacyMethod` to | ||
| `ClrDataMethodInstance`, which delegates `GetTokenAndScope` and other calls to it. | ||
| If the legacy enumeration only runs inside `#if DEBUG`, those delegated calls fail | ||
| in Release builds. | ||
|
|
||
| **Rule of thumb**: if a legacy call's result is stored and passed to another | ||
| object, keep it outside `#if DEBUG`. Only the assertion that compares | ||
| HResults/values belongs inside `#if DEBUG`. | ||
|
|
||
| ### Sized-buffer protocol | ||
|
|
||
| Several `ISOSDacInterface8` methods use a two-call pattern where the caller first | ||
| queries the needed buffer size, then calls again with a sufficiently large buffer: | ||
|
|
||
| ```csharp | ||
| int GetSomeTable(uint count, Data* buffer, uint* pNeeded) | ||
| ``` | ||
|
|
||
| The protocol is: | ||
| 1. Always set `*pNeeded` to the required count (if `pNeeded` is not null). | ||
| 2. If `count > 0 && buffer == null`: return `E_INVALIDARG`. | ||
| 3. If `count < needed`: return `S_FALSE` (buffer too small, but `*pNeeded` is set). | ||
| 4. If `count >= needed`: populate `buffer` and return `S_OK`. | ||
|
|
||
| This matches the native implementation in `src/coreclr/debug/daccess/request.cpp`. | ||
|
|
||
| ### Pointer conversions | ||
|
|
||
| - `TargetPointer` → `ClrDataAddress`: use `pointer.ToClrDataAddress(_target)`. | ||
| On 32-bit targets, this **sign-extends** the value (e.g., `0xAA000000` becomes | ||
| `0xFFFFFFFF_AA000000`). This matches native DAC behavior. | ||
| - `ClrDataAddress` → `TargetPointer`: use `address.ToTargetPointer(_target)`. | ||
|
|
||
| Both are defined in `ConversionExtensions.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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephentoub - Since earlier you mentioned context window sizes were a concern, any thoughts on using something like this as a mechanism for progressive discovery? I wanted to add more component-specific guidance (see READMEs elsewhere in this PR as an example) but I didn't want to bloat the context window for prompts working in unrelated parts of the code.