首先从网上下载一份gdb源码程序下来,网址为http://ftp.gnu.org/gnu/gdb/。
接下来,步骤很简单。
1.编译gdb源码
./configure --target=arm-linux
make
这里之所以用--target,是因为这里编译出来的gdb程序是供ubuntu主机使用的,但是调试的对象即target是arm板,所以这里的配置选项--host是默认主机,target是arm-linux。
编译完成后,安装。
mkdir tmp
make install prefix=./tmp
cp /tmp/bin/arm-linux-gdb /bin
最终编译出来的arm-linux-gdb就是我们需要运行在主机上的程序。
2.编译gdbserver
首先进入gdb目录中的gdbserver目录,然后开始配置编译。
./configure --host=arm-linux
make
同样,这里的--host配置选项为arm-linux代表编译出来的gdbserver程序是运行在arm端的提供gdb调试服务的程序。
3.使用
首先拷贝gdbserver到arm板,然后交叉编译一个helloworld程序,记得加上-g选项。
然后在arm端使用gdbserver启动调试程序helloworld。
./gdbserver 192.168.1.11:2345 helloworld
这里的IP和端口是arm端的IP和端口。
执行完,gdb就启动了,然后开始启动ubuntu上的arm-linux-gdb程序。
/bin/arm-linux-gdb ./helloworld
remote target 192.168.1.11:2345
list
break main
continue
在gdb启动后需要使用remote target来指定目标板的IP和端口,连接成功后就可以开始调试了。