Skip to content

Commit 3fe8518

Browse files
rcj1jkoritzinsky
andauthored
Packing Legacy cDAC apis (#121081)
This PR does some work and refactoring in order to facilitate a private version of the cDAC. 1. Assuming that we may want to access some of the legacy APIs from the private cDAC, I have pulled the legacy code into a separate package and made the COM interop classes public for use. 2. I have added a mechanism to add new contract implementations to a target upon instantiation of the target. This way the private cDAC can add its own contracts. 3. Exposing GetContract<TContract>. The private cDAC can in the future call GetContract with contracts not found in the default contract registry. This will probably be hidden behind an extension method but we need GetContract public for implementation. --------- Co-authored-by: Jeremy Koritzinsky <jkoritzinsky@gmail.com>
1 parent 9be281b commit 3fe8518

28 files changed

+178
-144
lines changed

eng/Subsets.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@
509509
<!-- Direct references to cDAC projects for packing -->
510510
<ProjectToBuild Include="$(SharedNativeRoot)managed\cdac\Microsoft.Diagnostics.DataContractReader\Microsoft.Diagnostics.DataContractReader.csproj;
511511
$(SharedNativeRoot)managed\cdac\Microsoft.Diagnostics.DataContractReader.Abstractions\Microsoft.Diagnostics.DataContractReader.Abstractions.csproj;
512+
$(SharedNativeRoot)managed\cdac\Microsoft.Diagnostics.DataContractReader.Legacy\Microsoft.Diagnostics.DataContractReader.Legacy.csproj;
512513
$(SharedNativeRoot)managed\cdac\Microsoft.Diagnostics.DataContractReader.Contracts\Microsoft.Diagnostics.DataContractReader.Contracts.csproj" Category="tools" Condition="'$(DotNetBuildSourceOnly)' != 'true'" />
513514
</ItemGroup>
514515

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/ContractRegistry.cs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,80 +14,82 @@ public abstract class ContractRegistry
1414
/// <summary>
1515
/// Gets an instance of the Exception contract for the target.
1616
/// </summary>
17-
public abstract IException Exception { get; }
17+
public virtual IException Exception => GetContract<IException>();
1818
/// <summary>
1919
/// Gets an instance of the Loader contract for the target.
2020
/// </summary>
21-
public abstract ILoader Loader { get; }
21+
public virtual ILoader Loader => GetContract<ILoader>();
2222
/// <summary>
2323
/// Gets an instance of the EcmaMetadata contract for the target.
2424
/// </summary>
25-
public abstract IEcmaMetadata EcmaMetadata { get; }
25+
public virtual IEcmaMetadata EcmaMetadata => GetContract<IEcmaMetadata>();
2626
/// <summary>
2727
/// Gets an instance of the Object contract for the target.
2828
/// </summary>
29-
public abstract IObject Object { get; }
29+
public virtual IObject Object => GetContract<IObject>();
3030
/// <summary>
3131
/// Gets an instance of the Thread contract for the target.
3232
/// </summary>
33-
public abstract IThread Thread { get; }
33+
public virtual IThread Thread => GetContract<IThread>();
3434
/// <summary>
3535
/// Gets an instance of the RuntimeTypeSystem contract for the target.
3636
/// </summary>
37-
public abstract IRuntimeTypeSystem RuntimeTypeSystem { get; }
37+
public virtual IRuntimeTypeSystem RuntimeTypeSystem => GetContract<IRuntimeTypeSystem>();
3838
/// <summary>
3939
/// Gets an instance of the DacStreams contract for the target.
4040
/// </summary>
41-
public abstract IDacStreams DacStreams { get; }
41+
public virtual IDacStreams DacStreams => GetContract<IDacStreams>();
4242
/// <summary>
4343
/// Gets an instance of the ExecutionManager contract for the target.
4444
/// </summary>
45-
public abstract IExecutionManager ExecutionManager { get; }
45+
public virtual IExecutionManager ExecutionManager => GetContract<IExecutionManager>();
4646
/// <summary>
4747
/// Gets an instance of the CodeVersions contract for the target.
4848
/// </summary>
49-
public abstract ICodeVersions CodeVersions { get; }
49+
public virtual ICodeVersions CodeVersions => GetContract<ICodeVersions>();
5050
/// <summary>
5151
/// Gets an instance of the PlatformMetadata contract for the target.
5252
/// </summary>
53-
public abstract IPlatformMetadata PlatformMetadata { get; }
53+
public virtual IPlatformMetadata PlatformMetadata => GetContract<IPlatformMetadata>();
5454
/// <summary>
5555
/// Gets an instance of the PrecodeStubs contract for the target.
5656
/// </summary>
57-
public abstract IPrecodeStubs PrecodeStubs { get; }
57+
public virtual IPrecodeStubs PrecodeStubs => GetContract<IPrecodeStubs>();
5858
/// <summary>
5959
/// Gets an instance of the ReJIT contract for the target.
6060
/// </summary>
61-
public abstract IReJIT ReJIT { get; }
61+
public virtual IReJIT ReJIT => GetContract<IReJIT>();
6262
/// <summary>
6363
/// Gets an instance of the StackWalk contract for the target.
6464
/// </summary>
65-
public abstract IStackWalk StackWalk { get; }
65+
public virtual IStackWalk StackWalk => GetContract<IStackWalk>();
6666
/// <summary>
6767
/// Gets an instance of the RuntimeInfo contract for the target.
6868
/// </summary>
69-
public abstract IRuntimeInfo RuntimeInfo { get; }
69+
public virtual IRuntimeInfo RuntimeInfo => GetContract<IRuntimeInfo>();
7070
/// <summary>
7171
/// Gets an instance of the ComWrappers contract for the target.
7272
/// </summary>
73-
public abstract IComWrappers ComWrappers { get; }
73+
public virtual IComWrappers ComWrappers => GetContract<IComWrappers>();
7474
/// Gets an instance of the DebugInfo contract for the target.
7575
/// </summary>
76-
public abstract IDebugInfo DebugInfo { get; }
76+
public virtual IDebugInfo DebugInfo => GetContract<IDebugInfo>();
7777
/// <summary>
7878
/// Gets an instance of the SHash contract for the target.
7979
/// </summary>
80-
public abstract ISHash SHash { get; }
80+
public virtual ISHash SHash => GetContract<ISHash>();
8181
/// <summary>
8282
/// Gets an instance of the GC contract for the target.
8383
/// </summary>
84-
public abstract IGC GC { get; }
84+
public virtual IGC GC => GetContract<IGC>();
8585
/// <summary>
8686
/// Gets an instance of the Notifications contract for the target.
8787
/// </summary>
88-
public abstract INotifications Notifications { get; }
88+
public virtual INotifications Notifications => GetContract<INotifications>();
8989
/// <summary>
9090
/// Gets an instance of the SignatureDecoder contract for the target.
9191
/// </summary>
92-
public abstract ISignatureDecoder SignatureDecoder { get; }
92+
public virtual ISignatureDecoder SignatureDecoder => GetContract<ISignatureDecoder>();
93+
94+
public abstract TContract GetContract<TContract>() where TContract : IContract;
9395
}

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/IContractFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ namespace Microsoft.Diagnostics.DataContractReader;
88
public interface IContractFactory<out TContract> where TContract : Contracts.IContract
99
{
1010
TContract CreateContract(Target target, int version);
11+
Type ContractType => typeof(TContract);
1112
}

src/native/managed/cdac/mscordaccore_universal/Legacy/ClrDataAddress.cs renamed to src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataAddress.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.Diagnostics.DataContractReader.Legacy;
1212
/// When marshalled to native code, this type is represented as a 64-bit unsigned integer.
1313
/// </summary>
1414
[NativeMarshalling(typeof(ClrDataAddressMarshaller))]
15-
internal struct ClrDataAddress : IEquatable<ClrDataAddress>
15+
public struct ClrDataAddress : IEquatable<ClrDataAddress>
1616
{
1717
public ulong Value;
1818

@@ -29,7 +29,7 @@ internal struct ClrDataAddress : IEquatable<ClrDataAddress>
2929
}
3030

3131
[CustomMarshaller(typeof(ClrDataAddress), MarshalMode.Default, typeof(ClrDataAddressMarshaller))]
32-
internal static class ClrDataAddressMarshaller
32+
public static class ClrDataAddressMarshaller
3333
{
3434
public static ClrDataAddress ConvertToManaged(ulong address) => new ClrDataAddress(address);
3535
public static ulong ConvertToUnmanaged(ClrDataAddress address) => address.Value;

src/native/managed/cdac/mscordaccore_universal/Legacy/ClrDataFrame.cs renamed to src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataFrame.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Microsoft.Diagnostics.DataContractReader.Legacy;
1313

1414
[GeneratedComClass]
15-
internal sealed unsafe partial class ClrDataFrame : IXCLRDataFrame, IXCLRDataFrame2
15+
public sealed unsafe partial class ClrDataFrame : IXCLRDataFrame, IXCLRDataFrame2
1616
{
1717
private readonly Target _target;
1818
private readonly IXCLRDataFrame? _legacyImpl;

src/native/managed/cdac/mscordaccore_universal/Legacy/ClrDataMethodInstance.cs renamed to src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataMethodInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace Microsoft.Diagnostics.DataContractReader.Legacy;
1616

1717
[GeneratedComClass]
18-
internal sealed unsafe partial class ClrDataMethodInstance : IXCLRDataMethodInstance
18+
public sealed unsafe partial class ClrDataMethodInstance : IXCLRDataMethodInstance
1919
{
2020
private readonly Target _target;
2121
private readonly MethodDescHandle _methodDesc;

src/native/managed/cdac/mscordaccore_universal/Legacy/ClrDataModule.cs renamed to src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
@@ -11,7 +11,7 @@
1111
namespace Microsoft.Diagnostics.DataContractReader.Legacy;
1212

1313
[GeneratedComClass]
14-
internal sealed unsafe partial class ClrDataModule : ICustomQueryInterface, IXCLRDataModule, IXCLRDataModule2
14+
public sealed unsafe partial class ClrDataModule : ICustomQueryInterface, IXCLRDataModule, IXCLRDataModule2
1515
{
1616
private readonly TargetPointer _address;
1717
private readonly Target _target;

src/native/managed/cdac/mscordaccore_universal/Legacy/ClrDataStackWalk.cs renamed to src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataStackWalk.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
@@ -12,7 +12,7 @@
1212
namespace Microsoft.Diagnostics.DataContractReader.Legacy;
1313

1414
[GeneratedComClass]
15-
internal sealed unsafe partial class ClrDataStackWalk : IXCLRDataStackWalk
15+
public sealed unsafe partial class ClrDataStackWalk : IXCLRDataStackWalk
1616
{
1717
private readonly TargetPointer _threadAddr;
1818
private readonly uint _flags;

src/native/managed/cdac/mscordaccore_universal/Legacy/ClrDataTask.cs renamed to src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ClrDataTask.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
55
using System.Runtime.InteropServices.Marshalling;
6+
using Microsoft.Diagnostics.DataContractReader.Contracts;
67

78
namespace Microsoft.Diagnostics.DataContractReader.Legacy;
89

910
[GeneratedComClass]
10-
internal sealed unsafe partial class ClrDataTask : IXCLRDataTask
11+
public sealed unsafe partial class ClrDataTask : IXCLRDataTask
1112
{
1213
private readonly TargetPointer _address;
1314
private readonly Target _target;

src/native/managed/cdac/mscordaccore_universal/Legacy/ConversionExtensions.cs renamed to src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ConversionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Microsoft.Diagnostics.DataContractReader.Legacy;
99

10-
internal static class ConversionExtensions
10+
public static class ConversionExtensions
1111
{
1212
private const uint Arm32ThumbBit = 1;
1313

@@ -86,7 +86,7 @@ public static TargetCodePointer ToTargetCodePointer(this ClrDataAddress address,
8686
/// <summary>
8787
/// Converts a TargetCodePointer to an address TargetPointer, removing any platform-specific bits such as the ARM32 Thumb bit or ARM64 pointer authentication.
8888
/// </summary>
89-
internal static TargetPointer ToAddress(this TargetCodePointer code, Target target)
89+
public static TargetPointer ToAddress(this TargetCodePointer code, Target target)
9090
{
9191
IPlatformMetadata metadata = target.Contracts.PlatformMetadata;
9292
CodePointerFlags flags = metadata.GetCodePointerFlags();

0 commit comments

Comments
 (0)