breakpoints to all the functions inside a .cs file
-
Hi all, Is this possible that set breakpoints to all the functions inside a file? I just want to see which function is first called among many functions. I've tried Macro recording but didn't work out. Thanks,
YOu may use Call Stack [^]to determine the execution order.
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Hi all, Is this possible that set breakpoints to all the functions inside a file? I just want to see which function is first called among many functions. I've tried Macro recording but didn't work out. Thanks,
Interesting question, and short of doing it manually I don't know of and doubt there is a standard way of setting breakpoints all over the shop. I can't see how the call stack would help either, as that just tells you how the runtime got to where it is now and may not include execution branches that have already run. Can you not just step through the code until such a function gets hit? Or, very obscure but perhaps you could intercept when the assembly is loaded which would give you an idea that one of its methos is about to be hit. I think there's an event on the AppDomain or something for that.
Regards, Rob Philpott.
-
Hi all, Is this possible that set breakpoints to all the functions inside a file? I just want to see which function is first called among many functions. I've tried Macro recording but didn't work out. Thanks,
Breakpoints are saved in the solutionname.suo It should be possible to use reflection to get the methods and add breakpoints accordingly. This could be a good article topic if you succeed! [Edit] This[^] might be a good starting point for working with the suo file [/Edit]
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)modified on Thursday, June 11, 2009 4:46 AM
-
Hi all, Is this possible that set breakpoints to all the functions inside a file? I just want to see which function is first called among many functions. I've tried Macro recording but didn't work out. Thanks,
Macro recording won't work, but you can write a macro that does the job. Here's what I came up with - it basically goes to each method in the currently open file and adds a breakpoint to the first line of the method.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.DiagnosticsPublic Module Module1
Public Sub AutoBreakPoint()
ProcessFile()
End SubFunction ProcessFile() Dim selection As EnvDTE.TextSelection Dim projectItem As ProjectItem Dim fileCodeModel As FileCodeModel Dim codeElement As CodeElement Dim i As Integer Dim currentFunction As CodeFunction projectItem = DTE.ActiveDocument.ProjectItem fileCodeModel = projectItem.FileCodeModel For i = 1 To fileCodeModel.CodeElements.Count codeElement = fileCodeModel.CodeElements.Item(i) ProcessCodeElement(codeElement) Next selection = DTE.ActiveDocument.Selection selection.SelectAll() selection.SmartFormat() End Function Sub ProcessNamespace(ByVal namespaceElement As CodeNamespace) Dim i As Integer Dim codeElement As CodeElement For i = 1 To namespaceElement.Members.Count codeElement = namespaceElement.Members.Item(i) ProcessCodeElement(codeElement) Next End Sub Sub ProcessCodeElement(ByVal codeElement As CodeElement) If codeElement.Kind = vsCMElement.vsCMElementNamespace Then ProcessNamespace(codeElement) ElseIf codeElement.Kind = vsCMElement.vsCMElementClass Then ProcessType(codeElement) ElseIf codeElement.Kind = vsCMElement.vsCMElementFunction Then ProcessMethod(codeElement) End If End Sub Sub ProcessType(ByVal typeElement As CodeClass) Dim i As Integer Dim codeElement As CodeElement For i = 1 To typeElement.Members.Count codeElement = typeElement.Members.Item(i) If codeElement.Kind = vsCMElement.vsCMElementFunction Then ProcessMethod(codeElement) ElseIf codeElement.Kind = vsCMElement.vsCMElementClass Then ProcessType(codeElement) End If Next End Sub Sub ProcessMethod(ByVal methodElement As CodeFunction) Dim selection As EnvDTE.TextSelection Dim editPoint As EnvDTE.EditPoint Dim verifyPoint As EnvDTE.TextPoint Dim endPointA
-
Macro recording won't work, but you can write a macro that does the job. Here's what I came up with - it basically goes to each method in the currently open file and adds a breakpoint to the first line of the method.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.DiagnosticsPublic Module Module1
Public Sub AutoBreakPoint()
ProcessFile()
End SubFunction ProcessFile() Dim selection As EnvDTE.TextSelection Dim projectItem As ProjectItem Dim fileCodeModel As FileCodeModel Dim codeElement As CodeElement Dim i As Integer Dim currentFunction As CodeFunction projectItem = DTE.ActiveDocument.ProjectItem fileCodeModel = projectItem.FileCodeModel For i = 1 To fileCodeModel.CodeElements.Count codeElement = fileCodeModel.CodeElements.Item(i) ProcessCodeElement(codeElement) Next selection = DTE.ActiveDocument.Selection selection.SelectAll() selection.SmartFormat() End Function Sub ProcessNamespace(ByVal namespaceElement As CodeNamespace) Dim i As Integer Dim codeElement As CodeElement For i = 1 To namespaceElement.Members.Count codeElement = namespaceElement.Members.Item(i) ProcessCodeElement(codeElement) Next End Sub Sub ProcessCodeElement(ByVal codeElement As CodeElement) If codeElement.Kind = vsCMElement.vsCMElementNamespace Then ProcessNamespace(codeElement) ElseIf codeElement.Kind = vsCMElement.vsCMElementClass Then ProcessType(codeElement) ElseIf codeElement.Kind = vsCMElement.vsCMElementFunction Then ProcessMethod(codeElement) End If End Sub Sub ProcessType(ByVal typeElement As CodeClass) Dim i As Integer Dim codeElement As CodeElement For i = 1 To typeElement.Members.Count codeElement = typeElement.Members.Item(i) If codeElement.Kind = vsCMElement.vsCMElementFunction Then ProcessMethod(codeElement) ElseIf codeElement.Kind = vsCMElement.vsCMElementClass Then ProcessType(codeElement) End If Next End Sub Sub ProcessMethod(ByVal methodElement As CodeFunction) Dim selection As EnvDTE.TextSelection Dim editPoint As EnvDTE.EditPoint Dim verifyPoint As EnvDTE.TextPoint Dim endPointA