介绍
chisel 是 facebook 开源的调试框架,封装了很多方便的 LLDB 命令便于调试 iOS App,今天介绍一下使用心得以及一些常用的命令,希望对你有写帮助。
测试环境:
Xcode 7.3 and iOS 9.3 simulator.
OS:OSX 10.11.4
pviews and presponder doesn’t work and no output.
Chisel issue on Xcode 7.3 #149
作者正在努力修复中…
Xcode7.2 版本没有问题
安装
brew update
brew install chisel
创建 ~/.lldbinit 假如不存在
编辑内容: command script import /usr/local/opt/chisel/libexec/fblldb.py
查看命令
(lldb)help
查看具体怎样使用
(lldb) help border
常用命令说明
| Command | Description |
|---|---|
| pviews | Print the recursive view description for the key window. |
| pvc | Print the recursive view controller description for the key window. |
| visualize | Open a UIImage , CGImageRef , UIView , CALayer , NSData (of an image), UIColor , CIColor , or CGColorRef in Preview.app on your Mac. |
| fv | Find a view in the hierarchy whose class name matches the provided regex. |
| fvc | Find a view controller in the hierarchy whose class name matches the provided regex. |
| show/hide | Show or hide the given view or layer. You don’t even have to continue the process to see the changes! |
| mask/unmask | Overlay a view or layer with a transparent rectangle to visualize where it is. |
| border/unborder | Add a border to a view or layer to visualize where it is. |
| caflush | Flush the render server (equivalent to a “repaint” if no animations are in-flight). |
| bmessage | Set a symbolic breakpoint on the method of a class or the method of an instance without worrying which class in the hierarchy actually implements the method. |
| wivar | Set a watchpoint on an instance variable of an object. |
| presponder | Print the responder chain starting from the given object. |
Tips:直接点控制台上方第三个按钮呼出
LLDB。
pviews(暂不可用)
显示 view 的层级。
border&unborder
border :给view或者layer添加边框颜色和边框的宽度。
使用如下:
(lldb) border 0x7ffc017b2970 -c green -w 10
标示设置 0x7ffc017b2970 视图或者图层一个宽度为 2 的绿色边框。
unborder :去掉view或者layer的边框颜色和边框宽度。
使用如下:
unborder 0x7ffc017b2970
pinternals
这个命令就是打印出来的一个控件( id )类型的内部结构。
使用如下:
pinternals 0x7ffc017b2970
presponder(暂不可用)
打印出一个继承于 UIResponder 控件的消息传递链。
visualize
可以使用 mac 下的预览 app 打开我们的图片 UIImage , CGImageRef 格式的图片,甚至 view 和 layer 的图片。
使用如下:
visualize 0x79ec3140 // 或者变量名,此地址是 id 类型的
pclass
pclass 可以打印出一个对象的继承关系。
使用如下:
pclass 0x7fcd15108800
taplog
这个命令是模拟敲击一下屏幕,并且打印出你敲击屏幕时候事件接收的对象。
hide&show
hide 命令可以直接隐藏一个对象,移除当前遮挡的对象便于你观察后面的对象。show 命令会让它再次显示出来。
bmessage
这个命令就是 LLDB 添加一个断点,譬如 -viewWillAppear: 这个方法,在当前控制器中你没有实现它,但是你又想在调用它的时机触发中断。
这个我就不解释了,需要补充一点的是 Objectiv-c 的方法是带 : 的。
pvc
打印出当前的控制器层级。
wivar
这个命令是加 watchPoint 。
参考链接:
- Chisel 常用命令总结 – 简书
- 与调试器共舞 - LLDB 的华尔兹 – objccn.io
- Dancing in the Debugger — A Waltz with LLDB – objc.io