Add cDAC tests and implementation for GetGenerationTable and GetFinalizationFillPointers#124674
Merged
noahfalk merged 7 commits intodotnet:mainfrom Mar 4, 2026
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements four ISOSDacInterface8 methods in the cDAC SOSDacImpl layer for querying GC generation tables and finalization fill pointers, along with comprehensive test infrastructure and documentation.
Changes:
- Implements
GetGenerationTable,GetGenerationTableSvr,GetFinalizationFillPointers, andGetFinalizationFillPointersSvrinSOSDacImpl.csby delegating to the existingIGCcontract - Introduces
TestPlaceholderTarget.Builderpattern with fluent API andTestContractRegistryto replaceMock<ContractRegistry>for more maintainable test setup - Adds
GCHeapBuilderwith extension methods (AddGCHeapWks/AddGCHeapSvr) to configure GC mock data declaratively - Provides 36 test cases total (3 contract-level + 6 SOSDacImpl-level × 4 architectures each) with proper sign-extension handling
- Documents the cDAC architecture, test patterns, and SOSDacImpl implementation conventions in new README files
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/native/managed/cdac/tests/TestPlaceholderTarget.cs | Removes Moq dependency; adds fluent Builder class and TestContractRegistry for programmatic test target construction |
| src/native/managed/cdac/tests/MockDescriptors/MockDescriptors.GC.cs | New file: GCHeapBuilder config class and extension methods to set up workstation/server GC heap mock data |
| src/native/managed/cdac/tests/GCTests.cs | New file: 3 contract-level tests verifying IGC.GetHeapData() correctly reads generation table and fill pointers |
| src/native/managed/cdac/tests/SOSDacInterface8Tests.cs | New file: 6 SOSDacImpl-level tests validating buffer sizing protocol, HResult codes, and pointer sign-extension |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs | Implements 4 ISOSDacInterface8 methods with proper validation, error handling, and debug cross-validation |
| src/native/managed/cdac/tests/README.md | New documentation: test architecture, builder patterns, sign-extension gotchas, and mock descriptor guidelines |
| src/native/managed/cdac/README.md | New documentation: cDAC architecture overview, project structure, and integration testing workflow |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/README.md | New documentation: SOSDacImpl implementation patterns, HResult conventions, and buffer sizing protocol |
| .github/copilot-instructions.md | Adds instruction to search for README files in directory hierarchy before making changes |
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
noahfalk
commented
Feb 20, 2026
noahfalk
commented
Feb 20, 2026
noahfalk
commented
Feb 20, 2026
f9fb24b to
398b718
Compare
src/native/managed/cdac/tests/MockDescriptors/MockDescriptors.GC.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/tests/MockDescriptors/MockDescriptors.GC.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
33c4550 to
10ab4c2
Compare
10ab4c2 to
77081c0
Compare
…izationFillPointers Implement the four ISOSDacInterface8 methods in cDAC SOSDacImpl: - GetGenerationTable / GetGenerationTableSvr - GetFinalizationFillPointers / GetFinalizationFillPointersSvr Add test infrastructure: - TestPlaceholderTarget.Builder: fluent builder that owns MockMemorySpace, accumulates types/globals, and wires contracts via TestContractRegistry. - GCHeapBuilder + extension methods (AddGCHeapWks/AddGCHeapSvr): configure GC mock data via Action<GCHeapBuilder> and build directly into the target. - TestContractRegistry: Dictionary<Type, Lazy<IContract>> replacement for Mock<ContractRegistry> in the builder path. Add tests: - 3 contract-level tests in GCTests.cs (x4 arch = 12) - 6 SOSDacImpl-level tests in SOSDacInterface8Tests.cs (x4 arch = 24) Add documentation: - README.md files for cdac/, Legacy/, and tests/ directories - Copilot instruction to search for READMEs along the path hierarchy Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixes discovered while running SOS integration tests against the new GetGenerationTable/GetFinalizationFillPointers implementation: - Fix cDAC library loading on Unix (PAL_GetPalHostModule) - Fix Thread data model crash on non-Windows (TryGetValue for UEWatsonBucketTrackerBuckets) - Fix HRESULT variable shadowing in 8 SOSDacInterface APIs in request.cpp where inner HRESULT declarations masked the return value - Fix cDAC legacy stack walk not advancing in Release builds (ClrDataStackWalk.Next must call legacy outside #if DEBUG) - Fix Debug assertion failures: catch VirtualReadException in GetAppDomainName and GetObjectData, fall back to legacy in EnumMethodInstanceByAddress - Address PR review feedback: add insufficient-buffer tests, pNeeded cross-validation assertions, and reduce test data duplication with shared helpers - Update README documentation with VirtualReadException guidance and legacy delegation placement Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…hard to diagnose CI failures.
…atch, use heapData.GenerationTable.Count, and use local buffers for debug cross-validation - Change void* to DacpGenerationData* in ISOSDacInterface8 methods - Move null/validation checks inside try/catch blocks per PR dotnet#124814 pattern - Replace ReadGlobal<uint>(TotalGenerationCount) with heapData.GenerationTable.Count - Use local buffers for legacy DAC cross-validation to avoid overwriting cDAC data - Use 'is null'/'is not null' instead of '== null'/'!= null' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
77081c0 to
6ceae96
Compare
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
…EBUG loop bounds - GetNumberGenerations: use gc.GetMaxGeneration()+1 via the GC contract instead of gc.GetHeapData() which throws on Server GC targets. - GetGenerationTable/GetFinalizationFillPointers DEBUG cross-validation: limit comparison loops to pNeededLocal (the actual written count) instead of the caller buffer size to avoid comparing uninitialized trailing entries. - GetFinalizationFillPointersSvr: use Math.Min(cFillPointers, pNeededLocal) for the same reason. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b856258 to
8fe5119
Compare
This was referenced Mar 3, 2026
rcj1
reviewed
Mar 3, 2026
max-charlamb
approved these changes
Mar 3, 2026
Member
max-charlamb
left a comment
There was a problem hiding this comment.
looks good modulo couple comments
.../managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs
Show resolved
Hide resolved
.../managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs
Show resolved
Hide resolved
…ally The legacy enumeration is started and advanced unconditionally in StartEnumMethodInstancesByAddress and EnumMethodInstanceByAddress, but EndEnumMethodInstancesByAddress only cleaned up the legacy handle under #if DEBUG. This would leak the legacy enumeration handle in Release builds. Remove the #if DEBUG guard so the cleanup runs in all builds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
GetGenerationTable and GetFinalizationFillPointers are WKS-only APIs; GetGenerationTableSvr and GetFinalizationFillPointersSvr are Server-only. When called against the wrong GC mode, the native DAC returns E_FAIL, but the cDAC was returning COR_E_INVALIDOPERATION (from the GC contract's InvalidOperationException), which would cause a debug assert mismatch during cross-validation. Add explicit GC mode checks to all four methods and add 16 unit tests validating the error behavior in both directions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Implement the four ISOSDacInterface8 methods in cDAC SOSDacImpl:
Add test infrastructure:
Add tests:
Add documentation:
Add a variety of fixes for pre-existing issues I discovered trying to run the SOS tests on Linux for both Release and Debug flavors. I'm guessing those testing configurations haven't been used much:
request.cpp where inner HRESULT declarations masked the return value
(ClrDataStackWalk.Next must call legacy outside #if DEBUG)
GetAppDomainName and GetObjectData, fall back to legacy in
EnumMethodInstanceByAddress
Fixes #124692
Fixes #124693
Fixes #124694
Fixes #124695