As developers, we often find ourselves deep in debugging sessions, relying heavily on tools like LLDB (Low Level Debugger). However, one common frustration with LLDB is its lack of built-in command history and advanced line editing features by default. In this post, we'll explore two methods to enhance LLDB's functionality: using rlwrap
and compiling LLDB with native readline support.
Method 1: Using rlwrap
What is rlwrap?
rlwrap
(readline wrapper) is a utility that adds readline-style editing and history capabilities to command line programs that don't have these features built-in. It's a quick and easy way to improve LLDB's usability without modifying the debugger itself.
Features of rlwrap:
- Maintains a history of commands
- Provides searchable history (use Ctrl-R to search backwards)
- Allows line editing with arrow keys, home/end, etc.
- Can save history between sessions
- Offers tab completion (if supported by the wrapped program)
Setting up rlwrap with LLDB:
- Install
rlwrap
:- On macOS with Homebrew:
brew install rlwrap
- On Ubuntu/Debian:
sudo apt-get install rlwrap
- On macOS with Homebrew:
- Create an alias in your shell configuration file (e.g.,
~/.bashrc
,~/.zshrc
):alias lldb='rlwrap lldb'
- Reload your shell configuration or start a new terminal session.
Now, when you run lldb
, you'll have access to command history, line editing, and other readline features.
Method 2: Compiling LLDB with Native Readline Support
For a more integrated solution, we can compile LLDB from source with readline support enabled. This method provides native readline functionality without relying on external wrappers.
Steps to Compile LLDB with Readline:
- Install prerequisites:
sudo apt-get update sudo apt-get install -y cmake ninja-build libreadline-dev
- Clone the LLVM project (which includes LLDB):
git clone https://github.com/llvm/llvm-project.git cd llvm-project
- Create a build directory and configure CMake:
mkdir build && cd build cmake -G Ninja ../llvm \ -DLLVM_ENABLE_PROJECTS="clang;lldb" \ -DCMAKE_BUILD_TYPE=Release \ -DLLDB_ENABLE_LIBEDIT=OFF \ -DLLDB_ENABLE_CURSES=OFF \ -DLLDB_ENABLE_READLINE=ON \ -DCMAKE_INSTALL_PREFIX=/usr/local
- Build and install LLDB:
ninja lldb sudo ninja install-lldb
This process will give you an LLDB binary with native readline support, providing features like searchable history and improved line editing.
Considerations
- The
rlwrap
method is quick and doesn't require recompiling LLDB, but it's an external wrapper and may not integrate as seamlessly. - Compiling LLDB from source provides a more integrated solution but requires more time, disk space, and technical knowledge.
- Building LLDB replaces your system's LLDB with a custom version. Make sure to back up your current installation first.
Final words
Both methods significantly improve LLDB's usability by adding crucial features like command history and advanced line editing. The choice between using rlwrap
or compiling with readline support depends on your specific needs and comfort level with building software from source.
By enhancing LLDB with these readline capabilities, you can make your debugging sessions more efficient and enjoyable. Happy debugging!