Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to attach the ndk-gdb to the android application

I am trying to attach the ndk-gdb to my Android application.

I am using is Android-ndk-r6b and device is Android 2.3,Samsung Galaxy S II.

I followed all the steps in this example Click here for the example

And also I tried with one application, when I am trying to attach gdb with another application but the verbose showing that it is always getting attached to the first application itself

Found package name: <1st attached package name>

I tried to launch the ndk-gdb using this command for the first time:

 ndk-gdb --start --force --verbose

I tried to attach to another application with the below command but not able to succeed:

ndk-gdb --launch=com.example.hellogdbserver.HelloGdbServer --force --verbose

I am always getting the below error with first application:

ERROR: Non-debuggable application installed on the target device.Please re-install the debuggable version!

This is complete shell log which i am getting

    sh-4.1$ ndk-gdb --verbose --start --force
    Android NDK installation path: /cygdrive/c/Android/android-ndk
    Using default adb command: /cygdrive/c/Android/android-sdk-windows/platform-tools/adb
    ADB version found: Android Debug Bridge version 1.0.26
    Using final ADB command: '/cygdrive/c/Android/android-sdk-windows/platform-tools/adb'
    Using auto-detected project path: /cygdrive/d/EclipseTestWorkspace/hello-gdbserver
    Found package name: com.example.hellogdbserver
    ABIs targetted by application: armeabi
    Device API Level: 10
    Device CPU ABIs: armeabi-v7a armeabi
    Compatible device ABI: armeabi
    Found debuggable flag: true
    Found device gdbserver: /data/data/com.example.hellogdbserver/lib/gdbserver
    Using gdb setup init: /cygdrive/d/EclipseTestWorkspace/hello-gdbserver/libs/armeabi/gdb.setup
    Using toolchain prefix: /cygdrive/c/Android/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-
    Using app out directory: /cygdrive/d/EclipseTestWorkspace/hello-gdbserver/obj/local/armeabi
    ERROR: Could not extract package's data directory. Are you sure that
           your installed application is debuggable?
    sh-4.1$

Please let me know how can I resolve the above error and also how to attach to new package.

My phone is not rooted. Hope this wont affect the gdb.

This was not helpful as well Link to similar problem. As my phone is new phone and dont have any app, other than the current developing app. (Only packages which come along with the Samsung phone are present. No app is downloaded from the market. )

Thanks & Regards,
SSuman185


Please go through the link Debugging native code in android app using the android ndk gdb

like image 421
Suman Avatar asked Nov 25 '11 09:11

Suman


3 Answers

Please first ensure that you are building the debuggable version of the app. The AndroidManifest.xml file should include the android:debuggable="true" tag.

You can also check it by finding the APK file in the bin directory, unpacking it (it's just a renamed ZIP file) and ensuring that lib\armeabi folder contains the gdbserver file.

If both conditions above are met, try installing the package on the device manually:

<android-sdk>\platform-tools\adb.exe install -r <your-package-file.APK>

Please carefully observe the output of adb.exe. If it displays an error, it might explain your problem.

like image 84
Ivan Shcherbakov Avatar answered Nov 15 '22 20:11

Ivan Shcherbakov


This problem will arise if you try to debug a library project. ndk-gdb is unable to attach to a project that is not the "main" one.

You have to put your jni code into the starting application project.

like image 23
cyrilchampier Avatar answered Nov 15 '22 18:11

cyrilchampier


make sure you have APP_OPTIM in jni/Application.mk set to debug

like image 20
iddqd Avatar answered Nov 15 '22 19:11

iddqd