I have two processes in the Android application- main application process and a remote service process. The native libraries are loaded from the remote service process.
I want to debug the native library code. The application is debuggable. The native library was built from Windows command-line using ndk-build. In Android.mk, -g -ggdb flag was used for this library. I am running ndk-gdb from cygwin.
Test device: Galaxy Nexus running Android 4.2.2
Error line: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
In the verbose information, I see that gdbserver is trying to attach to process id of the main application process. Should it matter that the library is loaded from a remote process within this application.
Detailed ndk-gdb run information-
$ ndk-gdb --verbose --force
Android NDK installation path: /cygdrive/c/work/android/ndk/android-ndk-r9-windows-x86/android-ndk-r9
Using default adb command: /cygdrive/c/work/android/sdk/android-sdk_r10-windows/android-sdk-windows/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.31
Using ADB flags:
Using JDB command: /cygdrive/c/program files (x86)/java/jdk1.6.0_25/bin/jdb
Using auto-detected project path: .
Found package name: [application-pkg-name]
ABIs targetted by application: armeabi
Device API Level: 17
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi
Using gdb setup init: ./libs/armeabi/gdb.setup
Using toolchain prefix: /cygdrive/c/work/android/ndk/android-ndk-r9-windows-x86/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi
Found debuggable flag: true
Found device gdbserver: /data/data/[applcation-pkg-name]/lib/gdbserver
Found data directory: '/data/data/[applcation-pkg-name]'
Found running PID: 17890
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: adb_cmd shell run-as [applcation-pkg-name] lib/gdbserver +debug-socket --attach 17890
## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/[applcation-pkg-name]/debug-socket
Attached; pid = 17890 [Comment: This pid is for the main application process]
Listening on Unix socket debug-socket
## COMMAND: adb_cmd pull /system/bin/app_process obj/local/armeabi/app_process
493 KB/s (9592 bytes in 0.019s)
Pulled app_process from device/emulator.
## COMMAND: adb_cmd pull /system/bin/linker obj/local/armeabi/linker
1165 KB/s (63244 bytes in 0.053s)
Pulled linker from device/emulator.
## COMMAND: adb_cmd pull /system/lib/libc.so obj/local/armeabi/libc.so
2442 KB/s (297608 bytes in 0.119s)
Pulled libc.so from device/emulator.
/cygdrive/c/work/android/ndk/android-ndk-r9-windows-x86/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-gdb.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
Couple of side notes that could be helpful-
1) If I run the ndk-gdb command without --force, it gives me error that Another debug session is running. Although the gdb prompt came out during the last run.
2) On Android 4.3, with the same application and setup, I get error that "Could not extract package's data directory"