Search code examples
visual-studio-codegdbqnx

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


I am trying to create a launch.json file where I want to call gdb. Only, when I call it, it seems that I have to use 4 backslashes in filepaths in order to get it working. So I am now using hardcoded paths, but I would like to use paths coming from 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"
        }
    ]
}

Solution

  • I have changed a couple of things to this script in order to get it working.

    1. It seems that forward slashes are using as well. So you can just do "text": "upload THIS/FOLDER/STRUCTURE/IS/WORKING /SOMEWHERE/ON/QNX
    2. ${workspaceRoot} still wasn't working, but I used VS Code Power Tools to make some custom commands that can be added to your build script and you can simply call them via ${command:myCustomCommand}. Inside of those commands, you can also call other commands, like cmake.launchTargetPath and change it to forward slashes with simple javascript regex.