【发布时间】:2013-04-27 01:13:59
【问题描述】:
如果你从 Xcode 编辑断点,有一个超级有用的选项可以添加一个“Action”,每次断点被触发时自动执行。
如何从 LLDB 命令行添加此类操作?
【问题讨论】:
标签: xcode debugging breakpoints lldb
如果你从 Xcode 编辑断点,有一个超级有用的选项可以添加一个“Action”,每次断点被触发时自动执行。
如何从 LLDB 命令行添加此类操作?
【问题讨论】:
标签: xcode debugging breakpoints lldb
使用breakpoint command add 命令轻松搞定。输入 help breakpoint command add 了解详细信息,但这里是一个示例。
int main ()
{
int i = 0;
while (i < 30)
{
i++; // break here
}
}
在此运行 lldb。首先,在源代码行的某处放置一个断点,其中包含“break”(像这样的例子很好的简写,但它基本上必须对你的源代码进行 grep,因此对大型项目没有用处)
(lldb) br s -p break
Breakpoint 1: where = a.out`main + 31 at a.c:6, address = 0x0000000100000f5f
添加断点条件,使断点仅在i 是 5 的倍数时停止:
(lldb) br mod -c 'i % 5 == 0' 1
让断点打印i 的当前值并在命中时回溯:
(lldb) br com add 1
Enter your debugger command(s). Type 'DONE' to end.
> p i
> bt
> DONE
然后使用它:
Process 78674 stopped and was programmatically restarted.
Process 78674 stopped and was programmatically restarted.
Process 78674 stopped and was programmatically restarted.
Process 78674 stopped and was programmatically restarted.
Process 78674 stopped
* thread #1: tid = 0x1c03, 0x0000000100000f5f a.out`main + 31 at a.c:6, stop reason = breakpoint 1.1
#0: 0x0000000100000f5f a.out`main + 31 at a.c:6
3 int i = 0;
4 while (i < 30)
5 {
-> 6 i++; // break here
7 }
8 }
(int) $25 = 20
* thread #1: tid = 0x1c03, 0x0000000100000f5f a.out`main + 31 at a.c:6, stop reason = breakpoint 1.1
#0: 0x0000000100000f5f a.out`main + 31 at a.c:6
#1: 0x00007fff8c2a17e1 libdyld.dylib`start + 1
【讨论】: