Reputation: 966
I'm using GDB to connect to a remote GDB server (OpenOCD, ARM). The program on the target uses semi hosting to print some debug messages.
I need to run in GDB these commands:
target remote 127.0.0.1:3333
monitor arm semihosting enable
Note that I must first connect to the remote target and then enable semihosting.
This works fine when running OpenOCD and gdb-multiarch from the command line. Now I would like to use an IDE: Theia and the CPP debug extension (which is based on the VS Code plugin cdt-gdb-vscode). How can I ensure that "monitor arm semihosting enable" is ran automatically after connecting to the target?
The launch.json is as follows:
{
"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"
}
]
}
I have tried adding commands to .gdbinit. Those commands are ran when I use the command line but not when using the IDE (Probably GDB is started from a different working directory).
Upvotes: 2
Views: 1475
Reputation: 359
Here is an example. The postRemoteConnectCommands are what your looking for.
{
"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"
}
]
}
Upvotes: 0