iOS調(diào)試工具 - LLDB

LLDB

LLDBXcode 默認(rèn)的調(diào)試工具, 支持調(diào)試 c, c++, Objective-C.支持的調(diào)試平臺(tái):

  • Mac OS X desktop user space debugging fori386 and x86-64
  • iOS simulator debugging oni386
  • iOS device debugging on ARM
  • Linux local user-space debugging fori386 and x86-64
  • FreeBSD local user-space debugging for i386 and x86-64
  • Windows local user-space debugging for i386 (*)

LLDB 常用指令

  • 語(yǔ)法
    <noun> <verb> [-options [option-value]] [argument [argument...]]
  • 添加breakpoint

// 給文件中某一行添加斷點(diǎn)
(lldb) breakpoint set --file foo.c --line 12
(lldb) breakpoint set -f foo.c -l 12
// 給某個(gè)方法添加斷點(diǎn)
(lldb) breakpoint set --name foo
(lldb) breakpoint set -n foo
// 一次給多個(gè)方法添加斷點(diǎn)
(lldb) breakpoint set --name foo --name bar
// c++中給方法添加斷點(diǎn)
(lldb) breakpoint set --method foo
(lldb) breakpoint set -M foo
// Objective-C 中給方法添加斷點(diǎn)
(lldb) breakpoint set --selector alignLeftEdges:
(lldb) breakpoint set -S alignLeftEdges:
// 給文件中方法添加斷點(diǎn)
(lldb) breakpoint set -n "-[SKTGraphicView alignLeftEdges:]"
(lldb) br s -n "-[SKTGraphicView alignLeftEdges:]"
// 查看斷點(diǎn)
(lldb) breakpoint list
// 為斷點(diǎn)設(shè)置打印信息
breakpoint command add 1.1
Enter your debugger command(s). Type 'DONE' to end.
> bt
> DONE
用--script 設(shè)置腳本
// 查詢幫助信息
(lldb) help break command add
Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit.
Syntax: breakpoint command add <cmd-options> <breakpt-id>
etc...
// 添加條件斷點(diǎn)
(lldb) breakpoint modify -c "self == nil" -C bt --auto-continue 1 2 3
// 條件設(shè)置優(yōu)化
(lldb) breakpoint set -N SelfNil
(lldb) breakpoint modify -c "self == nil" -C bt --auto-continue SelfNil
(lldb) breakpoint name configure -c "self == nil" -C bt --auto-continue SelfNil
// 設(shè)置別名
(lldb) command alias bfl breakpoint set -f %1 -l %2
(lldb) bfl foo.c 12
~/.lldbinit文件中, 設(shè)置別名(沒(méi)有此文件, 自己新建一個(gè))
// 給動(dòng)態(tài)庫(kù)中方法添加斷點(diǎn)
(lldb) breakpoint set --shlib foo.dylib --name foo
(lldb) breakpoint set -s foo.dylib -n foo

  • 添加watchpoint

// 添加
(lldb) watch set var global
Watchpoint created: Watchpoint 1: addr = 0x100001018 size = 4 state = enabled type = w declare @ '/Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp:12'
// 修改
(lldb) watch modify -c '(global==5)'
(lldb) watch list
// 查看
Current watchpoints: Watchpoint 1: addr = 0x100001018 size = 4 state = enabled type = w declare @ '/Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp:12' condition = '(global==5)'
// 繼續(xù)下一步
(lldb) c
Process 15562 resuming
(lldb) about to write to 'global'...
Process 15562 stopped and was programmatically restarted. Process 15562 stopped and was programmatically restarted. Process 15562 stopped and was programmatically restarted. Process 15562 stopped and was programmatically restarted. Process 15562 stopped
* thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out modify + 21 at main.cpp:16, stop reason = watchpoint 1 frame #0: 0x0000000100000ef5 a.out modify + 21 at main.cpp:16 13 14 static void modify(int32_t &var) { 15 ++var; -> 16 } 17 18 int main(int argc, char** argv) { 19 int local = 0;
// 查看調(diào)用棧
(lldb) bt
* thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out modify + 21 at main.cpp:16, stop reason = watchpoint 1 frame #0: 0x0000000100000ef5 a.out modify + 21 at main.cpp:16 frame #1: 0x0000000100000eac a.out main + 108 at main.cpp:25 frame #2: 0x00007fff8ac9c7e1 libdyld.dylib start + 1
// 設(shè)置監(jiān)聽(tīng)
(lldb) frame var global
(int32_t) global = 5
// 查看 watchpoint
(lldb) watch list -v
Current watchpoints: Watchpoint 1: addr = 0x100001018 size = 4 state = enabled type = w declare @ '/Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp:12' condition = '(global==5)' hw_index = 0 hit_count = 5 ignore_count = 0

  • 操作 process

(lldb) process launch
(lldb) run
(lldb) r
(lldb) process attach --pid 123
(lldb) process attach --name Sketch
(lldb) process attach --name Sketch --waitfor
(lldb) process attach -p 12345
Process 46915 Attaching Process 46915 Stopped 1 of 3 threads stopped with reasons: * thread #1: tid = 0x2c03, 0x00007fff85cac76a, where = libSystem.B.dylib __getdirentries64 + 10, stop reason = signal = SIGSTOP, queue = com.apple.main-thread

  • 線程

(lldb) thread continue
Resuming thread 0x2c03 in process 46915
Resuming process 46915
(lldb) c
(lldb) thread step-in // The same as gdb's "step" or "s"
(lldb) thread step-over // The same as gdb's "next" or "n"
(lldb) thread step-out // The same as gdb's "finish" or "f"
(lldb) thread step-inst // The same as gdb's "stepi" / "si"
(lldb) thread step-over-inst // The same as gdb's "nexti" / "ni"
(lldb) thread until 100

(lldb) process continue
(lldb) breakpoint set --name stop_here
(lldb) settings set target.process.disable-stdio true

  • 監(jiān)聽(tīng)變量

(lldb) frame variable self = (SKTGraphicView *) 0x0000000100208b40 _cmd = (struct objc_selector *) 0x000000010001bae1 sender = (id) 0x00000001001264e0 selection = (NSArray *) 0x00000001001264e0 i = (NSUInteger) 0x00000001001264e0 c = (NSUInteger) 0x00000001001253b0
(lldb) frame variable self (SKTGraphicView *) self = 0x0000000100208b40
(lldb) frame variable self.isa (struct objc_class *) self.isa = 0x0000000100023730
(lldb) frame variable *self (SKTGraphicView *) self = 0x0000000100208b40 (NSView) NSView = { (NSResponder) NSResponder = { ...
(lldb) frame variable &self (SKTGraphicView **) &self = 0x0000000100304ab
(lldb) frame variable argv[0] (char const *) argv[0] = 0x00007fff5fbffaf8 "/Projects/Sketch/build/Debug/Sketch.app/Contents/MacOS/Sketch"
(lldb) frame variable -o self (SKTGraphicView *) self = 0x0000000100208b40 <SKTGraphicView: 0x100208b40>
(lldb) frame select 9 frame #9: 0x0000000100015ae3, where = Sketchfunction1 + 33 at /Projects/Sketch/SKTFunctions.m:11
(lldb) expr self $0 = (SKTGraphicView *) 0x0000000100135430 (lldb) expr self = 0x00 $1 = (SKTGraphicView *) 0x0000000000000000 (lldb) frame var self (SKTGraphicView *) self = 0x0000000000000000
(lldb) expr (int) printf ("I have a pointer 0x%llx.\n", self) $2 = (int) 22 I have a pointer 0x0.
(lldb) expr self = $0 $4 = (SKTGraphicView *) 0x0000000100135430

  • Image 指令

image list
// 根據(jù)地址檢索
image lookup --address 0x1ec4
im loo -a 0x1ec4
image lookup -v --address 0x1ec4
image lookup --address 0x1ec4 a.out
im loo -a 0x1ec4 a.out
// 檢索庫(kù)文件中的方法
image lookup -r -n <FUNC_REGEX>
image lookup -r -s <FUNC_REGEX>

  • thread 指令

(lldb) thread list
(lldb) thread select 1
(lldb) t 1
(lldb) thread backtrace
(lldb) bt
(lldb) thread backtrace all
(lldb) bt all
(lldb) thread backtrace -c 5
(lldb) bt 5 (lldb-169 and later)
(lldb) bt -c 5 (lldb-168 and earlier)

  • frame 指令

(lldb) frame select 12
(lldb) fr s 12
(lldb) f 12
(lldb) frame info
(lldb) up
(lldb) frame select --relative=1
(lldb) down
(lldb) frame select --relative=-1
(lldb) fr s -r-1
(lldb) frame select --relative 2
(lldb) fr s -r2
(lldb) frame select --relative -3
(lldb) fr s -r-3

  • register 指令

(lldb) register read
(lldb) register write rax 123
(lldb) register write pc "$pc+8"
(lldb) register read --format i
(lldb) re r -f i
(lldb) register read --all
(lldb) re r -a
(lldb) register read rax rsp rbp
(lldb) register read --format binary rax
(lldb) re r -f b rax
(lldb) register read/t rax
(lldb) p/t $rax

  • memory 指令

(lldb) memory read --size 4 --format x --count 4 0xbffff3c0
(lldb) me r -s4 -fx -c4 0xbffff3c0
(lldb) x -s4 -fx -c4 0xbffff3c0
(lldb) memory read/4xw 0xbffff3c0
(lldb) x/4xw 0xbffff3c0
(lldb) memory read --gdb-format 4xw 0xbffff3c0
(lldb) memory read 'argv[0]'
(lldb) memory read --size 'sizeof(int)' 'argv[0]'
(lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0
(lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0
(lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0
(lldb) memory read --outfile /tmp/mem.bin --binary 0x1000 0x2000
(lldb) me r -o /tmp/mem.bin -b 0x1000 0x2000
(lldb) command script import lldb.macosx.heap
(lldb) process launch --environment MallocStackLogging=1 -- [ARGS]
(lldb) malloc_info --stack-history 0x10010d680

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末身冀,一起剝皮案震驚了整個(gè)濱河市记盒,隨后出現(xiàn)的幾起案子彬伦,更是在濱河造成了極大的恐慌,老刑警劉巖错邦,帶你破解...
    沈念sama閱讀 206,602評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件舆瘪,死亡現(xiàn)場(chǎng)離奇詭異朽肥,居然都是意外死亡梗脾,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,442評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門(mén)繁涂,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)拱她,“玉大人,你說(shuō)我怎么就攤上這事爆土⊥职茫” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 152,878評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵步势,是天一觀的道長(zhǎng)氧猬。 經(jīng)常有香客問(wèn)我,道長(zhǎng)坏瘩,這世上最難降的妖魔是什么盅抚? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,306評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮倔矾,結(jié)果婚禮上妄均,老公的妹妹穿的比我還像新娘。我一直安慰自己哪自,他們只是感情好丰包,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,330評(píng)論 5 373
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著壤巷,像睡著了一般邑彪。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上胧华,一...
    開(kāi)封第一講書(shū)人閱讀 49,071評(píng)論 1 285
  • 那天寄症,我揣著相機(jī)與錄音宙彪,去河邊找鬼。 笑死有巧,一個(gè)胖子當(dāng)著我的面吹牛释漆,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播篮迎,決...
    沈念sama閱讀 38,382評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼男图,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了甜橱?” 一聲冷哼從身側(cè)響起享言,我...
    開(kāi)封第一講書(shū)人閱讀 37,006評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎渗鬼,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體荧琼,經(jīng)...
    沈念sama閱讀 43,512評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡譬胎,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,965評(píng)論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了命锄。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片堰乔。...
    茶點(diǎn)故事閱讀 38,094評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖脐恩,靈堂內(nèi)的尸體忽然破棺而出镐侯,到底是詐尸還是另有隱情,我是刑警寧澤驶冒,帶...
    沈念sama閱讀 33,732評(píng)論 4 323
  • 正文 年R本政府宣布苟翻,位于F島的核電站,受9級(jí)特大地震影響骗污,放射性物質(zhì)發(fā)生泄漏崇猫。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,283評(píng)論 3 307
  • 文/蒙蒙 一需忿、第九天 我趴在偏房一處隱蔽的房頂上張望诅炉。 院中可真熱鬧,春花似錦屋厘、人聲如沸涕烧。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,286評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)议纯。三九已至,卻和暖如春仲翎,著一層夾襖步出監(jiān)牢的瞬間痹扇,已是汗流浹背铛漓。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,512評(píng)論 1 262
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留鲫构,地道東北人浓恶。 一個(gè)月前我還...
    沈念sama閱讀 45,536評(píng)論 2 354
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像结笨,于是被迫代替她去往敵國(guó)和親包晰。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,828評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容

  • [轉(zhuǎn)]淺談LLDB調(diào)試器文章來(lái)源于:http://www.cocoachina.com/ios/20150126/...
    loveobjc閱讀 2,484評(píng)論 2 6
  • 轉(zhuǎn)載 與調(diào)試器共舞 - LLDB 的華爾茲: https://objccn.io/issue-19-2/ 推薦:i...
    F麥子閱讀 3,327評(píng)論 0 10
  • LLDB的Xcode默認(rèn)的調(diào)試器炕吸,它與LLVM編譯器一起伐憾,帶給我們更豐富的流程控制和數(shù)據(jù)檢測(cè)的調(diào)試功能。平時(shí)用Xc...
    CoderSC閱讀 1,346評(píng)論 0 2
  • GDB TO LLDB COMMAND MAP Below is a table of GDB commands ...
    狂風(fēng)無(wú)跡閱讀 1,746評(píng)論 0 2
  • 你是否曾經(jīng)苦惱于理解你的代碼赫模,而去嘗試打印一個(gè)變量的值树肃? NSLog(@"%@", whatIsInsideThi...
    paraneaeee閱讀 1,181評(píng)論 0 7