Skip to content

Commit

Permalink
Refactoring and Bug Fixes. Prepare for GCDump
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneySprings committed Jan 3, 2024
1 parent 3667554 commit 451b423
Show file tree
Hide file tree
Showing 20 changed files with 448 additions and 373 deletions.
2 changes: 0 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ var configuration = Argument("configuration", "debug");
Task("clean").Does(() => {
EnsureDirectoryExists(ArtifactsDirectory);
CleanDirectory(ExtensionStagingDirectory);
CleanDirectories(_Path.Combine(RootDirectory, "src", "**", "bin"));
CleanDirectories(_Path.Combine(RootDirectory, "src", "**", "obj"));
});

///////////////////////////////////////////////////////////////////////////////
Expand Down
49 changes: 25 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@
"target": {
"type": "string",
"default": "build",
"enum": [ "build", "publish" ],
"enum": [
"build",
"publish"
],
"description": "%task.meteor.description.target%"
},
"args": {
Expand All @@ -88,7 +91,7 @@
{
"name": "%task.meteor.problemMatcher%",
"source": "%extension.displayName%",
"fileLocation":"relative",
"fileLocation": "relative",
"owner": "%extension.displayName%",
"pattern": {
"regexp": "^(.*.xaml)\\((\\d+),(\\d+)\\):.*?(error|warning)\\s(.*?):\\s(.*)$",
Expand All @@ -102,17 +105,17 @@
}
],
"breakpoints": [
{
"language": "csharp"
{
"language": "csharp"
},
{
"language": "fsharp"
{
"language": "fsharp"
},
{
"language": "razor"
{
"language": "razor"
},
{
"language": "aspnetcorerazor"
{
"language": "aspnetcorerazor"
}
],
"debuggers": [
Expand Down Expand Up @@ -154,17 +157,12 @@
"configurationAttributes": {
"launch": {
"properties": {
"device": {
"type": "string",
"description": "%debugger.meteor.description.device%"
},
"runtime": {
"type": "string",
"description": "%debugger.meteor.description.runtime%"
},
"profilerMode": {
"type": "string",
"enum": [ "trace" ],
"enum": [
"trace",
"gcdump"
],
"description": "%debugger.meteor.description.profilerMode%"
}
}
Expand All @@ -178,37 +176,39 @@
"dotnetMeteor.monoSdbDebuggerPortAndroid": {
"type": "integer",
"default": 10000,
"minimum": 0,
"description": "%configuration.description.monoSdbDebuggerPortAndroid%"
},
"dotnetMeteor.monoSdbDebuggerPortApple": {
"type": "integer",
"default": 55551,
"minimum": 0,
"description": "%configuration.description.monoSdbDebuggerPortApple%"
},
"dotnetMeteor.hotReloadHostPort": {
"type": "integer",
"default": 9988,
"minimum": 0,
"description": "%configuration.description.hotReloadHostPort%"
},
"dotnetMeteor.profilerHostPort": {
"type": "integer",
"default": 9000,
"minimum": 0,
"description": "%configuration.description.profilerHostPort%"
},
"dotnetMeteor.uninstallApplicationBeforeInstalling": {
"type": "boolean",
"default": true,
"description": "%configuration.description.uninstallApplicationBeforeInstalling%"
},


"dotnetMeteor.debuggerOptions.evaluationTimeout": {
"type":"integer",
"type": "integer",
"default": 5000,
"description": "%configuration.description.debuggerOptions.evaluationTimeout%"
},
"dotnetMeteor.debuggerOptions.memberEvaluationTimeout": {
"type":"integer",
"type": "integer",
"default": 5000,
"description": "%configuration.description.debuggerOptions.memberEvaluationTimeout%"
},
Expand Down Expand Up @@ -260,6 +260,7 @@
"dotnetMeteor.debuggerOptions.ellipsizedLength": {
"type": "integer",
"default": 260,
"minimum": 0,
"description": "%configuration.description.debuggerOptions.ellipsizedLength%"
},
"dotnetMeteor.debuggerOptions.integerDisplayFormat": {
Expand All @@ -274,4 +275,4 @@
}
}
}
}
}
24 changes: 24 additions & 0 deletions src/DotNet.Meteor.Debug/Agents/BaseLaunchAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using DotNet.Meteor.Processes;
using Mono.Debugging.Soft;

namespace DotNet.Meteor.Debug;

public abstract class BaseLaunchAgent {
public List<Action> Disposables { get; set; }

protected BaseLaunchAgent() {
Disposables = new List<Action>();
}

public abstract void Connect(SoftDebuggerSession session, LaunchConfiguration configuration);
public abstract void Launch(LaunchConfiguration configuration, IProcessLogger logger);

public virtual void Dispose() {
foreach(var disposable in Disposables)
disposable.Invoke();

Disposables.Clear();
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using System.IO;
using DotNet.Meteor.Shared;
using DotNet.Meteor.Processes;
using System;
using System.Net;
using Mono.Debugging.Soft;
using DotNet.Meteor.Debug.Extensions;
using DotNet.Meteor.Debug.Sdb;
using DotNet.Meteor.Debug.Sdk;
using DotNet.Meteor.Processes;
using DotNet.Meteor.Shared;
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol;
using Mono.Debugging.Soft;

namespace DotNet.Meteor.Debug;

public partial class DebugSession {
private void Connect(LaunchConfiguration configuration) {
public class DebugLaunchAgent : BaseLaunchAgent {
public override void Connect(SoftDebuggerSession session, LaunchConfiguration configuration) {
SoftDebuggerStartArgs arguments = null;

if (configuration.Device.IsAndroid || (configuration.Device.IsIPhone && !configuration.Device.IsEmulator))
Expand All @@ -21,22 +21,19 @@ private void Connect(LaunchConfiguration configuration) {

ArgumentNullException.ThrowIfNull(arguments, "Debugger connection arguments not implemented.");
session.Run(new SoftDebuggerStartInfo(arguments), configuration.DebuggerSessionOptions);
OnOutputDataReceived("Debugger is ready and listening...");
}
private void LaunchApplication(LaunchConfiguration configuration) {
DoSafe(() => {
if (configuration.Device.IsAndroid)
LaunchAndroid(configuration);
if (configuration.Device.IsIPhone)
LaunchAppleMobile(configuration);
if (configuration.Device.IsMacCatalyst)
LaunchMacCatalyst(configuration);
if (configuration.Device.IsWindows)
LaunchWindows(configuration);
});
public override void Launch(LaunchConfiguration configuration, IProcessLogger logger) {
if (configuration.Device.IsAndroid)
LaunchAndroid(configuration, logger);
if (configuration.Device.IsIPhone)
LaunchAppleMobile(configuration, logger);
if (configuration.Device.IsMacCatalyst)
LaunchMacCatalyst(configuration, logger);
if (configuration.Device.IsWindows)
throw new NotSupportedException();
}

private void LaunchAppleMobile(LaunchConfiguration configuration) {
private void LaunchAppleMobile(LaunchConfiguration configuration, IProcessLogger logger) {
// TODO: Implement Apple launching for Windows
// if (RuntimeSystem.IsWindows) {
// IDeviceTool.Installer(configuration.Device.Serial, configuration.OutputAssembly, this);
Expand All @@ -47,33 +44,28 @@ private void LaunchAppleMobile(LaunchConfiguration configuration) {
// }

if (configuration.Device.IsEmulator) {
var debugProcess = MonoLaunch.DebugSim(configuration.Device.Serial, configuration.OutputAssembly, configuration.DebugPort, this);
disposables.Add(() => debugProcess.Terminate());
var debugProcess = MonoLaunch.DebugSim(configuration.Device.Serial, configuration.OutputAssembly, configuration.DebugPort, logger);
Disposables.Add(() => debugProcess.Terminate());
} else {
var forwardingProcess = MonoLaunch.TcpTunnel(configuration.Device.Serial, configuration.DebugPort, this);
MonoLaunch.InstallDev(configuration.Device.Serial, configuration.OutputAssembly, this);
var forwardingProcess = MonoLaunch.TcpTunnel(configuration.Device.Serial, configuration.DebugPort, logger);
MonoLaunch.InstallDev(configuration.Device.Serial, configuration.OutputAssembly, logger);

var debugProcess = MonoLaunch.DebugDev(configuration.Device.Serial, configuration.OutputAssembly, configuration.DebugPort, this);
disposables.Add(() => debugProcess.Terminate());
disposables.Add(() => forwardingProcess.Terminate());
var debugProcess = MonoLaunch.DebugDev(configuration.Device.Serial, configuration.OutputAssembly, configuration.DebugPort, logger);
Disposables.Add(() => debugProcess.Terminate());
Disposables.Add(() => forwardingProcess.Terminate());
}
}
private void LaunchMacCatalyst(LaunchConfiguration configuration) {
private void LaunchMacCatalyst(LaunchConfiguration configuration, IProcessLogger logger) {
var tool = AppleSdk.OpenTool();
var processRunner = new ProcessRunner(tool, new ProcessArgumentBuilder().AppendQuoted(configuration.OutputAssembly));
processRunner.SetEnvironmentVariable("__XAMARIN_DEBUG_HOSTS__", "127.0.0.1");
processRunner.SetEnvironmentVariable("__XAMARIN_DEBUG_PORT__", configuration.DebugPort.ToString());
var result = processRunner.WaitForExit();

if (!result.Success)
throw new ProtocolException(string.Join(Environment.NewLine, result.StandardError));
}
private void LaunchWindows(LaunchConfiguration configuration) {
var program = new FileInfo(configuration.OutputAssembly);
var process = new ProcessRunner(program, new ProcessArgumentBuilder(), this).Start();
disposables.Add(() => process.Terminate());
ServerExtensions.ThrowException(string.Join(Environment.NewLine, result.StandardError));
}
private void LaunchAndroid(LaunchConfiguration configuration) {
private void LaunchAndroid(LaunchConfiguration configuration, IProcessLogger logger) {
var applicationId = configuration.GetApplicationName();
if (configuration.Device.IsEmulator)
configuration.Device.Serial = AndroidEmulator.Run(configuration.Device.Name).Serial;
Expand All @@ -84,18 +76,18 @@ private void LaunchAndroid(LaunchConfiguration configuration) {
DeviceBridge.Forward(configuration.Device.Serial, configuration.DebugPort);

if (configuration.UninstallApp)
DeviceBridge.Uninstall(configuration.Device.Serial, applicationId, this);
DeviceBridge.Uninstall(configuration.Device.Serial, applicationId, logger);

DeviceBridge.Install(configuration.Device.Serial, configuration.OutputAssembly, this);
DeviceBridge.Install(configuration.Device.Serial, configuration.OutputAssembly, logger);
DeviceBridge.Shell(configuration.Device.Serial, "setprop", "debug.mono.connect", $"port={configuration.DebugPort}");
DeviceBridge.Launch(configuration.Device.Serial, applicationId, this);
DeviceBridge.Launch(configuration.Device.Serial, applicationId, logger);
DeviceBridge.Flush(configuration.Device.Serial);

var logcatFirstChannelProcess = DeviceBridge.Logcat(configuration.Device.Serial, "system,crash", "*:I", this);
var logcatSecondChannelProcess = DeviceBridge.Logcat(configuration.Device.Serial, "main", "DOTNET:I", this);
var logcatFirstChannelProcess = DeviceBridge.Logcat(configuration.Device.Serial, "system,crash", "*:I", logger);
var logcatSecondChannelProcess = DeviceBridge.Logcat(configuration.Device.Serial, "main", "DOTNET:I", logger);

disposables.Add(() => logcatFirstChannelProcess.Terminate());
disposables.Add(() => logcatSecondChannelProcess.Terminate());
disposables.Add(() => DeviceBridge.RemoveForward(configuration.Device.Serial));
Disposables.Add(() => logcatFirstChannelProcess.Terminate());
Disposables.Add(() => logcatSecondChannelProcess.Terminate());
Disposables.Add(() => DeviceBridge.RemoveForward(configuration.Device.Serial));
}
}
39 changes: 39 additions & 0 deletions src/DotNet.Meteor.Debug/Agents/GCDumpLaunchAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.IO;
using DotNet.Meteor.Debug.Extensions;
using DotNet.Meteor.Debug.Sdk;
using DotNet.Meteor.Debug.Sdk.Profiling;
using DotNet.Meteor.Processes;
using DotNet.Meteor.Shared;
using Mono.Debugging.Soft;

namespace DotNet.Meteor.Debug;

public class GCDumpLaunchAgent : BaseLaunchAgent {
public override void Connect(SoftDebuggerSession session, LaunchConfiguration configuration) {}
public override void Launch(LaunchConfiguration configuration, IProcessLogger logger) {
// var nettracePath = Path.Combine(configuration.TempDirectoryPath, $"{configuration.GetApplicationName()}.nettrace");
// var diagnosticPort = Path.Combine(RuntimeSystem.HomeDirectory, $"{configuration.Device.Platform}-port.lock");
// ServerExtensions.TryDeleteFile(diagnosticPort);

// if (configuration.Device.IsAndroid)
// LaunchAndroid(configuration, logger, diagnosticPort, nettracePath);
// if (configuration.Device.IsIPhone)
// LaunchAppleMobile(configuration, logger, diagnosticPort, nettracePath);
// if (configuration.Device.IsMacCatalyst)
// LaunchMacCatalyst(configuration, logger, diagnosticPort, nettracePath);
// if (configuration.Device.IsWindows)
// LaunchWindows(configuration, logger, diagnosticPort, nettracePath);

// Disposables.Add(() => ServerExtensions.TryDeleteFile(diagnosticPort));
}

private void LaunchAppleMobile(LaunchConfiguration configuration, IProcessLogger logger, string diagnosticPort, string nettracePath) {
}
private void LaunchMacCatalyst(LaunchConfiguration configuration, IProcessLogger logger, string diagnosticPort, string nettracePath) {
}
private void LaunchAndroid(LaunchConfiguration configuration, IProcessLogger logger, string diagnosticPort, string nettracePath) {
}
private void LaunchWindows(LaunchConfiguration configuration, IProcessLogger logger, string diagnosticPort, string nettracePath) {
}
}
Loading

0 comments on commit 451b423

Please sign in to comment.