Experimenting with the ptrace() system call, I am trying to trace another thread of the same process. According to the man page, both the tracer and the tracee are specific threads (not processes), so I don't see a reason why it should not work. So far, I have tried the following:
- use
PTRACE_TRACEMEfrom theclone()d child: the call succeeds, but does not do what I want, probably because the parent of the to-be-traced thread is not the thread that calledclone() - use
PTRACE_ATTACHorPTRACE_SEIZEfrom the parent thread: this always fails withEPERM, even if the process runs as root and withprctl(PR_SET_DUMPABLE, 1)
In all cases, waitpid(-1, &status, __WALL) fails with ECHILD (same when passing the child pid explicitly).
What should I do to make it work?
If it is not possible at all, is it by desing or a bug in the kernel (I am using version 3.8.0). In the former case, could you point me to the right bit of the documentation?