lldb with app using shared lib not working


if I try to debug an application from the terminal that is using a
shared lib lldb complains always about not finding the library even
though everything is loading correctly when starting the app directly
from the same terminal:

<some path>

running with debugger, shared lib can be loaded:

otool -L DARWIN_X64/test_app
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 1225.1.1)
    libmyapp.dylib (compatibility version 0.0.0, current version 0.0.0)

lldb -f DARWIN_X64/test_app
(lldb) target create "DARWIN_X64/test_app"
Current executable set to 'DARWIN_X64/test_app' (x86_64).
(lldb) r
Process 32234 launched: '/Users/xxx/yyy/zzz/source/DARWIN_X64/test_app'
dyld: Library not loaded: libmyapp.dylib
  Referenced from: /Users/xxx/yyy/zzz/source/DARWIN_X64/test_app
  Reason: image not found
Process 32234 stopped
* thread #1: tid = 0x85c524, 0x00007fff5fc01075 dyld`dyld_fatal_error +
1, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
    frame #0: 0x00007fff5fc01075 dyld`dyld_fatal_error + 1
-> 0x7fff5fc01075 <+1>: nop

    0x7fff5fc01076 <+0>: pushq %rbp
    0x7fff5fc01077 <+1>: movq %rsp, %rbp
    0x7fff5fc0107a <+4>: pushq %r15

how can I achieve that the shared lib is used in the debugger correctly,
do I have to set some additional environment variables. Is there a
special r (process launch) syntax that I need to use ?

in gdb it used to work like a charm...

thanks for any help you can deliver in advance,



I found the solution to the problem:
DYLD_* env variables are purged from the environment due to SIP in El Capitan.
It is necessary to set any DYLD_* variable settings within (lldb)


lldb -f DARWIN_X64/test_app
(lldb) target create "DARWIN_X64/test_app"
Current executable set to 'DARWIN_X64/test_app' (x86_64).
(lldb) env DYLD_LIBRARY_PATH=<directory where lib lives>
(lldb) r

then the shared lib is honored as expected inside lldb.


You can else set environment variables when you launch manually:

(lldb) process launch -v DYLD_FRAMEWORK_PATH=/tmp -- arg1 arg2

"env" is nice because it sets it permanently for your target and you don't have to specify it over and over. But it you ever want to _sometimes_ launch with a different framework, the "-v" or "--environemnt" option to process launch can come in handy.