一、编译gdbserver
1. 下载gdb
http://ftp.gnu.org/gnu/gdb/
2.解压缩
tar xf gdb-8.0.tar.xz
3. 交叉编译
cd gdb/gdbserver/
./configure --host=arm-none-linux-gnueabihf --target=arm-none-linux-gnueabihf --program-prefix=arm-none-linux-gnueabihf- --prefix=/home/xman/gdb-8.0/binsvr
make
make install
将/home/xman/gdb-8.0/binsvr/gdbserver 拷贝到ARM开发板/bin
【错误及解决】
(1)linux-ptrace 编译错误:
In file included from ../../gdb/nat/linux-ptrace.c:20:
../../gdb/nat/linux-ptrace.h:180:22: 错误:expected identifier before numeric constant 180 | # define TRAP_HWBKPT 4
解决: gdb/nat/linux-ptrace.c 删除 #include "gdb_wait.h" #include "gdb_ptrace.h"
gdb/nat/linux-ptrace.h 中在 #include "nat/gdb_ptrace.h" 下增加 #include "gdb_wait.h"
参见 https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb/commit/e6600bbefd667810744fbe8eed3830bf5644c354
(2)makeinfo: not found
解决:sudo apt-get install texinfo
二、vscode配置
1. 安装插件:
vscode ssh连接到交叉编译环境主机(如VMware中ubuntu),安装c/c++插件
2. 配置launch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name":"(gdb)launch", "type":"cppdbg", "request": "launch", "program": "/home/xman/demo/test_main", "args": [], "stopAtEntry": false, "miDebuggerPath": "/usr/.../bin/arm-none-linux-gnueabihf-gdb", "miDebuggerServerAddress": "192.168.0.45:8889", "environment": [], "externalConsole": false, "MIMode": "gdb", "cwd": ".", "setupCommands": [ { "description": "sysroot", "text": "set sysroot target:/" }, { "description": "prettyprint", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "follow-fork-mode_child", "text": "set follow-fork-mode child" } ] } ] } |
三、开始调试
1. ARM开发板上启动gdbserver,调试守护进程pid(如32101, 可执行文件为 test_main)
# gdbserver :8889 --attach 32101
2. gdb客户端(PC 命令行)
$ arm-none-linux-gnueabihf-gdb test_main ……(省略命令输出) (gdb) target remote 192.168.0.45:8889 (gdb) set sysroot target:/ (gdb) set follow-fork-mode child (gdb) b x_function (gdb) c
【问题与解决】
(1) PC上运行arm-none-linux-gnueabihf-gdb时报错:
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>])
ImportError: No module named site
原因:可能没有安装 arm-none-linux-gnueabihf-gdb 依赖的 python版本
解决:readelf -d arm-none-linux-gnueabihf-gdb 查看gdb依赖的python库版本,如依赖2.7
安装python2.7: sudo apt-get install python2.7
sudo apt-get install libpython2.7
(2)安装python2.7后 undefined symbol: PyUnicodeUCS4_FromEncodedObject
原因: 在PATH某个交叉工具链路径下也包含了libpython2.7.so.1.0但其内没有定义函数PyUnicodeUCS4_FromoEncodedObject
解决:删除该路径下的libpython2.7.so.1.0,使用安装的libpython2.7
3 gdb客户端(vscode)
可以在代码中添加断点,发起gdb调试了。
标签:gnueabihf,vscode,gdbserver,none,arm,gdb,linux,ARM From: https://www.cnblogs.com/rtthread/p/18141017