文章目录
  1. 1. 调试
    1. 1.1. pviews
    2. 1.2. pinternals
    3. 1.3. presponder
    4. 1.4. pclass
    5. 1.5. taplog
  2. 2. UI操作
    1. 2.1. visualize
    2. 2.2. view操作
  3. 3. 参考

Chisel是facebook开源的一个lldb调试插件,他提供的一些命令可以让调试更加方便。按照chisel-github中的介绍,使用brew可以很方便的安装,这篇blog主要介绍常用的命令和使用举例

调试

pviews

使用pviews我们可以看到view的层级。

1
2
3
4
5
6
(lldb) pviews cell
<BUTitleTableCell: 0x7f9402698140; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0x7f94026988b0>>
| <UITableViewCellContentView: 0x7f9402698d00; frame = (0 0; 320 44); gestureRecognizers = <NSArray: 0x7f9402699810>; layer = <CALayer: 0x7f9402698f90>>
| | <UIImageView: 0x7f9402699920; frame = (0 0; 0 0); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7f9402699ad0>>
| | <YYLabel: 0x7f940253f1b0; frame = (0 0; 0 0); text = 'iOS应用架构(1)-开篇
架构设计需要考虑的问题...'; opaque = NO; layer = <YYAsyncLayer: 0x7f9402544bc0>>

pinternals

这个命令可以打印出来的一个控件(id)类型的内部结构,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
(lldb) pinternals cell
(BUTitleTableCell) $9 = {
UITableViewCell = {
UIView = {
UIResponder = {
NSObject = {
isa = BUTitleTableCell
}
}
}
}
_bu_imageView = 0x00007f9402699920
_bu_Label = 0x00007f940253f1b0
}

presponder

打印出一个UIResponder控件的消息传递链

1
2
3
4
5
6
7
8
9
(lldb) presponder self.navigationController
<UINavigationController: 0x7f9404026600>
| <UIViewControllerWrapperView: 0x7f94025544d0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f94024309e0>>
| | <UITransitionView: 0x7f9402424e20; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x7f9402425260>>
| | | <UILayoutContainerView: 0x7f940254acb0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f9402507f90>>
| | | | <PBTabBarViewController: 0x7f940261e160>
| | | | | <UIWindow: 0x7f9402544600; frame = (0 0; 375 667); tintColor = UIDeviceRGBColorSpace 0.337 0.57 0.731 1; gestureRecognizers = <NSArray: 0x7f940253b0d0>; layer = <UIWindowLayer: 0x7f9402546570>>
| | | | | | <UIApplication: 0x7f9402409c90>
| | | | | | | <AppDelegate: 0x7f940260bf90>

pclass

pclass可以打印出一个对象的继承关系。

1
2
3
4
5
6
7
(lldb) pclass 0x7f94039177d0

UIView

   | UIResponder

   |    | NSObject

taplog

这个命令是模拟敲击一下屏幕,并且打印出你敲击屏幕时候事件接收的对象。

1
2
3
4
5
6
7
//首先点击控制台暂停

(lldb) taplog
//回车
Process 7406 resuming
//点击手机屏幕,就会打印出触摸事件的接收对象
<UITabBarButton: 0x7f940254e690; frame = (252 1; 121 48); opaque = NO; layer = <CALayer: 0x7f940254e0c0>>

先介绍这些以后用到了在补充

UI操作

使用chisel我们可以在调试状态对界面进行一些操作并预览

visualize

可以使用mac下的预览app打开我们的图片UIImage, CGImageRef格式的图片,甚至view和layer的图片 。

1
2
3
4
5
6
7
8
9
(lldb) po cell.bu_imageView.image
<UIImage: 0x7f940269aa50>, {64, 64}

(lldb) visualize 0x7f940269aa50
(lldb) visualize 0x7f940269aa50
(lldb) po self.view
<UIView: 0x7f94039177d0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f9403917e50>>

(lldb) visualize 0x7f94039177d0

view操作

当点击控制台暂停按钮进入调试模式,我们可以使用下面命令对view进行操作

  • fv 可以打印出某一个view类的所有对象
  • fvc 可以打印出某一个viewcontroller类的所有对象
  • show/hide 显示/隐藏某个view或layer
  • border/unborder 为一个view或layer添加/移除一个外框
1
2
3
4
5
6
7
8
9
10
11
12
13
14
(lldb) fv UIImageView
0x7fc37aa3fee0 UIImageView
0x7fc37a8bb9c0 UIImageView
0x7fc3794a1180 UIImageView
0x7fc3794b2190 UIImageView
0x7fc37957af90 UIImageView
0x7fc37aa1e470 UIImageView
0x7fc379556870 UIImageView
(lldb) border 0x7fc379556870
(lldb) unborder 0x7fc379556870
(lldb) visualize 0x7fc3794a1180
(lldb) visualize 0x7fc37aa3fee0
(lldb) border 0x7fc37aa3fee0
(lldb) unborder 0x7fc37aa3fee0

参考

ReadMe-chisel

Chisel-LLDB命令插件,让调试更Easy