我正在使用 GDB 连接到远程 GDB 服务器(OpenOCD、ARM)。目标上的程序使用半托管来打印一些调试消息。
我需要在 GDB 中运行这些命令:
target remote 127.0.0.1:3333
monitor arm semihosting enable
请注意,我必须首先连接到远程目标,然后启用半主机。
从命令行运行 OpenOCD 和 gdb-multiarch 时效果很好。现在我想使用 IDE:Theia 和 CPP 调试扩展(基于 VS Code 插件 cdt-gdb-vscode)。如何确保“监控臂半主机启用”在连接到目标后自动运行?
launch.json如下:
{
"version": "0.2.0",
"configurations": [
{
"gdb": "gdb-multiarch",
"type": "gdbtarget",
"request": "attach",
"verbose": true,
"openGdbConsole": true,
"openDebug": "openOnDebugBreak",
"name": "Remote debug",
"target": {"port": "1234", "host": "127.0.0.1"},
"program": "${workspaceFolder}/target/thumbv7m-none-eabi/debug/example-embedded"
}
]
}
我尝试向 .gdbinit 添加命令。这些命令在我使用命令行时运行,但在使用 IDE 时不运行(可能 GDB 是从不同的工作目录启动的)。
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch OpenOCD Debugger",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${command:cmake.launchTargetPath}",
"MIMode": "gdb",
"miDebuggerPath": "gdb-multiarch.exe",
"miDebuggerServerAddress": "localhost:3333",
"debugServerPath": "openocd.exe",
"debugServerArgs": "-f board/st_nucleo_f7.cfg -c \u0022$_TARGETNAME configure -rtos FreeRTOS\u0022",
"serverStarted": "Listening on port .* for gdb connections",
"filterStderr": true,
"stopAtConnect": false,
"externalConsole": true,
"hardwareBreakpoints": {
"require": true,
"limit": 6
},
"postRemoteConnectCommands": [
{
"text": "-target-download",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \u0022monitor reset halt\u0022",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \u0022monitor arm semihosting enable\u0022",
"ignoreFailures": false
}
],
"svdPath": "${workspaceRoot}/STM32F756.svd"
}
]
}