Unable to debug native library issue with ndk-gdb (building with mvn & ndk-build on OS X)

1,182 views
Skip to first unread message

Corey Latislaw

unread,
Mar 4, 2011, 9:39:24 AM3/4/11
to android-ndk
Hello,

I'm debugging an issue with a native C library that's crashing only on
Gingerbread. I spent yesterday reading countless how-to's, discussion
threads, and documentation about getting ndk-gdb to run in order to
debug with my device. I verified that debuggable is set to true in the
manifest, built with ndk-build, installed the .apk on the device,
started the application, and started ndk-gdb. I get this error:

Found device gdbserver: /data/data/com.xfinity.tv/lib/gdbserver: No
such file or directory
ERROR: Non-debuggable application installed on the target device.
Please re-install the debuggable version!

Most advice I've seen for this is rebuild with ndk-build, build
project, install again, start the app, and run ndk-gdb. I've repeated
this process many times, tried using android-ndk-r4b instead, and even
tried hacking around in the android-ndk-r5b/build/core/ (don't worry
I've since restored them to their pristine state) to ensure that
debugging wasn't being stripped out. Nothing is working!

Has anyone experienced a similar issue? What am I missing here?

Thanks,
Corey

===============================================================
Specs/Tools
===============================================================
Mac OSX 10.6.6
Nexus S
android-ndk-r5b (also have android-ndk-r4b)
mvn

===============================================================
Build/Install Process
===============================================================
> ndk-build # from the jni directory
> mvn clean install # from the project directory
> adb install -r target/blah.apk
start app on device
> ndk-gdb

===============================================================
Android.mk contents
===============================================================
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := clibrary
LOCAL_SRC_FILES := blah.c blah2.c blah3.c
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS := --std=c99 -ggdb -g
APP_OPTIM := debug
LOCAL_CFLAGS += -O0 -g

include $(BUILD_SHARED_LIBRARY)

===============================================================
Output of "ndk-build NDK_DEBUG=1 NDK_LOG=1"
===============================================================
Android NDK: NDK installation path auto-detected: '/usr/local/android-
ndk-r5b'
Android NDK: GNU Make version 3.81 detected
Android NDK: Host OS was auto-detected: darwin
Android NDK: Host CPU was auto-detected: x86
Android NDK: HOST_TAG set to darwin-x86
Android NDK: Host awk tool was auto-detected: awk
Android NDK: Host awk test returned: Pass
Android NDK: This NDK supports the following toolchains and target
ABIs:
Android NDK: arm-eabi-4.4.0: armeabi armeabi-v7a
Android NDK: arm-linux-androideabi-4.4.3: armeabi armeabi-v7a
Android NDK: x86-4.2.1: x86
Android NDK: Found platform root directory: /usr/local/android-ndk-r5b/
platforms
Android NDK: Found supported platforms: android-3 android-4 android-5
android-8 android-9
Android NDK: PLATFORM android-3 supports: arm
Android NDK: ABI arm sysroot is: /usr/local/android-ndk-r5b/
platforms/android-3/arch-arm
Android NDK: PLATFORM android-4 supports: arm
Android NDK: ABI arm sysroot is: /usr/local/android-ndk-r5b/
platforms/android-4/arch-arm
Android NDK: PLATFORM android-5 supports: arm
Android NDK: ABI arm sysroot is: /usr/local/android-ndk-r5b/
platforms/android-5/arch-arm
Android NDK: PLATFORM android-8 supports: arm
Android NDK: ABI arm sysroot is: /usr/local/android-ndk-r5b/
platforms/android-8/arch-arm
Android NDK: PLATFORM android-9 supports: arm
Android NDK: ABI arm sysroot is: /usr/local/android-ndk-r5b/
platforms/android-9/arch-arm
Android NDK: Found stable platform levels: 3 4 5 8 9
Android NDK: Found max platform level: 9
Android NDK: Looking for AndroidManifest.xml in {PROJECT_DIRECTORY}/
jni
Android NDK: Looking for AndroidManifest.xml in {PROJECT_DIRECTORY}
Android NDK: Found it !
Android NDK: Found project path: {PROJECT_DIRECTORY}
Android NDK: Parsing {PROJECT_DIRECTORY}/jni/Application.mk
Android NDK: Found APP_PLATFORM=android-9 in {PROJECT_DIRECTORY}/
default.properties
Android NDK: Defaulted to APP_BUILD_SCRIPT={PROJECT_DIRECTORY}/jni/
Android.mk
Android NDK: Application 'local' forced debuggable through NDK_DEBUG
Android NDK: Selecting optimization mode through Application.mk: debug
Android NDK: Adding import directory: /usr/local/android-ndk-r5b/
sources
Android NDK: Building application 'local' for ABI 'armeabi'
Android NDK: Using target toolchain 'arm-linux-androideabi-4.4.3' for
'armeabi' ABI
Android NDK: Looking for imported module with tag 'cxx-stl/system'
Android NDK: Probing /usr/local/android-ndk-r5b/sources/cxx-stl/
system/Android.mk
Android NDK: Building application 'local' for ABI 'armeabi-v7a'
Android NDK: Using target toolchain 'arm-linux-androideabi-4.4.3' for
'armeabi-v7a' ABI
Android NDK: Looking for imported module with tag 'cxx-stl/system'
Android NDK: Probing /usr/local/android-ndk-r5b/sources/cxx-stl/
system/Android.mk
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi-v7a/
gdbserver
Gdbsetup : libs/armeabi-v7a/gdb.setup
Compile thumb : clibrary <= blah.c
Compile thumb : clibrary <= blah2.c
Compile thumb : clibrary <= blah3.c
SharedLibrary : libclibrary.so
Install : libclibrary.so => libs/armeabi/libclibrary.so
Compile thumb : clibrary <= JNIInit.c
SharedLibrary : libclibrary.so
Install : libclibrary.so => libs/armeabi-v7a/libclibrary.so

===============================================================
Output of "ndk-gdb --verbose"
===============================================================
Android NDK installation path: /usr/local/android-ndk-r5b
Using default adb command: /usr/local/android-sdk-mac_86/platform-
tools/adb
ADB version found: Android Debug Bridge version 1.0.26
Using final ADB command: '/usr/local/android-sdk-mac_86/platform-tools/
adb'
Using auto-detected project path: /Users/clatis200/workspace/mobile/
android/AndroidXfinityTV/XfinityTVApp
Found package name: com.xfinity.tv
ABIs targetted by application: armeabi armeabi-v7a
Device API Level: 9
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Found debuggable flag: true
Found device gdbserver: /data/data/com.xfinity.tv/lib/gdbserver: No
such file or directory
ERROR: Non-debuggable application installed on the target device.
Please re-install the debuggable version!

Doug Schaefer

unread,
Mar 4, 2011, 4:41:17 PM3/4/11
to andro...@googlegroups.com
Ran into the same thing as I recently gave ndk-gdb a try. I found I
had to add NDK_DEBUG=1 to the ndk-build command if gdbserver is
missing from the libs/armeabi folder in your project. But then even
then I had problems and had to scrub user data when launching the
emulator to clear things up. It was pretty weird and that message
isn't very helpful.

Doug.

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>

David Turner

unread,
Mar 4, 2011, 7:13:35 PM3/4/11
to andro...@googlegroups.com, Corey Latislaw
The message indicates that gdbserver was not installed by the PackageManager on the device at install time.
Quick questions:

1/ Which exact device and system image is this?
2/ Does gdbserver is included in your .apk  (run "unzip -l <your-apk>" to see its content, it should be under lib/armeabi/gdbserver)
3/ What does running "adb shell run-as <your-package-name> ls" outputs?

Thanks in advance

Corey Leigh Latislaw

unread,
Mar 7, 2011, 9:18:34 AM3/7/11
to android-ndk
Hi David,

Thanks for the reply. :)

1) Phone info:
Model: Nexsus S
Android Version: 2.3.2
Kernel Version: 2.6.35.7-g7f1638a
Android-build@apa28 #1

2) It looks like gdb support isn't being included in the apk – but I
can't figure out why or how to correct it!
gdbserver is not in lib/armeabi/, I have:
lib/armeabi/libclibrary.so
lib/armeabi-v7a/libclibrary.so

3) adb shell run-as com.xfinity.tv ls
lib
cache
files
shared_prefs

Thanks!
Corey

David Turner

unread,
Mar 17, 2011, 5:55:43 AM3/17/11
to andro...@googlegroups.com, Corey Leigh Latislaw
On Mon, Mar 7, 2011 at 3:18 PM, Corey Leigh Latislaw <col...@gmail.com> wrote:
Hi David,

Thanks for the reply. :)

1) Phone info:
Model: Nexsus S
Android Version: 2.3.2
Kernel Version: 2.6.35.7-g7f1638a
Android-build@apa28 #1

2) It looks like gdb support isn't being included in the apk – but I
can't figure out why or how to correct it!
gdbserver is not in lib/armeabi/, I have:
lib/armeabi/libclibrary.so
lib/armeabi-v7a/libclibrary.so

That is very weird. It looks like your Manifest has the android:debuggable flag set to true (which is why run-as works), but that the build system failed to include the gdbserver binary.
Can you tell me the build output when using: ndk-build NDK_LOG=1 -B ?

Corey Leigh Latislaw

unread,
Mar 17, 2011, 4:36:41 PM3/17/11
to andro...@googlegroups.com, Corey Leigh Latislaw
[colabug:/Users/colabug/workspace/mobile/android/app/jni] ndk-build NDK_LOG=1 -B
Android NDK: Looking for AndroidManifest.xml in /Users/colabug/workspace/mobile/android/app/jni
Android NDK: Looking for AndroidManifest.xml in /Users/colabug/workspace/mobile/android/app
Android NDK:     Found it !
Android NDK: Found project path: /Users/colabug/workspace/mobile/android/app
Android NDK: Parsing /Users/colabug/workspace/mobile/android/app/jni/Application.mk
Android NDK:   Found APP_PLATFORM=android-11 in /Users/colabug/workspace/mobile/android/app/default.properties
Android NDK: Application local targets unknown platform 'android-11'
Android NDK: Switching to android-9
Android NDK:   Defaulted to APP_BUILD_SCRIPT=/Users/colabug/workspace/mobile/android/app/jni/Android.mk
Android NDK: Application 'local' *is* debuggable
Android NDK: Selecting optimization mode through Application.mk: debug
Android NDK: Adding import directory: /usr/local/android-ndk-r5b/sources
Android NDK: Building application 'local' for ABI 'armeabi'
Android NDK: Using target toolchain 'arm-linux-androideabi-4.4.3' for 'armeabi' ABI
Android NDK: Looking for imported module with tag 'cxx-stl/system'
Android NDK:   Probing /usr/local/android-ndk-r5b/sources/cxx-stl/system/Android.mk
Android NDK: Building application 'local' for ABI 'armeabi-v7a'
Android NDK: Using target toolchain 'arm-linux-androideabi-4.4.3' for 'armeabi-v7a' ABI
Android NDK: Looking for imported module with tag 'cxx-stl/system'
Android NDK:   Probing /usr/local/android-ndk-r5b/sources/cxx-stl/system/Android.mk
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup
Compile thumb  : clibrary <= lib.c
Compile thumb  : clibrary <= lib1.c
Compile thumb  : clibrary <= lib2.c
Compile thumb  : clibrary <= lib3.c
Compile thumb  : clibrary <= lib4.c
Compile thumb  : clibrary <= lib5.c
Compile thumb  : clibrary <= lib6.c
Compile thumb  : clibrary <= lib7.c
Compile thumb  : clibrary <= lib8.c
Compile thumb  : clibrary <= lib9.c
Compile thumb  : clibrary <= lib10.c
Compile thumb  : clibrary <= lib11.c
SharedLibrary  : libclibrary.so
Install        : libclibrary.so => libs/armeabi/libclibrary.so
Compile thumb  : clibrary <= lib.c
Compile thumb  : clibrary <= lib1.c
Compile thumb  : clibrary <= lib2.c
Compile thumb  : clibrary <= lib3.c
Compile thumb  : clibrary <= lib4.c
Compile thumb  : clibrary <= lib5.c
Compile thumb  : clibrary <= lib6.c
Compile thumb  : clibrary <= lib7.c
Compile thumb  : clibrary <= lib8.c
Compile thumb  : clibrary <= lib9.c
Compile thumb  : clibrary <= lib10.c
Compile thumb  : clibrary <= lib11.c

David Turner

unread,
Mar 17, 2011, 8:17:47 PM3/17/11
to andro...@googlegroups.com
Ok, the lines:

Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup

Mean that gdbserver is properly copied to libs/armeabi/ and libs/armeabi-v7a/
The problem is that the final package doesn't include them.

This can normally happen if you're using an old version of the SDK Tools. Did you upgrade to Tools r9 or Tools r10?
If not, the result is not surprising. If you did, this is surprising and I'll ask you exactly how you're generating your final package.
Can you also look inside libs/armeabi/gdbserver to see if the files are there?

--
Reply all
Reply to author
Forward
0 new messages