Build GDB for Android
30 Jan 20150. introduction
If you need GDB on Android, it's very likely that you got a copy without some feature like gcore. So a good idea is to build GDB on your own to acquire these features.
Following process is done on Fedora 21 and should be compatible with other linux platform.
1. gdb part
source: https://android.googlesource.com/toolchain/gdb.git
Here we build version 7.7
Install termcap and bison, or there will be error during make process.
In file /gdb-7.7/gdb/remote.c, search for "packet reply is too long" and modify as follows:
//if(buf_len > 2 * rsa->sizeof_g_packet)
// error(_("Remote 'g' packet reply is too long: %s"),rs->buf);
if(buf_len > 2 * rsa->sizeof_g_packet)
{
rsa->sizeof_g_packet = buf_len;
...
Then run the following command:
./configure --target=arm-linux-androideabi --prefix=<result_absolute_path>
sudo make
sudo make install
If you see "no termcap library found", install termcap.
If you see something like "multiple definition of main" or "undefined reference to 'c_parse'", install bison.
2. gdbserver part
First, download android ndk and run:
chmod a+x android-ndk-r10c-darwin-x86_64.bin
./android-ndk-r10c-darwin-x86_64.bin
and in the extracted file directory, run:
sudo ./build/tools/make-standalone-toolchain.sh --system=linux-x86_64 --toolchain=arm-linux-androideabi-4.9 --install-dir=<target_dir> --ndk-dir=<extracted_file_dir>
This will install android toolchain to
In path ./gdb-7.7/gdb/gdbserver, do as follows:
CC=arm-linux-androideabi-gcc ./configure --target=arm-linux-androideabi --host=arm-linux-androideabi --prefix=<result_absolute_path>
sudo make && sudo makeinstal
If there is error "arm-linux-androideabi-gcc: command not found", replace "CC=arm-linux-androideabi-gcc" with "CC=<gccabsolutepath>".
3. done
Now two files are available: arm-linux-androideabi-gdb and gdbserver. Strip command is helpful if you need a smaller version.
We can push gdbserver to android and run:
./gdbserver :<port_id> --attach=<pid>
Then run in the host:
adb forward tcp:<port_id> tcp:<port_id>
./arm-linux-androideabi-gdb
target remote :<port_id>
You can download the two files here: gdbserver, arm-linux-androideabi-gdb.