Skip to content

Add a way to see if a remote debugger has attached #21392

@SeeminglyScience

Description

@SeeminglyScience

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?"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeWG-Enginecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions