美文网首页
LLDB调试

LLDB调试

作者: 小狼_zy | 来源:发表于2018-05-04 10:36 被阅读0次

    常用指令

    continue /  c    执行到下一个断点

    next / n           单步运行 把子函数当作整体

    step / s           单步运行 遇到函数会进去

    memory read / x   读取内存地址中的值


    增加断点的方法

    @implementation ViewController

    - (void)lldbDemo:(id)parame {}

    void test() {}

    breakpoint set -n 

    $breakpoint set -n test

    breakpoint set -n 

    $breakpoint set -n "-[ViewController lldbDemo:]"

    b -n  

    $b -n  "-[ViewController lldbDemo:]"

    b -[ViewController touchesBegan:withEvent:]

    $b -[ViewController lldbDemo:]

    breakpoint set --selector  /  b     

    将所有的同名方法都加断点

    $breakpoint set --selector lldbDemo

    $b lldbDemo

    breakpoint set --file  --selector 

    $breakpoint set --file  ViewController.m --selector lldbDemo:

    breakpoint list   /   break list

    $break list

    Current breakpoints:1: file = '~/ViewController.m', line = 27, exact_match = 0, locations = 1, resolved = 1, hit count = 1 

    1.1: where = lldbDemo`-[ViewController touchesBegan:withEvent:] + 80 at ViewController.m:28, address = 0x00000001087b1730, resolved, hit count = 1 2: name = '-[ViewController lldbDemo:]', locations = 1, resolved = 1, hit count = 0 

    2.1: where = lldbDemo`-[ViewController lldbDemo:] + 47 at ViewController.m:24, address = 0x00000001087b16cf, resolved, hit count = 0 

    breakpoint disable  /   break dis     breakpoint enable  /  break en

    $break dis 1.1

    $break en 2.1

    Current breakpoints:1: file = '~/ViewController.m', line = 27, exact_match = 0, locations = 1   

    1.1: where = lldbDemo`-[ViewController touchesBegan:withEvent:] + 80 at ViewController.m:28, address = 0x00000001087b1730, unresolved, hit count = 1 2: name = '-[ViewController lldbDemo:]', locations = 1, resolved = 1, hit count = 0  Options: disabled

    2.1: where = lldbDemo`-[ViewController lldbDemo:] + 47 at ViewController.m:24, address = 0x00000001087b16cf, resolved, hit count = 0  Options: enabled

    breakpoint delete

    只能删除整个大类,删除分类时只是将分类设为disable

    $breakpoint delete

    About to delete all breakpoints, do you want to do that?: [Y/n]

    $breakpoint delete 1.1  

    1.1: where = lldbDemo`-[ViewController touchesBegan:withEvent:] + 80 at ViewController.m:28, address = 0x00000001087b1730, unresolved, hit count = 1 2: name = '-[ViewController lldbDemo:]', locations = 1, resolved = 1, hit count = 0  Options: disabled

    breakpoint set -r   

    遍历满足项目中所有方法的关键字

     $breakpoint set -r touches

    Breakpoint 5: 359 locations.



    修改参数值

    expression /  p

    #import "Person.h"

    @implementation ViewController

    - (void)viewDidLoad {

        Person *p = [[Person alloc] init];

        [self.personModels addObject:p];

    }

    $p (Person *)self.personModels.firstObject    //获取参数内存地址

    (Person *) $1 = 0x000060000002fe20

    $p $1 .name = @""   //修改属性

    $p &person->_name  //查看属性


    断点轨迹调试

    backTrack   /   bt

    查看断点历史轨迹

    $bt

    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1   * frame #0: 0x000000010b43e730 lldbDemo`-[ViewController touchesBegan:withEvent:](self=0x00007fdc3f60d7c0, _cmd="touchesBegan:withEvent:", touches=1 element, event=0x000060800011c170) at ViewController.m:28 

    frame #1: 0x000000010c8077c7 UIKit`forwardTouchMethod + 340    

    frame #2: 0x000000010c807662 UIKit`-[UIResponder touchesBegan:withEvent:] + 49    

    frame #3: 0x000000010c64fe7a UIKit`-[UIWindow _sendTouchesForEvent:] + 2052    

    frame #4: 0x000000010c651821 UIKit`-[UIWindow sendEvent:] + 4086    

    frame #5: 0x000000010c5f5370 UIKit`-[UIApplication sendEvent:] + 352    

    frame #6: 0x000000010cf3657f UIKit`__dispatchPreprocessedEventFromEventQueue + 2796    

    frame #7: 0x000000010cf39194 UIKit`__handleEventQueueInternal + 5949    

    frame #8: 0x000000010eec7bb1 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17    

    frame #9: 0x000000010eeac4af CoreFoundation`__CFRunLoopDoSources0 + 271    

    frame #10: 0x000000010eeaba6f CoreFoundation`__CFRunLoopRun + 1263    

    frame #11: 0x000000010eeab30b CoreFoundation`CFRunLoopRunSpecific + 635    

    frame #12: 0x0000000111813a73 GraphicsServices`GSEventRunModal + 62    

    frame #13: 0x000000010c5da0b7 UIKit`UIApplicationMain + 159    

    frame #14: 0x000000010b43e7bf lldbDemo`main(argc=1, argv=0x00007ffee47c1060) at main.m:14    

    frame #15: 0x0000000110102955 libdyld.dylib`start + 1

    up  down

    更改断点位置

    frame select

    直接跳到指定断点

    $frame select 2

    frame variable

    打印断点所在位置的所有属性

    $frame variable

    (ViewController *) self = 0x00007fdc3f60d7c0

    (SEL) _cmd = "touchesBegan:withEvent:"

    (__NSSetM *) touches = 0x000060400002b940 1 element

    (UITouchesEvent *) event = 0x000060800011c170

    thread return

    断点执行到上一个,但是结束断点之后不会在执行之后的代码



    观察内存断点

    watchpoint set variable

    $watchpoint set variable p->_name     //当name属性的值发生变化时,断点自动执行到当前函数中

    watchpoint set expression

    通过内存地址添加观察断点

    $watchpoint set expression 0x000060400003c808 

    watchpoint list

    watchpoint delete

    使用方法参考breakpoint



    添加指令

    break command add

    $break list

    1.1 ...

    2.1...

    $break command add 1.1

    Enter your debugger command(s).  Type 'DONE' to end.

    >  frame variable   // 输入要执行的代码

    break command list

    break command delete 

    $break command list 1.1

    Breakpoint 1.1:    

    Breakpoint commands:      

    frame variable

    target stop-hook add    /   target stop-hook add -o

    将所有断点都添加指令

    $target stop-hook add -o "frame variable"

    target stop-hook list

    target stop-hook delete   /  undisplay

    target stop-hook disable



    查看异常指针

    'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray'

    *** First throw call stack:

    ( 0   CoreFoundation                      0x00000001068711e6 __exceptionPreprocess + 294

    1   libobjc.A.dylib                     0x0000000105f06031 objc_exception_throw + 48

    2   CoreFoundation                      0x0000000106889e3d -[__NSArray0 objectAtIndex:] + 93

    3   lldbDemo                            0x00000001056066d1 -[ViewController touchesBegan:withEvent:] + 129

    4   UIKit                               0x0000000106f1b7c7 forwardTouchMethod + 340

    5   UIKit                               0x0000000106f1b662 -[UIResponder touchesBegan:withEvent:] + 49

    6   UIKit                               0x0000000106d63e7a -[UIWindow _sendTouchesForEvent:] + 2052

    7   UIKit                               0x0000000106d65821 -[UIWindow sendEvent:] + 4086

    8   UIKit                               0x0000000106d09370 -[UIApplication sendEvent:] + 352

    9   UIKit                               0x000000010764a57f __dispatchPreprocessedEventFromEventQueue + 2796

    10  UIKit                               0x000000010764d194 __handleEventQueueInternal + 5949

    11  CoreFoundation                      0x0000000106813bb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

    12  CoreFoundation                      0x00000001067f84af __CFRunLoopDoSources0 + 271

    13  CoreFoundation                      0x00000001067f7a6f __CFRunLoopRun + 1263

    14  CoreFoundation                      0x00000001067f730b CFRunLoopRunSpecific + 635

    15  GraphicsServices                    0x000000010b9dba73 GSEventRunModal + 62

    16  UIKit                               0x0000000106cee0b7 UIApplicationMain + 159

    17  lldbDemo                            0x000000010560679f main + 111

    18  libdyld.dylib                       0x000000010a2ca955 start + 1

    19  ???                                 0x0000000000000001 0x0 + 1 )

    image lookup -a 

    查看异常指针

    $image lookup -a 0x00000001056066d1

     Address: lldbDemo[0x00000001000016d1] (lldbDemo.__TEXT.__text + 257)       Summary: lldbDemo`-[ViewController touchesBegan:withEvent:] + 129 at ViewController.m:28

    image lookup -t

    查看一个类信息

    $image lookup -t ViewController

    Best match found in ~/lldbDemo.app/lldbDemo: id = {0x10000002b}, name = "ViewController", byte-size = 8, decl = ViewController.h:11, compiler_type = "@interface ViewController : UIViewController @end"

    相关文章

      网友评论

          本文标题:LLDB调试

          本文链接:https://www.haomeiwen.com/subject/petlrftx.html