Last time wrote a few native program, think how to debug, after a while search and test, finally finished. There are several key points:
1 gdb and Gdbserver because these two need to be matched, it is recommended to use GDB and Gdbserver under the same NDK
Gdbserver is in Android-ndk-r9\prebuilt\android-arm\gdbserver this directory gdb is in android-ndk-r9\toolchains\ In the Arm-linux-androideabi-4.8\prebuilt\windows-x86_64\bin directory, the name is Arm-linux-androideabi-gdb.exe2 and the Gdbserver is installed to the device System/bin under ADB push gdbserver/system/bin/adb shell chmod u+x/system/bin/gdbserver3 Debug to compile the program specifically, is Ndk-build ndk_ Debug=1 can debug the program in the. \obj\local\armeabi directory, starting program adb push hello/data/local/tmp/adb shell chmod u+x/data/local/tmp/hellogdbserver relative to JNI directory 4 : 8123/data/local/tmp/hello5 start GdB to start debugging adb forward tcp:1234 tcp:8123 set adb forwarding arm-linux-androideabi-gdb (gdb) file. /obj/local/armeabi/sum Load Debugger (GDB) target remote:1234 Description Remote Debug Object (GDB) list Display code (GDB) Break main set Breakpoint (GDB) Cont continue to run 6 Summary because GDB originally supported remote debugging, when starting Gdbserver, specify the local debugging port, but because the device is connected through ADB, so the designated ADB to do the transfer, after the device starts debugging, wait for gdb to connect debugging, so GDB started, specify the local port, Load the code, and then you can debug the
Remote debugging Android native program with GDB