Tuesday, August 5, 2014

Cross-compile GDB for ARM (ARMEL & ARMHF)

Let's say you have:
Machine A: x86, cross-compile for armhf
Machine B: armhf

On Machine A, you create a program. Then you copy the program to Machine B.
On Machine B, you execute the program and boom fatal error, a core is generated.

The question is: on which machine should I use GDB to read the core file?
Answer: Machine A! But you need to install GDB for ARMHF!

Here are the steps (on Machine A):

Download GDB
wget http://ftp.gnu.org/gnu/gdb/gdb-7.8.tar.gz
Extract
gunzip gdb-7.8.tar.gz
tar -xf gdb-7.8.tar
Go to the folder
cd gdb-7.8/
Build GDB 
#ARMHF
./configure --target=arm-linux-gnueabihf --prefix=/usr/arm-linux-gnueabihf CXX="arm-linux-gnueabi-g++"
#ARMEL
./configure --target=arm-linux-gnueabi --prefix=/usr/arm-linux-gnueabi CXX="arm-linux-gnueabi-g++"
make
make install
And that's it.
From Machine B, copy the core file in Machine A, and run this command:
/usr/arm-linux-gnueabihf/arm-linux-gnueabihf-gdb myProgram core

And that's it.


Note: I'm not sure if you really need to specify CXX when building GDB.

3 comments:

Dave L said...

Is it Possible to use this in Eclipse in windows 8.1? or do I have to use this in linux only. The goal is to attach a Debugger to IDA Pro & Android it seems there is issues with the other GDB backend version as IDA States.

I am in need for a version that can be used for IDA Pro 6.5 & Windows

is there already Compiled versions of this Debugger? Somewhere? Thankyou.

Dave L said...

I also have Visual Studio Pro 2013

Eclipse IDE

NetBeans

alexandre klein said...

Hi,
I'm not so sure with Eclipse+Windows.
Maybe you can try to install VirtualBox and use Ubuntu, so you can have access to GDB