iOSデバッグツール-LLDB

10262 ワード

LLDB
LLDBはXcodeのデフォルトのデバッグツールで、デバッグc,c++,Objective-C.がサポートするデバッグプラットフォームです.
  • Mac OS X desktop user space debugging for i386 and x86-64
  • iOS simulator debugging on i386
  • iOS device debugging on ARM
  • Linux local user-space debugging for i386 and x86-64
  • FreeBSD local user-space debugging for i386 and x86-64
  • Windows local user-space debugging for i386 (*)

  • LLDB共通命令
  • 構文 [-options [option-value]] [argument [argument...]]
  • breakpoint
  • を追加
    //ファイルの行にブレークポイント(lldb)breakpoint set--file fooを追加する.c --line 12 (lldb) breakpoint set -f foo.c-l 12//あるメソッドにブレークポイント(lldb)breakpoint set--name foo(lldb)breakpoint set-n foo//複数のメソッドに一度にブレークポイント(lldb)breakpoint set--name foo--name bar//c++でメソッドにブレークポイント(lldb)breakpoint set--method foo(lldb)を追加breakpoint set-M foo//Objective-Cメソッドにブレークポイントを追加(lldb) breakpoint set --selector alignLeftEdges: (lldb) breakpoint set -S alignLeftEdges://ファイルにメソッドにブレークポイントを追加(lldb) breakpoint set -n "-[SKTGraphicView alignLeftEdges:]" (lldb) br s -n "-[SKTGraphicView alignLeftEdges:]"//ブレークポイントを表示(lldb) breakpoint list//ブレークポイントに印刷情報を設定breakpoint command add 1.1 Enter your debugger command(s). Type 'DONE' to end. > bt > DONE//クエリーヘルプ情報 --script (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 //追加条件ブレークポイントetc...//条件設定最適化(lldb) breakpoint modify -c "self == nil" -C bt --auto-continue 1 2 3 (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 (lldb) command alias bfl breakpoint set -f %1 -l %2 (lldb) bfl foo.c 12 ~/.lldbinit (lldb) watch set var globalこのファイルに別名を設定(このファイルがない、自分で新規作成する)/ダイナミックライブラリのメソッドにブレークポイント(lldb)breakpoint set--shlib fooを追加する.dylib --name foo (lldb) breakpoint set -s foo.dylib -n foo
  • watchpoint
  • を追加
    //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)'//表示(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;//表示呼び出しスタック(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//リスニング(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
  • 傍受変数
  • (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 (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.
    ", self) $2 = (int) 22 I have a pointer 0x0.
    (lldb) expr self = $0 $4 = (SKTGraphicView *) 0x0000000100135430
  • Image指令
  • image list//アドレスから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//ライブラリファイルを検索する方法image lookup -r -n image lookup -r -s
  • 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