The LLDB Debugger (LLDB) is the debugger created by Chris Lattner as a component of the LLVM project. It is built as a set of reusable components which extensively use existing libraries from LLVM, such as the Clang expression parser and LLVM disassembler. LLDB is free and open-source software under the University of Illinois/NCSA Open Source License, a BSD-style permissive software license. Since v9.0.0, it was relicensed to the Apache License 2.0 with LLVM Exceptions.

Current state

LLDB supports debugging of programs written in C, Objective-C, and C++. The Swift community maintains a version which adds support for the language. Free Pascal and the Lazarus IDE can use LLDB as backend for their own FpDebug engine.

The LLDB debugger is known to work on macOS, Linux, FreeBSD, NetBSD and Windows, and supports i386, x86-64, and ARM instruction sets. LLDB is the default debugger for Xcode 5 and later. Android Studio also uses LLDB for debug. LLDB can be used from other IDEs, including Visual Studio Code, C++Builder, Eclipse, and CLion.

Features matrix
FeatureFreeBSDLinuxmacOSNetBSDWindows
Backtracing
Breakpoints
C++11?
Command-line lldb tool
Core file debugging
Debugserver (remote debugging)
Disassembly
Expression evaluationWorks with some bugsWorks with some bugsWorks with some bugsWorks with some bugs
JIT debugging?Symbolic debugging onlyUntestedWork In Progress
Objective-C 2.0:?—N/a?—N/a

Examples of commands

lldb programDebug "program" (from the shell)
runRun the loaded program
break set -n mainSet a breakpoint at the start of function "main"
btBacktrace (in case the program crashed)
register readDump all registers
di -n mainDisassemble the function "main"

An example session

Consider the following incorrect program written in C:

Using the clang compiler on macOS, the code above can be compiled using the -g flag to include appropriate debug information on the binary generated—including the source code—making it easier to inspect it using LLDB. Assuming that the file containing the code above is named test.c, the command for the compilation could be:

And the binary can now be run:

Since the example code, when executed, generates a segmentation fault, lldb can be used to inspect the problem:

The problem occurs when calling the function strlen, but we can run a backtrace to identify the exact line of code that is causing the problem:

From the line beginning with frame #5, LLDB indicates that the error is at line 5 of test.c. Running source list, we see that this refers to the call to printf. According to the exception code EXC_BAD_ACCESS from the backtrace, strlen is trying to read from a region of memory it does not have access to by dereferencing an invalid pointer. Returning to the source code, we see that the variable msg is of type char but contains a string instead of a character. To fix the problem, we modify the code to indicate that msg is a pointer to a string of chars by adding the * operator:

After recompiling and running the executable again, LLDB now gives the correct result:

LLDB runs the program, which prints the output of printf to the screen. After the program exits normally, LLDB indicates that the process running the program has completed, and prints its exit status.

See also

External links