美文网首页
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 使用

    LLDB 使用 LLDB(Low Lever Debug)命令结构 其中: (命令)和 (子命令):LLDB调试命...

  • iOS LLDB调试

    掌握以下lldb命令,够用. ### LLDB调试总结 eNSString*$str=@"test"...

  • 各种调试技巧

    断点调试并配合LLDB常用调试命令LLDB命令详见:http://www.jianshu.com/p/d14a25...

  • iOS之LLDB常用调试命令

    iOS之LLDB常用调试命令熟练使用 LLDB,让你调试事半功倍使用facebook开源的Chisel调试Home...

  • iOS开发技能之lldb常用命令

    lldb命令调试 首先我们创建一个简单工程来调试这些命令。打断点,下方就可以进行lldb调试。 p & po po...

  • LLDB调试命令初探

    LLDB调试命令初探 初识LLDB 你可能从未使用过LLDB,那让我们先来热热身。 在调试器中最常用到的命令是p(...

  • 【LLDB】高级运用与深入理解

    摘要 如何在调试中高级运用调试方法,减少重新运行 LLDB获取帮助 调用help命令来列出LLDB所有的顶层命令 ...

  • 知识点-LLDB调试命令

    lldb是我们平时在打断点时候,打印面板出现的。 lldb是Xcode自带的调试工具,下面是常用的lldb调试命令...

  • LLDB命令调试与断点调试

    [LLDB命令调试与断点调试] https://my.oschina.net/notting/blog/11529...

  • LLDB 命令和调试(一)

    LLDB 命令和调试(一) 为什么要学习 LLDB 调试 对于我们程序员来说,构建调试几乎是每天必做的工作。 你是...

网友评论

      本文标题:lldb调试命令:

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