Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. breakpoints to all the functions inside a .cs file

breakpoints to all the functions inside a .cs file

Scheduled Pinned Locked Moved C#
question
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LiYS
    wrote on last edited by
    #1

    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,


    M R D S 4 Replies Last reply
    0
    • L LiYS

      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,


      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • L LiYS

        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,


        R Offline
        R Offline
        Rob Philpott
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • L LiYS

          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,


          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • L LiYS

            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,


            S Offline
            S Offline
            S Senthil Kumar
            wrote on last edited by
            #5

            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.Diagnostics

            Public Module Module1
            Public Sub AutoBreakPoint()
            ProcessFile()
            End Sub

            Function 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
            
            L 1 Reply Last reply
            0
            • S S Senthil Kumar

              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.Diagnostics

              Public Module Module1
              Public Sub AutoBreakPoint()
              ProcessFile()
              End Sub

              Function 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
              
              L Offline
              L Offline
              LiYS
              wrote on last edited by
              #6

              Tried and True. Thank you very much! Thanks,


              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups