VS Code:替换内置变量 launch.json 中的字符

VS Code: Replace characters in built-in variable launch.json

我正在尝试创建一个 launch.json 文件,我想在其中调用 gdb。只是,当我调用它时,似乎我必须在文件路径中使用 4 个反斜杠才能使其正常工作。所以我现在使用硬编码路径,但我想使用来自 cmake-tools 的路径。

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "gdb",
            "args": [],
            "externalConsole": true,
            "stopAtEntry": true,
            "windows": {
                "MIMode": "gdb",
                "cwd": "${workspaceRoot}",
                "miDebuggerPath": "${env:QNX_HOST}\usr\bin\ntox86_64-gdb.exe",
                "miDebuggerServerAddress": "192.168.88.128:1234",
                "launchCompleteCommand": "exec-run",
                "customLaunchSetupCommands": [
                    {
                        "text": "-environment-cd ${workspaceRoot}"
                    },
                    {
                        "description": "Connecting to QNX pdebug",
                        "text": "target qnx 192.168.88.128:1234",
                        "ignoreFailures": false
                    },
                    {
                        "description": "Loading symbol table",
                        "text": "file ${command:cmake.launchTargetPath}", // this line is returning single backslashes and I want to replace them with four backslashes
                        "ignoreFailures": false
                    },
                    {
                        "description": "Uploading",
                        "text": "upload THIS\\FOLDER\\STRUCTURE\\IS\\WORKING /SOMEWHERE/ON/QNX",
                        "ignoreFailures": false
                    }
                ]
            },
            "logging": {
                "engineLogging": true,
                "trace": true,
                "traceResponse": true
            },
            "targetArchitecture": "x86_64"
        }
    ]
}

为了让它正常工作,我对这个脚本做了一些更改。

  1. 似乎正斜杠也在使用。所以你可以做 "text": "upload THIS/FOLDER/STRUCTURE/IS/WORKING /SOMEWHERE/ON/QNX
  2. ${workspaceRoot} 仍然无法正常工作,但我使用 VS Code Power Tools 制作了一些可以添加到您的构建脚本中的自定义命令,您可以通过 ${command:myCustomCommand} 简单地调用它们。在这些命令中,您还可以调用其他命令,例如 cmake.launchTargetPath 并使用简单的 javascript 正则表达式将其更改为正斜杠。