5

我想在 Visual Studio 中定义一些断点集,以便在它们之间切换。

通过set,我的意思是我定义的某些行处的断点集合。我有很多场景想要在这些集合之间切换以简化调试。

例如:

Set 1: breakpoints at line 1, line 3, line 5, line 7
Set 2: breakpoints at line 2, line 4, line 6, line 8,

有没有办法在 Visual Studio 中做到这一点(首选 2008 及更高版本),或者是否有任何加载项?

4

2 回答 2

2

此功能在 Visual Studio 2010 和 2012 的断点窗口中可用。 http://msdn.microsoft.com/en-us/library/dd293674.aspx

(c) Visual Studio 团队(Microsoft 产品团队)2012 年 11 月 21 日

http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2394909-breakpoint-sets-or-groups-enable-disable-breakp

此外,这是在 Visual Studio 2008 中实现此功能的小宏。您可以将其复制到宏中的任何模块(工具 > 宏 > 宏资源管理器 > 右键单击​​任何模块 > 编辑 > 粘贴那里),然后将其添加为对任何菜单的命令(通过工具 > 自定义...)

Dim savePath = "c:\temp"
Sub SaveBreakpoints()
    Dim fname As String
    Dim lBreakpointsList As System.Collections.Generic.List(Of Breakpoint)
    Dim fileList = IO.Directory.GetFiles(savePath)
    Dim lFiles = ""
    For Each lFile In fileList
        lFiles = String.Concat(lFiles, IO.Path.GetFileNameWithoutExtension(lFile), vbCrLf)
    Next
    fname = InputBox(String.Concat("Existing sets:", vbCrLf, lFiles, vbCrLf, "Name of new set:"), "Save Breakpoints", "1")
    If fname = "" Then
        Return
    End If
    lBreakpointsList = New System.Collections.Generic.List(Of Breakpoint)
    For Each lBreakpoint As EnvDTE.Breakpoint In DTE.Debugger.Breakpoints
        lBreakpointsList.Add(New Breakpoint(lBreakpoint.File, lBreakpoint.FileLine, lBreakpoint.Condition))
    Next

    Using fs As New IO.StreamWriter(String.Concat("c:\temp\", fname, ".txt"))
        For Each lBreakpoint As Breakpoint In lBreakpointsList
            fs.WriteLine(String.Format("{0}   |||   {1}   |||   {2}", lBreakpoint.File, lBreakpoint.Line, lBreakpoint.Condition))
        Next
    End Using
End Sub

Sub RestoreBreakpoints()
    Dim fname As String
    Dim lBreakpointsList As System.Collections.Generic.List(Of Breakpoint)
    Dim lProperties As String()
    Dim fileList = IO.Directory.GetFiles(savePath)
    Dim lFiles = ""
    For Each lFile In fileList
        lFiles = String.Concat(lFiles, IO.Path.GetFileNameWithoutExtension(lFile), vbCrLf)
    Next
    fname = InputBox(String.Concat("Enter name of set to restore. Existing sets:", vbCrLf, vbCrLf, lFiles), "Restore Breakpoints", "1")
    If fname = "" Then
        Return
    End If
    lBreakpointsList = New Collections.Generic.List(Of Breakpoint)
    Dim lBp As Breakpoint
    Using fs As New IO.StreamReader(String.Concat("c:\temp\", fname, ".txt"))
        While Not fs.EndOfStream
            lProperties = fs.ReadLine().Split(New String() {"   |||   "}, StringSplitOptions.None)
            lBp = New Breakpoint(lProperties(0), lProperties(1), lProperties(2))
            lBreakpointsList.Add(lBp)
        End While
    End Using
    Try
        DTE.ExecuteCommand("Debug.DeleteAllBreakpoints")
    Catch ex As Exception
    End Try
    For Each lBp1 As Breakpoint In lBreakpointsList
        DTE.Debugger.Breakpoints.Add(, lBp1.File, Convert.ToInt32(lBp1.Line), , lBp1.Condition)
    Next
End Sub

Class Breakpoint
    Public File
    Public Line
    Public Condition

    Public Sub New(ByVal pFile, ByVal pLine, ByVal pCondition)
        File = pFile
        Line = pLine
        Condition = pCondition
    End Sub
End Class
于 2013-04-30T12:04:20.450 回答
0

您可以单击行首。然后单击断点>插入断点。您可以对每一行执行此操作。我想这就是你要找的。

于 2013-04-02T16:20:53.703 回答