Aracılığıyla paylaş


Programı kaydetme

Hata ayıklama altyapısı bir IDebugPort2 arabirimiyle temsil edilen bir bağlantı noktası aldıktan sonra, programın hata ayıklamasını etkinleştirmenin bir sonraki adımı bunu bağlantı noktasına kaydetmektir. Kaydedildikten sonra, program aşağıdaki araçlardan biriyle hata ayıklama için kullanılabilir:

  • Hata ayıklayıcının çalışan bir uygulamanın tam hata ayıklama denetimini elde etmesini sağlayan ekleme işlemi.

  • Hata ayıklayıcıdan bağımsız olarak çalışan bir programın olgu sonrası hata ayıklamasını sağlayan tam zamanında (JIT) hata ayıklama. Çalışma zamanı mimarisi bir hata yakaladığında, işletim sistemi veya çalışma zamanı ortamı hatalı programın belleğini ve kaynaklarını serbest bırakmadan önce hata ayıklayıcıya bildirilir.

Kayıt prosedürü

Programınızı kaydetmek için

  1. Bağlantı noktası tarafından uygulanan AddProgramNode yöntemini çağırın.

    IDebugPortNotify2::AddProgramNode IDebugProgramNode2 arabirimine yönelik bir işaretçi gerektirir.

    Genellikle işletim sistemi veya çalışma zamanı ortamı bir programı yüklediğinde program düğümünü oluşturur. Hata ayıklama altyapısından (DE) programı yüklemesi istenirse, DE program düğümünü oluşturur ve kaydeder.

    Aşağıdaki örnekte, programı başlatan ve bir bağlantı noktasına kaydeden hata ayıklama altyapısı gösterilmektedir.

    Uyarı

    Bu kod örneği bir işlemi başlatmanın ve sürdürmenin tek yolu değildir; bu kod temel olarak bir programı bir bağlantı noktasına kaydetme örneğidir.

    // 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);
    }