Wednesday, July 29, 2015

Tips and tricks: Debugging on Android

I searched all over for this information and want to save it for the future.

Situation: Code running on an android emulator, hosted on a Windows 8 box. GDB is available in an Ubuntu emulator running in VMware on the same Windows 8 box.

Goal: To connect the GDB in Ubuntu to a gdbserver on the android device.

1. Forward to the android device (here PORT is 5039)...      adb forward tcp:5039 tcp:5039
2. Open a shell to the android device... adb shell
3. Begin debugging the process on the device [gdbserver :PORT --attach PID]... gdbserver :5039 --attach 1574
4. adb forward Only forwarded, which the VM can't get to. Use netsh to forward the public IP to the localhost port...  netsh interface portproxy add v4tov4 listenport=5039 listenaddress= connectport=5039 connectaddress=
5. In Ubuntu, open gdb and connect to the server... target remote
Bam! The Windows box forwards the connection from the VM to the device and gdb meets gdbserver.

This isn't enough, as my gdb is rejecting the connection with "warning: Architecture rejected target-supplied description", but it is a big step forward. For the next step you need an appropriately built gdb which matches the ABI (application binary interface) of the targeted device.

Acquiring an ARM-Linux tool chain for targetting Android:
Download and run the android-ndk from

Once the files are present, use the instructions at to open the correct gdb