跟其他的開發(fā)工具一樣,LLDB也有大量健全的文檔.知道如何通過一些比較模糊的命令標(biāo)志在這些文檔中導(dǎo)航, 是掌握LLDB必不可少的技能.
LLDB官方文檔
help 命令
打開一個(gè)終端窗口鍵入lldb. LLDB會(huì)迅速出來.在那里簡單的鍵入help命令:
(lldb) help
這將會(huì)顯示出所有可以用的命令, 包括從~/.lldbinit加載出來的自定義的命令, 但是可能晚一點(diǎn)顯示出來

這里有相當(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命令, 但是只要把help 和 apropos這兩個(gè)命令記在心中.這些是查詢命令信息的基礎(chǔ), 在調(diào)試只路上你會(huì)不停的用到他們.