debugging
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseiOS 调试与问题排查
iOS Debugging and Troubleshooting
Crash 类型识别
Crash Type Identification
| 异常类型 | 常见原因 | 排查方向 |
|---|---|---|
| EXC_BAD_ACCESS | 野指针、force unwrap nil、数组越界 | 检查可选值解包、数组边界、多线程访问 |
| EXC_BAD_INSTRUCTION | fatalError、preconditionFailure | 检查 force unwrap、数组越界 |
| SIGABRT | NSException、unrecognized selector | 查看异常信息、检查 ObjC 互操作 |
| Watchdog | 主线程阻塞超时 | 检查主线程同步 I/O、死锁 |
| Exception Type | Common Causes | Troubleshooting Direction |
|---|---|---|
| EXC_BAD_ACCESS | wild pointer, force unwrap nil, array out of bounds | Check optional value unwrapping, array boundaries, multi-thread access |
| EXC_BAD_INSTRUCTION | fatalError, preconditionFailure | Check force unwrap, array out of bounds |
| SIGABRT | NSException, unrecognized selector | Check exception information, inspect ObjC interoperation |
| Watchdog | Main thread blocking timeout | Check main thread synchronous I/O, deadlocks |
Crash 排查流程
Crash Troubleshooting Process
- 看异常类型和信息 → 初步定位方向
- 看崩溃线程调用栈 → 定位具体代码位置
- 看相关上下文 → 联系前后逻辑推断根因
- 提出修复方案 → 给出具体代码修复
- Check exception type and information → Preliminary positioning direction
- Check crash thread call stack → Locate specific code position
- Check relevant context → Infer root cause by connecting preceding and following logic
- 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 letdefault value?? - array out of bounds → Safe subscript
array[safe: index] - Main thread stuck → Move time-consuming operations to or background queue
Task {} - Thread race → Protect with actor or synchronization mechanism
LLDB 调试命令
LLDB Debugging Commands
- 打印对象
po <变量> - 查看当前调用栈
bt - 查看所有线程
bt all - 运行时求值
expr <表达式> - Symbolic Breakpoint: ,
UIViewAlertForUnsatisfiableConstraintsobjc_exception_throw
- Print object
po <variable> - View current call stack
bt - View all threads
bt all - Runtime evaluation
expr <expression> - Symbolic Breakpoint: ,
UIViewAlertForUnsatisfiableConstraintsobjc_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: debuggingRules:
- 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