Udostępnij za pośrednictwem


Rejestrowanie programu

Po uzyskaniu portu reprezentowanego przez interfejs IDebugPort2 aparat debugowania następnym krokiem umożliwiającym debugowanie programu jest zarejestrowanie go w porcie. Po zarejestrowaniu program jest dostępny do debugowania za pomocą jednego z następujących środków:

  • Proces dołączania, który umożliwia debugerowi uzyskanie pełnej kontroli debugowania uruchomionej aplikacji.

  • Debugowanie typu just in time (JIT), które umożliwia debugowanie po fakcie programu uruchamianego niezależnie od debugera. Gdy architektura czasu wykonywania przechwytuje błąd, debuger jest powiadamiany przed wydaniem pamięci i zasobów programu błędów przez system operacyjny lub środowisko uruchomieniowe.

Procedura rejestrowania

Aby zarejestrować program

  1. Wywołaj metodę AddProgramNode zaimplementowaną przez port.

    IDebugPortNotify2::AddProgramNode wymaga wskaźnika do interfejsu IDebugProgramNode2 .

    Zwykle gdy system operacyjny lub środowisko uruchomieniowe ładuje program, tworzy węzeł programu. Jeśli aparat debugowania (DE) zostanie poproszony o załadowanie programu, de tworzy i rejestruje węzeł programu.

    W poniższym przykładzie pokazano, jak aparat debugowania uruchamia program i rejestruje go przy użyciu portu.

    Uwaga

    Ten przykładowy kod nie jest jedynym sposobem uruchamiania i wznawiania procesu; ten kod jest głównie przykładem rejestrowania programu przy użyciu portu.

    // This is an IDebugEngineLaunch2 method.
    HRESULT CDebugEngine::LaunchSuspended(/* omitted parameters */,
                                          IDebugPort2 *pPort,
                                          /* omitted parameters */,
                                          IDebugProcess2**ppDebugProcess)
    {
        // do stuff here to set up for a launch (such as handling the other parameters)
        ...
    
        // Now get the IPortNotify2 interface so we can register a program node
        // in CDebugEngine::ResumeProcess.
        CComPtr<IDebugDefaultPort2> spDefaultPort;
        HRESULT hr = pPort->QueryInterface(&spDefaultPort);
        if (SUCCEEDED(hr))
        {
            CComPtr<IDebugPortNotify2> spPortNotify;
            hr = spDefaultPort->GetPortNotify(&spPortNotify);
            if (SUCCEEDED(hr))
            {
                // Remember the port notify so we can use it in ResumeProcess.
                m_spPortNotify = spPortNotify;
    
                // Now launch the process in a suspended state and return the
                // IDebugProcess2 interface
                CComPtr<IDebugPortEx2> spPortEx;
                hr = pPort->QueryInterface(&spPortEx);
                if (SUCCEEDED(hr))
                {
                    // pass on the parameters we were given (omitted here)
                    hr = spPortEx->LaunchSuspended(/* omitted parameters */,ppDebugProcess)
                }
            }
        }
        return(hr);
    }
    
    HRESULT CDebugEngine::ResumeProcess(IDebugProcess2 *pDebugProcess)
    {
        // Make a program node for this process
        HRESULT hr;
        CComPtr<IDebugProgramNode2> spProgramNode;
        hr = this->GetProgramNodeForProcess(pProcess, &spProgramNode);
        if (SUCCEEDED(hr))
        {
            hr = m_spPortNotify->AddProgramNode(spProgramNode);
            if (SUCCEEDED(hr))
            {
                // resume execution of the process using the port given to us earlier.
               // (Querying for the IDebugPortEx2 interface is valid here since
               // that's how we got the IDebugPortNotify2 interface in the first place.)
                CComPtr<IDebugPortEx2> spPortEx;
                hr = m_spPortNotify->QueryInterface(&spPortEx);
                if (SUCCEEDED(hr))
                {
                    hr  = spPortEx->ResumeProcess(pDebugProcess);
                }
            }
        }
        return(hr);
    }