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"
make
make install
# 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
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
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:
...
Reading symbols from /driver_test/test_hello...done.
(gdb) list
3 #include
4 #include
5 #include
6
7
8 int main(void)
9 {
10 int fd;
11 int retval;
12 unsigned char temp[100]={0};