2013-05-02 24 views

Trả lời

18

Dễ dàng peasy với lệnh breakpoint command add. Nhập help breakpoint command add để biết chi tiết nhưng đây là một ví dụ.

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

Chạy lldb trên này. Đầu tiên, đặt một breakpoint trên dòng nguồn với "phá vỡ" ở đâu đó trong nó (viết tắt tốt đẹp cho ví dụ như thế này nhưng nó về cơ bản phải grep qua nguồn của bạn, vì vậy không có ích cho các dự án lớn)

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

Thêm một breakpoint điều kiện để các breakpoint chỉ dừng lại khi i là bội số của 5:

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

có in breakpoint giá trị hiện tại của i và vết lùi khi nó chạm:

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

và sau đó sử dụng nó:

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 
+0

Cảm ơn rất nhiều anh chàng! Tôi đoán nó phải ở đâu đó trong "breakpoint set" và tôi đã hoàn toàn sủa cây sai. – PHD

Các vấn đề liên quan