2014-01-11 43 views
7

隨着gdb到lldb的新變化,我找不到如何在某些內存地址上設置觀察點的方法。關於內存地址的觀察點

在gdb中我用這個

watch -location *0x123456 

做同樣的LLDB

w s e *0x123456 

是不是爲我工作。 那麼我能用什麼來在lldb中運行相同的命令?

回答

16

設置在LLDB監視點時省略了「提領操作」 *,只是通過地址:

watchpoint set expression -- 0x123456 
# short form: 
w s e -- 0x123456 

在存儲位置0x123456設置一個觀察點。或者,您可以使用--size來設置要觀看的字節數。例如,在短形式:

w s e -s 2 -- 0x123456 

還可以設置一個觀察點上的變量:

watchpoint set variable <variable> 
# short form: 
w s v <variable> 

例如:用下面的代碼,並設置在第二線斷點:

int x = 2; 
x = 5; 

我在Xcode調試器控制檯中這樣做了:

 
(lldb) p &x 
(int *) $0 = 0xbfffcbd8 
(lldb) w s e -- 0xbfffcbd8 
Watchpoint created: Watchpoint 1: addr = 0xbfffcbd8 size = 4 state = enabled type = w 
    new value: 2 
(lldb) n 

Watchpoint 1 hit: 
old value: 2 
new value: 5 
(lldb) 

更簡單地說,我可以設定

 
(lldb) w s v x 
Watchpoint created: Watchpoint 1: addr = 0x7fff5fbff7dc size = 4 state = enabled type = w 
    declare @ '/Users/martin/Documents/tmpprojects/watcher/watcher/main.c:16' 
    watchpoint spec = 'x' 
+0

觀察點我得到這個:地址錯誤表達式求值看失敗,表情評估 – user3001909

+0

@ user3001909:奇怪,我測試過這一點。 - 我添加了一個例子。 –

+0

我試過你的例子,lldb說使用未聲明的標識符'x'。然後做了 - e - 0xOFFSET,它工作。 watchpoint created:Watchpoint 1:addr = 0xOFFSET size = 4 state ... new value:10。 謝謝! – user3001909