How to compile library with source code with NDK tools?

6

How to compile library with source code ?

I am developing the native library with android ndk. Sometimes I got the crash dump messages from 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

It is a problem how to find the real source code at address 2e11c? I search some solutions from google, someone said:

arm-eabi-objdump -S my_library.so

But no source code in the output text, only assembly code there. I use the sample hello-jni project in the ndk5r:

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

Is it possible to show source with -S option ?


[UPDATE solution 2010/06/19]

I found the ndk-gdb tutorial: A debuggable JNI example for Android. it said, ndk-build script will kill my debug symbol. I try to figure out it by runing 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

The command will strip my debug symbol:

/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

I have no idea to disable the strip command, because my ndk version is different. However, I can use the .so before stripped in the path:

/Users/qrtt1/app/android-ndk-r5b/samples/hello-jni/obj/local/armeabi/libhello-jni.so

The source code is back:

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
android
android-ndk
objdump
asked on Stack Overflow Jun 18, 2011 by qrtt1 • edited Jun 19, 2011 by qrtt1

1 Answer

0
ndk-build NDK_DEBUG=1

will keep the symbol for debug.

answered on Stack Overflow Jun 22, 2011 by Kazuki Sakamoto

User contributions licensed under CC BY-SA 3.0