使用场景之一,接收他人的项目,快速理清其层次结构,可以打标识符断点,如下图
每一个VC,都加了个在viewDidLoad方法处的断点,这样运行程序时,逐步断点,便可以理清层次,
但是,需要手动不断的继续,依旧不是很好
如果使用LLDB,就事半功倍~
先上效果图
LIDB简史
Xcode5之前的调试器使用的是GDB,如果你不幸使用,那感觉简直了~然后伴随着Xcode5的发布,LLDB调试器取而代之,成为Xcode工程中默认的调试器,它和LVVM编译器一起,带给开发者丰富的流程控制和数据检测的调试功能.LLDB为Xcode提供了底层调试环境,其中,包括内嵌在Xcode IDE中的调试区域的控制面板,在这里我们可以直接调用LLDB命令.
chisel facebook团队良心出品的LLDB扩展
chisel 安装(需已有Homebrew,其安装很易,如若困惑可私信,这里不展开说明)
brew update
brew install chisel
安装结束后会打印出路径如 /usr/local/opt/chisel/libexec/fblldb.py
添加下述命令行到 ~/.lldbinit file
vi ~/.lldbinit
...
command script import /path/to/fblldb.py
_注意:_要将将上述/path/to/fblldb.py
,路径替换为安装成功后的打印出路径如:/usr/local/opt/chisel/libexec/fblldb.py
特别的如果不存在~/.lldbinit file.
可以使用touch
~/.lldbinit
来创建它.
然后,需要重启Xcode,方能使之生效.
LLDB常见命令
Command |
Description |
iOS |
OS X |
pviews |
Print the recursive view description for the key window. |
Yes |
Yes |
pvc |
Print the recursive view controller description for the key window. |
Yes |
No |
visualize |
Open a UIImage , CGImageRef , UIView , CALayer , NSData (of an image), UIColor , CIColor , or CGColorRef in Preview.app on your Mac. |
Yes |
No |
fv |
Find a view in the hierarchy whose class name matches the provided regex. |
Yes |
No |
fvc |
Find a view controller in the hierarchy whose class name matches the provided regex. |
Yes |
No |
show/hide |
Show or hide the given view or layer. You don't even have to continue the process to see the changes! |
Yes |
Yes |
mask/unmask |
Overlay a view or layer with a transparent rectangle to visualize where it is. |
Yes |
No |
border/unborder |
Add a border to a view or layer to visualize where it is. |
Yes |
Yes |
caflush |
Flush the render server (equivalent to a "repaint" if no animations are in-flight). |
Yes |
Yes |
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. |
Yes |
Yes |
wivar |
Set a watchpoint on an instance variable of an object. |
Yes |
Yes |
presponder |
Print the responder chain starting from the given object. |
Yes |
Yes |
... |
... and many more! |
|
|
pviews
该命令是最常用的命令,主要是用来查看布局中view的层级关系的。
图中command+R运行程序后,点击暂停按钮,就可进入lldb控制台,输入pivews命令查看当前布局中view的层级关系。
border/unborder
这两个命令分别是给要查看的view添加边框和移除边框,可以在lldb下输入help border查看具体的用法,如果我要给第二个view添加一个颜色为蓝色,宽度为2的边框,之后再用unborder命令移除,操作如下:
通过help border命令知道border的使用格式如下:
Options:
--color/-c <color>; Type: string; A color name such as 'red', 'green',
'magenta', etc.
--width/-w <width>; Type: CGFloat; Desired width of border.
Syntax: border [--color=color] [--kw" ><
viewOrLayer>以上是Chisel最常用的一些命令.当然这个不是全部,算是抛砖引玉.欢迎一起交流.