File tree 2 files changed +17
-2
lines changed
src/PowerShellEditorServices/Session
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>(
85
85
86
86
public void StopCommandInDebugger ( PowerShellContext powerShellContext )
87
87
{
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
+ }
89
93
}
90
94
91
95
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>(
765
765
executionOptions ,
766
766
true ) ;
767
767
768
- throw e ;
768
+ throw ;
769
769
}
770
770
finally
771
771
{
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
+
772
783
// Get the new prompt before releasing the runspace handle
773
784
if ( executionOptions . WriteOutputToHost )
774
785
{
You can’t perform that action at this time.
0 commit comments