LLDB(Low Lever Debug)

2018-05-10  本文已影响0人  NextStepPeng

断点

*设置断点(OC)
$breakpoint set -n "[ViewController pauseGame:]"
设置多个
$breakpoint set -n "[ViewController pauseGame:]" -n "[ViewController pauseGame1:]"
在某个文件里面设置
$breakpoint set --file ViewController.m --selector touchesBegan:withEvent:
遍历整个项目的方法
$breakpoint set -r Game:

流程控制

查看堆栈信息

$bt

* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x000000010003a3a8 LLDB`-[ViewController pengTest4:](self=0x0000000100205180, _cmd="pengTest4:", str=@"peng") at ViewController.m:105
    frame #1: 0x000000010003a35c LLDB`-[ViewController pengTest3:](self=0x0000000100205180, _cmd="pengTest3:", str=@"peng") at ViewController.m:101
  * frame #2: 0x000000010003a2d8 LLDB`-[ViewController pengTest2:](self=0x0000000100205180, _cmd="pengTest2:", str=@"peng") at ViewController.m:96
    frame #3: 0x000000010003a254 LLDB`-[ViewController pengTest1:](self=0x0000000100205180, _cmd="pengTest1:", str=@"peng") at ViewController.m:91
    frame #4: 0x000000010003a0bc LLDB`-[ViewController touchesBegan:withEvent:](self=0x0000000100205180, _cmd="touchesBegan:withEvent:", touches=1 element, event=0x00000001700f0f80) at ViewController.m:51
    frame #5: 0x000000019643401c UIKit`forwardTouchMethod + 336
    frame #6: 0x0000000196433eb8 UIKit`-[UIResponder touchesBegan:withEvent:] + 60
    frame #7: 0x00000001962d817c UIKit`-[UIWindow _sendTouchesForEvent:] + 1948
    frame #8: 0x00000001962d3728 UIKit`-[UIWindow sendEvent:] + 3192
    frame #9: 0x00000001962a433c UIKit`-[UIApplication sendEvent:] + 340
    frame #10: 0x0000000196a9e014 UIKit`__dispatchPreprocessedEventFromEventQueue + 2400
    frame #11: 0x0000000196a98770 UIKit`__handleEventQueue + 4268
    frame #12: 0x0000000196a98b9c UIKit`__handleHIDEventFetcherDrain + 148
    frame #13: 0x000000019012142c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    frame #14: 0x0000000190120d9c CoreFoundation`__CFRunLoopDoSources0 + 540
    frame #15: 0x000000019011e9a8 CoreFoundation`__CFRunLoopRun + 744
    frame #16: 0x000000019004eda4 CoreFoundation`CFRunLoopRunSpecific + 424
    frame #17: 0x0000000191ab8074 GraphicsServices`GSEventRunModal + 100
    frame #18: 0x0000000196309058 UIKit`UIApplicationMain + 208
    frame #19: 0x000000010003a4f0 LLDB`main(argc=1, argv=0x000000016fdcbae0) at main.m:14
    frame #20: 0x000000018f05d59c libdyld.dylib`start + 4

frame #3: 0x000000010003a254 LLDB`-[ViewController pengTest1:](self=0x0000000100205180, _cmd="pengTest1:", str=@"peng") at ViewController.m:91
   88   
   89   - (void)pengTest1:(NSString *)str{
   90       NSLog(@"%s",__func__);
-> 91       �[4m[�[0mself pengTest2:str];
   92   }
   93   
   94   - (void)pengTest2:(NSString *)str{

LLDB动态调试

$p [self.models addObject:[[Person alloc] init]];

$p Person *p5 = [[Person alloc] init];p5.name = "nextstep";p5.age = 13;[self.models addObject:p5];

内存断点

$frame variable
     
     (ViewController *) self = 0x0000000100509a20
     (SEL) _cmd = "viewDidLoad"
     (Person *) p1 = 0x000000010030aaf0
     (Person *) p2 = 0x0000000000000010
     (Person *) p3 = 0x000000016fd060f8
     //查看需要设置内存地址
     $p &p1->_name
     (NSString **) $0 = 0x000000010030ac98
     
     //设置
     $watchpoint set expression 0x000000010030ac98

cmmand指令(被动触发)

有时候当我们断点的时候,想让系统帮忙打印下对应信息

#设置断点
(lldb) b -[ViewController pengTest3:]
#输出
     Breakpoint 1: where = LLDB`-[ViewController pengTest3:] + 44 at ViewController.m:135, address = 0x0000000100012314

#查看断点清单
     (lldb) breakpoint list
     Current breakpoints:
     1: name = '-[ViewController pengTest3:]', locations = 1, resolved = 1, hit count = 1
     1.1: where = LLDB`-[ViewController pengTest3:] + 44 at ViewController.m:135, address = 0x0000000100012314, resolved, hit count = 1
     #设置断点指令(后续每次进入该断点 会运行对应指令)
     (lldb) breakpoint command add 1
     Enter your debugger command(s).  Type 'DONE' to end.
     > po self
     > p self.view
     > DONE
    #运行结果
 po self
<ViewController: 0x100405920>


 p self.view
(UIView *) $3 = 0x000000010020e7e0
    
  

*查看断点的指令
$breakpoint command list 1
*删除断点指令
$breakpoint command delete 1

p & po 区别

stop-hook(被动触发)

让你在每次stop的时候去执行一些命令,只对breadpoint,watchpoint
$target stop-hook add -o "frame variable"
断点一触发就会打印对应信息

Process 821 resuming
(ViewController *) self = 0x0000000100405920
(SEL) _cmd = "touchesBegan:withEvent:"
(__NSSetM *) touches = 0x0000000170246510 1 element
(UITouchesEvent *) event = 0x00000001740ef780
(UIView *) p1 = 0x000000010020e7e0

查看

$target stop-hook list

删除

$target stop-hook delete

直接取消 对应编号hook

$undisplay 2

常用命令

Best match found in /Users/pengxicheng/Library/Developer/Xcode/DerivedData/TestLLDB-ducscbzedftwabgaptewzlmqgexq/Build/Products/Debug-iphoneos/TestLLDB.app/TestLLDB:
id = {0x30000002b}, name = "Person", byte-size = 24, decl = Person.h:11, compiler_type = "@interface Person : NSObject{
    int _age;
    NSString * _name;
}
@property ( getter = name,setter = setName:,readwrite,copy,nonatomic ) NSString * name;
@property ( getter = age,setter = setAge:,assign,readwrite,nonatomic ) int age;

参考1:
http://lldb.llvm.org/index.html
参考2:
http://www.dreamingwish.com/article/lldb-usage-a.html
参考3:
https://developer.apple.com/library/content/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/lldb-basics.html#//apple_ref/doc/uid/TP40012917-CH2-SW1

上一篇 下一篇

猜你喜欢

热点阅读