How to use addr2line in Android

匿名 (未验证) 提交于 2019-12-03 01:59:02

问题:

I am stuck with my app, as I am unable to debug as it is a multithreaded one and crashes with error SIGSEGV. I get lot of information from LogCat, which gives me addresses in my native library. It would be helpful if I could convert these addresses into my code.

Does anybody have any idea how to use addr2line, which is provided with android-ndk?

回答1:

Let's say that logcat show you the following crash log (this is from one of my projects):

I/DEBUG   (   31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** I/DEBUG   (   31): Build fingerprint: 'generic/sdk/generic:2.3/GRH55/79397:eng/test-keys' I/DEBUG   (   31): pid: 378, tid: 386  >>> com.example.gltest 

Look at the last 3 lines; this is your callstack. 'pc' is the program counter, and the pc for stack frame #00 gives you the address where the crash occurred. This is the number to pass to addr2line.

I'm using NDK r5, so the executable I'm using is located at $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin; make sure that is in your $PATH. The command to use looks like

arm-linux-androideabi-addr2line -C -f -e obj/local/armeabi/libXXX.so 

Or, for the case above:

arm-linux-androideabi-addr2line -C -f -e obj/local/armeabi/libnativemaprender.so 0003deb4 

Which gives you the location of the crash.

Note:

  • The -C flag is to demangle C++ code
  • Use the .so file under obj/local/armeabi, since this is the non-stripped version

Also, when using NDK r5 with a 2.3 AVD, it is actually possible to debug multithreaded code.



回答2:

There's an easier way to do this now (ndk-r7). Check out the ndk-stack command. The docs are in you_android_ndk_path/docs/NDK-STACK.html



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!