Mobile Development 14 min read

LLDB Overview and Common Commands

LLDB is a high‑performance debugger integrated with Xcode that supports C, Objective‑C, and C++ development; this article introduces its command‑line syntax, explains key commands such as help, expression, thread, breakpoint, watchpoint, and image, and provides usage examples to improve debugging efficiency.

JD Retail Technology
JD Retail Technology
JD Retail Technology
LLDB Overview and Common Commands

LLDB Overview

LLDB is a high‑performance debugger composed of reusable components that heavily leverage existing LLVM libraries such as the Clang expression parser and the LLVM disassembler. It is the default debugger in Xcode and supports debugging of desktop and mobile applications written in C, Objective‑C, and C++.

Most Xcode users are familiar with LLDB’s convenient command‑navigation area and auto‑completion, but many only use a few basic commands for simple output. This article summarizes common LLDB commands and introduces some advanced usages to help developers debug faster and more accurately.

LLDB Command‑Line Syntax

<command> [<subcommand> [<subcommand>...]] <action> [-options [option‑value]] [argument [argument...]]
command: command name subcommand: sub‑command action: optional action option: optional command option argument: optional argument

Example:

breakpoint set -n main
command: breakpoint command action: set to create a breakpoint option: -n specifies the method name argument: main indicates the method name

When the action part is omitted, everything after the command is treated as arguments; when an action is present, “--” separates options from arguments.

- expression obj/value   // print an object’s address or value
- expression -o --obj   // invoke an object’s description method

Common LLDB Commands

help

Syntax: help <command>

The help command shows the usage of a specific LLDB command, similar to other terminal utilities.

Example:

(lldb) help expression
    Evaluate an expression on the current thread...
Syntax: expression <cmd‑options> -- <expr>
...

expression

Syntax: expression -- <expr>

options: command options --: end of options expr: expression to evaluate

Use this command to evaluate a method or expression at the current breakpoint without recompiling, saving debugging time.

Example:

expression self.refreshFlag = YES //

It can also be used for printing object information.

(lldb) expression -O -- arr
<__NSArrayI 0x600001f6cf00>(1,2,3)
(lldb) expression arr
(__NSArrayI *) $2 = 0x000060001f6cf00 @"3 elements"

thread

Syntax: thread [subcommand]

Commands for operating on one or more threads, such as displaying backtraces or stepping.

Example:

(lldb) thread backtrace
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
  * frame #0: ... ViewController.m:43:5
...
(lldb) thread continue
(lldb) thread step-in
(lldb) thread step-over
(lldb) thread step-out
(lldb) thread step-inst-over
(lldb) thread step-inst
(lldb) c   // short for continue
(lldb) n   // short for step-over
(lldb) s   // short for step-in
(lldb) nexti // short for step-inst-over

breakpoint

Syntax: breakpoint [subcommand]

Setting breakpoints helps locate execution points in code. LLDB provides powerful breakpoint commands.

Examples:

(lldb) breakpoint set               // set a breakpoint
(lldb) breakpoint set -n function1   // by function name
(lldb) breakpoint set -r regex       // by regular expression
(lldb) breakpoint list               // list all breakpoints
(lldb) breakpoint delete 3          // delete breakpoint 3
(lldb) breakpoint disable 2         // disable breakpoint 2
(lldb) breakpoint enable 2          // enable breakpoint 2

Breakpoint commands can attach custom debugger commands to a breakpoint, allowing on‑the‑fly code changes without recompilation.

(lldb) breakpoint command add 2
Enter your debugger command(s). Type 'DONE' to end.
> p self.view.backgroundColor = [UIColor redColor]
> p arr = @["1","2","3"]
> DONE
(lldb) breakpoint command list 2
Breakpoint commands:
    p self.view.backgroundColor = [UIColor redColor]
    p arr = @["1","2","3"]
(lldb) breakpoint command delete 2

watchpoint

Syntax: watchpoint [subcommand]

Watchpoints are memory breakpoints that pause execution when a specified memory location is read or written.

Examples:

(lldb) watchpoint set variable self->_refreshFlag
Watchpoint created: Watchpoint 1: addr = 0x7fca58007510 size = 1 state = enabled type = w
...
(lldb) watchpoint set expression &self->_mail
Watchpoint created: Watchpoint 1: addr = 0x7feb61509908 size = 8 state = enabled type = w
...
(lldb) watchpoint list
...
(lldb) watchpoint disable
All watchpoints disabled.
(lldb) watchpoint enable
All watchpoints enabled.

image

Syntax: target modules …

The image command accesses information about loaded modules, useful for inspecting dynamic libraries or locating class addresses.

Example:

(lldb) image list
[ 0] 913F3F08… /path/to/DebugTestProject.app/DebugTestProject
[ 1] 1D318D60… /usr/lib/dyld
...
(lldb) image lookup -t NSArray
Best match found in … DebugTestProject:
id = {0x7fffffff000002a7}, name = "NSArray", byte-size = 8, decl = NSArray.h:17

Conclusion

Although Xcode provides a graphical interface for common debugging actions, understanding LLDB’s command syntax and usage scenarios enables more flexible and powerful debugging, improving development efficiency. Future updates will expand this guide with additional commands and use cases.

iOSXcodebreakpointCommandLineLLDB
JD Retail Technology
Written by

JD Retail Technology

Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.