Friday, October 14, 2011

From Device Crash Log to Stack Trace

Update:  If this doesn't work for you anymore, try this:
http://iphoneidoit.blogspot.com/2016/03/reading-crash-logs.html

There seems to be a few ways to get the stack trace from the device logs.  One way is a 3rd party solution where you implement their API and they can send you a nice stack trace.  Another way is by using symbolicate, which seemed out of date.

Until I get around to using the 3rd party solution I use the atos command.  Below is a step by step in how you can get a stack trace from your device's crash logs.  You will need the build that caused the crash and the crash log.  Note, there may be an easier way to do this, I just haven't looked more after finding this method.

A typical unreadable crash log contains something like this:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000008
Crashed Thread:  6

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:

0   libicucore.A.dylib            0x318fb3c8 0x31897000 + 410568
1   libsystem_c.dylib             0x3310850a 0x330bb000 + 316682
2   libicucore.A.dylib            0x31971744 0x31897000 + 894788
3   libicucore.A.dylib            0x318a59b8 0x31897000 + 59832
4   libicucore.A.dylib            0x3189fe98 0x31897000 + 36504
5   CoreFoundation                0x34c6b042 0x34bef000 + 507970
6   CoreFoundation                0x34c2f14a 0x34bef000 + 262474
7   Foundation                    0x320d4020 0x320aa000 + 172064
8   Foundation                    0x320d3efe 0x320aa000 + 171774
...

For starters, turn that into this:
0x318fb3c8 0x31897000 + 410568 0x3310850a 0x330bb000 + 316682 0x31971744 0x31897000 + 894788 0x318a59b8 0x31897000 + 59832 0x3189fe98 0x31897000 + 36504 0x34c6b042 0x34bef000 + 507970 0x34c2f14a 0x34bef000 + 262474 0x320d4020 0x320aa000 + 172064 0x320d3efe 0x320aa000 + 171774

Just take out the first two columns and the carriage returns.  Save this to a file in some easy to type directory like ~/memory_addresses.txt

Get the Build
Get the binary where the error was generated from.  It should have a filename of something like mycrashingapp.app.

ATOS command
Navigate to where the app binary file is and type in the following, replace the bold with your specific info.

atos -o mycrashingapp.app/mycrashingapp -arch armv6 -f ~/memory_addresses.txt > stack.txt

stack.txt should now contain some useful information on where the crash happened.

1 comment:

  1. Thankyou Thankyou Thankyou .. Your line saved me days of searching for the EXC BAD ACCESS error. My app was rejected on the appStore and I had no way of tracing it :(
    ..
    You have given me a headstart on the debugging..

    ReplyDelete