iOS常用调试方法:LLDB命令
作者:媒体转发 时间:2019-04-26 09:39
在iOS项目开发过程中,常用到静态分析(Analyze)、断点(BreakPoint)和控制台(Console)进行代码调试。本篇文章介绍Xcode常用调试方法之”LLDB命令“。
本文来自360奇舞团QiShare团队投稿。

相关阅读:
《iOS 常用调试方法:静态分析》
《iOS 常用调试方法:断点调试》
简介
LLDB是新一代高性能调试器。它构建为一组可重用的组件,可以高度利用较大的LLVM项目中的现有库,例如Clang表达式解析器和LLVM反汇编程序。
LLDB是Mac OS X上Xcode的默认调试器,支持在桌面和iOS设备和模拟器上调试C,Objective-C和C ++。
LLDB项目中的所有代码都是在标准LLVM许可证下提供的,这是一种开源的“BSD风格”许可证。
帮助
LLDB命令格式如下:
<命令名称> <命令动作> [-可选项 [可选项的值]] [参数1 [参数2...]]
LLDB命令的各部分由空格分割,如果参数中包含空格,则需要使用双引号括起参数,如果参数中包含双引号或者反斜杠,则需要使用反斜杠进行转义。
LLDB命令有非常多的功能,完全背下来不太容易,也没必要。开发者可以使用help命令查看相关命令的用法,甚至可以查看help命令的用法。
(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.
This command takes options and free-form arguments. If your arguments
resemble option specifiers (i.e., they start with a - or --), you must use
' -- ' between the end of the command options and the beginning of the
arguments.
3. 执行
在LLDB中,执行命令expression是最基础的命令,简写为expr或者e,语法为:expression -- ,它的作用是执行一个表达式,并输出表达式返回的结果。示例如下:

//! 输出count的值
(lldb) expression count
(NSUInteger) $0 = 10
//! 执行string的拼接字符串方法
(lldb) expression [string stringByAppendingString:@"732"]
(__NSCFString *) $1 = 0x00006000006ac870 @"QiShare732"
//! 修改view的颜色
(lldb) expression self.view.backgroundColor = [UIColor redColor]
(UICachedDeviceRGBColor *) $2 = 0x0000600001d74780
(lldb) expression [CATransaction flush]
//!< 因为断点会终止UI线程,执行[CATransaction flush]命令可以渲染出修改后的界面
4. 打印




