views:

25

answers:

1

I have a file with 13.4K LOC. I would like to set a breakpoint that will be hit if any of the methods in the file are called. Is this possible? (Going through and marking them all myself would be a huge pain.)

A: 

You can write a Visual Studio macro to add a breakpoint at the beginning of each method in the file.

A macro would look something along the lines of this:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module Module1
    Public Sub AddBreakpointForCurrentMethod()
        Dim textSelection As EnvDTE.TextSelection
        Dim codeElement As EnvDTE.CodeElement

        textSelection = DTE.ActiveWindow.Selection
        Try
            codeElement = textSelection.ActivePoint.CodeElement(vsCMElement.vsCMElementFunction)
            If Not (codeElement Is Nothing) Then
                DTE.Debugger.Breakpoints.Add(Line:=codeElement.StartPoint.Line, File:=DTE.ActiveDocument.FullName)
            End If
        Catch
            MsgBox("Add error handling here.")
        End Try
    End Sub

End Module

To solve the problem in the long run you might consider refactoring your code into smaller units that can be handled more easily.

0xA3