VSCode远程调试
工作原理
使用gdb和gdbserver配合进行远程调试,其中gdbserver运行于开发板上。gdb对应的使用arm-linux-guneabihf-gdb
。
实现
先在开发板上运行gdbserver :1234 ./sport_audio -t
使用插件:C/C++或Native Debug
配置中的type项表示对应的插件,主要设置调试的文件名、使用的gdb工具以及远程地址。
其中对于C/C++插件,设置
"program": "${workspaceFolder}/out/build/cross_gcc_Debug/src/sport_audio",
"miDebuggerPath": "arm-linux-gnueabihf-gdb",
"miDebuggerServerAddress": "192.168.10.104:1234"
对于Native Debug,设置
"executable": "${workspaceFolder}/out/build/cross_gcc_Debug/src/sport_audio",
"target": "192.168.10.104:1234",
"remote": true,
"cwd": "${workspaceRoot}",
"gdbpath": "arm-linux-gnueabihf-gdb"
launch.json
:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cppdbg_remote",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/out/build/cross_gcc_Debug/src/sport_audio",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"miDebuggerPath": "arm-linux-gnueabihf-gdb",
"miDebuggerServerAddress": "192.168.10.104:1234"
},
{
"type": "gdb",
"request": "attach",
"name": "Attach to gdbserver",
"executable": "${workspaceFolder}/out/build/cross_gcc_Debug/src/sport_audio",
"target": "192.168.10.104:1234",
"remote": true,
"cwd": "${workspaceRoot}",
"gdbpath": "arm-linux-gnueabihf-gdb"
},
{
"type": "lldb",
"request": "custom",
"name": "lldb Remote debug",
"targetCreateCommands": [
"target create ${workspaceFolder}/out/build/cross_gcc_Debug/src/sport_audio"
],
"processCreateCommands": [
"gdb-remote 192.168.10.104:1234"
]
}
]
}
使用LLDB的问题
LLDB也支持gdbserver,使用以下配置,可以连接上,但是无法打断点。而且LLDB不会使用arm-linux-guneabihf-gdb
。
{
"type": "lldb",
"request": "custom",
"name": "lldb Remote debug",
"targetCreateCommands": [
"target create ${workspaceFolder}/out/build/cross_gcc_Debug/src/sport_audio"
],
"processCreateCommands": [
"gdb-remote 192.168.10.104:1234"
]
}