Add property and event for debug attach (#25788)

Adds the `IsRemoteDebuggerAttached` property to `Runspace` that
indicates whether a debugger is attached to the Runspace through the
`Debug-Runspace` cmdlet. Also adds a new engine event
`PowerShell.OnDebugAttach` that is emitted when the debugger is
attached.
This commit is contained in:
Jordan Borean
2025-10-07 18:34:15 -04:00
committed by GitHub
parent 60d4bc39bc
commit 0ef738b36f
4 changed files with 49 additions and 1 deletions
@@ -31,6 +31,33 @@ Describe "Debug-Runspace" -Tag "CI" {
$rs1.Debugger.SetDebugMode("None")
{ Debug-Runspace -Runspace $rs1 -ErrorAction stop } | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.DebugRunspaceCommand"
}
It "Should write attach event and mark runspace as having a remote debugger attached" {
$onAttachName = [System.Management.Automation.PSEngineEvent]::OnDebugAttach
$debugTarget = [PowerShell]::Create()
$null = $debugTarget.AddCommand('Wait-Event').AddParameter('SourceIdentifier', $onAttachName)
$waitTask = $debugTarget.BeginInvoke()
$debugTarget.Runspace.IsRemoteDebuggerAttached | Should -BeFalse
$debugger = [PowerShell]::Create()
$null = $debugger.AddCommand('Debug-Runspace').AddParameter('Id', $debugTarget.Runspace.Id)
$debugTask = $debugger.BeginInvoke()
$waitTask.AsyncWaitHandle.WaitOne(5000) | Should -BeTrue
$waitInfo = $debugTarget.EndInvoke($waitTask)
$waitInfo.SourceIdentifier | Should -Be $onAttachName
$debugTarget.Runspace.IsRemoteDebuggerAttached | Should -BeTrue
$debugger.Stop()
$exp = {
$debugger.EndInvoke($debugTask)
} | Should -Throw -PassThru
$exp.FullyQualifiedErrorId | Should -Be "PipelineStoppedException"
$debugTarget.Runspace.IsRemoteDebuggerAttached | Should -BeFalse
}
}