From a61590967fdf0035236af2ab8eb38d8cfd491d34 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Wed, 27 Sep 2017 07:50:01 -0400 Subject: [PATCH] [linker] Use correct namespace for async debugging helpers. Fixes #59015 (#2782) Replace https://github.com/xamarin/xamarin-macios/pull/2704 It's almost identical but it adds unit tests so this does not regress. The issue was already reported in [1] but the fix [2] was incorrect and that was also missed when the bug was verified by QA [3]. [1] https://bugzilla.xamarin.com/show_bug.cgi?id=55037 [2] https://github.com/xamarin/xamarin-macios/pull/2004 [3] https://bugzilla.xamarin.com/show_bug.cgi?id=55037#c10 --- tests/linker-ios/link all/LinkAllTest.cs | 31 ++++++++++++++++++++++++ tools/linker/MobileMarkStep.cs | 28 ++++++++++++--------- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/tests/linker-ios/link all/LinkAllTest.cs b/tests/linker-ios/link all/LinkAllTest.cs index b5fd67d0550e..83a6909752c2 100644 --- a/tests/linker-ios/link all/LinkAllTest.cs +++ b/tests/linker-ios/link all/LinkAllTest.cs @@ -15,6 +15,8 @@ using System.Net; using System.Net.Security; using System.Reflection; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; using System.Security.Cryptography.X509Certificates; using MonoTouch; @@ -542,5 +544,34 @@ public void WebKit_NSProxy () var fqn = typeof (NSObject).AssemblyQualifiedName.Replace ("Foundation.NSObject", "Foundation.NSProxy"); Assert.Null (Type.GetType (fqn), fqn); } + + [Test] + public void Bug59015 () + { + CheckAsyncTaskMethodBuilder (typeof (AsyncTaskMethodBuilder)); + CheckAsyncTaskMethodBuilder (typeof (AsyncTaskMethodBuilder)); + var t = typeof (Task); + var snfwc = t.GetMethod ("SetNotificationForWaitCompletion", BindingFlags.Instance | BindingFlags.NonPublic); +#if DEBUG + Assert.NotNull (snfwc, "Task.NotifyDebuggerOfWaitCompletion"); +#else + // something keeps it from being removed + // Assert.Null (snfwc, "Task.NotifyDebuggerOfWaitCompletion"); +#endif + } + + void CheckAsyncTaskMethodBuilder (Type atmb) + { + Assert.NotNull (atmb, "AsyncTaskMethodBuilder"); + var snfwc = atmb.GetMethod ("SetNotificationForWaitCompletion", BindingFlags.Instance | BindingFlags.NonPublic); + var oifd = atmb.GetProperty ("ObjectIdForDebugger", BindingFlags.Instance | BindingFlags.NonPublic); +#if DEBUG + Assert.NotNull (snfwc, atmb.FullName + ".SetNotificationForWaitCompletion"); + Assert.NotNull (oifd, atmb.FullName + ".ObjectIdForDebugger"); +#else + Assert.Null (snfwc, atmb.FullName + ".SetNotificationForWaitCompletion"); + Assert.Null (oifd, atmb.FullName + ".ObjectIdForDebugger"); +#endif + } } } diff --git a/tools/linker/MobileMarkStep.cs b/tools/linker/MobileMarkStep.cs index 1f3a51e57713..5b2107ba715f 100644 --- a/tools/linker/MobileMarkStep.cs +++ b/tools/linker/MobileMarkStep.cs @@ -259,19 +259,25 @@ void MarkMetadata (IMetadataTokenProvider tp) void ProcessCorlib (TypeDefinition type) { switch (type.Namespace) { - case "System.Runtime.CompilerServices.AsyncTaskMethodBuilder": - if (DebugBuild) - MarkNamedMethod (type, "SetNotificationForWaitCompletion"); - break; - case "System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1": - if (DebugBuild) - MarkNamedMethod (type, "SetNotificationForWaitCompletion"); + case "System.Runtime.CompilerServices": + switch (type.Name) { + case "AsyncTaskMethodBuilder": + case "AsyncTaskMethodBuilder`1": + if (DebugBuild) { + MarkNamedMethod (type, "SetNotificationForWaitCompletion"); + MarkNamedMethod (type, "get_ObjectIdForDebugger"); + } + break; + } break; - case "System.Threading.Tasks.Task": - if (DebugBuild) - MarkNamedMethod (type, "NotifyDebuggerOfWaitCompletion"); + case "System.Threading.Tasks": + switch (type.Name) { + case "Task": + if (DebugBuild) + MarkNamedMethod (type, "NotifyDebuggerOfWaitCompletion"); + break; + } break; - case "System.Security.Cryptography": switch (type.Name) { case "Aes":