LLDB 调试器集成于 Xcode 内部并支持 C++ ,Python插件,这里解释了其工作原理。常用命令包括print
、expression
、call
、po
(print object)等,👇介绍Facebook推出的基于Python适用于界面调试的LLDB插件"Chisel"
1 安装
1.1 brew update
需要先安装Homebrew
brew update
1.2 brew isntall chisel
brew install chisel
1.3 初始化load chisel
安装完成后terminal中会出现如下提示
==> Caveats
Add the following line to ~/.lldbinit to load chisel when Xcode launches:
command script import /usr/local/opt/chisel/libexec/fblldb.py
在当前用户根目录下创建".lldbinit"文本,复制上文中目录地址到文本中保存,重启XCode,Done~
2 常用命令
2.1 pvc
递归打印出viewController的层级。利用它我们可以对viewController的结构一目了然。该效果同UIViewController _printHierarchy
<TabBarController: 0x13772fd0; view = <UILayoutContainerView; 0x151b3a30>; frame = (0, 0; 414, 736)>
| <UINavigationController: 0x1602b800; view = <UILayoutContainerView; 0x1b00aca0>; frame = (0, 0; 414, 736)>
| | <FirstViewController: 0x16029c00; view = <UIView; 0x1b01e1c0>; frame = (0, 0; 414, 736)>
| <UINavigationController: 0x138c5200; view = <UILayoutContainerView; 0x1316a080>; frame = (0, 0; 414, 736)>
| | <SecondViewController: 0x16030400; view = <UIView; 0x2094b370>; frame = (0, 0; 414, 736)>
2.2 pviews
递归打印所有的view,并能标示层级,相当于 UIView 的私有辅助方法 [view recursiveDescription]
<TestView: 0x18df8070; baseClass = UIControl; frame = (144 9; 126 167); layer = <CALayer: 0x18df8150>>
| <UIView: 0x18df81d0; frame = (0 0; 126 126); userInteractionEnabled = NO; layer = <CALayer: 0x18df8240>>
| <UIImageView: 0x18df8330; frame = (0 0; 126 126); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x18df83b0>>
| <UILabel: 0x18df8460; frame = (0 135; 126 14); text = 'haha'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x18df7fb0>>
| | <_UILabelContentLayer: 0x131a3d50> (layer)
注:也可以通过XCode的Debug View Hierarchy查看视图层级
2.3 visualize
它可以使用Mac的预览打开一个 UIImage, CGImageRef, UIView, 或 CALayer。 非常好玩的截图功能,支持真机及模拟器
2.4 fv & fvc
这两个命令是用来通过类名搜索当前内存中存在的view和viewController实例并展示其地址,支持正则搜索。
(lldb) fv UIImageView
0x10643bdf0 UIImageView
0x106412200 UIImageView
0x10667fbe0 UIImageView
2.5 mask/unmask border/unborder
通过2.4的命令地址标识一个view或layer的位置
2.6 bmessage
设置断点,当想在viewWillAppear
设置断点但当前类有没有实现该方法时,利用这个命令就可以达到效果(实际是在父类中打断点)
2.7 caflush
刷新UI,调试时改变UI,无需rebuild,使用caflush刷新UI即可
2.8 pclass
打印对象集成链
2.9 presponder
打印响应链
2.10 自定义Commands
参考文献:
Chisel-LLDB命令插件,让调试更Easy