以前使用編譯器調試的時候,每次只是用常規的幾個調試命令。可是本着折騰的原則,今天把 全部的調試命令
及功能都羅列出來。html
語歌 博客git
再下面有更詳細的示範
github
若是想要了解更多編譯器調試的命令: 傳送門shell
接下來看一下經常使用的調試命令用法:express
apropos
列出與某個單詞或主題相關的調試器命令。
e.g(lldb) apropos po
swift
breakpoint
看截圖文檔:(lldb) breakpoint
xcode
能夠簡寫爲 br
功能很是強大,下面還有詳細的描述sass
breakpoint
(lldb) print sums
能夠簡寫成 (lldb) p sums
既: print
寫成 p
app
代碼中這樣:
var sums = ["0.00","0.00","0.00","0.00"]複製代碼
調試窗口這樣:
結果:less
(lldb) print sums
([String]) $R14 = 4 values {
[0] = "0.00"
[1] = "0.00"
[2] = "0.00"
[3] = "0.00"
}複製代碼
若是你想在命令行打印進制數:
輸入參數 | 表示進制 (e.g) |
---|---|
p/x 66 | (x表示16進制)(Int) $R17 = 0x0000000000000042 |
p/t 6 | (t表示2進制)(Int) $R20 = 0b0000000000000000000000000000000000000000000000000000000000000110 |
p/c "s" | (c表示字符)(String) $R24 = "s" |
expression
直接改變其值,點擊繼續運行,運行的結果就是本次賦值後的結果
(lldb) expression sums = ["10.00","0.00","0.00","0.00"]複製代碼
示例:
更多的用法:
以對象的方式來打印:expression -o -- sums
能夠直接簡寫成這樣: e -o -- sums
其中:e -o -- sums
能夠寫成 po
,並且做用是等效的。
process
與進程交互的命令,固然是配合其後面的參數來達到相應的目的 執行 (lldb) process help
以下:
舉個常見栗子:continue -- Continue execution of all threads in the current process.
就是繼續執行程序,當遇到斷點的時候,在 LLDB
中執行就是繼續執行程序
thread
與進程交互的命令,固然是配合其後面的參數來達到相應的目的 執行 (lldb) thread help
以下:
其搭配的參數命令執行的做用後面描繪的至關清楚。
這裏要重點介紹幾個:
* **`(lldb) thread return`** 過早的從堆棧中返回,當即執行返回命令,退出當前堆棧。能夠假裝一些返回信息等等。從寫一些函數的行爲等等。複製代碼
frame
一樣是配合其參數完成調試
lldb) frame info
經常使用按鈕
由圖中能夠看出用於調試的 4
個按鈕
第一個 continue
如遇到如圖所示,就點擊後程序就正常運行,若是有其它斷點,就會跳到下一個斷點.
ps: 點擊它與在 LLDB調試框
裏面輸入
(lldb) process continue
做用是同樣的。
c
做用效果也是同樣的
第二個 step over
當遇到一個斷點暫停後,點擊該按鈕程序就會一行一行的執行,即便遇到了函數的調用也不會進入函數裏面去,而是直接跳過這個函數的執行,以下圖:
115
行打了一個斷點,而後點擊該按鈕,他會執行 116
行,再點擊後會執行 117
行,而不會去執行 116
所調用的函數 裏面的行。LLDB
命令參數是同樣的命令是:(lldb) n
(lldb) next
(lldb) thread step-over
第三個step into
.它纔是真正意義上的一行一行的執行命令,即便遇到函數的執行,也會跳 進該函數裏面去一行一行
的執行代碼。就是說你想進入函數裏面的時候用它
ps: 在程序當中與該按鈕做用相同的 LLDB
命令參數是同樣的命令是:
(lldb) thread step-in
(lldb) step
(lldb) s
step out
若是你進入了一個函數,運行一兩行以後你想跳過該函數就用這個按鈕。其實它的運行就是一個 堆棧的結束。如圖這是經過點擊查看工程文件中全部的斷點
那麼經過 LLDB
命令來查看全部的斷點:(lldb) br list
或者 (lldb) br li
也能夠達到相同的目的
LLDB
快速建立斷點使用下面的命令完成了 115行 斷點的設定(lldb) breakpoint set -f ViewController.swift -l 115
這個時候咱們執行 continue
按鈕會發現跳到 115行斷點了。
咱們經過大列表查看 b
其介紹是:
Set a breakpoint using one of several shorthand formats.
設置斷點的命令是:(lldb) b ViewController.swift:127
在127
處設置了斷點
如圖:
由圖可看:
第1
步:咱們在 line 24
的地方打了一個斷點。
第2
步:咱們看到標 2
的框框,這裏 i==2
表示當 i等於2的時候纔會執行這個斷點
第3
步:咱們看到標 3
的框框,這裏表示當執行這個斷點的時候,LLDB
會執行 po i
的命令
第4
步:咱們看到標 4
的框框,當i爲2
的時候執行了斷點的打印操做
其中 ignore
表示該斷點第幾回纔會真正執行,好比 設置 ignore
爲 2
那麼該斷點會在第三次調用的時候觸發。
那麼這裏要說明的就是:斷點程序會先 比較 函數執行到該斷點的 次數。而後 再比較條件 ,條件知足後 執行 LLDB
命令 語句
其中的 +
號能夠支持多個 LLDB
命令。
其餘的斷點條件及執行的命令,依次類推。
Action
後面的更多做用!如圖:
AppleScript
蘋果的一種腳本語言,能夠在此開始運行
Capture GPU Frame
Unity遊戲
方面的調試。暫時沒有研究 😄
Debugger Command
至關於在 LLDB
上直接使用命令
Log Message
當執行到該斷點的時候 LLDB
欄中會直接打印這個 hello
的信息
Shell Command
如圖:
Hello world
Sound
選擇相應的聲音遇到該斷點會發出相應的聲音,也是挺有意思的。
隨便打個斷點:
命令行輸入: (lldb) help
快速查詢因此的命令 一覽表
命令 | 命令做用描述 | |||
---|---|---|---|---|
apropos | -- List debugger commands related to a word or subject.(列出與某個單詞或主題相關的調試器命令。) | |||
breakpoint | -- Commands for operating on breakpoints (see 'help b' for shorthand.)(斷點的相關操做,詳細看下面) | |||
bugreport | -- Commands for creating domain-specific bug reports.(建立某個特色做用域的bug 命令) | |||
command | -- Commands for managing custom LLDB commands. | |||
disassemble | -- Disassemble specified instructions in the current target. Defaults to the current function for the current thread and stack frame. | |||
expression | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting.(直接改變其值,點擊繼續運行) | |||
frame | -- Commands for selecting and examing the current thread's stack frames.(經過命令來檢查當前堆棧的相關信息。結合後面的命令參數) | |||
gdb-remote | -- Connect to a process via remote GDB server. If no host is specifed, localhost is assumed. | |||
gui | -- Switch into the curses based GUI mode. | |||
help | -- Show a list of all debugger commands, or give details about a specific command. | |||
kdp-remote | -- Connect to a process via remote KDP server. If no UDP port is specified, port 41139 is assumed. | |||
language | -- Commands specific to a source language. | |||
log | -- Commands controlling LLDB internal logging. | |||
memory | -- Commands for operating on memory in the current target process. | |||
platform | -- Commands to manage and create platforms. | |||
plugin | -- Commands for managing LLDB plugins. | |||
process | -- Commands for interacting with processes on the current platform.(配合其包含的命令繼續執行 執行 process help 便可看到) |
|||
quit | -- Quit the LLDB debugger. | |||
register | -- Commands to access registers for the current thread and stack frame. | |||
script | -- Invoke the script interpreter with provided code and display any results. Start the interactive interpreter if no code is supplied. | |||
settings | -- Commands for managing LLDB settings. | |||
source | -- Commands for examining source code described by debug information for the current target process. | |||
target | -- Commands for operating on debugger targets. | |||
thread | -- Commands for operating on one or more threads in the current process.(在當前進程中操做一個或多個線程的命令,結合其下面的參數進行。下面有其搭配參數詳細說明) | |||
type | -- Commands for operating on the type system. | |||
version | -- Show the LLDB debugger version.(查看開發語言的版本) | |||
watchpoint | -- Commands for operating on watchpoints. | |||
add-dsym | -- Add a debug symbol file to one of the target's current modules by specifying a path to a debug symbols file, or using the options to specify a module to download symbols for. | |||
attach | -- Attach to process by ID or name. | |||
b | -- Set a breakpoint using one of several shorthand formats. | |||
bt | -- Show the current thread's call stack. Any numeric argument displays at most that many frames. The argument 'all' displays all threads. | |||
c | -- Continue execution of all threads in the current process. | |||
call | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting. | |||
continue | -- Continue execution of all threads in the current process. | |||
detach | -- Detach from the current target process. | |||
di | -- Disassemble specified instructions in the current target. Defaults to the current function for the current thread and stack frame. | |||
dis | -- Disassemble specified instructions in the current target. Defaults to the current function for the current thread and stack frame. | |||
display | -- Evaluate an expression at every stop (see 'help target stop-hook'.) | |||
down | -- Select a newer stack frame. Defaults to moving one frame, a numeric argument can specify an arbitrary number. | |||
env | -- Shorthand for viewing and setting environment variables. | |||
exit | -- Quit the LLDB debugger. | |||
f | -- Select the current stack frame by index from within the current thread (see 'thread backtrace'.) | |||
file | -- Create a target using the argument as the main executable. | finish | -- Finish executing the current stack frame and stop after returning. Defaults to current thread unless specified. | |
image | -- Commands for accessing information for one or more target modules. | |||
j | -- Set the program counter to a new address. | |||
jump | -- Set the program counter to a new address. | |||
kill | -- Terminate the current target process. | |||
l | -- List relevant source code using one of several shorthand formats. | |||
list | -- List relevant source code using one of several shorthand formats. | |||
n | -- Source level single step, stepping over calls. Defaults to current thread unless specified.(至關於一行一行的執行函數) | |||
next | -- Source level single step, stepping over calls. Defaults to current thread unless specified.(與 n 的做用幾乎一致) | |||
nexti | -- Instruction level single step, stepping over calls. Defaults to current thread unless specified. | |||
ni | -- Instruction level single step, stepping over calls. Defaults to current thread unless specified. | |||
p | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting.(能夠打印程序中相關參數的值,其屬性狀態) | |||
parray | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting.(與 p 相同) | |||
po | -- Evaluate an expression on the current thread. Displays any returned value with formatting controlled by the type's author.(與 p 的區別是打印的值所帶的參數相對簡潔一點) | |||
poarray | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting.(與 p 相同) | |||
-- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting.(與 p 相同) | ||||
q | -- Quit the LLDB debugger. | |||
r | -- Launch the executable in the debugger. | |||
rbreak | -- Sets a breakpoint or set of breakpoints in the executable. | |||
repl | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting. | |||
reveal_load_dev | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting. | |||
reveal_load_sim | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting. | |||
reveal_start | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting. | |||
reveal_stop | -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting. | |||
run | -- Launch the executable in the debugger. | |||
s | -- Source level single step, stepping into calls. Defaults to current thread unless specified.(一步一步執行,即便遇到函數也會進入該函數一步一步執行代碼) | |||
si | -- Instruction level single step, stepping into calls. Defaults to current thread unless specified. | |||
sif | -- Step through the current block, stopping if you step directly into a function whose name matches the TargetFunctionName. | |||
step | -- Source level single step, stepping into calls. Defaults to current thread unless specified. | |||
stepi | -- Instruction level single step, stepping into calls. Defaults to current thread unless specified. | |||
t | -- Change the currently selected thread. | |||
tbreak | -- Set a one-shot breakpoint using one of several shorthand formats. | |||
undisplay | -- Stop displaying expression at every stop (specified by stop-hook index.) | |||
up | -- Select an older stack frame. Defaults to moving one frame, a numeric argument can specify an arbitrary number. | |||
x | -- Read from the memory of the current target process. |