1. 程式人生 > >嵌入式除錯——gdb環境搭建

嵌入式除錯——gdb環境搭建

一、準備工作

1.下載gdb軟體包

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

(我下載的是gdb7.7版本)

2.安裝必須的軟體或工具(以下在ubuntu上)

sudo apt-get install texinfo 
sudo apt-get install libncurses5-dev 
sudo apt-get install m4
sudo apt-get install flex 
sudo apt-get install bison

二、編譯得到gdb

GDB使用了autoconf/automake,因此編譯時只需配置configure指令碼的--target,--host,--prefix等引數就可實現方便的移植。
--target:指定編譯環境,一般設定為交叉編譯器字首,ix86-linux,arm-linux等 --prefix;指定安裝路徑。 --host:指定編譯後文件執行平臺,一般設定為交叉編譯器字首,ix86-linux,arm-linux等 --program-prefix:將生成可執行檔案前加字首

1)sudo mkdir /opt/gdb7.7

2)./configure --target=mips-linux-uclibc --prefix=/opt/gdb7.7

3)make

4)sudo make install

三、通過板子交叉編譯GDBServer(因為這個server要執行在板子上)

1) ./configure --target=mips-linux-uclibc --host=mips-linux-uclibc

2)  make CC=/opt/openwrt/bin/mips-linux-uclibc-gcc

(這裡需要說明一下,為什麼要用mips-linux-uclibc,因為這裡我用的板子是mips架構的,提供的工具鏈就是mips-linux-uclibc-gcc

我看其他arm版的工具鏈也有許多不同,--taget和--host都必須指定一下,要不然出錯。另一個mips-linux-uclibc-gcc這個地方我用的絕對路徑,因為我安裝了多個mips gcc,而且名稱也一樣,容易導致出錯)

四、測試

測試檔案編譯

mips-linux-uclibc-gcc -g gdbtest.c -o gdbtest 

將gdbtest和gdbserver兩個檔案拷貝到主機的/tftpboot目錄下
 host pc ip:192.168.0.67
 board ip:192.168.0.50 

通過tftp將gdbtest和gdbserver down下來

chmod +x gdbtest

chmod +x gdbserver

client board:
  #./gdbserver 192.168.0.67:7788 gdbtest 
host pc:
#./opt/gdb7.7/mips-linux-uclibc-gdb gdbtest(加粗部分,因為系統中存在其他同名gdb)
  (gdb)target remote 192.168.0.50:7788

五如何利用串列埠除錯

如果你用串列埠1 除錯hello 的話,你就要現在板子上執行命令:
gdbserver hello /dev/ttyS0
(詳情可以參考gdbserver 目錄下的readme 檔案),這時gdbserver 就在等待gdb 的應答訊號了。)
然後在pc 機上執行命令:
xxx-linux-gdb hello
在xxx-linux-gdb 裡敲入入下命令:
(gdb) set remotedevice /dev/ttyS0
(這裡設定串列埠1)
(gdb) set remote baud 9600
(這裡設定串列埠波特率)
(gdb) set debug remote
(可選)
(gdb) target remote /dev/ttyS0
操作到這兒,gdb 就應該和gdbserver 聯絡上了