前文介紹了GDB的編譯。咱們通過編譯以後獲得兩個文件:gdb和gdbserverhtml
下面開始嵌入式中使用gdb進行調試的方法介紹:linux
1.編譯代碼redis
arm-linux-gnueabi-gcc test.c -o test -gbash
必定要加‘-g’參數服務器
2.嵌入式設備端測試
gdbserver 10.11.2.33:1122 testdebug
gdbserver [IP]:[端口] 測試程序調試
注:這裏的IP是設備IP,不是主機IPcode
# ./gdbserver 10.11.22.36:1122 test Process /mnt/test created; pid = 127 Listening on port 1122 Remote debugging from host 10.11.22.36, port 57984
3.服務器端server
target remote 10.11.2.33:1122
進入gdb後,target remote [ip]:[port]
注:這裏的IP是設備IP,不是主機IP
# ./gdb GNU gdb (GDB) 8.3 Copyright (C) 2019 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-linux". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word". (gdb) target remote 10.11.2.33:1122 Remote debugging using 10.11.2.33:1122 Reading /mnt/test from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading /mnt/test from remote target... Reading symbols from target:/mnt/test... Reading /lib/ld-linux.so.3 from remote target... Reading /lib/ld-linux.so.3 from remote target... Reading symbols from target:/lib/ld-linux.so.3... (No debugging symbols found in target:/lib/ld-linux.so.3) 0xb6fcfa80 in _start () from target:/lib/ld-linux.so.3 (gdb)
GDB調試命令
b:打斷點
c:繼續執行