全部。我正在尝试在 vscode 中为 lldb 设置环境。例如,在终端上,如果我在 lldb 中运行可执行文件,我会得到以下信息:
(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.
但是,如果我启动 lldb 并设置如下环境:
(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!
====================
现在,当我在 launch.json 中设置它时,调试终端显示与我展示的第一个示例类似的问题,但我已经设置了环境:
{
"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"
}
为什么这不起作用?或者,我应该更改什么才能让 lldb 在启动调试器之前正确设置环境路径?
谢谢!
我找到了将导出变量传递给 lldb 的答案。只需在 .vscode 目录中创建一个名为 project.env 的文件即可。
将其添加到其中:
DYLD_LIBRARY_PATH=/Users/cdwalke8/Desktop/Dev/Build/lib
然后,更改 launch.json 以包含
envFile
设置:
{
"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",
"envFile": "/Users/cdwalke8/Desktop/Dev/examples/.vscode/project.env"
}
],
"version": "2.0.0"
}