2016-05-13 356 views
3

我想用lldb設置條件斷點。Lldb:設置條件斷點與字符串相等作爲條件

breakpoint set -f myFile.cpp -l 123 -c 'a==3' 

然而,在我來說,我想測試一個std::string對象是等於某個字符串值,但這樣做

breakpoint set -f myFile.cpp -l 123 -c 'a=="hello"' 

不工作... LLDB:這通常是使用-c選項來完成不會抱怨(雖然GDB會返回一個錯誤),但它會在到達斷點時忽略條件字符串,並且太早打破...

此問題與this one類似,但使用lldb而不是gdb。該解決方案提出了有

breakpoint set -f myFile.cpp -l 123 if strcmp(a, "hello")==0 

似乎並沒有有效與LLDB使用

LLDB版本:3.4

回答

2
(lldb) br s -n main -c '(int)strcmp("test", var)==0' 
Breakpoint 1: where = a.out`main + 11 at a.c:3, address = 0x0000000100000f8b 
(lldb) br li 
Current breakpoints: 
1: name = 'main', locations = 1 
Condition: (int)strcmp("test", var)==0 

    1.1: where = a.out`main + 11 at a.c:3, address = a.out[0x0000000100000f8b], unresolved, hit count = 0 

(lldb) 

您可以在事後添加的條件表達式。像

(lldb) br s -n main 
Breakpoint 1: where = a.out`main + 11 at a.c:3, address = 0x0000000100000f8b 
(lldb) br mod -c '(int) strcmp("test", var) == 0' 
(lldb) br li 
Current breakpoints: 
1: name = 'main', locations = 1 
Condition: (int) strcmp("test", var) == 0 

    1.1: where = a.out`main + 11 at a.c:3, address = a.out[0x0000000100000f8b], unresolved, hit count = 0 

(lldb) 

breakpoint modify採用斷點號的斷點號/表底,如果沒有指定(這是我在這裏做),默認爲最新的斷點。