debugging

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

iOS 调试与问题排查

iOS Debugging and Troubleshooting

Crash 类型识别

Crash Type Identification

异常类型常见原因排查方向
EXC_BAD_ACCESS野指针、force unwrap nil、数组越界检查可选值解包、数组边界、多线程访问
EXC_BAD_INSTRUCTIONfatalError、preconditionFailure检查 force unwrap、数组越界
SIGABRTNSException、unrecognized selector查看异常信息、检查 ObjC 互操作
Watchdog主线程阻塞超时检查主线程同步 I/O、死锁
Exception TypeCommon CausesTroubleshooting Direction
EXC_BAD_ACCESSwild pointer, force unwrap nil, array out of boundsCheck optional value unwrapping, array boundaries, multi-thread access
EXC_BAD_INSTRUCTIONfatalError, preconditionFailureCheck force unwrap, array out of bounds
SIGABRTNSException, unrecognized selectorCheck exception information, inspect ObjC interoperation
WatchdogMain thread blocking timeoutCheck main thread synchronous I/O, deadlocks

Crash 排查流程

Crash Troubleshooting Process

  1. 看异常类型和信息 → 初步定位方向
  2. 看崩溃线程调用栈 → 定位具体代码位置
  3. 看相关上下文 → 联系前后逻辑推断根因
  4. 提出修复方案 → 给出具体代码修复
  1. Check exception type and information → Preliminary positioning direction
  2. Check crash thread call stack → Locate specific code position
  3. Check relevant context → Infer root cause by connecting preceding and following logic
  4. Propose repair solution → Provide specific code fixes

常见修复模式

Common Repair Patterns

  • force unwrap crash →
    guard let
    /
    if let
    /
    ??
    默认值
  • 数组越界 → 安全下标
    array[safe: index]
  • 主线程卡死 → 耗时操作移到
    Task {}
    或后台队列
  • 线程竞争 → 用 actor 或同步机制保护
  • force unwrap crash →
    guard let
    /
    if let
    /
    ??
    default value
  • array out of bounds → Safe subscript
    array[safe: index]
  • Main thread stuck → Move time-consuming operations to
    Task {}
    or background queue
  • Thread race → Protect with actor or synchronization mechanism

LLDB 调试命令

LLDB Debugging Commands

  • po <变量>
    打印对象
  • bt
    查看当前调用栈
  • bt all
    查看所有线程
  • expr <表达式>
    运行时求值
  • Symbolic Breakpoint:
    UIViewAlertForUnsatisfiableConstraints
    ,
    objc_exception_throw
  • po <variable>
    Print object
  • bt
    View current call stack
  • bt all
    View all threads
  • expr <expression>
    Runtime evaluation
  • Symbolic Breakpoint:
    UIViewAlertForUnsatisfiableConstraints
    ,
    objc_exception_throw

Crash 输出格式

Crash Output Format

🔍 Crash 类型: [类型]
📍 崩溃位置: [文件:方法:行]
💡 根因分析: [分析]
🔧 修复方案: [代码]
🛡️ 防御建议: [如何预防]
🔍 Crash 类型: [类型]
📍 崩溃位置: [文件:方法:行]
💡 根因分析: [分析]
🔧 修复方案: [代码]
🛡️ 防御建议: [如何预防]

专项调试指南

Special Debugging Guides

  • 内存泄漏排查: 参见 references/memory-leak.md — 6 大泄漏模式检查清单、Memory Graph 使用
  • 性能问题诊断: 参见 references/performance-debugging.md — 按症状诊断卡顿/启动慢/内存高
  • Memory leak troubleshooting: See references/memory-leak.md — Checklist for 6 major leak patterns, Memory Graph usage
  • Performance issue diagnosis: See references/performance-debugging.md — Diagnose lag/slow startup/high memory according to symptoms

✅ Sentinel(Skill 使用自检)

✅ Sentinel (Skill Usage Self-check)

当且仅当你确定本 Skill 已被加载并用于当前任务时,在回复末尾追加:
// skill-used: debugging
规则:
  • 只能输出一次
  • 如果不确定是否加载,禁止输出 sentinel
  • 输出 sentinel 代表你已遵守本 Skill 的硬性规则与交付格式
  • 只有当任务与本 skill 的 description 明显匹配时才允许输出 sentinel
Append the following at the end of the reply if and only if you confirm that this Skill has been loaded and used for the current task:
// skill-used: debugging
Rules:
  • Can only be output once
  • If you are not sure whether it is loaded, do not output the sentinel
  • Outputting the sentinel means you have complied with the mandatory rules and delivery format of this Skill
  • It is allowed to output the sentinel only when the task clearly matches the description of this skill