linux下的GDB遠程調試

一、利用GDB進行遠程調試,首先需要明確一下幾點:

1、調試用的GDB必須是交叉編譯產生的GDB;

2、調試的程序必須是交叉編譯且帶 “-g” 選項的可執行程序。

3、在宿主機和目標開發板上調試的必須是同一個可執行程序。

4、基於 3 ,我們必須要建立一個宿主機和開發板的NFS共享目錄,以實現調試調試同一可執行程序。

5、目標開發板的gdbserver和宿主機用的GDB版本必須相同,最好是同一源文件編譯同時產生的。

6、在開發板上必須開通遠程調試所需要的端口,否則遠程調試機無法通過端口遠程連接到開發板上。

二、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]


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章