Chisel是facebook開源的輔助xcode進(jìn)行iOS開發(fā)調(diào)試的工具跌捆,包含一系列更加有用的lldb命令,而且Chisel還支持添加本地以及自定義命令赵抢。本文從工具介紹開始凤跑,帶大家認(rèn)識并使用這一強(qiáng)大工具。
Chisel 簡介
安裝
直接按照官方文檔進(jìn)行:
- 安裝Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 安裝Chisel
brew update
brew install chisel
-
更新.lldbinit
.lldbinit文件是lldb啟動之前加載的文件氢烘,用于lldb的初始化怀偷,每次lldb啟動都會加載。安裝chisel成功之后播玖,終端會打印如下提示椎工,按照提示,將啟動chisel的命令復(fù)制到.lldbinit文件中蜀踏。
chisel安裝.png
我是通過如下命令直接將上面的命令寫入文件中(>>表示追加到文件尾维蒙,如果你已經(jīng)添加過則無需再次添加)
echo command script import /usr/local/opt/chisel/libexec/fblldb.py >> ~/.lldbinit
-
重啟xcode并check
check方法有兩種,第一種是打開終端依次輸入:llbd<enter>,help<enter>果覆;第二種方法是打開xcode木西,打斷點(diǎn)并執(zhí)行到斷點(diǎn)處,輸入help命令随静。滾動help的結(jié)果八千,當(dāng)找到Current user-defined commands:一行吗讶,即表示安裝成功。
chisel安裝check.png
Chisel常用命令簡介
pmethods
print the class and instance methods of a class.pclass
Print the inheritance starting from an instance of any class.poobjc
Print the expression result, with the expression run in an ObjC++ context. (Shortcut for "expression -O -l ObjC++ -- " ).pviews
Print the recursion description of <aView>.pcells
Print the visible cells of the highest table view in the hierarchy.pblock
Print the block`s implementation address and signature.mask
Add a transparent rectangle to the window to reveal a possibly obscured or hidden view or layer's boundsborder
Draws a border around <viewOrLayer>. Color and width can be optionally provided. Additionally depth can be provided in order to recursively border subviews.show
Show a view or layer.
添加本地及自定義命令
參考官方文檔恋捆,這里整理出基本步驟如下:
- 開發(fā)命令腳本
官方文檔提供了一個example(源碼貼在下面方便大家閱讀) - 更新.lldbinit
同Chisel安裝完成后的步驟一樣照皆,需要將初始化的命令同步到.lldbinit文件中。 - check命令
同check Chisel是否安裝成功的方法一樣沸停。
#!/usr/bin/python
# Example file with custom commands, located at /magical/commands/example.py
import lldb
import fblldbbase as fb
def lldbcommands():
return [ PrintKeyWindowLevel() ]
class PrintKeyWindowLevel(fb.FBCommand):
def name(self):
return 'pkeywinlevel'
def description(self):
return 'An incredibly contrived command that prints the window level of the key window.'
def run(self, arguments, options):
# It's a good habit to explicitly cast the type of all return
# values and arguments. LLDB can't always find them on its own.
lldb.debugger.HandleCommand('p (CGFloat)[(id)[(id)[UIApplication sharedApplication] keyWindow] windowLevel]')
最后膜毁,Enjoy yourself!