How to trace a program from its very beginning without running it as root
dtrace, macos
Solution
Something like `sudo dtruss -f sudo -u <original username> <command>` has worked for me, but I felt bad about it afterwards.
I filed a Radar bug about it and had it closed as a duplicate of #5108629.
Problem
I'm writing a tool that calls through to DTrace to trace the program that the user specifies. If my tool uses dtrace -c to run the program as a subprocess of DTrace, not only can I not pass any arguments to the program, but the program runs with all the privileges of DTrace—that is, as root (I'm on Mac OS X). This makes certain things that should work break, and obviously makes a great many things that shouldn't work possible. The other solution I know of is to start the program myself, pause it by sending it `SIGSTOP`, pass its PID to `dtrace -p`, then continue it by sending it `SIGCONT`. The problem is that either the program runs for a few seconds without being traced while DTrace gathers the symbol information or, if I sleep for a few seconds before continuing the process, DTrace complains that `objc<pid>:<class>:<method>:entry` matches no probes. Is there a way that I can run the program under the user's account, not as root, but still have DTrace able to trace it from the beginning?