11

I'm debugging an ASP.NET Website with C# in Visual Studio. When I set a breakpoint (during debug), over time, the created breakpoint will accumulate many child breakpoints. (See here.)
Now, sometimes when I remove a breakpoint by clicking the red glyph, the breakpoint will still be hit the next time the line is executed, because the child breakpoints persisted.

Removing the breakpoint in the breakpoint window will resolve the problem, but it's annoying to find the correct breakpoint(s) when you have many set. Also, the removal of a breakpoint with many children is quite a slow operation.

So to get to the question, can I disable this creation of child breakpoints, or is there a way to quickly remove all children?
Alternative solutions are appreciated!


Please note that this isn't a duplicate of this: Question on how to remove a Visual Studio Breakpoint, because I'm asking how to deal with the child breakpoints. (Although our intended goal is the same.)

Community
  • 1
  • 1
Protector one
  • 6,926
  • 5
  • 62
  • 86
  • Mmmm, why are you so sure that your question is not a duplicate? Seems to me like you just had a better idea of how to ask the question. In any case, your answer is definitely on the [Microsoft Connect page ref'd by that post](http://connect.microsoft.com/VisualStudio/feedback/details/391642/permanently-remove-a-breakpoint-in-visual-studio-during-debugging) – sq33G Nov 03 '11 at 11:30
  • "Better" indicates it is different; thus not a duplicate. :) Also, if this question would generate different answers, would that not also validate its uniqueness? – Protector one Nov 03 '11 at 11:41
  • When there are answers, we'll talk ;) – sq33G Nov 03 '11 at 11:56
  • So have you tried the answer of the not-duplicate question? What causes that answer to not apply to your question? – C.Evenhuis Nov 03 '11 at 12:43
  • @C.Evenhuis: Yes those solutions work, but both are annoying. I already explained why this is the case for removing breakpoints from the breakpoint window. Stopping the debug session is annoying as well, because resuming debug requires recompiling. The answer doesn't apply here, because the question is different, even though the problem is the same. – Protector one Nov 03 '11 at 13:01
  • 1
    I don't think Visual Studio offers less-annoying alternatives, perhaps a custom add-in could be created to assist in disabling child breakpoints, but that seems a little far-fetched. – C.Evenhuis Nov 03 '11 at 13:51
  • +1 for posting something that I don't remember seeing on the not-a-duplicate – sq33G Nov 03 '11 at 21:13

3 Answers3

2

The following code can be used as a macro to remove all the child breakpoints.

Sub RemoveChildBreakpoints()
    Dim i As Integer
    Dim len As Integer
    Dim debugger As EnvDTE.Debugger = DTE.Debugger
    Dim children As EnvDTE.Breakpoints
    For Each bp As EnvDTE.Breakpoint In debugger.Breakpoints
        children = bp.Children
        len = children.Count
        For i = len To 1 Step -1
            children.Item(i).Delete()
        Next
    Next
End Sub

It's still insanely slow if you have many breakpoints, so it's best to do run it on a regular basis if you're having a problem with child breakpoints.

Protector one
  • 6,926
  • 5
  • 62
  • 86
1

The following code can be used as a macro to remove the breakpoint on the currently selected line. (Note that Visual Studio automatically selects the line of a breakpoint when it is hit.)

Sub RemoveBreakPoint()
    Dim debugger As EnvDTE.Debugger = DTE.Debugger
    Dim children As EnvDTE.Breakpoints
    Dim sel As Integer = DTE.ActiveDocument.Selection.ActivePoint.Line
    For Each bp As EnvDTE.Breakpoint In debugger.Breakpoints
        If bp.File <> DTE.ActiveDocument.FullName Then
            Continue For
        End If
        For Each bpc As EnvDTE.Breakpoint In bp.Children
            If bpc.FileLine = sel Then
                bp.Delete()
                Exit For
            End If
        Next
    Next
End Sub

You can assign a keyboard shortcut to it for easy access. (Tools > Options > Environment > Keyboard.)

Protector one
  • 6,926
  • 5
  • 62
  • 86
1

Here's an updated macro for the new javascript based macro add-in (https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MacrosforVisualStudio) to remove all children breakpoints:

/// <reference path="C:\Users\ERobishaw\AppData\Local\Microsoft\VisualStudio\14.0\Macros\dte.js" />
try {

    var outputWindowPane = dte.Windows.Item("{34E76E81-EE4A-11D0-AE2E-00A0C90FFFC3}").Object.ActivePane;
    outputWindowPane.Activate();
    outputWindowPane.OutputString("display this text in the output window panel\n");

    var i;
    var len;
    var dbgr = dte.Debugger;
    var brk = dbgr.Breakpoints;
    outputWindowPane.OutputString("There are " + brk.Count + " Total\n");
    //Macro.InsertText("There are " + brk.Count + " Total");
    for (var bpi = 1; bpi <= brk.Count; bpi++) {
        outputWindowPane.OutputString("On " + bpi + " of " + brk.Count + "\n");
        var bp = brk.Item(bpi);
        var children = bp.Children;
        var len = children.Count;
        
        for (var chi = len; chi > 0; chi--) {
            outputWindowPane.OutputString(" Children Count = " + children.Count + "\n");
            children.Item(chi).Delete();
        }
    }
}
catch (e) {
    outputWindowPane.OutputString("Error\n");
    outputWindowPane.OutputString(e + "\n");
}
user910531
  • 89
  • 1
  • 7