Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Mono.Android/Android.Runtime/JNINativeWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class JNINativeWrapper {

static void get_runtime_types ()
{
if (mono_unhandled_exception_method != null)
if (exception_handler_method != null)
return;
#if MONOANDROID1_0
mono_unhandled_exception_method = typeof (System.Diagnostics.Debugger).GetMethod (
Expand Down Expand Up @@ -70,10 +70,10 @@ public static Delegate CreateDelegate (Delegate dlg)
ig.Emit (OpCodes.Leave, label);

bool filter = Debugger.IsAttached || !JNIEnv.PropagateExceptions;
if (filter) {
if (filter && mono_unhandled_exception_method != null) {
ig.BeginExceptFilterBlock ();

ig.Emit (OpCodes.Call, mono_unhandled_exception_method!);
ig.Emit (OpCodes.Call, mono_unhandled_exception_method);
ig.Emit (OpCodes.Ldc_I4_1);
ig.BeginCatchBlock (null!);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ It is shared between "legacy" binding projects and .NET 5 projects.
</PropertyGroup>
</Target>

<Target Name="AndroidPrepareForBuild" DependsOnTargets="GetReferenceAssemblyPaths" />

<Target Name="GenerateBindings"
Condition=" '$(UsingAndroidNETSdk)' != 'true' Or '@(InputJar)' != '' Or '@(EmbeddedJar)' != '' "
DependsOnTargets="ExportJarToXml;_ResolveMonoAndroidSdks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved.
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>

<Target Name="AndroidPrepareForBuild" DependsOnTargets="GetReferenceAssemblyPaths" />

<!-- Warn about deprecated configurations.
Do it here because we want them to appear on every build,
even if we aren't rerunning generator -->
Expand Down
78 changes: 77 additions & 1 deletion tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using Mono.Debugging.Client;
using Mono.Debugging.Soft;
using NUnit.Framework;
using Xamarin.ProjectTools;

Expand All @@ -26,7 +31,6 @@ public void DotNetInstallAndRun ([Values (false, true)] bool isRelease, [Values
IsRelease = isRelease
};
}
proj.SetProperty (KnownProperties.AndroidSupportedAbis, DeviceAbi);
proj.SetRuntimeIdentifier (DeviceAbi);

var relativeProjDir = Path.Combine ("temp", TestName);
Expand All @@ -43,5 +47,77 @@ public void DotNetInstallAndRun ([Values (false, true)] bool isRelease, [Values
RunAdbCommand ($"uninstall {proj.PackageName}");
Assert.IsTrue(didLaunch, "Activity should have started.");
}

[Test]
public void DotNetDebug ()
{
if (!HasDevices)
Assert.Ignore ("Skipping Test. No devices available.");

XASdkProject proj;
proj = new XASdkProject ();
proj.SetRuntimeIdentifier (DeviceAbi);

var relativeProjDir = Path.Combine ("temp", TestName);
var fullProjDir = Path.Combine (Root, relativeProjDir);
TestOutputDirectories [TestContext.CurrentContext.Test.ID] = fullProjDir;
var files = proj.Save ();
proj.Populate (relativeProjDir, files);
proj.CopyNuGetConfig (relativeProjDir);
var dotnet = new DotNetCLI (proj, Path.Combine (fullProjDir, proj.ProjectFilePath));
Assert.IsTrue (dotnet.Build ("Install"), "`dotnet build` should succeed");

bool breakpointHit = false;
ManualResetEvent resetEvent = new ManualResetEvent (false);
var sw = new Stopwatch ();
// setup the debugger
var session = new SoftDebuggerSession ();
session.Breakpoints = new BreakpointStore {
{ Path.Combine (Root, dotnet.ProjectDirectory, "MainActivity.cs"), 19 },
};
session.TargetHitBreakpoint += (sender, e) => {
Console.WriteLine ($"BREAK {e.Type}");
breakpointHit = true;
session.Continue ();
};
var rnd = new Random ();
int port = rnd.Next (10000, 20000);
TestContext.Out.WriteLine ($"{port}");
var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) {
MaxConnectionAttempts = 10,
};
var startInfo = new SoftDebuggerStartInfo (args) {
WorkingDirectory = Path.Combine (dotnet.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets"),
};
var options = new DebuggerSessionOptions () {
EvaluationOptions = EvaluationOptions.DefaultOptions,
};
options.EvaluationOptions.UseExternalTypeResolver = true;
ClearAdbLogcat ();
Assert.True (dotnet.Build ("_Run", new string [] {
$"AndroidSdbTargetPort={port}",
$"AndroidSdbHostPort={port}",
"AndroidAttachDebugger=True",
}), "Project should have run.");

Assert.IsTrue (WaitForDebuggerToStart (Path.Combine (Root, dotnet.ProjectDirectory, "logcat.log")), "Activity should have started");
// we need to give a bit of time for the debug server to start up.
WaitFor (2000);
session.LogWriter += (isStderr, text) => { Console.WriteLine (text); };
session.OutputWriter += (isStderr, text) => { Console.WriteLine (text); };
session.DebugWriter += (level, category, message) => { Console.WriteLine (message); };
session.Run (startInfo, options);
WaitFor (TimeSpan.FromSeconds (30), () => session.IsConnected);
Assert.True (session.IsConnected, "Debugger should have connected but it did not.");
// we need to wait here for a while to allow the breakpoints to hit
// but we need to timeout
TimeSpan timeout = TimeSpan.FromSeconds (60);
while (session.IsConnected && !breakpointHit && timeout >= TimeSpan.Zero) {
Thread.Sleep (10);
timeout = timeout.Subtract (TimeSpan.FromMilliseconds (10));
}
WaitFor (2000);
Assert.IsTrue (breakpointHit, "Should have a breakpoint");
}
}
}