-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Summary of the new feature / enhancement
As a user who may want to attach to an otherwise unattended process to debug it, I want to be able to pause execution in said unattended process until I'm able to attach to it.
Proposed technical implementation details (optional)
A common pattern in C# for this would be something like
while (!Debugger.IsAttached) Thread.Sleep(200);
RestOfCodeHere(); // breakpoint on this line
Currently in PowerShell there's no supported way to tell if a debugger is attached to the current runspace. A minimal way to enable this scenario would be a property on Runspace
:
public partial abstract class Runspace
{
+ public bool IsRemoteDebuggerAttached { get; }
}
This would allow the user to write the code
while (-not $Host.Runspace.IsRemoteDebuggerAttached) { Start-Sleep -Milliseconds 200 }
Invoke-RestOfCodeHere # breakpoint on this line, or just make it `Wait-Debugger`
If there is sufficient demand for it, a command or method to wait for attach can also be considered, but to start off the proposal I'd recommend this as an MVP.
One question that I would suggest be answered in the WG decision is: "What should a remote runspace do for this parameter? Throw? Or always return false?"