开发者

Windows Debug Api - Detaching not working

I'm running my event loop in a thread that is created on attaching to target process. What I did before to detach was simply calling a function that would clear the debug and call DebugSetProcessKillOnExit etc. but getting bad return values I figured they must be called from the thread that I created. So I did, no errors now but the target process simply exits when I exit/detach myself.

At the moment I check for a bool in the event loop to check if I should detach (any better solutions?) and then do the following:


pEng->ClearHardwareBreakpoints();
DebugSetProcessKillOnExit(FALSE);
ContinueDebugEvent(pEng->pId, pEng->tId, DBG_CONTINUE); 
DebugActiveProcessStop(pEng->pId);

return 0;

ClearHardwareBreakpoints suspends the target thread, calls GetThreadContext with CONTEXT_DEBUG_REGISTERS and removes the debug registers with SetThreadContext and resuming the thread.

So, as I said, 开发者_高级运维the problem is that the debugged process exits with my process as well, as if the detaching did not work.

Any help is appreciated.


I found out the error: I was exiting my program before the thread had done its part (detaching).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜