How can I debug a crashing application on OS X?

Solution 1:

One possible way would be running:

sudo dtruss -n <app_executable>

where <app_executable> is the name of the executable file in the the app bundle in the Contents\MacOS folder inside the app.

For example, if you wanted to debug iTunes, you would first find out the executable name:

ls -alh /Applications/iTunes.app/Contents/MacOS/

drwxr-xr-x  5 root wheel 170 Mar 30 21:01 .
drwxr-xr-x 11 root wheel 374 Mar 30 21:01 ..
drwxr-xr-x  3 root wheel 102 Mar 30 21:02 iTunesHelper.app
-rwxr-xr-x  1 root wheel 29M Mar 29 02:01 iTunes <<<<<<<< this one
-rwxr-xr-x  1 root wheel 18K Mar 29 02:00 iTunesASUHelper

You can also do it by right-clicking an app in Finder and selecting Show Package Contents.

Once you figured out it is iTunes you can use the following command:

sudo dtruss -n iTunes

This will display a lot low-level info, but might contain something useful to identify the cause of a crash.

Other potentially useful built-in utilities are: iosnoop, iotop, opensnoop, execsnoop, opensnoop which are all based on dtrace which is also usable on its own. They all have man pages so you can use e.g. man iosnoop in a terminal for details on usage. All of them require sudo.