MacOS – How to debug a crashing application on OS X

crashgamesmacos

I have a game installed from Steam on my Mac (Crusader Kings II). The most recent patch from the developer has been having crashes and freezes on my Mac, and I'd like to help give the developer as much debugging information as possible (I'm an iOS developer myself).

One of the problems with the game involved the game completely freezing up. To assist in debugging, I used the Time Profiler from Xcode Instruments and attached it to the game. When it froze, I could see what exactly was using up processor time, and I've reported this to the developer.

However, the other problem with the game is a hard crash to the desktop. Normally, when applications (like Xcode) completely crash, OS X will give me an error report that will include useful information, like the stack trace. However, when this game crashes, I get nothing. It just completely disappears. The process is no longer in the Force Quit list, but I also get no crash report.

Is there any way, using Xcode Instruments, or any other means, to determine exactly what state the application is in in the instant just before it crashes?

My computer is a Mac Mini (late 2012 model) and I'm on OS X 10.10.1 if that matters.

Best Answer

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.