gdb調試之linux pc和linux arm環境下,gdbarm

來源:互聯網
上載者:User

gdb調試之linux pc和linux arm環境下,gdbarm
Linux PC應用程式gdb調試:

1、查看core檔案參數
yinkui@yinkui-desktop:~/File_unzip/cp_module$ ulimit -a

core file size          (blocks, -c) 0        //產生core檔案數目,不會產生core檔案

data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31042
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192        //應用程式棧大小
cpu time               (seconds, -t) unlimited
max user processes              (-u) 31042
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


2、設定產生 core檔案大小
ulimit -c unlimited(不限制core檔案的大小)
(預設不會現實PID資訊,可通過以下命令修改此檔案:  echo "1" > /proc/sys/kernel/core_uses_pid , 這樣每次程式掛了之後會產生類似 core.8909(8909是當時的進程號), 效果就是後續產生的core檔案不會覆蓋之前產生的core檔案。)
3、產生段錯誤之後,查看進程資訊
gcc -g test.c -o test (設定gdb調試)
ls -l core.*
4、使用gdb調試core檔案之前操作 查看core檔案資訊:file core
5、使用gdb調試core檔案 gdb --core=core.PID

(gdb)bt(第一次不會出現堆棧資訊)

(gdb)file ./a.out(運行程式)
(gdb)bt(backtrace資訊出現)
(可直接使用命令:ulimit -a; ulimit -c unlimited;ulimit -a;echo "1" > /proc/sys/kernel/core_uses_pid)
Linux  arm 應用程式arm-XXXX-gdb調試:

1、查看core檔案參數
yinkui@yinkui-desktop:~/File_unzip/cp_module$ ulimit -a

core file size          (blocks, -c) 0        //產生core檔案數目,不會產生core檔案

data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31042
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 31042
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


2、設定產生 core檔案大小
ulimit -c unlimited(不限制core檔案的大小)
(預設不會現實PID資訊,可通過以下命令修改此檔案:  echo "1" > /proc/sys/kernel/core_uses_pid , 這樣每次程式掛了之後會產生類似 core.8909(8909是當時的進程號), 效果就是後續產生的core檔案不會覆蓋之前產生的core檔案。)
3、編譯器選項
加入gdb可調試選項 arm-linux-XXX -g test.c -o test

4、構建GDB+GDB server nfs調試方法
(1)確保arm開發板與主機支援nfs功能,設定開發板和主機在同一網段,並設定共用目錄(如/mnt/nfs)。(2)將編譯器對應該的gdbserver和test(可執行檔)拷貝到共用目錄(/mnt/nfs),修改應用程式和 gdbserver許可權為777.
(3)通過telnet或者minicom登陸到開發板,掛在nfs檔案系統:mount -t nfs 主機IP:/mnt/nfs(共用目錄) /home/root/modbus_rtu_slave(開發板目錄) -o nolock
(4)進入共用目錄 運行gdbserver建立遠端偵錯server(格式為: ./gdbserver 主機IP:建立串連的連接埠號碼 可執行檔【其中連接埠號碼一般1024以上沒有佔用即可】,如下)./gdbserver 10.10.51.47:5000 test
(5)在主機目錄下運行可執行程式:
arm-linux-gdb test
---》target remote 10.10.51.33:5000    (進入gdb調試後運行命令,串連gdbserver)

注釋:set solib-absolute-prefix與set solib-search-path命令分別用於設定GDB共用庫尋找路徑首碼與共用庫尋找路徑,以阻止GDB尋找宿主機上的庫。若不指定這些路徑,遠端偵錯過程中GDB載入了宿主機的庫,會出現諸如“warning: GDB can't find the start of the function at 0x******”與“Cannot find bounds of current function”等錯誤提示。  文章主要主要來自參考、總結和實踐。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.