cmake VsCode:escape widnows path in launch.json command

5w9g7ksd  于 5个月前  发布在  Vscode
关注(0)|答案(1)|浏览(93)

我使用Vscode + CMake + arm-none-eabi + openocd在Linux上开发。我在将此设置迁移到windows时遇到了麻烦。这是相关的片段:

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

字符串
${command:cmake.launchTargetPath}返回一个带有'\'的windows路径,当作为gdb参数传递时,该路径被解释为转义字符。
"C:\\some\path\output.elf"作为"C:\somepathoutput.elf"传递

smdnsysy

smdnsysy1#

  • 安装Command Variable Extension
  • 使用transform命令定义一个输入,将反斜杠转换为斜杠。
  • 使用转换后的输入而不是原始命令
{
    "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"
            }
        }
    ]
}

字符串

相关问题