Поделиться через


Implementing CCodeBreakpointEvent

When the debug engine detects that a breakpoint has been encountered, it needs to inform the session debug manager (SDM) of this by sending an event represented by the IDebugBreakpointEvent2 interface. This interface allows enumeration over all bound breakpoints that were encountered, so the implementation of this interface needs to create that enumeration.

In TextInterpreter, the CCodeBreakpointEvent class implements the IDebugBreakpointEvent2 interface. Since only one bound breakpoint is created for each pending breakpoint, TextInterpreter’s implementation for IDebugBreakpointEvent2::EnumBreakpoints returns an enumeration with only one breakpoint in it.

To create the CCodeBreakpointEvent class

  1. In Solution Explorer, right-click the TextInterpreter project and click Add Class.

  2. Add a Generic C++ Class with the Class name CCodeBreakpointEvent and set its Base class to IDebugBreakpointEvent2. Set the .h file to EventBase.h and the .cpp file to EventBase.cpp. Make sure that Access is set to public. Click Finish. Answer Yes to the prompts that ask if you want to merge with the contents of the specified file.

  3. In Class View, right-click the new CCodeBreakpointEvent class, click Add Variable, and add a variable with the Variable name m_spBP, a Variable type of CComPtr<IDebugBoundBreakpoint2>, and an Access type of protected.

  4. Open the EventBase.h file, find the declaration for the new class CCodeBreakpointEvent, and modify the declaration to look like the following:

    class CCodeBreakpointEvent :
        public IDebugBreakpointEvent2, 
        public CEventBase 
    
  5. After the declaration of the CCodeBreakpointEvent destructor, add the following bold lines. These are the declarations for the methods on the IUnknown and IDebugBreakpointEvent2 interfaces.

        ~CCodeBreakpointEvent();
    
        //////////////////////////////////////////////////////////// 
        // IUnknown methods 
        DECLARE_IUNKNOWN 
    
        //////////////////////////////////////////////////////////// 
        //IDebugBreakpointEvent2 methods 
        STDMETHOD(EnumBreakpoints)(IEnumDebugBoundBreakpoints2 **ppEnum); 
    
  6. In EventBase.h, modify the CCodeBreakpointEvent constructor to take one parameter like this:

        CCodeBreakpointEvent(IDebugBoundBreakpoint2 *pBP);
    
  7. Open the EventBase.cpp file and insert the following bold lines after the last #include. This declares the enumeration type that is to be used for bound breakpoints.

    #include "eventbase.h"
    
    typedef CComEnumWithCount< 
        IEnumDebugBoundBreakpoints2, 
        &IID_IEnumDebugBoundBreakpoints2, 
        IDebugBoundBreakpoint2*, 
        _CopyInterface<IDebugBoundBreakpoint2> 
    > CEnumDebugBoundBreakpoints; 
    
  8. In EventBase.cpp, find the CCodeBreakpointEvent class and modify the constructor to look like the following:

    CCodeBreakpointEvent::CCodeBreakpointEvent(IDebugBoundBreakpoint2 *pBP)
    : CEventBase(IID_IDebugBreakpointEvent2, EVENT_SYNC_STOP) 
    {
        m_spBP = pBP; 
    }
    
  9. After the CCodeBreakpointEvent class destructor, add the following bold lines. These are the definitions for the methods on the IUnknown and IDebugBreakpointEvent2 interfaces.

    CCodeBreakpointEvent::~ CCodeBreakpointEvent()
    {
    }
    
    ////////////////////////////////////////////////////////////////////////////// 
    // IUnknown 
    IMPLEMENT_IUNKNOWN(CCodeBreakpointEvent, IDebugBreakpointEvent2) 
    
    ////////////////////////////////////////////////////////////////////////////// 
    // IDebugBreakpointEvent2 
    HRESULT CCodeBreakpointEvent::EnumBreakpoints(IEnumDebugBoundBreakpoints2 **ppEnum) 
    { 
        // Create the bound enumerator 
        CComObject<CEnumDebugBoundBreakpoints>* pBoundEnum; 
        CComObject<CEnumDebugBoundBreakpoints>::CreateInstance(&pBoundEnum); 
    
        IDebugBoundBreakpoint2* rgpBoundBP[] = { m_spBP }; 
        pBoundEnum->Init(rgpBoundBP, &(rgpBoundBP[1]), NULL, AtlFlagCopy); 
    
        *ppEnum = pBoundEnum; 
        (*ppEnum)->AddRef(); 
    
        return S_OK; 
    } 
    
  10. Build the project to make sure there are no errors.

See Also

Concepts

Firing the Breakpoint Event