1.安装Chisel
源码地址: Chisel
Chisel 使用 homebrew 来安装,如果你没有安装homebrew, 参考 homebrew。
<pre>
brew updatebrew
install chisel
</pre>
安装完成按照安装日志上的提示,在~/.lldbinit文件中添加一行,没有则新建。 提示类似如下:
<pre>
==> CaveatsAdd the following line to ~/.lldbinit to load chisel when Xcode launches: command script import /usr/local/opt/chisel/libexec/fblldb.py
</pre>
做好上面的步骤,然后重启Xcode就可以尝试下了。
如果安装成功的话,那么你就会看到如下图的这些命令。
这里大概会有30个命令吧,我记得我第一次装的时候没那么多命令的,facebook又更新了很多。其实这些封装的命令,就是使用python封装了一下函数然后调用。凡是这些封装的命令,你都可以通过多个lldb命令打出来,所以如果你会使用python的话,那么你可以根据自己的使用习惯封装一些常用的lldb命令。我使用了也有一段时间的chisel了,但是感觉并不是所有的命令都很常用,而且有写使用的场景也不是很清楚,所以在这里给大家普及一下,如果有谬误,请大家及时指正。(ps:和大家说个快捷键,cmd+k快速清楚console的信息。)
一般我们使用chisel的命令的时候,我们可以通过 help + chisel命令,譬如 help + pvc,得到如何具体使用这个命令,但是有时候你看了help信息也不一定就会用呢。
<pre>
常用命令
pvc 打印所有的viewController 然后搜索state: appeared快速定位当前viewController
pviews 递归打印view的描述,从window开始打印
pinternals 显示一个对象的内部属性 pinternals <object>
pivar 打印一个对象中变量值 pivar <object> <ivarName>
pactions 打印指定继承UIControl控件(比如UIButton)的action方法 pactions <control>
pcells 打印当前层级的tableview的cell信息
pdocspath 显示docoment的路径
pclass 打印一个对象的类集成列表 pclass <object>
fvc 通过正则表达式模糊查找指定的vc fvc [--name=classNameRegex] [--view=view]
fv 通过正则表达式模糊查找指定的view fv <classNameRegex>
wivar观察一个对象变量的变化 wivar <object> <ivarName>
visualize 打开一个UIView,图片或layer
pjson Print JSON representation of NSDictionary or NSArray object
unmask
border
unborder
taplog
show 显示一个view
paltrace 打印所给view的布局
</pre>
<pre>
==============================================================
wivar
Set a watchpoint for an object's instance variable.
Arguments:
<object>; Type: id; Object expression to be evaluated.
<ivarName>; Type: ; Name of the instance variable to watch.
Syntax: wivar <object> <ivarName>
wivar 0x7fcb6b7363d0 _count
使用如下命令删除:watchpoint delete 1
==============================================================
vs
Interactively search for a view by walking the hierarchy.
在该层搜索指定的view, 参数为view的地址
vs 0x7fb22b52f420
Arguments:
<view>; Type: UIView*; The view to border.
Syntax: vs <view>
==============================================================
help visualize
Open a UIImage, CGImageRef, UIView, or CALayer in Preview.app on your Mac.
Arguments:
<target>; Type: (id); The object to visualize.
Syntax: visualize <target>
help unslowanim
Turn off slow animations.
Syntax: unslowanim
==============================================================
help unmask
Remove mask from a view or layer
Arguments:
<viewOrLayer>; Type: UIView/CALayer *; The view/layer to mask.
==============================================================
help unborder
Removes border around <viewOrLayer>.
Arguments:
<viewOrLayer>; Type: UIView/NSView/CALayer *; The view/layer to unborder.
Syntax: unborder <viewOrLayer>
==============================================================
Log tapped view to the console.
Syntax: taplog
==============================================================
help slowanim
Slows down animations. Works on the iOS Simulator and a device.
Arguments:
<speed>; Type: float; Animation speed (default 0.1).
Syntax: slowanim <speed>
==============================================================
help show
Show a view or layer.
Arguments:
<viewOrLayer>; Type: UIView/NSView/CALayer *; The view/layer to show.
Syntax: show <viewOrLayer>
==============================================================
help pviews
Print the recursion description of <aView>. 递归打印描述
从window开始打印
Arguments:
<aView>; Type: UIView/NSView; The view to print the description of.
Options:
--up/-u ; Print only the hierarchy directly above the view, up to its window.
--depth/-d <depth>; Type: int; Print only to a given depth. 0 indicates
infinite depth.
Syntax: pviews [--up] [--depth=depth] <aView>
==============================================================
help ptv
Print the highest table view in the hierarchy.
Syntax: ptv
==============================================================
help pkp
Print out the value of the key path expression using -valueForKeyPath:
Arguments:
<keypath>; Type: NSString *; The keypath to print
Syntax: pkp <keypath>
==============================================================
help pjson
Print JSON representation of NSDictionary or NSArray object
Arguments:
<object>; Type: id; The NSDictionary or NSArray object to print
Options:
--plain/-p ; Plain JSON
Syntax: pjson [--plain] <object>
==============================================================
help pivar
Print the value of an object's named instance variable.
Arguments:
<object>; Type: id; Object expression to be evaluated.
<ivarName>; Type: ; Name of instance variable to print.
Syntax: pivar <object> <ivarName>
==============================================================
help pinternals
Show the internals of an object by dereferencing it as a pointer.
显示一个对象的内部属性
Arguments:
<object>; Type: id; Object expression to be evaluated.
Syntax: pinternals <object>
==============================================================
help pdocspath
Print application's 'Documents' directory path.
Options:
--open/-o ; open in Finder
Syntax: pdocspath [--open]
==============================================================
help pdata
Print the contents of NSData object as string.
Supported encodings:
- ascii,
- utf8,
- utf16, unicode,
- utf16l (Little endian),
- utf16b (Big endian),
- utf32,
- utf32l (Little endian),
- utf32b (Big endian),
- latin1, iso88591 (88591),
- latin2, iso88592 (88592),
- cp1251 (1251),
- cp1252 (1252),
- cp1253 (1253),
- cp1254 (1254),
- cp1250 (1250),
Arguments:
<data>; Type: NSData *; NSData object.
Options:
--encoding/-e <encoding>; Type: string; Used encoding (default utf-8).
Syntax: pdata [--encoding=encoding] <data>
==============================================================
help pcurl
Print the NSURLRequest (HTTP) as curl command.
Arguments:
<request>; Type: NSURLRequest/NSMutableURLRequest; The request to convert
to the curl command.
Options:
--embed-data/-e ; Embed request data as base64.
Syntax: pcurl [--embed-data] <request>
==============================================================
help pclass
Print the inheritance starting from an instance of any class.
Arguments:
<object>; Type: id; The instance to examine.
Syntax: pclass <object>
ViewController
| UIViewController
| | UIResponder
| | | NSObject
==============================================================
help pcells
Print the visible cells of the highest table view in the hierarchy.
Syntax: pcells
==============================================================
help pca
Print layer tree from the perspective of the render server.
Syntax: pca
==============================================================
help panim
Prints if the code is currently execution with a UIView animation block.
Syntax: panim
==============================================================
help paltrace
Print the Auto Layout trace for the given view. Defaults to the key window.
打印所给view的布局
Arguments:
<view>; Type: UIView *; The view to print the Auto Layout trace for.
Syntax: paltrace <view>
==============================================================
help pactions
Print the actions and targets of a control.
打印指定继承UIControl 的action方法
Arguments:
<control>; Type: UIControl *; The control to inspect the actions of.
Syntax: pactions <control>
==============================================================
help mask
Add a transparent rectangle to the window to reveal a possibly obscured or
hidden view or layer's bounds
Arguments:
<viewOrLayer>; Type: UIView/NSView/CALayer *; The view/layer to mask.
Options:
--color/-c <color>; Type: string; A color name such as 'red', 'green',
'magenta', etc.
--alpha/-a <alpha>; Type: CGFloat; Desired alpha of mask.
Syntax: mask [--color=color] [--alpha=alpha] <viewOrLayer>
==============================================================
help hide
Hide a view or layer.
Arguments:
<viewOrLayer>; Type: UIView/NSView/CALayer *; The view/layer to hide.
Syntax: hide <viewOrLayer>
help fvc
Find the view controllers whose class names match classNameRegex and puts the
address of first on the clipboard.
Options:
--name/-n <classNameRegex>; Type: string; The view-controller-class regex to
search the view controller hierarchy for.
--view/-v <view>; Type: UIView; This function will print the View Controller
that owns this view.
Syntax: fvc [--name=classNameRegex] [--view=view]
help fv
Find the views whose class names match classNameRegex and puts the address of
first on the clipboard.
Arguments:
<classNameRegex>; Type: string; The view-class regex to search the view
hierarchy for.
Syntax: fv <classNameRegex>
fv UIButton
==============================================================
help flicker
Quickly show and hide a view to quickly help visualize where it is.
Arguments:
<viewOrLayer>; Type: UIView/NSView*; The view to flicker.
Syntax: flicker <viewOrLayer>
==============================================================
help fa11y
Find the views whose accessibility labels match labelRegex and puts the address
of the first result on the clipboard.
Arguments:
<labelRegex>; Type: string; The accessibility label regex to search the view
hierarchy for.
Syntax: fa11y <labelRegex>
==============================================================
help dcomponents
Set debugging options for components.
Options:
--set/-s ; Set debug mode for components
--unset/-u ; Unset debug mode for components
Syntax: dcomponents [--set] [--unset]
==============================================================
help caflush
Force Core Animation to flush. This will 'repaint' the UI but also may mess
with ongoing animations.
Syntax: caflush
==============================================================
help border
Draws a border around <viewOrLayer>. Color and width can be optionally
provided.
Arguments:
<viewOrLayer>; Type: UIView/NSView/CALayer *; The view/layer to border.
NSViews must be layer-backed.
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] [--width=width] <viewOrLayer>
==============================================================
help bmessage
Set a breakpoint for a selector on a class, even if the class itself doesn't
override that selector. It walks the hierarchy until it finds a class that does
implement the selector and sets a conditional breakpoint there.
Arguments:
<expression>; Type: string; Expression to set a breakpoint on, e.g. "-[MyView
setFrame:]", "+[MyView awesomeClassMethod]" or "-[0xabcd1234 setFrame:]"
Syntax: bmessage <expression>
==============================================================
help binside
Set a breakpoint for a relative address within the framework/library that's
currently running. This does the work of finding the offset for the
framework/library and sliding your address accordingly.
Arguments:
<address>; Type: string; Address within the currently running framework to
set a breakpoint on.
Syntax: binside <address>
==============================================================
help alamunborder
Removes the border around views with an ambiguous layout
Syntax: alamunborder
==============================================================
help alamborder
Put a border around views with an ambiguous layout
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: alamborder [--color=color] [--width=width]
</pre>
LLdb篇2教你使用faceBook的chisel来提高调试效率
Chisel-LLDB命令插件,让调试更Easy
Chisel