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 127.0.0.1:PORT 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 127.0.0.1, 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=192.168.1.2 connectport=5039 connectaddress=127.0.0.1
5. In Ubuntu, open gdb and connect to the server... target remote 192.168.1.2:5039
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 https://developer.android.com/tools/sdk/ndk/index.html

Once the files are present, use the instructions at https://github.com/mapbox/mapbox-gl-native/wiki/Android-debugging-with-remote-GDB to open the correct gdb

No comments:

Post a Comment