// This function is used to terminate a process that the SampleEngine launched // The debugger will call IDebugEngineLaunch2::CanTerminateProcess before calling this method. int IDebugEngineLaunch2.TerminateProcess(IDebugProcess2 process) { /*Debug.Assert(Worker.MainThreadId == Worker.CurrentThreadId); * Debug.Assert(m_pollThread != null); * Debug.Assert(m_engineCallback != null);*/ Debug.Assert(debuggedProcess != null); try { int processId = EngineUtils.GetProcessId(process); if (processId != debuggedProcess.Id) { return(EngineConstants.S_FALSE); } debuggedProcess.Terminate(); return(EngineConstants.S_OK); } catch (ComponentException e) { return(e.HRESULT); } catch (Exception e) { return(EngineUtils.UnexpectedException(e)); } }
// Resume a process launched by IDebugEngineLaunch2.LaunchSuspended int IDebugEngineLaunch2.ResumeProcess(IDebugProcess2 process) { //Debug.Assert(Worker.MainThreadId == Worker.CurrentThreadId); /*Debug.Assert(m_pollThread != null); * Debug.Assert(m_engineCallback != null); * Debug.Assert(m_debuggedProcess != null); * Debug.Assert(m_ad7ProgramId == Guid.Empty);*/ try { int processId = EngineUtils.GetProcessId(process); if (processId != debuggedProcess.Id) { return(EngineConstants.S_FALSE); } // Send a program node to the SDM. This will cause the SDM to turn around and call IDebugEngine2.Attach // which will complete the hookup with AD7 IDebugPort2 port; EngineUtils.RequireOk(process.GetPort(out port)); IDebugDefaultPort2 defaultPort = (IDebugDefaultPort2)port; IDebugPortNotify2 portNotify; EngineUtils.RequireOk(defaultPort.GetPortNotify(out portNotify)); EngineUtils.RequireOk(portNotify.AddProgramNode(new AD7ProgramNode(debuggedProcess.Id))); if (m_ad7ProgramId == Guid.Empty) { Debug.Fail("Unexpected problem -- IDebugEngine2.Attach wasn't called"); return(EngineConstants.E_FAIL); } debuggedProcess.ResumeFromLaunch(); // Resume the threads in the debuggee process /*m_pollThread.RunOperation(new Operation(delegate * { * m_debuggedProcess.ResumeFromLaunch(); * }));*/ return(EngineConstants.S_OK); } catch (ComponentException e) { return(e.HRESULT); } catch (Exception e) { return(EngineUtils.UnexpectedException(e)); } }
// Attach the debug engine to a program. int IDebugEngine2.Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint celtPrograms, IDebugEventCallback2 ad7Callback, enum_ATTACH_REASON dwReason) { //Debug.Assert(Worker.MainThreadId == Worker.CurrentThreadId); Debug.Assert(m_ad7ProgramId == Guid.Empty); // MessageBox.Show("IDebugEngine2.Attach", "Debugger debugging", MessageBoxButtons.OK, 0); if (celtPrograms != 1) { Debug.Fail("SampleEngine only expects to see one program in a process"); throw new ArgumentException(); } try { int processId = EngineUtils.GetProcessId(rgpPrograms[0]); if (processId == 0) { return(EngineConstants.E_NOTIMPL); // sample engine only supports system processes } EngineUtils.RequireOk(rgpPrograms[0].GetProgramId(out m_ad7ProgramId)); // Attach can either be called to attach to a new process, or to complete an attach // to a launched process /* if (m_pollThread == null) * { * // We are being asked to debug a process when we currently aren't debugging anything * m_pollThread = new WorkerThread(); * * m_engineCallback = new EngineCallback(this, ad7Callback); * * // Complete the win32 attach on the poll thread * m_pollThread.RunOperation(new Operation(delegate * { * m_debuggedProcess = Worker.AttachToProcess(m_engineCallback, processId); * })); * * m_pollThread.SetDebugProcess(m_debuggedProcess); * } * else * { * if (processId != m_debuggedProcess.Id) * { * Debug.Fail("Asked to attach to a process while we are debugging"); * return EngineConstants.E_FAIL; * } * * m_pollThread.SetDebugProcess(m_debuggedProcess); * } */ AD7EngineCreateEvent.Send(this); AD7ProgramCreateEvent.Send(this); // start polling for debug events on the poll thread /*m_pollThread.RunOperationAsync(new Operation(delegate * { * m_debuggedProcess.ResumeEventPump(); * }));*/ return(EngineConstants.S_OK); } catch (ComponentException e) { return(e.HRESULT); } catch (Exception e) { return(EngineUtils.UnexpectedException(e)); } }