Skip to content

Commit

Permalink
ILLink: Keep parameter names unless DebuggerSupport is disabled (dotn…
Browse files Browse the repository at this point in the history
…et#105714)

Parameter name trimming is currently the only metadata trimming
optimization, but the check covers "all" to include any future
metadata trimming optimizations that might impact debuggers.
  • Loading branch information
sbomer committed Aug 7, 2024
1 parent 24786d2 commit 6278482
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Reflection;

/// <summary>
/// Ensures setting DebuggerSupport = false causes parameter names to be removed
/// </summary>
class Program
{
static int Main(string[] args)
{
// Ensure the method is kept
MethodWithParameter ("");

// Get parameter name via trim-incompatible reflection
var parameterName = reflectedType.GetMethod("MethodWithParameter")!.GetParameters()[0].Name;

// Parameter name should be removed
if (!string.IsNullOrEmpty(parameterName))
return -1;

return 100;
}

static Type reflectedType = typeof(Program);

public static void MethodWithParameter(string parameter) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Reflection;

/// <summary>
/// Ensures setting DebuggerSupport = true causes parameter names to be kept
/// </summary>
class Program
{
static int Main(string[] args)
{
// Ensure the method is kept
MethodWithParameter ("");

// Get parameter name via trim-incompatible reflection
var parameterName = reflectedType.GetMethod("MethodWithParameter")!.GetParameters()[0].Name;

// Parameter name should be kept
if (parameterName != "parameter")
return -1;

return 100;
}

static Type reflectedType = typeof(Program);

public static void MethodWithParameter(string parameter) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
<TestConsoleAppSourceFiles Include="AppDomainGetThreadWindowsPrincipalTest.cs">
<SkipOnTestRuntimes>osx-x64;linux-x64;browser-wasm</SkipOnTestRuntimes>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="DebuggerSupportTrue.cs">
<EnabledProperties>DebuggerSupport</EnabledProperties>
<NativeAotIncompatible>true</NativeAotIncompatible>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="DebuggerSupportFalse.cs">
<DisabledProperties>DebuggerSupport</DisabledProperties>
<NativeAotIncompatible>true</NativeAotIncompatible>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="DebuggerTypeProxyAttributeTests.cs" >
<EnabledProperties>DebuggerSupport</EnabledProperties>
</TestConsoleAppSourceFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Copyright (c) .NET Foundation. All rights reserved.
UnusedInterfaces="$(_TrimmerUnusedInterfaces)"
IPConstProp="$(_TrimmerIPConstProp)"
Sealer="$(_TrimmerSealer)"
KeepMetadata="@(_TrimmerKeepMetadata)"

Warn="$(ILLinkWarningLevel)"
NoWarn="$(NoWarn)"
Expand Down Expand Up @@ -240,6 +241,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<TrimmerRemoveSymbols Condition=" '$(DebuggerSupport)' != 'false' ">false</TrimmerRemoveSymbols>
</PropertyGroup>

<ItemGroup>
<!-- Keep parameter name and other metadata unless debugger support is disabled. -->
<_TrimmerKeepMetadata Include="all" Condition=" '$(DebuggerSupport)' != 'false' " />
</ItemGroup>

<PropertyGroup>
<_TrimmerPreserveSymbolPaths Condition=" '$(_TrimmerPreserveSymbolPaths)' == '' and '$(DeterministicSourcePaths)' == 'true' ">true</_TrimmerPreserveSymbolPaths>
<_TrimmerPreserveSymbolPaths Condition=" '$(_TrimmerPreserveSymbolPaths)' == '' ">false</_TrimmerPreserveSymbolPaths>
Expand Down

0 comments on commit 6278482

Please sign in to comment.