开发者

Can I spawn processes attached to a running debugger?

Imagine I have a program that spawns some processes (pseudo code)

main() {
   p1 = Spawn( "ClientProcess" );

   WaitForEventFrom( p1 );
}

Would it be possible to detect if the 'main' is a开发者_JAVA百科ttached to a debugger, and automatically attach that debugger to the client processes?

Bonus question: can it be done without changing the source code/executables?

(Note: I'm on windows, using VS2010. But any (decent) debugger would do)


You can use IsDebuggerPresent() to know if main() is being debugged.

But, you cannot redirect the VS debugger to un-attach and re-attach to the spawned process from within a debugged process.

The best I can imagine is spawning a new instance of vs attempting to attach it to clientprocess. It would probably be easier to spawn windbg and have that attached to ClientProcess since the commandline support for the pid, etc is there.

This would obviously also not work if the app is being remotely debugged (CheckRemoteDebuggerPresent() returns true) since you'd need to launch and attach from the remote system. Too many issues there...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜