Skip to content

Android and stack traces

While doing native development for the Android platform, native segmentation faults happen. And they are not very descriptive to the usual developer (which includes me, of course). You would see something along those lines:

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/GT-I9100/GT-I9100:2.3.3/GINGERBREAD/XWKE2:user/release-keys'
pid: 3833, tid: 4464 >>> <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
r0 00000027 r1 deadbaad r2 a0000000 r3 00000000
r4 00000001 r5 00000000 r6 00000000 r7 00000004
r8 00000001 r9 47e279dc 10 47e279e0 fp 47e270b4
ip afd46688 sp 47e27048 lr afd19471 pc afd15f40 cpsr 60000030
d0 0000009643160000 d1 3ff0000043160000
d2 0000000000000000 d3 0000000000000000
d4 bf80000000000000 d5 0000000000000000
d6 3f80000000000000 d7 4080000000000000
d8 4100000044228000 d9 c42cc000429c0000
d10 3fd3441341600000 d11 bfe3441350ad386e
d12 3ddb7cdfd9d7bdbb d13 0000000000000000
d14 0000000000000000 d15 0000000000000000
d16 0000000700000037 d17 3ff0000000000000
d18 3ff0000000000000 d19 0000000000000000
d20 0000000000000000 d21 0000000000000000
d22 3ff0000000000000 d23 0000000000000000
d24 3ff0000000000000 d25 0000000000000000
d26 0000000000000000 d27 0000000000000000
d28 bffe0d01b7ee0434 d29 3ff0000000000000
d30 0000000000000000 d31 3ff0000000000000
scr 60000013
#00 pc 00015f40 /system/lib/
#01 pc 000140a4 /system/lib/
#02 pc 0001475a /system/lib/

Now this is not very helpful, BUT, you can use the stack tool (but in my case, stack tool breaks on one too many variables (I have a custom build, with different library paths, etc)) or you can manually translate the location of PC with a tool called addr2line (in my case arm-linux-androideabi-addr2line - use something like

find . | grep addr2line

in your Android NDK directory). You can find the function name by setting a couple of parameters to addr2line. In the output

#00 pc 00015f40 /system/lib/

you see the address (00015f40) and the library name (/system/lib/ You can use addr2line tool to show the function name:

./addr2line -f -e /path/to/ 0x00015f40

and the output will be


Also, a helpful article on analyzing Android seg faults.

Another useful tool for analyzing stack traces is also android ndk stacktrace analyzer. Additional thing to note is, that if you have addresses in the upper range (0x8xxxxxxx), you can subtract 0x81800000 from that address and use addr2line tool for that.

Hopefully, this helps someone.

Posted in Uncategorized.

WP SlimStat