Remote Debugging of Android Native applications using Eclipse and gdbserver

I prefer plain GDB, but if want to use Eclipse, it’s possible.

Assuming the sources are located inside /home/ohad/mydroid/external/dragons (and you have eclipse, eclipse-cdt installed),

  1. Create a “Standard Make C Project”.
  2. Don’t use the default location. Instead, set it to /home/ohad/mydroid/external/dragons
  3. Don’t use the default Build command. Instead, set it to /home/ohad/mydroid/external/dragons/make_dragons
  4. Remove the “all” from the “Build (Incremental Build)” field, and uncheck “Clean”.
  5. Finish.

Next, create those two files:

  1. /home/ohad/mydroid/external/dragons/make_dragons

    #!/bin/bash
    ONE_SHOT_MAKEFILE=/home/ohad/mydroid/external/dragons/Android.mk make -C /home/ohad/mydroid files 2>&1 | sed -f /home/ohad/mydroid/external/dragons/android_sed_filter

  2. /home/ohad/mydroid/external/dragons/android_sed_filter

    # Streamlined Editor filter for Android native development with Eclipse
    /WARNING: adding test OTA key/d
    /implicitly installing apns-conf_sdk.xml/d

By now, you can use Eclipse to build dragons. Let’s move on to debugging.

Assuming that your target IP is 10.0.0.2 and your Eclipse host IP is 10.0.0.1,

  1. Create a “C/C++ Local Application” debug instance.
  2. Set “C/C++ Application” to your dragons binary, e.g., to “/home/ohad/mydroid/out/target/product/myboard/symbols/system/bin/dragons” (ignore the ‘CPU not supported’ warning for now).
  3. Choose “gdbserver Debugger”
  4. Set “GDB debugger” to your toolchain’s gdb binary
  5. Add “/home/ohad/mydroid/out/target/product/myboard/symbols/system/lib” to the “Shared Libraries” list tab.
  6. Fill up the Connection tab (e.g., TCP, 10.0.0.2, 1234).

Everything’s in place now. Before starting a debug session, execute (on the target) “gdbserver 10.0.0.1:1234 system/bin/dragons” (or gdbserver 10.0.0.1:1234 –attach <PID of dragons>).

Happy debugging ;)