iOS調試——Chisel

Chisel是facebook開源的輔助xcode進行iOS開發(fā)調試的工具,包含一系列更加有用的lldb命令,而且Chisel還支持添加本地以及自定義命令。本文從工具介紹開始,帶大家認識并使用這一強大工具。

Chisel 簡介

github地址

安裝

直接按照官方文檔進行:

  1. 安裝Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. 安裝Chisel
brew update
brew install chisel
  1. 更新.lldbinit
    .lldbinit文件是lldb啟動之前加載的文件,用于lldb的初始化,每次lldb啟動都會加載。安裝chisel成功之后,終端會打印如下提示,按照提示,將啟動chisel的命令復制到.lldbinit文件中。


    chisel安裝.png

    我是通過如下命令直接將上面的命令寫入文件中(>>表示追加到文件尾,如果你已經添加過則無需再次添加)

echo command script import /usr/local/opt/chisel/libexec/fblldb.py >> ~/.lldbinit
  1. 重啟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 bounds

  • border
    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.

添加本地及自定義命令

參考官方文檔,這里整理出基本步驟如下:

  1. 開發(fā)命令腳本
    官方文檔提供了一個example(源碼貼在下面方便大家閱讀)
  2. 更新.lldbinit
    同Chisel安裝完成后的步驟一樣,需要將初始化的命令同步到.lldbinit文件中。
  3. 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!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • [轉]淺談LLDB調試器文章來源于:http://www.cocoachina.com/ios/20150126/...
    loveobjc閱讀 2,728評論 2 6
  • Chisel 調試工具,Facebook開源的一款lldb調試工具-->GitHub 安裝Chisel 1.安裝h...
    黃二瓜閱讀 530評論 1 1
  • 馬上就要國慶了,提前祝大家國慶快樂??! 前兩天在gitHub上面發(fā)現了一個調試的三方框架,Chisel,由face...
    小明的知識庫閱讀 1,104評論 0 51
  • LLDB的Xcode默認的調試器,它與LLVM編譯器一起,帶給我們更豐富的流程控制和數據檢測的調試功能。平時用Xc...
    CoderSC閱讀 1,500評論 0 2
  • 1.順便問一下,你們互相認識嗎? ????? ?? ?? ?????? 2. 我很愿意為你引見我的朋友。 ?? ?...
    韓語小助手閱讀 437評論 0 3

友情鏈接更多精彩內容