question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debugger not started when breakpoint is set in the editor

See original GitHub issue

System Details

  • Operating system name and version: Windows Server 2012 64 bit
  • VS Code version: 1.15.0-insider
  • PowerShell extension version: 1.4.1
  • Output from $PSVersionTable: Name Value

PSVersion 5.1.14409. PSEdition Desktop PSCompatibleVersions {1.0, 2.0, BuildVersion 10.0.14409 CLRVersion 4.0.30319. WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Copy / paste the below commands into the PowerShell Integrated Terminal, and paste the output here

code -v
code : The term 'code' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the pa
th is correct and try again.
At line:1 char:1
+ code -v
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (code:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS S:\Prod> $pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      4      1      0

PS S:\Prod> code --list-extensions --show-versions
code : The term 'code' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the pa
th is correct and try again.
At line:1 char:1
+ code --list-extensions --show-versions
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (code:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Issue Description

The debugger is not started on a fresh start of vs code. Steps to reproduce the issue.

Step 1

Create file Testie.ps1 with content:

[CmdLetBinding()]
Param (
    [Parameter(Mandatory)]
    [String]$ProcessName
)
 
<# TESTs
    $TestParams = @{
        ProcessName  = 'Code'
        Verbose      = $true
    }
    &'S:\Test\Brecht\Testie3.ps1' @TestParams
#>

Write-Verbose "Script started"
Get-Process | where Name -Like "$ProcessName*"
Write-Verbose "Debugging done"

Step 2 Set a breakpoint at line 16 by clicking F9.

Step 3 Select the code in the comments and click F8. (The purpose of doing it this way is to have the parameter validation done) image

Observe that the script is completely executed without stopping at line 16. The current workaround is to run the whole script by clicking F5 and then doing step 3 again.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
MartinSGillcommented, Dec 24, 2017

I’ll try a different way of explaining what I mean. I’m using VSCode 1.19.0, which I believe is the current latest release.

In ISE:

  1. Start Editor with file (e.g. PS> ise mystuff.psm1)
  2. Set a breakpoint inside a function.
  3. In Console “Import-Module mystuff.psm1”
  4. In Console call imported function
  5. Break-point hit, execution stops in debugger

The steps as above in VSCode:

  1. Start Editor with file (e.g. PS> code mystuff.psm1) (no .vscode folder exists)
  2. Set a breakpoint inside a function.
  3. In Console “Import-Module mystuff.psm1”
  4. In Console call imported function
  5. Break-Point never hit.

I would consider this to be the “intuitive” behaviour, especially for someone coming from ISE.

Steps in VS Code to actually get it working. This is basically the I did when I was trying to figure out if I could get it working like ISE at all. Now I know how it works I can skip a few steps, but I believe this to be what someone coming from ISE is likely to also try.

Addition steps required are in bold.

  1. Start Editor with file. (e.g. PS> code mystuff.psm1) (no .vscode folder)
  2. Set a breakpoint inside a function.
  3. Select “Debug” sidebar
  4. Click on “Configure or Fix Launch.json”
  5. Error: “Please first open a folder in order to do advanced debug configuration.”
  6. Add folder my file is in.
  7. VS Code Restarts, repeat steps 1 to 5
  8. Default launch.json is created
  9. Select “Powershell Interactive Session” from Debug Configurations
  10. Start Debug
  11. In Console “Import-Module mystuff.psm1”
  12. In Console call imported function
  13. Breakpoint Hit

While I am sure there are limitations in what is possible in VS Code, given it’s a generic editor and not specifically a powershell editor, it surely must be possible to reduce the number of steps.

Even if you remember to open a folder and not a file directly, it’s still 10 steps, as opposed to the 5 in ISE before you can hit a breakpoint when using the console.

If there’s an easier way to do this, or a setting that I’m missing somehow, please let me know.

0reactions
hanpqcommented, Jun 14, 2018

I’ve tried to read up on launch configurations but I’ve not figured the following out; would it be possible to “chain” two debugging configurations into one launch-configuration?

Lets say I have a script containing a function definition. I hit F5 and the launch configuration launches the “Powershell Launch Current File” to re-define the function in the runspace and directly after starts and leaves the debugger running according to the “Powershell Interactive Session”-launch configuration which would allow me to call the function from the integrated terminal only running one launch configuration instead of two different launch configurations after one another?

Does that make sense? 😃

(This would be a temporary solution until this enhancement gets implemented (if launch configurations support this “feature” that is)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Breakpoints in the Visual Studio Debugger
"No Symbols have been loaded for this document" ... Go to the Modules window (Debug > Windows > Modules) and check whether your...
Read more >
Visual Studio Code - Node debugger breakpoints not being hit
If I set a breakpoint on a file I open through the VSCode editor the breakpoint is greyed out and when I hover...
Read more >
Breakpoints do not move down as you add lines to text editor
2. Add a class with some a few methods and a few lines in each method. 3. Set a break point. 4. Run...
Read more >
Breakpoints | IntelliJ IDEA Documentation - JetBrains
Set exception breakpoints · Click View Breakpoints View Breakpoints button in the left part of the Debug tool window or press Ctrl+Shift+F8 ....
Read more >
Using breakpoints - IBM
Breakpoints must be installed before they will suspend execution. It is possible to add a breakpoint that is not valid for the current...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found