交叉编译GDB工具

GDB是Linux下用来调试驱动的利器,可以单步、设置端点、查看变量等等,简直跟一个硬件调试器一样,很方便。现在要在Linux虚拟机中编译一个GDB,然后下载到Linux开发板中运行,好方便调试开发板的驱动。

如下步骤:

1 下载资源,共需要两个资源,一个是termcap,一个是gdb,前一个是gdb要编译所依赖的库。地址如下:(需要注意的是,下载的时候不要贪图最新版本,因为很有可能你装的编译器不支持最新版本的一些c语言特性,编译失败,我用的gdb 7.3, termcap可以用最新的)

ftp://ftp.gnu.org/gnu/termcap

http://www.gnu.org/software/gdb/download/


2 编译termcap。解压缩安装包以后进入目录,执行如下命令:

./configure --host=arm-linux --prefix="$PWD/../gdb"

说明:也就是执行目录下的configure,指定host为arm-Linux,并且指定操作目录为上一层目录中的gdb文件夹

执行完了以后生成Makefile,需要在里面将gcc改成arm-Linux-gcc,ar改成arm-Linux-at,ranlib改成arm-Linux-ranlib,改完以后,执行如下:

make
make install
执行完成以后,上层目录gdb/lib中有一个 libtermcap.a


3 编译gdb。解压缩gdb安装包并进入目录,执行如下命令:

./configure --target=arm-linux --host=arm-linux --prefix="$PWD/../gdb" --without-x --disable-gdbtk --disable-tui --without-included-regex --without-included-gettext LDFLAGS="-L$PWD/../gdb/lib" CPPFLAGS="-I$PWD/../gdb/include" LD="-ltermcap"
说明:此命令制定了target,host以及操作目录为上层目录中的gdb文件夹,然后执行如下命令:
make
make install
执行完后会在上层目录中gdb/bin中生成三个可执行文件:gdb, gdbserver, run,可以将这个几个文件拷贝到linux开发板的特定目录后在/bin中生成软链接,或者直接放到/bin中。例如我放到/usr/local/gdb中后生成软链接并修改权限:
# ln -s /usr/local/gdb/gdb /bin/gdb
# ln -s /usr/local/gdb/gdbserver /bin/gdbserver
# ln -s /usr/local/gdb/run /bin/run
# chmod 777 /bin/gdb
# chmod 777 /bin/gdbserver 
# chmod 777 /bin/run

4 使用方法。使用的时候直接输入:(注意:可执行文件需要编译选项中加-g才能被gdb使用,并且调试的时候可执行文件所在文件夹必须包含源码)
gdb 可执行文件名
就可以调试程序了。
# gdb test_hello
GNU gdb (GDB) 7.3.1
Copyright (C) 2011 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 "arm-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /driver_test/test_hello...done.
(gdb) list
3       #include <fcntl.h>
4       #include <errno.h>
5       #include <stdlib.h>
6
7
8       int main(void)
9       {
10              int fd;
11              int retval;
12              unsigned char temp[100]={0};


gdb的使用方法推荐链接:

http://www.cnblogs.com/hankers/archive/2012/12/07/2806836.html

http://blog.csdn.net/21cnbao/article/details/7385161

猜你喜欢

转载自blog.csdn.net/oushaojun2/article/details/78138427