lldb命令常用(備忘)
假如你准備在模擬器里面運行這個,你可以在“(lldb)”提示的后面輸入下面的:
(lldb) po $eax
LLDB在xcode4.3或者之后的版本里面是默認的調試器。假如你正在使用老一點版本的xcode的話,你又GDB調試器。他們有一些基本的相同的命令,因此假如你的xcode使用的是“(gdb)”提示,而不是“(lldb)”提示的話,你也能夠更隨一起做,而沒有問題。
“po”命令是“print object”(打印對象)的簡寫。“$eax”是cup的一個寄存器。在一個異常的情況下,這個寄存器將會包含一個異常對象的指針。注意:$eax只會在模擬器里面工作,假如你在設備上調試,你將需要使用”$r0″寄存器。
例如,假如你輸入:
(lldb) po [$eax class]
你將會看像這樣的東西:
(id) $2 = 0x01446e84 NSException
這些數字不重要,但是很明顯的是你正在處理的NSException對象在這里。
你可以對這個對象調用任何方法。例如:
(lldb) po [$eax name]
這個將會輸出這個異常的名字,在這里是NSInvalidArgumentException,並且:
(lldb) po [$eax reason]
這個將會輸出錯誤消息:
(unsigned int) $4 = 114784400 Receiver () has no segue with identifier 'ModalSegue'
注意:當你僅僅使用了“po $eax”,這個命令將會對這個對象調用“description”方法和打印出來,在這個情況下,你也會得到錯誤的消息。
實用LLDB命令
命令名 用法 說明
expr | expr 表達式 | 可以在調試時動態執行指定表達式,並將結果打印出來,很有用的命令。 |
po | po 表達式 | 與expr類似,打印對象,會調用對象description方法。是print-object的簡寫 |
print (type) 表達式 | 也是打印命令,需要指定類型。 | |
bt | bt [all] | 打印調用堆棧,是thread backtrace的簡寫,加all可打印所有thread的堆棧。 |
br l | br l | 是breakpoint list的簡寫 |
process continue l | process continue | 簡寫:c |
thread step-in l | thread step-in l | 簡寫:s |
thread step-inst l | thread step-inst l | 簡寫:si |
thread step-over l | thread step-over l | 簡寫:n |
thread step-over-inst l | thread step-over-inst l | 簡寫:ni |
thread step-out l | thread step-out l | 簡寫:f |
thread list | thread list | 簡寫:th l |