프로그램 등록
디버그 엔진이 IDebugPort2 인터페이스로 표시되는 포트를 획득한 후 프로그램을 디버그할 수 있도록 하는 다음 단계는 포트에 등록하는 것입니다. 등록이 완료되면 다음 방법 중 하나로 프로그램을 디버깅할 수 있습니다.
연결 프로세스를 통해 디버거가 실행 중인 애플리케이션에 대한 완전한 디버깅 제어 권한을 얻을 수 있습니다.
JIT(Just-In-Time) 디버깅을 통해 디버거와 독립적으로 실행되는 프로그램의 사후 디버깅이 가능합니다. 런타임 아키텍처가 오류를 catch하면 운영 체제 또는 런타임 환경에서 오류 프로그램의 메모리 및 리소스를 해제하기 전에 디버거에 알림이 전달됩니다.
등록 절차
프로그램을 등록하려면
포트에서 구현된 AddProgramNode 메서드를 호출합니다.
IDebugPortNotify2::AddProgramNode
에는 IDebugProgramNode2 인터페이스에 대한 포인터가 필요합니다.일반적으로 운영 체제 또는 런타임 환경에서 프로그램을 로드하면 프로그램 노드가 만들어집니다. DE(디버그 엔진)에 프로그램을 로드하라는 메시지가 표시되면 DE는 프로그램 노드를 만들고 등록합니다.
다음 예제에서는 프로그램을 시작하고 포트에 등록하는 디버그 엔진을 보여줍니다.
참고 항목
이 코드 샘플이 프로세스를 실행하고 다시 시작하는 유일한 방법은 아닙니다. 이 코드는 주로 포트에 프로그램을 등록하는 예제로 제공됩니다.
// 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); }