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

时间:2019-06-28 09:40:27

标签: visual-studio-code gdb qnx

我正在尝试在其中要调用gdb的地方创建launch.json文件。只是,当我调用它时,似乎必须在文件路径中使用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 个答案:

答案 0 :(得分:0)

为了使脚本工作,我对该脚本做了一些更改。

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