Chisel简单命令
border :
为某个视图加上边框,其中在Debug View Hierarchy 中的视图上无法显示,但在模拟器中是可以显示出来。
//给视图添加一个红色宽度为2的边框
border -c red -w 2 0x7facfad795c0
//取消边框
unborder 0x7facfad795c0
pviews:
这个命令可以递归打印所有的view,并能标示层级,相当于 UIView 的私有辅助方法 [view recursiveDescription] 。 善用使用这个功能会让你在调试定位问题时省去很多麻烦。
使用示例:
(lldb) pviews
; layer = >
| >
| | >
| | | >
| | | | ; layer = >
| | | | | >
| | | | | | >
| | | | | | | >
| | | | | | | | ; layer = ; contentOffset: {0, 0}; contentSize: {2070, 0}>
| | | | | | | | | ; layer = ; contentOffset: {0, -99}; contentSize: {414, 8762.2984924316406}>
| | | | | | | | | | >
| | | | | | | | | | |
pvc:
这个命令也是递归打印层级,但是不是view,而是viewController。利用它我们可以对viewController的结构一目了然。 其实苹果在IOS8也默默的添加了 UIViewController 的一个私有辅助方法 [UIViewController _printHierarchy] 同样的效果。
预览效果:
(lldb) pvc
, state: appeared, view:
| , state: appeared, view:
| | , state: appeared, view:
| | | , state: appeared, view:
| | | , state: disappeared, view: (view not loaded)
| | | , state: disappeared, view: (view not loaded)
| | | , state: disappeared, view: (view not loaded)
| | | , state: disappeared, view: (view not loaded)
| , state: disappeared, view: not in the window
| | , state: disappeared, view: (view not loaded)
| , state: disappeared, view: not in the window
| | , state: disappeared, view: (view not loaded)
| , state: disappeared, view: not in the window
| | , state: disappeared, view: (view not loaded)
paltrace:
打印某个View的autolayout详细信息,相当于调用_autolayoutTrace
paltrace
: 需要打印详细信息的view,不传参数默认为keyWindow
查看一下keyWindow上有哪个view存在Ambiguous Layouts
(lldb) paltrace
•UIWindow:0x7ff450d2fb50 - AMBIGUOUS LAYOUT
| •UIView:0x7ff450e14430
| | *_UILayoutGuide:0x7ff450d30e90
| | *_UILayoutGuide:0x7ff450d31230
| | *UIView:0x7ff450d32870- AMBIGUOUS LAYOUT for UIView:0x7ff450d32870.minX{id: 46}
Legend:
* - is laid out with auto layout
+ - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
• - layout engine host
我们可以看到,UIView:0x7ff450d32870
存在Ambiguous Layouts
,原因是缺少minX
。也就是没有设置X轴的位置
visualize:
它可以让你使用Mac的预览打开一个 UIImage, CGImageRef, UIView, 或 CALayer。 这个功能或许可以帮我们用来截图、用来定位一个view的具体内容。 但是在我试用了一下,发现暂时还是只能在模拟器时使用,真机还不行。
使用方式:
(lldb) visualize imageView
//或者接ImageView的视图地址
(lldb) visualize 0x7facfad795c0
presponder:
打印某个视图的响应链,会打印从application一直到当前view的响应链,可以看出看出当前view为什么没有响应,以及当前view的层级关系
Syntax: presponder
: UIResponder对象,响应链开始位置
使用方式:
(lldb) presponder 0x7facfad795c0
>
| >
| | >
| | | ; layer = >
| | | | >
| | | | | ; layer = ; contentOffset: {0, 0}; contentSize: {414, 637}>
| | | | | | ; layer = ; contentOffset: {0, -99}; contentSize: {414, 8762.2984924316406}>
| | | | | | |
| | | | | | | | ; layer = ; contentOffset: {0, 0}; contentSize: {2070, 0}>
| | | | | | | | | >
| | | | | | | | | |
| | | | | | | | | | |
caflush:
刷新UI界面。一般我们用LLDB命令改变UI,UI并不会立即更新,我们需要使用caflush刷新界面
caflush
//我们用命令将label的背景色改为红色
(lldb) fv uilabel
0x7fb3919189d0 UILabel
(lldb) e [((UILabel*)0x7fb3919189d0) setBackgroundColor:[UIColor redColor]]
(lldb) caflush
taplog:
在模拟器上点击 会打印你所触摸的view的相关信息。
说明:要查看的view必须能接收点击事件,也就是他的userInteractionEnabled必须为YES才能被找到,UILabel和UIImageView默认userInteractionEnabled为NO。
(lldb) taplog
Process 18014 resuming
>
pclass:
可以打印当前类的继承关系
(lldb) pclass 0x7facfad66390
HJTopicVideoView
| UIView
| | UIResponder
| | | NSObject
show:
显示一个view或者layer,相当于执行view.hidden = NO
(lldb) show 0x7facfad66390
hide:
隐藏一个view或者layer,相当于执行view.hidden = YES
(lldb) hide 0x7facfad66390
slowanim
减慢动画的速度
Syntax: slowanim
: 动画的速度,速度越大,动画越快。1表示原始速度。不传参数默认为0.1
// 原始动画我们设置为1s
[UIView animateWithDuration:1 animations:^{
self.subView.frame = frame;
}];
暂停程序,将动画放慢5倍
(lldb) slowanim 0.2
pinternals:
可以看到某个视图的相关的详细信息,包括视图的继承关系 和一些自定义的相关信息。
(lldb) pinternals 0x7facfad66390
(HJTopicVideoView) $389 = {
UIView = {
UIResponder = {
NSObject = {
isa = HJTopicVideoView
}
_hasOverrideClient = false
_hasOverrideHost = false
_hasInputAssistantItem = false
}
_constraintsExceptingSubviewAutoresizingConstraints = 0x000060000045b6f0 @"13 elements"
_cachedTraitCollection = 0x00006080000d2130
_layer = 0x00006000004348a0
_layerRetained = nil
_gestureInfo = nil
_gestureRecognizers = nil
_window = 0x00007facfae0c9a0
_subviewCache = 0x000060000045b570 @"5 elements"
_templateLayoutView = nil
_charge = 0
_tag = 0
_viewDelegate = nil
_backgroundColorSystemColorName = nil
_countOfMotionEffectsInSubtree = 0
_countOfTraitChangeRespondersInDirectSubtree = 6
_cachedScreenScale = 3
_layoutSubviewsCount = 0
_retainCount = 12
_tintAdjustmentDimmingCount = 0
_shouldArchiveUIAppearanceTags = false
_wantsDeepColorDrawing = true
_interactionTintColor = nil
_layoutMarginsGuide = nil
_minXVariable = 0x0000600000438c60
_minYVariable = 0x0000600000438ba0
_boundsWidthVariable = 0x0000600000438ce0
_boundsHeightVariable = 0x0000600000438ec0
_layoutEngine = 0x000060000019d4d0
_layoutDebuggingIdentifier = nil
_stashedLayoutVariableObservations = 0x00007facfad6aa80
_internalConstraints = 0x00006000006475f0 @"4 elements"
_continuousCornerRadius = 0
_countOfFocusedAncestorTrackingViewsInSubtree = 0
_semanticContentAttribute = 0
_contentSizeNotificationToken = nil
_readableContentGuide = nil
__preferedContentsFormat = 0
_previewingSegueTemplateStorage = nil
__presentationControllerToNotifyOnLayoutSubviews = nil
}
_topic = 0x000060800019ad00
_playCount = 0x00007facfad66b20
_timeLabel = 0x00007facfad66db0
_bgmView = 0x00007facfad66940
}
bmessage:
根据方法名设置断点
Syntax: bmessage
: 设置断点的方法名,如: -[MyView
setFrame:], +[MyView awesomeClassMethod], -[0xabcd1234 setFrame:]等
说明:一般设置断点,如果这个方法本类没有实现,是父类实现的,断点是无效的。bmessage有效避免了这种缺陷,即使本类没有实现,也能设置上断点
//给self中的btnAction:方法设置一个断点
(lldb) bmessage -[self btnAction:]
Setting a breakpoint at -[ViewController btnAction:] with condition (void*)(id)$rdi == 0x00007ff2485311e0
Breakpoint 4: where = TLLDB`-[ViewController btnAction:] at ViewController.m:42, address = 0x000000010c4bb620
pinvocation:
打印方法调用堆栈,仅支持x86
pinvocation [--all]
--all/-a: 表示打印所有堆栈,不设置默认只打印当前堆栈
说明:与bt命令类似,不过信息比bt打印得更详细,遗憾的是只能支持x86
//打印一下当前堆栈
(lldb) pinvocation
frame #0: 0x000962aa TMasonry`-[ViewController viewDidLoad](self=0x7bf2d9c0, _cmd="viewDidLoad") + 234 at ViewController.m:28
NSInvocation: 0x7bf433e0
self: 0x7bf2d9c0
//打印所有堆栈:
(lldb) pinvocation -a
frame #0: 0x000962aa TMasonry`-[ViewController viewDidLoad](self=0x7bf2d9c0, _cmd="viewDidLoad") + 234 at ViewController.m:28
NSInvocation: 0x7d2bb050
self: 0x7bf2d9c0
---------------------------------
frame #1: 0x008062ae UIKit`-[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
NSInvocation: 0x7be18a50
self: 0x7bf2d9c0
---------------------------------
frame #2: 0x0080adce UIKit`-[UIViewController loadViewIfRequired] + 1384
NSInvocation: 0x7bf0cc40
self: 0x7bf2d9c0
---------------------------------
frame #3: 0x008569f9 UIKit`-[UINavigationController _layoutViewController:] + 52
NSInvocation: 0x7d340c90
self: 0x7c89ee00
Argument:
0xbff69108, address of @} 0x7bf2d9c0
---------------------------------
frame #4: 0x008572b1 UIKit`-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 421
NSInvocation: 0x7d340cc0
self: 0x7c89ee00
2 Arguments:
0xbff69158, address of @} 0x0
0xbff6915c, address of @} 0x7bf2d9c0
---------------------------------
frame #5: 0x00857458 UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 145
NSInvocation: 0x7bf24870
self: 0x7c89ee00
3 Arguments:
0xbff69298, address of i} 0
0xbff6929c, address of @} 0x0
0xbff692a0, address of @} 0x7bf2d9c0
---------------------------------
frame #6: 0x00858854 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 1038
NSInvocation: 0x7bf16b50
self: 0x7c89ee00
Argument:
0xbff692f8, address of @} 0x0
---------------------------------
frame #7: 0x00859ada UIKit`-[UINavigationController __viewWillLayoutSubviews] + 68
NSInvocation: 0x7be18930
self: 0x7c89ee00
---------------------------------
frame #8: 0x00a35c4a UIKit`-[UILayoutContainerView layoutSubviews] + 252
NSInvocation: 0x7bf26ab0
self: 0x7bf40d40
---------------------------------
frame #9: 0x0070b008 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 810
NSInvocation: 0x7bf25da0
self: 0x7bf40d40
Argument:
0xbff693b8, address of @} 0x7bf40f80
---------------------------------
frame #10: 0x01b23059 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
NSInvocation: 0x7d2bb6c0
self: 0x7bf40d40
2 Arguments:
0xbff693d8, address of :} layoutSublayersOfLayer:
0xbff693dc, address of @} 0x7bf40f80
---------------------------------
frame #11: 0x0496b80a QuartzCore`-[CALayer layoutSublayers] + 144
NSInvocation: 0x7bf134c0
self: 0x7bf40f80
---------------------------------
frame #12: 0x0495f4ee QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 388
---------------------------------
frame #13: 0x0495f352 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26
---------------------------------
frame #14: 0x04951e8b QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 317
---------------------------------
frame #15: 0x04985e03 QuartzCore`CA::Transaction::commit() + 561
---------------------------------
frame #16: 0x049866c4 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
---------------------------------
frame #17: 0x01f66ffe CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
---------------------------------
frame #18: 0x01f66f5e CoreFoundation`__CFRunLoopDoObservers + 398
---------------------------------
frame #19: 0x01f5c108 CoreFoundation`CFRunLoopRunSpecific + 504
---------------------------------
frame #20: 0x01f5befb CoreFoundation`CFRunLoopRunInMode + 123
---------------------------------
frame #21: 0x00639206 UIKit`-[UIApplication _run] + 540
NSInvocation: 0x7d21fc00
self: 0x7d30bfe0
---------------------------------
frame #22: 0x0063ebfa UIKit`UIApplicationMain + 160
---------------------------------
frame #23: 0x00096a0a TMasonry`main(argc=1, argv=0xbff6a898) + 138 at main.m:14
---------------------------------
frame #24: 0x031caa21 libdyld.dylib`start + 1
---------------------------------
fa11y:
根据view的accessibilityLabel查找view
fa11y
: 需要匹配的text
说明:UILabel,UIButton的accessibilityLabel等于title
// 我们根据显示的文案,查找相应的控件
(lldb) fa11y 妈妈
(UILabel 0x176b5bd0) 妈妈叫你回家吃饭了
pa11y:
打印view层级中所有的accessibilityLabel
pa11y
: 需要打印层级的View,UIView类型
我们打印一下self.view层级中所有的accessibilityLabel
(lldb) pa11y self.view
UIView self.view
| (UIButton 0x176b4600) Button
| (UILabel 0x176b5bd0) 妈妈叫你回家吃饭了
mask:
给view添加一个半透明的矩形mask,用来查看view的位置
Syntax: mask [--color=color] [--alpha=alpha]
--color/-c: mask的颜色,string类型,比如:'red', 'green','magenta'等,不设置默认为红色
--alpha/-a: mask的透明度,不设置默认为0.5
: 需要添加mask的view或者layer
假如label是隐藏的,我们给他添加一个mask,看看他的位置在哪儿
(lldb) fv uilabel
0x7fe713901f10 UILabel
(lldb) mask 0x7fe713901f10
unmask:
将添加的mask去掉
Syntax: unmask
: 需要去掉mask的view或者layer
我们将刚刚添加的mask去掉
(lldb) unmask 0x7fe713901f10
使用命令之后,我们可以看到什么都没有了,因为label是hidden的
fvc:
根据viewController的Class名字查找VC
fvc [--name=classNameRegex] [--view=view]
--name/-n: string类型参数,根据viewController的Class名字查找viewController
--view/-v: UIView类型参数,根据viewController拥有的view查找viewController
说明:上面2个option不能同时使用,只能使用某一个
//我们先根据名字查找一下VC
(lldb) fvc --name=viewcontroller
0x7fd01a90f310 ViewController
//如果我们知道VC的view地址,也可以根据view来查找VC
(lldb) fvc --view=0x7fd0194194d0
Found the owning view controller.
fv:
根据view的class名字查找view
Syntax: fv
: view的class名称
//查找一下屏幕上的UILabel
(lldb) fv uilabel
0x7fd01a91dc10 UILabel
vs:
在view层级中搜索view,并显示出来
Syntax: vs
:要查找的view
说明:相比fv,vs主要用于显示view在屏幕上的位置,2个命令可以配合使用
假设我们要找屏幕上的一个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
>
输入命令后他会帮我们在屏幕上用粉红色标志出来vs
的view
flicker:
将view闪烁一下,以便于查找view的位置
flicker
需要闪烁的view或者layer
我们来看看self.subView的位置
(lldb) flicker self.subView
pkp:
通过-valueForKeyPath:打印key path对应的值。
pkp
: 需要打印的路径,如self.view
说明:以前打印属性一般都用po obj.xxx,现在我想用pkp obj.xxx是一个更好的选择了,因为po obj.xxx是调用getter方法,如果没有getter方法就无法打印了。pkp obj.xxx不仅会调用getter方法,没有getter方法还会去查找成员变量
//打印一下self.view
(lldb) pkp self.view
>
ptv:
打印屏幕中显示的tableView,主要是与pcells联合使用。如果有多个tableView,打印View层级中最上面的一个
ptv
看看当前最上面是哪个tableView
(lldb) ptv
; layer = ; contentOffset: {0, -64}; contentSize: {414, 176}>
pcells:
打印tableView中当前可见的cell,如果有多个tableView,打印View层级中最上面的tableView的可见cell
pcells
看看当前可见的cell有哪些
(lldb) pcells
<__NSArrayI 0x7fde52565a00>(
>,
>,
>,
>
)