locked
How to detect when the Visual Studio Debugger detects a breakpoint RRS feed

  • Question

  • Hi, 

    We are using the Microsoft Application Verifier tool on our application while it is running an automated test of the user interface. When the Application Verifier detects a problem, Visual Studio 2005 will have a breakpoint triggered. We are running an automated test of the user interface that uses the mouse and keyboard on the same machine as the debugger, which means the debugger window gets focus and could inadvertently receive the automated test's user interface commands (such as selecting the "Continue" button on the breakpoint message box).

    It would be nice to be able to detect when a breakpoint like that occurs so that we can signal our automated test to stop running. I found EnvDTE.DebuggerEventsClass online (http://msdn.microsoft.com/en-us/library/envdte.debuggereventsclass.onenterbreakmode(v=vs.80).aspx) and tried to use AddHandler within the Visual Studio Macros to catch when the debugger enters the break mode, however when I try to use it, I get a "Class Not Registered" error. Further digging found that the class/events are listed as "Microsoft Internal Use Only" (see: http://msdn.microsoft.com/en-us/library/envdte.debuggereventsclass.debuggereventsclass(v=vs.80).aspx).  Is there a public interface available that does this same functionality?

    I'm looking for something that does the same as the following:

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports System.Diagnostics
    
    Public Module DebuggerWatcher
    
        Public Sub StartWatching()
    
            Dim instance As New EnvDTE.DebuggerEventsClass
            AddHandler instance.OnEnterBreakMode, AddressOf BreakHandler
    
        End Sub
    
        Private Sub BreakHandler(ByVal Reason As EnvDTE.dbgEventReason, ByRef ExecutionAction As EnvDTE.dbgExecutionAction)
            MsgBox("BreakHander!!!")
        End Sub
    End Module

    Any help would be greatly appreciated.

    Thanks, Tim


    • Edited by TimKnor Monday, August 11, 2014 10:48 PM
    Monday, August 11, 2014 10:46 PM

Answers

  • Hi TimKnor,

    Yes, there doesn't seem to be any event in EnvDTE's DebuggerEvents that notifies the consumer when a breakpoint is deleted. And DebuggerEventsClass Constructor is for Microsoft Internal Use Only.

    I think you can resort to a timer polling DTE.Debugger.Breakpoints for changes as Cameron said.

    http://stackoverflow.com/questions/16772011/how-do-i-detect-a-breakpoint-being-deleted-in-visual-studio

    Debugger.Breakpoints Property

    http://msdn.microsoft.com/en-us/library/envdte.debugger.breakpoints(v=vs.80).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-4

    It gets a collection of breakpoints. The following example demonstrates how to use the Breakpoints property.

    Shared Sub Breakpoints(ByRef dte As EnvDTE.DTE)
        Dim str As String
    
        dte.Debugger.Breakpoints.Add("", "Target001.cs", 13, 1, "", _
                                     EnvDTE.dbgBreakpointConditionType.dbgBreakpointConditionTypeWhenTrue, _
                                     "C#", "", 0, "", 0, EnvDTE.dbgHitCountType.dbgHitCountTypeNone)
        dte.Debugger.Breakpoints.Add("", "Target001.cs", 15, 1, "", _
                                     EnvDTE.dbgBreakpointConditionType.dbgBreakpointConditionTypeWhenTrue, _
                                     "C#", "", 0, "", 0, EnvDTE.dbgHitCountType.dbgHitCountTypeNone)
        ' Setup debug Output window.
        Dim w As Window
        Dim ow As OutputWindow
        Dim owp As OutputWindowPane
        w = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
        w.Visible = True
        ow = w.Object
        owp = ow.OutputWindowPanes.Add("Debugger Test")
        owp.Activate()
        Dim debugger As EnvDTE.Debugger = dte.Debugger
        For Each bp As EnvDTE.Breakpoint In debugger.Breakpoints
            str += bp.Name + vbCrLf
        Next
        owp.OutputString("Number of breakpoints set: " + debugger.Breakpoints.Count.ToString() + _
                         vbCrLf + str)
        MessageBox.Show("Number of breakpoints set: " + debugger.Breakpoints.Count.ToString() + _
                         vbCrLf + str, "Debugger Test")
    End Sub
    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Anna Cc Friday, August 22, 2014 8:10 AM
    Thursday, August 14, 2014 3:22 AM