The LLDB Debugger

# Building LLDB on Mac OS X

Building on Mac OS X is as easy as downloading the code and building the Xcode project or workspace:

- Download the lldb sources.
- Follow the code signing instructions in lldb/docs/code-signing.txt
- In Xcode 3.x: lldb/lldb.xcodeproj, select the lldb-tool target, and build.
- In Xcode 4.x: lldb/lldb.xcworkspace, select the lldb-tool scheme, and build.

# Building LLDB on Linux

This document describes the steps needed to compile LLDB on most Linux systems.

## Preliminaries

LLDB relies on many of the technologies developed by the larger LLVM project. In particular, it requires both Clang and LLVM itself in order to build. Due to this tight integration the Getting Started guides for both of these projects come as prerequisite reading:

- LLVM
- Clang

In addition to any dependencies required by LLVM and Clang, LLDB needs a few development packages that may also need to be installed depending on your system. The current list of dependencies are:

- Swig
- libedit
- Python

So for example, on a Fedora system one might say:

`> yum install swig python-devel libedit-devel`

## Building LLDB

We first need to checkout the source trees into the appropriate locations. Both Clang and LLDB build as subprojects of LLVM. This means we will be checking out the source for both Clang and LLDB into the `tools` subdirectory of LLVM. We will be setting up a directory hierarchy looking something like this:

                      llvm
                      |
                      `-- tools
                          |
                          +-- clang
                          |
                          `-- lldb

For reference, we will call the root of the LLVM project tree `$llvm`, and the roots of the Clang and LLDB source trees `$clang` and `$lldb` respectively.

Change to the directory where you want to do development work and checkout LLVM:

`> svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm`

Now switch to LLVM’s tools subdirectory and checkout both Clang and LLDB:

`> cd $llvm/tools
> svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
> svn co http://llvm.org/svn/llvm-project/lldb/trunk lldb`

In general, LLDB requires specific revisions of both LLVM and Clang in order to build. This requirement insulates LLDB a bit from the constant development happening in both of these projects. The required revision can be discovered by consulting the Perl script `$lldb/scripts/build-llvm.pl` and locating the `$llvm_revision` variable. At the time of this writing, the required revision is `r127682`, so we might check and revert our LLVM and Clang trees to the required state as follows:

`> grep -m 1 llvm_revision $lldb/scripts/build-llvm.pl
our $llvm_revision = "127682";
> cd $clang
> svn update -r 127682
> cd $llvm
> svn update -r 127682`

It is highly recommended that you build the system out of tree. Create a second build directory and configure the LLVM project tree to your specifications as outlined in LLVM’s Getting Started Guide. For Linux development the x86 backend and JIT compiler should be enabled. A typical build procedure might be:

`> cd $llvm/..
> mkdir build
> cd build
> $llvm/configure --enable-targets=x86 --enable-jit
> make`

Note that once both LLVM and Clang have been configured and built it is not necessary to perform a top-level `make` to rebuild changes made only to LLDB. You can build from the `build/tools/lldb` subdirectory as well.

## Additional Notes

LLDB has a Python scripting capability and supplies it’s own Python module, `lldb.py`, built alongside the `lldb` binary. Python needs to know where to look for this module when LLDB starts up. There are two options available:

1. Keep a copy of `lldb.py` in the current working directory when starting lldb.

2. Set `PYTHONPATH` to point to the directory holding `lldb.py`.