Implementing CBreakpointResolution

In TextInterpreter, the CBreakpointResolution class implements the IDebugBreakpointResolution2 interface. Each instance of the class represents a single breakpoint resolution and is created in the call to CPendingBreakpoint::Bind (which implements IDebugPendingBreakpoint2::Bind).

Note that in TextInterpreter, the CBreakpointResolution class assumes it will always be associated with a code context. In a more typical implementation that uses both code (BP_RESOLUTION_CODE) and data (BP_RESOLUTION_DATA) resolution contexts, CBreakpointResolution would probably be implemented as two separate classes, one for each type of resolution context.

To implement CBreakpointResolution

  1. In Class View, right-click the CBreakpointResolution class. Click Add Variable and add a variable with the Variable name m_bpResolutionInfo, a Variable type of BP_RESOLUTION_INFO, and an Access type of protected.

  2. In Class View, right-click the CBreakpointResolution class and click Add Function to add a function with the Function name Initialize, a Return type of void, and the following parameter (click Add to add it to the Parameter list before clicking Finish):

    Parameter Type

    Parameter Name

    IDebugCodeContext2 *

    pCodeContext

  3. Open the Context.h file, find the CBreakpointResolution class declaration, and change the constructor so it is only declared. Then add a declaration for a virtual destructor:

        CBreakpointResolution();
        virtual ~CBreakpointResolution(); 
    
  4. Open the Context.cpp file and insert the following bold lines before the definition of CBreakpointResolution::GetBreakpointType:

    // CBreakpointResolution
    
    CBreakpointResolution::CBreakpointResolution() 
    { 
        memset(&m_bpResolutionInfo, 0, sizeof(BP_RESOLUTION_INFO)); 
    
        m_bpResolutionInfo.bpResLocation.bpType = BPT_CODE; 
        m_bpResolutionInfo.dwFields = BPRESI_BPRESLOCATION; 
    } 
    
    CBreakpointResolution::~CBreakpointResolution() 
    { 
        m_bpResolutionInfo.bpResLocation.bpResLocation.bpresCode.pCodeContext->Release(); 
    } 
    
  5. In CBreakpointResolution::Initialize, add the following bold lines:

    void CBreakpointResolution::Initialize(IDebugCodeContext2 * pCodeContext)
    {
        m_bpResolutionInfo.bpResLocation.bpResLocation.bpresCode.pCodeContext = pCodeContext; 
        m_bpResolutionInfo.bpResLocation.bpResLocation.bpresCode.pCodeContext->AddRef(); 
    }
    
  6. In CBreakpointResolution::GetBreakpointType, replace the line //TODO: RETURN BREAKPOINT TYPE as well as the following return statement with the following:

        *pBPType = BPT_CODE; 
        return S_OK; 
    
  7. In CBreakpointResolution::GetResolutionInfo, replace the line //TODO: RETURN RESOLUTION INFO as well as the following return statement with the following:

        // Start with a raw copy 
        if (pBPResolutionInfo == NULL) 
            return E_POINTER; 
    
        *pBPResolutionInfo = m_bpResolutionInfo; 
    
        // Set the fields. 
        pBPResolutionInfo->dwFields = dwFields & m_bpResolutionInfo.dwFields; 
    
        // Fill in the bp resolution destination 
        if (pBPResolutionInfo->dwFields & BPRESI_BPRESLOCATION) 
        { 
            pBPResolutionInfo->bpResLocation.bpResLocation.bpresCode.pCodeContext->AddRef(); 
            return S_OK; 
        } 
        return E_NOTIMPL; 
    
  8. Build the project to make sure there are no errors.

See Also

Concepts

Creating a Bound Breakpoint