Skip to content

Commit

Permalink
Fix debugging server start sequence for fix that landed on CLI v2.
Browse files Browse the repository at this point in the history
* Split out debugging start out of Deploy() method
* Remove unnecessary 'await Task.Run'
  • Loading branch information
alexischr committed Jan 9, 2025
1 parent 3830a00 commit a6bc2bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
18 changes: 3 additions & 15 deletions src/csharp/Meadow/MeadowDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,15 @@ public async void Dispose()
}
}

public async Task<DebuggingServer> Deploy(string folder, int debugPort = -1)
public async Task<IMeadowConnection> Deploy(string folder, bool isDebugging)
{
var isDebugging = debugPort > 1000;

await Task.Run(async () =>
{
if (meadowConnection != null)
{
meadowConnection.FileWriteProgress -= MeadowConnection_DeploymentProgress;
meadowConnection.DeviceMessageReceived -= MeadowConnection_DeviceMessageReceived;
}

meadowConnection = await MeadowConnectionManager.GetConnectionForRoute(PortName);
meadowConnection = new MeadowConnectionManager(new SettingsManager()).GetConnectionForRoute(PortName);

meadowConnection.FileWriteProgress += MeadowConnection_DeploymentProgress;
meadowConnection.DeviceMessageReceived += MeadowConnection_DeviceMessageReceived;
Expand Down Expand Up @@ -106,15 +102,7 @@ await Task.Run(async () =>
{
meadowConnection.FileWriteProgress -= MeadowConnection_DeploymentProgress;
}
});

// Debugger only returns when session is done
if (isDebugging)
{
Logger.LogInformation("Debugging application...");
return await meadowConnection?.StartDebuggingSession(debugPort, Logger, CancelToken);
}
return null;
return meadowConnection;
}

private async void MeadowConnection_DeviceMessageReceived(object sender, (string message, string source) e)
Expand Down
9 changes: 7 additions & 2 deletions src/csharp/MonoDebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,23 @@ public override async void Launch(Response response, dynamic args)
try {

var logger = new DebugSessionLogger(l => Log(l));

var isDebugging = launchOptions.DebugPort > 1024;

// DEPLOY
meadowDeployer = new MeadowDeployer(this, logger, launchOptions.Serial, ctsDeployMeadow.Token);

meadowDebuggingServer = await meadowDeployer.Deploy(fullOutputPath, launchOptions.DebugPort);
var meadowConnection = await meadowDeployer.Deploy(fullOutputPath, isDebugging);

if (meadowDebuggingServer != null)
if (isDebugging)
{
var meadowDebuggingServerTask = meadowConnection.StartDebuggingSession(launchOptions.DebugPort, logger, ctsDeployMeadow.Token);

_attachMode = true;
Log($"Connecting to debugger: {address}:{launchOptions.DebugPort}");

Connect(IPAddress.Loopback, launchOptions.DebugPort);
await meadowDebuggingServerTask;
}

SendResponse(response);
Expand Down

0 comments on commit a6bc2bf

Please sign in to comment.