这几天在在调试一个Android项目时,遇到了“signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad”异常,感觉是jni层操作内存不当引起的,由于是Android新手,没什么经验,而且调试ndk库又很麻烦,于是各种百度,各种搜索,ndk-stack,还是无法定位出现问题的地方,几乎奔溃!后面经过几经波折,单独测试了一些使用频繁的接口,果然,在一个jni接口中,java层传递的jbyteArray长度为1,这就奇怪了,查了下接口文档,tmd,应该是一时疏忽,写错了长度,jni库中需要操作的jbyteArray长度为8,而java层实际定义的长度为1,jni层操作时,拷贝8个字节的数据到jbyteArray,数组越界了,于是修改了长度,问题解决!
在Android ndk中遇到fault addr deadbaad异常,真的很让人头疼,不过大多数都是内存、指针等问题,往往都是一个疏忽导致了意想不到的BUG,所以在写代码时对于内存、指针的操作还是得特别地注意,像这次遇到的问题,我想大多数人还是会遇到的,所以贴出来跟大家分享一下,也给自己提个醒,下次再掉这坑里,那就埋了自己吧!!!
详细tombstone如下:
Build fingerprint: ‘Android/full_smdk4x12/smdk4x12:4.0.3/JILIN-V1.0.3/eng.root.20150730.174305:eng/test-keys‘
pid: 5318, tid: 5326 >>> com.genvict.m900 <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
r0 deadbaad r1 00000001 r2 40000000 r3 00000000
r4 00000000 r5 00000027 r6 58fd3980 r7 00000062
r8 40f1e018 r9 0000001a 10 58fd38d4 fp 58fd3918
ip ffffffff sp 58fd3898 lr 4009f149 pc 4009b8a8 cpsr 60000030
d0 42c8000042bb3cef d1 3ff00000004af418
d2 0000000000000000 d3 0000000000000000
d4 0000000000000000 d5 0000000000000000
d6 00500ff000000000 d7 0000005d4dea3acb
d8 0000000000000000 d9 0000000000000000
d10 0000000000000000 d11 0000000000000000
d12 0000000000000000 d13 0000000000000000
d14 0000000000000000 d15 0000000000000000
d16 000000c240acc7e0 d17 3ff0000000000000
d18 4198acab28000000 d19 0000000000000000
d20 0000000000000000 d21 0000000000000000
d22 0000000000000000 d23 0000000000000000
d24 0000000000000000 d25 0000000000000000
d26 0000000000000000 d27 0000000000000000
d28 0000000000000000 d29 0000000000000000
d30 0000000000000000 d31 0000000000000000
scr 80000012
#00 pc 000178a8 /system/lib/libc.so
#01 pc 00007984 /system/lib/libcutils.so (mspace_merge_objects)
#02 pc 0007b8a0 /system/lib/libdvm.so (_Z21dvmHeapSourceFreeListjPPv)
#03 pc 00042d98 /system/lib/libdvm.so
#04 pc 00032f7c /system/lib/libdvm.so (_Z22dvmHeapBitmapSweepWalkPK10HeapBitmapS1_jjPFvjPPvS2_ES2_)
#05 pc 00042d54 /system/lib/libdvm.so (_Z27dvmHeapSweepUnmarkedObjectsbbPjS_)
#06 pc 000337a8 /system/lib/libdvm.so (_Z25dvmCollectGarbageInternalPK6GcSpec)
#07 pc 000601a0 /system/lib/libdvm.so (_Z17dvmCollectGarbagev)
#08 pc 00072bc2 /system/lib/libdvm.so
#09 pc 00030a90 /system/lib/libdvm.so
code around pc:
4009b888 4623b15c 2c006824 e026d1fb b12368db \.#F$h.,..&..h#.
4009b898 21014a17 6011447a 48124798 24002527 .J.!zD.`.G.H‘%.$
4009b8a8 f7f47005 2106ee4c eedaf7f5 460aa901 .p..L..!.......F
4009b8b8 f04f2006 94015380 94029303 eaa4f7f5 . O..S..........
4009b8c8 4622a905 f7f52002 f7f4eaae 2106ee38 .."F. ......8..!
code around lr:
4009f128 41f0e92d 46804c0c 447c2600 68a56824 -..A.L.F.&|D$h.h
4009f138 e0076867 300cf9b5 dd022b00 47c04628 gh.....0.+..(F.G
4009f148 35544306 37fff117 6824d5f4 d1ee2c00 .CT5...7..$h.,..
4009f158 e8bd4630 bf0081f0 000283b2 41f0e92d 0F..........-..A
4009f168 fb01b086 9004f602 461f4815 4615460c .........H.F.F.F
memory map around addr deadbaad:
bed26000-bed47000 [stack]
(no map for address)
ffff0000-ffff1000 [vectors]
stack:
58fd3858 00000000
58fd385c 00000000
58fd3860 00000000
58fd3864 00000000
58fd3868 400c770c /system/lib/libc.so
58fd386c 400cc808
58fd3870 00000000
58fd3874 4009f149 /system/lib/libc.so
58fd3878 00000000
58fd387c 58fd38ac
58fd3880 58fd3980
58fd3884 00000062
58fd3888 40f1e018 /dev/ashmem/dalvik-heap (deleted)
58fd388c 4009e2b5 /system/lib/libc.so
58fd3890 df0027ad
58fd3894 00000000
#00 58fd3898 00000000
58fd389c 00000000
58fd38a0 010467a0 [heap]
58fd38a4 40fa57c8 /dev/ashmem/dalvik-heap (deleted)
58fd38a8 00000004
58fd38ac fffffbdf
58fd38b0 010467a0 [heap]
58fd38b4 40fa57c0 /dev/ashmem/dalvik-heap (deleted)
58fd38b8 40f1e010 /dev/ashmem/dalvik-heap (deleted)
58fd38bc 40063987 /system/lib/libcutils.so
#01 58fd38c0 010467a0 [heap]
58fd38c4 40fa5758 /dev/ashmem/dalvik-heap (deleted)
58fd38c8 58fd3980
58fd38cc 408938a3 /system/lib/libdvm.so
#02 58fd38d0 00000062
58fd38d4 000004ec
58fd38d8 58fd3b5c
58fd38dc 00000062
58fd38e0 00005c60
58fd38e4 00549b00
58fd38e8 50a70040 /dev/ashmem/dalvik-bitmap-1 (deleted)
58fd38ec 000054a2
58fd38f0 50ec8040 /dev/ashmem/dalvik-bitmap-2 (deleted)
58fd38f4 4085ad9c /system/lib/libdvm.so
#03 58fd38f8 0000546e
58fd38fc 58fd3918
58fd3900 010467fc [heap]
58fd3904 0000222c
58fd3908 0000549b
58fd390c 4084af80 /system/lib/libdvm.so
#04 58fd3910 80000000
58fd3914 58fd3a98
58fd3918 40fa3f20 /dev/ashmem/dalvik-heap (deleted)
58fd391c 40fa3f40 /dev/ashmem/dalvik-heap (deleted)
58fd3920 40fa3f98 /dev/ashmem/dalvik-heap (deleted)
58fd3924 40fa3fb8 /dev/ashmem/dalvik-heap (deleted)
58fd3928 40fa4028 /dev/ashmem/dalvik-heap (deleted)
58fd392c 40fa4048 /dev/ashmem/dalvik-heap (deleted)
58fd3930 40fa40b0 /dev/ashmem/dalvik-heap (deleted)
58fd3934 40fa40d0 /dev/ashmem/dalvik-heap (deleted)
58fd3938 40fa4148 /dev/ashmem/dalvik-heap (deleted)
58fd393c 40fa4168 /dev/ashmem/dalvik-heap (deleted)
58fd3940 40fa41d0 /dev/ashmem/dalvik-heap (deleted)
58fd3944 40fa41f0 /dev/ashmem/dalvik-heap (deleted)
58fd3948 40fa4a08 /dev/ashmem/dalvik-heap (deleted)
58fd394c 40fa4a20 /dev/ashmem/dalvik-heap (deleted)
58fd3950 40fa4a68 /dev/ashmem/dalvik-heap (deleted)
58fd3954 40fa4ef8 /dev/ashmem/dalvik-heap (deleted)
58fd3958 40fa4f60 /dev/ashmem/dalvik-heap (deleted)
58fd395c 40fa4f98 /dev/ashmem/dalvik-heap (deleted)
58fd3960 40fa4fb8 /dev/ashmem/dalvik-heap (deleted)
58fd3964 40fa5010 /dev/ashmem/dalvik-heap (deleted)
58fd3968 40fa5038 /dev/ashmem/dalvik-heap (deleted)
58fd396c 40fa5058 /dev/ashmem/dalvik-heap (deleted)
58fd3970 40fa5068 /dev/ashmem/dalvik-heap (deleted)
58fd3974 40fa5758 /dev/ashmem/dalvik-heap (deleted)
58fd3978 40fa5778 /dev/ashmem/dalvik-heap (deleted)
58fd397c 40fa57b0 /dev/ashmem/dalvik-heap (deleted)
58fd3980 40fa57c8 /dev/ashmem/dalvik-heap (deleted)
58fd3984 40fa57e0 /dev/ashmem/dalvik-heap (deleted)
58fd3988 40fa57f8 /dev/ashmem/dalvik-heap (deleted)
58fd398c 40fa5810 /dev/ashmem/dalvik-heap (deleted)
58fd3990 40fa5830 /dev/ashmem/dalvik-heap (deleted)
58fd3994 40fa5850 /dev/ashmem/dalvik-heap (deleted)
58fd3998 40fa58e8 /dev/ashmem/dalvik-heap (deleted)
58fd399c 40fa5900 /dev/ashmem/dalvik-heap (deleted)
58fd39a0 40fa5920 /dev/ashmem/dalvik-heap (deleted)
58fd39a4 40fa5938 /dev/ashmem/dalvik-heap (deleted)
58fd39a8 40fa5950 /dev/ashmem/dalvik-heap (deleted)
58fd39ac 40fa5968 /dev/ashmem/dalvik-heap (deleted)
58fd39b0 40fa5a80 /dev/ashmem/dalvik-heap (deleted)
58fd39b4 40fa5ab8 /dev/ashmem/dalvik-heap (deleted)
58fd39b8 40fa5ad0 /dev/ashmem/dalvik-heap (deleted)
58fd39bc 40fa5af0 /dev/ashmem/dalvik-heap (deleted)
58fd39c0 40fa5b30 /dev/ashmem/dalvik-heap (deleted)
58fd39c4 40fa5b58 /dev/ashmem/dalvik-heap (deleted)
58fd39c8 40fa5b78 /dev/ashmem/dalvik-heap (deleted)
58fd39cc 40fa5bb8 /dev/ashmem/dalvik-heap (deleted)
58fd39d0 40fa5bd0 /dev/ashmem/dalvik-heap (deleted)
58fd39d4 40fa5da0 /dev/ashmem/dalvik-heap (deleted)
58fd39d8 40fa5dc0 /dev/ashmem/dalvik-heap (deleted)
58fd39dc 40fa5e20 /dev/ashmem/dalvik-heap (deleted)
58fd39e0 40fa5e38 /dev/ashmem/dalvik-heap (deleted)
58fd39e4 40fa5e50 /dev/ashmem/dalvik-heap (deleted)
58fd39e8 40fa5f68 /dev/ashmem/dalvik-heap (deleted)
58fd39ec 40fa5f88 /dev/ashmem/dalvik-heap (deleted)
58fd39f0 40fa5fa8 /dev/ashmem/dalvik-heap (deleted)
58fd39f4 40fa6000 /dev/ashmem/dalvik-heap (deleted)
58fd39f8 40fa60d0 /dev/ashmem/dalvik-heap (deleted)
58fd39fc 40fa6100 /dev/ashmem/dalvik-heap (deleted)
58fd3a00 40fa6118 /dev/ashmem/dalvik-heap (deleted)
58fd3a04 40fa6148 /dev/ashmem/dalvik-heap (deleted)
58fd3a08 40fa6168 /dev/ashmem/dalvik-heap (deleted)
58fd3a0c 40fa6180 /dev/ashmem/dalvik-heap (deleted)
58fd3a10 40fa61d8 /dev/ashmem/dalvik-heap (deleted)
58fd3a14 40fa61f8 /dev/ashmem/dalvik-heap (deleted)
58fd3a18 40fa6358 /dev/ashmem/dalvik-heap (deleted)
58fd3a1c 40fa63b0 /dev/ashmem/dalvik-heap (deleted)
58fd3a20 40fa63f8 /dev/ashmem/dalvik-heap (deleted)
58fd3a24 40fa64c8 /dev/ashmem/dalvik-heap (deleted)
58fd3a28 40fa64f8 /dev/ashmem/dalvik-heap (deleted)
58fd3a2c 40fa6518 /dev/ashmem/dalvik-heap (deleted)
58fd3a30 40fa6548 /dev/ashmem/dalvik-heap (deleted)
58fd3a34 40fa6570 /dev/ashmem/dalvik-heap (deleted)
58fd3a38 40fa6590 /dev/ashmem/dalvik-heap (deleted)
58fd3a3c 40fa6600 /dev/ashmem/dalvik-heap (deleted)
58fd3a40 40fa6628 /dev/ashmem/dalvik-heap (deleted)
58fd3a44 40fa6660 /dev/ashmem/dalvik-heap (deleted)
58fd3a48 40fa6730 /dev/ashmem/dalvik-heap (deleted)
58fd3a4c 40fa6760 /dev/ashmem/dalvik-heap (deleted)
58fd3a50 40fa6778 /dev/ashmem/dalvik-heap (deleted)
58fd3a54 40fa67a8 /dev/ashmem/dalvik-heap (deleted)
58fd3a58 40fa67c0 /dev/ashmem/dalvik-heap (deleted)
58fd3a5c 40fa6808 /dev/ashmem/dalvik-heap (deleted)
58fd3a60 40fa6820 /dev/ashmem/dalvik-heap (deleted)
58fd3a64 40fa6858 /dev/ashmem/dalvik-heap (deleted)
58fd3a68 40fa6928 /dev/ashmem/dalvik-heap (deleted)
58fd3a6c 40fa6958 /dev/ashmem/dalvik-heap (deleted)
58fd3a70 40fa6970 /dev/ashmem/dalvik-heap (deleted)
58fd3a74 40fa69a0 /dev/ashmem/dalvik-heap (deleted)
58fd3a78 40fa69b8 /dev/ashmem/dalvik-heap (deleted)
58fd3a7c 40fa6a00 /dev/ashmem/dalvik-heap (deleted)
58fd3a80 40fa6a18 /dev/ashmem/dalvik-heap (deleted)
58fd3a84 40fa6a60 /dev/ashmem/dalvik-heap (deleted)
58fd3a88 40fa6b30 /dev/ashmem/dalvik-heap (deleted)
58fd3a8c 40fa6b60 /dev/ashmem/dalvik-heap (deleted)
58fd3a90 40fa6b80 /dev/ashmem/dalvik-heap (deleted)
58fd3a94 40fa6bb0 /dev/ashmem/dalvik-heap (deleted)
58fd3a98 40fa6bd8 /dev/ashmem/dalvik-heap (deleted)
58fd3a9c 40fa6bf8 /dev/ashmem/dalvik-heap (deleted)
58fd3aa0 40f38ac8 /dev/ashmem/dalvik-heap (deleted)
58fd3aa4 40f38af0 /dev/ashmem/dalvik-heap (deleted)
58fd3aa8 00000002
58fd3aac 400cc474
58fd3ab0 00000000
58fd3ab4 40098c25 /system/lib/libc.so
58fd3ab8 400cc4b0
58fd3abc 400cc4b0
58fd3ac0 011c37a8 [heap]
58fd3ac4 011c37b8 [heap]
58fd3ac8 58fd3bb0
58fd3acc 400cc498
58fd3ad0 00000000
58fd3ad4 00000003
58fd3ad8 56b124e8 /dev/ashmem/dalvik-LinearAlloc (deleted)
58fd3adc 00000002
58fd3ae0 57786456 /data/dalvik-cache/system@framework@core.jar@classes.dex
58fd3ae4 00000002
58fd3ae8 00000004
58fd3aec 00000000
58fd3af0 00000004
58fd3af4 011c3ab0 [heap]
58fd3af8 011c3a60 [heap]
58fd3afc 40881df3 /system/lib/libdvm.so
58fd3b00 011c37a8 [heap]
58fd3b04 40099a89 /system/lib/libc.so
58fd3b08 01046740 [heap]
58fd3b0c 40f66028 /dev/ashmem/dalvik-heap (deleted)
58fd3b10 00000000
58fd3b14 80000000
58fd3b18 40a77f70 /dev/ashmem/dalvik-heap (deleted)
58fd3b1c 00000000
58fd3b20 00000001
58fd3b24 58fd3b70
58fd3b28 58fd3b68
58fd3b2c 010467fc [heap]
58fd3b30 58fd3b5c
58fd3b34 010467e8 [heap]
58fd3b38 4085ad74 /system/lib/libdvm.so
58fd3b3c 4085ad58 /system/lib/libdvm.so
#05 58fd3b40 4085ad74 /system/lib/libdvm.so
58fd3b44 58fd3b5c
58fd3b48 01109058 [heap]
58fd3b4c 00000002
58fd3b50 58fd3bd4
58fd3b54 58fd3bd0
58fd3b58 408cfc58 /system/lib/libdvm.so
58fd3b5c 00000185
58fd3b60 00005c60
58fd3b64 408cff01 /system/lib/libdvm.so
58fd3b68 40fa7210 /dev/ashmem/dalvik-heap (deleted)
58fd3b6c 40f1dfff /dev/ashmem/dalvik-heap (deleted)
58fd3b70 40f1e000 /dev/ashmem/dalvik-heap (deleted)
58fd3b74 40a5d000 /dev/ashmem/dalvik-heap (deleted)
58fd3b78 00b0d57f
58fd3b7c 408c8014 /system/lib/libdvm.so
58fd3b80 01046728 [heap]
58fd3b84 408caf90 /system/lib/libdvm.so
58fd3b88 fffffe4c
58fd3b8c 00b0d59c
58fd3b90 408cfc58 /system/lib/libdvm.so
58fd3b94 00b0d57f
58fd3b98 01046738 [heap]
58fd3b9c 4084b7ac /system/lib/libdvm.so
#06 58fd3ba0 01046738 [heap]
58fd3ba4 00000000
58fd3ba8 00000000
58fd3bac 56bc08e8 /dev/ashmem/dalvik-LinearAlloc (deleted)
58fd3bb0 00000000
58fd3bb4 010d4348 [heap]
58fd3bb8 00000004
58fd3bbc 40840640 /system/lib/libdvm.so
58fd3bc0 00000000
58fd3bc4 00b0d599
58fd3bc8 00b0d581
58fd3bcc 7fffffff
58fd3bd0 00000004
58fd3bd4 011061a0 [heap]
58fd3bd8 408caf01 /system/lib/libdvm.so
58fd3bdc 57509f74 /data/dalvik-cache/system@framework@core.jar@classes.dex
58fd3be0 4002ef34
58fd3be4 011061a0 [heap]
58fd3be8 40acc7e0 /dev/ashmem/dalvik-heap (deleted)
58fd3bec 40840640 /system/lib/libdvm.so
58fd3bf0 00000000
58fd3bf4 4002ef08
58fd3bf8 58fd3d50
58fd3bfc 408781a3 /system/lib/libdvm.so
#07 58fd3c00 57509f74 /data/dalvik-cache/system@framework@core.jar@classes.dex
58fd3c04 4088abc7 /system/lib/libdvm.so
#08 58fd3c08 57509f74 /data/dalvik-cache/system@framework@core.jar@classes.dex
58fd3c0c 40848a94 /system/lib/libdvm.so
#09 58fd3c10 4002ef1c
58fd3c14 011061b0 [heap]
58fd3c18 56bc08e8 /dev/ashmem/dalvik-LinearAlloc (deleted)
58fd3c1c 011061a0 [heap]
58fd3c20 40a618e0 /dev/ashmem/dalvik-heap (deleted)
58fd3c24 011061a0 [heap]
58fd3c28 408caf90 /system/lib/libdvm.so
58fd3c2c 58fd3c50
58fd3c30 56b124e8 /dev/ashmem/dalvik-LinearAlloc (deleted)
58fd3c34 58fd3c94
58fd3c38 00000000
58fd3c3c 00000000
58fd3c40 58fd3d50
58fd3c44 4084c234 /system/lib/libdvm.so
58fd3c48 400cc520
58fd3c4c 400cc520
58fd3c50 00000000
58fd3c54 00000000
--------- tail end of log /dev/log/main
版权声明:本文为博主原创文章,未经博主允许不得转载。
Android NDK fault addr deadbaad异常
原文地址:http://blog.csdn.net/jayzeng/article/details/48000447