public async Task <DisconnectResponse> Handle(DisconnectArguments request, CancellationToken cancellationToken) { // TODO: We need to sort out the proper order of operations here. // Currently we just tear things down in some order without really checking what the debugger is doing. // We should instead ensure that the debugger is in some valid state, lock it and then tear things down _debugEventHandlerService.UnregisterEventHandlers(); if (!_debugStateService.ExecutionCompleted) { _debugStateService.ExecutionCompleted = true; _debugService.Abort(); if (_debugStateService.IsInteractiveDebugSession && _debugStateService.IsAttachSession) { // Pop the sessions if (_runspaceContext.CurrentRunspace.RunspaceOrigin == RunspaceOrigin.EnteredProcess) { try { await _executionService.ExecutePSCommandAsync( new PSCommand().AddCommand("Exit-PSHostProcess"), CancellationToken.None).ConfigureAwait(false); if (_debugStateService.IsRemoteAttach && _runspaceContext.CurrentRunspace.RunspaceOrigin == RunspaceOrigin.EnteredProcess) { await _executionService.ExecutePSCommandAsync( new PSCommand().AddCommand("Exit-PSSession"), CancellationToken.None).ConfigureAwait(false); } } catch (Exception e) { _logger.LogException("Caught exception while popping attached process after debugging", e); } } } _debugService.IsClientAttached = false; } _logger.LogInformation("Debug adapter is shutting down..."); #pragma warning disable CS4014 // Trigger the clean up of the debugger. No need to wait for it nor cancel it. Task.Run(_psesDebugServer.OnSessionEnded, CancellationToken.None); #pragma warning restore CS4014 return(new DisconnectResponse()); }
private async Task OnExecutionCompletedAsync(Task executeTask) { try { await executeTask.ConfigureAwait(false); } catch (Exception e) { _logger.LogError( "Exception occurred while awaiting debug launch task.\n\n" + e.ToString()); } _logger.LogTrace("Execution completed, terminating..."); _debugStateService.ExecutionCompleted = true; _debugEventHandlerService.UnregisterEventHandlers(); if (_debugStateService.IsAttachSession) { // Pop the sessions if (_powerShellContextService.CurrentRunspace.Context == RunspaceContext.EnteredProcess) { try { await _powerShellContextService.ExecuteScriptStringAsync("Exit-PSHostProcess"); if (_debugStateService.IsRemoteAttach && _powerShellContextService.CurrentRunspace.Location == RunspaceLocation.Remote) { await _powerShellContextService.ExecuteScriptStringAsync("Exit-PSSession"); } } catch (Exception e) { _logger.LogException("Caught exception while popping attached process after debugging", e); } } } _debugService.IsClientAttached = false; _jsonRpcServer.SendNotification(EventNames.Terminated); }
public async Task <DisconnectResponse> Handle(DisconnectArguments request, CancellationToken cancellationToken) { _debugEventHandlerService.UnregisterEventHandlers(); if (_debugStateService.ExecutionCompleted == false) { _debugStateService.ExecutionCompleted = true; _powerShellContextService.AbortExecution(shouldAbortDebugSession: true); if (_debugStateService.IsInteractiveDebugSession && _debugStateService.IsAttachSession) { // Pop the sessions if (_powerShellContextService.CurrentRunspace.Context == RunspaceContext.EnteredProcess) { try { await _powerShellContextService.ExecuteScriptStringAsync("Exit-PSHostProcess").ConfigureAwait(false); if (_debugStateService.IsRemoteAttach && _powerShellContextService.CurrentRunspace.Location == RunspaceLocation.Remote) { await _powerShellContextService.ExecuteScriptStringAsync("Exit-PSSession").ConfigureAwait(false); } } catch (Exception e) { _logger.LogException("Caught exception while popping attached process after debugging", e); } } } _debugService.IsClientAttached = false; } _logger.LogInformation("Debug adapter is shutting down..."); #pragma warning disable CS4014 // Trigger the clean up of the debugger. No need to wait for it. Task.Run(_psesDebugServer.OnSessionEnded); #pragma warning restore CS4014 return(new DisconnectResponse()); }