VsCode: escape widnows path in launch.json command

57 Views Asked by At

I'm using Vscode + CMake + arm-none-eabi + openocd to develop in linux. I've trouble migrating this setup to windows. this is the relevant snippet:

{
"version": "0.2.0",
"configurations": [
    {
    ...
      "setupCommands": [
      ...
        { "text": "-file-exec-and-symbols ${command:cmake.launchTargetPath}", "description": "load file", "ignoreFailures": false},
      ...
      ],
    ...
    }
  ...
  ]
}

${command:cmake.launchTargetPath} returns a windows path with '\' delimiter that is interpreted as an escape char when passed as a gdb argument.

"C:\\some\path\output.elf" is passed as "C:\somepathoutput.elf"

1

There are 1 best solutions below

0
On
  • Install Command Variable Extension

  • Define an input with the transform command to convert backslashes into slashes.

  • Use the transformed input instead of the original command

{
    "version": "0.2.0",
    "configurations": [
        {
            "setupCommands": [
                {
                    "text": "-file-exec-and-symbols ${command:cmake.launchTargetPath}",
                    "description": "load file",
                    "ignoreFailures": false
                }
            ]
        }
    ],
    "inputs": [
        {
            "id": "launchTargetPath",
            "type": "command",
            "command": "extension.commandvariable.transform",
            "args": {
                "text": "${command:cmake.launchTargetPath}",
                "find": "\\\\",
                "replace": "/",
                "flags": "g"
            }
        }
    ]
}