Member-only story
How To Add Swift Code as a Custom LLDB Command
Let’s juice up that LLDB debugger!
If I asked iOS developers which LLDB command they use the most, they would probably answer po
. But did you know that you can actually define your own custom LLDB command using purely Swift code?
In this article, I will show you what it takes to create your own LLDB command. Here is what I will be covering:
- Adding your first LLDB command
- Adding an LLDB command with arguments
- Converting complex Swift code to an LLDB command
Let’s get started!
Adding Your First LLDB Command
Understanding the LLDB command structure
In order to add a custom LLDB command, we must leverage the command alias
LLDB command. It has the following structure:
command alias [command_name] expr -l Swift -O -- [swift_code]
Let’s break down this command in detail:
command alias
: The LLDB command that aliases the Swift code with a name.[command_name]
: The custom command name.expr -l Swift -O --
: Asks the LLDB debugger to interpret everything that follows as Swift code.