According to LLDB main page, LLDB can be imported in a python script like this:
import lldb
After installing LLDB from a release package (on Lubuntu 15.04: sudo apt-get install lldb), I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/lldb/__init__.py", line 52, in <module>
_lldb = swig_import_helper()
File "/usr/lib/python2.7/dist-packages/lldb/__init__.py", line 44, in swig_import_helper
ImportError: No module named _lldb
This is expected! the LLDB page says:
LLDB has a Python scripting capability and supplies its own Python module named lldb. If a script is run inside the command line lldb application, the Python module is made available automatically. However, if a script is to be run by a Python interpreter outside the command line application, the PYTHONPATH environment variable can be used to let the Python interpreter find the lldb module.
The correct path can be obtained by invoking the command line lldb tool with the -P flag:
> export PYTHONPATH=`$llvm/build/Debug+Asserts/bin/lldb -P`
If you used a different build directory or made a release build, you may need to adjust the above to suit your needs.
So the those confident enough to build LLDB themselves get a clear instruction and the noobs who just want to use a released package are left with a vague explanation...
Does any one figured out what exactly means "adjust the above to suit your needs" for the most basic case where you install everything from release packages ? The path reported by lldb -P does not solve the problem:
user@user-VirtualBox:~$ lldb -P
/usr/lib/x86_64-linux-gnu/python2.7/site-packages
user@user-VirtualBox:~$ ls /usr/lib/x86_64-linux-gnu/python2.7/site-packages
ls: cannot access /usr/lib/x86_64-linux-gnu/python2.7/site-packages: No such file or directory
Looks like the symlinks that the lldb python package installs are botched. If you look in
/usr/lib/llvm-3.6/lib/python2.7/site-packages/lldb
you'll see three broken simlinks referencing the nonexistentx86_64-linux-gnu
directory. This fixed it for me (tested on Ubuntu 14.04, not Lubuntu but I'm assuming the issue is the same):