-
Notifications
You must be signed in to change notification settings - Fork 237
Add Start-DebugAttachSession function #2249
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 the `Start-DebugAttachSession` cmdlet which can be used to launch a new attach session debug request inside an existing launched debug session. This allows a script being debugged to launch a child debugging session using more dynamic environment information without requiring end users to manually setup the launch.json configuration.
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 the Start-DebugAttachSession
cmdlet that enables launching a new attach session debug request from within an existing debug session. This allows scripts to dynamically start child debugging sessions without requiring manual launch.json configuration.
Key changes:
- Added new
Start-DebugAttachSession
PowerShell function with comprehensive parameter support - Implemented debug server variable management for session lifecycle
- Added comprehensive documentation and examples
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
LaunchAndAttachHandler.cs | Sets global debug server variable during launch for child session access |
DisconnectHandler.cs | Cleans up debug server variable on disconnect for non-attach sessions |
DebugService.cs | Defines constant for debug server variable name |
Start-DebugAttachSession.ps1 | Main cmdlet implementation with parameter validation and debug request handling |
Start-DebugAttachSession.md | Comprehensive documentation with examples and parameter descriptions |
PowerShellEditorServices.Commands.md | Updates module documentation to include new cmdlet |
PowerShellEditorServices.Commands.psd1 | Exports new function in module manifest |
module/PowerShellEditorServices/Commands/Public/Start-DebugAttachSession.ps1
Outdated
Show resolved
Hide resolved
module/PowerShellEditorServices/Commands/Public/Start-DebugAttachSession.ps1
Outdated
Show resolved
Hide resolved
[ErrorCategory]::InvalidArgument, | ||
$null) | ||
$err.ErrorDetails = [ErrorDetails]::new("") | ||
$err.ErrorDetails.RecommendedAction = 'Specify only one of RunspaceId or RunspaceName.' |
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.
chefs kiss on recommendedaction
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.
Gotta play to the crowd :) It has made me notice that it's awkward to set it in PowerShell outside of Write-Error
. Might be something to look into some more.
module/PowerShellEditorServices/Commands/Public/Start-DebugAttachSession.ps1
Outdated
Show resolved
Hide resolved
// Start-DebugAttachSession attaches in a new temp console | ||
// so we cannot set this var if already running in that | ||
// console. | ||
PSCommand setVariableCmd = new PSCommand().AddCommand("Set-Variable") |
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.
Nice way to pass this in.
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.
LGTM for the most part, this will be a very useful addtiion!
-
doing detach in the runspace creates an unhandled exception, we should probably handle this nicer if at all possible but it might not be.
-
having tests for this would be ideal, but scaffolding it may be difficult. It should be doable without needing to E2E it via the vscode-powershell repo. I'll think on it.
I wonder if there's any way we can hook into child pwsh process starts from an active debug session and do "smart" attach similar to what node does, this way you could debug child processes without having to make code changes. That would be a separate PR though.
In any case, this is more or less nonexistent/broken functionality so this isn't a risky thing to merge.
This is somewhat of an existing problem and I definitely agree it would be nice to solve. Basically the underlying process ends which kills the transport and the debug server doesn't handle that properly. IIRC the error message also says if you see this at the end it can be ignored.
Testing an attach scenario is hard, I've started to add some scaffolding to #2250 but agree more tests are really needed for attaching. I think the difficult bit will be that Omnisharp doesn't actually know about |
module/PowerShellEditorServices/Commands/Public/Start-DebugAttachSession.ps1
Outdated
Show resolved
Hide resolved
Looks like there is a way to wait for any request by name in the test runner so it should be possible to test this out. I'll probably want to look at adding it in in a separate PR though as the tests in my various PRs are starting to rely on each other or repeat the same things. |
PR Summary
Adds the
Start-DebugAttachSession
cmdlet which can be used to launch a new attach session debug request inside an existing launched debug session. This allows a script being debugged to launch a child debugging session using more dynamic environment information without requiring end users to manually setup the launch.json configuration.PR Context
Fixes: #2244
Examples added with: PowerShell/vscode-powershell#5246