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

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就可以尝试下了。

如果安装成功的话,那么你就会看到如下图的这些命令。


img

这里大概会有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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,324评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,303评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,192评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,555评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,569评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,566评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,927评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,583评论 0 257
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,827评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,590评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,669评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,365评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,941评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,928评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,159评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,880评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,399评论 2 342

推荐阅读更多精彩内容