vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Debugger Issues

Open strickdd opened this issue 5 years ago • 49 comments

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)

  1. Close all VSCode instances
  2. Open new instance with no folder opened
  3. Create a new PowerShell script
  4. Past in script below (do not save)
function Write-SomeStatus {
    # Breakpoint on following line
    Write-Host 'Some Status'
}

Write-SomeStatus
  1. Press F5

Expected: Breakpoint is hit Actual: Breakpoint is skipped and script contents + "Some Status" is written to terminal

Scenario 2 (PowerShell 5.1)

  1. Save the script from Scenario 1 to C:\temp\DebuggingTest.ps1
  2. Readd the breakpoint to line 3 (as indicated)
  3. Press F5
  4. Debugger starts and attaches correctly
  5. Press F5 to run to completion
  6. Run Write-SomeStatus from the terminal directly
  7. Debugger attaches to breakpoint at line 3
  8. Press F5 to continue and the debugger hangs (screenshot below)

Visuals

Debugger attaches when adding new Write-Host line: image

Debugger hangs after calling from terminal directly: image

Logs

EditorServices.log StartEditorServices.log vscode-powershell.log

strickdd avatar Aug 24 '21 18:08 strickdd

Yeah...this did not quite work. I'll see if I can figure it out but unfortunately I think it's going to be a bit more complicated than just adding that code at the end of ExecuteCommandAsync.

andyleejordan avatar Sep 02 '21 03:09 andyleejordan

NestedPromptLevel is 1 is probably better anyway.

Basically it's just checking that the current REPL isn't for a debugger stop, a remote runspace, or a nested prompt.

SeeminglyScience avatar Sep 02 '21 03:09 SeeminglyScience

!PromptNest.IsInDebugger is what we were looking for, but even with that, it's not quite working.

andyleejordan avatar Sep 02 '21 03:09 andyleejordan

Roger that, I'll take a crack at it this weekend and see if it's feasible

SeeminglyScience avatar Sep 02 '21 03:09 SeeminglyScience

I seem to be sending the notification too soon...I'll take a look in the morning. It is stopping the debugger now, just it's doing so immediately after the breakpoint is hit. So it starts and then stops.

andyleejordan avatar Sep 02 '21 03:09 andyleejordan

Yeah that might not be the best place for the check. It's possible that it's firing right after some of the pre-debugger REPL stuff like setting breakpoints. Right now we'd be setting it once it returns to the "normal" prompt in the stack, but that doesn't necessarily mean that execution is resumed (and ofc very often doesn't mean execution is finished). Maybe the check should be when ReadLine is called? Or in an execution status event handler?

SeeminglyScience avatar Sep 02 '21 03:09 SeeminglyScience

Hey...it's a-working. It just might be a bit fragile (and it needs tests).

andyleejordan avatar Sep 02 '21 20:09 andyleejordan

@strickdd Can you test out the preview extension that updated yesterday for Scenario 2? I believe I've lit that feature up, but still working on a way to thoroughly cover it in tests.

andyleejordan avatar Sep 08 '21 17:09 andyleejordan

This change got dropped in the pipeline rewrite, so I am reopening this. The good news is that I also just fixed that!

andyleejordan avatar Jan 26 '22 20:01 andyleejordan