vscode-powershell: Powershell debugger hangs stepping over a script invocation
Issue Type: Bug
- Open a script with the following contents
Set-StrictMode -Version 5
$ErrorActionPreference = "Stop"
. $PSScriptRoot\test2.ps1
"hello 3"
- In test2.ps1, put literally anything (e.g. “hello from test2.ps1”, or even blank or non-existant).
- Put a breakpoint on line 3 (test2.ps1 invocation)
- Hit F5
- When it breaks hit F10
Result: debugger will never return. You have to stop it and restart the integrated powershell instance.
Note: If either of the first two lines are commented out, i.e. without either Set-StrictMode OR $EAP = “Stop”, it seems to work The combination causes fits.
Note 2: If there are no breakpoints, it seems to work then as well.
Extension version: 2020.4.0 VS Code version: Code 1.45.1 (5763d909d5f12fe19f215cbfdd29a91c0fa9208a, 2020-05-14T08:27:35.169Z) OS version: Windows_NT x64 10.0.19635
System Info
| Item | Value |
|---|---|
| CPUs | Intel® Core™ i7-8700K CPU @ 3.70GHz (12 x 3696) |
| GPU Status | 2d_canvas: enabled flash_3d: enabled flash_stage3d: enabled flash_stage3d_baseline: enabled gpu_compositing: enabled multiple_raster_threads: enabled_on oop_rasterization: disabled_off protected_video_decode: enabled rasterization: enabled skia_renderer: disabled_off_ok video_decode: enabled viz_display_compositor: enabled_on viz_hit_test_surface_layer: disabled_off_ok webgl: enabled webgl2: enabled |
| Load (avg) | undefined |
| Memory (System) | 31.78GB (15.85GB free) |
| Process Argv | –folder-uri file:///c%3A/repos/devdir |
| Screen Reader | no |
| VM | 0% |
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 27 (7 by maintainers)
I have had this issue today as well.
After looking at the log, I realized what caused it - at least in my case.
In my case, I had a variable in the watch window, which wasn’t initialized.
For example, I can run the following script to produce the issue:
With my watch set like this:
I can set a breakpoint on the first line and step through the script. As soon as I’ve stepped over the first two lines and try to step to the
Write-Hostline, the debugger freezes.StrictMode version 1.0 and onwards lists the following:
So I guess setting any version of StrictMode combined with
$ErrorActionPreference='Stop'will cause issues when setting a watch on a variable that doesn’t exist.Here’s what I saw in my log that helped me spot the issue:
It would be nice to have a fix for this. It would be great for the watch to check if the variable exists first, and if not, just write something like
$Name: uninitializedor something like that, rather than blindly trying to read it and getting locked up. 😄This is not a bad idea at all, I’ll see what I can do.
We’ll come back to this when the debugger implementation is revamped (in https://github.com/PowerShell/PowerShellEditorServices/issues/1295).
@johndog some next steps:
It looks like the log snippet you posted might be involved. It may be that strict mode prevents running something behind the scenes in the debugger.
I did try to reproduce this just now on my Windows (10.0.19041) machine and wasn’t able to in PowerShell 7.1, 7 or 5.1, so definitely worth trying the preview extension. Also worth determining if this always happens, or only sometimes.
It uses whichever of the PowerShells installed on your system you’ve got it configured to use. From your log snippet, this is currently PS 7.1 on your machine. You can change this by clicking on the little PowerShell icon/version in the lower right-hand corner of the VSCode window.
This might have something to do with it. From EditorServicesLog:
Does the powershell extension use pwsh or powershell?