Cannot Detach from process using mdbg

3

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?

c#
.net
debugging
mdbg
asked on Stack Overflow Dec 18, 2008 by glenatron • edited May 23, 2017 by Community

2 Answers

2

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.

answered on Stack Overflow Dec 18, 2008 by glenatron • edited Dec 18, 2008 by glenatron
1

Try this:

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

or

Proc.CorProcess.Stop(0);  
Proc.Detach();
answered on Stack Overflow Nov 14, 2009 by Saurabh • edited May 9, 2010 by Simon P Stevens

User contributions licensed under CC BY-SA 3.0