mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user