Google Android Debugging Utilities

 

Here are some gnu apps that I have compiled to ease the debugging of binary files on the android platform. I am making available the pre-compiled binaries, the source for this apps are already available and the compilation process is pretty straightforward, once you have the cross-compiler, I used the codesourcery arm-none-linux toolchain http://www.codesourcery.com/sgpp/lite/arm/portal/release644:

Steps to crosscompile gdb:

export PATH=$PATH:/home/alfred/android/arm-2008q3/bin/
./configure --target=arm-none-linux-gnueabi --host=arm-none-linux-gnueabi
make

gdb 6.8 will compile without any patching.

Android binaries:

strace, gdb and gdb-server (6.7), bash

gdb and gdb-server (6.8)


I have found that having a native gdb is much more convenient than having to connect to gdbserver, and the other utilities (strace and bash) are also useful while debugging.

You can upload the files using a command like:

$adb push gdb /data/bin

then:

$adb shell

# /data/bin/gdb
dlopen failed on 'libthread_db.so.1' - libthread_db.so.1: cannot open shared object file: No such file or directory
GDB will not be able to debug pthreads.

GNU gdb 6.7
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=arm-none-linux-gnueabi --target=".
(gdb)
 

 Disregard the "libthread" error, you can attach to threads directly on android, using their pid.

I rule.

 

UPDATE 3-5-2009:

 
The default gdb can't debug binaries, only attach to them. Therefore I don't rule, more like I suck.

This is the error showed:

Starting program: /data/gdb
Cannot exec /bin/sh: No such file or directory.
 

WORKARROUND:

Android doesn't have /bin/sh, so lets make one. First, make / writable:

 # mount -o remount / /

Then mkdir /bin and copy the 'bash' shell provided in this page as /bin/sh

Now gdb is ready to go. This works on android sdk 1.1r1 and before.

Or you can use the alternative method, (thanks Oren Poleg !):

export SHELL=/system/bin/sh