PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.71k stars 492 forks source link

Interactive debugging breaks when the console is set to hide on startup and also use temporary consoles for debugging #2795

Closed vexx32 closed 1 year ago

vexx32 commented 4 years ago

System Details

System Details Output


### VSCode version: 1.46.1 cd9ea6488829f560dc949a8b2fb789f3cdc05f5d x64

### VSCode extensions:
bierner.markdown-emoji@0.0.9
CoenraadS.bracket-pair-colorizer-2@0.1.4
DavidAnson.vscode-markdownlint@0.36.1
donjayamanne.githistory@0.6.5
dracula-theme.theme-dracula@2.22.1
eamodio.gitlens@10.2.2
GitHub.vscode-pull-request-github@0.17.0
Hyzeta.vscode-theme-github-light@7.14.2
johnpapa.vscode-peacock@3.7.2
johnpapa.winteriscoming@1.4.3
k--kato.docomment@0.1.13
karigari.chat@0.35.0
loilo.snazzy-light@1.1.7
ms-azure-devops.azure-pipelines@1.170.0
ms-dotnettools.csharp@1.22.1
ms-vscode-remote.remote-wsl@0.44.4
ms-vscode.azure-account@0.8.11
ms-vscode.cpptools@0.28.3
ms-vscode.powershell-preview@2020.6.1
ms-vscode.wordcount@0.1.0
ms-vsliveshare.vsliveshare@1.0.2427
ms-vsts.team@1.161.0
msnilshartmann.blue-light@0.0.8
oderwat.indent-rainbow@7.4.0
reflectiondm.classynaming@1.2.0
samlazrak.vegetation@1.1.0
Shan.code-settings-sync@3.4.3
streetsidesoftware.code-spell-checker@1.9.0
swiip.sunset-theme@0.9.2
thierrymichel.vscode-gitmoji-snippets@3.2.0
twxs.cmake@0.0.17
vitaliymaz.vscode-svg-previewer@0.5.2
wingrunr21.vscode-ruby@0.27.0
yzhang.markdown-all-in-one@3.1.0

### PSES version: 2.2.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.3
PSEdition                      Core
GitCommitId                    7.1.0-preview.3
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

Issue Description

The interactive debugging experience appears to be completely broken. These probably could be separate issues, so feel free to split them out, but they're all ultimately related and I really just want to fix the issue I'm currently trying to debug more than I really wanna spend hours debugging the issues in the extension I'm currently butting heads with.

Sincere apologies in advance in case my current frustration colours any of this, I've tried to be as detailed as I can manage at the moment, but ultimately I'm trying to debug an issue in my own code, so it's been a bit frustrating running into issues with the extension at the same time, especially for configurations that previously worked very intuitively and now don't seem to work at all.

Update:

Did a bit of poking around and realized what the underlying issue is here. These two settings don't work together:

  • PowerShell > Debugging: Create Temporary Integrated Console (ON)
  • PowerShell > Integrated Console: Show on Startup (OFF)

If you have this configuration, whenever you try to start a debugging session, the wrong console is exposed and focused -- the main integrated console is shown instead of the new temporary console. As a result, nothing seems to work, because the extension is still managing the debug session from the temporary session instead of the one it's actually showing.

/cc @rjmholt @TylerLeonhardt

Things I have tried:

Using the PowerShell Interactive Session or PowerShell Attach Interactive Session Runspace default debug configurations

The issue here seems to be that breakpoints are completely ignored. I can run commands in the interactive console, but no breakpoints I set in the VS Code UI are ever hit. For full clarity, I'm setting breakpoints in the files for my module functions, then importing the module in the interactive console and trying to run commands and hit the breakpoints from there.

To my memory, this did used to work somewhere around a few months back without an issue.

Using the PowerShell Attach to Host Process to attach to another Pwsh console and running commands in there

This is so far the best experience I've had recently and it's still very broken. Breakpoints are hit and I can step through easily, this is nice. However, in the Variable view pane in the sidebar, complex objects other than dictionary types like hashtables are apparently serialized to string, so all I can see is the type name and none of the property information, so I have very limited visibility as to what's actually going on.

Using the PowerShell Launch Current File / PowerShell Launch Script configurations

This seems to work most consistently and works fairly well, but in a lot of cases I want to be debugging my module functions, so I need to put all the commands I want to try out in a new file, which makes for (imo) a very clunky debugging experience, as I need to restart the debug session every time I want to try something else.

To remedy this, I tried to add a $host.EnterNestedPrompt() to the script to let me drop into the interactive console and work from there, running module commands myself so I can debug from there. The extension seems to be running all debugging in a background runspace rather than the "Integrated" console (so... it's not Integrated to a useful degree at all anymore, apparently!) and so the EnterNestedPrompt() call simply pauses execution with no possible way to resume it. No prompt is shown in the interactive console, so I can only conclude it's not running in the main integrated console runspace, which makes things very unintuitive.

Additionally, in this mode I don't get any output in the Integrated Console, which is usually still useful even when debugging. Not sure when that changed but it makes the debugging experience feel significantly more "flying blind" than I would like, it's more obtuse than littering my code with Write-Host (which I really hate to do, but would feel more intuitive than this experience currently does).

Attached Logs

Logs

Launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "PowerShell Launch Script",
            "type": "PowerShell",
            "request": "launch",
            "script": "./Start-DebugSession.ps1",
            "cwd": "${workspaceFolder}"
        },
        {
            "name": "PowerShell: Launch Current File",
            "type": "PowerShell",
            "request": "launch",
            "script": "${file}",
            "cwd": "${file}"
        },
        {
            "name": "PowerShell Interactive Session",
            "type": "PowerShell",
            "request": "launch",
            "cwd": ""
        },
        {
            "name": "PowerShell Attach Interactive Session Runspace",
            "type": "PowerShell",
            "request": "attach",
            "processId": "current"
        },
        {
            "name": "PowerShell Attach to Host Process",
            "type": "PowerShell",
            "request": "attach",
            "runspaceId": 1
        }
    ]
}
SydneyhSmith commented 4 years ago

Thanks @vexx32 really appreciate you opening this issue and being do detailed, unfortunately we were not able to reproduce interactive debugging not functioning properly so as you mentioned logs would be very helpful--instructions for how to do that are here

vexx32 commented 4 years ago

Did a bit of poking around and realized what the underlying issue is here. These two settings don't work together:

If you have this configuration, whenever you try to start a debugging session, the wrong console is exposed and focused -- the main integrated console is shown instead of the new temporary console. As a result, nothing seems to work, because the extension is still managing the debug session from the temporary session instead of the one it's actually showing.

This... explains a lot. 😂

rjmholt commented 4 years ago

Hmmm, I think we've discussed both the settings and the implementation for the temp console, and I'd personally be happy to improve how it all works once other work is out of the way

vexx32 commented 4 years ago

Thanks, that'd be awesome! 💖

If it helps, logs from a quick run through of the problem are attached. 😁 1594159755-2a72e192-4b06-449d-821a-1f1042b763891594158464672.zip

EDIT: Updated the original issue post with the above info & logs as well so it's all in one place.

andyleejordan commented 1 year ago

Hello! The latest code is available in the PowerShell Preview for VS Code, and includes a myriad of fixes. Could you verify if this issue still reproduces using the preview extension? Please note that this preview is likely to include other bugs, and you should feel free to file new issues for those so we can work through them. Thanks again!

andyleejordan commented 1 year ago

Going to assume it's no longer an issue, thanks!