Skip to content

how to make the debugger work consistently? #4281

Closed
@Rom265

Description

@Rom265

Prerequisites

  • I have written a descriptive issue title.
    I have searched all open and closed issues to ensure it has not already been reported.
    I have read the troubleshooting guide.
    I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
    I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
    If this is a security issue, I have read the security issue reporting guidance.

Summary

I can't get the debugger to work. Sometimes it will, sometimes it won't. The code just runs ignoring break points. I tried to follow the instructions in https://devblogs.microsoft.com/scripting/debugging-powershell-script-in-visual-studio-code-part-1/#comments but they aren't even right. They no longer describe the user interface. So, I don't know what to do. I got the "Powershell Launch Current File" into the drop down on the RUN AND DEBUG window. It seems like that worked once, but then I stopped the run part way through the script and the terminal hung on the DBG prompt. So, I closed that terminal. It popped up a message saying that it needed to be running; so, I started it again. But now, no breaking. Did I do it right, but this Powershell extension just really is broken or what?

PowerShell Version

Name                           Value
----                           -----
PSVersion                      5.1.17763.2931
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.2931
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visual Studio Code Version

1.73.1
6261075646f055b99068d3688932416f2346dd3b
x64

Extension Version

code --list-extensions --show-versions | Select-String powershell

Steps to Reproduce

open file.
set breakpoint.
type command into the terminal window and hit enter.

Visuals

No response

Logs

No response

Activity

ghost added
Needs: TriageMaintainer attention needed!
on Nov 22, 2022
andyleejordan

andyleejordan commented on Nov 22, 2022

@andyleejordan
Member

Can you try PowerShell 7? The PowerShell 5.1 support is best effort, and debugging is where it gets seriously janky (it doesn't have the debugger APIs that we use to support proper debugging like we do with PowerShell 7).

Rom265

Rom265 commented on Nov 24, 2022

@Rom265
Author

Can you try PowerShell 7? The PowerShell 5.1 support is best effort, and debugging is where it gets seriously janky (it doesn't have the debugger APIs that we use to support proper debugging like we do with PowerShell 7).

Thanks for replying, but no sadly it looks like I'll have to give up on VS Code again and go back to Powershell ISE as my only real choice for using Powershell.

TheMasterPrawn

TheMasterPrawn commented on Nov 24, 2022

@TheMasterPrawn

I have the same problem. Until PowerShell cmdlets for Azure etc support functionality that was available I am still expected to maintain code for customers in older versions of PowerShell. After moving the team to VSCODE its a massive step backwards as it took me months to get people off ISE. The latest is "Exception encountered starting EditorServices. Exception logged in D:\a_work\1\s\src\PowerShellEditorServices.Hosting\Commands\StartEditorServicesCommand.cs on line 238 in EndProcessing:"

Completely dead in the water on this

This looks like its related to some update in the ps add on

ninmonkey

ninmonkey commented on Nov 26, 2022

@ninmonkey

If there's an error, restarting the term usually resolves that.
image

Without logs, there's a bunch of different things that could have happened, we can't know what. It's not necessarily the debugger.

Re-Attach Debugger

if the debugger isn't attaching when you're running

Import-Module x -Force
DoStuff
  • Then in DoStuff place wait-debugger
  • save, run it
  • now you can delete wait-debugger
  • regular breakpoints are now working

update

When addons update, sometimes they require a reload. Until you reload, it definitely can break things. But that's not pwsh specific.

Rom265

Rom265 commented on Dec 1, 2022

@Rom265
Author

I figured it out. The problem stems from the fact that I have used Powershell a lot. This program is NOTHING LIKE Powershell ISE which I am used to. Actually, the problem is that this program is not made for Powershell and that will always be a problem. In some ways it will always be harder to use. Certainly harder to get started with. So, I expected that when I run a command from the terminal prompt, it will run. It does and that fools you because, to engage the debugger, you can ONLY USE F5 (or the icon). This means that you must create a temporary file somewhere, open it in VS Code, write the command line you need and then hit F5 there. Voila, it stops at the break point. Yes, this is very kludgy, one of the several ways Powershell presumably does not match the languages VS Code was created for.

andyleejordan

andyleejordan commented on Dec 1, 2022

@andyleejordan
Member

If you put a Wait-Debugger in the command / script-block you're running, that should start up and attach the VS Code debugger too (if it doesn't, let me know, I worked real hard to wire that up)! You should also check out the "Interactive Session" supplied default debug configuration.

andyleejordan

andyleejordan commented on Dec 1, 2022

@andyleejordan
Member

Also,

Actually, the problem is that this program is not made for Powershell and that will always be a problem.

You really hit the nail on the head about how difficult the development and maintenance of this extension is 😅

andyleejordan

andyleejordan commented on Dec 1, 2022

@andyleejordan
Member

We also have some work-in-progress to sync PowerShell breakpoints set via Set-PSBreakpoint etc. with the VS Code debugger: #4065 no ETA though.

ghost closed this as completedon Dec 2, 2022
ghost
Rom265

Rom265 commented on Dec 4, 2022

@Rom265
Author

Ah! You're a genius. ha ha I put wait-debugger; at the head of my command and then after running the command, I had to hit F5 a couple times to get past a tab that opened up called [this computer] Script Listing.ps1. And then it worked and stopped at the set break point. I haven't tried any complex breakpoints like a conditional breakpoint.

andyleejordan

andyleejordan commented on Dec 5, 2022

@andyleejordan
Member

Heck yeah! I'm glad to hear it. I definitely want you to be able to use (and enjoy using!) the extension, please let me know if you run into other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @andyleejordan@ninmonkey@TheMasterPrawn@Rom265

        Issue actions

          how to make the debugger work consistently? · Issue #4281 · PowerShell/vscode-powershell