Saturday, 17 May 2014

Getting lldb python module on Mac OS X

I was recently browsing lldb seeing that I had access the the awesome world of lldb (our very own debugger) via a python module and I could create custom lldb functions usable in Xcode directly.

But when I tried to check out the module, my python installation could not find the module!

The problem is simple, the module is not present in my `$PYTHONPATH`. Searching around a bit I gathered that the lldb module is a property of Xcode and thus is ported with the app itself. The path to the module is 
Now, the other issue, was how do I add this to my `$PYTHONPATH`. It would be outrageous to add a line on top of my every python script that fixes the `$PYTHONPATH` for me. The solution was in `~/.pythonrc`. I added the following code to my`~/.pythonrc` :

Voila! It is done! Now whenever I fire up python, `~/.pythonrc` is executed first, thus changing (fixing) the  `$PYTHONPATH` for every script of me.

Note : chisel is a great source of information on how things work and would work regarding the lldb python module.

Reference:
  1. http://lldb.llvm.org/python-reference.html - lldb python reference
  2. https://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH
  3. https://docs.python.org/2/library/user.html - .pythonrc reference
  4. https://github.com/facebook/chisel - a collection of LLDB commands to assist debugging iOS apps by facebook.