Share via


Implementing CDebugContext

In TextInterpreter, CPendingBreakpoint::Bind (the implementation for IDebugPendingBreakpoint2::Bind) creates an instance of CDebugContext and then calls CDebugContext::Initialize with the documentation name and position of the breakpoint. This information is returned from the few methods on the IDebugDocumentContext2 interface that are actually implemented here.

To implement CDebugContext

  1. In Class View, right-click the CDebugContext class, click Add Variable, and add a variable with the Variable name m_sbstrFileName, a Variable type of CComBSTR, and an Access type of protected.

  2. Add another variable to the CDebugContext class with the Variable name m_pos, a Variable type of TEXT_POSITION, and an Access type of protected.

  3. In Class View, right-click the CDebugContext class and click Add Function to add a function with the Function name Initialize, a Return type of void, and the following parameters in the order given (click Add between each one):

    Parameter type

    Parameter name

    LPCWSTR

    pszFileName

    TEXT_POSITION&

    pos

  4. Open the Context.cpp file, find CDebugContext::Initialize, and add the following bold lines:

    void CDebugContext::Initialize(LPCWSTR pszFileName, TEXT_POSITION& pos)
    {
        m_sbstrFileName = pszFileName; 
        m_pos = pos; 
    }
    
  5. In CDebugContext::GetDocumentContext, replace the line //TODO: RETURN DOCUMENT CONTEXT as well as the following return statement with the following:

        *ppSrcCxt = (IDebugDocumentContext2 *) this; 
        (*ppSrcCxt)->AddRef(); 
        return S_OK; 
    
  6. In CDebugContext::GetName, replace the line //TODO: RETURN CONTEXT FILENAME as well as the following return statement with the following:

        *pbstrFileName = SysAllocString(m_sbstrFileName); 
        return S_OK; 
    
  7. In CDebugContext::GetSourceRange, replace the line //TODO: RETURN SOURCE RANGE as well as the following return statement with the following. Note that the range is always zero characters, so the beginning and end positions are always the same.

        if (pBegPosition)  
            *pBegPosition = m_pos;  
        if (pEndPosition)  
            *pEndPosition = m_pos;  
        return S_OK;  
    
  8. In CDebugContext::GetStatementRange, replace the line //TODO: RETURN STATEMENT RANGE as well as the following return statement with the following. Note that because the document and code contexts are the same, the ranges are also the same.

        return GetSourceRange(pBegPosition, pEndPosition);  
    
  9. Build the project to make sure there are no errors.

See Also

Concepts

Creating a Bound Breakpoint