簡體   English   中英

如何通過LLDB命令行添加斷點操作?

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

如果您從Xcode編輯斷點,則有一個超級有用的選項可以添加一個“Action”,以便在每次遇到斷點時自動執行。

如何從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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM