Quick, dirty and definitely problematic enable of Linux ptrace support.
The main issue with linux ptrace, was that fork1 is called with RFSTOPPED and TDB_STOPATFORK. fork1 will block waiting for the thread do stop, but is not started so it hangs forever.
This is true not only for linux_fork* but for any other thread forked with RFSTOPPED & TDB_STOPATFORK.
In this patch I have moved the wait to a separate function fork_finish. It is not called in fork1 if RFSTOPPED is set. Calls to fork_finish are added after the thread is scheduled in the linux_fork * functions.
The only other change to enable ptrace is adding TDB_BORN in linux_clone_proc on new thread created.
Obvious problems:
racct_proc_fork_done is moved in this function. I have no idea what this is and if should stay in fork1 before the return. There are plenty of other callsites for fork1 that should also have fork_finish called. Some of them like the kthread* hopefully can't have TDB_STOPATFORK but some might have.
The code like this works, i.e. truss & gdb are fully functional on Linux binaries and I have not experienced issues.
Posting the code like this, as suggested by kib in the freebsd-emulation thread. The difference with initial patch there, is that I have moved the common code the fork_finish function.