開始學(xué)習(xí)LLDB命令(第二章:Help & Apropos)

跟其他的開發(fā)工具一樣,LLDB也有大量健全的文檔.知道如何通過一些比較模糊的命令標(biāo)志在這些文檔中導(dǎo)航, 是掌握LLDB必不可少的技能.
LLDB官方文檔

help 命令

打開一個(gè)終端窗口鍵入lldb. LLDB會(huì)迅速出來.在那里簡單的鍵入help命令:

(lldb) help

這將會(huì)顯示出所有可以用的命令, 包括從~/.lldbinit加載出來的自定義的命令, 但是可能晚一點(diǎn)顯示出來

page32image6336.png

這里有相當(dāng)多的LLDB命令可以用.
然而, 許多命令包含著幾個(gè)子命令, 這些子命令又有自己相關(guān)的文檔.
breakpoint命令為例. 通過鍵入下面的指令來查看breakpoint命令的文檔:

(lldb) help breakpoint

你會(huì)看到下面這些輸出:

Commands for operating on breakpoints (see 'help b' for shorthand.)
Syntax: breakpoint <subcommand> [<command-options>]
The following subcommands are supported:
      clear   -- Delete or disable breakpoints matching the specified
source file and line.
      command -- Commands for adding, removing and listing LLDB commands
executed when a breakpoint is hit.
      delete  -- Delete the specified breakpoint(s).  If no breakpoints
are specified, delete them all.
      disable -- Disable the specified breakpoint(s) without deleting
them.  If none are specified, disable all breakpoints.
      enable  -- Enable the specified disabled breakpoint(s). If no
breakpoints are specified, enable all of them.
      list    -- List some or all breakpoints at configurable levels of
detail.
      modify  -- Modify the options on a breakpoint or set of breakpoints
in the executable.  If no breakpoint is specified,
                 acts on the last created breakpoint.  With the exception
of -e, -d and -i, passing an empty argument clears
                 the modification.
      name    -- Commands to manage name tags for breakpoints
      set     -- Sets a breakpoint or set of breakpoints in the
executable.
For more help on any particular subcommand, type 'help <command>
<subcommand>'.

在這里你可以看到幾個(gè)支持的子命令. 要查看breakpoint name命令的文檔, 可以輸入下面的內(nèi)容:

(lldb) help breakpoint name

你將看到下面的輸出:

The following subcommands are supported:
      add    -- Add a name to the breakpoints provided.
      delete -- Delete a name from the breakpoints provided.
      list   -- List either the names for a breakpoint or the breakpoints
for a given name.
For more help on any particular subcommand, type 'help <command>
<subcommand>'.

如果此刻你不理解breakpoint name, 別擔(dān)心你將很快就會(huì)理解breakpoints和后面所有的命令.從現(xiàn)在開始, help是你要記住的最重要的命令.

apropos命令

有時(shí)你并不知道你要搜索的命令的名字, 但是你知道它包含的關(guān)鍵詞或者短語可以給你指出正確的方向.apropos就是為你做這件事的. 這有點(diǎn)像在web上用搜索引擎找東西.
apropos是不區(qū)分大小寫的,并且將返回LLDB文檔中匹配的任何結(jié)果.例如搜索任何與Swift有關(guān)內(nèi)容:

(lldb) apropos swift

你將會(huì)看到下面這些輸出:

The following built-in commands may relate to 'swift':
  breakpoint set          -- Sets a breakpoint or set of breakpoints in
the executable.
  expression              -- Evaluate an expression (ObjC++ or Swift) in
the current program context, using user defined variables and variables
                             currently in scope.
  language swift          -- A set of commands for operating on the Swift
Language Runtime.
  language swift demangle -- Demangle a Swift mangled name
  language swift refcount -- Inspect the reference count data for a Swift
object
The following settings variables may relate to 'swift':
  target.swift-framework-search-paths -- List of directories to be
searched when locating frameworks for Swift.
  target.swift-module-search-paths -- List of directories to be searched
when locating modules for Swift.
  target.use-all-compiler-flags -- Try to use compiler flags for all
modules when setting up the Swift expression parser, not just the main
executable.

這將選取出所有與單詞Swift相關(guān)的內(nèi)容.首先是相關(guān)的命令, 然后是可以控制LLDB操作的LLDB設(shè)置.
你也可以使用apropos去搜索一個(gè)特定的句子.例如, 如果你要搜索與reference counting相關(guān)的內(nèi)容, 你可以使用下面的命令:

(lldb) apropos "reference count"
The following built-in commands may relate to 'reference count':
  language swift refcount -- Inspect the reference count data for a Swift
object
  target modules list     -- List current executable and dependent shared
library images.

注意愛用雙引號(hào)包裹著單詞"reference count",.apropos只會(huì)接收一個(gè)搜索的參數(shù), 因此雙引號(hào)可以讓它們作為一個(gè)單獨(dú)的參數(shù)是必要的.
感覺不夠整潔?apropos是一個(gè)用來查詢的方便的工具.它不像現(xiàn)代互聯(lián)網(wǎng)搜索引擎那么復(fù)雜, 然而在平常的練習(xí)中你可以找到你想要的.
我們?yōu)槭裁匆獙W(xué)這些?
我們很容易就會(huì)忘記我們將要學(xué)習(xí)的大量的LLDB命令, 但是只要把helpapropos這兩個(gè)命令記在心中.這些是查詢命令信息的基礎(chǔ), 在調(diào)試只路上你會(huì)不停的用到他們.

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

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

  • LLDB的Xcode默認(rèn)的調(diào)試器,它與LLVM編譯器一起,帶給我們更豐富的流程控制和數(shù)據(jù)檢測的調(diào)試功能。平時(shí)用Xc...
    CoderSC閱讀 1,510評論 0 2
  • [轉(zhuǎn)]淺談LLDB調(diào)試器文章來源于:http://www.cocoachina.com/ios/20150126/...
    loveobjc閱讀 2,735評論 2 6
  • 本文是Advanced Apple Debugging的學(xué)習(xí)筆記.首先將Xcode升級(jí)到8.3版本.可以通過下載地...
    股金雜談閱讀 3,330評論 13 4
  • 隨著Xcode 5的發(fā)布,LLDB調(diào)試器已經(jīng)取代了GDB,成為了Xcode工程中默認(rèn)的調(diào)試器。它與LLVM編譯器一...
    隨風(fēng)飄蕩的小逗逼閱讀 1,462評論 0 0
  • 轉(zhuǎn)載 與調(diào)試器共舞 - LLDB 的華爾茲: https://objccn.io/issue-19-2/ 推薦:i...
    F麥子閱讀 3,459評論 0 10

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