Skip to content

[cDAC] Add GetApproxTypeHandle DacDbi API#128921

Open
Copilot wants to merge 19 commits into
mainfrom
copilot/implement-getapproxtypehandle
Open

[cDAC] Add GetApproxTypeHandle DacDbi API#128921
Copilot wants to merge 19 commits into
mainfrom
copilot/implement-getapproxtypehandle

Conversation

Copilot AI commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Add this API using a port of the native type-walk logic and a slight tweak to the RuntimeTypeSystem API that determines if something is a reference type.

Copilot AI and others added 2 commits June 2, 2026 15:30
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
@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.

…y+metadataToken

Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 3, 2026 00:35
Copilot AI changed the title Add DacDbi approximate type handle dump tests Add GetApproxTypeHandle dump tests Jun 3, 2026
Copilot finished work on behalf of rcj1 June 3, 2026 00:35
Copilot AI requested a review from rcj1 June 3, 2026 00:35
Copilot AI review requested due to automatic review settings June 3, 2026 02:46

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 adds dump-based coverage for DacDbiImpl.GetApproxTypeHandle by mirroring the existing exact-type-handle dump tests: it enumerates heap objects reachable from GC handles in the ExactTypeHandle debuggee, constructs the flattened DebuggerIPCE_TypeArgData[] tree (a managed port of CordbType::GatherTypeData), round-trips that through GetApproxTypeHandle, and asserts the returned vmTypeHandle matches an independently canonicalized expected MethodTable. To support this, it also adds a managed TypeDataWalk implementation and refactors some type lookup logic into a helper.

Changes:

  • Add a new dump test suite DacDbiApproxTypeHandleDumpTests implementing the right-side “gather type data” flattening and expected-handle canonicalization.
  • Implement managed GetApproxTypeHandle support via a new TypeDataWalk port and supporting helper types.
  • Replace IsObjRef(TypeHandle) usage with a new IsCorElementTypeObjRef(CorElementType) helper across tests, the contract, and documentation.
Show a summary per file
File Description
src/native/managed/cdac/tests/MethodTableTests.cs Updates objref classification assertions to use IsCorElementTypeObjRef(GetInternalCorElementType(...)).
src/native/managed/cdac/tests/DumpTests/RuntimeTypeSystemDumpTests.cs Updates dump-based RTS “objref consistency” test to use the new helper.
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiObjectDumpTests.cs Updates reference-type offset logic to use the new helper.
src/native/managed/cdac/tests/DumpTests/DacDbi/DacDbiApproxTypeHandleDumpTests.cs New dump test covering round-trip behavior for GetApproxTypeHandle across reachable handle objects.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/TypeDataWalk.cs New managed port of the native flattened-type-data walker used by GetApproxTypeHandle.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/IDacDbiInterface.cs Adds DebuggerIPCE_TypeArgData / TypeInfoList and tightens GetApproxTypeHandle signature to a typed pointer.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DbiHelpers.cs New helper for resolving typeDef/typeRef MethodTables from an assembly+token via loader lookup tables.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs Implements managed GetApproxTypeHandle and switches some ref-type checks to IsCorElementTypeObjRef.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs Replaces IsObjRef with IsCorElementTypeObjRef implementation used by the contract.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeTypeSystem.cs Changes the contract surface by removing IsObjRef(TypeHandle) and adding IsCorElementTypeObjRef(CorElementType).
docs/design/datacontracts/RuntimeTypeSystem.md Updates contract documentation to match the new helper.

Copilot's findings

  • Files reviewed: 11/11 changed files
  • Comments generated: 5

Comment thread docs/design/datacontracts/RuntimeTypeSystem.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 3, 2026 03:50

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.

Copilot's findings

  • Files reviewed: 11/11 changed files
  • Comments generated: 7

Comment thread docs/design/datacontracts/RuntimeTypeSystem.md Outdated
Comment thread src/native/managed/cdac/tests/UnitTests/MethodTableTests.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 3, 2026 04:02

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.

Copilot's findings

  • Files reviewed: 11/11 changed files
  • Comments generated: 4

Comment thread docs/design/datacontracts/RuntimeTypeSystem.md
rcj1 and others added 2 commits June 2, 2026 23:05
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please fix the cDAC dump tests.

Fixed the CdacDumpTests build break. The failure was a set of CS0246/CS0103 errors in DacDbiApproxTypeHandleDumpTests.cs (DumpTestBase, TestConfiguration, TestConfigurations not found). Those types were relocated to the Microsoft.Diagnostics.DataContractReader.TestInfrastructure namespace by the test-harness refactor (#128863) that landed via the merge, and the new test file was missing that using. Added the directive to match the sibling DacDbiExactTypeHandleDumpTests.cs.

Copilot finished work on behalf of rcj1 June 8, 2026 00:22
@rcj1 rcj1 changed the title Add GetApproxTypeHandle dump tests [cDAC] Add GetApproxTypeHandle DacDbi API Jun 8, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 22:27

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.

Copilot's findings

  • Files reviewed: 11/11 changed files
  • Comments generated: 1

Copilot AI review requested due to automatic review settings June 18, 2026 22:35

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.

Copilot's findings

  • Files reviewed: 11/11 changed files
  • Comments generated: 2

Copilot AI review requested due to automatic review settings June 19, 2026 00:05

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.

Copilot's findings

  • Files reviewed: 10/10 changed files
  • Comments generated: 2

Comment on lines +146 to 151
// True if the CorElementType represents a GC-collectable object reference.
bool IsCorElementTypeObjRef(CorElementType elementType) => throw new NotImplementedException();
// Returns the address of one of the runtime's well-known singleton MethodTables,
// or TargetPointer.Null if the runtime has not yet initialized that global.
TargetPointer GetWellKnownMethodTable(WellKnownMethodTable kind) => throw new NotImplementedException();
bool IsObjRef(TypeHandle typeHandle) => throw new NotImplementedException();
// True if the MethodTable represents a type that contains managed references
@rcj1 rcj1 marked this pull request as ready for review June 19, 2026 01:20
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

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.

Copilot's findings

  • Files reviewed: 10/10 changed files
  • Comments generated: 5

Comment on lines +706 to +709
Assert.True(contract.IsCorElementTypeObjRef(contract.GetInternalCorElementType(contract.GetTypeHandle(objectTypePtr))));
Assert.True(contract.IsCorElementTypeObjRef(contract.GetInternalCorElementType(contract.GetTypeHandle(stringTypePtr))));
Assert.True(contract.IsCorElementTypeObjRef(contract.GetInternalCorElementType(contract.GetTypeHandle(szArrayTypePtr))));
Assert.False(contract.IsCorElementTypeObjRef(contract.GetInternalCorElementType(contract.GetTypeHandle(truePrimitiveTypePtr))));
Comment on lines +26 to +31
/// - Top-level Class / ValueType keeps the typeDef; only its type-args are canonicalized.
/// - Reference-typed generic args collapse to <c>System.__Canon</c>.
/// - Value-type args are recursively approximated (with the same rules applied to their args).
/// - Array / Ptr / Byref: outer shape preserved; the inner type goes through the
/// type-arg canonicalization rules.
/// </para>
Comment on lines +2620 to +2624
IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem;

TargetPointer canonMtPtr = _target.ReadPointer(_target.ReadGlobalPointer(Constants.Globals.CanonMethodTable));
TypeHandle canonTh = rts.GetTypeHandle(canonMtPtr);

Comment on lines +4 to +7
using System;
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using Microsoft.Diagnostics.DataContractReader.Contracts;
Comment on lines 143 to 151
// True if the MethodTable is the System.Object MethodTable (g_pObjectClass)
bool IsObject(TypeHandle typeHandle) => throw new NotImplementedException();
bool IsString(TypeHandle typeHandle) => throw new NotImplementedException();
// True if the CorElementType represents a GC-collectable object reference.
bool IsCorElementTypeObjRef(CorElementType elementType) => throw new NotImplementedException();
// Returns the address of one of the runtime's well-known singleton MethodTables,
// or TargetPointer.Null if the runtime has not yet initialized that global.
TargetPointer GetWellKnownMethodTable(WellKnownMethodTable kind) => throw new NotImplementedException();
bool IsObjRef(TypeHandle typeHandle) => throw new NotImplementedException();
// True if the MethodTable represents a type that contains managed references
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants