Chisel是facebook開源的輔助xcode進行iOS開發(fā)調試的工具,包含一系列更加有用的lldb命令,而且Chisel還支持添加本地以及自定義命令。本文從工具介紹開始,帶大家認識并使用這一強大工具。
Chisel 簡介
安裝
直接按照官方文檔進行:
- 安裝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的命令復制到.lldbinit文件中。
chisel安裝.png
我是通過如下命令直接將上面的命令寫入文件中(>>表示追加到文件尾,如果你已經添加過則無需再次添加)
echo command script import /usr/local/opt/chisel/libexec/fblldb.py >> ~/.lldbinit
-
重啟xcode并check
check方法有兩種,第一種是打開終端依次輸入:llbd<enter>,help<enter>;第二種方法是打開xcode,打斷點并執(zhí)行到斷點處,輸入help命令。滾動help的結果,當找到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!

