Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to make the debugger work consistently? #4281

Closed
6 tasks done
Rom265 opened this issue Nov 22, 2022 · 11 comments
Closed
6 tasks done

how to make the debugger work consistently? #4281

Rom265 opened this issue Nov 22, 2022 · 11 comments
Labels
Area-Debugging Issue-Discussion Let's talk about it. Resolution-Answered Will close automatically.

Comments

@Rom265
Copy link

Rom265 commented Nov 22, 2022

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

@Rom265 Rom265 added the Issue-Bug A bug to squash. label Nov 22, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 22, 2022
@andyleejordan
Copy link
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
Copy link
Author

Rom265 commented Nov 24, 2022

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
Copy link

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
Copy link

ninmonkey commented Nov 26, 2022

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.

@andyleejordan andyleejordan added Issue-Discussion Let's talk about it. Area-Debugging and removed Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Dec 1, 2022
@Rom265
Copy link
Author

Rom265 commented Dec 1, 2022

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
Copy link
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
Copy link
Member

andyleejordan commented Dec 1, 2022

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
Copy link
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.

@andyleejordan andyleejordan added the Resolution-Answered Will close automatically. label Dec 1, 2022
@ghost ghost closed this as completed Dec 2, 2022
@ghost
Copy link

ghost commented Dec 2, 2022

This issue has been marked as answered and has not had any activity in a day. It has been automatically closed for housekeeping purposes.

@Rom265
Copy link
Author

Rom265 commented Dec 4, 2022

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
Copy link
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.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Debugging Issue-Discussion Let's talk about it. Resolution-Answered Will close automatically.
Projects
None yet
Development

No branches or pull requests

4 participants