LLDB Command Guide for iOS Debugging
This article introduces the most commonly used LLDB commands for iOS development, covering command syntax, help utilities, expression evaluation, printing, thread management, breakpoints, and watchpoints, and provides practical code examples to improve debugging efficiency in Xcode.
During iOS development, static analysis, breakpoints, and the console are frequently used for debugging. This guide focuses on the LLDB commands that Xcode provides for both desktop and iOS device debugging, supporting C, Objective‑C, and C++.
LLDB is a high‑performance debugger built on reusable components from the LLVM project, such as the Clang expression parser and LLVM disassembler. It is the default debugger in Xcode on macOS and iOS.
The basic LLDB command format is:
<command name> <command action> [-option [option value]] [arg1 [arg2...]]Commands are space‑separated; arguments containing spaces must be quoted, and quotes or backslashes inside arguments need escaping.
Use the help command to view usage details for any command:
(lldb) help help
Show a list of all debugger commands, or give details about a specific command.
Syntax: help [<cmd-name>]
Command Options Usage:
help [-ahu] [<cmd-name> [<cmd-name> ...]]
-a (--hide-aliases) Hide aliases in the command list.
-h (--show-hidden-commands) Include commands prefixed with an underscore.
-u (--hide-user-commands) Hide user‑defined commands from the list.The expression (or expr , e ) command evaluates an expression and prints the result. Examples:
(lldb) expression count
(unsigned long) $0 = 10
(lldb) expression [string stringByAppendingString:@"732"]
(__NSCFString *) $1 = 0x00006000006ac870 @"QiShare732"
(lldb) expression self.view.backgroundColor = [UIColor redColor]
(UICachedDeviceRGBColor *) $2 = 0x0000600001d74780
(lldb) expression [CATransaction flush]The print (or p , pri ) command is a shortcut for expression -- . It prints variables or expressions, and can be combined with format specifiers:
p/x count // hexadecimal
p/d count // signed decimal
p/u count // unsigned decimal
p/o count // octal
p/t count // binary
p/a string // address
p/c string // character constant
p/f string // floating point
p/s string // string
p/r expr // formatted outputThread commands allow inspection of thread state. Common subcommands include thread list , thread backtrace (alias bt ), and thread return :
(lldb) thread list
Process 4031 stopped
* thread #1: tid = 0x25cac, ...
thread #2: tid = 0x25d2f, ... (lldb) thread backtrace
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
frame #0: ...
frame #1: ...Breakpoints can be managed with the breakpoint command. Examples:
(lldb) breakpoint list
(lldb) breakpoint set -n viewDidAppear:
(lldb) breakpoint set -f QiConsoleViewController.m -n testLLDBCommands
(lldb) breakpoint set -f QiConsoleViewController.m -l 32
(lldb) breakpoint set -n handleString: -c "string != nil"Watchpoints monitor memory addresses for changes, similar to KVO. Example:
(lldb) watchpoint set variable string
Watchpoint created: Watchpoint 1: addr = 0x7ffeef497360 size = 8 state = enabled type = w
declare @ '/Users/.../QiConsoleViewController.m:33'
watchpoint spec = 'string'
new value: 0x00000001007670b8
(lldb) next
Watchpoint 1 hit:
old value: 0x00000001007670b8
new value: 0x0000000100767138
(lldb) image lookup -a 0x00000001007670b8
Address: QiDebugDemo[0x00000001000040b8] (QiDebugDemo.__DATA.__cfstring + 32)
Summary: @"QiShare"The article lists only a subset of useful LLDB commands; for a complete reference, consult the LLDB homepage (http://lldb.llvm.org) or other online resources.
360 Tech Engineering
Official tech channel of 360, building the most professional technology aggregation platform for the brand.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.