From 0d519960b767adaea9e6e05b78bcfdfc2d656edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=C5=84ski?= Date: Sun, 17 Sep 2023 13:38:48 +0100 Subject: [PATCH 1/4] Fix trimming of DebuggerDisplay with Name The `Name` property of the `DebuggerDisplay` attribute accepts the same format string as its `Value` property, but does not prevent trimming members it references. Thanks to this fix, members referenced by any of these two properties are not trimmed and can be displayed by a debugger. Additionally, this change adds references of three projects to the illink solution file to fix its build errors. --- src/tools/illink/illink.sln | 46 ++++++++ .../src/linker/Linker.Steps/MarkStep.cs | 109 ++++++++++-------- .../DebuggerDisplayAttributeOnType.cs | 11 +- .../DebuggerDisplayAttributeOnType.cs | 14 ++- 4 files changed, 129 insertions(+), 51 deletions(-) diff --git a/src/tools/illink/illink.sln b/src/tools/illink/illink.sln index 87e99d208c7fb..238a6b12a4c05 100644 --- a/src/tools/illink/illink.sln +++ b/src/tools/illink/illink.sln @@ -37,6 +37,12 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ILLink.Shared", "src\ILLink EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILLink.RoslynAnalyzer.Tests.Generator", "test\ILLink.RoslynAnalyzer.Tests.Generator\ILLink.RoslynAnalyzer.Tests.Generator.csproj", "{3DDE7064-4B68-4979-8843-FDF4CE5A5140}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicDataFlow", "test\Mono.Linker.Tests.Cases\TopLevelStatements\BasicDataFlow\BasicDataFlow.csproj", "{7E243617-E35D-47AB-981A-9FCD96E1AC52}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicKeptValidation", "test\Mono.Linker.Tests.Cases\TopLevelStatements\BasicKeptValidation\BasicKeptValidation.csproj", "{17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILVerification", "..\..\coreclr\tools\ILVerification\ILVerification.csproj", "{92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -203,6 +209,42 @@ Global {3DDE7064-4B68-4979-8843-FDF4CE5A5140}.Release|x64.Build.0 = Release|Any CPU {3DDE7064-4B68-4979-8843-FDF4CE5A5140}.Release|x86.ActiveCfg = Release|Any CPU {3DDE7064-4B68-4979-8843-FDF4CE5A5140}.Release|x86.Build.0 = Release|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|x64.ActiveCfg = Debug|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|x64.Build.0 = Debug|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|x86.ActiveCfg = Debug|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|x86.Build.0 = Debug|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|Any CPU.Build.0 = Release|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|x64.ActiveCfg = Release|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|x64.Build.0 = Release|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|x86.ActiveCfg = Release|Any CPU + {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|x86.Build.0 = Release|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|x64.ActiveCfg = Debug|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|x64.Build.0 = Debug|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|x86.ActiveCfg = Debug|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|x86.Build.0 = Debug|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|Any CPU.Build.0 = Release|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|x64.ActiveCfg = Release|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|x64.Build.0 = Release|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|x86.ActiveCfg = Release|Any CPU + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|x86.Build.0 = Release|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|x64.ActiveCfg = Debug|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|x64.Build.0 = Debug|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|x86.ActiveCfg = Debug|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|x86.Build.0 = Debug|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|Any CPU.Build.0 = Release|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|x64.ActiveCfg = Release|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|x64.Build.0 = Release|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|x86.ActiveCfg = Release|Any CPU + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -218,11 +260,15 @@ Global {8DA71B3B-5809-44E5-A018-5DE5C6FF6C2A} = {03EB085F-3E2E-4A68-A7DF-951ADF59A0CC} {6D20F334-B7E4-4585-854B-8A0E2B29B4AA} = {AA0569FB-73E9-4B42-9A19-714BB1229DAE} {3DDE7064-4B68-4979-8843-FDF4CE5A5140} = {C2969923-7BAA-4FE4-853C-F670B0D3C6C8} + {7E243617-E35D-47AB-981A-9FCD96E1AC52} = {C2969923-7BAA-4FE4-853C-F670B0D3C6C8} + {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87} = {C2969923-7BAA-4FE4-853C-F670B0D3C6C8} + {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2} = {C2969923-7BAA-4FE4-853C-F670B0D3C6C8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E43A3901-42B0-48CA-BB36-5CD40A99A6EE} EndGlobalSection GlobalSection(SharedMSBuildProjectFiles) = preSolution + test\Trimming.Tests.Shared\Trimming.Tests.Shared.projitems*{400a1561-b6b6-482d-9e4c-3ddaede5bd07}*SharedItemsImports = 5 src\ILLink.Shared\ILLink.Shared.projitems*{dd28e2b1-057b-4b4d-a04d-b2ebd9e76e46}*SharedItemsImports = 5 src\ILLink.Shared\ILLink.Shared.projitems*{f1a44a78-34ee-408b-8285-9a26f0e7d4f2}*SharedItemsImports = 5 src\ILLink.Shared\ILLink.Shared.projitems*{ff598e93-8e9e-4091-9f50-61a7572663ae}*SharedItemsImports = 13 diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs index 94fb8d5a7ec08..278edba270e6e 100644 --- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs +++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs @@ -2270,65 +2270,76 @@ void MarkTypeWithDebuggerDisplayAttribute (TypeDefinition type, CustomAttribute // Record a logical dependency on the attribute so that we can blame it for the kept members below. Tracer.AddDirectDependency (attribute, new DependencyInfo (DependencyKind.CustomAttribute, type), marked: false); - string displayString = (string) attribute.ConstructorArguments[0].Value; - if (string.IsNullOrEmpty (displayString)) - return; + MarkTypeWithDebuggerDisplayAttributeValue(type, attribute, (string) attribute.ConstructorArguments[0].Value); + if (attribute.HasProperties) { + foreach(var property in attribute.Properties) { + if(property.Name == "Name") { + MarkTypeWithDebuggerDisplayAttributeValue (type, attribute, (string) property.Argument.Value); + } + } + } + } + } - foreach (Match match in DebuggerDisplayAttributeValueRegex ().Matches (displayString)) { - // Remove '{' and '}' - string realMatch = match.Value.Substring (1, match.Value.Length - 2); + void MarkTypeWithDebuggerDisplayAttributeValue (TypeDefinition type, CustomAttribute attribute, string? displayString) + { + if (string.IsNullOrEmpty (displayString)) + return; - // Remove ",nq" suffix if present - // (it asks the expression evaluator to remove the quotes when displaying the final value) - if (ContainsNqSuffixRegex ().IsMatch (realMatch)) { - realMatch = realMatch.Substring (0, realMatch.LastIndexOf (',')); - } + foreach (Match match in DebuggerDisplayAttributeValueRegex ().Matches (displayString)) { + // Remove '{' and '}' + string realMatch = match.Value.Substring (1, match.Value.Length - 2); - if (realMatch.EndsWith ("()")) { - string methodName = realMatch.Substring (0, realMatch.Length - 2); + // Remove ",nq" suffix if present + // (it asks the expression evaluator to remove the quotes when displaying the final value) + if (ContainsNqSuffixRegex ().IsMatch (realMatch)) { + realMatch = realMatch.Substring (0, realMatch.LastIndexOf (',')); + } - // It's a call to a method on some member. Handling this scenario robustly would be complicated and a decent bit of work. - // - // We could implement support for this at some point, but for now it's important to make sure at least we don't crash trying to find some - // method on the current type when it exists on some other type - if (methodName.Contains ('.')) - continue; + if (realMatch.EndsWith ("()")) { + string methodName = realMatch.Substring (0, realMatch.Length - 2); - MethodDefinition? method = GetMethodWithNoParameters (type, methodName); - if (method != null) { - MarkMethod (method, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute), ScopeStack.CurrentScope.Origin); - continue; - } - } else { - FieldDefinition? field = GetField (type, realMatch); - if (field != null) { - MarkField (field, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute), ScopeStack.CurrentScope.Origin); - continue; - } + // It's a call to a method on some member. Handling this scenario robustly would be complicated and a decent bit of work. + // + // We could implement support for this at some point, but for now it's important to make sure at least we don't crash trying to find some + // method on the current type when it exists on some other type + if (methodName.Contains ('.')) + continue; - PropertyDefinition? property = GetProperty (type, realMatch); - if (property != null) { - if (property.GetMethod != null) { - MarkMethod (property.GetMethod, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute), ScopeStack.CurrentScope.Origin); - } - if (property.SetMethod != null) { - MarkMethod (property.SetMethod, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute), ScopeStack.CurrentScope.Origin); - } - continue; - } + MethodDefinition? method = GetMethodWithNoParameters (type, methodName); + if (method != null) { + MarkMethod (method, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute), ScopeStack.CurrentScope.Origin); + continue; + } + } else { + FieldDefinition? field = GetField (type, realMatch); + if (field != null) { + MarkField (field, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute), ScopeStack.CurrentScope.Origin); + continue; } - while (true) { - // Currently if we don't understand the DebuggerDisplayAttribute we mark everything on the type - // This can be improved: dotnet/linker/issues/1873 - MarkMethods (type, new DependencyInfo (DependencyKind.KeptForSpecialAttribute, attribute)); - MarkFields (type, includeStatic: true, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute)); - if (Context.TryResolve (type.BaseType) is not TypeDefinition baseType) - break; - type = baseType; + PropertyDefinition? property = GetProperty (type, realMatch); + if (property != null) { + if (property.GetMethod != null) { + MarkMethod (property.GetMethod, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute), ScopeStack.CurrentScope.Origin); + } + if (property.SetMethod != null) { + MarkMethod (property.SetMethod, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute), ScopeStack.CurrentScope.Origin); + } + continue; } - return; } + + while (true) { + // Currently if we don't understand the DebuggerDisplayAttribute we mark everything on the type + // This can be improved: dotnet/linker/issues/1873 + MarkMethods (type, new DependencyInfo (DependencyKind.KeptForSpecialAttribute, attribute)); + MarkFields (type, includeStatic: true, new DependencyInfo (DependencyKind.ReferencedBySpecialAttribute, attribute)); + if (Context.TryResolve (type.BaseType) is not TypeDefinition baseType) + break; + type = baseType; + } + return; } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs index 2671331751e6e..b3a1b93289357 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs @@ -12,6 +12,7 @@ public static void Main () var foo = new Foo (); var bar = new Bar (); var baz = new Baz (); + var fooBaz = new FooBaz (); } [Kept] @@ -39,5 +40,13 @@ public int Method () class Baz { } + + [Kept] + [KeptMember (".ctor()")] + [DebuggerDisplay ("_", Name="{Property}")] + class FooBaz + { + public int Property { get; set; } + } } -} \ No newline at end of file +} diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs index 767a76cae9e9d..90ab7e07533fb 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs @@ -13,6 +13,7 @@ public static void Main () { var foo = new Foo (); var bar = new Bar (); + var fooBaz = new FooBaz (); } [Kept] @@ -38,5 +39,16 @@ public int Method () return 1; } } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] + [DebuggerDisplay ("_", Name="{Property}")] + class FooBaz + { + [Kept] + [KeptBackingField] + public int Property { [Kept] get; [Kept] set; } + } } -} \ No newline at end of file +} From 368e82fa8e73623d49e5d9b43a6c2fe0cbef07e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=C5=84ski?= Date: Mon, 18 Sep 2023 19:12:37 +0100 Subject: [PATCH 2/4] Fix minor style issues --- src/tools/illink/src/linker/Linker.Steps/MarkStep.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs index 278edba270e6e..219666d16ade9 100644 --- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs +++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs @@ -2265,15 +2265,14 @@ void MarkXmlSchemaProvider (TypeDefinition type, CustomAttribute attribute) void MarkTypeWithDebuggerDisplayAttribute (TypeDefinition type, CustomAttribute attribute) { if (Context.KeepMembersForDebugger) { - // Members referenced by the DebuggerDisplayAttribute are kept even if the attribute may not be. // Record a logical dependency on the attribute so that we can blame it for the kept members below. Tracer.AddDirectDependency (attribute, new DependencyInfo (DependencyKind.CustomAttribute, type), marked: false); MarkTypeWithDebuggerDisplayAttributeValue(type, attribute, (string) attribute.ConstructorArguments[0].Value); if (attribute.HasProperties) { - foreach(var property in attribute.Properties) { - if(property.Name == "Name") { + foreach (var property in attribute.Properties) { + if (property.Name == "Name") { MarkTypeWithDebuggerDisplayAttributeValue (type, attribute, (string) property.Argument.Value); } } From b3e7460e0342d4e8b6d18e9198eefa55694bb68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=C5=84ski?= Date: Wed, 20 Sep 2023 08:14:34 +0100 Subject: [PATCH 3/4] Fix trimming of DebugDisplay wiith Type Also undo changes to the solution file so they can be fixed independently. --- src/tools/illink/illink.sln | 45 ------------------- .../src/linker/Linker.Steps/MarkStep.cs | 2 +- .../DebuggerDisplayAttributeOnType.cs | 9 ++++ .../DebuggerDisplayAttributeOnType.cs | 12 +++++ 4 files changed, 22 insertions(+), 46 deletions(-) diff --git a/src/tools/illink/illink.sln b/src/tools/illink/illink.sln index 238a6b12a4c05..9b8d904942baa 100644 --- a/src/tools/illink/illink.sln +++ b/src/tools/illink/illink.sln @@ -37,12 +37,6 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ILLink.Shared", "src\ILLink EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILLink.RoslynAnalyzer.Tests.Generator", "test\ILLink.RoslynAnalyzer.Tests.Generator\ILLink.RoslynAnalyzer.Tests.Generator.csproj", "{3DDE7064-4B68-4979-8843-FDF4CE5A5140}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicDataFlow", "test\Mono.Linker.Tests.Cases\TopLevelStatements\BasicDataFlow\BasicDataFlow.csproj", "{7E243617-E35D-47AB-981A-9FCD96E1AC52}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicKeptValidation", "test\Mono.Linker.Tests.Cases\TopLevelStatements\BasicKeptValidation\BasicKeptValidation.csproj", "{17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILVerification", "..\..\coreclr\tools\ILVerification\ILVerification.csproj", "{92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -209,42 +203,6 @@ Global {3DDE7064-4B68-4979-8843-FDF4CE5A5140}.Release|x64.Build.0 = Release|Any CPU {3DDE7064-4B68-4979-8843-FDF4CE5A5140}.Release|x86.ActiveCfg = Release|Any CPU {3DDE7064-4B68-4979-8843-FDF4CE5A5140}.Release|x86.Build.0 = Release|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|x64.ActiveCfg = Debug|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|x64.Build.0 = Debug|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|x86.ActiveCfg = Debug|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Debug|x86.Build.0 = Debug|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|Any CPU.Build.0 = Release|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|x64.ActiveCfg = Release|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|x64.Build.0 = Release|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|x86.ActiveCfg = Release|Any CPU - {7E243617-E35D-47AB-981A-9FCD96E1AC52}.Release|x86.Build.0 = Release|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|Any CPU.Build.0 = Debug|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|x64.ActiveCfg = Debug|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|x64.Build.0 = Debug|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|x86.ActiveCfg = Debug|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Debug|x86.Build.0 = Debug|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|Any CPU.ActiveCfg = Release|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|Any CPU.Build.0 = Release|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|x64.ActiveCfg = Release|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|x64.Build.0 = Release|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|x86.ActiveCfg = Release|Any CPU - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87}.Release|x86.Build.0 = Release|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|x64.ActiveCfg = Debug|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|x64.Build.0 = Debug|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|x86.ActiveCfg = Debug|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Debug|x86.Build.0 = Debug|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|Any CPU.Build.0 = Release|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|x64.ActiveCfg = Release|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|x64.Build.0 = Release|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|x86.ActiveCfg = Release|Any CPU - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -260,9 +218,6 @@ Global {8DA71B3B-5809-44E5-A018-5DE5C6FF6C2A} = {03EB085F-3E2E-4A68-A7DF-951ADF59A0CC} {6D20F334-B7E4-4585-854B-8A0E2B29B4AA} = {AA0569FB-73E9-4B42-9A19-714BB1229DAE} {3DDE7064-4B68-4979-8843-FDF4CE5A5140} = {C2969923-7BAA-4FE4-853C-F670B0D3C6C8} - {7E243617-E35D-47AB-981A-9FCD96E1AC52} = {C2969923-7BAA-4FE4-853C-F670B0D3C6C8} - {17F0B7BF-C150-4FFE-8D40-8A2FB2C8AF87} = {C2969923-7BAA-4FE4-853C-F670B0D3C6C8} - {92DA00DE-8CFA-4AE9-B622-39BDC83CB8B2} = {C2969923-7BAA-4FE4-853C-F670B0D3C6C8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E43A3901-42B0-48CA-BB36-5CD40A99A6EE} diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs index 219666d16ade9..93bf7c16afa35 100644 --- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs +++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs @@ -2272,7 +2272,7 @@ void MarkTypeWithDebuggerDisplayAttribute (TypeDefinition type, CustomAttribute MarkTypeWithDebuggerDisplayAttributeValue(type, attribute, (string) attribute.ConstructorArguments[0].Value); if (attribute.HasProperties) { foreach (var property in attribute.Properties) { - if (property.Name == "Name") { + if (property.Name is "Name" or "Type") { MarkTypeWithDebuggerDisplayAttributeValue (type, attribute, (string) property.Argument.Value); } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs index b3a1b93289357..2015911481252 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs @@ -13,6 +13,7 @@ public static void Main () var bar = new Bar (); var baz = new Baz (); var fooBaz = new FooBaz (); + var fooBar = new FooBar (); } [Kept] @@ -48,5 +49,13 @@ class FooBaz { public int Property { get; set; } } + + [Kept] + [KeptMember (".ctor()")] + [DebuggerDisplay ("_", Type="{Property}")] + class FooBar + { + public int Property { get; set; } + } } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs index 90ab7e07533fb..de9ca2c23ce32 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs @@ -14,6 +14,7 @@ public static void Main () var foo = new Foo (); var bar = new Bar (); var fooBaz = new FooBaz (); + var fooBar = new FooBar (); } [Kept] @@ -50,5 +51,16 @@ class FooBaz [KeptBackingField] public int Property { [Kept] get; [Kept] set; } } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] + [DebuggerDisplay ("_", Type="{Property}")] + class FooBar + { + [Kept] + [KeptBackingField] + public int Property { [Kept] get; [Kept] set; } + } } } From 5cc7bf4fcb757b20f1027bf51040cba3cbff9d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Zgodzi=C5=84ski?= Date: Wed, 20 Sep 2023 08:17:34 +0100 Subject: [PATCH 4/4] Undo the remaining change to the illink.sln --- src/tools/illink/illink.sln | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tools/illink/illink.sln b/src/tools/illink/illink.sln index 9b8d904942baa..87e99d208c7fb 100644 --- a/src/tools/illink/illink.sln +++ b/src/tools/illink/illink.sln @@ -223,7 +223,6 @@ Global SolutionGuid = {E43A3901-42B0-48CA-BB36-5CD40A99A6EE} EndGlobalSection GlobalSection(SharedMSBuildProjectFiles) = preSolution - test\Trimming.Tests.Shared\Trimming.Tests.Shared.projitems*{400a1561-b6b6-482d-9e4c-3ddaede5bd07}*SharedItemsImports = 5 src\ILLink.Shared\ILLink.Shared.projitems*{dd28e2b1-057b-4b4d-a04d-b2ebd9e76e46}*SharedItemsImports = 5 src\ILLink.Shared\ILLink.Shared.projitems*{f1a44a78-34ee-408b-8285-9a26f0e7d4f2}*SharedItemsImports = 5 src\ILLink.Shared\ILLink.Shared.projitems*{ff598e93-8e9e-4091-9f50-61a7572663ae}*SharedItemsImports = 13