diff --git a/src/SharpIDE.Application/Features/Debugging/Debugger.cs b/src/SharpIDE.Application/Features/Debugging/Debugger.cs index f2abdd7..3f94949 100644 --- a/src/SharpIDE.Application/Features/Debugging/Debugger.cs +++ b/src/SharpIDE.Application/Features/Debugging/Debugger.cs @@ -7,9 +7,9 @@ public class Debugger { public required SharpIdeProjectModel Project { get; init; } public required int ProcessId { get; init; } + private DebuggingService _debuggingService = new DebuggingService(); public async Task Attach(CancellationToken cancellationToken) { - var debuggingService = new DebuggingService(); - await debuggingService.Attach(ProcessId, cancellationToken); + await _debuggingService.Attach(ProcessId, cancellationToken); } } diff --git a/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs b/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs index 8945b1a..27b8bfa 100644 --- a/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs +++ b/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs @@ -11,6 +11,7 @@ namespace SharpIDE.Application.Features.Debugging; public class DebuggingService { + private DebugProtocolHost _debugProtocolHost = null!; public async Task Attach(int debuggeeProcessId, CancellationToken cancellationToken = default) { Guard.Against.NegativeOrZero(debuggeeProcessId, nameof(debuggeeProcessId), "Process ID must be a positive integer."); @@ -32,6 +33,7 @@ public class DebuggingService process.Start(); var debugProtocolHost = new DebugProtocolHost(process.StandardInput.BaseStream, process.StandardOutput.BaseStream, false); + _debugProtocolHost = debugProtocolHost; debugProtocolHost.LogMessage += (sender, args) => { //Console.WriteLine($"Log message: {args.Message}"); @@ -58,10 +60,15 @@ public class DebuggingService var signatureResponse = VsSigner.Sign(responder.Arguments.Value); responder.SetResponse(new HandshakeResponse(signatureResponse)); }); - debugProtocolHost.RegisterEventType(@event => + debugProtocolHost.RegisterEventType(async void (@event) => { - ; - var threadId = @event.ThreadId; + await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding); // The VS Code Debug Protocol throws if you try to send a request from the dispatcher thread + if (@event.Reason is StoppedEvent.ReasonValue.Exception) + { + Console.WriteLine("Stopped due to exception, continuing"); + var continueRequest = new ContinueRequest { ThreadId = @event.ThreadId!.Value }; + _debugProtocolHost.SendRequestSync(continueRequest); + } }); debugProtocolHost.VerifySynchronousOperationAllowed(); var initializeRequest = new InitializeRequest