All pastes #1246683 Raw Edit

Anonymous

public diff v1 · immutable
#1246683 ·published 2008-11-06 10:05 UTC
rendered paste body
Hello,I am developing a debugger and recently run into a strange problemwith ptrace() which showed up between 2.6.25.16 and 2.6.28-rc3.I'm using	int flags = PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK |		PTRACE_O_TRACEEXEC;	ptrace (PTRACE_SETOPTIONS, pid, 0, flags);after starting the target application and then do a	ret = waitpid (pid, status, WUNTRACED | __WALL | __WCLONE);in a special worker thread.My problem is that with recent kernels, I sometimes get the initialSIGSTOP event for a newly created thread before the `PTRACE_EVENT_CLONE'event for that thread.This causes two problems for me:a) I'm getting a SIGSTOP for an unknown PID, so I have to decide what   to do with it.   It seems that ptrace (PT_GETRETGS) on that PID sometimes works and   sometimes doesn't - what's going on here ?  Can I debug the new   thread just after receiving its initial SIGSTOP or do I need to   wait until the `PTRACE_EVENT_CLONE' ?b) After getting the PTRACE_EVENT_CLONE, there seems to be no reliable   way for me to wait until this new thread has stopped.   If I understand things correctly, you can't waitpid() on a thread   which is already stopped, so how do I check whether the newly   created thread has already stopped ?I put some really bad hack to work around this problem into thedevelopment version of our product, but I'd be very happy to hear aboutan official solution.Thanks,Martin Baulig