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.

Set-PSBreakpoint allows you to set the same breakpoint again, and again, and again

See original GitHub issue

The Set-PSBreakpoint command allows you to set a breakpoint multiple times. Most users never encounter this because if they debug and use breakpoints, they do so from Visual Studio Code or PowerShell ISE. For users who use the command line and set breakpoints that way, this behavior leads to additional breakpoints being created that are not necessary and do not add any value to their debugging experience.

Steps to reproduce

Set-PSBreakpoint -Command Get-Process
Set-PSBreakpoint -Command Get-Process
Set-PSBreakpoint -Command Get-Process

Expected behavior

  ID Script                            Line Command                           Variable                          Action
  -- ------                            ---- -------                           --------                          ------
   0                                        Get-Process

Actual behavior

  ID Script                            Line Command                           Variable                          Action
  -- ------                            ---- -------                           --------                          ------
   0                                        Get-Process

  ID Script                            Line Command                           Variable                          Action
  -- ------                            ---- -------                           --------                          ------
   1                                        Get-Process

  ID Script                            Line Command                           Variable                          Action
  -- ------                            ---- -------                           --------                          ------
   2                                        Get-Process

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.1
PSEdition                      Core
GitCommitId                    6.2.1
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Desired outcome

I would like to change this behavior such that Set-PSBreakpoint does not create duplicates, by having it look at existing breakpoints when a breakpoint is set. If an exact match is found, that breakpoint is returned to the caller. Otherwise, the new breakpoint is set and returned to the caller. There is no value in allowing multiple breakpoints that are 100% identical to be set in a debugger. In fact, graphical debuggers don’t allow you to do this, so the command line shouldn’t either.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
KirkMunrocommented, Jul 12, 2019

In my example it breaks once, but shows three triggering breakpoints that only differ by their ID when it does.

Here’s exactly what is shown in the console:

PS C:\Program Files\PowerShell\6> Get-Process
Entering debug mode. Use h or ? for help.

Hit Command breakpoint on 'Get-Process'
Hit Command breakpoint on 'Get-Process'
Hit Command breakpoint on 'Get-Process'

At line:1 char:1
+ Get-Process
+ ~~~~~~~~~~~

[DBG]: PS C:\Program Files\PowerShell\6>> $PSDebugContext.Breakpoints

  ID Script                      Line Command                     Variable                   Action
  -- ------                      ---- -------                     --------                   ------
   0                                  Get-Process
   1                                  Get-Process
   2                                  Get-Process
2reactions
bpayettecommented, Jul 11, 2019

@KirkMunro Don’t forget about actions. Each breakpoint object can have it’s own action q.e.d multiple breakpoints are necessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set-PSBreakpoint (Microsoft.PowerShell.Utility)
The Set-PSBreakpoint cmdlet sets a breakpoint in a script or in any command run in the current session. You can use Set-PSBreakpoint to...
Read more >
Enable-PSBreakpoint (Microsoft.PowerShell.Utility)
Enable -PSBreakpoint re-enables the breakpoint. Again, using the PassThru parameter we see that the value of the Enabled property is True.
Read more >
Quick and Efficient PowerShell Script Debugging with ...
Breakpoints can be created in PowerShell in one of two ways: by using the Write-Debug cmdlet, or by using the Set-PsBreakPoint cmdlet. Let's ......
Read more >
Breakpoints cannot be removed when debugger isn't running
I run Set-PSBreakpoint to set your breakpoint and then run the script; Script execution completes, debug mode ends (no more orange status bar) ......
Read more >
Understanding Debugging Breakpoints in PowerShell
To set breakpoints, we'll use the Set-PSBreakpoint command. Let's first use this command and set the line trigger to stop code execution and ......
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