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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16345261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:19:07  来源:igfitidea点击:

How do you add breakpoint actions via the LLDB command line?

xcodedebuggingbreakpointslldb

提问by PHD

If you edit a breakpoint from Xcode, there is the super-useful option to add an "Action" to be automatically executed every time the breakpoint is hit.

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

How can you add such actions from the LLDB command line?

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

回答by Jason Molenda

Easy peasy with the breakpoint command addcommand. Type help breakpoint command addfor details but here's an example.

使用breakpoint command add命令轻松完成。键入help breakpoint command add的细节,但这里有一个例子。

int main ()
{
    int i = 0;
    while (i < 30)
    {
        i++; // break here
    }
}

Run lldb on this. First, put a breakpoint on the source line with "break" somewhere in it (nice shorthand for examples like this but it basically has to grep over your sources, so not useful for larger projects)

对此运行 lldb。首先,在源代码行上放置一个带有“break”的断点(对于这样的例子来说是一个很好的速记,但它基本上必须对你的源代码进行 grep,所以对较大的项目没有用)

(lldb) br s -p break
Breakpoint 1: where = a.out`main + 31 at a.c:6, address = 0x0000000100000f5f

Add a breakpoint condition so the breakpoint only stops when iis a multiple of 5:

添加断点条件,以便断点仅在i5 的倍数时停止:

(lldb) br mod -c 'i % 5 == 0' 1

Have the breakpoint print the current value of iand backtrace when it hits:

让断点打印当前值i并在它命中时回溯:

(lldb) br com add 1
Enter your debugger command(s).  Type 'DONE' to end.
> p i
> bt
> DONE

and then use it:

然后使用它:

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)  = 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