Debugger Issues
Prerequisites
- [X] I have written a descriptive issue title.
- [X] I have searched all issues to ensure it has not already been reported.
- [X] I have read the troubleshooting guide.
- [X] I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
Summary
REF: https://github.com/PowerShell/vscode-powershell/issues/3394#issuecomment-904786408
After attempting to resolve my issue with the pre-release version of the extension, the debugger started failing again. Per @rjmholt 's suggestion, I am opening a new issue for tracking.
PowerShell Version
Both PS 5.1 and 7 have issues.
Name Value
---- -----
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
OS Microsoft Windows 10.0.18363
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Name Value
---- -----
PSVersion 5.1.18362.1474
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.1474
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Visual Studio Code Version
1.59.1
3866c3553be8b268c8a7f8c0482c0c0177aa8bfa
x64
Extension Version
[email protected]
[email protected]
Steps to Reproduce
Scenario 1 (PowerShell 5.1)
- Close all VSCode instances
- Open new instance with no folder opened
- Create a new PowerShell script
- Past in script below (do not save)
function Write-SomeStatus {
# Breakpoint on following line
Write-Host 'Some Status'
}
Write-SomeStatus
- Press F5
Expected: Breakpoint is hit Actual: Breakpoint is skipped and script contents + "Some Status" is written to terminal
Scenario 2 (PowerShell 5.1)
- Save the script from Scenario 1 to C:\temp\DebuggingTest.ps1
- Readd the breakpoint to line 3 (as indicated)
- Press F5
- Debugger starts and attaches correctly
- Press F5 to run to completion
- Run
Write-SomeStatusfrom the terminal directly - Debugger attaches to breakpoint at line 3
- Press F5 to continue and the debugger hangs (screenshot below)
Visuals
Debugger attaches when adding new Write-Host line:

Debugger hangs after calling from terminal directly:

Logs
EditorServices.log StartEditorServices.log vscode-powershell.log
Another weird thing is happening as I started testing more.
@strickdd You keep saying you "Press F5" but we really need to know: what debug configuration is this running?
Happy to provide you this information; how do I pull the debug configuration so I can provide it?
Here is my current settings.json, incase this helps:
{
"editor.find.autoFindInSelection": true,
"editor.minimap.maxColumn": 60,
"editor.mouseWheelZoom": true,
"editor.renderWhitespace": "all",
"editor.tabCompletion": "on",
"window.doubleClickIconToClose": true,
"window.newWindowDimensions": "maximized",
"window.restoreFullscreen": true,
"window.restoreWindows": "all",
"files.defaultLanguage": "powershell",
"search.usePCRE2": true,
"git.ignoreMissingGitWarning": true,
"powershell.codeFormatting.useCorrectCasing": true,
"editor.formatOnPaste": true,
"workbench.activityBar.visible": true,
"debug.openDebug": "neverOpen",
"workbench.colorTheme": "Visual Studio 2019 Dark",
"powershell.promptToUpdatePowerShell": false,
"diffEditor.ignoreTrimWhitespace": false,
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.preset": "Stroustrup",
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"powershell.codeFormatting.whitespaceBetweenParameters": true,
"powershell.codeFormatting.alignPropertyValuePairs": false,
"editor.autoSurround": "never",
"terminal.integrated.fontFamily": "Cascadia Mono PL",
"powershell.enableProfileLoading": false,
"gitlens.views.repositories.branches.layout": "list",
"vtools.autoHideSideBar": true,
"powershell.powerShellDefaultVersion": "PowerShell (x64)",
"powershell.integratedConsole.forceClearScrollbackBuffer": true,
"window.title": "${dirty}${rootName}${separator}${activeEditorShort}${separator}${appName}",
"workbench.startupEditor": "welcomePage",
"editor.detectIndentation": false,
"powershell.codeFormatting.useConstantStrings": true,
"powershell.developer.editorServicesLogLevel": "Diagnostic",
}
Happy to provide you this information; how do I pull the debug configuration so I can provide it?
In VS Code, "F5" launches your current debug configuration. You'll want to go to the debug panel and show us what you have set there. It will be one configuration out of potentially many options in your launch.json. For example, in the screenshot in the docs here it's "Launch Program" which is the value for the name field in their sample launch.json file. It may very well be a default/automatic debug configuration you're using, but the extension provides several of those (Launch File, Launch Script, Interactive Session, to name a few).
Here is what I have. Nothing but the default.

If I click the "Show all automatic debug configurations.", I get this:

Uhh @rjmholt what configuration is that using then?
Might have to ask @TylerLeonhardt
Here's the default config:
https://github.com/PowerShell/vscode-powershell/blob/64fc331380ece608a915cebc05a4485432ed0d45/src/features/DebugSession.ts#L209-L233
Ah, ok, helpful, thank you!
I'm happy to try another configuration if someone has one I can test with.
Also, not sure what's wrong because I've tried uninstalling VSCode, the extension, one, the other, and both and each time I reinstall I seem to have issues debugging.
@strickdd Can you explain what issues you have left unresolved?
For scenario 1: untitled debugging is not supported with Windows PowerShell (it doesn't have the necessary APIs), and you confirmed it does work with PowerShell 7. So you can either save your file and debug that way, or use PowerShell 7. For the "weird" issues with debugging an extant file that has unsaved changes, I would recommend saving the file. Is that not working for you?
For scenario 2: that seems to be working as expected. If you start the debugger within the PowerShell session and not using the GUI (so you ran code in the integrated console that has a breakpoint on it, or you executed Wait-Debugger, etc.), the GUI will know that it's started (which is working for you), but cannot know that it's ended (as expected, there's no Stop-Debugger nor way for it to know you will execute no more code with a breakpoint, that's the halting problem). So you'll have to manually end it (click the stop button). Is that not working for you?
If you've moved files around, I would suggest clearing all your set breakpoints, otherwise the PowerShell debugger is going to try to debug things that don't exist, and I wouldn't expect this to work well. You can execute Get-PSBreakpoint to see where the debugger has breakpoints (and it should generally match the breakpoints listed in VS Code).
Also if you're simply not saving files out of annoyance, may I suggest the VS Code setting files.autoSave.
@andschwa Scenario 1: I'll accept that it isn't supported in Windows PowerShell. We are working on upgrading to PS 7 so hopefully this is a short term annoyance. Re: the weird issue, this happens sporadically and may be because of the extant file. I'll look into the files.autoSave setting and try that out.
Scenario 2: I believe that is working for me. I don't think I've had to do that in the past (6+ months ago), but I'll live with this going forward and press the stop button.
Re: Moving things around: I didn't actually "move" anything TBH. I re-typed the contents because I forgot where I was saving the file. I'll be more cognizant of moving things though and try the Get-PSBreakpoint as suggested if I encounter an issue.
If there is a mismatch in the breakpoints listed between Get-PSBreakpoint and VSCode, what would my course of action be?
If there is a mismatch in the breakpoints listed between
Get-PSBreakpointand VSCode, what would my course of action be?
Starting the debugger through the button (or F5) should re-sync them. That sends all the breakpoints VS Code knows of across the Debug Adapter Protocol to the LSP server (PowerShell Editor Services), which then clears the breakpoints in the PowerShell session and resets them with the given breakpoints.
If all else fails, you can manually clear PowerShell's breakpoints with Get-PSBreakpoint | Remove-PSBreakpoint.
For scenario 2: that seems to be working as expected.
I think you're right and this was how it was designed to work (I was thinking of something else it seems).
That said, it may be worth considering a change here as I think that will be unexpected for most folks. In PowerShellContextService.OnDebuggerStop the startDebugger notification is sent if the debug server isn't active. If we kept trace of when we send that notification, we can send a corresponding stop notification when the current top level pipeline is completed.
I think it's possible but it seems very fragile, and I don't see much gain from it. There are certainly users who wouldn't want it to automatically stop, so then we'd need to make it configurable, and anyway the action of "click the stop button" doesn't seem to be a huge issue.
I don't feel strongly enough about it to press the issue, all I ask is that it's kept in mind when reviewing feedback. I have a feeling it's one of the things that contribute to a general perception of jank that most users would have difficulty articulating. Even with a pretty good understanding of how it all works I thought it was a bug 🤷
But yeah I agree, at face value having to hit stop or ctrl f5 every now and then is nbd
I think that's totally fair. It certainly took understanding it for it to make any sense at all, but then it became clear why it's that way and why it may not be fixable. It's that we've tied two debuggers together, and the protocol we used to do so (DAP) doesn't know the first debugger also has its own UI (the Wait-Debugger etc. commands).
and the protocol we used to do so (DAP) doesn't know the first debugger also has its own UI (the
Wait-Debuggeretc. commands).
That is a UI that we provide though. I'm probably going to over explain so please ignore what you already know and apologies:
When the engine hits a debug stop it invokes an event that the PSHost is expected to subscribe to. It's the PSHost's job handle rendering a nested repl, debug messages, and when to resume execution, etc. The PSHost in PowerShellEditorServices is what handles all that currently, and it's how we can control PowerShell's debugger via DAP in general. That's also how we start the debugger on an arbitrary stop, we just don't handle ending it as well.
Basically, if we were to add something like this here:
if (!IsDebugServerActive)
{
_didStartArbitraryDebug = true;
_languageServer?.SendNotification("powerShell/startDebugger");
}
And then something like this here:
if (IsDebugServerActive && _didStartArbitraryDebug && PromptNest.CurrentFrame.FrameType is PromptNestFrameType.Normal)
{
// Notification would need to be added
_languageServer?.SendNotification("powerShell/stopDebugger");
}
return executionResult;
Should work pretty reliably I think. Anyway, food for thought.
I came here trying to make heads or tails of the wide variety of odd behavior the 1.59.1 update seems to have brought my 5.1 debugging experience. Fairly consistently now in my module (no unnamed files) when i hit a breakpoint and then F5 to continue my integrated console hangs. This can't possibly be by design, I have tried clicking all the "stop" buttons to no avail
@liberdis do you think you might have the same issue(s) as #3539?
@SeeminglyScience what exactly is && PromptNest.CurrentFrame.FrameType is PromptNestFrameType.Normal checking, and is there an alternative? I've started an attempt to implement this and "'PromptNest.CurrentFrame' is inaccessible due to its protection level."