VSCode STM32 Debug 问题分析
· 阅读需 2 分钟
Windows环境,使用VSCode调试STM32时,从点Debug按钮开始到板子启动需等待20s左右,这明显不太正常。当前使用的主要工具:
先将Cortex-Debug的Debug Timestamps选项打开:
.vscode/launch.json
{
"configurations": [
{
"showDevDebugOutput": "raw",
"showDevDebugTimestamps":true,
...
}
...
]
...
}
按F5开启Debug,打开底部gdb-server终端,发现openocd启动很快,查看底部调试控制台,发现在file-exec-and-symbols卡住10多秒:
10-file-exec-and-symbols
...
-> 10^done
此处应该就是问题所在了,对应的Cortex-Debug源代码:
src/gdb.ts
private startGdb(response: DebugProtocol.LaunchResponse): Promise<void> {
...
} else {
this.gdbInitCommands.push(`file-exec-and-symbols "${this.args.executable}"`);
}
const ret = this.miDebugger.start(this.args.cwd, this.gdbInitCommands);
return ret;
...
Cortex-Debug是以mi2方式调用的gdb,先试试手动调用gdb:
arm-none-eabi-gdb --interpreter=mi2
...
(gdb)
-file-exec-and-symbols ${efi-file}
同样会卡住10多秒,可以确认是gdb解析符号时出问题了。换了几个不同版本的工具链测试对比测试下结果如下:
| Toolchain | 结果 |
|---|---|
| Windows arm-gnu-toolchain-13.2.rel1 | 卡 |
| Windows arm-gnu-toolchain-12.3.rel1 | 卡 |
| Windows MSYS2 gdb | 不卡 |
| Windows MSYS2 gdb-multiarch | 不卡 |
| MacOS Brew arm-none-eabi-gdb | 不卡 |
| Windows xPack arm-none-eabi-gdb | 不卡 |
只有ARM家的工具链有这个问题,改用xPack提供的工具链完美解决此问题。