Skip to content

Commit e3bb85d

Browse files
committed
[cDAC] Multi-target managed reader to net8.0/net9.0/net10.0
Changes TargetFramework -> TargetFrameworks on the cDAC managed reader projects so the shipped NuGet packages can be consumed by diagnostic tools running on older shipped runtimes (net8.0, net9.0, net10.0) in addition to $(NetCoreAppToolCurrent): Microsoft.Diagnostics.DataContractReader[.Abstractions|.Contracts|.Legacy] Microsoft.Diagnostics.DataContractReader.TestInfrastructure Microsoft.Diagnostics.DataContractReader.Tests Source-level downlevel compatibility fixes: - Directory.Build.props: gate ExperimentalAttribute injection to net9+ (the attribute type does not exist on net8). - X86Unwinder.cs: replace `ReadOnlySpan.Reverse()` LINQ usage with a manual reverse loop (LINQ Reverse on ReadOnlySpan is net9+). - ClrDataModule.cs + MetaDataImportImplTests.cs: use `Marshal.QueryInterface(..., ref Guid, ...)` and suppress CS9191; the `in Guid` overload is net9+. - DumpInfo.cs: gate `Architecture.RiscV64` / `LoongArch64` to net9+ (enum members added in net9). - LayoutSetSource.cs / Emitter.cs: drop `params ReadOnlySpan<T>` and emit collection-expression call sites; `params ROS` requires C# 13 / net9. - SOSDacImpl.cs / ISOSDacInterface.cs: rename `vtable` parameter to `vtableAddr` to avoid downlevel codegen ambiguity. - Tests.csproj: split mscordaccore_universal vs Legacy ProjectReference by TFM (universal is NAOT-published only at NetCoreAppToolCurrent).
1 parent 9dd152c commit e3bb85d

15 files changed

Lines changed: 56 additions & 25 deletions

File tree

src/native/managed/cdac/Directory.Build.props

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33

44
<PropertyGroup>
55
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
6-
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
7-
<AppendTargetFrameworkToOutputPath Condition="'$(BuildingInsideVisualStudio)' == 'true'">true</AppendTargetFrameworkToOutputPath>
6+
<!--
7+
Default TFMs for the cDAC managed reader transport packages. These ship via
8+
NuGet and must be consumable by diagnostic tools running on shipped runtimes
9+
in addition to $(NetCoreAppToolCurrent). Projects that should not multi-target
10+
(e.g. mscordaccore_universal, test harnesses) override this with TargetFramework.
11+
-->
12+
<CdacPackageTargetFrameworks>$(NetCoreAppToolCurrent);net10.0;net9.0;net8.0</CdacPackageTargetFrameworks>
813
</PropertyGroup>
914

10-
<ItemGroup>
15+
<!--
16+
ExperimentalAttribute is a .NET 9+ API. When multi-targeting downward
17+
(e.g. net8.0 for consumption by tools that target NetCoreAppMinTargetFramework),
18+
skip the injection on TFMs where the attribute type does not exist.
19+
-->
20+
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">
1121
<AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExperimentalAttribute">
1222
<_Parameter1>NETCDAC0001</_Parameter1>
1323
</AssemblyAttribute>

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Microsoft.Diagnostics.DataContractReader.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
4+
<TargetFrameworks>$(CdacPackageTargetFrameworks)</TargetFrameworks>
55
<RootNamespace>Microsoft.Diagnostics.DataContractReader</RootNamespace>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/X86/X86Unwinder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Diagnostics;
6-
using System.Linq;
76
using Microsoft.Diagnostics.DataContractReader.Contracts.Extensions;
87
using static Microsoft.Diagnostics.DataContractReader.Contracts.StackWalkHelpers.X86Context;
98

@@ -487,8 +486,9 @@ private bool UnwindEbpDoubleAlignFrame(
487486
if (gcInfo.Header.DoubleAlign && (curEbp & 0x04) != 0)
488487
pSavedRegs -= _pointerSize;
489488

490-
foreach (RegMask regMask in registerOrder.Reverse())
489+
for (int i = registerOrder.Length - 1; i >= 0; i--)
491490
{
491+
RegMask regMask = registerOrder[i];
492492
if (regMask == RegMask.EBP) continue;
493493

494494
if (!gcInfo.SavedRegsMask.HasFlag(regMask)) continue;
@@ -570,8 +570,9 @@ we need to know our exact location to determine the callee-saved registers */
570570
/* Increment "offset" in steps to see which callee-saved
571571
registers have been pushed already */
572572

573-
foreach (RegMask regMask in registerOrder.Reverse())
573+
for (int i = registerOrder.Length - 1; i >= 0; i--)
574574
{
575+
RegMask regMask = registerOrder[i];
575576
if (regMask == RegMask.EBP) continue;
576577

577578
if (!gcInfo.SavedRegsMask.HasFlag(regMask)) continue;

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
4+
<TargetFrameworks>$(CdacPackageTargetFrameworks)</TargetFrameworks>
55
<RootNamespace>Microsoft.Diagnostics.DataContractReader</RootNamespace>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ CustomQueryInterfaceResult ICustomQueryInterface.GetInterface(ref Guid iid, out
9191
try
9292
{
9393
Guid iidMetaDataImport = typeof(IMetaDataImport).GUID;
94-
if (_legacyModulePointer != 0 && Marshal.QueryInterface(_legacyModulePointer, iidMetaDataImport, out nint ppMdi) >= 0)
94+
#pragma warning disable CS9191 // 'ref' is equivalent to 'in' for net9+; net8 requires 'ref'
95+
if (_legacyModulePointer != 0 && Marshal.QueryInterface(_legacyModulePointer, ref iidMetaDataImport, out nint ppMdi) >= 0)
96+
#pragma warning restore CS9191
9597
{
9698
legacyImport = ComInterfaceMarshaller<IMetaDataImport>.ConvertToManaged((void*)ppMdi);
9799
Marshal.Release(ppMdi);

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ISOSDacInterface.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ public unsafe partial interface ISOSDacInterface
758758

759759
// Frames
760760
[PreserveSig]
761-
int GetFrameName(ClrDataAddress vtable, uint count, char* frameName, uint* pNeeded);
761+
int GetFrameName(ClrDataAddress vtableAddr, uint count, char* frameName, uint* pNeeded);
762762

763763
// PEFiles
764764
[PreserveSig]

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Microsoft.Diagnostics.DataContractReader.Legacy.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
4+
<TargetFrameworks>$(CdacPackageTargetFrameworks)</TargetFrameworks>
55
<RootNamespace>Microsoft.Diagnostics.DataContractReader.Legacy</RootNamespace>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,15 +1199,15 @@ int ISOSDacInterface.GetFieldDescData(ClrDataAddress fieldDesc, DacpFieldDescDat
11991199
return hr;
12001200
}
12011201

1202-
int ISOSDacInterface.GetFrameName(ClrDataAddress vtable, uint count, char* frameName, uint* pNeeded)
1202+
int ISOSDacInterface.GetFrameName(ClrDataAddress vtableAddr, uint count, char* frameName, uint* pNeeded)
12031203
{
12041204
int hr = HResults.S_OK;
12051205
try
12061206
{
1207-
if (vtable == 0)
1207+
if (vtableAddr == 0)
12081208
throw new ArgumentException();
12091209
IStackWalk stackWalk = _target.Contracts.StackWalk;
1210-
string name = stackWalk.GetFrameName(new(vtable));
1210+
string name = stackWalk.GetFrameName(new(vtableAddr));
12111211

12121212
if (string.IsNullOrEmpty(name))
12131213
throw new ArgumentException();
@@ -1234,7 +1234,7 @@ int ISOSDacInterface.GetFrameName(ClrDataAddress vtable, uint count, char* frame
12341234
int hrLocal;
12351235
fixed (char* ptr = nameLocal)
12361236
{
1237-
hrLocal = _legacyImpl.GetFrameName(vtable, count, ptr, &neededLocal);
1237+
hrLocal = _legacyImpl.GetFrameName(vtableAddr, count, ptr, &neededLocal);
12381238
}
12391239
Debug.ValidateHResult(hr, hrLocal);
12401240
if (hr == HResults.S_OK)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/Microsoft.Diagnostics.DataContractReader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
4+
<TargetFrameworks>$(CdacPackageTargetFrameworks)</TargetFrameworks>
55
<RootNamespace>Microsoft.Diagnostics.DataContractReader</RootNamespace>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

src/native/managed/cdac/gen/Emitter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private static string ReadExpression(MemberModel member, string baseVar, string
262262
};
263263

264264
private static string NameArgs(MemberModel member)
265-
=> string.Join(", ", Enumerate(member.Names).Select(n => $"\"{n}\""));
265+
=> "[" + string.Join(", ", Enumerate(member.Names).Select(n => $"\"{n}\"")) + "]";
266266

267267
private static IEnumerable<string> Enumerate(EquatableArray<string> array)
268268
{

0 commit comments

Comments
 (0)