-
Notifications
You must be signed in to change notification settings - Fork 517
WIP: Add examples for Start-DebugAttachSession #5246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Adds examples to demonstrate how the new `Start-DebugAttachSession` function added in PowerShell Editor Services can be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds example scripts demonstrating the usage of the new Start-DebugAttachSession
function from PowerShell Editor Services. The examples show how to attach a debugger to a child PowerShell process using custom named pipes.
- Provides a target script that can be debugged when launched as a child process
- Demonstrates the complete workflow for attaching to and debugging external PowerShell processes
- Includes handling for both Windows PowerShell 5.1 and PowerShell Core compatibility
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
examples/ChildDebugSessionTarget.ps1 | Target script that runs in a child process and waits for debugger attachment |
examples/ChildDebugSessionAttach.ps1 | Main example script showing how to launch and attach to a child PowerShell process |
$procParams = @{ | ||
FilePath = 'pwsh' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding 'pwsh' assumes PowerShell Core is available. Consider using $PSVersionTable.PSEdition
to detect the current PowerShell edition and use 'powershell' for Windows PowerShell or 'pwsh' for PowerShell Core, or provide a parameter to specify the executable.
$procParams = @{ | |
FilePath = 'pwsh' | |
$psExecutable = if ($PSVersionTable.PSEdition -eq 'Core') { 'pwsh' } else { 'powershell' } | |
$procParams = @{ | |
FilePath = $psExecutable |
Copilot uses AI. Check for mistakes.
while ($true) { | ||
if (Get-Runspace | Where-Object { $_.Id -notin $runspaces.Id }) { | ||
break | ||
} | ||
Start-Sleep -Seconds 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The polling loop calls Get-Runspace
repeatedly without any delay optimization. Consider adding a small delay before each check or implementing exponential backoff to reduce unnecessary CPU usage during the wait period.
while ($true) { | |
if (Get-Runspace | Where-Object { $_.Id -notin $runspaces.Id }) { | |
break | |
} | |
Start-Sleep -Seconds 1 | |
$currentDelay = 1 # Initial delay duration in seconds | |
$maxDelay = 16 # Maximum delay duration in seconds | |
while ($true) { | |
if (Get-Runspace | Where-Object { $_.Id -notin $runspaces.Id }) { | |
break | |
} | |
Start-Sleep -Seconds $currentDelay | |
$currentDelay = [math]::Min($currentDelay * 2, $maxDelay) # Exponential backoff |
Copilot uses AI. Check for mistakes.
$runspaces = Get-Runspace | ||
while ($true) { | ||
if (Get-Runspace | Where-Object { $_.Id -notin $runspaces.Id }) { | ||
break | ||
} | ||
Start-Sleep -Seconds 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The infinite loop lacks a timeout mechanism. Consider adding a maximum wait time to prevent the script from hanging indefinitely if the debugger never attaches.
$runspaces = Get-Runspace | |
while ($true) { | |
if (Get-Runspace | Where-Object { $_.Id -notin $runspaces.Id }) { | |
break | |
} | |
Start-Sleep -Seconds 1 | |
$runspaces = Get-Runspace | |
$maxWaitTime = 60 # Maximum wait time in seconds | |
$elapsedTime = 0 # Initialize elapsed time | |
while ($true) { | |
if (Get-Runspace | Where-Object { $_.Id -notin $runspaces.Id }) { | |
break | |
} | |
Start-Sleep -Seconds 1 | |
$elapsedTime += 1 | |
if ($elapsedTime -ge $maxWaitTime) { | |
Write-Host "Timeout reached while waiting for debugger to attach." | |
break | |
} |
Copilot uses AI. Check for mistakes.
PR Summary
Adds examples to demonstrate how the new
Start-DebugAttachSession
function added in PowerShell Editor Services can be used.The new function is attached by the PR PowerShell/PowerShellEditorServices#2249.
PR Checklist
Note: Tick the boxes below that apply to this pull request by putting an
x
between the square brackets.Please mark anything not applicable to this PR
NA
.WIP:
to the beginning of the title and remove the prefix when the PR is ready