Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables don't work with LLDB #191

Closed
NewProggie opened this issue Aug 31, 2016 · 22 comments
Closed

Environment variables don't work with LLDB #191

NewProggie opened this issue Aug 31, 2016 · 22 comments
Assignees
Labels

Comments

@NewProggie
Copy link

NewProggie commented Aug 31, 2016

Hey,

in order to debug my executable, I need to pass an environment variable to the debugger. On console this would be something like:

$ lldb ./my_executable
(lldb) env DYLD_LIBRARY_PATH=/my/foo/bar
(lldb) run

I already tried configuring launch.jsonwith "setupCommands": [{"text": "env DYLD_LIBRARY_PATH=/my/foo/bar"}] and "customLaunchSetupCommands": [{"text": "process launch -v DYLD_LIBRARY_PATH=/my/foo/bar"}] of which neither seem to work. Unfortunately, I don't get any specific error messages other than that the lldb process returned some error.
Configuring the environment variable in tasks.json to include those variables doesn't work either.

Second, is there a way to get more debugging information from the debugger? The only information I'm currently getting is that lldb returned some malformed information, but not any details.

Edit: I'm using OS X 10.11.6 with VS Code version 1.4.0.

@paulmaybee
Copy link

Did you mean "configuring the environment variable in launch.json ..."?

@NewProggie
Copy link
Author

Yes, both actually. Neither seem to work.

@delmyers
Copy link
Contributor

delmyers commented Sep 1, 2016

@NewProggie,

Can you please post your complete launch.json? The way to get this to work would normally be via the "environment" option in the launch.json.

@NewProggie
Copy link
Author

NewProggie commented Sep 2, 2016

@delmyers This is my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch MyProgram",
            "type": "cppdbg",
            "request": "launch",
            "targetArchitecture": "x64",
            "cwd": "${workspaceRoot}/../../",
            "environment": [
                {
                    "name": "DYLD_FRAMEWORK_PATH",
                    "value": "/path/to/custom/lib/"
                },
                {
                    "name": "MY_ROOT",
                    "value": "${workspaceRoot}/../../"
                }
            ],
            "program": "${workspaceRoot}/../../bin/my_executable",
            "args": [],
            "stopAtEntry": false,
            "externalConsole": true,
            "linux": {
                "MIMode": "gdb"
            },
            "osx": {
                "MIMode": "lldb"
            },
            "windows": {
                "MIMode": "gdb"
            }
        }
    ]
}

And this is my tasks.json

{
    "version": "0.1.0",
    "command": "make",
    "isShellCommand": true,
    "osx": {
        "options": {
            "env": {
                "DYLD_FRAMEWORK_PATH":"/path/to/custom/lib/",
                "ARCH":"macosx",
                "COMP":"gcc"
            }
        }
    },
    "options": {
        "cwd": "${workspaceRoot}",
        "env": {
            "MY_ROOT":"${workspaceRoot}/../../",
            "STATE":"release"
        }
    },
    "tasks": [
        {
            "taskName": "my_executable",
            "suppressTaskName": true,
            "echoCommand": false,
            "isBuildCommand": true,
            "showOutput": "always",
        }
    ]
}

If I start a new bash shell without loading any environment however, I can debug my executable sucessfully:

$ env - "$(command -v bash)" --noprofile --norc 
bash-3.2$ export DYLD_FRAMEWORK_PATH=/path/to/custom/lib
bash-3.2$ export MY_ROOT=/foo/bar
bash-3.2$ lldb ./my_executable
...

Edit: This is the error message I am getting. This is the same as if I would have tried to debug my executable without exporting the previously mentioned environment variables

Launching: '/foo/bar/../../bin/my_executable'
Working directory: '/foo/bar'
1 arguments:
argv[0] = '/foo/bar/../../bin/my_executable'
dyld: Library not loaded: @rpath/My_Lib
  Referenced from: /foo/bar/../../bin/my_executable
  Reason: image not found

@delmyers
Copy link
Contributor

delmyers commented Sep 2, 2016

@edumunoz, can you take a look at this?

@edumunoz
Copy link

edumunoz commented Sep 7, 2016

Thanks for the bug report, @NewProggie!

I am able to repro it. We will be changing the way environment variables are set.

@NewProggie
Copy link
Author

@edumunoz Nice, thanks. Will you keep us updated here? Can we expect an update any time soon?

@edumunoz edumunoz changed the title Debugger doesn't respect setupCommands settings Environment variables don't work with LLDB Sep 12, 2016
@NewProggie
Copy link
Author

@edumunoz Was your fix included in the recently released version 0.9.1 (https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)?

@edumunoz
Copy link

edumunoz commented Sep 13, 2016

No, sorry. I will comment on this issue once the fix is released.

@pieandcakes
Copy link
Contributor

@NewProggie This should be in our latest release 0.9.2. If you download the extension and find that it is still an issue, please reopen this Issue with us.

@NewProggie
Copy link
Author

Debugging works fine now. Thanks a lot!

@YLiu-5
Copy link

YLiu-5 commented Jul 6, 2020

Hi, I have the same issue with the LLDB here. It is not working on my machine yet.

Version: 1.46.1
Date: 2020-06-17T21:17:14.222Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 18.6.0

Below is my launch.json 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": "(lldb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/hFEM_OOP",
        "environment": [
            {
                "name": "DYLD_LIBRARY_PATH",
                "value": "/path/to/lib"
            }
        ],
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "externalConsole": false,
        "MIMode": "lldb",
    }
]

}`

Then I got the following error,
@"dyld: Library not loaded: src/libhpro.dylib\r\n" @" Referenced from: /Applications/deal.II.app/Contents/Resources/examples/hfem/build/hFEM_OOP\r\n" @" Reason: image not found\r\n"

In the terminal I have no issue setting the environment variable.

@pieandcakes
Copy link
Contributor

pieandcakes commented Jul 6, 2020

FYI: @WardenGnaw for macOS environment variable issues. It looks like the customer is trying to set debugger environment variables.

@YLiu-5 Environment variables are set for the Debuggee and not the debugger.

@YLiu-5
Copy link

YLiu-5 commented Jul 7, 2020

FYI: @WardenGnaw for macOS environment variable issues. It looks like the customer is trying to set debugger environment variables.

@YLiu-5 Environment variables are set for the Debuggee and not the debugger.

In the terminal I would type

$ lldb ./my_executable (lldb) env DYLD_LIBRARY_PATH=/my/foo/bar (lldb) run

Can you suggest what should I do in vscode to set the environment variable for the LLDB debugger?

@pieandcakes
Copy link
Contributor

@YLiu-5 if you have the lldb command, you can try setupCommands to add direct commands to lldb before we start debuggee execution.

@YLiu-5
Copy link

YLiu-5 commented Jul 8, 2020

@pieandcakes I tried but to no avail. The setupCommands will not load the environment variable for me.

Below is my launch.json file.

`
{
"version": "0.2.0",
"configurations": [

    {
        "name": "(lldb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/hFEM_OOP",
        "environment": [
            {
                "name": "DYLD_LIBRARY_PATH",
                "value": "/usr/local/hlibpro-2.8.1/lib"
            }
        ],
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "externalConsole": false,
        "MIMode": "lldb",
        "setupCommands": [
            { "text": "env DYLD_LIBRARY_PATH=/usr/local/hlibpro-2.8.1/lib", 
              "description": "load environment variable", 
              "ignoreFailures": true },
        ],
    }
]

}
`

The output in debug console,
@"dyld: Library not loaded: src/libhpro.dylib\r\n" @" Referenced from: /Applications/deal.II.app/Contents/Resources/examples/hfem/build/hFEM_OOP\r\n" @" Reason: image not found\r\n"

The debug process is paused on exception.

@pieandcakes
Copy link
Contributor

Can you include engine logging so we can see what the response from that command is? I don't have enough information to go off of but if that command works in LLDB then it should work in this instance too.

@YLiu-5
Copy link

YLiu-5 commented Jul 15, 2020

Hi, I just made it work by adding the environment in the file setting.json, instead of launch.json.

@fventer
Copy link

fventer commented Sep 16, 2021

This issue has not been solved yet. Environment variables not set using codelldb on MacOS using launch.json

@jdgp-hub
Copy link

jdgp-hub commented Sep 16, 2021 via email

@gintsgints
Copy link

Imho in this case environment is set uncorrectly. It should be done this way:

 "version": "0.2.0",
  "configurations": [
    {
      "type": "lldb",
      "request": "launch",
      "name": "Debug executable 'balcia-bdt-v2'",
      "env": {
        "RUST_BACKTRACE": "1"
      },

@harry-nutsfi
Copy link

Imho in this case environment is set uncorrectly. It should be done this way:

"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'balcia-bdt-v2'",
"env": {
"RUST_BACKTRACE": "1"
},

yes, this is the correct way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests