Corey4005
Corey4005

Reputation: 115

how to set up lldb environment in vscode?

all. I am trying to set an environment for lldb in vscode. For example, on the terminal if I run my executable in lldb, I get the following:

(base) cdwalke8@MSLAL0422100041 examples % lldb ./ExampleRunner
(lldb) target create "./ExampleRunner"
Current executable set to '/Users/cdwalke8/Desktop/Dev/examples/ExampleRunner' (x86_64).
(lldb) r
Process 65031 launched: '/Users/cdwalke8/Desktop/Dev/examples/ExampleRunner' (x86_64)
dyld[65031]: Library not loaded: ../lib/libex.so
  Referenced from: <953E1B45-2D99-3202-A89D-EEC0565FBD7C> /Users/cdwalke8/Desktop/Dev/examples/ExampleRunner
  Reason: tried: '../lib/libex.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS../libex.so' (no such file), '../lib/libex.so' (no such file), '/usr/local/lib/libex.so' (no such file), '/usr/lib/libex.so' (no such file, not in dyld cache)
Process 65031 stopped
* thread #1, stop reason = signal SIGABRT
    frame #0: 0x00007ff813265c66 dyld`__abort_with_payload + 10
dyld`:
->  0x7ff813265c66 <+10>: jae    0x7ff813265c70            ; <+20>
    0x7ff813265c68 <+12>: movq   %rax, %rdi
    0x7ff813265c6b <+15>: jmp    0x7ff8131fd170            ; cerror_nocancel
    0x7ff813265c70 <+20>: retq   
Target 0: (ExampleRunner) stopped.

However, if I start lldb and set the environment like this:

(base) cdwalke8@MSLAL0422100041 examples % lldb ./ExampleRunner
(lldb) target create "./ExampleRunner"
Current executable set to '/Users/cdwalke8/Desktop/Dev/examples/ExampleRunner' (x86_64).
(lldb) env DYLD_LIBRARY_PATH=/Users/cdwalke8/Desktop/Dev/Build/lib
(lldb) r
Process 65174 launched: '/Users/cdwalke8/Desktop/Dev/examples/ExampleRunner' (x86_64)

# This is not really what the program does, I am just replacing with Hello World for simplicity

====================
Hello World!  
====================

Now, when I set this in my launch.json, the debug terminal shows a similar issue as the first example I showed, but I have the enviornment set:

{
    "configurations": [

        {
            "name": "C/C++: clang build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "/Users/cdwalke8/Desktop/Dev/examples/ExampleRunner",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "externalConsole": false,
            "MIMode": "lldb",
            "environment": [{
                "name":"DYLD_LIBRARY_PATH", 
                "value": "/Users/cdwalke8/Desktop/Dev/Build/lib",
            }],
            "preLaunchTask": "C/C++: clang build active file"
        }
    ],
    "version": "2.0.0"
}

Why does this not work? Or, rather what should I change to get lldb to set the environment path correctly before it launches the debugger?

Thanks!

Upvotes: 0

Views: 319

Answers (2)

user28226240
user28226240

Reputation: 1

Also this works:

not, environment:, and not an array but an object.

      "env": {
        "PORT": "8080",
        "RUST_BACKTRACE": "1"
      },

Upvotes: 0

Corey4005
Corey4005

Reputation: 115

I found an answer to pass export variables to lldb. Simply create a file called project.env in your .vscode dir.

Add this to it:

DYLD_LIBRARY_PATH=/Users/cdwalke8/Desktop/Dev/Build/lib

Then, change your launch.json to include an envFile setting:

{
    "configurations": [

        {
            "name": "C/C++: clang build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "/Users/cdwalke8/Desktop/Dev/examples/ExampleRunner",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: clang build active file", 
            "envFile": "/Users/cdwalke8/Desktop/Dev/examples/.vscode/project.env"

        }
    ],
    "version": "2.0.0"
}

Upvotes: 0

Related Questions