如何使用NDK工具使用源代码编译库?

| 如何用源代码编译库? 我正在使用android ndk开发本机库。 有时我从logcat收到故障转储消息。
06-18 15:24:58.545: INFO/DEBUG(24667): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-18 15:24:58.545: INFO/DEBUG(24667): Build fingerprint: \'nvidia/harmony/harmony/harmony:2.2/FRF91/20110304.134348:eng/test-keys\'
06-18 15:24:58.545: INFO/DEBUG(24667): pid: 25870, tid: 26261  >>> com.andtv <<<
06-18 15:24:58.545: INFO/DEBUG(24667): signal 11 (SIGSEGV), fault addr 4a7b041c
06-18 15:24:58.545: INFO/DEBUG(24667):  r0 4a7b041c  r1 4a75220c  r2 00000200  r3 0000006d
06-18 15:24:58.545: INFO/DEBUG(24667):  r4 4a7b041d  r5 00000000  r6 82434ad0  r7 4a752768
06-18 15:24:58.545: INFO/DEBUG(24667):  r8 4a75220c  r9 000004b4  10 4a752777  fp 00000000
06-18 15:24:58.545: INFO/DEBUG(24667):  ip 00000000  sp 4a7521f8  lr 8202e11f  pc afd1d9cc  cpsr 00000030
06-18 15:24:58.545: INFO/DEBUG(24667):  d0  3fcc745e0ab0ad85  d1  3fd24aaf828e1369
06-18 15:24:58.545: INFO/DEBUG(24667):  d2  3fa56e5ff7cd8dc6  d3  3fe5568b9401f367
06-18 15:24:58.545: INFO/DEBUG(24667):  d4  bfc34e892d87a4ea  d5  bfd1c2b0f8ac7dc9
06-18 15:24:58.545: INFO/DEBUG(24667):  d6  3fe62e42fee00000  d7  3ff0000000000000
06-18 15:24:58.545: INFO/DEBUG(24667):  d8  4190000044038000  d9  4260000000000000
06-18 15:24:58.545: INFO/DEBUG(24667):  d10 423999a0423999a0  d11 0000000000000000
06-18 15:24:58.545: INFO/DEBUG(24667):  d12 0000000000000000  d13 0000000000000000
06-18 15:24:58.545: INFO/DEBUG(24667):  d14 0000000000000000  d15 0000000000000000
06-18 15:24:58.545: INFO/DEBUG(24667):  scr 80000012
06-18 15:24:58.565: ERROR/OMXPlayer(942): waiting to prepare 0x2b8fb0
06-18 15:24:58.925: INFO/DEBUG(24667):          #00  pc 0001d9cc  /system/lib/libc.so
06-18 15:24:58.925: INFO/DEBUG(24667):          #01  pc 0002e11c  /data/data/com.andtv/lib/libffmpeg.so
如何在地址2e11c中找到真实的源代码是一个问题? 我从Google搜索了一些解决方案,有人说:
arm-eabi-objdump -S my_library.so
但是输出文本中没有源代码,那里只有汇编代码。 我在ndk5r中使用了示例hello-jni项目:
qty:jni qrtt1$ arm-eabi-objdump -S ../libs/armeabi/libhello-jni.so 

../libs/armeabi/libhello-jni.so:     file format elf32-littlearm


Disassembly of section .text:

000002dc <Java_com_example_hellojni_HelloJni_stringFromJNI>:
 2dc:   b500            push    {lr}
 2de:   b083            sub     sp, #12
 2e0:   9001            str     r0, [sp, #4]
 2e2:   9100            str     r1, [sp, #0]
 2e4:   9b01            ldr     r3, [sp, #4]
 2e6:   681a            ldr     r2, [r3, #0]
 2e8:   23a7            movs    r3, #167
 2ea:   009b            lsls    r3, r3, #2
 2ec:   58d2            ldr     r2, [r2, r3]
 2ee:   9901            ldr     r1, [sp, #4]
 2f0:   4b04            ldr     r3, [pc, #16]   (304 <Java_com_example_hellojni_HelloJni_stringFromJNI+0x28>)
 2f2:   447b            add     r3, pc
 2f4:   1c08            adds    r0, r1, #0
 2f6:   1c19            adds    r1, r3, #0
 2f8:   4790            blx     r2
 2fa:   1c03            adds    r3, r0, #0
 2fc:   1c18            adds    r0, r3, #0
 2fe:   b003            add     sp, #12
 300:   bd00            pop     {pc}
 302:   46c0            nop                     (mov r8, r8)
 304:   0012            lsls    r2, r2, #0
是否可以使用-S选项显示源? [更新解决方案2010/06/19] 我找到了ndk-gdb教程:适用于Android的可调试JNI示例。它说,ndk-build脚本会杀死我的调试符号。我尝试通过运行ndk-build V = 1来找出问题:
qty:jni qrtt1$ ndk-build V=1
\\rm -f /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi/lib*.so /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi-v7a/lib*.so /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/x86/lib*.so
rm -f /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi/gdbserver /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi-v7a/gdbserver /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/x86/gdbserver
rm -f /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi/gdb.setup /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi-v7a/gdb.setup /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/x86/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
mkdir -p /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi
install -p /Users/qrtt1/app/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/gdbserver /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
echo \"set solib-search-path /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/obj/local/armeabi\" > /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi/gdb.setup
echo \"directory /Users/qrtt1/app/android-ndk-r5b/platforms/android-8/arch-arm/usr/include /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/jni /Users/qrtt1/app/android-ndk-r5b/sources/cxx-stl/system\" >> /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi/gdb.setup
Install        : libhello-jni.so => libs/armeabi/libhello-jni.so
mkdir -p /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi
install -p /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/obj/local/armeabi/libhello-jni.so /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi/libhello-jni.so
/Users/qrtt1/app/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-strip --strip-unneeded  /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi/libhello-jni.so
该命令将删除我的调试符号:
/Users/qrtt1/app/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-strip --strip-unneeded  /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/libs/armeabi/libhello-jni.so
我不知道禁用strip命令,因为我的ndk版本不同。但是,在删除路径之前,我可以使用.so:
/Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/obj/local/armeabi/libhello-jni.so
源代码又回来了:
qty:jni qrtt1$ arm-eabi-objdump -S /Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/obj/local/armeabi/libhello-jni.so

/Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/obj/local/armeabi/libhello-jni.so:     file format elf32-littlearm


Disassembly of section .text:

000002dc <Java_com_example_hellojni_HelloJni_stringFromJNI>:
 *   apps/samples/hello-jni/project/src/com/example/HelloJni/HelloJni.java
 */
jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
{
 2dc:   b500            push    {lr}
 2de:   b083            sub     sp, #12
 2e0:   9001            str     r0, [sp, #4]
 2e2:   9100            str     r1, [sp, #0]
    return (*env)->NewStringUTF(env, \"Hello from JNI !\");
 2e4:   9b01            ldr     r3, [sp, #4]
 2e6:   681a            ldr     r2, [r3, #0]
 2e8:   23a7            movs    r3, #167
 2ea:   009b            lsls    r3, r3, #2
 2ec:   58d2            ldr     r2, [r2, r3]
 2ee:   9901            ldr     r1, [sp, #4]
 2f0:   4b04            ldr     r3, [pc, #16]   (304 <Java_com_example_hellojni_HelloJni_stringFromJNI+0x28>)
 2f2:   447b            add     r3, pc
 2f4:   1c08            adds    r0, r1, #0
 2f6:   1c19            adds    r1, r3, #0
 2f8:   4790            blx     r2
 2fa:   1c03            adds    r3, r0, #0
}
 2fc:   1c18            adds    r0, r3, #0
 2fe:   b003            add     sp, #12
 300:   bd00            pop     {pc}
 302:   46c0            nop                     (mov r8, r8)
 304:   00000012        .word   0x00000012
    
已邀请:
        
ndk-build NDK_DEBUG=1
将保留用于调试的符号。     

要回复问题请先登录注册