The LLDB Debugger

# Continuous Integraton

The following LLVM buildbots build and test LLDB trunk:

- LLDB Linux x86_64 build with Clang (automake)
- LLDB Linux x86_64 build with GCC 4.6 (automake)
- LLDB Mac OS X x86_64 build with Clang (XCode)

# 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:

## Preliminaries

- XCode 4.3 or newer requires the "Command Line Tools" component (XCode->Preferences->Downloads->Components).
- Mac OS X Lion or newer requires installing Swig.

## Building LLDB

- 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

Supported compilers for building LLDB on Linux include:

- Clang 3.2
- GCC 4.6.2 (later versions should work as well)

It is recommended to use libstdc++ 4.6 (or higher) to build LLDB on Linux, but using libc++ is also known to work.

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 run:

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

On an Ubuntu system one might run:

`> sudo apt-get install swig python-dev libedit-dev`

## 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, building the LLDB trunk revision requires trunk revisions of both LLVM and Clang.

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. A typical build procedure might be:

`> cd $llvm/..
> mkdir build
> cd build`

## To build with CMake

Using CMake is documented on the Building LLVM with CMake page. Building LLDB is possible using one of the following generators:

- Ninja
- Unix Makefiles

### Using CMake + Ninja

Ninja is the fastest way to build LLDB! In order to use ninja, you need to have recent versions of CMake and ninja on your system. To build using ninja:

`
> cmake -C .. -G Ninja
> ninja lldb
> ninja check-lldb`

### Using CMake + Unix Makefiles

If you do not have Ninja, you can still use CMake to generate Unix Makefiles that build LLDB:

`
> cmake -C ..
> make
> make check-lldb`

## To build with autoconf

If you do not have CMake, it is still possible to build LLDB using the autoconf build system. If you are using Clang or GCC 4.7+, run:

`
> $llvm/configure --enable-cxx11
> make`

Or, if you are using a version of GCC that does not support the `-std=c++11` option:

`
> $llvm/configure
> make CXXFLAGS=-std=c++0x`

To run the LLDB test suite, run:

`
> make -C tools/lldb/test`

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 run `make` from the `build/tools/lldb` subdirectory as well.

If you wish to build with libc++ instead of libstdc++ (the default), run configure with the `--enable-libcpp` flag.

If you wish to build a release version of LLDB, run configure with the `--enable-optimized` flag.

## Additional Notes

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. To test that the lldb Python module is built correctly and is available to the default Python interpreter, run:

`> python -c 'import lldb'`