Debugging with Android NDK stack traces

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!


转载自:http://www.codexperiments.com/android/2010/08/tips-tricks-debugging-android-ndk-stack-traces/


                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值