http://www.codexperiments.com/android/2010/08/tips-tricks-debugging-android-ndk-stack-traces/
http://crazydaks.com/debugging-in-android-with-tombstones.html
http://blog.csdn.net/coder_jack/archive/2010/06/28/5700348.aspx
Everytime a process crashes under Android, a so called Tombstone is written for the process. A tombstone is a file containing important information about the process when it crashed. A slimmed core dump of sorts.
It is printed out in the log (can be seen in the printout using adb shell logcat), but the tombstones are also saved and stored on target under /data/tombstones/ and are called tombstone_XX where XX is a number increased by one with each crash.
To get a stacktrace for the crashed process containing file and line information we need to cross reference
the tombstone with the debugging symbols located on the host. generally the debug symbols are stripped when the libraries are loaded in the rootfs to save space. Hence you may need to dig the appropriate /out/product/xxx/symbols/system/libxx to get the unstripped libraries. Once that you can extract the line number and function name etc from a uitility called addr2line. this is generally found in the prebuilt directory of android source distribution. $(android-root)prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin is the normal location.
hence once you have located the unstripped libraries and location of addr2line tool on your host its as simple as using the addr2line command.
$(android-root)prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/addr2line -f -e /out/product/xxx/symbols/system/libc.so 0xbe8c1630 if 0xbe8c1630 is one of the symbols in the strack trace from library libc.so. is a typical dump for a system that underwent 6 crashes on my target.
# ls -l /data/tombstones
-rw——- system system 24216 2000-01-01 00:04 tombstone_02
-rw——- system system 22684 2000-01-01 00:03 tombstone_01
-rw——- system system 21913 2000-01-01 00:02 tombstone_06
-rw——- system system 24216 2000-01-01 00:04 tombstone_03
-rw——- system system 24322 2000-01-01 00:10 tombstone_05
-rw——- system system 22612 2000-01-01 00:02 tombstone_04
-rw——- system system 24665 2000-01-01 00:02 tombstone_00
# cat tombstone_01
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: ‘generic/myboard_xxx/xxx/myplatform:2.1/ERD79/eng.arunks.20100726.14330
8:eng/test-keys’
pid: 1138, tid: 1138 >>> /system/bin/bluetoothd <<<
signal 11 (SIGSEGV), fault addr deadbaad
r0 00000000 r1 afe13369 r2 00000027 r3 00000054
r4 afe3ae08 r5 00000000 r6 00000000 r7 0000a000
r8 00000000 r9 00000000 10 00000000 fp 00000000
ip 00002ed8 sp bec782d8 lr deadbaad pc afe10a20 cpsr 60000030
#00 pc 00010a20 /system/lib/libc.so
#01 pc 0000b332 /system/lib/libc.so
#02 pc 0000ca62 /system/lib/bluez-plugin/audio.so
#03 pc 0000d1ce /system/lib/bluez-plugin/audio.so
#04 pc 0000e0ba /system/lib/bluez-plugin/audio.so
#05 pc 0002f9a2 /system/lib/libbluetoothd.so
#06 pc 00026806 /system/lib/libbluetoothd.so
#07 pc 00026986 /system/lib/libbluetoothd.so
#08 pc 0002800c /system/lib/libbluetoothd.so
#09 pc 00028b72 /system/lib/libbluetoothd.so
#10 pc 0001891a /system/lib/libbluetoothd.so
#11 pc 0000c228 /system/lib/libc.so
code around pc:
afe10a10 f8442001 4798000c e054f8df 26002227
afe10a20 2000f88e ef2cf7fb f7fd2106 f04fe80a
afe10a30 91035180 460aa901 96012006 f7fc9602
code around lr:
deadba9c ffffffff ffffffff ffffffff ffffffff
deadbaac ffffffff ffffffff ffffffff ffffffff
deadbabc ffffffff ffffffff ffffffff ffffffff
stack:
bec78298 bec78334 [stack]
bec7829c bec7838b [stack]
bec782a0 afe3b02c /system/lib/libc.so
is a typical tombstone dump from my system….
Stuck in the hell of crashing applications? Don’t know how to find the tiny allocation or deallocation mistake hidden in a code stack of thousands of lines? Here is your way to heaven.
08-22 23:27:40.730: INFO/DEBUG(65): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 08-22 23:27:40.730: INFO/DEBUG(65): Build fingerprint: 'htc_wwe/htc_bravo/bravo/bravo:2.2/FRF91/218634:user/release-keys' 08-22 23:27:40.730: INFO/DEBUG(65): pid: 2474, tid: 2485 >>> com.test <<< 08-22 23:27:40.730: INFO/DEBUG(65): signal 11 (SIGSEGV), fault addr 00000001 08-22 23:27:40.730: INFO/DEBUG(65): r0 00000001 r1 00000000 r2 afd438e4 r3 00000001 08-22 23:27:40.730: INFO/DEBUG(65): r4 4825395c r5 00001000 r6 00001000 r7 00000001 08-22 23:27:40.730: INFO/DEBUG(65): r8 48253ad8 r9 432faf40 10 802a3448 fp 432faf40 ... 08-22 23:27:40.730: INFO/DEBUG(65): d30 0000000000000000 d31 0000000000000000 08-22 23:27:40.730: INFO/DEBUG(65): scr 80000012 08-22 23:27:40.790: INFO/DEBUG(65): #00 pc 00018656 /data/data/com.test/lib/libmylib.so 08-22 23:27:40.790: INFO/DEBUG(65): #01 pc 000186d2 /data/data/com.test/lib/libmylib.so 08-22 23:27:40.790: INFO/DEBUG(65): #02 pc 00018708 /data/data/com.test/lib/libmylib.so ...
Well if you understand that, then it means that either you’re an overly talented developer or you’d rather look for an ophthalmologist . But you’re just a normal coder, than at best you know that this is a stack trace. An Android native stack trace to be more precise, generated after an application crash.
Hopefully, some tools are available to “decrypt” that mysterious data: arm-eabi-addr2line. This tools is in the “${ANDROID_NDK}/build/prebuilt/linux-x86/arm-eabi-[version]/bin/” directory which contains some utility tools for ARM processors. And combine with the original library that generated it, you can find the incriminated methods and file lines. And that’s priceless when you can’t debug your code!
First ensure your native code is compiled in Debug mode to access code information (“APP_OPTIM := debug” in your application.mk). Then call the executable with your .so compiled library, for example:
${Android-NDK}/build/prebuilt/linux-x86/arm-eabi-[version]/bin/arm-eabi-addr2line -C -f -e libmylib.so
Then just type the address, the one you can find after the “pc” directive, for example:
00018656
taken from line “#00 pc 00018656 /system/lib/libstlport.so“.
That’s all!