More fun with labelling breakpoints
Back in my first Debugger tips post I provided some macros that allow you to tag a set of breakpoints with a string so that they can easily be enabled or disabled from the command window. Well, just for kicks, I decided to expand on that notion a bit and made a set of new macros that can not only do that, but also support multiple labels (the new name for tags) for breakpoints and tracepoints.
Following this description you'll find the source for these macros. Basically, you can use the instructions provided Idiot's Guide to Creating and Using VS Macros to add these macros to your installation. After you do that, just run the SetupBPLabels macro, and you'll be able to use the following commands in the command window:
I'm not really sure how useful this set of macros will be for you, but it was fun writing them! Let me know what you think, or if you think there's some improvements that could be made to make them even more useful! Please note that I am not much of a VB programmer, so if you have suggestions as to how to improve the code, I'm all ears!
' -------------------------------------------------------------------------
DTE.ExecuteCommand("alias enablebps Macros.MyMacros.BPLabels.EnableBPs")
DTE.ExecuteCommand("alias disablebps Macros.MyMacros.BPLabels.DisableBPs")
DTE.ExecuteCommand("alias listbps Macros.MyMacros.BPLabels.ListBPs")
DTE.ExecuteCommand("alias labelbps Macros.MyMacros.BPLabels.LabelEnabledBPs")
DTE.ExecuteCommand("alias clearlabel Macros.MyMacros.BPLabels.ClearBPLabel")
End Sub
Dim bps As EnvDTE.Breakpoints = DTE.Debugger.Breakpoints
If (bps.Count > 0) Then
For Each bp As EnvDTE.Breakpoint In bps
Dim strCurLabels As String = GetBPLabels(bp)
If (bp.Enabled = True And Not BPLabeledAs(bp, strLabel)) Then
If (strCurLabels.Length > 0) Then
strCurLabels += ";"
End If
strCurLabels = strCurLabels + strLabel
SetBPLabels(bp, strCurLabels)
Next
Else
System.Windows.Forms.MessageBox.Show("Can't find any breakpoints to label")
SetBPLabels(bp, "")
If (strBadLabel <> "*") Then
Dim labels() As String = strCurLabels.Split(";")
Dim strNewLabels As String = ""
For Each s As String In labels
If (s.ToLower <> strBadLabel.ToLower) Then
If (strNewLabels.Length > 0) Then
strNewLabels += ";"
strNewLabels = strNewLabels + s
SetBPLabels(bp, strNewLabels)
If (strLabel = "*" Or BPLabeledAs(bp, strLabel) Or (GetBPLabels(bp).Length = 0 And strLabel.Length = 0)) Then
bp.Enabled = True
System.Windows.Forms.MessageBox.Show("Can't find any breakpoints to enable")
bp.Enabled = False
Dim outpane As EnvDTE.CommandWindow = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow).Object
Dim i As Integer = 1
If (strLabel.Length = 0 Or BPLabeledAs(bp, strLabel)) Then
Dim strEnabled As String = ""
If bp.Enabled Then
strEnabled = "x"
outpane.OutputString("BP #" + i.ToString() + " " + strEnabled + vbTab + "Name: " + bp.Name + vbCrLf)
If (strLabel.Length = 0) Then
outpane.OutputString(vbTab + vbTab + "Labels: " + GetBPLabels(bp) + vbCrLf)
i = i + 1
Dim strStartTag As String = "<labels>"
Dim strEndTag As String = "</labels>"
Dim ndxStart As Integer = bp.Tag.IndexOf(strStartTag) + strStartTag.Length
Dim ndxEnd As Integer = bp.Tag.IndexOf(strEndTag)
If (ndxStart > 0 And ndxEnd > ndxStart) Then
GetBPLabels = bp.Tag.Substring(ndxStart, ndxEnd - ndxStart)
GetBPLabels = ""
End Function
bp.Tag = "<labels>" + labels + "</labels>"
Dim bLabelFound As Boolean = False
If (strLabel.Length > 0) Then
Dim strLabels = GetBPLabels(bp)
Dim labels() As String = strLabels.Split(";")
For i As Integer = 0 To labels.Length - 1 And bLabelFound = False
If (labels(i).ToLower = strLabel.ToLower) Then
bLabelFound = True
Return bLabelFound