5

I have a setup in launch.json for vscode as follows:

{
    // 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 25.0_regeragpu",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/25.0_regeragpu/Blazer/MercuryImageComputer/KT/leaf/M31/BrightField/bin/LeafStandalone/Debug/12/LeafStandAlone.x86-64",
            "args": ["-noForcedPatches","${workspaceFolder}/virgo_algo_preq/JobDump/JobInfo_108"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/25.0_regeragpu/Blazer/MercuryImageComputer/KT/leaf/M31/BrightField/bin/LeafStandalone/Debug/12",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

The purpose of this setup is to use GDB integration in vscode. In particular, I specified the following pair to ensure all environment variables set up in my bash session in terminal of vscode are inherited when debugging: "externalConsole": false. I also notice that there is a pair named environment in the configuration. It is my understanding that if a new bash session is started for debugging by vscode, then all environment variables should be specified in this environment pair. To try the option of starting a new bash when debug, I modified the configuration file:

{
    // 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 25.0_regeragpu",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/25.0_regeragpu/Blazer/MercuryImageComputer/KT/leaf/M31/BrightField/bin/LeafStandalone/Debug/12/LeafStandAlone.x86-64",
            "args": ["-noForcedPatches","${workspaceFolder}/virgo_algo_preq/JobDump/JobInfo_108"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/25.0_regeragpu/Blazer/MercuryImageComputer/KT/leaf/M31/BrightField/bin/LeafStandalone/Debug/12",
            "environment": [{"CUDA_VISIBLE_DEVICES":"0,1,2,3","CUDA_DEVICE_ORDER":"PCI_BUS_ID"}],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

In particular, it can be seen that I specified the following pairs: "environment": [{"CUDA_VISIBLE_DEVICES":"0,1,2,3","CUDA_DEVICE_ORDER":"PCI_BUS_ID"}] and "externalConsole": true. Nevertheless, as I started debugging, the debugging tool of vscode prepared forever and never entered the real debugging session. How should I set up the environment variables if I want to debug in a new console in vscode?

3 Answers 3

4

Here is an example, you set the value in the environment block.

    {
// 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": "g++ - (GDB 9.2) Build and debug active file with RepoCodeInspection",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/bin/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [
            {
                "description": "same as commands below by using 'setenv ...",
                "info": "cant debug b/c of libBase/libRecipe now requiring dependency to boost for stacktrace dumps",
                "name": "LD_LIBRARY_PATH",
                "value": "/libs/:./"
            }
        ],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "logging": {
            "trace": false,
            "traceResponse": false
        },
        "preLaunchTask": "RepoCodeInspection",
        
    },
    {
        "name": "g++ - (GDB 9.2) Attach to a running process",
        "type": "cppdbg",
        "request": "attach",
        "processId":"${command:pickProcess}",
        "program": "${fileDirname}/bin/${fileBasenameNoExtension}",
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "logging": {
            "trace": false,
            "traceResponse": false
        },
        "preLaunchTask": "RepoCodeInspection",
       
    },
]

}

1
  • The OP is already trying to use an environment block.  It would be better if you could explain your answer in English, rather than just hiding it in an unnecessarily-long code block. Aug 11, 2022 at 21:03
3

To set multiple environment variables, use comma-separated "name", "value" pairs.

Example:

"environment": [{"name": "LD_LIBRARY_PATH", "value": "/ld/library/path/"},
                {"name": "CUDA_VISIBLE_DEVICES", "value": "0"}
               ]
0

Let's debug your problem. First up, remember: this is a JSON file, thus we need to think of it as a JSON file.

This is your initial JSON object that we're thinking about:

  "environment": [
    {
      "CUDA_VISIBLE_DEVICES": "0,1,2,3",
      "CUDA_DEVICE_ORDER": "PCI_BUS_ID"
    }
  ]

So we have a JSON array (indicated by [ & ]) named "environment" which contains a single object (indicated by { & }). That single object then contains two key/value pairs. Here lies the problem.

A single object with multiple key value pairs is like a struct in C as opposed to a simple variable which has a single key/value pair.

Logically I would say what we desire is this:

  • our "environment" would hold a number of "environement variables"
  • our environment variables each have single key with a value.

Re-tooling our combination of [] & {} results in the following:

  "environment": [
    {
      "CUDA_VISIBLE_DEVICES": "0,1,2,3"
    },
    {
      "CUDA_DEVICE_ORDER": "PCI_BUS_ID"
    }
  ]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .