forked from PowerShell/vscode-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChildDebugSessionAttach.ps1
More file actions
22 lines (18 loc) · 972 Bytes
/
ChildDebugSessionAttach.ps1
File metadata and controls
22 lines (18 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Example on how Start-DebugAttachSession can be used to attach to another
# process. This launches a child process that runs ChildDebugSessionTarget.ps1
# but it can be adapted to attach to any other PowerShell process that is
# either already running or started like this example. To test this example,
# add a breakpoint to ChildDebugSessionTarget.ps1, select the
# 'PowerShell Launch Current File' configuration and press F5.
$pipeName = "TestPipe-$(New-Guid)"
$scriptPath = Join-Path -Path $PSScriptRoot -ChildPath 'ChildDebugSessionTarget.ps1'
$procParams = @{
FilePath = 'pwsh'
ArgumentList = ('-CustomPipeName {0} -File "{1}" -WaitForAttach' -f $pipeName, $scriptPath)
PassThru = $true
}
$proc = Start-Process @procParams
Start-DebugAttachSession -CustomPipeName $pipeName -RunspaceId 1
# We need to ensure this debug session stays alive until the process exits. If
# we exit early then the child debug session will also exit.
$proc | Wait-Process