歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 使用Gdb、gdbserver在ARM-Linux下進行遠程調試

使用Gdb、gdbserver在ARM-Linux下進行遠程調試

日期:2017/2/28 16:19:20   编辑:Linux教程

一、下載gdb-6.4.tar.gz源代碼 http://ftp.gnu.org/gnu/gdb/

點擊這裡下載Gdb 的簡單使用gdb+gdbserver 方式進行ARM 程序調試PDF版

二、編譯 GDB

2.1、編譯arm-linux-gdb

#tar zxvf gdb-6.4.tar.gz

#cd gdb-6.4
#./configure --target=arm-linux --prefix=/usr/local/arm-gdb
#make

#make install // 生成/usr/local/arm-gdb/bin

2.2、編譯GDB Client

#cd ./gdb/gdbserver
#export PATH=$PATH:/usr/local/arm-gdb/bin
#./configure --target=arm-linux --host=arm-linux
#vi config.h
//#define HAVA_SYS_REG_H //注釋此句

//#define HAVE_TD_VERSION //注釋此句
#make CC=arm-softfloat-linux-gnu-gcc //指定用於編譯gdbserv的交叉編譯器的路徑

編譯用於目標機的stub程序 生成gdbserver是GDB客戶端程序,在板子上運行。

三、實戰調試

1. 下載文件到目標板: gdbtest和gdbserver

假設 host pc ip:192.168.1.45
board ip:192.168.1.180

將文件拷貝到目標板上:

先將gdbtest和gdbserver兩個文件拷貝到主機的/tftpboot目錄下

在目標板的Linux中運行:

#mount 192.168.1.108:/tftpboot /mnt/nfs
#cd /mnt/nfs
#ls

看是否有gdbtest和gdbserver兩個文件。

3.運行調試

client board:
#./gdbserver 192.168.1.45:1234 gdbtest // 目標板上運行gdbtest 監聽端口1234
host pc:
#cd /usr/local/arm-gdb/bin/
#copy gdbtest /usr/local/arm-gdb/bin/ // 將前面編譯的文件gdbtest拷貝到此目錄
#./arm-linux-gdb gdbtest
(gdb)target remote 192.168.1.180:1234 // 連接到開發板 成功後就可以進行調試
(gdb)list or l
(gdb)break func
(gdb)break 22
(gdb)info br
(gdb)continue or c // 這裡不能用 run
(gdb)next or n
(gdb)print or p result
(gdb) finish // 跳出func函數
(gdb) next
(gdb) quit

建立連接後進行gdb遠程調試和gdb本地調試方法相同

gdb/gdbserver 調試多線程

While debuging a remote multithread program by means of gdb/gdbserver, frequently I see gdb complaints like this:

Program received signal SIG32, Real-time event 32.
0x400d7e84 in ?? ()
(gdb)

Then gdb is suspended to wait for new commands, and on this occasion, typing 'c' can make the debuging continue. But instruction 'info threads' can not list correct information.

In fact, this results from stripped libpthread/libthread_db, which can be easily verified by means of '/usr/bin/file'. To remove the problem, simply refer the libs to unstripped versions via gdb instructions like:

set solib-absolute-prefix [dir]

set solib-search-path [dir1];[dir2]

Copyright © Linux教程網 All Rights Reserved