xcode – 如何通过LLDB命令行添加断点操作?

如果你从 Xcode编辑一个断点,有一个超级有用的选项,可以添加一个“Action”,以便在每次遇到断点时自动执行.

如何从LLDB命令行添加此类操作?

解决方法

使用breakpoint命令添加命令很容易.键入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,stop reason = breakpoint 1.1
    #0: 0x0000000100000f5f a.out`main + 31 at a.c:6
    #1: 0x00007fff8c2a17e1 libdyld.dylib`start + 1

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...