加入收藏 | 设为首页 | 会员中心 | 我要投稿 东莞站长网 (https://www.0769zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长资讯 > 评论 > 正文

iOS常用调试方法:LLDB命令

发布时间:2019-04-27 01:30:58 所属栏目:评论 来源:360技术
导读:在iOS项目开发过程中,常用到静态分析(Analyze)、断点(BreakPoint)和控制台(Console)进行代码调试。本篇文章介绍Xcode常用调试方法之LLDB命令。 本文来自360奇舞团QiShare团队投稿。 相关阅读: 《iOS 常用调试方法:静态分析》 《iOS 常用调试方法:断点
副标题[/!--empirenews.page--]

在iOS项目开发过程中,常用到静态分析(Analyze)、断点(BreakPoint)和控制台(Console)进行代码调试。本篇文章介绍Xcode常用调试方法之”LLDB命令“。

本文来自360奇舞团QiShare团队投稿。

iOS常用调试方法:LLDB命令

相关阅读:

  • 《iOS 常用调试方法:静态分析》
  • 《iOS 常用调试方法:断点调试》

1.简介

LLDB是新一代高性能调试器。它构建为一组可重用的组件,可以高度利用较大的LLVM项目中的现有库,例如Clang表达式解析器和LLVM反汇编程序。

LLDB是Mac OS X上Xcode的默认调试器,支持在桌面和iOS设备和模拟器上调试C,Objective-C和C ++。

LLDB项目中的所有代码都是在标准LLVM许可证下提供的,这是一种开源的“BSD风格”许可证。

2.帮助

LLDB命令格式如下:

  1. <命令名称> <命令动作> [-可选项 [可选项的值]] [参数1 [参数2...]] 

LLDB命令的各部分由空格分割,如果参数中包含空格,则需要使用双引号括起参数,如果参数中包含双引号或者反斜杠,则需要使用反斜杠进行转义。

LLDB命令有非常多的功能,完全背下来不太容易,也没必要。开发者可以使用help命令查看相关命令的用法,甚至可以查看help命令的用法。

  1. (lldb) help help 
  2.      Show a list of all debugger commands, or give details about a specific 
  3.      command. 
  4.  
  5. Syntax: help [<cmd-name>] 
  6.  
  7. Command Options Usage: 
  8.   help [-ahu] [<cmd-name> [<cmd-name> [...]]] 
  9.  
  10.        -a ( --hide-aliases ) 
  11.             Hide aliases in the command list. 
  12.  
  13.        -h ( --show-hidden-commands ) 
  14.             Include commands prefixed with an underscore. 
  15.  
  16.        -u ( --hide-user-commands ) 
  17.             Hide user-defined commands from the list. 
  18.       
  19.      This command takes options and free-form arguments.  If your arguments 
  20.      resemble option specifiers (i.e., they start with a - or --), you must use 
  21.      ' -- ' between the end of the command options and the beginning of the 
  22.      arguments. 

3. 执行

在LLDB中,执行命令expression是最基础的命令,简写为expr或者e,语法为:expression -- ,它的作用是执行一个表达式,并输出表达式返回的结果。示例如下:

  1. //! 输出count的值 
  2. (lldb) expression count 
  3. (NSUInteger) $0 = 10 
  4.  
  5. //! 执行string的拼接字符串方法 
  6. (lldb) expression [string stringByAppendingString:@"732"] 
  7. (__NSCFString *) $1 = 0x00006000006ac870 @"QiShare732" 
  8.  
  9. //! 修改view的颜色 
  10. (lldb) expression self.view.backgroundColor = [UIColor redColor] 
  11. (UICachedDeviceRGBColor *) $2 = 0x0000600001d74780 
  12. (lldb) expression [CATransaction flush] 
  13. //!< 因为断点会终止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用来调用某个方法。示例如下:

  1. (lldb) expression -- self.view 
  2. (UIView *) $4 = 0x00007f8ca8401690 
  3.  
  4. (lldb) e self.view 
  5. (UIView *) $5 = 0x00007f8ca8401690 
  6.  
  7. (lldb) p self.view 
  8. (UIView *) $6 = 0x00007f8ca8401690 
  9.  
  10. (lldb) po self.view 
  11. <UIView: 0x7f8ca8401690; frame = (0 0; 375 812); autoresize = W+H; layer = <CALayer: 0x6000008a1dc0>> 
  12.  
  13. (lldb) call self.view 
  14. (UIView *) $8 = 0x00007f8ca8401690 

(编辑:东莞站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读