gdb+gdbserver調試

來源:互聯網
上載者:User

gdb+gdbserver 是偵錯目標板的常用方法.
看了網上的一些資料,加上我自己的一些體會, 寫個完整的記錄吧:
我的環境如下:HOST 192.168.0.33 Target: 192.168.0.34
NFS共用目錄: mount -t nfs -o nolock /home/itlanger/work /mnt

編譯arm-gdb:
下載gdb原始碼:

$ cd downloads

$ wget -t 0 -w 30 -c http://ftp.gnu.org/gnu/gdb/gdb-6.6.tar.gz
tar zxvf gdb-6.6.tar.gz
cd gdb-6.6
./configure --target=arm-linux --prefix=/usr/local/arm-gdb -v

make
sudo make install
export PATH=$PATH:/usr/local/arm-gdb
編譯arm-gdb-server
cd ~/downloads/gdb-6.6/gdb/gdbserver
./configure --target=arm-linux --host=arm-linux
make CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc ##這裡是交叉編譯器的路徑
cp gdbserver ~/work ##gdbserver是編譯產生的
export PATH=$PATH:/usr/local/arm-gdb/bin (最好加到.bashrc中)

拷貝libthread庫(這一步不做的話,運行gdbserver會出錯!)
$ cd /usr/local/arm/3.4.1/arm-linux/lib
$ ls -l libthread_db*
-rwxr-xr-x 1 2619 man 29151 2004-07-28 23:08 libthread_db-1.0.so
lrwxrwxrwx 1 2619 man    17 2008-05-25 12:00 libthread_db.so -> libthread_db.so.1
lrwxrwxrwx 1 2619 man    19 2008-05-25 12:00 libthread_db.so.1 -> libthread_db-1.0.so

$ cp libthread_db-1.0.so ~/work

minicom下:
# cd /lib/
# cp /mnt/libthread_db-1.0.so /lib/
# ln -s libthread_db-1.0.so libthread_db.so.1
# ln -s libthread_db-1.0.so libthread_db.so
測試
寫一個程式, 用arm-linux-gcc -g 編譯, 放到work目錄下, (我的為third)

minicom下: 

cd /mnt

./gdbserver 192.168.0.33:6666 third
Process third created; pid = 356
Listening on port 6666
終端下:
export PATH=$PATH:/usr/local/arm-gdb/bin
cd ~/work
arm-linux-gdb third
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux"...
(gdb)

(gdb) target remote 192.168.0.34:2345       ##(串連目標)
Remote debugging using 192.168.0.34:2345
0x40000dd0 in ?? () from /lib/ld-linux.so.2
現在可以通過l, b 設定斷點了
運行: 用命令c    ##記住這裡不是用run, 因為程式已在Target Board上面由gdbserver啟動了。結果輸出是在Target Board端

這樣就可以用emacs方便地遠端偵錯了。
M-x gdba ##(我已經綁定到F10了)

Run gdba (like this): arm-linux-gdb -annotate=3 third

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.