Wednesday, June 12, 2013

Using with JNI Stack Traces Debug JNI / C++ in Android SYSTEM_TOMBSTONE

First, your application which is written in C++ or being invoked over JNI will crash.

Hello! Honestly we both know it will crash a whole shitload. It's JNI -- what it really does is crash.

So, first we're writing JNI and that ensures we'll see this type of trash spewing out of logcat regularly.

I/DEBUG   ( 9753): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   ( 9753): Build fingerprint: 'verizon/voles/sholes/sholes:2.2.1/FRG83D/75603:user/release-keys'
I/DEBUG   ( 9753): pid: 10400, tid: 10408  >>> com.tresebrothers.games.heroesofsteel <<<
I/DEBUG   ( 9753): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000013
I/DEBUG   ( 9753):  r0 002ba6b4  r1 ffffffff  r2 002ba6a0  r3 002b9908
I/DEBUG   ( 9753):  r4 002a68f0  r5 00000d98  r6 00000400  r7 00000080

[/snip]

I/DEBUG   ( 9753): #01 448b8a50  80e9dad0
I/DEBUG   ( 9753):     448b8a54  8098ae80  /data/data/com.tresebrothers.games.heroesofsteel/lib/libheroesofsteel.so
I/BootReceiver( 9764): Copying /data/tombstones/tombstone_06 to DropBox (SYSTEM_TOMBSTONE)
E/InputDispatcher( 9764): channel '407abe08 com.tresebrothers.games.heroesofsteel/com.tresebrothers.games.heroesofsteel.HeroesOfSteel_android (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
E/InputDispatcher( 9764): channel '407abe08 com.tresebrothers.games.heroesofsteel/com.tresebrothers.games.heroesofsteel.HeroesOfSteel_android (server)' ~ Channel is unrecoverably broken and will be disposed!

I/ActivityManager( 9764): Process com.tresebrothers.games.heroesofsteel (pid 10400) has died.


That entire mess is worthless to us.

Foreign-language-we-do-not-know worthless to us.

We need to translate:
  • First, we download the data from the device (needs root.)
  • Second, we locate the translation tables (comes from the build.)
  • Third, we mash it all together with ndk-stack (comes from the NDK.)


Download the Tombstone Stack Traces

I ran the command
G:\stacks>"C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\adb.exe" pull /data/tombstones/

Had to make sure I had my shell running somewhere with permissions so that adb could write the tombstone files (AKA, not C:\Program Files)

ADB will chew on this for a minute and then print something like this:

pull: building file list...
pull: /data/tombstones/tombstone_01 -> ./tombstone_01
pull: /data/tombstones/tombstone_06 -> ./tombstone_06
pull: /data/tombstones/tombstone_07 -> ./tombstone_07
pull: /data/tombstones/tombstone_08 -> ./tombstone_08
pull: /data/tombstones/tombstone_05 -> ./tombstone_05
pull: /data/tombstones/tombstone_04 -> ./tombstone_04
pull: /data/tombstones/tombstone_02 -> ./tombstone_02
pull: /data/tombstones/tombstone_09 -> ./tombstone_09
pull: /data/tombstones/tombstone_00 -> ./tombstone_00
pull: /data/tombstones/tombstone_03 -> ./tombstone_03
10 files pulled. 0 files skipped.
1564 KB/s (607224 bytes in 0.379s)

This cannot be helped but at least your files were downloaded (if you were lucky.)


Locate the Translation Objects

They are located in {PROJ.ROOT}\obj\local\armeabi\

If you are using Cocos2d-x then it is like this:
G:\cocos2d-2.1rc0-x-2.1.2\YourCoolGame\proj.android\obj\local\armeabi


Run NDK-Stack

I ran the command
G:\android-ndk-r8d\ndk-stack.exe -sym G:\cocos2d-2.1rc0-x-2.1.2\HeroesOfSteel\proj.android\obj\local\armeabi -dump G:\strace\tombstone_06

If you do it all right you get something that looks like this and might tell you something about what is wrong with your program. Probably not. But it does include some line numbers which is better than afd11060 e2166903 1a000017 e5945000 e1a02004.

So this is what it ends up looking like:

********** Crash dump: **********
Build fingerprint: 'verizon/voles/sholes/sholes:2.2.1/FRG83D/75603:user/release-keys'
pid: 10322, tid: 10330  >>> com.tresebrothers.games.heroesofsteel <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 802bb1f8
Stack frame #00  pc 00013488  /system/lib/libc.so (dlfree)
Stack frame #01  pc 00014726  /system/lib/libc.so (free)
Stack frame #02  pc 00300528  /data/data/com.tresebrothers.games.heroesofsteel/lib/libheroesofsteel.so: Routine sqlite3MemFree in G:/cocos2d-2.1rc0-x-2.1.2/HeroesOfSteel/proj.android/../../StoryTeller
Core/proj.android/jni/../../Classes/sqlite3.c:15578


These were really useful pages




This 'addr2line' stuff is waaaaay too tedious to even consider. NDK-Stack is painful enough as is!

Love you, mean it.

-C

No comments: