ptrace() with multithreaded tracer

From: Niklas HambÃchen
Date: Sat Feb 16 2019 - 20:54:40 EST


Hello,

it would be awesome if somebody in the know could confirm or refute a suspicion on ptrace() that we have.

The man page says:

Attachment and subsequent commands are per thread:
in a multiâ threaded process, every thread can be individually attached to a
(potentially different) tracer, or left not attached and thus not debugged.
Therefore, "tracee" always means "(one) thread", never "a (possibly
multithreaded) process".

While the first sentence "Attachment ... [is] per thread" is quite general, the rest talks only about the multi-threadedness of the *tracee*.

What about multithreaded *tracers*?

We suspect (and observe program behaviour that supports this) that having one thread pA_t1 in a process A become the tracer of some tracee thread pB_t1, and then a different thread of A, pA_t2 running a `ptrace(pB_t1, ...)` is illegal and results in `ESRCH`.

Is this statement in true in general, or are there nuances?

Thanks,
Niklas


PS: We'd be happy to contribute these details to the man page based on an answer :)