Skip to content

[cDAC] Reduce SOSDacImpl.GetFieldDescData dependencies (add GetFieldDescNext; use GetFieldDescApproxTypeHandle) - #130643

Merged
max-charlamb merged 6 commits into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/cdac-getfielddescnext
Jul 14, 2026
Merged

max-charlamb merged 6 commits into
dotnet:mainfrom
max-charlamb:dev/max-charlamb/cdac-getfielddescnext

Conversation

@max-charlamb

@max-charlamb max-charlamb commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Two small refactors that reduce what SOSDacImpl.GetFieldDescData does directly, delegating to the RuntimeTypeSystem contract instead.

1. GetFieldDescNext -- stop depending on FieldDesc layout

The consumer computed the next FieldDesc inline as ptr + sizeof(FieldDesc) (via DataType.FieldDesc). "Next" is a synthetic notion -- a FieldDesc has no next pointer -- so producing it is an algorithm that belongs in the contract.

  • Add TargetPointer GetFieldDescNext(TargetPointer fieldDescPointer) to IRuntimeTypeSystem.
  • CoreCLR impl returns fieldDescPointer + sizeof(FieldDesc) (same value as before, now behind the contract).
  • SOSDacImpl.GetFieldDescData calls it and no longer references the FieldDesc data descriptor.

2. Use GetFieldDescApproxTypeHandle for the field-type MethodTable

GetFieldDescData decoded the field signature inline (via ISignature) to get the field type's TypeHandle. GetFieldDescApproxTypeHandle already encapsulates that exact decode, so the consumer now calls it and drops its ISignature dependency.

Behavior is unchanged for CoreCLR (the catch-all in GetFieldDescApproxTypeHandle tracks the legacy DAC's EX_CATCH), and the #if DEBUG legacy-DAC parity check still passes.

Testing

  • cDAC builds clean (0 warnings / 0 errors).
  • Full cDAC unit test suite passes (2693 passed, 16 skipped, 0 failed).

Note

This PR was created with GitHub Copilot.

…on FieldDesc layout

SOSDacImpl.GetFieldDescData computed the next FieldDesc as
ptr + sizeof(FieldDesc), which requires the consumer to know the FieldDesc
layout (via DataType.FieldDesc). "Next" is a synthetic notion -- a FieldDesc
has no next pointer -- so producing it is an algorithm that belongs in the
contract.

Add GetFieldDescNext(TargetPointer) to IRuntimeTypeSystem; the CoreCLR
implementation returns ptr + sizeof(FieldDesc). The consumer now calls the
contract method and no longer references the FieldDesc data descriptor.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors SOS legacy GetFieldDescData to stop computing the “next FieldDesc” via inline pointer arithmetic, moving that algorithm behind the cDAC IRuntimeTypeSystem contract.

Changes:

  • Adds IRuntimeTypeSystem.GetFieldDescNext(TargetPointer) to represent the synthetic “next FieldDesc” computation as a contract algorithm.
  • Implements GetFieldDescNext in RuntimeTypeSystem_1 (CoreCLR) using sizeof(FieldDesc) via the data descriptor size.
  • Updates SOSDacImpl.GetFieldDescData to call the new contract API when populating DacpFieldDescData.NextField.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs Switches NextField computation to the contract API.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs Adds CoreCLR implementation of GetFieldDescNext.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeTypeSystem.cs Adds the new contract method to the FieldDesc inspection APIs.

Copilot AI review requested due to automatic review settings July 13, 2026 20:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

…tFieldDescData

SOSDacImpl.GetFieldDescData decoded the field signature inline (via ISignature)
to obtain the field type's TypeHandle. GetFieldDescApproxTypeHandle already
encapsulates that exact decode, so call it instead and drop the ISignature
dependency. Behavior is unchanged -- the catch-all in GetFieldDescApproxTypeHandle
tracks the legacy DAC's EX_CATCH, and the DEBUG parity assert still passes.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings July 13, 2026 20:17
@max-charlamb max-charlamb changed the title [cDAC] Add IRuntimeTypeSystem.GetFieldDescNext to remove FieldDesc-layout dependency from SOSDacImpl [cDAC] Reduce SOSDacImpl.GetFieldDescData dependencies (add GetFieldDescNext; use GetFieldDescApproxTypeHandle) Jul 13, 2026
@max-charlamb
max-charlamb marked this pull request as ready for review July 13, 2026 20:20
@max-charlamb
max-charlamb requested a review from rcj1 July 13, 2026 20:20
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings July 13, 2026 20:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Change the RTS FieldDesc-advance API from a null-returning
GetFieldDescNext(TargetPointer) to a Try-pattern
TryGetFieldDescNext(TargetPointer, out TargetPointer) that returns false
when called on the last FieldDesc of a type. The implementation locates
the enclosing type via the FieldDesc's enclosing MethodTable and computes
the end of the contiguous FieldDesc list (mirroring GetFieldDescList) so
callers never receive a past-the-end pointer.

SOSDacImpl surfaces the 'no next field' result as 0 to match the legacy
DAC ABI, and the DEBUG parity assert tolerates that against the DAC's
past-the-end pointer. Updates RuntimeTypeSystem.md and adds a unit test.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings July 14, 2026 17:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@max-charlamb
max-charlamb enabled auto-merge (squash) July 14, 2026 18:56
@max-charlamb

Copy link
Copy Markdown
Member Author

/ba-g osx test infra timeout

@max-charlamb
max-charlamb merged commit 4d33abd into dotnet:main Jul 14, 2026
71 of 77 checks passed
@max-charlamb
max-charlamb deleted the dev/max-charlamb/cdac-getfielddescnext branch July 14, 2026 20:18
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 15, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants