Powershell debugger hangs stepping over a script invocation
See original GitHub issueIssue 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% |
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:27 (9 by maintainers)
Top Results From Across the Web
Use the PowerShell Debugger to Troubleshoot Scripts
Debugging a Windows PowerShell script often involves setting a breakpoint, ... The skipped statements are executed, but not stepped through.
Read more >about Debuggers - PowerShell | Microsoft Learn
Debugger Commands · s , StepInto : Executes the next statement and then stops. · v , StepOver : Executes the next statement,...
Read more >How to Debug Scripts in Windows PowerShell ISE
Press SHIFT + F5 or, on the Debug menu, click Stop Debugger, or, in the Console Pane, type Q and then press ENTER...
Read more >Debugging PowerShell script in Visual Studio Code – Part 1
First look at the PowerShell Debugger in Visual Studio Code · Continue / Pause – F5 · Step Over – F10 · Step...
Read more >Understanding PowerShell Script Debugging
Debugging the script ; Set-PSBreakpoint. Sets breakpoints on lines, variables, and commands ; Get-PSBreakpoint. Gets breakpoints in the current ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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-Host
line, 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: uninitialized
or 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.