How to use addr2line in Android
Solution 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 <<<
I/DEBUG ( 31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
I/DEBUG ( 31): r0 001dbdc0 r1 00000001 r2 00000000 r3 00000000
I/DEBUG ( 31): r4 00000000 r5 40a40000 r6 4051a480 r7 42ddbee8
I/DEBUG ( 31): r8 43661b24 r9 42ddbed0 10 42ddbebc fp 41e462d8
I/DEBUG ( 31): ip 00000001 sp 436619d0 lr 83a12f5d pc 8383deb4 cpsr 20000010
I/DEBUG ( 31): #00 pc 0003deb4 /data/data/com.example.gltest/lib/libnativemaprender.so
I/DEBUG ( 31): #01 pc 00039b76 /data/data/com.example.gltest/lib/libnativemaprender.so
I/DEBUG ( 31): #02 pc 00017d34 /system/lib/libdvm.so
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 <address>
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.
Solution 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
Related videos on Youtube

Anil Arrabole
Android and web developer with telecom, mobile and media domain experience.
Updated on July 05, 2022Comments
-
Anil Arrabole 5 months
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?
-
Anil Arrabole over 11 yearsGreat, Excellent. Thanks for the detailed answer. It worked for me 100%. Thank you and an up vote for you.
-
Ali Hidim over 11 yearsBrilliant, got this working thanks to you - I was struggling using the
.so
file inlibs
, which of course is stripped. The one inobj
works. -
Chris Markle over 11 yearsavdree - I'd encourage you to show the actual output of add2line in this otherwise very good answer.
-
alk3ovation over 10 yearsI tried the first answer by svdree and couldn't get any good output. I tried this one and it showed me the exact line my code was crashing on! Thanks Byron!
-
Morten Jensen over 10 yearsJust a comment, the addr2line utility can be used with any (GNU-produced?) binary containing debug symbols. Works for the desktop and embedded targets as well :)
-
Josh about 10 yearsMuch easier than addr2line used to be!
-
Ehtesh Choudhury over 9 yearsI would very much like a link/resource, if you could put one up.
-
Kushal over 7 yearsI am not using any native library except
android-support-v4
.. So is it possible that i can useaddr2line
tool to get line number of crash in java file.. i have added details at [stackoverflow.com/q/30093772/1994950].. -
Aadishri over 7 yearsThis is really good! (ndk-stack.html)[developer.android.com/ndk/guides/ndk-stack.html]
-
Mahendra Chhimwal over 6 yearsMy project logs says #00 pc 0025e520 [heap] #01 pc 0002230f /system/lib/libbinder.so (android::Parcel::freeDataNoInit()+22) #02 pc 00022371 /system/lib/libbinder.so (android::Parcel::~Parcel()+4) what adress I suppose to provide for these system/libs file like obj/local/armeabi/libnativemaprender.so
-
fillobotto almost 6 yearsI wanted to move your attention on the second note: Use the .so file under obj/local/<abi>. Lifesaver
-
George Thomas almost 5 years"directory containing symbolic versions of your app's shared libraries." How can we find the shared library for a xamarin forms android application
-
Angelina almost 4 yearsarm-linux-androideabi-addr2line: 'obj/local/armeabi/libart.so': No such file why?