LLDB: how to "set solib-search-path" or "set sysroot"?


With GDB, I could debug binary using core by just setting “set solib-search-path” or “set sysroot”.

While I am trying to find similar options for LLDB, I am not able to find in GDB to LLDB command map — The LLDB Debugger

I have tried:
(lldb) settings append target.exec-search-paths
(lldb) target modules search-paths add
but no luck in getting correct ‘bt’.

Can you please suggest set of simple steps to analyze a historical core, where ‘corefile’ and ‘binary’ files are present?

Thank you in advance.

To test this I created a crashing program and ran it from /tmp then moved it to <cwd>/foo/. If I saw symbols in the backtrace I assumed it had found the program file. I assume that roughly models your use case.

You can do:

$ ./bin/lldb foo/test.o --core core
(lldb) target create "foo/test.o" --core "core"

Likely you don’t want to have to specify the binary each time though.

So I tried target.exec-search-paths. This appears to only change things if it’s set before the core file is loaded.

$ ./bin/lldb
(lldb) settings append target.exec-search-paths "/tmp" "/home/david.spickett/build-llvm-aarch64/foo"
(lldb) target create -c core
Core file '/home/david.spickett/build-llvm-aarch64/core' (aarch64) was loaded.

So you don’t have to do it interactively each time:

$ ./bin/lldb --one-line-before-file "settings append target.exec-search-paths "/tmp" "/home/david.spickett/build-llvm-aarch64/foo"" --core
(lldb) settings append target.exec-search-paths /tmp /home/david.spickett/build-llvm-aarch64/foo
(lldb) target create --core "core"
Core file '/home/david.spickett/build-llvm-aarch64/core' (aarch64) was loaded.
(lldb) bt
* thread #1, name = 'test.o', stop reason = signal SIGSEGV
  * frame #0: 0x0000aaaad7247724 test.o`main at test.c:3:17

I’d assume that search paths for the initial executable are also used for shared objects, but I haven’t checked that myself.

1 Like

I could get symbols and bt with above steps.
Thanks DavidSpickett!

Got few more queries:
(A) When libs are in sub-dirs – /tmp/dir1/, /tmp/dir2, /tmp/dir3, then just specifying
–one-line-before-file “settings append target.exec-search-paths “/tmp” “/home/david.spickett/build-llvm-aarch64/foo””

“/tmp” in above line didn’t work.
To make it work I need to pass /tmp/dir1, /tmp/dir2 etc.

Do we have any alternatives?

(B) Is there a plan to make it one-to-one command mapping with GDB ?
Or at least aliases?

(C) Any guidance on migrating from GDB to LLDB, specific to historical-core-analysis, is welcome :slight_smile:

Thank you.

I think (did not check this) that this is the code that uses those paths: llvm-project/ModuleList.cpp at 06ade34c4bf8378f960b7e7564f1ba2316f6a990 · llvm/llvm-project · GitHub

At a glance, it does not search folders within folders only path + filename. Unlike the source path substitutions which do work as you expected.

Not sure if they should be doing a deeper search, I haven’t done enough of this to say. I suppose the use case if supplying sysroot/lib/ where all the libs are in a flat folder.

Alternatives, not to my knowledge.

Can you raise an issue for this? (Issues · llvm/llvm-project · GitHub) At least we can get the justification for the current behavior on record.

No plans to achieve one to one but there are some existing aliases like p that accept the GDB style formatting arguments.

Raise an issue/propose a patch (Contributing to LLVM — LLVM 16.0.0git documentation) /post here again if you have some ideas. If some commands act almost the same it seems like a decent thing to do. If we have to emulate a whole new command style, then no.

Not from me unfortunately, the Apple folks will have more practical experience I think. Keep asking questions here you might catch their attention :slight_smile: