Skip to content

Commit d490e7a

Browse files
Abort execution when in a nested debug frame
When attempting to step, if we're in a nested debug frame that isn't a REPL we should stop execution before trying to exit the REPL.
1 parent 9d18d81 commit d490e7a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/PowerShellEditorServices/Services/PowerShell/Debugging/PowerShellDebugContext.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using Microsoft.Extensions.Logging;
9+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Context;
910
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
1011
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility;
1112

@@ -145,15 +146,27 @@ public void SetDebugResuming(DebuggerResumeAction debuggerResumeAction)
145146
// TODO: We need to assign cancellation tokens to each frame, because the current
146147
// logic results in a deadlock here when we try to cancel the scopes...which
147148
// includes ourself (hence running it in a separate thread).
148-
Task.Run(() => _psesHost.UnwindCallStack());
149+
_ = Task.Run(() => _psesHost.UnwindCallStack());
149150
return;
150151
}
151152

152153
// Otherwise we're continuing or stepping (i.e. resuming) so we need to cancel the
153154
// debugger REPL.
154-
if (_psesHost.CurrentFrame.IsRepl)
155+
PowerShellFrameType frameType = _psesHost.CurrentFrame.FrameType;
156+
if (frameType.HasFlag(PowerShellFrameType.Repl))
155157
{
156158
_psesHost.CancelIdleParentTask();
159+
return;
160+
}
161+
162+
// If the user is running something via the REPL like `while ($true) { sleep 1 }`
163+
// and then tries to step, we want to stop that so that execution can resume.
164+
//
165+
// This also applies to anything we're running on debugger stop like watch variables.
166+
if (frameType.HasFlag(PowerShellFrameType.Debug | PowerShellFrameType.Nested))
167+
{
168+
_psesHost.ForceSetExit();
169+
_psesHost.CancelIdleParentTask();
157170
}
158171
}
159172

0 commit comments

Comments
 (0)