Ampaex
Ampaex

Reputation: 1

Not being able to setup environment variable for gdb in visual studio code

Description

I'm trying to run a custom gdb(qnx neutrino -> ntoaarch64-gdb), but for that, I need to set up some environment variables before. I've tried to use the "environment" field, the "envFile" approach, using "terminal.integrated.env.linux", doing a "preLaunchTask" and many other things but I'm not able to set them before the call of the binary. Every try results in gdb being executed without the environment variables. I also have an environment script(.sh) for setting up all the variables.

Steps to reproduce:

  1. I'm trying to run the launch gdb that needs some environment variables to be set.
  2. Try to add the envFile, environment field or any other approach.
  3. Launch the debugger
  4. See that the gdb debugger fails because variables are not set.

launch.json

{
          "name": "Launch debug (GDB)",
          "type": "cppdbg",
          "request": "launch",
          "miDebuggerPath": "/path/to/ntoaarch64-gdb",
          "program": "/path/to/binary",
          "stopAtEntry": false,
          "cwd": "${workspaceFolder}",
          "miDebuggerServerAddress": "(ip):(port)",
          "externalConsole": true,
          "MIMode": "gdb",
          "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
          ],
          "envFile": "${workspaceFolder}/.env",
          "environment": [
              {
                "name":"ENVVAR",
                "value": "/some/path/"
              }
           ]
        }

This returns this output:

¡QNX environment is not set!

It seems like vscode has two types of terminal, the integrated terminal and the internal terminal. The variables I've been setting sometimes has effect on the integrated one but never in the internal.

Could you help me with this issue? Thanks

I've tried to use the "environment" field, the "envFile" approach, using "terminal.integrated.env.linux", doing a "preLaunchTask" and many other things but I'm not able to set them before the call of the binary in the internal terminal.

Upvotes: 0

Views: 976

Answers (2)

V D
V D

Reputation: 1

Another option is to modify the batch file you have mentioned -

Add at the end a call to start VS Code like:

call "C:\....\Microsoft VS Code\Code.exe"

By using call, the execution of the batch file will wait for VS Code to finish before continuing, ensuring that any environment variables set before launching VS Code will be inherited by the VS Code process

Upvotes: 0

Caroline Gilger
Caroline Gilger

Reputation: 1

I was also having this issue and found that you have to set QNX_HOST and QNX_TARGET variables in the environment before launching VSCode.

Upvotes: 0

Related Questions