美文网首页
lldb调试命令:

lldb调试命令:

作者: sfandy | 来源:发表于2016-10-10 17:19 被阅读590次

    lldb调试命令:
    n/next:step over;

    s/step:step into;

    finish:step out;

    c/continue:goto next breakpoint;

    expr/expression:Evaluate a C/ObjC/C++ expression(动态执行C/ObjC/C++表达式);

    p/print/expr/expression:print as a C/C++ basic variable;

    po/expr -O/expression -O:Print as an Objective-C object;

    call:调用。其实上述p/po后接表达式(expression)也有调用的功能,一般只在不需要显式输出,或是无返回值时使用call,用于动态调试插入调用代码。

    例如可以在viewDidLoad:里面设置断点,然后在程序中断的时候输入以下命令:
    

    1

    call [self.view setBackgroundColor:[UIColor redColor]]

    继续运行程序,view的背景颜色将变成红色!
    bt(backtrace),打印当前调用堆栈(crash堆栈),“bt all”可打印所有thread的堆栈(相当于command+6的Debug Session Navigation)。

    image:可用于寻址,有多个组合命令,比较实用的一种用法是寻找栈地址对应的代码(行)位置。

    例如某个UITableView总共有2个section,当其引用的currentSection.index≥2时将会引起[UITableView rectForHeaderInSection:]调用异常,可使用expr动态改值制造crash场景模拟调试。
    此时crash时的控制台bt显示异常出现在应用层代码“0x00d055b8 - [FACategoryTableView FACategorySectionHeaderDidTouched:] + 744”处(其中0x00d055b8为当前栈(代码段)偏移量,744为栈帧偏移量——PC指针相对函数入口的偏移)。
    那么具体是FACategoryTableView.m文件哪一行代码调用引起的异常呢?此时通过“image lookup --address”后接bt的call stack中的代码段偏移地址(0x00d055b8)即可定位出异常调用的代码行位置。
    x/memory read:dump指定地址的内存(Read from the memory of the process being debugged),后接起止地址或-c指定count加起始地址。可help mem read查看帮助:

    Syntax:
    memory read[]

    Command Options Usage:
    size指定内存块(block/item)的大小,默认为1byte。
    --size):The size in bytes to use when displaying with the selected format.

    count指定内存块(block/item)的个数,可配合起始地址使用。
    -c( --count):The number of total items to display.

    format指定内容显示格式,格式符同print:c-char,s-string,d-decimal,x-hex。
    -f( --format):Specify a format to be used for display.

    Command Samples:
    (a)起止地址
    (lldb)mem read 0x10b88f0c 0x10b88f0c+9
    0x10b88f0c: 39 38 37 36 35 34 33 32 31 987654321
    (b)起始地址+内存块count
    (lldb)mem read 0x10b88f0c -c 9
    0x10b88f0c: 39 38 37 36 35 34 33 32 31 987654321
    (c)起始地址+内存块size+内存块count(dump hex format)
    (lldb)memory read -s 1 -f x -c 9 0x10b88f0c
    0x10b88f0c: 0x39 0x38 0x37 0x36 0x35 0x34 0x33 0x32
    0x10b88f14: 0x31
    (d)起始地址+内存块size+内存块count(dump char format)
    (lldb)memory read -s 1 -f c -c 9 0x10b88f0c
    0x10b88f0c: 987654321
    (e)起始地址+内存块size+内存块count(dump string format)
    (lldb)mem read 0x10b5cf2c -f s -c 1
    0x10b88f0c: "987654321"
    (f)起始地址+内存块size+内存块count(dump int format)
    (lldb)memory read -s 4 -f x -c 3 0x10b88f0c
    0x10b88f0c: 0x36373839 0x32333435 0x109f0031
    memory write:改写指定地址的内存(Write to the memory of the process being debugged)。可help mem write查看帮助:

    Syntax: memory write

    [[...]]

    相关文章

      网友评论

          本文标题:lldb调试命令:

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