OSX “strace” equivalent: dtruss – seeing inside applications what they do and why they hang

I am running OSX desktops coming from Linux background. We cross-develop software both on OSX and Linux. I am familiar of debugging system issues on Linux using strace command and now I had to try something similar on OSX. strace prints out system calls a running application makes so you can see “inside” the application and see where it crashes, hangs, etc.

OSX doesn’t have strace, but has its equivalent dtrace which originates from Solaris and I believe it has replaced OSX ktrace, truss etc. commands since OSX 10.5 Leopard.

Here are brief instructions how I tracked down a non-working Subversion svn up command. svn was correctly updating some repositories, but not others and just hung which means it probably hung on some system call.

Turns out dtrace itself is a very low level framework which its own programming language. I just want to dump the system calls. So there exist an utility called dtruss for this purpose.

But the first attempt failed:

dtruss svn up
dtrace: failed to initialize dtrace: DTrace requires additional privileges

You could solve this by running dtruss as root, but we really don’t want to do that. You can enable normal user execution for dtruss / dtrace with the following command:

sudo chmod u+s /usr/sbin/dtrace

Now we dtruss get output:

dtruss svn up
...
write(0x5, "( set-path ( 0: 94 false ( ) infinity ) ) ( link-path ( 10:thirdparty 31:svn+ssh://repo-svn/thirdparty 107 false ( ) infinity ) ) ( finish-report ( ) ) \0", 0x9A)         = 154 0
read(0x6, "( success ( ( ) 0: ) ) ( failure ( ( 170000 82:'svn+ssh://repo-svn/thirdparty' is not the same repository as 'svn+ssh://indweb' 63:/build/buildd/subversion-1.6.12dfsg/subversion/svnserve/serve.c 310 ) ) ) \0", 0x1000)         = 207 0
fcntl(0x5, 0x3, 0x0)         = 1 0
fcntl(0x5, 0x4, 0x5)         = 0 0
write(0x5, "( failure ( ( 210001 25:Unknown command 'failure' 34:subversion/libsvn_ra_svn/editorp.c 887 ) ) ) \0", 0x62)         = 98 0
fcntl(0x5, 0x3, 0x0)         = 5 0
fcntl(0x5, 0x4, 0x1)         = 0 0
read(0x6, "( failure ( ( 210001 25:Unknown command 'failure' 70:/build/buildd/subversion-1.6.12dfsg/subversion/libsvn_ra_svn/marshal.c 931 ) ) ) \0", 0x1000)         = 134 0
__disable_threadsignal(0x1, 0x0, 0x0)         = 0 0

… and there it hangs. Unknown command “failure”. In the end this all was not very helpful and I decided just selfupdate Macports and take clean checkout.

1. More info

 

 Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

2 thoughts on “OSX “strace” equivalent: dtruss – seeing inside applications what they do and why they hang

  1. sudo chmod u+s /usr/sbin/dtrace

    You have just opened big security hole on your mac. Congratulations.

  2. Maybe some constructive criticism for the alternative way to do this?

    You know, it’s my local Mac. I use it for development. I need to run dtrace as root.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>