From 194d6d1a2a9cfce0813df002f5f368e1bc13c552 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 13 Jun 2017 13:19:49 +0100 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Fix an issue where library projects cannot be debugged. The linker was not producing ppdb files. What is supposed to happen is the linker if it changes a dll should emit a new pdb file along with it. Because none of the assemblies were being loaded with debug symbols. Hence no updated pdb. So this commit loads the Symbols as part of the linker process to ensure that we are able to emit the new pdb when required. This is only done for files which have been changed by the linker. --- .../MonoDroid.Tuner/FixAbstractMethodsStep.cs | 1 + .../Xamarin.Android.Build.Tests/BuildTest.cs | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs index b69dd41622e..61dbcd0ce05 100644 --- a/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs +++ b/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs @@ -28,6 +28,7 @@ protected override void ProcessAssembly (AssemblyDefinition assembly) } if (changed) { + Context.SafeReadSymbols (assembly); AssemblyAction action = Annotations.HasAction (assembly) ? Annotations.GetAction (assembly) : AssemblyAction.Skip; if (action == AssemblyAction.Skip || action == AssemblyAction.Copy || action == AssemblyAction.Delete) Annotations.SetAction (assembly, AssemblyAction.Save); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index cc27ca21376..f3ad560cc60 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -499,6 +499,70 @@ public void BuildBasicApplicationCheckMdbRepeatBuild () } } + [Test] + public void BuildAppCheckDebugSymbols () + { + var path = Path.Combine ("temp", TestContext.CurrentContext.Test.Name); + var lib = new XamarinAndroidLibraryProject () { + IsRelease = false, + ProjectName = "Library1", + Sources = { + new BuildItem.Source ("Class1.cs") { + TextContent = () => @"using System; +namespace Library1 { + public class Class1 : Java.Lang.Object, global::Android.Views.View.IOnClickListener { + void global::Android.Views.View.IOnClickListener.OnClick(global::Android.Views.View v) + { + } + } +} +", + }, + }, + }; + var proj = new XamarinAndroidApplicationProject () { + IsRelease = false, + ProjectName = "App1", + References = { new BuildItem ("ProjectReference", "..\\Library1\\Library1.csproj") }, + Sources = { + new BuildItem.Source ("Class2.cs") { + TextContent= () => @" +using System; +namespace App1 +{ + public class Class2 + { + Library1.Class1 c; + public Class2 () + { + } + } +}" + }, + }, + }; + proj.SetProperty (KnownProperties.AndroidLinkMode, AndroidLinkMode.None.ToString ()); + using (var libb = CreateDllBuilder (Path.Combine (path, "Library1"))) { + Assert.IsTrue (libb.Build (lib), "Library1 Build should have succeeded."); + using (var b = CreateApkBuilder (Path.Combine (path, "App1"))) { + Assert.IsTrue (b.Build (proj), "App1 Build should have succeeded."); + var assetsPdb = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets", "Library1.pdb"); + var linkDst = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linkdst", "Library1.pdb"); + var linkSrc = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linksrc", "Library1.pdb"); + Assert.IsTrue ( + File.Exists (assetsPdb), + "Library1.pdb must be copied to Intermediate directory"); + Assert.IsTrue ( + File.Exists (linkDst), + "Library1.pdb must be copied to linkdst directory"); + Assert.IsTrue ( + File.Exists (linkSrc), + "Library1.pdb must be copied to linksrc directory"); + FileAssert.AreEqual (linkDst, assetsPdb, $"Library1.pdb in {assetsPdb} should match {linkDst}"); + } + } + } + [Test] public void BuildBasicApplicationCheckMdbAndPortablePdb () {