Skip to content
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

VS Code Powershell debugger hanging - PS 7 with Powershell extension #3415

Closed
bkarlow-optimo opened this issue Jun 15, 2021 · 35 comments
Closed
Assignees
Labels
Area-Debugging Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.

Comments

@bkarlow-optimo
Copy link

Issue Description

I am experiencing a problem with... VSCode debugger with Powershell integrated console set to Powershell Core version 7.1.3. The debugger launches, finds the first breakpoint in the entry point PS1 script file, executes to the first breakpoint - all good.

Immediately upon stepping over the breakpoint (F10), debugger hangs, terminal is non-responsive.

This MAY be related to #3410 , but unclear.

This is reproduceable.

VS Code settings:

{
"powershell.powerShellAdditionalExePaths": [
{
"exePath": "C:\Program Files\PowerShell\7\pwsh.exe",
"versionName": "PowerShell 7"
}
],
"powershell.powerShellDefaultVersion": "PowerShell 7",
"terminal.integrated.automationShell.windows": "C:\Program Files\PowerShell\7\pwsh.exe",
"terminal.external.windowsExec": "C:\Program Files\PowerShell\7\pwsh.exe",
"terminal.integrated.automationShell.osx": "",
"terminal.integrated.automationShell.linux": "",
"debug.javascript.autoAttachFilter": "smart",
"vs-kubernetes": {
"vscode-kubernetes.kubectl-path.windows": "C:\Users\genericuser\.vs-kubernetes\tools\kubectl\kubectl.exe",
"vscode-kubernetes.minikube-path.windows": "C:\Users\genericuser\.vs-kubernetes\tools\minikube\windows-amd64\minikube.exe",
"vscode-kubernetes.helm-path.windows": "C:\Users\genericuser\.vs-kubernetes\tools\helm\windows-amd64\helm.exe"
},
"mssql.connections": [
{
"server": "{{put-server-name-here}}",
"database": "{{put-database-name-here}}",
"user": "{{put-username-here}}",
"password": "{{put-password-here}}"
}
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"path": "C:\Program Files\PowerShell\7\pwsh.exe"
},
"Command Prompt": {
"path": [
"${env:windir}\Sysnative\cmd.exe",
"${env:windir}\System32\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
},
"PowerShell 7": {
"path": "C:\Program Files\PowerShell\7\pwsh.exe",
"args": []
}
}
}

Attached Logs

EditorServices.log
StartEditorServices.log
vscode-powershell.log

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.19043
VSCode 1.57.0
PowerShell Extension Version 2021.5.1

PowerShell Information

Name Value
PSVersion 7.1.3
PSEdition Core
GitCommitId 7.1.3
OS Microsoft Windows 10.0.19043
Platform Win32NT
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.10032.0 6.0.0 6.1.0 6.2.0 7.0.0 7.1.3
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
armview bencoleman 0.4.5
azure-account ms-vscode 0.9.8
azure-pipelines ms-azure-devops 1.188.1
azurecli ms-vscode 0.5.0
azurerm-vscode-tools msazurermtools 0.15.1
debugger-for-chrome msjsdiag 4.12.12
markdown-all-in-one yzhang 3.4.0
mssql ms-mssql 1.10.1
npm-intellisense christian-kohler 1.3.1
powershell ms-vscode 2021.5.1
remote-containers ms-vscode-remote 0.183.0
remote-wsl ms-vscode-remote 0.56.5
rest-client humao 0.24.5
vscode-aks-tools ms-kubernetes-tools 0.0.8
vscode-apimanagement ms-azuretools 1.0.2
vscode-azureappservice ms-azuretools 0.22.0
vscode-azurefunctions ms-azuretools 1.4.0
vscode-azureresourcegroups ms-azuretools 0.4.0
vscode-azurestorage ms-azuretools 0.12.1
vscode-azurevirtualmachines ms-azuretools 0.4.0
vscode-bicep ms-azuretools 0.4.63
vscode-commons redhat 0.0.6
vscode-cosmosdb ms-azuretools 0.16.0
vscode-docker ms-azuretools 1.13.0
vscode-dotnet-runtime ms-dotnettools 1.1.0
vscode-eslint dbaeumer 2.1.23
vscode-kubernetes-tools ms-kubernetes-tools 1.3.3
vscode-markdownlint DavidAnson 0.42.1
vscode-node-azure-pack ms-vscode 0.2.1
vscode-npm-script eg2 0.3.22
vscode-yaml redhat 0.19.2
@ghost ghost added the Needs: Triage Maintainer attention needed! label Jun 15, 2021
@strickdd
Copy link

strickdd commented Jun 22, 2021

I'm having a very similar issue, but the debugger never hits the first breakpoint and I'm using PS 5.1. It shows the toolbar (screenshot below), but never hits the breakpoint and the terminal hangs - can't scroll or type.

Debug Toolbar
image

Simple Script

function Get-SomeVal {
    # Breakpoint on this line
    'Some Val' | Write-Output
}

Get-SomeVal

Logs
EditorServices.log
PowerShellEditorServices.log
StartEditorServices.log
vscode-powershell.log

Code Version

PS:\>code -v
1.57.1
507ce72a4466fbb27b715c3722558bb15afa9f48
x64

Extensions

Editor Services Version

PS:\>$psEditor.EditorServicesVersion


Major  Minor  Build  Revision
-----  -----  -----  --------
2      4      4      0       

PSVersion Table

PS:\>$PSVersionTable


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

UPDATE
On a whim, I switched to PS 7.1 and it now hits the breakpoint, but once I step over it, I am taken to a "weird" file location in debug mode (screenshot below). Once I hit "F5" to continue, the terminal just hangs and the debug tollbar stays. Clicking the "Stop" on the debug toolback does nothing. I have to kill the terminal session and let it restart to proceed.

"Weird" file after F10:
image

Hanging debugger:
image

@strickdd
Copy link

Not sure if it matters, but highlighting code and pressing F8 runs that section of code without issue.

@andyleejordan
Copy link
Member

Hey, just an FYI we are actively working on PowerShell/PowerShellEditorServices#1295 which re-wires the debugger. Hence we are prioritizing that rather than fixing issues with the existing implementation. We intend to have that in the next preview, and then we will see if this problem goes away 😄

@andyleejordan andyleejordan added Area-Debugging Issue-Bug A bug to squash. Needs: Fix Verification Please verify the fix for us! and removed Needs: Triage Maintainer attention needed! labels Jun 22, 2021
@bkarlow-optimo
Copy link
Author

@strickdd -
Thanks for the feedback. I'm glad I'm not the only one experiencing similar issues.

@andschwa -
Thank you for the feedback. Understood regarding focus on new implementation of the debugger, and that is great news. I still think it important to raise these issues so others are aware they are not alone.

Any target release date for the new debugger? I read through the referenced thread and saw a mentioned target date of EOY 2020, which obviously is no longer accurate.

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jun 23, 2021
@andyleejordan
Copy link
Member

The whole year of 2020 was...a mess, for everyone (also I was not yet a maintainer here). We are planning to get it into the next release, hopefully end of this month, potentially next month, but not much later than that!

@bkarlow-optimo
Copy link
Author

@andschwa - Thank you for the update. I suppose I can work around this issue for now. Regards.

@peetrike
Copy link

The problem might be connected to PSReadline v2.2.0-Beta3 (reported in PowerShell/PSReadLine#2616)

@andyleejordan
Copy link
Member

If that is the case, could @peetrike and @bkarlow-optimo try ensuring you only have PSReadLine 2.1.0 on the machine?

#3393 (comment)

I will try to prioritize this: PowerShell/PowerShellEditorServices#1493

@strickdd
Copy link

I know I wasn't in the list, but in case it helps... here are my available PSReadline modules.
image

@bkarlow-optimo
Copy link
Author

I am only on version 2.1.0. See below:

PS C:> Get-Module PSReadline -ListAvailable

Directory: C:\program files\powershell\7\Modules

ModuleType Version PreRelease Name PSEdition ExportedCommands


Script 2.1.0 PSReadLine Desk {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remove-PSReadLineKeyHandler, Get-PSReadLineOption…}

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version PreRelease Name PSEdition ExportedCommands


Script 2.0.0 beta2 PSReadline Desk {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remove-PSReadLineKeyHandler, Get-PSReadLineOption…}

@hemingsent
Copy link

If that is the case, could @peetrike and @bkarlow-optimo try ensuring you only have PSReadLine 2.1.0 on the machine?

#3393 (comment)

I will try to prioritize this: PowerShell/PowerShellEditorServices#1493

This was indeed my issue. I removed the PSReadline v2.2.0-Beta3 and now it is working properly.

@thomglow
Copy link

thomglow commented Jul 8, 2021

Uninstalling PSReadline v2.2.0-Beta3 fixed my issue with the debugger hanging also.

@andyleejordan
Copy link
Member

I'm dropping a new Preview of the release this week that will only use the bundled version of PSReadLine, and so should avoid this issue entirely!

@andyleejordan andyleejordan self-assigned this Jul 13, 2021
@andyleejordan andyleejordan removed the Needs: Maintainer Attention Maintainer attention needed! label Jul 13, 2021
@andyleejordan andyleejordan added this to the Committed-vNext milestone Jul 13, 2021
@andyleejordan
Copy link
Member

@thomglow Can you try the 2021.7.0-preview version ("PowerShell Preview") on the marketplace, install PSReadLine v2.2.0-beta3 on your machine, and verify that this issue is fixed? The preview extension has logic now that only loads the bundled PSReadLine 😁

@hemingsent
Copy link

hemingsent commented Jul 20, 2021

@andschwa I did test mine without the beta of PSReadLine and it still hangs for me. I will get some more information here shortly and edit this post.

PS L:\powershell> code -v

1.58.2
c3f126316369cd610563c75b1b1725e0679adfb3
x64

PS L:\powershell> code --list-extensions --show-versions

[email protected]
[email protected]

PS L:\powershell> $psEditor.EditorServicesVersion

Major Minor Build Revision


2 4 6 0

PS L:\powershell> $PSVersionTable

Name Value


PSVersion 7.1.3
PSEdition Core
GitCommitId 7.1.3
OS Microsoft Windows 10.0.19043
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jul 20, 2021
@andyleejordan
Copy link
Member

Oops, actually I mean @hemingsent, whose issues did have to do with PSReadLine beta3. I think your issue is different.

@andyleejordan andyleejordan removed the Needs: Maintainer Attention Maintainer attention needed! label Jul 20, 2021
@peetrike
Copy link

peetrike commented Jul 21, 2021

Can you try the 2021.7.0-preview version ("PowerShell Preview") on the marketplace, install PSReadLine v2.2.0-beta3 on your machine, and verify that this issue is fixed?

the 2021.7.0-preview works with PSReadLine v2.2.0-beta3. Debugger starts and works normally

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jul 21, 2021
@andyleejordan
Copy link
Member

Yay, thank you!

@andyleejordan
Copy link
Member

I'm going to leave this issue open as @bkarlow-optimo original reported issue is, to my knowledge, unrelated to the PSReadLine beta3 incompatibility issue.

@andyleejordan andyleejordan removed Needs: Maintainer Attention Maintainer attention needed! Needs: Fix Verification Please verify the fix for us! labels Jul 21, 2021
@strickdd
Copy link

Just installed 2021.7.0-preview with PSReadLine v2.2.0-beta3 and tested. Debugger hangs for me still. The debug toolbar comes up, but the breakpoint is never hit. I'm using PS 5.1. The terminal locks up and has to be killed/restarted to interact with it again.

It looks like PSReadline 2.1.0 was loaded initially so I removed that and manually loaded PSReadline 2.2.0.

After manually loading 2.2.0, I run and get an error in the PowerShell Editor Services log (below). The weird thing is that it mentions "untitled:Untitled-2", but the file I'm trying to debug is "GroupMembershipRecurseWithCreds.ps1".

I'm happy to run any additional tests or provide additional details.

[Warn  - 9:48:21 AM] Microsoft.PowerShell.EditorServices.Services.WorkspaceService: Failed to get file for fileUri: 'untitled:Untitled-2' | 
[Error - 9:48:21 AM] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Execution of the following command(s) completed with errors:

    Microsoft.PowerShell.Utility\Set-PSBreakpoint -Command 

 | 
[Warn  - 9:48:21 AM] Microsoft.PowerShell.EditorServices.Services.PowerShellContextService: Runtime exception occurred while executing command | 

Additional Screenshots/Info
image

image

PS C:\> $PSVersionTable


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

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jul 22, 2021
@andyleejordan
Copy link
Member

Sounds like your issue @strickdd is also (unfortunately) not the PSReadLine issue.

@UselessGuru
Copy link

UselessGuru commented Jul 24, 2021

I am the co-developer of https://github.com/Minerx117/NemosMiner/tree/testing and I've got a slightly different problem with the debugger which might be related.

Executing

Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object System.Windows.Forms.Form

breaks the debugger - the breakpoint gets hit, but the relevant code will not get highlighted.

Sample code to reproduce the problem:

Function MyFunction { 
    Param(
        [Parameter(Mandatory = $false)]
        [String]$text
    )

    Write-Host $Text
    Start-Sleep -Seconds 1
}

MyFunction "Before Add-Type & Form"

Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object System.Windows.Forms.Form

MyFunction "After Add-Type & Form"
  1. Add a breakpoint to line 8 (Start-Sleep -Seconds 1)
  2. Start debugging.
  3. The first call to MyFunction prints 'Before Add-Type & Form' and the debugger highlights line 8.
  4. Continue the script with 'F5'
  5. The second call to MyFunction prints 'After Add-Type & Form'. The breakpoint gets hit, but the debugger does not highlight anything.

Latest working combo:
pwsh 7.2.0-preview5 or older
powershell extension 2021.2.2 or older

Upgrading pwsh to -preview7 or later breaks the debugger
Upgrading the powershell extension to a newer version (incl. preview 2021.7.0) breaks the debugger

Any ideas?

@andyleejordan
Copy link
Member

Yes, we seem to have a number of issues right now around the use of System.Windows.Forms. I need to (or someone else, if you're willing) debug through PowerShell Editor Services to see if we messed up any async calls. Most likely we need to ensure that .ConfigureAwait(false) is used on every call, otherwise the threads get mixed up since Forms brings in its own threads too. A process dump of your issue would be quite helpful!

@andyleejordan andyleejordan removed the Needs: Maintainer Attention Maintainer attention needed! label Jul 27, 2021
@UselessGuru
Copy link

UselessGuru commented Jul 29, 2021

I need to (or someone else, if you're willing) debug through PowerShell Editor Services

I am pleased to help - can you give exact instructions?
I know how to debug Powershell. However I do not (yet) understand 'PowerShell Editor Services'. Any links to prepare myself?

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jul 29, 2021
@AfanasievAA
Copy link

AfanasievAA commented Jul 30, 2021

I have same issue.

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$test = New-Object "System.Windows.Forms.Form"
Write-Host "OK"

After breakpoint (line 2) gets hit, pressing F10 reproduces a problem (debugger does not highlight anything and hungs). If you then hit F11 - script continues (writes "OK" to host) but debugger hungs anyway.

Update: I've rolled back to version 1.51.1 of Visual Studio and it works now.

@andyleejordan
Copy link
Member

andyleejordan commented Jul 30, 2021

I am pleased to help - can you give exact instructions?
I know how to debug Powershell. However I do not (yet) understand 'PowerShell Editor Services'. Any links to prepare myself?

@UselessGuru Your script has been quite useful, I spent yesterday debugging! I've got things a little more stable (you can now exit the debugger even after it "hangs" at that breakpoint, which didn't seem to be working at first).

It's perhaps a little painful to get this debugged, you end up with three concurrent debugging sessions. Before getting to that point, if you're interested, you can get setup just debugging PSES and the extension following these instructions.

@rjmholt
Copy link
Contributor

rjmholt commented Aug 3, 2021

See also: #2352

@andyleejordan
Copy link
Member

@UselessGuru @AfanasievAA (and anyone else with issues debugging a PowerShell script which uses an object from Systems.Windows.Forms), could you test the dev build uploaded in the linked comment and let me know if the issue is resolved? Thank you! #3394 (comment)

@bkarlow-optimo is your issue the same as theirs, or separate?

@AfanasievAA
Copy link

AfanasievAA commented Aug 10, 2021

I've quick tested it. It works! No more debugger fails. Used Visual Studio Code 1.60.0 insider (x64) with your extension.

Thanx for fixing it! )

@UselessGuru
Copy link

UselessGuru commented Aug 10, 2021

could you test the dev build uploaded in the linked comment

I've quick tested it. It works! VSC 1.59 & PWSH 7.2-Preview8
Thank you for fixing it.

@andyleejordan
Copy link
Member

Hooray! It might be a bit to get this fix into a proper release. The bug was in OmniSharp, so I'll need to get a PR accepted into that library, get them to do a release, and then pull that into PSES and the extension. But it's solved 🥳

@andyleejordan
Copy link
Member

@bkarlow-optimo and @strickdd I'm not certain your issues were the same root cause, but would you test the dev build posted in #3394 (comment) so I know?

@andyleejordan
Copy link
Member

@bkarlow-optimo and @strickdd I'm not certain your issues were the same root cause, but would you test the dev build posted in #3394 (comment) so I know?

Since my best guess is that this was related to the threading issues within PSES and OmniSharp, and since those are now fixed and merged, I'm going to mark this issue as resolved. Please wait for the next update to the extension to roll out (no later than Monday) and see if this has been fully resolved for you. If not, since this thread got long and covered several problems, please open a new issue.

@andyleejordan andyleejordan added Resolution-Fixed Will close automatically. and removed Needs: Fix Verification Please verify the fix for us! labels Aug 19, 2021
@ghost ghost closed this as completed Aug 19, 2021
@ghost
Copy link

ghost commented Aug 19, 2021

This issue has been marked as fixed. It has been automatically closed for housekeeping purposes.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Debugging Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.
Projects
None yet
Development

No branches or pull requests

9 participants