副标题[/!--empirenews.page--]
在iOS项目开发过程中,常用到静态分析(Analyze)、断点(BreakPoint)和控制台(Console)进行代码调试。本篇文章介绍Xcode常用调试方法之”LLDB命令“。
本文来自360奇舞团QiShare团队投稿。

相关阅读:
- 《iOS 常用调试方法:静态分析》
- 《iOS 常用调试方法:断点调试》
1.简介
LLDB是新一代高性能调试器。它构建为一组可重用的组件,可以高度利用较大的LLVM项目中的现有库,例如Clang表达式解析器和LLVM反汇编程序。
LLDB是Mac OS X上Xcode的默认调试器,支持在桌面和iOS设备和模拟器上调试C,Objective-C和C ++。
LLDB项目中的所有代码都是在标准LLVM许可证下提供的,这是一种开源的“BSD风格”许可证。
2.帮助
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. 打印
打印命令print是最常用的命令,简写为pri或者p,语法为:print ,它的作用是打印变量或者表达式。通过help print会发现print其实是expression --命令的简写:'print' is an abbreviation for 'expression --',其中--标识选项的结束和参数的开始。
同样常用的expression简写命令还有po和call。其中po表示print object,用来打印对象,call用来调用某个方法。示例如下:
- (lldb) expression -- self.view
- (UIView *) $4 = 0x00007f8ca8401690
-
- (lldb) e self.view
- (UIView *) $5 = 0x00007f8ca8401690
-
- (lldb) p self.view
- (UIView *) $6 = 0x00007f8ca8401690
-
- (lldb) po self.view
- <UIView: 0x7f8ca8401690; frame = (0 0; 375 812); autoresize = W+H; layer = <CALayer: 0x6000008a1dc0>>
-
- (lldb) call self.view
- (UIView *) $8 = 0x00007f8ca8401690
(编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|