GDB是Linux下用來調試驅動的利器,可以單步、設置端點、查看變量等等,簡直跟一個硬件調試器一樣,很方便。現在要在Linux虛擬機中編譯一個GDB,然後下載到Linux開發板中運行,好方便調試開發板的驅動。
如下步驟:
1 下載資源,共需要兩個資源,一個是termcap,一個是gdb,前一個是gdb要編譯所依賴的庫。地址如下:(需要注意的是,下載的時候不要貪圖最新版本,因爲很有可能你裝的編譯器不支持最新版本的一些c語言特性,編譯失敗,我用的gdb 7.3, 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.a3 編譯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 <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};