locked
Question on setting WhenHit-breakpoint in VStudio 2008 using a macro RRS feed

  • Question

  • Hello.

    I want to find out which code parts of class in a C# win forms UI are hit when I click a button in the UI.

    In my case I click a save button which stores data in a database. This fires some events and other classes

    update their state dependent on these events. So there are different event handlers implemented calling

    some methods within some classes.

    My question:

    I found this article http://www.codeguru.com/article.php/c5911 where I got this code line from.

      

    Bps = DTE.Debugger.Breakpoints.Add(File:=SrcFile, _ Line:=LineNum) 
    

    Is there a way to use

        Breakpoints.Add(.)

    to create a WhenHit-breakpoint ?

     

    thanks and cheers

    Joachim

    Monday, November 21, 2011 11:24 AM

Answers

  • Hello Lucy,

    Thanks for your answer. I tried to put your code into the macro I mentioned but with less success.

    So I investigated further and found the following code block.

    Sub AddBreakpointToMain()
         Dim bp As EnvDTE80.Breakpoint2
         Dim bps As EnvDTE.Breakpoints
    
    
         bps = DTE.Debugger.Breakpoints.Add("Main")
         For Each bp In bps
             bp.Tag = "SetByMacro"
             bp.BreakWhenHit = False
             bp.Message = "Hi, this is your tracepoint calling." // Here put in "Function : $FUNCTION"
         Next
    End Sub
    

    I found this here:

    http://stackoverflow.com/questions/791930/how-to-programatically-add-a-tracepoint-for-visual-studio

    thanks and cheers

    Joachim

    • Marked as answer by j.spehl Tuesday, November 22, 2011 3:27 PM
    Tuesday, November 22, 2011 3:24 PM

All replies

  • Hi j.spehl,

    I found you have asked the same issue in this thread http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/f80f2d70-b4f1-4574-861f-9e59b2bd513b/ .

    I think the Nancy’s reply is correct.

    When we right-click a breakpoint , select “When Hit” , the When Breakpoint Is Hit dialog shows. We can customize the action that occurs when a breakpoint is hit. Like : Print a Message, Run a Macro or Continue Execution (more information: http://msdn.microsoft.com/en-us/library/fhya4x5t.aspx )

    Now we can write an add-in or macros to simulate this processes. We can try to use DebuggerEvents object. When the breakpoint is hit , the OnEnterBreakMode Event will be fired, and we can add code to OnEnterBreakMode Event to print message or run a macro and so on.

    For example:

    //Add the following code to Exec method:

    _debugEvents = _applicationObject.Events.DebuggerEvents;

                        _debugEvents.OnEnterBreakMode += new _dispDebuggerEvents_OnEnterBreakModeEventHandler(DebugEvents_OnEnterBreakMode);

     

    //Add the following code within the connect class

     Public void DebugEvents_OnEnterBreakMode(dbgEventReason Reason, ref dbgExecutionAction ExecutionAction)

            {

                System.Windows.Forms.MessageBox.Show("Debugger enters break mode. " + "Reason: " + Reason.ToString());

            }

    In this example, we print message when the breakpoint is hit.

     

    In my opinion, write an add-in to realize this is better than write a macros.

    But if you really want to write a macros, you can try to convert the above code to vb.net. like:

    Dim dbge As DebuggerEvents = DTE.Events.DebuggerEvents

    AddHandler (dbge.OnEnterBreakMode), AddressOf DebugEvents_OnEnterBreakMod()

     

    Public Sub DebugEvents_OnEnterBreakMod(ByVal reason As dbgEventReason, ByVal execAction As dbgExecutionAction)

            System.Windows.Forms.MessageBox.Show("Debugger enters break mode. " + "Reason: " + reason.ToString())

        End Sub

     

     

    Best regards,

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, November 22, 2011 10:00 AM
  • Hello Lucy,

    Thanks for your answer. I tried to put your code into the macro I mentioned but with less success.

    So I investigated further and found the following code block.

    Sub AddBreakpointToMain()
         Dim bp As EnvDTE80.Breakpoint2
         Dim bps As EnvDTE.Breakpoints
    
    
         bps = DTE.Debugger.Breakpoints.Add("Main")
         For Each bp In bps
             bp.Tag = "SetByMacro"
             bp.BreakWhenHit = False
             bp.Message = "Hi, this is your tracepoint calling." // Here put in "Function : $FUNCTION"
         Next
    End Sub
    

    I found this here:

    http://stackoverflow.com/questions/791930/how-to-programatically-add-a-tracepoint-for-visual-studio

    thanks and cheers

    Joachim

    • Marked as answer by j.spehl Tuesday, November 22, 2011 3:27 PM
    Tuesday, November 22, 2011 3:24 PM