Better Programming

Advice for programmers.

Follow publication

Member-only story

How To Add Swift Code as a Custom LLDB Command

Let’s juice up that LLDB debugger!

Lee Kah Seng
Better Programming
Published in
6 min readJun 2, 2021

--

Drawing of code on monitor
Image by the author.

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.

--

--

Lee Kah Seng
Lee Kah Seng

Written by Lee Kah Seng

Support me by becoming a Medium member: https://leekahseng.medium.com/membership ⦿ 🇲🇾 Creator of https://swiftsenpai.com ⦿ iOS developer since 2011

No responses yet

Write a response