前文介绍了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:继续执行