npx skills add https://github.com/charleswiltgen/axiom --skill axiom-lldb-refXcode 中 LLDB 的完整命令参考。按任务组织,方便您找到所需的命令。
有关调试工作流和决策树,请参阅 /skill axiom-lldb。
v / frame variable直接读取内存。无需编译。对于 Swift 值最可靠。
(lldb) v # 当前帧中的所有变量
(lldb) v self # 当前上下文中的 self
(lldb) v self.propertyName # 特定属性
(lldb) v localVariable # 局部变量
(lldb) v self.array[0] # 集合元素
(lldb) v self._showDetails # SwiftUI @State 后备存储(下划线前缀)
标志:
| 标志 | 效果 |
|---|---|
-d run |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 运行动态类型解析(较慢但更准确) |
-T | 显示类型 |
-R | 显示原始(未格式化)输出 |
-D N | 将嵌套类型的深度限制为 N 层 |
-P N | 将指针深度限制为 N 层 |
-F | 扁平化输出(无层次结构) |
限制: 无法计算表达式、计算属性或函数调用。请使用 p。
p / expression (带格式)编译并执行表达式。显示格式化结果。
(lldb) p self.computedProperty
(lldb) p items.count
(lldb) p someFunction()
(lldb) p String(describing: someValue)
(lldb) p (1...10).map { $0 * 2 }
结果存储在编号变量中:
(lldb) p someValue
$R0 = 42
(lldb) p $R0 + 10
$R1 = 52
po / expression --object-description对结果调用 debugDescription(或 description)。
(lldb) po myObject
(lldb) po error
(lldb) po notification.userInfo
(lldb) po NSHomeDirectory()
po 何时有价值: 实现了 CustomDebugStringConvertible 的类、NSError、NSNotification、对象集合。
po 何时失败: 未实现 CustomDebugStringConvertible 的 Swift 结构体、协议类型的值(改用 v — 它执行迭代动态类型解析,而 po 不会)。
expression (完整形式)包含所有选项的完整表达式求值。
(lldb) expression self.view.backgroundColor = UIColor.red
(lldb) expression self.debugFlag = true
(lldb) expression myArray.append("test")
(lldb) expression CATransaction.flush() # 强制 UI 更新
(lldb) expression Self._printChanges() # SwiftUI 调试
标志:
| 标志 | 效果 |
|---|---|
-l objc | 作为 Objective-C 求值 |
-l swift | 作为 Swift 求值(默认) |
-O | 对象描述(与 po 相同) |
-i false | 在求值期间命中断点时停止(默认:忽略) |
-- | 标志和表达式之间的分隔符 |
用于 Swift 调试的 ObjC 表达式:
(lldb) expr -l objc -- (void)[[[UIApplication sharedApplication] keyWindow] recursiveDescription]
(lldb) expr -l objc -- (void)[CATransaction flush]
(lldb) expr -l objc -- (int)[[UIApplication sharedApplication] _isForeground]
register read低级寄存器检查:
(lldb) register read
(lldb) register read x0 x1 # 特定寄存器 (ARM64)
(lldb) register read --all # 所有寄存器组
(lldb) breakpoint set -f File.swift -l 42 # 文件 + 行号
(lldb) b File.swift:42 # 简短形式
(lldb) breakpoint set -n methodName # 按函数名
(lldb) breakpoint set -n "MyClass.myMethod" # 限定名
(lldb) breakpoint set -S layoutSubviews # ObjC 选择器
(lldb) breakpoint set -r "viewDid.*" # 名称正则表达式
(lldb) breakpoint set -a 0x100abc123 # 内存地址
(lldb) breakpoint set -f File.swift -l 42 -c "value == nil"
(lldb) breakpoint set -f File.swift -l 42 -c "index > 100"
(lldb) breakpoint set -f File.swift -l 42 -c 'name == "test"'
(lldb) breakpoint set -f File.swift -l 42 -i 50 # 跳过前 50 次命中
(lldb) breakpoint set -f File.swift -l 42 -o # 首次命中后删除
添加断点命中时执行的命令:
(lldb) breakpoint command add 1
> v self.state
> p self.items.count
> continue
> DONE
或者单行形式:
(lldb) breakpoint command add 1 -o "v self.state"
(lldb) breakpoint set -E swift # 所有 Swift 错误
(lldb) breakpoint set -E objc # 所有 ObjC 异常
# 按异常名称过滤需要 Xcode 的 GUI(编辑断点 → Exception 字段)
(lldb) breakpoint set -n UIViewAlertForUnsatisfiableConstraints # 自动布局
(lldb) breakpoint set -n "-[UIApplication _run]" # 应用启动
(lldb) breakpoint set -n swift_willThrow # Swift 抛出
(lldb) breakpoint list # 列出所有
(lldb) breakpoint list -b # 简要格式
(lldb) breakpoint enable 3 # 启用断点 3
(lldb) breakpoint disable 3 # 禁用断点 3
(lldb) breakpoint delete 3 # 删除断点 3
(lldb) breakpoint delete # 删除所有(请求确认)
(lldb) breakpoint modify 3 -c "x > 10" # 向现有断点添加条件
当变量的内存发生变化时中断:
(lldb) watchpoint set variable self.count # 监视写入
(lldb) watchpoint set variable -w read_write myGlobal # 监视读取或写入
(lldb) watchpoint set expression -- &myVariable # 监视内存地址
(lldb) watchpoint list # 列出所有
(lldb) watchpoint delete 1 # 删除监视点 1
(lldb) watchpoint modify 1 -c "self.count > 10" # 添加条件
注意: 硬件监视点数量有限(每个进程约 4 个)。请谨慎使用。
(lldb) bt # 当前线程回溯
(lldb) bt 10 # 限制为 10 帧
(lldb) bt all # 所有线程
(lldb) thread backtrace all # 与 bt all 相同
(lldb) thread list # 列出所有线程及其状态
(lldb) thread info # 当前线程详细信息 + 停止原因
(lldb) thread select 3 # 切换到线程 3
(lldb) frame info # 当前帧详细信息
(lldb) frame select 5 # 跳转到帧 5
(lldb) up # 向上移动一帧(朝向调用者)
(lldb) down # 快捷方式:向下移动一帧
强制从当前函数提前返回:
(lldb) thread return # 返回 void
(lldb) thread return 42 # 返回特定值
请谨慎使用 — 会跳过清理代码,可能导致状态不一致。
(lldb) expr let x = 42; print(x)
(lldb) expr self.view.backgroundColor = UIColor.red
(lldb) expr UIApplication.shared.windows.first?.rootViewController
(lldb) expr UserDefaults.standard.set(true, forKey: "debug")
当 Swift 表达式解析器失败时切换到 ObjC:
(lldb) expr -l objc -- (void)[CATransaction flush]
(lldb) expr -l objc -- (id)[[UIApplication sharedApplication] keyWindow]
(lldb) expr -l objc -- (void)[[NSNotificationCenter defaultCenter] postNotificationName:@"test" object:nil]
(lldb) expr -l objc -- (void)[[[UIApplication sharedApplication] keyWindow] recursiveDescription]
(lldb) po UIApplication.shared.windows.first?.rootViewController?.view.recursiveDescription()
(lldb) expr Self._printChanges() # 打印触发 body 重新求值的原因(仅在视图 body 内部有效)
(lldb) expr type(of: someValue)
(lldb) expr String(describing: type(of: someValue))
(lldb) continue # 恢复执行 (c)
(lldb) c # 简短形式
(lldb) process interrupt # 暂停正在运行的进程
(lldb) thread step-over # 单步跳过 (n / next)
(lldb) n # 简短形式
(lldb) thread step-in # 单步进入 (s / step)
(lldb) s # 简短形式
(lldb) thread step-out # 单步跳出 (finish)
(lldb) finish # 简短形式
(lldb) thread step-inst # 单步执行一条指令(汇编级别)
(lldb) ni # 单步跳过一条指令
(lldb) process launch # 启动/重启
(lldb) process attach --pid 1234 # 附加到正在运行的进程
(lldb) process attach --name MyApp # 按名称附加
(lldb) process detach # 分离而不终止
(lldb) kill # 终止被调试进程
(lldb) memory read 0x100abc123 # 读取地址处的内存
(lldb) memory read -c 64 0x100abc123 # 读取 64 字节
(lldb) memory read -f x 0x100abc123 # 格式化为十六进制
(lldb) memory read -f s 0x100abc123 # 格式化为字符串
(lldb) memory find -s "searchString" -- 0x100000000 0x200000000
(lldb) image lookup -a 0x100abc123 # 查找地址处的符号
(lldb) image lookup -n myFunction # 按名称查找函数
(lldb) image lookup -rn "MyClass.*" # 正则表达式搜索
(lldb) image list # 列出所有已加载的镜像/框架
(lldb) image list -b # 简要格式
常见用途: 查找崩溃地址属于哪个框架:
(lldb) image lookup -a 0x1a2b3c4d5
LLDB 在启动时读取 ~/.lldbinit。在 Xcode 方案设置中配置后,也支持每个项目的初始化文件。
添加到 ~/.lldbinit:
# 快速重载 — 刷新通过表达式所做的 UI 更改
command alias flush expr -l objc -- (void)[CATransaction flush]
# 打印视图层次结构
command alias views expr -l objc -- (void)[[[UIApplication sharedApplication] keyWindow] recursiveDescription]
# 打印自动布局约束
command alias constraints po [[UIWindow keyWindow] _autolayoutTrace]
# 将 CLLocationCoordinate2D 显示为 "lat, lon"
type summary add CLLocationCoordinate2D --summary-string "${var.latitude}, ${var.longitude}"
(lldb) settings show target.language # 当前语言
(lldb) settings set target.language swift # 强制 Swift 模式
(lldb) settings set target.max-children-count 100 # 显示更多集合项
在 Xcode 中:编辑方案 → 运行 → 选项 → "LLDB Init File" 字段。
将项目特定的别名和断点放在项目根目录的 .lldbinit 文件中。
原因: Swift 表达式解析器无法从当前模块解析类型。
修复方法:
v(无需编译)expr -l objc -- ...原因: 编译器优化掉了该变量。
修复方法:
-Onone(构建设置 → 每文件编译器标志)register read 检查值是否在寄存器中原因: LLDB 在某些上下文(尤其是在框架中)默认使用 ObjC。
修复方法:
(lldb) settings set target.language swift
(lldb) expr -l swift -- mySwiftExpression
原因: 您求值的表达式产生了导致崩溃的副作用。
修复方法:
v 进行只读检查原因: 通常是编译复杂表达式或在大型项目中解析类型。
修复方法:
v 代替 p/po(无需编译)po 期间挂起,按 Ctrl+C 取消并改用 v原因和修复方法:
| 原因 | 修复方法 |
|---|---|
| 错误的文件/行号(代码已移动) | 在当前代码上重新设置断点 |
| 断点已禁用 | breakpoint enable N |
| 代码未执行 | 验证代码路径是否被执行 |
| 被优化掉(Release) | 切换到 Debug 配置 |
| 在框架/SPM 包中 | 按函数名设置符号断点 |
WWDC : 2019-429, 2018-412, 2022-110370, 2015-402
文档 : /xcode/stepping-through-code-and-inspecting-variables-to-isolate-bugs, /xcode/setting-breakpoints-to-pause-your-running-app
技能 : axiom-lldb, axiom-xcode-debugging
每周安装量
39
仓库
GitHub 星标数
590
首次出现
2026 年 2 月 19 日
安全审计
安装于
opencode37
codex37
gemini-cli36
amp36
github-copilot36
kimi-cli36
Complete command reference for LLDB in Xcode. Organized by task so you can find the exact command you need.
For debugging workflows and decision trees, see /skill axiom-lldb.
v / frame variableReads memory directly. No compilation. Most reliable for Swift values.
(lldb) v # All variables in current frame
(lldb) v self # Self in current context
(lldb) v self.propertyName # Specific property
(lldb) v localVariable # Local variable
(lldb) v self.array[0] # Collection element
(lldb) v self._showDetails # SwiftUI @State backing store (underscore prefix)
Flags:
| Flag | Effect |
|---|---|
-d run | Run dynamic type resolution (slower but more accurate) |
-T | Show types |
-R | Show raw (unformatted) output |
-D N | Limit depth of nested types to N levels |
-P N | Limit pointer depth to N levels |
-F | Flat output (no hierarchy) |
Limitations: Cannot evaluate expressions, computed properties, or function calls. Use p for those.
p / expression (with format)Compiles and executes an expression. Shows formatted result.
(lldb) p self.computedProperty
(lldb) p items.count
(lldb) p someFunction()
(lldb) p String(describing: someValue)
(lldb) p (1...10).map { $0 * 2 }
Result stored in numbered variables:
(lldb) p someValue
$R0 = 42
(lldb) p $R0 + 10
$R1 = 52
po / expression --object-descriptionCalls debugDescription (or description) on the result.
(lldb) po myObject
(lldb) po error
(lldb) po notification.userInfo
(lldb) po NSHomeDirectory()
Whenpo adds value: Classes with CustomDebugStringConvertible, NSError, NSNotification, collections of objects.
Whenpo fails: Swift structs without CustomDebugStringConvertible, protocol-typed values (use v instead — it performs iterative dynamic type resolution that po doesn't).
expression (full form)Full expression evaluation with all options.
(lldb) expression self.view.backgroundColor = UIColor.red
(lldb) expression self.debugFlag = true
(lldb) expression myArray.append("test")
(lldb) expression CATransaction.flush() # Force UI update
(lldb) expression Self._printChanges() # SwiftUI debug
Flags:
| Flag | Effect |
|---|---|
-l objc | Evaluate as Objective-C |
-l swift | Evaluate as Swift (default) |
-O | Object description (same as po) |
-i false | Stop on breakpoints hit during evaluation (default: ignore) |
-- | Separator between flags and expression |
ObjC expressions for Swift debugging:
(lldb) expr -l objc -- (void)[[[UIApplication sharedApplication] keyWindow] recursiveDescription]
(lldb) expr -l objc -- (void)[CATransaction flush]
(lldb) expr -l objc -- (int)[[UIApplication sharedApplication] _isForeground]
register readLow-level register inspection:
(lldb) register read
(lldb) register read x0 x1 # Specific registers (ARM64)
(lldb) register read --all # All register sets
(lldb) breakpoint set -f File.swift -l 42 # File + line
(lldb) b File.swift:42 # Short form
(lldb) breakpoint set -n methodName # By function name
(lldb) breakpoint set -n "MyClass.myMethod" # Qualified name
(lldb) breakpoint set -S layoutSubviews # ObjC selector
(lldb) breakpoint set -r "viewDid.*" # Regex on name
(lldb) breakpoint set -a 0x100abc123 # Memory address
(lldb) breakpoint set -f File.swift -l 42 -c "value == nil"
(lldb) breakpoint set -f File.swift -l 42 -c "index > 100"
(lldb) breakpoint set -f File.swift -l 42 -c 'name == "test"'
(lldb) breakpoint set -f File.swift -l 42 -i 50 # Skip first 50 hits
(lldb) breakpoint set -f File.swift -l 42 -o # Delete after first hit
Add commands that execute when breakpoint hits:
(lldb) breakpoint command add 1
> v self.state
> p self.items.count
> continue
> DONE
Or in one line:
(lldb) breakpoint command add 1 -o "v self.state"
(lldb) breakpoint set -E swift # All Swift errors
(lldb) breakpoint set -E objc # All ObjC exceptions
# Filtering by exception name requires Xcode's GUI (Edit Breakpoint → Exception field)
(lldb) breakpoint set -n UIViewAlertForUnsatisfiableConstraints # Auto Layout
(lldb) breakpoint set -n "-[UIApplication _run]" # App launch
(lldb) breakpoint set -n swift_willThrow # Swift throw
(lldb) breakpoint list # List all
(lldb) breakpoint list -b # Brief format
(lldb) breakpoint enable 3 # Enable breakpoint 3
(lldb) breakpoint disable 3 # Disable breakpoint 3
(lldb) breakpoint delete 3 # Delete breakpoint 3
(lldb) breakpoint delete # Delete ALL (asks confirmation)
(lldb) breakpoint modify 3 -c "x > 10" # Add condition to existing
Break when a variable's memory changes:
(lldb) watchpoint set variable self.count # Watch for write
(lldb) watchpoint set variable -w read_write myGlobal # Watch for read or write
(lldb) watchpoint set expression -- &myVariable # Watch memory address
(lldb) watchpoint list # List all
(lldb) watchpoint delete 1 # Delete watchpoint 1
(lldb) watchpoint modify 1 -c "self.count > 10" # Add condition
Note: Hardware watchpoints are limited (~4 per process). Use sparingly.
(lldb) bt # Current thread backtrace
(lldb) bt 10 # Limit to 10 frames
(lldb) bt all # All threads
(lldb) thread backtrace all # Same as bt all
(lldb) thread list # List all threads with state
(lldb) thread info # Current thread details + stop reason
(lldb) thread select 3 # Switch to thread 3
(lldb) frame info # Current frame details
(lldb) frame select 5 # Jump to frame 5
(lldb) up # Go up one frame (toward caller)
(lldb) down # Shortcut: go down one frame
Force an early return from the current function:
(lldb) thread return # Return void
(lldb) thread return 42 # Return specific value
Use with caution — skips cleanup code, can leave state inconsistent.
(lldb) expr let x = 42; print(x)
(lldb) expr self.view.backgroundColor = UIColor.red
(lldb) expr UIApplication.shared.windows.first?.rootViewController
(lldb) expr UserDefaults.standard.set(true, forKey: "debug")
Switch to ObjC when Swift expression parser fails:
(lldb) expr -l objc -- (void)[CATransaction flush]
(lldb) expr -l objc -- (id)[[UIApplication sharedApplication] keyWindow]
(lldb) expr -l objc -- (void)[[NSNotificationCenter defaultCenter] postNotificationName:@"test" object:nil]
(lldb) expr -l objc -- (void)[[[UIApplication sharedApplication] keyWindow] recursiveDescription]
(lldb) po UIApplication.shared.windows.first?.rootViewController?.view.recursiveDescription()
(lldb) expr Self._printChanges() # Print what triggered body re-eval (inside view body only)
(lldb) expr type(of: someValue)
(lldb) expr String(describing: type(of: someValue))
(lldb) continue # Resume execution (c)
(lldb) c # Short form
(lldb) process interrupt # Pause running process
(lldb) thread step-over # Step over (n / next)
(lldb) n # Short form
(lldb) thread step-in # Step into (s / step)
(lldb) s # Short form
(lldb) thread step-out # Step out (finish)
(lldb) finish # Short form
(lldb) thread step-inst # Step one instruction (assembly-level)
(lldb) ni # Step over one instruction
(lldb) process launch # Launch/restart
(lldb) process attach --pid 1234 # Attach to running process
(lldb) process attach --name MyApp # Attach by name
(lldb) process detach # Detach without killing
(lldb) kill # Kill debugged process
(lldb) memory read 0x100abc123 # Read memory at address
(lldb) memory read -c 64 0x100abc123 # Read 64 bytes
(lldb) memory read -f x 0x100abc123 # Format as hex
(lldb) memory read -f s 0x100abc123 # Format as string
(lldb) memory find -s "searchString" -- 0x100000000 0x200000000
(lldb) image lookup -a 0x100abc123 # Lookup symbol at address
(lldb) image lookup -n myFunction # Find function by name
(lldb) image lookup -rn "MyClass.*" # Regex search
(lldb) image list # List all loaded images/frameworks
(lldb) image list -b # Brief format
Common use: Finding which framework a crash address belongs to:
(lldb) image lookup -a 0x1a2b3c4d5
LLDB reads ~/.lldbinit at startup. Per-project init files are also supported when configured in Xcode's scheme settings.
Add to ~/.lldbinit:
# Quick reload — flush UI changes made via expression
command alias flush expr -l objc -- (void)[CATransaction flush]
# Print view hierarchy
command alias views expr -l objc -- (void)[[[UIApplication sharedApplication] keyWindow] recursiveDescription]
# Print auto layout constraints
command alias constraints po [[UIWindow keyWindow] _autolayoutTrace]
# Show CLLocationCoordinate2D as "lat, lon"
type summary add CLLocationCoordinate2D --summary-string "${var.latitude}, ${var.longitude}"
(lldb) settings show target.language # Current language
(lldb) settings set target.language swift # Force Swift mode
(lldb) settings set target.max-children-count 100 # Show more collection items
In Xcode: Edit Scheme → Run → Options → "LLDB Init File" field.
Put project-specific aliases and breakpoints in a .lldbinit file in your project root.
Cause: Swift expression parser can't resolve types from the current module.
Fixes:
v instead (no compilation needed)expr -l objc -- ... for ObjC-bridge typesCause: Compiler optimized the variable out.
Fixes:
-Onone for the specific file (Build Settings → per-file compiler flags)register read to check if the value is in a registerCause: LLDB defaults to ObjC in some contexts (especially in frameworks).
Fix:
(lldb) settings set target.language swift
(lldb) expr -l swift -- mySwiftExpression
Cause: The expression you evaluated had a side effect that crashed.
Fix:
v for read-only inspectionCause: Usually compiling a complex expression or resolving types in a large project.
Fix:
v instead of p/po (no compilation)po, Ctrl+C to cancel and use v insteadCauses and fixes:
| Cause | Fix |
|---|---|
| Wrong file/line (code moved) | Re-set breakpoint on current code |
| Breakpoint disabled | breakpoint enable N |
| Code not executed | Verify the code path is reached |
| Optimized out (Release) | Switch to Debug configuration |
| In a framework/SPM package | Set symbolic breakpoint by function name |
WWDC : 2019-429, 2018-412, 2022-110370, 2015-402
Docs : /xcode/stepping-through-code-and-inspecting-variables-to-isolate-bugs, /xcode/setting-breakpoints-to-pause-your-running-app
Skills : axiom-lldb, axiom-xcode-debugging
Weekly Installs
39
Repository
GitHub Stars
590
First Seen
Feb 19, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode37
codex37
gemini-cli36
amp36
github-copilot36
kimi-cli36
二进制初步分析指南:使用ReVa工具快速识别恶意软件与逆向工程
69 周安装
PrivateInvestigator 道德人员查找工具 | 公开数据调查、反向搜索与背景研究
69 周安装
TorchTitan:PyTorch原生分布式大语言模型预训练平台,支持4D并行与H100 GPU加速
69 周安装
screenshot 截图技能:跨平台桌面截图工具,支持macOS/Linux权限管理与多模式捕获
69 周安装
tmux进程管理最佳实践:交互式Shell初始化、会话命名与生命周期管理
69 周安装
Git Rebase Sync:安全同步分支的Git变基工具,解决冲突与备份
69 周安装