Debug JNI code with ndk-gdb and eclipse GUI

Embed Size (px)

Citation preview

  1. 1. Debug JNI code with ndk-gdb and eclipse GUI Tom Chen
  2. 2. Overview Prerequisite Debug with ndk-gdb Set up eclipse gdb environment Debug JNI in eclipse
  3. 3. Prerequisite Build Debuggable JNI Lib Download android-ndk-r9 In AndroidManifest.xml android:debuggable=true In Application.mk, APP_OPTIM := debug. Without this variable is also fine. Just don't let it be "release". Build Code: ndk-build NDK_DEBUG=1
  4. 4. Prerequisite Cygwin Environment Download and install cygwin Remember to install make(2.7 or higher) Install JDK and set up env variables, PATH and CLASSPATH Without JDK is also fine, but have to run ndk-gdb with "--nowait". Set up path to android-sdk and ndk in PATH env variables. For unix-like env, just set up these relative paths.
  5. 5. Debug with ndk-gdb Steps First, run your debuggle app directly or via eclipse. Open cygwin and go to where your project resides. Execute ndk-gdb With --nowait specified if no JDK installed. Set up some break points and start debugging!
  6. 6. Debug with ndk-gdb Basic gdb commands break (br or b): Setup break points info br: Show all break points bt: Display call stack list: Show next ten lines of code print (p): Print the content of variable continue (c): Continue the process. step (s): Step to next line
  7. 7. Set up eclipse gdb CDT plugin is required! Create C/C++ debug configuration.
  8. 8. {ndk path}toolchainsarm-linux-androideabi-4.6prebuiltwindows- x86_64binarm-linux-androideabi-gdb.exe
  9. 9. Set up eclipse gdb Modify scripts ndk-gdb Make a copy and rename it as ndk-gdb-eclipse Edit the new file and comment out the last line #$GDBCLIENT -x `native_path $GDBSETUP` gdb.setup The file located at objlocalarmeabigdb.setup . Make a copy named gdb2.setup Delete the last line target remote :5039
  10. 10. Debug JNI in eclipse First, run your debuggle app directly or via eclipse Open cygwin and go to where your project resides. Execute ndk-gdb-eclipse With --nowait specified if no JDK installed. Wait until the command finish Go back to eclipse and execute the debug configuration just created!
  11. 11. Reference http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debuggi http://www.gnu.org/software/gdb/documentation/