How to get ndk-gdb working on Android


You don't need to use -O0 or -g switches. You need to do one of following:

    put android:debuggable="true" to the <application> tag in AndroidManifest.xml file
    use NDK_DEBUG=1 after ndk-build
    put APP_OPTIM := debug in Application.mk file

Doing anyone of these three things will automatically use -O0 and -g switches.

Can you try running gdb manually, without gdb script? It involves following steps:

    pushing gdbserver file to /data/local folder on device
    running your application & invoking in adb shell following command gdbserver :5055 --attach PID, where PID is your application process id.
    running adb forward tcp:5055 tcp:5055 on host
    running arm-linux-androideabi-gdb.exe from your app folder
    entering following commands in gdb
    set solib-search-path obj/local/armeabi
    file obj/local/armeabi/libMySharedLib.so
    target remote :5055

And see if you can debug then.

If you want see symbols for other shared libraries your library is using like libc.so, then pull them from device (from /system/lib folder) to your obj/local/armeabi folder.
share|improve this answer
    
    
1     
    
For an unrelated reason I had to recreate my project from scratch; after doing so and trying to set up everything by the book, including your suggestions Mārtiņš, NDK debugging worked. I'm not sure what the problem was unfortunately. Btw APP_OPTIM had to be set to debug (lowercase) rather than Debug. – Jonny Boy May 17 '12 at 6:49
    
[Re]built with the NDK_DEBUG=1 option when calling 'ndk-build'; not after. – soulseekah Nov 20 '12 at 18:14
    
where is the "ndk-build" ? – android developer Jan 22 at 12:29
    
ndk-build is command you invoke to build native code. ndk-build script is provided by Android NDK an is located in root of zip/tar.bz2 archive. – Mārtiņš Možeiko Jan 22 at 18:10
    
ok i've done all 3 steps (part of the ndk-build was done by looking at tools.android.com/recent/usingthendkplugin ) . however , when i start to debug , i get some errors , which start with "Unable to launch cygpath. Is Cygwin on the path?] java.io.IOException: Cannot run program "cygpath": CreateProcess error=2, The system cannot find the file specified" . how should i fix it ? does it mean i have to use cygwin ? – android developer Jan 22 at 21:05

你可能感兴趣的:(How to get ndk-gdb working on Android)