禁用/删除子断点?

时间:2011-11-03 10:47:05

标签: c# .net visual-studio breakpoints visual-studio-debugging

我正在使用Visual Studio中的C#调试ASP.NET网站。当我设置断点(在调试期间)时,随着时间的推移,创建的断点将累积许多子断点。 (见here。)
现在,有时当我通过单击红色字形删除断点时,断点仍将在下次执行该行时被命中,因为子断点仍然存在。

在断点窗口中删除断点将解决问题,但是当你有很多设置时找到正确的断点很烦人。此外,删除许多孩子的断点是一个非常缓慢的操作。

为了解决这个问题,我可以禁用这个子断点的创建,还是有办法快速删除所有孩子?
备受欢迎的解决方案!


请注意,这不是重复:Question on how to remove a Visual Studio Breakpoint,因为我在问如何处理子断点。 (虽然我们的预期目标是相同的。)

3 个答案:

答案 0 :(得分:2)

以下代码可用作宏来删除所有子断点。

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

如果你有很多断点,它仍然非常慢,所以如果你遇到儿童断点问题,最好定期运行它。

答案 1 :(得分:1)

以下代码可用作宏来删除当前所选行上的断点。 (请注意,Visual Studio会在命中时自动选择断点行。)

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

您可以为其指定键盘快捷键以便于访问。 (工具&gt;选项&gt;环境&gt;键盘。)

答案 2 :(得分:1)

这是基于新的基于JavaScript的宏加载项(https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MacrosforVisualStudio)的更新宏,用​​于删除所有子断点:

/// <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");
}