-
Notifications
You must be signed in to change notification settings - Fork 511
Debug Session not respecting Added or removed Breakpoints & Integrated Shell Crash #1494
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
Comments
Thanks for opening an issue @GABeech. I can reproduce this on my machine. I've been looking into it but haven't found the cause yet. Will continue investigating. |
So I've debugged this a couple of times and I've just hit a nasty hang here: |
@rjmholt If you have the PSRL build still, see if you can reproduce it there. I made a lot of changes around the runspace handle queues. |
So I did some more investigating on this today. The breakpoint is set correctly and unset correctly, but trying to set it again does nothing at all. This is almost certainly because PSES is being blocked by the current execution. I was curious as to where PSES thought it was, so I paused the PSES .NET debugger and on my Windows machine in 1.9.1, it reports itself as being here: In v2, I think it reports itself as being here: I think it basically comes down to the debug adapter not being able to interrupt the script to add a new breakpoint -- which is obviously a problem. In 1.9.1 I get no crash (or at least I didn't this time). But with v2 I got a pipe broken error, which I think we've seen can also occur in 1.9.1. |
After looking into this and thinking about it a bit, this looks like a deeper issue -- I'll see what we can do to fix it, but I think we will need to do some cleverness with interrupting the execution of the PowerShell pipeline. |
We could implement this in 2.0. Taking over script execution between sequence points can be done with events, but that requires all the nested context work done for PSReadLine. |
If we can engineer that, it would be useful in a whole bunch of cases for cancellation of the PowerShell executions powering most requests -- so we could finally implement |
We can already trigger a pipeline stop from any thread, the engine supports that. Just gotta tie a request to a powershell instance |
Ok @GABeech I've done some research on this one and talked to @PaulHigin as well, who is our debugger expert. Because the PowerShell debugger is just PowerShell, setting a breakpoint while the pipeline is running is a bit trickier than for other languages. As far as I know, it's something that neither PowerShell nor the ISE has directly supported. But, experimenting with your scenario, using the pause (⏸ or F6) button will stop pipeline execution. It hooks into the same API that the ISE uses with Ctrl+Break and PowerShell itself (the ConHost) uses with Ctrl+B. So the current way to set a breakpoint while a script is running like in the scenario above it:
Bear in mind that if you have a single long running command or .NET call, this can't pause that. There's no mechanism for that anywhere, because the PowerShell debugger is PowerShell -- it can't stop in the middle of a native or .NET call. I'm looking into how we might make this automatic -- so that when you set a breakpoint, it will stop the pipeline, insert the breakpoint and then continue on its way. But it's complicated by needing to sync up VSCode's client state. |
@rjmholt We could use events. I think this should be safe from issues like the completion deadlock. Here's a little sample: $timer = [System.Timers.Timer]::new(60000)
Register-ObjectEvent -InputObject $timer -EventName Elapsed -Action {
$Event | Unregister-Event
Set-PSBreakpoint -Variable someSpecificVar -Mode Write
}
$timer.Enabled = $true
# After a minute, the debugger will break on the someSpecificVar assignment.
while ($true) {
$someSpecificVar = $true
Start-Sleep 5
} We would probably want register it on an event on |
Does |
@rkeithhill Not sure what the usual timeout is for Same idea though, we would queue up breakpoints by raising an event on an object we control and the subscriber would get to it at the next sequence point. |
@rkeithhill I don't think The reason I mention our
It's what the ISE uses for interrupting a currently running script to break into it. Is there a reason using that is a bad idea for us? |
@rjmholt I could be wrong but I believe that just tells the debugger that it should pause at the next sequence point. I don't think it synchronously stops the debugger. |
Right, it just says "please pause the debugger at the next opportunity". Is there a way we think we can/should be doing better than that? |
We're not specifically trying to stop the debugger right? If we're just trying to set a breakpoint then I think the event route is cleaner. We could stop the debugger, then in the |
Ah, yes agreed! It seems like an API we ought to have on |
Sorry for the late contribution. If I understand the issue correctly, engine events are not needed to manage script breakpoints. But the only way to update script breakpoints on running script is to, as discussed above: Note that the first step (a.) can be problematic if the script is not running but is stalled during a dotNet API call or while running a native command. The debugger stop event will not occur until the next sequence point is executed. Breaking into the debugger can be done via the ScriptDebugger.SetDebuggerStepMode() method, and engine events are not needed. The method can be called from any thread. Then as @SeeminglyScience mentions, breakpoints can be managed during the DebuggerStop event callback via the ScriptDebugger.ProcessCommand() method. |
Issue Description
When I run a debug session two things happen:
You can replicate this by running a small script like:
Removing Breakpoint
Write-Output
Write-Output
What will happen is the debugger will break again on the first
Write-Output
and you won't be able to continue. If you stop execution and typeexit
in the debug terminal the integrated terminal will crashAdding Breakpoint
Attached Logs
EditorServices.log
vscode-powershell.log
) about
capturing and sending logs.
Environment Information
Visual Studio Code
PowerShell Information
Visual Studio Code Extensions
Visual Studio Code Extensions(Click to Expand)
The text was updated successfully, but these errors were encountered: