I have my launch.json file that contains:
{
"request": "launch",
"type": "cortex-debug",
"name": "Rt117xDemo Start",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/FW/image/Rt117xDemo.elf",
"servertype": "jlink",
"device": "MIMXRT1176xxxA_M7",
"interface": "swd",
"rtos": "FreeRTOS",
"svdFile": "${workspaceFolder}/FW/bsp/device/MIMXRT1175_cm7.svd",
"runToEntryPoint": "main",
"preLaunchTask": "build",
"serverArgs": [
"-gui"
],
"preLaunchCommands": [
"directory ${workspaceFolder}/FW"
],
"postLaunchCommands": [
"monitor reg pc 0x30002100"
]
}
I would like the address of the last line ("monitor reg pc 0x30002100") to be either the output of a bash command, or perhaps a "variable" (like ${workspaceFolder}
) that I would like to populate with the output of a bash command.
how can I achieve this?
EDIT 2023-23-06
I explain what I would like to do in this example.
I should run the following command:
/path/to/arm-none-eabi-readelf -l FW/image/Rt117xDemo.elf | sed -n 's/Entry point (0x[[:xdigit:]]{8})/1/p'
this command prints the address I need. It is taken from the compiled file so this command should be run every time I launch debugging (and certainly after running the build task).
so I’d like to be able to edit the launch.json line like this:
"postLaunchCommands": [
"monitor reg pc ${command: /path/to/arm-none-eabi-readelf -l ${workspaceFolder}/FW/image/Rt117xDemo.elf | sed -n 's/Entry point (0x[[:xdigit:]]{8})/1/p'}"
]
2
Answers
you can use the extension Command Variable and the command:
extension.commandvariable.file.content
Use an
${input}
variable:most likely the variables in the launch config are resolved before any execution is performed.
You then need to defer the execution of your
monitor
command to a shell script/path/to/run-monitor.sh
(my bash is a bit rusty, but you see the point)
Assign the result of the command
arm-none-eabi-readelf | sed
to a variable and use that variable.The workspace path to use is a parameter of the
run-monitor.sh
script.If you put
run-monitor.sh
in yourPATH
and give it exe permission you don’t have to specify the path.