views:

251

answers:

2

Following on from this question I now have code that can attach to a process using the Mdbg API.

The problem is that I can't detach from the process if I need to. When I call mgProcess.Detach().WaitOne(); ( where mgProcess is a MDbgProcess created from an MDbgEngine object ) I get the following error message:

 Process not synchronized. (Exception from HRESULT: 0x80131302)
     at Microsoft.Samples.Debugging.CorDebug.NativeApi.ICorDebugController.Detach()
     at Microsoft.Samples.Debugging.CorDebug.CorController.Detach() in C:\mdbg\src\debugger\corapi\Controller.cs:line 89
     at Microsoft.Samples.Debugging.MdbgEngine.MDbgProcess.Detach() in C:\mdbg\src\debugger\mdbgeng\Process.cs:line 716

If I just try to call mgProcess.Detach() or mgProcess.CorProcess.Detach() I get the same result.

Does anyone know the correct way to detach an Mdbg process?

A: 

It transpires that Mdbg will not allow you to do anything while the debugee is running.

  MgProcess.CorProcess.Stop(0);
  MgProcess.Detach();

Appears to be the way forward.

glenatron
+1  A: 

Try this:

proc.AsyncStop();
proc.Detach();

or

Proc.CorProcess.Stop(0);  
Proc.Detach();
Saurabh