gdb远程调试
GDB远程调试BMC
GDB远程调试是基于vscode,需要gdb和gdbserver。其中gdb是在宿主机上使用的,而gdbserver是在目标主机上使用的(即BMC单板上)。也可以不使用vscode,用终端工具也可以。使用vscode主要是可以方便看源码或者设置断点。
1 编译带符号表程序
以IPMIMain为例,在Makefile中注释掉:
#------- Comment/uncomment the following line to enable/disable debugging---------
DEBUG = y
然后重新编译该模块。编译完可以使用file命令查询是否携带debug信息:
file IPMIMain
IPMIMain: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 4.20.8, with debug_info, not stripped
输出结果中带有with debug_info, not stripped表示编译的目标文件带符号表。
2 配置vscode
配置vscode主要是配置launch.json文件。点击“运行”菜单,然后点击“添加配置”即可。直接把下面的内容拷贝过去进行修改:
{
"version": "0.2.0",
"configurations": [
{
"name": "gdb Remote Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/xcm/code/IPMIMain",
"args": [],
"stopAtEntry": true,
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/home/xcm/code/gdb/gdb",
"miDebuggerServerAddress": "10.13.192.43:2333",
"logging": {
"moduleLoad": false,
"engineLogging": false,
"trace": false
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"cwd": "${workspaceFolder}",
}
]
}
需要根据实际情况修改:
-
program:需要调试的可执行文件的路径
-
args:调试程序的入参,如:["./hello.so", "main"]
-
miDebuggerPath:实际放置gdb的路径
-
miDebuggerServerAddress:目标主板的ip和gdbserver的监听端口
3 运行gdbserver
把gdbserver上传到目标主板上并运行gdbserver:
/var/tmp # ./gdbserver :2333 /usr/local/bin/IPMIMain
Process /usr/local/bin/IPMIMain created; pid = 4187
Listening on port 2333
./gdbserver :2333:启动gdbserver,并监听端口2333,这个端口号需要与上面的vscode配置相同。
4 vscode运行调试
点击“运行”菜单,然后“启动调试”即可。或者直接“F5”运行。


浙公网安备 33010602011771号