Chisel is a collection of LLDB commands to assist debugging iOS apps.
Chisel
是python
寫的LLDB
的拓展命令集合。里面的一些命令可以讓你的調(diào)試加速猛遍。
Chisel安裝
brew update
brew install chisel
Chisel常用命令
pviews
打印view層次
也許你想打印某個UIView
的frame或者內(nèi)存地址姐赡,無需再使用Capture View Hierarchy
, 直接使用pviews
命令即刻
pviews [--up] [--depth=depth] <aView>
--up/-u
: 以view為起始位置,向上打印,直到打印到window層
--depth/-d
: 傳入int類型,表示打印的層數(shù),0表示沒有限制
e.g: 打印一下self.view
層級:
(lldb) pviews self.view
<UIView: 0x7fee7ae1fa60; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7fee7ae1d3c0>>
| <UIButton: 0x7fee7ae1dd90; frame = (54 244; 46 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fee7ae1e300>>
| <UIView: 0x7fee7ae1f2e0; frame = (35 312; 240 128); autoresize = RM+BM; layer = <CALayer: 0x7fee7ae1f660>>
| <_UILayoutGuide: 0x7fee7ae1fc20; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7fee7ae20030>>
| <_UILayoutGuide: 0x7fee7ae20b30; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7fee7ae1d100>>
| <UILabel: 0x7fee7ae1d3f0; frame = (0.4 150; 58.25 20.5); text = 'aaa'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fee7ae1bb30>>
fvc
+ VC
類名 = 找ViewController
fv
+ UI控件類名 = 找UIView
alamborder
所有帶有
Ambiguous Layouts
的view立即會被渲染上紅色border
Syntax: alamborder [--color=color] [--width=width]
--color
/-c
: border的顏色翰意,參數(shù)為string類型,比如'red', 'green', 'magenta'等信柿,不設(shè)置默認(rèn)為紅色冀偶。
--width
/-w
: border的寬度,參數(shù)為CGFloat類型渔嚷,不設(shè)置默認(rèn)寬度為2进鸠。
e.g: 假設(shè)我們寫了這么一段代碼,可以明顯看出形病,我們沒有設(shè)置X軸的位置堤如。
UIView *subview = [UIView new];[self.view addSubview:subview];[subview mas_makeConstraints:^(MASConstraintMaker *make) { make.top.offset(100); make.size.equalTo(@100);}];
運(yùn)行代碼之后,在LLDB
控制臺輸入alamborder
(lldb) alamborder
pinvocation
打印方法調(diào)用堆棧窒朋,僅支持x86
語法:Syntax: pinvocation [--all]
--all/-a
: 表示打印所有堆棧,不設(shè)置默認(rèn)只打印當(dāng)前堆棧
說明:與bt命令類似蝗岖,不過信息比bt打印得更詳細(xì)侥猩,遺憾的是只能支持x86
e.g: 打印一下當(dāng)前堆棧
(lldb) pinvocation
frame #0: 0x000962aa TMasonry`-[ViewController viewDidLoad](self=0x7bf2d9c0, _cmd="viewDidLoad") + 234 at ViewController.m:28
NSInvocation: 0x7bf433e0
self: 0x7bf2d9c0
pkp
通過
-valueForKeyPath:
打印key path
對應(yīng)的值。
語法: Syntax: pkp <keypath>
<keypath>: 需要打印的路徑抵赢,如self.view
說明:以前打印屬性一般都用po obj.xxx欺劳,現(xiàn)在我想用pkp obj.xxx是一個更好的選擇了,因?yàn)閜o obj.xxx是調(diào)用getter方法铅鲤,如果沒有g(shù)etter方法就無法打印了划提。pkp obj.xxx不僅會調(diào)用getter方法,沒有g(shù)etter方法還會去查找成員變量
e.g: 打印一下self.view
(lldb) pkp self.view
<UIView: 0x7fd1da52d5d0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7fd1da52d740>>
pivar
presponder
打印響應(yīng)鏈
語法: Syntax: presponder <startResponder>
<startResponder>: UIResponder對象邢享,響應(yīng)鏈開始位置
e.g: 打印一個tableView的響應(yīng)鏈
(lldb) presponder tableView
<UITableView: 0x7fde54810e00; frame = (0 0; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7fde52519ac0>; layer = <CALayer: 0x7fde5253b4c0>; contentOffset: {0, 0}; contentSize: {0, 220}>
| <UIView: 0x7fde5255c710; frame = (0 0; 600 600); autoresize = W+H; layer = <CALayer: 0x7fde5253b300>>
| | <TableViewController: 0x7fde52491310>
taplog
將點(diǎn)擊的
view
打印出來鹏往,這個命令對于查找哪個view
非常有幫助
語法:Syntax: taplog
說明:要查看的view必須能接收點(diǎn)擊事件,也就是他的userInteractionEnabled
必須為YES
才能被找到骇塘,UILabel
和UIImageView
默認(rèn)userInteractionEnabled
為NO伊履。
用法:我們需要先將程序暫停韩容,輸入taplog
,程序會自己運(yùn)行唐瀑,這時候點(diǎn)擊你需要查看的view
群凶,控制臺上就會顯示出你剛剛點(diǎn)擊的view
相關(guān)信息
e.g: 我們先將程序暫停,輸入taplog
(lldb) taplog
Process 28421 resuming
程序會自己運(yùn)行哄辣,我們再點(diǎn)擊一個UIButton:
<UIButton: 0x7fe6785284e0; frame = (54 244; 46 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fe678528a50>>
vs
在
view
層級中搜索view
请梢,并顯示出來
語法:Syntax:vs <view>
<view> :要查找的view
說明:相比fv,vs主要用于顯示view在屏幕上的位置力穗,2個命令可以配合使用.
e.g: 假設(shè)我們要找屏幕上的一個view
, 首先用fv
查找UIView
類型的view
(lldb) fv UIView 0x7fbcf37228d0 UIView 0x7fbcf3725e90 UIView
然后看看這2個view
到底哪個是我們想要找的view
(lldb) vs 0x7fbcf3725e90
Use the following and (q) to quit.
- (w) move to superview
- (s) move to first subview
- (a) move to previous sibling
- (d) move to next sibling
- (p) print the hierarchy
<UIView: 0x7fbcf3725e90; frame = (0 100; 100 100); layer = <CALayer: 0x7fbcf3712a40>>
輸入命令后他會幫我們在屏幕上用粉紅色標(biāo)志出來vs
的view
官方參考命令列表
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 |