File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
src/PowerShellEditorServices/Session Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,11 @@ public IEnumerable<TResult> ExecuteCommandInDebugger<TResult>(
8585
8686 public void StopCommandInDebugger ( PowerShellContext powerShellContext )
8787 {
88- powerShellContext . CurrentRunspace . Runspace . Debugger . StopProcessCommand ( ) ;
88+ // If the RunspaceAvailability is None, the runspace is dead and we should not try to run anything in it.
89+ if ( powerShellContext . CurrentRunspace . Runspace . RunspaceAvailability != RunspaceAvailability . None )
90+ {
91+ powerShellContext . CurrentRunspace . Runspace . Debugger . StopProcessCommand ( ) ;
92+ }
8993 }
9094
9195 public void ExitNestedPrompt ( PSHost host )
Original file line number Diff line number Diff line change @@ -765,10 +765,21 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
765765 executionOptions ,
766766 true ) ;
767767
768- throw e ;
768+ throw ;
769769 }
770770 finally
771771 {
772+ // If the RunspaceAvailability is None, it means that the runspace we're in is dead.
773+ // If this is the case, we should abort the execution which will clean up the runspace
774+ // (and clean up the debugger) and then pop it off the stack.
775+ // An example of when this happens is when the "attach" debug config is used and the
776+ // process you're attached to dies randomly.
777+ if ( this . CurrentRunspace . Runspace . RunspaceAvailability == RunspaceAvailability . None )
778+ {
779+ this . AbortExecution ( shouldAbortDebugSession : true ) ;
780+ this . PopRunspace ( ) ;
781+ }
782+
772783 // Get the new prompt before releasing the runspace handle
773784 if ( executionOptions . WriteOutputToHost )
774785 {
You can’t perform that action at this time.
0 commit comments