Chisel常用命令總結(jié)

Chisel簡介

Chisel是Facebook開源的一款lldb調(diào)試工具,其實就是對系統(tǒng)lldb命令的封裝,開發(fā)者可以通過簡化的命令更方便的進行調(diào)試工作。開源地址:https://github.com/facebook/chisel

Chisel安裝

Homebrew的安裝

Chisel的安裝是通過Homebrew來安裝的,所以安裝Chisel前需要先在mac上安裝Homebrew,安裝命令很簡單:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

拷貝該命令到terminal運行即可。

Chisel安裝

安裝完Homebrew后,就可按照github上介紹Chisel的安裝步驟來安裝了。

brew update
brew install chisel

安裝截圖如下:


安裝截圖

注意紅色方框中的內(nèi)容,大致意思是讓我們將下行的命令保存到~/.lldbinit文件中,以便Xcode啟動時去加載Chisel。
所以接下來我們就需要往~/.lldbinit中添加那一行:
在~/目錄下可能沒有.lldbinit文件,此時需要我們新建一個,并打開該文件將那一行添加到文件中:

touch .lldbinit  //新建文件
vim .lldbinit    //通過vim打開該文件

添加截圖如下:


添加截圖

添加完成后保存退出。
最后重啟Xcode,隨便打開一個項目,進入調(diào)試狀態(tài)后,在console中輸入help命令,如果出現(xiàn)以下內(nèi)容,就說明Chisel安裝成功了。

Current user-defined commands:
  alamborder   -- For more information run 'help alamborder'
  alamunborder -- For more information run 'help alamunborder'
  binside      -- For more information run 'help binside'
  bmessage     -- For more information run 'help bmessage'
  border       -- For more information run 'help border'
  caflush      -- For more information run 'help caflush'
  dcomponents  -- For more information run 'help dcomponents'
  fa11y        -- For more information run 'help fa11y'
  flicker      -- For more information run 'help flicker'
  fv           -- For more information run 'help fv'
  fvc          -- For more information run 'help fvc'
  hide         -- For more information run 'help hide'
  mask         -- For more information run 'help mask'
  pa11y        -- For more information run 'help pa11y'
  pactions     -- For more information run 'help pactions'
  paltrace     -- For more information run 'help paltrace'
  panim        -- For more information run 'help panim'
  pca          -- For more information run 'help pca'
  pcells       -- For more information run 'help pcells'
  pclass       -- For more information run 'help pclass'
  pcomponents  -- For more information run 'help pcomponents'
  pcurl        -- For more information run 'help pcurl'
  pdata        -- For more information run 'help pdata'
  pdocspath    -- For more information run 'help pdocspath'
  pinternals   -- For more information run 'help pinternals'
  pinvocation  -- For more information run 'help pinvocation'
  pivar        -- For more information run 'help pivar'
  pjson        -- For more information run 'help pjson'
  pkp          -- For more information run 'help pkp'
  presponder   -- For more information run 'help presponder'
  ptv          -- For more information run 'help ptv'
  pvc          -- For more information run 'help pvc'
  pviews       -- For more information run 'help pviews'
  rcomponents  -- For more information run 'help rcomponents'
  show         -- For more information run 'help show'
  slowanim     -- For more information run 'help slowanim'
  taplog       -- For more information run 'help taplog'
  unborder     -- For more information run 'help unborder'
  unmask       -- For more information run 'help unmask'
  unslowanim   -- For more information run 'help unslowanim'
  visualize    -- For more information run 'help visualize'
  vs           -- For more information run 'help vs'
  wivar        -- For more information run 'help wivar'

Chisel常用命令的使用

pviews

該命令是最常用的命令,主要是用來查看布局中view的層級關(guān)系的。


pviews

圖中command+R運行程序后,點擊暫停按鈕,就可進入lldb控制臺,輸入pivews命令查看當前布局中view的層級關(guān)系。

border/unborder

這兩個命令分別是給要查看的view添加邊框和移除邊框,可以在lldb下輸入help border查看具體的用法,如果我要給第二個view添加一個顏色為藍色,寬度為2的邊框,之后再用unborder命令移除,操作如下:


border/unborder

通過help border命令知道border的使用格式如下:

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>

其中viewOrLayer表示你要修改的view的地址,我們通過pviews命令知道,第二個view的地址是0x7feae2d605f0,所以我們輸入

border -c blue -w 2 0x7feae2d605f0  //添加邊框
unborder 0x7feae2d605f0   //移除邊框

注意我在輸入每個border/unborder命令時,右側(cè)模擬器第二個view的變化。
view的層級關(guān)系。

pinternals

這個命令主要是打印view的內(nèi)部詳細信息,太具體了,有需要的可以好好研究研究:

(lldb) pinternals 0x7feae2d605f0
(UIView) $22 = {
  UIResponder = {
    NSObject = {
      isa = UIView
    }
    _hasAlternateNextResponder = false
    _hasInputAssistantItem = false
  } _constraintsExceptingSubviewAutoresizingConstraints = 0x00007feae2d5cda0 @"3 objects"
  _cachedTraitCollection = nil
  _layer = 0x00007feae2d13760
  _layerRetained = nil
  _gestureInfo = nil
  _gestureRecognizers = nil
  _subviewCache = 0x00007feae2e621b0 @"1 object"
  _templateLayoutView = nil
  _charge = 0
  _tag = 0
  _viewDelegate = nil
  _backgroundColorSystemColorName = nil
  _countOfMotionEffectsInSubtree = 0
  _countOfTraitChangeRespondersInDirectSubtree = 0
  _cachedScreenScale = 0
  _retainCount = 14
  _tintAdjustmentDimmingCount = 0
  _shouldArchiveUIAppearanceTags = false
  _interactionTintColor = nil
  _layoutMarginsGuide = nil
  _minXVariable = 0x00007feae2e5f540
  _minYVariable = 0x00007feae2e64400
  _boundsWidthVariable = 0x00007feae2d0fe70
  _boundsHeightVariable = 0x00007feae2d5cf90
  _layoutEngine = 0x00007feae2e69220
  _layoutDebuggingIdentifier = nil
  _internalConstraints = 0x00007feae2d02e00
  _continuousCornerRadius = 0 _countOfFocusedAncestorTrackingViewsInSubtree = 0
  _semanticContentAttribute = 0
__presentationControllerToNotifyOnLayoutSubviews = nil
  _previewingSegueTemplateStorage = nil
  _contentSizeNotificationToken = nil
  _readableContentGuide = nil
}

visualize

可以使用mac下的預(yù)覽app打開我們的圖片UIImage, CGImageRef格式的圖片,甚至view和layer的圖片 。


visualize

pclass

這個可以查看view的層級關(guān)系


pclass

圖中先查看了UIView的層級關(guān)系,然后查看了一個第三方自定義的控件MMPlaceHolder的層級關(guān)系。

hide/show

這兩個命令顧名思義,就是顯示和隱藏某個指定的view,話不多說,上圖(注意模擬器中第二個view的變化):


show/hide

taplog

這個命令在你點擊屏幕后,lldb打印出你敲擊屏幕時接收事件的view的信息。


taplog

注意,我是先輸入的命令,然后點擊了屏幕才打印出對應(yīng)view的信息。

pvc

這個命令是打印當前的控制器層級,如下圖,我定義了一個UINavigationController,ViewController作為它的根控制器。


pvc

bmessage

有這么中需求,在當前控制器沒有實現(xiàn)某個方法(譬如:-viewWillAppear:)方法,但是我又想在該方法調(diào)用時觸發(fā)中斷,這個時候bmessage就派上用場了


bmessage

這里首先通過pvc命令查看當前控制器的層級關(guān)系,其中ViewController就是當前顯示的控制器,然后通過通過controller變量指向當前控制器,再給該控制器通過bmessage設(shè)置了斷點,之后讓程序繼續(xù)運行,當當前控制器再次被顯示的時候,viewDidAppear:方法被觸發(fā),此時斷點就起作用了,程序就中斷了。

(lldb) e id $controller=(id)0x7fe8ab72ab50 //設(shè)置controller變量指向當前ViewController
(lldb) bmessage [$controller viewDidAppear:] //給當前ViewController設(shè)置斷點
Setting a breakpoint at -[UIViewController viewDidAppear:] with condition (void*)(id)$rdi == 0x00007fe8ab72ab50
Breakpoint 1: where = UIKit`-[UIViewController viewDidAppear:], address = 0x000000010e646d12

以上是Chisel最常用的一些命令,其他的在某些特定場景也有用到,我也不是很了解,所以就不敢輕易寫了,以下是兩篇很好地參考資料,第二篇是第一篇的中文譯文。

<h1>參考</h1>
1、Dancing in the Debugger — A Waltz with LLDB

2、與調(diào)試器共舞 - LLDB 的華爾茲

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

相關(guān)閱讀更多精彩內(nèi)容

  • 不玩LLDB,不知道chisel有多強大。chisel之于LLDB,就像iPhone之于手機,前者幾乎給后者重新下...
    小笨狼閱讀 9,694評論 15 78
  • iOS調(diào)試之chisel Chisel 是一個 LLDB 指令集合,用戶輔助 iOS 應(yīng)用差錯。 安裝 chise...
    comst閱讀 4,692評論 0 13
  • LLDB 是一個有著 REPL 的特性和 C++ ,Python 插件的開源調(diào)試器。LLDB 綁定在 Xcode ...
    Eric_zheng閱讀 494評論 0 0
  • 與調(diào)試器共舞 - LLDB 的華爾茲 nangege 2014/12/19 你是否曾經(jīng)苦惱于理解你的代碼,而去嘗試...
    McDan閱讀 946評論 0 0
  • LLDB是XCode內(nèi)置的為我們開發(fā)者提供的調(diào)試工具,是一個有著 REPL 的特性和 C++ ,Python 插件...
    風(fēng)塵子閱讀 1,087評論 0 2

友情鏈接更多精彩內(nèi)容